Package org.apache.struts.action

Examples of org.apache.struts.action.ActionMessages


   * @throws Exception
   */
  protected ActionForward doPublishDraftDirectly(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    ActionMessages msgs = new ActionMessages();
    DiaryForm log = (DiaryForm) form;

    while (true) {
      UserBean loginUser = super.getLoginUser(request, response);
      if (loginUser == null) {
        msgs.add("log", new ActionMessage("error.user_not_login"));
        break;
      }
      if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
        msgs.add("log", new ActionMessage("error.user_not_available"));
        break;
      }
      SiteBean site = super.getSiteByID(log.getSid());
      if (site == null) {
        msgs.add("log", new ActionMessage("error.site_not_available"));
        break;
      }
      // �û����������ռǷ��౻����
      DiaryBean journal = DiaryDAO.getDiaryByID(log.getId());
      if (journal == null
          || journal.getStatus() != DiaryBean.STATUS_DRAFT
          || journal.getOwner().getId() != loginUser.getId()) {
        msgs.add("draft", new ActionMessage("error.draft_not_exists"));
        break;
      }
      boolean catalog_can_access = false;
      // վ�����Է���վ�ڵ��κη���
      if (site.isOwner(loginUser)) {
        catalog_can_access = true;
      } else {
        // �г��û��ڸ�վ��ɷ��ʵ��ռǷ���
        List catalogs = CatalogDAO.listCatalogs(site, loginUser, true);
        for (int i = 0; catalogs != null && i < catalogs.size(); i++) {
          CatalogBean t_catalog = (CatalogBean) catalogs.get(i);
          if (t_catalog.getId() == log.getCatalogId()) {
            catalog_can_access = true;
            break;
          }
        }
      }
      if (!catalog_can_access) {
        msgs.add("log", new ActionMessage("error.catalog_deny",
            new Integer(log.getCatalogId())));
        break;
      }
      // ��ȡ�����²ݸ����Ȼ���״̬��Ϊ����
      journal.setClient(new ClientInfo(request, log.getClientType()));
      journal.setViewCount(0);
      journal.setStatus(DiaryBean.STATUS_NORMAL);
      journal.setWriteTime(new Date());
      DiaryDAO.flush();
      break;
    }
    if (!msgs.isEmpty()) {
      saveMessages(request, msgs);
      return mapping.findForward("editlog");
    }
    return makeForward(mapping.findForward("diary"), log.getSid());
  }
