use of org.apache.velocity.context.Context in project openolat by klemens.
the class TaskFolderCallback method getTaskDeletedMailBody.
private String getTaskDeletedMailBody(UserRequest ureq, String fileName, String courseName, String courseLink) {
// grab standard text
String confirmation = translate("task.deleted.body");
Context c = new VelocityContext();
Identity identity = ureq.getIdentity();
c.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
c.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
c.put("email", UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()));
c.put("filename", fileName);
c.put("coursename", courseName);
c.put("courselink", courseLink);
return VelocityHelper.getInstance().evaluateVTL(confirmation, c);
}
use of org.apache.velocity.context.Context in project openolat by klemens.
the class DropboxController method getConfirmation.
private String getConfirmation(UserRequest ureq, String filename) {
// grab confirmation-text from bb-config
String confirmation = config.getStringValue(TACourseNode.CONF_DROPBOX_CONFIRMATION);
Context c = new VelocityContext();
Identity identity = ureq.getIdentity();
c.put("login", identity.getName());
c.put("first", identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
c.put("last", identity.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
c.put("email", UserManager.getInstance().getUserDisplayEmail(identity, getLocale()));
c.put("filename", filename);
Date now = new Date();
Formatter f = Formatter.getInstance(ureq.getLocale());
c.put("date", f.formatDate(now));
c.put("time", f.formatTime(now));
// update attempts counter for this user: one file - one attempts
AssessableCourseNode acn = (AssessableCourseNode) node;
acn.incrementUserAttempts(userCourseEnv, Role.user);
// log entry for this file
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
am.appendToUserNodeLog(node, identity, identity, "FILE UPLOADED: " + filename);
return VelocityHelper.getInstance().evaluateVTL(confirmation, c);
}
use of org.apache.velocity.context.Context in project openolat by klemens.
the class LocalizedXSLTransformer method initTransformer.
/**
* Helper to create XSLT transformer for this instance
*/
private void initTransformer() {
// translate xsl with velocity
Context vcContext = new VelocityContext();
vcContext.put("t", pT);
vcContext.put("staticPath", StaticMediaDispatcher.createStaticURIFor(""));
String xslAsString = "";
try (InputStream xslin = getClass().getResourceAsStream("/org/olat/ims/resources/xsl/" + XSLFILENAME)) {
xslAsString = slurp(xslin);
} catch (IOException e) {
log.error("Could not convert xsl to string!", e);
}
String replacedOutput = evaluateValue(xslAsString, vcContext);
TransformerFactory tfactory = TransformerFactory.newInstance();
XMLReader reader;
try {
reader = XMLReaderFactory.createXMLReader();
reader.setEntityResolver(er);
Source xsltsource = new SAXSource(reader, new InputSource(new StringReader(replacedOutput)));
templates = tfactory.newTemplates(xsltsource);
} catch (SAXException e) {
throw new OLATRuntimeException("Could not initialize transformer!", e);
} catch (TransformerConfigurationException e) {
throw new OLATRuntimeException("Could not initialize transformer (wrong config)!", e);
}
}
use of org.apache.velocity.context.Context in project dbflute-core by dbflute.
the class DfAbstractTexenTask method setupControlContext.
protected Context setupControlContext() {
final Context ctx;
try {
ctx = initControlContext();
} catch (Exception e) {
String msg = "Failed to initialize control context:";
msg = msg + " templatePath=" + templatePath + " useClasspath=" + useClasspath;
throw new IllegalStateException(msg, e);
}
try {
populateInitialContext(ctx);
} catch (Exception e) {
String msg = "Failed to populate initial context:";
msg = msg + " templatePath=" + templatePath + " useClasspath=" + useClasspath;
throw new IllegalStateException(msg, e);
}
if (contextProperties != null) {
for (Iterator<?> i = contextProperties.getKeys(); i.hasNext(); ) {
String property = (String) i.next();
String value = contextProperties.getString(property);
try {
ctx.put(property, new Integer(value));
} catch (NumberFormatException nfe) {
String booleanString = contextProperties.testBoolean(value);
if (booleanString != null) {
ctx.put(property, Boolean.valueOf(booleanString));
} else {
if (property.endsWith("file.contents")) {
final String canonicalPath;
try {
canonicalPath = getProject().resolveFile(value).getCanonicalPath();
} catch (IOException e) {
String msg = "Failed to get the canonical path:";
msg = msg + " property=" + property + " value=" + value;
throw new IllegalStateException(msg, e);
}
value = fileContentsToString(canonicalPath);
property = property.substring(0, property.indexOf("file.contents") - 1);
}
ctx.put(property, value);
}
}
}
}
return ctx;
}
use of org.apache.velocity.context.Context in project entando-core by entando.
the class BaseEntityRenderer method render.
@Override
public String render(IApsEntity entity, String velocityTemplate, String langCode, boolean convertSpecialCharacters) {
String renderedEntity = null;
List<TextAttributeCharReplaceInfo> conversions = null;
try {
if (convertSpecialCharacters) {
conversions = this.convertSpecialCharacters(entity, langCode);
}
Context velocityContext = new VelocityContext();
EntityWrapper entityWrapper = this.getEntityWrapper(entity);
entityWrapper.setRenderingLang(langCode);
velocityContext.put(this.getEntityWrapperContextName(), entityWrapper);
I18nManagerWrapper i18nWrapper = new I18nManagerWrapper(langCode, this.getI18nManager());
velocityContext.put("i18n", i18nWrapper);
StringWriter stringWriter = new StringWriter();
boolean isEvaluated = Velocity.evaluate(velocityContext, stringWriter, "render", velocityTemplate);
if (!isEvaluated) {
throw new ApsSystemException("Rendering error");
}
stringWriter.flush();
renderedEntity = stringWriter.toString();
} catch (Throwable t) {
_logger.error("Rendering error. entity {}", entity.getTypeCode(), t);
// ApsSystemUtils.logThrowable(t, this, "render", "Rendering error");
renderedEntity = "";
} finally {
if (convertSpecialCharacters && null != conversions) {
this.replaceSpecialCharacters(conversions);
}
}
return renderedEntity;
}
Aggregations