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.IOException;
023    import java.io.InputStream;
024    
025    import javax.servlet.jsp.tagext.PageData;
026    import javax.servlet.jsp.tagext.TagLibraryValidator;
027    import javax.servlet.jsp.tagext.ValidationMessage;
028    
029    
030    /**
031     * Example tag library validator that simply dumps the XML version of each
032     * page to standard output (which will typically be sent to the file
033     * <code>$CATALINA_HOME/logs/catalina.out</code>).  To utilize it, simply
034     * include a <code>taglib</code> directive for this tag library at the top
035     * of your JSP page.
036     *
037     * @author Craig McClanahan
038     * @version $Revision: 664175 $ $Date: 2008-06-06 18:43:44 -0400 (Fri, 06 Jun 2008) $
039     */
040    
041    public class DebugValidator extends TagLibraryValidator {
042    
043        // ----------------------------------------------------- Instance Variables
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    }