Java Code Examples for org.apache.commons.lang3.StringUtils.replace()

The following are Jave code examples for showing how to use replace() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: gitplex-mit   File: TestFormBehavior.java   View Source Code Vote up 6 votes
@Override
protected void respond(AjaxRequestTarget target) {
	String feedbackHtml;
	TestResult result = test();
	if (result.isSuccessful()) {
		feedbackHtml = String.format(
				"<div class='test-feedback alert alert-success'>%s</div>", 
				HtmlEscape.escapeHtml5(result.getMessage()));					
	} else {
		feedbackHtml = String.format(
				"<div class='test-feedback alert alert-danger'>%s</div>", 
				HtmlEscape.escapeHtml5(result.getMessage()));					
	} 
	feedbackHtml = StringUtils.replace(feedbackHtml, "\n", "<br>");
	target.appendJavaScript(String.format("var $button = $('#%s');"
			+ "$button.removeAttr('disabled');"
			+ "$button.val($button[0].prevValue);"
			+ "$button.html($button[0].prevHtml);"
			+ "$button.closest('form').append('%s');"
			+ "$button.removeClass('ajax-indicator');", 
			getComponent().getMarkupId(), JavaScriptEscape.escapeJavaScript(feedbackHtml)));
}
 
Example 2
Project: Quora-Marketing   File: QuoraCrawler.java   View Source Code Vote up 6 votes
private void scrapLinksForSearchJSoup(String keyWord, int cityId) {
	// log("crawling for keyword : " + keyWord + " and city: " +cityId);
	String url = QuoraConstants.getUrl(keyWord, cityId);
	Document doc = getDocument(url);

	Elements els = doc.select("div.g");

	for (Element el : els) {
		String quoraUrl = el.getElementsByTag("cite").text();
		quoraUrl = StringUtils.replace(quoraUrl, " ", "");
		if (!StringUtils.startsWith(quoraUrl, "http")) {
			quoraUrl = "http://" + quoraUrl;
		}
		if (!uniqueQuoraLinks.contains(quoraUrl)) {
			crawlQuoraPage(quoraUrl, true);
		}
	}
}
 
Example 3
Project: Java-Data-Science-Made-Easy   File: App.java   View Source Code Vote up 6 votes
public static String findReplaceApacheCommons(String text, String toFind, String replaceWith){
	out.println(text);
	text = StringUtils.replacePattern(text, "\\W\\s", " ");
	out.println(text);
	//out.println(StringUtils.replace(text, " me ", "X"));
	return StringUtils.replace(text, " me ", "X");
}
 
Example 4
Project: Java-for-Data-Science   File: App.java   View Source Code Vote up 5 votes
public static String findReplaceApacheCommons(String text, String toFind, String replaceWith){
	out.println(text);
	text = StringUtils.replacePattern(text, "\\W\\s", " ");
	out.println(text);
	//out.println(StringUtils.replace(text, " me ", "X"));
	return StringUtils.replace(text, " me ", "X");
}
 
Example 5
Project: circe-be   File: ConceptSetExpressionQueryBuilder.java   View Source Code Vote up 5 votes
private String buildConceptSetMappedQuery (
        ArrayList<Concept> mappedConcepts,
        ArrayList<Concept> mappedDescendantConcepts
) {
  String conceptSetQuery = buildConceptSetSubQuery(mappedConcepts, mappedDescendantConcepts);
  return StringUtils.replace(CONCEPT_SET_MAPPED_TEMPLATE, "@conceptsetQuery", conceptSetQuery);
}
 
Example 6
Project: gitplex-mit   File: MarkdownEditor.java   View Source Code Vote up 5 votes
private String render(String markdown) {
	if (StringUtils.isNotBlank(markdown)) {
		MarkdownManager markdownManager = GitPlex.getInstance(MarkdownManager.class);
		
		// Normalize line breaks to make source position tracking information comparable 
		// to textarea caret position when sync edit/preview scroll bar
		markdown = StringUtils.replace(markdown, "\r\n", "\n");
		return markdownManager.render(markdown, getBaseUrl(), true);
	} else {
		return "<div class='message'>Nothing to preview</div>";
	}
}
 
