1 21 package com.jaspersoft.jasperserver.war.action; 22 23 import java.util.List ; 24 25 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder; 26 import com.jaspersoft.jasperserver.api.metadata.common.domain.client.FolderImpl; 27 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService; 28 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl; 29 import com.jaspersoft.jasperserver.war.validation.FolderValidator; 30 import com.jaspersoft.jasperserver.war.dto.FolderWrapper; 31 import org.springframework.validation.DataBinder; 32 import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor; 33 import org.springframework.webflow.AttributeMap; 34 import org.springframework.webflow.Event; 35 import org.springframework.webflow.RequestContext; 36 import org.springframework.webflow.ScopeType; 37 import org.springframework.webflow.action.FormAction; 38 39 43 public class EditFolderAction extends FormAction 44 { 45 private static final String FORM_OBJECT_KEY = "folderWrapper"; 46 private static final String PARENT_FOLDER_ATTR = "parentFolder"; 47 private static final String CURRENT_FOLDER_ATTR = "currentFolder"; 48 private static final String IS_EDIT_FOLDER = "isEdit"; 49 50 51 private RepositoryService repository; 52 53 public RepositoryService getRepository() { 54 return repository; 55 } 56 57 public void setRepository(RepositoryService repository) { 58 this.repository = repository; 59 } 60 61 62 protected void initBinder(RequestContext context, DataBinder binder) { 63 binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); 64 } 65 66 67 70 public EditFolderAction(){ 71 setFormObjectClass(FolderWrapper.class); setFormObjectName(FORM_OBJECT_KEY); 73 setFormObjectScope(ScopeType.FLOW); setValidator(new FolderValidator()); 75 } 76 77 78 81 public Object loadFormObject(RequestContext context) 82 { 83 Folder folder; 84 FolderWrapper wrapper; 85 86 if (context.getFlowScope().get(IS_EDIT_FOLDER) != null) 87 { 88 ExecutionContextImpl executionContext = new ExecutionContextImpl(); 89 String currentFolder = (String ) context.getFlowScope().get(CURRENT_FOLDER_ATTR); 90 folder = repository.getFolder(executionContext, currentFolder); 91 wrapper = new FolderWrapper(folder); 92 wrapper.setEdit(true); 93 } 94 else 95 { 96 folder = new FolderImpl(); 97 String parentFolder = (String ) context.getFlowScope().get(PARENT_FOLDER_ATTR); 98 if (parentFolder == null || parentFolder.trim().length() == 0) 99 parentFolder = "/"; 100 folder.setParentFolder(parentFolder); 101 wrapper = new FolderWrapper(folder); 102 List folders=repository.getSubFolders(null,parentFolder); 104 wrapper.setAllFolders(folders); 105 } 106 return wrapper; 107 } 108 109 110 113 public Event saveFolder(RequestContext context) throws Exception 114 { 115 FolderWrapper wrapper = (FolderWrapper) getFormObject(context); 116 repository.saveFolder(null, wrapper.getActualFolder()); 117 return success(); 118 } 119 120 123 public Event setupEditForm(RequestContext context) throws Exception 124 { 125 AttributeMap rs = context.getRequestScope(); 126 rs.put(FORM_OBJECT_KEY, getFormObject(context)); 127 return success(); 128 } 129 130 } 131 | Popular Tags |