1 5 6 13 package org.exoplatform.services.portletcontainer.impl.portletAPIImp.tags; 14 15 import javax.servlet.jsp.tagext.BodyTagSupport ; 16 import javax.servlet.jsp.JspException ; 17 import javax.portlet.*; 18 19 import java.io.IOException ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 public abstract class XURLTag extends BodyTagSupport { 24 25 protected WindowState windowState; 26 protected PortletMode portletMode; 27 protected String var; 28 protected boolean secure; 29 private Map parameters = new HashMap (); 30 31 public void addParameter(String key, String value){ 32 parameters.put(key, new String []{value}); 33 } 34 35 public void setWindowState(String windowState) { 36 if(WindowState.MAXIMIZED.toString().equals(windowState)) 37 this.windowState = WindowState.MAXIMIZED; 38 else if (WindowState.MINIMIZED.toString().equals(windowState)) 39 this.windowState = WindowState.MINIMIZED; 40 else if (WindowState.NORMAL.toString().equals(windowState)) 41 this.windowState = WindowState.NORMAL; 42 else 43 this.windowState = new WindowState(windowState); 44 } 45 46 public void setPortletMode(String portletMode) { 47 if(PortletMode.EDIT.toString().equals(portletMode)) 48 this.portletMode = PortletMode.EDIT; 49 else if(PortletMode.HELP.toString().equals(portletMode)) 50 this.portletMode = PortletMode.HELP; 51 else if(PortletMode.VIEW.toString().equals(portletMode)) 52 this.portletMode = PortletMode.VIEW; 53 else 54 this.portletMode =new PortletMode(portletMode); 55 } 56 57 public String getVar() { 58 return var; 59 } 60 61 public void setVar(String var) { 62 this.var = var; 63 } 64 65 public void setSecure(String secure) { 66 if(secure.equals("true")) 67 this.secure = true; 68 else 69 this.secure = false; 70 } 71 72 public int doStartTag() throws JspException { 73 return EVAL_BODY_BUFFERED; 74 } 75 76 public int doEndTag() throws JspException { 77 PortletURL portletURL = getPortletURL(); 78 portletURL.setParameters(parameters); 79 try { 80 if(portletMode != null) 81 portletURL.setPortletMode(portletMode); 82 portletURL.setSecure(secure); 83 if(windowState != null) 84 portletURL.setWindowState(windowState); 85 } catch (PortletModeException e) { 86 throw new JspException (e); 87 } catch (WindowStateException e) { 88 throw new JspException (e); 89 } catch (PortletSecurityException e) { 90 throw new JspException (e); 91 } 92 93 if(var == null || "".equals(var)){ 94 try { 95 pageContext.getOut().print(portletURL.toString()); 96 } catch (IOException e1) { 97 throw new JspException (e1); 98 } 99 } else { 100 pageContext.setAttribute(var, portletURL.toString()); 101 } 102 103 return EVAL_PAGE; 104 } 105 106 public abstract PortletURL getPortletURL(); 107 } 108 | Popular Tags |