1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLSymbolImageContext.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmltkmap.hxx>
29 #include "xmloff/xmlnmspe.hxx"
30 #include <xmloff/xmlimp.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/XMLBase64ImportContext.hxx>
33 #include <com/sun/star/io/XOutputStream.hpp>
34 
35 TYPEINIT1( XMLSymbolImageContext, XMLElementPropertyContext );
36 
37 using namespace ::com::sun::star;
38 
39 enum SvXMLTokenMapAttrs
40 {
41 	XML_TOK_SYMBOL_IMAGE_HREF,
42 	XML_TOK_SYMBOL_IMAGE_TYPE,
43 	XML_TOK_SYMBOL_IMAGE_ACTUATE,
44     XML_TOK_SYMBOL_IMAGE_SHOW,
45 	XML_TOK_SYMBOL_IMAGE_END = XML_TOK_UNKNOWN
46 };
47 
48 static __FAR_DATA SvXMLTokenMapEntry aSymbolImageAttrTokenMap[] =
49 {
50 	{ XML_NAMESPACE_XLINK,  ::xmloff::token::XML_HREF,     XML_TOK_SYMBOL_IMAGE_HREF    },
51 	{ XML_NAMESPACE_XLINK,  ::xmloff::token::XML_TYPE,     XML_TOK_SYMBOL_IMAGE_TYPE    },
52 	{ XML_NAMESPACE_XLINK,  ::xmloff::token::XML_ACTUATE,  XML_TOK_SYMBOL_IMAGE_ACTUATE },
53 	{ XML_NAMESPACE_XLINK,  ::xmloff::token::XML_SHOW,     XML_TOK_SYMBOL_IMAGE_SHOW },
54 	XML_TOKEN_MAP_END
55 };
56 
XMLSymbolImageContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const XMLPropertyState & rProp,::std::vector<XMLPropertyState> & rProps)57 XMLSymbolImageContext::XMLSymbolImageContext(
58     SvXMLImport& rImport, sal_uInt16 nPrfx,
59     const ::rtl::OUString& rLName,
60     const XMLPropertyState& rProp,
61     ::std::vector< XMLPropertyState > &rProps ) :
62         XMLElementPropertyContext(
63             rImport, nPrfx, rLName, rProp, rProps )
64 {
65 }
66 
~XMLSymbolImageContext()67 XMLSymbolImageContext::~XMLSymbolImageContext()
68 {}
69 
StartElement(const uno::Reference<xml::sax::XAttributeList> & xAttrList)70 void XMLSymbolImageContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
71 {
72 	SvXMLTokenMap aTokenMap( aSymbolImageAttrTokenMap );
73     ::rtl::OUString aLocalName;
74 
75     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
76     for( sal_Int16 i = 0; i < nAttrCount; i++ )
77     {
78 		const ::rtl::OUString& rAttrName = xAttrList->getNameByIndex( i );
79 		sal_uInt16 nPrefix =
80 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
81 															&aLocalName );
82 		const ::rtl::OUString& rValue = xAttrList->getValueByIndex( i );
83 
84         switch( aTokenMap.Get( nPrefix, aLocalName ) )
85         {
86             case XML_TOK_SYMBOL_IMAGE_HREF:
87                 msURL = rValue;
88                 break;
89             case XML_TOK_SYMBOL_IMAGE_ACTUATE:
90             case XML_TOK_SYMBOL_IMAGE_TYPE:
91             case XML_TOK_SYMBOL_IMAGE_SHOW:
92                 // these values are currently not interpreted
93                 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
94                 break;
95         }
96     }
97 }
98 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)99 SvXMLImportContext* XMLSymbolImageContext::CreateChildContext(
100     sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
101     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
102 {
103 	SvXMLImportContext* pContext = NULL;
104 	if( xmloff::token::IsXMLToken( rLocalName,
105                                    xmloff::token::XML_BINARY_DATA ) )
106 	{
107 		if( ! msURL.getLength() && ! mxBase64Stream.is() )
108 		{
109 			mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
110 			if( mxBase64Stream.is() )
111 				pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
112                                                        rLocalName, xAttrList,
113                                                        mxBase64Stream );
114 		}
115 	}
116 	if( ! pContext )
117 	{
118 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
119 	}
120 
121 	return pContext;
122 }
123 
EndElement()124 void XMLSymbolImageContext::EndElement()
125 {
126     ::rtl::OUString sResolvedURL;
127 
128     if( msURL.getLength() )
129 	{
130 		sResolvedURL = GetImport().ResolveGraphicObjectURL( msURL, sal_False );
131 	}
132 	else if( mxBase64Stream.is() )
133 	{
134 		sResolvedURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
135 		mxBase64Stream = 0;
136 	}
137 
138     if( sResolvedURL.getLength())
139     {
140         // aProp is a member of XMLElementPropertyContext
141         aProp.maValue <<= sResolvedURL;
142         SetInsert( sal_True );
143     }
144 
145 	XMLElementPropertyContext::EndElement();
146 }
147