Package org.apache.jackrabbit.mk.json

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


        }
        return Iterables.transform(node.getPropertyNames(), new Function<String, PropertyState>() {
            @Override
            public PropertyState apply(String name) {
                String value = node.getProperty(name);
                JsopReader reader = new JsopTokenizer(value);
                if (reader.matches('[')) {
                    return readArrayProperty(name, reader);
                } else {
                    return readProperty(name, reader);
                }
            }
View Full Code Here


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

                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

            if (!isArray()) {
                throw new IllegalStateException("Scalar cannot be accessed as array");
            }

            List<Scalar> scalars = new ArrayList<Scalar>();
            JsopReader reader = new JsopTokenizer(value);
            reader.read('[');
            while (!reader.matches(']')) {
                scalars.add(readScalar(reader));
                reader.matches(',');
            }
            return scalars;
        }
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 == JsopTokenizer.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

    private synchronized void init() {
        if (properties == null) {
            String json = kernel.getNodes(
                    path, revision, 0, 0, MAX_CHILD_NODE_NAMES, null);

            JsopReader reader = new JsopTokenizer(json);
            reader.read('{');
            properties = new LinkedHashMap<String, PropertyState>();
            childNodes = new LinkedHashMap<String, NodeState>();
            do {
                String name = reader.readString();
                reader.read(':');
                if (":childNodeCount".equals(name)) {
                    childNodeCount =
                            Long.valueOf(reader.read(JsopTokenizer.NUMBER));
                } else if (reader.matches('{')) {
                    reader.read('}');
                    String childPath = path + '/' + name;
                    if ("/".equals(path)) {
                        childPath = '/' + name;
                    }
                    childNodes.put(name, new KernelNodeState(
                            kernel, childPath, revision));
                } else if (reader.matches(JsopTokenizer.NUMBER)) {
                    properties.put(name, new KernelPropertyState(
                            name, ScalarImpl.numberScalar(reader.getToken())));
                } else if (reader.matches(JsopTokenizer.STRING)) {
                    properties.put(name, new KernelPropertyState(
                            name, ScalarImpl.stringScalar(reader.getToken())));
                } else if (reader.matches(JsopTokenizer.TRUE)) {
                    properties.put(name, new KernelPropertyState(
                            name, ScalarImpl.booleanScalar(true)));
                } else if (reader.matches(JsopTokenizer.FALSE)) {
                    properties.put(name, new KernelPropertyState(
                            name, ScalarImpl.booleanScalar(false)));
                } else if (reader.matches('[')) {
                    properties.put(name, new KernelPropertyState(
                            name, readArray(reader)));
                } else {
                    throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
                }
            } while (reader.matches(','));
            reader.read('}');
            reader.read(JsopTokenizer.END);
        }
    }
View Full Code Here

        return buff;
    }

    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path) {
        rightsRevision = getHeadRevision();
        JsopReader diff = mk.diffStream(fromRevisionId, toRevisionId, path);
        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)) {
            throw ExceptionFactory.get("Node not found: " + path);
        }
        JsopReader t = mk.getNodesStream(path, revisionId, depth, offset, count, filter);
        if (admin) {
            return t;
        }
        t.read('{');
        NodeImpl n = NodeImpl.parse(map, t, 0);
        n = filterAccess(path, n);
        JsopStream buff = new JsopStream();
        if (n == null) {
            throw ExceptionFactory.get("Node not found: " + path);
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

            String head = mk.getHeadRevision();
            VirtualRepositoryWrapper vm = new VirtualRepositoryWrapper(mk);
            if (mk.nodeExists(MOUNT, head)) {
                String mounts = mk.getNodes(MOUNT, head);
                NodeMap map = new NodeMap();
                JsopReader t = new JsopTokenizer(mounts);
                t.read('{');
                NodeImpl n = NodeImpl.parse(map, t, 0);
                for (long pos = 0;; pos++) {
                    String childName = n.getChildNodeName(pos);
                    if (childName == null) {
                        break;
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.