Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONArray


        InputStream ins = new ByteArrayInputStream(json.getBytes(charSet));
        this.jsonReader.parse(ins, this.creator);
    }

    private JSONArray toJsonArray(String[] array) throws JSONException {
        return new JSONArray(Arrays.asList(array));
    }
View Full Code Here


    }

    public void testOnChange() throws Exception {
        res.onChange("modified", "argument1", "argument2");
        Object prop = res.getProperty("changes");
        JSONArray changes = assertInstanceOf(prop, JSONArray.class);
        assertEquals(1, changes.length());
        Object obj = changes.get(0);
        JSONObject change = assertInstanceOf(obj, JSONObject.class);
        assertEquals("modified", assertProperty(change, JSONResponse.PROP_TYPE, String.class));
        JSONArray arguments = assertProperty(change, JSONResponse.PROP_ARGUMENT, JSONArray.class);
        assertEquals(2, arguments.length());
    }
View Full Code Here

        }

        String[] mixinTypes = null;
        Object mixinsObject = obj.opt("jcr:mixinTypes");
        if (mixinsObject instanceof JSONArray) {
            JSONArray mixins = (JSONArray) mixinsObject;
            mixinTypes = new String[mixins.length()];
            for (int i = 0; i < mixins.length(); i++) {
                mixinTypes[i] = mixins.getString(i);
            }
        }

        contentCreator.createNode(name, primaryType, mixinTypes);

        // add properties and nodes
        JSONArray names = obj.names();
        for (int i = 0; names != null && i < names.length(); i++) {
            final String n = names.getString(i);
            // skip well known objects
            if (!ignoredNames.contains(n)) {
                Object o = obj.get(n);
                if (SECURITY_PRINCIPLES.equals(n)) {
                  this.createPrincipals(o, contentCreator);
View Full Code Here

    protected void createProperty(String name, Object value, ContentCreator contentCreator)
    throws JSONException, RepositoryException {
        // assume simple value
        if (value instanceof JSONArray) {
            // multivalue
            final JSONArray array = (JSONArray) value;
            if (array.length() > 0) {
                final String values[] = new String[array.length()];
                for (int i = 0; i < array.length(); i++) {
                    values[i] = array.get(i).toString();
                }
                final int propertyType = getType(name, array.get(0));
                contentCreator.createProperty(getName(name), propertyType, values);
            } else {
                contentCreator.createProperty(getName(name), PropertyType.STRING, new String[0]);
            }
View Full Code Here

      if (obj instanceof JSONObject) {
        //single principal
        createPrincipal((JSONObject)obj, contentCreator);
      } else if (obj instanceof JSONArray) {
        //array of principals
        JSONArray jsonArray = (JSONArray)obj;
        for (int i=0; i < jsonArray.length(); i++) {
          Object object = jsonArray.get(i);
          if (object instanceof JSONObject) {
              createPrincipal((JSONObject)object, contentCreator);
          } else {
            throw new JSONException("Unexpected data type in principals array: " + object.getClass().getName());
          }
View Full Code Here

      String name = json.getString("name");
      boolean isGroup = json.optBoolean("isgroup", false);

      //collect the extra property names to assign to the new principal
      Map<String, Object> extraProps = new LinkedHashMap<String, Object>();
    JSONArray names = json.names();
    for(int p=0; p < names.length(); p++) {
      String propName = names.getString(p);
      if (!ignoredPrincipalPropertyNames.contains(propName)) {
          Object value = json.get(propName);
          extraProps.put(propName, value);
      }
    }

      if (isGroup) {
        String [] members = null;
        JSONArray membersJSONArray = json.optJSONArray("members");
        if (membersJSONArray != null) {
          members = new String[membersJSONArray.length()];
          for (int i=0; i < membersJSONArray.length(); i++) {
            members[i] = membersJSONArray.getString(i);
          }
        }
        contentCreator.createGroup(name, members, extraProps);
      } else {
        String password = json.getString("password");
View Full Code Here

      if (obj instanceof JSONObject) {
        //single ace
        createAce((JSONObject)obj, contentCreator);
      } else if (obj instanceof JSONArray) {
        //array of aces
        JSONArray jsonArray = (JSONArray)obj;
        for (int i=0; i < jsonArray.length(); i++) {
          Object object = jsonArray.get(i);
          if (object instanceof JSONObject) {
              createAce((JSONObject)object, contentCreator);
          } else {
            throw new JSONException("Unexpected data type in acl array: " + object.getClass().getName());
          }
View Full Code Here

    protected void createAce(JSONObject ace, ContentCreator contentCreator)
    throws JSONException, RepositoryException {
    String principalID = ace.getString("principal");

    String [] grantedPrivileges = null;
    JSONArray granted = ace.optJSONArray("granted");
    if (granted != null) {
      grantedPrivileges = new String[granted.length()];
      for (int a=0; a < granted.length(); a++) {
        grantedPrivileges[a] = granted.getString(a);
      }
    }

    String [] deniedPrivileges = null;
    JSONArray denied = ace.optJSONArray("denied");
    if (denied != null) {
      deniedPrivileges = new String[denied.length()];
      for (int a=0; a < denied.length(); a++) {
        deniedPrivileges[a] = denied.getString(a);
      }
    }

    String order = ace.optString("order", null);
   
View Full Code Here

            } else {

                // Try multi-value "property"
                final String[] values = resource.adaptTo(String[].class);
                if (values != null) {
                    obj.put(resource.getName(), new JSONArray(Arrays.asList(values)));
                }

            }
            if ( resource.getResourceType() != null ) {
                obj.put("sling:resourceType", resource.getResourceType());
View Full Code Here

            } else {
                values = (Object[]) value;
            }
            // write out empty array
            if ( values.length == 0 ) {
                obj.put(key, new JSONArray());
                return;
            }
        }

        // special handling for binaries: we dump the length and not the data!
        if (value instanceof InputStream
            || (values != null && values[0] instanceof InputStream)) {
            // TODO for now we mark binary properties with an initial colon in
            // their name
            // (colon is not allowed as a JCR property name)
            // in the name, and the value should be the size of the binary data
            if (values == null) {
                obj.put(":" + key, getLength(valueMap, -1, key, (InputStream)value));
            } else {
                final JSONArray result = new JSONArray();
                for (int i = 0; i < values.length; i++) {
                    result.put(getLength(valueMap, i, key, (InputStream)values[i]));
                }
                obj.put(":" + key, result);
            }
            return;
        }

        if (!value.getClass().isArray()) {
            obj.put(key, getValue(value));
        } else {
            final JSONArray result = new JSONArray();
            for (Object v : values) {
                result.put(getValue(v));
            }
            obj.put(key, result);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.