📄 filesystemform.java
字号:
package com.sslexplorer.vfs.forms;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.sslexplorer.policyframework.forms.AbstractResourcesForm;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.vfs.FileSystemItem;
import com.sslexplorer.vfs.FileSystemItemModel;
import com.sslexplorer.vfs.NetworkPlace;
import com.sslexplorer.vfs.VFSPath;
import com.sslexplorer.vfs.clipboard.Clipboard;
import com.sslexplorer.vfs.webdav.DAVUtilities;
/**
* <p>
* The form that provides the data for file system view.
*
* @author James D Robinson
*
* @mail <a href="mailto:james@3sp.com"><james@3sp.com></a>
*/
public class FileSystemForm extends AbstractResourcesForm {
private static final long serialVersionUID = -8944288890287463553L;
static Log log = LogFactory.getLog(FileSystemForm.class);
private String path;
private boolean confirmDeletion;
private String newFolder;
private String newName;
private String fileName;
private int resourceId;
private NetworkPlace networkPlace;
private List paths;
private boolean viewOnly;
/**
* Constructor that sets up the form.
*/
public FileSystemForm() {
super(new FileSystemItemModel("fileSystem"));
this.path = null;
this.confirmDeletion = false;
this.newFolder = null;
this.newName = null;
this.fileName = null;
this.networkPlace = null;
this.paths = new ArrayList();
}
/**
* @return Object[] of the selected resources.
*/
public String[] getSelectedFileNames() {
List selected = new ArrayList();
for (Iterator i = getModel().getItems().iterator(); i.hasNext();) {
FileSystemItem ti = (FileSystemItem) i.next();
if (ti.getChecked())
selected.add(ti.getFileName());
}
return (String[]) selected.toArray(new String[selected.size()]);
}
/**
* @return weather the source resource is deleted after an operation, used
* on cut.
*/
public boolean isConfirmDeletion() {
return confirmDeletion;
}
/**
* @param confirmDeletion weather the resource should be deleted.
*/
public void setConfirmDeletion(boolean confirmDeletion) {
this.confirmDeletion = confirmDeletion;
}
/**
* @return The path to the current location.
*/
public String getPath() {
return path;
}
/**
* @param String path Sets the path to the current location.
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return String the path to the home of the network place.
*/
public String getHome() {
VFSPath tmp = (VFSPath) this.paths.get(0);
this.paths.clear();
this.paths.add(0, tmp);
return tmp.getPath();
}
/**
* @param String home sets the path to the home for this network place.
*/
public void setHome(String home) {
this.paths.add(new VFSPath(0, home));
}
public List getPaths() {
return this.paths;
}
/**
* @return int the id of the resource.
*/
public int getResourceId() {
return resourceId;
}
/**
* @return String the name of the new folder.
*/
public String getNewFolder() {
return newFolder;
}
/**
* @param newFolderString String to set the name of the new folder.
*/
public void setNewFolder(String newFolderString) {
this.newFolder = newFolderString;
}
/**
* @return String the name of the new name.
*/
public String getNewName() {
return newName;
}
/**
* @param newName String to set the name of the file.
*/
public void setNewName(String newName) {
this.newName = newName;
}
/**
* @return String of the file name selected.
*/
public String getFileName() {
return fileName;
}
/**
* @param fileName String of the file selected.
*/
public void setFileName(String fileName) {
this.fileName = fileName;
}
/**
* <p>
* Initialise the form.
*
* @param request The operation request.
* @param allFileSystemItems List of files to be viewed.
* @throws Exception
*/
public void initialize(HttpServletRequest request, List allFileSystemItems, SessionInfo session) throws Exception {
super.initialize(session.getHttpSession(), "name");
try {
Iterator i = allFileSystemItems.iterator();
while (i.hasNext()) {
FileSystemItem it = (FileSystemItem) i.next();
it.setSortFoldersFirst(true);
getModel().addItem(it);
}
getPager().setSortReverse(getSortReverse());
getPager().rebuild(getFilterText());
} catch (Throwable t) {
log.error("Failed to initialise resources form.", t);
}
}
/*
* (non-Javadoc)
*
* @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping,
* javax.servlet.http.HttpServletRequest)
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
viewOnly = true;
resourceId = -1;
this.confirmDeletion = false;
}
/**
* Set the folder to be read / write. By default a form is view only, this
* method must be called before any write functions are allowed.
*
*/
public void setReadWrite() {
viewOnly = false;
}
/**
* Get if this should be <i>view only</i>. For a folder to not be view
* only, {@link #setReadWrite()} must have been called
*
* @return view only
*/
public boolean isViewOnly() {
return viewOnly;
}
/**
* @return The network place acossiated with the file system view.
*/
public NetworkPlace getNetworkPlace() {
return networkPlace;
}
/**
* @param networkPlace Set the networkplace.
*/
public void setNetworkPlace(NetworkPlace networkPlace) {
this.networkPlace = networkPlace;
}
/**
* @param path The path to add or go to.
*/
public void addPath(String path) {
VFSPath newPath = new VFSPath(this.paths.size(), path);
VFSPath oldPath = null;
boolean add = true;
List newPaths = new ArrayList();
Iterator iter = this.paths.iterator();
while (iter.hasNext()) {
VFSPath element = (VFSPath) iter.next();
if (element.getPath().equals(newPath.getPath())) {
add = false;
newPaths.add(element);
break;
} else {
newPaths.add(element);
}
}
this.paths = newPaths;
if (add)
this.paths.add(newPath);
}
/**
* @param _id The position to move to...
*/
public void clearPathsTo(String _id) {
int id = Integer.parseInt(_id);
Iterator iter = this.paths.iterator();
List newPaths = new ArrayList();
while (iter.hasNext()) {
VFSPath element = (VFSPath) iter.next();
if (element.getPosition() <= id)
newPaths.add(element);
}
this.paths = newPaths;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
/*
* NOTE This done to avoid double slashes between folder names.
*/
if ("list".equals(getActionTarget())) {
if (this.getPath().endsWith("/")) {
this.setPath(this.getPath().substring(0, this.getPath().length() - 1));
}
}
return super.validate(mapping, request);
}
public String getFullURI() {
/*
* NOTE - BPS to JB. Its quite possible that a network place has not yet
* been initialised, in which case we cannot get this full path using
* this method
*/
if (networkPlace == null) {
return null;
} else {
StringTokenizer tok = new StringTokenizer(this.path, "/");
tok.nextToken(); // Important: skip the file type
tok.nextToken(); // Important: skip the root folder
String currentPath = this.networkPlace.getUri();
while (tok.hasMoreTokens()) {
String element = tok.nextToken();
currentPath += "\\" + element;
}
return currentPath;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -