geirm       02/03/15 03:21:20

  Modified:    src/java/org/apache/tools/dvsl DVSL.java
  Log:
  Pete Kazmier noted that the ready flag never got set to true.  While in there
  Added Bill as an author (forgot for some reason last time) a little WS
  cleanup
  
  Revision  Changes    Path
  1.9       +114 -105  jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java
  
  Index: DVSL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DVSL.java 22 Feb 2002 06:07:01 -0000      1.8
  +++ DVSL.java 15 Mar 2002 11:21:20 -0000      1.9
  @@ -82,6 +82,7 @@
    *  Main DVSL class - use this as the helper class for apps
    *
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
  + *  @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burton.</a>
    */
   public class DVSL
   {
  @@ -109,7 +110,6 @@
   
       boolean validate = false;
   
  -
       public DVSL()
       {
           classLoader = DVSL.class.getClassLoader();
  @@ -120,14 +120,16 @@
        *  lets the user specify a filename for logging.
        *  </p>
        */
  -    public void setLogFile( File logFile )
  +    public void setLogFile(File logFile)
       {
           this.logFile = logFile;
  -        if ( velConfig == null )
  +
  +        if (velConfig == null)
           {
               velConfig = new HashMap();
           }
  -        velConfig.put( VelocityEngine.RUNTIME_LOG, logFile.getAbsolutePath() );
  +
  +        velConfig.put(VelocityEngine.RUNTIME_LOG, logFile.getAbsolutePath());
       }
   
       /**
  @@ -135,14 +137,16 @@
        *  lets the user specify a class instance for logging.
        *  </p>
        */
  -    public void setLogSystem( LogSystem logger )
  +    public void setLogSystem(LogSystem logger)
       {
           this.logger = logger;
  -        if ( velConfig == null )
  +
  +        if (velConfig == null)
           {
               velConfig = new HashMap();
           }
  -        velConfig.put( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, logger );
  +
  +        velConfig.put(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, logger);
       }
   
       /**
  @@ -152,12 +156,13 @@
        *  used by DVSL
        *  </p>
        */
  -    public void setVelocityConfig( Map map )
  +    public void setVelocityConfig(Map map)
       {
  -        if ( velConfig != null )
  +        if (velConfig != null)
           {
               map.putAll(velConfig);
           }
  +
           velConfig = map;
       }
   
  @@ -171,7 +176,7 @@
        *
        *  @param ctx User context of data
        */
  -    public void setUserContext( Context ctx )
  +    public void setUserContext(Context ctx)
       {
           ready = false;
           userContext = ctx;
  @@ -185,7 +190,7 @@
        * @param validate
        */
   
  -    public void setValidatingParser( boolean vp )
  +    public void setValidatingParser(boolean vp)
       {
           validate = vp;
       }
  @@ -198,9 +203,9 @@
        *
        *  @param classLoader ClassLoader or null for default ClassLoader
        */
  -    public void setClassLoader( ClassLoader classLoader )
  +    public void setClassLoader(ClassLoader classLoader)
       {
  -        if ( classLoader == null )
  +        if (classLoader == null)
           {
               this.classLoader = this.getClass().getClassLoader();
           }
  @@ -216,11 +221,11 @@
        *  </p>
        *
        *  <p>
  -     *  Currently supports specification of the Toolbox 
  +     *  Currently supports specification of the Toolbox
        *  name in the context, creating classes, and string
        *  and integer values.  Ex :
        *  </p>
  -     *  
  +     *
        *  <pre>
        *  toolbox.contextname = floyd
        *  toolbox.tool.footool = Footool
  @@ -239,7 +244,7 @@
        *    $context.floyd.myint
        *  </pre>
        */
  -    public void setToolbox( Properties p )
  +    public void setToolbox(Properties p)
           throws ClassNotFoundException, InstantiationException, 
IllegalAccessException
       {
           ready = false;
  @@ -253,42 +258,42 @@
   
           String toolboxname = "toolbox";
   
  -        for( Enumeration e = p.propertyNames(); e.hasMoreElements(); )
  +        for (Enumeration e = p.propertyNames(); e.hasMoreElements(); )
           {
               String key = (String) e.nextElement();
   
               String value = p.getProperty(key);
   
  -            if ( key.startsWith( TOOL_PROP_PREFIX ))
  +            if (key.startsWith(TOOL_PROP_PREFIX))
               {
  -                String toolname = key.substring( TOOL_PROP_PREFIX.length());
  +                String toolname = key.substring(TOOL_PROP_PREFIX.length());
   
  -                Object o = Class.forName( value, true, classLoader ).newInstance();
  -                
  -                toolbox.put( toolname, o );
  +                Object o = Class.forName(value, true, classLoader).newInstance();
  +
  +                toolbox.put(toolname, o);
               }
  -            else if ( key.startsWith( INTEGER_PROP_PREFIX ) )
  +            else if (key.startsWith(INTEGER_PROP_PREFIX))
               {
  -                String toolname = key.substring( INTEGER_PROP_PREFIX.length());
  +                String toolname = key.substring(INTEGER_PROP_PREFIX.length());
   
                   int i = 0;
   
                   try
                   {
  -                    i = Integer.parseInt( value );
  +                    i = Integer.parseInt(value);
                   }
  -                catch( Exception ee )
  +                catch(Exception ee)
                   {
                   }
  -           
  -                toolbox.put( toolname, new Integer(i) );
  +
  +                toolbox.put(toolname, new Integer(i));
               }
  -            else if ( key.startsWith( STRING_PROP_PREFIX ) )
  +            else if (key.startsWith(STRING_PROP_PREFIX))
               {
  -                String toolname = key.substring( STRING_PROP_PREFIX.length());
  -                toolbox.put( toolname, value );
  +                String toolname = key.substring(STRING_PROP_PREFIX.length());
  +                toolbox.put(toolname, value);
               }
  -            else if ( key.startsWith( TOOLBOX_NAME ) )
  +            else if (key.startsWith(TOOLBOX_NAME))
               {
                   toolboxname = value;
               }
  @@ -296,13 +301,13 @@
   
           toolContext = new VelocityContext();
   
  -        toolContext.put( toolboxname, toolbox );
  +        toolContext.put(toolboxname, toolbox);
       }
   
       /**
        *  Convenience function.  See...
        */
  -    public void setStylesheet( String stylesheet )
  +    public void setStylesheet(String stylesheet)
           throws Exception
       {
           setStylesheet(new File(stylesheet));
  @@ -311,18 +316,18 @@
       /**
        *  Convenience function.  See...
        */
  -    public void setStylesheet( File stylesheet )
  +    public void setStylesheet(File stylesheet)
           throws Exception
       {
           FileReader fr = null;
  -        
  +
           try
           {
  -            fr = new FileReader( stylesheet );
  +            fr = new FileReader(stylesheet);
   
  -            setStylesheet( fr );
  +            setStylesheet(fr);
           }
  -        catch( Exception e )
  +        catch(Exception e)
           {
               throw e;
           }
  @@ -346,7 +351,7 @@
        *
        *  @param styleReader Reader with stylesheet char stream
        */
  -    public void setStylesheet( Reader styleReader )
  +    public void setStylesheet(Reader styleReader)
           throws Exception
       {
           ready = false;
  @@ -361,9 +366,9 @@
            * if there are user properties, set those first - carefully
            */
   
  -        if ( velConfig != null )
  +        if (velConfig != null)
           {
  -            configureVelocityEngine( ve, velConfig );
  +            configureVelocityEngine(ve, velConfig);
           }
   
           /*
  @@ -377,25 +382,26 @@
            *  add our template accumulator
            */
   
  -        ve.setApplicationAttribute( "org.apache.tools.dvsl.TemplateHandler", 
templateHandler );
  +        ve.setApplicationAttribute("org.apache.tools.dvsl.TemplateHandler", 
templateHandler);
   
           /*
            *  load and render the stylesheet
            *
            *  this sets stylesheet specific context
            *  values
  -         */  
  +         */
   
           StringWriter junkWriter = new StringWriter();
   
           styleContext = new VelocityContext();
  -        ve.evaluate( styleContext, junkWriter, "DVSL:stylesheet", styleReader );
  +        ve.evaluate(styleContext, junkWriter, "DVSL:stylesheet", styleReader);
   
           /*
            *  now run the base template through for the rules
            */
   
  -        InputStream is = this.getClass().getClassLoader().getResourceAsStream( 
"org/apache/tools/dvsl/resource/defaultroot.dvsl");
  +        InputStream is = this.getClass().getClassLoader()
  +              
.getResourceAsStream("org/apache/tools/dvsl/resource/defaultroot.dvsl");
   
           if (is == null)
           {
  @@ -403,16 +409,17 @@
           }
           else
           {
  -            ve.evaluate( new VelocityContext(), junkWriter, "defaultroot.dvsl", new 
InputStreamReader(is) );
  +            ve.evaluate(new VelocityContext(),
  +                    junkWriter, "defaultroot.dvsl", new InputStreamReader(is));
               is.close();
           }
   
           /*
  -         *  need a new transformer, as it depends on the 
  +         *  need a new transformer, as it depends on the
            *  velocity engine
            */
   
  -        transformer = new Transformer( ve, templateHandler,  baseContext, validate 
);
  +        transformer = new Transformer(ve, templateHandler,  baseContext, validate);
       }
   
       /**
  @@ -436,9 +443,9 @@
        *  the stylesheet, as that creates the VelocityEngine
        *  </p>
        */
  -    private void configureVelocityEngine( VelocityEngine ve, Map map )
  +    private void configureVelocityEngine(VelocityEngine ve, Map map)
       {
  -        if ( ve == null || map == null)
  +        if (ve == null || map == null)
           {
               return;
           }
  @@ -447,21 +454,21 @@
            * for now,  keep it simple
            */
   
  -        Object val = map.get(VelocityEngine.VM_LIBRARY );
  +        Object val = map.get(VelocityEngine.VM_LIBRARY);
   
           if (val instanceof String)
           {
  -            ve.setProperty( VelocityEngine.VM_LIBRARY, (String) val);
  +            ve.setProperty(VelocityEngine.VM_LIBRARY, (String) val);
           }
   
           /*
            *  assumes that for now, we are using the file loader
            */
  -        val = map.get(VelocityEngine.FILE_RESOURCE_LOADER_PATH );
  +        val = map.get(VelocityEngine.FILE_RESOURCE_LOADER_PATH);
   
  -        if ( val instanceof String)
  +        if (val instanceof String)
           {
  -            ve.setProperty( VelocityEngine.FILE_RESOURCE_LOADER_PATH, (String) val);
  +            ve.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, (String) val);
           }
   
           /*
  @@ -469,23 +476,23 @@
            */
           val = map.get(VelocityEngine.RUNTIME_LOG);
   
  -        if ( val instanceof String)
  +        if (val instanceof String)
           {
  -            ve.setProperty( VelocityEngine.RUNTIME_LOG,  val);
  +            ve.setProperty(VelocityEngine.RUNTIME_LOG,  val);
           }
   
           val = map.get(VelocityEngine.RUNTIME_LOG_LOGSYSTEM);
   
  -        if ( val != null )
  +        if (val != null)
           {
  -            ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM,  val);
  +            ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM,  val);
           }
   
           val = map.get(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS);
   
  -        if ( val instanceof String)
  +        if (val instanceof String)
           {
  -            ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,  val);
  +            ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,  val);
           }
   
       }
  @@ -501,66 +508,68 @@
   
           baseContext.clearContexts();
   
  -        baseContext.addContext( userContext );
  -        baseContext.addContext( toolContext );
  -        baseContext.setStyleContext( styleContext );   
  +        baseContext.addContext(userContext);
  +        baseContext.addContext(toolContext);
  +        baseContext.setStyleContext(styleContext);
  +
  +        ready = true;
        }
   
       /**
        *  does the transformation of the inputstream into
        *  the output writer
        */
  -    protected long xform( Reader reader, Writer writer )
  +    protected long xform(Reader reader, Writer writer)
           throws Exception
       {
           if (!ready)
               makeReady();
   
  -        return transformer.transform( reader, writer );
  +        return transformer.transform(reader, writer);
       }
   
  -    protected long xform( Document dom4jdoc, Writer writer )
  +    protected long xform(Document dom4jdoc, Writer writer)
           throws Exception
       {
           if (!ready)
               makeReady();
   
  -        return transformer.transform( dom4jdoc, writer );
  +        return transformer.transform(dom4jdoc, writer);
       }
   
  -    public long transform( File f, Writer writer )
  +    public long transform(File f, Writer writer)
           throws Exception
       {
           Reader reader = null;
   
           try
           {
  -            reader = new FileReader( f );
  -            return xform( reader, writer );
  +            reader = new FileReader(f);
  +            return xform(reader, writer);
           }
  -        catch( Exception e )
  +        catch(Exception e)
           {
               throw e;
           }
           finally
           {
  -            if ( reader != null)
  +            if (reader != null)
               {
                   reader.close();
               }
           }
       }
   
  -    public long transform( Reader reader, Writer writer )
  +    public long transform(Reader reader, Writer writer)
           throws Exception
       {
  -        return xform( reader, writer );
  +        return xform(reader, writer);
       }
   
  -    public long transform( InputStream is, Writer writer )
  +    public long transform(InputStream is, Writer writer)
           throws Exception
       {
  -        return xform( new InputStreamReader(is), writer );
  +        return xform(new InputStreamReader(is), writer);
       }
   
       /**
  @@ -569,29 +578,29 @@
        * @param dom4jdoc dom4j Document object
        * @param writer Writer for output
        */
  -    public long transform( Document dom4jdoc, Writer writer )
  +    public long transform(Document dom4jdoc, Writer writer)
           throws Exception
       {
  -        return xform( dom4jdoc, writer );
  +        return xform(dom4jdoc, writer);
       }
   
  -    public long transform( String infile, Writer writer )
  +    public long transform(String infile, Writer writer)
           throws Exception
       {
          Reader reader = null;
   
           try
           {
  -            reader = new FileReader( infile );
  -            return xform( reader, writer );
  +            reader = new FileReader(infile);
  +            return xform(reader, writer);
           }
  -        catch( Exception e )
  +        catch(Exception e)
           {
               throw e;
           }
           finally
           {
  -            if ( reader != null)
  +            if (reader != null)
               {
                   reader.close();
               }
  @@ -618,49 +627,49 @@
           String style = null;
           String outfile = null;
   
  -        Writer out = new OutputStreamWriter( System.out );
  +        Writer out = new OutputStreamWriter(System.out);
           String toolfile = null;
   
  -        for( int i = 0; i < args.length; i++)
  +        for(int i = 0; i < args.length; i++)
           {
  -            if ( args[i].equals("-IN"))
  +            if (args[i].equals("-IN"))
                   infile = args[++i];
  -            else if (args[i].equals("-OUT" ) )
  +            else if (args[i].equals("-OUT"))
                   outfile = args[++i];
  -           else if (args[i].equals("-STYLE" ) )
  +           else if (args[i].equals("-STYLE"))
                   style = args[++i];
  -           else if (args[i].equals("-TOOL" ) )
  +           else if (args[i].equals("-TOOL"))
                   toolfile = args[++i];
           }
  -        
  -        if ( style == null)
  +
  +        if (style == null)
           {
               System.out.println("usage :need to specify a stylesheet. ");
               System.out.println("java -jar dvsl.jar -STYLE stylesheeet [-IN infile] 
[-OUT outfile] [-TOOL toolboxname]");
               return;
           }
   
  -        if ( style != null)
  -            dvsl.setStylesheet( style );
  +        if (style != null)
  +            dvsl.setStylesheet(style);
   
  -        if ( toolfile != null)
  +        if (toolfile != null)
           {
               Properties p = new Properties();
   
  -            InputStream fis = new FileInputStream( toolfile );
  +            InputStream fis = new FileInputStream(toolfile);
   
  -            p.load( fis );
  +            p.load(fis);
   
  -            dvsl.setToolbox( p );
  +            dvsl.setToolbox(p);
           }
   
  -        if ( infile != null)
  -            in = new FileReader( infile );
  -    
  -        if ( outfile != null)
  -            out = new FileWriter( outfile );
  +        if (infile != null)
  +            in = new FileReader(infile);
  +
  +        if (outfile != null)
  +            out = new FileWriter(outfile);
   
  -        long time = dvsl.transform( in, out );
  +        long time = dvsl.transform(in, out);
   
           out.flush();
   
  
  
  

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

Reply via email to