use of javax.json.JsonArray in project sling by apache.
the class JsonReader method createNode.
protected void createNode(String name, JsonObject obj, ContentCreator contentCreator) throws RepositoryException {
String primaryType = obj.getString("jcr:primaryType", null);
String[] mixinTypes = null;
Object mixinsObject = obj.get("jcr:mixinTypes");
if (mixinsObject instanceof JsonArray) {
JsonArray mixins = (JsonArray) mixinsObject;
mixinTypes = new String[mixins.size()];
for (int i = 0; i < mixinTypes.length; i++) {
mixinTypes[i] = mixins.getString(i);
}
}
contentCreator.createNode(name, primaryType, mixinTypes);
writeChildren(obj, contentCreator);
contentCreator.finishNode();
}
use of javax.json.JsonArray in project sling by apache.
the class JsonReader method createPrincipal.
/**
* Create or update a user or group
*/
private void createPrincipal(JsonObject json, ContentCreator contentCreator) throws RepositoryException {
//create a principal
String name = json.getString("name");
boolean isGroup = json.getBoolean("isgroup", false);
//collect the extra property names to assign to the new principal
Map<String, Object> extraProps = new LinkedHashMap<String, Object>();
for (Map.Entry<String, JsonValue> entry : json.entrySet()) {
String propName = entry.getKey();
if (!ignoredPrincipalPropertyNames.contains(propName)) {
Object value = unbox(entry.getValue());
extraProps.put(propName, value);
}
}
if (isGroup) {
String[] members = null;
JsonArray membersJSONArray = (JsonArray) json.get("members");
if (membersJSONArray != null) {
members = new String[membersJSONArray.size()];
for (int i = 0; i < members.length; i++) {
members[i] = membersJSONArray.getString(i);
}
}
contentCreator.createGroup(name, members, extraProps);
} else {
String password = json.getString("password");
contentCreator.createUser(name, password, extraProps);
}
}
use of javax.json.JsonArray in project sling by apache.
the class JsonRenderer method valueToString.
/**
* Make a JSON text of an Object value.
* <p>
* Warning: This method assumes that the data structure is acyclical.
* @param value The value to be serialized.
* @return a printable, displayable, transmittable
* representation of the object, beginning
* with <code>{</code> <small>(left brace)</small> and ending
* with <code>}</code> <small>(right brace)</small>.
* @throws JSONException If the value is or contains an invalid number.
*/
public String valueToString(Object value) {
// TODO call the other valueToString instead
if (value == null || value.equals(null)) {
return "null";
}
if (value instanceof JsonString) {
quote(((JsonString) value).getString());
}
if (value instanceof Number) {
return numberToString((Number) value);
}
if (value instanceof Boolean) {
return value.toString();
}
if (value instanceof JsonObject || value instanceof JsonArray) {
StringWriter writer = new StringWriter();
Json.createGenerator(writer).write((JsonValue) value).close();
return writer.toString();
}
return quote(value.toString());
}
use of javax.json.JsonArray in project opentheso by miledrousset.
the class SelectedTerme method majNoticeBdd.
private void majNoticeBdd() {
// ResourceBundle bundlePref = getBundlePref();
// st.getTaskResultSet().getFragmentCount();
nbNotices = 0;
urlNotice = user.getNodePreference().getUrlBdd();
if (user.getNodePreference().isBddUseId()) {
urlNotice = urlNotice.replace("##value##", idC);
} else {
urlNotice = urlNotice.replace("##value##", nom);
}
// récupération du total des notices
String urlCounterBdd = user.getNodePreference().getUrlCounterBdd();
urlCounterBdd = urlCounterBdd.replace("##conceptId##", idC);
// urlCounterBdd = "http://healthandco.test.o2sources.com/concept/40/total";
// exemple des données récupérées
// "{\"content\":[{\"nb_notices\":\"s7\"}],\"debug\":\"\",\"error\":0}\" ";
// {"content":[{"nb_notices":"7"}],"debug":"","error":0}
URL url;
try {
url = new URL(urlCounterBdd);
InputStream is = url.openStream();
JsonReader reader = Json.createReader(is);
JsonObject totalNotices = reader.readObject();
reader.close();
JsonArray values = totalNotices.getJsonArray("content");
String name;
for (int i = 0; i < values.size(); i++) {
JsonObject item = values.getJsonObject(i);
try {
name = item.getString("nb_notices");
if (name != null) {
if (!name.isEmpty())
nbNotices = Integer.parseInt(name);
}
} catch (JsonException e) {
System.out.println(e.toString());
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
} catch (MalformedURLException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
}
// try {
// urlNotice = URLEncoder.encode(urlNotice);
// } catch (UnsupportedEncodingException ex) {
// Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
// }
}
use of javax.json.JsonArray in project cxf by apache.
the class JsrJsonpProviderTest method testReadJsonArray.
@Test
public void testReadJsonArray() throws Exception {
final StringWriter writer = new StringWriter();
Json.createGenerator(writer).writeStartArray().write("Tom").write("Tommyknocker").writeEnd().close();
final JsonStructure obj = provider.readFrom(JsonStructure.class, null, null, null, null, new ByteArrayInputStream(writer.toString().getBytes()));
assertThat(obj, instanceOf(JsonArray.class));
assertThat(((JsonArray) obj).getString(0), equalTo("Tom"));
assertThat(((JsonArray) obj).getString(1), equalTo("Tommyknocker"));
assertThat(((JsonArray) obj).size(), equalTo(2));
}
Aggregations