Search in sources :

Example 6 with JsopReader

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);
}
Also used : JsopReader(org.apache.jackrabbit.oak.commons.json.JsopReader) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer) Test(org.junit.Test)

Example 7 with JsopReader

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;
}
Also used : JsopReader(org.apache.jackrabbit.oak.commons.json.JsopReader) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer)

Example 8 with JsopReader

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;
}
Also used : JsopReader(org.apache.jackrabbit.oak.commons.json.JsopReader) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) JsonDeserializer(org.apache.jackrabbit.oak.json.JsonDeserializer) Base64BlobSerializer(org.apache.jackrabbit.oak.json.Base64BlobSerializer) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer)

Example 9 with JsopReader

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));
        }
    }
}
Also used : ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) JsopReader(org.apache.jackrabbit.oak.commons.json.JsopReader) ReferencedBlob(org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

JsopReader (org.apache.jackrabbit.oak.commons.json.JsopReader)9 JsopTokenizer (org.apache.jackrabbit.oak.commons.json.JsopTokenizer)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 Blob (org.apache.jackrabbit.oak.api.Blob)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 Base64BlobSerializer (org.apache.jackrabbit.oak.json.Base64BlobSerializer)1 JsonDeserializer (org.apache.jackrabbit.oak.json.JsonDeserializer)1 ReferencedBlob (org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 Test (org.junit.Test)1