package org.apache.commons.vfs2.provider.zip.test;

import java.io.File;
import java.io.IOException;
import java.net.URI;

import org.apache.commons.vfs2.FileObject;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * This SAX resolver opens VFS objects (FileObject, FileContent, InputStream) but does not close them.
 */
public class TestEntityResolver implements EntityResolver {

    private final FileObject containerFile;
    private final FileObject sourceFile;

    public TestEntityResolver(final FileObject containerFile, FileObject sourceFile) {
        this.containerFile = containerFile;
        this.sourceFile = sourceFile;
    }

    @Override
    public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
        // System.out.println("resolving publicId=" + publicId + ", systemId=" + systemId);
        final String fileName = new File(URI.create(systemId).getPath()).getName();
        if (/* fileName.equals("person.xsd") || */fileName.equals("name.xsd") || fileName.equals("address.xsd")) {
            final String path = "/read-xml-tests/" + fileName;
            final FileObject xsdFileObject = sourceFile.resolveFile(path);
            if (!xsdFileObject.exists()) {
                throw new IllegalStateException(
                        "Schema " + path + " not found in file " + containerFile + " parsing " + sourceFile);
            }
            return new InputSource(xsdFileObject.getContent().getInputStream());
        }
        return null;
    }

}

@@ -1326,24 +1326,102 @@
 xists()) %7B%0D%0A
+                System.err.println(%22File does not exist: %22 + xsdFileObject);%0D%0A
             
@@ -1576,32 +1576,112 @@
 %0A            %7D%0D%0A
+            // System.out.println(%22Opening input stream on %22 + xsdFileObject);%0D%0A
             retu

Add debug helpers.