use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.
the class AbstractBundlePersistenceManager method load.
/**
* {@inheritDoc}
*
* Loads the state via the appropriate NodePropBundle.
*/
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
NodePropBundle bundle = getBundle(id.getParentId());
if (bundle != null) {
PropertyState state = createNew(id);
PropertyEntry p = bundle.getPropertyEntry(id.getName());
if (p != null) {
state.setMultiValued(p.isMultiValued());
state.setType(p.getType());
state.setValues(p.getValues());
state.setModCount(p.getModCount());
} else if (id.getName().equals(JCR_UUID)) {
state.setType(PropertyType.STRING);
state.setMultiValued(false);
state.setValues(new InternalValue[] { InternalValue.create(id.getParentId().toString()) });
} else if (id.getName().equals(JCR_PRIMARYTYPE)) {
state.setType(PropertyType.NAME);
state.setMultiValued(false);
state.setValues(new InternalValue[] { InternalValue.create(bundle.getNodeTypeName()) });
} else if (id.getName().equals(JCR_MIXINTYPES)) {
state.setType(PropertyType.NAME);
state.setMultiValued(true);
Set<Name> mixins = bundle.getMixinTypeNames();
state.setValues(InternalValue.create(mixins.toArray(new Name[mixins.size()])));
} else {
throw new NoSuchItemStateException(id.toString());
}
return state;
} else {
throw new NoSuchItemStateException(id.toString());
}
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.
the class BundleBindingRandomizedTest method randomBundle.
private static NodePropBundle randomBundle(Random r) {
NodeId id = randomNodeId(r);
NodePropBundle bundle = new NodePropBundle(id);
bundle.setModCount((short) randomSize(r));
if (r.nextInt(10) > 0) {
bundle.setParentId(randomNodeId(r));
}
if (r.nextInt(100) > 0) {
bundle.setNodeTypeName(randomName(r));
}
if (r.nextInt(100) > 0) {
bundle.setMixinTypeNames(randomNameSet(r));
}
if (r.nextInt(10) > 0) {
bundle.setReferenceable(r.nextBoolean());
}
if (r.nextInt(10) > 0) {
bundle.setSharedSet(randomNodeIdSet(r));
}
int count = randomSize(r);
for (int i = 0; i < count; i++) {
PropertyEntry p = randomProperty(id, r);
bundle.addProperty(p);
}
count = randomSize(r);
for (int i = 0; i < count; i++) {
bundle.addChildNodeEntry(randomName(r), randomNodeId(r));
}
return bundle;
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.
the class BundleBindingRandomizedTest method randomProperty.
private static PropertyEntry randomProperty(NodeId nodeId, Random r) {
PropertyEntry p = new PropertyEntry(new PropertyId(nodeId, randomName(r)));
int type = PropertyType.STRING;
if (r.nextInt(10) == 0) {
type = r.nextInt() + 15;
}
p.setType(type);
p.setModCount((short) randomSize(r));
boolean multiValued = r.nextBoolean();
p.setMultiValued(multiValued);
int size;
if (multiValued && r.nextInt(10) > 0) {
size = 1;
} else {
size = randomSize(r);
}
InternalValue[] values = new InternalValue[size];
for (int i = 0; i < size; i++) {
values[i] = randomValue(r);
}
p.setValues(values);
return p;
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry in project jackrabbit by apache.
the class BundleBindingTest method testCorruptedBundle.
/**
* creates a future date that is illegal in v3 using v2, and checks that the
* error is being hadled gracefully
*
* JCR-3083 Degrade gracefully when reading invalid date values
*/
public void testCorruptedBundle() throws Exception {
// Bundle as described by the BundleDumper:
// version: 1
// nodeTypeName: #13:#49
// parentUUID: f22c788c-ab98-47cf-95ab-6c495239807a
// definitionId: 1705077083
// mixins: -
// property: #1:#509
// modcount: 1
// type: Date
// definitionId: 806470580
// value: string: 20112022-11-11T19:00:00.000+01:00
// referenceable: false
// childId: 08026c9f-a88a-471b-bcc3-fca2bd82000b #1:linked_products
// modCount: 3
//
// corrupted value: Date -> 20112022-11-11T19:00:00.000+01:00
byte[] corrupted = new byte[] { 1, 0, 0, 13, 0, 0, 0, 49, 1, -14, 44, 120, -116, -85, -104, 71, -49, -107, -85, 108, 73, 82, 57, -128, 122, 0, 10, 49, 55, 48, 53, 48, 55, 55, 48, 56, 51, -1, -1, -1, -1, 0, 0, 0, 1, 0, 0, 1, -3, 0, 1, 0, 5, 0, 0, 9, 56, 48, 54, 52, 55, 48, 53, 56, 48, 0, 0, 0, 1, 0, 0, 0, 33, 50, 48, 49, 49, 50, 48, 50, 50, 45, 49, 49, 45, 49, 49, 84, 49, 57, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 43, 48, 49, 58, 48, 48, -1, -1, -1, -1, 0, 1, 8, 2, 108, -97, -88, -118, 71, 27, -68, -61, -4, -94, -67, -126, 0, 11, 0, 0, 0, 1, 0, 15, 108, 105, 110, 107, 101, 100, 95, 112, 114, 111, 100, 117, 99, 116, 115, 0, 3, 0, 0, 0, 0, 70, -53, 75, -124 };
NodePropBundle result = binding.readBundle(new ByteArrayInputStream(corrupted), NodeId.randomId());
Iterator<PropertyEntry> iterator = result.getPropertyEntries().iterator();
PropertyEntry pe = iterator.next();
InternalValue iv = pe.getValues()[0];
assertEquals(PropertyType.DATE, pe.getType());
assertEquals(PropertyType.DATE, iv.getType());
assertEquals("20112022-11-11T19:00:00.000+01:00", iv.getString());
try {
iv.getDate();
fail("should not be able to read the property as a DATE");
} catch (Exception e) {
// expected
}
}
Aggregations