Search in sources :

Example 1 with I18nManagerWrapper

use of com.agiletec.aps.system.services.i18n.I18nManagerWrapper in project entando-core by entando.

the class BaseContentRenderer method render.

@Override
public String render(Content content, long modelId, String langCode, RequestContext reqCtx) {
    String renderedEntity = null;
    List<TextAttributeCharReplaceInfo> conversions = null;
    try {
        conversions = this.convertSpecialCharacters(content, langCode);
        String contentModel = this.getModelShape(modelId);
        Context velocityContext = new VelocityContext();
        ContentWrapper contentWrapper = (ContentWrapper) this.getEntityWrapper(content);
        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 content");
        }
        stringWriter.flush();
        renderedEntity = stringWriter.toString();
    } catch (Throwable t) {
        _logger.error("Error rendering content", t);
        // ApsSystemUtils.logThrowable(t, this, "render", "Error rendering content");
        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)

Example 2 with I18nManagerWrapper

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

Example 3 with I18nManagerWrapper

use of com.agiletec.aps.system.services.i18n.I18nManagerWrapper 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

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 I18nManagerWrapper (com.agiletec.aps.system.services.i18n.I18nManagerWrapper)3 StringWriter (java.io.StringWriter)3 VelocityContext (org.apache.velocity.VelocityContext)3 Context (org.apache.velocity.context.Context)3 RequestContext (com.agiletec.aps.system.RequestContext)2 TextAttributeCharReplaceInfo (com.agiletec.aps.system.common.renderer.TextAttributeCharReplaceInfo)2