List of usage examples for java.text DateFormat LONG
int LONG
To view the source code for java.text DateFormat LONG.
Click Source Link
From source file:com.alkacon.opencms.v8.formgenerator.CmsFormHandler.java
/** * Sends the collected data due to the configuration of the form * (email, database or both).<p>// w ww. j av a 2 s. c om * * @return <code>true</code> if successful */ public boolean sendData() { boolean result = true; try { CmsForm data = getFormConfiguration(); data.removeCaptchaField(); // fill the macro resolver for resolving in subject and content: List<I_CmsField> fields = data.getAllFields(false, true, true); Iterator<I_CmsField> itFields = fields.iterator(); // add field values as macros while (itFields.hasNext()) { I_CmsField field = itFields.next(); if (field instanceof CmsPagingField) { continue; } String fValue = field.getValue(); if ((field instanceof CmsDynamicField) && !((field instanceof CmsDisplayField) || (field instanceof CmsHiddenDisplayField))) { fValue = data.getFieldStringValueByName(field.getName()); } if (field instanceof CmsFileUploadField) { if (CmsStringUtil.isEmptyOrWhitespaceOnly(fValue)) { // try to read upload item from session attribute FileItem fileItem = getUploadFile(field); if (fileItem != null) { fValue = fileItem.getName(); } } fValue = CmsFormHandler.getTruncatedFileItemName(fValue); } m_macroResolver.addMacro(field.getLabel(), fValue); if (!field.getLabel().equals(field.getDbLabel())) { m_macroResolver.addMacro(field.getDbLabel(), fValue); } if (field instanceof CmsTableField) { Iterator<CmsFieldItem> it = field.getItems().iterator(); while (it.hasNext()) { CmsFieldItem item = it.next(); m_macroResolver.addMacro(item.getLabel(), item.getValue()); if (!item.getLabel().equals(item.getDbLabel())) { m_macroResolver.addMacro(item.getDbLabel(), item.getValue()); } } } } // add current date as macro m_macroResolver.addMacro(MACRO_DATE, CmsDateUtil.getDateTime(new Date(), DateFormat.LONG, getRequestContext().getLocale())); // send optional confirmation mail if (data.isConfirmationMailEnabled()) { if (!data.isConfirmationMailOptional() || Boolean.valueOf(getParameter(CmsForm.PARAM_SENDCONFIRMATION)).booleanValue()) { sendConfirmationMail(); } } if (data.isTransportDatabase()) { // save submitted form to database and store the uploaded files m_entryId = sendDatabase(); if (m_entryId > 0) { // successful submit result &= true; } else { // error during submit result &= false; } } if (data.isTransportEmail()) { result &= sendMail(); } } catch (Exception e) { // an error occurred during mail creation if (LOG.isErrorEnabled()) { LOG.error("An unexpected error occured.", e); } getErrors().put("sendmail", e.getMessage()); result = false; } return result; }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiToHTMLUtils.java
public static String toHtmlFormField(CustomFormField field, WikiToHTMLContext context) { // Set a default value if (field.getValue() == null) { field.setValue(field.getDefaultValue()); }//from w w w .j a v a 2s. c o m // Protect against any arbitrary input String fieldName = StringUtils.toHtmlValue(field.getName()); // Return output based on type switch (field.getType()) { case CustomFormField.TEXTAREA: String textAreaValue = StringUtils.replace(field.getValue(), "^", CRLF); return ("<textarea cols=\"" + field.getColumns() + "\" rows=\"" + field.getRows() + "\" name=\"" + fieldName + "\">" + StringUtils.toString(textAreaValue) + "</textarea>"); case CustomFormField.SELECT: LookupList lookupList = field.getLookupList(); int selectedItemId = -1; for (LookupElement thisElement : lookupList) { if (field.getValue().equals(thisElement.getDescription())) { selectedItemId = thisElement.getCode(); } } return lookupList.getHtmlSelect(fieldName, selectedItemId); case CustomFormField.CHECKBOX: return ("<input type=\"checkbox\" name=\"" + fieldName + "\" value=\"ON\" " + ("true".equals(field.getValue()) ? "checked" : "") + ">"); case CustomFormField.CALENDAR: String calendarValue = field.getValue(); if (StringUtils.hasText(calendarValue)) { try { String convertedDate = DateUtils.getUserToServerDateTimeString(null, DateFormat.SHORT, DateFormat.LONG, field.getValue()); Timestamp timestamp = DatabaseUtils.parseTimestamp(convertedDate); Locale locale = Locale.getDefault(); int dateFormat = DateFormat.SHORT; SimpleDateFormat dateFormatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale); calendarValue = dateFormatter.format(timestamp); } catch (Exception e) { LOG.error("toHtmlFormField calendar", e); } } // Output with a calendar control String language = System.getProperty("LANGUAGE"); String country = System.getProperty("COUNTRY"); return ("<input type=\"text\" name=\"" + fieldName + "\" id=\"" + fieldName + "\" size=\"10\" value=\"" + StringUtils.toHtmlValue(calendarValue) + "\" > " + "<a href=\"javascript:popCalendar('inputForm', '" + fieldName + "','" + language + "','" + country + "');\">" + "<img src=\"" + context.getServerUrl() + "/images/icons/stock_form-date-field-16.gif\" " + "border=\"0\" align=\"absmiddle\" height=\"16\" width=\"16\"/></a>"); case CustomFormField.PERCENT: return ("<input type=\"text\" name=\"" + fieldName + "\" size=\"5\" value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\"> " + "%"); case CustomFormField.INTEGER: // Determine the value to display in the field String integerValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(integerValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); integerValue = formatter.format(StringUtils.getIntegerNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not format integer: " + field.getValue()); } } return ("<input type=\"text\" name=\"" + fieldName + "\" size=\"8\" value=\"" + integerValue + "\"> "); case CustomFormField.FLOAT: // Determine the value to display in the field String decimalValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(decimalValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); decimalValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not decimal format: " + field.getValue()); } } return ("<input type=\"text\" name=\"" + fieldName + "\" size=\"8\" value=\"" + decimalValue + "\"> "); case CustomFormField.CURRENCY: // Use a currencyCode for formatting String currencyCode = field.getValueCurrency(); if (currencyCode == null) { currencyCode = field.getCurrency(); } if (!StringUtils.hasText(currencyCode)) { currencyCode = "USD"; } HtmlSelect currencyCodeList = HtmlSelectCurrencyCode.getSelect(fieldName + "Currency", currencyCode); // Determine the valut to display in the field String currencyValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(currencyValue)) { try { NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMaximumFractionDigits(2); currencyValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not currencyCode format: " + field.getValue()); } } return (currencyCodeList.getHtml() + "<input type=\"text\" name=\"" + fieldName + "\" size=\"8\" value=\"" + currencyValue + "\"> "); case CustomFormField.EMAIL: return ("<input type=\"text\" " + "name=\"" + fieldName + "\" maxlength=\"255\" size=\"40\" value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\" />"); case CustomFormField.PHONE: return ("<input type=\"text\" " + "name=\"" + fieldName + "\" maxlength=\"60\" size=\"20\" value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\" />"); case CustomFormField.URL: String value = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(value)) { if (!value.contains("://")) { value = "http://" + field.getValue(); } } return ("<input type=\"text\" " + "name=\"" + fieldName + "\" maxlength=\"255\" size=\"40\" value=\"" + StringUtils.toHtmlValue(value) + "\" />"); default: int maxlength = field.getMaxLength(); int size = -1; if (maxlength > -1) { if (maxlength > 40) { size = 40; } else { size = maxlength; } } return ("<input type=\"text\" " + "name=\"" + fieldName + "\" " + (maxlength == -1 ? "" : "maxlength=\"" + maxlength + "\" ") + (size == -1 ? "" : "size=\"" + size + "\" ") + "value=\"" + StringUtils.toHtmlValue(field.getValue()) + "\" />"); } }
From source file:com.clustercontrol.jobmanagement.factory.SelectJob.java
/** * ???????//from w ww . j a v a2s .c o m * * @param sessionId ID * @param jobId ID * @param jobunitId ID * @param destFacilityId ?ID * @param destFacilityName ??? * @param checksum ? * @param locale * @return * @throws JobInfoNotFound */ private String getFileJobDetailMessage(String sessionId, String jobunitId, String jobId, String destFacilityId, String destFacilityName, boolean checksum, Locale locale) throws JobInfoNotFound { final String START = "_START"; final String END = "_END"; final String FILE = "_FILE"; final String RTN = "\n"; StringBuilder message = new StringBuilder(); if (sessionId == null || sessionId.length() == 0 || jobId == null || jobId.length() == 0) { return message.toString(); } // UTILIUPDT_S?? if (CreateHulftJob.isHulftMode()) { try { JobSessionJobEntity job = QueryUtil.getJobSessionJobPK(sessionId, jobunitId, jobId); JobSessionJobEntity jobUtliupdtS = QueryUtil.getJobSessionJobPK(sessionId, jobunitId, job.getParentJobId() + CreateHulftJob.UTILIUPDT_S); if (jobUtliupdtS.getEndDate() != null) { if (jobUtliupdtS.getEndStatus() == null || jobUtliupdtS.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : jobUtliupdtS.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } } } } catch (JobInfoNotFound e) { m_log.debug("getFileJobDetailMessage() : " + e.getMessage()); } catch (InvalidRole e) { m_log.info("getFileJobDetailMessage() : " + e.getMessage()); } } //ID? Collection<JobSessionJobEntity> collection = QueryUtil.getChildJobSessionJobOrderByStartDate(sessionId, jobunitId, jobId); if (collection == null) { JobInfoNotFound je = new JobInfoNotFound("JobSessionJobEntity.findByStartDate" + ", [sessionId, parentJobId] = " + "[" + sessionId + ", " + jobId + "]"); m_log.info("getFileJobDetailMessage() : " + je.getClass().getSimpleName() + ", " + je.getMessage()); je.setSessionId(sessionId); je.setParentJobId(jobId); throw je; } DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, locale); dateFormat.setTimeZone(HinemosTime.getTimeZone()); HashMap<String, String> jobIdMap = new HashMap<String, String>(); for (JobSessionJobEntity childSessionJob : collection) { JobInfoEntity childJob = childSessionJob.getJobInfoEntity(); String childJobId = childSessionJob.getId().getJobId(); if (childJobId.indexOf(CreateFileJob.GET_KEY) != -1) { //"_GET_CHECKSUM"??ID? String fileJobId = childJobId.replaceAll(CreateFileJob.GET_KEY, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL)) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } else if (childJobId.indexOf(CreateFileJob.ADD_KEY) != -1) { //"_GET_CHECKSUM"??ID? String fileJobId = childJobId.replaceAll(CreateFileJob.ADD_KEY, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateFileJob.GET_CHECKSUM) != -1) { //"_GET_CHECKSUM"??ID? String fileJobId = childJobId.replaceAll(CreateFileJob.GET_CHECKSUM, ""); jobIdMap.put(fileJobId + FILE, childJob.getArgument()); //???? if (childSessionJob.getStartDate() != null) { String dateString = dateFormat.format(childSessionJob.getStartDate()); String file = childJob.getArgument(); String[] args = { dateString, file, destFacilityName }; message.append(MessageConstant.MESSAGE_STARTED_TO_TRANSFER_FILE.getMessage(args)); message.append(RTN); jobIdMap.put(fileJobId, START); } //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { String dateString = dateFormat.format(childSessionJob.getEndDate()); String file = childJob.getArgument(); String[] args = { dateString, file, destFacilityName }; message.append(MessageConstant.MESSAGE_FAILED_TO_TRANSFER_FILE.getMessage(args)); message.append(RTN); for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateFileJob.FORWARD) != -1) { //"_FORWARD"??ID? String fileJobId = childJobId.replaceAll(CreateFileJob.FORWARD, ""); //???? if (childSessionJob.getStartDate() != null && !checksum) { String dateString = dateFormat.format(childSessionJob.getStartDate()); String file = childJob.getArgument(); String[] args = { dateString, file, destFacilityName }; message.append(MessageConstant.MESSAGE_STARTED_TO_TRANSFER_FILE.getMessage(args)); message.append(RTN); jobIdMap.put(fileJobId, START); } //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { String dateString = dateFormat.format(childSessionJob.getEndDate()); String file = childJob.getArgument(); String[] args = { dateString, file, destFacilityName }; if (childSessionJob.getEndStatus() != null && childSessionJob.getEndStatus() == EndStatusConstant.TYPE_NORMAL) { if (!checksum) { message.append(MessageConstant.MESSAGE_FINISHED_TRANSFERRING_FILE.getMessage(args)); message.append(RTN); jobIdMap.put(fileJobId, END); } } else { message.append(MessageConstant.MESSAGE_FAILED_TO_TRANSFER_FILE.getMessage(args)); message.append(RTN); for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { m_log.debug(node.getId().getJobId()); String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } if (!checksum) { jobIdMap.remove(fileJobId); jobIdMap.remove(fileJobId + FILE); } } else if (childJobId.indexOf(CreateFileJob.CHECK_CHECKSUM) != -1) { //"_CHECK_CHECKSUM"??ID? String fileJobId = childJobId.replaceAll(CreateFileJob.CHECK_CHECKSUM, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { String dateString = dateFormat.format(childSessionJob.getEndDate()); String file = jobIdMap.get(fileJobId + FILE); String[] args = { dateString, file, destFacilityName }; if (childSessionJob.getEndStatus() != null && childSessionJob.getEndStatus() == EndStatusConstant.TYPE_NORMAL) { message.append(MessageConstant.MESSAGE_FINISHED_TRANSFERRING_FILE.getMessage(args)); message.append(RTN); } else { message.append(MessageConstant.MESSAGE_FAILED_TO_TRANSFER_FILE.getMessage(args)); message.append(RTN); for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { m_log.debug(node.getId().getJobId()); String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } jobIdMap.remove(fileJobId); jobIdMap.remove(fileJobId + FILE); } else if (childJobId.indexOf(CreateFileJob.DEL_KEY) != -1) { //"_DEL_KEY"??ID? String fileJobId = childJobId.replaceAll(CreateFileJob.DEL_KEY, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateHulftJob.UTILIUPDT_R) != -1) { //"_UTILIUPDT_R"??ID? String fileJobId = childJobId.replaceAll(CreateHulftJob.UTILIUPDT_R, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateHulftJob.UTILIUPDT_H_SND) != -1) { //"_UTLSEND"??ID? String fileJobId = childJobId.replaceAll(CreateHulftJob.UTILIUPDT_H_SND, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateHulftJob.UTILIUPDT_H_RCV) != -1) { //"_UTLSEND"??ID? String fileJobId = childJobId.replaceAll(CreateHulftJob.UTILIUPDT_H_RCV, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateHulftJob.UTLSEND) != -1) { //"_UTLSEND"??ID? String fileJobId = childJobId.replaceAll(CreateHulftJob.UTLSEND, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { if (childSessionJob.getEndStatus() == null || childSessionJob.getEndStatus() != EndStatusConstant.TYPE_NORMAL) { for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } } else if (childJobId.indexOf(CreateHulftJob.HULOPLCMD) != -1) { //"_HULOPLCMD"??ID? String fileJobId = childJobId.replaceAll(CreateHulftJob.HULOPLCMD, ""); //???? if (childSessionJob.getStartDate() != null && childSessionJob.getEndDate() != null && (jobIdMap.get(fileJobId) == null || !jobIdMap.get(fileJobId).equals(END))) { // HULOPLCMD?????????????? for (JobSessionNodeEntity node : childSessionJob.getJobSessionNodeEntities()) { String nodeMessage = node.getMessage(); if (nodeMessage != null && nodeMessage.length() > 0) { message.append(nodeMessage); message.append(RTN); } } jobIdMap.put(fileJobId, END); } } m_log.debug("getFileJobDetailMessage() : jobid=" + childJobId + ", message=" + message); } if (message.length() > 0) { message.setLength(message.length() - 1); } return message.toString(); }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
public static String getFieldValue(WikiPDFContext context, CustomFormField field) { // Return output based on type switch (field.getType()) { case CustomFormField.TEXTAREA: return StringUtils.replace(field.getValue(), "^", CRLF); case CustomFormField.SELECT: return field.getValue(); case CustomFormField.CHECKBOX: if ("true".equals(field.getValue())) { return "Yes"; } else {//from ww w. j ava 2s .c o m return "No"; } case CustomFormField.CALENDAR: String calendarValue = field.getValue(); if (StringUtils.hasText(calendarValue)) { try { String convertedDate = DateUtils.getUserToServerDateTimeString(null, DateFormat.SHORT, DateFormat.LONG, field.getValue()); Timestamp timestamp = DatabaseUtils.parseTimestamp(convertedDate); Locale locale = Locale.getDefault(); int dateFormat = DateFormat.SHORT; SimpleDateFormat dateFormatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale); calendarValue = dateFormatter.format(timestamp); } catch (Exception e) { LOG.error(e); } } return calendarValue; case CustomFormField.PERCENT: return field.getValue() + "%"; case CustomFormField.INTEGER: // Determine the value to display in the field String integerValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(integerValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); integerValue = formatter.format(StringUtils.getIntegerNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not integer format: " + field.getValue()); } } return integerValue; case CustomFormField.FLOAT: // Determine the value to display in the field String decimalValue = field.getValue(); if (StringUtils.hasText(decimalValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); decimalValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not decimal format: " + field.getValue()); } } return decimalValue; case CustomFormField.CURRENCY: // Use a currency for formatting String currencyCode = field.getValueCurrency(); if (currencyCode == null) { currencyCode = field.getCurrency(); } if (!StringUtils.hasText(currencyCode)) { currencyCode = "USD"; } try { NumberFormat formatter = NumberFormat.getCurrencyInstance(); if (currencyCode != null) { Currency currency = Currency.getInstance(currencyCode); formatter.setCurrency(currency); } return (formatter.format(StringUtils.getDoubleNumber(field.getValue()))); } catch (Exception e) { LOG.error(e.getMessage()); } return field.getValue(); case CustomFormField.EMAIL: return field.getValue(); case CustomFormField.PHONE: PhoneNumberBean phone = new PhoneNumberBean(); phone.setNumber(field.getValue()); PhoneNumberUtils.format(phone, Locale.getDefault()); return phone.toString(); case CustomFormField.URL: String value = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(value)) { if (!value.contains("://")) { value = "http://" + value; } if (value.contains("://")) { return value; } } return value; case CustomFormField.IMAGE: String image = field.getValue(); if (StringUtils.hasText(image)) { return "WikiImage:" + image; } return image; default: return field.getValue(); } }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Get log text of import status.//from ww w.j a v a 2 s . co m * * @param importStatus The import status. * @return The log text of import status. */ private String logImportStatus(ImportStatus importStatus) { Date now = new Date(); StringBuilder sb = new StringBuilder(CRLF); sb.append("Service Credit imported a data file from the bank lockbox on "); sb.append(DateFormat.getDateInstance(DateFormat.LONG, Locale.US).format(now)); sb.append(" at "); sb.append(DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(now)).append(".").append(CRLF); sb.append("Lockbox data imported into the ").append(databaseString); sb.append(" database on server ").append(datasourceString); sb.append(" from computer ").append(workstationId).append("."); sb.append(CRLF).append(CRLF); sb.append("# Lines in file = ") .append(importStatus.getNumberDuplicateRecords() + importStatus.getNumberDiscreteRecords()) .append(CRLF); if (importStatus.getNumberDiscreteRecords() > 0) { sb.append("# New Lines = ").append(importStatus.getNumberDiscreteRecords()).append(CRLF); } sb.append("# Duplicate Lines = ").append(importStatus.getNumberDuplicateRecords()).append(CRLF); sb.append(CRLF); int failedInserts = importStatus.getNumberBadChangeRecords() + importStatus.getNumberNoMatchChangeRecords() + importStatus.getNumberBadAchPayments() + importStatus.getNumberBadCheckPayments(); int successfulInserts = importStatus.getNumberGoodChangeRecords() + importStatus.getNumberGoodAchPayments() + importStatus.getNumberGoodCheckPayments(); sb.append("# Records Processed = ") .append(importStatus.getNumberBadDataRecords() + importStatus.getNumberGoodSummaryRecords() + importStatus.getNumberBadSummaryRecords() + importStatus.getNumberDupeAchPayments() + importStatus.getNumberDupeCheckPayments() + failedInserts + successfulInserts) .append(CRLF); sb.append("# Check Payments = ").append(importStatus.getNumberGoodCheckPayments() + importStatus.getNumberBadCheckPayments() + importStatus.getNumberDupeCheckPayments()) .append(CRLF); sb.append("# Good Check Payments = ").append(importStatus.getNumberGoodCheckPayments()).append(CRLF); sb.append("# Bad Check Payments = ").append(importStatus.getNumberBadCheckPayments()).append(CRLF); sb.append("# Dupe Check Payments = ").append(importStatus.getNumberDupeCheckPayments()).append(CRLF); sb.append("# ACH Payments = ").append(importStatus.getNumberGoodAchPayments() + importStatus.getNumberBadAchPayments() + importStatus.getNumberDupeAchPayments()).append(CRLF); sb.append("# Good ACH Payments = ").append(importStatus.getNumberGoodAchPayments()).append(CRLF); sb.append("# Bad ACH Payments = ").append(importStatus.getNumberBadAchPayments()).append(CRLF); sb.append("# Dupe ACH Payments = ").append(importStatus.getNumberDupeAchPayments()).append(CRLF); sb.append("# Bad Change Records = ").append(importStatus.getNumberBadChangeRecords()).append(CRLF); sb.append("# Good Change Records = ").append(importStatus.getNumberGoodChangeRecords()).append(CRLF); sb.append("# No Match Change Records = ").append(importStatus.getNumberNoMatchChangeRecords()).append(CRLF); sb.append("# Invalid Summary Records = ").append(importStatus.getNumberBadSummaryRecords()).append(CRLF); sb.append("# Valid Summary Records = ").append(importStatus.getNumberGoodSummaryRecords()).append(CRLF); sb.append("# Successful Transactions = ").append(successfulInserts).append(CRLF); sb.append("# Failed Transactions = ").append(failedInserts).append(CRLF); sb.append("# Invalid Lines = ").append(importStatus.getNumberBadDataRecords()).append(CRLF); sb.append(CRLF); sb.append("Total Check Payments = ").append(importStatus.getTotalCheckPayments()).append(CRLF); sb.append("Total ACH Payments = ").append(importStatus.getTotalACHPayments()).append(CRLF); sb.append("Total of Accepted Payments = ") .append(importStatus.getTotalCheckPayments().add(importStatus.getTotalACHPayments())).append(CRLF); if (Double.compare(importStatus.getTransactionsTotal().doubleValue(), importStatus.getFileSummaryTotal().doubleValue()) == 0) { sb.append("Total in File = ").append(importStatus.getFileSummaryTotal()).append(CRLF); } else { sb.append("Total in File Summary (checksum) = ").append(importStatus.getFileSummaryTotal()) .append(CRLF); sb.append("Total of Processed Transactions = ").append(importStatus.getTransactionsTotal()) .append(CRLF); sb.append(CRLF).append(CRLF); sb.append("ERROR: THE BANK FILE CONTAINED ").append(importStatus.getFileSummaryTotal()).append(" BUT ") .append(importStatus.getTransactionsTotal()) .append(" WAS IMPORTED INTO THE SERVICE CREDIT DATABASE. "); if (importStatus.getNumberGoodSummaryRecords() > 0) { if (Double.compare(importStatus.getTransactionsTotal().doubleValue(), importStatus.getFileSummaryTotal().doubleValue()) > 0) { sb.append("THE PROGRAM IMPORTED ") .append(importStatus.getTransactionsTotal() .subtract(importStatus.getFileSummaryTotal())) .append(" MORE THAN THE BANK TOTAL.").append(CRLF); } else if (Double.compare(importStatus.getTransactionsTotal().doubleValue(), importStatus.getFileSummaryTotal().doubleValue()) < 0) { sb.append("THE PROGRAM IMPORTED ") .append(importStatus.getFileSummaryTotal() .subtract(importStatus.getTransactionsTotal())) .append(" LESS THAN THE BANK TOTAL.").append(CRLF); } } } sb.append(CRLF); int failedCount = importStatus.getNumberBadDataRecords() + importStatus.getNumberBadSummaryRecords() + failedInserts; if (failedCount > 0) { sb.append("ERROR: ").append(failedCount).append(" RECORDS FAILED PROCESSING.").append(CRLF); } else { sb.append("No bad records in this batch.").append(CRLF); } if (failedInserts > 0) { sb.append("ERROR: ").append(failedInserts).append(" TRANSACTIONS COULD NOT BE READ INTO THE DATABASE!") .append(CRLF); } if (importStatus.getNumberBadSummaryRecords() > 0) { sb.append("ERROR: ").append(importStatus.getNumberBadSummaryRecords()) .append(" CHECKSUMS COULD NOT BE PROCESSED!").append(CRLF); } if (importStatus.getNumberDuplicateRecords() > 0) { sb.append(importStatus.getNumberDuplicateRecords()).append(" DUPLICATE RECORDS FROM THE BANK") .append(CRLF); } sb.append(successfulInserts).append(" = number of successful calls to the ProcessImportRecord function.") .append(CRLF); if (failedInserts > 0) { sb.append(failedInserts).append(" NUMBER OF FAILED CALLS TO THE PROCESSIMPORTRECORD FUNCTION!") .append(CRLF); } sb.append(CRLF); // Log pending payment transactions collated sb.append(" Accepted Payments: ").append( importStatus.getNumberAcceptedCheckPayments() + importStatus.getNumberAcceptedAchPayments()); sb.append(CRLF); sb.append(" Unresolved Payments: ").append( importStatus.getNumberUnresolvedCheckPayments() + importStatus.getNumberUnresolvedAchPayments()); sb.append(CRLF); sb.append(" Suspended Payments: ").append( importStatus.getNumberSuspendedCheckPayments() + importStatus.getNumberSuspendedAchPayments()); sb.append(CRLF); sb.append("-----------------------------------"); sb.append(CRLF); sb.append("Pending payments processed: ").append(importStatus.getNumberAcceptedCheckPayments() + importStatus.getNumberAcceptedAchPayments() + importStatus.getNumberUnresolvedCheckPayments() + importStatus.getNumberUnresolvedAchPayments() + importStatus.getNumberSuspendedCheckPayments() + importStatus.getNumberSuspendedAchPayments()); sb.append(CRLF); return sb.toString(); }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiToHTMLUtils.java
public static String toHtml(CustomFormField field, Wiki wiki, String contextPath) { // Return output based on type switch (field.getType()) { case CustomFormField.TEXTAREA: String textAreaValue = StringUtils.replace(field.getValue(), "^", CRLF); return StringUtils.toHtml(textAreaValue); case CustomFormField.SELECT: return StringUtils.toHtml(field.getValue()); case CustomFormField.CHECKBOX: if ("true".equals(field.getValue())) { return "Yes"; } else {/*w w w . j a va 2 s. c o m*/ return "No"; } case CustomFormField.CALENDAR: String calendarValue = field.getValue(); if (StringUtils.hasText(calendarValue)) { try { String convertedDate = DateUtils.getUserToServerDateTimeString(null, DateFormat.SHORT, DateFormat.LONG, field.getValue()); Timestamp timestamp = DatabaseUtils.parseTimestamp(convertedDate); Locale locale = Locale.getDefault(); int dateFormat = DateFormat.SHORT; SimpleDateFormat dateFormatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale); calendarValue = dateFormatter.format(timestamp); } catch (Exception e) { LOG.error("toHtml calendar", e); } } return StringUtils.toHtml(calendarValue); case CustomFormField.PERCENT: return StringUtils.toHtml(field.getValue()) + "%"; case CustomFormField.INTEGER: // Determine the value to display in the field String integerValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(integerValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); integerValue = formatter.format(StringUtils.getIntegerNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not integer format: " + field.getValue()); } } return integerValue; case CustomFormField.FLOAT: // Determine the value to display in the field String decimalValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(decimalValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); decimalValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not decimal format: " + field.getValue()); } } return decimalValue; case CustomFormField.CURRENCY: // Use a currency for formatting String currencyCode = field.getValueCurrency(); if (currencyCode == null) { currencyCode = field.getCurrency(); } if (!StringUtils.hasText(currencyCode)) { currencyCode = "USD"; } try { NumberFormat formatter = NumberFormat.getCurrencyInstance(); if (currencyCode != null) { Currency currency = Currency.getInstance(currencyCode); formatter.setCurrency(currency); } return (StringUtils.toHtml(formatter.format(StringUtils.getDoubleNumber(field.getValue())))); } catch (Exception e) { LOG.error("toHtml currency", e); } return StringUtils.toHtml(field.getValue()); case CustomFormField.EMAIL: return StringUtils.toHtml(field.getValue()); case CustomFormField.PHONE: PhoneNumberBean phone = new PhoneNumberBean(); phone.setNumber(field.getValue()); PhoneNumberUtils.format(phone, Locale.getDefault()); return StringUtils.toHtml(phone.toString()); case CustomFormField.URL: String value = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(value)) { if (!value.contains("://")) { value = "http://" + value; } if (value.contains("://")) { return ("<a href=\"" + StringUtils.toHtml(value) + "\">" + StringUtils.toHtml(value) + "</a>"); } } return StringUtils.toHtml(value); case CustomFormField.IMAGE: String image = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(image)) { Project project = ProjectUtils.loadProject(wiki.getProjectId()); return ("<img src=\"" + contextPath + "/show/" + project.getUniqueId() + "/wiki-image/" + image + "\"/>"); } return StringUtils.toHtml(image); default: return StringUtils.toHtml(field.getValue()); } }
From source file:com.sonicle.webtop.mail.Service.java
private String getForwardBody(Message msg, String body, int format, boolean isHtml, String fromtitle, String totitle, String cctitle, String datetitle, String subjecttitle) throws MessagingException { UserProfile profile = environment.getProfile(); Locale locale = profile.getLocale(); String msgSubject = msg.getSubject(); if (msgSubject == null) { msgSubject = ""; }/* w w w. j a v a 2 s . c o m*/ msgSubject = MailUtils.htmlescape(msgSubject); Address ad[] = msg.getFrom(); String msgFrom = ""; if (ad != null) { msgFrom = isHtml ? getHTMLDecodedAddress(ad[0]) : getDecodedAddress(ad[0]); } java.util.Date dt = msg.getSentDate(); String msgDate = ""; if (dt != null) { msgDate = DateFormat.getDateTimeInstance(java.text.DateFormat.LONG, java.text.DateFormat.LONG, locale) .format(dt); } ad = msg.getRecipients(Message.RecipientType.TO); String msgTo = null; if (ad != null) { msgTo = ""; for (int j = 0; j < ad.length; ++j) { msgTo += isHtml ? getHTMLDecodedAddress(ad[j]) : getDecodedAddress(ad[j]) + " "; } } ad = msg.getRecipients(Message.RecipientType.CC); String msgCc = null; if (ad != null) { msgCc = ""; for (int j = 0; j < ad.length; ++j) { msgCc += isHtml ? getHTMLDecodedAddress(ad[j]) : getDecodedAddress(ad[j]) + " "; } } StringBuffer sb = new StringBuffer(); String cr = "\n"; if (format != SimpleMessage.FORMAT_TEXT) { cr = "<BR>"; } if (format != SimpleMessage.FORMAT_HTML) { if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append("<TT>"); } sb.append(cr + cr + cr + "----------------------------------------------------------------------------------" + cr + cr); sb.append(fromtitle + ": " + msgFrom + cr); if (msgTo != null) { sb.append(totitle + ": " + msgTo + cr); } if (msgCc != null) { sb.append(cctitle + ": " + msgCc + cr); } sb.append(datetitle + ": " + msgDate + cr); sb.append(subjecttitle + ": " + msgSubject + cr + cr); if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append("</TT>"); } } else { sb.append(cr + "<HR>" + cr + cr); sb.append("<font face='Arial, Helvetica, sans-serif' size=2>"); sb.append("<B>" + fromtitle + ":</B> " + msgFrom + "<BR>"); if (msgTo != null) { sb.append("<B>" + totitle + ":</B> " + msgTo + "<BR>"); } if (msgCc != null) { sb.append("<B>" + cctitle + ":</B> " + msgCc + "<BR>"); } sb.append("<B>" + datetitle + ":</B> " + msgDate + "<BR>"); sb.append("<B>" + subjecttitle + ":</B> " + msgSubject + "<BR>"); sb.append("</font><br>" + cr); } // Prepend "> " for each line in the body // if (body != null) { if (format == SimpleMessage.FORMAT_HTML) { // sb.append("<TABLE border=0 width='100%'><TR><td width=2 bgcolor=#000088></td><td width=2></td><td>"); // sb.append("<BLOCKQUOTE style='BORDER-LEFT: #000080 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px'>"); } if (!isHtml) { if (format == SimpleMessage.FORMAT_PREFORMATTED) { // sb.append("<BLOCKQUOTE style='BORDER-LEFT: #000080 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px'>"); sb.append("<tt>"); } StringTokenizer st = new StringTokenizer(body, "\n", true); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.equals("\n")) { sb.append(cr); } else { if (format == SimpleMessage.FORMAT_TEXT) { sb.append("> "); } //sb.append(MailUtils.htmlescape(token)); sb.append(token); } } if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append("</tt>"); // sb.append("</BLOCKQUOTE>"); } } else { //sb.append(getBodyInnerHtml(body)); sb.append(body); } if (format == SimpleMessage.FORMAT_HTML) { // sb.append("</td></tr></table>"); // sb.append("</BLOCKQUOTE>"); } } return sb.toString(); }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Creates the General Ledger file given the database data. * <p/>/*from ww w . j a v a 2 s. c o m*/ * This method does not throw any exception. * * @param glFileDirectory The directory to create GL file. * @param procMessage The process message. Used to build the mail message. * @param now The current date. * @return true if execution is successful; false otherwise. */ private boolean makeGLFile(File glFileDirectory, StringBuilder procMessage, Date now) { if (!glFileDirectory.exists() || !glFileDirectory.isDirectory() || !glFileDirectory.canRead() || !glFileDirectory.canWrite()) { logger.warn("Can not make GL file in directory:" + glFileDirectory); procMessage.append(CRLF).append(CRLF).append("Can not make GL file in directory:" + glFileDirectory) .append(CRLF); return false; } File outputGLFile = new File(glFileDirectory, "SCGL" + new SimpleDateFormat("yyMMdd").format(now) + ".txt"); PrintWriter output = null; try { startTransaction(); StoredProcedureQuery sp = entityManager.createNamedStoredProcedureQuery("BatchDailyGLFile"); sp.setParameter("pDayToProcess", now, TemporalType.DATE); sp.execute(); @SuppressWarnings("unchecked") List<GLFileRecord> records = sp.getResultList(); commitTransaction(); Calendar cal = Calendar.getInstance(); cal.setTime(now); String dayOfYear = String.format("%03d", cal.get(Calendar.DAY_OF_YEAR)); for (GLFileRecord record : records) { StringBuilder line = new StringBuilder(""); line.append(record.getFeederSystemId()); line.append(record.getJulianDate()); line.append(dayOfYear); line.append(record.getGlFiller()); line.append(record.getGlCode()); int fiscalYear = record.getFiscalYear() == null ? 0 : record.getFiscalYear(); if (fiscalYear < 1000) { line.append(StringUtils.rightPad(record.getGlAccountingCode(), 20)); } else { line.append(fiscalYear % 100); line.append(" "); line.append(StringUtils.rightPad(record.getGlAccountingCode(), 16)); } line.append(String.format("%015d", record.getRecipientAmount().multiply(BatchProcessHelper.HUNDRED).longValue())); line.append(record.getRevenueSourceCode()); // Pad 28 spaces for (int i = 0; i < 28; i++) { line.append(" "); } if (output == null) { // Lazily create output file only when there is line to write output = new PrintWriter(outputGLFile); } output.println(line.toString()); } if (output != null) { output.flush(); logger.info("General Ledger file created."); procMessage.append(CRLF).append(CRLF).append("General Ledger file created.").append(CRLF); } else { String info = "There are no GL entries for " + DateFormat.getDateInstance(DateFormat.LONG, Locale.US).format(now) + " so no GL file was created. "; logger.info(info); procMessage.append(CRLF).append(CRLF).append(info).append(CRLF); } return true; } catch (PersistenceException pe) { logger.error("Database error creating the GL file.", pe); procMessage.append(CRLF).append(CRLF).append("Database error creating the GL file.").append(CRLF); return false; } catch (IOException e) { logger.error("IO error creating the GL file.", e); procMessage.append(CRLF).append(CRLF).append("IO error creating the GL file.").append(CRLF); return false; } finally { if (output != null) { output.close(); } } }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Sends the notification by email./*from w w w .j a v a 2 s. co m*/ * <p/> * This method does not throw any exception. * * @param mailMessage The message of the mail. * @param mailSubject The subject of the email. * @param processType The name of the current processor. It is used to distinguish the recipient of the email. */ private void notifyByEmail(String mailMessage, String mailSubject, String processType) { mailMessage = mailMessage.replace("@#$%EndingTime%$#@", DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(new Date())); String recipient = processType.equals("BillProcessing") ? billMailRecipient : generalMailRecipient; logger.info( "Send email to " + recipient + ", subject = [" + mailSubject + "]. Message:" + CRLF + mailMessage); MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message); try { helper.setTo(recipient); helper.setSubject(mailSubject); helper.setText(mailMessage); mailSender.send(message); } catch (MessagingException e) { logger.error("Error sending email to " + recipient + ", subject = [" + mailSubject + "].", e); } catch (MailSendException e) { logger.error("Error sending email to " + recipient + ", subject = [" + mailSubject + "].", e); } }
From source file:com.sonicle.webtop.mail.Service.java
private String getReplyBody(Message msg, String body, int format, boolean isHtml, String fromtitle, String totitle, String cctitle, String datetitle, String subjecttitle, ArrayList<String> attnames) throws MessagingException { UserProfile profile = environment.getProfile(); Locale locale = profile.getLocale(); String msgSubject = msg.getSubject(); if (msgSubject == null) { msgSubject = ""; }/*from w w w . j a va2s . c o m*/ msgSubject = MailUtils.htmlescape(msgSubject); Address ad[] = msg.getFrom(); String msgFrom = ""; if (ad != null) { msgFrom = isHtml ? getHTMLDecodedAddress(ad[0]) : getDecodedAddress(ad[0]); } java.util.Date dt = msg.getSentDate(); String msgDate = ""; if (dt != null) { msgDate = DateFormat.getDateTimeInstance(java.text.DateFormat.LONG, java.text.DateFormat.LONG, locale) .format(dt); } ad = msg.getRecipients(Message.RecipientType.TO); String msgTo = null; if (ad != null) { msgTo = ""; for (int j = 0; j < ad.length; ++j) { msgTo += isHtml ? getHTMLDecodedAddress(ad[j]) : getDecodedAddress(ad[j]) + " "; } } ad = msg.getRecipients(Message.RecipientType.CC); String msgCc = null; if (ad != null) { msgCc = ""; for (int j = 0; j < ad.length; ++j) { msgCc += isHtml ? getHTMLDecodedAddress(ad[j]) : getDecodedAddress(ad[j]) + " "; } } // /*String sfrom = ""; try { if (msg.getFrom() != null) { InternetAddress ia = (InternetAddress) msg.getFrom()[0]; String personal = ia.getPersonal(); String mail = ia.getAddress(); if (personal == null || personal.equals(mail)) { sfrom = mail; } else { sfrom = personal + " <" + mail + ">"; } } } catch (Exception exc) { }*/ StringBuffer sb = new StringBuffer(); String cr = "\n"; if (format != SimpleMessage.FORMAT_TEXT) { cr = "<BR>"; } if (format != SimpleMessage.FORMAT_HTML) { if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append("<TT>"); } sb.append(cr + cr + cr + "----------------------------------------------------------------------------------" + cr + cr); sb.append(fromtitle + ": " + msgFrom + cr); if (msgTo != null) { sb.append(totitle + ": " + msgTo + cr); } if (msgCc != null) { sb.append(cctitle + ": " + msgCc + cr); } sb.append(datetitle + ": " + msgDate + cr); sb.append(subjecttitle + ": " + msgSubject + cr + cr); if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append("</TT>"); } } else { sb.append(cr + "<HR>" + cr + cr); sb.append("<font face='Arial, Helvetica, sans-serif' size=2>"); sb.append("<B>" + fromtitle + ":</B> " + msgFrom + "<BR>"); if (msgTo != null) { sb.append("<B>" + totitle + ":</B> " + msgTo + "<BR>"); } if (msgCc != null) { sb.append("<B>" + cctitle + ":</B> " + msgCc + "<BR>"); } sb.append("<B>" + datetitle + ":</B> " + msgDate + "<BR>"); sb.append("<B>" + subjecttitle + ":</B> " + msgSubject + "<BR>"); sb.append("</font><br>" + cr); } // Prepend "> " for each line in the body // if (body != null) { if (format == SimpleMessage.FORMAT_HTML) { // sb.append("<TABLE border=0 width='100%'><TR><td width=2 bgcolor=#000088></td><td width=2></td><td>"); sb.append( "<BLOCKQUOTE style='BORDER-LEFT: #000080 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px'>"); } if (!isHtml) { if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append( "<BLOCKQUOTE style='BORDER-LEFT: #000080 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px'>"); sb.append("<tt>"); } StringTokenizer st = new StringTokenizer(body, "\n", true); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.equals("\n")) { sb.append(cr); } else { if (format == SimpleMessage.FORMAT_TEXT) { sb.append("> "); } //sb.append(MailUtils.htmlescape(token)); sb.append(token); } } if (format == SimpleMessage.FORMAT_PREFORMATTED) { sb.append("</tt>"); sb.append("</BLOCKQUOTE>"); } } else { /* //String ubody = body.toUpperCase(); while (true) { int ix1 = StringUtils.indexOfIgnoreCase(body,"<BODY"); if (ix1 < 0) { break; } int ix2 = StringUtils.indexOfIgnoreCase(body,">", ix1 + 1); if (ix2 < 0) { ix2 = ix1 + 4; } int ix3 = StringUtils.indexOfIgnoreCase(body,"</BODY", ix2 + 1); if (ix3 > 0) { body = body.substring(ix2 + 1, ix3); } else { body = body.substring(ix2 + 1); } } //body=removeStartEndTag(body,unwantedTags); */ sb.append(body); } htmlAppendAttachmentNames(sb, attnames); if (format == SimpleMessage.FORMAT_HTML) { // sb.append("</td></tr></table>"); sb.append("</BLOCKQUOTE>"); } } return sb.toString(); }