Class DVSL
- java.lang.Object
-
- org.apache.dvsl.DVSL
-
public class DVSL extends java.lang.ObjectMain DVSL class - use this as the helper class for apps- Author:
- Geir Magnusson Jr., Bill Burton.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDVSL.LogAdapter
-
Field Summary
Fields Modifier and Type Field Description private java.util.MapappValsprivate DVSLContextbaseContextprivate java.lang.ClassLoaderclassLoaderprivate org.dom4j.DocumentcurrentDocumentprivate java.io.WritercurrentWriterprivate static java.lang.StringINTEGER_PROP_PREFIXprivate java.io.FilelogFileprivate org.apache.velocity.runtime.log.LogChuteloggerprivate booleanreadyprivate static java.lang.StringSTRING_PROP_PREFIXprivate org.apache.velocity.context.ContextstyleContextprivate TemplateHandlertemplateHandlerprivate static java.lang.StringTOOL_PROP_PREFIXprivate static java.lang.StringTOOLBOX_NAMEprivate org.apache.velocity.context.ContexttoolContextprivate Transformertransformerprivate org.apache.velocity.context.ContextuserContext(package private) booleanvalidateprivate org.apache.velocity.app.VelocityEngineveprivate java.util.MapvelConfig
-
Constructor Summary
Constructors Constructor Description DVSL()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidconfigureVelocityEngine(org.apache.velocity.app.VelocityEngine ve, java.util.Map map)Adds the allowed properties from the Properties to the velocity enginejava.lang.ObjectgetAppValue(java.lang.Object key)Gets the application value for the specified keystatic voidmain(java.lang.String[] args)Allows command-line access.protected voidmakeReady()sets up all the context goodiesjava.lang.ObjectputAppValue(java.lang.Object key, java.lang.Object value)Sets the application value for the specified keyvoidsetClassLoader(java.lang.ClassLoader classLoader)Specify a classloader for loading the Toolbox classes.voidsetLogChute(org.apache.velocity.runtime.log.LogChute logger)lets the user specify a class instance for logging.voidsetLogFile(java.io.File logFile)lets the user specify a filename for logging.voidsetLogSystem(org.apache.velocity.runtime.log.LogSystem logger)Deprecated.use setLogChute insteadvoidsetStylesheet(java.io.File stylesheet)Convenience function.voidsetStylesheet(java.io.File stylesheet, java.lang.String stylesheetEncoding)Convenience function.voidsetStylesheet(java.io.Reader styleReader)Sets the stylesheet for this transformation setvoidsetStylesheet(java.lang.String stylesheet)Convenience function.voidsetToolbox(java.util.Properties p)Loads the toolbox from the input Properties.voidsetUserContext(org.apache.velocity.context.Context ctx)Sets the user context.voidsetValidatingParser(boolean validate)Uses a validating parser on all input documentsvoidsetVelocityConfig(java.util.Map map)lets the user pass a java.util.Properties containing properties for the configuration of the VelocityEngine used by DVSLlongtransform(java.io.File f, java.io.Writer writer)longtransform(java.io.InputStream is, java.io.Writer writer)longtransform(java.io.Reader reader, java.io.Writer writer)longtransform(java.lang.String infile, java.io.Writer writer)longtransform(org.dom4j.Document dom4jdoc, java.io.Writer writer)Transforms the given dom4j Document into the writer.protected longxform(java.io.Reader reader, java.io.Writer writer)does the transformation of the inputstream into the output writerprotected longxform(org.dom4j.Document dom4jdoc, java.io.Writer writer)
-
-
-
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
-
-
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 insteadlets 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.IllegalAccessExceptionLoads 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.ClassNotFoundExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessException
-
setStylesheet
public void setStylesheet(java.lang.String stylesheet) throws java.lang.ExceptionConvenience function. See...- Throws:
java.lang.Exception
-
setStylesheet
public void setStylesheet(java.io.File stylesheet) throws java.lang.ExceptionConvenience function. See...- Throws:
java.lang.Exception
-
setStylesheet
public void setStylesheet(java.io.File stylesheet, java.lang.String stylesheetEncoding) throws java.lang.ExceptionConvenience function. See...- Throws:
java.lang.Exception
-
setStylesheet
public void setStylesheet(java.io.Reader styleReader) throws java.lang.ExceptionSets 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 :
- 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
-
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.Exceptiondoes 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.ExceptionTransforms the given dom4j Document into the writer.- Parameters:
dom4jdoc- dom4j Document objectwriter- 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 valuevalue- value to be stored- Returns:
- old value if any, null otherwise
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionAllows command-line access.
Usage : java -jar dvsl.jar -STYLE stylesheeet [-IN infile] [-OUT outfile] [-TOOL toolboxname]
- Throws:
java.lang.Exception
-
-