View Full Code Here


   * @throws Exception
   */
  protected ActionForward doPublishDraft(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response, String identity)
      throws Exception {
    ActionMessages msgs = new ActionMessages();
    DiaryForm log = (DiaryForm) form;
    //super.validateClientId(request, log);
    while (true) {
      // ����ռDZ����ֵ
      if (StringUtils.isEmpty(log.getTitle())) {
        msgs.add("title", new ActionMessage("error.empty_not_allowed"));
        break;
      }
      if (StringUtils.isEmpty(log.getContent())) {
        msgs.add("content",
            new ActionMessage("error.empty_not_allowed"));
        break;
      }
      UserBean loginUser = super.getLoginUser(request, response);
      if (loginUser == null) {
        msgs.add("log", new ActionMessage("error.user_not_login"));
        break;
      }
      if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
        msgs.add("log", new ActionMessage("error.user_not_available"));
        break;
      }
      SiteBean site = super.getSiteByID(log.getSid());
      if (site == null) {
        msgs.add("log", new ActionMessage("error.site_not_available"));
        break;
      }
      boolean catalog_can_access = false;
      CatalogBean catalog = null;
      // վ�����Է���վ�ڵ��κη���
      if (site.isOwner(loginUser)) {
        catalog = CatalogDAO.getCatalogByID(log.getCatalogId());
        if (catalog.getSite().getId() == site.getId())
          catalog_can_access = true;
      } else {
        // �г��û��ڸ�վ��ɷ��ʵ��ռǷ���
        List catalogs = CatalogDAO.listCatalogs(site, loginUser, true);
        for (int i = 0; catalogs != null && i < catalogs.size(); i++) {
          CatalogBean t_catalog = (CatalogBean) catalogs.get(i);
          if (t_catalog.getId() == log.getCatalogId()) {
            catalog = t_catalog;
            catalog_can_access = true;
            break;
          }
        }
      }
      if (!catalog_can_access) {
        msgs.add("log", new ActionMessage("error.catalog_deny",
            new Integer(log.getCatalogId())));
        break;
      }
      // �û����������ռǷ��౻����
      DiaryBean journal = DiaryDAO.getDiaryByID(log.getId());
      if (journal == null
          || journal.getStatus() != DiaryBean.STATUS_DRAFT) {
        msgs.add("draft", new ActionMessage("error.draft_not_exists"));
        break;
      }
      // ��鱳�������Ƿ���Ч
      MusicBean song = MusicDAO.getMusicByID(log.getBgSound());
      if (song != null && song.getSite().getId() == site.getId()) {
        journal.setBgSound(song);
      }
      if (StringUtils.isEmpty(log.getWeather()))
        journal.setWeather(DEFAULT_WEATHER);
      else
        journal.setWeather(log.getWeather());
      if (StringUtils.isEmpty(log.getAuthor()))
        journal.setAuthor(loginUser.getNickname());
      else
        journal.setAuthor(log.getAuthor());
      if (StringUtils.isEmpty(log.getTags()))
        journal.setKeyword(null);
      else
        journal.setKeyword(log.getTags());
      if (StringUtils.isEmpty(log.getAuthorUrl()))
        journal.setAuthorUrl(null);
      else
        journal.setAuthorUrl(log.getAuthorUrl());
      if (StringUtils.isEmpty(log.getRefUrl()))
        journal.setRefUrl(null);
      else
        journal.setRefUrl(log.getRefUrl());
      // ��ȡ�����²ݸ����Ȼ���״̬��Ϊ����
      journal.setCatalog(catalog);
      journal.setClient(new ClientInfo(request, log.getClientType()));
      String ssn_id = RequestUtils.getDlogSessionId(request);
      boolean wml = WML_IDENTITY.equalsIgnoreCase(identity);
      String content = autoCompileContent(request, site, log.getContent(), loginUser.getId(), ssn_id, wml);
      journal.setContent(content);
      journal.setSize(content.getBytes().length);
      journal.setMoodLevel(log.getMoodLevel());
      journal.setReplyNotify(log.getNotify());
      journal.setViewCount(0);
      journal.setStatus(DiaryBean.STATUS_NORMAL);
      journal.setTitle(log.getTitle());
      journal.setWriteTime(new Date());
      DiaryDAO.create(journal, log.getBookmark() == 1);
      // �����ϴ�����Ϣ
      pickupUploadFileItems(request, response, loginUser.getId(), site, journal
          .getId(), DiaryBean.TYPE_DIARY);
      break;
    }
    if (!msgs.isEmpty()) {
      saveMessages(request, msgs);
      return mapping.findForward("editlog");
    }
    return makeForward(mapping.findForward("diary"), log.getSid());
  }
