Class Backend

java.lang.Object
com.cksource.ckfinder.filesystem.Backend

public class Backend extends Object
Class representing backend - an intermediate layer between CKFinder and filesystem.
  • Field Details

    • config

      protected Config.Backend config
    • fileSystem

      protected FileSystem fileSystem
    • ESCAPABLE_CHARS

      protected static final char[] ESCAPABLE_CHARS
  • Constructor Details

    • Backend

      public Backend(Config.Backend config, FileSystem fileSystem, Acl acl)
      Constructs backend instance.
      Parameters:
      config - backend configuration
      fileSystem - backend's filesystem
      acl - access control list
  • Method Details

    • usesProxyCommand

      public boolean usesProxyCommand()
      Returns:
      true if this backend uses the Proxy command, false otherwise
    • getBaseUrl

      public String getBaseUrl()
      Returns:
      the base URL defined for this backend
    • getRoot

      public String getRoot()
      Returns:
      filesystem path used as a root folder of this backend
    • getName

      public String getName()
      Returns:
      the name of this backend
    • getFileSystem

      public FileSystem getFileSystem()
      Returns:
      filesystem used by this backend
    • toFileSystemPath

      protected Path toFileSystemPath(String path) throws IllegalArgumentException
      Converts the internal CKFinder's path to a real filesystem path.
      Parameters:
      path - internal CKFinder's path
      Returns:
      filesystem path
      Throws:
      IllegalArgumentException - if given path is not valid
    • listFiles

      public List<File> listFiles(ResourceType resourceType, String folderPath, boolean allowHidden) throws IOException
      Returns a list of files in given folder.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      allowHidden - if true, the hidden files will be included in the returned result
      Returns:
      list of files in given folder
      Throws:
      IOException - in case of any processing exception
    • listFiles

      public List<File> listFiles(ResourceType resourceType, String folderPath) throws IOException
      Returns a list of files in given folder.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      Returns:
      list of files in given folder
      Throws:
      IOException - in case of any processing exception
    • listFolders

      public List<Folder> listFolders(ResourceType resourceType, String folderPath) throws IOException
      Returns a list of folders inside given folder.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      Returns:
      list of folders in given folder
      Throws:
      IOException - in case of any processing exception
    • hasFolder

      public boolean hasFolder(ResourceType resourceType, String folderPath, boolean allowHidden)
      Returns a list of folders inside given folder.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      allowHidden - if true, this check will not ignore hidden folders
      Returns:
      true if folder contains child folders inside it
    • hasFolder

      public boolean hasFolder(ResourceType resourceType, String folderPath)
      Returns a list of folders inside given folder (ignores hidden folders).
      Parameters:
      resourceType - resource type
      folderPath - folder path
      Returns:
      true if folder contains child folders inside it
    • createFolder

      public String createFolder(ResourceType resourceType, String folderPath, String folderName)
      Creates a new folder under given path.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      folderName - the name of the created folder
      Returns:
      the name of the created folder
    • createFolder

      public void createFolder(ResourceType resourceType, String folderPath)
      Creates folder under given path.

      In comparison to createFolder(ResourceType, String, String), this method doesn't perform any security checks.

      Parameters:
      resourceType - resource type
      folderPath - folder path
    • createResourceTypeFolder

      public void createResourceTypeFolder(ResourceType resourceType) throws IOException
      Creates the resource type root folder.
      Parameters:
      resourceType - resource type
      Throws:
      IOException - in case of any processing exception
    • folderContainsSubfolders

      public boolean folderContainsSubfolders(ResourceType resourceType, String folderPath) throws IOException
      Checks if given folder contains any subfolders.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      Returns:
      true if given folder contains subfolders
      Throws:
      IOException - in case of any processing exception
    • hasFile

      public boolean hasFile(ResourceType resourceType, String folderPath, String fileName)
      Checks if file under given path exists.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - file name
      Returns:
      true if file under given paths exists
    • getFileSize

      public long getFileSize(ResourceType resourceType, String folderPath, String fileName)
      Returns the size of a file under given path.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - file name
      Returns:
      file size in bytes
    • hasFile

      public boolean hasFile(String filePath)
      Checks if this backend has a file under given path.

      In comparison to hasFile(ResourceType, String, String), this method doesn't perform any security checks.

      Parameters:
      filePath - file path
      Returns:
      true if this backend contains file under given path
    • writeFile

      public void writeFile(ResourceType resourceType, String folderPath, String fileName, InputStream in)
      Saves file under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - file name
      in - file data input stream
    • writeFile

      public void writeFile(String filePath, InputStream in)
      Saves file under given location.

      In comparison to writeFile(ResourceType, String, String, InputStream), this method doesn't perform any security checks.

      Parameters:
      filePath - file path
      in - file data input stream
    • readFile

      public InputStream readFile(ResourceType resourceType, String folderPath, String fileName)
      Returns the data stream of file under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - file name
      Returns:
      file dta stream
    • readFile

      public InputStream readFile(String filePath)
      Returns the data stream of file under given location.

      In comparison to readFile(ResourceType, String, String), this method doesn't perform any security checks.

      Parameters:
      filePath - file path
      Returns:
      file data stream
    • deleteFile

      public void deleteFile(ResourceType resourceType, String folderPath, String fileName)
      Removes file under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - file name
    • deleteFile

      public void deleteFile(String filePath)
      Removes file under given location.

      In comparison to deleteFile(ResourceType, String, String), this method doesn't perform any security checks.

      Parameters:
      filePath - file path
    • renameFile

      public String renameFile(ResourceType resourceType, String folderPath, String fileName, String newFileName, boolean allowHidden)
      Renames file under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - old file name
      newFileName - new file name
      allowHidden - if true, this method will not ignore hidden files
      Returns:
      new file name
    • renameFile

      public String renameFile(ResourceType resourceType, String folderPath, String fileName, String newFileName)
      Renames file under given location (ignores hidden files).
      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - old file name
      newFileName - new file name
      Returns:
      new file name
    • renameFolder

      public String renameFolder(ResourceType resourceType, String folderPath, String oldFolderName, String newFolderName, boolean allowHidden, boolean validateNames)
      Renames folder under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      oldFolderName - old folder name
      newFolderName - new folder name
      allowHidden - if true, this method will not ignore hidden folders
      validateNames - if true, this method will validate folder names
      Returns:
      new folder name
    • renameFolder

      public void renameFolder(String folderPath, String newFolderPath)
      Renames folder under given location.
      Parameters:
      folderPath - old folder path
      newFolderPath - new folder path
    • renameFolder

      public String renameFolder(ResourceType resourceType, String folderPath, String oldFolderName, String newFolderName)
      Renames folder under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      oldFolderName - old folder name
      newFolderName - new folder name
      Returns:
      new folder name
    • deleteFolder

      public void deleteFolder(ResourceType resourceType, String folderPath, boolean allowHidden)
      Deletes folder under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
      allowHidden - if true, this method will not ignore hidden folders
    • deleteFolder

      public void deleteFolder(ResourceType resourceType, String folderPath)
      Deletes folder under given location.
      Parameters:
      resourceType - resource type
      folderPath - folder path
    • deleteFolder

      public void deleteFolder(String folderPath)
      Deletes folder under given location.
      Parameters:
      folderPath - folder path
    • autorenameFile

      public String autorenameFile(ResourceType resourceType, String folderPath, String fileName)
      Renames the file by adding a number to the file name.

      Renaming is done by adding a number in parenthesis provided that the file name does not collide with any other file existing in the target backend/path. For example, if the target backend path contains a file named foo.txt and the current file name is foo.txt, this method will change the current file name to foo(1).txt.

      Parameters:
      resourceType - resource type
      folderPath - folder path
      fileName - file name
      Returns:
      file name after autorename
    • sanitizeFileName

      public String sanitizeFileName(ResourceType resourceType, String fileName)
      Sanitizes current file name.
      Parameters:
      resourceType - resource type
      fileName - file name
      Returns:
      sanitized file name
    • validateDoubleExtensions

      public void validateDoubleExtensions(ResourceType resourceType, String fileName)
      Checks double extensions in a given file name.
      Parameters:
      resourceType - resource type
      fileName - file name
    • isAllowedHtmlExtension

      public boolean isAllowedHtmlExtension(String fileNameExtension)
      Checks if file with given extension is allowed to contain HTML-like data.
      Parameters:
      fileNameExtension - file name extension
      Returns:
      true if file with given extension is allowed to contain HTML-like data, false otherwise
    • isHiddenFile

      public boolean isHiddenFile(String fileName)
      Checks if file name is hidden.
      Parameters:
      fileName - file name
      Returns:
      true if file name is hidden
    • isHiddenFolder

      public boolean isHiddenFolder(String folderName)
      Checks if folder name is hidden.
      Parameters:
      folderName - folder name
      Returns:
      true if folder name is hidden
    • isHiddenPath

      public boolean isHiddenPath(String folderPath)
      Checks if folder path is hidden.
      Parameters:
      folderPath - folder path
      Returns:
      true if folder path is hidden
    • isValidFileName

      public boolean isValidFileName(String fileName)
      Checks if given file name is valid.
      Parameters:
      fileName - file name to check
      Returns:
      true if given file name is valid, false otherwise
    • isValidFolderName

      public boolean isValidFolderName(String folderName)
      Checks if given folder name is valid.
      Parameters:
      folderName - folder name to check
      Returns:
      true if given folder name is valid, false otherwise
    • folderContainsSubfolders

      public boolean folderContainsSubfolders(ResourceType resourceType) throws IOException
      Checks if resource type root folder contains subfolders.
      Parameters:
      resourceType - resource type
      Returns:
      true if resource type root folder contains subfolders
      Throws:
      IOException - in case of any processing exception
    • overwritesOnUpload

      public boolean overwritesOnUpload()
      Returns:
      true if this backend overwrites files on upload instead of autorenaming them