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 BundledDocumentDifferTest method testDiff.
@Test
public void testDiff() throws Exception {
NodeBuilder builder = createContentStructure();
NodeState r1 = merge(store, builder);
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/jcr:content").setProperty("foo", "bar");
NodeState r2 = merge(store, builder);
JsopWriter w = new JsopBuilder();
String path = "/test";
assertTrue(differ.diff(dns(r1, path), dns(r2, path), w));
assertTrue(w.toString().isEmpty());
w = new JsopBuilder();
path = "/test/book.jpg";
assertFalse(differ.diff(dns(r1, path), dns(r2, path), w));
assertEquals("^\"jcr:content\":{}", w.toString());
builder = store.getRoot().builder();
childBuilder(builder, "/test/book.jpg/foo");
NodeState r3 = merge(store, builder);
w = new JsopBuilder();
path = "/test/book.jpg";
//As there is a non bundled child differ should return true to continue diffing
assertTrue(differ.diff(dns(r1, path), dns(r3, path), w));
assertEquals("^\"jcr:content\":{}", w.toString());
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class IndexDefinitionPrinter method print.
@Override
public void print(PrintWriter printWriter, Format format, boolean isZip) {
if (format == Format.JSON) {
NodeState root = nodeStore.getRoot();
JsopWriter json = new JsopBuilder();
json.object();
for (String indexPath : indexPathService.getIndexPaths()) {
json.key(indexPath);
NodeState idxState = NodeStateUtils.getNode(root, indexPath);
NodeStateJsonUtils.copyAsJson(json, idxState, false);
}
json.endObject();
printWriter.print(JsopBuilder.prettyPrint(json.toString()));
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class RandomizedClusterTest method normalize.
private static String normalize(String json) {
JsopTokenizer t = new JsopTokenizer(json);
t.read('{');
JsonObject o = JsonObject.create(t);
JsopBuilder w = new JsopBuilder();
o.toJson(w);
return w.toString();
}
use of org.apache.jackrabbit.oak.commons.json.JsopBuilder in project jackrabbit-oak by apache.
the class SimpleTest method escapeUnescape.
@Test
public void escapeUnescape() {
DocumentMK mk = createMK();
String rev;
String nodes;
Random r = new Random(1);
for (int i = 0; i < 20; i++) {
int len = 1 + r.nextInt(5);
StringBuilder buff = new StringBuilder();
for (int j = 0; j < len; j++) {
buff.append((char) (32 + r.nextInt(128)));
}
String s = buff.toString();
String x2 = Utils.escapePropertyName(s);
String s2 = Utils.unescapePropertyName(x2);
if (!s.equals(s2)) {
assertEquals(s, s2);
}
if (s.indexOf('/') >= 0) {
continue;
}
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, 100, 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, 100, 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);
}
}
Aggregations