001 /* 002 * Copyright 2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 018 package validators; 019 020 021 import java.io.InputStream; 022 import java.io.IOException; 023 import javax.servlet.jsp.tagext.PageData; 024 import javax.servlet.jsp.tagext.TagLibraryValidator; 025 import javax.servlet.jsp.tagext.ValidationMessage; 026 027 028 /** 029 * Example tag library validator that simply dumps the XML version of each 030 * page to standard output (which will typically be sent to the file 031 * <code>$CATALINA_HOME/logs/catalina.out</code>). To utilize it, simply 032 * include a <code>taglib</code> directive for this tag library at the top 033 * of your JSP page. 034 * 035 * @author Craig McClanahan 036 * @version $Revision: 267129 $ $Date: 2004-03-18 08:40:35 -0800 (Thu, 18 Mar 2004) $ 037 */ 038 039 public class DebugValidator extends TagLibraryValidator { 040 041 042 // ----------------------------------------------------- Instance Variables 043 044 045 // --------------------------------------------------------- Public Methods 046 047 048 /** 049 * Validate a JSP page. This will get invoked once per directive in the 050 * JSP page. This method will return <code>null</code> if the page is 051 * valid; otherwise the method should return an array of 052 * <code>ValidationMessage</code> objects. An array of length zero is 053 * also interpreted as no errors. 054 * 055 * @param prefix The value of the prefix argument in this directive 056 * @param uri The value of the URI argument in this directive 057 * @param page The page data for this page 058 */ 059 public ValidationMessage[] validate(String prefix, String uri, 060 PageData page) { 061 062 System.out.println("---------- Prefix=" + prefix + " URI=" + uri + 063 "----------"); 064 065 InputStream is = page.getInputStream(); 066 while (true) { 067 try { 068 int ch = is.read(); 069 if (ch < 0) 070 break; 071 System.out.print((char) ch); 072 } catch (IOException e) { 073 break; 074 } 075 } 076 System.out.println(); 077 System.out.println("-----------------------------------------------"); 078 return (null); 079 080 } 081 082 083 }