Return-Path: Delivered-To: apmail-portals-jetspeed-dev-archive@www.apache.org Received: (qmail 91036 invoked from network); 18 Feb 2010 16:50:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Feb 2010 16:50:05 -0000 Received: (qmail 41738 invoked by uid 500); 18 Feb 2010 16:50:05 -0000 Delivered-To: apmail-portals-jetspeed-dev-archive@portals.apache.org Received: (qmail 41683 invoked by uid 500); 18 Feb 2010 16:50:04 -0000 Mailing-List: contact jetspeed-dev-help@portals.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@portals.apache.org Received: (qmail 41673 invoked by uid 99); 18 Feb 2010 16:50:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Feb 2010 16:50:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Feb 2010 16:50:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3676723888BD; Thu, 18 Feb 2010 16:49:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r911486 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java webapp/WEB-INF/view/custom/config-mode.vm Date: Thu, 18 Feb 2010 16:49:40 -0000 To: jetspeed-dev@portals.apache.org From: woonsan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100218164940.3676723888BD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: woonsan Date: Thu Feb 18 16:49:39 2010 New Revision: 911486 URL: http://svn.apache.org/viewvc?rev=911486&view=rev Log: JS2-1107: fixing custom config mode portlet based on new page layout component. Thanks to Randy for providing the proper apis. Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/config-mode.vm Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java?rev=911486&r1=911485&r2=911486&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/custom/CustomConfigModePortlet.java Thu Feb 18 16:49:39 2010 @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -33,14 +34,18 @@ import javax.portlet.RenderResponse; import javax.portlet.WindowState; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; import org.apache.jetspeed.CommonPortletServices; +import org.apache.jetspeed.PortalReservedParameters; +import org.apache.jetspeed.layout.PageLayoutComponent; import org.apache.jetspeed.om.common.SecurityConstraint; import org.apache.jetspeed.om.common.SecurityConstraints; -import org.apache.jetspeed.om.page.BaseFragmentElement; -import org.apache.jetspeed.om.page.Page; +import org.apache.jetspeed.om.page.ContentFragment; +import org.apache.jetspeed.om.page.ContentPage; import org.apache.jetspeed.page.PageManager; +import org.apache.jetspeed.request.RequestContext; import org.apache.portals.bridges.velocity.GenericVelocityPortlet; -import org.springframework.util.StringUtils; /** * Common Custom Config Mode Portlet @@ -50,34 +55,52 @@ public class CustomConfigModePortlet extends GenericVelocityPortlet { private static final PortletMode CONFIG_MODE = new PortletMode("config"); - private static final String DELIMITERS = "[],; "; + private static final String DELIMITERS = "[],; \t\r\n"; private PageManager pageManager; + private PageLayoutComponent pageLayoutComponent; private String configPage; + @Override public void init(PortletConfig config) throws PortletException { super.init(config); - this.configPage = config.getInitParameter("ConfigPage"); + configPage = config.getInitParameter("ConfigPage"); PortletContext context = getPortletContext(); - this.pageManager = (PageManager) context.getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT); - if (this.pageManager == null) + pageManager = (PageManager) context.getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT); + + if (pageManager == null) { throw new PortletException("Could not get instance of pageManager component"); } + + pageLayoutComponent = (PageLayoutComponent) context.getAttribute(CommonPortletServices.CPS_PAGE_LAYOUT_COMPONENT); + + if (pageLayoutComponent == null) + { + throw new PortletException("Could not get instance of pageLayoutComponent"); + } } + @Override protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException { - if ( !request.getWindowState().equals(WindowState.MINIMIZED)) + if (!request.getWindowState().equals(WindowState.MINIMIZED)) { PortletMode curMode = request.getPortletMode(); if (CONFIG_MODE.equals(curMode)) { + ContentFragment curFragment = (ContentFragment) request.getAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE); + + if (curFragment == null) + { + throw new PortletException("Cannot retrieve current fragment from the request."); + } + List securityContraintRefList = null; try @@ -94,7 +117,11 @@ request.setAttribute("securityContraintRefList", securityContraintRefList); } + request.setAttribute("fragmentId", curFragment.getId()); + request.setAttribute("securityConstraints", new TransientSecurityConstraints(curFragment.getSecurityConstraints())); + request.setAttribute(PARAM_EDIT_PAGE, this.configPage); + doEdit(request, response); } else @@ -104,6 +131,7 @@ } } + @Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { String action = request.getParameter("action"); @@ -122,66 +150,82 @@ } } + @Override + protected String getTitle(RenderRequest request) + { + String title = null; + + try + { + ContentFragment curFragment = (ContentFragment) request.getAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE); + title = curFragment.getPortletContent().getTitle(); + } + catch (Exception ignore) + { + } + + if (title != null) + { + return title; + } + + return super.getTitle(request); + } + private void addSecurityConstraint(ActionRequest request, ActionResponse response) throws PortletException, IOException { try { - String path = request.getParameter("path"); + RequestContext requestContext = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV); + ContentPage page = requestContext.getPage(); String fragmentId = request.getParameter("fragment"); - String type = request.getParameter("type"); - String roles = request.getParameter("roles"); - String groups = request.getParameter("groups"); - String users = request.getParameter("users"); - String permissions = request.getParameter("permissions"); - Page page = this.pageManager.getPage(path); - BaseFragmentElement fragment = page.getFragmentById(fragmentId); + ContentFragment fragment = page.getFragmentById(fragmentId); if (fragment == null) { - throw new IllegalStateException("Cannot find fragment: " + fragmentId); + throw new PortletException("Cannot find fragment: " + fragmentId); } - SecurityConstraints constraints = fragment.getSecurityConstraints(); + SecurityConstraints constraints = new TransientSecurityConstraints(fragment.getSecurityConstraints()); + SecurityConstraint constraint = new TransientSecurityConstraint(fragment.newSecurityConstraint()); + String [] rolesArray = StringUtils.split(request.getParameter("roles"), DELIMITERS); + String [] groupsArray = StringUtils.split(request.getParameter("groups"), DELIMITERS); + String [] usersArray = StringUtils.split(request.getParameter("users"), DELIMITERS); - if (constraints == null) + if (!ArrayUtils.isEmpty(rolesArray)) { - constraints = fragment.newSecurityConstraints(); + constraint.setRoles(Arrays.asList(rolesArray)); } - SecurityConstraint constraint = fragment.newSecurityConstraint(); - Set roleSet = convertToSet(roles, DELIMITERS); - Set groupSet = convertToSet(groups, DELIMITERS); - Set userSet = convertToSet(users, DELIMITERS); - - if (!roleSet.isEmpty()) + if (!ArrayUtils.isEmpty(groupsArray)) { - constraint.setRoles(new ArrayList(roleSet)); + constraint.setGroups(Arrays.asList(groupsArray)); } - if (!groupSet.isEmpty()) + + if (!ArrayUtils.isEmpty(usersArray)) { - constraint.setGroups(new ArrayList(groupSet)); + constraint.setUsers(Arrays.asList(usersArray)); } - if (!userSet.isEmpty()) + + String [] permissionArray = StringUtils.split(StringUtils.defaultString(request.getParameter("permissions")), DELIMITERS); + + if (!ArrayUtils.isEmpty(permissionArray)) { - constraint.setUsers(new ArrayList(userSet)); + constraint.setPermissions(Arrays.asList(permissionArray)); } - Set permissionSet = convertToSet(permissions, DELIMITERS); - - constraint.setPermissions(new ArrayList(permissionSet)); - List constraintList = constraints.getSecurityConstraints(); + List constraintList = constraints.getSecurityConstraints(); if (constraintList == null) { - constraintList = new ArrayList(); + constraintList = new ArrayList(); } constraintList.add(constraint); - constraints.setSecurityConstraints(constraintList); - fragment.setSecurityConstraints(constraints); - this.pageManager.updatePage(page); + + pageLayoutComponent.updateSecurityConstraints(fragment, constraints); } catch (Exception e) { @@ -193,24 +237,25 @@ { try { - String path = request.getParameter("path"); + RequestContext requestContext = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV); + ContentPage page = requestContext.getPage(); String fragmentId = request.getParameter("fragment"); - String roles = request.getParameter("roles"); - String groups = request.getParameter("groups"); - String users = request.getParameter("users"); - String permissions = request.getParameter("permissions"); - Page page = this.pageManager.getPage(path); - BaseFragmentElement fragment = page.getFragmentById(fragmentId); + ContentFragment fragment = page.getFragmentById(fragmentId); if (fragment == null) { - throw new IllegalStateException("Cannot find fragment: " + fragmentId); + throw new PortletException("Cannot find fragment: " + fragmentId); } + + String roles = request.getParameter("roles"); + String groups = request.getParameter("groups"); + String users = request.getParameter("users"); + String permissions = request.getParameter("permissions"); - SecurityConstraints constraints = fragment.getSecurityConstraints(); + SecurityConstraints constraints = new TransientSecurityConstraints(fragment.getSecurityConstraints()); - List constraintList = null; + List constraintList = null; if (constraints != null) { @@ -222,17 +267,17 @@ { SecurityConstraint constraint = (SecurityConstraint) it.next(); - Set removeRoleSet = convertToSet(roles, DELIMITERS); - Set removeGroupSet = convertToSet(groups, DELIMITERS); - Set removeUserSet = convertToSet(users, DELIMITERS); + String [] removeRoleArray = StringUtils.split(roles, DELIMITERS); + String [] removeGroupArray = StringUtils.split(groups, DELIMITERS); + String [] removeUserArray = StringUtils.split(users, DELIMITERS); - List roleList = constraint.getRoles(); - List groupList = constraint.getGroups(); - List userList = constraint.getUsers(); + List roleList = constraint.getRoles(); + List groupList = constraint.getGroups(); + List userList = constraint.getUsers(); - if (equalsSetAndList(removeRoleSet, roleList) && - equalsSetAndList(removeGroupSet, groupList) && - equalsSetAndList(removeUserSet, userList)) + if (hasEqualItems(removeRoleArray, roleList) && + hasEqualItems(removeGroupArray, groupList) && + hasEqualItems(removeUserArray, userList)) { it.remove(); break; @@ -246,8 +291,7 @@ constraints.setSecurityConstraints(constraintList); } - fragment.setSecurityConstraints(constraints.isEmpty() ? null : constraints); - this.pageManager.updatePage(page); + pageLayoutComponent.updateSecurityConstraints(fragment, constraints); } catch (Exception e) { @@ -259,26 +303,22 @@ { try { - String path = request.getParameter("path"); + RequestContext requestContext = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV); + ContentPage page = requestContext.getPage(); String fragmentId = request.getParameter("fragment"); - String [] securityConstraintRefs = request.getParameterValues("securityConstraintRef"); - Page page = this.pageManager.getPage(path); - BaseFragmentElement fragment = page.getFragmentById(fragmentId); + ContentFragment fragment = page.getFragmentById(fragmentId); if (fragment == null) { - throw new IllegalStateException("Cannot find fragment: " + fragmentId); + throw new PortletException("Cannot find fragment: " + fragmentId); } - SecurityConstraints constraints = fragment.getSecurityConstraints(); + String [] securityConstraintRefs = request.getParameterValues("securityConstraintRef"); - if (constraints == null) - { - constraints = fragment.newSecurityConstraints(); - } + SecurityConstraints constraints = new TransientSecurityConstraints(fragment.getSecurityConstraints()); - Set constraintRefSet = new HashSet(); + Set constraintRefSet = new HashSet(); if (securityConstraintRefs != null) { @@ -291,9 +331,9 @@ } } - constraints.setSecurityConstraintsRefs(constraintRefSet.isEmpty() ? null : new ArrayList(constraintRefSet)); - fragment.setSecurityConstraints(constraints.isEmpty() ? null : constraints); - this.pageManager.updatePage(page); + constraints.setSecurityConstraintsRefs(constraintRefSet.isEmpty() ? null : new ArrayList(constraintRefSet)); + + pageLayoutComponent.updateSecurityConstraints(fragment, constraints); } catch (Exception e) { @@ -301,37 +341,170 @@ } } - private Set convertToSet(String s, String delimiters) + private boolean hasEqualItems(String [] array, List list) { - Set set = new HashSet(); - - String [] tokens = StringUtils.tokenizeToStringArray(s, delimiters, true, true); + if (ArrayUtils.isEmpty(array)) + { + return (list == null || list.isEmpty()); + } + else if (list == null) + { + return ArrayUtils.isEmpty(array); + } + else if (ArrayUtils.getLength(array) == list.size()) + { + for (String item : array) + { + if (!list.contains(item)) + { + return false; + } + } - if (tokens != null) + return true; + } + + return false; + } + + private class TransientSecurityConstraints implements SecurityConstraints + { + private String owner; + private List securityConstraints; + private List securityConstraintsRefs; + + public TransientSecurityConstraints(SecurityConstraints sourceSecurityConstraints) { - for (int i = 0; i < tokens.length; i++) + if (sourceSecurityConstraints != null) { - set.add(tokens[i]); + this.owner = sourceSecurityConstraints.getOwner(); + + List sourceConstraintList = sourceSecurityConstraints.getSecurityConstraints(); + + if (sourceConstraintList != null) + { + this.securityConstraints = new ArrayList(); + + for (SecurityConstraint constraint : sourceConstraintList) + { + this.securityConstraints.add(new TransientSecurityConstraint(constraint)); + } + } + + List constraintsRefs = sourceSecurityConstraints.getSecurityConstraintsRefs(); + + if (constraintsRefs != null) + { + securityConstraintsRefs = new ArrayList(constraintsRefs); + } } } - return set; + public String getOwner() + { + return owner; + } + + public List getSecurityConstraints() + { + return securityConstraints; + } + + public List getSecurityConstraintsRefs() + { + return securityConstraintsRefs; + } + + public boolean isEmpty() + { + return (this.securityConstraints == null || this.securityConstraints.isEmpty()) && (this.securityConstraintsRefs == null || this.securityConstraintsRefs.isEmpty()); + } + + public void setOwner(String owner) + { + this.owner = owner; + } + + public void setSecurityConstraints(List constraints) + { + this.securityConstraints = constraints; + } + + public void setSecurityConstraintsRefs(List constraintsRefs) + { + this.securityConstraintsRefs = constraintsRefs; + } } - private boolean equalsSetAndList(Set set, List list) + private class TransientSecurityConstraint implements SecurityConstraint { - if (set == null) + private List roles; + private List groups; + private List users; + private List permissions; + + public TransientSecurityConstraint(SecurityConstraint sourceSecurityConstraint) { - return (list == null || list.isEmpty()); + if (sourceSecurityConstraint.getRoles() != null) + { + this.roles = new ArrayList(sourceSecurityConstraint.getRoles()); + } + + if (sourceSecurityConstraint.getGroups() != null) + { + this.groups = new ArrayList(sourceSecurityConstraint.getGroups()); + } + + if (sourceSecurityConstraint.getUsers() != null) + { + this.users = new ArrayList(sourceSecurityConstraint.getUsers()); + } + + if (sourceSecurityConstraint.getPermissions() != null) + { + this.permissions = new ArrayList(sourceSecurityConstraint.getPermissions()); + } } - else if (list == null) + + public List getGroups() + { + return groups; + } + + public List getPermissions() { - return set.isEmpty(); + return permissions; } - else + + public List getRoles() + { + return roles; + } + + public List getUsers() + { + return users; + } + + public void setGroups(List groups) + { + this.groups = groups; + } + + public void setPermissions(List permissions) + { + this.permissions = permissions; + } + + public void setRoles(List roles) + { + this.roles = roles; + } + + public void setUsers(List users) { - return set.equals(new HashSet(list)); + this.users = users; } } -} \ No newline at end of file +} Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/config-mode.vm URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/config-mode.vm?rev=911486&r1=911485&r2=911486&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/config-mode.vm (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/custom/config-mode.vm Thu Feb 18 16:49:39 2010 @@ -16,14 +16,11 @@ *# #set ($MESSAGES = $portletConfig.getResourceBundle($renderRequest.Locale)) -#set($curPage = $renderRequest.getAttribute("org.apache.jetspeed.Page")) -#set($curFrag = $renderRequest.getAttribute("org.apache.jetspeed.Fragment")) -#set($constraintList = $curFrag.securityConstraints.securityConstraints) -#set($constraintsRefList = $curFrag.securityConstraints.securityConstraintsRefs) +#set($fragmentId = $renderRequest.getAttribute("fragmentId")) +#set($securityConstraints = $renderRequest.getAttribute("securityConstraints")) +#set($constraintList = $securityConstraints.securityConstraints) +#set($constraintsRefList = $securityConstraints.securityConstraintsRefs) #set($securityContraintRefList = $renderRequest.getAttribute("securityContraintRefList")) - -$renderResponse.setTitle($curFrag.getPortletContent().getTitle()) - #set($actionUrl = $renderResponse.createActionURL())
@@ -65,8 +62,7 @@
- - + @@ -91,8 +87,7 @@ $MESSAGES.getString("customconfigmode.label.constraintref") - - + - - + --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org For additional commands, e-mail: jetspeed-dev-help@portals.apache.org