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/04/30 14:34:27 UTC

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

Author: andreas
Date: Mon Apr 30 05:34:26 2007
New Revision: 533723

URL: http://svn.apache.org/viewvc?view=rev&rev=533723
Log:
Move session selection from DocumentSourceFactory to LenyaSourceFactory. This fixes bugs 42237 and 42266.

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

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/LenyaSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/LenyaSourceFactory.java?view=diff&rev=533723&r1=533722&r2=533723
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/LenyaSourceFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/LenyaSourceFactory.java Mon Apr 30 05:34:26 2007
@@ -20,6 +20,8 @@
 import java.net.MalformedURLException;
 import java.util.Map;
 
+import org.apache.avalon.framework.configuration.Configuration;
+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;
@@ -29,6 +31,10 @@
 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;
 import org.apache.excalibur.source.SourceException;
@@ -37,6 +43,7 @@
 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;
 
 /**
  * A factory for the "lenya" scheme (virtual protocol), which is used to resolve any src="lenya:..."
@@ -79,10 +86,17 @@
     public Source getSource(final String location, final Map parameters)
             throws MalformedURLException, IOException, SourceException {
 
-        Request request = ContextHelper.getRequest(this.context);
+        String sessionName = null;
+        
+        String[] uriAndQuery = location.split("\\?");
+        if (uriAndQuery.length > 1) {
+            Query query = new Query(uriAndQuery[1]);
+            sessionName = query.getValue("session");
+        }
+
         Session session;
         try {
-            session = RepositoryUtil.getSession(this.manager, request);
+            session = getSession(sessionName);
         } catch (RepositoryException e) {
             throw new RuntimeException(e);
         }
@@ -93,6 +107,33 @@
 
         return new RepositorySource(this.manager, location, session, getLogger());
 
+    }
+
+    protected Session getSession(String sessionName) throws RepositoryException {
+        Map objectModel = ContextHelper.getObjectModel(this.context);
+        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);
+        }
     }
 
     /**

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=533723&r1=533722&r2=533723
==============================================================================
--- 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 Mon Apr 30 05:34:26 2007
@@ -24,7 +24,6 @@
 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;
@@ -34,9 +33,6 @@
 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;
@@ -49,9 +45,6 @@
 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;
 import org.apache.lenya.util.ServletHelper;
 
@@ -162,32 +155,6 @@
             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