View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.jdiagnose.library.web.spring;
17  
18  import java.util.Locale;
19  
20  import org.springframework.beans.BeansException;
21  import org.springframework.web.servlet.View;
22  import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
23  import org.springframework.web.servlet.view.velocity.VelocityToolboxView;
24  
25  /***
26   * @author jmccrindle
27   */
28  public class VelocityToolboxViewResolver extends AbstractTemplateViewResolver {
29  
30      private String toolboxConfigLocation = null;
31  
32      private String velocityFormatterAttribute;
33  
34      private String dateToolAttribute;
35  
36      private String numberToolAttribute;
37  
38      public VelocityToolboxViewResolver() {
39          setViewClass(org.springframework.web.servlet.view.velocity.VelocityToolboxView.class);
40      }
41  
42      /*
43       * (non-Javadoc)
44       * 
45       * @see org.springframework.web.servlet.view.velocity.VelocityViewResolver#loadView(java.lang.String,
46       *      java.util.Locale)
47       */
48      protected View loadView(String viewName, Locale locale)
49              throws BeansException {
50          VelocityToolboxView view = (VelocityToolboxView) super.loadView(
51                  viewName, locale);
52          view.setVelocityFormatterAttribute(velocityFormatterAttribute);
53          view.setDateToolAttribute(dateToolAttribute);
54          view.setNumberToolAttribute(numberToolAttribute);
55          view.setToolboxConfigLocation(toolboxConfigLocation);
56          return view;
57      }
58  
59      public void setToolboxConfigLocation(String toolboxConfigLocation) {
60          this.toolboxConfigLocation = toolboxConfigLocation;
61      }
62  
63      protected Class requiredViewClass() {
64          return org.springframework.web.servlet.view.velocity.VelocityToolboxView.class;
65      }
66  
67      public void setVelocityFormatterAttribute(String velocityFormatterAttribute) {
68          this.velocityFormatterAttribute = velocityFormatterAttribute;
69      }
70  
71      public void setDateToolAttribute(String dateToolAttribute) {
72          this.dateToolAttribute = dateToolAttribute;
73      }
74  
75      public void setNumberToolAttribute(String numberToolAttribute) {
76          this.numberToolAttribute = numberToolAttribute;
77      }
78  
79  }