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

Generated by: LCOV version 1.10