1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xmlnamespace.hxx>
26 #include <xmloff/xmlexp.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <comphelper/extract.hxx>
30 #include <comphelper/diagnose_ex.hxx>
31 #include "strings.hxx"
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::xml
;
39 using ::xmloff::token::XML_FORMS
;
40 using ::com::sun::star::xml::sax::XFastAttributeList
;
43 OFormsRootImport::OFormsRootImport( SvXMLImport
& rImport
)
44 :SvXMLImportContext(rImport
)
48 OFormsRootImport::~OFormsRootImport()
52 css::uno::Reference
< css::xml::sax::XFastContextHandler
> OFormsRootImport::createFastChildContext(
54 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
56 SvXMLImportContext
* pRet
= nullptr;
59 pRet
= GetImport().GetFormImport()->createContext( _nElement
, xAttrList
);
60 } catch (const Exception
&)
62 DBG_UNHANDLED_EXCEPTION("xmloff.forms");
67 void OFormsRootImport::implImportBool(const Reference
< XFastAttributeList
>& _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 sal_Int32 nCompleteAttributeName
= XML_ELEMENT(
74 OAttributeMetaData::getOfficeFormsAttributeToken(_eAttribute
));
76 // get and convert the value
77 OUString sAttributeValue
= _rxAttributes
->getOptionalValue(nCompleteAttributeName
);
78 bool bValue
= _bDefault
;
79 (void)::sax::Converter::convertBool(bValue
, sAttributeValue
);
82 if (_rxPropInfo
->hasPropertyByName(_rPropName
))
84 _rxProps
->setPropertyValue(_rPropName
, Any(bValue
));
88 void OFormsRootImport::startFastElement( sal_Int32
/*nElement*/, const Reference
< XFastAttributeList
>& _rxAttrList
)
90 ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
94 Reference
< XPropertySet
> xDocProperties(GetImport().GetModel(), UNO_QUERY
);
95 if ( xDocProperties
.is() )
96 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
97 // this is done via streaming the controls as XML.
98 Reference
< XPropertySetInfo
> xDocPropInfo
;
99 if (xDocProperties
.is())
100 xDocPropInfo
= xDocProperties
->getPropertySetInfo();
102 implImportBool(_rxAttrList
, ofaAutomaticFocus
, xDocProperties
, xDocPropInfo
, PROPERTY_AUTOCONTROLFOCUS
, false);
103 implImportBool(_rxAttrList
, ofaApplyDesignMode
, xDocProperties
, xDocPropInfo
, PROPERTY_APPLYDESIGNMODE
, true);
108 TOOLS_WARN_EXCEPTION("xmloff.forms",
109 "caught an exception while setting the document properties!");
113 void OFormsRootImport::endFastElement(sal_Int32
)
115 LEAVE_LOG_CONTEXT( );
119 OFormsRootExport::OFormsRootExport( SvXMLExport
& _rExp
)
121 addModelAttributes(_rExp
);
123 m_pImplElement
.reset( new SvXMLElementExport(_rExp
, XML_NAMESPACE_OFFICE
, XML_FORMS
, true, true) );
126 OFormsRootExport::~OFormsRootExport( )
130 void OFormsRootExport::implExportBool(SvXMLExport
& _rExp
, OfficeFormsAttributes _eAttribute
,
131 const Reference
< XPropertySet
>& _rxProps
, const Reference
< XPropertySetInfo
>& _rxPropInfo
,
132 const OUString
& _rPropName
, bool _bDefault
)
134 // retrieve the property value
135 bool bValue
= _bDefault
;
136 if (_rxPropInfo
->hasPropertyByName(_rPropName
))
137 bValue
= ::cppu::any2bool(_rxProps
->getPropertyValue(_rPropName
));
139 // convert into a string
140 OUStringBuffer aValue
;
141 ::sax::Converter::convertBool(aValue
, bValue
);
145 OAttributeMetaData::getOfficeFormsAttributeNamespace(),
146 OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute
),
147 aValue
.makeStringAndClear());
150 void OFormsRootExport::addModelAttributes(SvXMLExport
& _rExp
)
154 Reference
< XPropertySet
> xDocProperties(_rExp
.GetModel(), UNO_QUERY
);
155 if ( xDocProperties
.is() )
156 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
157 // this is done via streaming the controls as XML.
158 Reference
< XPropertySetInfo
> xDocPropInfo
;
159 if (xDocProperties
.is())
160 xDocPropInfo
= xDocProperties
->getPropertySetInfo();
162 implExportBool(_rExp
, ofaAutomaticFocus
, xDocProperties
, xDocPropInfo
, PROPERTY_AUTOCONTROLFOCUS
, false);
163 implExportBool(_rExp
, ofaApplyDesignMode
, xDocProperties
, xDocPropInfo
, PROPERTY_APPLYDESIGNMODE
, true);
168 TOOLS_WARN_EXCEPTION("xmloff.forms",
169 "caught an exception while retrieving the document properties!");
173 } // namespace xmloff
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */