mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 23:35:48 +02:00
[176216] parsers dynamically loaded when needed
This commit is contained in:
parent
23d19b52fe
commit
56c2add9e5
1 changed files with 86 additions and 39 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.rse.internal.subsystems.files.ftp.parser;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||||
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
||||||
|
@ -24,10 +25,12 @@ import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactor
|
||||||
|
|
||||||
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
|
||||||
|
|
||||||
private static FTPClientConfigFactory factory = null;
|
private static FTPClientConfigFactory factory = null;
|
||||||
|
|
||||||
|
private Set keySet = new TreeSet();
|
||||||
private Hashtable ftpConfig = new Hashtable();
|
private Hashtable ftpConfig = new Hashtable();
|
||||||
private Hashtable ftpFileEntryParser = new Hashtable();
|
private Hashtable ftpFileEntryParser = new Hashtable();
|
||||||
|
private IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.rse.subsystems.files.ftp","ftpFileEntryParser"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the parser factory
|
* Constructor of the parser factory
|
||||||
|
@ -45,44 +48,11 @@ private static FTPClientConfigFactory factory = null;
|
||||||
|
|
||||||
private FTPClientConfigFactory() {
|
private FTPClientConfigFactory() {
|
||||||
|
|
||||||
FTPClientConfig config = null;
|
|
||||||
|
|
||||||
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.rse.subsystems.files.ftp","ftpFileEntryParser"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
IConfigurationElement[] ce = ep.getConfigurationElements();
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
for (int i = 0; i < ce.length; i++) {
|
for (int i = 0; i < ce.length; i++) {
|
||||||
|
|
||||||
config = null;
|
String label = ce[i].getAttribute("name"); //$NON-NLS-1$
|
||||||
|
keySet.add(label);
|
||||||
String name = ce[i].getAttribute("name"); //$NON-NLS-1$
|
|
||||||
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
FTPFileEntryParser entryParser=null;
|
|
||||||
try {
|
|
||||||
entryParser = (FTPFileEntryParser)ce[i].createExecutableExtension("class"); //$NON-NLS-1$
|
|
||||||
} catch (CoreException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ftpFileEntryParser.put(clas, entryParser);
|
|
||||||
|
|
||||||
String defaultDateFormatStr = ce[i].getAttribute("defaultDateFormatStr"); //$NON-NLS-1$
|
|
||||||
String recentDateFormatStr = ce[i].getAttribute("recentDateFormatStr"); //$NON-NLS-1$
|
|
||||||
String serverLanguageCode = ce[i].getAttribute("serverLanguageCode"); //$NON-NLS-1$
|
|
||||||
String shortMonthNames = ce[i].getAttribute("shortMonthNames"); //$NON-NLS-1$
|
|
||||||
String serverTimeZoneId = ce[i].getAttribute("serverTimeZoneId"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
config = new FTPClientConfig(clas);
|
|
||||||
|
|
||||||
//not necessary checking for null, as null is valid input
|
|
||||||
config.setDefaultDateFormatStr(defaultDateFormatStr);
|
|
||||||
config.setRecentDateFormatStr(recentDateFormatStr);
|
|
||||||
config.setServerLanguageCode(serverLanguageCode);
|
|
||||||
config.setShortMonthNames(shortMonthNames);
|
|
||||||
config.setServerTimeZoneId(serverTimeZoneId);
|
|
||||||
|
|
||||||
ftpConfig.put(name, config);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +62,53 @@ private static FTPClientConfigFactory factory = null;
|
||||||
*/
|
*/
|
||||||
public FTPClientConfig getFTPClientConfig(String key)
|
public FTPClientConfig getFTPClientConfig(String key)
|
||||||
{
|
{
|
||||||
|
if(!ftpConfig.containsKey(key))
|
||||||
|
{
|
||||||
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
|
for (int i = 0; i < ce.length; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
String label = ce[i].getAttribute("name"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
if(label.equals(key))
|
||||||
|
{
|
||||||
|
|
||||||
|
FTPClientConfig config = null;
|
||||||
|
|
||||||
|
//populate tables
|
||||||
|
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
FTPFileEntryParser entryParser=null;
|
||||||
|
try {
|
||||||
|
entryParser = (FTPFileEntryParser)ce[i].createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
|
} catch (CoreException e) {
|
||||||
|
throw new ParserInitializationException(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
ftpFileEntryParser.put(clas, entryParser);
|
||||||
|
|
||||||
|
String defaultDateFormatStr = ce[i].getAttribute("defaultDateFormatStr"); //$NON-NLS-1$
|
||||||
|
String recentDateFormatStr = ce[i].getAttribute("recentDateFormatStr"); //$NON-NLS-1$
|
||||||
|
String serverLanguageCode = ce[i].getAttribute("serverLanguageCode"); //$NON-NLS-1$
|
||||||
|
String shortMonthNames = ce[i].getAttribute("shortMonthNames"); //$NON-NLS-1$
|
||||||
|
String serverTimeZoneId = ce[i].getAttribute("serverTimeZoneId"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
config = new FTPClientConfig(clas);
|
||||||
|
|
||||||
|
//not necessary checking for null, as null is valid input
|
||||||
|
config.setDefaultDateFormatStr(defaultDateFormatStr);
|
||||||
|
config.setRecentDateFormatStr(recentDateFormatStr);
|
||||||
|
config.setServerLanguageCode(serverLanguageCode);
|
||||||
|
config.setShortMonthNames(shortMonthNames);
|
||||||
|
config.setServerTimeZoneId(serverTimeZoneId);
|
||||||
|
|
||||||
|
ftpConfig.put(label, config);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (FTPClientConfig)ftpConfig.get(key);
|
return (FTPClientConfig)ftpConfig.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +118,7 @@ private static FTPClientConfigFactory factory = null;
|
||||||
*/
|
*/
|
||||||
public Set getKeySet()
|
public Set getKeySet()
|
||||||
{
|
{
|
||||||
return ftpConfig.keySet();
|
return keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -109,6 +126,37 @@ private static FTPClientConfigFactory factory = null;
|
||||||
* @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 {
|
||||||
|
|
||||||
|
//
|
||||||
|
// the hashtable "ftpFileEntryParser" will be populated previously by getFTPClientConfig()
|
||||||
|
// but in case the execution flow gets modified it's worth checking and populating it if required
|
||||||
|
//
|
||||||
|
if(!ftpFileEntryParser.containsKey(key))
|
||||||
|
{
|
||||||
|
IConfigurationElement[] ce = ep.getConfigurationElements();
|
||||||
|
for (int i = 0; i < ce.length; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
String label = ce[i].getAttribute("name"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
if(label.equals(key))
|
||||||
|
{
|
||||||
|
//populate tables
|
||||||
|
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
FTPFileEntryParser entryParser=null;
|
||||||
|
try {
|
||||||
|
entryParser = (FTPFileEntryParser)ce[i].createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
|
} catch (CoreException e) {
|
||||||
|
throw new ParserInitializationException(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
ftpFileEntryParser.put(clas, entryParser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (FTPFileEntryParser)ftpFileEntryParser.get(key);
|
return (FTPFileEntryParser)ftpFileEntryParser.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +164,7 @@ private static FTPClientConfigFactory factory = null;
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @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)
|
public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException {
|
||||||
throws ParserInitializationException {
|
|
||||||
|
|
||||||
String key = config.getServerSystemKey();
|
String key = config.getServerSystemKey();
|
||||||
return createFileEntryParser(key);
|
return createFileEntryParser(key);
|
||||||
|
|
Loading…
Add table
Reference in a new issue