LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLFootnoteImportContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 80 82.5 %
Date: 2012-08-25 Functions: 4 10 40.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 66 149 44.3 %

           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 "XMLFootnoteImportContext.hxx"
      30                 :            : 
      31                 :            : #include <rtl/ustring.hxx>
      32                 :            : #include <xmloff/xmlimp.hxx>
      33                 :            : #include <xmloff/txtimp.hxx>
      34                 :            : #include <xmloff/nmspmap.hxx>
      35                 :            : #include "xmloff/xmlnmspe.hxx"
      36                 :            : #include <xmloff/xmltoken.hxx>
      37                 :            : 
      38                 :            : #include "XMLFootnoteBodyImportContext.hxx"
      39                 :            : #include "XMLTextListBlockContext.hxx"
      40                 :            : #include "XMLTextListItemContext.hxx"
      41                 :            : 
      42                 :            : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      43                 :            : #include <com/sun/star/text/XTextContent.hpp>
      44                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      45                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      46                 :            : #include <com/sun/star/text/XFootnote.hpp>
      47                 :            : 
      48                 :            : 
      49                 :            : using ::rtl::OUString;
      50                 :            : using ::rtl::OUStringBuffer;
      51                 :            : 
      52                 :            : using namespace ::com::sun::star::uno;
      53                 :            : using namespace ::com::sun::star::text;
      54                 :            : using namespace ::com::sun::star::lang;
      55                 :            : using namespace ::com::sun::star::beans;
      56                 :            : using namespace ::com::sun::star::xml::sax;
      57                 :            : using namespace ::xmloff::token;
      58                 :            : 
      59 [ #  # ][ #  # ]:          0 : TYPEINIT1(XMLFootnoteImportContext, SvXMLImportContext);
      60                 :            : 
      61                 :            : const sal_Char sAPI_service_footnote[] = "com.sun.star.text.Footnote";
      62                 :            : const sal_Char sAPI_service_endnote[] = "com.sun.star.text.Endnote";
      63                 :            : 
      64                 :            : enum XMLFootnoteChildToken {
      65                 :            :     XML_TOK_FTN_NOTE_CITATION,
      66                 :            :     XML_TOK_FTN_NOTE_BODY
      67                 :            : };
      68                 :            : 
      69                 :            : static SvXMLTokenMapEntry aFootnoteChildTokenMap[] =
      70                 :            : {
      71                 :            :     { XML_NAMESPACE_TEXT, XML_NOTE_CITATION,
      72                 :            :       XML_TOK_FTN_NOTE_CITATION },
      73                 :            :     { XML_NAMESPACE_TEXT, XML_NOTE_BODY, XML_TOK_FTN_NOTE_BODY },
      74                 :            :     XML_TOKEN_MAP_END
      75                 :            : };
      76                 :            : 
      77                 :            : 
      78                 :          3 : XMLFootnoteImportContext::XMLFootnoteImportContext(
      79                 :            :     SvXMLImport& rImport,
      80                 :            :     XMLTextImportHelper& rHlp,
      81                 :            :     sal_uInt16 nPrfx,
      82                 :            :     const OUString& rLocalName )
      83                 :            : :   SvXMLImportContext(rImport, nPrfx, rLocalName)
      84                 :            : ,   sPropertyReferenceId(RTL_CONSTASCII_USTRINGPARAM("ReferenceId"))
      85                 :            : ,   mbListContextPushed(false)
      86         [ +  - ]:          3 : ,   rHelper(rHlp)
      87                 :            : {
      88                 :          3 : }
      89                 :            : 
      90                 :          3 : void XMLFootnoteImportContext::StartElement(
      91                 :            :     const Reference<XAttributeList> & xAttrList)
      92                 :            : {
      93                 :            :     // create footnote
      94                 :          3 :     Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
      95         [ +  - ]:          3 :                                              UNO_QUERY);
      96         [ +  - ]:          3 :     if( xFactory.is() )
      97                 :            :     {
      98                 :            :         // create endnote or footnote
      99                 :          3 :         sal_Bool bIsEndnote = sal_False;
     100 [ +  - ][ +  - ]:          3 :         sal_Int16 nLength = xAttrList->getLength();
     101         [ +  - ]:          9 :         for(sal_Int16 nAttr1 = 0; nAttr1 < nLength; nAttr1++)
     102                 :            :         {
     103                 :          6 :             OUString sLocalName;
     104                 :          6 :             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     105         [ +  - ]:          6 :                 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr1),
     106   [ +  -  +  - ]:         12 :                                   &sLocalName );
     107 [ +  + ][ +  + ]:         12 :             if( XML_NAMESPACE_TEXT == nPrefix && IsXMLToken( sLocalName,
                 [ +  - ]
     108         [ +  - ]:          6 :                                                             XML_NOTE_CLASS ) )
     109                 :            :             {
     110 [ +  - ][ +  - ]:          3 :                 const OUString& rValue = xAttrList->getValueByIndex( nAttr1 );
     111 [ +  - ][ -  + ]:          3 :                 if( IsXMLToken( rValue, XML_ENDNOTE ) )
     112                 :          0 :                     bIsEndnote = sal_True;
     113                 :          6 :                 break;
     114                 :            :             }
     115         [ +  + ]:          6 :         }
     116                 :            : 
     117         [ +  - ]:          3 :         Reference<XInterface> xIfc = xFactory->createInstance(
     118                 :            :             bIsEndnote ?
     119                 :            :             OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_service_endnote)) :
     120 [ -  + ][ #  # ]:          3 :             OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_service_footnote)) );
         [ +  - ][ +  - ]
     121                 :            : 
     122                 :            :         // attach footnote to document
     123         [ +  - ]:          3 :         Reference<XTextContent> xTextContent(xIfc, UNO_QUERY);
     124         [ +  - ]:          3 :         rHelper.InsertTextContent(xTextContent);
     125                 :            : 
     126                 :            :         // process id attribute
     127         [ +  + ]:          9 :         for(sal_Int16 nAttr2 = 0; nAttr2 < nLength; nAttr2++)
     128                 :            :         {
     129                 :          6 :             OUString sLocalName;
     130                 :          6 :             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     131         [ +  - ]:          6 :                 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr2),
     132   [ +  -  +  - ]:         12 :                                   &sLocalName );
     133                 :            : 
     134 [ +  + ][ +  + ]:         12 :             if ( (XML_NAMESPACE_TEXT == nPrefix) &&
                 [ +  - ]
     135         [ +  - ]:          6 :                  IsXMLToken( sLocalName, XML_ID )   )
     136                 :            :             {
     137                 :            :                 // get ID ...
     138         [ +  - ]:          3 :                 Reference<XPropertySet> xPropertySet(xTextContent, UNO_QUERY);
     139 [ +  - ][ +  - ]:          3 :                 Any aAny =xPropertySet->getPropertyValue(sPropertyReferenceId);
     140                 :          3 :                 sal_Int16 nID = 0;
     141                 :          3 :                 aAny >>= nID;
     142                 :            : 
     143                 :            :                 // ... and insert into map
     144                 :            :                 rHelper.InsertFootnoteID(
     145         [ +  - ]:          3 :                     xAttrList->getValueByIndex(nAttr2),
     146 [ +  - ][ +  - ]:          3 :                     nID);
     147                 :            :             }
     148                 :          6 :         }
     149                 :            : 
     150                 :            :         // save old cursor and install new one
     151 [ +  - ][ +  - ]:          3 :         xOldCursor = rHelper.GetCursor();
     152         [ +  - ]:          3 :         Reference<XText> xText(xTextContent, UNO_QUERY);
     153 [ +  - ][ +  - ]:          3 :         rHelper.SetCursor(xText->createTextCursor());
                 [ +  - ]
     154                 :            : 
     155                 :            :         // remember old list item and block (#89891#) and reset them
     156                 :            :         // for the footnote
     157         [ +  - ]:          3 :         rHelper.PushListContext();
     158                 :          3 :         mbListContextPushed = true;
     159                 :            : 
     160                 :            :         // remember footnote (for CreateChildContext)
     161         [ +  - ]:          3 :         Reference<XFootnote> xNote(xTextContent, UNO_QUERY);
     162         [ +  - ]:          3 :         xFootnote = xNote;
     163                 :          3 :     }
     164                 :            :     // else: ignore footnote! Content will be merged into document.
     165                 :          3 : }
     166                 :            : 
     167                 :          0 : void XMLFootnoteImportContext::Characters(const OUString&)
     168                 :            : {
     169                 :            :     // ignore characters! Text must be contained in paragraphs!
     170                 :            :     // rHelper.InsertString(rString);
     171                 :          0 : }
     172                 :            : 
     173                 :          3 : void XMLFootnoteImportContext::EndElement()
     174                 :            : {
     175                 :            :     // get rid of last dummy paragraph
     176                 :          3 :     rHelper.DeleteParagraph();
     177                 :            : 
     178                 :            :     // reinstall old cursor
     179                 :          3 :     rHelper.SetCursor(xOldCursor);
     180                 :            : 
     181                 :            :     // reinstall old list item
     182         [ +  - ]:          3 :     if (mbListContextPushed) {
     183                 :          3 :         rHelper.PopListContext();
     184                 :            :     }
     185                 :          3 : }
     186                 :            : 
     187                 :            : 
     188                 :          6 : SvXMLImportContext *XMLFootnoteImportContext::CreateChildContext(
     189                 :            :     sal_uInt16 p_nPrefix,
     190                 :            :     const OUString& rLocalName,
     191                 :            :     const Reference<XAttributeList> & xAttrList )
     192                 :            : {
     193                 :          6 :     SvXMLImportContext* pContext = NULL;
     194                 :            : 
     195         [ +  - ]:          6 :     SvXMLTokenMap aTokenMap(aFootnoteChildTokenMap);
     196                 :            : 
     197         [ +  - ]:          6 :     switch(aTokenMap.Get(p_nPrefix, rLocalName))
              [ +  +  - ]
     198                 :            :     {
     199                 :            :         case XML_TOK_FTN_NOTE_CITATION:
     200                 :            :         {
     201                 :            :             // little hack: we only care for one attribute of the citation
     202                 :            :             //              element. We handle that here, and then return a
     203                 :            :             //              default context.
     204 [ +  - ][ +  - ]:          3 :             sal_Int16 nLength = xAttrList->getLength();
     205         [ -  + ]:          3 :             for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     206                 :            :             {
     207                 :          0 :                 OUString sLocalName;
     208                 :          0 :                 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
     209         [ #  # ]:          0 :                     GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     210   [ #  #  #  # ]:          0 :                                       &sLocalName );
     211                 :            : 
     212 [ #  # ][ #  # ]:          0 :                 if ( (nPrefix == XML_NAMESPACE_TEXT) &&
                 [ #  # ]
     213         [ #  # ]:          0 :                      IsXMLToken( sLocalName, XML_LABEL ) )
     214                 :            :                 {
     215 [ #  # ][ #  # ]:          0 :                     xFootnote->setLabel(xAttrList->getValueByIndex(nAttr));
         [ #  # ][ #  # ]
     216                 :            :                 }
     217                 :          0 :             }
     218                 :            : 
     219                 :            :             // ignore content: return default context
     220                 :          3 :             pContext = new SvXMLImportContext(GetImport(),
     221 [ +  - ][ +  - ]:          3 :                                               p_nPrefix, rLocalName);
     222                 :          3 :             break;
     223                 :            :         }
     224                 :            : 
     225                 :            :         case XML_TOK_FTN_NOTE_BODY:
     226                 :            :             // return footnote body
     227                 :          3 :             pContext = new XMLFootnoteBodyImportContext(GetImport(),
     228 [ +  - ][ +  - ]:          3 :                                                         p_nPrefix, rLocalName);
     229                 :          3 :             break;
     230                 :            :         default:
     231                 :            :             // default:
     232                 :            :             pContext = SvXMLImportContext::CreateChildContext(p_nPrefix,
     233                 :            :                                                               rLocalName,
     234         [ #  # ]:          0 :                                                               xAttrList);
     235                 :          0 :             break;
     236                 :            :     }
     237                 :            : 
     238         [ +  - ]:          6 :     return pContext;
     239                 :            : }
     240                 :            : 
     241                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10