XsdEntityResolver.java 2.62 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
 *  javax.jcr.Binary
 *  javax.jcr.Node
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.xsd;

import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class XsdEntityResolver
implements EntityResolver {
    private ResourceResolverHelper resourceResolverHelper;
    private List<String> pathOfChildXSD;
    private Logger logger = LoggerFactory.getLogger(XsdEntityResolver.class);

    public XsdEntityResolver(ResourceResolverHelper resourceResolverHelper) {
        this.resourceResolverHelper = resourceResolverHelper;
    }

    @Override
    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
        InputSource isrc = null;
        ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
        String path = systemId.substring(5) + "/jcr:content";
        Resource slingResource = resolver.resolve(path);
        Node jcrNode = (Node)slingResource.adaptTo(Node.class);
        InputStream is = null;
        try {
            if (!jcrNode.hasProperty("jcr:data")) {
                jcrNode = jcrNode.getNode("renditions/original/jcr:content");
            }
            is = jcrNode.getProperty("jcr:data").getBinary().getStream();
            isrc = new InputSource(is);
            this.pathOfChildXSD = new ArrayList<String>();
            this.addXSDPathToList(path);
            isrc.setSystemId(systemId);
        }
        catch (RepositoryException e) {
            this.logger.error("Unable to access the jcr repository", (Throwable)e);
        }
        return isrc;
    }

    private void addXSDPathToList(String path) {
        this.pathOfChildXSD.add(path);
    }

    public List<String> getListOfAllXSD() {
        return this.pathOfChildXSD;
    }
}