1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 19 package validators; 20 21 22 import java.io.IOException; 23 import java.io.InputStream; 24 25 import javax.servlet.jsp.tagext.PageData; 26 import javax.servlet.jsp.tagext.TagLibraryValidator; 27 import javax.servlet.jsp.tagext.ValidationMessage; 28 29 30 /** 31 * Example tag library validator that simply dumps the XML version of each 32 * page to standard output (which will typically be sent to the file 33 * <code>$CATALINA_HOME/logs/catalina.out</code>). To utilize it, simply 34 * include a <code>taglib</code> directive for this tag library at the top 35 * of your JSP page. 36 * 37 * @author Craig McClanahan 38 * @version $Revision: 664175 $ $Date: 2008-06-06 18:43:44 -0400 (Fri, 06 Jun 2008) $ 39 */ 40 41 public class DebugValidator extends TagLibraryValidator { 42 43 // ----------------------------------------------------- Instance Variables 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 }