📄 cmstemplateformletter.java
字号:
return "";
}
/**
* Examines the value of the send copy checkbox and returns the "checked" attribute.<p>
*
* @return the "checked" attribute or an empty String
*/
public String isCopyChecked() {
return isChecked(getCopy());
}
/**
* Returns the "selected" attribute if the current "contact option" is selected.<p>
*
* @param currentValue the value of the current radio button to check
* @return the "selected" attribute if the current "contact option" is selected
*/
public String isSalutationSelected(String currentValue) {
if (isSelected(currentValue, getContactSalutation())) {
return " selected=\"selected\"";
}
return "";
}
/**
* Sends the recommendation email(s) to the recipient and/or the sender.<p>
*
* @return true if the emails were successfully sent, otherwise false;
*/
public boolean sendMail() {
// create the new mail message
CmsHtmlMail theMail = new CmsHtmlMail();
theMail.setSubject(key("letter.mail.subject.prefix") + getPageTitle());
theMail.setCharset(getRequestContext().getEncoding());
theMail.setHtmlMsg(getContent("letter_mail.html", "html", getRequestContext().getLocale()));
theMail.setTextMsg(getContent("letter_mail.html", "text", getRequestContext().getLocale()));
try {
// store the uri
String uri = getRequestContext().getUri();
// set the recipient from imprint information
try {
// create an instance of imprint bean
CmsTemplateImprint imprint = new CmsTemplateImprint(getJspContext(), getRequest(), getResponse());
// get the author email address
String receiver = imprint.getEmail(null);
theMail.addTo(receiver);
} finally {
// set request context uri back because this is changed in imprint bean
getRequestContext().setUri(uri);
}
// set the recipient and the reply to address
String sender = OpenCms.getSystemInfo().getMailSettings().getMailFromDefault();
String contactMail = getContactEmail();
if (CmsStringUtil.isEmptyOrWhitespaceOnly(contactMail)) {
contactMail = sender;
}
theMail.setFrom(sender);
theMail.addReplyTo(contactMail);
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) {
// send a copy of the mail to the sender
theMail.addCc(contactMail);
}
// send the mail
theMail.send();
} catch (Exception e) {
if (LOG.isWarnEnabled()) {
LOG.warn(e);
} else if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_SEND_MAIL_CONTACT_1));
}
return false;
}
return true;
}
/**
* Sets the concern of contact.<p>
*
* @param concern the concern of contact
*/
public void setConcern(String concern) {
m_concern = concern;
}
/**
* Sets the concern details if specified.<p>
*
* @param concernDetail the concern details if specified
*/
public void setConcernDetail(String concernDetail) {
m_concernDetail = concernDetail;
}
/**
* Sets the contact city.<p>
*
* @param contactCity the contact city
*/
public void setContactCity(String contactCity) {
m_contactCity = contactCity;
}
/**
* Sets the contact country.<p>
*
* @param contactCountry the contact country
*/
public void setContactCountry(String contactCountry) {
m_contactCountry = contactCountry;
}
/**
* Sets the contact email address.<p>
*
* @param email the contact email address
*/
public void setContactEmail(String email) {
m_contactEmail = email;
}
/**
* Sets the contact first name.<p>
*
* @param contactFirstName the contact first name
*/
public void setContactFirstName(String contactFirstName) {
m_contactFirstName = contactFirstName;
}
/**
* Sets the contact last name.<p>
*
* @param contactLastName the contact last name
*/
public void setContactLastName(String contactLastName) {
m_contactLastName = contactLastName;
}
/**
* Sets the contact street number.<p>
*
* @param contactNumber the contact street number
*/
public void setContactNumber(String contactNumber) {
m_contactNumber = contactNumber;
}
/**
* Sets the contact phone number.<p>
*
* @param contactPhone the contact phone number
*/
public void setContactPhone(String contactPhone) {
m_contactPhone = contactPhone;
}
/**
* Sets the contact salutation.<p>
*
* @param contactSalutation the contact salutation
*/
public void setContactSalutation(String contactSalutation) {
m_contactSalutation = contactSalutation;
}
/**
* Sets the contact street.<p>
*
* @param contactStreet the contact street
*/
public void setContactStreet(String contactStreet) {
m_contactStreet = contactStreet;
}
/**
* Sets the contact title.<p>
*
* @param contactTitle the contact title
*/
public void setContactTitle(String contactTitle) {
m_contactTitle = contactTitle;
}
/**
* Sets the contact zip code.<p>
*
* @param contactZip the contact zip code
*/
public void setContactZip(String contactZip) {
m_contactZip = contactZip;
}
/**
* Sets the send copy to sender flag.<p>
*
* @param copy the send copy to sender flag
*/
public void setCopy(String copy) {
m_copy = copy;
}
/**
* Sets the message for the recipient.<p>
*
* @param message the message for the recipient
*/
public void setMessage(String message) {
m_message = message;
}
/**
* Validates the values of the input fields and creates error messages, if necessary.<p>
*
* @return true if all checked input values are valid, otherwise false
*/
public boolean validate() {
boolean allOk = true;
setErrors(new HashMap());
// check concern
if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcern())) {
getErrors().put("concern", key("letter.error.concern.empty"));
allOk = false;
} else {
// concern given, check if "other" is selected
if ("other".equals(getConcern())) {
if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcernDetail())) {
// details not given
getErrors().put("concern", key("letter.error.concerndetails.empty"));
allOk = false;
}
}
}
// check message
if (CmsStringUtil.isEmptyOrWhitespaceOnly(getMessage())) {
getErrors().put("message", key("letter.error.message.empty"));
allOk = false;
}
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) {
// send copy to sender is checked, check email address
if (CmsStringUtil.isEmptyOrWhitespaceOnly(getContactEmail())) {
// email address is empty
getErrors().put("email", key("letter.error.email.empty"));
allOk = false;
}
}
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getContactEmail()) && !isValidEmailAddress(getContactEmail())) {
// email address is not valid
getErrors().put("email", key("letter.error.email.wrong"));
allOk = false;
}
return allOk;
}
/**
* @see org.opencms.frontend.templateone.CmsTemplateForm#checkTextsUri()
*/
protected String checkTextsUri() {
String fileUri = getConfigurationValue("page.form.letter", null);
if (fileUri != null) {
fileUri = getRequestContext().removeSiteRoot(fileUri);
try {
getCmsObject().readResource(fileUri);
return fileUri;
} catch (CmsException e) {
// file not found, use default texts page file
}
}
return CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/pages/letter_content.html";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -