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

The following are Jave code examples for showing how to use escapeJava() of the org.apache.commons.lang.StringEscapeUtils 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: alfresco-repository   File: TaggingServiceImpl.java   View Source Code Vote up 6 votes
/**
 * Gets the node reference for a given tag.
 * <p>
 * Returns null if tag is not present and not created.
 * 
 * @param storeRef      store reference
 * @param tag           tag
 * @param create        create a node if one doesn't exist?
 * @return NodeRef      tag node reference or null not exist
 */
private NodeRef getTagNodeRef(StoreRef storeRef, String tag, boolean create)
{
    for (String forbiddenSequence : FORBIDDEN_TAGS_SEQUENCES)
    {
        if (create && tag.contains(forbiddenSequence))
        {
            throw new IllegalArgumentException("Tag name must not contain " + StringEscapeUtils.escapeJava(forbiddenSequence) + " char sequence");
        }
    }
    
    NodeRef tagNodeRef = null;
    Collection<ChildAssociationRef> results = this.categoryService.getRootCategories(storeRef, ContentModel.ASPECT_TAGGABLE, tag, create);
    if (!results.isEmpty())
    {
        tagNodeRef = results.iterator().next().getChildRef();
    }
    return tagNodeRef;
}
 
Example 2
Project: ProjectAres   File: TextInspector.java   View Source Code Vote up 6 votes
@Override
public String scalar(Object value, Inspection options) {
    if(options.quote()) {
        if(value instanceof Character) {
            final char c = (char) value;
            switch(c) {
                case '\'': return "'\\''";
                case '"': return "'\"'";
                default: return "'" + StringEscapeUtils.escapeJava(String.valueOf(c)) + "'";
            }
        } else if(value instanceof String) {
            return "\"" + StringEscapeUtils.escapeJava((String) value) + "\"";
        }
    }

    if(value instanceof Class) {
        // Short class names are usually enough
        return ((Class) value).getSimpleName();
    }

    // everything else
    return String.valueOf(value);
}
 
Example 3
Project: scanning   File: ActivemqConnectorServiceJsonMarshallingTest.java   View Source Code Vote up 5 votes
@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;
		ActivemqConnectorService.setJsonMarshaller(null);
	}
 
Example 4
Project: hadoop   File: Graph.java   View Source Code Vote up 5 votes
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 5
Project: Equella   File: ExtendedPropertiesLayout.java   View Source Code Vote up 4 votes
@SuppressWarnings("nls")
private String escapeValue(Object value)
{
	String escapedValue = StringEscapeUtils.escapeJava(String.valueOf(value));
	return StringUtils.replace(escapedValue, "\\/", "/");
}
 
Example 6
Project: Equella   File: ExtendedPropertiesLayout.java   View Source Code Vote up 4 votes
@SuppressWarnings("nls")
private String escapeValue(Object value)
{
	String escapedValue = StringEscapeUtils.escapeJava(String.valueOf(value));
	return StringUtils.replace(escapedValue, "\\/", "/");
}
 
Example 7
Project: Reer   File: TextUtil.java   View Source Code Vote up 2 votes
/**
 * 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());
}