dion        2004/08/11 22:34:34

  Modified:    jelly/src/java/org/apache/commons/jelly JellyContext.java
               jelly/xdocs changes.xml
  Log:
  Jelly-108
  
  Revision  Changes    Path
  1.53      +54 -3     
jakarta-commons/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- JellyContext.java 26 Mar 2004 22:40:12 -0000      1.52
  +++ JellyContext.java 12 Aug 2004 05:34:34 -0000      1.53
  @@ -28,6 +28,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
   /** <p><code>JellyContext</code> represents the Jelly context.</p>
  @@ -460,6 +461,26 @@
           return script.compile();
       }
   
  +    /** 
  +     * Attempts to parse the script from the given InputSource using the 
  +     * [EMAIL PROTECTED] #getResource} method then returns the compiled script.
  +     */
  +    public Script compileScript(InputSource source) throws JellyException {
  +        XMLParser parser = getXMLParser();
  +        parser.setContext(this);
  +        
  +        Script script = null;
  +        try {
  +            script = parser.parse(source);
  +        } catch (IOException e) {
  +            throw new JellyException("Could not parse Jelly script",e);
  +        } catch (SAXException e) {
  +            throw new JellyException("Could not parse Jelly script",e);
  +        }
  +        
  +        return script.compile();
  +    }
  +
       /**
        * @return a thread pooled XMLParser to avoid the startup overhead
        * of the XMLParser
  @@ -502,6 +523,16 @@
       }
   
       /** 
  +     * Parses the script from the given InputSource then compiles it and runs it.
  +     * 
  +     * @return the new child context that was used to run the script
  +     */
  +    public JellyContext runScript(InputSource source, XMLOutput output) throws 
JellyException {
  +        return runScript(source, output, JellyContext.DEFAULT_EXPORT,
  +            JellyContext.DEFAULT_INHERIT);
  +    }
  +
  +    /** 
        * Parses the script from the given uri using the 
        * JellyContext.getResource() API then compiles it and runs it.
        * 
  @@ -565,11 +596,21 @@
        */
       public JellyContext runScript(URL url, XMLOutput output,
                             boolean export, boolean inherit) throws JellyException {
  -        Script script = compileScript(url);
  +        return runScript(new InputSource(url.toString()), output, export, inherit);
  +    }
  +
  +    /** 
  +     * Parses the script from the given InputSource then compiles it and runs it.
  +     * 
  +     * @return the new child context that was used to run the script
  +     */
  +    public JellyContext runScript(InputSource source, XMLOutput output,
  +                          boolean export, boolean inherit) throws JellyException {
  +        Script script = compileScript(source);
           
           URL newJellyContextURL = null;
           try {
  -            newJellyContextURL = getJellyContextURL(url);
  +            newJellyContextURL = getJellyContextURL(source);
           } catch (MalformedURLException e) {
               throw new JellyException(e.toString());
           }
  @@ -586,7 +627,7 @@
           } 
   
           if (log.isDebugEnabled() ) {
  -            log.debug( "About to run script: " + url );
  +            log.debug( "About to run script: " + source.getSystemId() );
               log.debug( "root context URL: " + newJellyContext.rootURL );
               log.debug( "current context URL: " + newJellyContext.currentURL );
           }
  @@ -838,6 +879,16 @@
        */
       protected URL getJellyContextURL(URL url) throws MalformedURLException {
           String text = url.toString();
  +        int idx = text.lastIndexOf('/');
  +        text = text.substring(0, idx + 1);
  +        return new URL(text);
  +    }
  +
  +    /** 
  +     * Strips off the name of a script to create a new context URL
  +     */
  +    protected URL getJellyContextURL(InputSource source) throws 
MalformedURLException {
  +        String text = source.getSystemId();
           int idx = text.lastIndexOf('/');
           text = text.substring(0, idx + 1);
           return new URL(text);
  
  
  
  1.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- changes.xml       12 Aug 2004 05:08:29 -0000      1.4
  +++ changes.xml       12 Aug 2004 05:34:34 -0000      1.5
  @@ -25,6 +25,7 @@
     </properties>
     <body>
       <release version="1.0-beta-4-SNAPSHOT" date="in CVS">
  +      <action dev="dion" type="add" issue="JELLY-108" due-to="Maarten Coene">Run a 
script from an input source</action>
         <action dev="dion" type="add" issue="JELLY-113" due-to="Gary Franklin">Thread 
safety of tag support</action>
         <action dev="dion" type="add" issue="JELLY-115" due-to="Felipe Leme">Add var 
to break tag</action>
         <action dev="dion" type="add" issue="JELLY-116" due-to="Felipe Leme">Add 
exceptionVar to invoke and invokeStatic</action>
  
  
  

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

Reply via email to