1 19 package org.netbeans.modules.exceptions.web; 20 21 import java.lang.String ; 22 import java.util.regex.Matcher ; 23 import java.util.regex.Pattern ; 24 import org.apache.commons.httpclient.HttpClient; 25 import org.apache.commons.httpclient.HttpMethod; 26 import org.apache.commons.httpclient.methods.GetMethod; 27 31 public class HttpUtils { 32 33 private static final String URL_PART1 = "http://www.netbeans.org/issues/buglist.cgi?long_desc_type=regexp&long_desc=http%3A%5C%2F%5C%2Fanna.nbextras.org%5C%2Fexceptions%5C%2Fdetail.do%5C%3Fid%3D"; 34 private static final String URL_PART2 = "%5B%5E0-9%5D"; 35 36 39 40 public static Integer checkIssuezillaId(Integer id) { 41 Integer issue = null; 42 HttpClient client = new HttpClient(); 43 System.err.println("--- " + id); 44 client.getHttpConnectionManager(). 46 getParams().setConnectionTimeout(20000); 47 HttpMethod method = null; 49 method = new GetMethod(URL_PART1 + id + URL_PART2); 51 method.setFollowRedirects(true); 52 53 try { 55 client.executeMethod(method); 56 String responseBody = method.getResponseBodyAsString(); 57 String target = responseBody; 58 String expression = "(<input type=\"hidden\" name=\"id\" value=\"(.*)\"./>)"; 59 Pattern p = Pattern.compile(expression); 60 Matcher m = p.matcher(target); 61 boolean result = m.find(); 62 if(result){ 63 Pattern pat = Pattern.compile(":"); 64 String [] items = pat.split(m.group(2)); 65 if (items.length > 0) { 66 issue = new Integer (items[0].trim()); 67 } 68 } 69 } catch(Exception e) { 70 e.printStackTrace(); 71 } finally { 72 method.releaseConnection(); 73 } 74 System.err.println("--- " + issue); 75 return issue; 76 } 77 78 } 79 80 81 82 | Popular Tags |