LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexMarkExport.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 84 0.0 %
Date: 2014-04-14 Functions: 0 9 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             : #include "XMLIndexMarkExport.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <rtl/ustring.hxx>
      23             : #include <rtl/ustrbuf.hxx>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      26             : #include <sax/tools/converter.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmlnmspe.hxx>
      29             : #include <xmloff/xmlexp.hxx>
      30             : 
      31             : 
      32             : using namespace ::xmloff::token;
      33             : 
      34             : using ::com::sun::star::beans::XPropertySet;
      35             : using ::com::sun::star::beans::XPropertySetInfo;
      36             : using ::com::sun::star::uno::Reference;
      37             : using ::com::sun::star::uno::Any;
      38             : 
      39             : 
      40             : 
      41           0 : XMLIndexMarkExport::XMLIndexMarkExport(
      42             :     SvXMLExport& rExp)
      43             : :   sLevel("Level")
      44             : ,   sUserIndexName("UserIndexName")
      45             : ,   sPrimaryKey("PrimaryKey")
      46             : ,   sSecondaryKey("SecondaryKey")
      47             : ,   sDocumentIndexMark("DocumentIndexMark")
      48             : ,   sIsStart("IsStart")
      49             : ,   sIsCollapsed("IsCollapsed")
      50             : ,   sAlternativeText("AlternativeText")
      51             : ,   sTextReading("TextReading")
      52             : ,   sPrimaryKeyReading("PrimaryKeyReading")
      53             : ,   sSecondaryKeyReading("SecondaryKeyReading")
      54             : ,   sMainEntry("IsMainEntry")
      55           0 : ,   rExport(rExp)
      56             : {
      57           0 : }
      58             : 
      59             : const enum XMLTokenEnum lcl_pTocMarkNames[] =
      60             :     { XML_TOC_MARK, XML_TOC_MARK_START, XML_TOC_MARK_END };
      61             : const enum XMLTokenEnum lcl_pUserIndexMarkName[] =
      62             :     { XML_USER_INDEX_MARK,
      63             :           XML_USER_INDEX_MARK_START, XML_USER_INDEX_MARK_END };
      64             : const enum XMLTokenEnum lcl_pAlphaIndexMarkName[] =
      65             :     { XML_ALPHABETICAL_INDEX_MARK,
      66             :           XML_ALPHABETICAL_INDEX_MARK_START,
      67             :           XML_ALPHABETICAL_INDEX_MARK_END };
      68             : 
      69             : 
      70           0 : XMLIndexMarkExport::~XMLIndexMarkExport()
      71             : {
      72           0 : }
      73             : 
      74           0 : void XMLIndexMarkExport::ExportIndexMark(
      75             :     const Reference<XPropertySet> & rPropSet,
      76             :     sal_Bool bAutoStyles)
      77             : {
      78             :     /// index marks have no styles!
      79           0 :     if (!bAutoStyles)
      80             :     {
      81           0 :         const enum XMLTokenEnum * pElements = NULL;
      82           0 :         sal_Int8 nElementNo = -1;
      83             : 
      84             :         // get index mark
      85           0 :         Any aAny;
      86           0 :         aAny = rPropSet->getPropertyValue(sDocumentIndexMark);
      87           0 :         Reference<XPropertySet> xIndexMarkPropSet;
      88           0 :         aAny >>= xIndexMarkPropSet;
      89             : 
      90             :         // common: handling of start, end, collapsed entries and
      91             :         // alternative text
      92             : 
      93             :         // collapsed/alternative text entry?
      94           0 :         aAny = rPropSet->getPropertyValue(sIsCollapsed);
      95           0 :         if (*(sal_Bool *)aAny.getValue())
      96             :         {
      97             :             // collapsed entry: needs alternative text
      98           0 :             nElementNo = 0;
      99             : 
     100           0 :             aAny = xIndexMarkPropSet->getPropertyValue(sAlternativeText);
     101           0 :             OUString sTmp;
     102           0 :             aAny >>= sTmp;
     103             :             DBG_ASSERT(!sTmp.isEmpty(),
     104             :                        "collapsed index mark without alternative text");
     105           0 :             rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STRING_VALUE, sTmp);
     106             :         }
     107             :         else
     108             :         {
     109             :             // start and end entries: has ID
     110           0 :             aAny = rPropSet->getPropertyValue(sIsStart);
     111           0 :             nElementNo = *(sal_Bool *)aAny.getValue() ? 1 : 2;
     112             : 
     113             :             // generate ID
     114           0 :             OUStringBuffer sBuf;
     115           0 :             GetID(sBuf, xIndexMarkPropSet);
     116             :             rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_ID,
     117           0 :                                  sBuf.makeStringAndClear());
     118             :         }
     119             : 
     120             :         // distinguish between TOC, user, alphab. index marks by
     121             :         // asking for specific properties
     122             :         // Export attributes for -mark-start and -mark elements,
     123             :         // but not for -mark-end
     124             :         Reference<XPropertySetInfo> xPropertySetInfo =
     125           0 :             xIndexMarkPropSet->getPropertySetInfo();
     126           0 :         if (xPropertySetInfo->hasPropertyByName(sUserIndexName))
     127             :         {
     128             :             // user index mark
     129           0 :             pElements = lcl_pUserIndexMarkName;
     130           0 :             if (nElementNo != 2)
     131             :             {
     132           0 :                 ExportUserIndexMarkAttributes(xIndexMarkPropSet);
     133             :             }
     134             :         }
     135           0 :         else if (xPropertySetInfo->hasPropertyByName(sPrimaryKey))
     136             :         {
     137             :             // alphabetical index mark
     138           0 :             pElements = lcl_pAlphaIndexMarkName;
     139           0 :             if (nElementNo != 2)
     140             :             {
     141           0 :                 ExportAlphabeticalIndexMarkAttributes(xIndexMarkPropSet);
     142             :             }
     143             :         }
     144             :         else
     145             :         {
     146             :             // table of content:
     147           0 :             pElements = lcl_pTocMarkNames;
     148           0 :             if (nElementNo != 2)
     149             :             {
     150           0 :                 ExportTOCMarkAttributes(xIndexMarkPropSet);
     151             :             }
     152             :         }
     153             : 
     154             :         // export element
     155             :         DBG_ASSERT(pElements != NULL, "illegal element array");
     156             :         DBG_ASSERT(nElementNo >= 0, "illegal name array index");
     157             :         DBG_ASSERT(nElementNo <= 2, "illegal name array index");
     158             : 
     159           0 :         if ((pElements != NULL) && (nElementNo != -1))
     160             :         {
     161             :             SvXMLElementExport aElem(rExport,
     162             :                                      XML_NAMESPACE_TEXT,
     163           0 :                                      pElements[nElementNo],
     164           0 :                                      false, false);
     165           0 :         }
     166             :     }
     167           0 : }
     168             : 
     169           0 : void XMLIndexMarkExport::ExportTOCMarkAttributes(
     170             :     const Reference<XPropertySet> & rPropSet)
     171             : {
     172             :     // outline level
     173           0 :     sal_Int16 nLevel = 0;
     174           0 :     Any aAny = rPropSet->getPropertyValue(sLevel);
     175           0 :     aAny >>= nLevel;
     176           0 :     OUStringBuffer sBuf;
     177           0 :     ::sax::Converter::convertNumber(sBuf, static_cast<sal_Int32>(nLevel + 1));
     178             :     rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
     179           0 :                              sBuf.makeStringAndClear());
     180           0 : }
     181             : 
     182           0 : static void lcl_ExportPropertyString( SvXMLExport& rExport,
     183             :                                const Reference<XPropertySet> & rPropSet,
     184             :                                const OUString & sProperty,
     185             :                                XMLTokenEnum eToken,
     186             :                                Any& rAny )
     187             : {
     188           0 :     rAny = rPropSet->getPropertyValue( sProperty );
     189             : 
     190           0 :     OUString sValue;
     191           0 :     if( rAny >>= sValue )
     192             :     {
     193           0 :         if( !sValue.isEmpty() )
     194             :         {
     195           0 :             rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, sValue );
     196             :         }
     197           0 :     }
     198           0 : }
     199             : 
     200           0 : static void lcl_ExportPropertyBool( SvXMLExport& rExport,
     201             :                              const Reference<XPropertySet> & rPropSet,
     202             :                              const OUString & sProperty,
     203             :                              XMLTokenEnum eToken,
     204             :                              Any& rAny )
     205             : {
     206           0 :     rAny = rPropSet->getPropertyValue( sProperty );
     207             : 
     208           0 :     sal_Bool bValue = sal_Bool();
     209           0 :     if( rAny >>= bValue )
     210             :     {
     211           0 :         if( bValue )
     212             :         {
     213           0 :             rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, XML_TRUE );
     214             :         }
     215             :     }
     216           0 : }
     217             : 
     218           0 : void XMLIndexMarkExport::ExportUserIndexMarkAttributes(
     219             :     const Reference<XPropertySet> & rPropSet)
     220             : {
     221             :     // name of user index
     222             :     // (unless it's the default index; then it has no name)
     223           0 :     Any aAny;
     224           0 :     lcl_ExportPropertyString( rExport, rPropSet, sUserIndexName, XML_INDEX_NAME, aAny );
     225             : 
     226             :     // additionally export outline level; just reuse ExportTOCMarkAttributes
     227           0 :     ExportTOCMarkAttributes( rPropSet );
     228           0 : }
     229             : 
     230           0 : void XMLIndexMarkExport::ExportAlphabeticalIndexMarkAttributes(
     231             :     const Reference<XPropertySet> & rPropSet)
     232             : {
     233             :     // primary and secondary keys (if available)
     234           0 :     Any aAny;
     235           0 :     lcl_ExportPropertyString( rExport, rPropSet, sTextReading, XML_STRING_VALUE_PHONETIC, aAny );
     236           0 :     lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKey, XML_KEY1, aAny );
     237           0 :     lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKeyReading, XML_KEY1_PHONETIC, aAny );
     238           0 :     lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKey, XML_KEY2, aAny );
     239           0 :     lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKeyReading, XML_KEY2_PHONETIC, aAny );
     240           0 :     lcl_ExportPropertyBool( rExport, rPropSet, sMainEntry, XML_MAIN_ENTRY, aAny );
     241           0 : }
     242             : 
     243           0 : void XMLIndexMarkExport::GetID(
     244             :     OUStringBuffer& sBuf,
     245             :     const Reference<XPropertySet> & rPropSet)
     246             : {
     247             :     static const sal_Char sPrefix[] = "IMark";
     248             : 
     249             :     // HACK: use address of object to form identifier
     250           0 :     sal_Int64 nId = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(rPropSet.get()));
     251           0 :     sBuf.appendAscii(sPrefix, sizeof(sPrefix)-1);
     252           0 :     sBuf.append(nId);
     253           0 : }
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10