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 #ifndef INCLUDED_XMLOFF_XMLEXPPR_HXX
21 #define INCLUDED_XMLOFF_XMLEXPPR_HXX
22 
23 #include <sal/config.h>
24 #include <xmloff/dllapi.h>
25 #include <salhelper/simplereferenceobject.hxx>
26 #include <o3tl/typed_flags_set.hxx>
27 #include <rtl/ustring.hxx>
28 
29 #include <memory>
30 #include <vector>
31 
32 namespace com::sun::star::uno { template <typename > class Reference; }
33 namespace com::sun::star::beans { class XPropertySet; }
34 namespace rtl { template <class reference_type> class Reference; }
35 
36 class XMLPropertySetMapper;
37 struct XMLPropertyState;
38 
39 enum class SvXmlExportFlags {
40     NONE        = 0x0000,
41     IGN_WS      = 0x0008
42 };
43 namespace o3tl
44 {
45     template<> struct typed_flags<SvXmlExportFlags> : is_typed_flags<SvXmlExportFlags, 0x08> {};
46 }
47 
48 class SvXMLUnitConverter;
49 class SvXMLAttributeList;
50 class SvXMLNamespaceMap;
51 class SvXMLExport;
52 
53 class XMLOFF_DLLPUBLIC SvXMLExportPropertyMapper : public salhelper::SimpleReferenceObject
54 {
55     struct Impl;
56     std::unique_ptr<Impl> mpImpl;
57 
58 protected:
59 
60     /** Filter all properties we don't want to export:
61         Take all properties of the XPropertySet which are also found in the
62         XMLPropertyMapEntry-array and which are not set directly (so, the value isn't
63         default and isn't inherited, apart from bDefault is true)
64         After this process It'll called 'Contextfilter' for application-specific
65         filter-processes. */
66     std::vector<XMLPropertyState> Filter_(
67             SvXMLExport const& rExport,
68             const css::uno::Reference<css::beans::XPropertySet>& rPropSet,
69             bool bDefault, bool bDisableFoFontFamily ) const;
70 
71     /** Application-specific filter. By default do nothing. */
72     virtual void ContextFilter(
73             bool bEnableFoFontFamily,
74             ::std::vector< XMLPropertyState >& rProperties,
75             const css::uno::Reference<css::beans::XPropertySet >& rPropSet ) const;
76 
77     /** fills the given attribute list with the items in the given set */
78     void _exportXML( sal_uInt16 nPropType, sal_uInt16& rPropTypeFlags,
79                      SvXMLAttributeList& rAttrList,
80                      const ::std::vector< XMLPropertyState >& rProperties,
81                      const SvXMLUnitConverter& rUnitConverter,
82                      const SvXMLNamespaceMap& rNamespaceMap,
83                      std::vector<sal_uInt16>* pIndexArray,
84                        sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx ) const;
85 
86     void _exportXML( SvXMLAttributeList& rAttrList,
87                      const XMLPropertyState& rProperty,
88                      const SvXMLUnitConverter& rUnitConverter,
89                      const SvXMLNamespaceMap& rNamespaceMap,
90                      const ::std::vector< XMLPropertyState > *pProperties,
91                      sal_uInt32 nIdx ) const;
92 
93     void exportElementItems(
94             SvXMLExport& rExport,
95             const ::std::vector< XMLPropertyState >& rProperties,
96             SvXmlExportFlags nFlags,
97             const std::vector<sal_uInt16>& rIndexArray ) const;
98 
99 public:
100 
101     SvXMLExportPropertyMapper(
102             const rtl::Reference< XMLPropertySetMapper >& rMapper );
103     virtual ~SvXMLExportPropertyMapper() override;
104 
105     // Add a ExportPropertyMapper at the end of the import mapper chain.
106     // The added mapper MUST not be used outside the Mapper chain any longer,
107     // because its PropertyMapper will be replaced.
108     void ChainExportMapper(
109         const rtl::Reference< SvXMLExportPropertyMapper>& rMapper );
110 
111     /** Filter all properties we don't want to export:
112         Take all properties of the XPropertySet which are also found in the
113         XMLPropertyMapEntry-array and which are not set directly (so, the value isn't
114         default and isn't inherited)
115         After this process It'll called 'Contextfilter' for application-specific
116         filter-processes. */
117     std::vector<XMLPropertyState> Filter(
118         SvXMLExport const& rExport,
119         const css::uno::Reference<css::beans::XPropertySet>& rPropSet, bool bEnableFoFontFamily = false ) const;
120 
121     /** Like Filter(), except that:
122       * - only properties that have the map flag MID_FLAG_DEFAULT_ITEM_EXPORT
123       *   set are exported,
124       * - instead of the property's value, its default value is exported.
125       */
126     std::vector<XMLPropertyState> FilterDefaults(
127         SvXMLExport const& rExport,
128         const css::uno::Reference<css::beans::XPropertySet>& rPropSet ) const;
129 
130     /** Provides a partial ordering over two arrays of XMLPropertyState,
131        Partial because implementing a full order requires quite a lot of code. */
132     bool LessPartial( const ::std::vector< XMLPropertyState >& aProperties1,
133                      const ::std::vector< XMLPropertyState >& aProperties2 ) const;
134 
135     /** Compare two arrays of XMLPropertyState */
136     bool Equals( const ::std::vector< XMLPropertyState >& aProperties1,
137                      const ::std::vector< XMLPropertyState >& aProperties2 ) const;
138     void exportXML(
139             SvXMLExport& rExport,
140             const ::std::vector< XMLPropertyState >& rProperties,
141             SvXmlExportFlags nFlags,
142             bool bUseExtensionNamespaceForGraphicProperties = false ) const;
143 
144     /** like above but only properties whose property map index is within the
145      *  specified range are exported
146      *
147      * @param bExtensionNamespace use the extension namespace for graphic-properties
148      */
149     void exportXML(
150             SvXMLExport& rExport,
151             const ::std::vector< XMLPropertyState >& rProperties,
152             sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
153             SvXmlExportFlags nFlags, bool bExtensionNamespace = false ) const;
154 
155     /** this method is called for every item that has the
156         MID_FLAG_ELEMENT_EXPORT flag set */
157     virtual void handleElementItem(
158             SvXMLExport& rExport,
159             const XMLPropertyState& rProperty,
160             SvXmlExportFlags nFlags,
161             const ::std::vector< XMLPropertyState > *pProperties,
162             sal_uInt32 nIdx ) const;
163 
164     /** this method is called for every item that has the
165         MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
166     virtual void handleSpecialItem(
167             SvXMLAttributeList& rAttrList,
168             const XMLPropertyState& rProperty,
169             const SvXMLUnitConverter& rUnitConverter,
170             const SvXMLNamespaceMap& rNamespaceMap,
171             const ::std::vector< XMLPropertyState > *pProperties,
172             sal_uInt32 nIdx ) const;
173 
174     const rtl::Reference<XMLPropertySetMapper>& getPropertySetMapper() const;
175 
176     void SetStyleName( const OUString& rStyleName );
177     const OUString& GetStyleName() const;
178 };
179 
180 #endif // INCLUDED_XMLOFF_XMLEXPPR_HXX
181 
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
183