LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexTitleTemplateContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 34 35 97.1 %
Date: 2015-06-13 12:38:46 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 "XMLIndexTitleTemplateContext.hxx"
      21             : #include <xmloff/xmlictxt.hxx>
      22             : #include <xmloff/xmlimp.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/xmltoken.hxx>
      26             : 
      27             : 
      28             : using ::com::sun::star::beans::XPropertySet;
      29             : using ::com::sun::star::uno::Any;
      30             : using ::com::sun::star::uno::Reference;
      31             : using ::com::sun::star::xml::sax::XAttributeList;
      32             : using ::xmloff::token::IsXMLToken;
      33             : using ::xmloff::token::XML_STYLE_NAME;
      34             : 
      35             : 
      36           0 : TYPEINIT1( XMLIndexTitleTemplateContext, SvXMLImportContext );
      37             : 
      38          23 : XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext(
      39             :     SvXMLImport& rImport,
      40             :     Reference<XPropertySet> & rPropSet,
      41             :     sal_uInt16 nPrfx,
      42             :     const OUString& rLocalName)
      43             : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
      44             : ,   sTitle("Title")
      45             : ,   sParaStyleHeading("ParaStyleHeading")
      46             : ,   bStyleNameOK(false)
      47          23 : ,   rTOCPropertySet(rPropSet)
      48             : {
      49          23 : }
      50             : 
      51             : 
      52          46 : XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
      53             : {
      54          46 : }
      55             : 
      56          23 : void XMLIndexTitleTemplateContext::StartElement(
      57             :     const Reference<XAttributeList> & xAttrList)
      58             : {
      59             :     // there's only one attribute: style-name
      60          23 :     sal_Int16 nLength = xAttrList->getLength();
      61          46 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      62             :     {
      63          23 :         OUString sLocalName;
      64          23 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      65          23 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      66          46 :                               &sLocalName );
      67          46 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
      68          23 :              (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
      69             :         {
      70          23 :             sStyleName = xAttrList->getValueByIndex(nAttr);
      71          23 :             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
      72          46 :                 XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName );
      73             :             const Reference < ::com::sun::star::container::XNameContainer >&
      74          23 :                 rStyles = GetImport().GetTextImport()->GetParaStyles();
      75          23 :             bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
      76             :         }
      77          23 :     }
      78          23 : }
      79             : 
      80          23 : void XMLIndexTitleTemplateContext::EndElement()
      81             : {
      82          23 :     Any aAny;
      83             : 
      84          23 :     aAny <<= sContent.makeStringAndClear();
      85          23 :     rTOCPropertySet->setPropertyValue(sTitle, aAny);
      86             : 
      87          23 :     if (bStyleNameOK)
      88             :     {
      89          44 :         aAny <<= GetImport().GetStyleDisplayName(
      90             :                                 XML_STYLE_FAMILY_TEXT_PARAGRAPH,
      91          22 :                                 sStyleName );
      92          22 :         rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny);
      93          23 :     }
      94          23 : }
      95             : 
      96          22 : void XMLIndexTitleTemplateContext::Characters(
      97             :     const OUString& sString)
      98             : {
      99          22 :     sContent.append(sString);
     100          22 : }
     101             : 
     102             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11