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

Generated by: LCOV version 1.11