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