Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "officeforms.hxx"
31 : :
32 : : #include <sax/tools/converter.hxx>
33 : :
34 : : #include <xmloff/xmltoken.hxx>
35 : : #include "xmloff/xmlnmspe.hxx"
36 : : #include <xmloff/xmlexp.hxx>
37 : : #include <xmloff/xmlimp.hxx>
38 : : #include <xmloff/nmspmap.hxx>
39 : : #include <comphelper/extract.hxx>
40 : : #include "strings.hxx"
41 : : #include <rtl/logfile.hxx>
42 : :
43 : : //.........................................................................
44 : : namespace xmloff
45 : : {
46 : : //.........................................................................
47 : :
48 : : using namespace ::com::sun::star::uno;
49 : : using namespace ::com::sun::star::beans;
50 : : using namespace ::com::sun::star::frame;
51 : : using namespace ::com::sun::star::xml;
52 : : using ::xmloff::token::XML_FORMS;
53 : : using ::com::sun::star::xml::sax::XAttributeList;
54 : :
55 : : //=========================================================================
56 : : //= OFormsRootImport
57 : : //=========================================================================
58 [ # # ][ # # ]: 0 : TYPEINIT1(OFormsRootImport, SvXMLImportContext);
59 : : //-------------------------------------------------------------------------
60 : 40 : OFormsRootImport::OFormsRootImport( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName )
61 : 40 : :SvXMLImportContext(rImport, nPrfx, rLocalName)
62 : : {
63 : 40 : }
64 : :
65 : : //-------------------------------------------------------------------------
66 : 40 : OFormsRootImport::~OFormsRootImport()
67 : : {
68 [ - + ]: 80 : }
69 : :
70 : : //-------------------------------------------------------------------------
71 : 12 : SvXMLImportContext* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
72 : : const Reference< XAttributeList>& xAttrList )
73 : : {
74 [ + - ][ + - ]: 12 : return GetImport().GetFormImport()->createContext( _nPrefix, _rLocalName, xAttrList );
75 : : }
76 : :
77 : : //-------------------------------------------------------------------------
78 : 80 : void OFormsRootImport::implImportBool(const Reference< XAttributeList >& _rxAttributes, OfficeFormsAttributes _eAttribute,
79 : : const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
80 : : const ::rtl::OUString& _rPropName, sal_Bool _bDefault)
81 : : {
82 : : // the complete attribute name to look for
83 : 80 : ::rtl::OUString sCompleteAttributeName = GetImport().GetNamespaceMap().GetQNameByIndex(
84 [ + - ]: 80 : OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
85 [ + - ][ + - ]: 160 : ::rtl::OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute)));
86 : :
87 : : // get and convert the value
88 [ + - ][ + - ]: 80 : ::rtl::OUString sAttributeValue = _rxAttributes->getValueByName(sCompleteAttributeName);
89 : 80 : bool bValue = _bDefault;
90 [ + - ]: 80 : ::sax::Converter::convertBool(bValue, sAttributeValue);
91 : :
92 : : // set the property
93 [ + - ][ + - ]: 80 : if (_rxPropInfo->hasPropertyByName(_rPropName))
[ + - ]
94 : : {
95 [ + - ][ + - ]: 80 : _rxProps->setPropertyValue(_rPropName, makeAny(bValue));
[ + - ]
96 : 80 : }
97 : 80 : }
98 : :
99 : : //-------------------------------------------------------------------------
100 : 40 : void OFormsRootImport::StartElement( const Reference< XAttributeList >& _rxAttrList )
101 : : {
102 : : ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
103 : 40 : SvXMLImportContext::StartElement( _rxAttrList );
104 : :
105 : : try
106 : : {
107 [ + - ]: 40 : Reference< XPropertySet > xDocProperties(GetImport().GetModel(), UNO_QUERY);
108 [ + - ]: 40 : if ( xDocProperties.is() )
109 : : { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
110 : : // this is done via streaming the controls as XML.
111 : 40 : Reference< XPropertySetInfo > xDocPropInfo;
112 [ + - ]: 40 : if (xDocProperties.is())
113 [ + - ][ + - ]: 40 : xDocPropInfo = xDocProperties->getPropertySetInfo();
[ + - ]
114 : :
115 [ + - ][ + - ]: 40 : implImportBool(_rxAttrList, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False);
116 [ + - ][ + - ]: 40 : implImportBool(_rxAttrList, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True);
117 [ # # ]: 40 : }
118 : : }
119 : 0 : catch(Exception&)
120 : : {
121 : : OSL_FAIL("OFormsRootImport::StartElement: caught an exception while setting the document properties!");
122 : : }
123 : 40 : }
124 : :
125 : : //-------------------------------------------------------------------------
126 : 40 : void OFormsRootImport::EndElement()
127 : : {
128 : 40 : SvXMLImportContext::EndElement();
129 : : LEAVE_LOG_CONTEXT( );
130 : 40 : }
131 : :
132 : : //=====================================================================
133 : : //= OFormsRootExport
134 : : //=====================================================================
135 : : //---------------------------------------------------------------------
136 : 0 : OFormsRootExport::OFormsRootExport( SvXMLExport& _rExp )
137 : 0 : :m_pImplElement(NULL)
138 : : {
139 : 0 : addModelAttributes(_rExp);
140 : :
141 [ # # ]: 0 : m_pImplElement = new SvXMLElementExport(_rExp, XML_NAMESPACE_OFFICE, XML_FORMS, sal_True, sal_True);
142 : 0 : }
143 : :
144 : : //---------------------------------------------------------------------
145 : 0 : OFormsRootExport::~OFormsRootExport( )
146 : : {
147 [ # # ]: 0 : delete m_pImplElement;
148 : 0 : }
149 : :
150 : : //-------------------------------------------------------------------------
151 : 0 : void OFormsRootExport::implExportBool(SvXMLExport& _rExp, OfficeFormsAttributes _eAttribute,
152 : : const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
153 : : const ::rtl::OUString& _rPropName, sal_Bool _bDefault)
154 : : {
155 : : // retrieve the property value
156 : 0 : sal_Bool bValue = _bDefault;
157 [ # # ][ # # ]: 0 : if (_rxPropInfo->hasPropertyByName(_rPropName))
[ # # ]
158 [ # # ][ # # ]: 0 : bValue = ::cppu::any2bool(_rxProps->getPropertyValue(_rPropName));
[ # # ]
159 : :
160 : : // convert into a string
161 : 0 : ::rtl::OUStringBuffer aValue;
162 [ # # ]: 0 : ::sax::Converter::convertBool(aValue, bValue);
163 : :
164 : : // add the attribute
165 : : _rExp.AddAttribute(
166 [ # # ]: 0 : OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
167 : : OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute),
168 [ # # ][ # # ]: 0 : aValue.makeStringAndClear());
[ # # ]
169 : 0 : }
170 : :
171 : : //-------------------------------------------------------------------------
172 : 0 : void OFormsRootExport::addModelAttributes(SvXMLExport& _rExp) SAL_THROW(())
173 : : {
174 : : try
175 : : {
176 [ # # ]: 0 : Reference< XPropertySet > xDocProperties(_rExp.GetModel(), UNO_QUERY);
177 [ # # ]: 0 : if ( xDocProperties.is() )
178 : : { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
179 : : // this is done via streaming the controls as XML.
180 : 0 : Reference< XPropertySetInfo > xDocPropInfo;
181 [ # # ]: 0 : if (xDocProperties.is())
182 [ # # ][ # # ]: 0 : xDocPropInfo = xDocProperties->getPropertySetInfo();
[ # # ]
183 : :
184 [ # # ][ # # ]: 0 : implExportBool(_rExp, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False);
185 [ # # ][ # # ]: 0 : implExportBool(_rExp, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True);
186 [ # # ]: 0 : }
187 : : }
188 : 0 : catch(Exception&)
189 : : {
190 : : OSL_FAIL("OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
191 : : }
192 : 0 : }
193 : :
194 : : //.........................................................................
195 : : } // namespace xmloff
196 : : //.........................................................................
197 : :
198 : :
199 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|