use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class DocumentNodeState method fromString.
public static DocumentNodeState fromString(DocumentNodeStore store, String s) {
JsopTokenizer json = new JsopTokenizer(s);
String path = null;
RevisionVector rootRev = null;
RevisionVector lastRev = null;
boolean hasChildren = false;
HashMap<String, String> map = new HashMap<String, String>();
while (true) {
String k = json.readString();
json.read(':');
if ("path".equals(k)) {
path = json.readString();
} else if ("rev".equals(k)) {
rootRev = RevisionVector.fromString(json.readString());
} else if ("lastRev".equals(k)) {
lastRev = RevisionVector.fromString(json.readString());
} else if ("hasChildren".equals(k)) {
hasChildren = json.read() == JsopReader.TRUE;
} else if ("prop".equals(k)) {
json.read('{');
while (true) {
if (json.matches('}')) {
break;
}
k = json.readString();
json.read(':');
String v = json.readString();
map.put(k, v);
json.matches(',');
}
}
if (json.matches(JsopReader.END)) {
break;
}
json.read(',');
}
List<PropertyState> props = Lists.newArrayListWithCapacity(map.size());
for (Entry<String, String> e : map.entrySet()) {
String value = e.getValue();
if (value != null) {
props.add(store.createPropertyState(e.getKey(), value));
}
}
return new DocumentNodeState(store, path, rootRev, props, hasChildren, lastRev);
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class DocumentNodeStore method getBinarySize.
/**
* Returns the binary size of a property value represented as a JSON or
* {@code -1} if the property is not of type binary.
*
* @param json the property value.
* @return the size of the referenced binary value(s); otherwise {@code -1}.
*/
private long getBinarySize(@Nullable String json) {
if (json == null) {
return -1;
}
PropertyState p = new DocumentPropertyState(DocumentNodeStore.this, "p", json);
if (p.getType().tag() != PropertyType.BINARY) {
return -1;
}
long size = 0;
if (p.isArray()) {
for (int i = 0; i < p.count(); i++) {
size += p.size(i);
}
} else {
size = p.size();
}
return size;
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class MergingNodeStateDiff method resolveConflict.
//------------------------------------------------------------< private >---
private void resolveConflict(ConflictType conflictType, NodeState conflictInfo) {
PropertyConflictHandler propertyConflictHandler = propertyConflictHandlers.get(conflictType);
if (propertyConflictHandler != null) {
for (PropertyState ours : conflictInfo.getProperties()) {
PropertyState theirs = parent.getProperty(ours.getName());
Resolution resolution = propertyConflictHandler.resolve(ours, theirs);
applyResolution(resolution, conflictType, ours);
}
} else {
NodeConflictHandler nodeConflictHandler = nodeConflictHandlers.get(conflictType);
if (nodeConflictHandler != null) {
for (ChildNodeEntry oursCNE : conflictInfo.getChildNodeEntries()) {
String name = oursCNE.getName();
NodeState ours = oursCNE.getNodeState();
NodeState theirs = parent.getChildNode(name);
Resolution resolution = nodeConflictHandler.resolve(name, ours, theirs);
applyResolution(resolution, conflictType, name, ours);
if (LOG.isDebugEnabled()) {
String diff = JsopDiff.diffToJsop(ours, theirs);
LOG.debug("{} resolved conflict of type {} with resolution {} on node {}, conflict trace {}", nodeConflictHandler, conflictType, resolution, name, diff);
}
}
} else {
LOG.warn("Ignoring unknown conflict '" + conflictType + '\'');
}
}
NodeBuilder conflictMarker = getConflictMarker(conflictType);
if (conflictMarker != null) {
assert conflictMarker.getChildNodeCount(1) == 0;
}
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class MergingNodeStateDiff method removeChild.
private static void removeChild(NodeBuilder target, String name) {
target.getChildNode(name).remove();
PropertyState childOrder = target.getProperty(TreeConstants.OAK_CHILD_ORDER);
if (childOrder != null) {
PropertyBuilder<String> builder = PropertyBuilder.copy(NAME, childOrder);
builder.removeValue(name);
target.setProperty(builder.getPropertyState());
}
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class CacheValidatorProviderTest method testModifyCache.
@Test
public void testModifyCache() throws Exception {
List<PropertyState> props = new ArrayList();
props.add(PropertyStates.createProperty(CacheConstants.REP_EXPIRATION, 25));
props.add(PropertyStates.createProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, EveryonePrincipal.NAME));
props.add(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME));
props.add(PropertyStates.createProperty("residualProp", "anyvalue"));
Tree cache = getCache(getTestUser());
for (PropertyState prop : props) {
try {
cache.setProperty(prop);
root.commit(CacheValidatorProvider.asCommitAttributes());
fail("Modifying rep:cache node below a user or group must fail.");
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
assertEquals(34, e.getCode());
} finally {
root.refresh();
}
}
}
Aggregations