コード例 #1
0
  /**
   * Manages the return exception of a dict query.
   *
   * @param dix The exception returned by the adapter
   * @param database The dictionary used
   * @return Exception message
   */
  private String manageException(DictException dix, String database) {
    int errorCode = dix.getErrorCode();

    // We change the text only for exception 550 (invalid dictionary) and 551 (invalid strategy)
    if (errorCode == DictReturnCode.INVALID_DATABASE) {
      return DictActivator.getResources()
          .getI18NString("plugin.dictaccregwizz.INVALID_DATABASE", new String[] {database});
    } else if (errorCode == DictReturnCode.INVALID_STRATEGY) {
      return DictActivator.getResources().getI18NString("plugin.dictaccregwizz.INVALID_STRATEGY");
    } else if (errorCode == DictReturnCode.NO_MATCH) {
      return DictActivator.getResources().getI18NString("plugin.dictaccregwizz.NO_MATCH");
    }

    return dix.getMessage();
  }
コード例 #2
0
  /**
   * Create, execute and display a query to a dictionary (ContactDictImpl)
   *
   * @param dictContact the contact containing the database name
   * @param message the message containing the word
   */
  private void submitDictQuery(ContactDictImpl dictContact, Message message) {
    Message msg = this.createMessage("");

    String database = dictContact.getContactID();
    DictConnection conn = this.parentProvider.getConnection();
    boolean doMatch = false;

    String word;

    // Formatting the query message, if the word as one or more spaces we
    // put it between quotes to prevent errors
    word = message.getContent().replace("\"", "").trim();
    if (word.indexOf(' ') > 0) {
      word = "\"" + word + "\"";
    }

    // Try to get the definition of the work
    try {
      List<Definition> definitions = conn.define(database, word);
      msg = this.createMessage(retrieveDefine(definitions, word));
    } catch (DictException dx) {
      if (dx.getErrorCode()
          == DictReturnCode.NO_MATCH) { // No word found, we are going to try the match command
        doMatch = true;
      } else { // Otherwise we display the error returned by the server
        msg = this.createMessage(manageException(dx, database));
      }
    }

    if (doMatch) {
      // Trying the match command
      try {
        List<MatchWord> matchWords = conn.match(database, word, this.accountID.getStrategy());
        msg = this.createMessage(retrieveMatch(matchWords, word));
      } catch (DictException dx) {
        msg = this.createMessage(manageException(dx, database));
      }
    }

    // Send message
    fireMessageReceived(msg, dictContact);
  }