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_TOKENCONTEXT_HXX
29 #define _XMLOFF_TOKENCONTEXT_HXX
30 
31 
32 //
33 // include for parent class and members
34 //
35 
36 #include <xmloff/xmlictxt.hxx>
37 
38 
39 //
40 // forward declarations
41 //
42 
43 namespace com { namespace sun { namespace star {
44     namespace xml { namespace sax { class XAttributeList; } }
45     namespace uno { template<typename T> class Reference; }
46 } } }
47 namespace rtl { class OUString; }
48 class SvXMLImport;
49 
50 #define TOKEN_MAP_ENTRY(NAMESPACE,TOKEN) { XML_NAMESPACE_##NAMESPACE, xmloff::token::XML_##TOKEN, xmloff::token::XML_##TOKEN }
51 
52 extern struct SvXMLTokenMapEntry aEmptyMap[1];
53 
54 /** handle attributes through an SvXMLTokenMap */
55 class TokenContext : public SvXMLImportContext
56 {
57 protected:
58     const SvXMLTokenMapEntry* mpAttributes;    /// static token map
59     const SvXMLTokenMapEntry* mpChildren;      /// static token map
60 
61 public:
62 
63     TokenContext( SvXMLImport& rImport,
64                   sal_uInt16 nPrefix,
65                   const ::rtl::OUString& rLocalName,
66                   const SvXMLTokenMapEntry* pAttributes = NULL,
67                   const SvXMLTokenMapEntry* pChildren = NULL );
68 
69     virtual ~TokenContext();
70 
71 
72     //
73     // implement SvXMLImportContext methods:
74     //
75 
76     /** call HandleAttribute for each attribute in the token map;
77      * create a warning for all others. Classes that wish to override
78      * StartElement need to call the parent method. */
79 	virtual void StartElement(
80         const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList );
81 
82     /** call HandleChild for each child element in the token map;
83      * create a warning for all others. Classes that wish to override
84      * CreateChildCotnenxt may want to call the parent method for
85      * handling of defaults. */
86 	virtual SvXMLImportContext* CreateChildContext(
87         sal_uInt16 nPrefix,
88         const rtl::OUString& rLocalName,
89         const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList );
90 
91     /** Create a warning for all non-namespace character
92      * content. Classes that wish to deal with character content have
93      * to overload this method anyway, and will thus get rid of the
94      * warnings. */
95 	virtual void Characters( const ::rtl::OUString& rChars );
96 
97 protected:
98     /** will be called for each attribute */
99     virtual void HandleAttribute(
100         sal_uInt16 nToken,
101         const rtl::OUString& rValue ) = 0;
102 
103     /** will be called for each child element */
104     virtual SvXMLImportContext* HandleChild(
105         sal_uInt16 nToken,
106 
107         // the following attributes are mainly to be used for child
108         // context creation
109         sal_uInt16 nPrefix,
110         const rtl::OUString& rLocalName,
111         const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList ) = 0;
112 };
113 
114 #endif
115