LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/draw - layerimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 48 68.8 %
Date: 2013-07-09 Functions: 8 14 57.1 %
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 <tools/debug.hxx>
      22             : #include <com/sun/star/drawing/XLayerManager.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      25             : #include <com/sun/star/drawing/XLayerSupplier.hpp>
      26             : #include <comphelper/extract.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmlimp.hxx>
      29             : #include "xmloff/xmlnmspe.hxx"
      30             : #include <xmloff/xmluconv.hxx>
      31             : #include <xmloff/nmspmap.hxx>
      32             : #include "layerimp.hxx"
      33             : 
      34             : 
      35             : #include "XMLStringBufferImportContext.hxx"
      36             : 
      37             : using namespace ::std;
      38             : using namespace ::cppu;
      39             : using namespace ::xmloff::token;
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::xml;
      42             : using namespace ::com::sun::star::xml::sax;
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star::drawing;
      45             : using namespace ::com::sun::star::beans;
      46             : using namespace ::com::sun::star::lang;
      47             : using namespace ::com::sun::star::container;
      48             : using ::xmloff::token::IsXMLToken;
      49             : 
      50             : class SdXMLLayerContext : public SvXMLImportContext
      51             : {
      52             : public:
      53             :     SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager );
      54             :     virtual ~SdXMLLayerContext();
      55             : 
      56             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
      57             :     virtual void EndElement();
      58             : 
      59             : private:
      60             :     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxLayerManager;
      61             :     OUString msName;
      62             :     OUStringBuffer sDescriptionBuffer;
      63             :     OUStringBuffer sTitleBuffer;
      64             : };
      65             : 
      66          35 : SdXMLLayerContext::SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager )
      67             : : SvXMLImportContext(rImport, nPrefix, rLocalName)
      68          35 : , mxLayerManager( xLayerManager )
      69             : {
      70          35 :     const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      71          35 :     for(sal_Int16 i=0; i < nAttrCount; i++)
      72             :     {
      73          35 :         OUString aLocalName;
      74          35 :         if( GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( i ), &aLocalName ) == XML_NAMESPACE_DRAW )
      75             :         {
      76          35 :             const OUString sValue( xAttrList->getValueByIndex( i ) );
      77             : 
      78          35 :             if( IsXMLToken( aLocalName, XML_NAME ) )
      79             :             {
      80          35 :                 msName = sValue;
      81          35 :                 break; // no more attributes needed
      82           0 :             }
      83             :         }
      84           0 :     }
      85             : 
      86          35 : }
      87             : 
      88          70 : SdXMLLayerContext::~SdXMLLayerContext()
      89             : {
      90          70 : }
      91             : 
      92           0 : SvXMLImportContext * SdXMLLayerContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& )
      93             : {
      94           0 :     if( (XML_NAMESPACE_SVG == nPrefix) && IsXMLToken(rLocalName, XML_TITLE) )
      95             :     {
      96           0 :         return new XMLStringBufferImportContext( GetImport(), nPrefix, rLocalName, sTitleBuffer);
      97             :     }
      98           0 :     else if( (XML_NAMESPACE_SVG == nPrefix) && IsXMLToken(rLocalName, XML_DESC) )
      99             :     {
     100           0 :         return new XMLStringBufferImportContext( GetImport(), nPrefix, rLocalName, sDescriptionBuffer);
     101             :     }
     102             :     else
     103             :     {
     104           0 :         return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     105             :     }
     106             : }
     107             : 
     108          35 : void SdXMLLayerContext::EndElement()
     109             : {
     110             :     DBG_ASSERT( !msName.isEmpty(), "xmloff::SdXMLLayerContext::EndElement(), draw:layer element without draw:name!" );
     111          35 :     if( !msName.isEmpty() ) try
     112             :     {
     113          35 :         Reference< XPropertySet > xLayer;
     114             : 
     115          35 :         if( mxLayerManager->hasByName( msName ) )
     116             :         {
     117          35 :             mxLayerManager->getByName( msName ) >>= xLayer;
     118             :             DBG_ASSERT( xLayer.is(), "xmloff::SdXMLLayerContext::EndElement(), failed to get existing XLayer!" );
     119             :         }
     120             :         else
     121             :         {
     122           0 :             Reference< XLayerManager > xLayerManager( mxLayerManager, UNO_QUERY );
     123           0 :             if( xLayerManager.is() )
     124           0 :                 xLayer = Reference< XPropertySet >::query( xLayerManager->insertNewByIndex( xLayerManager->getCount() ) );
     125             :             DBG_ASSERT( xLayer.is(), "xmloff::SdXMLLayerContext::EndElement(), failed to create new XLayer!" );
     126             : 
     127           0 :             if( xLayer.is() )
     128           0 :                 xLayer->setPropertyValue("Name", Any( msName ) );
     129             :         }
     130             : 
     131          35 :         if( xLayer.is() )
     132             :         {
     133          35 :             xLayer->setPropertyValue("Title", Any( sTitleBuffer.makeStringAndClear() ) );
     134          35 :             xLayer->setPropertyValue("Description", Any( sDescriptionBuffer.makeStringAndClear() ) );
     135          35 :         }
     136             :     }
     137           0 :     catch( Exception& )
     138             :     {
     139             :         OSL_FAIL("SdXMLLayerContext::EndElement(), exception caught!");
     140             :     }
     141          35 : }
     142             : 
     143             : 
     144           0 : TYPEINIT1( SdXMLLayerSetContext, SvXMLImportContext );
     145             : 
     146           7 : SdXMLLayerSetContext::SdXMLLayerSetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
     147             :         const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>&)
     148           7 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
     149             : {
     150           7 :     Reference< XLayerSupplier > xLayerSupplier( rImport.GetModel(), UNO_QUERY );
     151             :     DBG_ASSERT( xLayerSupplier.is(), "xmloff::SdXMLLayerSetContext::SdXMLLayerSetContext(), XModel is not supporting XLayerSupplier!" );
     152           7 :     if( xLayerSupplier.is() )
     153           7 :         mxLayerManager = xLayerSupplier->getLayerManager();
     154           7 : }
     155             : 
     156          14 : SdXMLLayerSetContext::~SdXMLLayerSetContext()
     157             : {
     158          14 : }
     159             : 
     160          35 : SvXMLImportContext * SdXMLLayerSetContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
     161             :         const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
     162             : {
     163          35 :     return new SdXMLLayerContext( GetImport(), nPrefix, rLocalName, xAttrList, mxLayerManager );
     164             : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10