Example 7
Project: atlas   File: DexDiffer.java   View Source Code Vote up 5 votes
/**
 * get dalvik className
 *
 * @param className
 * @return
 */
public static String getDalvikClassName(String className) {
    if (className.charAt(0) != 'L' || className.charAt(className.length() - 1) != ';') {
        throw new RuntimeException("Not a valid dalvik class name");
    }
    return StringUtils.replace(className.substring(1, className.length() - 1), "/", ".");
}
 
Example 8
Project: circe-be   File: CohortExpressionQueryBuilder.java   View Source Code Vote up 5 votes
private String wrapCriteriaQuery(String query, CriteriaGroup group)
{
  String eventQuery = StringUtils.replace(EVENT_TABLE_EXPRESSION_TEMPLATE, "@eventQuery", query);
  String groupQuery = this.getCriteriaGroupQuery(group, String.format("(%s)", eventQuery));
  groupQuery = StringUtils.replace(groupQuery,"@indexId", "" + 0);
  String wrappedQuery = String.format(
      "select PE.person_id, PE.event_id, PE.start_date, PE.end_date, PE.target_concept_id, PE.visit_occurrence_id FROM (\n%s\n) PE\nJOIN (\n%s) AC on AC.person_id = pe.person_id and AC.event_id = pe.event_id\n",
      query, groupQuery);
  return wrappedQuery;
}
 
Example 9
Project: circe-be   File: CohortExpressionQueryBuilder.java   View Source Code Vote up 4 votes
public String getCriteriaGroupQuery(CriteriaGroup group, String eventTable) {
  String query = GROUP_QUERY_TEMPLATE;
  ArrayList<String> additionalCriteriaQueries = new ArrayList<>();
  
  int indexId = 0;
  for(CorelatedCriteria cc : group.criteriaList)
  {
    String acQuery = this.getCorelatedlCriteriaQuery(cc, eventTable); //ac.accept(this);
    acQuery = StringUtils.replace(acQuery, "@indexId", "" + indexId);
    additionalCriteriaQueries.add(acQuery);
    indexId++;
  }
  
  for(DemographicCriteria dc : group.demographicCriteriaList)
  {
    String dcQuery = this.getDemographicCriteriaQuery(dc, eventTable); //ac.accept(this);
    dcQuery = StringUtils.replace(dcQuery, "@indexId", "" + indexId);
    additionalCriteriaQueries.add(dcQuery);
    indexId++;
  } 
  
  for(CriteriaGroup g : group.groups)
  {
    String gQuery = this.getCriteriaGroupQuery(g, eventTable); //g.accept(this);
    gQuery = StringUtils.replace(gQuery, "@indexId", "" + indexId);
    additionalCriteriaQueries.add(gQuery);  
    indexId++;
  }
  
  if (indexId > 0) // this group is not empty
  {
    query = StringUtils.replace(query, "@criteriaQueries", StringUtils.join(additionalCriteriaQueries, "\nUNION ALL\n"));
    
    String occurrenceCountClause = "HAVING COUNT(index_id) ";
    if (group.type.equalsIgnoreCase("ALL")) // count must match number of criteria + sub-groups in group.
      occurrenceCountClause += "= " + indexId;

    if (group.type.equalsIgnoreCase("ANY")) // count must be > 0 for an 'ANY' criteria
      occurrenceCountClause += "> 0"; 

    if (group.type.toUpperCase().startsWith("AT_"))
    {
      if (group.type.toUpperCase().endsWith("LEAST"))
        occurrenceCountClause += ">= " + group.count;
      else
        occurrenceCountClause += "<= " + group.count;
    }
    query = StringUtils.replace(query, "@occurrenceCountClause", occurrenceCountClause);
  }
  else // query group is empty so replace queries and occurence count clause with a friendly default
  {
    query = StringUtils.replace(query, "@criteriaQueries", "select ET.person_id, ET.event_id from @eventTable ET");
    query = StringUtils.replace(query, "@occurrenceCountClause", "");
  }

  query = StringUtils.replace(query, "@eventTable", eventTable);
  
  return query;    
}
 
