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


Java Velocity.setProperty方法代码示例

本文整理汇总了Java中org.apache.velocity.app.Velocity.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Velocity.setProperty方法的具体用法?Java Velocity.setProperty怎么用?Java Velocity.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.velocity.app.Velocity的用法示例。


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

示例1: VelocityDefaultConfigurationFactory

import org.apache.velocity.app.Velocity; //导入方法依赖的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();
}
 
开发者ID:Feng-Zihao,项目名称:jersey-mvc-velocity,代码行数:17,代码来源:VelocityDefaultConfigurationFactory.java

示例2: createTable

import org.apache.velocity.app.Velocity; //导入方法依赖的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", "");
}
 
开发者ID:georgfedermann,项目名称:compilers,代码行数:19,代码来源:LL1TableCreator.java

示例3: start

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * Simply initialize the Velocity engine
 */
@PostConstruct
public void start() throws Exception
{
	try
	{
		Velocity.setProperty(Velocity.RESOURCE_LOADER, "cp");
		Velocity.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
		Velocity.setProperty("cp.resource.loader.cache", "true");
		Velocity.setProperty("cp.resource.loader.modificationCheckInterval ", "0");
		Velocity.setProperty("input.encoding", "UTF-8");
		Velocity.setProperty("output.encoding", "UTF-8");
		// Very busy servers should increase this value. Default: 20
		// Velocity.setProperty("velocity.pool.size", "20");
		Velocity.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.JdkLogChute");
		Velocity.init();
		log.log(Level.FINE,"Velocity initialized!");
	}
	catch (Exception ex)
	{
		log.log(Level.SEVERE,"Unable to initialize Velocity", ex);
		throw new RuntimeException(ex);
	}
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:27,代码来源:VelocityService.java

示例4: createReportFromValidationResult

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
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);
    }

}
 
开发者ID:uniba-dsg,项目名称:BPMNspector,代码行数:26,代码来源:HtmlReportGenerator.java

示例5: initializeVelocity

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * Intializes the Apache Velocity template engine.
 * 
 * @throws ConfigurationException thrown if there is a problem initializing Velocity
 */
protected static void initializeVelocity() throws ConfigurationException {
    try {
        log.debug("Initializing Velocity template engine");
        Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                "org.apache.velocity.runtime.log.NullLogChute");
        Velocity.setProperty(RuntimeConstants.ENCODING_DEFAULT, "UTF-8");
        Velocity.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
        Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        Velocity.setProperty("classpath.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        Velocity.init();
    } catch (Exception e) {
        throw new ConfigurationException("Unable to initialize Velocity template engine", e);
    }
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:21,代码来源:DefaultBootstrap.java

示例6: AbstractReporter

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * @param classpathPrefix Where in the classpath to load templates from.
 */
protected AbstractReporter(String classpathPrefix) {
    this.classpathPrefix = classpathPrefix;
    Velocity.setProperty("resource.loader", "classpath");
    Velocity.setProperty("classpath.resource.loader.class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    if (!META.shouldGenerateVelocityLog()) {
        Velocity.setProperty("runtime.log.logsystem.class",
                "org.apache.velocity.runtime.log.NullLogSystem");
    }

    try {
        Velocity.init();
    } catch (Exception | AssertionError ex) {
        throw new ReportNGException("Failed to initialise Velocity.", ex);
    }
}
 
开发者ID:ggasoftware,项目名称:gga-selenium-framework,代码行数:20,代码来源:AbstractReporter.java

示例7: generateFile

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@Override
public File generateFile(String filePath, Metadata metadata, Logger logger,
    Object... args) throws IOException {
  File configFile = new File(filePath);
  VelocityMetadata velocityMetadata = new VelocityMetadata(metadata);
  // Velocity requires you to set a path of where to look for
  // templates. This path defaults to . if not set.
  int slashIndex = ((String) args[0]).lastIndexOf('/');
  String templatePath = ((String) args[0]).substring(0, slashIndex);
  Velocity.setProperty("file.resource.loader.path", templatePath);
  // Initialize Velocity and set context up
  Velocity.init();
  VelocityContext context = new VelocityContext();
  context.put("metadata", velocityMetadata);
  context.put("env", System.getenv());
  // Load template from templatePath
  String templateName = ((String) args[0]).substring(slashIndex);
  Template template = Velocity.getTemplate(templateName);
  // Fill out template and write to file
  StringWriter sw = new StringWriter();
  template.merge(context, sw);
  FileUtils.writeStringToFile(configFile, sw.toString());
  return configFile;
}
 
开发者ID:apache,项目名称:oodt,代码行数:25,代码来源:VelocityConfigFileWriter.java

示例8: main

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * @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());
}
 
开发者ID:xuesong123,项目名称:jsp-jstl-engine,代码行数:29,代码来源:Test1.java

示例9: processTemplate

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * 处理模版,结合模版和参数生成字符串
 * 
 * @param templateName
 *            模版名称
 * @param context
 *            参数内容
 * @return
 * @throws Exception
 */
private String processTemplate(String templateName,VelocityContext context){
	Writer writer=null;
	try {
		Velocity.setProperty(Velocity.INPUT_ENCODING, "utf-8");// 设置输入字符�?
		if (SystemPropertyUtils.isWindowsOS()) {
			Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,defaultWinRootPath);
		} else if (SystemPropertyUtils.isLinuxOS()) {
			Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,defaultLinuxRootPath);
		}
		Velocity.init();
		String templatePath=templateName+Constants.TEMPLATE_SUFFIX_NAME;
		Template template = Velocity.getTemplate(templatePath);
		writer = new StringWriter();
		template.merge(context, writer);
	} catch (Exception e) {
		try {
			throw new IllegalAccessException("resolve template and parameters is exception!!!");
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		}
	}
	return writer.toString();
}
 
