Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONArray


        }

        String[] mixinTypes = null;
        Object mixinsObject = obj.opt("jcr:mixinTypes");
        if (mixinsObject instanceof JSONArray) {
            JSONArray mixins = (JSONArray) mixinsObject;
            mixinTypes = new String[mixins.length()];
            for (int i = 0; i < mixins.length(); i++) {
                mixinTypes[i] = mixins.getString(i);
            }
        }

        contentCreator.createNode(name, primaryType, mixinTypes);

        // add properties and nodes
        JSONArray names = obj.names();
        for (int i = 0; names != null && i < names.length(); i++) {
            final String n = names.getString(i);
            // skip well known objects
            if (!ignoredNames.contains(n)) {
                Object o = obj.get(n);
                if (o instanceof JSONObject) {
                    this.createNode(n, (JSONObject) o, contentCreator);
View Full Code Here


    protected void createProperty(String name, Object value, ContentCreator contentCreator)
    throws JSONException, RepositoryException {
        // assume simple value
        if (value instanceof JSONArray) {
            // multivalue
            final JSONArray array = (JSONArray) value;
            if (array.length() > 0) {
                final String values[] = new String[array.length()];
                for (int i = 0; i < array.length(); i++) {
                    values[i] = array.get(i).toString();
                }
                final int propertyType = getType(name, values[0]);
                contentCreator.createProperty(getName(name), propertyType, values);
            } else {
                contentCreator.createProperty(getName(name), PropertyType.STRING, new String[0]);
View Full Code Here

                task.getRcp().setNoOrdering(data.optBoolean(PARAM_NO_ORDERING, false));
                if (data.has(PARAM_THROTTLE)) {
                    task.getRcp().setThrottle(data.getLong(PARAM_THROTTLE));
                }
                if (data.has(PARAM_EXCLUDES)) {
                    JSONArray excludes = data.getJSONArray(PARAM_EXCLUDES);
                    for (int idx = 0; idx < excludes.length(); idx++) {
                        task.addExclude(excludes.getString(idx));
                    }
                }
                if (data.has(PARAM_RESUME_FROM)) {
                    task.getRcp().setResumeFrom(data.getString(PARAM_RESUME_FROM));
                }
View Full Code Here

        String cmd = obj.getString(COMMAND);
        Channel channel = ctx.channel();
        if (CMD_HELLO.equals(cmd)) {
            JSONObject result = new JSONObject();
            result.put(COMMAND, CMD_HELLO);
            JSONArray protocols = new JSONArray();
            protocols.put(PROTOCOL_VERSION_7);
            result.put(PROTOCOLS, protocols);
            result.put("serverName", "AEM Live Reload Server");

            channel.write(new TextWebSocketFrame(result.toString()));
View Full Code Here

    }

    private boolean isSupported(JSONObject obj) {
        try {
            if (obj.has(PROTOCOLS)) {
                JSONArray protocols = obj.getJSONArray(PROTOCOLS);
                for (int i = 0; i < protocols.length(); i++) {
                    String protocol = protocols.getString(i);
                    if (PROTOCOL_VERSION_7.equals(protocol)) {
                        return true;
                    }
                }
            }
View Full Code Here

        final String plan = firstRow.getValue("plan").getString();
        json.put("plan", plan);



        final JSONArray propertyIndexes = new JSONArray();

        final Matcher propertyMatcher = PROPERTY_INDEX_PATTERN.matcher(plan);
        /* Property Index */
        while (propertyMatcher.find()) {
            final String match = propertyMatcher.group(1);
            if (StringUtils.isNotBlank(match)) {
                propertyIndexes.put(StringUtils.stripToEmpty(match));
            }
        }

        if (propertyIndexes.length() > 0) {
            json.put("propertyIndexes", propertyIndexes);
        }

        final Matcher filterMatcher = FILTER_PATTERN.matcher(plan);
        if(filterMatcher.find()) {
            /* Filter (nodeType index) */

            propertyIndexes.put("nodeType");
            json.put("propertyIndexes", propertyIndexes);
            json.put("slow", true);
        }

        if (StringUtils.contains(plan, " /* traverse ")) {
View Full Code Here

        return json;
    }


    private JSONArray compositeQueryDataToJSON(Collection<CompositeData> queries) throws JSONException {
        final JSONArray jsonArray = new JSONArray();

        for (CompositeData query : queries) {
            Long duration = (Long) query.get("duration");
            Integer occurrenceCount = (Integer) query.get("occurrenceCount");
            String language = (String) query.get("language");
            String statement = (String) query.get("statement");

            if (!ArrayUtils.contains(LANGUAGES, language)) {
                // Not a supported language
                continue;
            } else if (StringUtils.startsWithIgnoreCase(statement, "EXPLAIN ")
                    || StringUtils.startsWithIgnoreCase(statement, "MEASURE ")) {
                // Don't show EXPLAIN or MEASURE queries
                continue;
            }

            final JSONObject json = new JSONObject();

            try {
                json.put("duration", duration);
                json.put("language", language);
                json.put("occurrenceCount", occurrenceCount);
                json.put("statement", statement);

                jsonArray.put(json);
            } catch (JSONException e) {
                log.warn("Could not add query to results [ {} ]", statement);
                continue;
            }
        }
View Full Code Here

        bucketSize = json.optInt("bucketSize", DEFAULT_BUCKET_SIZE);
        saveThreshold = json.optInt("saveThreshold", DEFAULT_SAVE_THRESHOLD);

        properties = new HashMap<String, Object>();

        JSONArray jsonArray = json.getJSONArray("properties");

        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.length(); i++) {
                final JSONObject item = jsonArray.getJSONObject(i);

                boolean isMulti = item.optBoolean("multi", false);
                String name = item.optString("name", "");

                if (StringUtils.isNotBlank(name)) {
View Full Code Here

    private void writeJsonResponse(final List<String> categories,
                                   final SlingHttpServletResponse response) throws JSONException, IOException {

        final JSONObject jsonObject = new JSONObject();

        jsonObject.put("categories", new JSONArray(categories));

        response.getWriter().print(jsonObject.toString());
    }
View Full Code Here

        // set up response stuff
        JSONObject jsonResponse = new JSONObject();
        int statusCode = 400;

        // initialize json collections for response
        JSONArray jsonStatusMessages = new JSONArray();
        JSONArray jsonNodes = new JSONArray();
        JSONArray jsonEdges = new JSONArray();

        // resolve given path
        ResourceResolver resourceResolver = request.getResourceResolver();
        Resource pageResource = resourceResolver.resolve(paramPagePath);

        // check if path resolved
        if(StringUtils.isNotBlank(paramPagePath) && !ResourceUtil.isNonExistingResource(pageResource)) {

            // get content node
            Resource jcrContentResource = pageResource.getChild(JcrConstants.JCR_CONTENT);

            // keep track of categories
            Set<String> categories = new HashSet<String>();

            try {

                // write components to JSON
                for (String resourceType : ComponentUtils.getNestedComponentTypes(jcrContentResource)) {

                    // get dependent component
                    DependentComponent dependentComponent =
                            dependentComponentManager.getDependentComponentForResourceType(resourceType).orNull();

                    if(dependentComponent != null) {

                        // found dependent component, write it to JSON
                        jsonNodes.put(DomainToJSONUtil.buildJsonComponent(dependentComponent));

                        // add all dependencies to categories list, add edges from component to categories
                        String componentResourceType = dependentComponent.getResourceType();
                        Set<String> dependencies = dependentComponent.getDependencies();
                        for(String dependency : dependencies) {

                            JSONObject jsonEdge =
                                    DomainToJSONUtil.buildJsonEdge(componentResourceType, dependency, EdgeType.DEPENDS_ON);
                            jsonEdges.put(jsonEdge);

                        }
                        categories.addAll(dependencies);

                    } else {

                        // this is not a dependent component (probably OOTB), write it to JSON with what info it has
                        jsonNodes.put(DomainToJSONUtil.buildJsonBareComponent(resourceType));

                    }

                }

                // get graph
                DependencyGraph<ClientLibrary> dependencyGraph
                        = clientLibraryRepository.getClientLibraryDependencyGraph(jcrContentResource);

                // write client libraries to JSON
                for (ClientLibrary clientLibrary : dependencyGraph.getNodes()) {

                    jsonNodes.put(DomainToJSONUtil.buildJsonLibrary(clientLibrary));

                    String clientLibraryPath = clientLibrary.getClientLibraryPath();

                    // add all categories to categories list, add edges from categories to this library
                    Set<String> memberOfCategories = clientLibrary.getCategories();
                    for(String category : memberOfCategories) {

                        JSONObject jsonEdge =
                                DomainToJSONUtil.buildJsonEdge(clientLibraryPath, category, EdgeType.MEMBER_OF);
                        jsonEdges.put(jsonEdge);

                    }
                    categories.addAll(memberOfCategories);

                    // add all dependencies to categories list, add edges from categories to libraries
                    List<String> dependencies = clientLibrary.getDependencies();
                    for(String dependency : dependencies) {

                        JSONObject jsonEdge =
                                DomainToJSONUtil.buildJsonEdge(clientLibraryPath, dependency, EdgeType.DEPENDS_ON);
                        jsonEdges.put(jsonEdge);

                    }
                    categories.addAll(dependencies);

                    // add all embeds to categories list, add edges from embeds to categories
                    List<String> embeds = clientLibrary.getEmbeddedCategories();
                    for(String embed : embeds) {

                        JSONObject jsonEdge =
                                DomainToJSONUtil.buildJsonEdge(clientLibraryPath, embed, EdgeType.EMBEDS);
                        jsonEdges.put(jsonEdge);

                    }
                    categories.addAll(embeds);

                }
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.json.JSONArray

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.