Java 类org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader 实例源码

项目:jersey-mvc-velocity    文件:VelocityDefaultConfigurationFactory.java   
@Inject
public VelocityDefaultConfigurationFactory(@Optional final ServletContext servletContext) {
    String loader = "class";
    Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
    Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");

    if (servletContext != null) {
        Velocity.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getName());
        Velocity.setProperty("webapp.resource.loader.path", "/");
        Velocity.setApplicationAttribute("javax.servlet.ServletContext", servletContext);
        loader += ",webapp";
    }
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, loader);

    configuration = new Configuration();
}
项目:cas-5.1.0    文件:CoreSamlConfiguration.java   
@Lazy
@Bean(name = "shibboleth.VelocityEngine")
public VelocityEngineFactoryBean velocityEngineFactoryBean() {
    final VelocityEngineFactoryBean bean = new VelocityEngineFactoryBean();

    final Properties properties = new Properties();
    properties.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SLF4JLogChute.class.getName());
    properties.put(RuntimeConstants.INPUT_ENCODING, StandardCharsets.UTF_8.name());
    properties.put(RuntimeConstants.OUTPUT_ENCODING, StandardCharsets.UTF_8.name());
    properties.put(RuntimeConstants.ENCODING_DEFAULT, StandardCharsets.UTF_8.name());
    properties.put(RuntimeConstants.RESOURCE_LOADER, "file, classpath, string");
    properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FileUtils.getTempDirectory().getAbsolutePath());
    properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, Boolean.FALSE);
    properties.put("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    properties.put("string.resource.loader.class", StringResourceLoader.class.getName());
    properties.put("file.resource.loader.class", FileResourceLoader.class.getName());
    bean.setOverrideLogging(false);
    bean.setVelocityProperties(properties);
    return bean;
}
项目:snake-yaml    文件:VelocityTest.java   
public void testTemplate1() throws Exception {
    VelocityContext context = new VelocityContext();
    MyBean bean = createBean();
    context.put("bean", bean);
    Yaml yaml = new Yaml();
    context.put("list", yaml.dump(bean.getList()));
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();
    Template t = ve.getTemplate("template/mybean1.vm");
    StringWriter writer = new StringWriter();
    t.merge(context, writer);
    String output = writer.toString().trim().replaceAll("\\r\\n", "\n");
    // System.out.println(output);
    String etalon = Util.getLocalResource("template/etalon2-template.yaml").trim();
    assertEquals(etalon.length(), output.length());
    assertEquals(etalon, output);
    // parse the YAML document
    Yaml loader = new Yaml();
    MyBean parsedBean = loader.loadAs(output, MyBean.class);
    assertEquals(bean, parsedBean);
}
项目:compilers    文件:LL1TableCreator.java   
@Override
public String createTable(Grammar grammar) {
    Velocity.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
    Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    Velocity.init();
    VelocityContext context = new VelocityContext();
    context.put("grammar", grammar);

    context.put("nonterminalSymbols", grammar.getLhsSymbols());

    Template template = Velocity.getTemplate("/grammartools/PredictiveParsingTable.velo");
    StringWriter stringWriter = new StringWriter();
    template.merge(context, stringWriter);
    return stringWriter.toString().replaceAll("\n", "");
}
项目:ARCLib    文件:HtmlExporterTest.java   
@Before
public void setUp() throws TikaException, IOException, SAXException {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    Templater templater = new Templater();
    templater.setEngine(engine);

    exporter = new HtmlExporter();
    exporter.setTemplater(templater);

    TikaProvider provider = new TikaProvider();
    Tika tika = provider.tika();

    transformer = new TikaTransformer();
    transformer.setTika(tika);
}
项目:ARCLib    文件:PdfExporterTest.java   
@Before
public void setUp() throws TikaException, IOException, SAXException {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    Templater templater = new Templater();
    templater.setEngine(engine);

    exporter = new PdfExporter();
    exporter.setTemplater(templater);

    TikaProvider provider = new TikaProvider();
    Tika tika = provider.tika();

    transformer = new TikaTransformer();
    transformer.setTika(tika);
}
项目:spring-velocity-adapter    文件:VelocityConfigurer.java   
/**
 * Provides a ClasspathResourceLoader in addition to any default or user-defined
 * loader in order to load the spring Velocity macros from the class path.
 * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
 */
