Package org.apache.jackrabbit.mk.json

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


            }
        } 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;
            }
            String diff = commit.getChanges();
            if (filtered) {
                try {
                    diff = new DiffBuilder(
                            rep.getNodeState(commit.getParentId(), "/"),
                            rep.getNodeState(commit.getId(), "/"),
                            "/", rep.getRevisionStore(), path).build();
                    if (diff.isEmpty()) {
                        continue;
                    }
                } catch (Exception e) {
                    throw new MicroKernelException(e);
                }
            }
            commitBuff.object().
                    key("id").value(commit.getId().toString()).
                    key("ts").value(commit.getCommitTS()).
                    key("msg").value(commit.getMsg()).
                    key("changes").value(diff).endObject();
        }
        return commitBuff.endArray().toString();
    }
View Full Code Here


            NodeState nodeState = rep.getNodeState(revId, path);
            if (nodeState == null) {
                return null;
            }

            JsopBuilder buf = new JsopBuilder().object();
            toJson(buf, nodeState, depth, (int) offset, maxChildNodes, true, nodeFilter);
            return buf.endObject().toString();
        } catch (Exception e) {
            throw new MicroKernelException(e);
        }
    }
View Full Code Here

    public static String addFiles(AbstractBlobStore store, String dir) throws Exception {
        ArrayList<String> list = new ArrayList<String>();
        String root = new File(dir).getAbsolutePath();
        String parent = new File(dir).getParentFile().getAbsolutePath();
        addFiles(list, new File(root));
        JsopBuilder listing = new JsopBuilder();
        listing.object();
        for (String f : list) {
            FileInputStream in = new FileInputStream(f);
            String id = store.writeBlob(in);
            in.close();
            String name = f.substring(parent.length());
            listing.key(name).value(id);
            listing.newline();
        }
        listing.endObject();
        String l = listing.toString();
        String id = store.writeBlob(new ByteArrayInputStream(l.getBytes("UTF-8")));
        return id;
    }
View Full Code Here

        return mk.nodeExists(PathUtils.concat(indexRootNode, name), revision);
    }

    void createNodes(String path) {
        String rev = mk.getHeadRevision();
        JsopBuilder jsop = new JsopBuilder();
        String p = "/";
        path = PathUtils.concat(indexRootNode, path);
        for (String e : PathUtils.elements(path)) {
            p = PathUtils.concat(p, e);
            if (!mk.nodeExists(p, rev)) {
                jsop.tag('+').key(PathUtils.relativize("/", p)).
                    object().endObject().newline();
            }
        }
        revision = mk.commit("/", jsop.toString(), rev, null);
    }
View Full Code Here

     * @param toRevision the new index revision
     * @return the new head revision
     */
    String updateEnd(String toRevision) {
        readRevision = toRevision;
        JsopBuilder jsop = new JsopBuilder();
        jsop.tag('^').key(PathUtils.concat(INDEX_CONTENT, "rev")).value(readRevision);
        buffer(jsop.toString());
        flushBuffer();
        return revision;
    }
View Full Code Here

    }

    public String asString() {
        // TODO ALLOW_UNQUOTED_FIELD_NAMES to safe space
        // (check what Javascript supports and what are the keywords)
        JsopWriter json = new JsopBuilder();
        json.setLineLength(120);
        boolean inline = true;
        if (id != null && !id.isInline()) {
            String nodeId = map.formatId(id);
            if (nodeId != null) {
                inline = false;
                json.encodedValue(nodeId).tag('=');
            }
        }
        json.object();
        String[] pv = propertyValuePairs;
        if (pv != null) {
            for (int i = 0, size = pv.length; i < size; i += 2) {
                json.key(pv[i]).encodedValue(pv[i + 1]);
            }
        }
        if (map.getHash() && id != null) {
            byte[] hash = getHash();
            json.key(HASH).value(StringUtils.convertBytesToHex(hash));
        }
        if (childNodes != null && childNodes.size() > 0) {
            if (map.getDescendantCount()) {
                if (descendantCount > childNodes.size()) {
                    json.key(DESCENDANT_COUNT).value(descendantCount);
                }
            }
            childNodes.append(json, map);
        }
        json.endObject();
        if (!inline) {
            json.tag(';');
        }
        return json.toString();
    }
View Full Code Here

            }
        }
    }

    private String getJsop() {
        JsopBuilder jsop = new JsopBuilder();
        jsop.tag('+').key(PathUtils.concat(tree.getName(), Indexer.INDEX_CONTENT, 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();
        return jsop.toString();
    }
View Full Code Here

        }
        return c;
    }

    void bufferSetArray(String path, String propertyName, String[] data) {
        JsopBuilder jsop = new JsopBuilder();
        path = PathUtils.concat(name, Indexer.INDEX_CONTENT, 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

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

    void bufferDelete(String path) {
        JsopBuilder jsop = new JsopBuilder();
        jsop.tag('-').value(PathUtils.concat(name, Indexer.INDEX_CONTENT, path));
        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.