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/06/01 09:54:32 UTC

svn commit: r179368 - in /lenya/trunk/src: java/org/apache/lenya/cms/site/usecases/CreateDocument.java webapp/lenya/pubs/default/lenya/usecases/site/create.jx

Author: andreas
Date: Wed Jun  1 00:54:31 2005
New Revision: 179368

URL: http://svn.apache.org/viewcvs?rev=179368&view=rev
Log:
create-document usecase: checking selected relation in JX template, validate relation in exec conditions, set initial relation 'child'

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
    lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/site/create.jx

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=179368&r1=179367&r2=179368&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 Wed Jun  1 00:54:31 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.lenya.cms.site.usecases;
 
+import java.util.Arrays;
+
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentManager;
 import org.apache.lenya.cms.publication.Publication;
@@ -27,103 +29,117 @@
  */
 public class CreateDocument extends Create {
 
-	protected static final String PARENT_ID = "parentId";
-
-	protected static final String DOCUMENT_TYPE = "doctype";
-
-	protected static final String RELATION = "relation";
+    protected static final String PARENT_ID = "parentId";
 
-	protected static final String RELATIONS = "relations";
+    protected static final String DOCUMENT_TYPE = "doctype";
 
-	/**
-	 * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
-	 */
-	protected void initParameters() {
-		super.initParameters();
-
-		Document parent = getSourceDocument();
-		if (parent != null) {
-			setParameter(PARENT_ID, parent.getId());
-		} else {
-			setParameter(PARENT_ID, "");
-		}
-
-		String[] languages = parent.getPublication().getLanguages();
-		setParameter(LANGUAGES, languages);
-
-		/** todo: need to check valid relations for this new doc * */
-		String[] relations = { "child", "after" }; // "after");
-		setParameter(RELATIONS, relations);
-
-	}
-
-	/**
-	 * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
-	 */
-	protected void doCheckExecutionConditions() throws Exception {
-		super.doCheckExecutionConditions();
-
-		String documentName = getParameterAsString(DOCUMENT_ID);
-		String language = getParameterAsString(LANGUAGE);
-		String relation = getParameterAsString(RELATION);
-		DocumentManager documentManager = null;
-		try {
-			documentManager = (DocumentManager) this.manager
-					.lookup(DocumentManager.ROLE);
-			Document parent = getSourceDocument();
-			Publication publication = getSourceDocument().getPublication();
-			Document document = getSourceDocument().getIdentityMap().get(
-					publication, getSourceDocument().getArea(),
-					parent.getId() + "/" + documentName, language);
-			if (document.exists()) {
-				addErrorMessage("The document does already exist.");
-			}
-		} finally {
-			if (documentManager != null) {
-				this.manager.release(documentManager);
-			}
-		}
-	}
-
-	/**
-	 * @see Create#getNewDocumentName()
-	 */
-	protected String getNewDocumentName() {
-		return getParameterAsString(DOCUMENT_ID);
-	}
-
-	/**
-	 * @see Create#getNewRelation()
-	 */
-	protected String getRelation() {
-		return getParameterAsString(RELATION);
-	}
-
-	/**
-	 * @see Create#getNewDocumentId()
-	 */
-	protected String getNewDocumentId() {
-		String relation = getRelation();
-		Document sourceDoc = getSourceDocument();
-		if (relation.equals("child")) {
-			return sourceDoc.getId() + "/" + getNewDocumentName();
-		} else if (relation.equals("before")) {
-			return sourceDoc.getId().substring(0,
-					sourceDoc.getId().lastIndexOf(sourceDoc.getName()))
-					+ getNewDocumentName();
-		} else if (relation.equals("after")) {
-			return sourceDoc.getId().substring(0,
-					sourceDoc.getId().lastIndexOf(sourceDoc.getName()))
-					+ getNewDocumentName();
-		} else {
-			return getSourceDocument().getId() + "/" + getNewDocumentName();
-		}
-	}
-
-	/**
-	 * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
-	 */
-	protected String getDocumentTypeName() {
-		return getParameterAsString(DOCUMENT_TYPE);
-	}
+    protected static final String RELATION = "relation";
+    protected static final String RELATIONS = "relations";
+    protected static final String RELATION_CHILD = "child";
+    protected static final String RELATION_BEFORE = "before";
+    protected static final String RELATION_AFTER = "after";
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+     */
+    protected void initParameters() {
+        super.initParameters();
+
+        Document parent = getSourceDocument();
+        if (parent != null) {
+            setParameter(PARENT_ID, parent.getId());
+        } else {
+            setParameter(PARENT_ID, "");
+        }
+
+        String[] languages = parent.getPublication().getLanguages();
+        setParameter(LANGUAGES, languages);
+
+        String[] relations = { RELATION_CHILD, RELATION_AFTER };
+        setParameter(RELATIONS, relations);
+        setParameter(RELATION, RELATION_CHILD);
+    }
+
+    /**
+     * Override this method to support other relations.
+     * @return The supported relations.
+     */
+    protected String[] getSupportedRelations() {
+        return new String[] { RELATION_CHILD, RELATION_AFTER };
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
+     */
+    protected void doCheckExecutionConditions() throws Exception {
+        super.doCheckExecutionConditions();
+
+        String documentName = getParameterAsString(DOCUMENT_ID);
+        String language = getParameterAsString(LANGUAGE);
+        String relation = getParameterAsString(RELATION);
+
+        if (!Arrays.asList(getSupportedRelations()).contains(relation)) {
+            addErrorMessage("The relation '" + relation + "' is not supported.");
+        }
+
+        DocumentManager documentManager = null;
+        try {
+            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+            Document parent = getSourceDocument();
+            Publication publication = getSourceDocument().getPublication();
+            Document document = getSourceDocument().getIdentityMap().get(publication,
+                    getSourceDocument().getArea(),
+                    parent.getId() + "/" + documentName,
+                    language);
+            if (document.exists()) {
+                addErrorMessage("The document does already exist.");
+            }
+        } finally {
+            if (documentManager != null) {
+                this.manager.release(documentManager);
+            }
+        }
+    }
+
+    /**
+     * @see Create#getNewDocumentName()
+     */
+    protected String getNewDocumentName() {
+        return getParameterAsString(DOCUMENT_ID);
+    }
+
+    /**
+     * @return The relation between the source document and the created document.
+     */
+    protected String getRelation() {
+        return getParameterAsString(RELATION);
+    }
+
+    /**
+     * @see Create#getNewDocumentId()
+     */
+    protected String getNewDocumentId() {
+        String relation = getRelation();
+        Document sourceDoc = getSourceDocument();
+        if (relation.equals(RELATION_CHILD)) {
+            return sourceDoc.getId() + "/" + getNewDocumentName();
+        } else if (relation.equals(RELATION_BEFORE)) {
+            return sourceDoc.getId().substring(0,
+                    sourceDoc.getId().lastIndexOf(sourceDoc.getName()))
+                    + getNewDocumentName();
+        } else if (relation.equals(RELATION_AFTER)) {
+            return sourceDoc.getId().substring(0,
+                    sourceDoc.getId().lastIndexOf(sourceDoc.getName()))
+                    + getNewDocumentName();
+        } else {
+            return getSourceDocument().getId() + "/" + getNewDocumentName();
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
+     */
+    protected String getDocumentTypeName() {
+        return getParameterAsString(DOCUMENT_TYPE);
+    }
 }

Modified: lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/site/create.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/site/create.jx?rev=179368&r1=179367&r2=179368&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/site/create.jx (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/lenya/usecases/site/create.jx Wed Jun  1 00:54:31 2005
@@ -63,7 +63,14 @@
                 </td>
                 <td>
                     <jx:forEach var="relation" items="${usecase.getParameter('relations')}">
-                      <input type="radio" name="relation" value="${relation}"/><i18n:text>${relation}</i18n:text>
+                      <jx:choose>
+                        <jx:when test="${relation.equals(usecase.getParameter('relation'))}">
+                          <input type="radio" name="relation" value="${relation}" checked="checked"/><i18n:text>${relation}</i18n:text>
+                        </jx:when>
+                        <jx:otherwise>
+                          <input type="radio" name="relation" value="${relation}"/><i18n:text>${relation}</i18n:text>
+                        </jx:otherwise>
+                      </jx:choose>
                     </jx:forEach>
                 </td>
               </tr> 



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