1 10 package org.mmbase.applications.community.taglib; 11 12 import javax.servlet.jsp.JspTagException ; 13 import javax.servlet.jsp.tagext.BodyTag ; 14 15 import java.util.Hashtable ; 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 29 30 public class UpdateTag extends AbstractNodeProviderTag implements BodyTag { 31 32 private Module community=null; 33 private String message; 34 35 public void setMessage(String m) throws JspTagException { 36 message=getAttributeValue(m); 37 } 38 39 public int doStartTag() throws JspTagException { 40 if (message == null) { 42 throw new JspTagException ("Field 'message' not specified"); 43 } 44 community=getCloudContext().getModule("communityprc"); 45 Node node = getCloudVar().getNodeManager("message").createNode(); 47 setNodeVar(node); 48 return EVAL_BODY_BUFFERED; 49 } 50 51 public void doInitBody() throws JspTagException { 52 } 53 54 57 public int doAfterBody() throws JspTagException { 58 Node node=getNodeVar(); 59 String subject=node.getStringValue("subject").trim(); 60 String body=node.getStringValue("body").trim(); 61 String user=node.getStringValue("user"); 62 String username=node.getStringValue("username"); 63 node.cancel(); 64 65 if (body.length()==0) { 66 throw new JspTagException ("Field 'body' not specified"); 67 } 68 Hashtable params=new Hashtable (); 69 try { 70 Cloud cloud=getCloudVar(); 71 params.put("CLOUD",cloud); 72 } catch (JspTagException 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 err=params.get("MESSAGE-ERROR"); 80 if (err!=null) { 81 throw new JspTagException ("Post failed : "+err); 82 } 83 if (bodyContent != null) { 84 try { 85 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 86 } catch (java.io.IOException ioe){ 87 throw new JspTagException (ioe.toString()); 88 } 89 } 90 return SKIP_BODY; 91 } 92 } 93 | Popular Tags |