01: package net.sf.saxon.event;
02:
03: import net.sf.saxon.om.NamePool;
04: import net.sf.saxon.om.NamespaceConstant;
05: import net.sf.saxon.sort.IntHashSet;
06: import net.sf.saxon.trans.XPathException;
07:
08: /**
09: * XHTMLEmitter is an Emitter that generates XHTML output.
10: * It is the same as XMLEmitter except that it follows the legacy HTML browser
11: * compatibility rules: for example, generating empty elements such as [BR /], and
12: * using [p][/p] for empty paragraphs rather than [p/]
13: */
14:
15: public class XHTMLEmitter extends XMLEmitter {
16:
17: /**
18: * Table of XHTML tags that have no closing tag
19: */
20:
21: IntHashSet emptyTags = new IntHashSet(31);
22:
23: private static String[] emptyTagNames = { "area", "base",
24: "basefont", "br", "col", "frame", "hr", "img", "input",
25: "isindex", "link", "meta", "param" };
26:
27: /**
28: * Do the real work of starting the document. This happens when the first
29: * content is written.
30: *
31: * @throws net.sf.saxon.trans.XPathException
32: *
33: */
34:
35: protected void openDocument() throws XPathException {
36: NamePool pool = getPipelineConfiguration().getConfiguration()
37: .getNamePool();
38: for (int i = 0; i < emptyTagNames.length; i++) {
39: emptyTags.add(pool.allocate("", NamespaceConstant.XHTML,
40: emptyTagNames[i])
41: & NamePool.FP_MASK);
42: }
43: super .openDocument();
44: }
45:
46: /**
47: * Close an empty element tag.
48: */
49:
50: protected String emptyElementTagCloser(String displayName,
51: int nameCode) {
52: if (emptyTags.contains(nameCode & NamePool.FP_MASK)) {
53: return " />";
54: } else {
55: return "></" + displayName + '>';
56: }
57: }
58:
59: }
60:
61: //
62: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
63: // you may not use this file except in compliance with the License. You may obtain a copy of the
64: // License at http://www.mozilla.org/MPL/
65: //
66: // Software distributed under the License is distributed on an "AS IS" basis,
67: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
68: // See the License for the specific language governing rights and limitations under the License.
69: //
70: // The Original Code is: all this file.
71: //
72: // The Initial Developer of the Original Code is Michael H. Kay.
73: //
74: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
75: //
76: // Contributor(s): none.
77: //
|