@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 static Blob jsonHelper(String status, String message, List<String> dependencies) { List<Map<String, Object>> result = new ArrayList<>(); Map<String, Object> resultJSON = new LinkedHashMap<>(); resultJSON.put("status", status); resultJSON.put("message", message); if (dependencies != null) { resultJSON.put("deps", dependencies); } result.add(resultJSON); try { return Blobs.createJSONBlobFromValue(result); } catch (IOException e) { throw new NuxeoException("Unable to create json response", e); } } }
protected Blob getBlob(FileItem item) { try { Blob blob; if (item.isInMemory()) { blob = Blobs.createBlob(item.get()); } else { File file; if (item instanceof DiskFileItem // && (file = ((DiskFileItem) item).getStoreLocation()) != null) { // move the file to a temporary blob we own blob = Blobs.createBlobWithExtension(null); Files.move(file.toPath(), blob.getFile().toPath(), REPLACE_EXISTING); } else { // if we couldn't get to the file, use the InputStream try (InputStream in = item.getInputStream()) { blob = Blobs.createBlob(in); } } } blob.setMimeType(defaultIfEmpty(item.getContentType(), "application/octet-stream")); blob.setFilename(item.getName()); return blob; } catch (IOException e) { throw new NuxeoException("Failed to get blob data", e); } }
protected Blob saveInTempFile(PDDocument PdfDoc) throws IOException, COSVisitorException { Blob blob = Blobs.createBlobWithExtension(".pdf"); // creates a tracked temporary file blob.setMimeType(MIME_TYPE); PdfDoc.save(blob.getFile()); return blob; }
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; }
/** * 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); }
public static void export(List<DocumentModel> docList) { DocumentReader reader = null; DocumentWriter writer = null; Blob blob = null; try { reader = new DocumentModelListReader(docList); blob = Blobs.createBlobWithExtension("zip"); writer = new NuxeoArchiveWriter(blob.getFile()); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); pipe.run(); } catch (IOException e) { log.error("Error during XML export " + e.getMessage()); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } if (blob != null) { ComponentUtils.download(null, null, blob, "export.zip", "workListXML"); if (blob.getFile() != null) { blob.getFile().delete(); } } }
@OperationMethod public Blob run(String nxql) throws IOException { checkAccess(); String commandId = submitBulkCommand(nxql, false); return Blobs.createJSONBlobFromValue(Collections.singletonMap("commandId", commandId)); }
@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; }
pdfDoc = PDDocument.load(pdfBlob.getFile()); pdfDoc.protect(spp); Blob result = Blobs.createBlobWithExtension(".pdf"); pdfDoc.save(result.getFile()); result.setMimeType("application/pdf");
return Blobs.createJSONBlobFromValue(result);
/** * 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); }
Blob result = Blobs.createBlobWithExtension(".pdf"); pdfDoc.save(result.getFile()); result.setMimeType("application/pdf");
return Blobs.createJSONBlobFromValue(json);
@Override public DocumentModel createFile(String parentPath, String name) { Blob blob = Blobs.createBlob("", "application/octet-stream"); return createFile(parentPath, name, blob); }
Blob targetBlob = Blobs.createBlobWithExtension(".png"); targetBlob.setMimeType("image/png"); try (CloseableFile source = blob.getCloseableFile()) {
@OperationMethod public Blob run() throws IOException { checkAccess(); esa.dropAndInitRepositoryIndex(session.getRepositoryName(), false); String commandId = submitBulkCommand("SELECT ecm:uuid FROM Document", true); log.warn(String.format("Submitted index command: %s to index the entire %s repository.", commandId, session.getRepositoryName())); return Blobs.createJSONBlobFromValue(Collections.singletonMap("commandId", commandId)); }
public Object getValue(DocumentModel doc) { try { Blob blob = (Blob) doc.getPropertyValue("file:content"); if (blob != null) { return blob; } } catch (PropertyNotFoundException e) { // ignore } return Blobs.createBlob(""); } };
@OperationMethod public Blob run() throws IOException { List<Task> tasks = taskService.getCurrentTaskInstances(repo); if (tasks == null) { return null; } List<Map<String, Object>> rows = new ArrayList<>(); for (Task task : tasks) { DocumentModel doc = taskService.getTargetDocumentModel(task, repo); if (doc == null) { log.warn(String.format("User '%s' has a task of type '%s' on an " + "unexisting or invisible document", ctx.getPrincipal().getName(), task.getName())); continue; } DashBoardItem item = new DashBoardItemImpl(task, doc, null); Map<String, Object> obj = item.asMap(); rows.add(obj); } return Blobs.createJSONBlobFromValue(rows); }
/** * @deprecated Use addBinaryFileFromPlugin(Blob, String, String) to avoid loading the data in memory as a Bytes * array */ @Deprecated public String addBinaryFileFromPlugin(byte[] content, String mimetype, String fullName, String morePath) { Blob blob = Blobs.createBlob(content); return addBinaryFileFromPlugin(blob, fullName, morePath); }