1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: officeforms.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "officeforms.hxx"
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmlexp.hxx>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/nmspmap.hxx>
40 #include <comphelper/extract.hxx>
41 #include "strings.hxx"
42 #include <rtl/logfile.hxx>
44 //.........................................................................
47 //.........................................................................
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star::frame
;
52 using namespace ::com::sun::star::xml
;
53 using ::xmloff::token::XML_FORMS
;
55 //=========================================================================
57 //=========================================================================
58 TYPEINIT1(OFormsRootImport
, SvXMLImportContext
);
59 //-------------------------------------------------------------------------
60 OFormsRootImport::OFormsRootImport( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const rtl::OUString
& rLocalName
)
61 :SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
65 //-------------------------------------------------------------------------
66 OFormsRootImport::~OFormsRootImport()
70 //-------------------------------------------------------------------------
71 SvXMLImportContext
* OFormsRootImport::CreateChildContext( USHORT _nPrefix
, const ::rtl::OUString
& _rLocalName
,
72 const Reference
< sax::XAttributeList
>& xAttrList
)
74 return GetImport().GetFormImport()->createContext( _nPrefix
, _rLocalName
, xAttrList
);
77 //-------------------------------------------------------------------------
78 void OFormsRootImport::implImportBool(const Reference
< sax::XAttributeList
>& _rxAttributes
, OfficeFormsAttributes _eAttribute
,
79 const Reference
< XPropertySet
>& _rxProps
, const Reference
< XPropertySetInfo
>& _rxPropInfo
,
80 const ::rtl::OUString
& _rPropName
, sal_Bool _bDefault
)
82 // the complete attribute name to look for
83 ::rtl::OUString sCompleteAttributeName
= GetImport().GetNamespaceMap().GetQNameByIndex(
84 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute
),
85 ::rtl::OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute
)));
87 // get and convert the value
88 ::rtl::OUString sAttributeValue
= _rxAttributes
->getValueByName(sCompleteAttributeName
);
89 sal_Bool bValue
= _bDefault
;
90 GetImport().GetMM100UnitConverter().convertBool(bValue
, sAttributeValue
);
93 if (_rxPropInfo
->hasPropertyByName(_rPropName
))
94 _rxProps
->setPropertyValue(_rPropName
, ::cppu::bool2any(bValue
));
97 //-------------------------------------------------------------------------
98 void OFormsRootImport::StartElement( const Reference
< sax::XAttributeList
>& _rxAttrList
)
100 ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
101 SvXMLImportContext::StartElement( _rxAttrList
);
105 Reference
< XPropertySet
> xDocProperties(GetImport().GetModel(), UNO_QUERY
);
106 if ( xDocProperties
.is() )
107 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
108 // this is done via streaming the controls as XML.
109 Reference
< XPropertySetInfo
> xDocPropInfo
;
110 if (xDocProperties
.is())
111 xDocPropInfo
= xDocProperties
->getPropertySetInfo();
113 implImportBool(_rxAttrList
, ofaAutomaticFocus
, xDocProperties
, xDocPropInfo
, PROPERTY_AUTOCONTROLFOCUS
, sal_False
);
114 implImportBool(_rxAttrList
, ofaApplyDesignMode
, xDocProperties
, xDocPropInfo
, PROPERTY_APPLYDESIGNMODE
, sal_True
);
119 OSL_ENSURE(sal_False
, "OFormsRootImport::StartElement: caught an exception while setting the document properties!");
123 //-------------------------------------------------------------------------
124 void OFormsRootImport::EndElement()
126 SvXMLImportContext::EndElement();
127 LEAVE_LOG_CONTEXT( );
130 //=====================================================================
132 //=====================================================================
133 //---------------------------------------------------------------------
134 OFormsRootExport::OFormsRootExport( SvXMLExport
& _rExp
)
135 :m_pImplElement(NULL
)
137 addModelAttributes(_rExp
);
139 m_pImplElement
= new SvXMLElementExport(_rExp
, XML_NAMESPACE_OFFICE
, XML_FORMS
, sal_True
, sal_True
);
142 //---------------------------------------------------------------------
143 OFormsRootExport::~OFormsRootExport( )
145 delete m_pImplElement
;
148 //-------------------------------------------------------------------------
149 void OFormsRootExport::implExportBool(SvXMLExport
& _rExp
, OfficeFormsAttributes _eAttribute
,
150 const Reference
< XPropertySet
>& _rxProps
, const Reference
< XPropertySetInfo
>& _rxPropInfo
,
151 const ::rtl::OUString
& _rPropName
, sal_Bool _bDefault
)
153 // retrieve the property value
154 sal_Bool bValue
= _bDefault
;
155 if (_rxPropInfo
->hasPropertyByName(_rPropName
))
156 bValue
= ::cppu::any2bool(_rxProps
->getPropertyValue(_rPropName
));
158 // convert into a string
159 ::rtl::OUStringBuffer aValue
;
160 _rExp
.GetMM100UnitConverter().convertBool(aValue
, bValue
);
164 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute
),
165 OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute
),
166 aValue
.makeStringAndClear());
169 //-------------------------------------------------------------------------
170 void OFormsRootExport::addModelAttributes(SvXMLExport
& _rExp
) SAL_THROW(())
174 Reference
< XPropertySet
> xDocProperties(_rExp
.GetModel(), UNO_QUERY
);
175 if ( xDocProperties
.is() )
176 { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
177 // this is done via streaming the controls as XML.
178 Reference
< XPropertySetInfo
> xDocPropInfo
;
179 if (xDocProperties
.is())
180 xDocPropInfo
= xDocProperties
->getPropertySetInfo();
182 implExportBool(_rExp
, ofaAutomaticFocus
, xDocProperties
, xDocPropInfo
, PROPERTY_AUTOCONTROLFOCUS
, sal_False
);
183 implExportBool(_rExp
, ofaApplyDesignMode
, xDocProperties
, xDocPropInfo
, PROPERTY_APPLYDESIGNMODE
, sal_True
);
188 OSL_ENSURE(sal_False
, "OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
192 //.........................................................................
193 } // namespace xmloff
194 //.........................................................................