1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLSymbolImageContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLSymbolImageContext.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmltkmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmlimp.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/XMLBase64ImportContext.hxx>
40 #include <com/sun/star/io/XOutputStream.hpp>
42 TYPEINIT1( XMLSymbolImageContext
, XMLElementPropertyContext
);
44 using namespace ::com::sun::star
;
46 enum SvXMLTokenMapAttrs
48 XML_TOK_SYMBOL_IMAGE_HREF
,
49 XML_TOK_SYMBOL_IMAGE_TYPE
,
50 XML_TOK_SYMBOL_IMAGE_ACTUATE
,
51 XML_TOK_SYMBOL_IMAGE_SHOW
,
52 XML_TOK_SYMBOL_IMAGE_END
= XML_TOK_UNKNOWN
55 static __FAR_DATA SvXMLTokenMapEntry aSymbolImageAttrTokenMap
[] =
57 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_HREF
, XML_TOK_SYMBOL_IMAGE_HREF
},
58 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_TYPE
, XML_TOK_SYMBOL_IMAGE_TYPE
},
59 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_ACTUATE
, XML_TOK_SYMBOL_IMAGE_ACTUATE
},
60 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_SHOW
, XML_TOK_SYMBOL_IMAGE_SHOW
},
64 XMLSymbolImageContext::XMLSymbolImageContext(
65 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
66 const ::rtl::OUString
& rLName
,
67 const XMLPropertyState
& rProp
,
68 ::std::vector
< XMLPropertyState
> &rProps
) :
69 XMLElementPropertyContext(
70 rImport
, nPrfx
, rLName
, rProp
, rProps
)
74 XMLSymbolImageContext::~XMLSymbolImageContext()
77 void XMLSymbolImageContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
79 SvXMLTokenMap
aTokenMap( aSymbolImageAttrTokenMap
);
80 ::rtl::OUString aLocalName
;
82 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
83 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
85 const ::rtl::OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
87 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
89 const ::rtl::OUString
& rValue
= xAttrList
->getValueByIndex( i
);
91 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
93 case XML_TOK_SYMBOL_IMAGE_HREF
:
96 case XML_TOK_SYMBOL_IMAGE_ACTUATE
:
97 case XML_TOK_SYMBOL_IMAGE_TYPE
:
98 case XML_TOK_SYMBOL_IMAGE_SHOW
:
99 // these values are currently not interpreted
100 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
106 SvXMLImportContext
* XMLSymbolImageContext::CreateChildContext(
107 sal_uInt16 nPrefix
, const ::rtl::OUString
& rLocalName
,
108 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
110 SvXMLImportContext
* pContext
= NULL
;
111 if( xmloff::token::IsXMLToken( rLocalName
,
112 xmloff::token::XML_BINARY_DATA
) )
114 if( ! msURL
.getLength() && ! mxBase64Stream
.is() )
116 mxBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
117 if( mxBase64Stream
.is() )
118 pContext
= new XMLBase64ImportContext( GetImport(), nPrefix
,
119 rLocalName
, xAttrList
,
125 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
131 void XMLSymbolImageContext::EndElement()
133 ::rtl::OUString sResolvedURL
;
135 if( msURL
.getLength() )
137 sResolvedURL
= GetImport().ResolveGraphicObjectURL( msURL
, sal_False
);
139 else if( mxBase64Stream
.is() )
141 sResolvedURL
= GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream
);
145 if( sResolvedURL
.getLength())
147 // aProp is a member of XMLElementPropertyContext
148 aProp
.maValue
<<= sResolvedURL
;
149 SetInsert( sal_True
);
152 XMLElementPropertyContext::EndElement();