Package org.apache.jackrabbit.mk.json

Examples of org.apache.jackrabbit.mk.json.JsopWriter


            switch (r) {
            case '+':
                t.read(':');
                if (t.matches('{')) {
                    NodeImpl n = NodeImpl.parse(map, t, 0);
                    JsopWriter diff = new JsopBuilder();
                    diff.tag('+').key(path);
                    n.append(diff, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, false);
                    buffer(path, diff);
                } else {
                    String value = t.readRawValue().trim();
                    JsopWriter diff = new JsopBuilder();
                    diff.tag('+').key(path);
                    diff.encodedValue(value);
                    buffer(path, diff);
                }
                break;
            case '-': {
                JsopWriter diff = new JsopBuilder();
                diff.tag('-').value(path);
                buffer(path, diff);
                break;
            }
            case '^':
                t.read(':');
                String value;
                if (t.matches(JsopTokenizer.NULL)) {
                    JsopWriter diff = new JsopBuilder();
                    diff.tag('^').key(path).value(null);
                    buffer(path, diff);
                } else {
                    value = t.readRawValue().trim();
                    JsopWriter diff = new JsopBuilder();
                    diff.tag('^').key(path).encodedValue(value);
                    buffer(path, diff);
                }
                break;
            case '>': {
                t.read(':');
                JsopWriter diff = new JsopBuilder();
                if (t.matches('{')) {
                    String position = t.readString();
                    t.read(':');
                    String to = t.readString();
                    t.read('}');
                    if (!PathUtils.isAbsolute(to)) {
                        to = PathUtils.concat(rootPath, to);
                    }
                    diff.tag('>').key(path);
                    diff.object().key(position);
                    diff.value(to).endObject();
                } else {
                    String to = t.readString();
                    if (!PathUtils.isAbsolute(to)) {
                        to = PathUtils.concat(rootPath, to);
                    }
                    diff.tag('>').key(path);
                    diff.value(to);
                }
                buffer(path, diff);
                break;
            }
            default:
View Full Code Here


            getBuilder(mount).append(diff).newline();
        }
    }

    private JsopWriter getBuilder(String mount) {
        JsopWriter builder = builders.get(mount);
        if (builder == null) {
            builder = new JsopBuilder();
            builders.put(mount, builder);
        }
        return builder;
View Full Code Here

        size--;
        return result;
    }

    public String toString() {
        JsopWriter json = new JsopBuilder();
        json.object();
        for (int i = 0; i < size; i++) {
            json.key(names[i]).value(children[i].toString());
        }
        json.endObject();
        return json.toString();
    }
View Full Code Here

        Node to = getNode(path, Revision.fromString(toRevisionId));
        if (from == null || to == null) {
            // TODO implement correct behavior if the node does't/didn't exist
            throw new MicroKernelException("Diff is only supported if the node exists in both cases");
        }
        JsopWriter w = new JsopStream();
        for (String p : from.getPropertyNames()) {
            // changed or removed properties
            String fromValue = from.getProperty(p);
            String toValue = to.getProperty(p);
            if (!fromValue.equals(toValue)) {
                w.tag('^').key(p);
                if (toValue == null) {
                    w.value(toValue);
                } else {
                    w.encodedValue(toValue).newline();
                }
            }
        }
        for (String p : to.getPropertyNames()) {
            // added properties
            if (from.getProperty(p) == null) {
                w.tag('^').key(p).encodedValue(to.getProperty(p)).newline();
            }
        }
        Revision fromRev = Revision.fromString(fromRevisionId);
        Revision toRev = Revision.fromString(toRevisionId);
        // TODO this does not work well for large child node lists
        // use a MongoDB index instead
        Children fromChildren = getChildren(path, fromRev, Integer.MAX_VALUE);
        Children toChildren = getChildren(path, toRev, Integer.MAX_VALUE);
        Set<String> childrenSet = new HashSet<String>(toChildren.children);
        for (String n : fromChildren.children) {
            if (!childrenSet.contains(n)) {
                w.tag('-').value(n).newline();
            } else {
                Node n1 = getNode(n, fromRev);
                Node n2 = getNode(n, toRev);
                // this is not fully correct:
                // a change is detected if the node changed recently,
                // even if the revisions are well in the past
                // if this is a problem it would need to be changed
                if (!n1.getId().equals(n2.getId())) {
                    w.tag('^').key(n).object().endObject().newline();
                }
            }
        }
        childrenSet = new HashSet<String>(fromChildren.children);
        for (String n : toChildren.children) {
            if (!childrenSet.contains(n)) {
                w.tag('+').key(n).object().endObject().newline();
            }
        }
        return w.toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.mk.json.JsopWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.