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