Java Code Examples for org.apache.commons.lang3.StringEscapeUtils#unescapeJava()

The following examples show how to use org.apache.commons.lang3.StringEscapeUtils#unescapeJava() . 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: ClassifiedTweet.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param isPrettyPrinting turn PrettyPrinting on/off
 * @return serialized JSON string
 */
public String toJsonString(boolean isPrettyPrinting) {
	Gson jsonObject = null;
	
	if (isPrettyPrinting) {
	jsonObject = new GsonBuilder().serializeNulls().disableHtmlEscaping()
			.serializeSpecialFloatingPointValues().setPrettyPrinting()
			.create();
	} else {
		jsonObject = new GsonBuilder().serializeNulls().disableHtmlEscaping()
				.serializeSpecialFloatingPointValues()
				.create();
	}
	
	try {
		String jsonString = jsonObject.toJson(this, ClassifiedTweet.class);
		jsonString = jsonString.replace("\\\\u", "\\u");
		return StringEscapeUtils.unescapeJava(jsonString);
	} catch (Exception e) {
		logger.error("Error while parsing jsonObject to json string", e);
		return null;
	}
}
 
Example 2
Source File: TitledPage.java    From OpenModsLib with MIT License 6 votes vote down vote up
public TitledPage(String title, String content) {
	{
		final String translatedTitle = TranslationUtils.translateToLocal(title);
		final GuiComponentLabel titleLabel = new GuiComponentLabel(0, 0, translatedTitle).setScale(BookScaleConfig.getPageTitleScale());
		addComponent(new GuiComponentHCenter(0, 12, getWidth()).addComponent(titleLabel));
	}

	{
		final String translatedContent = StringEscapeUtils.unescapeJava(TranslationUtils.translateToLocal(content));
		final GuiComponentLabel lblContent = new GuiComponentLabel(0, 0, getWidth() - 20, 300, translatedContent);

		lblContent.setScale(BookScaleConfig.getPageContentScale());
		lblContent.setAdditionalLineHeight(BookScaleConfig.getTitlePageSeparator());

		addComponent(new GuiComponentHCenter(0, 35, getWidth()).addComponent(lblContent));
	}
}
 
Example 3
Source File: DLQMessageProcessor.java    From oneops with Apache License 2.0 6 votes vote down vote up
private String convertMessage(String message, Map<String, String> headers) {
    String newMessage = message;
    JsonElement msgRootElement = parser.parse(message);
    if (msgRootElement instanceof JsonObject) {
        JsonObject msgRoot = (JsonObject)msgRootElement;

        JsonElement element = msgRoot.get(PAYLOAD_ELEMENT_KEY);
        if (element != null) {
            if (!element.isJsonObject()) {
                //convert payLoad to a json object if it is not already
                msgRoot.remove(PAYLOAD_ELEMENT_KEY);
                String realPayload = element.getAsString();
                String escapedPayload = StringEscapeUtils.unescapeJava(realPayload);
                msgRoot.add(PAYLOAD_ELEMENT_KEY, parser.parse(escapedPayload));
            }
        }
        JsonElement hdrElement = GSON.toJsonTree(headers);
        msgRoot.add("msgHeaders", hdrElement);
        newMessage = GSON.toJson(msgRoot);
        if (logger.isDebugEnabled()) {
            logger.debug("message to be indexed " + newMessage);
        }
    }
    return newMessage;
}
 
Example 4
Source File: CliUtils.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Strips leading and trailing "'" characters, and handles
 * and escaped characters such as \n, \r, etc.
 * @param b - string to unescape
 * @return String - unexspaced string
 */
public static String unescapeSQLString(String b)
{
    if (b.charAt(0) == '\'' && b.charAt(b.length()-1) == '\'')
        b = b.substring(1, b.length()-1);
    return StringEscapeUtils.unescapeJava(b);
}
 
Example 5
Source File: HiveDDLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public SqlNode visit(SqlLiteral literal) {
	if (literal instanceof SqlCharStringLiteral) {
		SqlCharStringLiteral stringLiteral = (SqlCharStringLiteral) literal;
		String unescaped = StringEscapeUtils.unescapeJava(stringLiteral.getNlsString().getValue());
		return SqlLiteral.createCharString(unescaped, stringLiteral.getParserPosition());
	}
	return literal;
}
 
