예제 #1
0
 // 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;
 }
예제 #2
0
 // read xml File
 void readXmlFiles() throws ParserConfigurationException, SAXException, IOException {
   // prefix2url.xml
   Document document = HelpFunctions.getDocument(prefixFilePath);
   Element element = document.getDocumentElement();
   // System.out.println("根元素为:" + element.getTagName());
   NodeList childList = element.getChildNodes();
   for (int i = 0; i < childList.getLength(); i++) {
     Node node = childList.item(i);
     if (!(node instanceof Element)) continue;
     String prefix = node.getNodeName();
     String url = node.getTextContent();
     prefixMap.put(prefix, url);
   }
   // accessError.xml
   document = HelpFunctions.getDocument(errorInfoPath);
   element = document.getDocumentElement();
   // System.out.println("根元素为:" + element.getTagName());
   childList = element.getChildNodes();
   for (int i = 0; i < childList.getLength(); i++) {
     Node node = childList.item(i);
     if (node instanceof Element) {
       NodeList childList2 = node.getChildNodes();
       String url = null;
       String errorInfo = null;
       for (int j = 0; j < childList2.getLength(); j++) {
         Node node2 = childList2.item(j);
         if (node2 instanceof Element) {
           if (url == null) url = node2.getTextContent();
           else {
             errorInfo = node2.getTextContent();
             break;
           }
         }
       }
       errorInfoMap.put(url, errorInfo);
     }
   }
 }
예제 #3
0
 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 = "&lt;ArticleId IdType=\"pubmed\"&gt;";
   String endMark = "&lt;";
   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;
 }
예제 #4
0
 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 = "&lt;ArticleId IdType=\"doi\"&gt;";
   String endMark = "&lt;";
   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;
 }
예제 #5
0
  // 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;
  }