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

Generated by: LCOV version 1.10