Package org.json.simple

Examples of org.json.simple.JSONObject


      Map result = new HashMap();

      if ( tid != null )result.put( "tid", tid );

      try{
        JSONObject  payload = new JSONObject();
       
          // change this you need to change update too below
       
        payload.put( "engine_id", decodedMap.get( "engine_id" ));
        payload.put( "search_term", decodedMap.get( "search_term" ));
        payload.put( "filters", decodedMap.get( "filters" ));
        payload.put( "schedule", decodedMap.get( "schedule" ));
        payload.put( "options", decodedMap.get( "options" ));
       
        Subscription subs = SubscriptionManagerFactory.getSingleton().create(name, isPublic.booleanValue(), payload.toString());
       
        subs.getHistory().setDetails(
          isEnabled==null?true:isEnabled.booleanValue(),
          autoDownload==null?false:autoDownload.booleanValue());
               
        result.put( "id", subs.getID());
       
        sendBrowserMessage( "metasearch", "createSubscriptionCompleted", result );

      } catch( Throwable e ){
       
        result.put( "error", "create failed: " + Debug.getNestedExceptionMessage(e));

        sendBrowserMessage( "metasearch", "createSubscriptionFailed", result );
      }
    }else if( OP_READ_SUBSCRIPTION.equals(opid)){
     
      Map decodedMap = message.getDecodedMap();
     
      final Long   tid = (Long) decodedMap.get("tid");

      final String sid = (String) decodedMap.get("id");
     
      Map result = new HashMap();

      if ( tid != null )result.put( "tid", tid );

      try{
        Subscription subs = SubscriptionManagerFactory.getSingleton().getSubscriptionByID( sid );
       
        if ( subs == null ){
         
          result.put( "error", "Subscription not found" );

          sendBrowserMessage("metasearch", "readSubscriptionFailed",result);
         
        }else{
               
          boolean  shareable = subs.isShareable();
         
            // override public flag if not shareable
         
          result.put( "id", subs.getID());
          result.put( "name", subs.getName());
          result.put( "is_public", new Boolean( shareable && subs.isPublic()));
          result.put( "is_author", new Boolean( subs.isMine()));
          result.put( "is_shareable", new Boolean( shareable ));
          result.put( "auto_dl_supported", new Boolean( subs.isAutoDownloadSupported()));
         
          SubscriptionHistory history = subs.getHistory();
         
          Map  options = new HashMap();

          result.put( "options", options );

          options.put( "is_enabled", new Boolean( history.isEnabled()));
          options.put( "auto_dl", new Boolean( history.isAutoDownload()));
         
          Map  info = new HashMap();

          result.put( "info", info );
         
          info.put( "last_scan", new Long( history.getLastScanTime()));
          info.put( "last_new", new Long( history.getLastNewResultTime()));
          info.put( "num_unread", new Long( history.getNumUnread()));
          info.put( "num_read", new Long( history.getNumRead()));
         
          String json = subs.getJSON();
         
          Map map = JSONUtils.decodeJSON( json );
         
          result.put( "engine_id", map.get( "engine_id" ));
          result.put( "search_term", map.get( "search_term" ));
          result.put( "filters", map.get( "filters" ));
          result.put( "schedule", map.get( "schedule" ));
         
          sendBrowserMessage( "metasearch", "readSubscriptionCompleted", result );
        }
      } catch( Throwable e ){
       
        result.put( "error", "read failed: " + Debug.getNestedExceptionMessage(e));

        sendBrowserMessage("metasearch", "readSubscriptionFailed",result);
      }
    }else if (OP_UPDATE_SUBSCRIPTION.equals(opid)) {
     
      Map decodedMap = message.getDecodedMap();
     
      final Long   tid = (Long) decodedMap.get("tid");
     
      final String   name     = (String)decodedMap.get("name");
      final Boolean   isPublic  = (Boolean)decodedMap.get( "is_public" );
      final String   sid     = (String)decodedMap.get("id");
     
      Map      options    = (Map)decodedMap.get( "options" );
     
      Boolean   isEnabled    = (Boolean)options.get( "is_enabled" );
      Boolean   autoDownload  = (Boolean)options.get( "auto_dl" );

      Map result = new HashMap();

      if ( tid != null )result.put( "tid", tid );

      try{
        Subscription subs = SubscriptionManagerFactory.getSingleton().getSubscriptionByID( sid );
       
        if ( subs == null ){
         
          result.put( "error", "Subscription not found" );

          sendBrowserMessage("metasearch", "updateSubscriptionFailed",result);
         
        }else{
         
          JSONObject  payload = new JSONObject();
         
            // change this you need to change create too above
       
          payload.put( "engine_id", decodedMap.get( "engine_id" ));
          payload.put( "search_term", decodedMap.get( "search_term" ));
          payload.put( "filters", decodedMap.get( "filters" ));
          payload.put( "schedule", decodedMap.get( "schedule" ));
          payload.put( "options", decodedMap.get( "options" ));
       
          boolean  changed = subs.setDetails( name, isPublic.booleanValue(), payload.toString());
         
          subs.getHistory().setDetails(
              isEnabled==null?true:isEnabled.booleanValue(),
              autoDownload==null?false:autoDownload.booleanValue());
View Full Code Here


   
    return( rank );
  }
 
  public Map toJSONMap() {
    Map object = new JSONObject();
    try {
      object.put("d", MomentsAgoDateFormatter.getMomentsAgoString(this.getPublishedDate()));
      object.put("ts", "" + this.getPublishedDate().getTime());
    } catch(Exception e) {
      object.put("d", "unknown");
      object.put("ts", "0");
    }
   
    object.put("c", this.getCategory());
    object.put("n",this.getName());
   
    int  super_seeds = getNbSuperSeeds();
    int  seeds    = getNbSeeds();
   
    int  seed_total = -1;
   
    if ( super_seeds > 0 ){
     
      seed_total = 10*super_seeds + new Random().nextInt(10);
    }
   
    if ( seeds > 0 ){
     
      if ( seed_total == -1 ){
       
        seed_total = 0;
      }
     
      seed_total += seeds;
    }
   
    object.put("s","" + seed_total);
     
    if(this.getNbPeers() >= 0) {
      object.put("p","" + this.getNbPeers());
    } else {
      object.put("p","-1");
    }
   
    int  comments = getComments();
   
    if ( comments >= 0 ){
   
      object.put( "co", "" + comments );
    }
   
    long size = this.getSize();
    if(size >= 0) {
        // max three digits for display purposes
     
      String size_str = DisplayFormatters.formatByteCountToKiBEtc( size );
   
      size_str = DisplayFormatters.trimDigits( size_str, 3 );
     
      object.put("l", size_str );
      object.put("lb", "" + size  );
    } else {
      object.put("l", "-1");
      object.put("lb", "0");
    }
   
    object.put("r", "" + this.getRank());
   
    object.put("ct", this.getContentType());
   
    float accuracy = getAccuracy();
   
    if ( accuracy >= 0 ){
      if ( accuracy > 1 ){
        accuracy = 1;
      }
      object.put ("ac", "" + accuracy );
    }
   
    if ( this.getCDPLink().length() > 0 ){
      object.put("cdp", this.getCDPLink());
    }
   
      // This is also used by subscription code to extract download link so if you
      // change this you'll need to change that too...
   
    if ( this.getDownloadLink().length() > 0 ){
      object.put("dl", this.getDownloadLink());
    }
   
    if ( this.getDownloadButtonLink().length() > 0 ){
      object.put("dbl", this.getDownloadButtonLink());
    }
   
    if ( this.getPlayLink().length() > 0 ){
      object.put("pl", this.getPlayLink());
    }
   
    if ( this.getVotes() >= 0 ){
      object.put("v", "" + this.getVotes());
    }
   
    if ( this.getVotesDown() >= 0 ){
      object.put("vd", "" + this.getVotesDown());
    }
   
    String drmKey = getDRMKey();
    if(drmKey != null) {
      object.put("dk",drmKey);
    }
   
      // used by subscriptions...
   
    String uid = getUID();
    if ( uid != null ){
      object.put( "u", uid );
    }
    object.put("pr", this.isPrivate() ? "1" : "0");

    String hash = getHash();
    if ( hash != null ){
      object.put( "h", hash );
    }
   
    return object;
  }
View Full Code Here

        for(int i = 0 ; i < resultArray.size() ; i++) {
         
          Object obj = resultArray.get(i);
         
          if(obj instanceof JSONObject) {
            JSONObject jsonEntry = (JSONObject) obj;
           
            if ( absolute_max_matches >= 0 ){
              if ( --absolute_max_matches < 0 ){
                break;
              }
            }
           
            if ( listener != null ){
             
                // sort for consistent order
             
              Iterator it = new TreeMap( jsonEntry ).entrySet().iterator();
             
              String[]  groups = new String[ jsonEntry.size()];
             
              int  pos = 0;
             
              while( it.hasNext()){
               
                Map.Entry entry = (Map.Entry)it.next();
               
                Object key     = entry.getKey();
                Object value   = entry.getValue();
               
                if ( key != null && value != null ){
               
                  groups[pos++] = key.toString() + "=" + UrlUtils.encode( value.toString());
                 
                }else{
                 
                  groups[pos++] = "";
                }
              }
             
              listener.matchFound( this, groups );
            }
           
            WebResult result = new WebResult(this,getRootPage(),getBasePage(),getDateParser(),searchQuery);
                         
            for(int j = 0 ; j < mappings.length ; j++) {
              String fieldFrom = mappings[j].getName();
              if(fieldFrom != null) {
                int fieldTo = mappings[j].getField();
                Object fieldContentObj = ((Object)jsonEntry.get(fieldFrom));
                if(fieldContentObj != null) {
                  String fieldContent = fieldContentObj.toString();
                 
                  switch(fieldTo) {
                  case FIELD_NAME :
View Full Code Here

       
        log( "JSON export: unknown field id " + field_id );
       
      }else{
             
        JSONObject entry = new JSONObject();

        maps.add( entry );
         
        entry.put( "vuze_field", field_value );
       
        if ( getType() == ENGINE_TYPE_JSON ){
         
          entry.put( "field_name", fm.getName());
         
        }else{
         
          entry.put( "group_nb", fm.getName());
        }
      }
    } 
  }
View Full Code Here

  protected static String
  getSkeletonJSON(
    Engine    engine,
    int      check_interval_mins )
  {
    JSONObject  map = new JSONObject();
   
    map.put( "engine_id", new Long( engine.getId()));
   
    map.put( "search_term", "" );

    map.put( "filters", new HashMap());
   
    map.put( "options", new HashMap());
   
    Map schedule = new HashMap();
   
    schedule.put( "interval", new Long( check_interval_mins ));
   
    List  days = new ArrayList();
   
    for (int i=1;i<=7;i++){
     
      days.add( String.valueOf(i));
    }
   
    schedule.put( "days", days );
   
    map.put( "schedule", schedule );
   
    embedEngines( map, engine );
   
    return( JSONUtils.encodeToJSON( map ));
  }
View Full Code Here

    String      name,
    String      content )
 
    throws IOException
  {
    JSONObject map = (JSONObject)JSONUtils.decodeJSON( content );
   
    if ( type == Engine.ENGINE_TYPE_JSON ){
     
      return( JSONEngine.importFromJSONString( meta_search, id, last_updated, rank_bias, name, map ));
     
View Full Code Here

 
    throws IOException
  {
    List  result = new ArrayList();
     
    JSONObject  field_map = (JSONObject)map.get( str );
   
    if ( field_map != null ){
     
      Iterator  it = field_map.entrySet().iterator();
     
      while( it.hasNext()){
       
        Map.Entry  entry = (Map.Entry)it.next();
       
        String  key     = (String)entry.getKey();
        List  mappings   = (List)entry.getValue();
       
          // limited support for the moment:
          //    level one always maps to same field
          //    level two always maps to content type
       
        int  from_field   = vuzeFieldToID( key );
       
        if ( from_field == -1 ){
         
          log( "Unrecognised remapping key '" + key + "'" );
         
          continue;
       
        }
       
        int  to_field  = level_1?from_field:FIELD_CONTENT_TYPE;
       
        List  frs_l = new ArrayList();
       
        for (int i=0;i<mappings.size();i++){
         
          JSONObject mapping = (JSONObject)mappings.get(i);
         
          String  from_str   = URLDecoder.decode((String)mapping.get( level_1?"from_string":"cat_string" ),"UTF-8");

          if ( from_str == null ){
           
            log( "'from' value missing in " + mapping );
           
            continue;
          }
         
          from_str   = URLDecoder.decode( from_str, "UTF-8" );
         
          String  to_str     = URLDecoder.decode((String)mapping.get( level_1?"to_string":"media_type" ),"UTF-8");
         
          if ( to_str == null ){
           
            log( "'to' value missing in " + mapping );
           
View Full Code Here

    JSONObject      res,
    String        str,
    List        l,
    boolean        level_1 )
  {
    JSONObject  field_map = new JSONObject();
   
    res.put( str, field_map );
   
    for (int i=0;i<l.size();i++){
     
      FieldRemapper remapper = (FieldRemapper)l.get(i);
     
      int  from_field  = remapper.getInField();
      //int  to_field  = remapper.getOutField();
     
      String from_field_str = vuzeIDToField( from_field );
     
      JSONArray  mappings = new JSONArray();
     
      field_map.put( from_field_str, mappings );
     
      FieldRemapping[] frs = remapper.getMappings();
     
      for (int j=0;j<frs.length;j++){
       
        FieldRemapping fr = frs[j];
       
        String from_str = UrlUtils.encode( fr.getMatchString());
       
        String to_str  = fr.getReplacement();
       
        JSONObject map = new JSONObject();
       
        mappings.add( map );
       
        map.put( level_1?"from_string":"cat_string", from_str );
        map.put( level_1?"to_string":"media_type", to_str );
      }
    }
  }
View Full Code Here

  public String
  exportToJSONString()
 
    throws IOException
  {
    JSONObject  obj = new JSONObject();
   
    exportToJSONObject( obj );
   
    return( obj.toString());
  }
View Full Code Here

  {
    if (true) {
      return new ArrayList<contentNetworkDetails>(0);
    }

    JSONObject parameters = new JSONObject();
   
    parameters.put( "azver", Constants.AZUREUS_VERSION );
   
    Map reply = dispatcher.syncInvoke( OP_LIST_CNETORKS, parameters );

    List<Map>  networks = (List<Map>)reply.get( "networks" );
   
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.