LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLChangedRegionImportContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 56 65 86.2 %
Date: 2014-11-03 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          20 : XMLChangedRegionImportContext::XMLChangedRegionImportContext(
      46             :     SvXMLImport& rImport,
      47             :     sal_uInt16 nPrefix,
      48             :     const OUString& rLocalName) :
      49             :         SvXMLImportContext(rImport, nPrefix, rLocalName),
      50          20 :         bMergeLastPara(true)
      51             : {
      52          20 : }
      53             : 
      54          40 : XMLChangedRegionImportContext::~XMLChangedRegionImportContext()
      55             : {
      56          40 : }
      57             : 
      58          20 : void XMLChangedRegionImportContext::StartElement(
      59             :     const Reference<XAttributeList> & xAttrList)
      60             : {
      61             :     // process attributes: id
      62          20 :     bool bHaveXmlId( false );
      63          20 :     sal_Int16 nLength = xAttrList->getLength();
      64          60 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      65             :     {
      66          40 :         OUString sLocalName;
      67          40 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      68          40 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      69          80 :                               &sLocalName );
      70             : 
      71          80 :         const OUString sValue = xAttrList->getValueByIndex(nAttr);
      72          40 :         if (XML_NAMESPACE_XML == nPrefix)
      73             :         {
      74          20 :             if (IsXMLToken(sLocalName, XML_ID))
      75             :             {
      76          20 :                 sID = sValue;
      77          20 :                 bHaveXmlId = true;
      78             :             }
      79             :         }
      80          20 :         else if (XML_NAMESPACE_TEXT == nPrefix)
      81             :         {
      82          20 :             if (IsXMLToken(sLocalName, XML_ID))
      83             :             {
      84          20 :                 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          40 :     }
      96          20 : }
      97             : 
      98          20 : SvXMLImportContext* XMLChangedRegionImportContext::CreateChildContext(
      99             :     sal_uInt16 nPrefix,
     100             :     const OUString& rLocalName,
     101             :     const Reference<XAttributeList> & xAttrList)
     102             : {
     103          20 :     SvXMLImportContext* pContext = NULL;
     104             : 
     105          20 :     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          52 :         if ( IsXMLToken( rLocalName, XML_INSERTION ) ||
     111          20 :              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          20 :                GetImport(), nPrefix, rLocalName,
     117          20 :                IsXMLToken( rLocalName, XML_DELETION ),
     118          40 :                *this);
     119             :         }
     120             :         // else: it may be a text element, see below
     121             :     }
     122             : 
     123          20 :     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          20 :     return pContext;
     140             : }
     141             : 
     142          20 : void XMLChangedRegionImportContext::EndElement()
     143             : {
     144             :     // restore old XCursor (if necessary)
     145          20 :     if (xOldCursor.is())
     146             :     {
     147             :         // delete last paragraph
     148             :         // (one extra paragraph was inserted in the beginning)
     149             :         rtl::Reference<XMLTextImportHelper> rHelper =
     150          12 :             GetImport().GetTextImport();
     151          12 :         rHelper->DeleteParagraph();
     152             : 
     153          12 :         GetImport().GetTextImport()->SetCursor(xOldCursor);
     154          12 :         xOldCursor = NULL;
     155             :     }
     156          20 : }
     157             : 
     158          20 : void XMLChangedRegionImportContext::SetChangeInfo(
     159             :     const OUString& rType,
     160             :     const OUString& rAuthor,
     161             :     const OUString& rComment,
     162             :     const OUString& rDate)
     163             : {
     164          20 :     util::DateTime aDateTime;
     165          20 :     if (::sax::Converter::parseDateTime(aDateTime, 0, rDate))
     166             :     {
     167          40 :         GetImport().GetTextImport()->RedlineAdd(
     168          20 :             rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara);
     169             :     }
     170          20 : }
     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          12 :         rtl::Reference<XMLTextImportHelper> rHelper(GetImport().GetTextImport());
     179          24 :         Reference<XTextCursor> xCursor( rHelper->GetCursor() );
     180             : 
     181             :         // create Redline and new Cursor
     182             :         Reference<XTextCursor> xNewCursor =
     183          24 :             rHelper->RedlineCreateText(xCursor, sID);
     184             : 
     185          12 :         if (xNewCursor.is())
     186             :         {
     187             :             // save old cursor and install new one
     188          12 :             xOldCursor = xCursor;
     189          12 :             rHelper->SetCursor( xNewCursor );
     190          12 :         }
     191             :         // else: leave as is
     192             :     }
     193          18 : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10