Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split FaceletDoctype from HtmlDoctype as it's in prod env not recreated on every request #5275

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down