DebugValidator.java
上传用户:bj_pst
上传日期:2019-07-07
资源大小:7353k
文件大小:3k
源码类别:

Java编程

开发平台:

Java

  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. package validators;
  18. import java.io.InputStream;
  19. import java.io.IOException;
  20. import javax.servlet.jsp.tagext.PageData;
  21. import javax.servlet.jsp.tagext.TagLibraryValidator;
  22. import javax.servlet.jsp.tagext.ValidationMessage;
  23. /**
  24.  * Example tag library validator that simply dumps the XML version of each
  25.  * page to standard output (which will typically be sent to the file
  26.  * <code>$CATALINA_HOME/logs/catalina.out</code>).  To utilize it, simply
  27.  * include a <code>taglib</code> directive for this tag library at the top
  28.  * of your JSP page.
  29.  *
  30.  * @author Craig McClanahan
  31.  * @version $Revision: 466607 $ $Date: 2006-10-21 17:09:50 -0600 (Sat, 21 Oct 2006) $
  32.  */
  33. public class DebugValidator extends TagLibraryValidator {
  34.     // ----------------------------------------------------- Instance Variables
  35.     // --------------------------------------------------------- Public Methods
  36.     /**
  37.      * Validate a JSP page.  This will get invoked once per directive in the
  38.      * JSP page.  This method will return <code>null</code> if the page is
  39.      * valid; otherwise the method should return an array of
  40.      * <code>ValidationMessage</code> objects.  An array of length zero is
  41.      * also interpreted as no errors.
  42.      *
  43.      * @param prefix The value of the prefix argument in this directive
  44.      * @param uri The value of the URI argument in this directive
  45.      * @param page The page data for this page
  46.      */
  47.     public ValidationMessage[] validate(String prefix, String uri,
  48.                                         PageData page) {
  49.         System.out.println("---------- Prefix=" + prefix + " URI=" + uri +
  50.                            "----------");
  51.         InputStream is = page.getInputStream();
  52.         while (true) {
  53.             try {
  54.                 int ch = is.read();
  55.                 if (ch < 0)
  56.                     break;
  57.                 System.out.print((char) ch);
  58.             } catch (IOException e) {
  59.                 break;
  60.             }
  61.         }
  62.         System.out.println();
  63.         System.out.println("-----------------------------------------------");
  64.         return (null);
  65.     }
  66. }