You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2008/05/21 03:14:12 UTC
svn commit: r658520 [2/3] - in
/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net:
./ ftp/ ftp/parser/ smtp/ telnet/ tftp/ util/
Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java?rev=658520&r1=658519&r2=658520&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java Tue May 20 18:14:11 2008
@@ -37,459 +37,459 @@
*/
public class MVSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
- static final int UNKNOWN_LIST_TYPE = -1;
- static final int FILE_LIST_TYPE = 0;
- static final int MEMBER_LIST_TYPE = 1;
- static final int UNIX_LIST_TYPE = 2;
- static final int JES_LEVEL_1_LIST_TYPE = 3;
- static final int JES_LEVEL_2_LIST_TYPE = 4;
-
- private int isType = UNKNOWN_LIST_TYPE;
-
- /**
- * Fallback parser for Unix-style listings
- */
- private UnixFTPEntryParser unixFTPEntryParser;
-
- /**
- * Dates are ignored for file lists, but are used for member lists where
- * possible
- */
- static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd HH:mm"; // 2001/09/18
- // 13:52
-
- /**
- * Matches these entries: Volume Unit Referred Ext Used Recfm Lrecl BlkSz
- * Dsorg Dsname B10142 3390 2006/03/20 2 31 F 80 80 PS MDI.OKL.WORK
- *
- */
- static final String FILE_LIST_REGEX = "\\S+\\s+" + // volume
- // ignored
- "\\S+\\s+" + // unit - ignored
- "\\S+\\s+" + // access date - ignored
- "\\S+\\s+" + // extents -ignored
- "\\S+\\s+" + // used - ignored
- "[FV]\\S*\\s+" + // recfm - must start with F or V
- "\\S+\\s+" + // logical record length -ignored
- "\\S+\\s+" + // block size - ignored
- "(PS|PO|PO-E)\\s+" + // Dataset organisation. Many exist
- // but only support: PS, PO, PO-E
- "(\\S+)\\s*"; // Dataset Name (file name)
-
- /**
- * Matches these entries: Name VV.MM Created Changed Size Init Mod Id
- * TBSHELF 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001
- */
- static final String MEMBER_LIST_REGEX = "(\\S+)\\s+" + // name
- "\\S+\\s+" + // version, modification (ignored)
- "\\S+\\s+" + // create date (ignored)
- "(\\S+)\\s+" + // modification date
- "(\\S+)\\s+" + // modification time
- "\\S+\\s+" + // size in lines (ignored)
- "\\S+\\s+" + // size in lines at creation(ignored)
- "\\S+\\s+" + // lines modified (ignored)
- "\\S+\\s*"; // id of user who modified (ignored)
-
- /**
- * Matches these entries, note: no header: IBMUSER1 JOB01906 OUTPUT 3 Spool
- * Files 012345678901234567890123456789012345678901234 1 2 3 4
- */
- static final String JES_LEVEL_1_LIST_REGEX = "(\\S+)\\s+" + // job
- // name
- // ignored
- "(\\S+)\\s+" + // job number
- "(\\S+)\\s+" + // job status (OUTPUT,INPUT,ACTIVE)
- "(\\S+)\\s+" + // number of spool files
- "(\\S+)\\s+" + // Text "Spool" ignored
- "(\\S+)\\s*" // Text "Files" ignored
- ;
-
- /**
- * JES INTERFACE LEVEL 2 parser Matches these entries: JOBNAME JOBID OWNER
- * STATUS CLASS IBMUSER1 JOB01906 IBMUSER OUTPUT A RC=0000 3 spool files
- * IBMUSER TSU01830 IBMUSER OUTPUT TSU ABEND=522 3 spool files
- * 012345678901234567890123456789012345678901234 1 2 3 4
- * 012345678901234567890123456789012345678901234567890
- */
-
- static final String JES_LEVEL_2_LIST_REGEX = "(\\S+)\\s+" + // job
- // name
- // ignored
- "(\\S+)\\s+" + // job number
- "(\\S+)\\s+" + // owner ignored
- "(\\S+)\\s+" + // job status (OUTPUT,INPUT,ACTIVE) ignored
- "(\\S+)\\s+" + // job class ignored
- "(\\S+).*" // rest ignored
- ;
-
- /*
- * ---------------------------------------------------------------------
- * Very brief and incomplete description of the zOS/MVS-filesystem. (Note:
- * "zOS" is the operating system on the mainframe, and is the new name for
- * MVS)
- *
- * The filesystem on the mainframe does not have hierarchal structure as for
- * example the unix filesystem. For a more comprehensive description, please
- * refer to the IBM manuals
- *
- * @LINK:
- * http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dgt2d440/CONTENTS
- *
- *
- * Dataset names =============
- *
- * A dataset name consist of a number of qualifiers separated by '.', each
- * qualifier can be at most 8 characters, and the total length of a dataset
- * can be max 44 characters including the dots.
- *
- *
- * Dataset organisation ====================
- *
- * A dataset represents a piece of storage allocated on one or more disks.
- * The structure of the storage is described with the field dataset
- * organinsation (DSORG). There are a number of dataset organisations, but
- * only two are usable for FTP transfer.
- *
- * DSORG: PS: sequential, or flat file PO: partitioned dataset PO-E:
- * extended partitioned dataset
- *
- * The PS file is just a flat file, as you would find it on the unix file
- * system.
- *
- * The PO and PO-E files, can be compared to a single level directory
- * structure. A PO file consist of a number of dataset members, or files if
- * you will. It is possible to CD into the file, and to retrieve the
- * individual members.
- *
- *
- * Dataset record format =====================
- *
- * The physical layout of the dataset is described on the dataset itself.
- * There are a number of record formats (RECFM), but just a few is relavant
- * for the FTP transfer.
- *
- * Any one beginning with either F or V can safely used by FTP transfer. All
- * others should only be used with great care, so this version will just
- * ignore the other record formats. F means a fixed number of records per
- * allocated storage, and V means a variable number of records.
- *
- *
- * Other notes ===========
- *
- * The file system supports automatically backup and retrieval of datasets.
- * If a file is backed up, the ftp LIST command will return: ARCIVE Not
- * Direct Access Device KJ.IOP998.ERROR.PL.UNITTEST
- *
- *
- * Implementation notes ====================
- *
- * Only datasets that have dsorg PS, PO or PO-E and have recfm beginning
- * with F or V, is fully parsed.
- *
- * The following fields in FTPFile is used: FTPFile.Rawlisting: Always set.
- * FTPFile.Type: DIRECTORY_TYPE or FILE_TYPE or UNKNOWN FTPFile.Name: name
- * FTPFile.Timestamp: change time or null
- *
- *
- *
- * Additional information ======================
- *
- * The MVS ftp server supports a number of features via the FTP interface.
- * The features are controlled with the FTP command quote site filetype=<SEQ|JES|DB2>
- * SEQ is the default and used for normal file transfer JES is used to
- * interact with the Job Entry Subsystem (JES) similar to a job scheduler
- * DB2 is used to interact with a DB2 subsystem
- *
- * This parser supports SEQ and JES.
- *
- *
- *
- *
- *
- *
- */
-
- /**
- * The sole constructor for a MVSFTPEntryParser object.
- *
- */
- public MVSFTPEntryParser() {
- super(""); // note the regex is set in preParse.
- super.configure(null); // configure parser with default configurations
- }
-
- /**
- * Parses a line of an z/OS - 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, then
- * <code> null </code> is returned. Otherwise a <code> FTPFile </code>
- * instance representing the file is returned.
- *
- * @param entry
- * A line of text from the file listing
- * @return An FTPFile instance corresponding to the supplied entry
- */
- public FTPFile parseFTPEntry(String entry) {
- boolean isParsed = false;
- FTPFile f = new FTPFile();
-
- if (isType == FILE_LIST_TYPE)
- isParsed = parseFileList(f, entry);
- else if (isType == MEMBER_LIST_TYPE) {
- isParsed = parseMemberList(f, entry);
- if (!isParsed)
- isParsed = parseSimpleEntry(f, entry);
- } else if (isType == UNIX_LIST_TYPE) {
- isParsed = parseUnixList(f, entry);
- } else if (isType == JES_LEVEL_1_LIST_TYPE) {
- isParsed = parseJeslevel1List(f, entry);
- } else if (isType == JES_LEVEL_2_LIST_TYPE) {
- isParsed = parseJeslevel2List(f, entry);
- }
-
- if (!isParsed)
- f = null;
-
- return f;
- }
-
- /**
- * Parse entries representing a dataset list. Only datasets with DSORG PS or
- * PO or PO-E and with RECFM F* or V* will be parsed.
- *
- * Format of ZOS/MVS file list: 1 2 3 4 5 6 7 8 9 10 Volume Unit Referred
- * Ext Used Recfm Lrecl BlkSz Dsorg Dsname B10142 3390 2006/03/20 2 31 F 80
- * 80 PS MDI.OKL.WORK ARCIVE Not Direct Access Device
- * KJ.IOP998.ERROR.PL.UNITTEST B1N231 3390 2006/03/20 1 15 VB 256 27998 PO
- * PLU B1N231 3390 2006/03/20 1 15 VB 256 27998 PO-E PLB
- *
- * ----------------------------------- Group within Regex [1] Volume [2]
- * Unit [3] Referred [4] Ext: number of extents [5] Used [6] Recfm: Record
- * format [7] Lrecl: Logical record length [8] BlkSz: Block size [9] Dsorg:
- * Dataset organisation. Many exists but only support: PS, PO, PO-E [10]
- * Dsname: Dataset name
- *
- * Note: When volume is ARCIVE, it means the dataset is stored somewhere in
- * a tape archive. These entries is currently not supported by this parser.
- * A null value is returned.
- *
- * @param file
- * will be updated with Name, Type, Timestamp if parsed.
- * @param entry zosDirectoryEntry
- * @return true: entry was parsed, false: entry was not parsed.
- */
- private boolean parseFileList(FTPFile file, String entry) {
- if (matches(entry)) {
- file.setRawListing(entry);
- String name = group(2);
- String dsorg = group(1);
- file.setName(name);
-
- // DSORG
- if ("PS".equals(dsorg)) {
- file.setType(FTPFile.FILE_TYPE);
- }
- else if ("PO".equals(dsorg) || "PO-E".equals(dsorg)) {
- // regex already ruled out anything other than PO or PO-E
- file.setType(FTPFile.DIRECTORY_TYPE);
- }
- else {
- return false;
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Parse entries within a partitioned dataset.
- *
- * Format of a memberlist within a PDS: 1 2 3 4 5 6 7 8 9 Name VV.MM Created
- * Changed Size Init Mod Id TBSHELF 01.03 2002/09/12 2002/10/11 09:37 11 11
- * 0 KIL001 TBTOOL 01.12 2002/09/12 2004/11/26 19:54 51 28 0 KIL001
- *
- * ------------------------------------------- [1] Name [2] VV.MM: Version .
- * modification [3] Created: yyyy / MM / dd [4,5] Changed: yyyy / MM / dd
- * HH:mm [6] Size: number of lines [7] Init: number of lines when first
- * created [8] Mod: number of modified lines a last save [9] Id: User id for
- * last update
- *
- *
- * @param file
- * will be updated with Name, Type and Timestamp if parsed.
- * @param entry zosDirectoryEntry
- * @return true: entry was parsed, false: entry was not parsed.
- */
- private boolean parseMemberList(FTPFile file, String entry) {
- if (matches(entry)) {
- file.setRawListing(entry);
- String name = group(1);
- String datestr = group(2) + " " + group(3);
- file.setName(name);
- file.setType(FTPFile.FILE_TYPE);
- try {
- file.setTimestamp(super.parseTimestamp(datestr));
- } catch (ParseException e) {
- e.printStackTrace();
- // just ignore parsing errors.
- // TODO check this is ok
- return false; // this is a parsing failure too.
- }
- return true;
- }
-
- return false;
- }
-
- /**
- * Assigns the name to the first word of the entry. Only to be used from a
- * safe context, for example from a memberlist, where the regex for some
- * reason fails. Then just assign the name field of FTPFile.
- *
- * @param file
- * @param entry
- * @return
- */
- private boolean parseSimpleEntry(FTPFile file, String entry) {
- if (entry != null && entry.length() > 0) {
- file.setRawListing(entry);
- String name = entry.split(" ")[0];
- file.setName(name);
- file.setType(FTPFile.FILE_TYPE);
- return true;
- }
- return false;
- }
-
- /**
- * Parse the entry as a standard unix file. Using the UnixFTPEntryParser.
- *
- * @param file
- * @param entry
- * @return true: entry is parsed, false: entry could not be parsed.
- */
- private boolean parseUnixList(FTPFile file, String entry) {
- file = unixFTPEntryParser.parseFTPEntry(entry);
- if (file == null)
- return false;
- return true;
- }
-
- /**
- * Matches these entries, note: no header: [1] [2] [3] [4] [5] IBMUSER1
- * JOB01906 OUTPUT 3 Spool Files
- * 012345678901234567890123456789012345678901234 1 2 3 4
- * ------------------------------------------- Group in regex [1] Job name
- * [2] Job number [3] Job status (INPUT,ACTIVE,OUTPUT) [4] Number of sysout
- * files [5] The string "Spool Files"
- *
- *
- * @param file
- * will be updated with Name, Type and Timestamp if parsed.
- * @param entry zosDirectoryEntry
- * @return true: entry was parsed, false: entry was not parsed.
- */
- private boolean parseJeslevel1List(FTPFile file, String entry) {
- if (matches(entry)) {
- if (group(3).equalsIgnoreCase("OUTPUT")) {
- file.setRawListing(entry);
- String name = group(2); /* Job Number, used by GET */
- file.setName(name);
- file.setType(FTPFile.FILE_TYPE);
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Matches these entries, note: no header: [1] [2] [3] [4] [5] JOBNAME JOBID
- * OWNER STATUS CLASS IBMUSER1 JOB01906 IBMUSER OUTPUT A RC=0000 3 spool
- * files IBMUSER TSU01830 IBMUSER OUTPUT TSU ABEND=522 3 spool files
- * 012345678901234567890123456789012345678901234 1 2 3 4
- * ------------------------------------------- Group in regex [1] Job name
- * [2] Job number [3] Owner [4] Job status (INPUT,ACTIVE,OUTPUT) [5] Job
- * Class [6] The rest
- *
- *
- * @param file
- * will be updated with Name, Type and Timestamp if parsed.
- * @param entry zosDirectoryEntry
- * @return true: entry was parsed, false: entry was not parsed.
- */
- private boolean parseJeslevel2List(FTPFile file, String entry) {
- if (matches(entry)) {
- if (group(4).equalsIgnoreCase("OUTPUT")) {
- file.setRawListing(entry);
- String name = group(2); /* Job Number, used by GET */
- file.setName(name);
- file.setType(FTPFile.FILE_TYPE);
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * preParse is called as part of the interface. Per definition is is called
- * before the parsing takes place. Three kind of lists is recognize:
- * z/OS-MVS File lists z/OS-MVS Member lists unix file lists
- * @since 2.0
- */
- @Override
- public List<String> preParse(List<String> orig) {
- // simply remove the header line. Composite logic will take care of the
- // two different types of
- // list in short order.
- if (orig != null && orig.size() > 0) {
- String header = orig.get(0);
- if (header.indexOf("Volume") >= 0 && header.indexOf("Dsname") >= 0) {
- setType(FILE_LIST_TYPE);
- super.setRegex(FILE_LIST_REGEX);
- } else if (header.indexOf("Name") >= 0 && header.indexOf("Id") >= 0) {
- setType(MEMBER_LIST_TYPE);
- super.setRegex(MEMBER_LIST_REGEX);
- } else if (header.indexOf("total") == 0) {
- setType(UNIX_LIST_TYPE);
- unixFTPEntryParser = new UnixFTPEntryParser();
- } else if (header.indexOf("Spool Files") >= 30) {
- setType(JES_LEVEL_1_LIST_TYPE);
- super.setRegex(JES_LEVEL_1_LIST_REGEX);
- } else if (header.indexOf("JOBNAME") == 0
- && header.indexOf("JOBID") > 8) {// header contains JOBNAME JOBID OWNER // STATUS CLASS
- setType(JES_LEVEL_2_LIST_TYPE);
- super.setRegex(JES_LEVEL_2_LIST_REGEX);
- } else {
- setType(UNKNOWN_LIST_TYPE);
- }
-
- if (isType != JES_LEVEL_1_LIST_TYPE) { // remove header is necessary
- orig.remove(0);
- }
- }
-
- return orig;
- }
-
- /**
- * Explicitly set the type of listing being processed.
- * @param type The listing type.
- */
- void setType(int type) {
- isType = type;
- }
-
- /*
- * @return
- */
- @Override
- protected FTPClientConfig getDefaultConfiguration() {
- return new FTPClientConfig(FTPClientConfig.SYST_MVS,
- DEFAULT_DATE_FORMAT, null, null, null, null);
- }
+ static final int UNKNOWN_LIST_TYPE = -1;
+ static final int FILE_LIST_TYPE = 0;
+ static final int MEMBER_LIST_TYPE = 1;
+ static final int UNIX_LIST_TYPE = 2;
+ static final int JES_LEVEL_1_LIST_TYPE = 3;
+ static final int JES_LEVEL_2_LIST_TYPE = 4;
+
+ private int isType = UNKNOWN_LIST_TYPE;
+
+ /**
+ * Fallback parser for Unix-style listings
+ */
+ private UnixFTPEntryParser unixFTPEntryParser;
+
+ /**
+ * Dates are ignored for file lists, but are used for member lists where
+ * possible
+ */
+ static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd HH:mm"; // 2001/09/18
+ // 13:52
+
+ /**
+ * Matches these entries: Volume Unit Referred Ext Used Recfm Lrecl BlkSz
+ * Dsorg Dsname B10142 3390 2006/03/20 2 31 F 80 80 PS MDI.OKL.WORK
+ *
+ */
+ static final String FILE_LIST_REGEX = "\\S+\\s+" + // volume
+ // ignored
+ "\\S+\\s+" + // unit - ignored
+ "\\S+\\s+" + // access date - ignored
+ "\\S+\\s+" + // extents -ignored
+ "\\S+\\s+" + // used - ignored
+ "[FV]\\S*\\s+" + // recfm - must start with F or V
+ "\\S+\\s+" + // logical record length -ignored
+ "\\S+\\s+" + // block size - ignored
+ "(PS|PO|PO-E)\\s+" + // Dataset organisation. Many exist
+ // but only support: PS, PO, PO-E
+ "(\\S+)\\s*"; // Dataset Name (file name)
+
+ /**
+ * Matches these entries: Name VV.MM Created Changed Size Init Mod Id
+ * TBSHELF 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001
+ */
+ static final String MEMBER_LIST_REGEX = "(\\S+)\\s+" + // name
+ "\\S+\\s+" + // version, modification (ignored)
+ "\\S+\\s+" + // create date (ignored)
+ "(\\S+)\\s+" + // modification date
+ "(\\S+)\\s+" + // modification time
+ "\\S+\\s+" + // size in lines (ignored)
+ "\\S+\\s+" + // size in lines at creation(ignored)
+ "\\S+\\s+" + // lines modified (ignored)
+ "\\S+\\s*"; // id of user who modified (ignored)
+
+ /**
+ * Matches these entries, note: no header: IBMUSER1 JOB01906 OUTPUT 3 Spool
+ * Files 012345678901234567890123456789012345678901234 1 2 3 4
+ */
+ static final String JES_LEVEL_1_LIST_REGEX = "(\\S+)\\s+" + // job
+ // name
+ // ignored
+ "(\\S+)\\s+" + // job number
+ "(\\S+)\\s+" + // job status (OUTPUT,INPUT,ACTIVE)
+ "(\\S+)\\s+" + // number of spool files
+ "(\\S+)\\s+" + // Text "Spool" ignored
+ "(\\S+)\\s*" // Text "Files" ignored
+ ;
+
+ /**
+ * JES INTERFACE LEVEL 2 parser Matches these entries: JOBNAME JOBID OWNER
+ * STATUS CLASS IBMUSER1 JOB01906 IBMUSER OUTPUT A RC=0000 3 spool files
+ * IBMUSER TSU01830 IBMUSER OUTPUT TSU ABEND=522 3 spool files
+ * 012345678901234567890123456789012345678901234 1 2 3 4
+ * 012345678901234567890123456789012345678901234567890
+ */
+
+ static final String JES_LEVEL_2_LIST_REGEX = "(\\S+)\\s+" + // job
+ // name
+ // ignored
+ "(\\S+)\\s+" + // job number
+ "(\\S+)\\s+" + // owner ignored
+ "(\\S+)\\s+" + // job status (OUTPUT,INPUT,ACTIVE) ignored
+ "(\\S+)\\s+" + // job class ignored
+ "(\\S+).*" // rest ignored
+ ;
+
+ /*
+ * ---------------------------------------------------------------------
+ * Very brief and incomplete description of the zOS/MVS-filesystem. (Note:
+ * "zOS" is the operating system on the mainframe, and is the new name for
+ * MVS)
+ *
+ * The filesystem on the mainframe does not have hierarchal structure as for
+ * example the unix filesystem. For a more comprehensive description, please
+ * refer to the IBM manuals
+ *
+ * @LINK:
+ * http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dgt2d440/CONTENTS
+ *
+ *
+ * Dataset names =============
+ *
+ * A dataset name consist of a number of qualifiers separated by '.', each
+ * qualifier can be at most 8 characters, and the total length of a dataset
+ * can be max 44 characters including the dots.
+ *
+ *
+ * Dataset organisation ====================
+ *
+ * A dataset represents a piece of storage allocated on one or more disks.
+ * The structure of the storage is described with the field dataset
+ * organinsation (DSORG). There are a number of dataset organisations, but
+ * only two are usable for FTP transfer.
+ *
+ * DSORG: PS: sequential, or flat file PO: partitioned dataset PO-E:
+ * extended partitioned dataset
+ *
+ * The PS file is just a flat file, as you would find it on the unix file
+ * system.
+ *
+ * The PO and PO-E files, can be compared to a single level directory
+ * structure. A PO file consist of a number of dataset members, or files if
+ * you will. It is possible to CD into the file, and to retrieve the
+ * individual members.
+ *
+ *
+ * Dataset record format =====================
+ *
+ * The physical layout of the dataset is described on the dataset itself.
+ * There are a number of record formats (RECFM), but just a few is relavant
+ * for the FTP transfer.
+ *
+ * Any one beginning with either F or V can safely used by FTP transfer. All
+ * others should only be used with great care, so this version will just
+ * ignore the other record formats. F means a fixed number of records per
+ * allocated storage, and V means a variable number of records.
+ *
+ *
+ * Other notes ===========
+ *
+ * The file system supports automatically backup and retrieval of datasets.
+ * If a file is backed up, the ftp LIST command will return: ARCIVE Not
+ * Direct Access Device KJ.IOP998.ERROR.PL.UNITTEST
+ *
+ *
+ * Implementation notes ====================
+ *
+ * Only datasets that have dsorg PS, PO or PO-E and have recfm beginning
+ * with F or V, is fully parsed.
+ *
+ * The following fields in FTPFile is used: FTPFile.Rawlisting: Always set.
+ * FTPFile.Type: DIRECTORY_TYPE or FILE_TYPE or UNKNOWN FTPFile.Name: name
+ * FTPFile.Timestamp: change time or null
+ *
+ *
+ *
+ * Additional information ======================
+ *
+ * The MVS ftp server supports a number of features via the FTP interface.
+ * The features are controlled with the FTP command quote site filetype=<SEQ|JES|DB2>
+ * SEQ is the default and used for normal file transfer JES is used to
+ * interact with the Job Entry Subsystem (JES) similar to a job scheduler
+ * DB2 is used to interact with a DB2 subsystem
+ *
+ * This parser supports SEQ and JES.
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+
+ /**
+ * The sole constructor for a MVSFTPEntryParser object.
+ *
+ */
+ public MVSFTPEntryParser() {
+ super(""); // note the regex is set in preParse.
+ super.configure(null); // configure parser with default configurations
+ }
+
+ /**
+ * Parses a line of an z/OS - 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, then
+ * <code> null </code> is returned. Otherwise a <code> FTPFile </code>
+ * instance representing the file is returned.
+ *
+ * @param entry
+ * A line of text from the file listing
+ * @return An FTPFile instance corresponding to the supplied entry
+ */
+ public FTPFile parseFTPEntry(String entry) {
+ boolean isParsed = false;
+ FTPFile f = new FTPFile();
+
+ if (isType == FILE_LIST_TYPE)
+ isParsed = parseFileList(f, entry);
+ else if (isType == MEMBER_LIST_TYPE) {
+ isParsed = parseMemberList(f, entry);
+ if (!isParsed)
+ isParsed = parseSimpleEntry(f, entry);
+ } else if (isType == UNIX_LIST_TYPE) {
+ isParsed = parseUnixList(f, entry);
+ } else if (isType == JES_LEVEL_1_LIST_TYPE) {
+ isParsed = parseJeslevel1List(f, entry);
+ } else if (isType == JES_LEVEL_2_LIST_TYPE) {
+ isParsed = parseJeslevel2List(f, entry);
+ }
+
+ if (!isParsed)
+ f = null;
+
+ return f;
+ }
+
+ /**
+ * Parse entries representing a dataset list. Only datasets with DSORG PS or
+ * PO or PO-E and with RECFM F* or V* will be parsed.
+ *
+ * Format of ZOS/MVS file list: 1 2 3 4 5 6 7 8 9 10 Volume Unit Referred
+ * Ext Used Recfm Lrecl BlkSz Dsorg Dsname B10142 3390 2006/03/20 2 31 F 80
+ * 80 PS MDI.OKL.WORK ARCIVE Not Direct Access Device
+ * KJ.IOP998.ERROR.PL.UNITTEST B1N231 3390 2006/03/20 1 15 VB 256 27998 PO
+ * PLU B1N231 3390 2006/03/20 1 15 VB 256 27998 PO-E PLB
+ *
+ * ----------------------------------- Group within Regex [1] Volume [2]
+ * Unit [3] Referred [4] Ext: number of extents [5] Used [6] Recfm: Record
+ * format [7] Lrecl: Logical record length [8] BlkSz: Block size [9] Dsorg:
+ * Dataset organisation. Many exists but only support: PS, PO, PO-E [10]
+ * Dsname: Dataset name
+ *
+ * Note: When volume is ARCIVE, it means the dataset is stored somewhere in
+ * a tape archive. These entries is currently not supported by this parser.
+ * A null value is returned.
+ *
+ * @param file
+ * will be updated with Name, Type, Timestamp if parsed.
+ * @param entry zosDirectoryEntry
+ * @return true: entry was parsed, false: entry was not parsed.
+ */
+ private boolean parseFileList(FTPFile file, String entry) {
+ if (matches(entry)) {
+ file.setRawListing(entry);
+ String name = group(2);
+ String dsorg = group(1);
+ file.setName(name);
+
+ // DSORG
+ if ("PS".equals(dsorg)) {
+ file.setType(FTPFile.FILE_TYPE);
+ }
+ else if ("PO".equals(dsorg) || "PO-E".equals(dsorg)) {
+ // regex already ruled out anything other than PO or PO-E
+ file.setType(FTPFile.DIRECTORY_TYPE);
+ }
+ else {
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Parse entries within a partitioned dataset.
+ *
+ * Format of a memberlist within a PDS: 1 2 3 4 5 6 7 8 9 Name VV.MM Created
+ * Changed Size Init Mod Id TBSHELF 01.03 2002/09/12 2002/10/11 09:37 11 11
+ * 0 KIL001 TBTOOL 01.12 2002/09/12 2004/11/26 19:54 51 28 0 KIL001
+ *
+ * ------------------------------------------- [1] Name [2] VV.MM: Version .
+ * modification [3] Created: yyyy / MM / dd [4,5] Changed: yyyy / MM / dd
+ * HH:mm [6] Size: number of lines [7] Init: number of lines when first
+ * created [8] Mod: number of modified lines a last save [9] Id: User id for
+ * last update
+ *
+ *
+ * @param file
+ * will be updated with Name, Type and Timestamp if parsed.
+ * @param entry zosDirectoryEntry
+ * @return true: entry was parsed, false: entry was not parsed.
+ */
+ private boolean parseMemberList(FTPFile file, String entry) {
+ if (matches(entry)) {
+ file.setRawListing(entry);
+ String name = group(1);
+ String datestr = group(2) + " " + group(3);
+ file.setName(name);
+ file.setType(FTPFile.FILE_TYPE);
+ try {
+ file.setTimestamp(super.parseTimestamp(datestr));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ // just ignore parsing errors.
+ // TODO check this is ok
+ return false; // this is a parsing failure too.
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Assigns the name to the first word of the entry. Only to be used from a
+ * safe context, for example from a memberlist, where the regex for some
+ * reason fails. Then just assign the name field of FTPFile.
+ *
+ * @param file
+ * @param entry
+ * @return
+ */
+ private boolean parseSimpleEntry(FTPFile file, String entry) {
+ if (entry != null && entry.length() > 0) {
+ file.setRawListing(entry);
+ String name = entry.split(" ")[0];
+ file.setName(name);
+ file.setType(FTPFile.FILE_TYPE);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Parse the entry as a standard unix file. Using the UnixFTPEntryParser.
+ *
+ * @param file
+ * @param entry
+ * @return true: entry is parsed, false: entry could not be parsed.
+ */
+ private boolean parseUnixList(FTPFile file, String entry) {
+ file = unixFTPEntryParser.parseFTPEntry(entry);
+ if (file == null)
+ return false;
+ return true;
+ }
+
+ /**
+ * Matches these entries, note: no header: [1] [2] [3] [4] [5] IBMUSER1
+ * JOB01906 OUTPUT 3 Spool Files
+ * 012345678901234567890123456789012345678901234 1 2 3 4
+ * ------------------------------------------- Group in regex [1] Job name
+ * [2] Job number [3] Job status (INPUT,ACTIVE,OUTPUT) [4] Number of sysout
+ * files [5] The string "Spool Files"
+ *
+ *
+ * @param file
+ * will be updated with Name, Type and Timestamp if parsed.
+ * @param entry zosDirectoryEntry
+ * @return true: entry was parsed, false: entry was not parsed.
+ */
+ private boolean parseJeslevel1List(FTPFile file, String entry) {
+ if (matches(entry)) {
+ if (group(3).equalsIgnoreCase("OUTPUT")) {
+ file.setRawListing(entry);
+ String name = group(2); /* Job Number, used by GET */
+ file.setName(name);
+ file.setType(FTPFile.FILE_TYPE);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Matches these entries, note: no header: [1] [2] [3] [4] [5] JOBNAME JOBID
+ * OWNER STATUS CLASS IBMUSER1 JOB01906 IBMUSER OUTPUT A RC=0000 3 spool
+ * files IBMUSER TSU01830 IBMUSER OUTPUT TSU ABEND=522 3 spool files
+ * 012345678901234567890123456789012345678901234 1 2 3 4
+ * ------------------------------------------- Group in regex [1] Job name
+ * [2] Job number [3] Owner [4] Job status (INPUT,ACTIVE,OUTPUT) [5] Job
+ * Class [6] The rest
+ *
+ *
+ * @param file
+ * will be updated with Name, Type and Timestamp if parsed.
+ * @param entry zosDirectoryEntry
+ * @return true: entry was parsed, false: entry was not parsed.
+ */
+ private boolean parseJeslevel2List(FTPFile file, String entry) {
+ if (matches(entry)) {
+ if (group(4).equalsIgnoreCase("OUTPUT")) {
+ file.setRawListing(entry);
+ String name = group(2); /* Job Number, used by GET */
+ file.setName(name);
+ file.setType(FTPFile.FILE_TYPE);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * preParse is called as part of the interface. Per definition is is called
+ * before the parsing takes place. Three kind of lists is recognize:
+ * z/OS-MVS File lists z/OS-MVS Member lists unix file lists
+ * @since 2.0
+ */
+ @Override
+ public List<String> preParse(List<String> orig) {
+ // simply remove the header line. Composite logic will take care of the
+ // two different types of
+ // list in short order.
+ if (orig != null && orig.size() > 0) {
+ String header = orig.get(0);
+ if (header.indexOf("Volume") >= 0 && header.indexOf("Dsname") >= 0) {
+ setType(FILE_LIST_TYPE);
+ super.setRegex(FILE_LIST_REGEX);
+ } else if (header.indexOf("Name") >= 0 && header.indexOf("Id") >= 0) {
+ setType(MEMBER_LIST_TYPE);
+ super.setRegex(MEMBER_LIST_REGEX);
+ } else if (header.indexOf("total") == 0) {
+ setType(UNIX_LIST_TYPE);
+ unixFTPEntryParser = new UnixFTPEntryParser();
+ } else if (header.indexOf("Spool Files") >= 30) {
+ setType(JES_LEVEL_1_LIST_TYPE);
+ super.setRegex(JES_LEVEL_1_LIST_REGEX);
+ } else if (header.indexOf("JOBNAME") == 0
+ && header.indexOf("JOBID") > 8) {// header contains JOBNAME JOBID OWNER // STATUS CLASS
+ setType(JES_LEVEL_2_LIST_TYPE);
+ super.setRegex(JES_LEVEL_2_LIST_REGEX);
+ } else {
+ setType(UNKNOWN_LIST_TYPE);
+ }
+
+ if (isType != JES_LEVEL_1_LIST_TYPE) { // remove header is necessary
+ orig.remove(0);
+ }
+ }
+
+ return orig;
+ }
+
+ /**
+ * Explicitly set the type of listing being processed.
+ * @param type The listing type.
+ */
+ void setType(int type) {
+ isType = type;
+ }
+
+ /*
+ * @return
+ */
+ @Override
+ protected FTPClientConfig getDefaultConfiguration() {
+ return new FTPClientConfig(FTPClientConfig.SYST_MVS,
+ DEFAULT_DATE_FORMAT, null, null, null, null);
+ }
}
Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java?rev=658520&r1=658519&r2=658520&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParser.java Tue May 20 18:14:11 2008
@@ -35,142 +35,142 @@
*/
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+" // Directory/file flag
- + "\\[(.*)\\]\\s+" // Attributes
- + "(\\S+)\\s+" + "(\\d+)\\s+" // Owner and size
- + "(\\S+\\s+\\S+\\s+((\\d+:\\d+)|(\\d{4})))" // Long/short date format
- + "\\s+(.*)"; // Filename (incl. spaces)
-
- /**
- * 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 {@link 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) {
- // intentionally do nothing
- }
-
- //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.indexOf("R") != -1) {
- f.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION,
- true);
- }
- if (attrib.indexOf("W") != -1) {
- 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 {@link FTPClientConfig FTPClientConfig}
- * parameter being specified.
- * @return the default configuration for this parser.
- */
- @Override
- protected FTPClientConfig getDefaultConfiguration() {
- return new FTPClientConfig(FTPClientConfig.SYST_NETWARE,
- DEFAULT_DATE_FORMAT, DEFAULT_RECENT_DATE_FORMAT, null, null,
- null);
- }
+ /**
+ * 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+" // Directory/file flag
+ + "\\[(.*)\\]\\s+" // Attributes
+ + "(\\S+)\\s+" + "(\\d+)\\s+" // Owner and size
+ + "(\\S+\\s+\\S+\\s+((\\d+:\\d+)|(\\d{4})))" // Long/short date format
+ + "\\s+(.*)"; // Filename (incl. spaces)
+
+ /**
+ * 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 {@link 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) {
+ // intentionally do nothing
+ }
+
+ //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.indexOf("R") != -1) {
+ f.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION,
+ true);
+ }
+ if (attrib.indexOf("W") != -1) {
+ 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 {@link FTPClientConfig FTPClientConfig}
+ * parameter being specified.
+ * @return the default configuration for this parser.
+ */
+ @Override
+ protected FTPClientConfig getDefaultConfiguration() {
+ return new FTPClientConfig(FTPClientConfig.SYST_NETWARE,
+ DEFAULT_DATE_FORMAT, DEFAULT_RECENT_DATE_FORMAT, null, null,
+ null);
+ }
}
Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java?rev=658520&r1=658519&r2=658520&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java Tue May 20 18:14:11 2008
@@ -35,121 +35,121 @@
* @author Steve Cohen <sc...@apache.org>
*/
public abstract class RegexFTPFileEntryParserImpl extends
- FTPFileEntryParserImpl {
- /**
- * 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 Matcher _matcher_ = null;
-
- /**
- * The constructor for a RegexFTPFileEntryParserImpl 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 RegexFTPFileEntryParserImpl(String regex) {
- super();
- setRegex(regex);
- }
-
- /**
- * 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;
- _matcher_ = pattern.matcher(s);
- if (_matcher_.matches()) {
- this.result = _matcher_.toMatchResult();
- }
- return null != this.result;
- }
-
- /**
- * Convenience method
- *
- * @return the number of groups() in the internal MatchResult.
- */
-
- public int getGroupCnt() {
- if (this.result == null) {
- return 0;
- }
- return this.result.groupCount();
- }
-
- /**
- * 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.groupCount(); i++) {
- b.append(i).append(") ").append(this.result.group(i)).append(
- System.getProperty("line.separator"));
- }
- return b.toString();
- }
-
- /**
- * Alter the current regular expression being utilised for entry parsing
- * and create a new {@link Pattern} instance.
- * @param regex The new regular expression
- * @return
- * @since 2.0
- */
- public boolean setRegex(String regex) {
- try {
- pattern = Pattern.compile(regex);
- } catch (PatternSyntaxException pse) {
- throw new IllegalArgumentException("Unparseable regex supplied: "
- + regex);
- }
- return (pattern != null);
- }
+ FTPFileEntryParserImpl {
+ /**
+ * 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 Matcher _matcher_ = null;
+
+ /**
+ * The constructor for a RegexFTPFileEntryParserImpl 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 RegexFTPFileEntryParserImpl(String regex) {
+ super();
+ setRegex(regex);
+ }
+
+ /**
+ * 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;
+ _matcher_ = pattern.matcher(s);
+ if (_matcher_.matches()) {
+ this.result = _matcher_.toMatchResult();
+ }
+ return null != this.result;
+ }
+
+ /**
+ * Convenience method
+ *
+ * @return the number of groups() in the internal MatchResult.
+ */
+
+ public int getGroupCnt() {
+ if (this.result == null) {
+ return 0;
+ }
+ return this.result.groupCount();
+ }
+
+ /**
+ * 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.groupCount(); i++) {
+ b.append(i).append(") ").append(this.result.group(i)).append(
+ System.getProperty("line.separator"));
+ }
+ return b.toString();
+ }
+
+ /**
+ * Alter the current regular expression being utilised for entry parsing
+ * and create a new {@link Pattern} instance.
+ * @param regex The new regular expression
+ * @return
+ * @since 2.0
+ */
+ public boolean setRegex(String regex) {
+ try {
+ pattern = Pattern.compile(regex);
+ } catch (PatternSyntaxException pse) {
+ throw new IllegalArgumentException("Unparseable regex supplied: "
+ + regex);
+ }
+ return (pattern != null);
+ }
}
Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java?rev=658520&r1=658519&r2=658520&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java Tue May 20 18:14:11 2008
@@ -133,8 +133,8 @@
* @since 2.0
*/
public SMTP(String encoding) {
- this();
- this.encoding = encoding;
+ this();
+ this.encoding = encoding;
}
private int __sendCommand(String command, String args, boolean includeSpace)
Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTPClient.java?rev=658520&r1=658519&r2=658520&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTPClient.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTPClient.java Tue May 20 18:14:11 2008
@@ -137,7 +137,7 @@
* @since 2.0
*/
public SMTPClient(String encoding) {
- super(encoding);
+ super(encoding);
}
Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java?rev=658520&r1=658519&r2=658520&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java Tue May 20 18:14:11 2008
@@ -55,24 +55,24 @@
* @param acceptremote - if set to true, any WILL request is accepted.
***/
public WindowSizeOptionHandler(
- int nWidth,
- int nHeight,
- boolean initlocal,
- boolean initremote,
- boolean acceptlocal,
- boolean acceptremote
+ int nWidth,
+ int nHeight,
+ boolean initlocal,
+ boolean initremote,
+ boolean acceptlocal,
+ boolean acceptremote
) {
super (
- TelnetOption.WINDOW_SIZE,
- initlocal,
- initremote,
- acceptlocal,
- acceptremote
- );
-
- m_nWidth = nWidth;
- m_nHeight = nHeight;
- }
+ TelnetOption.WINDOW_SIZE,
+ initlocal,
+ initremote,
+ acceptlocal,
+ acceptremote
+ );
+
+ m_nWidth = nWidth;
+ m_nHeight = nHeight;
+ }
/***
* Constructor for the WindowSizeOptionHandler. Initial and accept
@@ -82,19 +82,19 @@
* @param nHeight - Window Height
***/
public WindowSizeOptionHandler(
- int nWidth,
- int nHeight
+ int nWidth,
+ int nHeight
) {
super (
- TelnetOption.WINDOW_SIZE,
- false,
- false,
- false,
- false
- );
+ TelnetOption.WINDOW_SIZE,
+ false,
+ false,
+ false,
+ false
+ );
- m_nWidth = nWidth;
- m_nHeight = nHeight;
+ m_nWidth = nWidth;
+ m_nHeight = nHeight;
}
/***
@@ -120,59 +120,59 @@
@Override
public int[] startSubnegotiationLocal()
{
- int nCompoundWindowSize = m_nWidth * 0x10000 + m_nHeight;
- int nResponseSize = 5;
- int nIndex;
- int nShift;
- int nTurnedOnBits;
-
- if ((m_nWidth % 0x100) == 0xFF) {
- nResponseSize += 1;
- }
-
- if ((m_nWidth / 0x100) == 0xFF) {
- nResponseSize += 1;
- }
-
- if ((m_nHeight % 0x100) == 0xFF) {
- nResponseSize += 1;
- }
-
- if ((m_nHeight / 0x100) == 0xFF) {
- nResponseSize += 1;
- }
-
- //
- // allocate response array
- //
- int response[] = new int[nResponseSize];
-
- //
- // Build response array.
- // ---------------------
- // 1. put option name.
- // 2. loop through Window size and fill the values,
- // 3. duplicate 'ff' if needed.
- //
-
- response[0] = WINDOW_SIZE; // 1 //
-
- for ( // 2 //
- nIndex=1, nShift = 24;
- nIndex < nResponseSize;
- nIndex++, nShift -=8
- ) {
- nTurnedOnBits = 0xFF;
- nTurnedOnBits <<= nShift;
- response[nIndex] = (nCompoundWindowSize & nTurnedOnBits) >>> nShift;
-
- if (response[nIndex] == 0xff) { // 3 //
- nIndex++;
- response[nIndex] = 0xff;
- }
- }
+ int nCompoundWindowSize = m_nWidth * 0x10000 + m_nHeight;
+ int nResponseSize = 5;
+ int nIndex;
+ int nShift;
+ int nTurnedOnBits;
+
+ if ((m_nWidth % 0x100) == 0xFF) {
+ nResponseSize += 1;
+ }
+
+ if ((m_nWidth / 0x100) == 0xFF) {
+ nResponseSize += 1;
+ }
+
+ if ((m_nHeight % 0x100) == 0xFF) {
+ nResponseSize += 1;
+ }
+
+ if ((m_nHeight / 0x100) == 0xFF) {
+ nResponseSize += 1;
+ }
+
+ //
+ // allocate response array
+ //
+ int response[] = new int[nResponseSize];
+
+ //
+ // Build response array.
+ // ---------------------
+ // 1. put option name.
+ // 2. loop through Window size and fill the values,
+ // 3. duplicate 'ff' if needed.
+ //
+
+ response[0] = WINDOW_SIZE; // 1 //
+
+ for ( // 2 //
+ nIndex=1, nShift = 24;
+ nIndex < nResponseSize;
+ nIndex++, nShift -=8
+ ) {
+ nTurnedOnBits = 0xFF;
+ nTurnedOnBits <<= nShift;
+ response[nIndex] = (nCompoundWindowSize & nTurnedOnBits) >>> nShift;
+
+ if (response[nIndex] == 0xff) { // 3 //
+ nIndex++;
+ response[nIndex] = 0xff;
+ }
+ }
- return response;
+ return response;
}
/***