Source Code Cross Referenced for NTFTPEntryParser.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 NT 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: NTFTPEntryParser.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 NTFTPEntryParser extends
032:                ConfigurableFTPFileEntryParserImpl {
033:
034:            private static final String DEFAULT_DATE_FORMAT = "MM-dd-yy hh:mma"; //11-09-01 12:30PM
035:
036:            /**
037:             * this is the regular expression used by this parser.
038:             */
039:            private static final String REGEX = "(\\S+)\\s+(\\S+)\\s+"
040:                    + "(<DIR>)?\\s*" + "([0-9]+)?\\s+" + "(\\S.*)";
041:
042:            /**
043:             * The sole constructor for an NTFTPEntryParser object.
044:             *
045:             * @exception IllegalArgumentException
046:             * Thrown if the regular expression is unparseable.  Should not be seen
047:             * under normal conditions.  It it is seen, this is a sign that
048:             * <code>REGEX</code> is  not a valid regular expression.
049:             */
050:            public NTFTPEntryParser() {
051:                this (null);
052:            }
053:
054:            /**
055:             * This constructor allows the creation of an NTFTPEntryParser object 
056:             * with something other than the default configuration.
057:             *
058:             * @param config The {@link FTPClientConfig configuration} object used to 
059:             * configure this parser.
060:             * @exception IllegalArgumentException
061:             * Thrown if the regular expression is unparseable.  Should not be seen
062:             * under normal conditions.  It it is seen, this is a sign that
063:             * <code>REGEX</code> is  not a valid regular expression.
064:             * @since 1.4
065:             */
066:            public NTFTPEntryParser(FTPClientConfig config) {
067:                super (REGEX);
068:                configure(config);
069:            }
070:
071:            /**
072:             * Parses a line of an NT FTP server file listing and converts it into a
073:             * usable format in the form of an <code> FTPFile </code> instance.  If the
074:             * file listing line doesn't describe a file, <code> null </code> is
075:             * returned, otherwise a <code> FTPFile </code> instance representing the
076:             * files in the directory is returned.
077:             * <p>
078:             * @param entry A line of text from the file listing
079:             * @return An FTPFile instance corresponding to the supplied entry
080:             */
081:            public FTPFile parseFTPEntry(String entry) {
082:                FTPFile f = new FTPFile();
083:                f.setRawListing(entry);
084:
085:                if (matches(entry)) {
086:                    String datestr = group(1) + " " + group(2);
087:                    String dirString = group(3);
088:                    String size = group(4);
089:                    String name = group(5);
090:                    try {
091:                        f.setTimestamp(super .parseTimestamp(datestr));
092:                    } catch (ParseException e) {
093:                        return null; // this is a parsing failure too.
094:                    }
095:
096:                    if (null == name || name.equals(".") || name.equals("..")) {
097:                        return (null);
098:                    }
099:                    f.setName(name);
100:
101:                    if ("<DIR>".equals(dirString)) {
102:                        f.setType(FTPFile.DIRECTORY_TYPE);
103:                        f.setSize(0);
104:                    } else {
105:                        f.setType(FTPFile.FILE_TYPE);
106:                        if (null != size) {
107:                            f.setSize(Long.parseLong(size));
108:                        }
109:                    }
110:                    return (f);
111:                }
112:                return null;
113:            }
114:
115:            /**
116:             * Defines a default configuration to be used when this class is
117:             * instantiated without a {@link  FTPClientConfig  FTPClientConfig}
118:             * parameter being specified.
119:             * @return the default configuration for this parser.
120:             */
121:            public FTPClientConfig getDefaultConfiguration() {
122:                return new FTPClientConfig(FTPClientConfig.SYST_NT,
123:                        DEFAULT_DATE_FORMAT, null, null, null, null);
124:            }
125:
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.