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 
24 #include <o3tl/sorted_vector.hxx>
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 
32 namespace com::sun::star::util {
33  struct Time;
34  struct Date;
35 }
36 
37 namespace 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  {
73  friend class OSinglePropertyContext;
74  friend class OListPropertyContext;
75 
76  protected:
77  typedef ::std::vector< css::beans::PropertyValue > PropertyValueArray;
78  PropertyValueArray m_aValues;
79  PropertyValueArray m_aGenericValues;
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 
131  void enableTrackAttributes() { m_bTrackAttributes = true; }
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  const OPropertyImportRef& _rPropertyImporter);
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  const OPropertyImportRef& _rPropertyImporter);
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  {
192  OPropertyImportRef m_xPropertyImporter;
193  OUString m_sPropertyName;
194  OUString m_sPropertyType;
195  ::std::vector< OUString > m_aListValues;
196 
197  public:
199  const OPropertyImportRef& _rPropertyImporter );
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: */
static css::uno::Any convertString(const css::uno::Type &_rExpectedType, const OUString &_rReadCharacters, const SvXMLEnumMapEntry< EnumT > *_pEnumMap=nullptr)
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 a single element
bool encounteredAttribute(sal_Int32 nElement) const
determine if the element imported by the object had a given attribute.
OListPropertyContext(SvXMLImport &_rImport, const OPropertyImportRef &_rPropertyImporter)
PropertyValueArray m_aGenericValues
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OPropertyImportRef m_xPropertyImporter
OPropertyElementsContext(SvXMLImport &_rImport, const OPropertyImportRef &_rPropertyImporter)
::std::vector< css::beans::PropertyValue > PropertyValueArray
helper class for importing the element
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_rxAttrList) override
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 ...
OPropertyImportRef m_xPropertyImporter
void enableTrackAttributes()
enables the tracking of the encountered attributes
o3tl::sorted_vector< sal_Int32 > m_aEncounteredAttributes
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OSinglePropertyContext(SvXMLImport &_rImport, const OPropertyImportRef &_rPropertyImporter)
rtl::Reference< OPropertyImport > OPropertyImportRef
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OFormLayerXMLImport_Impl & m_rContext
::std::vector< OUString > m_aListValues
PropertyValueArray m_aValues
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:39
void implPushBackPropertyValue(const css::beans::PropertyValue &_rProp)
virtual bool handleAttribute(sal_Int32 nElement, const OUString &_rValue)
handle one single attribute.
Helper class for importing property values.
OListValueContext(SvXMLImport &_rImport, OUString &_rListValueHolder)
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.
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OPropertyImport(OFormLayerXMLImport_Impl &_rImport)
void implPushBackGenericPropertyValue(const css::beans::PropertyValue &_rProp)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
static css::uno::Type xmlTypeToUnoType(const OUString &_rType)
void implPushBackPropertyValue(const OUString &_rName, const css::uno::Any &_rValue)