You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by gr...@apache.org on 2005/06/01 05:25:39 UTC

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

Author: gregor
Date: Tue May 31 20:25:37 2005
New Revision: 179343

URL: http://svn.apache.org/viewcvs?rev=179343&view=rev
Log:
Allow to set the relation of a new document to an existing one, thanks to a patch by Doug Chestnut. This resolves http://issues.apache.org/bugzilla/show_bug.cgi?id=35130 

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=179343&r1=179342&r2=179343&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 May 31 20:25:37 2005
@@ -1,97 +1,129 @@
-/*
- * 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.site.usecases;
-
-import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentManager;
-import org.apache.lenya.cms.publication.Publication;
-
-/**
- * Usecase to create a document.
- * 
- * @version $Id$
- */
-public class CreateDocument extends Create {
-
-    protected static final String PARENT_ID = "parentId";
-    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);
-    }
-
-    /**
-     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
-     */
-    protected void doCheckExecutionConditions() throws Exception {
-        super.doCheckExecutionConditions();
-
-        String documentName = getParameterAsString(DOCUMENT_ID);
-        String language = getParameterAsString(LANGUAGE);
-        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#getNewDocumentId()
-     */
-    protected String getNewDocumentId() {
-        return getSourceDocument().getId() + "/" + getNewDocumentName();
-    }
-
-    /**
-     * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
-     */
-    protected String getDocumentTypeName() {
-        return getParameterAsString(DOCUMENT_TYPE);
-    }
+/*
+ * 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.site.usecases;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+
+/**
+ * Usecase to create a document.
+ * 
+ * @version $Id$
+ */
+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 RELATIONS = "relations";
+
+	/**
+	 * @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);
+	}
 }

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=179343&r1=179342&r2=179343&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 Tue May 31 20:25:37 2005
@@ -59,6 +59,16 @@
               </tr>
               <tr>
                 <td class="lenya-entry-caption">
+                  <label for="relation"><i18n:text>Relation</i18n:text>*: </label>
+                </td>
+                <td>
+                    <jx:forEach var="relation" items="${usecase.getParameter('relations')}">
+                      <input type="radio" name="relation" value="${relation}"/><i18n:text>${relation}</i18n:text>
+                    </jx:forEach>
+                </td>
+              </tr> 
+              <tr>
+                <td class="lenya-entry-caption">
                   <label for="language"><i18n:text>Language</i18n:text>*: </label></td>
                 <td>
                   <select class="lenya-form-element" name="language">



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