You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by ni...@apache.org on 2004/04/15 01:44:39 UTC
svn commit: rev 10011 - xml/forrest/trunk/src/java/org/apache/forrest/conf
Author: nicolaken
Date: Wed Apr 14 16:44:38 2004
New Revision: 10011
Added:
xml/forrest/trunk/src/java/org/apache/forrest/conf/AntProperties.java
Modified:
xml/forrest/trunk/src/java/org/apache/forrest/conf/AntPropertiesModule.java
Log:
Separate the Module from the actual Ant property file reader.
Added: xml/forrest/trunk/src/java/org/apache/forrest/conf/AntProperties.java
==============================================================================
--- (empty file)
+++ xml/forrest/trunk/src/java/org/apache/forrest/conf/AntProperties.java Wed Apr 14 16:44:38 2004
@@ -0,0 +1,109 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.conf;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * @date barozzink 14-apr-2004
+ **/
+public class AntProperties extends Properties {
+
+ public AntProperties() {
+ super();
+ }
+
+ public AntProperties(Properties arg0) {
+ super(arg0);
+ }
+
+
+ public synchronized void load(InputStream arg0) throws IOException {
+ // TODO Auto-generated method stub
+ super.load(arg0);
+
+ BufferedReader in = null;
+ try {
+
+ in = new BufferedReader(new InputStreamReader(arg0));
+
+ String currentLine, name, value;
+ int splitIndex;
+
+ while((currentLine = in.readLine()) != null) {
+ // # == comment
+ if(!currentLine.startsWith("#")&&!(currentLine.trim().length()==0)){
+ splitIndex = currentLine.indexOf('=');
+ name = currentLine.substring(0, splitIndex).trim();
+ value = currentLine.substring(splitIndex+1).trim();
+ this.put(name,value);
+ }
+ }
+ }
+ finally {
+ if (in != null) {
+ try {
+ in.close();
+ }
+ catch (IOException e) {
+ }
+ }
+ }
+ }
+
+ public synchronized Object put(Object name, Object value) {
+ //if the property is already there don't overwrite, as in Ant
+ //properties defined first take precedence
+ if(!super.containsKey(name)){
+ Enumeration names = super.propertyNames();
+ while( names.hasMoreElements() ) {
+ String currentName = (String) names.nextElement();
+ String valueToSearchFor = "${"+currentName+"}";
+ String valueToReplaceWith = (String) super.get(currentName);
+ value = StringUtils.replace(value.toString(), valueToSearchFor, valueToReplaceWith);
+ }
+ return super.put(name,value);
+ }
+
+ return null;
+ }
+
+ public synchronized void putAll(Map arg0) {
+ Set keys = arg0.keySet();
+ Iterator i = keys.iterator();
+ while(i.hasNext()) {
+ String currentKey = i.next().toString();
+ this.put(currentKey,arg0.get(currentKey));
+ }
+
+ }
+
+ public synchronized Object setProperty(String name, String value) {
+ // TODO Auto-generated method stub
+ return this.put(name, value);
+ }
+
+}
Modified: xml/forrest/trunk/src/java/org/apache/forrest/conf/AntPropertiesModule.java
==============================================================================
--- xml/forrest/trunk/src/java/org/apache/forrest/conf/AntPropertiesModule.java (original)
+++ xml/forrest/trunk/src/java/org/apache/forrest/conf/AntPropertiesModule.java Wed Apr 14 16:44:38 2004
@@ -15,10 +15,8 @@
*/
package org.apache.forrest.conf;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Enumeration;
+import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
@@ -31,7 +29,6 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.modules.input.AbstractJXPathModule;
import org.apache.cocoon.components.modules.input.InputModule;
-import org.apache.commons.lang.StringUtils;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
@@ -73,37 +70,15 @@
protected void load(String file) throws ConfigurationException {
Source source = null;
- BufferedReader in = null;
+ InputStream in = null;
try {
source = m_resolver.resolveURI(file);
- in = new BufferedReader(new InputStreamReader(source.getInputStream()));
+ in = source.getInputStream();
- m_properties = new Properties();
- String currentLine, name, value;
- int splitIndex;
- Enumeration names;
-
- while((currentLine = in.readLine()) != null) {
- // # == comment
- if(!currentLine.startsWith("#")&&!(currentLine.trim().length()==0)){
- splitIndex = currentLine.indexOf('=');
- name = currentLine.substring(0, splitIndex).trim();
- //if the property is already there don't overwrite, as in Ant
- //properties defined first take precedence
- if(!m_properties.containsKey(name)){
- value = currentLine.substring(splitIndex+1).trim();
- names = m_properties.propertyNames();
- while( names.hasMoreElements() ) {
- String currentName = (String) names.nextElement();
- String valueToSearchFor = "${"+currentName+"}";
- String valueToReplaceWith = (String) m_properties.get(currentName);
- value = StringUtils.replace(value, valueToSearchFor, valueToReplaceWith);
- }
- m_properties.put(name,value);
- }
- }
- }
+ m_properties = new AntProperties();
+ m_properties.load(in);
+
}
catch (IOException e) {
throw new ConfigurationException("Cannot load properties file " + file);