}
boolean invalid = true;
// do not use getString because of string consuming
ValueData valueData = value;
if (type == PropertyType.STRING)
{
try
{
String strVal = new String(valueData.getAsByteArray(), Constants.DEFAULT_ENCODING);
for (int i = 0; invalid && i < constraints.length; i++)
{
String constrString = constraints[i];
if (strVal.matches(constrString))
{
invalid = false;
}
}
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException("FATAL ERROR Charset " + Constants.DEFAULT_ENCODING + " is not supported!");
}
catch (IOException e)
{
throw new RepositoryException("FATAL ERROR Value data stream reading error " + e.getMessage(), e);
}
}
else if (type == PropertyType.NAME)
{
NameValue nameVal;
try
{
nameVal = new NameValue(valueData, locator);
}
catch (IOException e)
{
throw new RepositoryException(e);
}
for (int i = 0; invalid && i < constraints.length; i++)
{
String constrString = constraints[i];
InternalQName constrName = locator.parseJCRName(constrString).getInternalName();
if (nameVal.getQName().equals(constrName))
{
invalid = false;
}
}
}
else if (type == PropertyType.PATH)
{
PathValue pathVal;
try
{
pathVal = new PathValue(valueData, locator);
}
catch (IOException e)
{
throw new RepositoryException(e);
}
for (int i = 0; invalid && i < constraints.length; i++)
{
JCRPathMatcher constrPath = parsePathMatcher(locator, constraints[i]);
if (constrPath.match(pathVal.getQPath()))
{
invalid = false;
}
}
}
else if (type == PropertyType.REFERENCE)
{
try
{
ReferenceValue refVal = new ReferenceValue(valueData);
NodeData refNode = (NodeData)itemDataConsumer.getItemData(refVal.getIdentifier().getString());
for (int i = 0; invalid && i < constraints.length; i++)
{
String constrString = constraints[i];
InternalQName constrName = locator.parseJCRName(constrString).getInternalName();
if (nodeTypeDataManager
.isNodeType(constrName, refNode.getPrimaryTypeName(), refNode.getMixinTypeNames()))
{
invalid = false;
}
}
}
catch (ItemNotFoundException e)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Reference constraint node is not found: " + e.getMessage());
}
// But if it's a versionHisroy ref property for add mix:versionable...
// we haven't a versionHisroy created until save method will be called
// on this
// session/item...
// it's transient state here.
invalid = false; // so, value is matched, we hope...
}
catch (RepositoryException e)
{
LOG.error("Reference constraint error: " + e.getMessage(), e);
// [PN] Posible trouble is session.getNodeByUUID() call result,
// till bug can be found in version restore operation.
invalid = true;
}
catch (IOException e)
{
LOG.error("Reference constraint error: " + e.getMessage(), e);
invalid = true;
}
}
else if (type == PropertyType.BINARY)
{
long valueLength = valueData.getLength();
for (int i = 0; invalid && i < constraints.length; i++)
{
String constrString = constraints[i];
boolean minInvalid = true;
boolean maxInvalid = true;
MinMaxConstraint constraint = parseAsMinMax(constrString);
long min =
constraint.getMin().getThreshold().length() > 0 ? new Long(constraint.getMin().getThreshold())
: Long.MIN_VALUE;
if (constraint.getMin().isExclusive())
{
if (valueLength > min)
{
minInvalid = false;
}
}
else
{
if (valueLength >= min)
{
minInvalid = false;
}
}
long max =
constraint.getMax().getThreshold().length() > 0 ? new Long(constraint.getMax().getThreshold())
: Long.MAX_VALUE;
if (constraint.getMax().isExclusive())
{
if (valueLength < max)
maxInvalid = false;
}
else
{
if (valueLength <= max)
maxInvalid = false;
}
invalid = maxInvalid | minInvalid;
}
}
else if (type == PropertyType.DATE)
{
Calendar valueCalendar;
try
{
valueCalendar = new DateValue(valueData).getDate();
}
catch (IOException e)
{
throw new RepositoryException(e);
}
for (int i = 0; invalid && i < constraints.length; i++)
{
boolean minInvalid = true;
boolean maxInvalid = true;
MinMaxConstraint constraint = parseAsMinMax(constraints[i]);
try
{
if (constraint.getMin().getThreshold().length() > 0)
{
Calendar min = JCRDateFormat.parse(constraint.getMin().getThreshold());
if (constraint.getMin().isExclusive())
{
if (valueCalendar.compareTo(min) > 0)
{
minInvalid = false;
}
}
else
{
if (valueCalendar.compareTo(min) >= 0)
{
minInvalid = false;
}
}
}
else
{
minInvalid = false;
}
}
catch (ValueFormatException e)
{
minInvalid = false;
}
try
{
if (constraint.getMax().getThreshold().length() > 0)
{
Calendar max = JCRDateFormat.parse(constraint.getMax().getThreshold());
if (constraint.getMax().isExclusive())
{
if (valueCalendar.compareTo(max) < 0)
maxInvalid = false;
}
else
{
if (valueCalendar.compareTo(max) <= 0)
maxInvalid = false;
}
}
else
{
maxInvalid = false;
}
}
catch (ValueFormatException e)
{
maxInvalid = false;
}
invalid = maxInvalid | minInvalid;
}
}
else if (type == PropertyType.LONG || type == PropertyType.DOUBLE)
{
// will be compared as double in any case
Number valueNumber;
try
{
valueNumber = new DoubleValue(valueData).getDouble();
}
catch (IOException e)
{
throw new RepositoryException(e);
}
for (int i = 0; invalid && i < constraints.length; i++)
{
boolean minInvalid = true;
boolean maxInvalid = true;
MinMaxConstraint constraint = parseAsMinMax(constraints[i]);
Number min =
constraint.getMin().getThreshold().length() > 0 ? new Double(constraint.getMin().getThreshold())
: Double.MIN_VALUE;
if (constraint.getMin().isExclusive())
{
if (valueNumber.doubleValue() > min.doubleValue())
{
minInvalid = false;
}
}
else
{
if (valueNumber.doubleValue() >= min.doubleValue())
{
minInvalid = false;
}
}
Number max =
constraint.getMax().getThreshold().length() > 0 ? new Double(constraint.getMax().getThreshold())
: Double.MAX_VALUE;
if (constraint.getMax().isExclusive())
{
if (valueNumber.doubleValue() < max.doubleValue())
{
maxInvalid = false;
}
}
else
{
if (valueNumber.doubleValue() <= max.doubleValue())
{
maxInvalid = false;
}
}
invalid = maxInvalid | minInvalid;
}
}
else if (type == PropertyType.BOOLEAN)
{
try
{
boolean bvalue = Boolean.parseBoolean(new String(valueData.getAsByteArray()));
for (int i = 0; invalid && i < constraints.length; i++)
{
if (Boolean.parseBoolean(constraints[i]) == bvalue)
{
invalid = false;