Exemplo n.º 1
0
 /*package*/
 static ResponseList<UserList> createUserListList(HttpResponse res, Configuration conf)
     throws TwitterException {
   try {
     if (conf.isJSONStoreEnabled()) {
       TwitterObjectFactory.clearThreadLocalMap();
     }
     JSONArray list = res.asJSONArray();
     int size = list.length();
     ResponseList<UserList> users = new ResponseListImpl<UserList>(size, res);
     for (int i = 0; i < size; i++) {
       JSONObject userListJson = list.getJSONObject(i);
       UserList userList = new UserListJSONImpl(userListJson);
       users.add(userList);
       if (conf.isJSONStoreEnabled()) {
         TwitterObjectFactory.registerJSONObject(userList, userListJson);
       }
     }
     if (conf.isJSONStoreEnabled()) {
       TwitterObjectFactory.registerJSONObject(users, list);
     }
     return users;
   } catch (JSONException jsone) {
     throw new TwitterException(jsone);
   }
 }
  // Get the list of all Twitter Search
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public String getListSearch(@Context HttpServletRequest req) throws NamingException {

    logger.debug("Method getListSearch(): Start");

    try {

      TwitterAnalysisLauncher launcher = new TwitterAnalysisLauncher();

      List<TwitterSearch> searchList = launcher.getTwitterSearchList(SearchTypeEnum.SEARCHAPI);

      JSONArray jsonArray = new JSONArray();

      for (TwitterSearch search : searchList) {

        jsonArray.put(search.toJSONObject());
      }

      // logger.debug("GET Result: " + jsonArray.toString());
      logger.debug("Method getListSearch(): End");
      return jsonArray.toString();
    } catch (Throwable th) {

      throw new SpagoBIRuntimeException(
          "Method getListSearch(): An error occurred in Twitter Historical Search API for REST service getListSearch ",
          th);
    }
  }
  /**
   * Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is
   * added.
   *
   * <p>Warning: This method assumes that the data structure is acyclical.
   *
   * @return The writer.
   * @throws JSONException
   */
  public Writer write(Writer writer) throws JSONException {
    try {
      boolean b = false;
      int len = length();

      writer.write('[');

      for (int i = 0; i < len; i += 1) {
        if (b) {
          writer.write(',');
        }
        Object v = this.myArrayList.get(i);
        if (v instanceof JSONObject) {
          ((JSONObject) v).write(writer);
        } else if (v instanceof JSONArray) {
          ((JSONArray) v).write(writer);
        } else {
          writer.write(JSONObject.valueToString(v));
        }
        b = true;
      }
      writer.write(']');
      return writer;
    } catch (IOException e) {
      throw new JSONException(e);
    }
  }
    static ResponseList createDirectMessageList(HttpResponse httpresponse, Configuration configuration)
    {
        int i;
        JSONArray jsonarray;
        JSONObject jsonobject;
        DirectMessageJSONImpl directmessagejsonimpl;
        int j;
        try
        {
            if (configuration.isJSONStoreEnabled())
            {
                TwitterObjectFactory.clearThreadLocalMap();
            }
            jsonarray = httpresponse.asJSONArray();
            j = jsonarray.length();
            httpresponse = new ResponseListImpl(j, httpresponse);
        }
        // Misplaced declaration of an exception variable
        catch (HttpResponse httpresponse)
        {
            throw new TwitterException(httpresponse);
        }
        i = 0;
_L2:
        if (i >= j)
        {
            break MISSING_BLOCK_LABEL_89;
        }
        jsonobject = jsonarray.getJSONObject(i);
        directmessagejsonimpl = new DirectMessageJSONImpl(jsonobject);
        httpresponse.add(directmessagejsonimpl);
        if (configuration.isJSONStoreEnabled())
        {
            TwitterObjectFactory.registerJSONObject(directmessagejsonimpl, jsonobject);
        }
        break MISSING_BLOCK_LABEL_116;
        if (configuration.isJSONStoreEnabled())
        {
            TwitterObjectFactory.registerJSONObject(httpresponse, jsonarray);
        }
        return httpresponse;
        i++;
        if (true) goto _L2; else goto _L1
    static ResponseList createSavedSearchList(HttpResponse httpresponse, Configuration configuration)
        throws TwitterException
    {
        int i;
        if (configuration.isJSONStoreEnabled())
        {
            TwitterObjectFactory.clearThreadLocalMap();
        }
        JSONArray jsonarray = httpresponse.asJSONArray();
        ResponseListImpl responselistimpl;
        JSONObject jsonobject;
        SavedSearchJSONImpl savedsearchjsonimpl;
        try
        {
            responselistimpl = new ResponseListImpl(jsonarray.length(), httpresponse);
        }
        // Misplaced declaration of an exception variable
        catch (Configuration configuration)
        {
            throw new TwitterException((new StringBuilder()).append(configuration.getMessage()).append(":").append(httpresponse.asString()).toString(), configuration);
        }
        i = 0;
_L2:
        if (i < jsonarray.length())
        {
            jsonobject = jsonarray.getJSONObject(i);
            savedsearchjsonimpl = new SavedSearchJSONImpl(jsonobject);
            responselistimpl.add(savedsearchjsonimpl);
            if (configuration.isJSONStoreEnabled())
            {
                TwitterObjectFactory.registerJSONObject(savedsearchjsonimpl, jsonobject);
            }
            break MISSING_BLOCK_LABEL_146;
        }
        if (configuration.isJSONStoreEnabled())
        {
            TwitterObjectFactory.registerJSONObject(responselistimpl, jsonarray);
        }
        return responselistimpl;
        i++;
        if (true) goto _L2; else goto _L1
 static void processLine(String line) throws JSONException {
   JSONArray array = new JSONArray(line);
   System.out.println(array.length());
 }