Skip to content
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 @@ -626,7 +626,9 @@ void substrateResourceBuildItems(BuildProducer<NativeImageResourceBuildItem> nat
"org/apache/myfaces/resource/javaee_5.xsd",
"org/apache/myfaces/resource/jakartaee_9.xsd",
"org/apache/myfaces/resource/jakartaee_10.xsd",
"org/apache/myfaces/resource/jakartaee_11.xsd",
"org/apache/myfaces/resource/web-facelettaglibrary_2_0.xsd",
"org/apache/myfaces/resource/web-facelettaglibrary_4_1.xsd",
"org/apache/myfaces/resource/XMLSchema.dtd",
"org/apache/myfaces/resource/facesconfig_1_0.dtd",
"org/apache/myfaces/resource/web-facesconfig_1_0.dtd",
Expand All @@ -638,6 +640,7 @@ void substrateResourceBuildItems(BuildProducer<NativeImageResourceBuildItem> nat
"org/apache/myfaces/resource/web-facesconfig_2_3.xsd",
"org/apache/myfaces/resource/web-facesconfig_3_0.xsd",
"org/apache/myfaces/resource/web-facesconfig_4_0.xsd",
"org/apache/myfaces/resource/web-facesconfig_4_1.dtd",
"org/apache/myfaces/resource/web-facesconfig_5_0.xsd",
"org/apache/myfaces/resource/xml.xsd"));

Expand Down
10 changes: 10 additions & 0 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@
-->
<exclude>src/main/resources/org/apache/myfaces/resource/javaee_5.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/javaee_web_services_client_1_2.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/jakartaee_11.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/web-facesconfig_4_1.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/web-facelettaglibrary_4_1.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/jakartaee_web_services_client_2_0.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/javaee_8.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/web-facelettaglibrary_3_0.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/web-facelettaglibrary_4_0.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/web-facelettaglibrary_2_3.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/javaee_web_services_client_1_4.xsd</exclude>
<exclude>src/main/resources/org/apache/myfaces/resource/web-facelettaglibrary_2_2.xsd</exclude>

<!-- This file probably needs a license, but I don't know if it's safe to put it in there -->
<exclude>src/test/resources/org/apache/myfaces/context/nestedScriptCDATA.xml</exclude>
Expand Down
8 changes: 4 additions & 4 deletions impl/src/main/conf/META-INF/standard-faces-config-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* under the License.
-->

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">

<!-- Initial application element with partial values -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -60,8 +61,21 @@ public class ConfigFilesXmlValidationUtils
private final static String FACES_CONFIG_SCHEMA_PATH_23 = "org/apache/myfaces/resource/web-facesconfig_2_3.xsd";
private final static String FACES_CONFIG_SCHEMA_PATH_30 = "org/apache/myfaces/resource/web-facesconfig_3_0.xsd";
private final static String FACES_CONFIG_SCHEMA_PATH_40 = "org/apache/myfaces/resource/web-facesconfig_4_0.xsd";
private final static String FACES_CONFIG_SCHEMA_PATH_41 = "org/apache/myfaces/resource/web-facesconfig_4_1.xsd";
private final static String FACES_CONFIG_SCHEMA_PATH_50 = "org/apache/myfaces/resource/web-facesconfig_5_0.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH = "org/apache/myfaces/resource/web-facelettaglibrary_2_0.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH_20 =
"org/apache/myfaces/resource/web-facelettaglibrary_2_0.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH_22 =
"org/apache/myfaces/resource/web-facelettaglibrary_2_2.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH_23 =
"org/apache/myfaces/resource/web-facelettaglibrary_2_3.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH_30 =
"org/apache/myfaces/resource/web-facelettaglibrary_3_0.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH_40 =
"org/apache/myfaces/resource/web-facelettaglibrary_4_0.xsd";
private final static String FACES_TAGLIB_SCHEMA_PATH_41 =
"org/apache/myfaces/resource/web-facelettaglibrary_4_1.xsd";

