From: <die...@us...> - 2010-02-18 11:53:05
|
Revision: 1984 http://openutils.svn.sourceforge.net/openutils/?rev=1984&view=rev Author: diego_schivo Date: 2010-02-18 11:52:59 +0000 (Thu, 18 Feb 2010) Log Message: ----------- MEDIA-107 Display the number of media for each type after a search Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java 2010-02-18 11:44:49 UTC (rev 1983) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/configuration/MediaConfigurationManager.java 2010-02-18 11:52:59 UTC (rev 1984) @@ -50,11 +50,11 @@ import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModule; import net.sourceforge.openutils.mgnlmedia.media.pages.MediaFolderViewPage; -import net.sourceforge.openutils.mgnlmedia.media.types.MediaTypeHandler; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.lang.StringUtils; +import org.apache.jackrabbit.util.ISO9075; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -348,6 +348,7 @@ * @param type if specified restricts the search to the type * @return found medias * @throws RepositoryException exception working on repository + * @deprecated, use find(String, String, String, boolean) */ @SuppressWarnings("unchecked") public Collection<Content> search(String text, final String type) throws RepositoryException @@ -384,6 +385,44 @@ return c; } + @SuppressWarnings("unchecked") + public Collection<Content> find(String path, String type, String search, boolean recursive) + throws RepositoryException + { + QueryManager qm = MgnlContext.getQueryManager(MediaModule.REPO); + StringBuffer sbQuery = new StringBuffer("/jcr:root/"); + path = StringUtils.removeEnd(StringUtils.removeStart(StringUtils.trimToEmpty(path), "/"), "/"); + if (StringUtils.isNotEmpty(path)) + { + sbQuery.append(ISO9075.encodePath(path)).append('/'); + } + if (recursive) + { + sbQuery.append('/'); + } + sbQuery.append("element(*," + MediaConfigurationManager.MEDIA.getSystemName() + ")"); + List<String> clauses = new ArrayList<String>(); + if (StringUtils.isNotBlank(search)) + { + clauses.add("jcr:contains(.,'" + StringUtils.replace(search, "'", "''") + "')"); + } + if (StringUtils.isNotBlank(type)) + { + clauses.add("@type='" + type + "'"); + } + if (!clauses.isEmpty()) + { + sbQuery.append('[').append(StringUtils.join(clauses, " and ")).append(']'); + } + if (StringUtils.isNotBlank(search)) + { + sbQuery.append(" order by @jcr:score descending"); + } + Query q = qm.createQuery(new String(sbQuery), Query.XPATH); + QueryResult qr = q.execute(); + return qr.getContent(MediaConfigurationManager.MGNL_MEDIA_TYPE); + } + /** * Get the type configuration for a media * @param media media Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java 2010-02-18 11:44:49 UTC (rev 1983) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaFolderViewPage.java 2010-02-18 11:52:59 UTC (rev 1984) @@ -161,7 +161,7 @@ types = MediaConfigurationManager.getInstance().getTypes().values(); } - if (!StringUtils.isBlank(path)) + if (!StringUtils.isBlank(path) || !StringUtils.isBlank(search)) { fillNumberOfMediaPerType(); } @@ -180,19 +180,17 @@ numberOfMedia = new HashMap<String, Integer>(); for (MediaTypeConfiguration mtc : types) { - QueryManager qm = MgnlContext.getQueryManager(MediaModule.REPO); try { - Query q = qm.createQuery( - ISO9075.encodePath(path.substring(1)) + "/*[type='" + mtc.getName() + "']", - Query.XPATH); - QueryResult qr = q.execute(); - - numberOfMedia.put(mtc.getName(), qr.getContent(MediaConfigurationManager.MEDIA.getSystemName()).size()); + Collection<Content> c = MediaConfigurationManager.getInstance().find( + path, + mtc.getName(), + search, + StringUtils.isBlank(path)); + numberOfMedia.put(mtc.getName(), c.size()); } catch (RepositoryException e) { - } } } @@ -235,7 +233,7 @@ writable = false; canPublish = false; - mediasOfType = MediaConfigurationManager.getInstance().search(search, type); + mediasOfType = MediaConfigurationManager.getInstance().find(null, type, search, true); } catch (RepositoryException ex) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |