Author: markt
Date: Sun Aug 26 22:50:13 2012
New Revision: 1377540
URL: http://svn.apache.org/viewvc?rev=1377540&view=rev
Log:
Revert r1377509
Modified:
tomcat/trunk/java/org/apache/jasper/compiler/JspConfig.java
tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
tomcat/trunk/java/org/apache/jasper/compiler/WebXml.java
Modified: tomcat/trunk/java/org/apache/jasper/compiler/JspConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JspConfig.java?rev=1377540&r1=1377539&r2=1377540&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/JspConfig.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/JspConfig.java Sun Aug 26
22:50:13 2012
@@ -17,14 +17,14 @@
package org.apache.jasper.compiler;
-import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletContext;
-import javax.servlet.descriptor.JspConfigDescriptor;
-import javax.servlet.descriptor.JspPropertyGroupDescriptor;
+import org.apache.jasper.JasperException;
+import org.apache.jasper.xmlparser.ParserUtils;
+import org.apache.jasper.xmlparser.TreeNode;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
@@ -59,105 +59,171 @@ public class JspConfig {
this.ctxt = ctxt;
}
- private void processWebDotXml() {
-
- // Very, very unlikely but just in case...
- if (ctxt.getMajorVersion() < 2) {
- defaultIsELIgnored = "true";
- defaultDeferedSyntaxAllowedAsLiteral = "true";
- return;
+ private double getVersion(TreeNode webApp) {
+ String v = webApp.findAttribute("version");
+ if (v != null) {
+ try {
+ return Double.parseDouble(v);
+ } catch (NumberFormatException e) {
+ }
}
- if (ctxt.getMajorVersion() == 2) {
- if (ctxt.getMinorVersion() < 5) {
- defaultDeferedSyntaxAllowedAsLiteral = "true";
+ return 2.3;
+ }
+
+ private void processWebDotXml() throws JasperException {
+
+ WebXml webXml = null;
+
+ try {
+ webXml = new WebXml(ctxt);
+
+ TreeNode webApp = null;
+ if (webXml.getInputSource() != null) {
+ ParserUtils pu = new ParserUtils();
+ webApp = pu.parseXMLDocument(webXml.getSystemId(),
+ webXml.getInputSource());
}
- if (ctxt.getMinorVersion() < 4) {
+
+ if (webApp == null
+ || getVersion(webApp) < 2.4) {
defaultIsELIgnored = "true";
+ defaultDeferedSyntaxAllowedAsLiteral = "true";
+ return;
+ }
+ if (getVersion(webApp) < 2.5) {
+ defaultDeferedSyntaxAllowedAsLiteral = "true";
+ }
+ TreeNode jspConfig = webApp.findChild("jsp-config");
+ if (jspConfig == null) {
return;
}
- }
-
- JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
-
- Collection<JspPropertyGroupDescriptor> jspPropertyGroups =
- jspConfig.getJspPropertyGroups();
- for (JspPropertyGroupDescriptor jspPropertyGroup : jspPropertyGroups) {
+ jspProperties = new Vector<>();
+ Iterator<TreeNode> jspPropertyList =
+ jspConfig.findChildren("jsp-property-group");
+ while (jspPropertyList.hasNext()) {
+
+ TreeNode element = jspPropertyList.next();
+ Iterator<TreeNode> list = element.findChildren();
+
+ Vector<String> urlPatterns = new Vector<>();
+ String pageEncoding = null;
+ String scriptingInvalid = null;
+ String elIgnored = null;
+ String isXml = null;
+ Vector<String> includePrelude = new Vector<>();
+ Vector<String> includeCoda = new Vector<>();
+ String deferredSyntaxAllowedAsLiteral = null;
+ String trimDirectiveWhitespaces = null;
+ String defaultContentType = null;
+ String buffer = null;
+ String errorOnUndeclaredNamespace = null;
+
+ while (list.hasNext()) {
+
+ element = list.next();
+ String tname = element.getName();
+
+ if ("url-pattern".equals(tname))
+ urlPatterns.addElement( element.getBody() );
+ else if ("page-encoding".equals(tname))
+ pageEncoding = element.getBody();
+ else if ("is-xml".equals(tname))
+ isXml = element.getBody();
+ else if ("el-ignored".equals(tname))
+ elIgnored = element.getBody();
+ else if ("scripting-invalid".equals(tname))
+ scriptingInvalid = element.getBody();
+ else if ("include-prelude".equals(tname))
+ includePrelude.addElement(element.getBody());
+ else if ("include-coda".equals(tname))
+ includeCoda.addElement(element.getBody());
+ else if
("deferred-syntax-allowed-as-literal".equals(tname))
+ deferredSyntaxAllowedAsLiteral = element.getBody();
+ else if ("trim-directive-whitespaces".equals(tname))
+ trimDirectiveWhitespaces = element.getBody();
+ else if ("default-content-type".equals(tname))
+ defaultContentType = element.getBody();
+ else if ("buffer".equals(tname))
+ buffer = element.getBody();
+ else if ("error-on-undeclared-namespace".equals(tname))
+ errorOnUndeclaredNamespace = element.getBody();
+ }
- Collection<String> urlPatterns = jspPropertyGroup.getUrlPatterns();
+ if (urlPatterns.size() == 0) {
+ continue;
+ }
- if (urlPatterns.size() == 0) {
- continue;
- }
-
- // Add one JspPropertyGroup for each URL Pattern. This makes
- // the matching logic easier.
- for (String urlPattern : urlPatterns) {
- String path = null;
- String extension = null;
-
- if (urlPattern.indexOf('*') < 0) {
- // Exact match
- path = urlPattern;
- } else {
- int i = urlPattern.lastIndexOf('/');
- String file;
- if (i >= 0) {
- path = urlPattern.substring(0,i+1);
- file = urlPattern.substring(i+1);
+ // Add one JspPropertyGroup for each URL Pattern. This makes
+ // the matching logic easier.
+ for( int p = 0; p < urlPatterns.size(); p++ ) {
+ String urlPattern = urlPatterns.elementAt( p );
+ String path = null;
+ String extension = null;
+
+ if (urlPattern.indexOf('*') < 0) {
+ // Exact match
+ path = urlPattern;
} else {
- file = urlPattern;
- }
+ int i = urlPattern.lastIndexOf('/');
+ String file;
+ if (i >= 0) {
+ path = urlPattern.substring(0,i+1);
+ file = urlPattern.substring(i+1);
+ } else {
+ file = urlPattern;
+ }
- // pattern must be "*", or of the form "*.jsp"
- if (file.equals("*")) {
- extension = "*";
- } else if (file.startsWith("*.")) {
- extension = file.substring(file.indexOf('.')+1);
- }
+ // pattern must be "*", or of the form "*.jsp"
+ if (file.equals("*")) {
+ extension = "*";
+ } else if (file.startsWith("*.")) {
+ extension = file.substring(file.indexOf('.')+1);
+ }
- // The url patterns are reconstructed as the following:
- // path != null, extension == null: / or /foo/bar.ext
- // path == null, extension != null: *.ext
- // path != null, extension == "*": /foo/*
- boolean isStar = "*".equals(extension);
- if ((path == null && (extension == null || isStar))
- || (path != null && !isStar)) {
- if (log.isWarnEnabled()) {
- log.warn(Localizer.getMessage(
- "jsp.warning.bad.urlpattern.propertygroup",
- urlPattern));
+ // The url patterns are reconstructed as the following:
+ // path != null, extension == null: / or /foo/bar.ext
+ // path == null, extension != null: *.ext
+ // path != null, extension == "*": /foo/*
+ boolean isStar = "*".equals(extension);
+ if ((path == null && (extension == null || isStar))
+ || (path != null && !isStar)) {
+ if (log.isWarnEnabled()) {
+ log.warn(Localizer.getMessage(
+
"jsp.warning.bad.urlpattern.propertygroup",
+ urlPattern));
+ }
+ continue;
}
- continue;
}
- }
-
- Vector<String> includePreludes = new Vector<>();
- includePreludes.addAll(jspPropertyGroup.getIncludePreludes());
- Vector<String> includeCodas = new Vector<>();
- includeCodas.addAll(jspPropertyGroup.getIncludeCodas());
+ JspProperty property = new JspProperty(isXml,
+ elIgnored,
+ scriptingInvalid,
+ pageEncoding,
+ includePrelude,
+ includeCoda,
+ deferredSyntaxAllowedAsLiteral,
+ trimDirectiveWhitespaces,
+ defaultContentType,
+ buffer,
+ errorOnUndeclaredNamespace);
+ JspPropertyGroup propertyGroup =
+ new JspPropertyGroup(path, extension, property);
- JspProperty property = new
JspProperty(jspPropertyGroup.getIsXml(),
- jspPropertyGroup.getElIgnored(),
- jspPropertyGroup.getScriptingInvalid(),
- jspPropertyGroup.getPageEncoding(),
- includePreludes,
- includeCodas,
- jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral(),
- jspPropertyGroup.getTrimDirectiveWhitespaces(),
- jspPropertyGroup.getDefaultContentType(),
- jspPropertyGroup.getBuffer(),
- jspPropertyGroup.getErrorOnUndeclaredNamespace());
- JspPropertyGroup propertyGroup =
- new JspPropertyGroup(path, extension, property);
-
- jspProperties.addElement(propertyGroup);
+ jspProperties.addElement(propertyGroup);
+ }
+ }
+ } catch (Exception ex) {
+ throw new JasperException(ex);
+ } finally {
+ if (webXml != null) {
+ webXml.close();
}
}
}
- private void init() {
+ private void init() throws JasperException {
if (!initialized) {
synchronized (this) {
@@ -220,7 +286,7 @@ public class JspConfig {
* @param uri the resource supplied.
* @return a JspProperty indicating the best match, or some default.
*/
- public JspProperty findJspProperty(String uri) {
+ public JspProperty findJspProperty(String uri) throws JasperException {
init();
@@ -383,7 +449,7 @@ public class JspConfig {
* To find out if an uri matches an url pattern in jsp config. If so,
* then the uri is a JSP page. This is used primarily for jspc.
*/
- public boolean isJspPage(String uri) {
+ public boolean isJspPage(String uri) throws JasperException {
init();
if (jspProperties == null) {
Modified: tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=1377540&r1=1377539&r2=1377540&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
(original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java Sun Aug
26 22:50:13 2012
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
@@ -30,8 +29,6 @@ import java.util.Set;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
-import javax.servlet.descriptor.JspConfigDescriptor;
-import javax.servlet.descriptor.TaglibDescriptor;
import org.apache.jasper.Constants;
import org.apache.jasper.JasperException;
@@ -153,10 +150,10 @@ public class TldLocationsCache {
* [0] The location
* [1] If the location is a jar file, this is the location of the tld.
*/
- private final Hashtable<String, TldLocation> mappings;
+ private Hashtable<String, TldLocation> mappings;
private volatile boolean initialized;
- private final ServletContext ctxt;
+ private ServletContext ctxt;
/** Constructor.
*
@@ -165,7 +162,7 @@ public class TldLocationsCache {
*/
public TldLocationsCache(ServletContext ctxt) {
this.ctxt = ctxt;
- mappings = new Hashtable<>();
+ mappings = new Hashtable<String, TldLocation>();
initialized = false;
}
@@ -275,34 +272,60 @@ public class TldLocationsCache {
/*
* Populates taglib map described in web.xml.
*
- * This is not kept in sync with o.a.c.startup.TldConfig as a) Jasper only
- * needs the URI to TLD mappings and b) Jasper can obtain the information
- * from the ServletContext.
+ * This is not kept in sync with o.a.c.startup.TldConfig as the Jasper only
+ * needs the URI to TLD mappings from scan web.xml whereas TldConfig needs
+ * to scan the actual TLD files.
*/
private void tldScanWebXml() throws Exception {
- JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
-
- Collection<TaglibDescriptor> taglibs = jspConfig.getTaglibs();
-
- for (TaglibDescriptor taglib : taglibs) {
-
- String tagUri = taglib.getTaglibURI();
- String tagLoc = taglib.getTaglibLocation();
+ WebXml webXml = null;
+ try {
+ webXml = new WebXml(ctxt);
+ if (webXml.getInputSource() == null) {
+ return;
+ }
+
+ // Parse the web application deployment descriptor
+ TreeNode webtld = null;
+ webtld = new ParserUtils().parseXMLDocument(webXml.getSystemId(),
+ webXml.getInputSource());
+
+ // Allow taglib to be an element of the root or jsp-config (JSP2.0)
+ TreeNode jspConfig = webtld.findChild("jsp-config");
+ if (jspConfig != null) {
+ webtld = jspConfig;
+ }
+ Iterator<TreeNode> taglibs = webtld.findChildren("taglib");
+ while (taglibs.hasNext()) {
+
+ // Parse the next <taglib> element
+ TreeNode taglib = taglibs.next();
+ String tagUri = null;
+ String tagLoc = null;
+ TreeNode child = taglib.findChild("taglib-uri");
+ if (child != null)
+ tagUri = child.getBody();
+ child = taglib.findChild("taglib-location");
+ if (child != null)
+ tagLoc = child.getBody();
- // Save this location if appropriate
- if (tagLoc == null)
- continue;
- if (uriType(tagLoc) == NOROOT_REL_URI)
- tagLoc = "/WEB-INF/" + tagLoc;
- TldLocation location;
- if (tagLoc.endsWith(JAR_EXT)) {
- location = new TldLocation("META-INF/taglib.tld",
- ctxt.getResource(tagLoc).toString());
- } else {
- location = new TldLocation(tagLoc);
+ // Save this location if appropriate
+ if (tagLoc == null)
+ continue;
+ if (uriType(tagLoc) == NOROOT_REL_URI)
+ tagLoc = "/WEB-INF/" + tagLoc;
+ TldLocation location;
+ if (tagLoc.endsWith(JAR_EXT)) {
+ location = new TldLocation("META-INF/taglib.tld",
ctxt.getResource(tagLoc).toString());
+ } else {
+ location = new TldLocation(tagLoc);
+ }
+ mappings.put(tagUri, location);
+ }
+ } finally {
+ if (webXml != null) {
+ webXml.close();
}
- mappings.put(tagUri, location);
}
}
Modified: tomcat/trunk/java/org/apache/jasper/compiler/WebXml.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/WebXml.java?rev=1377540&r1=1377539&r2=1377540&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/WebXml.java Sun Aug 26
22:50:13 2012
@@ -39,10 +39,7 @@ import org.xml.sax.InputSource;
* annotations with the main web.xml
*
* Clients *must* ensure that they call {@link #close()} to clean up resources.
- *
- * @deprecated Unused - will be removed in Tomcat 8.0.x
*/
-@Deprecated
public class WebXml {
private static final String FILE_PROTOCOL = "file:";
private static final String WEB_XML = "/WEB-INF/web.xml";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]