org.apache.dvsl
Class DVSL

java.lang.Object
  extended by org.apache.dvsl.DVSL

public class DVSL
extends java.lang.Object

Main DVSL class - use this as the helper class for apps

Author:
Geir Magnusson Jr., Bill Burton.

Nested Class Summary
protected static class DVSL.LogAdapter
           
 
Field Summary
private  java.util.Map appVals
           
private  DVSLContext baseContext
           
private  java.lang.ClassLoader classLoader
           
private  org.dom4j.Document currentDocument
           
private  java.io.Writer currentWriter
           
private static java.lang.String INTEGER_PROP_PREFIX
           
private  java.io.File logFile
           
private  org.apache.velocity.runtime.log.LogChute logger
           
private  boolean ready
           
private static java.lang.String STRING_PROP_PREFIX
           
private  org.apache.velocity.context.Context styleContext
           
private  TemplateHandler templateHandler
           
private static java.lang.String TOOL_PROP_PREFIX
           
private static java.lang.String TOOLBOX_NAME
           
private  org.apache.velocity.context.Context toolContext
           
private  Transformer transformer
           
private  org.apache.velocity.context.Context userContext
           
(package private)  boolean validate
           
private  org.apache.velocity.app.VelocityEngine ve
           
private  java.util.Map velConfig
           
 
Constructor Summary
DVSL()
           
 
Method Summary
private  void configureVelocityEngine(org.apache.velocity.app.VelocityEngine ve, java.util.Map map)
           Adds the allowed properties from the Properties to the velocity engine So far, we support, in RuntimeConstant parlance : VM_LIBRARY FILE_RESOURCE_LOADER_PATH RUNTIME_LOG RUNTIME_LOG_LOGSYSTEM RUNTIME_LOG_LOGSYSTEM_CLASS If you are going to use this, ensure you do it *before* setting the stylesheet, as that creates the VelocityEngine
 java.lang.Object getAppValue(java.lang.Object key)
          Gets the application value for the specified key
static void main(java.lang.String[] args)
           Allows command-line access.
protected  void makeReady()
          sets up all the context goodies
 java.lang.Object putAppValue(java.lang.Object key, java.lang.Object value)
          Sets the application value for the specified key
 void setClassLoader(java.lang.ClassLoader classLoader)
           Specify a classloader for loading the Toolbox classes.
 void setLogChute(org.apache.velocity.runtime.log.LogChute logger)
           lets the user specify a class instance for logging.
 void setLogFile(java.io.File logFile)
           lets the user specify a filename for logging.
 void setLogSystem(org.apache.velocity.runtime.log.LogSystem logger)
          Deprecated. use setLogChute instead
 void setStylesheet(java.io.File stylesheet)
          Convenience function.
 void setStylesheet(java.io.File stylesheet, java.lang.String stylesheetEncoding)
          Convenience function.
 void setStylesheet(java.io.Reader styleReader)
           Sets the stylesheet for this transformation set Note that don't need this for each document you want to transform.
 void setStylesheet(java.lang.String stylesheet)
          Convenience function.
 void setToolbox(java.util.Properties p)
           Loads the toolbox from the input Properties.
 void setUserContext(org.apache.velocity.context.Context ctx)
           Sets the user context.
 void setValidatingParser(boolean validate)
           Uses a validating parser on all input documents
 void setVelocityConfig(java.util.Map map)
           lets the user pass a java.util.Properties containing properties for the configuration of the VelocityEngine used by DVSL
 long transform(org.dom4j.Document dom4jdoc, java.io.Writer writer)
          Transforms the given dom4j Document into the writer.
 long transform(java.io.File f, java.io.Writer writer)
           
 long transform(java.io.InputStream is, java.io.Writer writer)
           
 long transform(java.io.Reader reader, java.io.Writer writer)
           
 long transform(java.lang.String infile, java.io.Writer writer)
           
protected  long xform(org.dom4j.Document dom4jdoc, java.io.Writer writer)
           
protected  long xform(java.io.Reader reader, java.io.Writer writer)
          does the transformation of the inputstream into the output writer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOOL_PROP_PREFIX

private static java.lang.String TOOL_PROP_PREFIX

STRING_PROP_PREFIX

private static java.lang.String STRING_PROP_PREFIX

INTEGER_PROP_PREFIX

private static java.lang.String INTEGER_PROP_PREFIX

TOOLBOX_NAME

private static java.lang.String TOOLBOX_NAME

ve

private org.apache.velocity.app.VelocityEngine ve

currentDocument

private org.dom4j.Document currentDocument

currentWriter

private java.io.Writer currentWriter

toolContext

private org.apache.velocity.context.Context toolContext

userContext

private org.apache.velocity.context.Context userContext

styleContext

private org.apache.velocity.context.Context styleContext

baseContext

private DVSLContext baseContext

transformer

private Transformer transformer

classLoader

private java.lang.ClassLoader classLoader

ready

private boolean ready

velConfig

private java.util.Map velConfig

logFile

private java.io.File logFile

logger

private org.apache.velocity.runtime.log.LogChute logger

appVals

