1 package com.dotmarketing.servlets; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileNotFoundException ; 6 import java.io.IOException ; 7 8 import javax.servlet.ServletException ; 9 import javax.servlet.ServletOutputStream ; 10 import javax.servlet.http.HttpServlet ; 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpServletResponse ; 13 14 import com.dotmarketing.util.Config; 15 import com.dotmarketing.util.Logger; 16 17 public class IconServlet extends HttpServlet { 18 19 private static final long serialVersionUID = 1L; 20 21 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 22 23 String i = request.getParameter("i"); 24 String icon = com.dotmarketing.util.UtilMethods.getFileExtension(i); 25 26 ServletOutputStream out = response.getOutputStream(); 27 response.setContentType("image/gif"); 28 29 java.util.GregorianCalendar expiration = new java.util.GregorianCalendar (); 30 expiration.add(java.util.Calendar.MONTH, 1); 31 java.text.SimpleDateFormat httpDate = new java.text.SimpleDateFormat ( "EEE, dd MMM yyyy HH:mm:ss z"); 32 33 response.setHeader("Expires", httpDate.format(expiration.getTime())); 34 response.setHeader("Cache-Control", "max-age=2592000"); 35 36 37 38 FileInputStream fis = null; 39 try { 40 41 fis = 42 new FileInputStream ( 43 com.dotmarketing.util.Config.CONTEXT.getRealPath(Config.getStringProperty("PATH_TO_ICONS") + File.separator + icon + ".gif")); 44 int n; 45 while ((n = fis.available()) > 0) { 46 byte[] b = new byte[n]; 47 int result = fis.read(b); 48 if (result == -1) 49 break; 50 out.write(b); 51 } } 53 catch (FileNotFoundException e) { 54 try { 55 fis = 56 new FileInputStream ( 59 com.dotmarketing.util.Config.CONTEXT.getRealPath(com.dotmarketing.util.Config.getStringProperty("PATH_TO_ICONS") + File.separator + "ukn.gif")); 60 int n; 61 while ((n = fis.available()) > 0) { 62 byte[] b = new byte[n]; 63 int result = fis.read(b); 64 if (result == -1) 65 break; 66 out.write(b); 67 } } 69 catch (Exception f) { 70 Logger.error(this, f.toString(), f); 71 } 72 } 73 finally { 74 if (fis != null) 75 fis.close(); 76 } 77 out.close(); 78 79 } 80 } 81 | Popular Tags |