svn commit: r742672 [3/6] - in /lenya/trunk: org.apache.lenya.core.ac/src/main/java/org/apache/lenya/cms/ac/ org.apache.lenya.core.acusecases/src/main/java/org/apache/lenya/cms/ac/usecases/ org.apache.lenya.core.administration/src/main/java/org/apache/...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java Mon Feb  9 18:49:13 2009
@@ -26,9 +26,9 @@
 import java.util.List;
 
 import org.apache.cocoon.spring.configurator.WebAppContextUtils;
-import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.commons.lang.Validate;
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
 import org.apache.lenya.cms.metadata.MetaData;
@@ -48,10 +48,12 @@
  * A typical CMS document.
  * @version $Id$
  */
-public class DocumentImpl extends AbstractLogEnabled implements Document {
+public class DocumentImpl implements Document {
+
+    private static final Log logger = LogFactory.getLog(DocumentImpl.class);
 
     private DocumentIdentifier identifier;
-    private DocumentFactory factory;
+    private org.apache.lenya.cms.publication.Session session;
     private NodeFactory nodeFactory;
     private int revision = -1;
 
@@ -89,19 +91,16 @@
 
     /**
      * Creates a new instance of DefaultDocument.
-     * @param manager The service manager.
-     * @param map The identity map the document belongs to.
+     * @param session The session the document belongs to.
      * @param identifier The identifier.
      * @param revision The revision number or -1 if the latest revision should be used.
-     * @param _logger a logger
      */
-    protected DocumentImpl(DocumentFactory map, DocumentIdentifier identifier, int revision,
-            Log logger) {
+    protected DocumentImpl(org.apache.lenya.cms.publication.Session session,
+            DocumentIdentifier identifier, int revision) {
 
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug(
-                    "DefaultDocument() creating new instance with id [" + identifier.getUUID()
-                            + "], language [" + identifier.getLanguage() + "]");
+        if (logger.isDebugEnabled()) {
+            logger.debug("DefaultDocument() creating new instance with id [" + identifier.getUUID()
+                    + "], language [" + identifier.getLanguage() + "]");
         }
 
         if (identifier.getUUID() == null) {
@@ -109,13 +108,12 @@
         }
 
         this.identifier = identifier;
-        this.factory = map;
+        this.session = session;
         this.revision = revision;
 
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug(
-                    "DefaultDocument() done building instance with _id [" + identifier.getUUID()
-                            + "], _language [" + identifier.getLanguage() + "]");
+        if (logger.isDebugEnabled()) {
+            logger.debug("DefaultDocument() done building instance with _id ["
+                    + identifier.getUUID() + "], _language [" + identifier.getLanguage() + "]");
         }
     }
 
@@ -169,11 +167,7 @@
      */
     public Publication getPublication() {
         if (this.publication == null) {
-            try {
-                this.publication = getFactory().getPublication(getIdentifier().getPublicationId());
-            } catch (PublicationException e) {
-                throw new RuntimeException(e);
-            }
+            this.publication = getSession().getPublication(getIdentifier().getPublicationId());
         }
         return this.publication;
     }
@@ -194,23 +188,17 @@
                 getLanguage());
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.Document#getLanguage()
-     */
     public String getLanguage() {
         return this.identifier.getLanguage();
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.Document#getLanguages()
-     */
-    public String[] getLanguages() throws DocumentException {
+    public String[] getLanguages() {
 
         List documentLanguages = new ArrayList();
         String[] allLanguages = getPublication().getLanguages();
 
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Number of languages of this publication: " + allLanguages.length);
+        if (logger.isDebugEnabled()) {
+            logger.debug("Number of languages of this publication: " + allLanguages.length);
         }
 
         for (int i = 0; i < allLanguages.length; i++) {
@@ -222,9 +210,6 @@
         return (String[]) documentLanguages.toArray(new String[documentLanguages.size()]);
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.Document#getArea()
-     */
     public String getArea() {
         return this.identifier.getArea();
     }
@@ -239,7 +224,7 @@
         if (extension == null) {
             String sourceExtension = getSourceExtension();
             if (sourceExtension.equals("xml") || sourceExtension.equals("")) {
-                getLogger().info("Default extension will be used: " + defaultExtension);
+                logger.info("Default extension will be used: " + defaultExtension);
                 return defaultExtension;
             } else {
                 return sourceExtension;
@@ -269,9 +254,8 @@
             throw new RuntimeException(e);
         }
         if (sourceExtension == null) {
-            getLogger().warn(
-                    "No source extension for document [" + this + "]. The extension \""
-                            + defaultSourceExtension + "\" will be used as default!");
+            logger.warn("No source extension for document [" + this + "]. The extension \""
+                    + defaultSourceExtension + "\" will be used as default!");
             sourceExtension = defaultSourceExtension;
         }
         return sourceExtension;
@@ -282,34 +266,27 @@
      * @param _extension A string.
      */
     protected void setExtension(String _extension) {
-    	Validate.notNull(_extension);
+        Validate.notNull(_extension);
         Validate.isTrue(!_extension.startsWith("."), "Extension must start with a dot");
         checkWritability();
         this.extension = _extension;
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.Document#exists()
-     */
-    public boolean exists() throws DocumentException {
+    public boolean exists() throws ResourceNotFoundException {
         try {
             return getRepositoryNode().exists();
         } catch (RepositoryException e) {
-            throw new DocumentException(e);
+            throw new ResourceNotFoundException(e);
         }
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.Document#existsInAnyLanguage()
-     */
-    public boolean existsInAnyLanguage() throws DocumentException {
+    public boolean existsInAnyLanguage() throws ResourceNotFoundException {
         String[] languages = getLanguages();
 
         if (languages.length > 0) {
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug(
-                        "Document (" + this + ") exists in at least one language: "
-                                + languages.length);
+            if (logger.isDebugEnabled()) {
+                logger.debug("Document (" + this + ") exists in at least one language: "
+                        + languages.length);
             }
             String[] allLanguages = getPublication().getLanguages();
             if (languages.length == allLanguages.length)
@@ -317,15 +294,14 @@
                 // could assume the
                 // languages EN and DE, but the document could exist for the
                 // languages DE and FR!
-                if (getLogger().isDebugEnabled()) {
-                    getLogger().debug(
-                            "Document (" + this
-                                    + ") exists even in all languages of this publication");
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Document (" + this
+                            + ") exists even in all languages of this publication");
                 }
             return true;
         } else {
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Document (" + this + ") does NOT exist in any language");
+            if (logger.isDebugEnabled()) {
+                logger.debug("Document (" + this + ") does NOT exist in any language");
             }
             return false;
         }
@@ -366,13 +342,6 @@
     }
 
     /**
-     * @see org.apache.lenya.cms.publication.Document#getFactory()
-     */
-    public DocumentFactory getFactory() {
-        return this.factory;
-    }
-
-    /**
      * @see org.apache.lenya.cms.publication.Document#getCanonicalWebappURL()
      */
     public String getCanonicalWebappURL() {
@@ -385,7 +354,7 @@
     public String getCanonicalDocumentURL() {
         try {
             DocumentBuilder builder = getPublication().getDocumentBuilder();
-            String webappUrl = builder.buildCanonicalUrl(getFactory(), getLocator());
+            String webappUrl = builder.buildCanonicalUrl(getSession(), getLocator());
             String prefix = "/" + getPublication().getId() + "/" + getArea();
             return webappUrl.substring(prefix.length());
         } catch (Exception e) {
@@ -393,10 +362,11 @@
         }
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.Document#accept(org.apache.lenya.cms.publication.util.DocumentVisitor)
-     */
-    public void accept(DocumentVisitor visitor) throws PublicationException {
+    public org.apache.lenya.cms.publication.Session getSession() {
+        return this.session;
+    }
+
+    public void accept(DocumentVisitor visitor) throws Exception {
         visitor.visitDocument(this);
     }
 
@@ -444,7 +414,7 @@
 
     public MetaData getMetaData(String namespaceUri) throws MetaDataException {
         MetaData meta = getContentHolder().getMetaData(namespaceUri);
-        if (getSession().isModifiable()) {
+        if (getRepositorySession().isModifiable()) {
             return meta;
         } else {
             String cacheKey = getPublication().getId() + ":" + getArea() + ":" + getUUID() + ":"
@@ -473,20 +443,20 @@
         }
     }
 
-    public long getContentLength() throws DocumentException {
+    public long getContentLength() {
         try {
             return getContentHolder().getContentLength();
         } catch (RepositoryException e) {
-            throw new DocumentException(e);
+            throw new RuntimeException(e);
         }
     }
 
-    public void setMimeType(String mimeType) throws DocumentException {
+    public void setMimeType(String mimeType) {
         checkWritability();
         try {
             getMetaData(METADATA_NAMESPACE).setValue(METADATA_MIME_TYPE, mimeType);
         } catch (MetaDataException e) {
-            throw new DocumentException(e);
+            throw new RuntimeException(e);
         }
     }
 
@@ -521,20 +491,12 @@
         return area().contains(getUUID(), language);
     }
 
-    public Document getAreaVersion(String area) throws DocumentException {
-        try {
-            return getFactory().get(getPublication(), area, getUUID(), getLanguage());
-        } catch (DocumentBuildException e) {
-            throw new DocumentException(e);
-        }
+    public Document getAreaVersion(String area) throws ResourceNotFoundException {
+        return getPublication().getArea(area).getDocument(getUUID(), getLanguage());
     }
 
-    public Document getTranslation(String language) throws DocumentException {
-        try {
-            return getFactory().get(getPublication(), getArea(), getUUID(), language);
-        } catch (DocumentBuildException e) {
-            throw new DocumentException(e);
-        }
+    public Document getTranslation(String language) throws ResourceNotFoundException {
+        return area().getDocument(getUUID(), language);
     }
 
     private Node repositoryNode;
@@ -544,7 +506,8 @@
      */
     public Node getRepositoryNode() {
         if (this.repositoryNode == null) {
-            this.repositoryNode = getRepositoryNode(getNodeFactory(), getFactory(), getSourceURI());
+            this.repositoryNode = getRepositoryNode(getNodeFactory(), (Session) getSession(),
+                    getSourceURI());
         }
         return this.repositoryNode;
     }
@@ -562,9 +525,8 @@
         }
     }
 
-    protected static Node getRepositoryNode(NodeFactory nodeFactory, DocumentFactory docFactory,
+    protected static Node getRepositoryNode(NodeFactory nodeFactory, Session session,
             String sourceUri) {
-        Session session = docFactory.getSession();
         try {
             return (Node) session.getRepositoryItem(nodeFactory, sourceUri);
         } catch (Exception e) {
@@ -593,12 +555,8 @@
         }
     }
 
-    public Document getVersion(String area, String language) throws DocumentException {
-        try {
-            return getFactory().get(getPublication(), area, getUUID(), language);
-        } catch (DocumentBuildException e) {
-            throw new DocumentException(e);
-        }
+    public Document getVersion(String area, String language) throws ResourceNotFoundException {
+        return getPublication().getArea(area).getDocument(getUUID(), language);
     }
 
     public Link getLink() throws DocumentException {
@@ -620,15 +578,11 @@
     }
 
     public Area area() {
-        try {
-            return getPublication().getArea(getArea());
-        } catch (PublicationException e) {
-            throw new RuntimeException(e);
-        }
+        return getPublication().getArea(getArea());
     }
 
     public void setResourceType(ResourceType resourceType) {
-    	Validate.notNull(resourceType);
+        Validate.notNull(resourceType);
         checkWritability();
         try {
             MetaData meta = getMetaData(DocumentImpl.METADATA_NAMESPACE);
@@ -639,7 +593,7 @@
     }
 
     public void setSourceExtension(String extension) {
-    	Validate.notNull(extension);
+        Validate.notNull(extension);
         Validate.isTrue(!extension.startsWith("."), "Extension must start with a dot");
         checkWritability();
         try {
@@ -677,8 +631,8 @@
         }
     }
 
-    public Session getSession() {
-        return getFactory().getSession();
+    public Session getRepositorySession() {
+        return (Session) getSession();
     }
 
     public int getRevisionNumber() {
@@ -709,4 +663,13 @@
         this.nodeFactory = nodeFactory;
     }
 
+    public void checkin() throws RepositoryException {
+        getRepositoryNode().checkin();
+    }
+
+    public boolean isCheckedOutBySession(org.apache.lenya.cms.publication.Session session)
+            throws RepositoryException {
+        return getRepositoryNode().isCheckedOutBySession((Session) session);
+    }
+
 }
\ No newline at end of file

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Mon Feb  9 18:49:13 2009
@@ -42,7 +42,6 @@
 import org.apache.lenya.cms.publication.util.DocumentVisitor;
 import org.apache.lenya.cms.repository.Node;
 import org.apache.lenya.cms.repository.NodeFactory;
-import org.apache.lenya.cms.repository.RepositoryException;
 import org.apache.lenya.cms.repository.UUIDGenerator;
 import org.apache.lenya.cms.site.Link;
 import org.apache.lenya.cms.site.NodeIterator;
@@ -73,9 +72,9 @@
             String extension, String navigationTitle, boolean visibleInNav)
             throws DocumentBuildException, PublicationException {
 
-        Document document = add(sourceDocument.getFactory(), sourceDocument.getResourceType(),
-                sourceDocument.getInputStream(), sourceDocument.getPublication(), area, path,
-                language, extension, navigationTitle, visibleInNav, sourceDocument.getMimeType());
+        Document document = add(sourceDocument.getResourceType(), sourceDocument.getInputStream(),
+                sourceDocument.getPublication(), area, path, language, extension, navigationTitle,
+                visibleInNav, sourceDocument.getMimeType());
 
         copyMetaData(sourceDocument, document);
         return document;
@@ -108,16 +107,10 @@
         }
     }
 
-    /**
-     * @see org.apache.lenya.cms.publication.DocumentManager#add(org.apache.lenya.cms.publication.DocumentFactory,
-     *      org.apache.lenya.cms.publication.ResourceType, java.lang.String,
-     *      org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String,
-     *      java.lang.String, java.lang.String, java.lang.String, boolean)
-     */
-    public Document add(DocumentFactory factory, ResourceType documentType,
-            String initialContentsURI, Publication pub, String area, String path, String language,
-            String extension, String navigationTitle, boolean visibleInNav)
-            throws DocumentBuildException, DocumentException, PublicationException {
+    public Document add(ResourceType documentType, String initialContentsURI, Publication pub,
+            String area, String path, String language, String extension, String navigationTitle,
+            boolean visibleInNav) throws DocumentBuildException, DocumentException,
+            PublicationException {
 
         Area areaObj = pub.getArea(area);
         SiteStructure site = areaObj.getSite();
@@ -126,17 +119,16 @@
                     + "] is already contained in site [" + site + "]");
         }
 
-        Document document = add(factory, documentType, initialContentsURI, pub, area, language,
-                extension);
+        Document document = add(documentType, initialContentsURI, pub, area, language, extension);
 
         addToSiteManager(path, document, navigationTitle, visibleInNav);
         return document;
     }
 
-    protected Document add(DocumentFactory factory, ResourceType documentType,
-            InputStream initialContentsStream, Publication pub, String area, String path,
-            String language, String extension, String navigationTitle, boolean visibleInNav,
-            String mimeType) throws DocumentBuildException, DocumentException, PublicationException {
+    protected Document add(ResourceType documentType, InputStream initialContentsStream,
+            Publication pub, String area, String path, String language, String extension,
+            String navigationTitle, boolean visibleInNav, String mimeType)
+            throws DocumentBuildException, DocumentException, PublicationException {
 
         Area areaObj = pub.getArea(area);
         SiteStructure site = areaObj.getSite();
@@ -145,24 +137,23 @@
                     + "] is already contained in site [" + site + "]");
         }
 
-        Document document = add(factory, documentType, initialContentsStream, pub, area, language,
+        Document document = add(documentType, initialContentsStream, pub, area, language,
                 extension, mimeType);
 
         addToSiteManager(path, document, navigationTitle, visibleInNav);
         return document;
     }
 
-    public Document add(DocumentFactory factory, ResourceType documentType,
-            String initialContentsURI, Publication pub, String area, String language,
-            String extension) throws DocumentBuildException, DocumentException,
-            PublicationException {
+    public Document add(ResourceType documentType, String initialContentsURI, Publication pub,
+            String area, String language, String extension) throws DocumentBuildException,
+            DocumentException, PublicationException {
 
         String uuid = getUuidGenerator().nextUUID();
         Source source = null;
         try {
             source = getSourceResolver().resolveURI(initialContentsURI);
-            return add(factory, documentType, uuid, source.getInputStream(), pub, area, language,
-                    extension, getMimeType(source));
+            return add(documentType, uuid, source.getInputStream(), pub, area, language, extension,
+                    getMimeType(source));
         } catch (Exception e) {
             throw new PublicationException(e);
         } finally {
@@ -180,27 +171,27 @@
         return mimeType;
     }
 
-    protected Document add(DocumentFactory factory, ResourceType documentType,
-            InputStream initialContentsStream, Publication pub, String area, String language,
-            String extension, String mimeType) throws DocumentBuildException, DocumentException,
-            PublicationException {
+    protected Document add(ResourceType documentType, InputStream initialContentsStream,
+            Publication pub, String area, String language, String extension, String mimeType)
+            throws DocumentBuildException, DocumentException, PublicationException {
 
         String uuid = getUuidGenerator().nextUUID();
-        return add(factory, documentType, uuid, initialContentsStream, pub, area, language,
-                extension, mimeType);
+        return add(documentType, uuid, initialContentsStream, pub, area, language, extension,
+                mimeType);
     }
 
-    protected Document add(DocumentFactory factory, ResourceType documentType, String uuid,
-            InputStream stream, Publication pub, String area, String language, String extension,
-            String mimeType) throws DocumentBuildException {
+    protected Document add(ResourceType documentType, String uuid, InputStream stream,
+            Publication pub, String area, String language, String extension, String mimeType)
+            throws DocumentBuildException {
         try {
 
-            if (exists(factory, pub, area, uuid, language)) {
+            Area areaObj = pub.getArea(area);
+            if (areaObj.contains(uuid, language)) {
                 throw new DocumentBuildException("The document [" + pub.getId() + ":" + area + ":"
                         + uuid + ":" + language + "] already exists!");
             }
 
-            Document document = factory.get(pub, area, uuid, language);
+            Document document = areaObj.getDocument(uuid, language);
             Node node = document.getRepositoryNode();
             node.lock();
 
@@ -676,11 +667,9 @@
      * @see org.apache.lenya.cms.publication.DocumentManager#deleteAllLanguageVersions(org.apache.lenya.cms.publication.Document)
      */
     public void deleteAllLanguageVersions(Document document) throws PublicationException {
-        DocumentFactory identityMap = document.getFactory();
         String[] languages = document.getLanguages();
         for (int i = 0; i < languages.length; i++) {
-            DocumentLocator version = document.getLocator().getLanguageVersion(languages[i]);
-            delete(identityMap.get(version));
+            delete(document.getTranslation(languages[i]));
         }
     }
 
@@ -726,7 +715,11 @@
         set.reverse();
 
         DocumentVisitor visitor = new DeleteVisitor(this);
-        set.visit(visitor);
+        try {
+            set.visit(visitor);
+        } catch (Exception e) {
+            throw new PublicationException(e);
+        }
 
     }
 
@@ -792,8 +785,9 @@
             int n = docs.length;
 
             Publication pub = docs[0].getPublication();
-            SiteManager siteManager = (SiteManager) WebAppContextUtils.getCurrentWebApplicationContext()
-                .getBean(SiteManager.class.getName() + "/" + pub.getSiteManagerHint());
+            SiteManager siteManager = (SiteManager) WebAppContextUtils
+                    .getCurrentWebApplicationContext().getBean(
+                            SiteManager.class.getName() + "/" + pub.getSiteManagerHint());
 
             Set nodes = new HashSet();
             for (int i = 0; i < docs.length; i++) {
@@ -834,26 +828,14 @@
 
     public Document addVersion(Document sourceDocument, String area, String language)
             throws DocumentBuildException, DocumentException, PublicationException {
-        Document document = add(sourceDocument.getFactory(), sourceDocument.getResourceType(),
-                sourceDocument.getUUID(), sourceDocument.getInputStream(), sourceDocument
-                        .getPublication(), area, language, sourceDocument.getSourceExtension(),
-                sourceDocument.getMimeType());
+        Document document = add(sourceDocument.getResourceType(), sourceDocument.getUUID(),
+                sourceDocument.getInputStream(), sourceDocument.getPublication(), area, language,
+                sourceDocument.getSourceExtension(), sourceDocument.getMimeType());
         copyMetaData(sourceDocument, document);
 
         return document;
     }
 
-    public boolean exists(DocumentFactory factory, Publication pub, String area, String uuid,
-            String language) throws PublicationException {
-        String sourceUri = DocumentImpl.getSourceURI(pub, area, uuid, language);
-        try {
-            Node node = DocumentImpl.getRepositoryNode(getNodeFactory(), factory, sourceUri);
-            return node.exists();
-        } catch (RepositoryException e) {
-            throw new PublicationException(e);
-        }
-    }
-
     public SourceResolver getSourceResolver() {
         return sourceResolver;
     }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationConfiguration.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationConfiguration.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationConfiguration.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/PublicationConfiguration.java Mon Feb  9 18:49:13 2009
@@ -33,7 +33,6 @@
 import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.commons.lang.Validate;
 import org.apache.lenya.cms.repository.Node;
-import org.apache.lenya.cms.repository.Session;
 
 /**
  * A publication's configuration. Keep in sync with
@@ -546,7 +545,7 @@
         return getId();
     }
 
-    public Area getArea(String name) throws PublicationException {
+    public Area getArea(String name) throws ResourceNotFoundException {
         throw new IllegalStateException("Not implemented!");
     }
 
@@ -579,7 +578,7 @@
         return this.name;
     }
 
-    public Session getSession() {
+    public Session getRepositorySession() {
         throw new UnsupportedOperationException();
     }
 
@@ -730,4 +729,8 @@
         return (String[]) this.modules.toArray(new String[this.modules.size()]);
     }
 
+    public Session getSession() {
+        throw new UnsupportedOperationException();
+    }
+
 }

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=742672&r1=742671&r2=742672&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 Mon Feb  9 18:49:13 2009
@@ -29,22 +29,19 @@
 public class PublicationFactory implements RepositoryItemFactory {
 
     private PublicationConfiguration config;
-    private DocumentFactoryBuilder documentFactoryBuilder;
     private NodeFactory nodeFactory;
 
     /**
      * @param config The publication configuration.
      */
-    public PublicationFactory(DocumentFactoryBuilder builder, NodeFactory nodeFactory,
-            PublicationConfiguration config) {
+    public PublicationFactory(NodeFactory nodeFactory, PublicationConfiguration config) {
         this.config = config;
-        this.documentFactoryBuilder = builder;
         this.nodeFactory = nodeFactory;
     }
 
     public RepositoryItem buildItem(Session session, String key) throws RepositoryException {
-        DocumentFactory factory = this.documentFactoryBuilder.createDocumentFactory(session);
-        return new PublicationImpl(factory, this.nodeFactory, config);
+        return new PublicationImpl((org.apache.lenya.cms.publication.Session) session,
+                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=742672&r1=742671&r2=742672&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 Mon Feb  9 18:49:13 2009
@@ -29,22 +29,22 @@
 import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.lenya.cms.repository.NodeFactory;
-import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.repository.RepositoryItem;
 
 /**
  * A publication.
  * @version $Id$
  */
-public class PublicationImpl extends AbstractLogEnabled implements Publication {
+public class PublicationImpl extends AbstractLogEnabled implements Publication, RepositoryItem {
 
     private PublicationConfiguration delegate;
-    private DocumentFactory factory;
     private NodeFactory nodeFactory;
+    private Session session;
 
-    protected PublicationImpl(DocumentFactory factory, NodeFactory nodeFactory,
+    protected PublicationImpl(Session session, NodeFactory nodeFactory,
             PublicationConfiguration delegate) {
         this.delegate = delegate;
-        this.factory = factory;
+        this.session = session;
         this.nodeFactory = nodeFactory;
     }
 
@@ -135,13 +135,9 @@
             this.allResourceTypes.addAll(Arrays.asList(this.delegate.getResourceTypeNames()));
             String templateId = getTemplateId();
             if (templateId != null) {
-                try {
-                    Publication template = getFactory().getPublication(templateId);
-                    String[] templateTypes = template.getResourceTypeNames();
-                    this.allResourceTypes.addAll(Arrays.asList(templateTypes));
-                } catch (PublicationException e) {
-                    throw new RuntimeException(e);
-                }
+                Publication template = getSession().getPublication(templateId);
+                String[] templateTypes = template.getResourceTypeNames();
+                this.allResourceTypes.addAll(Arrays.asList(templateTypes));
             }
         }
         return (String[]) this.allResourceTypes.toArray(new String[this.allResourceTypes.size()]);
@@ -167,12 +163,8 @@
         String schema = this.delegate.getWorkflowSchema(resourceType);
         if (schema == null && getTemplateId() != null) {
             String templateId = getTemplateId();
-            try {
-                Publication template = getFactory().getPublication(templateId);
-                schema = template.getWorkflowSchema(resourceType);
-            } catch (PublicationException e) {
-                throw new RuntimeException(e);
-            }
+            Publication template = getSession().getPublication(templateId);
+            schema = template.getWorkflowSchema(resourceType);
         }
         return schema;
     }
@@ -187,9 +179,9 @@
 
     private Map areas = new HashMap();
 
-    public Area getArea(String name) throws PublicationException {
+    public Area getArea(String name) {
         if (!this.areas.containsKey(name)) {
-            Area area = new AreaImpl(this.factory, this.nodeFactory, this, name);
+            Area area = new AreaImpl(this.session, this.nodeFactory, this, name);
             this.areas.put(name, area);
         }
         return (Area) this.areas.get(name);
@@ -199,10 +191,6 @@
         return delegate.getAreaNames();
     }
 
-    public DocumentFactory getFactory() {
-        return this.factory;
-    }
-
     public boolean equals(Object obj) {
         if (!getClass().isInstance(obj)) {
             return false;
@@ -222,8 +210,8 @@
         return delegate.getName();
     }
 
-    public Session getSession() {
-        return getFactory().getSession();
+    public org.apache.lenya.cms.repository.Session getRepositorySession() {
+        return (org.apache.lenya.cms.repository.Session) getSession();
     }
 
     public void addLanguage(String language) {
@@ -246,4 +234,8 @@
         this.delegate.setName(name);
     }
 
+    public org.apache.lenya.cms.publication.Session getSession() {
+        return this.session;
+    }
+
 }

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=742672&r1=742671&r2=742672&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 Mon Feb  9 18:49:13 2009
@@ -35,6 +35,7 @@
 import org.apache.commons.lang.Validate;
 import org.apache.lenya.cms.repository.NodeFactory;
 import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.repository.Session;
 
 /**
  * Factory for creating publication objects.
@@ -42,7 +43,6 @@
 public final class PublicationManagerImpl extends AbstractLogEnabled implements PublicationManager {
 
     private Map id2config;
-    private DocumentFactoryBuilder documentFactoryBuilder;
     private NodeFactory nodeFactory;
 
     protected synchronized Map getId2config() throws PublicationException {
@@ -72,8 +72,7 @@
     }
 
     public Publication getPublication(DocumentFactory factory, String id)
-    throws PublicationException
-    {
+            throws PublicationException {
         Validate.notNull(id);
         Map id2config = getId2config();
         if (!id2config.containsKey(id)) {
@@ -81,10 +80,10 @@
         }
 
         PublicationConfiguration config = (PublicationConfiguration) id2config.get(id);
-        PublicationFactory pubFactory = new PublicationFactory(getDocumentFactoryBuilder(),
-                getNodeFactory(), config);
+        PublicationFactory pubFactory = new PublicationFactory(getNodeFactory(), config);
         try {
-            return (Publication) factory.getSession().getRepositoryItem(pubFactory, id);
+            org.apache.lenya.cms.repository.Session repoSession = (Session) factory.getSession();
+            return (Publication) repoSession.getRepositoryItem(pubFactory, id);
         } catch (RepositoryException e) {
             throw new PublicationException(e);
         }
@@ -136,14 +135,6 @@
                 .getRealPath("/");
     }
 
-    public DocumentFactoryBuilder getDocumentFactoryBuilder() {
-        return documentFactoryBuilder;
-    }
-
-    public void setDocumentFactoryBuilder(DocumentFactoryBuilder documentFactoryBuilder) {
-        this.documentFactoryBuilder = documentFactoryBuilder;
-    }
-
     public NodeFactory getNodeFactory() {
         return nodeFactory;
     }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/RepositoryImpl.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/RepositoryImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/RepositoryImpl.java Mon Feb  9 18:49:13 2009
@@ -18,40 +18,85 @@
 package org.apache.lenya.cms.publication;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 
 import org.apache.commons.lang.Validate;
 import org.apache.lenya.ac.Identity;
+import org.apache.lenya.cms.observation.ObservationRegistry;
 import org.apache.lenya.cms.repository.RepositoryException;
-import org.apache.lenya.cms.repository.RepositoryManager;
-import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.SharedItemStore;
+import org.apache.lenya.cms.repository.UUIDGenerator;
 
 public class RepositoryImpl implements Repository {
 
-    private RepositoryManager repositoryManager;
-
     public Session getSession(HttpServletRequest request) {
         Validate.notNull(request);
-        try {
-            org.apache.lenya.cms.repository.Session repoSession = RepositoryUtil.getSession(
-                    this.repositoryManager, request);
-            return new SessionImpl(this, repoSession);
-        } catch (RepositoryException e) {
-            throw new RuntimeException(e);
+        SessionImpl session = (SessionImpl) request.getAttribute(Session.class.getName());
+        if (session == null) {
+            Identity identity = getIdentity(request);
+            // attach a read-only repository session to the HTTP request
+            session = (SessionImpl) startSession(identity, false);
+            request.setAttribute(Session.class.getName(), session);
+        } else if (session.getIdentity() == null) {
+            Identity identity = getIdentity(request);
+            if (identity != null) {
+                session.setIdentity(identity);
+            }
         }
-    }
-
-    public void setRepositoryManager(RepositoryManager repositoryManager) {
-        this.repositoryManager = repositoryManager;
+        return session;
     }
 
     public Session startSession(Identity identity, boolean modifiable) {
-        org.apache.lenya.cms.repository.Session repoSession;
+        SessionImpl session = new SessionImpl(identity, modifiable);
         try {
-            repoSession = this.repositoryManager.createSession(identity, modifiable);
+            session.setObservationRegistry(getObservationRegistry());
         } catch (RepositoryException e) {
             throw new RuntimeException(e);
         }
-        return new SessionImpl(this, repoSession);
+        session.setUuidGenerator(getUuidGenerator());
+        session.setSharedItemStore(getSharedItemStore());
+        return session;
+    }
+
+    private SharedItemStore sharedItemStore;
+    private UUIDGenerator uuidGenerator;
+    private ObservationRegistry observationRegistry;
+
+    protected SharedItemStore getSharedItemStore() {
+        return sharedItemStore;
+    }
+
+    public void setSharedItemStore(SharedItemStore sharedItemStore) {
+        this.sharedItemStore = sharedItemStore;
+    }
+
+    protected UUIDGenerator getUuidGenerator() {
+        return uuidGenerator;
+    }
+
+    public void setUuidGenerator(UUIDGenerator uuidGenerator) {
+        this.uuidGenerator = uuidGenerator;
+    }
+
+    protected ObservationRegistry getObservationRegistry() {
+        return observationRegistry;
+    }
+
+    public void setObservationRegistry(ObservationRegistry observationRegistry) {
+        this.observationRegistry = observationRegistry;
+    }
+
+    protected static Identity getIdentity(HttpServletRequest request) {
+        HttpSession session = request.getSession();
+        return (Identity) session.getAttribute(Identity.class.getName());
+    }
+
+    /**
+     * Removes the repository session from the servlet session.
+     * @param request The current request.
+     */
+    public void removeSession(HttpServletRequest request) {
+        request.removeAttribute(Session.class.getName());
     }
 
 }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/SessionImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/SessionImpl.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/SessionImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/SessionImpl.java Mon Feb  9 18:49:13 2009
@@ -17,25 +17,50 @@
  */
 package org.apache.lenya.cms.publication;
 
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.commons.lang.Validate;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.lenya.ac.Identity;
+import org.apache.lenya.cms.observation.ObservationRegistry;
+import org.apache.lenya.cms.observation.RepositoryEvent;
+import org.apache.lenya.cms.observation.RepositoryListener;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.Persistable;
 import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.repository.RepositoryItem;
+import org.apache.lenya.cms.repository.RepositoryItemFactory;
+import org.apache.lenya.cms.repository.RepositoryItemFactoryWrapper;
+import org.apache.lenya.cms.repository.SharedItemStore;
+import org.apache.lenya.cms.repository.UUIDGenerator;
 import org.apache.lenya.transaction.ConcurrentModificationException;
+import org.apache.lenya.transaction.IdentityMap;
+import org.apache.lenya.transaction.IdentityMapImpl;
+import org.apache.lenya.transaction.Lock;
+import org.apache.lenya.transaction.Lockable;
+import org.apache.lenya.transaction.TransactionException;
+import org.apache.lenya.transaction.TransactionLock;
+import org.apache.lenya.transaction.Transactionable;
+import org.apache.lenya.transaction.UnitOfWork;
+import org.apache.lenya.transaction.UnitOfWorkImpl;
+
+public class SessionImpl implements Session, org.apache.lenya.cms.repository.Session {
 
-public class SessionImpl implements Session {
+    private static final Log logger = LogFactory.getLog(SessionImpl.class);
 
-    public SessionImpl(RepositoryImpl repository,
-            org.apache.lenya.cms.repository.Session repoSession)
-    {
+    public SessionImpl(RepositoryImpl repository) {
         Validate.notNull(repository, "repository");
-        Validate.notNull(repoSession, "repository session");
         this.repository = repository;
-        this.repositorySession = repoSession;
     }
 
     private RepositoryImpl repository;
-    private org.apache.lenya.cms.repository.Session repositorySession;
     private DocumentFactory documentFactory;
+    private DocumentFactoryBuilder documentFactoryBuilder;
 
     public Publication getPublication(String id) {
         try {
@@ -51,7 +76,7 @@
 
     public DocumentFactory getDocumentFactory() {
         if (this.documentFactory == null) {
-            this.documentFactory = DocumentUtil.createDocumentFactory(this.repositorySession);
+            this.documentFactory = this.documentFactoryBuilder.createDocumentFactory(this);
         }
         return this.documentFactory;
     }
@@ -64,20 +89,243 @@
         return getDocumentFactory().getPublications();
     }
 
+    protected static final String UNMODIFIABLE_SESSION_ID = "unmodifiable";
+    private Identity identity;
+    private ObservationRegistry observationRegistry;
+    private UUIDGenerator uuidGenerator;
+
+    protected ObservationRegistry getObservationRegistry() {
+        return observationRegistry;
+    }
+
+    protected void setObservationRegistry(ObservationRegistry observationRegistry)
+            throws RepositoryException {
+        if (this.observationRegistry != null) {
+            throw new IllegalStateException("Observation registry already set.");
+        }
+        this.observationRegistry = observationRegistry;
+        addListener(observationRegistry);
+    }
+
+    protected UUIDGenerator getUuidGenerator() {
+        return uuidGenerator;
+    }
+
+    protected void setUuidGenerator(UUIDGenerator uuidGenerator) {
+        this.uuidGenerator = uuidGenerator;
+    }
+
+    /**
+     * Ctor.
+     * @param identity The identity.
+     * @param modifiable Determines if the repository items in this session can be modified.
+     * @param manager The service manager.
+     */
+    protected SessionImpl(Identity identity, boolean modifiable) {
+
+        this.identityMap = new IdentityMapImpl(logger);
+        this.identity = identity;
+        this.id = modifiable ? createUuid() : UNMODIFIABLE_SESSION_ID;
+
+        if (modifiable) {
+            this.unitOfWork = new UnitOfWorkImpl(this.identityMap, this.identity, logger);
+        }
+    }
+
+    protected String createUuid() {
+        return getUuidGenerator().nextUUID();
+    }
+
     public Identity getIdentity() {
-        return getDocumentFactory().getSession().getIdentity();
+        return this.identity;
     }
 
-    public void commit() throws RepositoryException, ConcurrentModificationException {
-        getDocumentFactory().getSession().commit();
+    private UnitOfWork unitOfWork;
+    private SharedItemStore sharedItemStore;
+
+    /**
+     * @return The unit of work.
+     */
+    protected UnitOfWork getUnitOfWork() {
+        if (this.unitOfWork == null) {
+            throw new RuntimeException("This session [" + getId() + "] is not modifiable!");
+        }
+        return this.unitOfWork;
     }
 
+    private boolean committing = false;
+
+    /**
+     * Commits the transaction.
+     * @throws RepositoryException if an error occurs.
+     * @throws ConcurrentModificationException if a transactionable has been modified by another
+     *             session.
+     */
+    public synchronized void commit() throws RepositoryException, ConcurrentModificationException {
+
+        savePersistables();
+
+        this.committing = true;
+
+        try {
+            synchronized (TransactionLock.LOCK) {
+
+                getUnitOfWork().commit();
+                getSharedItemStore().clear();
+            }
+        } catch (ConcurrentModificationException e) {
+            throw e;
+        } catch (TransactionException e) {
+            throw new RepositoryException(e);
+        }
+
+        for (Iterator i = this.events.iterator(); i.hasNext();) {
+            RepositoryEvent event = (RepositoryEvent) i.next();
+            for (Iterator l = this.listeners.iterator(); l.hasNext();) {
+                RepositoryListener listener = (RepositoryListener) l.next();
+                listener.eventFired(event);
+            }
+        }
+        this.events.clear();
+        this.committing = false;
+    }
+
+    /**
+     * Save all persistable objects to their nodes.
+     * @throws RepositoryException if an error occurs.
+     */
+    protected void savePersistables() throws RepositoryException {
+        Object[] objects = getIdentityMap().getObjects();
+        for (int i = 0; i < objects.length; i++) {
+            if (objects[i] instanceof Node) {
+                Node node = (Node) objects[i];
+                Persistable persistable = node.getPersistable();
+                if (persistable != null && persistable.isModified()) {
+                    persistable.save();
+                }
+            }
+        }
+    }
+
+    /**
+     * Rolls the transaction back.
+     * @throws RepositoryException if an error occurs.
+     */
     public void rollback() throws RepositoryException {
-        getDocumentFactory().getSession().rollback();        
+        try {
+            synchronized (TransactionLock.LOCK) {
+                getUnitOfWork().rollback();
+            }
+        } catch (TransactionException e) {
+            throw new RepositoryException(e);
+        }
+        this.events.clear();
+    }
+
+    protected SharedItemStore getSharedItemStore() {
+        return this.sharedItemStore;
+    }
+
+    protected void setSharedItemStore(SharedItemStore sharedItemStore) {
+        this.sharedItemStore = sharedItemStore;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.repository.Session#getRepositoryItem(org.apache.lenya.cms.repository.RepositoryItemFactory,
+     *      java.lang.String)
+     */
+    public RepositoryItem getRepositoryItem(RepositoryItemFactory factory, String key)
+            throws RepositoryException {
+        RepositoryItemFactoryWrapper wrapper = new RepositoryItemFactoryWrapper(factory, this);
+        return (RepositoryItem) getIdentityMap().get(wrapper, key);
+    }
+
+    public void registerNew(Transactionable object) throws TransactionException {
+        getUnitOfWork().registerNew(object);
+    }
+
+    public void registerDirty(Transactionable object) throws TransactionException {
+        getUnitOfWork().registerDirty(object);
+    }
+
+    public void registerRemoved(Transactionable object) throws TransactionException {
+        getUnitOfWork().registerRemoved(object);
+    }
+
+    /**
+     * @param identity The identity.
+     */
+    public void setIdentity(Identity identity) {
+        this.identity = identity;
+    }
+
+    public boolean isDirty(Transactionable transactionable) {
+        return getUnitOfWork().isDirty(transactionable);
+    }
+
+    public Lock createLock(Lockable lockable, int version) throws TransactionException {
+        return getUnitOfWork().createLock(lockable, version);
+    }
+
+    public void removeLock(Lockable lockable) throws TransactionException {
+        getUnitOfWork().removeLock(lockable);
+    }
+
+    private Set listeners = new HashSet();
+
+    public void addListener(RepositoryListener listener) throws RepositoryException {
+        if (this.listeners.contains(listener)) {
+            throw new RepositoryException("The listener [" + listener
+                    + "] is already registered for node [" + this + "]!");
+        }
+        this.listeners.add(listener);
+    }
+
+    public boolean isListenerRegistered(RepositoryListener listener) {
+        return this.listeners.contains(listener);
+    }
+
+    private List events = new ArrayList();
+    private IdentityMap identityMap;
+
+    public synchronized void enqueueEvent(RepositoryEvent event) {
+        Validate.isTrue(event.getSession() == this, "event belongs to session");
+        if (!isModifiable()) {
+            throw new RuntimeException("Can't enqueue event in unmodifiable session!");
+        }
+        if (committing) {
+            throw new RuntimeException(
+                    "No events can be queued while the session is being committed. Event: ["
+                            + event.getDescriptor() + "]");
+        }
+        this.events.add(event);
+    }
+
+    protected IdentityMap getIdentityMap() {
+        return this.identityMap;
     }
 
     public boolean isModifiable() {
-        return getDocumentFactory().getSession().isModifiable();
+        return this.unitOfWork != null;
+    }
+
+    private String id;
+
+    public String getId() {
+        return this.id;
+    }
+
+    public String toString() {
+        return "Session " + getId();
+    }
+    
+    private UriHandler uriHandler;
+
+    public UriHandler getUriHandler() {
+        if (this.uriHandler == null) {
+            this.uriHandler = new UriHandlerImpl(getDocumentFactory());
+        }
+        return this.uriHandler;
     }
 
 }

Added: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/UriHandlerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/UriHandlerImpl.java?rev=742672&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/UriHandlerImpl.java (added)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/UriHandlerImpl.java Mon Feb  9 18:49:13 2009
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.publication;
+
+import java.util.Arrays;
+
+public class UriHandlerImpl implements UriHandler {
+
+    private DocumentFactory factory;
+
+    public UriHandlerImpl(DocumentFactory factory) {
+        this.factory = factory;
+    }
+
+    public Document getDocument(String webappUri) throws ResourceNotFoundException {
+        return this.factory.getFromURL(webappUri);
+    }
+
+    public boolean isDocument(String webappUri) {
+        return this.factory.isDocument(webappUri);
+    }
+
+    public Area getArea(String webappUri) throws ResourceNotFoundException {
+        URLInformation info = new URLInformation(webappUri);
+        return getPublication(info.getPublicationId()).getArea(info.getArea());
+    }
+
+    public Publication getPublication(String webappUri) throws ResourceNotFoundException {
+        String id = new URLInformation(webappUri).getPublicationId();
+        if (id == null) {
+            throw new ResourceNotFoundException("No publication for URI " + webappUri);
+        }
+        try {
+            return this.factory.getPublication(id);
+        } catch (PublicationException e) {
+            throw new ResourceNotFoundException(e);
+        }
+    }
+
+    public boolean isArea(String webappUri) {
+        URLInformation info = new URLInformation(webappUri);
+        String pubId = info.getPublicationId();
+        if (pubId != null && isPublication(pubId)) {
+            Publication pub = getPublication(pubId);
+            String area = info.getArea();
+            if (area != null && Arrays.asList(pub.getAreaNames()).contains(area)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean isPublication(String webappUri) {
+        String id = new URLInformation(webappUri).getPublicationId();
+        return id != null && this.factory.existsPublication(id);
+    }
+
+}

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/ac/impl/AbstractAccessControlTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/ac/impl/AbstractAccessControlTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/ac/impl/AbstractAccessControlTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/ac/impl/AbstractAccessControlTest.java Mon Feb  9 18:49:13 2009
@@ -34,12 +34,9 @@
 import org.apache.lenya.ac.PolicyManager;
 import org.apache.lenya.ac.User;
 import org.apache.lenya.cms.LenyaTestCase;
-import org.apache.lenya.cms.publication.DocumentFactory;
-import org.apache.lenya.cms.publication.DocumentUtil;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
-import org.apache.lenya.cms.repository.Session;
-import org.apache.lenya.cms.repository.SessionImpl;
+import org.apache.lenya.cms.publication.Repository;
+import org.apache.lenya.cms.publication.Session;
 
 /**
  * To change the template for this generated type comment go to Window>Preferences>Java>Code
@@ -53,15 +50,14 @@
     private ServiceSelector accessControllerResolverSelector;
     private AccessControllerResolver accessControllerResolver;
     private AccessController accessController;
-
-    protected org.apache.lenya.cms.repository.Session login(String userId)
+    private Repository repository;
+    
+    protected Session login(String userId)
             throws AccessControlException {
         return login(userId, TEST_PUB_ID);
     }
 
     protected Session login(String userId, String pubId) throws AccessControlException {
-        Session session = new SessionImpl(null, true, logger);
-        getRequest().setAttribute(Session.class.getName(), session);
 
         AccessController ac = getAccessController(session, pubId);
         AccreditableManager acMgr = ac.getAccreditableManager();
@@ -94,7 +90,8 @@
             getLogger().info("Accreditable: " + accrs[i]);
         }
 
-        session.setIdentity(identity);
+        Session session = getRepository().startSession(identity, true);
+        getRequest().setAttribute(Session.class.getName(), session);
         return session;
     }
 
@@ -117,7 +114,7 @@
                     "Using access controller resolver: ["
                             + this.accessControllerResolver.getClass() + "]");
 
-            Publication pub = getPublication(session, pubId);
+            Publication pub = session.getPublication(pubId);
             getLogger().info("Resolve access controller");
             getLogger().info(
                     "Publication directory: [" + pub.getDirectory().getAbsolutePath() + "]");
@@ -169,14 +166,6 @@
         return getAccessController().getAccreditableManager();
     }
 
-    protected DocumentFactory getFactory() {
-        return DocumentUtil.createDocumentFactory(getSession());
-    }
-
-    protected DocumentFactory getFactory(Session session) {
-        return DocumentUtil.createDocumentFactory(session);
-    }
-
     private Session session;
 
     protected Session getSession() {
@@ -194,15 +183,15 @@
         return USER_ID;
     }
 
-    protected Publication getPublication(Session session, String pubId) throws PublicationException {
-        return getFactory(session).getPublication(pubId);
+    protected Identity getIdentity() {
+        return getSession().getIdentity();
     }
 
-    protected Publication getPublication(String id) throws PublicationException {
-        return getFactory().getPublication(id);
+    public void setRepository(Repository repository) {
+        this.repository = repository;
     }
 
-    protected Identity getIdentity() {
-        return getSession().getIdentity();
+    public Repository getRepository() {
+        return repository;
     }
 }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/LenyaTestCase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/LenyaTestCase.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/LenyaTestCase.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/LenyaTestCase.java Mon Feb  9 18:49:13 2009
@@ -44,6 +44,7 @@
 public class LenyaTestCase extends ContainerTestCase {
 
     protected DefaultContext context;
+    
 /*
     protected void addContext(DefaultContext context) {
         super.addContext(context);

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/metadata/MetaDataTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/metadata/MetaDataTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/metadata/MetaDataTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/metadata/MetaDataTest.java Mon Feb  9 18:49:13 2009
@@ -22,7 +22,6 @@
 import org.apache.lenya.ac.impl.AbstractAccessControlTest;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentFactory;
 import org.apache.lenya.cms.publication.Publication;
 
 /**
@@ -36,7 +35,7 @@
      */
     public void testMetaData() throws Exception {
 
-        Publication publication = getPublication("test");
+        Publication publication = getSession().getPublication("test");
         Document doc = publication.getArea("authoring").getSite().getNode("/index").getLink("en").getDocument(); 
 
         String namespaceUri = "foobar";
@@ -92,9 +91,8 @@
             getManager().release(registry);
         }
         
-        DocumentFactory factory = getFactory();
-        Document source = factory.get(pub, Publication.AUTHORING_AREA, "/index", "en");
-        Document target = factory.get(pub, Publication.AUTHORING_AREA, "/index", "en");
+        Document source = pub.getArea(Publication.AUTHORING_AREA).getDocument("/index", "en");
+        Document target = pub.getArea(Publication.AUTHORING_AREA).getDocument("/index", "en");
         
         MetaData sourceMeta = source.getMetaData(NAMESPACE);
         sourceMeta.setValue("copy", "sourceCopy");

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentBuilderTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentBuilderTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentBuilderTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentBuilderTest.java Mon Feb  9 18:49:13 2009
@@ -32,7 +32,7 @@
      * @see org.apache.lenya.cms.publication.DefaultDocumentTest#getDocument(DocumentTestSet)
      */
     protected Document getDocument(DocumentTestSet set) throws PublicationException {
-        Publication pub = getPublication("test");
-        return getFactory().getFromURL("/" + pub.getId() + "/" + set.getArea() + set.getUrl());
+        Publication pub = getSession().getPublication("test");
+        return getSession().getUriHandler().getDocument("/" + pub.getId() + "/" + set.getArea() + set.getUrl());
     }
 }
\ No newline at end of file

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DefaultDocumentTest.java Mon Feb  9 18:49:13 2009
@@ -52,7 +52,7 @@
         getLogger().info("Complete URL: " + document.getCanonicalWebappURL());
         getLogger().info("Extension:    " + document.getExtension());
 
-        Publication publication = getPublication("test");
+        Publication publication = getSession().getPublication("test");
         assertEquals(document.getPublication(), publication);
         assertEquals(document.getPath(), testSet.getPath());
         assertEquals(document.getArea(), testSet.getArea());
@@ -83,11 +83,11 @@
      */
     protected Document getDocument(DocumentTestSet testSet) throws PublicationException {
 
-        Publication pub = getPublication("test");
+        Publication pub = getSession().getPublication("test");
         String uuid = pub.getArea(testSet.getArea()).getSite().getNode(testSet.getPath()).getUuid();
         DocumentIdentifier id = new DocumentIdentifier(pub.getId(), testSet.getArea(), uuid, testSet
                 .getLanguage());
-        DocumentImpl document = new DocumentImpl(getFactory(), id, -1, logger);
+        DocumentImpl document = new DocumentImpl(getSession(), id, -1);
         document.setExtension(testSet.getExtension());
 
         return document;

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentFactoryTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentFactoryTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentFactoryTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentFactoryTest.java Mon Feb  9 18:49:13 2009
@@ -36,15 +36,15 @@
      */
     public void testDocumentFactory() throws Exception {
         Session session = this.repository.getSession(getRequest());
-        DocumentFactory factoryA = new DocumentFactoryImpl(session.getDocumentFactory().getSession(), logger);
+        DocumentFactory factoryA = new DocumentFactoryImpl(session);
 
-        Publication publication = getPublication("test");
+        Publication publication = getSession().getPublication("test");
         
         Document docA1 = factoryA.get(publication, Publication.AUTHORING_AREA, "/index", "en");
         Document docA2 = factoryA.get(publication, Publication.AUTHORING_AREA, "/index", "en");
         assertSame(docA1, docA2);
         
-        DocumentFactory factoryB = new DocumentFactoryImpl(session.getDocumentFactory().getSession(), logger);
+        DocumentFactory factoryB = new DocumentFactoryImpl(session);
 
         Document docB1 = factoryB.get(publication, Publication.AUTHORING_AREA, "/index", "en");
         

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentManagerTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentManagerTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentManagerTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DocumentManagerTest.java Mon Feb  9 18:49:13 2009
@@ -34,39 +34,31 @@
  * Document manager test.
  */
 public class DocumentManagerTest extends AbstractAccessControlTest {
+    
+    private DocumentManager docManager;
 
     /**
      * Do the test.
      * @throws Exception
      */
     public void testDocumentManager() throws Exception {
-        DocumentManager docManager = null;
-        try {
-            docManager = (DocumentManager) getManager().lookup(DocumentManager.ROLE);
-            doTestMoveAll(docManager, "/doctypes", "/tutorial/doctypes");
-            doTestMoveAll(docManager, "/tutorial/doctypes", "/doctypes");
-            doTestCopyAll(docManager, "/doctypes", "/tutorial/doctypes");
-
-            String areaName1 = "authoring";
-            String areaName2 = "live";
-            String path1 = "/tutorial";
-            String path2 = "/doctypes";
-
-            doTestCopyToArea(docManager, areaName1, areaName2, path1, path2);
-
-        } finally {
-            if (docManager != null) {
-                getManager().release(docManager);
-            }
-        }
+        doTestMoveAll(getDocManager(), "/doctypes", "/tutorial/doctypes");
+        doTestMoveAll(getDocManager(), "/tutorial/doctypes", "/doctypes");
+        doTestCopyAll(getDocManager(), "/doctypes", "/tutorial/doctypes");
+
+        String areaName1 = "authoring";
+        String areaName2 = "live";
+        String path1 = "/tutorial";
+        String path2 = "/doctypes";
+
+        doTestCopyToArea(getDocManager(), areaName1, areaName2, path1, path2);
     }
 
     protected void doTestCopyToArea(DocumentManager docManager, String sourceAreaName,
             String destAreaName, String path1, String path2) throws PublicationException,
             SiteException {
-        
-        DocumentFactory factory = getFactory();
-        Publication pub = factory.getPublication("test");
+
+        Publication pub = getSession().getPublication("test");
         SiteStructure sourceArea = pub.getArea(sourceAreaName).getSite();
         SiteStructure destArea = pub.getArea(destAreaName).getSite();
 
@@ -76,10 +68,10 @@
         if (destArea.contains(path2)) {
             destArea.getNode(path2).delete();
         }
-        
+
         assertFalse(destArea.contains(path1));
         assertFalse(destArea.contains(path2));
-        
+
         // copy second node first to test correct ordering
         doTestCopyToArea(docManager, path2, sourceAreaName, destAreaName);
         doTestCopyToArea(docManager, path1, sourceAreaName, destAreaName);
@@ -109,8 +101,7 @@
 
     protected void doTestCopyToArea(DocumentManager docManager, String path, String areaName1,
             String areaName2) throws PublicationException {
-        DocumentFactory factory = getFactory();
-        Publication pub = factory.getPublication("test");
+        Publication pub = getSession().getPublication("test");
         Area area1 = pub.getArea(areaName1);
         Document doc = area1.getSite().getNode(path).getLink("en").getDocument();
         docManager.copyToArea(doc, areaName2);
@@ -118,12 +109,11 @@
 
     protected void doTestCopyAll(DocumentManager docManager, String sourcePath, String targetPath)
             throws SiteException, DocumentException, PublicationException {
-        DocumentFactory factory = getFactory();
-        Publication pub = factory.getPublication("test");
+        Publication pub = getSession().getPublication("test");
         Area authoring = pub.getArea("authoring");
 
         SiteNode sourceNode = authoring.getSite().getNode(sourcePath);
-        
+
         NodeSet nodes = SiteUtil.getSubSite(sourceNode);
         Document[] docs = nodes.getDocuments();
         Map doc2path = new HashMap();
@@ -146,26 +136,25 @@
             assertEquals(newDoc.getContentLength(), docs[i].getContentLength());
             assertFalse(newDoc.getUUID().equals(docs[i].getUUID()));
         }
-        
+
         String[] sourceNames = getChildNames(sourceNode);
         SiteNode targetNode = authoring.getSite().getNode(targetPath);
         String[] targetNames = getChildNames(targetNode);
         assertEquals(StringUtil.join(sourceNames, ","), StringUtil.join(targetNames, ","));
     }
 
-	protected String[] getChildNames(SiteNode node) {
-		SiteNode[] sourceChildren = node.getChildren();
+    protected String[] getChildNames(SiteNode node) {
+        SiteNode[] sourceChildren = node.getChildren();
         String[] names = new String[sourceChildren.length];
         for (int i = 0; i < names.length; i++) {
-        	names[i] = sourceChildren[i].getName();
+            names[i] = sourceChildren[i].getName();
         }
-		return names;
-	}
+        return names;
+    }
 
     protected void doTestMoveAll(DocumentManager docManager, String sourcePath, String targetPath)
             throws SiteException, DocumentException, PublicationException {
-        DocumentFactory factory = getFactory();
-        Publication pub = factory.getPublication("test");
+        Publication pub = getSession().getPublication("test");
         Area authoring = pub.getArea("authoring");
 
         SiteNode sourceNode = authoring.getSite().getNode(sourcePath);
@@ -189,10 +178,18 @@
             String newPath = docs[i].getPath();
             assertEquals(targetBase + oldPath, newPath);
         }
-        
+
         SiteNode targetNode = authoring.getSite().getNode(targetPath);
         String[] targetNames = getChildNames(targetNode);
         assertEquals(StringUtil.join(sourceNames, ","), StringUtil.join(targetNames, ","));
-        
+
+    }
+
+    public void setDocManager(DocumentManager docManager) {
+        this.docManager = docManager;
+    }
+
+    public DocumentManager getDocManager() {
+        return docManager;
     }
 }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DublinCoreTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DublinCoreTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DublinCoreTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/DublinCoreTest.java Mon Feb  9 18:49:13 2009
@@ -49,7 +49,7 @@
         
         login("lenya");
         
-        Publication publication = getPublication("test");
+        Publication publication = getSession().getPublication("test");
         
         Document doc = publication.getArea(AREA).getSite().getNode(PATH).getLink(LANGUAGE).getDocument();
         

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/PublicationTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/PublicationTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/PublicationTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/PublicationTest.java Mon Feb  9 18:49:13 2009
@@ -34,22 +34,10 @@
      * @throws Exception
      */
     public void testPublication() throws Exception {
-
-        PublicationManager pubMgr = null;
-        try {
-            pubMgr = (PublicationManager) getManager().lookup(PublicationManager.ROLE);
-
-            Publication[] pubs = pubMgr.getPublications(getFactory());
-            for (int i = 0; i < pubs.length; i++) {
-                doTestPublication(pubs[i]);
-            }
-
-        } finally {
-            if (pubMgr != null) {
-                getManager().release(pubMgr);
-            }
+        Publication[] pubs = getSession().getPublications();
+        for (int i = 0; i < pubs.length; i++) {
+            doTestPublication(pubs[i]);
         }
-
     }
 
     protected void doTestPublication(Publication pub) throws PublicationException {
@@ -83,7 +71,7 @@
 
         String templateId = pub.getTemplateId();
         if (templateId != null) {
-            Publication template = pub.getFactory().getPublication(templateId);
+            Publication template = pub.getSession().getPublication(templateId);
             String[] templateTypes = template.getResourceTypeNames();
             for (int t = 0; t < templateTypes.length; t++) {
                 assertTrue(typeSet.contains(templateTypes[t]));

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/TestPageEnvelope.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/TestPageEnvelope.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/TestPageEnvelope.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/TestPageEnvelope.java Mon Feb  9 18:49:13 2009
@@ -23,8 +23,6 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.lenya.cms.repository.Session;
-import org.apache.lenya.cms.repository.SessionImpl;
 
 /**
  * To change the template for this generated type comment go to Window>Preferences>Java>Code
@@ -46,9 +44,8 @@
         setContext("");
 
         try {
-            Session session = new SessionImpl(null, false, logger);
-            DocumentFactory map = DocumentUtil.createDocumentFactory(session);
-            setDocument(map.getFromURL(url));
+            Session session = publication.getSession();
+            setDocument(session.getUriHandler().getDocument(url));
         } catch (Exception e) {
             throw new PageEnvelopeException(e);
         }

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/file/FilePublicationTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/file/FilePublicationTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/file/FilePublicationTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/publication/file/FilePublicationTest.java Mon Feb  9 18:49:13 2009
@@ -23,9 +23,9 @@
 import org.apache.lenya.ac.impl.AbstractAccessControlTest;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentException;
-import org.apache.lenya.cms.publication.DocumentFactory;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.Session;
 import org.apache.lenya.cms.site.SiteException;
 
 /**
@@ -58,18 +58,10 @@
      * @throws SiteException
      */
     public void testCopyDocument() throws PublicationException, DocumentException, SiteException {
-        testCopyDocument(Publication.AUTHORING_AREA,
-                sourceDocumentId,
-                sourceLanguage,
-                Publication.AUTHORING_AREA,
-                destinationDocumentId,
-                destinationLanguage);
-        testCopyDocument(Publication.AUTHORING_AREA,
-                sourceDocumentId,
-                sourceLanguage,
-                Publication.LIVE_AREA,
-                sourceDocumentId,
-                sourceLanguage);
+        testCopyDocument(Publication.AUTHORING_AREA, sourceDocumentId, sourceLanguage,
+                Publication.AUTHORING_AREA, destinationDocumentId, destinationLanguage);
+        testCopyDocument(Publication.AUTHORING_AREA, sourceDocumentId, sourceLanguage,
+                Publication.LIVE_AREA, sourceDocumentId, sourceLanguage);
     }
 
     /**
@@ -97,33 +89,28 @@
         getLogger().info("    Destination document ID: [" + _destinationDocumentId + "]");
         getLogger().info("    Destination language:    [" + _destinationLanguage + "]");
 
-        Publication publication = getPublication("test");
-        DocumentFactory map = getFactory();
+        Session session = getSession();
+        Publication publication = session.getPublication("test");
 
-        Document sourceDocument = map.get(publication,
-                sourceArea,
-                _sourceDocumentId,
+        Document sourceDocument = publication.getArea(sourceArea).getDocument(_sourceDocumentId,
                 _sourceLanguage);
-        Document destinationDocument = map.get(publication,
-                destinationArea,
-                _destinationDocumentId,
-                _destinationLanguage);
-/*
-        publication.copyDocument(sourceDocument, destinationDocument);
-
-        assertTrue(destinationDocument.exists());
-
-        TreeSiteManager manager = (TreeSiteManager) publication.getSiteManager(map);
-        SiteTree destinationTree = manager.getTree(destinationArea);
-        SiteTreeNode destinationNode = destinationTree.getNode(_destinationDocumentId);
-        assertNotNull(destinationNode);
-        Label destinationLabel = destinationNode.getLabel(_destinationLanguage);
-        assertNotNull(destinationLabel);
-
-        SiteTreeNode sourceNode = destinationTree.getNode(_sourceDocumentId);
-        Label sourceLabel = sourceNode.getLabel(_sourceLanguage);
-
-        assertTrue(destinationLabel.getLabel().equals(sourceLabel.getLabel()));
-*/
+        Document destinationDocument = publication.getArea(destinationArea).getDocument(
+                _destinationDocumentId, _destinationLanguage);
+        /*
+         * publication.copyDocument(sourceDocument, destinationDocument);
+         * 
+         * assertTrue(destinationDocument.exists());
+         * 
+         * TreeSiteManager manager = (TreeSiteManager) publication.getSiteManager(map); SiteTree
+         * destinationTree = manager.getTree(destinationArea); SiteTreeNode destinationNode =
+         * destinationTree.getNode(_destinationDocumentId); assertNotNull(destinationNode); Label
+         * destinationLabel = destinationNode.getLabel(_destinationLanguage);
+         * assertNotNull(destinationLabel);
+         * 
+         * SiteTreeNode sourceNode = destinationTree.getNode(_sourceDocumentId); Label sourceLabel =
+         * sourceNode.getLabel(_sourceLanguage);
+         * 
+         * assertTrue(destinationLabel.getLabel().equals(sourceLabel.getLabel()));
+         */
     }
 }
\ No newline at end of file

Modified: lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/rc/RevisionControllerTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/rc/RevisionControllerTest.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/rc/RevisionControllerTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/test/java/org/apache/lenya/cms/rc/RevisionControllerTest.java Mon Feb  9 18:49:13 2009
@@ -42,7 +42,7 @@
         DocumentManager docMgr = null;
         try {
             docMgr = (DocumentManager) getManager().lookup(DocumentManager.ROLE);
-            Document source = getPublication("test").getArea("authoring").getSite().getNode(
+            Document source = getSession().getPublication("test").getArea("authoring").getSite().getNode(
                     "/links").getLink("en").getDocument();
             Document target = docMgr.addVersion(source, "authoring", "es");
             target.delete();
@@ -52,7 +52,7 @@
             }
         }
 
-        getFactory().getSession().commit();
+        getSession().commit();
     }
 
     public void testRevisionController() throws RepositoryException, RevisionControlException {

Modified: lenya/trunk/org.apache.lenya.core.janitor/src/main/java/org/apache/lenya/cms/janitor/ContentJanitor.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.janitor/src/main/java/org/apache/lenya/cms/janitor/ContentJanitor.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.janitor/src/main/java/org/apache/lenya/cms/janitor/ContentJanitor.java (original)
+++ lenya/trunk/org.apache.lenya.core.janitor/src/main/java/org/apache/lenya/cms/janitor/ContentJanitor.java Mon Feb  9 18:49:13 2009
@@ -19,27 +19,22 @@
 
 import java.io.File;
 
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.cocoon.processing.ProcessInfoProvider;
 import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
 import org.apache.lenya.cms.observation.AbstractRepositoryListener;
 import org.apache.lenya.cms.observation.DocumentEvent;
 import org.apache.lenya.cms.observation.RepositoryEvent;
-import org.apache.lenya.cms.publication.DocumentFactory;
-import org.apache.lenya.cms.publication.DocumentUtil;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.repository.RepositoryManager;
-import org.apache.lenya.cms.repository.RepositoryUtil;
-import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.publication.Repository;
+import org.apache.lenya.cms.publication.Session;
 
 /**
  * The content janitor cleans up empty directories after a document is removed.
  */
 public class ContentJanitor extends AbstractRepositoryListener {
     
-    private RepositoryManager repositoryManager;
+    private Repository repository;
 
     public void eventFired(RepositoryEvent repoEvent) {
         
@@ -55,10 +50,8 @@
         try {
             ProcessInfoProvider process = (ProcessInfoProvider) WebAppContextUtils
                     .getCurrentWebApplicationContext().getBean(ProcessInfoProvider.ROLE);
-            HttpServletRequest request = process.getRequest();
-            Session session = RepositoryUtil.getSession(getRepositoryManager(), request);
-            DocumentFactory factory = DocumentUtil.createDocumentFactory(session);
-            Publication pub = factory.getPublication(event.getPublicationId());
+            Session session = this.repository.getSession(process.getRequest());
+            Publication pub = session.getPublication(event.getPublicationId());
             File contentFile = pub.getContentDirectory(event.getArea());
             String contentUri = contentFile.toURI().toString();
             SourceUtil.deleteEmptyCollections(contentUri, this.manager);
@@ -67,12 +60,8 @@
         }
     }
 
-    public void setRepositoryManager(RepositoryManager repositoryManager) {
-        this.repositoryManager = repositoryManager;
-    }
-
-    public RepositoryManager getRepositoryManager() {
-        return repositoryManager;
+    public void setRepository(Repository repository) {
+        this.repository = repository;
     }
 
 }

Modified: lenya/trunk/org.apache.lenya.core.linking/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.linking/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java?rev=742672&r1=742671&r2=742672&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.linking/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java (original)
+++ lenya/trunk/org.apache.lenya.core.linking/src/main/java/org/apache/lenya/cms/cocoon/components/modules/input/ProxyModule.java Mon Feb  9 18:49:13 2009
@@ -30,9 +30,6 @@
 import org.apache.lenya.cms.linking.OutgoingLinkRewriter;
 import org.apache.lenya.cms.publication.Repository;
 import org.apache.lenya.cms.publication.Session;
-import org.apache.lenya.cms.repository.RepositoryException;
-import org.apache.lenya.cms.repository.RepositoryManager;
-import org.apache.lenya.cms.repository.RepositoryUtil;
 
 /**
  * <p>
@@ -88,8 +85,7 @@
         return value;
     }
 
-    protected String rewrite(Request request, String url) throws RepositoryException,
-            ConfigurationException {
+    protected String rewrite(Request request, String url) throws ConfigurationException {
         Session session = this.repository.getSession(request);
         LinkRewriter rewriter = new OutgoingLinkRewriter(session, request.getRequestURI(), request
                 .isSecure(), false, this.relativeUrls);
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.