Hi all!
I'm trying to use a StringResourceRepository so that I can process dynamic
runtime templates.
I get the following error:
=========================
java.lang.IllegalStateException: RepositoryFactory was not properly set up
at
org.apache.velocity.runtime.resource.loader.StringResourceLoader$RepositoryFactory.getRepository(StringResourceLoader.java:274)
at
org.apache.velocity.runtime.resource.loader.StringResourceLoader.getRepository(StringResourceLoader.java:86)
My static method is:
=========================
public static String process(){
Logger logger = Logger.getLogger(TemplateProcessor.class);
StringBuffer out = new StringBuffer();
try{
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
context.put( "name", new String("Giddyup") );
Template template = null;
try{
StringResourceRepository repo =
StringResourceLoader.getRepository();
String myTemplateName = "pltemplate";
String myTemplate = "Hi, ${name}... what's a happennin'?";
repo.putStringResource(myTemplateName, myTemplate);
template = ve.getTemplate(myTemplateName);
} catch( ResourceNotFoundException rnfe ){
// couldn't find the template
logger.error("", rnfe);
} catch( ParseErrorException pee ){
// syntax error: problem parsing the template
logger.error("", pee);
} catch( MethodInvocationException mie ){
// something invoked in the template
logger.error("", mie);
} catch( Exception e ){
logger.error("", e);
}
StringWriter sw = new StringWriter();
template.merge( context, sw );
out.append(sw.toString());
} catch (Exception ex){
logger.error("", ex);
}
return out.toString();
}
What am I missing? I'd like to have all configuration done within this
static method. I'm running Velocity 1.5. I've seen some properties that
need to be set in the Javadoc. I set these in a Java Properties object and
used them to init() the vm but it still didn't work. Open to suggestions.
Thanks,
Joe