Examples of JSONObject


Examples of org.apache.axis2.json.gson.factory.JsonObject

                process();
            } catch (IOException e) {
                throw new XMLStreamException("Error occours while write first begin object ");
            }
        }
        JsonObject stackObj = null;
        try {
            if (miniStack.isEmpty()) {
                if (!queue.isEmpty()) {
                    JsonObject queObj = queue.peek();
                    if (queObj.getName().equals(localName)) {
                        if (flushObject != null) {
                            if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY
                                    && flushObject.getName().equals(topNestedArrayObj.getName())) {
                                topNestedArrayObj = null;
                                processedJsonObjects.clear();
                            }
                            popStack();
                            writeEndJson(flushObject);
                            flushObject = null;
                        }

                        if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_ARRAY ||
                                queObj.getType() == JSONType.NESTED_OBJECT)) {
                            processedJsonObjects.push(queObj);
                        }
                        writeStartJson(queObj);
                        stack.push(queue.poll());
                    } else if (!stack.isEmpty()) {
                        stackObj = stack.peek();
                        if (stackObj.getName().equals(localName)) {
                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                                fillMiniStack(stackObj);
                                jsonWriter.beginObject();
                                processedJsonObjects.push(stackObj);
                            }
                            flushObject = null;
                        } else {
                            throw new XMLStreamException("Invalid Staring element");
                        }
                    }
                } else {
                    if (!stack.isEmpty()) {
                        stackObj = stack.peek();
                        if (stackObj.getName().equals(localName)) {
                            flushObject = null;
                            if (stackObj.getType() == JSONType.NESTED_ARRAY) {
                                fillMiniStack(stackObj);
                                jsonWriter.beginObject();
                                processedJsonObjects.push(stackObj);
                            }
                        } else {
                            throw new XMLStreamException("Invalid Staring element");
                        }
                    } else {
                        throw new XMLStreamException("Invalid Starting  element");
                    }
                }
            } else {
                JsonObject queObj = miniStack.peek();
                if (queObj.getName().equals(localName)) {
                    if (flushObject != null) {
                        popStack();
                        writeEndJson(flushObject);
                        flushObject = null;
                    }
                    if (topNestedArrayObj != null && (queObj.getType() == JSONType.NESTED_OBJECT
                            || queObj.getType() == JSONType.NESTED_ARRAY)) {
                        processedJsonObjects.push(queObj);
                    }
                    writeStartJson(queObj);
                    stack.push(miniStack.pop());
                } else if (!stack.isEmpty()) {
View Full Code Here

Examples of org.apache.chemistry.opencmis.commons.impl.json.JSONObject

    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

Examples of org.apache.cordova.json4j.JSONObject

  public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, "Device: Invalid action:" + action);

    if(action.equals(ACTION_GET_DEVICE_INFO)){
      try {
        JSONObject device = new JSONObject();
        device.put( FIELD_PLATFORM, new String(DeviceInfo.getPlatformVersion() ) );
        device.put( FIELD_UUID, new Integer( DeviceInfo.getDeviceId()) );
        device.put( FIELD_CORDOVA, "1.5.0" );
        device.put( FIELD_NAME, new String(DeviceInfo.getDeviceName()) );
        device.put( FIELD_VERSION, new String(DeviceInfo.getSoftwareVersion()) );
        result = new PluginResult(PluginResult.Status.OK, device);
      } catch (JSONException e) {
        result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
      }
    }
View Full Code Here

Examples of org.apache.jackrabbit.mk.json.JsonObject

    }
   
    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();
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.commons.json.JsonObject

    }
   
    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();
    }
View Full Code Here

