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


Java Velocity.init方法代码示例

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


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

示例1: generate

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * 根据模板生成文件
 * @param inputVmFilePath 模板路径
 * @param outputFilePath 输出文件路径
 * @param context
 * @throws Exception
 */
public static void generate(String inputVmFilePath, String outputFilePath, VelocityContext context) throws Exception {
	try {
		Properties properties = new Properties();
		properties.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, getPath(inputVmFilePath));
		Velocity.init(properties);
		//VelocityEngine engine = new VelocityEngine();
		Template template = Velocity.getTemplate(getFile(inputVmFilePath), "utf-8");
		File outputFile = new File(outputFilePath);
		FileWriterWithEncoding writer = new FileWriterWithEncoding(outputFile, "utf-8");
		template.merge(context, writer);
		writer.close();
	} catch (Exception ex) {
		throw ex;
	}
}
 
开发者ID:ChangyiHuang,项目名称:shuzheng,代码行数:23,代码来源:VelocityUtil.java

示例2: usage1

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public void usage1(String inputFile) throws FileNotFoundException {
   Velocity.init();

    VelocityContext context = new VelocityContext();

    context.put("author", "Elliot A.");
    context.put("address", "217 E Broadway");
    context.put("phone", "555-1337");

    FileInputStream file = new FileInputStream(inputFile);

    //Evaluate
    StringWriter swOut = new StringWriter();
    Velocity.evaluate(context, swOut, "test", file);

    String result =  swOut.getBuffer().toString();
    System.out.println(result);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:19,代码来源:VelocityUsage.java

示例3: 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

示例4: VelocityViewProcessor

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@Inject
public VelocityViewProcessor(final javax.ws.rs.core.Configuration config, final ServiceLocator serviceLocator,
                             @Optional final ServletContext servletContext) {
    super(config, servletContext, "velocity", "vm");

    this.factory = getTemplateObjectFactory(serviceLocator, VelocityConfigurationFactory.class,
            new Value<VelocityConfigurationFactory>() {
                @Override
                public VelocityConfigurationFactory get() {
                    Configuration configuration = getTemplateObjectFactory(serviceLocator, Configuration.class,
                            Values.<Configuration>empty());
                    if (configuration == null) {
                        return new VelocityDefaultConfigurationFactory(servletContext);
                    } else {
                        return new VelocitySuppliedConfigurationFactory(configuration);
                    }
                }
            });
    Velocity.init();
}
 
开发者ID:Feng-Zihao,项目名称:jersey-mvc-velocity,代码行数:21,代码来源:VelocityViewProcessor.java

示例5: __doViewInit

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@Override
protected void __doViewInit(IWebMvc owner) {
    super.__doViewInit(owner);
    // 初始化Velocity模板引擎配置
    if (!__inited) {
        __velocityConfig.setProperty(Velocity.ENCODING_DEFAULT, owner.getModuleCfg().getDefaultCharsetEncoding());
        __velocityConfig.setProperty(Velocity.INPUT_ENCODING, owner.getModuleCfg().getDefaultCharsetEncoding());
        __velocityConfig.setProperty(Velocity.OUTPUT_ENCODING, owner.getModuleCfg().getDefaultCharsetEncoding());
        //
        if (__baseViewPath.startsWith("/WEB-INF")) {
            __velocityConfig.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(__baseViewPath, "/WEB-INF/")).getPath());
        } else {
            __velocityConfig.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, __baseViewPath);
        }
        //
        Velocity.init(__velocityConfig);
        //
        __inited = true;
    }
}
 
开发者ID:suninformation,项目名称:ymate-platform-v2,代码行数:21,代码来源:VelocityView.java

示例6: doMerge

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public static String doMerge(String strToMerge, Map map) {
  if (strToMerge == null)
    return null;

  try {

    // ask Velocity to evaluate it.
    Velocity.init();
    StringWriter w = new StringWriter();
    VelocityContext context = new VelocityContext(map);
    Velocity.evaluate(context, w, "logTag", strToMerge);
    return w.getBuffer().toString();

  } catch (Exception e) {
    return null;
  }
}
 
开发者ID:dbarowy,项目名称:java-aws-mturk,代码行数:18,代码来源:VelocityUtil.java

示例7: 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

示例8: generateCodeByVelocity

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * 生成代码 by velocity
 * @param map		变量
 * @param destPath	目的地址
 * @param destFile	目的文件名
 * @param tmpPath	模版地址
 * @param tmpFile	模版文件名
 * @return
 */
public static boolean generateCodeByVelocity(Map<String, Object> map, String destPath, String destFile, String tmpPath, String tmpFile){
	try {
		// 1.初始化
		Properties properties = new Properties();
		properties.put("file.resource.loader.path", tmpPath);  
		properties.put("input.encoding", "UTF-8");
		properties.put("output.encoding", "UTF-8");
		Velocity.init(properties);
		VelocityContext context = new VelocityContext(map);
			
		// 2.生成代码
		FileUtil.mkdir(destPath);
		BufferedWriter sw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(destPath, destFile)), "UTF-8"));
		Velocity.getTemplate(tmpFile).merge(context, sw);
		sw.flush();
		sw.close();
		
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:uikoo9,项目名称:jfinalQ-gencode,代码行数:33,代码来源:QUtil.java

示例9: createTemplatePage

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private void createTemplatePage(Content content, String templateFileName, Path outFilePath) throws IOException {
	// template name
	content.put("template", Config.getTemplate());

	Properties p = new Properties();
	p.setProperty("input.encoding", "UTF-8");
	p.setProperty("output.encoding", "UTF-8");
	p.setProperty("file.resource.loader.path", Config.getTemplateBaseDir());
	Velocity.init(p);
	
	VelocityContext context = content.getVelocityContext();
	
	org.apache.velocity.Template template = Velocity.getTemplate(Config.getTemplateFile(lang, templateFileName).toString(), "UTF-8");
	
	BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFilePath.toFile()), "UTF-8"));
	template.merge(context, bw);
	bw.close();
}
 
开发者ID:cccties,项目名称:chilo-producer,代码行数:19,代码来源:Process.java

示例10: configure

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public static boolean configure(File file) {
	boolean result = false;
	try {
		if (file != null) {
			Velocity.init(file.getAbsolutePath());
		} else {
			// default
			// org/apache/velocity/runtime/defaults/velocity.properties
			Velocity.init();
		}
		result = true;
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:17,代码来源:VelocityHelper.java

示例11: init

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public static void init() {

		if (_isInitialized) {
			return;
		}

		Properties veloProp = new Properties();
		try {
			veloProp.load(instance().getClass().getResourceAsStream("/velocity.properties")); //$NON-NLS-1$
			Velocity.init(veloProp);

			_isInitialized = true;

		} catch (Exception ex) {
			StatusUtil.log(ex);
		}
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:18,代码来源:VelocityService.java

示例12: 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

示例13: 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

示例14: 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

示例15: Test2

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public Test2() throws Exception {
    //init
    Velocity.init("Velocity/GS_Velocity_1/src/main/java/velocity.properties");
    // get Template
    Template template = Velocity.getTemplate("Test2.vm");
    // getContext
    Context context = new VelocityContext();

    String name = "Vova";

    context.put("name", name);
    // get Writer
    Writer writer = new StringWriter();
    // merge
    template.merge(context, writer);

    System.out.println(writer.toString());
}
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:19,代码来源:Test2.java


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