1 13 package info.magnolia.cms.beans.runtime; 14 15 import java.io.FileInputStream ; 16 import java.io.FileNotFoundException ; 17 import java.io.IOException ; 18 import java.io.InputStream ; 19 20 import org.apache.commons.lang.StringUtils; 21 22 23 28 public class Document { 29 30 33 private String atomName; 34 35 38 private String fileName; 39 40 43 private String extension; 44 45 48 private String type; 49 50 53 private java.io.File file; 54 55 58 private FileInputStream inputStream; 59 60 63 Document() { 64 } 65 66 70 public void setAtomName(String name) { 71 this.atomName = name; 72 } 73 74 78 public String getAtomName() { 79 return this.atomName; 80 } 81 82 86 public void setFileName(String name) { 87 this.fileName = name; 88 } 89 90 94 public String getFileName() { 95 return this.fileName; 96 } 97 98 102 public String getFileNameWithExtension() { 103 if (StringUtils.isEmpty(this.extension)) { 104 return this.fileName; 105 } 106 107 return this.fileName + "." + this.extension; } 109 110 114 public void setType(String type) { 115 this.type = type; 116 } 117 118 122 public String getType() { 123 return this.type; 124 } 125 126 130 public void setFile(java.io.File in) { 131 this.file = in; 132 } 133 134 138 public void setExtention(String ext) { 139 this.extension = ext; 140 } 141 142 146 public String getExtension() { 147 return this.extension; 148 } 149 150 154 public long getLength() { 155 return this.file.length(); 156 } 157 158 163 public InputStream getStream() { 164 try { 165 return (this.inputStream = (new FileInputStream (this.file))); 166 } 167 catch (FileNotFoundException e) { 168 return null; 169 } 170 } 171 172 177 public java.io.File getFile() { 178 return this.file; 179 } 180 181 184 public void delete() { 185 if (this.inputStream != null) { 186 try { 187 this.inputStream.close(); 188 } 189 catch (IOException e) { 190 } 192 } 193 this.file.delete(); 194 } 195 } 196 | Popular Tags |