Package org.json

Examples of org.json.JSONWriter


    private void writeJSON(final PrintWriter pw) throws IOException {
        final Set<Group> groups = groupManager.listAllGroups();
        final Set<Node> nodes = clusterManager.listNodes();

        final JSONWriter jw = new JSONWriter(pw);

        try {
            jw.object();
            jw.key("status");
            jw.value(getStatusLine(groups, nodes));
            jw.key("groups");
            jw.array();
            for (Group g : groups) {
                jw.object();
                jw.key("name");
                jw.value(g.getName());

                Set<Node> members = g.getMembers();
                jw.key("members");
                jw.array();
                if (nodes != null) {
                    for (Node n : members) {
                        jw.object();
                        jw.key("id");
                        jw.value(n.getId());
                        jw.endObject();
                    }
                }

                jw.endArray();
                jw.key("actions");
                jw.array();
                boolean enable = true;
                action(jw, enable, "removeNode", "Remove Node", "update");
                action(jw, enable, "deleteGroup", "Delete Group", "delete");
                jw.endArray();
                jw.endObject();
            }
            jw.endArray();
            jw.endObject();
        } catch (JSONException je) {
            throw new IOException(je.toString());
        }
    }
View Full Code Here


            bundles = allBundles;
        }

        Util.sort( bundles, locale );

        final JSONWriter jw = new JSONWriter( pw );

        try
        {
            jw.object();

            if (null != be)
            {
                final StringWriter s = new StringWriter();
                final Throwable t = be.getNestedException() != null ? be.getNestedException() : be;
                t.printStackTrace( new PrintWriter(s) );
                jw.key( "error" );
                jw.value( s.toString() );
            }

            jw.key( "status" );
            jw.value( statusLine );

            // add raw status
            jw.key( "s" );
            jw.array();
            for ( int i = 0; i < 5; i++ ) jw.value(status[i]);
            jw.endArray();

            jw.key( "data" );

            jw.array();

            for ( int i = 0; i < bundles.length; i++ )
            {
                bundleInfo( jw, bundles[i], fullDetails || bundle != null, pluginRoot, servicesRoot, locale );
            }

            jw.endArray();

            jw.endObject();

        }
        catch ( JSONException je )
        {
            throw new IOException( je.toString() );
View Full Code Here

    void printConfigurationJson( PrintWriter pw, String pid, Configuration config, String pidFilter,
        String locale )
    {

        JSONWriter result = new JSONWriter( pw );

        if ( pid != null )
        {
            try
            {
                result.object();
                this.configForm( result, pid, config, pidFilter, locale );
                result.endObject();
            }
            catch ( Exception e )
            {
                configManager.log( "Error reading configuration PID " + pid, e );
            }
View Full Code Here

        final PrintWriter pw = response.getWriter();
        writeJSON(pw);
    }

    private void writeJSON(final PrintWriter pw) {
        final JSONWriter jw = new JSONWriter(pw);
        final Instance[] instances = adminService.getInstances();
        try {
            jw.object();
            jw.key("status");
            jw.value(getStatusLine());
            jw.key("instances");
            jw.array();
            for (Instance i : instances) {
                instanceInfo(jw, i);
            }
            jw.endArray();
            jw.endObject();
        } catch (JSONException ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
View Full Code Here

    private void writeJSON(final PrintWriter pw) throws IOException {
        final List<Repository> repositories = this.getRepositories();
        final List<ExtendedFeature> features = this.getFeatures(repositories);
        final String statusLine = this.getStatusLine(features);

        final JSONWriter jw = new JSONWriter(pw);

        try {
            jw.object();

            jw.key("status");
            jw.value(statusLine);

            jw.key("repositories");
            jw.array();
            for (Repository r : repositories) {
                jw.object();
                jw.key("name");
                jw.value(r.getName());
                jw.key("url");
                String uri = r.getURI().toString();
                jw.value(uri);
                jw.key("actions");
                jw.array();
                boolean enable = true;
                if (uri.startsWith("bundle")) {
                    enable = false;
                }
                action(jw, enable, "refreshRepository", "Refresh", "refresh");
                action(jw, enable, "removeRepository", "Remove", "delete");
                jw.endArray();
                jw.endObject();
            }
            jw.endArray();

            jw.key("features");
            jw.array();
            for (ExtendedFeature f : features) {
                featureInfo(jw, f);
            }
            jw.endArray();

            jw.endObject();

        } catch (JSONException je) {
            throw new IOException(je.toString());
        }
    }
View Full Code Here

    {
        final List<Repository> repositories = this.getRepositories();
        final List<ExtendedFeature> features = this.getFeatures( repositories );
        final String statusLine = this.getStatusLine( features );

        final JSONWriter jw = new JSONWriter( pw );

        try
        {
            jw.object();

            jw.key( "status" );
            jw.value( statusLine );

            jw.key( "repositories" );
            jw.array();
            for ( Repository r : repositories )
            {
                jw.object();
                jw.key( "name" );
                jw.value( r.getName() );
                jw.key( "url" );
                String uri = r.getURI().toString();
                jw.value( uri );
                jw.key( "actions" );
                jw.array();
                boolean enable = true;
                if ( uri.startsWith( "bundle" ) ) {
                    enable = false;
                }
                action( jw, enable, "refreshRepository", "Refresh", "refresh" );
                action( jw, enable, "removeRepository", "Remove", "delete" );
                jw.endArray();
                jw.endObject();
            }
            jw.endArray();

            jw.key( "features" );
            jw.array();
            for ( ExtendedFeature f : features )
            {
                featureInfo( jw, f );
            }
            jw.endArray();

            jw.endObject();

        }
        catch ( JSONException je )
        {
            throw new IOException( je.toString() );
View Full Code Here

        final PrintWriter pw = response.getWriter();
        writeJSON(pw);
    }

    private void writeJSON(final PrintWriter pw) {
        final JSONWriter jw = new JSONWriter(pw);
        final Instance[] instances = adminService.getInstances();
        try {
            jw.object();
            jw.key("status");
            jw.value(getStatusLine());
            jw.key("instances");
            jw.array();
            for (Instance i : instances) {
//                if (!i.isRoot()) {
                    instanceInfo(jw, i);
//                }
            }
            jw.endArray();
            jw.endObject();
        } catch (JSONException ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
View Full Code Here

       
        try {
            Project project = getProject(pm, pid);

            Writer w = response.getWriter();
            JSONWriter writer = new JSONWriter(w);
            writer.object();
                writer.key("data"); writer.value(project.data.toString());
                writer.key("transformations");
                writer.array();
                    for (Text s : project.transformations) {
                        writer.value(s.toString());
                    }
                writer.endArray();
            writer.endObject();
            w.flush();
            w.close();
        } finally {
            pm.close();
        }
View Full Code Here

       
        try {
            Project project = getProject(pm, pid);

            Writer w = response.getWriter();
            JSONWriter writer = new JSONWriter(w);
            writer.object();
            writer.key("transformations");
            writer.array();
                int size = project.transformations.size();
                for (int i = tindex; i < size; i++) {
                    writer.value(project.transformations.get(i).toString());
                }
            writer.endArray();
            writer.endObject();
            w.flush();
            w.close();
        } finally {
            pm.close();
        }
View Full Code Here

    @Override
    protected void openProject(HttpServletResponse response, String pid) throws Exception {
        Project project = getProject(pid);

        Writer w = response.getWriter();
        JSONWriter writer = new JSONWriter(w);
        writer.object();
            writer.key("status"); writer.value("ok");
            writer.key("data"); writer.value(project.data);
            writer.key("metadata"); writer.value(new JSONObject(project.metadata));
            writer.key("transformations");
            writer.array();
                for (String s : project.transformations) {
                    writer.value(new JSONObject(s));
                }
            writer.endArray();
        writer.endObject();
        w.flush();
        w.close();
    }
View Full Code Here

TOP

Related Classes of org.json.JSONWriter

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.