xref: /trunk/main/xmloff/source/forms/propertyimport.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
29 #define _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
30 
31 #include <xmloff/xmlictxt.hxx>
32 #include "formattributes.hxx"
33 #include <vos/ref.hxx>
34 #include <comphelper/stl_types.hxx>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include "layerimport.hxx"
37 
38 namespace com { namespace sun { namespace star { namespace util {
39     struct Time;
40     struct Date;
41 } } } }
42 
43 //.........................................................................
44 namespace xmloff
45 {
46 //.........................................................................
47 
48     //=====================================================================
49     //= PropertyConversion
50     //=====================================================================
51     class PropertyConversion
52     {
53     public:
54         static ::com::sun::star::uno::Any convertString(
55             SvXMLImport& _rImporter,
56             const ::com::sun::star::uno::Type& _rExpectedType,
57             const ::rtl::OUString& _rReadCharacters,
58             const SvXMLEnumMapEntry* _pEnumMap = NULL,
59             const sal_Bool _bInvertBoolean = sal_False
60         );
61 
62         static ::com::sun::star::uno::Type xmlTypeToUnoType( const ::rtl::OUString& _rType );
63     };
64 
65     class OFormLayerXMLImport_Impl;
66     //=====================================================================
67     //= OPropertyImport
68     //=====================================================================
69     /** Helper class for importing property values
70 
71         <p>This class imports properties which are stored as attributes as well as properties which
72         are stored in </em>&lt;form:properties&gt;</em> elements.</p>
73     */
74     class OPropertyImport : public SvXMLImportContext
75     {
76         friend class OSinglePropertyContext;
77         friend class OListPropertyContext;
78 
79     protected:
80         typedef ::std::vector< ::com::sun::star::beans::PropertyValue > PropertyValueArray;
81         PropertyValueArray          m_aValues;
82         PropertyValueArray          m_aGenericValues;
83             // the values which the instance collects between StartElement and EndElement
84 
85         DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringSet );
86         StringSet                   m_aEncounteredAttributes;
87 
88         OFormLayerXMLImport_Impl&       m_rContext;
89 
90         sal_Bool                    m_bTrackAttributes;
91 
92         // TODO: think about the restriction that the class does not know anything about the object it is importing.
93         // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
94         // style properties) can be done in our own EndElement instead of letting derived classes do this.
95 
96     public:
97         OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName);
98 
99         virtual SvXMLImportContext* CreateChildContext(
100             sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
101             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
102 
103         virtual void StartElement(
104             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
105         virtual void Characters(const ::rtl::OUString& _rChars);
106 
107     protected:
108         /** handle one single attribute.
109 
110             <p>This is called for every attribute of the element. This class' implementaion checks if the attribute
111             describes a property, if so, it is added to <member>m_aValues</member>.</p>
112 
113             <p>All non-property attributes should be handled in derived classes.</p>
114 
115             @param _nNamespaceKey
116                 key of the namespace used in the attribute
117             @param _rLocalName
118                 local (relative to the namespace) attribute name
119             @param _rValue
120                 attribute value
121         */
122         virtual bool handleAttribute(sal_uInt16 _nNamespaceKey,
123             const ::rtl::OUString& _rLocalName,
124             const ::rtl::OUString& _rValue);
125 
126         /** determine if the element imported by the object had an given attribute.
127             <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
128             All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
129         */
130         sal_Bool    encounteredAttribute(const ::rtl::OUString& _rAttributeName) const;
131 
132         /** determine if the element imported by the object had an given attribute.
133             <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
134             All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
135         */
136         sal_Bool    encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(::rtl::OUString::createFromAscii(_pAttributeName)); }
137 
138         /** enables the tracking of the encountered attributes
139             <p>The tracking will raise the import costs a little bit, but it's cheaper than
140             derived classes tracking this themself.</p>
141         */
142         void        enableTrackAttributes() { m_bTrackAttributes = sal_True; }
143 
144         inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
145         {
146             m_aValues.push_back(_rProp);
147         }
148 
149         inline void implPushBackPropertyValue( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rValue )
150         {
151             m_aValues.push_back( ::com::sun::star::beans::PropertyValue(
152                 _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) );
153         }
154 
155         inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
156         {
157             m_aGenericValues.push_back(_rProp);
158         }
159     };
160     SV_DECL_IMPL_REF( OPropertyImport )
161 
162     //=====================================================================
163     //= OPropertyElementsContext
164     //=====================================================================
165     /** helper class for importing the &lt;form:properties&gt; element
166     */
167     class OPropertyElementsContext : public SvXMLImportContext
168     {
169     protected:
170         OPropertyImportRef  m_xPropertyImporter;    // to add the properties
171 
172     public:
173         OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
174                 const OPropertyImportRef& _rPropertyImporter);
175 
176         virtual SvXMLImportContext* CreateChildContext(
177             sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
178             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
179 
180 #if OSL_DEBUG_LEVEL > 0
181         virtual void StartElement(
182             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
183         virtual void Characters(const ::rtl::OUString& _rChars);
184 #endif
185     };
186 
187     //=====================================================================
188     //= OSinglePropertyContext
189     //=====================================================================
190     /** helper class for importing a single &lt;form:property&gt; element
191     */
192     class OSinglePropertyContext : public SvXMLImportContext
193     {
194         OPropertyImportRef          m_xPropertyImporter;    // to add the properties
195 
196     public:
197         OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
198                 const OPropertyImportRef& _rPropertyImporter);
199 
200         virtual SvXMLImportContext* CreateChildContext(
201             sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
202             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
203 
204         virtual void StartElement(
205             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
206     };
207 
208     //=====================================================================
209     //= OListPropertyContext
210     //=====================================================================
211     class OListPropertyContext : public SvXMLImportContext
212     {
213         OPropertyImportRef                  m_xPropertyImporter;
214         ::rtl::OUString                     m_sPropertyName;
215         ::rtl::OUString                     m_sPropertyType;
216         ::std::vector< ::rtl::OUString >    m_aListValues;
217 
218     public:
219         OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
220                 const OPropertyImportRef& _rPropertyImporter );
221 
222         virtual void StartElement(
223             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
224 
225         virtual void EndElement();
226 
227         virtual SvXMLImportContext* CreateChildContext(
228             sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
229             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
230     };
231 
232     //=====================================================================
233     //= OListValueContext
234     //=====================================================================
235     class OListValueContext : public SvXMLImportContext
236     {
237         ::rtl::OUString& m_rListValueHolder;
238 
239     public:
240         OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
241             ::rtl::OUString& _rListValueHolder );
242 
243         virtual void StartElement(
244             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
245     };
246 
247 //.........................................................................
248 }   // namespace xmloff
249 //.........................................................................
250 
251 #endif // _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
252 
253 
254