@Override public long getLength() { return blob.getLength(); }
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 long getSize(Blob arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) { long n = arg0.getLength(); return n <= 0 ? -1 : n; }
protected long getSizeOfBlobs(List<Blob> blobs) { int size = 0; if (blobs != null) { for (Blob blob : blobs) { long blobLength = blob.getLength(); if (blobLength > -1) { size += blobLength; } } } return size; }
/** * Avoid checkin for a 0-length blob. Microsoft-WebDAV-MiniRedir first creates a 0-length file and then locks it * before putting the real file. But we don't want this first placeholder to cause a versioning event. * * @deprecated since 9.1 automatic versioning is now handled at versioning service level, remove versioning * behaviors from importers */ @Deprecated protected boolean skipCheckInForBlob(Blob blob) { return blob == null || blob.getLength() == 0; }
@Override public long getSize(DocumentBlobHolder blobHolder, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { long n = blobHolder.getBlob().getLength(); return n < 0 ? -1 : n; }
@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); } }
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); }
public static void updateVideoInfo(DocumentModel docModel, Blob video) { VideoInfo videoInfo = getVideoInfo(video); if (videoInfo == null || video.getLength() == 0) { docModel.setPropertyValue("vid:info", (Serializable) VideoInfo.EMPTY_INFO.toMap()); return; } docModel.setPropertyValue("vid:info", (Serializable) videoInfo.toMap()); }
jg.writeStringField("digest", v); jg.writeStringField("length", Long.toString(blob.getLength()));
@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); } }
if (result != null && result.getBlob() != null && result.getBlob().getLength() > 0) { PictureResourceAdapter picture = docModel.getAdapter(PictureResourceAdapter.class); try {
public static VideoInfo getVideoInfo(Blob video) { if (video == null || video.getLength() == 0) { return null; } try { ExecResult result; try (CloseableFile cf = video.getCloseableFile("." + FilenameUtils.getExtension(video.getFilename()))) { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", cf.getFile().getAbsolutePath()); // read the duration with a first command to adjust the best rate: result = cles.execCommand(FFMPEG_INFO_COMMAND_LINE, params); } if (!result.isSuccessful()) { throw result.getError(); } return VideoInfo.fromFFmpegOutput(result.getOutput()); } catch (CommandNotAvailable | CommandException | IOException e) { throw new NuxeoException(e); } }
/** * @param childComment * @return */ protected JSONArray buildFilesInfos(DocumentModel childComment) { // Attached files List<Map<String, Object>> attachedFiles = (List<Map<String, Object>>) childComment.getPropertyValue("files:files"); JSONArray files = new JSONArray(); int index = 0; for (Map<String, Object> attachedFile : attachedFiles) { // File infos JSONObject fileInfos = new JSONObject(); Blob file = (Blob) attachedFile.get("file"); fileInfos.element("index", index); fileInfos.element("filename", file.getFilename()); fileInfos.element("mime-type", file.getMimeType()); fileInfos.element("length", file.getLength()); files.add(fileInfos); index++; } return files; }
if (blob.getLength() > Functions.getBigFileSizeLimit()) { FacesContext context = FacesContext.getCurrentInstance(); String bigDownloadURL = BaseURL.getBaseURL() + "/" + downloadService.getDownloadUrl(doc, xpath, filename);
protected PropStatBuilderExt getPropStatBuilderExt(DocumentModel doc, UriInfo uriInfo) { Date lastModified = getTimePropertyWrapper(doc, "dc:modified"); Date creationDate = getTimePropertyWrapper(doc, "dc:created"); String displayName = EscapeUtils.encodePath(backend.getDisplayName(doc)); PropStatBuilderExt props = new PropStatBuilderExt(); props.lastModified(lastModified).creationDate(creationDate).displayName(displayName).status(OK); if (doc.isFolder()) { props.isCollection(); } else { String mimeType = "application/octet-stream"; long size = 0; BlobHolder bh = doc.getAdapter(BlobHolder.class); if (bh != null) { Blob blob = bh.getBlob(); if (blob != null) { size = blob.getLength(); mimeType = blob.getMimeType(); } } if (StringUtils.isEmpty(mimeType) || "???".equals(mimeType)) { mimeType = "application/octet-stream"; } props.isResource(size, mimeType); } return props; }
Blob originalBlob; if (originalVideo == null || (originalBlob = originalVideo.getBlob()) == null || originalBlob.getLength() == 0) { resetTranscodedVideos(doc); return;
private void fetchInfoFromDoc(CoreSession session, DocumentModel doc) { if (includeBlob) { BlobHolder bh = doc.getAdapter(BlobHolder.class); if (bh != null) { List<Blob> blobs = bh.getBlobs(); if (blobs != null) { for (Blob blob : blobs) { if (blob != null) { hostTask.getInfo().addBlob(blob.getLength(), doc.getPath()); } } } } } if (doc.isVersion()) { hostTask.getInfo().addDoc(doc.getType(), doc.getPath(), true); } else { hostTask.getInfo().addDoc(doc.getType(), doc.getPath()); List<DocumentModel> versions = session.getVersions(doc.getRef()); for (DocumentModel version : versions) { fetchInfoFromDoc(session, version); } } }
private void fetchInfoFromDoc(CoreSession session, DocumentModel doc) { if (includeBlob) { BlobHolder bh = doc.getAdapter(BlobHolder.class); if (bh != null) { List<Blob> blobs = bh.getBlobs(); if (blobs != null) { for (Blob blob : blobs) { if (blob != null) { hostTask.getInfo().addBlob(blob.getLength(), doc.getPath()); } } } } } if (doc.isVersion()) { hostTask.getInfo().addDoc(doc.getType(), doc.getPath(), true); } else { hostTask.getInfo().addDoc(doc.getType(), doc.getPath()); List<DocumentModel> versions = session.getVersions(doc.getRef()); for (DocumentModel version : versions) { fetchInfoFromDoc(session, version); } } }