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/02/07 09:26:30 UTC

svn commit: r375544 - in /lenya/trunk/src/java/org/apache/lenya/cms: publication/ site/usecases/

Author: andreas
Date: Tue Feb  7 00:26:28 2006
New Revision: 375544

URL: http://svn.apache.org/viewcvs?rev=375544&view=rev
Log:
Moved method isValidDocumentName() from DocumentManager to DocumentBuilder. Allow dashes in document name in DefaultDocumentBuilder. This fixes bug #38127. Thanks for the patch by Renaud Richardet.

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocumentBuilder.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentBuilder.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java

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=375544&r1=375543&r2=375544&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 Tue Feb  7 00:26:28 2006
@@ -194,9 +194,7 @@
         }
 
         String documentURL = info.getDocumentUrl();
-        String originalURL = documentURL;
 
-        String extension = getExtension(documentURL);
         documentURL = removeExtensions(documentURL);
 
         String language = getLanguage(documentURL);
@@ -219,6 +217,13 @@
                 documentId,
                 language);
         return identifier;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.DocumentBuilder#isValidDocumentName(java.lang.String)
+     */
+    public boolean isValidDocumentName(String documentName) {
+        return documentName.matches("[a-zA-Z0-9\\-]+");
     }
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentBuilder.java?rev=375544&r1=375543&r2=375544&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentBuilder.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentBuilder.java Tue Feb  7 00:26:28 2006
@@ -29,14 +29,18 @@
      */
     String ROLE = DocumentBuilder.class.getName();
     
+    /**
+     * Returns a document identifier for a web application URL.
+     * @param webappUrl The web application URL.
+     * @return A document identifier.
+     * @throws DocumentBuildException if an error occurs.
+     */
     DocumentIdentifier getIdentitfier(String webappUrl) throws DocumentBuildException;
 
     /**
      * Builds a document.
      * @param map The identity map the document belongs to.
-     * @param publication The publication.
-     * @param url The URL of the form
-     *            /{publication-id}/{area}/{document-id}{language-suffix}.{extension}.
+     * @param identifier The document identifier.
      * @return A document.
      * @throws DocumentBuildException when something went wrong.
      */
@@ -45,7 +49,6 @@
 
     /**
      * Checks if an URL corresponds to a CMS document.
-     * @param publication The publication the document belongs to.
      * @param url The URL of the form /{publication-id}/...
      * @return A boolean value.
      * @throws DocumentBuildException when something went wrong.
@@ -53,14 +56,17 @@
     boolean isDocument(String url) throws DocumentBuildException;
 
     /**
-     * Builds an URL corresponding to a cms document from the publication, the area, the document id
-     * and the language
-     * @param publication The publication the document belongs to.
-     * @param area The area the document belongs to.
-     * @param documentid The document id of the document.
-     * @param language The language of the document.
-     * @return a String The builded url
+     * Builds an URL corresponding to a CMS document.
+     * @param identifier The document identifier.
+     * @return a String The corresponding URL.
      */
     String buildCanonicalUrl(DocumentIdentifier identifier);
+
+    /**
+     * Checks if a document name is valid.
+     * @param documentName The document name.
+     * @return A boolean value.
+     */
+    boolean isValidDocumentName(String documentName);
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java?rev=375544&r1=375543&r2=375544&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManager.java Tue Feb  7 00:26:28 2006
@@ -133,13 +133,6 @@
     void copy(DocumentSet sources, DocumentSet destinations) throws PublicationException;
     
     /**
-     * Checks if a document name is valid.
-     * @param documentName The document name.
-     * @return A boolean value.
-     */
-    boolean isValidDocumentName(String documentName);
-
-    /**
      * Moves a document to another location, incl. all requiring documents. If a sitetree is used,
      * this means that the whole subtree is moved.
      * @param source The source document.

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?rev=375544&r1=375543&r2=375544&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Tue Feb  7 00:26:28 2006
@@ -288,13 +288,6 @@
     }
 
     /**
-     * @see org.apache.lenya.cms.publication.DocumentManager#isValidDocumentName(java.lang.String)
-     */
-    public boolean isValidDocumentName(String documentName) {
-        return documentName.matches("[a-zA-Z0-9]+");
-    }
-
-    /**
      * @see org.apache.lenya.cms.publication.DocumentManager#moveAll(org.apache.lenya.cms.publication.Document,
      *      org.apache.lenya.cms.publication.Document)
      */

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java?rev=375544&r1=375543&r2=375544&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeNodeID.java Tue Feb  7 00:26:28 2006
@@ -21,8 +21,10 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.publication.DocumentBuilder;
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.DocumentIdentityMap;
 import org.apache.lenya.cms.publication.DocumentManager;
@@ -121,10 +123,13 @@
         super.doCheckExecutionConditions();
 
         String nodeId = getParameterAsString(NODE_ID);
-        DocumentManager documentManager = null;
+        ServiceSelector selector = null;
+        DocumentBuilder builder = null;
         try {
-            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
-            if (!documentManager.isValidDocumentName(nodeId)) {
+            selector = (ServiceSelector) this.manager.lookup(DocumentBuilder.ROLE + "Selector");
+            String hint = getSourceDocument().getPublication().getDocumentBuilderHint();
+            builder = (DocumentBuilder) selector.select(hint);
+            if (!builder.isValidDocumentName(nodeId)) {
                 addErrorMessage("The document ID is not valid.");
             } else {
                 Document document = getTargetDocument();
@@ -133,8 +138,11 @@
                 }
             }
         } finally {
-            if (documentManager != null) {
-                this.manager.release(documentManager);
+            if (selector != null) {
+                if (builder != null) {
+                    selector.release(builder);
+                }
+                this.manager.release(selector);
             }
         }
     }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java?rev=375544&r1=375543&r2=375544&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java Tue Feb  7 00:26:28 2006
@@ -18,8 +18,9 @@
 
 import java.util.Arrays;
 
+import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.DocumentBuilder;
 import org.apache.lenya.cms.publication.Publication;
 
 /**
@@ -86,16 +87,19 @@
             addErrorMessage("The relation '" + relation + "' is not supported.");
         }
 
-        DocumentManager documentManager = null;
+        ServiceSelector selector = null;
+        DocumentBuilder builder = null;
         try {
-            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+            selector = (ServiceSelector) this.manager.lookup(DocumentBuilder.ROLE + "Selector");
+            String hint = getSourceDocument().getPublication().getDocumentBuilderHint();
+            builder = (DocumentBuilder) selector.select(hint);
 
             boolean provided = getParameterAsBoolean(DOCUMENT_ID_PROVIDED, false);
-            if (!provided && !documentManager.isValidDocumentName(documentName)) {
+            if (!provided && !builder.isValidDocumentName(documentName)) {
                 addErrorMessage("The document ID may not contain any special characters.");
             } else {
                 Publication publication = getSourceDocument().getPublication();
-                String newDocumentId = getNewDocumentId(); 
+                String newDocumentId = getNewDocumentId();
                 Document document = getSourceDocument().getIdentityMap().get(publication,
                         getSourceDocument().getArea(),
                         newDocumentId,
@@ -105,8 +109,11 @@
                 }
             }
         } finally {
-            if (documentManager != null) {
-                this.manager.release(documentManager);
+            if (selector != null) {
+                if (builder != null) {
+                    selector.release(builder);
+                }
+                this.manager.release(selector);
             }
         }
     }



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