Coverage report

| %line | %branch
--- | --- | ---
org.apache.commons.net.ftp.parser.EnterpriseUnixFTPEntryParser |
91% |
100% |

1 |  |
     /*
2 |  |
      * Copyright 2001-2005 The Apache Software Foundation
3 |  |
      *
4 |  |
      * Licensed under the Apache License, Version 2.0 (the "License");
5 |  |
      * you may not use this file except in compliance with the License.
6 |  |
      * You may obtain a copy of the License at
7 |  |
      *
8 |  |
      *     http://www.apache.org/licenses/LICENSE-2.0
9 |  |
      *
10 |  |
      * Unless required by applicable law or agreed to in writing, software
11 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
12 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  |
      * See the License for the specific language governing permissions and
14 |  |
      * limitations under the License.
15 |  |
      */
16 |  |
     package org.apache.commons.net.ftp.parser;
17 |  |
     import java.util.Calendar;
18 |  |
19 |  |
     import org.apache.commons.net.ftp.FTPFile;
20 |  |
21 |  |
     /**
22 |  |
      * Parser for the Connect Enterprise Unix FTP Server From Sterling Commerce.
23 |  |
      * Here is a sample of the sort of output line this parser processes:
24 |  |
      *  "-C--E-----FTP B QUA1I1      18128       41 Aug 12 13:56 QUADTEST"
25 |  |
      * <P><B>
26 |  |
      * Note: EnterpriseUnixFTPEntryParser can only be instantiated through the
27 |  |
      * DefaultFTPParserFactory by classname.  It will not be chosen
28 |  |
      * by the autodetection scheme.
29 |  |
      * </B>
30 |  |
      * @version $Id: EnterpriseUnixFTPEntryParser.java 165675 2005-05-02 20:09:55Z rwinston $
31 |  |
      * @author <a href="Winston.Ojeda@qg.com">Winston Ojeda</a>
32 |  |
      * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions)
33 |  |
      * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
34 |  |
      */
35 |  |
     public class EnterpriseUnixFTPEntryParser extends RegexFTPFileEntryParserImpl
36 |  |
     {
37 |  |
38 |  |
         /**
39 |  |
          * months abbreviations looked for by this parser.  Also used
40 |  |
          * to determine <b>which</b> month has been matched by the parser.
41 |  |
          */
42 |  |
         private static final String MONTHS =
43 |  |
             "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
44 |  |
45 |  |
         /**
46 |  |
          * this is the regular expression used by this parser.
47 |  |
          */
48 |  |
         private static final String REGEX =
49 |  |
             "(([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])"
50 |  |
             + "([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z]))"
51 |  |
             + "(\\S*)\\s*"
52 |  |
             + "(\\S+)\\s*"
53 |  |
             + "(\\S*)\\s*"
54 |  |
             + "(\\d*)\\s*"
55 |  |
             + "(\\d*)\\s*"
56 |  |
             + MONTHS
57 |  |
             + "\\s*"
58 |  |
             + "((?:[012]\\d*)|(?:3[01]))\\s*"
59 |  |
             + "((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s"
60 |  |
             + "(\\S*)(\\s*.*)";
61 |  |
62 |  |
         /**
63 |  |
          * The sole constructor for a EnterpriseUnixFTPEntryParser object.
64 |  |
          *
65 |  |
          */
66 |  |
         public EnterpriseUnixFTPEntryParser()
67 |  |
         {
68 | 10 |
             super(REGEX);
69 | 10 |
         }
70 |  |
71 |  |
         /**
72 |  |
          * Parses a line of a unix FTP server file listing and converts  it into a
73 |  |
          * usable format in the form of an <code> FTPFile </code>  instance.  If
74 |  |
          * the file listing line doesn't describe a file,  <code> null </code> is
75 |  |
          * returned, otherwise a <code> FTPFile </code>  instance representing the
76 |  |
          * files in the directory is returned.
77 |  |
          *
78 |  |
          * @param entry A line of text from the file listing
79 |  |
          * @return An FTPFile instance corresponding to the supplied entry
80 |  |
          */
81 |  |
         public FTPFile parseFTPEntry(String entry)
82 |  |
         {
83 |  |
84 | 50 |
             FTPFile file = new FTPFile();
85 | 50 |
             file.setRawListing(entry);
86 |  |
87 | 50 |
             if (matches(entry))
88 |  |
             {
89 | 6 |
                 String usr = group(14);
90 | 6 |
                 String grp = group(15);
91 | 6 |
                 String filesize = group(16);
92 | 6 |
                 String mo = group(17);
93 | 6 |
                 String da = group(18);
94 | 6 |
                 String yr = group(20);
95 | 6 |
                 String hr = group(21);
96 | 6 |
                 String min = group(22);
97 | 6 |
                 String name = group(23);
98 |  |
99 | 6 |
                 file.setType(FTPFile.FILE_TYPE);
100 | 6 |
                 file.setUser(usr);
101 | 6 |
                 file.setGroup(grp);
102 |  |
                 try
103 |  |
                 {
104 | 6 |
                     file.setSize(Long.parseLong(filesize));
105 |  |
                 }
106 | 0 |
                 catch (NumberFormatException e)
107 |  |
                 {
108 |  |
                     // intentionally do nothing
109 | 6 |
                 }
110 |  |
111 | 6 |
                 Calendar cal = Calendar.getInstance();
112 | 6 |
     	    cal.set(Calendar.MILLISECOND, 0);
113 | 6 |
                 cal.set(Calendar.SECOND,
114 |  |
                         0);
115 | 6 |
                 cal.set(Calendar.MINUTE,
116 |  |
                         0);
117 | 6 |
                 cal.set(Calendar.HOUR_OF_DAY,
118 |  |
                         0);
119 |  |
                 try
120 |  |
                 {
121 |  |
122 | 6 |
                     int pos = MONTHS.indexOf(mo);
123 | 6 |
                     int month = pos / 4;
124 | 6 |
                     if (yr != null)
125 |  |
                     {
126 |  |
                         // it's a year
127 | 0 |
                         cal.set(Calendar.YEAR,
128 |  |
                                 Integer.parseInt(yr));
129 |  |
                     }
130 |  |
                     else
131 |  |
                     {
132 |  |
                         // it must be  hour/minute or we wouldn't have matched
133 | 6 |
                         int year = cal.get(Calendar.YEAR);
134 |  |
135 |  |
                         // if the month we're reading is greater than now, it must
136 |  |
                         // be last year
137 | 6 |
                         if (cal.get(Calendar.MONTH) < month)
138 |  |
                         {
139 | 6 |
                             year--;
140 |  |
                         }
141 | 6 |
                         cal.set(Calendar.YEAR,
142 |  |
                                 year);
143 | 6 |
                         cal.set(Calendar.HOUR_OF_DAY,
144 |  |
                                 Integer.parseInt(hr));
145 | 6 |
                         cal.set(Calendar.MINUTE,
146 |  |
                                 Integer.parseInt(min));
147 |  |
                     }
148 | 6 |
                     cal.set(Calendar.MONTH,
149 |  |
                             month);
150 | 6 |
                     cal.set(Calendar.DATE,
151 |  |
                             Integer.parseInt(da));
152 | 6 |
                     file.setTimestamp(cal);
153 |  |
                 }
154 | 0 |
                 catch (NumberFormatException e)
155 |  |
                 {
156 |  |
                     // do nothing, date will be uninitialized
157 | 6 |
                 }
158 | 6 |
                 file.setName(name);
159 |  |
160 | 6 |
                 return file;
161 |  |
             }
162 | 44 |
             return null;
163 |  |
         }
164 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.