1. addSelf() is odd, does not match with TC8. Bad merge?
2. Both add() and addSelf() should display a warning.
Maybe move "log.warn()" into locationFor(..) method.
3. What is the point of putting null values into the maps.
4. Message:
> digesterFactory.missingSchema=The XML schema [{0}] could not be found. This
> is likely to break XML validation if enabled.
It is ambiguous to what "if enabled" refers to (what is the subject
for that verb).
Overall I do not like motivation behind this change (as I replied in
Violetta's thread), but technically it does not change behaviour (in
the correct case) and provides a warning message instead of ugly NPE.
Thus it is OK with me.
2014-03-14 1:33 GMT+04:00 <[email protected]>:
> Author: markt
> Date: Thu Mar 13 21:33:08 2014
> New Revision: 1577328
>
> URL: http://svn.apache.org/r1577328
> Log:
> Enable Tomcat to work in a OSGI environment with alternative Servlet and JSP
> API JARs.
>
> Modified:
> tomcat/tc7.0.x/trunk/ (props changed)
>
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/DigesterFactory.java
>
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/LocalStrings.properties
> tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>
> Propchange: tomcat/tc7.0.x/trunk/
> ------------------------------------------------------------------------------
> Merged /tomcat/trunk:r1577315,1577324
>
> Modified:
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/DigesterFactory.java
> URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/DigesterFactory.java?rev=1577328&r1=1577327&r2=1577328&view=diff
> ==============================================================================
> ---
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/DigesterFactory.java
> (original)
> +++
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/DigesterFactory.java
> Thu Mar 13 21:33:08 2014
> @@ -23,8 +23,11 @@ import java.util.Map;
>
> import javax.servlet.ServletContext;
>
> +import org.apache.juli.logging.Log;
> +import org.apache.juli.logging.LogFactory;
> import org.apache.tomcat.util.digester.Digester;
> import org.apache.tomcat.util.digester.RuleSet;
> +import org.apache.tomcat.util.res.StringManager;
> import org.xml.sax.ext.EntityResolver2;
>
> /**
> @@ -33,6 +36,25 @@ import org.xml.sax.ext.EntityResolver2;
> */
> public class DigesterFactory {
>
> + private static final Log log = LogFactory.getLog(DigesterFactory.class);
> + private static final StringManager sm =
> + StringManager.getManager(Constants.PACKAGE_NAME);
> +
> + private static final Class<ServletContext> CLASS_SERVLET_CONTEXT;
> + private static final Class<?> CLASS_JSP_CONTEXT;
> +
> + static {
> + CLASS_SERVLET_CONTEXT = ServletContext.class;
> + Class<?> jspContext = null;
> + try {
> + jspContext = Class.forName("javax.servlet.jsp.JspContext");
> + } catch (ClassNotFoundException e) {
> + // Ignore - JSP API is not present.
> + }
> + CLASS_JSP_CONTEXT = jspContext;
> + }
> +
> +
> /**
> * Mapping of well-known public IDs used by the Servlet API to the
> matching
> * local resource.
> @@ -50,39 +72,39 @@ public class DigesterFactory {
> Map<String, String> systemIds = new HashMap<String, String>();
>
> // W3C
> - publicIds.put(XmlIdentifiers.XSD_10_PUBLIC, idFor("XMLSchema.dtd"));
> - publicIds.put(XmlIdentifiers.DATATYPES_PUBLIC,
> idFor("datatypes.dtd"));
> - systemIds.put(XmlIdentifiers.XML_2001_XSD, idFor("xml.xsd"));
> + add(publicIds, XmlIdentifiers.XSD_10_PUBLIC,
> locationFor("XMLSchema.dtd"));
> + add(publicIds, XmlIdentifiers.DATATYPES_PUBLIC,
> locationFor("datatypes.dtd"));
> + add(systemIds, XmlIdentifiers.XML_2001_XSD, locationFor("xml.xsd"));
>
> // from J2EE 1.2
> - publicIds.put(XmlIdentifiers.WEB_22_PUBLIC,
> idFor("web-app_2_2.dtd"));
> - publicIds.put(XmlIdentifiers.TLD_11_PUBLIC,
> idFor("web-jsptaglibrary_1_1.dtd"));
> + add(publicIds, XmlIdentifiers.WEB_22_PUBLIC,
> locationFor("web-app_2_2.dtd"));
> + add(publicIds, XmlIdentifiers.TLD_11_PUBLIC,
> locationFor("web-jsptaglibrary_1_1.dtd"));
>
> // from J2EE 1.3
> - publicIds.put(XmlIdentifiers.WEB_23_PUBLIC,
> idFor("web-app_2_3.dtd"));
> - publicIds.put(XmlIdentifiers.TLD_12_PUBLIC,
> idFor("web-jsptaglibrary_1_2.dtd"));
> + add(publicIds, XmlIdentifiers.WEB_23_PUBLIC,
> locationFor("web-app_2_3.dtd"));
> + add(publicIds, XmlIdentifiers.TLD_12_PUBLIC,
> locationFor("web-jsptaglibrary_1_2.dtd"));
>
> // from J2EE 1.4
> -
> systemIds.put("http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd",
> - idFor("j2ee_web_services_1_1.xsd"));
> -
> systemIds.put("http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd",
> - idFor("j2ee_web_services_client_1_1.xsd"));
> - systemIds.put(XmlIdentifiers.WEB_24_XSD, idFor("web-app_2_4.xsd"));
> - systemIds.put(XmlIdentifiers.TLD_20_XSD,
> idFor("web-jsptaglibrary_2_0.xsd"));
> + add(systemIds,
> "http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd",
> + locationFor("j2ee_web_services_1_1.xsd"));
> + add(systemIds,
> "http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd",
> + locationFor("j2ee_web_services_client_1_1.xsd"));
> + add(systemIds, XmlIdentifiers.WEB_24_XSD,
> locationFor("web-app_2_4.xsd"));
> + add(systemIds, XmlIdentifiers.TLD_20_XSD,
> locationFor("web-jsptaglibrary_2_0.xsd"));
> addSelf(systemIds, "j2ee_1_4.xsd");
> addSelf(systemIds, "jsp_2_0.xsd");
>
> // from JavaEE 5
> - systemIds.put(XmlIdentifiers.WEB_25_XSD, idFor("web-app_2_5.xsd"));
> - systemIds.put(XmlIdentifiers.TLD_21_XSD,
> idFor("web-jsptaglibrary_2_1.xsd"));
> + add(systemIds, XmlIdentifiers.WEB_25_XSD,
> locationFor("web-app_2_5.xsd"));
> + add(systemIds, XmlIdentifiers.TLD_21_XSD,
> locationFor("web-jsptaglibrary_2_1.xsd"));
> addSelf(systemIds, "javaee_5.xsd");
> addSelf(systemIds, "jsp_2_1.xsd");
> addSelf(systemIds, "javaee_web_services_1_2.xsd");
> addSelf(systemIds, "javaee_web_services_client_1_2.xsd");
>
> // from JavaEE 6
> - systemIds.put(XmlIdentifiers.WEB_30_XSD, idFor("web-app_3_0.xsd"));
> - systemIds.put(XmlIdentifiers.WEB_FRAGMENT_30_XSD,
> idFor("web-fragment_3_0.xsd"));
> + add(systemIds, XmlIdentifiers.WEB_30_XSD,
> locationFor("web-app_3_0.xsd"));
> + add(systemIds, XmlIdentifiers.WEB_FRAGMENT_30_XSD,
> locationFor("web-fragment_3_0.xsd"));
> addSelf(systemIds, "web-common_3_0.xsd");
> addSelf(systemIds, "javaee_6.xsd");
> addSelf(systemIds, "jsp_2_2.xsd");
> @@ -94,17 +116,29 @@ public class DigesterFactory {
> }
>
> private static void addSelf(Map<String, String> ids, String id) {
> - String systemId = idFor(id);
> + String systemId = locationFor(id);
> + ids.put(id, systemId);
> ids.put(systemId, systemId);
> ids.put(id, systemId);
> }
>
> - private static String idFor(String url) {
> - URL id = ServletContext.class.getResource("resources/" + url);
> - if (id == null) {
> - id = ServletContext.class.getResource("jsp/resources/" + url);
> + private static void add(Map<String,String> ids, String id, String
> location) {
> + if (location == null) {
> + log.warn(sm.getString("digesterFactory.missingSchema", id));
> + } else {
> + ids.put(id, location);
> + }
> + }
> +
> + private static String locationFor(String name) {
> + URL location = CLASS_SERVLET_CONTEXT.getResource("resources/" +
> name);
> + if (location == null && CLASS_JSP_CONTEXT != null) {
> + location = CLASS_JSP_CONTEXT.getResource("resources/" + name);
> + }
> + if (location == null) {
> + return null;
> }
> - return id.toExternalForm();
> + return location.toExternalForm();
> }
>
>
>
> Modified:
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/LocalStrings.properties
> URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/LocalStrings.properties?rev=1577328&r1=1577327&r2=1577328&view=diff
> ==============================================================================
> ---
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/LocalStrings.properties
> (original)
> +++
> tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/descriptor/LocalStrings.properties
> Thu Mar 13 21:33:08 2014
> @@ -13,6 +13,8 @@
> # See the License for the specific language governing permissions and
> # limitations under the License.
>
> +digesterFactory.missingSchema=The XML schema [{0}] could not be found. This
> is likely to break XML validation if enabled.
> +
> localResolver.unresolvedEntity=Could not resolve XML resource [{0}] with
> public ID [{1}], system ID [{2}] and base URI [{3}] to a known, local entity.
>
> xmlErrorHandler.error=Non-fatal error [{0}] reported processing [{1}].
>
> Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
> URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1577328&r1=1577327&r2=1577328&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
> +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Mar 13 21:33:08 2014
> @@ -90,6 +90,12 @@
> simply undeploy the old version of the application before deploying
> the
> new version. (markt)
> </fix>
> + <fix>
> + Enable Tomcat to work with alternative Servlet and JSP API JARs that
> + package the XML schemas in such as way as to require a dependency on
> the
> + JSP API before enabling validation for web.xml. Tomcat has no such
> + dependency. (markt)
> + </fix>
> </changelog>
> </subsection>
> <subsection name="Coyote">
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]