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); }