// Render the page.
if (Static.isInlineEditingAllContents(request)) {
response = new LazyWriterResponse(request, response);
}
writer = new HtmlWriter(response.getWriter());
((HtmlWriter) writer).putAllStandardDefaults();
request.setAttribute("sections", new PullThroughCache<String, Section>() {
@Override
protected Section produce(String name) {
return Query.from(Section.class).where("internalName = ?", name).first();
}
});
beginPage(request, response, writer, page);
if (!response.isCommitted()) {
request.getSession();
}
String context = request.getParameter("_context");
boolean contextNotBlank = !ObjectUtils.isBlank(context);
boolean embed = ObjectUtils.coalesce(
ObjectUtils.to(Boolean.class, request.getParameter("_embed")),
contextNotBlank);
String layoutPath = findLayoutPath(mainObject, embed);
if (page != null && ObjectUtils.isBlank(layoutPath)) {
layoutPath = findLayoutPath(page, embed);
if (!embed && ObjectUtils.isBlank(layoutPath)) {
layoutPath = page.getRendererPath();
}
}
if (ObjectUtils.isBlank(layoutPath) &&
Static.isPreview(request)) {
layoutPath = findLayoutPath(mainObject, true);
}
String typePath = mainType.as(Renderer.TypeModification.class).getPath();
boolean rendered = false;
try {
if (contextNotBlank) {
ContextTag.Static.pushContext(request, context);
}
if (!ObjectUtils.isBlank(layoutPath)) {
rendered = true;
JspUtils.include(request, response, writer, StringUtils.ensureStart(layoutPath, "/"));
} else if (page != null) {
Page.Layout layout = page.getLayout();
if (layout != null) {
rendered = true;
renderSection(request, response, writer, layout.getOutermostSection());
}
}
if (!rendered && !embed && !ObjectUtils.isBlank(typePath)) {
rendered = true;
JspUtils.include(request, response, writer, StringUtils.ensureStart(typePath, "/"));
}
if (!rendered && mainObject instanceof Renderer) {
rendered = true;
((Renderer) mainObject).renderObject(request, response, (HtmlWriter) writer);
}
} finally {
if (contextNotBlank) {
ContextTag.Static.popContext(request);
}
}
if (!rendered) {
if (Settings.isProduction()) {
chain.doFilter(request, response);
return;
} else {
StringBuilder message = new StringBuilder();
if (embed) {
message.append("@Renderer.EmbedPath required on [");
message.append(mainObject.getClass().getName());
message.append("] to render it in [");
message.append(ObjectUtils.isBlank(context) ? "_embed" : context);
message.append("] context");
} else {
message.append("@Renderer.Path or @Renderer.LayoutPath required on [");
message.append(mainObject.getClass().getName());
message.append("] to render it");
}
message.append(" (Object: [");
message.append(mainState.getLabel());
message.append("], ID: [");
message.append(mainState.getId().toString().replaceAll("-", ""));
message.append("])!");
throw new IllegalStateException(message.toString());
}
}
endPage(request, response, writer, page);
if (Static.isInlineEditingAllContents(request)) {
LazyWriterResponse lazyResponse = (LazyWriterResponse) response;
Map<String, String> map = new HashMap<String, String>();
State state = State.getInstance(mainObject);
StringBuilder marker = new StringBuilder();
map.put("id", state.getId().toString());
map.put("label", state.getLabel());
map.put("typeLabel", state.getType().getLabel());
marker.append("<span class=\"cms-mainObject\" style=\"display: none;\" data-object=\"");
marker.append(StringUtils.escapeHtml(ObjectUtils.toJson(map)));
marker.append("\"></span>");
lazyResponse.getLazyWriter().writeLazily(marker.toString());
}
} finally {
Database.Static.restoreDefault();
if (response instanceof LazyWriterResponse) {
((LazyWriterResponse) response).getLazyWriter().writePending();
}
}
if (Settings.isDebug() ||
(Static.isPreview(request) &&
!Boolean.TRUE.equals(request.getAttribute(PERSISTENT_PREVIEW_ATTRIBUTE)))) {
return;
}
String contentType = response.getContentType();
if (contentType == null ||
!StringUtils.ensureEnd(contentType, ";").startsWith("text/html;")) {
return;
}
Object mainObject = PageFilter.Static.getMainObject(request);
if (mainObject != null && user != null) {
if (!JspUtils.isError(request)) {
user.saveAction(request, mainObject);
}
@SuppressWarnings("all")
ToolPageContext page = new ToolPageContext(getServletContext(), request, response);
State mainState = State.getInstance(mainObject);
page.setDelegate(writer instanceof HtmlWriter ? (HtmlWriter) writer : new HtmlWriter(writer));
page.writeStart("style", "type", "text/css");
page.writeCss(".bsp-inlineEditorMain",
"background", "rgba(32, 52, 63, 0.8) !important",
"color", "white !important",