abstractportletcontrol.java
来自「jetspeed源代码」· Java 代码 · 共 825 行 · 第 1/2 页
JAVA
825 行
/*
* Copyright 2000-2001,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.portal.controls;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
// Jetspeed imports
import org.apache.jetspeed.om.registry.PortletControlEntry;
import org.apache.jetspeed.om.registry.MediaTypeEntry;
import org.apache.jetspeed.om.security.JetspeedUser;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletState;
import org.apache.jetspeed.portal.PortletConfig;
import org.apache.jetspeed.portal.PortletSet;
import org.apache.jetspeed.portal.PortletControl;
import org.apache.jetspeed.portal.PortletControlConfig;
import org.apache.jetspeed.portal.PortletController;
import org.apache.jetspeed.portal.PortletException;
import org.apache.jetspeed.portal.portlets.AbstractPortlet;
import org.apache.jetspeed.portal.security.portlets.PortletWrapper;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.util.MimeType;
import org.apache.jetspeed.services.resources.JetspeedResources;
// Turbine imports
import org.apache.turbine.util.RunData;
// ECS imports
import org.apache.ecs.ElementContainer;
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.StringElement;
/**
* The PortletControl acts both as a decoration around a Portlet or PortletSet
* and also as the window manager for the enclosed Portlet(Set).
* As such it controls the operation that may be performed on this portlet
* and whether the portlet content should be displayed or not.
* PortletControl also delegates all Portlet and PortletSet methods to its
* inner object and can thus be transparently cascaded or substituted to
* a simple portlet wherever in a PSML object tree.
*
* @author <a href="mailto:raphael@apache.org">Rapha雔 Luta</a>
* @author <a href="mailto:sgala@apache.org">Santiago Gala</a>
* @version $Id: AbstractPortletControl.java,v 1.22 2004/03/29 21:16:27 taylor Exp $
*/
public abstract class AbstractPortletControl extends AbstractPortlet
implements PortletControl
{
public static final String COLOR = "#CCCCCC";
public static final String BACKGROUND_COLOR = "#FFFFFF";
public static final String TITLE_COLOR = "#DDDDDD";
public static final String WIDTH = "100%";
private Portlet portlet = null;
private PortletControlConfig conf = null;
// PortletControl specifc interface
/**
* @return the PortletControl specific configuration
*/
public PortletControlConfig getConfig()
{
return this.conf;
}
/**
* Sets the PortletControl specific configuration
* @param conf the new PortletControl configuration
*/
public void setConfig(PortletControlConfig conf)
{
this.conf=conf;
}
/**
* Sets the portlet to be managed by this control
*
* @param portlet the new portlet to be managed by the control
*/
public void setPortlet(Portlet portlet)
{
this.portlet=portlet;
}
/**
* Retrieves the portlet managed by this control
* @return the portlet object managed or null
*/
public Portlet getPortlet()
{
return this.portlet;
}
/**
* Initializes the control and associates it with a portlet
*
* @param portlet the portlet to be managed by this control
*/
public void init( Portlet portlet )
{
this.setPortlet( portlet );
}
/**
* Returns the color to use for displaying the portlet text
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @return the text color value in HTML format (#RRGGBB)
*/
public String getColor()
{
return getPortlet().getPortletConfig().getPortletSkin().getTextColor();
}
/**
* Sets the color to use for displaying the portlet text
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @param color the text color value in HTML format (#RRGGBB)
*/
public void setColor(String color)
{
getPortlet().getPortletConfig().getPortletSkin().setTextColor( color );
}
/**
* Returns the color to use for displaying the portlet background
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @return the text color value in HTML format (#RRGGBB)
*/
public String getBackgroundColor()
{
return getPortlet().getPortletConfig().getPortletSkin().getBackgroundColor();
}
/**
* Sets the color to use for displaying the portlet background
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @param backgroundColor the background color value in HTML format (#RRGGBB)
*/
public void setBackgroundColor(String backgroundColor)
{
getPortlet().getPortletConfig().getPortletSkin().setBackgroundColor( backgroundColor );
}
/**
* Returns the color to use for displaying the portlet title
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @return the text color value in HTML format (#RRGGBB)
*/
public String getTitleColor()
{
return getPortlet().getPortletConfig().getPortletSkin().getTitleBackgroundColor();
}
/**
* Sets the color to use for displaying the portlet title
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @param titleColor the title color value in HTML format (#RRGGBB)
*/
public void setTitleColor(String titleColor)
{
getPortlet().getPortletConfig().getPortletSkin().setTitleBackgroundColor( titleColor );
}
/**
* Returns the width of the managed portlet relative to the size of
* portlet control.
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @return the size value. May be expressed in percentages (eg, "80%")
*/
public String getWidth() {
return getPortlet().getPortletConfig().getSkin( "width", WIDTH );
}
/**
* Sets the width of the managed portlet relative to the size of
* portlet control.
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @param width the width of portlet. Must be a positive, non nul integer
*/
public void setWidth(int width)
{
getPortlet().getPortletConfig().setSkin( "width", String.valueOf(width) );
}
/**
* Sets the width of the managed portlet relative to the size of
* portlet control.
*
* This method is deprecated and is only useful for ECS
* based Control implementation
* @deprecated
* @param width the width of portlet. Must be parseable as a positive, non
* nul integer or a percentage
*/
public void setWidth(String width)
{
getPortlet().getPortletConfig().setSkin( "width", width );
}
// Portlet interface implementation, delegates everything
// to the managed portlet
/**
* @return the inner portlet config object
*/
public PortletConfig getPortletConfig()
{
if (getPortlet()==null) return null;
return getPortlet().getPortletConfig();
}
/**
* Updates the managed portlet config object
*
* @param portletConfig the new portet config object
*/
public void setPortletConfig(PortletConfig portletConfig)
{
if (getPortlet()==null) return;
getPortlet().setPortletConfig(portletConfig);
}
/**
* @return the inner portlet name
*/
public String getName()
{
if (getPortlet()==null) return null;
return getPortlet().getName();
}
/**
* Updates the managed portlet name
*
* @param name the new portet name
*/
public void setName(String name)
{
if (getPortlet()!=null) getPortlet().setName(name);
}
/**
* @return the inner portlet title
*/
public String getTitle()
{
if (getPortlet()==null) return null;
return getPortlet().getTitle();
}
/**
* Set the title for the inner portlet
*
* @param title the new portlet title
*/
public void setTitle( String title )
{
if (getPortlet()!=null) getPortlet().setTitle(title);
}
/**
* @return the inner portlet description
*/
public String getDescription()
{
if (getPortlet()==null) return null;
return getPortlet().getDescription();
}
/**
* Set the description for the inner portlet
*
* @param description the new portlet description
*/
public void setDescription( String description )
{
if (getPortlet()!=null) getPortlet().setDescription(description);
}
/**
* Inits the inner portlet
*/
public void init() throws PortletException
{
if (getPortlet()!=null) getPortlet().init();
}
/**
* Returns the content of inner portlet
*
* @param rundata the RunData for the request
*/
public ConcreteElement getContent(RunData rundata)
{
Portlet portlet = getPortlet();
if (portlet == null)
{
return new ElementContainer();
}
// Check to see if the portlet allows view
// If the current security context disallows view,
// do not display the portlet OR the control decorator
if (portlet instanceof PortletWrapper)
{
PortletWrapper wrapper = (PortletWrapper)portlet;
if (!wrapper.getAllowView(rundata))
{
if (JetspeedResources.getBoolean("defaultportletcontrol.hide.decorator", true))
{
return new StringElement("");
}
}
}
return portlet.getContent( rundata );
}
/**
@see Portlet#supportsType
*/
public boolean supportsType( MimeType mimeType )
{
boolean allowed = true;
if (getPortlet()!=null)
{
allowed = getPortlet().supportsType( mimeType );
}
// the inner portlet does not support the type, return immediately...
if (allowed)
{
// we now need to check that the control also supports the type...
PortletControlEntry entry =
(PortletControlEntry)Registry.getEntry(Registry.PORTLET_CONTROL,
getConfig().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()))
{
allowed = true;
break;
}
}
}
}
}
return allowed;
}
// delegate the portletSet interface to the stored PortletSet
// or emulate a 1-element portletSet
/**
* @return the size of the inner portletSet, 1 if the inner portlet
* is not a set, or 0 if there's no inner portlet
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?