You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/11/04 18:22:36 UTC

svn commit: r330846 - in /lenya/trunk/src: java/org/apache/lenya/cms/migration/ java/org/apache/lenya/cms/repo/ modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/ modules/jackrabbit/repository/repository/nodetypes/ modules/jcr/java/src/or...

Author: andreas
Date: Fri Nov  4 09:22:03 2005
New Revision: 330846

URL: http://svn.apache.org/viewcvs?rev=330846&view=rev
Log:
Added 1st version of new Lenya repo interfaces + JCR-based implementation

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/repo/
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Area.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryFactory.java
      - copied, changed from r330793, lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFactory.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java
      - copied, changed from r330793, lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFacade.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java
      - copied, changed from r330793, lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositorySession.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNodeBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperBuilder.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java
Removed:
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRNodeFactory.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSourceNode.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFacade.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFactory.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositorySession.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
    lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepositoryFactory.java
    lenya/trunk/src/modules/jackrabbit/repository/repository/nodetypes/custom_nodetypes.xml
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRArea.java
    lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java?rev=330846&r1=330845&r2=330846&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java Fri Nov  4 09:22:03 2005
@@ -18,28 +18,16 @@
 
 import java.io.File;
 import java.io.FileFilter;
-import java.util.Arrays;
 
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
-
-import org.apache.jackrabbit.core.security.SimpleLoginModule;
-import org.apache.lenya.cms.jcr.JCRArea;
-import org.apache.lenya.cms.jcr.JCRPublication;
-import org.apache.lenya.cms.jcr.RepositoryFacade;
-import org.apache.lenya.cms.jcr.RepositoryFactory;
-import org.apache.lenya.cms.jcr.RepositorySession;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationImpl;
+import org.apache.lenya.cms.repo.Area;
+import org.apache.lenya.cms.repo.ContentNode;
+import org.apache.lenya.cms.repo.Publication;
+import org.apache.lenya.cms.repo.Repository;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.RepositoryManager;
+import org.apache.lenya.cms.repo.Session;
+import org.apache.lenya.cms.repo.SiteNode;
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
 
 /**
  * Migrate Lenya 1.4-dev content.
@@ -89,29 +77,33 @@
         this.repositoryFactory = repositoryFactory;
     }
 
-    private RepositoryFacade repo;
-    private RepositorySession session;
-    private Node contentNode;
+    private Repository repo;
+    private Session session;
 
-    protected RepositoryFacade getRepository() {
+    protected Repository getRepository() {
         return this.repo;
     }
 
-    protected RepositorySession getSession() {
+    protected Session getSession() {
         return this.session;
     }
 
+    static final String PUBLICATION_PREFIX = "lenya" + File.separator + "pubs";
+    static final String CONFIGURATION_PATH = "config";
+    static final String CONFIGURATION_FILE = CONFIGURATION_PATH + File.separator
+            + "publication.xconf";
+
     public void execute() throws BuildException {
 
         try {
-            this.repo = new RepositoryFacade(getWebappDirectory(), getRepositoryFactory());
+            this.repo = RepositoryManager.getRepository(getWebappDirectory(),
+                    getRepositoryFactory());
             this.session = this.repo.createSession();
 
-            File publicationsDirectory = new File(webappDirectory, Publication.PUBLICATION_PREFIX);
+            File publicationsDirectory = new File(webappDirectory, PUBLICATION_PREFIX);
             File[] pubDirs = publicationsDirectory.listFiles(new FileFilter() {
                 public boolean accept(File file) {
-                    return file.isDirectory()
-                            && new File(file, PublicationImpl.CONFIGURATION_FILE).exists();
+                    return file.isDirectory() && new File(file, CONFIGURATION_FILE).exists();
                 }
             });
 
@@ -119,6 +111,8 @@
                 importPublication(pubDirs[i]);
             }
 
+            getSession().save();
+
         } catch (Exception e) {
             e.printStackTrace(System.err);
             if (e.getCause() != null) {
@@ -137,7 +131,7 @@
 
     protected void importPublication(File pubDir) throws RepositoryException {
         String pubId = pubDir.getName();
-        JCRPublication pub = new JCRPublication(getSession(), pubId);
+        Publication pub = getSession().getPublication(pubId);
 
         File contentDir = new File(pubDir, "content");
         File[] areaDirs = contentDir.listFiles(directoryFilter);
@@ -146,32 +140,60 @@
         }
     }
 
-    protected void importContent(File contentDir, JCRPublication pub) throws RepositoryException {
+    protected void importContent(File contentDir, Publication pub) throws RepositoryException {
         String area = contentDir.getName();
-        JCRArea jcrArea = pub.getArea(area);
-        
-        System.out.println("pub node:  " + jcrArea.getPublicationNode().getPath());
-        System.out.println("site node: " + jcrArea.getSiteNode().getPath());
-        
-        importChildren(contentDir, jcrArea.getSiteNode());
+        Area repoArea = pub.getArea(area);
+        importChildren(contentDir, repoArea, null);
     }
 
-    protected void importDocument(File docDir, Node parent)
+    protected void importNode(File docDir, Area area, SiteNode parent)
             throws RepositoryException {
         String nodeId = docDir.getName();
-        String documentId = parent.getPath() + "/" + nodeId;
-        System.out.println("Importing [" + documentId + "]");
+        String parentPath = "";
+        if (parent != null) {
+            parentPath = parent.getPath();
+        }
+        String documentPath = parentPath + "/" + nodeId;
+        System.out.println("Importing [" + documentPath + "]");
+
+        SiteNode siteNode;
+        ContentNode contentNode = area.getContent().addNode(nodeId);
+        if (parent == null) {
+            siteNode = area.getSite().addChild(nodeId, contentNode);
+        } else {
+            siteNode = parent.addChild(nodeId, contentNode);
+        }
+
+        importDocuments(docDir, contentNode);
 
-        Node node = parent.addNode(nodeId);
+        importChildren(docDir, area, siteNode);
+    }
+
+    protected void importDocuments(File docDir, ContentNode contentNode) throws RepositoryException {
+        File[] files = docDir.listFiles(new FileFilter() {
+            public boolean accept(File file) {
+                return file.isFile() && file.getName().startsWith("index_")
+                        && file.getName().endsWith(".xml");
+            }
+        });
+        for (int i = 0; i < files.length; i++) {
+            importDocument(files[i], contentNode);
+        }
+    }
 
-        importChildren(docDir, node);
+    protected void importDocument(File file, ContentNode contentNode) throws RepositoryException {
+        String fileName = file.getName();
+        String suffix = fileName.substring("index_".length());
+        String language = suffix.substring(0, suffix.length() - ".xml".length());
+        contentNode.addDocument(language);
+        System.out.println(" language [" + language + "]");
     }
 
-    protected void importChildren(File docDir, Node parent)
+    protected void importChildren(File docDir, Area area, SiteNode parentNode)
             throws RepositoryException {
         File[] childDirs = docDir.listFiles(directoryFilter);
         for (int i = 0; i < childDirs.length; i++) {
-            importDocument(childDirs[i], parent);
+            importNode(childDirs[i], area, parentNode);
         }
     }
 }

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Area.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Area.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Area.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Area.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+/**
+ * An area.
+ */
+public interface Area {
+
+    /**
+     * @return The content of this area.
+     * @throws RepositoryException if an error occurs.
+     */
+    Content getContent() throws RepositoryException;
+    
+    /**
+     * @return The site of this area.
+     * @throws RepositoryException if an error occurs.
+     */
+    Site getSite() throws RepositoryException;
+    
+    /**
+     * Removes all content and site nodes from this area.
+     * @throws RepositoryException if an error occurs.
+     */
+    void clear() throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+/**
+ * The content of an area.
+ */
+public interface Content {
+
+    /**
+     * @param id The node ID.
+     * @return A node with a specific ID.
+     * @throws RepositoryException if an error occurs.
+     */
+    ContentNode getNode(String id) throws RepositoryException;
+    
+    /**
+     * @return All content nodes in this area.
+     */
+    ContentNode[] getNodes();
+    
+    /**
+     * @param id The node ID.
+     * @return The added node.
+     * @throws RepositoryException if an error occurs.
+     */
+    ContentNode addNode(String id) throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+public interface ContentNode {
+    
+    Document[] getDocuments() throws RepositoryException;
+    
+    void addDocument(String language) throws RepositoryException;
+    
+    void removeDocument(Document document) throws RepositoryException;
+    
+    Document getDocument(String language) throws RepositoryException;
+
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,25 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+public interface Document {
+    
+    String getLanguage() throws RepositoryException;
+    
+    void setLanguage(String language) throws RepositoryException;
+
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,23 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+public interface Publication {
+
+    Area getArea(String area) throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,7 @@
+package org.apache.lenya.cms.repo;
+
+public interface Repository {
+
+    Session createSession() throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+public class RepositoryException extends Exception {
+
+    /**
+     * 
+     */
+    public RepositoryException() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param arg0
+     * @param arg1
+     */
+    public RepositoryException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param arg0
+     */
+    public RepositoryException(String arg0) {
+        super(arg0);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param arg0
+     */
+    public RepositoryException(Throwable arg0) {
+        super(arg0);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Copied: lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryFactory.java (from r330793, lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFactory.java)
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryFactory.java?p2=lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryFactory.java&p1=lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFactory.java&r1=330793&r2=330846&rev=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryFactory.java Fri Nov  4 09:22:03 2005
@@ -14,13 +14,10 @@
  *  limitations under the License.
  *
  */
-package org.apache.lenya.cms.jcr;
-
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
+package org.apache.lenya.cms.repo;
 
 /**
- * Factory for JCR repositories.
+ * Factory for repositories.
  */
 public interface RepositoryFactory {
 

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright  1999-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+import java.io.File;
+
+public class RepositoryManager {
+
+    public static Repository getRepository(String webappPath, String repositoryFactoryClass)
+            throws RepositoryException {
+        try {
+            Class repoFactoryClass = Class.forName(repositoryFactoryClass);
+            RepositoryFactory repoFactory = (RepositoryFactory) repoFactoryClass.newInstance();
+
+            File webappDirectory = new File(webappPath);
+
+            String jaasPath = "lenya/modules/jackrabbit/repository/jaas.config";
+            System.setProperty("java.security.auth.login.config", new File(webappDirectory,
+                    jaasPath).getAbsolutePath());
+
+            Repository repository = repoFactory.getRepository(webappPath);
+            return repository;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,9 @@
+package org.apache.lenya.cms.repo;
+
+public interface Session {
+
+    Publication getPublication(String id) throws RepositoryException;
+    
+    public void save() throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+/**
+ * The site structure of an area.
+ */
+public interface Site {
+
+    /**
+     * @return The top level nodes in this area.
+     * @throws RepositoryException if an error occurs.
+     */
+    SiteNode[] getChildren() throws RepositoryException;
+    
+    /**
+     * @return The nodes of this site.
+     * @throws RepositoryException if an error occurs.
+     */
+    SiteNode[] getNodes() throws RepositoryException;
+    
+    /**
+     * @param name The name.
+     * @param contentNode The content node which the site node refers to.
+     * @return a site node.
+     * @throws RepositoryException if an error occurs.
+     */
+    SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repo;
+
+/**
+ * A site node, which represents a site (subsite) itself.
+ */
+public interface SiteNode {
+
+    /**
+     * @return The name, which corresponds to the URL snippet.
+     * @throws RepositoryException if an error occurs.
+     */
+    String getName() throws RepositoryException;
+    
+    /**
+     * @return The top level nodes in this area.
+     * @throws RepositoryException if an error occurs.
+     */
+    SiteNode[] getChildren() throws RepositoryException;
+    
+    /**
+     * @param name The name.
+     * @return A child node.
+     * @throws RepositoryException if an error occurs.
+     */
+    SiteNode getChild(String name) throws RepositoryException;
+
+    /**
+     * @param name The name.
+     * @param contentNode The content node which the site node refers to.
+     * @return a site node.
+     * @throws RepositoryException if an error occurs.
+     */
+    SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException;
+    
+    /**
+     * @return The path of the node, relative to the area.
+     * @throws RepositoryException if an error occurs.
+     */
+    String getPath() throws RepositoryException;
+}

Modified: lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepositoryFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepositoryFactory.java?rev=330846&r1=330845&r2=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepositoryFactory.java (original)
+++ lenya/trunk/src/modules/jackrabbit/java/src/org/apache/lenya/cms/jcr/jackrabbit/JackrabbitRepositoryFactory.java Fri Nov  4 09:22:03 2005
@@ -18,12 +18,12 @@
 
 import java.io.File;
 
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.apache.lenya.cms.jcr.RepositoryFactory;
+import org.apache.lenya.cms.jcr.JCRRepository;
+import org.apache.lenya.cms.repo.Repository;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.RepositoryFactory;
 
 /**
  * Jackrabbit-based repository factory.
@@ -35,14 +35,19 @@
     protected static final String configFilePath = "repository.xml";
 
     public Repository getRepository(String webappPath) throws RepositoryException {
-        File webappDirectory = new File(webappPath);
-        File repoDirectory = new File(webappDirectory, homePath);
-        File configFile = new File(repoDirectory, configFilePath);
-        RepositoryConfig repoConfig = RepositoryConfig.create(configFile.getAbsolutePath(),
-                repoDirectory.getAbsolutePath());
-        Repository repo = RepositoryImpl.create(repoConfig);
-        
-        return repo;
+
+        try {
+            File webappDirectory = new File(webappPath);
+            File repoDirectory = new File(webappDirectory, homePath);
+            File configFile = new File(repoDirectory, configFilePath);
+            RepositoryConfig repoConfig = RepositoryConfig.create(configFile.getAbsolutePath(),
+                    repoDirectory.getAbsolutePath());
+            JCRRepository repo = new JCRRepository(RepositoryImpl.create(repoConfig));
+
+            return repo;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
     }
 
 }

Modified: lenya/trunk/src/modules/jackrabbit/repository/repository/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jackrabbit/repository/repository/nodetypes/custom_nodetypes.xml?rev=330846&r1=330845&r2=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jackrabbit/repository/repository/nodetypes/custom_nodetypes.xml (original)
+++ lenya/trunk/src/modules/jackrabbit/repository/repository/nodetypes/custom_nodetypes.xml Fri Nov  4 09:22:03 2005
@@ -68,17 +68,17 @@
       <supertype>mix:referenceable</supertype>
       <supertype>mix:lockable</supertype>
     </supertypes>
-    <childNodeDef name="lenya:node" defaultPrimaryType="lnt:node" autoCreate="false" mandatory="false"
+    <childNodeDef name="lenya:contentnode" defaultPrimaryType="lnt:contentnode" autoCreate="false" mandatory="false"
       onParentVersion="ABORT" protected="false" sameNameSibs="true">
       <requiredPrimaryTypes>
-        <requiredPrimaryType>lnt:node</requiredPrimaryType>
+        <requiredPrimaryType>lnt:contentnode</requiredPrimaryType>
       </requiredPrimaryTypes>
     </childNodeDef>
   </nodeType>
   
   
   <!-- node in content subtree -->
-  <nodeType name="lnt:node" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
+  <nodeType name="lnt:contentnode" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
     <supertypes>
       <supertype>nt:hierarchyNode</supertype>
       <supertype>mix:referenceable</supertype>
@@ -148,26 +148,26 @@
     <childNodeDef name="*" defaultPrimaryType="lnt:item" autoCreate="false" mandatory="false"
       onParentVersion="ABORT" protected="false" sameNameSibs="false">
       <requiredPrimaryTypes>
-        <requiredPrimaryType>lnt:item</requiredPrimaryType>
+        <requiredPrimaryType>lnt:sitenode</requiredPrimaryType>
       </requiredPrimaryTypes>
     </childNodeDef>
   </nodeType>
   
   <!--
-  Site structure item
+  Site structure node
   -->
-  <nodeType name="lnt:item" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
+  <nodeType name="lnt:sitenode" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
     <supertypes>
       <supertype>nt:hierarchyNode</supertype>
       <supertype>mix:referenceable</supertype>
       <supertype>mix:lockable</supertype>
     </supertypes>
-    <propertyDef name="lenya:node" mandatory="false" autoCreate="false" multiple="false" onParentVersion="ABORT"
+    <propertyDef name="lenya:contentnode" mandatory="false" autoCreate="false" multiple="false" onParentVersion="ABORT"
       protected="false" requiredType="Reference"/>
-    <childNodeDef name="*" defaultPrimaryType="lnt:item" autoCreate="false" mandatory="false"
+    <childNodeDef name="*" defaultPrimaryType="lnt:sitenode" autoCreate="false" mandatory="false"
       onParentVersion="ABORT" protected="false" sameNameSibs="false">
       <requiredPrimaryTypes>
-        <requiredPrimaryType>lnt:item</requiredPrimaryType>
+        <requiredPrimaryType>lnt:sitenode</requiredPrimaryType>
       </requiredPrimaryTypes>
     </childNodeDef>
   </nodeType>

Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRArea.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRArea.java?rev=330846&r1=330845&r2=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRArea.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRArea.java Fri Nov  4 09:22:03 2005
@@ -17,20 +17,32 @@
 package org.apache.lenya.cms.jcr;
 
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
 
-public class JCRArea {
+import org.apache.lenya.cms.repo.Area;
+import org.apache.lenya.cms.repo.Content;
+import org.apache.lenya.cms.repo.Site;
+
+/**
+ * JCR area.
+ */
+public class JCRArea implements Area {
 
     private String area;
     private JCRPublication publication;
 
+    private NodeWrapperManager nodeManager;
+
+    /**
+     * Ctor.
+     * @param publication The publication.
+     * @param area The area ID.
+     */
     public JCRArea(JCRPublication publication, String area) {
         this.publication = publication;
         this.area = area;
+        this.nodeManager = new NodeWrapperManager(publication.getSession());
     }
 
     protected JCRPublication getPublication() {
@@ -41,29 +53,17 @@
         return this.area;
     }
 
-    public Session getSession() throws RepositoryException {
+    protected Session getSession() throws RepositoryException {
         return getPublication().getSession().getSession(getArea());
     }
 
-    public Node getPublicationNode() throws RepositoryException {
-        Node rootNode = getSession().getRootNode();
-
-        Node pubNode = null;
-
-        for (NodeIterator pubNodes = rootNode.getNodes("lenya:publication"); pubNodes.hasNext();) {
-            Node node = pubNodes.nextNode();
-            if (node.getProperty("lenya:id")
-                    .getString()
-                    .equals(getPublication().getPublicationId())) {
-                pubNode = node;
-            }
-        }
-        if (pubNode == null) {
-            pubNode = rootNode.addNode("lenya:publication");
-            pubNode.setProperty("lenya:id", getPublication().getPublicationId());
-        }
-
-        return pubNode;
+    protected JCRPublicationNode getPublicationNode()
+            throws org.apache.lenya.cms.repo.RepositoryException {
+        JCRPublicationNodeBuilder builder = new JCRPublicationNodeBuilder(getPublication().getPublicationId(),
+                getArea());
+        return (JCRPublicationNode) this.nodeManager.getNode(JCRPublicationNodeBuilder.NODE_NAME,
+                builder,
+                true);
     }
 
     protected Node getSubNode(Node parent, String childName) throws RepositoryException {
@@ -76,12 +76,19 @@
         return child;
     }
 
-    public Node getContentNode() throws RepositoryException {
-        return getSubNode(getPublicationNode(), "lenya:content");
+    public Content getContent() throws org.apache.lenya.cms.repo.RepositoryException {
+        NodeWrapperBuilder builder = new JCRContentBuilder(this);
+        return (Content) this.nodeManager.getNode(JCRContentBuilder.NODE_NAME, builder, true);
+    }
+
+    public Site getSite() throws org.apache.lenya.cms.repo.RepositoryException {
+        NodeWrapperBuilder builder = new JCRSiteBuilder(this);
+        return (Site) this.nodeManager.getNode(JCRSiteBuilder.NODE_NAME, builder, true);
     }
 
-    public Node getSiteNode() throws RepositoryException {
-        return getSubNode(getPublicationNode(), "lenya:site");
+    public void clear() throws org.apache.lenya.cms.repo.RepositoryException {
+        // TODO Auto-generated method stub
+
     }
 
 }

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+import org.apache.lenya.cms.repo.Content;
+import org.apache.lenya.cms.repo.ContentNode;
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * JCR content implementation.
+ */
+public class JCRContent extends NodeWrapper implements Content {
+
+    /**
+     * Ctor.
+     * @param node The JCR node.
+     * @param area The area.
+     */
+    public JCRContent(Node node, JCRArea area) {
+        super(node);
+        this.area = area;
+        this.nodeManager = new NodeWrapperManager(area.getPublication().getSession());
+    }
+
+    private JCRArea area;
+
+    protected JCRArea getArea() {
+        return this.area;
+    }
+
+    private NodeWrapperManager nodeManager;
+
+    public ContentNode getNode(String id) throws RepositoryException {
+        NodeWrapperBuilder builder = new JCRContentNodeBuilder(this, id);
+        ContentNode node = (ContentNode) this.nodeManager.getNode(id, builder, false);
+        if (node == null) {
+            throw new RepositoryException("The content node [" + id + "]Êdoes not exist.");
+        }
+        return node;
+    }
+
+    public ContentNode[] getNodes() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public ContentNode addNode(String id) throws RepositoryException {
+        NodeWrapperBuilder builder = new JCRContentNodeBuilder(this, id);
+        return (ContentNode) this.nodeManager.getNode(id, builder, true);
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * JCR content builder.
+ */
+public class JCRContentBuilder implements NodeWrapperBuilder {
+    
+    private JCRArea area;
+    
+    /**
+     * Ctor.
+     * @param area The area.
+     */
+    public JCRContentBuilder(JCRArea area) {
+        this.area = area;
+    }
+
+    protected static final String NODE_NAME = "lenya:content";
+
+    public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+        try {
+            
+            Node pubNode = this.area.getPublicationNode().getNode();
+            JCRContent wrapper = null;
+            Node contentNode;
+            if (pubNode.hasNode(NODE_NAME)) {
+                contentNode = pubNode.getNode(NODE_NAME);
+                wrapper = new JCRContent(contentNode, area);
+            }
+            else if (create) {
+                contentNode = pubNode.addNode(NODE_NAME);
+                wrapper = new JCRContent(contentNode, area);
+            }
+            
+            return wrapper;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.lenya.cms.repo.ContentNode;
+import org.apache.lenya.cms.repo.Document;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.SiteNode;
+
+/**
+ * JCR content node.
+ */
+public class JCRContentNode extends NodeWrapper implements ContentNode {
+
+    private NodeWrapperManager documentManager;
+    private JCRContent content;
+    
+    public JCRContentNode(JCRContent content, Node node) {
+        super(node);
+        this.content = content;
+        this.documentManager = new NodeWrapperManager(content.getArea().getPublication().getSession());
+    }
+    
+    public Document[] getDocuments() throws RepositoryException {
+        return null;
+    }
+
+    public void addDocument(String language) throws RepositoryException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void removeDocument(Document document) throws RepositoryException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public Document getDocument(String language) throws RepositoryException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * JCR content node builder.
+ */
+public class JCRContentNodeBuilder implements NodeWrapperBuilder {
+
+    protected static final String NODE_NAME = "lenya:contentnode";
+    protected static final String ID_ATTRIBUTE = "lenya:id";
+
+    private String id;
+    private JCRContent content;
+
+    /**
+     * Ctor.
+     * @param content The content.
+     * @param id The id.
+     */
+    public JCRContentNodeBuilder(JCRContent content, String id) {
+        this.id = id;
+        this.content = content;
+    }
+
+    public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+        try {
+            JCRContentNode jcrContentNode = null;
+            Node contentNode = null;
+            Node content = this.content.getNode();
+            for (NodeIterator nodes = content.getNodes(NODE_NAME); nodes.hasNext();) {
+                Node node = nodes.nextNode();
+                if (node.getProperty(ID_ATTRIBUTE).getString().equals(this.id)) {
+                    contentNode = node;
+                }
+            }
+            if (contentNode == null && create) {
+                contentNode = content.addNode(NODE_NAME);
+                contentNode.setProperty(ID_ATTRIBUTE, this.id);
+            }
+            if (contentNode != null) {
+                jcrContentNode = new JCRContentNode(this.content, contentNode);
+            }
+
+            return jcrContentNode;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,21 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+public class JCRDocument {
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,21 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+public class JCRDocumentBuilder {
+
+}

Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java?rev=330846&r1=330845&r2=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java Fri Nov  4 09:22:03 2005
@@ -19,19 +19,24 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
+import org.apache.lenya.cms.repo.Area;
+import org.apache.lenya.cms.repo.Publication;
+import org.apache.lenya.cms.repo.RepositoryException;
 
-public class JCRPublication {
+/**
+ * JCR publication.
+ */
+public class JCRPublication implements Publication {
 
     private String pubId;
-    private RepositorySession session;
+    private JCRSession session;
 
-    public JCRPublication(RepositorySession session, String pubId) {
+    /**
+     * Ctor.
+     * @param session The session.
+     * @param pubId The publication ID.
+     */
+    public JCRPublication(JCRSession session, String pubId) {
         this.pubId = pubId;
         this.session = session;
     }
@@ -40,13 +45,13 @@
         return this.pubId;
     }
 
-    protected RepositorySession getSession() {
+    protected JCRSession getSession() {
         return this.session;
     }
-    
+
     private Map areas = new HashMap();
-    
-    public JCRArea getArea(String area) {
+
+    public Area getArea(String area) throws RepositoryException {
         JCRArea jcrArea = (JCRArea) this.areas.get(area);
         if (jcrArea == null) {
             jcrArea = new JCRArea(this, area);

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+/**
+ * Publication node.
+ */
+public class JCRPublicationNode extends NodeWrapper {
+
+    /**
+     * Ctor.
+     * @param node The JCR node.
+     */
+    public JCRPublicationNode(Node node) {
+        super(node);
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * JCR publication node builder.
+ */
+public class JCRPublicationNodeBuilder implements NodeWrapperBuilder {
+
+    /**
+     * Ctor.
+     * @param pubId The publication ID.
+     * @param area The area.
+     */
+    public JCRPublicationNodeBuilder(String pubId, String area) {
+        this.pubId = pubId;
+        this.area = area;
+    }
+
+    private String pubId;
+    private String area;
+
+    protected static final String NODE_NAME = "lenya:publication";
+    protected static final String ID_ATTRIBUTE = "lenya:id";
+
+    public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+        try {
+            JCRPublicationNode wrapper = null;
+            Node rootNode = session.getSession(area).getRootNode();
+
+            Node pubNode = null;
+
+            for (NodeIterator pubNodes = rootNode.getNodes(NODE_NAME); pubNodes.hasNext();) {
+                Node node = pubNodes.nextNode();
+                if (node.getProperty(ID_ATTRIBUTE).getString().equals(pubId)) {
+                    pubNode = node;
+                }
+            }
+            if (pubNode == null && create) {
+                pubNode = rootNode.addNode(NODE_NAME);
+                pubNode.setProperty(ID_ATTRIBUTE, pubId);
+            }
+
+            if (pubNode != null) {
+                wrapper = new JCRPublicationNode(pubNode);
+            }
+            return wrapper;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+}

Copied: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java (from r330793, lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFacade.java)
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java?p2=lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java&p1=lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFacade.java&r1=330793&r2=330846&rev=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositoryFacade.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java Fri Nov  4 09:22:03 2005
@@ -16,52 +16,35 @@
  */
 package org.apache.lenya.cms.jcr;
 
-import java.io.File;
-
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
 
 /**
  * Facade to the JCR repository, providing Lenya-specific access.
  */
-public class RepositoryFacade {
-
-    public RepositoryFacade(String webappDirectoryPath, String repositoryFactoryClass)
-            throws RepositoryException {
-        try {
-            Class repoFactoryClass = Class.forName(repositoryFactoryClass);
-            RepositoryFactory repoFactory = (RepositoryFactory) repoFactoryClass.newInstance();
-
-            File webappDirectory = new File(webappDirectoryPath);
+public class JCRRepository implements org.apache.lenya.cms.repo.Repository {
 
-            String jaasPath = "lenya/modules/jackrabbit/repository/jaas.config";
-            System.setProperty("java.security.auth.login.config", new File(webappDirectory,
-                    jaasPath).getAbsolutePath());
-
-            this.repository = repoFactory.getRepository(webappDirectoryPath);
-        } catch (RepositoryException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new RepositoryException(e);
-        }
+    /**
+     * Ctor.
+     * @param repository The repository.
+     */
+    public JCRRepository(Repository repository) {
+        this.repository = repository;
     }
 
     private Repository repository;
 
-    public Repository getRepository() {
+    protected Repository getRepository() {
         return this.repository;
     }
 
     /**
      * @return The repository session.
      */
-    public RepositorySession createSession() {
-        return new RepositorySession(this);
+    public org.apache.lenya.cms.repo.Session createSession() {
+        return new JCRSession(this);
     }
 
     protected Node getSubNode(Session session, Node parent, String childName)

Copied: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java (from r330793, lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositorySession.java)
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java?p2=lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java&p1=lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositorySession.java&r1=330793&r2=330846&rev=330846&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/RepositorySession.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java Fri Nov  4 09:22:03 2005
@@ -18,42 +18,39 @@
 
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
-import javax.jcr.LoginException;
 import javax.jcr.NamespaceRegistry;
-import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
-import javax.jcr.Workspace;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
 
 import org.apache.jackrabbit.core.WorkspaceImpl;
+import org.apache.lenya.cms.repo.Publication;
 
 /**
  * Repository session.
  */
-public class RepositorySession {
+public class JCRSession implements org.apache.lenya.cms.repo.Session {
 
     /**
      * Ctor.
      * @param repository The repository facade.
      */
-    public RepositorySession(RepositoryFacade repository) {
+    public JCRSession(JCRRepository repository) {
         this.repository = repository;
     }
 
-    private RepositoryFacade repository;
+    private JCRRepository repository;
 
-    protected RepositoryFacade getRepository() {
+    protected JCRRepository getRepository() {
         return this.repository;
     }
 
     private Map area2session = new HashMap();
-
-    public Session getSession(String area) throws RepositoryException {
+    
+    protected Session getSession(String area) throws RepositoryException {
         Session session = (Session) this.area2session.get(area);
         if (session == null) {
 
@@ -79,6 +76,30 @@
         }
 
         return session;
+    }
+
+    public void save() throws org.apache.lenya.cms.repo.RepositoryException {
+        try {
+            for (Iterator i = this.area2session.keySet().iterator(); i.hasNext();) {
+                String area = (String) i.next();
+                Session session = (Session) this.area2session.get(area);
+                session.save();
+            }
+        } catch (RepositoryException e) {
+            throw new org.apache.lenya.cms.repo.RepositoryException(e);
+        }
+    }
+
+    private Map publications = new HashMap();
+
+    public Publication getPublication(String id)
+            throws org.apache.lenya.cms.repo.RepositoryException {
+        Publication pub = (Publication) this.publications.get(id);
+        if (pub == null) {
+            pub = new JCRPublication(this, id);
+            this.publications.put(id, pub);
+        }
+        return pub;
     }
 
 }

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.lenya.cms.repo.ContentNode;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.Site;
+import org.apache.lenya.cms.repo.SiteNode;
+
+/**
+ * JCR site.
+ */
+public class JCRSite extends NodeWrapper implements Site {
+
+    private JCRArea area;
+
+    /**
+     * Ctor.
+     * @param node The node.
+     * @param area The area.
+     */
+    public JCRSite(Node node, JCRArea area) {
+        super(node);
+        this.area = area;
+        this.childManager = new NodeWrapperManager(area.getPublication().getSession());
+    }
+
+    protected JCRArea getArea() {
+        return this.area;
+    }
+
+    private NodeWrapperManager childManager;
+
+    public SiteNode[] getChildren() throws RepositoryException {
+        try {
+            NodeIterator i = getNode().getNodes();
+            List nodes = new ArrayList();
+            while (i.hasNext()) {
+                Node child = i.nextNode();
+                nodes.add(getChild(child.getName()));
+            }
+            return (SiteNode[]) nodes.toArray(new SiteNode[nodes.size()]);
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public SiteNode getChild(String name) throws RepositoryException {
+        JCRSiteNodeBuilder builder = new JCRSiteNodeBuilder(this, getNode(), name);
+        SiteNode child = (SiteNode) this.childManager.getNode(name, builder, false);
+        if (child == null) {
+            throw new RepositoryException("The node [" + name + "] does not exist!");
+        }
+        return child;
+    }
+
+    public SiteNode[] getNodes() throws RepositoryException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException {
+        JCRSiteNodeBuilder builder = new JCRSiteNodeBuilder(this, getNode(), name);
+        return (SiteNode) this.childManager.getNode(name, builder, false);
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * JCR site builder.
+ */
+public class JCRSiteBuilder implements NodeWrapperBuilder {
+    
+    private JCRArea area;
+    
+    /**
+     * Ctor.
+     * @param area The area.
+     */
+    public JCRSiteBuilder(JCRArea area) {
+        this.area = area;
+    }
+
+    protected static final String NODE_NAME = "lenya:site";
+
+    public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+        try {
+            
+            Node pubNode = this.area.getPublicationNode().getNode();
+            JCRSite wrapper = null;
+            Node siteNode = null;
+            if (pubNode.hasNode(NODE_NAME)) {
+                siteNode = pubNode.getNode(NODE_NAME);
+            }
+            else if (create) {
+                siteNode = pubNode.addNode(NODE_NAME);
+            }
+            if (siteNode != null) {
+                wrapper = new JCRSite(siteNode, area);
+            }
+            
+            return wrapper;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.lenya.cms.repo.ContentNode;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.SiteNode;
+
+/**
+ * JCR site node.
+ */
+public class JCRSiteNode extends NodeWrapper implements SiteNode {
+
+    private JCRSite site;
+
+    /**
+     * Ctor.
+     * @param node The JCR node.
+     * @param site The site.
+     */
+    public JCRSiteNode(Node node, JCRSite site) {
+        super(node);
+        this.site = site;
+        this.childManager = new NodeWrapperManager(site.getArea().getPublication().getSession());
+    }
+
+    public String getName() throws RepositoryException {
+        try {
+            return getNode().getName();
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+    
+    protected JCRSite getSite() {
+        return this.site;
+    }
+
+    private NodeWrapperManager childManager;
+
+    public SiteNode[] getChildren() throws RepositoryException {
+        try {
+            NodeIterator i = getNode().getNodes();
+            List nodes = new ArrayList();
+            while (i.hasNext()) {
+                Node child = i.nextNode();
+                nodes.add(getChild(child.getName()));
+            }
+            return (SiteNode[]) nodes.toArray(new SiteNode[nodes.size()]);
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+    public SiteNode getChild(String name) throws RepositoryException {
+        JCRSiteNodeBuilder builder = new JCRSiteNodeBuilder(getSite(), getNode(), name);
+        SiteNode child = (SiteNode) this.childManager.getNode(name, builder, false);
+        if (child == null) {
+            throw new RepositoryException("The node [" + getPath() + "/" + name
+                    + "] does not exist!");
+        }
+        return child;
+    }
+
+    public SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException {
+        JCRSiteNodeBuilder builder = new JCRSiteNodeBuilder(getSite(), getNode(), name);
+        return (SiteNode) this.childManager.getNode(name, builder, false);
+    }
+
+    public String getPath() throws RepositoryException {
+        // TODO Auto-generated method stub
+        return "";
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNodeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNodeBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNodeBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNodeBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * JCR site node builder.
+ */
+public class JCRSiteNodeBuilder implements NodeWrapperBuilder {
+
+    private Node parent;
+    private String name;
+    private JCRContentNode contentNode;
+    private JCRSite site;
+
+    /**
+     * Ctor.
+     * @param site The site.
+     * @param parent The parent JCR node.
+     * @param name The name.
+     * @param contentNode The referenced content node.
+     */
+    public JCRSiteNodeBuilder(JCRSite site, Node parent, String name, JCRContentNode contentNode) {
+        this(site, parent, name);
+        this.contentNode = contentNode;
+    }
+
+    /**
+     * Ctor.
+     * @param site The site.
+     * @param parent The parent JCR node.
+     * @param name The name.
+     */
+    public JCRSiteNodeBuilder(JCRSite site, Node parent, String name) {
+        this.site = site;
+        this.parent = parent;
+        this.name = name;
+    }
+
+    protected static final String CONTENT_NODE_PROPERTY = "lenya:contentnode";
+
+    public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+        try {
+
+            JCRSiteNode wrapper = null;
+            Node siteNode = null;
+            if (parent.hasNode(this.name)) {
+                siteNode = parent.getNode(this.name);
+            } else if (create) {
+
+                if (this.contentNode == null) {
+                    throw new RepositoryException("You must provide a content node when creating a new site node!");
+                }
+
+                siteNode = parent.addNode(this.name);
+                siteNode.setProperty(CONTENT_NODE_PROPERTY, this.contentNode.getNode());
+            }
+            if (siteNode != null) {
+                wrapper = new JCRSiteNode(siteNode, this.site);
+            }
+
+            return wrapper;
+        } catch (RepositoryException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new RepositoryException(e);
+        }
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+/**
+ * A JCR node wrapper.
+ */
+public abstract class NodeWrapper {
+
+    /**
+     * Ctor.
+     */
+    public NodeWrapper(Node node) {
+        this.node = node;
+    }
+
+    private Node node;
+
+    protected Node getNode() {
+        return this.node;
+    }
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperBuilder.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperBuilder.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,27 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import javax.jcr.Node;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+public interface NodeWrapperBuilder {
+
+    NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException;
+
+}

Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java?rev=330846&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java Fri Nov  4 09:22:03 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.jcr;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A list of node wrappers.
+ */
+public class NodeWrapperManager {
+
+    /**
+     * Ctor.
+     * @param session The session.
+     */
+    public NodeWrapperManager(JCRSession session) {
+        this.session = session;
+    }
+
+    private JCRSession session;
+
+    private Map key2node = new HashMap();
+
+    protected NodeWrapper getNode(String key, NodeWrapperBuilder builder, boolean create)
+            throws org.apache.lenya.cms.repo.RepositoryException {
+
+        NodeWrapper wrapper = (NodeWrapper) this.key2node.get(key);
+        if (wrapper == null) {
+            wrapper = builder.buildNode(this.session, create);
+            this.key2node.put(key, wrapper);
+        }
+
+        return wrapper;
+    }
+    
+}



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