Example 6
Source File: CSVUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
    // Allows special, escaped characters as input, which is then un-escaped and converted to a single character.
    // Examples for special characters: \t (or \u0009), \f.
    if (input.length() > 1) {
        input = StringEscapeUtils.unescapeJava(input);
    }
    return new ValidationResult.Builder().subject(subject).input(input)
            .explanation("Only non-null single characters are supported")
            .valid(input.length() == 1 && input.charAt(0) != 0).build();
}
 
Example 7
Source File: PhoenixRuntime.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static char getCharacter(String s) {
    String unescaped = StringEscapeUtils.unescapeJava(s);
    if (unescaped.length() > 1) {
        throw new IllegalArgumentException("Invalid single character: '" + unescaped + "'");
    }
    return unescaped.charAt(0);
}
 
Example 8
Source File: WebTablesStringNormalizer.java    From winter with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param columnName
 * @return the normalised string
 */
public static String normaliseHeader(String columnName) {
	if(columnName==null)
	{
		return "";
	} else {
		columnName = StringEscapeUtils.unescapeJava(columnName);
		columnName = columnName.replace("\"", "");
		columnName = columnName.replace("|", " ");
		columnName = columnName.replace(",", "");
		columnName = columnName.replace("{", "");
		columnName = columnName.replace("}", "");
		columnName = columnName.replaceAll("\n", "");

		columnName = columnName.replace("&nbsp;", " ");
		columnName = columnName.replace("&nbsp", " ");
		columnName = columnName.replace("nbsp", " ");
		columnName = columnName.replaceAll("<.*>", "");

		columnName = columnName.toLowerCase();
		columnName = columnName.trim();

		columnName = columnName.replaceAll("\\.", "");
		columnName = columnName.replaceAll("\\$", "");
		// clean the values from additional strings
		// if (columnName.contains("/")) {
		// 	columnName = columnName.substring(0, columnName.indexOf("/"));
		// }

		// if (columnName.contains("\\")) {
		// 	columnName = columnName.substring(0, columnName.indexOf("\\"));
		// }
		if (possibleNullValues.contains(columnName)) {
			columnName = nullValue;
		}
		
		return columnName;
	}
}
 
Example 9
Source File: SearchResult.java    From Yui with Apache License 2.0 5 votes vote down vote up
private static String cleanString(String uncleanString)
{
    return StringEscapeUtils.unescapeJava(
            StringEscapeUtils.unescapeHtml4(
                    uncleanString
                            .replaceAll("\\s+", " ")
                            .replaceAll("\\<.*?>", "")
                            .replaceAll("\"", "")));
}
 
Example 10
Source File: CssSyntaxTag.java    From TranskribusCore with GNU General Public License v3.0 4 votes vote down vote up
public static String unescapeCss(String str) {
		// FIXME is this really sufficient??
		return StringEscapeUtils.unescapeJava(str);
		
//		return StringEscapeUtils.unescapeXml(str);
	}
 
Example 11
Source File: Functions.java    From MLib with GNU General Public License v3.0 4 votes vote down vote up
private static void unescapeThema(DatenFilm film) {
    // Thema
    film.arr[DatenFilm.FILM_THEMA] = StringEscapeUtils.unescapeXml(film.arr[DatenFilm.FILM_THEMA]);
    film.arr[DatenFilm.FILM_THEMA] = StringEscapeUtils.unescapeHtml4(film.arr[DatenFilm.FILM_THEMA]);
    film.arr[DatenFilm.FILM_THEMA] = StringEscapeUtils.unescapeJava(film.arr[DatenFilm.FILM_THEMA]);
}
 
Example 12
Source File: Functions.java    From MLib with GNU General Public License v3.0 4 votes vote down vote up
private static void unescapeTitel(DatenFilm film) {
    // Titel
    film.arr[DatenFilm.FILM_TITEL] = StringEscapeUtils.unescapeXml(film.arr[DatenFilm.FILM_TITEL]);
    film.arr[DatenFilm.FILM_TITEL] = StringEscapeUtils.unescapeHtml4(film.arr[DatenFilm.FILM_TITEL]);
    film.arr[DatenFilm.FILM_TITEL] = StringEscapeUtils.unescapeJava(film.arr[DatenFilm.FILM_TITEL]);
}
 
