LibreOffice Module xmloff (master) 1
propertyimport.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
22#include <sal/config.h>
23
25
26#include <xmloff/xmlictxt.hxx>
27#include "formattributes.hxx"
28#include <rtl/ref.hxx>
29#include <com/sun/star/beans/PropertyValue.hpp>
30#include "layerimport.hxx"
31
32namespace com::sun::star::util {
33 struct Time;
34 struct Date;
35}
36
37namespace xmloff
38{
39
40 //= PropertyConversion
42 {
43 public:
44 template<typename EnumT>
45 static css::uno::Any convertString(
46 const css::uno::Type& _rExpectedType,
47 const OUString& _rReadCharacters,
48 const SvXMLEnumMapEntry<EnumT>* _pEnumMap = nullptr
49 )
50 {
51 return convertString(_rExpectedType, _rReadCharacters,
52 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pEnumMap), /*_bInvertBoolean*/false);
53 }
54 static css::uno::Any convertString(
55 const css::uno::Type& _rExpectedType,
56 const OUString& _rReadCharacters,
57 const SvXMLEnumMapEntry<sal_uInt16>* _pEnumMap = nullptr,
58 const bool _bInvertBoolean = false
59 );
60
61 static css::uno::Type xmlTypeToUnoType( const OUString& _rType );
62 };
63
64 class OFormLayerXMLImport_Impl;
65 //= OPropertyImport
72 {
75
76 protected:
77 typedef ::std::vector< css::beans::PropertyValue > PropertyValueArray;
80 // the values which the instance collects between StartElement and EndElement
81
83
85
87
88 // TODO: think about the restriction that the class does not know anything about the object it is importing.
89 // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
90 // style properties) can be done in our own EndElement instead of letting derived classes do this.
91
92 public:
94
95 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
96 sal_Int32 nElement,
97 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
98
99 virtual void SAL_CALL startFastElement(
100 sal_Int32 nElement,
101 const css::uno::Reference< css::xml::sax::XFastAttributeList >& _rxAttrList) override;
102 virtual void SAL_CALL characters(const OUString& _rChars) override;
103
104 protected:
119 virtual bool handleAttribute(sal_Int32 nElement, const OUString& _rValue);
120
125 bool encounteredAttribute(sal_Int32 nElement) const;
126
132
133 void implPushBackPropertyValue(const css::beans::PropertyValue& _rProp)
134 {
135 m_aValues.push_back(_rProp);
136 }
137
138 void implPushBackPropertyValue( const OUString& _rName, const css::uno::Any& _rValue )
139 {
140 m_aValues.push_back( css::beans::PropertyValue(
141 _rName, -1, _rValue, css::beans::PropertyState_DIRECT_VALUE ) );
142 }
143
144 void implPushBackGenericPropertyValue(const css::beans::PropertyValue& _rProp)
145 {
146 m_aGenericValues.push_back(_rProp);
147 }
148 };
150
151 //= OPropertyElementsContext
155 {
156 OPropertyImportRef m_xPropertyImporter; // to add the properties
157
158 public:
160 OPropertyImportRef _xPropertyImporter);
161
162 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
163 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
164
165#if OSL_DEBUG_LEVEL > 0
166 virtual void SAL_CALL startFastElement(
167 sal_Int32 nElement,
168 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
169 virtual void SAL_CALL characters(const OUString& _rChars) override;
170#endif
171 };
172
173 //= OSinglePropertyContext
177 {
178 OPropertyImportRef m_xPropertyImporter; // to add the properties
179
180 public:
182 OPropertyImportRef _xPropertyImporter);
183
184 virtual void SAL_CALL startFastElement(
185 sal_Int32 nElement,
186 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
187 };
188
189 //= OListPropertyContext
191 {
195 ::std::vector< OUString > m_aListValues;
196
197 public:
199 OPropertyImportRef _xPropertyImporter );
200
201 virtual void SAL_CALL startFastElement(
202 sal_Int32 nElement,
203 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
204
205 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
206
207 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
208 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
209 };
210
211 //= OListValueContext
213 {
215
216 public:
217 OListValueContext( SvXMLImport& _rImport, OUString& _rListValueHolder );
218
219 virtual void SAL_CALL startFastElement(
220 sal_Int32 nElement,
221 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
222 };
223
224} // namespace xmloff
225
226/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
friend class SvXMLImport
Definition: xmlictxt.hxx:49
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OPropertyImportRef m_xPropertyImporter
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
::std::vector< OUString > m_aListValues
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
OListPropertyContext(SvXMLImport &_rImport, OPropertyImportRef _xPropertyImporter)
OListValueContext(SvXMLImport &_rImport, OUString &_rListValueHolder)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
helper class for importing the <form:properties> element
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OPropertyElementsContext(SvXMLImport &_rImport, OPropertyImportRef _xPropertyImporter)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OPropertyImportRef m_xPropertyImporter
virtual void SAL_CALL characters(const OUString &_rChars) override
This method is called for all characters that are contained in the current element.
Helper class for importing property values.
PropertyValueArray m_aValues
void implPushBackPropertyValue(const css::beans::PropertyValue &_rProp)
virtual bool handleAttribute(sal_Int32 nElement, const OUString &_rValue)
handle one single attribute.
o3tl::sorted_vector< sal_Int32 > m_aEncounteredAttributes
OPropertyImport(OFormLayerXMLImport_Impl &_rImport)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
void enableTrackAttributes()
enables the tracking of the encountered attributes
bool encounteredAttribute(sal_Int32 nElement) const
determine if the element imported by the object had a given attribute.
PropertyValueArray m_aGenericValues
::std::vector< css::beans::PropertyValue > PropertyValueArray
void implPushBackGenericPropertyValue(const css::beans::PropertyValue &_rProp)
virtual void SAL_CALL characters(const OUString &_rChars) override
This method is called for all characters that are contained in the current element.
OFormLayerXMLImport_Impl & m_rContext
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_rxAttrList) override
void implPushBackPropertyValue(const OUString &_rName, const css::uno::Any &_rValue)
helper class for importing a single <form:property> element
OPropertyImportRef m_xPropertyImporter
OSinglePropertyContext(SvXMLImport &_rImport, OPropertyImportRef _xPropertyImporter)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
static css::uno::Any convertString(const css::uno::Type &_rExpectedType, const OUString &_rReadCharacters, const SvXMLEnumMapEntry< EnumT > *_pEnumMap=nullptr)
static css::uno::Type xmlTypeToUnoType(const OUString &_rType)
rtl::Reference< OPropertyImport > OPropertyImportRef