Skip to content

Commit

Permalink
Fixing exception handling while generating search result resources list.
Browse files Browse the repository at this point in the history
Conflicts:
	src/org/opencms/workplace/search/CmsSearchResourcesCollector.java
  • Loading branch information
tHerrmann committed Feb 20, 2014
1 parent 2875f2c commit a6d450e
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/org/opencms/workplace/search/CmsSearchResourcesCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.search.CmsSearch;
import org.opencms.search.CmsSearchParameters;
import org.opencms.search.CmsSearchResult;
Expand All @@ -41,12 +42,14 @@
import org.opencms.workplace.list.CmsListItem;
import org.opencms.workplace.list.I_CmsListResourceCollector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;

/**
* Collector for receiving CmsResources from a search result set.<p>
*
Expand Down Expand Up @@ -173,28 +176,34 @@ public List<String> getCollectorNames() {
return Arrays.asList(COLLECTOR_NAME);
}

/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsSearchResourcesCollector.class);

/**
* @see org.opencms.workplace.list.A_CmsListResourceCollector#getResources(org.opencms.file.CmsObject, java.util.Map)
*/
@Override
public List<CmsResource> getResources(CmsObject cms, Map<String, String> params) throws CmsException {
public List<CmsResource> getResources(CmsObject cms, Map<String, String> params) {

List<CmsSearchResult> result = getSearchResults(params);
int count = getSearchBean(params).getSearchResultCount();
CmsResource[] resources = new CmsResource[count];
int from = (getSearchBean(params).getSearchPage() - 1) * getSearchBean(params).getMatchesPerPage();
int siteLen = cms.getRequestContext().getSiteRoot().length();

Iterator<CmsSearchResult> it = result.iterator();
while (it.hasNext()) {
CmsSearchResult sr = it.next();
CmsResource resource = cms.readResource(sr.getPath().substring(siteLen), CmsResourceFilter.ALL);
m_resCache.put(resource.getStructureId().toString(), resource);
m_srCache.put(resource.getStructureId().toString(), sr);
resources[from] = resource;
from++;
List<CmsResource> resources = new ArrayList<CmsResource>();
String siteRoot = cms.getRequestContext().getSiteRoot();
int siteLen = siteRoot.length();
for (CmsSearchResult sr : result) {
try {
String resultPath = sr.getPath();
if (resultPath.startsWith(siteRoot)) {
resultPath = sr.getPath().substring(siteLen);
}
CmsResource resource = cms.readResource(resultPath, CmsResourceFilter.ALL);
m_resCache.put(resource.getStructureId().toString(), resource);
m_srCache.put(resource.getStructureId().toString(), sr);
resources.add(resource);
} catch (CmsException e) {
LOG.warn(e.getLocalizedMessage(), e);
}
}
return Arrays.asList(resources);
return resources;
}

/**
Expand Down Expand Up @@ -226,7 +235,7 @@ public void setPage(int page) {
* @see org.opencms.workplace.list.A_CmsListResourceCollector#getInternalResources(org.opencms.file.CmsObject, java.util.Map)
*/
@Override
protected List<CmsResource> getInternalResources(CmsObject cms, Map<String, String> params) throws CmsException {
protected List<CmsResource> getInternalResources(CmsObject cms, Map<String, String> params) {

synchronized (this) {
if (m_resources == null) {
Expand Down

0 comments on commit a6d450e

Please sign in to comment.