KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > interceptors > IndexInterceptor


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under GPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portlet.forums.interceptors;
12
13 import org.jboss.portal.common.command.Command;
14 import org.jboss.portal.common.command.CommandException;
15 import org.jboss.portal.common.command.filter.AbstractCommandFilter;
16 import org.jboss.portal.common.command.result.Result;
17
18 /**
19  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
20  * @version $Revision: 1.4 $
21  */

22 public class IndexInterceptor
23    extends AbstractCommandFilter // implements IndexConstants
24
{
25    /*
26       private Index index;
27       public void setIndex(Index index)
28       {
29          this.index = index;
30       }
31       public Index getIndex()
32       {
33          return index;
34       }
35     */

36    public Result filter(Command cmd)
37    throws CommandException
38    {
39       /* Result result = getNext().filter(cmd);
40          if (index != null)
41          {
42             if (result == CommandConstants.TYPE_NEW_TOPIC_POSTED)
43             {
44                index.addDocument(createPostDocument(((NewTopicCommand)cmd).post));
45             }
46             else if (result == CommandConstants.TYPE_EDIT_POST_POSTED)
47             {
48                PostEJBLocal post = ((EditPostCommand)cmd).post;
49                Document postDoc = createPostDocument(post);
50                index.removeDocument(new Term("ID", post.getId().toString()));
51                index.addDocument(postDoc);
52             }
53             else if (result == CommandConstants.TYPE_REPLY_POSTED)
54             {
55                index.addDocument(createPostDocument(((ReplyCommand)cmd).newPost));
56             }
57             else if (result == CommandConstants.TYPE_POST_DELETED)
58             {
59                index.removeDocument(new Term("ID", ((SimpleResult)result).get("POST_ID").toString()));
60             }
61          }
62          return result;
63          }
64          private Document createPostDocument(PostEJBLocal post)
65          {
66             Message message = post.getMessage();
67             Document doc = new Document();
68             doc.add(new Field(IDX_MODULE, "bb", true, true, false));
69             doc.add(new Field(IDX_ID, "" + post.getId(), true, true, false));
70             doc.add(new Field("TOPIC_ID", "" + post.getTopic().getId(), true, true, false));
71             doc.add(new Field("FORUM_ID", "" + post.getForum().getId(), true, true, false));
72             doc.add(new Field("CATEGORY_ID", "" + post.getForum().getCategory().getId(), true, true, false));
73             doc.add(new Field(IDX_TITLE, "" + message.getSubject(), true, true, true));
74             doc.add(new Field(IDX_AUTHOR, "" + post.getPoster().getAuthor(false), true, true, false));
75             doc.add(new Field(IDX_TEXT, "" + message.getText(), false, true, true));
76             doc.add(new Field(IDX_CREATIONDATE, "" + DateField.dateToString(post.getPostDate()), true, true, false));
77             doc.add(new Field(IDX_URL, "/index.html?module=bb&op=viewtopic&t=" + post.getId(), true, false, false));
78             return doc;
79        */

80       return null;
81    }
82 }
Popular Tags