merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / text / XMLChangedRegionImportContext.cxx
blob5a0cf0bec47c303d0991d55efb0e461a093e1ea0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLChangedRegionImportContext.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLChangedRegionImportContext.hxx"
34 #include "XMLChangeElementImportContext.hxx"
35 #include <com/sun/star/uno/Reference.h>
36 #include <com/sun/star/util/DateTime.hpp>
37 #include <com/sun/star/text/XTextCursor.hpp>
38 #include <xmloff/xmlimp.hxx>
39 #include "xmlnmspe.hxx"
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/xmltoken.hxx>
42 #include <xmloff/xmluconv.hxx>
45 using namespace ::xmloff::token;
47 using ::rtl::OUString;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::text::XTextCursor;
50 using ::com::sun::star::util::DateTime;
51 using ::com::sun::star::xml::sax::XAttributeList;
55 TYPEINIT1(XMLChangedRegionImportContext, SvXMLImportContext);
57 XMLChangedRegionImportContext::XMLChangedRegionImportContext(
58 SvXMLImport& rImport,
59 sal_uInt16 nPrefix,
60 const OUString& rLocalName) :
61 SvXMLImportContext(rImport, nPrefix, rLocalName),
62 bMergeLastPara(sal_True)
66 XMLChangedRegionImportContext::~XMLChangedRegionImportContext()
70 void XMLChangedRegionImportContext::StartElement(
71 const Reference<XAttributeList> & xAttrList)
73 // process attributes: id
74 sal_Int16 nLength = xAttrList->getLength();
75 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
77 OUString sLocalName;
78 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
79 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
80 &sLocalName );
82 const OUString sValue = xAttrList->getValueByIndex(nAttr);
83 if ( XML_NAMESPACE_TEXT == nPrefix )
85 if( IsXMLToken( sLocalName, XML_ID ) )
87 sID = sValue;
89 else if( IsXMLToken( sLocalName, XML_MERGE_LAST_PARAGRAPH ) )
91 sal_Bool bTmp;
92 if( SvXMLUnitConverter::convertBool(bTmp, sValue) )
94 bMergeLastPara = bTmp;
101 SvXMLImportContext* XMLChangedRegionImportContext::CreateChildContext(
102 sal_uInt16 nPrefix,
103 const OUString& rLocalName,
104 const Reference<XAttributeList> & xAttrList)
106 SvXMLImportContext* pContext = NULL;
108 if (XML_NAMESPACE_TEXT == nPrefix)
110 if ( IsXMLToken( rLocalName, XML_INSERTION ) ||
111 IsXMLToken( rLocalName, XML_DELETION ) ||
112 IsXMLToken( rLocalName, XML_FORMAT_CHANGE ) )
114 // create XMLChangeElementImportContext for all kinds of changes
115 pContext = new XMLChangeElementImportContext(
116 GetImport(), nPrefix, rLocalName,
117 IsXMLToken( rLocalName, XML_DELETION ),
118 *this);
120 // else: it may be a text element, see below
123 if (NULL == pContext)
125 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
126 xAttrList);
128 // was it a text element? If not, use default!
129 if (NULL == pContext)
131 pContext = SvXMLImportContext::CreateChildContext(
132 nPrefix, rLocalName, xAttrList);
136 return pContext;
139 void XMLChangedRegionImportContext::EndElement()
141 // restore old XCursor (if necessary)
142 if (xOldCursor.is())
144 // delete last paragraph
145 // (one extra paragraph was inserted in the beginning)
146 UniReference<XMLTextImportHelper> rHelper =
147 GetImport().GetTextImport();
148 rHelper->DeleteParagraph();
150 GetImport().GetTextImport()->SetCursor(xOldCursor);
151 xOldCursor = NULL;
155 void XMLChangedRegionImportContext::SetChangeInfo(
156 const OUString& rType,
157 const OUString& rAuthor,
158 const OUString& rComment,
159 const OUString& rDate)
161 DateTime aDateTime;
162 if (SvXMLUnitConverter::convertDateTime(aDateTime, rDate))
164 GetImport().GetTextImport()->RedlineAdd(
165 rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara);
169 void XMLChangedRegionImportContext::UseRedlineText()
171 // if we haven't already installed the redline cursor, do it now
172 if (! xOldCursor.is())
174 // get TextImportHelper and old Cursor
175 UniReference<XMLTextImportHelper> rHelper(GetImport().GetTextImport());
176 Reference<XTextCursor> xCursor( rHelper->GetCursor() );
178 // create Redline and new Cursor
179 Reference<XTextCursor> xNewCursor =
180 rHelper->RedlineCreateText(xCursor, sID);
182 if (xNewCursor.is())
184 // save old cursor and install new one
185 xOldCursor = xCursor;
186 rHelper->SetCursor( xNewCursor );
188 // else: leave as is