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

Generated by: LCOV version 1.11