@Override public void setEncoding(String encoding) { blob.setEncoding(encoding); }
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); } }
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); } }
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; }
@Override public String getContent() { String encoding = "unset"; try { Blob blob = (Blob) doc.getPropertyValue("file:content"); if (blob == null) { return ""; } encoding = blob.getEncoding(); if (encoding == null || encoding.equals("")) { blob.setEncoding("utf-8"); } return blob.getString(); } catch (IOException | PropertyException e) { log.error("Error while reading content with encoding " + encoding, e); return "ERROR : " + e.getMessage(); } }
@Override public String getXmlFileContent() throws IOException { try { Blob xml = safeGet(Blob.class, "file:content", null); if (xml.getEncoding() == null || "".equals(xml.getEncoding())) { xml.setEncoding("utf-8"); } return xml.getString(); } catch (IOException e) { log.error("Error while reading blob", e); return ""; } }
@Override @SuppressWarnings("unchecked") public Map<String, String> getAttachments() { Map<String, String> attachments = new LinkedMap(); try { List<Map<String, Serializable>> atts = (List<Map<String, Serializable>>) doc.getPropertyValue("files:files"); if (atts != null) { for (Map<String, Serializable> att : atts) { Blob attBlob = (Blob) att.get("file"); if (attBlob.getEncoding() == null || attBlob.getEncoding().equals("")) { attBlob.setEncoding("utf-8"); } attachments.put((String) att.get("filename"), attBlob.getString()); } } } catch (IOException | PropertyException e) { log.error("Error while reading Attachments", e); } return attachments; }
@Override public String getManifest() { try { Blob mf = safeGet(Blob.class, "file:content", null); if (mf == null) { return "No MANIFEST.MF"; } if (mf.getEncoding() == null || "".equals(mf.getEncoding())) { mf.setEncoding("utf-8"); } return mf.getString(); } catch (IOException e) { log.error("Error while reading blob", e); return ""; } }
@Override public String getXml() { try { Blob xml = safeGet(Blob.class, "file:content", null); if (xml == null) { return ""; } if (xml.getEncoding() == null || "".equals(xml.getEncoding())) { xml.setEncoding("utf-8"); } return xml.getString(); } catch (IOException e) { log.error("Error while reading blob", e); return ""; } }
blob.setEncoding(encoding); blob.setMimeType(mimetype); document.setProperty("file", "content", blob);
newBlob.setEncoding(UTF_8); newBlob.setFilename(blob.getFilename()); return newBlob;
blob.setEncoding(encoding); blob.setFilename(filename); return blob;
blob.setEncoding(encoding); blob.setFilename(filename); return blob;
newBlob.setEncoding(blob.getEncoding()); newBlob.setFilename(blob.getFilename()); return newBlob;