Author: woonsan Date: Tue Dec 8 17:10:54 2009 New Revision: 888487 URL: http://svn.apache.org/viewvc?rev=888487&view=rev Log: JS2-1087: Initial addition of page management service bean. It's a simple replacement of GetPageAction. TODO: Add another service for layout component.
Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java (with props) portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java (with props) portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java (with props) Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java?rev=888487&view=auto ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java (added) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java Tue Dec 8 17:10:54 2009 @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.services.beans; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.jetspeed.om.page.ContentFragment; + +/** + * ContentFragmentBean + * + * @version $Id$ + */ +...@xmlrootelement(name="fragment") +public class ContentFragmentBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + private String id; + private String type; + private String name; + private String decorator; + private String mode; + private String state; + private Map<String, String> properties; + private Collection<ContentFragmentBean> contentFragmentBeans; + + + public ContentFragmentBean() + { + + } + + public ContentFragmentBean(final ContentFragment contentFragment) + { + id = contentFragment.getId(); + type = contentFragment.getType(); + name = contentFragment.getName(); + decorator = contentFragment.getDecorator(); + + mode = contentFragment.getMode(); + state = contentFragment.getState(); + properties = contentFragment.getProperties(); + + Collection<ContentFragment> childContentFragments = contentFragment.getFragments(); + + if (childContentFragments != null && !childContentFragments.isEmpty()) + { + ArrayList<ContentFragmentBean> childContentFragmentBeanList = new ArrayList<ContentFragmentBean>(); + + for (ContentFragment childContentFragment : childContentFragments) + { + childContentFragmentBeanList.add(new ContentFragmentBean(childContentFragment)); + } + + contentFragmentBeans = childContentFragmentBeanList; + } + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getType() + { + return type; + } + + public void setType(String type) + { + this.type = type; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getDecorator() + { + return decorator; + } + + public void setDecorator(String decorator) + { + this.decorator = decorator; + } + + public String getMode() + { + return mode; + } + + public void setMode(String mode) + { + this.mode = mode; + } + + public String getState() + { + return state; + } + + public void setState(String state) + { + this.state = state; + } + + public Map<String, String> getProperties() + { + return properties; + } + + public void setProperties(Map<String, String> properties) + { + this.properties = properties; + } + + @XmlElementWrapper(name="fragments") + @XmlElements(@XmlElement(name="fragment")) + public Collection<ContentFragmentBean> getContentFragmentBeans() + { + return contentFragmentBeans; + } + + public void setContentFragmentBeans(Collection<ContentFragmentBean> contentFragmentBeans) + { + this.contentFragmentBeans = contentFragmentBeans; + } + +} Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java?rev=888487&view=auto ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java (added) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java Tue Dec 8 17:10:54 2009 @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.services.beans; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.jetspeed.om.page.ContentFragment; +import org.apache.jetspeed.om.page.ContentPage; + +/** + * ContentPageBean + * + * @version $Id$ + */ +...@xmlrootelement(name="page") +public class ContentPageBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + private String id; + private String name; + private String path; + private String title; + private String shortTitle; + private String url; + private String skin; + private ContentFragmentBean rootFragmentBean; + + public ContentPageBean() + { + + } + + public ContentPageBean(final ContentPage contentPage) + { + id = contentPage.getId(); + name = contentPage.getName(); + path = contentPage.getPath(); + title = contentPage.getTitle(); + shortTitle = contentPage.getShortTitle(); + url = contentPage.getUrl(); + skin = contentPage.getSkin(); + + ContentFragment rootFragment = contentPage.getRootFragment(); + + if (rootFragment != null) + { + rootFragmentBean = new ContentFragmentBean(rootFragment); + } + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getPath() + { + return path; + } + + public void setPath(String path) + { + this.path = path; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getShortTitle() + { + return shortTitle; + } + + public void setShortTitle(String shortTitle) + { + this.shortTitle = shortTitle; + } + + public String getUrl() + { + return url; + } + + public void setUrl(String url) + { + this.url = url; + } + + public String getSkin() + { + return skin; + } + + public void setSkin(String skin) + { + this.skin = skin; + } + + @XmlElement(name="fragment") + public ContentFragmentBean getContentFragmentBean() + { + return rootFragmentBean; + } + + public void setContentFragmentBean(ContentFragmentBean rootFragmentBean) + { + this.rootFragmentBean = rootFragmentBean; + } + +} Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentPageBean.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=888487&view=auto ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java (added) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java Tue Dec 8 17:10:54 2009 @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.services.rest; + +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.UriInfo; + +import org.apache.jetspeed.JetspeedActions; +import org.apache.jetspeed.components.portletregistry.PortletRegistry; +import org.apache.jetspeed.decoration.DecorationValve; +import org.apache.jetspeed.layout.PortletActionSecurityBehavior; +import org.apache.jetspeed.om.page.ContentPage; +import org.apache.jetspeed.page.PageManager; +import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.services.beans.ContentPageBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * PageManagementService + * + * @version $Id$ + */ + +...@path("/") +public class PageManagementService +{ + + private static Logger log = LoggerFactory.getLogger(PageManagementService.class); + + @Context + private ServletConfig servletConfig; + + @Context + private ServletContext servletContext; + + private PageManager pageManager; + + private PortletActionSecurityBehavior securityBehavior; + + private PortletRegistry portletRegistry; + + private DecorationValve decorationValve; + + public PageManagementService(PageManager pageManager, + PortletActionSecurityBehavior securityBehavior, + PortletRegistry portletRegistry, + DecorationValve decorationValve) + { + this.pageManager = pageManager; + this.securityBehavior = securityBehavior; + this.portletRegistry = portletRegistry; + this.decorationValve = decorationValve; + } + + @GET + @Path("/{path:.*}") + public ContentPageBean getContentPage(@Context HttpServletRequest servletRequest, + @Context UriInfo uriInfo, + @PathParam("path") List<PathSegment> pathSegments) + { + RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV); + + try + { + checkPageAccess(requestContext, JetspeedActions.VIEW); + } + catch (SecurityException e) + { + throw new WebApplicationException(e); + } + + try + { + // Run the Decoration valve to get actions + decorationValve.invoke(requestContext, null); + + ContentPage contentPage = requestContext.getPage(); + + return new ContentPageBean(contentPage); + } + catch (Exception e) + { + throw new WebApplicationException(e); + } + } + + private void checkPageAccess(RequestContext requestContext, String action) throws SecurityException + { + if (securityBehavior != null) + { + if (!securityBehavior.checkAccess(requestContext, action)) + { + throw new SecurityException("Insufficient access to view page"); + } + } + } + +} Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageManagementService.java ------------------------------------------------------------------------------ svn:mime-type = text/plain 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=888487&r1=888486&r2=888487&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 17:10:54 2009 @@ -127,6 +127,7 @@ <!-- Resource providers --> <ref bean="jaxrsPortletRegistryService" /> + <ref bean="jaxrsPageManagementService" /> </set> </property> @@ -140,4 +141,13 @@ <constructor-arg ref="org.apache.jetspeed.search.SearchEngine" /> </bean> + <!-- Portal Page Management JAX-RS Service --> + <bean id="jaxrsPageManagementService" class="org.apache.jetspeed.services.rest.PageManagementService"> + <meta key="j2:cat" value="default" /> + <constructor-arg ref="org.apache.jetspeed.page.PageManager" /> + <constructor-arg ref="PortletActionSecurityBehavior" /> + <constructor-arg ref="org.apache.jetspeed.components.portletregistry.PortletRegistry" /> + <constructor-arg ref="DecorationValve" /> + </bean> + </beans> --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscr...@portals.apache.org For additional commands, e-mail: jetspeed-dev-h...@portals.apache.org