cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon Main.java
Date Sat, 24 Aug 2002 17:34:51 GMT
nicolaken    2002/08/24 10:34:51

  Modified:    .        changes.xml
               src/java/org/apache/cocoon Main.java
  Log:
    <action dev="NKB" type="update">
     Made Commandline Cocoon (Main.java) verbose output (-V option)
     less cluttered and grouped the log and output methods.
    </action>
  
  Revision  Changes    Path
  1.237     +5 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.236
  retrieving revision 1.237
  diff -u -r1.236 -r1.237
  --- changes.xml	24 Aug 2002 00:11:08 -0000	1.236
  +++ changes.xml	24 Aug 2002 17:34:50 -0000	1.237
  @@ -40,6 +40,10 @@
   
    <release version="@version@" date="@date@">
     <action dev="NKB" type="update">
  +   Made Commandline Cocoon (Main.java) verbose output (-V option)
  +   less cluttered and grouped the log and output methods.
  +  </action>
  +  <action dev="NKB" type="update">
      Commandline Cocoon (Main.java) now doesn't stop anymore on broken links, 
      but inserts an error page instead and correctly notifies it in the
      broken links file if requested.
  
  
  
  1.25      +65 -82    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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Main.java	24 Aug 2002 00:11:08 -0000	1.24
  +++ Main.java	24 Aug 2002 17:34:51 -0000	1.25
  @@ -250,7 +250,7 @@
           String accept = DEFAULT_ACCEPT;
           boolean followLinks = true;
   
  -        System.out.print("\nsetup...");
  +        System.out.print("\nSetup...");
           
           List clOptions = parser.getArguments();
           int size = clOptions.size();
  @@ -334,8 +334,6 @@
           Hierarchy.getDefaultHierarchy().setDefaultPriority(priority);
           log = Hierarchy.getDefaultHierarchy().getLoggerFor("");
           
  -        if (verbose) System.out.print(".");
  -        
           if (destDir.equals("")) {
               String error = "Careful, you must specify a destination dir when using the
-d/--destDir argument";
               log.fatalError(error);
  @@ -364,8 +362,6 @@
               System.exit(1);
           }
   
  -        if (verbose) System.out.print(".");
  -        
           try {
               File dest = null;
               if (!precompileOnly) {
  @@ -383,8 +379,6 @@
                        conf = new File(context, configFile);
               }
   
  -        if (verbose) System.out.print(".");
  -        
               DefaultContext appContext = new DefaultContext();
               appContext.put(Constants.CONTEXT_CLASS_LOADER, Main.class.getClassLoader());
               CommandlineContext clContext = new CommandlineContext(contextDir);
  @@ -411,9 +405,7 @@
                   logKitManager = new DefaultLogKitManager(Hierarchy.getDefaultHierarchy());
                   logKitManager.setLogger(log);
               }
  -            
  -        if (verbose) System.out.print(".");
  -                    
  +  
               appContext.put(Constants.CONTEXT_CLASSPATH, getClassPath(contextDir));
               appContext.put(Constants.CONTEXT_WORK_DIR, work);
               appContext.put(Constants.CONTEXT_UPLOAD_DIR, contextDir + "upload-dir");
  @@ -422,30 +414,32 @@
               appContext.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
               Cocoon c = new Cocoon();
              
  -        if (verbose) System.out.print(".");
  -                    
               c.enableLogging(new LogKitLogger(log));
               c.contextualize(appContext);
               c.setLogKitManager(logKitManager);
               c.initialize();
               Main main = new Main(c, context, dest, brokenLinkFile);
  -            
  -        if (verbose) System.out.print(".");
  -                    
  +   
               main.userAgent = userAgent;
               main.accept = accept;
               main.followLinks = followLinks;
   
  -        System.out.print(".done.\n");
  -                    
  +            System.out.println(" done.");
  +            
  +            System.out.print("Initializing...");                       
               main.warmup();
  +            
  +            System.out.println(" ready, let's go :-)");
               if (main.process(targets, precompileOnly) == 0) {
                   main.recursivelyPrecompile(context, context);
               }
  -        if (verbose) System.out.print("\ndisposing...");
  +            
  +            System.out.print("\ndisposing...");
               c.dispose();
  -        if (verbose) System.out.print(".done.\n");
  +            
  +            System.out.print(" done.\n");
               log.info("Done");
  +            
           } catch (Exception e) {
               log.fatalError("Exception caught ", e);
               System.exit(1);
  @@ -560,7 +554,7 @@
       private String userAgent;
       private String accept;
       private boolean followLinks;
  -
  +    
       /**
        * Creates the Main class
        * @param cocoon a <code>Cocoon</code> instance
  @@ -589,8 +583,6 @@
        * @exception Exception if an error occurs
        */
       public void warmup() throws Exception {
  -        log.info("Warming up...");
  -        if (verbose) System.out.println("Warming up...");    
           //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,

  @@ -605,10 +597,8 @@
        * @exception Exception if an error occurs
        */
       public int process(Collection uris, boolean precompileOnly) throws Exception {
  -        int nCount = 0;
  -        log.info("...ready, let's go:");
  -        if (verbose) System.out.println("...ready, let's go:");
   
  +        int nCount = 0;
           ArrayList links = new java.util.ArrayList();
           Iterator i = uris.iterator();
           String next;
  @@ -638,11 +628,7 @@
                       }
                   }
               } catch (ResourceNotFoundException rnfe) {
  -                log.warn("  [broken link]--> " + url);
  -                if (verbose) System.out.println("  [broken link]--> " + url);      
         
  -                if (null != this.brokenLinkWriter) {
  -                    this.brokenLinkWriter.println(url);
  -                }
  +                printBroken (url);
               }
           
               links.remove(url);
  @@ -653,6 +639,7 @@
                   log.info("  Processed, Translated & Left: " + allProcessedLinks.size()
+ ", "  + allTranslatedLinks.size() + ", " + links.size());
               }
           }
  +
           return nCount;
       }
   
  @@ -710,7 +697,6 @@
           cocoon.precompile(uri, env, markupLanguage, programmingLanguage);
       }
   
  -
       /**
        * Processes the given URI and return all links. The algorithm is the following:
        *
  @@ -733,9 +719,7 @@
        */
       public Collection processURI(String uri) throws Exception {
   
  -        log.info("Processing URI: " + uri);
  -        if (verbose) System.out.println("URI: " + uri);
  -        if (verbose) System.out.print("  getting links: .");
  +        System.out.print(" * ");
                   
           // Get parameters, deparameterized URI and path from URI
           final TreeMap parameters = new TreeMap();
  @@ -778,6 +762,7 @@
           final ArrayList absoluteLinks = new ArrayList();
           final HashMap translatedLinks = new HashMap();
           final Iterator i = this.getLinks(deparameterizedURI, parameters).iterator();
  +
           while (i.hasNext()) {
               String link = (String) i.next();
               // Fix relative links starting with "?"
  @@ -796,19 +781,11 @@
                   try {
                       translatedAbsoluteLink = this.translateURI(absoluteLink);
                       log.info("  Link translated: " + absoluteLink);
  -                    if (verbose) System.out.print(".");                    
                       allTranslatedLinks.put(absoluteLink, translatedAbsoluteLink);
                       absoluteLinks.add(absoluteLink);
                   }    
                   catch (ProcessingException pe) {
  -                    log.warn("  [broken link]--> " + absoluteLink);
  -                    if (verbose) System.out.println("\n  [broken link]--> " + absoluteLink);
  -                    
  -                    if (null != this.brokenLinkWriter) {
  -                        this.brokenLinkWriter.println(absoluteLink);
  -                    }
  -
  -                    //continue;
  +                    printBroken(absoluteLink);
                   }                
               }
               
  @@ -819,7 +796,7 @@
               translatedLinks.put(link, translatedRelativeLink);
           }
           
  -        if (verbose) System.out.println("\n  processing");     
  +        printInfo("["+translatedLinks.size()+"] ");
           
           try {
               // Process URI
  @@ -827,18 +804,11 @@
               OutputStream output = new BufferedOutputStream(new FileOutputStream(file));
               String type = getPage(deparameterizedURI, parameters, translatedLinks, output);
               output.close();
  -            //NKB impossible, already checked before
               if (type == null) {
  -                log.warn("  [broken link]--> " + filename);
  -                if (verbose) System.out.println("  [broken link]--> " + filename);
  -                               
  -                if (null != this.brokenLinkWriter) {
  -                    this.brokenLinkWriter.println(filename);
  -                }
  +                printBroken(filename);
                   resourceUnavailable(file, uri);
               } else {
  -                log.info("  [" + type + "]--> " + filename);
  -                if (verbose) System.out.println("  [" + type + "]--> " + filename);
   
  +              printlnInfo(uri); //(can also output type)
               }
           } catch (ResourceNotFoundException rnfe) {
               this.log.warn("Could not process URI: " + deparameterizedURI);
  @@ -904,7 +874,7 @@
       }
   
       /**
  -     * Mangle an URI.
  +     * Mangle a URI.
        *
        * @param uri a URI to mangle
        * @return a mangled URI
  @@ -926,33 +896,6 @@
       }
   
       /**
  -     * Generate the string for a leaf in ascii art for a tree view log output.
  -     *
  -     * @param level of nesting
  -     * @return a <code>String</code> value to print the levels requested
  -     */
  -    private String leaf(int level) {
  -        if (level == 0) {
  -            return "";
  -        }
  -        return tree(level - 2) + "+--";
  -    }
  -
  -    /**
  -     * Generate the string for a tree in ascii art for a tree view log output.
  -     *
  -     * @param level of nesting
  -     * @return a <code>String</code> value to print the levels requested
  -     */
  -    protected String tree(int level) {
  -        StringBuffer buffer = new StringBuffer();
  -        for (int i = 0; i <= level; i++) {
  -            buffer.append("|  ");
  -        }
  -        return buffer.toString();
  -    }
  -
  -    /**
        * Samples an URI for its links.
        *
        * @param deparameterizedURI a <code>String</code> value of an URI to start
sampling from
  @@ -1041,7 +984,47 @@
   
          return true;
       }
  +
  +    /**
  +     * Print the message of a broken link.
  +     *
  +     * @param env the <code>Environment</code> to process
  +     * @returns boolean true if no error were cast, false otherwise
  +     * @exception Exception if an error occurs, except RNFE
  +     */
  +    private void printBroken(String url) {
  +       System.out.println("");
  +       printlnInfo("-> [broken link] " + url +" <- ");
  +       if (null != this.brokenLinkWriter) {
  +             this.brokenLinkWriter.println(url);
  +       }       
  +    }
       
  +    /**
  +     * Print an info message.
  +     *
  +     * @param env the <code>Environment</code> to process
  +     * @returns boolean true if no error were cast, false otherwise
  +     * @exception Exception if an error occurs, except RNFE
  +     */
  +    private void printlnInfo (String message) {
  +        log.info(message);
  +        if (verbose) System.out.println(message);   
  +    }      
  +       
  +    /**
  +     * Print an info message.
  +     *
  +     * @param env the <code>Environment</code> to process
  +     * @returns boolean true if no error were cast, false otherwise
  +     * @exception Exception if an error occurs, except RNFE
  +     */
  +    private void printInfo (String message) {
  +        log.info(message);
  +        if (verbose) System.out.print(message);   
  +    }  
  +        
  +             
       /**
        * This builds the important ClassPath used by this class.  It
        * does so in a neutral way.
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message