Package org.apache.jackrabbit.mk.json

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


    }

    @Override
    public JsopReader getJournalStream(String fromRevisionId, String toRevisionId, String path) {
        rightsRevision = getHeadRevision();
        JsopReader t = mk.getJournalStream(fromRevisionId, toRevisionId, path);
        if (admin) {
            return t;
        }
        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


    }

    @Override
    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path, int depth) {
        rightsRevision = getHeadRevision();
        JsopReader diff = mk.diffStream(fromRevisionId, toRevisionId, path, depth);
        if (admin) {
            return diff;
        }
        return filterDiff(diff, toRevisionId);
    }
View Full Code Here

    public JsopReader getNodesStream(String path, String revisionId, int depth, long offset, int count, String filter) {
        rightsRevision = getHeadRevision();
        if (!checkRights(path, false)) {
            return null;
        }
        JsopReader t = mk.getNodesStream(path, revisionId, depth, offset, count, filter);
        if (admin || t == null) {
            return t;
        }
        t.read('{');
        NodeImpl n = NodeImpl.parse(map, t, 0);
        n = filterAccess(path, n);
        JsopStream buff = new JsopStream();
        if (n == null) {
            return null;
View Full Code Here

            String key = path + "@" + rightsRevision;
            NodeImpl n = cache.get(key);
            if (n == null) {
                if (mk.nodeExists(path, rightsRevision)) {
                    String json = mk.getNodes(path, rightsRevision, 0, 0, 0, null);
                    JsopReader t = new JsopTokenizer(json);
                    t.read('{');
                    n = NodeImpl.parse(map, t, 0);
                } else {
                    n = new NodeImpl(map, 0);
                }
                cache.put(key, n);
View Full Code Here

        return getJournalStream(fromRevisionId, toRevisionId, path).toString();
    }

    @Override
    public final String getNodes(String path, String revisionId, int depth, long offset, int maxChildNodes, String filter) {
        JsopReader reader =
                getNodesStream(path, revisionId, depth, offset, maxChildNodes, filter);
        if (reader != null) {
            return reader.toString();
        } else {
            return null;
        }
    }
View Full Code Here

        if (properties == null) {
            String json = kernel.getNodes(
                    path, revision, 0, 0, MAX_CHILD_NODE_NAMES,
                    "{\"properties\":[\"*\",\":hash\"]}");

            JsopReader reader = new JsopTokenizer(json);
            reader.read('{');
            properties = new LinkedHashMap<String, PropertyState>();
            childPaths = new LinkedHashMap<String, String>();
            do {
                String name = StringCache.get(reader.readString());
                reader.read(':');
                if (":childNodeCount".equals(name)) {
                    childNodeCount =
                            Long.valueOf(reader.read(JsopReader.NUMBER));
                } else if (":hash".equals(name)) {
                    hash = new String(reader.read(JsopReader.STRING));
                } else if (reader.matches('{')) {
                    reader.read('}');
                    String childPath = path + '/' + name;
                    if ("/".equals(path)) {
                        childPath = '/' + name;
                    }
                    childPaths.put(name, childPath);
                } else if (reader.matches('[')) {
                    properties.put(name, readArrayProperty(name, reader));
                } else {
                    properties.put(name, readProperty(name, reader));
                }
            } while (reader.matches(','));
            reader.read('}');
            reader.read(JsopReader.END);
            // optimize for empty childNodes
            if (childPaths.isEmpty()) {
                childPaths = Collections.emptyMap();
            }
        }
View Full Code Here

            public Iterator<ChildNodeEntry> iterator() {
                List<ChildNodeEntry> entries =
                        Lists.newArrayListWithCapacity(count);
                String json = kernel.getNodes(
                        path, revision, 0, offset, count, null);
                JsopReader reader = new JsopTokenizer(json);
                reader.read('{');
                do {
                    String name = StringCache.get(reader.readString());
                    reader.read(':');
                    if (reader.matches('{')) {
                        reader.read('}');
                        String childPath = getChildPath(name);
                        entries.add(new KernelChildNodeEntry(name, childPath));
                    } else if (reader.matches('[')) {
                        while (reader.read() != ']') {
                            // skip
                        }
                    } else {
                        reader.read();
                    }
                } while (reader.matches(','));
                reader.read('}');
                reader.read(JsopReader.END);
                return entries.iterator();
            }
        };
    }