@Override
protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
    velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext);
    velocityEngine.setProperty(
            SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
    velocityEngine.addProperty(
            VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME);
    velocityEngine.addProperty(
            VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY);

    if (logger.isInfoEnabled()) {
        logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME +
                "' added to configured VelocityEngine");
    }
}
项目:fsm-packagetype    文件:VelocityManager.java   
private static VelocityEngine setUpVelocity(final MavenProject project) {
  final String templateRoot = getTemplateRoot(project);

  final Properties config = new Properties();

  config.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath,file");
  config.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateRoot);
  config.setProperty(RuntimeConstants.VM_LIBRARY, "macros.vm");
  config.setProperty(RuntimeConstants.ENCODING_DEFAULT, UTF_8);
  config.setProperty(RuntimeConstants.INPUT_ENCODING, UTF_8);
  config.setProperty(RuntimeConstants.OUTPUT_ENCODING, UTF_8);

  final String resourceLoader = ClasspathResourceLoader.class.getName();
  config.setProperty("classpath.resource.loader.class", resourceLoader);

  final String includeHandler = OptionalIncludeEventHandler.class.getName();
  config.setProperty(RuntimeConstants.EVENTHANDLER_INCLUDE, includeHandler);


  VelocityEngine velocityEngine = new VelocityEngine();
  velocityEngine.init(config);
  return velocityEngine;
}
项目:spring4-understanding    文件:VelocityConfigurer.java   
/**
 * Provides a ClasspathResourceLoader in addition to any default or user-defined
 * loader in order to load the spring Velocity macros from the class path.
 * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
 */
@Override
protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
    velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext);
    velocityEngine.setProperty(
            SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
    velocityEngine.addProperty(
            VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME);
    velocityEngine.addProperty(
            VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY);

    if (logger.isInfoEnabled()) {
        logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME +
                "' added to configured VelocityEngine");
    }
}
项目:x-worker    文件:VelocityGenerator.java   
public VelocityGenerator(String packageName ) {
    this.packageName = packageName;
    this.javaClassGenerator = new JavaClassGenerator();

    velocityEngine = new VelocityEngine();

    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    try {
        velocityEngine.init();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("VelocityEngine can not initialize.");
        System.exit(0);
    }
}
项目:x-worker    文件:SQLGenerator.java   
public SQLGenerator(String type) {
    this.type = type;

    this.javaClassGenerator = new JavaClassGenerator();

    velocityEngine = new VelocityEngine();

    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    try {
        velocityEngine.init();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("VelocityEngine can not initialize.");
        System.exit(0);
    }
}
项目:reair    文件:VelocityUtils.java   
/**
 * Return the String representation of the template rendered using Velocity.
 *
 * @param context context use to render the template
 * @param templateFileName file name of the template in the classpath
 * @throws TemplateRenderException if there is an error with the template
 */
public static String renderTemplate(String templateFileName,
                                    VelocityContext context)
    throws TemplateRenderException {
  VelocityEngine ve = new VelocityEngine();
  ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
  ve.setProperty("classpath.resource.loader.class",
      ClasspathResourceLoader.class.getName());

  StringWriter sw = new StringWriter();

  try {
    ve.mergeTemplate(templateFileName, "UTF-8", context, sw);
  } catch (ResourceNotFoundException
      | ParseErrorException
      | MethodInvocationException e) {
    throw new TemplateRenderException("Error rendering template file: " + templateFileName, e);
  }

  return sw.toString();
}
项目:tesla    文件:TemplateEngine.java   
/**
 * Create a template.
 * 
 * @param language
 *            programming language name of the generated source code.
 * @param templatePath
 *            template path.
 * @param defaultTemplate
 *            default template path.
 */
