My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package action;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.neo4j.graphdb.Transaction;

import net.sourceforge.stripes.action.Before;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.HandlesEvent;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.controller.LifecycleStage;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import example.model.Post;
import example.model.Tag;

@UrlBinding("/blog/post")
public class PostAction extends BaseAction {

private Post post;
private String tag;

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

private Collection<String> splitTags() {
Set<String> results = new HashSet<String>();
if (tag!=null)
for (String str : tag.split(","))
results.add(str.trim());
return results;
}


@Before(stages = LifecycleStage.EventHandling)
public Resolution secure() throws Exception {
return ( context.getLogin() == null) ?
new RedirectResolution(LoginAction.class) : null;
}

@DefaultHandler
public Resolution start() {
return new ForwardResolution("/post.jsp");
}

@HandlesEvent("addTag")
public Resolution addTag() {
return new ForwardResolution("/post.jsp");
}

@HandlesEvent("save")
public Resolution post() {
Transaction t = pm().beginTx();
try {
post.setAuthor(context.getLogin());
for (String tagname : splitTags())
post.addTag(forName(tagname));
post.save();
t.success();
} finally {
t.finish();
}
return new RedirectResolution(HubAction.class);
}

private Tag forName(String str) {
Tag tag = new Tag();
tag = pm().find(tag).where(tag.name).is(str).result();
if (tag==null)
tag = new Tag(str);
return tag;
}

@ValidateNestedProperties({
@Validate(field="title", required=true, maxlength=75, on = "post"),
@Validate(field="content", required=true, maxlength=5000, on = "post")
})
public Post getPost() {
return post;
}

public void setPost(Post post) {
this.post = post;
}
}

Change log

r439 by thewebsemantic on Feb 6, 2010   Diff

 
Go to: 
Project members, sign in to write a code review

Older revisions

r311 by thewebsemantic on Dec 29, 2009   Diff
[No log message]
r245 by thewebsemantic on Dec 22, 2009   Diff
[No log message]
r242 by thewebsemantic on Dec 22, 2009   Diff
[No log message]
All revisions of this file

File info

Size: 2424 bytes, 95 lines
Powered by Google Project Hosting