net.fckeditor.tool
Class UtilsFile

java.lang.Object
  extended by net.fckeditor.tool.UtilsFile

public class UtilsFile
extends Object

Static helper methods for files.

Version:
$Id: UtilsFile.java 3876 2009-07-13 18:27:07Z mosipov $

Field Summary
protected static Pattern ILLEGAL_CURRENT_FOLDER_PATTERN
           
 
Constructor Summary
UtilsFile()
           
 
Method Summary
static void checkDirAndCreate(File dir)
          Checks a directory for existence and creates it if non-existent.
static String forceSingleExtension(String filename)
          Replaces all dots in a filename with underscores except the last one.
static File getUniqueFile(File file)
          Iterates over a base name and returns the first non-existent file.
static boolean isImage(InputStream in)
          Checks if the underlying input stream contains an image.
static boolean isSingleExtension(String filename)
          Checks if a filename contains more than one dot.
static boolean isValidPath(String path)
          Checks whether a path complies with the FCKeditor File Browser rules.
static String sanitizeFileName(String filename)
          Sanitizes a filename from certain chars.
static String sanitizeFolderName(String folderName)
          Sanitizes a folder name from certain chars.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ILLEGAL_CURRENT_FOLDER_PATTERN

protected static final Pattern ILLEGAL_CURRENT_FOLDER_PATTERN
Constructor Detail

UtilsFile

public UtilsFile()
Method Detail

sanitizeFileName

public static String sanitizeFileName(String filename)
Sanitizes a filename from certain chars.
This method enforces the forceSingleExtension property and then replaces all occurrences of \, /, |, :, ?, *, ", <, >, control chars by _ (underscore).

Parameters:
filename - a potentially 'malicious' filename
Returns:
sanitized filename

sanitizeFolderName

public static String sanitizeFolderName(String folderName)
Sanitizes a folder name from certain chars.
This method replaces all occurrences of \, /, |, :, ?, *, ", <, >, control chars by _ (underscore).

Parameters:
folderName - a potentially 'malicious' folder name
Returns:
sanitized folder name

isImage

public static boolean isImage(InputStream in)
Checks if the underlying input stream contains an image.

Parameters:
in - input stream of an image
Returns:
true if the underlying input stream contains an image, else false

isValidPath

public static boolean isValidPath(String path)
Checks whether a path complies with the FCKeditor File Browser rules.

Parameters:
path - a potentially 'malicious' path
Returns:
true if path complies with the rules, else false

forceSingleExtension

public static String forceSingleExtension(String filename)
Replaces all dots in a filename with underscores except the last one.

Parameters:
filename - filename to sanitize
Returns:
string with a single dot only

isSingleExtension

public static boolean isSingleExtension(String filename)
Checks if a filename contains more than one dot.

Parameters:
filename - filename to check
Returns:
true if filename contains severals dots, else false

checkDirAndCreate

public static void checkDirAndCreate(File dir)
Checks a directory for existence and creates it if non-existent.

Parameters:
dir - directory to check/create

getUniqueFile

public static File getUniqueFile(File file)
Iterates over a base name and returns the first non-existent file.
This method extracts a file's base name, iterates over it until the first non-existent appearance with basename(n).ext. Where n is a positive integer starting from one.

Parameters:
file - base file
Returns:
first non-existent file


Copyright © 2004-2009 Frederico Caldeira Knabben. All Rights Reserved.