KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > dialogpages > UserEditIncludeRolesDialogPage


1 package info.magnolia.module.admininterface.dialogpages;
2
3 import info.magnolia.cms.beans.config.ContentRepository;
4 import info.magnolia.cms.core.Content;
5 import info.magnolia.cms.core.HierarchyManager;
6 import info.magnolia.cms.gui.control.Button;
7 import info.magnolia.cms.gui.control.Hidden;
8 import info.magnolia.cms.gui.dialog.DialogSuper;
9 import info.magnolia.cms.gui.misc.CssConstants;
10 import info.magnolia.cms.i18n.Messages;
11 import info.magnolia.cms.i18n.MessagesManager;
12 import info.magnolia.cms.security.SessionAccessControl;
13 import info.magnolia.module.admininterface.DialogPageMVCHandler;
14
15 import java.io.IOException JavaDoc;
16 import java.io.PrintWriter JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 import javax.jcr.RepositoryException;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.log4j.Logger;
25
26
27 /**
28  * @author Fabrizio Giustina
29  * @version $Id: $
30  */

31 public class UserEditIncludeRolesDialogPage extends DialogPageMVCHandler {
32
33     /**
34      * Logger.
35      */

36     private static Logger log = Logger.getLogger(UserEditIncludeRolesDialogPage.class);
37
38     public UserEditIncludeRolesDialogPage(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
39         super(name, request, response);
40     }
41
42     /**
43      * Stable serialVersionUID.
44      */

45     private static final long serialVersionUID = 222L;
46
47     private static String JavaDoc getHtmlRowInner(HttpServletRequest JavaDoc request) {
48         boolean small = true;
49         Messages msgs = MessagesManager.getMessages(request);
50
51         Button choose = new Button();
52         choose.setLabel(msgs.get("buttons.choose")); //$NON-NLS-1$
53
choose.setOnclick("mgnlAclChoose('+index+',\\\'" + ContentRepository.USER_ROLES + "\\\');"); //$NON-NLS-1$ //$NON-NLS-2$
54

55         choose.setSmall(small);
56
57         Button delete = new Button();
58         delete.setLabel(msgs.get("buttons.delete")); //$NON-NLS-1$
59
delete.setOnclick("mgnlAclDelete('+index+');"); //$NON-NLS-1$
60
delete.setSmall(small);
61
62         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
63         // set as table since ie/win does not support setting of innerHTML of a tr
64
html.append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr style=\"height:20px\">"); //$NON-NLS-1$
65

66         // todo: show name instead of path again (adapt linkBrowser.jsp, resp. Tree.java)
67
// html.append("<td id=\"acl'+index+'TdName\" width=\"100%\" class=\"mgnlDialogAcl\">'+name+'</td>");
68

69         html.append("<td width=\"100%\" class=\"" //$NON-NLS-1$
70
+ CssConstants.CSSCLASS_EDITWITHBUTTON
71             + "\"><input name=\"acl'+index+'Path\" id=\"acl'+index+'Path\" class=\"" //$NON-NLS-1$
72
+ CssConstants.CSSCLASS_EDIT
73             + "\" type=\"text\" style=\"width:100%;\" value=\"'+path+'\" /></td>"); //$NON-NLS-1$
74
html.append("<td width=\"1\"></td>"); //$NON-NLS-1$
75
html.append("<td width=\"1\" class=\"" //$NON-NLS-1$
76
+ CssConstants.CSSCLASS_EDITWITHBUTTON + "\">" //$NON-NLS-1$
77
+ choose.getHtml() + "</td>"); //$NON-NLS-1$
78
html.append("<td width=\"1\"></td>"); //$NON-NLS-1$
79
html.append("<td width=\"1\" class=\"" //$NON-NLS-1$
80
+ CssConstants.CSSCLASS_EDITWITHBUTTON + "\">" //$NON-NLS-1$
81
+ delete.getHtml() + "</td>"); //$NON-NLS-1$
82

83         html.append("</tr></table>"); //$NON-NLS-1$
84

85         return html.toString();
86     }
87
88     /**
89      * @see info.magnolia.cms.servlets.BasePageServlet#draw(HttpServletRequest, HttpServletResponse)
90      */

91     protected void draw(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc {
92         PrintWriter JavaDoc out = response.getWriter();
93
94         DialogSuper dialogControl = (DialogSuper) request.getAttribute("dialogObject"); //$NON-NLS-1$
95
Content user = dialogControl.getWebsiteNode();
96
97         out.println(new Hidden("aclList", StringUtils.EMPTY, false).getHtml()); //$NON-NLS-1$
98

99         out.println("<table id=\"aclTable\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"></table>"); //$NON-NLS-1$
100

101         out.println("<script type=\"text/javascript\">"); //$NON-NLS-1$
102
out.println("function mgnlAclGetHtmlRow(index,path,name)"); //$NON-NLS-1$
103
out.println("{"); //$NON-NLS-1$
104
out.println("return '" + getHtmlRowInner(request) + "'"); //$NON-NLS-1$ //$NON-NLS-2$
105
out.println("}"); //$NON-NLS-1$
106

107         // add existing acls to table (by js, so the same mechanism as at adding rows can be used)
108
try {
109             Content acl = user.getContent("roles"); //$NON-NLS-1$
110
Iterator JavaDoc it = acl.getChildren().iterator();
111             while (it.hasNext()) {
112                 Content c = (Content) it.next();
113                 String JavaDoc path = c.getNodeData("path").getString(); //$NON-NLS-1$
114
String JavaDoc name = StringUtils.EMPTY;
115
116                 HierarchyManager hm = SessionAccessControl.getHierarchyManager(request, ContentRepository.USER_ROLES);
117                 Content role = null;
118                 try {
119                     role = hm.getContent(path);
120                     name = role.getTitle();
121                 }
122                 catch (RepositoryException re) {
123                     if (log.isDebugEnabled()) {
124                         log.debug("Repository exception: " + re.getMessage(), re); //$NON-NLS-1$
125
}
126                 }
127
128                 out.println("mgnlAclAdd(true,-1,'" + path + "','" + name + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
129
}
130         }
131         catch (Exception JavaDoc e) {
132             out.println("mgnlAclAdd(true,-1);"); //$NON-NLS-1$
133
}
134
135         out.println("</script>"); //$NON-NLS-1$
136

137     }
138 }
139
Popular Tags