KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tester > Xerces01


1 /*
2  * Copyright 1999, 2000, 2001 ,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18
19
20
21 package org.apache.tester;
22
23
24
25 import java.io.IOException JavaDoc;
26
27 import java.io.PrintWriter JavaDoc;
28
29 import java.net.MalformedURLException JavaDoc;
30
31 import java.net.URL JavaDoc;
32
33 import javax.servlet.*;
34
35 import javax.servlet.http.*;
36
37
38
39
40
41 /**
42
43  * Ensure that we can use the Xerces parser while included in a web application
44
45  * even though the servlet container might utilize its own parser for internal
46
47  * use.
48
49  *
50
51  * @author Amy Roh
52
53  * @author Craig McClanahan
54
55  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:57 $
56
57  */

58
59
60
61 public class Xerces01 extends HttpServlet {
62
63
64
65
66
67     // --------------------------------------------------------- Public Methods
68

69
70
71
72
73     /**
74
75      * Perform a simple SAX parse using Xerces (based on the SAXCount
76
77      * example application).
78
79      *
80
81      * @param request The servlet request we are processing
82
83      * @param response The servlet response we are creating
84
85      *
86
87      * @exception IOException if an input/output error occurs
88
89      * @exception ServletException if a servlet error occurs
90
91      */

92
93     public void service(HttpServletRequest request,
94
95                         HttpServletResponse response)
96
97         throws ServletException, IOException JavaDoc
98
99     {
100
101
102
103         // Prepare our output stream
104

105         response.setContentType("text/plain");
106
107         PrintWriter JavaDoc writer = response.getWriter();
108
109         boolean ok = true;
110
111
112
113         // Construct a new instance of our parser driver
114

115         URL JavaDoc url = null;
116
117         try {
118
119             url = getServletContext().getResource("/Xerces01.xml");
120
121         } catch (MalformedURLException JavaDoc e) {
122
123             writer.println("Xerces01 FAILED - " + e);
124
125             e.printStackTrace(writer);
126
127             ok = false;
128
129         }
130
131         Xerces01Parser parser = new Xerces01Parser();
132
133         try {
134
135             if (ok)
136
137                 parser.parse(url);
138
139         } catch (Exception JavaDoc e) {
140
141             writer.println("Xerces01 FAILED - " + e);
142
143             e.printStackTrace(writer);
144
145             ok = false;
146
147         }
148
149
150
151         // Report successful completion if OK
152

153         if (ok)
154
155             writer.println("Xerces01 PASSED");
156
157         while (true) {
158
159             String JavaDoc message = StaticLogger.read();
160
161             if (message == null)
162
163                 break;
164
165             writer.println(message);
166
167         }
168
169         StaticLogger.reset();
170
171
172
173     }
174
175
176
177
178
179 }
180
181
Popular Tags