JcrResourceProvider.java 1.35 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 */
package com.adobe.granite.ui.clientlibs.impl;

import com.adobe.granite.ui.clientlibs.impl.JcrPropertyResource;
import com.adobe.granite.ui.clientlibs.script.ScriptResource;
import com.adobe.granite.ui.clientlibs.script.ScriptResourceProvider;
import java.io.IOException;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

public class JcrResourceProvider
implements ScriptResourceProvider {
    private final Session session;

    public JcrResourceProvider(Session session) {
        this.session = session;
    }

    @Override
    public ScriptResource getResource(String path) throws IOException {
        try {
            String propPath = path + "/jcr:content/jcr:data";
            if (this.session.propertyExists(propPath)) {
                Property p = this.session.getProperty(propPath);
                return new JcrPropertyResource(p, p.getParent().getParent().getPath());
            }
            return null;
        }
        catch (RepositoryException e) {
            IOException io = new IOException("Unable to read resource at " + path);
            io.initCause((Throwable)e);
            throw io;
        }
    }
}