Examples of org.apache.jena.atlas.json.JsonObject

        return this ;
    }
   
    private void parse(InputStream in)
    {
        JsonObject obj = JSON.parse(in) ;
       
        if ( obj.hasKey(kBoolean) )
        {
            checkContains(obj, true, true, kHead, kBoolean) ;
            booleanResult = obj.get(kBoolean).getAsBoolean().value() ;
            rows = null ;
            return ;
        }
       
        rows = new ArrayList<Binding>(1000) ;
       
        checkContains(obj, true, true, kHead, kResults) ;
       
        // process head
        if ( ! obj.get(kHead).isObject() )
            throw new ResultSetException("Key 'head' must have a JSON object as value: found: "+obj.get(kHead)) ;
        JsonObject head = obj.get(kHead).getAsObject() ;
       
        // ---- Head
        // -- Link - array.
        if ( head.hasKey(kLink) )
        {
            List<String> links = new ArrayList<String>() ;

            if ( head.get(kLink).isString() )
            {
                Log.warn(this, "Link field is a string, should be an array of strings") ;
                links.add(head.get(kLink).getAsString().value()) ;
            }
            else
            {
                if ( ! head.get(kLink).isArray() )
                    throw new ResultSetException("Key 'link' must have be an array: found: "+obj.get(kLink)) ;

                for ( JsonValue v : head.get(kLink).getAsArray() )
                {
                    if ( ! v.isString() )
                        throw new ResultSetException("Key 'link' must have be an array of strings: found: "+v) ;
                    links.add(v.getAsString().value()) ;
                }
            }
        }
        // -- Vars
        vars = parseVars(head) ;

        // ---- Results
        JsonObject results = obj.get(kResults).getAsObject() ;
        if ( ! results.get(kBindings).isArray() )
            throw new ResultSetException("'bindings' must be an array") ;
        JsonArray array = results.get(kBindings).getAsArray() ;
        Iterator<JsonValue> iter = array.iterator() ;
       
        for ( ; iter.hasNext() ; )
        {
            BindingMap b = BindingFactory.create() ;
            JsonValue v = iter.next() ;
            if ( ! v.isObject() )
                throw new ResultSetException("Entry in 'bindings' array must be an object {}";
            JsonObject x = v.getAsObject() ;
            Set<String> varNames = x.keys() ;
            for ( String vn : varNames )
            {
                //if ( ! vars.contains(vn) ) {}
                JsonValue vt = x.get(vn) ;
                if ( ! vt.isObject() )
                    throw new ResultSetException("Binding for variable '"+vn+"' is not a JSON object: "+vt;
                Node n = parseOneTerm(vt.getAsObject()) ;
                b.add(Var.alloc(vn), n) ;
            }
View Full Code Here

Examples of org.apache.openjpa.json.JSONObject

        if (sm == null) {
            return null;
        }
       
        boolean ref = !visited.add(sm);
        JSONObject root =  new JSONObject(typeOf(sm), sm.getObjectId(), ref);;
        if (ref) {
            return root;
        }
       
        BitSet loaded = sm.getLoaded();
        StoreContext ctx = (StoreContext)sm.getGenericContext();
        List<Attribute<?, ?>> attrs = MetamodelHelper.getAttributesInOrder(sm.getMetaData(), model);
           
        for (int i = 0; i < attrs.size(); i++) {
            FieldMetaData fmd = ((Members.Member<?, ?>) attrs.get(i)).fmd;
            if (!loaded.get(fmd.getIndex()))
                continue;
            Object value = sm.fetch(fmd.getIndex());
            switch (fmd.getDeclaredTypeCode()) {
                case JavaTypes.BOOLEAN:
                case JavaTypes.BYTE:
                case JavaTypes.CHAR:
                case JavaTypes.DOUBLE:
                case JavaTypes.FLOAT:
                case JavaTypes.INT:
                case JavaTypes.LONG:
                case JavaTypes.SHORT:

                case JavaTypes.BOOLEAN_OBJ:
                case JavaTypes.BYTE_OBJ:
                case JavaTypes.CHAR_OBJ:
                case JavaTypes.DOUBLE_OBJ:
                case JavaTypes.FLOAT_OBJ:
                case JavaTypes.INT_OBJ:
                case JavaTypes.LONG_OBJ:
                case JavaTypes.SHORT_OBJ:

                case JavaTypes.BIGDECIMAL:
                case JavaTypes.BIGINTEGER:
                case JavaTypes.DATE:
                case JavaTypes.NUMBER:
                case JavaTypes.CALENDAR:
                case JavaTypes.LOCALE:
                case JavaTypes.STRING:
                case JavaTypes.ENUM:
                         root.set(fmd.getName(),value);
                break;
               
                case JavaTypes.PC:
                    if (value == null) {
                        root.set(fmd.getName(), null);
                    } else {
                        root.set(fmd.getName(),encodeManagedInstance(ctx.getStateManager(value), visited,
                            indent+1, false, model));
                    }
                    break;
                   
                case JavaTypes.ARRAY:
                    Object[] values = (Object[])value;
                    value = Arrays.asList(values);
                // no break;
                case JavaTypes.COLLECTION:
                    if (value == null) {
                        root.set(fmd.getName(), null);
                        break;
                    }
                    Collection<?> members = (Collection<?>)value;
                    JSONObject.Array array = new JSONObject.Array();
                    root.set(fmd.getName(), array);
                    if (members.isEmpty()) {
                        break;
                    }
                    boolean basic = fmd.getElement().getTypeMetaData() == null;
                    for (Object o : members) {
                        if (o == null) {
                            array.add(null);
                        } else {
                            if (basic) {
                                array.add(o);
                            } else {
                                array.add(encodeManagedInstance(ctx.getStateManager(o), visited, indent+1, true,
                                    model));
                            }
                        }
                    }
                    break;
                case JavaTypes.MAP:
                    if (value == null) {
                        root.set(fmd.getName(), null);
                        break;
                    }
                    Set<Map.Entry> entries = ((Map)value).entrySet();
                    JSONObject.KVMap map = new JSONObject.KVMap();
                    root.set(fmd.getName(), map);
                    if (entries.isEmpty()) {
                        break;
                    }
                   
                    boolean basicKey   = fmd.getElement().getTypeMetaData() == null;
                    boolean basicValue = fmd.getValue().getTypeMetaData() == null;
                    for (Map.Entry<?,?> e : entries) {
                        Object k = e.getKey();
                        Object v = e.getValue();
                        if (!basicKey) {
                            k = encodeManagedInstance(ctx.getStateManager(k), visited, indent+1, true, model);
                        }
                        if (!basicValue) {
                            v = encodeManagedInstance(ctx.getStateManager(e.getValue()), visited,
                                indent+1, false, model);
                        }
                        map.put(k,v);
                    }
                    break;
                   
                case JavaTypes.INPUT_STREAM:
                case JavaTypes.INPUT_READER:
                    root.set(fmd.getName(), streamToString(value));
                    break;
                   
                case JavaTypes.PC_UNTYPED:
                case JavaTypes.OBJECT:
                case JavaTypes.OID:
                    root.set(fmd.getName(), "***UNSUPPORTED***");
            }
        }
        return root;
    }
View Full Code Here

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

                // SLING-2320: always allow enumeration of one's children;
                // DOS-limitation is for deeper traversals.
                if (count > maxResources && maxRecursionLevels != 1) {
                    return currentLevel;
                }
                final JSONObject json = collectResource(res, jsonObj);
                nextQueue.addLast(new Entry(res, json));
            }
        }

        while (!currentQueue.isEmpty() || !nextQueue.isEmpty()) {
View Full Code Here

Examples of org.apache.tapestry.json.JSONObject

        return _registration;
    }

    Object onActionFromJSON()
    {
        JSONObject response = new JSONObject();

        response.put("content", "Directly coded JSON content");

        return response;
    }
View Full Code Here

Examples of org.apache.tapestry5.json.JSONObject

        "class", "t-autocomplete-menu");
        writer.end();

        Link link = resources.createEventLink(EVENT_NAME);

        JSONObject config = new JSONObject();
        config.put("paramName", PARAM_NAME);
        config.put("indicator", loaderId);

        if (resources.isBound("minChars"))
            config.put("minChars", minChars);

        if (resources.isBound("frequency"))
            config.put("frequency", frequency);

        if (resources.isBound("tokens"))
        {
            for (int i = 0; i < tokens.length(); i++)
            {
                config.accumulate("tokens", tokens.substring(i, i + 1));
            }
        }

        // Let subclasses do more.
        configure(config);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.