public static class LSInputImpl implements LSInput
{
Expand Down Expand Up @@ -199,6 +213,18 @@ public LSInput resolveResource(String type, String namespaceURI,
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream("org/apache/myfaces/resource/javaee_7.xsd"));
}
if ("javaee_8.xsd".equals(systemId))
{
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream("org/apache/myfaces/resource/javaee_8.xsd"));
}
if ("javaee_web_services_client_1_4.xsd".equals(systemId))
{
String location = "org/apache/myfaces/resource/javaee_web_services_client_1_4.xsd";
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream(location));
}

}
if ("https://jakarta.ee/xml/ns/jakartaee".equals(namespaceURI))
{
Expand All @@ -212,12 +238,24 @@ public LSInput resolveResource(String type, String namespaceURI,
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream("org/apache/myfaces/resource/jakartaee_10.xsd"));
}
if ("jakartaee_11.xsd".equals(systemId))
{
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream("org/apache/myfaces/resource/jakartaee_11.xsd"));
}
if ("jakartaee_web_services_client_2_0.xsd".equals(systemId))
{
String location = "org/apache/myfaces/resource/jakartaee_web_services_client_2_0.xsd";
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream(location));
}
}
if ("http://www.w3.org/XML/1998/namespace".equals(namespaceURI))
{
return new LSInputImpl(publicId, systemId, baseURI,
ClassUtils.getResourceAsStream("org/apache/myfaces/resource/xml.xsd"));
}

return null;
}

Expand Down Expand Up @@ -280,7 +318,8 @@ private static Source getFacesConfigSchemaFileAsSource(ExternalContext externalC
: ("2.2".equals(version) ? FACES_CONFIG_SCHEMA_PATH_22
: ("2.3".equals(version) ? FACES_CONFIG_SCHEMA_PATH_23
: ("3.0".equals(version) ? FACES_CONFIG_SCHEMA_PATH_30
: ("4.0".equals(version) ? FACES_CONFIG_SCHEMA_PATH_40 : FACES_CONFIG_SCHEMA_PATH_50))))));
: ("4.0".equals(version) ? FACES_CONFIG_SCHEMA_PATH_40
: ("4.1".equals(version) ? FACES_CONFIG_SCHEMA_PATH_41 : FACES_CONFIG_SCHEMA_PATH_50)))))));

InputStream stream = ClassUtils.getResourceAsStream(xmlSchema);

Expand Down Expand Up @@ -374,6 +413,10 @@ else if (handler.isVersion40())
{
return "4.0";
}
else if (handler.isVersion41())
{
return "4.1";
}
else if (handler.isVersion50OrLater())
{
return "5.0";
Expand All @@ -397,6 +440,7 @@ private static class FacesConfigVersionCheckHandler extends DefaultHandler
private boolean version23;
private boolean version30;
private boolean version40;
private boolean version41;
private boolean version50OrLater;

public boolean isVersion11()
Expand Down Expand Up @@ -439,6 +483,11 @@ public boolean isVersion40()
return this.version40;
}

public boolean isVersion41()
{
return this.version41;
}

public boolean isVersion50OrLater()
{
return this.version50OrLater;
Expand All @@ -454,6 +503,7 @@ protected void reset()
this.version23 = false;
this.version30 = false;
this.version40 = false;
this.version41 = false;
this.version50OrLater = false;
}

Expand Down Expand Up @@ -513,6 +563,11 @@ else if (attributes.getValue(i).equals("4.0"))
reset();
this.version40 = true;
}
else if (attributes.getValue(i).equals("4.1"))
{
reset();
this.version41 = true;
}
else
{
reset();
Expand All @@ -524,12 +579,12 @@ else if (attributes.getValue(i).equals("4.0"))
}
}

