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