protected Template createTemplate(String language, String templatePath,
        String defaultTemplate) {
    String defaultResourcePath = "resources/" + this.language + "/"
            + defaultTemplate;
    if (templatePath == null || templatePath.isEmpty()) {
        templatePath = defaultResourcePath;
    }

    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file, classpath");
    ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, "");
    ve.setProperty("classpath.resource.loader.class",
            ClasspathResourceLoader.class.getName());
    ve.init();

    try {
        return ve.getTemplate(templatePath);
    } catch (ResourceNotFoundException ex) {
        if (templatePath != defaultResourcePath) {
            return ve.getTemplate(defaultResourcePath);
        } else {
            throw ex;
        }
    }
}
项目:snakeyaml    文件:VelocityTest.java   
public void testTemplate1() throws Exception {
    VelocityContext context = new VelocityContext();
    MyBean bean = createBean();
    context.put("bean", bean);
    Yaml yaml = new Yaml();
    context.put("list", yaml.dump(bean.getList()));
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();
    Template t = ve.getTemplate("template/mybean1.vm");
    StringWriter writer = new StringWriter();
    t.merge(context, writer);
    String output = writer.toString().trim().replaceAll("\\r\\n", "\n");
    // System.out.println(output);
    String etalon = Util.getLocalResource("template/etalon2-template.yaml").trim();
    assertEquals(etalon.length(), output.length());
    assertEquals(etalon, output);
    // parse the YAML document
    Yaml loader = new Yaml();
    MyBean parsedBean = loader.loadAs(output, MyBean.class);
    assertEquals(bean, parsedBean);
}
项目:web-budget    文件:VelocityProducer.java   
/**
 * @return produz uma instancia do velocity template para uso no sistema
 */
@Produces
VelocityEngine produceEngine() {

    final VelocityEngine engine = new VelocityEngine();

    // manda carregar os recursos dos resources
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class");
    engine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());

    final Properties properties = new Properties();

    // joga os logs do velocity no log do server
    properties.put("runtime.log.logsystem.class",
            "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
    properties.put("runtime.log.logsystem.log4j.category", "velocity");
    properties.put("runtime.log.logsystem.log4j.logger", "velocity");

    engine.init(properties);

    return engine;
}
项目:ontopia    文件:APIInfoResource.java   
@Get
public Representation getAPIInfo() throws IOException {
    TemplateRepresentation r = new TemplateRepresentation("net/ontopia/topicmaps/rest/resources/info.html", MediaType.TEXT_HTML);
    r.getEngine().addProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
    r.getEngine().addProperty("classpath." + VelocityEngine.RESOURCE_LOADER + ".class", ClasspathResourceLoader.class.getName());

    Map<Restlet, String> allRoutes = new HashMap<>();
    list(allRoutes, getApplication().getInboundRoot(), "");
    Map<String, Object> data = new HashMap<>();
    data.put("util", this);
    data.put("root", getApplication().getInboundRoot());
    data.put("routes", allRoutes);
    data.put("cutil", ClassUtils.class);

    r.setDataModel(data);

    return r;
}
项目:JNIBridgeGenerator    文件:JNIProxyProcessor.java   
@Override public boolean process( Set<? extends TypeElement> annotations, RoundEnvironment roundEnv ) {
  ModelCollector collector = new ModelCollector( processingEnv.getMessager() );

  processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Start processing JNI Proxies" );
  JNIElementVisitor elementVisitor = new JNIElementVisitor( processingEnv.getMessager() );
  for ( TypeElement annotation : annotations ) {
    for ( Element element : roundEnv.getElementsAnnotatedWith( annotation ) ) {
      element.accept( elementVisitor, collector );
    }
  }
  VelocityEngine engine = new VelocityEngine();
  engine.setProperty( RuntimeConstants.RESOURCE_LOADER, "classpath" );
  engine.setProperty( "classpath.resource.loader.class", ClasspathResourceLoader.class.getName() );
  engine.init();

  GeneralGenerator generalGenerator = new GeneralGenerator( processingEnv, engine );

  for ( JNIProxyClass proxyClass : collector.getClasses() ) {
    proxyClass.accept( generalGenerator );
  }
  return true;
}
项目:BPMNspector    文件:HtmlReportGenerator.java   
private static void createReportFromValidationResult(ValidationResult result, Path outputPath) {
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    Velocity.init();

    try {
        Template template = Velocity.getTemplate("reporting/ValidationResult.vm");

        VelocityContext context = new VelocityContext();
        context.put("validationResult", result);
        context.put("resourcesWithWarnings", getResourcesWithWarnings(result));
        StringWriter sw = new StringWriter();
        template.merge(context, sw);

        try (FileWriter fw = new FileWriter(outputPath.toFile())) {
            fw.write(sw.toString());
            fw.flush();
        } catch (IOException ioe) {
            LOGGER.error("Creation of HTML Report file {} failed.", outputPath.toString(), ioe);
        }
    } catch (VelocityException e) {
        LOGGER.error("Creation of HTML report failed due to a Velocity Exception", e);
    }

}
项目:azkaban-customization    文件:AzkabanWebServer.java   
/**
 * Creates and configures the velocity engine.
 * 
 * @param devMode
 * @return
 */
