@Override public String getDigest() { return blob.getDigest(); }
jg.writeStringField("digestAlgorithm", v); v = blob.getDigest(); if (v == null) { jg.writeNullField("digest");
public static Map<String, Serializable> getMapFromBlob(Blob blob) { Map<String, Serializable> map = new HashMap<String, Serializable>(); if (blob == null) { map.put(FILE_NAME, null); map.put(MIME_TYPE, null); map.put(ENCODING, null); map.put(LENGTH, null); map.put(DIGEST, null); } else { // cannot return uri for blob for now: no edit implemented map.put(FILE_NAME, blob.getFilename()); map.put(MIME_TYPE, blob.getMimeType()); map.put(ENCODING, blob.getEncoding()); map.put(LENGTH, blob.getLength()); map.put(DIGEST, blob.getDigest()); } return map; }
@Override public String getHash() { Blob blob = getBlob(); if (blob != null) { String h = blob.getDigest(); if (h != null) { return h; } } return doc.getId() + xPath + String.valueOf(getModificationDate()); }
@Override public String getHash() { Blob blob = getBlob(); if (blob != null) { String h = blob.getDigest(); if (h == null) { h = getMD5Digest(); blob.setDigest(h); } return h; } return "NullBlob"; }
protected Object getMemberValue(Object object, String name) throws PropertyException { if (object == null) { throw new NuxeoException("Trying to access a member of a null object: " + name); } if (!(object instanceof Blob)) { throw new NuxeoException("Not a Blob: " + object); } Blob blob = (Blob) object; if (NAME.equals(name)) { return blob.getFilename(); } else if (MIME_TYPE.equals(name)) { return blob.getMimeType(); } else if (ENCODING.equals(name)) { return blob.getEncoding(); } else if (DIGEST.equals(name)) { return blob.getDigest(); } else if (LENGTH.equals(name)) { return Long.valueOf(blob.getLength()); } else { throw new PropertyNotFoundException(name); } }
@Override public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof Blob)) { return false; } Blob other = (Blob) object; if (!Objects.equals(getFilename(), other.getFilename())) { return false; } if (!Objects.equals(getMimeType(), other.getMimeType())) { return false; } if (!Objects.equals(getEncoding(), other.getEncoding())) { return false; } // ignore null digests, they are sometimes lazily computed // therefore mutable String digest = getDigest(); String otherDigest = other.getDigest(); if (digest != null && otherDigest != null && !digest.equals(otherDigest)) { return false; } // compare streams return equalsStream(other); }
protected boolean isBlobDirty(DocumentModel targetDoc) { BlobHolder bh = targetDoc.getAdapter(BlobHolder.class); Blob mainBlob = bh.getBlob(); if (mainBlob != null && mainBlob.getDigest() == null) { // Blobs that have not changed should be SQL Blobs and have a digest return true; } else { // newly uploaded Blob should be FileBlob, and anyway Digest can not // have been computed so far return false; } } }
@Override public TemplateCollectionModel values() throws TemplateModelException { try { List<Object> list = new ArrayList<Object>(keys.length); if (blob != null) { list.add(blob.getFilename()); list.add(blob.getString()); list.add(blob.getLength()); list.add(blob.getMimeType()); list.add(blob.getEncoding()); list.add(blob.getDigest()); } else { list.add(""); list.add(""); list.add(""); list.add(""); list.add(""); list.add(""); } return (TemplateCollectionModel) wrapper.wrap(list); } catch (IOException e) { throw new TemplateModelException("Failed to adapt complex property values", e); } }
/** * @deprecated since 7.3. Now returns directly the Blob and use default {@code BlobWriter}. */ @Deprecated public static Response buildResponseFromBlob(Request request, HttpServletRequest httpServletRequest, Blob blob, String filename) { if (filename == null) { filename = blob.getFilename(); } String digest = blob.getDigest(); EntityTag etag = digest == null ? null : new EntityTag(digest); if (etag != null) { Response.ResponseBuilder builder = request.evaluatePreconditions(etag); if (builder != null) { return builder.build(); } } String contentDisposition = ServletHelper.getRFC2231ContentDisposition(httpServletRequest, filename); // cached resource did change or no ETag -> serve updated content Response.ResponseBuilder builder = Response.ok(blob).header("Content-Disposition", contentDisposition).type( blob.getMimeType()); if (etag != null) { builder.tag(etag); } return builder.build(); }
@Override public String getHash() { Blob blob = getBlob(); if (blob != null) { String h = blob.getDigest(); if (h != null) { return h; } } return doc.getId() + xPath + getModificationDate().toString(); }
@Override public String getHash() { Blob blob = getBlob(); if (blob != null) { String h = blob.getDigest(); if (h != null) { return h; } } return doc.getId() + xPath + getModificationDate().toString(); }
@Override public TemplateModel get(String name) throws TemplateModelException { try { if (blob != null) { if (keys[0].equals(name)) { return new SimpleScalar(blob.getFilename()); } else if (keys[1].equals(name)) { return new SimpleScalar(blob.getString()); } else if (keys[2].equals(name)) { return new SimpleNumber(blob.getLength()); } else if (keys[3].equals(name)) { return new SimpleScalar(blob.getMimeType()); } else if (keys[4].equals(name)) { return new SimpleScalar(blob.getEncoding()); } else if (keys[5].equals(name)) { return new SimpleScalar(blob.getDigest()); } } return NOTHING; } catch (IOException e) { throw new TemplateModelException(e); } }
protected final void readBlob(Element element, ComplexType ctype, Blob blob, boolean inlineBlobs) throws IOException { String blobPath = Integer.toHexString(RANDOM.nextInt()) + ".blob"; element.addElement(ExportConstants.BLOB_ENCODING).addText(blob.getEncoding() != null ? blob.getEncoding() : ""); element.addElement(ExportConstants.BLOB_MIME_TYPE) .addText(blob.getMimeType() != null ? blob.getMimeType() : ""); element.addElement(ExportConstants.BLOB_FILENAME).addText(blob.getFilename() != null ? blob.getFilename() : ""); Element data = element.addElement(ExportConstants.BLOB_DATA); if (inlineBlobs) { String content = Base64.encodeBase64String(blob.getByteArray()); data.setText(content); } else { data.setText(blobPath); blobs.put(blobPath, blob); } element.addElement(ExportConstants.BLOB_DIGEST).addText(blob.getDigest() != null ? blob.getDigest() : ""); }
blobMap.put(FILENAME, blob.getFilename()); blobMap.put(LENGTH, String.valueOf(size)); blobMap.put(DIGEST, blob.getDigest()); kvs.put(key + DOT_BLOB_DOT + i, toJson(blobMap), ttl); i++;
String digest = blob.getDigest(); EntityTag etag = digest == null ? null : new EntityTag(digest);
protected void setValueBlob(T state, Blob blob, String xpath) throws PropertyException { BlobInfo blobInfo = new BlobInfo(); if (blob != null) { DocumentBlobManager blobManager = Framework.getService(DocumentBlobManager.class); try { blobInfo.key = blobManager.writeBlob(blob, this, xpath); } catch (IOException e) { throw new PropertyException("Cannot get blob info for: " + blob, e); } blobInfo.filename = blob.getFilename(); blobInfo.mimeType = blob.getMimeType(); blobInfo.encoding = blob.getEncoding(); blobInfo.digest = blob.getDigest(); blobInfo.length = blob.getLength() == -1 ? null : Long.valueOf(blob.getLength()); } setBlobInfo(state, blobInfo); }
protected void checkBlob(Document doc, BlobAccessor accessor) { Blob blob = accessor.getBlob(); if (!(blob instanceof ManagedBlob)) { return; } // compare current provider with expected String expectedProviderId = getProviderId(doc, blob, accessor.getXPath()); if (((ManagedBlob) blob).getProviderId().equals(expectedProviderId)) { return; } // re-write blob // TODO add APIs so that blob providers can copy blobs efficiently from each other Blob newBlob; try (InputStream in = blob.getStream()) { newBlob = Blobs.createBlob(in, blob.getMimeType(), blob.getEncoding()); newBlob.setFilename(blob.getFilename()); newBlob.setDigest(blob.getDigest()); } catch (IOException e) { throw new RuntimeException(e); } accessor.setBlob(newBlob); }
blob.transferTo(file); String digest = blob.getDigest(); blob = Blobs.createBlob(file, blob.getMimeType(), blob.getEncoding(), blob.getFilename()); blob.setDigest(digest);