Giter VIP home page Giter VIP logo

elfinder-2.x-servlet's Introduction

what's elfinder-2.x-servlet

GitHub issues GitHub forks GitHub stars GitHub license

elfinder-2.x-servlet implements a java servlet for elfinder-2.x connector

elfinder is an Open-source file manager for web, written in JavaScript using jQuery and jQuery UI. see also http://elfinder.org

for elfinder-1.2 users, please go to https://github.com/Studio-42/elfinder-servlet.

importing elfinder-2.x-servlet

this project is released as an artifact on the central repostory

use

<dependency>
    <groupId>org.grapheco</groupId>
    <artifactId>elfinder-servlet-2</artifactId>
    <version>1.4</version>
    <classifier>classes</classifier>
</dependency>

to add dependency in your pom.xml

building elfinder-2.x-servlet

the source files includes:

  • src/main/webapp : a normal j2ee application includes elfinder, WEB-INF...
  • src/main/java: source codes for elfinder-servlet
  • src/main/resources: source codes for elfinder-servlet

To build this project with maven run:

mvn install

to run this project within a jetty container use:

mvn jetty:run

using elfinder-2.x-servlet in your web apps

just use following codes to tell elfinder to connect with server-side servlet:

	<script type="text/javascript" charset="utf-8">
		$(document).ready(function() {
			$('#elfinder').elfinder({
				url : 'elfinder-servlet/connector',
			});
		});
	</script>

in your web.xml, following codes should be added to enable the servlet:

<servlet>
	<servlet-name>elfinder</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet
	</servlet-class>
</servlet>

