Java Code Examples for javax.jcr.PropertyType#UNDEFINED

The following examples show how to use javax.jcr.PropertyType#UNDEFINED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocViewProperty.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new property.
 * @param name name of the property
 * @param values values.
 * @param multi multiple flag
 * @param type type of the property
 * @param isRef {@code true} to indicated that this is a binary reference property
 * @throws IllegalArgumentException if single value property and not exactly 1 value is given.
 */
public DocViewProperty(String name, String[] values, boolean multi, int type, boolean isRef) {
    this.name = name;
    this.values = values;
    isMulti = multi;
    // validate type
    if (type == PropertyType.UNDEFINED) {
        if ("jcr:primaryType".equals(name) || "jcr:mixinTypes".equals(name)) {
            type = PropertyType.NAME;
        }
    }
    this.type = type;
    if (!isMulti && values.length != 1) {
        throw new IllegalArgumentException("Single value property needs exactly 1 value.");
    }
    this.isReferenceProperty = isRef;
}
 
Example 2
Source File: ValueImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
private static int selectPropertyType(Object value) {
    return (value instanceof String) ? PropertyType.STRING :
        (value instanceof Long) ? PropertyType.LONG :
            (value instanceof Double) ? PropertyType.DOUBLE :
                (value instanceof BigDecimal) ? PropertyType.DECIMAL :
                    (value instanceof Calendar) ? PropertyType.DATE :
                        (value instanceof Boolean) ? PropertyType.BOOLEAN :
                            (value instanceof Binary) ? PropertyType.BINARY :
                                PropertyType.UNDEFINED;
}
 
Example 3
Source File: CNDImporter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
private int doPropertyType(Node pdi) throws ParseException, RepositoryException {
    if (!currentTokenEquals(Lexer.BEGIN_TYPE)) {
        return PropertyType.UNDEFINED;
    }
    nextToken();
    int type = PropertyType.UNDEFINED;
    if (currentTokenEquals(Lexer.STRING)) {
        type = PropertyType.STRING;
    } else if (currentTokenEquals(Lexer.BINARY)) {
        type = PropertyType.BINARY;
    } else if (currentTokenEquals(Lexer.LONG)) {
        type = PropertyType.LONG;
    } else if (currentTokenEquals(Lexer.DOUBLE)) {
        type = PropertyType.DOUBLE;
    } else if (currentTokenEquals(Lexer.BOOLEAN)) {
        type = PropertyType.BOOLEAN;
    } else if (currentTokenEquals(Lexer.DATE)) {
        type = PropertyType.DATE;
    } else if (currentTokenEquals(Lexer.NAME)) {
        type = PropertyType.NAME;
    } else if (currentTokenEquals(Lexer.PATH)) {
        type = PropertyType.PATH;
    } else if (currentTokenEquals(Lexer.REFERENCE)) {
        type = PropertyType.REFERENCE;
    } else if (currentTokenEquals(Lexer.UNDEFINED)) {
        type = PropertyType.UNDEFINED;
    } else {
        lexer.fail("Unknown property type '" + currentToken + "' specified");
    }
    pdi.setProperty(JcrConstants.JCR_REQUIREDTYPE, PropertyType.nameFromValue(type).toUpperCase());
    nextToken();
    if (!currentTokenEquals(Lexer.END_TYPE)) {
        lexer.fail("Missing '" + Lexer.END_TYPE + "' delimiter for end of property type");
    }
    nextToken();
    return type;
}
 
Example 4
Source File: PropertyImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public int getType() throws RepositoryException {
    return !isMultiple() ? value.getType() :
        values.length > 0 ? values[0].getType() :
            PropertyType.UNDEFINED;
}
 
Example 5
Source File: DocViewProperty.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * Sets this property on the given node
 *
 * @param node the node
 * @return {@code true} if the value was modified.
 * @throws RepositoryException if a repository error occurs
 */
public boolean apply(Node node) throws RepositoryException {
    Property prop = node.hasProperty(name) ? node.getProperty(name) : null;
    // check if multiple flags are equal
    if (prop != null && isMulti != prop.getDefinition().isMultiple()) {
        prop.remove();
        prop = null;
    }
    if (prop != null) {
        int propType = prop.getType();
        if (propType != type && (propType != PropertyType.STRING || type != PropertyType.UNDEFINED)) {
            // never compare if types differ
            prop = null;
        }
    }
    if (isMulti) {
        // todo: handle multivalue binaries and reference binaries
        Value[] vs = prop == null ? null : prop.getValues();
        if (vs != null && vs.length == values.length) {
            // quick check all values
            boolean modified = false;
            for (int i=0; i<vs.length; i++) {
                if (!vs[i].getString().equals(values[i])) {
                    modified = true;
                }
            }
            if (!modified) {
                return false;
            }
        }
        if (type == PropertyType.UNDEFINED) {
            node.setProperty(name, values);
        } else {
            node.setProperty(name, values, type);
        }
        // assume modified
        return true;
    } else {
        Value v = prop == null ? null : prop.getValue();
        if (type == PropertyType.BINARY) {
            if (isReferenceProperty) {
                ReferenceBinary ref = new SimpleReferenceBinary(values[0]);
                Binary binary = node.getSession().getValueFactory().createValue(ref).getBinary();
                if (v != null) {
                    Binary bin = v.getBinary();
                    if (bin.equals(binary)) {
                        return false;
                    }
                }
                node.setProperty(name, binary);
            }
            // the binary property is always modified (TODO: check if still correct with JCRVLT-110)
            return true;
        }
        if (v == null || !v.getString().equals(values[0])) {
            try {
                if (type == PropertyType.UNDEFINED) {
                    node.setProperty(name, values[0]);
                } else {
                    node.setProperty(name, values[0], type);
                }
            } catch (ValueFormatException e) {
                // forcing string
                node.setProperty(name, values[0], PropertyType.STRING);
            }
            return true;
        }
    }
    return false;
}