You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2007/02/21 16:58:17 UTC

svn commit: r510069 - /lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java

Author: andreas
Date: Wed Feb 21 07:58:16 2007
New Revision: 510069

URL: http://svn.apache.org/viewvc?view=rev&rev=510069
Log:
Allow to specify the session when obtaining a lenya-document source

Modified:
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java

Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java?view=diff&rev=510069&r1=510068&r2=510069
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java Wed Feb 21 07:58:16 2007
@@ -24,6 +24,7 @@
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
@@ -33,6 +34,9 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.flow.FlowHelper;
+import org.apache.cocoon.components.modules.input.JXPathHelper;
+import org.apache.cocoon.components.modules.input.JXPathHelperConfiguration;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.excalibur.source.Source;
@@ -45,6 +49,7 @@
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.DocumentFactory;
 import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.repository.RepositoryException;
 import org.apache.lenya.cms.repository.RepositoryUtil;
 import org.apache.lenya.cms.repository.Session;
 import org.apache.lenya.util.Query;
@@ -52,8 +57,8 @@
 
 /**
  * <p>
- * This source factory allows to access documents using the
- * link syntax of the {@link org.apache.lenya.cms.linking.LinkResolver}.
+ * This source factory allows to access documents using the link syntax of the
+ * {@link org.apache.lenya.cms.linking.LinkResolver}.
  * </p>
  * <p>
  * Additional parameters:
@@ -124,9 +129,11 @@
             Document doc = target.getDocument();
 
             String format = null;
+            String sessionName = null;
             if (queryString != null) {
                 Query query = new Query(queryString);
                 format = query.getValue("format");
+                sessionName = query.getValue("session");
             }
             if (format != null) {
                 return getFormatSource(doc, format);
@@ -135,7 +142,7 @@
                 if (target.isRevisionSpecified()) {
                     lenyaURL += "?rev=" + target.getRevisionNumber();
                 }
-                Session session = RepositoryUtil.getSession(this.manager, request);
+                Session session = getSession(objectModel, sessionName);
                 return new RepositorySource(manager, lenyaURL, session, getLogger());
             }
 
@@ -143,6 +150,32 @@
             throw new RuntimeException(e);
         }
 
+    }
+
+    protected Session getSession(Map objectModel, String sessionName) throws RepositoryException {
+        Session session;
+        if (sessionName == null) {
+            Request request = ObjectModelHelper.getRequest(objectModel);
+            session = RepositoryUtil.getSession(this.manager, request);
+        } else if (sessionName.equals("usecase")) {
+            session = getUsecaseSession(objectModel);
+        } else {
+            throw new RepositoryException("Invalid session: [" + sessionName + "]");
+        }
+
+        return session;
+    }
+
+    protected Session getUsecaseSession(Map objectModel) throws RepositoryException {
+        try {
+            Configuration config = new DefaultConfiguration("foo");
+            JXPathHelperConfiguration helperConfig = JXPathHelper.setup(config);
+            Object contextObject = FlowHelper.getContextObject(objectModel);
+            return (Session) JXPathHelper.getAttribute("usecase/session", config, helperConfig,
+                    contextObject);
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
     }
 
     protected Source getFormatSource(Document doc, String format) throws DocumentException,



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org