KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Posts a message
25  *
26  * @author Pierre van Rooden
27  * @version $Id: UpdateTag.java,v 1.11 2005/01/30 16:46:35 nico Exp $
28  */

29  
30 public class UpdateTag extends AbstractNodeProviderTag implements BodyTag JavaDoc {
31
32     private Module community=null;
33     private String JavaDoc message;
34
35     public void setMessage(String JavaDoc m) throws JspTagException JavaDoc {
36         message=getAttributeValue(m);
37     }
38
39     public int doStartTag() throws JspTagException JavaDoc{
40         // firstly, search the node:
41
if (message == null) {
42             throw new JspTagException JavaDoc("Field 'message' not specified");
43         }
44         community=getCloudContext().getModule("communityprc");
45         // create a temporary message node that holds the new data
46
Node node = getCloudVar().getNodeManager("message").createNode();
47         setNodeVar(node);
48         return EVAL_BODY_BUFFERED;
49     }
50
51     public void doInitBody() throws JspTagException JavaDoc {
52     }
53
54     /**
55      * store the given value
56      **/

57     public int doAfterBody() throws JspTagException JavaDoc {
58         Node node=getNodeVar();
59         String JavaDoc subject=node.getStringValue("subject").trim();
60         String JavaDoc body=node.getStringValue("body").trim();
61         String JavaDoc user=node.getStringValue("user");
62         String JavaDoc username=node.getStringValue("username");
63         node.cancel();
64
65         if (body.length()==0) {
66             throw new JspTagException JavaDoc("Field 'body' not specified");
67         }
68         Hashtable JavaDoc params=new Hashtable JavaDoc();
69         try {
70             Cloud cloud=getCloudVar();
71             params.put("CLOUD",cloud);
72         } catch (JspTagException JavaDoc e) {}
73         params.put("MESSAGE-BODY",body);
74         if (user.length()!=0) params.put("MESSAGE-CHATTER",user);
75         if (username.length()!=0) params.put("MESSAGE-CHATTERNAME",username);
76         if (subject.length()!=0) params.put("MESSAGE-SUBJECT",subject);
77         community.process("MESSAGE-UPDATE",message,params,
78                           pageContext.getRequest(),pageContext.getResponse());
79         Object JavaDoc err=params.get("MESSAGE-ERROR");
80         if (err!=null) {
81             throw new JspTagException JavaDoc("Post failed : "+err);
82         }
83         if (bodyContent != null) {
84             try {
85                 bodyContent.writeOut(bodyContent.getEnclosingWriter());
86             } catch (java.io.IOException JavaDoc ioe){
87                 throw new JspTagException JavaDoc(ioe.toString());
88             }
89         }
90         return SKIP_BODY;
91     }
92 }
93
Popular Tags