當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。