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/util NetUtils.java StringUtils.java
Date Fri, 06 Oct 2000 21:25:33 GMT
stefano     00/10/06 14:25:33

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2 Constants.java
                        Main.java
               src/org/apache/cocoon/environment/commandline Tag:
                        xml-cocoon2 CommandLineRequest.java
                        FileSavingEnvironment.java
                        LinkSamplingEnvironment.java
               src/org/apache/cocoon/environment/http Tag: xml-cocoon2
                        HttpEnvironment.java
               src/org/apache/cocoon/generation Tag: xml-cocoon2
                        ServletGenerator.java
               src/org/apache/cocoon/matching Tag: xml-cocoon2
                        RegexpURIMatcherFactory.java
                        WildcardURIMatcherFactory.java
               src/org/apache/cocoon/reading Tag: xml-cocoon2
                        ResourceReader.java
               src/org/apache/cocoon/servlet Tag: xml-cocoon2
                        CocoonServlet.java
               src/org/apache/cocoon/sitemap Tag: xml-cocoon2
                        LinkTranslator.java
               src/org/apache/cocoon/transformation Tag: xml-cocoon2
                        XTTransformer.java XalanTransformer.java
               src/org/apache/cocoon/util Tag: xml-cocoon2 NetUtils.java
                        StringUtils.java
  Added:       src/org/apache/cocoon/environment/commandline Tag:
                        xml-cocoon2 AbstractCommandLineEnvironment.java
  Log:
  lots of important changes:
  
  1) fixed some major CLI design bugs.. now it works as it should
  2) added a few contants around instead of strings to enforce compile time checks
  3) some cleanup
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.8   +8 -2      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.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- Constants.java	2000/10/02 11:07:25	1.1.2.7
  +++ Constants.java	2000/10/06 21:25:27	1.1.2.8
  @@ -10,7 +10,7 @@
   
   /**
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/02 11:07:25 $
  + * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/10/06 21:25:27 $
    */
   
   public interface Constants {
  @@ -44,8 +44,14 @@
       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_OBJECT           = "links";
   
  +    public static final String REQUEST_OBJECT  = "request";
  +    public static final String RESPONSE_OBJECT = "response";
  +    public static final String CONTEXT_OBJECT  = "context";
  +    public static final String LINK_OBJECT     = "link";
  +    
  +    public static final String INDEX_URI = "index";
  +    
       public static final String CATALINA_SERVLET_CLASSPATH = "org.apache.catalina.jsp_classpath";
       public static final String TOMCAT_SERVLET_CLASSPATH = "org.apache.tomcat.jsp_classpath";
   
  
  
  
  1.1.4.12  +22 -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.11
  retrieving revision 1.1.4.12
  diff -u -r1.1.4.11 -r1.1.4.12
  --- Main.java	2000/10/02 11:07:26	1.1.4.11
  +++ Main.java	2000/10/06 21:25:27	1.1.4.12
  @@ -35,7 +35,7 @@
    * Command line entry point.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.4.11 $ $Date: 2000/10/02 11:07:26 $
  + * @version CVS $Revision: 1.1.4.12 $ $Date: 2000/10/06 21:25:27 $
    */
   
   public class Main {
  @@ -113,14 +113,14 @@
               File conf = getConfigurationFile(context);
               Main main = new Main(new Cocoon(conf, null, work.toString()), context, dest);
               log("Warming up...");
  -            log(" [Cocoon is compiling the sitemap, this might take a while]");
  +            log(" [Cocoon might need to compile the sitemaps, this might take a while]");
               main.warmup();
               log("...ready, let's go:");
               main.process(targets);
               log("Done");
           } catch (Exception e) {
               error("Exception caught (" + e.getClass().getName() + "): " + e.getMessage() + "\n");
  -            e.printStackTrace(System.err);
  +            e.printStackTrace();
           }
       }
   
  @@ -203,7 +203,6 @@
       private File destDir;
       private File context;
       private Map attributes;
  -    private Map parameters;
   
       /**
        * Creates the Main class
  @@ -213,14 +212,13 @@
           this.context = context;
           this.destDir = destDir;
           this.attributes = new HashMap();
  -        this.parameters = new HashMap();
       }
   
       /**
        * Warms up the engine by accessing the root.
        */
       public void warmup() throws Exception {
  -        cocoon.process(new LinkSamplingEnvironment("/", context, attributes, parameters));
  +        cocoon.process(new LinkSamplingEnvironment("/", context, attributes, null));
       }
   
       /**
  @@ -229,8 +227,7 @@
       public void process(Collection uris) throws Exception {
           Iterator i = uris.iterator();
           while (i.hasNext()) {
  -            String uri = (String) i.next();
  -            this.processURI(uri, uri, 0);
  +            this.processURI(NetUtils.normalize((String) i.next()), 0);
           }
       }
   
  @@ -247,12 +244,12 @@
        *      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 
  -     *      consistency with the URI and, if the extention is inconsistent
  +     *      consistency with the URI and, if the extension is inconsistent
        *      or absent, the file is renamed</li>
        *  <li>then the file name of the translated URI is returned</li>
        * </ul>
        */
  -    public String processURI(String uri, String origUri, int level) throws Exception {
  +    public String processURI(String uri, int level) throws Exception {
           log(leaf(level) + uri);
   
           Collection links = this.getLinks(uri);
  @@ -260,9 +257,12 @@
           Iterator i = links.iterator();
           while (i.hasNext()) {
               log(tree(level));
  -            String origLink = (String) i.next();
  -            String link = NetUtils.normalizeURI(NetUtils.adjustContext(uri, origLink));
  -            translatedLinks.put(link, this.processURI(link, origLink, level + 1));
  +            String path = NetUtils.getPath(uri);
  +            String relativeLink = (String) i.next();
  +            String absoluteLink = NetUtils.normalize(NetUtils.absolutize(path, relativeLink));
  +            String translatedAbsoluteLink = this.processURI(absoluteLink, level + 1);
  +            String translatedRelativeLink = NetUtils.relativize(path, translatedAbsoluteLink);
  +            translatedLinks.put(relativeLink, translatedRelativeLink);
           }
           
           String filename = mangle(uri);
  @@ -271,14 +271,14 @@
           String type = getPage(uri, translatedLinks, output);
           output.close();
   
  -        String ext = NetUtils.getExtension(uri);
  +        String ext = NetUtils.getExtension(filename);
           String defaultExt = MIMEUtils.getDefaultExtension(type);
           
           if ((ext == null) || (!ext.equals(defaultExt))) {
               filename += defaultExt;
  -            origUri += defaultExt;
               File newFile = IOUtils.createFile(destDir, filename);
               file.renameTo(newFile);
  +            file = newFile;
           }
   
           log(tree(level));
  @@ -290,7 +290,7 @@
               log(leaf(level + 1) + "[" + type + "]--> " + filename);
           }
           
  -        return mangle(origUri);
  +        return filename;
       }        
   
       void resourceUnavailable(File file) throws IOException {
  @@ -306,6 +306,7 @@
       }
       
       String mangle(String uri) {
  +        if (uri.charAt(uri.length() - 1) == '/') uri += Cocoon.INDEX_URI;
           uri = uri.replace('"', '\'');
           return uri.replace('?','_');
       }
  @@ -324,12 +325,16 @@
       }
       
       Collection getLinks(String uri) throws Exception {
  -        LinkSamplingEnvironment env = new LinkSamplingEnvironment(uri, context, attributes, parameters);
  +        HashMap parameters = new HashMap();
  +        String deparameterizedURI = NetUtils.deparameterize(uri, parameters);
  +        LinkSamplingEnvironment env = new LinkSamplingEnvironment(deparameterizedURI, context, attributes, parameters);
           cocoon.process(env);
           return env.getLinks();
       }
   
       String getPage(String uri, Map links, OutputStream stream) throws Exception {
  +        HashMap parameters = new HashMap();
  +        String deparameterizedURI = NetUtils.deparameterize(uri, parameters);
           FileSavingEnvironment env = new FileSavingEnvironment(uri, context, attributes, parameters, links, stream);
           cocoon.process(env);
           return env.getContentType();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +13 -5     xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/CommandLineRequest.java
  
  Index: CommandLineRequest.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/CommandLineRequest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- CommandLineRequest.java	2000/10/02 11:07:29	1.1.2.1
  +++ CommandLineRequest.java	2000/10/06 21:25:27	1.1.2.2
  @@ -29,7 +29,7 @@
    * Creates a specific servlet request simulation from command line usage.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2000/10/02 11:07:29 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/10/06 21:25:27 $
    */
   
   /*
  @@ -111,7 +111,9 @@
       public Enumeration getParameterNames() { 
           return (parameters != null) ? new IteratorWrapper(parameters.keySet().iterator()) : null;
       }
  -    public String[] getParameterValues(String name) { return null; } // FIXME
  +    public String[] getParameterValues(String name) { 
  +        throw new RuntimeException (this.getClass().getName() + ".getParameterValues(String name) method not yet implemented!");
  +    } // FIXME
   
       public String getHeader(String name) { 
           return (headers != null) ? (String) headers.get(name) : null;
  @@ -120,8 +122,12 @@
           String header = (headers != null) ? (String) headers.get(name) : null;
           return (header != null) ? Integer.parseInt(header) : -1;
       }
  -    public long getDateHeader(String name) { return -1; } // FIXME
  -    public Enumeration getHeaders(String name) { return null; } // FIXME
  +    public long getDateHeader(String name) { 
  +        throw new RuntimeException (this.getClass().getName() + ".getDateHeader(String name) method not yet implemented!");
  +    } // FIXME
  +    public Enumeration getHeaders(String name) { 
  +        throw new RuntimeException (this.getClass().getName() + ".getHeaders(String name) method not yet implemented!");
  +    } // FIXME
       public Enumeration getHeaderNames() {
           return (headers != null) ? new IteratorWrapper(headers.keySet().iterator()) : null;
       }
  @@ -150,7 +156,9 @@
       public boolean isRequestedSessionIdFromURL() { return false; }
   
       public Locale getLocale() { return Locale.getDefault(); }
  -    public Enumeration getLocales() { return null; } //FIXME
  +    public Enumeration getLocales() {
  +        throw new RuntimeException (this.getClass().getName() + ".getLocales() method not yet implemented!");
  +    } // FIXME
   
       public String getAuthType() { return null; }
       public boolean isSecure() { return false; }
  
  
  
  1.1.2.7   +5 -37     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.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- FileSavingEnvironment.java	2000/10/02 11:07:29	1.1.2.6
  +++ FileSavingEnvironment.java	2000/10/06 21:25:28	1.1.2.7
  @@ -24,49 +24,17 @@
    * This environment is used to save the requested file to disk.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/10/02 11:07:29 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/06 21:25:28 $
    */
   
  -public class FileSavingEnvironment extends AbstractEnvironment {
  +public class FileSavingEnvironment extends AbstractCommandLineEnvironment {
   
  -    private String contentType;
  -    private OutputStream stream;
  -    
       public FileSavingEnvironment(String uri, File context, Map attributes, Map parameters, Map links, OutputStream stream)
       throws MalformedURLException {
  -        super(uri, null, context);
  -        this.stream = stream;
  +        super(uri, null, context, stream);
           this.objectModel.put(Cocoon.LINK_OBJECT, links);
  -        this.objectModel.put("request", new CommandLineRequest(null, uri, null, attributes, parameters));
  -        this.objectModel.put("response", new CommandLineResponse());
  -    }
  -
  -    /**
  -     * Redirect the client to a new URL
  -     */
  -    public void redirect(String newURL) throws IOException {
  -        // FIXME (SM) What do we do here?
  -    }
  -    
  -    /**
  -     * Set the ContentType
  -     */
  -    public void setContentType(String contentType) {
  -        this.contentType = contentType;
  -    }
  -
  -    /**
  -     * Set the ContentType
  -     */
  -    public String getContentType() {
  -        return this.contentType;
  -    }
  -
  -    /**
  -     * Get the OutputStream
  -     */
  -    public OutputStream getOutputStream() throws IOException {
  -        return this.stream;
  +        this.objectModel.put(Cocoon.REQUEST_OBJECT, new CommandLineRequest(null, uri, null, attributes, parameters));
  +        this.objectModel.put(Cocoon.RESPONSE_OBJECT, new CommandLineResponse());
       }
   }
   
  
  
  
  1.1.2.7   +13 -23    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.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- LinkSamplingEnvironment.java	2000/10/02 11:07:29	1.1.2.6
  +++ LinkSamplingEnvironment.java	2000/10/06 21:25:28	1.1.2.7
  @@ -23,30 +23,28 @@
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   
  -
   import java.net.MalformedURLException;
   
  -import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.Main;
  +import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.environment.AbstractEnvironment;
   
   /**
    * This environment is sample the links of the resource.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/10/02 11:07:29 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/10/06 21:25:28 $
    */
   
  -public class LinkSamplingEnvironment extends AbstractEnvironment {
  +public class LinkSamplingEnvironment extends AbstractCommandLineEnvironment {
   
       private boolean skip = false;
  -    private ByteArrayOutputStream stream = new ByteArrayOutputStream();
       
       public LinkSamplingEnvironment(String uri, File contextFile, Map attributes, Map parameters) 
       throws MalformedURLException, IOException {
  -        super(uri, Cocoon.LINK_VIEW, contextFile);
  -        this.objectModel.put("request", new CommandLineRequest(null, uri, null, attributes, parameters));
  -        this.objectModel.put("response", new CommandLineResponse());
  +        super(uri, Cocoon.LINK_VIEW, contextFile, new ByteArrayOutputStream());
  +        this.objectModel.put(Cocoon.REQUEST_OBJECT, new CommandLineRequest(null, uri, null, attributes, parameters));
  +        this.objectModel.put(Cocoon.RESPONSE_OBJECT, new CommandLineResponse());
       }
   
       /** 
  @@ -59,26 +57,18 @@
       }
    
       /** 
  -     * Get the OutputStream 
  -     */ 
  -    public OutputStream getOutputStream() throws IOException {
  -        return this.stream;
  -    }
  -
  -    /**
  -     * Redirect the client to a new URL
  -     */
  -    public void redirect(String newURL) throws IOException {
  -        // FIXME (SM) What do we do here?
  -    }
  -
  -    /** 
        * Indicates if other links are present.
        */ 
       public Collection getLinks() throws IOException {
           ArrayList list = new ArrayList();
           if (!skip) {
  -            BufferedReader buffer = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(stream.toByteArray())));
  +            BufferedReader buffer = new BufferedReader(
  +                new InputStreamReader(
  +                    new ByteArrayInputStream(
  +                        ((ByteArrayOutputStream) stream).toByteArray()
  +                    )
  +                )
  +            );
               while (true) {
                   String line = buffer.readLine();
                   if (line == null) break;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +66 -0     xml-cocoon/src/org/apache/cocoon/environment/commandline/Attic/AbstractCommandLineEnvironment.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.15  +5 -4      xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java
  
  Index: HttpEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java,v
  retrieving revision 1.1.2.14
  retrieving revision 1.1.2.15
  diff -u -r1.1.2.14 -r1.1.2.15
  --- HttpEnvironment.java	2000/10/02 11:07:30	1.1.2.14
  +++ HttpEnvironment.java	2000/10/06 21:25:28	1.1.2.15
  @@ -19,6 +19,7 @@
   import javax.servlet.http.HttpServletRequest; 
   import javax.servlet.http.HttpServletResponse;
   
  +import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.environment.AbstractEnvironment; 
    
   import org.xml.sax.InputSource; 
  @@ -48,16 +49,16 @@
                               HttpServletResponse response, 
                               ServletContext servletContext) 
       throws MalformedURLException, IOException {
  -        super(uri, request.getParameter("cocoon-view"), servletContext.getRealPath("/"));
  +        super(uri, request.getParameter(Cocoon.VIEW_PARAM), servletContext.getRealPath("/"));
           this.request = new HttpRequest (request, this);
           this.servletRequest = request;
           this.response = new HttpResponse (response);
           this.servletResponse = response;
           this.servletContext = servletContext; 
           this.outputStream = response.getOutputStream();
  -        this.objectModel.put("request", this.request);
  -        this.objectModel.put("response", this.response);
  -        this.objectModel.put("context", this.servletContext);
  +        this.objectModel.put(Cocoon.REQUEST_OBJECT, this.request);
  +        this.objectModel.put(Cocoon.RESPONSE_OBJECT, this.response);
  +        this.objectModel.put(Cocoon.CONTEXT_OBJECT, this.servletContext);
       }
   
       /**
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +6 -4      xml-cocoon/src/org/apache/cocoon/generation/Attic/ServletGenerator.java
  
  Index: ServletGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/ServletGenerator.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ServletGenerator.java	2000/09/02 21:12:36	1.1.2.2
  +++ ServletGenerator.java	2000/10/06 21:25:29	1.1.2.3
  @@ -17,12 +17,14 @@
   import org.apache.avalon.ComponentManager;
   import org.apache.avalon.utils.Parameters;
   
  +import org.apache.cocoon.Cocoon;
  +
   import org.xml.sax.EntityResolver;
   
   /**
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/09/02 21:12:36 $
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/10/06 21:25:29 $
    */
   public abstract class ServletGenerator extends ComposerGenerator
   implements Composer {
  @@ -33,8 +35,8 @@
   
       public void setup(EntityResolver resolver, Map objectModel, String src, Parameters par) {
         super.setup(resolver, objectModel, src, par);
  -      this.request = (HttpServletRequest) objectModel.get("request");
  -      this.response = (HttpServletResponse) objectModel.get("response");
  -      this.context = (ServletContext) objectModel.get("context");
  +      this.request = (HttpServletRequest) objectModel.get(Cocoon.REQUEST_OBJECT);
  +      this.response = (HttpServletResponse) objectModel.get(Cocoon.RESPONSE_OBJECT);
  +      this.context = (ServletContext) objectModel.get(Cocoon.CONTEXT_OBJECT);
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.9   +2 -2      xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java
  
  Index: RegexpURIMatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/RegexpURIMatcherFactory.java,v
  retrieving revision 1.1.2.8
  retrieving revision 1.1.2.9
  diff -u -r1.1.2.8 -r1.1.2.9
  --- RegexpURIMatcherFactory.java	2000/10/02 11:07:31	1.1.2.8
  +++ RegexpURIMatcherFactory.java	2000/10/06 21:25:29	1.1.2.9
  @@ -20,7 +20,7 @@
    * for request URIs
    * 
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/10/02 11:07:31 $ 
  + * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/10/06 21:25:29 $ 
    */ 
   
   public class RegexpURIMatcherFactory implements MatcherFactory {
  @@ -70,7 +70,7 @@
           String instructions = name + "PatternInstructions";
           String pat = correctPattern (pattern);
           sb.append("java.util.ArrayList list = new java.util.ArrayList ();")
  -          .append("if(").append(name).append("Pattern.match(((javax.servlet.http.HttpServletRequest)objectModel.get(\"request\")).getRequestURI())) {");
  +          .append("if(").append(name).append("Pattern.match(((javax.servlet.http.HttpServletRequest)objectModel.get(org.apache.cocoon.Cocoon.REQUEST_OBJECT)).getRequestURI())) {");
           // Count number of parens
           int i = 0;
           int j = -1;
  
  
  
  1.1.2.14  +2 -2      xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java
  
  Index: WildcardURIMatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java,v
  retrieving revision 1.1.2.13
  retrieving revision 1.1.2.14
  diff -u -r1.1.2.13 -r1.1.2.14
  --- WildcardURIMatcherFactory.java	2000/10/02 11:07:31	1.1.2.13
  +++ WildcardURIMatcherFactory.java	2000/10/06 21:25:29	1.1.2.14
  @@ -18,7 +18,7 @@
    * 
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a> 
  - * @version CVS $Revision: 1.1.2.13 $ $Date: 2000/10/02 11:07:31 $ 
  + * @version CVS $Revision: 1.1.2.14 $ $Date: 2000/10/06 21:25:29 $ 
    */ 
   
   public class WildcardURIMatcherFactory implements MatcherFactory {
  @@ -45,7 +45,7 @@
       throws ConfigurationException {
           StringBuffer result = new StringBuffer();
           return result.append ("java.util.ArrayList list = new ArrayList();")
  -                     .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (list,((javax.servlet.http.HttpServletRequest)objectModel.get(\"request\")).getRequestURI(), ")
  +                     .append ("if (org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (list,((javax.servlet.http.HttpServletRequest)objectModel.get(org.apache.cocoon.Cocoon.REQUEST_OBJECT)).getRequestURI(), ")
                        .append(prefix).append("_expr))")
                        .append ("return list;")
                        .append ("else return null;").toString();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +4 -3      xml-cocoon/src/org/apache/cocoon/reading/Attic/ResourceReader.java
  
  Index: ResourceReader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/reading/Attic/ResourceReader.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- ResourceReader.java	2000/09/02 21:12:38	1.1.2.4
  +++ ResourceReader.java	2000/10/06 21:25:30	1.1.2.5
  @@ -18,6 +18,7 @@
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.ServletContext;
   
  +import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.ProcessingException;
   
   import org.xml.sax.SAXException;
  @@ -25,7 +26,7 @@
   /**
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/09/02 21:12:38 $
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/10/06 21:25:30 $
    */
   public class ResourceReader extends AbstractReader {
   
  @@ -33,7 +34,7 @@
        * Generates the requested resource.
        */
       public void generate() throws IOException, ProcessingException {
  -        HttpServletResponse res = (HttpServletResponse) objectModel.get("response");
  +        HttpServletResponse res = (HttpServletResponse) objectModel.get(Cocoon.RESPONSE_OBJECT);
           if (res == null) {
              throw new ProcessingException ("Missing a Response object in the objectModel");
           }
  @@ -57,7 +58,7 @@
           fis.close();
           res.setContentLength(buffer.length);
           res.setDateHeader("Last-Modified", file.lastModified());
  -        res.setHeader("Accept-Ranges","bytes");
  +        res.setHeader("Accept-Ranges", "bytes");
           out.write ( buffer );
       }
       /**
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.4.23  +63 -93    xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java,v
  retrieving revision 1.1.4.22
  retrieving revision 1.1.4.23
  diff -u -r1.1.4.22 -r1.1.4.23
  --- CocoonServlet.java	2000/09/22 22:17:59	1.1.4.22
  +++ CocoonServlet.java	2000/10/06 21:25:31	1.1.4.23
  @@ -40,11 +40,15 @@
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
    * @author <a href="mailto:nicolaken@supereva.it">Nicola Ken Barozzi</a> Aisa
  - * @version CVS $Revision: 1.1.4.22 $ $Date: 2000/09/22 22:17:59 $
  + * @version CVS $Revision: 1.1.4.23 $ $Date: 2000/10/06 21:25:31 $
    */
    
   public class CocoonServlet extends HttpServlet {
   
  +    final long second = 1000;
  +    final long minute = 60 * second;
  +    final long hour   = 60 * minute;
  +
       private long creationTime = 0;
       private Cocoon cocoon;
       private File configFile;
  @@ -62,7 +66,8 @@
   
           this.context = conf.getServletContext();
   
  -        // WARNING (SM): the line below BREAKS the Servlet API compatibility
  +        // WARNING (SM): the line below BREAKS the Servlet API portability of
  +        // web applications.
           // This is a hack to go around java compiler design problems that 
           // do not allow applications to force their own classloader to the
           // compiler during compilation.
  @@ -72,8 +77,13 @@
           // container classloading will break it on other servlet containers.
           // To fix this, Javac must be redesigned and rewritten or we have to
           // write our own compiler.
  -        // For now we tie ourselves to Tomcat but at least we can work without
  -        // placing everything in the system classpath.
  +        // So, for now, the cocoon.war file with included libraries can work
  +        // only in Tomcat or in containers that simulate this context attribute
  +        // (I don't know if any do) or, for other servlet containers, you have
  +        // to extract all the libraries and place them in the system classpath
  +        // or the compilation of sitemaps and XSP will fail.
  +        // I know this sucks, but I don't have the energy to write a java 
  +        // compiler to fix this :(
           this.classpath = (String) context.getAttribute(Cocoon.CATALINA_SERVLET_CLASSPATH);
           if (this.classpath == null) {
               this.classpath = (String) context.getAttribute(Cocoon.TOMCAT_SERVLET_CLASSPATH);
  @@ -104,8 +114,7 @@
       public void service(HttpServletRequest req, HttpServletResponse res)
               throws ServletException, IOException {
   
  -        long start = new Date().getTime();
  -        long end   = 0;
  +        long start = System.currentTimeMillis();
   
           // Reload cocoon if configuration changed or we are reloading
           boolean reloaded = false;
  @@ -114,21 +123,15 @@
               if (this.cocoon != null) {
                   if (this.cocoon.modifiedSince(this.creationTime)) {
                       this.context.log("Configuration changed reload attempt");
  -
                       this.cocoon = this.create();
                       reloaded    = true;
  -                } else if ((req.getPathInfo() == null)
  -                           && (req.getParameter(Cocoon.RELOAD_PARAM)
  -                               != null)) {
  +                } else if ((req.getPathInfo() == null) && (req.getParameter(Cocoon.RELOAD_PARAM) != null)) {
                       this.context.log("Forced reload attempt");
  -
                       this.cocoon = this.create();
                       reloaded    = true;
                   }
  -            } else if ((req.getPathInfo() == null)
  -                       && (req.getParameter(Cocoon.RELOAD_PARAM) != null)) {
  +            } else if ((req.getPathInfo() == null) && (req.getParameter(Cocoon.RELOAD_PARAM) != null)) {
                   this.context.log("Invalid configurations reload");
  -
                   this.cocoon = this.create();
                   reloaded    = true;
               }
  @@ -153,59 +156,37 @@
           // We got it... Process the request
           String uri =  req.getServletPath();
           String pathInfo = req.getPathInfo();
  -        if (pathInfo != null) uri += "/" + pathInfo;
  +        if (pathInfo != null) uri += pathInfo;
   
  -        if (!uri.equals("")) {
  -            try {
  -                if (uri.charAt(0) == '/') {
  -                    uri = uri.substring(1);
  -                }
  -
  -                HttpEnvironment env = new HttpEnvironment(uri, req, res,
  -                                                          context);
  +        try {
  +            if (uri.charAt(0) == '/') uri = uri.substring(1);
   
  -                if (!this.cocoon.process(env)) {
  +            HttpEnvironment env = new HttpEnvironment(uri, req, res, context);
   
  -                    //-----> FIXME (NKB) It is not true that!this.cocoon.process(env) means only SC_NOT_FOUND!
  -                    res.setStatus(res.SC_NOT_FOUND);
  +            if (!this.cocoon.process(env)) {
   
  -                    Notification n = new Notification(this);
  -                    n.setType("resource-not-found");
  -                    n.setTitle("Resource not found");
  -                    n.setSource("Cocoon servlet");
  -                    n.setMessage("Resource not found");
  -                    n.setDescription("The requested URI \""
  -                                     + req.getRequestURI()
  -                                     + "\" was not found.");
  -                    n.addExtraDescription("request-uri", req.getRequestURI());
  -                    n.addExtraDescription("path-info", uri);
  -                    Notifier.notify(n, req, res);
  -                }
  -            } catch (Exception e) {
  +                // FIXME (NKB) It is not true that !this.cocoon.process(env) 
  +                // means only SC_NOT_FOUND
  +                res.setStatus(res.SC_NOT_FOUND);
   
  -                //res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
  -                Notification n = new Notification(this, e);
  -                n.setType("internal-server-error");
  -                n.setTitle("Internal server error");
  +                Notification n = new Notification(this);
  +                n.setType("resource-not-found");
  +                n.setTitle("Resource not found");
                   n.setSource("Cocoon servlet");
  +                n.setMessage("Resource not found");
  +                n.setDescription("The requested URI \""
  +                                 + req.getRequestURI()
  +                                 + "\" was not found.");
                   n.addExtraDescription("request-uri", req.getRequestURI());
                   n.addExtraDescription("path-info", uri);
                   Notifier.notify(n, req, res);
               }
  -        } else {
  -            Notification n = new Notification(this);
  -            n.setType("information");
  -            n.setTitle(Cocoon.VERSION + "  :)");
  +        } catch (Exception e) {
  +            //res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
  +            Notification n = new Notification(this, e);
  +            n.setType("internal-server-error");
  +            n.setTitle("Internal server error");
               n.setSource("Cocoon servlet");
  -            n.setMessage("Ready to process requests...");
  -
  -            String OkDescription = "Ready to process requests...";
  -
  -            if (reloaded) {
  -                OkDescription += "configurations reloaded.";
  -            }
  -
  -            n.setDescription(OkDescription);
               n.addExtraDescription("request-uri", req.getRequestURI());
               n.addExtraDescription("path-info", uri);
               Notifier.notify(n, req, res);
  @@ -213,51 +194,18 @@
   
           ServletOutputStream out = res.getOutputStream();
   
  -        end = new Date().getTime();
  +        long end = System.currentTimeMillis();
   
           String showTime = req.getParameter(Cocoon.SHOWTIME_PARAM);
  -
  -        if ((showTime != null) &&!showTime.equalsIgnoreCase("no")) {
  -            float time   = (float) (end - start);
  -            float second = (float) 1000;
  -            float minute = (float) 60 * second;
  -            float hour   = (float) 60 * minute;
  -
  -            if (showTime.equalsIgnoreCase("hide")) {
  -                out.print("<!-- ");
  -            } else {
  -                out.print("<p>");
  -            }
  -
  -            out.print("Processed by Cocoon " + Cocoon.VERSION + " in ");
   
  -            if (time > hour) {
  -                out.print(time / hour);
  -                out.print(" hours.");
  -            } else if (time > minute) {
  -                out.print(time / minute);
  -                out.print(" minutes.");
  -            } else if (time > second) {
  -                out.print(time / second);
  -                out.print(" seconds.");
  -            } else {
  -                out.print(time);
  -                out.print(" milliseconds.");
  -            }
  -
  -            if (showTime.equalsIgnoreCase("hide")) {
  -                out.print("-->");
  -            } else {
  -                out.print("</p>");
  -            }
  +        if ((showTime != null) && !showTime.equalsIgnoreCase("no")) {
  +            showTime(out, showTime.equalsIgnoreCase("hide"), end - start);
           }
   
           out.flush();
       }
   
  -    /** Create a new <code>Cocoon</code> object. */
       private Cocoon create() {
  -
           try {
               this.context.log("Reloading from: " + this.configFile);
               Cocoon c = new Cocoon(this.configFile, this.classpath, this.workDir);
  @@ -266,9 +214,31 @@
           } catch (Exception e) {
               this.context.log("Exception reloading: " + e.getMessage());
               this.exception = e;
  +            return null;
  +        }
  +    }
  +    
  +    private void showTime(ServletOutputStream out, boolean hide, long time) throws IOException {
  +        
  +        out.print((hide) ? "<!-- " : "<p>");
  +
  +        out.print("Processed by " + Cocoon.COMPLETE_NAME + " in ");
  +
  +        if (time > hour) {
  +            out.print(time / hour);
  +            out.print(" hours.");
  +        } else if (time > minute) {
  +            out.print(time / minute);
  +            out.print(" minutes.");
  +        } else if (time > second) {
  +            out.print(time / second);
  +            out.print(" seconds.");
  +        } else {
  +            out.print(time);
  +            out.print(" milliseconds.");
           }
   
  -        return (null);
  +        out.println((hide) ? " -->" : "</p>");
       }
   }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.10  +12 -9     xml-cocoon/src/org/apache/cocoon/sitemap/Attic/LinkTranslator.java
  
  Index: LinkTranslator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/LinkTranslator.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- LinkTranslator.java	2000/10/01 00:18:03	1.1.2.9
  +++ LinkTranslator.java	2000/10/06 21:25:31	1.1.2.10
  @@ -14,6 +14,8 @@
   
   import java.util.Map;
   
  +import javax.servlet.http.HttpServletRequest;
  +
   import org.xml.sax.SAXException;
   import org.xml.sax.Attributes;
   import org.xml.sax.EntityResolver;
  @@ -24,16 +26,17 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.xml.xlink.ExtendedXLinkPipe;
   import org.apache.cocoon.transformation.Transformer;
  +import org.apache.cocoon.util.NetUtils;
   
   /**
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/10/01 00:18:03 $
  + * @version CVS $Revision: 1.1.2.10 $ $Date: 2000/10/06 21:25:31 $
    */
   
   public class LinkTranslator extends ExtendedXLinkPipe implements Transformer {
   
       private Map links;
  -    
  +
       /**
        * Set the <code>EntityResolver</code>, objectModel <code>Map</code>,
        * the source and sitemap <code>Parameters</code> used to process the request.
  @@ -42,16 +45,16 @@
       throws ProcessingException, SAXException, IOException {
           this.links = (Map) objectModel.get(Cocoon.LINK_OBJECT);
       }
  -    
  -    public void simpleLink(String href, String role, String arcrole, String title, String show, String actuate, String uri, String name, String raw, Attributes attr) 
  +
  +    public void simpleLink(String href, String role, String arcrole, String title, String show, String actuate, String uri, String name, String raw, Attributes attr)
       throws SAXException {
  -        String newhref = (String) this.links.get(href);
  -        super.simpleLink((newhref != null) ? newhref : href, role, arcrole, title, show, actuate, uri, name, raw, attr);
  +        String newHref = (String) this.links.get(href);
  +        super.simpleLink((newHref != null) ? newHref : href, role, arcrole, title, show, actuate, uri, name, raw, attr);
       }
  -    
  +
       public void startLocator(String href, String role, String title, String label, String uri, String name, String raw, Attributes attr)
       throws SAXException {
  -        String newhref = (String) this.links.get(href);
  -        super.startLocator((newhref != null) ? newhref : href, role, title, label, uri, name, raw, attr);
  +        String newHref = (String) this.links.get(href);
  +        super.startLocator((newHref != null) ? newHref : href, role, title, label, uri, name, raw, attr);
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +3 -2      xml-cocoon/src/org/apache/cocoon/transformation/Attic/XTTransformer.java
  
  Index: XTTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/XTTransformer.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- XTTransformer.java	2000/09/27 16:16:22	1.1.2.2
  +++ XTTransformer.java	2000/10/06 21:25:32	1.1.2.3
  @@ -22,6 +22,7 @@
   import org.apache.avalon.Modifiable;
   import org.apache.avalon.utils.Parameters;
   
  +import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.xml.XMLConsumer;
   import org.apache.cocoon.xml.DocumentHandlerAdapter;
  @@ -65,7 +66,7 @@
    * This Transformer use the XT processor.
    * 
    * @author <a href="mailto:ssahuc@imediation.com">Sahuc Sebastien</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/09/27 16:16:22 $
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/10/06 21:25:32 $
    */
   public class XTTransformer extends DocumentHandlerWrapper
   implements Transformer, Composer {
  @@ -96,7 +97,7 @@
       throws SAXException, ProcessingException, IOException {
   
           /** The Request object */
  -        HttpServletRequest request = (HttpServletRequest) objectModel.get("request");
  +        HttpServletRequest request = (HttpServletRequest) objectModel.get(Cocoon.REQUEST_OBJECT);
           if (request == null) {
               throw new ProcessingException ("Missing request object in objectModel");
           }
  
  
  
  1.1.2.10  +2 -2      xml-cocoon/src/org/apache/cocoon/transformation/Attic/XalanTransformer.java
  
  Index: XalanTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/transformation/Attic/XalanTransformer.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- XalanTransformer.java	2000/09/27 16:16:24	1.1.2.9
  +++ XalanTransformer.java	2000/10/06 21:25:32	1.1.2.10
  @@ -41,7 +41,7 @@
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/09/27 16:16:24 $
  + * @version CVS $Revision: 1.1.2.10 $ $Date: 2000/10/06 21:25:32 $
    */
   public class XalanTransformer extends DocumentHandlerWrapper
   implements Transformer, Composer {
  @@ -69,7 +69,7 @@
       throws SAXException, ProcessingException, IOException {
   
           /** The Request object */
  -        HttpServletRequest request = (HttpServletRequest) objectModel.get("request");
  +        HttpServletRequest request = (HttpServletRequest) objectModel.get(Cocoon.REQUEST_OBJECT);
   
           // Check the stylesheet uri
           String xsluri = src;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +141 -62   xml-cocoon/src/org/apache/cocoon/util/Attic/NetUtils.java
  
  Index: NetUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/util/Attic/NetUtils.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- NetUtils.java	2000/10/02 11:07:33	1.1.2.1
  +++ NetUtils.java	2000/10/06 21:25:32	1.1.2.2
  @@ -9,6 +9,7 @@
   package org.apache.cocoon.util;
   
   import java.io.File;
  +import java.util.Map;
   import java.net.URL;
   import java.net.MalformedURLException;
   
  @@ -17,13 +18,13 @@
    * utility methods
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2000/10/02 11:07:33 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/10/06 21:25:32 $
    */
   
   public class NetUtils {
   
       /**
  -     Create a URL from a location. This method supports the
  +     * Create a URL from a location. This method supports the
        * <i>resource://</i> pseudo-protocol for loading resources
        * accessible to this same class' <code>ClassLoader</code>
        *
  @@ -44,70 +45,17 @@
       }
   
       /**
  -     * Adjusts the context the location of the child depending on the
  -     * parent context.
  +     * Returns the path of the given resource.
        *
  -     * @param parentURI the parent context
  -     * @param childURI the context child
  -     * @return The location with the adjusted context
  -     */
  -    public static String adjustContext(String parentURI, String childURI) {
  -        if (childURI.charAt(0) != '/') {
  -            int lastSlash = parentURI.lastIndexOf('/');
  -            if (lastSlash > -1) {
  -                return parentURI.substring(0, lastSlash + 1) + childURI;
  -            } else {
  -                return childURI;
  -            }
  -        } else {
  -            return childURI;
  -        }
  -    }
  -
  -    /**
  -     * Normalize a uri containing ../ and ./ paths (the leading .. or . are 
  -     * left unchanged)
  -     *
  -     * @param uri The uri path to normalize
  -     * @return The normalized uri
  +     * @path the resource
  +     * @return the resource path
        */
  -    public static String normalizeURI(String uri) {
  -        String[] dirty = StringUtils.split(uri, "/");
  -        int length = dirty.length;
  -        String[] clean = new String[length];
  -
  -        boolean stillDirty;
  -        do {
  -            stillDirty = false;
  -            for (int i = 0, j = 0; (i < length) && (dirty[i] != null); i++) {
  -                if (!".".equals(dirty[i])) {
  -                    if ("..".equals(dirty[i])) {
  -                        stillDirty = true;
  -                    } else if ((i+1 < length) && ("..".equals(dirty[i+1]))) {
  -                        i += 2;
  -                    }
  -                    clean[j++] = dirty[i];
  -                }
  -            }
  -            dirty = clean;
  -            clean = new String[length];
  -        } while (stillDirty);
  -
  -        StringBuffer b = new StringBuffer(uri.length());
  -        
  -        for (int i = 0; (i < length) && (dirty[i] != null); i++) {
  -            b.append(dirty[i]);
  -            if ((i+1 < length) && (dirty[i+1] != null)) b.append("/");
  -        }
  -        
  -        return b.toString();
  +    public static String getPath(String uri) {
  +        int i = uri.lastIndexOf('/');
  +        return (i > -1) ? uri.substring(0, i) : "";
       }
   
  -    public static void main (String[] a) {
  -        System.out.println(a[0] + " ---> " + normalizeURI(a[0]));
  -    }
  -    
  -    /**
  +   /**
       * Remove path and file information from a filename returning only its
       * extension  component
       *
  @@ -137,5 +85,136 @@
           } else {
               return null;
           }
  +    }
  +
  +    /**
  +     * Absolutize a relative resource on the given absolute path.
  +     *
  +     * @path the absolute path
  +     * @relativeResource the relative resource
  +     * @return the absolutized resource
  +     */
  +    public static String absolutize(String path, String relativeResource) {
  +        if (("".equals(path)) || (path == null)) return relativeResource;
  +        if (relativeResource.charAt(0) != '/') {
  +            int length = path.length() - 1;
  +            boolean slashPresent = (path.charAt(length) == '/');
  +            StringBuffer b = new StringBuffer();
  +            b.append(path);
  +            if (!slashPresent) b.append('/');
  +            b.append(relativeResource);
  +            return b.toString();
  +        } else {
  +            // resource is already absolute
  +            return relativeResource;
  +        }
  +    }
  +
  +    /**
  +     * Relativize an absolute resource on a given absolute path.
  +     *
  +     * @path the absolute path
  +     * @relativeResource the absolute resource
  +     * @return the resource relative to the given path
  +     */
  +    public static String relativize(String path, String absoluteResource) {
  +        if (("".equals(path)) || (path == null)) return absoluteResource;
  +        int length = path.length() - 1;
  +        boolean slashPresent = path.charAt(length) == '/';
  +        if (absoluteResource.startsWith(path)) {
  +            // resource is direct descentant
  +            return absoluteResource.substring(length + (slashPresent ? 1 : 2));
  +        } else {
  +            // resource is not direct descendant
  +            if (!slashPresent) path += "/";
  +            int index = StringUtils.matchStrings(path, absoluteResource);
  +            String pathDiff = path.substring(index);
  +            String resource = absoluteResource.substring(index);
  +            int levels = StringUtils.count(pathDiff, '/');
  +            StringBuffer b = new StringBuffer();
  +            for (int i = 0; i < levels; i++) {
  +                b.append("../");
  +            }
  +            b.append(resource);
  +            return b.toString();
  +        }
  +    }
  +
  +    /**
  +     * Normalize a uri containing ../ and ./ paths.
  +     *
  +     * @param uri The uri path to normalize
  +     * @return The normalized uri
  +     */
  +    public static String normalize(String uri) {
  +        String[] dirty = StringUtils.split(uri, "/");
  +        int length = dirty.length;
  +        String[] clean = new String[length];
  +
  +        boolean path;
  +        boolean finished;
  +        while (true) {
  +            path = false;
  +            finished = true;
  +            for (int i = 0, j = 0; (i < length) && (dirty[i] != null); i++) {
  +                if (".".equals(dirty[i])) {
  +                    // ignore
  +                } else if ("..".equals(dirty[i])) {
  +                    clean[j++] = dirty[i];
  +                    if (path) finished = false;
  +                } else {
  +                    if ((i+1 < length) && ("..".equals(dirty[i+1]))) {
  +                        i++;
  +                    } else {
  +                        clean[j++] = dirty[i];
  +                        path = true;
  +                    }
  +                }
  +            }
  +            if (finished) {
  +                break;
  +            } else {
  +                dirty = clean;
  +                clean = new String[length];
  +            }
  +        }
  +
  +        StringBuffer b = new StringBuffer(uri.length());
  +
  +        for (int i = 0; (i < length) && (clean[i] != null); i++) {
  +            b.append(clean[i]);
  +            if ((i+1 < length) && (clean[i+1] != null)) b.append("/");
  +        }
  +
  +        return b.toString();
  +    }
  +
  +    /**
  +     * Remove parameters from a uri.
  +     *
  +     * @param uri The uri path to deparameterize.
  +     * @param parameters The map that collects parameters.
  +     * @return The cleaned uri
  +     */
  +    public static String deparameterize(String uri, Map parameters) {
  +        int i = uri.lastIndexOf('?');
  +        if (i == -1) return uri;
  +        String[] params = StringUtils.split(uri.substring(i+1), "&");
  +        for (int j = 0; j < params.length; j++) {
  +            String p = params[j];
  +            int k = p.indexOf('=');
  +            if (k == -1) break;
  +            String name = p.substring(0, k);
  +            String value = p.substring(k+1);
  +            parameters.put(name, value);
  +        }
  +        return uri.substring(0, i);
  +    }
  +
  +    public static void main(String[] args) {
  +        String absoluteURI = absolutize(args[0], args[1]);
  +        String normalizedURI = normalize(absoluteURI);
  +        String relativeURI = relativize(args[0], normalizedURI);
  +        System.out.println(absoluteURI + " --> " + normalizedURI + " --> " + relativeURI);
       }
   }
  
  
  
  1.1.2.4   +73 -38    xml-cocoon/src/org/apache/cocoon/util/Attic/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/util/Attic/StringUtils.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- StringUtils.java	2000/07/29 18:30:42	1.1.2.3
  +++ StringUtils.java	2000/10/06 21:25:33	1.1.2.4
  @@ -13,49 +13,84 @@
    * A collection of <code>String</code> handling utility methods.
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.3 $ $Date: 2000/07/29 18:30:42 $
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/10/06 21:25:33 $
    */
   public class StringUtils {
  -  /**
  -   * Split a string as an array using whitespace as separator
  -   *
  -   * @param line The string to be split
  -   * @return An array of whitespace-separated tokens
  -   */
  -  public static String[] split(String line) {
  -    return split(line, " \t\n\r");
  -  }
  +  
  +    /**
  +     * Split a string as an array using whitespace as separator
  +     *
  +     * @param line The string to be split
  +     * @return An array of whitespace-separated tokens
  +     */
  +    public static String[] split(String line) {
  +        return split(line, " \t\n\r");
  +    }
   
  -  /**
  -   * Split a string as an array using a given set of separators
  -   *
  -   * @param line The string to be split
  -   * @param delimiter A string containing token separators
  -   * @return An array of token
  -   */
  -  public static String[] split(String line, String delimiter) {
  -    Tokenizer tokenizer = new Tokenizer(line, delimiter);
  -    int tokenCount = tokenizer.countTokens();
  -    String[] result = new String[tokenCount];
  +    /**
  +     * Split a string as an array using a given set of separators
  +     *
  +     * @param line The string to be split
  +     * @param delimiter A string containing token separators
  +     * @return An array of token
  +     */
  +    public static String[] split(String line, String delimiter) {
  +        Tokenizer tokenizer = new Tokenizer(line, delimiter);
  +        int tokenCount = tokenizer.countTokens();
  +        String[] result = new String[tokenCount];
  +        
  +        for (int i = 0; i < tokenCount; i++) {
  +            result[i] = tokenizer.nextToken();
  +        }
  +        
  +        return result;
  +    }
   
  -    for (int i = 0; i < tokenCount; i++) {
  -      result[i] = tokenizer.nextToken();
  +    /**
  +     * Tests whether a given character is alphabetic, numeric or
  +     * underscore
  +     *
  +     * @param c The character to be tested
  +     * @return whether the given character is alphameric or not
  +     */
  +    public static boolean isAlphaNumeric(char c) {
  +        return c == '_' ||
  +            (c >= 'a' && c <= 'z') ||
  +            (c >= 'A' && c <= 'Z') ||
  +            (c >= '0' && c <= '9');
       }
   
  -    return result;
  -  }
  +    /**
  +     * Counts the occurrence of the given char in the string.
  +     *
  +     * @param str The string to be tested
  +     * @param c the char to be counted
  +     * @return the occurrence of the character in the string.
  +     */
  +    public static int count(String str, char c) {
  +        int index = 0;
  +        char[] chars = str.toCharArray();
  +        for (int i = 0; i < chars.length; i++) {
  +            if (chars[i] == c) index++;
  +        }
  +        return index;
  +    }
   
  -  /**
  -   * Tests whether a given character is alphabetic, numeric or
  -   * underscore
  -   *
  -   * @param c The character to be tested
  -   * @return whether the given character is alphameric or not
  -   */
  -  public static boolean isAlphaNumeric(char c) {
  -    return c == '_' ||
  -           (c >= 'a' && c <= 'z') ||
  -           (c >= 'A' && c <= 'Z') ||
  -           (c >= '0' && c <= '9');
  -  }
  +    /**
  +     * Matches two strings.
  +     *
  +     * @param a The first string
  +     * @param b The second string
  +     * @return the index where the two strings stop matching starting from 0
  +     */
  +    public static int matchStrings(String a, String b) {
  +        int i;
  +        char[] ca = a.toCharArray();
  +        char[] cb = b.toCharArray();
  +        for (i = 0; (i < ca.length) || (i < cb.length); i++) {
  +            if (ca[i] != cb[i]) break;
  +        }
  +        return i;
  +    }
   }
  
  
  

Mime
View raw message