List of utility methods to do String Sanitize
String | sanitizeIdentifier(String identifier) Sanitizes a stream identifier Stream identifiers are used to identify the content of a specific stream. StringBuilder sb = new StringBuilder(); for (int i = 0; i < 4 && i < identifier.length(); i++) { Character c = identifier.charAt(i); if (c.charValue() > 127 || !Character.isLetterOrDigit(c)) continue; sb.append(c); return String.format("%-4s", sb.toString()); ... |
String | sanitizeIdentifierName(String input) Escapes illegal characters in given identifier. if (input == null || input.isEmpty()) { return input; final StringBuilder result = new StringBuilder(); char ch = input.charAt(0); if (Character.isJavaIdentifierStart(ch)) { result.append(ch); } else { ... |
String | sanitizeIDs(String str) Replace last "|" in pageIDs if (str != null && str.length() > 0 && str.charAt(str.length() - 1) == '|') { str = str.substring(0, str.length() - 1); return str; |
String | sanitizeInput(String input) "Sanitizes" the given input by replacing any new line characters with spaces. return sanitizeInput(input, "\r\n", ' ', 255); |
String | sanitizeInput(String string) Sanitize HTML return string.replaceAll("(?i)<script.*?>.*?</script.*?>", "") .replaceAll("(?i)<script.*?/>", "") .replaceAll("(?i)<script.*?>", "") .replaceAll("(?i)<.*?javascript:.*?>.*?</.*?>", "") .replaceAll("(?i)<.*?javascript:.*?/>", "") .replaceAll("(?i)<.*?javascript:.*?>", "") .replaceAll("(?i)<.*?\\s+on.*?>.*?</.*?>", "") .replaceAll("(?i)<.*?\\s+on.*?/>", "") ... |
String | sanitizeJavascript(String originalString) sanitize Javascript return originalString.replaceAll("[\\\\(\"\')\\]\\[]", "\\\\$0"); |
String | sanitizeLine(String line) Sanitize a single line of the "meta data". final StringBuilder result = new StringBuilder(); final String[] lineRecord = line.split(CSV_SEPARATOR); try { Integer.valueOf(lineRecord[0]); result.append(lineRecord[0]); } catch (NumberFormatException e) { result.append(-1); result.append(CSV_SEPARATOR); result.append(lineRecord[1]); result.append(CSV_SEPARATOR); try { Integer.valueOf(lineRecord[2]); result.append(lineRecord[2]); } catch (NumberFormatException e) { result.append(-1); return result.toString(); |
String | sanitizeLineSpaces(String line) Replaces all tabs and multiple spaces with a single space return line.replaceAll("\\s+", " ").trim(); |
String | sanitizeLoggerNamePart(String name) sanitize Logger Name Part return name.replace('.', '_'); |
String | sanitizeMethodName(String methodName) Sanitizes a potential method name so it is both valid and follows Java conventions (camel-cased, no underscores, etc.). assert (methodName != null && methodName.length() > 0); StringBuilder sb = new StringBuilder(); char firstChar = methodName.charAt(0); if (Character.isJavaIdentifierStart(firstChar)) { if (Character.isUpperCase(firstChar)) { firstChar = Character.toLowerCase(firstChar); sb.append(firstChar); ... |