From: <fg...@us...> - 2010-08-29 16:00:29
|
Revision: 2933 http://openutils.svn.sourceforge.net/openutils/?rev=2933&view=rev Author: fgiust Date: 2010-08-29 16:00:21 +0000 (Sun, 29 Aug 2010) Log Message: ----------- CRIT-23 Remove deprecated API Modified Paths: -------------- trunk/openutils-mgnlcriteria/pom.xml trunk/openutils-mgnlcriteria/src/main/assembly/assembly-bundle.xml trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.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/xpath/impl/AbstractCriteriaImpl.java trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java Removed Paths: ------------- 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 Modified: trunk/openutils-mgnlcriteria/pom.xml =================================================================== --- trunk/openutils-mgnlcriteria/pom.xml 2010-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/pom.xml 2010-08-29 16:00:21 UTC (rev 2933) @@ -1,4 +1,5 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>net.sourceforge.openutils</groupId> @@ -115,7 +116,7 @@ <dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> - <version>2.0</version> + <version>${jcr.version}</version> </dependency> <dependency> <groupId>org.apache.jackrabbit</groupId> @@ -169,7 +170,7 @@ <properties> <magnolia.version>4.3.6</magnolia.version> <jackrabbit.version>1.6.2</jackrabbit.version> - <jcr.version>1.0</jcr.version> + <jcr.version>2.0</jcr.version> </properties> <!-- test running maven with -Djcr.version=2.0 -Djackrabbit.version=2.0.0 -Djcr.version=2.0 -Djackrabbit.version=2.1.0 --> </project> \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/assembly/assembly-bundle.xml =================================================================== --- trunk/openutils-mgnlcriteria/src/main/assembly/assembly-bundle.xml 2010-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/assembly/assembly-bundle.xml 2010-08-29 16:00:21 UTC (rev 2933) @@ -29,6 +29,8 @@ <outputDirectory>bin</outputDirectory> <includes> <include>net.sourceforge.openutils:*</include> + <include>cglib:*</include> + <include>javax.jcr:*</include> </includes> </dependencySet> </dependencySets> 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedCriteriaImpl.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -19,9 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; -import java.util.Collection; - -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; import net.sourceforge.openutils.mgnlcriteria.jcr.query.xpath.impl.AbstractCriteriaImpl; @@ -32,11 +29,4 @@ public class AdvancedCriteriaImpl extends AbstractCriteriaImpl { - /** - * {@inheritDoc} - */ - public Collection< ? > list() throws JCRQueryException - { - throw new UnsupportedOperationException("list() is not supported in advanced Criteria, please call execute()"); - } } 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/Criteria.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -19,8 +19,6 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; -import java.util.Collection; - import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Criterion; import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Order; @@ -131,15 +129,6 @@ Criteria setFirstResult(int firstResult); /** - * Method kept in 2.x only for temporary backward compatibility. Always use execute(); - * @return The Collection of matched query results. - * @throws JCRQueryException query exception - * @deprecated use execute() - */ - @Deprecated - Collection< ? > list() throws JCRQueryException; - - /** * Sets the base path of the query, i.e. the branch in the repository tree where the search will take place * @param path the handle of a node, or a xpath query prefix in the form //handle/of/a/node//* * @return this (for method chaining) 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/JCRCriteriaFactory.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -20,10 +20,7 @@ package net.sourceforge.openutils.mgnlcriteria.jcr.query; import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.util.DeprecationUtil; 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; /** @@ -62,97 +59,4 @@ return new DirectJcrQuery(hm, query, language); } - /** - * A factory for Magnolia CMS specific Criteria implementation <br> - * <strong>Warning: the object returned by this method is not thread-safe</strong>To use it as a shared global - * variable, client-code must coordinate access to it. - * @param path String - the path in JCR repository to search for Nodes. This is the path which precedes the - * predicate - * @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); - } - - /** - * A factory for Magnolia CMS specific Criteria implementation <br> - * <strong>Warning: the object returned by this method is not thread-safe</strong>To use it as a shared global - * variable, client-code must coordinate access to it. - * @param path String - the path in JCR repository to search for Nodes. This is the path which precedes the - * predicate - * @param queryManager - an instance of info.magnolia.cms.core.search.QueryManager - * @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); - } - - /** - * A factory for Magnolia CMS specific Criteria implementation which can return a subset of results instead of the - * whole resultset, much like a MySQL limit clause. For this to work, the underlying JCR repository implementation - * must support this feature (Jackrabbit 1.4+ does).<br> - * To set the maximum number of returned items you must call {@link Criteria#setMaxResults(int)} (by default - * {@link Criteria#setFirstResult(int)} is set to 0).<br> - * Please notice that if {@link Criteria#setMaxResults(int)} is not explicitly called before the - * {@link Criteria#list()} method, the latter will return the entire resultset as in - * {@link JCRCriteriaFactory#createMgnlCriteria(String, info.magnolia.cms.core.search.QueryManager, String)} <br> - * <strong>Warning: the object returned by this method is not thread-safe</strong>To use it as a shared global - * variable, client-code must coordinate access to it. - * @param path String - the path in JCR repository to search for Nodes. This is the path which precedes the - * predicate - * @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 createMgnlCriteriaWithLimit(String path, - info.magnolia.cms.core.search.QueryManager queryManager, String itemType) - { - DeprecationUtil.isDeprecated("please use createCriteria() instead"); - return new MagnoliaCriteriaWithLimitImpl(path, queryManager, itemType); - } - - /** - * A factory for Magnolia CMS specific Criteria implementation which can return a subset of results instead of the - * whole resultset, much like a MySQL limit clause. For this to work, the underlying JCR repository implementation - * must support this feature (Jackrabbit 1.4+ does).<br> - * To set the maximum number of returned items you must call {@link Criteria#setMaxResults(int)} (by default - * {@link Criteria#setFirstResult(int)} is set to 0).<br> - * Please notice that if {@link Criteria#setMaxResults(int)} is not explicitly called before the - * {@link Criteria#list()} method, the latter will return the entire resultset as in - * {@link JCRCriteriaFactory#createMgnlCriteria(String, info.magnolia.cms.core.search.QueryManager, String, Class)} <br> - * <strong>Warning: the object returned by this method is not thread-safe</strong>To use it as a shared global - * variable, client-code must coordinate access to it. - * @param path String - the path in JCR repository to search for Nodes. This is the path which precedes the - * predicate - * @param queryManager - an instance of info.magnolia.cms.core.search.QueryManager - * @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 createMgnlCriteriaWithLimit(String path, - info.magnolia.cms.core.search.QueryManager queryManager, String itemType, Class< ? > clazz) - { - - DeprecationUtil.isDeprecated("please use createCriteria() instead"); - return new MagnoliaCriteriaWithLimitImpl(path, queryManager, itemType, clazz); - } - } 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractCriteriaImpl.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -20,7 +20,6 @@ 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; @@ -65,8 +64,6 @@ protected int offset; - protected HierarchyManager hm; - protected String spellCheckString; protected String workspace = ContentRepository.WEBSITE; @@ -76,12 +73,6 @@ } - protected AbstractCriteriaImpl(HierarchyManager hm) - { - super(); - this.hm = hm; - } - /** * {@inheritDoc} */ @@ -226,13 +217,14 @@ */ public AdvancedResult execute() { + @SuppressWarnings("deprecation") String language = javax.jcr.query.Query.XPATH; String stmt = toXpathExpression(); return QueryExecutorHelper.execute( stmt, language, - this.hm != null ? this.hm : MgnlContext.getHierarchyManager(workspace), + MgnlContext.getHierarchyManager(workspace), maxResults, offset, spellCheckString); Deleted: 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/AbstractMagnoliaCriteriaImpl.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -1,101 +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.jcr.query.xpath.impl; - -import info.magnolia.cms.core.Content; -import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.core.ItemType; -import info.magnolia.cms.core.search.QueryManager; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; - -import org.apache.commons.lang.StringUtils; - - -/** - * @author fgrilli - * @version $Id$ - */ -@Deprecated -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 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()} - * @param classType Class<?> - defaults to {@link Content} - */ - protected AbstractMagnoliaCriteriaImpl(String path, QueryManager queryManager, String itemType, Class< ? > classType) - { - - super(getPrivateHierarchyManagerFromQuery(queryManager)); - if (StringUtils.isBlank(itemType)) - { - this.itemType = ItemType.CONTENT.getSystemName(); - } - else - { - this.itemType = itemType; - } - this.path = path; - this.queryManager = queryManager; - // defaults to info.magnolia.cms.core.Content - this.classType = classType == null ? Content.class : classType; - } - - protected static HierarchyManager getPrivateHierarchyManagerFromQuery(QueryManager queryManager) - { - if (queryManager == null) - { - return null; - } - - java.lang.reflect.Field field; - try - { - field = queryManager.getClass().getDeclaredField("hm"); - field.setAccessible(true); - HierarchyManager hm = (HierarchyManager) field.get(queryManager); - return hm; - } - catch (Throwable e) - { - throw new JCRQueryException("getting hierarchyManager", e); - } - - } - -} \ No newline at end of file Deleted: 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaImpl.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -1,155 +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.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; -import info.magnolia.cms.util.DeprecationUtil; -import info.magnolia.content2bean.Content2BeanException; -import info.magnolia.content2bean.Content2BeanUtil; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import javax.jcr.RepositoryException; -import javax.jcr.query.InvalidQueryException; - -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; - - -/** - * Magnolia XPATH implementation of the <tt>Criteria</tt> interface - * @author Federico Grilli - * @version $Id$ - */ -@Deprecated -public class MagnoliaCriteriaImpl extends AbstractMagnoliaCriteriaImpl -{ - - 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"); - - if (queryManager == null) - { - throw new IllegalStateException("QueryManager cannot be null"); - } - - log.debug("creating statement..."); - long start = System.currentTimeMillis(); - - String stmt = toXpathExpression(); - - long stop = System.currentTimeMillis(); - log.debug("statement created in {} ms", stop - start); - Collection< ? > retVal; - try - { - - Query q = queryManager.createQuery(stmt, Query.XPATH); - - log.debug("executing Query {}", q.getStatement()); - start = System.currentTimeMillis(); - - QueryResult r = q.execute(); - - stop = System.currentTimeMillis(); - log.debug("Query executed in {} ms", stop - start); - - log.debug("getting content..."); - start = System.currentTimeMillis(); - - retVal = r.getContent(itemType); - - stop = System.currentTimeMillis(); - - if (Content.class.isAssignableFrom(classType)) - { - log.debug("returning a Collection holding objects of type {} ", Content.class.getName()); - retVal = retVal == null ? new ArrayList<Content>() : retVal; - log.debug("got {} node(s) in {} ms", new Object[]{retVal.size(), stop - start }); - - return retVal; - - } - else - { - log.debug("returning a Collection holding objects of type {} ", classType.getName()); - List list = new ArrayList(); - for (Iterator iter = retVal.iterator(); iter.hasNext();) - { - Content node = (Content) iter.next(); - try - { - list.add(classType.cast(Content2BeanUtil.toBean(node, true, classType))); - } - catch (Content2BeanException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - } - log.debug("got {} node(s) in {} ms", new Object[]{list.size(), stop - start }); - return list; - } - - } - catch (InvalidQueryException e) - { - log.error(EXCEPTION_MSG, new Object[]{stmt, e.getMessage() }); - throw new JCRQueryException(stmt, e); - } - catch (RepositoryException e) - { - log.error(EXCEPTION_MSG, new Object[]{stmt, e.getMessage() }); - throw new JCRQueryException(stmt, e); - } - } - -} \ No newline at end of file Deleted: 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-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -1,344 +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.jcr.query.xpath.impl; - -import info.magnolia.cms.core.Content; -import info.magnolia.cms.core.DefaultContent; -import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.cms.core.ItemType; -import info.magnolia.cms.core.Path; -import info.magnolia.cms.core.search.Query; -import info.magnolia.cms.core.search.QueryManager; -import info.magnolia.cms.core.search.QueryResult; -import info.magnolia.cms.security.AccessManager; -import info.magnolia.cms.security.Permission; -import info.magnolia.content2bean.Content2BeanException; -import info.magnolia.content2bean.Content2BeanUtil; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.RepositoryException; -import javax.jcr.query.InvalidQueryException; - -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; -import org.slf4j.LoggerFactory; - - -/** - * <strong>Deprecated in mgnlcriteria 2.x. Paging is now implemented at jcr level in AdvancedCriteria, this class should - * not be used anymore.</strong> Magnolia XPATH implementation of the <tt>Criteria</tt> interface which supports - * limiting the result set according to the underlying JCR implementation (e.g. Jackrabbit 1.4+) - * @deprecated due to the way results are collected there is no guarantee that the offset specified is respected: for - * example if your query matches both a page and a paragraph in it, and you ask for results of type mgnl:content those - * two results will be merged into one. If you need paging use AdvancedCriteria and be sure to specify the desired - * return type in the query directly. - * @author Federico Grilli - * @version $Id$ - */ -@Deprecated -public class MagnoliaCriteriaWithLimitImpl extends MagnoliaCriteriaImpl -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(MagnoliaCriteriaWithLimitImpl.class); - - private static final String HIERARCHY_MANAGER = "hm"; - - 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(HierarchyManager hm) - { - super(hm); - } - - @Override - @SuppressWarnings("unchecked") - @Deprecated - public Collection< ? > list() throws JCRQueryException - { - if (queryManager == null) - { - throw new IllegalStateException("QueryManager cannot be null"); - } - - log.debug("creating statement..."); - long start = System.currentTimeMillis(); - - JCRMagnoliaCriteriaQueryTranslator translator = new JCRMagnoliaCriteriaQueryTranslator(this); - XPathSelect statement = new XPathSelect(); - statement.setRoot(XPathTextUtils.encodeDigitsInPath(this.path)); - statement.setPredicate(translator.getPredicate()); - statement.setOrderByClause(translator.getOrderBy()); - String stmt = statement.toStatementString(); - - long stop = System.currentTimeMillis(); - log.debug("statement created in {} milliseconds", stop - start); - - try - { - Class< ? extends QueryManager> managerClass = queryManager.getClass(); - java.lang.reflect.Field field = managerClass.getDeclaredField(QUERY_MANAGER); - field.setAccessible(true); - - javax.jcr.query.QueryManager jcrManager = (javax.jcr.query.QueryManager) field.get(queryManager); - org.apache.jackrabbit.core.query.QueryImpl q = (org.apache.jackrabbit.core.query.QueryImpl) jcrManager - .createQuery(stmt, Query.XPATH); - - if (getMaxResults() > 0) - { - q.setLimit(getMaxResults()); - } - - if (getFirstResult() >= 0) - { - q.setOffset(getFirstResult()); - } - - log.debug("offset is {} limit is {}", new Object[]{getFirstResult(), getMaxResults() }); - - log.debug("executing Query {}", q.getStatement()); - start = System.currentTimeMillis(); - javax.jcr.query.QueryResult result = q.execute(); - - stop = System.currentTimeMillis(); - log.debug("Query executed in {} milliseconds", stop - start); - - Collection<Content> retVal; - field = managerClass.getDeclaredField(HIERARCHY_MANAGER); - field.setAccessible(true); - HierarchyManager hm = (HierarchyManager) field.get(queryManager); - - log.debug("getting content..."); - start = System.currentTimeMillis(); - QueryResultImpl filteredResult = new QueryResultImpl(result, hm); - retVal = filteredResult.getContent(itemType); - - stop = System.currentTimeMillis(); - - if (Content.class.isAssignableFrom(classType)) - { - log.debug("returning a Collection holding objects of type {} ", Content.class.getName()); - retVal = retVal == null ? new ArrayList<Content>() : retVal; - log.debug("got {} node(s) in {} ms", new Object[]{retVal.size(), stop - start }); - - return retVal; - } - else - { - log.debug("returning a Collection holding objects of type {} ", classType.getName()); - Iterator iter = retVal.iterator(); - List list = new ArrayList(); - while (iter.hasNext()) - { - Content node = (Content) iter.next(); - try - { - list.add(classType.cast(Content2BeanUtil.toBean(node, true, classType))); - } - catch (Content2BeanException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - } - log.debug("got {} node(s) in {} ms", new Object[]{list.size(), stop - start }); - return list; - } - } - catch (InvalidQueryException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - catch (RepositoryException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - catch (SecurityException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - catch (NoSuchFieldException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - catch (IllegalArgumentException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - catch (IllegalAccessException e) - { - log.error(e.getMessage()); - throw new JCRQueryException(stmt, e); - } - } - - /** - * This is {@link QueryResultImpl} slightly modified - */ - protected static final class QueryResultImpl implements QueryResult - { - - /** - * Unfiltered result object - */ - private javax.jcr.query.QueryResult result; - - private AccessManager accessManager; - - private HierarchyManager hm; - - private Map<String, String> dirtyHandles = new Hashtable<String, String>(); - - protected QueryResultImpl(javax.jcr.query.QueryResult result, HierarchyManager hm) - { - this.result = result; - this.hm = hm; - this.accessManager = hm.getAccessManager(); - } - - public AccessManager getAccessManager() - { - return accessManager; - } - - public javax.jcr.query.QueryResult getJcrResult() - { - return result; - } - - /** - * Build required result objects - */ - private void build(String nodeType, Collection<Content> collection) throws RepositoryException - { - NodeIterator nodeIterator = this.result.getNodes(); - while (nodeIterator.hasNext()) - { - Node node = nodeIterator.nextNode(); - try - { - build(node, nodeType, collection); - } - catch (RepositoryException re) - { - log.error( - "{} caught while iterating on query results: {}", - re.getClass().getName(), - re.getMessage()); - if (log.isDebugEnabled()) - { - log.debug( - re.getClass().getName() + " caught while iterating on query results: " + re.getMessage(), - re); - } - } - } - } - - /** - * Build required result objects - */ - private void build(Node node, String nodeType, Collection<Content> collection) throws RepositoryException - { - /** - * All custom node types - */ - if ((node.isNodeType(nodeType) || StringUtils.isEmpty(nodeType)) && !node.isNodeType(ItemType.NT_RESOURCE)) - { - if (this.dirtyHandles.get(node.getPath()) == null) - { - boolean isAllowed = this.accessManager.isGranted( - Path.getAbsolutePath(node.getPath()), - Permission.READ); - if (isAllowed) - { - collection.add(new DefaultContent(node, this.hm)); - this.dirtyHandles.put(node.getPath(), StringUtils.EMPTY); - } - } - return; - } - if (node.getDepth() > 0) - { - this.build(node.getParent(), nodeType, collection); - } - } - - /** - * @see info.magnolia.cms.core.search.QueryResult#getContent() - */ - public Collection<Content> getContent() - { - return getContent(ItemType.CONTENT.getSystemName()); - } - - /** - * @see info.magnolia.cms.core.search.QueryResult#getContent(java.lang.String) - */ - public Collection<Content> getContent(String nodeType) - { - Collection<Content> resultSet = new ArrayList<Content>(); - try - { - this.build(nodeType, resultSet); - } - catch (RepositoryException re) - { - log.error(re.getMessage()); - } - return resultSet; - } - } -} \ No newline at end of file Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -40,44 +40,6 @@ } /** - * Escapes all illegal XPath search characters of a string. - * <p> - * Example:<br> - * A search string like 'test?' will run into a ParseException documented in - * http://issues.apache.org/jira/browse/JCR-1248 This is copied from org.apache.jackrabbit.util.Text and was put - * here just to keep this API JCR implementation agnostic - * @param s the string to encode - * @return the escaped string - * @deprecated may cause JCRQueryException on search-expressions like "\"milano\"" (CRIT-9) - */ - @Deprecated - public static String escapeIllegalXpathSearchChars(String s) - { - if (StringUtils.isEmpty(s)) - { - return s; - } - StringBuffer sb = new StringBuffer(); - sb.append(s.substring(0, (s.length() - 1))); - char c = s.charAt(s.length() - 1); - if (c == '!' - || c == '(' - || c == ':' - || c == '^' - || c == '[' - || c == ']' - || c == '\"' - || c == '{' - || c == '}' - || c == '?') - { - sb.append('\\'); - } - sb.append(c); - return sb.toString(); - } - - /** * Convert a string to an XPath 2.0 string literal, suitable for inclusion in a query. See JSR-170 spec v1.0, Sec. * 6.6.4.9. * @param str Any string. Modified: trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java 2010-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryDecoratorSupport.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -33,10 +33,13 @@ public class QueryDecoratorSupport { + /** + * The search index. + */ protected final SearchIndex index; /** - * + * */ public QueryDecoratorSupport(SearchIndex index) { Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-08-29 15:43:29 UTC (rev 2932) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-08-29 16:00:21 UTC (rev 2933) @@ -68,6 +68,7 @@ MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); } + @SuppressWarnings("deprecation") @Test public void testTrailingUnescaped() throws Exception { @@ -91,6 +92,7 @@ Assert.assertEquals(advResult.getTotalSize(), 0); } + @SuppressWarnings("deprecation") @Test public void testTrailingEscaped() throws Exception { @@ -103,6 +105,7 @@ Assert.assertEquals(advResult.getItems().next().getTitle(), "hello test? world"); } + @SuppressWarnings("deprecation") @Test public void testMiddle() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |