Skip to content

Commit 6f9a38e

Browse files
committed
Remove TldLocation
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1541539 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8203302 commit 6f9a38e

8 files changed

Lines changed: 62 additions & 130 deletions

File tree

java/org/apache/jasper/JspCompilationContext.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.jasper;
1918

2019
import java.io.File;
@@ -37,11 +36,11 @@
3736
import org.apache.jasper.compiler.JspUtil;
3837
import org.apache.jasper.compiler.Localizer;
3938
import org.apache.jasper.compiler.ServletWriter;
40-
import org.apache.jasper.compiler.TldLocation;
4139
import org.apache.jasper.servlet.JasperLoader;
4240
import org.apache.jasper.servlet.JspServletWrapper;
4341
import org.apache.juli.logging.Log;
4442
import org.apache.juli.logging.LogFactory;
43+
import org.apache.tomcat.util.descriptor.tld.TldResourcePath;
4544
import org.apache.tomcat.util.scan.Jar;
4645

4746
/**
@@ -558,10 +557,8 @@ public void setWriter(ServletWriter writer) {
558557
* Returns null if the given uri is not associated with any tag library
559558
* 'exposed' in the web application.
560559
*/
561-
public TldLocation getTldLocation(String uri) {
562-
TldLocation location =
563-
getOptions().getTldCache().getLocation(uri);
564-
return location;
560+
public TldResourcePath getTldResourcePath(String uri) {
561+
return getOptions().getTldCache().getTldResourcePath(uri);
565562
}
566563

567564
/**

java/org/apache/jasper/compiler/JspDocumentParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.apache.jasper.JasperException;
3333
import org.apache.jasper.JspCompilationContext;
34+
import org.apache.tomcat.util.descriptor.tld.TldResourcePath;
3435
import org.apache.tomcat.util.scan.Jar;
3536
import org.xml.sax.Attributes;
3637
import org.xml.sax.InputSource;
@@ -1267,8 +1268,8 @@ private TagLibraryInfo getTaglibInfo(String prefix, String uri)
12671268
isPlainUri = true;
12681269
}
12691270

1270-
TldLocation location = ctxt.getTldLocation(uri);
1271-
if (location != null || !isPlainUri) {
1271+
TldResourcePath tldResourcePath = ctxt.getTldResourcePath(uri);
1272+
if (tldResourcePath != null || !isPlainUri) {
12721273
if (ctxt.getOptions().isCaching()) {
12731274
result = ctxt.getOptions().getCache().get(uri);
12741275
}
@@ -1286,7 +1287,7 @@ private TagLibraryInfo getTaglibInfo(String prefix, String uri)
12861287
pageInfo,
12871288
prefix,
12881289
uri,
1289-
location,
1290+
tldResourcePath,
12901291
err,
12911292
null);
12921293
if (ctxt.getOptions().isCaching()) {

java/org/apache/jasper/compiler/Parser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.jasper.JasperException;
3030
import org.apache.jasper.JspCompilationContext;
3131
import org.apache.jasper.util.UniqueAttributesImpl;
32+
import org.apache.tomcat.util.descriptor.tld.TldResourcePath;
3233
import org.apache.tomcat.util.scan.Jar;
3334
import org.xml.sax.Attributes;
3435
import org.xml.sax.helpers.AttributesImpl;
@@ -406,9 +407,9 @@ private void parseTaglibDirective(Node parent) throws JasperException {
406407
.getCache().get(uri);
407408
}
408409
if (impl == null) {
409-
TldLocation location = ctxt.getTldLocation(uri);
410+
TldResourcePath tldResourcePath = ctxt.getTldResourcePath(uri);
410411
impl = new TagLibraryInfoImpl(ctxt, parserController,
411-
pageInfo, prefix, uri, location, err,
412+
pageInfo, prefix, uri, tldResourcePath, err,
412413
reader.mark());
413414
if (ctxt.getOptions().isCaching()) {
414415
ctxt.getOptions().getCache().put(uri, impl);

java/org/apache/jasper/compiler/TagFileProcessor.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.jasper.JspCompilationContext;
3838
import org.apache.jasper.runtime.JspSourceDependent;
3939
import org.apache.jasper.servlet.JspServletWrapper;
40+
import org.apache.tomcat.util.descriptor.tld.TldResourcePath;
4041
import org.apache.tomcat.util.scan.Jar;
4142

4243
/**
@@ -517,8 +518,12 @@ private Class<?> loadTagFile(Compiler compiler, String tagFilePath,
517518

518519
Jar tagJar = null;
519520
if (tagFilePath.startsWith("/META-INF/")) {
520-
tagJar = compiler.getCompilationContext().getTldLocation(
521-
tagInfo.getTagLibrary().getURI()).getJar();
521+
try {
522+
tagJar = compiler.getCompilationContext().getTldResourcePath(
523+
tagInfo.getTagLibrary().getURI()).getJar();
524+
} catch (IOException ioe) {
525+
throw new JasperException(ioe);
526+
}
522527
}
523528
String wrapperUri;
524529
if (tagJar == null) {
@@ -622,15 +627,20 @@ public void visit(Node.CustomTag n) throws JasperException {
622627
String tagFilePath = tagFileInfo.getPath();
623628
if (tagFilePath.startsWith("/META-INF/")) {
624629
// For tags in JARs, add the TLD and the tag as a dependency
625-
TldLocation location =
626-
compiler.getCompilationContext().getTldLocation(
630+
TldResourcePath tldResourcePath =
631+
compiler.getCompilationContext().getTldResourcePath(
627632
tagFileInfo.getTagInfo().getTagLibrary().getURI());
628-
Jar jar = location.getJar();
633+
Jar jar;
634+
try {
635+
jar = tldResourcePath.getJar();
636+
} catch (IOException ioe) {
637+
throw new JasperException(ioe);
638+
}
629639
if (jar != null) {
630640
try {
631641
// Add TLD
632-
pageInfo.addDependant(jar.getURL(location.getName()),
633-
Long.valueOf(jar.getLastModified(location.getName())));
642+
pageInfo.addDependant(jar.getURL(tldResourcePath.getEntryName()),
643+
Long.valueOf(jar.getLastModified(tldResourcePath.getEntryName())));
634644
// Add Tag
635645
pageInfo.addDependant(jar.getURL(tagFilePath.substring(1)),
636646
Long.valueOf(jar.getLastModified(tagFilePath.substring(1))));

java/org/apache/jasper/compiler/TagLibraryInfoImpl.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.jasper.compiler;
1918

2019
import java.io.File;
@@ -53,6 +52,7 @@
5352
import org.apache.jasper.xmlparser.TreeNode;
5453
import org.apache.juli.logging.Log;
5554
import org.apache.juli.logging.LogFactory;
55+
import org.apache.tomcat.util.descriptor.tld.TldResourcePath;
5656
import org.apache.tomcat.util.scan.Jar;
5757

5858
/**
@@ -147,8 +147,8 @@ private InputStream getResourceAsStream(String uriAsString)
147147
* Constructor.
148148
*/
149149
public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc,
150-
PageInfo pi, String prefix, String uriIn, TldLocation location,
151-
ErrorDispatcher err, Mark mark)
150+
PageInfo pi, String prefix, String uriIn,
151+
TldResourcePath tldResourcePath, ErrorDispatcher err, Mark mark)
152152
throws JasperException {
153153
super(prefix, uriIn);
154154

@@ -158,17 +158,21 @@ public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc,
158158
this.err = err;
159159
InputStream in = null;
160160

161-
if (location == null) {
161+
if (tldResourcePath == null) {
162162
// The URI points to the TLD itself or to a JAR file in which the
163163
// TLD is stored
164-
location = generateTLDLocation(uri, ctxt);
164+
tldResourcePath = generateTldResourcePath(uri, ctxt);
165165
}
166166

167-
String tldName = location.getName();
168-
Jar jar = location.getJar();
167+
Jar jar;
168+
try {
169+
jar = tldResourcePath.getJar();
170+
} catch (IOException ioe) {
171+
throw new JasperException(ioe);
172+
}
169173
try {
170174
if (jar == null) {
171-
// Location points directly to TLD file
175+
String tldName = tldResourcePath.getWebappPath();
172176
try {
173177
in = getResourceAsStream(tldName);
174178
if (in == null) {
@@ -187,6 +191,7 @@ public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc,
187191
}
188192
} else {
189193
// Tag library is packaged in JAR file
194+
String tldName = tldResourcePath.getEntryName();
190195
String uriExternal = jar.getJarFileURL().toExternalForm();
191196
try {
192197
in = jar.getInputStream(tldName);
@@ -313,8 +318,8 @@ else if ("tag-file".equals(tname)) {
313318
*
314319
* @return the location of the TLD identified by the uri
315320
*/
316-
private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
317-
throws JasperException {
321+
private TldResourcePath generateTldResourcePath(String uri,
322+
JspCompilationContext ctxt) throws JasperException {
318323

319324
// TODO: this matches the current implementation but the URL logic looks fishy
320325
// map URI to location per JSP 7.3.6.2
@@ -326,24 +331,20 @@ private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
326331
uri = ctxt.resolveRelativeUri(uri);
327332
}
328333

334+
URL url = null;
335+
try {
336+
url = ctxt.getResource(uri);
337+
} catch (Exception ex) {
338+
err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
339+
.toString());
340+
}
329341
if (uri.endsWith(".jar")) {
330-
URL url = null;
331-
try {
332-
url = ctxt.getResource(uri);
333-
} catch (Exception ex) {
334-
err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
335-
.toString());
336-
}
337342
if (url == null) {
338343
err.jspError("jsp.error.tld.missing_jar", uri);
339344
}
340-
try {
341-
return new TldLocation("META-INF/taglib.tld", url);
342-
} catch (IOException ioe) {
343-
throw new JasperException(ioe);
344-
}
345+
return new TldResourcePath(url, uri, "META-INF/taglib.tld");
345346
} else {
346-
return new TldLocation(uri);
347+
return new TldResourcePath(url, uri);
347348
}
348349
}
349350

java/org/apache/jasper/compiler/TldCache.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.apache.jasper.compiler;
1818

19-
import java.io.IOException;
20-
import java.net.URL;
2119
import java.util.HashMap;
2220
import java.util.Map;
2321

@@ -57,29 +55,7 @@ public TldCache(Map<String, TldResourcePath> uriTldResourcePathMap,
5755
}
5856

5957

60-
/**
61-
* This method is a temporary bridge between the old TLD handling code and
62-
* the new. It will be removed shortly, hopefully in the next wave of
63-
* refactoring.
64-
*/
65-
@Deprecated
66-
public TldLocation getLocation(String uri) {
67-
TldResourcePath tldResourcePath = uriTldResourcePathMap.get(uri);
68-
if (tldResourcePath == null) {
69-
return null;
70-
}
71-
URL url = tldResourcePath.getUrl();
72-
String entryName = tldResourcePath.getEntryName();
73-
TldLocation tldLocation;
74-
if (entryName == null) {
75-
tldLocation = new TldLocation(url.toExternalForm());
76-
} else {
77-
try {
78-
tldLocation = new TldLocation(entryName, url);
79-
} catch (IOException ioe) {
80-
throw new IllegalArgumentException(ioe);
81-
}
82-
}
83-
return tldLocation;
58+
public TldResourcePath getTldResourcePath(String uri) {
59+
return uriTldResourcePathMap.get(uri);
8460
}
8561
}

java/org/apache/jasper/compiler/TldLocation.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.URL;
2222
import java.util.Objects;
2323

24+
import org.apache.tomcat.util.scan.Jar;
2425
import org.apache.tomcat.util.scan.JarFactory;
2526

2627
/**
@@ -126,6 +127,14 @@ public InputStream openStream() throws IOException {
126127
}
127128
}
128129

130+
public Jar getJar() throws IOException {
131+
if (entryName == null) {
132+
return null;
133+
} else {
134+
return JarFactory.newInstance(url);
135+
}
136+
}
137+
129138
@Override
130139
public boolean equals(Object o) {
131140
if (this == o) {

0 commit comments

Comments
 (0)