Example 13
Source File: DelimiterClause.java    From macrobase with Apache License 2.0 4 votes vote down vote up
private DelimiterClause(Optional<NodeLocation> location, String delimiter) {
    super(location);
    requireNonNull(delimiter, "delimiter is null");
    this.delimiter = StringEscapeUtils.unescapeJava(delimiter);
}
 
Example 14
Source File: DSV.java    From validatar with Apache License 2.0 4 votes vote down vote up
private static byte[] getBytes(String string) {
    String unescaped = StringEscapeUtils.unescapeJava(string);
    return unescaped.getBytes(StandardCharsets.UTF_8);
}
 
Example 15
Source File: InferAvroSchema.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private static String unescapeString(String input) {
    if (input.length() > 1) {
        input = StringEscapeUtils.unescapeJava(input);
    }
    return input;
}
 
Example 16
Source File: JavaCXFExtServerCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
private String patternFor(CodegenVariable var) {
    String pattern = null;
    if (var != null) {
        if (var.pattern != null) {
            pattern = StringEscapeUtils.unescapeJava(var.pattern);
        } else if (var.dataFormat != null) {
            // According to JSON Schema (https://tools.ietf.org/html/draft-fge-json-schema-validation-00),
            // string-type values can be constrained by a format, one of: {date-time, email, hostname, ipv4, ipv6,
            // uri}. Custom formats are allowed. The OpenAPI Specification also mentions binary, byte, date,
            // password, uuid.
            switch (var.dataFormat) {
                case "binary":
                    // Any sequence of octets.
                    pattern = "[0-9A-F]{2}{4,24}";
                    break;
                case "byte":
                    // Base64 encoded bytes: 4 characters represent 3 bytes.
                    pattern = "[A-Za-z0-9+/]{4}{4,24}";
                    break;
                case "date":
                    // ISO-8601: YYYY-MM-DD
                    pattern = "20\\d{2}-(?:" // YY- (20yy)
                            + "(?:01|03|05|07|08|10|12)-(?:0[1-9]|[1-2][0-9]|3[0-1])|" // MM-DD (31 days)
                            + "(?:04|06|09|11)-(?:0[1-9]|[1-2][0-9]|30)|" // MM-DD (30 days)
                            + "02-(?:0[1-9]|1[0-9]|2[0-8]))"; // MM-DD (28 days)
                    break;
                case "date-time":
                    // ISO-8601: YYYY-MM-DDTHH:mm:ss(Z|+-HH:mm) NOTE: the time zone offset is mandatory.
                    pattern = "20\\d{2}-(?:" // YYYY-
                            + "(?:01|03|05|07|08|10|12)-(?:0[1-9]|[1-2][0-9]|3[0-1])|" // MM-DD (31 days)
                            + "(?:04|06|09|11)-(?:0[1-9]|[1-2][0-9]|30)|" // MM-DD (30 days)
                            + "02-(?:0[1-9]|1[0-9]|2[0-8]))" // MM-DD (28 days)
                            + "T(?:[0-1][0-9]|2[0-3])" // THH
                            + ":[0-5][0-9]" // :mm
                            + ":[0-5][0-9]" // :ss
                            + "(?:Z|(?:-0[1-9]|-1[0-2]|\\+0[0-9]|\\+1[0-4]):(?:00|30|45))"; // timezone
                    break;
                case "email":
                    pattern = "[a-z][a-z0-9_.-]{1,8}@[a-z][a-z0-9-.]{2,12}\\.[a-z]{2,4}"; // (simplistic but
                    // sufficient)
                    break;
                case "hostname":
                    pattern = "[a-z][a-z0-9-.]{2,12}\\.[a-z]{2,4}"; // (simplistic but sufficient)
                    break;
                case "ipv4":
                    pattern = "(?:(?:25[0-5]|2[0-4][0-9]|[1-9][0-9]|[0-9])\\.){3}"
                            + "(?:25[0-5]|2[0-4][0-9]|[1-9][0-9]|[0-9])";
                    break;
                case "ipv6":
                    // Simplified (!) from
                    // https://community.helpsystems.com/forums/intermapper/miscellaneous-topics/5acc4fcf-fa83-e511-80cf-0050568460e4
                    pattern = "(?:(?:[0-9A-F]{1,4}:){7}(?:[0-9A-F]{1,4}|:))|"
                            + "(?:(?:[0-9A-F]{1,4}:){6}(?::[0-9A-F]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|"
                            + "(?:(?:[0-9A-F]{1,4}:){5}(?:(?:(?::[0-9A-F]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|"
                            + "(?:(?:[0-9A-F]{1,4}:){4}(?:(?:(?::[0-9A-F]{1,4}){1,3})|(?:(?::[0-9A-F]{1,4})?:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|"
                            + "(?:(?:[0-9A-F]{1,4}:){3}(?:(?:(?::[0-9A-F]{1,4}){1,4})|(?:(?::[0-9A-F]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|"
                            + "(?:(?:[0-9A-F]{1,4}:){2}(?:(?:(?::[0-9A-F]{1,4}){1,5})|(?:(?::[0-9A-F]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|"
                            + "(?:(?:[0-9A-F]{1,4}:){1}(?:(?:(?::[0-9A-F]{1,4}){1,6})|(?:(?::[0-9A-F]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|"
                            + "(?::(?:(?:(?::[0-9A-F]{1,4}){1,7})|(?:(?::[0-9A-F]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))";
                    break;
                case "uri":
                    // SCHEME://AUTHORITY/PATH/PATH?PARAM=VALUE,PARAM=VALUE#ANCHOR
                    pattern = "(?:(?:http[s]?|ftp):)?" // scheme
                            + "(?://[a-z][a-z.]{4,12})?" // authority
                            + "(?:/[a-z]{1,8}){0,4}" // path
                            + "(?:\\?[a-z]{1,8}=[a-z0-9]{1,8}(?:&[a-z]{1,8}=[a-z0-9]{1,8}){0,3})?" // query
                            + "(?:#[a-z0-9_]{1,16})?"; // fragment
                    break;
                case "uuid":
                    pattern = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; // 8-4-4-4-12
                    break;
                case "password":
                    // Fall through.
                default:
                    break;
            }
        }
    }
    if (pattern == null) {
        int minLength = var == null || var.minLength == null ? 4 : var.minLength;
        int maxLength = var == null || var.maxLength == null ? 16 : var.maxLength;
        pattern = "[a-zA-Z][a-zA-Z0-9]{" + minLength + ',' + maxLength + '}';
    }
    return pattern;
}
 