private VelocityEngine configureVelocityEngine(final boolean devMode) {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty("resource.loader", "classpath, jar");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.setProperty("classpath.resource.loader.cache", !devMode);
    engine.setProperty("classpath.resource.loader.modificationCheckInterval", 5L);
    engine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName());
    engine.setProperty("jar.resource.loader.cache", !devMode);
    engine.setProperty("resource.manager.logwhenfound", false);
    engine.setProperty("input.encoding", "UTF-8");
    engine.setProperty("output.encoding", "UTF-8");
    engine.setProperty("directive.set.null.allowed", true);
    engine.setProperty("resource.manager.logwhenfound", false);
    engine.setProperty("velocimacro.permissions.allow.inline", true);
    engine.setProperty("velocimacro.library.autoreload", devMode);
    engine.setProperty("velocimacro.library", "/azkaban/webapp/servlet/velocity/macros.vm");
    engine.setProperty("velocimacro.permissions.allow.inline.to.replace.global", true);
    engine.setProperty("velocimacro.arguments.strict", true);
    engine.setProperty("runtime.log.invalid.references", devMode);
    engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class);
    engine.setProperty("runtime.log.logsystem.log4j.logger", Logger.getLogger("org.apache.velocity.Logger"));
    engine.setProperty("parser.pool.size", 3);
    return engine;
}
项目:test-html-generator-plugin    文件:TestGeneratorMojo.java   
private String getAccordianHeadingHTML(LinkObject link, List<LinkObject> links) {
    VelocityEngine engine = new VelocityEngine();
       engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
       engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
       StringWriter writer = new StringWriter();
       try
       {
        engine.init();

        VelocityContext context = new VelocityContext();
        context.put("link", link);
        context.put("links", links);

           engine.mergeTemplate("/templates/leftnav-accordian.vm", context, writer);
           return writer.toString();
       }
       catch (Exception e1)
       {
           getLog().error(e1);
       }
    return null;
}
项目:class-guard    文件:VelocityConfigurer.java   
/**
 * Provides a ClasspathResourceLoader in addition to any default or user-defined
 * loader in order to load the spring Velocity macros from the class path.
 * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
 */
