Exemplo n.º 1
0
  public void updateDB(String[] al) {

    for (int i = 0; i < al.length; i++) {
      String s = al[i];
      File f = new File(s);
      Status.getStatus().setStringStatus("Updating folder " + s);

      if (f.exists()) {
        Logger.getLogger().log("MediaIndexer.updateDB updating " + s);
        processMTRoot(s);
      } else {
        System.out.println("MediaIndexer.updateDB path " + s + " not reachable, ignoring");
      }
    }
    Status.getStatus().setStringStatus(Status.IDLE);
  }
Exemplo n.º 2
0
  private Tweet getTweetObjectFromStatus(Status status) {

    Tweet tweet = new Tweet();
    tweet.setId(Long.toString(status.getId()));
    tweet.setText(status.getText());
    tweet.setCreatedAt(status.getCreatedAt());

    tweet.setFavCount(status.getFavoriteCount());

    User user = status.getUser();

    tweet.setUserId(user.getId());
    tweet.setUserName(user.getName());
    tweet.setUserScreenName(user.getScreenName());

    HashtagEntity[] hashtagEntities = status.getHashtagEntities();
    List<String> hashtags = new ArrayList<String>();

    for (HashtagEntity hashtagEntity : hashtagEntities) {
      hashtags.add(hashtagEntity.getText());
    }

    tweet.setHashTags(hashtags.toArray(new String[hashtags.size()]));

    GeoLocation geoLocation = status.getGeoLocation();
    if (geoLocation != null) {
      double[] coordinates = {geoLocation.getLongitude(), geoLocation.getLatitude()};
      tweet.setCoordinates(coordinates);
    }

    return tweet;
  }
Exemplo n.º 3
0
  public void analyseData(ByteBuffer bb) {
    byte[] buff = new byte[bb.remaining()];
    bb.get(buff);
    String receiveData = new String(buff);

    String so1 = receiveData.substring(0, 1);
    String so2 = receiveData.substring(1, 2);
    int o1 = Integer.parseInt(so1);
    int o2 = Integer.parseInt(so2);
    switch (o1) {
      case 1:
        switch (o2) {
          case 0:
            Status.printStatus(receiveData.substring(2));
            break;
          case 1:
            Commentary.analyseCommentary(receiveData.substring(2));
        }
        break;
      case 2:
        switch (o2) {
          case 0:
            System.out.println(receiveData.substring(2));
            Friends.analyseFriendsRequest(receiveData.substring(2));
            break;
          case 1:
            // Réponse amis + envoi liste d'amis + status
            break;
          case 2:
            // Refus
            break;
          case 3:
            // Demande liste d'amis
            break;
          case 4:
            // Envoi liste d'amis
            break;
        }
        break;
      case 3:
        switch (o2) {
          case 0:
            // Demande status
            break;
          case 1:
            // Envoi status
            break;
        }
        break;
      case 4:
        switch (o2) {
          case 0:
            // image status
            break;
          case 1:
            // image profile
            break;
        }
        break;
    }
  }
Exemplo n.º 4
0
  /**
   * Post a file to the server. The different elements of the post are encoded in the specified
   * message.
   *
   * @param message The message that contains the post information.
   * @throws SWORDClientException if there is an error during the post operation.
   */
  public DepositResponse postFile(PostMessage message) throws SWORDClientException {
    if (message == null) {
      throw new SWORDClientException("Message cannot be null.");
    }

    PostMethod httppost = new PostMethod(message.getDestination());

    if (doAuthentication) {
      setBasicCredentials(username, password);
      httppost.setDoAuthentication(true);
    }

    DepositResponse response = null;

    String messageBody = "";

    try {
      if (message.isUseMD5()) {
        String md5 = ChecksumUtils.generateMD5(message.getFilepath());
        if (message.getChecksumError()) {
          md5 = "1234567890";
        }
        log.debug("checksum error is: " + md5);
        if (md5 != null) {
          httppost.addRequestHeader(new Header(HttpHeaders.CONTENT_MD5, md5));
        }
      }

      String filename = message.getFilename();
      if (!"".equals(filename)) {
        httppost.addRequestHeader(
            new Header(HttpHeaders.CONTENT_DISPOSITION, " filename=" + filename));
      }

      if (containsValue(message.getSlug())) {
        httppost.addRequestHeader(new Header(HttpHeaders.SLUG, message.getSlug()));
      }

      if (message.getCorruptRequest()) {
        // insert a header with an invalid boolean value
        httppost.addRequestHeader(new Header(HttpHeaders.X_NO_OP, "Wibble"));
      } else {
        httppost.addRequestHeader(
            new Header(HttpHeaders.X_NO_OP, Boolean.toString(message.isNoOp())));
      }
      httppost.addRequestHeader(
          new Header(HttpHeaders.X_VERBOSE, Boolean.toString(message.isVerbose())));

      String packaging = message.getPackaging();
      if (packaging != null && packaging.length() > 0) {
        httppost.addRequestHeader(new Header(HttpHeaders.X_PACKAGING, packaging));
      }

      String onBehalfOf = message.getOnBehalfOf();
      if (containsValue(onBehalfOf)) {
        httppost.addRequestHeader(new Header(HttpHeaders.X_ON_BEHALF_OF, onBehalfOf));
      }

      String userAgent = message.getUserAgent();
      if (containsValue(userAgent)) {
        httppost.addRequestHeader(new Header(HttpHeaders.USER_AGENT, userAgent));
      }

      FileRequestEntity requestEntity =
          new FileRequestEntity(new File(message.getFilepath()), message.getFiletype());
      httppost.setRequestEntity(requestEntity);

      client.executeMethod(httppost);
      status = new Status(httppost.getStatusCode(), httppost.getStatusText());

      log.info("Checking the status code: " + status.getCode());

      if (status.getCode() == HttpStatus.SC_ACCEPTED || status.getCode() == HttpStatus.SC_CREATED) {
        messageBody = readResponse(httppost.getResponseBodyAsStream());
        response = new DepositResponse(status.getCode());
        response.setLocation(httppost.getResponseHeader("Location").getValue());
        // added call for the status code.
        lastUnmarshallInfo = response.unmarshall(messageBody, new Properties());
      } else {
        messageBody = readResponse(httppost.getResponseBodyAsStream());
        response = new DepositResponse(status.getCode());
        response.unmarshallErrorDocument(messageBody);
      }
      return response;

    } catch (NoSuchAlgorithmException nex) {
      throw new SWORDClientException("Unable to use MD5. " + nex.getMessage(), nex);
    } catch (HttpException ex) {
      throw new SWORDClientException(ex.getMessage(), ex);
    } catch (IOException ioex) {
      throw new SWORDClientException(ioex.getMessage(), ioex);
    } catch (UnmarshallException uex) {
      throw new SWORDClientException(uex.getMessage() + "(<pre>" + messageBody + "</pre>)", uex);
    } finally {
      httppost.releaseConnection();
    }
  }
Exemplo n.º 5
0
  /**
   * Retrieve the service document. The service document is located at the specified URL. This calls
   * getServiceDocument(url,onBehalfOf).
   *
   * @param url The location of the service document.
   * @return The ServiceDocument, or <code>null</code> if there was a problem accessing the
   *     document. e.g. invalid access.
   * @throws SWORDClientException If there is an error accessing the resource.
   */
  public ServiceDocument getServiceDocument(String url, String onBehalfOf)
      throws SWORDClientException {
    URL serviceDocURL = null;
    try {
      serviceDocURL = new URL(url);
    } catch (MalformedURLException e) {
      // Try relative URL
      URL baseURL = null;
      try {
        baseURL = new URL("http", server, Integer.valueOf(port), "/");
        serviceDocURL = new URL(baseURL, (url == null) ? "" : url);
      } catch (MalformedURLException e1) {
        // No dice, can't even form base URL...
        throw new SWORDClientException(
            url
                + " is not a valid URL ("
                + e1.getMessage()
                + "), and could not form a relative one from: "
                + baseURL
                + " / "
                + url,
            e1);
      }
    }

    GetMethod httpget = new GetMethod(serviceDocURL.toExternalForm());
    if (doAuthentication) {
      // this does not perform any check on the username password. It
      // relies on the server to determine if the values are correct.
      setBasicCredentials(username, password);
      httpget.setDoAuthentication(true);
    }

    Properties properties = new Properties();

    if (containsValue(onBehalfOf)) {
      log.debug("Setting on-behalf-of: " + onBehalfOf);
      httpget.addRequestHeader(new Header(HttpHeaders.X_ON_BEHALF_OF, onBehalfOf));
      properties.put(HttpHeaders.X_ON_BEHALF_OF, onBehalfOf);
    }

    if (containsValue(userAgent)) {
      log.debug("Setting userAgent: " + userAgent);
      httpget.addRequestHeader(new Header(HttpHeaders.USER_AGENT, userAgent));
      properties.put(HttpHeaders.USER_AGENT, userAgent);
    }

    ServiceDocument doc = null;

    try {
      client.executeMethod(httpget);
      // store the status code
      status = new Status(httpget.getStatusCode(), httpget.getStatusText());

      if (status.getCode() == HttpStatus.SC_OK) {
        String message = readResponse(httpget.getResponseBodyAsStream());
        log.debug("returned message is: " + message);
        doc = new ServiceDocument();
        lastUnmarshallInfo = doc.unmarshall(message, properties);
      } else {
        throw new SWORDClientException("Received error from service document request: " + status);
      }
    } catch (HttpException ex) {
      throw new SWORDClientException(ex.getMessage(), ex);
    } catch (IOException ioex) {
      throw new SWORDClientException(ioex.getMessage(), ioex);
    } catch (UnmarshallException uex) {
      throw new SWORDClientException(uex.getMessage(), uex);
    } finally {
      httpget.releaseConnection();
    }

    return doc;
  }
Exemplo n.º 6
0
 public void setStatus(int status) {
   setStatus(Status.forValue(status));
 }
