01: /*
02: * Copyright 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: package validators;
18:
19: import java.io.InputStream;
20: import java.io.IOException;
21: import javax.servlet.jsp.tagext.PageData;
22: import javax.servlet.jsp.tagext.TagLibraryValidator;
23: import javax.servlet.jsp.tagext.ValidationMessage;
24:
25: /**
26: * Example tag library validator that simply dumps the XML version of each
27: * page to standard output (which will typically be sent to the file
28: * <code>$CATALINA_HOME/logs/catalina.out</code>). To utilize it, simply
29: * include a <code>taglib</code> directive for this tag library at the top
30: * of your JSP page.
31: *
32: * @author Craig McClanahan
33: * @version $Revision: 1.2 $ $Date: 2004/03/18 16:40:29 $
34: */
35:
36: public class DebugValidator extends TagLibraryValidator {
37:
38: // ----------------------------------------------------- Instance Variables
39:
40: // --------------------------------------------------------- Public Methods
41:
42: /**
43: * Validate a JSP page. This will get invoked once per directive in the
44: * JSP page. This method will return <code>null</code> if the page is
45: * valid; otherwise the method should return an array of
46: * <code>ValidationMessage</code> objects. An array of length zero is
47: * also interpreted as no errors.
48: *
49: * @param prefix The value of the prefix argument in this directive
50: * @param uri The value of the URI argument in this directive
51: * @param page The page data for this page
52: */
53: public ValidationMessage[] validate(String prefix, String uri,
54: PageData page) {
55:
56: System.out.println("---------- Prefix=" + prefix + " URI="
57: + uri + "----------");
58:
59: InputStream is = page.getInputStream();
60: while (true) {
61: try {
62: int ch = is.read();
63: if (ch < 0)
64: break;
65: System.out.print((char) ch);
66: } catch (IOException e) {
67: break;
68: }
69: }
70: System.out.println();
71: System.out
72: .println("-----------------------------------------------");
73: return (null);
74:
75: }
76:
77: }
|