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


Java VelocityException类代码示例

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


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

示例1: velocityEngineFactoryBeanWithVelocityProperties

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
@Test
public void velocityEngineFactoryBeanWithVelocityProperties() throws VelocityException, IOException {
	VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
	Properties props = new Properties();
	props.setProperty("myprop", "/mydir");
	vefb.setVelocityProperties(props);
	Object value = new Object();
	Map<String, Object> map = new HashMap<>();
	map.put("myentry", value);
	vefb.setVelocityPropertiesMap(map);
	vefb.afterPropertiesSet();
	assertThat(vefb.getObject(), instanceOf(VelocityEngine.class));
	VelocityEngine ve = vefb.getObject();
	assertEquals("/mydir", ve.getProperty("myprop"));
	assertEquals(value, ve.getProperty("myentry"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:VelocityConfigurerTests.java

示例2: velocityConfigurerWithCsvPathAndNonFileAccess

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void velocityConfigurerWithCsvPathAndNonFileAccess() throws IOException, VelocityException {
	VelocityConfigurer vc = new VelocityConfigurer();
	vc.setResourceLoaderPath("file:/mydir,file:/yourdir");
	vc.setResourceLoader(new ResourceLoader() {
		@Override
		public Resource getResource(String location) {
			if ("file:/yourdir/test".equals(location)) {
				return new DescriptiveResource("");
			}
			return new ByteArrayResource("test".getBytes(), "test");
		}
		@Override
		public ClassLoader getClassLoader() {
			return getClass().getClassLoader();
		}
	});
	vc.setPreferFileSystemAccess(false);
	vc.afterPropertiesSet();
	assertThat(vc.createVelocityEngine(), instanceOf(VelocityEngine.class));
	VelocityEngine ve = vc.createVelocityEngine();
	assertEquals("test", VelocityEngineUtils.mergeTemplateIntoString(ve, "test", Collections.emptyMap()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:VelocityConfigurerTests.java

示例3: evaluate

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
/**
 * Evaluates a template with a map of objects. <code>contextMap</code> can
 * be null if no keys/tokens are referenced in the <code>template</code>
 * 
 * @param contextMap Map of objects to be used in the template
 * @param template Velocity Template
 * @return Evaluated template
 */
public String evaluate(final Map<String, Object> contextMap, final String template) throws VelocityException {
	Reader readerOut = null;
	try {
		readerOut = new BufferedReader(new StringReader(template));
		return evaluate(contextMap, readerOut);
	} finally {
		if(readerOut != null) {
			try {
				readerOut.close();
			} catch (IOException e) {
				throw new VelocityException(e);
			}
				
		}
	}
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:25,代码来源:VelocityTemplateEngine.java

示例4: sendMessage

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
/**
    * Send a simple message based on a Velocity template.
    * 
    * @param msg
    *                the message to populate
    * @param templateName
    *                the Velocity template to use (relative to classpath)
    * @param model
    *                a map containing key/value pairs
    */
   @SuppressWarnings("unchecked")
   public void sendMessage(SimpleMailMessage msg, String templateName,
    Map model) {
String result = null;

try {
    result = VelocityEngineUtils.mergeTemplateIntoString(
	    velocityEngine, templateName, model);
} catch (VelocityException e) {
    log.error(e.getMessage());
}

msg.setText(result);
send(msg);
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:26,代码来源:MailEngine.java

示例5: sendMessage

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
/**
 * Send a simple message based on a Velocity template.
 * @param msg the message to populate
 * @param templateName the Velocity template to use (relative to classpath)
 * @param model a map containing key/value pairs
 */
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
        result =
            VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                                                        templateName, "UTF-8", model);
    } catch (VelocityException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }

    msg.setText(result);
    send(msg);
}
 
开发者ID:SMVBE,项目名称:ldadmin,代码行数:22,代码来源:MailEngine.java

示例6: generateReports

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
public void generateReports() throws VelocityException, IOException {
    listFilesForFolder(reportOutputDirectory);
    String jenkinsBasePath = "";
    String buildNumber = "1";
    String projectName = "cucumber-jvm";
    boolean runWithJenkins = false;
    boolean parallelTesting = false;

    Configuration configuration = new Configuration(reportOutputDirectory, projectName);
    configuration.setParallelTesting(parallelTesting);
    configuration.setRunWithJenkins(runWithJenkins);
    configuration.setBuildNumber(buildNumber);

    ReportBuilder reportBuilder = new ReportBuilder(list, configuration);
    reportBuilder.generateReports();
}
 
开发者ID:saikrishna321,项目名称:AppiumTestDistribution,代码行数:17,代码来源:HtmlReporter.java

示例7: createReportFromValidationResult

import org.apache.velocity.exception.VelocityException; //导入依赖的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

示例8: testVelocityConfigurerWithCsvPathAndNonFileAccess

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
public void testVelocityConfigurerWithCsvPathAndNonFileAccess() throws IOException, VelocityException {
	VelocityConfigurer vc = new VelocityConfigurer();
	vc.setResourceLoaderPath("file:/mydir,file:/yourdir");
	vc.setResourceLoader(new ResourceLoader() {
		@Override
		public Resource getResource(String location) {
			if ("file:/yourdir/test".equals(location)) {
				return new DescriptiveResource("");
			}
			return new ByteArrayResource("test".getBytes(), "test");
		}
		@Override
		public ClassLoader getClassLoader() {
			return getClass().getClassLoader();
		}
	});
	vc.setPreferFileSystemAccess(false);
	vc.afterPropertiesSet();
	assertThat(vc.createVelocityEngine(), instanceOf(VelocityEngine.class));
	VelocityEngine ve = vc.createVelocityEngine();
	assertEquals("test", VelocityEngineUtils.mergeTemplateIntoString(ve, "test", new HashMap()));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:VelocityConfigurerTests.java

示例9: mergeTemplate

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
private static String mergeTemplate(String templateContent, final VelocityContext context, boolean useSystemLineSeparators) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  try {
    Velocity.evaluate(context, stringWriter, "", templateContent);
  }
  catch (final VelocityException e) {
    LOG.error("Error evaluating template:\n"+templateContent,e);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()),
                                 IdeBundle.message("title.velocity.error"));
      }
    });
  }
  final String result = stringWriter.toString();

  if (useSystemLineSeparators) {
    final String newSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
    if (!"\n".equals(newSeparator)) {
      return StringUtil.convertLineSeparators(result, newSeparator);
    }
  }

  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:FileTemplateUtil.java

示例10: makeImportMailMessage

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
/**
 * Generates the mail message based on the file import status.
 *
 * @param importStatus The import status to generate file import mail message.
 * @return The file import mail message for the status.
*/
private String makeImportMailMessage(ImportStatus importStatus) {
    Map<String, Object> model = new HashMap<String, Object>();

    model.put("importStatus", importStatus);
    model.put("dateTool", new DateTool());
    model.put("mathTool", new MathTool());
    model.put("numberTool", new NumberTool());
    model.put("StringUtils", StringUtils.class);

    try {
        return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, fileImportMailTemplate, "utf-8", model);
    } catch (VelocityException ve) {
        logger.error("Error while making file import mail message", ve);
        // Use the log text instead...
        return logImportStatus(importStatus);
    }
}
 
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:24,代码来源:BatchProcessingJob.java

