0
|
1 package nabble.view.web.template;
|
|
2
|
|
3 import fschmidt.html.Html;
|
|
4 import nabble.model.FileUpload;
|
|
5 import nabble.model.MailMessageFormat;
|
|
6 import nabble.model.Message;
|
|
7 import nabble.model.Node;
|
|
8 import nabble.naml.compiler.Command;
|
|
9 import nabble.naml.compiler.CommandSpec;
|
|
10 import nabble.naml.compiler.IPrintWriter;
|
|
11 import nabble.naml.compiler.Interpreter;
|
|
12 import nabble.naml.compiler.Namespace;
|
|
13 import nabble.naml.compiler.ScopedInterpreter;
|
|
14
|
|
15
|
|
16 @Namespace (
|
|
17 name = "message",
|
|
18 global = false
|
|
19 )
|
|
20 public final class MessageNamespace {
|
|
21 private final Message message;
|
|
22
|
|
23 public MessageNamespace(Message message) {
|
|
24 this.message = message;
|
|
25 }
|
|
26
|
|
27 @Command public void as_text(IPrintWriter out,Interpreter interp) {
|
|
28 out.print( interp.encode(message.getText()) );
|
|
29 }
|
|
30
|
|
31 @Command public void as_quoted_text(IPrintWriter out,Interpreter interp) {
|
|
32 boolean isMail = message.getFormat() instanceof MailMessageFormat;
|
|
33 if( isMail ) {
|
|
34 Html html = new Html(message.getText());
|
|
35 MailMessageFormat.tagEmails(html,(Node)message.getSource());
|
|
36 out.print(html);
|
|
37 } else {
|
|
38 Html html = new Html(message.getRaw());
|
|
39 FileUpload.processFileTags(html,message.getSource());
|
|
40 out.print(html);
|
|
41 }
|
|
42 }
|
|
43
|
|
44 @Command public void as_text_without_quotes(IPrintWriter out,Interpreter interp) {
|
|
45 out.print( interp.encode(message.getTextWithoutQuotes()) );
|
|
46 }
|
|
47
|
|
48 @Command public void as_raw(IPrintWriter out,Interpreter interp) {
|
|
49 out.print( message.getRaw() );
|
|
50 }
|
|
51
|
|
52 @Command public void as_editable(IPrintWriter out,Interpreter interp) {
|
|
53 boolean isMail = message.getFormat() instanceof MailMessageFormat;
|
|
54 out.print( isMail ? message.getText() : message.getRaw() );
|
|
55 }
|
|
56
|
|
57 @Command public void is_imported_mail(IPrintWriter out,Interpreter interp) {
|
|
58 out.print( message.getFormat().isMail() );
|
|
59 }
|
|
60
|
|
61 @Command public void is_html_format(IPrintWriter out,Interpreter interp) {
|
|
62 out.print( message.getFormat() == Message.Format.HTML );
|
|
63 }
|
|
64
|
|
65 @Command public void is_text_format(IPrintWriter out,Interpreter interp) {
|
|
66 out.print( message.getFormat() == Message.Format.TEXT );
|
|
67 }
|
|
68
|
|
69 @Command public void is_deleted(IPrintWriter out,Interpreter interp) {
|
|
70 out.print( message.isDeleted() );
|
|
71 }
|
|
72
|
|
73 @Command public void is_deactivated(IPrintWriter out,Interpreter interp) {
|
|
74 out.print( message.isDeactivated() );
|
|
75 }
|
|
76
|
|
77 @Command public void format(IPrintWriter out,Interpreter interp) {
|
|
78 String s = message.getFormat().getName();
|
|
79 if( s.equals("subscription") )
|
|
80 s = "mail"; // hack for now
|
|
81 out.print(s);
|
|
82 }
|
|
83
|
|
84
|
|
85 public static final CommandSpec as_html_list = CommandSpec.DO;
|
|
86
|
|
87 @Command public void as_html_list(IPrintWriter out,ScopedInterpreter<HtmlListNamespace> interp) {
|
|
88 HtmlListNamespace html = new HtmlListNamespace( message.parse(), message.getSource(), message.getFormat());
|
|
89 interp.getArgString(html,"do");
|
|
90 out.print(html);
|
|
91 }
|
|
92
|
|
93 public static final CommandSpec as_raw_html_list = CommandSpec.DO;
|
|
94
|
|
95 @Command public void as_raw_html_list(IPrintWriter out,ScopedInterpreter<HtmlListNamespace> interp) {
|
|
96 HtmlListNamespace html = new HtmlListNamespace( new Html(message.getRaw()), message.getSource(), message.getFormat());
|
|
97 interp.getArgString(html,"do");
|
|
98 out.print(html);
|
|
99 }
|
|
100
|
|
101 public static final CommandSpec as_text_list = CommandSpec.DO;
|
|
102
|
|
103 @Command public void as_text_list(IPrintWriter out,ScopedInterpreter<HtmlListNamespace> interp) {
|
|
104 boolean isMail = message.getFormat() instanceof MailMessageFormat;
|
|
105 if( isMail ) {
|
|
106 out.print( message.getText() );
|
|
107 } else {
|
|
108 HtmlListNamespace html = new HtmlListNamespace( message.parseForMailText(), message.getSource(), message.getFormat());
|
|
109 interp.getArgString(html,"do");
|
|
110 out.print( html.toMailText() );
|
|
111 }
|
|
112 }
|
|
113
|
|
114 }
|