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/02/23 16:26:41 UTC
svn commit: r155023 - in lenya/trunk/src/java/org/apache/lenya/cms:
publication/DocumentFactory.java site/usecases/CreateDocument.java
Author: andreas
Date: Wed Feb 23 07:26:41 2005
New Revision: 155023
URL: http://svn.apache.org/viewcvs?view=rev&rev=155023
Log:
use site utility to validate document ID
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateDocument.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java?view=diff&r1=155022&r2=155023
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java Wed Feb 23 07:26:41 2005
@@ -139,5 +139,31 @@
}
return parent;
}
+
+ /**
+ * Checks if a string represents a valid document ID.
+ * @param id The string.
+ * @return A boolean value.
+ */
+ public boolean isValidDocumentId(String id) {
+
+ if (!id.startsWith("/")) {
+ return false;
+ }
+
+ String[] snippets = id.split("/");
+
+ if (snippets.length < 2) {
+ return false;
+ }
+
+ for (int i = 1; i < snippets.length; i++) {
+ if (!snippets[i].matches("[a-zA-Z0-9\\-]+")) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
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?view=diff&r1=155022&r2=155023
==============================================================================
--- 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 Feb 23 07:26:41 2005
@@ -53,18 +53,13 @@
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
*/
protected void doCheckExecutionConditions() throws Exception {
-
- String documentId = getParameterAsString(DOCUMENT_ID);
-
- if (documentId.equals("")) {
- addErrorMessage("The document ID is required.");
- }
-
- if (documentId.matches("[^a-zA-Z0-9\\-]+")) {
- addErrorMessage("The document ID is not valid.");
- }
-
super.doCheckExecutionConditions();
+
+ String nodeId = getParameterAsString(DOCUMENT_ID);
+ Document parent = getSourceDocument();
+ String language = getParameterAsString(LANGUAGE);
+ SiteUtility util = new SiteUtility();
+ addErrorMessages(util.canCreate(parent, nodeId, language));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org