mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-16 13:35:22 +02:00
[ftp] Avoid NPE when remote doesnt send system type
This commit is contained in:
parent
76ff946105
commit
3db44ba3b2
1 changed files with 53 additions and 46 deletions
|
@ -1,9 +1,9 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (c) 2007, 2008 Symbian Software Ltd. All rights reserved.
|
* Copyright (c) 2007, 2008 Symbian Software Ltd. All rights reserved.
|
||||||
* This program and the accompanying materials are made available under the terms
|
* 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
|
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Javier Montalvo Orus (Symbian) - initial API and implementation
|
* Javier Montalvo Orus (Symbian) - initial API and implementation
|
||||||
* Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
|
* Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
|
||||||
|
@ -30,12 +30,12 @@ import org.osgi.framework.Bundle;
|
||||||
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
|
|
||||||
private static FTPClientConfigFactory factory = null;
|
private static FTPClientConfigFactory factory = null;
|
||||||
|
|
||||||
private Hashtable ftpConfigProxyById = new Hashtable();
|
private Hashtable ftpConfigProxyById = new Hashtable();
|
||||||
private Hashtable ftpParsers = new Hashtable();
|
private Hashtable ftpParsers = new Hashtable();
|
||||||
private IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.rse.subsystems.files.ftp","ftpListingParsers"); //$NON-NLS-1$ //$NON-NLS-2$
|
private IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.rse.subsystems.files.ftp","ftpListingParsers"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
private UnixFTPEntryParser defaultFTPEntryParser = new UnixFTPEntryParser();
|
private UnixFTPEntryParser defaultFTPEntryParser = new UnixFTPEntryParser();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the parser factory
|
* Constructor of the parser factory
|
||||||
* @return an instance of the factory
|
* @return an instance of the factory
|
||||||
|
@ -46,72 +46,76 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
{
|
{
|
||||||
factory = new FTPClientConfigFactory();
|
factory = new FTPClientConfigFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FTPClientConfigFactory() {
|
private FTPClientConfigFactory() {
|
||||||
|
|
||||||
IConfigurationElement[] ce = ep.getConfigurationElements();
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
for (int i = 0; i < ce.length; i++) {
|
for (int i = 0; i < ce.length; i++) {
|
||||||
|
|
||||||
String id = ce[i].getAttribute("id"); //$NON-NLS-1$
|
String id = ce[i].getAttribute("id"); //$NON-NLS-1$
|
||||||
String label = ce[i].getAttribute("label"); //$NON-NLS-1$
|
String label = ce[i].getAttribute("label"); //$NON-NLS-1$
|
||||||
String priority = ce[i].getAttribute("priority"); //$NON-NLS-1$
|
String priority = ce[i].getAttribute("priority"); //$NON-NLS-1$
|
||||||
String systemTypeRegex = ce[i].getAttribute("systemTypeRegex"); //$NON-NLS-1$
|
String systemTypeRegex = ce[i].getAttribute("systemTypeRegex"); //$NON-NLS-1$
|
||||||
String className = ce[i].getAttribute("class"); //$NON-NLS-1$
|
String className = ce[i].getAttribute("class"); //$NON-NLS-1$
|
||||||
Bundle declaringBundle = Platform.getBundle(ce[i].getContributor().getName());
|
Bundle declaringBundle = Platform.getBundle(ce[i].getContributor().getName());
|
||||||
|
|
||||||
String listCommandModifiers = ce[i].getAttribute("listCommandModifiers"); //$NON-NLS-1$
|
String listCommandModifiers = ce[i].getAttribute("listCommandModifiers"); //$NON-NLS-1$
|
||||||
|
|
||||||
String defaultDateFormatStr = ce[i].getAttribute("defaultDateFormatStr"); //$NON-NLS-1$
|
String defaultDateFormatStr = ce[i].getAttribute("defaultDateFormatStr"); //$NON-NLS-1$
|
||||||
String recentDateFormatStr = ce[i].getAttribute("recentDateFormatStr"); //$NON-NLS-1$
|
String recentDateFormatStr = ce[i].getAttribute("recentDateFormatStr"); //$NON-NLS-1$
|
||||||
String serverLanguageCode = ce[i].getAttribute("serverLanguageCode"); //$NON-NLS-1$
|
String serverLanguageCode = ce[i].getAttribute("serverLanguageCode"); //$NON-NLS-1$
|
||||||
String shortMonthNames = ce[i].getAttribute("shortMonthNames"); //$NON-NLS-1$
|
String shortMonthNames = ce[i].getAttribute("shortMonthNames"); //$NON-NLS-1$
|
||||||
String serverTimeZoneId = ce[i].getAttribute("serverTimeZoneId"); //$NON-NLS-1$
|
String serverTimeZoneId = ce[i].getAttribute("serverTimeZoneId"); //$NON-NLS-1$
|
||||||
|
|
||||||
IConfigurationElement[] initialCommandsSequence = ce[i].getChildren("initCommand"); //$NON-NLS-1$
|
IConfigurationElement[] initialCommandsSequence = ce[i].getChildren("initCommand"); //$NON-NLS-1$
|
||||||
String[] initialCommands = new String[initialCommandsSequence.length];
|
String[] initialCommands = new String[initialCommandsSequence.length];
|
||||||
|
|
||||||
for (int j = 0; j < initialCommands.length; j++) {
|
for (int j = 0; j < initialCommands.length; j++) {
|
||||||
initialCommands[j] = initialCommandsSequence[j].getAttribute("cmd"); //$NON-NLS-1$
|
initialCommands[j] = initialCommandsSequence[j].getAttribute("cmd"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
FTPClientConfigProxy ftpClientConfigProxy = new FTPClientConfigProxy(id,label,priority,systemTypeRegex,className,declaringBundle,listCommandModifiers,
|
FTPClientConfigProxy ftpClientConfigProxy = new FTPClientConfigProxy(id,label,priority,systemTypeRegex,className,declaringBundle,listCommandModifiers,
|
||||||
defaultDateFormatStr,recentDateFormatStr,serverLanguageCode,shortMonthNames,serverTimeZoneId, initialCommands);
|
defaultDateFormatStr,recentDateFormatStr,serverLanguageCode,shortMonthNames,serverTimeZoneId, initialCommands);
|
||||||
|
|
||||||
ftpConfigProxyById.put(id, ftpClientConfigProxy);
|
ftpConfigProxyById.put(id, ftpClientConfigProxy);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getFTPClientConfig(java.lang.String)
|
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getFTPClientConfig(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IFTPClientConfigProxy getFTPClientConfig(String parser, String systemName)
|
public IFTPClientConfigProxy getFTPClientConfig(String parser, String systemName)
|
||||||
{
|
{
|
||||||
|
if (systemName == null) {
|
||||||
|
// avoid NPE if systemName could not be determined
|
||||||
|
systemName = ""; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
FTPClientConfigProxy foundFTPClientConfigProxy = null;
|
FTPClientConfigProxy foundFTPClientConfigProxy = null;
|
||||||
|
|
||||||
if(parser.equals("AUTO")) //$NON-NLS-1$
|
if(parser.equals("AUTO")) //$NON-NLS-1$
|
||||||
{
|
{
|
||||||
int previousPriority = Integer.MAX_VALUE;
|
int previousPriority = Integer.MAX_VALUE;
|
||||||
FTPClientConfigProxy foundProxy = null;
|
FTPClientConfigProxy foundProxy = null;
|
||||||
|
|
||||||
Enumeration ftpConfigProxyEnum = ftpConfigProxyById.elements();
|
Enumeration ftpConfigProxyEnum = ftpConfigProxyById.elements();
|
||||||
|
|
||||||
while(ftpConfigProxyEnum.hasMoreElements())
|
while(ftpConfigProxyEnum.hasMoreElements())
|
||||||
{
|
{
|
||||||
FTPClientConfigProxy proxy = (FTPClientConfigProxy)ftpConfigProxyEnum.nextElement();
|
FTPClientConfigProxy proxy = (FTPClientConfigProxy)ftpConfigProxyEnum.nextElement();
|
||||||
|
|
||||||
if(proxy.getSystemTypeRegex()!=null)
|
if(proxy.getSystemTypeRegex()!=null)
|
||||||
{
|
{
|
||||||
Pattern ftpSystemTypesRegex = Pattern.compile(proxy.getSystemTypeRegex());
|
Pattern ftpSystemTypesRegex = Pattern.compile(proxy.getSystemTypeRegex());
|
||||||
if(ftpSystemTypesRegex.matcher(systemName).matches())
|
if(ftpSystemTypesRegex.matcher(systemName).matches())
|
||||||
{
|
{
|
||||||
int priority = proxy.getPriority();
|
int priority = proxy.getPriority();
|
||||||
|
|
||||||
if(priority < previousPriority)
|
if(priority < previousPriority)
|
||||||
{
|
{
|
||||||
foundProxy = proxy;
|
foundProxy = proxy;
|
||||||
|
@ -120,12 +124,12 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//process the selected proxy
|
//process the selected proxy
|
||||||
if(foundProxy != null)
|
if(foundProxy != null)
|
||||||
{
|
{
|
||||||
FTPClientConfig config = null;
|
FTPClientConfig config = null;
|
||||||
|
|
||||||
if(!ftpParsers.containsKey(foundProxy.getClassName()))
|
if(!ftpParsers.containsKey(foundProxy.getClassName()))
|
||||||
{
|
{
|
||||||
FTPFileEntryParser entryParser = null;
|
FTPFileEntryParser entryParser = null;
|
||||||
|
@ -140,37 +144,37 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
}
|
}
|
||||||
ftpParsers.put(foundProxy.getClassName(), entryParser);
|
ftpParsers.put(foundProxy.getClassName(), entryParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = new FTPClientConfig(foundProxy.getClassName());
|
config = new FTPClientConfig(foundProxy.getClassName());
|
||||||
|
|
||||||
//not necessary checking for null, as null is valid input
|
//not necessary checking for null, as null is valid input
|
||||||
config.setDefaultDateFormatStr(foundProxy.getDefaultDateFormatStr());
|
config.setDefaultDateFormatStr(foundProxy.getDefaultDateFormatStr());
|
||||||
config.setRecentDateFormatStr(foundProxy.getRecentDateFormatStr());
|
config.setRecentDateFormatStr(foundProxy.getRecentDateFormatStr());
|
||||||
config.setServerLanguageCode(foundProxy.getServerLanguageCode());
|
config.setServerLanguageCode(foundProxy.getServerLanguageCode());
|
||||||
config.setShortMonthNames(foundProxy.getShortMonthNames());
|
config.setShortMonthNames(foundProxy.getShortMonthNames());
|
||||||
config.setServerTimeZoneId(foundProxy.getServerTimeZoneId());
|
config.setServerTimeZoneId(foundProxy.getServerTimeZoneId());
|
||||||
|
|
||||||
//not necessary storing in the hashtable, as discovered will not be reused
|
//not necessary storing in the hashtable, as discovered will not be reused
|
||||||
foundProxy.setFTPClientConfig(config);
|
foundProxy.setFTPClientConfig(config);
|
||||||
|
|
||||||
foundFTPClientConfigProxy = foundProxy;
|
foundFTPClientConfigProxy = foundProxy;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(foundFTPClientConfigProxy==null)
|
if(foundFTPClientConfigProxy==null)
|
||||||
{
|
{
|
||||||
if(ftpConfigProxyById.containsKey(parser))
|
if(ftpConfigProxyById.containsKey(parser))
|
||||||
{
|
{
|
||||||
//restore parser from the proxy hashtable
|
//restore parser from the proxy hashtable
|
||||||
foundFTPClientConfigProxy = (FTPClientConfigProxy)ftpConfigProxyById.get(parser);
|
foundFTPClientConfigProxy = (FTPClientConfigProxy)ftpConfigProxyById.get(parser);
|
||||||
|
|
||||||
//activate if necessary
|
//activate if necessary
|
||||||
if(foundFTPClientConfigProxy.getFTPClientConfig()==null)
|
if(foundFTPClientConfigProxy.getFTPClientConfig()==null)
|
||||||
{
|
{
|
||||||
FTPClientConfig config = null;
|
FTPClientConfig config = null;
|
||||||
|
|
||||||
if(!ftpParsers.containsKey(foundFTPClientConfigProxy.getClassName()))
|
if(!ftpParsers.containsKey(foundFTPClientConfigProxy.getClassName()))
|
||||||
{
|
{
|
||||||
FTPFileEntryParser entryParser = null;
|
FTPFileEntryParser entryParser = null;
|
||||||
|
@ -185,25 +189,25 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
}
|
}
|
||||||
ftpParsers.put(foundFTPClientConfigProxy.getClassName(), entryParser);
|
ftpParsers.put(foundFTPClientConfigProxy.getClassName(), entryParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = new FTPClientConfig(foundFTPClientConfigProxy.getClassName());
|
config = new FTPClientConfig(foundFTPClientConfigProxy.getClassName());
|
||||||
|
|
||||||
//not necessary checking for null, as null is valid input
|
//not necessary checking for null, as null is valid input
|
||||||
config.setDefaultDateFormatStr(foundFTPClientConfigProxy.getDefaultDateFormatStr());
|
config.setDefaultDateFormatStr(foundFTPClientConfigProxy.getDefaultDateFormatStr());
|
||||||
config.setRecentDateFormatStr(foundFTPClientConfigProxy.getRecentDateFormatStr());
|
config.setRecentDateFormatStr(foundFTPClientConfigProxy.getRecentDateFormatStr());
|
||||||
config.setServerLanguageCode(foundFTPClientConfigProxy.getServerLanguageCode());
|
config.setServerLanguageCode(foundFTPClientConfigProxy.getServerLanguageCode());
|
||||||
config.setShortMonthNames(foundFTPClientConfigProxy.getShortMonthNames());
|
config.setShortMonthNames(foundFTPClientConfigProxy.getShortMonthNames());
|
||||||
config.setServerTimeZoneId(foundFTPClientConfigProxy.getServerTimeZoneId());
|
config.setServerTimeZoneId(foundFTPClientConfigProxy.getServerTimeZoneId());
|
||||||
|
|
||||||
foundFTPClientConfigProxy.setFTPClientConfig(config);
|
foundFTPClientConfigProxy.setFTPClientConfig(config);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundFTPClientConfigProxy;
|
return foundFTPClientConfigProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getKeySet()
|
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getKeySet()
|
||||||
|
@ -218,18 +222,21 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(java.lang.String)
|
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public FTPFileEntryParser createFileEntryParser(String key) throws ParserInitializationException {
|
public FTPFileEntryParser createFileEntryParser(String key) throws ParserInitializationException {
|
||||||
|
|
||||||
FTPFileEntryParser entryParser = null;
|
FTPFileEntryParser entryParser = null;
|
||||||
|
if (key == null) {
|
||||||
|
// avoid NPE in containsKey when the SYST command returned null
|
||||||
|
key = ""; //$NON-NLS-1$
|
||||||
|
}
|
||||||
if(!ftpParsers.containsKey(key))
|
if(!ftpParsers.containsKey(key))
|
||||||
{
|
{
|
||||||
entryParser = defaultFTPEntryParser;
|
entryParser = defaultFTPEntryParser;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entryParser = (FTPFileEntryParser)ftpParsers.get(key);
|
entryParser = (FTPFileEntryParser)ftpParsers.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entryParser;
|
return entryParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,10 +245,10 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(org.apache.commons.net.ftp.FTPClientConfig)
|
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory#createFileEntryParser(org.apache.commons.net.ftp.FTPClientConfig)
|
||||||
*/
|
*/
|
||||||
public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException {
|
public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException {
|
||||||
|
|
||||||
String key = config.getServerSystemKey();
|
String key = config.getServerSystemKey();
|
||||||
return createFileEntryParser(key);
|
return createFileEntryParser(key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue