本文整理汇总了Java中org.apache.velocity.runtime.resource.loader.FileResourceLoader类的典型用法代码示例。如果您正苦于以下问题:Java FileResourceLoader类的具体用法?Java FileResourceLoader怎么用?Java FileResourceLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileResourceLoader类属于org.apache.velocity.runtime.resource.loader包,在下文中一共展示了FileResourceLoader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: velocityEngineFactoryBean
import org.apache.velocity.runtime.resource.loader.FileResourceLoader; //导入依赖的package包/类
@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;
}
示例2: postProcessVelocityEngine
import org.apache.velocity.runtime.resource.loader.FileResourceLoader; //导入依赖的package包/类
@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);
}
示例3: renderToFolder
import org.apache.velocity.runtime.resource.loader.FileResourceLoader; //导入依赖的package包/类
private void renderToFolder(EntityObject eo, String template, String folder, String fileName) throws IOException {
// first, let's build the filename.
String fullFileName = folder + File.separator + fileName;
VelocityEngine ve = new VelocityEngine();
// Tried using classpath, but discarded it.
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
ve.setProperty("file.resource.loader.class", FileResourceLoader.class.getName());
// setting it empty, so we can use an absolute path
ve.setProperty("file.resource.loader.path", "");
ve.init();
VelocityContext ctx = new VelocityContext();
ctx.put("ENTITY", eo);
ctx.put("display", new DisplayTool());
// now, let's expand the template path in case we are using one of our
// default templates.
if (template.startsWith("templates/")) {
// ok, we assume it's one of our default templates in MCP_HOME
String modelHomeFolder = System.getenv("MCP_HOME");
if (!modelHomeFolder.endsWith(File.separator))
modelHomeFolder = modelHomeFolder + File.separator;
template = modelHomeFolder + template;
}
Template t = ve.getTemplate(template);
StringWriter writer = new StringWriter();
t.merge(ctx, writer);
// System.out.println(writer);
log.info("Writing file " + fullFileName);
FileWriter fileWriter = new FileWriter(fullFileName);
fileWriter.write(writer.toString());
fileWriter.flush();
fileWriter.close();
}
示例4: createVelocityEngine
import org.apache.velocity.runtime.resource.loader.FileResourceLoader; //导入依赖的package包/类
private VelocityEngine createVelocityEngine(final File templateDir) {
final VelocityEngine ve = new VelocityEngine();
if (templateDir == null) {
ve.addProperty("resource.loader", "class");
} else {
ve.addProperty("resource.loader", "file, class");
ve.addProperty("file.resource.loader.class",
FileResourceLoader.class.getName());
ve.addProperty("file.resource.loader.path", templateDir.toString());
}
ve.addProperty("class.resource.loader.class",
ClasspathResourceLoader.class.getName());
ve.init();
return ve;
}
示例5: configure
import org.apache.velocity.runtime.resource.loader.FileResourceLoader; //导入依赖的package包/类
@Override
public void configure(String templatesPath, boolean debugMode)
throws JannocessorException {
logger.info(
"Configuring Velocity engine: {templates_path={}, debug={}}",
templatesPath, debugMode);
try {
Properties velocityConfig = new Properties();
if (templatesPath != null) {
velocityConfig
.setProperty("resource.loader", "file, classpath");
velocityConfig.setProperty(RESOURCE_LOADER_CLASS,
FileResourceLoader.class.getCanonicalName());
velocityConfig.setProperty(FILE_RESOURCE_LOADER_PATH,
templatesPath);
velocityConfig.setProperty("classpath.resource.loader.class",
ClasspathResourceLoader.class.getCanonicalName());
velocityConfig.setProperty("classpath.resource.loader.cache",
"false");
} else {
velocityConfig.setProperty(RESOURCE_LOADER_CLASS,
ClasspathResourceLoader.class.getCanonicalName());
}
velocityConfig.setProperty(VM_LIBRARY,
StringUtils.join(VM_LIBRARY_FILES, ","));
velocityConfig.setProperty(VM_MAX_DEPTH, "1000");
velocityConfig.setProperty(VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL,
"true");
velocityConfig.setProperty(VM_PERM_INLINE_LOCAL, "false");
velocityConfig.setProperty(VM_PERM_ALLOW_INLINE, "true");
// FIXME: deprecated
velocityConfig.setProperty(VM_CONTEXT_LOCALSCOPE, "true");
if (debugMode) {
velocityConfig.setProperty(VM_LIBRARY_AUTORELOAD, "true");
velocityConfig.setProperty(FILE_RESOURCE_LOADER_CACHE, "false");
} else {
velocityConfig.setProperty(VM_LIBRARY_AUTORELOAD, "false");
velocityConfig.setProperty(FILE_RESOURCE_LOADER_CACHE, "true");
}
engine.setProperty(RUNTIME_LOG_LOGSYSTEM, this);
engine.init(velocityConfig);
customize(true);
configured = true;
} catch (Exception e) {
throw new JannocessorException(
"Exception occured while configuring the template renderer",
e);
}
}
示例6: doWork
import org.apache.velocity.runtime.resource.loader.FileResourceLoader; //导入依赖的package包/类
@Override
public int doWork(List<String> args) {
if(args.size()!=1) {
LOG.error("expected one and only one argument.");
return -1;
}
if(this.velocityTemplate==null) {
LOG.error("undefined option -T");
return -1;
}
String command = args.get(0);
Reader jsonReader = null;
PrintWriter pw = null;
JsonElement jsonDoc=null;
try
{
final JsonParser parser=new JsonParser();
try {
File jsonF = new File(command);
if(!jsonF.exists() && jsonF.isFile()) {
jsonReader = new FileReader(jsonF);
}
} catch (IOException e) {
jsonReader=null;
}
if(jsonReader==null) {
if(command.endsWith(".php")) {
command+=".json";
}
if(command.startsWith("org_")) {
command = "https://software.broadinstitute.org/gatk/gatkdocs/"+command;
}
jsonReader = new InputStreamReader(IOUtils.openURIForReading(command));
}
jsonDoc = parser.parse(jsonReader);
jsonReader.close();
LOG.info("URL is :" + command);
IOUtil.assertFileIsReadable(this.velocityTemplate);
pw = openFileOrStdoutAsPrintWriter(this.outputFile);
VelocityContext context = new VelocityContext();
context.put("json", jsonDoc);
context.put("utils", new Utils());
final VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
ve.setProperty("file.resource.loader.class",FileResourceLoader.class.getName());
ve.setProperty("file.resource.loader.path",this.velocityTemplate.getParent());
ve.init();
final Template template = ve.getTemplate(this.velocityTemplate.getName());
template.merge( context, pw);
pw.flush();
return RETURN_OK;
}
catch(final Exception err)
{
LOG.error(err);
return -1;
}
finally
{
CloserUtil.close(pw);
CloserUtil.close(jsonReader);
}
}