1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include "officeforms.hxx" 27 #include <xmloff/xmluconv.hxx> 28 #include <xmloff/xmltoken.hxx> 29 #include "xmloff/xmlnmspe.hxx" 30 #include <xmloff/xmlexp.hxx> 31 #include <xmloff/xmlimp.hxx> 32 #include <xmloff/nmspmap.hxx> 33 #include <comphelper/extract.hxx> 34 #include "strings.hxx" 35 #include <rtl/logfile.hxx> 36 37 //......................................................................... 38 namespace xmloff 39 { 40 //......................................................................... 41 42 using namespace ::com::sun::star::uno; 43 using namespace ::com::sun::star::beans; 44 using namespace ::com::sun::star::frame; 45 using namespace ::com::sun::star::xml; 46 using ::xmloff::token::XML_FORMS; 47 48 //========================================================================= 49 //= OFormsRootImport 50 //========================================================================= 51 TYPEINIT1(OFormsRootImport, SvXMLImportContext); 52 //------------------------------------------------------------------------- OFormsRootImport(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLocalName)53 OFormsRootImport::OFormsRootImport( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName ) 54 :SvXMLImportContext(rImport, nPrfx, rLocalName) 55 { 56 } 57 58 //------------------------------------------------------------------------- ~OFormsRootImport()59 OFormsRootImport::~OFormsRootImport() 60 { 61 } 62 63 //------------------------------------------------------------------------- CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const Reference<sax::XAttributeList> & xAttrList)64 SvXMLImportContext* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, 65 const Reference< sax::XAttributeList>& xAttrList ) 66 { 67 return GetImport().GetFormImport()->createContext( _nPrefix, _rLocalName, xAttrList ); 68 } 69 70 //------------------------------------------------------------------------- implImportBool(const Reference<sax::XAttributeList> & _rxAttributes,OfficeFormsAttributes _eAttribute,const Reference<XPropertySet> & _rxProps,const Reference<XPropertySetInfo> & _rxPropInfo,const::rtl::OUString & _rPropName,sal_Bool _bDefault)71 void OFormsRootImport::implImportBool(const Reference< sax::XAttributeList >& _rxAttributes, OfficeFormsAttributes _eAttribute, 72 const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo, 73 const ::rtl::OUString& _rPropName, sal_Bool _bDefault) 74 { 75 // the complete attribute name to look for 76 ::rtl::OUString sCompleteAttributeName = GetImport().GetNamespaceMap().GetQNameByIndex( 77 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute), 78 ::rtl::OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute))); 79 80 // get and convert the value 81 ::rtl::OUString sAttributeValue = _rxAttributes->getValueByName(sCompleteAttributeName); 82 sal_Bool bValue = _bDefault; 83 GetImport().GetMM100UnitConverter().convertBool(bValue, sAttributeValue); 84 85 // set the property 86 if (_rxPropInfo->hasPropertyByName(_rPropName)) 87 _rxProps->setPropertyValue(_rPropName, ::cppu::bool2any(bValue)); 88 } 89 90 //------------------------------------------------------------------------- StartElement(const Reference<sax::XAttributeList> & _rxAttrList)91 void OFormsRootImport::StartElement( const Reference< sax::XAttributeList >& _rxAttrList ) 92 { 93 ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" ); 94 SvXMLImportContext::StartElement( _rxAttrList ); 95 96 try 97 { 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(); 105 106 implImportBool(_rxAttrList, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False); 107 implImportBool(_rxAttrList, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True); 108 } 109 } 110 catch(Exception&) 111 { 112 OSL_ENSURE(sal_False, "OFormsRootImport::StartElement: caught an exception while setting the document properties!"); 113 } 114 } 115 116 //------------------------------------------------------------------------- EndElement()117 void OFormsRootImport::EndElement() 118 { 119 SvXMLImportContext::EndElement(); 120 LEAVE_LOG_CONTEXT( ); 121 } 122 123 //===================================================================== 124 //= OFormsRootExport 125 //===================================================================== 126 //--------------------------------------------------------------------- OFormsRootExport(SvXMLExport & _rExp)127 OFormsRootExport::OFormsRootExport( SvXMLExport& _rExp ) 128 :m_pImplElement(NULL) 129 { 130 addModelAttributes(_rExp); 131 132 m_pImplElement = new SvXMLElementExport(_rExp, XML_NAMESPACE_OFFICE, XML_FORMS, sal_True, sal_True); 133 } 134 135 //--------------------------------------------------------------------- ~OFormsRootExport()136 OFormsRootExport::~OFormsRootExport( ) 137 { 138 delete m_pImplElement; 139 } 140 141 //------------------------------------------------------------------------- implExportBool(SvXMLExport & _rExp,OfficeFormsAttributes _eAttribute,const Reference<XPropertySet> & _rxProps,const Reference<XPropertySetInfo> & _rxPropInfo,const::rtl::OUString & _rPropName,sal_Bool _bDefault)142 void OFormsRootExport::implExportBool(SvXMLExport& _rExp, OfficeFormsAttributes _eAttribute, 143 const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo, 144 const ::rtl::OUString& _rPropName, sal_Bool _bDefault) 145 { 146 // retrieve the property value 147 sal_Bool bValue = _bDefault; 148 if (_rxPropInfo->hasPropertyByName(_rPropName)) 149 bValue = ::cppu::any2bool(_rxProps->getPropertyValue(_rPropName)); 150 151 // convert into a string 152 ::rtl::OUStringBuffer aValue; 153 _rExp.GetMM100UnitConverter().convertBool(aValue, bValue); 154 155 // add the attribute 156 _rExp.AddAttribute( 157 OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute), 158 OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute), 159 aValue.makeStringAndClear()); 160 } 161 162 //------------------------------------------------------------------------- addModelAttributes(SvXMLExport & _rExp)163 void OFormsRootExport::addModelAttributes(SvXMLExport& _rExp) SAL_THROW(()) 164 { 165 try 166 { 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(); 174 175 implExportBool(_rExp, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False); 176 implExportBool(_rExp, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True); 177 } 178 } 179 catch(Exception&) 180 { 181 OSL_ENSURE(sal_False, "OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!"); 182 } 183 } 184 185 //......................................................................... 186 } // namespace xmloff 187 //......................................................................... 188 189 190