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 ; 16 import java.io.PrintWriter ; 17 import java.util.Iterator ; 18 19 import javax.jcr.RepositoryException; 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 23 import org.apache.commons.lang.StringUtils; 24 import org.apache.log4j.Logger; 25 26 27 31 public class UserEditIncludeRolesDialogPage extends DialogPageMVCHandler { 32 33 36 private static Logger log = Logger.getLogger(UserEditIncludeRolesDialogPage.class); 37 38 public UserEditIncludeRolesDialogPage(String name, HttpServletRequest request, HttpServletResponse response) { 39 super(name, request, response); 40 } 41 42 45 private static final long serialVersionUID = 222L; 46 47 private static String getHtmlRowInner(HttpServletRequest request) { 48 boolean small = true; 49 Messages msgs = MessagesManager.getMessages(request); 50 51 Button choose = new Button(); 52 choose.setLabel(msgs.get("buttons.choose")); choose.setOnclick("mgnlAclChoose('+index+',\\\'" + ContentRepository.USER_ROLES + "\\\');"); 55 choose.setSmall(small); 56 57 Button delete = new Button(); 58 delete.setLabel(msgs.get("buttons.delete")); delete.setOnclick("mgnlAclDelete('+index+');"); delete.setSmall(small); 61 62 StringBuffer html = new StringBuffer (); 63 html.append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr style=\"height:20px\">"); 66 69 html.append("<td width=\"100%\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON 71 + "\"><input name=\"acl'+index+'Path\" id=\"acl'+index+'Path\" class=\"" + CssConstants.CSSCLASS_EDIT 73 + "\" type=\"text\" style=\"width:100%;\" value=\"'+path+'\" /></td>"); html.append("<td width=\"1\"></td>"); html.append("<td width=\"1\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">" + choose.getHtml() + "</td>"); html.append("<td width=\"1\"></td>"); html.append("<td width=\"1\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">" + delete.getHtml() + "</td>"); 83 html.append("</tr></table>"); 85 return html.toString(); 86 } 87 88 91 protected void draw(HttpServletRequest request, HttpServletResponse response) throws IOException { 92 PrintWriter out = response.getWriter(); 93 94 DialogSuper dialogControl = (DialogSuper) request.getAttribute("dialogObject"); Content user = dialogControl.getWebsiteNode(); 96 97 out.println(new Hidden("aclList", StringUtils.EMPTY, false).getHtml()); 99 out.println("<table id=\"aclTable\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"></table>"); 101 out.println("<script type=\"text/javascript\">"); out.println("function mgnlAclGetHtmlRow(index,path,name)"); out.println("{"); out.println("return '" + getHtmlRowInner(request) + "'"); out.println("}"); 107 try { 109 Content acl = user.getContent("roles"); Iterator it = acl.getChildren().iterator(); 111 while (it.hasNext()) { 112 Content c = (Content) it.next(); 113 String path = c.getNodeData("path").getString(); String 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); } 126 } 127 128 out.println("mgnlAclAdd(true,-1,'" + path + "','" + name + "');"); } 130 } 131 catch (Exception e) { 132 out.println("mgnlAclAdd(true,-1);"); } 134 135 out.println("</script>"); 137 } 138 } 139 | Popular Tags |