From: <fg...@us...> - 2010-05-11 19:45:37
|
Revision: 2391 http://openutils.svn.sourceforge.net/openutils/?rev=2391&view=rev Author: fgiust Date: 2010-05-11 19:45:29 +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/lifecycle/MediaModule.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/Option.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilter.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterAbstract.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterBeetweenCreationDate.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterEmpty.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterInMultivalue.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterMultiplevalue.java 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/SearchFilterSpecFieldMedia.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterStatus.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterText.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/configuration/ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/configuration/SearchMediaQueryConfiguration.java Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/Option.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/Option.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/Option.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,70 @@ +package net.sourceforge.openutils.mgnlmedia.media.advancedsearch; + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class Option +{ + + private String label; + + private String value; + + private Boolean defaultValue; + + /** + * Returns the label. + * @return the label + */ + public String getLabel() + { + return label; + } + + /** + * Sets the label. + * @param label the label to set + */ + public void setLabel(String label) + { + this.label = label; + } + + /** + * Returns the value. + * @return the value + */ + public String getValue() + { + return value; + } + + /** + * Sets the value. + * @param value the value to set + */ + public void setValue(String value) + { + this.value = value; + } + + /** + * Returns the defaultValue. + * @return the defaultValue + */ + public Boolean getDefaultValue() + { + return defaultValue; + } + + /** + * Sets the defaultValue. + * @param defaultValue the defaultValue to set + */ + public void setDefaultValue(Boolean defaultValue) + { + this.defaultValue = defaultValue; + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/Option.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/advancedsearch/SearchFilter.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilter.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilter.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,37 @@ +/** + * + * 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.advancedsearch; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public interface SearchFilter +{ + + List<Criterion> getCriterionList(String parameter, HttpServletRequest request); +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilter.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/advancedsearch/SearchFilterAbstract.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterAbstract.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterAbstract.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,112 @@ +/** + * + * 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.advancedsearch; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; + +import org.apache.commons.collections.ListUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterAbstract implements SearchFilter +{ + + /** + * Logger. + */ + protected Logger log = LoggerFactory.getLogger(SearchFilterAbstract.class); + + private Map<String, SearchFilter> subfilters = new LinkedHashMap<String, SearchFilter>(); + + private String control; + + private String label; + + /** + * Returns the subfilters. + * @return the subfilters + */ + public Map<String, SearchFilter> getSubfilters() + { + return subfilters; + } + + public void addSubfilters(String name, SearchFilter subfilter) + { + subfilters.put(name, subfilter); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public List<Criterion> getCriterionList(String parameter, HttpServletRequest request) + { + return ListUtils.EMPTY_LIST; + } + + /** + * Returns the type. + * @return the type + */ + public String getControl() + { + return control; + } + + /** + * Sets the type. + * @param type the type to set + */ + public void setControl(String type) + { + this.control = type; + } + + /** + * Returns the label. + * @return the label + */ + public String getLabel() + { + return label; + } + + /** + * Sets the label. + * @param label the label to set + */ + public void setLabel(String label) + { + this.label = label; + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterAbstract.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/advancedsearch/SearchFilterBeetweenCreationDate.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterBeetweenCreationDate.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterBeetweenCreationDate.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,139 @@ +/** + * + * 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.advancedsearch; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterBeetweenCreationDate extends SearchFilterAbstract +{ + + private static final String META_DATA_MGNL_CREATIONDATE = "MetaData/@mgnl:creationdate"; + + private Calendar from; + + private Calendar to; + + /** + * {@inheritDoc} + */ + @Override + public List<Criterion> getCriterionList(String parameter, HttpServletRequest request) + { + String[] values = (String[]) request.getParameterMap().get(parameter); + List<Criterion> criterionList = new ArrayList<Criterion>(); + + if (values != null && values.length > 0 && StringUtils.isNotBlank(values[0])) + { + Criterion c; + // From + from = getDate(values[0]); + c = Restrictions.gt(META_DATA_MGNL_CREATIONDATE, from); + if (MapUtils.isNotEmpty(getSubfilters())) + { + String key = getSubfilters().keySet().iterator().next(); + values = (String[]) request.getParameterMap().get(key); + if (StringUtils.isNotBlank(values[0])) + { + to = getDate(values[0]); + c = Restrictions.between(META_DATA_MGNL_CREATIONDATE, from, to); + } + } + criterionList.add(c); + } + return criterionList; + + } + + private Calendar getDate(String date) + { + Calendar cal = Calendar.getInstance(); + + Pattern datePattern = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2})"); + Matcher dateMatcher = datePattern.matcher(date); + + try + { + if (dateMatcher.find()) + { + cal.set(Integer.parseInt(dateMatcher.group(1)), Integer.parseInt(dateMatcher.group(2)), Integer + .parseInt(dateMatcher.group(3))); + } + } + catch (Exception e) + { + log.error("Invalid date: {}", date); + } + + return cal; + } + + /** + * Returns the from. + * @return the from + */ + public Calendar getFrom() + { + return from; + } + + /** + * Sets the from. + * @param from the from to set + */ + public void setFrom(Calendar from) + { + this.from = from; + } + + /** + * Returns the to. + * @return the to + */ + public Calendar getTo() + { + return to; + } + + /** + * Sets the to. + * @param to the to to set + */ + public void setTo(Calendar to) + { + this.to = to; + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterBeetweenCreationDate.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/advancedsearch/SearchFilterEmpty.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterEmpty.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterEmpty.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,29 @@ +/** + * + * 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.advancedsearch; + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterEmpty extends SearchFilterAbstract +{ + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterEmpty.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/advancedsearch/SearchFilterInMultivalue.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterInMultivalue.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterInMultivalue.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,74 @@ +/** + * + * 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.advancedsearch; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterInMultivalue extends SearchFilterOptionProvider +{ + + /** + * {@inheritDoc} + */ + @Override + public List<Criterion> getCriterionList(String parameter, HttpServletRequest request) + { + String[] values = (String[]) request.getParameterMap().get(parameter); + List<Criterion> criterionList = new ArrayList<Criterion>(); + + if (values != null) + { + for (String value : values) + { + if (StringUtils.isNotBlank(value)) + { + criterionList.add(Restrictions.contains(parameter, value)); + } + } + if (criterionList.size() > 1) + { + // put criterionList on or + Criterion c = Restrictions.or(criterionList.get(0), criterionList.get(1)); + for (int i = 2; i < criterionList.size(); i++) + { + c = Restrictions.or(c, criterionList.get(i)); + } + criterionList.removeAll(criterionList); + criterionList.add(c); + } + } + + return criterionList; + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterInMultivalue.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/advancedsearch/SearchFilterMultiplevalue.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterMultiplevalue.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterMultiplevalue.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,72 @@ +/** + * + * 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.advancedsearch; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterMultiplevalue extends SearchFilterOptionProvider +{ + + /** + * {@inheritDoc} + */ + @Override + public List<Criterion> getCriterionList(String parameter, HttpServletRequest request) + { + String[] values = (String[]) request.getParameterMap().get(parameter); + List<Criterion> criterionList = new ArrayList<Criterion>(); + if (values != null) + { + for (String value : values) + { + if (StringUtils.isNotBlank(value)) + { + criterionList.add(Restrictions.eq("@" + parameter, value)); + } + } + if (criterionList.size() > 1) + { + // put criterionList on or + Criterion c = Restrictions.or(criterionList.get(0), criterionList.get(1)); + for (int i = 2; i < criterionList.size(); i++) + { + c = Restrictions.or(c, criterionList.get(i)); + } + criterionList.removeAll(criterionList); + criterionList.add(c); + } + } + return criterionList; + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterMultiplevalue.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/advancedsearch/SearchFilterOptionProvider.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,114 @@ +/** + * + * 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.advancedsearch; + +import info.magnolia.cms.core.Content; +import info.magnolia.context.MgnlContext; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.jcr.RepositoryException; + +import org.apache.commons.lang.StringUtils; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterOptionProvider extends SearchFilterAbstract +{ + + private List<Option> options = new ArrayList<Option>(); + + private String reference; + + /** + * Returns the options. + * @return the options + */ + public List<Option> getOptions() + { + return options; + } + + /** + * Sets the options. + * @param options the options to set + */ + public void addOptions(Option option) + { + options.add(option); + } + + /** + * Returns the reference. + * @return the reference + */ + public String getReference() + { + return reference; + } + + /** + * Sets the reference. + * @param reference the reference to set + */ + public void setReference(String reference) + { + this.reference = reference; + + getOptionsFormReference(reference); + + } + + /** + * @param reference + */ + private void getOptionsFormReference(String reference) + { + if (StringUtils.isNotBlank(reference)) + { + try + { + Collection<Content> referenceOptions = MgnlContext + .getHierarchyManager("config") + .getContent(reference) + .getChildren(); + Option opt; + for (Content content : referenceOptions) + { + opt = new Option(); + opt.setLabel(content.getNodeData("label").getString()); + opt.setValue(content.getName()); + addOptions(opt); + } + } + catch (RepositoryException e) + { + // do nothing + log.error("Errore reference node on SearchFilterOptionProvider, {}", e); + } + } + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterOptionProvider.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/advancedsearch/SearchFilterSpecFieldMedia.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterSpecFieldMedia.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterSpecFieldMedia.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,59 @@ +/** + * + * 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.advancedsearch; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; +import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaTypeConfiguration; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterSpecFieldMedia extends SearchFilterMultiplevalue +{ + + /** + * {@inheritDoc} + */ + @Override + public List<Option> getOptions() + { + if (super.getOptions().size() > 0) + { + return super.getOptions(); + } + List<Option> options = new ArrayList<Option>(); + Map<String, MediaTypeConfiguration> mediatype = MediaConfigurationManager.getInstance().getTypes(); + Option option; + for (String media : mediatype.keySet()) + { + option = new Option(); + option.setValue(media); + option.setLabel(mediatype.get(media).getLabel()); + options.add(option); + } + return options; + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterSpecFieldMedia.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/advancedsearch/SearchFilterStatus.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterStatus.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterStatus.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,64 @@ +/** + * + * 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.advancedsearch; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; + +import org.apache.commons.lang.StringUtils; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterStatus extends SearchFilterOptionProvider +{ + + private static final String META_DATA_MGNL_ACTIVATED = "MetaData/@mgnl:activated"; + + /** + * {@inheritDoc} + */ + @Override + public List<Criterion> getCriterionList(String parameter, HttpServletRequest request) + { + String[] values = (String[]) request.getParameterMap().get(parameter); + List<Criterion> criterionList = new ArrayList<Criterion>(); + if (values != null && values.length > 0 && StringUtils.isNotBlank(values[0])) + { + if (!values[0].equals("ALL") && "PUB".equals(values[0])) + { + criterionList.add(Restrictions.eq(META_DATA_MGNL_ACTIVATED, "true")); + + } + if(!values[0].equals("ALL") && "NOTPUB".equals(values[0])) + { + criterionList.add(Restrictions.eq(META_DATA_MGNL_ACTIVATED, false)); + } + } + return criterionList; + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterStatus.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/advancedsearch/SearchFilterText.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterText.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterText.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,88 @@ +/** + * + * 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.advancedsearch; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchFilterText extends SearchFilterAbstract +{ + + /** + * {@inheritDoc} + */ + @Override + public List<Criterion> getCriterionList(String parameter, HttpServletRequest request) + { + String fullTextSearch; + String[] values = (String[]) request.getParameterMap().get(parameter); + + List<Criterion> criterionList = new ArrayList<Criterion>(); + + if (values != null && values.length > 0) + { + fullTextSearch = values[0]; + if (MapUtils.isNotEmpty(getSubfilters()) && StringUtils.isNotBlank(fullTextSearch)) + { + for (String key : getSubfilters().keySet()) + { + values = request.getParameterValues(key); + if (values != null) + { + for (String name : values) + { + criterionList.add(Restrictions.contains("@" + name, fullTextSearch)); + } + if (criterionList.size() > 1) + { + // put criterionList on or + Criterion c = Restrictions.or(criterionList.get(0), criterionList.get(1)); + for (int i = 2; i < criterionList.size(); i++) + { + c = Restrictions.or(c, criterionList.get(i)); + } + criterionList.removeAll(criterionList); + criterionList.add(c); + } + } + } + } + + if (StringUtils.isNotBlank(fullTextSearch)) + { + criterionList.add(Restrictions.contains(".", fullTextSearch)); + } + } + return criterionList; + } +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/SearchFilterText.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/advancedsearch/configuration/SearchMediaQueryConfiguration.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/configuration/SearchMediaQueryConfiguration.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/configuration/SearchMediaQueryConfiguration.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -0,0 +1,142 @@ +/** + * + * 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.advancedsearch.configuration; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; +import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.SearchFilter; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author cstrappazzon + * @version $Id$ + */ +public class SearchMediaQueryConfiguration +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(SearchMediaQueryConfiguration.class); + + private Map<String, SearchFilter> filters = new LinkedHashMap<String, SearchFilter>(); + + private String defaultBasePath; + + private int maxresults = 10000; + + /** + * Returns the filters. + * @return the filters + */ + public Map<String, SearchFilter> getFilters() + { + return filters; + } + + public void addFilter(String name, SearchFilter filter) + { + filters.put(name, filter); + } + + /** + * Sets the defaultBasePath. + * @param defaultBasePath the defaultBasePath to set + */ + public void setDefaultBasePath(String defaultBasePath) + { + this.defaultBasePath = defaultBasePath; + } + + /** + * Sets the maxresults. + * @param maxresults the maxresults to set + */ + public void setMaxresults(int maxresults) + { + this.maxresults = maxresults; + } + + /** + * {@inheritDoc} + */ + public AdvancedResult search(HttpServletRequest request, String basePath, String repository, String itemType) + { + return search(request, basePath, repository, itemType, maxresults, 1); + } + + public AdvancedResult search(HttpServletRequest request, String basePath, String repository, String itemType, + int itemsPerPage, int pageNumberStartingFromOne) + { + + StringBuilder sb = new StringBuilder(); + if (basePath == null) + { + // use default + sb.append("/").append(defaultBasePath).append("//*"); + } + if (StringUtils.isBlank(basePath) || basePath.equals("/")) + { + sb.append("//*"); + } + else + { + sb.append("/").append(basePath).append("//*"); + } + + Criteria c = JCRCriteriaFactory.createCriteria(); + + c.setBasePath(sb.toString()); + c.setWorkspace(repository); + + c.setPaging(itemsPerPage, pageNumberStartingFromOne); + c.addOrder(Order.desc("@jcr:score")); + + List<Criterion> criterionList = new ArrayList<Criterion>(); + for (String key : filters.keySet()) + { + criterionList = filters.get(key).getCriterionList(key, request); + for (Criterion criterion : criterionList) + { + c.add(criterion); + } + } + // set type + c.add(Restrictions.eq("@jcr:primaryType", "mgnl:media")); + + return c.execute(); + } + +} Property changes on: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/advancedsearch/configuration/SearchMediaQueryConfiguration.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java 2010-05-11 19:14:51 UTC (rev 2390) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/lifecycle/MediaModule.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -22,6 +22,7 @@ import info.magnolia.module.ModuleLifecycle; import info.magnolia.module.ModuleLifecycleContext; import info.magnolia.module.ModuleRegistry; +import net.sourceforge.openutils.mgnlmedia.media.advancedsearch.configuration.SearchMediaQueryConfiguration; import net.sourceforge.openutils.mgnlmedia.media.configuration.ImageProcessorsManager; import net.sourceforge.openutils.mgnlmedia.media.configuration.MediaConfigurationManager; @@ -54,6 +55,8 @@ private String version; + private SearchMediaQueryConfiguration search; + /** * Constructor */ @@ -137,4 +140,27 @@ return version; } + /** + * Returns the searchConfiguration. + * @return the searchConfiguration + */ + public SearchMediaQueryConfiguration getSearch() + { + return search; + } + + /** + * Sets the searchConfiguration. + * @param searchConfiguration the searchConfiguration to set + */ + public void setSearch(SearchMediaQueryConfiguration search) + { + this.search = search; + } + + public static SearchMediaQueryConfiguration getSearchConfiguration() + { + return ((MediaModule) ModuleRegistry.Factory.getInstance().getModuleInstance(NAME)).getSearch(); + } + } Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java 2010-05-11 19:14:51 UTC (rev 2390) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/pages/MessagesTemplatedMVCHandler.java 2010-05-11 19:45:29 UTC (rev 2391) @@ -19,11 +19,24 @@ package net.sourceforge.openutils.mgnlmedia.media.pages; +import freemarker.ext.beans.BeansWrapper; +import freemarker.template.TemplateHashModel; +import freemarker.template.TemplateMethodModel; +import freemarker.template.TemplateModelException; +import info.magnolia.cms.i18n.Messages; +import info.magnolia.cms.util.RequestFormUtil; +import info.magnolia.module.admininterface.TemplatedMVCHandler; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import info.magnolia.cms.i18n.Messages; -import info.magnolia.module.admininterface.TemplatedMVCHandler; +import org.apache.commons.beanutils.BeanUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -35,6 +48,13 @@ { /** + * Logger. + */ + protected Logger log = LoggerFactory.getLogger(getClass()); + + protected TemplateMethodModel getStatic = new GetStaticMethodModel(); + + /** * @param name * @param request * @param response @@ -53,4 +73,57 @@ return super.getMsgs(); } + /** + * Override the standard method in order to use request.getParameterMap instead of + * requestFormUtils.getParamenterMap() since the latter doesn't work with virtual URI + */ + @SuppressWarnings("unchecked") + @Override + protected void populateFromRequest(Object bean) + { + RequestFormUtil requestFormUtil = new RequestFormUtil(this.getRequest()); + Map<String, Object> parameters = new HashMap<String, Object>(); + + // FIX: use request.getParameterMap instead of requestFormUtils.getParamenterMap() + 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); + } + } + + /** + * Returns the getStatic. + * @return the getStatic + */ + public TemplateMethodModel getGetStatic() + { + return getStatic; + } + + public static class GetStaticMethodModel implements TemplateMethodModel + { + + /** + * {@inheritDoc} + */ + @SuppressWarnings({"cast" }) + public Object exec(List arguments) throws TemplateModelException + { + if (arguments != null && arguments.size() > 0) + { + BeansWrapper wrapper = BeansWrapper.getDefaultInstance(); + TemplateHashModel staticModel = wrapper.getStaticModels(); + return (TemplateHashModel) staticModel.get((String) arguments.get(0)); + } + return null; + } + } + } Modified: trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2010-05-11 19:14:51 UTC (rev 2390) +++ trunk/openutils-mgnlmedia/src/main/resources/net/sourceforge/openutils/mgnlmedia/media/pages/MediaBrowserPage.html 2010-05-11 19:45:29 UTC (rev 2391) @@ -96,8 +96,8 @@ items:[ { region:'west', + xtype: 'tabpanel', id:'west-panel', - title:'${this.msgs.get('tree.media.folders')}', split:true, width: 240, minSize: 175, @@ -106,7 +106,6 @@ margins:'0 0 0 0', padding: 0, expandOnShow: true, - contentEl: 'mediaTreeView', floatable: true, frame: false, border: false, @@ -114,7 +113,16 @@ hideBorders: true, animCollapse:false, animFloat: false, - stateful: true + stateful: true, + deferredRender:false, + activeTab:0, + items:[{ + contentEl:'mediaTreeView', + title: 'Browse' + },{ + contentEl:'advancedSearchView', + title: 'Search' + }] }, centerItem ] @@ -123,6 +131,7 @@ // FF 3.6 patch setTimeout(function() { frames['mediaTreeView'].location.href = getTreeUrl(); + frames['advancedSearchView'].location.href = "${this.request.contextPath}/.magnolia/pages/media-advsearchform.html?selectMedia="+selectMedia; }, 100); if (openPath != null && openPath != "null" && openPath.length > 0) @@ -276,9 +285,11 @@ </head> <body> <iframe id="mediaTreeView" name="mediaTreeView" class="x-panel-body" src="" - style="width:100%;height:100%;border: none;margin:0;padding:0px;" frameborder="0" scrolling="no"></iframe> + style="width:100%; height:100%; border:0 none; margin:0; padding:0;" frameborder="0" scrolling="no"></iframe> + <iframe id="advancedSearchView" name="advancedSearchView" class="x-panel-body" + src="" style="width:100%; height:100%; border:0 none; margin:0; padding:0; overflow:auto;" frameborder="0" scrolling="no"></iframe> <iframe id="mediaFolderView" name="mediaFolderView" class="x-panel-body" src="" - style="width:100%;height:100%;border:none; overflow:auto" frameborder="0" scrolling="auto"></iframe> + style="width:100%; height:100%; border:0 none; overflow:auto;" frameborder="0" scrolling="auto"></iframe> <div id="formDiv" style="display:none"> <form class="formToSubmit" action="" enctype="multipart/form-data" method="post"> <input type="hidden" name="command" value="saveZip" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |