01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.1 2006-06-27 14:42:52 sinisa 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
37: ErrorHandler {
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: out = new PrintWriter(new BufferedOutputStream(outStream), true);
54: }
55:
56: /**
57: * Receive notification of a warning.
58: *
59: * @param spe The warning information encapsulated in a SAX parse exception.
60: */
61: public void warning(SAXParseException spe) {
62: out.println("Parser Warning: " + spe.getMessage());
63: }
64:
65: /**
66: * Receive notification of a recoverable error.
67: *
68: * @param spe The error information encapsulated in a SAX parse exception.
69: */
70: public void error(SAXParseException spe) {
71: out.println("Parser Error: " + spe.getMessage());
72: }
73:
74: /**
75: * Receive notification of a non-recoverable error.
76: *
77: * @param spe The error information encapsulated in a SAX parse exception.
78: * @exception SAXException Always thrown
79: */
80: public void fatalError(SAXParseException spe) throws SAXException {
81: out.println("Parser Fatal Error: " + spe.getMessage());
82: throw spe;
83: }
84:
85: /**
86: * Returns the buffered processing message(s).
87: * @return Buffered processing message(s)
88: */
89: public String getMessage() {
90: return outStream.toString();
91: }
92: }
|