1 package org.jahia.taglibs.url; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletRequest ; 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.JspWriter ; 8 import javax.servlet.jsp.tagext.TagSupport ; 9 10 import org.jahia.data.JahiaData; 11 12 21 22 public abstract class AbstractURLTag extends TagSupport { 23 24 private static org.apache.log4j.Logger logger = 25 org.apache.log4j.Logger.getLogger(AbstractURLTag.class); 26 27 private String name = null; 28 private boolean display = true; 29 private boolean withJSPopup = true; 30 private JahiaData jData = null; 31 32 public String getName() { 33 return name; 34 } 35 public void setName(String name) { 36 this.name = name; 37 } 38 public boolean isDisplay() { 39 return display; 40 } 41 public void setDisplay(boolean display) { 42 this.display = display; 43 } 44 public boolean isWithJSPopup() { 45 return withJSPopup; 46 } 47 public void setWithJSPopup(boolean withJSPopup) { 48 this.withJSPopup = withJSPopup; 49 } 50 51 protected JahiaData getJahiaData() { 52 return jData; 53 } 54 55 61 protected abstract void init(); 62 63 72 protected abstract Object getIdObject(); 73 74 protected abstract String getURL(); 75 76 protected abstract String getJSPopupURL(); 77 78 public int doStartTag() { 79 80 ServletRequest request = pageContext.getRequest(); 81 82 jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 83 84 init(); 85 86 if (getId() != null) { 87 pageContext.removeAttribute(id); 89 90 if (getIdObject() != null) { 91 pageContext.setAttribute(id, getIdObject()); 92 } 93 } 94 95 if (isDisplay()) { 96 try { 97 String url = isWithJSPopup() ? getJSPopupURL() : getURL(); 98 if (url != null) { 99 JspWriter out = pageContext.getOut(); 100 out.print(url); 101 } 102 } catch (IOException ioe) { 103 logger.error("AddContainerURLTag: doStartTag ", ioe); 104 } 105 } 106 return SKIP_BODY; 107 } 108 109 110 public int doEndTag () 111 throws JspException { 112 super.doEndTag(); 113 display = true; 114 name = null; 115 withJSPopup = true; 116 jData = null; 117 return EVAL_PAGE; 118 } 119 120 } 121 | Popular Tags |