Example 10
Project: circe-be   File: CohortExpressionQueryBuilder.java   View Source Code Vote up 4 votes
@Override
public String getCriteriaSql(ConditionEra criteria)
{
  String query = CONDITION_ERA_TEMPLATE;
  
  String codesetClause = "";
  if (criteria.codesetId != null)
  {
    codesetClause = String.format("where ce.condition_concept_id in (SELECT concept_id from  #Codesets where codeset_id = %d)", criteria.codesetId);
  }
  query = StringUtils.replace(query, "@codesetClause",codesetClause);
  
  ArrayList<String> joinClauses = new ArrayList<>();
  
  if (criteria.ageAtStart != null || criteria.ageAtEnd != null || (criteria.gender != null && criteria.gender.length > 0)) // join to PERSON
    joinClauses.add("JOIN @cdm_database_schema.PERSON P on C.person_id = P.person_id");

  query = StringUtils.replace(query,"@joinClause", StringUtils.join(joinClauses,"\n"));
  
  ArrayList<String> whereClauses = new ArrayList<>();
  
  // first
  if (criteria.first != null && criteria.first == true)
    whereClauses.add("C.ordinal = 1");

  // eraStartDate
  if (criteria.eraStartDate != null)
  {
    whereClauses.add(buildDateRangeClause("C.condition_era_start_date",criteria.eraStartDate));
  }

  // eraEndDate
  if (criteria.eraEndDate != null)
  {
    whereClauses.add(buildDateRangeClause("C.condition_era_end_date",criteria.eraEndDate));
  }
  
  // occurrenceCount
  if (criteria.occurrenceCount != null)
  {
    whereClauses.add(buildNumericRangeClause("C.condition_occurrence_count", criteria.occurrenceCount));
  }      

  // eraLength
  if (criteria.eraLength != null)
  {
    whereClauses.add(buildNumericRangeClause("DATEDIFF(d,C.condition_era_start_date, C.condition_era_end_date)", criteria.eraLength));
  }      

  // ageAtStart
  if (criteria.ageAtStart != null)
  {
    whereClauses.add(buildNumericRangeClause("YEAR(C.condition_era_start_date) - P.year_of_birth", criteria.ageAtStart));
  }

  // ageAtEnd
  if (criteria.ageAtEnd != null)
  {
    whereClauses.add(buildNumericRangeClause("YEAR(C.condition_era_end_date) - P.year_of_birth", criteria.ageAtEnd));
  }

  // gender
  if (criteria.gender != null && criteria.gender.length > 0)
  {
    whereClauses.add(String.format("P.gender_concept_id in (%s)", StringUtils.join(getConceptIdsFromConcepts(criteria.gender),",")));
  }
  
  String whereClause = "";
  if (whereClauses.size() > 0)
    whereClause = "WHERE " + StringUtils.join(whereClauses, "\nAND ");
  query = StringUtils.replace(query, "@whereClause",whereClause);
  
  if (criteria.CorrelatedCriteria != null)
  {
    query = wrapCriteriaQuery(query, criteria.CorrelatedCriteria);
  }
  
  return query;
}
 
Example 11
Project: HL7Receiver   File: ResourceMapParameters.java   View Source Code Vote up 4 votes
private String unescapeString(String string) {
    string = StringUtils.replace(string, equalsSeperatorEscape, equalsSeperator);
    string = StringUtils.replace(string, keyValuePairSeperatorEscape, keyValuePairSeperator);
    string = StringUtils.replace(string, repeatingValueSeperatorEscape, repeatingValueSeperator);
    return string;
}
 
