Exemple #1
0
  public boolean execCommand(Protocol protocol, String msg) {
    final String cmd;
    final String param;
    int endCmd = msg.indexOf(' ');
    if (-1 != endCmd) {
      cmd = msg.substring(1, endCmd);
      param = msg.substring(endCmd + 1);
    } else {
      cmd = msg.substring(1);
      param = "";
    }
    String resource = param;
    String newMessage = "";

    int endNick = param.indexOf('\n');
    if (-1 != endNick) {
      resource = param.substring(0, endNick);
      newMessage = param.substring(endNick + 1);
    }
    String xml = null;
    final String on = "o" + "n";
    final String off = "o" + "f" + "f";
    if (on.equals(param) || off.equals(param)) {
      xml = Config.getConfigValue(cmd + ' ' + param, "/jabber-commands.txt");
    }
    if (null == xml) {
      xml = Config.getConfigValue(cmd, "/jabber-commands.txt");
    }
    if (null == xml) {
      return false;
    }

    XmppConnection xmppXml = ((Xmpp) protocol).getConnection();

    String jid = Jid.jimmJidToRealJid(getUserId());
    String fullJid = jid;
    if (isConference()) {
      String nick = ((XmppServiceContact) this).getMyName();
      fullJid = Jid.jimmJidToRealJid(getUserId() + '/' + nick);
    }

    xml = Util.replace(xml, "${jimm.caps}", xmppXml.getCaps());
    xml = Util.replace(xml, "${c.jid}", Util.xmlEscape(jid));
    xml = Util.replace(xml, "${c.fulljid}", Util.xmlEscape(fullJid));
    xml = Util.replace(xml, "${param.full}", Util.xmlEscape(param));
    xml = Util.replace(xml, "${param.res}", Util.xmlEscape(resource));
    xml = Util.replace(xml, "${param.msg}", Util.xmlEscape(newMessage));
    xml = Util.replace(xml, "${param.res.realjid}", Util.xmlEscape(getSubContactRealJid(resource)));
    xml = Util.replace(xml, "${param.full.realjid}", Util.xmlEscape(getSubContactRealJid(param)));

    xmppXml.requestRawXml(xml);
    return true;
  }
  public ContactEdit(Display display, Contact c) {
    this.display = display;
    parentView = display.getCurrent();

    StaticData sd = StaticData.getInstance();
    roster = sd.roster;

    Vector groups = sd.roster.groups.getRosterGroupNames();
    cf = Config.getInstance();

    f = new Form(SR.MS_ADD_CONTACT); // locale

    tJid = new TextField(SR.MS_USER_JID, null, 150, TextField.EMAILADDR);

    tNick = new TextField("Name", null, 32, TextField.ANY); // locale
    tGroup = new TextField(SR.MS_GROUP, null, 32, TextField.ANY); // locale

    tGrpList = new ChoiceGroup(SR.MS_GROUP, ConstMIDP.CHOICE_POPUP);
    tTranspList = new ChoiceGroup(SR.MS_TRANSPORT, ConstMIDP.CHOICE_POPUP);

    tAskSubscrCheckBox = new ChoiceGroup(SR.MS_SUBSCRIPTION, ChoiceGroup.MULTIPLE); // locale
    tAskSubscrCheckBox.append(SR.MS_ASK_SUBSCRIPTION, null); // locale

    tGrpList.addCommand(cmdSet);
    tGrpList.setItemCommandListener(this);

    tTranspList.addCommand(cmdSet);
    tTranspList.setItemCommandListener(this);

    // Transport droplist
    tTranspList.append(sd.account.getServer(), null);
    for (Enumeration e = sd.roster.getHContacts().elements(); e.hasMoreElements(); ) {
      Contact ct = (Contact) e.nextElement();
      Jid transpJid = ct.jid;
      if (transpJid.isTransport()) tTranspList.append(transpJid.getBareJid(), null);
    }
    tTranspList.append(SR.MS_OTHER, null); // locale

    try {
      String jid;
      if (c instanceof MucContact) {
        jid = Jid.toBareJid(((MucContact) c).realJid);
      } else {
        jid = c.getBareJid();
      }
      // edit contact
      tJid.setString(jid);
      tNick.setString(c.nick);

      if (c instanceof MucContact) {
        c = null;
        throw new Exception();
      }

      if (c.getGroupType() != Groups.TYPE_NOT_IN_LIST
          && c.getGroupType() != Groups.TYPE_SEARCH_RESULT) {
        // edit contact
        f.setTitle(jid);
        cmdOk = new Command("Update", Command.OK, 1); // locale
        newContact = false;
      } else c = null; // adding not-in-list
    } catch (Exception e) {
      c = null;
    } // if MucContact does not contains realJid

    int sel = -1;
    ngroups = 0;
    String grpName = "";
    if (c != null) grpName = c.getGroup().name;

    if (groups != null) {
      ngroups = groups.size();
      for (int i = 0; i < ngroups; i++) {
        String gn = (String) groups.elementAt(i);
        tGrpList.append(gn, null);

        if (gn.equals(grpName)) sel = i;
      }
    }

    // if (sel==-1) sel=groups.size()-1;
    if (sel < 0) sel = 0;
    // tGroup.setString(group(sel));

    if (c == null) {
      f.append(tJid);
      f.append(tTranspList);
    }
    updateChoise(tJid.getString(), tTranspList);
    f.append(tNick);

    tGrpList.append(SR.MS_NEWGROUP, null);

    tGrpList.setSelectedIndex(sel, true);

    grpFIndex = f.append(tGrpList);

    if (newContact) {
      f.append(tAskSubscrCheckBox);
      tAskSubscrCheckBox.setSelectedIndex(0, true);
    }

    f.addCommand(cmdOk);
    f.addCommand(cmdCancel);

    f.setCommandListener(this);
    f.setItemStateListener(this);

    display.setCurrent(f);
  }