1414 * See the License for the specific language governing permissions and
1515 * limitations under the License.
1616 */
17-
1817package org .apache .jasper .compiler ;
1918
2019import java .io .File ;
5352import org .apache .jasper .xmlparser .TreeNode ;
5453import org .apache .juli .logging .Log ;
5554import org .apache .juli .logging .LogFactory ;
55+ import org .apache .tomcat .util .descriptor .tld .TldResourcePath ;
5656import 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
0 commit comments