LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexSimpleEntryContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 43 67.4 %
Date: 2012-08-25 Functions: 6 11 54.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 72 23.6 %

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

Generated by: LCOV version 1.10