raphael 01/05/28 08:16:10
Modified: src/java/org/apache/jetspeed/portal PortletState.java
Added: src/java/org/apache/jetspeed/portal/controls
VelocityPortletControl.java
Log:
add VelocityPortletControl
Revision Changes Path
1.2 +7 -5
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/PortletState.java
Index: PortletState.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/PortletState.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PortletState.java 2001/05/07 20:48:34 1.1
+++ PortletState.java 2001/05/28 15:16:10 1.2
@@ -110,13 +110,15 @@
public boolean allowMinimize( RunData rundata );
/**
- * Returns true if this portlet is currently maximized
+ * Returns true if this portlet is currently minimized
*/
- public boolean isMaximized();
+ public boolean isMinimized(RunData data);
/**
- * Returns true if this portlet is currently minimized
+ * Toggles the portlet state between minimized and normal
+ *
+ * @param minimized the new portlet state
+ * @param data the RunData for this request
*/
- public boolean isMinimized();
-
+ public void setMinimized(boolean minimized, RunData data);
}
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/VelocityPortletControl.java
Index: VelocityPortletControl.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.portal.controls;
// Turbine stuff
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.RelativeDynamicURI;
// Jetspeed stuff
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletControl;
import org.apache.jetspeed.portal.PortletState;
import org.apache.jetspeed.util.MimeType;
import org.apache.jetspeed.util.template.ContentTemplateLink;
// Ecs stuff
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.StringElement;
// Velocity Stuff
import org.apache.velocity.context.Context;
import java.util.List;
import java.util.Vector;
import java.util.Iterator;
/**
* A Velocity based portlet control which implements all PortletState action
*
* <p>To use this control you need to define in your registry the following
* entry or similar:</p>
* <pre>
* <portlet-control-entry name="TitlePortletControl">
*
<classname>org.apache.jetspeed.portal.controls.VelocityPortletControl</classname>
* <parameter name="theme" value="default.vm"/>
* <meta-info>
* <title>TitleControl</title>
* <description>The standard Jetspeed boxed control</description>
* </meta-info>
* <media-type ref="html"/>
* </portlet-control-entry>
* </pre>
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Roberto Carrasco</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
*/
public class VelocityPortletControl extends AbstractPortletControl
{
/**
* Handles the content generation for this control using Velocity
*/
public ConcreteElement getContent( RunData rundata )
{
Portlet portlet = getPortlet();
// Create a new Velocity context
Context context = TurbineVelocity.getContext(rundata);
context.put("actions", buildActionList( rundata, portlet ) );
context.put("config", getConfig() );
context.put("skin", portlet.getPortletConfig().getPortletSkin() );
context.put("portlet", portlet );
// allow subclasses to add elements to the context
buildContext( rundata, context );
//FIXME: add tree traversal for handling media types and languages
//consolidate with the other tree traversal routines...
String theme = getConfig().getInitParameter("theme","default.vm");
String s = null;
try
{
s = TurbineVelocity.handleRequest(context, "controls/" + theme);
}
catch( Exception e )
{
s = e.toString();
}
return new StringElement( s );
}
/**
* This method allows subclasses of the VelocityPortletControl
* to populate the context of this control before rendering by
* the template engine.
*
* @param rundata the RunData object for this request
* @param context the Context used by the template
*/
public void buildContext( RunData rundata, Context context )
{
// empty, should be used by subclasses to populate the context
}
/** Builds a list of possible window actions for this portlet
* instance. For best results, the portlet should also implement the
* PortletState interface.
*
* @param rundata the request RunData
* @param the portlet instance managed by this control
* @return a list of ordered PortletAction objects describing the
* the actions available for this portlet
*/
protected List buildActionList( RunData rundata, Portlet portlet )
{
List actions = new Vector();
// list the available actiosn for this portlet
if (portlet instanceof PortletState)
{
// the portlet is state aware
PortletState state = (PortletState)portlet;
if ( state.allowCustomize( rundata ) )
{
actions.add( new PortletAction("customize") );
}
else
{
if ( state.allowInfo( rundata ) )
{
actions.add( new PortletAction("info") );
}
}
if ( ( state.isMinimized( rundata ) )
||
(portlet.getName().equals(rundata.getSession().getAttribute("maximize"))) )
{
actions.add( new PortletAction("restore") );
}
else
{
if ( state.allowMinimize( rundata ) )
{
actions.add( new PortletAction("minimize") );
}
if ( state.allowMaximize( rundata ) )
{
actions.add( new PortletAction("maximize") );
}
}
}
else
{
// the portlet only knows about edit and maximize
if ( portlet.getAllowEdit( rundata ) )
{
actions.add( new PortletAction("info") );
}
if ( portlet.getAllowMaximize( rundata ) )
{
actions.add( new PortletAction("maximize") );
}
}
// Now that we know which actions should be displayed,
// build the links and put it in the context
Iterator i = actions.iterator();
while( i.hasNext() )
{
PortletAction action = (PortletAction)i.next();
action.setLink( new RelativeDynamicURI( rundata )
.addQueryData("action", getAction( action.getName()
) )
.addQueryData("portlet", portlet.getName() )
.toString() );
}
return actions;
}
/** Transforms an Action name in Turbine valid action name, by
* adding a controls package prefix and capitalizing the first
* letter of the name.
*/
protected static String getAction( String name )
{
StringBuffer buffer = new StringBuffer( "controls." );
buffer.append( name.substring(0,1).toUpperCase() );
buffer.append( name.substring(1, name.length() ) );
return buffer.toString();
}
/** This utility class is used to give information about the actions
* available in a control theme template
*/
public class PortletAction
{
String name = null;
String link = null;
protected PortletAction( String name )
{
this.name = name;
}
public String getName()
{
return this.name;
}
public String getLink()
{
return this.link;
}
public void setLink(String link)
{
this.link=link;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]