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.

ExtractorProvider.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.File;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.util.List;
  20. import org.apache.poi.poifs.filesystem.DirectoryNode;
  21. import org.apache.poi.poifs.filesystem.Entry;
  22. import org.apache.poi.poifs.filesystem.FileMagic;
  23. public interface ExtractorProvider {
  24. boolean accepts(FileMagic fm);
  25. /**
  26. * Create Extractor via file
  27. * @param file the file
  28. * @param password the password or {@code null} if not encrypted
  29. * @return the extractor
  30. * @throws IOException if file can't be read or parsed
  31. */
  32. POITextExtractor create(File file, String password) throws IOException;
  33. /**
  34. * Create Extractor via InputStream
  35. * @param inputStream the stream
  36. * @param password the password or {@code null} if not encrypted
  37. * @return the extractor
  38. * @throws IOException if stream can't be read or parsed
  39. */
  40. POITextExtractor create(InputStream inputStream, String password) throws IOException;
  41. /**
  42. * Create Extractor from POIFS node
  43. * @param poifsDir the node
  44. * @param password the password or {@code null} if not encrypted
  45. * @return the extractor
  46. * @throws IOException if node can't be parsed
  47. */
  48. POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException;
  49. /**
  50. * Returns an array of text extractors, one for each of
  51. * the embedded documents in the file (if there are any).
  52. * If there are no embedded documents, you'll get back an
  53. * empty array. Otherwise, you'll get one open
  54. * {@link POITextExtractor} for each embedded file.
  55. *
  56. * @param ext the extractor holding the directory to start parsing
  57. * @param dirs a list to be filled with directory references holding embedded
  58. * @param nonPOIFS a list to be filled with streams which aren't based on POIFS entries
  59. *
  60. * @throws IOException when the format specific extraction fails because of invalid entires
  61. */
  62. default void identifyEmbeddedResources(POIOLE2TextExtractor ext, List<Entry> dirs, List<InputStream> nonPOIFS) throws IOException {
  63. throw new IllegalArgumentException("Error checking for Scratchpad embedded resources");
  64. }
  65. }