List of usage examples for java.util.regex Matcher appendTail
public StringBuilder appendTail(StringBuilder sb)
From source file:com.qumoon.commons.web.HTMLInputChecker.java
protected String checkTags(String s, boolean isHtml) { Matcher m = checkTagsPattern.matcher(s); StringBuffer buf = new StringBuffer(); while (m.find()) { String replaceStr = m.group(1); replaceStr = processTag(replaceStr, isHtml); appendReplacement(m, buf, replaceStr); }/* w ww. j a v a 2 s. c om*/ m.appendTail(buf); s = buf.toString(); if (isHtml) { // these get tallied in processTag // (remember to reset before subsequent calls to filter method) for (Iterator i = vTagCounts.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); for (int ii = 0; ii < ((Integer) vTagCounts.get(key)).intValue(); ii++) { s += "</" + key + ">"; } } } return s; }
From source file:com.google.code.simplestuff.bean.SimpleBeanTest.java
/** * Utility method for replace a pattern in a String. * //w w w. j a va 2 s .co m * @param source the source string. * @param pattern the pattern to match. * @param replacement The replacement. * @return the result string. */ private String replacePattern(String source, String pattern, String replacement) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(source); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, replacement); } m.appendTail(sb); return sb.toString(); }
From source file:Repackage.java
public StringBuffer repackage(StringBuffer sb) { StringBuffer result = null;/*www .j a v a2 s. c o m*/ for (int i = 0; i < _fromMatchers.length; i++) { Matcher m = (Matcher) _fromMatchers[i]; m.reset(sb); for (boolean found = m.find(); found; found = m.find()) { if (result == null) result = new StringBuffer(); m.appendReplacement(result, _toPackageNames[i]); } if (result != null) { m.appendTail(result); sb = result; result = null; } } return sb; }
From source file:com.brienwheeler.lib.validation.MessageSourceMessageInterpolator.java
@Override public String interpolate(String messageTemplate, Context context, Locale locale) { String resolvedMessage = messageSource.getMessage(messageTemplate, null, locale); // replaceVariables Matcher matcher = messageParameterPattern.matcher(resolvedMessage); StringBuffer sb = new StringBuffer(); String resolvedParameterValue; while (matcher.find()) { String parameterValue = removeCurlyBraces(matcher.group(1)); // first check the annotation constraints Object constraintValue = context.getConstraintDescriptor().getAttributes().get(parameterValue); if (constraintValue != null) parameterValue = constraintValue.toString(); // recurse back to MessageSource to find replacement value resolvedParameterValue = interpolate(parameterValue, context, locale); matcher.appendReplacement(sb, escapeMetaCharacters(resolvedParameterValue)); }//from w ww . ja v a 2 s . co m matcher.appendTail(sb); resolvedMessage = sb.toString(); // last but not least we have to take care of escaped literals resolvedMessage = resolvedMessage.replace("\\{", "{"); resolvedMessage = resolvedMessage.replace("\\}", "}"); resolvedMessage = resolvedMessage.replace("\\\\", "\\"); return resolvedMessage; }
From source file:com.g_node.gca.abstracts.AbstractContentTabFragment.java
private void fetchAndUpdateAuthorsDataFromDB() { //Query for getting author name, email, position, affiliation data for the particular Abstract String authorSQLQuery = "SELECT DISTINCT AUTHORS_DETAILS.AUTHOR_FIRST_NAME, " + "AUTHOR_MIDDLE_NAME, AUTHOR_LAST_NAME, AUTHOR_EMAIL, " + "ABSTRACT_AUTHOR_POSITION_AFFILIATION.AUTHOR_AFFILIATION, " + "ABSTRACT_AUTHOR_POSITION_AFFILIATION.AUTHOR_POSITION " + "FROM AUTHORS_DETAILS JOIN ABSTRACT_AUTHOR_POSITION_AFFILIATION USING (AUTHOR_UUID) " + "WHERE AUTHORS_DETAILS.AUTHOR_UUID IN " + "(SELECT AUTHOR_UUID FROM ABSTRACT_AUTHOR_POSITION_AFFILIATION WHERE ABSTRACT_UUID = '" + value + "') " + "AND ABSTRACT_AUTHOR_POSITION_AFFILIATION.AUTHOR_POSITION IN " + "(SELECT AUTHOR_POSITION FROM ABSTRACT_AUTHOR_POSITION_AFFILIATION WHERE ABSTRACT_UUID = '" + value + "') " + "ORDER BY AUTHOR_POSITION ASC;"; cursor = DatabaseHelper.database.rawQuery(authorSQLQuery, null); Log.i(gtag, "Auth executed query: rows = " + cursor.getCount()); List<String> abstractAuthorNames = new ArrayList<String>(); if (cursor != null && cursor.moveToFirst()) { do {// w w w .j a v a 2s. c o m Log.i(gtag, "in DO WHILE"); String authEmail = cursor.getString(cursor.getColumnIndexOrThrow("AUTHOR_EMAIL")); Log.i(gtag, "author email => " + authEmail); String authorName = cursor.getString(cursor.getColumnIndexOrThrow("AUTHOR_FIRST_NAME")) + " " + cursor.getString(cursor.getColumnIndexOrThrow("AUTHOR_LAST_NAME")); String authAffiliation = cursor.getString(cursor.getColumnIndexOrThrow("AUTHOR_AFFILIATION")); //remove unwanted characters from affiliation superscript id's String authAffiliationINTs = authAffiliation.replaceAll("[^0-9][,]", ""); //pattern to get the digits so to increment those by one later so affiliation numbering starts from 1 instead of 0 Pattern digitPattern = Pattern.compile("(\\d)"); // EDIT: Increment each digit. Matcher matcher = digitPattern.matcher(authAffiliationINTs); StringBuffer result = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(result, String.valueOf(Integer.parseInt(matcher.group(1)) + 1)); } matcher.appendTail(result); authAffiliation = result.toString(); if (abstractAuthorNames.indexOf(authorName) == -1) { abstractAuthorNames.add(authorName); if (authEmail == null || authEmail.equals("null")) { Log.i(gtag, "in author check - IF NULL"); authorNames.append(Html.fromHtml( "<b>" + authorName + "</b><sup><small>" + authAffiliation + "</small></sup><br/>")); } else { Log.i(gtag, "in author check - ELSE "); //authorNames.append(Html.fromHtml("<b><a href=\"mailto:" + authEmail + "\">" + authorName + "</a>" + "</b><sup><small>" // + authAffiliation + "</small></sup><br/>")); //authorNames.setMovementMethod(LinkMovementMethod.getInstance()); authorNames.append(Html.fromHtml( "<b>" + authorName + "</b><sup><small>" + authAffiliation + "</small></sup><br/>")); } } else { ; } } while (cursor.moveToNext()); } }
From source file:com.krawler.common.util.StringUtil.java
public static String serverHTMLStripperWithoutQuoteReplacement(String stripTags) throws IllegalStateException, IndexOutOfBoundsException { Pattern p = Pattern.compile("<[^>]*>"); Matcher m = p.matcher(stripTags); StringBuffer sb = new StringBuffer(); if (!isNullOrEmpty(stripTags)) { while (m.find()) { m.appendReplacement(sb, ""); }/*from w w w .java2 s. c om*/ m.appendTail(sb); stripTags = sb.toString(); stripTags = stripTags.replaceAll("\r", "<br/>"); stripTags = stripTags.replaceAll("\n", " "); stripTags = stripTags.replaceAll(" ", " "); } return stripTags.trim(); }
From source file:com.google.apigee.edgecallouts.HashcashCallout.java
private String resolvePropertyValue(String spec, MessageContext msgCtxt) { Matcher matcher = variableReferencePattern.matcher(spec); StringBuffer sb = new StringBuffer(); // System.out.printf("resolvePropertyValue spec(%s)\n", spec); while (matcher.find()) { // System.out.printf("resolvePropertyValue matcher: (%s) (%s) (%s)\n", // matcher.group(1), // matcher.group(2), // matcher.group(3)); matcher.appendReplacement(sb, ""); sb.append(matcher.group(1));//from w w w. j a v a 2 s . c o m sb.append((String) msgCtxt.getVariable(matcher.group(2))); sb.append(matcher.group(3)); } matcher.appendTail(sb); //System.out.printf("resolvePropertyValue result: (%s)\n", sb.toString()); return sb.toString(); }
From source file:com.krawler.common.util.StringUtil.java
public static String serverHTMLStripper(String stripTags) throws IllegalStateException, IndexOutOfBoundsException { Pattern p = Pattern.compile("<[^>]*>"); Matcher m = p.matcher(stripTags); StringBuffer sb = new StringBuffer(); if (!isNullOrEmpty(stripTags)) { while (m.find()) { m.appendReplacement(sb, ""); }/*from w w w. j av a2 s .co m*/ m.appendTail(sb); stripTags = sb.toString(); stripTags = stripTags.replaceAll("\r", "<br/>"); stripTags = stripTags.replaceAll("\n", " "); stripTags = stripTags.replaceAll("\'", "'"); stripTags = stripTags.replaceAll("\"", """); stripTags = stripTags.replaceAll(" ", " "); } return stripTags.trim(); }
From source file:org.fao.unredd.portal.ApplicationController.java
private String setLayerTimes() { String jsonLayers = config.getLayers(); Pattern patt = Pattern.compile("\\$\\{time\\.([\\w.]*)\\}"); Matcher m = patt.matcher(jsonLayers); StringBuffer sb = new StringBuffer(jsonLayers.length()); while (m.find()) { // Found time-dependant layer in json file String layerName = m.group(1); try {/*from w w w .ja v a 2 s . c om*/ m.appendReplacement(sb, getLayerTimesFromGeostore(layerName)); } catch (Exception e) { m.appendReplacement(sb, ""); logger.error("Error getting layer times from GeoStore."); } } m.appendTail(sb); return sb.toString(); }
From source file:com.haulmont.cuba.gui.data.impl.AbstractCollectionDatasource.java
protected String getJPQLQuery(Map<String, Object> parameterValues) { String query;//from w ww. ja v a2s . c om if (filter == null) query = this.query; else query = filter.processQuery(this.query, parameterValues); for (ParameterInfo info : queryParameters) { final String paramName = info.getName(); final String jpaParamName = info.getFlatName(); Pattern p = Pattern.compile(paramName.replace("$", "\\$") + "([^\\.]|$)"); // not ending with "." Matcher m = p.matcher(query); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, jpaParamName + "$1"); } m.appendTail(sb); query = sb.toString(); Object value = parameterValues.get(paramName); if (value != null) { parameterValues.put(jpaParamName, value); } } query = query.replace(":" + ParametersHelper.CASE_INSENSITIVE_MARKER, ":"); query = TemplateHelper.processTemplate(query, parameterValues); return query; }