当前位置: 首页>>代码示例>>Java>>正文


Java StringResourceLoader类代码示例

本文整理汇总了Java中org.apache.velocity.runtime.resource.loader.StringResourceLoader的典型用法代码示例。如果您正苦于以下问题:Java StringResourceLoader类的具体用法?Java StringResourceLoader怎么用?Java StringResourceLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringResourceLoader类属于org.apache.velocity.runtime.resource.loader包,在下文中一共展示了StringResourceLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: velocityEngineFactoryBean

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:CoreSamlConfiguration.java

示例2: CodeGenerator

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
public CodeGenerator(CodeGeneratorContext context, M model, Writer writer, URL templateUrl, String templateResource, Set<Class<? extends Directive>> directives) {
    this.context = context != null ? context : new CodeGeneratorContext();
    this.model = model;
    this.writer = writer;
    this.templateResource = templateResource;
    this.templateUrl = templateUrl;
    this.directives = directives;

    StringResourceRepository repo = StringResourceLoader.getRepository();
    try {
        repo.putStringResource(TEMPLATE, templateUrl != null ? loadResource(templateUrl) : loadResource(templateResource));
    } catch (Exception e) {
        throw new RuntimeException(TEMPLATE_READER_FAILURE, e);
    }

    for (Class<? extends Directive> directive : directives) {
        context.getVelocityEngine().loadDirective(directive.getCanonicalName());
    }

    this.template = this.context.getVelocityEngine().getTemplate(TEMPLATE);
    this.context.getVelocityContext().put(MODEL, model);
}
 
开发者ID:sundrio,项目名称:sundrio,代码行数:23,代码来源:CodeGenerator.java

示例3: buildVelocityEngine

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
private VelocityEngine buildVelocityEngine() throws IOException {
	if(site == null)
		throw new SiteNotLoadedException();
	// merge the configs
	Map<String, String> velConfig = ConfigurationUtil.getProperties(mergedSiteConfig, "velocity", true);

	Properties props = new Properties();
	props.putAll(velConfig);

	VelocityEngine ve = new VelocityEngine();
	ve.init(props);

	StringResourceRepository repo = StringResourceLoader.getRepository();

	// add site specific macros
	if(site.getMacros() != null)
		for(Macro macro : site.getMacros())
			repo.putStringResource(macro.getName(), macro.getText());

	// add content.vm
	// String content = IOUtils.toString(SiteManager.class.getResourceAsStream("/vm/content.vm"));
	// repo.putStringResource("content.vm", content);

	logger.info("*** VelocityEngine successful initialized for: {}", site.getUrl());
	return ve;
}
 
开发者ID:th-schwarz,项目名称:bacoma,代码行数:27,代码来源:SiteManager.java

示例4: generateScript

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
/**
 * Generate a script from the specified template
 * using the given object map.
 * 
 * @param template
 * @param objMap
 * 
 * @return script
 * 
 * @throws IOException
 */
public String generateScript(PraatScriptContext ctx) 
	throws IOException {
	final Properties p = new Properties();
	p.setProperty(RuntimeConstants.RESOURCE_LOADER, "string");
	p.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader");

	final VelocityEngine ve = new VelocityEngine();
	ve.init(p);
	
	if(scriptTemplate == null || scriptTemplate.length() == 0) {
		// install string and set template name
		scriptTemplate = UUID.randomUUID().toString();
		StringResourceRepository repository = StringResourceLoader.getRepository();
		repository.putStringResource(scriptTemplate, scriptText);
	}
	
	// load template
	final Template t = ve.getTemplate(getScriptTemplate());
	final StringWriter sw = new StringWriter();
	
	t.merge(ctx.velocityContext(), sw);
	
	return sw.toString();
}
 
开发者ID:phon-ca,项目名称:phon-praat-plugin,代码行数:36,代码来源:PraatScript.java

