You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by zo...@apache.org on 2010/02/07 11:01:11 UTC
svn commit: r907408 - in
/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main:
java/org/apache/aries/samples/blog/web/
java/org/apache/aries/samples/blog/web/util/ resources/WEB-INF/
Author: zoe
Date: Sun Feb 7 10:01:10 2010
New Revision: 907408
URL: http://svn.apache.org/viewvc?rev=907408&view=rev
Log:
ARIES-149
Added:
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddComment.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddCommentForm.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntry.java
- copied, changed from r907065, incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPost.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntryForm.java
- copied, changed from r907065, incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPostForm.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/JNDIHelper.java
Removed:
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPost.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPostForm.java
Modified:
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewAuthor.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewBlog.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/HTMLOutput.java
incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/resources/WEB-INF/web.xml
Added: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddComment.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddComment.java?rev=907408&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddComment.java (added)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddComment.java Sun Feb 7 10:01:10 2010
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.aries.samples.blog.web;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.aries.samples.blog.api.BloggingService;
+import org.apache.aries.samples.blog.web.util.JNDIHelper;
+
+public class AddComment extends HttpServlet {
+ private static final long serialVersionUID = -920234218060948564L;
+ public static final String ERROR_MESSAGES_ID = "commentErrorMessages";
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ // email address of the comment's author
+ String email = req.getParameter("email");
+ // the id of the blog entry to which this comment is associated
+ long postId = Long.parseLong(req.getParameter("postId"));
+ // the text of the comment
+ String text = req.getParameter("text");
+
+ BloggingService service = JNDIHelper.getBloggingService();
+
+ // retrieve the blog entry and create the associated comment
+
+ if (service.getBlogAuthor(email) != null) {
+ service.createBlogComment(text, email, postId);
+ resp.sendRedirect("ViewBlog");
+ } else {
+
+ if (email.equals(""))
+ addError(req, "The email field is required.");
+ else
+ addError(req, "The email filed is not valid.");
+ resp.sendRedirect("AddCommentForm?postId=" + postId);
+ }
+ }
+
+ public static void addError(HttpServletRequest req, String error) {
+ HttpSession session = req.getSession();
+ if (session != null) {
+ @SuppressWarnings("unchecked")
+ List<String> errors = (List<String>) session
+ .getAttribute(ERROR_MESSAGES_ID);
+
+ if (errors == null) {
+ errors = new ArrayList<String>();
+ session.setAttribute(ERROR_MESSAGES_ID, errors);
+ }
+
+ errors.add(error);
+ }
+ }
+}
Added: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddCommentForm.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddCommentForm.java?rev=907408&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddCommentForm.java (added)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/AddCommentForm.java Sun Feb 7 10:01:10 2010
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.aries.samples.blog.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.aries.samples.blog.web.util.HTMLOutput;
+
+public class AddCommentForm extends HttpServlet{
+ private static final long serialVersionUID = 4989805137759774598L;
+ public static final String ERROR_MESSAGES_ID = "commentErrorMessages";
+ public static final String ID = "comment";
+
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ PrintWriter out = resp.getWriter();
+
+ String postId = checkPostId(req.getParameter("postId"));
+
+ // if we have a valid postId, display the add comment page
+ if (postId != null) {
+ HTMLOutput.writeHTMLHeaderPartOne(out, "Add Comment");
+ HTMLOutput.writeDojoUses(out, "dojo.parser", "dijit.dijit",
+ "dijit.Editor", "dijit.form.TextBox");
+
+ out.println("<script type=\"text/javascript\">");
+ out.println("function storeCommentContent() {");
+ out.println("var textBox = dijit.byId('textArea');");
+ out.println("var textArea = dojo.byId('text');");
+ out.println("textArea.value = textBox.getValue();");
+ out.println("}");
+ out.println("</script>");
+
+ HTMLOutput.writeHTMLHeaderPartTwo(out);
+
+ List<String> errors = null;
+ if (req.getSession() != null)
+ errors = (List<String>) req.getSession().getAttribute(
+ ERROR_MESSAGES_ID);
+
+ if (errors != null) {
+ out.println("\t\t\t<div id=\"errorMessages\">");
+ for (String msg : errors) {
+ out.println("\t\t\t\t<div class=\"errorMessage\">" + msg
+ + "</div>");
+ }
+
+ out.println("\t\t\t</div>");
+ req.getSession().removeAttribute("commentErrorMessages");
+ }
+
+ out
+ .println("<form name=\"createComment\" method=\"get\" action=\"AddComment\">");
+ out
+ .println("<div class=\"textEntry\"><textarea dojoType=\"dijit.Editor\" id=\"textArea\" name=\"textArea\"></textarea></div>");
+ out
+ .println("<div class=\"textEntry\"><label>Email <input dojoType=\"dijit.form.TextBox\" type=\"text\" name=\"email\" /></label></div>");
+ out
+ .println("<input type=\"hidden\" name=\"text\" id=\"text\" value=\"\"/>");
+ out.print("<input type=\"hidden\" name=\"postId\" value=\"");
+ out.print(postId);
+ out.println("\"/>");
+ out
+ .println("<input class=\"submit\" type=\"submit\" value=\"Submit\" name=\"Submit\" onclick=\"storeCommentContent()\"/>");
+ out.println("</form>");
+
+ HTMLOutput.writeHTMLFooter(out);
+
+ } else {
+ // otherwise show the blog
+ RequestDispatcher dispatch = getServletContext()
+ .getRequestDispatcher("ViewBlog");
+ dispatch.forward(req, resp);
+ }
+ }
+
+ private String checkPostId(String parameter) {
+ if (parameter != null && parameter.matches("^\\d*$"))
+ return parameter;
+ return null;
+ }
+}
Copied: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntry.java (from r907065, incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPost.java)
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntry.java?p2=incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntry.java&p1=incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPost.java&r1=907065&r2=907408&rev=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPost.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntry.java Sun Feb 7 10:01:10 2010
@@ -27,9 +27,9 @@
import org.apache.aries.samples.blog.api.BloggingService;
import org.apache.aries.samples.blog.web.util.FormServlet;
-import org.apache.aries.samples.blog.web.util.HTMLOutput;
+import org.apache.aries.samples.blog.web.util.JNDIHelper;
-public class CreateBlogPost extends HttpServlet
+public class CreateBlogEntry extends HttpServlet
{
private static final long serialVersionUID = -6484228320837122235L;
@@ -49,10 +49,10 @@
String text = req.getParameter("text");
String tags = req.getParameter("tags");
- BloggingService service = HTMLOutput.getBloggingService();
+ BloggingService service = JNDIHelper.getBloggingService();
if (service.getBlogAuthor(email) != null) {
- service.getBlog().createPost(email, title, text, tags);
+ service.createBlogEntry(email, title, text, tags);
resp.sendRedirect("ViewBlog");
} else {
storeParam(req, "email", email);
@@ -65,12 +65,12 @@
else
FormServlet.addError(req, "The author's email is not valid.");
- resp.sendRedirect("CreateBlogPostForm");
+ resp.sendRedirect("CreateBlogEntryForm");
}
}
private void storeParam(HttpServletRequest req, String param, String value)
{
- FormServlet.storeParam(req, CreateBlogPostForm.ID, param, value);
+ FormServlet.storeParam(req, CreateBlogEntryForm.ID, param, value);
}
}
\ No newline at end of file
Copied: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntryForm.java (from r907065, incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPostForm.java)
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntryForm.java?p2=incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntryForm.java&p1=incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPostForm.java&r1=907065&r2=907408&rev=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogPostForm.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/CreateBlogEntryForm.java Sun Feb 7 10:01:10 2010
@@ -26,12 +26,12 @@
import org.apache.aries.samples.blog.web.util.HTMLOutput;
-public class CreateBlogPostForm extends FormServlet
+public class CreateBlogEntryForm extends FormServlet
{
private static final long serialVersionUID = -6484228320837122235L;
public static final String ID = "post";
- public CreateBlogPostForm()
+ public CreateBlogEntryForm()
{
super(ID);
}
@@ -50,7 +50,7 @@
String text = retrieveOrEmpty(req, "text");
String tags = retrieveOrEmpty(req, "tags");
- out.println("<form name=\"createPost\" method=\"post\" action=\"CreateBlogPost\">");
+ out.println("<form name=\"createPost\" method=\"post\" action=\"CreateBlogEntry\">");
out.println("<div class=\"textEntry\"><label>Title <input dojoType=\"dijit.form.TextBox\" type=\"text\" name=\"title\" value=\"" + title + "\"/></label></div>");
out.println("<div class=\"textEntry\"><textarea dojoType=\"dijit.Editor\" id=\"text\" name=\"text\">" + text + "</textarea></div>");
Modified: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java?rev=907408&r1=907407&r2=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java Sun Feb 7 10:01:10 2010
@@ -28,7 +28,7 @@
import org.apache.aries.samples.blog.api.BloggingService;
import org.apache.aries.samples.blog.web.util.FormServlet;
-import org.apache.aries.samples.blog.web.util.HTMLOutput;
+import org.apache.aries.samples.blog.web.util.JNDIHelper;
public class EditAuthor extends HttpServlet
{
@@ -67,14 +67,14 @@
FormServlet.addError(req, "The email field is required.");
resp.sendRedirect("EditAuthorForm");
} else {
- BloggingService service = HTMLOutput.getBloggingService();
+ BloggingService service = JNDIHelper.getBloggingService();
if (service.getBlogAuthor(email) != null) {
// do an update
- service.updateAuthor(email, nickName, name, bio, dob);
+ service.updateBlogAuthor(email, nickName, name, bio, dob);
} else {
// do a create
- service.createAuthor(email, nickName, name, bio, dob);
+ service.createBlogAuthor(email, nickName, name, bio, dob);
}
RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/ViewAuthor");
dispatch.forward(req, resp);
Modified: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java?rev=907408&r1=907407&r2=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java Sun Feb 7 10:01:10 2010
@@ -27,6 +27,7 @@
import org.apache.aries.samples.blog.api.BloggingService;
import org.apache.aries.samples.blog.web.util.FormServlet;
import org.apache.aries.samples.blog.web.util.HTMLOutput;
+import org.apache.aries.samples.blog.web.util.JNDIHelper;
public class EditAuthorForm extends FormServlet
@@ -50,7 +51,7 @@
{
String pageTitle = "Create Author";
- BloggingService service = HTMLOutput.getBloggingService();
+ BloggingService service = JNDIHelper.getBloggingService();
String email = getEmail(req);
if (email != null && !!!"".equals(email)) {
@@ -81,7 +82,7 @@
String dob = retrieveOrEmpty(req, "dob");
String email = getEmail(req);
- BloggingService service = HTMLOutput.getBloggingService();
+ BloggingService service = JNDIHelper.getBloggingService();
if (email != null && !!!"".equals(email)) {
BlogAuthor author = service.getBlogAuthor(email);
Modified: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewAuthor.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewAuthor.java?rev=907408&r1=907407&r2=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewAuthor.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewAuthor.java Sun Feb 7 10:01:10 2010
@@ -29,6 +29,7 @@
import org.apache.aries.samples.blog.api.BlogAuthor;
import org.apache.aries.samples.blog.api.BloggingService;
import org.apache.aries.samples.blog.web.util.HTMLOutput;
+import org.apache.aries.samples.blog.web.util.JNDIHelper;
@@ -47,7 +48,7 @@
} else {
PrintWriter out = resp.getWriter();
- BloggingService service = HTMLOutput.getBloggingService();
+ BloggingService service = JNDIHelper.getBloggingService();
BlogAuthor author = service.getBlogAuthor(email);
Modified: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewBlog.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewBlog.java?rev=907408&r1=907407&r2=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewBlog.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/ViewBlog.java Sun Feb 7 10:01:10 2010
@@ -24,16 +24,18 @@
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.aries.samples.blog.api.Blog;
-import org.apache.aries.samples.blog.api.BlogPost;
+import org.apache.aries.samples.blog.api.BlogComment;
+import org.apache.aries.samples.blog.api.BlogEntry;
import org.apache.aries.samples.blog.api.BloggingService;
import org.apache.aries.samples.blog.web.util.HTMLOutput;
+import org.apache.aries.samples.blog.web.util.JNDIHelper;
@@ -48,20 +50,20 @@
{
PrintWriter out = resp.getWriter();
- BloggingService service = HTMLOutput.getBloggingService();
+ BloggingService service = JNDIHelper.getBloggingService();
- Blog blog = service.getBlog();
+ String blogTitle = service.getBlogTitle();
// TODO cope with the service being null, redirect elsewhere.
- HTMLOutput.writeHTMLHeaderPartOne(out, blog.getBlogTitle());
+ HTMLOutput.writeHTMLHeaderPartOne(out, blogTitle);
HTMLOutput.writeDojoUses(out, "dojo.parser");
HTMLOutput.writeHTMLHeaderPartTwo(out);
- int maxPage = (blog.getNoOfPosts()-1) / POSTS_PER_PAGE;
+ int maxPage = (service.getNoOfEntries()-1) / POSTS_PER_PAGE;
int pageNoInt = 0;
String pageNo = req.getParameter("page");
@@ -79,14 +81,14 @@
}
}
- Iterator<BlogPost> posts = blog.getPosts(pageNoInt * POSTS_PER_PAGE, POSTS_PER_PAGE).iterator();
+ Iterator<? extends BlogEntry> posts = service.getBlogEntries(pageNoInt * POSTS_PER_PAGE, POSTS_PER_PAGE).iterator();
- out.println("<div class=\"links\"><a href=\"CreateBlogPostForm\">Create New Post</a> <a href=\"EditAuthorForm\">Create Author</a></div>");
+ out.println("<div class=\"links\"><a href=\"CreateBlogEntryForm\">Create New Post</a> <a href=\"EditAuthorForm\">Create Author</a></div>");
Date currentDate = null;
for (int i = 0; posts.hasNext(); i++) {
- BlogPost post = posts.next();
+ BlogEntry post = posts.next();
if (doesNotMatch(post.getPublishDate(), currentDate)) {
currentDate = post.getPublishDate();
@@ -112,9 +114,53 @@
out.print("\t\t\t<div class=\"postAuthor\"><a href=\"ViewAuthor?email=");
out.print(post.getAuthorEmail());
out.print("\">");
- out.print(post.getAuthor());
+ out.print(post.getAuthor().getFullName());
out.println("</a></div>");
+ if (service.isCommentingAvailable()) {
+
+ out.print("<div class=\"links\"><a href=\"AddCommentForm?postId=");
+ out.print(post.getId());
+ out.print("\">Add Comment</a></div>");
+
+ List<? extends BlogComment> comments = service
+ .getCommentsForEntry(post);
+ int size = comments.size();
+ out.print("<div class=\"commentTitle\"");
+ if (size > 0) {
+ out.print("onclick=\"expand(");
+ out.print(post.getId());
+ out.print(")\"");
+ }
+ out.print(" style=\"cursor: pointer;\">Comments (");
+ out.print(size);
+ out.println(")</div>");
+
+ if (size > 0) {
+
+ out.print("<div id=\"comments");
+ out.print(post.getId());
+ out.println("\">");
+
+ for (BlogComment comment : comments) {
+ out.println("<div class=\"comment\">");
+
+ out.println(comment.getComment());
+
+ out.println("</div>");
+ out
+ .print("\t\t\t<div class=\"commentAuthor\"><a href=\"ViewAuthor?email=");
+ out.print(comment.getAuthor().getEmailAddress());
+ out.print("\">");
+ out.print(
+ comment.getAuthor().getName());
+ out.println("</a></div>");
+ }
+
+ out.println("</div>");
+ }
+ }
+
out.println("\t\t</div>");
}
Modified: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/HTMLOutput.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/HTMLOutput.java?rev=907408&r1=907407&r2=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/HTMLOutput.java (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/HTMLOutput.java Sun Feb 7 10:01:10 2010
@@ -18,16 +18,10 @@
*/
package org.apache.aries.samples.blog.web.util;
-import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.aries.samples.blog.api.BloggingService;
-
/**
* Utility class to provide html headers, footers, dojo use and blogging
* service.
@@ -206,17 +200,4 @@
}
- public static final BloggingService getBloggingService() throws IOException {
- try {
- InitialContext ic = new InitialContext();
- return (BloggingService) ic.lookup("aries:services/"
- + BloggingService.class.getName());
- } catch (NamingException e) {
- e.printStackTrace();
- IOException ioe = new IOException(
- "Blogging service resolution failed");
- ioe.initCause(e);
- throw ioe;
- }
- }
}
\ No newline at end of file
Added: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/JNDIHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/JNDIHelper.java?rev=907408&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/JNDIHelper.java (added)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/java/org/apache/aries/samples/blog/web/util/JNDIHelper.java Sun Feb 7 10:01:10 2010
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.aries.samples.blog.web.util;
+
+import java.io.IOException;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.aries.samples.blog.api.BloggingService;
+
+public class JNDIHelper {
+ public static final BloggingService getBloggingService() throws IOException {
+ try {
+ InitialContext ic = new InitialContext();
+
+ return (BloggingService) ic.lookup("aries:services/"
+ + BloggingService.class.getName());
+ } catch (NamingException e) {
+ e.printStackTrace();
+ IOException ioe = new IOException(
+ "Blogging service resolution failed");
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+}
Modified: incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/resources/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/resources/WEB-INF/web.xml?rev=907408&r1=907407&r2=907408&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/resources/WEB-INF/web.xml (original)
+++ incubator/aries/trunk/samples/blog-sample/blog-servlet/src/main/resources/WEB-INF/web.xml Sun Feb 7 10:01:10 2010
@@ -16,8 +16,7 @@
limitations under the License.
-->
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
-
- <web-app id="Blog">
+ <web-app id="Blog">
<display-name>Blog Application</display-name>
<description>This is the Blog Sample Application.</description>
<servlet id="Servlet_1">
@@ -25,37 +24,57 @@
<display-name>View Blog Author</display-name>
<description>This Servlet loads and displays the details of a blog author.</description>
<servlet-class>org.apache.aries.samples.blog.web.ViewAuthor</servlet-class>
+ <load-on-startup></load-on-startup>
</servlet>
<servlet id="Servlet_2">
<servlet-name>Edit Blog Author</servlet-name>
<display-name>Edit Blog Author</display-name>
<description>This Servlet edits or creates the details of a blog author.</description>
<servlet-class>org.apache.aries.samples.blog.web.EditAuthor</servlet-class>
+ <load-on-startup></load-on-startup>
</servlet>
<servlet id="Servlet_3">
<servlet-name>Edit Blog Author Form</servlet-name>
<display-name>Edit Blog Author Form</display-name>
<description>This Servlet that displays the form for creating or updating the details of a blog author.</description>
<servlet-class>org.apache.aries.samples.blog.web.EditAuthorForm</servlet-class>
+ <load-on-startup></load-on-startup>
+ </servlet>
+ <servlet id="Servlet_4">
+ <servlet-name>Add Comment Form Servlet</servlet-name>
+ <display-name>Add Comment Form Servlet</display-name>
+ <description>This Servlet shows a form for adding comments.</description>
+ <servlet-class>org.apache.aries.samples.blog.web.AddCommentForm</servlet-class>
+ <load-on-startup></load-on-startup>
</servlet>
<servlet id="Servlet_5">
- <servlet-name>Create Blog Post</servlet-name>
- <display-name>Create Blog Post</display-name>
- <description>This Servlet that creates a blog post.</description>
- <servlet-class>org.apache.aries.samples.blog.web.CreateBlogPost</servlet-class>
+ <servlet-name>Create Blog Entry</servlet-name>
+ <display-name>Create Blog Entry</display-name>
+ <description>This Servlet that creates a blog entry.</description>
+ <servlet-class>org.apache.aries.samples.blog.web.CreateBlogEntry</servlet-class>
+ <load-on-startup></load-on-startup>
</servlet>
<servlet id="Servlet_6">
<servlet-name>View Blog</servlet-name>
<display-name>View Blog</display-name>
<description>This Servlet that views the blog posts.</description>
<servlet-class>org.apache.aries.samples.blog.web.ViewBlog</servlet-class>
- </servlet>
+ <load-on-startup></load-on-startup>
+ </servlet>
+ <servlet id="Servlet_7">
+ <servlet-name>Add Comment Servlet</servlet-name>
+ <display-name>Add Comment Servlet</display-name>
+ <description>This Servlet adds a comments.</description>
+ <servlet-class>org.apache.aries.samples.blog.web.AddComment</servlet-class>
+ <load-on-startup></load-on-startup>
+ </servlet>
<servlet id="Servlet_8">
- <servlet-name>Create Blog Post Form</servlet-name>
- <display-name>Create Blog Post Form</display-name>
+ <servlet-name>Create Blog Entry Form</servlet-name>
+ <display-name>Create Blog Entry Form</display-name>
<description>This Servlet that displays the form for creating a blog post.</description>
- <servlet-class>org.apache.aries.samples.blog.web.CreateBlogPostForm</servlet-class>
- </servlet>
+ <servlet-class>org.apache.aries.samples.blog.web.CreateBlogEntryForm</servlet-class>
+ <load-on-startup></load-on-startup>
+ </servlet>
<servlet-mapping id="ServletMapping_1">
<servlet-name>View Blog Author</servlet-name>
<url-pattern>/ViewAuthor</url-pattern>
@@ -68,21 +87,28 @@
<servlet-name>Edit Blog Author Form</servlet-name>
<url-pattern>/EditAuthorForm</url-pattern>
</servlet-mapping>
+ <servlet-mapping id="ServletMapping_4">
+ <servlet-name>Add Comment Form Servlet</servlet-name>
+ <url-pattern>/AddCommentForm</url-pattern>
+ </servlet-mapping>
<servlet-mapping id="ServletMapping_5">
- <servlet-name>Create Blog Post</servlet-name>
- <url-pattern>/CreateBlogPost</url-pattern>
+ <servlet-name>Create Blog Entry</servlet-name>
+ <url-pattern>/CreateBlogEntry</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping id="ServletMapping_7">
+ <servlet-name>Add Comment Servlet</servlet-name>
+ <url-pattern>/AddComment</url-pattern>
</servlet-mapping>
<servlet-mapping id="ServletMapping_6">
<servlet-name>View Blog</servlet-name>
<url-pattern>/ViewBlog</url-pattern>
</servlet-mapping>
<servlet-mapping id="ServletMapping_8">
- <servlet-name>Create Blog Post Form</servlet-name>
- <url-pattern>/CreateBlogPostForm</url-pattern>
+ <servlet-name>Create Blog Entry Form</servlet-name>
+ <url-pattern>/CreateBlogEntryForm</url-pattern>
</servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
</web-app>
-