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

Generated by: LCOV version 1.10