LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexSimpleEntryContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 40 43 93.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 "XMLIndexSimpleEntryContext.hxx"
      21             : #include "XMLIndexTemplateContext.hxx"
      22             : #include <xmloff/xmlictxt.hxx>
      23             : #include <xmloff/xmlimp.hxx>
      24             : #include <xmloff/txtimp.hxx>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include <xmloff/xmlnmspe.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : 
      30             : using ::com::sun::star::beans::PropertyValue;
      31             : using ::com::sun::star::beans::PropertyValues;
      32             : using ::com::sun::star::uno::Reference;
      33             : using ::com::sun::star::uno::Sequence;
      34             : using ::com::sun::star::uno::Any;
      35             : using ::com::sun::star::xml::sax::XAttributeList;
      36             : using ::xmloff::token::IsXMLToken;
      37             : using ::xmloff::token::XML_STYLE_NAME;
      38             : 
      39           0 : TYPEINIT1( XMLIndexSimpleEntryContext, SvXMLImportContext);
      40             : 
      41        1426 : XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
      42             :     SvXMLImport& rImport,
      43             :     const OUString& rEntry,
      44             :     XMLIndexTemplateContext& rTemplate,
      45             :     sal_uInt16 nPrfx,
      46             :     const OUString& rLocalName )
      47             : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
      48             : ,   rEntryType(rEntry)
      49             : ,   bCharStyleNameOK(false)
      50             : ,   rTemplateContext(rTemplate)
      51        1426 : ,   nValues(1)
      52             : {
      53        1426 : }
      54             : 
      55        1922 : XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
      56             : {
      57        1922 : }
      58             : 
      59         950 : void XMLIndexSimpleEntryContext::StartElement(
      60             :     const Reference<XAttributeList> & xAttrList)
      61             : {
      62             :     // we know only one attribute: style-name
      63         950 :     sal_Int16 nLength = xAttrList->getLength();
      64        1362 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      65             :     {
      66         412 :         OUString sLocalName;
      67         412 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      68         412 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      69         824 :                               &sLocalName );
      70         452 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
      71          40 :              IsXMLToken(sLocalName, XML_STYLE_NAME) )
      72             :         {
      73          40 :             sCharStyleName = xAttrList->getValueByIndex(nAttr);
      74          40 :             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
      75          80 :                 XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName );
      76             :             // #142494#: Check if style exists
      77             :             const Reference < ::com::sun::star::container::XNameContainer > & rStyles =
      78          40 :                 GetImport().GetTextImport()->GetTextStyles();
      79          40 :             if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
      80           0 :                 bCharStyleNameOK = true;
      81             :             else
      82          40 :                 bCharStyleNameOK = false;
      83             :         }
      84         412 :     }
      85             : 
      86             :     // if we have a style name, set it!
      87         950 :     if (bCharStyleNameOK)
      88             :     {
      89           0 :         nValues++;
      90             :     }
      91             : 
      92         950 : }
      93             : 
      94        1426 : void XMLIndexSimpleEntryContext::EndElement()
      95             : {
      96        1426 :     Sequence<PropertyValue> aValues(nValues);
      97             : 
      98        1426 :     FillPropertyValues(aValues);
      99        1426 :     rTemplateContext.addTemplateEntry(aValues);
     100        1426 : }
     101             : 
     102        1426 : void XMLIndexSimpleEntryContext::FillPropertyValues(
     103             :     ::com::sun::star::uno::Sequence<
     104             :         ::com::sun::star::beans::PropertyValue> & rValues)
     105             : {
     106             :     // due to the limited number of subclasses, we fill the values
     107             :     // directly into the slots. Subclasses will have to know they can
     108             :     // only use slot so-and-so.
     109             : 
     110        1426 :     Any aAny;
     111             : 
     112             :     // token type
     113        1426 :     rValues[0].Name = rTemplateContext.sTokenType;
     114        1426 :     aAny <<= rEntryType;
     115        1426 :     rValues[0].Value = aAny;
     116             : 
     117             :     // char style
     118        1426 :     if (bCharStyleNameOK)
     119             :     {
     120         178 :         rValues[1].Name = rTemplateContext.sCharacterStyleName;
     121         356 :         aAny <<= GetImport().GetStyleDisplayName(
     122             :                                     XML_STYLE_FAMILY_TEXT_TEXT,
     123         178 :                                     sCharStyleName );
     124         178 :         rValues[1].Value = aAny;
     125        1426 :     }
     126             : 
     127        1426 : }
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10