fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / core / recovery / settingsimport.cxx
blob4c6ec3e6145ac1c046c5d361e929497440b6648b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "settingsimport.hxx"
22 #include <tools/diagnose_ex.h>
23 #include <sax/tools/converter.hxx>
24 #include <xmloff/xmltoken.hxx>
26 namespace dbaccess
29 using ::com::sun::star::uno::Reference;
30 using ::com::sun::star::uno::XInterface;
31 using ::com::sun::star::uno::UNO_QUERY;
32 using ::com::sun::star::uno::UNO_QUERY_THROW;
33 using ::com::sun::star::uno::UNO_SET_THROW;
34 using ::com::sun::star::uno::Exception;
35 using ::com::sun::star::uno::RuntimeException;
36 using ::com::sun::star::uno::Any;
37 using ::com::sun::star::uno::makeAny;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::uno::Type;
40 using ::com::sun::star::xml::sax::XAttributeList;
42 // SettingsImport
43 SettingsImport::SettingsImport()
47 SettingsImport::~SettingsImport()
51 void SettingsImport::startElement( const Reference< XAttributeList >& i_rAttributes )
53 // find the name of the setting
54 if ( i_rAttributes.is() )
56 m_sItemName = i_rAttributes->getValueByName( "config:name" );
57 m_sItemType = i_rAttributes->getValueByName( "config:type" );
61 void SettingsImport::endElement()
65 void SettingsImport::characters( const OUString& i_rCharacters )
67 m_aCharacters.append( i_rCharacters );
70 void SettingsImport::split( const OUString& i_rElementName, OUString& o_rNamespace, OUString& o_rLocalName )
72 o_rNamespace.clear();
73 o_rLocalName = i_rElementName;
74 const sal_Int32 nSeparatorPos = i_rElementName.indexOf( ':' );
75 if ( nSeparatorPos > -1 )
77 o_rNamespace = i_rElementName.copy( 0, nSeparatorPos );
78 o_rLocalName = i_rElementName.copy( nSeparatorPos + 1 );
81 OSL_ENSURE( o_rNamespace == "config", "SettingsImport::split: unexpected namespace!" );
82 // our recovery file is kind of hand-made, so there shouldn't be anything else than "config".
83 // If there is, then just ignore it ...
86 // IgnoringSettingsImport
87 ::rtl::Reference< SettingsImport > IgnoringSettingsImport::nextState( const OUString& i_rElementName )
89 (void)i_rElementName;
90 return this;
93 // OfficeSettingsImport
94 OfficeSettingsImport::OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings )
95 :m_rSettings( o_rSettings )
99 OfficeSettingsImport::~OfficeSettingsImport()
103 ::rtl::Reference< SettingsImport > OfficeSettingsImport::nextState( const OUString& i_rElementName )
105 // separate the namespace part from the element name
106 OUString sNamespace;
107 OUString sLocalName;
108 split( i_rElementName, sNamespace, sLocalName );
110 if ( sLocalName == "config-item-set" )
111 return new ConfigItemSetImport( m_rSettings );
113 #if OSL_DEBUG_LEVEL > 0
114 OString sMessage( "unknown (or unsupported at this place) element name '" );
115 sMessage += OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 );
116 sMessage += "', ignoring";
117 OSL_FAIL( sMessage.getStr() );
118 #endif
119 return new IgnoringSettingsImport;
122 // ConfigItemImport
123 ConfigItemImport::ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings )
124 :m_rSettings( o_rSettings )
128 ConfigItemImport::~ConfigItemImport()
132 ::rtl::Reference< SettingsImport > ConfigItemImport::nextState( const OUString& i_rElementName )
134 OSL_FAIL( "ConfigItemImport::nextState: unexpected: this class is responsible for child-less items only!" );
135 (void)i_rElementName;
136 return new IgnoringSettingsImport;
139 void ConfigItemImport::endElement()
141 SettingsImport::endElement();
143 const OUString sItemName( getItemName() );
144 ENSURE_OR_RETURN_VOID( !sItemName.isEmpty(), "no item name -> no item value" );
145 Any aValue;
146 getItemValue( aValue );
147 m_rSettings.put( sItemName, aValue );
150 void ConfigItemImport::getItemValue( ::com::sun::star::uno::Any& o_rValue ) const
152 o_rValue.clear();
154 // the characters building up th evalue
155 OUStringBuffer aCharacters( getAccumulatedCharacters() );
156 const OUString sValue = aCharacters.makeStringAndClear();
158 const OUString& rItemType( getItemType() );
159 ENSURE_OR_RETURN_VOID( !rItemType.isEmpty(), "no item type -> no item value" );
161 if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_INT ) )
163 sal_Int32 nValue(0);
164 if (::sax::Converter::convertNumber( nValue, sValue ))
166 o_rValue <<= nValue;
168 else
170 OSL_FAIL( "ConfigItemImport::getItemValue: could not convert an int value!" );
173 else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_BOOLEAN ) )
175 bool bValue(false);
176 if (::sax::Converter::convertBool( bValue, sValue ))
178 o_rValue <<= bValue;
180 else
182 OSL_FAIL( "ConfigItemImport::getItemValue: could not convert a boolean value!" );
185 else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_STRING ) )
187 o_rValue <<= sValue;
189 #if OSL_DEBUG_LEVEL > 0
190 else
192 OString sMessage( "ConfigItemImport::getItemValue: unsupported item type '" );
193 sMessage += OUStringToOString( rItemType, RTL_TEXTENCODING_UTF8 );
194 sMessage += "', ignoring";
195 OSL_FAIL( sMessage.getStr() );
197 #endif
200 // ConfigItemSetImport
201 ConfigItemSetImport::ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings )
202 :ConfigItemImport( o_rSettings )
206 ConfigItemSetImport::~ConfigItemSetImport()
210 ::rtl::Reference< SettingsImport > ConfigItemSetImport::nextState( const OUString& i_rElementName )
212 // separate the namespace part from the element name
213 OUString sNamespace;
214 OUString sLocalName;
215 split( i_rElementName, sNamespace, sLocalName );
217 if ( sLocalName == "config-item-set" )
218 return new ConfigItemSetImport( m_aChildSettings );
219 if ( sLocalName == "config-item" )
220 return new ConfigItemImport( m_aChildSettings );
222 #if OSL_DEBUG_LEVEL > 0
223 OString sMessage( "unknown element name '" );
224 sMessage += OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 );
225 sMessage += "', ignoring";
226 OSL_FAIL( sMessage.getStr() );
227 #endif
228 return new IgnoringSettingsImport;
231 void ConfigItemSetImport::getItemValue( Any& o_rValue ) const
233 o_rValue <<= m_aChildSettings.getPropertyValues();
236 } // namespace dbaccess
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */