コード例 #1
0
ファイル: FlocImporter.java プロジェクト: rgo/jDip
  /** Do the work (import text) */
  public void run() {
    isInProgress = true;

    try {
      final String text = getGameInfo();

      if (!isInProgress) {
        return;
      }

      // see if game is registered
      if (text.length() == 0 || text.indexOf(NOT_REGISTERED) >= 0) {
        fic.flocImportUnregistered();
        return;
      }

      // game is registered
      if (fic.flocTextImportComplete(text)) {
        // now, process into a World object
        fic.flocImportMessage(Utils.getLocalString(CREATING_WORLD));

        JudgeImport ji = new JudgeImport(orderFactory, new StringReader(text), null);

        if (!isInProgress) {
          return;
        }

        fic.flocWorldImportComplete(ji.getWorld());
      }
    } catch (IOException e) {
      fic.flocImportException(e);
    } catch (Exception e) {
      // do nothing (catches any thread-abort errors)
    }
  } // run()
コード例 #2
0
ファイル: FlocImporter.java プロジェクト: rgo/jDip
  /**
   * Get the game information.
   *
   * <p>Returns the imported text.
   */
  private String getGameInfo() throws IOException {
    final StringBuffer gameInformation = new StringBuffer(16384);

    URL u = null;
    BufferedReader reader = null;
    try {
      u =
          new URL(
              "http://www.floc.net/observer.py?judge="
                  + judgeName
                  + "&game="
                  + gameName
                  + "&page=history&history_from=0&history_to=999999");

      fic.flocImportMessage(Utils.getLocalString(READING_CONTACT));

      // output is in HTML, so using the HTML editor kit parser removes
      // HTML cruft.
      //
      reader = new BufferedReader(new InputStreamReader(u.openStream()));

      if (!isInProgress) {
        return "";
      }

      ParserDelegator parser = new ParserDelegator();
      parser.parse(
          reader,
          new HTMLEditorKit.ParserCallback() {
            public void handleText(char[] text, int pos) {
              if (!isInProgress) {
                gameInformation.setLength(0); // abort!
                return;
              }

              fic.flocImportMessage(Utils.getLocalString(READING_FROM_NET));
              gameInformation.append(text);
              gameInformation.append("\n");
            } // handleText()
          },
          false);
    } finally {
      if (reader != null) {
        reader.close();
      }
    }

    return gameInformation.toString();
  } // getGameInfo()