Esempio n. 1
0
  protected String getFeatureText() {
    String txt = "";
    try {
      txt = ((HTMLDocument) getDocument()).getText(0, getDocument().getLength()).trim();

      StringBuffer buff = new StringBuffer();
      StringTokenizer tok = new StringTokenizer(txt, "/");
      int ntok = 0;

      while (tok.hasMoreTokens()) {
        String tokTxt = "/" + tok.nextToken().trim();

        int ind = tokTxt.indexOf("=");

        if (ntok != 0 && ind > -1 && qualifier.contains(tokTxt.substring(0, ind + 1)))
          buff.append("\n" + tokTxt);
        else buff.append(tokTxt);

        ntok++;
      }

      txt = buff.toString();
    } catch (BadLocationException ble) {
      ble.printStackTrace();
    }

    return txt;
  }
Esempio n. 2
0
  /**
   * 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()