KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > ftp > client > FTPUNIXListParser


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.ftp.client;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24
25 import org.openharmonise.vfs.*;
26
27
28 /**
29  * @author Matthew Large
30  *
31  */

32 public class FTPUNIXListParser implements FTPListParseable {
33
34     /**
35      *
36      */

37     public FTPUNIXListParser() {
38         super();
39     }
40
41     /* (non-Javadoc)
42      * @see com.simulacramedia.ftp.client.FTPListParseable#parse(java.lang.String[])
43      */

44     public List JavaDoc parse(String JavaDoc[] sListing, String JavaDoc sPath) {
45         ArrayList JavaDoc aListing = new ArrayList JavaDoc(7);
46         
47         ArrayList JavaDoc aSegments = (ArrayList JavaDoc) AbstractVirtualFileSystem.getPathSegments(sPath, "/");
48         
49         if(aSegments.size()==1) {
50             aSegments.add(0, "..");
51         } else if(aSegments.size()==0) {
52             aSegments.add(0, "..");
53             aSegments.add(1, ".");
54         }
55
56         for (int i = 1; i < sListing.length; i++) {
57             FTPListItem item = new FTPListItem();
58             StringTokenizer JavaDoc sTok = new StringTokenizer JavaDoc(sListing[i], " ", false);
59             int nCount = 1;
60             String JavaDoc sDateTemp = "";
61             while (sTok.hasMoreElements()) {
62                 String JavaDoc sTemp = (String JavaDoc) sTok.nextElement();
63
64                 if (nCount == 1) {
65                     if (sTemp.startsWith("d")) {
66                         item.setIsDirectory(true);
67                     }
68                 } else if (nCount == 5) {
69                     item.setSize(Integer.parseInt(sTemp));
70                 } else if (nCount == 6) {
71                     sDateTemp = sTemp;
72                 } else if (nCount == 7) {
73                     sDateTemp = sDateTemp + " " + sTemp;
74                 } else if (nCount == 8) {
75                     sDateTemp = sDateTemp + " " + sTemp;
76                     item.setDate(sDateTemp);
77                 } else if (nCount == 9) {
78                     if( sTemp.equals(".") ) {
79                         item.setFileName( (String JavaDoc)aSegments.get(aSegments.size()-1) );
80                     } else if( sTemp.equals("..") ) {
81                         item.setFileName( (String JavaDoc)aSegments.get(aSegments.size()-2) );
82                     } else {
83                         item.setFileName(sTemp);
84                     }
85                 }
86                 nCount++;
87             }
88             aListing.add(item);
89         }
90
91         return (List JavaDoc) aListing;
92     }
93
94 }
95
Popular Tags