1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmlnamespace.hxx>
30 #include <xmloff/namespacemap.hxx>
31 #include <xmloff/xmltoken.hxx>
34 using namespace ::xmloff::token
;
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
;
42 XMLChangedRegionImportContext::XMLChangedRegionImportContext(SvXMLImport
& rImport
) :
43 SvXMLImportContext(rImport
),
48 XMLChangedRegionImportContext::~XMLChangedRegionImportContext()
52 void XMLChangedRegionImportContext::StartElement(
53 const Reference
<XAttributeList
> & xAttrList
)
55 // process attributes: id
56 bool bHaveXmlId( false );
57 sal_Int16 nLength
= xAttrList
->getLength();
58 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
61 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
62 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
65 const OUString sValue
= xAttrList
->getValueByIndex(nAttr
);
66 if (XML_NAMESPACE_XML
== nPrefix
)
68 if (IsXMLToken(sLocalName
, XML_ID
))
74 else if (XML_NAMESPACE_TEXT
== nPrefix
)
76 if (IsXMLToken(sLocalName
, XML_ID
))
78 if (!bHaveXmlId
) { sID
= sValue
; }
80 else if( IsXMLToken( sLocalName
, XML_MERGE_LAST_PARAGRAPH
) )
83 if (::sax::Converter::convertBool(bTmp
, sValue
))
85 bMergeLastPara
= bTmp
;
92 SvXMLImportContextRef
XMLChangedRegionImportContext::CreateChildContext(
94 const OUString
& rLocalName
,
95 const Reference
<XAttributeList
> & /*xAttrList*/)
97 SvXMLImportContextRef xContext
;
99 if (XML_NAMESPACE_TEXT
== nPrefix
)
101 // from the ODF 1.2 standard :
102 // The <text:changed-region> element has the following child elements:
103 // <text:deletion>, <text:format-change> and <text:insertion>.
104 if ( IsXMLToken( rLocalName
, XML_INSERTION
) ||
105 IsXMLToken( rLocalName
, XML_DELETION
) ||
106 IsXMLToken( rLocalName
, XML_FORMAT_CHANGE
) )
108 // create XMLChangeElementImportContext for all kinds of changes
109 xContext
= new XMLChangeElementImportContext(
110 GetImport(), nPrefix
, rLocalName
,
111 IsXMLToken( rLocalName
, XML_DELETION
),
114 // else: it may be a text element, see below
119 // illegal element content! TODO: discard the redlines
120 // for the moment -> use text
121 // or default if text fail
127 void XMLChangedRegionImportContext::endFastElement(sal_Int32
)
129 // restore old XCursor (if necessary)
132 // delete last paragraph
133 // (one extra paragraph was inserted in the beginning)
134 rtl::Reference
<XMLTextImportHelper
> rHelper
=
135 GetImport().GetTextImport();
136 rHelper
->DeleteParagraph();
138 GetImport().GetTextImport()->SetCursor(xOldCursor
);
139 xOldCursor
= nullptr;
143 void XMLChangedRegionImportContext::SetChangeInfo(
144 const OUString
& rType
,
145 const OUString
& rAuthor
,
146 const OUString
& rComment
,
147 const OUString
& rDate
)
149 util::DateTime aDateTime
;
150 if (::sax::Converter::parseDateTime(aDateTime
, rDate
))
152 GetImport().GetTextImport()->RedlineAdd(
153 rType
, sID
, rAuthor
, rComment
, aDateTime
, bMergeLastPara
);
157 void XMLChangedRegionImportContext::UseRedlineText()
159 // if we haven't already installed the redline cursor, do it now
160 if ( xOldCursor
.is())
163 // get TextImportHelper and old Cursor
164 rtl::Reference
<XMLTextImportHelper
> rHelper(GetImport().GetTextImport());
165 Reference
<XTextCursor
> xCursor( rHelper
->GetCursor() );
167 // create Redline and new Cursor
168 Reference
<XTextCursor
> xNewCursor
=
169 rHelper
->RedlineCreateText(xCursor
, sID
);
173 // save old cursor and install new one
174 xOldCursor
= xCursor
;
175 rHelper
->SetCursor( xNewCursor
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */