Skip to content

Commit 0d66546

Browse files
committed
clipboard
1 parent 8725b23 commit 0d66546

File tree

5 files changed

+180
-24
lines changed

5 files changed

+180
-24
lines changed

Changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Version 1.1, 2016-01-10
2+
- Clipboard operations
3+
14
Version 0.9.7, 2015-11-11
25
- conversion from ant to maven build
36

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>de.jwi</groupId>
55
<artifactId>jFM</artifactId>
66
<packaging>war</packaging>
7-
<version>0.9.7-SNAPSHOT</version>
7+
<version>1.1-SNAPSHOT</version>
88
<name>jFM Maven Webapp</name>
99
<url>http://maven.apache.org</url>
1010

src/main/java/de/jwi/jfm/Folder.java

+117-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import java.util.Set;
5555
import java.util.zip.ZipOutputStream;
5656

57+
import javax.servlet.http.HttpSession;
58+
5759
import org.apache.commons.fileupload.FileItem;
5860
import org.apache.commons.io.FileUtils;
5961
import org.apache.commons.io.comparator.LastModifiedFileComparator;
@@ -380,17 +382,29 @@ private String copyOrMove(boolean move, String[] selectedIDs, String target)
380382

381383
if (move)
382384
{
383-
if (!f.renameTo(fx))
385+
if (f.isDirectory())
384386
{
385-
sb.append(f.getName()).append(" ");
387+
FileUtils.moveDirectoryToDirectory(f, fx, true);
388+
}
389+
else {
390+
if (!f.renameTo(fx))
391+
{
392+
sb.append(f.getName()).append(" ");
393+
}
386394
}
387395
}
388396
else
389397
{
390398
try
391399
{
392-
FileUtils.copyFile(f, fx, true);
393-
// fileCopy(f, fx);
400+
if (f.isDirectory())
401+
{
402+
FileUtils.copyDirectoryToDirectory(f, fx);
403+
}
404+
else
405+
{
406+
FileUtils.copyFile(f, fx, true);
407+
}
394408
}
395409
catch (IOException e)
396410
{
@@ -722,10 +736,96 @@ private String zip(OutputStream out, String[] selectedIDs)
722736
return null;
723737
}
724738

739+
private String copyOrCutClipboard(String[] selectedIDs, int cutOrCopy, HttpSession session)
740+
throws OutOfSyncException, IOException
741+
{
742+
File[] selectedfiles = new File[selectedIDs.length];
743+
744+
for (int i = 0; i < selectedIDs.length; i++)
745+
{
746+
File f = checkAndGet(selectedIDs[i]);
747+
748+
if (null == f)
749+
{
750+
throw new OutOfSyncException();
751+
}
752+
753+
selectedfiles[i] = f;
754+
}
755+
756+
ClipBoardContent clipBoardContent = new ClipBoardContent(cutOrCopy, selectedfiles);
757+
session.setAttribute("clipBoardContent", clipBoardContent);
758+
759+
return "";
760+
}
761+
762+
private String pasteClipboard(HttpSession session)
763+
throws OutOfSyncException, IOException
764+
{
765+
ClipBoardContent clipBoardContent = (ClipBoardContent)session.getAttribute("clipBoardContent");
766+
if (clipBoardContent == null)
767+
{
768+
return "nothing in clipboard";
769+
}
770+
771+
for (int i = 0; i < clipBoardContent.selectedfiles.length; i++)
772+
{
773+
File f = clipBoardContent.selectedfiles[i];
774+
File f1 = f.getParentFile();
775+
776+
if (myFile.getCanonicalFile().equals(f1.getCanonicalFile()))
777+
{
778+
return "same folder";
779+
}
780+
}
781+
782+
for (int i = 0; i < clipBoardContent.selectedfiles.length; i++)
783+
{
784+
File f = clipBoardContent.selectedfiles[i];
785+
786+
if (clipBoardContent.contentType == ClipBoardContent.COPY_CONTENT)
787+
{
788+
if (f.isDirectory())
789+
{
790+
FileUtils.copyDirectoryToDirectory(f, myFile);
791+
}
792+
else
793+
{
794+
FileUtils.copyFileToDirectory(f, myFile, true);
795+
}
796+
}
797+
if (clipBoardContent.contentType == ClipBoardContent.CUT_CONTENT)
798+
{
799+
if (f.isDirectory())
800+
{
801+
FileUtils.moveDirectoryToDirectory(f, myFile, false);
802+
}
803+
else
804+
{
805+
FileUtils.moveFileToDirectory(f, myFile, false);
806+
}
807+
}
808+
if (clipBoardContent.contentType == ClipBoardContent.CUT_CONTENT)
809+
{
810+
session.removeAttribute("clipBoardContent");
811+
}
812+
}
813+
814+
return "";
815+
}
816+
817+
private String clearClipboard(HttpSession session)
818+
throws OutOfSyncException, IOException
819+
{
820+
session.removeAttribute("clipBoardContent");
821+
822+
return "";
823+
}
824+
725825
// caller must have called load() before
726826

727827
public String action(int action, OutputStream out, String[] selectedIDs,
728-
String target) throws IOException, OutOfSyncException
828+
String target, HttpSession session) throws IOException, OutOfSyncException
729829
{
730830
String res = null;
731831

@@ -767,6 +867,18 @@ public String action(int action, OutputStream out, String[] selectedIDs,
767867
case Controller.JOIN_ACTION:
768868
res = join(selectedIDs);
769869
break;
870+
case Controller.CLIPBOARD_COPY_ACTION:
871+
res = copyOrCutClipboard(selectedIDs, ClipBoardContent.COPY_CONTENT, session);
872+
break;
873+
case Controller.CLIPBOARD_CUT_ACTION:
874+
res = copyOrCutClipboard(selectedIDs, ClipBoardContent.CUT_CONTENT, session);
875+
break;
876+
case Controller.CLIPBOARD_PASTE_ACTION:
877+
res = pasteClipboard(session);
878+
break;
879+
case Controller.CLIPBOARD_CLEAR_ACTION:
880+
res = clearClipboard(session);
881+
break;
770882
}
771883

772884
if ("".equals(res)) // no error, action succeded.

src/main/java/de/jwi/jfm/servlets/Controller.java

+30-6
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@
4141
import javax.servlet.http.HttpServlet;
4242
import javax.servlet.http.HttpServletRequest;
4343
import javax.servlet.http.HttpServletResponse;
44+
import javax.servlet.http.HttpSession;
4445

4546
import org.apache.commons.fileupload.DiskFileUpload;
4647
import org.apache.commons.fileupload.FileItem;
4748
import org.apache.commons.fileupload.FileUpload;
4849

50+
import de.jwi.jfm.ClipBoardContent;
4951
import de.jwi.jfm.Folder;
5052
import de.jwi.jfm.OutOfSyncException;
5153

@@ -91,6 +93,14 @@ public class Controller extends HttpServlet {
9193
public static final int JOIN_ACTION = 11;
9294

9395
public static final int CHMOD_ACTION = 12;
96+
97+
public static final int CLIPBOARD_COPY_ACTION = 13;
98+
99+
public static final int CLIPBOARD_CUT_ACTION = 14;
100+
101+
public static final int CLIPBOARD_PASTE_ACTION = 15;
102+
103+
public static final int CLIPBOARD_CLEAR_ACTION = 16;
94104

95105
private Properties dirmapping = null;
96106

@@ -284,6 +294,8 @@ private String handleQuery(HttpServletRequest request, HttpServletResponse respo
284294
throws OutOfSyncException, IOException {
285295
String rc = "";
286296

297+
HttpSession session = request.getSession();
298+
287299
String target = null;
288300
int action = NOP_ACTION;
289301
String[] selectedfiles = request.getParameterValues("index");
@@ -334,7 +346,7 @@ else if ("du".equals(sort)) {
334346
action = GETURL_ACTION;
335347
} else if ("Delete".equals(command)) {
336348
action = DELETE_ACTION;
337-
} else if ("Rename".equals(command)) {
349+
} else if ("Rename to".equals(command)) {
338350
target = request.getParameter("renameto");
339351
action = RENAME_ACTION;
340352
} else if ("Unzip".equals(command)) {
@@ -346,30 +358,42 @@ else if ("du".equals(sort)) {
346358
response.setHeader("Content-Disposition", "inline; filename=\"jFMdownload.zip\"");
347359

348360
out = response.getOutputStream();
349-
} else if ("Copy".equals(command)) {
361+
} else if ("Copy to".equals(command)) {
350362
target = request.getParameter("copyto");
351363
action = COPY_ACTION;
352-
} else if ("Move".equals(command)) {
364+
} else if ("Move to".equals(command)) {
353365
target = request.getParameter("moveto");
354366
action = MOVE_ACTION;
355-
} else if ("Chmod".equals(command)) {
367+
} else if ("Chmod to".equals(command)) {
356368
target = request.getParameter("chmodto");
357369
action = CHMOD_ACTION;
358370
} else if ("DeleteRecursively".equals(command)) {
359371
target = request.getParameter("confirm");
360372
action = DELETE_RECURSIVE_ACTION;
361-
} else if ("FtpUpload".equals(command)) {
373+
} else if ("FtpUpload to".equals(command)) {
362374
target = request.getParameter("ftpto");
363375
action = FTPUP_ACTION;
364376
} else if ("Join".equals(command)) {
365377
action = JOIN_ACTION;
378+
} else if ("cut".equals(command)) {
379+
action = CLIPBOARD_CUT_ACTION;
380+
} else if ("copy".equals(command)) {
381+
action = CLIPBOARD_COPY_ACTION;
382+
} else if ("paste".equals(command)) {
383+
action = CLIPBOARD_PASTE_ACTION;
366384
}
385+
else if ("clear".equals(command)) {
386+
action = CLIPBOARD_CLEAR_ACTION;
387+
}
388+
389+
390+
367391
if (NOP_ACTION == action) {
368392
return "";
369393
}
370394

371395
try {
372-
rc = folder.action(action, out, selectedfiles, target);
396+
rc = folder.action(action, out, selectedfiles, target, session);
373397
} catch (SecurityException e) {
374398
rc = "SecurityException: " + e.getMessage();
375399
return rc;

src/main/webapp/WEB-INF/fm.jsp

+29-12
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,30 @@ Check all
182182

183183
<table>
184184
<tbody>
185+
186+
<tr>
187+
<td colspan="4" class="header-left">Clipboard on selected Files</td>
188+
</tr>
189+
190+
<tr>
191+
<td class="row-center"><input type="submit" name="command" value="cut" title="cut selected files to clipboard"></td>
192+
<td class="row-center"><input type="submit" name="command" value="copy" title="copy selected files to clipboard"></td>
193+
<td class="row-center"><input type="submit" name="command" value="paste" title="paste clipboard to current directory"></td>
194+
<td class="row-center"><input type="submit" name="command" value="clear" title="clear clipboard"></td>
195+
<tr>
196+
<c:if test="${not empty sessionScope.clipBoardContent}">
197+
<tr><td colspan="4" style="font-size:small;">Clipboard contains ${sessionScope.clipBoardContent.fileCount} files to ${sessionScope.clipBoardContent.kind}.
198+
</td></tr>
199+
<tr><td colspan="4" style="font-size:small;">${sessionScope.clipBoardContent.files}</td></tr>
200+
</c:if>
185201
<tr>
186202
<td colspan="4" class="header-left">Action on selected Files</td>
187203
</tr>
188204

189205

190206
<tr>
191-
<td class="row-right"> <input type="submit" name="command" value="Rename" title="Rename selected file"></td>
192-
<td class="row-left">to <input name="renameto" type="text"></td>
207+
<td class="row-right"><input type="submit" name="command" value="Rename to" title="Rename selected file"></td>
208+
<td class="row-left"><input name="renameto" type="text"></td>
193209

194210

195211

@@ -202,8 +218,8 @@ Check all
202218
</tr>
203219

204220
<tr>
205-
<td class="row-right"> <input type="submit" name="command" value="Copy" title="Copy selected files"></td>
206-
<td class="row-left">to <input name="copyto" type="text"></td>
221+
<td class="row-right"><input type="submit" name="command" value="Copy to" title="Copy selected files"></td>
222+
<td class="row-left"><input name="copyto" type="text"></td>
207223

208224

209225
<td class="row-right"> <input type="submit" name="command" value="ZipDownload" title="Zip download files"></td>
@@ -213,19 +229,19 @@ Check all
213229
</tr>
214230

215231
<tr>
216-
<td class="row-right"> <input type="submit" name="command" value="Move" title="Move selected files"></td>
217-
<td class="row-left">to <input name="moveto" type="text"></td>
232+
<td class="row-right"><input type="submit" name="command" value="Move to" title="Move selected files"></td>
233+
<td class="row-left"><input name="moveto" type="text"></td>
218234

219235
<td class="row-right"> <input type="submit" name="command" value="DeleteRecursively" title="Delete selected folders recursively"></td>
220236
<td class="row-left">type YES <input name="confirm" type="text" size="3" title="Confirm with YES"></td>
221237
</tr>
222238

223239
<tr>
224-
<td class="row-right"> <input type="submit" name="command" value="Chmod" title="Chmod selected files"></td>
225-
<td class="row-left">to <input name="chmodto" type="text" size="9" title="format: rwxr-xr-x"></td>
240+
<td class="row-right"><input type="submit" name="command" value="Chmod to" title="Chmod selected files"></td>
241+
<td class="row-left"><input name="chmodto" type="text" size="9" title="format: rwxr-xr-x"></td>
226242

227-
<td class="row-right"><input type="submit" name="command" value="FtpUpload" title="ftp upload files"></td>
228-
<td class="row-left">to <input name="ftpto" type="text" size="60" value="" title="user:password@host/path"></td>
243+
<td class="row-right"><input type="submit" name="command" value="FtpUpload to" title="ftp upload files"></td>
244+
<td class="row-left"><input name="ftpto" type="text" value="" title="user:password@host/path"></td>
229245

230246

231247

@@ -239,16 +255,17 @@ Check all
239255
</form>
240256

241257

242-
<table style="width: 60%; text-align: left;" border="1">
258+
<table border="1">
243259
<tbody>
244260
<tr>
245261

246262
<td class="row-center">
247263

248264
<form action="${self}${path}" method="post">
249265

250-
<input name="newdir" type="text">
251266
<input type="submit" name="command" value="Mkdir" title="make directory">
267+
<input name="newdir" type="text">
268+
252269
</form>
253270
</td>
254271

0 commit comments

Comments
 (0)