List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:Main.java
public static String fixTagEndings(String body) { String newBody = body; Matcher matcher = ENDTAG_AFTER_NEWLINE_PATTERN.matcher(body); while (matcher.find()) { String endTag = matcher.group(1); newBody = newBody.replaceFirst("\n" + endTag, endTag + "\n"); matcher = ENDTAG_AFTER_NEWLINE_PATTERN.matcher(newBody); }//from w ww .j av a 2 s. com return newBody; }
From source file:org.restsql.core.impl.SqlUtils.java
public static String removeWhitespaceFromSql(String sql) { sql.replaceAll("\\n", " "); sql = sql.replaceAll("\\r", " "); sql = sql.replaceFirst("\\s+", " "); sql = sql.replaceFirst("\\t+", " "); sql = sql.replaceFirst("\\t+$", " "); sql = sql.replaceAll("\\t", " "); return sql;//from w ww . java2 s . c om }
From source file:com.syncthemall.enml4j.util.Utils.java
/** * Return a base64 encoded icon for a given mime type. If the mime type is unknown or the icon is unavailable, * returns the base64 encoded {@code String} of an unknown icon (an icon with a question mark). * /*from w ww. j a v a2 s . c o m*/ * @param mimeType the mime type (ie application/rtf, image/bmp, ...) * @return a base64 encoded {@code String} of the icon corresponding to the mime type in parameter */ public static String getEncodedIcon(final String mimeType) { InputStream icon = Utils.class.getResourceAsStream("/icons/" + mimeType.replaceFirst("/", "-") + ".png"); if (icon == null) { return UNKNOWN_ICON; } try { return encodeToBase64Binary(icon); } catch (IOException e) { return UNKNOWN_ICON; } }
From source file:com.bluexml.xforms.messages.DefaultMessages.java
/** * @param generationParameters/*from w ww. ja va2 s.co m*/ * @param args * @throws IOException */ public static boolean generateFormsFile(String filePath, Map<String, String> generationParameters) throws IOException { String[] properties = allFormsProperties; String alfURL = generationParameters.get(CONFIGURATION_PARAMETER_ALFRESCO_URL); String alfAdminLogin = generationParameters.get(CONFIGURATION_PARAMETER_ALFRESCO_ADMIN_LOGIN); String alfAdminPassWord = generationParameters.get(CONFIGURATION_PARAMETER_ALFRESCO_ADMIN_PSW); boolean haveNewURL = alfURL != null && !alfURL.equals(""); boolean haveNewLogin = alfAdminLogin != null && !alfAdminLogin.equals(""); boolean haveNewPswd = alfAdminPassWord != null && !alfAdminPassWord.equals(""); if (haveNewURL || haveNewLogin || haveNewPswd) { for (int i = 0; i < properties.length; i++) { String string = properties[i]; if (string.startsWith("alfresco.url") && haveNewURL) { properties[i] = string.replaceFirst("(alfresco\\.url=).*$", "$1" + alfURL); } if (string.startsWith("user.name") && haveNewLogin) { properties[i] = string.replaceFirst("(user\\.name=).*$", "$1" + alfAdminLogin); } if (string.startsWith("user.pswd") && haveNewPswd) { properties[i] = string.replaceFirst("(user\\.pswd=).*$", "$1" + alfAdminPassWord); } } } return generate(filePath, properties); }
From source file:com.nabla.wapp.server.json.SqlToJson.java
public static String createSql(final AbstractFetch options, final String baseSql) { String sql;//from w w w. j a v a2s .c om if (options.isRange()) sql = baseSql.replaceFirst("SELECT", "SELECT SQL_CALC_FOUND_ROWS"); else sql = baseSql; final String orderBy = options.getOrderBy(); if (orderBy != null) { if (log.isTraceEnabled()) log.trace("ORDER BY = " + orderBy); final String tmp = sql.replaceFirst("\\{ORDER BY\\}", "ORDER BY " + orderBy); if (sql.equals(tmp)) sql = tmp.replaceFirst("\\{AND ORDER BY\\}", ", " + orderBy); else sql = tmp; } else sql = sql.replaceFirst("\\{ORDER BY\\}", "").replaceFirst("\\{AND ORDER BY\\}", ""); final String where = options.getFilter(); if (where != null) { if (log.isTraceEnabled()) log.trace("WHERE = " + where); final String tmp = sql.replaceFirst("\\{WHERE\\}", "WHERE " + where); if (sql.equals(tmp)) sql = tmp.replaceFirst("\\{AND WHERE\\}", "AND " + where); else sql = tmp; } else { sql = sql.replaceFirst("\\{WHERE\\}", "").replaceFirst("\\{AND WHERE\\}", ""); } if (options.isRange()) sql += " LIMIT ? OFFSET ?"; sql += ";"; if (log.isInfoEnabled()) log.info("SQL: " + sql); return sql; }
From source file:dev.meng.wikipedia.profiler.util.StringUtils.java
public static String replace(String string, Object... values) { String result = string; for (Object value : values) { if (string.contains("?")) { result = result.replaceFirst("\\?", value.toString()); }/*from w ww.j a v a 2s . c o m*/ } return result; }
From source file:org.gytheio.messaging.jackson.JsonClassKeyDeserializer.java
public static Object deserializeKeyToClass(String key) throws IOException, JsonProcessingException { if (!key.startsWith("class ")) { throw new IllegalArgumentException("Invalid key format"); }/*from w w w.ja v a 2 s.c om*/ String classname = key.replaceFirst("class ", ""); try { return JsonClassKeyDeserializer.class.getClassLoader().loadClass(classname); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
From source file:org.wso2.bps.integration.tests.bpmn.BPMNTestUtils.java
/** * Returns BPMN rest endpoint from bps backend url * * @param backEndUrl/*from ww w . j av a 2 s . c o m*/ * @return bpmnUrl */ public static String getRestEndPoint(String backEndUrl) { return backEndUrl.replaceFirst(BACKEND_URL_SUFFIX, BPMN_REST_URL_SUFFIX); }
From source file:com.brett.http.geo.baidu.GeoRequestHttpClient.java
public static JsonNode geoAcquire(String city) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); // DefaultHttpParams.getDefaultParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); // httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); try {/*from w w w .j av a 2 s . c o m*/ String address = URLEncoder.encode(city, "utf-8"); String url = "http://api.map.baidu.com/geocoder/v2/?address={address}&output=json&ak=E4805d16520de693a3fe707cdc962045"; url = url.replaceFirst("\\{address\\}", address); HttpGet httpget = new HttpGet(url); httpget.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); httpget.setHeader("Accept-Encoding", "gzip, deflate, sdch"); httpget.setHeader("Accept-Language", "zh-CN,zh;q=0.8"); httpget.setHeader("Cache-Control", "no-cache"); httpget.setHeader("Connection", "keep-alive"); httpget.setHeader("Referer", "http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding"); httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"); System.out.println("Executing request httpget.getRequestLine() " + httpget.getRequestLine()); // Create a custom response handler ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity, "utf-8") : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; String responseBody = httpclient.execute(httpget, responseHandler); System.out.println("----------------------------------------"); System.out.println(HtmlDecoder.decode(responseBody)); System.out.println(responseBody); System.out.println("----------------------------------------"); ObjectMapper mapper = new ObjectMapper(); mapper.readValue(responseBody, AddressCoord.class); // JsonNode root = mapper.readTree(responseBody.substring("showLocation&&showLocation(".length(), responseBody.length()-1)); // {"status":0,"result":{"location":{"lng":116.30783584945,"lat":40.056876296398},"precise":1,"confidence":80,"level":"\u5546\u52a1\u5927\u53a6"}} JsonNode root = mapper.readTree(responseBody); System.out.println("result : " + city + " = " + root.get("result")); return root; } finally { httpclient.close(); } }
From source file:com.nextep.designer.sqlgen.helpers.GenerationHelper.java
/** * Tries to remove from the specified SQL definition the last specified * statement delimiter if present.//from w ww.j a va2s .c o m * * @param definition * a <code>String</code> representing a SQL definition of a * database object * @param delimiter * the statement delimiter to remove from the end of the SQL * definition * @return a <code>String</code> representing the cleaned SQL definition if * the specified delimiter has been found, the same SQL definition * otherwise */ public static String removeLastStatementDelimiter(String definition, String delimiter) { if (definition != null) { return definition.replaceFirst("\\s*" + delimiter + "\\s*$", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return definition; }