1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <com/sun/star/document/XGraphicObjectResolver.hpp> 28cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 29cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataControl.hpp> 30cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 31cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp> 32cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 33cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 34cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 35cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> 36cdf0e10cSrcweir #include <com/sun/star/drawing/LineDash.hpp> 37cdf0e10cSrcweir #include <com/sun/star/awt/Gradient.hpp> 38cdf0e10cSrcweir #include <com/sun/star/drawing/Hatch.hpp> 39cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 40cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_XSEEKABLE_HDL_ 41cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hdl> 42cdf0e10cSrcweir #endif 43cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 44cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 45cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 46cdf0e10cSrcweir #include <sfx2/docfile.hxx> 47cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 48cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 49cdf0e10cSrcweir #include "xmloff/nmspmap.hxx" 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include "xmloff/xmltoken.hxx" 52cdf0e10cSrcweir #include "xmloff/xmlmetae.hxx" 53cdf0e10cSrcweir #include "xmloff/DashStyle.hxx" 54cdf0e10cSrcweir #include "xmloff/GradientStyle.hxx" 55cdf0e10cSrcweir #include "xmloff/HatchStyle.hxx" 56cdf0e10cSrcweir #include "xmloff/ImageStyle.hxx" 57cdf0e10cSrcweir #include "xmloff/MarkerStyle.hxx" 58cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx> 59cdf0e10cSrcweir #include "svx/xmlgrhlp.hxx" 60cdf0e10cSrcweir #include "xmloff/attrlist.hxx" 61cdf0e10cSrcweir 62cdf0e10cSrcweir #include "xmlxtimp.hxx" 63cdf0e10cSrcweir 64cdf0e10cSrcweir using namespace com::sun::star; 65cdf0e10cSrcweir using namespace com::sun::star::container; 66cdf0e10cSrcweir using namespace com::sun::star::document; 67cdf0e10cSrcweir using namespace com::sun::star::uno; 68cdf0e10cSrcweir using namespace com::sun::star::awt; 69cdf0e10cSrcweir using namespace com::sun::star::lang; 70cdf0e10cSrcweir using namespace com::sun::star::xml::sax; 71cdf0e10cSrcweir using namespace ::rtl; 72cdf0e10cSrcweir using namespace ::xmloff::token; 73cdf0e10cSrcweir using namespace cppu; 74cdf0e10cSrcweir 75cdf0e10cSrcweir sal_Char __READONLY_DATA sXML_np__office[] = "__office"; 76cdf0e10cSrcweir sal_Char __READONLY_DATA sXML_np__office_ooo[] = "___office"; 77cdf0e10cSrcweir sal_Char __READONLY_DATA sXML_np__draw[] = "__draw"; 78cdf0e10cSrcweir sal_Char __READONLY_DATA sXML_np__draw_ooo[] = "___draw"; 79cdf0e10cSrcweir sal_Char __READONLY_DATA sXML_np__ooo[] = "__ooo"; 80cdf0e10cSrcweir sal_Char __READONLY_DATA sXML_np__xlink[] = "__xlink"; 81cdf0e10cSrcweir 82cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////// 83cdf0e10cSrcweir 84cdf0e10cSrcweir enum SvxXMLTableImportContextEnum { stice_unknown, stice_color, stice_marker, stice_dash, stice_hatch, stice_gradient, stice_bitmap }; 85cdf0e10cSrcweir 86cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////// 87cdf0e10cSrcweir 88cdf0e10cSrcweir class SvxXMLTableImportContext : public SvXMLImportContext 89cdf0e10cSrcweir { 90cdf0e10cSrcweir public: 91cdf0e10cSrcweir SvxXMLTableImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >& xAttrList, SvxXMLTableImportContextEnum eContext, const uno::Reference< XNameContainer >& xTable, 92cdf0e10cSrcweir sal_Bool bOOoFormat ); 93cdf0e10cSrcweir virtual ~SvxXMLTableImportContext(); 94cdf0e10cSrcweir 95cdf0e10cSrcweir virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir SvxXMLXTableImport& getImport() const { return *(SvxXMLXTableImport*)&GetImport(); } 98cdf0e10cSrcweir 99cdf0e10cSrcweir protected: 100cdf0e10cSrcweir void importColor( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ); 101cdf0e10cSrcweir void importMarker( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ); 102cdf0e10cSrcweir void importDash( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ); 103cdf0e10cSrcweir void importHatch( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ); 104cdf0e10cSrcweir void importGradient( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ); 105cdf0e10cSrcweir void importBitmap( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir private: 108cdf0e10cSrcweir uno::Reference< XNameContainer > mxTable; 109cdf0e10cSrcweir SvxXMLTableImportContextEnum meContext; 110cdf0e10cSrcweir sal_Bool mbOOoFormat; 111cdf0e10cSrcweir }; 112cdf0e10cSrcweir 113cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////// 114cdf0e10cSrcweir 115cdf0e10cSrcweir SvxXMLTableImportContext::SvxXMLTableImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >&, SvxXMLTableImportContextEnum eContext, const uno::Reference< XNameContainer >& xTable, sal_Bool bOOoFormat ) 116cdf0e10cSrcweir : SvXMLImportContext( rImport, nPrfx, rLName ), mxTable( xTable ), meContext( eContext ), 117cdf0e10cSrcweir mbOOoFormat( bOOoFormat ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir SvxXMLTableImportContext::~SvxXMLTableImportContext() 122cdf0e10cSrcweir { 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir SvXMLImportContext *SvxXMLTableImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& rAttrList ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir if( XML_NAMESPACE_DRAW == nPrefix ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir uno::Reference< XAttributeList > xAttrList( rAttrList ); 130cdf0e10cSrcweir if( mbOOoFormat && 131cdf0e10cSrcweir (stice_dash == meContext || stice_hatch == meContext || 132cdf0e10cSrcweir stice_bitmap == meContext) ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList ); 135cdf0e10cSrcweir xAttrList = pAttrList; 136cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 137cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i ); 140cdf0e10cSrcweir OUString aLocalName; 141cdf0e10cSrcweir sal_uInt16 nPrefix_ = 142cdf0e10cSrcweir GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, 143cdf0e10cSrcweir &aLocalName ); 144cdf0e10cSrcweir if( XML_NAMESPACE_XLINK == nPrefix_ && 145cdf0e10cSrcweir stice_bitmap == meContext && 146cdf0e10cSrcweir IsXMLToken( aLocalName, XML_HREF ) ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir const OUString rValue = xAttrList->getValueByIndex( i ); 149cdf0e10cSrcweir if( rValue.getLength() && '#' == rValue[0] ) 150cdf0e10cSrcweir pAttrList->SetValueByIndex( i, rValue.copy( 1 ) ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir else if( XML_NAMESPACE_DRAW == nPrefix_ && 153cdf0e10cSrcweir ( ( stice_dash == meContext && 154cdf0e10cSrcweir (IsXMLToken( aLocalName, XML_DOTS1_LENGTH ) || 155cdf0e10cSrcweir IsXMLToken( aLocalName, XML_DOTS2_LENGTH ) || 156cdf0e10cSrcweir IsXMLToken( aLocalName, XML_DISTANCE )) ) || 157cdf0e10cSrcweir ( stice_hatch == meContext && 158cdf0e10cSrcweir IsXMLToken( aLocalName, XML_HATCH_DISTANCE ) ) ) ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir const OUString rValue = xAttrList->getValueByIndex( i ); 161cdf0e10cSrcweir sal_Int32 nPos = rValue.getLength(); 162cdf0e10cSrcweir while( nPos && rValue[nPos-1] <= ' ' ) 163cdf0e10cSrcweir --nPos; 164cdf0e10cSrcweir if( nPos > 2 && 165cdf0e10cSrcweir ('c'==rValue[nPos-2] || 'C'==rValue[nPos-2]) && 166cdf0e10cSrcweir ('h'==rValue[nPos-1] || 'H'==rValue[nPos-1]) ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir pAttrList->SetValueByIndex( i, rValue.copy( 0, nPos-2 ) ); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir try 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Any aAny; 176cdf0e10cSrcweir OUString aName; 177cdf0e10cSrcweir 178cdf0e10cSrcweir switch( meContext ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir case stice_color: 181cdf0e10cSrcweir importColor( nPrefix, rLocalName, xAttrList, aAny, aName ); 182cdf0e10cSrcweir break; 183cdf0e10cSrcweir case stice_marker: 184cdf0e10cSrcweir importMarker( nPrefix, rLocalName, xAttrList, aAny, aName ); 185cdf0e10cSrcweir break; 186cdf0e10cSrcweir case stice_dash: 187cdf0e10cSrcweir importDash( nPrefix, rLocalName, xAttrList, aAny, aName ); 188cdf0e10cSrcweir break; 189cdf0e10cSrcweir case stice_hatch: 190cdf0e10cSrcweir importHatch( nPrefix, rLocalName, xAttrList, aAny, aName ); 191cdf0e10cSrcweir break; 192cdf0e10cSrcweir case stice_gradient: 193cdf0e10cSrcweir importGradient( nPrefix, rLocalName, xAttrList, aAny, aName ); 194cdf0e10cSrcweir break; 195cdf0e10cSrcweir case stice_bitmap: 196cdf0e10cSrcweir importBitmap( nPrefix, rLocalName, xAttrList, aAny, aName ); 197cdf0e10cSrcweir break; 198cdf0e10cSrcweir case stice_unknown: 199cdf0e10cSrcweir break; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir if( aName.getLength() && aAny.hasValue() ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir if( mxTable->hasByName( aName ) ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir mxTable->replaceByName( aName, aAny ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir else 209cdf0e10cSrcweir { 210cdf0e10cSrcweir mxTable->insertByName( aName, aAny ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir catch( uno::Exception& ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir void SvxXMLTableImportContext::importColor( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir (void)nPrfx; 225cdf0e10cSrcweir (void)rLocalName; 226cdf0e10cSrcweir 227cdf0e10cSrcweir const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 228cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); 231cdf0e10cSrcweir OUString aLocalName; 232cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aLocalName ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir 235cdf0e10cSrcweir if( XML_NAMESPACE_DRAW == nPrefix ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir if( aLocalName == GetXMLToken(XML_NAME) ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir rName = xAttrList->getValueByIndex( i ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else if( aLocalName == GetXMLToken(XML_COLOR) ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir Color aColor; 244cdf0e10cSrcweir SvXMLUnitConverter::convertColor(aColor, xAttrList->getValueByIndex( i )); 245cdf0e10cSrcweir rAny <<= (sal_Int32)aColor.GetColor(); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir void SvxXMLTableImportContext::importMarker( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir (void)nPrfx; 254cdf0e10cSrcweir (void)rLocalName; 255cdf0e10cSrcweir 256cdf0e10cSrcweir try 257cdf0e10cSrcweir { 258cdf0e10cSrcweir XMLMarkerStyleImport aMarkerStyle( GetImport() ); 259cdf0e10cSrcweir aMarkerStyle.importXML( xAttrList, rAny, rName ); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir catch( Exception& ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir DBG_ERROR("SvxXMLTableImportContext::importMarker(), exception caught!"); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir void SvxXMLTableImportContext::importDash( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir (void)nPrfx; 270cdf0e10cSrcweir (void)rLocalName; 271cdf0e10cSrcweir 272cdf0e10cSrcweir try 273cdf0e10cSrcweir { 274cdf0e10cSrcweir XMLDashStyleImport aDashStyle( GetImport() ); 275cdf0e10cSrcweir aDashStyle.importXML( xAttrList, rAny, rName ); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir catch( Exception& ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir DBG_ERROR("SvxXMLTableImportContext::importDash(), exception caught!"); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283cdf0e10cSrcweir void SvxXMLTableImportContext::importHatch( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir (void)nPrfx; 286cdf0e10cSrcweir (void)rLocalName; 287cdf0e10cSrcweir 288cdf0e10cSrcweir try 289cdf0e10cSrcweir { 290cdf0e10cSrcweir XMLHatchStyleImport aHatchStyle( GetImport() ); 291cdf0e10cSrcweir aHatchStyle.importXML( xAttrList, rAny, rName ); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir catch( Exception& ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir DBG_ERROR("SvxXMLTableImportContext::importHatch(), exception caught!"); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir void SvxXMLTableImportContext::importGradient( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir (void)nPrfx; 302cdf0e10cSrcweir (void)rLocalName; 303cdf0e10cSrcweir 304cdf0e10cSrcweir try 305cdf0e10cSrcweir { 306cdf0e10cSrcweir XMLGradientStyleImport aGradientStyle( GetImport() ); 307cdf0e10cSrcweir aGradientStyle.importXML( xAttrList, rAny, rName ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir catch( Exception& ) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir DBG_ERROR("SvxXMLTableImportContext::importGradient(), exception caught!"); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir void SvxXMLTableImportContext::importBitmap( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir (void)nPrfx; 318cdf0e10cSrcweir (void)rLocalName; 319cdf0e10cSrcweir 320cdf0e10cSrcweir try 321cdf0e10cSrcweir { 322cdf0e10cSrcweir XMLImageStyle aImageStyle; 323cdf0e10cSrcweir aImageStyle.importXML( xAttrList, rAny, rName, GetImport() ); 324cdf0e10cSrcweir } 325cdf0e10cSrcweir catch( Exception& ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir DBG_ERROR("SvxXMLTableImportContext::importBitmap(), exception caught!"); 328cdf0e10cSrcweir } 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////// 332cdf0e10cSrcweir 333cdf0e10cSrcweir // #110680# 334cdf0e10cSrcweir SvxXMLXTableImport::SvxXMLXTableImport( 335cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory, 336cdf0e10cSrcweir const uno::Reference< XNameContainer > & rTable, 337cdf0e10cSrcweir uno::Reference< XGraphicObjectResolver >& xGrfResolver ) 338cdf0e10cSrcweir : SvXMLImport(xServiceFactory, 0), 339cdf0e10cSrcweir mrTable( rTable ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir SetGraphicResolver( xGrfResolver ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooo ) ), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO ); 344cdf0e10cSrcweir GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE ); 345cdf0e10cSrcweir GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw ) ), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW ); 346cdf0e10cSrcweir GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xlink ) ), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK ); 347cdf0e10cSrcweir 348cdf0e10cSrcweir // OOo namespaces for reading OOo 1.1 files 349cdf0e10cSrcweir GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office_ooo ) ), 350cdf0e10cSrcweir GetXMLToken(XML_N_OFFICE_OOO), 351cdf0e10cSrcweir XML_NAMESPACE_OFFICE ); 352cdf0e10cSrcweir GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw_ooo ) ), 353cdf0e10cSrcweir GetXMLToken(XML_N_DRAW_OOO), 354cdf0e10cSrcweir XML_NAMESPACE_DRAW ); 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir SvxXMLXTableImport::~SvxXMLXTableImport() throw () 358cdf0e10cSrcweir { 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir sal_Bool SvxXMLXTableImport::load( const OUString& rUrl, const uno::Reference< XNameContainer >& xTable ) throw() 362cdf0e10cSrcweir { 363cdf0e10cSrcweir sal_Bool bRet = sal_True; 364cdf0e10cSrcweir 365cdf0e10cSrcweir uno::Reference< XGraphicObjectResolver > xGrfResolver; 366cdf0e10cSrcweir SvXMLGraphicHelper* pGraphicHelper = 0; 367cdf0e10cSrcweir 368cdf0e10cSrcweir try 369cdf0e10cSrcweir { 370cdf0e10cSrcweir do 371cdf0e10cSrcweir { 372cdf0e10cSrcweir SfxMedium aMedium( rUrl, STREAM_READ | STREAM_NOCREATE, sal_True ); 373cdf0e10cSrcweir 374cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() ); 375cdf0e10cSrcweir if( !xServiceFactory.is() ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir DBG_ERROR( "SvxXMLXTableImport::load: got no service manager" ); 378cdf0e10cSrcweir break; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir uno::Reference< xml::sax::XParser > xParser( xServiceFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ) ) ), uno::UNO_QUERY_THROW ); 382cdf0e10cSrcweir uno::Reference < io::XStream > xIStm; 383cdf0e10cSrcweir uno::Reference< io::XActiveDataSource > xSource; 384cdf0e10cSrcweir 385cdf0e10cSrcweir xml::sax::InputSource aParserInput; 386cdf0e10cSrcweir aParserInput.sSystemId = aMedium.GetName(); 387cdf0e10cSrcweir 388cdf0e10cSrcweir if( aMedium.IsStorage() ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir uno::Reference < embed::XStorage > xStorage( aMedium.GetStorage( sal_False ), uno::UNO_QUERY_THROW ); 391cdf0e10cSrcweir 392cdf0e10cSrcweir const String aContentStmName( RTL_CONSTASCII_USTRINGPARAM( "Content.xml" ) ); 393cdf0e10cSrcweir xIStm.set( xStorage->openStreamElement( aContentStmName, embed::ElementModes::READ ), uno::UNO_QUERY_THROW ); 394cdf0e10cSrcweir if( !xIStm.is() ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir DBG_ERROR( "could not open Content stream" ); 397cdf0e10cSrcweir break; 398cdf0e10cSrcweir } 399cdf0e10cSrcweir 400cdf0e10cSrcweir aParserInput.aInputStream = xIStm->getInputStream(); 401cdf0e10cSrcweir pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_READ ); 402cdf0e10cSrcweir xGrfResolver = pGraphicHelper; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir else 405cdf0e10cSrcweir { 406cdf0e10cSrcweir aParserInput.aInputStream = aMedium.GetInputStream(); 407cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW ); 408cdf0e10cSrcweir xSeek->seek( 0 ); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir if( xSource.is() ) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir uno::Reference< io::XActiveDataControl > xSourceControl( xSource, UNO_QUERY_THROW ); 414cdf0e10cSrcweir xSourceControl->start(); 415cdf0e10cSrcweir } 416cdf0e10cSrcweir 417cdf0e10cSrcweir // #110680# 418cdf0e10cSrcweir // uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTableImport( xTable, xGrfResolver ) ); 419cdf0e10cSrcweir uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTableImport( xServiceFactory, xTable, xGrfResolver ) ); 420cdf0e10cSrcweir 421cdf0e10cSrcweir xParser->setDocumentHandler( xHandler ); 422cdf0e10cSrcweir xParser->parseStream( aParserInput ); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir while(0); 425cdf0e10cSrcweir 426cdf0e10cSrcweir if( pGraphicHelper ) 427cdf0e10cSrcweir SvXMLGraphicHelper::Destroy( pGraphicHelper ); 428cdf0e10cSrcweir } 429cdf0e10cSrcweir catch( uno::Exception& ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir // CL: I disabled this assertion since its an error, but it happens 432cdf0e10cSrcweir // each time you load a document with property tables that are not 433cdf0e10cSrcweir // on the current machine. Maybe a better fix would be to place 434cdf0e10cSrcweir // a file exists check before importing... 435cdf0e10cSrcweir // DBG_ERROR("svx::SvxXMLXTableImport::load(), exception caught!"); 436cdf0e10cSrcweir bRet = sal_False; 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir return bRet; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir SvXMLImportContext *SvxXMLXTableImport::CreateContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir if( XML_NAMESPACE_OOO == nPrefix || 445cdf0e10cSrcweir XML_NAMESPACE_OFFICE == nPrefix ) 446cdf0e10cSrcweir { 447cdf0e10cSrcweir sal_Bool bOOoFormat = (XML_NAMESPACE_OFFICE == nPrefix); 448cdf0e10cSrcweir Type aType = mrTable->getElementType(); 449cdf0e10cSrcweir 450cdf0e10cSrcweir if( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "color-table" ) ) ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir if( aType == ::getCppuType((const sal_Int32*)0) ) 453cdf0e10cSrcweir return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_color, mrTable, bOOoFormat ); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir else if( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "marker-table" ) ) ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir if( aType == ::getCppuType((const drawing::PolyPolygonBezierCoords*)0) ) 458cdf0e10cSrcweir return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_marker, mrTable, bOOoFormat ); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir else if( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "dash-table" ) ) ) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir if( aType == ::getCppuType((const drawing::LineDash*)0) ) 463cdf0e10cSrcweir return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_dash, mrTable, bOOoFormat ); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir else if( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "hatch-table" ) ) ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir if( aType == ::getCppuType((const drawing::Hatch*)0) ) 468cdf0e10cSrcweir return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_hatch, mrTable, bOOoFormat ); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir else if( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "gradient-table" ) ) ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir if( aType == ::getCppuType((const awt::Gradient*)0)) 473cdf0e10cSrcweir return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_gradient, mrTable, bOOoFormat ); 474cdf0e10cSrcweir } 475cdf0e10cSrcweir else if( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "bitmap-table" ) ) ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir if( aType == ::getCppuType((const OUString*)0)) 478cdf0e10cSrcweir return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_bitmap, mrTable, bOOoFormat ); 479cdf0e10cSrcweir } 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir return new SvXMLImportContext( *this, nPrefix, rLocalName ); 483cdf0e10cSrcweir } 484cdf0e10cSrcweir 485