private ConfigurationItem constructConfigurationOptions() { String[] categoryHierarchy = new String[1]; categoryHierarchy[0] = this.translatorCategory; List<ConfigurationItem> configItems = null; try { configItems = configurationManager.getConfiguration(categoryHierarchy, true); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.debug("Size of configItem = " + (configItems != null ? configItems.size() : 0)); if (config == null) { return null; } ConfigurationItem configItem; if (configItems != null) { configItem = configItems.get(0); } else { configItem = new ConfigurationItem(categoryHierarchy); } configItem.clearNameValuePairs(); for (Map.Entry<String, ConfigurationOption> entry : config.entrySet()) { String key = entry.getKey(); ConfigurationOption option = entry.getValue(); if (key.equalsIgnoreCase("builtin")) { continue; } String optionName = option.getName(); Object optionValue = option.getValue(); if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.String")) { optionValue = this.rcps.getString(key); } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.Double")) { optionValue = this.rcps.getDouble(key); } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.Integer")) { optionValue = this.rcps.getInt(key); } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.Boolean")) { optionValue = this.rcps.getBoolean(key); } else { logger.debug( "Error saving configuration option, " + optionName + ", of type " + optionValue.getClass().getName()); } logger.debug("Setting " + optionName + " to " + optionValue.toString()); ConfigurationItem.NameValuePair nv = configItem.new NameValuePair(optionName, optionValue); nv.setConfigType(ConfigurationItem.ConfigurationType.SingleValue); configItem.addNameValuePair(nv); } return configItem; }
private void processConfigurationOptions() { nOptions = 0; int maxDescL = -1; int maxOptsL = 20; if (config == null) { width = 70; return; } for (Map.Entry<String, ConfigurationOption> entry : config.entrySet()) { String key = entry.getKey(); ConfigurationOption option = entry.getValue(); if (key.equalsIgnoreCase("builtin")) { continue; } nOptions++; // String optionName = option.getName(); String optionDescription = option.getDescription(); if (optionDescription.length() > maxDescL) { maxDescL = optionDescription.length(); } // String[] optionHierarchy = option.getCategoryHierarchy(); Object optionValue = option.getValue(); if (optionValue != null && optionValue.toString().length() > maxOptsL) { maxOptsL = optionValue.toString().length(); } Object[] optionPossibleValues = option.getPossibleValues(); if (optionPossibleValues != null && optionPossibleValues.length > 0) { for (int i = 0; i < optionPossibleValues.length; i++) { if (optionPossibleValues[i].toString().length() > maxOptsL) { maxOptsL = optionPossibleValues[i].toString().length(); } } } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.String")) { int size = Math.max(optionValue.toString().length(), 40); if (size > maxOptsL) { maxOptsL = size; } } // logger.debug("maxDescL = "+maxDescL+" maxOptsL = "+maxOptsL); } width = maxDescL + 5 + maxOptsL + 15; logger.debug("maxDescL = " + maxDescL + " maxOptsL = " + maxOptsL + " width = " + width); }