1 16 package org.apache.pluto.portlet.admin.taglib; 17 18 import java.io.IOException ; 19 import java.io.PrintWriter ; 20 21 import javax.portlet.PortletRequest; 22 import javax.portlet.PortletSession; 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.JspTagException ; 25 import javax.servlet.jsp.JspWriter ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 import org.apache.pluto.Constants; 29 import org.apache.pluto.portlet.admin.PlutoAdminConstants; 30 import org.apache.pluto.portlet.admin.bean.PortletMessage; 31 import org.apache.pluto.portlet.admin.bean.PortletMessageType; 32 33 69 public class MessageTag extends TagSupport { 70 71 private String message = null; 72 private String messageType = "status"; 73 74 private String cssClass = "portlet-msg-info"; 75 76 77 78 public static final String MSG_ERROR_CSS_CLASS = "portlet-msg-error"; 79 80 public static final String MSG_INFO_CSS_CLASS = "portlet-msg-info"; 81 82 public static final String MSG_STATUS_CSS_CLASS = "portlet-msg-status"; 83 84 public static final String MSG_ALERT_CSS_CLASS = "portlet-msg-alert"; 85 86 public static final String MSG_SUCCESS_CSS_CLASS = "portlet-msg-success"; 87 88 89 92 public int doStartTag() throws JspException { 93 94 PortletRequest request = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST); 95 PortletSession session = request.getPortletSession(); 96 Throwable error = (Throwable )session.getAttribute(PlutoAdminConstants.ERROR_ATTR); 97 session.removeAttribute(PlutoAdminConstants.ERROR_ATTR); 98 PortletMessage oMsg = (PortletMessage)session.getAttribute(PlutoAdminConstants.MESSAGE_ATTR); 99 session.removeAttribute(PlutoAdminConstants.MESSAGE_ATTR); 100 101 try { 102 JspWriter out = pageContext.getOut(); 103 if (message != null ) { 104 if (cssClass == null) { 105 cssClass = PortletMessageType.getTypeByName(messageType).CssClass; 106 } 107 out.print(wrapHtml(message, cssClass)); 108 } else if (oMsg != null ) { 109 out.print(wrapHtml(oMsg.getMessage(), oMsg.getType().CssClass)); 110 } else if (error != null ) { 111 StringBuffer sb = new StringBuffer (); 112 sb.append(error.getMessage()); 113 if (error.getCause() != null) { 114 sb.append("<br>Underlying Exception cause: "); 115 sb.append(error.getCause().getMessage()); 116 } 117 out.print(wrapHtml(sb.toString(), MSG_ERROR_CSS_CLASS)); 118 out.println("<!-- " + PlutoAdminConstants.LS); 120 PrintWriter writer = new PrintWriter (out, true); 121 error.printStackTrace(writer); 122 out.print(PlutoAdminConstants.LS + "-->"); 123 } 124 } catch (IOException e) { 125 throw new JspTagException ("Error in tag MessageTag: " + e.toString()); 126 } 127 return SKIP_BODY; 128 } 129 130 private String wrapHtml(String msg, String css){ 131 StringBuffer sb = new StringBuffer (); 132 sb.append("<p class=\"" + css + "\">"); 133 sb.append(msg); 134 sb.append("</p>"); 135 return sb.toString(); 136 } 137 138 141 public void setMessage(String message) { 142 this.message = message; 143 } 144 145 148 public void setCssClass(String cssClass) { 149 this.cssClass = cssClass; 150 } 151 154 public void setMessageType(String messageType) { 155 this.messageType = messageType; 156 } 157 } 158 | Popular Tags |