1 package net.sourceforge.blogentis.plugins.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.Arrays;
26 import java.util.List;
27
28 import net.sourceforge.blogentis.om.Blog;
29 import net.sourceforge.blogentis.plugins.IPlugin;
30 import net.sourceforge.blogentis.plugins.base.AbstractNavigationExtension;
31 import net.sourceforge.blogentis.turbine.BlogRunData;
32 import net.sourceforge.blogentis.utils.AbsoluteLinkURL;
33 import net.sourceforge.blogentis.utils.tools.SecurityTool;
34
35 /***
36 * This extension adds user preferences to the navigations.
37 *
38 * @author abas
39 */
40 public class UserNavigationExtension
41 extends AbstractNavigationExtension {
42
43 private static final String USER_PREFS = "UserPrefs";
44
45 public UserNavigationExtension(IPlugin plugin, Blog blog) {
46 super(plugin, blog);
47 }
48
49 private static final LinkToTemplate[] userPrefsPages = new LinkToSplitPage[] {
50 new LinkToSplitPage("UserIndex", "Your Feeds", "0"),
51 new LinkToSplitPage("UserIndex", "Personal Info", "1"),
52 new LinkToSplitPage("UserIndex", "Set Password", "2"),
53 new LinkToSplitPage("UserIndex", "Preferences", "3")};
54
55 private static final AbstractLink[] authoringActions = new AbstractLink[] {
56 new EditPost(),
57 new LinkToParameterPage("PostEdit", "New Post", "create", "true",
58 AuthorAuthenticator)};
59
60 private static final List userList = Arrays.asList(userPrefsPages),
61 authoringList = Arrays.asList(authoringActions);
62
63 private static final AbstractLink adminLink = new LinkToTemplate(
64 "BlogUsers", "Admin", BlogAdminAuthenticator),
65 userIndex = new LinkToTemplate("UserIndex", "Preferences"),
66 logIn = new LogInOut("LogoutUser", "Logout"),
67 logOut = new LinkToTemplate("LoginUser", "Login");
68
69 public void addNavigations(BlogRunData data, String navName, List links) {
70 SecurityTool st = new SecurityTool(data);
71 if (USER_PREFS.equals(navName)) {
72 links.addAll(userList);
73 } else if (USER_ACTIONS_NAME.equals(navName)) {
74 if (data.getUser().hasLoggedIn()) {
75 links.addAll(authoringList);
76 links.add(adminLink);
77 links.add(userIndex);
78 links.add(logIn);
79 } else {
80 links.add(logOut);
81 }
82 } else if (AUTHORING_ACTIONS_NAME.equals(navName)) {
83 links.addAll(authoringList);
84 }
85 }
86
87 public String getName() {
88 return "User preferences additions to navigation";
89 }
90
91 public static class EditPost
92 extends AbstractLink {
93 public EditPost() {
94 super("Edit Post", new Authenticator() {
95 public boolean isVisible(BlogRunData data) {
96 return new SecurityTool(data).getCanEditThisPost();
97 }
98 });
99 }
100
101 public AbsoluteLinkURL getLink(BlogRunData data, AbsoluteLinkURL link) {
102 return link.thisPage(data).setPage("PostEdit");
103 }
104
105 public boolean isCurrentPage(BlogRunData data) {
106 return false;
107 }
108 }
109
110 public static class LogInOut
111 extends AbstractLink {
112 String action;
113
114 public LogInOut(String action, String name) {
115 super(name, null);
116 this.action = action;
117 }
118
119 public AbsoluteLinkURL getLink(BlogRunData data, AbsoluteLinkURL link) {
120 return link.thisPage(data).setAction(action);
121 }
122
123 public boolean isCurrentPage(BlogRunData data) {
124 return false;
125 }
126 }
127 }