You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by rg...@apache.org on 2005/08/10 11:57:11 UTC
svn commit: r231206 -
/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java
Author: rgardler
Date: Wed Aug 10 02:57:02 2005
New Revision: 231206
URL: http://svn.apache.org/viewcvs?rev=231206&view=rev
Log:
add ForrestProperties class to facilitate easy maintenance
Added:
forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java (with props)
Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java?rev=231206&view=auto
==============================================================================
--- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java (added)
+++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java Wed Aug 10 02:57:02 2005
@@ -0,0 +1,90 @@
+package org.apache.forrest;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.forrest.eclipse.ForrestPlugin;
+import org.apache.forrest.eclipse.preference.ForrestPreferences;
+import org.apache.log4j.Logger;
+
+/**
+ * A representation of te forrest properties.
+ *
+ */
+public class ForrestProperties {
+ /** Path to the root of the Forrest project */
+ String projectPath;
+
+ /**
+ * Logger for this class
+ */
+ private static final Logger logger = Logger
+ .getLogger(ForrestProperties.class);
+
+ /**
+ * Create a new instance for the supplied projectPath.
+ *
+ * @param projectPath -
+ * path to the root of the forrest proejct
+ */
+ public ForrestProperties(String path) {
+ super();
+ projectPath = path;
+ }
+
+ /**
+ * Retrieves the value of a property in the forrest.properties file
+ *
+ * @param path -
+ * path to the forrest.properties file
+ * @param property -
+ * property to get the value from
+ *
+ */
+ public String getProperty(String property) {
+ File defaultFile = new File(getDefaultPropertiesPath());
+ Properties defaultProps = new Properties();
+ try {
+ defaultProps.load(new FileInputStream(defaultFile));
+ } catch (FileNotFoundException e) {
+ logger.error("Unable to load default forrest properties", e);
+ } catch (IOException e) {
+ logger.error("Unable to load default forrest properties", e);
+ }
+
+ File projectFile = new File(getProjectPropertiesPath());
+ Properties projectProps = new Properties(defaultProps);
+ try {
+ projectProps.load(new FileInputStream(projectFile));
+ } catch (FileNotFoundException e) {
+ logger.error("Unable to load project forrest properties", e);
+ } catch (IOException e) {
+ logger.error("Unable to load project forrest properties", e);
+ }
+ return projectProps.getProperty(property);
+ }
+
+ /**
+ * Get the path to the projects forrest properties file.
+ *
+ * @return path to file.
+ */
+ private String getProjectPropertiesPath() {
+ return projectPath + File.separator + "forrest.properties";
+ }
+
+ /**
+ * Get the path to the default forrest properties file.
+ *
+ * @return path to file.
+ */
+ private String getDefaultPropertiesPath() {
+ String forrestHome = ForrestPlugin.getDefault().getPluginPreferences()
+ .getString(ForrestPreferences.FORREST_HOME);
+ return forrestHome + File.separator + "main" + File.separator + "webapp" + File.separator + "default-forrest.properties";
+ }
+
+}
Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/ForrestProperties.java
------------------------------------------------------------------------------
svn:eol-style = native