Coverage Report - org.trails.descriptor.BlobDescriptorExtension
 
Classes in this File Line Coverage Branch Coverage Complexity
BlobDescriptorExtension
0% 
0% 
0
 
 1  0
 package org.trails.descriptor;
 2  
 
 3  
 import java.lang.reflect.InvocationTargetException;
 4  
 
 5  
 import org.apache.commons.beanutils.BeanUtils;
 6  
 import org.apache.commons.logging.Log;
 7  
 import org.apache.commons.logging.LogFactory;
 8  
 import org.trails.TrailsRuntimeException;
 9  
 import org.trails.component.blob.ITrailsBlob;
 10  
 
 11  0
 public class BlobDescriptorExtension implements IDescriptorExtension,
 12  
                 IExpressionSupport {
 13  0
         protected static final Log LOG = LogFactory
 14  0
                         .getLog(BlobDescriptorExtension.class);
 15  
 
 16  
         private Class beanType;
 17  
 
 18  
         private Class propertyType;
 19  
 
 20  0
         private boolean hidden = true;
 21  
 
 22  0
         private boolean searchable = true;
 23  
 
 24  0
         private IPropertyDescriptor propertyDescriptor = null;
 25  
 
 26  0
         public enum ContentDisposition {
 27  
 
 28  0
                 INLINE("inline"), ATTACHMENT("attachment");
 29  
 
 30  0
                 private String value = "";
 31  
 
 32  0
                 ContentDisposition(String value) {
 33  0
                         this.value = value;
 34  0
                 }
 35  
 
 36  
                 public String getValue() {
 37  0
                         return value;
 38  
                 }
 39  
         }
 40  
 
 41  0
         public enum RenderType {
 42  0
                 IMAGE, LINK, IFRAME;
 43  
 
 44  
                 public boolean isImage() {
 45  0
                         return this == IMAGE;
 46  
                 }
 47  
 
 48  
                 public boolean isLink() {
 49  0
                         return this == LINK;
 50  
                 }
 51  
 
 52  
                 public boolean isIFrame() {
 53  0
                         return this == IFRAME;
 54  
                 }
 55  
         }
 56  
 
 57  0
         private enum BlobType {
 58  0
                 BYTES, ITRAILSBLOB
 59  
         }
 60  
 
 61  0
         private BlobType blobType = BlobType.BYTES;
 62  
 
 63  0
         private String fileName = "";
 64  
 
 65  0
         private String contentType = "";
 66  
 
 67  0
         private ContentDisposition contentDisposition = ContentDisposition.INLINE;
 68  
 
 69  0
         private RenderType renderType = RenderType.LINK;
 70  
 
 71  
         /**
 72  
          * 
 73  
          * @param beanType
 74  
          * @param propertyDescriptor
 75  
          */
 76  0
         public BlobDescriptorExtension(Class beanType,
 77  
                         IPropertyDescriptor propertyDescriptor) {
 78  0
                 this.beanType = beanType;
 79  0
                 this.propertyType = propertyDescriptor.getPropertyType();
 80  0
                 this.propertyDescriptor = propertyDescriptor;
 81  
 
 82  0
                 if (ITrailsBlob.class.isAssignableFrom(beanType)) {
 83  0
                         blobType = BlobType.ITRAILSBLOB;
 84  0
                 } else if (beanType.isArray()) {
 85  0
                         blobType = BlobType.BYTES;
 86  
                 } else {
 87  0
                         throw new TrailsRuntimeException("type: " + beanType
 88  0
                                         + " - Not supported");
 89  
                 }
 90  0
         }
 91  
 
 92  
         /**
 93  
          * 
 94  
          * @param dto
 95  
          */
 96  0
         public BlobDescriptorExtension(BlobDescriptorExtension dto) {
 97  
                 try {
 98  0
                         BeanUtils.copyProperties(this, dto);
 99  0
                 } catch (IllegalAccessException e) {
 100  0
                         LOG.error(e.getMessage());
 101  0
                         e.printStackTrace();
 102  0
                 } catch (InvocationTargetException e) {
 103  0
                         LOG.error(e.getMessage());
 104  0
                         e.printStackTrace();
 105  0
                 } catch (Exception e) {
 106  0
                         LOG.error(e.toString());
 107  0
                         e.printStackTrace();
 108  
                 }
 109  0
         }
 110  
 
 111  
         public boolean isBytes() {
 112  0
                 return blobType == BlobType.BYTES;
 113  
         }
 114  
 
 115  
         public boolean isITrailsBlob() {
 116  0
                 return blobType == BlobType.ITRAILSBLOB;
 117  
         }
 118  
 
 119  
         public String getFileName() {
 120  0
                 return fileName;
 121  
         }
 122  
 
 123  
         public void setFileName(String fileName) {
 124  0
                 this.fileName = fileName;
 125  0
         }
 126  
 
 127  
         public String getContentType() {
 128  0
                 return contentType;
 129  
         }
 130  
 
 131  
         public void setContentType(String contentType) {
 132  0
                 this.contentType = contentType;
 133  0
         }
 134  
 
 135  
         public RenderType getRenderType() {
 136  0
                 return renderType;
 137  
         }
 138  
 
 139  
         public void setRenderType(RenderType renderType) {
 140  0
                 this.renderType = renderType;
 141  0
         }
 142  
 
 143  
         public ContentDisposition getContentDisposition() {
 144  0
                 return contentDisposition;
 145  
         }
 146  
 
 147  
         public void setContentDisposition(ContentDisposition contentDisposition) {
 148  0
                 this.contentDisposition = contentDisposition;
 149  0
         }
 150  
 
 151  
         /**
 152  
          * Overrides
 153  
          */
 154  
         @Override
 155  
         public Object clone() {
 156  0
                 return new BlobDescriptorExtension(this);
 157  
         }
 158  
 
 159  
         public void copyFrom (IDescriptor descriptor) {
 160  
 
 161  
                 try {
 162  0
                         BeanUtils.copyProperties(this, (BlobDescriptorExtension)descriptor);
 163  0
                 } catch (IllegalAccessException e) {
 164  0
                         LOG.error(e.getMessage());
 165  0
                         e.printStackTrace();
 166  0
                 } catch (InvocationTargetException e) {
 167  0
                         LOG.error(e.getMessage());
 168  0
                         e.printStackTrace();
 169  0
                 } catch (Exception e) {
 170  0
                         LOG.error(e.toString());
 171  0
                         e.printStackTrace();
 172  
                 }
 173  0
         }
 174  
 
 175  
         /**
 176  
          * Interface Implementation
 177  
          */
 178  
 
 179  
         public String findAddExpression() {
 180  0
                 return getExpression("");
 181  
         }
 182  
 
 183  
         public String findRemoveExpression() {
 184  0
                 return getExpression("");
 185  
         }
 186  
 
 187  
         public String getExpression(String method) {
 188  0
                 return getPropertyDescriptor().getName();
 189  
         }
 190  
 
 191  
         public Class getBeanType() {
 192  0
                 return beanType;
 193  
         }
 194  
 
 195  
         public void setBeanType(Class beanType) {
 196  0
                 this.beanType = beanType;
 197  0
         }
 198  
 
 199  
         public Class getPropertyType() {
 200  0
                 return propertyType;
 201  
         }
 202  
 
 203  
         public void setPropertyType(Class propertyType) {
 204  0
                 this.propertyType = propertyType;
 205  0
         }
 206  
 
 207  
         public boolean isSearchable() {
 208  0
                 return searchable;
 209  
         }
 210  
 
 211  
         public void setSearchable(boolean searchable) {
 212  0
                 this.searchable = searchable;
 213  0
         }
 214  
 
 215  
         public IPropertyDescriptor getPropertyDescriptor() {
 216  0
                 return propertyDescriptor;
 217  
         }
 218  
 
 219  
         public void setPropertyDescriptor(IPropertyDescriptor propertyDescriptor) {
 220  0
                 this.propertyDescriptor = propertyDescriptor;
 221  0
         }
 222  
 
 223  
         public boolean isHidden() {
 224  0
                 return hidden;
 225  
         }
 226  
 
 227  
         public void setHidden(boolean hidden) {
 228  0
                 this.hidden = hidden;
 229  0
         }
 230  
 }