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
33 #if !defined(OutputHIncl)
42 class DataLine; // see uri.h
58 // ESCAPING_CDATA, - use ESCAPING_NONE
67 //hard copy, no translations, no hidden ns....
69 //for physical output, hidden ns, aliasing
70 SAXOUTPUT_AS_PHYSICAL,
71 //as physical, but use expat like names
72 SAXOUTPUT_INT_PHYSICAL
75 #define THE_NAMESPACE_SEPARATOR '`'
77 // the following must match the size of outputStringAtts[] - 1
78 // as defined in output.cpp
79 #define STRING_ITEMS_COUNT 8
81 // constants for special values of precedence for xsl:output attributes
82 // use for OutputDefinition::setItemStr and setItemEQName
84 // specify only if not yet specified, otherwise no error
85 #define OUTPUT_PRECEDENCE_WEAKEST -1
87 #define OUTPUT_PRECEDENCE_STRONGEST -2
88 // for internal use only
89 #define OUTPUT_PRECEDENCE_UNSPECIFIED -3
93 // string with (import) precedence
94 // unspecified: precedence = -1
95 // to set, new precedence must be less than existing (unless existing == -1)
96 // special values of new precedence: override without checking (-1), set only if unspecified (-2)
105 precedence = OUTPUT_PRECEDENCE_UNSPECIFIED;
107 // sets the string if new precedence is stronger
108 // returns TRUE if new pref is non-negative and equal to old (does not set in this case)
109 Bool set(const Str& newString, int newPrecedence);
110 const Str& get() const
121 // same as StrPrec but holding EQName
130 precedence = OUTPUT_PRECEDENCE_UNSPECIFIED;
132 // sets the string if new precedence is stronger
133 // returns TRUE if new pref is non-negative and equal to old (does not set in this case)
134 Bool set(const EQName& newName, int newPrecedence);
135 const EQName& get() const
146 // stores the output-controlling information for an XSLT tree
149 #define OUTPUT_BUFFER_LIMIT 1024
150 #define OUTPUT_BUFFER_SIZE OUTPUT_BUFFER_LIMIT + 64
153 #define HTML_SPECIAL TRUE
154 #define NOT_HTML_SPECIAL FALSE
156 class OutputDefinition
161 // sets a string item
162 // itemId identifies the attribute code, 'value' is the new value
163 // 'caller' is the xsl:output element
164 // precedence is the current import precedence
165 // (may be OUTPUT_PRECEDENCE_STRONGEST to override, ..._WEAKEST to only set if unset) if !caller
167 Sit S, XSL_ATT itemId, const Str& value, Vertex *caller, int precedence);
168 // sets an EQName item (@method or @cdata-sect-elems)
170 Sit S, XSL_ATT itemId, const EQName& value, Vertex *caller, int precedence);
171 eFlag setDefaults(Sit S);
172 const Str& getValueStr(XSL_ATT itemId) const;
173 const EQName& getValueEQName(XSL_ATT itemId) const;
174 Bool askEQNameList(XSL_ATT itemId, const EQName &what) const;
175 int getStatus(XSL_ATT itemId) const;
176 OutputMethod getMethod() const;
177 Bool getIndent() const;
178 const Str& getEncoding() const;
180 StrPrec stringItems[STRING_ITEMS_COUNT];
185 DataLine *targetDataLine;
186 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
191 // PhysicalOutputterObj
195 class PhysicalOutputLayerObj
198 PhysicalOutputLayerObj(CDesc encodingCD_);
199 ~PhysicalOutputLayerObj();
200 eFlag setOptions(Sit S, DataLine *targetDataLine_, OutputDefinition *outDef_);
201 eFlag outputElementStart(Sit S, const Str& name,
202 const NamespaceStack& namespaces, const int namespace_index,
203 const StrStrList& atts, Bool isEmpty);
204 eFlag outputElementEnd(Sit S, const Str& name, Bool isEmpty);
205 eFlag outputText(Sit S, const Str& contents, Bool outputEscaping, Bool inHTMLSpecial);
206 eFlag outputComment(Sit S, const Str& contents);
207 eFlag outputCDataSection(Sit S, const Str& contents);
208 eFlag outputPI(Sit S, const Str& target, const Str& data);
209 eFlag outputDTD(Sit S, const Str& name, const Str& publicId, const Str& systemId);
210 eFlag outputTrailingNewline(Sit S);
211 eFlag outputDone(Sit S);
212 eFlag setMethodByDefault(Sit S, OutputMethod method_);
213 DataLine* getDataLine() { return targetDataLine; };
215 DataLine *targetDataLine;
216 OutputDefinition *outDef;
219 Bool after_markup; //pc
221 char buffer[OUTPUT_BUFFER_SIZE],
222 smallBuf[SMALL_BUFFER_SIZE];
227 eFlag sendOut(Sit S, const char* data, int length, EscMode escapeMode);
228 eFlag sendOutUntil(Sit S, const char* & data, int length,
229 EscMode escapeMode, const char* stoppingText);
230 int writeCharacterRef(char* dest, const char *src, EscMode escapeMode);
231 eFlag flushBuffer(Sit S);
232 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
241 //output document (for multiple document output)
252 OutputDocument(Str h, OutputDefinition *d) :
253 href (h), outputter(NULL), state(OUTDOC_NEW), def(d) {};
255 Str &getURI() { return uri; };
256 OutputterObj* setOutputter(OutputterObj* new_);
257 OutputterObj* getOutputter() { return outputter; };
258 OutputDefinition* getDefinition() { return def; };
259 OutdocState getState() { return state; };
260 void setState(OutdocState s) { state = s; };
262 Str &getHref() { return href; };
265 OutputterObj *outputter;
267 OutputDefinition *def;
271 //following structures are used for correct namespace exclusions
286 struct OutputHistoryItem
290 OutputDocument *document;
291 OutputDocument *useDocument;
294 typedef PList<OutputHistoryItem*> OutputHistory;
307 struct FrontMatterItem
309 FrontMatterKind kind;
310 Str string1, string2;
314 class FrontMatter : public PList<FrontMatterItem*>
317 eFlag appendConstruct(Sit S, FrontMatterKind kind, const Str& string1,
318 const Str& string2, Bool disableEsc);
319 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
328 eFlag setOptions(Sit S, DataLine *targetDataLine_, OutputDefinition *outDef_);
329 eFlag setOptionsSAX(Sit S, SAXHandler *streaming_, void *userData, SAXOutputType saxout_);
330 eFlag eventBeginOutput(Sit S);
331 //_PH_ used for subtree serialization, ends with eventEndOutput
332 eFlag eventBeginSubtree(Sit S);
333 eFlag eventElementStart(Sit S, const EQName& name);
334 eFlag eventElementEnd(Sit S, const EQName& name);
335 eFlag eventAttributeStart(Sit S, const EQName& name);
336 eFlag eventAttributeEnd(Sit S);
337 eFlag eventCommentStart(Sit S);
338 eFlag eventCommentEnd(Sit S);
339 //eFlag eventExcludeNS(Sit S, UriList &exNS);
340 eFlag eventNamespace(Sit S, const Str& prefix, const Str& uri,
341 Bool hidden = FALSE);
342 eFlag eventPIStart(Sit S, const Str& name);
343 eFlag eventPIEnd(Sit S);
344 eFlag eventData(Sit S, const Str& data, Bool hardCData = FALSE);
345 eFlag eventCDataSection(Sit S, const Str& data);
346 eFlag eventDisableEscapingForNext(Sit S);
347 eFlag eventEndOutput(Sit S);
348 eFlag eventTrailingNewline(Sit S);
349 eFlag setDocumentForLevel(Sit S, OutputDocument *doc);
350 OutputDocument* getDocumentForLevel(Bool forElement);
351 SAXOutputType getSAXOutputType() { return mySAXOutputType; };
352 PhysicalOutputLayerObj* getPhysical() { return physical; };
354 eFlag reportCurrData(Sit S, Bool hardCData = FALSE);
355 eFlag reportStartTag(Sit S, Bool isEmpty);
356 eFlag throwInMeta(Sit S);
357 Str* nameForSAX(Sit S, const EQName& q);
358 void pushLevel(const EQName& name);
362 return history.number() - 1; //ignore the '/' frame
366 return (history.number()? history.last() -> flags : 0);
370 return (history.number()? history.last() -> firstOwnNS : 0);
372 Bool nsExcluded(Sit S, Str & uri);
373 eFlag reportXMLDeclIfMust(Sit S);
374 eFlag reportDTDIfMust(Sit S, const EQName& docElementName);
375 eFlag reportFront(Sit S);
376 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
378 PhysicalOutputLayerObj *physical;
379 SAXHandler *mySAXHandler;
381 SAXOutputType mySAXOutputType;
382 OutputDefinition *outDef;
385 OutputterState state;
397 OutputHistory history;
405 #endif // OutputHIncl