1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-27 10:55:33 +02:00

[api] [163820] Allow encodings to be queried for IRemoteFile and implementations for encodings through a remote file encoding manager.

This commit is contained in:
Kushal Munir 2007-02-06 15:23:19 +00:00
parent 51ae4ccdf6
commit e7d2f267ca
8 changed files with 101 additions and 17 deletions

View file

@ -33,6 +33,7 @@ import org.eclipse.rse.ui.propertypages.SystemBasePropertyPage;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
@ -52,10 +53,16 @@ public class SystemFilePropertyPage extends SystemBasePropertyPage
//protected Button cbReadablePrompt, cbWritablePrompt; //protected Button cbReadablePrompt, cbWritablePrompt;
protected Button cbReadonlyPrompt, cbHiddenPrompt; protected Button cbReadonlyPrompt, cbHiddenPrompt;
protected Label labelName, labelType, labelPath, labelSize, labelModified, labelReadable, labelWritable, labelHidden; protected Label labelName, labelType, labelPath, labelSize, labelModified, labelReadable, labelWritable, labelHidden;
protected Button inheritedEncodingButton, otherEncodingButton;
protected Combo otherEncodingCombo;
protected String errorMessage; protected String errorMessage;
protected boolean initDone = false; protected boolean initDone = false;
protected boolean wasReadOnly = false; protected boolean wasReadOnly = false;
private boolean encodingFieldAdded = false;
private String defaultEncoding = null;
private boolean isValidBefore = true;
/** /**
* Constructor for SystemFilterPropertyPage * Constructor for SystemFilterPropertyPage
*/ */

View file

@ -61,6 +61,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
private int _bufferUploadSize = IUniversalDataStoreConstants.BUFFER_SIZE; private int _bufferUploadSize = IUniversalDataStoreConstants.BUFFER_SIZE;
private int _bufferDownloadSize = IUniversalDataStoreConstants.BUFFER_SIZE; private int _bufferDownloadSize = IUniversalDataStoreConstants.BUFFER_SIZE;
protected ISystemFileTypes _fileTypeRegistry; protected ISystemFileTypes _fileTypeRegistry;
private String remoteEncoding;
private static String _percentMsg = SystemMessage.sub(SystemMessage.sub(SystemMessage.sub(ServiceResources.DStore_Service_Percent_Complete_Message, "&0", "{0}"), "&1", "{1}"), "&2", "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ private static String _percentMsg = SystemMessage.sub(SystemMessage.sub(SystemMessage.sub(ServiceResources.DStore_Service_Percent_Complete_Message, "&0", "{0}"), "&1", "{1}"), "&2", "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
@ -1274,6 +1275,26 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
return false; return false;
} }
/**
* Queries the remote system for the platform encoding.
* @see org.eclipse.rse.services.files.IFileService#getEncoding(org.eclipse.core.runtime.IProgressMonitor)
* @since 2.0
*/
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException {
if (remoteEncoding == null) {
DataStore ds = getDataStore();
DataElement encodingElement = ds.createObject(null, UNIVERSAL_TEMP_DESCRIPTOR, ""); //$NON-NLS-1$
DataElement queryCmd = ds.localDescriptorQuery(encodingElement.getDescriptor(), C_SYSTEM_ENCODING);
DataElement status = ds.command(queryCmd, encodingElement, true);
remoteEncoding = encodingElement.getValue();
}
return remoteEncoding;
}
} }

View file

@ -88,8 +88,6 @@ public class LocalFileService extends AbstractFileService implements IFileServic
public LocalFileService(ISystemFileTypes fileTypeRegistry) public LocalFileService(ISystemFileTypes fileTypeRegistry)
{ {
_fileTypeRegistry = fileTypeRegistry; _fileTypeRegistry = fileTypeRegistry;
} }

View file

