From d971729e1ec06a473be4b077ecbca0b21cf17520 Mon Sep 17 00:00:00 2001 From: csalter Date: Sun, 20 Nov 2005 00:35:29 +0000 Subject: [113537] bug fixes to make physical resolution occur at the right places (where streams are opened) --- .../wst/dtd/core/internal/saxparser/DTDParser.java | 32 ++++++++++++---------- .../dtd/core/internal/validation/Validator.java | 23 ++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/bundles/org.eclipse.wst.dtd.core/saxparser/org/eclipse/wst/dtd/core/internal/saxparser/DTDParser.java b/bundles/org.eclipse.wst.dtd.core/saxparser/org/eclipse/wst/dtd/core/internal/saxparser/DTDParser.java index fee3129bfa..7d02d85ef2 100644 --- a/bundles/org.eclipse.wst.dtd.core/saxparser/org/eclipse/wst/dtd/core/internal/saxparser/DTDParser.java +++ b/bundles/org.eclipse.wst.dtd.core/saxparser/org/eclipse/wst/dtd/core/internal/saxparser/DTDParser.java @@ -25,6 +25,7 @@ import javax.xml.parsers.SAXParserFactory; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; +import org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.ErrorHandler; @@ -110,18 +111,20 @@ public class DTDParser extends DefaultHandler implements ContentHandler, DTDHand } /* Prints the output from the SAX callbacks. */ - public void parse(String uri) { - try { - boolean isReadable = URIHelper.isReadableURI(uri, true); + public void parse(String logicalURI) { + try { + // CS ensure that the physical URI is considered where streams are required + // and the logicalURI is used as the DTD's baseLocation + String physicalURI = URIResolverPlugin.createResolver().resolvePhysicalLocation("", "", logicalURI); + boolean isReadable = URIHelper.isReadableURI(physicalURI, true); if (!isReadable) { - throw new Exception("DTD parse error. Can not read the specified URI : " + uri); //$NON-NLS-1$ - } - - String document = ""; //$NON-NLS-1$ //$NON-NLS-2$ + throw new Exception("DTD parse error. Can not read the specified URI : " + logicalURI); //$NON-NLS-1$ + } + String document = ""; //$NON-NLS-1$ //$NON-NLS-2$ entityDepth = 0; - currentDTD = new DTD(uri); + currentDTD = new DTD(logicalURI); InputSource inputSource = new InputSource(new StringReader(document)); - inputSource.setSystemId(uri + ".xml"); //$NON-NLS-1$ + inputSource.setSystemId(logicalURI + ".xml"); //$NON-NLS-1$ reader.parse(inputSource); } catch (SAXParseException se) { @@ -654,11 +657,12 @@ public class DTDParser extends DefaultHandler implements ContentHandler, DTDHand public InputSource resolveEntity(String publicId, String systemId) throws SAXException { InputSource result = null; URIResolver idResolver = URIResolverPlugin.createResolver(); - String uri = idResolver.resolve(currentDTD.getName(), publicId, systemId); - if(uri == null){ - uri = systemId; - } - result = new InputSource(uri); + String logicalURI = idResolver.resolve(currentDTD.getName(), publicId, systemId); + // bug 113537, ensure physical resolution gets done here + // right before we attempt to open a stream + String physicalURI = idResolver.resolvePhysicalLocation(currentDTD.getName(), publicId, logicalURI); + result = new InputSource(logicalURI); + result.setByteStream(new LazyURLInputStream(physicalURI)); return result; } diff --git a/bundles/org.eclipse.wst.dtd.core/src-validation/org/eclipse/wst/dtd/core/internal/validation/Validator.java b/bundles/org.eclipse.wst.dtd.core/src-validation/org/eclipse/wst/dtd/core/internal/validation/Validator.java index 51fea6d9b7..289b46c96f 100644 --- a/bundles/org.eclipse.wst.dtd.core/src-validation/org/eclipse/wst/dtd/core/internal/validation/Validator.java +++ b/bundles/org.eclipse.wst.dtd.core/src-validation/org/eclipse/wst/dtd/core/internal/validation/Validator.java @@ -13,19 +13,20 @@ package org.eclipse.wst.dtd.core.internal.validation; import java.io.IOException; import java.io.StringReader; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; import java.util.StringTokenizer; + import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; + import org.eclipse.osgi.util.NLS; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; +import org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream; import org.eclipse.wst.xml.core.internal.validation.core.ValidationInfo; import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; import org.xml.sax.ContentHandler; @@ -95,18 +96,12 @@ public class Validator { InputSource is = null; if (location != null && !location.equals("")) //$NON-NLS-1$ { - try { - String physical = fURIResolver.resolvePhysicalLocation(fBaseLocation, publicId, location); - URL url = new URL(physical); - is = new InputSource(location); - is.setByteStream(url.openStream()); - } - catch (MalformedURLException e) { - throw new IOException(e.getMessage()); - } - catch (Exception e) - { - } + // CS : while working on bug 113537 I noticed we're not using the LazyURLInputStream + // so fixed this to avoid leaking file handles + // + String physical = fURIResolver.resolvePhysicalLocation(fBaseLocation, publicId, location); + is = new InputSource(location); + is.setByteStream(new LazyURLInputStream(physical)); } return is; } -- cgit v1.2.3