dion        2002/12/30 17:31:14

  Modified:    jelly/src/java/org/apache/commons/jelly JellyContext.java
  Log:
  Handle fully qualified files being passed to getResource
  
  Revision  Changes    Path
  1.37      +18 -9     
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- JellyContext.java 27 Nov 2002 15:39:43 -0000      1.36
  +++ JellyContext.java 31 Dec 2002 01:31:14 -0000      1.37
  @@ -562,9 +562,11 @@
       /**
        * Returns a URL for the given resource from the specified path.
        * If the uri starts with "/" then the path is taken as relative to 
  -     * the current context root. If the uri is a well formed URL then it
  -     * is used. Otherwise the uri is interpreted as relative to the current
  -     * context (the location of the current script).
  +     * the current context root.
  +     * If the uri is a well formed URL then it is used.
  +     * If the uri is a file that exists and can be read then it is used.
  +     * Otherwise the uri is interpreted as relative to the current context (the
  +     * location of the current script).
        */
       public URL getResource(String uri) throws MalformedURLException {
           if (uri.startsWith("/")) {
  @@ -576,13 +578,20 @@
                   return new URL(uri);
               }
               catch (MalformedURLException e) {
  -                // lets try find a relative resource
  -                try {
  -                    return createRelativeURL(currentURL, uri);
  -                }
  -                catch (MalformedURLException e2) {
  -                    throw e;
  +             // try for a fully qualified file first
  +             File nonRelativeFile = new File(uri);
  +             if (nonRelativeFile.exists() && nonRelativeFile.canRead()) {
  +                    return nonRelativeFile.toURL();
                   }
  +             else {
  +                    // lets try find a relative resource
  +                    try {
  +                        return createRelativeURL(currentURL, uri);
  +                    } 
  +                    catch (MalformedURLException e2) {
  +                        throw e;
  +                    }
  +                             }
               }
           }
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to