package edu.vt.marian.WebGate; import java.io.*; import java.net.*; import java.util.*; import edu.vt.marian.common.*; import edu.vt.marian.uip.*; /** Class name: Request Class description: this is a request webgate received from cgi (formit). Author: Jianxin Zhao Finished time: ????, 1998 Known bugs: none Platform: jdk1.1.5 under UNIX ------------------------------------------------------------------------ Modified By: Richard Baker Date Modified: May 1, 2000 Platform Modified With: Microsoft Visual J++ 6.0 under Windows NT Reason For Modification: Added methods to return the value of the variables number, folder_number, and folder_name in the string pool. */ public class request { /** this is just for debugging */ Debug debug; /** this is used to read and store information sent by cgi program */ private StringPool sp; /** this record the time this request is generated */ private Date time; /** this constructor will create a request object from an input stream, it now use stringpool to do so but maybe changed in the future, the change will bring no effect to other classes as long as this class still provide the same service */ public request(InputStream is, Debug debug) { // first initialize data members init(); this.debug = debug; sp = new StringPool(is, debug); } /** this method will tell us the cgi program name of this request, so we don't need to tell the system this by using command line parameter, also we may support multiple formit simutanulously. */ public String get_client_name() { return sp.GetValue("client_name"); } /** this method will return the user name of this request */ public String get_user_name() { return sp.GetValue("user_name"); } /** this method will return the full name of the user when he/she login the first time */ public String get_full_name() { return sp.GetValue("full_name"); } /** this method will return the password of this request, user name and password are used to identify an user */ public String get_password() { return sp.GetValue("password"); } /** this method will return the new password the user entered, at least this is useful when user want to change password */ public String get_new_password() { return sp.GetValue("new_password"); } /** this method will return the confirmation password input by the user, at least we need user to confirm password when he/she first login or change previous password */ public String get_password_confirm() { return sp.GetValue("password_confirm"); } /** this method will tell us the type of this request, current type include query, circulaton,... */ public String get_type() { return sp.GetValue("type"); } /** this method will tell wether or not this request object contains the specified string, this is helpful when the request type is the same but different processing are needed for different strings contained int the request */ public String contains(String name) { String s = name + ".x"; if (sp.GetValue(s) == null) { return "no"; } // we don't care what's returned by method GetValue(), as long as // there is something, it probably will be a number return "yes"; } /** * This method returns the folder number of this request. */ public String get_folder_number() { return sp.GetValue("folder_number"); } /** * This method returns the folder name of this request. */ public String get_folder_name() { return sp.GetValue("folder_name"); } /** * This method returns the number (folder or query) of this request. */ public String get_number() { return sp.GetValue("number"); } /** this method will return the query number of this request */ public String get_query_number() { return sp.GetValue("query_number"); } /** this method will return the query data of this request, usually this is something filled by our client */ public query_data get_query_data(uip_manager uipm) { // process server list chosen by the client Vector server_list = new Vector(); Vector names = sp.get_names("on"); int i; String s; String hostname; int port; for (i = 0; i < names.size(); i++) { s = (String) names.elementAt(i); if (s.startsWith("server")) { // this is a server check box, create corresponding uip server // we assume the format of the name is // "server_hostname_port" hostname = s.substring(7, s.lastIndexOf("_")); port = Integer.parseInt(s.substring(s.lastIndexOf("_") + 1)); //**BUG: Here we go, losing the human-readable descriptions //** of the servers. Instead, we should be asking uipm. uip_server us = uipm.get_server(hostname, port); server_list.addElement(us); } } // create the query data with the specified title and server list query_data qd = new query_data(sp.GetValue("query_title"), server_list, debug); // process various fields qd.add_field(server_list, "text1_type", sp.GetValue("text1_type")); qd.add_field(server_list, "text1", sp.GetValue("text1")); qd.add_field(server_list, "text2_type", sp.GetValue("text2_type")); qd.add_field(server_list, "text2", sp.GetValue("text2")); qd.add_field(server_list, "text3_type", sp.GetValue("text3_type")); qd.add_field(server_list, "text3", sp.GetValue("text3")); // process preference qd.add_preference("sort_rule", sp.GetValue("sort_rule")); qd.add_preference("display_style", sp.GetValue("display_style")); qd.add_preference("time_out_value", sp.GetValue("time_out_value")); qd.add_preference("batch_size", sp.GetValue("batch_size")); return qd; } /** this method will return the general query data of this request, usually this is something filled by our client, general query data can be used to query user manager, query database of a user or log manager. (not implemented yet) */ public general_query_data get_general_query_data() { return null; // not implemented yet } /** this method will return the uip server chose by the user to see full description */ public uip_server get_uip_server() { String hostname = sp.GetValue("host_name"); int port = Integer.parseInt(sp.GetValue("port")); uip_server us = new uip_server(hostname, port, null, null, debug); return us; } /** this method will return the document numbers which are chosen by our client */ public Vector get_doc_numbers() { Vector doc_numbers = new Vector(); Vector names = sp.get_names("on"); int i; String s, s1; for (i = 0; i < names.size(); i++) { s = (String) names.elementAt(i); if (s.startsWith("doc_number_")) { // we assume the format is "doc_number_xxx" s1 = s.substring(11); doc_numbers.addElement(s1); } } return doc_numbers; } /** this method will return the user login names which are chosen by the super user */ public Vector get_user_names() { Vector user_names = new Vector(); Vector names = sp.get_names("on"); int i; String s, s1; for (i = 0; i < names.size(); i++) { s = (String) names.elementAt(i); if (s.startsWith("user_name_")) { // we assume the format is user_name_xxx" s1 = s.substring(10); user_names.addElement(s1); } } return user_names; } /** this method will return the preference contents associated with this request object */ public preference get_preference() { preference pre = new preference(debug); Vector names = sp.get_names(); // we assume preference format is "pre_xxx=xxx" int i; String s; for (i = 0; i < names.size(); i++) { s = (String) names.elementAt(i); if (s.startsWith("pre_")) { // this is a preference pre.add(s.substring(4), sp.GetValue(s)); } } return pre; } /** this method will return the last document number of the current page, the reason for this method is that we need to know display to which document when user come back to Results list page. */ public String get_last_doc_number() { return sp.GetValue("last_doc_number"); } /** this method will return the last query number associated with this request object */ public String get_last_query_number() { return sp.GetValue("last_query_number"); } /** this method will return the number of latest requests super use choose to see when doing log file analysis */ public String get_number_logs() { return sp.GetValue("number_logs"); } /** this method will set the time when this request is generated, in fact it will be set to the time this method is called */ private String set_generate_time() { time = new Date(); return "OK"; } /** this method will return the time when this request is generated, this might be used in logging and performance measurement */ public String get_generate_time() { return time.toString(); } /** this method will print the content of this object to a stream, this might be useful for remote management in the future . (not implemented yet) */ public String to_stream(DataOutputStream dos) { return null; // not implemented yet } /** this method will print the content of this object to a stream, this might be useful for remote management in the future . (not implemented yet) */ public String toString() { return sp.toString(); } /** this method will initialize the data members of this object */ private void init() { debug = null; sp = null; time = new Date(); } }