01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * 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;
22: import java.util.List;
23: import java.util.StringTokenizer;
24:
25: import org.openharmonise.vfs.*;
26:
27: /**
28: * @author Matthew Large
29: *
30: */
31: public class FTPUNIXListParser implements FTPListParseable {
32:
33: /**
34: *
35: */
36: public FTPUNIXListParser() {
37: super ();
38: }
39:
40: /* (non-Javadoc)
41: * @see com.simulacramedia.ftp.client.FTPListParseable#parse(java.lang.String[])
42: */
43: public List parse(String[] sListing, String sPath) {
44: ArrayList aListing = new ArrayList(7);
45:
46: ArrayList aSegments = (ArrayList) AbstractVirtualFileSystem
47: .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 sTok = new StringTokenizer(sListing[i],
59: " ", false);
60: int nCount = 1;
61: String sDateTemp = "";
62: while (sTok.hasMoreElements()) {
63: String sTemp = (String) sTok.nextElement();
64:
65: if (nCount == 1) {
66: if (sTemp.startsWith("d")) {
67: item.setIsDirectory(true);
68: }
69: } else if (nCount == 5) {
70: item.setSize(Integer.parseInt(sTemp));
71: } else if (nCount == 6) {
72: sDateTemp = sTemp;
73: } else if (nCount == 7) {
74: sDateTemp = sDateTemp + " " + sTemp;
75: } else if (nCount == 8) {
76: sDateTemp = sDateTemp + " " + sTemp;
77: item.setDate(sDateTemp);
78: } else if (nCount == 9) {
79: if (sTemp.equals(".")) {
80: item.setFileName((String) aSegments
81: .get(aSegments.size() - 1));
82: } else if (sTemp.equals("..")) {
83: item.setFileName((String) aSegments
84: .get(aSegments.size() - 2));
85: } else {
86: item.setFileName(sTemp);
87: }
88: }
89: nCount++;
90: }
91: aListing.add(item);
92: }
93:
94: return (List) aListing;
95: }
96:
97: }
|