Java String Sanitize sanitizeSuiteName(String name)

Here you can find the source of sanitizeSuiteName(String name)

Description

Returns a sanitized suite name suitable for inclusion in a XML report.

License

Apache License

Parameter

Parameter Description
name The name to sanitize. In most cases this is the class name of the test being run, but some frameworks (I'm looking at you, Cucumber) like to pass weird things like human-readable free-form textual descriptions of the tests, so we can't make assumptions.

Declaration

static String sanitizeSuiteName(String name) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (see LICENSE).

public class Main {
    /**/*from ww w.  j a  va 2s .  co m*/
     * Returns a sanitized suite name suitable for inclusion in a XML report.
     *
     * This is also used to generate an XML report's filename, so it is important that it does not
     * contain special characters that are illegal on the filesystem.
     *
     * This strips out punction and whitespace, but leaves the '_', '.', and '-' symbols, and trailing
     * periods are trimmed.
     *
     * @param name The name to sanitize. In most cases this is the class name of the test being run,
     *   but some frameworks (I'm looking at you, Cucumber) like to pass weird things like
     *   human-readable free-form textual descriptions of the tests, so we can't make assumptions.
     * @return
     */
    static String sanitizeSuiteName(String name) {
        return name.replaceAll("[[\\p{Punct}][\\p{Space}]&&[^_.-]]", "-").replaceAll("[.]+$", "");
    }
}

Related

  1. sanitizeString(String s)
  2. sanitizeString(String str)
  3. sanitizeStringAsLiteral(String literal)
  4. sanitizeStringForXPath(String text)
  5. sanitizeStringLiteral(String inputString)
  6. sanitizeTag(String s)
  7. sanitizeTextAsDomId(final String text)
  8. sanitizeTimezones(String s)
  9. sanitizeTokenString(final String tokenString)