1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SETTINGSIMPORT_HXX
25 #define SETTINGSIMPORT_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/xml/sax/XAttributeList.hpp>
29 /** === end UNO includes === **/
30 
31 #include <comphelper/namedvaluecollection.hxx>
32 #include <rtl/ref.hxx>
33 #include <rtl/ustrbuf.hxx>
34 
35 //........................................................................
36 namespace dbaccess
37 {
38 //........................................................................
39 
40 	//====================================================================
41 	//= SettingsImport
42 	//====================================================================
43     /** a simplified version of xmloff/DocumentSettingsContext
44 
45         It would be nice if the DocumentSettingsContext would not be that tightly interwoven with the SvXMLImport
46         class, so we could re-use it here ...
47     */
48     class SettingsImport : public ::rtl::IReference
49 	{
50     public:
51         SettingsImport();
52 
53         // IReference
54 	    virtual oslInterlockedCount SAL_CALL acquire();
55 	    virtual oslInterlockedCount SAL_CALL release();
56 
57         // own overriables
58         virtual ::rtl::Reference< SettingsImport >  nextState(
59             const ::rtl::OUString& i_rElementName
60         ) = 0;
61         virtual void startElement(
62             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& i_rAttributes
63         );
64         virtual void endElement();
65         virtual void characters( const ::rtl::OUString& i_rCharacters );
66 
67     protected:
68         virtual ~SettingsImport();
69 
70     protected:
71         static void split( const ::rtl::OUString& i_rElementName, ::rtl::OUString& o_rNamespace, ::rtl::OUString& o_rLocalName );
72 
73     protected:
getItemName() const74         const ::rtl::OUString&          getItemName() const                 { return m_sItemName; }
getItemType() const75         const ::rtl::OUString&          getItemType() const                 { return m_sItemType; }
getAccumulatedCharacters() const76         const ::rtl::OUStringBuffer&    getAccumulatedCharacters() const    { return m_aCharacters; }
77 
78     private:
79         oslInterlockedCount     m_refCount;
80         // value of the config:name attribute, if any
81         ::rtl::OUString         m_sItemName;
82         // value of the config:type attribute, if any
83         ::rtl::OUString         m_sItemType;
84         // accumulated characters, if any
85         ::rtl::OUStringBuffer   m_aCharacters;
86 	};
87 
88 	//====================================================================
89 	//= IgnoringSettingsImport
90 	//====================================================================
91     class IgnoringSettingsImport : public SettingsImport
92     {
93     public:
IgnoringSettingsImport()94         IgnoringSettingsImport()
95         {
96         }
97 
98         // SettingsImport overridables
99         virtual ::rtl::Reference< SettingsImport >  nextState(
100             const ::rtl::OUString& i_rElementName
101         );
102 
103     private:
~IgnoringSettingsImport()104         ~IgnoringSettingsImport()
105         {
106         }
107     };
108 
109 	//====================================================================
110 	//= OfficeSettingsImport
111 	//====================================================================
112     class OfficeSettingsImport : public SettingsImport
113     {
114     public:
115         OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings );
116 
117         // SettingsImport overridables
118         virtual ::rtl::Reference< SettingsImport >  nextState(
119             const ::rtl::OUString& i_rElementName
120         );
121 
122     protected:
123         ~OfficeSettingsImport();
124 
125     private:
126         // the settings collection to which |this| will contribute a single setting
127         ::comphelper::NamedValueCollection& m_rSettings;
128     };
129 
130 	//====================================================================
131 	//= ConfigItemSetImport
132 	//====================================================================
133     class ConfigItemImport : public SettingsImport
134     {
135     public:
136         ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings );
137 
138     protected:
139         ~ConfigItemImport();
140 
141     public:
142         // SettingsImport overridables
143         virtual ::rtl::Reference< SettingsImport >  nextState(
144             const ::rtl::OUString& i_rElementName
145         );
146         virtual void endElement();
147 
148     protected:
149         // own overridables
150         /// retrieves the value represented by the element
151         virtual void getItemValue( ::com::sun::star::uno::Any& o_rValue ) const;
152 
153     private:
154         // the settings collection to which |this| will contribute a single setting
155         ::comphelper::NamedValueCollection& m_rSettings;
156     };
157 
158 	//====================================================================
159 	//= ConfigItemSetImport
160 	//====================================================================
161     class ConfigItemSetImport : public ConfigItemImport
162     {
163     public:
164         ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings );
165 
166     protected:
167         ~ConfigItemSetImport();
168 
169     public:
170         // SettingsImport overridables
171         virtual ::rtl::Reference< SettingsImport >  nextState(
172             const ::rtl::OUString& i_rElementName
173         );
174 
175     protected:
176         // ConfigItemImport overridables
177         virtual void getItemValue( ::com::sun::star::uno::Any& o_rValue ) const;
178 
179     private:
180         /// the settings represented by our child elements
181         ::comphelper::NamedValueCollection  m_aChildSettings;
182     };
183 
184 //........................................................................
185 } // namespace dbaccess
186 //........................................................................
187 
188 #endif // SETTINGSIMPORT_HXX
189