1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.ws.cxf;
17
18 import javax.activation.DataHandler;
19 import javax.xml.bind.attachment.AttachmentMarshaller;
20
21
22
23
24
25
26
27 public class NonReadingAttachmentMarshaller extends AttachmentMarshaller {
28 @Override
29 public boolean isXOPPackage() {
30 return true;
31 }
32
33 @Override
34 public String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName) {
35 return attachmentDescription(data.getName(), null, data.getContentType());
36 }
37
38 @Override
39 public String addMtomAttachment(byte[] data, int offset, int length, String mimeType,
40 String elementNamespace, String elementLocalName)
41 {
42 String size = Integer.toString(Math.min(length, data.length - offset));
43 return attachmentDescription(null, size, mimeType);
44 }
45
46 @Override
47 public String addSwaRefAttachment(DataHandler data) {
48 return attachmentDescription(data.getName(), null, data.getContentType());
49 }
50
51 private static String attachmentDescription(String name, String size, String contentType) {
52 return "Attachment: name='" + name != null ? name : "[unknown]" +
53 "', size='" + size != null ? size : "[unknown]" +
54 "', content type='" + contentType != null ? contentType : "[unknown]" + '\'';
55 }
56
57 }