@Override
protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
    velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext);
    velocityEngine.setProperty(
            SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
    velocityEngine.addProperty(
            VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME);
    velocityEngine.addProperty(
            VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY);

    if (logger.isInfoEnabled()) {
        logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME +
                "' added to configured VelocityEngine");
    }
}
项目:netTransformer    文件:GraphmlRenderer.java   
public String render(String template, HashMap<String,Object> parameters) throws Exception
{

    /*  first, get and initialize an engine  */
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();
    /*  next, get the Template  */
    Template t = ve.getTemplate( template );
    /*  create a context and add data */
    VelocityContext context = new VelocityContext();
    for (Map.Entry<String,Object> entry : parameters.entrySet()) {
        context.put(entry.getKey(),entry.getValue());
    }
    /* now render the template into a StringWriter */
    StringWriter writer = new StringWriter();
    t.merge( context, writer );
    /* show the World */
    return writer.toString();
}
项目:sharding    文件:VelocityTemplateConfigurer.java   
@Override
protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
    super.postProcessVelocityEngine(velocityEngine);
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp,file,class,url,jar,spring,springMacro");
    velocityEngine.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getName());
    velocityEngine.setProperty("file.resource.loader.class", FileResourceLoader.class.getName());
    velocityEngine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
    velocityEngine.setProperty("url.resource.loader.class", URLResourceLoader.class.getName());
    velocityEngine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName());

    velocityEngine.setProperty("resource.manager.cache.class", ResourceCacheImpl.class.getName());
    velocityEngine.setProperty("resource.manager.cache.size", 2048);
    velocityEngine.setProperty("resource.manager.class", ResourceManagerImpl.class.getName());

    velocityEngine.setProperty(RuntimeConstants.COUNTER_INITIAL_VALUE, 1);
    velocityEngine.setProperty(RuntimeConstants.INPUT_ENCODING, inputEncoding);
    velocityEngine.setProperty(RuntimeConstants.OUTPUT_ENCODING, outputEncoding);
    velocityEngine.setProperty("contentType", contentType);
    // org.apache.velocity.runtime.log.AvalonLogChute
    // org.apache.velocity.runtime.log.Log4JLogChute
    // org.apache.velocity.runtime.log.CommonsLogLogChute
    // org.apache.velocity.runtime.log.ServletLogChute
    // org.apache.velocity.runtime.log.JdkLogChute
    velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new Log4JLogChute());
    velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true);
}
项目:qemu-java    文件:SchemaWriter.java   
@Nonnull
private static VelocityEngine newVelocityEngine() {
    VelocityEngine engine = new VelocityEngine();
    engine
            .setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class
            .getName());
    // engine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());
    engine.setProperty(VelocityEngine.RESOURCE_LOADER,
            "classpath");
    engine.setProperty(
            "classpath.resource.loader.class", ClasspathResourceLoader.class
            .getName());
    // engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true");
    // engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "velocity/");
    engine.init();
    return engine;
}
项目:web-budget    文件:VelocityProducer.java   
/**
 * @return produz uma instancia do velocity template para uso no sistema
 */
@Produces
VelocityEngine produceEngine() {

    final VelocityEngine engine = new VelocityEngine();

    // manda carregar os recursos dos resources
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class");
    engine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());

    final Properties properties = new Properties();

    // joga os logs do velocity no log do server
    properties.put("runtime.log.logsystem.class",
            "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
    properties.put("runtime.log.logsystem.log4j.category", "velocity");
    properties.put("runtime.log.logsystem.log4j.logger", "velocity");

    engine.init(properties);

    return engine;
}
项目:jsp-jstl-engine    文件:Test1.java   
/**
 * @param args
 */
public static void main(String[] args) {
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    Velocity.setProperty(RuntimeConstants.RUNTIME_LOG, "velocity.log");
    Velocity.init();

    StringWriter writer = new StringWriter();
    VelocityContext context = new VelocityContext();
    context.put("a", 1);
    context.put("b", 2);
    context.put("c", 3);
    context.put("sysTime", new Date());
    context.put("dateUtil", new DateUtil());

    String template = ""
            + "#set($timeString = $dateUtil.format($sysTime, 'yyyy-MM-dd HH:mm:ss') + 'ssss')\r\n"
            + "#set($value = ($a + $b) * $c)\r\n"
            + "$value\r\n"
            + "${($a + $b) * $c}\r\n"
            + "$dateUtil.format($sysTime, 'yyyy-MM-dd HH:mm:ss')\r\n"
            + "$timeString\r\n";

    Velocity.evaluate(context, writer, "mergeTemplate", template);
    System.out.println(writer.toString());
}
项目:tomee    文件:Container.java   
private void copyTemplateTo(final File targetDir, final String filename) throws Exception {
    final File file = new File(targetDir, filename);
    if (file.exists()) {
        return;
    }

    // don't break apps using Velocity facade
    final VelocityEngine engine = new VelocityEngine();
    engine.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
    engine.setProperty(Velocity.RESOURCE_LOADER, "class");
    engine.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
    engine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();
    final Template template = engine.getTemplate("/org/apache/tomee/configs/" + filename);
    final VelocityContext context = new VelocityContext();
    context.put("tomcatHttpPort", Integer.toString(configuration.getHttpPort()));
    context.put("tomcatShutdownPort", Integer.toString(configuration.getStopPort()));
    final Writer writer = new FileWriter(file);
    template.merge(context, writer);
    writer.flush();
    writer.close();
}
项目:jcabi-velocity    文件:VelocityPage.java   
/**
 * Create and initialize Velocity engine.
 * @return The engine to use
 */
