/** * Get configuration object property value or default value if there is no property with requested name. * * @param name property name, * @param defaultValue default value. * @return configuration object property value or given default value. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. */ public String getProperty(String name, String defaultValue) { String value = getProperty(name); return value != null ? value : defaultValue; }
/** * Get configuration object property converter to requested type or null if there is no property with given name. * * @param name property name. * @param type type to convert property value to. * @param <T> value type. * @return newly created value object or null. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. * @throws IllegalArgumentException if <code>type</code> argument is null. * @throws ConverterException if there is no converter registered for value type or value parse fails. */ public <T> T getProperty(String name, Class<T> type) { return getProperty(name, type, null); }
/** * Create I18N repository instance and configure it. See {@link ConfigBuilder} for configuration object properties. * * @param config configuration object. * @throws IllegalArgumentException if configured base directory does not denote an existing directory. * @throws IOException if reading directories content fails, perhaps for lack of authorization. * @throws BugError if no files matching files pattern found or missing locale directory. */ public I18nRepository(Config config) throws IOException { this.multiLocale = config.getProperty("multi-locale", Boolean.class, true); File baseDir = config.getProperty("base-dir", File.class); Params.isDirectory(baseDir, "Base directory"); FileFilter fileFilter = new WildcardFilter(config.getProperty("files-pattern", WildcardFilter.ACCEPT_ALL)); if(this.multiLocale) { this.iterable = new MultipleLocale(baseDir, config.getProperty("sub-path"), fileFilter); } else { this.iterable = new SingleLocale(baseDir, fileFilter); } }
@Override public void config(Config config) throws ConfigException { super.config(config); // by convention configuration object name is the web application name appName = config.getName(); privateDir = server.getAppDir(appName); if (!privateDir.exists()) { privateDir.mkdir(); } Config loginConfig = config.getChild("login"); if (loginConfig != null) { loginRealm = loginConfig.getProperty("realm", appName); loginPage = loginConfig.getProperty("page"); if (loginPage != null && !loginPage.startsWith("/")) { loginPage = Strings.concat('/', appName, '/', loginPage); } } }
imagesRepositoryDir = config.getProperty("captcha.repository.path", File.class); if (imagesRepositoryDir == null) { throw new ConfigException("Missing <captcha.repository.path> property from CAPTCHA configuration."); challengeSetSize = config.getProperty("captcha.set.size", int.class, 6);
/** * Get configuration object property converter to requested type or default value if there is no property with given * name. * * @param name property name. * @param type type to convert property value to, * @param defaultValue default value, possible null or empty. * @param <T> value type. * @return newly created value object or default value. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. * @throws IllegalArgumentException if <code>type</code> argument is null. * @throws ConverterException if there is no converter registered for value type or value parse fails. */ public <T> T getProperty(String name, Class<T> type, T defaultValue) { Params.notNullOrEmpty(name, "Property name"); Params.notNull(type, "Property type"); String value = getProperty(name); if(value != null) { return converter.asObject(value, type); } return defaultValue; }