Package org.apache.struts.action

Examples of org.apache.struts.action.DynaActionForm


    MailHome mailHome = (MailHome) CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");
    try {
      HttpSession session = request.getSession();
      UserObject userObject = (UserObject) session.getAttribute("userobject");
      int individualID = userObject.getIndividualID();
      DynaActionForm dynaform = (DynaActionForm) form;
      String mergeType = (String) dynaform.get("mergetype");

      String actionType = null;
      if (request.getParameter("actionType") != null) {
        actionType = request.getParameter("actionType");
      }

      int categoryId = this.getCategoryIdFromType(mergeType);
      PrintTemplate PTRemote = PTHome.create();
      PTRemote.setDataSource(dataSource);
      AdvancedSearch remoteAdvancedSearch = advancedSearchHome.create();
      remoteAdvancedSearch.setDataSource(dataSource);
      String savedsearch1 = "";
      String specificentity = "";
      String entitysavedsearch = "";
      if (mergeType.equals("EMAIL")) {
        // collect the Account List and set it to the dynaActionForm.
        Mail mailRemote = mailHome.create();
        mailRemote.setDataSource(dataSource);
        ArrayList accountIDList = mailRemote.getUserAccountList(individualID);
        // also adding delegated accounts
        accountIDList.addAll(mailRemote.getDelegatedAccountList(individualID));
        ArrayList accountList = new ArrayList(); // this, we're sending to the
                                                  // form
        if (accountIDList.size() > 0) {
          // get the details of each account
          Iterator iter = accountIDList.iterator();
          while (iter.hasNext()) {
            Number accountID = (Number) iter.next();
            MailAccountVO accountVO = mailRemote.getMailAccountVO(accountID.intValue());
            InternetAddress address = new InternetAddress(accountVO.getEmailAddress(), accountVO.getAccountName());
            LabelValueBean accountDetails = new LabelValueBean(address.toString(), accountID.toString());
            accountList.add(accountDetails);
          }
        }
        dynaform.set("accountList", accountList);
      } // if (mergeType.equals("EMAIL"))
      entitysavedsearch = (String) dynaform.get("entitysavedsearch");
      if (entitysavedsearch.equals("ENTITY")) {
        savedsearch1 = (String) dynaform.get("savedsearch1");
      }
      if (entitysavedsearch.equals("SPECIFICENTITY")) {
        specificentity = (String) dynaform.get("specificentity");
      }
      // So if this is an email or print merge basically we need to gather up
      // a whole buttload of information to figure out which individuals will
      // be getting the message
      if (specificentity.equals("SPECIFICPRIMARY") && entitysavedsearch.equals("SPECIFICENTITY")) {
        // get the primary contact for this entity, they are the target
        // recipient
        String entityid = (String) dynaform.get("selectedEntityId");
        ArrayList entityIdCollection = new ArrayList();
        entityIdCollection.add(entityid);
        Collection contactID = PTRemote.getContactsForEntity(entityIdCollection, true);
        Iterator contactIdIterator = contactID.iterator();
        HashMap individualIds = new HashMap();
        if (contactIdIterator.hasNext()) {
          Number individualId = (Number) contactIdIterator.next();
          individualIds.put(individualId.toString(), individualId.toString());
        }
        dynaform.set("toIndividuals", individualIds);
      } else if (specificentity.equals("SPECIFICALL") && entitysavedsearch.equals("SPECIFICENTITY")) {
        // All individuals associated with the selected entity are
        // to be recipients
        String entityid = (String) dynaform.get("selectedEntityId");
        ArrayList entityIdCollection = new ArrayList();
        entityIdCollection.add(entityid);
        Collection contactID = PTRemote.getContactsForEntity(entityIdCollection, false);
        Iterator contactIdIterator = contactID.iterator();
        HashMap individualIds = new HashMap();
        while (contactIdIterator.hasNext()) {
          Number individualId = (Number) contactIdIterator.next();
          individualIds.put(individualId.toString(), individualId.toString());
        }
        dynaform.set("toIndividuals", individualIds);
      } else if (specificentity.equals("SPECIFICCONTACT") && entitysavedsearch.equals("SPECIFICENTITY")) {
        // specific
        String individualid = (String) dynaform.get("individualId");
        HashMap individualIds = new HashMap();
        individualIds.put(individualid, individualid);
        dynaform.set("toIndividuals", individualIds);
      } else if (entitysavedsearch.equals("INDIVIDUAL")) {
        String individualSearchId = (String) dynaform.get("individualSearchId");
        ArrayList results = new ArrayList();
        results.addAll(remoteAdvancedSearch.performSearch(individualID, Integer.parseInt(individualSearchId), "ADVANCE", null));
        HashMap individualIds = new HashMap();
        for (int i = 0; i < results.size(); i++) {
          Number resultId = (Number) results.get(i);
          // I stuck the key and value in to this hashmap as the same string
          // as that is how the rest of print templates is written and I
          // didn't have time to make it more reasonable.
          individualIds.put(resultId.toString(), resultId.toString());
        }
        dynaform.set("toIndividuals", individualIds);
      } else if (entitysavedsearch.equals("ENTITY") && savedsearch1.equals("PRIMARY")) {
        // this is when an entity saved search is selected, and we need to
        // get the individualid's of the primary contacts for the found set
        // of entities.
        String entitySearchId = (String) dynaform.get("entityId");
        ArrayList results = new ArrayList();
        results.addAll(remoteAdvancedSearch.performSearch(individualID, Integer.parseInt(entitySearchId), "ADVANCE", null));
        // results contains our collection of entity ids.
        Collection contactID = PTRemote.getContactsForEntity(results, true);
        Iterator contactIdIterator = contactID.iterator();
        HashMap individualIds = new HashMap();
        while (contactIdIterator.hasNext()) {
          Number individualId = (Number) contactIdIterator.next();
          individualIds.put(individualId.toString(), individualId.toString());
        }
        dynaform.set("toIndividuals", individualIds);
      } else if (entitysavedsearch.equals("ENTITY") && savedsearch1.equals("ALL")) {
        // This is exactly the same as above, except we are getting all
        // individuals instead of just primary contacts.
        String entitySearchId = (String) dynaform.get("entityId");
        ArrayList results = new ArrayList();
        results.addAll(remoteAdvancedSearch.performSearch(individualID, Integer.parseInt(entitySearchId), "ADVANCE", null));
        // results contains our collection of entity ids.
        Collection contactID = PTRemote.getContactsForEntity(results, false);
        Iterator contactIdIterator = contactID.iterator();
        HashMap individualIds = new HashMap();
        while (contactIdIterator.hasNext()) {
          Number individualId = (Number) contactIdIterator.next();
          individualIds.put(individualId.toString(), individualId.toString());
        }
        dynaform.set("toIndividuals", individualIds);
      } // end else if (entitysavedsearch.equals("ENTITY") &&
      request.setAttribute("body", "new");
      // now we finished getting the buttload of info.
      // So get the templates.
      Collection templateList = PTRemote.getallPrintTemplate(individualID, categoryId);
      session.setAttribute("mergeType", mergeType);
      dynaform.set("templateList", templateList);
      PrintTemplateVO ptVO = new PrintTemplateVO();
      String id = (String) dynaform.get("id");

      Integer templateId = null;
      // If the id is set on the form bean get the selected template.
      // Otherwise get the default.
      if (id != null && !id.equals("")) {
        try {
          templateId = Integer.valueOf(id);
        } catch (Exception e) {}
      }
      // anyway somehow we got the "Default" print template. So put it in the
      // bean
      if (templateId == null) {
        try {
          ptVO = PTRemote.getDefaultPrintTemplate(individualID, categoryId);
        } catch (Exception e) {
          logger.error("[Exception] PTListHandler.Execute Handler ", e);
          throw new ServletException(e);
        }
      } else {
        try {
          ptVO = PTRemote.getPrintTemplate(templateId.intValue());
        } catch (Exception e) {
          logger.error("[execute] Exception thrown.", e);
          throw new ServletException(e);
        }
      }
      dynaform.set("artifactname", ptVO.getArtifactName());
      dynaform.set("artifactid", String.valueOf(ptVO.getArtifactId()));
      if (actionType == null) {
        dynaform.set("templateData", ptVO.getPtData());
      }
      dynaform.set("templateName", ptVO.getPtname());
      dynaform.set("id", String.valueOf(ptVO.getPtdetailId()));
      dynaform.set("categoryId", String.valueOf(ptVO.getPtcategoryId()));
      if (ptVO.getPtsubject() != null) {
        dynaform.set("templatesubject", ptVO.getPtsubject());
      }
      FORWARD_final = FORWARD_newtemplate;
    } catch (Exception e) {
      logger.error("[Exception] PTListHandler.Execute Handler ", e);
      FORWARD_final = GLOBAL_FORWARD_failure;
View Full Code Here


    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);

