}
int beginIndex = NumberUtils.toInt(beginIndexParam, -1);
int maxResults = NumberUtils.toInt(maxResultsParam, -1);
PortletDefinitionBeanCollection pdBeans = new PortletDefinitionBeanCollection();
pdBeans.setBeginIndex(beginIndex);
pdBeans.setTotalSize(0);
List<PortletDefinitionBean> pdBeanList = new ArrayList<PortletDefinitionBean>();
if (!StringUtils.isBlank(keywordsParam) || !StringUtils.isBlank(queryParam))
{
String queryText =
ParsedObject.FIELDNAME_TYPE + ":\"" + ParsedObject.OBJECT_TYPE_PORTLET + "\" " +
"AND NOT " + ParsedObject.FIELDNAME_TYPE + ":\"" + ParsedObject.OBJECT_TYPE_PORTLET_APPLICATION + "\" " +
"AND ( " + (!StringUtils.isBlank(keywordsParam) ? keywordsParam : queryParam) + " )";
SearchResults searchResults = null;
if (!StringUtils.isBlank(keywordsParam))
{
searchResults = searchEngine.search(queryText, ParsedObject.FIELDNAME_KEYWORDS);
}
else
{
searchResults = searchEngine.search(queryText);
}
List<ParsedObject> searchResultList = searchResults.getResults();
ArrayList<PortletDefinition> searchedPortletDefinitions = new ArrayList<PortletDefinition>();
for (ParsedObject parsedObject : searchResultList)
{
String uniqueName = SearchEngineUtils.getPortletUniqueName(parsedObject);
if (StringUtils.isBlank(uniqueName))
{
continue;
}
PortletDefinition pd = portletRegistry.getPortletDefinitionByUniqueName(uniqueName);
if (pd != null && securityAccessController.checkPortletAccess(pd, JetspeedActions.MASK_VIEW))
{
searchedPortletDefinitions.add(pd);
}
}
Collection<PortletDefinition> filteredPortletDefinitions = filterPortletDefinitionsBySecurityAccess(searchedPortletDefinitions, JetspeedActions.MASK_VIEW, servletRequest);
pdBeans.setTotalSize(filteredPortletDefinitions.size());
for (PortletDefinition pd : (Collection<PortletDefinition>) PaginationUtils.subCollection(filteredPortletDefinitions, beginIndex, maxResults))
{
pdBeanList.add(new PortletDefinitionBean(pd));
}
}
else
{
if (StringUtils.isBlank(applicationName) && StringUtils.isBlank(definitionName))
{
Collection<PortletDefinition> pds = filterPortletDefinitionsBySecurityAccess(portletRegistry.getAllDefinitions(), JetspeedActions.MASK_VIEW, servletRequest);
pdBeans.setTotalSize(pds.size());
for (PortletDefinition pd : (Collection<PortletDefinition>) PaginationUtils.subCollection(pds, beginIndex, maxResults))
{
pdBeanList.add(new PortletDefinitionBean(pd));
}
}
else
{
PortletApplication pa = portletRegistry.getPortletApplication(applicationName, true);
if (pa != null)
{
if (StringUtils.isBlank(definitionName))
{
Collection<PortletDefinition> pds = filterPortletDefinitionsBySecurityAccess(pa.getPortlets(), JetspeedActions.MASK_VIEW, servletRequest);
pdBeans.setTotalSize(pds.size());
for (PortletDefinition pd : (List<PortletDefinition>) PaginationUtils.subCollection(pds, beginIndex, maxResults))
{
pdBeanList.add(new PortletDefinitionBean(pd));
}
}
else
{
PortletDefinition pd = pa.getPortlet(definitionName);
if (pd == null)
{
pd = pa.getClone(definitionName);
}
if (pd != null && securityAccessController.checkPortletAccess(pd, JetspeedActions.MASK_VIEW))
{
pdBeanList.add(new PortletDefinitionBean(pd));
pdBeans.setTotalSize(1);
}
}
}
}
}
pdBeans.setDefinitions(pdBeanList);
return pdBeans;
}