NodeUrlConnection.java 1.81 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
 *  javax.jcr.Node
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceMetadata
 *  org.apache.sling.api.resource.ResourceResolver
 */
package com.adobe.aemds.datamanager.impl;

import com.adobe.aemds.datamanager.impl.NodeBasedUrlConnection;
import com.adobe.aemds.datamanager.impl.ServiceContainer;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.jcr.Node;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;

class NodeUrlConnection
extends NodeBasedUrlConnection {
    protected Resource resource;

    NodeUrlConnection(URL url, Node node) {
        super(url, node);
    }

    protected Node getNode() throws Exception {
        return this.node;
    }

    protected void doConnect() throws Exception {
        Node n = this.getNode();
        this.resource = ServiceContainer.resourceResolverHelper.getResourceResolver().getResource(n.getPath());
    }

    protected String doGetContentType() throws Exception {
        return this.resource.getResourceMetadata().getContentType();
    }

    protected InputStream doGetInputStream() throws Exception {
        InputStream res = (InputStream)this.resource.adaptTo(InputStream.class);
        if (res == null) {
            throw new IOException("The JCR node at location " + this.url.toExternalForm() + " has no content!");
        }
        return res;
    }

    protected long doGetContentLength() throws Exception {
        return this.resource.getResourceMetadata().getContentLength();
    }
}