use of javax.jcr.Property in project jackrabbit by apache.
the class AuthorizableImpl method setProperty.
/**
* Sets the Value for the given name. If a value existed, it is replaced,
* if not it is created.
*
* @param relPath The relative path to the property or the property name.
* @param value The property value.
* @throws RepositoryException If the specified name defines a property
* that needs to be modified by this user API or setting the corresponding
* JCR property fails.
* @see Authorizable#setProperty(String, Value)
*/
public synchronized void setProperty(String relPath, Value value) throws RepositoryException {
String name = Text.getName(relPath);
String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath, 1);
checkProtectedProperty(name);
try {
Node n = getOrCreateTargetNode(intermediate);
// ValueFormatException.
if (n.hasProperty(name)) {
Property p = n.getProperty(name);
if (p.isMultiple()) {
p.remove();
}
}
n.setProperty(name, value);
if (userManager.isAutoSave()) {
node.save();
}
} catch (RepositoryException e) {
log.debug("Failed to set Property " + name + " for " + this, e);
node.refresh(false);
throw e;
}
}
use of javax.jcr.Property in project jackrabbit by apache.
the class AuthorizableImpl method removeProperty.
/**
* @see Authorizable#removeProperty(String)
*/
public synchronized boolean removeProperty(String relPath) throws RepositoryException {
String name = Text.getName(relPath);
checkProtectedProperty(name);
try {
if (node.hasProperty(relPath)) {
Property p = node.getProperty(relPath);
if (isAuthorizableProperty(p, true)) {
p.remove();
if (userManager.isAutoSave()) {
node.save();
}
return true;
}
}
// no such property or wasn't a property of this authorizable.
return false;
} catch (RepositoryException e) {
log.debug("Failed to remove Property " + relPath + " from " + this, e);
node.refresh(false);
throw e;
}
}
use of javax.jcr.Property in project jackrabbit by apache.
the class AuthorizableImpl method setProperty.
/**
* Sets the Value[] for the given name. If a value existed, it is replaced,
* if not it is created.
*
* @param relPath The relative path to the property or the property name.
* @param values The property values.
* @throws RepositoryException If the specified name defines a property
* that needs to be modified by this user API or setting the corresponding
* JCR property fails.
* @see Authorizable#setProperty(String, Value[])
*/
public synchronized void setProperty(String relPath, Value[] values) throws RepositoryException {
String name = Text.getName(relPath);
String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath, 1);
checkProtectedProperty(name);
try {
Node n = getOrCreateTargetNode(intermediate);
// ValueFormatException.
if (n.hasProperty(name)) {
Property p = n.getProperty(name);
if (!p.isMultiple()) {
p.remove();
}
}
n.setProperty(name, values);
if (userManager.isAutoSave()) {
node.save();
}
} catch (RepositoryException e) {
log.debug("Failed to set Property " + name + " for " + this, e);
node.refresh(false);
throw e;
}
}
use of javax.jcr.Property in project jackrabbit by apache.
the class TraversingNodeResolver method getMatchingNode.
/**
*
* @param node
* @param predicate
* @param relPath
* @param value
* @param exact
* @return
* @throws RepositoryException
*/
private static Node getMatchingNode(NodeImpl node, AuthorizableTypePredicate predicate, String relPath, String value, boolean exact) throws RepositoryException {
boolean match = false;
Node authNode = predicate.getAuthorizableNode(node);
if (authNode != null && node.hasProperty(relPath)) {
try {
Property prop = node.getProperty(relPath);
if (prop.isMultiple()) {
Value[] values = prop.getValues();
for (int i = 0; i < values.length && !match; i++) {
match = matches(value, values[i].getString(), exact);
}
} else {
match = matches(value, prop.getString(), exact);
}
} catch (PatternSyntaxException pe) {
log.debug("couldn't search for {}, pattern invalid: {}", value, pe.getMessage());
}
}
return (match) ? authNode : null;
}
use of javax.jcr.Property in project jackrabbit by apache.
the class JcrUtils method toString.
/**
* Returns a string representation of the given item. The returned string
* is designed to be easily readable while providing maximum amount of
* information for logging and debugging purposes.
* <p>
* The returned string is not meant to be parsed and the exact contents
* can change in future releases. The current string representation of
* a node is "/path/to/node [type]" and the representation of a property is
* "@name = value(s)". Binary values are expressed like "<123 bytes>"
* and other values as their standard binary representation. Multi-valued
* properties have their values listed in like "[ v1, v2, v3, ... ]". No
* more than the three first values are included. Long string values are
* truncated.
*
* @param item given node or property
* @return string representation of the given item
*/
public static String toString(Item item) {
StringBuilder builder = new StringBuilder();
try {
if (item.isNode()) {
builder.append(item.getPath());
builder.append(" [");
builder.append(((Node) item).getPrimaryNodeType().getName());
builder.append("]");
} else {
builder.append("@");
builder.append(item.getName());
builder.append(" = ");
Property property = (Property) item;
if (property.isMultiple()) {
builder.append("[ ");
Value[] values = property.getValues();
for (int i = 0; i < values.length && i < 3; i++) {
if (i > 0) {
builder.append(", ");
}
append(builder, values[i]);
}
if (values.length >= 3) {
builder.append(", ...");
}
builder.append(" ]");
} else {
append(builder, property.getValue());
}
}
} catch (RepositoryException e) {
builder.append("!!! ");
builder.append(e.getMessage());
builder.append(" !!!");
}
return builder.toString();
}
Aggregations