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 
31 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
32 #include "TransformerBase.hxx"
33 #endif
34 #include "PersMixedContentTContext.hxx"
35 
36 using ::rtl::OUString;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::xml::sax;
39 
40 //------------------------------------------------------------------------------
41 class XMLPersTextTContext_Impl : public XMLTransformerContext
42 {
43 	::rtl::OUString m_aCharacters;
44 
45 public:
46 	TYPEINFO();
47 
48 	XMLPersTextTContext_Impl( XMLTransformerBase& rTransformer,
49 						   const ::rtl::OUString& rChars );
50 	virtual ~XMLPersTextTContext_Impl();
51 
52 	virtual XMLTransformerContext *CreateChildContext( sal_uInt16 nPrefix,
53 								   const ::rtl::OUString& rLocalName,
54 								   const ::rtl::OUString& rQName,
55 								   const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
56 	virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
57 	virtual void EndElement();
58 	virtual void Characters( const ::rtl::OUString& rChars );
59 
60 	virtual sal_Bool IsPersistent() const;
61 	virtual void Export();
62 	const ::rtl::OUString& GetText() const { return m_aCharacters; }
63 };
64 
65 TYPEINIT1( XMLPersTextTContext_Impl, XMLTransformerContext );
66 
67 XMLPersTextTContext_Impl::XMLPersTextTContext_Impl(
68 		XMLTransformerBase& rImp,
69 		const OUString& rChars ) :
70 	XMLTransformerContext( rImp, OUString() ),
71 	m_aCharacters( rChars )
72 {
73 }
74 
75 XMLPersTextTContext_Impl::~XMLPersTextTContext_Impl()
76 {
77 }
78 
79 XMLTransformerContext *XMLPersTextTContext_Impl::CreateChildContext(
80 		sal_uInt16,
81 		const OUString&,
82 		const OUString&,
83 		const Reference< XAttributeList >& )
84 {
85 	OSL_ENSURE( !this, "illegal call to CreateChildContext" );
86 	return 0;
87 }
88 
89 void XMLPersTextTContext_Impl::StartElement(
90 	const Reference< XAttributeList >& )
91 {
92 	OSL_ENSURE( !this, "illegal call to StartElement" );
93 }
94 
95 void XMLPersTextTContext_Impl::EndElement()
96 {
97 	OSL_ENSURE( !this, "illegal call to EndElement" );
98 }
99 
100 sal_Bool XMLPersTextTContext_Impl::IsPersistent() const
101 {
102 	return sal_True;
103 }
104 
105 void XMLPersTextTContext_Impl::Characters( const OUString& rChars )
106 {
107 	m_aCharacters += rChars;
108 }
109 
110 void XMLPersTextTContext_Impl::Export()
111 {
112 	GetTransformer().GetDocHandler()->characters( m_aCharacters );
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 TYPEINIT1( XMLPersMixedContentTContext, XMLPersElemContentTContext );
118 
119 XMLPersMixedContentTContext::XMLPersMixedContentTContext(
120 		XMLTransformerBase& rImp,
121 		const OUString& rQName ) :
122 	XMLPersElemContentTContext( rImp, rQName )
123 {
124 }
125 
126 XMLPersMixedContentTContext::XMLPersMixedContentTContext(
127 		XMLTransformerBase& rImp,
128 		const OUString& rQName,
129 	   sal_uInt16 nActionMap ) :
130 	XMLPersElemContentTContext( rImp, rQName, nActionMap )
131 {
132 }
133 
134 XMLPersMixedContentTContext::XMLPersMixedContentTContext(
135 		XMLTransformerBase& rImp,
136 		const OUString& rQName,
137 	    sal_uInt16 nPrefix,
138 		::xmloff::token::XMLTokenEnum eToken ) :
139 	XMLPersElemContentTContext( rImp, rQName, nPrefix, eToken )
140 {
141 }
142 
143 XMLPersMixedContentTContext::XMLPersMixedContentTContext(
144 		XMLTransformerBase& rImp,
145 		const OUString& rQName,
146 	    sal_uInt16 nPrefix,
147 		::xmloff::token::XMLTokenEnum eToken,
148 	   sal_uInt16 nActionMap ) :
149 	XMLPersElemContentTContext( rImp, rQName, nPrefix, eToken, nActionMap )
150 {
151 }
152 
153 XMLPersMixedContentTContext::~XMLPersMixedContentTContext()
154 {
155 }
156 
157 void XMLPersMixedContentTContext::Characters( const OUString& rChars )
158 {
159 	AddContent( new XMLPersTextTContext_Impl( GetTransformer(), rChars ) );
160 }
161