dion        2004/09/15 18:12:11

  Modified:    jelly/src/java/org/apache/commons/jelly/impl
                        StaticTagScript.java TagScript.java
               jelly/xdocs changes.xml
  Log:
  JELLY-45. Resource lookup in compiled scripts does not work correctly
  
  Revision  Changes    Path
  1.24      +7 -1      
jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/StaticTagScript.java
  
  Index: StaticTagScript.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/StaticTagScript.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- StaticTagScript.java      9 Sep 2004 12:26:22 -0000       1.23
  +++ StaticTagScript.java      16 Sep 2004 01:12:11 -0000      1.24
  @@ -15,6 +15,7 @@
    */
   package org.apache.commons.jelly.impl;
   
  +import java.net.URL;
   import java.util.Iterator;
   import java.util.Map;
   
  @@ -50,7 +51,6 @@
       // Script interface
       //-------------------------------------------------------------------------
       public void run(JellyContext context, XMLOutput output) throws 
JellyTagException {
  -
           try {
               startNamespacePrefixes(output);
           } catch (SAXException e) {
  @@ -71,11 +71,14 @@
               throw new JellyTagException(e);
           }
   
  +        URL rootURL = context.getRootURL();
  +        URL currentURL = context.getCurrentURL();
           try {
               if ( tag == null ) {
                   return;
               }
               tag.setContext(context);
  +            setContextURLs(context);
   
               DynaTag dynaTag = (DynaTag) tag;
   
  @@ -103,6 +106,9 @@
           }
           catch (RuntimeException e) {
               handleException(e);
  +        } finally {
  +            context.setCurrentURL(currentURL);
  +            context.setRootURL(rootURL);
           }
   
           try {
  
  
  
  1.44      +41 -1     
jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
  
  Index: TagScript.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- TagScript.java    9 Sep 2004 12:26:22 -0000       1.43
  +++ TagScript.java    16 Sep 2004 01:12:11 -0000      1.44
  @@ -16,6 +16,8 @@
   package org.apache.commons.jelly.impl;
   
   import java.lang.reflect.InvocationTargetException;
  +import java.net.MalformedURLException;
  +import java.net.URL;
   import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.Map;
  @@ -107,6 +109,9 @@
   
       /** the SAX attributes */
       private Attributes saxAttributes;
  +    
  +    /** the url of the script when parsed */
  +    private URL scriptURL = null;
   
       /**
        * @return a new TagScript based on whether
  @@ -170,11 +175,24 @@
           attributes.put(name, expression);
       }
   
  +    /**
  +     * Strips off the name of a script to create a new context URL
  +     * FIXME: Copied from JellyContext
  +     */
  +    private URL getJellyContextURL(URL url) throws MalformedURLException {
  +        String text = url.toString();
  +        int idx = text.lastIndexOf('/');
  +        text = text.substring(0, idx + 1);
  +        return new URL(text);
  +    }
  +
       // Script interface
       //-------------------------------------------------------------------------
   
       /** Evaluates the body of a tag */
       public void run(JellyContext context, XMLOutput output) throws 
JellyTagException {
  +        URL rootURL = context.getRootURL();
  +        URL currentURL = context.getCurrentURL();
           if ( ! context.isCacheTags() ) {
               clearTag();
           }
  @@ -184,6 +202,7 @@
                   return;
               }
               tag.setContext(context);
  +            setContextURLs(context);
   
               if ( tag instanceof DynaTag ) {
                   DynaTag dynaTag = (DynaTag) tag;
  @@ -248,10 +267,25 @@
               * Errors in the normal course of operation.  Hmm...
               */
               handleException(e);
  +        } finally {
  +            context.setRootURL(rootURL);
  +            context.setCurrentURL(currentURL);
           }
   
       }
   
  +    /**
  +     * Set the context's root and current URL if not present
  +     * @param context
  +     * @throws JellyTagException
  +     */
  +    protected void setContextURLs(JellyContext context) throws JellyTagException {
  +        if ((context.getCurrentURL() == null || context.getRootURL() == null) && 
scriptURL != null)
  +        {
  +            if (context.getRootURL() == null) context.setRootURL(scriptURL);
  +            if (context.getCurrentURL() == null) context.setCurrentURL(scriptURL);
  +        }
  +    }
   
       // Properties
       //-------------------------------------------------------------------------
  @@ -331,6 +365,12 @@
        */
       public void setFileName(String fileName) {
           this.fileName = fileName;
  +        try
  +        {
  +            this.scriptURL = getJellyContextURL(new URL(fileName));
  +        } catch (MalformedURLException e) {
  +            log.debug("error setting script url", e);
  +        }
       }
   
   
  
  
  
  1.19      +1 -0      jakarta-commons/jelly/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/xdocs/changes.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- changes.xml       12 Sep 2004 16:46:19 -0000      1.18
  +++ changes.xml       16 Sep 2004 01:12:11 -0000      1.19
  @@ -25,6 +25,7 @@
     </properties>
     <body>
       <release version="1.0-beta-5-SNAPSHOT" date="in CVS">
  +      <action dev="dion" type="fix" issue="JELLY-45">Scripts set the context URL 
when executing so that resources are found relative to the current script.</action>
         <action dev="dion" type="add" issue="JELLY-49">Add Regexp taglib</action>
       </release>
       <release version="1.0-beta-4" date="2004-09-09">
  
  
  

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

Reply via email to