|
From: <fg...@us...> - 2012-12-17 20:30:48
|
Revision: 4153
http://openutils.svn.sourceforge.net/openutils/?rev=4153&view=rev
Author: fgiust
Date: 2012-12-17 20:30:42 +0000 (Mon, 17 Dec 2012)
Log Message:
-----------
remove some deprecations, convert from Content to ContentMap
Modified Paths:
--------------
magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java
magnoliamodules/trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld
Added Paths:
-----------
magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsDeprecatedAdapters.java
Added: magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsDeprecatedAdapters.java
===================================================================
--- magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsDeprecatedAdapters.java (rev 0)
+++ magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsDeprecatedAdapters.java 2012-12-17 20:30:42 UTC (rev 4153)
@@ -0,0 +1,83 @@
+package it.openutils.mgnlutils.el;
+
+import info.magnolia.cms.core.AggregationState;
+import info.magnolia.cms.core.Content;
+import info.magnolia.context.MgnlContext;
+import info.magnolia.context.WebContext;
+import info.magnolia.jcr.util.ContentMap;
+
+import javax.jcr.Node;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Adapters for methods deprecated in magnolia 4.5 without a clear or non deprecated replacement.
+ * @author fgiust
+ * @version $Id$
+ */
+@SuppressWarnings("deprecation")
+public class MgnlUtilsDeprecatedAdapters
+{
+
+ private static Logger log = LoggerFactory.getLogger(MgnlUtilsDeprecatedAdapters.class);
+
+ public static Node getCurrentContent()
+ {
+ AggregationState aggregationState = safeGetAggregationStateIfAvailable();
+ if (aggregationState != null)
+ {
+ Content mainContent = aggregationState.getCurrentContent();
+ return mainContent != null ? mainContent.getJCRNode() : null;
+ }
+ return null;
+ }
+
+ public static Node getCurrentMain()
+ {
+ AggregationState aggregationState = safeGetAggregationStateIfAvailable();
+ if (aggregationState != null)
+ {
+ Content mainContent = aggregationState.getMainContent();
+ return mainContent != null ? mainContent.getJCRNode() : null;
+ }
+ return null;
+ }
+
+ public static AggregationState safeGetAggregationStateIfAvailable()
+ {
+ WebContext ctx = MgnlContext.getWebContextOrNull();
+ if (ctx != null)
+ {
+ return ctx.getAggregationState();
+ }
+ return null;
+ }
+
+ public static Node toNode(Object nodeorcontent)
+ {
+ if (nodeorcontent == null)
+ {
+ return null;
+ }
+ if (nodeorcontent instanceof Node)
+ {
+ return (Node) nodeorcontent;
+ }
+ else if (nodeorcontent instanceof ContentMap)
+ {
+ return ((ContentMap) nodeorcontent).getJCRNode();
+ }
+ else if (nodeorcontent instanceof Content)
+ {
+ return ((Content) nodeorcontent).getJCRNode();
+ }
+ else
+ {
+ log.warn("Unable to handle object of type {}", nodeorcontent);
+ }
+
+ return null;
+ }
+}
Property changes on: magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsDeprecatedAdapters.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java
===================================================================
--- magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2012-12-10 20:28:23 UTC (rev 4152)
+++ magnoliamodules/trunk/openutils-mgnlutils/src/main/java/it/openutils/mgnlutils/el/MgnlUtilsElFunctions.java 2012-12-17 20:30:42 UTC (rev 4153)
@@ -39,6 +39,7 @@
import info.magnolia.context.MgnlContext;
import info.magnolia.context.WebContext;
import info.magnolia.jaas.principal.EntityImpl;
+import info.magnolia.jcr.util.ContentMap;
import info.magnolia.jcr.util.NodeUtil;
import info.magnolia.link.LinkException;
import info.magnolia.link.LinkUtil;
@@ -58,11 +59,17 @@
import java.util.Properties;
import java.util.Set;
+import javax.jcr.Item;
import javax.jcr.ItemNotFoundException;
+import javax.jcr.LoginException;
+import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import javax.security.auth.Subject;
import javax.servlet.http.HttpServletRequest;
+import net.sourceforge.openutils.mgnlcriteria.jcr.query.AdvancedResult;
+import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria;
import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory;
import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions;
@@ -129,16 +136,29 @@
* @param repository repository type
* @return the content of a given path and repository
*/
- public static Content contentByPath(String path, String repository)
+ public static ContentMap contentByPath(String path, String repository)
{
+ if (path == null || repository == null)
+ {
+ return null;
+ }
try
{
- return MgnlContext.getHierarchyManager(repository).getContent(path);
+ Node node = MgnlContext.getJCRSession(repository).getNode(path);
+ if (node != null)
+ {
+ return wrapNode(node);
+ }
}
catch (RepositoryException e)
{
- return null;
+ log.debug("{} loading path {} from workspace {}:{}", new Object[]{
+ e.getClass().getName(),
+ path,
+ repository,
+ e.getMessage() });
}
+ return null;
}
/**
@@ -1002,23 +1022,35 @@
}
/**
- * Get a Content node by its UUID. Internally uses JCR Criteria.
+ * Get a node by its UUID, wrapped as ContentMap.
* @param uuid content UUID
* @param repo workspace name
- * @return Content or null if not found
+ * @return ContentMap or null if not found
*/
- public static Content contentByUUID(String uuid, String repo)
+ public static ContentMap contentByUUID(String uuid, String repo) throws RepositoryException
{
if (StringUtils.isBlank(uuid))
{
return null;
}
- return JCRCriteriaFactory
- .createCriteria()
- .setWorkspace(repo)
- .add(Restrictions.eq("@jcr:uuid", uuid))
- .execute()
- .getFirstResult();
+
+ Session session;
+ try
+ {
+ session = MgnlContext.getJCRSession(repo);
+ Node loaded = session.getNodeByIdentifier(uuid);
+
+ if (loaded != null)
+ {
+ return wrapNode(loaded);
+ }
+ }
+ catch (ItemNotFoundException e)
+ {
+ // ignore
+ }
+
+ return null;
}
/**
@@ -1177,4 +1209,43 @@
}
}
+ public static ContentMap ancestor(Object nodeorcontent, int level)
+ {
+
+ Node node = MgnlUtilsDeprecatedAdapters.toNode(nodeorcontent);
+
+ if (node == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ if (node.getDepth() < level)
+ {
+ return null;
+ }
+ if (node.getDepth() == level)
+ {
+ return wrapNode(node);
+ }
+
+ return wrapNode((Node) node.getAncestor(level));
+ }
+ catch (RepositoryException e)
+ {
+ log.debug("Got a {} while loading level {} starting from {}: {}", new Object[]{
+ e.getClass().getName(),
+ level,
+ node,
+ e.getMessage() });
+ return null;
+ }
+
+ }
+
+ private static ContentMap wrapNode(Node node)
+ {
+ return new ContentMap(node);
+ }
}
Modified: magnoliamodules/trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld
===================================================================
--- magnoliamodules/trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2012-12-10 20:28:23 UTC (rev 4152)
+++ magnoliamodules/trunk/openutils-mgnlutils/src/main/resources/META-INF/tld/mgnlutils.tld 2012-12-17 20:30:42 UTC (rev 4153)
@@ -101,7 +101,7 @@
<description>Return the content of a given path and repository</description>
<name>contentByPath</name>
<function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class>
- <function-signature>info.magnolia.cms.core.Content contentByPath(java.lang.String, java.lang.String)</function-signature>
+ <function-signature>info.magnolia.jcr.util.ContentMap contentByPath(java.lang.String, java.lang.String)</function-signature>
<example>
<![CDATA[
${mu:contentByPath('Magnolia-Utils','website')}
@@ -339,10 +339,10 @@
<function-signature>void setActivePage(info.magnolia.cms.core.Content)</function-signature>
</function>
<function>
- <description>Get a Content node by its UUID. Internally uses JCR Criteria. Params are UUID and repository name.</description>
+ <description>Get a node by its UUID, wrapped as ContentMap.</description>
<name>contentByUUID</name>
<function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class>
- <function-signature>info.magnolia.cms.core.Content contentByUUID(java.lang.String, java.lang.String)</function-signature>
+ <function-signature>info.magnolia.jcr.util.ContentMap contentByUUID(java.lang.String, java.lang.String)</function-signature>
</function>
<function>
<description>Check if the current user belongs the given role</description>
@@ -436,5 +436,11 @@
<function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class>
<function-signature>java.util.Collection nodeDataIterator(info.magnolia.cms.core.Content, java.lang.String)</function-signature>
</function>
+ <function>
+ <description>Loads the ancestor of the given jcr Node/ContentMap. Returns null if the object is null or if requested level is greater than current depth</description>
+ <name>ancestor</name>
+ <function-class>it.openutils.mgnlutils.el.MgnlUtilsElFunctions</function-class>
+ <function-signature>info.magnolia.jcr.util.ContentMap ancestor(java.lang.Object, int)</function-signature>
+ </function>
<!-- please don't add new funtions without a meaningfull <description> -->
</taglib>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|