JcrUtil.java 1.85 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
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.jetbrains.annotations.NotNull
 */
package com.adobe.cq.dam.s7imaging.impl.catalog;

import com.scene7.is.util.callbacks.Option;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.jetbrains.annotations.NotNull;

public class JcrUtil {
    private static final String RELATIONS_PATH = "{http://www.jcp.org/jcr/1.0}content/related";

    public static Option<Resource> getResource(ResourceResolver resolver, String path) {
        return Option.some((Object)resolver.getResource(path));
    }

    public static Option<Node> getNode(Node node, String relPath) throws RepositoryException {
        if (node.hasNode(relPath)) {
            return Option.some((Object)node.getNode(relPath));
        }
        return Option.none();
    }

    public static Option<Resource> getChild(Resource resource, String relPath) {
        return Option.some((Object)resource.getChild(relPath));
    }

    @NotNull
    public static <T> Option<T> adaptTo(Class<T> clazz, @NotNull Adaptable instance) {
        return Option.some((Object)instance.adaptTo(clazz));
    }

    @NotNull
    public static <T> T as(@NotNull Class<T> clazz, @NotNull Adaptable instance) {
        Object result = instance.adaptTo(clazz);
        if (result != null) {
            return (T)result;
        }
        throw new IllegalArgumentException((Object)instance + " is not adaptable to " + clazz);
    }

    private JcrUtil() {
    }
}