View Full Code Here

  protected SearchVO getSearchVOFromForm(ActionForm form, HttpServletRequest request) throws IOException, ServletException
  {
    // The SearchVO we need should only consist of an array of searchCriteria
    // and a moduleid.
    DynaActionForm advancedSearchForm = (DynaActionForm)form;
    SearchVO searchVO = new SearchVO();
    int moduleId = ((Integer)advancedSearchForm.get("moduleId")).intValue();
    searchVO.setModuleID(moduleId);
    List searchCriteriaList = Arrays.asList((SearchCriteriaVO[])advancedSearchForm.get("searchCriteria"));
    ArrayList searchCriteria = new ArrayList(searchCriteriaList);
    // before simply setting the criteria on the VO check and make sure we really have any.
    for (int i = 0; i < searchCriteria.size(); i++) {
      SearchCriteriaVO currentCriteria = (SearchCriteriaVO)searchCriteria.get(i);
      if (currentCriteria.getTableID().equals("") || currentCriteria.getFieldID().equals("") || currentCriteria.getValue().equals("")) {
View Full Code Here

    HttpSession session = request.getSession(true);
    // Need the userobject so we know who we are.
    UserObject userObject = (UserObject)session.getAttribute("userobject");
    int individualId = userObject.getIndividualID();

    DynaActionForm reportForm = (DynaActionForm)form;
    int moduleId = reportVO.getModuleId();

    reportForm.set("description", reportVO.getDescription());
    reportForm.set("moduleId", new Integer(moduleId));
    reportForm.set("name", reportVO.getName());
    reportForm.set("reportId", new Integer(reportVO.getReportId()));
    String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
    // Get Saved searches from the EJB
    AdvancedSearch remoteAdvancedSearch = null;
    try {
      AdvancedSearchHome advancedSearchHome = (AdvancedSearchHome)CVUtility.getHomeObject("com.centraview.advancedsearch.AdvancedSearchHome", "AdvancedSearch");
      remoteAdvancedSearch = advancedSearchHome.create();
      remoteAdvancedSearch.setDataSource(dataSource);
    } catch (Exception e) {
      logger.error("[getAdHocReportFormFromReportVO] Exception thrown.", e);
    }
    HashMap allFields = (HashMap)reportForm.get("allFields");
    // Only repopulate all the lists if it is empty
    if (allFields == null || allFields.isEmpty()) {
      // Build dem drop downs
      HashMap tableMap = remoteAdvancedSearch.getSearchTablesForModule(individualId, moduleId);
      HashMap conditionMap = SearchVO.getConditionOptions();
      // Build an ArrayList of LabelValueBeans
      ArrayList tableList = AdvancedSearchUtil.buildSelectOptionList(tableMap);
      ArrayList conditionList = AdvancedSearchUtil.buildSelectOptionList(conditionMap);
      reportForm.set("tableList", tableList);
      reportForm.set("conditionList", conditionList);

      // Get all the appropriate field lists and stick them on the formbean
      // The fieldList (ArrayList of LabelValueBean) will be stored in a
      // HashMap with the key being the (Number)tableId
      TreeSet keySet = new TreeSet(tableMap.keySet());
      Iterator keyIterator = keySet.iterator();
      allFields = new HashMap();
      while (keyIterator.hasNext()) {
        Number key = (Number)keyIterator.next();
        // iterate the tables and get all the field lists
        // stick them in a hashmap of arraylists on the form bean.
        HashMap tableFields = remoteAdvancedSearch.getSearchFieldsForTable(individualId, key.intValue(), moduleId);
        ArrayList tableFieldList = AdvancedSearchUtil.buildSelectOptionList(tableFields);
        allFields.put(key, tableFieldList);
      } // end while(keyIterator.hasNext())
      reportForm.set("allFields", allFields);
    } // end if (allFields == null || allFields.isEmpty())
    return reportForm;
  }
View Full Code Here

*/
public class SaveAddressHandler extends org.apache.struts.action.Action
{
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws RuntimeException, Exception
  {
    DynaActionForm dynaForm = (DynaActionForm)form;
    String operation = (String)dynaForm.get("operation");

    String forward = "edit_related_address";
    if (operation != null && operation.equals("edit")) {
      forward = "edit_related_address";
    }else if (operation != null && operation.equals("add")){
View Full Code Here

   * @return ReportVO
   */
  protected ReportVO getStandardReportVOFromForm(String timeZone, ActionForm form)
  {

    DynaActionForm reportForm = (DynaActionForm)form;
    ReportVO reportVO = new ReportVO();
    reportVO.setModuleId(((Integer)reportForm.get("moduleId")).intValue());
    reportVO.setName((String)reportForm.get("name"));
    reportVO.setDescription((String)reportForm.get("description"));
    reportVO.setReportId(((Integer)reportForm.get("reportId")).intValue());
    if (((String)reportForm.get("startday")) != null && !((String)reportForm.get("startday")).equals(""))
      reportVO.setFrom(getDate((String)reportForm.get("startday"), (String)reportForm.get("startmonth"), (String)reportForm.get("startyear"), timeZone));
    if (((String)reportForm.get("endday")) != null && !((String)reportForm.get("endday")).equals(""))
      reportVO.setTo(getDate((String)reportForm.get("endday"), (String)reportForm.get("endmonth"), (String)reportForm.get("endyear"), timeZone));
    reportVO.setSearchFields(getSearchFields((String)reportForm.get("searchFields")));
    return reportVO;
  }
View Full Code Here

   * @param reportVO ReportVO
   * @return ActionForm
   */
  protected ActionForm getStandardReportFormFromReportVO(ReportVO reportVO, ActionForm form, HttpServletRequest request) throws RemoteException
  {
    DynaActionForm reportForm = (DynaActionForm)form;
    int moduleId = reportVO.getModuleId();
    HttpSession session = request.getSession(true);
    // Need the userobject so we know who we are.
    UserObject userObject = (UserObject)session.getAttribute("userobject");
    int individualId = userObject.getIndividualID();

    reportForm.set("description", reportVO.getDescription());
    reportForm.set("moduleId", new Integer(moduleId));
    reportForm.set("name", reportVO.getName());
    reportForm.set("reportId", new Integer(reportVO.getReportId()));
    if (reportVO.getFrom() != null) {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(reportVO.getFrom());
      reportForm.set("startday", String.valueOf(calendar.get(Calendar.DATE)));
      reportForm.set("startmonth", String.valueOf(calendar.get(Calendar.MONTH) + 1));
      reportForm.set("startyear", String.valueOf(calendar.get(Calendar.YEAR)));
    }
    if (reportVO.getTo() != null) {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(reportVO.getTo());
      reportForm.set("endday", String.valueOf(calendar.get(Calendar.DATE)));
      reportForm.set("endmonth", String.valueOf(calendar.get(Calendar.MONTH) + 1));
      reportForm.set("endyear", String.valueOf(calendar.get(Calendar.YEAR)));
    }
    // fields for the search part of things.
    reportForm.set("ownerId", (String.valueOf(individualId)));
    SearchCriteriaVO[] searchCriteria = (SearchCriteriaVO[])reportForm.get("searchCriteria");
    String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
    // We need some advanced Search stuff from the EJB layer
    AdvancedSearch remoteAdvancedSearch = null;
    try {
      AdvancedSearchHome advancedSearchHome = (AdvancedSearchHome)CVUtility.getHomeObject("com.centraview.advancedsearch.AdvancedSearchHome", "AdvancedSearch");
      remoteAdvancedSearch = advancedSearchHome.create();
      remoteAdvancedSearch.setDataSource(dataSource);
    } catch (Exception e) {
      logger.error("[getStandardReportFormFromReportVO] Exception thrown.", e);
    }
    HashMap allFields = (HashMap)reportForm.get("allFields");
    // Only repopulate all the lists if it is empty
    if (allFields == null || allFields.isEmpty()) {
      // Build dem drop downs
      HashMap tableMap = remoteAdvancedSearch.getSearchTablesForModule(individualId, moduleId);
      HashMap conditionMap = SearchVO.getConditionOptions();
      // Build an ArrayList of LabelValueBeans
      ArrayList tableList = AdvancedSearchUtil.buildSelectOptionList(tableMap);
      ArrayList conditionList = AdvancedSearchUtil.buildSelectOptionList(conditionMap);
      // Get all the appropriate field lists and stick them on the formbean
      // The fieldList (ArrayList of LabelValueBean) will be stored in a
      // HashMap with the key being the (Number)tableId
      TreeSet keySet = new TreeSet(tableMap.keySet());
      Iterator keyIterator = keySet.iterator();
      allFields = new HashMap();
      while (keyIterator.hasNext()) {
        Number key = (Number)keyIterator.next();
        // iterate the tables and get all the field lists
        // stick them in a hashmap of arraylists on the form bean.
        HashMap tableFields = remoteAdvancedSearch.getSearchFieldsForTable(individualId, key.intValue(), moduleId);
        ArrayList tableFieldList = AdvancedSearchUtil.buildSelectOptionList(tableFields);
        allFields.put(key, tableFieldList);
      } // end while(keyIterator.hasNext())
      reportForm.set("allFields", allFields);
      reportForm.set("tableList", tableList);
      reportForm.set("conditionList", conditionList);
    } // end if (allFields == null || allFields.isEmpty())
    reportForm.set("searchCriteria", searchCriteria);
    return reportForm;
  }
View Full Code Here

*/
public class SaveContactMethodHandler extends org.apache.struts.action.Action
{
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws RuntimeException, Exception
  {
    DynaActionForm dynaForm = (DynaActionForm)form;
    String operation = (String)dynaForm.get("operation");

    String forward = "edit_contact_method";
    if (operation != null && operation.equals("edit")) {
      forward = "edit_contact_method";
    }else if (operation != null && operation.equals("add")){
View Full Code Here

    ActionErrors allErrors = new ActionErrors();
    String forward = "displayComposeForm";
    String errorForward = "errorOccurred";

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

    MailHome home = (MailHome)CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");

    try {
      // get the message ID from the form bean
      Integer messageID = (Integer)emailForm.get("messageID");

      // now, check the message ID on the form...
      if (messageID == null || messageID.intValue() <= 0 ) {
        // if Message ID is not set on the form, then there is
        // no point in continuing forward. Show user the door. :-)
        allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "Message ID"));
        return(mapping.findForward(errorForward));
      }

      Mail remote = (Mail)home.create();
      remote.setDataSource(dataSource);

      MailMessageVO messageVO = remote.getEmailMessageVO(individualID, messageID.intValue());

      // set the subject on the form bean. Don't forget to prepend "Fw: "
      String prevSubject = (String)messageVO.getSubject();
      String newSubject = "";
      if (prevSubject != null && prevSubject.length() > 0) {
        if ((prevSubject.toLowerCase()).startsWith("fw: ")) {
          // If the subject already has "Fw:" pre-pended, do not add another "Fw:"
          newSubject = prevSubject;
        }else{
          newSubject = "Fw: " + prevSubject;
        }
      }
      emailForm.set("subject", newSubject);

      String linebreak = "\n";
      UserPrefererences userPref= userObject.getUserPref();
      if ((userPref.getContentType()).equals("HTML")) {
        linebreak = "<br>\n";
      }


      StringBuffer body = new StringBuffer();
      body.append(linebreak + linebreak + "---- Original Message: ----" + linebreak);
      body.append("From: " + messageVO.getFromAddress() + linebreak);
      body.append("Sent: " + messageVO.getReceivedDate() + linebreak);
      body.append("Subject: " + messageVO.getSubject() + linebreak + linebreak);

      // if the original message is an HTML message, we can only quote
      // it if the user is using IE (with HTMLArea). Otherwise, we need
      // to attach the original message as an attachment to the new message
      boolean saveOrigBodyAsAttachment = false;
      String originalBody = (String)messageVO.getBody();
      originalBody = originalBody.replaceAll("\r", "");
      originalBody = originalBody.replaceAll("\n", linebreak);
     
      body.append(originalBody);

      String messageBody = body.toString();
      emailForm.set("body", messageBody);


      // 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      // key being the fileID and the value being the filename.
      // So we'll have to replicate that behavior here, getting the
      // ArrayList of attachments from the MailMessageVO, looping
      // through that list, and adding an entry to a HashMap for each
      // attached file. Then Process the HashMap and get the FileID and File Title
      // an attribute named "attachmentList". PLEASE NOTE: we are going
      // to want to change this in the future. 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 SendHandler
      // reflects your changes.
      ArrayList attachmentList = (ArrayList)messageVO.getAttachedFiles();

      Iterator iter = attachmentList.iterator();
      ArrayList attachmentMap = new ArrayList();
      int i = 0;
      while (iter.hasNext()) {
        CvFileVO fileVO = (CvFileVO)iter.next();
        int fileID = fileVO.getFileId();
        String fileName = fileVO.getTitle();
        attachmentMap.add(new DDNameValue(fileID+"#"+fileName,fileName));
      }

      if (saveOrigBodyAsAttachment) {
        CvFolderVO attachmentFolderVO = (CvFolderVO)remote.getAttachmentFolder(individualID);
        int attachmentFolderID = attachmentFolderVO.getFolderId();
        int newFileID = -1;

        // somehow create a file using CvFileFacade, and get a CvFileVO from that.
        CvFileVO fileVO = new CvFileVO();
        SimpleDateFormat df = new SimpleDateFormat("MMMM_dd_yyyy_hh_mm_ss_S");
        String prependDate = df.format(new Date());
        fileVO.setName("OriginalMessage_#" + messageID.intValue() + "_" + prependDate + ".html");
        fileVO.setTitle("OriginalMessage_#" + messageID.intValue());
        fileVO.setDescription("");
        fileVO.setFileSize(0.0f);   // float
        fileVO.setVersion("1.0");
        fileVO.setStatus("PUBLISHED");
        fileVO.setVisibility(CvFileVO.FV_PRIVATE);
        fileVO.setPhysical(CvFileVO.FP_PHYSICAL);
        fileVO.setPhysicalFolder(attachmentFolderID);
        fileVO.setAuthorId(individualID);
        fileVO.setIsTemporary(CvFileVO.FIT_YES);

        ByteArrayInputStream inputStream = new ByteArrayInputStream(originalBody.getBytes());

        try {
          CvFileFacade fileFacade = new CvFileFacade();
          newFileID = fileFacade.addFile(individualID, attachmentFolderID, fileVO, inputStream, dataSource);
        }catch(CvFileException cfe){
          // I guess do nothing
        }

        if (newFileID > 0) {
          // Add the CvFileVO to attachmentList, and the following line for the attachmentMap
          fileVO.setFileId(newFileID);

          String FileName= "OriginalMessage_" + messageID.intValue();
          attachmentMap.add(new DDNameValue(newFileID+"#"+FileName,FileName));
        }
      }   // end if (saveOrigBodyAsAttachment)

      if (! attachmentMap.isEmpty()) {
        emailForm.set("attachmentList", attachmentMap);
      }
    }catch(Exception e){
      logger.error("[Exception] ForwardHandler.Execute Handler ", e);
    }
    return(mapping.findForward(forward));
View Full Code Here

    String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();


    HttpSession session = request.getSession(true);
    UserObject userObject = (UserObject) session.getAttribute("userobject");
    DynaActionForm dynaForm = (DynaActionForm) form;
    int individualID = userObject.getIndividualID();
    int faqId = 0;
    Vector questionColumns = new Vector();
    questionColumns.addElement("Question");
    questionColumns.addElement("Answer");
    request.setAttribute(SupportConstantKeys.TYPEOFSUBMODULE, "FAQ");
    request.setAttribute("questionColumns", questionColumns);

    String typeOfOperation = request.getParameter(Constants.TYPEOFOPERATION);

    if (typeOfOperation.equals(SupportConstantKeys.EDIT)
        || typeOfOperation.equals(SupportConstantKeys.DUPLICATE)
        || typeOfOperation.equals(SupportConstantKeys.VIEW))
    {
      if (request.getAttribute("faqId") != null) {
        faqId = ((Integer) (request.getAttribute("faqId"))).intValue();
      else {
        faqId = Integer.parseInt(request.getParameter("rowId"));
      }

      int ownerID = 0;

      FaqVO faqVO = new FaqVO();
      SupportFacadeHome supFacade = (SupportFacadeHome) CVUtility
        .getHomeObject("com.centraview.support.supportfacade.SupportFacadeHome",
          "SupportFacade");

      try
      {
        SupportFacade remote = supFacade.create();
        remote.setDataSource(dataSource);
        FaqVO fVO = remote.getFaq(individualID, faqId);

        dynaForm.set("faqid", new Integer(fVO.getFaqId()).toString());
        dynaForm.set("title", fVO.getTitle());
        dynaForm.set("status", fVO.getStatus());
        dynaForm.set("publishToCustomerView", fVO.getPublishToCustomerView());
        ownerID = fVO.getOwner();

        QuestionList questionList = remote.getQuestionList(individualID, fVO.getFaqId());
        questionList = setLinksfunction(questionList);
        request.setAttribute("questionlist", questionList);

        // Condition if the record status is Publish then Only Owner can update it.
        // Other user can't update it.
        // thats why we will disable the Edit button
        boolean editFlag = false;
        if(fVO.getStatus() != null && fVO.getStatus().equals("PUBLISH")){
          AuthorizationHome homeAuthorization = (AuthorizationHome)CVUtility.getHomeObject("com.centraview.administration.authorization.AuthorizationHome", "Authorization");
          try{
            Authorization remoteAuthorization = homeAuthorization.create();
            remoteAuthorization.setDataSource(dataSource);
            editFlag = remoteAuthorization.canPerformRecordOperation(individualID, "FAQ", faqId, ModuleFieldRightMatrix.UPDATE_RIGHT);
          }
          catch (Exception e)
          {
            logger.error("[Exception] [ViewFaqHandler.execute Calling Authorization]  ", e);
            FORWARD_final = GLOBAL_FORWARD_failure;
          }
        }
        else if (individualID == ownerID){
          editFlag = true;
        }
        request.setAttribute("showEditRecordButton", new Boolean(editFlag));

      }
      catch (Exception e) {
        logger.error("[Exception] [ViewFaqHandler.execute Calling SupportFacade]  ", e);
        FORWARD_final = GLOBAL_FORWARD_failure;
      }
    }

    if (typeOfOperation.equals(SupportConstantKeys.VIEW)) {
      FORWARD_final = FORWARD_viewfaq;
    } else if (typeOfOperation.equals(SupportConstantKeys.ADD)) {
      FORWARD_final = FORWARD_addfaq;
    else {
      FORWARD_final = FORWARD_editfaq;
    }

    String closeornew = (String) request.getParameter("closeornew");
    String saveandclose = null;
    String saveandnew = null;

    if (closeornew != null)
    {
      if (closeornew.equals("close"))
      {
        saveandclose = "saveandclose";
      }
      else if (closeornew.equals("new"))
      {
        dynaForm.set("title", "");
        dynaForm.set("status", "DRAFT");
        saveandnew = "saveandnew";
      }

      if (saveandclose != null)
      {
View Full Code Here

TOP

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

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.