1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.net.ftp;
  17. import java.io.BufferedReader;
  18. import java.io.IOException;
  19. import java.util.List;
  20. /**
  21. * FTPFileEntryParser defines the interface for parsing a single FTP file
  22. * listing and converting that information into an
  23. * <a href="org.apache.commons.net.ftp.FTPFile.html"> FTPFile </a> instance.
  24. * Sometimes you will want to parse unusual listing formats, in which
  25. * case you would create your own implementation of FTPFileEntryParser and
  26. * if necessary, subclass FTPFile.
  27. * <p>
  28. * Here are some examples showing how to use one of the classes that
  29. * implement this interface.
  30. * <p>
  31. * The first example shows how to get an <b>iterable</b> list of files in which the
  32. * more expensive <code>FTPFile</code> objects are not created until needed. This
  33. * is suitable for paged displays. It requires that a parser object be created
  34. * beforehand: <code>parser</code> is an object (in the package
  35. * <code>org.apache.commons.net.ftp.parser</code>)
  36. * implementing this inteface.
  37. *
  38. * <pre>
  39. * FTPClient f=FTPClient();
  40. * f.connect(server);
  41. * f.login(username, password);
  42. * FTPFileList list = f.createFileList(directory, parser);
  43. * FTPFileIterator iter = list.iterator();
  44. *
  45. * while (iter.hasNext()) {
  46. * FTPFile[] files = iter.getNext(25); // "page size" you want
  47. * //do whatever you want with these files, display them, etc.
  48. * //expensive FTPFile objects not created until needed.
  49. * }
  50. * </pre>
  51. *
  52. * The second example uses the revised <code>FTPClient.listFiles()</code>
  53. * API to pull the whole list from the subfolder <code>subfolder</code> in
  54. * one call, attempting to automatically detect the parser type. This
  55. * method, without a parserKey parameter, indicates that autodection should
  56. * be used.
  57. *
  58. * <pre>
  59. * FTPClient f=FTPClient();
  60. * f.connect(server);
  61. * f.login(username, password);
  62. * FTPFile[] files = f.listFiles("subfolder");
  63. * </pre>
  64. *
  65. * The third example uses the revised <code>FTPClient.listFiles()</code>>
  66. * API to pull the whole list from the current working directory in one call,
  67. * but specifying by classname the parser to be used. For this particular
  68. * parser class, this approach is necessary since there is no way to
  69. * autodetect this server type.
  70. *
  71. * <pre>
  72. * FTPClient f=FTPClient();
  73. * f.connect(server);
  74. * f.login(username, password);
  75. * FTPFile[] files = f.listFiles(
  76. * "org.apache.commons.net.ftp.parser.EnterpriseUnixFTPFileEntryParser",
  77. * ".");
  78. * </pre>
  79. *
  80. * The fourth example uses the revised <code>FTPClient.listFiles()</code>
  81. * API to pull a single file listing in an arbitrary directory in one call,
  82. * specifying by KEY the parser to be used, in this case, VMS.
  83. *
  84. * <pre>
  85. * FTPClient f=FTPClient();
  86. * f.connect(server);
  87. * f.login(username, password);
  88. * FTPFile[] files = f.listFiles("VMS", "subfolder/foo.java");
  89. * </pre>
  90. *
  91. * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
  92. * @version $Id: FTPFileEntryParser.java,v 1.19 2004/04/21 23:30:33 scohen Exp $
  93. * @see org.apache.commons.net.ftp.FTPFile
  94. * @see org.apache.commons.net.ftp.FTPClient#createFileList
  95. */
  96. public interface FTPFileEntryParser
  97. {
  98. /**
  99. * Parses a line of an FTP server file listing and converts it into a usable
  100. * format in the form of an <code> FTPFile </code> instance. If the
  101. * file listing line doesn't describe a file, <code> null </code> should be
  102. * returned, otherwise a <code> FTPFile </code> instance representing the
  103. * files in the directory is returned.
  104. * <p>
  105. * @param listEntry A line of text from the file listing
  106. * @return An FTPFile instance corresponding to the supplied entry
  107. */
  108. FTPFile parseFTPEntry(String listEntry);
  109. /**
  110. * Reads the next entry using the supplied BufferedReader object up to
  111. * whatever delemits one entry from the next. Implementors must define
  112. * this for the particular ftp system being parsed. In many but not all
  113. * cases, this can be defined simply by calling BufferedReader.readLine().
  114. *
  115. * @param reader The BufferedReader object from which entries are to be
  116. * read.
  117. *
  118. * @return A string representing the next ftp entry or null if none found.
  119. * @exception IOException thrown on any IO Error reading from the reader.
  120. */
  121. String readNextEntry(BufferedReader reader) throws IOException;
  122. /**
  123. * This method is a hook for those implementors (such as
  124. * VMSVersioningFTPEntryParser, and possibly others) which need to
  125. * perform some action upon the FTPFileList after it has been created
  126. * from the server stream, but before any clients see the list.
  127. *
  128. * The default implementation can be a no-op.
  129. *
  130. * @param original Original list after it has been created from the server stream
  131. *
  132. * @return Original list as processed by this method.
  133. */
  134. List preParse(List original);
  135. }
  136. /* Emacs configuration
  137. * Local variables: **
  138. * mode: java **
  139. * c-basic-offset: 4 **
  140. * indent-tabs-mode: nil **
  141. * End: **
  142. */