public Object resolveEntity()

in src/main/java/org/apache/maven/xinclude/LocalXmlResolver.java [41:85]


    public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace)
            throws XMLStreamException {
        if (rootDirectory == null) {
            return null;
        }
        if (systemID == null) {
            throw new XMLStreamException("systemID is null");
        }
        if (baseURI == null) {
            throw new XMLStreamException("baseURI is null");
        }
        URI baseUri;
        try {
            baseUri = new URI(baseURI).normalize();
        } catch (URISyntaxException e) {
            throw new XMLStreamException("Invalid syntax for baseURI URI: " + baseURI, e);
        }
        URI systemIDUri;
        try {
            systemIDUri = new URI(systemID).normalize();
        } catch (URISyntaxException e) {
            throw new XMLStreamException("Invalid syntax for systemID URI: " + systemID, e);
        }
        if (systemIDUri.getScheme() != null) {
            throw new XMLStreamException("systemID must be a relative URI: " + systemID);
        }
        Path base = Paths.get(baseUri).normalize();
        if (!base.startsWith(rootDirectory)) {
            return null;
        }
        Path systemIDPath = Paths.get(systemIDUri.getSchemeSpecificPart()).normalize();
        if (systemIDPath.isAbsolute()) {
            throw new XMLStreamException("systemID must be a relative path: " + systemID);
        }
        Path resourcePath = base.resolveSibling(systemIDPath).normalize();
        if (!resourcePath.startsWith(rootDirectory)) {
            throw new XMLStreamException("systemID cannot refer to a path outside rootDirectory: " + systemID);
        }
        try {
            return new StreamSource(
                    Files.newInputStream(resourcePath), resourcePath.toUri().toASCIIString());
        } catch (IOException e) {
            throw new XMLStreamException("Unable to create Source for " + systemID + ": " + e.getMessage(), e);
        }
    }