From: paspes <pa...@us...> - 2007-11-19 12:11:52
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25066/modules/core/src/com/babeldoc/core/option Modified Files: ConfigOption.java ConfigData.java Log Message: Bug resolution: [1119364 ] AsyncronusFeeder and error handlers Index: ConfigOption.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigOption.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ConfigOption.java 30 Jul 2004 01:33:01 -0000 1.17 --- ConfigOption.java 19 Nov 2007 12:10:23 -0000 1.18 *************** *** 427,431 **** public void addSuboption(ConfigOption suboption) { if (getSuboptions() == null) { ! suboptions = new HashMap(); } --- 427,431 ---- public void addSuboption(ConfigOption suboption) { if (getSuboptions() == null) { ! suboptions = new Hashtable(); } Index: ConfigData.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigData.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ConfigData.java 30 Jul 2004 01:33:01 -0000 1.7 --- ConfigData.java 19 Nov 2007 12:10:24 -0000 1.8 *************** *** 1 **** ! /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header$ * $DateTime$ * $Author$ * */ package com.babeldoc.core.option; import java.io.IOException; import java.io.StringReader; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import org.apache.commons.lang.builder.ToStringBuilder; import com.babeldoc.core.Named; import com.babeldoc.core.config.ConfigException; import com.babeldoc.core.config.ConfigService; import com.babeldoc.core.config.IConfig; import com.mindprod.csv.CSVReader; /** * This tree-like object represents data that is understood by <strong>Babeldoc</strong>. This is * used in pipelines and scanners. Each <code>ConfigData<code> object can have a string value * and a map of children. This constitutes the tree like structure of this object. * * @author Bmcdonald * @version 1.1 */ public class ConfigData extends Named implements IConfigData { /** The children of this configuration data object. */ private Map children = null; /** The current value (of this node).*/ private String value = null; /** * construct a null object. */ public ConfigData() { super(); } /** * Construct a named config. * * @param name of configdata */ public ConfigData(String name) { super(name); } /** * Construct a named config with a set of children. * * @param name configdata name * @param map children */ public ConfigData(String name, Map map) { super(name); this.children = map; } /** * Construct a named config with a value. * * @param name configdata name * @param value configdata value */ public ConfigData(String name, String value) { super(name); this.value = value; this.children = null; } /** * Construct a named config with a set of children and a value. * * @param name of this configuration data object * @param value value of this configuration * @param map children */ public ConfigData(String name, String value, Map map) { super(name); this.value = value; this.children = map; } /** * Get the number of child configs. * * @return number of children */ public int getNumberChildren() { if (children != null) { return children.size(); } else { return 0; } } /** * Set the configuration value. * * @param value new value */ public void setValue(String value) { this.value = value; } /** * Get the value of this config object. * * @return current value */ public String getValue() { return this.value; } /** * Get the value of the child object. * * @param childName name of the child object * @return the value of the child object */ public String getValue(String childName) { IConfigData child = this.getChild(childName); if (child != null) { return child.getValue(); } else { return null; } } /** * getChild the child pipelinestage configurations. * * @param name child name to seek * @return child object */ public IConfigData getChild(String name) { if (children == null) { children = new HashMap(); } return (ConfigData) children.get(name); } /** * getChild the child pipelinestage configurations. * * @return set of names of all the child objects */ public Set getChildrenNameSet() { if (children == null) { return Collections.EMPTY_SET; } return children.keySet(); } /** * Add the child to this configuration data object. The name of the child must * be set on the configuation data object. * * @param configData add a new child */ public void addChild(IConfigData configData) { if (children == null) { children = new HashMap(); } // System.out.println(this.getName()+" adding child: "+configData.getName()+" = "+configData.getValue()); this.children.put(configData.getName(), configData); } /** * remove the named child from the list of children of this * configuation data object. * * @param configData child to remove */ public void removeChild(IConfigData configData) { if (configData != null) { this.children.remove(configData.getName()); } } /** * Convert to a string. * * @return stringified */ public String toString() { return new ToStringBuilder(this) .append("name", getName()) .append("value", value) .append("children", children) .toString(); } /** * This will search down the supplied config data, looking for the matching * configuration data object all the while. This is very similar to a * hierarchical tree search. * * @param data root of the tree * @param pathbits path through the tree * * @return object at the end of path */ public static IConfigData getOptionInPath( IConfigData data, String[] pathbits) { if ((pathbits != null) && (pathbits.length > 0)) { data = data.getChild(pathbits[0]); if (data != null) { for (int i = 1; i < pathbits.length; ++i) { data = data.getChild(pathbits[i]); if (data == null) { return null; } } } return data; } return null; } /** * search down a path of config option names until option data name is found and * return it. * * @param path stringified path (like a directory) * @param data configuration data * @return object at the end of the path */ public static IConfigData getOptionDataInPath( IConfigData data, String path) { StringTokenizer st = new StringTokenizer(path, "/"); String[] pathParts = new String[st.countTokens()]; for (int i = 0; i < pathParts.length; ++i) { pathParts[i] = st.nextToken(); } return getOptionInPath(data, pathParts); } /** * Make a configuration data object with name 'rootName' from the * configuration system, using the configuration name. This takes the * place of the TieredConfigurationHelper * * @param rootName rootname of the configuration object * @param configName the path to the configuration data * @return nicely setup configuration object */ public static IConfigData getConfigData( String rootName, String configName) { IConfig config = ConfigService.getInstance().getConfig(configName); return getConfigData(rootName, config); } /** * Make a configuration data object with name 'rootName' from the * configuration system, using the configuration name. This takes the * place of the TieredConfigurationHelper * * @param rootName rootname of the configuration object * @param config the path to the configuration data * @return nicely setup configuration object */ public static IConfigData getConfigData(String rootName, IConfig config) { IConfigData data = new ConfigData(rootName); Set keys = config.keys(); for (Iterator i = keys.iterator(); i.hasNext();) { String key = (String) i.next(); String value = config.getString(key); try { CSVReader csvReader = new CSVReader(new StringReader(key), '.', '"', false, true); String[] tokens = csvReader.getAllFieldsInLine(); int numTokens = tokens.length; IConfigData working = data; for (int tokenCount = 0; tokenCount < numTokens; ++tokenCount) { String token = tokens[tokenCount]; if (working.getChild(token) == null) { working.addChild(new ConfigData(token)); } working = working.getChild(token); if (tokenCount == numTokens - 1) { working.setValue(value); } } } catch (IOException e) { // This should never happen } } return data; } /** * Extract the configuration data from the data object and place in the config * object ready to be persisted. * * @param config configuration object * @param data configdata object to extract the data from * @return filled config object * @throws ConfigException configuration exception */ public static IConfig getConfigFromData(IConfig config, IConfigData data) throws ConfigException { Stack names = new Stack(); getConfigFromData(data.getName(), config, data, names); return config; } /** * Extract the configuration data from the data object and place in the config * object ready to be persisted. * * @param stageName the name of the stage * @param config the configuration data to fill * @param data the configuration data object * @param names stack of names * @throws ConfigException configuration exception */ protected static void getConfigFromData( String stageName, IConfig config, IConfigData data, Stack names) throws ConfigException { if (data.getNumberChildren() > 0) { Set children = data.getChildrenNameSet(); for (Iterator iterator = children.iterator(); iterator.hasNext(); ) { String s = (String) iterator.next(); IConfigData child = data.getChild(s); names.add(child.getName()); getConfigFromData(stageName, config, child, names); } } else { // System.out.println("Data: " + data); StringBuffer sb = new StringBuffer(stageName + "."); for (Iterator iterator = names.iterator(); iterator.hasNext();) { String s = (String) iterator.next(); sb.append(s); if (iterator.hasNext()) { sb.append("."); } } String key = sb.toString(); String value = (data.getValue() == null) ? " " : data.getValue(); // System.out.println("Key found: " + key + " = " + value); config.setString(key, value); names.clear(); } } /** * Main method. * @param args command line. */ public static void main(String[] args) { class TestConfig extends Named implements IConfig { Properties props; TestConfig(String name, Properties props) { super(name); this.props = props; } public boolean isDirty() { return false; } public void setDirty(boolean dirty) { } public void setString(String key, String value) { props.setProperty(key, value); } public String getString(String name) { return props.getProperty(name); } public boolean hasKey(String name) { return props.getProperty(name) != null; } public Set keys() { return props.keySet(); } public Map getProperties() { return props; } } TestConfig cfg = new TestConfig("test", new Properties()); cfg.setString("roger.this", "that"); cfg.setString("roger.one", "1"); cfg.setString("roger.two", "2"); cfg.setString("roger.three", "3"); cfg.setString("roger.four", "4"); cfg.setString("roger.five", "5"); cfg.setString("roger.five.alpha", "5a"); cfg.setString("mike.two", "2"); cfg.setString("mike.three", "3"); cfg.setString("mike.four", "4"); cfg.setString("mike.five", "5"); cfg.setString("peter.\"four.alpha\"", "4"); cfg.setString("peter.\"five.beta\"", "5"); cfg.setString("\".info.broken\"", "aaa"); IConfigData data = getConfigData("root", cfg); System.out.println(data); // printMap(data, 0); } } \ No newline at end of file --- 1 ---- ! /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header$ * $DateTime$ * $Author$ * */ package com.babeldoc.core.option; import java.io.IOException; import java.io.StringReader; import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import org.apache.commons.lang.builder.ToStringBuilder; import com.babeldoc.core.Named; import com.babeldoc.core.config.ConfigException; import com.babeldoc.core.config.ConfigService; import com.babeldoc.core.config.IConfig; import com.mindprod.csv.CSVReader; /** * This tree-like object represents data that is understood by <strong>Babeldoc</strong>. This is * used in pipelines and scanners. Each <code>ConfigData<code> object can have a string value * and a map of children. This constitutes the tree like structure of this object. * * @author Bmcdonald * @version 1.1 */ public class ConfigData extends Named implements IConfigData { /** The children of this configuration data object. */ private Map children = null; /** The current value (of this node).*/ private String value = null; /** * construct a null object. */ public ConfigData() { super(); } /** * Construct a named config. * * @param name of configdata */ public ConfigData(String name) { super(name); } /** * Construct a named config with a set of children. * * @param name configdata name * @param map children */ public ConfigData(String name, Map map) { super(name); this.children = map; } /** * Construct a named config with a value. * * @param name configdata name * @param value configdata value */ public ConfigData(String name, String value) { super(name); this.value = value; this.children = null; } /** * Construct a named config with a set of children and a value. * * @param name of this configuration data object * @param value value of this configuration * @param map children */ public ConfigData(String name, String value, Map map) { super(name); this.value = value; this.children = map; } /** * Get the number of child configs. * * @return number of children */ public int getNumberChildren() { if (children != null) { return children.size(); } else { return 0; } } /** * Set the configuration value. * * @param value new value */ public void setValue(String value) { this.value = value; } /** * Get the value of this config object. * * @return current value */ public String getValue() { return this.value; } /** * Get the value of the child object. * * @param childName name of the child object * @return the value of the child object */ public String getValue(String childName) { IConfigData child = this.getChild(childName); if (child != null) { return child.getValue(); } else { return null; } } /** * getChild the child pipelinestage configurations. * * @param name child name to seek * @return child object */ public IConfigData getChild(String name) { if (children == null) { children = new Hashtable (); } return (ConfigData) children.get(name); } /** * getChild the child pipelinestage configurations. * * @return set of names of all the child objects */ public Set getChildrenNameSet() { if (children == null) { return Collections.EMPTY_SET; } return children.keySet(); } /** * Add the child to this configuration data object. The name of the child must * be set on the configuation data object. * * @param configData add a new child */ public void addChild(IConfigData configData) { if (children == null) { children = new HashMap(); } // System.out.println(this.getName()+" adding child: "+configData.getName()+" = "+configData.getValue()); this.children.put(configData.getName(), configData); } /** * remove the named child from the list of children of this * configuation data object. * * @param configData child to remove */ public void removeChild(IConfigData configData) { if (configData != null) { this.children.remove(configData.getName()); } } /** * Convert to a string. * * @return stringified */ public String toString() { return new ToStringBuilder(this) .append("name", getName()) .append("value", value) .append("children", children) .toString(); } /** * This will search down the supplied config data, looking for the matching * configuration data object all the while. This is very similar to a * hierarchical tree search. * * @param data root of the tree * @param pathbits path through the tree * * @return object at the end of path */ public static IConfigData getOptionInPath( IConfigData data, String[] pathbits) { if ((pathbits != null) && (pathbits.length > 0)) { data = data.getChild(pathbits[0]); if (data != null) { for (int i = 1; i < pathbits.length; ++i) { data = data.getChild(pathbits[i]); if (data == null) { return null; } } } return data; } return null; } /** * search down a path of config option names until option data name is found and * return it. * * @param path stringified path (like a directory) * @param data configuration data * @return object at the end of the path */ public static IConfigData getOptionDataInPath( IConfigData data, String path) { StringTokenizer st = new StringTokenizer(path, "/"); String[] pathParts = new String[st.countTokens()]; for (int i = 0; i < pathParts.length; ++i) { pathParts[i] = st.nextToken(); } return getOptionInPath(data, pathParts); } /** * Make a configuration data object with name 'rootName' from the * configuration system, using the configuration name. This takes the * place of the TieredConfigurationHelper * * @param rootName rootname of the configuration object * @param configName the path to the configuration data * @return nicely setup configuration object */ public static IConfigData getConfigData( String rootName, String configName) { IConfig config = ConfigService.getInstance().getConfig(configName); return getConfigData(rootName, config); } /** * Make a configuration data object with name 'rootName' from the * configuration system, using the configuration name. This takes the * place of the TieredConfigurationHelper * * @param rootName rootname of the configuration object * @param config the path to the configuration data * @return nicely setup configuration object */ public static IConfigData getConfigData(String rootName, IConfig config) { IConfigData data = new ConfigData(rootName); Set keys = config.keys(); for (Iterator i = keys.iterator(); i.hasNext();) { String key = (String) i.next(); String value = config.getString(key); try { CSVReader csvReader = new CSVReader(new StringReader(key), '.', '"', false, true); String[] tokens = csvReader.getAllFieldsInLine(); int numTokens = tokens.length; IConfigData working = data; for (int tokenCount = 0; tokenCount < numTokens; ++tokenCount) { String token = tokens[tokenCount]; if (working.getChild(token) == null) { working.addChild(new ConfigData(token)); } working = working.getChild(token); if (tokenCount == numTokens - 1) { working.setValue(value); } } } catch (IOException e) { // This should never happen } } return data; } /** * Extract the configuration data from the data object and place in the config * object ready to be persisted. * * @param config configuration object * @param data configdata object to extract the data from * @return filled config object * @throws ConfigException configuration exception */ public static IConfig getConfigFromData(IConfig config, IConfigData data) throws ConfigException { Stack names = new Stack(); getConfigFromData(data.getName(), config, data, names); return config; } /** * Extract the configuration data from the data object and place in the config * object ready to be persisted. * * @param stageName the name of the stage * @param config the configuration data to fill * @param data the configuration data object * @param names stack of names * @throws ConfigException configuration exception */ protected static void getConfigFromData( String stageName, IConfig config, IConfigData data, Stack names) throws ConfigException { if (data.getNumberChildren() > 0) { Set children = data.getChildrenNameSet(); for (Iterator iterator = children.iterator(); iterator.hasNext(); ) { String s = (String) iterator.next(); IConfigData child = data.getChild(s); names.add(child.getName()); getConfigFromData(stageName, config, child, names); } } else { // System.out.println("Data: " + data); StringBuffer sb = new StringBuffer(stageName + "."); for (Iterator iterator = names.iterator(); iterator.hasNext();) { String s = (String) iterator.next(); sb.append(s); if (iterator.hasNext()) { sb.append("."); } } String key = sb.toString(); String value = (data.getValue() == null) ? " " : data.getValue(); // System.out.println("Key found: " + key + " = " + value); config.setString(key, value); names.clear(); } } /** * Main method. * @param args command line. */ public static void main(String[] args) { class TestConfig extends Named implements IConfig { Properties props; TestConfig(String name, Properties props) { super(name); this.props = props; } public boolean isDirty() { return false; } public void setDirty(boolean dirty) { } public void setString(String key, String value) { props.setProperty(key, value); } public String getString(String name) { return props.getProperty(name); } public boolean hasKey(String name) { return props.getProperty(name) != null; } public Set keys() { return props.keySet(); } public Map getProperties() { return props; } } TestConfig cfg = new TestConfig("test", new Properties()); cfg.setString("roger.this", "that"); cfg.setString("roger.one", "1"); cfg.setString("roger.two", "2"); cfg.setString("roger.three", "3"); cfg.setString("roger.four", "4"); cfg.setString("roger.five", "5"); cfg.setString("roger.five.alpha", "5a"); cfg.setString("mike.two", "2"); cfg.setString("mike.three", "3"); cfg.setString("mike.four", "4"); cfg.setString("mike.five", "5"); cfg.setString("peter.\"four.alpha\"", "4"); cfg.setString("peter.\"five.beta\"", "5"); cfg.setString("\".info.broken\"", "aaa"); IConfigData data = getConfigData("root", cfg); System.out.println(data); // printMap(data, 0); } } \ No newline at end of file |