KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cyberneko > html > filters > Identity


1 /*
2  * (C) Copyright 2002-2005, Andy Clark. All rights reserved.
3  *
4  * This file is distributed under an Apache style license. Please
5  * refer to the LICENSE file for specific details.
6  */

7
8 package org.cyberneko.html.filters;
9
10 import org.cyberneko.html.HTMLConfiguration;
11 import org.cyberneko.html.HTMLEventInfo;
12
13 import org.apache.xerces.xni.Augmentations;
14 import org.apache.xerces.xni.QName;
15 import org.apache.xerces.xni.XMLAttributes;
16 import org.apache.xerces.xni.XNIException;
17 import org.apache.xerces.xni.parser.XMLDocumentFilter;
18 import org.apache.xerces.xni.parser.XMLInputSource;
19 import org.apache.xerces.xni.parser.XMLParserConfiguration;
20
21 /**
22  * This filter performs the identity operation of the original
23  * document event stream generated by the HTML scanner by removing
24  * events that are synthesized by the tag balancer. This operation
25  * is essentially the same as turning off tag-balancing in the
26  * parser. However, this filter is useful when you want the tag
27  * balancer to report "errors" but do not want the synthesized
28  * events in the output.
29  * <p>
30  * <strong>Note:</strong>
31  * This filter requires the augmentations feature to be turned on.
32  * For example:
33  * <pre>
34  * XMLParserConfiguration parser = new HTMLConfiguration();
35  * parser.setFeature("http://cyberneko.org/html/features/augmentations", true);
36  * </pre>
37  * <p>
38  * <strong>Note:</strong>
39  * This isn't <em>exactly</em> the identify transform because the
40  * element and attributes names may have been modified from the
41  * original document. For example, by default, NekoHTML converts
42  * element names to upper-case and attribute names to lower-case.
43  *
44  * @author Andy Clark
45  *
46  * @version $Id: Identity.java,v 1.4 2005/02/14 03:56:54 andyc Exp $
47  */

48 public class Identity
49     extends DefaultFilter {
50
51     //
52
// Constants
53
//
54

55     /** Augmentations feature identifier. */
56     protected static final String JavaDoc AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations";
57
58     /** Filters property identifier. */
59     protected static final String JavaDoc FILTERS = "http://cyberneko.org/html/properties/filters";
60
61     //
62
// XMLDocumentHandler methods
63
//
64

65     /** Start element. */
66     public void startElement(QName element, XMLAttributes attributes,
67                              Augmentations augs) throws XNIException {
68         if (augs == null || !synthesized(augs)) {
69             super.startElement(element, attributes, augs);
70         }
71     } // startElement(QName,XMLAttributes,Augmentations)
72

73     /** Empty element. */
74     public void emptyElement(QName element, XMLAttributes attributes,
75                              Augmentations augs) throws XNIException {
76         if (augs == null || !synthesized(augs)) {
77             super.emptyElement(element, attributes, augs);
78         }
79     } // emptyElement(QName,XMLAttributes,Augmentations)
80

81     /** End element. */
82     public void endElement(QName element, Augmentations augs)
83         throws XNIException {
84         if (augs == null || !synthesized(augs)) {
85             super.endElement(element, augs);
86         }
87     } // endElement(QName,XMLAttributes,Augmentations)
88

89     //
90
// Protected static methods
91
//
92

93     /** Returns true if the information provided is synthesized. */
94     protected static boolean synthesized(Augmentations augs) {
95         HTMLEventInfo info = (HTMLEventInfo)augs.getItem(AUGMENTATIONS);
96         return info != null ? info.isSynthesized() : false;
97     } // synthesized(Augmentations):boolean
98

99 } // class Identity
100
Popular Tags