/** Creates a new instance of AccountPicker */
  public AccountSelect(Display display, boolean enableQuit) {
    super();
    // this.display=display;

    setTitleItem(new Title(SR.MS_ACCOUNTS));

    accountList = new Vector();
    Account a;

    int index = 0;
    activeAccount = Config.getInstance().accountIndex;
    do {
      a = Account.createFromStorage(index);
      if (a != null) {
        accountList.addElement(a);
        a.active = (activeAccount == index);
        index++;
      }
    } while (a != null);
    if (accountList.isEmpty()) {
      a = Account.createFromJad();
      if (a != null) {
        // a.updateJidCache();
        accountList.addElement(a);
        rmsUpdate();
      }
    }
    attachDisplay(display);
    addCommand(cmdAdd);

    if (enableQuit) addCommand(cmdQuit);

    commandState();
    setCommandListener(this);
  }
 private void switchAccount(boolean login) {
   if (!login) parentView = StaticData.getInstance().roster;
   destroyView();
   Config cf = Config.getInstance();
   cf.accountIndex = cursor;
   cf.saveToStorage();
   Account.loadAccount(login);
 }
Ejemplo n.º 3
0
 public static Realm getDefault() throws RealmException {
   try {
     return new Realm(Config.getInstance().getDefaultRealm());
   } catch (RealmException re) {
     throw re;
   } catch (KrbException ke) {
     throw new RealmException(ke);
   }
 }
Ejemplo n.º 4
0
  public static void ajaxEditDocument(Long documentId, String newTitle, String newContent) {
    Document document = Document.findById(documentId);
    document.changeSubject(newTitle);

    Config config = Config.getInstance();
    User currentUser = User.findById(config.getSingedInUserId());
    Version newVersion = new Version(currentUser, document, newContent).save();
    System.out.println("* A new version is successfully created.");

    document.addVersion(newVersion);
    document.save();
  }
Ejemplo n.º 5
0
  /*
   * Create a document and save using Ajax
   */
  public static void ajaxCreateDocument(String subject, String content, Long parentId) {
    /*
     * Create a document and save
     * Create first version of the document
     * Create permalink of that version
     */

    // By creating a document, I assume that the document is created by the
    // program, and versions in the document are created by users
    // Create a new document for current user, current user is defined in Config
    Document document = new Document(subject, parentId).save();
    System.out.println("* A new document is successfully created.");

    Config config = Config.getInstance();
    User currentUser = User.findById(config.getSingedInUserId());
    Version aversion = new Version(currentUser, document, content).save();
    System.out.println("* A new version is successfully created.");

    document.addVersion(aversion);
    Documents.ajaxAllDocuments();
  }
Ejemplo n.º 6
0
  /**
   * Parses the [capaths] stanza of the configuration file for a list of realms to traverse to
   * obtain credentials from the initiating realm cRealm to the target realm sRealm.
   *
   * <p>For a given client realm C there is a tag C in [capaths] whose subtag S has a value which is
   * a (possibly partial) path from C to S. When the path is partial, it contains only the tail of
   * the full path. Values of other subtags will be used to build the full path. The value "." means
   * a direct path from C to S. If realm S does not appear as a subtag, there is no path defined
   * here.
   *
   * <p>The implementation ignores all values which equals to C or S, or a "." in multiple values,
   * or any duplicated realm names.
   *
   * <p>When a path value has more than two realms, they can be specified with multiple key-value
   * pairs each having a single value, but the order must not change.
   *
   * <p>For example:
   *
   * <p>[capaths] TIVOLI.COM = { IBM.COM = IBM_LDAPCENTRAL.COM MOONLITE.ORG IBM_LDAPCENTRAL.COM =
   * LDAPCENTRAL.NET LDAPCENTRAL.NET = . }
   *
   * <p>TIVOLI.COM has a direct path to LDAPCENTRAL.NET, which has a direct path to
   * IBM_LDAPCENTRAL.COM. It also has a partial path to IBM.COM being "IBM_LDAPCENTRAL.COM
   * MOONLITE.ORG". Merging these info together, a full path from TIVOLI.COM to IBM.COM will be
   *
   * <p>TIVOLI.COM -> LDAPCENTRAL.NET -> IBM_LDAPCENTRAL.COM -> IBM_LDAPCENTRAL.COM -> MOONLITE.ORG
   *
   * <p>Please note the sRealm IBM.COM does not appear in the path.
   *
   * @param cRealm the initiating realm
   * @param sRealm the target realm, not the same as cRealm
   * @returns array of realms including at least cRealm as the first element
   * @throws KrbException if the config does not contain a sub-stanza for cRealm in [capaths] or the
   *     sub-stanza does not contain sRealm as a tag
   */
  private static String[] parseCapaths(String cRealm, String sRealm) throws KrbException {

    // This line could throw a KrbException
    Config cfg = Config.getInstance();

    if (!cfg.exists("capaths", cRealm, sRealm)) {
      throw new KrbException("No conf");
    }

    LinkedList<String> path = new LinkedList<>();

    String head = sRealm;
    while (true) {
      String value = cfg.getAll("capaths", cRealm, head);
      if (value == null) {
        break;
      }
      String[] more = value.split("\\s+");
      boolean changed = false;
      for (int i = more.length - 1; i >= 0; i--) {
        if (path.contains(more[i])
            || more[i].equals(".")
            || more[i].equals(cRealm)
            || more[i].equals(sRealm)
            || more[i].equals(head)) {
          // Ignore invalid values
          continue;
        }
        changed = true;
        path.addFirst(more[i]);
      }
      if (!changed) break;
      head = path.getFirst();
    }
    path.addFirst(cRealm);
    return path.toArray(new String[path.size()]);
  }
  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);
  }