@ -94,5 +94,12 @@ public abstract class AbstractFileService implements IFileService
return ok; return ok;
} }
/**
* Returns the local platform encoding by default. Subclasses should override to return the actual remote encoding.
* @see org.eclipse.rse.services.files.IFileService#getEncoding(org.eclipse.core.runtime.IProgressMonitor)
* @since 2.0
*/
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException {
return System.getProperty("file.encoding");
}
} }

View file

@ -284,4 +284,13 @@ public interface IFileService extends IService
* @return true if the readonly permission was changed successfully * @return true if the readonly permission was changed successfully
*/ */
public boolean setReadOnly(IProgressMonitor monitor, String parent, String name, boolean readOnly) throws SystemMessageException; public boolean setReadOnly(IProgressMonitor monitor, String parent, String name, boolean readOnly) throws SystemMessageException;
/**
* Gets the remote encoding.
* @param monitor the progress monitor.
* @return the encoding.
* @throws SystemMessageException if an error occurs.
* @since 2.0
*/
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException;
} }

View file

@ -119,13 +119,6 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
return _hostFileToRemoteFileAdapter; return _hostFileToRemoteFileAdapter;
} }
public String getRemoteEncoding()
{
return System.getProperty("file.encoding"); //$NON-NLS-1$
}
public void setHostFileToRemoteFileAdapter(IHostFileToRemoteFileAdapter hostFileAdapter) public void setHostFileToRemoteFileAdapter(IHostFileToRemoteFileAdapter hostFileAdapter)
{ {
_hostFileToRemoteFileAdapter = hostFileAdapter; _hostFileToRemoteFileAdapter = hostFileAdapter;
@ -899,4 +892,22 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
_userHome = null; _userHome = null;
} }
/**
* Returns the encoding from the file service being used by this subsystem.
* @see RemoteFileSubSystem#getRemoteEncoding()
*/
public String getRemoteEncoding() {
String encoding = null;
try {
encoding = getFileService().getEncoding(null);
}
catch (SystemMessageException e) {
SystemMessageDialog dlg = new SystemMessageDialog(getShell(), e.getSystemMessage());
dlg.open();
encoding = super.getRemoteEncoding();
}
return encoding;
}
} }

View file

@ -215,11 +215,27 @@ public interface IRemoteFileSubSystem extends ISubSystem{
public String getParentFolderName(IRemoteFile folderOrFile); public String getParentFolderName(IRemoteFile folderOrFile);
/** /**
* Get the default encoding of the target system * Returns whether the file subsystem supports encodings. There are file subsystems that deal with codepages and encodings
* @return the encoding * using other mechanisms besides encodings, and such platforms should return <code>false</code>. Other file subsystems
* may not deal with encodings at all.
* @return <code>true<code> if the file subsystem supports encodings, <code>false</code> otherwise.
* @since 2.0
*/
public boolean supportsEncoding();
/**
* Returns the encoding of the remote system.
* @return the encoding of the remote system.
*/ */
public String getRemoteEncoding(); public String getRemoteEncoding();
/**
* Returns the encoding of the file with the remote path.
* @param remotePath the remote path of the file.
* @return the encoding of the remote file.
*/
// public String getEncoding(String remotePath);
/** /**
* Given a set of fully qualified file or folder names, return an ISystemResourceSet object for it. * Given a set of fully qualified file or folder names, return an ISystemResourceSet object for it.
* @param folderOrFileNames Fully qualified folder or file names * @param folderOrFileNames Fully qualified folder or file names

View file

@ -1742,8 +1742,6 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
return null; return null;
} }
/** /**
* @deprecated * @deprecated
*/ */
@ -1752,4 +1750,21 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/**
* Returns <code>true</code> by default. Subclasses should override if they do not support encodings.
* @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#supportsEncoding()
* @since 2.0
*/
public boolean supportsEncoding() {
return true;
}
/**
* Returns the local platform encoding by default. Subclasses should override to return the actual remote encoding.
* @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#getRemoteEncoding()
*/
public String getRemoteEncoding() {
return System.getProperty("file.encoding");
}
} }