1 17 18 19 package org.apache.catalina.ant; 20 21 22 import java.io.BufferedInputStream ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.InputStream ; 26 27 import org.apache.catalina.startup.Constants; 28 import org.apache.catalina.startup.DigesterFactory; 29 import org.apache.tomcat.util.digester.Digester; 30 import org.apache.tools.ant.BuildException; 31 import org.xml.sax.InputSource ; 32 33 34 42 43 public class ValidatorTask extends BaseRedirectorHelperTask { 44 45 46 48 49 51 52 55 protected String path = null; 56 57 public String getPath() { 58 return (this.path); 59 } 60 61 public void setPath(String path) { 62 this.path = path; 63 } 64 65 66 68 69 76 public void execute() throws BuildException { 77 78 if (path == null) { 79 throw new BuildException("Must specify 'path'"); 80 } 81 82 File file = new File (path, Constants.ApplicationWebXml); 83 if ((!file.exists()) || (!file.canRead())) { 84 throw new BuildException("Cannot find web.xml"); 85 } 86 87 ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); 89 Thread.currentThread().setContextClassLoader 90 (ValidatorTask.class.getClassLoader()); 91 92 Digester digester = DigesterFactory.newDigester(true, true, null); 93 try { 94 file = file.getCanonicalFile(); 95 InputStream stream = 96 new BufferedInputStream (new FileInputStream (file)); 97 InputSource is = new InputSource (file.toURL().toExternalForm()); 98 is.setByteStream(stream); 99 digester.parse(is); 100 handleOutput("web.xml validated"); 101 } catch (Throwable t) { 102 if (isFailOnError()) { 103 throw new BuildException("Validation failure", t); 104 } else { 105 handleErrorOutput("Validation failure: " + t); 106 } 107 } finally { 108 Thread.currentThread().setContextClassLoader(oldCL); 109 closeRedirector(); 110 } 111 112 } 113 114 115 } 116 | Popular Tags |