From: <fg...@us...> - 2010-03-19 22:40:22
|
Revision: 2175 http://openutils.svn.sourceforge.net/openutils/?rev=2175&view=rev Author: fgiust Date: 2010-03-19 22:40:13 +0000 (Fri, 19 Mar 2010) Log Message: ----------- [maven-release-plugin] copy for tag openutils-mgnlcriteria-2.0-b5 Added Paths: ----------- tags/openutils-mgnlcriteria-2.0-b5/ tags/openutils-mgnlcriteria-2.0-b5/pom.xml tags/openutils-mgnlcriteria-2.0-b5/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java Removed Paths: ------------- tags/openutils-mgnlcriteria-2.0-b5/pom.xml tags/openutils-mgnlcriteria-2.0-b5/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java Deleted: tags/openutils-mgnlcriteria-2.0-b5/pom.xml =================================================================== --- trunk/openutils-mgnlcriteria/pom.xml 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-mgnlcriteria-2.0-b5/pom.xml 2010-03-19 22:40:13 UTC (rev 2175) @@ -1,144 +0,0 @@ -<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> - <artifactId>openutils-parent</artifactId> - <version>1.2</version> - </parent> - <artifactId>openutils-mgnlcriteria</artifactId> - <name>Magnolia Criteria API</name> - <version>2.0-b5-SNAPSHOT</version> - <inceptionYear>2009</inceptionYear> - <description>A Hibernate's Criteria-like API to programmatically generate JCR queries with Magnolia</description> - <licenses> - <license> - <name>GPLv3</name> - <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> - </license> - </licenses> - <url>http://www.openmindlab.com/lab/products/mgnlcriteria.html</url> - <issueManagement> - <system>jira</system> - <url>http://jira.openmindlab.com/browse/CRIT</url> - </issueManagement> - <build> - <plugins> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <id>bundle</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - <configuration> - <descriptors> - <descriptor>${basedir}/src/main/assembly/assembly-bundle.xml</descriptor> - </descriptors> - </configuration> - </plugin> - <plugin> - <groupId>com.mycila.maven-license-plugin</groupId> - <artifactId>maven-license-plugin</artifactId> - <version>1.5.0</version> - <configuration> - <header>src/main/etc/header.txt</header> - <includes> - <include>src/**/*.java</include> - </includes> - <properties> - <year>${project.inceptionYear}-2010</year> - <name>${project.name}</name> - <description>${project.description}</description> - <url>${project.url}</url> - </properties> - </configuration> - <executions> - <execution> - <goals> - <goal>check</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <useManifestOnlyJar>false</useManifestOnlyJar> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-core</artifactId> - <version>${magnolia.version}</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.5.8</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.5.8</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>1.5.8</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - <version>2.0</version> - </dependency> - <dependency> - <groupId>info.magnolia</groupId> - <artifactId>magnolia-core</artifactId> - <classifier>tests</classifier> - <version>${magnolia.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.7</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - <version>5.10</version> - <scope>test</scope> - </dependency> - </dependencies> - <repositories> - <repository> - <id>repository.magnolia.info</id> - <name>magnolia repository</name> - <url>http://repository.magnolia-cms.com/m2/</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - </repositories> - <properties> - <magnolia.version>4.2.3</magnolia.version> - </properties> -</project> \ No newline at end of file Copied: tags/openutils-mgnlcriteria-2.0-b5/pom.xml (from rev 2174, trunk/openutils-mgnlcriteria/pom.xml) =================================================================== --- tags/openutils-mgnlcriteria-2.0-b5/pom.xml (rev 0) +++ tags/openutils-mgnlcriteria-2.0-b5/pom.xml 2010-03-19 22:40:13 UTC (rev 2175) @@ -0,0 +1,150 @@ +<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> + <artifactId>openutils-parent</artifactId> + <version>1.2</version> + </parent> + <artifactId>openutils-mgnlcriteria</artifactId> + <name>Magnolia Criteria API</name> + <version>2.0-b5</version> + <inceptionYear>2009</inceptionYear> + <description>A Hibernate's Criteria-like API to programmatically generate JCR queries with Magnolia</description> + <licenses> + <license> + <name>GPLv3</name> + <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> + </license> + </licenses> + <url>http://www.openmindlab.com/lab/products/mgnlcriteria.html</url> + <issueManagement> + <system>jira</system> + <url>http://jira.openmindlab.com/browse/CRIT</url> + </issueManagement> + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>bundle</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + <configuration> + <descriptors> + <descriptor>${basedir}/src/main/assembly/assembly-bundle.xml</descriptor> + </descriptors> + </configuration> + </plugin> + <plugin> + <groupId>com.mycila.maven-license-plugin</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>1.5.0</version> + <configuration> + <header>src/main/etc/header.txt</header> + <includes> + <include>src/**/*.java</include> + </includes> + <properties> + <year>${project.inceptionYear}-2010</year> + <name>${project.name}</name> + <description>${project.description}</description> + <url>${project.url}</url> + </properties> + </configuration> + <executions> + <execution> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useManifestOnlyJar>false</useManifestOnlyJar> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <version>${magnolia.version}</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.8</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.5.8</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>1.5.8</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <classifier>tests</classifier> + <version>${magnolia.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.10</version> + <scope>test</scope> + </dependency> + </dependencies> + <repositories> + <repository> + <id>repository.magnolia.info</id> + <name>magnolia repository</name> + <url>http://repository.magnolia-cms.com/m2/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + <properties> + <magnolia.version>4.3</magnolia.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlcriteria-2.0-b5</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-mgnlcriteria-2.0-b5</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-mgnlcriteria-2.0-b5</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-mgnlcriteria-2.0-b5/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-19 09:34:10 UTC (rev 2159) +++ tags/openutils-mgnlcriteria-2.0-b5/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-03-19 22:40:13 UTC (rev 2175) @@ -1,341 +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; - - -/** - * 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); - } - - @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 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<DefaultContent> 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<DefaultContent> 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<DefaultContent> getContent() - { - return getContent(ItemType.CONTENT.getSystemName()); - } - - /** - * @see info.magnolia.cms.core.search.QueryResult#getContent(java.lang.String) - */ - public Collection<DefaultContent> getContent(String nodeType) - { - Collection<DefaultContent> resultSet = new ArrayList<DefaultContent>(); - try - { - this.build(nodeType, resultSet); - } - catch (RepositoryException re) - { - log.error(re.getMessage()); - } - return resultSet; - } - } -} \ No newline at end of file Copied: tags/openutils-mgnlcriteria-2.0-b5/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java (from rev 2173, trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java) =================================================================== --- tags/openutils-mgnlcriteria-2.0-b5/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java (rev 0) +++ tags/openutils-mgnlcriteria-2.0-b5/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/impl/MagnoliaCriteriaWithLimitImpl.java 2010-03-19 22:40:13 UTC (rev 2175) @@ -0,0 +1,340 @@ +/** + * + * 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; + + +/** + * 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); + } + + @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 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 Deleted: tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java 2010-03-19 22:40:13 UTC (rev 2175) @@ -1,195 +0,0 @@ -package net.sourceforge.openutils.mgnlcriteria.advanced; - -import info.magnolia.cms.beans.config.ContentRepository; -import info.magnolia.context.MgnlContext; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import junit.framework.Assert; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; -import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; - -import org.apache.commons.lang.StringUtils; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - - -/** - * @author dschivo - * @version $Id$ - */ -public class JcrContainsCriteriaSearchTest extends RepositoryTestNgTestcase -{ - - /** - * {@inheritDoc} - */ - @Override - @BeforeClass - protected void setUp() throws Exception - { - setRepositoryConfigFileName("/crit-repository/test-repositories.xml"); - setJackrabbitRepositoryConfigFileName("/crit-repository/jackrabbit-test-configuration.xml"); - - super.setUp(); - - // Titles of the nodes in this workspace: - // - hello test? world - // - hello te?st world - // - hello "Milano" world - // - lorem - // - lorem ipsum - // - dolor sit - // - dolor sit amet - bootstrapSingleResource("/crit-bootstrap/website.contains.xml"); - MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); - } - - @Test - public void testLoremAndIpsum() throws Exception - { - Criteria criteria = criteria("lorem ipsum", false); - AdvancedResult advResult = criteria.execute(); - Assert.assertNotNull(advResult); - Assert.assertEquals(1, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - AdvancedResultItem item = items.next(); - Assert.assertEquals("lorem ipsum", item.getTitle()); - } - - @Test - public void testLoremAndNotIpsum() throws Exception - { - Criteria criteria = criteria("lorem -ipsum", false); - AdvancedResult advResult = criteria.execute(); - Assert.assertNotNull(advResult); - Assert.assertEquals(1, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - AdvancedResultItem item = items.next(); - Assert.assertEquals("lorem", item.getTitle()); - } - - @Test - public void testIpsumOrAmet() throws Exception - { - Criteria criteria = criteria("ipsum OR amet", false); - AdvancedResult advResult = criteria.execute(); - Assert.assertNotNull(advResult); - Assert.assertEquals(2, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - List<String> titles = new ArrayList<String>(); - while (items.hasNext()) - { - titles.add(items.next().getTitle()); - } - Collections.sort(titles); - Assert.assertEquals("dolor sit amet", titles.get(0)); - Assert.assertEquals("lorem ipsum", titles.get(1)); - } - - @Test - public void testIpsumOrSitAndAmet() throws Exception - { - Criteria criteria = criteria("ipsum OR \"sit AND amet\"", false); - AdvancedResult advResult = criteria.execute(); - Assert.assertNotNull(advResult); - Assert.assertEquals(2, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - List<String> titles = new ArrayList<String>(); - while (items.hasNext()) - { - titles.add(items.next().getTitle()); - } - Collections.sort(titles); - Assert.assertEquals("dolor sit amet", titles.get(0)); - Assert.assertEquals("lorem ipsum", titles.get(1)); - } - - @Test - public void testTest1() throws Exception - { - String textEnteredByUser = "test?"; - Criteria criteria = criteria(textEnteredByUser, true); - Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'test\\?')))]", StringUtils - .remove(criteria.toXpathExpression(), ' ')); - AdvancedResult advResult = null; - try - { - advResult = criteria.execute(); - } - catch (JCRQueryException e) - { - Assert.fail("Invalid query. " + e.getMessage()); - } - Assert.assertNotNull(advResult); - Assert.assertEquals(1, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - AdvancedResultItem item = items.next(); - Assert.assertEquals("hello test? world", item.getTitle()); - } - - @Test - public void testTest2() throws Exception - { - String textEnteredByUser = "te?st"; - Criteria criteria = criteria(textEnteredByUser, true); - Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'te\\?st')))]", StringUtils - .remove(criteria.toXpathExpression(), ' ')); - AdvancedResult advResult = null; - try - { - advResult = criteria.execute(); - } - catch (JCRQueryException e) - { - Assert.fail("Invalid query. " + e.getMessage()); - } - Assert.assertNotNull(advResult); - Assert.assertEquals(1, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - AdvancedResultItem item = items.next(); - Assert.assertEquals("hello te?st world", item.getTitle()); - } - - @Test - public void testMilano() throws Exception - { - String textEnteredByUser = "\"Milano\""; - Criteria criteria = criteria(textEnteredByUser, true); - System.out.println("> " + criteria.toXpathExpression()); - Assert.assertEquals( - "//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'\\\"Milano\\\"')))]", - StringUtils.remove(criteria.toXpathExpression(), ' ')); - AdvancedResult advResult = null; - try - { - advResult = criteria.execute(); - } - catch (JCRQueryException e) - { - Assert.fail("Invalid query. " + e.getMessage()); - } - Assert.assertNotNull(advResult); - Assert.assertEquals(1, advResult.getTotalSize()); - ResultIterator<AdvancedResultItem> items = advResult.getItems(); - AdvancedResultItem item = items.next(); - Assert.assertEquals("hello \"Milano\" world", item.getTitle()); - } - - private Criteria criteria(String titleSearch, boolean escape) - { - Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); - criteria.setBasePath(StringUtils.EMPTY); - criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); - criteria.add(Restrictions.contains("@title", titleSearch, escape)); - return criteria; - } -} Copied: tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java (from rev 2171, trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java) =================================================================== --- tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java (rev 0) +++ tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsCriteriaSearchTest.java 2010-03-19 22:40:13 UTC (rev 2175) @@ -0,0 +1,213 @@ +/** + * + * 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.beans.config.ContentRepository; +import info.magnolia.context.MgnlContext; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import junit.framework.Assert; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; +import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions; +import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; + +import org.apache.commons.lang.StringUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +/** + * @author dschivo + * @version $Id$ + */ +public class JcrContainsCriteriaSearchTest extends RepositoryTestNgTestcase +{ + + /** + * {@inheritDoc} + */ + @Override + @BeforeClass + protected void setUp() throws Exception + { + setRepositoryConfigFileName("/crit-repository/test-repositories.xml"); + setJackrabbitRepositoryConfigFileName("/crit-repository/jackrabbit-test-configuration.xml"); + + super.setUp(); + + // Titles of the nodes in this workspace: + // - hello test? world + // - hello te?st world + // - hello "Milano" world + // - lorem + // - lorem ipsum + // - dolor sit + // - dolor sit amet + bootstrapSingleResource("/crit-bootstrap/website.contains.xml"); + MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); + } + + @Test + public void testLoremAndIpsum() throws Exception + { + Criteria criteria = criteria("lorem ipsum", false); + AdvancedResult advResult = criteria.execute(); + Assert.assertNotNull(advResult); + Assert.assertEquals(1, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + AdvancedResultItem item = items.next(); + Assert.assertEquals("lorem ipsum", item.getTitle()); + } + + @Test + public void testLoremAndNotIpsum() throws Exception + { + Criteria criteria = criteria("lorem -ipsum", false); + AdvancedResult advResult = criteria.execute(); + Assert.assertNotNull(advResult); + Assert.assertEquals(1, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + AdvancedResultItem item = items.next(); + Assert.assertEquals("lorem", item.getTitle()); + } + + @Test + public void testIpsumOrAmet() throws Exception + { + Criteria criteria = criteria("ipsum OR amet", false); + AdvancedResult advResult = criteria.execute(); + Assert.assertNotNull(advResult); + Assert.assertEquals(2, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + List<String> titles = new ArrayList<String>(); + while (items.hasNext()) + { + titles.add(items.next().getTitle()); + } + Collections.sort(titles); + Assert.assertEquals("dolor sit amet", titles.get(0)); + Assert.assertEquals("lorem ipsum", titles.get(1)); + } + + @Test + public void testIpsumOrSitAndAmet() throws Exception + { + Criteria criteria = criteria("ipsum OR \"sit AND amet\"", false); + AdvancedResult advResult = criteria.execute(); + Assert.assertNotNull(advResult); + Assert.assertEquals(2, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + List<String> titles = new ArrayList<String>(); + while (items.hasNext()) + { + titles.add(items.next().getTitle()); + } + Collections.sort(titles); + Assert.assertEquals("dolor sit amet", titles.get(0)); + Assert.assertEquals("lorem ipsum", titles.get(1)); + } + + @Test + public void testTest1() throws Exception + { + String textEnteredByUser = "test?"; + Criteria criteria = criteria(textEnteredByUser, true); + Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'test\\?')))]", StringUtils + .remove(criteria.toXpathExpression(), ' ')); + AdvancedResult advResult = null; + try + { + advResult = criteria.execute(); + } + catch (JCRQueryException e) + { + Assert.fail("Invalid query. " + e.getMessage()); + } + Assert.assertNotNull(advResult); + Assert.assertEquals(1, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + AdvancedResultItem item = items.next(); + Assert.assertEquals("hello test? world", item.getTitle()); + } + + @Test + public void testTest2() throws Exception + { + String textEnteredByUser = "te?st"; + Criteria criteria = criteria(textEnteredByUser, true); + Assert.assertEquals("//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'te\\?st')))]", StringUtils + .remove(criteria.toXpathExpression(), ' ')); + AdvancedResult advResult = null; + try + { + advResult = criteria.execute(); + } + catch (JCRQueryException e) + { + Assert.fail("Invalid query. " + e.getMessage()); + } + Assert.assertNotNull(advResult); + Assert.assertEquals(1, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + AdvancedResultItem item = items.next(); + Assert.assertEquals("hello te?st world", item.getTitle()); + } + + @Test + public void testMilano() throws Exception + { + String textEnteredByUser = "\"Milano\""; + Criteria criteria = criteria(textEnteredByUser, true); + Assert.assertEquals( + "//*[((@jcr:primaryType='mgnl:content')and(jcr:contains(@title,'\\\"Milano\\\"')))]", + StringUtils.remove(criteria.toXpathExpression(), ' ')); + AdvancedResult advResult = null; + try + { + advResult = criteria.execute(); + } + catch (JCRQueryException e) + { + Assert.fail("Invalid query. " + e.getMessage()); + } + Assert.assertNotNull(advResult); + Assert.assertEquals(1, advResult.getTotalSize()); + ResultIterator<AdvancedResultItem> items = advResult.getItems(); + AdvancedResultItem item = items.next(); + Assert.assertEquals("hello \"Milano\" world", item.getTitle()); + } + + private Criteria criteria(String titleSearch, boolean escape) + { + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath(StringUtils.EMPTY); + criteria.add(Restrictions.eq("@jcr:primaryType", "mgnl:content")); + criteria.add(Restrictions.contains("@title", titleSearch, escape)); + return criteria; + } +} Deleted: tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-03-19 22:40:13 UTC (rev 2175) @@ -1,103 +0,0 @@ -package net.sourceforge.openutils.mgnlcriteria.advanced; - -import info.magnolia.cms.beans.config.ContentRepository; -import info.magnolia.cms.core.HierarchyManager; -import info.magnolia.context.MgnlContext; - -import javax.jcr.query.Query; - -import junit.framework.Assert; -import net.sourceforge.openutils.mgnlcriteria.advanced.impl.AdvancedResultImpl; -import net.sourceforge.openutils.mgnlcriteria.advanced.impl.QueryExecutorHelper; -import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; -import net.sourceforge.openutils.mgnlcriteria.tests.RepositoryTestNgTestcase; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - - -/** - * Unit test on escaping quotation mark in jcr:contains(). - * Unescaped quotation marks are not illegal: no Exception is thrown on query execution. - * All quotation marks (not only the trailing one) should be escaped to obatain results. - * @author dschivo - * @version $Id$ - */ -public class JcrContainsQuestionMarkTest extends RepositoryTestNgTestcase -{ - - /** - * {@inheritDoc} - */ - @Override - @BeforeClass - protected void setUp() throws Exception - { - setRepositoryConfigFileName("/crit-repository/test-repositories.xml"); - setJackrabbitRepositoryConfigFileName("/crit-repository/jackrabbit-test-configuration.xml"); - - super.setUp(); - - // Titles of the nodes in this workspace: - // - hello test? world - // - hello te?st world - // - hello "Milano" world - // - lorem - // - lorem ipsum - // - dolor sit - // - dolor sit amet - bootstrapSingleResource("/crit-bootstrap/website.contains.xml"); - MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save(); - } - - @Test - public void testTrailingUnescaped() throws Exception - { - HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); - - AdvancedResultImpl advResult = null; - try - { - String stmt = "//*[((@jcr:primaryType='mgnl:content') and (jcr:contains(@title,'test?')))]"; - advResult = QueryExecutorHelper.execute(stmt, Query.XPATH, hm, 10, 0, null); - } - catch (JCRQueryException e) - { - // The following statement is NOT true: - // A search string like 'test?' will run into a ParseException documented in - // http://issues.apache.org/jira/browse/JCR-1248 - Assert.fail("http://issues.apache.org/jira/browse/JCR-1248"); - } - - Assert.assertEquals(0, advResult.getTotalSize()); - } - - @Test - public void testTrailingEscaped() throws Exception - { - HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); - - String stmt = "//*[((@jcr:primaryType='mgnl:content') and (jcr:contains(@title,'test\\?')))]"; - AdvancedResultImpl advResult = QueryExecutorHelper.execute(stmt, Query.XPATH, hm, -1, 0, null); - - Assert.assertEquals(1, advResult.getTotalSize()); - Assert.assertEquals("hello test? world", advResult.getItems().next().getTitle()); - } - - @Test - public void testMiddle() throws Exception - { - HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); - String stmt; - AdvancedResultImpl advResult; - - stmt = "//*[((@jcr:primaryType='mgnl:content') and (jcr:contains(@title,'te?st')))]"; - advResult = QueryExecutorHelper.execute(stmt, Query.XPATH, hm, -1, 0, null); - Assert.assertEquals(0, advResult.getTotalSize()); - - stmt = "//*[((@jcr:primaryType='mgnl:content') and (jcr:contains(@title,'te\\?st')))]"; - advResult = QueryExecutorHelper.execute(stmt, Query.XPATH, hm, -1, 0, null); - Assert.assertEquals(1, advResult.getTotalSize()); - Assert.assertEquals("hello te?st world", advResult.getItems().next().getTitle()); - } -} Copied: tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java (from rev 2171, trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java) =================================================================== --- tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java (rev 0) +++ tags/openutils-mgnlcriteria-2.0-b5/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/JcrContainsQuestionMarkTest.java 2010-03-19 22:40:13 UTC (rev 2175) @@ -0,0 +1,122 @@ +/** + * + * 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 Gen... [truncated message content] |