use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class SimpleTest method nodeAndPropertyNames.
@Test
public void nodeAndPropertyNames() {
DocumentMK mk = createMK();
String rev;
String nodes;
for (String s : new String[] { "_", "$", "__", "_id", "$x", ".", ".\\", "x\\", "\\x", "first.name" }) {
String x2 = Utils.escapePropertyName(s);
String s2 = Utils.unescapePropertyName(x2);
if (!s.equals(s2)) {
assertEquals(s, s2);
}
JsopBuilder jsop = new JsopBuilder();
jsop.tag('+').key(s).object().key(s).value("x").endObject();
rev = mk.commit("/", jsop.toString(), null, null);
nodes = mk.getNodes("/" + s, rev, 0, 0, 10, null);
jsop = new JsopBuilder();
jsop.object().key(s).value("x").key(":childNodeCount").value(0).endObject();
String n = jsop.toString();
assertEquals(n, nodes);
nodes = mk.getNodes("/", rev, 0, 0, 10, null);
jsop = new JsopBuilder();
jsop.object().key(s).object().endObject().key(":childNodeCount").value(1).endObject();
n = jsop.toString();
assertEquals(n, nodes);
jsop = new JsopBuilder();
jsop.tag('-').value(s);
rev = mk.commit("/", jsop.toString(), rev, null);
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class ClusterView method asJson.
/**
* Converts the provided parameters into the clusterview json that will be
* provided via JMX
**/
private String asJson(final long viewSeqNum, final boolean viewFinal, final String clusterId, final int localId, final Set<Integer> activeIds, final Set<Integer> deactivatingIds, final Set<Integer> inactiveIds) {
JsopBuilder builder = new JsopBuilder();
builder.object();
builder.key("seq").value(viewSeqNum);
builder.key("final").value(viewFinal);
builder.key("id").value(clusterId);
builder.key("me").value(localId);
builder.key("active").array();
for (Iterator<Integer> it = activeIds.iterator(); it.hasNext(); ) {
Integer anInstance = it.next();
builder.value(anInstance);
}
builder.endArray();
builder.key("deactivating").array();
for (Iterator<Integer> it = deactivatingIds.iterator(); it.hasNext(); ) {
Integer anInstance = it.next();
builder.value(anInstance);
}
builder.endArray();
builder.key("inactive").array();
for (Iterator<Integer> it = inactiveIds.iterator(); it.hasNext(); ) {
Integer anInstance = it.next();
builder.value(anInstance);
}
builder.endArray();
builder.endObject();
return builder.toString();
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class AbstractBlobStoreTest method addFiles.
public static String addFiles(BlobStore store, String dir) throws Exception {
ArrayList<String> list = new ArrayList<String>();
String root = new File(dir).getAbsolutePath();
String parent = new File(dir).getParentFile().getAbsolutePath();
addFiles(list, new File(root));
JsopBuilder listing = new JsopBuilder();
listing.object();
for (String f : list) {
FileInputStream in = new FileInputStream(f);
String id = store.writeBlob(in);
in.close();
String name = f.substring(parent.length());
listing.key(name).value(id);
listing.newline();
}
listing.endObject();
String l = listing.toString();
String id = store.writeBlob(new ByteArrayInputStream(l.getBytes("UTF-8")));
return id;
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class JsonIndexCommand method runQuery.
private void runQuery(String query, String language, String columnName, boolean quiet, int depth) throws RepositoryException {
ArrayList<String> list = new ArrayList<String>();
columnName = query.startsWith("explain") ? "plan" : columnName;
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(query, language);
for (String b : q.getBindVariableNames()) {
ValueFactory vf = session.getValueFactory();
q.bindValue(b, vf.createValue(data.get("$" + b).toString()));
}
QueryResult result = q.execute();
if (depth != 0) {
NodeIterator ni = result.getNodes();
JsopBuilder builder = new JsopBuilder().array();
while (ni.hasNext()) {
Node n = ni.nextNode();
builder.key(n.getPath());
appendNode(builder, n, depth - 1);
}
output.println(JsopBuilder.prettyPrint(builder.endArray().toString()));
return;
}
RowIterator ri = result.getRows();
while (ri.hasNext()) {
Row r = ri.nextRow();
if (columnName != null) {
String x = r.getValue(columnName).getString();
list.add(x);
if (!quiet) {
output.println(x);
}
} else {
String[] columnNames = result.getColumnNames();
for (String cn : columnNames) {
Value v = r.getValue(cn);
String x = v == null ? null : v.getString();
if (columnNames.length == 1) {
list.add(x);
if (!quiet) {
output.println(x);
}
} else {
list.add(x);
if (!quiet) {
output.println(cn + ": " + x);
}
}
}
}
}
data.put("$resultSize", (long) list.size());
data.put("$result", list.toArray(new String[0]));
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class LuceneJournalPropertyBuilder method buildAsString.
@Override
public String buildAsString() {
JsopWriter json = new JsopBuilder();
json.object();
for (Map.Entry<String, Collection<String>> e : indexedNodes.asMap().entrySet()) {
json.key(e.getKey()).array();
for (String v : e.getValue()) {
json.value(v);
}
json.endArray();
}
json.endObject();
return json.toString();
}
Aggregations