LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexSimpleEntryContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 43 97.7 %
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 "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         981 : 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         981 : ,   nValues(1)
      52             : {
      53         981 : }
      54             : 
      55        1289 : XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
      56             : {
      57        1289 : }
      58             : 
      59         634 : void XMLIndexSimpleEntryContext::StartElement(
      60             :     const Reference<XAttributeList> & xAttrList)
      61             : {
      62             :     // we know only one attribute: style-name
      63         634 :     sal_Int16 nLength = xAttrList->getLength();
      64         912 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      65             :     {
      66         278 :         OUString sLocalName;
      67         278 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      68         278 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      69         556 :                               &sLocalName );
      70         305 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
      71          27 :              IsXMLToken(sLocalName, XML_STYLE_NAME) )
      72             :         {
      73          27 :             sCharStyleName = xAttrList->getValueByIndex(nAttr);
      74          27 :             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
      75          54 :                 XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName );
      76             :             // #142494#: Check if style exists
      77             :             const Reference < ::com::sun::star::container::XNameContainer > & rStyles =
      78          27 :                 GetImport().GetTextImport()->GetTextStyles();
      79          27 :             if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
      80           7 :                 bCharStyleNameOK = true;
      81             :             else
      82          20 :                 bCharStyleNameOK = false;
      83             :         }
      84         278 :     }
      85             : 
      86             :     // if we have a style name, set it!
      87         634 :     if (bCharStyleNameOK)
      88             :     {
      89           7 :         nValues++;
      90             :     }
      91             : 
      92         634 : }
      93             : 
      94         981 : void XMLIndexSimpleEntryContext::EndElement()
      95             : {
      96         981 :     Sequence<PropertyValue> aValues(nValues);
      97             : 
      98         981 :     FillPropertyValues(aValues);
      99         981 :     rTemplateContext.addTemplateEntry(aValues);
     100         981 : }
     101             : 
     102         981 : 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         981 :     Any aAny;
     111             : 
     112             :     // token type
     113         981 :     rValues[0].Name = rTemplateContext.sTokenType;
     114         981 :     aAny <<= rEntryType;
     115         981 :     rValues[0].Value = aAny;
     116             : 
     117             :     // char style
     118         981 :     if (bCharStyleNameOK)
     119             :     {
     120         105 :         rValues[1].Name = rTemplateContext.sCharacterStyleName;
     121         210 :         aAny <<= GetImport().GetStyleDisplayName(
     122             :                                     XML_STYLE_FAMILY_TEXT_TEXT,
     123         105 :                                     sCharStyleName );
     124         105 :         rValues[1].Value = aAny;
     125         981 :     }
     126             : 
     127         981 : }
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11