weaver 2004/06/10 13:12:45
Added: layout-portlets/src/java/org/apache/jetspeed/portlets/layout
MultiColumnPortlet.java LayoutPortlet.java
layout-portlets/src/webapp/WEB-INF portlet.tld web.xml
portlet.xml
layout-portlets project.xml project.properties
Log:
layout-portlets mvoed to there own sub-project
Revision Changes Path
1.1
jakarta-jetspeed-2/layout-portlets/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.1
jakarta-jetspeed-2/layout-portlets/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
Index: LayoutPortlet.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 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;
/**
*/
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;
}
}
1.1
jakarta-jetspeed-2/layout-portlets/src/webapp/WEB-INF/portlet.tld
Index: portlet.tld
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
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.
-->
<!DOCTYPE taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>Tags for portlets</shortname>
<tag>
<name>defineObjects</name>
<tagclass>org.apache.pluto.tags.DefineObjectsTag</tagclass>
<teiclass>org.apache.pluto.tags.DefineObjectsTag$TEI</teiclass>
<bodycontent>empty</bodycontent>
</tag>
<tag>
<name>param</name>
<tagclass>org.apache.pluto.tags.ParamTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>actionURL</name>
<tagclass>org.apache.pluto.tags.ActionURLTag</tagclass>
<teiclass>org.apache.pluto.tags.BasicURLTag$TEI</teiclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>windowState</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>portletMode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>secure</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>renderURL</name>
<tagclass>org.apache.pluto.tags.RenderURLTag</tagclass>
<teiclass>org.apache.pluto.tags.BasicURLTag$TEI</teiclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>windowState</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>portletMode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>secure</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>namespace</name>
<tagclass>org.apache.pluto.tags.NamespaceTag</tagclass>
<bodycontent>empty</bodycontent>
</tag>
</taglib>
1.1 jakarta-jetspeed-2/layout-portlets/src/webapp/WEB-INF/web.xml
Index: web.xml
===================================================================
<?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.
-->
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Jetspeed 2 Core Portlets</display-name>
<description>Jetspeed 2 Core Portlets</description>
<servlet>
<servlet-name>JetspeedContainer</servlet-name>
<display-name>Jetspeed Container</display-name>
<description>MVC Servlet for Jetspeed Portlet Applications</description>
<servlet-class>org.apache.jetspeed.container.JetspeedContainerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
JetspeedContainer
</servlet-name>
<url-pattern>
/container/*
</url-pattern>
</servlet-mapping>
<!-- Portlet tag library TLD -->
<taglib>
<taglib-uri>portlet.tld</taglib-uri>
<taglib-location>/WEB-INF/portlet.tld</taglib-location>
</taglib>
</web-app>
1.1
jakarta-jetspeed-2/layout-portlets/src/webapp/WEB-INF/portlet.xml
Index: portlet.xml
===================================================================
<?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-app>
1.1 jakarta-jetspeed-2/layout-portlets/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Id: project.xml,v 1.1 2004/06/10 20:12:45 weaver Exp $
-->
<project>
<extend>${basedir}/../project.xml</extend>
<id>jetspeed2-layout-portlets</id>
<groupId>jetspeed2</groupId>
<name>Jetspeed-2 Layout Portlets</name>
<description>Layout Portlets</description>
<shortDescription>Layouts.</shortDescription>
<repository>
<connection>scm:cvs:pserver:[EMAIL
PROTECTED]:/home/cvspublic:jakarta-jetspeed-2/applications/demo</connection>
<url>http://cvs.apache.org/viewcvs/jakarta-jetspeed-2/applications/demo/</url>
</repository>
<dependencies>
<dependency>
<id>portlet-api</id>
<version>1.0</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>pluto</id>
<version>1.0.1-SNAPSHOT</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>servletapi</id>
<version>2.3</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>velocity</id>
<version>1.4-rc1</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>servletapi</id>
<version>2.3</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>jetspeed2:jetspeed-commons</id>
<version>2.0-a1-dev</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>jetspeed2:jetspeed-api</id>
<version>2.0-a1-dev</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>jetspeed2:jetspeed-cm</id>
<version>2.0-a1-dev</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>jetspeed2:jetspeed-registry</id>
<version>2.0-a1-dev</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
<dependency>
<id>jetspeed2:jetspeed</id>
<version>2.0-a1-dev</version>
<properties>
<war.bundle.jar>false</war.bundle.jar>
</properties>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/java</sourceDirectory>
</build>
<reports>
<report>maven-jdepend-plugin</report>
<!--
<report>maven-checkstyle-plugin</report>
-->
<report>maven-pmd-plugin</report>
<report>maven-changelog-plugin</report>
<report>maven-file-activity-plugin</report>
<report>maven-developer-activity-plugin</report>
<report>maven-license-plugin</report>
<report>maven-javadoc-plugin</report>
<report>maven-jxr-plugin</report>
<report>maven-junit-report-plugin</report>
<report>maven-linkcheck-plugin</report>
<report>maven-tasklist-plugin</report>
</reports>
</project>
1.1 jakarta-jetspeed-2/layout-portlets/project.properties
Index: project.properties
===================================================================
#
# $Id: project.properties,v 1.1 2004/06/10 20:12:45 weaver Exp $
#
# Display the date on the Maven web site
maven.xdoc.date = left
# Display the maven version the web site is documenting
maven.xdoc.version = ${pom.currentVersion}
maven.checkstyle.header.file=${basedir}/../../checkstyle.license
maven.checkstyle.properties=${basedir}/../../checkstyle.xml
maven.compile.deprecation=on
maven.license.licenseFile=${basedir}/../../LICENSE.TXT
maven.compile.fork=yes
maven.junit.fork=yes
# Include private method and field in Javadoc.
maven.javadoc.private=true
# Removed the rule ${plugin.resources}/rulesets/naming.xml from the default
# maven.pmd.rulesetfiles. This is because the LongVariableName rule is to
# restrictive. We need to increase the limit from 12 to 20
maven.pmd.rulesetfiles=${plugin.resources}/rulesets/strings.xml,${plugin.resources}/rulesets/junit.xml,${plugin.resources}/rulesets/braces.xml,${plugin.resources}/rulesets/basic.xml,${plugin.resources}/rulesets/unusedcode.xml,${plugin.resources}/rulesets/design.xml,${plugin.resources}/rulesets/imports.xml,${plugin.resources}/rulesets/codesize.xml
maven.multiproject.type=war
maven.war.final.name=jetspeed-layouts.war
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]