Source Code Cross Referenced for OS2FTPEntryParser.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.text.ParseException;
019:
020:        import org.apache.commons.net.ftp.FTPClientConfig;
021:        import org.apache.commons.net.ftp.FTPFile;
022:
023:        /**
024:         * Implementation of FTPFileEntryParser and FTPFileListParser for OS2 Systems.
025:         *
026:         * @author <a href="Winston.Ojeda@qg.com">Winston Ojeda</a>
027:         * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
028:         * @version $Id: OS2FTPEntryParser.java 155429 2005-02-26 13:13:04Z dirkv $
029:         * @see org.apache.commons.net.ftp.FTPFileEntryParser FTPFileEntryParser (for usage instructions)
030:         */
031:        public class OS2FTPEntryParser extends
032:                ConfigurableFTPFileEntryParserImpl
033:
034:        {
035:
036:            private static final String DEFAULT_DATE_FORMAT = "MM-dd-yy HH:mm"; //11-09-01 12:30
037:            /**
038:             * this is the regular expression used by this parser.
039:             */
040:            private static final String REGEX = "(\\s+|[0-9]+)\\s*"
041:                    + "(\\s+|[A-Z]+)\\s*" + "(DIR|\\s+)\\s*"
042:                    + "(\\S+)\\s+(\\S+)\\s+" /* date stuff */
043:                    + "(\\S.*)";
044:
045:            /**
046:             * The default constructor for a OS2FTPEntryParser object.
047:             *
048:             * @exception IllegalArgumentException
049:             * Thrown if the regular expression is unparseable.  Should not be seen
050:             * under normal conditions.  It it is seen, this is a sign that
051:             * <code>REGEX</code> is  not a valid regular expression.
052:             */
053:            public OS2FTPEntryParser() {
054:                this (null);
055:            }
056:
057:            /**
058:             * This constructor allows the creation of an OS2FTPEntryParser object 
059:             * with something other than the default configuration.
060:             *
061:             * @param config The {@link FTPClientConfig configuration} object used to 
062:             * configure this parser.
063:             * @exception IllegalArgumentException
064:             * Thrown if the regular expression is unparseable.  Should not be seen
065:             * under normal conditions.  It it is seen, this is a sign that
066:             * <code>REGEX</code> is  not a valid regular expression.
067:             * @since 1.4
068:             */
069:            public OS2FTPEntryParser(FTPClientConfig config) {
070:                super (REGEX);
071:                configure(config);
072:            }
073:
074:            /**
075:             * Parses a line of an OS2 FTP server file listing and converts it into a
076:             * usable format in the form of an <code> FTPFile </code> instance.  If the
077:             * file listing line doesn't describe a file, <code> null </code> is
078:             * returned, otherwise a <code> FTPFile </code> instance representing the
079:             * files in the directory is returned.
080:             * <p>
081:             * @param entry A line of text from the file listing
082:             * @return An FTPFile instance corresponding to the supplied entry
083:             */
084:            public FTPFile parseFTPEntry(String entry) {
085:
086:                FTPFile f = new FTPFile();
087:                if (matches(entry)) {
088:                    String size = group(1);
089:                    String attrib = group(2);
090:                    String dirString = group(3);
091:                    String datestr = group(4) + " " + group(5);
092:                    String name = group(6);
093:                    try {
094:                        f.setTimestamp(super .parseTimestamp(datestr));
095:                    } catch (ParseException e) {
096:                        return null; // this is a parsing failure too.
097:                    }
098:
099:                    //is it a DIR or a file
100:                    if (dirString.trim().equals("DIR")
101:                            || attrib.trim().equals("DIR")) {
102:                        f.setType(FTPFile.DIRECTORY_TYPE);
103:                    } else {
104:                        f.setType(FTPFile.FILE_TYPE);
105:                    }
106:
107:                    //set the name
108:                    f.setName(name.trim());
109:
110:                    //set the size
111:                    f.setSize(Long.parseLong(size.trim()));
112:
113:                    return (f);
114:                }
115:                return null;
116:
117:            }
118:
119:            /**
120:             * Defines a default configuration to be used when this class is
121:             * instantiated without a {@link  FTPClientConfig  FTPClientConfig}
122:             * parameter being specified.
123:             * @return the default configuration for this parser.
124:             */
125:            protected FTPClientConfig getDefaultConfiguration() {
126:                return new FTPClientConfig(FTPClientConfig.SYST_OS2,
127:                        DEFAULT_DATE_FORMAT, null, null, null, null);
128:            }
129:
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.