📄 cifsmount.java
字号:
package com.sslexplorer.vfs.store.cifs;
import java.io.IOException;
import java.net.URLDecoder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
import com.sslexplorer.boot.Util;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.vfs.NetworkPlace;
import com.sslexplorer.vfs.utils.URI;
import com.sslexplorer.vfs.utils.URI.MalformedURIException;
import com.sslexplorer.vfs.webdav.AbstractNetworkPlaceMount;
import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException;
import com.sslexplorer.vfs.webdav.DAVStore;
import com.sslexplorer.vfs.webdav.DAVTransaction;
import com.sslexplorer.vfs.webdav.DAVUtilities;
/**
* <p>
* CIFSMount is an implementation of <@link
* com.sslexplorer.vfs.webdav.AbstractMount> for use with smb paths and also
* Windows Network Neighborhood.
*
* @author James D Robinson <a href="mailto:james@3sp.com"><james@3sp.com></a>
*
*/
public class CIFSMount extends AbstractNetworkPlaceMount {
final static Log log = LogFactory.getLog(CIFSMount.class);
/**
* <p>
* Constructor for creating the mount.
*
* @param networkPlace
* @param store
*/
public CIFSMount(NetworkPlace networkPlace, DAVStore store) {
super(networkPlace, store);
}
/* (non-Javadoc)
* @see com.sslexplorer.vfs.webdav.AbstractNetworkPlaceMount#getRootVFSURI(com.sslexplorer.vfs.webdav.DAVTransaction)
*/
public URI getRootVFSURI(DAVTransaction transaction, String charset) throws MalformedURIException {
try {
return super.getRootVFSURI(transaction, charset);
}
catch(MalformedURIException muri) {
String npath ="smb:" + getNetworkPlace().getUri().replace("\\\\", "/");
return DAVUtilities.processAndEncodeURI(npath, transaction.getSessionInfo(), charset);
}
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.vfs.webdav.DAVMount#createRoot(java.lang.String,
* com.sslexplorer.vfs.webdav.DAVTransaction)
*/
public FileObject createVFSFileObject(String path, DAVTransaction transaction) throws IOException, DAVAuthenticationRequiredException {
if (this.getNetworkPlace().getUri().equals("smb://")) {
return wnnCIFS(path, transaction);
} else {
return standardCIFS(path, transaction);
}
}
/**
* <p>
* Method to perform the Windows Network Neighborhood fvs navigation.
*
* @param path The path from the root of the mount.
* @param transaction The session transaction.
* @return The FileObject for the path.
* @throws MalformedURIException thrown if the uri is malformed.
* @throws DAVAuthenticationRequiredException thrown if there is a problem
* with the authentication
* @throws FileSystemException Thrown if there is something wrong with the
* file system connection.
*/
private FileObject wnnCIFS(String path, DAVTransaction transaction) throws MalformedURIException,
DAVAuthenticationRequiredException, FileSystemException {
try {
URI uri = getRootVFSURI(transaction, System.getProperty("jcifs.encoding", "cp860"));
// if (transaction.getCurrentCredentials() != null) {
// uri.setUserinfo(DAVUtilities.encodeURIUserInfo(transaction.getCurrentCredentials().getUserInfoString()));
// }
uri.setUserinfo(null);
// to check weather it is the root of a workgroup/domain if it is
// use it, if its a child
// then the workgroup/domain needs removing.
if (path.equals("")) {
uri.setPath(uri.getPath() + DAVUtilities.encodePath(path));
} else {
uri.setPath(path.substring(path.indexOf("/") + 1));
}
FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
if (root.getType().equals(FileType.FOLDER)) {
// extra chack so that the correct exception is thrown.
root.getChildren();
}
return root;
} catch (FileSystemException fse) {
if (fse.getCause().getClass().getName().equals("jcifs.smb.SmbAuthException")) {
throw new DAVAuthenticationRequiredException(this, true);
}
throw fse;
}
}
/**
* <p>
* Method to perform the smb fvs navigation.
*
* @param path The path from the root of the mount.
* @param transaction The session transaction.
* @return The FileObject for the path.
* @throws MalformedURIException thrown if the uri is malformed.
* @throws DAVAuthenticationRequiredException thrown if there is a problem
* with the authentication
* @throws FileSystemException Thrown if there is something wrong with the
* file system connection.
*/
private FileObject standardCIFS(String path, DAVTransaction transaction) throws MalformedURIException,
DAVAuthenticationRequiredException, FileSystemException {
try {
URI uri = getRootVFSURI(transaction, System.getProperty("jcifs.encoding", "cp860"));
if (transaction.getCurrentCredentials() != null) {
uri.setUserinfo(DAVUtilities.encodeURIUserInfo(transaction.getCurrentCredentials().getUserInfoString()));
}
uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path, System.getProperty("jcifs.encoding", "cp860")));
FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
if (root.getType().equals(FileType.FOLDER)) {
// extra chack so that the correct exception is thrown.
root.getChildren();
}
return root;
} catch (FileSystemException fse) {
if (fse.getCause().getClass().getName().equals("jcifs.smb.SmbAuthException")) {
throw new DAVAuthenticationRequiredException(this, true);
}
throw fse;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -