KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > community > taglib > PostTag


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.applications.community.taglib;
11
12 import javax.servlet.jsp.JspTagException JavaDoc;
13 import javax.servlet.jsp.tagext.BodyTag JavaDoc;
14
15 import java.util.Hashtable JavaDoc;
16
17 import org.mmbase.bridge.Cloud;
18 import org.mmbase.bridge.Module;
19 import org.mmbase.bridge.Node;
20
21 import org.mmbase.bridge.jsp.taglib.*;
22
23 /**
24  * This tag posts a message. The body of the tag is the message text.
25  *
26  * @author Pierre van Rooden
27  * @version $Id: PostTag.java,v 1.13 2005/01/30 16:46:35 nico Exp $
28  */

29  
30 public class PostTag extends AbstractNodeProviderTag implements BodyTag JavaDoc {
31
32     private Module community=null;
33     private String JavaDoc jspvar=null;
34
35     public void setJspvar(String JavaDoc v) {
36         jspvar = v;
37     }
38
39     public int doStartTag() throws JspTagException JavaDoc{
40         community=getCloudContext().getModule("communityprc");
41         // create a temporary message node that holds the new data
42
Node node = getCloudVar().getNodeManager("message").createNode();
43         setNodeVar(node);
44         return EVAL_BODY_BUFFERED;
45     }
46
47     /**
48      * @see javax.servlet.jsp.tagext.BodyTag#doInitBody()
49      */

50     public void doInitBody() throws JspTagException JavaDoc {
51     }
52
53     /**
54      * store the given value
55      * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
56      **/

57     public int doAfterBody() throws JspTagException JavaDoc {
58         Node node=getNodeVar();
59         // node fields
60
String JavaDoc subject=(String JavaDoc)node.getValue("subject");
61         String JavaDoc body=node.getStringValue("body").trim();
62         String JavaDoc thread=node.getStringValue("thread");
63         // node temporary fields
64
String JavaDoc user=node.getStringValue("user");
65         String JavaDoc channel=node.getStringValue("channel");
66         String JavaDoc username=(String JavaDoc)node.getValue("username");
67         node.cancel();
68
69         if (body.length()==0) {
70             throw new JspTagException JavaDoc("Field 'body' not specified");
71         }
72         if (channel.length()==0) {
73             throw new JspTagException JavaDoc("Field 'channel' not specified");
74         }
75         if (thread.length()==0) { // thread not null
76
thread=channel;
77         }
78         Hashtable JavaDoc params=new Hashtable JavaDoc();
79         try {
80             Cloud cloud=getCloudVar();
81             params.put("CLOUD",cloud);
82         } catch (JspTagException JavaDoc e) {}
83         params.put("MESSAGE-BODY",body);
84         params.put("MESSAGE-CHANNEL",channel);
85         if (user.length()!=0) params.put("MESSAGE-CHATTER",user);
86         if (username!=null) params.put("MESSAGE-CHATTERNAME",username.trim());
87         if (subject!=null) params.put("MESSAGE-SUBJECT",subject.trim());
88         community.process("MESSAGE-POST",thread,params,
89                           pageContext.getRequest(),pageContext.getResponse());
90         Object JavaDoc resultvalue = params.get("MESSAGE-NUMBER");
91         Object JavaDoc err = params.get("MESSAGE-ERROR");
92         if (err != null) {
93             throw new JspTagException JavaDoc("Post failed : "+err);
94         }
95         if (jspvar!=null) {
96             pageContext.setAttribute(jspvar, ""+resultvalue);
97         }
98         if (bodyContent != null) {
99             try {
100                 bodyContent.writeOut(bodyContent.getEnclosingWriter());
101             } catch (java.io.IOException JavaDoc ioe){
102                 throw new JspTagException JavaDoc(ioe.toString());
103             }
104         }
105         return SKIP_BODY;
106     }
107
108 }
109
Popular Tags