vgritsenko 2003/02/01 15:57:21 Modified: src/java/org/apache/cocoon Main.java src/java/org/apache/cocoon/environment/commandline CommandLineRequest.java Log: Make some public methods private, cosmetic changes. Revision Changes Path 1.31 +72 -90 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.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- Main.java 31 Jan 2003 22:51:18 -0000 1.30 +++ Main.java 1 Feb 2003 23:57:20 -0000 1.31 @@ -58,7 +58,6 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.avalon.framework.context.DefaultContext; -//import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.logger.LogKitLogger; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.commandline.CommandlineContext; @@ -145,10 +144,10 @@ CLOptionDescriptor.ARGUMENT_DISALLOWED, VERSION_OPT, "print the version information and exit"), - new CLOptionDescriptor("verbose", - CLOptionDescriptor.ARGUMENT_DISALLOWED, - VERBOSE_OPT, - "enable verbose messages to System.out"), + new CLOptionDescriptor("verbose", + CLOptionDescriptor.ARGUMENT_DISALLOWED, + VERBOSE_OPT, + "enable verbose messages to System.out"), new CLOptionDescriptor("logKitconfig", CLOptionDescriptor.ARGUMENT_REQUIRED, LOG_KIT_OPT, @@ -226,7 +225,6 @@ } } - /** * The <code>main</code> method. * @@ -263,8 +261,8 @@ break; case Main.CONFIG_FILE: - configFile = option.getArgument(); - break; + configFile = option.getArgument(); + break; case Main.HELP_OPT: printUsage(); @@ -274,9 +272,9 @@ printVersion(); break; - case Main.VERBOSE_OPT: - Main.verbose = true; - break; + case Main.VERBOSE_OPT: + Main.verbose = true; + break; case Main.DEST_DIR_OPT: destDir = option.getArgument(); @@ -370,7 +368,7 @@ File context = getDir(contextDir, "context"); File conf = null; - if ( null == configFile ) { + if (null == configFile) { conf = getConfigurationFile(context); } else { conf = new File(configFile); @@ -472,9 +470,9 @@ * * @param dir a <code>File</code> where to look for configuration files * @return a <code>File</code> representing the configuration - * @exception Exception if an error occurs + * @exception IOException if an error occurs */ - private static File getConfigurationFile(File dir) throws Exception { + private static File getConfigurationFile(File dir) throws IOException { if (log.isDebugEnabled()) { log.debug("Trying configuration file at: " + dir + File.separator + Constants.DEFAULT_CONF_FILE); @@ -487,7 +485,7 @@ if (log.isDebugEnabled()) { log.debug("Trying configuration file at: " + System.getProperty("user.dir") + File.separator + Constants.DEFAULT_CONF_FILE); } - f = new File(System.getProperty("user.dir") + File.separator + Constants.DEFAULT_CONF_FILE); + f = new File(System.getProperty("user.dir"), Constants.DEFAULT_CONF_FILE); if (f.canRead()) { return f; } @@ -510,9 +508,9 @@ * @param dir a <code>String</code> with a directory name * @param type a <code>String</code> describing the type of directory * @return a <code>File</code> value - * @exception Exception if an error occurs + * @exception IOException if an error occurs */ - private static File getDir(String dir, String type) throws Exception { + private static File getDir(String dir, String type) throws IOException { if (log.isDebugEnabled()) { log.debug("Getting handle to " + type + " directory '" + dir + "'"); @@ -582,8 +580,7 @@ */ public void warmup() throws Exception { //log.info(" [Cocoon might need to compile the sitemaps, this might take a while]"); - //cocoon.process(new LinkSamplingEnvironment("/", context, attributes, null)); - cocoon.generateSitemap(new LinkSamplingEnvironment("/", context, attributes, null, + cocoon.generateSitemap(new LinkSamplingEnvironment("/", context, attributes, null, new LogKitLogger(log))); } @@ -594,7 +591,7 @@ * @return an <code>int</code> value with the number of links processed * @exception Exception if an error occurs */ - public int process(Collection uris, boolean precompileOnly) throws Exception { + private int process(Collection uris, boolean precompileOnly) throws Exception { int nCount = 0; ArrayList links = new java.util.ArrayList(); @@ -614,7 +611,7 @@ if (precompileOnly) { this.processXSP(url); } else if (this.followLinks) { - i = this.processURI(url).iterator(); + i = processURI(url).iterator(); while (i.hasNext()) { next = (String)i.next(); if (!links.contains(next)) { @@ -622,13 +619,13 @@ } } } else { - this.processURI(url); + processURI(url); } } } catch (ResourceNotFoundException rnfe) { printBroken (url, rnfe.getMessage()); } - + links.remove(url); nCount++; @@ -646,7 +643,7 @@ * @param contextDir a <code>File</code> value for the context directory * @param file a <code>File</code> value for a single XSP file or a directory to scan recursively */ - public void recursivelyPrecompile(File contextDir, File file) { + private void recursivelyPrecompile(File contextDir, File file) { if (file.isDirectory()) { String entries[] = file.list(); for (int i = 0; i < entries.length; i++) { @@ -673,10 +670,10 @@ * @param uri a <code>String</code> pointing to an xsp URI * @exception Exception if an error occurs */ - public void processXSP(String uri) throws Exception { + private void processXSP(String uri) throws Exception { String markupLanguage = "xsp"; String programmingLanguage = "java"; - Environment env = new LinkSamplingEnvironment("/", context, attributes, null, + Environment env = new LinkSamplingEnvironment("/", context, attributes, null, new LogKitLogger(log)); cocoon.precompile(uri, env, markupLanguage, programmingLanguage); } @@ -687,10 +684,10 @@ * @param uri a <code>String</code> pointing to an xmap URI * @exception Exception if an error occurs */ - public void processXMAP(String uri) throws Exception { + private void processXMAP(String uri) throws Exception { String markupLanguage = "sitemap"; String programmingLanguage = "java"; - Environment env = new LinkSamplingEnvironment("/", context, attributes, null, + Environment env = new LinkSamplingEnvironment("/", context, attributes, null, new LogKitLogger(log)); cocoon.precompile(uri, env, markupLanguage, programmingLanguage); } @@ -715,10 +712,9 @@ * @return a <code>Collection</code> containing all links found * @exception Exception if an error occurs */ - public Collection processURI(String uri) throws Exception { - + private Collection processURI(String uri) throws Exception { System.out.print(" * "); - + // Get parameters, deparameterized URI and path from URI final TreeMap parameters = new TreeMap(); final String deparameterizedURI = NetUtils.deparameterize(uri, parameters); @@ -737,7 +733,6 @@ } String filename = (String)allTranslatedLinks.get(suri); - if (filename == null) { filename = mangle(suri); final String type = getType(deparameterizedURI, parameters); @@ -747,7 +742,6 @@ filename += defaultExt; } allTranslatedLinks.put(suri, filename); - } // Store processed URI list to avoid eternal loop allProcessedLinks.put(suri, filename); @@ -781,21 +775,20 @@ log.info(" Link translated: " + absoluteLink); allTranslatedLinks.put(absoluteLink, translatedAbsoluteLink); absoluteLinks.add(absoluteLink); - } - catch (ProcessingException pe) { + } catch (ProcessingException pe) { printBroken(absoluteLink, pe.getMessage()); - } + } } - + // I have to add also broken links to the absolute links // to be able to generate the "broken link" page - absoluteLinks.add(absoluteLink); + absoluteLinks.add(absoluteLink); final String translatedRelativeLink = NetUtils.relativize(path, translatedAbsoluteLink); translatedLinks.put(link, translatedRelativeLink); } - + printInfo("["+translatedLinks.size()+"] "); - + try { // Process URI File file = IOUtils.createFile(destDir, NetUtils.decodePath(filename)); @@ -806,18 +799,20 @@ printlnInfo(uri); // (can also output type returned by getPage) } catch(ProcessingException pe) { printBroken(filename, DefaultNotifyingBuilder.getRootCause(pe).getMessage()); + output.close(); resourceUnavailable(file, uri); } finally { try { - output.close(); + if (output != null) + output.close(); } catch(IOException ioex) { log.warn(ioex.toString()); } } } catch (Exception rnfe) { - System.out.println("XXX"+rnfe); + System.out.println("XXX" + rnfe); log.warn("Could not process URI: " + deparameterizedURI); - if (verbose) System.out.println("Could not process URI: " + deparameterizedURI); + if (verbose) System.out.println("Could not process URI: " + deparameterizedURI); } return absoluteLinks; @@ -830,7 +825,7 @@ * @return a <code>String</code> vlaue for the file * @exception Exception if an error occurs */ - public String translateURI(String uri) throws Exception { + private String translateURI(String uri) throws Exception { if (null == uri || "".equals(uri)) { log.warn("translate empty uri"); if (verbose) System.out.println("translate empty uri"); @@ -859,7 +854,6 @@ * @exception IOException if an error occurs */ private void resourceUnavailable(File file, String uri) throws IOException { - SimpleNotifyingBean n = new SimpleNotifyingBean(this); n.setType("resource-not-found"); n.setTitle("Resource not Found"); @@ -872,8 +866,7 @@ PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(file))); Notifier.notify(n, out, "text/html"); out.flush(); - out.close(); - + out.close(); } /** @@ -934,12 +927,10 @@ links, stream, new LogKitLogger(log)); - - //Here Cocoon can throw an exception if there are errors in processing the page - cocoon.process(env); - //if we get here, the page was created :-) - return env.getContentType(); - + // Here Cocoon can throw an exception if there are errors in processing the page + cocoon.process(env); + // if we get here, the page was created :-) + return env.getContentType(); } /** Class <code>NullOutputStream</code> here. */ @@ -980,8 +971,7 @@ private boolean processLenient(Environment env) throws Exception { try{ cocoon.process(env); - } - catch(ProcessingException pe){ + } catch(ProcessingException pe) { return false; } @@ -995,38 +985,34 @@ * @param cause of the broken link */ private void printBroken(String url, String cause) { + int screenWidth = 67; + int causeWidth = screenWidth - 6; - int screenWidth=67; - int causeWidth= screenWidth - 6; + printlnInfo(""); + printlnInfo("-> [broken page] " + url +" <- "); + printlnInfo(""); + printInfo(" "); - printlnInfo(""); - printlnInfo("-> [broken page] " + url +" <- "); - printlnInfo(""); - printInfo(" "); - - int causeLength = cause.length(), currentStart = -causeWidth, currentEnd = 0 ; - - do{ - - currentStart+=causeWidth; - currentEnd +=causeWidth; + int causeLength = cause.length(), currentStart = -causeWidth, currentEnd = 0 ; + do { + currentStart += causeWidth; + currentEnd += causeWidth; - if(currentEnd>causeLength){ - currentEnd=causeLength; + if (currentEnd>causeLength) { + currentEnd=causeLength; } - printlnInfo(cause.substring(currentStart, currentEnd) ); - printInfo(" "); - - }while(currentEnd<causeLength); - - printlnInfo(""); - + printlnInfo(cause.substring(currentStart, currentEnd) ); + printInfo(" "); + } while(currentEnd < causeLength); + + printlnInfo(""); + if (null != this.brokenLinkWriter) { this.brokenLinkWriter.println(url); - } + } } - + /** * Print an info message. * @@ -1034,9 +1020,9 @@ */ private void printlnInfo (String message) { log.info(message); - if (verbose) System.out.println(message); - } - + if (verbose) System.out.println(message); + } + /** * Print an info message. * @@ -1044,10 +1030,9 @@ */ private void printInfo (String message) { log.info(message); - if (verbose) System.out.print(message); - } - - + if (verbose) System.out.print(message); + } + /** * This builds the important ClassPath used by this class. It * does so in a neutral way. @@ -1089,6 +1074,3 @@ return buildClassPath.toString(); } } - - - 1.6 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java Index: CommandLineRequest.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CommandLineRequest.java 31 Jan 2003 22:51:44 -0000 1.5 +++ CommandLineRequest.java 1 Feb 2003 23:57:20 -0000 1.6 @@ -187,7 +187,7 @@ final String value = this.getParameter(name); if (value != null) { return new String[] {value}; - } + } return null; }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]