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 106 : OFormsRootImport::OFormsRootImport( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName )
45 106 : :SvXMLImportContext(rImport, nPrfx, rLocalName)
46 : {
47 106 : }
48 :
49 212 : OFormsRootImport::~OFormsRootImport()
50 : {
51 212 : }
52 :
53 18 : SvXMLImportContext* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix, const OUString& _rLocalName,
54 : const Reference< XAttributeList>& xAttrList )
55 : {
56 18 : return GetImport().GetFormImport()->createContext( _nPrefix, _rLocalName, xAttrList );
57 : }
58 :
59 212 : void OFormsRootImport::implImportBool(const Reference< XAttributeList >& _rxAttributes, OfficeFormsAttributes _eAttribute,
60 : const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
61 : const OUString& _rPropName, bool _bDefault)
62 : {
63 : // the complete attribute name to look for
64 212 : OUString sCompleteAttributeName = GetImport().GetNamespaceMap().GetQNameByIndex(
65 212 : OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
66 636 : OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute)));
67 :
68 : // get and convert the value
69 424 : OUString sAttributeValue = _rxAttributes->getValueByName(sCompleteAttributeName);
70 212 : bool bValue = _bDefault;
71 212 : ::sax::Converter::convertBool(bValue, sAttributeValue);
72 :
73 : // set the property
74 212 : if (_rxPropInfo->hasPropertyByName(_rPropName))
75 : {
76 212 : _rxProps->setPropertyValue(_rPropName, makeAny(bValue));
77 212 : }
78 212 : }
79 :
80 106 : void OFormsRootImport::StartElement( const Reference< XAttributeList >& _rxAttrList )
81 : {
82 : ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
83 106 : SvXMLImportContext::StartElement( _rxAttrList );
84 :
85 : try
86 : {
87 106 : Reference< XPropertySet > xDocProperties(GetImport().GetModel(), UNO_QUERY);
88 106 : 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 106 : Reference< XPropertySetInfo > xDocPropInfo;
92 106 : if (xDocProperties.is())
93 106 : xDocPropInfo = xDocProperties->getPropertySetInfo();
94 :
95 106 : implImportBool(_rxAttrList, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, false);
96 106 : implImportBool(_rxAttrList, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, true);
97 106 : }
98 : }
99 0 : catch(Exception&)
100 : {
101 : OSL_FAIL("OFormsRootImport::StartElement: caught an exception while setting the document properties!");
102 : }
103 106 : }
104 :
105 106 : void OFormsRootImport::EndElement()
106 : {
107 106 : SvXMLImportContext::EndElement();
108 : LEAVE_LOG_CONTEXT( );
109 106 : }
110 :
111 : //= OFormsRootExport
112 2 : OFormsRootExport::OFormsRootExport( SvXMLExport& _rExp )
113 2 : :m_pImplElement(NULL)
114 : {
115 2 : addModelAttributes(_rExp);
116 :
117 2 : m_pImplElement = new SvXMLElementExport(_rExp, XML_NAMESPACE_OFFICE, XML_FORMS, true, true);
118 2 : }
119 :
120 2 : OFormsRootExport::~OFormsRootExport( )
121 : {
122 2 : delete m_pImplElement;
123 2 : }
124 :
125 4 : void OFormsRootExport::implExportBool(SvXMLExport& _rExp, OfficeFormsAttributes _eAttribute,
126 : const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
127 : const OUString& _rPropName, bool _bDefault)
128 : {
129 : // retrieve the property value
130 4 : bool bValue = _bDefault;
131 4 : if (_rxPropInfo->hasPropertyByName(_rPropName))
132 4 : bValue = ::cppu::any2bool(_rxProps->getPropertyValue(_rPropName));
133 :
134 : // convert into a string
135 4 : OUStringBuffer aValue;
136 4 : ::sax::Converter::convertBool(aValue, bValue);
137 :
138 : // add the attribute
139 : _rExp.AddAttribute(
140 4 : OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
141 : OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute),
142 8 : aValue.makeStringAndClear());
143 4 : }
144 :
145 2 : void OFormsRootExport::addModelAttributes(SvXMLExport& _rExp)
146 : {
147 : try
148 : {
149 2 : Reference< XPropertySet > xDocProperties(_rExp.GetModel(), UNO_QUERY);
150 2 : 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 2 : Reference< XPropertySetInfo > xDocPropInfo;
154 2 : if (xDocProperties.is())
155 2 : xDocPropInfo = xDocProperties->getPropertySetInfo();
156 :
157 2 : implExportBool(_rExp, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, false);
158 2 : implExportBool(_rExp, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, true);
159 2 : }
160 : }
161 0 : catch(Exception&)
162 : {
163 : OSL_FAIL("OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
164 : }
165 2 : }
166 :
167 : } // namespace xmloff
168 :
169 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|