📄 basejetspeedlink.java
字号:
}
/**
* Add a portlet reference in the link.
*
* Note: This must be used with caution, since a portlet may exist may times
* in a PSML. setPortletById() is the perfered method.
*
* @param portletName the name of the portlet to link to
* @return a DynamicURI referencing the named portlet
*/
public DynamicURI getPortletByName(String portletName)
{
return getLink(JetspeedLink.CURRENT, null, this.getPageName(), JetspeedLink.PORTLET_NAME, portletName, null, null, null, null, null);
}
/**
* Return a link to a default page for the role
*
* @param role Desired role
* @return DynamicURI that to the desired page
*/
public DynamicURI getRole(String role)
{
return getLink(JetspeedLink.ROLE, role, "", JetspeedLink.DEFAULT, null, null, null, null, null, null);
}
/**
* Return a link to a desired page for the role
*
* @param role Desired role
* @param page Desired page
* @return DynamicURI that to the desired page
*/
public DynamicURI getRole(String role, String page)
{
return getLink(JetspeedLink.ROLE, role, page, JetspeedLink.DEFAULT, null, null, null, null, null, null);
}
/**
* Return a link to the template.
*
* @param template to add to link
* @return DynamicURI to specific portlet
*/
public DynamicURI getTemplate(String template)
{
return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.DEFAULT, null, null, template, null, null, null);
}
/**
* Return a link to a default page for the user
*
* @param user Desired user
* @return DynamicURI that to the desired page
*/
public DynamicURI getUser(String user)
{
return getLink(JetspeedLink.USER, user, "", JetspeedLink.DEFAULT, null, null, null, null, null, null);
}
/**
* Return a link to a desired page for the user
*
* @param page Desired page
* @param user Desired user
* @return DynamicURI that to the desired page
*/
public DynamicURI getUser(String user, String page)
{
return getLink(JetspeedLink.USER, user, page, JetspeedLink.DEFAULT, null, null, null, null, null, null);
}
private void initLink()
{
if (initDone == true)
{
return;
}
try
{
// get the profile that is set in the rundata
profile = rundata.getProfile();
// if there was no profile, try making one from the rundata
if (profile == null)
{
// this would only happen if the JetspeedAccessController didn't get a chance
// to setup the rundata...
profile = Profiler.getProfile(rundata);
rundata.setProfile(profile);
logger.warn("BaseJetspeedLink: profile in rundata was null");
}
}
catch (ProfileException e)
{
logger.error("Exception", e);
}
if (profile != null)
{
// Get ProfileLocator for path info.
if ((profile instanceof ProfileLocator) == true)
{
locator = (ProfileLocator) profile;
}
}
initDone = true;
}
/**
* Return a link to the root portlet or pane
*
* @throws ProfileException if the profile detects an error
* @return URI to the root portlet/pane
*/
private DynamicURI getRoot() throws ProfileException
{
DynamicURI uri = null;
initLink();
if (locator != null)
{
uri = Profiler.makeDynamicURI(rundata, locator);
}
if (uri == null)
{
uri = new DynamicURI(rundata);
}
// check if we need to force to a secure (https) link
if (JetspeedResources.getBoolean("force.ssl", false))
{
uri.setSecure();
}
return uri;
}
/**
* Return a URL, as a string, the the root page or pane.
*
* @return a URL, as a string, the the root page or pane.
*/
public String toString()
{
try
{
return getRoot().toString();
}
catch (ProfileException e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return the action key. Used by velocity templates, i.e. $jlink.ActionKey
*
* @return the action parameter name
*/
public String getActionKey()
{
return JetspeedResources.PATH_ACTION_KEY;
}
/**
* Is the PSML for the anonymous user?
*
* @return True = PSML is for the anonymous user
*/
public boolean getAnonymous()
{
initLink();
try
{
return locator.getAnonymous();
}
catch (Exception e)
{
logger.error("Exception", e);
return true;
}
}
/**
* Return country of the PSML file
*
* @return Country of PSML, or null if no country
*/
public String getCountry()
{
initLink();
try
{
return locator.getCountry();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return Group name of the PSML file
*
* @return Group name of PSML, or null if no Group name
*/
public String getGroupName()
{
initLink();
try
{
return locator.getGroupName();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return Language of the PSML file
*
* @return Language of PSML, or null if no Language
*/
public String getLanguage()
{
initLink();
try
{
return locator.getLanguage();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return Media Type of the PSML file
*
* @return Media Type of PSML, or null if no Media Type
*/
public String getMediaType()
{
initLink();
try
{
return locator.getMediaType();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return Page name of the PSML file
*
* @return Page name of PSML, or null if no Page name
*/
public String getPageName()
{
initLink();
try
{
return locator.getName();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return Role name of the PSML file
*
* @return Role name of PSML, or null if no Role name
*/
public String getRoleName()
{
initLink();
try
{
return locator.getRoleName();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Return User name of the PSML file
*
* @return User name of PSML, or null if no User name
*/
public String getUserName()
{
initLink();
try
{
return locator.getUserName();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* The following methods used by Velocity to get value of constants
*/
public static int getCURRENT()
{
return JetspeedLink.CURRENT;
}
public static int getDEFAULT()
{
return JetspeedLink.DEFAULT;
}
public static int getGROUP()
{
return JetspeedLink.GROUP;
}
public static int getPANE_ID()
{
return JetspeedLink.PANE_ID;
}
public static int getPANE_NAME()
{
return JetspeedLink.PANE_NAME;
}
public static int getPORTLET_ID()
{
return JetspeedLink.PORTLET_ID;
}
public static int getPORTLET_NAME()
{
return JetspeedLink.PORTLET_NAME;
}
public static int getROLE()
{
return JetspeedLink.ROLE;
}
public static int getUSER()
{
return JetspeedLink.USER;
}
public static String getDEFAULT_PAGE()
{
return "";
}
/**
* deprecated methods from JetspeedTemplateLink.
*/
/**
* <p> Set the portlet giving context to this Link object.</p>
*
* This method is from JetspeedTemplateLink and is only here
* for backward compatibility. This it should not be used for
* any new development. Also any problems with this method will
* not be fixed
*
* @param portlet the name of the active portlet
* @deprecated the name is confusing. Use @see(#forPaneById()) instead.
*/
public void setPortlet(Portlet portlet)
{
this.activePortlet = portlet;
}
/**
* Add a portlet reference in the link.
*
* Note: This must be used with caution, since a portlet may exist may times
* in a PSML. setPortletById() is the perfered method.
*
* @param portletName the name of the portlet to link to
* @return a DynamicURI referencing the named portlet for easy link construction in template
*/
public DynamicURI setPortletByName(String portletName)
{
DynamicURI uri = null;
try
{
uri = getRoot();
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
if ((portletName != null) && (portletName.length() > 0))
{
uri.addPathInfo(JetspeedResources.PATH_PORTLET_KEY, portletName);
}
return uri;
}
/**
* Methods required by ApplictionTool interface
*
*/
/**
* This will initialise a JetspeedLink object that was
* constructed with the default constructor (ApplicationTool
* method).
*
* @param data assumed to be a RunData object
*/
public void init(Object data)
{
// Keeping init small and fast
if (data instanceof JetspeedRunData)
{
this.rundata = (JetspeedRunData) data;
}
else
{
this.rundata = null;
}
profile = null;
locator = null;
initDone = false;
return;
}
/**
* Refresh method - does nothing
*/
public void refresh()
{
// empty
}
public DynamicURI setMediaType(String mediaType)
{
return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.DEFAULT, null, null, null, mediaType);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -