Package org.apache.jackrabbit.mk.json

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


        }
        return filterDiff(diff, toRevisionId);
    }

    private JsopReader filterDiff(JsopReader t, String revisionId) {
        JsopStream buff = new JsopStream();
        verifyDiff(t, revisionId, null, buff);
        return buff;
    }
View Full Code Here


            return t;
        }
        t.read('{');
        NodeImpl n = NodeImpl.parse(map, t, 0);
        n = filterAccess(path, n);
        JsopStream buff = new JsopStream();
        if (n == null) {
            return null;
        } else {
            // TODO childNodeCount properties might be wrong
            // when count and offset are used
View Full Code Here

    private String doCommit(String rootPath, JsopReader t, String revisionId, String message) {
        long oldRevision = headRevId, rev = headRevId + 1;
        NodeImpl root = nodeMap.getRootId().getNode(nodeMap);
        NodeImpl head = root.getNode("head"), oldHead = head;
        NodeImpl data = head.getNode("data");
        JsopWriter diff = new JsopStream();
        while (true) {
            int r = t.read();
            if (r == JsopReader.END) {
                break;
            }
            String path = PathUtils.concat(rootPath, t.readString());
            String from = PathUtils.relativize("/", path);
            switch (r) {
            case '+':
                t.read(':');
                diff.tag('+').key(path);
                if (t.matches('{')) {
                    NodeImpl n = NodeImpl.parse(nodeMap, t, rev);
                    data = data.cloneAndAddChildNode(from, false, null, n, rev);
                    n.append(diff, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, false);
                } else {
                    String value = t.readRawValue().trim();
                    String nodeName = PathUtils.getParentPath(from);
                    String propertyName = PathUtils.getName(from);
                    if (data.getNode(nodeName).hasProperty(propertyName)) {
                        throw ExceptionFactory.get("Property already exists: " + propertyName);
                    }
                    data = data.cloneAndSetProperty(from, value, rev);
                    diff.encodedValue(value);
                }
                diff.newline();
                break;
            case '-':
                diff.tag('-').value(path).newline();
                if (data.exists(from) || !getRevisionDataRoot(revisionId).exists(from)) {
                    // this will fail if the node didn't exist
                    data = data.cloneAndRemoveChildNode(from, rev);
                }
                break;
            case '^':
                t.read(':');
                boolean isConfigChange = from.startsWith(":root/head/config/");
                String value;
                if (t.matches(JsopReader.NULL)) {
                    value = null;
                    diff.tag('^').key(path).value(null);
                } else {
                    value = t.readRawValue().trim();
                    String nodeName = PathUtils.getParentPath(from);
                    String propertyName = PathUtils.getName(from);
                    if (isConfigChange || data.getNode(nodeName).hasProperty(propertyName)) {
                        diff.tag('^');
                    } else {
                        diff.tag('+');
                    }
                    diff.key(path).encodedValue(value);
                }
                if (isConfigChange) {
                    String p = PathUtils.relativize(":root/head", from);
                    if (!head.exists("config")) {
                        head = head.setChild("config", new NodeImpl(nodeMap, rev), rev);
                    }
                    head = head.cloneAndSetProperty(p, value, rev);
                    applyConfig(head);
                } else {
                    data = data.cloneAndSetProperty(from, value, rev);
                }
                diff.newline();
                break;
            case '>': {
                t.read(':');
                diff.tag('>').key(path);
                String name = PathUtils.getName(from);
                String position, target, to;
                boolean rename;
                if (t.matches('{')) {
                    rename = false;
                    position = t.readString();
                    t.read(':');
                    target = t.readString();
                    t.read('}');
                    diff.object().key(position);
                    if (!PathUtils.isAbsolute(target)) {
                        target = PathUtils.concat(rootPath, target);
                    }
                    diff.value(target).endObject();
                } else {
                    rename = true;
                    position = null;
                    target = t.readString();
                    if (!PathUtils.isAbsolute(target)) {
                        target = PathUtils.concat(rootPath, target);
                    }
                    diff.value(target);
                }
                diff.newline();
                boolean before = false;
                if ("last".equals(position)) {
                    target = PathUtils.concat(target, name);
                    position = null;
                } else if ("first".equals(position)) {
                    target = PathUtils.concat(target, name);
                    position = null;
                    before = true;
                } else if ("before".equals(position)) {
                    position = PathUtils.getName(target);
                    target = PathUtils.getParentPath(target);
                    target = PathUtils.concat(target, name);
                    before = true;
                } else if ("after".equals(position)) {
                    position = PathUtils.getName(target);
                    target = PathUtils.getParentPath(target);
                    target = PathUtils.concat(target, name);
                } else if (position == null) {
                    // move
                } else {
                    throw ExceptionFactory.get("position: " + position);
                }
                to = PathUtils.relativize("/", target);
                boolean inPlaceRename = false;
                if (rename) {
                    if (PathUtils.getParentPath(from).equals(PathUtils.getParentPath(to))) {
                        inPlaceRename = true;
                        position = PathUtils.getName(from);
                    }
                }
                NodeImpl node = data.getNode(from);
                if (!inPlaceRename) {
                    data = data.cloneAndRemoveChildNode(from, rev);
                }
                data = data.cloneAndAddChildNode(to, before, position, node, rev);
                if (inPlaceRename) {
                    data = data.cloneAndRemoveChildNode(from, rev);
                }
                break;
            }
            case '*': {
                // TODO possibly support target position notation
                t.read(':');
                String target = t.readString();
                if (!PathUtils.isAbsolute(target)) {
                    target = PathUtils.concat(rootPath, target);
                }
                diff.tag('*').key(path).value(target);
                String to = PathUtils.relativize("/", target);
                NodeImpl node = data.getNode(from);
                JsopStream json = new JsopStream();
                node.append(json, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, false);
                json.read('{');
                NodeImpl n2 = NodeImpl.parse(nodeMap, json, rev);
                data = data.cloneAndAddChildNode(to, false, null, n2, rev);
                break;
            }
            default:
View Full Code Here

                    }
                    revisions.add(r);
                }
            }
        }
        JsopStream buff = new JsopStream().array();
        Collections.sort(revisions);
        for (Revision rev : revisions) {
            if (rev.getNanos() > sinceNanos) {
                buff.encodedValue(rev.toString());
            }
        }
        return buff.endArray();
    }
