// id doesn't contain the prefix "SAMPLE" public String get_sample_attributes(String id) throws HttpException, IOException { String prefix = prefixMap.get("SAMPLE"); String postfix = id + "&format=text"; String url = HelpFunctions.getUrl(prefix, postfix); String webpage = getWebPage(url); String[] lines = webpage.split("\n"); String result = ""; String comma = ","; boolean start = false; boolean descriptionTag = false; for (int i = 0; i < lines.length; i++) { String line = lines[i].trim(); if (line.length() == 0) continue; if (line.equals("</pre>")) break; if (line.equals("Attributes:") || line.equals("Additional attributes:")) { start = true; continue; } else if (line.equals("Description:")) { result += "description=\""; // read the next line result += (lines[i + 1].trim() + "\""); break; } else if (start) { if (line.charAt(0) == '/') line = line.substring(1); result += (line + comma); } } // for // remove the comma if (result.charAt(result.length() - 1) == ',') result = result.substring(0, result.length() - 1); return result; }
public String get_pmid(String doi) throws HttpException, IOException { String prefix = prefixMap.get("pmid"); String postfix = "?term=" + doi + "&presentation=xml"; String url = HelpFunctions.getUrl(prefix, postfix); String webpage = getWebPage(url); // System.out.println(webpage); String beginMark = "<ArticleId IdType=\"pubmed\">"; String endMark = "<"; int beginIndex = webpage.indexOf(beginMark) + beginMark.length(); if (beginIndex < beginMark.length()) return null; int endIndex = webpage.indexOf(endMark, beginIndex); String pmid = webpage.substring(beginIndex, endIndex).trim(); if (pmid.equals("")) return null; return pmid; }
public String get_doi(String pmid) throws HttpException, IOException { String prefix = prefixMap.get("pmid"); String postfix = "?term=" + pmid + "&presentation=xml"; String url = HelpFunctions.getUrl(prefix, postfix); // String url = prefixMap.get("pmid") + "?term=" + pmid // + "&presentation=xml"; String webpage = getWebPage(url); // System.out.println(webpage); String beginMark = "<ArticleId IdType=\"doi\">"; String endMark = "<"; int beginIndex = webpage.indexOf(beginMark) + beginMark.length(); if (beginIndex < beginMark.length()) return null; int endIndex = webpage.indexOf(endMark, beginIndex); String doi = webpage.substring(beginIndex, endIndex); return doi; }
// postfix should not be null or "" boolean accessTest(String postfix, String prefix, String field, String log) throws HttpException, IOException { if (postfix == null || postfix.equals("") || postfix.equals("null")) return true; // String logon_site // int LOGON_PORT=80; String url = HelpFunctions.getUrl(prefix, postfix); // if(ur) // System.out.println("**"+url+"** "+field); String urlRegex = Validation.urlRegex; if (!Validation.regexTest(urlRegex, url, field, log)) return false; // client.getHostConfiguration().setHost(url, LOGON_PORT); try { GetMethod getMethod = new GetMethod(url); int status = client.executeMethod(getMethod); // not found the webpage if (status == 404) { Excel2Database.excel2DBLog.writeLine( "ValidTest for " + field + " : '" + postfix + "' cann't be resolved." + log); return false; } else if (status == 200) { if (errorInfoMap.keySet().contains(prefix)) { String pageContent = getMethod.getResponseBodyAsString(); String errorInfo = errorInfoMap.get(prefix); if (pageContent.contains(errorInfo)) { Excel2Database.excel2DBLog.writeLine( "ValidTest for " + field + " : '" + postfix + "' can't be resolved." + log); return false; } } } getMethod.releaseConnection(); } catch (Exception e) { // TODO: handle exception System.out.println(url); } return true; }