Search in sources :

Example 16 with Context

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);
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 17 with Context

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);
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) MathEntryInteraction(uk.ac.ed.ph.qtiworks.mathassess.MathEntryInteraction)

Example 18 with Context

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;
}
Also used : Context(org.apache.velocity.context.Context) Escape(org.apache.velocity.anakia.Escape)

Example 19 with 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);
    }
}
Also used : Context(org.apache.velocity.context.Context) ParseErrorException(org.apache.velocity.exception.ParseErrorException) BuildException(org.apache.tools.ant.BuildException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) DfGenerator(org.dbflute.friends.velocity.DfGenerator) SQLException(java.sql.SQLException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException)

Example 20 with Context

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;
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Aggregations

Context (org.apache.velocity.context.Context)41 VelocityContext (org.apache.velocity.VelocityContext)33 StringWriter (java.io.StringWriter)9 IOException (java.io.IOException)8 Identity (org.olat.core.id.Identity)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 StringReader (java.io.StringReader)4 Locale (java.util.Locale)4 Map (java.util.Map)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 MailContext (org.olat.core.util.mail.MailContext)4 I18nManagerWrapper (com.agiletec.aps.system.services.i18n.I18nManagerWrapper)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)3 Renderer (org.olat.core.gui.render.Renderer)3