1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLChangeImportContext.hxx"
31 #include <com/sun/star/text/XTextRange.hpp>
32 #include <tools/debug.hxx>
33 #include <xmloff/xmlimp.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/nmspmap.hxx>
36 #include <xmloff/xmltoken.hxx>
37 
38 using ::rtl::OUString;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::text::XTextRange;
41 using ::com::sun::star::xml::sax::XAttributeList;
42 using ::xmloff::token::IsXMLToken;
43 using ::xmloff::token::XML_CHANGE_ID;
44 
45 TYPEINIT1( XMLChangeImportContext, SvXMLImportContext );
46 
47 XMLChangeImportContext::XMLChangeImportContext(
48 	SvXMLImport& rImport,
49 	sal_Int16 nPrefix,
50 	const OUString& rLocalName,
51 	sal_Bool bStart,
52 	sal_Bool bEnd,
53 	sal_Bool bOutsideOfParagraph) :
54 		SvXMLImportContext(rImport, nPrefix, rLocalName),
55 		bIsStart(bStart),
56 		bIsEnd(bEnd),
57 		bIsOutsideOfParagraph(bOutsideOfParagraph)
58 {
59 	DBG_ASSERT(bStart || bEnd, "Must be either start, end, or both!");
60 }
61 
62 XMLChangeImportContext::~XMLChangeImportContext()
63 {
64 }
65 
66 void XMLChangeImportContext::StartElement(
67 	const Reference<XAttributeList>& xAttrList)
68 {
69 	sal_Int16 nLength = xAttrList->getLength();
70 	for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
71 	{
72 		OUString sLocalName;
73 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
74 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
75 							  &sLocalName );
76 		if ( (XML_NAMESPACE_TEXT == nPrefix) &&
77              IsXMLToken( sLocalName, XML_CHANGE_ID ) )
78 		{
79 			// Id found! Now call RedlineImportHelper
80 
81 			// prepare parameters
82 			UniReference<XMLTextImportHelper> rHelper =
83 				GetImport().GetTextImport();
84 			OUString sID = xAttrList->getValueByIndex(nAttr);
85 
86 			// call for bStart and bEnd (may both be true)
87 			if (bIsStart)
88 				rHelper->RedlineSetCursor(sID,sal_True,bIsOutsideOfParagraph);
89 			if (bIsEnd)
90 				rHelper->RedlineSetCursor(sID,sal_False,bIsOutsideOfParagraph);
91 
92 			// outside of paragraph and still open? set open redline ID
93 			if (bIsOutsideOfParagraph)
94             {
95                 rHelper->SetOpenRedlineId(sID);
96 			}
97 		}
98 		// else: ignore
99 	}
100 }
101