Package org.json

Examples of org.json.JSONWriter


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

    private void writeJSON(final PrintWriter pw) {
        final JSONWriter jw = new JSONWriter(pw);
        final Instance[] instances = instanceService.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(InstancePlugin.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(InstancePlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
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

    }

    private void renderResult(final PrintWriter pw, final Component component)
        throws IOException
    {
        final JSONWriter jw = new JSONWriter(pw);
        try
        {
            jw.object();

            final ScrService scrService = getScrService();
            if (scrService == null)
            {
                jw.key("status"); //$NON-NLS-1$
                jw.value(-1);
            }
            else
            {
                final Component[] components = scrService.getComponents();

                if (components == null || components.length == 0)
                {
                    jw.key("status"); //$NON-NLS-1$
                    jw.value(0);
                }
                else
                {
                    // order components by name
                    sortComponents(components);

                    final StringBuffer buffer = new StringBuffer();
                    buffer.append(components.length);
                    buffer.append(" component"); //$NON-NLS-1$
                    if (components.length != 1)
                    {
                        buffer.append('s');
                    }
                    buffer.append(" installed."); //$NON-NLS-1$
                    jw.key("status"); //$NON-NLS-1$
                    jw.value(components.length);

                    // render components
                    jw.key("data"); //$NON-NLS-1$
                    jw.array();
                    if (component != null)
                    {
                        component(jw, component, true);
                    }
                    else
                    {
                        for (int i = 0; i < components.length; i++)
                        {
                            component(jw, components[i], false);
                        }
                    }
                    jw.endArray();
                }
            }

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

    {

        resp.setContentType("application/json"); //$NON-NLS-1$
        resp.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
        final PrintWriter out = resp.getWriter();
        final JSONWriter jw = new JSONWriter(out);
        final String action = req.getParameter("action"); //$NON-NLS-1$

        final String role = req.getParameter("role"); //$NON-NLS-1$
        final String group = req.getParameter("group"); //$NON-NLS-1$
View Full Code Here

        final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();

        StringWriter w = new StringWriter();
        PrintWriter w2 = new PrintWriter(w);
        JSONWriter jw = new JSONWriter(w2);
        try
        {
            jw.object();
            if (null == admin)
            {
                jw.key("error"); //$NON-NLS-1$
                jw.value(true);
            }
            else
            {
                final DeploymentPackage[] packages = admin.listDeploymentPackages();
                jw.key("data"); //$NON-NLS-1$

                jw.array();
                for (int i = 0; i < packages.length; i++)
                {
                    packageInfoJson(jw, packages[i]);
                }
                jw.endArray();

            }
            jw.endObject();

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

        final String statusLine = getStatusLine( allServices );

        final ServiceReference[] services = ( service != null ) ? new ServiceReference[]
            { service } : allServices;

        final JSONWriter jw = new JSONWriter( pw );

        try
        {
            jw.object();

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

            jw.key( "serviceCount" );
            jw.value( allServices.length );

            jw.key( "data" );

            jw.array();

            for ( int i = 0; i < services.length; i++ )
            {
                serviceInfo( jw, services[i], fullDetails || service != null, locale );
            }

            jw.endArray();

            jw.endObject();

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

    }

    private String getScriptConfig0() throws JSONException
    {
        StringWriter sw = new StringWriter();
        JSONWriter jw = new JSONWriter(sw);
        jw.array();

        for (ScriptEngineFactory sef : scriptEngineManager.getEngineFactories())
        {
            jw.object();
            if (sef.getExtensions().isEmpty())
            {
                continue;
            }
            jw.key("langName").value(sef.getLanguageName());
            jw.key("langCode").value(sef.getExtensions().get(0));

            //Language mode as per CodeMirror names
            String mode = determineMode(sef.getExtensions());
            if (mode != null)
            {
                jw.key("mode").value(mode);
            }

            jw.endObject();
        }

        jw.endArray();
        return sw.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

    {
        // create status line
        final LogReaderService logReaderService = ( LogReaderService ) this.getService( LogReaderService.class
            .getName() );

        JSONWriter jw = new JSONWriter( pw );
        try
        {
            jw.object();

            jw.key( "status" ); //$NON-NLS-1$
            jw.value( logReaderService == null ? Boolean.FALSE : Boolean.TRUE );

            jw.key( "data" ); //$NON-NLS-1$
            jw.array();

            if ( logReaderService != null )
            {
                int index = 0;
                for ( Enumeration logEntries = logReaderService.getLog(); logEntries.hasMoreElements()
                    && index < MAX_LOGS; )
                {
                    LogEntry nextLog = ( LogEntry ) logEntries.nextElement();
                    if ( nextLog.getLevel() <= minLogLevel )
                    {
                        logJson( jw, nextLog, index++, traces );
                    }
                }
            }

            jw.endArray();

            jw.endObject();

        }
        catch ( JSONException je )
        {
            throw new IOException( je.toString() );
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.