private static VelocityEngine init() {
    final VelocityEngine engine = new VelocityEngine();
    engine.setProperty("resource.loader", "cp");
    engine.setProperty(
        "cp.resource.loader.class",
        ClasspathResourceLoader.class.getName()
    );
    engine.setProperty(
        RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
        "org.apache.velocity.runtime.log.Log4JLogChute"
    );
    engine.setProperty(
        "runtime.log.logsystem.log4j.logger",
        "org.apache.velocity"
    );
    engine.init();
    return engine;
}
项目:voldemort    文件:VelocityEngine.java   
public VelocityEngine(String baseTemplateDir) {
    this.baseTemplateDir = Utils.notNull(baseTemplateDir);
    this.engine = new org.apache.velocity.app.VelocityEngine();
    engine.setProperty("resource.loader", "classpath");
    engine.setProperty("classpath.resource.loader.class",
                       ClasspathResourceLoader.class.getName());
    engine.setProperty("classpath.resource.loader.cache", false);
    engine.setProperty("file.resource.loader.modificationCheckInterval", 0);
    engine.setProperty("input.encoding", "UTF-8");
    engine.setProperty("velocimacro.permissions.allow.inline", true);
    engine.setProperty("velocimacro.library.autoreload", true);
    engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class);
    engine.setProperty("runtime.log.logsystem.log4j.logger",
                       Logger.getLogger("org.apache.velocity.Logger"));
    engine.setProperty("parser.pool.size", 3);
}
项目:cloud-portal    文件:VelocityService.java   
@PostConstruct
public void init() {

    // create velocity engine
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    velocityEngine.init();
}
项目:ARCLib    文件:TemplaterTest.java   
@Before
public void setUp() {
    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    templater = new Templater();
    templater.setEngine(engine);
}
项目:ARCLib    文件:ReportGeneratorTest.java   
@Before
public void setUp() throws IOException, TikaException, SAXException {
    MockitoAnnotations.initMocks(this);

    createDirectories(Paths.get("fileTestFiles"));

    docxExporter = new DocxExporter();

    xlsxExporter = new XlsxExporter();

    VelocityEngine engine = new VelocityEngine();
    engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();

    templater = new Templater();
    templater.setEngine(engine);

    pdfExporter = new PdfExporter();
    pdfExporter.setTemplater(templater);

    ObjectMapperProducer objectMapperProducer = new ObjectMapperProducer();
    mapper = objectMapperProducer.objectMapper(false, false);

    TikaProvider provider = new TikaProvider();
    Tika tika = provider.tika();

    transformer = new TikaTransformer();
    transformer.setTika(tika);
}
项目:CoffeeMaker    文件:VelocityUtil.java   
public static String parse(String templateFileName, AbstractFileWrapper data) {

        // 初始化模板引擎
        VelocityEngine engine = new VelocityEngine();
        engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
        engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

        Properties props = new Properties();

        URL resource = VelocityUtil.class.getClassLoader().getResource(".");
        Objects.requireNonNull(resource);

        // 设置模板目录
        String basePath = resource.getPath() + Const.TEMPLATE_LOCATION_DIR;
        props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,  basePath);
        //设置velocity的编码
        props.setProperty(Velocity.ENCODING_DEFAULT, StandardCharsets.UTF_8.name());
        props.setProperty(Velocity.INPUT_ENCODING,   StandardCharsets.UTF_8.name());
        props.setProperty(Velocity.OUTPUT_ENCODING,  StandardCharsets.UTF_8.name());
        engine.init(props);

        Template template = engine.getTemplate(templateFileName);
        // 设置变量
        VelocityContext ctx = new VelocityContext();

        ctx.put("data", data);

        StringWriter writer = new StringWriter();
        template.merge(ctx, writer);

        return writer.toString();


    }
