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 2006/02/10 12:22:50 UTC

svn commit: r376637 - in /lenya/trunk/src: java/org/apache/lenya/cms/migration/ modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/ modules/jcr/java/src/org/apache/lenya/cms/jcr/ modules/repository/java/src/org/apache/lenya/cms/cocoon/sour...

Author: andreas
Date: Fri Feb 10 03:22:45 2006
New Revision: 376637

URL: http://svn.apache.org/viewcvs?rev=376637&view=rev
Log:
Login to repository with user name.

Added:
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/cocoon/
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/cocoon/SessionUtil.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
    lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepository.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/cocoon/source/ContentSourceFactory.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/Repository.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java
    lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/url/URLUtil.java
    lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/repo/RepositoryTest.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java Fri Feb 10 03:22:45 2006
@@ -24,14 +24,6 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.lenya.cms.repo.mock.AssetTypeResolverImpl;
 import org.apache.lenya.cms.metadata.LenyaMetaData;
 import org.apache.lenya.cms.repo.Area;
 import org.apache.lenya.cms.repo.Asset;
@@ -44,6 +36,7 @@
 import org.apache.lenya.cms.repo.SiteNode;
 import org.apache.lenya.cms.repo.Translation;
 import org.apache.lenya.cms.repo.impl.AssetTypeImpl;
+import org.apache.lenya.cms.repo.mock.AssetTypeResolverImpl;
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
 import org.apache.tools.ant.BuildException;
@@ -129,7 +122,7 @@
                     getRepositoryFactory());
             repo.setAssetTypeResolver(new AssetTypeResolverImpl());
 
-            this.session = this.repo.createSession();
+            this.session = this.repo.login("john");
 
             File publicationsDirectory = new File(webappDirectory, PUBLICATION_PREFIX);
             File[] pubDirs = publicationsDirectory.listFiles(new FileFilter() {
@@ -181,8 +174,10 @@
 
         File contentDir = new File(pubDir, "content");
         File[] areaDirs = contentDir.listFiles(directoryFilter);
-        for (int i = 0; i < areaDirs.length; i++) {
-            importContent(areaDirs[i], pub);
+        if (areaDirs != null) {
+            for (int i = 0; i < areaDirs.length; i++) {
+                importContent(areaDirs[i], pub);
+            }
         }
     }
 
@@ -294,24 +289,6 @@
             throw new RepositoryException(e);
         }
         copy(in, out);
-        /*
-        try {
-            Transformer transformer = TransformerFactory.newInstance().newTransformer();
-            Source source = new StreamSource(file);
-            Result result = new StreamResult(out);
-            transformer.transform(source, result);
-        } catch (Exception e) {
-            throw new RepositoryException(e);
-        } finally {
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    throw new RepositoryException(e);
-                }
-            }
-        }
-        */
     }
 
     static void copy(InputStream fis, OutputStream fos) {

Modified: lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepository.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepository.java (original)
+++ lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepository.java Fri Feb 10 03:22:45 2006
@@ -31,9 +31,9 @@
         ((RepositoryImpl) getRepository()).shutdown();
     }
 
