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.

TestHeadersFooters.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.sl;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.junit.Assert.assertFalse;
  22. import static org.junit.Assert.assertNull;
  23. import static org.junit.Assert.assertTrue;
  24. import static org.apache.poi.sl.TestTable.openSampleSlideshow;
  25. import java.io.IOException;
  26. import java.util.List;
  27. import org.apache.poi.hslf.model.HeadersFooters;
  28. import org.apache.poi.hslf.usermodel.HSLFSlide;
  29. import org.apache.poi.hslf.usermodel.HSLFSlideShow;
  30. import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
  31. import org.apache.poi.sl.usermodel.Shape;
  32. import org.apache.poi.sl.usermodel.Slide;
  33. import org.apache.poi.sl.usermodel.SlideShow;
  34. import org.apache.poi.sl.usermodel.TextParagraph;
  35. import org.apache.poi.sl.usermodel.TextShape;
  36. import org.junit.Test;
  37. public class TestHeadersFooters {
  38. @Test
  39. public void bug58144() throws IOException {
  40. SlideShow<?,?> ppt1 = openSampleSlideshow("bug58144-headers-footers-2003.ppt");
  41. HSLFSlide sl1 = (HSLFSlide)ppt1.getSlides().get(0);
  42. HeadersFooters hfs1 = sl1.getHeadersFooters();
  43. assertNull(hfs1.getHeaderText());
  44. assertEquals("Confidential", hfs1.getFooterText());
  45. List<List<HSLFTextParagraph>> llp1 = sl1.getTextParagraphs();
  46. assertEquals("Test", HSLFTextParagraph.getText(llp1.get(0)));
  47. assertFalse(llp1.get(0).get(0).isHeaderOrFooter());
  48. ppt1.close();
  49. String ppt2007s[] = {
  50. "bug58144-headers-footers-2007.ppt", "bug58144-headers-footers-2007.pptx"
  51. };
  52. for (String pptName : ppt2007s) {
  53. SlideShow<?,?> ppt2 = openSampleSlideshow(pptName);
  54. Slide<?,?> sl2 = ppt2.getSlides().get(0);
  55. if (ppt2 instanceof HSLFSlideShow) {
  56. HeadersFooters hfs2 = ((HSLFSlide)sl2).getHeadersFooters();
  57. assertNull(hfs2.getHeaderText());
  58. assertEquals("Slide footer", hfs2.getFooterText());
  59. }
  60. List<? extends Shape<?,?>> shapes = sl2.getShapes();
  61. TextShape<?,?> ts0 = (TextShape<?,?>)shapes.get(0);
  62. assertEquals("Test file", ts0.getText());
  63. TextShape<?,?> ts1 = (TextShape<?,?>)shapes.get(1);
  64. assertEquals("Has some text in the headers and footers", ts1.getText());
  65. TextShape<?,?> ts2 = (TextShape<?,?>)shapes.get(2);
  66. assertEquals("Slide footer", ts2.getText());
  67. List<? extends TextParagraph<?,?,?>> ltp2 = ts2.getTextParagraphs();
  68. assertTrue(ltp2.get(0).isHeaderOrFooter());
  69. ppt2.close();
  70. }
  71. }
  72. }