LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexBibliographyEntryContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 40 97.5 %
Date: 2014-11-03 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         356 : 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         356 :         bBibliographyInfoOK(false)
      55             : {
      56         356 : }
      57             : 
      58         712 : XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
      59             : {
      60         712 : }
      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         356 : void XMLIndexBibliographyEntryContext::StartElement(
     101             :     const Reference<XAttributeList> & xAttrList)
     102             : {
     103             :     // handle both, style name and bibliography info
     104         356 :     sal_Int16 nLength = xAttrList->getLength();
     105         890 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     106             :     {
     107         534 :         OUString sLocalName;
     108         534 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     109         534 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     110        1068 :                               &sLocalName );
     111         534 :         if (XML_NAMESPACE_TEXT == nPrefix)
     112             :         {
     113         534 :             if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
     114             :             {
     115         178 :                 sCharStyleName = xAttrList->getValueByIndex(nAttr);
     116         178 :                 bCharStyleNameOK = true;
     117             :             }
     118         356 :             else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
     119             :             {
     120             :                 sal_uInt16 nTmp;
     121         712 :                 if (SvXMLUnitConverter::convertEnum(
     122         356 :                     nTmp, xAttrList->getValueByIndex(nAttr),
     123         712 :                     aBibliographyDataFieldMap))
     124             :                 {
     125         356 :                     nBibliographyInfo = nTmp;
     126         356 :                     bBibliographyInfoOK = true;
     127             :                 }
     128             :             }
     129             :         }
     130         534 :     }
     131             : 
     132             :     // if we have a style name, set it!
     133         356 :     if (bCharStyleNameOK)
     134             :     {
     135         178 :         nValues++;
     136             :     }
     137             : 
     138             :     // always bibliography; else element is not valid
     139         356 :     nValues++;
     140         356 : }
     141             : 
     142         356 : void XMLIndexBibliographyEntryContext::EndElement()
     143             : {
     144             :     // only valid, if we have bibliography info
     145         356 :     if (bBibliographyInfoOK)
     146             :     {
     147         356 :         XMLIndexSimpleEntryContext::EndElement();
     148             :     }
     149         356 : }
     150             : 
     151         356 : 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         356 :     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
     157             : 
     158             :     // bibliography data field
     159         356 :     sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
     160         356 :     rValues[nIndex].Name = rTemplateContext.sBibliographyDataField;
     161         356 :     Any aAny;
     162         356 :     aAny <<= nBibliographyInfo;
     163         356 :     rValues[nIndex].Value = aAny;
     164         356 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10