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 #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>
36 using namespace ::rtl
;
37 using namespace ::std
;
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
43 inline sal_Int32
toInt32( OUString
const & rStr
) SAL_THROW(())
46 if (rStr
.getLength() > 2 && rStr
[ 0 ] == '0' && rStr
[ 1 ] == 'x')
48 nVal
= rStr
.copy( 2 ).toInt32( 16 );
52 nVal
= rStr
.toInt32();
56 inline bool getBoolAttr(
57 sal_Bool
* pRet
, OUString
const & rAttrName
,
58 Reference
< xml::input::XAttributes
> const & xAttributes
, sal_Int32 uid
)
61 xAttributes
->getValueByUidName( uid
, rAttrName
) );
62 if (!aValue
.isEmpty())
64 if ( aValue
== "true" )
69 else if ( aValue
== "false" )
76 throw xml::sax::SAXException(rAttrName
+ ": no boolean value (true|false)!", Reference
< XInterface
>(), Any() );
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
,
96 xAttributes
->getValueByUidName( uid
, rAttrName
) );
97 if (!aValue
.isEmpty())
99 *pRet
= toInt32( aValue
);
105 //==================================================================================================
108 //==================================================================================================
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
;
122 inline LibraryImport( LibDescriptorArray
* pLibArray
)
124 : mpLibArray( pLibArray
)
125 , mpLibDesc( NULL
) {}
126 // Single library mode
127 inline LibraryImport( LibDescriptor
* pLibDesc
)
130 , mpLibDesc( pLibDesc
) {}
131 virtual ~LibraryImport()
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 //==================================================================================================
154 : public ::cppu::WeakImplHelper1
< xml::input::XElement
>
157 LibraryImport
* _pImport
;
158 LibElementBase
* _pParent
;
160 OUString _aLocalName
;
161 Reference
< xml::input::XAttributes
> _xAttributes
;
165 OUString
const & rLocalName
,
166 Reference
< xml::input::XAttributes
> const & xAttributes
,
167 LibElementBase
* pParent
, LibraryImport
* pImport
)
169 virtual ~LibElementBase()
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
;
204 vector
< LibDescriptor
> mLibDescriptors
;
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
);
215 OUString
const & rLocalName
,
216 Reference
< xml::input::XAttributes
> const & xAttributes
,
217 LibElementBase
* pParent
, LibraryImport
* pImport
)
219 : LibElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
223 //==================================================================================================
225 class LibraryElement
: public LibElementBase
228 vector
< OUString
> mElements
;
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
);
240 OUString
const & rLocalName
,
241 Reference
< xml::input::XAttributes
> const & xAttributes
,
242 LibElementBase
* pParent
, LibraryImport
* pImport
)
244 : LibElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */