1 20 package org.jahia.data.files; 21 22 import java.util.Properties ; 23 24 import org.jahia.utils.JahiaTools; 25 26 33 public class JahiaFileField extends JahiaFile implements Cloneable { 34 35 static public String FIELD_FILE_TITLE_PROP = "field_file_title"; 36 static public String FIELD_FILE_FILEID_PROP = "field_file_fileid"; 37 static public String FIELD_FILE_VERSION_PROP = "field_file_version"; 38 39 40 private int id = -1; 41 42 private Properties properties = new Properties (); 43 44 48 protected JahiaFileField(){ 49 } 50 51 56 public JahiaFileField( JahiaFile fileItem, 57 Properties properties ){ 58 if ( properties != null ){ 59 this.properties = properties; 60 } 61 62 if ( fileItem != null ){ 63 setFile(fileItem); 64 } 65 66 if ( this.getFileFieldTitle() == null 68 || "".equals(this.getFileFieldTitle()) ){ 69 this.setFileFieldTitle(fileItem.getTitle()); 70 } 71 72 } 73 74 public int getID(){ 75 return this.id; 76 } 77 78 public void setID(int id){ 79 this.id = id; 80 } 81 82 public void setFile(JahiaFile fileItem){ 83 if ( fileItem == null ){ 84 return; 85 } 86 setFileID(fileItem.getFileID()); 87 setFilemanagerID(fileItem.getFilemanagerID()); 88 setFolderID(fileItem.getFolderID()); 89 setUploadUser(fileItem.getUploadUser()); 90 setRealName(fileItem.getRealName()); 91 setStorageName(fileItem.getStorageName()); 92 setLastModifDate(fileItem.getLastModifDate()); 93 setSize(fileItem.getSize()); 94 setType(fileItem.getType()); 95 setTitle(fileItem.getTitle()); 96 setDescr(fileItem.getDescr()); 97 setVersion(fileItem.getVersion()); 98 setState(fileItem.getState()); 99 100 this.setProperty(JahiaFileField.FIELD_FILE_FILEID_PROP, 101 String.valueOf(fileItem.getFileID())); 102 103 this.setProperty(JahiaFileField.FIELD_FILE_VERSION_PROP,fileItem.getVersion()); 104 105 if ( this.getFileFieldTitle() == null ){ 106 this.setFileFieldTitle(fileItem.getTitle()); 107 } 108 109 } 110 111 public String getFileFieldTitle(){ 112 if ( properties == null ){ 113 return null; 114 } 115 return JahiaTools.text2html((String )properties.get(FIELD_FILE_TITLE_PROP)); 116 } 117 118 public void setFileFieldTitle(String title){ 119 if ( title == null ){ 120 return; 121 } 122 setProperty(FIELD_FILE_TITLE_PROP,title); 123 } 124 125 public void setProperty(String name, String value){ 126 if ( properties == null ){ 127 properties = new Properties (); 128 } 129 properties.setProperty(name,value); 130 } 131 132 public Properties getProperties(){ 133 return this.properties; 134 } 135 136 public void setProperties(Properties properties){ 137 if ( properties != null ){ 138 this.properties = properties; 139 } 140 } 141 142 public Object clone(){ 143 144 JahiaFile file = 145 new JahiaFile(this.getFilemanagerID(), 146 this.getFolderID(),this.getUploadUser(),this.getRealName(), 147 this.getStorageName(),this.getLastModifDate(),this.getSize(), 148 this.getType(),this.getTitle(),this.getDescr(),this.getVersion(),this.getState()); 149 file.setFileID(this.getFileID()); 150 151 Properties props = (Properties )this.properties.clone(); 152 153 JahiaFileField clone = new JahiaFileField(file,props); 154 155 return clone; 156 } 157 } | Popular Tags |