CLEiM
Cross Lingual Education in Medicine
 All Classes Namespaces Files Functions Variables
CallMLP.java
Go to the documentation of this file.
00001 
00005 package com.uem.gsi.cleim.scl;
00006 
00007 import org.apache.commons.httpclient.HttpClient;
00008 import org.apache.commons.httpclient.methods.GetMethod;
00009 import org.apache.commons.httpclient.util.URIUtil;
00010 
00011 import com.uem.gsi.cleim.util.Constants;
00012 
00013 public class CallMLP {
00014   
00015         //MEDLINEPLUS Web service parameter defaults
00016   private String healthTopics="healthTopics";
00017   private String term = "";
00018   private String logic = "+";
00019   private String retstart ="0";
00020   private String retmax ="100";
00021   
00022         public String doMLPQuery(){
00023                 String sSource="";
00024                 try {
00025           HttpClient client = new HttpClient();
00026       GetMethod method=new GetMethod(Constants.MLP_SEARCH);
00027       String urlenc=URIUtil.encodeQuery("db="+healthTopics+
00028                          "&term="+term+"&retstart="+retstart+"&retmax="+retmax);
00029       urlenc=urlenc.replaceAll("%20", logic);
00030       method.setQueryString(urlenc);
00031       // Execute the GET method
00032                         int statusCode = client.executeMethod(method);
00033                         if( statusCode != -1 ) {
00034                           sSource = method.getResponseBodyAsString();
00035                           method.releaseConnection();
00036                         }else{
00037                                 sSource="<statusCode>"+statusCode+"</statusCode>";
00038                         }
00039     }
00040     catch( Exception e ) {
00041       e.printStackTrace();
00042     }
00043                 return sSource;
00044         }
00045         public void setTerm(String pterm){
00046                 this.term=pterm;
00047         }
00048         public void setLogic(String plogic){
00049                 this.logic=plogic;
00050         }
00051         public void setRetstart(String pretstart){
00052                 this.retstart=pretstart;
00053         }
00054         public void setRetmax(String pretmax){
00055                 this.retmax=pretmax;
00056         }
00057         
00058         public static void main (String[] args){
00059                 CallMLP cm=new CallMLP();
00060                 cm.setTerm("prostate cancer");
00061                 //cm.setLogic("+OR+");
00062                 System.out.println(cm.doMLPQuery());
00063         }
00064 }