1 31 32 package org.opencms.frontend.templateone; 33 34 import org.opencms.mail.CmsHtmlMail; 35 import org.opencms.main.CmsException; 36 import org.opencms.main.CmsLog; 37 import org.opencms.main.OpenCms; 38 import org.opencms.util.CmsStringUtil; 39 import org.opencms.workplace.CmsWorkplace; 40 41 import java.util.HashMap ; 42 43 import javax.servlet.http.HttpServletRequest ; 44 import javax.servlet.http.HttpServletResponse ; 45 import javax.servlet.jsp.PageContext ; 46 47 import org.apache.commons.logging.Log; 48 49 58 public class CmsTemplateFormLetter extends CmsTemplateForm { 59 60 61 private static final Log LOG = CmsLog.getLog(CmsTemplateFormLetter.class); 62 63 64 private String m_concern; 65 66 private String m_concernDetail; 67 68 private String m_contactCity; 69 70 private String m_contactCountry; 71 72 private String m_contactEmail; 73 74 private String m_contactFirstName; 75 76 private String m_contactLastName; 77 78 private String m_contactNumber; 79 80 private String m_contactPhone; 81 82 private String m_contactSalutation; 83 84 private String m_contactStreet; 85 86 private String m_contactTitle; 87 88 private String m_contactZip; 89 90 private String m_copy; 91 92 private String m_message; 93 94 97 public CmsTemplateFormLetter() { 98 99 super(); 100 m_concern = ""; 102 m_concernDetail = ""; 103 m_contactCity = ""; 104 m_contactCountry = ""; 105 m_contactEmail = ""; 106 m_contactFirstName = ""; 107 m_contactLastName = ""; 108 m_contactNumber = ""; 109 m_contactPhone = ""; 110 m_contactSalutation = ""; 111 m_contactStreet = ""; 112 m_contactTitle = ""; 113 m_contactZip = ""; 114 m_copy = ""; 115 m_message = ""; 116 117 } 118 119 128 public CmsTemplateFormLetter(PageContext context, HttpServletRequest req, HttpServletResponse res) { 129 130 super(); 131 super.init(context, req, res); 132 } 133 134 139 public String getConcern() { 140 141 return m_concern; 142 } 143 144 149 public String getConcernDetail() { 150 151 return m_concernDetail; 152 } 153 154 159 public String getContactCity() { 160 161 return m_contactCity; 162 } 163 164 169 public String getContactCountry() { 170 171 return m_contactCountry; 172 } 173 174 179 public String getContactEmail() { 180 181 return m_contactEmail; 182 } 183 184 189 public String getContactFirstName() { 190 191 return m_contactFirstName; 192 } 193 194 199 public String getContactLastName() { 200 201 return m_contactLastName; 202 } 203 204 209 public String getContactNumber() { 210 211 return m_contactNumber; 212 } 213 214 219 public String getContactPhone() { 220 221 return m_contactPhone; 222 } 223 224 229 public String getContactSalutation() { 230 231 return m_contactSalutation; 232 } 233 234 239 public String getContactStreet() { 240 241 return m_contactStreet; 242 } 243 244 249 public String getContactTitle() { 250 251 return m_contactTitle; 252 } 253 254 259 public String getContactZip() { 260 261 return m_contactZip; 262 } 263 264 269 public String getCopy() { 270 271 return m_copy; 272 } 273 274 279 public String getMessage() { 280 281 return m_message; 282 } 283 284 290 public String isConcernChecked(String currentValue) { 291 292 if (isSelected(currentValue, getConcern())) { 293 return " checked=\"checked\""; 294 } 295 return ""; 296 } 297 298 303 public String isCopyChecked() { 304 305 return isChecked(getCopy()); 306 } 307 308 314 public String isSalutationSelected(String currentValue) { 315 316 if (isSelected(currentValue, getContactSalutation())) { 317 return " selected=\"selected\""; 318 } 319 return ""; 320 } 321 322 327 public boolean sendMail() { 328 329 CmsHtmlMail theMail = new CmsHtmlMail(); 331 theMail.setSubject(key("letter.mail.subject.prefix") + getPageTitle()); 332 theMail.setCharset(getRequestContext().getEncoding()); 333 theMail.setHtmlMsg(getContent("letter_mail.html", "html", getRequestContext().getLocale())); 334 theMail.setTextMsg(getContent("letter_mail.html", "text", getRequestContext().getLocale())); 335 try { 336 String uri = getRequestContext().getUri(); 338 try { 340 CmsTemplateImprint imprint = new CmsTemplateImprint(getJspContext(), getRequest(), getResponse()); 342 String receiver = imprint.getEmail(null); 344 theMail.addTo(receiver); 345 } finally { 346 getRequestContext().setUri(uri); 348 } 349 String sender = OpenCms.getSystemInfo().getMailSettings().getMailFromDefault(); 351 String contactMail = getContactEmail(); 352 if (CmsStringUtil.isEmptyOrWhitespaceOnly(contactMail)) { 353 contactMail = sender; 354 } 355 theMail.setFrom(sender); 356 theMail.addReplyTo(contactMail); 357 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { 358 theMail.addCc(contactMail); 360 } 361 theMail.send(); 363 } catch (Exception e) { 364 if (LOG.isWarnEnabled()) { 365 LOG.warn(e); 366 } else if (LOG.isErrorEnabled()) { 367 LOG.error(Messages.get().getBundle().key(Messages.LOG_SEND_MAIL_CONTACT_1)); 368 } 369 return false; 370 } 371 return true; 372 } 373 374 379 public void setConcern(String concern) { 380 381 m_concern = concern; 382 } 383 384 389 public void setConcernDetail(String concernDetail) { 390 391 m_concernDetail = concernDetail; 392 } 393 394 399 public void setContactCity(String contactCity) { 400 401 m_contactCity = contactCity; 402 } 403 404 409 public void setContactCountry(String contactCountry) { 410 411 m_contactCountry = contactCountry; 412 } 413 414 419 public void setContactEmail(String email) { 420 421 m_contactEmail = email; 422 } 423 424 429 public void setContactFirstName(String contactFirstName) { 430 431 m_contactFirstName = contactFirstName; 432 } 433 434 439 public void setContactLastName(String contactLastName) { 440 441 m_contactLastName = contactLastName; 442 } 443 444 449 public void setContactNumber(String contactNumber) { 450 451 m_contactNumber = contactNumber; 452 } 453 454 459 public void setContactPhone(String contactPhone) { 460 461 m_contactPhone = contactPhone; 462 } 463 464 469 public void setContactSalutation(String contactSalutation) { 470 471 m_contactSalutation = contactSalutation; 472 } 473 474 479 public void setContactStreet(String contactStreet) { 480 481 m_contactStreet = contactStreet; 482 } 483 484 489 public void setContactTitle(String contactTitle) { 490 491 m_contactTitle = contactTitle; 492 } 493 494 499 public void setContactZip(String contactZip) { 500 501 m_contactZip = contactZip; 502 } 503 504 509 public void setCopy(String copy) { 510 511 m_copy = copy; 512 } 513 514 519 public void setMessage(String message) { 520 521 m_message = message; 522 } 523 524 529 public boolean validate() { 530 531 boolean allOk = true; 532 setErrors(new HashMap ()); 533 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcern())) { 535 getErrors().put("concern", key("letter.error.concern.empty")); 536 allOk = false; 537 } else { 538 if ("other".equals(getConcern())) { 540 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcernDetail())) { 541 getErrors().put("concern", key("letter.error.concerndetails.empty")); 543 allOk = false; 544 } 545 } 546 } 547 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getMessage())) { 549 getErrors().put("message", key("letter.error.message.empty")); 550 allOk = false; 551 } 552 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { 553 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getContactEmail())) { 555 getErrors().put("email", key("letter.error.email.empty")); 557 allOk = false; 558 } 559 } 560 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getContactEmail()) && !isValidEmailAddress(getContactEmail())) { 561 getErrors().put("email", key("letter.error.email.wrong")); 563 allOk = false; 564 } 565 return allOk; 566 } 567 568 571 protected String checkTextsUri() { 572 573 String fileUri = getConfigurationValue("page.form.letter", null); 574 if (fileUri != null) { 575 fileUri = getRequestContext().removeSiteRoot(fileUri); 576 try { 577 getCmsObject().readResource(fileUri); 578 return fileUri; 579 } catch (CmsException e) { 580 } 582 } 583 return CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/pages/letter_content.html"; 584 } 585 586 } 587 | Popular Tags |