Search in sources :

Example 16 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project sling by apache.

the class ResourceTraversor method collectChildren.

/**
     * @param resource
     * @param currentLevel
     * @throws JsonException
     */
private void collectChildren(final Resource resource, final JsonObjectBuilder jsonObj) throws JsonException {
    final Iterator<Resource> children = resource.listChildren();
    while (children.hasNext()) {
        final Resource res = children.next();
        final JsonObjectBuilder json = collectResource(res, jsonObj);
        collectChildren(res, json);
    }
}
Also used : Resource(org.apache.sling.api.resource.Resource) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 17 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project jersey by jersey.

the class DocumentFilteringResource method filter.

@POST
public JsonArray filter(final JsonArray properties) {
    final JsonArrayBuilder documents = Json.createArrayBuilder();
    final List<JsonString> propertyList = properties.getValuesAs(JsonString.class);
    for (final JsonObject jsonObject : DocumentStorage.getAll()) {
        final JsonObjectBuilder documentBuilder = Json.createObjectBuilder();
        for (final JsonString property : propertyList) {
            final String key = property.getString();
            if (jsonObject.containsKey(key)) {
                documentBuilder.add(key, jsonObject.get(key));
            }
        }
        final JsonObject document = documentBuilder.build();
        if (!document.isEmpty()) {
            documents.add(document);
        }
    }
    return documents.build();
}
Also used : JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) JsonObjectBuilder(javax.json.JsonObjectBuilder) POST(javax.ws.rs.POST)

Example 18 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project visualee by Thomas-S-B.

the class GraphCreator method generateGraph.

public static Graph generateGraph(String fileName, String title, DependencyFilter filter, File outputdirectory) {
    id = 0;
    Graph graph = new Graph();
    graph.setName(fileName);
    File jsonFile = new File(outputdirectory.toString() + File.separatorChar + fileName + ".json");
    graph.setJsonFile(jsonFile);
    File htmlFile = new File(outputdirectory.toString() + File.separatorChar + fileName + ".html");
    graph.setHtmlFile(htmlFile);
    graph.setTitle(title);
    GraphConfigurator.configGraph(graph);
    JsonObjectBuilder builder = Json.createObjectBuilder();
    // Nodes
    JsonArrayBuilder nodesArray = buildJSONNodes(filter);
    builder.add("nodes", nodesArray);
    // Links
    JsonArrayBuilder linksArray = buildJSONLinks(filter);
    builder.add("links", linksArray);
    JsonObject json = builder.build();
    try (PrintStream ps = new PrintStream(graph.getJsonFile())) {
        ps.println(json.toString());
    } catch (FileNotFoundException ex) {
        LogProvider.getInstance().error("Didn't found file " + graph.getJsonFile().getName(), ex);
    }
    return graph;
}
Also used : PrintStream(java.io.PrintStream) Graph(de.strullerbaumann.visualee.ui.graph.entity.Graph) FileNotFoundException(java.io.FileNotFoundException) JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) File(java.io.File)

Example 19 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project visualee by Thomas-S-B.

the class GraphCreator method buildJSONLinks.

static JsonArrayBuilder buildJSONLinks(DependencyFilter filter) {
    JsonArrayBuilder linksArray = Json.createArrayBuilder();
    int value = 1;
    Set<JavaSource> relevantClasses = DependencyContainer.getInstance().getFilteredJavaSources(filter);
    for (JavaSource javaSource : relevantClasses) {
        for (Dependency d : DependencyContainer.getInstance().getDependencies(javaSource)) {
            DependencyType type = d.getDependencyType();
            if (filter == null || (relevantClasses.contains(d.getJavaSourceTo()) && filter.contains(type))) {
                int source = d.getJavaSourceFrom().getId();
                int target = d.getJavaSourceTo().getId();
                JsonObjectBuilder linksBuilder = Json.createObjectBuilder();
                if (DependencyType.isInverseDirection(type)) {
                    linksBuilder.add("source", source);
                    linksBuilder.add("target", target);
                } else {
                    linksBuilder.add("source", target);
                    linksBuilder.add("target", source);
                }
                linksBuilder.add("value", value);
                linksBuilder.add("type", type.toString());
                linksArray.add(linksBuilder);
            }
        }
    }
    return linksArray;
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) JsonArrayBuilder(javax.json.JsonArrayBuilder) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 20 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project CoreNLP by stanfordnlp.

the class ConstantsAndVariables method getLearnedWordsAsJson.

//  public Map<String, Counter<CandidatePhrase>> getLearnedWords() {
//    return Counters.flatten(learnedWordsEachIter);
//  }
//public void setLearnedWords(Counter<CandidatePhrase> words, String label) {
//  this.learnedWords.put(label, words);
//}
public String getLearnedWordsAsJson() {
    JsonObjectBuilder obj = Json.createObjectBuilder();
    for (String label : getLabels()) {
        Counter<CandidatePhrase> learnedWords = getLearnedWords(label);
        JsonArrayBuilder arr = Json.createArrayBuilder();
        for (CandidatePhrase k : learnedWords.keySet()) arr.add(k.getPhrase());
        obj.add(label, arr);
    }
    return obj.build().toString();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

JsonObjectBuilder (javax.json.JsonObjectBuilder)34 JsonArrayBuilder (javax.json.JsonArrayBuilder)21 Map (java.util.Map)11 JsonObject (javax.json.JsonObject)10 JsonException (javax.json.JsonException)7 HashMap (java.util.HashMap)6 StringWriter (java.io.StringWriter)5 ArrayList (java.util.ArrayList)5 List (java.util.List)3 Entry (java.util.Map.Entry)3 JsonValue (javax.json.JsonValue)3 JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)2 File (java.io.File)2 Privilege (javax.jcr.security.Privilege)2 JsonArray (javax.json.JsonArray)2 JsonString (javax.json.JsonString)2 Resource (org.apache.sling.api.resource.Resource)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 AttributeReference (com.torodb.core.language.AttributeReference)1 IndexType (com.torodb.core.model.IndexedAttributes.IndexType)1