Author: woonsan
Date: Mon Feb  8 18:29:53 2010
New Revision: 907748

URL: http://svn.apache.org/viewvc?rev=907748&view=rev
Log:
JS2-1057: Adding cancel button in space management portlet. Also code clean ups 
in java/jsp.

Modified:
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/spaces/resources/SpacesResources.properties
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp

Modified: 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java?rev=907748&r1=907747&r2=907748&view=diff
==============================================================================
--- 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
 (original)
+++ 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
 Mon Feb  8 18:29:53 2010
@@ -62,15 +62,24 @@
     {
         super.init(config);
         PortletContext context = getPortletContext();
+        
         portalConfig = (PortalConfiguration) 
context.getAttribute(CommonPortletServices.CPS_PORTAL_CONFIGURATION);
+        if (portalConfig == null)
+        {
+            throw new PortletException("Could not get instance of portal 
config component");
+        }
+        
         spacesService = (Spaces) 
context.getAttribute(CommonPortletServices.CPS_SPACES_SERVICE);
         if (spacesService == null)
-                throw new PortletException(
-                        "Could not get instance of portal spaces service 
component");
-        admin = (PortalAdministration) getPortletContext().getAttribute(
-                CommonPortletServices.CPS_PORTAL_ADMINISTRATION);
-        if (null == admin) { throw new PortletException(
-                "Failed to find the Portal Administration on portlet 
initialization"); }
+        {
+            throw new PortletException("Could not get instance of portal 
spaces service component");
+        }
+        
+        admin = (PortalAdministration) 
context.getAttribute(CommonPortletServices.CPS_PORTAL_ADMINISTRATION);
+        if (admin == null)
+        {
+            throw new PortletException("Failed to find the Portal 
Administration on portlet initialization");
+        }
     }
 
     @SuppressWarnings("unchecked")

Modified: 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java?rev=907748&r1=907747&r2=907748&view=diff
==============================================================================
--- 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java
 (original)
+++ 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java
 Mon Feb  8 18:29:53 2010
@@ -36,6 +36,7 @@
 import org.apache.jetspeed.om.page.SecurityConstraintsDef;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.portlets.toolbox.ThemeBean;
+import org.apache.jetspeed.security.UserManager;
 import org.apache.jetspeed.spaces.Space;
 import org.apache.jetspeed.spaces.Spaces;
 import org.apache.portals.bridges.common.GenericServletPortlet;
@@ -63,7 +64,8 @@
     private static Logger log = LoggerFactory.getLogger(SpacesManager.class);
     
     protected PageManager pageManager;
-    private PortalAdministration admin;    
+    private PortalAdministration admin;
+    private UserManager userManager;
     
     private Spaces spacesService;
     protected DecorationFactory decorationFactory;    
@@ -71,25 +73,33 @@
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
+        
         PortletContext context = getPortletContext();
+        
         spacesService = (Spaces) 
context.getAttribute(CommonPortletServices.CPS_SPACES_SERVICE);
         if (spacesService == null)
         {
-                throw new PortletException(
-                        "Could not get instance of portal spaces service 
component");
+            throw new PortletException("Could not get instance of portal 
spaces service component");
         }
-        admin = (PortalAdministration) getPortletContext().getAttribute(
-                CommonPortletServices.CPS_PORTAL_ADMINISTRATION);
-        if (null == admin) 
+        
+        admin = (PortalAdministration) 
context.getAttribute(CommonPortletServices.CPS_PORTAL_ADMINISTRATION);
+        if (admin == null) 
         { 
-            throw new PortletException(
-                "Failed to find the Portal Administration on portlet 
initialization"); 
+            throw new PortletException("Failed to find the Portal 
Administration on portlet initialization"); 
         }
+        
         pageManager = 
(PageManager)context.getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT);
-        if (null == pageManager)
+        if (pageManager == null)
         {
             throw new PortletException("Failed to find the Page Manager on 
portlet initialization");
         }
+        
+        userManager = (UserManager) 
context.getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
+        if (null == userManager)
+        {
+            throw new PortletException("Failed to find the user manager on 
portlet initialization");
+        }                
+        
         decorationFactory = 
(DecorationFactory)context.getAttribute(CommonPortletServices.CPS_DECORATION_FACTORY);
         if (null == decorationFactory)
         {
@@ -151,6 +161,7 @@
     public void processAction(ActionRequest actionRequest, ActionResponse 
actionResponse) throws PortletException,
     IOException
     {
+        boolean isCanceled = (actionRequest.getParameter("cancelAction") != 
null);
        String persisted = scrapeParameter(actionRequest, "spacePersisted");
        boolean isNew = (persisted == null || persisted.equals("0") || 
persisted.equalsIgnoreCase("false"));
         String name = scrapeParameter(actionRequest, "spaceName");
@@ -158,74 +169,118 @@
         String description = scrapeParameter(actionRequest, 
"spaceDescription");
         String theme = scrapeParameter(actionRequest, "theme");
         String constraint = scrapeParameter(actionRequest, 
"securityConstraintRef");
-        if (name.length() > 0)
+        
+        if (isCanceled)
         {
             try
             {
-               if (isNew)
-               {
-                       // TODO: better validation
-                       String spaceName = name.replace(' ', '_');              
  
-                    String templateFolderPath = 
actionRequest.getPreferences().getValue(SPACE_TEMPLATE, 
DEFAULT_SPACE_TEMPLATE);               
-                    if (!pageManager.folderExists(templateFolderPath))
-                    {
-                        throw new PortletException("Space template folder does 
not exist: " + templateFolderPath);
-                    }                
-                    Folder templateFolder = 
pageManager.getFolder(templateFolderPath);
-                       String owner = 
actionRequest.getUserPrincipal().getName();
-                       Space space = spacesService.newSpace(spaceName, owner);
-                       space.setTheme(theme);
-                       space.setTitle((title == null) ? name : title);         
       
-                       space.setDescription((description == null) ? "" : 
description);
-                       if (!constraint.equals(""))
-                       {
-                               space.setSecurityConstraint(constraint);
-                       }
-                       space = spacesService.storeSpaceFromTemplate(space, 
templateFolder);                
-                       // redirect
-                       String path = admin.getPortalURL(actionRequest, 
actionResponse, space.getPath());
-                       actionResponse.sendRedirect(path);
-               }
-               else
-               {
-                    String owner = scrapeParameter(actionRequest, 
"spaceOwner");
-                    Space space = spacesService.lookupSpace(name);
-                    if (space != null)
-                    {
-                               space.setDescription(description);
-                               space.setTitle(title);
-                               space.setTheme(theme);
-                               if (constraint.equals(""))
-                               {
-                                       String old = 
space.getSecurityConstraint();
-                                       if (old != null)
-                                       {
-                                               if (!"".equals(old))
-                                                       
space.setSecurityConstraint(constraint);                                        
        
-                                       }
-                                               
-                               }
-                               else
-                               {
-                                       space.setSecurityConstraint(constraint);
-                               }                               
-                               spacesService.storeSpace(space);
-                    }
-                    // redirect
-                    String path = admin.getPortalURL(actionRequest, 
actionResponse, space.getPath());
-                    actionResponse.sendRedirect(path);
-               }
-                PortletMessaging.publish(actionRequest, 
SpacesManager.MSG_TOPIC_SPACE_LIST, SpacesManager.MSG_SPACE_CHANGE, name);      
          
-                PortletMessaging.publish(actionRequest, 
SpacesManager.MSG_TOPIC_SPACE_NAV, SpacesManager.MSG_SPACE_CHANGE, name);
-                PortletMessaging.publish(actionRequest, 
SpacesManager.MSG_TOPIC_PAGE_NAV, SpacesManager.MSG_SPACE_CHANGE, name);
-                
actionRequest.getPortletSession().removeAttribute(SpaceNavigator.ATTRIBUTE_SPACES);
-                
actionRequest.getPortletSession().removeAttribute(SpaceNavigator.ATTRIBUTE_SPACE);
             
+                Space space = (!"".equals(name) ? 
spacesService.lookupSpace(name) : null);
+                String path = admin.getPortalURL(actionRequest, 
actionResponse, (space != null ? space.getPath() : "/"));
+                actionResponse.sendRedirect(path);
+                return;
             }
             catch (Exception e)
             {
-                log.error("Failed to create space.", e);
+                log.error("Failed to retrieve space.", e);
             }
         }
+        
+        if ("".equals(name))
+        {
+            return;
+        }
+        
+        try
+        {
+            if (isNew)
+               {
+                       // TODO: better validation
+                       String spaceName = name.replace(' ', '_');              
  
+                String templateFolderPath = 
actionRequest.getPreferences().getValue(SPACE_TEMPLATE, 
DEFAULT_SPACE_TEMPLATE);               
+                if (!pageManager.folderExists(templateFolderPath))
+                {
+                    throw new PortletException("Space template folder does not 
exist: " + templateFolderPath);
+                }
+                
+                Folder templateFolder = 
pageManager.getFolder(templateFolderPath);
+                String owner = actionRequest.getUserPrincipal().getName();
+                try
+                {
+                    userManager.getUser(owner);
+                }
+                catch (SecurityException notFoundEx)
+                {
+                    throw new PortletException("Space owner is not found: " + 
owner);
+                }
+                
+                Space space = spacesService.newSpace(spaceName, owner);
+                space.setTheme(theme);
+                space.setTitle((title == null) ? name : title);                
+                space.setDescription((description == null) ? "" : description);
+                if (!constraint.equals(""))
+                {
+                       space.setSecurityConstraint(constraint);
+                }
+                space = spacesService.storeSpaceFromTemplate(space, 
templateFolder);                
+                // redirect
+                String path = admin.getPortalURL(actionRequest, 
actionResponse, space.getPath());
+                actionResponse.sendRedirect(path);
+               }
+               else
+               {
+                String owner = scrapeParameter(actionRequest, "spaceOwner");
+                Space space = spacesService.lookupSpace(name);
+                if (space != null)
+                {
+                       space.setDescription(description);
+                       space.setTitle(title);
+                       space.setTheme(theme);
+                       
+                       if (constraint.equals(""))
+                       {
+                               String old = space.getSecurityConstraint();
+                               if (old != null)
+                               {
+                                       if (!"".equals(old))
+                                               
space.setSecurityConstraint(constraint);                                        
        
+                               }
+                                       
+                       }
+                       else
+                       {
+                               space.setSecurityConstraint(constraint);
+                       }
+                       
+                       if (owner != null && !owner.equals(space.getOwner()))
+                       {
+                        try
+                        {
+                            userManager.getUser(owner);
+                        }
+                        catch (SecurityException notFoundEx)
+                        {
+                            throw new PortletException("Space owner is not 
found: " + owner);
+                        }
+                        space.setOwner(owner);
+                       }
+                       
+                       spacesService.storeSpace(space);
+                }
+                // redirect
+                String path = admin.getPortalURL(actionRequest, 
actionResponse, space.getPath());
+                actionResponse.sendRedirect(path);
+               }
+            
+            PortletMessaging.publish(actionRequest, 
SpacesManager.MSG_TOPIC_SPACE_LIST, SpacesManager.MSG_SPACE_CHANGE, name);      
          
+            PortletMessaging.publish(actionRequest, 
SpacesManager.MSG_TOPIC_SPACE_NAV, SpacesManager.MSG_SPACE_CHANGE, name);
+            PortletMessaging.publish(actionRequest, 
SpacesManager.MSG_TOPIC_PAGE_NAV, SpacesManager.MSG_SPACE_CHANGE, name);
+            
actionRequest.getPortletSession().removeAttribute(SpaceNavigator.ATTRIBUTE_SPACES);
+            
actionRequest.getPortletSession().removeAttribute(SpaceNavigator.ATTRIBUTE_SPACE);
                 
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to save space.", e);
+        }
     }        
     
     private String scrapeParameter(ActionRequest request, String paramName)

Modified: 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/spaces/resources/SpacesResources.properties
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/spaces/resources/SpacesResources.properties?rev=907748&r1=907747&r2=907748&view=diff
==============================================================================
--- 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/spaces/resources/SpacesResources.properties
 (original)
+++ 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/resources/org/apache/jetspeed/portlets/spaces/resources/SpacesResources.properties
 Mon Feb  8 18:29:53 2010
@@ -29,7 +29,8 @@
 spaces.label.delete = Delete
 spaces.label.add = Add Space
 spaces.label.edit.current = Edit Current Space
-spaces.label.update = Update Space
+spaces.label.save = Save
+spaces.label.cancel = Cancel
 
 spaces.pages.label.add = Add Page
 spaces.pages.label.space.title = {0} Space

Modified: 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp?rev=907748&r1=907747&r2=907748&view=diff
==============================================================================
--- 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp
 (original)
+++ 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp
 Mon Feb  8 18:29:53 2010
@@ -33,73 +33,69 @@
   <c:set var="portalContextPath" value="/"/>
 </c:if>
 
-<form id='jsSpacesManagement' method="POST" action='<portlet:actionURL/>'>
-<input type='hidden' name='spacePersisted' value='${space.persisted}'/>
-<table width="100%">
-       <tr>
-       <td>
-       <table>
+<form method="POST" action='<portlet:actionURL/>'>
+  <input type='hidden' name='spacePersisted' value='${space.persisted}'/>
+  <table width="100%">
     <tr>
-       <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.name"/></td>
-       <td class="portlet-section-subheader"><input type="text" <c:if 
test="${space.persisted}">readonly</c:if> name="spaceName" size="30" 
value="${space.name}" /></td>
-       </tr>
-    <c:if test="${space.persisted}">
-      <tr>
-           <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.owner"/></td>
-           <td class="portlet-section-subheader"><input type="text" readonly 
name="spaceOwner" size="30" value="${space.owner}" /></td>
-         </tr>
-    </c:if>
-    <tr>
-       <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.title"/></td>
-       <td class="portlet-section-subheader"><input type="text" 
name="spaceTitle" size="30" value="${space.title}" /></td>
-       </tr>
-    <tr>
-       <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.description"/></td>
-       <td class="portlet-section-subheader"><input type="text" 
name="spaceDescription" size="30" value="${space.description}" /></td>
-       </tr>
-       <tr>
-       <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.security"/></td>
-       <td class="portlet-section-subheader">
-      <select name="securityConstraintRef">
-        <c:forEach items="${constraints}" var="constraint">
-          <option value="${constraint}" <c:if test="${space.securityConstraint 
== constraint}"> selected </c:if>>${constraint}</option>
-        </c:forEach>                 
-      </select>
-    </td>
-       </tr>
+      <td>
+        <table>
+          <tr>
+            <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.name"/></td>
+            <td class="portlet-section-subheader"><input type="text" <c:if 
test="${space.persisted}">readonly</c:if> name="spaceName" size="30" 
value="${space.name}" /></td>
+          </tr>
+          <c:if test="${space.persisted}">
+            <tr>
+              <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.owner"/></td>
+              <td class="portlet-section-subheader"><input type="text" 
name="spaceOwner" size="30" value="${space.owner}" /></td>
+            </tr>
+          </c:if>
+          <tr>
+            <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.title"/></td>
+            <td class="portlet-section-subheader"><input type="text" 
name="spaceTitle" size="30" value="${space.title}" /></td>
+          </tr>
+          <tr>
+            <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.description"/></td>
+            <td class="portlet-section-subheader">
+              <textarea name="spaceDescription" rows="4" 
cols="60">${space.description}</textarea>
+            </td>
+          </tr>
+          <tr>
+            <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.security"/></td>
+            <td class="portlet-section-subheader">
+              <select name="securityConstraintRef">
+                <c:forEach items="${constraints}" var="constraint">
+                  <option value="${constraint}" <c:if 
test="${space.securityConstraint == constraint}"> selected 
</c:if>>${constraint}</option>
+                </c:forEach>
+              </select>
+            </td>
+          </tr>
+          <tr>
+            <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.theme"/></td>
+            <td class="portlet-section-subheader"></td>
+          </tr>
+          <tr>
+            <td colspan='2'>
+              <table>
+                <c:forEach var="theme" items="${themes}">
+                  <tr>
+                    <td><img src='<c:url context="${portalContextPath}" 
value="/decorations/layout/${theme.name}/${theme.image}"/>'></td>
+                    <td style="vertical-align: middle"><input type="radio" 
<c:if test="${theme.selected}"> checked </c:if> name="theme" 
value="${theme.name}" /> ${theme.title}</td>
+                  </tr>
+                </c:forEach>
+              </table>
+            </td>
+          </tr>
+        </table>
+      </td>
+    </tr>
     <tr>
-       <td class="portlet-section-subheader"><fmt:message 
key="spaces.label.theme"/></td>
-       <td class="portlet-section-subheader"></td>
-       </tr>
-       <tr>
-       <td colspan='2'>        
-               <table>
-                   <c:forEach var="theme" items="${themes}">   
-                       <tr>
-                        <td><img src='<c:url context="${portalContextPath}" 
value="/decorations/layout/${theme.name}/${theme.image}"/>'></td>               
    
-                                <td style="vertical-align: middle"><input 
type="radio" <c:if test="${theme.selected}"> checked </c:if> name="theme" 
value="${theme.name}" /> ${theme.title}</td>
-                       </tr>
-                       </c:forEach>
-               </table>
-   </td>
-       </tr>
-       </table>
-       </td>
-       </tr>
-       <tr>
       <td colspan='2' style="text-align: center" 
class="portlet-section-subheader">
-        <c:choose>
-          <c:when test="${space.persisted}">
-            <input type="submit" value="<fmt:message 
key='spaces.label.update'/>" />
-          </c:when>
-          <c:otherwise>
-            <input type="submit" value="<fmt:message key='spaces.label.add'/>" 
/>
-          </c:otherwise>
-        </c:choose>
+        <input type="submit" name="saveAction" value="<fmt:message 
key='spaces.label.save'/>" />
+        <input type="submit" name="cancelAction" value="<fmt:message 
key='spaces.label.cancel'/>" />
       </td>
-       </tr>
-       <tr>
-               <th class="portlet-section-header" colspan="2"></th>
-       </tr>
-</table>
+    </tr>
+    <tr>
+      <th class="portlet-section-header" colspan="2"></th>
+    </tr>
+  </table>
 </form>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to