示例5: initVelocity

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
private void initVelocity() throws Exception {
    if (ve != null)
        return;

    ve = new VelocityEngine();
    ve.addProperty(Velocity.RESOURCE_LOADER, "string");
    Velocity
        .addProperty("string.resource.loader.description", "Velocity StringResource loader");
    ve.addProperty(
        "string.resource.loader.class",
        "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
    ve.addProperty(
        "string.resource.loader.repository.class",
        "org.apache.velocity.runtime.resource.util.StringResourceRepositoryImpl");
    ve.addProperty("string.resource.loader.repository.name", "repo");

    ve.setProperty(
        "runtime.log.logsystem.class",
        "org.apache.velocity.runtime.log.NullLogChute");

    ve.init();
    stringTemplateRepo = StringResourceLoader.getRepository("repo");
}
 
开发者ID:inepex,项目名称:ineform,代码行数:24,代码来源:VelocityUtil.java

示例6: merge

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
public String merge(NodeWizardReportContext ctx) {
	// TODO move velocity init somewhere else
	final Properties p = new Properties();
	try {
		p.load(getClass().getResourceAsStream("velocity.properties"));
	} catch (IOException e) {
		LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
	}

	final VelocityEngine ve = new VelocityEngine();
	ve.init(p);

	StringResourceRepository repository = StringResourceLoader.getRepository();
	repository.putStringResource(getName(), getTemplate(), "UTF-8");

	// load template
	final Template t = ve.getTemplate(getName(), "UTF-8");
	final StringWriter sw = new StringWriter();

	t.merge(ctx.velocityContext(), sw);

	return sw.toString();
}
 
开发者ID:phon-ca,项目名称:phon,代码行数:24,代码来源:NodeWizardReportTemplate.java

示例7: getSiteEngine

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
/**
 * Initialization of a VelocityEngine for a {@link Site}. <i>It is necessary to have different {@link VelocityEngine}s because we need different
 * configurations for each site, e.g. velocity macros. </i> <br>
 * The VelocityEngines are managed by the {@link SiteHolder}, so the engine can live and die with the site object.
 * 
 * @param site
 * @return VelocityEngine
 */
public static VelocityEngine getSiteEngine(final Site site) {
	logger.debug("Entered initEngine.");
	Properties commonProperties = InitializationManager.getBean(PropertiesManager.class).getVelocityProperties();
	VelocityEngine velocityEngine = new VelocityEngine();

	try {
		velocityEngine.init(commonProperties);
		StringResourceRepository repo = StringResourceLoader.getRepository();

		// add site specific macros
		if (site.getMacros() != null)
			for (Macro macro : site.getMacros())
				repo.putStringResource(macro.getName(), macro.getText());
		
		// add content.vm
		repo.putStringResource("content.vm", FileTool.toString(new File(InitializationManager.getDefaultResourcesPath(), "content.vm")));
		logger.info("*** VelocityEngine is initialized for: ".concat(site.getUrl()));
	} catch (Exception e) {
		throw new FatalException("Error initializing a VelocityEngine for: " + site.getUrl(), e);
	}
	return velocityEngine;
}
 
开发者ID:th-schwarz,项目名称:pmcms,代码行数:31,代码来源:VelocityUtils.java

示例8: TemplateEngine

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
/**
 * Constructs a new {@link TemplateEngine} object, and initializes it. This
 * constructor will throw a {@link RuntimeException} if initializing fails.
 * 
 * @param path The path containing all the templates.
 * @param executor
 */
public TemplateEngine(Path path, ExecutorService executor) {
	this.executor = executor;
	try {
		this.path = path;
		this.modificationTimes = Maps.newHashMap();
		this.engine = new VelocityEngine();

		engine.setProperty("resource.loader", "string");
		engine.setProperty("runtime.log.logsystem.class", getPath(NullLogChute.class));
		engine.setProperty("string.resource.loader.class", getPath(StringResourceLoader.class));
		engine.setProperty("string.resource.loader.description", "Velocity StringResource loader");
		engine.setProperty("string.resource.loader.repository.class", getPath(StringResourceRepositoryImpl.class));
		engine.init();

		updateTemplates();

	} catch (Exception e) {
		LOG.error(e.getLocalizedMessage(), e);
		throw new DevHubException("Could not initialize the TemplateEngine", e);
	}
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:29,代码来源:TemplateEngine.java

示例9: getTemplate

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
/**
 * This method will return a {@link Template} object containing the requested
 * template. This method will also throw a {@link RuntimeException} if the
 * template could not be loaded, in which case you probably specified the
 * wrong file.
 * 
 * @param templatePath The template file to load.
 * 
 * @return The loaded {@link Template} object.
 */
public Template getTemplate(final String templatePath) {
	synchronized (engine) {
		if (!engine.resourceExists(templatePath)) {
			StringResourceRepository repo = StringResourceLoader.getRepository();
			repo.putStringResource(templatePath, getTemplateFromResource(templatePath));
		}

		try {
			return engine.getTemplate(templatePath);
		} catch (Exception e) {
			LOG.error(e.getLocalizedMessage(), e);
			throw new DevHubException(e);
		}
	}
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:26,代码来源:TemplateEngine.java

示例10: applyVelocityTemplate

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
private String applyVelocityTemplate(String templateData) throws Exception {
    Properties properties = new Properties();
    properties.setProperty("resource.loader", "string");
    properties.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
    properties.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
    properties.setProperty("userdirective",
            "com.github.xmltopdf.MoneyUAHDirective,"
            + "com.github.xmltopdf.MoneyToStrDirective,"
            + "com.github.xmltopdf.DateDirective,"
            + "com.github.xmltopdf.UkrToLatinDirective");
    Velocity.init(properties);

    StringResourceRepository repo = StringResourceLoader.getRepository();
    repo.putStringResource("template", templateData);
    Template template = Velocity.getTemplate("template", "UTF-8");
    StringWriter writer = new StringWriter();
    VelocityContext context = new VelocityContext();
    context.put("xml", xmlTag);
    template.merge(context, writer);
    writer.flush();
    writer.close();
    return writer.toString();
}
 
开发者ID:javadev,项目名称:jasper-xml-to-pdf-generator,代码行数:24,代码来源:JasperPdfGenerator.java

示例11: VelocityTemplate

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
/**
 * Create an instance.
 * @param header The fixed header
 * @param footer The fixed footer
 * @param row The template for the rows
 */
public VelocityTemplate(String header, String footer, String row) {
  super(header, footer);
  VelocityEngine engine = new VelocityEngine();
  engine.setProperty(Velocity.RESOURCE_LOADER, "string");
  engine.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
  engine.addProperty("string.resource.loader.repository.static", "false");
  engine.init();
  StringResourceRepository repository = (StringResourceRepository)engine.getApplicationAttribute(
      StringResourceLoader.REPOSITORY_NAME_DEFAULT);
  repository.putStringResource(TEMPLATE_NAME, row);
  template = engine.getTemplate(TEMPLATE_NAME);
}
 
开发者ID:Enterprise-Content-Management,项目名称:infoarchive-sip-sdk,代码行数:19,代码来源:VelocityTemplate.java

示例12: CodeGeneratorContext

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
public CodeGeneratorContext(VelocityEngine velocityEngine, VelocityContext velocityContext) {
    this.velocityEngine = velocityEngine;
    this.velocityContext = velocityContext;

    this.velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "string");
    this.velocityEngine.setProperty("string.resource.loader.class", StringResourceLoader.class.getName());
    this.velocityEngine.init();

    //Load standard directives
    this.velocityEngine.loadDirective(ClassDirective.class.getCanonicalName());
    this.velocityEngine.loadDirective(MethodDirective.class.getCanonicalName());
    this.velocityEngine.loadDirective(FieldDirective.class.getCanonicalName());
}
 
开发者ID:sundrio,项目名称:sundrio,代码行数:14,代码来源:CodeGeneratorContext.java

示例13: initStringResourceRepository

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
private StringResourceRepository initStringResourceRepository(Map<String, String> pathToTempalteMapping) throws IOException {
	StringResourceRepository result = new StringResourceRepositoryImpl();
	StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT, result);
	registerResource(result, RuntimeConstants.VM_LIBRARY_DEFAULT, RuntimeConstants.VM_LIBRARY_DEFAULT);
	for (Map.Entry<String, String> pathToTempalteMappingItem : pathToTempalteMapping.entrySet()) {
		registerResource(result, pathToTempalteMappingItem.getKey(), pathToTempalteMappingItem.getValue());
	}
	return result;
}
 
开发者ID:mvmn,项目名称:gp2srv,代码行数:10,代码来源:TemplateEngine.java

示例14: getConfigurationAsProperties

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
private Properties getConfigurationAsProperties() {
	Properties result = new Properties();

	result.setProperty(RuntimeConstants.RESOURCE_LOADER, "string");
	result.setProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, "false");
	result.setProperty(RuntimeConstants.VM_LIBRARY, RuntimeConstants.VM_LIBRARY_DEFAULT);
	result.setProperty("string.resource.loader.class", StringResourceLoader.class.getName());
	result.setProperty("string.resource.loader.modificationCheckInterval", "0");
	result.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());

	return result;
}
 
开发者ID:mvmn,项目名称:gp2srv,代码行数:13,代码来源:TemplateEngine.java

示例15: updateTemplates

import org.apache.velocity.runtime.resource.loader.StringResourceLoader; //导入依赖的package包/类
private void updateTemplates() {
	LOG.info("Updating template cache...");
	StringResourceRepository repo = StringResourceLoader.getRepository();
	URI uri = path.toUri();
	if (uri == null) {
		LOG.error("Could not locate templates folder!");
		return;
	}

	File dir = new File(uri);

	File[] templates = dir.listFiles(new FilenameFilter() {
		@Override
		public boolean accept(File arg0, String arg1) {
			boolean isTemplateFile = arg1 != null && arg1.endsWith(".tpl");
			if (!isTemplateFile) {
				return false;
			}

			return fileHasBeenModified(new File(arg0, arg1));
		}
	});

	if (templates != null && templates.length > 0) {
		for (File template : templates) {
			repo.putStringResource(template.getName(), getTemplateFromResource(template.getName()));
		}
	}
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:30,代码来源:TemplateEngine.java


注:本文中的org.apache.velocity.runtime.resource.loader.StringResourceLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。