1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 15:15:25 +02:00

added FTPClientConfigProxy, parsers listed by ID and custom LIST parameter

This commit is contained in:
Javier Montalvo Orus 2007-05-15 21:52:24 +00:00
parent 6b12e6b899
commit 8d0d5ea796
8 changed files with 292 additions and 128 deletions

View file

@ -65,6 +65,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.rse.core.model.IPropertySet;
import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory;
import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigProxy;
import org.eclipse.rse.services.Mutex;
import org.eclipse.rse.services.clientserver.FileTypeMatcher;
import org.eclipse.rse.services.clientserver.IMatcher;
@ -97,7 +98,7 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
private boolean _isBinaryFileType = true;
private boolean _isPassiveDataConnectionMode = false;
private IFTPClientConfigFactory _entryParserFactory;
private IFTPClientConfigProxy _clientConfigProxy;
private class FTPBufferedInputStream extends BufferedInputStream {
@ -303,7 +304,9 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
_ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
}
//FTPClientConfigProxy object with information of the extended LIST command, or null
_clientConfigProxy = _entryParserFactory.getFTPClientConfigProxy(_ftpPropertySet.getPropertyValue("parser")); //$NON-NLS-1$
// Initial active/passive mode. This action will be refreshed later using setDataConnectionMode()
if(_ftpPropertySet.getPropertyValue("passive").equalsIgnoreCase("true")) //$NON-NLS-1$ //$NON-NLS-2$
{
@ -980,7 +983,19 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
public void run() {
try {
_ftpFiles = _ftpClient.listFiles();
_ftpFiles = null;
if(_clientConfigProxy!=null)
{
_ftpFiles = _ftpClient.listFiles(_clientConfigProxy.getListCommandModifiers());
}
else
{
_ftpFiles = _ftpClient.listFiles();
}
} catch (IOException e) {
_exception = e;
}

View file

@ -11,8 +11,6 @@
package org.eclipse.rse.internal.services.files.ftp.parser;
import java.util.Set;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
@ -28,9 +26,16 @@ public interface IFTPClientConfigFactory extends FTPFileEntryParserFactory {
public FTPClientConfig getFTPClientConfig(String parser, String systemName);
/**
* Returns a Set of key names
* @return a Set containing the name attribute of the extension points
* Returns an array of strings containing the id
* @return a String[] containing the name attribute of the extension points
*/
public Set getKeySet();
public String[] getKeySet();
/**
* Returns the IFTPClientConfigProxy that matches the given id
* @param id of the FTPClientConfigProxy
* @return The IFTPClientConfigProxy or null if not found
*/
public IFTPClientConfigProxy getFTPClientConfigProxy(String id);
}

View file

@ -0,0 +1,30 @@
/********************************************************************************
* Copyright (c) 2007 Symbian Software Ltd. 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:
* Javier Montalvo Orus (Symbian) - initial API and implementation
********************************************************************************/
package org.eclipse.rse.internal.services.files.ftp.parser;
import org.osgi.framework.Bundle;
public interface IFTPClientConfigProxy {
public String getId();
public String getLabel();
public int getPriority();
public String getSystemTypeRegex();
public String getClassName();
public Bundle getDeclaringBundle();
public String getListCommandModifiers();
public String getDefaultDateFormatStr();
public String getRecentDateFormatStr();
public String getServerLanguageCode();
public String getShortMonthNames();
public String getServerTimeZoneId();
}

View file

@ -51,42 +51,42 @@ Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
<extension point="org.eclipse.rse.subsystems.files.ftp.ftpFileEntryParser">
<parser
class="org.apache.commons.net.ftp.parser.UnixFTPEntryParser"
ftpSystemTypes=".*[Uu][Nn][Ii][Xx].*"
id="org.eclipse.rse.ftp.parser.Unix"
label="%FTPParser.UNIX"
priority="100">
priority="100"
systemTypeRegex=".*[Uu][Nn][Ii][Xx].*">
</parser>
<parser
class="org.apache.commons.net.ftp.parser.MVSFTPEntryParser"
ftpSystemTypes=".*[Mm][Vv][Ss].*"
systemTypeRegex=".*[Mm][Vv][Ss].*"
id="org.eclipse.rse.ftp.parser.MVS"
label="%FTPParser.MVS"
priority="100">
</parser>
<parser
class="org.eclipse.rse.internal.subsystems.files.ftp.parser.RSENTFTPEntryParser"
ftpSystemTypes=".*[Ww][Ii][Nn][Dd][Oo][Ww][Ss].*"
systemTypeRegex=".*[Ww][Ii][Nn][Dd][Oo][Ww][Ss].*"
id="org.eclipse.rse.ftp.parser.WinNT"
label="%FTPParser.WinNT"
priority="100">
</parser>
<parser
class="org.apache.commons.net.ftp.parser.OS2FTPEntryParser"
ftpSystemTypes=".*[Oo][Ss]/2.*"
systemTypeRegex=".*[Oo][Ss]/2.*"
id="org.eclipse.rse.ftp.parser.OS2"
label="%FTPParser.OS2"
priority="100">
</parser>
<parser
class="org.apache.commons.net.ftp.parser.OS400FTPEntryParser"
ftpSystemTypes=".*[Oo][Ss]/400.*"
systemTypeRegex=".*[Oo][Ss]/400.*"
id="org.eclipse.rse.ftp.parser.OS400"
label="%FTPParser.OS400"
priority="100">
</parser>
<parser
class="org.eclipse.rse.internal.subsystems.files.ftp.parser.RSEVMSFTPEntryParser"
ftpSystemTypes=".*[Vv][Mm][Ss].*"
systemTypeRegex=".*[Vv][Mm][Ss].*"
id="org.eclipse.rse.ftp.parser.VMS"
label="%FTPParser.VMS"
priority="100">

View file

@ -139,7 +139,7 @@ only 8-bit ASCII characters are known to be supported. For example, a set of mo
</documentation>
</annotation>
</attribute>
<attribute name="ftpSystemTypes" type="string">
<attribute name="systemTypeRegex" type="string">
<annotation>
<documentation>
Regular expression used to match with the string returned by the FTP SYST command to autodetect the parser if not specified by the user
@ -149,7 +149,16 @@ only 8-bit ASCII characters are known to be supported. For example, a set of mo
<attribute name="priority" type="string">
<annotation>
<documentation>
Priority used if more than one extension matches the regular expression given by ftpSystemTypes.
Priority used if more than one extension matches the regular expression given by the &lt;code&gt;ftpSystemTypes&lt;/code&gt; attribute. Integer values are allowed.
In case of more than one parser with a matching regular expression, the parser with lower priority number will be used.
If no priority is specified, the default value will be &lt;code&gt;Integer.MAX_VALUE&lt;/code&gt;.
</documentation>
</annotation>
</attribute>
<attribute name="listCommandModifiers" type="string">
<annotation>
<documentation>
Modifiers of the FTP &quot;LIST&quot; command. As an example if the LIST command has to be &quot;LIST -l&quot;, the contents of this optional field has to be &quot;-l&quot;
</documentation>
</annotation>
</attribute>

View file

@ -23,7 +23,6 @@ package org.eclipse.rse.internal.subsystems.files.ftp.connectorservice;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.rse.core.model.IHost;
@ -61,10 +60,11 @@ public class FTPConnectorService extends StandardConnectorService
_propertySet.addProperty("passive","false",PropertyType.getEnumPropertyType(new String[]{"true","false"})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// FTP List parser
Set keys = FTPClientConfigFactory.getParserFactory().getKeySet();
String[] keysArray = new String[keys.size()+1];
String[] keys = FTPClientConfigFactory.getParserFactory().getKeySet();
String[] keysArray = new String[keys.length+1];
System.arraycopy(keys, 0, keysArray, 0, keys.length);
keys.toArray(keysArray);
keysArray[keysArray.length-1]="AUTO"; //$NON-NLS-1$
Arrays.sort(keysArray);

View file

@ -11,25 +11,26 @@
package org.eclipse.rse.internal.subsystems.files.ftp.parser;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFileEntryParser;
import org.apache.commons.net.ftp.parser.ParserInitializationException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory;
import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigProxy;
import org.osgi.framework.Bundle;
public class FTPClientConfigFactory implements IFTPClientConfigFactory {
private static FTPClientConfigFactory factory = null;
private Set keySet = new TreeSet();
private Hashtable ftpConfigProxyById = new Hashtable();
private Hashtable ftpConfig = 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$
@ -53,8 +54,26 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
IConfigurationElement[] ce = ep.getConfigurationElements();
for (int i = 0; i < ce.length; i++) {
String label = ce[i].getAttribute("label"); //$NON-NLS-1$
keySet.add(label);
String id = ce[i].getAttribute("id"); //$NON-NLS-1$
String label = ce[i].getAttribute("label"); //$NON-NLS-1$
String priority = ce[i].getAttribute("priority"); //$NON-NLS-1$
String systemTypeRegex = ce[i].getAttribute("systemTypeRegex"); //$NON-NLS-1$
String className = ce[i].getAttribute("class"); //$NON-NLS-1$
Bundle declaringBundle = Platform.getBundle(ce[i].getContributor().getName());
String listCommandModifiers = ce[i].getAttribute("listCommandModifiers"); //$NON-NLS-1$
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$
FTPClientConfigProxy ftpClientConfigProxy = new FTPClientConfigProxy(id,label,priority,systemTypeRegex,className,declaringBundle,listCommandModifiers,
defaultDateFormatStr,recentDateFormatStr,serverLanguageCode,shortMonthNames,serverTimeZoneId);
ftpConfigProxyById.put(id, ftpClientConfigProxy);
}
}
@ -69,73 +88,59 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
if(parser.equals("AUTO")) //$NON-NLS-1$
{
int priorityInt = Integer.MAX_VALUE;
int previousPriorityInt = Integer.MAX_VALUE;
IConfigurationElement selectedCofiguration = null;
int previousPriority = Integer.MAX_VALUE;
FTPClientConfigProxy foundProxy = null;
IConfigurationElement[] ce = ep.getConfigurationElements();
for (int i = 0; i < ce.length; i++)
Enumeration ftpConfigProxyEnum = ftpConfigProxyById.elements();
while(ftpConfigProxyEnum.hasMoreElements())
{
String ftpSystemTypes = ce[i].getAttribute("ftpSystemTypes"); //$NON-NLS-1$
if(ftpSystemTypes!=null)
FTPClientConfigProxy proxy = (FTPClientConfigProxy)ftpConfigProxyEnum.nextElement();
if(proxy.getSystemTypeRegex()!=null)
{
Pattern ftpSystemTypesRegex = Pattern.compile(ftpSystemTypes);
Pattern ftpSystemTypesRegex = Pattern.compile(proxy.getSystemTypeRegex());
if(ftpSystemTypesRegex.matcher(systemName).matches())
{
//try to get priority otherwise assigning Integer.MAX_VALUE
String priority = ce[i].getAttribute("priority"); //$NON-NLS-1$
if(priority!=null)
{
priorityInt = Integer.parseInt(priority);
}
else
{
priorityInt = Integer.MAX_VALUE;
}
int priority = proxy.getPriority();
if(priorityInt < previousPriorityInt)
if(priority < previousPriority)
{
selectedCofiguration = ce[i];
previousPriorityInt = priorityInt;
foundProxy = proxy;
previousPriority = priority;
}
}
}
}
//process the selected IConfigurationElement
if(selectedCofiguration != null)
//process the selected proxy
if(foundProxy != null)
{
FTPClientConfig config = null;
//populate tables
String clas = selectedCofiguration.getAttribute("class"); //$NON-NLS-1$
if(!ftpFileEntryParser.containsKey(clas))
if(!ftpFileEntryParser.containsKey(foundProxy.getClassName()))
{
FTPFileEntryParser entryParser=null;
FTPFileEntryParser entryParser = null;
try {
entryParser = (FTPFileEntryParser)selectedCofiguration.createExecutableExtension("class"); //$NON-NLS-1$
} catch (CoreException e) {
throw new ParserInitializationException(e.getMessage());
}
ftpFileEntryParser.put(clas, entryParser);
entryParser = (FTPFileEntryParser)foundProxy.getDeclaringBundle().loadClass(foundProxy.getClassName()).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ftpFileEntryParser.put(foundProxy.getClassName(), entryParser);
}
String defaultDateFormatStr = selectedCofiguration.getAttribute("defaultDateFormatStr"); //$NON-NLS-1$
String recentDateFormatStr = selectedCofiguration.getAttribute("recentDateFormatStr"); //$NON-NLS-1$
String serverLanguageCode = selectedCofiguration.getAttribute("serverLanguageCode"); //$NON-NLS-1$
String shortMonthNames = selectedCofiguration.getAttribute("shortMonthNames"); //$NON-NLS-1$
String serverTimeZoneId = selectedCofiguration.getAttribute("serverTimeZoneId"); //$NON-NLS-1$
config = new FTPClientConfig(clas);
config = new FTPClientConfig(foundProxy.getClassName());
//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);
config.setDefaultDateFormatStr(foundProxy.getDefaultDateFormatStr());
config.setRecentDateFormatStr(foundProxy.getRecentDateFormatStr());
config.setServerLanguageCode(foundProxy.getServerLanguageCode());
config.setShortMonthNames(foundProxy.getShortMonthNames());
config.setServerTimeZoneId(foundProxy.getServerTimeZoneId());
//not necessary storing in the hashtable, as discovered will not be reused
ftpClientConfig = config;
@ -153,46 +158,42 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
}
else
{
IConfigurationElement[] ce = ep.getConfigurationElements();
for (int i = 0; i < ce.length; i++)
{
String label = ce[i].getAttribute("label"); //$NON-NLS-1$
Enumeration ftpConfigProxyEnum = ftpConfigProxyById.elements();
while(ftpConfigProxyEnum.hasMoreElements())
{
FTPClientConfigProxy proxy = (FTPClientConfigProxy)ftpConfigProxyEnum.nextElement();
if(label.equals(parser))
if(proxy.getId().equals(parser))
{
FTPClientConfig config = null;
//populate tables
String clas = ce[i].getAttribute("class"); //$NON-NLS-1$
if(!ftpFileEntryParser.containsKey(proxy.getClassName()))
{
FTPFileEntryParser entryParser = null;
try {
entryParser = (FTPFileEntryParser)proxy.getDeclaringBundle().loadClass(proxy.getClassName()).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ftpFileEntryParser.put(proxy.getClassName(), entryParser);
}
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);
config = new FTPClientConfig(proxy.getClassName());
//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);
config.setDefaultDateFormatStr(proxy.getDefaultDateFormatStr());
config.setRecentDateFormatStr(proxy.getRecentDateFormatStr());
config.setServerLanguageCode(proxy.getServerLanguageCode());
config.setShortMonthNames(proxy.getShortMonthNames());
config.setServerTimeZoneId(proxy.getServerTimeZoneId());
ftpConfig.put(parser, config);
ftpClientConfig = (FTPClientConfig)ftpConfig.get(parser);
break;
@ -200,7 +201,6 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
}
}
}
}
@ -211,9 +211,9 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
* (non-Javadoc)
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getKeySet()
*/
public Set getKeySet()
public String[] getKeySet()
{
return keySet;
return (String[])ftpConfigProxyById.keySet().toArray(new String[ftpConfigProxyById.size()]);
}
/*
@ -228,27 +228,19 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
//
if(!ftpFileEntryParser.containsKey(key))
{
IConfigurationElement[] ce = ep.getConfigurationElements();
for (int i = 0; i < ce.length; i++)
{
String label = ce[i].getAttribute("label"); //$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);
}
}
FTPClientConfigProxy proxy = (FTPClientConfigProxy)ftpConfigProxyById.get(key);
FTPFileEntryParser entryParser = null;
try {
entryParser = (FTPFileEntryParser)proxy.getDeclaringBundle().loadClass(proxy.getClassName()).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ftpFileEntryParser.put(proxy.getClassName(), entryParser);
}
@ -266,4 +258,13 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
}
/*
* (non-Javadoc)
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getFTPClientConfigProxy(java.lang.String)
*/
public IFTPClientConfigProxy getFTPClientConfigProxy(String id)
{
return (IFTPClientConfigProxy)ftpConfigProxyById.get(id);
}
}

View file

@ -0,0 +1,104 @@
/********************************************************************************
* Copyright (c) 2007 Symbian Software Ltd. 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:
* Javier Montalvo Orus (Symbian) - initial API and implementation
* Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
********************************************************************************/
package org.eclipse.rse.internal.subsystems.files.ftp.parser;
import org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigProxy;
import org.osgi.framework.Bundle;
public class FTPClientConfigProxy implements IFTPClientConfigProxy{
private String id;
private String label;
private int priority = Integer.MAX_VALUE;
private String systemTypeRegex;
private String className;
private Bundle declaringBundle;
private String listCommandModifiers;
private String defaultDateFormatStr;
private String recentDateFormatStr;
private String serverLanguageCode;
private String shortMonthNames;
private String serverTimeZoneId;
public FTPClientConfigProxy(String id, String label, String priority, String systemTypeRegex, String className, Bundle declaringBundle, String listCommandModifiers,
String defaultDateFormatStr, String recentDateFormatStr, String serverLanguageCode, String shortMonthNames, String serverTimeZoneId)
{
this.id = id;
this.label = label;
try{
this.priority = Integer.parseInt(priority);
}catch(NumberFormatException e){}
this.systemTypeRegex = systemTypeRegex;
this.className = className;
this.listCommandModifiers = listCommandModifiers;
this.declaringBundle = declaringBundle;
this.defaultDateFormatStr = defaultDateFormatStr;
this.recentDateFormatStr = recentDateFormatStr;
this.serverLanguageCode = serverLanguageCode;
this.shortMonthNames = shortMonthNames;
this.serverTimeZoneId = serverTimeZoneId;
}
public String getId() {
return id;
}
public String getLabel() {
return label;
}
public int getPriority() {
return priority;
}
public String getSystemTypeRegex() {
return systemTypeRegex;
}
public String getClassName() {
return className;
}
public Bundle getDeclaringBundle() {
return declaringBundle;
}
public String getListCommandModifiers() {
return listCommandModifiers;
}
public String getDefaultDateFormatStr() {
return defaultDateFormatStr;
}
public String getRecentDateFormatStr() {
return recentDateFormatStr;
}
public String getServerLanguageCode() {
return serverLanguageCode;
}
public String getShortMonthNames() {
return shortMonthNames;
}
public String getServerTimeZoneId() {
return serverTimeZoneId;
}
}