On Thu, Jun 19, 2008 at 9:20 AM, Joe Reger, Jr. <[EMAIL PROTECTED]> wrote:
> 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();
you need to tell the VelocityEngine to use the StringResourceLoader,
so that it can initialize the repository for you. see below for more
questions...
> 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.
what properties did you set? they should have been these:
resource.loader = string
string.resource.loader.class =
org.apache.velocity.runtime.resource.loader.StringResourceLoader
> Thanks,
>
> Joe
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]