KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.springframework.webflow.action.FormAction;
24 import org.springframework.webflow.RequestContext;
25 import org.springframework.webflow.ScopeType;
26 import org.springframework.webflow.Event;
27 import org.springframework.webflow.AttributeMap;
28 import org.springframework.validation.DataBinder;
29 import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
30 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
31 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder;
32 import com.jaspersoft.jasperserver.api.metadata.common.domain.DataType;
33 import com.jaspersoft.jasperserver.api.metadata.common.domain.client.FolderImpl;
34 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl;
35 import com.jaspersoft.jasperserver.war.validation.FolderValidator;
36 import com.jaspersoft.jasperserver.war.validation.DataTypeValidator;
37 import com.jaspersoft.jasperserver.war.dto.DataTypeWrapper;
38 import com.jaspersoft.jasperserver.war.dto.BaseDTO;
39
40 /**
41  * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
42  * @version $Id: EditDataTypeAction.java 3197 2006-04-20 18:26:21Z inedelcu $
43  */

44 public class EditDataTypeAction extends FormAction
45 {
46     private static final String JavaDoc FORM_OBJECT_KEY = "dataType";
47     private static final String JavaDoc PARENT_FOLDER_ATTR = "parentFolder";
48     private static final String JavaDoc CURRENT_DATATYPE_ATTR = "currentDataType";
49     private static final String JavaDoc IS_EDIT = "isEdit";//FIXME use wrapper to disable name in UI
50

51
52     private RepositoryService repository;
53
54     public RepositoryService getRepository() {
55         return repository;
56     }
57
58     public void setRepository(RepositoryService repository) {
59         this.repository = repository;
60     }
61
62
63     protected void initBinder(RequestContext context, DataBinder binder) {
64         binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
65     }
66
67
68     /**
69      *
70      */

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

82     public Object JavaDoc loadFormObject(RequestContext context)
83     {
84         DataType dataType;
85         DataTypeWrapper wrapper;
86         ExecutionContextImpl executionContext = new ExecutionContextImpl();
87
88         if (context.getFlowScope().get(IS_EDIT) != null)
89         {
90             String JavaDoc currentDataType = (String JavaDoc) context.getFlowScope().get(CURRENT_DATATYPE_ATTR);
91             dataType = (DataType) repository.getResource(executionContext, currentDataType);
92             wrapper = new DataTypeWrapper(dataType);
93             wrapper.setMode(BaseDTO.MODE_STAND_ALONE_EDIT);
94         }
95         else
96         {
97             dataType = (DataType) repository.newResource(executionContext, DataType.class);
98             String JavaDoc parentFolder = (String JavaDoc) context.getFlowScope().get(PARENT_FOLDER_ATTR);
99             if (parentFolder == null || parentFolder.trim().length() == 0)
100                 parentFolder = "/";
101             dataType.setParentFolder(parentFolder);
102             wrapper = new DataTypeWrapper(dataType);
103             wrapper.setMode(BaseDTO.MODE_STAND_ALONE_NEW);
104         }
105
106         return wrapper;
107     }
108
109
110     /**
111      *
112      */

113     public Event saveDataType(RequestContext context) throws Exception JavaDoc
114     {
115         DataTypeWrapper wrapper = (DataTypeWrapper) getFormObject(context);
116         if (wrapper.isStandAloneMode())
117             repository.saveResource(null, wrapper.getDataType());
118
119         return success();
120     }
121
122     /**
123      *
124      */

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