View Javadoc

1   /*
2    * Copyright 2004 Jeff Johnston
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.extremecomponents.table.model;
17  
18  import java.io.InputStream;
19  import java.util.Properties;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  
25  /***
26   * Load up the properties file that will be used by the Model.
27   * The properties file contains default table attributes.
28   * TODO: should be able to load up a properties file that cooresponds
29   * with the current table if want to.
30   *
31   * @author Jeff Johnston
32   */
33  public class TableProperties
34  {
35  	private static Log logger = LogFactory.getLog(TableProperties.class);
36  	public final static String EXTREMECOMPONENTS_PROPERTIES = "extremecomponents.properties";
37  	public final static String EXTREMETABLE_PROPERTIES = "extremetable.properties";
38  
39  	public final static String AUTO_INCLUDE_PARAMETERS = "table.autoIncludeParameters";
40  	public final static String BORDER = "table.border";
41  	public final static String CELL = "table.cell_";
42  	public final static String CELLPADDING = "table.cellpadding";
43  	public final static String CELLSPACING = "table.cellspacing";
44  	public final static String EXPORT = "table.export";
45  	public final static String FILTER = "table.filter";
46  	public final static String FORMAT = "table.format_";
47  	public final static String HEADER_CLASS = "table.headerClass";
48  	public final static String HEADER_SORT_CLASS = "table.headerSortClass";
49  	public final static String IMAGE_PATH = "table.imagePath";
50  	public final static String MAX_ROWS = "table.maxRows";
51  	public final static String METHOD = "table.method";
52  	public final static String PAGINATION = "table.pagination";
53  	public final static String PARSE = "table.parse_";
54  	public final static String PROCESS_COLUMN = "table.processColumn";
55  	public final static String SORT = "table.sort";
56  	public final static String STYLE_CLASS = "table.styleClass";
57  	public final static String VIEW = "table.view_";
58  	public final static String VIEW_HTML= "table.view_html";
59  	public final static String WIDTH = "table.width";
60  	
61  	private Properties properties;
62  
63  	public TableProperties()
64  	{
65  		try
66  		{
67  			properties = new Properties();
68  			properties.load(this.getClass().getResourceAsStream(EXTREMETABLE_PROPERTIES)); //load up the default values
69  			
70  			InputStream input = this.getClass().getResourceAsStream("/" + EXTREMECOMPONENTS_PROPERTIES);
71  			if (input != null)
72  			{
73  				properties.load(input); //load up the overridding values
74  			}
75  		}
76  		catch (Exception e)
77  		{
78  			logger.error("Could not load the Properties.", e);
79  		}
80  	}
81  
82  	/***
83  	 * Get the default property.
84  	 */
85  	public String getProperty(String name)
86  	{
87  		return (String) properties.get(name);
88  	}
89  
90  	/***
91  	 * add/override properties.
92  	 */
93  	public void setProperty(String name, String value)
94  	{
95  		properties.setProperty(name, value);
96  	}
97  	
98  	public void destroy()
99  	{
100 		properties = null;
101 	}
102 }