Ejemplo n.º 1
0
  /**
   * Export a file.
   *
   * @param fileToExport the file to export.
   * @return the status of the attempt to export the file.
   */
  public Status export(File fileToExport) {
    HttpURLConnection conn;
    OutputStream svros;
    OutputStreamWriter writer;
    XmlObject xmlObject = null;

    // Parse the file and make sure we can handle it
    try {
      xmlObject = new XmlObject(fileToExport);
    } catch (Exception invalid) {
      return Status.FAIL;
    }

    Document doc = xmlObject.getDocument();
    Element root = doc.getDocumentElement();
    String rootName = root.getTagName();
    if (!rootName.equals("ImageAnnotation")) {
      logger.warn(name + ": XmlObject with illegal root (" + rootName + ") not transmitted.");
      return Status.FAIL;
    }

    // Get the text.
    String text = XmlUtil.toString(doc.getDocumentElement());

    // Make the connection and send the text.
    try {
      // Establish the connection
      conn = HttpUtil.getConnection(url);
      conn.connect();

      // Get a writer for UTF-8
      svros = conn.getOutputStream();
      writer = new OutputStreamWriter(svros, FileUtil.utf8);

      // Send the text to the server
      writer.write(text, 0, text.length());
      writer.flush();
      writer.close();

      // Get the response code
      int responseCode = conn.getResponseCode();

      // Get the response.
      String response = FileUtil.getText(conn.getInputStream());

      // Check the response, make any necessary log entries, and return the appropriate Status
      // instance.
      boolean ok = response.toLowerCase().contains("document submitted");
      if (logAll || (!ok && logFailed))
        logger.info(name + ": export response code: " + responseCode + "\n" + response);
      return (ok ? Status.OK : Status.FAIL);
    } catch (Exception e) {
      // This indicates a network failure; log it and set up for a retry.
      logger.warn(name + ": export failed: " + e.getMessage());
      logger.debug(e);
    }
    return Status.RETRY;
  }
  private boolean isAIMAnnotation(XmlObject file) {
    Document document = file.getDocument();
    Element documentElement = document.getDocumentElement();

    System.out.println(
        "isAim:" + documentElement.getLocalName() + "," + documentElement.getNamespaceURI());

    return documentElement.getLocalName().equals("ImageAnnotation")
        && (documentElement
                .getNamespaceURI()
                .equals("gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM")
            || documentElement
                .getNamespaceURI()
                .equals("gme://caCORE/3.2/edu.northwestern.radiology.AIM"));
  }