Package org.json

Examples of org.json.JSONArray


            try {
                if (status == 200) {
                    input = httpMethod.getResponseBodyAsStream();
                    JSONObject obj = new JSONObject(new JSONTokener(new InputStreamReader(input)));
   
                    JSONArray bundleStatus = obj.getJSONArray("s");
   
                    int total = bundleStatus.getInt(0);
                    int active = bundleStatus.getInt(1);
                    int fragment = bundleStatus.getInt(2);
   
                    debug("bundle http call status: total = " + total + ", active = " + active + ", fragment = " + fragment);
   
                    if (total == active + fragment) {
                        debug("All bundles are started, we are done here");
View Full Code Here


        return json.toString();
    }

    private JSONArray getEntries(File dir, String localServerURL)
            throws JSONException {
        JSONArray fileArray = new JSONArray();
        return getEntries(dir, localServerURL, "", fileArray);
    }
View Full Code Here

            JSONObject json = new JSONObject( jsonString );

            pw.println( "Status: " + json.get( "status" ) );
            pw.println();

            JSONArray data = json.getJSONArray( "data" );
            for ( int i = 0; i < data.length(); i++ )
            {
                if ( !data.isNull( i ) )
                {
                    JSONObject bundle = data.getJSONObject( i );

                    pw.println( MessageFormat.format( "Bundle {0} - {1} {2} (state: {3})", new Object[]
                        { bundle.get( "id" ), bundle.get( "name" ), bundle.get( "version" ), bundle.get( "state" ) } ) );

                    JSONArray props = bundle.getJSONArray( "props" );
                    for ( int pi = 0; pi < props.length(); pi++ )
                    {
                        if ( !props.isNull( pi ) )
                        {
                            JSONObject entry = props.getJSONObject( pi );
                            String key = ( String ) entry.get( "key" );
                            if ( "nfo".equals( key ) )
                            {
                                // BundleInfo (see #bundleInfo & #bundleInfoDetails
                                JSONObject infos = ( JSONObject ) entry.get( "value" );
                                Iterator infoKeys = infos.keys();
                                while ( infoKeys.hasNext() )
                                {
                                    String infoKey = ( String ) infoKeys.next();
                                    pw.println( "    " + infoKey + ": " );

                                    JSONArray infoA = infos.getJSONArray( infoKey );
                                    for ( int iai = 0; iai < infoA.length(); iai++ )
                                    {
                                        if ( !infoA.isNull( iai ) )
                                        {
                                            JSONObject info = infoA.getJSONObject( iai );
                                            pw.println( "        " + info.get( "name" ) );
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // regular data
                                pw.print( "    " + key + ": " );

                                Object entryValue = entry.get( "value" );
                                if ( entryValue instanceof JSONArray )
                                {
                                    pw.println();
                                    JSONArray entryArray = ( JSONArray ) entryValue;
                                    for ( int ei = 0; ei < entryArray.length(); ei++ )
                                    {
                                        if ( !entryArray.isNull( ei ) )
                                        {
                                            pw.println( "        " + entryArray.get( ei ) );
                                        }
                                    }
                                }
                                else
                                {
View Full Code Here

                {
                    return compare( ( ExportedPackage ) o1, ( ExportedPackage ) o2 );
                }
            } );

            JSONArray val = new JSONArray();
            for ( int j = 0; j < exports.length; j++ )
            {
                ExportedPackage export = exports[j];
                collectExport( val, export.getName(), export.getVersion() );
                Bundle[] ubList = export.getImportingBundles();
                if ( ubList != null )
                {
                    for ( int i = 0; i < ubList.length; i++ )
                    {
                        Bundle ub = ubList[i];
                        String name = ub.getSymbolicName();
                        if (name == null) name = ub.getLocation();
                        usingBundles.put( name, ub );
                    }
                }
            }
            WebConsoleUtil.keyVal( jw, "Exported Packages", val );
        }
        else
        {
            WebConsoleUtil.keyVal( jw, "Exported Packages", "---" );
        }

        exports = packageAdmin.getExportedPackages( ( Bundle ) null );
        if ( exports != null && exports.length > 0 )
        {
            // collect import packages first
            final List imports = new ArrayList();
            for ( int i = 0; i < exports.length; i++ )
            {
                final ExportedPackage ep = exports[i];
                final Bundle[] importers = ep.getImportingBundles();
                for ( int j = 0; importers != null && j < importers.length; j++ )
                {
                    if ( importers[j].getBundleId() == bundle.getBundleId() )
                    {
                        imports.add( ep );

                        break;
                    }
                }
            }
            // now sort
            JSONArray val = new JSONArray();
            if ( imports.size() > 0 )
            {
                final ExportedPackage[] packages = ( ExportedPackage[] ) imports.toArray( new ExportedPackage[imports
                    .size()] );
                Arrays.sort( packages, new Comparator()
                {
                    public int compare( ExportedPackage p1, ExportedPackage p2 )
                    {
                        return p1.getName().compareTo( p2.getName() );
                    }


                    public int compare( Object o1, Object o2 )
                    {
                        return compare( ( ExportedPackage ) o1, ( ExportedPackage ) o2 );
                    }
                } );
                // and finally print out
                for ( int i = 0; i < packages.length; i++ )
                {
                    ExportedPackage ep = packages[i];
                    collectImport( val, ep.getName(), ep.getVersion(), false, ep, pluginRoot );
                }
            }
            else
            {
                // add description if there are no imports
                val.put( "None" );
            }

            WebConsoleUtil.keyVal( jw, "Imported Packages", val );
        }

        if ( !usingBundles.isEmpty() )
        {
            JSONArray val = new JSONArray();
            for ( Iterator ui = usingBundles.values().iterator(); ui.hasNext(); )
            {
                Bundle usingBundle = ( Bundle ) ui.next();
                val.put( getBundleDescriptor( usingBundle, pluginRoot ) );
            }
            WebConsoleUtil.keyVal( jw, "Importing Bundles", val );
        }
    }
View Full Code Here

                    {
                        return compare( ( Clause) o1, ( Clause ) o2 );
                    }
                } );

                JSONArray val = new JSONArray();
                for ( int i = 0; i < pkgs.length; i++ )
                {
                    Clause export = new Clause( pkgs[i].getName(), pkgs[i].getDirectives(), pkgs[i].getAttributes() );
                    collectExport( val, export.getName(), export.getAttribute( Constants.VERSION_ATTRIBUTE ) );
                }
                WebConsoleUtil.keyVal( jw, "Exported Packages", val );
            }
            else
            {
                WebConsoleUtil.keyVal( jw, "Exported Packages", "---" );
            }
        }

        target = ( String ) dict.get( Constants.IMPORT_PACKAGE );
        if ( target != null )
        {
            Clause[] pkgs = Parser.parseHeader( target );
            if ( pkgs != null && pkgs.length > 0 )
            {
                Map imports = new TreeMap();
                for ( int i = 0; i < pkgs.length; i++ )
                {
                    Clause pkg = pkgs[i];
                    imports.put( pkg.getName(), new Clause( pkg.getName(), pkg.getDirectives(), pkg.getAttributes() ) );
                }

                // collect import packages first
                final Map candidates = new HashMap();
                PackageAdmin packageAdmin = getPackageAdmin();
                if ( packageAdmin != null )
                {
                    ExportedPackage[] exports = packageAdmin.getExportedPackages( ( Bundle ) null );
                    if ( exports != null && exports.length > 0 )
                    {

                        for ( int i = 0; i < exports.length; i++ )
                        {
                            final ExportedPackage ep = exports[i];

                            Clause imp = ( Clause ) imports.get( ep.getName() );
                            if ( imp != null && isSatisfied( imp, ep ) )
                            {
                                candidates.put( ep.getName(), ep );
                            }
                        }
                    }
                }

                // now sort
                JSONArray val = new JSONArray();
                if ( imports.size() > 0 )
                {
                    for ( Iterator ii = imports.values().iterator(); ii.hasNext(); )
                    {
                        Clause r4Import = ( Clause ) ii.next();
                        ExportedPackage ep = ( ExportedPackage ) candidates.get( r4Import.getName() );

                        // if there is no matching export, check whether this
                        // bundle has the package, ignore the entry in this case
                        if ( ep == null )
                        {
                            String path = r4Import.getName().replace( '.', '/' );
                            if ( bundle.getEntry( path ) != null )
                            {
                                continue;
                            }
                        }

                        collectImport( val, r4Import.getName(), r4Import.getAttribute( Constants.VERSION_ATTRIBUTE ),
                            Constants.RESOLUTION_OPTIONAL.equals( r4Import
                                .getDirective( Constants.RESOLUTION_DIRECTIVE ) ), ep, pluginRoot );
                    }
                }
                else
                {
                    // add description if there are no imports
                    val.put( "---" );
                }

                WebConsoleUtil.keyVal( jw, "Imported Packages", val );
            }
        }
View Full Code Here

        {


            String key = "Service ID " + getServiceID( refs[i], servicesRoot );

            JSONArray val = new JSONArray();

            appendProperty( val, refs[i], Constants.OBJECTCLASS, "Types" );
            appendProperty( val, refs[i], Constants.SERVICE_PID, "Service PID" );
            appendProperty( val, refs[i], "org.apache.felix.karaf.features.configKey", "Feature PID" );
            appendProperty( val, refs[i], ConfigurationAdmin.SERVICE_FACTORYPID, "Factory PID" );
View Full Code Here

    }


    private void listHeaders( JSONWriter jw, Bundle bundle ) throws JSONException
    {
        JSONArray val = new JSONArray();

        Dictionary headers = bundle.getHeaders(""); // don't localize at all - raw headers
        Enumeration he = headers.keys();
        while ( he.hasMoreElements() )
        {
            Object header = he.nextElement();
            String value = String.valueOf(headers.get( header ));
            // Package headers may be long, support line breaking by
            // ensuring blanks after comma and semicolon.
            value = enableLineWrapping(value);
            val.put( header + ": " + value );
        }

        WebConsoleUtil.keyVal( jw, "Manifest Headers", val );
    }
View Full Code Here

        if ( isFragmentBundle( bundle ) )
        {
            Bundle[] hostBundles = getPackageAdmin().getHosts( bundle );
            if ( hostBundles != null )
            {
                JSONArray val = new JSONArray();
                for ( int i = 0; i < hostBundles.length; i++ )
                {
                    val.put( getBundleDescriptor( hostBundles[i], pluginRoot ) );
                }
                WebConsoleUtil.keyVal( jw, "Host Bundles", val );
            }
        }
        else
        {
            Bundle[] fragmentBundles = getPackageAdmin().getFragments( bundle );
            if ( fragmentBundles != null )
            {
                JSONArray val = new JSONArray();
                for ( int i = 0; i < fragmentBundles.length; i++ )
                {
                    val.put( getBundleDescriptor( fragmentBundles[i], pluginRoot ) );
                }
                WebConsoleUtil.keyVal( jw, "Fragments Attached", val );
            }
        }
View Full Code Here

            json.key( "value" ); //$NON-NLS-1$
            json.value( value );
        }
        else
        {
            value = new JSONArray( toList( value ) );
            if ( isPassword )
            {
                JSONArray tmp = ( JSONArray ) value;
                for ( int tmpI = 0; tmpI < tmp.length(); tmpI++ )
                {
                    tmp.put( tmpI, PASSWORD_PLACEHOLDER_VALUE );
                }
            }
            json.key( "values" ); //$NON-NLS-1$
            json.value( value );
        }
View Full Code Here

        res.getWriter().print(TEMPLATE);
    }

    private static final JSONArray getBundleData(Bundle[] bundles, Locale locale) throws IOException
    {
        JSONArray ret = new JSONArray();
        try
        {
            for (int i = 0; i < bundles.length; i++)
            {
                Bundle bundle = bundles[i];

                JSONObject files = findResource(bundle, LICENSE_FILES);
                addLicensesFromHeader(bundle, files);
                if (files.length() > 0)
                { // has resources
                    JSONObject data = new JSONObject();
                    data.put( "bid", bundle.getBundleId() );
                    data.put( "title", Util.getName( bundle, locale ) );
                    data.put( "files", files );
                    ret.put( data );
                }
            }
        }
        catch (JSONException je)
        {
View Full Code Here

TOP

Related Classes of org.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.