List of usage examples for java.lang String toString
public String toString()
From source file:net.firstpartners.nounit.utility.XmlUtil.java
/** * indexes the nodes in the document that is passed in , via a HashMap mapping * mapping is in the format <index> as String , handle to <element> of node<BR> * Strings are used as they are better lookup in the hashmap. * @param inXmlDocument to generated the hashmap from * @param uniqueAttribute to do the index on (i.e. key in HashMap). Examples * of uniqueAttributes are id's or names. * @return HashMap containing mappings//from ww w .ja v a2 s .c o m */ public static HashMap getNodeIndex(Document inXmlDocument, String uniqueAttribute) { //Internal Variables int stackPointer = 0; String locationId = null; Attribute tmpAttribute = null; Element thisElement = null; ListIterator deepestList = null; HashMap mappings = new HashMap(); List stack = new Vector(); //Get the list information for the entire document stack.add(inXmlDocument.getContent().listIterator()); //Loop though the elements on list while (!stack.isEmpty()) { //Get the last list on the stack deepestList = (ListIterator) stack.get(stack.size() - 1); //Does this list have more elements? if (deepestList.hasNext()) { //if so Get Next element from this list thisElement = (Element) deepestList.next(); //Add Mapping for this element to hashtable tmpAttribute = thisElement.getAttribute(uniqueAttribute); //Attibute can be null for non folder elements (e.g. root element) - if so ignore if (tmpAttribute != null) { locationId = tmpAttribute.getValue(); if ((locationId != null) && (locationId != "")) { mappings.put(locationId.toString(), thisElement); } } //end add mapping //does this list have children ? if (thisElement.hasChildren()) { //if so add to the stack stackPointer++; stack.add(thisElement.getChildren().listIterator()); } } else { //if not , remove this list from the stack stack.remove(stackPointer); stackPointer--; } // end if stack has more elements } return mappings; }
From source file:com.ineunet.knife.persist.dao.support.JdbcDaoSupport.java
@Override public List<T> find(ICriteria criteria) { String sql = criteria.getQueryString(); log.info(sql);/*from w ww . j a v a 2 s .c o m*/ return getJdbcTemplate().query(sql.toString(), criteria.getValues(), this.getRowMapper()); }
From source file:com.android.dialer.lookup.google.GoogleForwardLookup.java
/** * Fetch a URL and return the response as a string encoded in either * UTF-8 or the charset specified in the Content-Type header. * * @param url URL//from w ww. ja v a 2s . c om * @return Response from server */ private String httpGetRequest(String url) throws IOException { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url.toString()); request.setHeader("User-Agent", mUserAgent); HttpResponse response = client.execute(request); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); String charset = getCharsetFromContentType(response.getEntity().getContentType().getValue()); return new String(out.toByteArray(), charset); }
From source file:com.mnxfst.testing.client.TSClientPlanResultCollectCallable.java
public TSClientPlanResultCollectCallable(String hostname, int port, String uri) { this.httpHost = new HttpHost(hostname, port); this.getMethod = new HttpGet(uri.toString()); // TODO setting? SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ThreadSafeClientConnManager threadSafeClientConnectionManager = new ThreadSafeClientConnManager( schemeRegistry);/* w w w. j a v a 2 s . co m*/ threadSafeClientConnectionManager.setMaxTotal(20); threadSafeClientConnectionManager.setDefaultMaxPerRoute(20); this.httpClient = new DefaultHttpClient(threadSafeClientConnectionManager); }
From source file:com.ripariandata.timberwolf.writer.hive.HiveMailWriter.java
private void getHive(final String hiveUri) { try {//from www. jav a 2s.c o m hive = DriverManager.getConnection(hiveUri); } catch (SQLException e) { String msg = "Error opening connection to hive at " + hiveUri.toString(); throw HiveMailWriterException.log(LOG, new HiveMailWriterException(msg, e)); } }
From source file:eionet.meta.dao.mysql.FolderDAOImpl.java
/** * {@inheritDoc}//from ww w .ja v a 2 s . co m */ @Override public void deleteFolder(int folderId) { String sql = "delete from VOCABULARY_SET where ID=:folderId"; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("folderId", folderId); getNamedParameterJdbcTemplate().update(sql.toString(), parameters); }
From source file:gate.util.TestFiles.java
/** Test the updateXmlElement method. */ public void testUpdateXmlElement() throws IOException { String nl = Strings.getNl();/*from ww w. jav a 2 s . c o m*/ String configElementName = "GATECONFIG"; String configElement = "<" + configElementName + " FULLSIZE=\"yes\"/>"; String exampleXmlStart = "<?xml version=\"1.0\"?>" + nl + "<!-- a comment -->" + nl + "<GATE>" + nl + "" + nl + "<CREOLE-DIRECTORY>http://on.the.net/</CREOLE-DIRECTORY>" + nl + "<!--- The next element may be overwritten by the GUI --->" + nl; String exampleXmlEnd = "</GATE>" + nl; String exampleXml = exampleXmlStart + configElement + nl + exampleXmlEnd; // check that the getEmptyElement method works assertTrue("the GATECONFIG element doesn't match", getEmptyElement(exampleXml, configElementName).equals(configElement)); // a map of values to place in the new element Map<String, String> newAttrs = new HashMap<String, String>(); newAttrs.put("a", "1"); newAttrs.put("b", "2"); newAttrs.put("c", "3"); newAttrs.put("d", "needs&escaping"); // test the files method String newXml = Files.updateXmlElement(new BufferedReader(new StringReader(exampleXml)), configElementName, newAttrs); assertTrue("newXml doesn't match (1): " + newXml.toString(), newXml.toString().startsWith(exampleXmlStart) && newXml.toString().endsWith(exampleXmlEnd) && newXml.toString().contains("a=\"1\"") && newXml.toString().contains("d=\"needs&escaping\"")); if (DEBUG) Out.prln(newXml); // write the example data into a temp file and try on that File tempFile = Files.writeTempFile(exampleXml); newXml = Files.updateXmlElement(tempFile, configElementName, newAttrs); assertTrue("newXml doesn't match (2): " + newXml.toString(), newXml.toString().startsWith(exampleXmlStart) && newXml.toString().endsWith(exampleXmlEnd) && newXml.toString().contains("a=\"1\"") && newXml.toString().contains("d=\"needs&escaping\"")); if (DEBUG) Out.prln(newXml); // check that the file was overwritten successfully newXml = Files.getString(tempFile); assertTrue("newXml doesn't match (3): " + newXml.toString(), newXml.toString().startsWith(exampleXmlStart) && newXml.toString().endsWith(exampleXmlEnd) && newXml.toString().contains("a=\"1\"") && newXml.toString().contains("d=\"needs&escaping\"")); if (DEBUG) Out.prln(newXml); }
From source file:com.discovery.darchrow.net.URIUtil.java
/** * map ?? queryString./*from w ww. j av a 2 s . c o m*/ * * @param appendMap * request.getParamMap * @param charsetType * {@link CharsetType} ??null empty,?,?<br> * ??,??,ie?chrome ? url , ? * @return if isNullOrEmpty(appendMap) ,return "" * @see CharsetType */ public static String combineQueryString(Map<String, String[]> appendMap, String charsetType) { if (Validator.isNullOrEmpty(appendMap)) { return ""; } StringBuilder sb = new StringBuilder(); int i = 0; int size = appendMap.size(); for (Map.Entry<String, String[]> entry : appendMap.entrySet()) { String key = entry.getKey(); String[] paramValues = entry.getValue(); // ************************************************************** if (Validator.isNotNullOrEmpty(charsetType)) { // decode ? encode // ? key = encode(decode(key, charsetType), charsetType); } // ************************************************************** if (Validator.isNullOrEmpty(paramValues)) { LOGGER.warn("the param key:[{}] value is null", key); sb.append(key); sb.append("="); sb.append(""); } else { List<String> paramValueList = null; // value isNotNullOrEmpty if (Validator.isNotNullOrEmpty(charsetType)) { paramValueList = new ArrayList<String>(); for (String value : paramValues) { if (Validator.isNotNullOrEmpty(value)) { // ?queryString()? // chrome query encoded ??? // ie ???? // ??encoded, decode ? encode // ? decode(query, charsetType) ,? = paramValueList.add(encode(decode(value.toString(), charsetType), charsetType)); } else { paramValueList.add(""); } } } else { paramValueList = ArrayUtil.toList(paramValues); } for (int j = 0, z = paramValueList.size(); j < z; ++j) { String value = paramValueList.get(j); sb.append(key); sb.append("="); sb.append(value); // ?& ? if (j != z - 1) { sb.append(URIComponents.AMPERSAND); } } } // ?& ? if (i != size - 1) { sb.append(URIComponents.AMPERSAND); } ++i; } return sb.toString(); }
From source file:de.tu_berlin.dima.aim3.querysuggestion.QuerySuggTCase.java
private String[] splitInputString(String inputString, char splitChar, int noSplits) { String splitString = inputString.toString(); String[] splits = new String[noSplits]; int partitionSize = (splitString.length() / noSplits) - 2; // split data file and copy parts for (int i = 0; i < noSplits - 1; i++) { int cutPos = splitString.indexOf(splitChar, (partitionSize < splitString.length() ? partitionSize : (splitString.length() - 1))); try {//from w w w. j a v a 2s . c o m splits[i] = splitString.substring(0, cutPos) + "\n"; splitString = splitString.substring(cutPos + 1); System.out.println(splitString); } catch (Exception e) { System.err.println("bad split"); } } splits[noSplits - 1] = splitString; return splits; }
From source file:com.alibaba.wasp.zookeeper.FServerTracker.java
@Override public void nodeDeleted(String path) { if (path.startsWith(watcher.fsZNode)) { String serverName = ZKUtil.getNodeName(path); LOG.info("FServer ephemeral node deleted, processing expiration [" + serverName + "]"); ServerName sn = ServerName.parseServerName(serverName); if (!serverManager.isServerOnline(sn)) { LOG.warn(serverName.toString() + " is not online or isn't known to the master." + "The latter could be caused by a DNS misconfiguration."); return; }/*www . j a v a 2 s . c om*/ remove(sn); this.serverManager.expireServer(sn); } }