List of usage examples for java.util Properties keys
@Override
public Enumeration<Object> keys()
From source file:org.mrgeo.data.accumulo.utils.AccumuloConnector.java
public static String encodeAccumuloProperties(String r) { StringBuffer sb = new StringBuffer(); // sb.append(MrGeoAccumuloConstants.MRGEO_ACC_ENCODED_PREFIX); Properties props = getAccumuloProperties(); props.setProperty(MrGeoAccumuloConstants.MRGEO_ACC_KEY_RESOURCE, r); Enumeration<?> e = props.keys(); while (e.hasMoreElements()) { String k = (String) e.nextElement(); String v = props.getProperty(k); if (sb.length() > 0) { sb.append(MrGeoAccumuloConstants.MRGEO_ACC_ENCODED_DELIM); }/*from w w w.ja va 2 s . c o m*/ sb.append(k + "=" + v); } byte[] enc = Base64.encodeBase64(sb.toString().getBytes()); String retStr = new String(enc); retStr = MrGeoAccumuloConstants.MRGEO_ACC_ENCODED_PREFIX + retStr; return retStr; }
From source file:gdt.data.grain.Locator.java
/** * Remove the name/value pair from the locator. * @param locator$ the locator string/*from w ww . j ava2 s .c o m*/ * @param name$ the name. * @return the locator string. */ public static String remove(String locator$, String name$) { if (name$ == null) return locator$; Properties locator = toProperties(locator$); if (locator == null) return locator$; Enumeration<?> en = locator.keys(); String key$; while (en.hasMoreElements()) { key$ = (String) en.nextElement(); if (name$.equals(key$)) { locator.remove(key$); break; } } return toString(locator); }
From source file:Main.java
/** * Find an element//from w w w.j av a 2s .c om * @param doc XML document * @param tagName Tag name * @param props Properties corresponding to attributes in tag * @return Element or null if not found */ public static Element findElement(Document doc, String tagName, Properties props) { Element elmt = null; NodeList nlist = doc.getElementsByTagName(tagName); for (int i = 0; i < nlist.getLength() && elmt == null; i++) { Node node = nlist.item(i); if (node instanceof Element) { Element temp = (Element) node; boolean matches = true; for (Enumeration en = props.keys(); en.hasMoreElements() && matches;) { String name = (String) en.nextElement(); String value = props.getProperty(name); String attValue = temp.getAttribute(name); if (attValue == null) matches = false; else if (!value.equals(attValue)) matches = false; } if (matches) elmt = temp; } } return elmt; }
From source file:gdt.data.grain.Locator.java
/** * Append the name/value pairs from the other locator. If the name * already exists it will be ignored. * @param locator$ the target locator string * @param locator2$ the second locator string. * @return the result locator string. *//*from w w w .j a v a 2 s .c o m*/ public static String merge(String locator$, String locator2$) { try { Properties locator = toProperties(locator2$); if (locator == null) return locator$; Enumeration<?> en = locator.keys(); String key$; String value$; while (en.hasMoreElements()) { key$ = (String) en.nextElement(); value$ = locator.getProperty(key$); locator$ = Locator.append(locator$, key$, value$); } return locator$; } catch (Exception e) { Logger.getLogger(Locator.class.getName()).severe(e.toString()); return null; } }
From source file:org.openadaptor.util.PropertiesPoster.java
/** * Simple utility method to convert a set of properties into a HTTP POST string. * // www .j a v a2 s . com * @param properties * @return String containing appropriately encoded name/value pairs * @throws UnsupportedEncodingException */ public static String generatePOSTData(Properties properties) throws UnsupportedEncodingException { StringBuffer sb = new StringBuffer(); if (properties != null) { for (Enumeration keys = properties.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); String value = properties.getProperty(key); if (sb.length() > 0) {// Need separator between <name>=<value> pairs sb.append("&"); } sb.append(URLEncoder.encode(key, DEFAULT_ENCODING)); sb.append("="); sb.append(URLEncoder.encode(value, DEFAULT_ENCODING)); } } log.debug("Generated POST data:" + sb.toString()); return sb.toString(); }
From source file:Main.java
/** * Convert Properties to string/* w w w . j ava 2 s . c om*/ * * @param props * @return xml string * @throws IOException */ public static String writePropToString(Properties props) throws IOException { try { org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); org.w3c.dom.Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); for (Enumeration e = props.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object object = props.get(name); String value; if (object instanceof String) { value = (String) object; } else { continue; } org.w3c.dom.Element propNode = doc.createElement("property"); conf.appendChild(propNode); org.w3c.dom.Element nameNode = doc.createElement("name"); nameNode.appendChild(doc.createTextNode(name.trim())); propNode.appendChild(nameNode); org.w3c.dom.Element valueNode = doc.createElement("value"); valueNode.appendChild(doc.createTextNode(value.trim())); propNode.appendChild(valueNode); conf.appendChild(doc.createTextNode("\n")); } Source source = new DOMSource(doc); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (Exception e) { throw new IOException(e); } }
From source file:gdt.data.grain.Locator.java
/** * Convert properties into the locator string. * @param props properties // ww w. j av a 2 s.co m * @return locator string. */ public static String toString(Properties props) { if (props == null) return null; try { StringBuffer sb = new StringBuffer(); Enumeration<?> keys = props.keys(); if (keys == null) return null; String name$; String value$; while (keys.hasMoreElements()) { name$ = (String) keys.nextElement(); value$ = props.getProperty(name$); if (value$ != null) sb.append(name$ + VALUE_DELIMITER + value$ + NAME_DELIMITER); } String locator$ = sb.toString(); locator$.substring(0, locator$.length() - NAME_DELIMITER.length()); return sb.toString(); } catch (Exception e) { Logger.getLogger(Locator.class.getName()).severe(":compress:" + e.toString()); return null; } }
From source file:org.jfrog.teamcity.agent.util.ArtifactoryClientConfigurationBuilder.java
private static void addMatrixParamProperties(BuildRunnerContext runnerContext, ArtifactoryClientConfiguration clientConf) { Properties fileAndSystemProperties = BuildInfoExtractorUtils .mergePropertiesWithSystemAndPropertyFile(new Properties()); Properties filteredMatrixParams = BuildInfoExtractorUtils.filterDynamicProperties(fileAndSystemProperties, BuildInfoExtractorUtils.MATRIX_PARAM_PREDICATE); Enumeration<Object> propertyKeys = filteredMatrixParams.keys(); while (propertyKeys.hasMoreElements()) { String key = propertyKeys.nextElement().toString(); clientConf.publisher.addMatrixParam(key, filteredMatrixParams.getProperty(key)); }//from w ww .ja v a 2s . c o m HashMap<String, String> allParamMap = Maps .newHashMap(runnerContext.getBuildParameters().getAllParameters()); allParamMap.putAll(((BuildRunnerContextImpl) runnerContext).getConfigParameters()); gatherBuildInfoParams(allParamMap, clientConf.publisher, ClientProperties.PROP_DEPLOY_PARAM_PROP_PREFIX, Constants.ENV_PREFIX, Constants.SYSTEM_PREFIX); }
From source file:info.guardianproject.net.http.HttpManager.java
public static String doGet(String serviceEndpoint, Properties props) throws Exception { HttpClient httpClient = new SocksHttpClient(); StringBuilder uriBuilder = new StringBuilder(serviceEndpoint); StringBuffer sbResponse = new StringBuffer(); Enumeration<Object> enumProps = props.keys(); String key, value = null;// w ww. j a v a2 s. co m uriBuilder.append('?'); while (enumProps.hasMoreElements()) { key = (String) enumProps.nextElement(); value = (String) props.get(key); uriBuilder.append(key); uriBuilder.append('='); uriBuilder.append(java.net.URLEncoder.encode(value)); uriBuilder.append('&'); } HttpGet request = new HttpGet(uriBuilder.toString()); HttpResponse response = httpClient.execute(request); int status = response.getStatusLine().getStatusCode(); // we assume that the response body contains the error message if (status != HttpStatus.SC_OK) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); response.getEntity().writeTo(ostream); Log.e("HTTP CLIENT", ostream.toString()); return null; } else { InputStream content = response.getEntity().getContent(); // <consume response> BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) sbResponse.append(line); content.close(); // this will also close the connection } return sbResponse.toString(); }
From source file:com.openideals.android.net.HttpManager.java
public static String doGet(String serviceEndpoint, Properties props) throws Exception { HttpClient httpClient = new DefaultHttpClient(); StringBuilder uriBuilder = new StringBuilder(serviceEndpoint); StringBuffer sbResponse = new StringBuffer(); Enumeration<Object> enumProps = props.keys(); String key, value = null;/*from w w w .ja v a 2 s. co m*/ uriBuilder.append('?'); while (enumProps.hasMoreElements()) { key = (String) enumProps.nextElement(); value = (String) props.get(key); uriBuilder.append(key); uriBuilder.append('='); uriBuilder.append(java.net.URLEncoder.encode(value)); uriBuilder.append('&'); } HttpGet request = new HttpGet(uriBuilder.toString()); HttpResponse response = httpClient.execute(request); int status = response.getStatusLine().getStatusCode(); // we assume that the response body contains the error message if (status != HttpStatus.SC_OK) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); response.getEntity().writeTo(ostream); Log.e("HTTP CLIENT", ostream.toString()); return null; } else { InputStream content = response.getEntity().getContent(); // <consume response> BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) sbResponse.append(line); content.close(); // this will also close the connection } return sbResponse.toString(); }