Package org.apache.jackrabbit.mk.json

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


            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('}');
                        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);
                return entries.iterator();
            }
        };
    }
View Full Code Here


            baseRev = headRevision;
            baseRevId = baseRev.toString();
        } else {
            baseRev = Revision.fromString(stripBranchRevMarker(baseRevId));
        }
        JsopReader t = new JsopTokenizer(json);
        Revision rev = newRevision();
        Commit commit = new Commit(this, baseRev, rev);
        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);
                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);
                moveNode(sourcePath, targetPath, baseRev, 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);
                copyNode(sourcePath, targetPath, baseRev, commit);
                break;
            }
            default:
                throw new MicroKernelException("token: " + (char) t.getTokenType());
            }
        }
        if (baseRevId.startsWith("b")) {
            // remember branch commit
            Branch b = branches.getBranch(baseRev);
View Full Code Here

    private static void cleanRepository(MicroKernel mk) {
        String result = mk.getNodes("/", mk.getHeadRevision(), 0, 0, -1, null);
        List<String> names = new ArrayList<String>();
        List<String> properties = new ArrayList<String>();
        JsopReader t = new JsopTokenizer(result);
        t.read('{');
        if (!t.matches('}')) {
            do {
                String key = t.readString();
                t.read(':');
                if (t.matches('{')) {
                    names.add(key);
                    NodeImpl.parse(new NodeMap(), t, 0);
                } else {
                    if (!key.equals(":childNodeCount")) {
                        properties.add(key);
                    } else if (!key.equals(":hash")) {
                        properties.add(key);
                    }
                    t.readRawValue();
                }
            } while (t.matches(','));
            t.read('}');
        }
        if (!names.isEmpty()) {
            JsopBuilder buff = new JsopBuilder();
            for (String name : names) {
                buff.tag('-').value(name).newline();
View Full Code Here

    @Test
    public void testFromJsonValue() throws IOException {
        for (CoreValue v : singleValueMap.keySet()) {
            String json = singleValueMap.get(v);
            JsopReader reader = new JsopTokenizer(json);
            assertEquals(v, CoreValueMapper.fromJsopReader(reader, valueFactory));
        }
    }
View Full Code Here

    @Test
    public void testListFromJsopReader() throws IOException {
        for (String json : mvValueMap.keySet()) {
            List<CoreValue> values = mvValueMap.get(json);
            JsopReader reader = new JsopTokenizer(json);
            if (reader.matches('[')) {
                assertEquals(values, CoreValueMapper.listFromJsopReader(reader, valueFactory));
            }
        }
    }
View Full Code Here

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

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

        }
    }

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

            indexer.updateIndex(rootPath, jsonDiff, rev);
            rev = mk.getHeadRevision();
            rev = indexer.updateEnd(rev);
            return rev;
        }
        JsopReader t = jsonDiff;
        while (true) {
            int r = t.read();
            if (r == JsopReader.END) {
                break;
            }
            String path;
            if (rootPath == null) {
                path = t.readString();
            } else {
                path = PathUtils.concat(rootPath, t.readString());
            }
            switch (r) {
            case '+':
                t.read(':');
                t.read('{');
                // parse but ignore
                NodeImpl.parse(map, t, 0);
                path = PathUtils.relativize(INDEX_PATH, path);
                if (path.startsWith(TYPE_PREFIX)) {
                    String prefix = path.substring(TYPE_PREFIX.length());
                    PrefixIndex idx = indexer.createPrefixIndex(prefix);
                    prefixIndexes.put(path, idx);
                } else if (path.startsWith(TYPE_PROPERTY)) {
                    String property = path.substring(TYPE_PROPERTY.length());
                    boolean unique = false;
                    if (property.endsWith("," + UNIQUE)) {
                        unique = true;
                        property = property.substring(0, property.length() - UNIQUE.length() - 1);
                    }
                    PropertyIndex idx = indexer.createPropertyIndex(property, unique);
                    propertyIndexes.put(path, idx);
                } else {
                    throw ExceptionFactory.get("Unknown index type: " + path);
                }
                break;
            case '-':
                throw ExceptionFactory.get("Removing indexes is not yet implemented");
            default:
                throw ExceptionFactory.get("token: " + (char) t.getTokenType());
            }
        }
        return null;
    }
View Full Code Here

        this.mk = MicroKernelWrapperBase.wrap(mk);
        // TODO security for the index mechanism

        String role = mk.getNodes("/:user/" + user, mk.getHeadRevision());
        NodeMap map = new NodeMap();
        JsopReader t = new JsopTokenizer(role);
        t.read('{');
        NodeImpl n = NodeImpl.parse(map, t, 0);
        String password = JsopTokenizer.decodeQuoted(n.getProperty("password"));
        if (!pass.equals(password)) {
            throw ExceptionFactory.get("Wrong password");
        }
View Full Code Here

    }

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

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.