⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jwmacontroller.java

📁 java windows mda and reveus
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      }    } else if (dome.equals("move")) {      String[] messages =          session.getRequest().getParameterValues("numbers");      String destination =          session.getRequestParameter("destination");      if (messages == null || messages.length == 0) {        throw new JwmaException("message.move.missingnumbers");      } else if (destination == null) {        throw new JwmaException("message.move.missingdestination");      } else {        //check if it's about the active message        if (messages[0].trim().equals("actual")) {          doMoveActualMessage(session, destination);        } else {          doMoveMessages(session, destination, toInts(messages));        }      }    } else if (dome.equals("compose")) {      String to = session.getRequestParameter("to");      if (to == null) {        to = "";      }      boolean reply = new Boolean(          session.getRequestParameter("reply")      ).booleanValue();      boolean toall = new Boolean(          session.getRequestParameter("toall")      ).booleanValue();      boolean togglequote = new Boolean(          session.getRequestParameter("togglequote")      ).booleanValue();      //see if its a forward      boolean forward = new Boolean(          session.getRequestParameter("forward")      ).booleanValue();      //and if attachments should be forwarded      boolean attfwd = new Boolean(          session.getRequestParameter("withattachments")      ).booleanValue();      doComposeMessage(session, to, forward, reply, toall, togglequote, attfwd);      return;    } else if (dome.equals("composedraft")) {      String number = session.getRequestParameter("number");      if (number == null) {        throw new JwmaException("message.draft.missingnumber");      }      doComposeDraft(session, toInt(number));    } else if (dome.equals("delete")) {      String[] messages =          session.getRequest().getParameterValues("numbers");      if (messages == null || messages.length == 0) {        throw new JwmaException("message.delete.missingnumbers");      } else {        //check if it's about the active message        if (messages[0].trim().equals("actual")) {          doDeleteActualMessage(session);        } else {          doDeleteMessages(session, toInts(messages));        }      }    } else {      throw new JwmaException("message.action.invalid");    }  }//doDispatchMessageActions  /**   * Dispatches actions targeting <tt>preferences</tt>.   *   * @param session a <tt>JwmaSession</tt> instance.   * @param dome the task as <tt>String</tt>.   *   * @throws JwmaException if it fails to dispatch the request to a   *         method (i.e. invalid request), or the action method fails   *         to execute the task.   */  private void doDispatchPreferencesActions(      JwmaSession session, String dome)      throws JwmaException {    if (dome.equals("update")) {      doUpdatePreferences(session);    } else if (dome.equals("addmailid")) {      doAddMailIdentity(session);    } else if (dome.equals("removemailid")) {      //retrieve the uid      String uid = session.getRequestParameter("mid.uid");      if (uid == null) {        throw new JwmaException("preferences.mailid.missinguid");      } else {        doRemoveMailIdentity(session, uid);        return;      }    } else if (dome.equals("updatemailid")) {      //retrieve the uid      String uid = session.getRequestParameter("mid.uid");      if (uid == null) {        throw new JwmaException("preferences.mailid.missinguid");      } else {        doUpdateMailIdentity(session, uid);        return;      }    } else {      throw new JwmaException("preferences.action.invalid");    }  }//doDispatchPreferencesActions  /*** End Dispatchers *************************************************/  /*** Session Actions  ************************************************/  /**   * Handles a user login to the jwma system.   * <p>   * <ul>   * <li>Checks if a user account exists.</li>   * <li>Handles account creation according to settings.</li>   * <li>Initializes session with the post office.</li>   * <li>Ensures jwma specific folders are there (trash, archives).</li>   * <li>Redirects the user to the folder view.</li>   * <ul>   *   * @param session a <tt>JwmaSession</tt> instance.   * @param username of the user as <tt>String</tt>.   * @param password of the user as <tt>String</tt>.   * @param post office the name of a post office as <tt>String</tt>.   *   * @throws JwmaException if it fails to execute properly.   */  private void doLogin(JwmaSession session, String user, String passwd, String postoffice)      throws JwmaException {    log.debug("doLogin() called");    boolean storelogin =        new Boolean(session.getRequestParameter("remember")).booleanValue();    JwmaKernel kernel = JwmaKernel.getReference();    JwmaConfiguration config = kernel.getConfiguration();    boolean newAccount = false;    //set post office host, if not allowed or invalid,    //it will be the system's set default postoffice host    session.setPostOffice(config.getPostOfficeByName(postoffice));    log.debug("PostOffice set to: " + session.getPostOffice().getName());    //get the assembled id, session has no user yet    String identity = session.getUserIdentity(user);    //check if user exists (i.e. preferences exist for the user)    if (!kernel.getPrefsPersistencePlugin().isPersistent(identity)) {      //get settings to decide strategy      if (config.isAccountCreationEnabled()) {        newAccount = true;      } else {        //Forward to set view for account creation or        //for telling how it is done        session.redirect(JwmaKernel.ACCOUNT_CREATION_VIEW);      }    }    log.debug("identity=" + identity + ":prefsExist=" + (!newAccount));    //2. user exists for jwma -> authenticate user    session.authenticate(user, passwd, newAccount);    log.debug("Authenticated!");    //we have now a created store    JwmaStoreImpl store = session.getJwmaStore();    log.debug("Have Store!");    //store storeinfo bean    session.storeBean("jwma.storeinfo", (JwmaStoreInfo) store);    //store inboxinfo bean    session.storeBean("jwma.inboxinfo", store.getInboxInfo());    //store trashinfo bean    session.storeBean("jwma.trashinfo", store.getTrashInfo());    //store actual folder    session.storeBean("jwma.folder", store.getActualFolder());    //load contacts    if (kernel.getContactManagementPlugin().isPersistent(session.getPreferences().getContactDatabaseID())) {      log.debug("Loading contact database.");      session.storeBean("jwma.contacts",          kernel.getContactManagementPlugin()          .loadContacts(session.getPreferences().getContactDatabaseID())      );      log.debug("Loaded user's contact database.");    } else {      log.debug("Creating contact database.");      JwmaContactsImpl contacts = kernel.getContactManagementPlugin().createContacts();      session.getPreferences().setContactDatabaseID(contacts.getUID());      session.storeBean("jwma.contacts", contacts);    }    //add cookie if      if(storelogin) {        doSetCookie(session);      }    //redirect to folder view    session.redirect(JwmaKernel.FOLDER_VIEW);  }//doLogin  /**   * Logs a user out of a jwma system, ending the session.   *   * @param session a <tt>JwmaSession</tt> instance.   *   * @throws JwmaException if it fails to execute properly.   */  private void doLogout(JwmaSession session)      throws JwmaException {    try {      //perform cleanup of store      session.getJwmaStore().cleanup();      //ensure saving contactsdb      log.debug("Saving contacts database.");      JwmaKernel.getReference().getContactManagementPlugin()          .saveContacts((JwmaContactsImpl) session.getWebSession().getValue("jwma.contacts"));      //end session    } catch (JwmaException ex) {      throw new JwmaException("session.logout.failed").setException(ex);    } finally {      session.end();      session.redirect(JwmaKernel.LOGOUT_VIEW);    }  }//doLogout  /**   * Redirects a request to a given & possible view,   * to the last view or to the main view otherwise   * (defined by the root folder view).   * <i><b>Note:</b> the model instances are updated!</i>   *   * @param session a <tt>JwmaSession</tt> instance.   * @param view the view as <tt>String</tt>.   *   * @throws JwmaException if it fails to execute properly.   */  private void doRedirect(JwmaSession session, String view) {    try {      if (view != null) {        //clean whitespace        view.trim();        if (view.equals("last")) {          session.redirectToLast();          return;        } else if (view.equals("actual")) {          session.redirectToActual();          return;        } else if (view.equals("folder")) {          //dispatch to folder display, invoke update          session.getJwmaStore().getActualFolder().update(session.getJwmaStore());          session.redirect(JwmaKernel.FOLDER_VIEW);          return;        } else if (view.equals("message")) {          session.storeBean("jwma.message",              session.getJwmaStore().getActualFolder().getActualMessage()          );          session.redirect(JwmaKernel.MESSAGE_VIEW);        }      }      //if fall through here display root folder      session.storeBean("jwma.folder",          session.getJwmaStore().resetToRootFolder());      session.redirect(JwmaKernel.FOLDER_VIEW);      return;    } catch (Exception ex) {      log.error("Failed to redirect.", ex);      //JwmaKernel.getReference().debugLog().writeStackTrace(ex);    }  }//doRedirect  private void doSetCookie(JwmaSession session)      throws JwmaException {    HttpServletResponse res = session.getResponse();    StringBuffer cracker = new StringBuffer("");    cracker.append(session.getUsername())        .append(".")        .append(MD5.hash(session.getPostOffice().getName()));    Cookie polly = new Cookie("jwmalogin",cracker.toString());    polly.setPath("/webmail");    polly.setMaxAge(COOKIE_EXPIRES);    res.addCookie(polly);  }//doSetCookie  /*** End Session Actions  ***********************************************/  /*** Folder Actions  ****************************************************/  /**   * Prepares a given folder for display and redirects to the   * folder view.   *   * @param session a <tt>JwmaSession</tt> instance.   * @param foldername the full path of a valid folder of the   *        actual store.   *   * @throws JwmaException if it fails to execute properly.   */  private void doDisplayFolder(JwmaSession session, String foldername)      throws JwmaException {    JwmaStoreImpl store = session.getJwmaStore();    //1. check folder existence    if (!store.checkFolderExistence(foldername)) {      throw new JwmaException("folder.display.existence");    }    //2. store new actual folder, creation delegated to store    session.storeBean("jwma.folder",        store.setActualFolder(foldername)    );    //redirect to folder view    session.redirect(JwmaKernel.FOLDER_VIEW);  }//doDisplayFolder  /**   * Sorts the messages in the actual folder according to   * the given criteria and redirects to the folder view.   *   * @param session a <tt>JwmaSession</tt> instance.   * @param criteria a valid criteria for sorting the messages   *        in the actual folder.   *   * @throws JwmaException if it fails to execute properly.   */  private void doSortFolderMessages(JwmaSession session, int criteria)      throws JwmaException {    //1. get actual folder reference    JwmaFolderImpl folder = session.getJwmaStore().getActualFolder();    //2. ensure it is a folder holding messages    if (folder.hasMessages()) {      //3. get and sort the message info list      folder.getMessageInfoList().sort(criteria);    }    //4. remember set sort criteria    session.getPreferences().setMessageSortCriteria(criteria);    session.redirect(JwmaKernel.FOLDER_VIEW);    return;  }//doSortFolderMessages  /**   * Deletes the given folders and redirects to the folder view.   *   * @param session a <tt>JwmaSession</tt> instance.   * @param foldernames an array of strings; each <tt>String</tt>   *        representing the full path of a valid folder of the   *        actual store.   *   * @throws JwmaException if it fails to execute properly.   */  private void doDeleteFolders(JwmaSession session, String[] foldernames)      throws JwmaException {    //delete Folders by path    session.getJwmaStore().deleteFolders(foldernames);    //redirect to folder view

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -