Search in sources :

Example 1 with LazyURLInputStream

use of org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream in project webtools.sourceediting by eclipse.

the class DTDParser method resolveEntity.

public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
    InputSource result = null;
    URIResolver idResolver = URIResolverPlugin.createResolver();
    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);
    if (// $NON-NLS-1$
    !(physicalURI == null || physicalURI.equals("") || URIHelper.hasProtocol(physicalURI))) {
        // $NON-NLS-1$
        physicalURI = "file:///" + physicalURI;
    }
    result.setByteStream(new LazyURLInputStream(physicalURI));
    return result;
}
Also used : InputSource(org.xml.sax.InputSource) LazyURLInputStream(org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)

Example 2 with LazyURLInputStream

use of org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream in project webtools.sourceediting by eclipse.

the class XMLValidator method _internalResolveEntity.

public static XMLInputSource _internalResolveEntity(URIResolver uriResolver, XMLResourceIdentifier rid, NestedValidatorContext context) throws IOException {
    XMLInputSource is = null;
    if (uriResolver != null) {
        String id = rid.getPublicId();
        if (id == null) {
            id = rid.getNamespace();
        }
        String location = null;
        if (id != null || rid.getLiteralSystemId() != null) {
            location = uriResolver.resolve(rid.getBaseSystemId(), id, rid.getLiteralSystemId());
        }
        if (location != null) {
            String physical = uriResolver.resolvePhysicalLocation(rid.getBaseSystemId(), id, location);
            // if physical is already a known bad uri, just go ahead and throw an exception
            if (context instanceof XMLNestedValidatorContext) {
                XMLNestedValidatorContext xmlContext = ((XMLNestedValidatorContext) context);
                if (xmlContext.isURIMarkedInaccessible(physical)) {
                    throw new FileNotFoundException(physical);
                }
            }
            is = new XMLInputSource(rid.getPublicId(), location, location);
            // This block checks that the file exists. If it doesn't we need to throw
            // an exception so Xerces will report an error. note: This may not be
            // necessary with all versions of Xerces but has specifically been
            // experienced with the version included in IBM's 1.4.2 JDK.
            InputStream isTemp = null;
            try {
                isTemp = new URL(physical).openStream();
            } catch (IOException e) {
                // physical was a bad url, so cache it so we know next time
                if (context instanceof XMLNestedValidatorContext) {
                    XMLNestedValidatorContext xmlContext = ((XMLNestedValidatorContext) context);
                    xmlContext.markURIInaccessible(physical);
                }
                throw e;
            } finally {
                if (isTemp != null) {
                    isTemp.close();
                }
            }
            is.setByteStream(new LazyURLInputStream(physical));
        }
    }
    return is;
}
Also used : LazyURLInputStream(org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) LazyURLInputStream(org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

LazyURLInputStream (org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 XMLInputSource (org.apache.xerces.xni.parser.XMLInputSource)1 URIResolver (org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)1 InputSource (org.xml.sax.InputSource)1