You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

POITextExtractor.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.extractor;
  16. import java.io.Closeable;
  17. import java.io.IOException;
  18. /**
  19. * Common Parent for Text Extractors
  20. * of POI Documents.
  21. * You will typically find the implementation of
  22. * a given format's text extractor under
  23. * org.apache.poi.[format].extractor .
  24. *
  25. * @see org.apache.poi.hssf.extractor.ExcelExtractor
  26. * @see org.apache.poi.hdgf.extractor.VisioTextExtractor
  27. * @see org.apache.poi.hwpf.extractor.WordExtractor
  28. */
  29. public interface POITextExtractor extends Closeable {
  30. /**
  31. * Retrieves all the text from the document.
  32. * How cells, paragraphs etc are separated in the text
  33. * is implementation specific - see the javadocs for
  34. * a specific project for details.
  35. * @return All the text from the document
  36. */
  37. String getText();
  38. /**
  39. * Returns another text extractor, which is able to
  40. * output the textual content of the document
  41. * metadata / properties, such as author and title.
  42. *
  43. * @return the metadata and text extractor
  44. */
  45. POITextExtractor getMetadataTextExtractor();
  46. /**
  47. * @param doCloseFilesystem {@code true} (default), if underlying resources/filesystem should be
  48. * closed on {@link #close()}
  49. */
  50. void setCloseFilesystem(boolean doCloseFilesystem);
  51. /**
  52. * @return {@code true}, if resources/filesystem should be closed on {@link #close()}
  53. */
  54. boolean isCloseFilesystem();
  55. /**
  56. * @return The underlying resources/filesystem
  57. */
  58. Closeable getFilesystem();
  59. /**
  60. * Allows to free resources of the Extractor as soon as
  61. * it is not needed any more. This may include closing
  62. * open file handles and freeing memory.
  63. *
  64. * The Extractor cannot be used after close has been called.
  65. */
  66. @Override
  67. default void close() throws IOException {
  68. Closeable fs = getFilesystem();
  69. if (isCloseFilesystem() && fs != null) {
  70. fs.close();
  71. }
  72. }
  73. /**
  74. * @return the processed document
  75. */
  76. Object getDocument();
  77. }