LCOV - code coverage report
Current view: top level - xmloff/source/forms - officeforms.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 61 65 93.8 %
Date: 2015-06-13 12:38:46 Functions: 11 16 68.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11