use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class JsonSerializerTest method childOrder.
@Test
public void childOrder() throws Exception {
NodeBuilder builder = EMPTY_NODE.builder();
builder.child("a");
builder.child("b");
builder.child("c");
List<String> expectedOrder = Arrays.asList("a", "c", "b");
builder.setProperty(":childOrder", expectedOrder, Type.NAMES);
NodeState state = builder.getNodeState();
String json = serialize(state);
JsopReader reader = new JsopTokenizer(json);
List<String> childNames = Lists.newArrayList();
reader.read('{');
do {
String key = reader.readString();
reader.read(':');
if (reader.matches('{')) {
childNames.add(key);
reader.matches('}');
}
} while (reader.matches(','));
assertEquals(expectedOrder, childNames);
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class JsonDeserializer method deserialize.
public NodeState deserialize(String json) {
JsopReader reader = new JsopTokenizer(json);
reader.read('{');
NodeState state = deserialize(reader);
reader.read(JsopReader.END);
return state;
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class IndexDefinitionUpdater method getIndexDefnStates.
private static Map<String, NodeState> getIndexDefnStates(String json) throws IOException {
Base64BlobSerializer blobHandler = new Base64BlobSerializer();
Map<String, NodeState> indexDefns = Maps.newHashMap();
JsopReader reader = new JsopTokenizer(json);
reader.read('{');
if (!reader.matches('}')) {
do {
String indexPath = reader.readString();
if (!indexPath.startsWith("/")) {
String msg = String.format("Invalid format of index definitions. The key name [%s] should " + "be index path ", indexPath);
throw new IllegalArgumentException(msg);
}
reader.read(':');
if (reader.matches('{')) {
JsonDeserializer deserializer = new JsonDeserializer(blobHandler);
NodeState idxState = deserializer.deserialize(reader);
indexDefns.put(indexPath, idxState);
}
} while (reader.matches(','));
reader.read('}');
}
return indexDefns;
}
use of org.apache.jackrabbit.oak.commons.json.JsopReader in project jackrabbit-oak by apache.
the class BlobCollector method loadValue.
private void loadValue(String v, Collection<ReferencedBlob> blobs, String nodeId) {
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(new ReferencedBlob(b, nodeId));
}
}
} else {
p = DocumentPropertyState.readProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARY) {
Blob b = p.getValue(Type.BINARY);
blobs.add(new ReferencedBlob(b, nodeId));
}
}
}
Aggregations