예제 #1
0
 /**
  * Create a MIRCdocument XML string by parsing a file. This method does no additional processing
  * on the text.
  *
  * @param mircDocument the file containing the MIRCdocument XML string.
  */
 public static String getText(File mircDocument) {
   try {
     Document templateXML;
     // Parse the MIRCdocument file to catch any problems,
     // then just return the file text.
     templateXML = XmlUtil.getDocument(mircDocument);
     return FileUtil.getFileText(mircDocument);
   } catch (Exception e) {
     return null;
   }
 }
예제 #2
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;
    }
  }