portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r888521 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
Date Tue, 08 Dec 2009 19:02:37 GMT
Author: woonsan
Date: Tue Dec  8 19:02:36 2009
New Revision: 888521

URL: http://svn.apache.org/viewvc?rev=888521&view=rev
Log:
JS2-1087: Adding jax-rs operations for addPortlet and removePortlet.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java?rev=888521&r1=888520&r2=888521&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java
Tue Dec  8 19:02:36 2009
@@ -21,17 +21,24 @@
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.decoration.DecorationValve;
+import org.apache.jetspeed.layout.PageLayoutComponent;
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.page.PageManager;
@@ -66,42 +73,81 @@
     
     private DecorationValve decorationValve;
     
+    private PageLayoutComponent pageLayoutComponent;
+    
     public PageManagementService(PageManager pageManager,
                                        PortletActionSecurityBehavior securityBehavior,
                                        PortletRegistry portletRegistry,
-                                       DecorationValve decorationValve)
+                                       DecorationValve decorationValve,
+                                       PageLayoutComponent pageLayoutComponent)
     {
         this.pageManager = pageManager;
         this.securityBehavior = securityBehavior;
         this.portletRegistry = portletRegistry;
         this.decorationValve = decorationValve;
+        this.pageLayoutComponent = pageLayoutComponent;
     }
     
     @GET
     @Path("/{path:.*}")
     public ContentPageBean getContentPage(@Context HttpServletRequest servletRequest,
-                                      @Context UriInfo uriInfo,
-                                      @PathParam("path") List<PathSegment> pathSegments)
+                                          @Context UriInfo uriInfo,
+                                          @PathParam("path") List<PathSegment> pathSegments)
     {
         RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV);
-        
-        try
+        ContentPage contentPage = getContentPage(requestContext);
+        return new ContentPageBean(contentPage);
+    }
+    
+    @POST
+    @Path("/{path:.*}")
+    public Response addContentFragment(@Context HttpServletRequest servletRequest,
+                                       @Context UriInfo uriInfo,
+                                       @PathParam("path") List<PathSegment> pathSegments,
+                                       @FormParam("type") String fragmentType,
+                                       @FormParam("name") String fragmentName)
+    {
+        if (StringUtils.isBlank(fragmentType) || StringUtils.isBlank(fragmentName))
         {
-            checkPageAccess(requestContext, JetspeedActions.VIEW);
+            throw new WebApplicationException(new IllegalArgumentException("Fragment type
and name not specified"));
         }
-        catch (SecurityException e)
+        
+        RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV);
+        ContentPage contentPage = getContentPage(requestContext);
+        
+        pageLayoutComponent.addPortlet(contentPage, fragmentType, fragmentName);
+        
+        return Response.ok().build();
+    }
+    
+    @DELETE
+    @Path("/{path:.*}")
+    public Response deleteContentFragment(@Context HttpServletRequest servletRequest,
+                                       @Context UriInfo uriInfo,
+                                       @PathParam("path") List<PathSegment> pathSegments,
+                                       @QueryParam("id") String fragmentId)
+    {
+        if (StringUtils.isBlank(fragmentId))
         {
-            throw new WebApplicationException(e);
+            throw new WebApplicationException(new IllegalArgumentException("Fragment id not
specified"));
         }
         
+        RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV);
+        ContentPage contentPage = getContentPage(requestContext);
+        
+        pageLayoutComponent.removeFragment(contentPage, fragmentId);
+        
+        return Response.ok().build();
+    }
+    
+    private ContentPage getContentPage(RequestContext requestContext) throws WebApplicationException
+    {
         try
         {
+            checkPageAccess(requestContext, JetspeedActions.VIEW);
             // Run the Decoration valve to get actions
             decorationValve.invoke(requestContext, null);
-            
-            ContentPage contentPage = requestContext.getPage();
-            
-            return new ContentPageBean(contentPage);
+            return requestContext.getPage();
         }
         catch (Exception e)
         {

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml?rev=888521&r1=888520&r2=888521&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
Tue Dec  8 19:02:36 2009
@@ -148,6 +148,7 @@
     <constructor-arg ref="PortletActionSecurityBehavior" />
     <constructor-arg ref="org.apache.jetspeed.components.portletregistry.PortletRegistry"
/>
     <constructor-arg ref="DecorationValve" />
+    <constructor-arg ref="org.apache.jetspeed.layout.PageLayoutComponent" />
   </bean>
   
 </beans>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message