cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/environment/commandline FileSavingEnvironment.java LinkSamplingEnvironment.java
Date Sun, 03 Sep 2000 17:45:47 GMT
stefano     00/09/03 10:45:46

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Constants.java
                        Main.java
               src/org/apache/cocoon/environment Tag: xml-cocoon2
                        AbstractEnvironment.java
               src/org/apache/cocoon/environment/commandline Tag:
                        xml-cocoon2 FileSavingEnvironment.java
                        LinkSamplingEnvironment.java
  Log:
  added almost final command line usage implementation... just a link transformer to write
and I'm done (awaiting for views to be fully operational)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +24 -17    xml-cocoon/src/org/apache/cocoon/Attic/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Constants.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- Constants.java	2000/08/31 16:41:01	1.1.2.1
  +++ Constants.java	2000/09/03 17:45:45	1.1.2.2
  @@ -10,32 +10,39 @@
   
   /**
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2000/08/31 16:41:01 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/09/03 17:45:45 $
    */
   
   public interface Constants {
   
  -    public static final String NAME                = "@name@";
  -    public static final String VERSION             = "@version@";
  -    public static final String CONF_VERSION        = "2.0";
  -    public static final String YEAR                = "@year@";
  -    public static final String RELOAD_PARAM        = "cocoon-reload";
  -    public static final String SHOWTIME_PARAM      = "cocoon-showtime";
  -    public static final String VIEW_PARAM          = "cocoon-view";
  -    public static final String TEMPDIR_PROPERTY    = "org.apache.cocoon.properties.tempdir";
  -    public static final String DEFAULT_CONF_FILE   = "cocoon.xconf";
  -    public static final String DEFAULT_DEST_DIR    = "./site";
  -    public static final String DEFAULT_TEMP_DIR    = "./work";
  -    public static final String LINK_CONTENT_TYPE   = "x-application/x-cocoon-links";
  -    public static final String LINK_VIEW           = "links";
  -    public static final String LINK_CRAWLING_ROLE  = "static";
  -    public static final String PARSER_PROPERTY     = "org.apache.cocoon.components.parser.Parser";
  -    public static final String DEFAULT_PARSER      = "org.apache.cocoon.components.parser.XercesParser";
  +    public static final String NAME         = "@name@";
  +    public static final String VERSION      = "@version@";
  +    public static final String CONF_VERSION = "2.0";
  +    public static final String YEAR         = "@year@";
  +
  +    public static final String RELOAD_PARAM   = "cocoon-reload";
  +    public static final String SHOWTIME_PARAM = "cocoon-showtime";
  +    public static final String VIEW_PARAM     = "cocoon-view";
  +
  +    public static final String TEMPDIR_PROPERTY  = "org.apache.cocoon.properties.tempdir";
  +    public static final String DEFAULT_CONF_FILE = "cocoon.xconf";
  +    public static final String DEFAULT_DEST_DIR  = "./site";
  +    public static final String DEFAULT_TEMP_DIR  = "./work";
  +
  +    public static final String PARSER_PROPERTY = "org.apache.cocoon.components.parser.Parser";
  +    public static final String DEFAULT_PARSER  = "org.apache.cocoon.components.parser.XercesParser";
  +
       public static final String XSP_PREFIX          = "xsp";
       public static final String XSP_URI             = "http://apache.org/xsp";
       public static final String XSP_REQUEST_PREFIX  = "xsp-request";
       public static final String XSP_REQUEST_URI     = XSP_URI + "/request";
       public static final String XSP_RESPONSE_PREFIX = "xsp-response";
       public static final String XSP_RESPONSE_URI    = XSP_URI + "/response";  
  +
  +    public static final String LINK_CONTENT_TYPE     = "application/x-cocoon-links";
  +    public static final String LINK_VIEW             = "links";
  +    public static final String LINK_CRAWLING_ROLE    = "static";
  +    public static final String LINK_TRANSLATING_VIEW = "translate-links";
  +    public static final String LINK_TRANSLATED_NAME  = "translated-links";    
   
   }
  
  
  
  1.1.4.3   +127 -17   xml-cocoon/src/org/apache/cocoon/Attic/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Main.java,v
  retrieving revision 1.1.4.2
  retrieving revision 1.1.4.3
  diff -u -r1.1.4.2 -r1.1.4.3
  --- Main.java	2000/08/31 15:59:23	1.1.4.2
  +++ Main.java	2000/09/03 17:45:45	1.1.4.3
  @@ -13,10 +13,14 @@
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.PrintStream;
  +import java.io.OutputStream;
   
  +import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
   import java.util.ArrayList;
  +import java.util.Map;
  +import java.util.HashMap;
   
   import org.apache.cocoon.util.IOUtils;
   import org.apache.cocoon.environment.Environment;
  @@ -28,7 +32,7 @@
    * Command line entry point.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.4.2 $ $Date: 2000/08/31 15:59:23 $
  + * @version CVS $Revision: 1.1.4.3 $ $Date: 2000/09/03 17:45:45 $
    */
   
   public class Main {
  @@ -100,7 +104,7 @@
               File root = conf.getParentFile();
               Main main = new Main(new Cocoon(conf), conf, dest);
               System.out.println("[main] Starting...");
  -            main.processLinks(targets.iterator());
  +            main.process(targets);
               System.out.println("[main] Done.");
           } catch (Exception e) {
               System.out.println("[fatal error] Exception caught (" + e.getClass().getName()
+ "): " + e.getMessage() + "\n");
  @@ -195,27 +199,133 @@
       }
   
       /**
  -     * Process the link list and recursively process them all.
  +     * Process the URI list and process them all independently.
        */
  -    public void processLinks(Iterator links) throws Exception {
  -        while (links.hasNext()) {
  -            String link = (String) links.next();
  -            this.processLinks(this.processLink(link));
  +    public void process(Collection uris) throws Exception {
  +        Iterator i = uris.iterator();
  +        while (i.hasNext()) {
  +            String uri = (String) i.next();
  +            System.out.println("[main] starting from: " + uri);
  +            this.processURI(uri);
           }
       }
   
       /**
  -     * Process the given link and return the list of sublinks.
  +     * Processes the given URI in a recursive way. The algorithm followed by
  +     * this method is the following:
  +     *
  +     * <ul>
  +     *  <li>the link view of the given URI is called and the resourced linked
  +     *      to the requested one are obtained.</li>
  +     *  <li>for each link, this method is recursively called and returns
  +     *      the file used to save the resource on disk.</li>
  +     *  <li>after the complete list of links is translated, the link-translating
  +     *      view of the resource is called to obtain a link-translated version
  +     *      of the resource with the given link map</li>
  +     *  <li>the resource is saved on disk and the URI MIME type is checked for 
  +     *      consistenci with the URI and, if the extention is inconsistent
  +     *      or absent, the file is renamed</li>
  +     *  <li>then the file name of the translated URI is returned</li>
  +     * </ul>
        */
  -    public Iterator processLink(String link) throws Exception {
  -        System.out.println("[main] processing link: " + link);        
  -        // First process the given link and save it on disk
  -        FileSavingEnvironment fileEnv = new FileSavingEnvironment(link, root, destDir);
  -        cocoon.process(fileEnv);
  -        // Then process it again (with another view) to obtain the hyperlinks
  -        LinkSamplingEnvironment linkEnv = new LinkSamplingEnvironment(link);
  -        cocoon.process(linkEnv);
  -        return linkEnv.getLinks();
  +    public File processURI(String uri) throws Exception {
  +        System.out.println("[main] processing: " + uri);
  +        
  +        Collection links = getLinks(uri);
  +        Map translatedLinks = new HashMap(links.size());
  +        Iterator i = links.iterator();
  +        while (i.hasNext()) {
  +            String link = (String) i.next();
  +            translatedLinks.put(link, processURI(link));
  +        }
  +        
  +        File outputFile = getFile(uri);
  +        FileOutputStream output = new FileOutputStream(getFile(uri));
  +        String type = getPage(uri, translatedLinks, output);
  +        output.close();
  +        
  +        if (!matchesExtention(uri, type)) {
  +            outputFile.renameTo(getFile(uri, type));
  +        }
  +        
  +        return outputFile;
  +    }        
  +    
  +    Collection getLinks(String uri) throws Exception {
  +        LinkSamplingEnvironment env = new LinkSamplingEnvironment(uri);
  +        cocoon.process(env);
  +        return env.getLinks();
  +    }
  +
  +    String getPage(String uri, Map links, OutputStream stream) throws Exception {
  +        FileSavingEnvironment env = new FileSavingEnvironment(uri, root, links, stream);
  +        cocoon.process(env);
  +        return env.getContentType();
  +    }
  +    
  +    File getFile(String uri) {
  +        return new File(destDir, uri);
  +    }
  +    
  +    File getFile(String uri, String type) {
  +        return new File(destDir, uri + File.separator + getExtension(type));
  +    }
  +    
  +    boolean matchesExtention(String uri, String type) {
  +        int dotindex = uri.lastIndexOf('.');
  +        int slashindex = uri.indexOf('/', dotindex);
  +        if ((dotindex != -1) && (slashindex == -1)) {
  +            String ext = uri.substring(dotindex);
  +            return type.equals(getExtension(type));
  +        }
  +        return false;
       }
  +    
  +    String getExtension(String type) {
  +        if ("text/html".equals(type)) {
  +            return "html";
  +        } else if ("text/xml".equals(type)) {
  +            return "xml";
  +        } else if ("text/css".equals(type)) {
  +            return "css";
  +        } else if ("text/vnd.wap.wml".equals(type)) {
  +            return "wml";
  +        } else if ("image/jpg".equals(type)) {
  +            return "jpg";
  +        } else if ("image/png".equals(type)) {
  +            return "png";
  +        } else if ("image/gif".equals(type)) {
  +            return "gif";
  +        } else if ("image/svg-xml".equals(type)) {
  +            return "svg";
  +        } else if ("application/pdf".equals(type)) {
  +            return "pdf";
  +        } else if ("model/vrml".equals(type)) {
  +            return "wrl";
  +        } else if ("text/plain".equals(type)) {
  +            return "txt";
  +        } else if ("application/rtf".equals(type)) {
  +            return "rtf";
  +        } else if ("text/rtf".equals(type)) {
  +            return "rtf";
  +        } else if ("application/smil".equals(type)) {
  +            return "smil";
  +        } else if ("application/x-javascript".equals(type)) {
  +            return "js";
  +        } else if ("application/zip".equals(type)) {
  +            return "zip";
  +        } else if ("video/mpeg".equals(type)) {
  +            return "mpg";
  +        } else if ("video/quicktime".equals(type)) {
  +            return "mov";
  +        } else if ("audio/midi".equals(type)) {
  +            return "mid";
  +        } else if ("audio/mpeg".equals(type)) {
  +            return "mp3";
  +        } else {
  +            return "xxx";
  +        }
  +    }
  +    
   }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +1 -1      xml-cocoon/src/org/apache/cocoon/environment/Attic/AbstractEnvironment.java
  
  Index: AbstractEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/Attic/AbstractEnvironment.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- AbstractEnvironment.java	2000/09/02 21:12:35	1.1.2.4
  +++ AbstractEnvironment.java	2000/09/03 17:45:45	1.1.2.5
  @@ -105,7 +105,7 @@
       public String getView() {
           return this.view;
       }
  -    
  +
       // Response methods
   
       /**
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +21 -19    xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/FileSavingEnvironment.java
  
  Index: FileSavingEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/FileSavingEnvironment.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- FileSavingEnvironment.java	2000/08/31 15:56:56	1.1.2.2
  +++ FileSavingEnvironment.java	2000/09/03 17:45:46	1.1.2.3
  @@ -12,18 +12,24 @@
   import java.io.IOException;
   import java.io.OutputStream;
   import java.io.FileOutputStream;
  +
  +import java.util.Map;
  +
   import java.net.MalformedURLException;
  +
  +import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.environment.AbstractEnvironment;
   
   public class FileSavingEnvironment extends AbstractEnvironment {
   
  -    private File destDir;
  -    private String extention;
  -
  -    public FileSavingEnvironment(String uri, File context, File destDir)
  +    private String contentType;
  +    private OutputStream stream;
  +    
  +    public FileSavingEnvironment(String uri, File context, Map links, OutputStream stream)
       throws MalformedURLException {
  -        super(uri, null, context);
  -        this.destDir = destDir;
  +        super(uri, Cocoon.LINK_TRANSLATING_VIEW, context);
  +        this.stream = stream;
  +        this.objectModel.put(Cocoon.LINK_TRANSLATED_NAME, links);
       }
   
       /**
  @@ -37,25 +43,21 @@
        * Set the ContentType
        */
       public void setContentType(String contentType) {
  -        this.extention = getExtention(contentType);
  +        this.contentType = contentType;
  +    }
  +
  +    /**
  +     * Set the ContentType
  +     */
  +    public String getContentType() {
  +        return this.contentType;
       }
   
       /**
        * Get the OutputStream
        */
       public OutputStream getOutputStream() throws IOException {
  -        File file = new File(destDir, uri + "." + extention);
  -        return new FileOutputStream(file);
  -    }
  -    
  -    private String getExtention(String contentType) {
  -        if ("text/html".equals(contentType)) {
  -            return "html";
  -        } else if ("application/pdf".equals(contentType)) {
  -            return "pdf";
  -        } else {
  -            return "unknown";
  -        }
  +        return this.stream;
       }
   }
   
  
  
  
  1.1.2.2   +8 -4      xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/LinkSamplingEnvironment.java
  
  Index: LinkSamplingEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/LinkSamplingEnvironment.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- LinkSamplingEnvironment.java	2000/08/23 22:44:28	1.1.2.1
  +++ LinkSamplingEnvironment.java	2000/09/03 17:45:46	1.1.2.2
  @@ -10,13 +10,17 @@
   
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Collection;
   import java.util.Collections;
   import java.util.ArrayList;
  +
   import java.io.File;
   import java.io.IOException;
   import java.io.OutputStream;
   import java.io.ByteArrayOutputStream;
  +
   import java.net.MalformedURLException;
  +
   import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.environment.AbstractEnvironment;
   
  @@ -57,8 +61,8 @@
       /** 
        * Indicates if other links are present.
        */ 
  -    public Iterator getLinks() {
  -        return this.links.iterator();
  +    public Collection getLinks() {
  +        return this.links.list();
       }
       
       /**
  @@ -79,9 +83,9 @@
               }
           }
           
  -        public Iterator iterator() {
  +        public Collection list() {
               synchronized (links) {
  -                return links.iterator();
  +                return links;
               }
           }
       }
  
  
  

Mime
View raw message