1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_XMLSCRIPT_SOURCE_XMLLIB_IMEXP_IMP_SHARE_HXX
21 #define INCLUDED_XMLSCRIPT_SOURCE_XMLLIB_IMEXP_IMP_SHARE_HXX
23 #include <xmlscript/xmllib_imexp.hxx>
25 #include <cppuhelper/implbase1.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/awt/XControlModel.hpp>
32 #include <com/sun/star/awt/FontDescriptor.hpp>
34 #include <com/sun/star/xml/input/XRoot.hpp>
40 inline sal_Int32
toInt32( OUString
const & rStr
)
43 if (rStr
.getLength() > 2 && rStr
[ 0 ] == '0' && rStr
[ 1 ] == 'x')
45 nVal
= rStr
.copy( 2 ).toUInt32( 16 );
49 nVal
= rStr
.toInt32();
53 inline bool getBoolAttr(
54 bool * pRet
, OUString
const & rAttrName
,
55 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
, sal_Int32 uid
)
58 xAttributes
->getValueByUidName( uid
, rAttrName
) );
59 if (!aValue
.isEmpty())
61 if ( aValue
== "true" )
66 else if ( aValue
== "false" )
73 throw css::xml::sax::SAXException(rAttrName
+ ": no boolean value (true|false)!", css::uno::Reference
< css::uno::XInterface
>(), css::uno::Any() );
79 inline bool getStringAttr(
80 OUString
* pRet
, OUString
const & rAttrName
,
81 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
, sal_Int32 uid
)
83 *pRet
= xAttributes
->getValueByUidName( uid
, rAttrName
);
84 return (!pRet
->isEmpty());
87 inline bool getLongAttr(
88 sal_Int32
* pRet
, OUString
const & rAttrName
,
89 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
,
93 xAttributes
->getValueByUidName( uid
, rAttrName
) );
94 if (!aValue
.isEmpty())
96 *pRet
= toInt32( aValue
);
105 : public ::cppu::WeakImplHelper1
< css::xml::input::XRoot
>
107 friend class LibrariesElement
;
108 friend class LibraryElement
;
110 LibDescriptorArray
* mpLibArray
;
111 LibDescriptor
* mpLibDesc
; // Single library mode
113 sal_Int32 XMLNS_LIBRARY_UID
;
114 sal_Int32 XMLNS_XLINK_UID
;
117 explicit LibraryImport( LibDescriptorArray
* pLibArray
)
118 : mpLibArray(pLibArray
)
120 , XMLNS_LIBRARY_UID(0)
125 // Single library mode
126 explicit LibraryImport(LibDescriptor
* pLibDesc
)
128 , mpLibDesc(pLibDesc
)
129 , XMLNS_LIBRARY_UID(0)
134 virtual ~LibraryImport();
137 virtual void SAL_CALL
startDocument(
138 css::uno::Reference
< css::xml::input::XNamespaceMapping
> const & xNamespaceMapping
)
139 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
140 virtual void SAL_CALL
endDocument()
141 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
142 virtual void SAL_CALL
processingInstruction(
143 OUString
const & rTarget
, OUString
const & rData
)
144 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
145 virtual void SAL_CALL
setDocumentLocator(
146 css::uno::Reference
< css::xml::sax::XLocator
> const & xLocator
)
147 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
148 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startRootElement(
149 sal_Int32 nUid
, OUString
const & rLocalName
,
150 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
)
151 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
155 : public ::cppu::WeakImplHelper1
< css::xml::input::XElement
>
158 LibraryImport
* _pImport
;
159 LibElementBase
* _pParent
;
161 OUString _aLocalName
;
162 css::uno::Reference
< css::xml::input::XAttributes
> _xAttributes
;
166 OUString
const & rLocalName
,
167 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
,
168 LibElementBase
* pParent
, LibraryImport
* pImport
);
169 virtual ~LibElementBase();
172 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
getParent()
173 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
174 virtual OUString SAL_CALL
getLocalName()
175 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
176 virtual sal_Int32 SAL_CALL
getUid()
177 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
178 virtual css::uno::Reference
< css::xml::input::XAttributes
> SAL_CALL
getAttributes()
179 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
180 virtual void SAL_CALL
ignorableWhitespace(
181 OUString
const & rWhitespaces
)
182 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
183 virtual void SAL_CALL
characters( OUString
const & rChars
)
184 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
185 virtual void SAL_CALL
processingInstruction(
186 OUString
const & rTarget
, OUString
const & rData
)
187 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
188 virtual void SAL_CALL
endElement()
189 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
190 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
191 sal_Int32 nUid
, OUString
const & rLocalName
,
192 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
)
193 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
196 class LibrariesElement
: public LibElementBase
198 friend class LibraryElement
;
201 std::vector
< LibDescriptor
> mLibDescriptors
;
204 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
205 sal_Int32 nUid
, OUString
const & rLocalName
,
206 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
)
207 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
208 virtual void SAL_CALL
endElement()
209 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
212 OUString
const & rLocalName
,
213 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
,
214 LibElementBase
* pParent
, LibraryImport
* pImport
)
215 : LibElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
219 class LibraryElement
: public LibElementBase
222 std::vector
< OUString
> mElements
;
226 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
227 sal_Int32 nUid
, OUString
const & rLocalName
,
228 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
)
229 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
230 virtual void SAL_CALL
endElement()
231 throw (css::xml::sax::SAXException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
234 OUString
const & rLocalName
,
235 css::uno::Reference
< css::xml::input::XAttributes
> const & xAttributes
,
236 LibElementBase
* pParent
, LibraryImport
* pImport
)
237 : LibElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
243 #endif // INCLUDED_XMLSCRIPT_SOURCE_XMLLIB_IMEXP_IMP_SHARE_HXX
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */