'Resource Loader Demo'에 해당되는 글 1건

  1. 2010.02.19 Resource Loader Demo
98..Etc/velocity2010. 2. 19. 18:11
반응형
import java.io.StringWriter;
import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class ResourceLoaders {

  private static final String FILE_RESOURCE_LOADER_TEMPLATE = "./src/ResourceLoader1.vm";

  private static final String JAR_RESOURCE_LOADER_TEMPLATE = "./src/ResourceLoader2.vm";

  private static final String CLASSPATH_RESOURCE_LOADER_TEMPLATE = "./src/ResourceLoader3.vm";

  public static void main(String[] args) throws Exception {
    processTemplate(FILE_RESOURCE_LOADER_TEMPLATE);
    processTemplate(FILE_RESOURCE_LOADER_TEMPLATE);
    processTemplate(JAR_RESOURCE_LOADER_TEMPLATE);
    processTemplate(JAR_RESOURCE_LOADER_TEMPLATE);
    processTemplate(CLASSPATH_RESOURCE_LOADER_TEMPLATE);
    processTemplate(CLASSPATH_RESOURCE_LOADER_TEMPLATE);
  }

  private static void processTemplate(String templateName) throws Exception {
    Velocity.init();
    Template template = Velocity.getTemplate(templateName);
    VelocityContext context = new VelocityContext();
    Writer writer = new StringWriter();
    template.merge(context, writer);
    System.out.println(writer.toString());
  }
}
-------------------------------------------------------------------------------------
//File: ResourceLoader1.vm
ResourceLoader1 Template!

//File: ResourceLoader2.vm
ResourceLoader2 Template Modified!


//File: ResourceLoader3.vm
ResourceLoader3 Template 3

           
Posted by 1010