1 /*** 2 * Copyright 2004 Fabrizio Giustina. 3 * 4 * Licensed under the Artistic License; you may not use this file 5 * except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://maven-taglib.sourceforge.net/license.html 9 * 10 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR 11 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 12 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 */ 14 package net.sf.maventaglib; 15 16 import java.io.File; 17 import java.util.ArrayList; 18 import java.util.List; 19 20 import javax.xml.parsers.DocumentBuilder; 21 22 import net.sf.maventaglib.checker.Tld; 23 import net.sf.maventaglib.checker.TldChecker; 24 import net.sf.maventaglib.checker.TldParser; 25 26 import org.dom4j.io.DocumentSource; 27 import org.w3c.dom.Document; 28 29 30 /*** 31 * Generates a tag library validation report. 32 * @author Fabrizio Giustina 33 * @version $Id: TaglibValidatePlugin.java,v 1.5 2005/08/23 12:29:52 fgiust Exp $ 34 */ 35 public class TaglibValidatePlugin extends TaglibPlugin 36 { 37 38 /*** 39 * Taglib validation ouput file. 40 */ 41 protected String report; 42 43 /*** 44 * Sets the output file name for the taglib validation xdoc. 45 * @param file output file name for the taglib validation xdoc 46 */ 47 public void setReport(String file) 48 { 49 this.report = file; 50 } 51 52 /*** 53 * @see net.sf.maventaglib.TaglibPlugin#execute() 54 */ 55 public void execute() throws Exception 56 { 57 File srcDirFile = new File(this.srcDir); 58 File outFile = new File(this.report); 59 echo("Validating tld files in " + srcDirFile.getAbsolutePath()); 60 if (!srcDirFile.isDirectory()) 61 { 62 throw new IllegalArgumentException("Not a directory: " + srcDirFile.getAbsolutePath()); 63 } 64 65 File[] files = srcDirFile.listFiles(); 66 DocumentBuilder builder = getDocumentBuilder(); 67 List tldList = new ArrayList(); 68 for (int i = 0; i < files.length; i++) 69 { 70 File current = files[i]; 71 if (!current.isDirectory() && current.getName().toLowerCase().endsWith(".tld")) 72 { 73 Document tldDoc = builder.parse(current); 74 Tld tld = TldParser.parse(tldDoc, current.getName()); 75 tldList.add(tld); 76 } 77 } 78 if (tldList.size() == 0) 79 { 80 echo("No tlds found in " + srcDirFile.getAbsolutePath() + "!"); 81 return; 82 } 83 84 TldChecker checker = new TldChecker(); 85 org.dom4j.Document checked = checker.check((Tld[]) tldList.toArray(new Tld[tldList.size()])); 86 87 this.applyXslt(new DocumentSource(checked), "/taglibvalidate.xsl", outFile); 88 } 89 }