View Javadoc
1   package eu.simuline.util.sgml;
2   
3   import org.xml.sax.ContentHandler;
4   import org.xml.sax.Locator;
5   import org.xml.sax.SAXException;
6   import org.xml.sax.Attributes;
7   
8   /**
9    * A ContentHandler wrapping another ContentHandler 
10   * which filters information 
11   * in a way that is useful/necessary for html-parsers: 
12   * turn tags into lower case. 
13   *
14   *
15   * Created: Mon Jul  4 19:42:05 2005
16   *
17   * @author <a href="mailto:ernst.reissner@simuline.eu">Ernst Reissner</a>
18   * @version 1.0
19   */
20  public final class SGMLFilter implements ContentHandler {
21  
22      /* --------------------------------------------------------------------- *
23       * attributes                                                            *
24       * --------------------------------------------------------------------- */
25  
26      private final ContentHandler handler;
27  
28      /* --------------------------------------------------------------------- *
29       * constructors                                                          *
30       * --------------------------------------------------------------------- */
31  
32      SGMLFilter(ContentHandler handler) {
33  	this.handler = handler;
34      }
35  
36      /* --------------------------------------------------------------------- *
37       * methods                                                               *
38       * --------------------------------------------------------------------- */
39  
40  
41      /** <!-- api-docs inherited from interface implemented.  -->*/ 
42      public void setDocumentLocator(Locator locator) {
43  	this.handler.setDocumentLocator(locator);
44      }
45  
46      public void startDocument() throws SAXException {
47  	this.handler.startDocument();
48      }
49  
50      public void endDocument() throws SAXException {
51  	this.handler.endDocument();
52      }
53  
54      public void startPrefixMapping(String prefix,
55  				   String uri)
56  	throws SAXException {
57  	this.handler.startPrefixMapping(prefix, uri);
58      }
59  
60      public void endPrefixMapping(String prefix)
61  	throws SAXException {
62  	this.handler.endPrefixMapping(prefix);
63      }
64  
65      private static String toLowerCase(String str) {
66  	if (str == null) {
67  	    return null;
68  	}
69  	return str.toLowerCase(); // NOPMD
70      }
71  
72      public void startElement(String namespaceURI,
73  			     String localName,
74  			     String qName,
75  			     Attributes atts)
76  	throws SAXException {
77  	this.handler.startElement(namespaceURI,
78  				  toLowerCase(localName),
79  				  toLowerCase(qName),
80  				  atts);
81  				  //((AttributesImpl) atts).toLowerCase());
82      }
83  
84      public void endElement(String namespaceURI,
85  			   String localName,
86  			   String qName)
87  	throws SAXException {
88  	this.handler.endElement(namespaceURI,
89  				toLowerCase(localName),
90  				toLowerCase(qName));
91      }
92  
93      public void characters(char[] chr,
94  			   int start,
95  			   int length)
96  	throws SAXException {
97  	this.handler.characters(chr, start, length);
98      }
99  
100     public void ignorableWhitespace(char[] chr,
101 				    int start,
102 				    int length)
103 	throws SAXException {
104 	this.handler.ignorableWhitespace(chr, start, length);
105     }
106 
107     public void processingInstruction(String target,
108 				      String data)
109 	throws SAXException {
110 	this.handler.processingInstruction(target, data);
111     }
112 
113     public void skippedEntity(String name)
114 	throws SAXException {
115 	this.handler.skippedEntity(name);
116     }
117 
118     public ContentHandler getWrapped() {
119 	return this.handler;
120     }
121 }