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.tree.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 TreeProperties
34  {
35  	private static Log logger = LogFactory.getLog(TreeProperties.class);
36  	public final static String EXTREMECOMPONENTS_PROPERTIES = "extremecomponents.properties";
37  	public final static String EXTREMETABLE_PROPERTIES = "extremetree.properties";
38  
39  	public final static String AUTO_INCLUDE_PARAMETERS = "tree.autoIncludeParameters";
40  	public final static String BORDER = "tree.border";
41  	public final static String CELL = "tree.cell_";
42  	public final static String CELLPADDING = "tree.cellpadding";
43  	public final static String CELLSPACING = "tree.cellspacing";
44  	public final static String EXPORT = "tree.export";
45  	public final static String FILTER = "tree.filter";
46  	public final static String FORMAT = "tree.format_";
47  	public final static String HEADER_CLASS = "tree.headerClass";
48  	public final static String HEADER_SORT_CLASS = "tree.headerSortClass";
49  	public final static String IMAGE_PATH = "tree.imagePath";
50  	public final static String MAX_ROWS = "tree.maxRows";
51  	public final static String METHOD = "tree.method";
52  	public final static String PAGINATION = "tree.pagination";
53  	public final static String PARSE = "tree.parse_";
54  	public final static String PROCESS_COLUMN = "tree.processColumn";
55  	public final static String SORT = "tree.sort";
56  	public final static String STYLE_CLASS = "tree.styleClass";
57  	public final static String VIEW = "tree.view_";
58  	public final static String VIEW_HTML= "tree.view_html";
59  	public final static String WIDTH = "table.width";
60  	
61  	private Properties properties;
62  
63  	public TreeProperties()
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 }