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/08/29 23:38:10 UTC

svn commit: r264643 - in /lenya/trunk/src/java/org/apache/lenya/cms: cocoon/transformation/WorkflowMenuTransformer.java publication/DefaultDocumentBuilder.java publication/URLInformation.java

Author: andreas
Date: Mon Aug 29 14:38:03 2005
New Revision: 264643

URL: http://svn.apache.org/viewcvs?rev=264643&view=rev
Log:
[minor change] cleaned up document builder code to use URLInformation, simplified WorkflowMenuTransformer code

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/URLInformation.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java?rev=264643&r1=264642&r2=264643&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java Mon Aug 29 14:38:03 2005
@@ -126,10 +126,10 @@
             Session session = RepositoryUtil.getSession(request, getLogger());
             DocumentIdentityMap map = new DocumentIdentityMap(session, this.manager, getLogger());
 
-            Document document = map.getFromURL(ServletHelper.getWebappURI(request));
-            if (document == null) {
-                setHasWorkflow(false);
-            } else {
+            String webappUrl = ServletHelper.getWebappURI(request);
+            Document document = null;
+            if (map.isDocument(webappUrl)) {
+                document = map.getFromURL(webappUrl);
                 ResourceType doctype = document.getResourceType();
                 if (document.getPublication().getWorkflowSchema(doctype) != null) {
                     setHasWorkflow(true);
@@ -137,6 +137,8 @@
                 } else {
                     setHasWorkflow(false);
                 }
+            } else {
+                setHasWorkflow(false);
             }
 
             if (hasWorkflow()) {

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java?rev=264643&r1=264642&r2=264643&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java Mon Aug 29 14:38:03 2005
@@ -133,19 +133,12 @@
         boolean isDocument = false;
 
         URLInformation info = new URLInformation(url);
-
-        String publicationURI = url.substring(("/" + info.getPublicationId()).length());
-        if (publicationURI.startsWith("/")) {
-            publicationURI = publicationURI.substring(1);
-
-            int slashIndex = publicationURI.indexOf("/");
-            if (slashIndex > -1) {
-                String area = publicationURI.substring(0, slashIndex);
-                String documentUri = publicationURI.substring(slashIndex);
-                if (PublicationImpl.isValidArea(area) && !area.equals(Publication.ADMIN_AREA)
-                        && documentUri.startsWith("/") && documentUri.length() > 1) {
-                    isDocument = true;
-                }
+        String area = info.getArea();
+        if (area != null && PublicationImpl.isValidArea(area)
+                && !area.equals(Publication.ADMIN_AREA)) {
+            String documentUrl = info.getDocumentUrl();
+            if (documentUrl != null && documentUrl.startsWith("/") && documentUrl.length() > 1) {
+                isDocument = true;
             }
         }
 
@@ -185,6 +178,12 @@
      * @see org.apache.lenya.cms.publication.DocumentBuilder#getIdentitfier(java.lang.String)
      */
     public DocumentIdentifier getIdentitfier(String webappUrl) throws DocumentBuildException {
+
+        if (!isDocument(webappUrl)) {
+            throw new DocumentBuildException("The webapp URL [" + webappUrl
+                    + "] does not refer to a document!");
+        }
+
         URLInformation info = new URLInformation(webappUrl);
 
         Publication publication;

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/URLInformation.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/URLInformation.java?rev=264643&r1=264642&r2=264643&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/URLInformation.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/URLInformation.java Mon Aug 29 14:38:03 2005
@@ -23,12 +23,12 @@
  * This class resolves all Lenya-specific information from a webapp URL.
  */
 public class URLInformation {
-    
+
     private String publicationId = null;
     private String area = null;
-	private String completeArea = null;
+    private String completeArea = null;
     private String documentUrl = null;
-    
+
     /**
      * Returns the area (without the "info-" prefix).
      * @return A string.
@@ -37,13 +37,13 @@
         return this.area;
     }
 
-	/**
-	 * Returns the complete area (including the "info-" prefix).
-	 * @return A string.
-	 */
-	public String getCompleteArea() {
-		return this.completeArea;
-	}
+    /**
+     * Returns the complete area (including the "info-" prefix).
+     * @return A string.
+     */
+    public String getCompleteArea() {
+        return this.completeArea;
+    }
 
     /**
      * Returns the document URL.
@@ -67,30 +67,29 @@
      */
     public URLInformation(String webappUrl) {
         assert webappUrl.startsWith("/");
-        
+
         String url = webappUrl.substring(1);
-        
+
         String[] fragments = url.split("/");
-        this.publicationId = fragments[0];
-        
-        if (fragments.length > 1) {
-            this.completeArea = fragments[1];
-            
-            if (url.length() > (this.publicationId + "/" + this.completeArea).length()) {
-                this.documentUrl = url.substring((this.publicationId + "/" + this.completeArea).length());
-            }
-            else {
-                this.documentUrl = "";
-            }
-            
-            if (this.completeArea.startsWith(Publication.SEARCH_AREA_PREFIX)) {
-                this.area = this.completeArea.substring(Publication.SEARCH_AREA_PREFIX.length());
-            }
-            else {
-            	this.area = this.completeArea;
+        if (fragments.length > 0) {
+            this.publicationId = fragments[0];
+
+            if (fragments.length > 1) {
+                this.completeArea = fragments[1];
+
+                if (url.length() > (this.publicationId + "/" + this.completeArea).length()) {
+                    this.documentUrl = url.substring((this.publicationId + "/" + this.completeArea).length());
+                } else {
+                    this.documentUrl = "";
+                }
+
+                if (this.completeArea.startsWith(Publication.SEARCH_AREA_PREFIX)) {
+                    this.area = this.completeArea.substring(Publication.SEARCH_AREA_PREFIX.length());
+                } else {
+                    this.area = this.completeArea;
+                }
             }
         }
     }
-    
-    
+
 }



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