1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 08:40:35 -0800 (Thu, 18 Mar 2004) $
37 */
38
39 public class DebugValidator extends TagLibraryValidator {
40
41
42
43
44
45
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 }