View Javadoc

1   package net.mlw.vlh.web;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import net.mlw.vlh.web.tag.support.CellInterceptor;
7   import net.mlw.vlh.web.tag.support.CsvDisplayProvider;
8   import net.mlw.vlh.web.tag.support.DefaultLinkEncoder;
9   import net.mlw.vlh.web.tag.support.DisplayProvider;
10  import net.mlw.vlh.web.tag.support.ExcelDisplayProvider;
11  import net.mlw.vlh.web.tag.support.GroupingCellInterceptor;
12  import net.mlw.vlh.web.tag.support.HtmlDisplayProvider;
13  import net.mlw.vlh.web.tag.support.LinkEncoder;
14  import net.mlw.vlh.web.util.DisplayHelper;
15  import net.mlw.vlh.web.util.PassThroughDisplayHelper;
16  
17  import org.springframework.context.MessageSource;
18  import org.springframework.context.support.ResourceBundleMessageSource;
19  import org.springframework.web.servlet.LocaleResolver;
20  import org.springframework.web.servlet.i18n.SessionLocaleResolver;
21  
22  /***
23   * 
24   * net.mlw.vlh.web.ValueListConfigBean
25   * 
26   * @author Matthew Wilson, Andrej Zachar
27   */
28  public class ValueListConfigBean
29  {
30  
31  	public static final String DEFAULT_NAME = "classicLook";
32  
33  	public static final CellInterceptor DEFAULT_CELL_INTERCEPTOR = new GroupingCellInterceptor();
34  	
35  	public static final int DEFAULT_STYLE_COUNT = 2;
36  
37  	public static final String DEFAULT_STYLE_PREFIX = "classicLook";
38  
39  	public static final DisplayProvider DEFAULT_DISPLAY_PROVIDER = new HtmlDisplayProvider();
40  
41  	public static final LocaleResolver DEFAULT_LOCALE_RESOLVER = new SessionLocaleResolver();
42  
43  	public static final DisplayHelper DEFAULT_DISPLAY_HELPER = new PassThroughDisplayHelper();
44  
45  	public static final LinkEncoder DEFAULT_LINK_ENCODER = new DefaultLinkEncoder();
46  
47  	public static final ResourceBundleMessageSource DEFAULT_MESSAGE_SOURCE = new ResourceBundleMessageSource();
48  
49  	public static final Map DEFAULT_DISPLAY_PROVIDERS = new HashMap();
50  	static
51  	{
52  		DEFAULT_MESSAGE_SOURCE.setBasename("classicLook");
53  
54  		DEFAULT_DISPLAY_PROVIDERS.put("html", new HtmlDisplayProvider());
55  		DEFAULT_DISPLAY_PROVIDERS.put("csv", new CsvDisplayProvider());
56  		DEFAULT_DISPLAY_PROVIDERS.put("excel", new ExcelDisplayProvider());
57  
58  	}
59  
60  	private CellInterceptor cellInterceptor = DEFAULT_CELL_INTERCEPTOR;
61  	
62  	private String nullToken = "-";
63  
64  	private int styleCount = DEFAULT_STYLE_COUNT;
65  
66  	private String stylePrefix = DEFAULT_STYLE_PREFIX;
67  
68  	private MessageSource messageSource = DEFAULT_MESSAGE_SOURCE;
69  
70  	private DisplayHelper displayHelper = DEFAULT_DISPLAY_HELPER;
71  
72  	private LocaleResolver localeResolver = DEFAULT_LOCALE_RESOLVER;
73  
74  	private Map displayProviders;
75  
76  	private LinkEncoder linkEncoder = DEFAULT_LINK_ENCODER;
77  
78  	private String imageRoot = "/images";
79  	/***
80  	 * @return Returns the displayProviders.
81  	 */
82  	public DisplayProvider getDisplayProvider(String name)
83  	{
84  		if (displayProviders == null)
85  		{
86  			return DEFAULT_DISPLAY_PROVIDER;
87  		}
88  
89  		DisplayProvider display = (DisplayProvider) displayProviders.get(name);
90  		if (display == null)
91  		{
92  			display = (DisplayProvider) DEFAULT_DISPLAY_PROVIDERS.get(name);
93  		}
94  		if (display == null)
95  		{
96  			display = DEFAULT_DISPLAY_PROVIDER;
97  		}
98  
99  		return display;
100 	}
101 
102 	/***
103 	 * @param displayProviders
104 	 *            The displayProviders to set.
105 	 */
106 	public void setDisplayProviders(Map displayProviders)
107 	{
108 		this.displayProviders = displayProviders;
109 	}
110 
111 	/***
112 	 * @return Returns the displayHelper.
113 	 */
114 	public DisplayHelper getDisplayHelper()
115 	{
116 		return displayHelper;
117 	}
118 
119 	/***
120 	 * @param displayHelper
121 	 *            The displayHelper to set.
122 	 */
123 	public void setDisplayHelper(DisplayHelper displayHelper)
124 	{
125 		this.displayHelper = displayHelper;
126 	}
127 
128 	/***
129 	 * @return Returns the nullToken.
130 	 */
131 	public String getNullToken()
132 	{
133 		return nullToken;
134 	}
135 
136 	/***
137 	 * @param nullToken
138 	 *            The nullToken to set.
139 	 */
140 	public void setNullToken(String nullToken)
141 	{
142 		this.nullToken = nullToken;
143 	}
144 
145 	/***
146 	 * @return Returns the styleCount.
147 	 */
148 	public int getStyleCount()
149 	{
150 		return styleCount;
151 	}
152 
153 	/***
154 	 * @param styleCount
155 	 *            The styleCount to set.
156 	 */
157 	public void setStyleCount(int styleCount)
158 	{
159 		this.styleCount = styleCount;
160 	}
161 
162 	/***
163 	 * @return Returns the stylePrefix.
164 	 */
165 	public String getStylePrefix()
166 	{
167 		return stylePrefix;
168 	}
169 
170 	/***
171 	 * @param stylePrefix
172 	 *            The stylePrefix to set.
173 	 */
174 	public void setStylePrefix(String stylePrefix)
175 	{
176 		this.stylePrefix = stylePrefix;
177 	}
178 
179 	/***
180 	 * @return Returns the messageSource.
181 	 */
182 	public MessageSource getMessageSource()
183 	{
184 		if (messageSource == null)
185 		{
186 			ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
187 			messageSource.setBasename("classicLook");
188 			this.messageSource = messageSource;
189 		}
190 
191 		return messageSource;
192 	}
193 
194 	/***
195 	 * @param messageSource
196 	 *            The messageSource to set.
197 	 */
198 	public void setMessageSource(MessageSource messageSource)
199 	{
200 		this.messageSource = messageSource;
201 	}
202 
203 	/***
204 	 * @return Returns the localeResolver.
205 	 */
206 	public LocaleResolver getLocaleResolver()
207 	{
208 		return localeResolver;
209 	}
210 
211 	/***
212 	 * @param localeResolver
213 	 *            The localeResolver to set.
214 	 */
215 	public void setLocaleResolver(LocaleResolver localeResolver)
216 	{
217 		this.localeResolver = localeResolver;
218 	}
219 
220 	/***
221 	 * @return Returns the linkEncoder.
222 	 */
223 	public LinkEncoder getLinkEncoder()
224 	{
225 		return linkEncoder;
226 	}
227 
228 	/***
229 	 * @param linkEncoder The linkEncoder to set.
230 	 */
231 	public void setLinkEncoder(LinkEncoder linkEncoder)
232 	{
233 		this.linkEncoder = linkEncoder;
234 	}
235 
236     /***
237      * @return String  The style for focused row.
238      */
239     public String getFocusedRowStyle() {        
240         return getStylePrefix()+"FocusedRow";
241     }
242    /***
243     * @return Returns the cellInterceptor.
244     */
245    public CellInterceptor getCellInterceptor()
246    {
247       return cellInterceptor;
248    }
249    /***
250     * @param cellInterceptor The cellInterceptor to set.
251     */
252    public void setCellInterceptor(CellInterceptor cellInterceptor)
253    {
254       this.cellInterceptor = cellInterceptor;
255    }
256    /***
257     * @return Returns the imageRoot.
258     */
259    public String getImageRoot()
260    {
261       return imageRoot;
262    }
263    /***
264     * @param imageRoot The imageRoot to set.
265     */
266    public void setImageRoot(String imageRoot)
267    {
268       this.imageRoot = imageRoot;
269    }
270 }