LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlStyleImport.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 68 106 64.2 %
Date: 2014-04-11 Functions: 17 28 60.7 %
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 "xmlStyleImport.hxx"
      21             : 
      22             : #include <xmloff/nmspmap.hxx>
      23             : #include <xmloff/xmlnmspe.hxx>
      24             : #include <xmloff/xmlimppr.hxx>
      25             : #include <xmloff/families.hxx>
      26             : #include <xmloff/xmlnumfi.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      29             : #include <com/sun/star/container/XNameContainer.hpp>
      30             : #include <comphelper/extract.hxx>
      31             : #include <xmloff/xmlprcon.hxx>
      32             : #include <xmloff/xmluconv.hxx>
      33             : #include <osl/diagnose.h>
      34             : #include "xmlfilter.hxx"
      35             : #include "xmlHelper.hxx"
      36             : 
      37             : namespace dbaxml
      38             : {
      39             : 
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::xml::sax;
      43             : using namespace ::com::sun::star::style;
      44             : using namespace ::com::sun::star::frame;
      45             : using namespace ::com::sun::star::beans;
      46             : using namespace ::com::sun::star::container;
      47             : using namespace xmloff::token;
      48             : 
      49        1960 : TYPEINIT1( OTableStyleContext, XMLPropStyleContext );
      50           0 : TYPEINIT1( OTableStylesContext, SvXMLStylesContext );
      51             : 
      52          99 : OTableStyleContext::OTableStyleContext( ODBFilter& rImport,
      53             :         sal_uInt16 nPrfx, const OUString& rLName,
      54             :         const Reference< XAttributeList > & xAttrList,
      55             :         SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle )
      56             :     :XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle )
      57             :     ,sNumberFormat(OUString("NumberFormat"))
      58             :     ,pStyles(&rStyles)
      59          99 :     ,m_nNumberFormat(-1)
      60             : {
      61             : 
      62          99 : }
      63             : 
      64         198 : OTableStyleContext::~OTableStyleContext()
      65             : {
      66             : 
      67         198 : }
      68             : 
      69         735 : void OTableStyleContext::FillPropertySet(
      70             :             const Reference< XPropertySet > & rPropSet )
      71             : {
      72         735 :     if ( !IsDefaultStyle() )
      73             :     {
      74         735 :         if ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE )
      75             :         {
      76           0 :             if ( !sPageStyle.isEmpty() )
      77             :             {
      78           0 :                 uno::Any aAny;
      79           0 :                 aAny <<= sPageStyle;
      80           0 :                 AddProperty(CTF_DB_MASTERPAGENAME, aAny);
      81             :             }
      82             :         }
      83         735 :         else if ( GetFamily() == XML_STYLE_FAMILY_TABLE_COLUMN )
      84             :         {
      85         245 :             if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
      86             :             {
      87           2 :                 SvXMLNumFormatContext* pStyle = PTR_CAST(SvXMLNumFormatContext,pStyles->FindStyleChildContext(
      88             :                     XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, true));
      89           2 :                 if ( !pStyle )
      90             :                 {
      91           0 :                     OTableStylesContext* pMyStyles = PTR_CAST(OTableStylesContext,GetOwnImport().GetAutoStyles());
      92           0 :                     if ( pMyStyles )
      93           0 :                         pStyle = PTR_CAST(SvXMLNumFormatContext,pMyStyles->
      94           0 :                             FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, true));
      95             :                     else {
      96             :                         OSL_FAIL("not possible to get style");
      97             :                     }
      98             :                 }
      99           2 :                 if ( pStyle )
     100             :                 {
     101           2 :                     uno::Any aNumberFormat;
     102           2 :                     m_nNumberFormat = pStyle->GetKey();
     103           2 :                     aNumberFormat <<= m_nNumberFormat;
     104           2 :                     AddProperty(CTF_DB_NUMBERFORMAT, aNumberFormat);
     105             :                 }
     106             :             }
     107             :         }
     108             :     }
     109         735 :     XMLPropStyleContext::FillPropertySet(rPropSet);
     110         735 : }
     111             : 
     112           0 : void OTableStyleContext::SetDefaults()
     113             : {
     114           0 : }
     115             : 
     116           2 : void OTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
     117             : {
     118           2 :     sal_Int32 nIndex(static_cast<OTableStylesContext *>(pStyles)->GetIndex(nContextID));
     119             :     OSL_ENSURE(nIndex != -1, "Property not found in Map");
     120           2 :     XMLPropertyState aPropState(nIndex, rValue);
     121           2 :     GetProperties().push_back(aPropState); // has to be insertes in a sort order later
     122           2 : }
     123             : 
     124         200 : void OTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
     125             :                                         const OUString& rLocalName,
     126             :                                         const OUString& rValue )
     127             : {
     128             :     // TODO: use a map here
     129         200 :     if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
     130           2 :         m_sDataStyleName = rValue;
     131         198 :     else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
     132           0 :         sPageStyle = rValue;
     133             :     else
     134         198 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
     135         200 : }
     136             : 
     137           0 : ODBFilter& OTableStyleContext::GetOwnImport()
     138             : {
     139           0 :     return static_cast<ODBFilter&>(GetImport());
     140             : }
     141             : 
     142             : 
     143          14 : OTableStylesContext::OTableStylesContext( SvXMLImport& rImport,
     144             :                                           sal_uInt16 nPrfx ,
     145             :                                           const OUString& rLName ,
     146             :                                           const Reference< XAttributeList > & xAttrList,
     147             :                                           const sal_Bool bTempAutoStyles )
     148             :     : SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList )
     149             :     , sTableStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))
     150             :     , sColumnStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))
     151             :     , sCellStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ))
     152             :     , m_nNumberFormatIndex(-1)
     153             :     , m_nMasterPageNameIndex(-1)
     154          14 :     , bAutoStyles(bTempAutoStyles)
     155             : {
     156             : 
     157          14 : }
     158             : 
     159          28 : OTableStylesContext::~OTableStylesContext()
     160             : {
     161             : 
     162          28 : }
     163             : 
     164          14 : void OTableStylesContext::EndElement()
     165             : {
     166          14 :     SvXMLStylesContext::EndElement();
     167          14 :     if (bAutoStyles)
     168          14 :         GetImport().GetTextImport()->SetAutoStyles( this );
     169             :     else
     170           0 :         GetImport().GetStyles()->CopyStylesToDoc(true);
     171          14 : }
     172             : 
     173             : UniReference < SvXMLImportPropertyMapper >
     174         825 :     OTableStylesContext::GetImportPropertyMapper(
     175             :                     sal_uInt16 nFamily ) const
     176             : {
     177         825 :     UniReference < SvXMLImportPropertyMapper > xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
     178             : 
     179         825 :     if (!xMapper.is())
     180             :     {
     181         825 :         switch( nFamily )
     182             :         {
     183             :             case XML_STYLE_FAMILY_TABLE_TABLE:
     184             :             {
     185           0 :                 if ( !m_xTableImpPropMapper.is() )
     186           0 :                     m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     187           0 :                 xMapper = m_xTableImpPropMapper;
     188             :             }
     189           0 :              break;
     190             :             case XML_STYLE_FAMILY_TABLE_COLUMN:
     191             :             {
     192         326 :                 if ( !m_xColumnImpPropMapper.is() )
     193           9 :                     m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     194         326 :                 xMapper = m_xColumnImpPropMapper;
     195             :             }
     196         326 :              break;
     197             :             case XML_STYLE_FAMILY_TABLE_CELL:
     198             :             {
     199         499 :                 if ( !m_xCellImpPropMapper.is() )
     200           9 :                     m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     201         499 :                 xMapper = m_xCellImpPropMapper;
     202             :             }
     203         499 :              break;
     204             :         }
     205             :     }
     206             : 
     207         825 :     return xMapper;
     208             : }
     209             : 
     210          99 : SvXMLStyleContext *OTableStylesContext::CreateStyleStyleChildContext(
     211             :         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
     212             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     213             : {
     214             :     SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
     215             :                                                             rLocalName,
     216          99 :                                                             xAttrList );
     217          99 :     if (!pStyle)
     218             :     {
     219          99 :         switch( nFamily )
     220             :         {
     221             :         case XML_STYLE_FAMILY_TABLE_TABLE:
     222             :         case XML_STYLE_FAMILY_TABLE_COLUMN:
     223             :         case XML_STYLE_FAMILY_TABLE_CELL:
     224             :             pStyle = new OTableStyleContext( GetOwnImport(), nPrefix, rLocalName,
     225          99 :                                                xAttrList, *this, nFamily );
     226          99 :             break;
     227             :         }
     228             :     }
     229             : 
     230          99 :     return pStyle;
     231             : }
     232             : 
     233             : Reference < XNameContainer >
     234           0 :         OTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
     235             : {
     236           0 :     Reference < XNameContainer > xStyles = SvXMLStylesContext::GetStylesContainer(nFamily);
     237           0 :     return xStyles;
     238             : }
     239             : 
     240           0 : OUString OTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
     241             : {
     242           0 :     OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
     243           0 :     if (sServiceName.isEmpty())
     244             :     {
     245           0 :         switch( nFamily )
     246             :         {
     247             :         case XML_STYLE_FAMILY_TABLE_TABLE:
     248           0 :             sServiceName = sTableStyleServiceName;
     249           0 :             break;
     250             :         case XML_STYLE_FAMILY_TABLE_COLUMN:
     251           0 :             sServiceName = sColumnStyleServiceName;
     252           0 :             break;
     253             :         case XML_STYLE_FAMILY_TABLE_CELL:
     254           0 :             sServiceName = sCellStyleServiceName;
     255           0 :             break;
     256             : 
     257             :         }
     258             :     }
     259           0 :     return sServiceName;
     260             : }
     261             : 
     262           2 : sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID)
     263             : {
     264           2 :     if ( nContextID == CTF_DB_NUMBERFORMAT )
     265             :     {
     266           2 :         if (m_nNumberFormatIndex == -1)
     267             :             m_nNumberFormatIndex =
     268           1 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID);
     269           2 :         return m_nNumberFormatIndex;
     270             :     }
     271           0 :     else if ( nContextID == CTF_DB_MASTERPAGENAME )
     272             :     {
     273           0 :         if (m_nMasterPageNameIndex == -1)
     274             :             m_nMasterPageNameIndex =
     275           0 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
     276           0 :         return m_nMasterPageNameIndex;
     277             :     }
     278             :     else
     279           0 :         return -1;
     280             : }
     281             : 
     282         117 : ODBFilter& OTableStylesContext::GetOwnImport()
     283             : {
     284         117 :     return static_cast<ODBFilter&>(GetImport());
     285             : }
     286             : 
     287             : } // dbaxml
     288             : 
     289             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10