use of org.apache.jackrabbit.oak.commons.json.JsopTokenizer in project jackrabbit-oak by apache.
the class FacetResult method parseJson.
private void parseJson(String dimension, String jsonFacetString) {
JsopTokenizer jsopTokenizer = new JsopTokenizer(jsonFacetString);
List<Facet> facets = new LinkedList<Facet>();
int c;
String label = null;
int count;
while ((c = jsopTokenizer.read()) != JsopReader.END) {
if (JsopReader.STRING == c) {
label = jsopTokenizer.getEscapedToken();
} else if (JsopReader.NUMBER == c) {
count = Integer.parseInt(jsopTokenizer.getEscapedToken());
if (label != null) {
facets.add(new Facet(label, count));
}
label = null;
}
}
perDimFacets.put(dimension, facets);
}
use of org.apache.jackrabbit.oak.commons.json.JsopTokenizer in project jackrabbit-oak by apache.
the class QueryTest method parseJson.
private static JsonObject parseJson(String json) {
JsopTokenizer t = new JsopTokenizer(json);
t.read('{');
return JsonObject.create(t);
}
use of org.apache.jackrabbit.oak.commons.json.JsopTokenizer in project jackrabbit-oak by apache.
the class JsonIndexCommand method execute.
void execute(String command) throws RepositoryException {
JsopTokenizer t = new JsopTokenizer(command);
t.read('{');
JsonObject json = JsonObject.create(t);
Map<String, String> properties = json.getProperties();
if (properties.containsKey("if")) {
Object value = getValueOrVariable(properties.get("if"));
Object equals = getValueOrVariable(properties.get("="));
if (value == null) {
if (equals != null) {
return;
}
} else if (!value.equals(equals)) {
return;
}
}
for (Entry<String, String> e : properties.entrySet()) {
String k = e.getKey();
Object value = getValueOrVariable(e.getValue());
if ("addNode".equals(k)) {
String nodePath = value.toString();
String parent = PathUtils.getParentPath(nodePath);
if (session.nodeExists(parent)) {
Node p = session.getNode(parent);
String nodeName = PathUtils.getName(nodePath);
if (!p.hasNode(nodeName)) {
JsonObject node = json.getChildren().get("node");
addNode(p, nodeName, node);
}
}
} else if ("removeNode".equals(k)) {
String path = value.toString();
if (session.nodeExists(path)) {
session.getNode(path).remove();
}
} else if ("setProperty".equals(k)) {
String itemPath = value.toString();
String nodePath = PathUtils.getParentPath(itemPath);
if (session.nodeExists(nodePath)) {
String propertyName = PathUtils.getName(itemPath);
Object propertyValue = getValueOrVariable(properties.get("value"));
setProperty(session.getNode(nodePath), propertyName, propertyValue);
}
} else if ("session".equals(k)) {
if ("save".equals(value)) {
session.save();
}
} else if ("xpath".equals(k) || "sql".equals(k)) {
String language = "xpath".equals(k) ? k : Query.JCR_SQL2;
String columnName = "xpath".equals(k) ? "jcr:path" : null;
boolean quiet = properties.containsKey("quiet");
int depth = properties.containsKey("depth") ? Integer.parseInt(properties.get("depth")) : 0;
runQuery(value.toString(), language, columnName, quiet, depth);
} else if ("print".equals(k)) {
output.println(value);
} else if ("for".equals(k)) {
String name = JsopTokenizer.decodeQuoted(properties.get(k));
Object old = data.get(name);
String[] commands = (String[]) getValueOrVariable(properties.get("do"));
for (String x : (String[]) value) {
data.put(name, x);
for (String c : commands) {
execute(c);
}
}
data.put(name, old);
} else if ("loop".equals(k)) {
while (true) {
for (String c : (String[]) value) {
execute(c);
if (data.remove("$break") != null) {
return;
}
}
}
} else if (k.startsWith("$")) {
setVariable(properties, k, value);
}
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopTokenizer in project jackrabbit-oak by apache.
the class DocumentNodeStoreHelper method loadValue.
private static void loadValue(String v, java.util.Collection<Blob> blobs, DocumentNodeStore nodeStore) {
JsopReader reader = new JsopTokenizer(v);
PropertyState p;
if (reader.matches('[')) {
p = DocumentPropertyState.readArrayProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARIES) {
for (int i = 0; i < p.count(); i++) {
Blob b = p.getValue(Type.BINARY, i);
blobs.add(b);
}
}
} else {
p = DocumentPropertyState.readProperty("x", nodeStore, reader);
if (p.getType() == Type.BINARY) {
Blob b = p.getValue(Type.BINARY);
blobs.add(b);
}
}
}
use of org.apache.jackrabbit.oak.commons.json.JsopTokenizer in project jackrabbit-oak by apache.
the class LuceneJournalPropertyBuilder method addSerializedProperty.
//~---------------------------------< deserialize >
@Override
public void addSerializedProperty(@Nullable String json) {
if (json == null || json.isEmpty()) {
return;
}
//TODO Add support for overflow
JsopReader reader = new JsopTokenizer(json);
reader.read('{');
if (!reader.matches('}')) {
do {
String path = reader.readString();
reader.read(':');
reader.read('[');
for (boolean first = true; !reader.matches(']'); first = false) {
if (!first) {
reader.read(',');
}
if (sizeWithinLimits()) {
indexedNodes.put(path, reader.readString());
}
}
} while (reader.matches(','));
reader.read('}');
}
reader.read(JsopReader.END);
}
Aggregations