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 <sal/config.h>
22 #include <sal/log.hxx>
24 #include "imp_share.hxx"
25 #include <xml_import.hxx>
26 #include <xmlscript/xmlns.h>
29 using namespace css::uno
;
34 Reference
< xml::input::XElement
> LibElementBase::getParent()
36 return mxParent
.get();
39 OUString
LibElementBase::getLocalName()
44 sal_Int32
LibElementBase::getUid()
46 return mxImport
->XMLNS_LIBRARY_UID
;
49 Reference
< xml::input::XAttributes
> LibElementBase::getAttributes()
54 void LibElementBase::ignorableWhitespace(
55 OUString
const & /*rWhitespaces*/ )
59 void LibElementBase::characters( OUString
const & /*rChars*/ )
61 // not used, all characters ignored
64 void LibElementBase::processingInstruction(
65 OUString
const & /*rTarget*/, OUString
const & /*rData*/ )
69 void LibElementBase::endElement()
72 Reference
< xml::input::XElement
> LibElementBase::startChildElement(
73 sal_Int32
/*nUid*/, OUString
const & /*rLocalName*/,
74 Reference
< xml::input::XAttributes
> const & /*xAttributes*/ )
76 throw xml::sax::SAXException("unexpected element!", Reference
< XInterface
>(), Any() );
79 LibElementBase::LibElementBase(
80 OUString
const & rLocalName
,
81 Reference
< xml::input::XAttributes
> const & xAttributes
,
82 LibElementBase
* pParent
, LibraryImport
* pImport
)
85 , _aLocalName( rLocalName
)
86 , _xAttributes( xAttributes
)
90 LibElementBase::~LibElementBase()
92 SAL_INFO("xmlscript.xmllib", "LibElementBase::~LibElementBase(): " << _aLocalName
);
97 void LibraryImport::startDocument(
98 Reference
< xml::input::XNamespaceMapping
> const & xNamespaceMapping
)
100 XMLNS_LIBRARY_UID
= xNamespaceMapping
->getUidByUri( XMLNS_LIBRARY_URI
);
101 XMLNS_XLINK_UID
= xNamespaceMapping
->getUidByUri( XMLNS_XLINK_URI
);
104 void LibraryImport::endDocument()
108 void LibraryImport::processingInstruction(
109 OUString
const & /*rTarget*/, OUString
const & /*rData*/ )
113 void LibraryImport::setDocumentLocator(
114 Reference
< xml::sax::XLocator
> const & /*xLocator*/ )
118 Reference
< xml::input::XElement
> LibraryImport::startRootElement(
119 sal_Int32 nUid
, OUString
const & rLocalName
,
120 Reference
< xml::input::XAttributes
> const & xAttributes
)
122 if (XMLNS_LIBRARY_UID
!= nUid
)
124 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
126 else if ( mpLibArray
&& rLocalName
== "libraries" )
128 return new LibrariesElement( rLocalName
, xAttributes
, this );
130 else if ( mpLibDesc
&& rLocalName
== "library" )
132 LibDescriptor
& aDesc
= *mpLibDesc
;
133 aDesc
.bLink
= aDesc
.bReadOnly
= aDesc
.bPasswordProtected
= aDesc
.bPreload
= false;
135 aDesc
.aName
= xAttributes
->getValueByUidName(XMLNS_LIBRARY_UID
, "name" );
136 getBoolAttr( &aDesc
.bReadOnly
, "readonly", xAttributes
, XMLNS_LIBRARY_UID
);
137 getBoolAttr( &aDesc
.bPasswordProtected
, "passwordprotected", xAttributes
, XMLNS_LIBRARY_UID
);
138 getBoolAttr( &aDesc
.bPreload
, "preload", xAttributes
, XMLNS_LIBRARY_UID
);
140 return new LibraryElement( rLocalName
, xAttributes
, nullptr, this );
144 throw xml::sax::SAXException( "illegal root element (expected libraries) given: " + rLocalName
, Reference
< XInterface
>(), Any() );
148 LibraryImport::~LibraryImport()
150 SAL_INFO("xmlscript.xmllib", "LibraryImport::~LibraryImport()." );
154 Reference
< xml::input::XElement
> LibrariesElement::startChildElement(
155 sal_Int32 nUid
, OUString
const & rLocalName
,
156 Reference
< xml::input::XAttributes
> const & xAttributes
)
158 if (mxImport
->XMLNS_LIBRARY_UID
!= nUid
)
160 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
163 else if ( rLocalName
== "library" )
166 aDesc
.bLink
= aDesc
.bReadOnly
= aDesc
.bPasswordProtected
= aDesc
.bPreload
= false;
168 aDesc
.aName
= xAttributes
->getValueByUidName(mxImport
->XMLNS_LIBRARY_UID
, "name" );
169 aDesc
.aStorageURL
= xAttributes
->getValueByUidName( mxImport
->XMLNS_XLINK_UID
, "href" );
170 getBoolAttr(&aDesc
.bLink
, "link", xAttributes
, mxImport
->XMLNS_LIBRARY_UID
);
171 getBoolAttr(&aDesc
.bReadOnly
, "readonly", xAttributes
, mxImport
->XMLNS_LIBRARY_UID
);
172 getBoolAttr(&aDesc
.bPasswordProtected
, "passwordprotected", xAttributes
, mxImport
->XMLNS_LIBRARY_UID
);
174 mLibDescriptors
.push_back( aDesc
);
175 return new LibraryElement( rLocalName
, xAttributes
, this, mxImport
.get() );
179 throw xml::sax::SAXException( "expected styles of bulletinboard element!", Reference
< XInterface
>(), Any() );
183 void LibrariesElement::endElement()
185 sal_Int32 nLibCount
= mxImport
->mpLibArray
->mnLibCount
= static_cast<sal_Int32
>(mLibDescriptors
.size());
186 mxImport
->mpLibArray
->mpLibs
.reset( new LibDescriptor
[ nLibCount
] );
188 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
190 const LibDescriptor
& rLib
= mLibDescriptors
[i
];
191 mxImport
->mpLibArray
->mpLibs
[i
] = rLib
;
196 Reference
< xml::input::XElement
> LibraryElement::startChildElement(
197 sal_Int32 nUid
, OUString
const & rLocalName
,
198 Reference
< xml::input::XAttributes
> const & xAttributes
)
200 if (mxImport
->XMLNS_LIBRARY_UID
!= nUid
)
202 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
205 else if ( rLocalName
== "element" )
207 OUString
aValue( xAttributes
->getValueByUidName(mxImport
->XMLNS_LIBRARY_UID
, "name" ) );
208 if (!aValue
.isEmpty())
209 mElements
.push_back( aValue
);
211 return new LibElementBase( rLocalName
, xAttributes
, this, mxImport
.get() );
215 throw xml::sax::SAXException( "expected styles ot bulletinboard element!", Reference
< XInterface
>(), Any() );
219 void LibraryElement::endElement()
221 sal_Int32 nElementCount
= mElements
.size();
222 Sequence
< OUString
> aElementNames( nElementCount
);
223 OUString
* pElementNames
= aElementNames
.getArray();
224 for( sal_Int32 i
= 0 ; i
< nElementCount
; i
++ )
225 pElementNames
[i
] = mElements
[i
];
227 LibDescriptor
* pLib
= mxImport
->mpLibDesc
;
229 pLib
= &static_cast< LibrariesElement
* >( mxParent
.get() )->mLibDescriptors
.back();
230 pLib
->aElementNames
= aElementNames
;
233 Reference
< css::xml::sax::XDocumentHandler
>
234 importLibraryContainer( LibDescriptorArray
* pLibArray
)
236 return ::xmlscript::createDocumentHandler(new LibraryImport(pLibArray
));
239 css::uno::Reference
< css::xml::sax::XDocumentHandler
>
240 importLibrary( LibDescriptor
& rLib
)
242 return ::xmlscript::createDocumentHandler(new LibraryImport(&rLib
));
245 LibDescriptorArray::LibDescriptorArray( sal_Int32 nLibCount
)
247 mnLibCount
= nLibCount
;
248 mpLibs
.reset( new LibDescriptor
[ mnLibCount
] );
251 LibDescriptorArray::~LibDescriptorArray()
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */