}
int beginIndex = NumberUtils.toInt(beginIndexParam, -1);
int maxResults = NumberUtils.toInt(maxResultsParam, -1);
PortletApplicationBeanCollection paBeans = new PortletApplicationBeanCollection();
paBeans.setBeginIndex(beginIndex);
paBeans.setTotalSize(0);
List<PortletApplicationBean> paBeanList = new ArrayList<PortletApplicationBean>();
if (!StringUtils.isBlank(queryParam))
{
String queryText =
ParsedObject.FIELDNAME_TYPE + ":\"" + ParsedObject.OBJECT_TYPE_PORTLET_APPLICATION + "\" AND ( " + queryParam + " )";
SearchResults searchResults = searchEngine.search(queryText);
List<ParsedObject> searchResultList = searchResults.getResults();
paBeans.setTotalSize(searchResultList.size());
for (ParsedObject parsedObject : (List<ParsedObject>) PaginationUtils.subList(searchResultList, beginIndex, maxResults))
{
String appName = SearchEngineUtils.getFieldAsString(parsedObject, "ID", null);
if (StringUtils.isBlank(appName))
{
continue;
}
PortletApplication pa = portletRegistry.getPortletApplication(appName);
if (pa != null)
{
paBeanList.add(new PortletApplicationBean(pa));
}
}
}
else
{
if (StringUtils.isBlank(applicationName))
{
Collection<PortletApplication> pas = portletRegistry.getPortletApplications();
paBeans.setTotalSize(pas.size());
for (PortletApplication pa : (Collection<PortletApplication>) PaginationUtils.subCollection(pas, beginIndex, maxResults))
{
paBeanList.add(new PortletApplicationBean(pa));
}
}
else
{
PortletApplication pa = portletRegistry.getPortletApplication(applicationName, true);
if (pa != null)
{
paBeans.setTotalSize(1);
paBeanList.add(new PortletApplicationBean(pa));
}
}
}
paBeans.setApplications(paBeanList);
return paBeans;
}