Dear All,
I work in portlet customization for jetspeed, and find
there is a need for jetspeed to add a new feature,
that default.psml can manage the action (max, min,
edit, close). is there some one work on it?>
This <parameter> tag is best if implemented in xreg,
but I still don't know how to read xreg from
PortletConfig... may be someone can give me a detail
explaination... ;)
Yah I need someone explain how to read default.psml,
and portlets.xreg become pages.. plz..
How this script work?
Add <parameter> tag in <entry> tag in default.psml and
if the user login, the action button of that portlet
will follow the <parameter> value
Sample 1:
<entry >
<parameter name="_action"
value="customize,maximize,close"/>
</entry>
This will show only customize,maximize, and close
button only.
Sample 2:
<entry parent="HelloVelocity">
<parameter name="_action"
value="close,minimize,maximize"/>
</entry>
This will show only close, minimze, and maximize.
Sample 3:
<entry parent="HelloVelocity"/>
This will show all the button (close, min, max, edit).
I add several function to the Abstract Portlet, and
add class to several file:
- AbstractPortlet.java
public String[] getActionParameter(RunData rundata)
- StringUtils
public static String[] getExtractString(String text,
String separator)
- and add parameter="_action" in default.psml.
<parameter name="_action"
value="customize,maximize,close"/>
QUESTION...
to who create a customization of 3 column or 2 colum
(75/25, 50/50. 25/70)
I cannot find the extract string class.. do you know
where is it?
Frans
=====
Empowering Open Source Spirit...
Open Source is Open Source. Shared Source is another thing.
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
/* ====================================================================
* 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.portlets;
//jetspeed
import org.apache.jetspeed.portal.*;
import org.apache.jetspeed.portal.expire.*;
import org.apache.jetspeed.capability.*;
import org.apache.jetspeed.util.*;
import org.apache.jetspeed.services.portletcache.Cacheable;
import org.apache.jetspeed.portal.service.PersistenceService;
import org.apache.jetspeed.portal.service.ServiceFactory;
import org.apache.jetspeed.portal.service.ServiceException;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.om.registry.MediaTypeEntry;
//ecs
import org.apache.ecs.*;
//turbine stuff
import org.apache.turbine.util.*;
//java stuff
import java.util.*;
import java.io.*;
/**
<p>
Should be used by most Portlets that wish to conform to default behavior
</p>
<p>
PERFORMANCE NOTE:
getContent returns a StringElement that was generated on setContent(). This is
used so that performance is increased since ECS does not have to work overtime
to generate output.
</p>
@author <A HREF="mailto:[EMAIL PROTECTED]">Kevin A. Burton</A>
@author <A HREF="mailto:[EMAIL PROTECTED]">Rapha�l Luta</A>
@version $Id: AbstractPortlet.java,v 1.44 2001/07/29 13:41:57 raphael Exp $
*/
public abstract class AbstractPortlet implements Portlet, PortletState, Cacheable
{
private boolean cacheable = true;
private PortletConfig pc = null;
/**
Provide a required name for this Portlet
*/
private String name = null;
/**
Cache handle for this object.
*/
private String handle = "";
/**
Holds instances of ConcreteElements (Portlet output/content)
based on its current CapabilityMap.
*/
protected Hashtable content = new Hashtable();
/**
The time this portlet was created.
*/
private long creationTime;
/**
*/
public String getName()
{
if ( name == null )
{
if (getPortletConfig()!=null)
{
if (getPortletConfig().getName()!=null)
{
return getPortletConfig().getName();
}
else
{
return this.getClass().getName();
}
}
}
return name;
}
/**
*/
public void setName( String name ) {
this.name = name;
}
/**
*/
public PortletConfig getPortletConfig() {
return this.pc;
}
/**
*/
public void setPortletConfig( PortletConfig pc ) {
this.pc = pc;
}
//Cacheable interface
/**
*/
public boolean isCacheable() {
return this.cacheable;
}
/**
*/
public void setCacheable(boolean cacheable) {
this.cacheable = cacheable;
}
/**
*/
public Expire getExpire() {
try {
return ExpireFactory.getExpire( this, ExpireFactory.NO_EXPIRE );
} catch ( JetspeedException e ) {
Log.error( e );
return null;
}
}
/**
*/
public final String getHandle() {
return this.handle;
}
/**
*/
public final void setHandle( String handle ) {
this.handle = handle;
}
/** Builds a new cache handle for this cacheable class with the specified
* config object.
*
* @param config the configuration object to use for building the handle
* @return a cache handle
*/
public static Object getHandle(Object config)
{
//this implementation expects a PortletConfig object as its
// configuration
PortletConfig pc = null;
if (!(config instanceof PortletConfig))
{
return null;
}
// By default, only take into account the init parameters
pc = (PortletConfig)config;
StringBuffer handle = new StringBuffer(256);
if (pc.getURL()!=null)
{
handle.append(String.valueOf(pc.getURL().hashCode()));
}
Iterator i = pc.getInitParameterNames();
while(i.hasNext())
{
String name = (String)i.next();
String value = pc.getInitParameter(name);
if (value!=null)
{
handle.append("|").append(name).append("-").append(value);
}
}
return handle.toString();
}
/**
*/
public ConcreteElement getContent( RunData rundata ) {
return getContent( rundata, null , true );
}
public ConcreteElement getContent( RunData rundata, CapabilityMap map ) {
CapabilityMap mymap = map;
if ( mymap == null ) mymap = CapabilityMapFactory.getCapabilityMap( rundata );
return (ConcreteElement)content.get( mymap.toString() );
}
/**
*/
public ConcreteElement getContent( RunData rundata,
CapabilityMap map,
boolean allowRecurse ) {
CapabilityMap mymap = map;
if ( mymap == null ) mymap = CapabilityMapFactory.getCapabilityMap( rundata );
ConcreteElement element = (ConcreteElement)content.get( mymap.toString() );
if ( element == null ) {
if ( allowRecurse ) {
try {
// init will put content under default cmap
init( );
element = getContent( rundata, mymap, false );
if( element != null ) {
// now we put it under our cmap
this.setContent( element, mymap );
}
} catch (Exception e) {
element = new StringElement("Error when retrieving Portlet
contents");
}
} else {
if( element == null ) {
//FIXME: Let's asume that the contents under "default" map are good
mymap = CapabilityMapFactory.getDefaultCapabilityMap();
element = (ConcreteElement)content.get( mymap.toString() );
if( element == null ) {
element = new ClearElement("");
}
}
}
}
return element;
}
/**
*/
protected void clearContent() {
this.content.clear();
}
/**
*/
protected void setContent( ConcreteElement content ) {
this.setContent( content, null );
}
/**
*/
protected void setContent( String content ) {
this.setContent( new ClearElement( content ), null );
}
/**
*/
protected void setContent( ConcreteElement content,
CapabilityMap map )
throws IllegalArgumentException
{
CapabilityMap mymap = map;
if ( mymap == null ) {
mymap = CapabilityMapFactory.getDefaultCapabilityMap();
}
ConcreteElement buffer = new ClearElement( content.toString( ) );
this.content.put( mymap.toString(), buffer );
}
/**
Provide a description within PML if the user has specified one.
@return a null entry if the user hasn't defined anything
*/
public String getDescription() {
if (getPortletConfig()!=null)
if (getPortletConfig().getMetainfo()!=null)
return getPortletConfig().getMetainfo().getDescription();
return null;
}
/**
*/
public void setDescription( String description ) {
PortletConfig pc = getPortletConfig();
if (pc==null) {
pc = new BasePortletConfig();
setPortletConfig(pc);
}
MetaData meta = pc.getMetainfo();
if (meta==null) {
meta = new MetaData();
pc.setMetainfo(meta);
}
meta.setDescription(description);
}
//provide default titles so that the user can define them in PML
/**
Provide a title within PML if the user has specified one.
@return a null entry if the user hasn't defined anything
*/
public String getTitle() {
if (getPortletConfig()!=null)
if (getPortletConfig().getMetainfo()!=null)
return getPortletConfig().getMetainfo().getTitle();
return null;
}
/**
Set the title for this Portlet
*/
public void setTitle( String title ) {
PortletConfig pc = getPortletConfig();
if (pc==null) {
pc = new BasePortletConfig();
setPortletConfig(pc);
}
MetaData meta = pc.getMetainfo();
if (meta==null) {
meta = new MetaData();
pc.setMetainfo(meta);
}
meta.setTitle(title);
}
/**
*/
public boolean getAllowEdit( RunData rundata )
{
return allowInfo( rundata );
}
/**
*/
public boolean getAllowMaximize( RunData rundata )
{
return allowMaximize( rundata );
}
/**
By default don't provide any initialization
*/
public void init( ) throws PortletException
{
// make sure to clean all content
clearContent();
}
/**
@see Portlet#getCreationTime
*/
public long getCreationTime() {
return this.creationTime;
}
/**
@see Portlet.setCreationTime
*/
public void setCreationTime( long creationTime ) {
this.creationTime = creationTime;
}
/**
@see Portlet.supportsType
*/
public boolean supportsType( MimeType mimeType )
{
PortletEntry entry = (PortletEntry)Registry.getEntry(Registry.PORTLET,
getName() );
String baseType = mimeType.toString();
if (entry!=null)
{
Iterator i = entry.listMediaTypes();
while(i.hasNext())
{
String name = (String)i.next();
MediaTypeEntry media =
(MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, name);
if (media != null)
{
if (baseType.equals(media.getMimeType())) return true;
}
}
}
return MimeType.HTML.equals( mimeType );
}
// PortletState Interface implementation
/**
* Implements the default close behavior: any authenticated user may
* remove a portlet from his page
*
* @param rundata the RunData object for the current request
*/
public boolean allowClose( RunData rundata )
{
return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
}
/**
* Returns true if this portlet is currently closed
*/
public boolean isClosed(RunData rundata)
{
return this.getAttribute("_display", "normal", rundata ).equals("closed");
}
/**
* Toggles the portlet state between closed and normal
*
* @param minimized the new portlet state
* @param data the RunData for this request
*/
public void setClosed(boolean close, RunData rundata)
{
if( allowClose( rundata ) )
{
this.setAttribute("_display", close ? "closed" : "normal", rundata );
}
}
/* --- modified by frans */
/**
* getActionParameter will return _action value
*
* if none means all
*
* example:
* <parameter name="_action" value="customize, edit, delete, minimize,
maximize";/>
* will return "customize, edit, delete, minimize, maximize";
* use together with $actions.
*/
public String[] getActionParameter(RunData rundata)
{
String sDefaultAction="customize,close,minimize,maximize";
String[] subStr=new String[6];
org.apache.jetspeed.util.StringUtils es = new
org.apache.jetspeed.util.StringUtils();
subStr = es.getExtractString(this.getAttribute("_action", sDefaultAction,
rundata ),",");
return subStr;
}
/* ---------------------- */
/**
* Implements the default info behavior: any authenticated user may
* get information on a portlet
*
* @param rundata the RunData object for the current request
*/
public boolean allowInfo( RunData rundata )
{
return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
}
/**
* Implements the default customize behavior: any authenticated user may
* customize a portlet
*
* @param rundata the RunData object for the current request
*/
public boolean allowCustomize( RunData rundata )
{
return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
}
/**
* Implements the default maximize behavior: any authenticated user may
* maximize a portlet
*
* @param rundata the RunData object for the current request
*/
public boolean allowMaximize( RunData rundata )
{
return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
}
/**
* Implements the default info behavior: any authenticated user may
* minimize a portlet
*
* @param rundata the RunData object for the current request
*/
public boolean allowMinimize( RunData rundata )
{
return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
}
/**
* Returns true if this portlet is currently minimized
*/
public boolean isMinimized(RunData rundata)
{
return this.getAttribute("_display", "normal", rundata ).equals("minimized");
}
/**
Change the portlet visibility state ( minimized <-> normal )
@param minimize True if the portlet change to minimized
@param rundata A RunData object
*/
public void setMinimized( boolean minimize, RunData rundata )
{
if( allowMinimize( rundata ) )
{
this.setAttribute("_display", minimize ? "minimized" : "normal", rundata );
}
}
// utility methods
/**
Retrieve a portlet attribute from persistent storage
@param attrName The attribute to retrieve
@parm attrDefValue The value if the attr doesn't exists
@param rundata A RunData object
@return The attribute value
*/
public String getAttribute( String attrName, String attrDefValue, RunData rundata )
{
String attrValue = null ;
try
{
Object[] params = { this };
PersistenceService ps = (PersistenceService)ServiceFactory
.getService( PersistenceService.class,
rundata, params);
attrValue = ps.getPage().getAttribute( attrName );
if( attrValue == null )
{
attrValue = attrDefValue ;
}
}
catch ( Exception e )
{
Log.error("Exception while retrieving attribute "+attrName+" for portlet
"+getName(),e);
attrValue = attrDefValue ;
}
return attrValue;
}
/**
A way to store a portlet attribute in persistent storage
@param attrName The attribute to retrieve
@parm attrValue The value to store
@param rundata A RunData object
*/
public void setAttribute( String attrName, String attrValue, RunData rundata )
{
try
{
Object[] params = { this };
PersistenceService ps = (PersistenceService)ServiceFactory
.getService( PersistenceService.class,
rundata, params);
ps.getPage().setAttribute( attrName, attrValue );
// only allow to persist if user is logged in
if (rundata.getUser().hasLoggedIn())
{
ps.store();
}
}
catch ( Exception e )
{
Log.error("Exception while setting attribute "+attrName+" for portlet
"+getName(),e);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<portlets xmlns="http://www.apache.org/2000/02/CVS">
<controller name="CardPortletController"/>
<control name="TabControl"/>
<skin name="blue-grey"/>
<portlets>
<controller name="ColumnController"/>
<metainfo>
<title>Home</title>
</metainfo>
<entry parent="HelloVelocity">
<parameter name="_action" value="close,minimize,maximize"/>
</entry>
<entry parent="http://jakarta.apache.org/jetspeed/channels/jetspeed.rss">
<parameter name="showtitle" value="true"/>
<parameter name="_action" value="customize,close,minimize"/>
</entry>
<entry parent="http://jakarta.apache.org/jetspeed/channels/turbine.rss">
<parameter name="_action" value="customize,maximize,close"/>
</entry>
<entry parent="http://www.mozilla.org/news.rdf"/>
</portlets>
<portlets>
<controller name="ColumnController"/>
<metainfo>
<title>frans</title>
</metainfo>
<entry parent="Apacheweek"/>
</portlets>
</portlets>
/* ====================================================================
* 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.util;
import org.apache.turbine.util.Log;
/**
* This class provides static util methods for String manaipulation that
* aren't part of the default JDK functionalities.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
* @version $Id: StringUtils.java,v 1.3 2001/03/07 06:50:06 taylor Exp $
*/
public class StringUtils
{
/**
* Replaces all the occurences of a substring found within a string by a
* replacement string
*
* @deprecated (Generates too much garbage)
* @param original the string in where the replace will take place
* @param find the substring to find and replace
* @param replacement the replacement string for all occurences of find
* @returns the original string where all the occurences of find are replaced by
* replacement
*/
public static String replaceAll(String original, String find, String replacement)
{
StringBuffer buffer = new StringBuffer(original);
int idx = original.length();
int offset = find.length();
while( ( idx=original.lastIndexOf(find, idx-1) ) > -1 )
{
buffer.replace(idx,idx+offset, replacement);
}
return buffer.toString();
}
/**
* Replaces all the occurences of a substring found
* within a StringBuffer by a
* replacement string
*
* @param buffer the StringBuffer in where the replace will take place
* @param find the substring to find and replace
* @param replacement the replacement string for all occurences of find
* @returns the original StringBuffer where all the
* occurences of find are replaced by replacement
*/
public static StringBuffer replaceAll(StringBuffer buffer, String find, String
replacement)
{
int bufidx = buffer.length() - 1;
int offset = find.length();
while( bufidx > -1 ) {
int findidx = offset -1;
while( findidx > -1 ) {
if( bufidx == -1 ) {
//Done
return buffer;
}
if( buffer.charAt( bufidx ) == find.charAt( findidx ) ) {
findidx--; //Look for next char
bufidx--;
} else {
findidx = offset - 1; //Start looking again
bufidx--;
if( bufidx == -1 ) {
//Done
return buffer;
}
continue;
}
}
//Found
//System.out.println( "replacing from " + (bufidx + 1) +
// " to " + (bufidx + 1 + offset ) +
// " with '" + replacement + "'" );
buffer.replace( bufidx+1,
bufidx+1+offset,
replacement);
//start looking again
}
//No more matches
return buffer;
}
public static String[] getExtractString(String text, String separator)
{
int count=0;
int index=0;
do
{
++count;
++index;
index = text.indexOf(separator, index);
}
while (index !=-1);
String[] subStr=new String[count];
index = 0;
int endIndex=0;
for (int i=0;i<count;i++)
{
endIndex=text.indexOf(separator,index);
if (endIndex==-1)
subStr[i]=text.substring(index);
else
subStr[i]=text.substring(index, endIndex);
index=endIndex+1;
}
return subStr;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]