jon 00/12/17 14:05:42
Modified: src/java/org/apache/velocity/runtime Runtime.java
Log:
code cleanup. no real functional changes
Revision Changes Path
1.70 +72 -34
jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java
Index: Runtime.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- Runtime.java 2000/12/17 21:54:42 1.69
+++ Runtime.java 2000/12/17 22:05:42 1.70
@@ -154,7 +154,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jeff Bowden</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magusson Jr.</a>
- * @version $Id: Runtime.java,v 1.69 2000/12/17 21:54:42 jon Exp $
+ * @version $Id: Runtime.java,v 1.70 2000/12/17 22:05:42 jon Exp $
*/
public class Runtime implements RuntimeConstants
{
@@ -236,7 +236,6 @@
/**
* Initializes the Velocity Runtime.
*/
-
public synchronized static void init( Properties p )
throws Exception
{
@@ -246,20 +245,17 @@
/*
* set the default properties, and don't call assembleSourceInitializers()
*/
-
setDefaultProperties( false);
/*
* now add the new ones from the calling app
*/
-
if (p != null)
addPropertiesFromProperties( p );
/*
* now call init to do the real work
*/
-
init();
initializedPublic = true;
@@ -271,7 +267,6 @@
/*
* if we have been initialized fully, don't do it again
*/
-
if (initializedPublic)
return;
@@ -281,18 +276,15 @@
* then load the local properties to layover the default ones. This
should make
* life easy for users.
*/
-
setDefaultProperties( false );
/*
* if we were passed propertis, try loading propertiesFile as a straight
file first,
* if that fails, then try and use the classpath
*/
-
if (propertiesFileName != null && !propertiesFileName.equals(""))
{
File file = new File(propertiesFileName);
-
try
{
if( file.exists() )
@@ -307,14 +299,17 @@
/*
* lets try the classpath
*/
-
ClassLoader classLoader = Runtime.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(
propertiesFileName );
if (inputStream!= null)
+ {
addPropertiesFromStream( inputStream, propertiesFileName );
+ }
else
+ {
info ("Override Properties : " + propertiesFileName + " not
found in classpath.");
+ }
}
}
catch (Exception ex)
@@ -326,9 +321,7 @@
/*
* now call init to do the real work
*/
-
init();
-
initializedPublic = true;
}
@@ -343,7 +336,6 @@
/*
* lets load the properties, and then iterate them out
*/
-
Properties p = new Properties();
p.load( is );
@@ -363,14 +355,12 @@
/*
* iterate them out
*/
-
for (Enumeration e = p.keys(); e.hasMoreElements() ; )
{
String s = (String) e.nextElement();
VelocityResources.setProperty( s, p.getProperty(s) );
info (" ** Property Override : " + s + " = " + p.getProperty(s));
}
-
return true;
}
@@ -460,7 +450,9 @@
info ("Properties File: " + new
File(propertiesFileName).getAbsolutePath());
}
else
+ {
throw new Exception("Cannot find " + propertiesFileName + "!");
+ }
}
}
@@ -484,7 +476,9 @@
VelocityResources.setPropertiesInputStream( inputStream );
if (doAssoc)
+ {
assembleSourceInitializers();
+ }
info ("Default Properties File: " + new
File(DEFAULT_RUNTIME_PROPERTIES).getPath());
}
@@ -536,9 +530,10 @@
* iterate and log each individual message...
*/
for( Enumeration e = pendingMessages.elements(); e.hasMoreElements(); )
+ {
logger.info( (String) e.nextElement());
+ }
}
-
Runtime.info("Log file being used is: " + new
File(logFile).getAbsolutePath());
}
@@ -553,7 +548,9 @@
private static void initializeTemplateLoader() throws Exception
{
if(!sourceInitializersAssembled)
+ {
assembleSourceInitializers();
+ }
templateLoaders = new ArrayList();
@@ -585,7 +582,9 @@
Enumeration e = VelocityResources.getKeys(loaderID);
if (!e.hasMoreElements())
+ {
continue;
+ }
Hashtable sourceInitializer = new Hashtable();
@@ -605,11 +604,11 @@
* template.loader.1.template.path and the translated
* name would be used to set the property.
*/
-
if (property.equals("public.name"))
+ {
sourceInitializerMap.put(value, sourceInitializer);
+ }
}
-
sourceInitializerList.add(sourceInitializer);
sourceInitializersAssembled = true;
}
@@ -654,7 +653,6 @@
* are all class names for example:
*
* org.apache.velocity.runtime.directive.Foreach
- *
*/
Enumeration directiveClasses = directiveProperties.elements();
@@ -745,8 +743,9 @@
return AST;
}
else
+ {
error("Runtime : ran out of parsers!");
-
+ }
return null;
}
@@ -763,11 +762,17 @@
globalCache = new Hashtable();
}
+ /**
+ * These are the paths used by #include
+ */
private static void initializeIncludePaths()
{
includePaths = VelocityResources.getStringArray(INCLUDE_PATHS);
}
+ /**
+ * These are the paths used by #include
+ */
public static String[] getIncludePaths()
{
return includePaths;
@@ -817,7 +822,6 @@
Template t= null;
TemplateLoader tl = null;
-
/*
* Check to see if the template was placed in the cache.
* If it was placed in the cache then we will use
@@ -838,7 +842,6 @@
* the input stream and parse it to make a new
* AST for the template.
*/
-
if (t.requiresChecking() && tl.isSourceModified(t))
{
try
@@ -870,7 +873,6 @@
* which one gives us a stream that we can use to
* make a template with.
*/
-
for (int i = 0; i < templateLoaders.size(); i++)
{
tl = (TemplateLoader) templateLoaders.get(i);
@@ -888,7 +890,9 @@
* Return null if we can't find a template.
*/
if (is == null)
+ {
throw new Exception("Can't find " + template + "!");
+ }
t.setLastModified(tl.getLastModified(t));
t.setModificationCheckInterval(tl.getModificationCheckInterval());
@@ -903,9 +907,10 @@
* Place the template in the cache if the template
* loader says to.
*/
-
if (tl.useCache())
+ {
globalCache.put(template, t);
+ }
}
catch (Exception e)
{
@@ -915,22 +920,36 @@
return t;
}
+ /**
+ * Handle logging
+ */
private static void log(String message)
{
if (logger != null)
+ {
logger.info(message);
+ }
else
+ {
pendingMessages.addElement(message);
+ }
}
- /** Log a warning message */
+ /**
+ * Log a warning message
+ */
public static void warn(Object message)
{
String out = null;
- if ( getBoolean(RUNTIME_LOG_WARN_STACKTRACE, false) && (message instanceof
Throwable || message instanceof Exception) )
+ if ( getBoolean(RUNTIME_LOG_WARN_STACKTRACE, false) &&
+ (message instanceof Throwable || message instanceof Exception) )
+ {
out = StringUtils.stackTrace((Throwable)message);
+ }
else
+ {
out = message.toString();
+ }
log(WARN + out);
}
@@ -938,31 +957,50 @@
public static void info(Object message)
{
String out = null;
- if ( getBoolean(RUNTIME_LOG_INFO_STACKTRACE, false) && ( message instanceof
Throwable || message instanceof Exception) )
+ if ( getBoolean(RUNTIME_LOG_INFO_STACKTRACE, false) &&
+ ( message instanceof Throwable || message instanceof Exception) )
+ {
out = StringUtils.stackTrace((Throwable)message);
+ }
else
+ {
out = message.toString();
+ }
log(INFO + out);
}
- /** Log an error message */
+ /**
+ * Log an error message
+ */
public static void error(Object message)
{
String out = null;
- if ( getBoolean(RUNTIME_LOG_ERROR_STACKTRACE, false) && ( message
instanceof Throwable || message instanceof Exception ) )
+ if ( getBoolean(RUNTIME_LOG_ERROR_STACKTRACE, false) &&
+ ( message instanceof Throwable || message instanceof Exception ) )
+ {
out = StringUtils.stackTrace((Throwable)message);
+ }
else
+ {
out = message.toString();
+ }
log(ERROR + out);
}
- /** Log a debug message */
+ /**
+ * Log a debug message
+ */
public static void debug(Object message)
{
if (DEBUG_ON)
+ {
log(DEBUG + message.toString());
+ }
}
+ /**
+ * Why does Runtime have a main?
+ */
public static void main(String[] args) throws Exception
{
System.out.println(StringUtils.fileToURL(args[0]));
@@ -1002,9 +1040,11 @@
* @return boolean True if added, false if rejected for some reason (either
parameters or permission settings)
*/
public static boolean addVelocimacro( String strName, String strMacro, String
strArgArray[],
- String strMacroArray[], TreeMap
tmArgIndexMap, String strSourceTemplate )
+ String strMacroArray[], TreeMap
tmArgIndexMap,
+ String strSourceTemplate )
{
- return vmFactory.addVelocimacro( strName, strMacro, strArgArray,
strMacroArray, tmArgIndexMap, strSourceTemplate);
+ return vmFactory.addVelocimacro( strName, strMacro, strArgArray,
strMacroArray,
+ tmArgIndexMap, strSourceTemplate);
}
/**
@@ -1075,5 +1115,3 @@
return VelocityResources.getBoolean( strKey, def );
}
}
-
-