List of usage examples for org.apache.commons.configuration Configuration isEmpty
boolean isEmpty();
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static JSONObject getJSON(Configuration config) { JSONObject output = new JSONObject(); if (!config.isEmpty()) { Iterator it = config.getKeys(); while (it.hasNext()) { String k = (String) it.next(); // noinspection unchecked String v = (String) config.getProperty(k); output.put(k, v);/*from w w w . jav a 2s . c o m*/ } } return output; }
From source file:com.qmetry.qaf.automation.testng.pro.DataProviderUtil.java
public static List<Object[]> getDataSetAsMap(String key) { Configuration config = ConfigurationManager.getBundle().subset(key); ArrayList<Object[]> dataset = new ArrayList<Object[]>(); if (config.isEmpty()) { logger.error("Missing data with key [" + key + "]. "); throw new DataProviderException("Not test data found with key:" + key); }/*from w ww.jav a2 s. com*/ int size = config.getList(config.getKeys().next().toString()).size(); for (int i = 0; i < size; i++) { Map<String, String> map = new LinkedHashMap<String, String>(); Iterator<?> iter = config.getKeys(); while (iter.hasNext()) { String dataKey = String.valueOf(iter.next()); try { map.put(dataKey, config.getStringArray(dataKey)[i]); } catch (ArrayIndexOutOfBoundsException e) { logger.error( "Missing entry for property " + dataKey + ". Provide value for each property (or blank) in each data set in data file.", e); throw e; } } dataset.add(new Object[] { map }); } return dataset; }
From source file:com.konakart.apiexamples.BaseApiExample.java
/** * Initialise a KonaKart engine instance and perform a login to get a session id. * /* w w w . j a v a2s. c o m*/ * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws KKException * @throws ConfigurationException * @throws IOException * @throws InvocationTargetException * @throws IllegalArgumentException */ static protected void init() throws ClassNotFoundException, InstantiationException, IllegalAccessException, KKException, ConfigurationException, IOException, IllegalArgumentException, InvocationTargetException { EngineConfig engConf = new EngineConfig(); engConf.setMode(getEngineMode()); engConf.setStoreId(getStoreId()); engConf.setCustomersShared(isCustomersShared()); engConf.setProductsShared(isProductsShared()); engConf.setCategoriesShared(isCategoriesShared()); /* * Instantiate a KonaKart Engine. Different engines can be instantiated by passing * KKWSEngName or KKRMIEngName or KKJSONEngName for the SOAP, RMI or JSON engines */ eng = getKKEngByName(KKEngName, engConf); /* * Login with default credentials */ sessionId = eng.login(getUsername(), getPassword()); if (sessionId == null) { String msg = "Login of " + DEFAULT_USERNAME + " was unsuccessful"; log.warn(msg); throw new KKException(msg); } if (getEngineMode() == EngineConfig.MODE_MULTI_STORE_NON_SHARED_DB) { dbName = getStoreId(); } // Read the KonaKart config file - note that this is done in the engine but if we are // running this over SOAP we might not have access to the engine's Configuration data - so // we do it here explicitly on the client side. PropertiesConfiguration allConfig = new PropertiesConfiguration(KKConstants.KONAKART_PROPERTIES_FILE); if (allConfig.isEmpty()) { throw new KKException("The configuration file: " + KKConstants.KONAKART_PROPERTIES_FILE + " does not appear to contain any keys"); } // Look for properties that are in the "konakart" namespace. Configuration subConf = allConfig.subset("konakart"); if (subConf == null || subConf.isEmpty()) { log.error("The konakart section in the properties file is missing. " + "You must add at least one property to resolve this problem. " + "e.g. konakart.session.expirationMinutes=30"); return; } konakartConfig = subConf; log.info((new File(KKConstants.KONAKART_PROPERTIES_FILE)).getCanonicalPath() + " read"); }
From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java
public static boolean configure(File tempDir, Configuration configuration) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && configuration != null && !configuration.isEmpty()) { VelocityEngine velocityEngine = new VelocityEngine(); Properties vProps = new Properties(); vProps.setProperty("resource.loader", "string"); vProps.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); velocityEngine.init(vProps);//from w w w .ja va 2 s . c o m Template template = null; VelocityContext velocityContext = JPackageManagerBU.createVelocityContext(configuration); StringResourceRepository stringResourceRepository = StringResourceLoader.getRepository(); String templateContent = null; StringWriter stringWriter = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_DIR_NAME + "/" + JPackageManagerBU.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})", "#$2$3$4$5$6"); stringResourceRepository.putStringResource(JPackageManagerBU.CURRENT_TEMPLATE_NAME, templateContent); stringWriter = new StringWriter(); template = velocityEngine.getTemplate(JPackageManagerBU.CURRENT_TEMPLATE_NAME); template.merge(velocityContext, stringWriter); templateContent = stringWriter.toString(); templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})", "\\$$2$3$4$5$6"); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerBU.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})", "#$2$3$4$5$6"); stringResourceRepository.putStringResource(JPackageManagerBU.CURRENT_TEMPLATE_NAME, templateContent); stringWriter = new StringWriter(); template = velocityEngine.getTemplate(JPackageManagerBU.CURRENT_TEMPLATE_NAME); template.merge(velocityContext, stringWriter); templateContent = stringWriter.toString(); templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})", "\\$$2$3$4$5$6"); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } return status; }
From source file:com.linkedin.pinot.routing.PercentageBasedRoutingTableSelector.java
public void init(Configuration configuration) { try {/*from ww w. ja v a 2 s . c om*/ Configuration tablesConfig = configuration.subset(TABLE_KEY); if (tablesConfig == null || tablesConfig.isEmpty()) { LOGGER.info("No specific table configuration. Using 0% LLC for all tables"); return; } ConfigurationMap cmap = new ConfigurationMap(tablesConfig); Set<Map.Entry<String, Integer>> mapEntrySet = cmap.entrySet(); for (Map.Entry<String, Integer> entry : mapEntrySet) { LOGGER.info("Using {} percent LLC routing for table {}", entry.getValue(), entry.getKey()); _percentMap.put(entry.getKey(), entry.getValue()); } } catch (Exception e) { LOGGER.warn("Could not parse get config for {}. Using no LLC routing", TABLE_KEY, e); } }
From source file:com.litt.saap.core.web.listener.InitSystemListener.java
/** * ?.// www .j av a2 s .c om */ public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); ServletContext application = event.getServletContext(); //HOME? Configuration config = ConfigManager.getInstance().getConfig(); if (config.isEmpty()) { logger.error("???"); throw new java.lang.RuntimeException("???"); } logger.info("?" + config.getString("system.version")); //homePath = props.getProperty("home.path"); String homePath = config.getString("home.path"); CoreConstants.IS_DEBUG = config.getBoolean("debug", false); SaapConstants.HOME_PATH = homePath; //???? logger.info("?" + homePath); File homeFile = new File(homePath); if (!homeFile.exists()) //??? { homeFile.mkdirs(); } //read license. // File licensePath = new File(homePath, "license"); // File licenseFile = new File(licensePath, "license.xml"); // File publicKeyFile = new File(licensePath, "license.key"); // try { // LicenseManager.reload(licenseFile.getPath(), publicKeyFile.getPath()); // } catch (LicenseException e) { // logger.error("Can't read license file.", e); // } String contextPath = application.getContextPath(); //???APPLICATION ISystemInfoService systemInfoService = BeanManager.getBean("systemInfoService", ISystemInfoService.class); SystemInfoVo systemInfoVo = systemInfoService.getSystemInfo(); systemInfoVo.setBaseUrl(config.getString("baseUrl") + contextPath); systemInfoVo.setHomePath(homePath); application.setAttribute(CoreConstants.APP_SYSTEMINFO, systemInfoVo); //servlet? }
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
public static boolean configureCommons(File tempDir, Configuration configuration) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && configuration != null && !configuration.isEmpty()) { Map<String, String> substitutionContext = JPackageManagerOld.createSubstitutionContext(configuration); StrSubstitutor strSubstitutor = new StrSubstitutor(substitutionContext); String templateContent = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); templateContent = strSubstitutor.replace(templateContent); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); }/*from w w w . j a va 2 s .c om*/ } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = strSubstitutor.replace(templateContent); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } return status; }
From source file:cz.cas.lib.proarc.common.object.emods.BornDigitalDisseminationHandler.java
private void createThumbnail(File inputFile, String message) throws DigitalObjectException { Configuration thumbConf = getConfig().getImportConfiguration().getThumbnailProcessor(); if (thumbConf != null && !thumbConf.isEmpty()) { GenericExternalProcess thumbProc = new GenericExternalProcess(thumbConf).addInputFile(inputFile) .addOutputFile(new File(inputFile.getAbsolutePath() + ".jpg")); thumbProc.run();/*from w w w .j a v a2 s .c o m*/ if (thumbProc.isOk()) { ddh.setDsDissemination(BinaryEditor.THUMB_ID, thumbProc.getOutputFile(), BinaryEditor.THUMB_LABEL, BinaryEditor.IMAGE_JPEG, message); } } }
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
public static boolean configure(File tempDir, Configuration configuration) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && configuration != null && !configuration.isEmpty()) { ST stringTemplate = null;// w w w. ja v a 2 s . c o m String templateContent = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); templateContent = templateContent.replace("${", "\\${"); templateContent = templateContent.replace("@", "\\@"); stringTemplate = new ST(JPackageManagerOld.ST_GROUP, templateContent); // stringTemplate = new ST(FileUtils.readFileToString(pfile)); JPackageManagerOld.addTemplateAttributes(stringTemplate, configuration); templateContent = stringTemplate.render(); templateContent = templateContent.replace("\\${", "${"); templateContent = templateContent.replace("\\@", "@"); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = templateContent.replace("${", "\\${"); templateContent = templateContent.replace("@", "\\@"); stringTemplate = new ST(JPackageManagerOld.ST_GROUP, templateContent); // stringTemplate = new ST(FileUtils.readFileToString(pfile)); JPackageManagerOld.addTemplateAttributes(stringTemplate, configuration); templateContent = stringTemplate.render(); templateContent = templateContent.replace("\\${", "${"); templateContent = templateContent.replace("\\@", "@"); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } return status; }
From source file:cz.cas.lib.proarc.common.imports.ImportProfile.java
public Configuration getThumbnailProcessor() { String processor = config.getString(THUMBNAIL_PROCESSOR, "-"); String confId = PROCESSOR + "." + processor; Configuration subset = config.subset(confId); if (!subset.isEmpty() && !subset.containsKey("id")) { subset.addProperty("id", confId); }/*w w w . j a v a 2 s . c o m*/ return subset; }