1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imp_share.hxx,v $
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>
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
;
57 inline sal_Int32
toInt32( OUString
const & rStr
) SAL_THROW( () )
60 if (rStr
.getLength() > 2 && rStr
[ 0 ] == '0' && rStr
[ 1 ] == 'x')
62 nVal
= rStr
.copy( 2 ).toInt32( 16 );
66 nVal
= rStr
.toInt32();
70 inline bool getBoolAttr(
71 sal_Bool
* pRet
, OUString
const & rAttrName
,
72 Reference
< xml::input::XAttributes
> const & xAttributes
, sal_Int32 uid
)
75 xAttributes
->getValueByUidName( uid
, rAttrName
) );
76 if (aValue
.getLength())
78 if (aValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("true") ))
83 else if (aValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("false") ))
90 throw xml::sax::SAXException(
92 OUString( RTL_CONSTASCII_USTRINGPARAM(
93 ": no boolean value (true|false)!") ),
94 Reference
< XInterface
>(), Any() );
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
,
114 xAttributes
->getValueByUidName( uid
, rAttrName
) );
115 if (aValue
.getLength())
117 *pRet
= toInt32( aValue
);
123 //==================================================================================================
126 //==================================================================================================
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
;
140 inline LibraryImport( LibDescriptorArray
* pLibArray
)
142 : mpLibArray( pLibArray
)
143 , mpLibDesc( NULL
) {}
144 // Single library mode
145 inline LibraryImport( LibDescriptor
* pLibDesc
)
148 , mpLibDesc( pLibDesc
) {}
149 virtual ~LibraryImport()
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 //==================================================================================================
172 : public ::cppu::WeakImplHelper1
< xml::input::XElement
>
175 LibraryImport
* _pImport
;
176 LibElementBase
* _pParent
;
178 OUString _aLocalName
;
179 Reference
< xml::input::XAttributes
> _xAttributes
;
183 OUString
const & rLocalName
,
184 Reference
< xml::input::XAttributes
> const & xAttributes
,
185 LibElementBase
* pParent
, LibraryImport
* pImport
)
187 virtual ~LibElementBase()
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
;
222 vector
< LibDescriptor
> mLibDescriptors
;
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
);
233 OUString
const & rLocalName
,
234 Reference
< xml::input::XAttributes
> const & xAttributes
,
235 LibElementBase
* pParent
, LibraryImport
* pImport
)
237 : LibElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
241 //==================================================================================================
243 class LibraryElement
: public LibElementBase
246 vector
< OUString
> mElements
;
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
);
258 OUString
const & rLocalName
,
259 Reference
< xml::input::XAttributes
> const & xAttributes
,
260 LibElementBase
* pParent
, LibraryImport
* pImport
)
262 : LibElementBase( rLocalName
, xAttributes
, pParent
, pImport
)