001: /*
002: * Copyright 2005 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.net.ftp.parser;
017:
018: import org.apache.commons.net.ftp.FTPClientConfig;
019: import org.apache.commons.net.ftp.FTPFile;
020:
021: /**
022: * Implementation of FTPFileEntryParser and FTPFileListParser for IBM MVS Systems.
023: *
024: * @author <a href="jnadler@srcginc.com">Jeff Nadler</a>
025: * @author <a href="wnoto@openfinance.com">William Noto</a>
026: * @version $Id$
027: * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions)
028: */
029: public class MVSFTPEntryParser extends
030: ConfigurableFTPFileEntryParserImpl {
031: /**
032: * This is the regular expression used by this parser.
033: */
034: private static final String REGEX = "(.*)\\s+([^\\s]+)\\s*";
035:
036: /**
037: * Although this parser is now ignoring dates, someone may someday
038: * figure out a way to accomodate this and this appears to be the
039: * format used. For now, it won't be used.
040: * SMC 2005/04/08
041: */
042: static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd"; // 2001/11/09
043:
044: // This is not at all the tightest possible regexp for MVS LIST
045: // output, but I'm not a mainframe guru so I have little idea what the
046: // range of valid values are. I just needed to get the filename (Dsname);
047: // note that no other FTPFile fields can be filled in with the results of
048: // a LIST on MVS. The 'Referred' date seems to be 'last accessed date'
049: // and not 'last modified date' so I didn't bother parsing it.
050: //
051: // Of course it works perfectly as-is and it distinguishes header lines from
052: // file results so that's the important thing.
053: //
054: // This parser should be used when SYST returns:
055: // 'MVS is the operating system of this server. FTP Server is running on z/OS.'
056: //
057: // Also note that there is no concept of directories in MVS, just datasets,
058: // which have names composed of four dot separated names of up to 8 chars.
059: // As a result, FTPFile.FILE_TYPE is always used. -JN 6/2004 jnadler<at>srcginc<dotcom>
060:
061: // Sample LIST results from MVS:
062: //
063: //Volume Unit Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname
064: //FPFS42 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.RPTBM023.D061704
065: //FPFS41 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.RPTBM056.D061704
066: //FPFS25 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.WTM204.D061704
067:
068: /**
069: * The sole constructor for a MVSFTPEntryParser object.
070: *
071: * @exception IllegalArgumentException
072: * Thrown if the regular expression is unparseable. Should not be seen
073: * under normal conditions. It it is seen, this is a sign that
074: * <code>REGEX</code> is not a valid regular expression.
075: */
076: public MVSFTPEntryParser() {
077: super (REGEX);
078: }
079:
080: /**
081: * Parses a line of an MVS FTP server file listing and converts it into a
082: * usable format in the form of an <code> FTPFile </code> instance. If the
083: * file listing line doesn't describe a file, <code> null </code> is
084: * returned, otherwise a <code> FTPFile </code> instance representing the
085: * files in the directory is returned.
086: * <p>
087: * @param entry A line of text from the file listing
088: * @return An FTPFile instance corresponding to the supplied entry
089: */
090: public FTPFile parseFTPEntry(String entry) {
091: FTPFile f = null;
092: if (matches(entry)) {
093: f = new FTPFile();
094: String dataSetName = group(2);
095: f.setType(FTPFile.FILE_TYPE);
096: f.setName(dataSetName);
097:
098: return (f);
099: }
100: return null;
101: }
102:
103: /*
104: * @return
105: */
106: protected FTPClientConfig getDefaultConfiguration() {
107: return new FTPClientConfig(FTPClientConfig.SYST_MVS,
108: DEFAULT_DATE_FORMAT, null, null, null, null);
109: }
110: }
|