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.

OSGiSlideShowIT.java 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.osgi;
  16. import org.apache.poi.hslf.usermodel.HSLFSlideShow;
  17. import org.apache.poi.sl.usermodel.*;
  18. import org.apache.poi.xslf.usermodel.XMLSlideShow;
  19. import org.junit.Test;
  20. import org.junit.runner.RunWith;
  21. import org.ops4j.pax.exam.junit.PaxExam;
  22. import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
  23. import org.ops4j.pax.exam.spi.reactors.PerClass;
  24. import java.awt.*;
  25. import java.io.ByteArrayInputStream;
  26. import java.io.ByteArrayOutputStream;
  27. import java.util.List;
  28. import static org.junit.Assert.assertEquals;
  29. /**
  30. * Test to ensure that all our main formats can create, write
  31. * and read back in, when running under OSGi
  32. */
  33. @RunWith(PaxExam.class)
  34. @ExamReactorStrategy(PerClass.class)
  35. public class OSGiSlideShowIT extends BaseOSGiTestCase {
  36. // create a workbook, validate and write back
  37. void testSS(SlideShow ppt) throws Exception {
  38. Slide<?, ?> slide = ppt.createSlide();
  39. TextBox<?, ?> box1 = slide.createTextBox();
  40. box1.setTextPlaceholder(TextShape.TextPlaceholder.TITLE);
  41. box1.setText("HSLF in a Nutshell");
  42. box1.setAnchor(new Rectangle(36, 15, 648, 65));
  43. TextBox<?, ?> box2 = slide.createTextBox();
  44. box2.setTextPlaceholder(TextShape.TextPlaceholder.BODY);
  45. box2.setText(
  46. "HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
  47. "Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
  48. "Comprehensive support of PowerPoint objects\r" +
  49. "Rich text\r" +
  50. "Tables\r" +
  51. "Shapes\r" +
  52. "Pictures\r" +
  53. "Master slides\r" +
  54. "Access to low level data structures"
  55. );
  56. List<? extends TextParagraph<?, ?, ?>> tp = box2.getTextParagraphs();
  57. for (int i : new byte[]{0, 1, 2, 8}) {
  58. tp.get(i).getTextRuns().get(0).setFontSize(28d);
  59. }
  60. for (int i : new byte[]{3, 4, 5, 6, 7}) {
  61. tp.get(i).getTextRuns().get(0).setFontSize(24d);
  62. tp.get(i).setIndentLevel(1);
  63. }
  64. box2.setAnchor(new Rectangle(36, 80, 648, 400));
  65. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  66. ppt.write(baos);
  67. ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  68. ppt = SlideShowFactory.create(bais);
  69. assertEquals(1, ppt.getSlides().size());
  70. slide = (Slide) ppt.getSlides().iterator().next();
  71. assertEquals(2, slide.getShapes().size());
  72. }
  73. @Test
  74. public void testHSLF() throws Exception {
  75. testSS(new HSLFSlideShow());
  76. }
  77. @Test
  78. public void testXSLF() throws Exception {
  79. testSS(new XMLSlideShow());
  80. }
  81. }