LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/text - XMLIndexTOCStylesContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 49 0.0 %
Date: 2012-12-27 Functions: 0 11 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             : #include "XMLIndexTOCStylesContext.hxx"
      21             : #include <com/sun/star/beans/XPropertySet.hpp>
      22             : #include <com/sun/star/container/XIndexReplace.hpp>
      23             : #include <xmloff/xmlictxt.hxx>
      24             : #include <xmloff/xmlimp.hxx>
      25             : #include <xmloff/txtimp.hxx>
      26             : #include "xmloff/xmlnmspe.hxx"
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include <xmloff/xmltoken.hxx>
      29             : #include <sax/tools/converter.hxx>
      30             : #include <com/sun/star/uno/Sequence.hxx>
      31             : #include <rtl/ustring.hxx>
      32             : 
      33             : 
      34             : using namespace ::xmloff::token;
      35             : 
      36             : using ::rtl::OUString;
      37             : using ::com::sun::star::beans::XPropertySet;
      38             : using ::com::sun::star::uno::Reference;
      39             : using ::com::sun::star::uno::Sequence;
      40             : using ::com::sun::star::uno::Any;
      41             : using ::com::sun::star::container::XIndexReplace;
      42             : using ::com::sun::star::xml::sax::XAttributeList;
      43             : 
      44             : 
      45             : const sal_Char sAPI_LevelParagraphStyles[] = "LevelParagraphStyles";
      46             : 
      47           0 : TYPEINIT1( XMLIndexTOCStylesContext, SvXMLImportContext );
      48             : 
      49             : 
      50           0 : XMLIndexTOCStylesContext::XMLIndexTOCStylesContext(
      51             :     SvXMLImport& rImport,
      52             :     Reference<XPropertySet> & rPropSet,
      53             :     sal_uInt16 nPrfx,
      54             :     const OUString& rLocalName )
      55             : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
      56             : ,   sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_LevelParagraphStyles))
      57           0 : ,   rTOCPropertySet(rPropSet)
      58             : {
      59           0 : }
      60             : 
      61           0 : XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext()
      62             : {
      63           0 : }
      64             : 
      65           0 : void XMLIndexTOCStylesContext::StartElement(
      66             :     const Reference<XAttributeList> & xAttrList )
      67             : {
      68             :     // find text:outline-level attribute
      69           0 :     sal_Int16 nCount = xAttrList->getLength();
      70           0 :     for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
      71             :     {
      72           0 :         OUString sLocalName;
      73           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      74           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      75           0 :                               &sLocalName );
      76           0 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
      77           0 :              (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) )
      78             :         {
      79             :             sal_Int32 nTmp;
      80           0 :             if (::sax::Converter::convertNumber(
      81           0 :                     nTmp, xAttrList->getValueByIndex(nAttr), 1,
      82           0 :                     GetImport().GetTextImport()->GetChapterNumbering()->
      83           0 :                                                                 getCount()))
      84             :             {
      85             :                 // API numbers 0..9, we number 1..10
      86           0 :                 nOutlineLevel = nTmp-1;
      87             :             }
      88             :         }
      89           0 :     }
      90           0 : }
      91             : 
      92           0 : void XMLIndexTOCStylesContext::EndElement()
      93             : {
      94             :     // if valid...
      95           0 :     if (nOutlineLevel >= 0)
      96             :     {
      97             :         // copy vector into sequence
      98           0 :         const sal_Int32 nCount = aStyleNames.size();
      99           0 :         Sequence<OUString> aStyleNamesSequence(nCount);
     100           0 :         for(sal_Int32 i = 0; i < nCount; i++)
     101             :         {
     102           0 :             aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
     103             :                             XML_STYLE_FAMILY_TEXT_PARAGRAPH,
     104           0 :                                aStyleNames[i] );
     105             :         }
     106             : 
     107             :         // get index replace
     108           0 :         Any aAny = rTOCPropertySet->getPropertyValue(sLevelParagraphStyles);
     109           0 :         Reference<XIndexReplace> xIndexReplace;
     110           0 :         aAny >>= xIndexReplace;
     111             : 
     112             :         // set style names
     113           0 :         aAny <<= aStyleNamesSequence;
     114           0 :         xIndexReplace->replaceByIndex(nOutlineLevel, aAny);
     115             :     }
     116           0 : }
     117             : 
     118           0 : SvXMLImportContext *XMLIndexTOCStylesContext::CreateChildContext(
     119             :     sal_uInt16 p_nPrefix,
     120             :     const OUString& rLocalName,
     121             :     const Reference<XAttributeList> & xAttrList )
     122             : {
     123             :     // check for index-source-style
     124           0 :     if ( (XML_NAMESPACE_TEXT == p_nPrefix) &&
     125           0 :          IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) )
     126             :     {
     127             :         // find text:style-name attribute and record in aStyleNames
     128           0 :         sal_Int16 nCount = xAttrList->getLength();
     129           0 :         for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
     130             :         {
     131           0 :             OUString sLocalName;
     132           0 :             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     133           0 :                 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     134           0 :                                   &sLocalName );
     135           0 :             if ( (XML_NAMESPACE_TEXT == nPrefix) &&
     136           0 :                  IsXMLToken( sLocalName, XML_STYLE_NAME ) )
     137             :             {
     138           0 :                 aStyleNames.push_back(xAttrList->getValueByIndex(nAttr));
     139             :             }
     140           0 :         }
     141             :     }
     142             : 
     143             :     // always return default context; we already got the interesting info
     144             :     return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
     145           0 :                                                   xAttrList);
     146             : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10