@Override public String getMimeType() { return blob.getMimeType(); }
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; }
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 void setBlob(Blob blob) { if (blob == null) { doc.getProperty(xPath).setValue(null); mt = null; } else { String string; try { string = blob.getString(); } catch (IOException e) { throw new NuxeoException(e); } // strip '\0 chars from text if (string.indexOf('\0') >= 0) { string = string.replace("\0", ""); } doc.getProperty(xPath).setValue(string); mt = blob.getMimeType(); } }
@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); }
@Override public String getContentType() { return blob.getMimeType(); }
/** * @deprecated use {@link #isLiveEditable(DocumentModel doc, String blobXpath)} */ @Deprecated public boolean isLiveEditable(Blob blob) { if (blob == null) { return false; } String mimetype = blob.getMimeType(); return isMimeTypeLiveEditable(mimetype); }
public boolean isMimeTypeLiveEditable(Blob blob) { if (blob == null) { return false; } String mimetype = blob.getMimeType(); return isMimeTypeLiveEditable(mimetype); }
@Override public boolean isCompleted() { Blob blob = getBlob(); if (blob == null) { return true; } String mimeType = blob.getMimeType(); // lazy rendition with build in-progress has blob mimeType containing "empty=true" return mimeType == null || !mimeType.contains(EMPTY_MARKER); }
/** * Check if blob is a pdf. */ protected void checkPdf(Blob blob) throws OperationException { if (!"application/pdf".equals(blob.getMimeType())) { throw new OperationException("Blob " + blob.getFilename() + " is not a PDF."); } } }
@Override public boolean isExportableToPDF(Blob blob) { if (blob == null) { return false; } // check if there's a conversion available if (getPDFConversionURL(blob) != null) { return true; } String mimeType = blob.getMimeType(); return isMimeTypeExportableToPDF(mimeType); }
protected void updateResultBlobMimeType(BlobHolder resultBh, ConverterDescriptor desc) { Blob mainBlob = resultBh.getBlob(); if (mainBlob == null) { return; } String mimeType = mainBlob.getMimeType(); if (StringUtils.isBlank(mimeType) || mimeType.equals("application/octet-stream")) { mainBlob.setMimeType(desc.getDestinationMimeType()); } }
public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { Blob blob = blobHolder.getBlob(); String mimeType = blob.getMimeType(); if (!mimeType.equals("application/zip") && !mimeType.equals("application/x-zip-compressed")) { throw new ConversionException("not a zip file"); } return new ZipCachableBlobHolder(blob); }
public DocumentBlob(String name, Blob blob) throws IOException { this.blob = blob.getByteArray(); encoding = blob.getEncoding(); mimeType = blob.getMimeType(); this.name = name; }
private String getMimetypeFromDocument(String propertyName) { Blob blob = (Blob) getDocument().getPropertyValue(propertyName); return blob.getMimeType(); }
@Override public List<PictureView> computeViewsFor(Blob blob, List<PictureConversion> pictureConversions, ImageInfo imageInfo, boolean convert) throws IOException { String mimeType = blob.getMimeType(); if (mimeType == null) { blob.setMimeType(getImageMimeType(blob)); } if (imageInfo == null) { imageInfo = getImageInfo(blob); } List<PictureView> views = new ArrayList<>(); for (PictureConversion pictureConversion : pictureConversions) { views.add(computeView(blob, pictureConversion, imageInfo, convert)); } return views; }
@Override public void updateDocument(DocumentModel doc, Blob content) { String string; try { string = getString(content); } catch (IOException e) { throw new NuxeoException(e); } doc.setProperty(NOTE_SCHEMA, NOTE_FIELD, string); doc.setProperty(NOTE_SCHEMA, MT_FIELD, content.getMimeType()); }
@Override public PictureView computeViewFor(Blob blob, PictureConversion pictureConversion, ImageInfo imageInfo, boolean convert) throws IOException { String mimeType = blob.getMimeType(); if (mimeType == null) { blob.setMimeType(getImageMimeType(blob)); } if (imageInfo == null) { imageInfo = getImageInfo(blob); } return computeView(blob, pictureConversion, imageInfo, convert); }
public TemplateProcessorDescriptor findProcessorDescriptor(Blob templateBlob) { TemplateProcessorDescriptor processor = null; String mt = templateBlob.getMimeType(); if (mt != null) { processor = findProcessorByMimeType(mt); } if (processor == null) { String fileName = templateBlob.getFilename(); if (fileName != null) { String ext = FileUtils.getFileExtension(fileName); processor = findProcessorByExtension(ext); } } return processor; }
protected String findConverter(Blob blob, String destMimeType) { MimetypeRegistry mtr = Framework.getService(MimetypeRegistry.class); String srcMt = mtr.getMimetypeFromFilenameAndBlobWithDefault(blob.getFilename(), blob, blob.getMimeType()); blob.setMimeType(srcMt); ConversionService cs = Framework.getService(ConversionService.class); return cs.getConverterName(srcMt, destMimeType); }