bloritsch 02/01/11 11:58:39 Modified: src/java/org/apache/cocoon Main.java Log: add facility to list all broken links to a file Revision Changes Path 1.10 +32 -3 xml-cocoon2/src/java/org/apache/cocoon/Main.java Index: Main.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/Main.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Main.java 11 Jan 2002 19:32:10 -0000 1.9 +++ Main.java 11 Jan 2002 19:58:39 -0000 1.10 @@ -81,6 +81,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FileWriter; +import java.io.PrintWriter; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; @@ -97,7 +99,7 @@ * Command line entry point. * * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Revision: 1.9 $ $Date: 2002/01/11 19:32:10 $ + * @version CVS $Revision: 1.10 $ $Date: 2002/01/11 19:58:39 $ */ public class Main { @@ -118,11 +120,16 @@ protected static final int URI_FILE = 'f'; protected static final int FOLLOW_LINKS_OPT = 'r'; protected static final int CONFIG_FILE = 'C'; + protected static final int BROKEN_LINK_FILE = 'b'; protected static final String DEFAULT_USER_AGENT = Constants.COMPLETE_NAME; protected static final String DEFAULT_ACCEPT = "text/html, */*"; protected static final CLOptionDescriptor [] OPTIONS = new CLOptionDescriptor [] { + new CLOptionDescriptor("brokenLinkFile", + CLOptionDescriptor.ARGUMENT_REQUIRED, + BROKEN_LINK_FILE, + "send a list of broken links to a file (1 uri per line)"), new CLOptionDescriptor("uriFile", CLOptionDescriptor.ARGUMENT_REQUIRED, URI_FILE, @@ -222,6 +229,7 @@ String destDir = Constants.DEFAULT_DEST_DIR; String contextDir = Constants.DEFAULT_CONTEXT_DIR; String configFile = null; + File brokenLinkFile = null; String workDir = Constants.DEFAULT_WORK_DIR; List targets = new ArrayList(); CLArgsParser parser = new CLArgsParser(args, OPTIONS); @@ -299,6 +307,11 @@ case Main.FOLLOW_LINKS_OPT: followLinks = "yes".equals(option.getArgument()) || "true".equals(option.getArgument()); + break; + + case Main.BROKEN_LINK_FILE: + brokenLinkFile = new File(option.getArgument()); + break; } } @@ -383,7 +396,7 @@ c.contextualize(appContext); c.setLogKitManager(logKitManager); c.initialize(); - Main main = new Main(c, context, dest); + Main main = new Main(c, context, dest, brokenLinkFile); main.userAgent = userAgent; main.accept = accept; main.followLinks = followLinks; @@ -499,6 +512,7 @@ private Cocoon cocoon; private File destDir; private File context; + private PrintWriter brokenLinkWriter; private Map attributes; private HashMap empty; private Map allProcessedLinks; @@ -513,10 +527,15 @@ * @param context a <code>File</code> for the context directory * @param destDir a <code>File</code> for the destination directory */ - public Main(Cocoon cocoon, File context, File destDir) { + public Main(Cocoon cocoon, File context, File destDir, File brokenLinks) { this.cocoon = cocoon; this.context = context; this.destDir = destDir; + try { + this.brokenLinkWriter = new PrintWriter(new FileWriter(brokenLinks), true); + } catch (IOException ioe) { + log.error("File does not exist: " + brokenLinks.getAbsolutePath()); + } this.attributes = new HashMap(); this.empty = new HashMap(); this.allProcessedLinks = new HashMap(); @@ -575,6 +594,9 @@ } } catch (ResourceNotFoundException rnfe) { log.warn(" [broken link]--> " + url); + if (null != this.brokenLinkWriter) { + this.brokenLinkWriter.println(url); + } } links.remove(url); nCount++; @@ -702,6 +724,10 @@ absoluteLinks.add(absoluteLink); } catch (ResourceNotFoundException rnfe) { log.warn(" [broken link]--> " + absoluteLink); + + if (null != this.brokenLinkWriter) { + this.brokenLinkWriter.println(absoluteLink); + } continue; } } @@ -719,6 +745,9 @@ if (type == null) { log.warn(" [broken link]--> " + filename); + if (null != this.brokenLinkWriter) { + this.brokenLinkWriter.println(filename); + } resourceUnavailable(file); } else { log.info(" [" + type + "]--> " + filename);
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]