<%@ page language = "java" import = "java.net.*" import = "java.io.*" %><%@ page trimDirectiveWhitespaces="true" %><%
String mime;
	HttpSession ses = request.getSession(true);
	String reqUrl = request.getParameter("url");
	reqUrl=reqUrl.replace(" ","%20");
	String docId= request.getParameter("P_DOC_ID");
	if (reqUrl.indexOf("?")>0)
	{
		reqUrl+="&";
	} else {
		reqUrl+="?";
	}
	reqUrl+="sid=" + request.getSession().getId();
	
	if(docId!=null) {
		reqUrl+="&P_DOC_ID=" + docId;
	}

	/*if(request.getParameter("mimeType") == null)
			mime = "text/xml";
		else
			mime =request.getParameter("mimeType");
	mime = mime.trim();*/
        URL url = new URL(reqUrl);
        
        //String message = nl.knowledgeplaza.util.IOUtil.toString( url.openStream() );
    	if (request.getParameter("downloadAs")!=null)
    	{
    		response.setHeader("Content-Disposition", "attachment;filename=\"" + request.getParameter("downloadAs") + "\"");
    		response.setHeader("Content-Type", "application/octet-stream;");
    		response.setHeader("Accept-Ranges", "bytes");
    		//response.setHeader("Content-Length", String.valueOf(message.length()));
    	} else {
    		//response.setContentType(mime);
    	}
	OutputStream o = response.getOutputStream();
	 URLConnection conn = url.openConnection();
    InputStream is =  conn.getInputStream();
      //url.openStream();
    byte[] buf = new byte[32 * 1024]; // 32k buffer
    int nRead = 0;
    while( (nRead=is.read(buf)) != -1 ) {
        o.write(buf, 0, nRead);
    }
    o.flush();
    o.close();// *important* to ensure no more jsp output
    return; 
%>