1 17 package org.alfresco.web.bean.wizard; 18 19 import java.io.File ; 20 import java.io.Serializable ; 21 import java.text.MessageFormat ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.ResourceBundle ; 25 26 import javax.faces.context.FacesContext; 27 28 import org.alfresco.model.ContentModel; 29 import org.alfresco.repo.content.MimetypeMap; 30 import org.alfresco.repo.content.filestore.FileContentReader; 31 import org.alfresco.service.cmr.repository.ContentReader; 32 import org.alfresco.service.namespace.QName; 33 import org.alfresco.web.app.Application; 34 import org.alfresco.web.bean.FileUploadBean; 35 import org.alfresco.web.bean.repository.Repository; 36 37 42 public class AddContentWizard extends BaseContentWizard 43 { 44 private static final String WIZARD_TITLE_ID = "add_content_title"; 46 private static final String WIZARD_DESC_ID = "add_content_desc"; 47 private static final String STEP1_TITLE_ID = "add_conent_step1_title"; 48 private static final String STEP1_DESCRIPTION_ID = "add_conent_step1_desc"; 49 private static final String STEP2_TITLE_ID = "add_conent_step2_title"; 50 private static final String STEP2_DESCRIPTION_ID = "add_conent_step2_desc"; 51 52 private File file; 54 55 56 59 public String next() 60 { 61 String outcome = super.next(); 62 63 if (outcome.equals("properties")) 66 { 67 this.contentType = Repository.getMimeTypeForFileName( 68 FacesContext.getCurrentInstance(), this.fileName); 69 70 this.inlineEdit = (this.contentType.equals(MimetypeMap.MIMETYPE_HTML)); 72 73 ContentReader cr = new FileContentReader(this.file); 75 cr.setMimetype(this.contentType); 76 Map <QName, Serializable > contentProps = new HashMap <QName, Serializable >(5, 1.0f); 78 79 if (Repository.extractMetadata(FacesContext.getCurrentInstance(), cr, contentProps)) 80 { 81 this.author = (String )(contentProps.get(ContentModel.PROP_AUTHOR)); 82 this.title = (String )(contentProps.get(ContentModel.PROP_TITLE)); 83 this.description = (String )(contentProps.get(ContentModel.PROP_DESCRIPTION)); 84 } 85 if (this.title == null) 86 { 87 this.title = this.fileName; 88 } 89 } 90 91 return outcome; 92 } 93 94 99 public String finish() 100 { 101 String outcome = saveContent(this.file, null); 102 103 if (this.editMode) 106 { 107 this.browseBean.getDocument().reset(); 108 } 109 110 return outcome; 111 } 112 113 116 public String getWizardDescription() 117 { 118 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID); 119 } 120 121 124 public String getWizardTitle() 125 { 126 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID); 127 } 128 129 132 public String getStepDescription() 133 { 134 String stepDesc = null; 135 136 switch (this.currentStep) 137 { 138 case 1: 139 { 140 stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID); 141 break; 142 } 143 case 2: 144 { 145 stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID); 146 break; 147 } 148 case 3: 149 { 150 stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID); 151 break; 152 } 153 default: 154 { 155 stepDesc = ""; 156 } 157 } 158 159 return stepDesc; 160 } 161 162 165 public String getStepTitle() 166 { 167 String stepTitle = null; 168 169 switch (this.currentStep) 170 { 171 case 1: 172 { 173 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID); 174 break; 175 } 176 case 2: 177 { 178 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID); 179 break; 180 } 181 case 3: 182 { 183 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID); 184 break; 185 } 186 default: 187 { 188 stepTitle = ""; 189 } 190 } 191 192 return stepTitle; 193 } 194 195 198 public void init() 199 { 200 super.init(); 201 202 clearUpload(); 203 204 this.file = null; 205 } 206 207 210 public String getFileUploadSuccessMsg() 211 { 212 String msg = Application.getMessage(FacesContext.getCurrentInstance(), "file_upload_success"); 213 return MessageFormat.format(msg, new Object [] {getFileName()}); 214 } 215 216 219 public String getFileName() 220 { 221 FacesContext ctx = FacesContext.getCurrentInstance(); 224 FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap(). 225 get(FileUploadBean.FILE_UPLOAD_BEAN_NAME); 226 if (fileBean != null) 227 { 228 this.file = fileBean.getFile(); 229 this.fileName = fileBean.getFileName(); 230 } 231 232 return this.fileName; 233 } 234 235 238 public void setFileName(String fileName) 239 { 240 this.fileName = fileName; 241 242 FacesContext ctx = FacesContext.getCurrentInstance(); 244 FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap(). 245 get(FileUploadBean.FILE_UPLOAD_BEAN_NAME); 246 if (fileBean != null) 247 { 248 fileBean.setFileName(this.fileName); 249 } 250 } 251 252 255 public String getSummary() 256 { 257 ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); 258 259 return buildSummary( 260 new String [] {bundle.getString("file_name"), bundle.getString("type"), 261 bundle.getString("content_type"), bundle.getString("title"), 262 bundle.getString("description"), bundle.getString("author"), 263 bundle.getString("inline_editable")}, 264 new String [] {this.fileName, getSummaryObjectType(), getSummaryContentType(), this.title, 265 this.description, this.author, Boolean.toString(this.inlineEdit)}); 266 } 267 268 271 protected String determineOutcomeForStep(int step) 272 { 273 String outcome = null; 274 275 switch(step) 276 { 277 case 1: 278 { 279 outcome = "upload"; 280 break; 281 } 282 case 2: 283 { 284 outcome = "properties"; 285 break; 286 } 287 case 3: 288 { 289 outcome = "summary"; 290 break; 291 } 292 default: 293 { 294 outcome = CANCEL_OUTCOME; 295 } 296 } 297 298 return outcome; 299 } 300 301 304 private void clearUpload() 305 { 306 if (this.file != null) 308 { 309 this.file.delete(); 310 } 311 312 FacesContext ctx = FacesContext.getCurrentInstance(); 314 ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME); 315 } 316 } 317 | Popular Tags |