use of org.apache.velocity.context.Context in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderPositionObjectStage.
private void renderPositionObjectStage(AssessmentRenderer renderer, StringOutput sb, PositionObjectStage positionObjectStage, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
Context ctx = new VelocityContext();
ctx.put("positionObjectStage", positionObjectStage);
String page = getInteractionTemplate(positionObjectStage);
renderVelocity(renderer, sb, positionObjectStage, ctx, page, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
}
use of org.apache.velocity.context.Context in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderCustomInteraction.
/**
* Render the interaction or the PositionStageObject
* @param renderer
* @param sb
* @param interaction
* @param assessmentItem
* @param itemSessionState
* @param component
* @param ubu
* @param translator
*/
private void renderCustomInteraction(AssessmentRenderer renderer, StringOutput sb, CustomInteraction<?> interaction, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
Context ctx = new VelocityContext();
ctx.put("interaction", interaction);
String page;
if (interaction instanceof MathEntryInteraction) {
page = velocity_root.concat("/mathEntryInteraction.html");
} else {
page = velocity_root.concat("/unsupportedCustomInteraction.html");
}
renderVelocity(renderer, sb, interaction, ctx, page, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
}
use of org.apache.velocity.context.Context in project dbflute-core by dbflute.
the class TorqueDocumentationTask method initControlContext.
// ===================================================================================
// Prepare Generation
// ==================
@Override
public Context initControlContext() throws Exception {
final Context context = super.initControlContext();
context.put("escape", new Escape());
context.put("selector", _documentSelector);
return context;
}
use of org.apache.velocity.context.Context 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);
}
}
use of org.apache.velocity.context.Context in project entando-core by entando.
the class DefaultVelocityRenderer method render.
@Override
public String render(Object object, String velocityTemplate) {
String renderedObject = null;
try {
Context velocityContext = new VelocityContext();
velocityContext.put(this.getWrapperContextName(), object);
StringWriter stringWriter = new StringWriter();
boolean isEvaluated = Velocity.evaluate(velocityContext, stringWriter, "render", velocityTemplate);
if (!isEvaluated) {
throw new ApsSystemException("Rendering error");
}
stringWriter.flush();
renderedObject = stringWriter.toString();
} catch (Throwable t) {
_logger.error("Rendering error, class: {} - template: {}", object.getClass().getSimpleName(), velocityTemplate, t);
// ApsSystemUtils.logThrowable(t, this, "render", "Rendering error");
renderedObject = "";
}
return renderedObject;
}
Aggregations