Changeset 3512
- Timestamp:
- 2002-11-01T09:33:34+13:00 (21 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/AppletAction.java
r3491 r3512 25 25 } 26 26 27 Element request = (Element)message.getElementsByTagName( "request").item(0);27 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 28 28 29 29 // subaction is display/request 30 String request_type = request.getAttribute( "subaction"); // should be 'd' or 'r'30 String request_type = request.getAttribute(GSXML.SUBACTION_ATT); // should be 'd' or 'r' 31 31 if (!request_type.equals("d")&&!request_type.equals("r")) { 32 32 return GSHTML.errorPage("the sa arg to a=a should be d or r!!"); … … 34 34 35 35 // get the collection and service param 36 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");36 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 37 37 cgi_.toLong(cgi_paramList); 38 38 HashMap params = GSXML.extractParams(cgi_paramList); … … 58 58 //build up the mr request 59 59 60 Element mr_message = doc_.createElement( "message");61 Element mr_request = doc_.createElement( "request");60 Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM); 61 Element mr_request = doc_.createElement(GSXML.REQUEST_ELEM); 62 62 mr_message.appendChild(mr_request); 63 mr_request.setAttribute( "type", "describe");64 mr_request.setAttribute( "to", to);65 //mr_request.setAttribute( "info", "appletInfo");63 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 64 mr_request.setAttribute(GSXML.TO_ATT, to); 65 //mr_request.setAttribute(GSXML."info", "appletInfo"); 66 66 67 67 Element mr_response = (Element)mr_.process(mr_message); … … 70 70 System.out.println(converter_.getString(mr_response)); 71 71 // create the return page tree 72 Element page = doc_.createElement( "page");73 page.setAttribute( "lang", message.getAttribute("lang"));72 Element page = doc_.createElement(GSXML.PAGE_ELEM); 73 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT)); 74 74 // add the lang stuff from message 75 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));75 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true)); 76 76 // add the config stuff from message 77 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));77 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 78 78 79 79 page.appendChild(doc_.importNode(request, true)); 80 80 81 81 // add in the applet info 82 Element app_desc = (Element)doc_.importNode(GSXML.getNodeByPath(mr_response, "response/service/applet"), true); 82 String path = GSXML.RESPONSE_ELEM; 83 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 84 path = GSPath.appendLink(path, GSXML.APPLET_ELEM); 85 Element app_desc = (Element)doc_.importNode(GSXML.getNodeByPath(mr_response, path), true); 83 86 // must handle any params that have values that are not 84 87 // necessarily known by the service … … 95 98 // we are processing stuff for the applet send a message to the service, type="query", and take out the something element, and return that as our result - the applet must take xml 96 99 97 Element mr_message = doc_.createElement( "message");98 Element mr_request = doc_.createElement( "request");100 Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM); 101 Element mr_request = doc_.createElement(GSXML.REQUEST_ELEM); 99 102 mr_message.appendChild(mr_request); 100 mr_request.setAttribute( "type", "query");101 mr_request.setAttribute( "to", to);103 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 104 mr_request.setAttribute(GSXML.TO_ATT, to); 102 105 103 106 // just append the params for now … … 108 111 // dont need to create a page, just extract the info out. 109 112 System.out.println(converter_.getString(mr_response)); 110 Element applet_info = (Element)GSXML.getNodeByPath(mr_response, "response/appletData").getFirstChild(); 113 // add in the applet data 114 String path = GSXML.RESPONSE_ELEM; 115 path = GSPath.appendLink(path, GSXML.APPLET_DATA_ELEM); 116 Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild(); 111 117 System.out.println("applet action: applet data ="); 112 118 System.out.println(converter_.getString(applet_info)); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java
r3491 r3512 16 16 17 17 // create the return page tree 18 Element page = doc_.createElement( "page");19 page.setAttribute( "lang", message.getAttribute("lang"));18 Element page = doc_.createElement(GSXML.PAGE_ELEM); 19 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT)); 20 20 // add the lang stuff from message 21 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));21 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true)); 22 22 // add the system stuff from message 23 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));23 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 24 24 25 Element request = (Element)message.getElementsByTagName( "request").item(0);25 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 26 26 27 27 // the browse type is the subaction 28 String browse_type = request.getAttribute( "subaction");28 String browse_type = request.getAttribute(GSXML.SUBACTION_ATT); 29 29 30 30 if (browse_type.equals("classifier")) { … … 48 48 // extract the params from the cgi-request, and check that we have a coll specified 49 49 // first convert short to long names 50 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");50 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 51 51 cgi_.toLong(cgi_paramList); 52 52 HashMap params = GSXML.extractParams(cgi_paramList); … … 63 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 query 64 64 65 Element mr_info_message = doc_.createElement( "message");66 Element mr_info_request = doc_.createElement( "request");65 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM); 66 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM); 67 67 mr_info_message.appendChild(mr_info_request); 68 mr_info_request.setAttribute( "type", "describe");68 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 69 69 70 70 String to = collection; 71 71 to = GSPath.appendLink(to, "ClassifierBrowse"); 72 mr_info_request.setAttribute( "to", to);72 mr_info_request.setAttribute(GSXML.TO_ATT, to); 73 73 74 74 Element mr_info_response = (Element) mr_.process(mr_info_message); 75 Element description = doc_.createElement("description"); 76 Node cl = GSXML.getNodeByPath(mr_info_response, "response/service/classifierList"); 75 Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM); 76 77 String path = GSXML.RESPONSE_ELEM; 78 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); 77 81 78 82 Element imported_classList = (Element)doc_.importNode(cl, true); … … 93 97 94 98 // get the info for the selected node 95 Element mr_query_message = doc_.createElement( "message");96 Element mr_query_request = doc_.createElement( "request");99 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 100 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 97 101 mr_query_message.appendChild(mr_query_request); 98 102 99 mr_query_request.setAttribute( "type", "query");100 mr_query_request.setAttribute( "to", to);103 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 104 mr_query_request.setAttribute(GSXML.TO_ATT, to); 101 105 102 106 // paramList - empty for now 103 Element paramList = doc_.createElement( "paramList");107 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 104 108 mr_query_request.appendChild(paramList); 105 109 … … 107 111 // content - contains the classifier node, may be more than one 108 112 // call this resource list for now 109 Element query_content = doc_.createElement( "content");113 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM); 110 114 mr_query_request.appendChild(query_content); 111 115 112 Element resource_list = doc_.createElement( "resourceList");113 Element resource = doc_.createElement( "resource");114 resource.setAttribute( "name", node);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); 115 119 resource_list.appendChild(resource); 116 120 query_content.appendChild(resource_list); … … 118 122 Element mr_query_response = (Element)mr_.process(mr_query_message); 119 123 120 Element response = (Element)GSXML.getChildByTagName(mr_query_response, "response");124 Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 121 125 Node new_style = GSXML.getChildByTagName(response, "stylesheet"); 122 126 if (new_style !=null) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java
r3491 r3512 16 16 public String process (Element message) { 17 17 18 Element request = (Element)message.getElementsByTagName( "request").item(0);18 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 19 19 // the page name is the subaction 20 String page_name = request.getAttribute( "subaction");20 String page_name = request.getAttribute(GSXML.SUBACTION_ATT); 21 21 22 22 // create the return page tree 23 Element page = doc_.createElement( "page");24 page.setAttribute( "lang", message.getAttribute("lang"));23 Element page = doc_.createElement(GSXML.PAGE_ELEM); 24 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT)); 25 25 // add the lang stuff from xml_in 26 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));26 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true)); 27 27 // add the system stuff from xml_in 28 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));28 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 29 29 30 30 if (page_name.equals("")) { … … 46 46 // first, get the list of collections from mr 47 47 48 Element coll_list_message = doc_.createElement( "message");49 coll_list_message.setAttribute( "lang", page.getAttribute("lang"));50 Element coll_list_request = doc_.createElement( "request");48 Element coll_list_message = doc_.createElement(GSXML.MESSAGE_ELEM); 49 coll_list_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 50 Element coll_list_request = doc_.createElement(GSXML.REQUEST_ELEM); 51 51 coll_list_message.appendChild(coll_list_request); 52 coll_list_request.setAttribute( "type", "describe");52 coll_list_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 53 53 //coll_list_request.setAttribute("info", "collectionList"); 54 54 … … 59 59 60 60 // second, get the metadata for each collection 61 NodeList colls = coll_list_response.getElementsByTagName( "collection");61 NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM); 62 62 63 Element metadata_message = doc_.createElement("message");64 metadata_message.setAttribute("lang", page.getAttribute("lang"));65 Element metadata_request = doc_.createElement("request");66 metadata_message.appendChild(metadata_request);67 metadata_request.setAttribute("type", "describe");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); 68 68 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 Element metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 72 metadata_message.appendChild(metadata_request); 73 metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 74 69 75 // get the metadata for each one 70 76 Element c = (Element)colls.item(i); 71 String name = c.getAttribute("name"); 77 String name = c.getAttribute(GSXML.NAME_ATT); 78 System.out.println("getting metadata for coll "+name); 72 79 73 metadata_request.setAttribute("to", name); // overwrites the old value 80 metadata_request.setAttribute(GSXML.TO_ATT, name); // overwrites the old value 81 System.out.println("metadata message = \n"+converter_.getString(metadata_message)); 74 82 Element metadata_response = (Element)mr_.process(metadata_message); 75 Element coll = (Element)metadata_response.getElementsByTagName("collection").item(0); 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)); 86 } 76 87 GSXML.mergeMetadataLists(c, coll); // add the metadata to the original response 77 88 } … … 80 91 81 92 // add it in to the page xml tree 82 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_list_response, "response"), true));93 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_list_response, GSXML.RESPONSE_ELEM), true)); 83 94 84 95 String stylesheet = GSFile.stylesheetFile(config_, "home.xsl"); … … 96 107 // extract the params from the cgi-request, 97 108 // first convert short to long names 98 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");109 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 99 110 cgi_.toLong(cgi_paramList); 100 111 HashMap params = GSXML.extractParams(cgi_paramList); … … 108 119 } 109 120 110 Element coll_about_message = doc_.createElement( "message");111 coll_about_message.setAttribute( "lang", page.getAttribute("lang"));121 Element coll_about_message = doc_.createElement(GSXML.MESSAGE_ELEM); 122 coll_about_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 112 123 113 Element coll_about_request = doc_.createElement( "request");124 Element coll_about_request = doc_.createElement(GSXML.REQUEST_ELEM); 114 125 coll_about_message.appendChild(coll_about_request); 115 coll_about_request.setAttribute( "type", "describe");116 coll_about_request.setAttribute( "to", coll_name);126 coll_about_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 127 coll_about_request.setAttribute(GSXML.TO_ATT, coll_name); 117 128 118 129 Element coll_about_response = (Element)mr_.process(coll_about_message); … … 121 132 //System.out.println(converter_.getString(coll_about_response)); 122 133 // add the response to the page 123 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, "response"), true));134 page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM), true)); 124 135 125 136 // process using the stylesheet -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java
r3491 r3512 22 22 23 23 // create the return page tree 24 Element page = doc_.createElement( "page");25 page.setAttribute( "lang", message.getAttribute("lang"));24 Element page = doc_.createElement(GSXML.PAGE_ELEM); 25 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT)); 26 26 // add the lang stuff from message 27 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));27 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true)); 28 28 // add the system stuff from message 29 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));30 31 Element request = (Element)message.getElementsByTagName( "request").item(0);29 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 30 31 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 32 32 // query type is teh subaction 33 String query_type = request.getAttribute( "subaction");33 String query_type = request.getAttribute(GSXML.SUBACTION_ATT); 34 34 35 35 if (query_type.equals("")) { … … 59 59 // extract the params from the cgi-request, and check that we have a coll specified 60 60 // first convert short to long names 61 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");61 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 62 62 cgi_.toLong(cgi_paramList); 63 63 HashMap params = GSXML.extractParams(cgi_paramList); … … 74 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 75 76 Element mr_info_message = doc_.createElement( "message");77 Element mr_info_request = doc_.createElement( "request");76 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM); 77 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM); 78 78 mr_info_message.appendChild(mr_info_request); 79 mr_info_request.setAttribute( "type", "describe");79 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 80 80 81 81 String to = collection; 82 82 to = GSPath.appendLink(to, "TextQuery"); 83 mr_info_request.setAttribute( "to", to);83 mr_info_request.setAttribute(GSXML.TO_ATT, to); 84 84 85 85 Element mr_info_response = (Element) mr_.process(mr_info_message); 86 86 System.err.println("describe response for service"); 87 87 System.err.println(converter_.getString(mr_info_response)); 88 Element description = doc_.createElement( "description");88 Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM); 89 89 // just param list for now - may need content info too 90 Node pl = GSXML.getNodeByPath(mr_info_response, "response/service/paramList"); 90 String path = GSXML.RESPONSE_ELEM; 91 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); 91 94 if (pl ==null) { 92 95 System.out.println("pl is null"); … … 106 109 Element param = (Element)imported_paramList.getFirstChild(); 107 110 while (param !=null) { 108 if (param.getNodeName().equals( "param")) { // just in case109 String name = param.getAttribute( "name");111 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case 112 String name = param.getAttribute(GSXML.NAME_ATT); 110 113 String current = (String)params.get(name); 111 114 if (current !=null && !current.equals("")) { 112 param.setAttribute( "default", current);115 param.setAttribute(GSXML.DEFAULT_ATT, current); 113 116 } 114 117 } … … 119 122 120 123 // check the query string 121 String query = (String)params.get( "query");124 String query = (String)params.get(GSXML.REQUEST_TYPE_QUERY); 122 125 123 126 if (query==null|| query.equals("")) { … … 130 133 131 134 // else do the request, output search box and results 132 Element mr_query_message = doc_.createElement( "message");133 Element mr_query_request = doc_.createElement( "request");135 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 136 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 134 137 mr_query_message.appendChild(mr_query_request); 135 138 136 mr_query_request.setAttribute( "type", "query");137 mr_query_request.setAttribute( "to", to);139 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 140 mr_query_request.setAttribute(GSXML.TO_ATT, to); 138 141 139 142 // paramList 140 Element paramList = doc_.createElement( "paramList");143 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 141 144 mr_query_request.appendChild(paramList); 142 145 … … 148 151 String value = (String)e.getValue(); 149 152 // if (!name.equals("c")) { 150 Element p = doc_.createElement( "param");151 p.setAttribute( "name", name);152 p.setAttribute( "value", value);153 Element p = doc_.createElement(GSXML.PARAM_ELEM); 154 p.setAttribute(GSXML.NAME_ATT, name); 155 p.setAttribute(GSXML.VALUE_ATT, value); 153 156 paramList.appendChild(p); 154 157 // } … … 157 160 158 161 // content - contains the query string 159 Element query_content = doc_.createElement( "content");162 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM); 160 163 Text query_text = doc_.createTextNode(query); 161 164 query_content.appendChild(query_text); … … 169 172 170 173 // check that there are some resources - for now check the list, but later should use a numdocs metadata elem 171 Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response, "response/content/resourceList"); // resourceList not present if no docs found 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 172 180 if (resource_list == null) { 173 181 174 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, "response");182 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 175 183 176 184 page.appendChild(doc_.importNode(result_response, true)); … … 185 193 // can we dynamically decide what metadata to get? 186 194 // get the Title metadata 187 Element mr_metadata_message = doc_.createElement( "message");188 Element mr_metadata_request = doc_.createElement( "request");195 Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 196 Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 189 197 mr_metadata_message.appendChild(mr_metadata_request); 190 198 191 mr_metadata_request.setAttribute( "type", "query");199 mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 192 200 to = GSPath.appendLink(collection, "MetadataRetrieve"); 193 mr_metadata_request.setAttribute( "to", to);194 195 Element meta_content = doc_.createElement( "content");201 mr_metadata_request.setAttribute(GSXML.TO_ATT, to); 202 203 Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM); 196 204 mr_metadata_request.appendChild(meta_content); 197 205 … … 200 208 201 209 // the second part of the content is the metadata list 202 Element metadata_list = doc_.createElement( "metadataList");203 Element title = doc_.createElement( "element");204 title.setAttribute( "name", "Title");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"); 205 213 metadata_list.appendChild(title); 206 214 meta_content.appendChild(metadata_list); … … 208 216 Element mr_metadata_response = (Element)mr_.process(mr_metadata_message); 209 217 210 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, "response");218 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM); 211 219 212 220 page.appendChild(doc_.importNode(result_response, true)); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ResourceAction.java
r3491 r3512 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( "request").item(0);29 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 30 30 31 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");31 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 32 32 cgi_.toLong(cgi_paramList); 33 33 HashMap params = GSXML.extractParams(cgi_paramList); … … 41 41 42 42 // create the return page tree 43 Element page = doc_.createElement( "page");44 page.setAttribute( "lang", message.getAttribute("lang"));43 Element page = doc_.createElement(GSXML.PAGE_ELEM); 44 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT)); 45 45 // add the lang stuff from message 46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true)); 47 47 // add the config stuff from message 48 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));48 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 49 49 50 50 51 51 52 52 // build up the mr request 53 Element mr_message = doc_.createElement( "message");54 Element mr_request = doc_.createElement( "request");53 Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM); 54 Element mr_request = doc_.createElement(GSXML.REQUEST_ELEM); 55 55 mr_message.appendChild(mr_request); 56 mr_request.setAttribute( "type", "query");56 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 57 57 mr_request.setAttribute("resourceType", "core"); 58 58 String to = (String)params.get("collection"); // collection name 59 59 to = GSPath.appendLink(to, "ResourceRetrieve"); 60 mr_request.setAttribute( "to", to);60 mr_request.setAttribute(GSXML.TO_ATT, to); 61 61 62 62 // all query requests must have a paramList and a content 63 Element paramList = doc_.createElement( "paramList");63 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 64 64 mr_request.appendChild(paramList); 65 65 66 Element content = doc_.createElement( "content");66 Element content = doc_.createElement(GSXML.CONTENT_ELEM); 67 67 mr_request.appendChild(content); 68 68 69 Element resource_list = doc_.createElement( "resourceList");70 Element resource = doc_.createElement( "resource");71 resource.setAttribute( "name", resource_name);69 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 70 Element resource = doc_.createElement(GSXML.RESOURCE_ELEM); 71 resource.setAttribute(GSXML.NAME_ATT, resource_name); 72 72 resource_list.appendChild(resource); 73 73 content.appendChild(resource_list); … … 77 77 // add the results to the page 78 78 page.appendChild(doc_.importNode(request, true)); 79 page.appendChild(doc_.importNode(GSXML.getChildByTagName(mr_result, "response"), true));79 page.appendChild(doc_.importNode(GSXML.getChildByTagName(mr_result, GSXML.RESPONSE_ELEM), true)); 80 80 81 81 // process using the stylesheet -
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java
r3468 r3512 53 53 converter_ = new XMLConverter(); 54 54 doc_ = converter_.newDOM(); 55 description_ = doc_.createElement( "collection");56 service_info_ = doc_.createElement( "serviceList");57 meta_info_ = doc_.createElement( "metadataList");55 description_ = doc_.createElement(GSXML.COLLECTION_ELEM); 56 service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 57 meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 58 58 59 59 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
r3502 r3512 80 80 public void setClusterName(String name) { 81 81 cluster_name_ = name; 82 description_.setAttribute( "name", name);82 description_.setAttribute(GSXML.NAME_ATT, name); 83 83 } 84 84 … … 91 91 converter_ = new XMLConverter(); 92 92 doc_ = converter_.newDOM(); 93 description_ = doc_.createElement( "serviceCluster");94 service_info_ = doc_.createElement( "serviceList");95 meta_info_ = doc_.createElement( "metadataList");93 description_ = doc_.createElement(GSXML.CLUSTER_ELEM); 94 service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 95 meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 96 96 97 97 } … … 129 129 130 130 // get the appropriate service cluster element 131 Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), "ServiceClusterList");132 Element sc = GSXML.getNamedElement(cluster_list, "ServiceCluster",133 "name", cluster_name_);131 Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER); 132 Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM, 133 GSXML.NAME_ATT, cluster_name_); 134 134 135 135 return this.configure(sc); … … 139 139 140 140 // create all the services 141 NodeList nodes = cluster_info.getElementsByTagName("servicesImpl"); 142 143 // the xml request to send to each servicesImpl to query what 144 // services it provides 145 Element request = doc_.createElement("request"); 146 request.setAttribute("type", "describe"); 147 request.setAttribute("info", "serviceList"); 148 141 NodeList nodes = cluster_info.getElementsByTagName(GSXML.SERVICE_IMPL_ELEM); 149 142 if (nodes.getLength()==0) { 150 143 System.err.println("Cluster configuration error: cluster "+cluster_name_+" has no service modules!"); … … 153 146 154 147 for(int i=0; i<nodes.getLength(); i++) { 148 149 // the xml request to send to the servicesImpl to query what 150 // services it provides 151 Element message = doc_.createElement(GSXML.MESSAGE_ELEM); 152 Element request = doc_.createElement(GSXML.REQUEST_ELEM); 153 message.appendChild(request); 154 request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 155 request.setAttribute(GSXML.INFO_ATT, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 156 157 155 158 Element n = (Element)nodes.item(i); 156 String servicetype = n.getAttribute( "name");159 String servicetype = n.getAttribute(GSXML.NAME_ATT); 157 160 158 161 try { … … 166 169 167 170 // find out the supported service types for this service module 168 Node types = s.process( request);169 NodeList typenodes = ((Element)types).getElementsByTagName( "service");171 Node types = s.process(message); 172 NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM); 170 173 171 174 for (int j=0; j<typenodes.getLength();j++) { 172 String service = ((Element) typenodes.item(j)).getAttribute( "name");175 String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT); 173 176 service_map_.put(service, s); 174 177 … … 185 188 186 189 // get the metadata - for now just add it to the list 187 Element meta_list = (Element) GSXML.getChildByTagName(cluster_info, "metadataList");188 NodeList metanodes = meta_list.getElementsByTagName( "metadata");190 Element meta_list = (Element) GSXML.getChildByTagName(cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 191 NodeList metanodes = meta_list.getElementsByTagName(GSXML.METADATA_ELEM); 189 192 190 193 if (metanodes.getLength()>0) { … … 225 228 public Element process(Element message) { 226 229 227 String to = message.getAttribute("to"); 228 229 // the cluster name should be first, check, then remove 230 String clustername = GSPath.getFirstLink(to); 231 if (clustername.equals(cluster_name_)){ 230 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 231 Document mess_doc = message.getOwnerDocument(); 232 Element mainResult = doc_.createElement(GSXML.MESSAGE_ELEM); 233 if (requests.getLength()==0) { 234 System.out.println("no requests for cluster:"+cluster_name_); 235 // no requests 236 return mainResult; // for now 237 } 238 for (int i=0; i<requests.getLength(); i++) { 239 Element request = (Element)requests.item(i); 240 String to = request.getAttribute(GSXML.TO_ATT); 241 242 // the cluster name should be first, check, then remove 243 String clustername = GSPath.getFirstLink(to); 244 if (!clustername.equals(cluster_name_)){ 245 System.out.println("ServiceCluster error: cluster name wrong! was "+clustername+" should have been "+cluster_name_); 246 continue; // ignore this request 247 } 232 248 to = GSPath.removeFirstLink(to); 233 message.setAttribute("to", to); 234 } else { 235 System.out.println("ServiceCluster error: cluster name wrong! was "+clustername+" should have been "+cluster_name_); 236 return null; 237 } 238 239 if (to.equals("")) { // this command is for me 240 String type = message.getAttribute("type"); 241 if (type.equals("describe")) { 242 // create a response with the description inside it 243 Element response = doc_.createElement("response"); 244 response.setAttribute("from", cluster_name_); 245 response.setAttribute("type", "describe"); 246 response.appendChild(description_); 247 return response; 248 } else { 249 System.out.println("ServiceCluster: error, cant handle request:"); 250 System.out.println(converter_.getString(message)); 251 return null; 252 } 253 254 } else { // the request is for one of my services 255 String service = GSPath.getFirstLink(to); 256 257 if (service_map_.containsKey(service)) { 258 return ((ModuleInterface)service_map_.get(service)).process(message); 259 } else { 260 System.err.println("ServiceCluster: non-existant service, "+service+", specified, in:\n"+converter_.getString(message)); 261 return null; 262 } 263 264 } 249 request.setAttribute(GSXML.TO_ATT, to); 250 251 if (to.equals("")) { // this command is for me 252 String type = request.getAttribute(GSXML.TYPE_ATT); 253 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) { 254 // create a response with the description inside it 255 Element response = doc_.createElement(GSXML.RESPONSE_ELEM); 256 response.setAttribute(GSXML.FROM_ATT, cluster_name_); 257 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 258 response.appendChild(description_); 259 mainResult.appendChild(response); 260 261 } else { 262 System.out.println("ServiceCluster: error, cant handle request:"); 263 System.out.println(converter_.getString(request)); 264 265 } 266 267 } else { // the request is for one of my services 268 String service = GSPath.getFirstLink(to); 269 270 if (!service_map_.containsKey(service)) { 271 System.err.println("ServiceCluster: non-existant service, "+service+", specified, in:\n"+converter_.getString(request)); 272 continue; 273 } 274 // have to pass the request to the service 275 Element single_message = mess_doc.createElement(GSXML.MESSAGE_ELEM); 276 single_message.appendChild(request); 277 Element response = ((ModuleInterface)service_map_.get(service)).process(single_message); 278 if (response != null) { 279 mainResult.appendChild(doc_.importNode(GSXML.getChildByTagName(response, "response"), true)); 280 } 281 282 } // else 283 284 285 } // for each request 286 System.out.println("servicecluster returning result"); 287 System.out.println(converter_.getString(mainResult)); 288 return mainResult; 265 289 } 266 290 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java
r3505 r3512 66 66 public boolean configure(Element site_elem) { 67 67 68 String type = site_elem.getAttribute( "type");69 if (!type.equals( "soap")) {68 String type = site_elem.getAttribute(GSXML.TYPE_ATT); 69 if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { 70 70 System.err.println("SOAPCommunicator: wrong type of site"); 71 71 return false; 72 72 } 73 remote_site_name_ = site_elem.getAttribute( "name");74 remote_site_address_ = site_elem.getAttribute( "address");73 remote_site_name_ = site_elem.getAttribute(GSXML.NAME_ATT); 74 remote_site_address_ = site_elem.getAttribute(GSXML.ADDRESS_ATT); 75 75 if (remote_site_name_==null || remote_site_name_.equals("")) { 76 76 System.err.println("SOAPCommunicator: must have name attribute in site element"); … … 88 88 89 89 90 // put this into Communicator?? 91 public Element process(Element xml_in) { 92 // needs to catch SOAPException, MalformedURLException 93 try { 94 // add the message encloser back on, and edit the to field 95 Document newdoc = converter_.newDOM(); 96 Element top = newdoc.createElement("message"); 97 top.appendChild(newdoc.importNode(xml_in, true)); 98 //newdoc.appendChild(top); 99 NodeList requests = top.getElementsByTagName("request"); 100 if (requests.getLength()==0) { 101 // no requests 102 return null; 103 } 90 public Element process(Element message) { 91 92 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 93 if (requests.getLength()==0) { 94 // no requests 95 return null; 96 } 97 98 // if the communicator is part of a site, it needs to edit the to and from fields, otherwise it just passes the message on, as is 99 // for now, use local_site_name_ as the flag. 100 if (local_site_name_!=null) { // no local site 101 104 102 for (int i=0;i<requests.getLength(); i++) { 105 103 Element e = (Element)requests.item(i); 106 String to = e.getAttribute( "to");104 String to = e.getAttribute(GSXML.TO_ATT); 107 105 to = GSPath.removeFirstLink(to); // remove the server name, should check that it is present 108 e.setAttribute( "to", to);109 String from = e.getAttribute( "from");106 e.setAttribute(GSXML.TO_ATT, to); 107 String from = e.getAttribute(GSXML.FROM_ATT); 110 108 from = GSPath.appendLink(from, local_site_name_); 111 e.setAttribute( "from", from);109 e.setAttribute(GSXML.FROM_ATT, from); 112 110 } 113 114 // Set Method Parameters 111 } 112 // else do nothing to the message, just pass it on 113 114 // needs to catch SOAPException, MalformedURLException 115 try { 115 116 116 // dont use Strings anymore 117 //String converted_request = converter_.getString(top); 118 //System.out.println("converted request = "+converted_request); 119 // 120 //Parameter param = new Parameter("xml_in", String.class, 121 //converted_request, Constants.NS_URI_SOAP_ENC); 122 123 124 // use straight xml 117 // Set Method Parameters - use literal xml 125 118 Parameter param = new Parameter("xml_in", 126 119 org.w3c.dom.Element.class, 127 top,120 message, 128 121 Constants.NS_URI_LITERAL_XML); 129 122 … … 139 132 140 133 // Check for Faults 141 if (!resp.generatedFault()) { 142 134 if (!resp.generatedFault()) { // no error 135 // Extract Return value 143 136 Parameter result = resp.getReturnValue (); 144 //String res = (String) result.getValue();145 //Element result_node = converter_.getDOM(res).getDocumentElement();146 137 Element result_node = (Element) result.getValue(); 147 138 148 // have to modify the from field139 if (local_site_name_ != null) {// have to modify the from field 149 140 150 NodeList responses = result_node.getElementsByTagName("response");151 for (int i=0;i<responses.getLength(); i++) {152 153 String from = e.getAttribute("from");154 155 e.setAttribute("from", from);156 }157 141 NodeList responses = result_node.getElementsByTagName(GSXML.RESPONSE_ELEM); 142 for (int i=0;i<responses.getLength(); i++) { 143 Element e = (Element)responses.item(i); 144 String from = e.getAttribute(GSXML.FROM_ATT); 145 from = GSPath.prependLink(from, remote_site_name_); 146 e.setAttribute(GSXML.FROM_ATT, from); 147 } 148 } // else return as is 158 149 return result_node; 159 150 } 160 else { 151 else { // error 161 152 // Extract Fault Code and String 162 153 Fault f = resp.getFault(); … … 166 157 System.err.println("Fault Code: "+faultCode); 167 158 System.err.println("Fault String: "+faultString); 168 return converter_.getDOM("< message>Fault Occurred. No greeting for you!</message>").getDocumentElement();159 return converter_.getDOM("<"+GSXML.MESSAGE_ELEM+">Fault Occurred. No greeting for you!</"+GSXML.MESSAGE_ELEM+">").getDocumentElement(); 169 160 } 170 161 } catch (SOAPException e) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r3505 r3512 59 59 public class MessageRouter implements ModuleInterface { 60 60 61 // should go in a separate class? do other names too? 62 static protected String GSDL_MESSAGE_NAME = "message"; 63 64 /** site home */ 61 /** site home - the home directory for the site */ 65 62 protected String site_home_=null; 66 63 /** the global name for this site */ 67 protected String site_name_=null;68 69 /** map of name to Module object*/64 protected String global_site_name_=null; 65 66 /** map of names to Module objects */ 70 67 protected HashMap module_map_=null; 71 68 … … 74 71 /** the full description of this site */ 75 72 protected Element description_ = null; 73 74 // should these things be separated into local and remote?? 75 76 76 /** list of collections that can be reached */ 77 77 protected Element collection_list_ = null; … … 81 81 * can we have single services? or chould all be part of a cluster */ 82 82 protected Element service_list_ = null; 83 83 84 /** list of sites that can be reached */ 84 85 protected Element site_list_ = null; … … 120 121 121 122 // start the description_ XML tree 122 description_ = doc_.createElement( "response");123 description_.setAttribute( "type", "describe");124 collection_list_ = doc_.createElement( "collectionList");125 cluster_list_ = doc_.createElement( "serviceClusterList");126 service_list_ = doc_.createElement( "serviceList");127 site_list_ = doc_.createElement( "siteList");123 description_ = doc_.createElement(GSXML.RESPONSE_ELEM); 124 description_.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 125 collection_list_ = doc_.createElement(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER); 126 cluster_list_ = doc_.createElement(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER); 127 service_list_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 128 site_list_ = doc_.createElement(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 128 129 129 130 … … 187 188 188 189 // check that its a correct message tag 189 if (!message.getTagName().equals(GS DL_MESSAGE_NAME)) {190 System.out.println("Invalid message. GSDL message should start with <"+GS DL_MESSAGE_NAME+">, instead it starts with:"+message.getTagName()+".");190 if (!message.getTagName().equals(GSXML.MESSAGE_ELEM)) { 191 System.out.println("Invalid message. GSDL message should start with <"+GSXML.MESSAGE_ELEM+">, instead it starts with:"+message.getTagName()+"."); 191 192 return null; 192 193 } 193 194 194 NodeList requests = message.getElementsByTagName( "request");195 196 Element mainResult = doc_.createElement( "message");195 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 196 197 Element mainResult = doc_.createElement(GSXML.MESSAGE_ELEM); 197 198 198 199 // empty request … … 201 202 } 202 203 203 // for now, just process each request one by one 204 Document message_doc = message.getOwnerDocument(); 205 206 // for now, just process each request one by one, and append the results to mainResult 204 207 for (int i=0; i<requests.getLength(); i++) { 205 208 Node result=null; 206 209 Element req = (Element)requests.item(i); 207 String path = req.getAttribute( "to"); // returns "" if no att of this name210 String path = req.getAttribute(GSXML.TO_ATT); // returns "" if no att of this name 208 211 if (path.equals("")) { 209 212 // its a message for the message router 210 213 result = processMessage(req); 214 mainResult.appendChild(doc_.importNode(result, true)); 211 215 } else { 212 216 // find the module to pass it on to 217 // need to put the request into a message element 218 Element mess = message_doc.createElement(GSXML.MESSAGE_ELEM); 219 mess.appendChild(req); 213 220 String obj = GSPath.getFirstLink(path); 214 221 if (module_map_.containsKey(obj)) { 215 result = ((ModuleInterface)module_map_.get(obj)).process(req); 222 result = ((ModuleInterface)module_map_.get(obj)).process(mess); 223 if (result !=null ) { 224 // append the contents of the message to the mainResult - there will only be one response at this stage 225 mainResult.appendChild(doc_.importNode(GSXML.getChildByTagName(result, GSXML.RESPONSE_ELEM), true)); 226 } 216 227 } else { 217 228 System.err.println("MessageRouter: request has illegal module name in:\n"+converter_.getString(req)); … … 219 230 } 220 231 221 if (result !=null ) {222 // hack for now for external comms stuff223 if (result.getNodeName().equals("message")) {224 // remove the message bit225 Node child = result.getFirstChild();226 while (child !=null) {227 mainResult.appendChild(doc_.importNode(child, true));228 child = child.getNextSibling();229 }230 } else {231 // just append the whole node232 mainResult.appendChild(doc_.importNode(result, true));233 }234 }235 232 } // for each request 233 System.out.println("MR returning result"); 234 System.out.println(converter_.getString(mainResult)); 235 236 236 return mainResult; 237 237 … … 244 244 /** 245 245 * configures the message router based on the site config file 246 * - site cfg.xml246 * - siteConfig.xml 247 247 * 248 248 */ … … 253 253 254 254 Element local_site_name = (Element)GSXML.getChildByTagName(config, 255 "localSiteName");255 GSXML.SITE_NAME_ELEM); 256 256 if (local_site_name == null) { 257 257 System.err.println("MessageRouter configure error:no site name in config file"); 258 258 return false; 259 259 } else { 260 site_name_ = local_site_name.getAttribute("value");260 global_site_name_ = local_site_name.getAttribute(GSXML.VALUE_ATT); 261 261 } 262 262 … … 264 264 System.out.println("loading service clusters ..."); 265 265 Node cluster_list = GSXML.getChildByTagName(config, 266 "serviceClusterList");266 GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER); 267 267 if (cluster_list == null) { 268 268 System.out.println("... none to be loaded"); … … 274 274 275 275 for (int i=0; i<service_clusters.getLength(); i++) { 276 if (service_clusters.item(i).getNodeName().equals( "serviceCluster")) {276 if (service_clusters.item(i).getNodeName().equals(GSXML.CLUSTER_ELEM)) { 277 277 Element cluster = (Element)service_clusters.item(i); 278 String name = cluster.getAttribute( "name");278 String name = cluster.getAttribute(GSXML.NAME_ATT); 279 279 System.out.println("..."+name); 280 280 ServiceCluster sc = new ServiceCluster(); … … 285 285 module_map_.put(name, sc); 286 286 //add short info to 287 Element e = doc_.createElement( "serviceCluster");288 e.setAttribute( "name", name);287 Element e = doc_.createElement(GSXML.CLUSTER_ELEM); 288 e.setAttribute(GSXML.NAME_ATT, name); 289 289 cluster_list_.appendChild(e); 290 290 … … 299 299 300 300 Node module_list = GSXML.getChildByTagName(config, 301 "servicesImplList");301 GSXML.SERVICE_IMPL_ELEM+GSXML.LIST_MODIFIER); 302 302 if (module_list == null) { 303 303 System.out.println("... none to be loaded"); … … 308 308 } else { 309 309 310 Element service_request = doc_.createElement( "request");311 service_request.setAttribute( "type", "describe");312 service_request.setAttribute( "info", "serviceList");310 Element service_request = doc_.createElement(GSXML.REQUEST_ELEM); 311 service_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 312 service_request.setAttribute(GSXML.INFO_ATT, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 313 313 314 314 for(int i=0; i<service_impls.getLength(); i++) { 315 if (service_impls.item(i).getNodeName().equals( "servicesImpl")) {315 if (service_impls.item(i).getNodeName().equals(GSXML.SERVICE_IMPL_ELEM)) { 316 316 Element n = (Element)service_impls.item(i); 317 String service_name = n.getAttribute( "name");317 String service_name = n.getAttribute(GSXML.NAME_ATT); 318 318 System.out.println("..."+service_name); 319 319 try { … … 327 327 // find out the supported services for this service module 328 328 Element service_response = (Element) s.process(service_request); 329 NodeList services = service_response.getElementsByTagName( "service");329 NodeList services = service_response.getElementsByTagName(GSXML.SERVICE_ELEM); 330 330 if (services.getLength()==0) { 331 331 System.err.println("MessageRouter configure error: servicesImpl "+service_name+" has no services!"); 332 332 } else { 333 333 for (int j=0; j<services.getLength();j++) { 334 String service = ((Element)services.item(j)).getAttribute( "name");334 String service = ((Element)services.item(j)).getAttribute(GSXML.NAME_ATT); 335 335 module_map_.put(service, s); 336 336 … … 350 350 // load up the sites 351 351 System.out.println("loading external sites..."); 352 Node site_list = GSXML.getChildByTagName(config, "siteList");352 Node site_list = GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 353 353 if (site_list ==null ) { 354 354 System.out.println("...none found"); … … 360 360 361 361 for (int i=0; i<sites.getLength(); i++) { 362 if (sites.item(i).getNodeName().equals( "site")) {362 if (sites.item(i).getNodeName().equals(GSXML.SITE_ELEM)) { 363 363 Element s = (Element)sites.item(i); 364 364 Communicator comm=null; 365 String type = s.getAttribute( "type");366 String name = s.getAttribute( "name");367 if (type.equals( "soap")) {365 String type = s.getAttribute(GSXML.TYPE_ATT); 366 String name = s.getAttribute(GSXML.NAME_ATT); 367 if (type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { 368 368 comm = new SOAPCommunicator(); 369 369 if (comm.configure(s)) { 370 comm.setLocalSiteName( site_name_);370 comm.setLocalSiteName(global_site_name_); 371 371 372 372 // add to map of modules … … 377 377 // configure problem - leave as is for now, 378 378 // but fix up later - kjdon 379 getRemoteCollectionInfo(comm, name); 380 getRemoteServiceInfo(comm, name); 379 if (!getRemoteSiteInfo(comm, name)) { 380 System.err.println("couldn't get info from site "+name); 381 } 381 382 } else { 382 383 System.err.println("couldn't configure soap site:"+name); … … 401 402 } 402 403 403 /** get collection list from external site 404 405 /** get site info from external site 404 406 * 405 407 * @param comm - the communicator object for the external site … … 407 409 * @return true if successful 408 410 */ 409 protected boolean getRemoteCollectionInfo(Communicator comm, String site_name) { 410 System.out.println("MessageRouter: getting coll info from site:"+site_name); 411 String coll_request = "<request type='describe' info='collectionList'/>"; 412 413 String coll_response = comm.process(coll_request); 414 415 Document coll_doc = converter_.getDOM(coll_response); 416 NodeList colls = coll_doc.getElementsByTagName("collection"); 411 protected boolean getRemoteSiteInfo(Communicator comm, String site_name) { 412 413 System.out.println("MessageRouter: getting info from site:"+site_name); 414 415 Element info_request = doc_.createElement(GSXML.MESSAGE_ELEM); 416 Element req = doc_.createElement(GSXML.REQUEST_ELEM); 417 info_request.appendChild(req); 418 req.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 419 420 // process the message 421 Element info_response = comm.process(info_request); 422 if (info_response == null) { 423 return false; 424 } 425 // collection info 426 NodeList colls = info_response.getElementsByTagName(GSXML.COLLECTION_ELEM); 417 427 if (colls.getLength()>0) { 418 428 for (int i=0; i<colls.getLength(); i++) { 419 429 Element e = (Element)colls.item(i); 420 String col_name = e.getAttribute( "name");430 String col_name = e.getAttribute(GSXML.NAME_ATT); 421 431 // add the info to own coll list - may want to keep 422 432 // this separate in future - so can distinguish own and 423 // other collections 424 e.setAttribute( "name", GSPath.prependLink(col_name, site_name));433 // other collections ?? 434 e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(col_name, site_name)); 425 435 collection_list_.appendChild(doc_.importNode(e, true)); 426 436 } 427 437 } 428 return true; 429 430 } 431 /** get service list from external site 432 * 433 * @param comm - the communicator object for the external site 434 * @param site_name - the name of the external site 435 * @return true if successful 436 */ 437 protected boolean getRemoteServiceInfo(Communicator comm, String site_name) { 438 System.out.println("MessageRouter: getting service info from site:"+site_name); 439 String serv_request = "<request type='describe' info='serviceList'/>"; 440 String serv_response = comm.process(serv_request); 441 Document serv_doc = converter_.getDOM(serv_response); 442 NodeList services = serv_doc.getElementsByTagName("service"); 438 439 // service info 440 NodeList services = info_response.getElementsByTagName(GSXML.SERVICE_ELEM); 443 441 if (services.getLength()>0) { 444 442 for (int i=0; i<services.getLength(); i++) { 445 443 Element e = (Element)services.item(i); 446 String serv_name = e.getAttribute( "name");444 String serv_name = e.getAttribute(GSXML.NAME_ATT); 447 445 System.out.println("found service name="+serv_name); 448 e.setAttribute( "name", GSPath.prependLink(serv_name, site_name));446 e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(serv_name, site_name)); 449 447 service_list_.appendChild(doc_.importNode(e, true)); 450 448 } 451 449 } 450 451 // serviceCluster info 452 NodeList clusters = info_response.getElementsByTagName(GSXML.CLUSTER_ELEM); 453 if (clusters.getLength()>0) { 454 for (int i=0; i<clusters.getLength(); i++) { 455 Element e = (Element)clusters.item(i); 456 String clus_name = e.getAttribute(GSXML.NAME_ATT); 457 System.out.println("found cluster name="+clus_name); 458 e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(clus_name, site_name)); 459 cluster_list_.appendChild(doc_.importNode(e, true)); 460 } 461 } 452 462 return true; 453 454 } 463 } 464 455 465 456 466 /** creates and configures a new collection … … 468 478 if (c.configure()) { 469 479 // this could be a reactivation, so delete the old version 470 deactivate( "collection", col_name);480 deactivate(GSXML.COLLECTION_ELEM, col_name); 471 481 // add to list of collections 472 482 module_map_.put(col_name, c); 473 483 //add short description_ to collection_list_ 474 Element e = doc_.createElement( "collection");475 e.setAttribute( "name", col_name);484 Element e = doc_.createElement(GSXML.COLLECTION_ELEM); 485 e.setAttribute(GSXML.NAME_ATT, col_name); 476 486 collection_list_.appendChild(e); 477 487 return true; … … 505 515 506 516 // message for self, should be type=describe/configure at this stage 507 String type = req.getAttribute( "type");508 Element response = doc_.createElement( "response");509 510 if (type.equals( "describe")) {511 String info = req.getAttribute( "info");517 String type = req.getAttribute(GSXML.TYPE_ATT); 518 Element response = doc_.createElement(GSXML.RESPONSE_ELEM); 519 520 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) { 521 String info = req.getAttribute(GSXML.INFO_ATT); 512 522 if (info.equals("")) { 513 523 // return full description … … 515 525 } 516 526 // use the new response with the appropriate info 517 response.setAttribute( "type", "describe");527 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 518 528 519 if (info.equals( "collectionList")) {529 if (info.equals(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER)) { 520 530 response.appendChild(collection_list_); 521 531 return response; 522 } else if (info.equals( "serviceClusterList")) {532 } else if (info.equals(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER)) { 523 533 response.appendChild(cluster_list_); 524 534 return response; 525 } else if (info.equals( "serviceList")) {535 } else if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) { 526 536 response.appendChild(service_list_); 527 537 return response; 528 } else if (info.equals( "sitelist")) {538 } else if (info.equals(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER)) { 529 539 response.appendChild(site_list_); 530 540 return response; 531 541 } 532 542 533 } else if (type.equals( "configure")) {543 } else if (type.equals(GSXML.REQUEST_TYPE_CONFIGURE)) { 534 544 535 545 // a list of configure requests - should put any error messages 536 546 // or success messages into response 537 NodeList commands = req.get ChildNodes();547 NodeList commands = req.getElementsByTagName(GSXML.CONFIGURE_ELEM); 538 548 for (int i=0; i<commands.getLength(); i++) { 539 549 // all the commands should be Elements 540 if (commands.item(i).getNodeType() == Node.ELEMENT_NODE) { 541 Element elem = (Element)commands.item(i); 542 String name = elem.getNodeName(); 543 String module_name = elem.getAttribute("name"); 544 String module_type = elem.getAttribute("type"); 545 if (name.equals("activate")) { 546 if (module_type.equals("collection")) { 547 activateCollection(module_name); 548 } else if (module_type.equals("servicesImpl")) { 549 activateServicesImpl(module_name); 550 } else if (module_type.equals("serviceCluster")) { 551 activateServiceCluster(module_name); 552 } else { 553 // cant process the activation 554 // send an error 555 } 556 } else if (name.equals("deactivate")) { 550 Element elem = (Element)commands.item(i); 551 String action = elem.getAttribute(GSXML.ACTION_ATT); 552 String module_name = elem.getAttribute(GSXML.NAME_ATT); 553 String module_type = elem.getAttribute(GSXML.TYPE_ATT); 554 if (action.equals(GSXML.CONFIG_ACTION_ACTIVATE)) { 555 if (module_type.equals(GSXML.COLLECTION_ELEM)) { 556 activateCollection(module_name); 557 } else if (module_type.equals(GSXML.SERVICE_IMPL_ELEM)) { 558 activateServicesImpl(module_name); 559 } else if (module_type.equals(GSXML.CLUSTER_ELEM)) { 560 activateServiceCluster(module_name); 561 } else { 562 // cant process the activation 563 // send an error 564 } 565 } else if (action.equals(GSXML.CONFIG_ACTION_DEACTIVATE)) { 557 566 deactivate(module_type, module_name); 558 567 559 }560 568 } 561 569 } 570 562 571 return response; 563 572 … … 578 587 579 588 // also remove the xml bit from description list 580 if (type.equals( "collection")) {581 Element this_col = GSXML.getNamedElement(collection_list_, "collection", "name", name);589 if (type.equals(GSXML.COLLECTION_ELEM)) { 590 Element this_col = GSXML.getNamedElement(collection_list_, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name); 582 591 collection_list_.removeChild(this_col); 583 592 return true; 584 } else if (type.equals( "service")) {585 Element this_service = GSXML.getNamedElement(service_list_, "service", "name", name);593 } else if (type.equals(GSXML.SERVICE_ELEM)) { 594 Element this_service = GSXML.getNamedElement(service_list_, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, name); 586 595 service_list_.removeChild(this_service); 587 596 return true; 588 } else if (type.equals( "serviceCluster")) {589 Element this_cluster = GSXML.getNamedElement(cluster_list_, "serviceCluster", "name", name);597 } else if (type.equals(GSXML.CLUSTER_ELEM)) { 598 Element this_cluster = GSXML.getNamedElement(cluster_list_, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, name); 590 599 cluster_list_.removeChild(this_cluster); 591 600 return true; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java
r3502 r3512 110 110 Element message = message_doc.getDocumentElement(); 111 111 // there should only be one request per message 112 Element request = (Element)GSXML.getChildByTagName(message, "request");112 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 113 113 if (request == null) { 114 114 return GSHTML.errorPage("no request in the message"); 115 115 } 116 116 117 String type = request.getAttribute( "type"); // returns "" if no att of this name118 if (!type.equals( "action")) {117 String type = request.getAttribute(GSXML.TYPE_ATT); // returns "" if no att of this name 118 if (!type.equals(GSXML.REQUEST_TYPE_ACTION)) { 119 119 return GSHTML.errorPage("wrong type in request - should be action"); 120 120 } 121 121 122 String action = request.getAttribute( "action");122 String action = request.getAttribute(GSXML.ACTION_ATT); 123 123 if (action.equals("")) { 124 124 return GSHTML.errorPage(" no action specified"); … … 146 146 147 147 // add in the translation bit - should we do it here? or give the actions access to the translation object? 148 String lang = message.getAttribute( "lang");148 String lang = message.getAttribute(GSXML.LANG_ATT); 149 149 Element trans = translation_.getLanguageTree(lang); 150 150 message.appendChild(message_doc.importNode(trans, true)); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GSDL2ClassifierServices.java
r3492 r3512 36 36 extends ServicesImpl { 37 37 38 // the services on offer 39 private static final String CLASSIFIER_SERVICE = "ClassifierBrowse"; 40 38 41 /** gdbm wrapper */ 39 42 private GDBMWrapper gdbm_src_=null; … … 47 50 protected Element processService(String name, Element request) { 48 51 49 if (!name.equals( "ClassifierBrowse")) {52 if (!name.equals(CLASSIFIER_SERVICE)) { 50 53 System.err.println("GSDL2ClassifierServices:should never get here. service type wrong:"+name); 51 54 return null; 52 55 } 53 56 // the response element 54 Element result = doc_.createElement( "response");55 String from = GSPath.appendLink(cluster_name_, "ClassifierBrowse");56 result.setAttribute( "from", from);57 result.setAttribute( "type", "query");58 Element result_content = doc_.createElement( "content");57 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 58 String from = GSPath.appendLink(cluster_name_, CLASSIFIER_SERVICE); 59 result.setAttribute(GSXML.FROM_ATT, from); 60 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 61 Element result_content = doc_.createElement(GSXML.CONTENT_ELEM); 59 62 result.appendChild(result_content); 60 63 61 64 // get the classifier name out of request content - assume only one for now 62 Element elem = (Element)GSXML.getNodeByPath(request, "content/resourceList/resource"); 63 String elem_name = elem.getAttribute("name"); 65 String path = GSXML.CONTENT_ELEM; 66 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 67 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM); 68 69 Element elem = (Element)GSXML.getNodeByPath(request, path); 70 String elem_name = elem.getAttribute(GSXML.NAME_ATT); 64 71 System.out.println("elem name="+elem_name); 65 72 … … 72 79 73 80 // build up the XML 74 Element classifier = doc_.createElement( "classifier");81 Element classifier = doc_.createElement(GSXML.CLASSIFIER_ELEM); 75 82 76 83 String classifier_name = OID.getTop(elem_name); 77 classifier.setAttribute( "name", classifier_name);84 classifier.setAttribute(GSXML.NAME_ATT, classifier_name); 78 85 result_content.appendChild(classifier); 79 86 DBInfo top_info; … … 123 130 } 124 131 String title = info.getInfo("Title"); 125 Element meta_list = doc_.createElement( "metadataList");132 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 126 133 GSXML.addMetadata(doc_, meta_list, "Title", title); 127 134 this_node.appendChild(meta_list); … … 146 153 } 147 154 title = i.getInfo("Title"); 148 meta_list = doc_.createElement( "metadataList");155 meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 149 156 GSXML.addMetadata(doc_, meta_list, "Title", title); 150 157 temp_node.appendChild(meta_list); … … 169 176 if (child.startsWith("HASH")) { 170 177 // a resource 171 node = doc_.createElement( "resource");178 node = doc_.createElement(GSXML.RESOURCE_ELEM); 172 179 } else { // a node in the classification 173 180 node = doc_.createElement("node"); … … 175 182 } 176 183 177 node.setAttribute( "name", child);178 Element meta_list = doc_.createElement( "metadataList");184 node.setAttribute(GSXML.NAME_ATT, child); 185 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 179 186 GSXML.addMetadata(doc_, meta_list, "Title", title); 180 187 node.appendChild(meta_list); … … 196 203 // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built. 197 204 // set up short_service_info_ - for now just has name and type 198 e = doc_.createElement( "service");199 e.setAttribute( "type", "query");200 e.setAttribute( "name", "ClassifierBrowse");205 e = doc_.createElement(GSXML.SERVICE_ELEM); 206 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 207 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE); 201 208 short_service_info_.appendChild(e); 202 209 203 210 // set up service_info_map_ - for now, just has the same elements as above 204 211 // should have full details about each service incl params lists etc. 205 e = doc_.createElement( "service");206 e.setAttribute( "type", "query");207 e.setAttribute( "name", "ClassifierBrowse");212 e = doc_.createElement(GSXML.SERVICE_ELEM); 213 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 214 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE); 208 215 209 216 // get the classifier list out of the service info 210 Node classList = GSXML.getChildByTagName(info, "classifierList");217 Node classList = GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER); 211 218 e.appendChild(doc_.importNode(classList, true)); 212 219 213 service_info_map_.put( "ClassifierBrowse", e);220 service_info_map_.put(CLASSIFIER_SERVICE, e); 214 221 215 222 if (gdbm_src_.openDatabase(GSFile.GDBMDatabaseFile(site_home_, cluster_name_), GDBMWrapper.READER)) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MGGDBMServices.java
r3492 r3512 19 19 package org.greenstone.gsdl3.service; 20 20 21 import org.greenstone.gsdl3.util.*; 22 21 23 import org.w3c.dom.Document; 22 24 import org.w3c.dom.Node; … … 33 35 extends ServicesImpl { 34 36 37 // the services on offer 38 private static final String TEXT_QUERY_SERVICE = "TextQuery"; 39 private static final String RESOURCE_RETRIEVE_SERVICE = "ResourceRetrieve"; 40 private static final String METADATA_RETRIEVE_SERVICE = "MetadataRetrieve"; 41 35 42 /** passes the request Element to the appropriate service function*/ 36 43 protected Element processService(String name, Element request) { 37 44 38 45 // dont need to check that the service name is supported for this particular object, because that has been checked by ServicesImpl 39 if (name.equals( "TextQuery")) {46 if (name.equals(TEXT_QUERY_SERVICE)) { 40 47 return processTextQuery(request); 41 } else if (name.equals( "DocRetrieve")) {48 } else if (name.equals(RESOURCE_RETRIEVE_SERVICE)) { 42 49 return processDocRetrieve(request); 43 } else if (name.equals( "MetadataRetrieve")) {50 } else if (name.equals(METADATA_RETRIEVE_SERVICE)) { 44 51 return processMetadataRetrieve(request); 45 52 } … … 56 63 // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built. 57 64 // set up short_service_info_ - for now just has name and type 58 e = doc_.createElement( "service");59 e.setAttribute( "type", "query");60 e.setAttribute( "name", "TextQuery");65 e = doc_.createElement(GSXML.SERVICE_ELEM); 66 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 67 e.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE); 61 68 short_service_info_.appendChild(e); 62 69 63 e = doc_.createElement( "service");64 e.setAttribute( "type", "query");65 e.setAttribute( "name", "DocRetrieve");70 e = doc_.createElement(GSXML.SERVICE_ELEM); 71 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 72 e.setAttribute(GSXML.NAME_ATT, RESOURCE_RETRIEVE_SERVICE); 66 73 short_service_info_.appendChild(e); 67 74 68 e = doc_.createElement( "service");69 e.setAttribute( "type", "query");70 e.setAttribute( "name", "MetadataRetrieve");75 e = doc_.createElement(GSXML.SERVICE_ELEM); 76 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 77 e.setAttribute(GSXML.NAME_ATT, METADATA_RETRIEVE_SERVICE); 71 78 short_service_info_.appendChild(e); 72 79 … … 74 81 // set up service_info_map_ - for now, just has the same elements as above 75 82 // should have full details about each service incl params lists etc. 76 e = doc_.createElement( "service");77 e.setAttribute( "type", "query");78 e.setAttribute( "name", "TextQuery");79 service_info_map_.put( "TextQuery", e);83 e = doc_.createElement(GSXML.SERVICE_ELEM); 84 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 85 e.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE); 86 service_info_map_.put(TEXT_QUERY_SERVICE, e); 80 87 81 e = doc_.createElement( "service");82 e.setAttribute( "type", "query");83 e.setAttribute( "name", "DocRetrieve");84 service_info_map_.put( "DocRetrieve", e);88 e = doc_.createElement(GSXML.SERVICE_ELEM); 89 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 90 e.setAttribute(GSXML.NAME_ATT, RESOURCE_RETRIEVE_SERVICE); 91 service_info_map_.put(RESOURCE_RETRIEVE_SERVICE, e); 85 92 86 e = doc_.createElement( "service");87 e.setAttribute( "type", "query");88 e.setAttribute( "name", "MetadataRetrieve");89 service_info_map_.put( "MetadataRetrieve", e);93 e = doc_.createElement(GSXML.SERVICE_ELEM); 94 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 95 e.setAttribute(GSXML.NAME_ATT, METADATA_RETRIEVE_SERVICE); 96 service_info_map_.put(METADATA_RETRIEVE_SERVICE, e); 90 97 91 98 return true; … … 93 100 /** process a text query */ 94 101 protected Element processTextQuery(Element request) { 95 Element result = doc_.createElement( "response");96 result.setAttribute( "name", "TextQuery");102 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 103 result.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE); 97 104 98 105 // dummy result 99 106 Text t = null; 100 t = doc_.createTextNode( "Textqueryresult... ");107 t = doc_.createTextNode(TEXT_QUERY_SERVICE+" result... "); 101 108 result.appendChild(t); 102 109 return result; … … 105 112 /** retrieve a document */ 106 113 protected Element processDocRetrieve(Element request) { 107 Element result = doc_.createElement( "response");108 result.setAttribute( "name", "DocRetrieve");114 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 115 result.setAttribute(GSXML.NAME_ATT, RESOURCE_RETRIEVE_SERVICE); 109 116 110 117 // dummy result 111 118 Text t = null; 112 t = doc_.createTextNode( "DocRetrieveresult... ");119 t = doc_.createTextNode(RESOURCE_RETRIEVE_SERVICE+" result... "); 113 120 result.appendChild(t); 114 121 return result; … … 117 124 /** retrieve metadata */ 118 125 protected Element processMetadataRetrieve(Element request) { 119 Element result = doc_.createElement( "response");120 result.setAttribute( "name", "MetadataRetrieve");126 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 127 result.setAttribute(GSXML.NAME_ATT, METADATA_RETRIEVE_SERVICE); 121 128 122 129 // dummy result 123 130 Text t = null; 124 t = doc_.createTextNode( "MetadataRetrieveresult... ");131 t = doc_.createTextNode(METADATA_RETRIEVE_SERVICE+" result... "); 125 132 result.appendChild(t); 126 133 return result; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MGPPGDBMServices.java
r3492 r3512 46 46 extends ServicesImpl { 47 47 48 // the services on offer 49 private static final String TEXT_QUERY_SERVICE = "TextQuery"; 50 private static final String FIELD_QUERY_SERVICE = "FieldQuery"; 51 private static final String RESOURCE_RETRIEVE_SERVICE = "ResourceRetrieve"; 52 private static final String METADATA_RETRIEVE_SERVICE = "MetadataRetrieve"; 53 48 54 private MGPPWrapper mgpp_src_=null; 49 55 private GDBMWrapper gdbm_src_=null; … … 67 73 Element def = (Element)GSXML.getChildByTagName(info, "defaultIndex"); 68 74 if (def !=null) { 69 default_index_ = def.getAttribute( "name");75 default_index_ = def.getAttribute(GSXML.NAME_ATT); 70 76 } 71 77 if (default_index_==null||default_index_.equals("")) { … … 79 85 def = (Element)GSXML.getChildByTagName(info, "defaultLevel"); 80 86 if (def !=null) { 81 default_level_ = def.getAttribute( "name");87 default_level_ = def.getAttribute(GSXML.NAME_ATT); 82 88 } 83 89 if (default_level_==null||default_level_.equals("")) { … … 94 100 95 101 // set up short_service_info_ - for now just has name and type 96 e = doc_.createElement( "service");97 e.setAttribute( "type", "query");98 e.setAttribute( "name", "TextQuery");102 e = doc_.createElement(GSXML.SERVICE_ELEM); 103 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 104 e.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE); 99 105 short_service_info_.appendChild(e); 100 106 101 e = doc_.createElement( "service");102 e.setAttribute( "type", "query");103 e.setAttribute( "name", "FieldQuery");107 e = doc_.createElement(GSXML.SERVICE_ELEM); 108 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 109 e.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE); 104 110 short_service_info_.appendChild(e); 105 111 106 e = doc_.createElement( "service");107 e.setAttribute( "type", "query");108 e.setAttribute( "name", "ResourceRetrieve");112 e = doc_.createElement(GSXML.SERVICE_ELEM); 113 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 114 e.setAttribute(GSXML.NAME_ATT, RESOURCE_RETRIEVE_SERVICE); 109 115 short_service_info_.appendChild(e); 110 116 111 e = doc_.createElement( "service");112 e.setAttribute( "type", "query");113 e.setAttribute( "name", "MetadataRetrieve");117 e = doc_.createElement(GSXML.SERVICE_ELEM); 118 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 119 e.setAttribute(GSXML.NAME_ATT, METADATA_RETRIEVE_SERVICE); 114 120 short_service_info_.appendChild(e); 115 121 … … 117 123 // should have full details about each service incl params lists etc. 118 124 // do the text query one - for now a static list. later use buildcfg.xml values to dynamically change this 119 e = doc_.createElement( "service");120 e.setAttribute( "type", "query");121 e.setAttribute( "name", "TextQuery");122 Element paramList = doc_.createElement( "paramList");125 e = doc_.createElement(GSXML.SERVICE_ELEM); 126 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 127 e.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE); 128 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 123 129 Element param; 124 130 // first do index and level params … … 132 138 String [] inds = new String[len]; 133 139 for (int i=0; i<len; i++) { 134 inds[i] = ((Element)indexes.item(i)).getAttribute( "name");140 inds[i] = ((Element)indexes.item(i)).getAttribute(GSXML.NAME_ATT); 135 141 } 136 142 param = GSXML.createParameter(doc_, "index", GSXML.PARAM_TYPE_ENUM, default_index_, inds); … … 146 152 String [] levs = new String[len]; 147 153 for (int i=0; i<len; i++) { 148 levs[i] = ((Element)levels.item(i)).getAttribute( "name");154 levs[i] = ((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT); 149 155 } 150 156 param = GSXML.createParameter(doc_, "queryLevel", GSXML.PARAM_TYPE_ENUM, default_level_, levs); … … 172 178 e.appendChild(paramList); 173 179 174 service_info_map_.put( "TextQuery", e);175 176 177 e = doc_.createElement( "service");178 e.setAttribute( "type", "query");179 e.setAttribute( "name", "FieldQuery");180 service_info_map_.put( "FieldQuery", e);181 182 e = doc_.createElement( "service");183 e.setAttribute( "type", "query");184 e.setAttribute( "name", "ResourceRetrieve");185 service_info_map_.put( "ResourceRetrieve", e);186 187 e = doc_.createElement( "service");188 e.setAttribute( "type", "query");189 e.setAttribute( "name", "MetadataRetrieve");190 service_info_map_.put( "MetadataRetrieve", e);180 service_info_map_.put(TEXT_QUERY_SERVICE, e); 181 182 183 e = doc_.createElement(GSXML.SERVICE_ELEM); 184 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 185 e.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE); 186 service_info_map_.put(FIELD_QUERY_SERVICE, e); 187 188 e = doc_.createElement(GSXML.SERVICE_ELEM); 189 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 190 e.setAttribute(GSXML.NAME_ATT, RESOURCE_RETRIEVE_SERVICE); 191 service_info_map_.put(RESOURCE_RETRIEVE_SERVICE, e); 192 193 e = doc_.createElement(GSXML.SERVICE_ELEM); 194 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 195 e.setAttribute(GSXML.NAME_ATT, METADATA_RETRIEVE_SERVICE); 196 service_info_map_.put(METADATA_RETRIEVE_SERVICE, e); 191 197 192 198 if (gdbm_src_.openDatabase(GSFile.GDBMDatabaseFile(site_home_, cluster_name_), GDBMWrapper.READER)) { … … 204 210 205 211 // dont need to check that the service name is supported for this particular object, because that has been checked by ServicesImpl 206 if (name.equals( "TextQuery")) {212 if (name.equals(TEXT_QUERY_SERVICE)) { 207 213 return processTextQuery(request); 208 } else if(name.equals( "FieldQuery")) {214 } else if(name.equals(FIELD_QUERY_SERVICE)) { 209 215 return processFieldQuery(request); 210 } else if (name.equals( "ResourceRetrieve")) {216 } else if (name.equals(RESOURCE_RETRIEVE_SERVICE)) { 211 217 return processResourceRetrieve(request); 212 } else if (name.equals( "MetadataRetrieve")) {218 } else if (name.equals(METADATA_RETRIEVE_SERVICE)) { 213 219 return processMetadataRetrieve(request); 214 220 } … … 223 229 protected Element processTextQuery(Element request) { 224 230 225 Element result = doc_.createElement( "response");226 String from = GSPath.appendLink(cluster_name_, "TextQuery");227 result.setAttribute( "from", from);228 result.setAttribute( "type", "query");231 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 232 String from = GSPath.appendLink(cluster_name_, TEXT_QUERY_SERVICE); 233 result.setAttribute(GSXML.FROM_ATT, from); 234 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 229 235 230 236 // get param list and content … … 234 240 while (n!=null) { 235 241 String node_name = n.getNodeName(); 236 if (node_name.equals( "paramList")) {242 if (node_name.equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) { 237 243 param_elem = (Element)n; 238 } else if (node_name.equals( "content")) {244 } else if (node_name.equals(GSXML.CONTENT_ELEM)) { 239 245 content_elem = (Element)n; 240 246 } … … 278 284 } 279 285 // create a resourceList element 280 Element c = doc_.createElement( "content");286 Element c = doc_.createElement(GSXML.CONTENT_ELEM); 281 287 result.appendChild(c); 282 Element resource_list = doc_.createElement( "resourceList");288 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 283 289 c.appendChild(resource_list); 284 290 // add each resource … … 294 300 /** process a fielded query */ 295 301 protected Element processFieldQuery(Element request) { 296 Element result = doc_.createElement( "response");297 String from = GSPath.appendLink(cluster_name_, "FieldQuery");298 result.setAttribute( "from", from);299 result.setAttribute( "type", "query");302 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 303 String from = GSPath.appendLink(cluster_name_, FIELD_QUERY_SERVICE); 304 result.setAttribute(GSXML.FROM_ATT, from); 305 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 300 306 301 307 302 308 // dummy result 303 309 Text t = null; 304 t = doc_.createTextNode( "Fieldqueryresult... ");310 t = doc_.createTextNode(FIELD_QUERY_SERVICE+" result... "); 305 311 result.appendChild(t); 306 312 return result; … … 316 322 317 323 // an empty result 318 Element result = doc_.createElement( "response");319 String from = GSPath.appendLink(cluster_name_, "ResourceRetrieve");320 result.setAttribute( "from", from);321 result.setAttribute( "type", "query");322 Element result_doc = doc_.createElement( "content");324 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 325 String from = GSPath.appendLink(cluster_name_, RESOURCE_RETRIEVE_SERVICE); 326 result.setAttribute(GSXML.FROM_ATT, from); 327 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 328 Element result_doc = doc_.createElement(GSXML.CONTENT_ELEM); 323 329 result.appendChild(result_doc); 324 330 … … 330 336 while (n!=null) { 331 337 String node_name = n.getNodeName(); 332 if (node_name.equals( "paramList")) {338 if (node_name.equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) { 333 339 param_elem = (Element)n; 334 } else if (node_name.equals( "content")) {340 } else if (node_name.equals(GSXML.CONTENT_ELEM)) { 335 341 content_elem = (Element)n; 336 342 } … … 409 415 /** retrieve metadata */ 410 416 protected Element processMetadataRetrieve(Element request) { 411 Element result = doc_.createElement( "response");412 String from = GSPath.appendLink(cluster_name_, "MetadataRetrieve");413 result.setAttribute( "from", from);414 result.setAttribute( "type", "query");415 Element result_content = doc_.createElement( "content");417 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 418 String from = GSPath.appendLink(cluster_name_, METADATA_RETRIEVE_SERVICE); 419 result.setAttribute(GSXML.FROM_ATT, from); 420 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 421 Element result_content = doc_.createElement(GSXML.CONTENT_ELEM); 416 422 result.appendChild(result_content); 417 Element resource_list = doc_.createElement( "resourceList");423 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 418 424 result_content.appendChild(resource_list); 419 425 // get the metadata 420 426 421 Element content = (Element)request.getElementsByTagName( "content").item(0);427 Element content = (Element)request.getElementsByTagName(GSXML.CONTENT_ELEM).item(0); 422 428 if (content==null) { 423 429 // error: query had no content!! - should make an error message -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/PhindServices.java
r3492 r3512 38 38 extends ServicesImpl { 39 39 40 // the services on offer 41 private static final String PHIND_SERVICE = "PhindApplet"; 42 40 43 private MGPPWrapper mgpp_src_=null; 41 44 private String basepath_ = null; … … 59 62 60 63 // set up short_service_info_ - for now just has name and type 61 Element e = doc_.createElement( "service");62 e.setAttribute( "type", "query");63 e.setAttribute( "name", "PhindApplet");64 Element e = doc_.createElement(GSXML.SERVICE_ELEM); 65 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 66 e.setAttribute(GSXML.NAME_ATT, PHIND_SERVICE); 64 67 short_service_info_.appendChild(e); 65 68 66 69 // set up service_info_map_ - we only have one element, and it has 67 70 // no extra info yet - we are not processing the config info 68 Element f = doc_.createElement( "service");69 f.setAttribute( "type", "query");70 f.setAttribute( "name", "PhindApplet");71 Element f = doc_.createElement(GSXML.SERVICE_ELEM); 72 f.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY); 73 f.setAttribute(GSXML.NAME_ATT, PHIND_SERVICE); 71 74 72 75 // add in the applet info for the phind applet … … 75 78 // this is left blank at this end, and must be filled in by applet action - if the library name is not needed, this param is left out 76 79 // phindcgi param now is not complete - library must be prepended to it. 77 String app_info = "< appletCODEBASE='lib/java' CODE='org.greenstone.applet.phind.Phind.class' ARCHIVE='phind.jar, xercesImpl.jar, gsdl3.jar, jaxp.jar, xml-apis.jar' WIDTH='500' HEIGHT='400'><PARAM NAME='library' VALUE=''/> <PARAM NAME='phindcgi' VALUE='?a=a&sa=r&sn=Phind'/>";80 String app_info = "<"+GSXML.APPLET_ELEM+" CODEBASE='lib/java' CODE='org.greenstone.applet.phind.Phind.class' ARCHIVE='phind.jar, xercesImpl.jar, gsdl3.jar, jaxp.jar, xml-apis.jar' WIDTH='500' HEIGHT='400'><PARAM NAME='library' VALUE=''/> <PARAM NAME='phindcgi' VALUE='?a=a&sa=r&sn=Phind'/>"; 78 81 app_info +="<PARAM NAME='collection' VALUE='"; 79 82 app_info += cluster_name_; 80 app_info += "'/> <PARAM NAME='classifier' VALUE='1'/> <PARAM NAME='orientation' VALUE='vertical'/> <PARAM NAME='depth' VALUE='2'/> <PARAM NAME='resultorder' VALUE='L,l,E,e,D,d'/> <PARAM NAME='backdrop' VALUE='interfaces/default/images/phindbg1.jpg'/><PARAM NAME='fontsize' VALUE='10'/> <PARAM NAME='blocksize' VALUE='10'/>The Phind java applet.</ applet>";83 app_info += "'/> <PARAM NAME='classifier' VALUE='1'/> <PARAM NAME='orientation' VALUE='vertical'/> <PARAM NAME='depth' VALUE='2'/> <PARAM NAME='resultorder' VALUE='L,l,E,e,D,d'/> <PARAM NAME='backdrop' VALUE='interfaces/default/images/phindbg1.jpg'/><PARAM NAME='fontsize' VALUE='10'/> <PARAM NAME='blocksize' VALUE='10'/>The Phind java applet.</"+GSXML.APPLET_ELEM+">"; 81 84 82 85 Document dom = converter_.getDOM(app_info); … … 84 87 f.appendChild(doc_.importNode(app_elem, true)); 85 88 86 service_info_map_.put( "PhindApplet", f);89 service_info_map_.put(PHIND_SERVICE, f); 87 90 88 91 return true; … … 91 94 protected Element processService(String name, Element request) { 92 95 93 if (!name.equals( "PhindApplet")) {96 if (!name.equals(PHIND_SERVICE)) { 94 97 System.err.println("PhindServices:you have asked for a non-existant service - "+name+"!"); 95 98 return null; 96 99 } 97 Element param_elem = (Element)GSXML.getChildByTagName(request, "paramList");100 Element param_elem = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 98 101 HashMap params = GSXML.extractParams(param_elem); 99 102 … … 118 121 119 122 // the result element 120 Element result = doc_.createElement( "response");123 Element result = doc_.createElement(GSXML.RESPONSE_ELEM); 121 124 String from = GSPath.appendLink(cluster_name_, "PhindApplet"); 122 result.setAttribute( "from", from);123 result.setAttribute( "type", "query");125 result.setAttribute(GSXML.FROM_ATT, from); 126 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 124 127 125 128 // applet result info must be in appletInfo element 126 Element applet_data = doc_.createElement( "appletData");129 Element applet_data = doc_.createElement(GSXML.APPLET_DATA_ELEM); 127 130 result.appendChild(applet_data); 128 131 Element phind_data = doc_.createElement("phindData"); … … 442 445 } 443 446 444 445 /*446 // CREATE dummy response447 Element res = doc_.createElement("response");448 res.setAttribute("from", "PhindApplet");449 Element data = doc_.createElement("service");450 Element app_data = doc_.createElement("appletData");451 data.appendChild(app_data);452 String phind_info ="<phindData id='2507' tf='19424' ef='1632' df='1843' lf='0'><phrase>FOREST</phrase><expansionList length='1632' start='0' end='10'><expansion num='0' id='177648' tf='2162' df='519'><suffix>MANAGEMENT</suffix></expansion> <expansion num='1' id='177531' tf='1958' df='566'><suffix>PRODUCTS</suffix></expansion> <expansion num='2' id='177469' tf='1328' df='532'><suffix>RESOURCES</suffix></expansion> <expansion num='3' id='177773' tf='943' df='177'><suffix>GENETIC</suffix></expansion> <expansion num='4' id='177335' tf='736' df='258'><prefix>SUSTAINABLE</prefix></expansion> </expansionList><documentList length='1843' start='0' end='10'><document num='0' hash='HASH011fb8a7d8bf781ab3cbb087' freq='363'><title>FO-edu List of Countries 0</title></document><document num='1' hash='HASH27ae41229eb0636849a5be' freq='344' ><title>FO-edu List of Countries 1</title></document><document num='2' hash='HASH0187ef85c9dbf5bf132ea1d1' freq='263'><title>FO-edu List of Countries 2</title></document><document num='3' hash='HASH0125ec9ef67960446f471280' freq='238'><title>FO-edu List of Countries 3</title></document><document num='4' hash='HASH67087f7717eb35050ce1ac' freq='213'><title>FO-edu List of Countries 4</title></document></documentList><thesaurusList><thesaurus num='3' id='36506' tf='0' df='0' type='RT'><phrase>FRANCOPHONE</phrase></thesaurus></thesaurusList></phindData>";453 454 Node t = converter_.getDOM(phind_info).getDocumentElement();455 app_data.appendChild(doc_.importNode(t, true));456 457 res.appendChild(data);458 459 return res;460 */ -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServicesImpl.java
r3502 r3512 25 25 // xml classes 26 26 import org.w3c.dom.Node; 27 import org.w3c.dom.NodeList; 27 28 import org.w3c.dom.Element; 28 29 import org.w3c.dom.Document; … … 97 98 converter_ = new XMLConverter(); 98 99 doc_ = converter_.newDOM(); 99 short_service_info_ = doc_.createElement( "serviceList");100 short_service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER); 100 101 service_info_map_ = new HashMap(); 101 102 } … … 132 133 * 133 134 * @param xml_in the Element node containing the request 134 * should be <request> or maybe <multipleRequest>?? if more than one 135 * request coming at once 135 * should be <message> 136 136 * @return an Element with the result XML 137 137 * @see Element 138 138 */ 139 public Element process(Element request) { 140 141 String req = request.getNodeName(); 142 if (!req.equals("request")) { 143 System.err.println("ServicesImpl:process - should have been passed a request element, instead was given a "+req+" element!"); 144 return null; 139 public Element process(Element message) { 140 141 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); 142 Document mess_doc = message.getOwnerDocument(); 143 Element mainResult = doc_.createElement(GSXML.MESSAGE_ELEM); 144 if (requests.getLength()==0) { 145 // no requests 146 return mainResult; // for now 145 147 } 146 148 147 String type = request.getAttribute("type"); 148 if (type.equals("describe")) { 149 return processDescribe(request); 150 } 151 152 String to = GSPath.getFirstLink(request.getAttribute("to")); 153 154 // other type of request, must be processed by the subclass - 155 // send to the service method 156 if (service_info_map_.containsKey(to)) { 157 return processService(to, request); 158 } 159 else { 160 // else error in to field 161 System.err.println("ServicesImpl describe request: error in 'to' field, to='"+to+"'."); 162 return null; 163 } 149 for (int i=0; i<requests.getLength(); i++) { 150 Element request = (Element)requests.item(i); 151 152 153 String type = request.getAttribute(GSXML.TYPE_ATT); 154 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) { 155 Element response = processDescribe(request); 156 if (response !=null) { 157 mainResult.appendChild(doc_.importNode(response, true)); 158 } 159 160 } else { 161 162 String to = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT)); 163 164 // other type of request, must be processed by the subclass - 165 // send to the service method 166 if (service_info_map_.containsKey(to)) { 167 Element response = processService(to, request); 168 if (response !=null) { 169 mainResult.appendChild(doc_.importNode(response, true)); 170 } 171 } else { 172 // else error in to field 173 System.err.println("ServicesImpl describe request: error in 'to' field, to='"+to+"'."); 174 return null; 175 } 176 } 177 } // for each request 178 System.out.println("servicesImpl returning result"); 179 System.out.println(converter_.getString(mainResult)); 180 181 return mainResult; 164 182 165 183 … … 171 189 protected Element processDescribe(Element request) { 172 190 173 Element response = doc_.createElement( "response");174 response.setAttribute( "type", "describe");175 176 String info = request.getAttribute( "info");177 String to = GSPath.getFirstLink(request.getAttribute( "to"));191 Element response = doc_.createElement(GSXML.RESPONSE_ELEM); 192 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 193 194 String info = request.getAttribute(GSXML.INFO_ATT); 195 String to = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT)); 178 196 179 197 if (to.equals("")) { // to="", look at info 180 if (info.equals( "serviceList")) {198 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) { 181 199 response.appendChild(short_service_info_); 182 200 return response; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/ConfigVars.java
r3476 r3512 31 31 Document doc = converter.newDOM(); 32 32 33 config_xml_ = doc.createElement( "config");33 config_xml_ = doc.createElement(GSXML.CONFIGURATION_ELEM); 34 34 35 35 Element e; -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java
r3509 r3512 21 21 public static final String SITE_ELEM = "site"; 22 22 public static final String PARAM_ELEM = "param"; 23 public static final String OPTION_ELEM = "option";23 public static final String PARAM_OPTION_ELEM = "option"; 24 24 public static final String CONTENT_ELEM = "content"; 25 25 public static final String RESOURCE_ELEM = "resource"; 26 26 public static final String METADATA_ELEM = "metadata"; 27 27 public static final String SERVICE_IMPL_ELEM = "servicesImpl"; 28 public static final String CLASSIFIER_ELEM = "classifier"; 29 public static final String APPLET_ELEM = "applet"; 30 public static final String APPLET_DATA_ELEM = "appletData"; 31 public static final String CONFIGURE_ELEM = "configure"; 32 public static final String STATUS_ELEM = "status"; 33 34 // elems for the pages to be processed by xslt 35 public final static String PAGE_ELEM = "page"; 36 public final static String TRANSLATION_ELEM = "translate"; 37 public final static String CONFIGURATION_ELEM = "config"; 38 public final static String DESCRIPTION_ELEM = "description"; 39 40 public static final String SITE_NAME_ELEM = "localSiteName"; 28 41 // add on to another elem type to get a list of that type 29 42 public static final String LIST_MODIFIER = "List"; … … 41 54 public static final String DEFAULT_ATT = "default"; 42 55 public static final String INFO_ATT = "info"; 56 public static final String ACTION_ATT = "action"; 57 public static final String SUBACTION_ATT = "subaction"; 58 public static final String ADDRESS_ATT = "address"; 59 43 60 // parameter types 44 61 public static final String PARAM_TYPE_INTEGER = "integer"; … … 51 68 public static final String REQUEST_TYPE_CONFIGURE = "configure"; 52 69 public static final String REQUEST_TYPE_QUERY = "query"; 53 // public static final String REQUEST_TYPE_ 70 public static final String REQUEST_TYPE_ACTION = "action"; 71 public static final String REQUEST_TYPE_BUILD = "build"; 72 73 // service types 74 public static final String SERVICE_TYPE_QUERY = "query"; 75 public static final String SERVICE_TYPE_BUILD = "build"; 76 77 // configure types 78 public static final String CONFIG_ACTION_ACTIVATE = "activate"; 79 public static final String CONFIG_ACTION_DEACTIVATE = "deactivate"; 80 81 // communicator types 82 public static final String COMM_TYPE_SOAP_JAVA = "soap"; 54 83 55 84 // takes a node with a resource elements inside it and extracts all the … … 159 188 public static boolean addDocText(Document owner, Element doc, String text) { 160 189 161 Element content = owner.createElement( "content");190 Element content = owner.createElement(CONTENT_ELEM); 162 191 Text t = owner.createTextNode(text); 163 192 content.appendChild(t); … … 167 196 /** adds an empty MetadataList elem to a doc, and returns a ref to it*/ 168 197 public static Element addMetaList(Document owner, Element doc) { 169 Element list = owner.createElement( "metadataList");198 Element list = owner.createElement(METADATA_ELEM+LIST_MODIFIER); 170 199 doc.appendChild(list); 171 200 return list; … … 177 206 return false; 178 207 } 179 Element data = owner.createElement( "metadata");180 data.setAttribute( "name", meta_name);208 Element data = owner.createElement(METADATA_ELEM); 209 data.setAttribute(NAME_ATT, meta_name); 181 210 Text t = owner.createTextNode(meta_value); 182 211 data.appendChild(t); … … 187 216 188 217 public static boolean mergeMetadataLists(Node to, Node from) { 189 Node to_meta = GSXML.getChildByTagName(to, "metadataList");190 Node from_meta = getChildByTagName(from, "metadataList");218 Node to_meta = getChildByTagName(to, METADATA_ELEM+LIST_MODIFIER); 219 Node from_meta = getChildByTagName(from, METADATA_ELEM+LIST_MODIFIER); 191 220 192 221 if (from_meta == null) { // nothing to copy … … 319 348 320 349 321 Element p = owner.createElement( "param");322 p.setAttribute( "name", param_name);323 p.setAttribute( "type", type);350 Element p = owner.createElement(PARAM_ELEM); 351 p.setAttribute(NAME_ATT, param_name); 352 p.setAttribute(TYPE_ATT, type); 324 353 if (default_value != null) { 325 p.setAttribute( "default", default_value);354 p.setAttribute(DEFAULT_ATT, default_value); 326 355 } 327 356 if (type.equals(PARAM_TYPE_ENUM) && values!=null) { 328 357 for (int i=0; i<values.length; i++) { 329 Element e = owner.createElement( "element");330 e.setAttribute( "name", values[i]);358 Element e = owner.createElement(PARAM_OPTION_ELEM); 359 e.setAttribute(NAME_ATT, values[i]); 331 360 p.appendChild(e); 332 361 }
Note:
See TracChangeset
for help on using the changeset viewer.