0
|
1 package nabble.view.web.forum;
|
|
2
|
|
3 import nabble.model.Message;
|
|
4 import nabble.model.ModelException;
|
|
5 import nabble.model.Node;
|
|
6 import nabble.model.export.Export;
|
|
7 import nabble.naml.compiler.Command;
|
|
8 import nabble.naml.compiler.CommandSpec;
|
|
9 import nabble.naml.compiler.IPrintWriter;
|
|
10 import nabble.naml.compiler.Interpreter;
|
|
11 import nabble.naml.compiler.Namespace;
|
|
12 import nabble.naml.compiler.ScopedInterpreter;
|
|
13 import nabble.naml.namespaces.TemplateException;
|
|
14 import nabble.view.lib.Permissions;
|
|
15 import nabble.view.web.template.NodeNamespace;
|
|
16 import nabble.view.web.template.ServletNamespace;
|
|
17 import nabble.view.web.template.UrlMapperNamespace;
|
|
18
|
|
19 import java.util.Calendar;
|
|
20
|
|
21
|
|
22 @Namespace (
|
|
23 name = "node_editor",
|
|
24 global = true
|
|
25 )
|
|
26 public final class NodeEditorNamespace {
|
|
27 private final Node node;
|
|
28 private final ServletNamespace servletNs;
|
|
29
|
|
30 public NodeEditorNamespace(Node node,ServletNamespace servletNs) {
|
|
31 this.node = node;
|
|
32 this.servletNs = servletNs;
|
|
33 }
|
|
34
|
|
35 public Node node() {
|
|
36 return node;
|
|
37 }
|
|
38
|
|
39 private Node getLocalNode(String url) throws ModelException.InvalidPermalink {
|
|
40 url = url.trim();
|
|
41 if (url.length() == 0)
|
|
42 return null;
|
|
43 Node n = UrlMapperNamespace.getNodeFromUrl(url);
|
|
44 if (n != null) {
|
|
45 return n.getSite().equals(node.getSite())? n : null;
|
|
46 }
|
|
47 // No app found. Let's check if this is a permalink url...
|
|
48 n = Permalink.getPostFromUrl(url);
|
|
49 if (n == null)
|
|
50 throw new ModelException.InvalidPermalink();
|
|
51 return n.getSite().equals(node.getSite())? n : null;
|
|
52 }
|
|
53
|
|
54 public static final CommandSpec edited_node = CommandSpec.DO;
|
|
55
|
|
56 @Command public void edited_node(IPrintWriter out,ScopedInterpreter<NodeNamespace> interp) {
|
|
57 NodeNamespace ns = new NodeNamespace(node);
|
|
58 out.print( interp.getArg(ns,"do") );
|
|
59 }
|
|
60
|
|
61 public static final CommandSpec save_node = CommandSpec.NO_OUTPUT;
|
|
62
|
|
63 @Command public void save_node(IPrintWriter out,Interpreter interp)
|
|
64 throws ModelException
|
|
65 {
|
|
66 if( node.isInDb() )
|
|
67 node.update();
|
|
68 else
|
|
69 node.insert(true);
|
|
70 }
|
|
71
|
|
72 public static final CommandSpec set_parent_url = new CommandSpec.Builder()
|
|
73 .parameters("parent_url")
|
|
74 .build()
|
|
75 ;
|
|
76
|
|
77 @Command public void set_parent_url(IPrintWriter out,Interpreter interp)
|
|
78 throws TemplateException
|
|
79 {
|
|
80 String url = interp.getArgString("parent_url");
|
|
81 Node parent = getLocalNode(url);
|
|
82 if( node.equals(parent) )
|
|
83 throw TemplateException.newInstance("same_node_loop");
|
|
84 node.changeParent(parent);
|
|
85 }
|
|
86
|
|
87 public static final CommandSpec set_subject = new CommandSpec.Builder()
|
|
88 .parameters("subject")
|
|
89 .build()
|
|
90 ;
|
|
91
|
|
92 @Command public void set_subject(IPrintWriter out,Interpreter interp)
|
|
93 throws ModelException
|
|
94 {
|
|
95 String subject = interp.getArgString("subject");
|
|
96 node.setSubject(subject);
|
|
97 }
|
|
98
|
|
99 public static final CommandSpec set_message = new CommandSpec.Builder()
|
|
100 .parameters("message","is_html")
|
|
101 .build()
|
|
102 ;
|
|
103
|
|
104 @Command public void set_message(IPrintWriter out,Interpreter interp)
|
|
105 throws ModelException
|
|
106 {
|
|
107 Message.Format msgFmt = interp.getArgAsBoolean("is_html") ? Message.Format.HTML : Message.Format.TEXT;
|
|
108 String message = interp.getArgString("message");
|
|
109 node.setMessage(message,msgFmt);
|
|
110 }
|
|
111
|
|
112 public static final CommandSpec set_type = new CommandSpec.Builder()
|
|
113 .parameters("type")
|
|
114 .build()
|
|
115 ;
|
|
116
|
|
117 @Command public void set_type(IPrintWriter out,Interpreter interp)
|
|
118 throws ModelException
|
|
119 {
|
|
120 String type = interp.getArgString("type");
|
|
121 node.setType(type);
|
|
122 }
|
|
123
|
|
124 public static final CommandSpec set_when_created = new CommandSpec.Builder()
|
|
125 .parameters("date")
|
|
126 .build()
|
|
127 ;
|
|
128
|
|
129 @Command public void set_when_created(IPrintWriter out,Interpreter interp)
|
|
130 throws ModelException
|
|
131 {
|
|
132 String date = interp.getArgString("date");
|
|
133 try {
|
|
134 Calendar cal = Calendar.getInstance();
|
|
135 cal.setTimeInMillis(Long.valueOf(date));
|
|
136 node.setWhenCreated(cal.getTime());
|
|
137 } catch (NumberFormatException e) {
|
|
138 throw ModelException.newInstance("invalid_date", "Invalid date in milliseconds");
|
|
139 }
|
|
140 }
|
|
141
|
|
142
|
|
143 public static final CommandSpec remove_permissions = CommandSpec.NO_OUTPUT;
|
|
144
|
|
145 @Command public void remove_permissions(IPrintWriter out,Interpreter interp) {
|
|
146 Permissions.removePermissions(node);
|
|
147 }
|
|
148
|
|
149 public static final CommandSpec add_permission = CommandSpec.NO_OUTPUT()
|
|
150 .parameters("permission")
|
|
151 .optionalParameters("group")
|
|
152 .build()
|
|
153 ;
|
|
154
|
|
155 @Command public void add_permission(IPrintWriter out,Interpreter interp) {
|
|
156 String perm = interp.getArgString("permission");
|
|
157 String group = interp.getArgString("group");
|
|
158 if( group == null )
|
|
159 Permissions.addPermission(node,perm);
|
|
160 else
|
|
161 Permissions.addPermission(node,perm,group);
|
|
162 }
|
|
163
|
|
164 public static final CommandSpec remove_permission = CommandSpec.NO_OUTPUT()
|
|
165 .parameters("permission")
|
|
166 .optionalParameters("group")
|
|
167 .build()
|
|
168 ;
|
|
169
|
|
170 @Command public void remove_permission(IPrintWriter out,Interpreter interp) {
|
|
171 String group = interp.getArgString("group");
|
|
172 String perm = interp.getArgString("permission");
|
|
173 if (group == null)
|
|
174 Permissions.removePermission(node,perm);
|
|
175 else
|
|
176 Permissions.removePermission(node,perm,group);
|
|
177 }
|
|
178
|
|
179 public static final CommandSpec is_valid_export_permalink = new CommandSpec.Builder()
|
|
180 .parameters("permalink")
|
|
181 .build()
|
|
182 ;
|
|
183
|
|
184 @Command public void is_valid_export_permalink(IPrintWriter out,Interpreter interp)
|
|
185 throws ModelException
|
|
186 {
|
|
187 out.print(Export.isValidExportServer(interp.getArgString("permalink")));
|
|
188 }
|
|
189 }
|