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