luehe 2004/02/26 17:03:56 Modified: jasper2/src/share/org/apache/jasper/compiler TldLocationsCache.java JspConfig.java Log: Close input stream Revision Changes Path 1.24 +47 -37 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TldLocationsCache.java Index: TldLocationsCache.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TldLocationsCache.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- TldLocationsCache.java 4 Feb 2004 20:01:13 -0000 1.23 +++ TldLocationsCache.java 27 Feb 2004 01:03:55 -0000 1.24 @@ -293,49 +293,59 @@ */ private void processWebDotXml() throws Exception { - // Acquire an input stream to the web application deployment descriptor - InputStream is = ctxt.getResourceAsStream(WEB_XML); - if (is == null) { - if (log.isWarnEnabled()) { - log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", - WEB_XML)); + InputStream is = null; + + try { + // Acquire input stream to web application deployment descriptor + is = ctxt.getResourceAsStream(WEB_XML); + if (is == null) { + if (log.isWarnEnabled()) { + log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", + WEB_XML)); + } + return; } - return; - } - // Parse the web application deployment descriptor - TreeNode webtld = new ParserUtils().parseXMLDocument(WEB_XML, is); + // Parse the web application deployment descriptor + TreeNode webtld = new ParserUtils().parseXMLDocument(WEB_XML, is); - // 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 taglibs = webtld.findChildren("taglib"); - while (taglibs.hasNext()) { + // 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 taglibs = webtld.findChildren("taglib"); + while (taglibs.hasNext()) { - // Parse the next <taglib> element - TreeNode taglib = (TreeNode) 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(); + // Parse the next <taglib> element + TreeNode taglib = (TreeNode) 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; - String tagLoc2 = null; - if (tagLoc.endsWith(JAR_FILE_SUFFIX)) { - tagLoc = ctxt.getResource(tagLoc).toString(); - tagLoc2 = "META-INF/taglib.tld"; + // Save this location if appropriate + if (tagLoc == null) + continue; + if (uriType(tagLoc) == NOROOT_REL_URI) + tagLoc = "/WEB-INF/" + tagLoc; + String tagLoc2 = null; + if (tagLoc.endsWith(JAR_FILE_SUFFIX)) { + tagLoc = ctxt.getResource(tagLoc).toString(); + tagLoc2 = "META-INF/taglib.tld"; + } + mappings.put(tagUri, new String[] { tagLoc, tagLoc2 }); + } + } finally { + if (is != null) { + try { + is.close(); + } catch (Throwable t) {} } - mappings.put(tagUri, new String[] { tagLoc, tagLoc2 }); } } 1.15 +121 -109 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspConfig.java Index: JspConfig.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspConfig.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- JspConfig.java 27 Jan 2004 01:20:22 -0000 1.14 +++ JspConfig.java 27 Feb 2004 01:03:55 -0000 1.15 @@ -102,117 +102,129 @@ private void processWebDotXml(ServletContext ctxt) throws JasperException { - InputStream is = ctxt.getResourceAsStream(WEB_XML); - if (is == null) { - // no web.xml - return; - } - - ParserUtils pu = new ParserUtils(); - TreeNode webApp = pu.parseXMLDocument(WEB_XML, is); - if (webApp == null || !"2.4".equals(webApp.findAttribute("version"))) { - defaultIsELIgnored = "true"; - return; - } - TreeNode jspConfig = webApp.findChild("jsp-config"); - if (jspConfig == null) { - return; - } - - jspProperties = new Vector(); - Iterator jspPropertyList = jspConfig.findChildren("jsp-property-group"); - while (jspPropertyList.hasNext()) { - - TreeNode element = (TreeNode) jspPropertyList.next(); - Iterator list = element.findChildren(); - - Vector urlPatterns = new Vector(); - String pageEncoding = null; - String scriptingInvalid = null; - String elIgnored = null; - String isXml = null; - Vector includePrelude = new Vector(); - Vector includeCoda = new Vector(); - - while (list.hasNext()) { - - element = (TreeNode) 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()); + InputStream is = null; + + try { + is = ctxt.getResourceAsStream(WEB_XML); + if (is == null) { + // no web.xml + return; } - if (urlPatterns.size() == 0) { - continue; - } - - // Add one JspPropertyGroup for each URL Pattern. This makes - // the matching logic easier. - for( int p = 0; p < urlPatterns.size(); p++ ) { - String urlPattern = (String)urlPatterns.elementAt( p ); - String path = null; - String extension = null; + ParserUtils pu = new ParserUtils(); + TreeNode webApp = pu.parseXMLDocument(WEB_XML, is); + if (webApp == null + || !"2.4".equals(webApp.findAttribute("version"))) { + defaultIsELIgnored = "true"; + return; + } + TreeNode jspConfig = webApp.findChild("jsp-config"); + if (jspConfig == null) { + return; + } + + jspProperties = new Vector(); + Iterator jspPropertyList = jspConfig.findChildren("jsp-property-group"); + while (jspPropertyList.hasNext()) { + + TreeNode element = (TreeNode) jspPropertyList.next(); + Iterator list = element.findChildren(); + + Vector urlPatterns = new Vector(); + String pageEncoding = null; + String scriptingInvalid = null; + String elIgnored = null; + String isXml = null; + Vector includePrelude = new Vector(); + Vector includeCoda = new Vector(); + + while (list.hasNext()) { + + element = (TreeNode) 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()); + } + + if (urlPatterns.size() == 0) { + continue; + } - 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 { - file = urlPattern; - } + // Add one JspPropertyGroup for each URL Pattern. This makes + // the matching logic easier. + for( int p = 0; p < urlPatterns.size(); p++ ) { + String urlPattern = (String)urlPatterns.elementAt( p ); + String path = null; + String extension = null; - // 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 follwoing: - // 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; - } - } + 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 { + file = urlPattern; + } - JspProperty property = new JspProperty(isXml, - elIgnored, - scriptingInvalid, - pageEncoding, - includePrelude, - includeCoda); - JspPropertyGroup propertyGroup = - new JspPropertyGroup(path, extension, property); - - jspProperties.addElement(propertyGroup); - } - } + // 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 follwoing: + // 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); + JspPropertyGroup propertyGroup = + new JspPropertyGroup(path, extension, property); + + jspProperties.addElement(propertyGroup); + } + } + } finally { + if (is != null) { + try { + is.close(); + } catch (Throwable t) {} + } + } } private void init() throws JasperException {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]