View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.portals.applications.springmvc;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.portlet.ActionRequest;
23  import javax.portlet.ActionResponse;
24  import javax.portlet.PortletRequest;
25  import javax.portlet.RenderRequest;
26  import javax.portlet.RenderResponse;
27  
28  import org.springframework.beans.factory.InitializingBean;
29  import org.springframework.validation.BindException;
30  import org.springframework.web.portlet.bind.PortletRequestDataBinder;
31  import org.springframework.web.portlet.mvc.SimpleFormController;
32  import org.springframework.web.portlet.ModelAndView;
33  
34  import org.apache.portals.applications.springmvc.DOMTree;
35  
36  public class DOMTreePrefsController extends SimpleFormController implements InitializingBean {
37  
38      private DOMTreeService domTreeService;
39      
40      public void afterPropertiesSet() throws Exception
41      {
42          if ( this.domTreeService == null )
43              throw new IllegalArgumentException( "DOMTreeService is required" );
44      }
45  
46  	public void onSubmitAction( ActionRequest request, ActionResponse response,
47  			Object command,	BindException errors ) throws Exception
48  	{	
49          String save = request.getParameter( "save" );
50          if ( save != null )
51          {
52          	domTreeService.saveDOMTree( request.getParameter("name"), request.getParameter("path"), request );
53          }
54  		response.setRenderParameter( "action", "list" );
55  	}
56  	
57  	protected Object formBackingObject( PortletRequest request ) throws Exception
58  	{
59  		String name = request.getParameter( "domTree" );
60  		if ( name == null )
61  		{
62  			return new DOMTree();
63  		}
64  		else
65  		{
66  			return domTreeService.getDOMTree( name, request );
67  		}
68  	}
69      
70  	protected void initBinder(PortletRequest request, PortletRequestDataBinder binder)
71  			throws Exception
72      {
73  	    //SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
74  	    //binder.registerCustomEditor(Date.class, null, new	CustomDateEditor(dateFormat, true));
75  	    //binder.setAllowedFields(new String[] {"author","title","description","availability","count"});
76  	}
77  
78  	protected ModelAndView renderInvalidSubmit(RenderRequest request, RenderResponse response)
79  			throws Exception
80  	{
81  	    return null;
82  	}
83  	
84  	protected void handleInvalidSubmit(ActionRequest request, ActionResponse response)
85  			throws Exception
86  	{
87  		response.setRenderParameter( "action","view" );
88  	}
89  
90      public void setDomTreeService(DOMTreeService domTreeService)
91      {
92          this.domTreeService = domTreeService;
93      }
94  }