blob: eb249ec97bb594cd37d5b4f6c0fadde6327b1009 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.ptp.remote.internal.core;
import java.net.URI;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ptp.remote.core.IRemoteFileManager;
public class LocalFileManager implements IRemoteFileManager {
private IPath fWorkingDir = null;
/* (non-Javadoc)
* @see org.eclipse.ptp.remote.core.IRemoteFileManager#getResource(java.lang.String)
*/
public IFileStore getResource(String pathStr) {
IPath path = new Path(pathStr);
if (!path.isAbsolute()) {
path = getWorkingDirectoryPath().append(path);
}
return EFS.getLocalFileSystem().getStore(path);
}
/* (non-Javadoc)
* @see org.eclipse.ptp.remote.core.IRemoteFileManager#getWorkingDirectory(org.eclipse.core.runtime.IProgressMonitor)
*/
public String getWorkingDirectory() {
return getWorkingDirectoryPath().toString();
}
/* (non-Javadoc)
* @see org.eclipse.ptp.remote.core.IRemoteFileManager#setWorkingDirectory(java.lang.String)
*/
public void setWorkingDirectory(String pathStr) {
IPath path = new Path(pathStr);
if (path.isAbsolute()) {
fWorkingDir = path;
}
}
/* (non-Javadoc)
* @see org.eclipse.ptp.remote.core.IRemoteFileManager#toPath(java.net.URI)
*/
public String toPath(URI uri) {
return URIUtil.toPath(uri).toString();
}
/* (non-Javadoc)
* @see org.eclipse.ptp.remote.core.IRemoteFileManager#toURI(org.eclipse.core.runtime.IPath)
*/
public URI toURI(IPath path) {
return URIUtil.toURI(path);
}
/* (non-Javadoc)
* @see org.eclipse.ptp.remote.core.IRemoteFileManager#toURI(java.lang.String)
*/
public URI toURI(String path) {
return URIUtil.toURI(path);
}
private IPath getWorkingDirectoryPath() {
if (fWorkingDir == null) {
String home = System.getProperty("user.home"); //$NON-NLS-1$
if (home != null) {
fWorkingDir = new Path(home);
} else {
fWorkingDir = new Path("."); //$NON-NLS-1$
}
}
return fWorkingDir;
}
}