public static boolean matchAttachmentId(Attachment at, String value) { if (value.isEmpty()) { return true; } if (at.getContentId().equals(value)) { return true; } ContentDisposition cd = at.getContentDisposition(); return cd != null && value.equals(cd.getParameter("name")); }
public Attachment getAttachment(String contentId) { for (Attachment a : atts) { if (contentId.equalsIgnoreCase(a.getContentId())) { return a; } ContentDisposition cd = a.getContentDisposition(); if (cd != null && contentId.equals(cd.getParameter("name"))) { return a; } } return null; }
public static boolean matchAttachmentId(Attachment at, String value) { if (value.isEmpty()) { return true; } if (at.getContentId().equals(value)) { return true; } ContentDisposition cd = at.getContentDisposition(); if (cd != null && value.equals(cd.getParameter("name"))) { return true; } return false; }
public Attachment getAttachment(String contentId) { for (Attachment a : atts) { if (contentId.equalsIgnoreCase(a.getContentId())) { return a; } ContentDisposition cd = a.getContentDisposition(); if (cd != null && contentId.equals(cd.getParameter("name"))) { return a; } } return null; }
private static Map<String, Attachment> fromListToMap(List<Attachment> atts, boolean preferContentDisposition) { Map<String, Attachment> map = new LinkedHashMap<>(); for (Attachment a : atts) { String contentId = null; if (preferContentDisposition) { ContentDisposition cd = a.getContentDisposition(); if (cd != null) { contentId = cd.getParameter("name"); } } if (contentId == null) { contentId = a.getContentId(); } map.put(contentId, a); } return map; }
private static Map<String, Attachment> fromListToMap(List<Attachment> atts, boolean preferContentDisposition) { Map<String, Attachment> map = new LinkedHashMap<String, Attachment>(); for (Attachment a : atts) { String contentId = null; if (preferContentDisposition) { ContentDisposition cd = a.getContentDisposition(); if (cd != null) { contentId = cd.getParameter("name"); } } if (contentId == null) { contentId = a.getContentId(); } map.put(contentId, a); } return map; }
att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj);
@POST @Path("/books/attachments") @Produces("text/xml") public Response addBookFromAttachments() throws Exception { Collection<Attachment> handlers = AttachmentUtils.getChildAttachments(context); for (Attachment a : handlers) { if ("book2".equals(a.getContentId())) { return readBookFromInputStream(a.getDataHandler().getInputStream()); } } throw new WebApplicationException(500); }
att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj);
@POST @Path("/books/formimage") @Consumes("multipart/form-data") @Produces("multipart/form-data") public MultipartBody addBookFormImage(MultipartBody image) throws Exception { List<Attachment> atts = image.getAllAttachments(); if (atts.size() != 1) { throw new WebApplicationException(); } List<Attachment> newAtts = new ArrayList<>(); Attachment at = atts.get(0); MultivaluedMap<String, String> headers = at.getHeaders(); if (!"http://host/bar".equals(headers.getFirst("Content-Location"))) { throw new WebApplicationException(); } if (!"custom".equals(headers.getFirst("Custom-Header"))) { throw new WebApplicationException(); } headers.putSingle("Content-Location", "http://host/location"); newAtts.add(new Attachment(at.getContentId(), at.getDataHandler(), headers)); return new MultipartBody(newAtts); }
AttachmentImpl att = new AttachmentImpl(handler.getContentId(), handler.getDataHandler()); for (String key : handler.getHeaders().keySet()) { att.setHeader(key, handler.getHeader(key));
AttachmentImpl att = new AttachmentImpl(handler.getContentId(), handler.getDataHandler()); for (String key : handler.getHeaders().keySet()) { att.setHeader(key, handler.getHeader(key));
String contentId = a.getContentId(); String name = StringUtils.isEmpty(cdName) ? contentId : cdName.replace("\"", "").replace("'", ""); if (StringUtils.isEmpty(name)) {
String contentId = a.getContentId(); String name = StringUtils.isEmpty(cdName) ? contentId : cdName.replace("\"", "").replace("'", ""); if (StringUtils.isEmpty(name)) {