LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLChangedRegionImportContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 65 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 110 0.0 %

           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 "XMLChangedRegionImportContext.hxx"
      30                 :            : #include "XMLChangeElementImportContext.hxx"
      31                 :            : #include <com/sun/star/uno/Reference.h>
      32                 :            : #include <com/sun/star/util/DateTime.hpp>
      33                 :            : #include <com/sun/star/text/XTextCursor.hpp>
      34                 :            : 
      35                 :            : #include <sax/tools/converter.hxx>
      36                 :            : 
      37                 :            : #include <xmloff/xmlimp.hxx>
      38                 :            : #include "xmloff/xmlnmspe.hxx"
      39                 :            : #include <xmloff/nmspmap.hxx>
      40                 :            : #include <xmloff/xmltoken.hxx>
      41                 :            : 
      42                 :            : 
      43                 :            : using namespace ::xmloff::token;
      44                 :            : 
      45                 :            : using ::rtl::OUString;
      46                 :            : using ::com::sun::star::uno::Reference;
      47                 :            : using ::com::sun::star::text::XTextCursor;
      48                 :            : using ::com::sun::star::util::DateTime;
      49                 :            : using ::com::sun::star::xml::sax::XAttributeList;
      50                 :            : 
      51                 :            : 
      52                 :            : 
      53 [ #  # ][ #  # ]:          0 : TYPEINIT1(XMLChangedRegionImportContext, SvXMLImportContext);
      54                 :            : 
      55                 :          0 : XMLChangedRegionImportContext::XMLChangedRegionImportContext(
      56                 :            :     SvXMLImport& rImport,
      57                 :            :     sal_uInt16 nPrefix,
      58                 :            :     const OUString& rLocalName) :
      59                 :            :         SvXMLImportContext(rImport, nPrefix, rLocalName),
      60                 :          0 :         bMergeLastPara(sal_True)
      61                 :            : {
      62                 :          0 : }
      63                 :            : 
      64                 :          0 : XMLChangedRegionImportContext::~XMLChangedRegionImportContext()
      65                 :            : {
      66         [ #  # ]:          0 : }
      67                 :            : 
      68                 :          0 : void XMLChangedRegionImportContext::StartElement(
      69                 :            :     const Reference<XAttributeList> & xAttrList)
      70                 :            : {
      71                 :            :     // process attributes: id
      72                 :          0 :     bool bHaveXmlId( false );
      73                 :          0 :     sal_Int16 nLength = xAttrList->getLength();
      74         [ #  # ]:          0 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      75                 :            :     {
      76                 :          0 :         OUString sLocalName;
      77                 :          0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      78         [ #  # ]:          0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      79   [ #  #  #  # ]:          0 :                               &sLocalName );
      80                 :            : 
      81 [ #  # ][ #  # ]:          0 :         const OUString sValue = xAttrList->getValueByIndex(nAttr);
      82         [ #  # ]:          0 :         if (XML_NAMESPACE_XML == nPrefix)
      83                 :            :         {
      84 [ #  # ][ #  # ]:          0 :             if (IsXMLToken(sLocalName, XML_ID))
      85                 :            :             {
      86                 :          0 :                 sID = sValue;
      87                 :          0 :                 bHaveXmlId = true;
      88                 :            :             }
      89                 :            :         }
      90         [ #  # ]:          0 :         else if (XML_NAMESPACE_TEXT == nPrefix)
      91                 :            :         {
      92 [ #  # ][ #  # ]:          0 :             if (IsXMLToken(sLocalName, XML_ID))
      93                 :            :             {
      94         [ #  # ]:          0 :                 if (!bHaveXmlId) { sID = sValue; }
      95                 :            :             }
      96 [ #  # ][ #  # ]:          0 :             else if( IsXMLToken( sLocalName, XML_MERGE_LAST_PARAGRAPH ) )
      97                 :            :             {
      98                 :          0 :                 bool bTmp(false);
      99 [ #  # ][ #  # ]:          0 :                 if (::sax::Converter::convertBool(bTmp, sValue))
     100                 :            :                 {
     101                 :          0 :                     bMergeLastPara = bTmp;
     102                 :            :                 }
     103                 :            :             }
     104                 :            :         }
     105                 :          0 :     }
     106                 :          0 : }
     107                 :            : 
     108                 :          0 : SvXMLImportContext* XMLChangedRegionImportContext::CreateChildContext(
     109                 :            :     sal_uInt16 nPrefix,
     110                 :            :     const OUString& rLocalName,
     111                 :            :     const Reference<XAttributeList> & xAttrList)
     112                 :            : {
     113                 :          0 :     SvXMLImportContext* pContext = NULL;
     114                 :            : 
     115         [ #  # ]:          0 :     if (XML_NAMESPACE_TEXT == nPrefix)
     116                 :            :     {
     117   [ #  #  #  #  :          0 :         if ( IsXMLToken( rLocalName, XML_INSERTION ) ||
           #  # ][ #  # ]
     118                 :          0 :              IsXMLToken( rLocalName, XML_DELETION ) ||
     119                 :          0 :              IsXMLToken( rLocalName, XML_FORMAT_CHANGE ) )
     120                 :            :         {
     121                 :            :             // create XMLChangeElementImportContext for all kinds of changes
     122                 :            :             pContext = new XMLChangeElementImportContext(
     123                 :          0 :                GetImport(), nPrefix, rLocalName,
     124                 :          0 :                IsXMLToken( rLocalName, XML_DELETION ),
     125         [ #  # ]:          0 :                *this);
     126                 :            :         }
     127                 :            :         // else: it may be a text element, see below
     128                 :            :     }
     129                 :            : 
     130         [ #  # ]:          0 :     if (NULL == pContext)
     131                 :            :     {
     132                 :            :         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
     133                 :          0 :                                                           xAttrList);
     134                 :            : 
     135                 :            :         // was it a text element? If not, use default!
     136         [ #  # ]:          0 :         if (NULL == pContext)
     137                 :            :         {
     138                 :            :             pContext = SvXMLImportContext::CreateChildContext(
     139                 :          0 :                 nPrefix, rLocalName, xAttrList);
     140                 :            :         }
     141                 :            :     }
     142                 :            : 
     143                 :          0 :     return pContext;
     144                 :            : }
     145                 :            : 
     146                 :          0 : void XMLChangedRegionImportContext::EndElement()
     147                 :            : {
     148                 :            :     // restore old XCursor (if necessary)
     149         [ #  # ]:          0 :     if (xOldCursor.is())
     150                 :            :     {
     151                 :            :         // delete last paragraph
     152                 :            :         // (one extra paragraph was inserted in the beginning)
     153                 :            :         UniReference<XMLTextImportHelper> rHelper =
     154         [ #  # ]:          0 :             GetImport().GetTextImport();
     155 [ #  # ][ #  # ]:          0 :         rHelper->DeleteParagraph();
     156                 :            : 
     157 [ #  # ][ #  # ]:          0 :         GetImport().GetTextImport()->SetCursor(xOldCursor);
         [ #  # ][ #  # ]
     158 [ #  # ][ #  # ]:          0 :         xOldCursor = NULL;
     159                 :            :     }
     160                 :          0 : }
     161                 :            : 
     162                 :          0 : void XMLChangedRegionImportContext::SetChangeInfo(
     163                 :            :     const OUString& rType,
     164                 :            :     const OUString& rAuthor,
     165                 :            :     const OUString& rComment,
     166                 :            :     const OUString& rDate)
     167                 :            : {
     168                 :          0 :     DateTime aDateTime;
     169 [ #  # ][ #  # ]:          0 :     if (::sax::Converter::convertDateTime(aDateTime, rDate))
     170                 :            :     {
     171 [ #  # ][ #  # ]:          0 :         GetImport().GetTextImport()->RedlineAdd(
                 [ #  # ]
     172         [ #  # ]:          0 :             rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara);
     173                 :            :     }
     174                 :          0 : }
     175                 :            : 
     176                 :          0 : void XMLChangedRegionImportContext::UseRedlineText()
     177                 :            : {
     178                 :            :     // if we haven't already installed the redline cursor, do it now
     179         [ #  # ]:          0 :     if (! xOldCursor.is())
     180                 :            :     {
     181                 :            :         // get TextImportHelper and old Cursor
     182         [ #  # ]:          0 :         UniReference<XMLTextImportHelper> rHelper(GetImport().GetTextImport());
     183 [ #  # ][ #  # ]:          0 :         Reference<XTextCursor> xCursor( rHelper->GetCursor() );
     184                 :            : 
     185                 :            :         // create Redline and new Cursor
     186                 :            :         Reference<XTextCursor> xNewCursor =
     187 [ #  # ][ #  # ]:          0 :             rHelper->RedlineCreateText(xCursor, sID);
     188                 :            : 
     189         [ #  # ]:          0 :         if (xNewCursor.is())
     190                 :            :         {
     191                 :            :             // save old cursor and install new one
     192         [ #  # ]:          0 :             xOldCursor = xCursor;
     193 [ #  # ][ #  # ]:          0 :             rHelper->SetCursor( xNewCursor );
     194         [ #  # ]:          0 :         }
     195                 :            :         // else: leave as is
     196                 :            :     }
     197                 :          0 : }
     198                 :            : 
     199                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10