svn commit: r741388 - in /lenya/trunk/org.apache.lenya.core.impl/src/main: java/org/apache/lenya/cms/publication/ resources/META-INF/cocoon/spring/

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Fri Feb  6 03:37:53 2009
New Revision: 741388

URL: http://svn.apache.org/viewvc?rev=741388&view=rev
Log:
Springify Lenya core components.

Modified:
    lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/AreaImpl.java
    lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationFactory.java
    lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationImpl.java
    lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java
    lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/AreaImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/AreaImpl.java?rev=741388&r1=741387&r2=741388&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/AreaImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/AreaImpl.java Fri Feb  6 03:37:53 2009
@@ -20,9 +20,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.lenya.cms.repository.Node;
 import org.apache.lenya.cms.repository.NodeFactory;
 import org.apache.lenya.cms.repository.RepositoryException;
@@ -41,19 +39,17 @@
     private Publication pub;
     private DocumentFactory factory;
     private NodeFactory nodeFactory;
-    private ServiceManager manager;
 
     /**
-     * @param manager The service manager.
      * @param factory The factory.
      * @param pub The publication.
      * @param name The area name.
      */
-    public AreaImpl(ServiceManager manager, DocumentFactory factory, Publication pub, String name) {
-        this.manager = manager;
+    public AreaImpl(DocumentFactory factory, NodeFactory nodeFactory, Publication pub, String name) {
         this.factory = factory;
         this.pub = pub;
         this.name = name;
+        this.nodeFactory = nodeFactory;
     }
 
     public boolean contains(String uuid, String language) {
@@ -78,13 +74,6 @@
     }
 
     protected NodeFactory getNodeFactory() {
-        if (this.nodeFactory == null) {
-            try {
-                this.nodeFactory = (NodeFactory) this.manager.lookup(NodeFactory.ROLE);
-            } catch (ServiceException e) {
-                throw new RuntimeException(e);
-            }
-        }
         return this.nodeFactory;
     }
 
@@ -105,20 +94,12 @@
     public SiteStructure getSite() {
         if (this.site == null) {
             SiteManager siteManager = null;
-            ServiceSelector selector = null;
             try {
-                selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
-                siteManager = (SiteManager) selector.select(getPublication().getSiteManagerHint());
+                siteManager = (SiteManager) WebAppContextUtils.getCurrentWebApplicationContext()
+                        .getBean(SiteManager.ROLE + "/" + getPublication().getSiteManagerHint());
                 this.site = siteManager.getSiteStructure(this.factory, getPublication(), getName());
             } catch (Exception e) {
                 throw new RuntimeException(e);
-            } finally {
-                if (selector != null) {
-                    if (siteManager != null) {
-                        selector.release(siteManager);
-                    }
-                    this.manager.release(selector);
-                }
             }
         }
         return this.site;

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationFactory.java?rev=741388&r1=741387&r2=741388&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationFactory.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationFactory.java Fri Feb  6 03:37:53 2009
@@ -17,7 +17,7 @@
  */
 package org.apache.lenya.cms.publication;
 
-import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.repository.NodeFactory;
 import org.apache.lenya.cms.repository.RepositoryException;
 import org.apache.lenya.cms.repository.RepositoryItem;
 import org.apache.lenya.cms.repository.RepositoryItemFactory;
@@ -28,21 +28,23 @@
  */
 public class PublicationFactory implements RepositoryItemFactory {
 
-    private ServiceManager manager;
     private PublicationConfiguration config;
+    private DocumentFactoryBuilder documentFactoryBuilder;
+    private NodeFactory nodeFactory;
 
     /**
-     * @param manager The service manager.
      * @param config The publication configuration.
      */
-    public PublicationFactory(ServiceManager manager, PublicationConfiguration config) {
-        this.manager = manager;
+    public PublicationFactory(DocumentFactoryBuilder builder, NodeFactory nodeFactory,
+            PublicationConfiguration config) {
         this.config = config;
+        this.documentFactoryBuilder = builder;
+        this.nodeFactory = nodeFactory;
     }
 
     public RepositoryItem buildItem(Session session, String key) throws RepositoryException {
-        DocumentFactory factory = DocumentUtil.createDocumentFactory(this.manager, session);
-        return new PublicationImpl(this.manager, factory, config);
+        DocumentFactory factory = this.documentFactoryBuilder.createDocumentFactory(session);
+        return new PublicationImpl(factory, this.nodeFactory, config);
     }
 
     public String getItemType() {

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationImpl.java?rev=741388&r1=741387&r2=741388&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationImpl.java Fri Feb  6 03:37:53 2009
@@ -25,11 +25,10 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.cocoon.util.AbstractLogEnabled;
-import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
+import org.apache.lenya.cms.repository.NodeFactory;
 import org.apache.lenya.cms.repository.Session;
 
 /**
@@ -39,14 +38,14 @@
 public class PublicationImpl extends AbstractLogEnabled implements Publication {
 
     private PublicationConfiguration delegate;
-    protected ServiceManager manager;
     private DocumentFactory factory;
+    private NodeFactory nodeFactory;
 
-    protected PublicationImpl(ServiceManager manager, DocumentFactory factory,
+    protected PublicationImpl(DocumentFactory factory, NodeFactory nodeFactory,
             PublicationConfiguration delegate) {
         this.delegate = delegate;
-        this.manager = manager;
         this.factory = factory;
+        this.nodeFactory = nodeFactory;
     }
 
     public boolean exists() {
@@ -78,13 +77,14 @@
     }
 
     private DocumentBuilder documentBuilder;
-    
+
     public DocumentBuilder getDocumentBuilder() {
         if (this.documentBuilder == null) {
-            ServiceSelector selector = null;
             try {
-                selector = (ServiceSelector) this.manager.lookup(DocumentBuilder.ROLE + "Selector");
-                this.documentBuilder = (DocumentBuilder) selector.select(delegate.getDocumentBuilderHint());
+                this.documentBuilder = (DocumentBuilder) WebAppContextUtils
+                        .getCurrentWebApplicationContext()
+                        .getBean(
+                                DocumentBuilder.class.getName() + delegate.getDocumentBuilderHint());
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }
@@ -115,23 +115,14 @@
     public Proxy getProxy(String area, boolean isSslProtected) {
         return delegate.getProxy(area, isSslProtected);
     }
-    
+
     private String contextPath;
-    
+
     protected String getContextPath() {
         if (this.contextPath == null) {
-            ContextUtility context = null;
-            try {
-                context = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
-                this.contextPath = context.getRequest().getContextPath();
-            } catch (ServiceException e) {
-                throw new RuntimeException(e);
-            }
-            finally {
-                if (context != null) {
-                    this.manager.release(context);
-                }
-            }
+            ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
+                    .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
+            this.contextPath = process.getRequest().getContextPath();
         }
         return this.contextPath;
     }
@@ -195,10 +186,10 @@
     }
 
     private Map areas = new HashMap();
-    
+
     public Area getArea(String name) throws PublicationException {
         if (!this.areas.containsKey(name)) {
-            Area area = new AreaImpl(this.manager, this.factory, this, name);
+            Area area = new AreaImpl(this.factory, this.nodeFactory, this, name);
             this.areas.put(name, area);
         }
         return (Area) this.areas.get(name);

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java?rev=741388&r1=741387&r2=741388&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationManagerImpl.java Fri Feb  6 03:37:53 2009
@@ -29,48 +29,43 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.container.ContainerUtil;
-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.processing.ProcessInfoProvider;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.cocoon.util.AbstractLogEnabled;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.SourceUtil;
-import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
+import org.apache.lenya.cms.repository.NodeFactory;
 import org.apache.lenya.cms.repository.RepositoryException;
 import org.apache.lenya.util.Assert;
 
 /**
  * Factory for creating publication objects.
  */
-public final class PublicationManagerImpl extends AbstractLogEnabled implements PublicationManager,
-        Serviceable, Initializable, ThreadSafe {
-
-    /**
-     * Create a new <code>PublicationFactory</code>.
-     */
-    public PublicationManagerImpl() {
-    }
+public final class PublicationManagerImpl extends AbstractLogEnabled implements PublicationManager {
 
     private Map id2config;
+    private DocumentFactoryBuilder documentFactoryBuilder;
+    private NodeFactory nodeFactory;
 
     protected synchronized Map getId2config() throws PublicationException {
         if (this.id2config == null) {
             this.id2config = new HashMap();
-            File servletContext = new File(this.servletContextPath);
+            File servletContext = new File(getServletContextPath());
             File publicationsDirectory = new File(servletContext, Publication.PUBLICATION_PREFIX);
-            File[] publicationDirectories = publicationsDirectory.listFiles(new FileFilter() {
-                public boolean accept(File file) {
-                    File configFile = new File(file, PublicationConfiguration.CONFIGURATION_FILE);
-                    return configFile.exists();
+            if (publicationsDirectory.isDirectory()) {
+                File[] publicationDirectories = publicationsDirectory.listFiles(new FileFilter() {
+                    public boolean accept(File file) {
+                        File configFile = new File(file,
+                                PublicationConfiguration.CONFIGURATION_FILE);
+                        return configFile.exists();
+                    }
+                });
+                for (int i = 0; i < publicationDirectories.length; i++) {
+                    String id = publicationDirectories[i].getName();
+                    addPublication(id);
                 }
-            });
-            for (int i = 0; i < publicationDirectories.length; i++) {
-                String id = publicationDirectories[i].getName();
-                addPublication(id);
+            } else {
+                getLogger().warn(
+                        "The publications directory " + publicationsDirectory.getAbsolutePath()
+                                + " does not exist.");
             }
         }
         return this.id2config;
@@ -86,7 +81,8 @@
         }
 
         PublicationConfiguration config = (PublicationConfiguration) id2config.get(id);
-        PublicationFactory pubFactory = new PublicationFactory(this.manager, config);
+        PublicationFactory pubFactory = new PublicationFactory(getDocumentFactoryBuilder(),
+                getNodeFactory(), config);
         try {
             return (Publication) factory.getSession().getRepositoryItem(pubFactory, id);
         } catch (RepositoryException e) {
@@ -123,54 +119,37 @@
         return (String[]) ids.toArray(new String[ids.size()]);
     }
 
-    private String servletContextPath;
-
-    private ServiceManager manager;
-
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-    }
-
-    public void initialize() throws Exception {
-        SourceResolver resolver = null;
-        Source source = null;
-        try {
-            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
-            source = resolver.resolveURI("context:///");
-            this.servletContextPath = SourceUtil.getFile(source).getCanonicalPath();
-        } finally {
-            if (resolver != null) {
-                if (source != null) {
-                    resolver.release(source);
-                }
-                this.manager.release(resolver);
-            }
-        }
-    }
-
     public void addPublication(String pubId) throws PublicationException {
         Map id2config = getId2config();
         if (id2config.containsKey(pubId)) {
             throw new PublicationException("The publication [" + pubId + "] already exists.");
         }
-        ContextUtility context = null;
-        try {
-            context = (ContextUtility) this.manager.lookup(ContextUtility.ROLE);
-            PublicationConfiguration config = new PublicationConfiguration(pubId,
-                    this.servletContextPath, context.getRequest().getContextPath());
-            id2config.put(pubId, config);
-        } catch (ServiceException e) {
-            throw new PublicationException(e);
-        }
-        finally {
-            if (context != null) {
-                this.manager.release(context);
-            }
-        }
+        ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
+                .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
+        PublicationConfiguration config = new PublicationConfiguration(pubId,
+                getServletContextPath(), process.getRequest().getContextPath());
+        id2config.put(pubId, config);
     }
 
     protected String getServletContextPath() {
-        return this.servletContextPath;
+        return WebAppContextUtils.getCurrentWebApplicationContext().getServletContext()
+                .getRealPath("/");
+    }
+
+    public DocumentFactoryBuilder getDocumentFactoryBuilder() {
+        return documentFactoryBuilder;
+    }
+
+    public void setDocumentFactoryBuilder(DocumentFactoryBuilder documentFactoryBuilder) {
+        this.documentFactoryBuilder = documentFactoryBuilder;
+    }
+
+    public NodeFactory getNodeFactory() {
+        return nodeFactory;
+    }
+
+    public void setNodeFactory(NodeFactory nodeFactory) {
+        this.nodeFactory = nodeFactory;
     }
 
 }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml?rev=741388&r1=741387&r2=741388&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml Fri Feb  6 03:37:53 2009
@@ -26,7 +26,10 @@
     <property name="sharedItemStore" ref="org.apache.lenya.cms.repository.SharedItemStore"/>
   </bean>
   <bean name="org.apache.lenya.cms.publication.PublicationManager"
-    class="org.apache.lenya.cms.publication.PublicationManagerImpl"/>
+    class="org.apache.lenya.cms.publication.PublicationManagerImpl">
+    <property name="documentFactoryBuilder" ref="org.apache.lenya.cms.publication.DocumentFactoryBuilder"/>
+    <property name="nodeFactory" ref="org.apache.lenya.cms.repository.NodeFactory"/>
+  </bean>
   <bean name="org.apache.lenya.cms.metadata.MetaDataCache"
     class="org.apache.lenya.cms.metadata.MetaDataCache"/>
   <bean name="org.apache.lenya.cms.publication.DocumentFactoryBuilder"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.