use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class XMLPersistenceManager method readState.
private void readState(DOMWalker walker, PropertyState state) throws ItemStateException {
// first do some paranoid sanity checks
if (!walker.getName().equals(PROPERTY_ELEMENT)) {
String msg = "invalid serialization format (unexpected element: " + walker.getName() + ")";
log.debug(msg);
throw new ItemStateException(msg);
}
// check name
if (!state.getName().equals(factory.create(walker.getAttribute(NAME_ATTRIBUTE)))) {
String msg = "invalid serialized state: name mismatch";
log.debug(msg);
throw new ItemStateException(msg);
}
// check parentUUID
NodeId parentId = NodeId.valueOf(walker.getAttribute(PARENTUUID_ATTRIBUTE));
if (!parentId.equals(state.getParentId())) {
String msg = "invalid serialized state: parentUUID mismatch";
log.debug(msg);
throw new ItemStateException(msg);
}
// now we're ready to read state
// type
String typeName = walker.getAttribute(TYPE_ATTRIBUTE);
int type;
try {
type = PropertyType.valueFromName(typeName);
} catch (IllegalArgumentException iae) {
// should never be getting here
throw new ItemStateException("unexpected property-type: " + typeName, iae);
}
state.setType(type);
// multiValued
String multiValued = walker.getAttribute(MULTIVALUED_ATTRIBUTE);
state.setMultiValued(Boolean.parseBoolean(multiValued));
// modification count
String modCount = walker.getAttribute(MODCOUNT_ATTRIBUTE);
state.setModCount(Short.parseShort(modCount));
// values
ArrayList<InternalValue> values = new ArrayList<InternalValue>();
if (walker.enterElement(VALUES_ELEMENT)) {
while (walker.iterateElements(VALUE_ELEMENT)) {
// read serialized value
String content = walker.getContent();
if (PropertyType.STRING == type) {
// STRING value can be empty; ignore length
values.add(InternalValue.valueOf(content, type));
} else if (content.length() > 0) {
// non-empty non-STRING value
if (type == PropertyType.BINARY) {
try {
// in the BLOB store
if (blobStore instanceof ResourceBasedBLOBStore) {
// optimization: if the BLOB store is resource-based
// retrieve the resource directly rather than having
// to read the BLOB from an input stream
FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(content);
values.add(InternalValue.create(fsRes));
} else {
InputStream in = blobStore.get(content);
try {
values.add(InternalValue.create(in));
} finally {
IOUtils.closeQuietly(in);
}
}
} catch (Exception e) {
String msg = "error while reading serialized binary value";
log.debug(msg);
throw new ItemStateException(msg, e);
}
} else {
// non-empty non-STRING non-BINARY value
values.add(InternalValue.valueOf(content, type));
}
} else {
// empty non-STRING value
log.warn(state.getPropertyId() + ": ignoring empty value of type " + PropertyType.nameFromValue(type));
}
}
walker.leaveElement();
}
state.setValues((InternalValue[]) values.toArray(new InternalValue[values.size()]));
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class InternalBaselineImpl method getBaseVersions.
/**
* {@inheritDoc}
*/
public VersionSet getBaseVersions() throws RepositoryException {
InternalValue[] vs = ((InternalFrozenNodeImpl) getFrozenNode()).node.getPropertyValues(NameConstants.REP_VERSIONS);
Map<NodeId, InternalVersion> versions = new HashMap<NodeId, InternalVersion>();
if (vs != null) {
for (InternalValue v : vs) {
InternalVersion iv = vMgr.getVersion(v.getNodeId());
if (iv != null) {
versions.put(iv.getVersionHistory().getId(), iv);
}
}
}
return new VersionSet(versions);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class InternalVersionHistoryImpl method create.
/**
* Creates a new version history below the given parent node and with
* the given name.
*
* @param vMgr version manager
* @param parent parent node
* @param name history name
* @param nodeState node state
* @param copiedFrom the id of the base version
* @return new node state
* @throws RepositoryException if an error occurs
*/
static NodeStateEx create(InternalVersionManagerBase vMgr, NodeStateEx parent, Name name, NodeState nodeState, NodeId copiedFrom) throws RepositoryException {
// create history node
NodeId historyId = vMgr.getNodeIdFactory().newNodeId();
NodeStateEx pNode = parent.addNode(name, NameConstants.NT_VERSIONHISTORY, historyId, true);
// set the versionable uuid
String versionableUUID = nodeState.getNodeId().toString();
pNode.setPropertyValue(NameConstants.JCR_VERSIONABLEUUID, InternalValue.create(versionableUUID));
// create label node
pNode.addNode(NameConstants.JCR_VERSIONLABELS, NameConstants.NT_VERSIONLABELS, null, false);
// initialize the 'jcr:copiedFrom' property
if (copiedFrom != null) {
pNode.setPropertyValue(NameConstants.JCR_COPIEDFROM, InternalValue.create(copiedFrom, true));
}
// create root version
NodeId versionId = vMgr.getNodeIdFactory().newNodeId();
NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION, versionId, true);
// initialize 'created' and 'predecessors'
vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
vNode.setPropertyValues(NameConstants.JCR_SUCCESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
// add also an empty frozen node to the root version
NodeStateEx node = vNode.addNode(NameConstants.JCR_FROZENNODE, NameConstants.NT_FROZENNODE, null, true);
// initialize the internal properties
node.setPropertyValue(NameConstants.JCR_FROZENUUID, InternalValue.create(versionableUUID));
node.setPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE, InternalValue.create(nodeState.getNodeTypeName()));
Set<Name> mixins = nodeState.getMixinTypeNames();
if (!mixins.isEmpty()) {
InternalValue[] ivalues = new InternalValue[mixins.size()];
Iterator<Name> iter = mixins.iterator();
for (int i = 0; i < mixins.size(); i++) {
ivalues[i] = InternalValue.create(iter.next());
}
node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES, PropertyType.NAME, ivalues);
}
parent.store(false);
pNode.store(true);
return pNode;
}
use of org.apache.jackrabbit.core.value.InternalValue 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.value.InternalValue 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