List of usage examples for java.util Properties isEmpty
@Override public boolean isEmpty()
From source file:org.mule.util.PropertiesUtilsTestCase.java
@Test public void testLoadAllPropertiesNoFile() { Properties properties = PropertiesUtils.loadAllProperties( "META-INF/services/org/mule/config/mule-non-existent.properties", this.getClass().getClassLoader()); assertThat(properties, IsNull.notNullValue()); assertThat(properties.isEmpty(), is(true)); }
From source file:com.trafficspaces.api.controller.Connector.java
private String toQueryString(Properties params) throws TrafficspacesAPIException { StringBuffer queryString = new StringBuffer(); if (params != null && !params.isEmpty()) { Iterator itr = params.entrySet().iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); try { queryString.append(URLEncoder.encode((String) entry.getKey(), "UTF-8")); queryString.append("="); queryString.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); queryString.append("&"); } catch (UnsupportedEncodingException uee) { throw new TrafficspacesAPIException(uee); }//from w w w . j a v a 2 s .c o m } } return queryString.toString(); }
From source file:hydrograph.server.execution.tracking.utils.ExecutionTrackingUtils.java
/** * This function will load property file to initialize the parameters values. * *//*from w w w. j a v a 2s. c o m*/ public void loadPropertyFile() { try (FileInputStream stream = getExternalPropertyFilePath(); InputStream inputStream = this.getClass().getResourceAsStream(getInternalPropertyFilePath());) { Properties properties = new Properties(); if (stream != null) { properties.load(stream); } else { properties.load(inputStream); } if (!properties.isEmpty()) { portNo = properties.getProperty(PORT_NO); host = properties.getProperty(LOCAL_URL); route = properties.getProperty(TRACKING_ROUTE); String frequency = properties.getProperty(STATUS_FREQUENCY); statusFrequency = Long.parseLong(frequency); } } catch (IOException exception) { logger.error("Failed to load properties file", exception); } }
From source file:com.fer.hr.olap.query.QuerySerializer.java
private Element appendProperties(Element rootElement) { Element props = new Element("Properties"); Properties p = this.query.getProperties(); if (p != null && !p.isEmpty()) { for (Object key : p.keySet()) { Element pe = new Element("Property"); String k = key.toString(); String v = p.getProperty(k); pe.setAttribute("name", k); pe.setAttribute("value", v); props.addContent(pe);/*from w w w . ja va2s . co m*/ } } rootElement.addContent(props); return rootElement; }
From source file:com.laex.j2objc.ToObjectiveCDelegate.java
/** * Builds the command.//w w w . j a v a 2s . c o m * * @param display the display * @param prefs the prefs * @param project the project * @param resource the resource * @param sourcePath the source path * @param outputPath the output path * @return the string * @throws CoreException the core exception * @throws IOException Signals that an I/O exception has occurred. */ private String buildCommand(Display display, Map<String, String> prefs, IProject project, IResource resource, String sourcePath, String outputPath) throws CoreException, IOException { StringBuilder sb = new StringBuilder(); // Create platform indenpendent path and append the path to the compiler IPath pathToCompiler = new Path(prefs.get(PreferenceConstants.PATH_TO_COMPILER)) .append(PreferenceConstants.J2_OBJC_COMPILER); sb.append(pathToCompiler.toOSString()).append(" "); Properties classpathProps = PropertiesUtil.getClasspathEntries(project); if (!classpathProps.isEmpty()) { sb.append(PreferenceConstants.CLASSPAPTH).append(" "); for (Object key : classpathProps.keySet()) { sb.append(key).append(":"); } sb.append(" "); } if (StringUtils.isEmpty(prebuiltSwitch)) { prebuildSwitches(display, prefs, project); } sb.append(prebuiltSwitch); if (resource instanceof IFile) { String charset = ((IFile) resource).getCharset(); sb.append(PreferenceConstants.ENCODING).append(" ").append(charset).append(" "); } sb.append(PreferenceConstants.OUTPUT_DIR).append(" ").append(outputPath).append(" "); sb.append(sourcePath); return sb.toString(); }
From source file:org.eclipse.gyrex.cloud.internal.state.ZooKeeperNodeStatePublisher.java
public void publish(final String pid, final ServiceReference<INodeState> reference) { if (!IdHelper.isValidId(pid)) throw new IllegalArgumentException("Invalid PID"); try {//from ww w . java 2s. c o m execute(new ZooKeeperGateCallable<Boolean>() { @Override protected Boolean call(final ZooKeeperGate keeper) throws Exception { // create data to save final Properties props = getStateData(reference); if (props.isEmpty()) return Boolean.FALSE; // serialize service properties final ByteArrayOutputStream out = new ByteArrayOutputStream(); props.store(out, null); final byte[] data = out.toByteArray(); // write data keeper.writeRecord(IZooKeeperLayout.PATH_NODES_STATE_BY_NODE_ID.append(myNodeId).append(pid), CreateMode.EPHEMERAL, data); keeper.writeRecord( IZooKeeperLayout.PATH_NODES_STATE_BY_SERVICE_PID.append(pid).append(myNodeId), CreateMode.EPHEMERAL, data); return Boolean.TRUE; } }); } catch (final SessionExpiredException e) { // safe to ignore because we use ephemeral nodes } catch (final Exception e) { if ((e instanceof ConnectionLossException) || (e instanceof GateDownException)) { LOG.debug("Unable to publish node state '{}'. {}", new Object[] { pid, ExceptionUtils.getRootCauseMessage(e), e }); } else { LOG.error("Unable to publish node state '{}'. {}", new Object[] { pid, ExceptionUtils.getRootCauseMessage(e), e }); } } }
From source file:org.apache.falcon.recipe.RecipeTool.java
@Override public int run(String[] arguments) throws Exception { Map<RecipeToolArgs, String> argMap = setupArgs(arguments); if (argMap == null || argMap.isEmpty()) { throw new Exception("Arguments passed to recipe is null"); }// ww w . j a va2 s . c o m Configuration conf = getConf(); String recipePropertiesFilePath = argMap.get(RecipeToolArgs.RECIPE_PROPERTIES_FILE_ARG); Properties recipeProperties = loadProperties(recipePropertiesFilePath); validateProperties(recipeProperties); String recipeOperation = argMap.get(RecipeToolArgs.RECIPE_OPERATION_ARG); Recipe recipeType = RecipeFactory.getRecipeToolType(recipeOperation); if (recipeType != null) { recipeType.validate(recipeProperties); Properties props = recipeType.getAdditionalSystemProperties(recipeProperties); if (props != null && !props.isEmpty()) { recipeProperties.putAll(props); } } createWindowsLocalPaths(recipeProperties); String processFilename; FileSystem fs = getFileSystemForHdfs(recipeProperties, conf); validateArtifacts(recipeProperties, fs); String recipeName = recipeProperties.getProperty(RecipeToolOptions.RECIPE_NAME.getName()); copyFilesToHdfsIfRequired(recipeProperties, fs, recipeName); processFilename = RecipeProcessBuilderUtils.createProcessFromTemplate( argMap.get(RecipeToolArgs.RECIPE_FILE_ARG), recipeProperties, argMap.get(RecipeToolArgs.RECIPE_PROCESS_XML_FILE_PATH_ARG)); System.out.println("Generated process file to be scheduled: "); System.out.println(FileUtils.readFileToString(new File(processFilename))); System.out.println("Completed recipe processing"); return 0; }
From source file:org.intermine.web.logic.config.WebConfig.java
/** * Load a set of files into a single merged properties file. These files should all be * located in the WEB-INF directory of the webapp war. * * @param fileNames The file names to load. * @throws FileNotFoundException If a file is listed but does not exist in WEB-INF. * @throws IllegalStateException If two files configure the same key. * @throws IOException if the properties cannot be loaded. *//*from w w w. j a va 2s. co m*/ private static Properties loadMergedProperties(final List<String> fileNames, final ServletContext context) throws IOException { final Properties props = new Properties(); for (final String fileName : fileNames) { LOG.info("Loading properties from " + fileName); final Properties theseProps = new Properties(); final InputStream is = context.getResourceAsStream("/WEB-INF/" + fileName); if (is == null) { throw new FileNotFoundException("Could not find mappings file: " + fileName); } try { theseProps.load(is); } catch (final IOException e) { throw new Error("Problem reading from " + fileName, e); } if (!props.isEmpty()) { for (@SuppressWarnings("rawtypes") final Enumeration e = props.propertyNames(); e.hasMoreElements();) { final String key = (String) e.nextElement(); if (theseProps.containsKey(key)) { throw new IllegalStateException("Duplicate label found for " + key + " in " + fileName); } } } if (theseProps.isEmpty()) { LOG.info("No properties loaded from " + fileName); } else { LOG.info("Merging in " + theseProps.size() + " mappings from " + fileName); props.putAll(theseProps); } } return props; }
From source file:fr.landel.utils.commons.StringUtils.java
/** * Injects all arguments in the specified char sequence. The arguments are * injected by replacement of keys between braces. To exclude keys, just * double braces (like {{key}} will return {key}). If some keys aren't * found, they are ignored./*from w ww . j a v a2 s . co m*/ * * <p> * precondition: {@code charSequence} cannot be {@code null} * </p> * * <pre> * Properties properties = new Properties(); * properties.setProperty("where", "beach"); * properties.setProperty("when", "afternoon"); * * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "", properties); * // => "" * * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to the ${where} this ${when}", properties); * // => "I'll go to the beach this afternoon" * * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to ${where}${{where}}${where}", properties); * // => "I'll go to beach${where}beach" * </pre> * * @param include * the characters that surround the property key to replace * @param exclude * the characters that surround the property key to exclude of * replacement * @param charSequence * the input char sequence * @param properties * the properties to inject * @return the result with replacements */ public static String injectKeys(final Pair<String, String> include, final Pair<String, String> exclude, final CharSequence charSequence, final Properties properties) { if (charSequence == null) { throw new IllegalArgumentException("The input char sequence cannot be null"); } else if (isEmpty(charSequence) || properties == null || properties.isEmpty()) { return charSequence.toString(); } return injectKeys(include, exclude, charSequence, properties.entrySet().toArray(CastUtils.cast(new Map.Entry[properties.size()]))); }
From source file:org.wso2.carbon.datasource.ui.DatasourceManagementClient.java
public void editDatasourceInformation(DataSourceInformation information) throws DataSourceManagementException, RemoteException { validateDataSourceInformation(information); if (log.isDebugEnabled()) { log.debug("Going to Edit DataSourceInformation :" + information); }/*from w w w . j a v a 2s . co m*/ Properties properties = DataSourceInformationSerializer.serialize(information); if (properties.isEmpty()) { handleException("Empty Properties"); } OMElement datasourceElement = createOMElement(properties); validateDataSourceElement(datasourceElement); if (log.isDebugEnabled()) { log.debug("DataSourceconfiguration :" + datasourceElement); } stub.editDataSourceInformation(information.getAlias(), datasourceElement); }