1 43 44 package org.jfree.chart.servlet; 45 46 import java.io.File ; 47 import java.io.IOException ; 48 49 import javax.servlet.ServletException ; 50 import javax.servlet.http.HttpServlet ; 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 import javax.servlet.http.HttpSession ; 54 55 72 public class DisplayChart extends HttpServlet { 73 74 77 public DisplayChart() { 78 super(); 79 } 80 81 86 public void init() throws ServletException { 87 return; 88 } 89 90 99 public void service(HttpServletRequest request, 100 HttpServletResponse response) 101 throws ServletException , IOException { 102 103 HttpSession session = request.getSession(); 104 String filename = request.getParameter("filename"); 105 106 if (filename == null) { 107 throw new ServletException ("Parameter 'filename' must be supplied"); 108 } 109 110 filename = ServletUtilities.searchReplace(filename, "..", ""); 113 114 File file = new File (System.getProperty("java.io.tmpdir"), filename); 116 if (!file.exists()) { 117 throw new ServletException ( 118 "File '" + file.getAbsolutePath() + "' does not exist" 119 ); 120 } 121 122 boolean isChartInUserList = false; 125 ChartDeleter chartDeleter = (ChartDeleter) session.getAttribute( 126 "JFreeChart_Deleter" 127 ); 128 if (chartDeleter != null) { 129 isChartInUserList = chartDeleter.isChartAvailable(filename); 130 } 131 132 boolean isChartPublic = false; 133 if (filename.length() >= 6) { 134 if (filename.substring(0, 6).equals("public")) { 135 isChartPublic = true; 136 } 137 } 138 139 boolean isOneTimeChart = false; 140 if (filename.startsWith(ServletUtilities.getTempOneTimeFilePrefix())) { 141 isOneTimeChart = true; 142 } 143 144 if (isChartInUserList || isChartPublic || isOneTimeChart) { 145 ServletUtilities.sendTempFile(file, response); 147 if (isOneTimeChart) { 148 file.delete(); 149 } 150 } 151 else { 152 throw new ServletException ("Chart image not found"); 153 } 154 return; 155 } 156 157 } 158 | Popular Tags |