use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class DocumentNodeStoreHelper method loadValue.
private static void loadValue(String v, java.util.Collection<Blob> blobs, DocumentNodeStore nodeStore) {
JsopReader reader = new JsopTokenizer(v);
PropertyState p;
if (reader.matches('[')) {
p = DocumentPropertyState.readArrayProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARIES) {
for (int i = 0; i < p.count(); i++) {
Blob b = p.getValue(Type.BINARY, i);
blobs.add(b);
}
}
} else {
p = DocumentPropertyState.readProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARY) {
Blob b = p.getValue(Type.BINARY);
blobs.add(b);
}
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class ChangeSet method fromString.
public static ChangeSet fromString(String json) {
JsopReader reader = new JsopTokenizer(json);
int maxPathDepth = 0;
Set<String> parentPaths = null;
Set<String> parentNodeNames = null;
Set<String> parentNodeTypes = null;
Set<String> propertyNames = null;
Set<String> allNodeTypes = null;
reader.read('{');
if (!reader.matches('}')) {
do {
String name = reader.readString();
reader.read(':');
if ("maxPathDepth".equals(name)) {
maxPathDepth = Integer.parseInt(reader.read(JsopReader.NUMBER));
} else {
Set<String> data = readArrayAsSet(reader);
if ("parentPaths".equals(name)) {
parentPaths = data;
} else if ("parentNodeNames".equals(name)) {
parentNodeNames = data;
} else if ("parentNodeTypes".equals(name)) {
parentNodeTypes = data;
} else if ("propertyNames".equals(name)) {
propertyNames = data;
} else if ("allNodeTypes".equals(name)) {
allNodeTypes = data;
}
}
} while (reader.matches(','));
reader.read('}');
}
reader.read(JsopReader.END);
return new ChangeSet(maxPathDepth, parentPaths, parentNodeNames, parentNodeTypes, propertyNames, allNodeTypes);
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class LuceneJournalPropertyBuilder method addSerializedProperty.
// ~---------------------------------< deserialize >
@Override
public void addSerializedProperty(@Nullable String json) {
if (json == null || json.isEmpty()) {
return;
}
// TODO Add support for overflow
JsopReader reader = new JsopTokenizer(json);
reader.read('{');
if (!reader.matches('}')) {
do {
String path = reader.readString();
reader.read(':');
reader.read('[');
for (boolean first = true; !reader.matches(']'); first = false) {
if (!first) {
reader.read(',');
}
if (sizeWithinLimits()) {
indexedNodes.put(path, reader.readString());
}
}
} while (reader.matches(','));
reader.read('}');
}
reader.read(JsopReader.END);
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class DocumentMK method parseJsonDiff.
// ------------------------------< internal >--------------------------------
private void parseJsonDiff(Commit commit, String json, String rootPath) {
RevisionVector baseRev = commit.getBaseRevision();
String baseRevId = baseRev != null ? baseRev.toString() : null;
Set<String> added = Sets.newHashSet();
JsopReader t = new JsopTokenizer(json);
while (true) {
int r = t.read();
if (r == JsopReader.END) {
break;
}
String path = PathUtils.concat(rootPath, t.readString());
switch(r) {
case '+':
t.read(':');
t.read('{');
parseAddNode(commit, t, path);
added.add(path);
break;
case '-':
DocumentNodeState toRemove = nodeStore.getNode(path, commit.getBaseRevision());
if (toRemove == null) {
throw new DocumentStoreException("Node not found: " + path + " in revision " + baseRevId);
}
commit.removeNode(path, toRemove);
markAsDeleted(toRemove, commit, true);
break;
case '^':
t.read(':');
String value;
if (t.matches(JsopReader.NULL)) {
value = null;
} else {
value = t.readRawValue().trim();
}
String p = PathUtils.getParentPath(path);
if (!added.contains(p) && nodeStore.getNode(p, commit.getBaseRevision()) == null) {
throw new DocumentStoreException("Node not found: " + path + " in revision " + baseRevId);
}
String propertyName = PathUtils.getName(path);
commit.updateProperty(p, propertyName, value);
break;
case '>':
{
t.read(':');
String targetPath = t.readString();
if (!PathUtils.isAbsolute(targetPath)) {
targetPath = PathUtils.concat(rootPath, targetPath);
}
DocumentNodeState source = nodeStore.getNode(path, baseRev);
if (source == null) {
throw new DocumentStoreException("Node not found: " + path + " in revision " + baseRevId);
} else if (nodeExists(targetPath, baseRevId)) {
throw new DocumentStoreException("Node already exists: " + targetPath + " in revision " + baseRevId);
}
moveNode(source, targetPath, commit);
break;
}
case '*':
{
t.read(':');
String targetPath = t.readString();
if (!PathUtils.isAbsolute(targetPath)) {
targetPath = PathUtils.concat(rootPath, targetPath);
}
DocumentNodeState source = nodeStore.getNode(path, baseRev);
if (source == null) {
throw new DocumentStoreException("Node not found: " + path + " in revision " + baseRevId);
} else if (nodeExists(targetPath, baseRevId)) {
throw new DocumentStoreException("Node already exists: " + targetPath + " in revision " + baseRevId);
}
copyNode(source, targetPath, commit);
break;
}
default:
throw new DocumentStoreException("token: " + (char) t.getTokenType());
}
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class ChangeSet method fromString.
public static ChangeSet fromString(String json) {
JsopReader reader = new JsopTokenizer(json);
int maxPathDepth = 0;
Set<String> parentPaths = null;
Set<String> parentNodeNames = null;
Set<String> parentNodeTypes = null;
Set<String> propertyNames = null;
Set<String> allNodeTypes = null;
reader.read('{');
if (!reader.matches('}')) {
do {
String name = reader.readString();
reader.read(':');
if ("maxPathDepth".equals(name)) {
maxPathDepth = Integer.parseInt(reader.read(JsopReader.NUMBER));
} else {
Set<String> data = readArrayAsSet(reader);
if ("parentPaths".equals(name)) {
parentPaths = data;
} else if ("parentNodeNames".equals(name)) {
parentNodeNames = data;
} else if ("parentNodeTypes".equals(name)) {
parentNodeTypes = data;
} else if ("propertyNames".equals(name)) {
propertyNames = data;
} else if ("allNodeTypes".equals(name)) {
allNodeTypes = data;
}
}
} while (reader.matches(','));
reader.read('}');
}
reader.read(JsopReader.END);
return new ChangeSet(maxPathDepth, parentPaths, parentNodeNames, parentNodeTypes, propertyNames, allNodeTypes);
}
Aggregations