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 PostTag extends AbstractNodeProviderTag implements BodyTag { 31 32 private Module community=null; 33 private String jspvar=null; 34 35 public void setJspvar(String v) { 36 jspvar = v; 37 } 38 39 public int doStartTag() throws JspTagException { 40 community=getCloudContext().getModule("communityprc"); 41 Node node = getCloudVar().getNodeManager("message").createNode(); 43 setNodeVar(node); 44 return EVAL_BODY_BUFFERED; 45 } 46 47 50 public void doInitBody() throws JspTagException { 51 } 52 53 57 public int doAfterBody() throws JspTagException { 58 Node node=getNodeVar(); 59 String subject=(String )node.getValue("subject"); 61 String body=node.getStringValue("body").trim(); 62 String thread=node.getStringValue("thread"); 63 String user=node.getStringValue("user"); 65 String channel=node.getStringValue("channel"); 66 String username=(String )node.getValue("username"); 67 node.cancel(); 68 69 if (body.length()==0) { 70 throw new JspTagException ("Field 'body' not specified"); 71 } 72 if (channel.length()==0) { 73 throw new JspTagException ("Field 'channel' not specified"); 74 } 75 if (thread.length()==0) { thread=channel; 77 } 78 Hashtable params=new Hashtable (); 79 try { 80 Cloud cloud=getCloudVar(); 81 params.put("CLOUD",cloud); 82 } catch (JspTagException 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 resultvalue = params.get("MESSAGE-NUMBER"); 91 Object err = params.get("MESSAGE-ERROR"); 92 if (err != null) { 93 throw new JspTagException ("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 ioe){ 102 throw new JspTagException (ioe.toString()); 103 } 104 } 105 return SKIP_BODY; 106 } 107 108 } 109 | Popular Tags |