Beispiel #1
0
  public void parseStatusXml(String statusXml) {
    try {
      Document statusDoc = SubmissionUtils.emptyDocument();
      SubmissionUtils.transform(new StringReader(statusXml), statusDoc);

      if (statusDoc.getDocumentElement().getTagName().equals("error")) {
        String runName = statusDoc.getElementsByTagName("RunName").item(0).getTextContent();
        String runDirRegex = "(\\d{6})_([A-z0-9]+)_(\\d+)_[A-z0-9_]*";
        Matcher m = Pattern.compile(runDirRegex).matcher(runName);
        if (m.matches()) {
          setStartDate(new SimpleDateFormat("yyMMdd").parse(m.group(1)));
          setInstrumentName(m.group(2));
        }
        setRunName(runName);
        setHealth(HealthType.Unknown);
      } else {
        String runStarted = statusDoc.getElementsByTagName("RunStarted").item(0).getTextContent();
        setStartDate(new SimpleDateFormat("EEEE, MMMMM dd, yyyy h:mm aaa").parse(runStarted));
        setInstrumentName(
            statusDoc.getElementsByTagName("InstrumentName").item(0).getTextContent());
        setRunName(statusDoc.getElementsByTagName("RunName").item(0).getTextContent());
        setHealth(HealthType.Unknown);
      }
      setXml(statusXml);
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
 /**
  * Parses a string path representing an XML file on disk into a StringWriter
  *
  * @param fromPath the file path represented as a String to use as the source
  * @param toWriter the destination StringWriter
  * @throws javax.xml.transform.TransformerException
  * @throws java.io.IOException
  */
 public static void transform(String fromPath, StringWriter toWriter)
     throws TransformerException, IOException {
   SubmissionUtils.transform(new File(fromPath), toWriter);
 }
 /**
  * Transforms a string path representing a file on disk into a DOM Document
  *
  * @param fromPath the file path represented as a String to use as the source
  * @param toDocument the destination Document
  * @throws javax.xml.transform.TransformerException
  * @throws java.io.IOException
  */
 public static void transform(String fromPath, Document toDocument)
     throws TransformerException, IOException {
   // Reader reader = bomCheck(new File(fromPath));
   UnicodeReader reader = new UnicodeReader(new FileInputStream(new File(fromPath)), "UTF-8");
   SubmissionUtils.transform(reader, toDocument);
 }