LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexTitleTemplateContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 34 35 97.1 %
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 "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          38 : 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          38 : ,   rTOCPropertySet(rPropSet)
      48             : {
      49          38 : }
      50             : 
      51             : 
      52          76 : XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
      53             : {
      54          76 : }
      55             : 
      56          38 : void XMLIndexTitleTemplateContext::StartElement(
      57             :     const Reference<XAttributeList> & xAttrList)
      58             : {
      59             :     // there's only one attribute: style-name
      60          38 :     sal_Int16 nLength = xAttrList->getLength();
      61          76 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      62             :     {
      63          38 :         OUString sLocalName;
      64          38 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      65          38 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      66          76 :                               &sLocalName );
      67          76 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
      68          38 :              (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
      69             :         {
      70          38 :             sStyleName = xAttrList->getValueByIndex(nAttr);
      71          38 :             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
      72          76 :                 XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName );
      73             :             const Reference < ::com::sun::star::container::XNameContainer >&
      74          38 :                 rStyles = GetImport().GetTextImport()->GetParaStyles();
      75          38 :             bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
      76             :         }
      77          38 :     }
      78          38 : }
      79             : 
      80          38 : void XMLIndexTitleTemplateContext::EndElement()
      81             : {
      82          38 :     Any aAny;
      83             : 
      84          38 :     aAny <<= sContent.makeStringAndClear();
      85          38 :     rTOCPropertySet->setPropertyValue(sTitle, aAny);
      86             : 
      87          38 :     if (bStyleNameOK)
      88             :     {
      89          72 :         aAny <<= GetImport().GetStyleDisplayName(
      90             :                                 XML_STYLE_FAMILY_TEXT_PARAGRAPH,
      91          36 :                                 sStyleName );
      92          36 :         rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny);
      93          38 :     }
      94          38 : }
      95             : 
      96          36 : void XMLIndexTitleTemplateContext::Characters(
      97             :     const OUString& sString)
      98             : {
      99          36 :     sContent.append(sString);
     100          36 : }
     101             : 
     102             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10