private void adjustName() { // If there is no name then use the initials name if (configAll.get(KEY_DESCRIPTION) == null) { LOGGER.error("Malformed conf file: missing [{}]{}=. Using {}", configAll.getName(), KEY_DESCRIPTION, configAll.getName()); setProperty(KEY_DESCRIPTION, configAll.getName()); } }
/** * Get the first value for the key in the first section. * * @param key the key * @return the value at the specified index * @throws ArrayIndexOutOfBoundsException when the index is out of bounds */ public String getValue(String key) { IniSection section = getSection(); return section == null ? null : section.get(key); }
private static void adjustHistory(IniSection config) { // Iterate over a copy of the keys so that we don't get // a concurrent modification exception when we remove matching keys // and when we add new keys List<String> keys = new ArrayList(config.getKeys()); for (String key : keys) { String value = config.get(key); ConfigEntryType type = ConfigEntryType.fromString(key); if (ConfigEntryType.HISTORY.equals(type)) { config.remove(key); int pos = key.indexOf('_'); value = key.substring(pos + 1) + ' ' + value; config.add(KEY_HISTORY, value); } } }
String value = config.get(key, i);
/** * Get the first value for the key specified by the index and the section. * * @param sectionName the name of the section * @param key the key for the section * @return the value at the specified index * @throws ArrayIndexOutOfBoundsException when the index is out of bounds */ public String getValue(String sectionName, String key) { IniSection section = doGetSection(sectionName); return section == null ? null : section.get(key, 0); }
private void adjustLanguage() { String lang = getProperty(KEY_LANG); testLanguage(KEY_LANG, lang); String langFrom = configAll.get(KEY_GLOSSARY_FROM); String langTo = configAll.get(KEY_GLOSSARY_TO); // If we have either langFrom or langTo, we are dealing with a glossary if (langFrom != null || langTo != null) { if (langFrom == null) { langFrom = lang; setProperty(KEY_GLOSSARY_FROM, langFrom); LOGGER.warn("Missing data for [{}]. Assuming {}={}", configAll.getName(), KEY_GLOSSARY_FROM, langFrom); } testLanguage(KEY_GLOSSARY_FROM, langFrom); if (langTo == null) { langTo = Language.DEFAULT_LANG.getGivenSpecification(); setProperty(KEY_GLOSSARY_TO, langTo); LOGGER.warn("Missing data for [{}]. Assuming {}={}", configAll.getName(), KEY_GLOSSARY_TO, langTo); } testLanguage(KEY_GLOSSARY_TO, langTo); // At least one of the two languages should match the lang entry if (!langFrom.equals(lang) && !langTo.equals(lang)) { LOGGER.error("Data error in [{}]. Neither {} or {} match {}", configAll.getName(), KEY_GLOSSARY_FROM, KEY_GLOSSARY_TO, KEY_LANG); } } setLanguage((Language) getValue(KEY_LANG)); }
/** * Get the value for the key specified by the index for the first section. * * @param key the key * @param index the index * @return the value at the specified index * @throws ArrayIndexOutOfBoundsException when the index is out of bounds */ public String getValue(String key, int index) { IniSection section = getSection(); return section == null ? null : section.get(key, index); }
/** * Get the value for the key specified by the index and the section. * * @param sectionName the name of the section * @param key the key for the section * @param index the index in the list of values * @return the value at the specified index * @throws ArrayIndexOutOfBoundsException when the index is out of bounds */ public String getValue(String sectionName, String key, int index) { IniSection section = doGetSection(sectionName); return section == null ? null : section.get(key, index); }
public String getProperty(String key) { if (KEY_LANGUAGE.equals(key)) { return getLanguage().getName(); } return configAll.get(key, DEFAULTS.get(key)); }
public void parse() throws IOException { File confFile = new File(conf); if (!confFile.exists()) { System.err.println("File does not exist: " + conf); return; } IniSection config = new IniSection(); // So called Latin-1 is the default, but most are UTF-8 config.load(confFile, "UTF-8"); String encoding = config.get("Encoding"); if (encoding == null || "Latin-1".equalsIgnoreCase(encoding)) { config.clear(); config.load(confFile, "WINDOWS-1252"); } SwordBookMetaData.report(config); SwordBookMetaData.normalize(new PrintWriter(System.out), config, CANONICAL_ORDER); }
/** * Load the conf from a buffer. This is used to load conf entries from the cached mods.d.tar.gz or mods.d.zip file. * * @param buffer * the buffer to load * @throws IOException */ private void loadBuffer(byte[] buffer, Filter<String> keepers) throws IOException { filtered = keepers != null; configAll.clear(); configAll.load(buffer, ENCODING_UTF8, keepers); String encoding = configAll.get(KEY_ENCODING); if (!ENCODING_UTF8.equalsIgnoreCase(encoding)) { configAll.clear(); configAll.load(buffer, ENCODING_LATIN1, keepers); } }
/** * Load the conf from a file. * * @param keepers * the keys to keep. When null keep all * @throws IOException */ private void loadFile(Filter<String> keepers) throws IOException { filtered = keepers != null; configAll.clear(); configAll.load(configFile, ENCODING_UTF8, keepers); String encoding = configAll.get(KEY_ENCODING); if (!ENCODING_UTF8.equalsIgnoreCase(encoding)) { configAll.clear(); configAll.load(configFile, ENCODING_LATIN1, keepers); } }
private Element toRow(OSISUtil.OSISFactory factory, String key) { int size = configAll.size(key); if (size == 0) { return null; } // See if it is a predefined type ConfigEntryType type = ConfigEntryType.fromString(key); Element nameEle = toKeyCell(factory, key); Element valueElement = factory.createCell(); for (int j = 0; j < size; j++) { if (j > 0) { valueElement.addContent(factory.createLB()); } String text = configAll.get(key, j); if (type != null && !type.isText() && type.isAllowed(text)) { text = type.convert(text).toString(); } text = XMLUtil.escape(text); if (type != null && type.allowsRTF()) { valueElement.addContent(OSISUtil.rtfToOsis(text)); } else { valueElement.addContent(text); } } // Each key gets one row. Element rowEle = factory.createRow(); rowEle.addContent(nameEle); rowEle.addContent(valueElement); return rowEle; }