Author: rwinston
Date: Mon Apr 17 08:25:21 2006
New Revision: 394700
URL: http://svn.apache.org/viewcvs?rev=394700&view=rev
Log:
Added support for a Netware-based FTP server. Tested on Novell Netware 6.5.
Added:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java
Modified:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
Modified:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java?rev=394700&r1=394699&r2=394700&view=diff
==============================================================================
---
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
(original)
+++
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
Mon Apr 17 08:25:21 2006
@@ -175,6 +175,12 @@
* the commons-net ftp system.
*/
public static final String SYST_MVS = "MVS";
+
+ /**
+ * Identifier by which an Netware-based ftp server is known throughout
+ * the commons-net ftp system.
+ */
+ public static final String SYST_NETWARE = "NETWARE";
private final String serverSystemKey;
private String defaultDateFormatStr = null;
Modified:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java?rev=394700&r1=394699&r2=394700&view=diff
==============================================================================
---
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
(original)
+++
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
Mon Apr 17 08:25:21 2006
@@ -115,6 +115,10 @@
{
parser = createMVSEntryParser();
}
+ else if (ukey.indexOf(FTPClientConfig.SYST_NETWARE) >= 0)
+ {
+ parser = createNetwareFTPEntryParser();
+ }
else
{
throw new ParserInitializationException("Unknown parser
type: " + key);
@@ -194,6 +198,10 @@
public FTPFileEntryParser createVMSVersioningFTPEntryParser()
{
return (FTPFileEntryParser) new VMSVersioningFTPEntryParser();
+ }
+
+ public FTPFileEntryParser createNetwareFTPEntryParser() {
+ return new NetwareFTPEntryParser();
}
public FTPFileEntryParser createNTFTPEntryParser()
Added:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java?rev=394700&view=auto
==============================================================================
---
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
(added)
+++
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
Mon Apr 17 08:25:21 2006
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.net.ftp.parser;
+
+import java.text.ParseException;
+
+import org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.commons.net.ftp.FTPFile;
+
+/**
+ * Implementation of FTPFileEntryParser and FTPFileListParser for Netware
Systems. Note that some of the proprietary
+ * extensions for Novell-specific operations are not supported. See
+ * <a
href="http://www.novell.com/documentation/nw65/index.html?page=/documentation/nw65/ftp_enu/data/fbhbgcfa.html">http://www.novell.com/documentation/nw65/index.html?page=/documentation/nw65/ftp_enu/data/fbhbgcfa.html</a>
+ * for more details.
+ *
+ * @author <a href="[EMAIL PROTECTED]">Rory Winston</a>
+ * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for
usage instructions)
+ * @version $Id$
+ */
+public class NetwareFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
+
+ /**
+ * Default date format is e.g. Feb 22 2006
+ */
+ private static final String DEFAULT_DATE_FORMAT = "MMM dd yyyy";
+
+ /**
+ * Default recent date format is e.g. Feb 22 17:32
+ */
+ private static final String DEFAULT_RECENT_DATE_FORMAT = "MMM dd HH:mm";
+
+ /**
+ * this is the regular expression used by this parser.
+ * Example: d [-W---F--] SCION_VOL2 512 Apr 13
23:12 VOL2
+ */
+ private static final String REGEX = "(d|-){1}\\s+" + "\\[(.*)\\]\\s+"
+ + "(\\S+)\\s+" + "(\\d+)\\s+"
+ + "(\\S+\\s+\\S+\\s+((\\d+:\\d+)|(\\d{4})))" +
"\\s+(.*)";
+
+ /**
+ * The default constructor for a NetwareFTPEntryParser object.
+ *
+ * @exception IllegalArgumentException
+ * Thrown if the regular expression is unparseable. Should not be seen
+ * under normal conditions. It it is seen, this is a sign that
+ * <code>REGEX</code> is not a valid regular expression.
+ */
+ public NetwareFTPEntryParser() {
+ this(null);
+ }
+
+ /**
+ * This constructor allows the creation of an NetwareFTPEntryParser
object
+ * with something other than the default configuration.
+ *
+ * @param config The [EMAIL PROTECTED] FTPClientConfig configuration}
object used to
+ * configure this parser.
+ * @exception IllegalArgumentException
+ * Thrown if the regular expression is unparseable. Should not be seen
+ * under normal conditions. It it is seen, this is a sign that
+ * <code>REGEX</code> is not a valid regular expression.
+ * @since 1.4
+ */
+ public NetwareFTPEntryParser(FTPClientConfig config) {
+ super(REGEX);
+ configure(config);
+ }
+
+ /**
+ * Parses a line of an NetwareFTP server file listing and converts it
into a
+ * usable format in the form of an <code> FTPFile </code> instance. If
the
+ * file listing line doesn't describe a file, <code> null </code> is
+ * returned, otherwise a <code> FTPFile </code> instance representing
the
+ * files in the directory is returned.
+ * <p>
+ * <p>
+ * Netware file permissions are in the following format: RWCEAFMS, and
are explained as follows:
+ * <ul>
+ * <li><b>S</b> - Supervisor; All rights.
+ * <li><b>R</b> - Read; Right to open and read or execute.
+ * <li><b>W</b> - Write; Right to open and modify.
+ * <li><b>C</b> - Create; Right to create; when assigned to a file,
allows a deleted file to be recovered.
+ * <li><b>E</b> - Erase; Right to delete.
+ * <li><b>M</b> - Modify; Right to rename a file and to change
attributes.
+ * <li><b>F</b> - File Scan; Right to see directory or file listings.
+ * <li><b>A</b> - Access Control; Right to modify trustee assignments
and the Inherited Rights Mask.
+ * </ul>
+ *
+ * See <a
href="http://www.novell.com/documentation/nfap10/index.html?page=/documentation/nfap10/nfaubook/data/abxraws.html">here</a>
+ * for more details
+ *
+ * @param entry A line of text from the file listing
+ * @return An FTPFile instance corresponding to the supplied entry
+ */
+ public FTPFile parseFTPEntry(String entry) {
+
+ FTPFile f = new FTPFile();
+ if (matches(entry)) {
+ String dirString = group(1);
+ String attrib = group(2);
+ String user = group(3);
+ String size = group(4);
+ String datestr = group(5);
+ String name = group(9);
+
+ try {
+ f.setTimestamp(super.parseTimestamp(datestr));
+ } catch (ParseException e) {
+ return null; // this is a parsing failure too.
+ }
+
+ //is it a DIR or a file
+ if (dirString.trim().equals("d")) {
+ f.setType(FTPFile.DIRECTORY_TYPE);
+ } else // Should be "-"
+ {
+ f.setType(FTPFile.FILE_TYPE);
+ }
+
+ f.setUser(user);
+
+ //set the name
+ f.setName(name.trim());
+
+ //set the size
+ f.setSize(Long.parseLong(size.trim()));
+
+ // Now set the permissions (or at least a subset
thereof - full permissions would probably require
+ // subclassing FTPFile and adding extra metainformation
there)
+ if (attrib.contains("R")) {
+ f.setPermission(FTPFile.USER_ACCESS,
FTPFile.READ_PERMISSION,
+ true);
+ }
+ if (attrib.contains("W")) {
+ f.setPermission(FTPFile.USER_ACCESS,
FTPFile.WRITE_PERMISSION,
+ true);
+ }
+
+ return (f);
+ }
+ return null;
+
+ }
+
+ /**
+ * Defines a default configuration to be used when this class is
+ * instantiated without a [EMAIL PROTECTED] FTPClientConfig
FTPClientConfig}
+ * parameter being specified.
+ * @return the default configuration for this parser.
+ */
+ protected FTPClientConfig getDefaultConfiguration() {
+ return new FTPClientConfig(FTPClientConfig.SYST_NETWARE,
+ DEFAULT_DATE_FORMAT,
DEFAULT_RECENT_DATE_FORMAT, null, null,
+ null);
+ }
+
+}
Added:
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java?rev=394700&view=auto
==============================================================================
---
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java
(added)
+++
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java
Mon Apr 17 08:25:21 2006
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.net.ftp.parser;
+
+import java.util.Calendar;
+
+import junit.framework.TestSuite;
+
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPFileEntryParser;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Rory Winston</a>
+ * @version $Id$
+ */
+public class NetwareFTPEntryParserTest extends FTPParseTestFramework {
+
+ private static final String[] badsamples = {
+ "a [-----F--] SCION_SYS 512 Apr 13
23:52 SYS",
+ "d [----AF--] 0 512 10-04-2001
_ADMIN"
+ };
+
+ private static final String [] goodsamples = {
+ "d [-----F--] SCION_SYS 512 Apr 13 23:52 SYS",
+ "d [----AF--] 0 512 Feb 22 17:32
_ADMIN",
+ "d [-W---F--] SCION_VOL2 512 Apr 13 23:12 VOL2",
+ "- [RWCEAFMS] rwinston 19968 Mar 12 15:20
Executive Summary.doc",
+ "d [RWCEAFMS] rwinston 512 Nov 24 2005
Favorites"
+ };
+
+ /**
+ * @see junit.framework.TestCase#TestCase(String)
+ */
+ public NetwareFTPEntryParserTest(String name) {
+ super(name);
+ }
+
+ /**
+ * @see
org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
+ */
+ protected String[] getBadListing() {
+ return (badsamples);
+ }
+
+ /**
+ * @see
org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
+ */
+ protected String[] getGoodListing() {
+ return (goodsamples);
+ }
+
+ /**
+ * @see
org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
+ */
+ protected FTPFileEntryParser getParser() {
+ return (new NetwareFTPEntryParser());
+ }
+
+ /**
+ * @see
org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
+ */
+
+ public void testParseFieldsOnDirectory() throws Exception {
+ String reply = "d [-W---F--] testUser
512 Apr 13 23:12 testFile";
+ FTPFile f = getParser().parseFTPEntry(reply);
+
+ assertNotNull("Could not parse file", f);
+ assertEquals("testFile", f.getName());
+ assertEquals(512L, f.getSize());
+ assertEquals("testUser", f.getUser());
+ assertTrue("Directory flag is not set!", f.isDirectory());
+
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.MONTH, 3);
+ cal.set(Calendar.DAY_OF_MONTH, 13);
+ cal.set(Calendar.HOUR_OF_DAY, 23);
+ cal.set(Calendar.MINUTE, 12);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+
+ assertEquals(df.format(cal.getTime()),
df.format(f.getTimestamp()
+ .getTime()));
+
+ }
+
+
+ /**
+ * @see
org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
+ */
+ public void testParseFieldsOnFile() throws Exception {
+ String reply = "- [R-CEAFMS] rwinston
19968 Mar 12 15:20 Document name with spaces.doc";
+
+ FTPFile f = getParser().parseFTPEntry(reply);
+
+ assertNotNull("Could not parse file", f);
+ assertEquals("Document name with spaces.doc", f.getName());
+ assertEquals(19968L, f.getSize());
+ assertEquals("rwinston", f.getUser());
+ assertTrue("File flag is not set!", f.isFile());
+
+ assertTrue(f.hasPermission(FTPFile.USER_ACCESS,
FTPFile.READ_PERMISSION));
+ assertFalse(f.hasPermission(FTPFile.USER_ACCESS,
FTPFile.WRITE_PERMISSION));
+ }
+
+
+ /**
+ * Method suite.
+ * @return TestSuite
+ */
+ public static TestSuite suite() {
+ return (new TestSuite(NetwareFTPEntryParserTest.class));
+ }
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]