bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / forms / officeforms.cxx
blobe289e78671e26388a00b379857c9f05eb4157263
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 "officeforms.hxx"
22 #include <sax/tools/converter.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 #include <xmloff/xmlexp.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include <comphelper/extract.hxx>
30 #include "strings.hxx"
32 namespace xmloff
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::frame;
38 using namespace ::com::sun::star::xml;
39 using ::xmloff::token::XML_FORMS;
40 using ::com::sun::star::xml::sax::XAttributeList;
42 //= OFormsRootImport
43 TYPEINIT1(OFormsRootImport, SvXMLImportContext);
44 OFormsRootImport::OFormsRootImport( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName )
45 :SvXMLImportContext(rImport, nPrfx, rLocalName)
49 OFormsRootImport::~OFormsRootImport()
53 SvXMLImportContext* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix, const OUString& _rLocalName,
54 const Reference< XAttributeList>& xAttrList )
56 SvXMLImportContext* pRet = 0;
57 try
59 pRet = GetImport().GetFormImport()->createContext( _nPrefix, _rLocalName, xAttrList );
60 } catch (const Exception& rException)
62 SAL_WARN("xmloff.forms", "OFormsRootImport::CreateChildContext: " << rException.Message);
64 return pRet;
67 void OFormsRootImport::implImportBool(const Reference< XAttributeList >& _rxAttributes, OfficeFormsAttributes _eAttribute,
68 const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
69 const OUString& _rPropName, bool _bDefault)
71 // the complete attribute name to look for
72 OUString sCompleteAttributeName = GetImport().GetNamespaceMap().GetQNameByIndex(
73 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
74 OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute)));
76 // get and convert the value
77 OUString sAttributeValue = _rxAttributes->getValueByName(sCompleteAttributeName);
78 bool bValue = _bDefault;
79 ::sax::Converter::convertBool(bValue, sAttributeValue);
81 // set the property
82 if (_rxPropInfo->hasPropertyByName(_rPropName))
84 _rxProps->setPropertyValue(_rPropName, makeAny(bValue));
88 void OFormsRootImport::StartElement( const Reference< XAttributeList >& _rxAttrList )
90 ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
91 SvXMLImportContext::StartElement( _rxAttrList );
93 try
95 Reference< XPropertySet > xDocProperties(GetImport().GetModel(), UNO_QUERY);
96 if ( xDocProperties.is() )
97 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
98 // this is done via streaming the controls as XML.
99 Reference< XPropertySetInfo > xDocPropInfo;
100 if (xDocProperties.is())
101 xDocPropInfo = xDocProperties->getPropertySetInfo();
103 implImportBool(_rxAttrList, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, false);
104 implImportBool(_rxAttrList, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, true);
107 catch(Exception&)
109 OSL_FAIL("OFormsRootImport::StartElement: caught an exception while setting the document properties!");
113 void OFormsRootImport::EndElement()
115 SvXMLImportContext::EndElement();
116 LEAVE_LOG_CONTEXT( );
119 //= OFormsRootExport
120 OFormsRootExport::OFormsRootExport( SvXMLExport& _rExp )
121 :m_pImplElement(NULL)
123 addModelAttributes(_rExp);
125 m_pImplElement = new SvXMLElementExport(_rExp, XML_NAMESPACE_OFFICE, XML_FORMS, true, true);
128 OFormsRootExport::~OFormsRootExport( )
130 delete m_pImplElement;
133 void OFormsRootExport::implExportBool(SvXMLExport& _rExp, OfficeFormsAttributes _eAttribute,
134 const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
135 const OUString& _rPropName, bool _bDefault)
137 // retrieve the property value
138 bool bValue = _bDefault;
139 if (_rxPropInfo->hasPropertyByName(_rPropName))
140 bValue = ::cppu::any2bool(_rxProps->getPropertyValue(_rPropName));
142 // convert into a string
143 OUStringBuffer aValue;
144 ::sax::Converter::convertBool(aValue, bValue);
146 // add the attribute
147 _rExp.AddAttribute(
148 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
149 OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute),
150 aValue.makeStringAndClear());
153 void OFormsRootExport::addModelAttributes(SvXMLExport& _rExp)
157 Reference< XPropertySet > xDocProperties(_rExp.GetModel(), UNO_QUERY);
158 if ( xDocProperties.is() )
159 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
160 // this is done via streaming the controls as XML.
161 Reference< XPropertySetInfo > xDocPropInfo;
162 if (xDocProperties.is())
163 xDocPropInfo = xDocProperties->getPropertySetInfo();
165 implExportBool(_rExp, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, false);
166 implExportBool(_rExp, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, true);
169 catch(Exception&)
171 OSL_FAIL("OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
175 } // namespace xmloff
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */