You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/08/26 22:29:27 UTC
svn commit: r1377511 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/jasper/compiler/JspConfig.java
java/org/apache/jasper/compiler/TldLocationsCache.java
java/org/apache/jasper/compiler/WebXml.java webapps/docs/changelog.xml
Author: markt
Date: Sun Aug 26 20:29:27 2012
New Revision: 1377511
URL: http://svn.apache.org/viewvc?rev=1377511&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53737
Access JSP configuration information via the ServletContext rather than re-parsing web.xml
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1377509
Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java?rev=1377511&r1=1377510&r2=1377511&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java Sun Aug 26 20:29:27 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,171 +59,105 @@ public class JspConfig {
this.ctxt = ctxt;
}
- private double getVersion(TreeNode webApp) {
- String v = webApp.findAttribute("version");
- if (v != null) {
- try {
- return Double.parseDouble(v);
- } catch (NumberFormatException e) {
- }
- }
- 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());
- }
+ private void processWebDotXml() {
- if (webApp == null
- || getVersion(webApp) < 2.4) {
- defaultIsELIgnored = "true";
- defaultDeferedSyntaxAllowedAsLiteral = "true";
- return;
- }
- if (getVersion(webApp) < 2.5) {
+ // Very, very unlikely but just in case...
+ if (ctxt.getMajorVersion() < 2) {
+ defaultIsELIgnored = "true";
+ defaultDeferedSyntaxAllowedAsLiteral = "true";
+ return;
+ }
+ if (ctxt.getMajorVersion() == 2) {
+ if (ctxt.getMinorVersion() < 5) {
defaultDeferedSyntaxAllowedAsLiteral = "true";
}
- TreeNode jspConfig = webApp.findChild("jsp-config");
- if (jspConfig == null) {
+ if (ctxt.getMinorVersion() < 4) {
+ defaultIsELIgnored = "true";
return;
}
+ }
- jspProperties = new Vector<JspPropertyGroup>();
- 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>();
- String pageEncoding = null;
- String scriptingInvalid = null;
- String elIgnored = null;
- String isXml = null;
- Vector<String> includePrelude = new Vector<String>();
- Vector<String> includeCoda = new Vector<String>();
- 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();
- }
+ JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
- if (urlPatterns.size() == 0) {
- continue;
- }
+ Collection<JspPropertyGroupDescriptor> jspPropertyGroups =
+ jspConfig.getJspPropertyGroups();
+
+ for (JspPropertyGroupDescriptor jspPropertyGroup : jspPropertyGroups) {
- // 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;
+ Collection<String> urlPatterns = jspPropertyGroup.getUrlPatterns();
+
+ 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);
} else {
- int i = urlPattern.lastIndexOf('/');
- String file;
- if (i >= 0) {
- path = urlPattern.substring(0,i+1);
- file = urlPattern.substring(i+1);
- } else {
- file = urlPattern;
- }
+ 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));
- }
- continue;
+ // 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;
}
+ }
- JspProperty property = new JspProperty(isXml,
- elIgnored,
- scriptingInvalid,
- pageEncoding,
- includePrelude,
- includeCoda,
- deferredSyntaxAllowedAsLiteral,
- trimDirectiveWhitespaces,
- defaultContentType,
- buffer,
- errorOnUndeclaredNamespace);
- JspPropertyGroup propertyGroup =
- new JspPropertyGroup(path, extension, property);
+ Vector<String> includePreludes = new Vector<String>();
+ includePreludes.addAll(jspPropertyGroup.getIncludePreludes());
- jspProperties.addElement(propertyGroup);
- }
- }
- } catch (Exception ex) {
- throw new JasperException(ex);
- } finally {
- if (webXml != null) {
- webXml.close();
+ Vector<String> includeCodas = new Vector<String>();
+ includeCodas.addAll(jspPropertyGroup.getIncludeCodas());
+
+ 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);
}
}
}
- private void init() throws JasperException {
+ private void init() {
if (!initialized) {
synchronized (this) {
@@ -285,7 +219,7 @@ public class JspConfig {
* @param uri the resource supplied.
* @return a JspProperty indicating the best match, or some default.
*/
- public JspProperty findJspProperty(String uri) throws JasperException {
+ public JspProperty findJspProperty(String uri) {
init();
@@ -448,7 +382,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) throws JasperException {
+ public boolean isJspPage(String uri) {
init();
if (jspProperties == null) {
Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=1377511&r1=1377510&r2=1377511&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java Sun Aug 26 20:29:27 2012
@@ -22,6 +22,7 @@ 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;
@@ -29,6 +30,8 @@ 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;
@@ -151,10 +154,10 @@ public class TldLocationsCache {
* [0] The location
* [1] If the location is a jar file, this is the location of the tld.
*/
- private Hashtable<String, TldLocation> mappings;
+ private final Hashtable<String, TldLocation> mappings;
private volatile boolean initialized;
- private ServletContext ctxt;
+ private final ServletContext ctxt;
/** Constructor.
*
@@ -273,60 +276,34 @@ public class TldLocationsCache {
/*
* Populates taglib map described in web.xml.
*
- * 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.
+ * 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.
*/
private void tldScanWebXml() throws Exception {
- 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();
+ JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
- // 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();
+ Collection<TaglibDescriptor> taglibs = jspConfig.getTaglibs();
+
+ for (TaglibDescriptor taglib : taglibs) {
+
+ String tagUri = taglib.getTaglibURI();
+ String tagLoc = taglib.getTaglibLocation();
+
+ // 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);
}
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java?rev=1377511&r1=1377510&r2=1377511&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java Sun Aug 26 20:29:27 2012
@@ -39,7 +39,10 @@ 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";
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=1377511&r1=1377510&r2=1377511&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sun Aug 26 20:29:27 2012
@@ -198,6 +198,10 @@
<bug>53654</bug>: Support <code>file://</code> URLs for JSP
dependencies. Patch provided by Viola Lu. (markt)
</fix>
+ <fix>
+ <bug>53737</bug>: Access JSP configuration information from web.xml via
+ the <code>ServletContext</code> rather than re-parsing web.xml. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1377511 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/jasper/compiler/JspConfig.java
java/org/apache/jasper/compiler/TldLocationsCache.java java/org/apache/jasper/compiler/WebXml.java
webapps/docs/changelog.xml
Posted by Mark Thomas <ma...@apache.org>.
On 26/08/2012 22:23, Mark Thomas wrote:
> On 26/08/2012 22:16, Konstantin Kolinko wrote:
>> 2012/8/27 <ma...@apache.org>:
>>> Author: markt
>>> Date: Sun Aug 26 20:29:27 2012
>>> New Revision: 1377511
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1377511&view=rev
>>> Log:
>>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53737
>>> Access JSP configuration information via the ServletContext rather than re-parsing web.xml
>>>
>>> Modified:
>>> tomcat/tc7.0.x/trunk/ (props changed)
>>> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
>>> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
>>> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java
>>> tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>>>
>>
>> I have not tested yet, but there are two things that I wonder
>> regarding this change
>>
>> 1) Is JspC still working?
>>
>> It uses JspCServletContext which implementation of
>> #getJspConfigDescriptor() always returns null.
>
> I haven't tested that. On the face of it, this change may need to be
> reverted / modified.
I don't see a quick way around this problem and I'd rather get 7.0.30
out. I'll revert this change in 7.0.x and trunk.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1377511 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/jasper/compiler/JspConfig.java
java/org/apache/jasper/compiler/TldLocationsCache.java java/org/apache/jasper/compiler/WebXml.java
webapps/docs/changelog.xml
Posted by Mark Thomas <ma...@apache.org>.
On 26/08/2012 22:16, Konstantin Kolinko wrote:
> 2012/8/27 <ma...@apache.org>:
>> Author: markt
>> Date: Sun Aug 26 20:29:27 2012
>> New Revision: 1377511
>>
>> URL: http://svn.apache.org/viewvc?rev=1377511&view=rev
>> Log:
>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53737
>> Access JSP configuration information via the ServletContext rather than re-parsing web.xml
>>
>> Modified:
>> tomcat/tc7.0.x/trunk/ (props changed)
>> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
>> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
>> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java
>> tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>>
>
> I have not tested yet, but there are two things that I wonder
> regarding this change
>
> 1) Is JspC still working?
>
> It uses JspCServletContext which implementation of
> #getJspConfigDescriptor() always returns null.
I haven't tested that. On the face of it, this change may need to be
reverted / modified.
> 2) Can we stop publishing merged web.xml as context attribute (make
> this publishing off by default)?
Potentially, yes.
Mark
>
> org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1377511 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/jasper/compiler/JspConfig.java java/org/apache/jasper/compiler/TldLocationsCache.java
java/org/apache/jasper/compiler/WebXml.java webapps/docs/changelog.xml
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/8/27 <ma...@apache.org>:
> Author: markt
> Date: Sun Aug 26 20:29:27 2012
> New Revision: 1377511
>
> URL: http://svn.apache.org/viewvc?rev=1377511&view=rev
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53737
> Access JSP configuration information via the ServletContext rather than re-parsing web.xml
>
> Modified:
> tomcat/tc7.0.x/trunk/ (props changed)
> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java
> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
> tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/WebXml.java
> tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
>
I have not tested yet, but there are two things that I wonder
regarding this change
1) Is JspC still working?
It uses JspCServletContext which implementation of
#getJspConfigDescriptor() always returns null.
2) Can we stop publishing merged web.xml as context attribute (make
this publishing off by default)?
org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org