Example 17
Source File: DrillStringUtils.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * Unescapes any Java literals found in the {@code String}.
 * For example, it will turn a sequence of {@code '\'} and
 * {@code 'n'} into a newline character, unless the {@code '\'}
 * is preceded by another {@code '\'}.
 *
 * @param input  the {@code String} to unescape, may be null
 * @return a new unescaped {@code String}, {@code null} if null string input
 */
public static final String unescapeJava(String input) {
  return StringEscapeUtils.unescapeJava(input);
}
 
Example 18
Source File: DremioStringUtils.java    From dremio-oss with Apache License 2.0 2 votes vote down vote up
/**
 * Unescapes any Java literals found in the {@code String}.
 * For example, it will turn a sequence of {@code '\'} and
 * {@code 'n'} into a newline character, unless the {@code '\'}
 * is preceded by another {@code '\'}.
 *
 * @param input  the {@code String} to unescape, may be null
 * @return a new unescaped {@code String}, {@code null} if null string input
 */
public static final String unescapeJava(String input) {
  return StringEscapeUtils.unescapeJava(input);
}
 
Example 19
Source File: DataUtil.java    From Prism with MIT License 2 votes vote down vote up
/**
 * Decodes all encoded characters in the provided String.
 *
 * @param string Escaped string
 * @return string Unescaped string
 */
public static String unescape(String string) {
    return StringEscapeUtils.unescapeJava(string);
}
 
Example 20
Source File: YamlStringEscapeUtils.java    From ratel with Apache License 2.0 2 votes vote down vote up
/**
 * <p>Unescapes any Java literals found in the <code>String</code>.
 * For example, it will turn a sequence of <code>'\'</code> and
 * <code>'n'</code> into a newline character, unless the <code>'\'</code>
 * is preceded by another <code>'\'</code>.</p>
 *
 * @param str  the <code>String</code> to unescape, may be null
 * @return a new unescaped <code>String</code>, <code>null</code> if null string input
 */
public static String unescapeString(String str) {
    return StringEscapeUtils.unescapeJava(str);
}