Changeset 19984
- Timestamp:
- 2009-07-13T10:25:21+12:00 (15 years ago)
- Location:
- greenstone3/trunk/src/java/org/greenstone/gsdl3
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java
r19771 r19984 580 580 } 581 581 582 // get all the <a> elements 583 NodeList hrefs = data.getElementsByTagName("a"); 584 for (int i=0; i<hrefs.getLength(); i++) { 585 Element a = (Element)hrefs.item(i); 586 // ugly hack to get rid of : in the args - interferes with session handling 587 String href = a.getAttribute("href"); 588 if (!href.equals("")) { 589 if (href.indexOf("?")!=-1) { 590 String[] parts = href.split("\\?", -1); 591 parts[1]=parts[1].replaceAll(":", "%3A"); 592 href = parts[0]+"?"+parts[1]; 593 } 594 a.setAttribute("href", response.encodeURL(href)); 595 } 596 } 597 598 // now find any submit bits - get all the <form> elements 599 NodeList forms = data.getElementsByTagName("form"); 600 for (int i=0; i<forms.getLength(); i++) { 601 Element form = (Element)forms.item(i); 602 form.setAttribute("action", response.encodeURL(form.getAttribute("action"))); 603 } 604 // are these the only cases where URLs occur?? 605 // we should only do this for greenstone urls? 582 if ( data != null ) { 583 584 // get all the <a> elements 585 NodeList hrefs = data.getElementsByTagName("a"); 586 for (int i=0; hrefs!=null && i<hrefs.getLength(); i++) { 587 Element a = (Element)hrefs.item(i); 588 // ugly hack to get rid of : in the args - interferes with session handling 589 String href = a.getAttribute("href"); 590 if (!href.equals("")) { 591 if (href.indexOf("?")!=-1) { 592 String[] parts = href.split("\\?", -1); 593 parts[1]=parts[1].replaceAll(":", "%3A"); 594 href = parts[0]+"?"+parts[1]; 595 } 596 a.setAttribute("href", response.encodeURL(href)); 597 } 598 } 599 600 // now find any submit bits - get all the <form> elements 601 NodeList forms = data.getElementsByTagName("form"); 602 for (int i=0; forms!=null && i<forms.getLength(); i++) { 603 Element form = (Element)forms.item(i); 604 form.setAttribute("action", response.encodeURL(form.getAttribute("action"))); 605 } 606 // are these the only cases where URLs occur?? 607 // we should only do this for greenstone urls? 608 } 606 609 607 610 } -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/Action.java
r16688 r19984 37 37 this.converter = new XMLConverter(); 38 38 this.doc = this.converter.newDOM(); 39 System.err.println("action doc: " + doc ); 39 40 } 40 41 /** the config variables must be set before configure is called */ … … 134 135 return true; 135 136 } 137 138 void addSiteMetadata( Element element, String lang, String uid ) { 139 //ADD SITE METADATA 140 Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", lang, uid); 141 //create a hashmap of params 142 HashMap subset_params = new HashMap(1); 143 subset_params.put(GSXML.SUBSET_PARAM, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 144 //create the element to put the params in 145 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 146 //put them in 147 GSXML.addParametersToList( this.doc, param_list, subset_params ); 148 metadata_request.appendChild(param_list); 149 //create the message 150 Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 151 metadata_message.appendChild(metadata_request); 152 153 //get response 154 Element metadata_response_message = (Element)this.mr.process(metadata_message); 155 156 //drill down to response 157 Element metadata_response = (Element)GSXML.getChildByTagName(metadata_response_message, GSXML.RESPONSE_ELEM); 158 159 GSXML.mergeMetadataLists(element,metadata_response); 160 161 } 136 162 } 137 163 -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/BrowseAction.java
r16688 r19984 91 91 page_response.appendChild(this.doc.importNode(service_description, true)); 92 92 93 //append site metadata 94 addSiteMetadata(page_response, lang, uid); 95 93 96 // if rt=d, then we are just displaying the service 94 97 String request_type = (String)params.get(GSParams.REQUEST_TYPE); -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/DocumentAction.java
r19639 r19984 85 85 // just in case there are some that need to get passed to the services 86 86 HashMap service_params = (HashMap)params.get("s0"); 87 87 88 88 89 String has_rl = null; … … 131 132 } 132 133 } 134 135 //append site metadata 136 addSiteMetadata( page_response, lang, uid); 137 133 138 // get the additional data needed for the page 134 139 getBackgroundData(page_response, collection, lang, uid); -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java
r16688 r19984 82 82 page_response.appendChild(this.doc.importNode(service_description, true)); 83 83 84 //append site metadata 85 addSiteMetadata( page_response, lang, uid); 86 84 87 // if rt=d, then we are just displaying the service 85 88 String request_type = (String)params.get(GSParams.REQUEST_TYPE); -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/GeneralAction.java
r19851 r19984 23 23 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 24 24 logger.debug(" request="+this.converter.getString(request)); 25 26 String lang = request.getAttribute(GSXML.LANG_ATT); 27 String uid = request.getAttribute(GSXML.USER_ID_ATT); 28 25 29 //A shortcut action serving the flax web page requests 26 30 if(request.getAttribute(GSXML.SUBACTION_ATT).equals(GSXML.FLAX_PAGE_GENERATION) … … 33 37 page_response.appendChild((Element)this.doc.importNode(flaxPageNode, true)); 34 38 } 35 return result; 39 addSiteMetadata(result, lang, uid); 40 System.err.println("a"); 41 return result; 36 42 } 37 43 … … 47 53 } 48 54 String request_type = (String) params.get(GSParams.REQUEST_TYPE); 49 String lang = request.getAttribute(GSXML.LANG_ATT);50 String uid = request.getAttribute(GSXML.USER_ID_ATT);51 55 // what is carried out depends on the request_type 52 56 // if rt=d, then a describe request is done, … … 89 93 if (response_only) { 90 94 // just send the reponse as is 95 addSiteMetadata(result_response, lang, uid); 96 System.err.println("b"); 91 97 return result_response; 92 98 } … … 116 122 } 117 123 124 addSiteMetadata(page_response, lang, uid); 125 System.err.println("c"); 118 126 return result; 119 127 } -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/PageAction.java
r19641 r19984 5 5 //XML classes 6 6 import org.w3c.dom.Node; 7 import org.w3c.dom.NodeList; 8 import org.w3c.dom.Document; 7 import org.w3c.dom.NodeList; 8 import org.w3c.dom.Document; 9 9 import org.w3c.dom.Element; 10 10 … … 115 115 String uid = request.getAttribute(GSXML.USER_ID_ATT); 116 116 // extract the params from the cgi-request, 117 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 117 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 118 118 HashMap params = GSXML.extractParams(cgi_paramList, false); 119 119 … … 122 122 logger.error("about page requested with no collection or cluster specified!"); 123 123 // return an empty response 124 return this.doc.createElement(GSXML.RESPONSE_ELEM); 124 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM); 125 addSiteMetadata(response, lang, uid); 126 return response; 125 127 } 126 128 … … 128 130 Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 129 131 130 Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, 132 Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, lang, uid); 131 133 coll_about_message.appendChild(coll_about_request); 132 133 134 Element coll_about_response = (Element)this.mr.process(coll_about_message); 134 135 135 136 // add collection type attribute to paramList 136 137 String col_type = ""; … … 159 160 return null; 160 161 } 161 162 163 162 164 // second, get the info for each service - we only want display items 163 165 // but for now, we'll just get it all … … 168 170 169 171 Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM); 172 //add the site metadata 173 addSiteMetadata(response, lang, uid); 170 174 return response; 171 175 } … … 190 194 if (coll_name == null || coll_name.equals("")) { 191 195 // just return an empty response 192 return this.doc.createElement(GSXML.RESPONSE_ELEM); 196 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM); 197 addSiteMetadata(response, lang, uid); 198 return response; 193 199 } 194 200 … … 205 211 206 212 Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM); 213 214 //add the site metadata 215 addSiteMetadata(response, lang, uid); 216 207 217 return response; 208 218 … … 275 285 return page_response; 276 286 } 287 288 277 289 } -
greenstone3/trunk/src/java/org/greenstone/gsdl3/action/QueryAction.java
r19640 r19984 46 46 */ 47 47 protected Element basicQuery(Element request) { 48 48 49 49 // the result 50 50 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 51 51 52 52 // extract the params from the cgi-request, and check that we have a coll specified 53 53 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); … … 84 84 page_response.appendChild(service_description); 85 85 } 86 86 87 87 if (request_type.indexOf("r") == -1) { 88 88 // just a display request, no actual processing to do 89 return page_response; 90 } 91 89 System.err.println("just a display request, no actual processing to do"); 90 //append site metadata 91 addSiteMetadata( page_response, lang, uid); 92 return page_response; 93 } 94 92 95 // check that we have some service params 93 96 HashMap service_params = (HashMap)params.get("s1"); 94 97 if (service_params == null) { // no query 98 //append site metadata 99 addSiteMetadata( page_response, lang, uid); 95 100 return page_response; 96 101 } … … 116 121 // check for errors 117 122 if (processErrorElements(mr_query_response, page_response)) { 123 //append site metadata 124 addSiteMetadata( page_response, lang, uid); 118 125 return page_response; 119 126 } … … 143 150 // add in a dummy doc node list - used by the display. need to think about this 144 151 page_response.appendChild(this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER)); 152 //append site metadata 153 addSiteMetadata( page_response, lang, uid); 145 154 return page_response; 146 155 } … … 152 161 // append the doc list to the result 153 162 page_response.appendChild(this.doc.importNode(document_list, true)); 163 //append site metadata 164 addSiteMetadata( page_response, lang, uid); 154 165 return page_response; 155 166 } … … 203 214 204 215 logger.debug("Query page:\n" + this.converter.getPrettyString(page_response)); 216 //append site metadata 217 addSiteMetadata( page_response, lang, uid); 205 218 return page_response; 206 219 } -
greenstone3/trunk/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r19893 r19984 107 107 /** list of sites that can be reached */ 108 108 protected Element site_list = null; 109 /** list of metadata for the site */ 110 protected Element metadata_list = null; 109 111 110 112 … … 120 122 this.converter = new XMLConverter(); 121 123 this.doc = this.converter.newDOM(); 124 System.err.println("mr doc: " + doc ); 122 125 } 123 126 … … 420 423 Element site_list_elem = (Element)GSXML.getChildByTagName(config_info, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 421 424 configureExternalSites(site_list_elem); 425 426 // load up the site metadata 427 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 428 Element metadata_list_elem = (Element)GSXML.getChildByTagName(config_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 429 loadMetadata(metadata_list_elem); 430 422 431 423 432 return true; … … 724 733 return true; 725 734 } 735 736 /** Goes through the metadataList and loads each metadatum found */ 737 protected boolean loadMetadata(Element config_metadata_list) { 738 739 // load up the sites 740 logger.info("loading site metadata..."); 741 if (config_metadata_list ==null ) { 742 logger.info("...none found"); 743 return true; 744 } 745 746 NodeList metadata = config_metadata_list.getElementsByTagName(GSXML.METADATA_ELEM); 747 if (metadata.getLength()==0) { 748 logger.info("...none found"); 749 return true; 750 } 751 752 753 for (int i=0; i<metadata.getLength(); i++) { 754 Element s = (Element)metadata.item(i); 755 this.metadata_list.appendChild(this.doc.importNode(s, true)); 756 } 757 return true; 758 } 759 726 760 727 761 /** get site info from external site … … 882 916 response.appendChild(this.site_list); 883 917 response.appendChild(this.service_list); 918 response.appendChild(this.metadata_list); 884 919 return response; 885 920 } 921 886 922 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM); 887 923 … … 895 931 if (info.equals(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER)) { 896 932 response.appendChild(this.collection_list); 897 898 933 } else if (info.equals(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER)) { 899 934 response.appendChild(this.cluster_list); 900 901 935 } else if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) { 902 936 response.appendChild(this.service_list); 903 937 } else if (info.equals(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER)) { 904 938 response.appendChild(this.site_list); 939 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) { 940 response.appendChild(this.metadata_list); 905 941 } 906 942 } -
greenstone3/trunk/src/java/org/greenstone/gsdl3/service/BerryBasket.java
r13270 r19984 32 32 import org.greenstone.gsdl3.util.GSXML; 33 33 import org.greenstone.gsdl3.util.GSPath; 34 import org.greenstone.gsdl3.util.GlobalProperties; 34 35 35 36 import java.net.InetAddress; … … 483 484 484 485 485 public Element processSendMail(Element request){ 486 // Create a new (empty) result message 487 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM); 488 489 // Get the parameters of the request 490 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 491 492 GSXML.printXMLNode(param_list); 493 494 if (param_list == null) { 495 logger.error("BerryBasket Error: SendMail request had no paramList."); 496 return result; // Return the empty result 497 } 498 499 HashMap params = GSXML.extractParams(param_list, false); 500 501 String to = (String)params.get("address"); 502 String subject = (String)params.get("subject"); 503 String mailhost = (String)params.get("host"); 504 String content = (String)params.get("content"); 505 String cc = (String)params.get("cc"); 506 String bcc = (String)params.get("bcc"); 507 username = (String)params.get("user"); 508 password = (String)params.get("password"); 509 String mailer = "msgsend"; 510 511 try { 512 513 Properties props = System.getProperties(); 514 // XXX - could use Session.getTransport() and Transport.connect() 515 // XXX - assume we're using SMTP 516 // TODO: need to get Mail server info from the configuration file 517 if (mailhost != null && mailhost.trim().equals("")) 518 props.put("mail.smtp.host", mailhost); 519 else{ 520 props.put("mail.smtp.host", "webmail.cs.waikato.ac.nz"); 521 } 522 523 // TODO: need to get account info from the configuration file 524 Authenticator auth = new Authenticator(){ 525 protected PasswordAuthentication getPasswordAuthentication(){ 526 if (username == null || username.equals("")){ 527 username = "xxxxx"; 528 password = "xxxxx"; 529 } 530 return new PasswordAuthentication(username,password); 531 } 532 }; 533 534 Session session = Session.getInstance(props, auth); 535 536 Message msg = new MimeMessage(session); 537 msg.setFrom(); 538 539 msg.setRecipients(Message.RecipientType.TO, 540 InternetAddress.parse(to, false)); 541 if (cc != null) 542 msg.setRecipients(Message.RecipientType.CC, 543 InternetAddress.parse(cc, false)); 544 if (bcc != null) 545 msg.setRecipients(Message.RecipientType.BCC, 546 InternetAddress.parse(bcc, false)); 547 548 msg.setSubject(subject); 549 550 msg.setText(content.replaceAll("-------","&")); 551 msg.setHeader("X-Mailer", mailer); 552 msg.setSentDate(new Date()); 553 554 // send the thing off 555 Transport.send(msg); 556 557 logger.info("\nMail was sent successfully."); 558 result.appendChild(this.doc.createTextNode("Mail was sent successfully.")); 559 } catch (Exception e) { 560 e.printStackTrace(); 561 result.appendChild(this.doc.createTextNode(e.getMessage())); 562 } 563 564 return result; 565 } 566 567 protected class Item { 568 569 public String collection; 570 public String docid; 571 public String title=""; 572 public String query=""; 573 public String date=""; 574 public String rootTitle=""; 575 576 public Item(String coll, String id) { 577 this.collection = coll; 578 this.docid = id; 579 } 486 public Element processSendMail(Element request){ 487 // Create a new (empty) result message 488 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM); 489 490 // Get the parameters of the request 491 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 492 493 GSXML.printXMLNode(param_list); 494 495 if (param_list == null) { 496 logger.error("BerryBasket Error: SendMail request had no paramList."); 497 return result; // Return the empty result 498 } 499 500 HashMap params = GSXML.extractParams(param_list, false); 501 502 String to = (String)params.get("address"); 503 String subject = (String)params.get("subject"); 504 String content = (String)params.get("content"); 505 String cc = (String)params.get("cc"); 506 String bcc = (String)params.get("bcc"); 507 508 String mailhost = GlobalProperties.getProperty("mail.smtp.host"); 509 username = GlobalProperties.getProperty("mail.smtp.username"); 510 password = GlobalProperties.getProperty("mail.smtp.password"); 511 String from = GlobalProperties.getProperty("mail.from"); 512 513 String mailer = "msgsend"; 514 515 try { 516 517 Properties props = System.getProperties(); 518 519 //Setup smtp host and from address 520 // XXX - could use Session.getTransport() and Transport.connect() 521 // XXX - assume we're using SMTP 522 if ( mailhost != null && !mailhost.trim().equals("") ) { 523 props.put("mail.smtp.host", mailhost); 524 } else { 525 props.put("mail.smtp.host", "localhost"); 526 } 527 if ( from != null && !from.trim().equals("") ) { 528 props.put("mail.from", from); 529 } 530 531 //setup username and password to the smtp server 532 if ( username == null || username.trim().equals("") ) username = ""; 533 if ( password == null || password.trim().equals("") ) password = ""; 534 Authenticator auth = new Authenticator() { 535 protected PasswordAuthentication getPasswordAuthentication() { 536 return new PasswordAuthentication( username, password ); 537 } 538 }; 539 540 Session session = Session.getInstance(props, auth); 541 542 Message msg = new MimeMessage(session); 543 msg.setFrom(); 544 msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse(to, false) ); 545 if ( cc != null ) { 546 msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false) ); 547 } 548 if ( bcc != null ) { 549 msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc, false) ); 550 } 551 msg.setSubject(subject); 552 msg.setText(content.replaceAll("-------","&")); 553 msg.setHeader("X-Mailer", mailer); 554 msg.setSentDate(new Date()); 555 556 // send the thing off 557 Transport.send(msg); 558 559 logger.info("\nMail was sent successfully."); 560 result.appendChild(this.doc.createTextNode("Mail was sent successfully.")); 561 } catch (Exception e) { 562 e.printStackTrace(); 563 result.appendChild(this.doc.createTextNode(e.getMessage())); 564 } 565 566 return result; 567 } 568 569 570 protected class Item { 571 public String collection; 572 public String docid; 573 public String title=""; 574 public String query=""; 575 public String date=""; 576 public String rootTitle=""; 577 578 public Item(String coll, String id) { 579 this.collection = coll; 580 this.docid = id; 581 } 580 582 581 583 public boolean equals(Object o){ -
greenstone3/trunk/src/java/org/greenstone/gsdl3/util/GSXML.java
r16882 r19984 25 25 import org.w3c.dom.Document; 26 26 import org.w3c.dom.Text; 27 28 29 import javax.xml.transform.TransformerFactory; 30 import javax.xml.transform.Transformer; 31 import java.io.StringWriter; 32 import javax.xml.transform.stream.StreamResult; 33 import javax.xml.transform.dom.DOMSource; 27 34 28 35 import java.util.Map; … … 970 977 971 978 } 979 980 public static void elementToLogAsString(Element e) { 981 try { 982 TransformerFactory tf = TransformerFactory.newInstance(); 983 Transformer trans = tf.newTransformer(); 984 StringWriter sw = new StringWriter(); 985 trans.transform(new DOMSource(e), new StreamResult(sw)); 986 System.err.println( sw.toString() ); 987 } catch( Exception ex ) { 988 System.err.println( "couldn't write " + e + " to log" ); 989 } 990 991 } 972 992 }
Note:
See TracChangeset
for help on using the changeset viewer.