├── 23205811_gr0b.png
├── 23205833_rxSV.png
├── src
└── main
│ ├── java
│ └── org
│ │ └── grapheco
│ │ └── elfinder
│ │ ├── service
│ │ ├── FsItem.java
│ │ ├── FsServiceConfig.java
│ │ ├── FsSecurityChecker.java
│ │ ├── FsItemFilter.java
│ │ ├── FsServiceFactory.java
│ │ ├── FsService.java
│ │ └── FsVolume.java
│ │ ├── controller
│ │ ├── executor
│ │ │ ├── CommandExecutorFactory.java
│ │ │ ├── CommandExecutor.java
│ │ │ ├── CommandExecutionContext.java
│ │ │ ├── DefaultCommandExecutorFactory.java
│ │ │ ├── AbstractJsonCommandExecutor.java
│ │ │ ├── FsItemEx.java
│ │ │ └── AbstractCommandExecutor.java
│ │ ├── FsException.java
│ │ ├── executors
│ │ │ ├── MissingCommandExecutor.java
│ │ │ ├── SearchCommandExecutor.java
│ │ │ ├── MkdirCommandExecutor.java
│ │ │ ├── GetCommandExecutor.java
│ │ │ ├── PutCommandExecutor.java
│ │ │ ├── TreeCommandExecutor.java
│ │ │ ├── SizeCommandExecutor.java
│ │ │ ├── LsCommandExecutor.java
│ │ │ ├── RenameCommandExecutor.java
│ │ │ ├── RmCommandExecutor.java
│ │ │ ├── MkfileCommandExecutor.java
│ │ │ ├── ParentsCommandExecutor.java
│ │ │ ├── PasteCommandExecutor.java
│ │ │ ├── OpenCommandExecutor.java
│ │ │ ├── DuplicateCommandExecutor.java
│ │ │ ├── TmbCommandExecutor.java
│ │ │ ├── DimCommandExecutor.java
│ │ │ ├── FileCommandExecutor.java
│ │ │ └── UploadCommandExecutor.java
│ │ ├── ErrorException.java
│ │ ├── MultipleUploadItems.java
│ │ └── ConnectorController.java
│ │ ├── impl
│ │ ├── DefaultFsServiceConfig.java
│ │ ├── FsSecurityCheckFilterMapping.java
│ │ ├── StaticFsServiceFactory.java
│ │ ├── FsSecurityCheckForAll.java
│ │ ├── FsSecurityCheckerChain.java
│ │ └── DefaultFsService.java
│ │ ├── util
│ │ ├── FsServiceUtils.java
│ │ ├── MimeTypesUtils.java
│ │ └── FsItemFilterUtils.java
│ │ ├── localfs
│ │ ├── LocalFsItem.java
│ │ └── LocalFsVolume.java
│ │ └── servlet
│ │ └── ConnectorServlet.java
│ ├── resources
│ ├── log4j.properties
│ └── mime.types
│ └── webapp
│ ├── WEB-INF
│ ├── web.xml
│ ├── web.xml.1
│ └── elfinder-servlet.xml
│ └── index.html
├── .gitattributes
├── .github
└── FUNDING.yml
├── LICENSE
├── .gitignore
├── pom.xml
└── README.md
/23205811_gr0b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bluejoe2008/elfinder-2.x-servlet/HEAD/23205811_gr0b.png
--------------------------------------------------------------------------------
/23205833_rxSV.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bluejoe2008/elfinder-2.x-servlet/HEAD/23205833_rxSV.png
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsItem.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | public interface FsItem
4 | {
5 | FsVolume getVolume();
6 | }
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsServiceConfig.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | public interface FsServiceConfig
4 | {
5 | int getTmbWidth();
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | public interface CommandExecutorFactory
4 | {
5 | CommandExecutor get(String commandName);
6 | }
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | public interface CommandExecutor
4 | {
5 | void execute(CommandExecutionContext commandExecutionContext)
6 | throws Exception;
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/FsException.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller;
2 |
3 | import java.io.IOException;
4 |
5 | public class FsException extends IOException
6 | {
7 |
8 | public FsException(String message)
9 | {
10 | super(message);
11 | }
12 |
13 | public FsException(String message, Throwable e)
14 | {
15 | super(message, e);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsSecurityChecker.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | import java.io.IOException;
4 |
5 | public interface FsSecurityChecker
6 | {
7 |
8 | boolean isLocked(FsService fsService, FsItem fsi) throws IOException;
9 |
10 | boolean isReadable(FsService fsService, FsItem fsi) throws IOException;
11 |
12 | boolean isWritable(FsService fsService, FsItem fsi) throws IOException;
13 |
14 | }
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/impl/DefaultFsServiceConfig.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.impl;
2 |
3 | import org.grapheco.elfinder.service.FsServiceConfig;
4 |
5 | public class DefaultFsServiceConfig implements FsServiceConfig
6 | {
7 | private int _tmbWidth;
8 |
9 | public void setTmbWidth(int tmbWidth)
10 | {
11 | _tmbWidth = tmbWidth;
12 | }
13 |
14 | @Override
15 | public int getTmbWidth()
16 | {
17 | return _tmbWidth;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Custom for Visual Studio
2 | *.cs diff=csharp
3 | *.sln merge=union
4 | *.csproj merge=union
5 | *.vbproj merge=union
6 | *.fsproj merge=union
7 | *.dbproj merge=union
8 |
9 | # Standard to msysgit
10 | *.doc diff=astextplain
11 | *.DOC diff=astextplain
12 | *.docx diff=astextplain
13 | *.DOCX diff=astextplain
14 | *.dot diff=astextplain
15 | *.DOT diff=astextplain
16 | *.pdf diff=astextplain
17 | *.PDF diff=astextplain
18 | *.rtf diff=astextplain
19 | *.RTF diff=astextplain
20 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsItemFilter.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | import org.grapheco.elfinder.controller.executor.FsItemEx;
4 |
5 | /**
6 | * A FsItemFilter tells if a FsItem is matched or not
7 | *
8 | * @author bluejoe
9 | *
10 | */
11 | public interface FsItemFilter
12 | {
13 | // TODO: bad designs: FsItemEx should not used here
14 | // top level interfaces should only know FsItem instead of FsItemEx
15 | public boolean accepts(FsItemEx item);
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Output pattern : date [thread] priority category - message
2 | log4j.rootLogger=INFO,Console
3 |
4 | #Console
5 | log4j.appender.Console=org.apache.log4j.ConsoleAppender
6 | log4j.appender.Console.Threshold=DEBUG
7 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout
8 | log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
9 |
10 | #Project default level
11 | log4j.logger.org.grapheco.elfinder=DEBUG
12 | log4j.logger.net.sf=INFO
13 | log4j.logger.org.apache=INFO
14 | log4j.logger.org.springframework=INFO
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 |
7 | import org.grapheco.elfinder.service.FsServiceFactory;
8 |
9 | public interface CommandExecutionContext
10 | {
11 | FsServiceFactory getFsServiceFactory();
12 |
13 | HttpServletRequest getRequest();
14 |
15 | HttpServletResponse getResponse();
16 |
17 | ServletContext getServletContext();
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.util;
2 |
3 | import java.io.IOException;
4 |
5 | import org.grapheco.elfinder.controller.executor.FsItemEx;
6 | import org.grapheco.elfinder.service.FsItem;
7 | import org.grapheco.elfinder.service.FsService;
8 |
9 | public abstract class FsServiceUtils
10 | {
11 | public static FsItemEx findItem(FsService fsService, String hash)
12 | throws IOException
13 | {
14 | FsItem fsi = fsService.fromHash(hash);
15 | if (fsi == null)
16 | {
17 | return null;
18 | }
19 |
20 | return new FsItemEx(fsi, fsService);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | index.html
5 | index.jsp
6 |
7 |
8 |
9 |
10 |
11 | elfinder
12 | org.springframework.web.servlet.DispatcherServlet
13 |
14 |
15 |
16 | elfinder
17 | /elfinder-servlet/*
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: https://bluejoe2008.github.io/open-source-sponser.png
13 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml.1:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | index.html
5 | index.jsp
6 |
7 |
8 |
9 |
10 |
11 | elfinder-connector-servlet
12 | org.grapheco.elfinder.servlet.ConnectorServlet
13 |
14 |
15 |
16 | elfinder-connector-servlet
17 | /elfinder-servlet/connector
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/impl/FsSecurityCheckFilterMapping.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.impl;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | import org.grapheco.elfinder.service.FsSecurityChecker;
6 |
7 | public class FsSecurityCheckFilterMapping
8 | {
9 | FsSecurityChecker _checker;
10 |
11 | String _pattern;
12 |
13 | public FsSecurityChecker getChecker()
14 | {
15 | return _checker;
16 | }
17 |
18 | public String getPattern()
19 | {
20 | return _pattern;
21 | }
22 |
23 | public boolean matches(String hash)
24 | {
25 | return Pattern.compile(_pattern).matcher(hash).matches();
26 | }
27 |
28 | public void setChecker(FsSecurityChecker checker)
29 | {
30 | _checker = checker;
31 | }
32 |
33 | public void setPattern(String pattern)
34 | {
35 | _pattern = pattern;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/localfs/LocalFsItem.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.localfs;
2 |
3 | import java.io.File;
4 |
5 | import org.grapheco.elfinder.service.FsItem;
6 | import org.grapheco.elfinder.service.FsVolume;
7 |
8 | public class LocalFsItem implements FsItem
9 | {
10 | File _file;
11 |
12 | FsVolume _volume;
13 |
14 | public LocalFsItem(LocalFsVolume volume, File file)
15 | {
16 | super();
17 | _volume = volume;
18 | _file = file;
19 | }
20 |
21 | public File getFile()
22 | {
23 | return _file;
24 | }
25 |
26 | public FsVolume getVolume()
27 | {
28 | return _volume;
29 | }
30 |
31 | public void setFile(File file)
32 | {
33 | _file = file;
34 | }
35 |
36 | public void setVolume(FsVolume volume)
37 | {
38 | _volume = volume;
39 | }
40 |
41 | @Override
42 | public String toString()
43 | {
44 | return "LocalFsVolume [" + _file + "]";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/impl/StaticFsServiceFactory.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.impl;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.grapheco.elfinder.service.FsService;
7 | import org.grapheco.elfinder.service.FsServiceFactory;
8 |
9 | /**
10 | * A StaticFsServiceFactory always returns one FsService, despite of whatever it
11 | * is requested
12 | *
13 | * @author bluejoe
14 | *
15 | */
16 | public class StaticFsServiceFactory implements FsServiceFactory
17 | {
18 | FsService _fsService;
19 |
20 | @Override
21 | public FsService getFileService(HttpServletRequest request,
22 | ServletContext servletContext)
23 | {
24 | return _fsService;
25 | }
26 |
27 | public FsService getFsService()
28 | {
29 | return _fsService;
30 | }
31 |
32 | public void setFsService(FsService fsService)
33 | {
34 | _fsService = fsService;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | /**
7 | * a factory which creates FsServices
8 | *
9 | * @author bluejoe
10 | *
11 | */
12 | public interface FsServiceFactory
13 | {
14 | /**
15 | * sometimes a FsService should be constructed dynamically according to
16 | * current web request. e.g users may own separated file spaces in a net
17 | * disk service platform, in this case, getFileService() get user principal
18 | * from current request and offers him/her different file view.
19 | *
20 | * @param request
21 | * The current HttpServletRequest.
22 | * @param servletContext
23 | * The servlet context.
24 | * @return The {@link FsService} for the current request.
25 | */
26 | FsService getFileService(HttpServletRequest request,
27 | ServletContext servletContext);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/MissingCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.grapheco.elfinder.controller.ErrorException;
7 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
8 | import org.json.JSONObject;
9 |
10 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
11 | import org.grapheco.elfinder.service.FsService;
12 |
13 | /**
14 | * This is a command that should be executed when a matching command can't be
15 | * found.
16 | */
17 | public class MissingCommandExecutor extends AbstractJsonCommandExecutor
18 | implements CommandExecutor
19 | {
20 | @Override
21 | protected void execute(FsService fsService, HttpServletRequest request,
22 | ServletContext servletContext, JSONObject json) throws Exception
23 | {
24 | String cmd = request.getParameter("cmd");
25 | throw new ErrorException("errUnknownCmd", cmd);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/ErrorException.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller;
2 |
3 | /**
4 | * This Exception is thrown when the implementation can't complete and wants to
5 | * return an error to the client.
6 | */
7 | public class ErrorException extends RuntimeException
8 | {
9 |
10 | private final String error;
11 | private final String[] args;
12 |
13 | /**
14 | * See /elfinder/js/i18n/elfinder.??.js for error codes.
15 | *
16 | * @param error
17 | * The error code.
18 | * @param args
19 | * Any arguments needed by the error message.
20 | */
21 | public ErrorException(String error, String... args)
22 | {
23 | this.error = error;
24 | this.args = args;
25 | }
26 |
27 | /**
28 | * @return The error code that will translated by elfinder to a nice
29 | * message.
30 | */
31 | public String getError()
32 | {
33 | return error;
34 | }
35 |
36 | /**
37 | * @return The arguments needed by the error message.
38 | */
39 | public String[] getArgs()
40 | {
41 | return args;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/SearchCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
7 | import org.grapheco.elfinder.util.FsItemFilterUtils;
8 | import org.json.JSONObject;
9 |
10 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
11 | import org.grapheco.elfinder.service.FsService;
12 |
13 | public class SearchCommandExecutor extends AbstractJsonCommandExecutor
14 | implements CommandExecutor
15 | {
16 | @Override
17 | public void execute(FsService fsService, HttpServletRequest request,
18 | ServletContext servletContext, JSONObject json) throws Exception
19 | {
20 | json.put(
21 | "files",
22 | files2JsonArray(request, FsItemFilterUtils.filterFiles(
23 | fsService.find(FsItemFilterUtils
24 | .createFileNameKeywordFilter(request
25 | .getParameter("q"))), super
26 | .getRequestedFilter(request))));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsService.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | import java.io.IOException;
4 |
5 | import org.grapheco.elfinder.controller.executor.FsItemEx;
6 |
7 | public interface FsService
8 | {
9 | FsItem fromHash(String hash) throws IOException;
10 |
11 | String getHash(FsItem item) throws IOException;
12 |
13 | FsSecurityChecker getSecurityChecker();
14 |
15 | String getVolumeId(FsVolume volume);
16 |
17 | FsVolume[] getVolumes();
18 |
19 | FsServiceConfig getServiceConfig();
20 |
21 | /**
22 | * find files by name pattern, this provides a simple recursively iteration
23 | * based method lucene engines can be introduced to improve it! This
24 | * searches across all volumes.
25 | *
26 | * @param filter
27 | * The filter to apply to select files.
28 | * @return A collection of files that match the filter and gave the root as
29 | * a parent.
30 | */
31 | // TODO: bad designs: FsItemEx should not used here top level interfaces
32 | // should only know FsItem instead of FsItemEx
33 | FsItemEx[] find(FsItemFilter filter);
34 | }
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/MkdirCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.json.JSONObject;
7 |
8 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
9 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
10 | import org.grapheco.elfinder.controller.executor.FsItemEx;
11 | import org.grapheco.elfinder.service.FsService;
12 |
13 | public class MkdirCommandExecutor extends AbstractJsonCommandExecutor implements
14 | CommandExecutor
15 | {
16 | @Override
17 | public void execute(FsService fsService, HttpServletRequest request,
18 | ServletContext servletContext, JSONObject json) throws Exception
19 | {
20 | String target = request.getParameter("target");
21 | String name = request.getParameter("name");
22 |
23 | FsItemEx fsi = super.findItem(fsService, target);
24 | FsItemEx dir = new FsItemEx(fsi, name);
25 | dir.createFolder();
26 |
27 | json.put("added", new Object[] { getFsItemInfo(request, dir) });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/GetCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.io.InputStream;
4 |
5 | import javax.servlet.ServletContext;
6 | import javax.servlet.http.HttpServletRequest;
7 |
8 | import org.apache.commons.io.IOUtils;
9 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
10 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
11 | import org.grapheco.elfinder.controller.executor.FsItemEx;
12 | import org.json.JSONObject;
13 |
14 | import org.grapheco.elfinder.service.FsService;
15 |
16 | public class GetCommandExecutor extends AbstractJsonCommandExecutor implements
17 | CommandExecutor
18 | {
19 | @Override
20 | public void execute(FsService fsService, HttpServletRequest request,
21 | ServletContext servletContext, JSONObject json) throws Exception
22 | {
23 | String target = request.getParameter("target");
24 |
25 | FsItemEx fsi = super.findItem(fsService, target);
26 | InputStream is = fsi.openInputStream();
27 | String content = IOUtils.toString(is, "utf-8");
28 | is.close();
29 | json.put("content", content);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/PutCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.io.ByteArrayInputStream;
4 |
5 | import javax.servlet.ServletContext;
6 | import javax.servlet.http.HttpServletRequest;
7 |
8 | import org.json.JSONObject;
9 |
10 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
11 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
12 | import org.grapheco.elfinder.controller.executor.FsItemEx;
13 | import org.grapheco.elfinder.service.FsService;
14 |
15 | public class PutCommandExecutor extends AbstractJsonCommandExecutor implements
16 | CommandExecutor
17 | {
18 | @Override
19 | public void execute(FsService fsService, HttpServletRequest request,
20 | ServletContext servletContext, JSONObject json) throws Exception
21 | {
22 | String target = request.getParameter("target");
23 |
24 | FsItemEx fsi = super.findItem(fsService, target);
25 | fsi.writeStream(new ByteArrayInputStream(request
26 | .getParameter("content").getBytes("utf-8")));
27 | json.put("changed", new Object[] { super.getFsItemInfo(request, fsi) });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/TreeCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.json.JSONObject;
10 |
11 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
12 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
13 | import org.grapheco.elfinder.controller.executor.FsItemEx;
14 | import org.grapheco.elfinder.service.FsService;
15 |
16 | public class TreeCommandExecutor extends AbstractJsonCommandExecutor implements
17 | CommandExecutor
18 | {
19 | @Override
20 | public void execute(FsService fsService, HttpServletRequest request,
21 | ServletContext servletContext, JSONObject json) throws Exception
22 | {
23 | String target = request.getParameter("target");
24 |
25 | Map files = new HashMap();
26 | FsItemEx fsi = super.findItem(fsService, target);
27 | super.addSubfolders(files, fsi);
28 |
29 | json.put("tree", files2JsonArray(request, files.values()));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/SizeCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.json.JSONObject;
7 |
8 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
9 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
10 | import org.grapheco.elfinder.controller.executor.FsItemEx;
11 | import org.grapheco.elfinder.service.FsService;
12 |
13 | /**
14 | * This calculates the total size of all the supplied targets and returns the
15 | * size in bytes.
16 | */
17 | public class SizeCommandExecutor extends AbstractJsonCommandExecutor implements
18 | CommandExecutor
19 | {
20 | @Override
21 | protected void execute(FsService fsService, HttpServletRequest request,
22 | ServletContext servletContext, JSONObject json) throws Exception
23 | {
24 | String[] targets = request.getParameterValues("targets[]");
25 | long size = 0;
26 | for (String target : targets)
27 | {
28 | FsItemEx item = findItem(fsService, target);
29 | size += item.getSize();
30 | }
31 | json.put("size", size);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/LsCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
10 | import org.json.JSONObject;
11 |
12 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
13 | import org.grapheco.elfinder.controller.executor.FsItemEx;
14 | import org.grapheco.elfinder.service.FsService;
15 |
16 | public class LsCommandExecutor extends AbstractJsonCommandExecutor implements
17 | CommandExecutor
18 | {
19 | @Override
20 | public void execute(FsService fsService, HttpServletRequest request,
21 | ServletContext servletContext, JSONObject json) throws Exception
22 | {
23 | String target = request.getParameter("target");
24 | String[] onlyMimes = request.getParameterValues("mimes[]");
25 |
26 | Map files = new HashMap();
27 | FsItemEx fsi = super.findItem(fsService, target);
28 | super.addChildren(files, fsi, onlyMimes);
29 |
30 | json.put("list", files2JsonArray(request, files.values()));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/RenameCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
7 | import org.json.JSONObject;
8 |
9 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
10 | import org.grapheco.elfinder.controller.executor.FsItemEx;
11 | import org.grapheco.elfinder.service.FsService;
12 |
13 | public class RenameCommandExecutor extends AbstractJsonCommandExecutor
14 | implements CommandExecutor
15 | {
16 | @Override
17 | public void execute(FsService fsService, HttpServletRequest request,
18 | ServletContext servletContext, JSONObject json) throws Exception
19 | {
20 | String target = request.getParameter("target");
21 | String current = request.getParameter("current");
22 | String name = request.getParameter("name");
23 |
24 | FsItemEx fsi = super.findItem(fsService, target);
25 | FsItemEx dst = new FsItemEx(fsi.getParent(), name);
26 | fsi.renameTo(dst);
27 |
28 | json.put("added", new Object[] { getFsItemInfo(request, dst) });
29 | json.put("removed", new String[] { target });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/RmCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
10 | import org.json.JSONObject;
11 |
12 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
13 | import org.grapheco.elfinder.controller.executor.FsItemEx;
14 | import org.grapheco.elfinder.service.FsService;
15 |
16 | public class RmCommandExecutor extends AbstractJsonCommandExecutor implements
17 | CommandExecutor
18 | {
19 | @Override
20 | public void execute(FsService fsService, HttpServletRequest request,
21 | ServletContext servletContext, JSONObject json) throws Exception
22 | {
23 | String[] targets = request.getParameterValues("targets[]");
24 | String current = request.getParameter("current");
25 | List removed = new ArrayList();
26 |
27 | for (String target : targets)
28 | {
29 | FsItemEx ftgt = super.findItem(fsService, target);
30 | ftgt.delete();
31 | removed.add(ftgt.getHash());
32 | }
33 |
34 | json.put("removed", removed.toArray());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/impl/FsSecurityCheckForAll.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.impl;
2 |
3 | import org.grapheco.elfinder.service.FsItem;
4 | import org.grapheco.elfinder.service.FsSecurityChecker;
5 | import org.grapheco.elfinder.service.FsService;
6 |
7 | public class FsSecurityCheckForAll implements FsSecurityChecker
8 | {
9 | boolean _locked = false;
10 |
11 | boolean _readable = true;
12 |
13 | boolean _writable = true;
14 |
15 | public boolean isLocked()
16 | {
17 | return _locked;
18 | }
19 |
20 | @Override
21 | public boolean isLocked(FsService fsService, FsItem fsi)
22 | {
23 | return _locked;
24 | }
25 |
26 | public boolean isReadable()
27 | {
28 | return _readable;
29 | }
30 |
31 | @Override
32 | public boolean isReadable(FsService fsService, FsItem fsi)
33 | {
34 | return _readable;
35 | }
36 |
37 | public boolean isWritable()
38 | {
39 | return _writable;
40 | }
41 |
42 | @Override
43 | public boolean isWritable(FsService fsService, FsItem fsi)
44 | {
45 | return _writable;
46 | }
47 |
48 | public void setLocked(boolean locked)
49 | {
50 | _locked = locked;
51 | }
52 |
53 | public void setReadable(boolean readable)
54 | {
55 | _readable = readable;
56 | }
57 |
58 | public void setWritable(boolean writable)
59 | {
60 | _writable = writable;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/MkfileCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 |
6 | import org.json.JSONObject;
7 |
8 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
9 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
10 | import org.grapheco.elfinder.controller.executor.FsItemEx;
11 | import org.grapheco.elfinder.service.FsItemFilter;
12 | import org.grapheco.elfinder.service.FsService;
13 |
14 | public class MkfileCommandExecutor extends AbstractJsonCommandExecutor
15 | implements CommandExecutor
16 | {
17 | @Override
18 | public void execute(FsService fsService, HttpServletRequest request,
19 | ServletContext servletContext, JSONObject json) throws Exception
20 | {
21 | String target = request.getParameter("target");
22 | String name = request.getParameter("name");
23 |
24 | FsItemEx fsi = super.findItem(fsService, target);
25 | FsItemEx dir = new FsItemEx(fsi, name);
26 | dir.createFile();
27 |
28 | // if the new file is allowed to be display?
29 | FsItemFilter filter = getRequestedFilter(request);
30 | json.put(
31 | "added",
32 | filter.accepts(dir) ? new Object[] { getFsItemInfo(request, dir) }
33 | : new Object[0]);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, shen zhihong
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
25 |
--------------------------------------------------------------------------------
/src/main/webapp/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | elFinder 2.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/DefaultCommandExecutorFactory.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class DefaultCommandExecutorFactory implements CommandExecutorFactory
7 | {
8 | String _classNamePattern;
9 |
10 | private Map _map = new HashMap();
11 |
12 | private CommandExecutor _fallbackCommand;
13 |
14 | @Override
15 | public CommandExecutor get(String commandName)
16 | {
17 | if (_map.containsKey(commandName))
18 | return _map.get(commandName);
19 |
20 | try
21 | {
22 | String className = String.format(_classNamePattern, commandName
23 | .substring(0, 1).toUpperCase() + commandName.substring(1));
24 | return (CommandExecutor) Class.forName(className).newInstance();
25 | }
26 | catch (Exception e)
27 | {
28 | // not found
29 | return _fallbackCommand;
30 | }
31 | }
32 |
33 | public String getClassNamePattern()
34 | {
35 | return _classNamePattern;
36 | }
37 |
38 | public Map getMap()
39 | {
40 | return _map;
41 | }
42 |
43 | public CommandExecutor getFallbackCommand()
44 | {
45 | return _fallbackCommand;
46 | }
47 |
48 | public void setClassNamePattern(String classNamePattern)
49 | {
50 | _classNamePattern = classNamePattern;
51 | }
52 |
53 | public void setMap(Map map)
54 | {
55 | _map = map;
56 | }
57 |
58 | public void setFallbackCommand(CommandExecutor fallbackCommand)
59 | {
60 | this._fallbackCommand = fallbackCommand;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/ParentsCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.grapheco.elfinder.controller.ErrorException;
10 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
11 | import org.json.JSONObject;
12 |
13 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
14 | import org.grapheco.elfinder.controller.executor.FsItemEx;
15 | import org.grapheco.elfinder.service.FsService;
16 |
17 | public class ParentsCommandExecutor extends AbstractJsonCommandExecutor
18 | implements CommandExecutor
19 | {
20 | // This is a limit on the number of parents so that a badly implemented
21 | // FsService can't
22 | // result in a runaway thread.
23 | final static int LIMIT = 1024;
24 |
25 | @Override
26 | public void execute(FsService fsService, HttpServletRequest request,
27 | ServletContext servletContext, JSONObject json) throws Exception
28 | {
29 | String target = request.getParameter("target");
30 |
31 | Map files = new HashMap();
32 | FsItemEx fsi = findItem(fsService, target);
33 | for (int i = 0; !fsi.isRoot(); i++)
34 | {
35 | super.addSubfolders(files, fsi);
36 | fsi = fsi.getParent();
37 | if (i > LIMIT)
38 | {
39 | throw new ErrorException(
40 | "Reached recursion limit on parents of: " + LIMIT);
41 | }
42 | }
43 |
44 | json.put("tree", files2JsonArray(request, files.values()));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/PasteCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.json.JSONObject;
10 |
11 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
12 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
13 | import org.grapheco.elfinder.controller.executor.FsItemEx;
14 | import org.grapheco.elfinder.service.FsService;
15 |
16 | public class PasteCommandExecutor extends AbstractJsonCommandExecutor implements
17 | CommandExecutor
18 | {
19 | @Override
20 | public void execute(FsService fsService, HttpServletRequest request,
21 | ServletContext servletContext, JSONObject json) throws Exception
22 | {
23 | String[] targets = request.getParameterValues("targets[]");
24 | String src = request.getParameter("src");
25 | String dst = request.getParameter("dst");
26 | boolean cut = "1".equals(request.getParameter("cut"));
27 |
28 | List added = new ArrayList<>();
29 | List removed = new ArrayList<>();
30 |
31 | FsItemEx fsrc = super.findItem(fsService, src);
32 | FsItemEx fdst = super.findItem(fsService, dst);
33 |
34 | for (String target : targets)
35 | {
36 | FsItemEx ftgt = super.findItem(fsService, target);
37 | String name = ftgt.getName();
38 | FsItemEx newFile = new FsItemEx(fdst, name);
39 | super.createAndCopy(ftgt, newFile);
40 | added.add(newFile);
41 |
42 | if (cut)
43 | {
44 | ftgt.delete();
45 | removed.add(target);
46 | }
47 | }
48 |
49 | json.put("added", files2JsonArray(request, added));
50 | json.put("removed", removed);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/impl/FsSecurityCheckerChain.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.impl;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import org.grapheco.elfinder.service.FsItem;
7 | import org.grapheco.elfinder.service.FsSecurityChecker;
8 | import org.grapheco.elfinder.service.FsService;
9 |
10 | public class FsSecurityCheckerChain implements FsSecurityChecker
11 | {
12 | private static final FsSecurityChecker DEFAULT_SECURITY_CHECKER = new FsSecurityCheckForAll();
13 |
14 | List _filterMappings;
15 |
16 | private FsSecurityChecker getChecker(FsService fsService, FsItem fsi)
17 | throws IOException
18 | {
19 | String hash = fsService.getHash(fsi);
20 | for (FsSecurityCheckFilterMapping mapping : _filterMappings)
21 | {
22 | if (mapping.matches(hash))
23 | {
24 | return mapping.getChecker();
25 | }
26 | }
27 |
28 | return DEFAULT_SECURITY_CHECKER;
29 | }
30 |
31 | public List getFilterMappings()
32 | {
33 | return _filterMappings;
34 | }
35 |
36 | @Override
37 | public boolean isLocked(FsService fsService, FsItem fsi) throws IOException
38 | {
39 | return getChecker(fsService, fsi).isLocked(fsService, fsi);
40 | }
41 |
42 | @Override
43 | public boolean isReadable(FsService fsService, FsItem fsi)
44 | throws IOException
45 | {
46 | return getChecker(fsService, fsi).isReadable(fsService, fsi);
47 | }
48 |
49 | @Override
50 | public boolean isWritable(FsService fsService, FsItem fsi)
51 | throws IOException
52 | {
53 | return getChecker(fsService, fsi).isWritable(fsService, fsi);
54 | }
55 |
56 | public void setFilterMappings(
57 | List filterMappings)
58 | {
59 | _filterMappings = filterMappings;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/util/MimeTypesUtils.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.util;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | import org.springframework.core.io.ClassPathResource;
11 |
12 | public abstract class MimeTypesUtils
13 | {
14 | private static Map _map;
15 |
16 | public static final String UNKNOWN_MIME_TYPE = "application/oct-stream";
17 |
18 | static
19 | {
20 | _map = new HashMap();
21 | try
22 | {
23 | load();
24 | }
25 | catch (Throwable e)
26 | {
27 | e.printStackTrace();
28 | }
29 | }
30 |
31 | public static String getMimeType(String ext)
32 | {
33 | return _map.get(ext.toLowerCase());
34 | }
35 |
36 | public static boolean isUnknownType(String mime)
37 | {
38 | return mime == null || UNKNOWN_MIME_TYPE.equals(mime);
39 | }
40 |
41 | private static void load() throws IOException
42 | {
43 | InputStream is = new ClassPathResource("/mime.types").getInputStream();
44 | BufferedReader fr = new BufferedReader(new InputStreamReader(is));
45 | String line;
46 | while ((line = fr.readLine()) != null)
47 | {
48 | line = line.trim();
49 | if (line.startsWith("#") || line.isEmpty())
50 | {
51 | continue;
52 | }
53 |
54 | String[] tokens = line.split("\\s+");
55 | if (tokens.length < 2)
56 | continue;
57 |
58 | for (int i = 1; i < tokens.length; i++)
59 | {
60 | putMimeType(tokens[i], tokens[0]);
61 | }
62 | }
63 |
64 | is.close();
65 | }
66 |
67 | public static void putMimeType(String ext, String type)
68 | {
69 | if (ext == null || type == null)
70 | return;
71 |
72 | _map.put(ext.toLowerCase(), type);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/AbstractJsonCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import javax.servlet.ServletContext;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | import org.grapheco.elfinder.controller.ErrorException;
10 | import org.json.JSONArray;
11 | import org.json.JSONObject;
12 |
13 | import org.grapheco.elfinder.service.FsService;
14 |
15 | public abstract class AbstractJsonCommandExecutor extends
16 | AbstractCommandExecutor
17 | {
18 | @Override
19 | final public void execute(FsService fsService, HttpServletRequest request,
20 | HttpServletResponse response, ServletContext servletContext)
21 | throws Exception
22 | {
23 | JSONObject json = new JSONObject();
24 | try
25 | {
26 | execute(fsService, request, servletContext, json);
27 | }
28 | catch (ErrorException e)
29 | {
30 | if (e.getArgs() == null || e.getArgs().length == 0)
31 | {
32 | json.put("error", e.getError());
33 | }
34 | else
35 | {
36 | JSONArray errors = new JSONArray();
37 | errors.put(e.getError());
38 | for (String arg : e.getArgs())
39 | {
40 | errors.put(arg);
41 | }
42 | json.put("error", errors);
43 | }
44 | }
45 | catch (Exception e)
46 | {
47 | e.printStackTrace();
48 | json.put("error", e.getMessage());
49 | }
50 | finally
51 | {
52 | // response.setContentType("application/json; charset=UTF-8");
53 | response.setContentType("text/html; charset=UTF-8");
54 |
55 | PrintWriter writer = response.getWriter();
56 | json.write(writer);
57 | writer.flush();
58 | writer.close();
59 | }
60 | }
61 |
62 | protected abstract void execute(FsService fsService,
63 | HttpServletRequest request, ServletContext servletContext,
64 | JSONObject json) throws Exception;
65 |
66 | }
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/OpenCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
10 | import org.grapheco.elfinder.service.FsVolume;
11 | import org.json.JSONObject;
12 |
13 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
14 | import org.grapheco.elfinder.controller.executor.FsItemEx;
15 | import org.grapheco.elfinder.service.FsService;
16 |
17 | public class OpenCommandExecutor extends AbstractJsonCommandExecutor implements
18 | CommandExecutor
19 | {
20 | @Override
21 | public void execute(FsService fsService, HttpServletRequest request,
22 | ServletContext servletContext, JSONObject json) throws Exception
23 | {
24 | boolean init = request.getParameter("init") != null;
25 | boolean tree = request.getParameter("tree") != null;
26 | String target = request.getParameter("target");
27 |
28 | Map files = new LinkedHashMap();
29 | if (init)
30 | {
31 | json.put("api", 2.1);
32 | json.put("netDrivers", new Object[0]);
33 | }
34 |
35 | if (tree)
36 | {
37 | for (FsVolume v : fsService.getVolumes())
38 | {
39 | FsItemEx root = new FsItemEx(v.getRoot(), fsService);
40 | files.put(root.getHash(), root);
41 | addSubfolders(files, root);
42 | }
43 | }
44 |
45 | FsItemEx cwd = findCwd(fsService, target);
46 | files.put(cwd.getHash(), cwd);
47 | String[] onlyMimes = request.getParameterValues("mimes[]");
48 | addChildren(files, cwd, onlyMimes);
49 |
50 | json.put("files", files2JsonArray(request, files.values()));
51 | json.put("cwd", getFsItemInfo(request, cwd));
52 | json.put("options", getOptions(request, cwd));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/DuplicateCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.servlet.ServletContext;
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | import org.apache.commons.io.FilenameUtils;
10 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
11 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
12 | import org.grapheco.elfinder.controller.executor.FsItemEx;
13 | import org.json.JSONObject;
14 |
15 | import org.grapheco.elfinder.service.FsService;
16 |
17 | public class DuplicateCommandExecutor extends AbstractJsonCommandExecutor
18 | implements CommandExecutor
19 | {
20 | @Override
21 | public void execute(FsService fsService, HttpServletRequest request,
22 | ServletContext servletContext, JSONObject json) throws Exception
23 | {
24 | String[] targets = request.getParameterValues("targets[]");
25 |
26 | List added = new ArrayList();
27 |
28 | for (String target : targets)
29 | {
30 | FsItemEx fsi = super.findItem(fsService, target);
31 | String name = fsi.getName();
32 | String baseName = FilenameUtils.getBaseName(name);
33 | String extension = FilenameUtils.getExtension(name);
34 |
35 | int i = 1;
36 | FsItemEx newFile = null;
37 | baseName = baseName.replaceAll("\\(\\d+\\)$", "");
38 |
39 | while (true)
40 | {
41 | String newName = String.format("%s(%d)%s", baseName, i,
42 | (extension == null || extension.isEmpty() ? "" : "."
43 | + extension));
44 | newFile = new FsItemEx(fsi.getParent(), newName);
45 | if (!newFile.exists())
46 | {
47 | break;
48 | }
49 | i++;
50 | }
51 |
52 | createAndCopy(fsi, newFile);
53 | added.add(newFile);
54 | }
55 |
56 | json.put("added", files2JsonArray(request, added));
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/service/FsVolume.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.service;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.Map;
6 |
7 | public interface FsVolume
8 | {
9 | void createFile(FsItem fsi) throws IOException;
10 |
11 | void createFolder(FsItem fsi) throws IOException;
12 |
13 | void deleteFile(FsItem fsi) throws IOException;
14 |
15 | void deleteFolder(FsItem fsi) throws IOException;
16 |
17 | boolean exists(FsItem newFile);
18 |
19 | FsItem fromPath(String relativePath);
20 |
21 | String getDimensions(FsItem fsi);
22 |
23 | long getLastModified(FsItem fsi);
24 |
25 | String getMimeType(FsItem fsi);
26 |
27 | String getName();
28 |
29 | String getName(FsItem fsi);
30 |
31 | FsItem getParent(FsItem fsi);
32 |
33 | String getPath(FsItem fsi) throws IOException;
34 |
35 | FsItem getRoot();
36 |
37 | long getSize(FsItem fsi) throws IOException;
38 |
39 | String getThumbnailFileName(FsItem fsi);
40 |
41 | boolean hasChildFolder(FsItem fsi);
42 |
43 | boolean isFolder(FsItem fsi);
44 |
45 | boolean isRoot(FsItem fsi);
46 |
47 | FsItem[] listChildren(FsItem fsi);
48 |
49 | InputStream openInputStream(FsItem fsi) throws IOException;
50 |
51 | void writeStream(FsItem f, InputStream is) throws IOException;
52 |
53 | void rename(FsItem src, FsItem dst) throws IOException;
54 |
55 | /**
56 | * Gets the URL for the supplied item.
57 | *
58 | * @param f
59 | * The item to get the URL for.
60 | * @return An absolute URL or null if we should not send back a
61 | * URL.
62 | */
63 | String getURL(FsItem f);
64 |
65 | /**
66 | * This allows volumes to change the options returned to the client for a
67 | * particular item. Implementations should update the map they are passed.
68 | *
69 | * @param f
70 | * The item to filter the options for.
71 | * @param map
72 | * The options that are going to be returned.
73 | */
74 | void filterOptions(FsItem f, Map map);
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/TmbCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.awt.image.BufferedImage;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.InputStream;
6 | import java.util.Calendar;
7 |
8 | import javax.imageio.ImageIO;
9 | import javax.servlet.ServletContext;
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 |
13 | import org.apache.commons.lang3.time.DateUtils;
14 |
15 | import org.grapheco.elfinder.controller.executor.AbstractCommandExecutor;
16 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
17 | import org.grapheco.elfinder.controller.executor.FsItemEx;
18 | import org.grapheco.elfinder.service.FsService;
19 |
20 | import com.mortennobel.imagescaling.DimensionConstrain;
21 | import com.mortennobel.imagescaling.ResampleOp;
22 |
23 | public class TmbCommandExecutor extends AbstractCommandExecutor implements
24 | CommandExecutor
25 | {
26 | @Override
27 | public void execute(FsService fsService, HttpServletRequest request,
28 | HttpServletResponse response, ServletContext servletContext)
29 | throws Exception
30 | {
31 | String target = request.getParameter("target");
32 | FsItemEx fsi = super.findItem(fsService, target);
33 | InputStream is = fsi.openInputStream();
34 | BufferedImage image = ImageIO.read(is);
35 | int width = fsService.getServiceConfig().getTmbWidth();
36 | ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(
37 | width, -1));
38 | rop.setNumberOfThreads(4);
39 | BufferedImage b = rop.filter(image, null);
40 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
41 | ImageIO.write(b, "png", baos);
42 | byte[] bytesOut = baos.toByteArray();
43 | is.close();
44 |
45 | response.setHeader("Last-Modified",
46 | DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)
47 | .toGMTString());
48 | response.setHeader("Expires",
49 | DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)
50 | .toGMTString());
51 |
52 | ImageIO.write(b, "png", response.getOutputStream());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.grapheco.elfinder.controller.executor.FsItemEx;
7 | import org.grapheco.elfinder.service.FsItemFilter;
8 |
9 | public abstract class FsItemFilterUtils
10 | {
11 | public static FsItemFilter FILTER_ALL = new FsItemFilter()
12 | {
13 | @Override
14 | public boolean accepts(FsItemEx item)
15 | {
16 | return true;
17 | }
18 | };
19 |
20 | public static FsItemFilter FILTER_FOLDER = new FsItemFilter()
21 | {
22 | @Override
23 | public boolean accepts(FsItemEx item)
24 | {
25 | return item.isFolder();
26 | }
27 | };
28 |
29 | public static FsItemFilter createFileNameKeywordFilter(final String keyword)
30 | {
31 | return new FsItemFilter()
32 | {
33 | @Override
34 | public boolean accepts(FsItemEx item)
35 | {
36 | return item.getName().contains(keyword);
37 | }
38 | };
39 | }
40 |
41 | public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles,
42 | FsItemFilter filter)
43 | {
44 | List filtered = new ArrayList();
45 | for (FsItemEx file : sourceFiles)
46 | {
47 | if (filter.accepts(file))
48 | filtered.add(file);
49 | }
50 |
51 | return filtered.toArray(new FsItemEx[0]);
52 | }
53 |
54 | /**
55 | * returns a FsItemFilter according to given mimeFilters
56 | *
57 | * @param mimeFilters
58 | * An array of MIME types, if null no filtering is
59 | * done
60 | * @return A filter that only accepts the supplied MIME types.
61 | */
62 | public static FsItemFilter createMimeFilter(final String[] mimeFilters)
63 | {
64 | if (mimeFilters == null || mimeFilters.length == 0)
65 | return FILTER_ALL;
66 |
67 | return new FsItemFilter()
68 | {
69 | @Override
70 | public boolean accepts(FsItemEx item)
71 | {
72 | String mimeType = item.getMimeType().toUpperCase();
73 |
74 | for (String mf : mimeFilters)
75 | {
76 | mf = mf.toUpperCase();
77 | if (mimeType.startsWith(mf + "/") || mimeType.equals(mf))
78 | return true;
79 | }
80 | return false;
81 | }
82 | };
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/DimCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.awt.image.BufferedImage;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | import javax.imageio.ImageIO;
8 | import javax.servlet.ServletContext;
9 | import javax.servlet.http.HttpServletRequest;
10 |
11 | import org.json.JSONObject;
12 |
13 | import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor;
14 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
15 | import org.grapheco.elfinder.controller.executor.FsItemEx;
16 | import org.grapheco.elfinder.service.FsService;
17 |
18 | /**
19 | * This returns the dimensions on an image.
20 | */
21 | public class DimCommandExecutor extends AbstractJsonCommandExecutor implements
22 | CommandExecutor
23 | {
24 | @Override
25 | protected void execute(FsService fsService, HttpServletRequest request,
26 | ServletContext servletContext, JSONObject json) throws Exception
27 | {
28 | String target = request.getParameter("target");
29 | FsItemEx item = findItem(fsService, target);
30 | // If it's not an image then just return empty JSON.
31 | if (item.getMimeType().startsWith("image"))
32 | {
33 | InputStream inputStream = null;
34 | try
35 | {
36 | inputStream = item.openInputStream();
37 | BufferedImage image = ImageIO.read(inputStream);
38 | int width = image.getWidth();
39 | int height = image.getHeight();
40 | json.put("dim", String.format("%dx%d", width, height));
41 | }
42 | catch (IOException ioe)
43 | {
44 | String message = "Failed load image to get dimensions: "
45 | + item.getPath();
46 | if (LOG.isDebugEnabled())
47 | {
48 | LOG.debug(message, ioe);
49 | }
50 | else
51 | {
52 | LOG.warn(message);
53 | }
54 |
55 | }
56 | finally
57 | {
58 | if (inputStream != null)
59 | {
60 | try
61 | {
62 | inputStream.close();
63 | }
64 | catch (IOException ioe)
65 | {
66 | LOG.debug(
67 | "Failed to close stream to: " + item.getPath(),
68 | ioe);
69 | }
70 | }
71 | }
72 |
73 | }
74 | else
75 | {
76 | LOG.debug("dim command called on non-image: " + item.getPath());
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 | /target/
217 | /.idea/
218 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executors/FileCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executors;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.io.UnsupportedEncodingException;
7 | import java.net.URLEncoder;
8 |
9 | import javax.mail.internet.MimeUtility;
10 | import javax.servlet.ServletContext;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 |
14 | import org.apache.commons.io.IOUtils;
15 |
16 | import org.grapheco.elfinder.controller.executor.AbstractCommandExecutor;
17 | import org.grapheco.elfinder.controller.executor.CommandExecutor;
18 | import org.grapheco.elfinder.controller.executor.FsItemEx;
19 | import org.grapheco.elfinder.service.FsService;
20 | import org.grapheco.elfinder.util.MimeTypesUtils;
21 |
22 | public class FileCommandExecutor extends AbstractCommandExecutor implements
23 | CommandExecutor
24 | {
25 | @Override
26 | public void execute(FsService fsService, HttpServletRequest request,
27 | HttpServletResponse response, ServletContext servletContext)
28 | throws Exception
29 | {
30 | String target = request.getParameter("target");
31 | boolean download = "1".equals(request.getParameter("download"));
32 | FsItemEx fsi = super.findItem(fsService, target);
33 | String mime = fsi.getMimeType();
34 |
35 | response.setCharacterEncoding("utf-8");
36 | response.setContentType(mime);
37 | // String fileUrl = getFileUrl(fileTarget);
38 | // String fileUrlRelative = getFileUrl(fileTarget);
39 |
40 | // a folder!
41 | if (fsi.isFolder())
42 | {
43 | response.sendRedirect(request.getHeader("Referer") + "#elf_"
44 | + fsi.getHash());
45 | return;
46 | }
47 |
48 | String fileName = fsi.getName();
49 | // fileName = new String(fileName.getBytes("utf-8"), "ISO8859-1");
50 | if (download || MimeTypesUtils.isUnknownType(mime))
51 | {
52 | response.setHeader(
53 | "Content-Disposition",
54 | "attachments; "
55 | + getAttachementFileName(fileName,
56 | request.getHeader("USER-AGENT")));
57 | // response.setHeader("Content-Location", fileUrlRelative);
58 | response.setHeader("Content-Transfer-Encoding", "binary");
59 | }
60 |
61 | OutputStream out = response.getOutputStream();
62 | InputStream is = null;
63 | response.setContentLength((int) fsi.getSize());
64 | try
65 | {
66 | // serve file
67 | is = fsi.openInputStream();
68 | IOUtils.copy(is, out);
69 | out.flush();
70 | out.close();
71 | }
72 | finally
73 | {
74 | if (is != null)
75 | {
76 | try
77 | {
78 | is.close();
79 | }
80 | catch (IOException e)
81 | {
82 | e.printStackTrace();
83 | }
84 | }
85 | }
86 | }
87 |
88 | private String getAttachementFileName(String fileName, String userAgent)
89 | throws UnsupportedEncodingException
90 | {
91 | if (userAgent != null)
92 | {
93 | userAgent = userAgent.toLowerCase();
94 |
95 | if (userAgent.indexOf("msie") != -1)
96 | {
97 | return "filename=\"" + URLEncoder.encode(fileName, "UTF8")
98 | + "\"";
99 | }
100 |
101 | // Opera浏览器只能采用filename*
102 | if (userAgent.indexOf("opera") != -1)
103 | {
104 | return "filename*=UTF-8''"
105 | + URLEncoder.encode(fileName, "UTF8");
106 | }
107 | // Safari浏览器,只能采用ISO编码的中文输出
108 | if (userAgent.indexOf("safari") != -1)
109 | {
110 | return "filename=\""
111 | + new String(fileName.getBytes("UTF-8"), "ISO8859-1")
112 | + "\"";
113 | }
114 | // Chrome浏览器,只能采用MimeUtility编码或ISO编码的中文输出
115 | if (userAgent.indexOf("applewebkit") != -1)
116 | {
117 | return "filename=\""
118 | + MimeUtility.encodeText(fileName, "UTF8", "B") + "\"";
119 | }
120 | // FireFox浏览器,可以使用MimeUtility或filename*或ISO编码的中文输出
121 | if (userAgent.indexOf("mozilla") != -1)
122 | {
123 | return "filename*=UTF-8''"
124 | + URLEncoder.encode(fileName, "UTF8");
125 | }
126 | }
127 |
128 | return "filename=\"" + URLEncoder.encode(fileName, "UTF8") + "\"";
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/MultipleUploadItems.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller;
2 |
3 | import org.apache.commons.fileupload.FileItemStream;
4 | import org.apache.commons.fileupload.FileUploadException;
5 | import org.apache.commons.io.IOUtils;
6 | import org.apache.log4j.Logger;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import java.io.*;
10 | import java.lang.reflect.InvocationHandler;
11 | import java.lang.reflect.Method;
12 | import java.lang.reflect.Proxy;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * this class stores upload files in the request attributes for later usage
18 | *
19 | * @author bluejoe
20 | */
21 | public class MultipleUploadItems {
22 | Logger _logger = Logger.getLogger(this.getClass());
23 | List _items = new ArrayList();
24 | File _tempDir;
25 |
26 | public List items() {
27 | return _items;
28 | }
29 |
30 | public MultipleUploadItems(File tempDir) {
31 | _tempDir = tempDir;
32 | }
33 |
34 | /**
35 | * find items with given form field name
36 | *
37 | * @param fieldName
38 | * @return
39 | */
40 | public List items(String fieldName) {
41 | List filteredItems = new ArrayList();
42 | for (FileItemStream fis : _items) {
43 | if (fis.getFieldName().equals(fieldName))
44 | filteredItems.add(fis);
45 | }
46 |
47 | return filteredItems;
48 | }
49 |
50 | public void addItem(FileItemStream fis) {
51 | _items.add(fis);
52 | }
53 |
54 | public void addItemProxy(final FileItemStream item) throws IOException {
55 | InputStream stream = item.openStream();
56 | //ByteArrayOutputStream os = new ByteArrayOutputStream();
57 | //create a temp source
58 | final File source = File.createTempFile("elfinder_upload_", "", _tempDir);
59 | FileOutputStream os = new FileOutputStream(source);
60 | IOUtils.copy(stream, os);
61 | os.close();
62 | //final byte[] bs = os.toByteArray();
63 | stream.close();
64 | _logger.debug(String.format("saving item: %s", source.getCanonicalPath()));
65 | addItem((FileItemStream) Proxy.newProxyInstance(this.getClass()
66 | .getClassLoader(), new Class[]{FileItemStream.class, Finalizable.class},
67 | new InvocationHandler() {
68 | @Override
69 | public Object invoke(Object proxy, Method method,
70 | Object[] args) throws Throwable {
71 | if ("openStream".equals(method.getName())) {
72 | //return new ByteArrayInputStream(bs);
73 | return new FileInputStream(source);
74 | }
75 | if ("finalize".equals(method.getName())) {
76 | source.delete();
77 | _logger.debug(String.format("removing item: %s", source.getCanonicalPath()));
78 | return null;
79 | }
80 | return method.invoke(item, args);
81 | }
82 | }));
83 | }
84 |
85 | public void writeInto(HttpServletRequest request)
86 | throws FileUploadException, IOException {
87 | // store items for compatablity
88 | request.setAttribute(FileItemStream.class.getName(), _items);
89 | request.setAttribute(MultipleUploadItems.class.getName(), this);
90 | }
91 |
92 | public static MultipleUploadItems loadFrom(HttpServletRequest request) {
93 | return (MultipleUploadItems) request
94 | .getAttribute(MultipleUploadItems.class.getName());
95 | }
96 |
97 | public static void finalize(HttpServletRequest request) {
98 | MultipleUploadItems mui = loadFrom(request);
99 | if (mui != null) {
100 | for (FileItemStream fis : mui.items()) {
101 | if (fis instanceof Finalizable) {
102 | ((Finalizable) fis).finalize();
103 | }
104 | }
105 | }
106 | }
107 |
108 | interface Finalizable {
109 | void finalize();
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/servlet/ConnectorServlet.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.servlet;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import javax.servlet.ServletConfig;
7 | import javax.servlet.ServletException;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 | import org.grapheco.elfinder.controller.ConnectorController;
13 | import org.grapheco.elfinder.controller.executor.CommandExecutorFactory;
14 | import org.grapheco.elfinder.controller.executor.DefaultCommandExecutorFactory;
15 | import org.grapheco.elfinder.controller.executors.MissingCommandExecutor;
16 | import org.grapheco.elfinder.impl.DefaultFsService;
17 | import org.grapheco.elfinder.impl.DefaultFsServiceConfig;
18 | import org.grapheco.elfinder.impl.FsSecurityCheckForAll;
19 | import org.grapheco.elfinder.impl.StaticFsServiceFactory;
20 | import org.grapheco.elfinder.localfs.LocalFsVolume;
21 |
22 | /**
23 | * ConnectorServlet is an example servlet
24 | * it creates a ConnectorController on init() and use it to handle requests on doGet()/doPost()
25 | *
26 | * users should extend from this servlet and customize required protected methods
27 | *
28 | * @author bluejoe
29 | *
30 | */
31 | public class ConnectorServlet extends HttpServlet
32 | {
33 | // core member of this Servlet
34 | ConnectorController _connectorController;
35 |
36 | /**
37 | * create a command executor factory
38 | *
39 | * @param config
40 | * @return
41 | */
42 | protected CommandExecutorFactory createCommandExecutorFactory(
43 | ServletConfig config)
44 | {
45 | DefaultCommandExecutorFactory defaultCommandExecutorFactory = new DefaultCommandExecutorFactory();
46 | defaultCommandExecutorFactory
47 | .setClassNamePattern("cn.bluejoe.elfinder.controller.executors.%sCommandExecutor");
48 | defaultCommandExecutorFactory
49 | .setFallbackCommand(new MissingCommandExecutor());
50 | return defaultCommandExecutorFactory;
51 | }
52 |
53 | /**
54 | * create a connector controller
55 | *
56 | * @param config
57 | * @return
58 | */
59 | protected ConnectorController createConnectorController(ServletConfig config)
60 | {
61 | ConnectorController connectorController = new ConnectorController();
62 |
63 | connectorController
64 | .setCommandExecutorFactory(createCommandExecutorFactory(config));
65 | connectorController.setFsServiceFactory(createServiceFactory(config));
66 |
67 | return connectorController;
68 | }
69 |
70 | protected DefaultFsService createFsService()
71 | {
72 | DefaultFsService fsService = new DefaultFsService();
73 | fsService.setSecurityChecker(new FsSecurityCheckForAll());
74 |
75 | DefaultFsServiceConfig serviceConfig = new DefaultFsServiceConfig();
76 | serviceConfig.setTmbWidth(80);
77 |
78 | fsService.setServiceConfig(serviceConfig);
79 |
80 | fsService.addVolume("A",
81 | createLocalFsVolume("My Files", new File("/tmp/a")));
82 | fsService.addVolume("B",
83 | createLocalFsVolume("Shared", new File("/tmp/b")));
84 |
85 | return fsService;
86 | }
87 |
88 | private LocalFsVolume createLocalFsVolume(String name, File rootDir)
89 | {
90 | LocalFsVolume localFsVolume = new LocalFsVolume();
91 | localFsVolume.setName(name);
92 | localFsVolume.setRootDir(rootDir);
93 | return localFsVolume;
94 | }
95 |
96 | /**
97 | * create a service factory
98 | *
99 | * @param config
100 | * @return
101 | */
102 | protected StaticFsServiceFactory createServiceFactory(ServletConfig config)
103 | {
104 | StaticFsServiceFactory staticFsServiceFactory = new StaticFsServiceFactory();
105 | DefaultFsService fsService = createFsService();
106 |
107 | staticFsServiceFactory.setFsService(fsService);
108 | return staticFsServiceFactory;
109 | }
110 |
111 | @Override
112 | protected void doGet(HttpServletRequest req, HttpServletResponse resp)
113 | throws ServletException, IOException
114 | {
115 | _connectorController.connector(req, resp);
116 | }
117 |
118 | @Override
119 | protected void doPost(HttpServletRequest req, HttpServletResponse resp)
120 | throws ServletException, IOException
121 | {
122 | _connectorController.connector(req, resp);
123 | }
124 |
125 | @Override
126 | public void init(ServletConfig config) throws ServletException
127 | {
128 | _connectorController = createConnectorController(config);
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/elfinder-servlet.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
19 |
21 |
22 |
24 |
25 |
26 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
62 |
63 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import org.grapheco.elfinder.service.FsItem;
10 | import org.grapheco.elfinder.service.FsItemFilter;
11 | import org.grapheco.elfinder.service.FsService;
12 | import org.grapheco.elfinder.service.FsVolume;
13 |
14 | /**
15 | * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its
16 | * context including FsService, FsVolume, etc
17 | *
18 | * @author bluejoe
19 | *
20 | */
21 | public class FsItemEx
22 | {
23 | private FsItem _f;
24 |
25 | private FsService _s;
26 |
27 | private FsVolume _v;
28 |
29 | public FsItemEx(FsItem fsi, FsService fsService)
30 | {
31 | _f = fsi;
32 | _v = fsi.getVolume();
33 | _s = fsService;
34 | }
35 |
36 | public FsItemEx(FsItemEx parent, String name) throws IOException
37 | {
38 | _v = parent._v;
39 | _s = parent._s;
40 | // Directories may already have a trailing slash on them so we make sure
41 | // we don't double up
42 | String path = _v.getPath(parent._f);
43 | if (path != null)
44 | {
45 | if (!path.endsWith("/"))
46 | {
47 | path = path + "/";
48 | }
49 | path = path + name;
50 | }
51 | else
52 | {
53 | path = name;
54 | }
55 | _f = _v.fromPath(path);
56 | }
57 |
58 | public FsItemEx createChild(String name) throws IOException
59 | {
60 | return new FsItemEx(this, name);
61 | }
62 |
63 | public void createFile() throws IOException
64 | {
65 | _v.createFile(_f);
66 | }
67 |
68 | public void createFolder() throws IOException
69 | {
70 | _v.createFolder(_f);
71 | }
72 |
73 | public void delete() throws IOException
74 | {
75 | if (_v.isFolder(_f))
76 | {
77 | _v.deleteFolder(_f);
78 | }
79 | else
80 | {
81 | _v.deleteFile(_f);
82 | }
83 | }
84 |
85 | public void deleteFile() throws IOException
86 | {
87 | _v.deleteFile(_f);
88 | }
89 |
90 | public void deleteFolder() throws IOException
91 | {
92 | _v.deleteFolder(_f);
93 | }
94 |
95 | public boolean exists()
96 | {
97 | return _v.exists(_f);
98 | }
99 |
100 | public String getHash() throws IOException
101 | {
102 | return _s.getHash(_f);
103 | }
104 |
105 | public long getLastModified()
106 | {
107 | return _v.getLastModified(_f);
108 | }
109 |
110 | public String getMimeType()
111 | {
112 | return _v.getMimeType(_f);
113 | }
114 |
115 | public String getName()
116 | {
117 | return _v.getName(_f);
118 | }
119 |
120 | public FsItemEx getParent()
121 | {
122 | return new FsItemEx(_v.getParent(_f), _s);
123 | }
124 |
125 | public String getPath() throws IOException
126 | {
127 | return _v.getPath(_f);
128 | }
129 |
130 | public long getSize() throws IOException
131 | {
132 | return _v.getSize(_f);
133 | }
134 |
135 | public String getVolumeId()
136 | {
137 | return _s.getVolumeId(_v);
138 | }
139 |
140 | public String getVolumnName()
141 | {
142 | return _v.getName();
143 | }
144 |
145 | public boolean hasChildFolder()
146 | {
147 | return _v.hasChildFolder(_f);
148 | }
149 |
150 | public boolean isFolder()
151 | {
152 | return _v.isFolder(_f);
153 | }
154 |
155 | public boolean isLocked(FsItemEx fsi) throws IOException
156 | {
157 | return _s.getSecurityChecker().isLocked(_s, _f);
158 | }
159 |
160 | public boolean isReadable(FsItemEx fsi) throws IOException
161 | {
162 | return _s.getSecurityChecker().isReadable(_s, _f);
163 | }
164 |
165 | public boolean isRoot()
166 | {
167 | return _v.isRoot(_f);
168 | }
169 |
170 | public boolean isWritable(FsItemEx fsi) throws IOException
171 | {
172 | return _s.getSecurityChecker().isWritable(_s, _f);
173 | }
174 |
175 | public List listChildren()
176 | {
177 | List list = new ArrayList();
178 | for (FsItem child : _v.listChildren(_f))
179 | {
180 | list.add(new FsItemEx(child, _s));
181 | }
182 | return list;
183 | }
184 |
185 | public InputStream openInputStream() throws IOException
186 | {
187 | return _v.openInputStream(_f);
188 | }
189 |
190 | public void writeStream(InputStream is) throws IOException
191 | {
192 | _v.writeStream(_f, is);
193 | }
194 |
195 | public void renameTo(FsItemEx dst) throws IOException
196 | {
197 | _v.rename(_f, dst._f);
198 | }
199 |
200 | public List listChildren(FsItemFilter filter)
201 | {
202 | List list = new ArrayList();
203 | for (FsItem child : _v.listChildren(_f))
204 | {
205 | FsItemEx childEx = new FsItemEx(child, _s);
206 | if (filter.accepts(childEx))
207 | {
208 | list.add(childEx);
209 | }
210 | }
211 | return list;
212 | }
213 |
214 | public String getURL()
215 | {
216 | return _v.getURL(_f);
217 | }
218 |
219 | public void filterOptions(Map map)
220 | {
221 | _v.filterOptions(_f, map);
222 | }
223 | }
224 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/impl/DefaultFsService.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.impl;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.Collection;
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Map.Entry;
10 |
11 | import org.apache.commons.codec.binary.Base64;
12 | import org.apache.log4j.Logger;
13 |
14 | import org.grapheco.elfinder.controller.executor.FsItemEx;
15 | import org.grapheco.elfinder.service.FsItem;
16 | import org.grapheco.elfinder.service.FsItemFilter;
17 | import org.grapheco.elfinder.service.FsSecurityChecker;
18 | import org.grapheco.elfinder.service.FsService;
19 | import org.grapheco.elfinder.service.FsServiceConfig;
20 | import org.grapheco.elfinder.service.FsVolume;
21 |
22 | public class DefaultFsService implements FsService
23 | {
24 | FsSecurityChecker _securityChecker;
25 |
26 | FsServiceConfig _serviceConfig;
27 |
28 | Map _volumeMap = new HashMap();
29 |
30 | // special characters should be encoded, avoid to be processed as a part of
31 | // URL
32 | String[][] escapes = { { "+", "_P" }, { "-", "_M" }, { "/", "_S" },
33 | { ".", "_D" }, { "=", "_E" } };
34 |
35 | @Override
36 | /**
37 | * find files by name pattern, this provides a simple recursively iteration based method
38 | * lucene engines can be introduced to improve it!
39 | * This searches across all volumes.
40 | *
41 | * @param filter The filter to apply to select files.
42 | * @return A collection of files that match the filter and gave the root as a parent.
43 | */
44 | public FsItemEx[] find(FsItemFilter filter)
45 | {
46 | List results = new ArrayList();
47 | for (FsVolume vol : _volumeMap.values())
48 | {
49 | FsItem root = vol.getRoot();
50 | results.addAll(findRecursively(filter, root));
51 | }
52 |
53 | return results.toArray(new FsItemEx[0]);
54 | }
55 |
56 | /**
57 | * find files recursively in specific folder
58 | *
59 | * @param filter
60 | * The filter to apply to select files.
61 | * @param root
62 | * The location in the hierarchy to search from.
63 | * @return A collection of files that match the filter and have the root as
64 | * a parent.
65 | */
66 | private Collection findRecursively(FsItemFilter filter,
67 | FsItem root)
68 | {
69 | List results = new ArrayList();
70 | FsVolume vol = root.getVolume();
71 | for (FsItem child : vol.listChildren(root))
72 | {
73 | if (vol.isFolder(child))
74 | {
75 | results.addAll(findRecursively(filter, child));
76 | }
77 | else
78 | {
79 | FsItemEx item = new FsItemEx(child, this);
80 | if (filter.accepts(item))
81 | results.add(item);
82 | }
83 | }
84 |
85 | return results;
86 | }
87 |
88 | @Override
89 | public FsItem fromHash(String hash)
90 | {
91 | for (FsVolume v : _volumeMap.values())
92 | {
93 | String prefix = getVolumeId(v) + "_";
94 |
95 | if (hash.equals(prefix))
96 | {
97 | return v.getRoot();
98 | }
99 |
100 | if (hash.startsWith(prefix))
101 | {
102 | String localHash = hash.substring(prefix.length());
103 |
104 | for (String[] pair : escapes)
105 | {
106 | localHash = localHash.replace(pair[1], pair[0]);
107 | }
108 |
109 | String relativePath = new String(Base64.decodeBase64(localHash));
110 | return v.fromPath(relativePath);
111 | }
112 | }
113 |
114 | return null;
115 | }
116 |
117 | @Override
118 | public String getHash(FsItem item) throws IOException
119 | {
120 | String relativePath = item.getVolume().getPath(item);
121 | String base = new String(Base64.encodeBase64(relativePath.getBytes()));
122 |
123 | for (String[] pair : escapes)
124 | {
125 | base = base.replace(pair[0], pair[1]);
126 | }
127 |
128 | return getVolumeId(item.getVolume()) + "_" + base;
129 | }
130 |
131 | public FsSecurityChecker getSecurityChecker()
132 | {
133 | return _securityChecker;
134 | }
135 |
136 | public FsServiceConfig getServiceConfig()
137 | {
138 | return _serviceConfig;
139 | }
140 |
141 | @Override
142 | public String getVolumeId(FsVolume volume)
143 | {
144 | for (Entry en : _volumeMap.entrySet())
145 | {
146 | if (en.getValue() == volume)
147 | return en.getKey();
148 | }
149 |
150 | return null;
151 | }
152 |
153 | public Map getVolumeMap()
154 | {
155 | return _volumeMap;
156 | }
157 |
158 | public FsVolume[] getVolumes()
159 | {
160 | return _volumeMap.values().toArray(new FsVolume[0]);
161 | }
162 |
163 | public void setSecurityChecker(FsSecurityChecker securityChecker)
164 | {
165 | _securityChecker = securityChecker;
166 | }
167 |
168 | public void setServiceConfig(FsServiceConfig serviceConfig)
169 | {
170 | _serviceConfig = serviceConfig;
171 | }
172 |
173 | public void setVolumeMap(Map volumeMap)
174 | {
175 | for (Entry en : volumeMap.entrySet())
176 | {
177 | addVolume(en.getKey(), en.getValue());
178 | }
179 | }
180 |
181 | /**
182 | * @deprecated {@link #setVolumeMap(Map)}
183 | * @param volumes
184 | * The volumes available.
185 | * @throws IOException
186 | * If there is a problem with using one of the volumes.
187 | */
188 | public void setVolumes(FsVolume[] volumes) throws IOException
189 | {
190 | Logger.getLogger(getClass())
191 | .warn("calling setVolumes() is deprecated, please use setVolumeMap() to specify volume id explicitly");
192 | char vid = 'A';
193 | for (FsVolume volume : volumes)
194 | {
195 | _volumeMap.put("" + vid, volume);
196 | Logger.getLogger(this.getClass()).info(
197 | String.format("mounted %s: %s", "" + vid, volume));
198 | vid++;
199 | }
200 | }
201 |
202 | public void addVolume(String name, FsVolume fsVolume)
203 | {
204 | _volumeMap.put(name, fsVolume);
205 | Logger.getLogger(this.getClass()).info(
206 | String.format("mounted %s: %s", name, fsVolume));
207 | }
208 | }
209 |
--------------------------------------------------------------------------------
/src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java:
--------------------------------------------------------------------------------
1 | package org.grapheco.elfinder.controller.executor;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.ArrayList;
6 | import java.util.Arrays;
7 | import java.util.Collection;
8 | import java.util.HashMap;
9 | import java.util.List;
10 | import java.util.Map;
11 |
12 | import javax.servlet.ServletContext;
13 | import javax.servlet.http.HttpServletRequest;
14 | import javax.servlet.http.HttpServletResponse;
15 |
16 | import org.apache.log4j.Logger;
17 |
18 | import org.grapheco.elfinder.service.FsItemFilter;
19 | import org.grapheco.elfinder.service.FsService;
20 | import org.grapheco.elfinder.util.FsItemFilterUtils;
21 | import org.grapheco.elfinder.util.FsServiceUtils;
22 |
23 | public abstract class AbstractCommandExecutor implements CommandExecutor
24 | {
25 | protected static Logger LOG = Logger
26 | .getLogger(AbstractCommandExecutor.class);
27 |
28 | protected FsItemFilter getRequestedFilter(HttpServletRequest request)
29 | {
30 | String[] onlyMimes = request.getParameterValues("mimes[]");
31 | if (onlyMimes == null)
32 | return FsItemFilterUtils.FILTER_ALL;
33 |
34 | return FsItemFilterUtils.createMimeFilter(onlyMimes);
35 | }
36 |
37 | protected void addChildren(Map map, FsItemEx fsi,
38 | String[] mimeFilters) throws IOException
39 | {
40 | FsItemFilter filter = FsItemFilterUtils.createMimeFilter(mimeFilters);
41 | addChildren(map, fsi, filter);
42 | }
43 |
44 | private void addChildren(Map map, FsItemEx fsi,
45 | FsItemFilter filter) throws IOException
46 | {
47 | for (FsItemEx f : fsi.listChildren(filter))
48 | {
49 | map.put(f.getHash(), f);
50 | }
51 | }
52 |
53 | protected void addSubfolders(Map map, FsItemEx fsi)
54 | throws IOException
55 | {
56 | addChildren(map, fsi, FsItemFilterUtils.FILTER_FOLDER);
57 | }
58 |
59 | protected void createAndCopy(FsItemEx src, FsItemEx dst) throws IOException
60 | {
61 | if (src.isFolder())
62 | {
63 | createAndCopyFolder(src, dst);
64 | }
65 | else
66 | {
67 | createAndCopyFile(src, dst);
68 | }
69 | }
70 |
71 | protected void createAndCopyFile(FsItemEx src, FsItemEx dst)
72 | throws IOException
73 | {
74 | dst.createFile();
75 | InputStream is = src.openInputStream();
76 | dst.writeStream(is);
77 | }
78 |
79 | protected void createAndCopyFolder(FsItemEx src, FsItemEx dst)
80 | throws IOException
81 | {
82 | dst.createFolder();
83 |
84 | for (FsItemEx c : src.listChildren())
85 | {
86 | if (c.isFolder())
87 | {
88 | createAndCopyFolder(c, new FsItemEx(dst, c.getName()));
89 | }
90 | else
91 | {
92 | createAndCopyFile(c, new FsItemEx(dst, c.getName()));
93 | }
94 | }
95 | }
96 |
97 | @Override
98 | public void execute(CommandExecutionContext ctx) throws Exception
99 | {
100 | FsService fileService = ctx.getFsServiceFactory().getFileService(
101 | ctx.getRequest(), ctx.getServletContext());
102 | execute(fileService, ctx.getRequest(), ctx.getResponse(),
103 | ctx.getServletContext());
104 | }
105 |
106 | public abstract void execute(FsService fsService,
107 | HttpServletRequest request, HttpServletResponse response,
108 | ServletContext servletContext) throws Exception;
109 |
110 | protected Object[] files2JsonArray(HttpServletRequest request,
111 | Collection list) throws IOException
112 | {
113 | return files2JsonArray(request, list.toArray(new FsItemEx[0]));
114 | }
115 |
116 | protected Object[] files2JsonArray(HttpServletRequest request,
117 | FsItemEx[] list) throws IOException
118 | {
119 | List