LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/text - XMLIndexSimpleEntryContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 43 67.4 %
Date: 2013-07-09 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             : const sal_Char sAPI_TokenType[] = "TokenType";
      40             : const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
      41             : 
      42           0 : TYPEINIT1( XMLIndexSimpleEntryContext, SvXMLImportContext);
      43             : 
      44         490 : XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
      45             :     SvXMLImport& rImport,
      46             :     const OUString& rEntry,
      47             :     XMLIndexTemplateContext& rTemplate,
      48             :     sal_uInt16 nPrfx,
      49             :     const OUString& rLocalName )
      50             : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
      51             : ,   rEntryType(rEntry)
      52             : ,   bCharStyleNameOK(sal_False)
      53             : ,   rTemplateContext(rTemplate)
      54         490 : ,   nValues(1)
      55             : {
      56         490 : }
      57             : 
      58         596 : XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
      59             : {
      60         596 : }
      61             : 
      62         292 : void XMLIndexSimpleEntryContext::StartElement(
      63             :     const Reference<XAttributeList> & xAttrList)
      64             : {
      65             :     // we know only one attribute: style-name
      66         292 :     sal_Int16 nLength = xAttrList->getLength();
      67         396 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      68             :     {
      69         104 :         OUString sLocalName;
      70         104 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      71         104 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      72         208 :                               &sLocalName );
      73         104 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
      74           0 :              IsXMLToken(sLocalName, XML_STYLE_NAME) )
      75             :         {
      76           0 :             sCharStyleName = xAttrList->getValueByIndex(nAttr);
      77           0 :             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
      78           0 :                 XML_STYLE_FAMILY_TEXT_TEXT, sCharStyleName );
      79             :             // #142494#: Check if style exists
      80             :             const Reference < ::com::sun::star::container::XNameContainer > & rStyles =
      81           0 :                 GetImport().GetTextImport()->GetTextStyles();
      82           0 :             if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
      83           0 :                 bCharStyleNameOK = sal_True;
      84             :             else
      85           0 :                 bCharStyleNameOK = sal_False;
      86             :         }
      87         104 :     }
      88             : 
      89             :     // if we have a style name, set it!
      90         292 :     if (bCharStyleNameOK)
      91             :     {
      92           0 :         nValues++;
      93             :     }
      94             : 
      95         292 : }
      96             : 
      97         490 : void XMLIndexSimpleEntryContext::EndElement()
      98             : {
      99         490 :     Sequence<PropertyValue> aValues(nValues);
     100             : 
     101         490 :     FillPropertyValues(aValues);
     102         490 :     rTemplateContext.addTemplateEntry(aValues);
     103         490 : }
     104             : 
     105         490 : void XMLIndexSimpleEntryContext::FillPropertyValues(
     106             :     ::com::sun::star::uno::Sequence<
     107             :         ::com::sun::star::beans::PropertyValue> & rValues)
     108             : {
     109             :     // due to the limited number of subclasses, we fill the values
     110             :     // directly into the slots. Subclasses will have to know they can
     111             :     // only use slot so-and-so.
     112             : 
     113         490 :     Any aAny;
     114             : 
     115             :     // token type
     116         490 :     rValues[0].Name = rTemplateContext.sTokenType;
     117         490 :     aAny <<= rEntryType;
     118         490 :     rValues[0].Value = aAny;
     119             : 
     120             :     // char style
     121         490 :     if (bCharStyleNameOK)
     122             :     {
     123           0 :         rValues[1].Name = rTemplateContext.sCharacterStyleName;
     124           0 :         aAny <<= GetImport().GetStyleDisplayName(
     125             :                                     XML_STYLE_FAMILY_TEXT_TEXT,
     126           0 :                                     sCharStyleName );
     127           0 :         rValues[1].Value = aAny;
     128         490 :     }
     129             : 
     130         490 : }
     131             : 
     132             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10