Relation.java 1.92 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.callbacks.Option
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 *  org.apache.sling.api.adapter.Adaptable
 */
package com.adobe.cq.dam.s7imaging.impl.jcr.adapters;

import com.adobe.cq.dam.s7imaging.impl.catalog.JcrUtil;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.JcrProps;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropExtractor;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.PropKey;
import com.adobe.cq.dam.s7imaging.impl.jcr.props.StandardExtractors;
import com.scene7.is.util.callbacks.Option;
import java.util.Iterator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.adapter.Adaptable;

public class Relation {
    public final String path;
    public final JcrProps props;
    private static final String SLING_RESOURCE = "sling:resource";
    private static final PropKey<Option<String>> SlingResource = PropKey.optional("sling:resource", StandardExtractors.toString);

    public static Option<Relation> relation(Node node) throws RepositoryException {
        JcrProps props = JcrProps.jcrProps(node);
        Iterator i$ = props.get(SlingResource).iterator();
        if (i$.hasNext()) {
            String path = (String)i$.next();
            return Option.some((Object)new Relation(path, props));
        }
        return Option.none();
    }

    public static Option<Relation> relation(Adaptable node) throws RepositoryException {
        Iterator i$ = JcrUtil.adaptTo(Node.class, node).iterator();
        if (i$.hasNext()) {
            Node n = (Node)i$.next();
            return Relation.relation(n);
        }
        return Option.none();
    }

    public static Relation relation(String path) {
        return new Relation(path, JcrProps.emptyJcrProps());
    }

    private Relation(String path, JcrProps props) {
        this.path = path;
        this.props = props;
    }
}