public class

FileNameCharacterCheckerUtil

extends Object
java.lang.Object
   ↳ com.atlassian.jira.web.util.FileNameCharacterCheckerUtil

Class Overview

This is a centralized object for checking illegal characters in attachment file names. This is used by the AttachmentManager, the Screenshot Applet, the Abstract Message Handler and others.

Summary

Public Constructors
FileNameCharacterCheckerUtil()
Public Methods
String assertFileNameDoesNotContainInvalidChars(String filename)
This will test the given filename string for any invalid characters.
static char[] getInvalidCharacters()
String getPrintableInvalidCharacters()
String replaceInvalidChars(String filename, char replacementChar)
Replaces each invalid character of the given filename with the replacementChar.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public FileNameCharacterCheckerUtil ()

Public Methods

public String assertFileNameDoesNotContainInvalidChars (String filename)

This will test the given filename string for any invalid characters. If it contains an invalid character then the string returned will be the character. A return value of null means that the string is a valid filename. if the filename is null it will return null for the caller to handle the null filename.

Parameters
filename the filename to be checked.
Returns
  • null if the filename is valid, else the character that is invalid.

public static char[] getInvalidCharacters ()

public String getPrintableInvalidCharacters ()

public String replaceInvalidChars (String filename, char replacementChar)

Replaces each invalid character of the given filename with the replacementChar. If the filename is null, returns null so that the caller can handle the null filename

Parameters
filename file name to replace invalid characters from
replacementChar character to replace invalid characters
Returns
  • new filename with valid characters
Throws
IllegalArgumentException if replacementChar is an invalid character itself