Return-Path: Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 97195 invoked by uid 500); 4 Jul 2003 13:55:09 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 97184 invoked by uid 500); 4 Jul 2003 13:55:09 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 97180 invoked from network); 4 Jul 2003 13:55:08 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 4 Jul 2003 13:55:08 -0000 Received: (qmail 19281 invoked by uid 1638); 4 Jul 2003 13:55:10 -0000 Date: 4 Jul 2003 13:55:10 -0000 Message-ID: <20030704135510.19280.qmail@icarus.apache.org> From: bruno@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/java/org/apache/cocoon/xml XMLBaseSupport.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bruno 2003/07/04 06:55:10 Modified: src/java/org/apache/cocoon/transformation XIncludeTransformer.java src/java/org/apache/cocoon/xml XMLBaseSupport.java Log: Avoid resolving the same URI twice. Revision Changes Path 1.7 +4 -3 cocoon-2.1/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java Index: XIncludeTransformer.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XIncludeTransformer.java 4 Jul 2003 09:45:17 -0000 1.6 +++ XIncludeTransformer.java 4 Jul 2003 13:55:09 -0000 1.7 @@ -371,7 +371,7 @@ href = this.href; } - url = resolver.resolveURI(xmlBaseSupport.makeAbsolute(href)); + url = xmlBaseSupport.makeAbsolute(href); if (getLogger().isDebugEnabled()) { getLogger().debug("URL: " + url.getURI() + "\nSuffix: " + suffix); } @@ -442,7 +442,8 @@ } catch (SourceException se) { throw SourceUtil.handle(se); } finally { - resolver.release(url); + if (url != null) + resolver.release(url); } } 1.3 +21 -19 cocoon-2.1/src/java/org/apache/cocoon/xml/XMLBaseSupport.java Index: XMLBaseSupport.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/xml/XMLBaseSupport.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XMLBaseSupport.java 7 Jun 2003 21:16:10 -0000 1.2 +++ XMLBaseSupport.java 4 Jul 2003 13:55:10 -0000 1.3 @@ -101,7 +101,15 @@ level++; String base = attrs.getValue(XMLBASE_NAMESPACE_URI, XMLBASE_ATTRIBUTE); if (base != null) { - String baseUrl = resolve(getCurrentBase(), base); + Source baseSource = null; + String baseUrl; + try { + baseSource = resolve(getCurrentBase(), base); + baseUrl = baseSource.getURI(); + } finally { + if (baseSource != null) + resolver.release(baseSource); + } bases.push(new BaseInfo(baseUrl, level)); } } @@ -112,37 +120,31 @@ level--; } - private String resolve(String baseURI, String location) throws SAXException { + /** + * Warning: do not forget to release the source returned by this method. + */ + private Source resolve(String baseURI, String location) throws SAXException { try { - String url; + Source source; if (baseURI != null) { - Source source = resolver.resolveURI(location, baseURI, Collections.EMPTY_MAP); - try { - url = source.getURI(); - } finally { - resolver.release(source); - } + source = resolver.resolveURI(location, baseURI, Collections.EMPTY_MAP); } else { - Source source = resolver.resolveURI(location); - try { - url = source.getURI(); - } finally { - resolver.release(source); - } + source = resolver.resolveURI(location); } if (logger.isDebugEnabled()) - logger.debug("XMLBaseSupport: resolved location " + location + " against base URI " + baseURI + " to " + url); - return url; + logger.debug("XMLBaseSupport: resolved location " + location + " against base URI " + baseURI + " to " + source.getURI()); + return source; } catch (IOException e) { throw new SAXException("XMLBaseSupport: problem resolving uri.", e); } } /** - * Makes the given path absolute based on the current base URL. + * Makes the given path absolute based on the current base URL. Do not forget to release + * the returned source object! * @param spec any URL (relative or absolute, containing a scheme or not) */ - public String makeAbsolute(String spec) throws SAXException { + public Source makeAbsolute(String spec) throws SAXException { return resolve(getCurrentBase(), spec); }