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;
}
Aggregations