use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.
the class FreemarkerTemplateParameterTag method doStartTag.
@Override
public int doStartTag() throws JspException {
ServletRequest request = this.pageContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
try {
ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
TemplateModel templateModel = ebc.getTemplateModel();
if (!(templateModel instanceof AllHttpScopesHashModel)) {
return EVAL_BODY_INCLUDE;
}
AllHttpScopesHashModel hashModel = (AllHttpScopesHashModel) templateModel;
Object object = this.pageContext.getAttribute(this.getValueName());
if (null == object) {
Environment environment = Environment.getCurrentEnvironment();
if (null != environment) {
Object wrapper = environment.getVariable(this.getValueName());
if (null != wrapper) {
if (wrapper instanceof StringModel) {
object = ((StringModel) wrapper).getWrappedObject();
} else {
object = wrapper;
}
}
}
}
if (null != object) {
hashModel.put(this.getVar(), object);
}
} catch (Throwable t) {
_logger.error("error in doStartTag", t);
throw new JspException("Error during tag initialization", t);
}
return EVAL_BODY_INCLUDE;
}
use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.
the class FreemarkerTemplateParameterTag method doEndTag.
@Override
public int doEndTag() throws JspException {
if (this.isRemoveOnEndTag()) {
ServletRequest request = this.pageContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
try {
ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
TemplateModel templateModel = ebc.getTemplateModel();
if (templateModel instanceof AllHttpScopesHashModel) {
AllHttpScopesHashModel hashModel = (AllHttpScopesHashModel) templateModel;
hashModel.remove(this.getVar());
}
} catch (Throwable t) {
_logger.error("error in doEndTag", t);
throw new JspException("Error evaluating di end tag", t);
}
}
this.release();
return EVAL_PAGE;
}
use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.
the class ControllerServlet method initFreemarker.
protected void initFreemarker(HttpServletRequest request, HttpServletResponse response, RequestContext reqCtx) throws TemplateModelException {
Configuration config = new Configuration();
DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
config.setObjectWrapper(wrapper);
config.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);
TemplateModel templateModel = this.createModel(wrapper, this.getServletContext(), request, response);
ExecutorBeanContainer ebc = new ExecutorBeanContainer(config, templateModel);
reqCtx.addExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER, ebc);
}
use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.
the class GuiFragmentResult method doExecute.
/**
* Execute this result, using the specified fragment.
* @param code The code of the fragment
* @param invocation The invocation
*/
@Override
public void doExecute(String code, ActionInvocation invocation) throws Exception {
if (null == code) {
code = conditionalParse(this._code, invocation);
}
if (null == code) {
this.executeDispatcherResult(invocation);
return;
}
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req);
try {
GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code);
String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null;
if (StringUtils.isBlank(output)) {
_logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace());
boolean execution = this.executeDispatcherResult(invocation);
if (!execution) {
output = "The fragment '" + code + "' is not available";
} else {
return;
}
}
RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
Writer writer = this.getWriter();
Template template = new Template(code, new StringReader(output), ebc.getConfiguration());
template.process(ebc.getTemplateModel(), writer);
} catch (Throwable t) {
_logger.error("Error processing GuiFragment result!", t);
throw new RuntimeException("Error processing GuiFragment result!", t);
}
}
use of org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer in project entando-core by entando.
the class GuiFragmentTag method extractFragmentOutput.
protected String extractFragmentOutput(RequestContext reqCtx) throws ApsSystemException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, this.pageContext);
GuiFragment guiFragment = guiFragmentManager.getGuiFragment(this.getCode());
if (null == guiFragment || StringUtils.isBlank(guiFragment.getCurrentGui())) {
return null;
}
ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
Writer out = new OutputStreamWriter(baos);
Template template = new Template(this.getCode(), new StringReader(guiFragment.getCurrentGui()), ebc.getConfiguration());
template.process(ebc.getTemplateModel(), out);
out.flush();
} catch (Throwable t) {
String msg = "Error creating fragment output - code '" + this.getCode() + "'";
_logger.error(msg, t);
throw new ApsSystemException(msg, t);
}
return baos.toString();
}
Aggregations