Package org.apache.jackrabbit.mk.json

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


    @Override
    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path) {
        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

            // not a query (expected: /index/prefix:x?y) - treat as regular node lookup
            return mk.getNodesStream(path, revisionId, depth, offset, count, filter);
        }
        String data = index.substring(idx + 1);
        index = index.substring(0, idx);
        JsopStream s = new JsopStream();
        s.array();
        if (index.startsWith(Indexer.TYPE_PREFIX)) {
            String prefix = index.substring(Indexer.TYPE_PREFIX.length());
            PrefixIndex prefixIndex = indexer.getPrefixIndex(prefix);
            if (prefixIndex == null) {
                throw ExceptionFactory.get("Unknown index: " + index);
            }
            Iterator<String> it = prefixIndex.getPaths(data, revisionId);
            while (it.hasNext()) {
                s.value(it.next());
            }
        } else if (index.startsWith(Indexer.TYPE_PROPERTY)) {
            String property = index.substring(Indexer.TYPE_PROPERTY.length());
            boolean unique = false;
            if (property.endsWith("," + Indexer.UNIQUE)) {
                unique = true;
                property = property.substring(0, property.length() - Indexer.UNIQUE.length() - 1);
            }
            PropertyIndex propertyIndex = indexer.getPropertyIndex(property);
            if (propertyIndex == null) {
                throw ExceptionFactory.get("Unknown index: " + index);
            }
            if (unique) {
                String value = propertyIndex.getPath(data, revisionId);
                if (value != null) {
                    s.value(value);
                }
            } else {
                Iterator<String> it = propertyIndex.getPaths(data, revisionId);
                while (it.hasNext()) {
                    s.value(it.next());
                }
            }
        }
        s.endArray();
        return s;
    }
View Full Code Here

        }
        t.read('[');
        if (t.matches(']')) {
            return new JsopTokenizer("[]");
        }
        JsopStream buff = new JsopStream();
        buff.array();
        String revision = fromRevisionId;
        do {
            t.read('{');
            buff.object();
            do {
                String key = t.readString();
                buff.key(key);
                t.read(':');
                if (key.equals("id")) {
                    t.read();
                    String value = t.getToken();
                    revision = value;
                    buff.value(value);
                } else if (key.equals("changes")) {
                    t.read();
                    String value = t.getToken();
                    value = filterDiff(new JsopTokenizer(value), revision).toString();
                    buff.value(value);
                } else {
                    String raw = t.readRawValue();
                    //System.out.println(key + ":" + raw);
                    buff.encodedValue(raw);
                }
            } while (t.matches(','));
            buff.endObject();
            t.read('}');
        } while (t.matches(','));
        buff.endArray();
        return buff;
    }
View Full Code Here

        }
        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

    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

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.