@Override public Blob getBlob(String uri) throws PropertyException, IOException { String localPath = getLocalName(uri); String path = getFileAbsolutePath(localPath); File file = new File(path); if (!file.exists()) { throw new PropertyException(String.format("Cannot find file at '%s'", path)); } Blob blob = Blobs.createBlob(file); blob.setFilename(file.getName()); return blob; } }
protected void setMemberValue(Blob blob, String name, Object value) throws PropertyNotFoundException { if (NAME.equals(name)) { blob.setFilename((String) value); } else if (MIME_TYPE.equals(name)) { blob.setMimeType((String) value); } else if (ENCODING.equals(name)) { blob.setEncoding((String) value); } else if (DIGEST.equals(name)) { blob.setDigest((String) value); } else { throw new PropertyNotFoundException(name); } }
@Override public Blob getBlob() { String string = (String) doc.getProperty(xPath).getValue(); if (string == null) { return null; } Blob blob = Blobs.createBlob(string, mt); String ext = ".txt"; if ("text/html".equals(mt)) { ext = ".html"; } else if ("text/xml".equals(mt)) { ext = ".xml"; } else if ("text/x-web-markdown".equals(mt)) { ext = ".md"; } String title = doc.getTitle(); if (!title.endsWith(ext)) { title = title.concat(ext); } blob.setFilename(title); return blob; }
public static Blob getBlobFromMap(Map<String, Object> mapValue) { if (mapValue == null) { return null; } String uri = (String) mapValue.get(URI); if (uri == null || "".equals(uri)) { return null; } String filename = (String) mapValue.get(FILE_NAME); String mimeType = (String) mapValue.get(MIME_TYPE); String encoding = (String) mapValue.get(ENCODING); String digest = (String) mapValue.get(DIGEST); try { BlobHolderAdapterService service = Framework.getService(BlobHolderAdapterService.class); if (service == null) { throw new NuxeoException("BlobHolderAdapterService not found"); } Blob blob = service.getExternalBlobForUri(uri); if (filename != null) { blob.setFilename(filename); } blob.setMimeType(mimeType); blob.setEncoding(encoding); // TODO maybe check if digest is still a match to the retrieved blob blob.setDigest(digest); return blob; } catch (IOException e) { throw new NuxeoException(e); } }
public void addDirectoryToList(File directory, String prefix) throws IOException { File[] directoryContent = directory.listFiles(); for (File file : directoryContent) { if (file.isDirectory()) { int beginIndex = prefix.length(); prefix = prefix + file.getName() + File.separatorChar; addDirectoryToList(file, prefix); prefix = prefix.substring(0, beginIndex); } else { Blob blob = Blobs.createBlob(file); blob.setFilename(prefix + file.getName()); if (file.getName().equalsIgnoreCase("index.html")) { blobs.add(0, blob); } else { blobs.add(blob); } } } }
@Override public void load(String path) throws IOException { blobs = new ArrayList<>(); File base = new File(path); if (base.isDirectory()) { addDirectoryToList(base, ""); } else { File file = new File(path); Blob mainBlob = Blobs.createBlob(file); mainBlob.setFilename(file.getName()); blobs.add(mainBlob); } orderIndexPageFirst(blobs); }
protected List<Blob> loadBlobs(List<Map<String, String>> blobInfos) { log.debug("Loading blobs from the file system: " + blobInfos); List<Blob> blobs = new ArrayList<>(); for (Map<String, String> info : blobInfos) { File blobFile = new File(cacheDir, info.get("file")); Blob blob = new FileBlob(blobFile); blob.setEncoding(info.get("encoding")); blob.setMimeType(info.get("mimetype")); blob.setFilename(info.get("filename")); blob.setDigest(info.get("digest")); blobs.add(blob); } return blobs; }
protected void adjustBlobName(String filename, Blob blob, String mimeType) { if (StringUtils.isBlank(filename)) { filename = "file_" + System.currentTimeMillis(); } else { filename = FilenameUtils.removeExtension(FilenameUtils.getName(filename)); } String extension = Framework.getService(MimetypeRegistry.class) .getExtensionsFromMimetypeName(mimeType) .stream() .findFirst() .orElse("bin"); blob.setFilename(filename + "." + extension); blob.setMimeType(mimeType); }
@Override protected BlobHolder buildResult(List<String> cmdOutput, CmdParameters cmdParams) throws ConversionException { final ParameterValue outputPath = cmdParams.getParameters().get("outDirPath"); final File outputDir = new File(outputPath.getValue()); final File[] files = outputDir.listFiles(); final List<Blob> blobs = new ArrayList<>(); for (final File file : files) { final Blob blob = new FileBlob(file); blob.setFilename(file.getName()); if (file.getName().equalsIgnoreCase("index.html")) { blobs.add(0, blob); } else { blobs.add(blob); } } return new SimpleCachableBlobHolder(blobs); }
@Override protected BlobHolder buildResult(List<String> cmdOutput, CmdParameters cmdParams) { String outputPath = cmdParams.getParameter("outDirPath"); File outputDir = new File(outputPath); File[] files = outputDir.listFiles(); List<Blob> blobs = new ArrayList<>(); for (File file : files) { try { Blob blob = Blobs.createBlob(file); blob.setFilename(file.getName()); blobs.add(blob); } catch (IOException e) { throw new ConversionException("Cannot create Blob", e); } } return new SimpleCachableBlobHolder(blobs); }
@Override protected BlobHolder buildResult(List<String> cmdOutput, CmdParameters cmdParams) { String outputPath = cmdParams.getParameter("outDirPath"); File outputDir = new File(outputPath); File[] files = outputDir.listFiles(); List<Blob> blobs = new ArrayList<Blob>(); for (File file : files) { try { Blob blob = Blobs.createBlob(file); blob.setFilename(file.getName()); blobs.add(blob); } catch (IOException e) { throw new ConversionException("Cannot create Blob", e); } } return new SimpleCachableBlobHolder(blobs); }
protected void resizeAvatar(DocumentModel doc, Blob avatarImage) throws PropertyException { ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder bh = new SimpleBlobHolder(avatarImage); Map<String, Serializable> parameters = new HashMap<>(); parameters.put("targetWidth", String.valueOf(RESIZED_IMAGE_WIDTH)); parameters.put("targetHeight", String.valueOf(RESIZED_IMAGE_HEIGHT)); try { BlobHolder result = conversionService.convert("resizeAvatar", bh, parameters); if (result != null) { Blob blob = result.getBlob(); blob.setFilename(avatarImage.getFilename()); doc.setPropertyValue(USER_PROFILE_AVATAR_FIELD, (Serializable) blob); } } catch (NuxeoException e) { log.warn("Unable to resize avatar image"); log.debug(e, e); } }
public Blob getBlob(String path) throws IOException, MimetypeNotFoundException, MimetypeDetectionException, ConversionException { String filePath = key + path; File file = new File(filePath); Blob blob = Blobs.createBlob(file); String mimeType = getMimeTypeService().getMimetypeFromBlob(blob); blob.setMimeType(mimeType); blob.setFilename(path); return blob; }
protected Blob appendPDFs(PDFMergerUtility ut) throws IOException, COSVisitorException { File tempFile = Framework.createTempFile(filename, ".pdf"); ut.setDestinationFileName(tempFile.getAbsolutePath()); ut.mergeDocuments(); Blob fb = Blobs.createBlob(tempFile); Framework.trackFile(tempFile, fb); fb.setFilename(filename); return fb; }
@Override public Blob getPictureFromTitle(String title) throws PropertyException { if (title == null) { return null; } Collection<Property> views = doc.getProperty(VIEWS_PROPERTY).getChildren(); for (Property property : views) { if (title.equals(property.getValue(TITLE_PROPERTY))) { Blob blob = (Blob) property.getValue("content"); if (blob != null) { blob.setFilename((String) property.getValue(FILENAME_PROPERTY)); } return blob; } } return null; }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws java.lang.Exception { Property p = doc.getProperty(xpath); Object o = p.getValue(); if (o instanceof Blob) { Blob blob = (Blob) o; blob.setFilename(name); p.setValue(blob); } if (save) { doc = session.saveDocument(doc); } return doc; }
public static FileBlob saveInTempFile(PDDocument inPdfDoc, String inFileName) throws IOException, COSVisitorException { Blob result = Blobs.createBlobWithExtension(".pdf"); File resultFile = result.getFile(); inPdfDoc.save(result.getFile()); result.setMimeType("application/pdf"); if (StringUtils.isNotBlank(inFileName)) { result.setFilename(inFileName); } FileBlob fb = new FileBlob(resultFile); fb.setMimeType("application/pdf"); return fb; }
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); }
@OperationMethod(collector = BlobCollector.class) public Blob run(DocumentModel doc) { Blob blob = (Blob) doc.getPropertyValue(xpath); if (blob == null) { BlobHolder bh = doc.getAdapter(BlobHolder.class); if (bh != null) { blob = bh.getBlob(); } } // cannot return null since it may break the next operation if (blob == null) { // create an empty blob blob = Blobs.createBlob(""); blob.setFilename(doc.getName() + ".null"); } return blob; }
protected Blob applyConverter(Blob blob, String converter, String destMimeType, Map<String, Serializable> params) { ConversionService cs = Framework.getService(ConversionService.class); BlobHolder bh = cs.convert(converter, new SimpleBlobHolder(blob), params); if (bh == null || bh.getBlob() == null) { return blob; } else { Blob result = bh.getBlob(); MimetypeRegistry mtr = Framework.getService(MimetypeRegistry.class); String filename = FileUtils.getFileNameNoExt(blob.getFilename()); filename = filename + "." + mtr.getExtensionsFromMimetypeName(destMimeType).get(0); result.setFilename(filename); if (result.getMimeType() == null) { result.setMimeType(destMimeType); } return result; } }