Class AServletElFinderConnector<Response>

java.lang.Object
de.xima.fc.gui.elfinder.AServletElFinderConnector<Response>
Type Parameters:
Response - The type of the response object that is returned by handleRequest.
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FileSystemElFinderConnector

public abstract class AServletElFinderConnector<Response> extends Object implements Serializable
Abstract class for an elfinder connector, based on Java servlets. This class provides base functionality for implementing a server side endpoint for the elfinder file manager. See also the elFinder project.

Implementations need to implement at least readRequestJsonPayload and writeResponseJsonPayload. Implementations should then implement the handleCommand* methods for the commands they wish to support.

Since:
8.3.0.
Author:
XIMA MEDIA GmbH
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkState(javax.servlet.http.HttpServletRequest request)
    Checks whether the current state of this connector allows the request to be processed.
    protected static com.alibaba.fastjson.JSONObject
     
    protected static String
    getRequestId(javax.servlet.http.HttpServletRequest request)
    Gets the ID of the request.
    protected abstract Response
    handleCommandAbort(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Abort the specified request
    protected com.alibaba.fastjson.JSONObject
    handleCommandArchive(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Packs directories / files into an archive.
    protected Response
    handleCommandCallback(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Output callback result with JavaScript that control elFinder or HTTP redirect to callback URL.
    protected com.alibaba.fastjson.JSONObject
    handleCommandChangeMode(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    chmod target items.
    protected com.alibaba.fastjson.JSONObject
    handleCommandDimensions(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Returns the dimensions of an image / video.
    protected com.alibaba.fastjson.JSONObject
    handleCommandDuplicate(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Creates a duplicate for directories / files.
    protected Response
    handleCommandExtract(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Unpacks an archive.
    protected Response
    handleCommandFile(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Output file into browser.
    protected com.alibaba.fastjson.JSONObject
    handleCommandGet(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Returns the content as String (As UTF-8).
    protected com.alibaba.fastjson.JSONObject
    handleCommandInfo(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Returns information about places nodes.
    protected com.alibaba.fastjson.JSONObject
    handleCommandList(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Return a list of item names in the target directory.
    protected com.alibaba.fastjson.JSONObject
    handleCommandMakeDir(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Create a new directory.
    protected com.alibaba.fastjson.JSONObject
    handleCommandMakeFile(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Create a new blank file.
    protected com.alibaba.fastjson.JSONObject
    handleCommandNetMount(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Mount network volume during user session.
    protected com.alibaba.fastjson.JSONObject
    handleCommandOpen(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles an open request.
    protected com.alibaba.fastjson.JSONObject
    handleCommandParents(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Returns all parent folders and their first level (at least) subfolders and own(target) stat.
    protected com.alibaba.fastjson.JSONObject
    handleCommandPaste(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Copies or moves a directory / files.
    protected com.alibaba.fastjson.JSONObject
    handleCommandPing(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Ping to keep current session.
    protected com.alibaba.fastjson.JSONObject
    handleCommandPut(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Stores contents data in a file.
    protected com.alibaba.fastjson.JSONObject
    handleCommandRemove(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Recursively removes files and directories.
    protected com.alibaba.fastjson.JSONObject
    handleCommandRename(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Renaming a directory/file.
    protected com.alibaba.fastjson.JSONObject
    handleCommandResize(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Change the size of an image.
    protected com.alibaba.fastjson.JSONObject
    handleCommandSearch(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Return a list of files and folders list, that match the search string. arguments:
    protected com.alibaba.fastjson.JSONObject
    handleCommandSize(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Returns the size of a directory or file.
    protected com.alibaba.fastjson.JSONObject
    handleCommandThumbnail(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Background command.
    protected com.alibaba.fastjson.JSONObject
    handleCommandTree(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Return folder's subfolders.
    protected OneOfN.Either<com.alibaba.fastjson.JSONObject, Response>
    handleCommandUnknown(String cmd, com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles an unknown command.
    protected com.alibaba.fastjson.JSONObject
    handleCommandUploadChunked(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Process file upload requests with files uploaded in chunks.
    protected com.alibaba.fastjson.JSONObject
    handleCommandUploadSimple(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Process file upload requests.
    protected com.alibaba.fastjson.JSONObject
    handleCommandUrl(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Returns the url of a file.
    protected OneOfN.Either<com.alibaba.fastjson.JSONObject, Response>
    handleCommandZipDownload(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Downloads a set of files as a ZIP archive. 1st request to make temporary archive file on server side. 2nd request to download the archive file.
    final Response
    handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Server side endpoint for the elfinder file manager.
    protected abstract com.alibaba.fastjson.JSONObject
    readRequestJsonPayload(javax.servlet.http.HttpServletRequest req)
     
    protected abstract Response
    writeResponseJsonPayload(javax.servlet.http.HttpServletResponse response, com.alibaba.fastjson.JSONObject responsePayload)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AServletElFinderConnector

      public AServletElFinderConnector()
  • Method Details

    • handleRequest

      public final Response handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Server side endpoint for the elfinder file manager. See Client-Server-API-2.1

      Handles the given request and writes the response to the given response object. It reads the request payload, dispatches the request to the appropriate command handler, and writes the response payload to the request.

      Parameters:
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response object create in response to the request.
    • checkState

      protected void checkState(javax.servlet.http.HttpServletRequest request) throws ElfinderConnectorException
      Checks whether the current state of this connector allows the request to be processed. This method can be overridden by subclasses i.e. to abort the request if the user is not authenticated, or when a session is missing.
      Parameters:
      request - The HTTP request.
      Throws:
      ElfinderConnectorException - When the state is invalid. This will result in an error response to the client.
    • handleCommandAbort

      protected abstract Response handleCommandAbort(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Abort the specified request

      Arguments:

      • cmd : abort
      • id : request id to abort

      Response:

      Empty content with HTTP response code "204 No Content"

      Parameters:
      payload - The abort request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandArchive

      protected com.alibaba.fastjson.JSONObject handleCommandArchive(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Packs directories / files into an archive. API >= 2.1029

      Arguments:

      • cmd : archive
      • name : file name of the archive to create
      • type : mime-type for the archive
      • target : hash of the directory that are added to the archive directories / files
      • targets[] : an array of hashes of the directories / files to archive

      Response:

      • added : (Array) Information about File/Directory of a new archive
      Parameters:
      payload - The archive request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the archive request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandCallback

      protected Response handleCommandCallback(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Output callback result with JavaScript that control elFinder or HTTP redirect to callback URL. This is used for communication with the outside, such as OAuth of netmount.

      Arguments:

      • node : elFinder node DOM id that accepted /^[a-zA-Z0-9;._-]+$/ only
      • json : JSON data for output
      • bind : bind command name (optional)
      • done : 1 or 0 - 0: output redirect HTTP response, 1: output HTML included JavaScript for IFRAME/Child Window.

      Response:

      • HTTP response. Location: [Redirect URL(Defined in the volume driver)]?node={node}&json={json}&bind={bind}&done=1*
      • HTML included JavaScript for IFRAME/Child Window Must be replace {$node}, {$bind}, {$json} to each value.
      Parameters:
      payload - The callback request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the callback request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandChangeMode

      protected com.alibaba.fastjson.JSONObject handleCommandChangeMode(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      chmod target items.

      Arguments:

      • cmd : chmod
      • targets[] : array of hashed paths of the nodes
      • mode : Numeric notation file system permissions

      Response:

      An array of successfully uploaded files if success, an error otherwise.

      • changed : (Array) of files that were successfully done chmod.
      Parameters:
      payload - The change mode request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the change mode request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandDimensions

      protected com.alibaba.fastjson.JSONObject handleCommandDimensions(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Returns the dimensions of an image / video.

      Arguments:

      • cmd: dim
      • target: Hash path of the node
      • substitute : Width in pixel for requesting a substitute image (optional) - API >= 2.1030 When given, the server must return a URL to a thumbnail with the given width.

      Response:

      • dim: The dimensions of the media in the format {width}x{height} (e.g. "640x480").
      • url: The URL to the requested substitute image. (optional)
      Parameters:
      payload - The dimensions request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the dimensions request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandDuplicate

      protected com.alibaba.fastjson.JSONObject handleCommandDuplicate(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Creates a duplicate for directories / files. Copy name is generated as follows:
      basedir_name_filecopy+serialnumber.extension (if any).
      

      Arguments:

      • cmd : duplicate
      • targets[] : An array of hashes for the directories or files to be duplicated

      Response:

      • added (Array) Information about the duplicated files or directories.
      Parameters:
      payload - The duplicate request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the duplicate request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandExtract

      protected Response handleCommandExtract(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Unpacks an archive.

      Arguments:

      • cmd : extract
      • target : hash of the archive file
      • makedir : "1" to extract to new directory

      Response:

      • added : (Array) Information about file / directory of extracted items
      Parameters:
      payload - The extract payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the extract request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandFile

      protected Response handleCommandFile(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Output file into browser. This command applies to download and preview actions.

      Arguments:

      • cmd : file
      • target : file's hash,
      • download : Send headers to force download file instead of opening it in the browser.
      • cpath (API >= 2.1.39) : Cookie path that temporary cookie set up until download starts. If this parameter is specified, the connector must set the cookie name as "elfdl" + Request ID (The value is irrelevant, maybe "1") . This cookie is deleted by the client at the start of download.
      May need to set Content-Disposition, Content-Location and Content-Transfer-Encoding. Content-Disposition should have 'inline' for preview action or 'attachments' for download.
      Parameters:
      payload - The file request payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The binary response object.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandGet

      protected com.alibaba.fastjson.JSONObject handleCommandGet(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Returns the content as String (As UTF-8).

      Arguments:

      • cmd : get
      • current : hash of the directory where the file is stored
      • target : hash of the file
      • conv : instructions for character encoding conversion of the text file
        • 1 : auto detect encoding(Return false as content in response data when failed)
        • 0 : auto detect encoding(Return { "doconv" : "unknown" } as response data when failed)
        • Original Character encoding : original character encoding as specified by the user

      Response:

      • content - file contents (UTF-8 String or Data URI Scheme String) or false
      • encoding - (Optional) Detected original character encoding (Require when converting from encoding other than UTF-8)
      • doconv - (Optional) "doconv":"unknown" is returned to ask the user for the original encoding if automatic conversion to UTF-8 is not possible when requested with conv = 0.
      For files other than text files, content must be returned as string data of Data URI Scheme.
      Parameters:
      payload - The get payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the get request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandInfo

      protected com.alibaba.fastjson.JSONObject handleCommandInfo(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Returns information about places nodes.

      Arguments:

      • cmd : info
      • targets[] : array of hashed paths of the nodes

      Response:

      • files: (Array of data) places directories info data.
      Parameters:
      payload - The info payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the info request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandList

      protected com.alibaba.fastjson.JSONObject handleCommandList(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Return a list of item names in the target directory.

      Arguments:

      • cmd : ls
      • target : hash of directory,
      • intersect[] : An array of the item names for presence check.

      Response:

      • list : (Object) item names list with hash as key. Return only duplicate files if the intersect[] is specified.
      Parameters:
      payload - The ls payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the ls request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandMakeDir

      protected com.alibaba.fastjson.JSONObject handleCommandMakeDir(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Create a new directory.

      Arguments:

      • cmd : mkdir
      • target : hash of target directory,
      • name : New directory name
      • dirs[] : array of new directories path (requests at pre-flight of folder upload)

      Response:

      • added : (Array) Array with a single object - a new directory.
      • hashes : (Object) Object of path in the dirs[] as a key to the corresponding hash value.
      Parameters:
      payload - The mkdir payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the mkdir request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandMakeFile

      protected com.alibaba.fastjson.JSONObject handleCommandMakeFile(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Create a new blank file.

      Arguments:

      • cmd : mkfile
      • target : hash of target directory,
      • name : New file name

      Response:

      • added : (Array) Array with a single object - a new file.
      Parameters:
      payload - The mkfile payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the mkfile request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandNetMount

      protected com.alibaba.fastjson.JSONObject handleCommandNetMount(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Mount network volume during user session.

      Arguments:

      • cwd: netmount
      • protocol : network protocol. Now only ftp supports. Required.
      • host : host name. Required.
      • path : root folder path.
      • port : port.
      • user : user name. Required.
      • pass : password. Required.
      • alias : mount point name. For future usage. Now not used on client side.
      • options : additional options for driver. For future usage. Now not used on client side.
      Parameters:
      payload - The netmount payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the netmount request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandOpen

      protected com.alibaba.fastjson.JSONObject handleCommandOpen(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Handles an open request.

      Returns information about requested directory and its content, optionally can return directory tree as files, and options for the current volume.

      Arguments:

      • init : (true|false|not set), optional parameter. If true indicates that this request is an initialization request and its response must include the value api (number or string >= 2) and should include the options object, but will still work without it. Also, this option affects the processing of parameter target hash value. If init == true and target is not set or that directory doesn't exist, then the data connector must return the root directory of the default volume. Otherwise it must return error "File not found".
      • target : (string) Hash of directory to open. Required if init == false or init is not set
      • tree : (true|false), optional. If true, response must contain the top-level object of other volumes.

      Response:

      • api : (Float) The version number of the protocol, must be >= 2.1, ATTENTION - return api ONLY for init request!
      • cwd : (Object) Current Working Directory - information about the current directory.
      • files : (Array) array of objects - files and directories in current directory. If parameter tree == true, then added to the root folder objects of other volumes. The order of files is not important. Information about File/Directory
      • netDrivers : (Array) Network protocols list which can be mounted on the fly (using netmount command). Now only ftp supported.
      • uplMaxFile : (Number) Allowed upload max number of file per request. For example 20
      • uplMaxSize : (String) Allowed upload max size per request. For example "32M"
      • options : (Object) Further information about the folder and its volume
      Parameters:
      payload - The open request to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the open request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandParents

      protected com.alibaba.fastjson.JSONObject handleCommandParents(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Returns all parent folders and their first level (at least) subfolders and own(target) stat. This command is invoked when a folder is reloaded or there is no data to display the tree of the target folder in the client. Data provided by 'parents' command should enable the correct drawing of tree hierarchy directories.

      Arguments:

      • cmd : parents
      • target : folder's hash
      • until : until to hash, getting parents is enough for that (API >= 2.1024)

      Response:

      • tree : (Array) Folders list.
      Parameters:
      payload - The parents payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the parents request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandPaste

      protected com.alibaba.fastjson.JSONObject handleCommandPaste(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Copies or moves a directory / files.

      Arguments:

      • cmd : paste
      • dst : hash of the directory to which the files will be copied / moved (the destination)
      • targets[] : An array of hashes for the files to be copied / moved
      • cut : 1 if the files are moved, missing if the files are copied
      • renames[] : Filename list of rename request
      • suffix : Suffixes during rename (default is "~")

      Response:

      • added : (Array) array of file and directory objects pasted.
      • removed : (Array) array of file and directory 'hashes' that were successfully deleted

      Caution:

      • If the file name of the rename list exists in the directory, The command should rename the file to "filename + suffix"
      • The command should stop copying at the first error. Is not allowed to overwrite files / directories with the same name. But the behavior of this command depends on some options on connector (if the user uses the default one). Please, take look the options:
      Parameters:
      payload - The paste payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the paste request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandPing

      protected com.alibaba.fastjson.JSONObject handleCommandPing(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Ping to keep current session.

      Previously it was used to prevent bugs of uploading with Safari, but it is not currently used.

      Arguments:

      • cmd : ping

      Response: sends a blank response with the header @Connection: close@.

      Parameters:
      payload - The ping payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the ping request.
      Throws:
      ElfinderConnectorException
    • handleCommandPut

      protected com.alibaba.fastjson.JSONObject handleCommandPut(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Stores contents data in a file.

      Arguments:

      • cmd : put
      • target : hash of the file
      • content : new contents of the file
      • encoding : character encoding at the time of saving (Text data will be sent by UTF-8) or "scheme" for URL of contents or Data URI scheme
      Content of file data other than text file is sent as string data of Data URI Scheme or URL of new contents with param encoding=scheme.

      Response: An array of successfully uploaded files if success, an error otherwise.

      • changed : (Array) of files that were successfully uploaded. Information about File/Directory
      Parameters:
      payload - The put payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the put request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandRemove

      protected com.alibaba.fastjson.JSONObject handleCommandRemove(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Recursively removes files and directories.

      Arguments:

      • cmd : rm
      • targets[] : (Array) array of file and directory hashes to delete

      Response:

      • removed : (Array) array of file and directory 'hashes' that were successfully deleted
      Parameters:
      payload - The rm payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the rm request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandRename

      protected com.alibaba.fastjson.JSONObject handleCommandRename(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Renaming a directory/file.

      Arguments:

      • cmd : rename
      • target : hash directory/file renaming
      • name : New name of the directory/file

      Response:

      • added : (Array) array of file and directory objects renamed.
      • removed : (Array) array of file and directory 'hashes' that were successfully removed.
      Parameters:
      payload - The rename payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the rename request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandResize

      protected com.alibaba.fastjson.JSONObject handleCommandResize(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Change the size of an image.

      Arguments:

      • Change the size of an image.
      • mode : 'resize' or 'crop' or 'rotate'
      • target : hash of the image path
      • width : new image width
      • height : new image height
      • x : x of crop (mode='crop')
      • y : y of crop (mode='crop')
      • degree : rotate degree (mode='rotate')
      • quality: compression quality, e.g. for JPEG images
      • bg: CSS hex color string for the background (when rotating)

      Response:

      • changed : (Array) of files that were successfully resized.
      Parameters:
      payload - The resize payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the resize request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandSearch

      protected com.alibaba.fastjson.JSONObject handleCommandSearch(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Return a list of files and folders list, that match the search string. arguments:

      Arguments:

      • cmd : search
      • q : search string
      • target : search target hash (optional)
      • mimes : Array of search target MIME-type (optional)

      Response:

      • files : (Array) array of objects - files and folders list, that match the search string.
      Parameters:
      payload - The search payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the search request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandSize

      protected com.alibaba.fastjson.JSONObject handleCommandSize(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Returns the size of a directory or file.

      Arguments:

      • cmd : size
      • targets[] : hash paths of the nodes

      Response:

      • size: The total size for all the supplied targets.
      • fileCnt: The total counts of the file for all the supplied targets. (Optional to API >= 2.1025)
      • dirCnt: The total counts of the directory for all the supplied targets. (Optional to API >= 2.1025)
      • sizes: An object of each target size information. (Optional to API >= 2.1030)
      Parameters:
      payload - The size payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the size request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandThumbnail

      protected com.alibaba.fastjson.JSONObject handleCommandThumbnail(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Background command. Creates thumbnails for images that do not have them.

      Arguments:

      • cmd : tmb
      • targets[] : an array of hash path to the directory in which to create thumbnails

      Response:

      • images: An object with the file hash as the key and the thumbnail URL as the value.
      Parameters:
      payload - The thumbnail payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the thumbnail request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandTree

      protected com.alibaba.fastjson.JSONObject handleCommandTree(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Return folder's subfolders.

      Arguments

      • cmd : tree
      • target : folder's hash
      Response
      • tree : (Array) Folders list.
      Parameters:
      payload - The tree payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the tree request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandUnknown

      protected OneOfN.Either<com.alibaba.fastjson.JSONObject, Response> handleCommandUnknown(String cmd, com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Handles an unknown command.
      Parameters:
      cmd - The unknown command.
      payload - The payload of the unknown command.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the unknown command.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandUploadChunked

      protected com.alibaba.fastjson.JSONObject handleCommandUploadChunked(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Process file upload requests with files uploaded in chunks. Client may request the upload of multiple files at once.

      Arguments:

      • cmd : upload
      • target : hash of the directory to upload
      • upload[] : array of multipart files to upload
      • upload_path[] : (optional) array of target directory hash, it has been a pair with upload[]. (specified at folder upload)
      • mtime[] : (optional) array of files UNIX time stamp, it has been a pair with upload[].
      • name[] : (optional) array of files name for suggest, it has been a pair with upload[].
      • renames[] : (optional) array of rename request filenames
      • suffix : (optional) rename suffix
      • hashes[hash] : (optional) array of hash: filename pairs
      • overwrite : (optional) Flag to overwrite or save another name. If "0" is specified and the same name file exists, the connector should save the upload file as a different name.

      Response:

      • added : (Array) of files that were successfully uploaded.
      • warning : (Array) of error messages like a errors. Ony if the files could not be uploaded.
      Chunked uploads

      Chunking Extra arguments:

      • chunk : chunk name "filename.[NUMBER]_[TOTAL].part"
      • cid : unique id of chunked uploading filerange : Bytes range of file "Start byte,Chunk length,Total bytes"
      • range : Bytes range of file "Start byte,Chunk length,Total bytes"

      Response:

      • added : (Array) empty array
      • _chunkmerged : (String) file name of server side. ONLY when the upload of all the chunk file has been completed.
      • _name : (String) uploading file name.  ONLY when the upload of all the chunk file has been completed.

      Chunk merge request (When receive _chunkmerged, _name)

      Extra arguments:

      • upload[] : Value of _name
      • chunk : Value of _chunkmerged

      Response:

      • added : (Array) of files that were successfully uploaded.
      Parameters:
      payload - The upload payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the upload request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandUploadSimple

      protected com.alibaba.fastjson.JSONObject handleCommandUploadSimple(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Process file upload requests. Client may request the upload of multiple files at once.

      Arguments:

      • cmd : upload
      • target : hash of the directory to upload
      • upload[] : array of multipart files to upload
      • upload_path[] : (optional) array of target directory hash, it has been a pair with upload[]. (specified at folder upload)
      • mtime[] : (optional) array of files UNIX time stamp, it has been a pair with upload[].
      • name[] : (optional) array of files name for suggest, it has been a pair with upload[].
      • renames[] : (optional) array of rename request filenames
      • suffix : (optional) rename suffix
      • hashes[hash] : (optional) array of hash: filename pairs
      • overwrite : (optional) Flag to overwrite or save another name. If "0" is specified and the same name file exists, the connector should save the upload file as a different name.

      Response:

      • added : (Array) of files that were successfully uploaded.
      • warning : (Array) of error messages like a errors. Ony if the files could not be uploaded.
      Parameters:
      payload - The upload payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the upload request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandUrl

      protected com.alibaba.fastjson.JSONObject handleCommandUrl(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Returns the url of a file. This method is called if the initial value for the file's url is "1".

      Arguments:

      • cmd : url
      • target : hash of file
      • options[] : array of options (?)

      Response:

      • url: url of the file
      Parameters:
      payload - The url payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the url request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • handleCommandZipDownload

      protected OneOfN.Either<com.alibaba.fastjson.JSONObject, Response> handleCommandZipDownload(com.alibaba.fastjson.JSONObject payload, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ElfinderConnectorException
      Downloads a set of files as a ZIP archive. 1st request to make temporary archive file on server side. 2nd request to download the archive file.

      1st request

      Arguments:

      • cmd : zipdl
      • targets[] : array of hashed paths of the nodes to download

      Response:

      • zipdl: array data for 2nd request
      2nd request

      Arguments:

      • cmd : zipdl
      • download : 1
      • targets[0] : hash path for detect target volume drive (e.g. cwd hash)
      • targets[1] : target temporary archive file key
      • targets[2] : download file name
      • targets[3] : MIME type
      Response: RAW data of archive file with HTTP headers for download
      Parameters:
      payload - The zip download payload to handle.
      request - The HTTP request.
      response - The HTTP response.
      Returns:
      The response to the zip download request.
      Throws:
      ElfinderConnectorException - When the command could not be handled.
    • readRequestJsonPayload

      protected abstract com.alibaba.fastjson.JSONObject readRequestJsonPayload(javax.servlet.http.HttpServletRequest req) throws ElfinderConnectorException
      Throws:
      ElfinderConnectorException
    • writeResponseJsonPayload

      protected abstract Response writeResponseJsonPayload(javax.servlet.http.HttpServletResponse response, com.alibaba.fastjson.JSONObject responsePayload)
    • createErrorResponse

      protected static com.alibaba.fastjson.JSONObject createErrorResponse(Exception e)
    • getRequestId

      protected static String getRequestId(javax.servlet.http.HttpServletRequest request)
      Gets the ID of the request. From the docs:
      A client with elFinder 2.1.29 or later sends a request including the HTTP header "X-elFinderReqid" or the request parameter "reqid" as the request ID. In addition, the client sends abort command when aborting the request. When the connector receives this "abort" command, it can interrupt the operation of that request.
      Parameters:
      request - The HTTP request.
      Returns:
      The request ID, empty string if not found.