use of org.apache.velocity.exception.ParseErrorException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method copyResourceIfExists.
protected boolean copyResourceIfExists(File file, String relFileName, VelocityContext context) throws IOException, MojoExecutionException {
for (Resource resource : resources) {
File resourceDirectory = new File(resource.getDirectory());
if (!resourceDirectory.exists()) {
continue;
}
// TODO - really should use the resource includes/excludes and name mapping
File source = new File(resourceDirectory, relFileName);
File templateSource = new File(resourceDirectory, relFileName + TEMPLATE_SUFFIX);
if (!source.exists() && templateSource.exists()) {
source = templateSource;
}
if (source.exists() && !source.equals(file)) {
if (source == templateSource) {
Reader reader = null;
Writer writer = null;
DeferredFileOutputStream os = new DeferredFileOutputStream(velocityFilterInMemoryThreshold, file);
try {
if (encoding != null) {
reader = new InputStreamReader(new FileInputStream(source), encoding);
writer = new OutputStreamWriter(os, encoding);
} else {
reader = ReaderFactory.newPlatformReader(source);
writer = WriterFactory.newPlatformWriter(os);
}
velocity.evaluate(context, writer, "", reader);
writer.close();
writer = null;
reader.close();
reader = null;
} catch (ParseErrorException e) {
throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
} catch (MethodInvocationException e) {
throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
} catch (ResourceNotFoundException e) {
throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
} finally {
IOUtil.close(writer);
IOUtil.close(reader);
}
fileWriteIfDiffers(os);
} else if (resource.isFiltering()) {
MavenFileFilterRequest req = setupRequest(resource, source, file);
try {
fileFilter.copyFile(req);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("Error filtering resource: " + source, e);
}
} else {
FileUtils.copyFile(source, file);
}
// exclude the original (so eclipse doesn't complain about duplicate resources)
resource.addExclude(relFileName);
return true;
}
}
return false;
}
use of org.apache.velocity.exception.ParseErrorException in project wcomponents by BorderTech.
the class VelocityRenderer method paintXml.
/**
* Paints the component in XML using the Velocity Template.
*
* @param component the component to paint.
* @param writer the writer to send the HTML output to.
*/
public void paintXml(final WComponent component, final Writer writer) {
if (LOG.isDebugEnabled()) {
LOG.debug("paintXml called for component class " + component.getClass());
}
String templateText = null;
if (component instanceof AbstractWComponent) {
AbstractWComponent abstractComp = ((AbstractWComponent) component);
templateText = abstractComp.getTemplateMarkUp();
}
try {
Map<String, WComponent> componentsByKey = new HashMap<>();
VelocityContext context = new VelocityContext();
fillContext(component, context, componentsByKey);
VelocityWriter velocityWriter = new VelocityWriter(writer, componentsByKey, UIContextHolder.getCurrent());
if (templateText != null) {
VelocityEngine engine = VelocityEngineFactory.getVelocityEngine();
engine.evaluate(context, velocityWriter, component.getClass().getSimpleName(), templateText);
} else {
Template template = getTemplate(component);
if (template == null) {
LOG.warn("VelocityRenderer invoked for a component with no template: " + component.getClass().getName());
} else {
template.merge(context, velocityWriter);
}
}
velocityWriter.close();
if (component instanceof VelocityProperties) {
((VelocityProperties) component).mapUsed();
}
} catch (ResourceNotFoundException rnfe) {
LOG.error("Could not find template '" + url + "' for component " + component.getClass().getName(), rnfe);
} catch (ParseErrorException pee) {
// syntax error : problem parsing the template
LOG.error("Parse problems", pee);
} catch (MethodInvocationException mie) {
// something invoked in the template
// threw an exception
Throwable wrapped = mie.getWrappedThrowable();
LOG.error("Problems with velocity", mie);
if (wrapped != null) {
LOG.error("Wrapped exception...", wrapped);
}
} catch (Exception e) {
LOG.error("Problems with velocity", e);
}
}
use of org.apache.velocity.exception.ParseErrorException in project cayenne by apache.
the class ResultDirective method render.
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
String column = getChildAsString(context, node, 0);
if (column == null) {
throw new ParseErrorException("Column name expected at line " + node.getLine() + ", column " + node.getColumn());
}
String alias = getChildAsString(context, node, 2);
String dataRowKey = getChildAsString(context, node, 3);
// determine what we want to name this column in a resulting DataRow...
String label = (!Util.isEmptyString(dataRowKey)) ? dataRowKey : (!Util.isEmptyString(alias)) ? alias : null;
ColumnDescriptor columnDescriptor = new ColumnDescriptor();
columnDescriptor.setName(column);
columnDescriptor.setDataRowKey(label);
String type = getChildAsString(context, node, 1);
if (type != null) {
columnDescriptor.setJavaClass(guessType(type));
}
// TODO: andrus 6/27/2007 - this is an unofficial jdbcType parameter
// that is added
// temporarily pending CAY-813 implementation for the sake of EJBQL
// query...
Object jdbcType = getChild(context, node, 4);
if (jdbcType instanceof Number) {
columnDescriptor.setJdbcType(((Number) jdbcType).intValue());
}
writer.write(column);
// won't probably buy us much.
if (!Util.isEmptyString(alias) && !alias.equals(column)) {
writer.write(" AS ");
writer.write(alias);
}
bindResult(context, columnDescriptor);
return true;
}
use of org.apache.velocity.exception.ParseErrorException in project carbon-apimgt by wso2.
the class GatewaySourceGeneratorImpl method getEndpointConfigStringFromTemplate.
@Override
public String getEndpointConfigStringFromTemplate(Endpoint endpoint) throws APITemplateException {
StringWriter writer = new StringWriter();
String templatePath = "resources" + File.separator + "template" + File.separator + "endpoint.xml";
try {
// build the context for template and apply the necessary decorators
ConfigContext configcontext = new EndpointContext(endpoint, packageName);
VelocityContext context = configcontext.getContext();
VelocityEngine velocityengine = new VelocityEngine();
velocityengine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
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();
}
Aggregations