Package org.apache.jackrabbit.mk.json

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


            }
        } catch (Exception e) {
            throw new MicroKernelException(e);
        }

        JsopBuilder buff = new JsopBuilder().array();
        for (int i = history.size() - 1; i >= 0; i--) {
            StoredCommit commit = history.get(i);
            buff.object().
                    key("id").value(commit.getId().toString()).
                    key("ts").value(commit.getCommitTS()).
                    key("msg").value(commit.getMsg()).
                    endObject();
        }
        return buff.endArray().toString();
    }
View Full Code Here


            }
        } catch (Exception e) {
            throw new MicroKernelException(e);
        }

        JsopBuilder commitBuff = new JsopBuilder().array();
        // iterate over commits in chronological order,
        // starting with oldest commit
        for (int i = commits.size() - 1; i >= 0; i--) {
            StoredCommit commit = commits.get(i);
            if (commit.getParentId() == null) {
                continue;
            }
            commitBuff.object().
                    key("id").value(commit.getId().toString()).
                    key("ts").value(commit.getCommitTS()).
                    key("msg").value(commit.getMsg()).
                    key("changes").value(commit.getChanges()).endObject();
        }
        return commitBuff.endArray().toString();
    }
View Full Code Here

        try {
            NodeState nodeState = rep.getNodeState(revId, path);
            if (nodeState == null) {
                return null;
            }
            JsopBuilder buf = new JsopBuilder().object();
            toJson(buf, nodeState, depth, (int) offset, count, true);
            return buf.endObject().toString();
        } catch (Exception e) {
            throw new MicroKernelException(e);
        }
    }
View Full Code Here

    }

    public String build() throws Exception {
        // TODO extract and evaluate filter criteria specified in 'filter' parameter

        final JsopBuilder buff = new JsopBuilder();
        // maps (key: id of target node, value: path/to/target)
        // for tracking added/removed nodes; this allows us
        // to detect 'move' operations
        final HashMap<NodeState, String> addedNodes = new HashMap<NodeState, String>();
        final HashMap<NodeState, String> removedNodes = new HashMap<NodeState, String>();

        if (before == null) {
            if (after != null) {
                buff.tag('+').key(path).object();
                toJson(buff, after);
                return buff.endObject().newline().toString();
            } else {
                throw new Exception("path doesn't exist in the specified revisions: " + path);
            }
        } else if (after == null) {
            buff.tag('-');
            buff.value(path);
            return buff.newline().toString();
        }

        TraversingNodeDiffHandler diffHandler = new TraversingNodeDiffHandler(store) {
            @Override
            public void propertyAdded(PropertyState after) {
                buff.tag('+').
                        key(PathUtils.concat(getCurrentPath(), after.getName())).
                        encodedValue(after.getEncodedValue()).
                        newline();
            }

            @Override
            public void propertyChanged(PropertyState before, PropertyState after) {
                buff.tag('^').
                        key(PathUtils.concat(getCurrentPath(), after.getName())).
                        encodedValue(after.getEncodedValue()).
                        newline();
            }

            @Override
            public void propertyDeleted(PropertyState before) {
                // since property and node deletions can't be distinguished
                // using the "- <path>" notation we're representing
                // property deletions as "^ <path>:null"
                buff.tag('^').
                        key(PathUtils.concat(getCurrentPath(), before.getName())).
                        value(null).
                        newline();
            }

            @Override
            public void childNodeAdded(String name, NodeState after) {
                addedNodes.put(after, PathUtils.concat(getCurrentPath(), name));
                buff.tag('+').
                        key(PathUtils.concat(getCurrentPath(), name)).object();
                toJson(buff, after);
                buff.endObject().newline();
            }

            @Override
            public void childNodeDeleted(String name, NodeState before) {
                removedNodes.put(before, PathUtils.concat(getCurrentPath(), name));
                buff.tag('-');
                buff.value(PathUtils.concat(getCurrentPath(), name));
                buff.newline();
            }
        };
        diffHandler.start(before, after, path);

        // check if this commit includes 'move' operations
        // by building intersection of added and removed nodes
        addedNodes.keySet().retainAll(removedNodes.keySet());
        if (!addedNodes.isEmpty()) {
            // this commit includes 'move' operations
            removedNodes.keySet().retainAll(addedNodes.keySet());
            // addedNodes & removedNodes now only contain information about moved nodes

            // re-build the diff in a 2nd pass, this time representing moves correctly
            buff.resetWriter();

            // TODO refactor code, avoid duplication

            diffHandler = new TraversingNodeDiffHandler(store) {
                @Override
                public void propertyAdded(PropertyState after) {
                    buff.tag('+').
                            key(PathUtils.concat(getCurrentPath(), after.getName())).
                            encodedValue(after.getEncodedValue()).
                            newline();
                }

                @Override
                public void propertyChanged(PropertyState before, PropertyState after) {
                    buff.tag('^').
                            key(PathUtils.concat(getCurrentPath(), after.getName())).
                            encodedValue(after.getEncodedValue()).
                            newline();
                }

                @Override
                public void propertyDeleted(PropertyState before) {
                    // since property and node deletions can't be distinguished
                    // using the "- <path>" notation we're representing
                    // property deletions as "^ <path>:null"
                    buff.tag('^').
                            key(PathUtils.concat(getCurrentPath(), before.getName())).
                            value(null).
                            newline();
                }

                @Override
                public void childNodeAdded(String name, NodeState after) {
                    if (addedNodes.containsKey(after)) {
                        // moved node, will be processed separately
                        return;
                    }
                    buff.tag('+').
                            key(PathUtils.concat(getCurrentPath(), name)).object();
                    toJson(buff, after);
                    buff.endObject().newline();
                }

                @Override
                public void childNodeDeleted(String name, NodeState before) {
                    if (addedNodes.containsKey(before)) {
                        // moved node, will be processed separately
                        return;
                    }
                    buff.tag('-');
                    buff.value(PathUtils.concat(getCurrentPath(), name));
                    buff.newline();
                }

            };
            diffHandler.start(before, after, path);

            // finally process moved nodes
            for (Map.Entry<NodeState, String> entry : addedNodes.entrySet()) {
                buff.tag('>').
                        // path/to/deleted/node
                        key(removedNodes.get(entry.getKey())).
                        // path/to/added/node
                        value(entry.getValue()).
                        newline();
            }
        }
        return buff.toString();
    }
