You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by hu...@apache.org on 2001/12/30 07:09:56 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/environment/commandline CommandlineContext.java

huber       01/12/29 22:09:56

  Modified:    src/org/apache/cocoon/environment/commandline
                        CommandlineContext.java
  Log:
  fixing BUG5060,
  trust File to calculate getResource, getRealPath,
  don't try to build it using string concat
  
  Revision  Changes    Path
  1.10      +32 -18    xml-cocoon2/src/org/apache/cocoon/environment/commandline/CommandlineContext.java
  
  Index: CommandlineContext.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/environment/commandline/CommandlineContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CommandlineContext.java	27 Nov 2001 16:38:37 -0000	1.9
  +++ CommandlineContext.java	30 Dec 2001 06:09:56 -0000	1.10
  @@ -36,50 +36,64 @@
        */
       public CommandlineContext (String contextDir) {
           String contextDirPath = new File(contextDir).getAbsolutePath();
  -        if (contextDirPath.endsWith("/.")) {
  -          int pos = contextDirPath.lastIndexOf("/.");
  -          this.contextDir = contextDirPath.substring(0, pos);
  -        }
  -        else {
  -          this.contextDir = contextDirPath;
  -        }
  +        // store contextDirPath as is don't remove trailing /.
  +        // fix BUG 5060
  +        this.contextDir = contextDirPath;
           this.attributes = new HashMap();
       }
   
       public Object getAttribute(String name) {
  -        getLogger().debug("CommandlineContext: getAttribute=" + name);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: getAttribute=" + name);
  +        }
           return this.attributes.get(name);
       }
   
       public void setAttribute(String name, Object value) {
  -        getLogger().debug("CommandlineContext: setAttribute=" + name);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: setAttribute=" + name);
  +        }
           this.attributes.put(name, value);
       }
       
       public void removeAttribute(String name) {
  -        getLogger().debug("CommandlineContext: removeAttribute=" + name);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: removeAttribute=" + name);
  +        }
           this.attributes.remove(name);
       }
       
       public Enumeration getAttributeNames() {
  -        getLogger().debug("CommandlineContext: getAttributeNames");
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: getAttributeNames");
  +        }
           return new IteratorEnumeration(this.attributes.keySet().iterator());
       }
   
       public URL getResource(String path) throws MalformedURLException {
  -        getLogger().debug("CommandlineContext: getResource=" + path);
  -        //return servletContext.getResource(path);
  -        return new URL(new StringBuffer("file:").append(this.contextDir).append(path).toString());
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: getResource=" + path);
  +        }
  +        // rely on File to build correct File and URL
  +        // fix BUG 5060
  +        File f = new File( contextDir, path );
  +        return f.toURL();
       }
   
       public String getRealPath(String path) {
  -        getLogger().debug("CommandlineContext: getRealPath=" + path);
  -        //return servletContext.getRealPath(path);
  -        return this.contextDir + path;
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: getRealPath=" + path);
  +        }
  +        // rely on File to build correct File and URL
  +        // fix BUG 5060
  +        File f = new File( this.contextDir, path );
  +        return f.getAbsolutePath();
       }
   
       public String getMimeType(String file) {
  -        getLogger().debug("CommandlineContext: getMimeType=" + file);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("CommandlineContext: getMimeType=" + file);
  +        }
           //return servletContext.getMimeType(file);
           return null;
       }
  
  
  

----------------------------------------------------------------------
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