scohen 2004/01/10 08:01:49
Modified: net/src/java/org/apache/commons/net/ftp/parser
EnterpriseUnixFTPEntryParser.java
NTFTPEntryParser.java OS2FTPEntryParser.java
UnixFTPEntryParser.java VMSFTPEntryParser.java
VMSVersioningFTPEntryParser.java
Added: net/src/java/org/apache/commons/net/ftp
FTPFileEntryParserImpl.java
Removed: net/src/java/org/apache/commons/net/ftp
FTPFileListParserImpl.java
Log:
Refactor - renamed FTPFileListParserImpl to FTPFileEntryParserImpl to get ready
for the eventual removal of FTPFileListParser in 2.0.
Revision Changes Path
1.1
jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileEntryParserImpl.java
Index: FTPFileEntryParserImpl.java
===================================================================
package org.apache.commons.net.ftp;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Commons" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ListIterator;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.Perl5Matcher;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.MatchResult;
/**
* This abstract class implements both the older FTPFileListParser and
* newer FTPFileEntryParser interfaces with default functionality.
* All the classes in the parser subpackage inherit from this.
*
* @author Steve Cohen <[EMAIL PROTECTED]>
*/
public abstract class FTPFileEntryParserImpl
implements FTPFileEntryParser, FTPFileListParser
{
/**
* internal pattern the matcher tries to match, representing a file
* entry
*/
private Pattern pattern = null;
/**
* internal match result used by the parser
*/
private MatchResult result = null;
/**
* Internal PatternMatcher object used by the parser. It has protected
* scope in case subclasses want to make use of it for their own purposes.
*/
protected PatternMatcher _matcher_ = null;
/**
* The constructor for a MatchApparatus object.
*
* @param regex The regular expression with which this object is
* initialized.
*
* @exception IllegalArgumentException
* Thrown if the regular expression is unparseable. Should not be seen in
* normal conditions. It it is seen, this is a sign that a subclass has
* been created with a bad regular expression. Since the parser must be
* created before use, this means that any bad parser subclasses created
* from this will bomb very quickly, leading to easy detection.
*/
public FTPFileEntryParserImpl(String regex)
{
try
{
_matcher_ = new Perl5Matcher();
pattern = new Perl5Compiler().compile(regex);
}
catch (MalformedPatternException e)
{
throw new IllegalArgumentException (
"Unparseable regex supplied: " + regex);
}
}
/***
* Parses an FTP server file listing and converts it into a usable format
* in the form of an array of <code> FTPFile </code> instances. If the
* file list contains no files, <code> null </code> should be
* returned, otherwise an array of <code> FTPFile </code> instances
* representing the files in the directory is returned.
* <p>
* @param listStream The InputStream from which the file list should be
* read.
* @return The list of file information contained in the given path. null
* if the list could not be obtained or if there are no files in
* the directory.
* @exception IOException If an I/O error occurs reading the listStream.
***/
public FTPFile[] parseFileList(InputStream listStream) throws IOException
{
FTPFileList ffl = FTPFileList.create(listStream, this);
return ffl.getFiles();
}
/**
* Convenience method delegates to the internal MatchResult's matches()
* method.
*
* @param s the String to be matched
* @return true if s matches this object's regular expression.
*/
public boolean matches(String s)
{
this.result = null;
if (_matcher_.matches(s.trim(), this.pattern))
{
this.result = _matcher_.getMatch();
}
return null != this.result;
}
/**
* Convenience method delegates to the internal MatchResult's groups()
* method.
*
* @return the number of groups() in the internal MatchResult.
*/
public int getGroupCnt()
{
if (this.result == null)
{
return 0;
}
return this.result.groups();
}
/**
* Convenience method delegates to the internal MatchResult's group()
* method.
*
* @param matchnum match group number to be retrieved
*
* @return the content of the <code>matchnum'th<code> group of the internal
* match or null if this method is called without a match having
* been made.
*/
public String group(int matchnum)
{
if (this.result == null)
{
return null;
}
return this.result.group(matchnum);
}
/**
* For debugging purposes - returns a string shows each match group by
* number.
*
* @return a string shows each match group by number.
*/
public String getGroupsAsString()
{
StringBuffer b = new StringBuffer();
for (int i = 1; i <= this.result.groups(); i++)
{
b.append(i).append(") ").append(this.result.group(i))
.append(System.getProperty("line.separator"));
}
return b.toString();
}
/**
* Reads the next entry using the supplied BufferedReader object up to
* whatever delemits one entry from the next. This default implementation
* simply calls BufferedReader.readLine().
*
* @param reader The BufferedReader object from which entries are to be
* read.
*
* @return A string representing the next ftp entry or null if none found.
* @exception IOException thrown on any IO Error reading from the reader.
*/
public String readNextEntry(BufferedReader reader) throws IOException
{
return reader.readLine();
}
/**
* Implement hook provided for those implementers (such as
* VMSVersioningFTPEntryParser, and possibly others) which return
* multiple files with the same name to remove the duplicates by
* defining a no-op method which simply returns the original
* FTPFileList. This method should not be overridden except in
* parsers that really have to remove duplicates.
*
* @param original Original list
*
* @return Original list
*/
public FTPFileList removeDuplicates(FTPFileList original) {
return original;
}
/**
* return a ListIterator to the internal Vector of lines of <code>list</code>,
* used in purging duplicates.
*
* This method could go away if FTPFileEntryParser were moved down into the
* parser package.
*
* @return a ListIterator to the internal Vector of lines, used in purging
* duplicates.
*/
protected ListIterator getInternalIteratorForFtpFileList(FTPFileList list) {
return list.getInternalIterator();
}
}
/* Emacs configuration
* Local variables: **
* mode: java **
* c-basic-offset: 4 **
* indent-tabs-mode: nil **
* End: **
*/
1.7 +3 -3
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java
Index: EnterpriseUnixFTPEntryParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- EnterpriseUnixFTPEntryParser.java 2 Jan 2004 03:39:05 -0000 1.6
+++ EnterpriseUnixFTPEntryParser.java 10 Jan 2004 16:01:48 -0000 1.7
@@ -56,7 +56,7 @@
import java.util.Calendar;
import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPFileListParserImpl;
+import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
/**
* Parser for the Connect Enterprise Unix FTP Server From Sterling Commerce.
@@ -66,7 +66,7 @@
* @author <a href="[EMAIL PROTECTED]">Winston Ojeda</a>
* @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage
instructions)
*/
-public class EnterpriseUnixFTPEntryParser extends FTPFileListParserImpl
+public class EnterpriseUnixFTPEntryParser extends FTPFileEntryParserImpl
{
/**
1.9 +3 -3
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java
Index: NTFTPEntryParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NTFTPEntryParser.java 5 Jan 2004 23:56:49 -0000 1.8
+++ NTFTPEntryParser.java 10 Jan 2004 16:01:48 -0000 1.9
@@ -56,7 +56,7 @@
import java.util.Calendar;
import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPFileListParserImpl;
+import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
/**
* Implementation of FTPFileEntryParser and FTPFileListParser for NT Systems.
@@ -66,7 +66,7 @@
* @version $Id$
* @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage
instructions)
*/
-public class NTFTPEntryParser extends FTPFileListParserImpl
+public class NTFTPEntryParser extends FTPFileEntryParserImpl
{
/**
* this is the regular expression used by this parser.
1.8 +3 -3
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParser.java
Index: OS2FTPEntryParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- OS2FTPEntryParser.java 5 Jan 2004 23:56:49 -0000 1.7
+++ OS2FTPEntryParser.java 10 Jan 2004 16:01:49 -0000 1.8
@@ -56,7 +56,7 @@
import java.util.Calendar;
import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPFileListParserImpl;
+import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
/**
* Implementation of FTPFileEntryParser and FTPFileListParser for OS2 Systems.
@@ -66,7 +66,7 @@
* @version $Id$
* @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage
instructions)
*/
-public class OS2FTPEntryParser extends FTPFileListParserImpl
+public class OS2FTPEntryParser extends FTPFileEntryParserImpl
{
/**
1.8 +3 -3
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
Index: UnixFTPEntryParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UnixFTPEntryParser.java 5 Jan 2004 23:56:49 -0000 1.7
+++ UnixFTPEntryParser.java 10 Jan 2004 16:01:49 -0000 1.8
@@ -56,7 +56,7 @@
import java.util.Calendar;
import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPFileListParserImpl;
+import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
/**
* Implementation FTPFileEntryParser and FTPFileListParser for standard
@@ -69,7 +69,7 @@
* @version $Id$
* @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage
instructions)
*/
-public class UnixFTPEntryParser extends FTPFileListParserImpl
+public class UnixFTPEntryParser extends FTPFileEntryParserImpl
{
/**
* months abbreviations looked for by this parser. Also used
1.15 +2 -2
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java
Index: VMSFTPEntryParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- VMSFTPEntryParser.java 10 Jan 2004 15:36:40 -0000 1.14
+++ VMSFTPEntryParser.java 10 Jan 2004 16:01:49 -0000 1.15
@@ -71,7 +71,7 @@
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileList;
-import org.apache.commons.net.ftp.FTPFileListParserImpl;
+import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
/**
* Implementation FTPFileEntryParser and FTPFileListParser for VMS Systems.
@@ -89,7 +89,7 @@
*
* @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage
instructions)
*/
-public class VMSFTPEntryParser extends FTPFileListParserImpl
+public class VMSFTPEntryParser extends FTPFileEntryParserImpl
{
1.2 +0 -1
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
Index: VMSVersioningFTPEntryParser.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- VMSVersioningFTPEntryParser.java 10 Jan 2004 15:36:40 -0000 1.1
+++ VMSVersioningFTPEntryParser.java 10 Jan 2004 16:01:49 -0000 1.2
@@ -73,7 +73,6 @@
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileList;
-import org.apache.commons.net.ftp.FTPFileListParserImpl;
/**
* Special implementation VMSFTPEntryParser with versioning turned on.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]