LibreOffice Module xmlscript (master) 1
xmllib_imexp/imp_share.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
23
25
26#include <com/sun/star/xml/input/XRoot.hpp>
27#include <com/sun/star/xml/sax/SAXException.hpp>
28#include <rtl/ref.hxx>
29#include <o3tl/string_view.hxx>
30
31#include <vector>
32
33namespace xmlscript
34{
35inline sal_Int32 toInt32( std::u16string_view rStr )
36{
37 sal_Int32 nVal;
38 if (rStr.size() > 2 && rStr[ 0 ] == '0' && rStr[ 1 ] == 'x')
39 {
40 nVal = o3tl::toUInt32(rStr.substr( 2 ), 16);
41 }
42 else
43 {
44 nVal = o3tl::toInt32(rStr);
45 }
46 return nVal;
47}
48inline bool getBoolAttr(
49 bool * pRet, OUString const & rAttrName,
50 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
51{
52 OUString aValue(
53 xAttributes->getValueByUidName( uid, rAttrName ) );
54 if (!aValue.isEmpty())
55 {
56 if ( aValue == "true" )
57 {
58 *pRet = true;
59 return true;
60 }
61 else if ( aValue == "false" )
62 {
63 *pRet = false;
64 return true;
65 }
66 else
67 {
68 throw css::xml::sax::SAXException(rAttrName + ": no boolean value (true|false)!", css::uno::Reference< css::uno::XInterface >(), css::uno::Any() );
69 }
70 }
71 return false;
72}
73
74inline bool getStringAttr(
75 OUString * pRet, OUString const & rAttrName,
76 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
77{
78 *pRet = xAttributes->getValueByUidName( uid, rAttrName );
79 return (!pRet->isEmpty());
80}
81
82inline bool getLongAttr(
83 sal_Int32 * pRet, OUString const & rAttrName,
84 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes,
85 sal_Int32 uid )
86{
87 OUString aValue(
88 xAttributes->getValueByUidName( uid, rAttrName ) );
89 if (!aValue.isEmpty())
90 {
91 *pRet = toInt32( aValue );
92 return true;
93 }
94 return false;
95}
96
97// Library import
98
100 : public ::cppu::WeakImplHelper< css::xml::input::XRoot >
101{
102 friend class LibrariesElement;
103 friend class LibraryElement;
104
106 LibDescriptor* const mpLibDesc; // Single library mode
107
110
111public:
112 explicit LibraryImport( LibDescriptorArray* pLibArray )
113 : mpLibArray(pLibArray)
114 , mpLibDesc(nullptr)
116 , XMLNS_XLINK_UID(0)
117 {
118 }
119
120 // Single library mode
121 explicit LibraryImport(LibDescriptor* pLibDesc)
122 : mpLibArray(nullptr)
123 , mpLibDesc(pLibDesc)
125 , XMLNS_XLINK_UID(0)
126 {
127 }
128
129 virtual ~LibraryImport() override;
130
131 // XRoot
132 virtual void SAL_CALL startDocument(
133 css::uno::Reference< css::xml::input::XNamespaceMapping > const & xNamespaceMapping ) override;
134 virtual void SAL_CALL endDocument() override;
135 virtual void SAL_CALL processingInstruction(
136 OUString const & rTarget, OUString const & rData ) override;
137 virtual void SAL_CALL setDocumentLocator(
138 css::uno::Reference< css::xml::sax::XLocator > const & xLocator ) override;
139 virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startRootElement(
140 sal_Int32 nUid, OUString const & rLocalName,
141 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ) override;
142};
143
145 : public ::cppu::WeakImplHelper< css::xml::input::XElement >
146{
147protected:
150private:
151 OUString const _aLocalName;
152 css::uno::Reference< css::xml::input::XAttributes > _xAttributes;
153
154public:
156 OUString aLocalName,
157 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes,
158 LibElementBase * pParent, LibraryImport * pImport );
159 virtual ~LibElementBase() override;
160
161 // XElement
162 virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL getParent() override;
163 virtual OUString SAL_CALL getLocalName() override;
164 virtual sal_Int32 SAL_CALL getUid() override;
165 virtual css::uno::Reference< css::xml::input::XAttributes > SAL_CALL getAttributes() override;
166 virtual void SAL_CALL ignorableWhitespace(
167 OUString const & rWhitespaces ) override;
168 virtual void SAL_CALL characters( OUString const & rChars ) override;
169 virtual void SAL_CALL processingInstruction(
170 OUString const & rTarget, OUString const & rData ) override;
171 virtual void SAL_CALL endElement() override;
172 virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(
173 sal_Int32 nUid, OUString const & rLocalName,
174 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ) override;
175};
176
178{
179 friend class LibraryElement;
180
181 std::vector< LibDescriptor > mLibDescriptors;
182
183public:
184 virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(
185 sal_Int32 nUid, OUString const & rLocalName,
186 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ) override;
187 virtual void SAL_CALL endElement() override;
188
190 OUString const & rLocalName,
191 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes,
192 LibraryImport * pImport )
193 : LibElementBase( rLocalName, xAttributes, nullptr, pImport )
194 {}
195};
196
198{
199 std::vector< OUString > mElements;
200
201public:
202
203 virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(
204 sal_Int32 nUid, OUString const & rLocalName,
205 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ) override;
206 virtual void SAL_CALL endElement() override;
207
209 OUString const & rLocalName,
210 css::uno::Reference< css::xml::input::XAttributes > const & xAttributes,
211 LibElementBase * pParent, LibraryImport * pImport )
212 : LibElementBase( rLocalName, xAttributes, pParent, pImport )
213 {}
214};
215
216}
217
218
219/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL getParent() override
virtual void SAL_CALL characters(OUString const &rChars) override
virtual sal_Int32 SAL_CALL getUid() override
css::uno::Reference< css::xml::input::XAttributes > _xAttributes
virtual void SAL_CALL processingInstruction(OUString const &rTarget, OUString const &rData) override
virtual void SAL_CALL endElement() override
virtual void SAL_CALL ignorableWhitespace(OUString const &rWhitespaces) override
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(sal_Int32 nUid, OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes) override
rtl::Reference< LibraryImport > mxImport
LibElementBase(OUString aLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, LibElementBase *pParent, LibraryImport *pImport)
virtual css::uno::Reference< css::xml::input::XAttributes > SAL_CALL getAttributes() override
virtual ~LibElementBase() override
rtl::Reference< LibElementBase > mxParent
virtual OUString SAL_CALL getLocalName() override
LibrariesElement(OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, LibraryImport *pImport)
std::vector< LibDescriptor > mLibDescriptors
virtual void SAL_CALL endElement() override
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(sal_Int32 nUid, OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes) override
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startChildElement(sal_Int32 nUid, OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes) override
std::vector< OUString > mElements
virtual void SAL_CALL endElement() override
LibraryElement(OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, LibElementBase *pParent, LibraryImport *pImport)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)
bool getLongAttr(sal_Int32 *pRet, OUString const &rAttrName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, sal_Int32 nUid)
bool getBoolAttr(sal_Bool *pRet, OUString const &rAttrName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, sal_Int32 nUid)
sal_Int32 toInt32(std::u16string_view rStr)
bool getStringAttr(OUString *pRet, OUString const &rAttrName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes, sal_Int32 nUid)
virtual css::uno::Reference< css::xml::input::XElement > SAL_CALL startRootElement(sal_Int32 nUid, OUString const &rLocalName, css::uno::Reference< css::xml::input::XAttributes > const &xAttributes) override
virtual void SAL_CALL startDocument(css::uno::Reference< css::xml::input::XNamespaceMapping > const &xNamespaceMapping) override
virtual void SAL_CALL setDocumentLocator(css::uno::Reference< css::xml::sax::XLocator > const &xLocator) override
LibraryImport(LibDescriptorArray *pLibArray)
LibraryImport(LibDescriptor *pLibDesc)
virtual void SAL_CALL endDocument() override
virtual ~LibraryImport() override
virtual void SAL_CALL processingInstruction(OUString const &rTarget, OUString const &rData) override