1*05236b1aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*05236b1aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*05236b1aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*05236b1aSAndrew Rist * distributed with this work for additional information 6*05236b1aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*05236b1aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*05236b1aSAndrew Rist * "License"); you may not use this file except in compliance 9*05236b1aSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*05236b1aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*05236b1aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*05236b1aSAndrew Rist * software distributed under the License is distributed on an 15*05236b1aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*05236b1aSAndrew Rist * KIND, either express or implied. See the License for the 17*05236b1aSAndrew Rist * specific language governing permissions and limitations 18*05236b1aSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*05236b1aSAndrew Rist *************************************************************/ 21*05236b1aSAndrew Rist 22*05236b1aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <xmlscript/xmllib_imexp.hxx> 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp> 33cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <com/sun/star/xml/input/XRoot.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <vector> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::rtl; 43cdf0e10cSrcweir using namespace ::std; 44cdf0e10cSrcweir using namespace ::com::sun::star; 45cdf0e10cSrcweir using namespace ::com::sun::star::uno; 46cdf0e10cSrcweir 47cdf0e10cSrcweir namespace xmlscript 48cdf0e10cSrcweir { 49cdf0e10cSrcweir // 50cdf0e10cSrcweir inline sal_Int32 toInt32( OUString const & rStr ) SAL_THROW( () ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir sal_Int32 nVal; 53cdf0e10cSrcweir if (rStr.getLength() > 2 && rStr[ 0 ] == '0' && rStr[ 1 ] == 'x') 54cdf0e10cSrcweir { 55cdf0e10cSrcweir nVal = rStr.copy( 2 ).toInt32( 16 ); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir else 58cdf0e10cSrcweir { 59cdf0e10cSrcweir nVal = rStr.toInt32(); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir return nVal; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir inline bool getBoolAttr( 64cdf0e10cSrcweir sal_Bool * pRet, OUString const & rAttrName, 65cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir OUString aValue( 68cdf0e10cSrcweir xAttributes->getValueByUidName( uid, rAttrName ) ); 69cdf0e10cSrcweir if (aValue.getLength()) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("true") )) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir *pRet = sal_True; 74cdf0e10cSrcweir return true; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("false") )) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir *pRet = sal_False; 79cdf0e10cSrcweir return true; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir else 82cdf0e10cSrcweir { 83cdf0e10cSrcweir throw xml::sax::SAXException( 84cdf0e10cSrcweir rAttrName + 85cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( 86cdf0e10cSrcweir ": no boolean value (true|false)!") ), 87cdf0e10cSrcweir Reference< XInterface >(), Any() ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir } 90cdf0e10cSrcweir return false; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir inline bool getStringAttr( 94cdf0e10cSrcweir OUString * pRet, OUString const & rAttrName, 95cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir *pRet = xAttributes->getValueByUidName( uid, rAttrName ); 98cdf0e10cSrcweir return (pRet->getLength() > 0); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir inline bool getLongAttr( 102cdf0e10cSrcweir sal_Int32 * pRet, OUString const & rAttrName, 103cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 104cdf0e10cSrcweir sal_Int32 uid ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir OUString aValue( 107cdf0e10cSrcweir xAttributes->getValueByUidName( uid, rAttrName ) ); 108cdf0e10cSrcweir if (aValue.getLength()) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir *pRet = toInt32( aValue ); 111cdf0e10cSrcweir return true; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir return false; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir //================================================================================================== 117cdf0e10cSrcweir // Library import 118cdf0e10cSrcweir 119cdf0e10cSrcweir //================================================================================================== 120cdf0e10cSrcweir struct LibraryImport 121cdf0e10cSrcweir : public ::cppu::WeakImplHelper1< xml::input::XRoot > 122cdf0e10cSrcweir { 123cdf0e10cSrcweir friend class LibrariesElement; 124cdf0e10cSrcweir friend class LibraryElement; 125cdf0e10cSrcweir 126cdf0e10cSrcweir LibDescriptorArray* mpLibArray; 127cdf0e10cSrcweir LibDescriptor* mpLibDesc; // Single library mode 128cdf0e10cSrcweir 129cdf0e10cSrcweir sal_Int32 XMLNS_LIBRARY_UID; 130cdf0e10cSrcweir sal_Int32 XMLNS_XLINK_UID; 131cdf0e10cSrcweir 132cdf0e10cSrcweir public: 133cdf0e10cSrcweir inline LibraryImport( LibDescriptorArray* pLibArray ) 134cdf0e10cSrcweir SAL_THROW( () ) 135cdf0e10cSrcweir : mpLibArray( pLibArray ) 136cdf0e10cSrcweir , mpLibDesc( NULL ) {} 137cdf0e10cSrcweir // Single library mode 138cdf0e10cSrcweir inline LibraryImport( LibDescriptor* pLibDesc ) 139cdf0e10cSrcweir SAL_THROW( () ) 140cdf0e10cSrcweir : mpLibArray( NULL ) 141cdf0e10cSrcweir , mpLibDesc( pLibDesc ) {} 142cdf0e10cSrcweir virtual ~LibraryImport() 143cdf0e10cSrcweir SAL_THROW( () ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir // XRoot 146cdf0e10cSrcweir virtual void SAL_CALL startDocument( 147cdf0e10cSrcweir Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping ) 148cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 149cdf0e10cSrcweir virtual void SAL_CALL endDocument() 150cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 151cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 152cdf0e10cSrcweir OUString const & rTarget, OUString const & rData ) 153cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 154cdf0e10cSrcweir virtual void SAL_CALL setDocumentLocator( 155cdf0e10cSrcweir Reference< xml::sax::XLocator > const & xLocator ) 156cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 157cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startRootElement( 158cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 159cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 160cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 161cdf0e10cSrcweir }; 162cdf0e10cSrcweir 163cdf0e10cSrcweir //================================================================================================== 164cdf0e10cSrcweir class LibElementBase 165cdf0e10cSrcweir : public ::cppu::WeakImplHelper1< xml::input::XElement > 166cdf0e10cSrcweir { 167cdf0e10cSrcweir protected: 168cdf0e10cSrcweir LibraryImport * _pImport; 169cdf0e10cSrcweir LibElementBase * _pParent; 170cdf0e10cSrcweir 171cdf0e10cSrcweir OUString _aLocalName; 172cdf0e10cSrcweir Reference< xml::input::XAttributes > _xAttributes; 173cdf0e10cSrcweir 174cdf0e10cSrcweir public: 175cdf0e10cSrcweir LibElementBase( 176cdf0e10cSrcweir OUString const & rLocalName, 177cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 178cdf0e10cSrcweir LibElementBase * pParent, LibraryImport * pImport ) 179cdf0e10cSrcweir SAL_THROW( () ); 180cdf0e10cSrcweir virtual ~LibElementBase() 181cdf0e10cSrcweir SAL_THROW( () ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir // XElement 184cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL getParent() 185cdf0e10cSrcweir throw (RuntimeException); 186cdf0e10cSrcweir virtual OUString SAL_CALL getLocalName() 187cdf0e10cSrcweir throw (RuntimeException); 188cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getUid() 189cdf0e10cSrcweir throw (RuntimeException); 190cdf0e10cSrcweir virtual Reference< xml::input::XAttributes > SAL_CALL getAttributes() 191cdf0e10cSrcweir throw (RuntimeException); 192cdf0e10cSrcweir virtual void SAL_CALL ignorableWhitespace( 193cdf0e10cSrcweir OUString const & rWhitespaces ) 194cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 195cdf0e10cSrcweir virtual void SAL_CALL characters( OUString const & rChars ) 196cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 197cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 198cdf0e10cSrcweir OUString const & rTarget, OUString const & rData ) 199cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 200cdf0e10cSrcweir virtual void SAL_CALL endElement() 201cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 202cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startChildElement( 203cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 204cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 205cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 206cdf0e10cSrcweir }; 207cdf0e10cSrcweir 208cdf0e10cSrcweir //================================================================================================== 209cdf0e10cSrcweir 210cdf0e10cSrcweir class LibrariesElement : public LibElementBase 211cdf0e10cSrcweir { 212cdf0e10cSrcweir friend class LibraryElement; 213cdf0e10cSrcweir 214cdf0e10cSrcweir protected: 215cdf0e10cSrcweir vector< LibDescriptor > mLibDescriptors; 216cdf0e10cSrcweir 217cdf0e10cSrcweir public: 218cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startChildElement( 219cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 220cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 221cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 222cdf0e10cSrcweir virtual void SAL_CALL endElement() 223cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 224cdf0e10cSrcweir 225cdf0e10cSrcweir LibrariesElement( 226cdf0e10cSrcweir OUString const & rLocalName, 227cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 228cdf0e10cSrcweir LibElementBase * pParent, LibraryImport * pImport ) 229cdf0e10cSrcweir SAL_THROW( () ) 230cdf0e10cSrcweir : LibElementBase( rLocalName, xAttributes, pParent, pImport ) 231cdf0e10cSrcweir {} 232cdf0e10cSrcweir }; 233cdf0e10cSrcweir 234cdf0e10cSrcweir //================================================================================================== 235cdf0e10cSrcweir 236cdf0e10cSrcweir class LibraryElement : public LibElementBase 237cdf0e10cSrcweir { 238cdf0e10cSrcweir protected: 239cdf0e10cSrcweir vector< OUString > mElements; 240cdf0e10cSrcweir 241cdf0e10cSrcweir public: 242cdf0e10cSrcweir 243cdf0e10cSrcweir virtual Reference< xml::input::XElement > SAL_CALL startChildElement( 244cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName, 245cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes ) 246cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 247cdf0e10cSrcweir virtual void SAL_CALL endElement() 248cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 249cdf0e10cSrcweir 250cdf0e10cSrcweir LibraryElement( 251cdf0e10cSrcweir OUString const & rLocalName, 252cdf0e10cSrcweir Reference< xml::input::XAttributes > const & xAttributes, 253cdf0e10cSrcweir LibElementBase * pParent, LibraryImport * pImport ) 254cdf0e10cSrcweir SAL_THROW( () ) 255cdf0e10cSrcweir : LibElementBase( rLocalName, xAttributes, pParent, pImport ) 256cdf0e10cSrcweir {} 257cdf0e10cSrcweir }; 258cdf0e10cSrcweir 259cdf0e10cSrcweir } 260