From: <fg...@us...> - 2011-01-24 18:06:47
|
Revision: 3282 http://openutils.svn.sourceforge.net/openutils/?rev=3282&view=rev Author: fgiust Date: 2011-01-24 18:06:39 +0000 (Mon, 24 Jan 2011) Log Message: ----------- CRIT-32 Better handling of invalid/missing results Modified Paths: -------------- 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/AdvancedResultItemResultIterator.java Added Paths: ----------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/utils/JcrCompatUtils.java 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 2011-01-24 13:48:27 UTC (rev 3281) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultImpl.java 2011-01-24 18:06:39 UTC (rev 3282) @@ -23,6 +23,7 @@ import info.magnolia.content2bean.Content2BeanException; import info.magnolia.content2bean.Content2BeanUtil; +import javax.jcr.Item; import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.query.InvalidQueryException; @@ -35,6 +36,7 @@ import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRQueryException; import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIterator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIteratorImpl; +import net.sourceforge.openutils.mgnlcriteria.utils.JcrCompatUtils; import org.apache.jackrabbit.core.query.lucene.QueryResultImpl; import org.slf4j.Logger; @@ -224,7 +226,16 @@ { try { - return (K) Content2BeanUtil.toBean(new AdvancedResultItemImpl(row, this.hm), true, theclass); + Item jcrNode = JcrCompatUtils.getJCRNode(row); + if (jcrNode == null) + { + return null; + } + + return (K) Content2BeanUtil.toBean( + new AdvancedResultItemImpl(row, jcrNode, this.hm), + true, + theclass); } catch (RepositoryException e) { 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 2011-01-24 13:48:27 UTC (rev 3281) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemResultIterator.java 2011-01-24 18:06:39 UTC (rev 3282) @@ -22,12 +22,14 @@ import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.security.AccessDeniedException; +import javax.jcr.Item; import javax.jcr.RepositoryException; import javax.jcr.query.Row; import javax.jcr.query.RowIterator; import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; import net.sourceforge.openutils.mgnlcriteria.jcr.query.ResultIteratorImpl; +import net.sourceforge.openutils.mgnlcriteria.utils.JcrCompatUtils; /** @@ -55,7 +57,13 @@ { try { - return new AdvancedResultItemImpl(row, this.hm); + Item jcrNode = JcrCompatUtils.getJCRNode(row); + if (jcrNode == null) + { + return null; + } + + return new AdvancedResultItemImpl(row, jcrNode, this.hm); } catch (AccessDeniedException e) { Added: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/utils/JcrCompatUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/utils/JcrCompatUtils.java (rev 0) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/utils/JcrCompatUtils.java 2011-01-24 18:06:39 UTC (rev 3282) @@ -0,0 +1,74 @@ +/** + * + * Criteria API for Magnolia CMS (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.utils; + +import java.lang.reflect.InvocationTargetException; + +import javax.jcr.Item; +import javax.jcr.RepositoryException; +import javax.jcr.query.Row; + +import org.apache.commons.beanutils.PropertyUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Utility methods for accessing jcr 2.0 only properties using reflection, for compatibility with jackrabbit 1.6. + * @author fgiust + * @version $Id$ + */ +public final class JcrCompatUtils +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(JcrCompatUtils.class); + + // don't instantiate + private JcrCompatUtils() + { + + } + + public static Item getJCRNode(Row row) throws RepositoryException + { + + try + { + return (Item) PropertyUtils.getProperty(row, "node"); + } + catch (IllegalAccessException e) + { + } + catch (InvocationTargetException e) + { + log.warn("Error extracting node from row", e.getTargetException()); + } + catch (NoSuchMethodException e) + { + log + .error("Unsupported version of jackrabbit detected, you need at least 1.6.x or a jcr 2.0 compliant version"); + } + + return null; + } +} Property changes on: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/utils/JcrCompatUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |