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 .
21 #include "officeforms.hxx"
23 #include <sax/tools/converter.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include "xmloff/xmlnmspe.hxx"
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include <comphelper/extract.hxx>
31 #include "strings.hxx"
32 #include <rtl/logfile.hxx>
34 //.........................................................................
37 //.........................................................................
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::frame
;
42 using namespace ::com::sun::star::xml
;
43 using ::xmloff::token::XML_FORMS
;
44 using ::com::sun::star::xml::sax::XAttributeList
;
46 //=========================================================================
48 //=========================================================================
49 TYPEINIT1(OFormsRootImport
, SvXMLImportContext
);
50 //-------------------------------------------------------------------------
51 OFormsRootImport::OFormsRootImport( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLocalName
)
52 :SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
56 //-------------------------------------------------------------------------
57 OFormsRootImport::~OFormsRootImport()
61 //-------------------------------------------------------------------------
62 SvXMLImportContext
* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
63 const Reference
< XAttributeList
>& xAttrList
)
65 return GetImport().GetFormImport()->createContext( _nPrefix
, _rLocalName
, xAttrList
);
68 //-------------------------------------------------------------------------
69 void OFormsRootImport::implImportBool(const Reference
< XAttributeList
>& _rxAttributes
, OfficeFormsAttributes _eAttribute
,
70 const Reference
< XPropertySet
>& _rxProps
, const Reference
< XPropertySetInfo
>& _rxPropInfo
,
71 const OUString
& _rPropName
, sal_Bool _bDefault
)
73 // the complete attribute name to look for
74 OUString sCompleteAttributeName
= GetImport().GetNamespaceMap().GetQNameByIndex(
75 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute
),
76 OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute
)));
78 // get and convert the value
79 OUString sAttributeValue
= _rxAttributes
->getValueByName(sCompleteAttributeName
);
80 bool bValue
= _bDefault
;
81 ::sax::Converter::convertBool(bValue
, sAttributeValue
);
84 if (_rxPropInfo
->hasPropertyByName(_rPropName
))
86 _rxProps
->setPropertyValue(_rPropName
, makeAny(bValue
));
90 //-------------------------------------------------------------------------
91 void OFormsRootImport::StartElement( const Reference
< XAttributeList
>& _rxAttrList
)
93 ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
94 SvXMLImportContext::StartElement( _rxAttrList
);
98 Reference
< XPropertySet
> xDocProperties(GetImport().GetModel(), UNO_QUERY
);
99 if ( xDocProperties
.is() )
100 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
101 // this is done via streaming the controls as XML.
102 Reference
< XPropertySetInfo
> xDocPropInfo
;
103 if (xDocProperties
.is())
104 xDocPropInfo
= xDocProperties
->getPropertySetInfo();
106 implImportBool(_rxAttrList
, ofaAutomaticFocus
, xDocProperties
, xDocPropInfo
, PROPERTY_AUTOCONTROLFOCUS
, sal_False
);
107 implImportBool(_rxAttrList
, ofaApplyDesignMode
, xDocProperties
, xDocPropInfo
, PROPERTY_APPLYDESIGNMODE
, sal_True
);
112 OSL_FAIL("OFormsRootImport::StartElement: caught an exception while setting the document properties!");
116 //-------------------------------------------------------------------------
117 void OFormsRootImport::EndElement()
119 SvXMLImportContext::EndElement();
120 LEAVE_LOG_CONTEXT( );
123 //=====================================================================
125 //=====================================================================
126 //---------------------------------------------------------------------
127 OFormsRootExport::OFormsRootExport( SvXMLExport
& _rExp
)
128 :m_pImplElement(NULL
)
130 addModelAttributes(_rExp
);
132 m_pImplElement
= new SvXMLElementExport(_rExp
, XML_NAMESPACE_OFFICE
, XML_FORMS
, sal_True
, sal_True
);
135 //---------------------------------------------------------------------
136 OFormsRootExport::~OFormsRootExport( )
138 delete m_pImplElement
;
141 //-------------------------------------------------------------------------
142 void OFormsRootExport::implExportBool(SvXMLExport
& _rExp
, OfficeFormsAttributes _eAttribute
,
143 const Reference
< XPropertySet
>& _rxProps
, const Reference
< XPropertySetInfo
>& _rxPropInfo
,
144 const OUString
& _rPropName
, sal_Bool _bDefault
)
146 // retrieve the property value
147 sal_Bool bValue
= _bDefault
;
148 if (_rxPropInfo
->hasPropertyByName(_rPropName
))
149 bValue
= ::cppu::any2bool(_rxProps
->getPropertyValue(_rPropName
));
151 // convert into a string
152 OUStringBuffer aValue
;
153 ::sax::Converter::convertBool(aValue
, bValue
);
157 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute
),
158 OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute
),
159 aValue
.makeStringAndClear());
162 //-------------------------------------------------------------------------
163 void OFormsRootExport::addModelAttributes(SvXMLExport
& _rExp
) SAL_THROW(())
167 Reference
< XPropertySet
> xDocProperties(_rExp
.GetModel(), UNO_QUERY
);
168 if ( xDocProperties
.is() )
169 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
170 // this is done via streaming the controls as XML.
171 Reference
< XPropertySetInfo
> xDocPropInfo
;
172 if (xDocProperties
.is())
173 xDocPropInfo
= xDocProperties
->getPropertySetInfo();
175 implExportBool(_rExp
, ofaAutomaticFocus
, xDocProperties
, xDocPropInfo
, PROPERTY_AUTOCONTROLFOCUS
, sal_False
);
176 implExportBool(_rExp
, ofaApplyDesignMode
, xDocProperties
, xDocPropInfo
, PROPERTY_APPLYDESIGNMODE
, sal_True
);
181 OSL_FAIL("OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
185 //.........................................................................
186 } // namespace xmloff
187 //.........................................................................
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */