1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLChangeImportContext.hxx"
27 #include <com/sun/star/text/XTextRange.hpp>
28 #include <tools/debug.hxx>
29 #include <xmloff/xmlimp.hxx>
30 #include "xmloff/xmlnmspe.hxx"
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 
34 using ::rtl::OUString;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::text::XTextRange;
37 using ::com::sun::star::xml::sax::XAttributeList;
38 using ::xmloff::token::IsXMLToken;
39 using ::xmloff::token::XML_CHANGE_ID;
40 
41 TYPEINIT1( XMLChangeImportContext, SvXMLImportContext );
42 
XMLChangeImportContext(SvXMLImport & rImport,sal_Int16 nPrefix,const OUString & rLocalName,sal_Bool bStart,sal_Bool bEnd,sal_Bool bOutsideOfParagraph)43 XMLChangeImportContext::XMLChangeImportContext(
44 	SvXMLImport& rImport,
45 	sal_Int16 nPrefix,
46 	const OUString& rLocalName,
47 	sal_Bool bStart,
48 	sal_Bool bEnd,
49 	sal_Bool bOutsideOfParagraph) :
50 		SvXMLImportContext(rImport, nPrefix, rLocalName),
51 		bIsStart(bStart),
52 		bIsEnd(bEnd),
53 		bIsOutsideOfParagraph(bOutsideOfParagraph)
54 {
55 	DBG_ASSERT(bStart || bEnd, "Must be either start, end, or both!");
56 }
57 
~XMLChangeImportContext()58 XMLChangeImportContext::~XMLChangeImportContext()
59 {
60 }
61 
StartElement(const Reference<XAttributeList> & xAttrList)62 void XMLChangeImportContext::StartElement(
63 	const Reference<XAttributeList>& xAttrList)
64 {
65 	sal_Int16 nLength = xAttrList->getLength();
66 	for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
67 	{
68 		OUString sLocalName;
69 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
70 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
71 							  &sLocalName );
72 		if ( (XML_NAMESPACE_TEXT == nPrefix) &&
73              IsXMLToken( sLocalName, XML_CHANGE_ID ) )
74 		{
75 			// Id found! Now call RedlineImportHelper
76 
77 			// prepare parameters
78 			UniReference<XMLTextImportHelper> rHelper =
79 				GetImport().GetTextImport();
80 			OUString sID = xAttrList->getValueByIndex(nAttr);
81 
82 			// call for bStart and bEnd (may both be true)
83 			if (bIsStart)
84 				rHelper->RedlineSetCursor(sID,sal_True,bIsOutsideOfParagraph);
85 			if (bIsEnd)
86 				rHelper->RedlineSetCursor(sID,sal_False,bIsOutsideOfParagraph);
87 
88 			// outside of paragraph and still open? set open redline ID
89 			if (bIsOutsideOfParagraph)
90             {
91                 rHelper->SetOpenRedlineId(sID);
92 			}
93 		}
94 		// else: ignore
95 	}
96 }
97