xref: /AOO41X/main/xmloff/source/style/FillStyleContext.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
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 <com/sun/star/container/XNameContainer.hpp>
27 #include "FillStyleContext.hxx"
28 #include <xmloff/xmlimp.hxx>
29 #include "xmloff/GradientStyle.hxx"
30 #include "xmloff/HatchStyle.hxx"
31 #include "xmloff/ImageStyle.hxx"
32 #include "TransGradientStyle.hxx"
33 #include "xmloff/MarkerStyle.hxx"
34 #include "xmloff/DashStyle.hxx"
35 #include <xmloff/families.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/XMLBase64ImportContext.hxx>
39 
40 using namespace ::com::sun::star;
41 using ::rtl::OUString;
42 using ::rtl::OUStringBuffer;
43 
44 
45 //////////////////////////////////////////////////////////////////////////////
46 //////////////////////////////////////////////////////////////////////////////
47 
48 TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
49 
50 XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
51                                               const OUString& rLName,
52                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
53 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
54 {
55     // set Family
56 //  SetFamily( XML_STYLE_FAMILY_FILLSTYLE_GRADIENT_ID );
57 
58     // start import
59     XMLGradientStyleImport aGradientStyle( GetImport() );
60     aGradientStyle.importXML( xAttrList, maAny, maStrName );
61 }
62 
63 XMLGradientStyleContext::~XMLGradientStyleContext()
64 {
65 }
66 
67 void XMLGradientStyleContext::EndElement()
68 {
69     uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
70 
71     try
72     {
73         if(xGradient.is())
74         {
75             if( xGradient->hasByName( maStrName ) )
76             {
77                 xGradient->replaceByName( maStrName, maAny );
78             }
79             else
80             {
81                 xGradient->insertByName( maStrName, maAny );
82             }
83         }
84     }
85     catch( container::ElementExistException& )
86     {}
87 }
88 
89 sal_Bool XMLGradientStyleContext::IsTransient() const
90 {
91     return sal_True;
92 }
93 
94 //////////////////////////////////////////////////////////////////////////////
95 //////////////////////////////////////////////////////////////////////////////
96 
97 TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
98 
99 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
100                                               const OUString& rLName,
101                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
102 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
103 {
104     // start import
105     XMLHatchStyleImport aHatchStyle( GetImport() );
106     aHatchStyle.importXML( xAttrList, maAny, maStrName );
107 }
108 
109 XMLHatchStyleContext::~XMLHatchStyleContext()
110 {
111 }
112 
113 void XMLHatchStyleContext::EndElement()
114 {
115     uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
116 
117     try
118     {
119         if(xHatch.is())
120         {
121             if( xHatch->hasByName( maStrName ) )
122             {
123                 xHatch->replaceByName( maStrName, maAny );
124             }
125             else
126             {
127                 xHatch->insertByName( maStrName, maAny );
128             }
129         }
130     }
131     catch( container::ElementExistException& )
132     {}
133 }
134 
135 sal_Bool XMLHatchStyleContext::IsTransient() const
136 {
137     return sal_True;
138 }
139 
140 //////////////////////////////////////////////////////////////////////////////
141 //////////////////////////////////////////////////////////////////////////////
142 
143 TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
144 
145 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
146                                               const OUString& rLName,
147                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
148 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
149 {
150     // start import
151     XMLImageStyle aBitmapStyle;
152     aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
153 }
154 
155 XMLBitmapStyleContext::~XMLBitmapStyleContext()
156 {
157 }
158 
159 SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
160 {
161     SvXMLImportContext *pContext = 0;
162     if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
163     {
164         OUString sURL;
165         maAny >>= sURL;
166         if( !sURL.getLength() && !mxBase64Stream.is() )
167         {
168             mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
169             if( mxBase64Stream.is() )
170                 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
171                                                     rLocalName, xAttrList,
172                                                     mxBase64Stream );
173         }
174     }
175     if( !pContext )
176     {
177         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
178     }
179 
180     return pContext;
181 }
182 
183 void XMLBitmapStyleContext::EndElement()
184 {
185     OUString sURL;
186     maAny >>= sURL;
187 
188     if( !sURL.getLength() && mxBase64Stream.is() )
189     {
190         sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
191         mxBase64Stream = 0;
192         maAny <<= sURL;
193     }
194 
195     uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
196 
197     try
198     {
199         if(xBitmap.is())
200         {
201             if( xBitmap->hasByName( maStrName ) )
202             {
203                 xBitmap->replaceByName( maStrName, maAny );
204             }
205             else
206             {
207                 xBitmap->insertByName( maStrName, maAny );
208             }
209         }
210     }
211     catch( container::ElementExistException& )
212     {}
213 }
214 
215 sal_Bool XMLBitmapStyleContext::IsTransient() const
216 {
217     return sal_True;
218 }
219 
220 
221 //////////////////////////////////////////////////////////////////////////////
222 //////////////////////////////////////////////////////////////////////////////
223 
224 TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
225 
226 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
227                                               const OUString& rLName,
228                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
229 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
230 {
231     // start import
232     XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
233     aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
234 }
235 
236 XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
237 {
238 }
239 
240 void XMLTransGradientStyleContext::EndElement()
241 {
242     uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
243 
244     try
245     {
246         if(xTransGradient.is())
247         {
248             if( xTransGradient->hasByName( maStrName ) )
249             {
250                 xTransGradient->replaceByName( maStrName, maAny );
251             }
252             else
253             {
254                 xTransGradient->insertByName( maStrName, maAny );
255             }
256         }
257     }
258     catch( container::ElementExistException& )
259     {}
260 }
261 
262 sal_Bool XMLTransGradientStyleContext::IsTransient() const
263 {
264     return sal_True;
265 }
266 
267 //////////////////////////////////////////////////////////////////////////////
268 //////////////////////////////////////////////////////////////////////////////
269 
270 TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
271 
272 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
273                                               const OUString& rLName,
274                                               const uno::Reference< xml::sax::XAttributeList >& xAttrList)
275 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
276 {
277     // start import
278     XMLMarkerStyleImport aMarkerStyle( GetImport() );
279     aMarkerStyle.importXML( xAttrList, maAny, maStrName );
280 }
281 
282 XMLMarkerStyleContext::~XMLMarkerStyleContext()
283 {
284 }
285 
286 void XMLMarkerStyleContext::EndElement()
287 {
288     uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
289 
290     try
291     {
292         if(xMarker.is())
293         {
294             if( xMarker->hasByName( maStrName ) )
295             {
296                 xMarker->replaceByName( maStrName, maAny );
297             }
298             else
299             {
300                 xMarker->insertByName( maStrName, maAny );
301             }
302         }
303     }
304     catch( container::ElementExistException& )
305     {}
306 }
307 
308 sal_Bool XMLMarkerStyleContext::IsTransient() const
309 {
310     return sal_True;
311 }
312 
313 //////////////////////////////////////////////////////////////////////////////
314 //////////////////////////////////////////////////////////////////////////////
315 
316 TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
317 
318 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
319                                           const OUString& rLName,
320                                           const uno::Reference< xml::sax::XAttributeList >& xAttrList)
321 :   SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
322 {
323     // start import
324     XMLDashStyleImport aDashStyle( GetImport() );
325     aDashStyle.importXML( xAttrList, maAny, maStrName );
326 }
327 
328 XMLDashStyleContext::~XMLDashStyleContext()
329 {
330 }
331 
332 void XMLDashStyleContext::EndElement()
333 {
334     uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
335 
336     try
337     {
338         if(xDashes.is())
339         {
340             if( xDashes->hasByName( maStrName ) )
341             {
342                 xDashes->replaceByName( maStrName, maAny );
343             }
344             else
345             {
346                 xDashes->insertByName( maStrName, maAny );
347             }
348         }
349     }
350     catch( container::ElementExistException& )
351     {}
352 }
353 
354 sal_Bool XMLDashStyleContext::IsTransient() const
355 {
356     return sal_True;
357 }
358