From: <fg...@us...> - 2010-05-11 20:05:42
|
Revision: 2394 http://openutils.svn.sourceforge.net/openutils/?rev=2394&view=rev Author: fgiust Date: 2010-05-11 20:05:35 +0000 (Tue, 11 May 2010) Log Message: ----------- MEDIA-106 advanced search: first import Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.java Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchFormPage.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchPage.java Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.java 2010-05-11 19:53:42 UTC (rev 2393) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.java 2010-05-11 20:05:35 UTC (rev 2394) @@ -28,6 +28,9 @@ import javax.jcr.RepositoryException; +import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.Option; +import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.SearchFilterAbstract; + import org.apache.commons.lang.StringUtils; @@ -94,7 +97,12 @@ .getHierarchyManager("config") .getContent(reference) .getChildren(); - Option opt; + + Option opt = new Option(); + opt.setValue(""); + opt.setLabel("---"); + addOptions(opt); + for (Content content : referenceOptions) { opt = new Option(); Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchFormPage.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchFormPage.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchFormPage.java 2010-05-11 20:05:35 UTC (rev 2394) @@ -0,0 +1,61 @@ +/** + * + * Magnolia SimpleMedia Module (http://www.openmindlab.com/lab/products/media.html) + * Copyright (C)2008 - 2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmedia.media.pages; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.configuration.SearchMediaQueryConfiguration; +import net.sourceforge.openutils.mgnlmedia.media.lifecycle.MediaModule; + + +/** + * Page that renders the folder view + * @author molaschi + * @version $Id$ + */ +public class MediaAdvancedSearchFormPage extends MediaFolderViewPage +{ + + protected SearchMediaQueryConfiguration configuration; + + /** + * @param name + * @param request + * @param response + */ + public MediaAdvancedSearchFormPage(String name, HttpServletRequest request, HttpServletResponse response) + { + super(name, request, response); + + configuration = MediaModule.getSearchConfiguration(); + + } + + /** + * Returns the configuration. + * @return the configuration + */ + public SearchMediaQueryConfiguration getConfiguration() + { + return configuration; + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchFormPage.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchPage.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchPage.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchPage.java 2010-05-11 20:05:35 UTC (rev 2394) @@ -0,0 +1,433 @@ +/** + * + * Magnolia SimpleMedia Module (http://www.openmindlab.com/lab/products/media.html) + * Copyright (C)2008 - 2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmedia.media.pages; + +import info.magnolia.cms.exchange.ActivationManagerFactory; +import info.magnolia.cms.security.Permission; +import info.magnolia.cms.util.RequestFormUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.jcr.RepositoryException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.configuration.SearchMediaQueryConfiguration; +import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; +import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaTypeConfiguration; +import net.sourceforge.openutils.mgnlmedia.media.tags.el.MediaEl; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import freemarker.ext.beans.BeansWrapper; +import freemarker.template.TemplateHashModel; +import freemarker.template.TemplateMethodModel; +import freemarker.template.TemplateModelException; + + +/** + * Page that renders the folder view + * @author molaschi + * @version $Id$ + */ +public class MediaAdvancedSearchPage extends MediaAdvancedSearchFormPage +{ + + private Logger log = LoggerFactory.getLogger(MediaAdvancedSearchPage.class); + + private static final String VIEW_RESULTS = "-results"; + + private static final String VIEW_RESULTS_XML = "-results-xml"; + + private TemplateMethodModel getStatic = new GetStaticMethodModel(); + + private String queryString; + + private String format; + + private AdvancedResult contentMediaDetails; + + private String selectTab; + + // Pirelli pagination + private int page = 1; // Numero di pagina + + private int items = 100; // Items per page + + // Path di ricerca + private String path; + + /** + * @param name + * @param request + * @param response + */ + public MediaAdvancedSearchPage(String name, HttpServletRequest request, HttpServletResponse response) + { + super(name, request, response); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings({"unchecked", "deprecation" }) + @Override + protected void populateFromRequest(Object bean) + { + RequestFormUtil requestFormUtil = new RequestFormUtil(this.getRequest()); + Map<String, Object> parameters = new HashMap<String, Object>(); // needed, can't directly modify the map + // returned by request.getParameterMap() + + // FIX: siccome arriva da un virtual uri mapping, i parametri originali non sono nella query string e quindi non + // posso usare il requestFormUtil.getParam... che fa un parsing custom della querystring + parameters.putAll(request.getParameterMap()); + parameters.putAll(requestFormUtil.getDocuments()); // handle uploaded files too + + try + { + BeanUtils.populate(bean, parameters); + } + catch (Exception e) + { + log.error("can't set properties on the handler", e); + } + } + + public String show() + { + + // @todo defaultBasePath handling only on xml requests? + if ("xml".equals(format)) + { + contentMediaDetails = configuration.search(request, null, "media", "nt:base", items, page); + } + else + { + contentMediaDetails = configuration.search(request, "/", "media", "nt:base"); + } + + setMedias(new ArrayList<MediaBean>(contentMediaDetails.getTotalSize())); + + setNumberOfMedia(new HashMap<String, Integer>()); + + selectTab = StringUtils.trimToEmpty(selectTab); + if (StringUtils.isNotBlank(selectTab)) + { + setType(selectTab); + } + + ResultIterator<AdvancedResultItem> items = contentMediaDetails.getItems(); + + // @todo don't do this, all the search should be laxy + while (items.hasNext()) + { + AdvancedResultItem media = items.next(); + + MediaTypeConfiguration mtc = MediaConfigurationManager.getInstance().getMediaTypeConfigurationFromMedia( + media); + + if (mtc != null) + { + getNumberOfMedia().put(mtc.getName(), MapUtils.getInteger(getNumberOfMedia(), mtc.getName(), 0) + 1); + + if (!"xml".equals(format) && (StringUtils.isBlank(getType()) || getType().equals(mtc.getName()))) + { + MediaBean mb = new MediaBean(); + + mb.setContent(media); + mb.setMetaData(media.getMetaData()); + mb.setHandle(media.getHandle()); + mb.setFilename(mtc.getHandler().getFilename(media)); + mb.setTitle(mtc.getHandler().getTitle(media)); + mb.setThumbnailUrl(mtc.getHandler().getThumbnailUrl(media)); + mb.setPreviewUrl(mtc.getHandler().getPreviewUrl(media)); + mb.setDescription(mtc.getHandler().getDescription(media)); + mb.setUuid(media.getUUID()); + + try + { + mb.setWritable(media.getParent().isGranted(Permission.WRITE)); + mb.setCanPublish(!MediaEl.module().isSingleinstance() + && mb.isWritable() + && ActivationManagerFactory.getActivationManager().hasAnyActiveSubscriber()); + + mb.getUsedInWebPages().addAll( + MediaConfigurationManager.getInstance().getUsedInWebPages(media.getUUID())); + } + catch (RepositoryException ex) + { + log.error("Exception caught", ex); + } + + mb.setMediaInfo(mtc.getHandler().getMediaInfo(media)); + mb.setExternal(mtc.getHandler().isExternal(media)); + + try + { + mb.setWritable(media.getParent().isGranted(Permission.WRITE)); + mb.getUsedInWebPages().addAll( + MediaConfigurationManager.getInstance().getUsedInWebPages(media.getUUID())); + } + catch (RepositoryException ex) + { + log.error(ex.getMessage(), ex); + log.error("Going on after exception"); + } + getMedias().add(mb); + } + } + } + + StringBuilder qs = new StringBuilder(); + for (String key : (Set<String>) request.getParameterMap().keySet()) + { + if (!"type".equals(key)) + { + if (request.getParameterMap().get(key).getClass().isArray()) + { + for (String value : (String[]) request.getParameterMap().get(key)) + { + if ("command".equals(key)) + { + continue; + } + if (qs.length() > 0) + { + qs.append("&"); + } + qs.append(key).append("=").append(value); + } + } + else + { + qs.append(key).append("=").append(request.getParameter(key)); + } + } + } + queryString = qs.toString(); + + setSearch(queryString); + if (!StringUtils.isNotBlank(selectTab)) + { + selectTab = getType(); + } + + if (StringUtils.isNotBlank(format) && "xml".equals(format)) + { + this.response.setContentType("text/xml"); + return VIEW_RESULTS_XML; + } + return VIEW_RESULTS; + } + + /** + * Returns the getStatic. + * @return the getStatic + */ + public TemplateMethodModel getGetStatic() + { + return getStatic; + } + + public class GetStaticMethodModel implements TemplateMethodModel + { + + /** + * {@inheritDoc} + */ + @Override + public Object exec(List arguments) throws TemplateModelException + { + if (arguments != null && arguments.size() > 0) + { + BeansWrapper wrapper = BeansWrapper.getDefaultInstance(); + TemplateHashModel staticModel = wrapper.getStaticModels(); + return staticModel.get((String) arguments.get(0)); + } + return null; + } + + } + + /** + * Returns the queryString. + * @return the queryString + */ + public String getQueryString() + { + return queryString; + } + + /** + * Sets the queryString. + * @param queryString the queryString to set + */ + public void setQueryString(String queryString) + { + this.queryString = queryString; + } + + /** + * Returns the format. + * @return the format + */ + public String getFormat() + { + return format; + } + + /** + * Sets the format. + * @param format the format to set + */ + public void setFormat(String format) + { + this.format = format; + } + + /** + * Returns the contentMediaDetails. + * @return the contentMediaDetails + */ + public AdvancedResult getContentMediaDetails() + { + return contentMediaDetails; + } + + /** + * Sets the contentMediaDetails. + * @param contentMediaDetails the contentMediaDetails to set + */ + public void setContentMediaDetails(AdvancedResult contentMediaDetails) + { + this.contentMediaDetails = contentMediaDetails; + } + + /** + * Returns the configuration. + * @return the configuration + */ + public SearchMediaQueryConfiguration getConfiguration() + { + return configuration; + } + + /** + * Sets the configuration. + * @param configuration the configuration to set + */ + public void setConfiguration(SearchMediaQueryConfiguration configuration) + { + this.configuration = configuration; + } + + /** + * Sets the getStatic. + * @param getStatic the getStatic to set + */ + public void setGetStatic(TemplateMethodModel getStatic) + { + this.getStatic = getStatic; + } + + /** + * Returns the selectTab. + * @return the selectTab + */ + public String getSelectTab() + { + return selectTab; + } + + /** + * Sets the selectTab. + * @param selectTab the selectTab to set + */ + public void setSelectTab(String selectTab) + { + this.selectTab = selectTab; + } + + /** + * Returns the page. + * @return the page + */ + public int getPage() + { + return page; + } + + /** + * Sets the page. + * @param page the page to set + */ + public void setPage(int page) + { + this.page = page; + } + + /** + * Returns the items. + * @return the items + */ + public int getItems() + { + return items; + } + + /** + * Sets the items. + * @param items the items to set + */ + public void setItems(int items) + { + this.items = items; + } + + /** + * Returns the path. + * @return the path + */ + public String getPath() + { + return path; + } + + /** + * Sets the path. + * @param path the path to set + */ + public void setPath(String path) + { + this.path = path; + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MediaAdvancedSearchPage.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |