2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU General Public License Version 2 or later (the
22 * "GPL"), in which case the provisions of the GPL are applicable
23 * instead of those above. If you wish to allow use of your
24 * version of this file only under the terms of the GPL and not to
25 * allow others to use your version of this file under the MPL,
26 * indicate your decision by deleting the provisions above and
27 * replace them with the notice and other provisions required by
28 * the GPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under either the MPL or the
34 // Sablotron's interface to a SAX-like XML parser (currently expat)
44 #if defined (HAVE_EXPAT_H)
46 #elif defined (HAVE_XMLPARSE_H)
48 #elif defined (HAVE_XMLTOK_XMLPARSE_H)
49 #include <xmltok/xmlparse.h>
61 SAXHandlerStartNamespace2(void* userData, SablotHandle processor_,
62 const char* prefix, const char* uri, Bool hidden);
64 /* must be compatible with SAXHandler */
67 SAXHandlerStartDocument *startDocument;
68 SAXHandlerStartElement *startElement;
69 SAXHandlerEndElement *endElement;
70 SAXHandlerStartNamespace *startNamespace;
71 SAXHandlerEndNamespace *endNamespace;
72 SAXHandlerComment *comment;
73 SAXHandlerPI *processingInstruction;
74 SAXHandlerCharacters *characters;
75 SAXHandlerEndDocument *endDocument;
76 SAXHandlerStartNamespace2 *startNamespace2;
82 TreeConstructer(Sit S_);
84 eFlag parseDataLineUsingExpat(Sit S,
85 Tree *t, DataLine *d, char* base_ = NULL);
86 eFlag parseUsingSAX(Sit S, Tree *t, OutputterObj& source,
87 SAXOutputType ot = SAXOUTPUT_COPY_TREE);
89 eFlag parseUsingSAXForAWhile(Sit S, OutputterObj& source, Str &saxUri,
93 eFlag parseUsingSAXForAWhileDone(Sit S, OutputterObj& source,
94 Bool resetNamespaces);
97 static void tcStartDocument(
99 static void tcStartElement(
100 void *constructer, const char *elName, const char **atts);
101 static void tcEndElement(
102 void* constructer, const char* name);
103 static void tcStartNamespace(
104 void* userData, const char* prefix, const char* uri);
105 static void tcStartNamespace2(
106 void* userData, const char* prefix, const char* uri, Bool hidden);
107 static void tcEndNamespace(
108 void* constructer, const char* prefix);
109 static void tcComment(
110 void* constructer, const char* contents);
112 void* constructer, const char* target, const char* contents);
113 static void tcCharacters(
114 void* constructer, const char* contents, int length);
115 static void tcEndDocument(
117 // the unknown encoding handler is no more used:
118 // static int tcUnknownEncoding(
119 // void *encodingHandlerData, const char *name, XML_Encoding *info);
120 static int tcExternalEntityRef(
121 XML_Parser parser, const char* context, const char* base,
122 const char* systemId, const char* publicId);
123 static void tcEntityDecl(void *userData, const char *entityName,
124 int is_parameter_entity, const char *value,
125 int value_length, const char *base,
126 const char *systemId, const char *publicId,
127 const char *notationName);
128 //methods for sax handler (the processor is passed in)
129 static void saxStartDocument(
130 void* userData, SablotHandle processor_);
131 static void saxStartElement(
132 void *constructer, SablotHandle processor_,
133 const char *elName, const char **atts);
134 static void saxEndElement(
135 void* constructer, SablotHandle processor_, const char* name);
136 static void saxStartNamespace(
137 void* userData, SablotHandle processor_,
138 const char* prefix, const char* uri);
139 static void saxStartNamespace2(
140 void* userData, SablotHandle processor_,
141 const char* prefix, const char* uri, Bool hidden);
142 static void saxEndNamespace(
143 void* constructer, SablotHandle processor_, const char* prefix);
144 static void saxComment(
145 void* constructer, SablotHandle processor_, const char* contents);
147 void* constructer, SablotHandle processor_,
148 const char* target, const char* contents);
149 static void saxCharacters(
150 void* constructer, SablotHandle processor_,
151 const char* contents, int length);
152 static void saxEndDocument(
153 void* constructer, SablotHandle processor_);
156 eFlag parseDataLineUsingGivenExpat(Sit S, Tree *t, DataLine *d,
157 XML_Parser theParser_);
158 static eFlag setQNameFromExpat(Sit S, TreeConstructer* this_,
159 QName& qname_, const char* text);
160 static eFlag feedDocumentToParser(Sit S, void* constructer);
161 static eFlag getDocEncoding(Sit S, const char *buf, Str& theEncoding,
162 TreeConstructer *this_);
163 int getCurrentLineNumber() const;
164 XML_Parser theParser;
167 DataLine *theDataLine;
171 static SAXHandlerInternal myHandlerRecord; // initialized in parser.h
172 void report(Sit S, MsgType type, MsgCode code,
173 const Str& arg1, const Str& arg2) const;
174 List<Bool> preserveSpace;