Changeset 3363
- Timestamp:
- 2002-08-20T10:39:06+12:00 (22 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/Library2.java
r3292 r3363 27 27 import java.io.IOException; 28 28 /** 29 * A program to take XML strings from the command line and send 30 * them to the system. 29 * A program to take XML cgi-input from the command line and return html 31 30 * 32 31 * @author <a href="mailto:[email protected]">Katherine Don</a> 33 32 * @version $Revision$ 34 33 */ 34 35 35 final public class Library2 { 36 36 37 37 public static void main(String args[]) { 38 38 39 if (args.length != 2) {40 System.out.println("Usage: Library2 < gsdl3home> <sitehome>");39 if (args.length != 4) { 40 System.out.println("Usage: Library2 <sites home> <site name> <interfaces home> <interface name>"); 41 41 System.exit(1); 42 42 } 43 String gsdl_home = args[0]; 44 String transform_home = GSFile.xmlTransformDir(gsdl_home); 45 String site_home = args[1]; 43 44 ConfigVars config_ = new ConfigVars(); 45 config_.sites_home_ = args[0]; 46 config_.site_name_ = args[1]; 47 config_.interfaces_home_ = args[2]; 48 config_.interface_name_ = args[3]; 49 50 config_.createXML(); 46 51 47 MessageRouter mr = new MessageRouter(); 48 mr.setSiteHome(site_home); 49 mr.configure(); 50 51 // for doing xslt transforms 52 XMLTransformer transformer = new XMLTransformer(); 52 // new message router - create it and pass a handle to recept. 53 // the servlet wont use this directly 54 MessageRouter message_router_ = new MessageRouter(); 55 message_router_.setSiteHome(config_.sites_home_+File.separatorChar 56 +config_.site_name_); 57 message_router_.configure(); 58 // new receptionist 59 Receptionist recept_ = new Receptionist(); 60 recept_.setConfigVars(config_); 61 recept_.setMessageRouter(message_router_); 62 recept_.configure(); 53 63 54 64 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 55 65 String query=null; 56 String request=null;57 66 String result=null; 58 String collect=null;59 String service=null;60 String info=null;61 String content=null;62 67 while (true) { 63 System.out.println("Please enter a query type (choose from: describe, query)or 'exit' to quit");68 System.out.println("Please enter an XML query all on one line, or 'exit' to quit"); 64 69 try { 65 70 query = br.readLine(); 66 query.trim(); 67 68 if (query.startsWith("exit")) { 69 System.exit(1); 70 } 71 if (query.equals("describe")|| query.equals("query")) { 72 System.out.println("\nPlease enter a collection name (or <enter> for no collection)"); 73 collect = br.readLine(); 74 collect.trim(); 75 System.out.println("\nPlease enter a service name (or <enter> for no service)"); 76 service = br.readLine(); 77 service.trim(); 78 if (query.equals("describe")) { 79 80 System.out.println("\nPlease enter an info name (or <enter> for no info)"); 81 info = br.readLine(); 82 info.trim(); 83 84 } else if (query.equals("query") ) { 85 System.out.println("\nPlease enter the content to your query (in xml, all on one line - sorry about that)"); 86 content=br.readLine(); 87 content.trim(); 88 } 89 90 request = "<message><request type='"+query+"' to='"; 91 92 if (!collect.equals ("")) { 93 request += collect+"/"; 94 } 95 if (!service.equals("")) { 96 request += service+"/"; 97 } 98 request += "'"; 99 if (query.equals("describe") && !info.equals("")) { 100 request += " info='"+info+"'/>"; 101 } 102 else if (query.equals("query") && !content.equals("")) { 103 request +=">"+content+"</request>"; 104 } else { 105 request += "/>"; 106 } 71 } catch (Exception e) { 72 System.err.println("Library1 exception:"+e.getMessage()); 73 } 74 if (query.startsWith("exit")) { 75 System.exit(1); 76 } 77 78 result = recept_.process(query); 79 80 System.out.println(result); 107 81 108 82 109 request += "</message>"; 110 111 System.out.println("Sending message to MessageRouter:\n"+request); 112 result = mr.process(request); 113 114 System.out.println("Raw Result:\n"+result+"\n"); 115 116 // transform the result 117 118 // select a stylesheet 119 String stylesheet = null; 120 if (query.equals("describe")) { 121 if (collect.equals("")&&service.equals("")) { 122 stylesheet = transform_home+File.separatorChar+"home.xsl"; 123 } else if (!collect.equals("")) { 124 stylesheet = transform_home+File.separatorChar+"collect_about.xsl"; 125 } else if (!service.equals("")) { 126 stylesheet = transform_home+File.separatorChar+"service_about.xsl"; 127 } 128 } else if (query.equals("query")) { 129 stylesheet = transform_home+File.separatorChar+"query_result.xsl"; 130 } 131 if (stylesheet != null) { 132 File style = new File(stylesheet); 133 if (!style.exists()) { 134 System.err.println("stylesheet doesn't exist"); 135 } else { 136 137 String transformed_result = transformer.transform(stylesheet, result); 138 System.out.println("Transformed result:\n"+transformed_result); 139 } 140 } else { 141 System.out.println("no appropriate stylesheet found"); 142 } 143 } else { 144 System.out.println("your request was not understood, sorry"); 145 } 146 147 } catch (IOException e) { 148 System.err.println("Library2 IO exception:"+e.getMessage()); 149 } 150 151 } // while (true 152 } 153 83 } 84 85 } 154 86 } 155 87 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r3346 r3363 22 22 public class LibraryServlet extends HttpServlet { 23 23 24 private ConfigVars config_=null; // holds all t ehsystem set up vars24 private ConfigVars config_=null; // holds all the system set up vars 25 25 private Receptionist recept_=null; 26 private M oduleInterfacemessage_router_=null;26 private MessageRouter message_router_=null; 27 27 /** initialise the servlet 28 28 */ … … 52 52 // new message router - create it and pass a handle to recept. 53 53 // the servlet wont use this directly 54 MessageRouter mr= new MessageRouter();55 m r.setSiteHome(config_.sites_home_+File.separatorChar54 message_router_ = new MessageRouter(); 55 message_router_.setSiteHome(config_.sites_home_+File.separatorChar 56 56 +config_.site_name_); 57 m r.configure();57 message_router_.configure(); 58 58 // new receptionist 59 59 recept_ = new Receptionist(); 60 60 recept_.setConfigVars(config_); 61 recept_.setMessageRouter(m r);61 recept_.setMessageRouter(message_router_); 62 62 recept_.configure(); 63 63 … … 68 68 throws ServletException, IOException { 69 69 70 response.setContentType("text/html"); 70 request.setCharacterEncoding("UTF-8"); 71 response.setContentType("text/html;charset=UTF-8"); 72 //response.setContentType("text/html"); 71 73 PrintWriter out = response.getWriter(); 72 74 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/Action.java
r3340 r3363 5 5 // XML classes 6 6 import org.w3c.dom.Node; 7 import org.w3c.dom.Element; 7 8 import org.w3c.dom.Document; 8 9 9 abstract public class Action implements ModuleInterface{10 abstract public class Action { 10 11 11 12 protected ConfigVars config_=null; … … 15 16 /** a converter class to parse XML and create Docs */ 16 17 protected XMLConverter converter_=null; 18 /** cgi args conveter */ 19 protected CGIArgConverter cgi_=null; 17 20 /** a transformer class to transform xml using xslt */ 18 21 protected XMLTransformer transformer_=null; … … 38 41 } 39 42 43 public void setCGIConverter(CGIArgConverter cgi) { 44 cgi_ = cgi; 45 } 40 46 public void configure() { 41 47 // does nothing yet … … 45 51 * and returns the page of results - may be in html/xml/other 46 52 * depending on the output att of the request */ 47 abstract public String process(String xml_in);48 49 /*Document doc = converter_.getDOM(xml_in);53 public String process(String xml_in) { 54 55 Element message = converter_.getDOM(xml_in).getDocumentElement(); 50 56 51 Node res = process(doc);52 return converter_.getString(res); // does this work for html? */ 57 return process(message); 58 } 53 59 54 public Node process(Node xml_in){ 55 return xml_in; // for now 56 } 60 abstract public String process(Element xml_in); 61 57 62 58 63 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java
r3340 r3363 11 11 12 12 13 public String process ( String xml_in) {13 public String process (Element message) { 14 14 15 Element message = converter_.getDOM(xml_in).getDocumentElement();16 15 Element request = (Element)message.getElementsByTagName("request").item(0); 17 16 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java
r3340 r3363 12 12 public class PageAction extends Action { 13 13 14 15 public String process (String xml_in) { 14 public String process (Element message) { 16 15 17 Element message = converter_.getDOM(xml_in).getDocumentElement();18 16 Element request = (Element)message.getElementsByTagName("request").item(0); 19 20 17 String info = request.getAttribute("info"); 21 18 // remove the page/ bit 22 19 info = GSPath.removeFirstLink(info); 23 20 String page_name = GSPath.getFirstLink(info); 21 22 // create the return page tree 23 Element page = doc_.createElement("page"); 24 page.setAttribute("lang", message.getAttribute("lang")); 25 // add the lang stuff from xml_in 26 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true)); 27 // add the system stuff from xml_in 28 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true)); 29 24 30 if (page_name.equals("")) { 25 31 // for now send an error. change to always display the home page? … … 27 33 } 28 34 if (page_name.equals("home")) { 29 return homePage( request);35 return homePage(page, request); 30 36 } else if (page_name.equals("about")) { 31 return aboutPage( request);37 return aboutPage(page, request); 32 38 } else { 33 39 return GSHTML.errorPage("page: "+page_name+" not yet implemented"); … … 35 41 } 36 42 37 protected String homePage(Element request) { 43 44 protected String homePage(Element page, Element orig_message) { 38 45 39 46 // first, get the list of collections from mr 40 47 41 48 Element coll_list_message = doc_.createElement("message"); 49 coll_list_message.setAttribute("lang", page.getAttribute("lang")); 42 50 Element coll_list_request = doc_.createElement("request"); 43 51 coll_list_message.appendChild(coll_list_request); … … 53 61 System.out.println(converter_.getString(coll_list_response)); 54 62 63 // second, get the metadata for each collection 55 64 NodeList colls = coll_list_response.getElementsByTagName("collection"); 56 65 57 66 Element metadata_message = doc_.createElement("message"); 67 metadata_message.setAttribute("lang", page.getAttribute("lang")); 58 68 Element metadata_request = doc_.createElement("request"); 59 69 metadata_message.appendChild(metadata_request); … … 70 80 } 71 81 72 //return GSHTML.htmlSafe(converter_.getString(coll_list_response));73 //now the full response is in coll_list_response74 //String stylesheet = GSFile.stylesheetPath(gsdl_home_, site_home_,75 // display_home_, "home.xsl");76 String stylesheet = GSFile.stylesheetPath(config_, "home.xsl");77 78 Element system = doc_.createElement("system");79 //Element sitename = doc_.createElement("sitename");80 system.setAttribute("sitename", "localsite");81 coll_list_response.appendChild(coll_list_response.getOwnerDocument().importNode(system, true));82 83 82 System.out.println("the second xml response is"); 84 83 System.out.println(converter_.getString(coll_list_response)); 85 84 85 //now the full response is in coll_list_response 86 87 // add it in to the page xml tree 88 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_list_response, "response"), true)); 89 90 String stylesheet = GSFile.stylesheetPath(config_, "home.xsl"); 86 91 String transformed_result = transformer_.transform(stylesheet, 87 coll_list_response);92 page); 88 93 return transformed_result; 89 94 90 95 } // homePage 91 96 92 protected String aboutPage(Element request) {97 protected String aboutPage(Element page, Element request) { 93 98 94 99 // get the params out 95 HashMap params = GSXML.extractParams((Element)GSXML.get ChildByTagName(request, "paramList"));100 HashMap params = GSXML.extractParams((Element)GSXML.getNodeByPath(request, "paramList")); 96 101 String coll_name = (String)params.get("c"); 97 String lang = (String)params.get("l"); 98 if (lang==null || lang.equals("")) { 99 lang="en"; // the default 100 } 101 System.out.println("lang="+lang); 102 102 103 Element coll_about_message = doc_.createElement("message"); 103 //coll_about_message.setAttribute("xml:lang", lang); 104 coll_about_message.setAttribute("lang", page.getAttribute("lang")); 105 104 106 Element coll_about_request = doc_.createElement("request"); 105 107 coll_about_message.appendChild(coll_about_request); 106 108 coll_about_request.setAttribute("type", "describe"); 107 109 coll_about_request.setAttribute("to", coll_name); 110 108 111 Element coll_about_response = (Element)mr_.process(coll_about_message); 109 coll_about_response.setAttribute("lang", lang); 110 //return GSHTML.htmlSafe(converter_.getString(coll_about_response)); 111 //String stylesheet = GSFile.stylesheetPath(gsdl_home_, site_home_, 112 // display_home_, "about.xsl"); 112 113 114 // add the response to the page 115 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, "response"), true)); 116 117 // process using the stylesheet 113 118 String stylesheet = GSFile.stylesheetPath(config_, "about.xsl"); 114 119 115 System.out.println("stylesheet="+stylesheet);120 //System.out.println("response="+converter_.getString(page)); 116 121 String transformed_result = transformer_.transform(stylesheet, 117 coll_about_response);122 page); 118 123 return transformed_result; 119 124 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java
r3340 r3363 10 10 11 11 import java.util.HashMap; 12 import java.util.Map; 13 //import java.util.Map; 14 import java.util.Iterator; 12 15 13 16 public class QueryAction extends Action { 14 17 15 18 16 public String process (String xml_in) { 17 18 Element message = converter_.getDOM(xml_in).getDocumentElement(); 19 public String process (Element message) { 20 21 22 // create the return page tree 23 Element page = doc_.createElement("page"); 24 page.setAttribute("lang", message.getAttribute("lang")); 25 // add the lang stuff from message 26 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true)); 27 // add the system stuff from message 28 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true)); 29 19 30 Element request = (Element)message.getElementsByTagName("request").item(0); 20 21 31 String info = request.getAttribute("info"); 22 32 // remove the q/ bit … … 29 39 30 40 if (query_type.equals("text")) { 31 return textQuery( request);41 return textQuery(page, request); 32 42 } 33 43 if (query_type.equals("field")) { 34 return fieldQuery( request);35 } 36 return unknownQuery( request);44 return fieldQuery(page, request); 45 } 46 return unknownQuery(page, request); 37 47 38 48 39 49 } 40 50 41 protected String textQuery(Element request) { 42 43 Element query_request = doc_.createElement("message"); 44 query_request.appendChild(doc_.importNode(request, true)); 45 51 // we may be able to generalize this for all query types? 52 protected String textQuery(Element page, Element request) { 53 54 // chack that the stylesheet is present - cant output a page without one. we may adapt this to use unknownquery stylesheet? - or ask for one from the MR 46 55 String stylesheet = GSFile.stylesheetPath(config_, "textquery.xsl"); 47 48 //String stylesheet = GSFile.stylesheetPath(gsdl_home_, site_home_,49 // display_home_, "textquery.xsl");50 56 if (stylesheet==null) { 51 57 return GSHTML.errorPage("textquery stylesheet not found!"); 52 58 } 53 54 HashMap params = GSXML.extractParams((Element)GSXML.getChildByTagName(request, "paramList")); 59 60 // extract the params from the cgi-request, and check that we have a coll specified 61 // first convert short to long names 62 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList"); 63 cgi_.toLong(cgi_paramList); 64 HashMap params = GSXML.extractParams(cgi_paramList); 65 66 String collection = (String)params.get("c"); 67 if (collection == null || collection.equals("")) { 68 return GSHTML.errorPage("textquery, need to specify a colleciton!"); 69 } 70 71 // the first part of the data for the page is the cgi-params 72 Element cgi_request = (Element)doc_.importNode(request, true); 73 page.appendChild(cgi_request); 74 75 // get the service info from the MR - this will probably need to be cached somehow later on. and add as a description node to the cgi-request - this doesn't work. change to add the specified value as a current attribute to the param - need to do somthing different for query 76 77 Element mr_info_message = doc_.createElement("message"); 78 Element mr_info_request = doc_.createElement("request"); 79 mr_info_message.appendChild(mr_info_request); 80 mr_info_request.setAttribute("type", "describe"); 81 82 String to = collection; 83 to = GSPath.appendLink(to, "TextQuery"); 84 mr_info_request.setAttribute("to", to); 85 86 Element mr_info_response = (Element) mr_.process(mr_info_message); 87 System.err.println("describe response for service"); 88 System.err.println(converter_.getString(mr_info_response)); 89 Element description = doc_.createElement("description"); 90 // just param list for now - may need content info too 91 Node pl = GSXML.getNodeByPath(mr_info_response, "response/service/paramList"); 92 if (pl ==null) { 93 System.out.println("pl is null"); 94 } 95 else { 96 System.out.println("pl name is "+pl.getNodeName()); 97 } 98 Element imported_paramList = (Element)doc_.importNode(pl, true); 99 System.out.println("imported param list="); 100 System.out.println(converter_.getString(imported_paramList)); 101 // convert the name to short 102 cgi_.addShortNames(imported_paramList); 103 System.out.println("converted param list="); 104 System.out.println(converter_.getString(imported_paramList)); 105 106 description.appendChild(imported_paramList); 107 108 // for each param in page_request, set the current value if present 109 //actually, prob dont need to know the default value, just which one to display - overwrite the default att? 110 111 Element param = (Element)imported_paramList.getFirstChild(); 112 while (param !=null) { 113 if (param.getNodeName().equals("param")) { // just in case 114 String name = param.getAttribute("name"); 115 String current = (String)params.get(name); 116 System.out.println("name="+name+", current="+current); 117 if (current !=null && !current.equals("")) { 118 param.setAttribute("default", current); 119 } 120 } 121 param = (Element)param.getNextSibling(); 122 } 123 System.out.println("adapted param list="); 124 System.out.println(converter_.getString(imported_paramList)); 125 126 cgi_request.appendChild(description); 127 128 // check the query string 55 129 String query = (String)params.get("q"); 130 56 131 if (query==null|| query.equals("")) { 57 // if there is no q set, just output the search box58 S tring transformed_result = transformer_.transform(stylesheet,59 query_request);60 return transforme d_result;132 // if there is no q set, just output the search form 133 System.out.println("the plain page with no query data"); 134 System.out.println(converter_.getString(page)); 135 return transformer_.transform(stylesheet, page); 61 136 } 62 137 63 138 // else do the request, output search box and results 64 Element mr_message = doc_.createElement("message"); 65 Element mr_request = doc_.createElement("request"); 66 mr_message.appendChild(mr_request); 67 68 mr_request.setAttribute("type", "query"); 69 String to = (String)params.get("c"); // collection name 70 to = GSPath.appendLink(to, "TextQuery"); 71 mr_request.setAttribute("to", to); 72 73 // ignore paramList for now 139 Element mr_query_message = doc_.createElement("message"); 140 Element mr_query_request = doc_.createElement("request"); 141 mr_query_message.appendChild(mr_query_request); 142 143 mr_query_request.setAttribute("type", "query"); 144 mr_query_request.setAttribute("to", to); 145 146 // paramList 74 147 Element paramList = doc_.createElement("paramList"); 75 mr_request.appendChild(paramList); 148 mr_query_request.appendChild(paramList); 149 150 Iterator i = params.entrySet().iterator(); 151 while (i.hasNext()) { 152 Map.Entry e = (Map.Entry)i.next(); 153 String name = cgi_.toLong((String)e.getKey()); 154 if (!name.equals("")) { 155 String value = (String)e.getValue(); 156 // if (!name.equals("c")) { 157 Element p = doc_.createElement("param"); 158 p.setAttribute("name", name); 159 p.setAttribute("value", value); 160 paramList.appendChild(p); 161 // } 162 } 163 } 76 164 77 165 // content - contains the query string 78 Element content = doc_.createElement("content");79 Text text = doc_.createTextNode(query);80 content.appendChild(text);81 mr_ request.appendChild(content);82 //return GSHTML.errorPage(GSHTML.htmlSafe(converter_.getString(mr_message)));83 84 Element result1 = (Element)mr_.process(mr_message); 166 Element query_content = doc_.createElement("content"); 167 Text query_text = doc_.createTextNode(query); 168 query_content.appendChild(query_text); 169 mr_query_request.appendChild(query_content); 170 171 Element mr_query_response = (Element)mr_.process(mr_query_message); 172 85 173 // this result is the list of docs. 86 174 // now take that list, and get the Titles 87 175 // for now, just create a whole new request 88 176 89 Element resource_list = (Element)result1.getElementsByTagName("resourceList").item(0); // should always be a resource list - but it may be empty90 91 Element first_resource = (Element)GSXML.getChildByTagName(resource_list, "resource");92 if (first_resource == null) { // no docs found - dont bother getting metadata 93 Element result_response = (Element)GSXML.getChildByTagName( result1, "response");177 // check that there are some resources - for now check the list, but later should use a numdocs metadata elem 178 Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response, "response/content/resourceList"); // resourceList not present if no docs found 179 if (resource_list == null) { 180 181 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, "response"); 94 182 95 query_request.appendChild(doc_.importNode(result_response, true)); 96 97 String transformed_result = transformer_.transform(stylesheet, 98 query_request); 99 100 return transformed_result; 101 } 183 page.appendChild(doc_.importNode(result_response, true)); 184 System.out.println("the page with empty response"); 185 System.out.println(converter_.getString(page)); 186 return transformer_.transform(stylesheet, page); 187 } 188 189 // we have a doc list, so get the metadata - for now, get title. 190 // can we dynamically decide what metadata to get? 102 191 // get the Title metadata 103 Element mr_me ssage2= doc_.createElement("message");104 Element mr_ request2= doc_.createElement("request");105 mr_me ssage2.appendChild(mr_request2);106 107 mr_ request2.setAttribute("type", "query");108 to = (String)params.get("c"); // collection name109 to = GSPath.appendLink(to, "MetadataRetrieve");110 mr_request2.setAttribute("to", to);111 Element content2= doc_.createElement("content");112 mr_ request2.appendChild(content2);192 Element mr_metadata_message = doc_.createElement("message"); 193 Element mr_metadata_request = doc_.createElement("request"); 194 mr_metadata_message.appendChild(mr_metadata_request); 195 196 mr_metadata_request.setAttribute("type", "query"); 197 to = GSPath.appendLink(collection, "MetadataRetrieve"); 198 mr_metadata_request.setAttribute("to", to); 199 200 Element meta_content = doc_.createElement("content"); 201 mr_metadata_request.appendChild(meta_content); 113 202 114 203 // the first part of the content is the doc list 115 content2.appendChild(doc_.importNode(resource_list, true));204 meta_content.appendChild(doc_.importNode(resource_list, true)); 116 205 117 206 // the second part of the content is the metadata list … … 120 209 title.setAttribute("name", "Title"); 121 210 metadata_list.appendChild(title); 122 content2.appendChild(metadata_list); 123 124 //return GSHTML.errorPage(GSHTML.htmlSafe(converter_.getString(mr_request2))); 125 Element result2 = (Element)mr_.process(mr_message2); 126 127 Element result2_response = (Element)GSXML.getChildByTagName(result2, "response"); 128 129 query_request.appendChild(doc_.importNode(result2_response, true)); 130 //return GSHTML.errorPage(GSHTML.htmlSafe(converter_.getString(query_request))); 131 132 String transformed_result = transformer_.transform(stylesheet, 133 query_request); 134 135 return transformed_result; 136 137 } 138 139 protected String fieldQuery(Element request) { 211 meta_content.appendChild(metadata_list); 212 213 System.out.println("the metadata request to mr"); 214 System.out.println(converter_.getString(mr_metadata_message)); 215 216 Element mr_metadata_response = (Element)mr_.process(mr_metadata_message); 217 218 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, "response"); 219 220 page.appendChild(doc_.importNode(result_response, true)); 221 222 System.out.println("the page with full response"); 223 System.out.println(converter_.getString(page)); 224 225 return transformer_.transform(stylesheet, page); 226 227 } 228 229 protected String fieldQuery(Element page, Element request) { 140 230 return GSHTML.errorPage("field query not implemented"); 141 231 142 232 143 233 } 144 protected String unknownQuery(Element request) {234 protected String unknownQuery(Element page, Element request) { 145 235 146 236 return GSHTML.errorPage("unknown query subtype - unknown query not implemented"); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ResourceAction.java
r3340 r3363 10 10 import java.util.HashMap; 11 11 public class ResourceAction extends Action { 12 13 12 14 public String process (String xml_in) {15 13 16 Element message = converter_.getDOM(xml_in).getDocumentElement(); 17 Element request = (Element)message.getElementsByTagName("request").item(0); 14 // could pass in action name, and have it dynamically decide the name 15 16 public String process (Element message) { 18 17 19 // could pass in aciton name, and have it dynamically decide the name18 // find the stylesheet 20 19 String stylesheet = GSFile.stylesheetPath(config_, "resource.xsl"); 21 20 22 //String stylesheet = GSFile.stylesheetPath(gsdl_home_, site_home_,23 // display_home_, "resource.xsl");24 21 if (stylesheet==null) { 25 22 return GSHTML.errorPage("resource stylesheet not found!"); 26 23 } 27 24 28 25 // for now, info="r" eventually we may want to change to r/text r/assoc 29 26 // or something 30 31 HashMap params = GSXML.extractParams((Element)request.getElementsByTagName("paramList").item(0)); 32 27 Element request = (Element)message.getElementsByTagName("request").item(0); 28 29 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList"); 30 cgi_.toLong(cgi_paramList); 31 HashMap params = GSXML.extractParams(cgi_paramList); 32 33 33 String resource_name = (String)params.get("r"); 34 34 if (resource_name == null || resource_name.equals("")) { … … 36 36 return GSHTML.errorPage("no resource specified"); 37 37 } 38 39 40 // create the return page tree 41 Element page = doc_.createElement("page"); 42 page.setAttribute("lang", message.getAttribute("lang")); 43 // add the lang stuff from message 44 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true)); 45 // add the config stuff from message 46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true)); 47 48 38 49 39 50 // build up the mr request 40 41 51 Element mr_message = doc_.createElement("message"); 42 52 Element mr_request = doc_.createElement("request"); … … 61 71 content.appendChild(resource_list); 62 72 63 //return GSHTML.errorPage(GSHTML.htmlSafe(converter_.getString(mr_message))); 64 Element result = (Element)mr_.process(mr_message); 65 //return GSHTML.errorPage(GSHTML.htmlSafe(converter_.getString(mr_message)+"<p>"+converter_.getString(result))); 73 Element mr_result = (Element)mr_.process(mr_message); 66 74 67 // create a new Element 68 Element page = doc_.createElement("message"); 75 // add the results to the page 69 76 page.appendChild(doc_.importNode(request, true)); 70 page.appendChild(doc_.importNode(GSXML.getChildByTagName( result, "response"), true));71 //message.appendChild(doc_.importNode(GSXML.getChildByTagName(result, "response"), true));77 page.appendChild(doc_.importNode(GSXML.getChildByTagName(mr_result, "response"), true)); 78 72 79 73 80 String transformed_result = transformer_.transform(stylesheet, page); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java
r3344 r3363 18 18 protected ConfigVars config_=null; 19 19 20 /** the cgi args converter */ 21 protected CGIArgConverter cgi_=null; 22 20 23 /** container Document to create XML Nodes */ 21 24 protected Document doc_=null; … … 29 32 protected HashMap action_map_=null; 30 33 34 protected Translate translation_=null; 31 35 public Receptionist() { 32 36 converter_ = new XMLConverter(); 33 37 doc_ = converter_.newDOM(); 34 38 action_map_= new HashMap(); 39 translation_ = new Translate(); 40 cgi_ = new CGIArgConverter(); 35 41 } 36 42 … … 38 44 public void setConfigVars(ConfigVars config) { 39 45 config_ = config; 46 translation_.setConfigVars(config); 40 47 } 41 48 /** sets the message router - it should already be created and … … 56 63 } 57 64 65 // for now, assume default is en, so load that 66 translation_.setDefaultLanguage("en"); 58 67 // for now, just statically add in the actions 59 68 // actions may disappear if xslt is all that is needed … … 62 71 a.setConfigVars(config_); 63 72 a.setMessageRouter(mr_); 73 a.setCGIConverter(cgi_); 64 74 a.configure(); 65 75 action_map_.put("p", a); … … 67 77 a = new QueryAction(); 68 78 a.setConfigVars(config_); 79 a.setCGIConverter(cgi_); 69 80 a.setMessageRouter(mr_); 70 81 a.configure(); … … 73 84 a = new BrowseAction(); 74 85 a.setConfigVars(config_); 86 a.setCGIConverter(cgi_); 75 87 a.setMessageRouter(mr_); 76 88 a.configure(); … … 79 91 a = new ResourceAction(); 80 92 a.setConfigVars(config_); 93 a.setCGIConverter(cgi_); 81 94 a.setMessageRouter(mr_); 82 95 a.configure(); … … 87 100 public String process(String xml_in) { 88 101 89 Element message = converter_.getDOM(xml_in).getDocumentElement(); 102 Document message_doc = converter_.getDOM(xml_in); 103 Element message = message_doc.getDocumentElement(); 104 90 105 NodeList requests = message.getElementsByTagName("request"); 91 106 if (requests.getLength()==0) { … … 106 121 // pass to appropriate action 107 122 108 ModuleInterface mi = (ModuleInterface)action_map_.get(action);109 if ( mi==null) {123 Action a = (Action)action_map_.get(action); 124 if (a==null) { 110 125 return GSHTML.errorPage("no action for "+action); 111 126 } 127 128 // add in the translation bit - should we do it here? or give the actions access to the translation object? 129 String lang = message.getAttribute("lang"); 130 Element trans = translation_.getLanguageTree(lang); 131 message.appendChild(message_doc.importNode(trans, true)); 132 133 // add in the system vars bit 134 message.appendChild(message_doc.importNode(config_.config_xml_, true)); 135 136 System.out.println("message at receptionist is:"); 137 System.out.println(converter_.getString(message)); 138 String page = a.process(message); 139 return page; 112 140 // just pass a string for now - better to pass the doc cos already 113 141 // parsed it, but we want a string back 114 String page = mi.process(xml_in);142 //String page = mi.process(xml_in); 115 143 116 144 // output the page 117 return page;145 //return page; 118 146 } 119 147 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MGPPGDBMService.java
r3343 r3363 81 81 82 82 System.out.println("configuring MGPPGDBMService"); 83 default_index_="tt"; 83 System.out.println("config info="); 84 System.out.println(converter_.getString(info)); 85 // get the default index out of metadata 86 NodeList metadata = info.getElementsByTagName("metadata"); 87 String name=null; 88 for(int i=0; i<metadata.getLength(); i++) { 89 Element e = (Element)metadata.item(i); 90 name = e.getAttribute("name"); 91 if (name.equals("defaultIndex")) { 92 default_index_ = GSXML.getValue(e); 93 break; 94 } 95 } 96 System.out.println("default index="+default_index_); 84 97 Element e = null; 85 98 // these entries should reflect the build config file - some services may not be available depending on how the collection was built. … … 107 120 // set up service_info_map_ - for now, just has the same elements as above 108 121 // should have full details about each service incl params lists etc. 122 // do the text query one - for now a static list. later use buildcfg.xml values to dynamically change this 109 123 e = doc_.createElement("service"); 110 124 e.setAttribute("type", "query"); 111 125 e.setAttribute("name", "TextQuery"); 126 Element paramList = doc_.createElement("paramList"); 127 // boolean params 128 Element param = GSXML.createParameter(doc_, "case", GSXML.PARAM_TYPE_BOOLEAN, "1", null); 129 paramList.appendChild(param); 130 param = GSXML.createParameter(doc_, "stem", GSXML.PARAM_TYPE_BOOLEAN, "1", null); 131 paramList.appendChild(param); 132 // enum params 133 String []vals = {"all", "some"}; 134 param = GSXML.createParameter(doc_, "matchMode", GSXML.PARAM_TYPE_ENUM, "all", vals); 135 paramList.appendChild(param); 136 String [] vals1 = {"rank", "natural"}; 137 param = GSXML.createParameter(doc_, "sortBy", GSXML.PARAM_TYPE_ENUM, "rank", vals1 ); 138 paramList.appendChild(param); 139 String [] vals2 = {"Document", "Section"}; 140 param = GSXML.createParameter(doc_, "queryLevel", GSXML.PARAM_TYPE_ENUM, "Section", vals2); 141 paramList.appendChild(param); 142 // Integer params 143 param = GSXML.createParameter(doc_, "maxDocs", GSXML.PARAM_TYPE_INTEGER, "10", null); 144 paramList.appendChild(param); 145 146 147 e.appendChild(paramList); 148 112 149 service_info_map_.put("TextQuery", e); 113 150 151 114 152 e = doc_.createElement("service"); 115 153 e.setAttribute("type", "query"); … … 173 211 174 212 HashMap params = GSXML.extractParams(param_elem); 175 String index = (String)params.get("Index"); // we must have an index elem213 String index = (String)params.get("Index"); 176 214 if (index==null) { // if its not present, use the default index 177 215 index=default_index_; … … 289 327 for (int j=0; j<ids.length; j++) { 290 328 long real_num = gdbm_src_.oid2Docnum(ids[j]); 329 System.out.println("getting doc text, basedir="+basedir+", textdir="+textdir+", level="+level+", num="+real_num); 291 330 String document = mgpp_src_.getDocument(basedir, textdir, level, real_num); 292 331 // for now, stick it in a text node - eventually should be parsed as xml?? 332 333 // something funny with the doc - 293 334 Element new_doc = GSXML.createResourceElement(doc_, ids[j]); 294 335 GSXML.addDocText(doc_, new_doc, document); … … 365 406 366 407 if (name.equals("case")) { 367 boolean val = (value.equals(" true")?true:false);408 boolean val = (value.equals("1")?true:false); 368 409 mgpp_src_.setCase(val); 369 410 } else if (name.equals("stem")) { 370 boolean val = (value.equals(" true")?true:false);411 boolean val = (value.equals("1")?true:false); 371 412 mgpp_src_.setStem(val); 372 413 } else if (name.equals("maxDocs")) { … … 378 419 mgpp_src_.setReturnLevel(value); 379 420 } else if (name.equals("matchMode")) { 380 int mode = Integer.parseInt(value); 421 int mode; 422 if (value.equals("all")) mode=1; 423 else mode=0; 381 424 mgpp_src_.setMatchMode(mode); 382 } else if (name.equals("sortByRank")) { 383 boolean val = (value.equals("true")?true:false); 384 mgpp_src_.setSortByRank(val); 425 } else if (name.equals("sortBy")) { 426 if (value.equals("rank")) { 427 mgpp_src_.setSortByRank(true); 428 } else if (value.equals("natural")) { 429 mgpp_src_.setSortByRank(false); 430 } 385 431 } else if (name.equals("termInfo")) { 386 boolean val = (value.equals(" true")?true:false);432 boolean val = (value.equals("1")?true:false); 387 433 mgpp_src_.setReturnTerms(val); 388 434 } // ignore any others -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/PhindService.java
r3342 r3363 72 72 f.setAttribute("type", "query"); 73 73 f.setAttribute("name", "PhindBrowse"); 74 75 // add in teh applet info for the phind applet 76 String app_info = "<APPLET CODEBASE='/gsdl/bin/java' CODE='org.greenstone.gsdl3.applet.Phind.class' ARCHIVE='Phind.jar' WIDTH=500 HEIGHT=400> 77 <PARAM NAME=library VALUE='/cgi-bin/library?e=d-000-00---0fi1998--00-0-0-0prompt-10---4---Document-dtx--0-1l--0-en-50---20-preferences-the--001-011-1-0isoZz-8859Zz-1-0'> 78 <PARAM NAME=phindcgi VALUE='library?a=browse/phind'> 79 <PARAM NAME=collection VALUE='fi1998'> 80 <PARAM NAME=classifier VALUE='1'> 81 82 <PARAM NAME=orientation VALUE='vertical'> 83 <PARAM NAME=depth VALUE='2'> 84 <PARAM NAME=resultorder VALUE='L,l,E,e,D,d'> 85 86 <PARAM NAME=backdrop VALUE='interfaces/default/images/phindbg1.jpg'> 87 <PARAM NAME=fontsize VALUE='10'> 88 <PARAM NAME=blocksize VALUE='10'> 89 90 The Phind java applet. 91 </APPLET>"; 92 74 93 service_info_map_.put("PhindBrowse", f); 75 94 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceModule.java
r3235 r3363 207 207 String info = request.getAttribute("info"); 208 208 if (type.equals("describe")) { // process here, not by subclass 209 Element response = doc_.createElement("response"); 210 response.setAttribute("type", "describe"); 209 211 if (to.equals("")) { // to="", look at info 210 212 if (info.equals("serviceList")) { 211 return short_service_info_; 213 response.appendChild(short_service_info_); 214 return response; 212 215 } 213 216 // else error in info field … … 216 219 } else { // describe a particular service 217 220 if (service_info_map_.containsKey(to)) { 218 return (Element)service_info_map_.get(to); 221 response.appendChild((Element)service_info_map_.get(to)); 222 return response; 219 223 } 220 224 // else error in to field
Note:
See TracChangeset
for help on using the changeset viewer.