<servlet-mapping>
	<servlet-name>elfinder</servlet-name>
	<url-pattern>/elfinder-servlet/*</url-pattern>
</servlet-mapping>

yes! elfinder-2.x-servlet is developed upon SpringFramework (http://springframework.org)

an example elfinder-servlet.xml configuration is shown below:

<!-- find appropriate  command executor for given command-->
<bean id="commandExecutorFactory"
	class="org.grapheco.elfinder.controller.executor.DefaultCommandExecutorFactory">
	<property name="classNamePattern"
		value="org.grapheco.elfinder.controller.executors.%sCommandExecutor" />
	<property name="map">
		<map>
		<!-- 
			<entry key="tree">
				<bean class="org.grapheco.elfinder.controller.executors.TreeCommandExecutor" />
			</entry>
		-->
		</map>
	</property>
</bean>

<!-- FsService is often retrieved from HttpRequest -->
<!-- while a static FsService is defined here -->
<bean id="fsServiceFactory" class="org.grapheco.elfinder.impl.StaticFsServiceFactory">
	<property name="fsService">
		<bean class="org.grapheco.elfinder.impl.DefaultFsService">
			<property name="serviceConfig">
				<bean class="org.grapheco.elfinder.impl.DefaultFsServiceConfig">
					<property name="tmbWidth" value="80" />
				</bean>
			</property>
			<property name="volumeMap">
				<!-- two volumes are mounted here -->
				<map>
					<entry key="A">
						<bean class="org.grapheco.elfinder.localfs.LocalFsVolume">
							<property name="name" value="MyFiles" />
							<property name="rootDir" value="/tmp/a" />
						</bean>
					</entry>
					<entry key="B">
						<bean class="org.grapheco.elfinder.localfs.LocalFsVolume">
							<property name="name" value="Shared" />
							<property name="rootDir" value="/tmp/b" />
						</bean>
					</entry>
				</map>
			</property>
			<property name="securityChecker">
				<bean class="org.grapheco.elfinder.impl.FsSecurityCheckerChain">
					<property name="filterMappings">
						<list>
							<bean class="org.grapheco.elfinder.impl.FsSecurityCheckFilterMapping">
								<property name="pattern" value="A_.*" />
								<property name="checker">
									<bean class="org.grapheco.elfinder.impl.FsSecurityCheckForAll">
										<property name="readable" value="true" />
										<property name="writable" value="true" />
									</bean>
								</property>
							</bean>
							<bean class="org.grapheco.elfinder.impl.FsSecurityCheckFilterMapping">
								<property name="pattern" value="B_.*" />
								<property name="checker">
									<bean class="org.grapheco.elfinder.impl.FsSecurityCheckForAll">
										<property name="readable" value="true" />
										<property name="writable" value="false" />
									</bean>
								</property>
							</bean>
						</list>
					</property>
				</bean>
			</property>
		</bean>
	</property>
</bean>

A ConnectorServlet is provided for people who do not use spring framework:

<servlet>
	<servlet-name>elfinder-connector-servlet</servlet-name>
	<servlet-class>org.grapheco.elfinder.servlet.ConnectorServlet
	</servlet-class>
</servlet>
<servlet-mapping>
	<servlet-name>elfinder-connector-servlet</servlet-name>
	<url-pattern>/elfinder-servlet/connector</url-pattern>
</servlet-mapping>

If you want to customize behavior of ConnectorServlet(see https://github.com/bluejoe2008/elfinder-2.x-servlet/blob/0.9/src/main/java/cn/bluejoe/elfinder/servlet/ConnectorServlet.java), you may need to create a derivided servlet class based on ConnectorServlet.

features

  • easy to use: just define a servlet in your web.xml, or configure the XML file in spring IOC format, and then start your web application
  • easy to import: an artifact on the central repostory is provided, use maven to manage the dependency
  • logic file views: a local file system is not necessary, you can define your FsService
  • easy to personalize: different file views are allowed for different users, just provide a custom FsServiceFactory
  • easy to modify and extend: provide your own CommandExecutors to respond new commands

Command, CommandExecutor, CommandExecutorManager

elfinder-2.x-servlet implements file management commands including:

  • DIM
  • DUPLICATE
  • FILE
  • GET
  • LS
  • MKDIR
  • MKFILE
  • OPEN
  • PARENT
  • PASTE
  • PUT
  • RENAME
  • RM
  • SEARCH
  • SIZE
  • TMB
  • TREE
  • UPLOAD(CHUNK supported!!!)

Each command corresponds to a CommandExecutor class, for example, the TREE command is implemented by the class TreeCommandExecutor(see https://github.com/bluejoe2008/elfinder-2.x-servlet/src/main/java/cn/bluejoe/elfinder/controller/executors/TreeCommandExecutor.java). Users can modify existing class or entend new executor class by following this naming rule.

Furthermore, this rule can even be modified via setting the commandExecutorFactory in elfinder-servlet.xml, in which default factory is DefaultCommandExecutorFactory(see https://github.com/bluejoe2008/elfinder-2.x-servlet/src/main/java/cn/bluejoe/elfinder/controller/executor/DefaultCommandExecutorFactory.java). A CommandExecutorFactory tells how to locate the command executor(TreeCommandExecutor as an example) by a given command name("TREE" as an example), it is designed as an interface:

public interface CommandExecutorFactory
{
	CommandExecutor get(String commandName);
}

FsItem, FsVolume, FsService, FsServiceFactory

Each file is represented as a FsItem. And the root of a file is represented as a FsVolume. A FsVolume tells parent-children relations between all FsItems and implements all file operation (for example, create/delete).

A FsService may have many FsVolumes. Users can create a FsService via a FsServiceFactory:

public interface FsServiceFactory
{
	FsService getFileService(HttpServletRequest request, ServletContext servletContext);
}

A simple (and stupid) StaticFsServiceFactory is provided in https://github.com/bluejoe2008/elfinder-2.x-servlet/src/main/java/cn/bluejoe/elfinder/impl/StaticFsServiceFactory.java, which always returns a fixed FsService, despite of whatever it is requested. However, sometimes a FsService should be constructed dynamically according to current Web request. For example, users may own separated file spaces in a network disk service platform, in this case, getFileService() get user principal from current request and offers him/her different file view.

elfinder-2.x-servlet's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elfinder-2.x-servlet's Issues

IE Drop file(s) for upload does not work

The Drop of file(s) for IE (11) does not work while Chrome does.

Class: UploadCommandExecutor.java

For the file droped: (ex. "C:\temp\abc.txt"):
Chrome: fileName = "abc.txt"
IE: fileName = "C:\temp\abc.txt"

Temporary fix: Always try to get only the filename.

    // OLD: String fileName = fis.getName();
    // OLD: FsItemEx newFile = new FsItemEx(dir, fileName);
    java.nio.file.Path p = java.nio.file.Paths.get(fis.getName());
    FsItemEx newFile = new FsItemEx(dir, p.getFileName().toString());

Note: Could it be fixed at higher level like javascript?

Error uploading a file, "java.io.IOException: charsetName"

Cannot upload a file. A error dialog is displayed stating "Unable to connect to backend". Tried running on both Tomcat 7.0.59 and JBoss EAP 6.3. The server logs the following error:

2015-04-10 07:56:57,844 [http-bio-8080-exec-2] DEBUG [org.springframework.web.bind.annotation.support.HandlerMethodInvoker] - Invoking request handler method: public void cn.bluejoe.elfinder.controller.ConnectorController.connector(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2015-04-10 07:56:57,845 [http-bio-8080-exec-2] DEBUG [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver] - Resolving exception from handler [cn.bluejoe.elfinder.controller.ConnectorController@7939de8b]: java.io.IOException: charsetName
2015-04-10 07:56:57,845 [http-bio-8080-exec-2] DEBUG [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver] - Resolving exception from handler [cn.bluejoe.elfinder.controller.ConnectorController@7939de8b]: java.io.IOException: charsetName
2015-04-10 07:56:57,846 [http-bio-8080-exec-2] DEBUG [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] - Resolving exception from handler [cn.bluejoe.elfinder.controller.ConnectorController@7939de8b]: java.io.IOException: charsetName
2015-04-10 07:56:57,847 [http-bio-8080-exec-2] DEBUG [org.springframework.web.servlet.DispatcherServlet] - Could not complete request
java.io.IOException: charsetName
at cn.bluejoe.elfinder.controller.ConnectorController.connector(ConnectorController.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

File Upload failed from IE browser

Hi,
There's a npe when uploading file from IE (11) browser.
see stacktrace (french logs !) :
java.io.IOException: La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at cn.bluejoe.elfinder.localfs.LocalFsVolume.createFile(LocalFsVolume.java:43)
at cn.bluejoe.elfinder.controller.executor.FsItemEx.createFile(FsItemEx.java:65)
at cn.bluejoe.elfinder.controller.executors.UploadCommandExecutor.execute(UploadCommandExecutor.java:40)
at cn.bluejoe.elfinder.controller.executor.AbstractJsonCommandExecutor.execute(AbstractJsonCommandExecutor.java:24)
at cn.bluejoe.elfinder.controller.executor.AbstractCommandExecutor.execute(AbstractCommandExecutor.java:102)
at cn.bluejoe.elfinder.controller.ConnectorController.connector(ConnectorController.java:67)
at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

After debugging, the problem is that IE give for the file name the full path of the file. With Chrome just the filename is sent.
The problem is on UploadCommandExecutor (line 38) : String fileName = fis.getName(); is set with the fullpath instead of only the file name.

Hope this helps and fix will come :-)

Regards.

Unable to connect backend

I have implemented elfinder with jar file of this same project. and implemented connector perfectly. But sometimes it is giving me above error with HTTP error 404 . and sometimes works perfect.
Where can I be wrong? And where could be file saved in my system if I have uploaded from elfinder

Integration Elfinder Connector with CKEditor

Hello, I'm trying to call connector from CKEditor with Elfinder , editing the config.js of Ckeditor ( I follow https://github.com/Studio-42/elFinder/wiki/Integration-with-CKEditor and http://docs-old.ckeditor.com/CKEditor_3.x/Developers_Guide/File_Browser_(Uploader) )
But when I click on "Send to server" of CKEditor I have target == null

CKEDITOR.replace( 'editor1',
{
config.filebrowserBrowseUrl = '/myapp/elFinder/elfinder-cke.html';
config.filebrowserImageBrowseUrl = '/myapp/elFinder/elfinder-cke.html';
config.filebrowserUploadUrl = '/myapp/elfinder-servlet/connector?cmd=upload';
config.filebrowserImageUploadUrl = '/myapp/elfinder-servlet/connector?cmd=upload';
});

Anyone integrate elfinder in ckeditor?
thank a lots

No server side filtering by mime type

There is a client-side option in elFinder that allows one to filter the results by mime:

{
  // ...
  // Restrict to images and flash files
  onlyMimes: ['image', 'application/x-shockwave-flash']
  // ...
}

Each option in the onlyMimes array is sent on the server-side URL requests, e.g:

?mimes[]=image&mimes[]=application%2Fx-shockwave-flash&cmd=open&target=SOMEHASH&init=1&tree=1

This servlet doesn't yet support the client-side filtering (i.e. no matter what you give to the onlyMimes array, all files are returned in response JSONs).

The exec command in the elFinder PHP class seems to take the mimes array and set the filter. Not sure where this would need to be implemented in the Java servlet.

Use elFinder without XML configuration

Wouldn't it be nice to use elFinder by just adding a maven depency and a single initialisation in the code, so without all the xml-config? Spring can work without them.

I am not sure if this is something you want, but just a suggestion

上传文件夹问题

上传多个文件夹时, 会合成一个名叫null文件夹,所有文件都混在同一个文件夹内
dv5 jme89m5cslnt7e giac
su oitl6 dwtc1 o x0f2p

Make maven artifact release

For inclusion into the Sakai project it would be helpful if this project was released as a maven artifact so that Sakai builds could depend on it and download it, rather than including a copy of the elfinder code in the Sakai codebase.

The alternative is that we have a Sakai fork, which we release to the Sonatype repository.

Do you have any preferences?

Maven问题

不知道为什么maven的1.1版本我在maven中心库里面搜索出来是war包的,不知道怎么导入,求指导

mvn install 报错

executors/PasteCommandExecutor.java:[28,54] -source 1.6 中不支持 diamond 运算符
[ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.