brett       2004/05/11 02:39:12

  Modified:    src/java/org/apache/maven/jelly Tag: MAVEN-1_0-BRANCH
                        JellyUtils.java
  Log:
  PR: MAVEN-1275
  Submitted by: Henning Schmiedehausen
  Reviewed by:  Brett Porter
  evaluate jexl expressions before setting ant properties
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.16.4.10 +56 -7     maven/src/java/org/apache/maven/jelly/JellyUtils.java
  
  Index: JellyUtils.java
  ===================================================================
  RCS file: /home/cvs/maven/src/java/org/apache/maven/jelly/JellyUtils.java,v
  retrieving revision 1.16.4.9
  retrieving revision 1.16.4.10
  diff -u -r1.16.4.9 -r1.16.4.10
  --- JellyUtils.java   7 May 2004 22:59:23 -0000       1.16.4.9
  +++ JellyUtils.java   11 May 2004 09:39:12 -0000      1.16.4.10
  @@ -25,6 +25,7 @@
   import org.apache.commons.jelly.expression.ExpressionFactory;
   import org.apache.commons.jelly.parser.XMLParser;
   import org.xml.sax.XMLReader;
  +import org.xml.sax.InputSource;
   
   import javax.xml.parsers.SAXParserFactory;
   import java.io.File;
  @@ -64,6 +65,27 @@
                                     XMLOutput output )
           throws Exception
       {
  +        runScript( scriptInputStream, null, rootUrl, context, output );
  +    }
  +
  +    /**
  +     * Run a jelly script.
  +     *
  +     * @param scriptInputStream Script input stream.
  +     * @param systemId the system identifier to help resolve relative URLs
  +     * @param rootUrl Root explicit context of the script.
  +     * @param context Jelly context.
  +     * @param output Output sink.
  +     * @throws Exception If an error occurs while locating, compiling or
  +     *      executing the script.
  +     */
  +    public static void runScript( InputStream scriptInputStream,
  +                                  String systemId,
  +                                  URL rootUrl,
  +                                  JellyContext context,
  +                                  XMLOutput output )
  +        throws Exception
  +    {
           URL oldRoot = context.getRootURL();
           URL oldCurrent = context.getCurrentURL();
   
  @@ -73,7 +95,7 @@
               context.setCurrentURL( rootUrl );
           }
   
  -        Script script = compileScript( scriptInputStream, context );
  +        Script script = compileScript( scriptInputStream, systemId, context );
           script.run( context, output );
   
           context.setRootURL( oldRoot );
  @@ -102,6 +124,7 @@
           }
   
           runScript( new FileInputStream( scriptFile ),
  +                   scriptFile.getAbsolutePath(),
                      rootUrl,
                      context,
                      output );
  @@ -120,7 +143,7 @@
                                           JellyContext context )
           throws Exception
       {
  -        return compileScript( new FileInputStream(scriptFile), context );
  +        return compileScript( new FileInputStream( scriptFile ), 
scriptFile.getAbsolutePath(), context );
       }
   
       /**
  @@ -136,13 +159,32 @@
                                           JellyContext context )
           throws Exception
       {
  -        return compileScript( scriptInputStream, context, null );
  +        return compileScript( scriptInputStream, null, context, null );
       }
   
       /**
        * Compile a jelly script.
        *
        * @param scriptInputStream Script input stream.
  +     * @param systemId the system identifier to help resolve relative URLs
  +     * @param context Jelly context.
  +     * @throws Exception If an error occurs while locating or compiling the
  +     *      script.
  +     * @return The compiled script.
  +     */
  +    public static Script compileScript( InputStream scriptInputStream,
  +                                        String systemId,
  +                                        JellyContext context )
  +        throws Exception
  +    {
  +        return compileScript( scriptInputStream, systemId, context, null );
  +    }
  +
  +    /**
  +     * Compile a jelly script.
  +     *
  +     * @param scriptInputStream Script input stream.
  +     * @param systemId the system identifier to help resolve relative URLs
        * @param context Jelly context.
        * @param encoding To use when reading XML.
        * @throws Exception If an error occurs while locating or compiling the
  @@ -150,7 +192,10 @@
        * @return The compiled script.
        * @todo throw something else
        */
  -    public static Script compileScript( InputStream scriptInputStream, JellyContext 
context, String encoding )
  +    public static Script compileScript( InputStream scriptInputStream, 
  +                                        String systemId, 
  +                                        JellyContext context, 
  +                                        String encoding )
           throws Exception
       {
           // FIXME: This should all be done by Jelly.
  @@ -163,14 +208,18 @@
   
           Script script = null;
   
  +        InputSource source = null;
           if ( encoding != null )
           {
  -            script = parser.parse( new InputStreamReader( scriptInputStream, 
encoding ) );
  +            source = new InputSource( new InputStreamReader( scriptInputStream, 
encoding ) ) ;
           }
           else
           {
  -            script = parser.parse( scriptInputStream );
  +            source = new InputSource( scriptInputStream );
           }
  +
  +        source.setSystemId( systemId );
  +        script = parser.parse( source );
   
           script = script.compile();
   
  
  
  

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

Reply via email to