Changeset 3568
- Timestamp:
- 2002-11-26T13:55:24+13:00 (21 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/action
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/Action.java
r3363 r3568 8 8 import org.w3c.dom.Document; 9 9 10 /** base class for Actions */ 10 11 abstract public class Action { 11 12 13 /** the interface setup variables */ 12 14 protected ConfigVars config_=null; 13 14 15 /** container Document to create XML Nodes */ 15 16 protected Document doc_=null; 16 17 /** a converter class to parse XML and create Docs */ 17 18 protected XMLConverter converter_=null; 18 /** cgi args conve ter */19 /** cgi args converter */ 19 20 protected CGIArgConverter cgi_=null; 20 21 /** a transformer class to transform xml using xslt */ … … 55 56 Element message = converter_.getDOM(xml_in).getDocumentElement(); 56 57 57 return process(message); 58 Element result = process(message); 59 return converter_.getString(result); 58 60 } 59 61 60 abstract public Stringprocess(Element xml_in);62 abstract public Element process(Element xml_in); 61 63 62 64 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/AppletAction.java
r3512 r3568 12 12 import java.io.File; 13 13 14 /** action class for handling applets */ 14 15 public class AppletAction extends Action { 15 16 16 17 17 public Stringprocess (Element message) {18 18 public Element process (Element message) { 19 19 20 20 21 // find the stylesheet … … 22 23 23 24 if (stylesheet==null) { 24 return GSHTML.errorPage("applet stylesheet not found!"); 25 System.err.println("AppletAction Error: applet stylesheet not found!"); 26 return null; 25 27 } 26 27 Element request = (Element) message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);28 29 // subaction is display /request30 String request_type = request.getAttribute(GSXML.SUBACTION_ATT); // should be 'd' or 'r'28 29 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 30 31 // subaction is display (d) or request (r) 32 String request_type = request.getAttribute(GSXML.SUBACTION_ATT); 31 33 if (!request_type.equals("d")&&!request_type.equals("r")) { 32 return GSHTML.errorPage("the sa arg to a=a should be d or r!!"); 34 System.err.println("AppletAction Error: the sa arg should be either d or r, instead it was "+request_type+"!"); 35 return null; 33 36 } 34 37 35 38 // get the collection and service param 36 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 37 cgi_.toLong(cgi_paramList); 38 HashMap params = GSXML.extractParams(cgi_paramList); 39 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 40 HashMap params = GSXML.extractParams(cgi_param_list); 39 41 40 42 String collection = (String)params.get("collection"); … … 49 51 } 50 52 51 System.out.println("to="+to);52 53 54 53 if (request_type.equals("d")) { 55 54 // we are just displaying the applet - get the description from … … 62 61 mr_message.appendChild(mr_request); 63 62 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 63 mr_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 64 64 mr_request.setAttribute(GSXML.TO_ATT, to); 65 //mr_request.setAttribute(GSXML."info", "appletInfo");66 65 67 66 Element mr_response = (Element)mr_.process(mr_message); 68 67 69 System.out.println("applet mr response =");70 System.out.println(converter_.getString(mr_response));71 68 // create the return page tree 72 69 Element page = doc_.createElement(GSXML.PAGE_ELEM); 73 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));70 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 74 71 // add the lang stuff from message 75 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));72 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 76 73 // add the config stuff from message 77 74 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); … … 92 89 Document style_doc = converter_.getDOM(new File(stylesheet)); 93 90 GSXSLT.absoluteIncludePaths(style_doc, config_); 94 return transformer_.transform(style_doc, page);91 return (Element)transformer_.transform(style_doc, page); 95 92 96 93 } … … 103 100 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 104 101 mr_request.setAttribute(GSXML.TO_ATT, to); 105 102 mr_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 103 106 104 // just append the params for now 107 mr_request.appendChild(doc_.importNode(cgi_param List, true));105 mr_request.appendChild(doc_.importNode(cgi_param_list, true)); 108 106 109 107 Element mr_response = (Element)mr_.process(mr_message); 110 System.out.println("applet query response:");111 // dont need to create a page, just extract the info out.112 System.out.println(converter_.getString(mr_response));113 108 // add in the applet data 114 109 String path = GSXML.RESPONSE_ELEM; 115 110 path = GSPath.appendLink(path, GSXML.APPLET_DATA_ELEM); 116 111 Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild(); 117 System.out.println("applet action: applet data ="); 118 System.out.println(converter_.getString(applet_info)); 119 return converter_.getString(applet_info); 112 return applet_info; 120 113 121 114 } 122 else { 123 // should never get here 124 return GSHTML.errorPage("applet action, wrong subaction type"); 125 } 115 // should never get here 116 return null; 126 117 } 127 118 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java
r3512 r3568 10 10 import java.util.HashMap; 11 11 import java.io.File; 12 13 /** action for classifier browsing */ 12 14 public class BrowseAction extends Action { 13 15 16 public Element process (Element message) { 14 17 15 public String process (Element message) { 16 18 // get the request - assume only one 19 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 20 17 21 // create the return page tree 18 22 Element page = doc_.createElement(GSXML.PAGE_ELEM); 19 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));23 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 20 24 // add the lang stuff from message 21 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));25 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 22 26 // add the system stuff from message 23 27 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 24 28 25 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);26 29 27 30 // the browse type is the subaction … … 37 40 38 41 39 protected StringclassifierBrowse(Element page, Element request) {42 protected Element classifierBrowse(Element page, Element request) { 40 43 41 44 // check 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 42 45 String stylesheet = GSFile.stylesheetFile(config_, "classifier.xsl"); 43 46 if (stylesheet==null) { 44 return GSHTML.errorPage("classifier stylesheet not found!"); 47 System.err.println("BrowseAction Error: classifier stylesheet not found!"); 48 return null; 45 49 } 46 50 Document style_doc = converter_.getDOM(new File(stylesheet)); … … 54 58 String collection = (String)params.get("collection"); 55 59 if (collection == null || collection.equals("")) { 56 return GSHTML.errorPage("classifierbrowse, need to specify a collection!"); 60 System.err.println("BrowseAction Error:classifierbrowse, need to specify a collection!"); 61 return null; 62 57 63 } 58 64 59 // the first part of the data for the page is the cgi-params60 Element cgi_request = (Element)doc_.importNode(request, true);61 page.appendChild(cgi_request);62 65 63 // 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 query66 // get the service info from the MR - this will probably need to be cached somehow later on. 64 67 65 68 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM); … … 67 70 mr_info_message.appendChild(mr_info_request); 68 71 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 72 mr_info_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 69 73 70 74 String to = collection; … … 73 77 74 78 Element mr_info_response = (Element) mr_.process(mr_info_message); 75 Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM);76 79 77 80 String path = GSXML.RESPONSE_ELEM; 78 81 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 79 path = GSPath.appendLink(path, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);80 Node cl = GSXML.getNodeByPath(mr_info_response, path);81 82 82 Element imported_classList = (Element)doc_.importNode(cl, true); 83 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 84 85 // the first part of the data for the page is the cgi-params 86 Element cgi_request = (Element)doc_.importNode(request, true); 87 page.appendChild(cgi_request); 83 88 84 description.appendChild(imported_classList); 85 cgi_request.appendChild(description); 86 87 89 page.appendChild(description); 90 88 91 // if there is a cl field in the cgi params, get the classifier info 89 92 String node = (String)params.get("classifier"); 93 94 if (node!=null && !node.equals("")) { 90 95 91 if (node==null|| node.equals("")) { 92 System.out.println("no cl node selected"); 93 // if there is no cl set, just output the list 94 GSXSLT.absoluteIncludePaths(style_doc, config_); 95 return transformer_.transform(style_doc, page); 96 // get the info for the selected node 97 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 98 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 99 mr_query_message.appendChild(mr_query_request); 100 101 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 102 mr_query_request.setAttribute(GSXML.TO_ATT, to); 103 mr_query_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 104 105 106 // paramList - empty for now 107 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 108 mr_query_request.appendChild(paramList); 109 110 111 // content - contains the classifier node, may be more than one 112 // call this resource list for now 113 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM); 114 mr_query_request.appendChild(query_content); 115 116 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 117 Element resource = doc_.createElement(GSXML.RESOURCE_ELEM); 118 resource.setAttribute(GSXML.NAME_ATT, node); 119 resource_list.appendChild(resource); 120 query_content.appendChild(resource_list); 121 122 Element mr_query_response = (Element)mr_.process(mr_query_message); 123 124 Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 125 Node new_style = GSXML.getChildByTagName(response, "stylesheet"); 126 if (new_style !=null) { 127 GSXSLT.mergeStylesheets(style_doc, (Element)new_style); 128 response.removeChild(new_style); 129 } 130 // add the response to the page data 131 page.appendChild(doc_.importNode(response, true)); 132 96 133 } 97 134 98 // get the info for the selected node99 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);100 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);101 mr_query_message.appendChild(mr_query_request);102 103 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);104 mr_query_request.setAttribute(GSXML.TO_ATT, to);105 106 // paramList - empty for now107 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);108 mr_query_request.appendChild(paramList);109 110 111 // content - contains the classifier node, may be more than one112 // call this resource list for now113 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM);114 mr_query_request.appendChild(query_content);115 116 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);117 Element resource = doc_.createElement(GSXML.RESOURCE_ELEM);118 resource.setAttribute(GSXML.NAME_ATT, node);119 resource_list.appendChild(resource);120 query_content.appendChild(resource_list);121 122 Element mr_query_response = (Element)mr_.process(mr_query_message);123 124 Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);125 Node new_style = GSXML.getChildByTagName(response, "stylesheet");126 if (new_style !=null) {127 GSXSLT.mergeStylesheets(style_doc, (Element)new_style);128 response.removeChild(new_style);129 }130 // add the response to the page data131 page.appendChild(doc_.importNode(response, true));132 133 135 GSXSLT.absoluteIncludePaths(style_doc, config_); 134 return transformer_.transform(style_doc, page);136 return (Element)transformer_.transform(style_doc, page); 135 137 } 136 138 137 protected StringunknownBrowse(Element page, Element request, String browse_type) {138 139 return GSHTML.errorPage("unknown browse subtype: "+browse_type);139 protected Element unknownBrowse(Element page, Element request, String browse_type) { 140 System.err.println("BrowseAction Error: unknown browse subtype: "+browse_type); 141 return null; 140 142 } 141 143 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BuildAction.java
r3513 r3568 17 17 18 18 19 public Stringprocess (Element message) {19 public Element process (Element message) { 20 20 21 //find the stylesheet 21 //find the stylesheet - cant go any further if not found 22 22 String stylesheet = GSFile.stylesheetFile(config_, "build.xsl"); 23 23 24 24 if (stylesheet==null) { 25 return GSHTML.errorPage("build stylesheet not found!"); 25 System.err.println("BuildAction Error: build stylesheet not found!"); 26 return null; 26 27 } 28 29 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 30 String service_name = request.getAttribute(GSXML.SUBACTION_ATT); 31 // get the param list 32 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 33 HashMap params = GSXML.extractParams(cgi_param_list); 27 34 28 35 // create the return page tree 29 36 Element page = doc_.createElement(GSXML.PAGE_ELEM); 30 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));37 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 31 38 // add the lang stuff from message 32 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));39 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 33 40 // add the system stuff from message 34 41 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 42 35 43 36 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 37 String service_name = request.getAttribute(GSXML.SUBACTION_ATT); 44 // we need to do the request before getting the description- 45 // it may have changedthe action may change the descripiton, eg 46 // deleting a collection changes the collection list 47 String collection = (String)params.get("collection"); 48 String to = "build"; // knwo this cos its build action - loaded by a cluster called build 49 to = GSPath.appendLink(to, service_name); 38 50 39 // get the param list 40 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 41 cgi_.toLong(cgi_paramList); 42 HashMap params = GSXML.extractParams(cgi_paramList); 51 if (collection != null && !collection.equals("")) { 52 53 // a collection has been specified - do the request 54 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 55 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 56 mr_query_message.appendChild(mr_query_request); 57 58 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_BUILD); 59 mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 60 61 mr_query_request.setAttribute(GSXML.TO_ATT, to); 62 63 // paramList 64 Element query_param_list = (Element) doc_.importNode(cgi_param_list, true); 65 mr_query_request.appendChild(query_param_list); 66 67 Element mr_query_response = (Element)mr_.process(mr_query_message); 68 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 69 // append the response to the page 70 page.appendChild(doc_.importNode(result_response, true)); 71 } 43 72 44 // the first part of the data for the page is the cgi-params 45 Element cgi_request = (Element)doc_.importNode(request, true); 46 page.appendChild(cgi_request); 73 // another part of the page is the service description 47 74 48 // the second part of the page is the param list for the service 49 // request the service info for the selected service - should be cached? 50 75 // request the service info for the selected service - should be cached 51 76 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM); 52 77 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM); 53 78 mr_info_message.appendChild(mr_info_request); 54 79 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 80 mr_info_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 55 81 56 String to = "build"; // knwo this cos its build action - loaded by a cluster called build57 to = GSPath.appendLink(to, service_name);58 82 mr_info_request.setAttribute(GSXML.TO_ATT, to); 59 83 60 84 Element mr_info_response = (Element) mr_.process(mr_info_message); 61 System.err.println("describe response for service");62 System.err.println(converter_.getString(mr_info_response));63 Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM);64 // just param list for now - may need content info too65 85 66 86 String path = GSXML.RESPONSE_ELEM; 67 87 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 68 path = GSPath.appendLink(path, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);88 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 69 89 70 Node pl = GSXML.getNodeByPath(mr_info_response, path); 71 if (pl ==null) { 72 System.out.println("pl is null"); 73 } 74 else { 75 System.out.println("pl name is "+pl.getNodeName()); 76 } 77 Element imported_paramList = (Element)doc_.importNode(pl, true); 78 // convert the name to short 79 cgi_.addShortNames(imported_paramList); 90 Element pl = (Element)GSXML.getChildByTagName(description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 91 92 if (pl !=null) { 93 // add short names to the params in the param list 94 cgi_.addShortNames(pl); 80 95 81 description.appendChild(imported_paramList); 82 83 // for each param in page_request, set the current value if present 84 //actually, prob dont need to know the default value, just which one to display - overwrite the default att? 85 86 Element param = (Element)imported_paramList.getFirstChild(); 87 while (param !=null) { 88 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case 89 String name = param.getAttribute(GSXML.NAME_ATT); 90 String current = (String)params.get(name); 91 if (current !=null && !current.equals("")) { 92 param.setAttribute(GSXML.DEFAULT_ATT, current); 96 // for each param in the description, overwrite teh default value with the currently set value if present 97 Element param = (Element)pl.getFirstChild(); 98 while (param !=null) { 99 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case 100 String name = param.getAttribute(GSXML.NAME_ATT); 101 String current = (String)params.get(name); 102 if (current !=null && !current.equals("")) { 103 param.setAttribute(GSXML.DEFAULT_ATT, current); 104 } 93 105 } 94 } 95 param = (Element)param.getNextSibling(); 96 } 97 98 cgi_request.appendChild(description); 99 100 // now see if we need to actually do anything - only if a colleciton has been set 101 String collection = (String)params.get("collection"); 102 if (collection == null || collection.equals("")) { 103 // no coll set - just output the form 104 105 Document style_doc = converter_.getDOM(new File(stylesheet)); 106 GSXSLT.absoluteIncludePaths(style_doc, config_); 107 return transformer_.transform(style_doc, page); 108 } 109 110 // else do the request, output search box and results 111 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 112 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 113 mr_query_message.appendChild(mr_query_request); 114 115 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_BUILD); 116 mr_query_request.setAttribute(GSXML.TO_ATT, to); 117 118 // paramList 119 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 120 mr_query_request.appendChild(paramList); 121 122 Iterator i = params.entrySet().iterator(); 123 while (i.hasNext()) { 124 Map.Entry e = (Map.Entry)i.next(); 125 String name = cgi_.toLong((String)e.getKey()); 126 if (!name.equals("")) { 127 String value = (String)e.getValue(); 128 // if (!name.equals("c")) { 129 Element p = doc_.createElement(GSXML.PARAM_ELEM); 130 p.setAttribute(GSXML.NAME_ATT, name); 131 p.setAttribute(GSXML.VALUE_ATT, value); 132 paramList.appendChild(p); 133 // } 106 param = (Element)param.getNextSibling(); 134 107 } 135 108 } 109 page.appendChild(description); 110 111 // part of the data for the page is the cgi-params 112 // if we have this here, do we need to do the previous step? 113 Element cgi_request = (Element)doc_.importNode(request, true); 114 page.appendChild(cgi_request); 136 115 137 Element mr_query_response = (Element)mr_.process(mr_query_message);138 116 139 // this result is a message 140 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 141 page.appendChild(doc_.importNode(result_response, true)); 142 117 // now process the page and return the result 143 118 Document style_doc = converter_.getDOM(new File(stylesheet)); 144 119 145 120 GSXSLT.absoluteIncludePaths(style_doc, config_); 146 return transformer_.transform(style_doc, page);121 return (Element)transformer_.transform(style_doc, page); 147 122 } 148 123 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java
r3512 r3568 14 14 public class PageAction extends Action { 15 15 16 public Stringprocess (Element message) {16 public Element process (Element message) { 17 17 18 Element request = (Element) message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);18 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 19 19 // the page name is the subaction 20 20 String page_name = request.getAttribute(GSXML.SUBACTION_ATT); 21 21 if (page_name.equals("")) { // if no page specified, assume home page 22 page_name = "home"; 23 } 24 22 25 // create the return page tree 23 26 Element page = doc_.createElement(GSXML.PAGE_ELEM); 24 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));25 // add the lang stuff from xml_in26 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));27 // add the system stuff from xml_in27 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 28 // add the lang stuff from message 29 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 30 // add the system stuff from message 28 31 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 29 30 if (page_name.equals("")) { 31 // for now send an error. change to always display the home page? 32 return GSHTML.errorPage(" page action specified, but no page specified"); 33 } 32 34 33 if (page_name.equals("home")) { 35 34 return homePage(page, request); … … 37 36 return aboutPage(page, request); 38 37 } else { 39 return GSHTML.errorPage("page: "+page_name+" not yet implemented"); 38 System.err.println("PageAction Error: unimplemented page specified!"); 39 return null; 40 40 } 41 41 } 42 43 44 protected String homePage(Element page, Element orig_message) { 42 43 protected Element homePage(Element page, Element orig_message) { 45 44 46 // first, get the list of collections from mr 47 45 // first, get the message router info 48 46 Element coll_list_message = doc_.createElement(GSXML.MESSAGE_ELEM); 49 coll_list_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));50 47 Element coll_list_request = doc_.createElement(GSXML.REQUEST_ELEM); 51 48 coll_list_message.appendChild(coll_list_request); 52 49 coll_list_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 53 //coll_list_request.setAttribute("info", "collectionList");54 50 coll_list_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 51 System.out.println("PageAction: getting mesage router description."); 55 52 Element coll_list_response = (Element)mr_.process(coll_list_message); 56 53 if (coll_list_response==null) { 57 return GSHTML.errorPage("couldn't query the mr about collections"); 54 System.err.println("PageAction Error: couldn't query the message router!"); 55 return null; 58 56 } 59 57 60 // second, get the metadata for each collection 58 // second, get the metadata for each collection - we only want specific 59 // elements but for now, we'll just get it all 61 60 NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM); 62 63 //Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 64 //metadata_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 65 //Element metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 66 //metadata_message.appendChild(metadata_request); 67 //metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 61 // we will send all the requests in a single message 62 Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 68 63 for (int i=0; i<colls.getLength(); i++) { 69 Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);70 metadata_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));71 64 Element metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 65 metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 66 metadata_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 67 Element c = (Element)colls.item(i); 68 String name = c.getAttribute(GSXML.NAME_ATT); 69 metadata_request.setAttribute(GSXML.TO_ATT, name); // overwrites the old value 70 // add this request to the message 72 71 metadata_message.appendChild(metadata_request); 73 metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 74 75 // get the metadata for each one 76 Element c = (Element)colls.item(i); 77 String name = c.getAttribute(GSXML.NAME_ATT); 78 System.out.println("getting metadata for coll "+name); 79 80 metadata_request.setAttribute(GSXML.TO_ATT, name); // overwrites the old value 81 System.out.println("metadata message = \n"+converter_.getString(metadata_message)); 82 Element metadata_response = (Element)mr_.process(metadata_message); 83 Element coll = (Element)metadata_response.getElementsByTagName(GSXML.COLLECTION_ELEM).item(0); 84 if (coll==null) { 85 System.out.println("coll is null, in \n"+converter_.getString(metadata_response)); 72 } 73 System.out.println("PageAction: getting metadata for each collection."); 74 Element metadata_response = (Element)mr_.process(metadata_message); 75 76 NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.COLLECTION_ELEM); 77 // check that have same number of responses as collections 78 if (colls.getLength() != coll_responses.getLength()) { 79 System.err.println("PageAction Error: didn't get a response for each collection - somethings gone wrong!"); 80 // for now, dont use the metadata 81 } else { 82 for (int i=0; i<colls.getLength(); i++) { 83 Element c1 = (Element)colls.item(i); 84 Element c2 = (Element)coll_responses.item(i); 85 if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) { 86 // add the metadata to the original response 87 GSXML.mergeMetadataLists(c1, c2); // add the metadata to the original response 88 } else { 89 System.err.println("PageAction Error: response does not correspond to request!"); 90 } 91 86 92 } 87 GSXML.mergeMetadataLists(c, coll); // add the metadata to the original response88 93 } 89 94 … … 96 101 Document style_doc = converter_.getDOM(new File(stylesheet)); 97 102 GSXSLT.absoluteIncludePaths(style_doc, config_); 98 //System.out.println("page="); 99 //System.out.println(converter_.getString(page)); 100 return transformer_.transform(style_doc, page); 103 return (Element)transformer_.transform(style_doc, page); 101 104 102 103 105 } // homePage 104 106 105 protected StringaboutPage(Element page, Element request) {107 protected Element aboutPage(Element page, Element request) { 106 108 107 109 // extract the params from the cgi-request, 108 // first convert short to long names109 110 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 110 cgi_.toLong(cgi_paramList);111 111 HashMap params = GSXML.extractParams(cgi_paramList); 112 112 … … 116 116 } 117 117 if (coll_name == null || coll_name.equals("")) { 118 return GSHTML.errorPage("about page - need to specify coll name or cluster name"); 118 System.err.println("PageAction Error: about page requested with no collection or cluster specified!"); 119 return null; 119 120 } 120 121 122 // get the collection or cluster description 121 123 Element coll_about_message = doc_.createElement(GSXML.MESSAGE_ELEM); 122 coll_about_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));123 124 124 Element coll_about_request = doc_.createElement(GSXML.REQUEST_ELEM); 125 125 coll_about_message.appendChild(coll_about_request); 126 126 coll_about_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 127 127 coll_about_request.setAttribute(GSXML.TO_ATT, coll_name); 128 128 coll_about_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 129 129 130 Element coll_about_response = (Element)mr_.process(coll_about_message); 130 131 131 // System.out.println("coll response=");132 //System.out.println(converter_.getString(coll_about_response));133 132 // add the response to the page 134 133 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM), true)); … … 138 137 Document style_doc = converter_.getDOM(new File(stylesheet)); 139 138 GSXSLT.absoluteIncludePaths(style_doc, config_); 140 return transformer_.transform(style_doc, page);139 return (Element)transformer_.transform(style_doc, page); 141 140 142 141 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java
r3512 r3568 5 5 // XML classes 6 6 import org.w3c.dom.Node; 7 import org.w3c.dom.NodeList; 7 8 import org.w3c.dom.Text; 8 9 import org.w3c.dom.Document; … … 11 12 import java.util.HashMap; 12 13 import java.util.Map; 13 //import java.util.Map;14 14 import java.util.Iterator; 15 15 import java.io.File; 16 16 17 /** action class for queries */ 17 18 public class QueryAction extends Action { 18 19 19 20 public String process (Element message) { 21 20 public Element process (Element message) { 21 22 // get the request - assume there is only one 23 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 22 24 23 25 // create the return page tree 24 26 Element page = doc_.createElement(GSXML.PAGE_ELEM); 25 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));27 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 26 28 // add the lang stuff from message 27 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));29 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 28 30 // add the system stuff from message 29 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 30 31 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 31 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 32 32 33 // query type is teh subaction 33 34 String query_type = request.getAttribute(GSXML.SUBACTION_ATT); … … 49 50 50 51 // we may be able to generalize this for all query types? 51 protected StringtextQuery(Element page, Element request) {52 53 // ch ack 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 MR52 protected Element textQuery(Element page, Element request) { 53 54 // check 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 54 55 String stylesheet = GSFile.stylesheetFile(config_, "textquery.xsl"); 55 56 if (stylesheet==null) { 56 return GSHTML.errorPage("textquery stylesheet not found!"); 57 System.err.println("QueryAction Error: textquery stylesheet not found!"); 58 return null; 57 59 } 58 60 59 61 // extract the params from the cgi-request, and check that we have a coll specified 60 // first convert short to long names 61 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 62 cgi_.toLong(cgi_paramList); 63 HashMap params = GSXML.extractParams(cgi_paramList); 62 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 63 HashMap params = GSXML.extractParams(cgi_param_list); 64 64 65 65 String collection = (String)params.get("collection"); 66 66 if (collection == null || collection.equals("")) { 67 return GSHTML.errorPage("textquery, need to specify a colleciton!"); 68 } 69 70 // the first part of the data for the page is the cgi-params 71 Element cgi_request = (Element)doc_.importNode(request, true); 72 page.appendChild(cgi_request); 73 74 // 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 75 67 System.err.println("QueryAction Error: no colleciton was specified!"); 68 return null; 69 } 70 71 // get the service info from the MR - this will probably need to be cached somehow later on. and add the service node to the page 76 72 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM); 77 73 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM); 78 74 mr_info_message.appendChild(mr_info_request); 79 75 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 76 mr_info_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 80 77 81 78 String to = collection; … … 84 81 85 82 Element mr_info_response = (Element) mr_.process(mr_info_message); 86 System.err.println("describe response for service"); 87 System.err.println(converter_.getString(mr_info_response)); 88 Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM); 89 // just param list for now - may need content info too 83 90 84 String path = GSXML.RESPONSE_ELEM; 91 85 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 92 path = GSPath.appendLink(path, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 93 Node pl = GSXML.getNodeByPath(mr_info_response, path); 94 if (pl ==null) { 95 System.out.println("pl is null"); 96 } 97 else { 98 System.out.println("pl name is "+pl.getNodeName()); 99 100 Element imported_paramList = (Element)doc_.importNode(pl, true); 101 // convert the name to short 102 cgi_.addShortNames(imported_paramList); 103 104 description.appendChild(imported_paramList); 105 106 // for each param in page_request, set the current value if present 107 //actually, prob dont need to know the default value, just which one to display - overwrite the default att? 108 109 Element param = (Element)imported_paramList.getFirstChild(); 86 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 87 Element pl = (Element)GSXML.getChildByTagName(description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 88 89 if (pl !=null) { 90 // add short names to the params in the param list 91 cgi_.addShortNames(pl); 92 93 // for each param in the description, overwrite teh default value with the currently set value if present 94 Element param = (Element)pl.getFirstChild(); 110 95 while (param !=null) { 111 96 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case … … 119 104 } 120 105 } 121 cgi_request.appendChild(description); 106 107 // part of the data for the description is the cgi-params 108 // if we have this here, do we need to do the previous step? 109 Element cgi_request = (Element)doc_.importNode(request, true); 110 page.appendChild(cgi_request); 111 112 page.appendChild(description); 122 113 123 114 // check the query string 124 115 String query = (String)params.get(GSXML.REQUEST_TYPE_QUERY); 125 116 126 if (query==null|| query.equals("")) { 127 // if there is no q set, just output the search form 128 129 Document style_doc = converter_.getDOM(new File(stylesheet)); 130 GSXSLT.absoluteIncludePaths(style_doc, config_); 131 return transformer_.transform(style_doc, page); 132 } 133 134 // else do the request, output search box and results 135 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 136 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 137 mr_query_message.appendChild(mr_query_request); 138 139 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 140 mr_query_request.setAttribute(GSXML.TO_ATT, to); 141 142 // paramList 143 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 144 mr_query_request.appendChild(paramList); 145 146 Iterator i = params.entrySet().iterator(); 147 while (i.hasNext()) { 148 Map.Entry e = (Map.Entry)i.next(); 149 String name = cgi_.toLong((String)e.getKey()); 150 if (!name.equals("")) { 151 String value = (String)e.getValue(); 152 // if (!name.equals("c")) { 153 Element p = doc_.createElement(GSXML.PARAM_ELEM); 154 p.setAttribute(GSXML.NAME_ATT, name); 155 p.setAttribute(GSXML.VALUE_ATT, value); 156 paramList.appendChild(p); 157 // } 117 if (query!=null&& !query.equals("")) { 118 // do the query 119 120 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 121 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 122 mr_query_message.appendChild(mr_query_request); 123 124 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 125 mr_query_request.setAttribute(GSXML.TO_ATT, to); 126 mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 127 // paramList 128 // should we remove the query from the param list? 129 Element query_param_list = (Element)doc_.importNode(cgi_param_list, true); 130 mr_query_request.appendChild(query_param_list); 131 132 // content - contains the query string 133 Element query_content = GSXML.createTextElement(doc_, GSXML.CONTENT_ELEM, query); 134 mr_query_request.appendChild(query_content); 135 136 Element mr_query_response = (Element)mr_.process(mr_query_message); 137 138 // this result is the list of docs. 139 // now take that list, and get the Titles 140 // for now, just create a whole new request 141 142 // check that there are some resources - for now check the list, but later should use a numdocs metadata elem 143 path = GSXML.RESPONSE_ELEM; 144 path = GSPath.appendLink(path, GSXML.CONTENT_ELEM); 145 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 146 147 Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response, 148 path); // resourceList not present if no docs found 149 if (resource_list == null) { 150 151 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 152 153 page.appendChild(doc_.importNode(result_response, true)); 154 155 Document style_doc = converter_.getDOM(new File(stylesheet)); 156 GSXSLT.absoluteIncludePaths(style_doc, config_); 157 return (Element)transformer_.transform(style_doc, page); 158 158 159 } 159 } 160 161 // content - contains the query string 162 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM); 163 Text query_text = doc_.createTextNode(query); 164 query_content.appendChild(query_text); 165 mr_query_request.appendChild(query_content); 166 167 Element mr_query_response = (Element)mr_.process(mr_query_message); 168 169 // this result is the list of docs. 170 // now take that list, and get the Titles 171 // for now, just create a whole new request 172 173 // check that there are some resources - for now check the list, but later should use a numdocs metadata elem 174 path = GSXML.RESPONSE_ELEM; 175 path = GSPath.appendLink(path, GSXML.CONTENT_ELEM); 176 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 177 178 Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response, 179 path); // resourceList not present if no docs found 180 if (resource_list == null) { 181 182 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 160 161 // we have a doc list, so get the metadata - for now, get title. 162 // can we dynamically decide what metadata to get? 163 Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 164 Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 165 mr_metadata_message.appendChild(mr_metadata_request); 166 167 mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 168 mr_metadata_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 169 to = GSPath.appendLink(collection, "MetadataRetrieve"); 170 mr_metadata_request.setAttribute(GSXML.TO_ATT, to); 171 172 Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM); 173 mr_metadata_request.appendChild(meta_content); 174 175 // the first part of the content is the doc list 176 meta_content.appendChild(doc_.importNode(resource_list, true)); 177 178 // the second part of the content is the metadata list 179 Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 180 Element title = doc_.createElement(GSXML.METADATA_ELEM); 181 title.setAttribute(GSXML.NAME_ATT, "Title"); 182 metadata_list.appendChild(title); 183 meta_content.appendChild(metadata_list); 184 185 Element mr_metadata_response = (Element)mr_.process(mr_metadata_message); 186 187 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM); 183 188 184 189 page.appendChild(doc_.importNode(result_response, true)); 185 186 Document style_doc = converter_.getDOM(new File(stylesheet)); 187 GSXSLT.absoluteIncludePaths(style_doc, config_); 188 return transformer_.transform(style_doc, page); 189 190 } 191 192 // we have a doc list, so get the metadata - for now, get title. 193 // can we dynamically decide what metadata to get? 194 // get the Title metadata 195 Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 196 Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 197 mr_metadata_message.appendChild(mr_metadata_request); 198 199 mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 200 to = GSPath.appendLink(collection, "MetadataRetrieve"); 201 mr_metadata_request.setAttribute(GSXML.TO_ATT, to); 202 203 Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM); 204 mr_metadata_request.appendChild(meta_content); 205 206 // the first part of the content is the doc list 207 meta_content.appendChild(doc_.importNode(resource_list, true)); 208 209 // the second part of the content is the metadata list 210 Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 211 Element title = doc_.createElement(GSXML.METADATA_ELEM); 212 title.setAttribute(GSXML.NAME_ATT, "Title"); 213 metadata_list.appendChild(title); 214 meta_content.appendChild(metadata_list); 215 216 Element mr_metadata_response = (Element)mr_.process(mr_metadata_message); 217 218 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM); 219 220 page.appendChild(doc_.importNode(result_response, true)); 221 190 191 } // do teh query 192 193 194 // output the page 222 195 // process using the stylesheet 223 196 Document style_doc = converter_.getDOM(new File(stylesheet)); 224 197 GSXSLT.absoluteIncludePaths(style_doc, config_); 225 return transformer_.transform(style_doc, page); 226 227 } 228 229 protected String fieldQuery(Element page, Element request) { 230 return GSHTML.errorPage("field query not implemented"); 231 232 233 } 234 protected String unknownQuery(Element page, Element request, String query_type) { 235 236 return GSHTML.errorPage("unknown query subtype - "+query_type+" query not implemented"); 198 return (Element)transformer_.transform(style_doc, page); 199 200 } 201 202 protected Element fieldQuery(Element page, Element request) { 203 String p = GSHTML.errorPage("field query not implemented"); 204 205 return converter_.getDOM(p).getDocumentElement(); 206 } 207 protected Element unknownQuery(Element page, Element request, String query_type) { 208 209 String p = GSHTML.errorPage("unknown query subtype - "+query_type+" query not implemented"); 210 return null;//converter_.getDOM(p).getDocumentElement(); 237 211 } 238 212 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ResourceAction.java
r3512 r3568 11 11 import java.io.File; 12 12 13 /** Action class for retrieving Documents or Resources via the message router 14 */ 13 15 public class ResourceAction extends Action { 14 15 16 // could pass in action name, and have it dynamically decide the name 17 18 public String process (Element message) { 19 16 17 public Element process (Element message) { 18 20 19 // find the stylesheet 21 20 String stylesheet = GSFile.stylesheetFile(config_, "resource.xsl"); 22 21 23 22 if (stylesheet==null) { 24 return GSHTML.errorPage("resource stylesheet not found!"); 23 System.err.println("ResourceAction Error: resource stylesheet not found!"); 24 return null; 25 25 } 26 26 27 27 // for now, no subaction eventually we may want to have subactions such as text assoc or something ? 28 28 29 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);30 29 // get the request - assume only one 30 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 31 31 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 32 cgi_.toLong(cgi_paramList);33 32 HashMap params = GSXML.extractParams(cgi_paramList); 34 33 35 34 String resource_name = (String)params.get("resource"); 36 35 if (resource_name == null || resource_name.equals("")) { 37 // no doc to show38 return GSHTML.errorPage("no resource specified");36 System.err.println("ResourceAction Error: no resource specified!"); 37 return null; 39 38 } 40 41 39 42 40 // create the return page tree 43 41 Element page = doc_.createElement(GSXML.PAGE_ELEM); 44 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));42 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 45 43 // add the lang stuff from message 46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));44 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 47 45 // add the config stuff from message 48 46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 49 50 51 47 52 48 // build up the mr request … … 55 51 mr_message.appendChild(mr_request); 56 52 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 53 mr_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 57 54 mr_request.setAttribute("resourceType", "core"); 58 55 String to = (String)params.get("collection"); // collection name … … 82 79 Document style_doc = converter_.getDOM(new File(stylesheet)); 83 80 GSXSLT.absoluteIncludePaths(style_doc, config_); 84 return transformer_.transform(style_doc, page);81 return (Element)transformer_.transform(style_doc, page); 85 82 86 83 }
Note:
See TracChangeset
for help on using the changeset viewer.