Java Code Examples for org.apache.commons.lang.StringEscapeUtils#escapeJava()

The following examples show how to use org.apache.commons.lang.StringEscapeUtils#escapeJava() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Attribute.java    From xcurator with Apache License 2.0 6 votes vote down vote up
@Override
    public String toString() {
        StringBuilder instanceSb = new StringBuilder();
        instanceSb.append("[");
        if (!instances.isEmpty()) {
            for (String str : instances) {
//                str = str.replace("\"", "\\\"");
                str = StringEscapeUtils.escapeJava(str);
                if (str.length() > 30) {
                    str = str.substring(0, 30) + "...";
                }
                instanceSb.append("\"").append(str).append("\"").append(", ");
            }
            instanceSb.deleteCharAt(instanceSb.length() - 1);
            instanceSb.deleteCharAt(instanceSb.length() - 1);
        }
        instanceSb.append("]");
        return "{"
                + "\"Attribute\": {"
                + "\"rdfUri\":" + "\"" + rdfUri + "\""
                + ", \"xmlTypeUri\":" + "\"" + xmlTypeUri + "\""
                + ", \"instances\":" + instanceSb
                + '}'
                + '}';
    }
 
Example 2
Source File: BingTranslationApi.java    From AndroidStringsOneTabTranslation with Apache License 2.0 6 votes vote down vote up
private static String generateUrl(String accessToken, List<String> querys, SupportedLanguages from, SupportedLanguages to) {
    String[] texts = new String[]{};
    texts = querys.toArray(texts);
    for (int i = 0; i < texts.length; i++) {
        texts[i] = StringEscapeUtils.escapeJava(texts[i]);
    }

    try {
        final String params =
                (accessToken != null ? PARAM_APP_ID + URLEncoder.encode("Bearer " + accessToken, ENCODING) : "")
                        + PARAM_FROM_LANG + URLEncoder.encode(from.getLanguageCode(), ENCODING)
                        + PARAM_TO_LANG + URLEncoder.encode(to.getLanguageCode(), ENCODING)
                        + PARAM_TEXT_ARRAY + URLEncoder.encode(buildStringArrayParam(texts), ENCODING);

        return TRANSLATE_URL + params;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 3
Source File: MethodBlock.java    From Chimera with MIT License 6 votes vote down vote up
void literal(String variable, Token token) {
    builder.append(literal.format(new Object[] {
        variable,
        StringEscapeUtils.escapeJava(token.lexeme),
        parameter(token, Binding.COMMAND, "null"),
        parameter(token, Binding.REQUIREMENT, "REQUIREMENT"),
    }));
    
    var parameters = new Object[2];
    for (var name : token.aliases) {
        parameters[0] = variable;
        parameters[1] = StringEscapeUtils.escapeJava(name);
        
        builder.append(alias.format(parameters));
    }
}
 
Example 4
Source File: TextMarkerJsGenerator.java    From olat with Apache License 2.0 6 votes vote down vote up
public static StringBuilder buildJSArrayString(ArrayList<GlossaryItem> glossaryItemArr) {
    StringBuilder sb = new StringBuilder();
    sb.append("new Array(");
    for (Iterator iterator = glossaryItemArr.iterator(); iterator.hasNext();) {
        GlossaryItem glossaryItem = (GlossaryItem) iterator.next();
        ArrayList<String> allHighlightStrings = glossaryItem.getAllStringsToMarkup();
        sb.append("new Array(\"");
        for (Iterator iterator2 = allHighlightStrings.iterator(); iterator2.hasNext();) {
            String termFlexionSynonym = StringEscapeUtils.escapeJava((String) iterator2.next());
            sb.append(termFlexionSynonym);
            sb.append("\"");
            if (iterator2.hasNext())
                sb.append(",\"");
        }
        sb.append(")");
        if (iterator.hasNext())
            sb.append(",");
    }

    sb.append(");");
    return sb;
}
 
Example 5
Source File: OrderSafeProperties.java    From restcommander with Apache License 2.0 6 votes vote down vote up
@Override
public void load(InputStream inputStream) throws IOException {

    // read all lines from file as utf-8
    List<String> lines = IOUtils.readLines(inputStream, "utf-8");
    IOUtils.closeQuietly(inputStream);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // escape "special-chars" (to utf-16 on the format \\uxxxx) in lines and store as iso-8859-1
    // see info about escaping - http://download.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html - "public void load(InputStream inStream)"
    for (String line : lines) {

        // due to "...by the rule above, single and double quote characters preceded
        // by a backslash still yield single and double quote characters, respectively."
        // we must transform \" => " and \' => ' before escaping to prevent escaping the backslash
        line = line.replaceAll("\\\\\"", "\"").replaceAll("(^|[^\\\\])(\\\\')", "$1'");
        
        String escapedLine = StringEscapeUtils.escapeJava( line ) + "\n";
        // remove escaped backslashes
        escapedLine = escapedLine.replaceAll("\\\\\\\\","\\\\");
        out.write( escapedLine.getBytes("iso-8859-1"));
    }

    // read properties-file with regular java.util.Properties impl
    super.load( new ByteArrayInputStream( out.toByteArray()) );
}
 
Example 6
Source File: JsonMarshallerCustomClassesTest.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
@After
	public void tearDown() throws Exception {
		if (json != null) {
			// So we can see what's going on
//			System.out.println("JSON: " + json);

			// To make it easy to replace expected JSON values in the code when we're sure they're correct
			@SuppressWarnings("unused")
			String javaLiteralForJSONString = '"' + StringEscapeUtils.escapeJava(json) + '"';
//			System.out.println("Java literal:\n" + javaLiteralForJSONString);
		}
		json = null;
		marshaller = null;
	}
 
Example 7
Source File: TestEdge.java    From datawave with Apache License 2.0 5 votes vote down vote up
protected String formatRow(String source) {
    String tempSource = source;
    if (normalizer != null) {
        tempSource = normalizer.normalize(source);
    }
    tempSource = StringEscapeUtils.escapeJava(tempSource);
    return tempSource;
}
 
Example 8
Source File: Graph.java    From tez with Apache License 2.0 5 votes vote down vote up
private static String wrapSafeString(String label) {
  if (label.indexOf(',') >= 0) {
    if (label.length()>14) {
      label = label.replaceAll(",", ",\n");
    }
  }
  label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
  return label;
}
 
Example 9
Source File: JsonMarshallerInbuiltTypesTest.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
@After
	public void tearDown() throws Exception {
		if (json != null) {
			// So we can see what's going on
//			System.out.println("JSON: " + json);

			// To make it easy to replace expected JSON values in the code when we're sure they're correct
			@SuppressWarnings("unused")
			String javaLiteralForJSONString = '"' + StringEscapeUtils.escapeJava(json) + '"';
//			System.out.println("Java literal:\n" + javaLiteralForJSONString);
		}
		json = null;
		marshaller = null;
	}
 
Example 10
Source File: SQLAnalyzer.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public static String escapeDelimiter(String value) {
  try {
    String delimiter = StringEscapeUtils.unescapeJava(value);
    delimiter = new String(new byte[]{Byte.valueOf(delimiter).byteValue()});
    return StringEscapeUtils.escapeJava(delimiter);
  } catch (NumberFormatException e) {
  }
  return value;
}
 
Example 11
Source File: Graph.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static String wrapSafeString(String label) {
  if (label.indexOf(',') >= 0) {
    if (label.length()>14) {
      label = label.replaceAll(",", ",\n");
    }
  }
  label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
  return label;
}
 
Example 12
Source File: Graph.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
private static String wrapSafeString(String label) {
  if (label.indexOf(',') >= 0) {
    if (label.length()>14) {
      label = label.replaceAll(",", ",\n");
    }
  }
  label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
  return label;
}
 
Example 13
Source File: Graph.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static String wrapSafeString(String label) {
  if (label.indexOf(',') >= 0) {
    if (label.length()>14) {
      label = label.replaceAll(",", ",\n");
    }
  }
  label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
  return label;
}
 
Example 14
Source File: FormData.java    From candybean with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String toString() {
	return "{\"header\":\""+StringEscapeUtils.escapeJava(header)+"\"" + ",\"formFields\":"+JSON.DEFAULT.toJSON(formFields)+
			"}";
}
 
Example 15
Source File: Neo4JOutput.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 4 votes vote down vote up
public String escapeProp( String str ) {
  return StringEscapeUtils.escapeJava( str );
}
 
Example 16
Source File: CStringLiteral.java    From SJS with Apache License 2.0 4 votes vote down vote up
@Override
public String toSource(int x) { return "L\""+StringEscapeUtils.escapeJava(val)+'"'; }
 
Example 17
Source File: FormFieldData.java    From candybean with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String toString() {
	return "{\"comments\":\""+StringEscapeUtils.escapeJava(fieldComments)+"\"" + ",\"value\":\""+StringEscapeUtils.escapeJava(fieldValue)+"\"" +
			"}";
}
 
Example 18
Source File: TextUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Escapes the toString() representation of {@code obj} for use in a literal string.
 * This is useful for interpolating variables into script strings, as well as in other situations.
 */
public static String escapeString(Object obj) {
    return obj == null ? null : StringEscapeUtils.escapeJava(obj.toString());
}
 
Example 19
Source File: oConvertUtils.java    From jeecg with Apache License 2.0 2 votes vote down vote up
/**
 * 转义成Unicode编码
 * @param s
 * @return
 */
public static String escapeJava(Object s) {
	return StringEscapeUtils.escapeJava(getString(s));
}
 
Example 20
Source File: TextUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Escapes the toString() representation of {@code obj} for use in a literal string.
 * This is useful for interpolating variables into script strings, as well as in other situations.
 */
public static String escapeString(Object obj) {
    return obj == null ? null : StringEscapeUtils.escapeJava(obj.toString());
}