List of usage examples for org.apache.commons.lang3 StringUtils replace
public static String replace(final String text, final String searchString, final String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"
From source file:cgeo.geocaching.connector.gc.GCParser.java
private static String convertLinks(String input) { if (input == null) { return null; }/*from ww w. j a v a2 s .c o m*/ return StringUtils.replace(input, "../", GCConstants.GC_URL); }
From source file:com.sonicle.webtop.mail.Service.java
public String replaceCidUrls(String html, HTMLMailData maildata, String preurl) throws MessagingException { for (String cidname : maildata.getCidNames()) { //Part part=maildata.getCidPart(cidname); String surl = preurl + cidname; html = StringUtils.replace(html, "cid:" + cidname, surl); }//from w w w . j a v a 2 s. c o m return html; }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
private synchronized String buildGetDeviceCommandPath(DeviceCommand command) { String path = StringUtils.replace(PATH_DEVICES_COMMAND, "{deviceId}", command.getDeviceId()); path = StringUtils.replace(path, "{command}", command.getCommand()); if (command.getParams() != null) { path += "?"; Integer index = 0;/*from w w w . j a v a 2s. c o m*/ for (Entry<String, String> entry : command.getParams().entrySet()) { if (index > 0) { path += "&"; } try { path += URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { logger.warn("Device command parameter invalid: {}", e.getMessage()); mCaller.apiError("Device command parameter invalid: " + e.getMessage(), false); return null; } index++; } } return path; }
From source file:com.xpn.xwiki.store.XWikiHibernateStore.java
/** * This is in response to the fact that Hibernate interprets backslashes differently from the database. Our solution * is to simply replace all instances of \ with \\ which makes the first backslash escape the second. * /*from w w w. jav a 2 s. com*/ * @param sql the uncleaned sql. * @return same as sql except it is guarenteed not to contain groups of odd numbers of backslashes. * @since 2.4M1 */ private String filterSQL(String sql) { return StringUtils.replace(sql, "\\", "\\\\"); }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
/********************** ****** ZWaveAPI ******//from w w w. j a v a 2 s . c o m **********************/ /* * (non-Javadoc) * * @see de.fh_zwickau.informatik.sensor.ZWayApiBase#getZWaveDevice(int) */ @Override public synchronized ZWaveDevice getZWaveDevice(int nodeId) { if (checkLogin()) { try { startHttpClient(); String path = URLEncoder.encode( StringUtils.replace(ZWAVE_PATH_DEVICES, "{nodeId}", String.valueOf(nodeId)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).method(HttpMethod.GET) .header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getZWaveDevice(nodeId); } } else { processResponseStatus(statusCode); } } else { return parseGetZWaveDevice(response.getContentAsString()); } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { return getZWaveDevice(nodeId); } } } else { handleException(e, "get zwave device"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method return null; }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public void getZWaveDevice(final int nodeId, final IZWayCallback<ZWaveDevice> callback) { if (checkLogin()) { try {/*from w ww.j a va 2s . c om*/ startHttpClient(); String path = URLEncoder.encode( StringUtils.replace(ZWAVE_PATH_DEVICES, "{nodeId}", String.valueOf(nodeId)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).method(HttpMethod.GET) .header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)) .onRequestFailure(new ZWayFailureListener()); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } request.send(new BufferingResponseListener() { @Override public void onComplete(Result result) { int statusCode = result.getResponse().getStatus(); if (statusCode != HttpStatus.OK_200) { if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getZWaveDevice(nodeId, callback); } } else { processResponseStatus(statusCode); } } else { callback.onSuccess(parseGetZWaveDevice(getContentAsString())); } } }); } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getZWaveDevice(nodeId, callback); } } } else { handleException(e, "get zwave device"); } } finally { // do not stop http client for asynchronous call } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized void getZWaveInclusion(int flag) { if (checkLogin()) { try {/* w w w . ja v a2 s .com*/ startHttpClient(); String path = URLEncoder .encode(StringUtils.replace(ZWAVE_PATH_INCLUSION, "{flag}", String.valueOf(flag)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).method(HttpMethod.GET) .header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getZWaveInclusion(flag); } } else { processResponseStatus(statusCode); } } else { return; } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getZWaveInclusion(flag); } } } else { handleException(e, "get zwave inclusion"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:de.fh_zwickau.informatik.sensor.ZWayApiHttp.java
@Override public synchronized void getZWaveExclusion(int flag) { if (checkLogin()) { try {/*from ww w . j av a 2 s .c om*/ startHttpClient(); String path = URLEncoder .encode(StringUtils.replace(ZWAVE_PATH_EXCLUSION, "{flag}", String.valueOf(flag)), "UTF-8"); Request request = mHttpClient.newRequest(getZWaveTopLevelUrl() + "/" + path).method(HttpMethod.GET) .header(HttpHeader.ACCEPT, "application/json") .header(HttpHeader.CONTENT_TYPE, "application/json") .cookie(new HttpCookie("ZWAYSession", mZWaySessionId)); if (mUseRemoteService) { request.cookie(new HttpCookie("ZBW_SESSID", mZWayRemoteSessionId)); } ContentResponse response = request.send(); // Check HTTP status code int statusCode = response.getStatus(); if (statusCode != HttpStatus.OK_200) { // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getZWaveExclusion(flag); } } else { processResponseStatus(statusCode); } } else { return; } } catch (Exception e) { if (e.getCause() instanceof HttpResponseException) { int statusCode = ((HttpResponseException) e.getCause()).getResponse().getStatus(); // Authentication error - retry login and operation if (statusCode == HttpStatus.UNAUTHORIZED_401) { if (getLogin() == null) { mCaller.authenticationError(); } else { getZWaveExclusion(flag); } } } else { handleException(e, "get zwave exclusion"); } } finally { stopHttpClient(); } } // no else ... checkLogin() method will invoke the appropriate callback method }
From source file:it.at.script.ConnectionScannerTest.java
public static String getRealPathOfResource(String resourceName) throws IOException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final Enumeration<URL> resources = loader.getResources(resourceName); final String path = resources.nextElement().toString(); final String replace = StringUtils.replace(path, "target/test-classes", "src/test/resources"); return StringUtils.substringAfter(replace, "file:"); }
From source file:com.hiperf.common.ui.server.storage.impl.PersistenceHelper.java
private StringBuilder getCheckExistsQuery(String className, String attribute, String value, boolean isNumber, boolean isString) { StringBuilder q = new StringBuilder("select 1 from " + className + " o where "); if (isString) { q.append("lower(o.").append(attribute).append(") = ?1"); } else if (isNumber) q.append("o.").append(attribute).append(" = ").append(value); else/*from w ww .j a v a2s.c o m*/ q.append("o.").append(attribute).append(" = '").append(StringUtils.replace(value, "'", "''")) .append("'"); return q; }