2006/unicorn/src/org/w3c/unicorn/util UCNProperties.java,1.1.2.2,1.1.2.3 Property.java,1.1.2.2,1.1.2.3

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/util
In directory hutz:/tmp/cvs-serv2800/src/org/w3c/unicorn/util

Added Files:
      Tag: dev2
	UCNProperties.java Property.java 
Log Message:
w3 => w3c 

--- NEW FILE: Property.java ---
package org.w3c.unicorn.util;

import java.util.Properties;

public class Property {
	
	private static Properties unicornProperties;
	
	public static String get(String key) {
		return unicornProperties.getProperty(key);
	}
	
	public static String get(String key1, String key2) {
		return unicornProperties.getProperty(key1) + unicornProperties.getProperty(key2);
	}

	public static void setUnicornProperties(Properties unicornProperties) {
		Property.unicornProperties = unicornProperties;
	}

	public static Properties getUnicornProperties() {
		return unicornProperties;
	}
}

--- NEW FILE: UCNProperties.java ---
package org.w3c.unicorn.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;

public class UCNProperties extends Properties {
	
	private static final long serialVersionUID = 1L;
	
	static Logger logger = Logger.getLogger("Init");
	
	private Pattern pattern = Pattern.compile("\\$\\{[a-zA-Z_0-9]*\\}");
	
	@Override
	public synchronized void load(InputStream inStream) throws IOException {
		super.load(inStream);
		this.parse();
	}

	public void parse() {
		for(Object key : this.keySet()) {
			logger.debug("-----------------------------------------------------------------------------");
			logger.debug("Parsing Property : \"" + key + "\" => \"" + this.getProperty((String) key));
			Matcher matcher = pattern.matcher(this.getProperty((String) key));
			
			if (matcher.find()) {
				matcher.reset();
				while (matcher.find()) {
					String match = matcher.group();
					logger.debug("> Pattern matched with: \"" + match + "\"");
					
					String foundKey = (String) match.subSequence(2, match.length()-1);
					
					if (!this.containsKey(foundKey)) {
						logger.warn("> String \"" + foundKey + "\" is not an existing property.");
					} else {
						String foundProp = this.getProperty(foundKey);
						logger.debug("> Found coresponding property: \"" + foundKey + "\" => \"" + foundProp +"\"");
						
						String subst = this.getProperty((String) key);
						subst = subst.replace(match, foundProp);
						this.put(key, subst);
						matcher = pattern.matcher(this.getProperty((String) key)); 
					}
				}
				logger.debug("> Parsed property: \"" + key + "\" => \"" + this.getProperty((String) key) + "\"");
			} else {
				logger.debug("> No nested property found");
			}
		}
	}

	@Override
	public String toString() {
		String result = "";
		for(Object key : this.keySet()) {
			result += "\n"+key+"\t=>\t"+this.getProperty((String) key);
		}
		return result;
	}
}

Received on Thursday, 6 August 2009 12:47:08 UTC