Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ReadTitle.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.examples.hpsf;
  16. import java.io.File;
  17. import java.io.IOException;
  18. import org.apache.poi.hpsf.PropertySetFactory;
  19. import org.apache.poi.hpsf.SummaryInformation;
  20. import org.apache.poi.poifs.eventfilesystem.POIFSReader;
  21. import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
  22. /**
  23. * <p>Sample application showing how to read a OLE 2 document's
  24. * title. Call it with the document's file name as command line
  25. * parameter.</p>
  26. *
  27. * <p>Explanations can be found in the HPSF HOW-TO.</p>
  28. */
  29. @SuppressWarnings({"java:S106","java:S4823"})
  30. public final class ReadTitle {
  31. private ReadTitle() {}
  32. /**
  33. * <p>Runs the example program.</p>
  34. *
  35. * @param args Command-line arguments. The first command-line argument must
  36. * be the name of a POI filesystem to read.
  37. * @throws IOException if any I/O exception occurs.
  38. */
  39. public static void main(final String[] args) throws IOException {
  40. final String filename = args[0];
  41. POIFSReader r = new POIFSReader();
  42. r.registerListener(ReadTitle::processPOIFSReaderEvent, SummaryInformation.DEFAULT_STREAM_NAME);
  43. r.read(new File(filename));
  44. }
  45. private static void processPOIFSReaderEvent(final POIFSReaderEvent event) {
  46. SummaryInformation si;
  47. try {
  48. si = (SummaryInformation) PropertySetFactory.create(event.getStream());
  49. } catch (Exception ex) {
  50. throw new RuntimeException("Property set stream \"" + event.getPath() + event.getName() + "\": " + ex);
  51. }
  52. final String title = si.getTitle();
  53. System.out.println(title != null ? "Title: \"" + title + "\"" : "Document has no title.");
  54. }
  55. }