LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexBibliographyEntryContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 40 90.0 %
Date: 2012-08-25 Functions: 6 11 54.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 50 44.0 %

           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 "XMLIndexBibliographyEntryContext.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                 :            : #include <com/sun/star/text/BibliographyDataField.hpp>
      30                 :            : 
      31                 :            : 
      32                 :            : using namespace ::com::sun::star::text;
      33                 :            : using namespace ::xmloff::token;
      34                 :            : 
      35                 :            : using ::rtl::OUString;
      36                 :            : using ::com::sun::star::beans::PropertyValue;
      37                 :            : using ::com::sun::star::beans::PropertyValues;
      38                 :            : using ::com::sun::star::uno::Reference;
      39                 :            : using ::com::sun::star::uno::Sequence;
      40                 :            : using ::com::sun::star::uno::Any;
      41                 :            : using ::com::sun::star::xml::sax::XAttributeList;
      42                 :            : 
      43                 :            : 
      44                 :            : const sal_Char sAPI_TokenType[] = "TokenType";
      45                 :            : const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
      46                 :            : 
      47 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLIndexBibliographyEntryContext, XMLIndexSimpleEntryContext);
      48                 :            : 
      49                 :        356 : XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
      50                 :            :     SvXMLImport& rImport,
      51                 :            :     XMLIndexTemplateContext& rTemplate,
      52                 :            :     sal_uInt16 nPrfx,
      53                 :            :     const OUString& rLocalName ) :
      54                 :            :         XMLIndexSimpleEntryContext(rImport,
      55                 :            :                                    rTemplate.sTokenBibliographyDataField,
      56                 :            :                                    rTemplate,
      57                 :            :                                    nPrfx, rLocalName),
      58                 :            :         nBibliographyInfo(BibliographyDataField::IDENTIFIER),
      59                 :        356 :         bBibliographyInfoOK(sal_False)
      60                 :            : {
      61                 :        356 : }
      62                 :            : 
      63                 :        356 : XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
      64                 :            : {
      65         [ -  + ]:        712 : }
      66                 :            : 
      67                 :            : const SvXMLEnumMapEntry aBibliographyDataFieldMap[] =
      68                 :            : {
      69                 :            :     { XML_ADDRESS,              BibliographyDataField::ADDRESS },
      70                 :            :     { XML_ANNOTE,               BibliographyDataField::ANNOTE },
      71                 :            :     { XML_AUTHOR,               BibliographyDataField::AUTHOR },
      72                 :            :     { XML_BIBLIOGRAPHY_TYPE,    BibliographyDataField::BIBILIOGRAPHIC_TYPE },
      73                 :            :     // #96658#: also read old documents (bib*i*liographic...)
      74                 :            :     { XML_BIBILIOGRAPHIC_TYPE,  BibliographyDataField::BIBILIOGRAPHIC_TYPE },
      75                 :            :     { XML_BOOKTITLE,            BibliographyDataField::BOOKTITLE },
      76                 :            :     { XML_CHAPTER,              BibliographyDataField::CHAPTER },
      77                 :            :     { XML_CUSTOM1,              BibliographyDataField::CUSTOM1 },
      78                 :            :     { XML_CUSTOM2,              BibliographyDataField::CUSTOM2 },
      79                 :            :     { XML_CUSTOM3,              BibliographyDataField::CUSTOM3 },
      80                 :            :     { XML_CUSTOM4,              BibliographyDataField::CUSTOM4 },
      81                 :            :     { XML_CUSTOM5,              BibliographyDataField::CUSTOM5 },
      82                 :            :     { XML_EDITION,              BibliographyDataField::EDITION },
      83                 :            :     { XML_EDITOR,               BibliographyDataField::EDITOR },
      84                 :            :     { XML_HOWPUBLISHED,         BibliographyDataField::HOWPUBLISHED },
      85                 :            :     { XML_IDENTIFIER,           BibliographyDataField::IDENTIFIER },
      86                 :            :     { XML_INSTITUTION,          BibliographyDataField::INSTITUTION },
      87                 :            :     { XML_ISBN,                 BibliographyDataField::ISBN },
      88                 :            :     { XML_JOURNAL,              BibliographyDataField::JOURNAL },
      89                 :            :     { XML_MONTH,                BibliographyDataField::MONTH },
      90                 :            :     { XML_NOTE,                 BibliographyDataField::NOTE },
      91                 :            :     { XML_NUMBER,               BibliographyDataField::NUMBER },
      92                 :            :     { XML_ORGANIZATIONS,        BibliographyDataField::ORGANIZATIONS },
      93                 :            :     { XML_PAGES,                BibliographyDataField::PAGES },
      94                 :            :     { XML_PUBLISHER,            BibliographyDataField::PUBLISHER },
      95                 :            :     { XML_REPORT_TYPE,          BibliographyDataField::REPORT_TYPE },
      96                 :            :     { XML_SCHOOL,               BibliographyDataField::SCHOOL },
      97                 :            :     { XML_SERIES,               BibliographyDataField::SERIES },
      98                 :            :     { XML_TITLE,                BibliographyDataField::TITLE },
      99                 :            :     { XML_URL,                  BibliographyDataField::URL },
     100                 :            :     { XML_VOLUME,               BibliographyDataField::VOLUME },
     101                 :            :     { XML_YEAR,                 BibliographyDataField::YEAR },
     102                 :            :     { XML_TOKEN_INVALID, 0 }
     103                 :            : };
     104                 :            : 
     105                 :        356 : void XMLIndexBibliographyEntryContext::StartElement(
     106                 :            :     const Reference<XAttributeList> & xAttrList)
     107                 :            : {
     108                 :            :     // handle both, style name and bibliography info
     109                 :        356 :     sal_Int16 nLength = xAttrList->getLength();
     110         [ +  + ]:        712 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     111                 :            :     {
     112                 :        356 :         OUString sLocalName;
     113                 :        356 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     114         [ +  - ]:        356 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     115   [ +  -  +  - ]:        712 :                               &sLocalName );
     116         [ +  - ]:        356 :         if (XML_NAMESPACE_TEXT == nPrefix)
     117                 :            :         {
     118 [ +  - ][ -  + ]:        356 :             if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
     119                 :            :             {
     120 [ #  # ][ #  # ]:          0 :                 sCharStyleName = xAttrList->getValueByIndex(nAttr);
     121                 :          0 :                 bCharStyleNameOK = sal_True;
     122                 :            :             }
     123 [ +  - ][ +  - ]:        356 :             else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
     124                 :            :             {
     125                 :            :                 sal_uInt16 nTmp;
     126         [ +  - ]:        356 :                 if (SvXMLUnitConverter::convertEnum(
     127         [ +  - ]:        356 :                     nTmp, xAttrList->getValueByIndex(nAttr),
     128 [ +  - ][ +  - ]:        356 :                     aBibliographyDataFieldMap))
     129                 :            :                 {
     130                 :        356 :                     nBibliographyInfo = nTmp;
     131                 :        356 :                     bBibliographyInfoOK = sal_True;
     132                 :            :                 }
     133                 :            :             }
     134                 :            :         }
     135                 :        356 :     }
     136                 :            : 
     137                 :            :     // if we have a style name, set it!
     138         [ -  + ]:        356 :     if (bCharStyleNameOK)
     139                 :            :     {
     140                 :          0 :         nValues++;
     141                 :            :     }
     142                 :            : 
     143                 :            :     // always bibliography; else element is not valid
     144                 :        356 :     nValues++;
     145                 :        356 : }
     146                 :            : 
     147                 :        356 : void XMLIndexBibliographyEntryContext::EndElement()
     148                 :            : {
     149                 :            :     // only valid, if we have bibliography info
     150         [ +  - ]:        356 :     if (bBibliographyInfoOK)
     151                 :            :     {
     152                 :        356 :         XMLIndexSimpleEntryContext::EndElement();
     153                 :            :     }
     154                 :        356 : }
     155                 :            : 
     156                 :        356 : void XMLIndexBibliographyEntryContext::FillPropertyValues(
     157                 :            :     ::com::sun::star::uno::Sequence<
     158                 :            :         ::com::sun::star::beans::PropertyValue> & rValues)
     159                 :            : {
     160                 :            :     // entry name and (optionally) style name in parent class
     161         [ +  - ]:        356 :     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
     162                 :            : 
     163                 :            :     // bibliography data field
     164         [ -  + ]:        356 :     sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
     165         [ +  - ]:        356 :     rValues[nIndex].Name = rTemplateContext.sBibliographyDataField;
     166                 :        356 :     Any aAny;
     167         [ +  - ]:        356 :     aAny <<= nBibliographyInfo;
     168         [ +  - ]:        356 :     rValues[nIndex].Value = aAny;
     169                 :        356 : }
     170                 :            : 
     171                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10