Beispiel #1
0
  /**
   * Get a MIRCdocument XML string by parsing an existing MIRCdocument. If the FileObject is an
   * instance of a DicomObject, and the document contains insertion elements (indicating that it has
   * not yet received a DicomObject), insert data from the DicomObject where called for in the
   * MIRCdocument.
   *
   * @param mircDocument the file containing the MIRCdocument XML string.
   * @param fileObject the FileObject to be used to update the MIRCdocument.
   */
  public static String getText(File mircDocument, FileObject fileObject) {
    if (!(fileObject instanceof DicomObject)) return getText(mircDocument);
    DicomObject dicomObject = (DicomObject) fileObject;
    try {
      // get the mircDocument file
      Document templateXML;
      templateXML = XmlUtil.getDocument(mircDocument);
      Element root = templateXML.getDocumentElement();

      if (dicomObject.isManifest()) {
        // This is a TCE manifest. All we do for this object is to
        // set the title, author, abstract, and notes sections.
        // We leave all the other elements intact so they can be
        // processed when an image object is received.
        return insertManifestText(root, dicomObject);
      } else if (dicomObject.isRawData()) {
        if (checkTree(root)) {
          // This MIRCdocument has not been loaded with values from the
          // first non-manifest DicomObject, so we have to process the
          // XML object.
          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + getElementText(root, dicomObject);
        } else return FileUtil.getFileText(mircDocument);
      } else if (!dicomObject.isImage()) {
        // This is not an image, so we should leave all the elements
        // in the MIRCdocument intact so they can be processed when an
        // image has been received. If we ever want to process KOS or SR
        // objects, we should do it here.
        return getText(mircDocument);
      } else if (checkTree(root)) {
        // This MIRCdocument has not been loaded with values from the
        // first non-manifest DicomObject, so we have to process the
        // XML object.
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + getElementText(root, dicomObject);
      } else {
        // There is nothing to process, just return the document text.
        return FileUtil.getFileText(mircDocument);
      }
    } catch (Exception e) {
      return null;
    }
  }
Beispiel #2
0
  /**
   * Update a MIRCdocument XML string by parsing the string to obtain a MIRCdocument. If the
   * MIRCdocument contains insertion elements, insert data from the DicomObject where called for in
   * the MIRCdocument.
   *
   * @param mircDocument the MIRCdocument XML string.
   * @param dicomObject the object to be used to update the MIRCdocument.
   */
  public static String getText(String mircDocument, DicomObject dicomObject) {

    // Don't insert elements from anything but images.
    if (!dicomObject.isImage()) return mircDocument;

    // It's an image; process the document.
    try {
      // get the mircDocument DOM Document
      Document templateXML;
      templateXML = XmlUtil.getDocumentFromString(mircDocument);
      Element root = templateXML.getDocumentElement();

      if (checkTree(root)) {
        // This MIRCdocument has not been loaded with values from the
        // first non-manifest DicomObject, so we have to process the
        // XML object.
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + getElementText(root, dicomObject);
      }
    } catch (Exception e) {
    }
    return mircDocument;
  }