Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "officeforms.hxx"
21 :
22 : #include <sax/tools/converter.hxx>
23 :
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"
31 :
32 : namespace xmloff
33 : {
34 :
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;
41 :
42 : //= OFormsRootImport
43 0 : TYPEINIT1(OFormsRootImport, SvXMLImportContext);
44 0 : OFormsRootImport::OFormsRootImport( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName )
45 0 : :SvXMLImportContext(rImport, nPrfx, rLocalName)
46 : {
47 0 : }
48 :
49 0 : OFormsRootImport::~OFormsRootImport()
50 : {
51 0 : }
52 :
53 0 : SvXMLImportContext* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix, const OUString& _rLocalName,
54 : const Reference< XAttributeList>& xAttrList )
55 : {
56 0 : return GetImport().GetFormImport()->createContext( _nPrefix, _rLocalName, xAttrList );
57 : }
58 :
59 0 : void OFormsRootImport::implImportBool(const Reference< XAttributeList >& _rxAttributes, OfficeFormsAttributes _eAttribute,
60 : const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
61 : const OUString& _rPropName, sal_Bool _bDefault)
62 : {
63 : // the complete attribute name to look for
64 0 : OUString sCompleteAttributeName = GetImport().GetNamespaceMap().GetQNameByIndex(
65 0 : OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
66 0 : OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute)));
67 :
68 : // get and convert the value
69 0 : OUString sAttributeValue = _rxAttributes->getValueByName(sCompleteAttributeName);
70 0 : bool bValue = _bDefault;
71 0 : ::sax::Converter::convertBool(bValue, sAttributeValue);
72 :
73 : // set the property
74 0 : if (_rxPropInfo->hasPropertyByName(_rPropName))
75 : {
76 0 : _rxProps->setPropertyValue(_rPropName, makeAny(bValue));
77 0 : }
78 0 : }
79 :
80 0 : void OFormsRootImport::StartElement( const Reference< XAttributeList >& _rxAttrList )
81 : {
82 : ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
83 0 : SvXMLImportContext::StartElement( _rxAttrList );
84 :
85 : try
86 : {
87 0 : Reference< XPropertySet > xDocProperties(GetImport().GetModel(), UNO_QUERY);
88 0 : if ( xDocProperties.is() )
89 : { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
90 : // this is done via streaming the controls as XML.
91 0 : Reference< XPropertySetInfo > xDocPropInfo;
92 0 : if (xDocProperties.is())
93 0 : xDocPropInfo = xDocProperties->getPropertySetInfo();
94 :
95 0 : implImportBool(_rxAttrList, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False);
96 0 : implImportBool(_rxAttrList, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True);
97 0 : }
98 : }
99 0 : catch(Exception&)
100 : {
101 : OSL_FAIL("OFormsRootImport::StartElement: caught an exception while setting the document properties!");
102 : }
103 0 : }
104 :
105 0 : void OFormsRootImport::EndElement()
106 : {
107 0 : SvXMLImportContext::EndElement();
108 : LEAVE_LOG_CONTEXT( );
109 0 : }
110 :
111 : //= OFormsRootExport
112 0 : OFormsRootExport::OFormsRootExport( SvXMLExport& _rExp )
113 0 : :m_pImplElement(NULL)
114 : {
115 0 : addModelAttributes(_rExp);
116 :
117 0 : m_pImplElement = new SvXMLElementExport(_rExp, XML_NAMESPACE_OFFICE, XML_FORMS, true, true);
118 0 : }
119 :
120 0 : OFormsRootExport::~OFormsRootExport( )
121 : {
122 0 : delete m_pImplElement;
123 0 : }
124 :
125 0 : void OFormsRootExport::implExportBool(SvXMLExport& _rExp, OfficeFormsAttributes _eAttribute,
126 : const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
127 : const OUString& _rPropName, sal_Bool _bDefault)
128 : {
129 : // retrieve the property value
130 0 : sal_Bool bValue = _bDefault;
131 0 : if (_rxPropInfo->hasPropertyByName(_rPropName))
132 0 : bValue = ::cppu::any2bool(_rxProps->getPropertyValue(_rPropName));
133 :
134 : // convert into a string
135 0 : OUStringBuffer aValue;
136 0 : ::sax::Converter::convertBool(aValue, bValue);
137 :
138 : // add the attribute
139 : _rExp.AddAttribute(
140 0 : OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
141 : OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute),
142 0 : aValue.makeStringAndClear());
143 0 : }
144 :
145 0 : void OFormsRootExport::addModelAttributes(SvXMLExport& _rExp) SAL_THROW(())
146 : {
147 : try
148 : {
149 0 : Reference< XPropertySet > xDocProperties(_rExp.GetModel(), UNO_QUERY);
150 0 : if ( xDocProperties.is() )
151 : { // an empty model is allowed: when doing a copy'n'paste from e.g. Writer to Calc,
152 : // this is done via streaming the controls as XML.
153 0 : Reference< XPropertySetInfo > xDocPropInfo;
154 0 : if (xDocProperties.is())
155 0 : xDocPropInfo = xDocProperties->getPropertySetInfo();
156 :
157 0 : implExportBool(_rExp, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False);
158 0 : implExportBool(_rExp, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True);
159 0 : }
160 : }
161 0 : catch(Exception&)
162 : {
163 : OSL_FAIL("OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
164 : }
165 0 : }
166 :
167 : } // namespace xmloff
168 :
169 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|