本文整理汇总了Java中org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader类的典型用法代码示例。如果您正苦于以下问题:Java ClasspathResourceLoader类的具体用法?Java ClasspathResourceLoader怎么用?Java ClasspathResourceLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClasspathResourceLoader类属于org.apache.velocity.runtime.resource.loader包,在下文中一共展示了ClasspathResourceLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTemplate1
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
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);
}
示例2: VelocityDefaultConfigurationFactory
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
@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();
}
示例3: velocityEngineFactoryBean
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的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;
}
示例4: createTable
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
@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", "");
}
示例5: configureVelocityEngine
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
/**
* 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;
}
示例6: setUp
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
@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);
}
示例7: setUp
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
@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);
}
示例8: postProcessVelocityEngine
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
/**
* 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");
}
}
示例9: setUpVelocity
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
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;
}
示例10: VelocityGenerator
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
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);
}
}
示例11: SQLGenerator
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
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);
}
}
示例12: renderTemplate
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
/**
* 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();
}
示例13: produceEngine
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
/**
* @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;
}
示例14: getAPIInfo
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
@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;
}
示例15: process
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; //导入依赖的package包/类
@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;
}