/***** * Find the MIME type to use at display time, giving first priority to the * preview payload, then to the source payload. * * @param indexerFormats The list of types so far allocated by the rules * script. * @param object The object being indexed. * @param preview The preview payload * @return String The MIME type to be used at display time. */ public String getDisplayMimeType(String[] indexerFormats, DigitalObject object, String preview) { // The source should be the first type given by the indexer String result = indexerFormats[0]; // Lets look for a preview payload if (preview != null) { try { Payload payload = object.getPayload(preview); PayloadType type = payload.getType(); if (type != null && type.equals(PayloadType.Preview)) { if (payload.getContentType() != null) { result = payload.getContentType(); } } } catch (StorageException ex) { log.error("Error accessing payload: '{}'", preview, ex); } } return result; }
/** * Creates a copy of the specified payload * * @param payload payload to copy */ public GenericPayload(Payload payload) { if (payload != null) { setId(payload.getId()); setLabel(payload.getLabel()); setContentType(payload.getContentType()); setType(payload.getType()); try { setInputStream(payload.open()); } catch (StorageException e) { log.error( "Error accessing input stream during payload creation", e); } } metaChanged = false; }
private void buildManifest() throws StorageException { Map<String, Payload> manifest = getManifest(); BlobStore blobStore = BlobStoreClient.getClient(); Blob manifestBlob = blobStore.getBlob(BlobStoreClient.getContainerName(), getId() + "/object-manifest"); if (manifestBlob == null) { String manifestString = "{}"; manifestBlob = blobStore.blobBuilder(getId() + "/object-manifest").build(); manifestBlob.setPayload(manifestString); blobStore.putBlob(BlobStoreClient.getContainerName(), manifestBlob); } else { InputStreamReader isr; try { JsonSimple manifestObject = new JsonSimple(manifestBlob.getPayload().openStream()); if (manifestObject.getArray("items") != null) { for (Object itemObject : manifestObject.getArray("items")) { JsonObject item = (JsonObject) itemObject; String name = (String) item.get("name"); Payload payload = new BlobStorePayload(getId(), name); if (PayloadType.Source.equals(payload.getType())) { setSourceId(name); } manifest.put(name, payload); } } } catch (IOException e) { new StorageException("Failed to build manifest", e); } } }