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"
26 #include <xml_import.hxx>
27 #include <xmlscript/xmlns.h>
30 using namespace css::uno
;
35 Reference
< xml::input::XElement
> LibElementBase::getParent()
40 OUString
LibElementBase::getLocalName()
45 sal_Int32
LibElementBase::getUid()
47 return mxImport
->XMLNS_LIBRARY_UID
;
50 Reference
< xml::input::XAttributes
> LibElementBase::getAttributes()
55 void LibElementBase::ignorableWhitespace(
56 OUString
const & /*rWhitespaces*/ )
60 void LibElementBase::characters( OUString
const & /*rChars*/ )
62 // not used, all characters ignored
65 void LibElementBase::processingInstruction(
66 OUString
const & /*rTarget*/, OUString
const & /*rData*/ )
70 void LibElementBase::endElement()
73 Reference
< xml::input::XElement
> LibElementBase::startChildElement(
74 sal_Int32
/*nUid*/, OUString
const & /*rLocalName*/,
75 Reference
< xml::input::XAttributes
> const & /*xAttributes*/ )
77 throw xml::sax::SAXException("unexpected element!", Reference
< XInterface
>(), Any() );
80 LibElementBase::LibElementBase(
82 Reference
< xml::input::XAttributes
> const & xAttributes
,
83 LibElementBase
* pParent
, LibraryImport
* pImport
)
86 , _aLocalName(std::move( aLocalName
))
87 , _xAttributes( xAttributes
)
91 LibElementBase::~LibElementBase()
93 SAL_INFO("xmlscript.xmllib", "LibElementBase::~LibElementBase(): " << _aLocalName
);
98 void LibraryImport::startDocument(
99 Reference
< xml::input::XNamespaceMapping
> const & xNamespaceMapping
)
101 XMLNS_LIBRARY_UID
= xNamespaceMapping
->getUidByUri( XMLNS_LIBRARY_URI
);
102 XMLNS_XLINK_UID
= xNamespaceMapping
->getUidByUri( XMLNS_XLINK_URI
);
105 void LibraryImport::endDocument()
109 void LibraryImport::processingInstruction(
110 OUString
const & /*rTarget*/, OUString
const & /*rData*/ )
114 void LibraryImport::setDocumentLocator(
115 Reference
< xml::sax::XLocator
> const & /*xLocator*/ )
119 Reference
< xml::input::XElement
> LibraryImport::startRootElement(
120 sal_Int32 nUid
, OUString
const & rLocalName
,
121 Reference
< xml::input::XAttributes
> const & xAttributes
)
123 if (XMLNS_LIBRARY_UID
!= nUid
)
125 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
127 else if ( mpLibArray
&& rLocalName
== "libraries" )
129 return new LibrariesElement( rLocalName
, xAttributes
, this );
131 else if ( mpLibDesc
&& rLocalName
== "library" )
133 LibDescriptor
& aDesc
= *mpLibDesc
;
134 aDesc
.bLink
= aDesc
.bReadOnly
= aDesc
.bPasswordProtected
= aDesc
.bPreload
= false;
136 aDesc
.aName
= xAttributes
->getValueByUidName(XMLNS_LIBRARY_UID
, "name" );
137 getBoolAttr( &aDesc
.bReadOnly
, "readonly", xAttributes
, XMLNS_LIBRARY_UID
);
138 getBoolAttr( &aDesc
.bPasswordProtected
, "passwordprotected", xAttributes
, XMLNS_LIBRARY_UID
);
139 getBoolAttr( &aDesc
.bPreload
, "preload", xAttributes
, XMLNS_LIBRARY_UID
);
141 return new LibraryElement( rLocalName
, xAttributes
, nullptr, this );
145 throw xml::sax::SAXException( "illegal root element (expected libraries) given: " + rLocalName
, Reference
< XInterface
>(), Any() );
149 LibraryImport::~LibraryImport()
151 SAL_INFO("xmlscript.xmllib", "LibraryImport::~LibraryImport()." );
155 Reference
< xml::input::XElement
> LibrariesElement::startChildElement(
156 sal_Int32 nUid
, OUString
const & rLocalName
,
157 Reference
< xml::input::XAttributes
> const & xAttributes
)
159 if (mxImport
->XMLNS_LIBRARY_UID
!= nUid
)
161 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
164 else if ( rLocalName
== "library" )
167 aDesc
.bLink
= aDesc
.bReadOnly
= aDesc
.bPasswordProtected
= aDesc
.bPreload
= false;
169 aDesc
.aName
= xAttributes
->getValueByUidName(mxImport
->XMLNS_LIBRARY_UID
, "name" );
170 aDesc
.aStorageURL
= xAttributes
->getValueByUidName( mxImport
->XMLNS_XLINK_UID
, "href" );
171 getBoolAttr(&aDesc
.bLink
, "link", xAttributes
, mxImport
->XMLNS_LIBRARY_UID
);
172 getBoolAttr(&aDesc
.bReadOnly
, "readonly", xAttributes
, mxImport
->XMLNS_LIBRARY_UID
);
173 getBoolAttr(&aDesc
.bPasswordProtected
, "passwordprotected", xAttributes
, mxImport
->XMLNS_LIBRARY_UID
);
175 mLibDescriptors
.push_back( aDesc
);
176 return new LibraryElement( rLocalName
, xAttributes
, this, mxImport
.get() );
180 throw xml::sax::SAXException( "expected styles of bulletinboard element!", Reference
< XInterface
>(), Any() );
184 void LibrariesElement::endElement()
186 sal_Int32 nLibCount
= mxImport
->mpLibArray
->mnLibCount
= static_cast<sal_Int32
>(mLibDescriptors
.size());
187 mxImport
->mpLibArray
->mpLibs
.reset( new LibDescriptor
[ nLibCount
] );
189 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
191 const LibDescriptor
& rLib
= mLibDescriptors
[i
];
192 mxImport
->mpLibArray
->mpLibs
[i
] = rLib
;
197 Reference
< xml::input::XElement
> LibraryElement::startChildElement(
198 sal_Int32 nUid
, OUString
const & rLocalName
,
199 Reference
< xml::input::XAttributes
> const & xAttributes
)
201 if (mxImport
->XMLNS_LIBRARY_UID
!= nUid
)
203 throw xml::sax::SAXException( "illegal namespace!", Reference
< XInterface
>(), Any() );
206 else if ( rLocalName
== "element" )
208 OUString
aValue( xAttributes
->getValueByUidName(mxImport
->XMLNS_LIBRARY_UID
, "name" ) );
209 if (!aValue
.isEmpty())
210 mElements
.push_back( aValue
);
212 return new LibElementBase( rLocalName
, xAttributes
, this, mxImport
.get() );
216 throw xml::sax::SAXException( "expected styles or bulletinboard element!", Reference
< XInterface
>(), Any() );
220 void LibraryElement::endElement()
222 sal_Int32 nElementCount
= mElements
.size();
223 Sequence
< OUString
> aElementNames( nElementCount
);
224 OUString
* pElementNames
= aElementNames
.getArray();
225 for( sal_Int32 i
= 0 ; i
< nElementCount
; i
++ )
226 pElementNames
[i
] = mElements
[i
];
228 LibDescriptor
* pLib
= mxImport
->mpLibDesc
;
230 pLib
= &static_cast< LibrariesElement
* >( mxParent
.get() )->mLibDescriptors
.back();
231 pLib
->aElementNames
= aElementNames
;
234 Reference
< css::xml::sax::XDocumentHandler
>
235 importLibraryContainer( LibDescriptorArray
* pLibArray
)
237 return ::xmlscript::createDocumentHandler(new LibraryImport(pLibArray
));
240 css::uno::Reference
< css::xml::sax::XDocumentHandler
>
241 importLibrary( LibDescriptor
& rLib
)
243 return ::xmlscript::createDocumentHandler(new LibraryImport(&rLib
));
246 LibDescriptorArray::LibDescriptorArray( sal_Int32 nLibCount
)
248 mnLibCount
= nLibCount
;
249 mpLibs
.reset( new LibDescriptor
[ mnLibCount
] );
252 LibDescriptorArray::~LibDescriptorArray()
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */