package cn.bluejoe.elfinder.controller.executors;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.json.JSONObject;

import cn.bluejoe.elfinder.controller.executor.AbstractJsonCommandExecutor;
import cn.bluejoe.elfinder.controller.executor.CommandExecutor;
import cn.bluejoe.elfinder.controller.executor.FsItemEx;
import cn.bluejoe.elfinder.service.FsService;

public class PasteCommandExecutor extends AbstractJsonCommandExecutor implements CommandExecutor
{
	@Override
	public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json)
			throws Exception
	{
		String[] targets = request.getParameterValues("targets[]");
		String src = request.getParameter("src");
		String dst = request.getParameter("dst");
		boolean cut = "1".equals(request.getParameter("cut"));

		List<FsItemEx> added = new ArrayList<FsItemEx>();
		List<FsItemEx> removed = new ArrayList<FsItemEx>();

		FsItemEx fsrc = super.findItem(fsService, src);
		FsItemEx fdst = super.findItem(fsService, dst);

		for (String target : targets)
		{
			FsItemEx ftgt = super.findItem(fsService, target);
			String name = ftgt.getName();
			FsItemEx newFile = new FsItemEx(fdst, name);
			super.createAndCopy(ftgt, newFile);
			added.add(newFile);

			if (cut)
			{
				ftgt.delete();
				removed.add(ftgt);
			}
		}

		json.put("added", files2JsonArray(request, added));
		json.put("removed", files2JsonArray(request, removed));
	}
}

@@ -947,32 +947,24 @@
 w ArrayList%3C
-FsItemEx
 %3E();%0A%09%09List%3C
@@ -963,24 +963,22 @@
 %0A%09%09List%3C
-FsItemEx
+String
 %3E remove
@@ -995,24 +995,16 @@
 rayList%3C
-FsItemEx
 %3E();%0A%0A%09%09
@@ -1388,19 +1388,21 @@
 ved.add(
-ftg
+targe
 t);%0A%09%09%09%7D
@@ -1486,33 +1486,8 @@
 ed%22,
- files2JsonArray(request,
  rem
@@ -1491,16 +1491,15 @@
 removed)
-)
 ;%0A%09%7D%0A%7D%0A

paste command should return just the hashes of removed