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