📄 abstractportlet.java
字号:
*/
public String getDescription() {
if (getPortletConfig()!=null)
if (getPortletConfig().getMetainfo()!=null)
return getPortletConfig().getMetainfo().getDescription();
return null;
}
/**
* Provide a Description within PML if the user has specified one.
*
* @return a null if entry AND portlet have not defined a description
*/
public String getDescription(String instanceDescription)
{
if (instanceDescription != null)
return instanceDescription;
return getDescription();
}
/**
*/
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;
}
/**
* Provide a title within PML if the user has specified one.
*
* @return a null if entry AND portlet have not defined a title
*/
public String getTitle(String instanceTitle)
{
if (instanceTitle != null)
return instanceTitle;
return getTitle();
}
/**
* Set the title for this Portlet.
* @param title Portlet title.
*/
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);
}
/**
* Getter for property image.
* @return Name of portlet image, icon. The name is expected to be in the form of a URL.
*/
public String getImage()
{
if (getPortletConfig()!=null)
if (getPortletConfig().getMetainfo()!=null)
return getPortletConfig().getMetainfo().getImage();
return null;
}
/**
* Getter for property image.
* @return a null if entry AND portlet have not defined an icon.
*/
public String getImage(String instanceImage)
{
if (instanceImage != null)
return instanceImage;
return getImage();
}
public void setImage( String image )
{
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.setImage(image);
}
/**
* Is the portled editable/customizeable.
* @param rundata The RunData object for the current request
* @return <CODE>true</CODE> Editing is allow
* <CODE>false</CODE> Editing is NOT alowed
*/
public boolean getAllowEdit( RunData rundata )
{
return allowCustomize(rundata);
}
/**
* Is the portled viewable.
* @param rundata The RunData object for the current request
* @return <CODE>true</CODE> Viewing is allow
* <CODE>false</CODE> Viewing is NOT alowed
*
* Override this method to control your own View behavior
*/
public boolean getAllowView( RunData rundata )
{
return allowView( rundata );
}
/**
* Can this portlet be maximized
* @param rundata The RunData object for the current request
* @return <CODE>true</CODE> Portlet can be maximized<br>
* <CODE>false</CODE> Portlet can NOT be maximized
*/
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();
}
/**
*/
public long getCreationTime() {
return this.creationTime;
}
/**
*/
public void setCreationTime( long creationTime ) {
this.creationTime = creationTime;
}
/**
*/
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 );
}
/*
* Implement methods required by PortletState
*/
/**
* Implements the default close behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowClose( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return !isClosed( rundata );
}
/**
* Returns true if this portlet is currently closed
*
* @param rundata The RunData object for the current request
*/
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 rundata The RunData object for the current request
*/
public void setClosed(boolean close, RunData rundata)
{
if( allowClose( rundata ) )
{
this.setAttribute("_display", close ? "closed" : "normal", rundata );
}
}
/**
* Implements the default info behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowInfo( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return true;
}
/**
* Implements the default customize behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowCustomize( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return true;
}
/**
* Implements the default maximize behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowMaximize( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return true;
}
/**
* Implements the default info behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowMinimize( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return true;
}
/**
* Implements the default view behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowView( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return true;
}
/**
* Implements the default print friendly format behavior:
* security permissions will be checked.
*
* @param rundata The RunData object for the current request
*/
public boolean allowPrintFriendly( RunData rundata )
{
//Security will not allow this call to succeed if there are
//not enough permissions
return true;
}
/**
* Returns true if this portlet is currently minimized
*
* @param rundata The RunData object for the current request
*/
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 The RunData object for the current request
*/
public void setMinimized( boolean minimize, RunData rundata )
{
if( allowMinimize( rundata ) )
{
this.setAttribute("_display", minimize ? "minimized" : "normal", rundata );
}
}
/**
* Returns TRUE if the title bar in should be displayed. The title bar includes
* the portlet title and action buttons. This
*
* @param rundata The RunData object for the current request
*/
public boolean isShowTitleBar(RunData rundata)
{
if (getPortletConfig()!=null)
{
// Parameter can exist in PSML or <portlet-entry>
return Boolean.valueOf(getPortletConfig().getInitParameter("_showtitlebar","true")).booleanValue();
}
return this.getAttribute("_showtitlebar", "true", rundata ).equals("true");
}
// utility methods
/**
* Retrieve a portlet attribute from persistent storage
*
* @param attrName The attribute to retrieve
* @param attrDefValue The value if the attr doesn't exists
* @param rundata The RunData object for the current request
* @return The attribute value
*/
public String getAttribute( String attrName, String attrDefValue, RunData rundata )
{
String attrValue = null ;
PortletInstance instance = PersistenceManager.getInstance(this, rundata);
attrValue = instance.getAttribute(attrName, attrDefValue);
return attrValue;
}
/**
* Stores a portlet attribute in persistent storage
*
* @param attrName The attribute to retrieve
* @paarm attrValue The value to store
* @param rundata The RunData object for the current request
*/
public void setAttribute( String attrName, String attrValue, RunData rundata )
{
try
{
PortletInstance instance = PersistenceManager.getInstance(this, rundata);
instance.setAttribute(attrName, attrValue);
PersistenceManager.store(instance);
}
catch (PortalPersistenceException e)
{
logger.error("Exception while setting attribute "+attrName+" for portlet "+getName(), e);
}
}
/**
* Gets the portlet instance associated with this portlet.
*
* @param rundata The RunData object for the current request
* @return PortletInstance
*/
public PortletInstance getInstance(RunData rundata)
{
return PersistenceManager.getInstance(this, rundata);
}
//
// DST: Shouldn't getID and setID be deprecated and added to PortletInstance...
//
public String getID()
{
return id;
}
public void setID(String id)
{
this.id = id;
}
/**
* @return true if the portlet does its own customization
*/
public boolean providesCustomization()
{
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -