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);
}
}
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();
}
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;
}
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;
}
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();
}
Aggregations