项目:acmeair    文件:ReportGenerator.java   
private void generateHtmlfile(Map<String, Object> input) {     
 try{
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName());
    ve.init();
    Template template = ve.getTemplate("templates/acmeair-report.vtl");
    VelocityContext context = new VelocityContext();


    for(Map.Entry<String, Object> entry: input.entrySet()){
        context.put(entry.getKey(), entry.getValue());
    }
    context.put("math", new MathTool());
    context.put("number", new NumberTool());
    context.put("date", new ComparisonDateTool());

    Writer file = new FileWriter(new File(searchingLocation
    + System.getProperty("file.separator") + RESULTS_FILE));        
    template.merge( context, file );
    file.flush();
    file.close();

 }catch(Exception e){
    e.printStackTrace();
 }
}
项目:flow-platform    文件:AppConfig.java   
@Bean
public VelocityEngine velocityEngine() throws Exception {
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    ve.setProperty(Velocity.ENCODING_DEFAULT, DEFAULT_CHARSET.name());
    ve.setProperty(Velocity.INPUT_ENCODING, DEFAULT_CHARSET.name());
    ve.setProperty(Velocity.OUTPUT_ENCODING, DEFAULT_CHARSET.name());

    ve.init();
    return ve;
}
项目:sc-generator    文件:VelocityUtil.java   
public static Template getTempate(String path) {
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();
    Template t = ve.getTemplate(path, "utf-8");
    return t;
}
项目:hollow    文件:HollowUIRouter.java   
protected VelocityEngine initVelocity() {
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
    ve.setProperty("runtime.log.logsystem.log4j.category", "velocity");
    ve.setProperty("runtime.log.logsystem.log4j.logger", "velocity");
    ve.init();
    return ve;
}
项目:gs-spring-commons    文件:TemplateConfiguration.java   
@Bean
public VelocityEngine velocityEngine() {
    VelocityEngine velocity = new VelocityEngine();
    if (Stream.of(environment.getActiveProfiles()).noneMatch(s -> "dev".equals(s) || "sandbox".equals(s))) {
        // Get the template from the compiled resource folder (in no dev environments the source code isn't available)
        velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    }
    velocity.setProperty(RuntimeConstants.EVENTHANDLER_INCLUDE, IncludeRelativePath.class.getName());
    velocity.init();
    return velocity;
}
项目:subtitle-converter    文件:AbstractVelocityExportHandler.java   
/**
 * Creates a new instance with it's own velocityEngine.
 */
public AbstractVelocityExportHandler() {
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    velocityEngine.init();
}
项目:azkaban    文件:AzkabanWebServer.java   
/**
 * Creates and configures the velocity engine.
 *
 * @param devMode
 * @return
 */
private VelocityEngine configureVelocityEngine(final boolean devMode) {
  VelocityEngine engine = new VelocityEngine();
  engine.setProperty("resource.loader", "classpath, jar");
  engine.setProperty("classpath.resource.loader.class",
      ClasspathResourceLoader.class.getName());
  engine.setProperty("classpath.resource.loader.cache", !devMode);
  engine.setProperty("classpath.resource.loader.modificationCheckInterval",
      5L);
  engine.setProperty("jar.resource.loader.class",
      JarResourceLoader.class.getName());
  engine.setProperty("jar.resource.loader.cache", !devMode);
  engine.setProperty("resource.manager.logwhenfound", false);
  engine.setProperty("input.encoding", "UTF-8");
  engine.setProperty("output.encoding", "UTF-8");
  engine.setProperty("directive.set.null.allowed", true);
  engine.setProperty("resource.manager.logwhenfound", false);
  engine.setProperty("velocimacro.permissions.allow.inline", true);
  engine.setProperty("velocimacro.library.autoreload", devMode);
  engine.setProperty("velocimacro.library",
      "/azkaban/webapp/servlet/velocity/macros.vm");
  engine.setProperty(
      "velocimacro.permissions.allow.inline.to.replace.global", true);
  engine.setProperty("velocimacro.arguments.strict", true);
  engine.setProperty("runtime.log.invalid.references", devMode);
  engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class);
  engine.setProperty("runtime.log.logsystem.log4j.logger",
      Logger.getLogger("org.apache.velocity.Logger"));
  engine.setProperty("parser.pool.size", 3);
  return engine;
}