KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > event > XHTMLIndenter


1 package net.sf.saxon.event;
2
3 import net.sf.saxon.om.NamePool;
4 import net.sf.saxon.om.NamespaceConstant;
5
6 import java.util.HashSet JavaDoc;
7
8
9 /**
10  * XHTMLIndenter: This class indents XHTML elements, by adding whitespace
11  * character data where appropriate. This class differs from its superclass,
12  * HTMLIndenter, only in the way it classifies elements as being inline or
13  * formatted elements: unlike the HTML indenter, it requires the element names
14  * to be in lower case and to be in the XHTML namespace.
15  *
16  * @author Michael Kay
17 */

18
19
20 public class XHTMLIndenter extends HTMLIndenter {
21
22     private HashSet JavaDoc inlineTagSet;
23     private HashSet JavaDoc formattedTagSet;
24
25
26     protected int classifyTag(int nameCode) {
27         if (inlineTagSet == null) {
28             NamePool pool = getNamePool();
29             inlineTagSet = new HashSet JavaDoc(40);
30             formattedTagSet = new HashSet JavaDoc(10);
31             for (int i=0; i<inlineTags.length; i++) {
32                 int nc = pool.allocate("", NamespaceConstant.XHTML, inlineTags[i]);
33                 inlineTagSet.add(new Integer JavaDoc(nc));
34             }
35             for (int i=0; i<formattedTags.length; i++) {
36                 int nc = pool.allocate("", NamespaceConstant.XHTML, formattedTags[i]);
37                 formattedTagSet.add(new Integer JavaDoc(nc));
38             }
39         }
40         int r = 0;
41         Integer JavaDoc key = new Integer JavaDoc(nameCode & NamePool.FP_MASK);
42         if (inlineTagSet.contains(key)) {
43             r |= IS_INLINE;
44         }
45         if (formattedTagSet.contains(key)) {
46             r |= IS_FORMATTED;
47         }
48         return r;
49     }
50
51
52     public XHTMLIndenter() {}
53
54
55 };
56
57 //
58
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
59
// you may not use this file except in compliance with the License. You may obtain a copy of the
60
// License at http://www.mozilla.org/MPL/
61
//
62
// Software distributed under the License is distributed on an "AS IS" basis,
63
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
64
// See the License for the specific language governing rights and limitations under the License.
65
//
66
// The Original Code is: all this file.
67
//
68
// The Initial Developer of the Original Code is Michael H. Kay.
69
//
70
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
71
//
72
// Contributor(s): none.
73
//
74

75
Popular Tags