[Yanel-commits] rev 60754 - 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 14:05:16 CEST 2011
Author: michi
Date: 2011-09-16 14:05:16 +0200 (Fri, 16 Sep 2011)
New Revision: 60754
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:
simple 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 11:42:19 UTC (rev 60753)
+++ public/yanel/trunk/src/resources/comment/htdocs/add-comment.xsl 2011-09-16 12:05:16 UTC (rev 60754)
@@ -31,8 +31,8 @@
<body>
<xsl:apply-templates select="/exception"/>
- <h2>Add comment re page '<xsl:value-of select="/no-comment-yet/@path"/><xsl:value-of select="/comment/@path"/>'</h2>
- <xsl:apply-templates select="/no-comment-yet"/>
+ <h2>Add comment re page '<xsl:value-of select="/no-valid-comment-submitted-yet/@path"/><xsl:value-of select="/comment/@path"/>'</h2>
+ <xsl:apply-templates select="/no-valid-comment-submitted-yet"/>
<xsl:apply-templates select="/comment"/>
</body>
</html>
@@ -42,7 +42,12 @@
<div style="color: red;">EXCEPTION: <xsl:value-of select="."/></div>
</xsl:template>
- <xsl:template match="no-comment-yet">
+ <xsl:template match="message">
+ <div style="color: red;"><xsl:value-of select="."/></div>
+ </xsl:template>
+
+ <xsl:template match="no-valid-comment-submitted-yet">
+ <xsl:apply-templates select="message"/>
<p>Please enter your comment below:</p>
<form>
<input type="hidden" name="path" value="{@path}"/>
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 11:42:19 UTC (rev 60753)
+++ 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)
@@ -30,7 +30,65 @@
log.debug("requested viewId: " + viewId);
}
+ return new ByteArrayInputStream(generateXML().toString().getBytes());
+ }
+ /**
+ * Notify an "administrator" by email re a new comment
+ * @param path Path of commentable resource
+ * @param comment Comment which has been added to commentable resource
+ */
+ private void notifyAdministrator(String path, CommentV1 comment) throws Exception {
+ String emailTo = getResourceConfigProperty("email-to");
+ String emailFrom = getResourceConfigProperty("email-from");
+ if (emailTo != null && emailFrom != null) {
+ String from = emailFrom;
+ String name = null; // TODO: Make this configurable
+ String replyTo = from; // TODO: Make this configurable
+ String to = emailTo;
+ String subject = "New comment added"; // TODO: Make this configurable
+
+ StringBuilder content = new StringBuilder("Commented page URL: " + path);
+ content.append("\n\nE-Mail address of author of comment: " + comment.getAuthorMail());
+ if (comment.getAuthorName() != null) {
+ content.append("\n\nName of author of comment: " + comment.getAuthorName());
+ } else {
+ content.append("\n\nNo name of author available.");
+ }
+ javax.servlet.http.Cookie cookie = org.wyona.yanel.servlet.AccessLog.getYanelAnalyticsCookie(getEnvironment().getRequest());
+ String cookieValue = null;
+ if (cookie != null) {
+ content.append("\n\nYanel analytics cookie: " + cookie.getValue());
+ } else {
+ log.warn("No Yanel analytics cookie set yet!");
+ }
+ content.append("\n\nComment title: " + comment.getTitle());
+ content.append("\n\nComment text:\n" + comment.getCommentText());
+
+ org.wyona.yanel.core.util.MailUtil.send(from, name, replyTo, to, subject, content.toString());
+ } else {
+ log.warn("No email addresses (either 'to' or 'from') are configured in order to notify 'administrator' re a new comment!");
+ }
+ }
+
+ /**
+ * 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
+ */
+ private String generateNoValidCommentSubmittedYetXML(String path, String message) {
+ StringBuilder sb = new StringBuilder("<no-valid-comment-submitted-yet path=\"" + path + "\">");
+ if (message != null) {
+ sb.append("<message>" + message + "</message>");
+ }
+ sb.append("</no-valid-comment-submitted-yet>");
+ return sb.toString();
+ }
+
+ /**
+ * Generate XML and save comment if applicable
+ */
+ private StringBuilder generateXML() throws Exception {
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
String path = getEnvironment().getRequest().getParameter("path");
if (path != null) {
@@ -54,7 +112,10 @@
if (email != null && email.trim().length() > 0) {
comment.setAuthorMail(email);
} else {
- log.warn("No author email specified!");
+ String message = "No author email specified!";
+ log.warn(message);
+ sb.append(generateNoValidCommentSubmittedYetXML(path, message));
+ return sb;
}
String name = getEnvironment().getRequest().getParameter("name");
if (name != null && name.trim().length() > 0) {
@@ -72,7 +133,7 @@
sb.append(body);
sb.append("</comment>");
} else {
- sb.append("<no-valid-comment-submitted-yet path=\"" + path + "\"/>");
+ sb.append(generateNoValidCommentSubmittedYetXML(path, null));
}
} else {
String message = "Resource is not commentable: " + path;
@@ -89,45 +150,6 @@
log.error(message);
sb.append("<exception status=\"no-path\">" + message + "</exception>");
}
-
- return new ByteArrayInputStream(sb.toString().getBytes());
+ return sb;
}
-
- /**
- * Notify an "administrator" by email re a new comment
- * @param path Path of commentable resource
- * @param comment Comment which has been added to commentable resource
- */
- private void notifyAdministrator(String path, CommentV1 comment) throws Exception {
- String emailTo = getResourceConfigProperty("email-to");
- String emailFrom = getResourceConfigProperty("email-from");
- if (emailTo != null && emailFrom != null) {
- String from = emailFrom;
- String name = null; // TODO: Make this configurable
- String replyTo = from; // TODO: Make this configurable
- String to = emailTo;
- String subject = "New comment added"; // TODO: Make this configurable
-
- StringBuilder content = new StringBuilder("Commented page URL: " + path);
- content.append("\n\nE-Mail address of author of comment: " + comment.getAuthorMail());
- if (comment.getAuthorName() != null) {
- content.append("\n\nName of author of comment: " + comment.getAuthorName());
- } else {
- content.append("\n\nNo name of author available.");
- }
- javax.servlet.http.Cookie cookie = org.wyona.yanel.servlet.AccessLog.getYanelAnalyticsCookie(getEnvironment().getRequest());
- String cookieValue = null;
- if (cookie != null) {
- content.append("\n\nYanel analytics cookie: " + cookie.getValue());
- } else {
- log.warn("No Yanel analytics cookie set yet!");
- }
- content.append("\n\nComment title: " + comment.getTitle());
- content.append("\n\nComment text:\n" + comment.getCommentText());
-
- org.wyona.yanel.core.util.MailUtil.send(from, name, replyTo, to, subject, content.toString());
- } else {
- log.warn("No email addresses (either 'to' or 'from') are configured in order to notify 'administrator' re a new comment!");
- }
- }
}
More information about the Yanel-commits
mailing list