use of org.apache.velocity.Template in project nextprot-api by calipho-sib.
the class EntryTTLStreamWriter method writeHeader.
@Override
protected void writeHeader(Map<String, Object> infos) {
int entryNum = (int) infos.get(EntryStreamWriter.getEntryCountKey());
ReleaseInfoVersions releaseInfoVersions = (ReleaseInfoVersions) infos.get(EntryStreamWriter.getReleaseInfoKey());
Template headerTemplate = velocityConfig.getVelocityEngine().getTemplate("turtle/prefix.ttl.vm");
headerTemplate.merge(new NXVelocityContext(entryNum, releaseInfoVersions), getStream());
}
use of org.apache.velocity.Template in project nextprot-api by calipho-sib.
the class EntryXMLStreamWriter method writeHeader.
@Override
protected void writeHeader(Map<String, Object> infos) throws IOException {
int entryNum = (int) infos.get(EntryStreamWriter.getEntryCountKey());
ReleaseInfoVersions releaseInfoVersions = (ReleaseInfoVersions) infos.get(EntryStreamWriter.getReleaseInfoKey());
ReleaseInfoDataSources releaseInfoDataSources = (ReleaseInfoDataSources) infos.get(EntryStreamWriter.getReleaseDataSourcesKey());
Template headerTemplate = velocityConfig.getVelocityEngine().getTemplate("export-header.xml.vm");
headerTemplate.merge(new NXVelocityContext(entryNum, releaseInfoVersions), getStream());
Template releaseContentTemplate = velocityConfig.getVelocityEngine().getTemplate("release-contents.xml.vm");
writePrettyXml(releaseContentTemplate, new NXVelocityContext(entryNum, releaseInfoVersions, releaseInfoDataSources), 2);
getStream().write(" </header>\n");
getStream().write(" <entry-list>\n");
}
use of org.apache.velocity.Template in project nextprot-api by calipho-sib.
the class EntryTTLValidationIntegrationTest method addTurtlePrefixes.
static void addTurtlePrefixes(Writer writer, VelocityConfig config) {
Template headerTemplate = config.getVelocityEngine().getTemplate("turtle/prefix.ttl.vm");
headerTemplate.merge(new NXVelocityContext(), writer);
}
use of org.apache.velocity.Template in project OpenOLAT by OpenOLAT.
the class VelocityHelper method merge.
/**
* @param template e.g. org/olat/demo/_content/index.html
* @param c the context
* @param theme the theme e.g. "accessibility" or "printing". may be null if the default theme ("") should be taken
* @return String the rendered template
*/
private void merge(String template, Context c, Writer wOut, String theme) {
try {
Template vtemplate = null;
if (isLogDebugEnabled())
logDebug("Merging template::" + template + " for theme::" + theme, null);
if (theme != null) {
// try the theme first, if resource not found exception, fallback to normal resource.
// e.g. try /_accessibility/index.html first, if not found, try /index.html.
// this allows for themes to only provide the delta to the default templates
// todo we could avoid those string operations, if the performance gain is measureable
int latestSlash = template.lastIndexOf('/');
StringBuilder sb = new StringBuilder(template.substring(0, latestSlash));
sb.append("/_").append(theme).append("/").append(template.substring(latestSlash + 1));
String themedTemplatePath = sb.toString();
// check cache
boolean notFound = resourcesNotFound.contains(themedTemplatePath);
if (!notFound) {
// never tried before -> try to load it
if (!ve.resourceExists(themedTemplatePath)) {
// this will happen once for each theme when a resource does not exist in its themed variant but only in the default theme.
if (!Settings.isDebuging()) {
resourcesNotFound.add(themedTemplatePath);
}
// for debugging, allow introduction of themed files without restarting the application
} else {
// template exists -> load it
vtemplate = ve.getTemplate(themedTemplatePath, VelocityModule.getInputEncoding());
}
}
// if not found, fallback to standard
if (vtemplate == null) {
vtemplate = ve.getTemplate(template, VelocityModule.getInputEncoding());
}
} else {
// no theme, load the standard template
vtemplate = ve.getTemplate(template, VelocityModule.getInputEncoding());
}
vtemplate.merge(c, wOut);
} catch (MethodInvocationException me) {
throw new OLATRuntimeException(VelocityHelper.class, "MethodInvocationException occured while merging template: methName:" + me.getMethodName() + ", refName:" + me.getReferenceName(), me.getWrappedThrowable());
} catch (Exception e) {
throw new OLATRuntimeException(VelocityHelper.class, "exception occured while merging template: " + e.getMessage(), e);
}
}
use of org.apache.velocity.Template in project thingsboard by thingsboard.
the class VelocityUtils method create.
public static Template create(String source, String templateName) throws ParseException {
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(source);
SimpleNode node = runtimeServices.parse(reader, templateName);
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
return template;
}
Aggregations