Example 12
Project: dremio-oss   File: RelJsonWriter.java   View Source Code Vote up 4 votes
/** Escape the backslash for string output */
private static String escapeSpecialChars(final String input) {
  return StringUtils.replace(input, "\\", "\\\\");
}
 
Example 13
Project: memory-graph   File: SimpleNameSubstitutionStrategy.java   View Source Code Vote up 4 votes
public String deflate(String value) {
    return StringUtils.replace(value, pattern, replacement);
}
 
Example 14
Project: circe-be   File: CohortExpressionQueryBuilder.java   View Source Code Vote up 4 votes
public String getCorelatedlCriteriaQuery(CorelatedCriteria corelatedCriteria, String eventTable)
 {
   String query = ADDITIONAL_CRITERIA_TEMMPLATE;
   
   String criteriaQuery = corelatedCriteria.criteria.accept(this);
   query = StringUtils.replace(query,"@criteriaQuery",criteriaQuery);
   query = StringUtils.replace(query,"@eventTable",eventTable);
   
   // build index date window expression
   String startExpression;
   String endExpression;
   ArrayList<String> clauses = new ArrayList<>();
   clauses.add("A.START_DATE >= P.OP_START_DATE AND A.START_DATE <= P.OP_END_DATE");
   
   // StartWindow
   Window startWindow = corelatedCriteria.startWindow;
   if (startWindow.start.days != null)
     startExpression = String.format("DATEADD(day,%d,P.START_DATE)", startWindow.start.coeff * startWindow.start.days);
   else
     startExpression = startWindow.start.coeff == -1 ? "P.OP_START_DATE" : "P.OP_END_DATE";

   if (startWindow.end.days != null)
     endExpression = String.format("DATEADD(day,%d,P.START_DATE)", startWindow.end.coeff * startWindow.end.days);
   else
     endExpression = startWindow.end.coeff == -1 ? "P.OP_START_DATE" : "P.OP_END_DATE";
   
   clauses.add(String.format("A.START_DATE >= %s and A.START_DATE <= %s", startExpression, endExpression));
   
   // EndWindow
   Window endWindow = corelatedCriteria.endWindow;

   if (endWindow != null)
   {
     if (endWindow.start.days != null)
         startExpression = String.format("DATEADD(day,%d,P.START_DATE)", endWindow.start.coeff * endWindow.start.days);
     else
       startExpression = endWindow.start.coeff == -1 ? "P.OP_START_DATE" : "P.OP_END_DATE";

     if (endWindow.end.days != null)
         endExpression = String.format("DATEADD(day,%d,P.START_DATE)", endWindow.end.coeff * endWindow.end.days);
     else
       endExpression = endWindow.end.coeff == -1 ? "P.OP_START_DATE" : "P.OP_END_DATE";

     clauses.add(String.format("A.END_DATE >= %s AND A.END_DATE <= %s", startExpression, endExpression));    
   }

// RestrictVisit
	boolean restrictVisit = corelatedCriteria.restrictVisit;
	if (restrictVisit) {
		clauses.add("A.visit_occurrence_id = P.visit_occurrence_id");
	}
	
   query = StringUtils.replace(query,"@windowCriteria",StringUtils.join(clauses, " AND "));

   // Occurrence criteria
   String occurrenceCriteria = String.format(
     "HAVING COUNT(%sA.TARGET_CONCEPT_ID) %s %d",
     corelatedCriteria.occurrence.isDistinct ? "DISTINCT " : "",
     getOccurrenceOperator(corelatedCriteria.occurrence.type), 
     corelatedCriteria.occurrence.count
   );
   
   query = StringUtils.replace(query, "@occurrenceCriteria", occurrenceCriteria);

   return query;
 }
 
Example 15
Project: datax   File: Configuration.java   View Source Code Vote up 4 votes
private String split(final String path) {
	return StringUtils.replace(path, "[", ".[");
}
 
