Update ooo320-m1
[ooovba.git] / xmlscript / source / xmllib_imexp / imp_share.hxx
blobd602103fa7f5b12d0dd8a4d30648a384711a9f00
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imp_share.hxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <xmlscript/xmllib_imexp.hxx>
33 #include <cppuhelper/implbase1.hxx>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/container/XNameContainer.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/awt/XControlModel.hpp>
40 #include <com/sun/star/awt/FontDescriptor.hpp>
42 #include <com/sun/star/xml/input/XRoot.hpp>
44 #include <vector>
46 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
49 using namespace ::rtl;
50 using namespace ::std;
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::uno;
54 namespace xmlscript
57 inline sal_Int32 toInt32( OUString const & rStr ) SAL_THROW( () )
59 sal_Int32 nVal;
60 if (rStr.getLength() > 2 && rStr[ 0 ] == '0' && rStr[ 1 ] == 'x')
62 nVal = rStr.copy( 2 ).toInt32( 16 );
64 else
66 nVal = rStr.toInt32();
68 return nVal;
70 inline bool getBoolAttr(
71 sal_Bool * pRet, OUString const & rAttrName,
72 Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
74 OUString aValue(
75 xAttributes->getValueByUidName( uid, rAttrName ) );
76 if (aValue.getLength())
78 if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("true") ))
80 *pRet = sal_True;
81 return true;
83 else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("false") ))
85 *pRet = sal_False;
86 return true;
88 else
90 throw xml::sax::SAXException(
91 rAttrName +
92 OUString( RTL_CONSTASCII_USTRINGPARAM(
93 ": no boolean value (true|false)!") ),
94 Reference< XInterface >(), Any() );
97 return false;
100 inline bool getStringAttr(
101 OUString * pRet, OUString const & rAttrName,
102 Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
104 *pRet = xAttributes->getValueByUidName( uid, rAttrName );
105 return (pRet->getLength() > 0);
108 inline bool getLongAttr(
109 sal_Int32 * pRet, OUString const & rAttrName,
110 Reference< xml::input::XAttributes > const & xAttributes,
111 sal_Int32 uid )
113 OUString aValue(
114 xAttributes->getValueByUidName( uid, rAttrName ) );
115 if (aValue.getLength())
117 *pRet = toInt32( aValue );
118 return true;
120 return false;
123 //==================================================================================================
124 // Library import
126 //==================================================================================================
127 struct LibraryImport
128 : public ::cppu::WeakImplHelper1< xml::input::XRoot >
130 friend class LibrariesElement;
131 friend class LibraryElement;
133 LibDescriptorArray* mpLibArray;
134 LibDescriptor* mpLibDesc; // Single library mode
136 sal_Int32 XMLNS_LIBRARY_UID;
137 sal_Int32 XMLNS_XLINK_UID;
139 public:
140 inline LibraryImport( LibDescriptorArray* pLibArray )
141 SAL_THROW( () )
142 : mpLibArray( pLibArray )
143 , mpLibDesc( NULL ) {}
144 // Single library mode
145 inline LibraryImport( LibDescriptor* pLibDesc )
146 SAL_THROW( () )
147 : mpLibArray( NULL )
148 , mpLibDesc( pLibDesc ) {}
149 virtual ~LibraryImport()
150 SAL_THROW( () );
152 // XRoot
153 virtual void SAL_CALL startDocument(
154 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
155 throw (xml::sax::SAXException, RuntimeException);
156 virtual void SAL_CALL endDocument()
157 throw (xml::sax::SAXException, RuntimeException);
158 virtual void SAL_CALL processingInstruction(
159 OUString const & rTarget, OUString const & rData )
160 throw (xml::sax::SAXException, RuntimeException);
161 virtual void SAL_CALL setDocumentLocator(
162 Reference< xml::sax::XLocator > const & xLocator )
163 throw (xml::sax::SAXException, RuntimeException);
164 virtual Reference< xml::input::XElement > SAL_CALL startRootElement(
165 sal_Int32 nUid, OUString const & rLocalName,
166 Reference< xml::input::XAttributes > const & xAttributes )
167 throw (xml::sax::SAXException, RuntimeException);
170 //==================================================================================================
171 class LibElementBase
172 : public ::cppu::WeakImplHelper1< xml::input::XElement >
174 protected:
175 LibraryImport * _pImport;
176 LibElementBase * _pParent;
178 OUString _aLocalName;
179 Reference< xml::input::XAttributes > _xAttributes;
181 public:
182 LibElementBase(
183 OUString const & rLocalName,
184 Reference< xml::input::XAttributes > const & xAttributes,
185 LibElementBase * pParent, LibraryImport * pImport )
186 SAL_THROW( () );
187 virtual ~LibElementBase()
188 SAL_THROW( () );
190 // XElement
191 virtual Reference< xml::input::XElement > SAL_CALL getParent()
192 throw (RuntimeException);
193 virtual OUString SAL_CALL getLocalName()
194 throw (RuntimeException);
195 virtual sal_Int32 SAL_CALL getUid()
196 throw (RuntimeException);
197 virtual Reference< xml::input::XAttributes > SAL_CALL getAttributes()
198 throw (RuntimeException);
199 virtual void SAL_CALL ignorableWhitespace(
200 OUString const & rWhitespaces )
201 throw (xml::sax::SAXException, RuntimeException);
202 virtual void SAL_CALL characters( OUString const & rChars )
203 throw (xml::sax::SAXException, RuntimeException);
204 virtual void SAL_CALL processingInstruction(
205 OUString const & rTarget, OUString const & rData )
206 throw (xml::sax::SAXException, RuntimeException);
207 virtual void SAL_CALL endElement()
208 throw (xml::sax::SAXException, RuntimeException);
209 virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
210 sal_Int32 nUid, OUString const & rLocalName,
211 Reference< xml::input::XAttributes > const & xAttributes )
212 throw (xml::sax::SAXException, RuntimeException);
215 //==================================================================================================
217 class LibrariesElement : public LibElementBase
219 friend class LibraryElement;
221 protected:
222 vector< LibDescriptor > mLibDescriptors;
224 public:
225 virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
226 sal_Int32 nUid, OUString const & rLocalName,
227 Reference< xml::input::XAttributes > const & xAttributes )
228 throw (xml::sax::SAXException, RuntimeException);
229 virtual void SAL_CALL endElement()
230 throw (xml::sax::SAXException, RuntimeException);
232 LibrariesElement(
233 OUString const & rLocalName,
234 Reference< xml::input::XAttributes > const & xAttributes,
235 LibElementBase * pParent, LibraryImport * pImport )
236 SAL_THROW( () )
237 : LibElementBase( rLocalName, xAttributes, pParent, pImport )
241 //==================================================================================================
243 class LibraryElement : public LibElementBase
245 protected:
246 vector< OUString > mElements;
248 public:
250 virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
251 sal_Int32 nUid, OUString const & rLocalName,
252 Reference< xml::input::XAttributes > const & xAttributes )
253 throw (xml::sax::SAXException, RuntimeException);
254 virtual void SAL_CALL endElement()
255 throw (xml::sax::SAXException, RuntimeException);
257 LibraryElement(
258 OUString const & rLocalName,
259 Reference< xml::input::XAttributes > const & xAttributes,
260 LibElementBase * pParent, LibraryImport * pImport )
261 SAL_THROW( () )
262 : LibElementBase( rLocalName, xAttributes, pParent, pImport )