You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2005/04/08 20:42:21 UTC

svn commit: r160582 - in jakarta/commons/proper/net/trunk/src: java/org/apache/commons/net/ftp/ java/org/apache/commons/net/ftp/parser/ test/org/apache/commons/net/ftp/parser/

Author: scohen
Date: Fri Apr  8 11:42:20 2005
New Revision: 160582

URL: http://svn.apache.org/viewcvs?view=rev&rev=160582
Log:
Handle bug 34360 - add new FTP Entry parser for MVS.  Contributed by William Noto and Jeff Nadler.

Added:
    jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
    jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.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
    jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/AllTests.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?view=diff&r1=160581&r2=160582
==============================================================================
--- 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 Fri Apr  8 11:42:20 2005
@@ -170,6 +170,12 @@
      */
     public static final String SYST_OS400 = "OS/400";
     
+    /**
+     * Identifier by which an MVS-based ftp server is known throughout
+     * the commons-net ftp system.
+     */
+    public static final String SYST_MVS = "MVS";
+    
     private final String serverSystemKey;
 	private String defaultDateFormatStr = null;
 	private String recentDateFormatStr = 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?view=diff&r1=160581&r2=160582
==============================================================================
--- 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 Fri Apr  8 11:42:20 2005
@@ -66,6 +66,7 @@
      *               <li>{@link FTPClientConfig#SYST_OS2 OS/2}</li>
      *               <li>{@link FTPClientConfig#SYST_OS400 OS/400}</li>
      *               <li>{@link FTPClientConfig#SYST_VMS VMS}</li>
+     *               <li>{@link FTPClientConfig#SYST_MVS MVS}</li>
      *               </ul>
      * @return the FTPFileEntryParser corresponding to the supplied key.
      * @throws ParserInitializationException thrown if for any reason the factory cannot resolve
@@ -108,6 +109,10 @@
             {
                 parser = createOS400FTPEntryParser();
             }
+            else if (ukey.indexOf(FTPClientConfig.SYST_MVS) >= 0)
+            {
+                parser = createMVSEntryParser();
+        	}
             else
             {
                 throw new ParserInitializationException("Unknown parser type: " + key);
@@ -204,6 +209,10 @@
     	}
     }
 
+    public FTPFileEntryParser createMVSEntryParser()
+    {
+        return new MVSFTPEntryParser();
+    }
 
 
 	

Added: jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java?view=auto&rev=160582
==============================================================================
--- jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java (added)
+++ jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java Fri Apr  8 11:42:20 2005
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2005 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 org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.commons.net.ftp.FTPFile;
+
+/**
+ * Implementation of FTPFileEntryParser and FTPFileListParser for IBM MVS Systems.
+ *
+ * @author <a href="jnadler@srcginc.com">Jeff Nadler</a>
+ * @author <a href="wnoto@openfinance.com">William Noto</a>
+ * @version $Id$
+ * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions)
+ */
+public class MVSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl
+{  
+    /**
+     * This is the regular expression used by this parser.
+     */
+	private static final String REGEX = "(.*)\\s+([^\\s]+)\\s*";
+	
+    /**
+     * Although this parser is now ignoring dates, someone may someday
+     * figure out a way to accomodate this and this appears to be the 
+     * format used.  For now, it won't be used.
+     * SMC 2005/04/08
+     */
+    static final String DEFAULT_DATE_FORMAT 
+		= "yyyy/MM/dd"; // 2001/11/09
+
+        
+ 	// This is not at all the tightest possible regexp for MVS LIST
+	// output, but I'm not a mainframe guru so I have little idea what the
+	// range of valid values are.  I just needed to get the filename (Dsname);
+	// note that no other FTPFile fields can be filled in with the results of
+	// a LIST on MVS.  The 'Referred' date seems to be 'last accessed date'
+	// and not 'last modified date' so I didn't bother parsing it.
+	//
+	// Of course it works perfectly as-is and it distinguishes header lines from
+	// file results so that's the important thing.  
+	//
+	// This parser should be used when SYST returns:
+	// 'MVS is the operating system of this server. FTP Server is running on z/OS.'
+	//
+	// Also note that there is no concept of directories in MVS, just datasets,
+	// which have names composed of four dot separated names of up to 8 chars.
+	// As a result, FTPFile.FILE_TYPE is always used. -JN 6/2004 jnadler<at>srcginc<dotcom>
+
+	// Sample LIST results from MVS:
+	//
+	//Volume Unit    Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname
+	//FPFS42 3390   2004/06/23  1    1  FB     128  6144  PS  INCOMING.RPTBM023.D061704
+	//FPFS41 3390   2004/06/23  1    1  FB     128  6144  PS  INCOMING.RPTBM056.D061704
+	//FPFS25 3390   2004/06/23  1    1  FB     128  6144  PS  INCOMING.WTM204.D061704
+
+    /**
+     * The sole constructor for a MVSFTPEntryParser 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 MVSFTPEntryParser()
+    {
+        super(REGEX);
+    }
+
+    /**
+     * Parses a line of an MVS FTP 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>
+     * @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 = null;
+        if (matches(entry))          
+        {
+            f = new FTPFile();
+            String dataSetName = group(2);
+            f.setType(FTPFile.FILE_TYPE);
+			f.setName(dataSetName);
+
+			return (f);
+        }
+        return null;
+    }
+
+    /* 
+     * @return
+     */
+    protected FTPClientConfig getDefaultConfiguration() {
+        return new FTPClientConfig(
+                FTPClientConfig.SYST_MVS,
+                DEFAULT_DATE_FORMAT,
+                null, null, null, null);
+    }
+}

Modified: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/AllTests.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/AllTests.java?view=diff&r1=160581&r2=160582
==============================================================================
--- jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/AllTests.java (original)
+++ jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/AllTests.java Fri Apr  8 11:42:20 2005
@@ -29,6 +29,8 @@
         suite.addTest(EnterpriseUnixFTPEntryParserTest.suite());
         suite.addTest(OS400FTPEntryParserTest.suite());
         suite.addTest(NTFTPEntryParserTest.suite());
+        suite.addTest(MVSFTPEntryParserTest.suite());
+
         //$JUnit-END$
         return suite;
     }

Added: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java?view=auto&rev=160582
==============================================================================
--- jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java (added)
+++ jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java Fri Apr  8 11:42:20 2005
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2005 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 junit.framework.TestSuite;
+
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPFileEntryParser;
+
+/**
+ * Created on Apr 6, 2005<br/>
+ * @author <a href="mailto:wnoto@openfinance.com">William Noto</a>
+ * @version $Id: NTFTPEntryParserTest.java,v 1.16 2005/01/02 03:17:50 scohen Exp $
+ */
+public class MVSFTPEntryParserTest extends FTPParseTestFramework 
+{
+    private static final String [] goodsamples  = 
+    {
+        "Migrated                                                file1.I",
+        "Migrated                                                file2.I",
+        "PSMLC1 3390   2005/04/04  1    1  VB   27994 27998  PS  file3.I",
+        "PSMLB9 3390   2005/04/04  1    1  VB   27994 27998  PS  file4.I.BU",
+        "PSMLB6 3390   2005/04/05  1    1  VB   27994 27998  PS  file3.I.BU",
+        "PSMLC6 3390   2005/04/05  1    1  VB   27994 27998  PS  file6.I",
+        "Migrated                                                file6.O",
+        "PSMLB7 3390   2005/04/04  1    1  VB   27994 27998  PS  file7.O",
+        "PSMLC6 3390   2005/04/05  1    1  VB   27994 27998  PS  file7.O.BU",
+    	"FPFS42 3390   2004/06/23  1    1  FB     128  6144  PS  INCOMING.RPTBM023.D061704",
+    	"FPFS41 3390   2004/06/23  1    1  FB     128  6144  PS  INCOMING.RPTBM056.D061704",
+    	"FPFS25 3390   2004/06/23  1    1  FB     128  6144  PS  INCOMING.WTM204.D061704",                
+    };
+    
+    private static final String [] badsamples = 
+    {
+        "MigratedP201.$FTXPBI1.$CF2ITB.$AAB0402.I",
+        "PSMLC133902005/04/041VB2799427998PSfile1.I",
+        "file2.O",
+    };
+    
+    /**
+     * @see junit.framework.TestCase#TestCase(String)
+     */
+    public MVSFTPEntryParserTest (String name) 
+    {
+        super(name);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getBadListings()
+     */
+    protected String[] getBadListing() {
+        return badsamples;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getGoodListings()
+     */
+    protected String[] getGoodListing() {
+        return goodsamples;
+    }
+
+    
+    /**
+     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
+     */
+    protected FTPFileEntryParser getParser()
+    {
+        return new CompositeFileEntryParser(new FTPFileEntryParser[]
+        {
+            new MVSFTPEntryParser(),
+        });
+    }
+    
+    /**
+     * Method suite.
+     * 
+     * @return TestSuite
+     */
+    public static TestSuite suite()
+    {
+        return(new TestSuite(MVSFTPEntryParserTest.class));
+    }
+    
+    public void testParseFieldsOnDirectory() throws Exception
+    {
+        // I don't really know how to test this because the MVS system that I 
+        // connect with does not allow me to create directories.         
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
+     */
+    public void testParseFieldsOnFile() throws Exception {
+        FTPFile file = getParser().parseFTPEntry("Migrated                                                file1.I");
+        assertNotNull("Could not parse entry.", file);
+        assertTrue("Should have been a file.", file.isFile());
+        assertEquals("file1.I", file.getName());
+        
+        FTPFile file2 = getParser().parseFTPEntry("PSMLC1 3390   2005/04/04  1    1  VB   27994 27998  PS  file2.I");
+        assertNotNull("Could not parse entry.", file2);
+        assertTrue("Should have been a file.", file2.isFile());
+        assertEquals("file2.I", file2.getName());
+    }    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org