开发者ID:zubryan,项目名称:CloudM,代码行数:34,代码来源:ResolveTemplate.java

示例10: main

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public static void main(String[] args) {
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.ALL);

    Velocity.setProperty(Velocity.RESOURCE_LOADER, "report, class");
    Velocity.setProperty("report.resource.loader.description", "WASR Velocity Report resource loader");
    Velocity.setProperty("report.resource.loader.class", "wasr.velocity.ReportResourceLoader");
    Velocity.setProperty("report.resource.loader.cache", "false");
    Velocity.setProperty("class.resource.loader.description", "Velocity Classpath resource loader");
    Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    Velocity.init();

    WASRFrame frame = WASRFrame.getInstance();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
    frame.init();
}
 
开发者ID:JGillam,项目名称:WASR,代码行数:18,代码来源:WASRFrame.java

示例11: CodeGenerator

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public CodeGenerator(AbstractCModule cModule) {
    this.cModule = cModule;
    Velocity.setProperty("file.resource.loader.path", getTemplateSearchDirPath());
    //Velocity.setProperty("runtime.log.error.stacktrace", "true");
    //Velocity.setProperty("runtime.log.warn.stacktrace", "true");
    //Velocity.setProperty("runtime.log.info.stacktrace", "true");
    Velocity.init();
}
 
开发者ID:ChangeVision,项目名称:astah-uml2c-plugin,代码行数:9,代码来源:CodeGenerator.java

示例12: createSummaryHtml

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private static void createSummaryHtml(String baseFolder, Path summaryFile, int checkedFilesSum, int validResults,
                               Map<String, Integer> violationsByConstraintCount,
                               List<SingleValidationSummary> summaries) {
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    Velocity.init();

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

        VelocityContext context = new VelocityContext();
        context.put("baseFolder", baseFolder);
        context.put("checkedFilesSum", checkedFilesSum);
        context.put("directlyChecked", summaries.size());
        context.put("importedFilesChecked", checkedFilesSum-summaries.size());
        context.put("validResults", validResults);
        context.put("invalidResults", summaries.size()-validResults);
        context.put("violationsByConstraintCount", violationsByConstraintCount);
        context.put("summaries", summaries);

        StringWriter sw = new StringWriter();
        template.merge(context, sw);


        try (FileWriter fw = new FileWriter(summaryFile.toFile())) {
            fw.write(sw.toString());
            fw.flush();
        } catch (IOException ioe) {
            LOGGER.error("Creation of HTML Report file {} failed.", summaryFile.toString(), ioe);
        }
    } catch (VelocityException e) {
        LOGGER.error("Creation of HTML report failed due to a Velocity Exception", e);
    }
}
 
开发者ID:uniba-dsg,项目名称:BPMNspector,代码行数:35,代码来源:HtmlReportGenerator.java

示例13: setUpVelocityProperties

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@PostConstruct
public void setUpVelocityProperties() {
    try {
        Velocity.setProperty(LOGSYSTEM_CLASS, LOG4J);
        Velocity.setProperty(LOGSYSTEM_LOGGER, LOG4J);
        Velocity.init();
    } catch (Exception e) {
        throw new IllegalStateException(String.format("Error initializing template engine: %s", e.toString()), e);
    }
}
 
开发者ID:motech,项目名称:modules,代码行数:11,代码来源:TemplateController.java

示例14: initVelocity

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private static void initVelocity() {
	try {
		// Use log4j
		Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getCanonicalName());
		Velocity.setProperty("runtime.log.logsystem.log4j.logger", "org.apache.velocity");
		// Use UTF-8
		Velocity.setProperty("input.encoding", "UTF-8");
		Velocity.setProperty("output.encoding", "UTF-8");
		Velocity.init();
	} catch (Exception e) {
		System.err.println("Couldn't start up velocity.");
		System.exit(1);
	}
}
 
开发者ID:cinovo,项目名称:cloudconductor-agent-redhat,代码行数:15,代码来源:Starter.java

示例15: runVelocity

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public static void runVelocity(BeanDescription desc, Map<String, Object> commonMap, String pckg, String modelPckg,
		String presenterPckg, String viewPckg, String profileName, String templateName, File outFile,
		boolean mandatory, String templatePackage, Log log) throws IOException {
	Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
	Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
	Template template;
	// Issue #6: for optional templates check whether it's there
	boolean runTemplate;
	if (mandatory) {
		runTemplate = true;
	} else {
		runTemplate = isTemplateExisting(templateName, templatePackage);
	}
	if (!runTemplate) {
		return;
	}
	template = Velocity.getTemplate(templatePackage + templateName);
	String className = desc != null ? desc.getClassName() : "no description found ";
	log.debug("Create file with template: "+ template.getName() + " for bean " + className + " in profile: " + profileName);
	VelocityContext context = new VelocityContext();
	context.put("bean", desc);
	context.put("common", commonMap);
	context.put("package", pckg);
	context.put("modelPackage", modelPckg);
	context.put("presenterPackage", presenterPckg);
	context.put("viewPackage", viewPckg);
	context.put("profileName", profileName);
	context.put("unicodeUtil", UnicodeUtil.SINGLETON);
	Writer writer = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8");
	template.merge(context, writer);
	writer.close();
	log.info("Written file: " + outFile);
}
 
开发者ID:akquinet,项目名称:vaadinator,代码行数:34,代码来源:GeneratorUtil.java


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