BrightSide Workbench Full Report + Source Code
elephant/src/main/java/org/turro/mail/impl/MailMessageTemplate.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.mail.impl;
20 
21 import java.io.StringWriter;
22 import org.turro.string.Strings;
23 import org.turro.marker.ElephantMarker;
24 import org.turro.plugin.contacts.IContact;
25 
30 @Deprecated
31 public class MailMessageTemplate extends MailMessage {
32 
33  private String root;
34  private boolean processLiveLinks = true;
35 
36  public void setRoot(String root) {
37  this.root = root;
38  }
39 
40  public void setProcessLiveLinks(boolean processLiveLinks) {
41  this.processLiveLinks = processLiveLinks;
42  }
43 
44  public void setMessage(ElephantMarker marker, IContact contact) {
45  setMessage(marker, null, contact);
46  }
47 
48  public void setMessage(ElephantMarker marker, String template, IContact contact) {
49  if(contact != null && contact.isWebUser()) {
50  setMessage(marker, template, Recipient.of(contact));
51  }
52  }
53 
54  public void setMessage(ElephantMarker marker, String email, String name) {
55  setMessage(marker, null, Recipient.of(email, name));
56  }
57 
58  public void setMessage(ElephantMarker marker, String template, String email, String name) {
59  setMessage(marker, template, Recipient.of(email, name));
60  }
61 
62  public void setMessage(ElephantMarker marker, String template, Recipient recipient) {
63  StringWriter sw = new StringWriter();
64  marker.put("message", this);
65  marker.process("content" + (root == null ? "" : root), getMailTemplate(template), sw);
66  String msg = sw.toString();
67  if(processLiveLinks && !recipient.isEmpty()) {
68  msg = MailUtils.processLinks(recipient.getEmail(), msg);
69  }
70  msg = MailUtils.processUser(recipient, msg);
71  msg = MailUtils.processImgWidth(msg);
72  setMessage(msg);
73  }
74 
75  public String getMailTemplate(String template) {
76  return Strings.isBlank(template) ? "default-mail" : template;
77  }
78 
79 }
void setMessage(ElephantMarker marker, String template, IContact contact)
void setMessage(ElephantMarker marker, String template, Recipient recipient)
void setMessage(ElephantMarker marker, String template, String email, String name)
static String processLinks(IContact contact, String message)
static String processUser(IContact contact, String message)
static Recipient of(IContact contact)
Definition: Recipient.java:81
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)