Exemplo n.º 7
0
  public static void main(String[] args) {

    try {

      meet myobj = new meet();

      // load jsiconfig.txt
      ArrayList<String> myconfiglist = new ArrayList<String>();
      myconfiglist = myobj.loadArray("jsiconfig.txt");

      // The text uri
      // "mongodb://*****:*****@ds023288.mongolab.com:23288/sample";
      String textUri = myconfiglist.get(0);

      // Create MongoClientURI object from which you get MongoClient obj
      MongoClientURI uri = new MongoClientURI(textUri);

      // Connect to that uri
      MongoClient m = new MongoClient(uri);

      // get the database named sample
      String DBname = myconfiglist.get(1);
      DB d = m.getDB(DBname);

      // get the collection mycollection in sample
      String collectionName = myconfiglist.get(2);
      DBCollection collection = d.getCollection(collectionName);

      // System.out.println("Config: "+textUri+":"+DBname+":"+collectionName);

      // twitter4j
      // Twitter twitter = new TwitterFactory().getInstance();
      Twitter twitter = new TwitterFactory().getSingleton();
      User user = twitter.verifyCredentials();

      // Twitter collection of latest tweets into the home account - defaulted to latest 20 tweets//
      //////////////////////////////////////////////////////////////

      ArrayList<String> mylatesttweetslist = new ArrayList<String>();
      // get list of tweets from a user or the next tweet listed
      try {
        long actid = 0;
        // twitter.createFriendship(actid);

        // The factory instance is re-useable and thread safe.
        // Twitter twitter = TwitterFactory.getSingleton();
        List<Status> statuses = twitter.getHomeTimeline();
        System.out.println("Showing home timeline.");

        for (Status status : statuses) {

          // System.out.println(status.getUser().getName() + ":" +status.getText());
          // Addes timeline to an array
          String mytweets = status.getUser().getName() + ":" + status.getText();
          mylatesttweetslist.add(mytweets);
        }
        ;

      } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
      }

      // MongoDB Insert Below //
      //////////////////////////

      // System Date
      Date sd = new Date();
      String sysdate = sd.toString();

      // Toggle the below to display and insert the transactions as required
      boolean showtrans = true;
      boolean inserttrans = true;

      // checkArray - loads args to a text string to allow the contains function
      String checkString = "";
      for (int ck = 0; ck < args.length; ck++) {
        checkString = checkString + args[ck];
      }
      ;

      // display transactions flag on runnning jsimongo eg: java jsimongo -d  will NOT display
      // transactions
      // insert transactions flag on runnning jsimongo eg: java jsimongo -i  will NOT insert
      // transactions

      if (args.length > 0) {
        if (checkString.contains("-d")) showtrans = false;
        if (checkString.contains("-i")) inserttrans = false;
      }
      ;

      int x = 0;
      for (String atweet : mylatesttweetslist) {
        x++;
        // Display tweets to console
        if (showtrans == true) {
          System.out.println("tweet : " + atweet);
          System.out.println("Created_DateTime : " + sysdate); // was sysdate
        }
        ;

        // Insert JSON into MongoDB
        if (inserttrans == true) {
          BasicDBObject b = new BasicDBObject();
          System.out.println("tweet : " + atweet);
          System.out.println("Created_DateTime : " + sysdate); // was sysdate

          // Insert the JSON object into the chosen collection
          collection.insert(b);
        }
        ;
        Thread.sleep(1);
      }
      ;

      System.out.println("End, the number of tweets inserted at this time was: " + x);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public void testRetweetStatusAsJSON() throws Exception {
   // single Status
   HttpClientImpl http = new HttpClientImpl();
   Status status =
       new StatusJSONImpl(
           http.get("http://twitter4j.org/en/testcases/statuses/retweet/6010814202.json"), conf);
   Assert.assertEquals(new Date(1259078050000l), status.getCreatedAt());
   Assert.assertEquals(6011259778l, status.getId());
   Assert.assertEquals(null, status.getInReplyToScreenName());
   Assert.assertEquals(-1l, status.getInReplyToStatusId());
   Assert.assertEquals(-1, status.getInReplyToUserId());
   Assert.assertNull(status.getGeoLocation());
   Assert.assertEquals(
       "<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>", status.getSource());
   Assert.assertEquals(
       "RT @yusukey: この前取材受けた奴 -> 次世代のシステム環境を見据えたアプリケーションサーバー製品の選択 ITpro: http://special.nikkeibp.co.jp/ts/article/0iaa/104388/",
       status.getText());
   Assert.assertEquals(6358482, status.getUser().getId());
   Assert.assertTrue(status.isRetweet());
   assertDeserializedFormIsEqual(status);
 }
 public void testStatusAsJSON() throws Exception {
   // single Status
   HttpClientImpl http = new HttpClientImpl();
   List<Status> statuses =
       StatusJSONImpl.createStatusList(
           http.get("http://twitter4j.org/en/testcases/statuses/public_timeline.json"), conf);
   Status status = statuses.get(0);
   Assert.assertEquals(new Date(1259041785000l), status.getCreatedAt());
   Assert.assertEquals(6000554383l, status.getId());
   Assert.assertEquals("G_Shock22", status.getInReplyToScreenName());
   Assert.assertEquals(6000444309l, status.getInReplyToStatusId());
   Assert.assertEquals(20159829, status.getInReplyToUserId());
   Assert.assertNull(status.getGeoLocation());
   Assert.assertEquals("web", status.getSource());
   Assert.assertEquals(
       "@G_Shock22 I smelled a roast session coming when yu said that shyt about @2koolNicia lol....",
       status.getText());
   Assert.assertEquals(23459577, status.getUser().getId());
   Assert.assertFalse(status.isRetweet());
   assertDeserializedFormIsEqual(statuses);
 }