1 16 17 package org.apache.taglibs.xsl; 18 19 20 import java.io.BufferedInputStream ; 21 import java.io.InputStreamReader ; 22 import java.net.URL ; 23 import java.net.URLConnection ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.JspWriter ; 27 import javax.servlet.jsp.PageContext ; 28 import javax.servlet.jsp.tagext.TagSupport ; 29 30 31 41 42 public class IncludeTag extends TagSupport { 43 44 45 47 48 51 private String page = null; 52 53 public String getPage() { 54 return (this.page); 55 } 56 57 public void setPage(String page) { 58 this.page = page; 59 } 60 61 62 64 65 70 public int doStartTag() throws JspException { 71 72 if (!page.startsWith("/")) 75 throw new JspException ("Page value must start with '/'"); 76 77 JspWriter out = pageContext.getOut(); 79 80 HttpServletRequest request = 84 (HttpServletRequest ) pageContext.getRequest(); 85 StringBuffer url = new StringBuffer (); 86 url.append(request.getScheme()); 87 url.append("://"); 88 url.append(request.getServerName()); 89 if (request.getServerPort() != 80) { 90 url.append(':'); 91 url.append(request.getServerPort()); 92 } 93 if (request.getContextPath() != null) 94 url.append(request.getContextPath()); 95 url.append(page); URLConnection conn = null; 97 try { 98 conn = (new URL (url.toString())).openConnection(); 99 conn.setAllowUserInteraction(false); 100 conn.setDoInput(true); 101 conn.setDoOutput(false); 102 conn.connect(); 103 } catch (Exception e) { 104 throw new JspException ("Error opening connection: " + 105 e.toString()); 106 } 107 108 try { 110 BufferedInputStream is = 111 new BufferedInputStream (conn.getInputStream()); 112 InputStreamReader in = new InputStreamReader (is); 113 while (true) { 114 int ch = in.read(); 115 if (ch < 0) 116 break; 117 out.write(ch); 118 } 119 } catch (Exception e) { 120 throw new JspException ("Error reading connection: " + 121 e.toString()); 122 } 123 124 return (SKIP_BODY); 126 127 } 128 129 130 } 131 | Popular Tags |