LCOV - code coverage report
Current view: top level - xmloff/source/draw - layerimp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 48 0.0 %
Date: 2014-04-14 Functions: 0 14 0.0 %
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 ) SAL_OVERRIDE;
      57             :     virtual void EndElement() SAL_OVERRIDE;
      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           0 : SdXMLLayerContext::SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager )
      67             : : SvXMLImportContext(rImport, nPrefix, rLocalName)
      68           0 : , mxLayerManager( xLayerManager )
      69             : {
      70           0 :     const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      71           0 :     for(sal_Int16 i=0; i < nAttrCount; i++)
      72             :     {
      73           0 :         OUString aLocalName;
      74           0 :         if( GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( i ), &aLocalName ) == XML_NAMESPACE_DRAW )
      75             :         {
      76           0 :             const OUString sValue( xAttrList->getValueByIndex( i ) );
      77             : 
      78           0 :             if( IsXMLToken( aLocalName, XML_NAME ) )
      79             :             {
      80           0 :                 msName = sValue;
      81           0 :                 break; // no more attributes needed
      82           0 :             }
      83             :         }
      84           0 :     }
      85             : 
      86           0 : }
      87             : 
      88           0 : SdXMLLayerContext::~SdXMLLayerContext()
      89             : {
      90           0 : }
      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           0 : void SdXMLLayerContext::EndElement()
     109             : {
     110             :     DBG_ASSERT( !msName.isEmpty(), "xmloff::SdXMLLayerContext::EndElement(), draw:layer element without draw:name!" );
     111           0 :     if( !msName.isEmpty() ) try
     112             :     {
     113           0 :         Reference< XPropertySet > xLayer;
     114             : 
     115           0 :         if( mxLayerManager->hasByName( msName ) )
     116             :         {
     117           0 :             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           0 :         if( xLayer.is() )
     132             :         {
     133           0 :             xLayer->setPropertyValue("Title", Any( sTitleBuffer.makeStringAndClear() ) );
     134           0 :             xLayer->setPropertyValue("Description", Any( sDescriptionBuffer.makeStringAndClear() ) );
     135           0 :         }
     136             :     }
     137           0 :     catch( Exception& )
     138             :     {
     139             :         OSL_FAIL("SdXMLLayerContext::EndElement(), exception caught!");
     140             :     }
     141           0 : }
     142             : 
     143             : 
     144           0 : TYPEINIT1( SdXMLLayerSetContext, SvXMLImportContext );
     145             : 
     146           0 : SdXMLLayerSetContext::SdXMLLayerSetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,
     147             :         const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>&)
     148           0 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
     149             : {
     150           0 :     Reference< XLayerSupplier > xLayerSupplier( rImport.GetModel(), UNO_QUERY );
     151             :     DBG_ASSERT( xLayerSupplier.is(), "xmloff::SdXMLLayerSetContext::SdXMLLayerSetContext(), XModel is not supporting XLayerSupplier!" );
     152           0 :     if( xLayerSupplier.is() )
     153           0 :         mxLayerManager = xLayerSupplier->getLayerManager();
     154           0 : }
     155             : 
     156           0 : SdXMLLayerSetContext::~SdXMLLayerSetContext()
     157             : {
     158           0 : }
     159             : 
     160           0 : 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           0 :     return new SdXMLLayerContext( GetImport(), nPrefix, rLocalName, xAttrList, mxLayerManager );
     164             : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10