@Override
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
final UIPage page = (UIPage) component;
final TobagoConfig tobagoConfig = TobagoConfig.getInstance(facesContext);
// invoke prepareRender
RenderUtils.prepareRendererAll(facesContext, page);
LayoutContext layoutContext = new LayoutContext(page);
layoutContext.layout();
if (FacesContextUtils.getFocusId(facesContext) == null && !StringUtils.isBlank(page.getFocusId())) {
FacesContextUtils.setFocusId(facesContext, page.getFocusId());
}
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
// reset responseWriter and render page
facesContext.setResponseWriter(writer);
ResponseUtils.ensureNoCacheHeader(facesContext);
ResponseUtils.ensureContentSecurityPolicyHeader(facesContext, tobagoConfig.getContentSecurityPolicy());
if (LOG.isDebugEnabled()) {
for (Object o : page.getAttributes().entrySet()) {
Map.Entry entry = (Map.Entry) o;
LOG.debug("*** '" + entry.getKey() + "' -> '" + entry.getValue() + "'");
}
}
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
String viewId = facesContext.getViewRoot().getViewId();
String formAction = viewHandler.getActionURL(facesContext, viewId);
formAction = facesContext.getExternalContext().encodeActionURL(formAction);
String contentType = writer.getContentTypeWithCharSet();
ResponseUtils.ensureContentTypeHeader(facesContext, contentType);
String clientId = page.getClientId(facesContext);
final ClientProperties client = VariableResolverUtils.resolveClientProperties(facesContext);
final ProjectStage projectStage = tobagoConfig.getProjectStage();
final boolean developmentMode = projectStage == ProjectStage.Development;
final boolean debugMode = client.isDebugMode() || developmentMode;
final boolean productionMode = !debugMode && projectStage == ProjectStage.Production;
int clientLogSeverity = 2;
if (debugMode) {
String severity = (String) facesContext.getExternalContext().getRequestMap().get(CLIENT_DEBUG_SEVERITY);
if (LOG.isDebugEnabled()) {
LOG.debug("get " + CLIENT_DEBUG_SEVERITY + " = " + severity);
}
if (severity != null) {
try {
int index = severity.indexOf(';');
if (index == -1) {
index = severity.length();
}
clientLogSeverity = Integer.parseInt(severity.substring(0, index));
} catch (NumberFormatException e) {
// ignore; use default
}
}
}
boolean preventFrameAttacks = tobagoConfig.isPreventFrameAttacks();
if (!FacesContextUtils.isAjax(facesContext)) {
HtmlRendererUtils.renderDojoDndSource(facesContext, component);
String title = (String) page.getAttributes().get(Attributes.LABEL);