jetspeedportaltoolkitservice.java
来自「jetspeed源代码」· Java 代码 · 共 908 行 · 第 1/2 页
JAVA
908 行
// Populate the PortletSet with Portlets
// Entry[] entries = portlets.getEntry();
// for( int i = 0; i < entries.length; ++i )
for (Iterator eit = portlets.getEntriesIterator(); eit.hasNext();)
{
try
{
Entry psmlEntry = (Entry) eit.next();
PortletEntry entry =
(PortletEntry) Registry.getEntry(Registry.PORTLET, psmlEntry.getParent());
if (entry != null)
{
Portlet p = PortletFactory.getPortlet(psmlEntry);
if (p != null)
{
Map constraints = getParameters(psmlEntry.getLayout());
int position = getPosition(psmlEntry.getLayout());
PortletControl control = getControl(psmlEntry.getControl(), entry);
set.addPortlet(
initControl(control, p),
controller.getConstraints(constraints),
position);
}
}
else
{
logger.error(
" The portlet "
+ psmlEntry.getParent()
+ " does not exist in the Registry ");
continue;
}
}
catch (JetspeedException e)
{
logger.error("Exception", e);
continue;
}
}
// Decorate with a control if required and return
if (portlets.getControl() != null)
{
PortletControl control = getControl(portlets.getControl());
return initControl(control, set);
}
set.sortPortletSet();
// Or return the set
return set;
}
/**
* Associates a PortletControl with an existing Portlet and
* returns the Control
*
* @param pc the existing PortletControl
* @param portlet the existing Portlet to be associated with the control
* @return first PortletControl associated with the portlet
*/
protected PortletControl initControl(PortletControl pc, Portlet portlet)
{
if (portlet == null)
{
throw new IllegalArgumentException("Portlet not specified");
}
if (pc == null)
{
throw new IllegalArgumentException("PortletControl not specified");
}
pc.init(portlet);
return pc;
}
/**
Given a PSML Portlets, get the value of what its PortletConfig would be.
@param entry the Portlets containing the config
@return the newly created PortletConfig object
*/
protected PortletConfig getPortletConfig(Portlets portlets)
{
PortletConfig pc = new BasePortletConfig();
pc.setName(portlets.getName());
pc.setInitParameters(getParameters(portlets));
//Invocation of new skin-locating algorithim
pc.setPortletSkin(getSkin(findSkin(portlets)));
pc.setSecurityRef(portlets.getSecurityRef());
pc.setMetainfo(getMetaData(portlets));
return pc;
}
/**
* Fetches the parameters out of a PSML Portlets entry
*
* @param portlets the Portlets entry to check for parameters
* @return a Map containing the parameters names/values, an empty Dictionary
* is returned if there are no parameters
*/
protected static Map getParameters(Portlets portlets)
{
Hashtable hash = new Hashtable();
if (portlets != null)
{
Parameter[] props = portlets.getParameter();
for (int i = 0; i < props.length; ++i)
{
hash.put(props[i].getName(), props[i].getValue());
}
}
return hash;
}
/**
* Retrieves the parameters from a PSML Control object
*
* @param control the PSML object to explore
* @return a Map of the existing control parameters or an empty map
*/
protected static Map getParameters(Control control)
{
Hashtable hash = new Hashtable();
if (control != null)
{
Parameter[] params = control.getParameter();
for (int i = 0; i < params.length; i++)
{
hash.put(params[i].getName(), params[i].getValue());
}
}
return hash;
}
/**
* Retrieves the parameters from a PSML Controller object
*
* @param controller the PSML object to explore
* @return a Map of the existing controller parameters or an empty map
*/
protected static Map getParameters(Controller controller)
{
Hashtable hash = new Hashtable();
if (controller != null)
{
Parameter[] params = controller.getParameter();
for (int i = 0; i < params.length; i++)
{
hash.put(params[i].getName(), params[i].getValue());
}
}
return hash;
}
/**
* Retrieves a parameter Map from an array of PSML Layout object
*
* @param layout the Layout object to use
* @return a Map containing the names/values, an empty map
* is returned if there are no properties
*/
protected static Map getParameters(Layout layout)
{
Hashtable hash = new Hashtable();
if (layout != null)
{
Parameter[] props = layout.getParameter();
for (int i = 0; i < props.length; ++i)
{
hash.put(props[i].getName(), props[i].getValue());
}
}
return hash;
}
/**
* Retrieves a parameter Map from a PSML skin object
*
* @param skin the Skin object to use
* @return a Map containing the names/values, an empty map
* is returned if there are no properties
*/
protected static Map getParameters(Skin skin)
{
Hashtable hash = new Hashtable();
if (skin != null)
{
Parameter[] props = skin.getParameter();
for (int i = 0; i < props.length; ++i)
{
hash.put(props[i].getName(), props[i].getValue());
}
}
return hash;
}
/**
Create a MetaData object from a PSML Metainfo object
@param meta the Metainfo to copy
@return the new MetaData object, empty if meta is null
*/
protected static MetaData getMetaData(Portlets portlets)
{
MetaData data = new MetaData();
MetaInfo meta = portlets.getMetaInfo();
if (meta != null)
{
if (meta.getTitle() != null)
{
data.setTitle(meta.getTitle());
}
if (meta.getDescription() != null)
{
data.setDescription(meta.getDescription());
}
if (meta.getImage() != null)
{
data.setImage(meta.getImage());
}
}
return data;
}
/**
* Get the position value in a Layout object
*
* @param layout the Layout object to use
*
* @return the defined position or -1 if undefined
*/
protected static int getPosition(Layout layout)
{
int pos = -1;
try
{
pos = (int) layout.getPosition();
}
catch (RuntimeException e)
{
// either layout is null or the position isn't an integer
// keep the default value
}
return pos;
}
protected static class VariableInteger
{
int value;
public VariableInteger(int value)
{
this.value = value;
}
public int getValue()
{
return this.value;
}
public void setValue(int value)
{
this.value = value;
}
}
/**
* Given a locator String path, returns a Portlets collecton
*
* @param locatorPath ProfileLocator resource path identifier
* @return a portlets collection from the PSML resource
*/
public Portlets getReference(String locatorPath)
{
ProfileLocator locator = Profiler.createLocator();
locator.createFromPath(locatorPath);
String id = locator.getId();
try
{
Profile profile = Profiler.getProfile(locator);
PSMLDocument doc = profile.getDocument();
if (doc == null)
{
return null;
}
Portlets portlets = doc.getPortlets();
return portlets;
}
catch (Exception e)
{
logger.error("Exception", e);
return null;
}
}
/**
* Helps locate a skin, recursively if neccesary.
* <ul>
* <li>First: return the name of the skin defined for this <code>Portlets</code>
* collection.</li>
* <li> If the this <code>Portlets</code> collection has no skin defined, it's
* parent is checked, then it's parent's parent and so on until either a skin
* is found.</li>
* <li> If the previous two attempts fail the, the system default skin is used</li>
* @param Portlets portlets Portlets collection whose skin needs to be located.
*/
protected String findSkin(Portlets portlets)
{
if (portlets.getSkin() != null)
{
return portlets.getSkin().getName();
}
else if (portlets.getParentPortlets() != null)
{
return findSkin(portlets.getParentPortlets());
}
else
{
return this.defaultSkin;
}
}
/**
* Gets default security ref based on the profile type (user|role|group). Returns
* null if no default is defined.
*
* @param profile
* @return default security reference
*/
public SecurityReference getDefaultSecurityRef(Profile profile)
{
String type = null;
if (profile.getUserName() != null)
{
if (profile.getAnonymous())
{
type = Profiler.PARAM_ANON;
}
else
{
type = Profiler.PARAM_USER;
}
}
else if (profile.getRoleName() != null)
{
type = Profiler.PARAM_ROLE;
}
else if (profile.getGroupName() != null)
{
type = Profiler.PARAM_GROUP;
}
return getDefaultSecurityRef(type);
}
/**
* Gets default security ref based on the profile type (user|role|group). Returns
* null if no default is defined.
*
* @param type of entity to return default security ref for
* @return default security reference
*/
public SecurityReference getDefaultSecurityRef(String type)
{
BaseSecurityReference result = null;
SecurityEntry entry = null;
String defaultRef = null;
if (type.equals(Profiler.PARAM_USER))
{
defaultRef = this.defaultUserSecurityRef;
}
else if (type.equals(Profiler.PARAM_ANON))
{
defaultRef = this.defaultAnonSecurityRef;
}
else if (type.equals(Profiler.PARAM_ROLE))
{
defaultRef = this.defaultRoleSecurityRef;
}
else if (type.equals(Profiler.PARAM_GROUP))
{
defaultRef = this.defaultGroupSecurityRef;
}
if (defaultRef != null)
{
entry = (SecurityEntry) Registry.getEntry(Registry.SECURITY, defaultRef);
if (logger.isDebugEnabled())
{
logger.debug(
"JetspeedPortalToolkit: default security for type: " + type + " is " + defaultRef);
}
if (entry != null)
{
result = new BaseSecurityReference();
result.setParent(entry.getName());
if (logger.isDebugEnabled())
{
logger.debug(
"JetspeedPortalToolkit: default security for type: "
+ type
+ " was set to "
+ entry.getName());
}
}
}
return result;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?