1 10 package org.mmbase.bridge.jsp.taglib.pageflow; 11 12 import org.mmbase.bridge.jsp.taglib.util.Attribute; 13 import org.mmbase.bridge.jsp.taglib.*; 14 import java.net.*; 15 import java.io.*; 16 import javax.servlet.jsp.JspTagException ; 17 import javax.servlet.jsp.tagext.BodyContent ; 18 import javax.servlet.http.*; 19 import javax.servlet.*; 20 21 import java.util.*; 22 23 import org.mmbase.util.*; 24 import org.mmbase.util.logging.Logger; 25 import org.mmbase.util.logging.Logging; 26 27 33 34 public class HasPageTag extends ContextReferrerTag implements Condition { 35 36 private static final Logger log = Logging.getLoggerInstance(HasPageTag.class); 37 38 protected Attribute page = Attribute.NULL; 39 public void setPage(String p) throws JspTagException { 40 page = getAttribute(p); 41 } 42 protected Attribute inverse = Attribute.NULL; 43 44 public void setInverse(String b) throws JspTagException { 45 inverse = getAttribute(b); 46 } 47 protected boolean getInverse() throws JspTagException { 48 return inverse.getBoolean(this, false); 49 } 50 51 52 53 public int doStartTag() throws JspTagException { 54 if (page == Attribute.NULL) { 55 throw new JspTagException ("Attribute 'page' was not specified"); 56 } 57 String resource = page.getString(this); 58 if (! resource.startsWith("/")) { 59 HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); 60 String includingServlet = (String ) request.getAttribute(IncludeTag.INCLUDE_PATH_KEY); 63 if (includingServlet == null) { 64 includingServlet = request.getServletPath(); 65 } 66 try { 67 log.debug("URL was relative"); 68 URL u = new URL("http", "localhost", includingServlet); 70 URL dir = new URL(u, "."); File currentDir = new File(includingServlet + "includetagpostfix"); resource = new URL(dir, resource).getFile(); 73 } catch (MalformedURLException mfue) { 74 log.error(mfue); 75 } 76 77 } 78 try { 79 if (ResourceLoader.getWebRoot().getResource(resource).openConnection().getDoInput() != getInverse()) { 80 return EVAL_BODY; 81 } else { 82 return SKIP_BODY; 83 } 84 } catch (IOException ioe) { 85 log.error(ioe); 86 return SKIP_BODY; 87 } 88 } 89 90 public int doAfterBody() throws JspTagException { 91 if (EVAL_BODY == EVAL_BODY_BUFFERED) { if (bodyContent != null) { 93 try{ 94 if(bodyContent != null) { 95 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 96 } 97 } catch(java.io.IOException e){ 98 throw new TaglibException(e); 99 } 100 } 101 } 102 return SKIP_BODY; 103 } 104 } 105 | Popular Tags |