View Full Code Here

                    break;
                }
                node = node.getNode(next);
            }
        }
        JsopStream buff = new JsopStream().array().newline();
        for (int i = revisions.size() - 1; i >= 0; i--) {
            Revision rev = revisions.get(i);
            if (rev.getId() >= fromRev && rev.getId() <= toRev) {
                rev.appendJournal(buff);
            }
        }
        return buff.endArray();
   }
View Full Code Here

    @Override
    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String filter) {
        fromRevisionId = fromRevisionId == null ? headRevision : fromRevisionId;
        toRevisionId = toRevisionId == null ? headRevision : toRevisionId;
        // TODO implement if required
        return new JsopStream();
    }
View Full Code Here

            n = getRevisionDataRoot(revisionId).getNode(path.substring(1));
        }
        if (n == null) {
            return null;
        }
        JsopStream json = new JsopStream();
        n.append(json, depth, offset, count, true);
        return json;
    }
View Full Code Here

    //-----------------------------< internal >---------------------------------

    private String diffImpl(Node from, Node to)
            throws MicroKernelException {
        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(null);
                } 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();
            }
        }
        // TODO this does not work well for large child node lists
        // use a document store index instead
        int max = MANY_CHILDREN_THRESHOLD;
        Node.Children fromChildren, toChildren;
        fromChildren = getChildren(from, null, max);
        toChildren = getChildren(to, null, max);
        if (!fromChildren.hasMore && !toChildren.hasMore) {
            diffFewChildren(w, fromChildren, from.getLastRevision(),
                    toChildren, to.getLastRevision());
        } else {
            if (FAST_DIFF) {
                diffManyChildren(w, from.getPath(),
                        from.getLastRevision(), to.getLastRevision());
            } else {
                max = Integer.MAX_VALUE;
                fromChildren = getChildren(from, null, max);
                toChildren = getChildren(to, null, max);
                diffFewChildren(w, fromChildren, from.getLastRevision(),
                        toChildren, to.getLastRevision());
            }
        }
        return w.toString();
    }
View Full Code Here

                    }
                    revisions.add(r);
                }
            }
        }
        JsopStream buff = new JsopStream().array();
        Collections.sort(revisions);
        for (Revision rev : revisions) {
            if (rev.getNanos() > sinceNanos) {
                buff.encodedValue(rev.toString());
            }
        }
        return buff.endArray();
    }
View Full Code Here

                    break;
                }
                node = node.getNode(next);
            }
        }
        JsopStream buff = new JsopStream().array().newline();
        for (int i = revisions.size() - 1; i >= 0; i--) {
            Revision rev = revisions.get(i);
            if (rev.getId() >= fromRev && rev.getId() <= toRev) {
                rev.appendJournal(buff);
            }
        }
        return buff.endArray();
   }
View Full Code Here

TOP

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

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.