use of jakarta.faces.component.Doctype in project mojarra by eclipse-ee4j.
the class FaceletViewHandlingStrategy method renderView.
/**
* @see jakarta.faces.view.ViewDeclarationLanguage#renderView(jakarta.faces.context.FacesContext,
* jakarta.faces.component.UIViewRoot)
*/
@Override
public void renderView(FacesContext ctx, UIViewRoot viewToRender) throws IOException {
// Suppress rendering if "rendered" property on the component is false
if (!viewToRender.isRendered()) {
return;
}
// Log request
if (LOGGER.isLoggable(FINE)) {
LOGGER.fine("Rendering View: " + viewToRender.getViewId());
}
WriteBehindStateWriter stateWriter = null;
try {
// Only build the view if this view has not yet been built.
if (!isViewPopulated(ctx, viewToRender)) {
vdlFactory.getViewDeclarationLanguage(viewToRender.getViewId()).buildView(ctx, viewToRender);
}
// Setup writer and assign it to the ctx
ResponseWriter origWriter = ctx.getResponseWriter();
if (origWriter == null) {
origWriter = createResponseWriter(ctx);
}
ExternalContext extContext = ctx.getExternalContext();
/*
* Make sure we have a session here if we are using server state saving. The WriteBehindStateWriter needs an active
* session when it writes out state to a server session.
*
* Note if you flag a view as transient then we won't acquire the session as you are stating it does not need one.
*/
if (isServerStateSaving() && !viewToRender.isTransient()) {
getSession(ctx);
}
stateWriter = new WriteBehindStateWriter(extContext.getResponseOutputWriter(), ctx, responseBufferSize);
ResponseWriter writer = origWriter.cloneWithWriter(stateWriter);
ctx.setResponseWriter(writer);
if (ctx.getPartialViewContext().isPartialRequest()) {
// Any pre/post processing logic such as startDocument(), doPostPhaseActions() and endDocument() must be done in PartialViewContextImpl, see also #4977
viewToRender.encodeAll(ctx);
} else {
if (ctx.isProjectStage(Development)) {
FormOmittedChecker.check(ctx);
}
// Render the XML declaration to the response
String xmlDecl = getXMLDECLFromFacesContextAttributes(ctx);
if (xmlDecl != null) {
// Do not escape.
writer.writePreamble(xmlDecl);
}
// Render the DOCTYPE declaration to the response
Doctype doctype = viewToRender.getDoctype();
if (doctype != null) {
if (doctype instanceof UIComponent) {
// E.g. HtmlDoctype + DoctypeRenderer
((UIComponent) doctype).encodeAll(ctx);
} else {
// Do not escape.
writer.writeDoctype(DoctypeRenderer.toString(doctype));
}
writer.append('\n');
}
// Render the view to the response
writer.startDocument();
viewToRender.encodeAll(ctx);
try {
ctx.getExternalContext().getFlash().doPostPhaseActions(ctx);
} catch (UnsupportedOperationException uoe) {
LOGGER.fine("ExternalContext.getFlash() throw UnsupportedOperationException -> Flash unavailable");
}
writer.endDocument();
}
// Finish writing
writer.close();
// Flush to origWriter
if (stateWriter.stateWritten()) {
stateWriter.flushToWriter();
}
} catch (FileNotFoundException fnfe) {
handleFaceletNotFound(ctx, viewToRender.getViewId(), fnfe.getMessage());
} catch (Exception e) {
handleRenderException(ctx, e);
} finally {
if (stateWriter != null) {
stateWriter.release();
}
}
}
use of jakarta.faces.component.Doctype in project mojarra by eclipse-ee4j.
the class RenderKitUtils method isOutputHtml5Doctype.
/**
* Returns <code>true</code> if the view root associated with the given faces context will be rendered with a HTML5 doctype.
* @param context Involved faces context.
* @return <code>true</code> if the view root associated with the given faces context will be rendered with a HTML5 doctype.
*/
public static boolean isOutputHtml5Doctype(FacesContext context) {
UIViewRoot viewRoot = context.getViewRoot();
if (viewRoot == null) {
return false;
}
Doctype doctype = viewRoot.getDoctype();
if (doctype == null) {
return false;
}
return "html".equalsIgnoreCase(doctype.getRootElement()) && doctype.getPublic() == null && doctype.getSystem() == null;
}
use of jakarta.faces.component.Doctype in project mojarra by eclipse-ee4j.
the class DoctypeRenderer method encodeBegin.
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.append(toString((Doctype) component));
}
use of jakarta.faces.component.Doctype in project myfaces by apache.
the class HtmlRendererUtils method isOutputHtml5Doctype.
/**
* Returns <code>true</code> if the view root associated with the given faces context will be rendered with a HTML5 doctype.
* @param context Involved faces context.
* @return <code>true</code> if the view root associated with the given faces context will be rendered with a HTML5 doctype.
*/
public static boolean isOutputHtml5Doctype(FacesContext context) {
UIViewRoot viewRoot = context.getViewRoot();
if (viewRoot == null) {
return false;
}
Doctype doctype = viewRoot.getDoctype();
if (doctype == null) {
return false;
}
return "html".equalsIgnoreCase(doctype.getRootElement()) && doctype.getPublic() == null && doctype.getSystem() == null;
}
use of jakarta.faces.component.Doctype in project mojarra by eclipse-ee4j.
the class FaceletViewHandlingStrategy method buildView.
/**
* @see ViewDeclarationLanguage#buildView(FacesContext, UIViewRoot)
*/
@Override
public void buildView(FacesContext ctx, UIViewRoot view) throws IOException {
StateContext stateCtx = StateContext.getStateContext(ctx);
if (isViewPopulated(ctx, view)) {
Facelet facelet = faceletFactory.getFacelet(ctx, view.getViewId());
// virute of re-applying the handlers.
try {
stateCtx.setTrackViewModifications(false);
facelet.apply(ctx, view);
reapplyDynamicActions(ctx);
if (stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
markInitialStateIfNotMarked(view);
}
} finally {
stateCtx.setTrackViewModifications(true);
}
return;
}
view.setViewId(view.getViewId());
LOGGER.log(FINE, () -> "Building View: " + view.getViewId());
if (faceletFactory == null) {
faceletFactory = ApplicationAssociate.getInstance(ctx.getExternalContext()).getFaceletFactory();
}
RequestStateManager.set(ctx, FACELET_FACTORY, faceletFactory);
Facelet facelet = faceletFactory.getFacelet(ctx, view.getViewId());
// populate UIViewRoot
try {
ctx.getAttributes().put(IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
stateCtx.setTrackViewModifications(false);
facelet.apply(ctx, view);
if (facelet instanceof XMLFrontMatterSaver) {
XMLFrontMatterSaver frontMatterSaver = (XMLFrontMatterSaver) facelet;
Doctype doctype = frontMatterSaver.getSavedDoctype();
if (doctype != null) {
saveDOCTYPEToFacesContextAttributes(doctype);
}
String XMLDECL = frontMatterSaver.getSavedXMLDecl();
if (XMLDECL != null) {
saveXMLDECLToFacesContextAttributes(XMLDECL);
}
}
Doctype doctype = getDOCTYPEFromFacesContextAttributes(ctx);
if (doctype != null) {
view.setDoctype(doctype);
}
if (!stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
reapplyDynamicActions(ctx);
}
startTrackViewModifications(ctx, view);
} finally {
ctx.getAttributes().remove(IS_BUILDING_INITIAL_STATE);
}
ctx.getApplication().publishEvent(ctx, PostAddToViewEvent.class, UIViewRoot.class, view);
markInitialState(ctx, view);
setViewPopulated(ctx, view);
}
Aggregations