Package org.json.simple

Examples of org.json.simple.JSONObject


  
   /*
    * Example how parse json return session
    */
      Object objSessionJson = JSONValue.parse( ApiAuthRest.getRequestGet("session"));
       JSONObject jsonObjectSessionJson= (JSONObject) objSessionJson;
       String sessionId = (String) jsonObjectSessionJson.get("sessionId");
       Boolean authenticated = (Boolean) jsonObjectSessionJson.get("authenticated");
       System.out.println("Session:"+sessionId+" Authenticated:"+authenticated);
      
      System.out.println("########################");
      System.out.println("Search the persons that have name  JOHN");
      Object obj = JSONValue.parse( ApiAuthRest.getRequestGet("person?q=john"));
       JSONObject jsonObject = (JSONObject) obj;
       JSONArray arrayResult = (JSONArray) jsonObject.get("results");
       /*
        * Leemo primera posicion
        */
       System.out.println("########################");
       int largoArray = arrayResult.size();
       int contador;
       for(contador=0; contador < largoArray; contador ++){
         JSONObject registro = (JSONObject) arrayResult.get(contador);
         String uuid = (String) registro.get("uuid");
         String display = (String) registro.get("display");
         System.out.println("Rows "+ contador + " => Result Persons UUID:" + uuid +" Display:"+display);
        
         //Show ROWS LINKS
         JSONArray arrayResultLinks = (JSONArrayregistro.get("links");
         int largoArrayLinks = arrayResultLinks.size();
           int contadorLinks;
          for(contadorLinks=0; contadorLinks < largoArrayLinks; contadorLinks ++){
            JSONObject registroLink = (JSONObject) arrayResultLinks.get(contadorLinks);
             String uri = (String) registroLink.get("uri");
             String rel = (String) registroLink.get("rel");
             System.out.println("==>Record Row "+ contador + "."+ contadorLinks
                   +" =>  URI:" + uri +" REL:"+rel);
                       
          }
          System.out.println("########################");
View Full Code Here


    public static JSONObject convert(RepositoryInfo repositoryInfo, HttpServletRequest request) {
        if (repositoryInfo == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        result.put(REPINFO_ID, repositoryInfo.getId());
        result.put(REPINFO_NAME, repositoryInfo.getName());
        result.put(REPINFO_DESCRIPTION, repositoryInfo.getDescription());
        result.put(REPINFO_VENDOR, repositoryInfo.getVendorName());
        result.put(REPINFO_PRODUCT, repositoryInfo.getProductName());
        result.put(REPINFO_PRODUCT_VERSION, repositoryInfo.getProductVersion());
        result.put(REPINFO_ROOT_FOLDER_ID, repositoryInfo.getRootFolderId());
        result.put(REPINFO_CAPABILITIES, convert(repositoryInfo.getCapabilities()));
        result.put(REPINFO_ACL_CAPABILITIES, convert(repositoryInfo.getAclCapabilities()));
        result.put(REPINFO_CHANGE_LOCK_TOKEN, repositoryInfo.getLatestChangeLogToken());
        result.put(REPINFO_CMIS_VERSION_SUPPORTED, repositoryInfo.getCmisVersionSupported());
        result.put(REPINFO_THIN_CLIENT_URI, repositoryInfo.getThinClientUri());
        result.put(REPINFO_CHANGES_INCOMPLETE, repositoryInfo.getChangesIncomplete());

        if (repositoryInfo.getChangesOnType() != null) {
            JSONArray changesOnType = new JSONArray();

            for (BaseTypeId type : repositoryInfo.getChangesOnType()) {
                changesOnType.add(getJSONStringValue(type));
            }

            result.put(REPINFO_CHANGES_ON_TYPE, changesOnType);
        }

        result.put(REPINFO_PRINCIPAL_ID_ANONYMOUS, repositoryInfo.getPrincipalIdAnonymous());
        result.put(REPINFO_PRINCIPAL_ID_ANYONE, repositoryInfo.getPrincipalIdAnyone());

        result.put(REPINFO_REPOSITORY_URL, BrowserBindingUtils.compileRepositoryUrl(request, repositoryInfo.getId())
                .toString());
        result.put(REPINFO_ROOT_FOLDER_URL, BrowserBindingUtils.compileRootUrl(request, repositoryInfo.getId())
                .toString());

        return result;
    }
View Full Code Here

    public static JSONObject convert(RepositoryCapabilities capabilities) {
        if (capabilities == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        result.put(JSON_CAP_CONTENT_STREAM_UPDATES, getJSONStringValue(capabilities.getContentStreamUpdatesCapability()
                .value()));
        result.put(JSON_CAP_CHANGES, getJSONStringValue(capabilities.getChangesCapability().value()));
        result.put(JSON_CAP_RENDITIONS, getJSONStringValue(capabilities.getRenditionsCapability().value()));
        result.put(JSON_CAP_GET_DESCENDANTS, capabilities.isGetDescendantsSupported());
        result.put(JSON_CAP_GET_FOLDER_TREE, capabilities.isGetFolderTreeSupported());
        result.put(JSON_CAP_MULTIFILING, capabilities.isMultifilingSupported());
        result.put(JSON_CAP_UNFILING, capabilities.isUnfilingSupported());
        result.put(JSON_CAP_VERSION_SPECIFIC_FILING, capabilities.isVersionSpecificFilingSupported());
        result.put(JSON_CAP_PWC_SEARCHABLE, capabilities.isPwcSearchableSupported());
        result.put(JSON_CAP_PWC_UPDATABLE, capabilities.isPwcUpdatableSupported());
        result.put(JSON_CAP_ALL_VERSIONS_SEARCHABLE, capabilities.isAllVersionsSearchableSupported());
        result.put(JSON_CAP_QUERY, getJSONStringValue(capabilities.getQueryCapability().value()));
        result.put(JSON_CAP_JOIN, getJSONStringValue(capabilities.getJoinCapability().value()));
        result.put(JSON_CAP_ACL, getJSONStringValue(capabilities.getAclCapability().value()));

        return result;
    }
View Full Code Here

    public static JSONObject convert(AclCapabilities capabilities) {
        if (capabilities == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        result.put(JSON_ACLCAP_SUPPORTED_PERMISSIONS,
                getJSONStringValue(capabilities.getSupportedPermissions().value()));
        result.put(JSON_ACLCAP_ACL_PROPAGATION, getJSONStringValue(capabilities.getAclPropagation().value()));

        // permissions
        if (capabilities.getPermissions() != null) {
            JSONArray permissions = new JSONArray();

            for (PermissionDefinition permDef : capabilities.getPermissions()) {
                JSONObject permission = new JSONObject();
                permission.put(JSON_ACLCAP_PERMISSION_PERMISSION, permDef.getId());
                permission.put(JSON_ACLCAP_PERMISSION_DESCRIPTION, permDef.getDescription());

                permissions.add(permission);
            }

            result.put(JSON_ACLCAP_PERMISSIONS, permissions);
        }

        // permission mapping

        if (capabilities.getPermissionMapping() != null) {
            JSONArray permissionMapping = new JSONArray();

            for (PermissionMapping permMap : capabilities.getPermissionMapping().values()) {
                JSONArray mappingPermissions = new JSONArray();
                if (permMap.getPermissions() != null) {
                    for (String p : permMap.getPermissions()) {
                        mappingPermissions.add(p);
                    }
                }

                JSONObject mapping = new JSONObject();
                mapping.put(JSON_ACLCAP_MAPPING_KEY, permMap.getKey());
                mapping.put(JSON_ACLCAP_MAPPING_PERMISSION, mappingPermissions);

                permissionMapping.add(mapping);
            }

            result.put(JSON_ACLCAP_PERMISSION_MAPPING, permissionMapping);
View Full Code Here

    public static JSONObject convert(ObjectData object, TypeCache typeCache) {
        if (object == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        // properties
        if (object.getProperties() != null) {
            JSONObject properties = new JSONObject();

            for (PropertyData<?> property : object.getProperties().getPropertyList()) {
                TypeDefinition type = null;
                if (typeCache != null) {
                    type = typeCache.getTypeDefinitionForObject(object.getId());
                }

                PropertyDefinition<?> propDef = null;
                if (type != null) {
                    propDef = type.getPropertyDefinitions().get(property.getId());
                }

                properties.put(property.getId(), convert(property, propDef));
            }

            result.put(JSON_OBJECT_PROPERTIES, properties);
        }

        // allowable actions
        if (object.getAllowableActions() != null) {
            result.put(JSON_OBJECT_ALLOWABLE_ACTIONS, convert(object.getAllowableActions()));
        }

        // relationships
        if (object.getRelationships() != null) {
            JSONArray relationships = new JSONArray();

            for (ObjectData relationship : object.getRelationships()) {
                relationships.add(convert(relationship, typeCache));
            }

            result.put(JSON_OBJECT_RELATIONSHIPS, relationships);
        }

        // change event info
        if (object.getChangeEventInfo() != null) {
            JSONObject changeEventInfo = new JSONObject();

            ChangeEventInfo cei = object.getChangeEventInfo();
            changeEventInfo.put(JSON_CHANGE_EVENT_TYPE, getJSONStringValue(cei.getChangeType().value()));
            changeEventInfo.put(JSON_CHANGE_EVENT_TIME, getJSONValue(cei.getChangeTime()));

            result.put(JSON_OBJECT_CHANGE_EVENT_INFO, changeEventInfo);
        }

        // ACL
View Full Code Here

    public static JSONObject convert(PropertyData<?> property, PropertyDefinition<?> propDef) {
        if (property == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        result.put(JSON_PROPERTY_ID, property.getId());
        result.put(JSON_PROPERTY_LOCALNAME, property.getLocalName());
        result.put(JSON_PROPERTY_DISPLAYNAME, property.getDisplayName());
        result.put(JSON_PROPERTY_QUERYNAME, property.getQueryName());

        if (propDef != null) {
            result.put(JSON_PROPERTY_DATATYPE, propDef.getPropertyType().value());
            result.put(JSON_PROPERTY_CARDINALITY, propDef.getCardinality().value());

            if ((property.getValues() == null) || (property.getValues().size() == 0)) {
                result.put(JSON_PROPERTY_VALUE, null);
            } else if (propDef.getCardinality() == Cardinality.SINGLE) {
                result.put(JSON_PROPERTY_VALUE, getJSONValue(property.getValues().get(0)));
            } else {
                JSONArray values = new JSONArray();

                for (Object value : property.getValues()) {
                    values.add(getJSONValue(value));
                }

                result.put(JSON_PROPERTY_VALUE, values);
            }
        } else {
            result.put(JSON_PROPERTY_DATATYPE, getJSONPropertyDataType(property));

            if ((property.getValues() == null) || (property.getValues().size() == 0)) {
                result.put(JSON_PROPERTY_VALUE, null);
            } else if (property.getValues().size() == 1) {
                JSONArray values = new JSONArray();

                for (Object value : property.getValues()) {
                    values.add(getJSONValue(value));
                }

                result.put(JSON_PROPERTY_VALUE, values);
            }
        }

        return result;
    }
View Full Code Here

    public static JSONObject convert(AllowableActions allowableActions) {
        if (allowableActions == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        Set<Action> actionSet = allowableActions.getAllowableActions();
        for (Action action : Action.values()) {
            result.put(action.value(), actionSet.contains(action));
        }

        return result;
    }
View Full Code Here

                for (String p : ace.getPermissions()) {
                    permissions.add(p);
                }
            }

            JSONObject aceObject = new JSONObject();
            JSONObject principalObjecy = new JSONObject();
            principalObjecy.put(JSON_ACE_PRINCIPAL_ID, ace.getPrincipalId());
            aceObject.put(JSON_ACE_PRINCIPAL, principalObjecy);
            aceObject.put(JSON_ACE_PERMISSIONS, permissions);
            aceObject.put(JSON_ACE_IS_DIRECT, ace.isDirect());

            aceObjects.add(aceObject);
        }

        JSONObject result = new JSONObject();
        result.put(JSON_ACL_ACES, aceObjects);
        result.put(JSON_ACL_IS_EXACT, acl.isExact());

        return result;
    }
View Full Code Here

    public static JSONObject convert(RenditionData rendition) {
        if (rendition == null) {
            return null;
        }

        JSONObject result = new JSONObject();

        result.put(JSON_RENDITION_STREAM_ID, rendition.getStreamId());
        result.put(JSON_RENDITION_MIMETYPE, rendition.getMimeType());
        result.put(JSON_RENDITION_LENGTH, rendition.getBigLength());
        result.put(JSON_RENDITION_KIND, rendition.getKind());
        result.put(JSON_RENDITION_TITLE, rendition.getTitle());
        result.put(JSON_RENDITION_HEIGHT, rendition.getBigHeight());
        result.put(JSON_RENDITION_WIDTH, rendition.getBigWidth());
        result.put(JSON_RENDITION_DOCUMENT_ID, rendition.getRenditionDocumentId());

        return result;
    }
View Full Code Here

    /**
     * Converts a query object list.
     */
    @SuppressWarnings("unchecked")
    public static JSONObject convert(ObjectList list) {
        JSONObject result = new JSONObject();

        if (list != null) {
            JSONArray objects = new JSONArray();
            if (list.getObjects() != null) {
                for (ObjectData object : list.getObjects()) {
                    objects.add(convert(object, null));
                }
            }

            result.put(JSON_OBJECTLIST_OBJECTS, objects);

            if (list.hasMoreItems() != null) {
                result.put(JSON_OBJECTLIST_HAS_MORE_ITEMS, list.hasMoreItems());
            }
            if (list.getNumItems() != null) {
                result.put(JSON_OBJECTLIST_NUM_ITEMS, list.getNumItems());
            }
        }

        return result;
    }
View Full Code Here

TOP

Related Classes of org.json.simple.JSONObject

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.