View Full Code Here

                String json = kernel.getNodes(
                        path, revision, 0, 0, MAX_CHILD_NODE_NAMES,
                        "{\"properties\":[\"*\",\":hash\",\":id\"]}");

                checkNotNull(json,"No node found at path [%s] for revision [%s]",path,revision);
                JsopReader reader = new JsopTokenizer(json);
                reader.read('{');
                properties = new LinkedHashMap<String, PropertyState>();
                childNames = new LinkedHashSet<String>();
                do {
                    String name = StringCache.get(reader.readString());
                    reader.read(':');
                    if (":childNodeCount".equals(name)) {
                        childNodeCount =
                                Long.valueOf(reader.read(JsopReader.NUMBER));
                    } else if (":hash".equals(name)) {
                        hash = new String(reader.read(JsopReader.STRING));
                        if (hash.equals(id)) {
                            // save some memory
                            hash = id;
                        }
                    } else if (":id".equals(name)) {
                        id = new String(reader.read(JsopReader.STRING));
                        if (id.equals(hash)) {
                            // save some memory
                            id = hash;
                        }
                    } else if (reader.matches('{')) {
                        reader.read('}');
                        childNames.add(name);
                    } else if (reader.matches('[')) {
                        properties.put(name, readArrayProperty(name, reader));
                    } else {
                        properties.put(name, readProperty(name, reader));
                    }
                } while (reader.matches(','));
                reader.read('}');
                reader.read(JsopReader.END);
                // optimize for empty childNodes
                if (childNames.isEmpty()) {
                    childNames = Collections.emptySet();
                }
                initialized = true;
View Full Code Here

                    private void fetchEntries() {
                        List<ChildNodeEntry> entries = Lists
                                .newArrayListWithCapacity(MAX_CHILD_NODE_NAMES);
                        String json = kernel.getNodes(path, revision, 0,
                                currentOffset, MAX_CHILD_NODE_NAMES, null);
                        JsopReader reader = new JsopTokenizer(json);
                        reader.read('{');
                        do {
                            String name = StringCache.get(reader.readString());
                            reader.read(':');
                            if (reader.matches('{')) {
                                reader.read('}');
                                entries.add(new KernelChildNodeEntry(name));
                            } else if (reader.matches('[')) {
                                while (reader.read() != ']') {
                                    // skip
                                }
                            } else {
                                reader.read();
                            }
                        } while (reader.matches(','));
                        reader.read('}');
                        reader.read(JsopReader.END);
                        if (entries.isEmpty()) {
                            current = null;
                        } else {
                            currentOffset += entries.size();
                            current = entries.iterator();
View Full Code Here

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

    private void parseJsonDiff(Commit commit, String json, String rootPath) {
        String baseRevId = commit.getBaseRevision() != null ?
                commit.getBaseRevision().toString() : null;
        JsopReader t = new JsopTokenizer(json);
        while (true) {
            int r = t.read();
            if (r == JsopReader.END) {
                break;
            }
            String path = PathUtils.concat(rootPath, t.readString());
            switch (r) {
                case '+':
                    t.read(':');
                    t.read('{');
                    parseAddNode(commit, t, path);
                    break;
                case '-':
                    commit.removeNode(path);
                    nodeStore.markAsDeleted(path, commit, true);
                    commit.removeNodeDiff(path);
                    break;
                case '^':
                    t.read(':');
                    String value;
                    if (t.matches(JsopReader.NULL)) {
                        value = null;
                    } else {
                        value = t.readRawValue().trim();
                    }
                    String p = PathUtils.getParentPath(path);
                    String propertyName = PathUtils.getName(path);
                    commit.updateProperty(p, propertyName, value);
                    commit.updatePropertyDiff(p, propertyName, value);
                    break;
                case '>': {
                    // TODO support moving nodes that were modified within this commit
                    t.read(':');
                    String sourcePath = path;
                    String targetPath = t.readString();
                    if (!PathUtils.isAbsolute(targetPath)) {
                        targetPath = PathUtils.concat(rootPath, targetPath);
                    }
                    if (!nodeExists(sourcePath, baseRevId)) {
                        throw new MicroKernelException("Node not found: " + sourcePath + " in revision " + baseRevId);
                    } else if (nodeExists(targetPath, baseRevId)) {
                        throw new MicroKernelException("Node already exists: " + targetPath + " in revision " + baseRevId);
                    }
                    commit.moveNode(sourcePath, targetPath);
                    nodeStore.moveNode(sourcePath, targetPath, commit);
                    break;
                }
                case '*': {
                    // TODO support copying nodes that were modified within this commit
                    t.read(':');
                    String sourcePath = path;
                    String targetPath = t.readString();
                    if (!PathUtils.isAbsolute(targetPath)) {
                        targetPath = PathUtils.concat(rootPath, targetPath);
                    }
                    if (!nodeExists(sourcePath, baseRevId)) {
                        throw new MicroKernelException("Node not found: " + sourcePath + " in revision " + baseRevId);
                    } else if (nodeExists(targetPath, baseRevId)) {
                        throw new MicroKernelException("Node already exists: " + targetPath + " in revision " + baseRevId);
                    }
                    commit.copyNode(sourcePath, targetPath);
                    nodeStore.copyNode(sourcePath, targetPath, commit);
                    break;
                }
                default:
                    throw new MicroKernelException("token: " + (char) t.getTokenType());
            }
        }
    }
View Full Code Here

TOP

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

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.