Source Code Cross Referenced for EnterpriseUnixFTPEntryParser.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » ftp » parser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.ftp.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-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 java.util.Calendar;
019:
020:        import org.apache.commons.net.ftp.FTPFile;
021:
022:        /**
023:         * Parser for the Connect Enterprise Unix FTP Server From Sterling Commerce.
024:         * Here is a sample of the sort of output line this parser processes:
025:         *  "-C--E-----FTP B QUA1I1      18128       41 Aug 12 13:56 QUADTEST"
026:         * <P><B>
027:         * Note: EnterpriseUnixFTPEntryParser can only be instantiated through the
028:         * DefaultFTPParserFactory by classname.  It will not be chosen
029:         * by the autodetection scheme.
030:         * </B>
031:         * @version $Id: EnterpriseUnixFTPEntryParser.java 165675 2005-05-02 20:09:55Z rwinston $
032:         * @author <a href="Winston.Ojeda@qg.com">Winston Ojeda</a>
033:         * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions)
034:         * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
035:         */
036:        public class EnterpriseUnixFTPEntryParser extends
037:                RegexFTPFileEntryParserImpl {
038:
039:            /**
040:             * months abbreviations looked for by this parser.  Also used
041:             * to determine <b>which</b> month has been matched by the parser.
042:             */
043:            private static final String MONTHS = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
044:
045:            /**
046:             * this is the regular expression used by this parser.
047:             */
048:            private static final String REGEX = "(([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])"
049:                    + "([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z]))"
050:                    + "(\\S*)\\s*"
051:                    + "(\\S+)\\s*"
052:                    + "(\\S*)\\s*"
053:                    + "(\\d*)\\s*"
054:                    + "(\\d*)\\s*"
055:                    + MONTHS
056:                    + "\\s*"
057:                    + "((?:[012]\\d*)|(?:3[01]))\\s*"
058:                    + "((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s"
059:                    + "(\\S*)(\\s*.*)";
060:
061:            /**
062:             * The sole constructor for a EnterpriseUnixFTPEntryParser object.
063:             *
064:             */
065:            public EnterpriseUnixFTPEntryParser() {
066:                super (REGEX);
067:            }
068:
069:            /**
070:             * Parses a line of a unix FTP server file listing and converts  it into a
071:             * usable format in the form of an <code> FTPFile </code>  instance.  If
072:             * the file listing line doesn't describe a file,  <code> null </code> is
073:             * returned, otherwise a <code> FTPFile </code>  instance representing the
074:             * files in the directory is returned.
075:             *
076:             * @param entry A line of text from the file listing
077:             * @return An FTPFile instance corresponding to the supplied entry
078:             */
079:            public FTPFile parseFTPEntry(String entry) {
080:
081:                FTPFile file = new FTPFile();
082:                file.setRawListing(entry);
083:
084:                if (matches(entry)) {
085:                    String usr = group(14);
086:                    String grp = group(15);
087:                    String filesize = group(16);
088:                    String mo = group(17);
089:                    String da = group(18);
090:                    String yr = group(20);
091:                    String hr = group(21);
092:                    String min = group(22);
093:                    String name = group(23);
094:
095:                    file.setType(FTPFile.FILE_TYPE);
096:                    file.setUser(usr);
097:                    file.setGroup(grp);
098:                    try {
099:                        file.setSize(Long.parseLong(filesize));
100:                    } catch (NumberFormatException e) {
101:                        // intentionally do nothing
102:                    }
103:
104:                    Calendar cal = Calendar.getInstance();
105:                    cal.set(Calendar.MILLISECOND, 0);
106:                    cal.set(Calendar.SECOND, 0);
107:                    cal.set(Calendar.MINUTE, 0);
108:                    cal.set(Calendar.HOUR_OF_DAY, 0);
109:                    try {
110:
111:                        int pos = MONTHS.indexOf(mo);
112:                        int month = pos / 4;
113:                        if (yr != null) {
114:                            // it's a year
115:                            cal.set(Calendar.YEAR, Integer.parseInt(yr));
116:                        } else {
117:                            // it must be  hour/minute or we wouldn't have matched
118:                            int year = cal.get(Calendar.YEAR);
119:
120:                            // if the month we're reading is greater than now, it must
121:                            // be last year
122:                            if (cal.get(Calendar.MONTH) < month) {
123:                                year--;
124:                            }
125:                            cal.set(Calendar.YEAR, year);
126:                            cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hr));
127:                            cal.set(Calendar.MINUTE, Integer.parseInt(min));
128:                        }
129:                        cal.set(Calendar.MONTH, month);
130:                        cal.set(Calendar.DATE, Integer.parseInt(da));
131:                        file.setTimestamp(cal);
132:                    } catch (NumberFormatException e) {
133:                        // do nothing, date will be uninitialized
134:                    }
135:                    file.setName(name);
136:
137:                    return file;
138:                }
139:                return null;
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.