1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_TOKENCONTEXT_HXX
25 #define _XMLOFF_TOKENCONTEXT_HXX
26 
27 
28 //
29 // include for parent class and members
30 //
31 
32 #include <xmloff/xmlictxt.hxx>
33 
34 
35 //
36 // forward declarations
37 //
38 
39 namespace com { namespace sun { namespace star {
40     namespace xml { namespace sax { class XAttributeList; } }
41     namespace uno { template<typename T> class Reference; }
42 } } }
43 namespace rtl { class OUString; }
44 class SvXMLImport;
45 
46 #define TOKEN_MAP_ENTRY(NAMESPACE,TOKEN) { XML_NAMESPACE_##NAMESPACE, xmloff::token::XML_##TOKEN, xmloff::token::XML_##TOKEN }
47 
48 extern struct SvXMLTokenMapEntry aEmptyMap[1];
49 
50 /** handle attributes through an SvXMLTokenMap */
51 class TokenContext : public SvXMLImportContext
52 {
53 protected:
54     const SvXMLTokenMapEntry* mpAttributes;    /// static token map
55     const SvXMLTokenMapEntry* mpChildren;      /// static token map
56 
57 public:
58 
59     TokenContext( SvXMLImport& rImport,
60                   sal_uInt16 nPrefix,
61                   const ::rtl::OUString& rLocalName,
62                   const SvXMLTokenMapEntry* pAttributes = NULL,
63                   const SvXMLTokenMapEntry* pChildren = NULL );
64 
65     virtual ~TokenContext();
66 
67 
68     //
69     // implement SvXMLImportContext methods:
70     //
71 
72     /** call HandleAttribute for each attribute in the token map;
73      * create a warning for all others. Classes that wish to override
74      * StartElement need to call the parent method. */
75 	virtual void StartElement(
76         const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList );
77 
78     /** call HandleChild for each child element in the token map;
79      * create a warning for all others. Classes that wish to override
80      * CreateChildCotnenxt may want to call the parent method for
81      * handling of defaults. */
82 	virtual SvXMLImportContext* CreateChildContext(
83         sal_uInt16 nPrefix,
84         const rtl::OUString& rLocalName,
85         const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList );
86 
87     /** Create a warning for all non-namespace character
88      * content. Classes that wish to deal with character content have
89      * to overload this method anyway, and will thus get rid of the
90      * warnings. */
91 	virtual void Characters( const ::rtl::OUString& rChars );
92 
93 protected:
94     /** will be called for each attribute */
95     virtual void HandleAttribute(
96         sal_uInt16 nToken,
97         const rtl::OUString& rValue ) = 0;
98 
99     /** will be called for each child element */
100     virtual SvXMLImportContext* HandleChild(
101         sal_uInt16 nToken,
102 
103         // the following attributes are mainly to be used for child
104         // context creation
105         sal_uInt16 nPrefix,
106         const rtl::OUString& rLocalName,
107         const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList ) = 0;
108 };
109 
110 #endif
111