mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 13:05:22 +02:00
[209704] move code for getting code page converter from activator to CodePageConverterManager utility class
This commit is contained in:
parent
e77a193982
commit
51a2ca0ee4
3 changed files with 156 additions and 127 deletions
|
@ -57,7 +57,6 @@ import org.eclipse.dstore.core.model.DataStoreResources;
|
||||||
import org.eclipse.dstore.core.model.IDataStoreProvider;
|
import org.eclipse.dstore.core.model.IDataStoreProvider;
|
||||||
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
|
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
|
||||||
import org.eclipse.rse.dstore.universal.miners.UniversalByteStreamHandler;
|
import org.eclipse.rse.dstore.universal.miners.UniversalByteStreamHandler;
|
||||||
import org.eclipse.rse.internal.services.Activator;
|
|
||||||
import org.eclipse.rse.internal.services.dstore.ServiceResources;
|
import org.eclipse.rse.internal.services.dstore.ServiceResources;
|
||||||
import org.eclipse.rse.services.clientserver.FileTypeMatcher;
|
import org.eclipse.rse.services.clientserver.FileTypeMatcher;
|
||||||
import org.eclipse.rse.services.clientserver.IMatcher;
|
import org.eclipse.rse.services.clientserver.IMatcher;
|
||||||
|
@ -72,6 +71,7 @@ import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
|
||||||
import org.eclipse.rse.services.dstore.AbstractDStoreService;
|
import org.eclipse.rse.services.dstore.AbstractDStoreService;
|
||||||
import org.eclipse.rse.services.dstore.util.DownloadListener;
|
import org.eclipse.rse.services.dstore.util.DownloadListener;
|
||||||
import org.eclipse.rse.services.dstore.util.FileSystemMessageUtil;
|
import org.eclipse.rse.services.dstore.util.FileSystemMessageUtil;
|
||||||
|
import org.eclipse.rse.services.files.CodePageConverterManager;
|
||||||
import org.eclipse.rse.services.files.IFileService;
|
import org.eclipse.rse.services.files.IFileService;
|
||||||
import org.eclipse.rse.services.files.IFileServiceCodePageConverter;
|
import org.eclipse.rse.services.files.IFileServiceCodePageConverter;
|
||||||
import org.eclipse.rse.services.files.IHostFile;
|
import org.eclipse.rse.services.files.IHostFile;
|
||||||
|
@ -489,10 +489,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
||||||
|
|
||||||
int localLineSepLength = localLineSep.length();
|
int localLineSepLength = localLineSep.length();
|
||||||
|
|
||||||
IFileServiceCodePageConverter codePageConverter = Activator.getCodePageConverter(hostEncoding, this);
|
IFileServiceCodePageConverter codePageConverter = CodePageConverterManager.getCodePageConverter(hostEncoding, this);
|
||||||
if (codePageConverter == null) {
|
|
||||||
codePageConverter = Activator.getDefaultCodePageConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
// upload bytes while available
|
// upload bytes while available
|
||||||
while (available > 0 && !isCancelled)
|
while (available > 0 && !isCancelled)
|
||||||
|
@ -788,12 +785,10 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
||||||
if (resultChild.getType().equals(IUniversalDataStoreConstants.DOWNLOAD_RESULT_SUCCESS_TYPE))
|
if (resultChild.getType().equals(IUniversalDataStoreConstants.DOWNLOAD_RESULT_SUCCESS_TYPE))
|
||||||
{
|
{
|
||||||
if (!isBinary){ // do standard conversion if this is text!
|
if (!isBinary){ // do standard conversion if this is text!
|
||||||
String localEncoding = System.getProperty("file.encoding");
|
String localEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IFileServiceCodePageConverter codePageConverter = CodePageConverterManager.getCodePageConverter(encoding, this);
|
||||||
|
|
||||||
IFileServiceCodePageConverter codePageConverter = Activator.getCodePageConverter(encoding, this);
|
|
||||||
if (codePageConverter == null) {
|
|
||||||
codePageConverter = Activator.getDefaultCodePageConverter();
|
|
||||||
}
|
|
||||||
codePageConverter.convertFileFromRemoteEncoding(localFile, encoding, localEncoding, this);
|
codePageConverter.convertFileFromRemoteEncoding(localFile, encoding, localEncoding, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1011,6 +1006,8 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
||||||
List resultList = remoteElement.getNestedData();
|
List resultList = remoteElement.getNestedData();
|
||||||
DataElement resultChild = null;
|
DataElement resultChild = null;
|
||||||
|
|
||||||
|
if (resultList != null)
|
||||||
|
{
|
||||||
for (int i = 0; i < resultList.size(); i++)
|
for (int i = 0; i < resultList.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1020,11 +1017,9 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
||||||
{
|
{
|
||||||
// do standard conversion if this is text!
|
// do standard conversion if this is text!
|
||||||
if (!isBinaries[i]){ // do standard conversion if this is text!
|
if (!isBinaries[i]){ // do standard conversion if this is text!
|
||||||
String localEncoding = System.getProperty("file.encoding");
|
String localEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||||
IFileServiceCodePageConverter codePageConverter = Activator.getCodePageConverter(hostEncodings[i], this);
|
IFileServiceCodePageConverter codePageConverter = CodePageConverterManager.getCodePageConverter(hostEncodings[i], this);
|
||||||
if (codePageConverter == null) {
|
|
||||||
codePageConverter = Activator.getDefaultCodePageConverter();
|
|
||||||
}
|
|
||||||
codePageConverter.convertFileFromRemoteEncoding(localFile, hostEncodings[i], localEncoding, this);
|
codePageConverter.convertFileFromRemoteEncoding(localFile, hostEncodings[i], localEncoding, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1066,6 +1061,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
|
||||||
//monitor.done();
|
//monitor.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.eclipse.rse.internal.services;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
@ -36,8 +35,7 @@ import org.osgi.framework.Bundle;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
|
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
|
||||||
import org.eclipse.rse.services.files.DefaultFileServiceCodePageConverter;
|
import org.eclipse.rse.services.files.CodePageConverterManager;
|
||||||
import org.eclipse.rse.services.files.IFileService;
|
|
||||||
import org.eclipse.rse.services.files.IFileServiceCodePageConverter;
|
import org.eclipse.rse.services.files.IFileServiceCodePageConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,8 +46,6 @@ public class Activator extends Plugin {
|
||||||
//The shared instance.
|
//The shared instance.
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
|
||||||
private static IFileServiceCodePageConverter _defaultCodePageConverter;
|
|
||||||
protected static Vector _codePageConverters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor.
|
* The constructor.
|
||||||
|
@ -130,24 +126,23 @@ public class Activator extends Plugin {
|
||||||
|
|
||||||
private void registerCodePageConverters()
|
private void registerCodePageConverters()
|
||||||
{
|
{
|
||||||
if (_codePageConverters == null) {
|
|
||||||
// retrieve all extension points
|
// retrieve all extension points
|
||||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||||
IExtensionPoint ep = registry.getExtensionPoint("org.eclipse.rse.services", "codePageConverters"); //$NON-NLS-1$
|
IExtensionPoint ep = registry.getExtensionPoint("org.eclipse.rse.services", "codePageConverters"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
if (ep != null){
|
if (ep != null){
|
||||||
IExtension[] extensions = ep.getExtensions();
|
IExtension[] extensions = ep.getExtensions();
|
||||||
_codePageConverters = new Vector();
|
|
||||||
for (int i = 0; i < extensions.length; i++) {
|
for (int i = 0; i < extensions.length; i++) {
|
||||||
IExtension extension = extensions[i];
|
IExtension extension = extensions[i];
|
||||||
IConfigurationElement[] configElements = extension.getConfigurationElements();
|
IConfigurationElement[] configElements = extension.getConfigurationElements();
|
||||||
for (int j = 0; j < configElements.length; j++) {
|
for (int j = 0; j < configElements.length; j++) {
|
||||||
IConfigurationElement element = configElements[j];
|
IConfigurationElement element = configElements[j];
|
||||||
if (element.getName().equalsIgnoreCase("codePageConverter")) {
|
if (element.getName().equalsIgnoreCase("codePageConverter")) { //$NON-NLS-1$
|
||||||
try {
|
try {
|
||||||
Object codePageConverter = element.createExecutableExtension("class");
|
Object codePageConverter = element.createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
if (codePageConverter!=null && codePageConverter instanceof IFileServiceCodePageConverter){
|
if (codePageConverter!=null && codePageConverter instanceof IFileServiceCodePageConverter){
|
||||||
// only save extension point which implement the correct interface
|
// only save extension point which implement the correct interface
|
||||||
_codePageConverters.add(codePageConverter);
|
CodePageConverterManager.registerCodePageConverter((IFileServiceCodePageConverter)codePageConverter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CoreException e) {
|
catch (CoreException e) {
|
||||||
|
@ -160,49 +155,6 @@ public class Activator extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_defaultCodePageConverter == null){
|
|
||||||
_defaultCodePageConverter = new DefaultFileServiceCodePageConverter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IFileServiceCodePageConverter getDefaultCodePageConverter()
|
|
||||||
{
|
|
||||||
return _defaultCodePageConverter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the first codepage converter provided via the codePageConverter extension point for the specified
|
|
||||||
* encoding
|
|
||||||
* @param serverEncoding The server encoding for which to retrieve a code page converter
|
|
||||||
* @return A code page converter for the specified encoding, or null if no converter was found for that encoding.
|
|
||||||
*/
|
|
||||||
public static IFileServiceCodePageConverter getCodePageConverter(String serverEncoding, IFileService fileService) {
|
|
||||||
|
|
||||||
IFileServiceCodePageConverter matchingCodePageConverter = null;
|
|
||||||
if (_codePageConverters != null)
|
|
||||||
{
|
|
||||||
|
|
||||||
//scan through the available converters and return the first valid one for the specified encoding for this
|
|
||||||
// subsystem implementation
|
|
||||||
for (int i=0; i<_codePageConverters.size(); i++) {
|
|
||||||
IFileServiceCodePageConverter codePageConverter = (IFileServiceCodePageConverter)_codePageConverters.elementAt(i);
|
|
||||||
if (codePageConverter.isServerEncodingSupported(serverEncoding, fileService))
|
|
||||||
{
|
|
||||||
if (matchingCodePageConverter != null){
|
|
||||||
int matchingPriority = matchingCodePageConverter.getPriority(serverEncoding, fileService);
|
|
||||||
int newPriority = codePageConverter.getPriority(serverEncoding, fileService);
|
|
||||||
if (newPriority < matchingPriority){
|
|
||||||
matchingCodePageConverter = codePageConverter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
matchingCodePageConverter = codePageConverter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matchingCodePageConverter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs an throwable to the log for this plugin.
|
* Logs an throwable to the log for this plugin.
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
/********************************************************************************
|
||||||
|
* Copyright (c) 2007 IBM Corporation. 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
|
||||||
|
*
|
||||||
|
* Initial Contributors:
|
||||||
|
* The following IBM employees contributed to the Remote System Explorer
|
||||||
|
* component that contains this file: David McKnight.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* {Name} (company) - description of contribution.
|
||||||
|
* David McKnight (IBM) - [209704] [api] Ability to override default encoding conversion needed.
|
||||||
|
********************************************************************************/
|
||||||
|
package org.eclipse.rse.services.files;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for getting a file service code page converter for a given server encoding and file service
|
||||||
|
*/
|
||||||
|
public class CodePageConverterManager {
|
||||||
|
|
||||||
|
|
||||||
|
private static IFileServiceCodePageConverter _defaultCodePageConverter;
|
||||||
|
protected static Vector _codePageConverters = new Vector();
|
||||||
|
|
||||||
|
public static void registerCodePageConverter(IFileServiceCodePageConverter converter)
|
||||||
|
{
|
||||||
|
_codePageConverters.add(converter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IFileServiceCodePageConverter getDefaultCodePageConverter()
|
||||||
|
{
|
||||||
|
if (_defaultCodePageConverter == null){
|
||||||
|
_defaultCodePageConverter = new DefaultFileServiceCodePageConverter();
|
||||||
|
}
|
||||||
|
return _defaultCodePageConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the first codepage converter provided via the codePageConverter extension point for the specified
|
||||||
|
* encoding
|
||||||
|
* @param serverEncoding The server encoding for which to retrieve a code page converter
|
||||||
|
* @return A code page converter for the specified encoding, or null if no converter was found for that encoding.
|
||||||
|
*/
|
||||||
|
public static IFileServiceCodePageConverter getCodePageConverter(String serverEncoding, IFileService fileService) {
|
||||||
|
|
||||||
|
IFileServiceCodePageConverter matchingCodePageConverter = null;
|
||||||
|
if (_codePageConverters != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
//scan through the available converters and return the first valid one for the specified encoding for this
|
||||||
|
// subsystem implementation
|
||||||
|
for (int i=0; i<_codePageConverters.size(); i++) {
|
||||||
|
IFileServiceCodePageConverter codePageConverter = (IFileServiceCodePageConverter)_codePageConverters.elementAt(i);
|
||||||
|
if (codePageConverter.isServerEncodingSupported(serverEncoding, fileService))
|
||||||
|
{
|
||||||
|
if (matchingCodePageConverter != null){
|
||||||
|
int matchingPriority = matchingCodePageConverter.getPriority(serverEncoding, fileService);
|
||||||
|
int newPriority = codePageConverter.getPriority(serverEncoding, fileService);
|
||||||
|
if (newPriority < matchingPriority){
|
||||||
|
matchingCodePageConverter = codePageConverter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
matchingCodePageConverter = codePageConverter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchingCodePageConverter == null)
|
||||||
|
{
|
||||||
|
matchingCodePageConverter = _defaultCodePageConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchingCodePageConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue