taylor 2004/05/18 12:51:39 Modified: portal/src/webapp/WEB-INF portlet.xml portal/src/java/org/apache/jetspeed/portlets/layout LayoutPortlet.java portal maven.xml Added: portal/src/java/org/apache/jetspeed/portlets/layout MultiColumnPortlet.java Removed: portal/src/java/org/apache/jetspeed/portlets/decorator GenericDecoratorPortlet.java DecoratorPortlet.java portal/src/java/org/apache/jetspeed/layout LayoutPortlet.java MultiColumnPortlet.java portal/src/webapp/WEB-INF/layout portletstd-top.jsp columns.jsp clear-bottom.jsp clear-top.jsp portletstd-bottom.jsp portal/src/java/org/apache/jetspeed/portlets/layout GenericLayoutPortlet.java Log: moving all portlets under portlets tree
dropping dead-end implementations of aggregation, layout PR: Obtained from: Submitted by: Reviewed by: CVS: ---------------------------------------------------------------------- CVS: PR: CVS: If this change addresses a PR in the problem report tracking CVS: database, then enter the PR number(s) here. CVS: Obtained from: CVS: If this change has been taken from another system, such as NCSA, CVS: then name the system in this line, otherwise delete it. CVS: Submitted by: CVS: If this code has been contributed to Apache by someone else; i.e., CVS: they sent us a patch or a new module, then include their name/email CVS: address here. If this is your work then delete this line. CVS: Reviewed by: CVS: If we are doing pre-commit code reviews and someone else has CVS: reviewed your changes, include their name(s) here. CVS: If you have not had it reviewed then delete this line. Revision Changes Path 1.9 +1 -1 jakarta-jetspeed-2/portal/src/webapp/WEB-INF/portlet.xml Index: portlet.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/portlet.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- portlet.xml 8 May 2004 01:20:31 -0000 1.8 +++ portlet.xml 18 May 2004 19:51:39 -0000 1.9 @@ -1 +1 @@ -<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright 2004 The Apache Software Foundation Licensed 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. --> <portlet-app id="jetspeed" version="1.0"> <portlet id="TwoColumns"> <portlet-name>TwoColumns</portlet-name> <display-name>Two Columns Layout</display-name> <init-param> <name>ViewPage</name> <value>/WEB-INF/layout/columns.jsp</value> </init-param> <init-param> <name>columns</name> <value>2</value> </init-param> <init-param> <name>sizes</name> <value>50%,50%</value> </init-param> <portlet-class>org.apache.jetspeed.layout.MultiColumnPortlet</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> </supports> <portlet-info> <title>TwoColumns</title> <short-title>TwoColumns</short-title> </portlet-info> </portlet> <portlet id="VelocityTwoColumns"> <portlet-name>VelocityTwoColumns</portlet-name> <display-name>Two Columns Layout Using Velocity</display-name> <init-param> <name>ViewPage</name> <value>columns</value> </init-param> <init-param> <name>MaxPage</name> <value>maximized</value> </init-param> <init-param> <name>columns</name> <value>2</value> </init-param> <init-param> <name>sizes</name> <value>50%,50%</value> </init-param> <portlet-class>org.apache.jetspeed.layout.MultiColumnPortlet</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> </supports> <portlet-info> <title>VelocityTwoColumns</title> <short-title>TwoColumns</short-title> </portlet-info> </portlet> <portlet id="PortletApplicationBrowser"> <init-param> <description>This parameter sets the template used in view mode.</description> <name>ViewPage</name> <value>/pages/pam/pam-browser.jsp</value> </init-param> <portlet-name>PortletApplicationBrowser</portlet-name> <display-name>Portlet Application Browser</display-name> <description>The PAM (Portlet Application Manager) Portlet Application Browser displays a list of portlet applications deployed to this portal. From here you can add, edit, and delete portlet applications.</description> <portlet-class>org.apache.jetspeed.portlets.pam.PortletApplicationBrowser</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>EDIT</portlet-mode> <portlet-mode>VIEW</portlet-mode> <portlet-mode>HELP</portlet-mode> </supports> <portlet-info> <title>Portlet Application Browser</title> <short-title>Apps</short-title> <keywords>applications,apps,PAM</keywords> </portlet-info> </portlet> <portlet id="PortletApplicationDetail"> <init-param> <description>This parameter sets the template used in view mode.</description> <name>ViewPage</name> <value>/pages/pam/pam-detail.jsp</value> </init-param> <portlet-name>PortletApplicationDetail</portlet-name> <display-name>Portlet Application Detail</display-name> <description>The PAM (Portlet Application Manager) Portlet Application Detail displays a specific portlet application deployed to this portal. From here you can add, edit, and delete this portlet application.</description> <portlet-class>org.apache.jetspeed.portlets.pam.PortletApplicationDetail</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>EDIT</portlet-mode> <portlet-mode>VIEW</portlet-mode> <portlet-mode>HELP</portlet-mode> </supports> <portlet-info> <title>Portlet Application Detail</title> <short-title>PAD</short-title> <keywords>applications,apps,PAM,PAD</keywords> </portlet-info> </portlet> </portlet-app> \ No newline at end of file +<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright 2004 The Apache Software Foundation Licensed 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. --> <portlet-app id="jetspeed" version="1.0"> <portlet id="TwoColumns"> <portlet-name>TwoColumns</portlet-name> <display-name>Two Columns Layout</display-name> <init-param> <name>ViewPage</name> <value>/WEB-INF/layout/columns.jsp</value> </init-param> <init-param> <name>columns</name> <value>2</value> </init-param> <init-param> <name>sizes</name> <value>50%,50%</value> </init-param> <portlet-class>org.apache.jetspeed.portlets.layout.MultiColumnPortlet</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> </supports> <portlet-info> <title>TwoColumns</title> <short-title>TwoColumns</short-title> </portlet-info> </portlet> <portlet id="VelocityTwoColumns"> <portlet-name>VelocityTwoColumns</portlet-name> <display-name>Two Columns Layout Using Velocity</display-name> <init-param> <name>ViewPage</name> <value>columns</value> </init-param> <init-param> <name>MaxPage</name> <value>maximized</value> </init-param> <init-param> <name>columns</name> <value>2</value> </init-param> <init-param> <name>sizes</name> <value>50%,50%</value> </init-param> <portlet-class>org.apache.jetspeed.portlets.layout.MultiColumnPortlet</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> </supports> <portlet-info> <title>VelocityTwoColumns</title> <short-title>TwoColumns</short-title> </portlet-info> </portlet> <portlet id="PortletApplicationBrowser"> <init-param> <description>This parameter sets the template used in view mode.</description> <name>ViewPage</name> <value>/pages/pam/pam-browser.jsp</value> </init-param> <portlet-name>PortletApplicationBrowser</portlet-name> <display-name>Portlet Application Browser</display-name> <description>The PAM (Portlet Application Manager) Portlet Application Browser displays a list of portlet applications deployed to this portal. From here you can add, edit, and delete portlet applications.</description> <portlet-class>org.apache.jetspeed.portlets.pam.PortletApplicationBrowser</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>EDIT</portlet-mode> <portlet-mode>VIEW</portlet-mode> <portlet-mode>HELP</portlet-mode> </supports> <portlet-info> <title>Portlet Application Browser</title> <short-title>Apps</short-title> <keywords>applications,apps,PAM</keywords> </portlet-info> </portlet> <portlet id="PortletApplicationDetail"> <init-param> <description>This parameter sets the template used in view mode.</description> <name>ViewPage</name> <value>/pages/pam/pam-detail.jsp</value> </init-param> <portlet-name>PortletApplicationDetail</portlet-name> <display-name>Portlet Application Detail</display-name> <description>The PAM (Portlet Application Manager) Portlet Application Detail displays a specific portlet application deployed to this portal. From here you can add, edit, and delete this portlet application.</description> <portlet-class>org.apache.jetspeed.portlets.pam.PortletApplicationDetail</portlet-class> <expiration-cache>-1</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>EDIT</portlet-mode> <portlet-mode>VIEW</portlet-mode> <portlet-mode>HELP</portlet-mode> </supports> <portlet-info> <title>Portlet Application Detail</title> <short-title>PAD</short-title> <keywords>applications,apps,PAM,PAD</keywords> </portlet-info> </portlet> </portlet-app> \ No newline at end of file 1.3 +127 -7 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java Index: LayoutPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LayoutPortlet.java 8 Mar 2004 00:31:30 -0000 1.2 +++ LayoutPortlet.java 18 May 2004 19:51:39 -0000 1.3 @@ -15,14 +15,134 @@ */ package org.apache.jetspeed.portlets.layout; -import javax.portlet.Portlet; +import java.io.IOException; + +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletPreferences; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.Jetspeed; +import org.apache.jetspeed.aggregator.ContentDispatcher; +import org.apache.jetspeed.locator.TemplateLocatorException; +import org.apache.jetspeed.om.page.Fragment; +import org.apache.jetspeed.om.page.Page; +import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.velocity.JetspeedPowerTool; +import org.apache.pluto.om.window.PortletWindow; /** - * LayoutPortlet - * - * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> - * @version $Id$ */ -public interface LayoutPortlet extends Portlet +public class LayoutPortlet extends org.apache.jetspeed.portlet.ServletPortlet { -} + /** Commons logging */ + protected final static Log log = LogFactory.getLog(LayoutPortlet.class); + + public void init(PortletConfig config) throws PortletException + { + super.init(config); + } + + public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException + { + response.setContentType("text/html"); + + RequestContext context = Jetspeed.getCurrentRequestContext(); + PortletWindow window = context.getNavigationalState().getMaximizedWindow(context.getPage()); + boolean maximized = (window != null); + + request.setAttribute("page", getPage(request)); + request.setAttribute("fragment", getFragment(request, maximized)); + request.setAttribute("dispatcher", getDispatcher(request)); + if (maximized) + { + request.setAttribute("layout", getMaximizedLayout(request)); + } + else + { + request.setAttribute("layout", getFragment(request, false)); + } + // now invoke the JSP associated with this portlet + JetspeedPowerTool jpt = new JetspeedPowerTool(request, response, getPortletConfig()); + PortletPreferences prefs = request.getPreferences(); + if (prefs != null) + { + String absViewPage = null; + try + { + if (maximized) + { + String viewPage = prefs.getValue(PARAM_MAX_PAGE, "maximized"); + + // TODO: Need to retreive layout.properties instead of hard-coding ".vm" + absViewPage = jpt.getTemplate(viewPage+"/"+JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE+".vm", + JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE).getAppRelativePath(); + } + else + { + String viewPage = prefs.getValue(PARAM_VIEW_PAGE, "columns"); + + // TODO: Need to retreive layout.properties instead of hard-coding ".vm" + absViewPage = jpt.getTemplate(viewPage+"/"+JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE+".vm", + JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE).getAppRelativePath(); + } + log.debug("Path to view page for LayoutPortlet "+absViewPage); + request.setAttribute(PARAM_VIEW_PAGE, absViewPage); + } + catch (TemplateLocatorException e) + { + throw new PortletException("Unable to locate view page " + absViewPage, e); + } + } + + super.doView(request, response); + + request.removeAttribute("page"); + request.removeAttribute("fragment"); + request.removeAttribute("layout"); + request.removeAttribute("dispatcher"); + } + + protected Fragment getFragment(RenderRequest request, boolean maximized) + { + // Very ugly and Pluto dependant but I don't see anything better right now + ServletRequest innerRequest = ((HttpServletRequestWrapper) request).getRequest(); + String attribute = (maximized) ? "org.apache.jetspeed.maximized.Fragment" : "org.apache.jetspeed.Fragment"; + Fragment fragment = (Fragment) innerRequest.getAttribute(attribute); + + return fragment; + } + + protected Fragment getMaximizedLayout(RenderRequest request) + { + // Very ugly and Pluto dependant but I don't see anything better right now + ServletRequest innerRequest = ((HttpServletRequestWrapper) request).getRequest(); + String attribute = "org.apache.jetspeed.maximized.Layout" ; + Fragment fragment = (Fragment) innerRequest.getAttribute(attribute); + return fragment; + } + + protected Page getPage(RenderRequest request) + { + // Very ugly and Pluto dependant but I don't see anything better right now + ServletRequest innerRequest = ((HttpServletRequestWrapper) request).getRequest(); + Page page = (Page) innerRequest.getAttribute("org.apache.jetspeed.Page"); + + return page; + } + + protected ContentDispatcher getDispatcher(RenderRequest request) + { + // Very ugly and Pluto dependant but I don't see anything better right now + ServletRequest innerRequest = ((HttpServletRequestWrapper) request).getRequest(); + ContentDispatcher dispatcher = (ContentDispatcher) innerRequest.getAttribute("org.apache.jetspeed.ContentDispatcher"); + + return dispatcher; + } + +} \ No newline at end of file 1.1 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/portlets/layout/MultiColumnPortlet.java Index: MultiColumnPortlet.java =================================================================== /* * Copyright 2000-2004 The Apache Software Foundation. * * Licensed 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.portlets.layout; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Vector; import java.util.StringTokenizer; import java.util.Collections; import javax.portlet.PortletConfig; import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.jetspeed.Jetspeed; import org.apache.jetspeed.om.page.Fragment; import org.apache.jetspeed.om.page.Property; import org.apache.jetspeed.request.RequestContext; import org.apache.pluto.om.window.PortletWindow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** */ public class MultiColumnPortlet extends LayoutPortlet { /** Commons logging */ protected final static Log log = LogFactory.getLog(MultiColumnPortlet.class); protected final static String PARAM_NUM_COLUMN = "columns"; protected final static int DEFAULT_NUM_COLUMN = 2; protected final static String PARAM_COLUMN_SIZES = "sizes"; protected final static String DEFAULT_COLUMN_SIZES = "50%,50%"; private int numColumns = 0; private String colSizes = null; private String portletName = null; public void init(PortletConfig config) throws PortletException { super.init(config); this.numColumns = Integer.parseInt(config.getInitParameter(PARAM_NUM_COLUMN)); this.colSizes = config.getInitParameter(PARAM_COLUMN_SIZES); this.portletName = config.getPortletName(); } public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { RequestContext context = Jetspeed.getCurrentRequestContext(); PortletWindow window = context.getNavigationalState().getMaximizedWindow(context.getPage()); // if (targetState != null && targetState.isMaximized()) if (window != null) { super.doView(request,response); return; } List[] columns = buildColumns(getFragment(request, false), this.numColumns); request.setAttribute("columns", columns); // now invoke the JSP associated with this portlet super.doView(request,response); request.removeAttribute("columns"); } protected List[] buildColumns(Fragment f, int colNum) { // normalize the constraints and calculate max num of rows needed Iterator iterator = f.getFragments().iterator(); int row = 0; int col = 0; int rowNum = 0; while (iterator.hasNext()) { Fragment fChild = (Fragment) iterator.next(); List properties = fChild.getProperties(this.portletName); if (properties != null) { Iterator pIterator = properties.iterator(); while(pIterator.hasNext()) { Property prop = (Property)pIterator.next(); try { if (prop.getName().equals("row")) { row = Integer.parseInt(prop.getValue()); if (row > rowNum) { rowNum = row; } } else if (prop.getName().equals("column")) { col = Integer.parseInt(prop.getValue()); if (col > colNum) { prop.setValue(String.valueOf(col % colNum)); } } } catch (Exception e) { //ignore any malformed layout properties } } } } int sCount = f.getFragments().size(); row = (sCount / colNum) + 1; if (row > rowNum) { rowNum = row; } // initialize the result position table and the work list List[] table = new List[colNum]; List filler = Collections.nCopies(rowNum + 1, null); for (int i = 0; i < colNum; i++) { table[i] = new ArrayList(); table[i].addAll(filler); } List work = new ArrayList(); //position the constrained elements and keep a reference to the //others for (int i = 0; i < sCount; i++) { addElement((Fragment)f.getFragments().get(i), table, work, colNum); } //insert the unconstrained elements in the table Iterator i = work.iterator(); for (row = 0; row < rowNum; row++) { for (col = 0; i.hasNext() && (col < colNum); col++) { if (table[col].get(row) == null) { table[col].set(row, i.next()); } } } // now cleanup any remaining null elements for (int j = 0; j < table.length; j++) { i = table[j].iterator(); while (i.hasNext()) { Object obj = i.next(); if (obj == null) { i.remove(); } } } return table; } /** Parses the size config info and returns a list of * size values for the current set * * @param sizeList java.lang.String a comma separated string a values * @return a List of values */ protected static List getCellSizes(String sizeList) { List list = new Vector(); if (sizeList != null) { StringTokenizer st = new StringTokenizer(sizeList, ","); while (st.hasMoreTokens()) { list.add(st.nextToken()); } } return list; } protected static List getCellClasses(String classlist) { List list = new Vector(); if (classlist != null) { StringTokenizer st = new StringTokenizer(classlist, ","); while (st.hasMoreTokens()) { list.add(st.nextToken()); } } return list; } /** * Add an element to the "table" or "work" objects. If the element is * unconstrained, and the position is within the number of columns, then * the element is added to "table". Othewise the element is added to "work" * * @param f fragment to add * @param table of positioned elements * @param work list of un-positioned elements * @param columnCount Number of colum */ protected void addElement(Fragment f, List[] table, List work, int columnCount) { int row = -1; int col = -1; List properties = f.getProperties(this.portletName); if (properties != null) { Iterator pIterator = properties.iterator(); while(pIterator.hasNext()) { Property prop = (Property)pIterator.next(); try { if (prop.getName().equals("row")) { row = Integer.parseInt(prop.getValue()); } else if (prop.getName().equals("column")) { col = Integer.parseInt(prop.getValue()); } } catch (Exception e) { //ignore any malformed layout properties } } } if ((row >= 0) && (col >= 0) && (col < columnCount)) { table[col].set(row, f); } else { work.add(f); } } } 1.74 +1 -1 jakarta-jetspeed-2/portal/maven.xml Index: maven.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portal/maven.xml,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- maven.xml 12 May 2004 18:50:37 -0000 1.73 +++ maven.xml 18 May 2004 19:51:39 -0000 1.74 @@ -20,7 +20,7 @@ xmlns:maven="jelly:maven"> <!-- Target of maven test:single test --> -<property name='testcase' value='org.apache.jetspeed.container.session.TestNavigationalState'/> +<property name='testcase' value='org.apache.jetspeed.pipeline.TestPipeline'/> <preGoal name="java:prepare-filesystem"> <echo message="====================================" /> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]