Bump for 4.0-15
[LibreOffice.git] / xmlscript / source / xmllib_imexp / imp_share.hxx
blobbbeeea6bcc3171af904c8abaa2057666f1d6a54b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xmlscript/xmllib_imexp.hxx>
22 #include <cppuhelper/implbase1.hxx>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/awt/XControlModel.hpp>
29 #include <com/sun/star/awt/FontDescriptor.hpp>
31 #include <com/sun/star/xml/input/XRoot.hpp>
33 #include <vector>
36 using namespace ::rtl;
37 using namespace ::std;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
41 namespace xmlscript
43 inline sal_Int32 toInt32( OUString const & rStr ) SAL_THROW(())
45 sal_Int32 nVal;
46 if (rStr.getLength() > 2 && rStr[ 0 ] == '0' && rStr[ 1 ] == 'x')
48 nVal = rStr.copy( 2 ).toInt32( 16 );
50 else
52 nVal = rStr.toInt32();
54 return nVal;
56 inline bool getBoolAttr(
57 sal_Bool * pRet, OUString const & rAttrName,
58 Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
60 OUString aValue(
61 xAttributes->getValueByUidName( uid, rAttrName ) );
62 if (!aValue.isEmpty())
64 if ( aValue == "true" )
66 *pRet = sal_True;
67 return true;
69 else if ( aValue == "false" )
71 *pRet = sal_False;
72 return true;
74 else
76 throw xml::sax::SAXException(rAttrName + ": no boolean value (true|false)!", Reference< XInterface >(), Any() );
79 return false;
82 inline bool getStringAttr(
83 OUString * pRet, OUString const & rAttrName,
84 Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
86 *pRet = xAttributes->getValueByUidName( uid, rAttrName );
87 return (!pRet->isEmpty());
90 inline bool getLongAttr(
91 sal_Int32 * pRet, OUString const & rAttrName,
92 Reference< xml::input::XAttributes > const & xAttributes,
93 sal_Int32 uid )
95 OUString aValue(
96 xAttributes->getValueByUidName( uid, rAttrName ) );
97 if (!aValue.isEmpty())
99 *pRet = toInt32( aValue );
100 return true;
102 return false;
105 //==================================================================================================
106 // Library import
108 //==================================================================================================
109 struct LibraryImport
110 : public ::cppu::WeakImplHelper1< xml::input::XRoot >
112 friend class LibrariesElement;
113 friend class LibraryElement;
115 LibDescriptorArray* mpLibArray;
116 LibDescriptor* mpLibDesc; // Single library mode
118 sal_Int32 XMLNS_LIBRARY_UID;
119 sal_Int32 XMLNS_XLINK_UID;
121 public:
122 inline LibraryImport( LibDescriptorArray* pLibArray )
123 SAL_THROW(())
124 : mpLibArray( pLibArray )
125 , mpLibDesc( NULL ) {}
126 // Single library mode
127 inline LibraryImport( LibDescriptor* pLibDesc )
128 SAL_THROW(())
129 : mpLibArray( NULL )
130 , mpLibDesc( pLibDesc ) {}
131 virtual ~LibraryImport()
132 SAL_THROW(());
134 // XRoot
135 virtual void SAL_CALL startDocument(
136 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
137 throw (xml::sax::SAXException, RuntimeException);
138 virtual void SAL_CALL endDocument()
139 throw (xml::sax::SAXException, RuntimeException);
140 virtual void SAL_CALL processingInstruction(
141 OUString const & rTarget, OUString const & rData )
142 throw (xml::sax::SAXException, RuntimeException);
143 virtual void SAL_CALL setDocumentLocator(
144 Reference< xml::sax::XLocator > const & xLocator )
145 throw (xml::sax::SAXException, RuntimeException);
146 virtual Reference< xml::input::XElement > SAL_CALL startRootElement(
147 sal_Int32 nUid, OUString const & rLocalName,
148 Reference< xml::input::XAttributes > const & xAttributes )
149 throw (xml::sax::SAXException, RuntimeException);
152 //==================================================================================================
153 class LibElementBase
154 : public ::cppu::WeakImplHelper1< xml::input::XElement >
156 protected:
157 LibraryImport * _pImport;
158 LibElementBase * _pParent;
160 OUString _aLocalName;
161 Reference< xml::input::XAttributes > _xAttributes;
163 public:
164 LibElementBase(
165 OUString const & rLocalName,
166 Reference< xml::input::XAttributes > const & xAttributes,
167 LibElementBase * pParent, LibraryImport * pImport )
168 SAL_THROW(());
169 virtual ~LibElementBase()
170 SAL_THROW(());
172 // XElement
173 virtual Reference< xml::input::XElement > SAL_CALL getParent()
174 throw (RuntimeException);
175 virtual OUString SAL_CALL getLocalName()
176 throw (RuntimeException);
177 virtual sal_Int32 SAL_CALL getUid()
178 throw (RuntimeException);
179 virtual Reference< xml::input::XAttributes > SAL_CALL getAttributes()
180 throw (RuntimeException);
181 virtual void SAL_CALL ignorableWhitespace(
182 OUString const & rWhitespaces )
183 throw (xml::sax::SAXException, RuntimeException);
184 virtual void SAL_CALL characters( OUString const & rChars )
185 throw (xml::sax::SAXException, RuntimeException);
186 virtual void SAL_CALL processingInstruction(
187 OUString const & rTarget, OUString const & rData )
188 throw (xml::sax::SAXException, RuntimeException);
189 virtual void SAL_CALL endElement()
190 throw (xml::sax::SAXException, RuntimeException);
191 virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
192 sal_Int32 nUid, OUString const & rLocalName,
193 Reference< xml::input::XAttributes > const & xAttributes )
194 throw (xml::sax::SAXException, RuntimeException);
197 //==================================================================================================
199 class LibrariesElement : public LibElementBase
201 friend class LibraryElement;
203 protected:
204 vector< LibDescriptor > mLibDescriptors;
206 public:
207 virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
208 sal_Int32 nUid, OUString const & rLocalName,
209 Reference< xml::input::XAttributes > const & xAttributes )
210 throw (xml::sax::SAXException, RuntimeException);
211 virtual void SAL_CALL endElement()
212 throw (xml::sax::SAXException, RuntimeException);
214 LibrariesElement(
215 OUString const & rLocalName,
216 Reference< xml::input::XAttributes > const & xAttributes,
217 LibElementBase * pParent, LibraryImport * pImport )
218 SAL_THROW(())
219 : LibElementBase( rLocalName, xAttributes, pParent, pImport )
223 //==================================================================================================
225 class LibraryElement : public LibElementBase
227 protected:
228 vector< OUString > mElements;
230 public:
232 virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
233 sal_Int32 nUid, OUString const & rLocalName,
234 Reference< xml::input::XAttributes > const & xAttributes )
235 throw (xml::sax::SAXException, RuntimeException);
236 virtual void SAL_CALL endElement()
237 throw (xml::sax::SAXException, RuntimeException);
239 LibraryElement(
240 OUString const & rLocalName,
241 Reference< xml::input::XAttributes > const & xAttributes,
242 LibElementBase * pParent, LibraryImport * pImport )
243 SAL_THROW(())
244 : LibElementBase( rLocalName, xAttributes, pParent, pImport )
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */