Search in sources :

Example 41 with Context

use of org.apache.velocity.context.Context in project entando-core by entando.

the class BaseDataObjectRenderer method render.

@Override
public String render(DataObject dataobject, long modelId, String langCode, RequestContext reqCtx) {
    String renderedEntity = null;
    List<TextAttributeCharReplaceInfo> conversions = null;
    try {
        conversions = this.convertSpecialCharacters(dataobject, langCode);
        String contentModel = this.getModelShape(modelId);
        Context velocityContext = new VelocityContext();
        DataObjectWrapper contentWrapper = (DataObjectWrapper) this.getEntityWrapper(dataobject);
        contentWrapper.setRenderingLang(langCode);
        contentWrapper.setReqCtx(reqCtx);
        velocityContext.put(this.getEntityWrapperContextName(), contentWrapper);
        I18nManagerWrapper i18nWrapper = new I18nManagerWrapper(langCode, this.getI18nManager());
        velocityContext.put("i18n", i18nWrapper);
        SystemInfoWrapper systemInfoWrapper = new SystemInfoWrapper(reqCtx);
        velocityContext.put("info", systemInfoWrapper);
        StringWriter stringWriter = new StringWriter();
        boolean isEvaluated = Velocity.evaluate(velocityContext, stringWriter, "render", contentModel);
        if (!isEvaluated) {
            throw new ApsSystemException("Error rendering DataObject");
        }
        stringWriter.flush();
        renderedEntity = stringWriter.toString();
    } catch (Throwable t) {
        _logger.error("Error rendering dataobject", t);
        renderedEntity = "";
    } finally {
        if (null != conversions) {
            this.replaceSpecialCharacters(conversions);
        }
    }
    return renderedEntity;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) RequestContext(com.agiletec.aps.system.RequestContext) Context(org.apache.velocity.context.Context) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) TextAttributeCharReplaceInfo(com.agiletec.aps.system.common.renderer.TextAttributeCharReplaceInfo) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) I18nManagerWrapper(com.agiletec.aps.system.services.i18n.I18nManagerWrapper)

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