From 3ef9dc7575edee9b5d79d50a3bba336c0e66e23a Mon Sep 17 00:00:00 2001 From: bwalding Date: Sat, 15 Feb 2003 08:04:20 +0000 Subject: [PATCH] o Rhino classes on classpath to stop javascript warning, additional code to disable scripting parsing git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112933 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/linkcheck/LinkCheck.java | 434 +++++++++--------- 1 file changed, 219 insertions(+), 215 deletions(-) diff --git a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java index 65f27dd5..8ce9577a 100644 --- a/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java +++ b/linkcheck/src/main/org/apache/maven/linkcheck/LinkCheck.java @@ -72,249 +72,253 @@ import org.apache.maven.linkcheck.validation.HTTPLinkValidator; import org.apache.maven.linkcheck.validation.LinkValidatorManager; import org.apache.maven.linkcheck.validation.MailtoLinkValidator; +import com.meterware.httpunit.HttpUnitOptions; + /** * The main bean to be called whenever a set of documents should have * their links checked. * * @author Ben Walding - * @version $Id: LinkCheck.java,v 1.4 2003/02/07 11:47:14 evenisse Exp $ + * @version $Id: LinkCheck.java,v 1.5 2003/02/15 08:04:20 bwalding Exp $ */ public class LinkCheck { - /** Log */ - private static final Log LOG = LogFactory.getLog(LinkCheck.class); + /** Log */ + private static final Log LOG = LogFactory.getLog(LinkCheck.class); - /** - * Output file for xml document - */ - private File output; + /** + * Output file for xml document + */ + private File output; - /** output encoding for the xml document */ - private String outputEncoding; + /** output encoding for the xml document */ + private String outputEncoding; - private File baseDir; - private String cache; - private String exclude; + private File baseDir; + private String cache; + private String exclude; - /** - * Set the base directory for the change log generator. - * @param base the base directory - */ - public void setBasedir(File base) - { - this.baseDir = base; - } - - /** - * Get the base directory for the change log generator. - * - * @return the base directory - */ - public File getBasedir() - { - return baseDir; - } - - /** - * Set the output file for the log. - * @param output the output file - */ - public void setOutput(File output) - { - this.output = output; - } - - /** - * Execute task. - * @throws FileNotFoundException if {@link ChangeLog#base} doesn't exist - * @throws IOException if there are problems running CVS - * @throws UnsupportedEncodingException if the underlying platform doesn't - * support ISO-8859-1 encoding - */ - List filesToCheck = null; //of FileToCheck - public void doExecute() throws Exception - { - if (output == null) + /** + * Set the base directory for the change log generator. + * @param base the base directory + */ + public void setBasedir(File base) { - throw new NullPointerException("output must be set"); - } - LinkValidatorManager lvm = getLinkValidatorManager(); - - filesToCheck = new ArrayList(); - lvm.loadCache(cache); - List files = new ArrayList(); - findFiles(files, baseDir); - Iterator fileIter = files.iterator(); - while (fileIter.hasNext()) - { - FileToCheck flc = (FileToCheck) fileIter.next(); - try - { - filesToCheck.add(flc); - flc.check(lvm); - } - catch (Exception e) - { - e.printStackTrace(); - } + this.baseDir = base; } - createDocument(files); - lvm.saveCache(cache); - } - - public List getFiles() - { - return filesToCheck; - } - - public void findFiles(List allFiles, File base) - { - FilenameFilter ff = new FilenameFilter() + /** + * Get the base directory for the change log generator. + * + * @return the base directory + */ + public File getBasedir() { - /** - * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String) - */ - public boolean accept(File dir, String name) - { - File n = new File(dir, name); - if (n.isDirectory()) - return true; + return baseDir; + } - if (name.endsWith(".html")) - return true; - - return false; - } - }; - - File[] f = base.listFiles(ff); - - if (f != null) + /** + * Set the output file for the log. + * @param output the output file + */ + public void setOutput(File output) { - for (int i = 0; i < f.length; i++) - { - File file = f[i]; - if (file.isDirectory()) + this.output = output; + } + + /** + * Execute task. + * @throws FileNotFoundException if {@link ChangeLog#base} doesn't exist + * @throws IOException if there are problems running CVS + * @throws UnsupportedEncodingException if the underlying platform doesn't + * support ISO-8859-1 encoding + */ + List filesToCheck = null; //of FileToCheck + public void doExecute() throws Exception + { + HttpUnitOptions.setScriptingEnabled(false); + if (output == null) { - findFiles(allFiles, file); + throw new NullPointerException("output must be set"); } - else + LinkValidatorManager lvm = getLinkValidatorManager(); + + filesToCheck = new ArrayList(); + lvm.loadCache(cache); + List files = new ArrayList(); + findFiles(files, baseDir); + Iterator fileIter = files.iterator(); + while (fileIter.hasNext()) { - allFiles.add(new FileToCheck(baseDir, file)); + FileToCheck flc = (FileToCheck) fileIter.next(); + try + { + filesToCheck.add(flc); + flc.check(lvm); + } + catch (Exception e) + { + e.printStackTrace(); + } } - } + + createDocument(files); + lvm.saveCache(cache); } - } - /** - * Create the XML document from the currently available details - * @throws FileNotFoundException when the output file previously provided - * does not exist - * @throws UnsupportedEncodingException when the platform doesn't support - * ISO-8859-1 encoding - */ - private void createDocument(List files) throws Exception - { - File dir = output.getParentFile(); - if (dir != null) { - dir.mkdirs(); - } - PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), getOutputEncoding())); - - StringBuffer buffer = new StringBuffer(); - buffer.append("\n"); - - out.write(buffer.toString()); - - out.write(toXML()); - out.close(); - } - - /** - * Returns the outputEncoding. - * @return String - */ - public String getOutputEncoding() - { - return outputEncoding; - } - - /** - * Sets the outputEncoding. - * @param outputEncoding The outputEncoding to set - */ - public void setOutputEncoding(String outputEncoding) - { - this.outputEncoding = outputEncoding; - } - - LinkValidatorManager lvm = null; - public LinkValidatorManager getLinkValidatorManager() - { - if (lvm == null) + public List getFiles() { - lvm = new LinkValidatorManager(); - lvm.setExclude(exclude); - lvm.addLinkValidator(new FileLinkValidator()); - lvm.addLinkValidator(new HTTPLinkValidator()); - lvm.addLinkValidator(new MailtoLinkValidator()); - lvm.loadCache(cache); + return filesToCheck; } - return lvm; - } - /** - * Returns the cacheFile. - * @return String - */ - public String getCache() - { - return cache; - } - - /** - * Sets the cacheFile. - * @param cacheFile The cacheFile to set - */ - public void setCache(String cache) - { - this.cache = cache; - } - - /** - * Returns the exclude. - * @return String - */ - public String getExclude() - { - return exclude; - } - - /** - * Sets the exclude. - * @param exclude The exclude to set - */ - public void setExclude(String exclude) - { - this.exclude = exclude; - } - - public String toXML() - { - StringBuffer buf = new StringBuffer(); - - buf.append("\n"); - - //buf.append(" \n"); - for (Iterator iter = getFiles().iterator(); iter.hasNext();) + public void findFiles(List allFiles, File base) { - FileToCheck ftc = (FileToCheck) iter.next(); - buf.append(ftc.toXML()); + FilenameFilter ff = new FilenameFilter() + { + /** + * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String) + */ + public boolean accept(File dir, String name) + { + File n = new File(dir, name); + if (n.isDirectory()) + return true; + + if (name.endsWith(".html")) + return true; + + return false; + } + }; + + File[] f = base.listFiles(ff); + + if (f != null) + { + for (int i = 0; i < f.length; i++) + { + File file = f[i]; + if (file.isDirectory()) + { + findFiles(allFiles, file); + } + else + { + allFiles.add(new FileToCheck(baseDir, file)); + } + } + } + } + + /** + * Create the XML document from the currently available details + * @throws FileNotFoundException when the output file previously provided + * does not exist + * @throws UnsupportedEncodingException when the platform doesn't support + * ISO-8859-1 encoding + */ + private void createDocument(List files) throws Exception + { + File dir = output.getParentFile(); + if (dir != null) + { + dir.mkdirs(); + } + PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), getOutputEncoding())); + + StringBuffer buffer = new StringBuffer(); + buffer.append("\n"); + + out.write(buffer.toString()); + + out.write(toXML()); + out.close(); + } + + /** + * Returns the outputEncoding. + * @return String + */ + public String getOutputEncoding() + { + return outputEncoding; + } + + /** + * Sets the outputEncoding. + * @param outputEncoding The outputEncoding to set + */ + public void setOutputEncoding(String outputEncoding) + { + this.outputEncoding = outputEncoding; + } + + LinkValidatorManager lvm = null; + public LinkValidatorManager getLinkValidatorManager() + { + if (lvm == null) + { + lvm = new LinkValidatorManager(); + lvm.setExclude(exclude); + lvm.addLinkValidator(new FileLinkValidator()); + lvm.addLinkValidator(new HTTPLinkValidator()); + lvm.addLinkValidator(new MailtoLinkValidator()); + lvm.loadCache(cache); + } + return lvm; + } + + /** + * Returns the cacheFile. + * @return String + */ + public String getCache() + { + return cache; + } + + /** + * Sets the cacheFile. + * @param cacheFile The cacheFile to set + */ + public void setCache(String cache) + { + this.cache = cache; + } + + /** + * Returns the exclude. + * @return String + */ + public String getExclude() + { + return exclude; + } + + /** + * Sets the exclude. + * @param exclude The exclude to set + */ + public void setExclude(String exclude) + { + this.exclude = exclude; + } + + public String toXML() + { + StringBuffer buf = new StringBuffer(); + + buf.append("\n"); + + //buf.append(" \n"); + for (Iterator iter = getFiles().iterator(); iter.hasNext();) + { + FileToCheck ftc = (FileToCheck) iter.next(); + buf.append(ftc.toXML()); + } + //buf.append(" \n"); + buf.append("\n"); + return buf.toString(); } - //buf.append(" \n"); - buf.append("\n"); - return buf.toString(); - } } \ No newline at end of file