1 23 24 package com.sun.enterprise.tools.admingui.servlet; 25 26 import java.io.InputStreamReader ; 27 import java.io.IOException ; 28 import java.io.File ; 29 import java.io.FileInputStream ; 30 import java.util.Properties ; 31 import java.net.URL ; 32 33 import javax.servlet.*; 34 import javax.servlet.http.*; 35 import javax.management.ObjectName ; 36 37 import com.sun.enterprise.tools.admingui.util.Util; 38 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 39 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 40 41 public class HandleQuickStartDocs extends HttpServlet { 42 43 public void init(ServletConfig config) throws ServletException { 44 super.init(config); 45 } 46 47 public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 48 doPost(req, res); 49 } 50 51 52 public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 53 String pathInfo = req.getPathInfo(); 54 55 if(pathInfo == null || pathInfo.length() == 0) { 56 pathInfo = "/QuickStart.html"; 58 } 59 File fileIn = null; 60 FileInputStream streamIn = null; 61 62 try { 63 fileIn = new File (getInstallDir()+pathInfo); 65 66 if(!fileIn.exists()) { 67 fileIn = new File (getInstallDir()+"/QuickStart.html"); 69 } 70 71 if(fileIn.canRead()) 73 streamIn = new FileInputStream (fileIn); 74 else { 75 res.sendError(400, req.getRequestURI()); 76 return; 77 78 } 79 80 } catch (Exception e) 81 { 82 res.sendError(400, req.getRequestURI()); 83 return; 84 } 85 86 byte[] data = new byte[(int)fileIn.length()]; 88 if(data != null && (int)fileIn.length() > 0) 89 { 90 streamIn.read(data); 91 streamIn.close(); 92 } 93 94 if(req.getRequestURI().indexOf(".gif") > 0 || req.getRequestURI().indexOf(".jpg") > 0 || req.getRequestURI().indexOf(".jpeg") > 0 ) { 95 ServletOutputStream imageOut = res.getOutputStream(); 97 98 if(req.getRequestURI().indexOf(".gif") > 0) 99 res.setContentType("image/gif"); 100 else 101 res.setContentType("image/jpeg"); 102 imageOut.write(data); 104 imageOut.close(); 105 } else { 106 if(req.getRequestURI().indexOf(".css") > 0) { 107 res.setContentType("text/css"); 108 } else { 109 res.setContentType("text/html"); 110 111 } 112 113 ServletOutputStream textOut = res.getOutputStream(); 115 textOut.write(data); 116 textOut.close(); 117 } 118 } 119 120 protected String getInstallDir() throws Exception { 121 String dir = ""; 122 try { 123 Object [] params = new Object []{"${com.sun.aas.installRoot}", "server", new Boolean ("true")}; 124 String [] types = new String []{"java.lang.String", "java.lang.String", "boolean"}; 125 Object installDir = MBeanUtil.invoke( 126 new ObjectName ("com.sun.appserv:type=domain,category=config"), "resolveTokens", params, types); 127 if(dir != null) 128 dir = installDir.toString(); 129 } catch (Exception ex) { 130 throw ex; 131 } 132 return getDocsDir(dir); 133 } 134 135 protected String getDocsDir(String dir){ 136 return dir+"/docs"; 137 } 138 139 } 140 | Popular Tags |