LCOV - code coverage report
Current view: top level - reportdesign/source/filter/xml - xmlStyleImport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 166 0.0 %
Date: 2014-11-03 Functions: 0 32 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             : #include "xmlStyleImport.hxx"
      20             : #include <xmloff/nmspmap.hxx>
      21             : #include <xmloff/xmlnmspe.hxx>
      22             : #include <xmloff/xmlimppr.hxx>
      23             : #include <xmloff/txtimppr.hxx>
      24             : #include <xmloff/families.hxx>
      25             : #include <xmloff/xmlnumfi.hxx>
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      28             : #include <com/sun/star/container/XNameContainer.hpp>
      29             : #include <comphelper/extract.hxx>
      30             : #include <xmloff/xmlprcon.hxx>
      31             : #include <xmloff/xmluconv.hxx>
      32             : #include <xmloff/XMLGraphicsDefaultStyle.hxx>
      33             : #include <tools/debug.hxx>
      34             : #include "xmlfilter.hxx"
      35             : #include "xmlHelper.hxx"
      36             : #include <osl/diagnose.h>
      37             : 
      38             : namespace rptxml
      39             : {
      40             : 
      41             : using namespace ::com::sun::star;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::com::sun::star::xml::sax;
      44             : using namespace ::com::sun::star::style;
      45             : using namespace ::com::sun::star::frame;
      46             : using namespace ::com::sun::star::beans;
      47             : using namespace ::com::sun::star::container;
      48             : using namespace xmloff::token;
      49             : 
      50             : 
      51             : 
      52           0 : class OSpecialHanldeXMLImportPropertyMapper : public SvXMLImportPropertyMapper
      53             : {
      54             : public:
      55           0 :     OSpecialHanldeXMLImportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper,SvXMLImport& _rImport) : SvXMLImportPropertyMapper(rMapper ,_rImport)
      56             :     {
      57           0 :     }
      58             :     /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
      59           0 :     virtual bool handleSpecialItem(
      60             :             XMLPropertyState& /*rProperty*/,
      61             :             ::std::vector< XMLPropertyState >& /*rProperties*/,
      62             :             const OUString& /*rValue*/,
      63             :             const SvXMLUnitConverter& /*rUnitConverter*/,
      64             :             const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const SAL_OVERRIDE
      65             :     {
      66             :         // nothing to do here
      67           0 :         return true;
      68             :     }
      69             : };
      70             : 
      71           0 : TYPEINIT1( OControlStyleContext, XMLPropStyleContext );
      72           0 : TYPEINIT1( OReportStylesContext, SvXMLStylesContext );
      73             : 
      74           0 : OControlStyleContext::OControlStyleContext( ORptFilter& rImport,
      75             :         sal_uInt16 nPrfx, const OUString& rLName,
      76             :         const Reference< XAttributeList > & xAttrList,
      77             :         SvXMLStylesContext& rStyles, sal_uInt16 nFamily, bool bDefaultStyle ) :
      78             :     XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
      79             :     sNumberFormat(OUString("NumberFormat")),
      80             :     pStyles(&rStyles),
      81             :     m_nNumberFormat(-1),
      82             :     m_rImport(rImport),
      83             :     bConditionalFormatCreated(false),
      84           0 :     bParentSet(false)
      85             : {
      86             : 
      87           0 : }
      88             : 
      89             : 
      90           0 : OControlStyleContext::~OControlStyleContext()
      91             : {
      92             : 
      93           0 : }
      94             : 
      95             : 
      96           0 : void OControlStyleContext::FillPropertySet(const Reference< XPropertySet > & rPropSet )
      97             : {
      98           0 :     if ( !IsDefaultStyle() )
      99             :     {
     100           0 :         if ( GetFamily() == XML_STYLE_FAMILY_TABLE_CELL )
     101             :         {
     102           0 :             if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty())
     103             :             {
     104             :                 SvXMLNumFormatContext* pStyle = const_cast< SvXMLNumFormatContext*>(dynamic_cast<const SvXMLNumFormatContext*>(pStyles->FindStyleChildContext(
     105           0 :                     XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, false)));
     106           0 :                 if ( !pStyle )
     107             :                 {
     108           0 :                     OReportStylesContext* pMyStyles = PTR_CAST(OReportStylesContext,GetOwnImport().GetAutoStyles());
     109           0 :                     if ( pMyStyles )
     110           0 :                         pStyle = const_cast<SvXMLNumFormatContext*>(PTR_CAST(SvXMLNumFormatContext,pMyStyles->
     111           0 :                             FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, true)));
     112             :                     else {
     113             :                         OSL_FAIL("not possible to get style");
     114             :                     }
     115             :                 }
     116           0 :                 if ( pStyle )
     117             :                 {
     118           0 :                     m_nNumberFormat = pStyle->GetKey();
     119           0 :                     AddProperty(CTF_RPT_NUMBERFORMAT, uno::makeAny(m_nNumberFormat));
     120             :                 }
     121             :             }
     122             :         }
     123             :     }
     124           0 :     XMLPropStyleContext::FillPropertySet(rPropSet);
     125           0 : }
     126             : 
     127           0 : void OControlStyleContext::SetDefaults()
     128             : {
     129           0 : }
     130             : 
     131             : 
     132           0 : void OControlStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
     133             : {
     134           0 :     sal_Int32 nIndex(static_cast<OReportStylesContext *>(pStyles)->GetIndex(nContextID));
     135             :     OSL_ENSURE(nIndex != -1, "Property not found in Map");
     136           0 :     XMLPropertyState aPropState(nIndex, rValue);
     137           0 :     GetProperties().push_back(aPropState); // has to be insertes in a sort order later
     138           0 : }
     139             : 
     140           0 : void OControlStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
     141             :                                         const OUString& rLocalName,
     142             :                                         const OUString& rValue )
     143             : {
     144             :     // TODO: use a map here
     145           0 :     if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
     146           0 :         m_sDataStyleName = rValue;
     147           0 :     else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
     148           0 :         sPageStyle = rValue;
     149             :     else
     150           0 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
     151           0 : }
     152             : 
     153             : 
     154             : 
     155           0 : OReportStylesContext::OReportStylesContext( ORptFilter& rImport,
     156             :         sal_uInt16 nPrfx ,
     157             :         const OUString& rLName ,
     158             :         const Reference< XAttributeList > & xAttrList,
     159             :         const bool bTempAutoStyles ) :
     160             :     SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
     161             :     m_sTableStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME )),
     162             :     m_sColumnStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME )),
     163             :     m_sRowStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME )),
     164             :     m_sCellStyleFamilyName( OUString( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME )),
     165             :     m_rImport(rImport),
     166             :     m_nNumberFormatIndex(-1),
     167           0 :     bAutoStyles(bTempAutoStyles)
     168             : {
     169             : 
     170           0 : }
     171             : 
     172             : 
     173           0 : OReportStylesContext::~OReportStylesContext()
     174             : {
     175             : 
     176           0 : }
     177             : 
     178             : 
     179           0 : void OReportStylesContext::EndElement()
     180             : {
     181           0 :     SvXMLStylesContext::EndElement();
     182           0 :     if (bAutoStyles)
     183           0 :         GetImport().GetTextImport()->SetAutoStyles( this );
     184             :     else
     185           0 :         GetImport().GetStyles()->CopyStylesToDoc(true);
     186           0 : }
     187             : 
     188             : 
     189             : rtl::Reference < SvXMLImportPropertyMapper >
     190           0 :     OReportStylesContext::GetImportPropertyMapper(
     191             :                     sal_uInt16 nFamily ) const
     192             : {
     193           0 :     rtl::Reference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily));
     194             : 
     195           0 :     if (!xMapper.is())
     196             :     {
     197           0 :         ORptFilter& rImport = GetOwnImport();
     198           0 :         switch( nFamily )
     199             :         {
     200             :             case XML_STYLE_FAMILY_TABLE_CELL:
     201             :             {
     202           0 :                 if( !m_xCellImpPropMapper.is() )
     203             :                 {
     204           0 :                     m_xCellImpPropMapper =
     205           0 :                         new XMLTextImportPropertyMapper/*OSpecialHanldeXMLImportPropertyMapper*/( rImport.GetCellStylesPropertySetMapper(), m_rImport );
     206             : 
     207           0 :                     m_xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(m_rImport));
     208             :                 }
     209           0 :                 xMapper = m_xCellImpPropMapper;
     210             :             }
     211           0 :             break;
     212             :             case XML_STYLE_FAMILY_TABLE_COLUMN:
     213             :             {
     214           0 :                 if( !m_xColumnImpPropMapper.is() )
     215           0 :                     m_xColumnImpPropMapper =
     216           0 :                         new SvXMLImportPropertyMapper( rImport.GetColumnStylesPropertySetMapper(), m_rImport );
     217             : 
     218           0 :                 xMapper = m_xColumnImpPropMapper;
     219             :             }
     220           0 :              break;
     221             :             case XML_STYLE_FAMILY_TABLE_ROW:
     222             :             {
     223           0 :                 if( !m_xRowImpPropMapper.is() )
     224           0 :                     m_xRowImpPropMapper =new OSpecialHanldeXMLImportPropertyMapper( rImport.GetRowStylesPropertySetMapper(), m_rImport );
     225           0 :                 xMapper = m_xRowImpPropMapper;
     226             :             }
     227           0 :              break;
     228             :             case XML_STYLE_FAMILY_TABLE_TABLE:
     229             :             {
     230           0 :                 if( !m_xTableImpPropMapper.is() )
     231             :                 {
     232           0 :                     rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory();
     233           0 :                     m_xTableImpPropMapper = new SvXMLImportPropertyMapper( new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(), xFac, false), m_rImport );
     234             :                 }
     235           0 :                 xMapper = m_xTableImpPropMapper;
     236             :             }
     237           0 :              break;
     238             :             default:
     239           0 :                 break;
     240             :         }
     241             :     }
     242             : 
     243           0 :     return xMapper;
     244             : }
     245             : 
     246           0 : SvXMLStyleContext *OReportStylesContext::CreateDefaultStyleStyleChildContext(
     247             :         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
     248             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     249             : {
     250           0 :     SvXMLStyleContext *pStyle = 0;
     251             : 
     252           0 :     switch( nFamily )
     253             :     {
     254             :         case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
     255             :             // There are no writer specific defaults for graphic styles!
     256           0 :             pStyle = new XMLGraphicsDefaultStyle( GetImport(), nPrefix,
     257           0 :                                 rLocalName, xAttrList, *this );
     258           0 :             break;
     259             :         default:
     260             :             pStyle = SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily,
     261             :                                                                        nPrefix,
     262             :                                                                 rLocalName,
     263           0 :                                                                 xAttrList );
     264           0 :             break;
     265             :     }
     266           0 :     return pStyle;
     267             : }
     268             : 
     269           0 : SvXMLStyleContext *OReportStylesContext::CreateStyleStyleChildContext(
     270             :         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
     271             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     272             : {
     273             :     SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
     274             :                                                             rLocalName,
     275           0 :                                                             xAttrList );
     276           0 :     if (!pStyle)
     277             :     {
     278           0 :         switch( nFamily )
     279             :         {
     280             :         case XML_STYLE_FAMILY_TABLE_TABLE:
     281             :         case XML_STYLE_FAMILY_TABLE_COLUMN:
     282             :         case XML_STYLE_FAMILY_TABLE_ROW:
     283             :         case XML_STYLE_FAMILY_TABLE_CELL:
     284             :             pStyle = new OControlStyleContext( GetOwnImport(), nPrefix, rLocalName,
     285           0 :                                                xAttrList, *this, nFamily );
     286           0 :             break;
     287             :         default:
     288             :             OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. PLease check.");
     289           0 :             break;
     290             :         }
     291             :     }
     292             : 
     293           0 :     return pStyle;
     294             : }
     295             : 
     296             : Reference < XNameContainer >
     297           0 :         OReportStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
     298             : {
     299           0 :     Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
     300           0 :     if (!xStyles.is())
     301             :     {
     302           0 :      OUString sName;
     303           0 :         switch( nFamily )
     304             :         {
     305             :             case XML_STYLE_FAMILY_TABLE_TABLE:
     306             :             {
     307           0 :                 if( m_xTableStyles.is() )
     308           0 :                     xStyles.set(m_xTableStyles);
     309             :                 else
     310           0 :                     sName =
     311           0 :                      OUString( OUString( "TableStyles" ));
     312             :             }
     313           0 :             break;
     314             :             case XML_STYLE_FAMILY_TABLE_CELL:
     315             :             {
     316           0 :                 if( m_xCellStyles.is() )
     317           0 :                     xStyles.set(m_xCellStyles);
     318             :                 else
     319           0 :                     sName =
     320           0 :                      OUString( OUString( "CellStyles" ));
     321             :             }
     322           0 :             break;
     323             :             case XML_STYLE_FAMILY_TABLE_COLUMN:
     324             :             {
     325           0 :                 if( m_xColumnStyles.is() )
     326           0 :                     xStyles.set(m_xColumnStyles);
     327             :                 else
     328           0 :                     sName =
     329           0 :                      OUString( OUString( "ColumnStyles" ));
     330             :             }
     331           0 :             break;
     332             :             case XML_STYLE_FAMILY_TABLE_ROW:
     333             :             {
     334           0 :                 if( m_xRowStyles.is() )
     335           0 :                     xStyles.set(m_xRowStyles);
     336             :                 else
     337           0 :                     sName =
     338           0 :                      OUString( OUString( "RowStyles" ));
     339             :             }
     340           0 :             break;
     341             :             case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
     342           0 :                 xStyles = ((SvXMLImport *)&GetImport())->GetTextImport()->GetFrameStyles();
     343           0 :                 break;
     344             :             default:
     345             :                 OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. PLease check.");
     346           0 :                 break;
     347             :         }
     348           0 :         if( !xStyles.is() && !sName.isEmpty() && GetOwnImport().GetModel().is() )
     349             :         {
     350             :             Reference< XStyleFamiliesSupplier > xFamiliesSupp(
     351           0 :                                             GetOwnImport().GetModel(), UNO_QUERY );
     352           0 :             if (xFamiliesSupp.is())
     353             :             {
     354           0 :                 Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
     355             : 
     356           0 :                 xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
     357           0 :                 switch( nFamily )
     358             :                 {
     359             :                 case XML_STYLE_FAMILY_TABLE_TABLE:
     360           0 :                     m_xTableStyles.set(xStyles);
     361           0 :                     break;
     362             :                 case XML_STYLE_FAMILY_TABLE_CELL:
     363           0 :                     m_xCellStyles.set(xStyles);
     364           0 :                     break;
     365             :                 case XML_STYLE_FAMILY_TABLE_COLUMN:
     366           0 :                     m_xColumnStyles.set(xStyles);
     367           0 :                     break;
     368             :                 case XML_STYLE_FAMILY_TABLE_ROW:
     369           0 :                     m_xRowStyles.set(xStyles);
     370           0 :                     break;
     371             :                     default:
     372           0 :                         break;
     373           0 :                 }
     374           0 :             }
     375           0 :         }
     376             :     }
     377             : 
     378           0 :     return xStyles;
     379             : }
     380             : 
     381             : 
     382           0 : OUString OReportStylesContext::GetServiceName( sal_uInt16 nFamily ) const
     383             : {
     384           0 :     OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
     385           0 :     if (sServiceName.isEmpty())
     386             :     {
     387           0 :         switch( nFamily )
     388             :         {
     389             :             case XML_STYLE_FAMILY_TABLE_TABLE:
     390           0 :                 sServiceName = m_sTableStyleFamilyName;
     391           0 :                 break;
     392             :             case XML_STYLE_FAMILY_TABLE_COLUMN:
     393           0 :                 sServiceName = m_sColumnStyleFamilyName;
     394           0 :                 break;
     395             :             case XML_STYLE_FAMILY_TABLE_ROW:
     396           0 :                 sServiceName = m_sRowStyleFamilyName;
     397           0 :                 break;
     398             :             case XML_STYLE_FAMILY_TABLE_CELL:
     399           0 :                 sServiceName = m_sCellStyleFamilyName;
     400           0 :                 break;
     401             :             default:
     402           0 :                 break;
     403             :         }
     404             :     }
     405           0 :     return sServiceName;
     406             : }
     407             : 
     408             : 
     409           0 : sal_Int32 OReportStylesContext::GetIndex(const sal_Int16 nContextID)
     410             : {
     411           0 :     if ( nContextID == CTF_RPT_NUMBERFORMAT )
     412             :     {
     413           0 :         if (m_nNumberFormatIndex == -1)
     414             :             m_nNumberFormatIndex =
     415           0 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
     416           0 :         return m_nNumberFormatIndex;
     417             :     }
     418           0 :     return -1;
     419             : }
     420             : 
     421             : 
     422           0 : sal_uInt16 OReportStylesContext::GetFamily( const OUString& rFamily ) const
     423             : {
     424           0 :     sal_uInt16 nFamily = SvXMLStylesContext::GetFamily(rFamily);
     425           0 :     return nFamily;
     426             : }
     427             : 
     428             : } // rptxml
     429             : 
     430             : 
     431             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10