LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/text - XMLIndexChapterInfoEntryContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-12-27 Functions: 0 10 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             : 
      21             : #include "XMLIndexChapterInfoEntryContext.hxx"
      22             : 
      23             : #include <com/sun/star/text/ChapterFormat.hpp>
      24             : 
      25             : #include <sax/tools/converter.hxx>
      26             : 
      27             : #include "XMLIndexTemplateContext.hxx"
      28             : #include <xmloff/xmlictxt.hxx>
      29             : #include <xmloff/xmlimp.hxx>
      30             : #include <xmloff/txtimp.hxx>
      31             : #include <xmloff/nmspmap.hxx>
      32             : #include "xmloff/xmlnmspe.hxx"
      33             : #include <xmloff/xmltoken.hxx>
      34             : #include <xmloff/xmluconv.hxx>
      35             : 
      36             : 
      37             : using namespace ::com::sun::star::text;
      38             : using namespace ::xmloff::token;
      39             : 
      40             : using ::rtl::OUString;
      41             : using ::com::sun::star::beans::PropertyValue;
      42             : using ::com::sun::star::beans::PropertyValues;
      43             : using ::com::sun::star::uno::Reference;
      44             : using ::com::sun::star::uno::Sequence;
      45             : using ::com::sun::star::uno::Any;
      46             : using ::com::sun::star::xml::sax::XAttributeList;
      47             : 
      48             : 
      49             : 
      50           0 : TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext);
      51             : 
      52           0 : XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext(
      53             :     SvXMLImport& rImport,
      54             :     XMLIndexTemplateContext& rTemplate,
      55             :     sal_uInt16 nPrfx,
      56             :     const OUString& rLocalName,
      57             :     sal_Bool bT ) :
      58             :         XMLIndexSimpleEntryContext(rImport,
      59             :                                    (bT ? rTemplate.sTokenEntryNumber
      60             :                                           : rTemplate.sTokenChapterInfo),
      61             :                                    rTemplate, nPrfx, rLocalName),
      62             :         nChapterInfo(ChapterFormat::NAME_NUMBER),
      63             :         bChapterInfoOK(sal_False),
      64             :         bTOC( bT ),
      65             :         nOutlineLevel( 0 ),
      66           0 :         bOutlineLevelOK(sal_False)
      67             : {
      68           0 : }
      69             : 
      70           0 : XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext()
      71             : {
      72           0 : }
      73             : 
      74             : static const SvXMLEnumMapEntry aChapterDisplayMap[] =
      75             : {
      76             :     { XML_NAME,                     ChapterFormat::NAME },
      77             :     { XML_NUMBER,                   ChapterFormat::NUMBER },
      78             :     { XML_NUMBER_AND_NAME,          ChapterFormat::NAME_NUMBER },
      79             :     //---> i89791
      80             :     // enabled for ODF 1.2, full index support in 3.0
      81             :     { XML_PLAIN_NUMBER_AND_NAME,    ChapterFormat::NO_PREFIX_SUFFIX },
      82             :     { XML_PLAIN_NUMBER,             ChapterFormat::DIGIT },
      83             :     { XML_TOKEN_INVALID,            0 }
      84             : };
      85             : 
      86           0 : void XMLIndexChapterInfoEntryContext::StartElement(
      87             :     const Reference<XAttributeList> & xAttrList)
      88             : {
      89             :     // handle both, style name and bibliography info
      90           0 :     sal_Int16 nLength = xAttrList->getLength();
      91           0 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      92             :     {
      93           0 :         OUString sLocalName;
      94           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      95           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      96           0 :                               &sLocalName );
      97           0 :         if (XML_NAMESPACE_TEXT == nPrefix)
      98             :         {
      99           0 :             if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
     100             :             {
     101           0 :                 sCharStyleName = xAttrList->getValueByIndex(nAttr);
     102           0 :                 bCharStyleNameOK = sal_True;
     103             :             }
     104           0 :             else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well
     105             :             {
     106             :                 sal_uInt16 nTmp;
     107           0 :                 if (SvXMLUnitConverter::convertEnum(
     108           0 :                     nTmp, xAttrList->getValueByIndex(nAttr),
     109           0 :                     aChapterDisplayMap))
     110             :                 {
     111           0 :                     nChapterInfo = nTmp;
     112           0 :                     bChapterInfoOK = sal_True;
     113             :                 }
     114             :             }
     115           0 :             else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
     116             :             {
     117             :                 sal_Int32 nTmp;
     118           0 :                 if (::sax::Converter::convertNumber(nTmp,
     119           0 :                         xAttrList->getValueByIndex(nAttr)))
     120             :                 {
     121             : //control on range is carried out in the UNO level
     122           0 :                     nOutlineLevel = static_cast<sal_uInt16>(nTmp);
     123           0 :                     bOutlineLevelOK = sal_True;
     124             :                 }
     125             :             }
     126             :         }
     127           0 :     }
     128             : 
     129             :     // if we have a style name, set it!
     130           0 :     if (bCharStyleNameOK)
     131             :     {
     132           0 :         nValues++;
     133             :     }
     134             : 
     135             :     // if we have chaper info, set it!
     136           0 :     if (bChapterInfoOK)
     137             :     {
     138           0 :         nValues++;
     139             :         /* Some of the index chapter information attributes written to ODF 1.1
     140             :            and 1.2 don't reflect the displaying (#i89791#)
     141             :         */
     142           0 :         if ( !bTOC )
     143             :         {
     144           0 :             bool bConvert( false );
     145             :             {
     146           0 :                 sal_Int32 nUPD( 0 );
     147           0 :                 sal_Int32 nBuild( 0 );
     148           0 :                 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
     149           0 :                 if ( GetImport().IsTextDocInOOoFileFormat() ||
     150             :                      ( bBuildIdFound &&
     151             :                        ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) )
     152             :                 {
     153           0 :                     bConvert = true;
     154             :                 }
     155             :             }
     156           0 :             if ( bConvert )
     157             :             {
     158           0 :                 if ( nChapterInfo == ChapterFormat::NUMBER )
     159             :                 {
     160           0 :                     nChapterInfo = ChapterFormat::DIGIT;
     161             :                 }
     162           0 :                 else if ( nChapterInfo == ChapterFormat::NAME_NUMBER )
     163             :                 {
     164           0 :                     nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX;
     165             :                 }
     166             :             }
     167             :         }
     168             :     }
     169           0 :     if (bOutlineLevelOK)
     170           0 :         nValues++;
     171           0 : }
     172             : 
     173           0 : void XMLIndexChapterInfoEntryContext::FillPropertyValues(
     174             :     ::com::sun::star::uno::Sequence<
     175             :         ::com::sun::star::beans::PropertyValue> & rValues)
     176             : {
     177             :     // entry name and (optionally) style name in parent class
     178           0 :     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
     179             : 
     180           0 :     sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
     181             : 
     182           0 :     if( bChapterInfoOK )
     183             :     {
     184             :         // chapter info field
     185           0 :         rValues[nIndex].Name = rTemplateContext.sChapterFormat;
     186           0 :         Any aAny;
     187           0 :         aAny <<= nChapterInfo;
     188           0 :         rValues[nIndex].Value = aAny;
     189           0 :         nIndex++;
     190             :     }
     191           0 :     if( bOutlineLevelOK )
     192             :     {
     193           0 :         rValues[nIndex].Name = rTemplateContext.sChapterLevel;
     194           0 :         Any aAny;
     195           0 :         aAny <<= nOutlineLevel;
     196           0 :         rValues[nIndex].Value = aAny;
     197             :     }
     198           0 : }
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10