From 32c1810af67d54746e5b3eb5987d4546f150733a Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sun, 9 Jul 2023 11:40:06 -0400 Subject: [PATCH] https://github.com/eclipse-ee4j/mojarra/issues/5273 Split FaceletDoctype from HtmlDoctype as it's in prod env not recreated on every request --- .../view/FaceletViewHandlingStrategy.java | 10 ++++-- .../facelets/compiler/FaceletDoctype.java | 32 +++++++++++++++++++ .../faces/facelets/compiler/SAXCompiler.java | 9 +----- 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 impl/src/main/java/com/sun/faces/facelets/compiler/FaceletDoctype.java diff --git a/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java b/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java index 3522957f44..4075ffb474 100644 --- a/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java +++ b/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java @@ -81,6 +81,7 @@ import com.sun.faces.application.ApplicationAssociate; import com.sun.faces.config.WebConfiguration; import com.sun.faces.context.StateContext; +import com.sun.faces.facelets.compiler.FaceletDoctype; import com.sun.faces.facelets.el.ContextualCompositeMethodExpression; import com.sun.faces.facelets.el.VariableMapperWrapper; import com.sun.faces.facelets.impl.DefaultFaceletFactory; @@ -113,6 +114,7 @@ import jakarta.faces.component.UIComponent; import jakarta.faces.component.UIPanel; import jakarta.faces.component.UIViewRoot; +import jakarta.faces.component.html.HtmlDoctype; import jakarta.faces.component.visit.VisitContext; import jakarta.faces.component.visit.VisitResult; import jakarta.faces.context.ExternalContext; @@ -342,9 +344,13 @@ public void buildView(FacesContext ctx, UIViewRoot view) throws IOException { } } - Doctype doctype = getDOCTYPEFromFacesContextAttributes(ctx); + FaceletDoctype doctype = (FaceletDoctype) getDOCTYPEFromFacesContextAttributes(ctx); if (doctype != null) { - view.setDoctype(doctype); + HtmlDoctype htmlDoctype = new HtmlDoctype(); + htmlDoctype.setRootElement(doctype.getRootElement()); + htmlDoctype.setPublic(doctype.getPublic()); + htmlDoctype.setSystem(doctype.getSystem()); + view.setDoctype(htmlDoctype); } if (!stateCtx.isPartialStateSaving(ctx, view.getViewId())) { diff --git a/impl/src/main/java/com/sun/faces/facelets/compiler/FaceletDoctype.java b/impl/src/main/java/com/sun/faces/facelets/compiler/FaceletDoctype.java new file mode 100644 index 0000000000..ed236379da --- /dev/null +++ b/impl/src/main/java/com/sun/faces/facelets/compiler/FaceletDoctype.java @@ -0,0 +1,32 @@ +package com.sun.faces.facelets.compiler; + +import jakarta.faces.component.Doctype; + +public class FaceletDoctype implements Doctype { + + private final String rootElement; + private final String _public; + private final String system; + + public FaceletDoctype(String rootElement, String _public, String system) { + this.rootElement = rootElement; + this._public = _public; + this.system = system; + } + + @Override + public String getRootElement() { + return rootElement; + } + + @Override + public String getPublic() { + return _public; + } + + @Override + public String getSystem() { + return system; + } + +} diff --git a/impl/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java b/impl/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java index 4780104665..7c69a67751 100644 --- a/impl/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java +++ b/impl/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java @@ -47,7 +47,6 @@ import com.sun.faces.facelets.tag.faces.core.CoreLibrary; import com.sun.faces.util.Util; -import jakarta.faces.component.html.HtmlDoctype; import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; import jakarta.faces.view.Location; @@ -208,13 +207,7 @@ public void startDTD(String name, String publicId, String systemId) throws SAXEx boolean outputAsHtml5 = facelets.isOutputHtml5Doctype(alias); if (inDocument && (processAsXhtml || outputAsHtml5)) { - HtmlDoctype doctype = new HtmlDoctype(); - doctype.setRootElement(name); - - if (!outputAsHtml5) { - doctype.setPublic(publicId); - doctype.setSystem(systemId); - } + FaceletDoctype doctype = new FaceletDoctype(name, outputAsHtml5 ? null : publicId, outputAsHtml5 ? null : systemId); // It is essential to save the doctype here because this is the // *only* time we will have access to it.