private java.util.Map appVals

templateHandler

private TemplateHandler templateHandler

validate

boolean validate
Constructor Detail

DVSL

public DVSL()
Method Detail

setLogFile

public void setLogFile(java.io.File logFile)

lets the user specify a filename for logging.


setLogSystem

public void setLogSystem(org.apache.velocity.runtime.log.LogSystem logger)
Deprecated. use setLogChute instead

lets the user specify a class instance for logging.


setLogChute

public void setLogChute(org.apache.velocity.runtime.log.LogChute logger)

lets the user specify a class instance for logging.


setVelocityConfig

public void setVelocityConfig(java.util.Map map)

lets the user pass a java.util.Properties containing properties for the configuration of the VelocityEngine used by DVSL


setUserContext

public void setUserContext(org.apache.velocity.context.Context ctx)

Sets the user context. The user context is a Velocity Context containing user-supplied objects and data that are to be made available in the template

Parameters:
ctx - User context of data

setValidatingParser

public void setValidatingParser(boolean validate)

Uses a validating parser on all input documents

Parameters:
validate -

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)

Specify a classloader for loading the Toolbox classes. Setting to null resets to the default ClassLoader.

Parameters:
classLoader - ClassLoader or null for default ClassLoader

setToolbox

public void setToolbox(java.util.Properties p)
                throws java.lang.ClassNotFoundException,
                       java.lang.InstantiationException,
                       java.lang.IllegalAccessException

Loads the toolbox from the input Properties.

Currently supports specification of the Toolbox name in the context, creating classes, and string and integer values. Ex :

  toolbox.contextname = floyd
  toolbox.tool.footool = Footool
  toolbox.string.mystring = Hello there!
  toolbox.integer.myint = 7
  toolbox.string.sourcebase = ./xdocs/
  

So in template, this toolbox and it's values would be accessed as :

    $context.floyd.footool.getFoo()
    $context.floyd.mystring
    $context.floyd.myint
  

Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

setStylesheet

public void setStylesheet(java.lang.String stylesheet)
                   throws java.lang.Exception
Convenience function. See...

Throws:
java.lang.Exception

setStylesheet

public void setStylesheet(java.io.File stylesheet)
                   throws java.lang.Exception
Convenience function. See...

Throws:
java.lang.Exception

setStylesheet

public void setStylesheet(java.io.File stylesheet,
                          java.lang.String stylesheetEncoding)
                   throws java.lang.Exception
Convenience function. See...

Throws:
java.lang.Exception

setStylesheet

public void setStylesheet(java.io.Reader styleReader)
                   throws java.lang.Exception

Sets the stylesheet for this transformation set

Note that don't need this for each document you want to transform. Just do it once, and transform away...

Parameters:
styleReader - Reader with stylesheet char stream
Throws:
java.lang.Exception

configureVelocityEngine

private void configureVelocityEngine(org.apache.velocity.app.VelocityEngine ve,
                                     java.util.Map map)

Adds the allowed properties from the Properties to the velocity engine

So far, we support, in RuntimeConstant parlance :

If you are going to use this, ensure you do it *before* setting the stylesheet, as that creates the VelocityEngine


makeReady

protected void makeReady()
sets up all the context goodies


xform

protected long xform(java.io.Reader reader,
                     java.io.Writer writer)
              throws java.lang.Exception
does the transformation of the inputstream into the output writer

Throws:
java.lang.Exception

xform

protected long xform(org.dom4j.Document dom4jdoc,
                     java.io.Writer writer)
              throws java.lang.Exception
Throws:
java.lang.Exception

transform

public long transform(java.io.File f,
                      java.io.Writer writer)
               throws java.lang.Exception
Throws:
java.lang.Exception

transform

public long transform(java.io.Reader reader,
                      java.io.Writer writer)
               throws java.lang.Exception
Throws:
java.lang.Exception

transform

public long transform(java.io.InputStream is,
                      java.io.Writer writer)
               throws java.lang.Exception
Throws:
java.lang.Exception

transform

public long transform(org.dom4j.Document dom4jdoc,
                      java.io.Writer writer)
               throws java.lang.Exception
Transforms the given dom4j Document into the writer.

Parameters:
dom4jdoc - dom4j Document object
writer - Writer for output
Throws:
java.lang.Exception

transform

public long transform(java.lang.String infile,
                      java.io.Writer writer)
               throws java.lang.Exception
Throws:
java.lang.Exception

getAppValue

public java.lang.Object getAppValue(java.lang.Object key)
Gets the application value for the specified key

Parameters:
key - key to use to retrieve value
Returns:
value if found, null otherwise

putAppValue

public java.lang.Object putAppValue(java.lang.Object key,
                                    java.lang.Object value)
Sets the application value for the specified key

Parameters:
key - key to use to store value
value - value to be stored
Returns:
old value if any, null otherwise

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception

Allows command-line access.

Usage : java -jar dvsl.jar -STYLE stylesheeet [-IN infile] [-OUT outfile] [-TOOL toolboxname]

Throws:
java.lang.Exception


Copyright (c) 2001-2007 Apache Software Foundation