use of org.apache.velocity.exception.ResourceNotFoundException in project jena by apache.
the class SimpleVelocity method process.
/** Process a template */
public static void process(String base, String path, Writer out, VelocityContext context) {
VelocityEngine velocity = new VelocityEngine();
// Turn off logging - catch exceptions and log ourselves
velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, velocityLogChute);
velocity.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, base);
velocity.init();
try {
Template temp = velocity.getTemplate(path);
temp.merge(context, out);
out.flush();
} catch (ResourceNotFoundException ex) {
velocityLog.error("Resource not found: " + ex.getMessage());
} catch (ParseErrorException ex) {
velocityLog.error("Parse error (" + path + ") : " + ex.getMessage());
} catch (MethodInvocationException ex) {
velocityLog.error("Method invocation exception (" + path + ") : " + ex.getMessage());
} catch (IOException ex) {
velocityLog.warn("IOException", ex);
}
}
use of org.apache.velocity.exception.ResourceNotFoundException in project traccar by tananaev.
the class NotificationFormatter method getTemplate.
public static Template getTemplate(Event event, String path) {
String templateFilePath;
Template template;
try {
templateFilePath = Paths.get(path, event.getType() + ".vm").toString();
template = Context.getVelocityEngine().getTemplate(templateFilePath, StandardCharsets.UTF_8.name());
} catch (ResourceNotFoundException error) {
Log.warning(error);
templateFilePath = Paths.get(path, "unknown.vm").toString();
template = Context.getVelocityEngine().getTemplate(templateFilePath, StandardCharsets.UTF_8.name());
}
return template;
}
use of org.apache.velocity.exception.ResourceNotFoundException in project carbon-apimgt by wso2.
the class GatewaySourceGeneratorImpl method getConfigStringFromTemplate.
@Override
public String getConfigStringFromTemplate(List<TemplateBuilderDTO> apiResources) throws APITemplateException {
StringWriter writer = new StringWriter();
String templatePath = "resources" + File.separator + "template" + File.separator + "template.xml";
try {
// build the context for template and apply the necessary decorators
apiConfigContext.validate();
ConfigContext configContext = new ResourceConfigContext(apiConfigContext, apiResources);
VelocityContext context = configContext.getContext();
VelocityEngine velocityengine = new VelocityEngine();
velocityengine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityengine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
velocityengine.init();
Template template = velocityengine.getTemplate(templatePath);
template.merge(context, writer);
} catch (ResourceNotFoundException e) {
log.error("Template " + templatePath + " not Found", e);
throw new APITemplateException("Template " + templatePath + " not Found", ExceptionCodes.TEMPLATE_EXCEPTION);
} catch (ParseErrorException e) {
log.error("Syntax error in " + templatePath, e);
throw new APITemplateException("Syntax error in " + templatePath, ExceptionCodes.TEMPLATE_EXCEPTION);
}
return writer.toString();
}
use of org.apache.velocity.exception.ResourceNotFoundException in project carbon-apimgt by wso2.
the class GatewaySourceGeneratorImpl method getCompositeAPIConfigStringFromTemplate.
@Override
public String getCompositeAPIConfigStringFromTemplate(List<TemplateBuilderDTO> apiResources, List<CompositeAPIEndpointDTO> compositeApiEndpoints) throws APITemplateException {
StringWriter writer = new StringWriter();
String templatePath = "resources" + File.separator + "template" + File.separator + "composite_template.xml";
try {
// build the context for template and apply the necessary decorators
apiConfigContext.validate();
CompositeAPIConfigContext configContext = new CompositeAPIConfigContext(apiConfigContext, apiResources, compositeApiEndpoints);
VelocityContext context = configContext.getContext();
VelocityEngine velocityengine = new VelocityEngine();
velocityengine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityengine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
velocityengine.init();
Template template = velocityengine.getTemplate(templatePath);
template.merge(context, writer);
} catch (ResourceNotFoundException e) {
log.error("Template " + templatePath + " not Found", e);
throw new APITemplateException("Template " + templatePath + " not Found", ExceptionCodes.TEMPLATE_EXCEPTION);
} catch (ParseErrorException e) {
log.error("Syntax error in " + templatePath, e);
throw new APITemplateException("Syntax error in " + templatePath, ExceptionCodes.TEMPLATE_EXCEPTION);
}
return writer.toString();
}
use of org.apache.velocity.exception.ResourceNotFoundException in project dbflute-core by dbflute.
the class DfAbstractTexenTask method fireVelocityProcess.
protected void fireVelocityProcess() {
assertBasicAntParameter();
// set up the encoding of templates from DBFlute property
setInputEncoding(getBasicProperties().getTemplateFileEncoding());
setOutputEncoding(getBasicProperties().getSourceFileEncoding());
try {
initializeGeneratorInstance();
final DfGenerator generator = setupGenerator();
final Context ctx = setupControlContext();
_log.info("generator.parse(\"" + controlTemplate + "\", ctx);");
generator.parse(controlTemplate, ctx);
generator.shutdown();
cleanup();
} catch (BuildException e) {
throw e;
} catch (MethodInvocationException e) {
final String method = e.getReferenceName() + "." + e.getMethodName() + "()";
String msg = "Exception thrown by " + method + ": control=" + controlTemplate;
throw new IllegalStateException(msg, e.getWrappedThrowable());
} catch (ParseErrorException e) {
throw new IllegalStateException("Velocity syntax error: control=" + controlTemplate, e);
} catch (ResourceNotFoundException e) {
throw new IllegalStateException("Resource not found: control=" + controlTemplate, e);
} catch (Exception e) {
throw new IllegalStateException("Generation failed: control=" + controlTemplate, e);
}
}
Aggregations