[jboss-svn-commits] JBL Code SVN: r5454 - in labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds: data/model exceptions portlet
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 3 17:30:59 EDT 2006
Author: adamw
Date: 2006-08-03 17:30:57 -0400 (Thu, 03 Aug 2006)
New Revision: 5454
Added:
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/exceptions/FeedEntryDoesNotExistException.java
Modified:
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/model/FeedEntries.java
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/portlet/FeedsViewPortlet.java
Log:
http://jira.jboss.com/jira/browse/JBSHOTOKU-38
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/model/FeedEntries.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/model/FeedEntries.java 2006-08-03 19:47:37 UTC (rev 5453)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/model/FeedEntries.java 2006-08-03 21:30:57 UTC (rev 5454)
@@ -1,5 +1,7 @@
package org.jboss.shotoku.feeds.data.model;
+import org.jboss.shotoku.feeds.exceptions.FeedEntryDoesNotExistException;
+
import java.util.Date;
import java.util.List;
@@ -47,4 +49,23 @@
public List<FeedEntry> getEntries() {
return entries;
}
+
+ public int getEntryIndex(String guid)
+ throws FeedEntryDoesNotExistException {
+ int i = 0;
+ for (FeedEntry entry : getEntries()) {
+ if (entry.getGuid().equals(guid)) {
+ return i;
+ }
+
+ i++;
+ }
+
+ throw new FeedEntryDoesNotExistException(guid);
+ }
+
+ public FeedEntry getEntry(String guid)
+ throws FeedEntryDoesNotExistException {
+ return getEntries().get(getEntryIndex(guid));
+ }
}
Added: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/exceptions/FeedEntryDoesNotExistException.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/exceptions/FeedEntryDoesNotExistException.java 2006-08-03 19:47:37 UTC (rev 5453)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/exceptions/FeedEntryDoesNotExistException.java 2006-08-03 21:30:57 UTC (rev 5454)
@@ -0,0 +1,21 @@
+package org.jboss.shotoku.feeds.exceptions;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class FeedEntryDoesNotExistException extends FeedDoesNotExistException {
+ public FeedEntryDoesNotExistException() {
+ }
+
+ public FeedEntryDoesNotExistException(String message) {
+ super(message);
+ }
+
+ public FeedEntryDoesNotExistException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public FeedEntryDoesNotExistException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/portlet/FeedsViewPortlet.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/portlet/FeedsViewPortlet.java 2006-08-03 19:47:37 UTC (rev 5453)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/portlet/FeedsViewPortlet.java 2006-08-03 21:30:57 UTC (rev 5454)
@@ -7,6 +7,7 @@
import org.jboss.shotoku.feeds.tools.FeedsConstants;
import org.jboss.shotoku.feeds.FeedsDescriptor;
import org.jboss.shotoku.feeds.exceptions.FeedDoesNotExistException;
+import org.jboss.shotoku.feeds.exceptions.FeedEntryDoesNotExistException;
import org.jboss.shotoku.feeds.comments.exceptions.UnauthorizedToCommentException;
import org.jboss.shotoku.feeds.comments.exceptions.CommentsNotAvialableException;
import org.jboss.shotoku.feeds.comments.exceptions.CommentableFeedDoesNotExistException;
@@ -48,6 +49,7 @@
private static final String COMMENTABLE = "commentable";
private static final String COMMENTABLE_BY_USER = "commentableByUser";
private static final String MESSAGES = "messages";
+ private static final String COMMENT = "comment";
/**
* Parameter where operation type is held when doing ActionRequests.
@@ -57,7 +59,7 @@
/**
* Parameter where guid of an entry is held when doing ActionRequests.
*/
- public static final String GUID_PARAM = "guid";
+ private static final String GUID_PARAM = "guid";
/**
* Operation types.
@@ -134,19 +136,6 @@
return newBegin;
}
- private int getFeedEntryIndex(List<FeedEntry> entries, String guid) {
- int i = 0;
- for (FeedEntry fe : entries) {
- if (fe.getGuid().equals(guid)) {
- return i;
- }
-
- i++;
- }
-
- return -1;
- }
-
private void clearMessages(Feed feed, PortletRequest request) {
List<String> msgs = (List<String>) getSessionAttribute(request,
feed.getGuid(), MESSAGES);
@@ -183,12 +172,14 @@
case TOP :
// We have to look up the entry and move the begin
// index.
- int index = getFeedEntryIndex(feed.getFeedEntries().
- getEntries(), guid);
- if (index == -1) {
- // Entry not found -> simply showing the first one.
+ int index;
+ try {
+ index = feed.getFeedEntries().getEntryIndex(guid);
+ } catch (FeedEntryDoesNotExistException e) {
+ // Entry not found -> simply showing the first one
index = 0;
}
+
setEntriesBegin(feed.getGuid(), request, index);
break;
@@ -250,23 +241,32 @@
ok = false;
}
- if (!ok) {
- return;
+ if (ok) {
+ try {
+ feed.addComment(guid, author, title, description,
+ request.getServerName());
+ addMessage(feed, request, "Comment added. It should appear " +
+ "soon.");
+ } catch (UnauthorizedToCommentException e) {
+ addMessage(feed, request, "You are not authorized to add " +
+ "comments.");
+ ok = false;
+ } catch (CommentsNotAvialableException e) {
+ addMessage(feed, request, "You cannot add comments to this feed.");
+ ok = false;
+ } catch (CommentableFeedDoesNotExistException e) {
+ addMessage(feed, request, "The feed or entry which you want to " +
+ "comment does not exist");
+ ok = false;
+ }
}
- try {
- feed.addComment(guid, author, title, description,
- request.getServerName());
- addMessage(feed, request, "Comment added. It should appear " +
- "soon.");
- } catch (UnauthorizedToCommentException e) {
- addMessage(feed, request, "You are not authorized to add " +
- "comments.");
- } catch (CommentsNotAvialableException e) {
- addMessage(feed, request, "You cannot add comments to this feed.");
- } catch (CommentableFeedDoesNotExistException e) {
- addMessage(feed, request, "The feed or entry which you want to " +
- "comment does not exist");
+ if (!ok) {
+ // Passing the comment data so that it can be eventually
+ // altered to be correct.
+ setSessionAttribute(request, feed.getGuid(), COMMENT,
+ new FeedEntry(author, title, description, null, null,
+ null, null));
}
}
@@ -294,6 +294,9 @@
// Clearing any previous messages.
clearMessages(feed, request);
+ // Clearing comment data.
+ setSessionAttribute(request, feed.getGuid(), COMMENT, null);
+
// Exectuing the appropriate actions.
switch (opType) {
case VIEW: processActionView(feed, request); break;
@@ -348,6 +351,10 @@
request.setAttribute(MESSAGES, getSessionAttribute(request,
feed.getGuid(), MESSAGES));
+ // Copying possible comment data.
+ request.setAttribute(COMMENT, getSessionAttribute(request,
+ feed.getGuid(), COMMENT));
+
Object showSingleObj = getSessionAttribute(request, feed.getGuid(),
SHOW_SINGLE);
boolean showSingle = ((showSingleObj != null) &&
@@ -360,13 +367,8 @@
getSessionAttribute(request, feed.getGuid(), SHOW_GUID));
// Looking up the entry to show.
- List<FeedEntry> entries = feed.getFeedEntries().getEntries();
- int index = getFeedEntryIndex(entries, guid);
- if (index == -1) {
- // If the entry is not found, simply showing the whole list.
- showSingle = false;
- } else {
- FeedEntry entry = entries.get(index);
+ try {
+ FeedEntry entry = feed.getFeedEntries().getEntry(guid);
request.setAttribute("entry", entry);
if (entry.getCommentLink() != null) {
@@ -390,6 +392,9 @@
getPortletContext().getRequestDispatcher(JSP_SINGLE).include(
request, response);
+ } catch (FeedEntryDoesNotExistException e) {
+ // If the entry is not found, simply showing the whole list.
+ showSingle = false;
}
}
More information about the jboss-svn-commits
mailing list