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 #ifndef _XMLOFF_TRANSFORMERCONTEXT_HXX
29 #define _XMLOFF_TRANSFORMERCONTEXT_HXX
30 
31 #include <com/sun/star/xml/sax/XAttributeList.hpp>
32 #include <tools/solar.h>
33 #include <salhelper/simplereferenceobject.hxx>
34 #include <rtl/ustring.hxx>
35 #include <tools/rtti.hxx>
36 #include <xmloff/xmltoken.hxx>
37 
38 class SvXMLNamespaceMap;
39 class XMLTransformerBase;
40 
41 class XMLTransformerContext : public ::salhelper::SimpleReferenceObject
42 {
43 	friend class XMLTransformerBase;
44 
45 	XMLTransformerBase& m_rTransformer;
46 
47 	::rtl::OUString m_aQName;
48 
49 	SvXMLNamespaceMap	*m_pRewindMap;
50 
51 	SvXMLNamespaceMap  *GetRewindMap() const { return m_pRewindMap; }
52 	void SetRewindMap( SvXMLNamespaceMap *p ) { m_pRewindMap = p; }
53 
54 protected:
55 
56 	XMLTransformerBase& GetTransformer() { return m_rTransformer; }
57 	const XMLTransformerBase& GetTransformer() const { return m_rTransformer; }
58 
59 	void SetQName( const ::rtl::OUString& rQName ) { m_aQName = rQName; }
60 
61 public:
62 	TYPEINFO();
63 
64 	const ::rtl::OUString& GetQName() const { return m_aQName; }
65 	sal_Bool HasQName( sal_uInt16 nPrefix,
66 					   ::xmloff::token::XMLTokenEnum eToken ) const;
67 	sal_Bool HasNamespace( sal_uInt16 nPrefix ) const;
68 
69 	// A contexts constructor does anything that is required if an element
70 	// starts. Namespace processing has been done already.
71 	// Note that virtual methods cannot be used inside constructors. Use
72 	// StartElement instead if this is required.
73 	XMLTransformerContext( XMLTransformerBase& rTransformer,
74 						const ::rtl::OUString& rQName );
75 
76 	// A contexts destructor does anything that is required if an element
77 	// ends. By default, nothing is done.
78 	// Note that virtual methods cannot be used inside destructors. Use
79 	// EndElement instead if this is required.
80 	virtual ~XMLTransformerContext();
81 
82 	// Create a childs element context. By default, the import's
83 	// CreateContext method is called to create a new default context.
84 	virtual XMLTransformerContext *CreateChildContext( sal_uInt16 nPrefix,
85 								   const ::rtl::OUString& rLocalName,
86 								   const ::rtl::OUString& rQName,
87 								   const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
88 
89 	// StartElement is called after a context has been constructed and
90 	// before a elements context is parsed. It may be used for actions that
91 	// require virtual methods. The default is to do nothing.
92 	virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
93 
94 	// EndElement is called before a context will be destructed, but
95 	// after a elements context has been parsed. It may be used for actions
96 	// that require virtual methods. The default is to do nothing.
97 	virtual void EndElement();
98 
99 	// This method is called for all characters that are contained in the
100 	// current element. The default is to ignore them.
101 	virtual void Characters( const ::rtl::OUString& rChars );
102 
103 	// Is the current context a persistent one (i.e. one that saves is content
104 	// rather than exporting it directly?
105 	virtual sal_Bool IsPersistent() const;
106 
107 	// Export the whole element. By default, nothing is done here
108 	virtual void Export();
109 
110 	// Export the element content. By default, nothing is done here
111 	virtual void ExportContent();
112 };
113 
114 
115 #endif	//  _XMLOFF_TRANSFORMERCONTEXT_HXX
116 
117