* simple habit... we prollie don't have an AST beneath us
*/
super.init(context, data);
RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
/*
* the stringlit is set at template parse time, so we can do this here
* for now. if things change and we can somehow create stringlits at
* runtime, this must move to the runtime execution path
*
* so, only if interpolation is turned on AND it starts with a " AND it
* has a directive or reference, then we can interpolate. Otherwise,
* don't bother.
*/
Token ff=tokens.get(0);
interpolate = rsvc.getBoolean(
RuntimeConstants.INTERPOLATE_STRINGLITERALS, true)
&& ff.image.startsWith("\"")
&& ((ff.image.indexOf('$') != -1) || (ff.image
.indexOf('#') != -1));
/*
* get the contents of the string, minus the '/" at each end
*/
String img = ff.image;
image = img.substring(1, img.length() - 1);
if (img.startsWith("\""))
{
image = unescape(image);
}
if (img.charAt(0) == '"' || img.charAt(0) == '\'' )
{
// replace double-double quotes like "" with a single double quote "
// replace double single quotes '' with a single quote '
image = replaceQuotes(image, img.charAt(0));
}
/**
* note. A kludge on a kludge. The first part, Geir calls this the
* dreaded <MORE> kludge. Basically, the use of the <MORE> token eats
* the last character of an interpolated string. EXCEPT when a line
* comment (##) is in the string this isn't an issue.
*
* So, to solve this we look for a line comment. If it isn't found we
* add a space here and remove it later.
*/
/**
* Note - this should really use a regexp to look for [^\]## but
* apparently escaping of line comments isn't working right now anyway.
*/
containsLineComment = (image.indexOf("##") != -1);
/*
* if appropriate, tack a space on the end (dreaded <MORE> kludge)
*/
String interpolateimage=null;
if (!containsLineComment)
{
interpolateimage = image + " ";
}
else
{
interpolateimage = image;
}
if (interpolate)
{
/*
* now parse and init the nodeTree
*/
StringReader br = new StringReader(interpolateimage);
/*
* it's possible to not have an initialization context - or we don't
* want to trust the caller - so have a fallback value if so
*
* Also, do *not* dump the VM namespace for this template
*/
String templateName =
(context != null) ? context.getCurrentTemplateName() : "StringLiteral";
try
{
nodeTree = rsvc.parse(br, templateName, false);
}
catch (ParseException e)
{
String msg = "Failed to parse String literal at "+
VelocityException.formatFileString(templateName, getLine(), getColumn());