use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class NodeIndexer method getValue.
/**
* Utility method that extracts the first value of the named property
* of the current node. Returns <code>null</code> if the property does
* not exist or contains no values.
*
* @param name property name
* @return value of the named property, or <code>null</code>
* @throws ItemStateException if the property can not be accessed
*/
protected InternalValue getValue(Name name) throws ItemStateException {
try {
PropertyId id = new PropertyId(node.getNodeId(), name);
PropertyState property = (PropertyState) stateProvider.getItemState(id);
InternalValue[] values = property.getValues();
if (values.length > 0) {
return values[0];
} else {
return null;
}
} catch (NoSuchItemStateException e) {
return null;
}
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class NodeImpl method isCheckedOut.
//------------------------------< versioning support: public Node methods >
/**
* {@inheritDoc}
*/
public boolean isCheckedOut() throws RepositoryException {
// check state of this instance
sanityCheck();
// otherwise it would had been impossible to add it in the first place
if (isNew()) {
return true;
}
// this would have a negative impact on performance though...
try {
NodeState state = getNodeState();
while (!state.hasPropertyName(JCR_ISCHECKEDOUT)) {
ItemId parentId = state.getParentId();
if (parentId == null) {
// root reached or out of hierarchy
return true;
}
state = (NodeState) sessionContext.getItemStateManager().getItemState(parentId);
}
PropertyId id = new PropertyId(state.getNodeId(), JCR_ISCHECKEDOUT);
PropertyState ps = (PropertyState) sessionContext.getItemStateManager().getItemState(id);
InternalValue[] values = ps.getValues();
if (values == null || values.length != 1) {
// in which case it's probably not mix:versionable
return true;
}
return values[0].getBoolean();
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class NodeTypeReader method getPropDef.
/**
* Returns the property definition specified by the current element.
*
* @return property definition
* @throws InvalidNodeTypeDefException if the definition is invalid
* @throws NameException if the definition contains an
* illegal name
* @throws NamespaceException if a namespace is not defined
*/
private QPropertyDefinitionBuilder getPropDef() throws InvalidNodeTypeDefException, NameException, NamespaceException {
QPropertyDefinitionBuilder def = new QPropertyDefinitionBuilder();
String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
if (name.equals("*")) {
def.setName(NameConstants.ANY_NAME);
} else {
def.setName(resolver.getQName(name));
}
// simple attributes
def.setAutoCreated(Boolean.valueOf(walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE)));
def.setMandatory(Boolean.valueOf(walker.getAttribute(Constants.MANDATORY_ATTRIBUTE)));
def.setProtected(Boolean.valueOf(walker.getAttribute(Constants.PROTECTED_ATTRIBUTE)));
def.setOnParentVersion(OnParentVersionAction.valueFromName(walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
def.setMultiple(Boolean.valueOf(walker.getAttribute(Constants.MULTIPLE_ATTRIBUTE)));
def.setFullTextSearchable(Boolean.valueOf(walker.getAttribute(Constants.ISFULLTEXTSEARCHABLE_ATTRIBUTE)));
def.setQueryOrderable(Boolean.valueOf(walker.getAttribute(Constants.ISQUERYORDERABLE_ATTRIBUTE)));
String s = walker.getAttribute(Constants.AVAILABLEQUERYOPERATORS_ATTRIBUTE);
if (s != null && s.length() > 0) {
String[] ops = s.split(" ");
List<String> queryOps = new ArrayList<String>();
for (String op1 : ops) {
String op = op1.trim();
if (op.equals(Constants.EQ_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
} else if (op.equals(Constants.NE_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO);
} else if (op.equals(Constants.LT_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN);
} else if (op.equals(Constants.LE_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
} else if (op.equals(Constants.GT_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN);
} else if (op.equals(Constants.GE_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
} else if (op.equals(Constants.LIKE_ENTITY)) {
queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LIKE);
} else {
throw new InvalidNodeTypeDefException("'" + op + "' is not a valid query operator");
}
}
def.setAvailableQueryOperators(queryOps.toArray(new String[queryOps.size()]));
}
def.setRequiredType(PropertyType.valueFromName(walker.getAttribute(Constants.REQUIREDTYPE_ATTRIBUTE)));
// value constraints
if (walker.enterElement(Constants.VALUECONSTRAINTS_ELEMENT)) {
List<QValueConstraint> constraints = new ArrayList<QValueConstraint>();
int type = def.getRequiredType();
while (walker.iterateElements(Constants.VALUECONSTRAINT_ELEMENT)) {
String constraint = walker.getContent();
try {
constraints.add(ValueConstraint.create(type, constraint.trim(), resolver));
} catch (InvalidConstraintException e) {
throw new InvalidNodeTypeDefException("Invalid value constraint " + constraint, e);
}
}
def.setValueConstraints(constraints.toArray(new QValueConstraint[constraints.size()]));
walker.leaveElement();
}
// default values
if (walker.enterElement(Constants.DEFAULTVALUES_ELEMENT)) {
List<InternalValue> values = new ArrayList<InternalValue>();
int type = def.getRequiredType();
if (type == PropertyType.UNDEFINED) {
type = PropertyType.STRING;
}
while (walker.iterateElements(Constants.DEFAULTVALUE_ELEMENT)) {
String value = walker.getContent();
try {
Value v = ValueHelper.convert(value, type, valueFactory);
values.add((InternalValue) ValueFormat.getQValue(v, resolver, qValueFactory));
} catch (RepositoryException e) {
throw new InvalidNodeTypeDefException("Unable to create default value: " + value, e);
}
}
def.setDefaultValues(values.toArray(new InternalValue[values.size()]));
walker.leaveElement();
}
return def;
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class NodeTypeImpl method canSetProperty.
/**
* {@inheritDoc}
*/
public boolean canSetProperty(String propertyName, Value value) {
if (value == null) {
// setting a property to null is equivalent of removing it
return canRemoveItem(propertyName);
}
try {
Name name = resolver.getQName(propertyName);
QPropertyDefinition def;
try {
// try to get definition that matches the given value type
def = ent.getApplicablePropertyDef(name, value.getType(), false);
} catch (ConstraintViolationException cve) {
// fallback: ignore type
def = ent.getApplicablePropertyDef(name, PropertyType.UNDEFINED, false);
}
if (def.isProtected()) {
return false;
}
if (def.isMultiple()) {
return false;
}
int targetType;
if (def.getRequiredType() != PropertyType.UNDEFINED && def.getRequiredType() != value.getType()) {
// type conversion required
targetType = def.getRequiredType();
} else {
// no type conversion required
targetType = value.getType();
}
// perform type conversion as necessary and create InternalValue
// from (converted) Value
InternalValue internalValue;
if (targetType != value.getType()) {
// type conversion required
Value targetVal = ValueHelper.convert(value, targetType, valueFactory);
internalValue = InternalValue.create(targetVal, resolver, store);
} else {
// no type conversion required
internalValue = InternalValue.create(value, resolver, store);
}
EffectiveNodeType.checkSetPropertyValueConstraints(def, new InternalValue[] { internalValue });
return true;
} catch (NameException be) {
// implementation specific exception, fall through
} catch (RepositoryException re) {
// fall through
}
return false;
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class XMLPersistenceManager method destroy.
/**
* {@inheritDoc}
*/
protected void destroy(PropertyState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
// delete binary values (stored as files)
InternalValue[] values = state.getValues();
if (values != null) {
for (int i = 0; i < values.length; i++) {
InternalValue val = values[i];
if (val != null) {
val.deleteBinaryResource();
}
}
}
// delete property file
String propFilePath = buildPropFilePath(state.getPropertyId());
FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
try {
if (propFile.exists()) {
// delete resource and prune empty parent folders
propFile.delete(true);
}
} catch (FileSystemException fse) {
String msg = "failed to delete property state: " + state.getParentId() + "/" + state.getName();
log.debug(msg);
throw new ItemStateException(msg, fse);
}
}
Aggregations