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 00:11:08 GMT
nicolaken    2002/08/23 17:11:08

  Modified:    .        changes.xml
               src/java/org/apache/cocoon Main.java
  Log:
    <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.
    </action>
  
  Revision  Changes    Path
  1.236     +6 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.235
  retrieving revision 1.236
  diff -u -r1.235 -r1.236
  --- changes.xml	19 Aug 2002 08:27:42 -0000	1.235
  +++ changes.xml	24 Aug 2002 00:11:08 -0000	1.236
  @@ -39,6 +39,11 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <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.
  +  </action>
     <action dev="SMS" type="update">
      Add the methods 'copy', 'move' and 'delete' to the WriteableSource 
      interface.
  
  
  
  1.24      +64 -22    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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Main.java	31 Jul 2002 13:13:21 -0000	1.23
  +++ Main.java	24 Aug 2002 00:11:08 -0000	1.24
  @@ -67,6 +67,11 @@
   import org.apache.cocoon.util.IOUtils;
   import org.apache.cocoon.util.MIMEUtils;
   import org.apache.cocoon.util.NetUtils;
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.components.notification.Notifying;
  +import org.apache.cocoon.components.notification.SimpleNotifyingBean;
  +import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
  +import org.apache.cocoon.components.notification.Notifier;
   import org.apache.log.Hierarchy;
   import org.apache.log.Logger;
   import org.apache.log.Priority;
  @@ -329,7 +334,7 @@
           Hierarchy.getDefaultHierarchy().setDefaultPriority(priority);
           log = Hierarchy.getDefaultHierarchy().getLoggerFor("");
           
  -        System.out.print(".");
  +        if (verbose) System.out.print(".");
           
           if (destDir.equals("")) {
               String error = "Careful, you must specify a destination dir when using the
-d/--destDir argument";
  @@ -639,6 +644,7 @@
                       this.brokenLinkWriter.println(url);
                   }
               }
  +        
               links.remove(url);
               nCount++;
   
  @@ -726,7 +732,7 @@
        * @exception Exception if an error occurs
        */
       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: .");
  @@ -749,6 +755,7 @@
           }
   
           String filename = (String)allTranslatedLinks.get(suri);
  +        
           if (filename == null) {
               filename = mangle(suri);
               final String type = getType(deparameterizedURI, parameters);
  @@ -758,6 +765,7 @@
                   filename += defaultExt;
               }
               allTranslatedLinks.put(suri, filename);
  +      
           }
           // Store processed URI list to avoid eternal loop
           allProcessedLinks.put(suri, filename);
  @@ -791,17 +799,22 @@
                       if (verbose) System.out.print(".");                    
                       allTranslatedLinks.put(absoluteLink, translatedAbsoluteLink);
                       absoluteLinks.add(absoluteLink);
  -                } catch (ResourceNotFoundException rnfe) {
  +                }    
  +                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;
  -                }
  -            }
   
  +                    //continue;
  +                }                
  +            }
  +            
  +            //I have to add also broken links to the absolute links
  +            //to be able to generate the "broken link" page
  +            absoluteLinks.add(absoluteLink);  
               final String translatedRelativeLink = NetUtils.relativize(path, translatedAbsoluteLink);
               translatedLinks.put(link, translatedRelativeLink);
           }
  @@ -814,7 +827,7 @@
               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);
  @@ -822,7 +835,7 @@
                   if (null != this.brokenLinkWriter) {
                       this.brokenLinkWriter.println(filename);
                   }
  -                resourceUnavailable(file);
  +                resourceUnavailable(file, uri);
               } else {
                   log.info("  [" + type + "]--> " + filename);
                   if (verbose) System.out.println("  [" + type + "]--> " + filename);
   
  @@ -833,6 +846,7 @@
           }
   
           return absoluteLinks;
  +      
       }
   
       /**
  @@ -871,16 +885,22 @@
        * @param file being unavailable
        * @exception IOException if an error occurs
        */
  -    private void resourceUnavailable(File file) throws IOException {
  +    private void resourceUnavailable(File file, String uri) throws IOException {
  +    
  +        SimpleNotifyingBean n = new SimpleNotifyingBean(this);
  +        n.setType("resource-not-found");
  +        n.setTitle("Resource not Found");
  +        n.setSource("Cocoon commandline (Main.java)");
  +        n.setMessage("Page Not Available.");
  +        n.setDescription("The requested resource couldn't be found.");
  +        n.addExtraDescription("request-uri", uri);
  +        n.addExtraDescription("missing-file", file.toString());
  +
           PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(file)));
  -        out.println(
  -            new StringBuffer("<html><head><title>Page Not Available</title></head>")
  -                .append("<body><h1 align=\"center\">Page Not Available</h1>")
  -                .append("<body><p align=\"center\">Generated by ")
  -                .append(Constants.COMPLETE_NAME)
  -                .append("</p></body></html>")
  -        );
  -        out.close();
  +        Notifier.notify(n, out, "text/html");
  +        out.flush();
  +        out.close();  
  +
       }
   
       /**
  @@ -946,7 +966,7 @@
                     attributes,
                     parameters,
                     new LogKitLogger(this.log));
  -        cocoon.process(env);
  +        processLenient(env);
           return env.getLinks();
       }
   
  @@ -968,8 +988,12 @@
                           links,
                           stream,
                           new LogKitLogger(this.log));
  -        cocoon.process(env);
  -        return env.getContentType();
  +        if(processLenient(env)==true){
  +          return env.getContentType();
  +        }
  +        else{
  +          return null;
  +        }
       }
   
       /** Class <code>NullOutputStream</code> here. */
  @@ -996,10 +1020,28 @@
                        empty,
                        new NullOutputStream(),
                        new LogKitLogger(this.log));
  -        cocoon.process(env);
  +        processLenient(env);
           return env.getContentType();
       }
   
  +    /**
  +     * Try to process something but don't throw a ProcessingException.
  +     *
  +     * @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 boolean processLenient(Environment env) throws Exception {
  +       try{
  +            cocoon.process(env);
  +       }
  +       catch(ProcessingException pe){
  +         return false;
  +       }
  +
  +       return true;
  +    }
  +    
       /**
        * 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