From: <mol...@us...> - 2010-09-23 17:08:08
|
Revision: 3114 http://openutils.svn.sourceforge.net/openutils/?rev=3114&view=rev Author: molaschi Date: 2010-09-23 17:08:01 +0000 (Thu, 23 Sep 2010) Log Message: ----------- CRIT-29 Modified Paths: -------------- trunk/openutils-mgnlcriteria/pom.xml trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java Modified: trunk/openutils-mgnlcriteria/pom.xml =================================================================== --- trunk/openutils-mgnlcriteria/pom.xml 2010-09-15 16:58:57 UTC (rev 3113) +++ trunk/openutils-mgnlcriteria/pom.xml 2010-09-23 17:08:01 UTC (rev 3114) @@ -180,8 +180,8 @@ </repositories> <properties> <magnolia.version>4.3.6</magnolia.version> - <jackrabbit.version>2.0.0</jackrabbit.version> - <jcr.version>2.0</jcr.version> + <jackrabbit.version>1.6.2</jackrabbit.version> + <jcr.version>1.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/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-09-15 16:58:57 UTC (rev 3113) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/AdvancedResultItemImpl.java 2010-09-23 17:08:01 UTC (rev 3114) @@ -19,15 +19,21 @@ package net.sourceforge.openutils.mgnlcriteria.advanced.impl; +import info.magnolia.cms.core.Content; import info.magnolia.cms.core.HierarchyManager; import info.magnolia.cms.security.AccessDeniedException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.jcr.Item; import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.query.Row; import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResultItem; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,17 +52,85 @@ */ private Logger log = LoggerFactory.getLogger(AdvancedResultItemImpl.class); + private final static Method JCR_ROW_GETNODE; + + private final static Method JCR_ROW_GETSCORE; + + static + { + Method jcrRowGetNode = null; + try + { + jcrRowGetNode = Row.class.getDeclaredMethod("getNode", (Class[]) null); + } + catch (SecurityException e) + { + } + catch (NoSuchMethodException e) + { + } + JCR_ROW_GETNODE = jcrRowGetNode; + + Method jcrRowGetScore = null; + try + { + jcrRowGetScore = Row.class.getDeclaredMethod("getScore", new Class[]{String.class }); + } + catch (SecurityException e) + { + } + catch (NoSuchMethodException e) + { + } + JCR_ROW_GETSCORE = jcrRowGetScore; + } + + public static Item getJCRNode(Row row, HierarchyManager hierarchyManager) throws RepositoryException + { + if (JCR_ROW_GETNODE != null) + { + try + { + return (Item) JCR_ROW_GETNODE.invoke(row, (Object[]) null); + } + catch (IllegalAccessException e) + { + } + catch (InvocationTargetException e) + { + } + } + else + { + Value path = row.getValue("jcr:path"); + if (path != null && StringUtils.isNotBlank(path.getString())) + { + Content node = hierarchyManager.getContent(path.getString()); + if (node != null) + { + return node.getJCRNode(); + } + } + + } + return null; + } + /** * @param elem * @param hierarchyManager * @throws RepositoryException * @throws AccessDeniedException + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws IllegalStateException + * @throws IllegalArgumentException */ public AdvancedResultItemImpl(Row row, HierarchyManager hierarchyManager) throws RepositoryException, AccessDeniedException { - super(row.getNode(), hierarchyManager); + super(getJCRNode(row, hierarchyManager), hierarchyManager); this.row = row; } @@ -115,15 +189,52 @@ */ public double getScore(String selector) { - try + if (JCR_ROW_GETSCORE != null) { - return row.getScore(selector); + try + { + return (Double) JCR_ROW_GETSCORE.invoke(row, new Object[]{selector }); + } + catch (IllegalArgumentException e) + { + log.warn("Error getting score for {}", this.getHandle(), e); + } + catch (IllegalAccessException e) + { + log.warn("Error getting score for {}", this.getHandle(), e); + } + catch (InvocationTargetException e) + { + log.warn("Error getting score for {}", this.getHandle(), e); + } } - catch (RepositoryException e) + else { - log.warn("Error getting score for " + this.getHandle(), e); - return 0; + Value scoreValue; + try + { + scoreValue = row.getValue("jcr:score(" + selector + ")"); + } + catch (RepositoryException e) + { + log.warn("Error getting excerpt for " + this.getHandle(), e); + return 0; + } + + if (scoreValue != null) + { + try + { + return scoreValue.getDouble(); + } + catch (RepositoryException e) + { + log.warn("Error getting score for " + this.getHandle(), e); + return 0; + } + } } + return 0; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |