| 1 |
0 |
package org.trails.descriptor.extension; |
| 2 |
|
|
| 3 |
|
import org.apache.commons.logging.Log; |
| 4 |
|
import org.apache.commons.logging.LogFactory; |
| 5 |
|
import org.trails.descriptor.IDescriptorExtension; |
| 6 |
|
import org.trails.exception.TrailsRuntimeException; |
| 7 |
|
|
| 8 |
0 |
public class BlobDescriptorExtension implements IDescriptorExtension |
| 9 |
|
{ |
| 10 |
0 |
protected static final Log LOG = LogFactory.getLog(BlobDescriptorExtension.class); |
| 11 |
|
|
| 12 |
0 |
public enum ContentDisposition |
| 13 |
|
{ |
| 14 |
0 |
INLINE, ATTACHMENT; |
| 15 |
|
|
| 16 |
|
public String getValue() |
| 17 |
|
{ |
| 18 |
0 |
return name().toLowerCase(); |
| 19 |
|
} |
| 20 |
|
} |
| 21 |
|
|
| 22 |
0 |
public enum RenderType |
| 23 |
|
{ |
| 24 |
0 |
IMAGE, LINK, IFRAME, ICON; |
| 25 |
|
|
| 26 |
|
public boolean isImage() |
| 27 |
|
{ |
| 28 |
0 |
return this == IMAGE; |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
public boolean isLink() |
| 32 |
|
{ |
| 33 |
0 |
return this == LINK; |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
public boolean isIFrame() |
| 37 |
|
{ |
| 38 |
0 |
return this == IFRAME; |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
public boolean isIcon() |
| 42 |
|
{ |
| 43 |
0 |
return this == ICON; |
| 44 |
|
} |
| 45 |
|
} |
| 46 |
|
|
| 47 |
0 |
private enum BlobType |
| 48 |
|
{ |
| 49 |
0 |
BYTES, ITRAILSBLOB |
| 50 |
|
} |
| 51 |
|
|
| 52 |
0 |
private BlobType blobType = BlobType.BYTES; |
| 53 |
|
|
| 54 |
0 |
private String fileName = ""; |
| 55 |
|
|
| 56 |
0 |
private String contentType = ""; |
| 57 |
|
|
| 58 |
0 |
private ContentDisposition contentDisposition = ContentDisposition.INLINE; |
| 59 |
|
|
| 60 |
0 |
private RenderType renderType = RenderType.LINK; |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
0 |
public BlobDescriptorExtension(Class beanType) |
| 66 |
|
{ |
| 67 |
0 |
if (ITrailsBlob.class.isAssignableFrom(beanType)) |
| 68 |
|
{ |
| 69 |
0 |
blobType = BlobType.ITRAILSBLOB; |
| 70 |
0 |
} else if (beanType.isArray()) |
| 71 |
|
{ |
| 72 |
0 |
blobType = BlobType.BYTES; |
| 73 |
|
} else |
| 74 |
|
{ |
| 75 |
0 |
throw new TrailsRuntimeException("type: " + beanType + " - Not supported"); |
| 76 |
|
} |
| 77 |
0 |
} |
| 78 |
|
|
| 79 |
|
public boolean isBytes() |
| 80 |
|
{ |
| 81 |
0 |
return blobType == BlobType.BYTES; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public boolean isITrailsBlob() |
| 85 |
|
{ |
| 86 |
0 |
return blobType == BlobType.ITRAILSBLOB; |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
public String getFileName() |
| 90 |
|
{ |
| 91 |
0 |
return fileName; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
public void setFileName(String fileName) |
| 95 |
|
{ |
| 96 |
0 |
this.fileName = fileName; |
| 97 |
0 |
} |
| 98 |
|
|
| 99 |
|
public String getContentType() |
| 100 |
|
{ |
| 101 |
0 |
return contentType; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
public void setContentType(String contentType) |
| 105 |
|
{ |
| 106 |
0 |
this.contentType = contentType; |
| 107 |
0 |
} |
| 108 |
|
|
| 109 |
|
public RenderType getRenderType() |
| 110 |
|
{ |
| 111 |
0 |
return renderType; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
public void setRenderType(RenderType renderType) |
| 115 |
|
{ |
| 116 |
0 |
this.renderType = renderType; |
| 117 |
0 |
} |
| 118 |
|
|
| 119 |
|
public ContentDisposition getContentDisposition() |
| 120 |
|
{ |
| 121 |
0 |
return contentDisposition; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
public void setContentDisposition(ContentDisposition contentDisposition) |
| 125 |
|
{ |
| 126 |
0 |
this.contentDisposition = contentDisposition; |
| 127 |
0 |
} |
| 128 |
|
} |