Package org.apache.jackrabbit.mk.json

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


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

        Revision rev = Revision.fromString(revisionId);
        Node n = nodeStore.getNode(path, rev);
        if (n == null) {
            return null;
        }
        JsopStream json = new JsopStream();
        boolean includeId = filter != null && filter.contains(":id");
        includeId |= filter != null && filter.contains(":hash");
        json.object();
        n.append(json, includeId);
        int max;
        if (maxChildNodes == -1) {
            max = Integer.MAX_VALUE;
            maxChildNodes = Integer.MAX_VALUE;
        } else {
            // use long to avoid overflows
            long m = ((long) maxChildNodes) + offset;
            max = (int) Math.min(m, Integer.MAX_VALUE);
        }
        Children c = nodeStore.getChildren(n, null, max);
        for (long i = offset; i < c.children.size(); i++) {
            if (maxChildNodes-- <= 0) {
                break;
            }
            String name = PathUtils.getName(c.children.get((int) i));
            json.key(name).object().endObject();
        }
        if (c.hasMore) {
            // TODO use a better way to notify there are more children
            json.key(":childNodeCount").value(Long.MAX_VALUE);
        } else {
            json.key(":childNodeCount").value(c.children.size());
        }
        json.endObject();
        return json.toString();
    }
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(PropertyIndexConstants.TYPE_PREFIX)) {
            String prefix = index.substring(PropertyIndexConstants.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(PropertyIndexConstants.TYPE_PROPERTY)) {
            String property = index.substring(PropertyIndexConstants.TYPE_PROPERTY.length());
            boolean unique = false;
            if (property.endsWith("," + PropertyIndexConstants.UNIQUE)) {
                unique = true;
                property = property.substring(0, property.length() - PropertyIndexConstants.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

        Revision rev = Revision.fromString(revisionId);
        Node n = nodeStore.getNode(path, rev);
        if (n == null) {
            return null;
        }
        JsopStream json = new JsopStream();
        boolean includeId = filter != null && filter.contains(":id");
        includeId |= filter != null && filter.contains(":hash");
        json.object();
        n.append(json, includeId);
        int max;
        if (maxChildNodes == -1) {
            max = Integer.MAX_VALUE;
            maxChildNodes = Integer.MAX_VALUE;
        } else {
            // use long to avoid overflows
            long m = ((long) maxChildNodes) + offset;
            max = (int) Math.min(m, Integer.MAX_VALUE);
        }
        Children c = nodeStore.getChildren(path, rev, max);
        for (long i = offset; i < c.children.size(); i++) {
            if (maxChildNodes-- <= 0) {
                break;
            }
            String name = PathUtils.getName(c.children.get((int) i));
            json.key(name).object().endObject();
        }
        if (c.hasMore) {
            // TODO use a better way to notify there are more children
            json.key(":childNodeCount").value(Long.MAX_VALUE);
        } else {
            json.key(":childNodeCount").value(c.children.size());
        }
        json.endObject();
        return json.toString();
    }
View Full Code Here

        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();
            }
        }
        // TODO this does not work well for large child node lists
        // use a MongoDB index instead
        int max = MANY_CHILDREN_THRESHOLD;
        Children fromChildren, toChildren;
        fromChildren = nodeStore.getChildren(path, fromRev, max);
        toChildren = nodeStore.getChildren(path, toRev, max);
        if (!fromChildren.hasMore && !toChildren.hasMore) {
            diffFewChildren(w, fromChildren, fromRev, toChildren, toRev);
        } else {
            if (FAST_DIFF) {
                diffManyChildren(w, path, fromRev, toRev);
            } else {
                max = Integer.MAX_VALUE;
                fromChildren = nodeStore.getChildren(path, fromRev, max);
                toChildren = nodeStore.getChildren(path, toRev, max);
                diffFewChildren(w, fromChildren, fromRev, toChildren, toRev);
            }
        }
        return w.toString();
    }
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.