1 package org.ashkelon.pages; 2 3 import org.ashkelon.util.*; 4 import java.io.*; 5 import java.util.*; 6 import java.sql.*; 7 8 9 12 public class ClassSourcePage extends Page 13 { 14 private File srcHtmlDir = null; 15 private static final String SRCHTMLDIRNAME = "srchtml"; 16 private HtmlGenerator generator = new Java2HtmlGenerator(); 17 18 public ClassSourcePage() 19 { 20 super(); 21 } 22 23 public void setApplication(javax.servlet.ServletContext context) 24 { 25 super.setApplication(context); 26 27 srcHtmlDir = new File(context.getRealPath("/") + File.separator + SRCHTMLDIRNAME); 28 if (!srcHtmlDir.exists()) srcHtmlDir.mkdir(); 29 30 generator.initialize(srcHtmlDir); 31 } 32 33 34 public String handleRequest() throws SQLException 35 { 36 String qualifiedName = ServletUtils.getRequestParam(request, "cls_name"); 37 String fileName = qualifiedName.replace('.', File.separatorChar) + ".java"; 38 39 request.setAttribute("cls_name", qualifiedName); 40 41 List sourcepaths = (List) app.getAttribute("sourcepath"); 42 log.debug("number of paths in source path: "+sourcepaths.size()); 43 44 Iterator itr = sourcepaths.iterator(); 45 String path = null; 46 String sourceFile = null; 47 while (itr.hasNext()) 48 { 49 path = (String ) itr.next(); 50 if (!path.endsWith(File.separator)) 51 path += File.separator; 52 sourceFile = path + fileName; 53 log.debug("looking for "+sourceFile); 54 if (new File(sourceFile).exists()) 55 { 56 request.setAttribute("source_file", sourceFile); 57 String htmlFile = SRCHTMLDIRNAME + File.separator + fileName + ".html"; 58 request.setAttribute("html_file", htmlFile); 59 String realHtmlFile = srcHtmlDir + File.separator + fileName + ".html"; 60 61 if (! (new File(realHtmlFile).exists()) ) 62 { 63 generator.produceHtml(sourceFile, realHtmlFile); 64 } 65 66 return null; 67 } 68 } 69 70 request.setAttribute("source_file", ""); 71 return null; 72 } 73 74 } 75 | Popular Tags |