1 19 20 package com.sslexplorer.core.tags; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.net.URL ; 26 27 import javax.servlet.jsp.JspException ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.struts.taglib.TagUtils; 32 import org.apache.struts.taglib.html.BaseHandlerTag; 33 34 import com.sslexplorer.boot.Util; 35 36 public class ExternalContentTag extends BaseHandlerTag { 37 38 final static Log log = LogFactory.getLog(ExternalContentTag.class); 39 40 String url; 41 42 public ExternalContentTag() { 43 } 44 45 public int doEndTag() throws JspException { 46 InputStream in = null; 47 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 48 try { 49 in = new URL (url).openStream(); 50 Util.copy(in, baos); 51 TagUtils.getInstance().write(pageContext, new String (baos.toByteArray())); 52 } 53 catch(IOException ioe) { 54 throw new JspException ("Failed to load external page.", ioe); 55 } 56 finally { 57 Util.closeStream(in); 58 Util.closeStream(baos); 59 } 60 return (EVAL_PAGE); 61 } 62 63 public void release() { 64 super.release(); 65 url = null; 66 } 67 68 public int doStartTag() { 69 return EVAL_BODY_INCLUDE; 70 } 71 72 public void setUrl(String url) { 73 this.url = url; 74 } 75 } | Popular Tags |