public BlobWrapper(Blob blob) { this.blob = blob; filename = blob.getFilename(); }
protected static String getFileName(Blob blob) { String entry = blob.getFilename(); if (entry == null) { entry = "Unknown_" + System.identityHashCode(blob); } return escapeEntryPath(entry); }
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 getFilePath() { String path = getBasePath(); Blob blob = getBlob(); if (blob != null) { path = path + "/" + blob.getFilename(); } return path; }
/** * Zip a list of blob. * * @param blobs the blob list * @param fileName if no filename is given, the first blob's filename will be used * @return a zip containing the list of blob * @throws IOException */ public static Blob zip(List<Blob> blobs, String fileName) throws IOException { if (fileName == null || (fileName = fileName.trim()).length() == 0) { fileName = blobs.isEmpty() ? null : blobs.get(0).getFilename(); } File file = Framework.createTempFile("nxops-createzip-", ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); Framework.trackFile(file, file); try { zip(blobs, out); } finally { out.finish(); out.close(); } return Blobs.createBlob(file, "application/zip", null, fileName); }
/** * Zip the given blob. * * @param blob the blob * @param filename if no filename is given, the blob's filename will be used * @return a zip containing the blob * @throws IOException */ public static Blob zip(Blob blob, String filename) throws IOException { if (filename == null || (filename = filename.trim()).length() == 0) { filename = blob.getFilename(); } File file = Framework.createTempFile("nxops-createzip-", ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); Framework.trackFile(file, file); try { zip(blob, out); } finally { out.finish(); out.close(); } return Blobs.createBlob(file, "application/zip", null, filename); }
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); }
@Override public String getName() { return blob.getFilename(); }
protected String getFilename(Blob blob, String targetExt) { String baseName = FilenameUtils.getBaseName(blob.getFilename()); return baseName + "." + targetExt; }
@Override public String getXmlFileName() { Blob xml = safeGet(Blob.class, "file:content", null); return xml == null ? "" : xml.getFilename() == null ? "" : xml.getFilename(); }
private String getFileName(Blob blob) { String originalName = blob.getFilename(); if (StringUtils.isBlank(originalName)) { return "extracted"; } else { int pos = originalName.toLowerCase().lastIndexOf(".pdf"); if (pos > 0) { originalName = originalName.substring(0, pos); } return originalName; } }
@Override public String getFileName() { Blob blob = getTemplateBlob(); if (blob != null) { return blob.getFilename(); } return null; }
public Blob getBlob(String name) { List<Blob> blobs = getBlobs(); if (blobs == null) { return null; } for (Blob blob : blobs) { if (name.equals(blob.getFilename())) { return blob; } } return null; }
public String getBlobUrl(String name) { List<Blob> blobs = getBlobs(); if (blobs == null) { return null; } for (int index = 0; index < blobs.size(); index++) { if (name.equals(blobs.get(index).getFilename())) { return getBlobUrl(index); } } return null; }
/** * 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."); } } }
protected String getFileName(DocumentModel doc) { BlobHolder bh = doc.getAdapter(BlobHolder.class); if (bh != null) { Blob blob = bh.getBlob(); if (blob != null) { return blob.getFilename(); } } return null; }
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); }
public void createPictureimpl(String description, String tag, String title, Integer maxsize, String filename, Integer width, Integer height, Integer depth, Blob fileContent) throws IOException { if (fileContent.getFilename() == null) { fileContent.setFilename(filename); } if (maxsize == null) { maxsize = 0; } PictureConversion pictureConversion = new PictureConversion(title, description, tag, maxsize); pictureConversion.setChainId("Image.Blob.Resize"); PictureView view = getImagingService().computeViewFor(fileContent, pictureConversion, getImageInfo(), true); addPictureView(view); }
protected PictureView computeViewWithoutConversion(Blob blob, PictureConversion pictureConversion, ImageInfo imageInfo) { PictureView view = new PictureViewImpl(); view.setBlob(blob); view.setWidth(imageInfo.getWidth()); view.setHeight(imageInfo.getHeight()); view.setFilename(blob.getFilename()); view.setTitle(pictureConversion.getId()); view.setDescription(pictureConversion.getDescription()); view.setTag(pictureConversion.getTag()); view.setImageInfo(imageInfo); return view; }