geirm 01/02/11 20:19:07
Modified: src/java/org/apache/velocity/app Velocity.java
Log:
Support our columnaristically challenged bretheren...
(no functional changes - just formatting...)
Revision Changes Path
1.3 +73 -38 jakarta-velocity/src/java/org/apache/velocity/app/Velocity.java
Index: Velocity.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/app/Velocity.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Velocity.java 2001/02/12 01:25:06 1.2
+++ Velocity.java 2001/02/12 04:19:07 1.3
@@ -80,13 +80,14 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="[EMAIL PROTECTED]">Christoph Reck</a>
- * @version $Id: Velocity.java,v 1.2 2001/02/12 01:25:06 geirm Exp $
+ * @version $Id: Velocity.java,v 1.3 2001/02/12 04:19:07 geirm Exp $
*/
public class Velocity
{
/**
- * initialize the Velocity runtime engine, using the default properties of the
Velocity distribution
+ * initialize the Velocity runtime engine, using the default
+ * properties of the Velocity distribution
*
* @return true if successful, false otherwise
*/
@@ -99,7 +100,8 @@
}
catch(Exception e )
{
- System.out.println("Velocity.init() : Velocity init exception : " + e);
+ System.out.println("Velocity.init() : Velocity init exception : "
+ + e);
return true;
}
}
@@ -108,9 +110,11 @@
* initialize the Velocity runtime engine, using default properties
* plus the properties in the properties file passed in as the arg
*
- * @param propsFilename file containing properties to use to initialize the
Velocity runtime
+ * @param propsFilename file containing properties to use to initialize
+ * the Velocity runtime
*
- * @return true if successful, false otherwise. Check runtime log if false
+ * @return true if successful, false otherwise. Check runtime log if
+ * false
*/
public static boolean init( String propsFilename )
{
@@ -121,7 +125,9 @@
}
catch(Exception e )
{
- System.out.println("Velocity.init( filename ) : Velocity init exception
: " + e);
+ System.out.println("Velocity.init( filename ) : "
+ + "Velocity init exception : "
+ + e);
return false;
}
}
@@ -143,40 +149,52 @@
}
catch(Exception e )
{
- System.out.println("Velocity.init( props ) : Velocity init exception :
" + e);
+ System.out.println("Velocity.init( props ) : "
+ + " Velocity init exception : "
+ + e);
return false;
}
}
/**
- * renders the input string using the context into the output writer. To be
used when a template is
- * dynamically constructed, or want to use Velocity as a token replacer.
+ * renders the input string using the context into the output writer.
+ * To be used when a template is dynamically constructed, or want to use
+ * Velocity as a token replacer.
*
* @param context context to use in rendering input string
* @param out Writer in which to render the output
- * @param logTag string to be used as the template name for log messages in
case of error
+ * @param logTag string to be used as the template name for log
+ * messages in case of error
* @param instring input string containing the VTL to be rendered
*
- * @return true if successful, false otherwise. If false, see Velocity
runtime log
+ * @return true if successful, false otherwise. If false, see
+ * Velocity runtime log
*/
- public static boolean evaluate( Context context, Writer out, String logTag,
String instring )
+ public static boolean evaluate( Context context, Writer out,
+ String logTag, String instring )
{
- ByteArrayInputStream inStream = new ByteArrayInputStream(
instring.getBytes() );
+ ByteArrayInputStream inStream =
+ new ByteArrayInputStream( instring.getBytes() );
+
return evaluate( context, out, logTag, inStream );
}
/**
- * renders the input stream using the context into the output writer. To be
used when a template is
- * dynamically constructed, or want to use Velocity as a token replacer.
+ * Renders the input stream using the context into the output writer.
+ * To be used when a template is dynamically constructed, or want to
+ * use Velocity as a token replacer.
*
* @param context context to use in rendering input string
* @param out Writer in which to render the output
- * @param logTag string to be used as the template name for log messages in
case of error
+ * @param logTag string to be used as the template name for log messages
+ * in case of error
* @param instream input stream containing the VTL to be rendered
*
- * @return true if successful, false otherwise. If false, see Velocity
runtime log
+ * @return true if successful, false otherwise. If false, see
+ * Velocity runtime log
*/
- public static boolean evaluate( Context context, Writer writer, String logTag,
InputStream instream )
+ public static boolean evaluate( Context context, Writer writer,
+ String logTag, InputStream instream )
{
SimpleNode nodeTree = null;
@@ -186,7 +204,9 @@
if (nodeTree != null)
{
- InternalContextAdapterImpl ica = new InternalContextAdapterImpl(
context );
+ InternalContextAdapterImpl ica =
+ new InternalContextAdapterImpl( context );
+
ica.pushCurrentTemplateName( logTag );
nodeTree.init( ica, null );
@@ -204,7 +224,8 @@
}
catch( Exception e )
{
- Runtime.error("Velocity.evaluate() : tag = " + logTag + " : " + e );
+ Runtime.error("Velocity.evaluate() : tag = "
+ + logTag + " : " + e );
}
return false;
@@ -217,18 +238,22 @@
* Note : currently only accepts args to the VM if they are in the context.
*
* @param vmName name of Velocimacro to call
- * @param params[] args used to invoke Velocimacro. In context key format : eg
"foo","bar" (rather than "$foo","$bar")
+ * @param params[] args used to invoke Velocimacro. In context key format :
+ * eg "foo","bar" (rather than "$foo","$bar")
* @param context Context object containing data/objects used for rendering.
* @param writer Writer for output stream
* @return true if Velocimacro exists and successfully invoked, false
otherwise.
*/
- public static boolean invokeVelocimacro( String vmName, String namespace,
String params[], Context context, Writer writer )
+ public static boolean invokeVelocimacro( String vmName, String namespace,
+ String params[], Context context,
+ Writer writer )
{
/*
* check parms
*/
- if ( vmName == null || params == null || context == null || writer ==
null || namespace == null)
+ if ( vmName == null || params == null || context == null
+ || writer == null || namespace == null)
{
Runtime.error( "Velocity.invokeVelocimacro() : invalid parameter");
return false;
@@ -237,10 +262,11 @@
/*
* does the VM exist?
*/
-
+
if (!Runtime.isVelocimacro( vmName, namespace ))
{
- Runtime.error( "Velocity.invokeVelocimacro() : VM '"+ vmName+"' not
registered.");
+ Runtime.error( "Velocity.invokeVelocimacro() : VM '"+ vmName
+ + "' not registered.");
return false;
}
@@ -248,22 +274,27 @@
* apparently. Ok, make one..
*/
- VelocimacroProxy vp = (VelocimacroProxy) Runtime.getVelocimacro( vmName,
namespace );
+ VelocimacroProxy vp =
+ (VelocimacroProxy) Runtime.getVelocimacro( vmName, namespace );
if ( vp == null )
{
- Runtime.error( "Velocity.invokeVelocimacro() : VM '" + vmName + "' :
severe error. Unable to get VM from factory.");
+ Runtime.error( "Velocity.invokeVelocimacro() : VM '"
+ + vmName
+ + "' : severe error. Unable to get VM from factory.");
return false;
}
-
+
/*
* if we get enough args?
*/
if ( vp.getNumArgs() > params.length )
{
- Runtime.error( "Velocity.invokeVelocimacro() : VM '" + vmName + "' :
invalid # of args. Needed "
- + vp.getNumArgs() + " but called with " + params.length);
+ Runtime.error( "Velocity.invokeVelocimacro() : VM '"
+ + vmName + "' : invalid # of args. Needed "
+ + vp.getNumArgs()
+ + " but called with " + params.length);
return false;
}
@@ -272,7 +303,8 @@
*/
/*
- * fix the parms : since we don't require the $ from the caller, we need
to add it
+ * fix the parms : since we don't require the $ from the caller,
+ * we need to add it
*/
int [] types = new int[vp.getNumArgs()];
@@ -288,7 +320,8 @@
try
{
- InternalContextAdapterImpl ica = new InternalContextAdapterImpl(
context );
+ InternalContextAdapterImpl ica
+ = new InternalContextAdapterImpl( context );
try
{
@@ -316,9 +349,11 @@
* @param context filled context to be used in merge
* @param writer writer to write template into
*
- * @return true if successful, false otherwise. Errors logged to velocity log.
+ * @return true if successful, false otherwise. Errors
+ * logged to velocity log.
*/
- public static boolean mergeTemplate( String templateName, Context context,
Writer writer )
+ public static boolean mergeTemplate( String templateName,
+ Context context, Writer writer )
{
try
{
@@ -326,7 +361,8 @@
if ( template == null )
{
- Runtime.error("Velocity.parseTemplate() failed loading template '"
+ templateName + "'" );
+ Runtime.error("Velocity.parseTemplate() failed loading template '"
+ + templateName + "'" );
}
else
{
@@ -337,11 +373,10 @@
}
catch( Exception e )
{
- Runtime.error("Velocity.parseTemplate() with " + templateName + " : " +
e );
+ Runtime.error("Velocity.parseTemplate() with "
+ + templateName + " : " + e );
}
return false;
}
}
-
-