LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexMarkExport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 84 6.0 %
Date: 2012-08-25 Functions: 2 9 22.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 136 8.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "XMLIndexMarkExport.hxx"
      30                 :            : #include <tools/debug.hxx>
      31                 :            : #include <rtl/ustring.hxx>
      32                 :            : #include <rtl/ustrbuf.hxx>
      33                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      34                 :            : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      35                 :            : #include <sax/tools/converter.hxx>
      36                 :            : #include <xmloff/xmltoken.hxx>
      37                 :            : #include "xmloff/xmlnmspe.hxx"
      38                 :            : #include <xmloff/xmlexp.hxx>
      39                 :            : 
      40                 :            : 
      41                 :            : using namespace ::xmloff::token;
      42                 :            : 
      43                 :            : using ::rtl::OUString;
      44                 :            : using ::rtl::OUStringBuffer;
      45                 :            : using ::com::sun::star::beans::XPropertySet;
      46                 :            : using ::com::sun::star::beans::XPropertySetInfo;
      47                 :            : using ::com::sun::star::uno::Reference;
      48                 :            : using ::com::sun::star::uno::Any;
      49                 :            : 
      50                 :            : 
      51                 :            : 
      52                 :         77 : XMLIndexMarkExport::XMLIndexMarkExport(
      53                 :            :     SvXMLExport& rExp)
      54                 :            : :   sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
      55                 :            : ,   sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName"))
      56                 :            : ,   sPrimaryKey(RTL_CONSTASCII_USTRINGPARAM("PrimaryKey"))
      57                 :            : ,   sSecondaryKey(RTL_CONSTASCII_USTRINGPARAM("SecondaryKey"))
      58                 :            : ,   sDocumentIndexMark(RTL_CONSTASCII_USTRINGPARAM("DocumentIndexMark"))
      59                 :            : ,   sIsStart(RTL_CONSTASCII_USTRINGPARAM("IsStart"))
      60                 :            : ,   sIsCollapsed(RTL_CONSTASCII_USTRINGPARAM("IsCollapsed"))
      61                 :            : ,   sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText"))
      62                 :            : ,   sTextReading(RTL_CONSTASCII_USTRINGPARAM("TextReading"))
      63                 :            : ,   sPrimaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("PrimaryKeyReading"))
      64                 :            : ,   sSecondaryKeyReading(RTL_CONSTASCII_USTRINGPARAM("SecondaryKeyReading"))
      65                 :            : ,   sMainEntry(RTL_CONSTASCII_USTRINGPARAM("IsMainEntry"))
      66 [ +  - ][ +  - ]:         77 : ,   rExport(rExp)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      67                 :            : {
      68                 :         77 : }
      69                 :            : 
      70                 :            : const enum XMLTokenEnum lcl_pTocMarkNames[] =
      71                 :            :     { XML_TOC_MARK, XML_TOC_MARK_START, XML_TOC_MARK_END };
      72                 :            : const enum XMLTokenEnum lcl_pUserIndexMarkName[] =
      73                 :            :     { XML_USER_INDEX_MARK,
      74                 :            :           XML_USER_INDEX_MARK_START, XML_USER_INDEX_MARK_END };
      75                 :            : const enum XMLTokenEnum lcl_pAlphaIndexMarkName[] =
      76                 :            :     { XML_ALPHABETICAL_INDEX_MARK,
      77                 :            :           XML_ALPHABETICAL_INDEX_MARK_START,
      78                 :            :           XML_ALPHABETICAL_INDEX_MARK_END };
      79                 :            : 
      80                 :            : 
      81                 :         77 : XMLIndexMarkExport::~XMLIndexMarkExport()
      82                 :            : {
      83                 :         77 : }
      84                 :            : 
      85                 :          0 : void XMLIndexMarkExport::ExportIndexMark(
      86                 :            :     const Reference<XPropertySet> & rPropSet,
      87                 :            :     sal_Bool bAutoStyles)
      88                 :            : {
      89                 :            :     /// index marks have no styles!
      90         [ #  # ]:          0 :     if (!bAutoStyles)
      91                 :            :     {
      92                 :          0 :         const enum XMLTokenEnum * pElements = NULL;
      93                 :          0 :         sal_Int8 nElementNo = -1;
      94                 :            : 
      95                 :            :         // get index mark
      96                 :          0 :         Any aAny;
      97 [ #  # ][ #  # ]:          0 :         aAny = rPropSet->getPropertyValue(sDocumentIndexMark);
      98                 :          0 :         Reference<XPropertySet> xIndexMarkPropSet;
      99         [ #  # ]:          0 :         aAny >>= xIndexMarkPropSet;
     100                 :            : 
     101                 :            :         // common: handling of start, end, collapsed entries and
     102                 :            :         // alternative text
     103                 :            : 
     104                 :            :         // collapsed/alternative text entry?
     105 [ #  # ][ #  # ]:          0 :         aAny = rPropSet->getPropertyValue(sIsCollapsed);
     106         [ #  # ]:          0 :         if (*(sal_Bool *)aAny.getValue())
     107                 :            :         {
     108                 :            :             // collapsed entry: needs alternative text
     109                 :          0 :             nElementNo = 0;
     110                 :            : 
     111 [ #  # ][ #  # ]:          0 :             aAny = xIndexMarkPropSet->getPropertyValue(sAlternativeText);
     112                 :          0 :             OUString sTmp;
     113                 :          0 :             aAny >>= sTmp;
     114                 :            :             DBG_ASSERT(!sTmp.isEmpty(),
     115                 :            :                        "collapsed index mark without alternative text");
     116         [ #  # ]:          0 :             rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STRING_VALUE, sTmp);
     117                 :            :         }
     118                 :            :         else
     119                 :            :         {
     120                 :            :             // start and end entries: has ID
     121 [ #  # ][ #  # ]:          0 :             aAny = rPropSet->getPropertyValue(sIsStart);
     122         [ #  # ]:          0 :             nElementNo = *(sal_Bool *)aAny.getValue() ? 1 : 2;
     123                 :            : 
     124                 :            :             // generate ID
     125                 :          0 :             OUStringBuffer sBuf;
     126         [ #  # ]:          0 :             GetID(sBuf, xIndexMarkPropSet);
     127                 :            :             rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_ID,
     128 [ #  # ][ #  # ]:          0 :                                  sBuf.makeStringAndClear());
     129                 :            :         }
     130                 :            : 
     131                 :            :         // distinguish between TOC, user, alphab. index marks by
     132                 :            :         // asking for specific properties
     133                 :            :         // Export attributes for -mark-start and -mark elements,
     134                 :            :         // but not for -mark-end
     135                 :            :         Reference<XPropertySetInfo> xPropertySetInfo =
     136 [ #  # ][ #  # ]:          0 :             xIndexMarkPropSet->getPropertySetInfo();
     137 [ #  # ][ #  # ]:          0 :         if (xPropertySetInfo->hasPropertyByName(sUserIndexName))
                 [ #  # ]
     138                 :            :         {
     139                 :            :             // user index mark
     140                 :          0 :             pElements = lcl_pUserIndexMarkName;
     141         [ #  # ]:          0 :             if (nElementNo != 2)
     142                 :            :             {
     143         [ #  # ]:          0 :                 ExportUserIndexMarkAttributes(xIndexMarkPropSet);
     144                 :            :             }
     145                 :            :         }
     146 [ #  # ][ #  # ]:          0 :         else if (xPropertySetInfo->hasPropertyByName(sPrimaryKey))
                 [ #  # ]
     147                 :            :         {
     148                 :            :             // alphabetical index mark
     149                 :          0 :             pElements = lcl_pAlphaIndexMarkName;
     150         [ #  # ]:          0 :             if (nElementNo != 2)
     151                 :            :             {
     152         [ #  # ]:          0 :                 ExportAlphabeticalIndexMarkAttributes(xIndexMarkPropSet);
     153                 :            :             }
     154                 :            :         }
     155                 :            :         else
     156                 :            :         {
     157                 :            :             // table of content:
     158                 :          0 :             pElements = lcl_pTocMarkNames;
     159         [ #  # ]:          0 :             if (nElementNo != 2)
     160                 :            :             {
     161         [ #  # ]:          0 :                 ExportTOCMarkAttributes(xIndexMarkPropSet);
     162                 :            :             }
     163                 :            :         }
     164                 :            : 
     165                 :            :         // export element
     166                 :            :         DBG_ASSERT(pElements != NULL, "illegal element array");
     167                 :            :         DBG_ASSERT(nElementNo >= 0, "illegal name array index");
     168                 :            :         DBG_ASSERT(nElementNo <= 2, "illegal name array index");
     169                 :            : 
     170 [ #  # ][ #  # ]:          0 :         if ((pElements != NULL) && (nElementNo != -1))
     171                 :            :         {
     172                 :            :             SvXMLElementExport aElem(rExport,
     173                 :            :                                      XML_NAMESPACE_TEXT,
     174                 :          0 :                                      pElements[nElementNo],
     175 [ #  # ][ #  # ]:          0 :                                      sal_False, sal_False);
     176                 :          0 :         }
     177                 :            :     }
     178                 :          0 : }
     179                 :            : 
     180                 :          0 : void XMLIndexMarkExport::ExportTOCMarkAttributes(
     181                 :            :     const Reference<XPropertySet> & rPropSet)
     182                 :            : {
     183                 :            :     // outline level
     184                 :          0 :     sal_Int16 nLevel = 0;
     185 [ #  # ][ #  # ]:          0 :     Any aAny = rPropSet->getPropertyValue(sLevel);
     186                 :          0 :     aAny >>= nLevel;
     187                 :          0 :     OUStringBuffer sBuf;
     188         [ #  # ]:          0 :     ::sax::Converter::convertNumber(sBuf, static_cast<sal_Int32>(nLevel + 1));
     189                 :            :     rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
     190 [ #  # ][ #  # ]:          0 :                              sBuf.makeStringAndClear());
     191                 :          0 : }
     192                 :            : 
     193                 :          0 : void lcl_ExportPropertyString( SvXMLExport& rExport,
     194                 :            :                                const Reference<XPropertySet> & rPropSet,
     195                 :            :                                const OUString & sProperty,
     196                 :            :                                XMLTokenEnum eToken,
     197                 :            :                                Any& rAny )
     198                 :            : {
     199 [ #  # ][ #  # ]:          0 :     rAny = rPropSet->getPropertyValue( sProperty );
     200                 :            : 
     201                 :          0 :     OUString sValue;
     202         [ #  # ]:          0 :     if( rAny >>= sValue )
     203                 :            :     {
     204         [ #  # ]:          0 :         if( !sValue.isEmpty() )
     205                 :            :         {
     206         [ #  # ]:          0 :             rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, sValue );
     207                 :            :         }
     208                 :          0 :     }
     209                 :          0 : }
     210                 :            : 
     211                 :          0 : void lcl_ExportPropertyBool( SvXMLExport& rExport,
     212                 :            :                              const Reference<XPropertySet> & rPropSet,
     213                 :            :                              const OUString & sProperty,
     214                 :            :                              XMLTokenEnum eToken,
     215                 :            :                              Any& rAny )
     216                 :            : {
     217 [ #  # ][ #  # ]:          0 :     rAny = rPropSet->getPropertyValue( sProperty );
     218                 :            : 
     219                 :          0 :     sal_Bool bValue = sal_Bool();
     220         [ #  # ]:          0 :     if( rAny >>= bValue )
     221                 :            :     {
     222         [ #  # ]:          0 :         if( bValue )
     223                 :            :         {
     224         [ #  # ]:          0 :             rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, XML_TRUE );
     225                 :            :         }
     226                 :            :     }
     227                 :          0 : }
     228                 :            : 
     229                 :          0 : void XMLIndexMarkExport::ExportUserIndexMarkAttributes(
     230                 :            :     const Reference<XPropertySet> & rPropSet)
     231                 :            : {
     232                 :            :     // name of user index
     233                 :            :     // (unless it's the default index; then it has no name)
     234                 :          0 :     Any aAny;
     235         [ #  # ]:          0 :     lcl_ExportPropertyString( rExport, rPropSet, sUserIndexName, XML_INDEX_NAME, aAny );
     236                 :            : 
     237                 :            :     // additionally export outline level; just reuse ExportTOCMarkAttributes
     238         [ #  # ]:          0 :     ExportTOCMarkAttributes( rPropSet );
     239                 :          0 : }
     240                 :            : 
     241                 :          0 : void XMLIndexMarkExport::ExportAlphabeticalIndexMarkAttributes(
     242                 :            :     const Reference<XPropertySet> & rPropSet)
     243                 :            : {
     244                 :            :     // primary and secondary keys (if available)
     245                 :          0 :     Any aAny;
     246         [ #  # ]:          0 :     lcl_ExportPropertyString( rExport, rPropSet, sTextReading, XML_STRING_VALUE_PHONETIC, aAny );
     247         [ #  # ]:          0 :     lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKey, XML_KEY1, aAny );
     248         [ #  # ]:          0 :     lcl_ExportPropertyString( rExport, rPropSet, sPrimaryKeyReading, XML_KEY1_PHONETIC, aAny );
     249         [ #  # ]:          0 :     lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKey, XML_KEY2, aAny );
     250         [ #  # ]:          0 :     lcl_ExportPropertyString( rExport, rPropSet, sSecondaryKeyReading, XML_KEY2_PHONETIC, aAny );
     251         [ #  # ]:          0 :     lcl_ExportPropertyBool( rExport, rPropSet, sMainEntry, XML_MAIN_ENTRY, aAny );
     252                 :          0 : }
     253                 :            : 
     254                 :          0 : void XMLIndexMarkExport::GetID(
     255                 :            :     OUStringBuffer& sBuf,
     256                 :            :     const Reference<XPropertySet> & rPropSet)
     257                 :            : {
     258                 :            :     static const sal_Char sPrefix[] = "IMark";
     259                 :            : 
     260                 :            :     // HACK: use address of object to form identifier
     261                 :          0 :     sal_Int64 nId = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(rPropSet.get()));
     262                 :          0 :     sBuf.appendAscii(sPrefix, sizeof(sPrefix)-1);
     263                 :          0 :     sBuf.append(nId);
     264                 :          0 : }
     265                 :            : 
     266                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10