View Full Code Here

   * @throws Exception
   */
  protected ActionForward doSaveAsDraft(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    ActionMessages msgs = new ActionMessages();
    DiaryForm log = (DiaryForm) form;
    //super.validateClientId(request, log);
    UserBean loginUser = super.getLoginUser(request, response);
    while (true) {
      if (loginUser == null) {
        msgs.add("log", new ActionMessage("error.user_not_login"));
        break;
      }
      if (loginUser.getStatus() != UserBean.STATUS_NORMAL) {
        msgs.add("log", new ActionMessage("error.user_not_available"));
        break;
      }
     
      SiteBean site = super.getSiteByID(log.getSid());
      if (site == null) {
        msgs.add("log", new ActionMessage("error.site_not_available"));
        break;
      }
      boolean catalog_can_access = false;
      CatalogBean catalog = null;
      // վ�����Է���վ�ڵ��κη���
      if (site.isOwner(loginUser)) {
        catalog = CatalogDAO.getCatalogByID(log.getCatalogId());
        if (catalog.getSite().getId() == site.getId())
          catalog_can_access = true;
      } else {
        // �г��û��ڸ�վ��ɷ��ʵ��ռǷ���
        List catalogs = CatalogDAO.listCatalogs(site, loginUser, true);
        for (int i = 0; catalogs != null && i < catalogs.size(); i++) {
          CatalogBean t_catalog = (CatalogBean) catalogs.get(i);
          if (t_catalog.getId() == log.getCatalogId()
              && t_catalog.getSite().getId() == site.getId()) {
            catalog = t_catalog;
            catalog_can_access = true;
            break;
          }
        }
      }
      //�û����������ռǷ��಻������
      if(!catalog_can_access){
        msgs.add("log", new ActionMessage("error.catalog_deny",
            new Integer(log.getCatalogId())));
        break;
      }
      // ����ռDZ����ֵ
      if (StringUtils.isEmpty(log.getTitle())){
        msgs.add("title", new ActionMessage(
            "error.empty_not_allowed"));
        break;
      }
      if (StringUtils.isEmpty(log.getContent())){
        msgs.add("content", new ActionMessage(
            "error.empty_not_allowed"));
        break;
      }
      if (StringUtils.isEmpty(log.getWeather()))
        log.setWeather(DEFAULT_WEATHER);
      if (StringUtils.isEmpty(log.getAuthor()))
        log.setAuthor(loginUser.getNickname());
      if (StringUtils.isEmpty(log.getTags()))
        log.setTags(null);
      if (StringUtils.isEmpty(log.getAuthorUrl()))
        log.setAuthorUrl(null);
      if (StringUtils.isEmpty(log.getRefUrl()))
        log.setRefUrl(null);
      // ����JournalBean
      DiaryBean journal = new DiaryBean();
      journal.setOwner(loginUser);
      journal.setSite(site);
      journal.setAuthor(super.autoFiltrate(site,log.getAuthor()));
      journal.setAuthorUrl(log.getAuthorUrl());
      journal.setCatalog(catalog);
      journal.setClient(new ClientInfo(request, log
          .getClientType()));
      journal.setContent(super.autoFiltrate(site,log.getContent()));
      journal.setMoodLevel(log.getMoodLevel());
      journal.setRefUrl(log.getRefUrl());
      journal.setReplyNotify(log.getNotify());
      journal.setStatus(DiaryBean.STATUS_DRAFT);
      journal.setKeyword(super.autoFiltrate(site,log.getTags()));
      journal.setTitle(super.autoFiltrate(site,log.getTitle()));
      journal.setWeather(log.getWeather());
      journal.setWriteTime(DateUtils.mergeDateTime(log.getWriteDate(), log.getWriteTime()).getTime());
      Date curTime = new Date();
      if(journal.getWriteTime()==null || journal.getWriteTime().after(curTime))
        journal.setWriteTime(curTime);
      DiaryDAO.create(journal, false);
      //�����ϴ�����Ϣ
      super.pickupUploadFileItems(request, response, loginUser
          .getId(), site, journal.getId(), DiaryBean.TYPE_DIARY);
   
      break;
    }
    if (!msgs.isEmpty()) {
      saveMessages(request, msgs);
      return mapping.findForward("addlog");
    }
    return makeForward(mapping.findForward("draft"), log.getSid());
  }
View Full Code Here

      HttpServletRequest request, HttpServletResponse response)
      throws Exception
  {
    LinkForm lform = (LinkForm)form;
    super.validateClientId(request, lform);
    ActionMessages msgs = new ActionMessages();
    if(StringUtils.isEmpty(lform.getTitle())){
      msgs.add("title", new ActionMessage("error.link_title_empty"));
    }
    else if(StringUtils.isEmpty(lform.getUrl())){
      msgs.add("url", new ActionMessage("error.link_url_empty"));
    }
    else{
      LinkBean lbean = new LinkBean();
      lbean.setCreateTime(new Date());
      lbean.setSiteId(lform.getSid());
      lbean.setTitle(lform.getTitle());
      lbean.setUrl(lform.getUrl());
      lbean.setType(lform.getType());
      lbean.setStatus(lform.getStatus());
      try{
        LinkDAO.create(lbean, lform.getId(), (lform.getDirection()==1));
      }catch(Exception e){
        msgs.add("link", new ActionMessage("error.database", e.getMessage()));
      }
    }
   
    if(!msgs.isEmpty())
      return mapping.getInputForward();
   
    return makeForward(mapping.findForward("links"), lform.getSid());
  }
View Full Code Here

      int individualId = userObject.getIndividualID();
      String typeOfActivity = "";

      // Check the session for an existing error message (possibly from the
      // delete handler)
      ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");
      if (allErrors != null) {
        saveErrors(request, allErrors);
        session.removeAttribute("listErrorMessage");
      }
