baseportletset.java
来自「jetspeed源代码」· Java 代码 · 共 829 行 · 第 1/2 页
JAVA
829 行
/*
* 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.portal;
// standard java stuff
import java.util.Vector;
import java.util.Enumeration;
// Jetspeed stuff
import org.apache.jetspeed.om.security.JetspeedUser;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.persistence.PersistenceManager;
import org.apache.jetspeed.services.persistence.PortalPersistenceException;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.services.security.PortalResource;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.util.template.JetspeedLink;
import org.apache.jetspeed.util.template.JetspeedLinkFactory;
import org.apache.jetspeed.util.MetaData;
import org.apache.jetspeed.util.MimeType;
// turbine stuff
import org.apache.turbine.services.localization.Localization;
import org.apache.turbine.util.RunData;
// ECS stuff
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.StringElement;
/**
* The PortletSet is basically a wrapper around an array of portlets. It provides
* runtime context for a set of portlets.
* A portlet can get its current set by calling via its PortletConfig
*
* @author <a href="mailto:raphael@apache.org">Rapha雔 Luta</a>
* @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
* @version $Id: BasePortletSet.java,v 1.35 2004/03/29 21:38:42 taylor Exp $
*/
public class BasePortletSet implements PortletSet, Portlet, PortletState
{
/**
* Static initialization of the logger for this class
*/
private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BasePortletSet.class.getName());
/**
Is this set sorted
*/
private boolean dirty = false;
/**
The PortletConfig of this set
*/
private PortletConfig pc = null;
/**
Provide a name for this set
*/
private String name = null;
/**
Storage for the portlets assigned to this set
*/
private Vector portlets = null;
/**
Controller which will layout the set
*/
private PortletController controller = null;
/**
The time this portlet was created.
*/
private long creationTime;
/**
The name of the portlet displaying info
*/
private String info;
/**
The portletset id
*/
private String id = null;
/**
Builds a new empty set for storing portlets
*/
public BasePortletSet()
{
portlets = new Vector();
try
{
init();
}
catch (PortletException e)
{
logger.error("Exception", e);
}
}
/**
Builds a new empty set for storing portlets with a default controller
*/
public BasePortletSet(PortletController controller)
{
portlets = new Vector();
setController(controller);
}
/**
*/
public void init() throws PortletException
{
if (getPortletConfig() == null)
{
setPortletConfig(new BasePortletConfig());
}
}
// Set manipulation methods
/**
Returns the number of portlets currently stored in this set
*/
public int size()
{
return portlets.size();
}
/**
Returns the portlet set as an array.
*/
public Portlet[] toArray()
{
sortPortletSet();
Portlet[] p = new Portlet[portlets.size()];
portlets.copyInto(p);
return p;
}
/**
Returns the Portlet at position pos
*/
public Portlet getPortletAt(int pos)
{
sortPortletSet();
return (Portlet) portlets.elementAt(pos);
}
/**
Returns the Portlet with the given id
*/
public Portlet getPortletByID(String id)
{
if (portlets == null)
{
return null;
}
Portlet portlet = null;
for (int ix = 0; ix < portlets.size(); ix++)
{
portlet = (Portlet) portlets.elementAt(ix);
if (portlet.getID().equals(id))
{
return portlet;
}
}
return null;
}
/**
Returns the Portlet with the given name
*/
public Portlet getPortletByName(String name)
{
if (portlets == null)
{
return null;
}
Portlet portlet = null;
for (int ix = 0; ix < portlets.size(); ix++)
{
portlet = (Portlet) portlets.elementAt(ix);
if (portlet.getName().equals(name))
{
return portlet;
}
}
return null;
}
/**
Returns the portlet set as an Enumeration
*/
public Enumeration getPortlets()
{
sortPortletSet();
return portlets.elements();
}
// set content manipulation methods
/**
Add a portlet to this set.It updates its config to modify the current set
*/
public void addPortlet(Portlet portlet)
{
addPortlet(portlet, null, -1);
}
/**
Add a portlet to this set.It updates its config to modify the current set
*/
public void addPortlet(Portlet portlet, int position)
{
addPortlet(portlet, null, position);
}
/**
Add a portlet to this set.It updates its config to modify the current set
*/
public void addPortlet(Portlet portlet, PortletSet.Constraints constraints)
{
addPortlet(portlet, constraints, -1);
}
/**
Add a portlet to this set.It updates its config to modify the current set
*/
public void addPortlet(Portlet portlet, PortletSet.Constraints constraints, int position)
{
synchronized (portlets)
{
portlets.addElement(portlet);
PortletConfig pc = portlet.getPortletConfig();
if (pc != null)
{
pc.setPortletSet(this);
if (constraints != null)
{
pc.setConstraints(constraints);
}
if (position >= 0)
{
pc.setPosition(position);
if (position < (portlets.size() - 1))
{
this.dirty = true;
}
}
}
}
}
// set properties setters/getters
/**
Return the current controller for this set
*/
public PortletController getController()
{
return this.controller;
}
/**
Set the controller for this set
*/
public synchronized void setController(PortletController controller)
{
this.controller = controller;
controller.setPortlets(this);
}
// portlet interface implementation
/**
*/
public ConcreteElement getContent(RunData rundata)
{
ConcreteElement content = null;
PortletController controller = getController();
PortalResource portalResource = new PortalResource(this);
try
{
JetspeedLink jsLink = JetspeedLinkFactory.getInstance(rundata);
portalResource.setOwner(jsLink.getUserName());
JetspeedLinkFactory.putInstance(jsLink);
}
catch (Exception e)
{
logger.warn(e.toString(), e);
portalResource.setOwner(null);
}
if (!JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(),
portalResource, JetspeedSecurity.PERMISSION_VIEW))
{
if ( logger.isDebugEnabled() )
{
logger.debug("Unauthorized access by user \"" + rundata.getUser().getUserName() + "\"");
}
// Clear any portlets that exist in this set
if (this.portlets != null)
{
this.portlets.clear();
}
return new StringElement(Localization.getString(rundata, "SECURITY_NO_ACCESS"));
}
else
{
if ( logger.isDebugEnabled() )
{
logger.debug("User \"" + rundata.getUser().getUserName() + "\" is authorized to portlet set " + getID());
}
}
if (controller == null)
{
Portlet p = getPortletAt(0);
if (p != null)
{
content = p.getContent(rundata);
}
}
else
{
content = controller.getContent(rundata);
}
if (content == null)
{
content = new ConcreteElement();
}
return content;
}
/**
*/
public String getName()
{
if (name == null)
{
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;
}
/**
*/
public String getDescription()
{
if (getPortletConfig() != null)
{
if (getPortletConfig().getMetainfo() != null)
{
return getPortletConfig().getMetainfo().getDescription();
}
}
return null;
}
/**
* Getter for property description.
* @return Name of portlet description.
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?