示例11: mergeTemplate

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
private static String mergeTemplate(String templateContent, final VelocityContext context, boolean useSystemLineSeparators) throws IOException {
  final StringWriter stringWriter = new StringWriter();
  try {
    VelocityWrapper.evaluate(null, context, stringWriter, templateContent);
  }
  catch (final VelocityException e) {
    LOG.error("Error evaluating template:\n" + templateContent, e);
    ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(IdeBundle.message("error.parsing.file.template", e.getMessage()), IdeBundle.message("title.velocity.error")));
  }
  final String result = stringWriter.toString();

  if (useSystemLineSeparators) {
    final String newSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
    if (!"\n".equals(newSeparator)) {
      return StringUtil.convertLineSeparators(result, newSeparator);
    }
  }

  return result;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:21,代码来源:FileTemplateUtil.java

示例12: velocityConfig

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
@Bean
public VelocityConfig velocityConfig() throws IOException, VelocityException {
    Properties config = new Properties();
    config.setProperty("input.encoding", "UTF-8");
    config.setProperty("output.encoding", "UTF-8");
    config.setProperty("default.contentType", "text/html;charset=UTF-8");
    config.setProperty("resource.loader", "class");
    config.setProperty("class.resource.loader.class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
    velocityConfigurer.setVelocityProperties(config);
    velocityConfigurer.afterPropertiesSet();

    return velocityConfigurer;
}
 
开发者ID:bingoohuang,项目名称:quartz-glass,代码行数:17,代码来源:SpringConfig.java

示例13: geVelocityTemplateContent

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
private String geVelocityTemplateContent(Map<String, Object> model, String templateName) throws VelocityException {
    StringBuilder content = new StringBuilder();
    try {
        content.append(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, "UTF-8", model));
        return content.toString();
    } catch (VelocityException e) {
        log.debug("Exception occured while processing velocity template: " + e.getMessage());
        throw e;
    }
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:11,代码来源:EmailServiceImpl.java

示例14: getVelocityEngine

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
@Bean
public VelocityEngine getVelocityEngine() throws VelocityException, IOException {
    Properties props = new Properties();
    props.setProperty("resource.loader", "class");
    props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    return new VelocityEngine(props);
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:9,代码来源:MailingConfig.java

示例15: createVelocityEngine

import org.apache.velocity.exception.VelocityException; //导入依赖的package包/类
/**
 * Prepare the VelocityEngine instance and return it.
 * @return the VelocityEngine instance
 * @throws IOException if the config file wasn't found
 * @throws VelocityException on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
	VelocityEngine velocityEngine = newVelocityEngine();
	Map<String, Object> props = new HashMap<String, Object>();

	// Load config file if set.
	if (this.configLocation != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Loading Velocity config from [" + this.configLocation + "]");
		}
		CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
	}

	// Merge local properties if set.
	if (!this.velocityProperties.isEmpty()) {
		props.putAll(this.velocityProperties);
	}

	// Set a resource loader path, if required.
	if (this.resourceLoaderPath != null) {
		initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath);
	}

	// Log via Commons Logging?
	if (this.overrideLogging) {
		velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
	}

	// Apply properties to VelocityEngine.
	for (Map.Entry<String, Object> entry : props.entrySet()) {
		velocityEngine.setProperty(entry.getKey(), entry.getValue());
	}

	postProcessVelocityEngine(velocityEngine);

	// Perform actual initialization.
	velocityEngine.init();

	return velocityEngine;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:VelocityEngineFactory.java


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