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 #include <xmlscript/xmllib_imexp.hxx> 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <com/sun/star/xml/input/XRoot.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <vector> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::rtl; 47*cdf0e10cSrcweir using namespace ::std; 48*cdf0e10cSrcweir using namespace ::com::sun::star; 49*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir namespace xmlscript 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir // 54*cdf0e10cSrcweir inline sal_Int32 toInt32( OUString const & rStr ) SAL_THROW( () ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir sal_Int32 nVal; 57*cdf0e10cSrcweir if (rStr.getLength() > 2 && rStr[ 0 ] == '0' && rStr[ 1 ] == 'x') 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir nVal = rStr.copy( 2 ).toInt32( 16 ); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir else 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir nVal = rStr.toInt32(); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir return nVal; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir inline bool getBoolAttr( 68*cdf0e10cSrcweir sal_Bool * pRet, OUString const & rAttrName, 69*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir OUString aValue( 72*cdf0e10cSrcweir xAttributes->getValueByUidName( uid, rAttrName ) ); 73*cdf0e10cSrcweir if (aValue.getLength()) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("true") )) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir *pRet = sal_True; 78*cdf0e10cSrcweir return true; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("false") )) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir *pRet = sal_False; 83*cdf0e10cSrcweir return true; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir else 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir throw xml::sax::SAXException( 88*cdf0e10cSrcweir rAttrName + 89*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( 90*cdf0e10cSrcweir ": no boolean value (true|false)!") ), 91*cdf0e10cSrcweir Reference< XInterface >(), Any() ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir return false; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir inline bool getStringAttr( 98*cdf0e10cSrcweir OUString * pRet, OUString const & rAttrName, 99*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir *pRet = xAttributes->getValueByUidName( uid, rAttrName ); 102*cdf0e10cSrcweir return (pRet->getLength() > 0); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir inline bool getLongAttr( 106*cdf0e10cSrcweir sal_Int32 * pRet, OUString const & rAttrName, 107*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 108*cdf0e10cSrcweir sal_Int32 uid ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir OUString aValue( 111*cdf0e10cSrcweir xAttributes->getValueByUidName( uid, rAttrName ) ); 112*cdf0e10cSrcweir if (aValue.getLength()) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir *pRet = toInt32( aValue ); 115*cdf0e10cSrcweir return true; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir return false; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir //================================================================================================== 121*cdf0e10cSrcweir // Library import 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir //================================================================================================== 124*cdf0e10cSrcweir struct LibraryImport 125*cdf0e10cSrcweir : public ::cppu::WeakImplHelper1< xml::input::XRoot > 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir friend class LibrariesElement; 128*cdf0e10cSrcweir friend class LibraryElement; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir LibDescriptorArray* mpLibArray; 131*cdf0e10cSrcweir LibDescriptor* mpLibDesc; // Single library mode 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir sal_Int32 XMLNS_LIBRARY_UID; 134*cdf0e10cSrcweir sal_Int32 XMLNS_XLINK_UID; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir public: 137*cdf0e10cSrcweir inline LibraryImport( LibDescriptorArray* pLibArray ) 138*cdf0e10cSrcweir SAL_THROW( () ) 139*cdf0e10cSrcweir : mpLibArray( pLibArray ) 140*cdf0e10cSrcweir , mpLibDesc( NULL ) {} 141*cdf0e10cSrcweir // Single library mode 142*cdf0e10cSrcweir inline LibraryImport( LibDescriptor* pLibDesc ) 143*cdf0e10cSrcweir SAL_THROW( () ) 144*cdf0e10cSrcweir : mpLibArray( NULL ) 145*cdf0e10cSrcweir , mpLibDesc( pLibDesc ) {} 146*cdf0e10cSrcweir virtual ~LibraryImport() 147*cdf0e10cSrcweir SAL_THROW( () ); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // XRoot 150*cdf0e10cSrcweir virtual void SAL_CALL startDocument( 151*cdf0e10cSrcweir Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping ) 152*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 153*cdf0e10cSrcweir virtual void SAL_CALL endDocument() 154*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 155*cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 156*cdf0e10cSrcweir OUString const & rTarget, OUString const & rData ) 157*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 158*cdf0e10cSrcweir virtual void SAL_CALL setDocumentLocator( 159*cdf0e10cSrcweir Reference< xml::sax::XLocator > const & xLocator ) 160*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 161*cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startRootElement( 162*cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 163*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 164*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 165*cdf0e10cSrcweir }; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir //================================================================================================== 168*cdf0e10cSrcweir class LibElementBase 169*cdf0e10cSrcweir : public ::cppu::WeakImplHelper1< xml::input::XElement > 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir protected: 172*cdf0e10cSrcweir LibraryImport * _pImport; 173*cdf0e10cSrcweir LibElementBase * _pParent; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir OUString _aLocalName; 176*cdf0e10cSrcweir Reference< xml::input::XAttributes > _xAttributes; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir public: 179*cdf0e10cSrcweir LibElementBase( 180*cdf0e10cSrcweir OUString const & rLocalName, 181*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 182*cdf0e10cSrcweir LibElementBase * pParent, LibraryImport * pImport ) 183*cdf0e10cSrcweir SAL_THROW( () ); 184*cdf0e10cSrcweir virtual ~LibElementBase() 185*cdf0e10cSrcweir SAL_THROW( () ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // XElement 188*cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL getParent() 189*cdf0e10cSrcweir throw (RuntimeException); 190*cdf0e10cSrcweir virtual OUString SAL_CALL getLocalName() 191*cdf0e10cSrcweir throw (RuntimeException); 192*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getUid() 193*cdf0e10cSrcweir throw (RuntimeException); 194*cdf0e10cSrcweir virtual Reference< xml::input::XAttributes > SAL_CALL getAttributes() 195*cdf0e10cSrcweir throw (RuntimeException); 196*cdf0e10cSrcweir virtual void SAL_CALL ignorableWhitespace( 197*cdf0e10cSrcweir OUString const & rWhitespaces ) 198*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 199*cdf0e10cSrcweir virtual void SAL_CALL characters( OUString const & rChars ) 200*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 201*cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 202*cdf0e10cSrcweir OUString const & rTarget, OUString const & rData ) 203*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 204*cdf0e10cSrcweir virtual void SAL_CALL endElement() 205*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 206*cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startChildElement( 207*cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 208*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 209*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 210*cdf0e10cSrcweir }; 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //================================================================================================== 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir class LibrariesElement : public LibElementBase 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir friend class LibraryElement; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir protected: 219*cdf0e10cSrcweir vector< LibDescriptor > mLibDescriptors; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir public: 222*cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startChildElement( 223*cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 224*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 225*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 226*cdf0e10cSrcweir virtual void SAL_CALL endElement() 227*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir LibrariesElement( 230*cdf0e10cSrcweir OUString const & rLocalName, 231*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 232*cdf0e10cSrcweir LibElementBase * pParent, LibraryImport * pImport ) 233*cdf0e10cSrcweir SAL_THROW( () ) 234*cdf0e10cSrcweir : LibElementBase( rLocalName, xAttributes, pParent, pImport ) 235*cdf0e10cSrcweir {} 236*cdf0e10cSrcweir }; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //================================================================================================== 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir class LibraryElement : public LibElementBase 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir protected: 243*cdf0e10cSrcweir vector< OUString > mElements; 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir public: 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startChildElement( 248*cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 249*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 250*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 251*cdf0e10cSrcweir virtual void SAL_CALL endElement() 252*cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir LibraryElement( 255*cdf0e10cSrcweir OUString const & rLocalName, 256*cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 257*cdf0e10cSrcweir LibElementBase * pParent, LibraryImport * pImport ) 258*cdf0e10cSrcweir SAL_THROW( () ) 259*cdf0e10cSrcweir : LibElementBase( rLocalName, xAttributes, pParent, pImport ) 260*cdf0e10cSrcweir {} 261*cdf0e10cSrcweir }; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir } 264