Changeset 3346
- Timestamp:
- 2002-08-12T09:53:13+12:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r3309 r3346 7 7 import javax.servlet.*; 8 8 import javax.servlet.http.*; 9 import java.util.Enumeration; 10 import java.io.File; 9 11 10 12 /** a servlet to serve the greenstone library - using servlets instead 11 13 * of cgi 14 * the init method is called only once - the first time the servlet classes 15 * are loaded. Each time a request comes in to the servlet, the session() 16 * method is called in a new thread (calls doGet/doPut etc) 17 * takes the a=p&p=home type args and builds a simple request to send to 18 * its receptionist, which returns the result in html, cos output=html 19 * is set in the request 20 * @see Receptionist 12 21 */ 13 22 public class LibraryServlet extends HttpServlet { 14 23 15 private String gsdl_home_; 16 private String site_home_; 17 private MessageRouter mr_=null; 18 24 private ConfigVars config_=null; // holds all teh system set up vars 25 private Receptionist recept_=null; 26 private ModuleInterface message_router_=null; 27 /** initialise the servlet 28 */ 19 29 public void init(ServletConfig config) throws ServletException { 20 30 // always call super.init; 21 31 super.init(config); 22 gsdl_home_ = config.getInitParameter("gsdlhome"); 23 if (gsdl_home_ == null) { 32 33 config_ = new ConfigVars(); 34 String sites_home_ = config.getInitParameter("siteshome"); 35 String site_name_ = config.getInitParameter("sitename"); 36 String interfaces_home_ = config.getInitParameter("interfaceshome"); 37 String interface_name_ = config.getInitParameter("interfacename"); 38 if (sites_home_ == null || site_name_==null || interfaces_home_ ==null || interface_name_==null) { 24 39 // must have this 25 System.err.println("gsdlhome not set!"); 26 System.exit(1); 27 } 28 site_home_ = config.getInitParameter("sitehome"); 29 if (site_home_ == null) { 30 // must have this 31 System.err.println("sitehome not set!"); 40 System.err.println("initialisation parameters not all set!"); 41 System.err.println(" you must have siteshome, sitename, interfaceshome, interfacename"); 32 42 System.exit(1); 33 43 } 34 44 35 // new message router 36 mr_ = new MessageRouter(); 37 mr_.setSiteHome(site_home_); 38 mr_.configure(); 45 config_.sites_home_ = sites_home_; 46 config_.site_name_ = site_name_; 47 config_.interfaces_home_ = interfaces_home_; 48 config_.interface_name_ =interface_name_; 49 50 config_.createXML(); 51 52 // new message router - create it and pass a handle to recept. 53 // the servlet wont use this directly 54 MessageRouter mr = new MessageRouter(); 55 mr.setSiteHome(config_.sites_home_+File.separatorChar 56 +config_.site_name_); 57 mr.configure(); 58 // new receptionist 59 recept_ = new Receptionist(); 60 recept_.setConfigVars(config_); 61 recept_.setMessageRouter(mr); 62 recept_.configure(); 39 63 40 64 } … … 46 70 response.setContentType("text/html"); 47 71 PrintWriter out = response.getWriter(); 48 72 73 String lang = request.getParameter("l"); 74 if (lang==null || lang.equals("")) { 75 lang = "en"; // the default 76 } 77 // the request to the receptionist 78 String xml_request="<message lang='"+lang+"'>"; 79 49 80 String action = request.getParameter("a"); 50 81 if (action==null || action.equals("")) { 51 // the home page 52 53 //String describe = "<message><request type='describe' info='collectionList'/></message>"; 54 //String result = mr_.process(describe); 55 82 // display the home page 83 // a=p&p=home 84 xml_request +="<request type='action' output='html' info='p/home'/>"; 85 } else { 86 String subaction = request.getParameter("sa"); 87 xml_request += "<request type='action' info='"+action; 88 if (subaction != null) { 89 xml_request += "/"+subaction; 90 } 91 xml_request += "'><paramList>"; 92 Enumeration params = request.getParameterNames(); 93 while(params.hasMoreElements()) { 94 String name = (String)params.nextElement(); 95 if (!name.equals("a") && !name.equals("sa")) { 96 String value = request.getParameter(name); 97 // for now, just add value as attribute - should un-url 98 // encode them etc and so some might need to be text not atts 99 // or is that done already? 100 xml_request += "<param name='"+name+"' value='"+value+"'/>"; 101 } 102 } 103 xml_request += "</paramList></request>"; 104 } 105 xml_request += "</message>"; 56 106 57 //try a transform - hard coded result to test the stylesheet 58 String result = "<message><collectionList><collection name='mycol'><metadata name='icon'>logo.gif</metadata><metadata name='title'>my collection</metadata></collection><collection name='demo'><metadata name='icon'>fao.gif</metadata><metadata name='title'>mg demo</metadata></collection><collection name='mgppdemo'><metadata name='icon'>demo.gif</metadata><metadata name='title'>mgpp demo</metadata></collection></collectionList></message>"; 107 System.out.println("request="+xml_request); 59 108 60 XMLTransformer transformer = new XMLTransformer(); 61 String stylesheet = "/research/kjdon/home/gsdl3/transform/home.xsl"; 62 String transformed_result = transformer.transform(stylesheet, result); 63 out.println(transformed_result); 64 } 65 else { 66 // do the appropriate action 67 out.println("<html>\n"+ 68 "<head><title>Hello Greenstone Library</title></head>"+ 69 "<body>\n"+ 70 "<p>greenstone action:"+action+"</p>\n"+ 71 "</body></html>"); 72 73 } 109 String result = recept_.process(xml_request); 110 out.println(result); 111 112 74 113 75 114 }
Note:
See TracChangeset
for help on using the changeset viewer.