1 package com.dotmarketing.portlets.files.model; 2 3 import java.io.Serializable ; 4 import java.util.Map ; 5 6 import org.apache.commons.lang.builder.EqualsBuilder; 7 import org.apache.commons.lang.builder.HashCodeBuilder; 8 import org.apache.commons.lang.builder.ToStringBuilder; 9 10 import com.dotmarketing.beans.Identifier; 11 import com.dotmarketing.beans.WebAsset; 12 import com.dotmarketing.factories.IdentifierFactory; 13 import com.dotmarketing.portlets.folders.model.Folder; 14 import com.dotmarketing.util.Logger; 15 import com.dotmarketing.util.UtilMethods; 16 17 18 public class File extends WebAsset implements Serializable , Comparable { 19 20 private static final long serialVersionUID = 1L; 21 22 23 private long parent; 24 25 26 private String fileName; 27 28 29 private int size; 30 31 32 private int height; 33 34 35 private int width; 36 37 38 private String mimeType; 39 40 41 private String author; 42 43 44 private java.util.Date publishDate; 45 46 47 private int maxSize; 48 49 private int maxHeight; 50 51 private int maxWidth; 52 53 private int minHeight; 54 55 56 private String [] categories; 57 58 59 public File() { 60 super.setType("file_asset"); 61 super.setModDate(new java.util.Date ()); 62 publishDate = new java.util.Date (); 63 } 64 65 public String getURI(Folder folder) { 66 return folder.getPath() + this.getFileName(); 67 } 68 public String getURI() { 69 Identifier id = IdentifierFactory.getIdentifierByInode(this); 70 return id.getURI(); 71 72 73 } 74 75 public long getInode() { 76 return this.inode; 77 } 78 79 public void setInode(long inode) { 80 this.inode = inode; 81 } 82 public java.lang.String getFileName() { 83 return this.fileName; 84 } 85 86 public void setFileName(java.lang.String fileName) { 87 this.fileName = fileName; 88 } 89 public int getSize() { 90 return this.size; 91 } 92 93 public void setSize(int size) { 94 this.size = size; 95 } 96 public String toString() { 97 return ToStringBuilder.reflectionToString(this); 98 } 99 100 public boolean equals(Object other) { 101 if ( !(other instanceof File) ) return false; 102 File castOther = (File) other; 103 return new EqualsBuilder() 104 .append(this.inode, castOther.inode) 105 .isEquals(); 106 } 107 108 public int hashCode() { 109 return new HashCodeBuilder() 110 .append(inode) 111 .toHashCode(); 112 } 113 114 118 public int getMaxHeight() { 119 return maxHeight; 120 } 121 122 126 public int getMaxSize() { 127 return maxSize; 128 } 129 130 134 public int getMaxWidth() { 135 return maxWidth; 136 } 137 138 142 public int getMinHeight() { 143 return minHeight; 144 } 145 146 150 public void setMaxHeight(int maxHeight) { 151 this.maxHeight = maxHeight; 152 } 153 154 158 public void setMaxSize(int maxSize) { 159 this.maxSize = maxSize; 160 } 161 162 166 public void setMaxWidth(int maxWidth) { 167 this.maxWidth = maxWidth; 168 } 169 170 174 public void setMinHeight(int minHeight) { 175 this.minHeight = minHeight; 176 } 177 178 182 public long getParent() { 183 return parent; 184 } 185 186 190 public void setParent(long parent) { 191 this.parent = parent; 192 } 193 194 public void copy(File newFile) { 196 this.setParent(newFile.getParent()); 197 this.setFileName(newFile.getFileName()); 198 this.setSize(newFile.getSize()); 199 this.setMimeType(newFile.getMimeType()); 200 this.setWidth(newFile.getWidth()); 201 this.setHeight(newFile.getHeight()); 202 super.copy(newFile); 203 } 204 208 public String getMimeType() { 209 return mimeType; 210 } 211 212 216 public void setMimeType(String mimeType) { 217 this.mimeType = mimeType; 218 } 219 220 224 public int getHeight() { 225 return height; 226 } 227 228 232 public int getWidth() { 233 return width; 234 } 235 236 public String getExtension(){ 237 return UtilMethods.getFileExtension(fileName); 238 239 } 240 241 public java.lang.String getNameOnly() { 242 return UtilMethods.getFileName(fileName); 243 } 244 245 249 public void setHeight(int height) { 250 this.height = height; 251 } 252 253 257 public void setWidth(int width) { 258 this.width = width; 259 } 260 261 public int compareTo(Object compObject){ 262 263 if(!(compObject instanceof File))return -1; 264 265 File file = (File) compObject; 266 return (file.getFileName().compareTo(this.getFileName())); 267 268 } 269 270 274 public String getAuthor() { 275 return author; 276 } 277 278 282 public java.util.Date getPublishDate() { 283 return publishDate; 284 } 285 286 290 public void setAuthor(String author) { 291 this.author = author; 292 } 293 294 298 public void setPublishDate(java.util.Date publishDate) { 299 this.publishDate = publishDate; 300 } 301 302 306 public String [] getCategories() { 307 return categories; 308 } 309 310 314 public void setCategories(String [] categories) { 315 Logger.debug(this, "\n\nFile setCategories=" + categories.length); 316 this.categories = categories; 317 } 318 319 322 public Map <String , Object > getMap () { 323 Map <String , Object > map = super.getMap(); 324 map.put("parent", parent); 325 map.put("fileName", fileName); 326 map.put("extension", getExtension()); 327 map.put("size", size); 328 map.put("height", height); 329 map.put("width", width); 330 map.put("maxHeight", maxHeight); 331 map.put("maxSize", maxSize); 332 map.put("publishDate", publishDate); 333 map.put("author", author); 334 map.put("maxWidth", maxWidth); 335 map.put("minHeight", minHeight); 336 map.put("categories", categories); 337 return map; 338 } 339 } 340 | Popular Tags |