Example 16
Project: util   File: URLResourceUtil.java   View Source Code Vote up 4 votes
public static URI toURI(String location) throws URISyntaxException {
	return new URI(StringUtils.replace(location, " ", "%20"));
}
 
Example 17
Project: circe-be   File: ConceptSetExpressionQueryBuilder.java   View Source Code Vote up 4 votes
public String buildExpressionQuery(ConceptSetExpression expression)
{
  // handle included concepts.
  ArrayList<Concept> includeConcepts = new ArrayList<>();
  ArrayList<Concept> includeDescendantConcepts = new ArrayList<>();
  ArrayList<Concept> includeMappedConcepts = new ArrayList<>();
  ArrayList<Concept> includeMappedDescendantConcepts = new ArrayList<>();
 
  ArrayList<Concept> excludeConcepts = new ArrayList<>();
  ArrayList<Concept> excludeDescendantConcepts = new ArrayList<>();
  ArrayList<Concept> excludeMappedConcepts = new ArrayList<>();
  ArrayList<Concept> excludeMappedDescendantConcepts = new ArrayList<>();
  
  // populate each sub-set of cocnepts from the flags set in each concept set item
  for (ConceptSetExpression.ConceptSetItem item : expression.items)
  {
    if (!item.isExcluded)
    {
      includeConcepts.add(item.concept);

      if (item.includeDescendants)
        includeDescendantConcepts.add(item.concept);

      if (item.includeMapped)
      {
        includeMappedConcepts.add(item.concept);
        if (item.includeDescendants)
          includeMappedDescendantConcepts.add(item.concept);
      }
    } else {
      excludeConcepts.add(item.concept);
      if (item.includeDescendants)
        excludeDescendantConcepts.add(item.concept);
      if (item.includeMapped)
      {
        excludeMappedConcepts.add(item.concept);
        if (item.includeDescendants)
          excludeMappedDescendantConcepts.add(item.concept);
      }
    }
  }
  
  // each ArrayList contains the concepts that are used in the sub-query of the codeset expression query
  
  String conceptSetQuery = StringUtils.replace(CONCEPT_SET_INCLUDE_TEMPLATE,"@includeQuery", buildConceptSetQuery(includeConcepts, includeDescendantConcepts, includeMappedConcepts, includeMappedDescendantConcepts));
  
  if (excludeConcepts.size() > 0){
    String excludeConceptsQuery = StringUtils.replace(CONCEPT_SET_EXCLUDE_TEMPLATE, "@excludeQuery", buildConceptSetQuery(excludeConcepts, excludeDescendantConcepts, excludeMappedConcepts, excludeMappedDescendantConcepts));
    conceptSetQuery += excludeConceptsQuery;
  }
  
  return conceptSetQuery;
}
 
Example 18
Project: Yidu   File: ChapterDTO.java   View Source Code Vote up 4 votes
public String getEsccapeContent() {
    String escapeContent = StringUtils.replace(this.getContent(), "<", "&lt;");
    escapeContent = StringUtils.replace(escapeContent, ">", "&gt;");
    return escapeContent;
}
 
Example 19
Project: bluegreen-manager   File: StringSubstituterBaseImpl.java   View Source Code Vote up 2 votes
/**
 * Performs a key/value substitution on the template, returning the result.
 * <p/>
 * Substitutes the actual value for regular variable expressions, and substitutes a bleep for expurgated variable
 * expressions.
 * <p/>
 * Template exits unchanged if the key is not found.
 */
private String expurgate(String template, String key, String value)
{
  String substituted = StringUtils.replace(template, OPEN_SUBSTITUTE + key + CLOSE_SUBSTITUTE, value);
  return StringUtils.replace(substituted, OPEN_EXPURGATE + key + CLOSE_EXPURGATE, BLEEP);
}
 
Example 20
Project: mylion-mvn   File: GeneratorModel.java   View Source Code Vote up 2 votes
public String getFolder() {
	String replace = StringUtils.replace(targetPackage, ".", File.separator);
	
	
	return replace ;
}