[Yanel-commits] rev 60755 - in public/yanel/trunk/src/resources/comment: htdocs src/java/org/wyona/yanel/impl/resources/comment
michi at wyona.com
michi at wyona.com
Fri Sep 16 16:52:50 CEST 2011
Author: michi
Date: 2011-09-16 16:52:49 +0200 (Fri, 16 Sep 2011)
New Revision: 60755
Modified:
public/yanel/trunk/src/resources/comment/htdocs/add-comment.xsl
public/yanel/trunk/src/resources/comment/src/java/org/wyona/yanel/impl/resources/comment/CommentResource.java
Log:
field validation added
Modified: public/yanel/trunk/src/resources/comment/htdocs/add-comment.xsl
===================================================================
--- public/yanel/trunk/src/resources/comment/htdocs/add-comment.xsl 2011-09-16 12:05:16 UTC (rev 60754)
+++ public/yanel/trunk/src/resources/comment/htdocs/add-comment.xsl 2011-09-16 14:52:49 UTC (rev 60755)
@@ -52,16 +52,23 @@
<form>
<input type="hidden" name="path" value="{@path}"/>
Title<br/>
- <input type="text" name="title"/>
+ <input type="text" name="title" value="{title}"/>
<br/><br/>
Body<br/>
- <textarea cols="50" rows="10" name="body"/>
+ <xsl:choose>
+ <xsl:when test="text">
+ <textarea cols="50" rows="10" name="body"><xsl:value-of select="text"/></textarea>
+ </xsl:when>
+ <xsl:otherwise>
+ <textarea cols="50" rows="10" name="body"/>
+ </xsl:otherwise>
+ </xsl:choose>
<br/><br/>
E-Mail (please note that your email will not be displayed to the public)<br/>
- <input type="text" name="email"/>
+ <input type="text" name="email" value="{author-email-address}"/>
<br/><br/>
Name (optional, whereas please note that your name will not be displayed to the public)<br/>
- <input type="text" name="name"/>
+ <input type="text" name="name" value="{author-name}"/>
<br/><br/>
<input type="submit" value="Add comment"/>
</form>
Modified: public/yanel/trunk/src/resources/comment/src/java/org/wyona/yanel/impl/resources/comment/CommentResource.java
===================================================================
--- public/yanel/trunk/src/resources/comment/src/java/org/wyona/yanel/impl/resources/comment/CommentResource.java 2011-09-16 12:05:16 UTC (rev 60754)
+++ public/yanel/trunk/src/resources/comment/src/java/org/wyona/yanel/impl/resources/comment/CommentResource.java 2011-09-16 14:52:49 UTC (rev 60755)
@@ -75,12 +75,29 @@
* Generate XML expressing that no valid comment has been submitted yet
* @param path Path of commentable resource
* @param message Message why comment might not be valid
+ * @param comment Comment which might has been submitted, but is not valid
*/
- private String generateNoValidCommentSubmittedYetXML(String path, String message) {
+ private String generateNoValidCommentSubmittedYetXML(String path, String message, CommentV1 comment) {
StringBuilder sb = new StringBuilder("<no-valid-comment-submitted-yet path=\"" + path + "\">");
if (message != null) {
sb.append("<message>" + message + "</message>");
}
+ if (comment != null) {
+ if (comment.getTitle() != null) {
+ sb.append("<title>" + comment.getTitle() + "</title>");
+ }
+ if (comment.getCommentText() != null) {
+ sb.append("<text>" + comment.getCommentText() + "</text>");
+ }
+ if (comment.getAuthorMail() != null) {
+ sb.append("<author-email-address>" + comment.getAuthorMail() + "</author-email-address>");
+ }
+ if (comment.getAuthorName() != null) {
+ sb.append("<author-name>" + comment.getAuthorName() + "</author-name>");
+ }
+ } else {
+ sb.append("<no-comment-data-available-yet/>");
+ }
sb.append("</no-valid-comment-submitted-yet>");
return sb.toString();
}
@@ -108,23 +125,30 @@
} else {
log.warn("No title set!");
}
+
+ String name = getEnvironment().getRequest().getParameter("name");
+ if (name != null && name.trim().length() > 0) {
+ comment.setAuthorName(name);
+ } else {
+ log.info("No author name specified!");
+ }
+
String email = getEnvironment().getRequest().getParameter("email");
if (email != null && email.trim().length() > 0) {
comment.setAuthorMail(email);
+ if (email.indexOf("@") <= 0) {
+ String message = "Author email does not seem to be a valid email address!"; // TODO: i18n
+ log.warn(message);
+ sb.append(generateNoValidCommentSubmittedYetXML(path, message, comment));
+ return sb;
+ }
} else {
- String message = "No author email specified!";
+ String message = "No author email specified!"; // TODO: i18n
log.warn(message);
- sb.append(generateNoValidCommentSubmittedYetXML(path, message));
+ sb.append(generateNoValidCommentSubmittedYetXML(path, message, comment));
return sb;
}
- String name = getEnvironment().getRequest().getParameter("name");
- if (name != null && name.trim().length() > 0) {
- comment.setAuthorName(name);
- } else {
- log.info("No author name specified!");
- }
- // TODO: Validate fields (e.g. email should be mandatory)!
cMan.addComment(getRealm(), path, comment);
notifyAdministrator(path, comment);
@@ -133,7 +157,7 @@
sb.append(body);
sb.append("</comment>");
} else {
- sb.append(generateNoValidCommentSubmittedYetXML(path, null));
+ sb.append(generateNoValidCommentSubmittedYetXML(path, null, null));
}
} else {
String message = "Resource is not commentable: " + path;
More information about the Yanel-commits
mailing list