public static void validateFaceletTagLibFile(URL xmlFile, ExternalContext externalContext, String version)
public static void validateFaceletTagLibFile(URL xmlFile, ExternalContext externalContext, Double version)
throws SAXException, IOException, ParserConfigurationException
{
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Source schemaFile = getFaceletSchemaFileAsSource(externalContext);
Source schemaFile = getFaceletSchemaFileAsSource(externalContext, version);
if (schemaFile == null)
{
throw new IOException("Could not find schema file for validation.");
Expand All @@ -548,44 +603,59 @@ public static void validateFaceletTagLibFile(URL xmlFile, ExternalContext extern
}
}

private static Source getFaceletSchemaFileAsSource(ExternalContext externalContext)
private static Source getFaceletSchemaFileAsSource(ExternalContext externalContext, Double version)
{
InputStream stream = ClassUtils.getResourceAsStream(FACES_TAGLIB_SCHEMA_PATH);
String tagLibraryPath = "";

if (stream == null)
if(version == 4.1)
{
stream = externalContext.getResourceAsStream(FACES_TAGLIB_SCHEMA_PATH);
tagLibraryPath = FACES_TAGLIB_SCHEMA_PATH_41;
}
else if(version == 4.0)
{
tagLibraryPath = FACES_TAGLIB_SCHEMA_PATH_40;
}

if (stream == null)
else if(version == 3.0)
{
return null;
tagLibraryPath = FACES_TAGLIB_SCHEMA_PATH_30;
}
else if(version == 2.3)
{
tagLibraryPath = FACES_TAGLIB_SCHEMA_PATH_23;
}
else if(version == 2.2)
{
tagLibraryPath = FACES_TAGLIB_SCHEMA_PATH_22;
}
else
{
tagLibraryPath = FACES_TAGLIB_SCHEMA_PATH_20;
}

return new StreamSource(stream);
}
InputStream stream = ClassUtils.getResourceAsStream(tagLibraryPath);

public static final String getFaceletTagLibVersion(URL url)
{
if (isTaglibDocument20OrLater(url))
if (stream == null)
{
return "2.0";
stream = externalContext.getResourceAsStream(tagLibraryPath);
}
else

if (stream == null)
{
return "1.0";
return null;
}

return new StreamSource(stream);
}

private static boolean isTaglibDocument20OrLater(URL url)
public static Double getTagLibVersion(URL url)
{
TagLibVersionHandler handler = new TagLibVersionHandler();
try
{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser;
VersionCheckHandler handler = new VersionCheckHandler();

// We need to create a non-validating, non-namespace aware parser used to simply check
// We need to create a non-validating, non-namespace aware parser used to simply
// check
// which version of the facelets taglib document we are dealing with.
factory.setNamespaceAware(false);
factory.setFeature("http://xml.org/sax/features/validation", false);
Expand All @@ -597,7 +667,7 @@ private static boolean isTaglibDocument20OrLater(URL url)
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setXIncludeAware(false);
}
}
catch (Throwable e)
{
log.log(Level.WARNING, "SAXParserFactory#setFeature not implemented. Skipping...", e);
Expand All @@ -608,39 +678,67 @@ private static boolean isTaglibDocument20OrLater(URL url)
conn.setUseCaches(false);
try (InputStream input = conn.getInputStream())
{
try
try
{
parser.parse (input, handler);
parser.parse(input, handler);
}
catch (SAXException e)
{
// This is as a result of our aborted parse, so ignore.
}
}

return handler.isVersion20OrLater();
}
return handler.getVersion();
}
catch (Throwable e)
{
// Most likely a result of our aborted parse, so ignore.
}

return false;
return handler.getDefaultVersion();
}


/*
* We need this class to do a quick check on a facelets taglib document to see if it's
* a pre-2.0 document. If it is, we really need to construct a DTD validating, non-namespace
* aware parser. Otherwise, we have to construct a schema validating, namespace-aware parser.
* We need this class to do a quick check on a facelets taglib document to see
* if it's
* a pre-2.0 document. If it is, we really need to construct a DTD validating,
* non-namespace
* aware parser. Otherwise, we have to construct a schema validating,
* namespace-aware parser.
*/
private static class VersionCheckHandler extends DefaultHandler
private static class TagLibVersionHandler extends DefaultHandler
{
private boolean version20OrLater;
private double version;
private double defaultVersion = 1.0;
private ArrayList<Double> acceptedVersions;

public TagLibVersionHandler()
{
acceptedVersions = new ArrayList<Double>();
// 1.0/1.1 isn't necessary as the version attribute wasn't required prior to 2.0
acceptedVersions.add(2.0);
acceptedVersions.add(2.2);
acceptedVersions.add(2.3);
acceptedVersions.add(3.0);
acceptedVersions.add(4.0);
acceptedVersions.add(4.1);
}

public Double getVersion()
{
if (acceptedVersions.contains(this.version))
{
return this.version;
}
else
{
return getDefaultVersion();
}
}

public boolean isVersion20OrLater()
public Double getDefaultVersion()
{
return this.version20OrLater;
return defaultVersion;
}

@Override
Expand All @@ -658,17 +756,24 @@ public void startElement(String uri, String localName, String name, Attributes a
: attributes.getQName(i);
if (attrName.equals("version"))
{
// This document has a "version" attribute in the <facelet-taglib> element, so
// it must be a 2.0 or later document as this attribute was never required before.
this.version20OrLater = true;
try
{
this.version = Double.parseDouble(attributes.getValue(i));
}
catch (Exception e)
{
this.version = getDefaultVersion();
}
}
}

// Throw a dummy parsing exception to terminate parsing as there really isn't any need to go any
// Throw a dummy parsing exception to terminate parsing as there really isn't
// any need to go any
// further.
// -= Leonardo Uribe =- THIS IS NOT GOOD PRACTICE! It is better to let the checker continue that
// -= Leonardo Uribe =- THIS IS NOT GOOD PRACTICE! It is better to let the
// checker continue that
// throw an exception, and run this one only when project stage != production.
//throw new SAXException();
// throw new SAXException();
}
}
}
Expand Down
Loading
Loading