From: <fg...@us...> - 2010-03-03 23:00:07
|
Revision: 2088 http://openutils.svn.sourceforge.net/openutils/?rev=2088&view=rev Author: fgiust Date: 2010-03-03 22:59:50 +0000 (Wed, 03 Mar 2010) Log Message: ----------- CRIT-7 deep refactoring, trying to merge old and new APIs Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteriaSearchTest.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java Removed Paths: ------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedCriteria.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,55 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-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.mgnlcriteria.advanced; - -import java.util.Collection; - -import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; - - -/** - * @author fgiust - * @version $Id$ - */ -public interface AdvancedCriteria extends Criteria, ExecutableQuery -{ - - AdvancedCriteria setBasePath(String path); - - AdvancedCriteria setWorkspace(String path); - - AdvancedCriteria setSpellCheckString(String path); - - AdvancedCriteria add(Criterion criterion); - - AdvancedCriteria addOrder(Order order); - - /** - * @deprecated list() can't be used for advanced criterias, please use execute() - */ - @Deprecated - Collection< ? > list() throws JCRQueryException; - - AdvancedCriteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); - -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,76 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-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.mgnlcriteria.advanced; - -/** - * @author fgiust - * @version $Id$ - */ -public interface AdvancedResult -{ - - int getItemsPerPage(); - - int getPage(); - - int getTotalSize(); - - int getNumberOfPages(); - - String getSpellCheckerSuggestion(); - - ResultIterator<AdvancedResultItem> getItems(); - - public static AdvancedResult EMPTY_RESULT = new AdvancedResult() - { - - public int getTotalSize() - { - return 0; - } - - public String getSpellCheckerSuggestion() - { - return null; - } - - public int getPage() - { - return 0; - } - - public int getItemsPerPage() - { - return 0; - } - - public ResultIterator<AdvancedResultItem> getItems() - { - // @todo return an empty result - return null; - } - - public int getNumberOfPages() - { - return 0; - } - }; - -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,39 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-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.mgnlcriteria.advanced; - -import info.magnolia.cms.core.Content; - - -/** - * @author fgiust - * @version $Id$ - */ -public interface AdvancedResultItem extends Content -{ - - String getExcerpt(); - - String getExcerpt(String selector); - - double getScore(); - - double getScore(String selector); -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,110 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-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.mgnlcriteria.advanced; - -import info.magnolia.cms.core.HierarchyManager; -import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DirectJcrQuery implements ExecutableQuery -{ - - private HierarchyManager hm; - - private String query; - - private String language; - - private String spellCheckString; - - private int maxResults; - - private int offset; - - /** - * @param hm - * @param query - * @param language - */ - public DirectJcrQuery(HierarchyManager hm, String query, String language) - { - this.hm = hm; - this.query = query; - this.language = language; - } - - /** - * Sets the spellCheckString. - * @param spellCheckString the spellCheckString to set - */ - public DirectJcrQuery setSpellCheckString(String spellCheckString) - { - this.spellCheckString = spellCheckString; - return this; - } - - /** - * Sets the maxResults. - * @param maxResults the maxResults to set - */ - public DirectJcrQuery setMaxResultsPerPage(int maxResults) - { - this.maxResults = maxResults; - return this; - } - - /** - * Sets the offset. - * @param offset the offset to set - */ - public DirectJcrQuery setOffset(int offset) - { - this.offset = offset; - return this; - } - - /** - * Utility method for setting offset easier. If this method is called you should not use setOffset/setMaxResults - * directly anymore. - * @param itemsPerPage - * @param pageNumberStartingFromOne - * @return - */ - public DirectJcrQuery setPaging(int itemsPerPage, int pageNumberStartingFromOne) - { - this.maxResults = itemsPerPage; - this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedResult execute() - { - - return QueryExecutorHelper.execute(query, language, hm, maxResults, offset, spellCheckString); - } - -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,30 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-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.mgnlcriteria.advanced; - -/** - * @author fgiust - * @version $Id$ - */ -public interface ExecutableQuery -{ - - AdvancedResult execute(); -} Deleted: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -1,99 +0,0 @@ -/** - * - * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) - * Copyright(C) 2009-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.mgnlcriteria.advanced; - -import info.magnolia.cms.core.HierarchyManager; - -import javax.jcr.RangeIterator; -import javax.jcr.query.Row; -import javax.jcr.query.RowIterator; - - -/** - * @author fgiust - * @version $Id$ - */ -public abstract class ResultIterator<T> implements RangeIterator -{ - - protected RowIterator rowIterator; - - protected final HierarchyManager hm; - - /** - * @param rowIterator - */ - public ResultIterator(RowIterator rowIterator, HierarchyManager hm) - { - this.rowIterator = rowIterator; - this.hm = hm; - } - - /** - * {@inheritDoc} - */ - public boolean hasNext() - { - return rowIterator.hasNext(); - } - - /** - * {@inheritDoc} - */ - public void remove() - { - rowIterator.remove(); - } - - /** - * {@inheritDoc} - */ - public void skip(long skipNum) - { - rowIterator.skip(skipNum); - } - - /** - * {@inheritDoc} - */ - public long getSize() - { - return rowIterator.getSize(); - } - - /** - * {@inheritDoc} - */ - public long getPosition() - { - return rowIterator.getPosition(); - } - - /** - * {@inheritDoc} - */ - public T next() - { - return wrap(rowIterator.nextRow()); - } - - protected abstract T wrap(Row row); - -} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -19,33 +19,24 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; -import info.magnolia.cms.beans.config.ContentRepository; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.context.MgnlContext; import java.util.Collection; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedCriteria; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -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.xpath.impl.AbstractCriteriaImpl; -import org.apache.commons.lang.StringUtils; - /** * @author fgiust * @version $Id$ */ -public class AdvancedCriteriaImpl extends AbstractCriteriaImpl implements AdvancedCriteria +public class AdvancedCriteriaImpl extends AbstractCriteriaImpl implements Criteria { - private String workspace = ContentRepository.WEBSITE; - - private String spellCheckString; - public AdvancedCriteriaImpl() { // empty @@ -54,79 +45,9 @@ /** * {@inheritDoc} */ - // @todo must be reviewd, cleaned up - public AdvancedCriteria setBasePath(String path) - { - - String finalPath = path; - if (!StringUtils.startsWith(path, Criterion.JCR_ROOT) && !StringUtils.startsWith(path, "//")) - { - finalPath = Criterion.JCR_ROOT + path; - } - if (!StringUtils.contains(finalPath, "*")) - { - finalPath = finalPath + "//*"; - } - - this.path = finalPath; - - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedCriteria setWorkspace(String workspace) - { - this.workspace = workspace; - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedCriteria setSpellCheckString(String spellCheckString) - { - this.spellCheckString = spellCheckString; - return this; - } - - /** - * {@inheritDoc} - */ - public AdvancedCriteria setPaging(int itemsPerPage, int pageNumberStartingFromOne) - { - this.maxResults = itemsPerPage; - this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public AdvancedCriteria add(Criterion expression) - { - super.add(expression); - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public AdvancedCriteria addOrder(Order ordering) - { - super.addOrder(ordering); - return this; - } - - /** - * {@inheritDoc} - */ public Collection< ? > list() throws JCRQueryException { - throw new UnsupportedOperationException("list() is not supported in AdvancedCriteria, please call execute()"); + throw new UnsupportedOperationException("list() is not supported in advanced Criteria, please call execute()"); } /** Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -28,10 +28,10 @@ import javax.jcr.query.Row; import javax.jcr.query.RowIterator; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResult; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.advanced.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; import org.apache.jackrabbit.core.query.lucene.QueryResultImpl; import org.slf4j.Logger; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -28,7 +28,7 @@ import javax.jcr.Value; import javax.jcr.query.Row; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -26,8 +26,8 @@ import javax.jcr.query.Row; import javax.jcr.query.RowIterator; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.advanced.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; /** Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResult.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResult.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,77 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-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.mgnlcriteria.jcr.query; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface AdvancedResult +{ + + int getItemsPerPage(); + + int getPage(); + + int getTotalSize(); + + int getNumberOfPages(); + + String getSpellCheckerSuggestion(); + + ResultIterator<AdvancedResultItem> getItems(); + + public static AdvancedResult EMPTY_RESULT = new AdvancedResult() + { + + public int getTotalSize() + { + return 0; + } + + public String getSpellCheckerSuggestion() + { + return null; + } + + public int getPage() + { + return 0; + } + + public int getItemsPerPage() + { + return 0; + } + + public ResultIterator<AdvancedResultItem> getItems() + { + // @todo return an empty result + return null; + } + + public int getNumberOfPages() + { + return 0; + } + }; + +} Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/AdvancedResultItem.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/AdvancedResultItem.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,39 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-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.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.Content; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface AdvancedResultItem extends Content +{ + + String getExcerpt(); + + String getExcerpt(String selector); + + double getScore(); + + double getScore(String selector); +} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -21,7 +21,6 @@ import java.util.Collection; -import net.sourceforge.openutils.mgnlcriteria.advanced.ExecutableQuery; 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; @@ -156,6 +155,14 @@ @Deprecated Collection< ? > list() throws JCRQueryException; + Criteria setBasePath(String path); + + Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne); + + Criteria setSpellCheckString(String path); + + Criteria setWorkspace(String path); + /** * Returns the generated xpath expression * @return the generated xpath expression Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/DirectJcrQuery.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/DirectJcrQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,110 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-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.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.HierarchyManager; +import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DirectJcrQuery implements ExecutableQuery +{ + + private HierarchyManager hm; + + private String query; + + private String language; + + private String spellCheckString; + + private int maxResults; + + private int offset; + + /** + * @param hm + * @param query + * @param language + */ + public DirectJcrQuery(HierarchyManager hm, String query, String language) + { + this.hm = hm; + this.query = query; + this.language = language; + } + + /** + * Sets the spellCheckString. + * @param spellCheckString the spellCheckString to set + */ + public DirectJcrQuery setSpellCheckString(String spellCheckString) + { + this.spellCheckString = spellCheckString; + return this; + } + + /** + * Sets the maxResults. + * @param maxResults the maxResults to set + */ + public DirectJcrQuery setMaxResultsPerPage(int maxResults) + { + this.maxResults = maxResults; + return this; + } + + /** + * Sets the offset. + * @param offset the offset to set + */ + public DirectJcrQuery setOffset(int offset) + { + this.offset = offset; + return this; + } + + /** + * Utility method for setting offset easier. If this method is called you should not use setOffset/setMaxResults + * directly anymore. + * @param itemsPerPage + * @param pageNumberStartingFromOne + * @return + */ + public DirectJcrQuery setPaging(int itemsPerPage, int pageNumberStartingFromOne) + { + this.maxResults = itemsPerPage; + this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; + return this; + } + + /** + * {@inheritDoc} + */ + public AdvancedResult execute() + { + + return QueryExecutorHelper.execute(query, language, hm, maxResults, offset, spellCheckString); + } + +} Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ExecutableQuery.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ExecutableQuery.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,31 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-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.mgnlcriteria.jcr.query; + + +/** + * @author fgiust + * @version $Id$ + */ +public interface ExecutableQuery +{ + + AdvancedResult execute(); +} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -21,8 +21,6 @@ import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.util.DeprecationUtil; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedCriteria; -import net.sourceforge.openutils.mgnlcriteria.advanced.DirectJcrQuery; import net.sourceforge.openutils.mgnlcriteria.advanced.impl.AdvancedCriteriaImpl; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl.MagnoliaCriteriaImpl; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl.MagnoliaCriteriaWithLimitImpl; @@ -39,7 +37,7 @@ { } - public static AdvancedCriteria createAdvancedCriteria() + public static Criteria createCriteria() { return new AdvancedCriteriaImpl(); } @@ -58,10 +56,13 @@ * @param queryManager - an instance of info.magnolia.cms.core.search.QueryManager * @param itemType String - if not specified defaults to "mgnl:content" * @return a factory for Magnolia CMS specific Criteria implementation + * @deprecated please use createCriteria() */ + @Deprecated public static Criteria createMgnlCriteria(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType) { + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaImpl(path, queryManager, itemType); } @@ -75,10 +76,13 @@ * @param itemType String - if not specified defaults to "mgnl:content" * @param clazz Class<?> - the list method of this implementation must return instances of this type * @return a factory for Magnolia CMS specific Criteria implementation + * @deprecated please use createCriteria() */ + @Deprecated public static Criteria createMgnlCriteria(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType, Class< ? > clazz) { + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaImpl(path, queryManager, itemType, clazz); } @@ -98,13 +102,13 @@ * @param queryManager - an instance of info.magnolia.cms.core.search.QueryManager * @param itemType String - if not specified defaults to "mgnl:content" * @return a factory for Magnolia CMS specific Criteria implementation - * @deprecated if you need paging/query limits please use createAdvancedCriteria() + * @deprecated please use createCriteria() */ @Deprecated public static Criteria createMgnlCriteriaWithLimit(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType) { - DeprecationUtil.isDeprecated("please use createAdvancedCriteria() instead"); + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaWithLimitImpl(path, queryManager, itemType); } @@ -125,14 +129,14 @@ * @param itemType String - if not specified defaults to "mgnl:content" * @param clazz Class<?> - the list method of this implementation must return instances of this type * @return a factory for Magnolia CMS specific Criteria implementation - * @deprecated if you need paging/query limits please use createAdvancedCriteria() + * @deprecated please use createCriteria() */ @Deprecated public static Criteria createMgnlCriteriaWithLimit(String path, info.magnolia.cms.core.search.QueryManager queryManager, String itemType, Class< ? > clazz) { - DeprecationUtil.isDeprecated("please use createAdvancedCriteria() instead"); + DeprecationUtil.isDeprecated("please use createCriteria() instead"); return new MagnoliaCriteriaWithLimitImpl(path, queryManager, itemType, clazz); } Copied: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java (from rev 2079, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/ResultIterator.java) =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/ResultIterator.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -0,0 +1,99 @@ +/** + * + * Magnolia Criteria API (http://www.openmindlab.com/lab/products/mgnlcriteria.html) + * Copyright(C) 2009-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.mgnlcriteria.jcr.query; + +import info.magnolia.cms.core.HierarchyManager; + +import javax.jcr.RangeIterator; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; + + +/** + * @author fgiust + * @version $Id$ + */ +public abstract class ResultIterator<T> implements RangeIterator +{ + + protected RowIterator rowIterator; + + protected final HierarchyManager hm; + + /** + * @param rowIterator + */ + public ResultIterator(RowIterator rowIterator, HierarchyManager hm) + { + this.rowIterator = rowIterator; + this.hm = hm; + } + + /** + * {@inheritDoc} + */ + public boolean hasNext() + { + return rowIterator.hasNext(); + } + + /** + * {@inheritDoc} + */ + public void remove() + { + rowIterator.remove(); + } + + /** + * {@inheritDoc} + */ + public void skip(long skipNum) + { + rowIterator.skip(skipNum); + } + + /** + * {@inheritDoc} + */ + public long getSize() + { + return rowIterator.getSize(); + } + + /** + * {@inheritDoc} + */ + public long getPosition() + { + return rowIterator.getPosition(); + } + + /** + * {@inheritDoc} + */ + public T next() + { + return wrap(rowIterator.nextRow()); + } + + protected abstract T wrap(Row row); + +} Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/BetweenExpression.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -24,6 +24,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; + /** * @author fgrilli * @version $Id$ @@ -58,17 +59,20 @@ fragment.append(" (").append(propertyName).append(" >= "); if (lo instanceof String && hi instanceof String) + { fragment.append("'" + lo + "' and " + propertyName + " <= '" + hi + "'"); + } else if (lo instanceof Number && hi instanceof Number) + { fragment.append(lo + " and " + propertyName + " <= " + hi); + } else if (lo instanceof Calendar && hi instanceof Calendar) { Calendar cal = (Calendar) lo; Calendar cal2 = (Calendar) hi; StringBuilder date = new StringBuilder(); date.append(XS_DATETIME_FUNCTION + "('"); - date - .append(cal.get(Calendar.YEAR)) + date.append(cal.get(Calendar.YEAR)) .append(HYPHEN) .append( cal.get(Calendar.MONTH) < MONTH_MAX Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Conjunction.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -25,6 +25,7 @@ */ public class Conjunction extends Junction { + private static final long serialVersionUID = 7590346442271897522L; public Conjunction() Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Criterion.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -19,7 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion; - import java.io.Serializable; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; @@ -41,33 +40,33 @@ public interface Criterion extends Serializable { - public static final Logger log = LoggerFactory.getLogger(Criterion.class); + Logger log = LoggerFactory.getLogger(Criterion.class); - public static final String ATTRIBUTE_SELECTOR = "@"; + String ATTRIBUTE_SELECTOR = "@"; - public static final String JCR_PREFIX = "jcr:"; + String JCR_PREFIX = "jcr:"; - public static final String JCR_ROOT = "/jcr:root"; + String JCR_ROOT = "/jcr:root"; - public static final String ALL_ELEMENTS = "//*"; + String ALL_ELEMENTS = "//*"; - public static final String ANY_PROPERTY = "."; + String ANY_PROPERTY = "."; - public static final String XS_DATETIME_FUNCTION = "xs:dateTime"; + String XS_DATETIME_FUNCTION = "xs:dateTime"; - public static final String MIDNIGHT = "T00:00:00.000+00:00"; + String MIDNIGHT = "T00:00:00.000+00:00"; - public static final String T235959 = "T23:59:59.000+00:00"; + String T235959 = "T23:59:59.000+00:00"; - public static final String NT_BASE = "nt:base"; + String NT_BASE = "nt:base"; - public static final String NOT = " not("; + String NOT = " not("; - public static final String HYPHEN = "-"; + String HYPHEN = "-"; - public static final int DAY_MAX = 10; + int DAY_MAX = 10; - public static final int MONTH_MAX = 9; + int MONTH_MAX = 9; /** * Render the XPath fragment Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/Disjunction.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -25,6 +25,7 @@ */ public class Disjunction extends Junction { + private static final long serialVersionUID = 1573336261639362776L; protected Disjunction() Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/InExpression.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -52,7 +52,9 @@ inClause.append(containsPredicate); // if this is not the last value, append an 'or' if ((i + 1) != values.length) + { inClause.append(" or "); + } } inClause.append(") "); return inClause.toString(); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/criterion/LikeExpression.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -38,7 +38,9 @@ { super(propertyName, value, function); if (matchMode == null) + { throw new IllegalArgumentException("MatchMode can't be null"); + } this.matchMode = matchMode; } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -19,11 +19,17 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl; +import info.magnolia.cms.beans.config.ContentRepository; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.context.MgnlContext; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.TranslatableCriteria; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; @@ -32,6 +38,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.XPathSelect; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,8 +55,6 @@ protected String path = Criterion.JCR_ROOT; - protected String itemType; - protected Class< ? > classType; protected List<CriterionEntry> criterionEntries = new ArrayList<CriterionEntry>(); @@ -60,13 +65,21 @@ protected int offset = 0; - protected Integer timeout; + protected HierarchyManager hm; - protected String comment; + protected String spellCheckString; + protected String workspace = ContentRepository.WEBSITE; + protected AbstractCriteriaImpl() { + + } + + protected AbstractCriteriaImpl(HierarchyManager hm) + { super(); + this.hm = hm; } public Collection<CriterionEntry> getCriterionEntries() @@ -119,25 +132,37 @@ return this; } - public Integer getTimeout() + /** + * {@inheritDoc} + */ + public Criteria setBasePath(String path) { - return timeout; + this.path = StringUtils.defaultIfEmpty(path, "//*"); + return this; } - public Criteria setTimeout(int timeout) + /** + * {@inheritDoc} + */ + public Criteria setSpellCheckString(String spellCheckString) { - this.timeout = timeout; + this.spellCheckString = spellCheckString; return this; } - public String getComment() + /** + * {@inheritDoc} + */ + public Criteria setWorkspace(String workspace) { - return comment; + this.workspace = workspace; + return this; } - public Criteria setComment(String comment) + public Criteria setPaging(int itemsPerPage, int pageNumberStartingFromOne) { - this.comment = comment; + this.maxResults = itemsPerPage; + this.offset = (Math.max(pageNumberStartingFromOne, 1) - 1) * maxResults; return this; } @@ -155,4 +180,17 @@ return stmt; } + /** + * {@inheritDoc} + */ + public AdvancedResult execute() + { + + String language = javax.jcr.query.Query.XPATH; + String stmt = toXpathExpression(); + + return QueryExecutorHelper.execute(stmt, language, this.hm != null ? this.hm : MgnlContext + .getHierarchyManager(workspace), maxResults, offset, spellCheckString); + } + } \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -23,10 +23,7 @@ import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.ItemType; import info.magnolia.cms.core.search.QueryManager; -import net.sourceforge.openutils.mgnlcriteria.advanced.AdvancedResult; -import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; import org.apache.commons.lang.StringUtils; @@ -38,11 +35,23 @@ public abstract class AbstractMagnoliaCriteriaImpl extends AbstractCriteriaImpl { + @Deprecated protected info.magnolia.cms.core.search.QueryManager queryManager; + @Deprecated + protected String itemType; + /** + * @param hm + */ + public AbstractMagnoliaCriteriaImpl(HierarchyManager hm) + { + super(hm); + } + + /** * Constructor to be used by subclasses - * @param path String - the path preceeding the predicate in the jcr query statement (you dont need to do escaping + * @param path String - the path preceding the predicate in the jcr query statement (you dont need to do escaping * yourself) * @param queryManager - an instance of {@link QueryManager} * @param itemType - String the itemType. Defaults to {@link ItemType#getSystemName#toString()} @@ -50,7 +59,8 @@ */ protected AbstractMagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) { - super(); + + super(getPrivateHierarchyManagerFromQuery(queryManager)); if (StringUtils.isBlank(itemType)) { this.itemType = ItemType.CONTENT.getSystemName(); @@ -59,32 +69,14 @@ { this.itemType = itemType; } - this.path = XPathTextUtils.encodeDigitsInPath(path); + this.path = path; this.queryManager = queryManager; // defaults to info.magnolia.cms.core.Content this.classType = classType == null ? Content.class : classType; } - /** - * {@inheritDoc} - */ - public AdvancedResult execute() + protected static HierarchyManager getPrivateHierarchyManagerFromQuery(QueryManager queryManager) { - - String language = javax.jcr.query.Query.XPATH; - String stmt = toXpathExpression(); - - return QueryExecutorHelper.execute( - stmt, - language, - getPrivateHierarchyManagerFromQuery(stmt), - maxResults, - offset, - null); - } - - private HierarchyManager getPrivateHierarchyManagerFromQuery(String stmt) - { java.lang.reflect.Field field; try { @@ -95,9 +87,7 @@ } catch (Throwable e) { - - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); + throw new JCRQueryException("getting hierarchyManager", e); } } Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -20,6 +20,7 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl; import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.core.search.Query; import info.magnolia.cms.core.search.QueryManager; import info.magnolia.cms.core.search.QueryResult; @@ -48,17 +49,28 @@ protected static final String EXCEPTION_MSG = "An error occurred while executing a query. Xpath query was {}. Exception message is {}"; + @Deprecated public MagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType) { super(path, queryManager, itemType, null); } + @Deprecated public MagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) { super(path, queryManager, itemType, classType); } + /** + * @param hm + */ + public MagnoliaCriteriaImpl(HierarchyManager hm) + { + super(hm); + } + @SuppressWarnings("unchecked") + @Deprecated public Collection< ? > list() throws JCRQueryException { DeprecationUtil.isDeprecated("please use execute() instead"); Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-03-03 07:55:14 UTC (rev 2087) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-03-03 22:59:50 UTC (rev 2088) @@ -47,6 +47,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.JCRMagnoliaCriteriaQueryTranslator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.XPathSelect; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.utils.XPathTextUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -64,7 +65,7 @@ * @version $Id$ */ @Deprecated -public class MagnoliaCriteriaWithLimitImpl extends AbstractMagnoliaCriteriaImpl +public class MagnoliaCriteriaWithLimitImpl extends MagnoliaCriteriaImpl { /** @@ -76,17 +77,28 @@ private static final String QUERY_MANAGER = "queryManager"; + @Deprecated public MagnoliaCriteriaWithLimitImpl(String path, QueryManager queryManager, String itemType) { super(path, queryManager, itemType, null); } + @Deprecated public MagnoliaCriteriaWithLimitImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) { super(path, queryManager, itemType, classType); } + /** + * @param hm + */ + public MagnoliaCriteriaWithLimitImpl(HierarchyMan... [truncated message content] |