Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/container/XNameContainer.hpp>
21 : #include "FillStyleContext.hxx"
22 : #include <xmloff/xmlimp.hxx>
23 : #include "xmloff/GradientStyle.hxx"
24 : #include "xmloff/HatchStyle.hxx"
25 : #include "xmloff/ImageStyle.hxx"
26 : #include "TransGradientStyle.hxx"
27 : #include "xmloff/MarkerStyle.hxx"
28 : #include "xmloff/DashStyle.hxx"
29 : #include <xmloff/families.hxx>
30 : #include <xmloff/nmspmap.hxx>
31 : #include "xmloff/xmlnmspe.hxx"
32 : #include <xmloff/XMLBase64ImportContext.hxx>
33 :
34 : using namespace ::com::sun::star;
35 :
36 :
37 : //////////////////////////////////////////////////////////////////////////////
38 : //////////////////////////////////////////////////////////////////////////////
39 :
40 0 : TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
41 :
42 18 : XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
43 : const OUString& rLName,
44 : const uno::Reference< xml::sax::XAttributeList >& xAttrList)
45 18 : : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
46 : {
47 :
48 : // start import
49 18 : XMLGradientStyleImport aGradientStyle( GetImport() );
50 18 : aGradientStyle.importXML( xAttrList, maAny, maStrName );
51 18 : }
52 :
53 36 : XMLGradientStyleContext::~XMLGradientStyleContext()
54 : {
55 36 : }
56 :
57 18 : void XMLGradientStyleContext::EndElement()
58 : {
59 18 : uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
60 :
61 : try
62 : {
63 18 : if(xGradient.is())
64 : {
65 18 : if( xGradient->hasByName( maStrName ) )
66 : {
67 0 : xGradient->replaceByName( maStrName, maAny );
68 : }
69 : else
70 : {
71 18 : xGradient->insertByName( maStrName, maAny );
72 : }
73 : }
74 : }
75 0 : catch( container::ElementExistException& )
76 18 : {}
77 18 : }
78 :
79 18 : sal_Bool XMLGradientStyleContext::IsTransient() const
80 : {
81 18 : return sal_True;
82 : }
83 :
84 : //////////////////////////////////////////////////////////////////////////////
85 : //////////////////////////////////////////////////////////////////////////////
86 :
87 0 : TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
88 :
89 14 : XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
90 : const OUString& rLName,
91 : const uno::Reference< xml::sax::XAttributeList >& xAttrList)
92 14 : : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
93 : {
94 : // start import
95 14 : XMLHatchStyleImport aHatchStyle( GetImport() );
96 14 : aHatchStyle.importXML( xAttrList, maAny, maStrName );
97 14 : }
98 :
99 28 : XMLHatchStyleContext::~XMLHatchStyleContext()
100 : {
101 28 : }
102 :
103 14 : void XMLHatchStyleContext::EndElement()
104 : {
105 14 : uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
106 :
107 : try
108 : {
109 14 : if(xHatch.is())
110 : {
111 14 : if( xHatch->hasByName( maStrName ) )
112 : {
113 0 : xHatch->replaceByName( maStrName, maAny );
114 : }
115 : else
116 : {
117 14 : xHatch->insertByName( maStrName, maAny );
118 : }
119 : }
120 : }
121 0 : catch( container::ElementExistException& )
122 14 : {}
123 14 : }
124 :
125 14 : sal_Bool XMLHatchStyleContext::IsTransient() const
126 : {
127 14 : return sal_True;
128 : }
129 :
130 : //////////////////////////////////////////////////////////////////////////////
131 : //////////////////////////////////////////////////////////////////////////////
132 :
133 0 : TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
134 :
135 6 : XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
136 : const OUString& rLName,
137 : const uno::Reference< xml::sax::XAttributeList >& xAttrList)
138 6 : : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
139 : {
140 : // start import
141 6 : XMLImageStyle aBitmapStyle;
142 6 : aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
143 6 : }
144 :
145 12 : XMLBitmapStyleContext::~XMLBitmapStyleContext()
146 : {
147 12 : }
148 :
149 0 : SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
150 : {
151 0 : SvXMLImportContext *pContext = 0;
152 0 : if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
153 : {
154 0 : OUString sURL;
155 0 : maAny >>= sURL;
156 0 : if( sURL.isEmpty() && !mxBase64Stream.is() )
157 : {
158 0 : mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
159 0 : if( mxBase64Stream.is() )
160 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
161 : rLocalName, xAttrList,
162 0 : mxBase64Stream );
163 0 : }
164 : }
165 0 : if( !pContext )
166 : {
167 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
168 : }
169 :
170 0 : return pContext;
171 : }
172 :
173 6 : void XMLBitmapStyleContext::EndElement()
174 : {
175 6 : OUString sURL;
176 6 : maAny >>= sURL;
177 :
178 6 : if( sURL.isEmpty() && mxBase64Stream.is() )
179 : {
180 0 : sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
181 0 : mxBase64Stream = 0;
182 0 : maAny <<= sURL;
183 : }
184 :
185 12 : uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
186 :
187 : try
188 : {
189 6 : if(xBitmap.is())
190 : {
191 6 : if( xBitmap->hasByName( maStrName ) )
192 : {
193 0 : xBitmap->replaceByName( maStrName, maAny );
194 : }
195 : else
196 : {
197 6 : xBitmap->insertByName( maStrName, maAny );
198 : }
199 : }
200 : }
201 0 : catch( container::ElementExistException& )
202 6 : {}
203 6 : }
204 :
205 6 : sal_Bool XMLBitmapStyleContext::IsTransient() const
206 : {
207 6 : return sal_True;
208 : }
209 :
210 :
211 : //////////////////////////////////////////////////////////////////////////////
212 : //////////////////////////////////////////////////////////////////////////////
213 :
214 0 : TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
215 :
216 6 : XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
217 : const OUString& rLName,
218 : const uno::Reference< xml::sax::XAttributeList >& xAttrList)
219 6 : : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
220 : {
221 : // start import
222 6 : XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
223 6 : aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
224 6 : }
225 :
226 12 : XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
227 : {
228 12 : }
229 :
230 6 : void XMLTransGradientStyleContext::EndElement()
231 : {
232 6 : uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
233 :
234 : try
235 : {
236 6 : if(xTransGradient.is())
237 : {
238 6 : if( xTransGradient->hasByName( maStrName ) )
239 : {
240 0 : xTransGradient->replaceByName( maStrName, maAny );
241 : }
242 : else
243 : {
244 6 : xTransGradient->insertByName( maStrName, maAny );
245 : }
246 : }
247 : }
248 0 : catch( container::ElementExistException& )
249 6 : {}
250 6 : }
251 :
252 6 : sal_Bool XMLTransGradientStyleContext::IsTransient() const
253 : {
254 6 : return sal_True;
255 : }
256 :
257 : //////////////////////////////////////////////////////////////////////////////
258 : //////////////////////////////////////////////////////////////////////////////
259 :
260 0 : TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
261 :
262 19 : XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
263 : const OUString& rLName,
264 : const uno::Reference< xml::sax::XAttributeList >& xAttrList)
265 19 : : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
266 : {
267 : // start import
268 19 : XMLMarkerStyleImport aMarkerStyle( GetImport() );
269 19 : aMarkerStyle.importXML( xAttrList, maAny, maStrName );
270 19 : }
271 :
272 38 : XMLMarkerStyleContext::~XMLMarkerStyleContext()
273 : {
274 38 : }
275 :
276 19 : void XMLMarkerStyleContext::EndElement()
277 : {
278 19 : uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
279 :
280 : try
281 : {
282 19 : if(xMarker.is())
283 : {
284 19 : if( xMarker->hasByName( maStrName ) )
285 : {
286 7 : xMarker->replaceByName( maStrName, maAny );
287 : }
288 : else
289 : {
290 12 : xMarker->insertByName( maStrName, maAny );
291 : }
292 : }
293 : }
294 0 : catch( container::ElementExistException& )
295 19 : {}
296 19 : }
297 :
298 19 : sal_Bool XMLMarkerStyleContext::IsTransient() const
299 : {
300 19 : return sal_True;
301 : }
302 :
303 : //////////////////////////////////////////////////////////////////////////////
304 : //////////////////////////////////////////////////////////////////////////////
305 :
306 0 : TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
307 :
308 1 : XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
309 : const OUString& rLName,
310 : const uno::Reference< xml::sax::XAttributeList >& xAttrList)
311 1 : : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
312 : {
313 : // start import
314 1 : XMLDashStyleImport aDashStyle( GetImport() );
315 1 : aDashStyle.importXML( xAttrList, maAny, maStrName );
316 1 : }
317 :
318 2 : XMLDashStyleContext::~XMLDashStyleContext()
319 : {
320 2 : }
321 :
322 1 : void XMLDashStyleContext::EndElement()
323 : {
324 1 : uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
325 :
326 : try
327 : {
328 1 : if(xDashes.is())
329 : {
330 1 : if( xDashes->hasByName( maStrName ) )
331 : {
332 0 : xDashes->replaceByName( maStrName, maAny );
333 : }
334 : else
335 : {
336 1 : xDashes->insertByName( maStrName, maAny );
337 : }
338 : }
339 : }
340 0 : catch( container::ElementExistException& )
341 1 : {}
342 1 : }
343 :
344 1 : sal_Bool XMLDashStyleContext::IsTransient() const
345 : {
346 1 : return sal_True;
347 : }
348 :
349 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|