Values.java 1.55 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  javax.jcr.Value
 *  javax.jcr.nodetype.NodeType
 */
package com.day.crx.explorer.impl.util;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.nodetype.NodeType;

public class Values {
    public static final Value[] EMPTY_VALUES = new Value[0];

    public static String[] getNames(NodeType[] nodeTypes) {
        String[] ret = new String[nodeTypes.length];
        for (int i = 0; i < nodeTypes.length; ++i) {
            ret[i] = nodeTypes[i].getName();
        }
        return ret;
    }

    public static String getProperty(Node node, String name, String def) throws RepositoryException {
        return node != null && node.hasProperty(name) ? node.getProperty(name).getString() : def;
    }

    public static String[] getProperty(Node node, String name, String[] def) throws RepositoryException {
        if (node == null || !node.hasProperty(name)) {
            return def;
        }
        Value[] values = node.getProperty(name).getValues();
        String[] ret = new String[values.length];
        for (int i = 0; i < ret.length; ++i) {
            ret[i] = values[i].getString();
        }
        return ret;
    }

    public static boolean getProperty(Node node, String name, boolean def) throws RepositoryException {
        return node != null && node.hasProperty(name) ? node.getProperty(name).getBoolean() : def;
    }
}