private static int openOrImportFileAndGetTree(JoeTree tree, DocumentInfo docInfo, FileProtocol protocol, int mode) {
		String msg = null;
		int openOrImportResult = FAILURE;
		OpenFileFormat openOrImportFileFormat = null ;
		
		// try to open the file
		if (!protocol.openFile(docInfo)) {
			return FAILURE;
		}
		
		// Get the proper file format object for the specified mode
		switch (mode) {
			
			case MODE_OPEN:
				openOrImportFileFormat = Outliner.fileFormatManager.getOpenFormat(PropertyContainerUtil.getPropertyAsString(docInfo, DocumentInfo.KEY_FILE_FORMAT));
				break;
				
			case MODE_IMPORT:
				openOrImportFileFormat = Outliner.fileFormatManager.getImportFormat(PropertyContainerUtil.getPropertyAsString(docInfo, DocumentInfo.KEY_FILE_FORMAT));
				break;
				
			default:
				// Ack, this shouldn't happen.
				// illegal/unknown mode specification
				System.out.println("FileMenu:OpenFile: bad mode parameter");
				return FAILURE;
		}
		
		// if we couldn't get a file format object reference ...
		if (openOrImportFileFormat == null) {
			msg = GUITreeLoader.reg.getText("error_could_not_open_no_file_format");
			msg = Replace.replace(msg,GUITreeComponentRegistry.PLACEHOLDER_1, PropertyContainerUtil.getPropertyAsString(docInfo, DocumentInfo.KEY_PATH));
			msg = Replace.replace(msg,GUITreeComponentRegistry.PLACEHOLDER_2, PropertyContainerUtil.getPropertyAsString(docInfo, DocumentInfo.KEY_FILE_FORMAT));
			JOptionPane.showMessageDialog(Outliner.outliner, msg);
		} else {
			// we got one try to open the file
			openOrImportResult = openOrImportFileFormat.open(tree, docInfo, docInfo.getInputStream());
			
			// if we couldn't ....
			if (openOrImportResult == FAILURE) {
				msg = GUITreeLoader.reg.getText("error_could_not_open_file");
				msg = Replace.replace(msg,GUITreeComponentRegistry.PLACEHOLDER_1, PropertyContainerUtil.getPropertyAsString(docInfo, DocumentInfo.KEY_PATH));
				
				JOptionPane.showMessageDialog(Outliner.outliner, msg);
				RecentFilesList.removeFileNameFromList(docInfo);
				
			} else if (openOrImportResult != FAILURE_USER_ABORTED) {
				// Deal with a childless RootNode or an Empty or Null Tree
				if ((tree.getRootNode() == null) || (tree.getRootNode().numOfChildren() <= 0)) {
					tree.reset();
				}
			}
		}
		
		// no matter what happened, reset the input stream in the docInfo
		docInfo.setInputStream(null);
		
		return openOrImportResult;
	}