Author: woonsan Date: Tue Dec 15 15:22:01 2009 New Revision: 890823 URL: http://svn.apache.org/viewvc?rev=890823&view=rev Log: JS2-1084: Adding decorator actions during portlet addition. Also, allows PortalURLValveImpl to retrieve portal servlet path as well as portal path info by delimiting by ':' if provided. (When ajax client invokes rest api to retrieve decorator action links, the portal needs to know the servlet path.) If the portal path provided by the ajax client does not contain ':', then it is regarded as a portal page path simply.
Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java (with props) portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java (with props) Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp?rev=890823&r1=890822&r2=890823&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp (original) +++ portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp Tue Dec 15 15:22:01 2009 @@ -236,7 +236,9 @@ <div class="portlet <%=pageDec%>"> <div class="PTitle"> <div class="PTitleContent">Loading...</div> - <div class="PActionBar"></div> + <div class="PActionBar"> + <span style='cursor: pointer; z-index: 1000;' id='jetspeed-close-XXX' title="close" class="portlet-action-close"><img src="<%=request.getContextPath()%>/decorations/portlet/jetspeed/images/close.gif" alt="Close" border="0" /></span> + </div> </div> <div class="PContentBorder"> <div class="PContent"></div> Modified: portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js?rev=890823&r1=890822&r2=890823&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js (original) +++ portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js Tue Dec 15 15:22:01 2009 @@ -274,13 +274,60 @@ var config = { on: { complete: portal.onPortletRemoveComplete }, method: "DELETE", - headers: { "X-Portal-Path" : portal.portalPagePath }, + headers: { "X-Portal-Path" : portal.portalServletPath + ":" + portal.portalPagePath }, arguments: { complete: [ windowId ] } }; var request = Y.io(uri, config); }, /** + * @method onPortletDecorationReadComplete + */ + onPortletDecorationReadComplete : function(id, o, args) { + if (!JETUI_YUI || !JETUI_YUI.portalInstance) + return; + var portal = JETUI_YUI.portalInstance; + var windowId = args.complete[0]; + var actionBarElem = args.complete[1]; + var existingActionElem = null; + var childElems = actionBarElem.getElementsByTagName("*"); + if (childElems.size() > 0) { + existingActionElem = childElems.item(0); + } + var result = null; + + try { + result = Y.JSON.parse(o.responseText); + if (!result) { + Y.log("Error: no data found."); + return; + } + } catch (e) { + Y.log("Error: " + e.message); + return; + } + + var decoActions = result.decoratorActions; + for (var i = 0; i < decoActions.length; i++) { + var link = Y.Node.create("<a class='action portlet-action'/>"); + var icon = Y.Node.create("<img border='0'/>"); + link.setAttribute("href", decoActions[i].action); + if (link.target) { + link.setAttribute("target", decoActions[i].target); + } + link.setAttribute("title", decoActions[i].name); + icon.setAttribute("src", portal.portalContextPath + "/" + decoActions[i].link); + icon.setAttribute("alt", decoActions[i].alt); + link.appendChild(icon); + if (existingActionElem) { + actionBarElem.insertBefore(link, existingActionElem); + } else { + actionBarElem.appendChild(link); + } + } + }, + + /** * @method onPortletRenderComplete */ onPortletRenderComplete : function(id, o, args) { @@ -291,12 +338,15 @@ var v = args.complete; var windowId = v.get("id"); var titleElem = null; + var actionBarElem = null; var closeElem = null; var contentElem = null; var children = v.getElementsByTagName("*"); children.each(function(v, k) { if (v.hasClass("PTitleContent")) { titleElem = v; + } else if (v.hasClass("PActionBar")) { + actionBarElem = v; } else if (v.hasClass("PContent")) { contentElem = v; } else if (/^jetspeed-close/.test("" + v.get("id"))) { @@ -315,6 +365,16 @@ if (contentElem) { contentElem.setContent(portletContent); } + + if (actionBarElem) { + var uri = portal.portalContextPath + "/services/pagelayout/decoration/fragment/" + windowId + "/?_type=json"; + var config = { + on: { complete: portal.onPortletDecorationReadComplete }, + headers: { "X-Portal-Path" : portal.portalServletPath + ":" + portal.portalPagePath }, + arguments: { complete: [ windowId, actionBarElem ] } + }; + var request = Y.io(uri, config); + } }, /** Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java?rev=890823&r1=890822&r2=890823&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/url/impl/PortalURLValveImpl.java Tue Dec 15 15:22:01 2009 @@ -116,16 +116,16 @@ if (param != null) { - final String pathInfoParam = param; + int offset = param.indexOf(':'); - servletRequest = new HttpServletRequestWrapper(servletRequest) + if (offset == -1) { - @Override - public String getPathInfo() - { - return pathInfoParam; - } - }; + servletRequest = new PortalPathAdjustedHttpServletRequestWrapper(servletRequest, null, param); + } + else + { + servletRequest = new PortalPathAdjustedHttpServletRequestWrapper(servletRequest, param.substring(0, offset), param.substring(offset + 1)); + } } } @@ -136,4 +136,30 @@ { return "PortalURLValveImpl"; } + + private static class PortalPathAdjustedHttpServletRequestWrapper extends HttpServletRequestWrapper + { + private String servletPath; + private String pathInfo; + + private PortalPathAdjustedHttpServletRequestWrapper(HttpServletRequest request, String servletPath, String pathInfo) + { + super(request); + + this.servletPath = servletPath; + this.pathInfo = pathInfo; + } + + @Override + public String getServletPath() + { + return (servletPath != null ? servletPath : super.getServletPath()); + } + + @Override + public String getPathInfo() + { + return (pathInfo != null ? pathInfo : super.getPathInfo()); + } + } } Modified: 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=890823&r1=890822&r2=890823&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ContentFragmentBean.java Tue Dec 15 15:22:01 2009 @@ -42,6 +42,7 @@ private String id; private String type; private String name; + private boolean locked; private String decorator; private String mode; private String state; @@ -59,6 +60,7 @@ id = contentFragment.getId(); type = contentFragment.getType(); name = contentFragment.getName(); + locked = contentFragment.isLocked(); decorator = contentFragment.getDecorator(); mode = contentFragment.getMode(); @@ -109,7 +111,17 @@ { this.name = name; } - + + public boolean isLocked() + { + return locked; + } + + public void setLocked(boolean locked) + { + this.locked = locked; + } + public String getDecorator() { return decorator; Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java?rev=890823&view=auto ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java (added) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java Tue Dec 15 15:22:01 2009 @@ -0,0 +1,131 @@ +/* + * 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.List; + +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.decoration.Decoration; +import org.apache.jetspeed.decoration.DecoratorAction; + +/** + * DecorationBean + * + * @version $Id$ + */ +...@xmlrootelement(name="decoration") +public class DecorationBean implements Serializable +{ + private static final long serialVersionUID = 1L; + + private String name; + private String styleSheet; + private String basePath; + private String baseCSSClass; + private Decoration.ActionsOption actionsOption; + private Collection<DecoratorActionBean> actionBeans; + + public DecorationBean() + { + + } + + public DecorationBean(final Decoration decoration) + { + name = decoration.getName(); + styleSheet = decoration.getStyleSheet(); + basePath = decoration.getBasePath(); + baseCSSClass = decoration.getBaseCSSClass(); + actionsOption = decoration.getActionsOption(); + actionBeans = new ArrayList<DecoratorActionBean>(); + + for (DecoratorAction action : (List<DecoratorAction>) decoration.getActions()) + { + actionBeans.add(new DecoratorActionBean(action)); + } + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getStyleSheet() + { + return styleSheet; + } + + public void setStyleSheet(String styleSheet) + { + this.styleSheet = styleSheet; + } + + public String getBasePath() + { + return basePath; + } + + public void setBasePath(String basePath) + { + this.basePath = basePath; + } + + public String getBaseCSSClass() + { + return baseCSSClass; + } + + public void setBaseCSSClass(String baseCSSClass) + { + this.baseCSSClass = baseCSSClass; + } + + public String getActionsOption() + { + return actionsOption.toString(); + } + + public void setActionsOption(String actionsOption) + { + this.actionsOption = Decoration.ActionsOption.valueOf(actionsOption); + } + + @XmlElementWrapper(name="decoratorActions") + @XmlElements(@XmlElement(name="decoratorAction")) + public Collection<DecoratorActionBean> getActionBeans() + { + return actionBeans; + } + + public void setActionBeans(Collection<DecoratorActionBean> actionBeans) + { + this.actionBeans = actionBeans; + } + +} Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecorationBean.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java?rev=890823&view=auto ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java (added) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java Tue Dec 15 15:22:01 2009 @@ -0,0 +1,129 @@ +/* + * 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.XmlRootElement; + +import org.apache.jetspeed.decoration.DecoratorAction; + +/** + * DecoratorActionBean + * + * @version $Id$ + */ +...@xmlrootelement(name="decoratorAction") +public class DecoratorActionBean implements Serializable +{ + private static final long serialVersionUID = 1L; + + private String action; + private String actionName; + private String actionType; + private String alt; + private String link; + private String name; + private String target; + + public DecoratorActionBean() + { + + } + + public DecoratorActionBean(final DecoratorAction decoratorAction) + { + action = decoratorAction.getAction(); + actionName = decoratorAction.getActionName(); + actionType = decoratorAction.getActionType(); + alt = decoratorAction.getAlt(); + link = decoratorAction.getLink(); + name = decoratorAction.getName(); + target = decoratorAction.getTarget(); + } + + public String getAction() + { + return action; + } + + public void setAction(String action) + { + this.action = action; + } + + public String getActionName() + { + return actionName; + } + + public void setActionName(String actionName) + { + this.actionName = actionName; + } + + public String getActionType() + { + return actionType; + } + + public void setActionType(String actionType) + { + this.actionType = actionType; + } + + public String getAlt() + { + return alt; + } + + public void setAlt(String alt) + { + this.alt = alt; + } + + public String getLink() + { + return link; + } + + public void setLink(String link) + { + this.link = link; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getTarget() + { + return target; + } + + public void setTarget(String target) + { + this.target = target; + } + +} Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/DecoratorActionBean.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java?rev=890823&r1=890822&r2=890823&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java Tue Dec 15 15:22:01 2009 @@ -39,6 +39,7 @@ import org.apache.commons.lang.math.NumberUtils; import org.apache.jetspeed.JetspeedActions; import org.apache.jetspeed.components.portletregistry.PortletRegistry; +import org.apache.jetspeed.decoration.Decoration; import org.apache.jetspeed.layout.PageLayoutComponent; import org.apache.jetspeed.layout.PortletActionSecurityBehavior; import org.apache.jetspeed.om.page.ContentFragment; @@ -48,6 +49,7 @@ import org.apache.jetspeed.request.RequestContext; import org.apache.jetspeed.services.beans.ContentFragmentBean; import org.apache.jetspeed.services.beans.ContentPageBean; +import org.apache.jetspeed.services.beans.DecorationBean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,6 +97,29 @@ return new ContentPageBean(contentPage); } + @GET + @Path("/fragment/{id}/") + public ContentFragmentBean getContentFragment(@Context HttpServletRequest servletRequest, + @Context UriInfo uriInfo, + @PathParam("id") String fragmentId) + { + if (StringUtils.isBlank(fragmentId)) + { + throw new WebApplicationException(new IllegalArgumentException("Fragment id not specified")); + } + + RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV); + ContentPage contentPage = getContentPage(requestContext, JetspeedActions.EDIT); + ContentFragment contentFragment = contentPage.getFragmentById(fragmentId); + + if (contentFragment == null) + { + throw new WebApplicationException(new IllegalArgumentException("Fragment not found with the specified id: " + fragmentId)); + } + + return new ContentFragmentBean(contentFragment); + } + @POST @Path("/fragment/{type}/{name}/") public ContentFragmentBean addContentFragment(@Context HttpServletRequest servletRequest, @@ -133,8 +158,8 @@ @DELETE @Path("/fragment/{id}/") public ContentFragmentBean deleteContentFragment(@Context HttpServletRequest servletRequest, - @Context UriInfo uriInfo, - @PathParam("id") String fragmentId) + @Context UriInfo uriInfo, + @PathParam("id") String fragmentId) { if (StringUtils.isBlank(fragmentId)) { @@ -351,6 +376,36 @@ return new ContentFragmentBean(contentFragment); } + + @GET + @Path("/decoration/fragment/{id}/") + public DecorationBean getDecorationOfContentFragment(@Context HttpServletRequest servletRequest, + @Context UriInfo uriInfo, + @PathParam("id") String fragmentId) + { + if (StringUtils.isBlank(fragmentId)) + { + throw new WebApplicationException(new IllegalArgumentException("Fragment id not specified")); + } + + RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV); + ContentPage contentPage = getContentPage(requestContext, JetspeedActions.EDIT); + ContentFragment contentFragment = contentPage.getFragmentById(fragmentId); + + if (contentFragment == null) + { + throw new WebApplicationException(new IllegalArgumentException("Fragment not found with the specified id: " + fragmentId)); + } + + Decoration decoration = contentFragment.getDecoration(); + + if (decoration == null) + { + throw new WebApplicationException(new IllegalArgumentException("Decoration not found with the specified id: " + fragmentId)); + } + + return new DecorationBean(decoration); + } private ContentPage getContentPage(RequestContext requestContext, String action) throws WebApplicationException { --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscr...@portals.apache.org For additional commands, e-mail: jetspeed-dev-h...@portals.apache.org