KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nbbuild > misc > bugcompare > ChangelogRecognizer


1 package nbbuild.misc.bugcompare;
2
3 /*
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  */

21
22 public class ChangelogRecognizer_1 implements org.xml.sax.DocumentHandler JavaDoc {
23     private java.lang.StringBuffer JavaDoc buffer;
24
25     private ChangelogParslet parslet;
26
27     private ChangelogHandler handler;
28
29     private java.util.Stack JavaDoc context;
30
31     public ChangelogRecognizer_1(final ChangelogHandler handler, final ChangelogParslet parslet) {
32         this.parslet = parslet;
33         this.handler = handler;
34         buffer = new StringBuffer JavaDoc(111);
35         context = new java.util.Stack JavaDoc();
36     }
37
38     public void setDocumentLocator(org.xml.sax.Locator JavaDoc locator) {
39     }
40     
41     public void startDocument() throws org.xml.sax.SAXException JavaDoc {
42     }
43     
44     public void endDocument() throws org.xml.sax.SAXException JavaDoc {
45     }
46     
47     public void startElement(java.lang.String JavaDoc name, org.xml.sax.AttributeList JavaDoc attrs) throws org.xml.sax.SAXException JavaDoc {
48         dispatch(true);
49         context.push(new Object JavaDoc[] {name, new org.xml.sax.helpers.AttributeListImpl JavaDoc(attrs)});
50     }
51     
52     public void endElement(java.lang.String JavaDoc name) throws org.xml.sax.SAXException JavaDoc {
53         dispatch(false);
54         context.pop();
55     }
56     
57     public void characters(char[] chars, int start, int len) throws org.xml.sax.SAXException JavaDoc {
58         buffer.append(chars, start, len);
59     }
60     
61     public void ignorableWhitespace(char[] chars, int start, int len) throws org.xml.sax.SAXException JavaDoc {
62     }
63     
64     public void processingInstruction(java.lang.String JavaDoc target, java.lang.String JavaDoc data) throws org.xml.sax.SAXException JavaDoc {
65     }
66     
67     private void dispatch(final boolean fireOnlyIfMixed) throws org.xml.sax.SAXException JavaDoc {
68         if (fireOnlyIfMixed && buffer.length() == 0) return; //skip it
69

70         Object JavaDoc[] ctx = (Object JavaDoc[]) context.peek();
71         String JavaDoc here = (String JavaDoc) ctx[0];
72         org.xml.sax.AttributeList JavaDoc attrs = (org.xml.sax.AttributeList JavaDoc) ctx[1];
73         if ("author".equals(here)) {
74             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
75             handler.handle_author(buffer.length() == 0 ? null : buffer.toString(), attrs);
76         } else if ("branch".equals(here)) {
77             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
78             handler.handle_branch(buffer.length() == 0 ? null : buffer.toString(), attrs);
79         } else if ("branchroot".equals(here)) {
80             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
81             handler.handle_branchroot(buffer.length() == 0 ? null : buffer.toString(), attrs);
82         } else if ("changelog".equals(here)) {
83             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
84             handler.handle_changelog(buffer.length() == 0 ? null : buffer.toString(), attrs);
85         } else if ("commondir".equals(here)) {
86             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
87             handler.handle_commondir(buffer.length() == 0 ? null : buffer.toString(), attrs);
88         } else if ("date".equals(here)) {
89             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
90             handler.handle_date(buffer.length() == 0 ? null : buffer.toString(), attrs);
91         } else if ("entry".equals(here)) {
92             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
93             handler.handle_entry(buffer.length() == 0 ? null : buffer.toString(), attrs);
94         } else if ("file".equals(here)) {
95             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
96             handler.handle_file(buffer.length() == 0 ? null : buffer.toString(), attrs);
97         } else if ("msg".equals(here)) {
98             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
99             handler.handle_msg(buffer.length() == 0 ? null : buffer.toString(), attrs);
100         } else if ("name".equals(here)) {
101             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
102             handler.handle_name(buffer.length() == 0 ? null : buffer.toString(), attrs);
103         } else if ("revision".equals(here)) {
104             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
105             handler.handle_revision(buffer.length() == 0 ? null : buffer.toString(), attrs);
106         } else if ("tag".equals(here)) {
107             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
108             handler.handle_tag(buffer.length() == 0 ? null : buffer.toString(), attrs);
109         } else if ("time".equals(here)) {
110             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
111             handler.handle_time(buffer.length() == 0 ? null : buffer.toString(), attrs);
112         } else if ("utag".equals(here)) {
113             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
114             handler.handle_utag(buffer.length() == 0 ? null : buffer.toString(), attrs);
115         } else if ("weekday".equals(here)) {
116             if (fireOnlyIfMixed) throw new IllegalStateException JavaDoc("Unexpected mixed content element or a parser reporting whitespaces via characters() event!");
117             handler.handle_weekday(buffer.length() == 0 ? null : buffer.toString(), attrs);
118         } else {
119             //do not care
120
}
121         buffer.delete(0, buffer.length());
122     }
123     
124     /**
125      * The recognizer entry method taking an InputSource.
126      * @param input InputSource to be parsed.
127      * @throws java.io.IOException on I/O error.
128      * @throws org.xml.sax.SAXException propagated exception thrown by a DocumentHandler.
129      * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
130      * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
131      */

132     public void parse(final org.xml.sax.InputSource JavaDoc input) throws org.xml.sax.SAXException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, java.io.IOException JavaDoc {
133         parse(input, this);
134     }
135     
136     /**
137      * The recognizer entry method taking a URL.
138      * @param url URL source to be parsed.
139      * @throws java.io.IOException on I/O error.
140      * @throws org.xml.sax.SAXException propagated exception thrown by a DocumentHandler.
141      * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
142      * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
143      */

144     public void parse(final java.net.URL JavaDoc url) throws org.xml.sax.SAXException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, java.io.IOException JavaDoc {
145         parse(new org.xml.sax.InputSource JavaDoc(url.toExternalForm()), this);
146     }
147     
148     /**
149      * The recognizer entry method taking an Inputsource.
150      * @param input InputSource to be parsed.
151      * @throws java.io.IOException on I/O error.
152      * @throws org.xml.sax.SAXException propagated exception thrown by a DocumentHandler.
153      * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
154      * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
155      */

156     public static void parse(final org.xml.sax.InputSource JavaDoc input, final ChangelogHandler handler, final ChangelogParslet parslet) throws org.xml.sax.SAXException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, java.io.IOException JavaDoc {
157         parse(input, new ChangelogRecognizer(handler, parslet));
158     }
159     
160     /**
161      * The recognizer entry method taking a URL.
162      * @param url URL source to be parsed.
163      * @throws java.io.IOException on I/O error.
164      * @throws org.xml.sax.SAXException propagated exception thrown by a DocumentHandler.
165      * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
166      * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
167      */

168     public static void parse(final java.net.URL JavaDoc url, final ChangelogHandler handler, final ChangelogParslet parslet) throws org.xml.sax.SAXException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, java.io.IOException JavaDoc {
169         parse(new org.xml.sax.InputSource JavaDoc(url.toExternalForm()), handler, parslet);
170     }
171     
172     private static void parse(final org.xml.sax.InputSource JavaDoc input, final ChangelogRecognizer recognizer) throws org.xml.sax.SAXException JavaDoc, javax.xml.parsers.ParserConfigurationException JavaDoc, java.io.IOException JavaDoc {
173         javax.xml.parsers.SAXParserFactory JavaDoc factory = javax.xml.parsers.SAXParserFactory.newInstance();
174         factory.setValidating(false); //the code was generated according DTD
175
factory.setNamespaceAware(false); //the code was generated according DTD
176
org.xml.sax.Parser JavaDoc parser = factory.newSAXParser().getParser();
177         parser.setDocumentHandler(recognizer);
178         parser.parse(input);
179     }
180     
181     
182 }
Popular Tags