KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servlet > ApplyXSLTListener


1 /*
2  * Copyright 1999-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  * $Id: ApplyXSLTListener.java,v 1.7 2004/02/17 19:13:22 minchau Exp $
18  */

19 package servlet;
20
21 import java.io.*;
22 import org.xml.sax.*;
23 import org.apache.xml.utils.DefaultErrorHandler;
24
25 /*****************************************************************************************************
26  * ApplyXSLTListener provides a buffered listener essential for capturing, and then subsequently
27  * reporting, XML and XSL processor messages which may be of use in debugging XML+XSL processed at
28  * the server.
29  *
30  * @author Spencer Shepard (sshepard@us.ibm.com)
31  * @author R. Adam King (rak@us.ibm.com)
32  * @author Tom Rowe (trowe@us.ibm.com)
33  *
34  *****************************************************************************************************/

35
36 public class ApplyXSLTListener extends DefaultErrorHandler implements ErrorHandler
37 {
38
39     /**
40       * Output stream
41       */

42     private ByteArrayOutputStream outStream = new ByteArrayOutputStream();
43
44     /**
45       * Buffered output stream
46       */

47     public PrintWriter out = null;
48
49     /**
50       * Constructor.
51       */

52     public ApplyXSLTListener()
53     {
54       out = new PrintWriter(new BufferedOutputStream(outStream), true);
55     }
56
57     /**
58       * Receive notification of a warning.
59       *
60       * @param spe The warning information encapsulated in a SAX parse exception.
61       */

62     public void warning(SAXParseException spe)
63     {
64     out.println("Parser Warning: " + spe.getMessage());
65     }
66
67     /**
68       * Receive notification of a recoverable error.
69       *
70       * @param spe The error information encapsulated in a SAX parse exception.
71       */

72     public void error(SAXParseException spe)
73     {
74     out.println("Parser Error: " + spe.getMessage());
75     }
76
77     /**
78       * Receive notification of a non-recoverable error.
79       *
80       * @param spe The error information encapsulated in a SAX parse exception.
81       * @exception SAXException Always thrown
82       */

83     public void fatalError(SAXParseException spe)
84     throws SAXException
85     {
86     out.println("Parser Fatal Error: " + spe.getMessage());
87     throw spe;
88     }
89
90     /**
91       * Returns the buffered processing message(s).
92       * @return Buffered processing message(s)
93       */

94     public String JavaDoc getMessage()
95     {
96     return outStream.toString();
97     }
98 }
99
100
Popular Tags