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 "XMLChangeElementImportContext.hxx"
31 #include "XMLChangedRegionImportContext.hxx"
32 #include "XMLChangeInfoContext.hxx"
33 #include <com/sun/star/uno/Reference.h>
34 #include <xmloff/xmlimp.hxx>
35 #include "xmloff/xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 
38 
39 
40 using ::rtl::OUString;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::xml::sax::XAttributeList;
43 using ::xmloff::token::IsXMLToken;
44 using ::xmloff::token::XML_P;
45 using ::xmloff::token::XML_CHANGE_INFO;
46 
47 TYPEINIT1( XMLChangeElementImportContext, SvXMLImportContext );
48 
49 XMLChangeElementImportContext::XMLChangeElementImportContext(
50 	SvXMLImport& rImport,
51 	sal_uInt16 nPrefix,
52 	const OUString& rLocalName,
53 	sal_Bool bAccContent,
54 	XMLChangedRegionImportContext& rParent) :
55 		SvXMLImportContext(rImport, nPrefix, rLocalName),
56 		bAcceptContent(bAccContent),
57 		rChangedRegion(rParent)
58 {
59 }
60 
61 SvXMLImportContext* XMLChangeElementImportContext::CreateChildContext(
62 	sal_uInt16 nPrefix,
63 	const OUString& rLocalName,
64 	const Reference<XAttributeList> & xAttrList)
65 {
66 	SvXMLImportContext* pContext = NULL;
67 
68 	if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
69          IsXMLToken( rLocalName, XML_CHANGE_INFO) )
70 	{
71 		pContext = new XMLChangeInfoContext(GetImport(), nPrefix, rLocalName,
72 											rChangedRegion, GetLocalName());
73 	}
74 	else
75 	{
76         // import into redline -> create XText
77         rChangedRegion.UseRedlineText();
78 
79 		pContext = GetImport().GetTextImport()->CreateTextChildContext(
80 			GetImport(), nPrefix, rLocalName, xAttrList,
81 			XML_TEXT_TYPE_CHANGED_REGION);
82 
83         if (NULL == pContext)
84         {
85             // no text element -> use default
86             pContext = SvXMLImportContext::CreateChildContext(
87                 nPrefix, rLocalName, xAttrList);
88 
89             // illegal element content! TODO: discard this redline!
90         }
91 	}
92 
93 
94 	return pContext;
95 }
96 
97 // #107848#
98 void XMLChangeElementImportContext::StartElement( const Reference< XAttributeList >& )
99 {
100 	if(bAcceptContent)
101 	{
102 		GetImport().GetTextImport()->SetInsideDeleteContext(sal_True);
103 	}
104 }
105 
106 // #107848#
107 void XMLChangeElementImportContext::EndElement()
108 {
109 	if(bAcceptContent)
110 	{
111 		GetImport().GetTextImport()->SetInsideDeleteContext(sal_False);
112 	}
113 }
114