View Full Code Here

        CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();

    try {
      FORWARD_final = FORWARD_save;

      ActionMessages allErrors = new ActionMessages();

      HttpSession session = request.getSession();

      ((ActivityForm)form).setLocale(request.getLocale());
      // populate form bean for previous sub-activity
      PopulateForm populateForm = new PopulateForm();

      // set the form elements
      populateForm.setForm(request, form);

      // get form with respect to new opening page
      form = populateForm.getForm(request, form, ConstantKeys.DETAIL);
      ((ActivityForm)form).setLocale(request.getLocale());

      // populate VOX
      ActivityVOX activityVOX = new ActivityVOX(form);

      // initialize VO
      ActivityVO activityVO = activityVOX.getVO();

      UserObject userObject = (UserObject)session.getAttribute("userobject");
      int IndividualId = userObject.getIndividualID();

      // this method will convert the date to GMT
      String currTimeZone = userObject.getUserPref().getTimeZone();
      activityVO.changeTimeZoneOfAllDates(currTimeZone, "EST");

      String emailinvitation = ((ActivityForm)form).getActivityEmailInvitation();
      if (emailinvitation != null && emailinvitation.equals("on")) {
        ContactFacadeHome cfh = (ContactFacadeHome)CVUtility.getHomeObject(
            "com.centraview.contact.contactfacade.ContactFacadeHome", "ContactFacade");
        try {
          ContactFacade remote = cfh.create();
          remote.setDataSource(dataSource);
          // Static 2 because we are looking for the Individual's Primary Email
          // Address
          String emailAddress = remote.getPrimaryEmailAddress(IndividualId, 2);
          if (emailAddress == null || emailAddress.equals("")) {
            allErrors
                .add(
                    ActionMessages.GLOBAL_MESSAGE,
                    new ActionMessage(
                        "error.freeForm",
                        "Error while sending email invitations. You do not have an email address configured. Please configure a primary email address in order to send email invitations."));
View Full Code Here

    HttpSession session = request.getSession(true);

    // Check the session for an existing error message (possibly from the delete
    // handler)
    ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");

    if (allErrors != null) {
      saveErrors(request, allErrors);
      session.removeAttribute("listErrorMessage");
    }
View Full Code Here

      HttpSession session = request.getSession(true);
      request.setAttribute(AccountConstantKeys.TYPEOFSUBMODULE, AccountConstantKeys.INVENTORY);

      InventoryForm invenForm = (InventoryForm)request.getAttribute("inventoryform");

      ActionMessages allErrors = new ActionMessages();

      // now, check the account ID on the form...
      if (invenForm.getItemName() == null || invenForm.getItemName().length() <= 0) {
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
            "error.general.requiredField", "Item"));
      }

      // now, check the account ID on the form...
      if (invenForm.getLocationName() == null || invenForm.getLocationName().length() <= 0) {
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
            "error.general.requiredField", "Location"));
      }
      int invID = 0;

      if (invenForm != null)
        invID = invenForm.getInventoryID();

      if (!allErrors.isEmpty()) {
        saveErrors(request, allErrors);
        request.setAttribute("inventoryform", invenForm);
        if (invID > 0) {
          FORWARD_final = FORWARD_save;
        } else {
View Full Code Here

      UserObject userObject = (UserObject)session.getAttribute("userobject");
      int individualId = userObject.getIndividualID();

      // Check the session for an existing error message (possibly from the
      // delete handler)
      ActionMessages allErrors = (ActionMessages)session.getAttribute("listErrorMessage");
      if (allErrors != null) {
        saveErrors(request, allErrors);
        session.removeAttribute("listErrorMessage");
      }
View Full Code Here

    HttpSession session = request.getSession();
    UserObject userObject = (UserObject)session.getAttribute("userobject");

    int individualID = userObject.getIndividualID(); // logged in user

    ActionMessages allErrors = new ActionMessages();
    String forward = "displayComposeForm";

    ActionMessages messages = new ActionMessages();

    // "composeMailForm", defined in struts-config-email.xml
    DynaActionForm emailForm = (DynaActionForm)form;

    // Populate the Attachments In-Case. If we face any problem while sending
    // email.
    // Populating the ArrayList with the DDNameValue.
    ArrayList attachments = new ArrayList();
    ArrayList attachmentFileIDs = new ArrayList();
    String[] tempAttachmentMap = (String[])emailForm.get("attachments");

    if (tempAttachmentMap != null && tempAttachmentMap.length > 0) {
      for (int i = 0; i < tempAttachmentMap.length; i++) {
        String fileKeyName = tempAttachmentMap[i];
        if (fileKeyName != null) {
          int indexOfHash = fileKeyName.indexOf("#");
          if (indexOfHash != -1) {
            int lenString = fileKeyName.length();
            String fileID = fileKeyName.substring(0, indexOfHash);
            String fileName = fileKeyName.substring(indexOfHash + 1, lenString);
            attachments.add(new DDNameValue(fileID + "#" + fileName, fileName));
            attachmentFileIDs.add(new Integer(fileID));
          }
        }
      }
    }
    // Setting the Attachments to form.
    emailForm.set("attachmentList", attachments);

    try {
      MailHome home = (MailHome)CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");
      Mail remote = home.create();
      remote.setDataSource(dataSource);

      // create a MailMessageVO
      MailMessageVO messageVO = new MailMessageVO();

      Integer messageID = new Integer(0);

      messageVO.setMessageID(messageID.intValue());

      Integer accountID = (Integer)emailForm.get("accountID");
      messageVO.setEmailAccountID(accountID.intValue());

      // IMPORTANT: Because we use this same handler to do the save "Template"
      // functionality, note the logic below. Here, we're getting the folder ID
      // for the folder where we are going to store the message. Instead of
      // writing
      // a second handler for Save Template that did almost the same exact thing
      // as this handler, I created a SaveTemplateHandler that just sets one
      // Boolean
      // request attribute named "saveTemplate". If that attribute is set to
      // true
      // here, then we'll get the folderID of the Templates folder instead of
      // the
      // Drafts folder. That is the ONLY difference between Draft and Template.
      String folderName = MailFolderVO.DRAFTS_FOLDER_NAME;
      Boolean saveTemplate = (Boolean)request.getAttribute("saveTemplate");
      if (saveTemplate != null && saveTemplate.booleanValue() == true) {
        messageID = (Integer)emailForm.get("templateID");
        folderName = MailFolderVO.TEMPLATES_FOLDER_NAME;
      } else {
        messageID = (Integer)emailForm.get("savedDraftID");
      }
      messageVO.setMessageID(messageID.intValue());
      MailFolderVO draftsFolder = remote.getEmailFolderByName(accountID.intValue(), folderName);
      messageVO.setEmailFolderID(draftsFolder.getFolderID());

      MailAccountVO accountVO = remote.getMailAccountVO(accountID.intValue());
      if (accountVO == null) {
        accountVO = new MailAccountVO();
      }

      InternetAddress fromAddress = new InternetAddress(accountVO.getEmailAddress(), accountVO
          .getAccountName());
      messageVO.setFromAddress(fromAddress.toString());

      messageVO.setReplyTo(accountVO.getReplyToAddress());

      String subject = (String)emailForm.get("subject");
      messageVO.setSubject(subject);

      String body = (String)emailForm.get("body");
      messageVO.setBody(body);

      Boolean composeInHTML = (Boolean)emailForm.get("composeInHTML");
      if (composeInHTML.booleanValue()) {
        messageVO.setContentType(MailMessageVO.PLAIN_TEXT_TYPE);
      } else {
        messageVO.setContentType(MailMessageVO.HTML_TEXT_TYPE);
      }

      // To: is *NOT* a required field here
      ArrayList toList = this.parseAddresses((String)emailForm.get("to"));
      messageVO.setToList(toList);

      ArrayList ccList = this.parseAddresses((String)emailForm.get("cc"));
      messageVO.setCcList(ccList);

      ArrayList bccList = this.parseAddresses((String)emailForm.get("bcc"));
      messageVO.setBccList(bccList);

      Date receivedDate = new Date();
      messageVO.setReceivedDate(receivedDate);

      // Handle attachments - the attachment handler puts a ArrayList
      // This ArrayList contains the list of attached fileIDs.
      // So we'll get that ArrayList, iterate through it, creating a
      // CvFileVO object for each attachment, then add that file VO
      // to the messageVO object which will take care of the rest in
      // the EJB layer. Note that in the future, we'll want to make
      // this better by not saving the attachment list on the session.
      // So if you intend to modify this code, please consult the rest
      // of the team to see if it makes sense to make that change now.
      // Also, if you make a change here, you must make sure the
      // attachment handling code in ForwardHandler reflects your changes.
      if (attachmentFileIDs != null && attachmentFileIDs.size() > 0) {
        CvFileFacade fileRemote = new CvFileFacade();

        for (int i = 0; i < attachmentFileIDs.size(); i++) {
          int fileID = ((Integer)attachmentFileIDs.get(i)).intValue();
          // get the CvFileVO from the EJB layer
          CvFileVO fileVO = fileRemote.getFile(individualID, fileID, dataSource);
          if (fileVO != null) {
            // add this attachment to the messageVO
            messageVO.addAttachedFiles(fileVO);
          }
        } // end while (attachIter.hasNext())
      } // end if (attachmentMap != null && attachmentMap.size() > 0)

      remote.saveDraft(individualID, messageVO);
      // **ATTENTION** Note the "tricky" logic here. We're using the action
      // errors framework to send a *SUCCESS* message to the user!!!
      // We're going to add a message to the error list *only* if there
      // were no errors up to this point. In all cases, we're going to save
      // the error messages and forward back to the Compose.do handler.
      if (allErrors.isEmpty()) {
        messages.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("error.freeForm",
            "Message saved in " + folderName + " folder."));
        saveMessages(request, messages);
      }
      saveErrors(request, allErrors);

View Full Code Here

TOP

Related Classes of org.apache.struts.action.ActionMessages

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.