1 23 package org.infoglue.deliver.taglib.content; 24 25 import java.io.File ; 26 27 import javax.servlet.jsp.JspException ; 28 import javax.servlet.jsp.JspTagException ; 29 30 import org.apache.commons.fileupload.FileItem; 31 import org.infoglue.cms.io.FileHelper; 32 import org.infoglue.cms.webservices.elements.RemoteAttachment; 33 import org.infoglue.deliver.taglib.AbstractTag; 34 35 41 42 public class DigitalAssetParameterTag extends AbstractTag 43 { 44 47 private static final long serialVersionUID = 4482006814634520239L; 48 49 52 private String assetKey; 53 54 57 private String fileName; 58 59 62 private String filePath; 63 64 67 private String contentType; 68 69 72 private byte[] bytes; 73 74 77 private File file; 78 79 82 private FileItem fileItem; 83 84 87 public DigitalAssetParameterTag() 88 { 89 super(); 90 } 91 92 99 public int doEndTag() throws JspException 100 { 101 addDigitalAsset(); 102 return EVAL_PAGE; 103 } 104 105 110 protected void addDigitalAsset() throws JspException 111 { 112 final ContentVersionParameterInterface parent = (ContentVersionParameterInterface) findAncestorWithClass(this, ContentVersionParameterInterface.class); 113 if(parent == null) 114 { 115 throw new JspTagException ("DigitalAssetParameterTag must have a ContentVersionParameterInterface ancestor."); 116 } 117 118 if(bytes != null) 119 { 120 } 121 else if(file != null) 122 { 123 try 124 { 125 this.bytes = FileHelper.getFileBytes(file); 126 } 127 catch (Exception e) 128 { 129 e.printStackTrace(); 130 } 131 } 132 else if(fileItem != null) 133 { 134 try 135 { 136 this.bytes = fileItem.get(); 137 } 138 catch (Exception e) 139 { 140 e.printStackTrace(); 141 } 142 } 143 else 144 { 145 throw new JspException ("Must state either bytes, a file or a fileItem"); 146 } 147 148 RemoteAttachment attachment = new RemoteAttachment(this.assetKey, this.fileName, this.filePath, this.contentType, this.bytes); 149 150 ((ContentVersionParameterInterface) parent).addDigitalAsset(attachment); 151 } 152 153 159 public void setAssetKey(final String assetKey) throws JspException 160 { 161 this.assetKey = evaluateString("parameter", "assetKey", assetKey); 162 } 163 164 170 public void setFileName(final String fileName) throws JspException 171 { 172 this.fileName = evaluateString("parameter", "fileName", fileName); 173 } 174 175 181 public void setFilePath(final String filePath) throws JspException 182 { 183 this.filePath = evaluateString("parameter", "filePath", filePath); 184 } 185 186 192 public void setContentType(final String contentType) throws JspException 193 { 194 this.contentType = evaluateString("parameter", "contentType", contentType); 195 } 196 197 203 public void setBytes(final String bytes) throws JspException 204 { 205 this.bytes = (byte[]) evaluate("addAttachment", "bytes", bytes, Object .class); 206 } 207 208 214 public void setFile(final String file) throws JspException 215 { 216 this.file = (File ) evaluate("addAttachment", "file", file, Object .class); 217 } 218 219 225 public void setFileItem(final String fileItem) throws JspException 226 { 227 this.fileItem = (FileItem) evaluate("addAttachment", "fileItem", fileItem, Object .class); 228 } 229 230 } 231 | Popular Tags |