LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/forms - officeforms.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 62 48.4 %
Date: 2012-12-27 Functions: 6 16 37.5 %
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             : 
      21             : #include "officeforms.hxx"
      22             : 
      23             : #include <sax/tools/converter.hxx>
      24             : 
      25             : #include <xmloff/xmltoken.hxx>
      26             : #include "xmloff/xmlnmspe.hxx"
      27             : #include <xmloff/xmlexp.hxx>
      28             : #include <xmloff/xmlimp.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <comphelper/extract.hxx>
      31             : #include "strings.hxx"
      32             : #include <rtl/logfile.hxx>
      33             : 
      34             : //.........................................................................
      35             : namespace xmloff
      36             : {
      37             : //.........................................................................
      38             : 
      39             :     using namespace ::com::sun::star::uno;
      40             :     using namespace ::com::sun::star::beans;
      41             :     using namespace ::com::sun::star::frame;
      42             :     using namespace ::com::sun::star::xml;
      43             :     using ::xmloff::token::XML_FORMS;
      44             :     using ::com::sun::star::xml::sax::XAttributeList;
      45             : 
      46             :     //=========================================================================
      47             :     //= OFormsRootImport
      48             :     //=========================================================================
      49           0 :     TYPEINIT1(OFormsRootImport, SvXMLImportContext);
      50             :     //-------------------------------------------------------------------------
      51           2 :     OFormsRootImport::OFormsRootImport( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName )
      52           2 :         :SvXMLImportContext(rImport, nPrfx, rLocalName)
      53             :     {
      54           2 :     }
      55             : 
      56             :     //-------------------------------------------------------------------------
      57           4 :     OFormsRootImport::~OFormsRootImport()
      58             :     {
      59           4 :     }
      60             : 
      61             :     //-------------------------------------------------------------------------
      62           0 :     SvXMLImportContext* OFormsRootImport::CreateChildContext( sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
      63             :             const Reference< XAttributeList>& xAttrList )
      64             :     {
      65           0 :         return GetImport().GetFormImport()->createContext( _nPrefix, _rLocalName, xAttrList );
      66             :     }
      67             : 
      68             :     //-------------------------------------------------------------------------
      69           4 :     void OFormsRootImport::implImportBool(const Reference< XAttributeList >& _rxAttributes, OfficeFormsAttributes _eAttribute,
      70             :             const Reference< XPropertySet >& _rxProps, const Reference< XPropertySetInfo >& _rxPropInfo,
      71             :             const ::rtl::OUString& _rPropName, sal_Bool _bDefault)
      72             :     {
      73             :         // the complete attribute name to look for
      74           4 :         ::rtl::OUString sCompleteAttributeName = GetImport().GetNamespaceMap().GetQNameByIndex(
      75           4 :             OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
      76          12 :             ::rtl::OUString::createFromAscii(OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute)));
      77             : 
      78             :         // get and convert the value
      79           4 :         ::rtl::OUString sAttributeValue = _rxAttributes->getValueByName(sCompleteAttributeName);
      80           4 :         bool bValue = _bDefault;
      81           4 :         ::sax::Converter::convertBool(bValue, sAttributeValue);
      82             : 
      83             :         // set the property
      84           4 :         if (_rxPropInfo->hasPropertyByName(_rPropName))
      85             :         {
      86           4 :             _rxProps->setPropertyValue(_rPropName, makeAny(bValue));
      87           4 :         }
      88           4 :     }
      89             : 
      90             :     //-------------------------------------------------------------------------
      91           2 :     void OFormsRootImport::StartElement( const Reference< XAttributeList >& _rxAttrList )
      92             :     {
      93             :         ENTER_LOG_CONTEXT( "xmloff::OFormsRootImport - importing the complete tree" );
      94           2 :         SvXMLImportContext::StartElement( _rxAttrList );
      95             : 
      96             :         try
      97             :         {
      98           2 :             Reference< XPropertySet > xDocProperties(GetImport().GetModel(), UNO_QUERY);
      99           2 :             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           2 :                 Reference< XPropertySetInfo > xDocPropInfo;
     103           2 :                 if (xDocProperties.is())
     104           2 :                     xDocPropInfo = xDocProperties->getPropertySetInfo();
     105             : 
     106           2 :                 implImportBool(_rxAttrList, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False);
     107           2 :                 implImportBool(_rxAttrList, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True);
     108           2 :             }
     109             :         }
     110           0 :         catch(Exception&)
     111             :         {
     112             :             OSL_FAIL("OFormsRootImport::StartElement: caught an exception while setting the document properties!");
     113             :         }
     114           2 :     }
     115             : 
     116             :     //-------------------------------------------------------------------------
     117           2 :     void OFormsRootImport::EndElement()
     118             :     {
     119           2 :         SvXMLImportContext::EndElement();
     120             :         LEAVE_LOG_CONTEXT( );
     121           2 :     }
     122             : 
     123             :     //=====================================================================
     124             :     //= OFormsRootExport
     125             :     //=====================================================================
     126             :     //---------------------------------------------------------------------
     127           0 :     OFormsRootExport::OFormsRootExport( SvXMLExport& _rExp )
     128           0 :         :m_pImplElement(NULL)
     129             :     {
     130           0 :         addModelAttributes(_rExp);
     131             : 
     132           0 :         m_pImplElement = new SvXMLElementExport(_rExp, XML_NAMESPACE_OFFICE, XML_FORMS, sal_True, sal_True);
     133           0 :     }
     134             : 
     135             :     //---------------------------------------------------------------------
     136           0 :     OFormsRootExport::~OFormsRootExport( )
     137             :     {
     138           0 :         delete m_pImplElement;
     139           0 :     }
     140             : 
     141             :     //-------------------------------------------------------------------------
     142           0 :     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           0 :         sal_Bool bValue = _bDefault;
     148           0 :         if (_rxPropInfo->hasPropertyByName(_rPropName))
     149           0 :             bValue = ::cppu::any2bool(_rxProps->getPropertyValue(_rPropName));
     150             : 
     151             :         // convert into a string
     152           0 :         ::rtl::OUStringBuffer aValue;
     153           0 :         ::sax::Converter::convertBool(aValue, bValue);
     154             : 
     155             :         // add the attribute
     156             :         _rExp.AddAttribute(
     157           0 :             OAttributeMetaData::getOfficeFormsAttributeNamespace(_eAttribute),
     158             :             OAttributeMetaData::getOfficeFormsAttributeName(_eAttribute),
     159           0 :             aValue.makeStringAndClear());
     160           0 :     }
     161             : 
     162             :     //-------------------------------------------------------------------------
     163           0 :     void OFormsRootExport::addModelAttributes(SvXMLExport& _rExp) SAL_THROW(())
     164             :     {
     165             :         try
     166             :         {
     167           0 :             Reference< XPropertySet > xDocProperties(_rExp.GetModel(), UNO_QUERY);
     168           0 :             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           0 :                 Reference< XPropertySetInfo > xDocPropInfo;
     172           0 :                 if (xDocProperties.is())
     173           0 :                     xDocPropInfo = xDocProperties->getPropertySetInfo();
     174             : 
     175           0 :                 implExportBool(_rExp, ofaAutomaticFocus, xDocProperties, xDocPropInfo, PROPERTY_AUTOCONTROLFOCUS, sal_False);
     176           0 :                 implExportBool(_rExp, ofaApplyDesignMode, xDocProperties, xDocPropInfo, PROPERTY_APPLYDESIGNMODE, sal_True);
     177           0 :             }
     178             :         }
     179           0 :         catch(Exception&)
     180             :         {
     181             :             OSL_FAIL("OFormsRootExport::addModelAttributes: caught an exception while retrieving the document properties!");
     182             :         }
     183           0 :     }
     184             : 
     185             : //.........................................................................
     186             : }   // namespace xmloff
     187             : //.........................................................................
     188             : 
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10