KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > webui > FileClipboard


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.webui;
24
25 import org.meshcms.util.*;
26
27 /**
28  * A simple class to store path and names of files selected with the cut and
29  * copy features of the file manager.
30  */

31 public class FileClipboard {
32   private Path dirPath;
33   private String JavaDoc[] fileNames;
34   private boolean cut;
35
36   /**
37    * Creates a new clipboard (usually one clipboard per session should be used).
38    */

39   public FileClipboard() {
40   }
41
42   /**
43    * Sets the content of the clipboard.
44    *
45    * @param dirPath the path of the directory where the files are located
46    * @param names a comma-separated list of the file names
47    * @param cut true for the "cut" operation, false for the "copy"
48    */

49   public void setContent(Path dirPath, String JavaDoc names, boolean cut) {
50     this.dirPath = dirPath;
51     fileNames = Utils.tokenize(names, ",");
52     this.cut = cut;
53   }
54
55   /**
56    * Retrieves the content of the clipboard.
57    *
58    * @return an array of file paths
59    */

60   public Path[] getContent() {
61     if (dirPath == null || fileNames == null || fileNames.length == 0) {
62       return null;
63     }
64
65     Path[] paths = new Path[fileNames.length];
66
67     for (int i = 0; i < paths.length; i++) {
68       paths[i] = dirPath.add(fileNames[i]);
69     }
70
71     return paths;
72   }
73
74   /**
75    * Marks the clipboard as empty.
76    */

77   public void clear() {
78     dirPath = null;
79     fileNames = null;
80     cut = false;
81   }
82
83   /**
84    * @return the number of files in the clipboard.
85    */

86   public int countFiles() {
87     return fileNames == null ? 0 : fileNames.length;
88   }
89
90   /**
91    * @return the path of the directory where the files are located
92    */

93   public Path getDirPath() {
94     return dirPath;
95   }
96
97   /**
98    * @return the file names.
99    */

100   public String JavaDoc[] getFileNames() {
101     return fileNames;
102   }
103
104   /**
105    * @return true for the "cut" operation, false for the "copy"
106    */

107   public boolean isCut() {
108     return cut;
109   }
110 }
111
Popular Tags