net.fckeditor.connector.impl
Class AbstractLocalFileSystemConnector

java.lang.Object
  extended by net.fckeditor.connector.impl.AbstractLocalFileSystemConnector
All Implemented Interfaces:
Connector
Direct Known Subclasses:
ContextConnector, LocalConnector

public abstract class AbstractLocalFileSystemConnector
extends Object
implements Connector

Abstract local filesystem backend connector. This class is the default implementation of the official connector specification.

It serves files and folders against a specific local directory which is resolved in a subclass. You cannot use this class directly, instead you have to subclass it and implement the abstract methods and override methods if necessary.

Version:
$Id: AbstractLocalFileSystemConnector.java 4785 2009-12-21 20:10:28Z mosipov $

Field Summary
protected  ServletContext servletContext
           
 
Fields inherited from interface net.fckeditor.connector.Connector
KEY_NAME, KEY_SIZE
 
Constructor Summary
AbstractLocalFileSystemConnector()
           
 
Method Summary
 void createFolder(ResourceType type, String currentFolder, String newFolder)
          Creates a new folder on the backend.
 String fileUpload(ResourceType type, String currentFolder, String fileName, InputStream inputStream)
          Uploads a new file on to the backend.
 List<Map<String,Object>> getFiles(ResourceType type, String currentFolder)
          Returns a list of file attributes from the backend.
 List<String> getFolders(ResourceType type, String currentFolder)
          Returns a list of folders from the backend.
protected static File getOrCreateResourceTypeDir(String baseDir, ResourceType type)
          Returns a file reference to a created resource type directory.
protected abstract  String getRealUserFilesAbsolutePath(String userFilesAbsolutePath)
          Resolves a provided userfiles absolute path against a specific backend.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.fckeditor.connector.Connector
init
 

Field Detail

servletContext

protected ServletContext servletContext
Constructor Detail

AbstractLocalFileSystemConnector

public AbstractLocalFileSystemConnector()
Method Detail

fileUpload

public String fileUpload(ResourceType type,
                         String currentFolder,
                         String fileName,
                         InputStream inputStream)
                  throws InvalidCurrentFolderException,
                         WriteException
Description copied from interface: Connector
Uploads a new file on to the backend. You are not allowed to overwrite already existing files, rename the new file and return the new filename.

Specified by:
fileUpload in interface Connector
Parameters:
type - the current resource type
currentFolder - the current folder
fileName - the name of the new file
inputStream - input stream of the new file
Returns:
the (eventually renamed) name of the uploaded file
Throws:
InvalidCurrentFolderException - if the current folder name is invalid or does not exist within the underlying backend
WriteException - if the new file could not be created due to some reason

createFolder

public void createFolder(ResourceType type,
                         String currentFolder,
                         String newFolder)
                  throws InvalidCurrentFolderException,
                         InvalidNewFolderNameException,
                         FolderAlreadyExistsException
Description copied from interface: Connector
Creates a new folder on the backend.

Specified by:
createFolder in interface Connector
Parameters:
type - the current resource type
currentFolder - the current folder
newFolder - name of the new folder
Throws:
InvalidCurrentFolderException - if the current folder name is invalid or does not exist within the underlying backend
InvalidNewFolderNameException - if the new folder name is invalid due to some reason
FolderAlreadyExistsException - if the new folder already exists

getFiles

public List<Map<String,Object>> getFiles(ResourceType type,
                                         String currentFolder)
                                  throws InvalidCurrentFolderException
Description copied from interface: Connector
Returns a list of file attributes from the backend. Use the pre-defined keys ("name", "size") to put file attributes into the file map. The file length can be any instance of Number, its long value will be taken as the final value.

Specified by:
getFiles in interface Connector
Parameters:
type - the current resource type
currentFolder - the current folder
Returns:
a list of file attributes
Throws:
InvalidCurrentFolderException - if the current folder name is invalid or does not exist within the underlying backend

getFolders

public List<String> getFolders(ResourceType type,
                               String currentFolder)
                        throws InvalidCurrentFolderException
Description copied from interface: Connector
Returns a list of folders from the backend.

Specified by:
getFolders in interface Connector
Parameters:
type - the current resource type
currentFolder - the current folder
Returns:
a list of folder names
Throws:
InvalidCurrentFolderException - if the current folder name is invalid or does not exist within the underlying backend

getRealUserFilesAbsolutePath

protected abstract String getRealUserFilesAbsolutePath(String userFilesAbsolutePath)
Resolves a provided userfiles absolute path against a specific backend. The is no restriction how to resolve the path. To keep it simple, you may use UserPathBuilder.getUserFilesAbsolutePath. The return value has to be consistent within the entire request cycle.

Parameters:
userFilesAbsolutePath - the userfiles absolute path to resolve against a specific backend
Returns:
the resolved userfiles absolute path

getOrCreateResourceTypeDir

protected static File getOrCreateResourceTypeDir(String baseDir,
                                                 ResourceType type)
Returns a file reference to a created resource type directory. The directory will be created only if it does not exist.

Parameters:
baseDir - the current resource type's base directory
type - the current resource type
Returns:
a file reference the resource type directory


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