KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > action > EditFolderAction


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.action;
22
23 import java.util.List JavaDoc;
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 /**
40  * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
41  * @version $Id: EditFolderAction.java 4144 2006-08-08 08:39:54Z saiyedm $
42  */

43 public class EditFolderAction extends FormAction
44 {
45     private static final String JavaDoc FORM_OBJECT_KEY = "folderWrapper";
46     private static final String JavaDoc PARENT_FOLDER_ATTR = "parentFolder";
47     private static final String JavaDoc CURRENT_FOLDER_ATTR = "currentFolder";
48     private static final String JavaDoc 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     /**
68      *
69      */

70     public EditFolderAction(){
71         setFormObjectClass(FolderWrapper.class); //custom form backing object class
72
setFormObjectName(FORM_OBJECT_KEY);
73         setFormObjectScope(ScopeType.FLOW); //this is a multi-page wizard!
74
setValidator(new FolderValidator());
75     }
76
77
78     /**
79      *
80      */

81     public Object JavaDoc 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 JavaDoc currentFolder = (String JavaDoc) 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 JavaDoc parentFolder = (String JavaDoc) 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             // Get a list of all folders in the current folder to validate name uniqueness
103
List JavaDoc folders=repository.getSubFolders(null,parentFolder);
104             wrapper.setAllFolders(folders);
105         }
106         return wrapper;
107     }
108
109
110     /**
111      *
112      */

113     public Event saveFolder(RequestContext context) throws Exception JavaDoc
114     {
115         FolderWrapper wrapper = (FolderWrapper) getFormObject(context);
116         repository.saveFolder(null, wrapper.getActualFolder());
117         return success();
118     }
119
120     /**
121      *
122      */

123     public Event setupEditForm(RequestContext context) throws Exception JavaDoc
124     {
125         AttributeMap rs = context.getRequestScope();
126         rs.put(FORM_OBJECT_KEY, getFormObject(context));
127         return success();
128     }
129
130 }
131
Popular Tags