private void initVelocity() throws InitializationException
{
/*
* Get the configuration for this service.
*/
Configuration configuration = getConfiguration();
/*
* Now we have to perform a couple of path translations
* for our log file and template paths.
*/
String path = Turbine.getRealPath
(configuration.getString(Velocity.RUNTIME_LOG, null));
if (StringUtils.isValid(path))
{
configuration.setProperty(Velocity.RUNTIME_LOG, path);
}
else
{
String msg = VelocityService.SERVICE_NAME + " runtime log file " +
"is misconfigured: '" + path + "' is not a valid log file";
if (TurbineServlet.getServletConfig() instanceof TurbineConfig)
{
msg += ": TurbineConfig users must use a path relative to " +
"web application root";
}
throw new Error(msg);
}
/*
* Get all the template paths where the velocity runtime should search
* for templates and collect them into a separate vector to avoid
* concurrent modification exceptions.
*/
String key;
Vector keys = new Vector();
for (Iterator i = configuration.getKeys(); i.hasNext();)
{
key = (String) i.next();
if (key.endsWith(RESOURCE_LOADER_PATH))
{
keys.add(key);
}
}
/*
* Loop through all template paths, clear the corresponding
* velocity properties and translate them all to the webapp space.
*/
int ind;
Vector paths;
String entry;
for (Iterator i = keys.iterator(); i.hasNext();)
{
key = (String) i.next();
paths = configuration.getVector(key,null);
if (paths != null)
{
Velocity.clearProperty(key);
configuration.clearProperty(key);
for (Iterator j = paths.iterator(); j.hasNext();)
{
path = (String) j.next();
if (path.startsWith(JAR_PREFIX + "file"))
{
/*
* A local jar resource URL path is a bit more
* complicated, but we can translate it as well.
*/
ind = path.indexOf("!/");
if (ind >= 0)
{
entry = path.substring(ind);
path = path.substring(9,ind);
}
else
{
entry = "!/";
path = path.substring(9);
}
path = JAR_PREFIX + "file:" +
Turbine.getRealPath(path) + entry;
}
else if (path.startsWith(ABSOLUTE_PREFIX))
{
path = path.substring (ABSOLUTE_PREFIX.length(),
path.length());
}
else if (!path.startsWith(JAR_PREFIX))
{
// But we don't translate remote jar URLs.
path = Turbine.getRealPath(path);
}
// Put the translated paths back to the configuration.
configuration.addProperty(key,path);
}
}
}
try
{