-    protected Session getSession(String workspaceName) throws RepositoryException {
+    protected Session getSession(String workspaceName, String userId) throws RepositoryException {
         try {
-            Session defaultWorkspaceSession = getRepository().login(new SimpleCredentials("john",
+            Session defaultWorkspaceSession = getRepository().login(new SimpleCredentials(userId,
                     "".toCharArray()));
             WorkspaceImpl defaultWorkspace = (WorkspaceImpl) defaultWorkspaceSession.getWorkspace();
             String[] workspaces = defaultWorkspace.getAccessibleWorkspaceNames();
@@ -42,7 +42,7 @@
                 // create = true;
             }
 
-            return getRepository().login(new SimpleCredentials("john", "".toCharArray()),
+            return getRepository().login(new SimpleCredentials(userId, "".toCharArray()),
                     workspaceName);
         } catch (javax.jcr.RepositoryException e) {
             throw new RepositoryException(e);

Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java Fri Feb 10 03:22:45 2006
@@ -48,11 +48,8 @@
         return this.repository;
     }
 
-    /**
-     * @return The repository session.
-     */
-    public org.apache.lenya.cms.repo.Session createSession() {
-        return new JCRSession(this);
+    public org.apache.lenya.cms.repo.Session login(String userId) {
+        return new JCRSession(this, userId);
     }
 
     private AssetTypeResolver typeResolver;
@@ -68,6 +65,7 @@
 
     private MetaDataRegistry metaDataRegistry;
     protected Session internalSession;
+    protected static final String INTERNAL_USER = "admin";
 
     public MetaDataRegistry getMetaDataRegistry() throws RepositoryException {
         if (this.metaDataRegistry == null) {
@@ -76,11 +74,12 @@
         return this.metaDataRegistry;
     }
 
-    protected abstract Session getSession(String workspaceName) throws RepositoryException;
+    protected abstract Session getSession(String workspaceName, String userId)
+            throws RepositoryException;
 
     protected Session getInternalSession() throws RepositoryException {
         if (this.internalSession == null) {
-            this.internalSession = getSession(INTERNAL_WORKSPACE);
+            this.internalSession = getSession(INTERNAL_WORKSPACE, INTERNAL_USER);
         }
         return this.internalSession;
     }

Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java Fri Feb 10 03:22:45 2006
@@ -39,13 +39,27 @@
  * Repository session.
  */
 public class JCRSession implements org.apache.lenya.cms.repo.Session {
+    
+    private String userId;
 
     /**
      * Ctor.
      * @param repository The repository facade.
+     * @param userId The user to log in.
      */
-    public JCRSession(JCRRepository repository) {
+    public JCRSession(JCRRepository repository, String userId) {
+        if (repository == null) {
+            throw new IllegalArgumentException("The repository must not be null!");
+        }
         this.repository = repository;
+        if (userId == null) {
+            throw new IllegalArgumentException("The user ID must not be null!");
+        }
+        this.userId = userId;
+    }
+    
+    protected String getUserId() {
+        return this.userId;
     }
 
     private JCRRepository repository;
@@ -67,7 +81,7 @@
             try {
                 // boolean create = false;
 
-                Session session = getJcrRepository().getSession(area);
+                Session session = getJcrRepository().getSession(area, getUserId());
                 facade = new RepositoryFacade(this,
                         session,
                         getRepository().getAssetTypeResolver(),

Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/cocoon/source/ContentSourceFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/cocoon/source/ContentSourceFactory.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/cocoon/source/ContentSourceFactory.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/cocoon/source/ContentSourceFactory.java Fri Feb 10 03:22:45 2006
@@ -28,12 +28,13 @@
 import org.apache.excalibur.source.SourceFactory;
 import org.apache.lenya.cms.repo.Area;
 import org.apache.lenya.cms.repo.Asset;
-import org.apache.lenya.cms.repo.Translation;
 import org.apache.lenya.cms.repo.Publication;
 import org.apache.lenya.cms.repo.Repository;
 import org.apache.lenya.cms.repo.Session;
 import org.apache.lenya.cms.repo.SiteNode;
+import org.apache.lenya.cms.repo.Translation;
 import org.apache.lenya.cms.repo.avalon.RepositoryFactory;
+import org.apache.lenya.cms.repo.cocoon.SessionUtil;
 
 /**
  * Repository source factory.
@@ -54,7 +55,7 @@
                 this.repository = factory.getRepository();
             }
 
-            Session session = this.repository.createSession();
+            Session session = SessionUtil.getSession(this.manager);
 
             String[] parts = location.split(":");
 
@@ -87,6 +88,8 @@
             } else {
                 throw new MalformedURLException("The locator must start with either one or two slashes.");
             }
+
+            session.logout();
 
         } catch (MalformedURLException e) {
             throw e;

Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/Repository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/Repository.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/Repository.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/Repository.java Fri Feb 10 03:22:45 2006
@@ -24,10 +24,11 @@
 public interface Repository {
 
     /**
+     * @param userId The user ID.
      * @return A session.
      * @throws RepositoryException if an error occurs.
      */
-    Session createSession() throws RepositoryException;
+    Session login(String userId) throws RepositoryException;
 
     /**
      * @return The meta data registry.

Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/adapter/RepoNodeFactory.java Fri Feb 10 03:22:45 2006
@@ -16,20 +16,17 @@
  */
 package org.apache.lenya.cms.repo.adapter;
 
-import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.lenya.cms.repo.Area;
 import org.apache.lenya.cms.repo.Asset;
-import org.apache.lenya.cms.repo.AssetTypeResolver;
 import org.apache.lenya.cms.repo.Publication;
-import org.apache.lenya.cms.repo.Repository;
 import org.apache.lenya.cms.repo.RepositoryException;
 import org.apache.lenya.cms.repo.SiteNode;
 import org.apache.lenya.cms.repo.Translation;
-import org.apache.lenya.cms.repo.avalon.RepositoryFactory;
+import org.apache.lenya.cms.repo.cocoon.SessionUtil;
 import org.apache.lenya.cms.repository.Node;
 import org.apache.lenya.cms.repository.NodeFactory;
 import org.apache.lenya.cms.repository.Session;
@@ -40,8 +37,7 @@
 /**
  * Repository node factory.
  */
-public class RepoNodeFactory extends AbstractLogEnabled implements NodeFactory, Serviceable,
-        Initializable {
+public class RepoNodeFactory extends AbstractLogEnabled implements NodeFactory, Serviceable {
 
     private Session oldSession;
 
@@ -68,11 +64,13 @@
         } else {
 
             try {
-                String language = docPath.substring(underscoreIndex + 1, underscoreIndex + 3);
 
+                org.apache.lenya.cms.repo.Session session = SessionUtil.getSession(this.manager);
+                
+                String language = docPath.substring(underscoreIndex + 1, underscoreIndex + 3);
                 docPath = docPath.substring(0, docPath.length() - "/index_de.xml".length());
 
-                Publication pub = this.session.getPublication(pubId);
+                Publication pub = session.getPublication(pubId);
                 Area area = pub.getArea(areaId);
 
                 Translation trans = null;
@@ -97,27 +95,9 @@
     }
 
     private ServiceManager manager;
-    private org.apache.lenya.cms.repo.Session session;
 
     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
-    }
-
-    public void initialize() throws Exception {
-        RepositoryFactory factory = null;
-        try {
-            factory = (RepositoryFactory) manager.lookup(RepositoryFactory.ROLE);
-            Repository repository = factory.getRepository();
-            AssetTypeResolver resolver = new ResourceTypeWrapperResolver(this.manager);
-            repository.setAssetTypeResolver(resolver);
-            this.session = repository.createSession();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        } finally {
-            if (factory != null) {
-                manager.release(factory);
-            }
-        }
     }
 
 }

Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java Fri Feb 10 03:22:45 2006
@@ -24,18 +24,23 @@
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.lenya.cms.repo.AssetTypeResolver;
 import org.apache.lenya.cms.repo.Repository;
 import org.apache.lenya.cms.repo.RepositoryException;
 import org.apache.lenya.cms.repo.RepositoryManager;
+import org.apache.lenya.cms.repo.adapter.ResourceTypeWrapperResolver;
 
 /**
  * Repository factory implementation.
  */
 public class RepositoryFactoryImpl implements RepositoryFactory, Contextualizable, Configurable,
-        ThreadSafe {
+        ThreadSafe, Serviceable {
 
     public void contextualize(Context context) throws ContextException {
         this.context = context;
@@ -54,8 +59,16 @@
             Map objectModel = ContextHelper.getObjectModel(this.context);
             String webappPath = ObjectModelHelper.getContext(objectModel).getRealPath("/");
             this.repository = RepositoryManager.getRepository(webappPath, this.factoryClassName);
+            AssetTypeResolver resolver = new ResourceTypeWrapperResolver(manager);
+            this.repository.setAssetTypeResolver(resolver);
         }
         return this.repository;
+    }
+    
+    private ServiceManager manager;
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
     }
 
 }

Added: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/cocoon/SessionUtil.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/cocoon/SessionUtil.java?rev=376637&view=auto
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/cocoon/SessionUtil.java (added)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/repo/cocoon/SessionUtil.java Fri Feb 10 03:22:45 2006
@@ -0,0 +1,96 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo.cocoon;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
+import org.apache.lenya.cms.repo.Repository;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.Session;
+import org.apache.lenya.cms.repo.avalon.RepositoryFactory;
+
+/**
+ * Session utility class.
+ */
+public class SessionUtil {
+
+    /**
+     * @param manager The service manager.
+     * @return The current session.
+     * @throws RepositoryException if an error occurs.
+     */
+    public static Session getSession(ServiceManager manager) throws RepositoryException {
+        ContextUtility context = null;
+        try {
+            context = (ContextUtility) manager.lookup(ContextUtility.ROLE);
+            Request request = context.getRequest();
+            org.apache.cocoon.environment.Session cocoonSession = request.getSession(true);
+
+            Session session = (Session) cocoonSession.getAttribute(Session.class.getName());
+            if (session == null) {
+                session = createSession(manager, request);
+                cocoonSession.setAttribute(Session.class.getName(), session);
+            }
+            return session;
+        } catch (RepositoryException e) {
+            throw e;
+        } catch (ServiceException e) {
+            throw new RepositoryException(e);
+        } finally {
+            if (context != null) {
+                manager.release(context);
+            }
+        }
+    }
+
+    protected static Session createSession(ServiceManager manager, Request request)
+            throws ServiceException, RepositoryException {
+        Session session;
+        RepositoryFactory factory = null;
+        try {
+            factory = (RepositoryFactory) manager.lookup(RepositoryFactory.ROLE);
+            Repository repo = factory.getRepository();
+
+            User user = getUserId(request);
+
+            session = repo.login(user.getId());
+        } finally {
+            if (factory != null) {
+                manager.release(factory);
+            }
+        }
+        return session;
+    }
+
+    protected static User getUserId(Request request) throws RepositoryException {
+        Identity identity = (Identity) request.getSession(false)
+                .getAttribute(Identity.class.getName());
+        if (identity == null) {
+            throw new RepositoryException("The session doesn't contain an identity.");
+        }
+        User user = identity.getUser();
+        if (user == null) {
+            throw new RepositoryException("The identity doesn't contain a user.");
+        }
+        return user;
+    }
+
+}

Modified: lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/url/URLUtil.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/url/URLUtil.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/url/URLUtil.java (original)
+++ lenya/trunk/src/modules/repository/java/src/org/apache/lenya/cms/url/URLUtil.java Fri Feb 10 03:22:45 2006
@@ -22,11 +22,10 @@
 import org.apache.lenya.cms.publication.URLInformation;
 import org.apache.lenya.cms.repo.Area;
 import org.apache.lenya.cms.repo.Publication;
-import org.apache.lenya.cms.repo.Repository;
 import org.apache.lenya.cms.repo.RepositoryException;
 import org.apache.lenya.cms.repo.Session;
 import org.apache.lenya.cms.repo.Translation;
-import org.apache.lenya.cms.repo.avalon.RepositoryFactory;
+import org.apache.lenya.cms.repo.cocoon.SessionUtil;
 import org.apache.lenya.cms.repo.metadata.MetaData;
 import org.apache.lenya.cms.repo.metadata.MetaDataRegistry;
 import org.apache.lenya.cms.url.impl.LanguageSuffixMapper;
@@ -39,34 +38,6 @@
 
     /**
      * @param manager The service manager.
-     * @param request The request object.
-     * @param logger The logger to use.
-     * @return A session.
-     */
-    public static Session getSession(ServiceManager manager, Request request, Logger logger) {
-        Session session = (Session) request.getAttribute(Session.class.getName());
-        if (session == null) {
-
-            RepositoryFactory factory = null;
-            try {
-                factory = (RepositoryFactory) manager.lookup(RepositoryFactory.ROLE);
-                Repository repository = factory.getRepository();
-                session = repository.createSession();
-                request.setAttribute(Session.class.getName(), session);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            } finally {
-                if (factory != null) {
-                    manager.release(factory);
-                }
-            }
-
-        }
-        return session;
-    }
-
-    /**
-     * @param manager The service manager.
      * @param request The request.
      * @param logger The logger.
      * @return A publication.
@@ -74,7 +45,7 @@
      */
     public static Publication getPublication(ServiceManager manager, Request request, Logger logger)
             throws RepositoryException {
-        Session session = getSession(manager, request, logger);
+        Session session = SessionUtil.getSession(manager);
         String url = ServletHelper.getWebappURI(request);
         String pubId = new URLInformation(url).getPublicationId();
         return session.getPublication(pubId);

Modified: lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/repo/RepositoryTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/repo/RepositoryTest.java?rev=376637&r1=376636&r2=376637&view=diff
==============================================================================
--- lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/repo/RepositoryTest.java (original)
+++ lenya/trunk/src/modules/repository/java/test/org/apache/lenya/cms/repo/RepositoryTest.java Fri Feb 10 03:22:45 2006
@@ -108,7 +108,7 @@
         System.out.println("Starting test");
 
         this.repo = RepositoryManager.getRepository(getWebappDirectory(), getRepositoryFactory());
-        Session session = repo.createSession();
+        Session session = repo.login("john");
 
         URL schemaUrl = getClass().getResource("schema.xml");
         Schema schema = new Schema(Validator.GRAMMAR_RELAX_NG, schemaUrl.toString());



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