You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/08/10 18:21:18 UTC

svn commit: r430422 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/publication/

Author: andreas
Date: Thu Aug 10 09:21:17 2006
New Revision: 430422

URL: http://svn.apache.org/viewvc?rev=430422&view=rev
Log:
Added Area interface

Added:
    lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/AreaImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Area.java
Modified:
    lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java

Added: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/AreaImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/AreaImpl.java?rev=430422&view=auto
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/AreaImpl.java (added)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/AreaImpl.java Thu Aug 10 09:21:17 2006
@@ -0,0 +1,98 @@
+/*
+ * 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.publication;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteStructure;
+
+/**
+ * Area implementation.
+ */
+public class AreaImpl implements Area {
+
+    private String name;
+    private Publication pub;
+    private DocumentFactory factory;
+    private ServiceManager manager;
+
+    /**
+     * @param manager The service manager.
+     * @param factory The factory.
+     * @param pub The publication.
+     * @param name The area name.
+     */
+    public AreaImpl(ServiceManager manager, DocumentFactory factory, Publication pub, String name) {
+        this.manager = manager;
+        this.factory = factory;
+        this.pub = pub;
+        this.name = name;
+    }
+
+    public boolean contains(String uuid, String language) {
+        String sourceUri = DocumentImpl.getSourceURI(pub, name, uuid, language);
+        Node node = DocumentImpl.getRepositoryNode(this.manager, this.factory, sourceUri);
+        try {
+            return node.exists();
+        } catch (RepositoryException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Document getDocument(String uuid, String language) throws PublicationException {
+        if (!contains(uuid, language)) {
+            throw new PublicationException("The area [" + this + "] doesn't contain the document ["
+                    + uuid + ":" + language + "].");
+        }
+        return this.factory.get(getPublication(), getName(), uuid, language);
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public Publication getPublication() {
+        return this.pub;
+    }
+
+    public SiteStructure getSite() {
+        SiteManager siteManager = null;
+        ServiceSelector selector = null;
+        try {
+            selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
+            siteManager = (SiteManager) selector.select(getPublication().getSiteManagerHint());
+            return siteManager.getSiteStructure(this.factory, getPublication(), getName());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (selector != null) {
+                if (siteManager != null) {
+                    selector.release(siteManager);
+                }
+                this.manager.release(selector);
+            }
+        }
+    }
+    
+    public String toString() {
+        return getPublication().getId() + ":" + getName();
+    }
+
+}

Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=430422&r1=430421&r2=430422&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java Thu Aug 10 09:21:17 2006
@@ -699,4 +699,8 @@
         throw new DocumentException("The document [" + this
                 + "] is not referenced in the site structure!");
     }
+
+    public Area area() {
+        return new AreaImpl(this.manager, getFactory(), getPublication(), getArea());
+    }
 }

Added: lenya/trunk/src/java/org/apache/lenya/cms/publication/Area.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Area.java?rev=430422&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Area.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Area.java Thu Aug 10 09:21:17 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.publication;
+
+import org.apache.lenya.cms.site.SiteStructure;
+
+/**
+ * An area.
+ */
+public interface Area {
+
+    /**
+     * @return The name of the area ("authoring", "live", etc.).
+     */
+    String getName();
+    
+    /**
+     * @return The publication the area belongs to.
+     */
+    Publication getPublication();
+    
+    /**
+     * @return The site structure of the area.
+     */
+    SiteStructure getSite();
+    
+    /**
+     * @param uuid The UUID.
+     * @param language The language.
+     * @return A document.
+     * @throws PublicationException if the document is not contained.
+     */
+    Document getDocument(String uuid, String language) throws PublicationException;
+    
+    /**
+     * Checks if a document is contained.
+     * @param uuid The UUID.
+     * @param language The language.
+     * @return A boolean value.
+     */
+    boolean contains(String uuid, String language);
+    
+}

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java?rev=430422&r1=430421&r2=430422&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Thu Aug 10 09:21:17 2006
@@ -318,5 +318,10 @@
      * @throws DocumentException if the document is not referenced in the site structure.
      */
     Link getLink() throws DocumentException;
-
+    
+    /**
+     * @return The area the document belongs to.
+     */
+    Area area();
+    
 }



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