View Full Code Here

        jsop = null;
    }

    public String toString() {
        if (jsop == null) {
            JsopBuilder w = new JsopBuilder();
            w.object();
            if (lengthIndex) {
                if (map.containsKey(LENGTHS_KEY)) {
                    throw new IllegalStateException("Object already contains the key " + LENGTHS_KEY);
                }
                StringBuilder buff = new StringBuilder();
                for (Entry<String, String> e : map.entrySet()) {
                    if (buff.length() > 0) {
                        buff.append(',');
                    }
                    buff.append(e.getValue().length());
                }
                w.key(LENGTHS_KEY).value(buff.toString());
            }
            for (Entry<String, String> e : map.entrySet()) {
                w.key(e.getKey()).encodedValue(e.getValue());
            }
            w.endObject();
            jsop = w.toString();
            start = 0;
        }
        return jsop.substring(start);
    }
View Full Code Here

    private final JsopBuilder builder;

    private final BlobSerializer blobs;

    CommitDiff(@Nonnull Commit commit, @Nonnull BlobSerializer blobs) {
        this(checkNotNull(commit), "/", new JsopBuilder(), checkNotNull(blobs));
    }
View Full Code Here

    @Override
    void writeCreate() {
        verify();
        tree.modified(this);
        JsopBuilder jsop = new JsopBuilder();
        jsop.tag('+').key(PathUtils.concat(tree.getName(), getPath())).object();
        jsop.key("keys").array();
        for (String k : keys) {
            jsop.value(k);
        }
        jsop.endArray();
        jsop.key("values").array();
        for (String v : values) {
            jsop.value(v);
        }
        jsop.endArray();
        // could just use child node list, but then
        // new children need to be ordered at the right position,
        // and we would need a way to distinguish empty lists
        // from a leaf
        jsop.key("children").array();
        for (String d : children) {
            jsop.value(d);
        }
        jsop.endArray();
        jsop.endObject();
        jsop.newline();
        tree.buffer(jsop.toString());
    }
View Full Code Here

    public BTree(Indexer indexer, String name, boolean unique) {
        this.indexer = indexer;
        this.name = name;
        this.unique = unique;
        if (!indexer.nodeExists(name)) {
            JsopBuilder jsop = new JsopBuilder();
            jsop.tag('+').key(name).object().endObject();
            indexer.commit(jsop.toString());
        }
    }
View Full Code Here

        }
        return c;
    }

    void bufferSetArray(String path, String propertyName, String[] data) {
        JsopBuilder jsop = new JsopBuilder();
        path = PathUtils.concat(name, path);
        jsop.tag('^').key(PathUtils.concat(path, propertyName));
        if (data == null) {
            jsop.value(null);
        } else {
            jsop.array();
            for (String d : data) {
                jsop.value(d);
            }
            jsop.endArray();
        }
        jsop.newline();
        indexer.buffer(jsop.toString());
    }
View Full Code Here

        jsop.newline();
        indexer.buffer(jsop.toString());
    }

    void bufferMove(String path, String newPath) {
        JsopBuilder jsop = new JsopBuilder();
        jsop.tag('>').key(path).value(newPath);
        jsop.newline();
        indexer.buffer(jsop.toString());
    }
View Full Code Here

TOP

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

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.