Java Utililty Methods String Sanitize

List of utility methods to do String Sanitize

Description

The list of methods to do String Sanitize are organized into topic(s).

Method

StringsanitizeMimeType(final String mimeType)
Mimetypes can be a tricky thing as browsers and/or environments tend to alter them without good reason.
if (MIME_TYPE_PJPEG.equalsIgnoreCase(mimeType)) {
    return MIME_TYPE_JPEG;
if (MIME_TYPE_CITRIX_JPEG.equalsIgnoreCase(mimeType)) {
    return MIME_TYPE_JPEG;
} else if (MIME_TYPE_CITRIX_GIF.equalsIgnoreCase(mimeType)) {
    return MIME_TYPE_GIF;
if (MIME_TYPE_X_PNG.equalsIgnoreCase(mimeType)) {
    return MIME_TYPE_PNG;
return mimeType.toLowerCase();
StringsanitizeName(String input)
sanitize Name
return blankIfNull(input).replaceAll("[^A-Za-z0-9]", "");
StringSanitizeName(String Name)
Takes a string and rewrites it by replacing all special characters with an '_'.
char C[] = Name.toCharArray();
for (int i = 0; i < C.length; ++i) {
    switch (C[i]) {
    case ' ':
    case '*':
    case '\'':
    case '/':
    case '"':
...
StringsanitizeName(String name)
Returns an identifier from the given string that can be used as resource name.
if (name != null) {
    return name.replaceAll("[^A-Za-z0-9]+", "-");
return null;
StringsanitizeName(String name)
Sanitize a String so that it can be used as a Java identifier.
char[] nameArray = name.toCharArray();
for (int i = 0; i < nameArray.length; i++) {
    if (!Character.isJavaIdentifierPart(nameArray[i])) {
        nameArray[i] = '_';
if (nameArray.length == 0) {
    return "";
...
StringsanitizeName(String name)
sanitize Name
return name != null ? (name.contains(" ") ? name.toLowerCase().replaceAll(" ", "_") : name.toLowerCase())
        : null;
StringsanitizeName(String origName)
Produce a sanitized name that fits our standards for likely to work.
char c[] = origName.toCharArray();
StringBuffer buffer = new StringBuffer();
if ((c[0] >= '0') && (c[0] <= '9')) {
    buffer.append('_');
for (int i = 0; i < c.length; i++) {
    if (((c[i] >= '0') && (c[i] <= '9')) || ((c[i] >= 'a') && (c[i] <= 'z'))
            || ((c[i] >= 'A') && (c[i] <= 'Z'))) {
...
StringsanitizeNamespace(String namespace)
sanitize Namespace
return namespace.replaceAll("(http://)|(/$)", "").replaceAll("[./-]", "_");
StringsanitizeOperationId(String operationId)
sanitize Operation Id
StringBuffer result = new StringBuffer();
for (int i = 0; i < operationId.length(); i++) {
    char c = operationId.charAt(i);
    if (c == '-' || c == ' ' || c == '_') {
        try {
            while (c == '-' || c == ' ' || c == '_') {
                i++;
                c = operationId.charAt(i);
...
StringsanitizePackageName(String raw)
Convert a raw package name to a legal Java package name.
StringBuffer buff = new StringBuffer(raw.length());
boolean first = true;
for (int i = 0; i < raw.length();) {
    char chr = buff.charAt(i);
    if (first) {
        if (Character.isJavaIdentifierStart(chr)) {
            first = false;
            i++;
...