public static TCEncapsulatedDocument create(TCReferencedInstance ref) throws Exception { Instance instance = ((TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME)) .findInstanceByUID(ref.getInstanceUID()); List<org.dcm4chee.archive.entity.File> files = instance.getFiles(); DicomObject attrs = instance.getAttributes(false); attrs.remove(Tag.EncapsulatedDocument); MimeType mimeType = null; String mimeTypeStr = attrs.getString(Tag.MIMETypeOfEncapsulatedDocument); if (mimeTypeStr != null) { mimeType = MimeType.get(mimeTypeStr); } if (mimeType == null) { mimeType = getDocumentMimeTypeFromLabel(attrs.getString(Tag.ContentLabel)); } String fsId = files.get(0).getFileSystem().getDirectoryPath(); String fileId = files.get(0).getFilePath(); File file = fsId.startsWith("tar:") ? TarRetrieveDelegate.getInstance().retrieveFileFromTar(fsId, fileId) : FileUtils.resolve(new File(fsId, fileId)); return new TCEncapsulatedDocument(mimeType, ref, attrs, file); }
public static TCDocumentObject create(TCReferencedInstance ref) throws Exception { Instance instance = ((TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME)) .findInstanceByUID(ref.getInstanceUID()); if (instance == null) { return null; } DicomObject attrs = instance.getAttributes(false); MimeType mimeType = null; String mimeTypeStr = attrs.getString(Tag.MIMETypeOfEncapsulatedDocument); if (mimeTypeStr != null) { mimeType = MimeType.get(mimeTypeStr); } if (mimeType == null) { mimeType = getDocumentMimeTypeFromLabel(attrs.getString(Tag.ContentLabel)); } if (mimeType != null) { DocumentType docType = mimeType.getDocumentType(); if (TCImageDocument.DOC_TYPES.contains(docType)) { return TCImageDocument.create(ref); } else if (TCEncapsulatedDocument.DOC_TYPES.contains(docType)) { return TCEncapsulatedDocument.create(ref); } } throw new Exception( "Unable to create TC encapsulated object: Mime type not supported (" + mimeTypeStr + ")"); }