Examples of StringResourceRepository


Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

   */
  public String render(String templateName, String templateSource) throws CRException {
    String renderedTemplate = null;
    long s1 = System.currentTimeMillis();

    StringResourceRepository rep = StringResourceLoader.getRepository();
    if (rep == null) {
      rep = new StringResourceRepositoryImpl();
      StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT, rep);
    }
    rep.setEncoding(this.encoding);
    try {

      Template template = this.templates.get(templateName);
      if (template == null) {
        rep.putStringResource(templateName, templateSource);

        template = Velocity.getTemplate(templateName);
        rep.removeStringResource(templateName);
        this.templates.put(templateName, template);
      }

      VelocityContext context = new VelocityContext();
      Iterator<String> it = this.objectstoput.keySet().iterator();
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

    if (cache != null) {
      template = (Template) cache.get(name + source);
    }

    if (template == null) {
      StringResourceRepository rep = StringResourceLoader.getRepository();
      rep.setEncoding(encoding);
      rep.putStringResource(name, source);
      try {
        template = Velocity.getTemplate(name);
      } catch (ResourceNotFoundException e1) {
        log.warn("Could not create Velocity Template.", e1);
      } catch (ParseErrorException e1) {
        log.warn("Could not create Velocity Template.", e1);
      } catch (Exception e1) {
        log.warn("Could not create Velocity Template.", e1);
      }
      rep.removeStringResource(name);
      if (cache != null) {
        try {
          cache.put(name + source, template);
        } catch (CacheException e) {
          log.warn("Could not put Velocity Template to cache.");
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

        if (log.isDebugEnabled())
        {
            log.debug("Creating string repository using class "+className+"...");
        }

        StringResourceRepository repo;
        try
        {
            repo = (StringResourceRepository) ClassUtils.getNewInstance(className);
        }
        catch (ClassNotFoundException cnfe)
        {
            throw new VelocityException("Could not find '" + className + "'", cnfe);
        }
        catch (IllegalAccessException iae)
        {
            throw new VelocityException("Could not access '" + className + "'", iae);
        }
        catch (InstantiationException ie)
        {
            throw new VelocityException("Could not instantiate '" + className + "'", ie);
        }

        if (encoding != null)
        {
            repo.setEncoding(encoding);
        }
        else
        {
            repo.setEncoding(REPOSITORY_ENCODING_DEFAULT);
        }

        if (log.isDebugEnabled())
        {
            log.debug("Default repository encoding is " + repo.getEncoding());
        }
        return repo;
    }
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

        // extension hook
    }

    protected StringResourceRepository getStringRepository()
    {
        StringResourceRepository repo =
            (StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
        if (repo == null)
        {
            engine.init();
            repo =
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

        Velocity.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
        Velocity.addProperty("string.resource.loader.modificationCheckInterval", "1");
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());
        Velocity.init();

        StringResourceRepository repo = getRepo(null, null);

        // this will fail when run as part of suite of tests in one process
        // but it's only required for several tests
        if (repo != null)
        {
            repo.putStringResource("foo", "This is $foo");
            repo.putStringResource("bar", "This is $bar");
        }

        context = new VelocityContext();
        context.put("foo", "wonderful!");
        context.put("bar", "horrible!");
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

    public void testAlternateStaticRepo() throws Exception
    {
        VelocityEngine engine = newStringEngine("alternate.repo", true);
        // should be null be for init
        StringResourceRepository repo = getRepo("alternate.repo", null);
        assertNull(repo);
        engine.init();
        // and not null after init
        repo = getRepo("alternate.repo", null);
        assertNotNull(repo);
        repo.putStringResource("foo", "This is NOT $foo");

        // get and merge template with the same name from both runtimes with the same context
        String engineOut = render(engine.getTemplate("foo"));
        String singletonOut = render(RuntimeSingleton.getTemplate("foo"));
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

    public void testAppRepo() throws Exception
    {
        VelocityEngine engine = newStringEngine(null, false);
        engine.init();

        StringResourceRepository repo = getRepo(null, engine);
        assertNotNull(repo);
        repo.putStringResource("woogie", "What is $woogie?");

        String out = render(engine.getTemplate("woogie"));
        assertEquals(out, "What is a woogie?");
    }
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

    public void testAlternateAppRepo() throws Exception
    {
        VelocityEngine engine = newStringEngine("alternate.app.repo", false);
        engine.init();

        StringResourceRepository repo = getRepo("alternate.app.repo", engine);
        assertNotNull(repo);
        repo.putStringResource("you/foo.vm", "You look $foo");

        String out = render(engine.getTemplate("you/foo.vm"));
        assertEquals(out, "You look wonderful!");
    }
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

        Velocity.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
        Velocity.addProperty("string.resource.loader.modificationCheckInterval", "1");
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());
        Velocity.init();

        StringResourceRepository repo = getRepo(null, null);
        repo.putStringResource("foo", "This is $foo");
        repo.putStringResource("bar", "This is $bar");

        context = new VelocityContext();
        context.put("foo", "wonderful!");
        context.put("bar", "horrible!");
        context.put("woogie", "a woogie");
View Full Code Here

Examples of org.apache.velocity.runtime.resource.util.StringResourceRepository

    public void testAlternateStaticRepo() throws Exception
    {
        VelocityEngine engine = newStringEngine("alternate.repo", true);
        // should be null be for init
        StringResourceRepository repo = getRepo("alternate.repo", null);
        assertNull(repo);
        engine.init();
        // and not null after init
        repo = getRepo("alternate.repo", null);
        assertNotNull(repo);
        repo.putStringResource("foo", "This is NOT $foo");

        // get and merge template with the same name from both runtimes with the same context
        String engineOut = render(engine.getTemplate("foo"));
        String singletonOut = render(RuntimeSingleton.getTemplate("foo"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.