-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.*;\r
-import org.apache.poi.hslf.model.*;\r
-import org.apache.poi.hslf.record.TextHeaderAtom;\r
-\r
-import java.io.IOException;\r
-import java.io.FileOutputStream;\r
-import java.io.File;\r
-import java.awt.*;\r
-\r
-/**\r
- * Presentation for Fast Feather Track on ApacheconEU 2008\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class ApacheconEU08 {\r
-\r
- public static void main(String[] args) throws IOException {\r
- SlideShow ppt = new SlideShow();\r
- ppt.setPageSize(new Dimension(720, 540));\r
-\r
- slide1(ppt);\r
- slide2(ppt);\r
- slide3(ppt);\r
- slide4(ppt);\r
- slide5(ppt);\r
- slide6(ppt);\r
- slide7(ppt);\r
- slide8(ppt);\r
- slide9(ppt);\r
- slide10(ppt);\r
- slide11(ppt);\r
- slide12(ppt);\r
-\r
- FileOutputStream out = new FileOutputStream("apachecon_eu_08.ppt");\r
- ppt.write(out);\r
- out.close();\r
-\r
- }\r
-\r
- public static void slide1(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);\r
- tr1.setText("POI-HSLF");\r
- box1.setAnchor(new Rectangle(54, 78, 612, 115));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);\r
- tr2.setText("Java API To Access Microsoft PowerPoint Format Files");\r
- box2.setAnchor(new Rectangle(108, 204, 504, 138));\r
- slide.addShape(box2);\r
-\r
- TextBox box3 = new TextBox();\r
- TextRun tr3 = box3.getTextRun();\r
- tr3.getRichTextRuns()[0].setFontSize(32);\r
- box3.setHorizontalAlignment(TextBox.AlignCenter);\r
- tr3.setText(\r
- "Yegor Kozlov\r" +\r
- "yegor - apache - org");\r
- box3.setAnchor(new Rectangle(206, 348, 310, 84));\r
- slide.addShape(box3);\r
- }\r
-\r
- public static void slide2(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("What is HSLF?");\r
- box1.setAnchor(new Rectangle(36, 21, 648, 90));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +\r
- "of the Powerpoint binary file format. \r" +\r
- "POI sub-project since 2005\r" +\r
- "Started by Nick Birch, Yegor Kozlov joined soon after");\r
- box2.setAnchor(new Rectangle(36, 126, 648, 356));\r
- slide.addShape(box2);\r
-\r
-\r
- }\r
-\r
- public static void slide3(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("HSLF in a Nutshell");\r
- box1.setAnchor(new Rectangle(36, 15, 648, 65));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr2.setText(\r
- "HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +\r
- "Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +\r
- "Comprehensive support of PowerPoint objects");\r
- tr2.getRichTextRuns()[0].setFontSize(28);\r
- box2.setAnchor(new Rectangle(36, 80, 648, 200));\r
- slide.addShape(box2);\r
-\r
- TextBox box3 = new TextBox();\r
- TextRun tr3 = box3.getTextRun();\r
- tr3.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr3.setText(\r
- "Rich text\r" +\r
- "Tables\r" +\r
- "Shapes\r" +\r
- "Pictures\r" +\r
- "Master slides");\r
- tr3.getRichTextRuns()[0].setFontSize(24);\r
- tr3.getRichTextRuns()[0].setIndentLevel(1);\r
- box3.setAnchor(new Rectangle(36, 265, 648, 150));\r
- slide.addShape(box3);\r
-\r
- TextBox box4 = new TextBox();\r
- TextRun tr4 = box4.getTextRun();\r
- tr4.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr4.setText("Access to low level data structures");\r
- box4.setAnchor(new Rectangle(36, 430, 648, 50));\r
- slide.addShape(box4);\r
- }\r
-\r
- public static void slide4(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- String[][] txt1 = {\r
- {"Note"},\r
- {"This presentation was created programmatically using POI HSLF"}\r
- };\r
- Table table1 = new Table(2, 1);\r
- for (int i = 0; i < txt1.length; i++) {\r
- for (int j = 0; j < txt1[i].length; j++) {\r
- TableCell cell = table1.getCell(i, j);\r
- cell.setText(txt1[i][j]);\r
- cell.getTextRun().getRichTextRuns()[0].setFontSize(10);\r
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];\r
- rt.setFontName("Arial");\r
- rt.setBold(true);\r
- if(i == 0){\r
- rt.setFontSize(32);\r
- rt.setFontColor(Color.white);\r
- cell.getFill().setForegroundColor(new Color(0, 153, 204));\r
- } else {\r
- rt.setFontSize(28);\r
- cell.getFill().setForegroundColor(new Color(235, 239, 241));\r
- }\r
- cell.setVerticalAlignment(TextBox.AnchorMiddle);\r
- }\r
- }\r
-\r
- Line border1 = table1.createBorder();\r
- border1.setLineColor(Color.black);\r
- border1.setLineWidth(1.0);\r
- table1.setAllBorders(border1);\r
-\r
- Line border2 = table1.createBorder();\r
- border2.setLineColor(Color.black);\r
- border2.setLineWidth(2.0);\r
- table1.setOutsideBorders(border2);\r
-\r
- table1.setColumnWidth(0, 510);\r
- table1.setRowHeight(0, 60);\r
- table1.setRowHeight(1, 100);\r
- slide.addShape(table1);\r
-\r
- table1.moveTo(100, 100);\r
-\r
- TextBox box1 = new TextBox();\r
- box1.setHorizontalAlignment(TextBox.AlignCenter);\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setText("The source code is available at\r" +\r
- "http://people.apache.org/~yegor/apachecon_eu08/");\r
- RichTextRun rt = tr1.getRichTextRuns()[0];\r
- rt.setFontSize(24);\r
- box1.setAnchor(new Rectangle(80, 356, 553, 65));\r
- slide.addShape(box1);\r
-\r
- }\r
-\r
- public static void slide5(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("HSLF in Action - 1\rData Extraction");\r
- box1.setAnchor(new Rectangle(36, 21, 648, 100));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr2.setText(\r
- "Text from slides and notes\r" +\r
- "Images\r" +\r
- "Shapes and their properties (type, position in the slide, color, font, etc.)");\r
- box2.setAnchor(new Rectangle(36, 150, 648, 300));\r
- slide.addShape(box2);\r
-\r
-\r
- }\r
-\r
- public static void slide6(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("HSLF in Action - 2");\r
- box1.setAnchor(new Rectangle(36, 20, 648, 90));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.getRichTextRuns()[0].setFontSize(18);\r
- tr2.setText("Creating a simple presentation from scratch");\r
- box2.setAnchor(new Rectangle(170, 100, 364, 30));\r
- slide.addShape(box2);\r
-\r
- TextBox box3 = new TextBox();\r
- TextRun tr3 = box3.getTextRun();\r
- RichTextRun rt3 = tr3.getRichTextRuns()[0];\r
- rt3.setFontName("Courier New");\r
- rt3.setFontSize(8);\r
- tr3.setText(\r
- " SlideShow ppt = new SlideShow();\r" +\r
- " Slide slide = ppt.createSlide();\r" +\r
- "\r" +\r
- " TextBox box2 = new TextBox();\r" +\r
- " box2.setHorizontalAlignment(TextBox.AlignCenter);\r" +\r
- " box2.setVerticalAlignment(TextBox.AnchorMiddle);\r" +\r
- " box2.getTextRun().setText(\"Java Code\");\r" +\r
- " box2.getFill().setForegroundColor(new Color(187, 224, 227));\r" +\r
- " box2.setLineColor(Color.black);\r" +\r
- " box2.setLineWidth(0.75);\r" +\r
- " box2.setAnchor(new Rectangle(66, 243, 170, 170));\r" +\r
- " slide.addShape(box2);\r" +\r
- "\r" +\r
- " TextBox box3 = new TextBox();\r" +\r
- " box3.setHorizontalAlignment(TextBox.AlignCenter);\r" +\r
- " box3.setVerticalAlignment(TextBox.AnchorMiddle);\r" +\r
- " box3.getTextRun().setText(\"*.ppt file\");\r" +\r
- " box3.setLineWidth(0.75);\r" +\r
- " box3.setLineColor(Color.black);\r" +\r
- " box3.getFill().setForegroundColor(new Color(187, 224, 227));\r" +\r
- " box3.setAnchor(new Rectangle(473, 243, 170, 170));\r" +\r
- " slide.addShape(box3);\r" +\r
- "\r" +\r
- " AutoShape box4 = new AutoShape(ShapeTypes.Arrow);\r" +\r
- " box4.getFill().setForegroundColor(new Color(187, 224, 227));\r" +\r
- " box4.setLineWidth(0.75);\r" +\r
- " box4.setLineColor(Color.black);\r" +\r
- " box4.setAnchor(new Rectangle(253, 288, 198, 85));\r" +\r
- " slide.addShape(box4);\r" +\r
- "\r" +\r
- " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +\r
- " ppt.write(out);\r" +\r
- " out.close();");\r
- box3.setAnchor(new Rectangle(30, 150, 618, 411));\r
- slide.addShape(box3);\r
- }\r
-\r
- public static void slide7(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box2 = new TextBox();\r
- box2.setHorizontalAlignment(TextBox.AlignCenter);\r
- box2.setVerticalAlignment(TextBox.AnchorMiddle);\r
- box2.getTextRun().setText("Java Code");\r
- box2.getFill().setForegroundColor(new Color(187, 224, 227));\r
- box2.setLineColor(Color.black);\r
- box2.setLineWidth(0.75);\r
- box2.setAnchor(new Rectangle(66, 243, 170, 170));\r
- slide.addShape(box2);\r
-\r
- TextBox box3 = new TextBox();\r
- box3.setHorizontalAlignment(TextBox.AlignCenter);\r
- box3.setVerticalAlignment(TextBox.AnchorMiddle);\r
- box3.getTextRun().setText("*.ppt file");\r
- box3.setLineWidth(0.75);\r
- box3.setLineColor(Color.black);\r
- box3.getFill().setForegroundColor(new Color(187, 224, 227));\r
- box3.setAnchor(new Rectangle(473, 243, 170, 170));\r
- slide.addShape(box3);\r
-\r
- AutoShape box4 = new AutoShape(ShapeTypes.Arrow);\r
- box4.getFill().setForegroundColor(new Color(187, 224, 227));\r
- box4.setLineWidth(0.75);\r
- box4.setLineColor(Color.black);\r
- box4.setAnchor(new Rectangle(253, 288, 198, 85));\r
- slide.addShape(box4);\r
- }\r
-\r
- public static void slide8(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("Wait, there is more!");\r
- box1.setAnchor(new Rectangle(36, 21, 648, 90));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr2.setText(\r
- "Rich text\r" +\r
- "Tables\r" +\r
- "Pictures (JPEG, PNG, BMP, WMF, PICT)\r" +\r
- "Comprehensive formatting features");\r
- box2.setAnchor(new Rectangle(36, 126, 648, 356));\r
- slide.addShape(box2);\r
- }\r
-\r
- public static void slide9(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("HSLF in Action - 3");\r
- box1.setAnchor(new Rectangle(36, 20, 648, 50));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.getRichTextRuns()[0].setFontSize(18);\r
- tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");\r
- box2.setAnchor(new Rectangle(178, 70, 387, 30));\r
- slide.addShape(box2);\r
-\r
- TextBox box3 = new TextBox();\r
- TextRun tr3 = box3.getTextRun();\r
- RichTextRun rt3 = tr3.getRichTextRuns()[0];\r
- rt3.setFontName("Courier New");\r
- rt3.setFontSize(8);\r
- tr3.setText(\r
- " //bar chart data. The first value is the bar color, the second is the width\r" +\r
- " Object[] def = new Object[]{\r" +\r
- " Color.yellow, new Integer(100),\r" +\r
- " Color.green, new Integer(150),\r" +\r
- " Color.gray, new Integer(75),\r" +\r
- " Color.red, new Integer(200),\r" +\r
- " };\r" +\r
- "\r" +\r
- " SlideShow ppt = new SlideShow();\r" +\r
- " Slide slide = ppt.createSlide();\r" +\r
- "\r" +\r
- " ShapeGroup group = new ShapeGroup();\r" +\r
- " //define position of the drawing in the slide\r" +\r
- " Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);\r" +\r
- " group.setAnchor(bounds);\r" +\r
- " slide.addShape(group);\r" +\r
- " Graphics2D graphics = new PPGraphics2D(group);\r" +\r
- "\r" +\r
- " //draw a simple bar graph\r" +\r
- " int x = bounds.x + 50, y = bounds.y + 50;\r" +\r
- " graphics.setFont(new Font(\"Arial\", Font.BOLD, 10));\r" +\r
- " for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {\r" +\r
- " graphics.setColor(Color.black);\r" +\r
- " int width = ((Integer)def[i+1]).intValue();\r" +\r
- " graphics.drawString(\"Q\" + idx, x-20, y+20);\r" +\r
- " graphics.drawString(width + \"%\", x + width + 10, y + 20);\r" +\r
- " graphics.setColor((Color)def[i]);\r" +\r
- " graphics.fill(new Rectangle(x, y, width, 30));\r" +\r
- " y += 40;\r" +\r
- " }\r" +\r
- " graphics.setColor(Color.black);\r" +\r
- " graphics.setFont(new Font(\"Arial\", Font.BOLD, 14));\r" +\r
- " graphics.draw(bounds);\r" +\r
- " graphics.drawString(\"Performance\", x + 70, y + 40);\r" +\r
- "\r" +\r
- " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +\r
- " ppt.write(out);\r" +\r
- " out.close();");\r
- box3.setAnchor(new Rectangle(96, 110, 499, 378));\r
- slide.addShape(box3);\r
- }\r
-\r
- public static void slide10(SlideShow ppt) throws IOException {\r
- //bar chart data. The first value is the bar color, the second is the width\r
- Object[] def = new Object[]{\r
- Color.yellow, new Integer(100),\r
- Color.green, new Integer(150),\r
- Color.gray, new Integer(75),\r
- Color.red, new Integer(200),\r
- };\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- ShapeGroup group = new ShapeGroup();\r
- //define position of the drawing in the slide\r
- Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);\r
- group.setAnchor(bounds);\r
- slide.addShape(group);\r
- Graphics2D graphics = new PPGraphics2D(group);\r
-\r
- //draw a simple bar graph\r
- int x = bounds.x + 50, y = bounds.y + 50;\r
- graphics.setFont(new Font("Arial", Font.BOLD, 10));\r
- for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {\r
- graphics.setColor(Color.black);\r
- int width = ((Integer)def[i+1]).intValue();\r
- graphics.drawString("Q" + idx, x-20, y+20);\r
- graphics.drawString(width + "%", x + width + 10, y + 20);\r
- graphics.setColor((Color)def[i]);\r
- graphics.fill(new Rectangle(x, y, width, 30));\r
- y += 40;\r
- }\r
- graphics.setColor(Color.black);\r
- graphics.setFont(new Font("Arial", Font.BOLD, 14));\r
- graphics.draw(bounds);\r
- graphics.drawString("Performance", x + 70, y + 40);\r
-\r
- }\r
-\r
- public static void slide11(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);\r
- tr1.setText("HSLF Development Plans");\r
- box1.setAnchor(new Rectangle(36, 21, 648, 90));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr2.getRichTextRuns()[0].setFontSize(32);\r
- tr2.setText(\r
- "Support for more PowerPoint functionality\r" +\r
- "Rendering slides into java.awt.Graphics2D");\r
- box2.setAnchor(new Rectangle(36, 126, 648, 100));\r
- slide.addShape(box2);\r
-\r
- TextBox box3 = new TextBox();\r
- TextRun tr3 = box3.getTextRun();\r
- tr3.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr3.getRichTextRuns()[0].setIndentLevel(1);\r
- tr3.setText(\r
- "A way to export slides into images or other formats");\r
- box3.setAnchor(new Rectangle(36, 220, 648, 70));\r
- slide.addShape(box3);\r
-\r
- TextBox box4 = new TextBox();\r
- TextRun tr4 = box4.getTextRun();\r
- tr4.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr4.getRichTextRuns()[0].setFontSize(32);\r
- tr4.setText(\r
- "Integration with Apache FOP - Formatting Objects Processor");\r
- box4.setAnchor(new Rectangle(36, 290, 648, 90));\r
- slide.addShape(box4);\r
-\r
- TextBox box5 = new TextBox();\r
- TextRun tr5 = box5.getTextRun();\r
- tr5.setRunType(TextHeaderAtom.BODY_TYPE);\r
- tr5.getRichTextRuns()[0].setIndentLevel(1);\r
- tr5.setText(\r
- "Transformation of XSL-FO into PPT\r" +\r
- "PPT2PDF transcoder");\r
- box5.setAnchor(new Rectangle(36, 380, 648, 100));\r
- slide.addShape(box5);\r
- }\r
-\r
- public static void slide12(SlideShow ppt) throws IOException {\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox box1 = new TextBox();\r
- TextRun tr1 = box1.getTextRun();\r
- tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);\r
- tr1.setText("Questions?");\r
- box1.setAnchor(new Rectangle(54, 167, 612, 115));\r
- slide.addShape(box1);\r
-\r
- TextBox box2 = new TextBox();\r
- TextRun tr2 = box2.getTextRun();\r
- tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);\r
- tr2.setText(\r
- "http://poi.apache.org/hslf/\r" +\r
- "http://people.apache.org/~yegor");\r
- box2.setAnchor(new Rectangle(108, 306, 504, 138));\r
- slide.addShape(box2);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.awt.*;
+
+/**
+ * Presentation for Fast Feather Track on ApacheconEU 2008
+ *
+ * @author Yegor Kozlov
+ */
+public final class ApacheconEU08 {
+
+ public static void main(String[] args) throws IOException {
+ SlideShow ppt = new SlideShow();
+ ppt.setPageSize(new Dimension(720, 540));
+
+ slide1(ppt);
+ slide2(ppt);
+ slide3(ppt);
+ slide4(ppt);
+ slide5(ppt);
+ slide6(ppt);
+ slide7(ppt);
+ slide8(ppt);
+ slide9(ppt);
+ slide10(ppt);
+ slide11(ppt);
+ slide12(ppt);
+
+ FileOutputStream out = new FileOutputStream("apachecon_eu_08.ppt");
+ ppt.write(out);
+ out.close();
+
+ }
+
+ public static void slide1(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
+ tr1.setText("POI-HSLF");
+ box1.setAnchor(new Rectangle(54, 78, 612, 115));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
+ tr2.setText("Java API To Access Microsoft PowerPoint Format Files");
+ box2.setAnchor(new Rectangle(108, 204, 504, 138));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ tr3.getRichTextRuns()[0].setFontSize(32);
+ box3.setHorizontalAlignment(TextBox.AlignCenter);
+ tr3.setText(
+ "Yegor Kozlov\r" +
+ "yegor - apache - org");
+ box3.setAnchor(new Rectangle(206, 348, 310, 84));
+ slide.addShape(box3);
+ }
+
+ public static void slide2(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("What is HSLF?");
+ box1.setAnchor(new Rectangle(36, 21, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
+ "of the Powerpoint binary file format. \r" +
+ "POI sub-project since 2005\r" +
+ "Started by Nick Birch, Yegor Kozlov joined soon after");
+ box2.setAnchor(new Rectangle(36, 126, 648, 356));
+ slide.addShape(box2);
+
+
+ }
+
+ public static void slide3(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in a Nutshell");
+ box1.setAnchor(new Rectangle(36, 15, 648, 65));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText(
+ "HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
+ "Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
+ "Comprehensive support of PowerPoint objects");
+ tr2.getRichTextRuns()[0].setFontSize(28);
+ box2.setAnchor(new Rectangle(36, 80, 648, 200));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ tr3.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr3.setText(
+ "Rich text\r" +
+ "Tables\r" +
+ "Shapes\r" +
+ "Pictures\r" +
+ "Master slides");
+ tr3.getRichTextRuns()[0].setFontSize(24);
+ tr3.getRichTextRuns()[0].setIndentLevel(1);
+ box3.setAnchor(new Rectangle(36, 265, 648, 150));
+ slide.addShape(box3);
+
+ TextBox box4 = new TextBox();
+ TextRun tr4 = box4.getTextRun();
+ tr4.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr4.setText("Access to low level data structures");
+ box4.setAnchor(new Rectangle(36, 430, 648, 50));
+ slide.addShape(box4);
+ }
+
+ public static void slide4(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ String[][] txt1 = {
+ {"Note"},
+ {"This presentation was created programmatically using POI HSLF"}
+ };
+ Table table1 = new Table(2, 1);
+ for (int i = 0; i < txt1.length; i++) {
+ for (int j = 0; j < txt1[i].length; j++) {
+ TableCell cell = table1.getCell(i, j);
+ cell.setText(txt1[i][j]);
+ cell.getTextRun().getRichTextRuns()[0].setFontSize(10);
+ RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
+ rt.setFontName("Arial");
+ rt.setBold(true);
+ if(i == 0){
+ rt.setFontSize(32);
+ rt.setFontColor(Color.white);
+ cell.getFill().setForegroundColor(new Color(0, 153, 204));
+ } else {
+ rt.setFontSize(28);
+ cell.getFill().setForegroundColor(new Color(235, 239, 241));
+ }
+ cell.setVerticalAlignment(TextBox.AnchorMiddle);
+ }
+ }
+
+ Line border1 = table1.createBorder();
+ border1.setLineColor(Color.black);
+ border1.setLineWidth(1.0);
+ table1.setAllBorders(border1);
+
+ Line border2 = table1.createBorder();
+ border2.setLineColor(Color.black);
+ border2.setLineWidth(2.0);
+ table1.setOutsideBorders(border2);
+
+ table1.setColumnWidth(0, 510);
+ table1.setRowHeight(0, 60);
+ table1.setRowHeight(1, 100);
+ slide.addShape(table1);
+
+ table1.moveTo(100, 100);
+
+ TextBox box1 = new TextBox();
+ box1.setHorizontalAlignment(TextBox.AlignCenter);
+ TextRun tr1 = box1.getTextRun();
+ tr1.setText("The source code is available at\r" +
+ "http://people.apache.org/~yegor/apachecon_eu08/");
+ RichTextRun rt = tr1.getRichTextRuns()[0];
+ rt.setFontSize(24);
+ box1.setAnchor(new Rectangle(80, 356, 553, 65));
+ slide.addShape(box1);
+
+ }
+
+ public static void slide5(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in Action - 1\rData Extraction");
+ box1.setAnchor(new Rectangle(36, 21, 648, 100));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText(
+ "Text from slides and notes\r" +
+ "Images\r" +
+ "Shapes and their properties (type, position in the slide, color, font, etc.)");
+ box2.setAnchor(new Rectangle(36, 150, 648, 300));
+ slide.addShape(box2);
+
+
+ }
+
+ public static void slide6(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in Action - 2");
+ box1.setAnchor(new Rectangle(36, 20, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.getRichTextRuns()[0].setFontSize(18);
+ tr2.setText("Creating a simple presentation from scratch");
+ box2.setAnchor(new Rectangle(170, 100, 364, 30));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ RichTextRun rt3 = tr3.getRichTextRuns()[0];
+ rt3.setFontName("Courier New");
+ rt3.setFontSize(8);
+ tr3.setText(
+ " SlideShow ppt = new SlideShow();\r" +
+ " Slide slide = ppt.createSlide();\r" +
+ "\r" +
+ " TextBox box2 = new TextBox();\r" +
+ " box2.setHorizontalAlignment(TextBox.AlignCenter);\r" +
+ " box2.setVerticalAlignment(TextBox.AnchorMiddle);\r" +
+ " box2.getTextRun().setText(\"Java Code\");\r" +
+ " box2.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
+ " box2.setLineColor(Color.black);\r" +
+ " box2.setLineWidth(0.75);\r" +
+ " box2.setAnchor(new Rectangle(66, 243, 170, 170));\r" +
+ " slide.addShape(box2);\r" +
+ "\r" +
+ " TextBox box3 = new TextBox();\r" +
+ " box3.setHorizontalAlignment(TextBox.AlignCenter);\r" +
+ " box3.setVerticalAlignment(TextBox.AnchorMiddle);\r" +
+ " box3.getTextRun().setText(\"*.ppt file\");\r" +
+ " box3.setLineWidth(0.75);\r" +
+ " box3.setLineColor(Color.black);\r" +
+ " box3.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
+ " box3.setAnchor(new Rectangle(473, 243, 170, 170));\r" +
+ " slide.addShape(box3);\r" +
+ "\r" +
+ " AutoShape box4 = new AutoShape(ShapeTypes.Arrow);\r" +
+ " box4.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
+ " box4.setLineWidth(0.75);\r" +
+ " box4.setLineColor(Color.black);\r" +
+ " box4.setAnchor(new Rectangle(253, 288, 198, 85));\r" +
+ " slide.addShape(box4);\r" +
+ "\r" +
+ " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +
+ " ppt.write(out);\r" +
+ " out.close();");
+ box3.setAnchor(new Rectangle(30, 150, 618, 411));
+ slide.addShape(box3);
+ }
+
+ public static void slide7(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box2 = new TextBox();
+ box2.setHorizontalAlignment(TextBox.AlignCenter);
+ box2.setVerticalAlignment(TextBox.AnchorMiddle);
+ box2.getTextRun().setText("Java Code");
+ box2.getFill().setForegroundColor(new Color(187, 224, 227));
+ box2.setLineColor(Color.black);
+ box2.setLineWidth(0.75);
+ box2.setAnchor(new Rectangle(66, 243, 170, 170));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ box3.setHorizontalAlignment(TextBox.AlignCenter);
+ box3.setVerticalAlignment(TextBox.AnchorMiddle);
+ box3.getTextRun().setText("*.ppt file");
+ box3.setLineWidth(0.75);
+ box3.setLineColor(Color.black);
+ box3.getFill().setForegroundColor(new Color(187, 224, 227));
+ box3.setAnchor(new Rectangle(473, 243, 170, 170));
+ slide.addShape(box3);
+
+ AutoShape box4 = new AutoShape(ShapeTypes.Arrow);
+ box4.getFill().setForegroundColor(new Color(187, 224, 227));
+ box4.setLineWidth(0.75);
+ box4.setLineColor(Color.black);
+ box4.setAnchor(new Rectangle(253, 288, 198, 85));
+ slide.addShape(box4);
+ }
+
+ public static void slide8(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("Wait, there is more!");
+ box1.setAnchor(new Rectangle(36, 21, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText(
+ "Rich text\r" +
+ "Tables\r" +
+ "Pictures (JPEG, PNG, BMP, WMF, PICT)\r" +
+ "Comprehensive formatting features");
+ box2.setAnchor(new Rectangle(36, 126, 648, 356));
+ slide.addShape(box2);
+ }
+
+ public static void slide9(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in Action - 3");
+ box1.setAnchor(new Rectangle(36, 20, 648, 50));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.getRichTextRuns()[0].setFontSize(18);
+ tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
+ box2.setAnchor(new Rectangle(178, 70, 387, 30));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ RichTextRun rt3 = tr3.getRichTextRuns()[0];
+ rt3.setFontName("Courier New");
+ rt3.setFontSize(8);
+ tr3.setText(
+ " //bar chart data. The first value is the bar color, the second is the width\r" +
+ " Object[] def = new Object[]{\r" +
+ " Color.yellow, new Integer(100),\r" +
+ " Color.green, new Integer(150),\r" +
+ " Color.gray, new Integer(75),\r" +
+ " Color.red, new Integer(200),\r" +
+ " };\r" +
+ "\r" +
+ " SlideShow ppt = new SlideShow();\r" +
+ " Slide slide = ppt.createSlide();\r" +
+ "\r" +
+ " ShapeGroup group = new ShapeGroup();\r" +
+ " //define position of the drawing in the slide\r" +
+ " Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);\r" +
+ " group.setAnchor(bounds);\r" +
+ " slide.addShape(group);\r" +
+ " Graphics2D graphics = new PPGraphics2D(group);\r" +
+ "\r" +
+ " //draw a simple bar graph\r" +
+ " int x = bounds.x + 50, y = bounds.y + 50;\r" +
+ " graphics.setFont(new Font(\"Arial\", Font.BOLD, 10));\r" +
+ " for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {\r" +
+ " graphics.setColor(Color.black);\r" +
+ " int width = ((Integer)def[i+1]).intValue();\r" +
+ " graphics.drawString(\"Q\" + idx, x-20, y+20);\r" +
+ " graphics.drawString(width + \"%\", x + width + 10, y + 20);\r" +
+ " graphics.setColor((Color)def[i]);\r" +
+ " graphics.fill(new Rectangle(x, y, width, 30));\r" +
+ " y += 40;\r" +
+ " }\r" +
+ " graphics.setColor(Color.black);\r" +
+ " graphics.setFont(new Font(\"Arial\", Font.BOLD, 14));\r" +
+ " graphics.draw(bounds);\r" +
+ " graphics.drawString(\"Performance\", x + 70, y + 40);\r" +
+ "\r" +
+ " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +
+ " ppt.write(out);\r" +
+ " out.close();");
+ box3.setAnchor(new Rectangle(96, 110, 499, 378));
+ slide.addShape(box3);
+ }
+
+ public static void slide10(SlideShow ppt) throws IOException {
+ //bar chart data. The first value is the bar color, the second is the width
+ Object[] def = new Object[]{
+ Color.yellow, new Integer(100),
+ Color.green, new Integer(150),
+ Color.gray, new Integer(75),
+ Color.red, new Integer(200),
+ };
+
+ Slide slide = ppt.createSlide();
+
+ ShapeGroup group = new ShapeGroup();
+ //define position of the drawing in the slide
+ Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
+ group.setAnchor(bounds);
+ slide.addShape(group);
+ Graphics2D graphics = new PPGraphics2D(group);
+
+ //draw a simple bar graph
+ int x = bounds.x + 50, y = bounds.y + 50;
+ graphics.setFont(new Font("Arial", Font.BOLD, 10));
+ for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
+ graphics.setColor(Color.black);
+ int width = ((Integer)def[i+1]).intValue();
+ graphics.drawString("Q" + idx, x-20, y+20);
+ graphics.drawString(width + "%", x + width + 10, y + 20);
+ graphics.setColor((Color)def[i]);
+ graphics.fill(new Rectangle(x, y, width, 30));
+ y += 40;
+ }
+ graphics.setColor(Color.black);
+ graphics.setFont(new Font("Arial", Font.BOLD, 14));
+ graphics.draw(bounds);
+ graphics.drawString("Performance", x + 70, y + 40);
+
+ }
+
+ public static void slide11(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF Development Plans");
+ box1.setAnchor(new Rectangle(36, 21, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.getRichTextRuns()[0].setFontSize(32);
+ tr2.setText(
+ "Support for more PowerPoint functionality\r" +
+ "Rendering slides into java.awt.Graphics2D");
+ box2.setAnchor(new Rectangle(36, 126, 648, 100));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ tr3.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr3.getRichTextRuns()[0].setIndentLevel(1);
+ tr3.setText(
+ "A way to export slides into images or other formats");
+ box3.setAnchor(new Rectangle(36, 220, 648, 70));
+ slide.addShape(box3);
+
+ TextBox box4 = new TextBox();
+ TextRun tr4 = box4.getTextRun();
+ tr4.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr4.getRichTextRuns()[0].setFontSize(32);
+ tr4.setText(
+ "Integration with Apache FOP - Formatting Objects Processor");
+ box4.setAnchor(new Rectangle(36, 290, 648, 90));
+ slide.addShape(box4);
+
+ TextBox box5 = new TextBox();
+ TextRun tr5 = box5.getTextRun();
+ tr5.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr5.getRichTextRuns()[0].setIndentLevel(1);
+ tr5.setText(
+ "Transformation of XSL-FO into PPT\r" +
+ "PPT2PDF transcoder");
+ box5.setAnchor(new Rectangle(36, 380, 648, 100));
+ slide.addShape(box5);
+ }
+
+ public static void slide12(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
+ tr1.setText("Questions?");
+ box1.setAnchor(new Rectangle(54, 167, 612, 115));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
+ tr2.setText(
+ "http://poi.apache.org/hslf/\r" +
+ "http://people.apache.org/~yegor");
+ box2.setAnchor(new Rectangle(108, 306, 504, 138));
+ slide.addShape(box2);
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.RichTextRun;\r
-import org.apache.poi.hslf.model.Slide;\r
-import org.apache.poi.hslf.model.TextBox;\r
-\r
-import java.io.FileOutputStream;\r
-\r
-/**\r
- * How to create a single-level bulleted list\r
- * and change some of the bullet attributes\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class BulletsDemo {\r
-\r
- public static void main(String[] args) throws Exception {\r
-\r
- SlideShow ppt = new SlideShow();\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox shape = new TextBox();\r
- RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];\r
- shape.setText(\r
- "January\r" +\r
- "February\r" +\r
- "March\r" +\r
- "April");\r
- rt.setFontSize(42);\r
- rt.setBullet(true);\r
- rt.setBulletOffset(0); //bullet offset\r
- rt.setTextOffset(50); //text offset (should be greater than bullet offset)\r
- rt.setBulletChar('\u263A'); //bullet character\r
- slide.addShape(shape);\r
-\r
- shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide\r
- slide.addShape(shape);\r
-\r
- FileOutputStream out = new FileOutputStream("bullets.ppt");\r
- ppt.write(out);\r
- out.close();\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.model.Slide;
+import org.apache.poi.hslf.model.TextBox;
+
+import java.io.FileOutputStream;
+
+/**
+ * How to create a single-level bulleted list
+ * and change some of the bullet attributes
+ *
+ * @author Yegor Kozlov
+ */
+public final class BulletsDemo {
+
+ public static void main(String[] args) throws Exception {
+
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ TextBox shape = new TextBox();
+ RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];
+ shape.setText(
+ "January\r" +
+ "February\r" +
+ "March\r" +
+ "April");
+ rt.setFontSize(42);
+ rt.setBullet(true);
+ rt.setBulletOffset(0); //bullet offset
+ rt.setTextOffset(50); //text offset (should be greater than bullet offset)
+ rt.setBulletChar('\u263A'); //bullet character
+ slide.addShape(shape);
+
+ shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide
+ slide.addShape(shape);
+
+ FileOutputStream out = new FileOutputStream("bullets.ppt");
+ ppt.write(out);
+ out.close();
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.RichTextRun;\r
-import org.apache.poi.hslf.model.*;\r
-\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.awt.*;\r
-\r
-/**\r
- * Demonstrates how to create hyperlinks in PowerPoint presentations\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class CreateHyperlink {\r
-\r
- public static void main(String[] args) throws Exception {\r
- SlideShow ppt = new SlideShow();\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- TextBox shape = new TextBox();\r
- shape.setText("Apache POI");\r
- Rectangle anchor = new Rectangle(100, 100, 200, 50);\r
- shape.setAnchor(anchor);\r
-\r
- String text = shape.getText();\r
- Hyperlink link = new Hyperlink();\r
- link.setAddress("http://www.apache.org");\r
- link.setTitle(shape.getText());\r
- int linkId = ppt.addHyperlink(link);\r
-\r
- shape.setHyperlink(linkId, 0, text.length());\r
-\r
- slide.addShape(shape);\r
-\r
- FileOutputStream out = new FileOutputStream("hyperlink.ppt");\r
- ppt.write(out);\r
- out.close();\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.model.*;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.awt.*;
+
+/**
+ * Demonstrates how to create hyperlinks in PowerPoint presentations
+ *
+ * @author Yegor Kozlov
+ */
+public final class CreateHyperlink {
+
+ public static void main(String[] args) throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ TextBox shape = new TextBox();
+ shape.setText("Apache POI");
+ Rectangle anchor = new Rectangle(100, 100, 200, 50);
+ shape.setAnchor(anchor);
+
+ String text = shape.getText();
+ Hyperlink link = new Hyperlink();
+ link.setAddress("http://www.apache.org");
+ link.setTitle(shape.getText());
+ int linkId = ppt.addHyperlink(link);
+
+ shape.setHyperlink(linkId, 0, text.length());
+
+ slide.addShape(shape);
+
+ FileOutputStream out = new FileOutputStream("hyperlink.ppt");
+ ppt.write(out);
+ out.close();
+
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.*;\r
-import org.apache.poi.hslf.model.*;\r
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
-import org.apache.poi.hwpf.HWPFDocument;\r
-import org.apache.poi.hwpf.usermodel.Range;\r
-import org.apache.poi.hwpf.usermodel.Paragraph;\r
-\r
-import java.io.*;\r
-\r
-/**\r
- * Demonstrates how you can extract misc embedded data from a ppt file\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class DataExtraction {\r
-\r
- public static void main(String args[]) throws Exception {\r
-\r
- if (args.length == 0) {\r
- usage();\r
- return;\r
- }\r
-\r
- FileInputStream is = new FileInputStream(args[0]);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- //extract all sound files embedded in this presentation\r
- SoundData[] sound = ppt.getSoundData();\r
- for (int i = 0; i < sound.length; i++) {\r
- String type = sound[i].getSoundType(); //*.wav\r
- String name = sound[i].getSoundName(); //typically file name\r
- byte[] data = sound[i].getData(); //raw bytes\r
-\r
- //save the sound on disk\r
- FileOutputStream out = new FileOutputStream(name + type);\r
- out.write(data);\r
- out.close();\r
- }\r
-\r
- //extract embedded OLE documents\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- Shape[] shape = slide[i].getShapes();\r
- for (int j = 0; j < shape.length; j++) {\r
- if (shape[j] instanceof OLEShape) {\r
- OLEShape ole = (OLEShape) shape[j];\r
- ObjectData data = ole.getObjectData();\r
- String name = ole.getInstanceName();\r
- if ("Worksheet".equals(name)) {\r
-\r
- //read xls\r
- HSSFWorkbook wb = new HSSFWorkbook(data.getData());\r
-\r
- } else if ("Document".equals(name)) {\r
- HWPFDocument doc = new HWPFDocument(data.getData());\r
- //read the word document\r
- Range r = doc.getRange(); \r
- for(int k = 0; k < r.numParagraphs(); k++) {\r
- Paragraph p = r.getParagraph(k);\r
- System.out.println(p.text());\r
- }\r
-\r
- //save on disk\r
- FileOutputStream out = new FileOutputStream(name + "-("+(j)+").doc");\r
- doc.write(out);\r
- out.close();\r
- } else {\r
- FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat");\r
- InputStream dis = data.getData();\r
- byte[] chunk = new byte[2048];\r
- int count;\r
- while ((count = dis.read(chunk)) >= 0) {\r
- out.write(chunk,0,count);\r
- }\r
- is.close();\r
- out.close();\r
- }\r
- }\r
-\r
- }\r
- }\r
-\r
- //Pictures\r
- for (int i = 0; i < slide.length; i++) {\r
- Shape[] shape = slide[i].getShapes();\r
- for (int j = 0; j < shape.length; j++) {\r
- if (shape[j] instanceof Picture) {\r
- Picture p = (Picture) shape[j];\r
- PictureData data = p.getPictureData();\r
- String name = p.getPictureName();\r
- int type = data.getType();\r
- String ext;\r
- switch (type) {\r
- case Picture.JPEG:\r
- ext = ".jpg";\r
- break;\r
- case Picture.PNG:\r
- ext = ".png";\r
- break;\r
- case Picture.WMF:\r
- ext = ".wmf";\r
- break;\r
- case Picture.EMF:\r
- ext = ".emf";\r
- break;\r
- case Picture.PICT:\r
- ext = ".pict";\r
- break;\r
- case Picture.DIB:\r
- ext = ".dib";\r
- break;\r
- default:\r
- continue;\r
- }\r
- FileOutputStream out = new FileOutputStream("pict-" + j + ext);\r
- out.write(data.getData());\r
- out.close();\r
- }\r
-\r
- }\r
- }\r
-\r
- }\r
-\r
- private static void usage(){\r
- System.out.println("Usage: DataExtraction ppt");\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.usermodel.Range;
+import org.apache.poi.hwpf.usermodel.Paragraph;
+
+import java.io.*;
+
+/**
+ * Demonstrates how you can extract misc embedded data from a ppt file
+ *
+ * @author Yegor Kozlov
+ */
+public final class DataExtraction {
+
+ public static void main(String args[]) throws Exception {
+
+ if (args.length == 0) {
+ usage();
+ return;
+ }
+
+ FileInputStream is = new FileInputStream(args[0]);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ //extract all sound files embedded in this presentation
+ SoundData[] sound = ppt.getSoundData();
+ for (int i = 0; i < sound.length; i++) {
+ String type = sound[i].getSoundType(); //*.wav
+ String name = sound[i].getSoundName(); //typically file name
+ byte[] data = sound[i].getData(); //raw bytes
+
+ //save the sound on disk
+ FileOutputStream out = new FileOutputStream(name + type);
+ out.write(data);
+ out.close();
+ }
+
+ //extract embedded OLE documents
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ for (int j = 0; j < shape.length; j++) {
+ if (shape[j] instanceof OLEShape) {
+ OLEShape ole = (OLEShape) shape[j];
+ ObjectData data = ole.getObjectData();
+ String name = ole.getInstanceName();
+ if ("Worksheet".equals(name)) {
+
+ //read xls
+ HSSFWorkbook wb = new HSSFWorkbook(data.getData());
+
+ } else if ("Document".equals(name)) {
+ HWPFDocument doc = new HWPFDocument(data.getData());
+ //read the word document
+ Range r = doc.getRange();
+ for(int k = 0; k < r.numParagraphs(); k++) {
+ Paragraph p = r.getParagraph(k);
+ System.out.println(p.text());
+ }
+
+ //save on disk
+ FileOutputStream out = new FileOutputStream(name + "-("+(j)+").doc");
+ doc.write(out);
+ out.close();
+ } else {
+ FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat");
+ InputStream dis = data.getData();
+ byte[] chunk = new byte[2048];
+ int count;
+ while ((count = dis.read(chunk)) >= 0) {
+ out.write(chunk,0,count);
+ }
+ is.close();
+ out.close();
+ }
+ }
+
+ }
+ }
+
+ //Pictures
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ for (int j = 0; j < shape.length; j++) {
+ if (shape[j] instanceof Picture) {
+ Picture p = (Picture) shape[j];
+ PictureData data = p.getPictureData();
+ String name = p.getPictureName();
+ int type = data.getType();
+ String ext;
+ switch (type) {
+ case Picture.JPEG:
+ ext = ".jpg";
+ break;
+ case Picture.PNG:
+ ext = ".png";
+ break;
+ case Picture.WMF:
+ ext = ".wmf";
+ break;
+ case Picture.EMF:
+ ext = ".emf";
+ break;
+ case Picture.PICT:
+ ext = ".pict";
+ break;
+ case Picture.DIB:
+ ext = ".dib";
+ break;
+ default:
+ continue;
+ }
+ FileOutputStream out = new FileOutputStream("pict-" + j + ext);
+ out.write(data.getData());
+ out.close();
+ }
+
+ }
+ }
+
+ }
+
+ private static void usage(){
+ System.out.println("Usage: DataExtraction ppt");
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.model.*;\r
-\r
-import java.awt.*;\r
-import java.io.FileOutputStream;\r
-import java.io.FileInputStream;\r
-\r
-/**\r
- * Demonstrates how to draw into a slide using the HSLF Graphics2D driver.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class Graphics2DDemo {\r
-\r
- /**\r
- * A simple bar chart demo\r
- */\r
- public static void main(String[] args) throws Exception {\r
- SlideShow ppt = new SlideShow();\r
-\r
- //bar chart data. The first value is the bar color, the second is the width\r
- Object[] def = new Object[]{\r
- Color.yellow, new Integer(40),\r
- Color.green, new Integer(60),\r
- Color.gray, new Integer(30),\r
- Color.red, new Integer(80),\r
- };\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- ShapeGroup group = new ShapeGroup();\r
- //define position of the drawing in the slide\r
- Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);\r
- group.setAnchor(bounds);\r
- group.setCoordinates(new java.awt.Rectangle(0, 0, 100, 100));\r
- slide.addShape(group);\r
- Graphics2D graphics = new PPGraphics2D(group);\r
-\r
- //draw a simple bar graph\r
- int x = 10, y = 10;\r
- graphics.setFont(new Font("Arial", Font.BOLD, 10));\r
- for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {\r
- graphics.setColor(Color.black);\r
- int width = ((Integer)def[i+1]).intValue();\r
- graphics.drawString("Q" + idx, x-5, y+10);\r
- graphics.drawString(width + "%", x + width+3, y + 10);\r
- graphics.setColor((Color)def[i]);\r
- graphics.fill(new Rectangle(x, y, width, 10));\r
- y += 15;\r
- }\r
- graphics.setColor(Color.black);\r
- graphics.setFont(new Font("Arial", Font.BOLD, 14));\r
- graphics.draw(group.getCoordinates());\r
- graphics.drawString("Performance", x + 30, y + 10);\r
-\r
- FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");\r
- ppt.write(out);\r
- out.close();\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.*;
+
+import java.awt.*;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+
+/**
+ * Demonstrates how to draw into a slide using the HSLF Graphics2D driver.
+ *
+ * @author Yegor Kozlov
+ */
+public final class Graphics2DDemo {
+
+ /**
+ * A simple bar chart demo
+ */
+ public static void main(String[] args) throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ //bar chart data. The first value is the bar color, the second is the width
+ Object[] def = new Object[]{
+ Color.yellow, new Integer(40),
+ Color.green, new Integer(60),
+ Color.gray, new Integer(30),
+ Color.red, new Integer(80),
+ };
+
+ Slide slide = ppt.createSlide();
+
+ ShapeGroup group = new ShapeGroup();
+ //define position of the drawing in the slide
+ Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
+ group.setAnchor(bounds);
+ group.setCoordinates(new java.awt.Rectangle(0, 0, 100, 100));
+ slide.addShape(group);
+ Graphics2D graphics = new PPGraphics2D(group);
+
+ //draw a simple bar graph
+ int x = 10, y = 10;
+ graphics.setFont(new Font("Arial", Font.BOLD, 10));
+ for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
+ graphics.setColor(Color.black);
+ int width = ((Integer)def[i+1]).intValue();
+ graphics.drawString("Q" + idx, x-5, y+10);
+ graphics.drawString(width + "%", x + width+3, y + 10);
+ graphics.setColor((Color)def[i]);
+ graphics.fill(new Rectangle(x, y, width, 10));
+ y += 15;
+ }
+ graphics.setColor(Color.black);
+ graphics.setFont(new Font("Arial", Font.BOLD, 14));
+ graphics.draw(group.getCoordinates());
+ graphics.drawString("Performance", x + 30, y + 10);
+
+ FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");
+ ppt.write(out);
+ out.close();
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.model.Slide;\r
-import org.apache.poi.hslf.model.TextRun;\r
-import org.apache.poi.hslf.model.Hyperlink;\r
-import org.apache.poi.hslf.model.Shape;\r
-\r
-import java.io.FileInputStream;\r
-\r
-/**\r
- * Demonstrates how to read hyperlinks from a presentation\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class Hyperlinks {\r
-\r
- public static void main(String[] args) throws Exception {\r
- for (int i = 0; i < args.length; i++) {\r
- FileInputStream is = new FileInputStream(args[i]);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- Slide[] slide = ppt.getSlides();\r
- for (int j = 0; j < slide.length; j++) {\r
- System.out.println("slide " + slide[j].getSlideNumber());\r
-\r
- //read hyperlinks from the slide's text runs\r
- System.out.println("reading hyperlinks from the text runs");\r
- TextRun[] txt = slide[j].getTextRuns();\r
- for (int k = 0; k < txt.length; k++) {\r
- String text = txt[k].getText();\r
- Hyperlink[] links = txt[k].getHyperlinks();\r
- if(links != null) for (int l = 0; l < links.length; l++) {\r
- Hyperlink link = links[l];\r
- String title = link.getTitle();\r
- String address = link.getAddress();\r
- System.out.println(" " + title);\r
- System.out.println(" " + address);\r
- String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1);//in ppt end index is inclusive\r
- System.out.println(" " + substring);\r
- }\r
- }\r
-\r
- //in PowerPoint you can assign a hyperlink to a shape without text,\r
- //for example to a Line object. The code below demonstrates how to\r
- //read such hyperlinks\r
- System.out.println(" reading hyperlinks from the slide's shapes");\r
- Shape[] sh = slide[j].getShapes();\r
- for (int k = 0; k < sh.length; k++) {\r
- Hyperlink link = sh[k].getHyperlink();\r
- if(link != null) {\r
- String title = link.getTitle();\r
- String address = link.getAddress();\r
- System.out.println(" " + title);\r
- System.out.println(" " + address);\r
- }\r
- }\r
- }\r
-\r
- }\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.Slide;
+import org.apache.poi.hslf.model.TextRun;
+import org.apache.poi.hslf.model.Hyperlink;
+import org.apache.poi.hslf.model.Shape;
+
+import java.io.FileInputStream;
+
+/**
+ * Demonstrates how to read hyperlinks from a presentation
+ *
+ * @author Yegor Kozlov
+ */
+public final class Hyperlinks {
+
+ public static void main(String[] args) throws Exception {
+ for (int i = 0; i < args.length; i++) {
+ FileInputStream is = new FileInputStream(args[i]);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Slide[] slide = ppt.getSlides();
+ for (int j = 0; j < slide.length; j++) {
+ System.out.println("slide " + slide[j].getSlideNumber());
+
+ //read hyperlinks from the slide's text runs
+ System.out.println("reading hyperlinks from the text runs");
+ TextRun[] txt = slide[j].getTextRuns();
+ for (int k = 0; k < txt.length; k++) {
+ String text = txt[k].getText();
+ Hyperlink[] links = txt[k].getHyperlinks();
+ if(links != null) for (int l = 0; l < links.length; l++) {
+ Hyperlink link = links[l];
+ String title = link.getTitle();
+ String address = link.getAddress();
+ System.out.println(" " + title);
+ System.out.println(" " + address);
+ String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1);//in ppt end index is inclusive
+ System.out.println(" " + substring);
+ }
+ }
+
+ //in PowerPoint you can assign a hyperlink to a shape without text,
+ //for example to a Line object. The code below demonstrates how to
+ //read such hyperlinks
+ System.out.println(" reading hyperlinks from the slide's shapes");
+ Shape[] sh = slide[j].getShapes();
+ for (int k = 0; k < sh.length; k++) {
+ Hyperlink link = sh[k].getHyperlink();
+ if(link != null) {
+ String title = link.getTitle();
+ String address = link.getAddress();
+ System.out.println(" " + title);
+ System.out.println(" " + address);
+ }
+ }
+ }
+
+ }
+
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.*;\r
-import org.apache.poi.hslf.model.*;\r
-import org.apache.poi.hslf.record.TextHeaderAtom;\r
-\r
-import javax.imageio.ImageIO;\r
-import java.io.IOException;\r
-import java.io.FileOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.awt.*;\r
-import java.awt.image.BufferedImage;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-/**\r
- * Demonstrates how you can use HSLF to convert each slide into a PNG image\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class PPT2PNG {\r
-\r
- public static void main(String args[]) throws Exception {\r
-\r
- if (args.length == 0) {\r
- usage();\r
- return;\r
- }\r
-\r
- int slidenum = -1;\r
- float scale = 1;\r
- String file = null;\r
-\r
- for (int i = 0; i < args.length; i++) {\r
- if (args[i].startsWith("-")) {\r
- if ("-scale".equals(args[i])){\r
- scale = Float.parseFloat(args[++i]);\r
- } else if ("-slide".equals(args[i])) {\r
- slidenum = Integer.parseInt(args[++i]);\r
- }\r
- } else {\r
- file = args[i];\r
- }\r
- }\r
- if(file == null){\r
- usage();\r
- return;\r
- }\r
-\r
- FileInputStream is = new FileInputStream(file);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- Dimension pgsize = ppt.getPageSize();\r
- int width = (int)(pgsize.width*scale);\r
- int height = (int)(pgsize.height*scale);\r
-\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- if (slidenum != -1 && slidenum != (i+1)) continue;\r
-\r
- String title = slide[i].getTitle();\r
- System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title));\r
-\r
- BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);\r
- Graphics2D graphics = img.createGraphics();\r
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);\r
- graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);\r
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);\r
-\r
- graphics.setPaint(Color.white);\r
- graphics.fill(new Rectangle2D.Float(0, 0, width, height));\r
-\r
- graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);\r
-\r
- slide[i].draw(graphics);\r
-\r
- String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png");\r
- FileOutputStream out = new FileOutputStream(fname);\r
- ImageIO.write(img, "png", out);\r
- out.close();\r
- }\r
- }\r
-\r
- private static void usage(){\r
- System.out.println("Usage: PPT2PNG [-scale <scale> -slide <num>] ppt");\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+import javax.imageio.ImageIO;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Demonstrates how you can use HSLF to convert each slide into a PNG image
+ *
+ * @author Yegor Kozlov
+ */
+public final class PPT2PNG {
+
+ public static void main(String args[]) throws Exception {
+
+ if (args.length == 0) {
+ usage();
+ return;
+ }
+
+ int slidenum = -1;
+ float scale = 1;
+ String file = null;
+
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].startsWith("-")) {
+ if ("-scale".equals(args[i])){
+ scale = Float.parseFloat(args[++i]);
+ } else if ("-slide".equals(args[i])) {
+ slidenum = Integer.parseInt(args[++i]);
+ }
+ } else {
+ file = args[i];
+ }
+ }
+ if(file == null){
+ usage();
+ return;
+ }
+
+ FileInputStream is = new FileInputStream(file);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Dimension pgsize = ppt.getPageSize();
+ int width = (int)(pgsize.width*scale);
+ int height = (int)(pgsize.height*scale);
+
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ if (slidenum != -1 && slidenum != (i+1)) continue;
+
+ String title = slide[i].getTitle();
+ System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title));
+
+ BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = img.createGraphics();
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+
+ graphics.setPaint(Color.white);
+ graphics.fill(new Rectangle2D.Float(0, 0, width, height));
+
+ graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);
+
+ slide[i].draw(graphics);
+
+ String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png");
+ FileOutputStream out = new FileOutputStream(fname);
+ ImageIO.write(img, "png", out);
+ out.close();
+ }
+ }
+
+ private static void usage(){
+ System.out.println("Usage: PPT2PNG [-scale <scale> -slide <num>] ppt");
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.examples;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.RichTextRun;\r
-import org.apache.poi.hslf.model.*;\r
-\r
-import java.awt.*;\r
-import java.io.FileOutputStream;\r
-\r
-/**\r
- * Demonstrates how to create tables\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TableDemo {\r
-\r
- public static void main(String[] args) throws Exception {\r
-\r
- //test data for the first taable\r
- String[][] txt1 = {\r
- {"INPUT FILE", "NUMBER OF RECORDS"},\r
- {"Item File", "11,559"},\r
- {"Vendor File", "502"},\r
- {"Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)", "12,852"},\r
- {"Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)", "53,523" },\r
- {"Total PO History Spend", "$10,172,038"}\r
- };\r
-\r
- SlideShow ppt = new SlideShow();\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- //six rows, two columns\r
- Table table1 = new Table(6, 2);\r
- for (int i = 0; i < txt1.length; i++) {\r
- for (int j = 0; j < txt1[i].length; j++) {\r
- TableCell cell = table1.getCell(i, j);\r
- cell.setText(txt1[i][j]);\r
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];\r
- rt.setFontName("Arial");\r
- rt.setFontSize(10);\r
- if(i == 0){\r
- cell.getFill().setForegroundColor(new Color(227, 227, 227));\r
- } else {\r
- rt.setBold(true);\r
- }\r
- cell.setVerticalAlignment(TextBox.AnchorMiddle);\r
- cell.setHorizontalAlignment(TextBox.AlignCenter);\r
- }\r
- }\r
-\r
- Line border1 = table1.createBorder();\r
- border1.setLineColor(Color.black);\r
- border1.setLineWidth(1.0);\r
- table1.setAllBorders(border1);\r
-\r
- table1.setColumnWidth(0, 300);\r
- table1.setColumnWidth(1, 150);\r
-\r
- slide.addShape(table1);\r
- int pgWidth = ppt.getPageSize().width;\r
- table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);\r
-\r
- //test data for the second taable\r
- String[][] txt2 = {\r
- {"Data Source"},\r
- {"CAS Internal Metrics - Item Master Summary\r" +\r
- "CAS Internal Metrics - Vendor Summary\r" +\r
- "CAS Internal Metrics - PO History Summary"}\r
- };\r
-\r
- //two rows, one column\r
- Table table2 = new Table(2, 1);\r
- for (int i = 0; i < txt2.length; i++) {\r
- for (int j = 0; j < txt2[i].length; j++) {\r
- TableCell cell = table2.getCell(i, j);\r
- cell.setText(txt2[i][j]);\r
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];\r
- rt.setFontSize(10);\r
- rt.setFontName("Arial");\r
- if(i == 0){\r
- cell.getFill().setForegroundColor(new Color(0, 51, 102));\r
- rt.setFontColor(Color.white);\r
- rt.setBold(true);\r
- rt.setFontSize(14);\r
- cell.setHorizontalAlignment(TextBox.AlignCenter);\r
- } else {\r
- rt.setBullet(true);\r
- rt.setFontSize(12);\r
- cell.setHorizontalAlignment(TextBox.AlignLeft);\r
- }\r
- cell.setVerticalAlignment(TextBox.AnchorMiddle);\r
- }\r
- }\r
- table2.setColumnWidth(0, 300);\r
- table2.setRowHeight(0, 30);\r
- table2.setRowHeight(1, 70);\r
-\r
- Line border2 = table2.createBorder();\r
- table2.setOutsideBorders(border2);\r
-\r
- slide.addShape(table2);\r
- table2.moveTo(200, 400);\r
-\r
- FileOutputStream out = new FileOutputStream("hslf-table.ppt");\r
- ppt.write(out);\r
- out.close();\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.model.*;
+
+import java.awt.*;
+import java.io.FileOutputStream;
+
+/**
+ * Demonstrates how to create tables
+ *
+ * @author Yegor Kozlov
+ */
+public final class TableDemo {
+
+ public static void main(String[] args) throws Exception {
+
+ //test data for the first taable
+ String[][] txt1 = {
+ {"INPUT FILE", "NUMBER OF RECORDS"},
+ {"Item File", "11,559"},
+ {"Vendor File", "502"},
+ {"Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)", "12,852"},
+ {"Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)", "53,523" },
+ {"Total PO History Spend", "$10,172,038"}
+ };
+
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ //six rows, two columns
+ Table table1 = new Table(6, 2);
+ for (int i = 0; i < txt1.length; i++) {
+ for (int j = 0; j < txt1[i].length; j++) {
+ TableCell cell = table1.getCell(i, j);
+ cell.setText(txt1[i][j]);
+ RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
+ rt.setFontName("Arial");
+ rt.setFontSize(10);
+ if(i == 0){
+ cell.getFill().setForegroundColor(new Color(227, 227, 227));
+ } else {
+ rt.setBold(true);
+ }
+ cell.setVerticalAlignment(TextBox.AnchorMiddle);
+ cell.setHorizontalAlignment(TextBox.AlignCenter);
+ }
+ }
+
+ Line border1 = table1.createBorder();
+ border1.setLineColor(Color.black);
+ border1.setLineWidth(1.0);
+ table1.setAllBorders(border1);
+
+ table1.setColumnWidth(0, 300);
+ table1.setColumnWidth(1, 150);
+
+ slide.addShape(table1);
+ int pgWidth = ppt.getPageSize().width;
+ table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);
+
+ //test data for the second taable
+ String[][] txt2 = {
+ {"Data Source"},
+ {"CAS Internal Metrics - Item Master Summary\r" +
+ "CAS Internal Metrics - Vendor Summary\r" +
+ "CAS Internal Metrics - PO History Summary"}
+ };
+
+ //two rows, one column
+ Table table2 = new Table(2, 1);
+ for (int i = 0; i < txt2.length; i++) {
+ for (int j = 0; j < txt2[i].length; j++) {
+ TableCell cell = table2.getCell(i, j);
+ cell.setText(txt2[i][j]);
+ RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
+ rt.setFontSize(10);
+ rt.setFontName("Arial");
+ if(i == 0){
+ cell.getFill().setForegroundColor(new Color(0, 51, 102));
+ rt.setFontColor(Color.white);
+ rt.setBold(true);
+ rt.setFontSize(14);
+ cell.setHorizontalAlignment(TextBox.AlignCenter);
+ } else {
+ rt.setBullet(true);
+ rt.setFontSize(12);
+ cell.setHorizontalAlignment(TextBox.AlignLeft);
+ }
+ cell.setVerticalAlignment(TextBox.AnchorMiddle);
+ }
+ }
+ table2.setColumnWidth(0, 300);
+ table2.setRowHeight(0, 30);
+ table2.setRowHeight(1, 70);
+
+ Line border2 = table2.createBorder();
+ table2.setOutsideBorders(border2);
+
+ slide.addShape(table2);
+ table2.moveTo(200, 400);
+
+ FileOutputStream out = new FileOutputStream("hslf-table.ppt");
+ ppt.write(out);
+ out.close();
+
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import org.apache.poi.hwpf.HWPFDocument;
import java.io.*;
-public class Word2Forrest
+public final class Word2Forrest
{
Writer _out;
HWPFDocument _doc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.event;
import java.util.ArrayList;
-public class EventBridge implements HDFLowLevelParsingListener
+public final class EventBridge implements HDFLowLevelParsingListener
{
private static int HEADER_EVEN_INDEX = 0;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.event;
import org.apache.poi.hdf.model.hdftypes.ChpxNode;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.event;
import org.apache.poi.hdf.model.hdftypes.SectionProperties;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class CHP implements Cloneable
+public final class CHP implements Cloneable
{
boolean _bold;
boolean _italic;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class FontTable
+public final class FontTable
{
String[] fontNames;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class HeaderFooter
+public final class HeaderFooter
{
public static final int HEADER_EVEN = 1;
public static final int HEADER_ODD = 2;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class NewOleFile extends RandomAccessFile
+public final class NewOleFile extends RandomAccessFile
{
private byte[] LAOLA_ID_ARRAY = new byte[]{(byte)0xd0, (byte)0xcf, (byte)0x11,
(byte)0xe0, (byte)0xa1, (byte)0xb1,
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class PAP implements Cloneable
+public final class PAP implements Cloneable
{
int _istd;//index to style descriptor.
byte _jc;//justification code
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class PropertySet
+public final class PropertySet
{
private String _name;
private int _type;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class SEP
+public final class SEP
{
int _index;
byte _bkc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class StyleDescription
+public final class StyleDescription
{
private static int PARAGRAPH_STYLE = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class StyleSheet
+public final class StyleSheet
{
private static final int NIL_STYLE = 4095;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class TAP
+public final class TAP
{
short _jc;
int _dxaGapHalf;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class TC
+public final class TC
{
boolean _fFirstMerged;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class TableRow
+public final class TableRow
{
TAP _descriptor;
ArrayList _cells;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class TextPiece extends PropertyNode implements Comparable
+public final class TextPiece extends PropertyNode implements Comparable
{
private boolean _usesUnicode;
private int _length;
public int compareTo(Object obj) {
return 0;
}
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class Utils
+public final class Utils
{
public static short convertBytesToShort(byte firstByte, byte secondByte)
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor;
* @author Ryan Ackley
*/
-public class WordDocument
+public final class WordDocument
{
/** byte buffer containing the main Document stream*/
byte[] _header;
{
this(new FileInputStream(fileName));
}
-
+
public WordDocument(InputStream inputStream) throws IOException
{
//do Ole stuff
return "<fo:region-" + where + " display-align=\"" + align + "\" extent=\""
+ extent + "pt\" "+region+"/>";
-// org.apache.fop.fo.expr.PropertyException:
-// Border and padding for region "xsl-region-before" must be '0'
+// org.apache.fop.fo.expr.PropertyException:
+// Border and padding for region "xsl-region-before" must be '0'
// (See 6.4.13 in XSL 1.0).
// extent + "pt\" padding-left=\"" + marginLeft + "pt\" padding-right=\"" +
// marginRight + "pt\" padding-top=\"" + marginTop + "pt\" padding-bottom=\"" +
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.data;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class DOP
+public final class DOP
{
public boolean _fFacingPages;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.data;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class LFO
+public final class LFO
{
int _lsid;
int _clfolvl;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.data;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class LFOLVL
+public final class LFOLVL
{
int _iStartAt;
int _ilvl;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.data;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class LST
+public final class LST
{
int _lsid;
int _tplc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.data;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class LVL
+public final class LVL
{
public int _iStartAt;
public byte _nfc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.data;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class ListTables
+public final class ListTables
{
LFO[] _pllfo;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.util;
* are in ascending order. The Iterator.remove() method is supported.
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*
*/
-public class BTreeSet extends AbstractSet implements Set {
+public final class BTreeSet extends AbstractSet implements Set {
/*
* Instance Variables
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.util;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class ChpxNode extends PropertyNode
+public final class ChpxNode extends PropertyNode
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.util;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class NumberFormatter
+public final class NumberFormatter
{
private final static int ARABIC = 0;
private final static int UPPER_ROMAN = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.util;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class PapxNode extends PropertyNode
+public final class PapxNode extends PropertyNode
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.util;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class PropertyNode implements Comparable
-{
+public abstract class PropertyNode implements Comparable {
private byte[] _grpprl;
private int _fcStart;
private int _fcEnd;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.extractor.util;
/**
* Comment me
*
- * @author Ryan Ackley
+ * @author Ryan Ackley
*/
-public class SepxNode extends PropertyNode
+public final class SepxNode extends PropertyNode
{
int _index;
{
return getGrpprl();
}
-
+
public int compareTo(Object obj) {
return 0;
}
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model;
import java.io.InputStream;
import org.apache.poi.hdf.event.HDFParsingListener;
import org.apache.poi.hdf.event.EventBridge;
-public class HDFDocument
+public final class HDFDocument
{
HDFObjectModel _model;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-/*
- * HDFObjectFactory.java
- *
- * Created on February 24, 2002, 2:17 PM
- */
package org.apache.poi.hdf.model;
* that represent the data.
* @author andy
*/
-public class HDFObjectFactory
+public final class HDFObjectFactory
{
/** OLE stuff*/
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model;
import org.apache.poi.hdf.event.HDFLowLevelParsingListener;
import org.apache.poi.hdf.model.hdftypes.StyleSheet;
-public class HDFObjectModel implements HDFLowLevelParsingListener
+public final class HDFObjectModel implements HDFLowLevelParsingListener
{
/** "WordDocument" from the POIFS */
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model.hdftypes;
import org.apache.poi.util.LittleEndian;
*
* @author Ryan Ackley
*/
-public class CHPFormattedDiskPage extends FormattedDiskPage
+public final class CHPFormattedDiskPage extends FormattedDiskPage
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class CharacterProperties extends CHPAbstractType implements Cloneable
+public final class CharacterProperties extends CHPAbstractType implements Cloneable
{
public CharacterProperties()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class ChpxNode extends PropertyNode
+public final class ChpxNode extends PropertyNode
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class DocumentProperties implements HDFType
+public final class DocumentProperties implements HDFType
{
public boolean _fFacingPages;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model.hdftypes;
import org.apache.poi.util.BitField;
*
* @author andy
*/
-public class FileInformationBlock extends FIBAbstractType
+public final class FileInformationBlock extends FIBAbstractType
{
/*
private short field_1_id;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class FontTable implements HDFType
+public final class FontTable implements HDFType
{
String[] fontNames;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.model.hdftypes;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-/*
- * HDFType.java
- *
- * Created on February 24, 2002, 2:37 PM
- */
package org.apache.poi.hdf.model.hdftypes;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class HeaderFooter
+public final class HeaderFooter
{
public static final int HEADER_EVEN = 1;
public static final int HEADER_ODD = 2;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class LFO
+public final class LFO
{
int _lsid;
int _clfolvl;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class LFOLVL
+public final class LFOLVL
{
int _iStartAt;
int _ilvl;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class LST
+public final class LST
{
int _lsid;
int _tplc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
*/
-public class LVL
+public final class LVL
{
public int _iStartAt;
public byte _nfc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class ListTables implements HDFType
+public final class ListTables implements HDFType
{
LFO[] _pllfo;
lfolvl._fFormatting = StyleSheet.getFlag(lfolvl._ilvl & 0x20);
lfolvl._ilvl = (lfolvl._ilvl & (byte)0x0f);
lfolvlNum++;
-
+
if(lfolvl._fFormatting)
{
// The size of a LFOLVL is 8 bytes.
lvl._fPrevSpace = StyleSheet.getFlag(code & 0x20);
lvl._fWord6 = StyleSheet.getFlag(code & 0x40);
- // rgbxchNums - This array should be zero terminated unless it is full
+ // rgbxchNums - This array should be zero terminated unless it is full
// (all 9 levels full).
System.arraycopy(data, offset, lvl._rgbxchNums, 0, 9);
offset += 9;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model.hdftypes;
import org.apache.poi.util.LittleEndian;
*
* @author Ryan Ackley
*/
-public class PAPFormattedDiskPage extends FormattedDiskPage
+public final class PAPFormattedDiskPage extends FormattedDiskPage
{
/**
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class PapxNode extends PropertyNode
+public final class PapxNode extends PropertyNode
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class ParagraphProperties extends PAPAbstractType implements Cloneable
+public final class ParagraphProperties extends PAPAbstractType implements Cloneable
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model.hdftypes;
*
* @author Ryan Ackley
*/
-public class PlexOfCps
+public final class PlexOfCps
{
private int _count;
private int _offset;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model.hdftypes;
*
* @author Ryan Ackley
*/
-public class PropertyNode implements Comparable
-{
+public abstract class PropertyNode implements Comparable {
private byte[] _grpprl;
private int _fcStart;
private int _fcEnd;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class SectionProperties extends SEPAbstractType implements HDFType
+public final class SectionProperties extends SEPAbstractType implements HDFType
{
/*int _index;
byte _bkc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class SepxNode extends PropertyNode
+public final class SepxNode extends PropertyNode
{
int _index;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class StyleDescription implements HDFType
+public final class StyleDescription implements HDFType
{
private static int PARAGRAPH_STYLE = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class StyleSheet implements HDFType
+public final class StyleSheet implements HDFType
{
private static final int NIL_STYLE = 4095;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class TableCellDescriptor extends TCAbstractType implements HDFType
+public final class TableCellDescriptor extends TCAbstractType implements HDFType
{
/*boolean _fFirstMerged;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class TableProperties extends TAPAbstractType
+public final class TableProperties extends TAPAbstractType
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hdf.model.hdftypes;
* @author Ryan Ackley
*/
-public class TextPiece extends PropertyNode implements Comparable
+public final class TextPiece extends PropertyNode implements Comparable
{
private boolean _usesUnicode;
private int _length;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.hdftypes.definitions;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.util;
*
*/
-public class BTreeSet extends AbstractSet
+public final class BTreeSet extends AbstractSet
{
/*
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model.util;
* @author Ryan Ackley
*/
-public class NumberFormatter
+public final class NumberFormatter
{
private final static int ARABIC = 0;
private final static int UPPER_ROMAN = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hdf.model.util;
import org.apache.poi.hdf.model.hdftypes.FormattedDiskPage;
-public class ParsingState
+public final class ParsingState
{
//int _numPages;// = charPlcf.length();
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf;
import java.io.FileInputStream;
* http://www.gnome.ru/projects/docs/slide1.png
* http://www.gnome.ru/projects/docs/slide2.png
*/
-public class HDGFDiagram extends POIDocument {
+public final class HDGFDiagram extends POIDocument {
private static final String VISIO_HEADER = "Visio (TM) Drawing\r\n";
-
+
private byte[] _docstream;
-
+
private short version;
private long docSize;
-
+
private Pointer trailerPointer;
private TrailerStream trailer;
-
+
private ChunkFactory chunkFactory;
private PointerFactory ptrFactory;
-
+
public HDGFDiagram(POIFSFileSystem fs) throws IOException {
this(fs.getRoot(), fs);
}
public HDGFDiagram(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
super(dir, fs);
-
+
DocumentEntry docProps =
(DocumentEntry)dir.getEntry("VisioDocument");
// Grab the document stream
_docstream = new byte[docProps.getSize()];
dir.createDocumentInputStream("VisioDocument").read(_docstream);
-
+
// Read in the common POI streams
readProperties();
-
+
// Check it's really visio
String typeString = new String(_docstream, 0, 20);
if(! typeString.equals(VISIO_HEADER)) {
throw new IllegalArgumentException("Wasn't a valid visio document, started with " + typeString);
}
-
+
// Grab the version number, 0x1a -> 0x1b
version = LittleEndian.getShort(_docstream, 0x1a);
// Grab the document size, 0x1c -> 0x1f
docSize = LittleEndian.getUInt(_docstream, 0x1c);
// ??? 0x20 -> 0x23
-
+
// Create the Chunk+Pointer Factories for the document version
ptrFactory = new PointerFactory(version);
chunkFactory = new ChunkFactory(version);
-
+
// Grab the pointer to the trailer
trailerPointer = ptrFactory.createPointer(_docstream, 0x24);
-
+
// Now grab the trailer
trailer = (TrailerStream)
Stream.createStream(trailerPointer, _docstream, chunkFactory, ptrFactory);
-
+
// Finally, find all our streams
trailer.findChildren(_docstream);
}
*/
public Stream[] getTopLevelStreams() { return trailer.getPointedToStreams(); }
public long getDocumentSize() { return docSize; }
-
+
/**
* Prints out some simple debug on the base contents of the file.
- * @see org.apache.poi.hdgf.dev.VSDDumper
+ * @see org.apache.poi.hdgf.dev.VSDDumper
*/
public void debug() throws IOException {
System.err.println("Trailer is at " + trailerPointer.getOffset());
System.err.println("Trailer has type " + trailerPointer.getType());
System.err.println("Trailer has length " + trailerPointer.getLength());
System.err.println("Trailer has format " + trailerPointer.getFormat());
-
+
for(int i=0; i<trailer.getPointedToStreams().length; i++) {
Stream stream = trailer.getPointedToStreams()[i];
Pointer ptr = stream.getPointer();
-
+
System.err.println("Looking at pointer " + i);
System.err.println("\tType is " + ptr.getType() + "\t\t" + Integer.toHexString(ptr.getType()));
System.err.println("\tOffset is " + ptr.getOffset() + "\t\t" + Long.toHexString(ptr.getOffset()));
System.err.println("\tFormat is " + ptr.getFormat() + "\t\t" + Long.toHexString(ptr.getFormat()));
System.err.println("\tCompressed is " + ptr.destinationCompressed());
System.err.println("\tStream is " + stream.getClass());
-
+
if(stream instanceof PointerContainingStream) {
PointerContainingStream pcs = (PointerContainingStream)stream;
-
+
if(pcs.getPointedToStreams() != null && pcs.getPointedToStreams().length > 0) {
System.err.println("\tContains " + pcs.getPointedToStreams().length + " other pointers/streams");
for(int j=0; j<pcs.getPointedToStreams().length; j++) {
}
}
}
-
+
if(stream instanceof StringsStream) {
System.err.println("\t\t**strings**");
StringsStream ss = (StringsStream)stream;
}
}
}
-
+
public void write(OutputStream out) {
throw new IllegalStateException("Writing is not yet implemented, see http://poi.apache.org/hdgf/");
}
-
+
/**
* For testing only
*/
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
import java.util.ArrayList;
/**
* Base of all chunks, which hold data, flags etc
*/
-public class Chunk {
- /**
- * The contents of the chunk, excluding the header,
- * trailer and separator
+public final class Chunk {
+ /**
+ * The contents of the chunk, excluding the header,
+ * trailer and separator
*/
private byte[] contents;
private ChunkHeader header;
//private Block[] blocks
/** The name of the chunk, as found from the commandDefinitions */
private String name;
-
+
/** For logging warnings about the structure of the file */
private POILogger logger = POILogFactory.getLogger(Chunk.class);
-
+
public Chunk(ChunkHeader header, ChunkTrailer trailer, ChunkSeparator separator, byte[] contents) {
this.header = header;
this.trailer = trailer;
this.separator = separator;
this.contents = contents;
}
-
+
public byte[] _getContents() {
return contents;
}
}
return size;
}
-
+
/**
* Uses our CommandDefinitions to process the commands
* our chunk type has, and figure out the
if(commandDefinitions == null) {
throw new IllegalStateException("You must supply the command definitions before calling processCommands!");
}
-
+
// Loop over the definitions, building the commands
// and getting their values
ArrayList commands = new ArrayList();
for(int i=0; i<commandDefinitions.length; i++) {
int type = commandDefinitions[i].getType();
int offset = commandDefinitions[i].getOffset();
-
+
// Handle virtual commands
if(type == 10) {
name = commandDefinitions[i].getName();
continue;
}
-
+
// Build the appropriate command for the type
Command command;
if(type == 11 || type == 21) {
} else {
command = new Command(commandDefinitions[i]);
}
-
+
// Bizarely, many of the offsets are from the start of the
// header, not from the start of the chunk body
switch(type) {
offset -= 19;
}
}
-
+
// Check we seem to have enough data
if(offset >= contents.length) {
- logger.log(POILogger.WARN,
+ logger.log(POILogger.WARN,
"Command offset " + offset + " past end of data at " + contents.length
);
continue;
}
-
+
// Process
switch(type) {
// Types 0->7 = a flat at bit 0->7
if(endsAt == startsAt) {
endsAt = contents.length;
}
-
+
int strLen = (endsAt-startsAt) / 2;
command.value = StringUtil.getFromUnicodeLE(contents, startsAt, strLen);
break;
LittleEndian.getInt(contents, offset)
);
break;
-
+
// Types 11 and 21 hold the offset to the blocks
case 11: case 21:
if(offset < contents.length - 3) {
bcmd.setOffset(bOffset);
}
break;
-
+
default:
- logger.log(POILogger.INFO,
+ logger.log(POILogger.INFO,
"Command of type " + type + " not processed!");
}
-
+
// Add to the array
commands.add(command);
}
-
+
// Save the commands we liked the look of
this.commands = (Command[])commands.toArray(
new Command[commands.size()] );
-
+
// Now build up the blocks, if we had a command that tells
// us where a block is
}
-
+
/**
- * A command in the visio file. In order to make things fun,
+ * A command in the visio file. In order to make things fun,
* all the chunk actually stores is the value of the command.
* You have to have your own lookup table to figure out what
* the commands are based on the chunk type.
public static class Command {
protected Object value;
private CommandDefinition definition;
-
+
private Command(CommandDefinition definition, Object value) {
this.definition = definition;
this.value = value;
private Command(CommandDefinition definition) {
this(definition, null);
}
-
+
public CommandDefinition getDefinition() { return definition; }
public Object getValue() { return value; }
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
import java.io.BufferedReader;
* Makes use of chunks_parse_cmds.tbl from vsdump to be able
* to process the chunk value area
*/
-public class ChunkFactory {
+public final class ChunkFactory {
/** The version of the currently open document */
private int version;
/**
* Key is a Chunk's type, value is an array of its CommandDefinitions
*/
private Hashtable chunkCommandDefinitions = new Hashtable();
- /**
- * What the name is of the chunk table definitions file?
+ /**
+ * What the name is of the chunk table definitions file?
* This file comes from the scratchpad resources directory.
*/
- private static String chunkTableName =
+ private static String chunkTableName =
"/org/apache/poi/hdgf/chunks_parse_cmds.tbl";
-
+
/** For logging problems we spot with the file */
private POILogger logger = POILogFactory.getLogger(ChunkFactory.class);
-
+
public ChunkFactory(int version) throws IOException {
this.version = version;
-
+
processChunkParseCommands();
}
-
- /**
+
+ /**
* Open chunks_parse_cmds.tbl and process it, to get the definitions
- * of all the different possible chunk commands.
+ * of all the different possible chunk commands.
*/
private void processChunkParseCommands() throws IOException {
String line;
if(cpd == null) {
throw new IllegalStateException("Unable to find HDGF chunk definition on the classpath - " + chunkTableName);
}
-
+
BufferedReader inp = new BufferedReader(new InputStreamReader(cpd));
while( (line = inp.readLine()) != null ) {
if(line.startsWith("#")) continue;
}
int chunkType = Integer.parseInt(line.substring(6));
ArrayList defsL = new ArrayList();
-
+
// Data entries
while( ! (line = inp.readLine()).startsWith("end") ) {
StringTokenizer st = new StringTokenizer(line, " ");
int defType = Integer.parseInt(st.nextToken());
int offset = Integer.parseInt(st.nextToken());
String name = st.nextToken("\uffff").substring(1);
-
+
CommandDefinition def = new CommandDefinition(defType,offset,name);
defsL.add(def);
}
-
+
CommandDefinition[] defs = (CommandDefinition[])
defsL.toArray(new CommandDefinition[defsL.size()]);
-
+
// Add to the hashtable
chunkCommandDefinitions.put(new Integer(chunkType), defs);
}
inp.close();
cpd.close();
}
-
+
public int getVersion() { return version; }
/**
*/
public Chunk createChunk(byte[] data, int offset) {
// Create the header
- ChunkHeader header =
+ ChunkHeader header =
ChunkHeader.createChunkHeader(version, data, offset);
// Sanity check
if(header.length < 0) {
throw new IllegalArgumentException("Found a chunk with a negative length, which isn't allowed");
}
-
+
// How far up to look
int endOfDataPos = offset + header.getLength() + header.getSizeInBytes();
-
+
// Check we have enough data, and tweak the header size
// as required
if(endOfDataPos > data.length) {
logger.log(POILogger.WARN,
"Header called for " + header.getLength() +" bytes, but that would take us passed the end of the data!");
-
+
endOfDataPos = data.length;
header.length = data.length - offset - header.getSizeInBytes();
-
+
if(header.hasTrailer()) {
header.length -= 8;
endOfDataPos -= 8;
endOfDataPos -= 4;
}
}
-
+
// Create the trailer and separator, if required
ChunkTrailer trailer = null;
byte[] contents = new byte[header.getLength()];
System.arraycopy(data, offset+header.getSizeInBytes(), contents, 0, contents.length);
Chunk chunk = new Chunk(header, trailer, separator, contents);
-
+
// Feed in the stuff from chunks_parse_cmds.tbl
CommandDefinition[] defs = (CommandDefinition[])
chunkCommandDefinitions.get(new Integer(header.getType()));
if(defs == null) defs = new CommandDefinition[0];
chunk.commandDefinitions = defs;
-
+
// Now get the chunk to process its commands
chunk.processCommands();
-
+
// All done
return chunk;
}
-
+
/**
* The definition of a Command, which a chunk may hold.
* The Command holds the value, this describes it.
this.offset = offset;
this.name = name;
}
-
+
public String getName() {
return name;
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
import org.apache.poi.util.LittleEndian;
protected int id;
protected int length;
protected int unknown1;
-
+
/**
* Creates the appropriate ChunkHeader for the Chunk Header at
* the given location, for the given document version.
ch.length = (int)LittleEndian.getUInt(data, offset + 12);
ch.unknown2 = LittleEndian.getShort(data, offset + 16);
ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 18);
-
+
return ch;
} else if(documentVersion == 5 || documentVersion == 4) {
ChunkHeaderV4V5 ch = new ChunkHeaderV4V5();
-
+
ch.type = (int)LittleEndian.getShort(data, offset + 0);
ch.id = (int)LittleEndian.getShort(data, offset + 2);
ch.unknown2 = (short)LittleEndian.getUnsignedByte(data, offset + 4);
ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 5);
ch.unknown1 = (short)LittleEndian.getShort(data, offset + 6);
ch.length = (int)LittleEndian.getUInt(data, offset + 8);
-
+
return ch;
} else {
throw new IllegalArgumentException("Visio files with versions below 4 are not supported, yours was " + documentVersion);
}
}
-
+
/**
* Returns the size of a chunk header for the given document version.
*/
return ChunkHeaderV4V5.getHeaderSize();
}
}
-
+
public abstract int getSizeInBytes();
public abstract boolean hasTrailer();
public abstract boolean hasSeparator();
-
+
/**
* Returns the ID/IX of the chunk
*/
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
/**
* A chunk header from v11+
*/
-public class ChunkHeaderV11 extends ChunkHeaderV6 {
+public final class ChunkHeaderV11 extends ChunkHeaderV6 {
/**
* Does the chunk have a separator?
*/
public boolean hasSeparator() {
- // For some reason, there are two types that don't have a
+ // For some reason, there are two types that don't have a
// separator despite the flags that indicate they do
if(type == 0x1f || type == 0xc9) { return false; }
-
+
// If there's a trailer, there's a separator
if(hasTrailer()) { return true; }
if(unknown2 == 2 && unknown3 == 0x54 && type == 0xaa) { return true; }
if(unknown2 == 3 && unknown3 != 0x50) { return true; }
if(type == 0x69) { return true; }
-
+
return false;
}
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
/**
* A chunk header from v4 or v5
*/
-public class ChunkHeaderV4V5 extends ChunkHeader {
+public final class ChunkHeaderV4V5 extends ChunkHeader {
protected short unknown2;
protected short unknown3;
public short getUnknown3() {
return unknown3;
}
-
+
protected static int getHeaderSize() {
return 12;
}
-
+
public int getSizeInBytes() {
return getHeaderSize();
}
-
+
/**
* Does the chunk have a trailer?
*/
// V4 and V5 never has trailers
return false;
}
-
+
/**
* Does the chunk have a separator?
*/
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
/**
public short getUnknown3() {
return unknown3;
}
-
+
protected static int getHeaderSize() {
// Looks like it ought to be 19...
return 19;
public int getSizeInBytes() {
return getHeaderSize();
}
-
+
/**
* Does the chunk have a trailer?
*/
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
/**
* A separator between the trailer of one chunk, and the
* header of the next one
*/
-public class ChunkSeparator {
+public final class ChunkSeparator {
protected byte[] separatorData;
-
+
public ChunkSeparator(byte[] data, int offset) {
separatorData = new byte[4];
System.arraycopy(data, offset, separatorData, 0, 4);
}
-
+
public String toString() {
return "<ChunkSeparator of length " + separatorData.length + ">";
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
/**
* A trailer that follows a chunk
*/
-public class ChunkTrailer {
+public final class ChunkTrailer {
protected byte[] trailerData;
-
+
public ChunkTrailer(byte[] data, int offset) {
trailerData = new byte[8];
System.arraycopy(data, offset, trailerData, 0, 8);
}
-
+
public String toString() {
return "<ChunkTrailer of length " + trailerData.length + ">";
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.dev;
import java.io.FileInputStream;
* Developer helper class to dump out the pointer+stream structure
* of a Visio file
*/
-public class VSDDumper {
+public final class VSDDumper {
public static void main(String[] args) throws Exception {
if(args.length == 0) {
System.err.println("Use:");
System.err.println(" VSDDumper <filename>");
System.exit(1);
}
-
+
HDGFDiagram hdgf = new HDGFDiagram(
new POIFSFileSystem(new FileInputStream(args[0]))
);
-
+
System.out.println("Opened " + args[0]);
System.out.println("The document claims a size of " +
- hdgf.getDocumentSize() + " (" +
+ hdgf.getDocumentSize() + " (" +
Long.toHexString(hdgf.getDocumentSize()) + ")");
System.out.println();
-
+
dumpStream(hdgf.getTrailerStream(), 0);
}
-
+
public static void dumpStream(Stream stream, int indent) {
String ind = "";
for(int i=0; i<indent; i++) {
}
String ind2 = ind + " ";
String ind3 = ind2 + " ";
-
-
+
+
Pointer ptr = stream.getPointer();
System.out.println(ind + "Stream at\t" + ptr.getOffset() +
" - " + Integer.toHexString(ptr.getOffset()));
}
System.out.println(ind + " Compressed is\t" + ptr.destinationCompressed());
System.out.println(ind + " Stream is\t" + stream.getClass().getName());
-
+
byte[] db = stream._getStore()._getContents();
String ds = "";
if(db.length >= 8) {
}
}
System.out.println(ind + " First few bytes are\t" + ds);
-
+
if(stream instanceof PointerContainingStream) {
PointerContainingStream pcs = (PointerContainingStream)stream;
- System.out.println(ind + " Has " +
+ System.out.println(ind + " Has " +
pcs.getPointedToStreams().length + " children:");
-
+
for(int i=0; i<pcs.getPointedToStreams().length; i++) {
dumpStream(pcs.getPointedToStreams()[i], (indent+1));
}
ChunkStream cs = (ChunkStream)stream;
System.out.println(ind + " Has " + cs.getChunks().length +
" chunks:");
-
+
for(int i=0; i<cs.getChunks().length; i++) {
Chunk chunk = cs.getChunks()[i];
System.out.println(ind2 + "" + chunk.getName());
System.out.println(ind2 + " Holds " + chunk.getCommands().length + " commands");
for(int j=0; j<chunk.getCommands().length; j++) {
Command command = chunk.getCommands()[j];
- System.out.println(ind3 + "" +
+ System.out.println(ind3 + "" +
command.getDefinition().getName() +
" " + command.getValue()
);
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-\r
-package org.apache.poi.hdgf.exceptions;\r
-\r
-/**\r
- * The superclass of all HDGF exceptions\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class HDGFException extends RuntimeException {\r
-\r
- public HDGFException() {\r
- super();\r
- }\r
-\r
- public HDGFException(String message) {\r
- super(message);\r
- }\r
-\r
- public HDGFException(String message, Throwable cause) {\r
- super(message, cause);\r
- }\r
-\r
- public HDGFException(Throwable cause) {\r
- super(cause);\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hdgf.exceptions;
+
+/**
+ * The superclass of all HDGF exceptions
+ *
+ * @author Yegor Kozlov
+ */
+public final class HDGFException extends RuntimeException {
+
+ public HDGFException() {
+ super();
+ }
+
+ public HDGFException(String message) {
+ super(message);
+ }
+
+ public HDGFException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public HDGFException(Throwable cause) {
+ super(cause);
+ }
+
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.extractor;
import java.io.FileInputStream;
* Can opperate on the command line (outputs to stdout), or
* can return the text for you (eg for use with Lucene).
*/
-public class VisioTextExtractor extends POIOLE2TextExtractor {
+public final class VisioTextExtractor extends POIOLE2TextExtractor {
private HDGFDiagram hdgf;
private POIFSFileSystem fs;
public VisioTextExtractor(InputStream inp) throws IOException {
this(new POIFSFileSystem(inp));
}
-
+
/**
* Locates all the text entries in the file, and returns their
* contents.
ChunkStream cs = (ChunkStream)stream;
for(int i=0; i<cs.getChunks().length; i++) {
Chunk chunk = cs.getChunks()[i];
- if(chunk != null &&
+ if(chunk != null &&
chunk.getName() != null &&
chunk.getName().equals("Text") &&
chunk.getCommands().length > 0) {
}
}
}
-
+
/**
* Returns the textual contents of the file.
* Each textual object's text will be separated
}
return text.toString();
}
-
+
public static void main(String[] args) throws Exception {
if(args.length == 0) {
System.err.println("Use:");
System.err.println(" VisioTextExtractor <file.vsd>");
System.exit(1);
}
-
- VisioTextExtractor extractor =
+
+ VisioTextExtractor extractor =
new VisioTextExtractor(new FileInputStream(args[0]));
-
+
// Print not PrintLn as already has \n added to it
System.out.print(extractor.getText());
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.pointers;
/**
- * Base class of pointers, which hold metadata and offsets about
+ * Base class of pointers, which hold metadata and offsets about
* blocks elsewhere in the file
*/
public abstract class Pointer {
protected int offset;
protected int length;
protected short format;
-
+
public int getAddress() {
return address;
}
public int getType() {
return type;
}
-
+
public abstract int getSizeInBytes();
public abstract boolean destinationHasStrings();
public abstract boolean destinationHasPointers();
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.pointers;
import org.apache.poi.util.LittleEndian;
* Factor class to create the appropriate pointers, based on the version
* of the file
*/
-public class PointerFactory {
+public final class PointerFactory {
private int version;
public PointerFactory(int version) {
this.version = version;
}
public int getVersion() { return version; }
-
+
public Pointer createPointer(byte[] data, int offset) {
Pointer p;
if(version >= 6) {
p.offset = (int)LittleEndian.getUInt(data, offset+8);
p.length = (int)LittleEndian.getUInt(data, offset+12);
p.format = LittleEndian.getShort(data, offset+16);
-
+
return p;
} else if(version == 5) {
throw new RuntimeException("TODO");
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.pointers;
/**
- * A Pointer from v6+
+ * A Pointer from v6+
*/
-public class PointerV6 extends Pointer {
+public final class PointerV6 extends Pointer {
public boolean destinationHasStrings() {
return (0x40 <= format && format < 0x50);
}
public boolean destinationHasChunks() {
return (0xd0 <= format && format < 0xdf);
}
-
+
public boolean destinationCompressed() {
// Apparently, it's the second least significant bit
return (format & 2) > 0;
}
-
+
/**
* With v6 pointers, the on-disk size is 18 bytes
*/
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import java.util.ArrayList;
import org.apache.poi.hdgf.chunks.ChunkHeader;
import org.apache.poi.hdgf.pointers.Pointer;
-public class ChunkStream extends Stream {
+public final class ChunkStream extends Stream {
private ChunkFactory chunkFactory;
/** All the Chunks we contain */
private Chunk[] chunks;
-
+
protected ChunkStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory) {
super(pointer, store);
this.chunkFactory = chunkFactory;
-
+
// For compressed stores, we require all of the data
store.copyBlockHeaderToContents();
}
-
+
public Chunk[] getChunks() { return chunks; }
-
+
/**
* Process the contents of the stream out into chunks
*/
public void findChunks() {
ArrayList chunksA = new ArrayList();
-
+
if(getPointer().getOffset() == 0x64b3) {
int i = 0;
i++;
}
-
+
int pos = 0;
byte[] contents = getStore().getContents();
while(pos < contents.length) {
if(pos+headerSize <= contents.length) {
Chunk chunk = chunkFactory.createChunk(contents, pos);
chunksA.add(chunk);
-
+
pos += chunk.getOnDiskSize();
} else {
System.err.println("Needed " + headerSize + " bytes to create the next chunk header, but only found " + (contents.length-pos) + " bytes, ignoring rest of data");
pos = contents.length;
}
}
-
+
chunks = (Chunk[])chunksA.toArray(new Chunk[chunksA.size()]);
}
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import java.io.ByteArrayInputStream;
* A StreamStore where the data on-disk is compressed,
* using the crazy Visio LZW
*/
-public class CompressedStreamStore extends StreamStore {
+public final class CompressedStreamStore extends StreamStore {
/** The raw, compressed contents */
private byte[] compressedContents;
- /**
+ /**
* We're not sure what this is, but it comes before the
* real contents in the de-compressed data
*/
private byte[] blockHeader = new byte[4];
private boolean blockHeaderInContents = false;
-
+
protected byte[] _getCompressedContents() { return compressedContents; }
protected byte[] _getBlockHeader() { return blockHeader; }
-
+
/**
* Creates a new compressed StreamStore, which will handle
* the decompression.
*/
protected CompressedStreamStore(byte[] data, int offset, int length) throws IOException {
this(decompress(data,offset,length));
-
+
compressedContents = new byte[length];
System.arraycopy(data, offset, compressedContents, 0, length);
}
super(decompressedData[1], 0, decompressedData[1].length);
blockHeader = decompressedData[0];
}
-
+
/**
* Some kinds of streams expect their 4 byte header to be
* on the front of the contents.
*/
protected void copyBlockHeaderToContents() {
if(blockHeaderInContents) return;
-
+
prependContentsWith(blockHeader);
blockHeaderInContents = true;
}
-
+
/**
* Decompresses the given data, returning it as header + contents
*/
public static byte[][] decompress(byte[] data, int offset, int length) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(data, offset, length);
-
+
// Decompress
HDGFLZW lzw = new HDGFLZW();
byte[] decompressed = lzw.decode(bais);
-
+
// Split into header and contents
byte[][] ret = new byte[2][];
ret[0] = new byte[4];
ret[1] = new byte[decompressed.length - 4];
-
+
System.arraycopy(decompressed, 0, ret[0], 0, 4);
System.arraycopy(decompressed, 4, ret[1], 0, ret[1].length);
-
+
// All done
return ret;
}
-}
\ No newline at end of file
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import org.apache.poi.hdgf.chunks.ChunkFactory;
* A stream that holds pointers, possibly in addition to some
* other data too.
*/
-public class PointerContainingStream extends Stream {
+public class PointerContainingStream extends Stream { // TODO - instantiable superclass
private Pointer[] childPointers;
private Stream[] childStreams;
-
+
private ChunkFactory chunkFactory;
private PointerFactory pointerFactory;
private int numPointersLocalOffset;
-
+
protected PointerContainingStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory, PointerFactory pointerFactory) {
super(pointer, store);
this.chunkFactory = chunkFactory;
this.pointerFactory = pointerFactory;
-
+
// Find the offset to the number of child pointers we have
// This ought to be the first thing stored in us
numPointersLocalOffset = (int)LittleEndian.getUInt(
store.getContents(), 0
);
-
+
// Generate the objects for the pointers we contain
int numPointers = (int)LittleEndian.getUInt(
store.getContents(), numPointersLocalOffset
);
childPointers = new Pointer[numPointers];
-
+
// After the number of pointers is another (unknown)
// 4 byte value
int pos = numPointersLocalOffset + 4 + 4;
-
+
// Now create the pointer objects
for(int i=0; i<numPointers; i++) {
childPointers[i] = pointerFactory.createPointer(
pos += childPointers[i].getSizeInBytes();
}
}
-
+
/**
* Returns all the pointers that we contain
*/
* These are all the streams pointed to by the pointers
* that we contain.
*/
- public Stream[] getPointedToStreams() { return childStreams; }
-
+ public Stream[] getPointedToStreams() { return childStreams; }
+
/**
* Performs a recursive search, identifying the pointers we contain,
* creating the Streams for where they point to, then searching
for(int i=0; i<childPointers.length; i++) {
Pointer ptr = childPointers[i];
childStreams[i] = Stream.createStream(ptr, documentData, chunkFactory, pointerFactory);
-
+
// Process chunk streams into their chunks
if(childStreams[i] instanceof ChunkStream) {
ChunkStream child = (ChunkStream)childStreams[i];
child.findChunks();
}
-
+
// Recurse into pointer containing streams
if(childStreams[i] instanceof PointerContainingStream) {
- PointerContainingStream child =
+ PointerContainingStream child =
(PointerContainingStream)childStreams[i];
child.findChildren(documentData);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import java.io.IOException;
public abstract class Stream {
private Pointer pointer;
private StreamStore store;
-
+
public Pointer getPointer() { return pointer; }
protected StreamStore getStore() { return store; }
public StreamStore _getStore() { return store; }
public int _getContentsLength() { return store.getContents().length; }
-
+
/**
* Creates a new Stream, having already used the pointer
- * to build a store
+ * to build a store
*/
protected Stream(Pointer pointer, StreamStore store) {
this.pointer = pointer;
this.store = store;
}
-
+
/**
* Uses the pointer to locate a Stream within the document
* data, and creates it.
documentData, pointer.getOffset(), pointer.getLength()
);
}
-
+
// Figure out what sort of Stream to create, create and return it
if(pointer.getType() == 20) {
return new TrailerStream(pointer, store, chunkFactory, pointerFactory);
return new PointerContainingStream(pointer, store, chunkFactory, pointerFactory);
}
else if(pointer.destinationHasChunks()) {
- return new ChunkStream(pointer, store, chunkFactory);
+ return new ChunkStream(pointer, store, chunkFactory);
}
else if(pointer.destinationHasStrings()) {
return new StringsStream(pointer, store, chunkFactory);
}
-
+
// Give up and return a generic one
return new UnknownStream(pointer, store);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
/**
* handles de-compressing it as required.
* In future, may also handle writing it back out again
*/
-public class StreamStore {
+public class StreamStore { // TODO - instantiable superclass
private byte[] contents;
-
+
/**
* Creates a new, non compressed Stream Store
*/
contents = new byte[length];
System.arraycopy(data, offset, contents, 0, length);
}
-
+
protected void prependContentsWith(byte[] b) {
byte[] newContents = new byte[contents.length + b.length];
System.arraycopy(b, 0, newContents, 0, b.length);
contents = newContents;
}
protected void copyBlockHeaderToContents() {}
-
+
protected byte[] getContents() { return contents; }
public byte[] _getContents() { return contents; }
-}
\ No newline at end of file
+}
/* ====================================================================
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import org.apache.poi.hdgf.chunks.ChunkFactory;
* A Stream which holds Strings. This is just another kind
* of ChunkStream, it seems
*/
-public class StringsStream extends Stream {
+public final class StringsStream extends Stream {
protected StringsStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory) {
super(pointer, store);
// super(pointer, store, chunkFactory);
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import org.apache.poi.hdgf.chunks.ChunkFactory;
* These is one of these in each document, and it's pointed to by
* a special series of byte near the start of the file.
*/
-public class TrailerStream extends PointerContainingStream {
+public class TrailerStream extends PointerContainingStream { // TODO - instantiable superclass
protected TrailerStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory, PointerFactory pointerFactory) {
super(pointer, store, chunkFactory, pointerFactory);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import org.apache.poi.hdgf.pointers.Pointer;
/**
- * A placeholder for a stream where we don't known anything
+ * A placeholder for a stream where we don't known anything
* about how to process / handle it
*/
-public class UnknownStream extends Stream {
+public final class UnknownStream extends Stream {
protected UnknownStream(Pointer pointer, StreamStore store) {
super(pointer, store);
}
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
- * This class provides the basic functionality
+ * This class provides the basic functionality
* for HPBF, our implementation of the publisher
- * file format.
+ * file format.
*/
public final class HPBFDocument extends POIDocument {
private MainContents mainContents;
private QuillContents quillContents;
private EscherStm escherStm;
private EscherDelayStm escherDelayStm;
-
+
/**
* Opens a new publisher document
*/
public HPBFDocument(InputStream inp) throws IOException {
this(new POIFSFileSystem(inp));
}
-
+
/**
* Opens an embeded publisher document,
* at the given directory.
*/
public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
super(dir, fs);
-
+
// Go looking for our interesting child
// streams
mainContents = new MainContents(dir);
quillContents = new QuillContents(dir);
-
+
// Now the Escher bits
escherStm = new EscherStm(dir);
escherDelayStm = new EscherDelayStm(dir);
public EscherDelayStm getEscherDelayStm() {
return escherDelayStm;
}
-
+
public void write(OutputStream out) throws IOException {
throw new IllegalStateException("Writing is not yet implemented, see http://poi.apache.org/hpbf/");
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.dev;
import java.io.FileInputStream;
* files, while we try to figure out how they're
* constructed.
*/
-public class HPBFDumper {
+public final class HPBFDumper {
private POIFSFileSystem fs;
public HPBFDumper(POIFSFileSystem fs) {
this.fs = fs;
public HPBFDumper(InputStream inp) throws IOException {
this(new POIFSFileSystem(inp));
}
-
+
private static byte[] getData(DirectoryNode dir, String name) throws IOException {
DocumentEntry docProps =
(DocumentEntry)dir.getEntry(name);
// Grab the document stream
byte[] d = new byte[docProps.getSize()];
dir.createDocumentInputStream(name).read(d);
-
+
// All done
return d;
}
-
+
/**
* Dumps out the given number of bytes as hex,
* two chars
int j = i + offset;
int b = data[j];
if(b < 0) { b += 256; }
-
+
String bs = Integer.toHexString(b);
if(bs.length() == 1)
ret.append('0');
}
return ret.toString();
}
-
+
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Use:");
HPBFDumper dump = new HPBFDumper(
new FileInputStream(args[0])
);
-
+
System.out.println("Dumping " + args[0]);
dump.dumpContents();
dump.dumpEnvelope();
dump.dumpEscher();
dump.dump001CompObj(dump.fs.getRoot());
dump.dumpQuill();
-
+
// Still to go:
// (0x03)Internal
// Objects
}
-
+
/**
* Dump out the escher parts of the file.
* Escher -> EscherStm and EscherDelayStm
*/
public void dumpEscher() throws IOException {
- DirectoryNode escherDir = (DirectoryNode)
+ DirectoryNode escherDir = (DirectoryNode)
fs.getRoot().getEntry("Escher");
-
+
dumpEscherStm(escherDir);
dumpEscherDelayStm(escherDir);
}
private void dumpEscherStream(byte[] data) {
- DefaultEscherRecordFactory erf =
+ DefaultEscherRecordFactory erf =
new DefaultEscherRecordFactory();
-
+
// Dump
int left = data.length;
while(left > 0) {
EscherRecord er = erf.createRecord(data, 0);
er.fillFields(data, 0, erf);
left -= er.getRecordSize();
-
+
System.out.println(er.toString());
}
}
if(data.length > 0)
dumpEscherStream(data);
}
-
+
public void dumpEnvelope() throws IOException {
byte[] data = getData(fs.getRoot(), "Envelope");
-
+
System.out.println("");
System.out.println("Envelope - " + data.length + " bytes long:");
}
-
+
public void dumpContents() throws IOException {
byte[] data = getData(fs.getRoot(), "Contents");
-
+
System.out.println("");
System.out.println("Contents - " + data.length + " bytes long:");
-
+
// 8 bytes, always seems to be
- // E8 AC 2C 00 E8 03 05 01
- // E8 AC 2C 00 E8 03 05 01
-
+ // E8 AC 2C 00 E8 03 05 01
+ // E8 AC 2C 00 E8 03 05 01
+
// 4 bytes - size of contents
// 13/15 00 00 01
-
+
// ....
-
+
// E8 03 08 08 0C 20 03 00 00 00 00 88 16 00 00 00 ..... ..........
-
+
// 01 18 27 00 03 20 00 00 E8 03 08 08 0C 20 03 00 ..'.. ....... ..
-
- // 01 18 30 00 03 20 00 00
+
+ // 01 18 30 00 03 20 00 00
// E8 03 06 08 07 08 08 08 09 10 01 00 0C 20 04 00
// 00 00 00 88 1E 00 00 00
-
+
// 01 18 31 00 03 20 00 00
// E8 03 06 08 07 08 08 08 09 10 01 00 0C 20 04 00
// 00 00 00 88 1E 00 00 00
-
+
// 01 18 32 00 03 20 00 00
// E8 03 06 08 07 08 08 08 09 10 01 00 0C 20 04 00
// 00 00 00 88 1E 00 00 00
}
-
+
public void dumpCONTENTSraw(DirectoryNode dir) throws IOException {
byte[] data = getData(dir, "CONTENTS");
-
+
System.out.println("");
System.out.println("CONTENTS - " + data.length + " bytes long:");
-
+
// Between the start and 0x200 we have
// CHNKINK(space) + 24 bytes
// 0x1800
// STSH + 8 bytes
// but towards 0x200 the pattern may
// break down a little bit
-
+
// After the second of a given type,
// it seems to be 4 bytes giving the start,
// then 4 bytes giving the length, then
new String(data, 0, 8) +
dumpBytes(data, 8, 0x20-8)
);
-
+
int pos = 0x20;
boolean sixNotEight = true;
while(pos < 0x200) {
System.out.println(
text + " " + dumpBytes(data, pos+4, blen)
);
-
+
pos += 4 + blen;
sixNotEight = ! sixNotEight;
}
-
+
// Text from 0x200 onwards until we get
// to \r(00)\n(00)(00)(00)
int textStop = -1;
StringUtil.getFromUnicodeLE(data, 0x200, len)
);
}
-
+
// The font list comes slightly later
-
+
// The hyperlinks may come before the fonts,
// or slightly in front
}
public void dumpCONTENTSguessed(DirectoryNode dir) throws IOException {
byte[] data = getData(dir, "CONTENTS");
-
+
System.out.println("");
System.out.println("CONTENTS - " + data.length + " bytes long:");
-
+
String[] startType = new String[20];
String[] endType = new String[20];
int[] optA = new int[20];
int[] optC = new int[20];
int[] from = new int[20];
int[] len = new int[20];
-
+
for(int i=0; i<20; i++) {
int offset = 0x20 + i*24;
if(data[offset] == 0x18 && data[offset+1] == 0x00) {
// Doesn't have data
}
}
-
+
String text = StringUtil.getFromUnicodeLE(
data, from[0], len[0]/2
);
-
+
// Dump
for(int i=0; i<20; i++) {
String num = Integer.toString(i);
num = "0" + i;
}
System.out.print(num + " ");
-
+
if(startType[i] == null) {
System.out.println("(not present)");
} else {
System.out.println(
"\t" +
- startType[i] + " " +
- optA[i] + " " +
+ startType[i] + " " +
+ optA[i] + " " +
optB[i] + " " +
optC[i]
);
endType[i] + " " +
"from: " +
Integer.toHexString(from[i]) +
- " (" + from[i] + ")" +
+ " (" + from[i] + ")" +
", len: " +
Integer.toHexString(len[i]) +
" (" + len[i] + ")"
);
}
}
-
+
// Text
System.out.println("");
System.out.println("TEXT:");
System.out.println(text);
System.out.println("");
-
+
// All the others
for(int i=0; i<20; i++) {
if(startType[i] == null) {
continue;
}
int start = from[i];
-
+
System.out.println(
startType[i] + " -> " + endType[i] +
- " @ " + Integer.toHexString(start) +
+ " @ " + Integer.toHexString(start) +
" (" + start + ")"
);
System.out.println("\t" + dumpBytes(data, start, 4));
System.out.println("\t(etc)");
}
}
-
+
protected void dump001CompObj(DirectoryNode dir) {
// TODO
}
-
+
public void dumpQuill() throws IOException {
- DirectoryNode quillDir = (DirectoryNode)
+ DirectoryNode quillDir = (DirectoryNode)
fs.getRoot().getEntry("Quill");
- DirectoryNode quillSubDir = (DirectoryNode)
+ DirectoryNode quillSubDir = (DirectoryNode)
quillDir.getEntry("QuillSub");
dump001CompObj(quillSubDir);
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.dev;
import java.io.FileInputStream;
* HPBF (Publisher) file, while we try to figure out
* what the format of them is.
*/
-public class PLCDumper {
+public final class PLCDumper {
private HPBFDocument doc;
private QuillContents qc;
-
+
public PLCDumper(HPBFDocument hpbfDoc) {
doc = hpbfDoc;
qc = doc.getQuillContents();
public PLCDumper(InputStream inp) throws IOException {
this(new POIFSFileSystem(inp));
}
-
+
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Use:");
PLCDumper dump = new PLCDumper(
new FileInputStream(args[0])
);
-
+
System.out.println("Dumping " + args[0]);
dump.dumpPLC();
}
-
- private void dumpPLC() {
+
+ private void dumpPLC() {
QCBit[] bits = qc.getBits();
-
+
for(int i=0; i<bits.length; i++) {
if(bits[i] == null) continue;
if(bits[i].getBitType().equals("PLC ")) {
}
}
}
-
+
private void dumpBit(QCBit bit, int index) {
System.out.println("");
System.out.println("Dumping " + bit.getBitType() + " bit at " + index);
System.out.println(" Is a " + bit.getThingType() + ", number is " + bit.getOptA());
System.out.println(" Starts at " + bit.getDataOffset() + " (0x" + Integer.toHexString(bit.getDataOffset()) + ")");
System.out.println(" Runs for " + bit.getLength() + " (0x" + Integer.toHexString(bit.getLength()) + ")");
-
+
System.out.println(HexDump.dump(bit.getData(), 0, 0));
}
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.extractor;
import java.io.FileInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
- * Extract text from HPBF Publisher files
+ * Extract text from HPBF Publisher files
*/
-public class PublisherTextExtractor extends POIOLE2TextExtractor {
+public final class PublisherTextExtractor extends POIOLE2TextExtractor {
private HPBFDocument doc;
private boolean hyperlinksByDefault = false;
-
+
public PublisherTextExtractor(HPBFDocument doc) {
super(doc);
this.doc = doc;
public PublisherTextExtractor(InputStream is) throws IOException {
this(new POIFSFileSystem(is));
}
-
+
/**
* Should a call to getText() return hyperlinks inline
* with the text?
this.hyperlinksByDefault = hyperlinksByDefault;
}
-
+
public String getText() {
StringBuffer text = new StringBuffer();
-
+
// Get the text from the Quill Contents
QCBit[] bits = doc.getQuillContents().getBits();
for(int i=0; i<bits.length; i++) {
text.append( t.getText().replace('\r', '\n') );
}
}
-
+
// If requested, add in the hyperlinks
// Ideally, we'd do these inline, but the hyperlink
// positions are relative to the text area the
}
}
}
-
+
// Get more text
// TODO
-
+
return text.toString();
}
-
-
+
+
public static void main(String[] args) throws Exception {
if(args.length == 0) {
System.err.println("Use:");
System.err.println(" PublisherTextExtractor <file.pub>");
}
-
+
for(int i=0; i<args.length; i++) {
PublisherTextExtractor te = new PublisherTextExtractor(
new FileInputStream(args[i])
import java.io.IOException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
-
+/**
+ *
+ */
public final class EscherDelayStm extends EscherPart {
private static final String[] PATH = { "Escher", "EscherDelayStm", };
*/
public abstract class EscherPart extends HPBFPart {
private EscherRecord[] records;
-
+
/**
* Creates the Escher Part, and finds our child
* escher records
*/
public EscherPart(DirectoryNode baseDir, String[] parts) throws IOException {
super(baseDir, parts);
-
+
// Now create our Escher children
- DefaultEscherRecordFactory erf =
+ DefaultEscherRecordFactory erf =
new DefaultEscherRecordFactory();
-
+
ArrayList ec = new ArrayList();
int left = data.length;
while(left > 0) {
EscherRecord er = erf.createRecord(data, 0);
er.fillFields(data, 0, erf);
left -= er.getRecordSize();
-
+
ec.add(er);
}
-
+
records = (EscherRecord[])
ec.toArray(new EscherRecord[ec.size()]);
}
-
+
public EscherRecord[] getEscherRecords() {
return records;
}
-
+
/**
* Serialises our Escher children back
* into bytes.
protected void generateData() {
int size = 0;
for(int i=0; i<records.length; i++) {
- size += records[i].getRecordSize();
+ size += records[i].getRecordSize();
}
-
+
data = new byte[size];
size = 0;
for(int i=0; i<records.length; i++) {
- int thisSize =
+ int thisSize =
records[i].serialize(size, data);
size += thisSize;
}
import java.io.IOException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
-
+/**
+ *
+ */
public final class EscherStm extends EscherPart {
private static final String[] PATH = { "Escher", "EscherStm", };
public EscherStm(DirectoryNode baseDir) throws IOException {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model;
import java.io.ByteArrayInputStream;
* @param path the path to the part, eg Contents or Quill, QuillSub, CONTENTS
*/
public HPBFPart(DirectoryNode baseDir, String[] path) throws IOException {
-
+
DirectoryNode dir = getDir(path, baseDir);
String name = path[path.length-1];
-
+
DocumentEntry docProps;
try {
docProps = (DocumentEntry)dir.getEntry(name);
} catch (FileNotFoundException e) {
- throw new IllegalArgumentException("File invalid - failed to find document entry '"
+ throw new IllegalArgumentException("File invalid - failed to find document entry '"
+ name + "'");
}
try {
dir = (DirectoryNode)dir.getEntry(path[i]);
} catch (FileNotFoundException e) {
- throw new IllegalArgumentException("File invalid - failed to find directory entry '"
+ throw new IllegalArgumentException("File invalid - failed to find directory entry '"
+ path[i] + "'");
}
}
return dir;
}
-
+
public void writeOut(DirectoryNode baseDir) throws IOException {
String[] path = getPath();
-
+
// Ensure that all parent directories exist
DirectoryNode dir = baseDir;
for(int i=0; i<path.length-1; i++) {
dir.createDirectory(path[i]);
}
}
-
+
// Update the byte array with the latest data
generateData();
-
+
// Write out
ByteArrayInputStream bais = new ByteArrayInputStream(data);
dir.createDocument(path[path.length-1], bais);
}
-
+
/**
* Called just before writing out, to trigger
* the data byte array to be updated with the
* latest contents.
*/
protected abstract void generateData();
-
+
/**
* Returns the raw data that makes up
* this document part.
*/
public final class MainContents extends HPBFPart {
private static final String[] PATH = { "Contents", };
-
+
public MainContents(DirectoryNode baseDir) throws IOException {
super(baseDir, PATH);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model;
import java.io.IOException;
public final class QuillContents extends HPBFPart {
private static final String[] PATH = { "Quill", "QuillSub", "CONTENTS", };
private QCBit[] bits;
-
+
public QuillContents(DirectoryNode baseDir) throws IOException {
super(baseDir, PATH);
-
+
// Now parse the first 512 bytes, and produce
// all our bits
-
+
// Check first 8 bytes
String f8 = new String(data, 0, 8);
if(! f8.equals("CHNKINK ")) {
throw new IllegalArgumentException("Expecting 'CHNKINK ' but was '"+f8+"'");
}
// Ignore the next 24, for now at least
-
+
// Now, parse all our QC Bits
bits = new QCBit[20];
for(int i=0; i<20; i++) {
String bitType = new String(data, offset+12, 4);
int from = (int)LittleEndian.getUInt(data, offset+16);
int len = (int)LittleEndian.getUInt(data, offset+20);
-
+
byte[] bitData = new byte[len];
System.arraycopy(data, from, bitData, 0, len);
-
+
// Create
if(bitType.equals("TEXT")) {
bits[i] = new QCTextBit(thingType, bitType, bitData);
public QCBit[] getBits() {
return bits;
}
-
+
protected void generateData() {
// TODO
throw new IllegalStateException("Not done yet!");
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model.qcbits;
/**
protected String thingType;
protected String bitType;
protected byte[] data;
-
+
protected int optA;
protected int optB;
protected int optC;
-
+
protected int dataOffset;
-
+
public QCBit(String thingType, String bitType, byte[] data) {
this.thingType = thingType;
this.bitType = bitType;
this.data = data;
}
-
+
/**
* Returns the type of the thing, eg TEXT, FONT
* or TOKN
public void setDataOffset(int offset) {
this.dataOffset = offset;
}
-
+
public int getLength() {
return data.length;
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model.qcbits;
import org.apache.poi.util.LittleEndian;
* A "PLC " (PLC) based bit of Quill Contents. The exact
* format is determined by the type of the PLCs.
*/
-public class QCPLCBit extends QCBit {
+public abstract class QCPLCBit extends QCBit {
protected int numberOfPLCs;
protected int typeOfPLCS;
- /**
+ /**
* The data which goes before the main PLC entries.
- * This is apparently always made up of 2 byte
+ * This is apparently always made up of 2 byte
* un-signed ints..
*/
protected int[] preData;
protected long[] plcValA;
/** The second value of each PLC, normally 4 bytes */
protected long[] plcValB;
-
-
+
+
private QCPLCBit(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
-
+
// First four bytes are the number
numberOfPLCs = (int)LittleEndian.getUInt(data, 0);
-
+
// Next four bytes are the type
typeOfPLCS = (int)LittleEndian.getUInt(data, 4);
-
+
// Init the arrays that we can
plcValA = new long[numberOfPLCs];
plcValB = new long[numberOfPLCs];
}
-
-
-
+
+
+
public int getNumberOfPLCs() {
return numberOfPLCs;
}
}
}
-
+
/**
* Type 0 seem to be somewhat rare. They have 8 bytes of pre-data,
* then 2x 2 byte values.
public static class Type0 extends QCPLCBit {
private Type0(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
-
+
// Grab our 4x pre-data
preData = new int[4];
preData[0] = LittleEndian.getUShort(data, 8+0);
preData[1] = LittleEndian.getUShort(data, 8+2);
preData[2] = LittleEndian.getUShort(data, 8+4);
preData[3] = LittleEndian.getUShort(data, 8+6);
-
+
// And grab the 2 byte values
for(int i=0; i<numberOfPLCs; i++) {
plcValA[i] = LittleEndian.getUShort(data, 16+(4*i));
}
}
}
-
+
/**
* Type 4 is quite common. They have 8 bytes of pre-data,
* then 2x 4 byte values.
public static class Type4 extends QCPLCBit {
private Type4(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
-
+
// Grab our 4x pre-data
preData = new int[4];
preData[0] = LittleEndian.getUShort(data, 8+0);
preData[1] = LittleEndian.getUShort(data, 8+2);
preData[2] = LittleEndian.getUShort(data, 8+4);
preData[3] = LittleEndian.getUShort(data, 8+6);
-
+
// And grab the 4 byte values
for(int i=0; i<numberOfPLCs; i++) {
plcValA[i] = LittleEndian.getUInt(data, 16+(8*i));
}
}
}
-
+
/**
* Type 8 is quite common. They have 14 bytes of pre-data,
* then 2x 4 byte values.
public static class Type8 extends QCPLCBit {
private Type8(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
-
+
// Grab our 7x pre-data
preData = new int[7];
preData[0] = LittleEndian.getUShort(data, 8+0);
preData[4] = LittleEndian.getUShort(data, 8+8);
preData[5] = LittleEndian.getUShort(data, 8+10);
preData[6] = LittleEndian.getUShort(data, 8+12);
-
+
// And grab the 4 byte values
for(int i=0; i<numberOfPLCs; i++) {
plcValA[i] = LittleEndian.getUInt(data, 22+(8*i));
}
}
}
-
+
/**
* Type 12 holds hyperlinks, and is very complex.
* There is normally one of these for each text
*/
public static class Type12 extends QCPLCBit {
private String[] hyperlinks;
-
+
private static final int oneStartsAt = 0x4c;
private static final int twoStartsAt = 0x68;
private static final int threePlusIncrement = 22;
-
+
private Type12(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
-
+
// How many hyperlinks do we really have?
// (zero hyperlinks gets numberOfPLCs=1)
if(data.length == 0x34) {
} else {
hyperlinks = new String[numberOfPLCs];
}
-
+
// We have 4 bytes, then the start point of each
// hyperlink, then the end point of the text.
preData = new int[1+numberOfPLCs+1];
for(int i=0; i<preData.length; i++) {
preData[i] = (int)LittleEndian.getUInt(data, 8+(i*4));
}
-
+
// Then we have a whole bunch of stuff, which grows
// with the number of hyperlinks
// For now, we think these are shorts
} else if(numberOfPLCs >= 2) {
until = twoStartsAt + (numberOfPLCs-2)*threePlusIncrement;
}
-
+
plcValA = new long[(until-at)/2];
plcValB = new long[0];
for(int i=0; i<plcValA.length; i++) {
plcValA[i] = LittleEndian.getUShort(data, at+(i*2));
}
-
+
// Finally, we have a series of lengths + hyperlinks
at = until;
for(int i=0; i<hyperlinks.length; i++) {
}
}
}
-
+
/**
- * Returns the number of hyperlinks, which should
+ * Returns the number of hyperlinks, which should
* either be zero, or the number of PLC bits
*/
public int getNumberOfHyperlinks() {
}
/**
* Returns where in the text (in characters) the
- * hyperlink at the given index starts
+ * hyperlink at the given index starts
* applying to.
* This position is relative to the text area that this
* PLCBit applies to.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model.qcbits;
import org.apache.poi.util.StringUtil;
/**
* A Text based bit of Quill Contents
*/
-public class QCTextBit extends QCBit {
+public final class QCTextBit extends QCBit {
public QCTextBit(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
}
data, 0, data.length/2
);
}
-
+
public void setText(String text) {
data = new byte[text.length()*2];
StringUtil.putUnicodeLE(text, data, 0);
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model.qcbits;
/**
* Any Quill Contents bits we don't know
* how to handle explicitly
*/
-public class UnknownQCBit extends QCBit {
+public final class UnknownQCBit extends QCBit {
public UnknownQCBit(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf;
/**
* This class provides helper functions for determining if a
- * PowerPoint document is Encrypted.
+ * PowerPoint document is Encrypted.
* In future, it may also provide Encryption and Decryption
- * functions, but first we'd need to figure out how
+ * functions, but first we'd need to figure out how
* PowerPoint encryption is really done!
*
* @author Nick Burch
*/
-public class EncryptedSlideShow
+public final class EncryptedSlideShow
{
/**
* Check to see if a HSLFSlideShow represents an encrypted
} catch(FileNotFoundException fnfe) {
// Doesn't have encrypted properties
}
-
+
// If they encrypted the document but not the properties,
// it's harder.
// We need to see what the last record pointed to by the
- // first PersistPrtHolder is - if it's a
+ // first PersistPrtHolder is - if it's a
// DocumentEncryptionAtom, then the file's Encrypted
DocumentEncryptionAtom dea = fetchDocumentEncryptionAtom(hss);
if(dea != null) {
}
return false;
}
-
+
/**
* Return the DocumentEncryptionAtom for a HSLFSlideShow, or
* null if there isn't one.
* @return a DocumentEncryptionAtom, or null if there isn't one
*/
public static DocumentEncryptionAtom fetchDocumentEncryptionAtom(HSLFSlideShow hss) {
- // Will be the last Record pointed to by the
+ // Will be the last Record pointed to by the
// first PersistPrtHolder, if there is one
-
+
CurrentUserAtom cua = hss.getCurrentUserAtom();
if(cua.getCurrentEditOffset() != 0) {
// Check it's not past the end of the file
if(cua.getCurrentEditOffset() > hss.getUnderlyingBytes().length) {
throw new CorruptPowerPointFileException("The CurrentUserAtom claims that the offset of last edit details are past the end of the file");
}
-
+
// Grab the details of the UserEditAtom there
// If the record's messed up, we could AIOOB
Record r = null;
if(r == null) { return null; }
if(! (r instanceof UserEditAtom)) { return null; }
UserEditAtom uea = (UserEditAtom)r;
-
+
// Now get the PersistPtrHolder
Record r2 = Record.buildRecordAtOffset(
hss.getUnderlyingBytes(),
);
if(! (r2 instanceof PersistPtrHolder)) { return null; }
PersistPtrHolder pph = (PersistPtrHolder)r2;
-
+
// Now get the last record
int[] slideIds = pph.getKnownSlideIDs();
int maxSlideId = -1;
if(slideIds[i] > maxSlideId) { maxSlideId = slideIds[i]; }
}
if(maxSlideId == -1) { return null; }
-
+
int offset = (
(Integer)pph.getSlideLocationsLookup().get(
new Integer(maxSlideId)
hss.getUnderlyingBytes(),
offset
);
-
+
// If we have a DocumentEncryptionAtom, it'll be this one
if(r3 instanceof DocumentEncryptionAtom) {
return (DocumentEncryptionAtom)r3;
}
}
-
+
return null;
}
}
import org.apache.poi.util.POILogger;
/**
- * This class contains the main functionality for the Powerpoint file
+ * This class contains the main functionality for the Powerpoint file
* "reader". It is only a very basic class for now
*
* @author Nick Burch
}
/**
- * Constructs a Powerpoint document from fileName. Parses the document
+ * Constructs a Powerpoint document from fileName. Parses the document
* and places all the important stuff into data structures.
*
* @param fileName The name of the file to read.
{
this(new FileInputStream(fileName));
}
-
+
/**
- * Constructs a Powerpoint document from an input stream. Parses the
+ * Constructs a Powerpoint document from an input stream. Parses the
* document and places all the important stuff into data structures.
*
* @param inputStream the source of the data
}
/**
- * Constructs a Powerpoint document from a POIFS Filesystem. Parses the
+ * Constructs a Powerpoint document from a POIFS Filesystem. Parses the
* document and places all the important stuff into data structures.
*
* @param filesystem the POIFS FileSystem to read from
{
this(filesystem.getRoot(), filesystem);
}
-
+
/**
- * Constructs a Powerpoint document from a specific point in a
+ * Constructs a Powerpoint document from a specific point in a
* POIFS Filesystem. Parses the document and places all the
* important stuff into data structures.
*
public HSLFSlideShow(DirectoryNode dir, POIFSFileSystem filesystem) throws IOException
{
super(dir, filesystem);
-
+
// First up, grab the "Current User" stream
// We need this before we can detect Encrypted Documents
readCurrentUserStream();
-
- // Next up, grab the data that makes up the
+
+ // Next up, grab the data that makes up the
// PowerPoint stream
readPowerPointStream();
-
+
// Check to see if we have an encrypted document,
// bailing out if we do
boolean encrypted = EncryptedSlideShow.checkIfEncrypted(this);
// Look for Property Streams:
readProperties();
-
+
// Look for any other streams
readOtherStreams();
}
/**
- * Extracts the main PowerPoint document stream from the
- * POI file, ready to be passed
+ * Extracts the main PowerPoint document stream from the
+ * POI file, ready to be passed
*
* @throws IOException
*/
_docstream = new byte[docProps.getSize()];
directory.createDocumentInputStream("PowerPoint Document").read(_docstream);
}
-
+
/**
- * Builds the list of records, based on the contents
+ * Builds the list of records, based on the contents
* of the PowerPoint stream
*/
private void buildRecords()
// <xx xx yy yy zz zz zz zz dd dd dd dd dd dd dd>
// All lengths given exclude the 8 byte record header
// (Data records are known as Atoms)
-
+
// Document should start with:
// 0F 00 E8 03 ## ## ## ##
// (type 1000 = document, info 00 0f is normal, rest is document length)
// 05 00 00 00 0A 00 00 00 xx xx xx
// (the contents of the document atom, not sure what it means yet)
// (records then follow)
-
+
// When parsing a document, look to see if you know about that type
- // of the current record. If you know it's a type that has children,
+ // of the current record. If you know it's a type that has children,
// process the record's data area looking for more records
// If you know about the type and it doesn't have children, either do
// something with the data (eg TextRun) or skip over it
private Record[] read(byte[] docstream, int usrOffset){
ArrayList lst = new ArrayList();
- HashMap offset2id = new HashMap();
+ HashMap offset2id = new HashMap();
while (usrOffset != 0){
UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset);
lst.add(new Integer(usrOffset));
}
/**
- * Find the "Current User" stream, and load it
+ * Find the "Current User" stream, and load it
*/
private void readCurrentUserStream() {
try {
currentUser = new CurrentUserAtom();
}
}
-
+
/**
- * Find any other streams from the filesystem, and load them
+ * Find any other streams from the filesystem, and load them
*/
private void readOtherStreams() {
// Currently, there aren't any
DocumentInputStream is = directory.createDocumentInputStream("Pictures");
is.read(pictstream);
} catch (FileNotFoundException e){
- // Silently catch exceptions if the presentation doesn't
+ // Silently catch exceptions if the presentation doesn't
// contain pictures - will use a null set instead
return;
}
logger.log(POILogger.ERROR, "Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!");
}
}
-
+
pos += imgsize;
}
}
// The list of entries we've written out
List writtenEntries = new ArrayList(1);
-
+
// Write out the Property Streams
writeProperties(outFS, writtenEntries);
currentUser.writeToFS(outFS);
writtenEntries.add("Current User");
-
+
// Write any pictures, into another stream
if (_pictures.size() > 0) {
ByteArrayOutputStream pict = new ByteArrayOutputStream();
);
writtenEntries.add("Pictures");
}
-
+
// If requested, write out any other streams we spot
if(preserveNodes) {
copyNodes(filesystem, outFS, writtenEntries);
_records = r;
return addedAt;
}
-
+
/**
* Add a new picture to this presentation.
*
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.hslf.usermodel.PictureData;
/**
* Represents a bitmap picture data: JPEG or PNG.
* The data is not compressed and the exact file content is written in the stream.
- *
+ *
* @author Yegor Kozlov
*/
public abstract class Bitmap extends PictureData {
-package org.apache.poi.hslf.blip;\r
-\r
-import org.apache.poi.hslf.usermodel.PictureData;\r
-import org.apache.poi.hslf.model.Picture;\r
-import org.apache.poi.util.POILogger;\r
-import org.apache.poi.util.POILogFactory;\r
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-import javax.imageio.ImageIO;\r
-import java.awt.*;\r
-import java.awt.image.BufferedImage;\r
-import java.io.ByteArrayInputStream;\r
-\r
-/**\r
- * Creates BufferedImage using javax.imageio.ImageIO and draws it in the specified graphics.\r
- *\r
- * @author Yegor Kozlov.\r
- */\r
-public class BitmapPainter implements ImagePainter {\r
- protected POILogger logger = POILogFactory.getLogger(this.getClass());\r
-\r
- public void paint(Graphics2D graphics, PictureData pict, Picture parent) {\r
- BufferedImage img;\r
- try {\r
- img = ImageIO.read(new ByteArrayInputStream(pict.getData()));\r
- }\r
- catch (Exception e){\r
- logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + pict.getType());\r
- return;\r
- }\r
- Rectangle anchor = parent.getAnchor();\r
- Image scaledImg = img.getScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);\r
- graphics.drawImage(scaledImg, anchor.x, anchor.y, null);\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.blip;
+
+import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.model.Picture;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
+
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Creates BufferedImage using javax.imageio.ImageIO and draws it in the specified graphics.
+ *
+ * @author Yegor Kozlov.
+ */
+public final class BitmapPainter implements ImagePainter {
+ protected POILogger logger = POILogFactory.getLogger(this.getClass());
+
+ public void paint(Graphics2D graphics, PictureData pict, Picture parent) {
+ BufferedImage img;
+ try {
+ img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
+ }
+ catch (Exception e){
+ logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + pict.getType());
+ return;
+ }
+ Rectangle anchor = parent.getAnchor();
+ Image scaledImg = img.getScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);
+ graphics.drawImage(scaledImg, anchor.x, anchor.y, null);
+ }
+
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.hslf.model.Picture;
/**
* Represents a DIB picture data in a PPT file
- *
+ *
* @author Yegor Kozlov
*/
-public class DIB extends Bitmap {
+public final class DIB extends Bitmap {
/**
* Size of the BITMAPFILEHEADER structure preceding the actual DIB bytes
*/
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.hslf.model.Picture;
/**
* Represents EMF (Windows Enhanced Metafile) picture data.
- *
+ *
* @author Yegor Kozlov
*/
-public class EMF extends Metafile {
+public final class EMF extends Metafile {
/**
* Extract compressed EMF data from a ppt
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.blip;\r
-\r
-import org.apache.poi.hslf.model.Picture;\r
-import org.apache.poi.hslf.usermodel.PictureData;\r
-\r
-import java.awt.*;\r
-\r
-/**\r
- * A common interface for objects that can render ppt picture data.\r
- * <p>\r
- * Subclasses can redefine it and use third-party libraries for actual rendering,\r
- * for example, Bitmaps can be rendered using javax.imageio.* , WMF can be rendered using Apache Batik,\r
- * PICT can be rendered using Apple QuickTime API for Java, etc.\r
- * </p>\r
- *\r
- * A typical usage is as follows:\r
- * <code>\r
- * public WMFPaiter implements ImagePainter{\r
- * public void paint(Graphics2D graphics, PictureData pict, Picture parent){\r
- * DataInputStream is = new DataInputStream(new ByteArrayInputStream(pict.getData()));\r
- * org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore wmfStore =\r
- * new org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore();\r
- * try {\r
- * wmfStore.read(is);\r
- * } catch (IOException e){\r
- * return;\r
- * }\r
- *\r
- * Rectangle anchor = parent.getAnchor();\r
- * float scale = (float)anchor.width/wmfStore.getWidthPixels();\r
- *\r
- * org.apache.batik.transcoder.wmf.tosvg.WMFPainter painter =\r
- * new org.apache.batik.transcoder.wmf.tosvg.WMFPainter(wmfStore, 0, 0, scale);\r
- * graphics.translate(anchor.x, anchor.y);\r
- * painter.paint(graphics);\r
- * }\r
- * }\r
- * PictureData.setImagePainter(Picture.WMF, new WMFPaiter());\r
- * ...\r
- * </code>\r
- * Subsequent calls of Slide.draw(Graphics gr) will use WMFPaiter for WMF images.\r
- *\r
- * @author Yegor Kozlov.\r
- */\r
-public interface ImagePainter {\r
-\r
- /**\r
- * Paints the specified picture data\r
- *\r
- * @param graphics the graphics to paintb into\r
- * @param pict the data to paint\r
- * @param parent the shapes that owns the picture data\r
- */\r
- public void paint(Graphics2D graphics, PictureData pict, Picture parent);\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.blip;
+
+import org.apache.poi.hslf.model.Picture;
+import org.apache.poi.hslf.usermodel.PictureData;
+
+import java.awt.*;
+
+/**
+ * A common interface for objects that can render ppt picture data.
+ * <p>
+ * Subclasses can redefine it and use third-party libraries for actual rendering,
+ * for example, Bitmaps can be rendered using javax.imageio.* , WMF can be rendered using Apache Batik,
+ * PICT can be rendered using Apple QuickTime API for Java, etc.
+ * </p>
+ *
+ * A typical usage is as follows:
+ * <code>
+ * public WMFPaiter implements ImagePainter{
+ * public void paint(Graphics2D graphics, PictureData pict, Picture parent){
+ * DataInputStream is = new DataInputStream(new ByteArrayInputStream(pict.getData()));
+ * org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore wmfStore =
+ * new org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore();
+ * try {
+ * wmfStore.read(is);
+ * } catch (IOException e){
+ * return;
+ * }
+ *
+ * Rectangle anchor = parent.getAnchor();
+ * float scale = (float)anchor.width/wmfStore.getWidthPixels();
+ *
+ * org.apache.batik.transcoder.wmf.tosvg.WMFPainter painter =
+ * new org.apache.batik.transcoder.wmf.tosvg.WMFPainter(wmfStore, 0, 0, scale);
+ * graphics.translate(anchor.x, anchor.y);
+ * painter.paint(graphics);
+ * }
+ * }
+ * PictureData.setImagePainter(Picture.WMF, new WMFPaiter());
+ * ...
+ * </code>
+ * Subsequent calls of Slide.draw(Graphics gr) will use WMFPaiter for WMF images.
+ *
+ * @author Yegor Kozlov.
+ */
+public interface ImagePainter {
+
+ /**
+ * Paints the specified picture data
+ *
+ * @param graphics the graphics to paintb into
+ * @param pict the data to paint
+ * @param parent the shapes that owns the picture data
+ */
+ public void paint(Graphics2D graphics, PictureData pict, Picture parent);
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.hslf.model.Picture;
/**
* Represents a JPEG picture data in a PPT file
- *
+ *
* @author Yegor Kozlov
*/
-public class JPEG extends Bitmap {
+public final class JPEG extends Bitmap {
/**
* @return type of this picture
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.util.LittleEndian;
/**
* Represents a metafile picture which can be one of the following types: EMF, WMF, or PICT.
* A metafile is stored compressed using the ZIP deflate/inflate algorithm.
- *
+ *
* @author Yegor Kozlov
*/
public abstract class Metafile extends PictureData {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.hslf.model.Picture;
/**
* Represents Macintosh PICT picture data.
- *
+ *
* @author Yegor Kozlov
*/
-public class PICT extends Metafile {
+public final class PICT extends Metafile {
public PICT(){
super();
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.hslf.model.Picture;
/**
* Represents a PNG picture data in a PPT file
- *
+ *
* @author Yegor Kozlov
*/
-public class PNG extends Bitmap {
+public final class PNG extends Bitmap {
/**
* @return PNG data
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.blip;
import org.apache.poi.util.LittleEndian;
/**
* Represents a WMF (Windows Metafile) picture data.
- *
+ *
* @author Yegor Kozlov
*/
-public class WMF extends Metafile {
+public final class WMF extends Metafile {
/**
* Extract compressed WMF data from a ppt
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
* Having found them, it sees if they have DDF Textbox records, and if so,
* searches those for text. Prints out any text it finds
*/
-public class PPDrawingTextListing {
+public final class PPDrawingTextListing {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Need to give a filename");
* @author Yegor Kozlov
*/
-public class PPTXMLDump {
+public final class PPTXMLDump {
public static final int HEADER_SIZE = 8; //size of the record header
public static final int PICT_HEADER_SIZE = 25; //size of the picture header
public final static String PPDOC_ENTRY = "PowerPoint Document";
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.HSLFSlideShow;
* Having found them, it sees if they have any SlideListWithTexts,
* and reports how many, and what sorts of things they contain
*/
-public class SLWTListing {
+public final class SLWTListing {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Need to give a filename");
if(records[i] instanceof Document) {
Document doc = (Document)records[i];
SlideListWithText[] slwts = doc.getSlideListWithTexts();
-
+
System.out.println("Document at " + i + " had " + slwts.length + " SlideListWithTexts");
if(slwts.length == 0) {
System.err.println("** Warning: Should have had at least 1! **");
if(slwts.length > 3) {
System.err.println("** Warning: Shouldn't have more than 3!");
}
-
+
// Check the SLWTs contain what we'd expect
for(int j=0; j<slwts.length; j++) {
SlideListWithText slwt = slwts[j];
Record[] children = slwt.getChildRecords();
-
+
System.out.println(" - SLWT at " + j + " had " + children.length + " children:");
-
+
// Should only have SlideAtomSets if the second one
int numSAS = slwt.getSlideAtomsSets().length;
if(j == 1) {
System.err.println(" ** SLWT " + j + " had " + numSAS + " SlideAtomSets! (expected 0)");
}
}
-
+
// Report the first 5 children, to give a flavour
int upTo = 5;
if(children.length < 5) { upTo = children.length; }
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
* Having found them, it sees if they have any text, and prints out
* what it finds.
*/
-public class SLWTTextListing {
+public final class SLWTTextListing {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Need to give a filename");
System.out.println("Found SLWT at pos " + j + " in the Document at " + i);
System.out.println(" Has " + docChildren[j].getChildRecords().length + " children");
- // Grab the SlideAtomSet's, which contain
+ // Grab the SlideAtomSet's, which contain
// a SlidePersistAtom and then a bunch of text
// + related records
SlideListWithText slwt = (SlideListWithText)docChildren[j];
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
* what they are all about. Useful for checking the matching between
* Slides, Master Slides and Notes
*/
-public class SlideAndNotesAtomListing {
+public final class SlideAndNotesAtomListing {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Need to give a filename");
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
* in them, and displays them, so you can try to guess what they
* all mean
*/
-public class SlideIdListing {
+public final class SlideIdListing {
private static byte[] fileContents;
public static void main(String[] args) throws Exception {
// Create the slideshow object, for normal working with
HSLFSlideShow hss = new HSLFSlideShow(args[0]);
SlideShow ss = new SlideShow(hss);
-
+
// Grab the base contents
fileContents = hss.getUnderlyingBytes();
Record[] records = hss.getRecords();
Record[] latestRecords = ss.getMostRecentCoreRecords();
-
+
// Grab any records that interest us
Document document = null;
for(int i=0; i<latestRecords.length; i++) {
document = (Document)latestRecords[i];
}
}
-
+
System.out.println("");
-
-
+
+
// Look for SlidePersistAtoms, and report what they have to
// say about possible slide IDs
SlideListWithText[] slwts = document.getSlideListWithTexts();
}
}
}
-
+
System.out.println("");
-
+
// Look for latest core records that are slides or notes
for(int i=0; i<latestRecords.length; i++) {
if(latestRecords[i] instanceof Slide) {
}
System.out.println("");
-
+
// Find any persist ones first
int pos = 0;
for(int i=0; i<records.length; i++) {
long rlen = LittleEndian.getUInt(fileContents, pos+4);
Record r = Record.createRecordForType(type,fileContents,pos,(int)rlen+8);
-
+
return r;
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
* To figure out what things are, and if they are atoms or not, used the
* list in hslf.record.RecordTypes
*
- * To peek inside PPDrawings, which hold Escher drawings, we use the
+ * To peek inside PPDrawings, which hold Escher drawings, we use the
* DDF package from POI (but we can fake it by using the Escher listings
* from hslf.record.RecordTypes also)
- *
+ *
* @author Nick Burch
*/
-public class SlideShowDumper
+public final class SlideShowDumper
{
private InputStream istream;
private POIFSFileSystem filesystem;
/**
- * Constructs a Powerpoint dump from fileName. Parses the document
+ * Constructs a Powerpoint dump from fileName. Parses the document
* and dumps out the contents
*
* @param fileName The name of the file to read.
{
this(new FileInputStream(fileName));
}
-
+
/**
- * Constructs a Powerpoint dump from an input stream. Parses the
+ * Constructs a Powerpoint dump from an input stream. Parses the
* document and dumps out the contents
*
* @param inputStream the source of the data
}
/**
- * Constructs a Powerpoint dump from a POIFS Filesystem. Parses the
+ * Constructs a Powerpoint dump from a POIFS Filesystem. Parses the
* document and dumps out the contents
*
* @param filesystem the POIFS FileSystem to read from
// (type 1001 = document atom, info 00 01 normal, 28 bytes long)
// When parsing a document, look to see if you know about that type
- // of the current record. If you know it's a type that has children,
+ // of the current record. If you know it's a type that has children,
// process the record's data area looking for more records
// If you know about the type and it doesn't have children, either do
// something with the data (eg TextRun) or skip over it
boolean escher = false;
int ndx=0;
- for (; ndx<args.length; ndx++) {
+ for (; ndx<args.length; ndx++) {
if (!args[ndx].substring(0,1).equals("-"))
break;
-
+
if (args[ndx].equals("-escher")) {
escher = true;
} else if (args[ndx].equals("-verbose")) {
return;
}
}
-
+
// parsed any options, expect exactly one remaining arg (filename)
if (ndx != args.length-1) {
printUsage();
return;
}
-
+
filename = args[ndx];
SlideShowRecordDumper foo = new SlideShowRecordDumper(filename, verbose, escher);
foo.printDump();
}
-
+
public static void printUsage() {
System.err.println("Usage: SlideShowRecordDumper [-escher] [-verbose] <filename>");
System.err.println("Valid Options:");
/**
- * Constructs a Powerpoint dump from fileName. Parses the document
+ * Constructs a Powerpoint dump from fileName. Parses the document
* and dumps out the contents
*
* @param fileName The name of the file to read.
public int getDiskLen(Record r) throws IOException {
if (r == null) return 0;
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
public String getPrintableRecordContents(Record r) throws IOException {
if (r==null) return "<<null>>";
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
r.writeOut(baos);
byte[] b = baos.toByteArray();
return HexDump.dump(b, 0, 0);
}
-
+
public String printEscherRecord( EscherRecord er ) {
String nl = System.getProperty( "line.separator" );
StringBuffer buf = new StringBuffer();
buf.append(printEscherContainerRecord( (EscherContainerRecord)er ));
} else if (er instanceof EscherTextboxRecord) {
buf.append("EscherTextboxRecord:" + nl);
-
+
EscherTextboxWrapper etw = new EscherTextboxWrapper((EscherTextboxRecord)er);
Record children[] = etw.getChildRecords();
for (int j=0; j<children.length; j++) {
if (children[j] instanceof StyleTextPropAtom) {
-
+
// need preceding Text[Chars|Bytes]Atom to initialize the data structure
- if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
+ if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
children[j-1] instanceof TextBytesAtom)) {
-
- int size = (children[j-1] instanceof TextCharsAtom) ?
- ((TextCharsAtom)children[j-1]).getText().length() :
+
+ int size = (children[j-1] instanceof TextCharsAtom) ?
+ ((TextCharsAtom)children[j-1]).getText().length() :
((TextBytesAtom)children[j-1]).getText().length();
-
+
StyleTextPropAtom tsp = (StyleTextPropAtom)children[j];
tsp.setParentTextSize(size);
-
+
} else {
buf.append("Error! Couldn't find preceding TextAtom for style\n");
}
-
+
buf.append(children[j].toString() + nl );
- } else {
+ } else {
buf.append(children[j].toString() + nl );
}
}
} else {
buf.append( er.toString() );
- }
+ }
return buf.toString();
}
-
+
public String printEscherContainerRecord( EscherContainerRecord ecr ) {
String indent = "";
-
+
String nl = System.getProperty( "line.separator" );
StringBuffer children = new StringBuffer();
EscherRecord record = iterator.next();
children.append(newIndent + "Child " + count + ":" + nl);
-
+
children.append( printEscherRecord(record) );
count++;
}
- return
+ return
indent + ecr.getClass().getName() + " (" + ecr.getRecordName() + "):" + nl +
indent + " isContainer: " + ecr.isContainerRecord() + nl +
indent + " options: 0x" + HexDump.toHex( ecr.getOptions() ) + nl +
// Figure out how big it is
int len = getDiskLen(r);
-
+
// Grab the type as hex
String hexType = makeHex((int)r.getRecordType(),4);
String rHexType = reverseHex(hexType);
EscherRecord er = factory.createRecord(b, 0);
er.fillFields(b, 0, factory);
-
+
System.out.println( printEscherRecord( er ) );
-
+
} else if(optVerbose && r.getChildRecords() == null) {
String recData = getPrintableRecordContents(r);
System.out.println(ind + recData );
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
* Uses record level code to locate StyleTextPropAtom entries.
* Having found them, it shows the contents
*/
-public class TextStyleListing {
+public final class TextStyleListing {
public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Need to give a filename");
System.out.println(" Characters covered is " + tpc.getCharactersCovered());
showTextProps(tpc);
}
-
+
LinkedList charStyles = stpa.getCharacterStyles();
System.out.println("Contains " + charStyles.size() + " character styles:");
for(int i=0; i<charStyles.size(); i++) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
* persistence related atoms. Tries to match them together, to help
* illuminate quite what all the offsets mean
*/
-public class UserEditAndPersistListing {
+public final class UserEditAndPersistListing {
private static byte[] fileContents;
public static void main(String[] args) throws Exception {
CurrentUserAtom cua = ss.getCurrentUserAtom();
System.out.println("Checking Current User Atom");
System.out.println(" Thinks the CurrentEditOffset is " + cua.getCurrentEditOffset());
-
+
System.out.println("");
}
long rlen = LittleEndian.getUInt(fileContents, pos+4);
Record r = Record.createRecordForType(type,fileContents,pos,(int)rlen+8);
-
+
return r;
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.exceptions;
* @author Nick Burch
*/
-public class CorruptPowerPointFileException extends IllegalStateException
+public final class CorruptPowerPointFileException extends IllegalStateException
{
public CorruptPowerPointFileException(String s) {
super(s);
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.exceptions;
import org.apache.poi.EncryptedDocumentException;
* This exception is thrown when we try to open a PowerPoint file, and
* discover that it is encrypted
*/
-public class EncryptedPowerPointFileException extends EncryptedDocumentException
+public final class EncryptedPowerPointFileException extends EncryptedDocumentException
{
public EncryptedPowerPointFileException(String s) {
super(s);
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.exceptions;\r
-\r
-/**\r
- * A generic exception that can be thrown by HSLF classes\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class HSLFException extends RuntimeException {\r
-\r
- public HSLFException() {\r
- super();\r
- }\r
-\r
- public HSLFException(String message) {\r
- super(message);\r
- }\r
-\r
- public HSLFException(String message, Throwable cause) {\r
- super(message, cause);\r
- }\r
-\r
- public HSLFException(Throwable cause) {\r
- super(cause);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.exceptions;
+
+/**
+ * A generic exception that can be thrown by HSLF classes
+ *
+ * @author Yegor Kozlov
+ */
+public final class HSLFException extends RuntimeException {
+
+ public HSLFException() {
+ super();
+ }
+
+ public HSLFException(String message) {
+ super(message);
+ }
+
+ public HSLFException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public HSLFException(Throwable cause) {
+ super(cause);
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.exceptions;
* @author Nick Burch
*/
-public class InvalidRecordFormatException extends Exception
+public final class InvalidRecordFormatException extends Exception
{
public InvalidRecordFormatException(String s) {
super(s);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.extractor;
import org.apache.poi.hslf.usermodel.SlideShow;
*
* @author Yegor Kozlov
*/
-public class ImageExtractor {
+public final class ImageExtractor {
public static void main(String args[]) throws IOException {
if (args.length < 1) {
System.err.println("Usage:");
private HSLFSlideShow _hslfshow;
private SlideShow _show;
private Slide[] _slides;
-
+
private boolean slidesByDefault = true;
private boolean notesByDefault = false;
private boolean commentsByDefault = false;
}
/**
- * Fetches all the slide text from the slideshow,
+ * Fetches all the slide text from the slideshow,
* but not the notes, unless you've called
* setSlidesByDefault() and setNotesByDefault()
* to change this
return getText(getSlideText, getNoteText, commentsByDefault);
}
public String getText(boolean getSlideText, boolean getNoteText, boolean getCommentText) {
- StringBuffer ret = new StringBuffer();
+ StringBuffer ret = new StringBuffer();
if(getSlideText) {
for(int i=0; i<_slides.length; i++) {
Slide slide = _slides[i];
-
+
// Slide header, if set
HeadersFooters hf = slide.getHeadersFooters();
if(hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
ret.append(hf.getHeaderText() + "\n");
}
-
+
// Slide text
TextRun[] runs = slide.getTextRuns();
for(int j=0; j<runs.length; j++) {
}
}
}
-
+
// Slide footer, if set
if(hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
ret.append(hf.getFooterText() + "\n");
}
-
+
// Comments, if requested and present
if(getCommentText) {
Comment[] comments = slide.getComments();
for(int j=0; j<comments.length; j++) {
ret.append(
- comments[j].getAuthor() +
+ comments[j].getAuthor() +
" - " +
- comments[j].getText() +
+ comments[j].getText() +
"\n"
);
}
// but ensure no duplicates
HashSet seenNotes = new HashSet();
HeadersFooters hf = _show.getNotesHeadersFooters();
-
+
for(int i=0; i<_slides.length; i++) {
Notes notes = _slides[i].getNotesSheet();
if(notes == null) { continue; }
Integer id = new Integer(notes._getSheetNumber());
if(seenNotes.contains(id)) { continue; }
seenNotes.add(id);
-
+
// Repeat the Notes header, if set
if(hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
ret.append(hf.getHeaderText() + "\n");
}
}
}
-
+
// Repeat the notes footer, if set
if(hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
ret.append(hf.getFooterText() + "\n");
return ret.toString();
}
-}
\ No newline at end of file
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.extractor;
* This class will get all the text from a Powerpoint Document, including
* all the bits you didn't want, and in a somewhat random order, but will
* do it very fast.
- * The class ignores most of the hslf classes, and doesn't use
+ * The class ignores most of the hslf classes, and doesn't use
* HSLFSlideShow. Instead, it just does a very basic scan through the
* file, grabbing all the text records as it goes. It then returns the
* text, either as a single string, or as a vector of all the individual
* strings.
- * Because of how it works, it will return a lot of "crud" text that you
+ * Because of how it works, it will return a lot of "crud" text that you
* probably didn't want! It will return text from master slides. It will
* return duplicate text, and some mangled text (powerpoint files often
* have duplicate copies of slide text in them). You don't get any idea
* @author Nick Burch
*/
-public class QuickButCruddyTextExtractor
+public final class QuickButCruddyTextExtractor
{
private POIFSFileSystem fs;
private InputStream is;
TextCharsAtom tca = (TextCharsAtom)Record.createRecordForType(type, pptContents, startPos, len+8);
trun = new TextRun((TextHeaderAtom)null,tca,(StyleTextPropAtom)null);
}
-
+
// CString (doesn't go via a TextRun)
if(type == RecordTypes.CString.typeID) {
CString cs = (CString)Record.createRecordForType(type, pptContents, startPos, len+8);
String text = cs.getText();
-
+
// Ignore the ones we know to be rubbish
if(text.equals("___PPT10")) {
} else if(text.equals("Default Design")) {
if(trun != null) {
textV.add(trun.getText());
}
-
+
// Wind on by the atom length, and check we're not at the end
int newPos = (startPos + 8 + len);
- if(newPos > (pptContents.length - 8)) {
+ if(newPos > (pptContents.length - 8)) {
newPos = -1;
}
return newPos;
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.hslf.record.*;\r
-import org.apache.poi.hslf.exceptions.HSLFException;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.UnsupportedEncodingException;\r
-import java.util.Iterator;\r
-\r
-/**\r
- * Represents an ActiveX control in a PowerPoint document.\r
- *\r
- * TODO: finish\r
- * @author Yegor Kozlov\r
- */\r
-public final class ActiveXShape extends Picture {\r
- public static final int DEFAULT_ACTIVEX_THUMBNAIL = -1;\r
-\r
- /**\r
- * Create a new <code>Picture</code>\r
- *\r
- * @param pictureIdx the index of the picture\r
- */\r
- public ActiveXShape(int movieIdx, int pictureIdx){\r
- super(pictureIdx, null);\r
- setActiveXIndex(movieIdx);\r
- }\r
-\r
- /**\r
- * Create a <code>Picture</code> object\r
- *\r
- * @param escherRecord the <code>EscherSpContainer</code> record which holds information about\r
- * this picture in the <code>Slide</code>\r
- * @param parent the parent shape of this picture\r
- */\r
- protected ActiveXShape(EscherContainerRecord escherRecord, Shape parent){\r
- super(escherRecord, parent);\r
- }\r
-\r
- /**\r
- * Create a new Placeholder and initialize internal structures\r
- *\r
- * @return the created <code>EscherContainerRecord</code> which holds shape data\r
- */\r
- protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {\r
- _escherContainer = super.createSpContainer(idx, isChild);\r
-\r
- EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);\r
- spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE | EscherSpRecord.FLAG_OLESHAPE);\r
-\r
- setShapeType(ShapeTypes.HostControl);\r
- setEscherProperty(EscherProperties.BLIP__PICTUREID, idx);\r
- setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);\r
- setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008);\r
- setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);\r
- setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, -1);\r
-\r
- EscherClientDataRecord cldata = new EscherClientDataRecord();\r
- cldata.setOptions((short)0xF);\r
- _escherContainer.addChildRecord(cldata); // TODO unit test to prove getChildRecords().add is wrong\r
-\r
- OEShapeAtom oe = new OEShapeAtom();\r
-\r
- //convert hslf into ddf\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- try {\r
- oe.writeOut(out);\r
- } catch(Exception e){\r
- throw new HSLFException(e);\r
- }\r
- cldata.setRemainingData(out.toByteArray());\r
-\r
- return _escherContainer;\r
- }\r
-\r
- /**\r
- * Assign a control to this shape\r
- *\r
- * @see org.apache.poi.hslf.usermodel.SlideShow#addMovie(String, int)\r
- * @param idx the index of the movie\r
- */\r
- public void setActiveXIndex(int idx){\r
- EscherContainerRecord spContainer = getSpContainer();\r
- for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {\r
- EscherRecord obj = it.next();\r
- if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {\r
- EscherClientDataRecord clientRecord = (EscherClientDataRecord)obj;\r
- byte[] recdata = clientRecord.getRemainingData();\r
- LittleEndian.putInt(recdata, 8, idx);\r
- }\r
- }\r
- }\r
-\r
- public int getControlIndex(){\r
- int idx = -1;\r
- OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);\r
- if(oe != null) idx = oe.getOptions();\r
- return idx;\r
- }\r
-\r
- /**\r
- * Set a property of this ActiveX control\r
- * @param key\r
- * @param value\r
- */\r
- public void setProperty(String key, String value){\r
-\r
- }\r
-\r
- /**\r
- * Document-level container that specifies information about an ActiveX control\r
- *\r
- * @return container that specifies information about an ActiveX control\r
- */\r
- public ExControl getExControl(){\r
- int idx = getControlIndex();\r
- ExControl ctrl = null;\r
- Document doc = getSheet().getSlideShow().getDocumentRecord();\r
- ExObjList lst = (ExObjList)doc.findFirstOfType(RecordTypes.ExObjList.typeID);\r
- if(lst != null){\r
- Record[] ch = lst.getChildRecords();\r
- for (int i = 0; i < ch.length; i++) {\r
- if(ch[i] instanceof ExControl){\r
- ExControl c = (ExControl)ch[i];\r
- if(c.getExOleObjAtom().getObjID() == idx){\r
- ctrl = c;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- return ctrl;\r
- }\r
-\r
- protected void afterInsert(Sheet sheet){\r
- ExControl ctrl = getExControl();\r
- ctrl.getExControlAtom().setSlideId(sheet._getSheetNumber());\r
-\r
- try {\r
- String name = ctrl.getProgId() + "-" + getControlIndex();\r
- byte[] data = (name + '\u0000').getBytes("UTF-16LE");\r
- EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data);\r
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- opt.addEscherProperty(prop);\r
- } catch (UnsupportedEncodingException e){\r
- throw new HSLFException(e);\r
- }\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.util.LittleEndian;
+
+import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+
+/**
+ * Represents an ActiveX control in a PowerPoint document.
+ *
+ * TODO: finish
+ * @author Yegor Kozlov
+ */
+public final class ActiveXShape extends Picture {
+ public static final int DEFAULT_ACTIVEX_THUMBNAIL = -1;
+
+ /**
+ * Create a new <code>Picture</code>
+ *
+ * @param pictureIdx the index of the picture
+ */
+ public ActiveXShape(int movieIdx, int pictureIdx){
+ super(pictureIdx, null);
+ setActiveXIndex(movieIdx);
+ }
+
+ /**
+ * Create a <code>Picture</code> object
+ *
+ * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
+ * this picture in the <code>Slide</code>
+ * @param parent the parent shape of this picture
+ */
+ protected ActiveXShape(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+ }
+
+ /**
+ * Create a new Placeholder and initialize internal structures
+ *
+ * @return the created <code>EscherContainerRecord</code> which holds shape data
+ */
+ protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
+ _escherContainer = super.createSpContainer(idx, isChild);
+
+ EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+ spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE | EscherSpRecord.FLAG_OLESHAPE);
+
+ setShapeType(ShapeTypes.HostControl);
+ setEscherProperty(EscherProperties.BLIP__PICTUREID, idx);
+ setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+ setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008);
+ setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
+ setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, -1);
+
+ EscherClientDataRecord cldata = new EscherClientDataRecord();
+ cldata.setOptions((short)0xF);
+ _escherContainer.addChildRecord(cldata); // TODO unit test to prove getChildRecords().add is wrong
+
+ OEShapeAtom oe = new OEShapeAtom();
+
+ //convert hslf into ddf
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ oe.writeOut(out);
+ } catch(Exception e){
+ throw new HSLFException(e);
+ }
+ cldata.setRemainingData(out.toByteArray());
+
+ return _escherContainer;
+ }
+
+ /**
+ * Assign a control to this shape
+ *
+ * @see org.apache.poi.hslf.usermodel.SlideShow#addMovie(String, int)
+ * @param idx the index of the movie
+ */
+ public void setActiveXIndex(int idx){
+ EscherContainerRecord spContainer = getSpContainer();
+ for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext();) {
+ EscherRecord obj = it.next();
+ if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
+ EscherClientDataRecord clientRecord = (EscherClientDataRecord)obj;
+ byte[] recdata = clientRecord.getRemainingData();
+ LittleEndian.putInt(recdata, 8, idx);
+ }
+ }
+ }
+
+ public int getControlIndex(){
+ int idx = -1;
+ OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
+ if(oe != null) idx = oe.getOptions();
+ return idx;
+ }
+
+ /**
+ * Set a property of this ActiveX control
+ * @param key
+ * @param value
+ */
+ public void setProperty(String key, String value){
+
+ }
+
+ /**
+ * Document-level container that specifies information about an ActiveX control
+ *
+ * @return container that specifies information about an ActiveX control
+ */
+ public ExControl getExControl(){
+ int idx = getControlIndex();
+ ExControl ctrl = null;
+ Document doc = getSheet().getSlideShow().getDocumentRecord();
+ ExObjList lst = (ExObjList)doc.findFirstOfType(RecordTypes.ExObjList.typeID);
+ if(lst != null){
+ Record[] ch = lst.getChildRecords();
+ for (int i = 0; i < ch.length; i++) {
+ if(ch[i] instanceof ExControl){
+ ExControl c = (ExControl)ch[i];
+ if(c.getExOleObjAtom().getObjID() == idx){
+ ctrl = c;
+ break;
+ }
+ }
+ }
+ }
+ return ctrl;
+ }
+
+ protected void afterInsert(Sheet sheet){
+ ExControl ctrl = getExControl();
+ ctrl.getExControlAtom().setSlideId(sheet._getSheetNumber());
+
+ try {
+ String name = ctrl.getProgId() + "-" + getControlIndex();
+ byte[] data = (name + '\u0000').getBytes("UTF-16LE");
+ EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data);
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+ opt.addEscherProperty(prop);
+ } catch (UnsupportedEncodingException e){
+ throw new HSLFException(e);
+ }
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.EscherProperties;\r
-\r
-import java.awt.geom.*;\r
-\r
-/**\r
- * Stores definition of auto-shapes.\r
- * See the Office Drawing 97-2007 Binary Format Specification for details.\r
- *\r
- * TODO: follow the spec and define all the auto-shapes\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class AutoShapes {\r
- protected static ShapeOutline[] shapes;\r
-\r
-\r
- /**\r
- * Return shape outline by shape type\r
- * @param type shape type see {@link ShapeTypes}\r
- *\r
- * @return the shape outline\r
- */\r
- public static ShapeOutline getShapeOutline(int type){\r
- ShapeOutline outline = shapes[type];\r
- return outline;\r
- }\r
-\r
- /**\r
- * Auto-shapes are defined in the [0,21600] coordinate system.\r
- * We need to transform it into normal slide coordinates\r
- *\r
- */\r
- public static java.awt.Shape transform(java.awt.Shape outline, Rectangle2D anchor){\r
- AffineTransform at = new AffineTransform();\r
- at.translate(anchor.getX(), anchor.getY());\r
- at.scale(\r
- 1.0f/21600*anchor.getWidth(),\r
- 1.0f/21600*anchor.getHeight()\r
- );\r
- return at.createTransformedShape(outline);\r
- }\r
-\r
- static {\r
- shapes = new ShapeOutline[255];\r
-\r
- shapes[ShapeTypes.Rectangle] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- Rectangle2D path = new Rectangle2D.Float(0, 0, 21600, 21600);\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.RoundRectangle] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
- RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval);\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Ellipse] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- Ellipse2D path = new Ellipse2D.Float(0, 0, 21600, 21600);\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Diamond] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(10800, 0);\r
- path.lineTo(21600, 10800);\r
- path.lineTo(10800, 21600);\r
- path.lineTo(0, 10800);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- //m@0,l,21600r21600\r
- shapes[ShapeTypes.IsocelesTriangle] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 10800);\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(0, 21600);\r
- path.lineTo(21600, 21600);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.RightTriangle] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(0, 0);\r
- path.lineTo(21600, 21600);\r
- path.lineTo(0, 21600);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Parallelogram] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(21600, 0);\r
- path.lineTo(21600 - adjval, 21600);\r
- path.lineTo(0, 21600);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Trapezoid] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(0, 0);\r
- path.lineTo(adjval, 21600);\r
- path.lineTo(21600 - adjval, 21600);\r
- path.lineTo(21600, 0);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Hexagon] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(21600 - adjval, 0);\r
- path.lineTo(21600, 10800);\r
- path.lineTo(21600 - adjval, 21600);\r
- path.lineTo(adjval, 21600);\r
- path.lineTo(0, 10800);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Octagon] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 6326);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(21600 - adjval, 0);\r
- path.lineTo(21600, adjval);\r
- path.lineTo(21600, 21600-adjval);\r
- path.lineTo(21600-adjval, 21600);\r
- path.lineTo(adjval, 21600);\r
- path.lineTo(0, 21600-adjval);\r
- path.lineTo(0, adjval);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Plus] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(21600 - adjval, 0);\r
- path.lineTo(21600 - adjval, adjval);\r
- path.lineTo(21600, adjval);\r
- path.lineTo(21600, 21600-adjval);\r
- path.lineTo(21600-adjval, 21600-adjval);\r
- path.lineTo(21600-adjval, 21600);\r
- path.lineTo(adjval, 21600);\r
- path.lineTo(adjval, 21600-adjval);\r
- path.lineTo(0, 21600-adjval);\r
- path.lineTo(0, adjval);\r
- path.lineTo(adjval, adjval);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Pentagon] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(10800, 0);\r
- path.lineTo(21600, 8259);\r
- path.lineTo(21600 - 4200, 21600);\r
- path.lineTo(4200, 21600);\r
- path.lineTo(0, 8259);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.DownArrow] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m0@0 l@1@0 @1,0 @2,0 @2@0,21600@0,10800,21600xe\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);\r
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(0, adjval);\r
- path.lineTo(adjval2, adjval);\r
- path.lineTo(adjval2, 0);\r
- path.lineTo(21600-adjval2, 0);\r
- path.lineTo(21600-adjval2, adjval);\r
- path.lineTo(21600, adjval);\r
- path.lineTo(10800, 21600);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.UpArrow] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m0@0 l@1@0 @1,21600@2,21600@2@0,21600@0,10800,xe\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(0, adjval);\r
- path.lineTo(adjval2, adjval);\r
- path.lineTo(adjval2, 21600);\r
- path.lineTo(21600-adjval2, 21600);\r
- path.lineTo(21600-adjval2, adjval);\r
- path.lineTo(21600, adjval);\r
- path.lineTo(10800, 0);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Arrow] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m@0, l@0@1 ,0@1,0@2@0@2@0,21600,21600,10800xe\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);\r
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(adjval, adjval2);\r
- path.lineTo(0, adjval2);\r
- path.lineTo(0, 21600-adjval2);\r
- path.lineTo(adjval, 21600-adjval2);\r
- path.lineTo(adjval, 21600);\r
- path.lineTo(21600, 10800);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.LeftArrow] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m@0, l@0@1,21600@1,21600@2@0@2@0,21600,,10800xe\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(adjval, 0);\r
- path.lineTo(adjval, adjval2);\r
- path.lineTo(21600, adjval2);\r
- path.lineTo(21600, 21600-adjval2);\r
- path.lineTo(adjval, 21600-adjval2);\r
- path.lineTo(adjval, 21600);\r
- path.lineTo(0, 10800);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.Can] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m10800,qx0@1l0@2qy10800,21600,21600@2l21600@1qy10800,xem0@1qy10800@0,21600@1nfe\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);\r
-\r
- GeneralPath path = new GeneralPath();\r
-\r
- path.append(new Arc2D.Float(0, 0, 21600, adjval, 0, 180, Arc2D.OPEN), false);\r
- path.moveTo(0, adjval/2);\r
-\r
- path.lineTo(0, 21600 - adjval/2);\r
- path.closePath();\r
-\r
- path.append(new Arc2D.Float(0, 21600 - adjval, 21600, adjval, 180, 180, Arc2D.OPEN), false);\r
- path.moveTo(21600, 21600 - adjval/2);\r
-\r
- path.lineTo(21600, adjval/2);\r
- path.append(new Arc2D.Float(0, 0, 21600, adjval, 180, 180, Arc2D.OPEN), false);\r
- path.moveTo(0, adjval/2);\r
- path.closePath();\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.LeftBrace] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m21600,qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);\r
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(21600, 0);\r
-\r
- path.append(new Arc2D.Float(10800, 0, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);\r
- path.moveTo(10800, adjval);\r
-\r
- path.lineTo(10800, adjval2 - adjval);\r
-\r
- path.append(new Arc2D.Float(-10800, adjval2 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);\r
- path.moveTo(0, adjval2);\r
-\r
- path.append(new Arc2D.Float(-10800, adjval2, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);\r
- path.moveTo(10800, adjval2 + adjval);\r
-\r
- path.lineTo(10800, 21600 - adjval);\r
-\r
- path.append(new Arc2D.Float(10800, 21600 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);\r
-\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.RightBrace] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- //m,qx10800@0 l10800@2qy21600@11,10800@3l10800@1qy,21600e\r
- int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);\r
- int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);\r
-\r
- GeneralPath path = new GeneralPath();\r
- path.moveTo(0, 0);\r
-\r
- path.append(new Arc2D.Float(-10800, 0, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);\r
- path.moveTo(10800, adjval);\r
-\r
- path.lineTo(10800, adjval2 - adjval);\r
-\r
- path.append(new Arc2D.Float(10800, adjval2 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);\r
- path.moveTo(21600, adjval2);\r
-\r
- path.append(new Arc2D.Float(10800, adjval2, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);\r
- path.moveTo(10800, adjval2 + adjval);\r
-\r
- path.lineTo(10800, 21600 - adjval);\r
-\r
- path.append(new Arc2D.Float(-10800, 21600 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);\r
-\r
- return path;\r
- }\r
- };\r
-\r
- shapes[ShapeTypes.StraightConnector1] = new ShapeOutline(){\r
- public java.awt.Shape getOutline(Shape shape){\r
- return new Line2D.Float(0, 0, 21600, 21600);\r
- }\r
- };\r
-\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.EscherProperties;
+
+import java.awt.geom.*;
+
+/**
+ * Stores definition of auto-shapes.
+ * See the Office Drawing 97-2007 Binary Format Specification for details.
+ *
+ * TODO: follow the spec and define all the auto-shapes
+ *
+ * @author Yegor Kozlov
+ */
+public final class AutoShapes {
+ protected static ShapeOutline[] shapes;
+
+
+ /**
+ * Return shape outline by shape type
+ * @param type shape type see {@link ShapeTypes}
+ *
+ * @return the shape outline
+ */
+ public static ShapeOutline getShapeOutline(int type){
+ ShapeOutline outline = shapes[type];
+ return outline;
+ }
+
+ /**
+ * Auto-shapes are defined in the [0,21600] coordinate system.
+ * We need to transform it into normal slide coordinates
+ *
+ */
+ public static java.awt.Shape transform(java.awt.Shape outline, Rectangle2D anchor){
+ AffineTransform at = new AffineTransform();
+ at.translate(anchor.getX(), anchor.getY());
+ at.scale(
+ 1.0f/21600*anchor.getWidth(),
+ 1.0f/21600*anchor.getHeight()
+ );
+ return at.createTransformedShape(outline);
+ }
+
+ static {
+ shapes = new ShapeOutline[255];
+
+ shapes[ShapeTypes.Rectangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ Rectangle2D path = new Rectangle2D.Float(0, 0, 21600, 21600);
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.RoundRectangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+ RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval);
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Ellipse] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ Ellipse2D path = new Ellipse2D.Float(0, 0, 21600, 21600);
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Diamond] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ GeneralPath path = new GeneralPath();
+ path.moveTo(10800, 0);
+ path.lineTo(21600, 10800);
+ path.lineTo(10800, 21600);
+ path.lineTo(0, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ //m@0,l,21600r21600
+ shapes[ShapeTypes.IsocelesTriangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 10800);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(0, 21600);
+ path.lineTo(21600, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.RightTriangle] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+ path.lineTo(21600, 21600);
+ path.lineTo(0, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Parallelogram] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600, 0);
+ path.lineTo(21600 - adjval, 21600);
+ path.lineTo(0, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Trapezoid] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+ path.lineTo(adjval, 21600);
+ path.lineTo(21600 - adjval, 21600);
+ path.lineTo(21600, 0);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Hexagon] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600 - adjval, 0);
+ path.lineTo(21600, 10800);
+ path.lineTo(21600 - adjval, 21600);
+ path.lineTo(adjval, 21600);
+ path.lineTo(0, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Octagon] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 6326);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600 - adjval, 0);
+ path.lineTo(21600, adjval);
+ path.lineTo(21600, 21600-adjval);
+ path.lineTo(21600-adjval, 21600);
+ path.lineTo(adjval, 21600);
+ path.lineTo(0, 21600-adjval);
+ path.lineTo(0, adjval);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Plus] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(21600 - adjval, 0);
+ path.lineTo(21600 - adjval, adjval);
+ path.lineTo(21600, adjval);
+ path.lineTo(21600, 21600-adjval);
+ path.lineTo(21600-adjval, 21600-adjval);
+ path.lineTo(21600-adjval, 21600);
+ path.lineTo(adjval, 21600);
+ path.lineTo(adjval, 21600-adjval);
+ path.lineTo(0, 21600-adjval);
+ path.lineTo(0, adjval);
+ path.lineTo(adjval, adjval);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Pentagon] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(10800, 0);
+ path.lineTo(21600, 8259);
+ path.lineTo(21600 - 4200, 21600);
+ path.lineTo(4200, 21600);
+ path.lineTo(0, 8259);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.DownArrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m0@0 l@1@0 @1,0 @2,0 @2@0,21600@0,10800,21600xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, adjval);
+ path.lineTo(adjval2, adjval);
+ path.lineTo(adjval2, 0);
+ path.lineTo(21600-adjval2, 0);
+ path.lineTo(21600-adjval2, adjval);
+ path.lineTo(21600, adjval);
+ path.lineTo(10800, 21600);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.UpArrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m0@0 l@1@0 @1,21600@2,21600@2@0,21600@0,10800,xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, adjval);
+ path.lineTo(adjval2, adjval);
+ path.lineTo(adjval2, 21600);
+ path.lineTo(21600-adjval2, 21600);
+ path.lineTo(21600-adjval2, adjval);
+ path.lineTo(21600, adjval);
+ path.lineTo(10800, 0);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Arrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m@0, l@0@1 ,0@1,0@2@0@2@0,21600,21600,10800xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(adjval, adjval2);
+ path.lineTo(0, adjval2);
+ path.lineTo(0, 21600-adjval2);
+ path.lineTo(adjval, 21600-adjval2);
+ path.lineTo(adjval, 21600);
+ path.lineTo(21600, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.LeftArrow] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m@0, l@0@1,21600@1,21600@2@0@2@0,21600,,10800xe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
+ GeneralPath path = new GeneralPath();
+ path.moveTo(adjval, 0);
+ path.lineTo(adjval, adjval2);
+ path.lineTo(21600, adjval2);
+ path.lineTo(21600, 21600-adjval2);
+ path.lineTo(adjval, 21600-adjval2);
+ path.lineTo(adjval, 21600);
+ path.lineTo(0, 10800);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.Can] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m10800,qx0@1l0@2qy10800,21600,21600@2l21600@1qy10800,xem0@1qy10800@0,21600@1nfe
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
+
+ GeneralPath path = new GeneralPath();
+
+ path.append(new Arc2D.Float(0, 0, 21600, adjval, 0, 180, Arc2D.OPEN), false);
+ path.moveTo(0, adjval/2);
+
+ path.lineTo(0, 21600 - adjval/2);
+ path.closePath();
+
+ path.append(new Arc2D.Float(0, 21600 - adjval, 21600, adjval, 180, 180, Arc2D.OPEN), false);
+ path.moveTo(21600, 21600 - adjval/2);
+
+ path.lineTo(21600, adjval/2);
+ path.append(new Arc2D.Float(0, 0, 21600, adjval, 180, 180, Arc2D.OPEN), false);
+ path.moveTo(0, adjval/2);
+ path.closePath();
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.LeftBrace] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m21600,qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(21600, 0);
+
+ path.append(new Arc2D.Float(10800, 0, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval);
+
+ path.lineTo(10800, adjval2 - adjval);
+
+ path.append(new Arc2D.Float(-10800, adjval2 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
+ path.moveTo(0, adjval2);
+
+ path.append(new Arc2D.Float(-10800, adjval2, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval2 + adjval);
+
+ path.lineTo(10800, 21600 - adjval);
+
+ path.append(new Arc2D.Float(10800, 21600 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
+
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.RightBrace] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ //m,qx10800@0 l10800@2qy21600@11,10800@3l10800@1qy,21600e
+ int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
+ int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
+
+ GeneralPath path = new GeneralPath();
+ path.moveTo(0, 0);
+
+ path.append(new Arc2D.Float(-10800, 0, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval);
+
+ path.lineTo(10800, adjval2 - adjval);
+
+ path.append(new Arc2D.Float(10800, adjval2 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
+ path.moveTo(21600, adjval2);
+
+ path.append(new Arc2D.Float(10800, adjval2, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
+ path.moveTo(10800, adjval2 + adjval);
+
+ path.lineTo(10800, 21600 - adjval);
+
+ path.append(new Arc2D.Float(-10800, 21600 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
+
+ return path;
+ }
+ };
+
+ shapes[ShapeTypes.StraightConnector1] = new ShapeOutline(){
+ public java.awt.Shape getOutline(Shape shape){
+ return new Line2D.Float(0, 0, 21600, 21600);
+ }
+ };
+
+
+ }
+}
/**
* Background shape
- *
+ *
* @author Yegor Kozlov
*/
-public class Background extends Shape {
+public final class Background extends Shape {
protected Background(EscherContainerRecord escherRecord, Shape parent) {
super(escherRecord, parent);
import org.apache.poi.hslf.record.Comment2000;
/**
- *
+ *
* @author Nick Burch
*/
public final class Comment {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
*
* @author Yegor Kozlov
*/
-public class Fill {
+public final class Fill {
// For logging
protected POILogger logger = POILogFactory.getLogger(this.getClass());
/**
* Assign picture used to fill the underlying shape.
*
- * @param idx 0-based index of the picture added to this ppt by <code>SlideShow.addPicture</code> method.
+ * @param idx 0-based index of the picture added to this ppt by <code>SlideShow.addPicture</code> method.
*/
public void setPictureData(int idx){
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-import org.apache.poi.util.HexDump;\r
-\r
-import java.awt.geom.*;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * A "Freeform" shape.\r
- *\r
- * <p>\r
- * Shapes drawn with the "Freeform" tool have cubic bezier curve segments in the smooth sections\r
- * and straight-line segments in the straight sections. This object closely corresponds to <code>java.awt.geom.GeneralPath</code>.\r
- * </p>\r
- * @author Yegor Kozlov\r
- */\r
-public class Freeform extends AutoShape {\r
-\r
- public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40};\r
- public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC};\r
- public static final byte[] SEGMENTINFO_ESCAPE = new byte[]{0x01, 0x00};\r
- public static final byte[] SEGMENTINFO_ESCAPE2 = new byte[]{0x01, 0x20};\r
- public static final byte[] SEGMENTINFO_CUBICTO = new byte[]{0x00, (byte)0xAD};\r
- public static final byte[] SEGMENTINFO_CUBICTO2 = new byte[]{0x00, (byte)0xB3}; //OpenOffice inserts 0xB3 instead of 0xAD.\r
- public static final byte[] SEGMENTINFO_CLOSE = new byte[]{0x01, (byte)0x60};\r
- public static final byte[] SEGMENTINFO_END = new byte[]{0x00, (byte)0x80};\r
-\r
- /**\r
- * Create a Freeform object and initialize it from the supplied Record container.\r
- *\r
- * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape\r
- * @param parent the parent of the shape\r
- */\r
- protected Freeform(EscherContainerRecord escherRecord, Shape parent){\r
- super(escherRecord, parent);\r
-\r
- }\r
-\r
- /**\r
- * Create a new Freeform. This constructor is used when a new shape is created.\r
- *\r
- * @param parent the parent of this Shape. For example, if this text box is a cell\r
- * in a table then the parent is Table.\r
- */\r
- public Freeform(Shape parent){\r
- super(null, parent);\r
- _escherContainer = createSpContainer(ShapeTypes.NotPrimitive, parent instanceof ShapeGroup);\r
- }\r
-\r
- /**\r
- * Create a new Freeform. This constructor is used when a new shape is created.\r
- *\r
- */\r
- public Freeform(){\r
- this(null);\r
- }\r
-\r
- /**\r
- * Set the shape path\r
- *\r
- * @param path\r
- */\r
- public void setPath(GeneralPath path)\r
- {\r
- Rectangle2D bounds = path.getBounds2D();\r
- PathIterator it = path.getPathIterator(new AffineTransform());\r
-\r
- ArrayList segInfo = new ArrayList();\r
- ArrayList pntInfo = new ArrayList();\r
- boolean isClosed = false;\r
- while (!it.isDone()) {\r
- double[] vals = new double[6];\r
- int type = it.currentSegment(vals);\r
- switch (type) {\r
- case PathIterator.SEG_MOVETO:\r
- pntInfo.add(new Point2D.Double(vals[0], vals[1]));\r
- segInfo.add(SEGMENTINFO_MOVETO);\r
- break;\r
- case PathIterator.SEG_LINETO:\r
- pntInfo.add(new Point2D.Double(vals[0], vals[1]));\r
- segInfo.add(SEGMENTINFO_LINETO);\r
- segInfo.add(SEGMENTINFO_ESCAPE);\r
- break;\r
- case PathIterator.SEG_CUBICTO:\r
- pntInfo.add(new Point2D.Double(vals[0], vals[1]));\r
- pntInfo.add(new Point2D.Double(vals[2], vals[3]));\r
- pntInfo.add(new Point2D.Double(vals[4], vals[5]));\r
- segInfo.add(SEGMENTINFO_CUBICTO);\r
- segInfo.add(SEGMENTINFO_ESCAPE2);\r
- break;\r
- case PathIterator.SEG_QUADTO:\r
- //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO \r
- logger.log(POILogger.WARN, "SEG_QUADTO is not supported");\r
- break;\r
- case PathIterator.SEG_CLOSE:\r
- pntInfo.add(pntInfo.get(0));\r
- segInfo.add(SEGMENTINFO_LINETO);\r
- segInfo.add(SEGMENTINFO_ESCAPE);\r
- segInfo.add(SEGMENTINFO_LINETO);\r
- segInfo.add(SEGMENTINFO_CLOSE);\r
- isClosed = true;\r
- break;\r
- }\r
-\r
- it.next();\r
- }\r
- if(!isClosed) segInfo.add(SEGMENTINFO_LINETO);\r
- segInfo.add(new byte[]{0x00, (byte)0x80});\r
-\r
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));\r
-\r
- EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);\r
- verticesProp.setNumberOfElementsInArray(pntInfo.size());\r
- verticesProp.setNumberOfElementsInMemory(pntInfo.size());\r
- verticesProp.setSizeOfElements(0xFFF0);\r
- for (int i = 0; i < pntInfo.size(); i++) {\r
- Point2D.Double pnt = (Point2D.Double)pntInfo.get(i);\r
- byte[] data = new byte[4];\r
- LittleEndian.putShort(data, 0, (short)((pnt.getX() - bounds.getX())*MASTER_DPI/POINT_DPI));\r
- LittleEndian.putShort(data, 2, (short)((pnt.getY() - bounds.getY())*MASTER_DPI/POINT_DPI));\r
- verticesProp.setElement(i, data);\r
- }\r
- opt.addEscherProperty(verticesProp);\r
-\r
- EscherArrayProperty segmentsProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null);\r
- segmentsProp.setNumberOfElementsInArray(segInfo.size());\r
- segmentsProp.setNumberOfElementsInMemory(segInfo.size());\r
- segmentsProp.setSizeOfElements(0x2);\r
- for (int i = 0; i < segInfo.size(); i++) {\r
- byte[] seg = (byte[])segInfo.get(i);\r
- segmentsProp.setElement(i, seg);\r
- }\r
- opt.addEscherProperty(segmentsProp);\r
-\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)(bounds.getWidth()*MASTER_DPI/POINT_DPI)));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)(bounds.getHeight()*MASTER_DPI/POINT_DPI)));\r
-\r
- opt.sortProperties();\r
-\r
- setAnchor(bounds);\r
- }\r
-\r
- /**\r
- * Gets the freeform path\r
- *\r
- * @return the freeform path\r
- */\r
- public GeneralPath getPath(){\r
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));\r
-\r
- EscherArrayProperty verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000));\r
- if(verticesProp == null) verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES));\r
-\r
- EscherArrayProperty segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000));\r
- if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO));\r
-\r
- //sanity check\r
- if(verticesProp == null) {\r
- logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES ");\r
- return null;\r
- }\r
- if(segmentsProp == null) {\r
- logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO ");\r
- return null;\r
- }\r
-\r
- GeneralPath path = new GeneralPath();\r
- int numPoints = verticesProp.getNumberOfElementsInArray();\r
- int numSegments = segmentsProp.getNumberOfElementsInArray();\r
- for (int i = 0, j = 0; i < numSegments && j < numPoints; i++) {\r
- byte[] elem = segmentsProp.getElement(i);\r
- if(Arrays.equals(elem, SEGMENTINFO_MOVETO)){\r
- byte[] p = verticesProp.getElement(j++);\r
- short x = LittleEndian.getShort(p, 0);\r
- short y = LittleEndian.getShort(p, 2);\r
- path.moveTo(\r
- ((float)x*POINT_DPI/MASTER_DPI),\r
- ((float)y*POINT_DPI/MASTER_DPI));\r
- } else if (Arrays.equals(elem, SEGMENTINFO_CUBICTO) || Arrays.equals(elem, SEGMENTINFO_CUBICTO2)){\r
- i++;\r
- byte[] p1 = verticesProp.getElement(j++);\r
- short x1 = LittleEndian.getShort(p1, 0);\r
- short y1 = LittleEndian.getShort(p1, 2);\r
- byte[] p2 = verticesProp.getElement(j++);\r
- short x2 = LittleEndian.getShort(p2, 0);\r
- short y2 = LittleEndian.getShort(p2, 2);\r
- byte[] p3 = verticesProp.getElement(j++);\r
- short x3 = LittleEndian.getShort(p3, 0);\r
- short y3 = LittleEndian.getShort(p3, 2);\r
- path.curveTo(\r
- ((float)x1*POINT_DPI/MASTER_DPI), ((float)y1*POINT_DPI/MASTER_DPI),\r
- ((float)x2*POINT_DPI/MASTER_DPI), ((float)y2*POINT_DPI/MASTER_DPI),\r
- ((float)x3*POINT_DPI/MASTER_DPI), ((float)y3*POINT_DPI/MASTER_DPI));\r
-\r
- } else if (Arrays.equals(elem, SEGMENTINFO_LINETO)){\r
- i++;\r
- byte[] pnext = segmentsProp.getElement(i);\r
- if(Arrays.equals(pnext, SEGMENTINFO_ESCAPE)){\r
- if(j + 1 < numPoints){\r
- byte[] p = verticesProp.getElement(j++);\r
- short x = LittleEndian.getShort(p, 0);\r
- short y = LittleEndian.getShort(p, 2);\r
- path.lineTo(\r
- ((float)x*POINT_DPI/MASTER_DPI), ((float)y*POINT_DPI/MASTER_DPI));\r
- }\r
- } else if (Arrays.equals(pnext, SEGMENTINFO_CLOSE)){\r
- path.closePath();\r
- }\r
- }\r
- }\r
- return path;\r
- }\r
-\r
- public java.awt.Shape getOutline(){\r
- GeneralPath path = getPath();\r
- Rectangle2D anchor = getAnchor2D();\r
- Rectangle2D bounds = path.getBounds2D();\r
- AffineTransform at = new AffineTransform();\r
- at.translate(anchor.getX(), anchor.getY());\r
- at.scale(\r
- anchor.getWidth()/bounds.getWidth(),\r
- anchor.getHeight()/bounds.getHeight()\r
- );\r
- return at.createTransformedShape(path);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.HexDump;
+
+import java.awt.geom.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * A "Freeform" shape.
+ *
+ * <p>
+ * Shapes drawn with the "Freeform" tool have cubic bezier curve segments in the smooth sections
+ * and straight-line segments in the straight sections. This object closely corresponds to <code>java.awt.geom.GeneralPath</code>.
+ * </p>
+ * @author Yegor Kozlov
+ */
+public final class Freeform extends AutoShape {
+
+ public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40};
+ public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC};
+ public static final byte[] SEGMENTINFO_ESCAPE = new byte[]{0x01, 0x00};
+ public static final byte[] SEGMENTINFO_ESCAPE2 = new byte[]{0x01, 0x20};
+ public static final byte[] SEGMENTINFO_CUBICTO = new byte[]{0x00, (byte)0xAD};
+ public static final byte[] SEGMENTINFO_CUBICTO2 = new byte[]{0x00, (byte)0xB3}; //OpenOffice inserts 0xB3 instead of 0xAD.
+ public static final byte[] SEGMENTINFO_CLOSE = new byte[]{0x01, (byte)0x60};
+ public static final byte[] SEGMENTINFO_END = new byte[]{0x00, (byte)0x80};
+
+ /**
+ * Create a Freeform object and initialize it from the supplied Record container.
+ *
+ * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected Freeform(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+
+ }
+
+ /**
+ * Create a new Freeform. This constructor is used when a new shape is created.
+ *
+ * @param parent the parent of this Shape. For example, if this text box is a cell
+ * in a table then the parent is Table.
+ */
+ public Freeform(Shape parent){
+ super(null, parent);
+ _escherContainer = createSpContainer(ShapeTypes.NotPrimitive, parent instanceof ShapeGroup);
+ }
+
+ /**
+ * Create a new Freeform. This constructor is used when a new shape is created.
+ *
+ */
+ public Freeform(){
+ this(null);
+ }
+
+ /**
+ * Set the shape path
+ *
+ * @param path
+ */
+ public void setPath(GeneralPath path)
+ {
+ Rectangle2D bounds = path.getBounds2D();
+ PathIterator it = path.getPathIterator(new AffineTransform());
+
+ ArrayList segInfo = new ArrayList();
+ ArrayList pntInfo = new ArrayList();
+ boolean isClosed = false;
+ while (!it.isDone()) {
+ double[] vals = new double[6];
+ int type = it.currentSegment(vals);
+ switch (type) {
+ case PathIterator.SEG_MOVETO:
+ pntInfo.add(new Point2D.Double(vals[0], vals[1]));
+ segInfo.add(SEGMENTINFO_MOVETO);
+ break;
+ case PathIterator.SEG_LINETO:
+ pntInfo.add(new Point2D.Double(vals[0], vals[1]));
+ segInfo.add(SEGMENTINFO_LINETO);
+ segInfo.add(SEGMENTINFO_ESCAPE);
+ break;
+ case PathIterator.SEG_CUBICTO:
+ pntInfo.add(new Point2D.Double(vals[0], vals[1]));
+ pntInfo.add(new Point2D.Double(vals[2], vals[3]));
+ pntInfo.add(new Point2D.Double(vals[4], vals[5]));
+ segInfo.add(SEGMENTINFO_CUBICTO);
+ segInfo.add(SEGMENTINFO_ESCAPE2);
+ break;
+ case PathIterator.SEG_QUADTO:
+ //TODO: figure out how to convert SEG_QUADTO into SEG_CUBICTO
+ logger.log(POILogger.WARN, "SEG_QUADTO is not supported");
+ break;
+ case PathIterator.SEG_CLOSE:
+ pntInfo.add(pntInfo.get(0));
+ segInfo.add(SEGMENTINFO_LINETO);
+ segInfo.add(SEGMENTINFO_ESCAPE);
+ segInfo.add(SEGMENTINFO_LINETO);
+ segInfo.add(SEGMENTINFO_CLOSE);
+ isClosed = true;
+ break;
+ }
+
+ it.next();
+ }
+ if(!isClosed) segInfo.add(SEGMENTINFO_LINETO);
+ segInfo.add(new byte[]{0x00, (byte)0x80});
+
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
+
+ EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
+ verticesProp.setNumberOfElementsInArray(pntInfo.size());
+ verticesProp.setNumberOfElementsInMemory(pntInfo.size());
+ verticesProp.setSizeOfElements(0xFFF0);
+ for (int i = 0; i < pntInfo.size(); i++) {
+ Point2D.Double pnt = (Point2D.Double)pntInfo.get(i);
+ byte[] data = new byte[4];
+ LittleEndian.putShort(data, 0, (short)((pnt.getX() - bounds.getX())*MASTER_DPI/POINT_DPI));
+ LittleEndian.putShort(data, 2, (short)((pnt.getY() - bounds.getY())*MASTER_DPI/POINT_DPI));
+ verticesProp.setElement(i, data);
+ }
+ opt.addEscherProperty(verticesProp);
+
+ EscherArrayProperty segmentsProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000), false, null);
+ segmentsProp.setNumberOfElementsInArray(segInfo.size());
+ segmentsProp.setNumberOfElementsInMemory(segInfo.size());
+ segmentsProp.setSizeOfElements(0x2);
+ for (int i = 0; i < segInfo.size(); i++) {
+ byte[] seg = (byte[])segInfo.get(i);
+ segmentsProp.setElement(i, seg);
+ }
+ opt.addEscherProperty(segmentsProp);
+
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)(bounds.getWidth()*MASTER_DPI/POINT_DPI)));
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)(bounds.getHeight()*MASTER_DPI/POINT_DPI)));
+
+ opt.sortProperties();
+
+ setAnchor(bounds);
+ }
+
+ /**
+ * Gets the freeform path
+ *
+ * @return the freeform path
+ */
+ public GeneralPath getPath(){
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
+
+ EscherArrayProperty verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000));
+ if(verticesProp == null) verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES));
+
+ EscherArrayProperty segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000));
+ if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO));
+
+ //sanity check
+ if(verticesProp == null) {
+ logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__VERTICES ");
+ return null;
+ }
+ if(segmentsProp == null) {
+ logger.log(POILogger.WARN, "Freeform is missing GEOMETRY__SEGMENTINFO ");
+ return null;
+ }
+
+ GeneralPath path = new GeneralPath();
+ int numPoints = verticesProp.getNumberOfElementsInArray();
+ int numSegments = segmentsProp.getNumberOfElementsInArray();
+ for (int i = 0, j = 0; i < numSegments && j < numPoints; i++) {
+ byte[] elem = segmentsProp.getElement(i);
+ if(Arrays.equals(elem, SEGMENTINFO_MOVETO)){
+ byte[] p = verticesProp.getElement(j++);
+ short x = LittleEndian.getShort(p, 0);
+ short y = LittleEndian.getShort(p, 2);
+ path.moveTo(
+ ((float)x*POINT_DPI/MASTER_DPI),
+ ((float)y*POINT_DPI/MASTER_DPI));
+ } else if (Arrays.equals(elem, SEGMENTINFO_CUBICTO) || Arrays.equals(elem, SEGMENTINFO_CUBICTO2)){
+ i++;
+ byte[] p1 = verticesProp.getElement(j++);
+ short x1 = LittleEndian.getShort(p1, 0);
+ short y1 = LittleEndian.getShort(p1, 2);
+ byte[] p2 = verticesProp.getElement(j++);
+ short x2 = LittleEndian.getShort(p2, 0);
+ short y2 = LittleEndian.getShort(p2, 2);
+ byte[] p3 = verticesProp.getElement(j++);
+ short x3 = LittleEndian.getShort(p3, 0);
+ short y3 = LittleEndian.getShort(p3, 2);
+ path.curveTo(
+ ((float)x1*POINT_DPI/MASTER_DPI), ((float)y1*POINT_DPI/MASTER_DPI),
+ ((float)x2*POINT_DPI/MASTER_DPI), ((float)y2*POINT_DPI/MASTER_DPI),
+ ((float)x3*POINT_DPI/MASTER_DPI), ((float)y3*POINT_DPI/MASTER_DPI));
+
+ } else if (Arrays.equals(elem, SEGMENTINFO_LINETO)){
+ i++;
+ byte[] pnext = segmentsProp.getElement(i);
+ if(Arrays.equals(pnext, SEGMENTINFO_ESCAPE)){
+ if(j + 1 < numPoints){
+ byte[] p = verticesProp.getElement(j++);
+ short x = LittleEndian.getShort(p, 0);
+ short y = LittleEndian.getShort(p, 2);
+ path.lineTo(
+ ((float)x*POINT_DPI/MASTER_DPI), ((float)y*POINT_DPI/MASTER_DPI));
+ }
+ } else if (Arrays.equals(pnext, SEGMENTINFO_CLOSE)){
+ path.closePath();
+ }
+ }
+ }
+ return path;
+ }
+
+ public java.awt.Shape getOutline(){
+ GeneralPath path = getPath();
+ Rectangle2D anchor = getAnchor2D();
+ Rectangle2D bounds = path.getBounds2D();
+ AffineTransform at = new AffineTransform();
+ at.translate(anchor.getX(), anchor.getY());
+ at.scale(
+ anchor.getWidth()/bounds.getWidth(),
+ anchor.getHeight()/bounds.getHeight()
+ );
+ return at.createTransformedShape(path);
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.hslf.record.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-/**\r
- * Header / Footer settings.\r
- * \r
- * You can get these on slides, or across all notes\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class HeadersFooters {\r
-\r
- private HeadersFootersContainer _container;\r
- private boolean _newRecord;\r
- private SlideShow _ppt;\r
- private Sheet _sheet;\r
- private boolean _ppt2007;\r
-\r
-\r
- public HeadersFooters(HeadersFootersContainer rec, SlideShow ppt, boolean newRecord, boolean isPpt2007){\r
- _container = rec;\r
- _newRecord = newRecord;\r
- _ppt = ppt;\r
- _ppt2007 = isPpt2007;\r
- }\r
-\r
- public HeadersFooters(HeadersFootersContainer rec, Sheet sheet, boolean newRecord, boolean isPpt2007){\r
- _container = rec;\r
- _newRecord = newRecord;\r
- _sheet = sheet;\r
- _ppt2007 = isPpt2007;\r
- }\r
-\r
- /**\r
- * Headers's text\r
- *\r
- * @return Headers's text\r
- */\r
- public String getHeaderText(){\r
- CString cs = _container == null ? null : _container.getHeaderAtom();\r
- return getPlaceholderText(OEPlaceholderAtom.MasterHeader, cs);\r
- }\r
-\r
- /**\r
- * Sets headers's text\r
- *\r
- * @param text headers's text\r
- */\r
- public void setHeaderText(String text){\r
- if(_newRecord) attach();\r
-\r
- setHeaderVisible(true);\r
- CString cs = _container.getHeaderAtom();\r
- if(cs == null) cs = _container.addHeaderAtom();\r
-\r
- cs.setText(text);\r
- }\r
-\r
- /**\r
- * Footer's text\r
- *\r
- * @return Footer's text\r
- */\r
- public String getFooterText(){\r
- CString cs = _container == null ? null : _container.getFooterAtom();\r
- return getPlaceholderText(OEPlaceholderAtom.MasterFooter, cs);\r
- }\r
-\r
- /**\r
- * Sets footers's text\r
- *\r
- * @param text footers's text\r
- */\r
- public void setFootersText(String text){\r
- if(_newRecord) attach();\r
-\r
- setFooterVisible(true);\r
- CString cs = _container.getFooterAtom();\r
- if(cs == null) cs = _container.addFooterAtom();\r
-\r
- cs.setText(text);\r
- }\r
-\r
- /**\r
- * This is the date that the user wants in the footers, instead of today's date.\r
- *\r
- * @return custom user date\r
- */\r
- public String getDateTimeText(){\r
- CString cs = _container == null ? null : _container.getUserDateAtom();\r
- return getPlaceholderText(OEPlaceholderAtom.MasterDate, cs);\r
- }\r
-\r
- /**\r
- * Sets custom user date to be displayed instead of today's date.\r
- *\r
- * @param text custom user date\r
- */\r
- public void setDateTimeText(String text){\r
- if(_newRecord) attach();\r
-\r
- setUserDateVisible(true);\r
- setDateTimeVisible(true);\r
- CString cs = _container.getUserDateAtom();\r
- if(cs == null) cs = _container.addUserDateAtom();\r
-\r
- cs.setText(text);\r
- }\r
-\r
- /**\r
- * whether the footer text is displayed.\r
- */\r
- public boolean isFooterVisible(){\r
- return isVisible(HeadersFootersAtom.fHasFooter, OEPlaceholderAtom.MasterFooter);\r
- }\r
-\r
- /**\r
- * whether the footer text is displayed.\r
- */\r
- public void setFooterVisible(boolean flag){\r
- if(_newRecord) attach();\r
- _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasFooter, flag);\r
- }\r
-\r
- /**\r
- * whether the header text is displayed.\r
- */\r
- public boolean isHeaderVisible(){\r
- return isVisible(HeadersFootersAtom.fHasHeader, OEPlaceholderAtom.MasterHeader);\r
- }\r
-\r
- /**\r
- * whether the header text is displayed.\r
- */\r
- public void setHeaderVisible(boolean flag){\r
- if(_newRecord) attach();\r
- _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasHeader, flag);\r
- }\r
-\r
- /**\r
- * whether the date is displayed in the footer.\r
- */\r
- public boolean isDateTimeVisible(){\r
- return isVisible(HeadersFootersAtom.fHasDate, OEPlaceholderAtom.MasterDate);\r
- }\r
-\r
- /**\r
- * whether the date is displayed in the footer.\r
- */\r
- public void setDateTimeVisible(boolean flag){\r
- if(_newRecord) attach();\r
- _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasDate, flag);\r
- }\r
-\r
- /**\r
- * whether the custom user date is used instead of today's date.\r
- */\r
- public boolean isUserDateVisible(){\r
- return isVisible(HeadersFootersAtom.fHasUserDate, OEPlaceholderAtom.MasterDate);\r
- }\r
-\r
- /**\r
- * whether the date is displayed in the footer.\r
- */\r
- public void setUserDateVisible(boolean flag){\r
- if(_newRecord) attach();\r
- _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasUserDate, flag);\r
- }\r
-\r
- /**\r
- * whether the slide number is displayed in the footer.\r
- */\r
- public boolean isSlideNumberVisible(){\r
- return isVisible(HeadersFootersAtom.fHasSlideNumber, OEPlaceholderAtom.MasterSlideNumber);\r
- }\r
-\r
- /**\r
- * whether the slide number is displayed in the footer.\r
- */\r
- public void setSlideNumberVisible(boolean flag){\r
- if(_newRecord) attach();\r
- _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasSlideNumber, flag);\r
- }\r
-\r
- /**\r
- * An integer that specifies the format ID to be used to style the datetime.\r
- *\r
- * @return an integer that specifies the format ID to be used to style the datetime.\r
- */\r
- public int getDateTimeFormat(){\r
- return _container.getHeadersFootersAtom().getFormatId();\r
- }\r
-\r
- /**\r
- * An integer that specifies the format ID to be used to style the datetime.\r
- *\r
- * @param formatId an integer that specifies the format ID to be used to style the datetime.\r
- */\r
- public void setDateTimeFormat(int formatId){\r
- if(_newRecord) attach();\r
- _container.getHeadersFootersAtom().setFormatId(formatId);\r
- }\r
-\r
- /**\r
- * Attach this HeadersFootersContainer to the parent Document record\r
- */\r
- private void attach(){\r
- Document doc = _ppt.getDocumentRecord();\r
- Record[] ch = doc.getChildRecords();\r
- Record lst = null;\r
- for (int i=0; i < ch.length; i++){\r
- if(ch[i].getRecordType() == RecordTypes.List.typeID){\r
- lst = ch[i];\r
- break;\r
- }\r
- }\r
- doc.addChildAfter(_container, lst);\r
- _newRecord = false;\r
- }\r
-\r
- private boolean isVisible(int flag, int placeholderId){\r
- boolean visible;\r
- if(_ppt2007){\r
- Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];\r
- TextShape placeholder = master.getPlaceholder(placeholderId);\r
- visible = placeholder != null && placeholder.getText() != null;\r
- } else {\r
- visible = _container.getHeadersFootersAtom().getFlag(flag);\r
- }\r
- return visible;\r
- }\r
-\r
- private String getPlaceholderText(int placeholderId, CString cs){\r
- String text = null;\r
- if(_ppt2007){\r
- Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];\r
- TextShape placeholder = master.getPlaceholder(placeholderId);\r
- if(placeholder != null) text = placeholder.getText();\r
-\r
- //default text in master placeholders is not visible\r
- if("*".equals(text)) text = null;\r
- } else {\r
- text = cs == null ? null : cs.getText();\r
- }\r
- return text;\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+/**
+ * Header / Footer settings.
+ *
+ * You can get these on slides, or across all notes
+ *
+ * @author Yegor Kozlov
+ */
+public final class HeadersFooters {
+
+ private HeadersFootersContainer _container;
+ private boolean _newRecord;
+ private SlideShow _ppt;
+ private Sheet _sheet;
+ private boolean _ppt2007;
+
+
+ public HeadersFooters(HeadersFootersContainer rec, SlideShow ppt, boolean newRecord, boolean isPpt2007){
+ _container = rec;
+ _newRecord = newRecord;
+ _ppt = ppt;
+ _ppt2007 = isPpt2007;
+ }
+
+ public HeadersFooters(HeadersFootersContainer rec, Sheet sheet, boolean newRecord, boolean isPpt2007){
+ _container = rec;
+ _newRecord = newRecord;
+ _sheet = sheet;
+ _ppt2007 = isPpt2007;
+ }
+
+ /**
+ * Headers's text
+ *
+ * @return Headers's text
+ */
+ public String getHeaderText(){
+ CString cs = _container == null ? null : _container.getHeaderAtom();
+ return getPlaceholderText(OEPlaceholderAtom.MasterHeader, cs);
+ }
+
+ /**
+ * Sets headers's text
+ *
+ * @param text headers's text
+ */
+ public void setHeaderText(String text){
+ if(_newRecord) attach();
+
+ setHeaderVisible(true);
+ CString cs = _container.getHeaderAtom();
+ if(cs == null) cs = _container.addHeaderAtom();
+
+ cs.setText(text);
+ }
+
+ /**
+ * Footer's text
+ *
+ * @return Footer's text
+ */
+ public String getFooterText(){
+ CString cs = _container == null ? null : _container.getFooterAtom();
+ return getPlaceholderText(OEPlaceholderAtom.MasterFooter, cs);
+ }
+
+ /**
+ * Sets footers's text
+ *
+ * @param text footers's text
+ */
+ public void setFootersText(String text){
+ if(_newRecord) attach();
+
+ setFooterVisible(true);
+ CString cs = _container.getFooterAtom();
+ if(cs == null) cs = _container.addFooterAtom();
+
+ cs.setText(text);
+ }
+
+ /**
+ * This is the date that the user wants in the footers, instead of today's date.
+ *
+ * @return custom user date
+ */
+ public String getDateTimeText(){
+ CString cs = _container == null ? null : _container.getUserDateAtom();
+ return getPlaceholderText(OEPlaceholderAtom.MasterDate, cs);
+ }
+
+ /**
+ * Sets custom user date to be displayed instead of today's date.
+ *
+ * @param text custom user date
+ */
+ public void setDateTimeText(String text){
+ if(_newRecord) attach();
+
+ setUserDateVisible(true);
+ setDateTimeVisible(true);
+ CString cs = _container.getUserDateAtom();
+ if(cs == null) cs = _container.addUserDateAtom();
+
+ cs.setText(text);
+ }
+
+ /**
+ * whether the footer text is displayed.
+ */
+ public boolean isFooterVisible(){
+ return isVisible(HeadersFootersAtom.fHasFooter, OEPlaceholderAtom.MasterFooter);
+ }
+
+ /**
+ * whether the footer text is displayed.
+ */
+ public void setFooterVisible(boolean flag){
+ if(_newRecord) attach();
+ _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasFooter, flag);
+ }
+
+ /**
+ * whether the header text is displayed.
+ */
+ public boolean isHeaderVisible(){
+ return isVisible(HeadersFootersAtom.fHasHeader, OEPlaceholderAtom.MasterHeader);
+ }
+
+ /**
+ * whether the header text is displayed.
+ */
+ public void setHeaderVisible(boolean flag){
+ if(_newRecord) attach();
+ _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasHeader, flag);
+ }
+
+ /**
+ * whether the date is displayed in the footer.
+ */
+ public boolean isDateTimeVisible(){
+ return isVisible(HeadersFootersAtom.fHasDate, OEPlaceholderAtom.MasterDate);
+ }
+
+ /**
+ * whether the date is displayed in the footer.
+ */
+ public void setDateTimeVisible(boolean flag){
+ if(_newRecord) attach();
+ _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasDate, flag);
+ }
+
+ /**
+ * whether the custom user date is used instead of today's date.
+ */
+ public boolean isUserDateVisible(){
+ return isVisible(HeadersFootersAtom.fHasUserDate, OEPlaceholderAtom.MasterDate);
+ }
+
+ /**
+ * whether the date is displayed in the footer.
+ */
+ public void setUserDateVisible(boolean flag){
+ if(_newRecord) attach();
+ _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasUserDate, flag);
+ }
+
+ /**
+ * whether the slide number is displayed in the footer.
+ */
+ public boolean isSlideNumberVisible(){
+ return isVisible(HeadersFootersAtom.fHasSlideNumber, OEPlaceholderAtom.MasterSlideNumber);
+ }
+
+ /**
+ * whether the slide number is displayed in the footer.
+ */
+ public void setSlideNumberVisible(boolean flag){
+ if(_newRecord) attach();
+ _container.getHeadersFootersAtom().setFlag(HeadersFootersAtom.fHasSlideNumber, flag);
+ }
+
+ /**
+ * An integer that specifies the format ID to be used to style the datetime.
+ *
+ * @return an integer that specifies the format ID to be used to style the datetime.
+ */
+ public int getDateTimeFormat(){
+ return _container.getHeadersFootersAtom().getFormatId();
+ }
+
+ /**
+ * An integer that specifies the format ID to be used to style the datetime.
+ *
+ * @param formatId an integer that specifies the format ID to be used to style the datetime.
+ */
+ public void setDateTimeFormat(int formatId){
+ if(_newRecord) attach();
+ _container.getHeadersFootersAtom().setFormatId(formatId);
+ }
+
+ /**
+ * Attach this HeadersFootersContainer to the parent Document record
+ */
+ private void attach(){
+ Document doc = _ppt.getDocumentRecord();
+ Record[] ch = doc.getChildRecords();
+ Record lst = null;
+ for (int i=0; i < ch.length; i++){
+ if(ch[i].getRecordType() == RecordTypes.List.typeID){
+ lst = ch[i];
+ break;
+ }
+ }
+ doc.addChildAfter(_container, lst);
+ _newRecord = false;
+ }
+
+ private boolean isVisible(int flag, int placeholderId){
+ boolean visible;
+ if(_ppt2007){
+ Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
+ TextShape placeholder = master.getPlaceholder(placeholderId);
+ visible = placeholder != null && placeholder.getText() != null;
+ } else {
+ visible = _container.getHeadersFootersAtom().getFlag(flag);
+ }
+ return visible;
+ }
+
+ private String getPlaceholderText(int placeholderId, CString cs){
+ String text = null;
+ if(_ppt2007){
+ Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
+ TextShape placeholder = master.getPlaceholder(placeholderId);
+ if(placeholder != null) text = placeholder.getText();
+
+ //default text in master placeholders is not visible
+ if("*".equals(text)) text = null;
+ } else {
+ text = cs == null ? null : cs.getText();
+ }
+ return text;
+ }
+
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.hslf.record.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.ddf.EscherContainerRecord;\r
-import org.apache.poi.ddf.EscherRecord;\r
-import org.apache.poi.ddf.EscherClientDataRecord;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Iterator;\r
-\r
-/**\r
- * Represents a hyperlink in a PowerPoint document\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class Hyperlink {\r
- public static final byte LINK_NEXTSLIDE = InteractiveInfoAtom.LINK_NextSlide;\r
- public static final byte LINK_PREVIOUSSLIDE = InteractiveInfoAtom.LINK_PreviousSlide;\r
- public static final byte LINK_FIRSTSLIDE = InteractiveInfoAtom.LINK_FirstSlide;\r
- public static final byte LINK_LASTSLIDE = InteractiveInfoAtom.LINK_LastSlide;\r
- public static final byte LINK_URL = InteractiveInfoAtom.LINK_Url;\r
- public static final byte LINK_NULL = InteractiveInfoAtom.LINK_NULL;\r
-\r
- private int id=-1;\r
- private int type;\r
- private String address;\r
- private String title;\r
- private int startIndex, endIndex;\r
-\r
- /**\r
- * Gets the type of the hyperlink action.\r
- * Must be a <code>LINK_*</code> constant</code>\r
- *\r
- * @return the hyperlink URL\r
- * @see InteractiveInfoAtom\r
- */\r
- public int getType() {\r
- return type;\r
- }\r
-\r
- public void setType(int val) {\r
- type = val;\r
- switch(type){\r
- case LINK_NEXTSLIDE:\r
- title = "NEXT";\r
- address = "1,-1,NEXT";\r
- break;\r
- case LINK_PREVIOUSSLIDE:\r
- title = "PREV";\r
- address = "1,-1,PREV";\r
- break;\r
- case LINK_FIRSTSLIDE:\r
- title = "FIRST";\r
- address = "1,-1,FIRST";\r
- break;\r
- case LINK_LASTSLIDE:\r
- title = "LAST";\r
- address = "1,-1,LAST";\r
- break;\r
- default:\r
- title = "";\r
- address = "";\r
- break;\r
- }\r
- }\r
-\r
- /**\r
- * Gets the hyperlink URL\r
- *\r
- * @return the hyperlink URL\r
- */\r
- public String getAddress() {\r
- return address;\r
- }\r
-\r
- public void setAddress(String str) {\r
- address = str;\r
- }\r
-\r
- public int getId() {\r
- return id;\r
- }\r
-\r
- public void setId(int id) {\r
- this.id = id;\r
- }\r
-\r
- /**\r
- * Gets the hyperlink user-friendly title (if different from URL)\r
- *\r
- * @return the hyperlink user-friendly title\r
- */\r
- public String getTitle() {\r
- return title;\r
- }\r
-\r
- public void setTitle(String str) {\r
- title = str;\r
- }\r
-\r
- /**\r
- * Gets the beginning character position\r
- *\r
- * @return the beginning character position\r
- */\r
- public int getStartIndex() {\r
- return startIndex;\r
- }\r
-\r
- /**\r
- * Gets the ending character position\r
- *\r
- * @return the ending character position\r
- */\r
- public int getEndIndex() {\r
- return endIndex;\r
- }\r
-\r
- /**\r
- * Find hyperlinks in a text run\r
- *\r
- * @param run <code>TextRun</code> to lookup hyperlinks in\r
- * @return found hyperlinks or <code>null</code> if not found\r
- */\r
- protected static Hyperlink[] find(TextRun run){\r
- ArrayList lst = new ArrayList();\r
- SlideShow ppt = run.getSheet().getSlideShow();\r
- //document-level container which stores info about all links in a presentation\r
- ExObjList exobj = ppt.getDocumentRecord().getExObjList();\r
- if (exobj == null) {\r
- return null;\r
- }\r
- Record[] records = run._records;\r
- if(records != null) find(records, exobj, lst);\r
-\r
- Hyperlink[] links = null;\r
- if (lst.size() > 0){\r
- links = new Hyperlink[lst.size()];\r
- lst.toArray(links);\r
- }\r
- return links;\r
- }\r
-\r
- /**\r
- * Find hyperlink assigned to the supplied shape\r
- *\r
- * @param shape <code>Shape</code> to lookup hyperlink in\r
- * @return found hyperlink or <code>null</code>\r
- */\r
- protected static Hyperlink find(Shape shape){\r
- ArrayList lst = new ArrayList();\r
- SlideShow ppt = shape.getSheet().getSlideShow();\r
- //document-level container which stores info about all links in a presentation\r
- ExObjList exobj = ppt.getDocumentRecord().getExObjList();\r
- if (exobj == null) {\r
- return null;\r
- }\r
-\r
- EscherContainerRecord spContainer = shape.getSpContainer();\r
- for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext(); ) {\r
- EscherRecord obj = it.next();\r
- if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID){\r
- byte[] data = obj.serialize();\r
- Record[] records = Record.findChildRecords(data, 8, data.length-8);\r
- if(records != null) find(records, exobj, lst);\r
- }\r
- }\r
-\r
- return lst.size() == 1 ? (Hyperlink)lst.get(0) : null;\r
- }\r
-\r
- private static void find(Record[] records, ExObjList exobj, List out){\r
- for (int i = 0; i < records.length; i++) {\r
- //see if we have InteractiveInfo in the textrun's records\r
- if( records[i] instanceof InteractiveInfo){\r
- InteractiveInfo hldr = (InteractiveInfo)records[i];\r
- InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();\r
- int id = info.getHyperlinkID();\r
- ExHyperlink linkRecord = exobj.get(id);\r
- if (linkRecord != null){\r
- Hyperlink link = new Hyperlink();\r
- link.title = linkRecord.getLinkTitle();\r
- link.address = linkRecord.getLinkURL();\r
- link.type = info.getAction();\r
-\r
- if (++i < records.length && records[i] instanceof TxInteractiveInfoAtom){\r
- TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[i];\r
- link.startIndex = txinfo.getStartIndex();\r
- link.endIndex = txinfo.getEndIndex();\r
- }\r
- out.add(link);\r
- }\r
- }\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.EscherClientDataRecord;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * Represents a hyperlink in a PowerPoint document
+ *
+ * @author Yegor Kozlov
+ */
+public final class Hyperlink {
+ public static final byte LINK_NEXTSLIDE = InteractiveInfoAtom.LINK_NextSlide;
+ public static final byte LINK_PREVIOUSSLIDE = InteractiveInfoAtom.LINK_PreviousSlide;
+ public static final byte LINK_FIRSTSLIDE = InteractiveInfoAtom.LINK_FirstSlide;
+ public static final byte LINK_LASTSLIDE = InteractiveInfoAtom.LINK_LastSlide;
+ public static final byte LINK_URL = InteractiveInfoAtom.LINK_Url;
+ public static final byte LINK_NULL = InteractiveInfoAtom.LINK_NULL;
+
+ private int id=-1;
+ private int type;
+ private String address;
+ private String title;
+ private int startIndex, endIndex;
+
+ /**
+ * Gets the type of the hyperlink action.
+ * Must be a <code>LINK_*</code> constant</code>
+ *
+ * @return the hyperlink URL
+ * @see InteractiveInfoAtom
+ */
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int val) {
+ type = val;
+ switch(type){
+ case LINK_NEXTSLIDE:
+ title = "NEXT";
+ address = "1,-1,NEXT";
+ break;
+ case LINK_PREVIOUSSLIDE:
+ title = "PREV";
+ address = "1,-1,PREV";
+ break;
+ case LINK_FIRSTSLIDE:
+ title = "FIRST";
+ address = "1,-1,FIRST";
+ break;
+ case LINK_LASTSLIDE:
+ title = "LAST";
+ address = "1,-1,LAST";
+ break;
+ default:
+ title = "";
+ address = "";
+ break;
+ }
+ }
+
+ /**
+ * Gets the hyperlink URL
+ *
+ * @return the hyperlink URL
+ */
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String str) {
+ address = str;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets the hyperlink user-friendly title (if different from URL)
+ *
+ * @return the hyperlink user-friendly title
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String str) {
+ title = str;
+ }
+
+ /**
+ * Gets the beginning character position
+ *
+ * @return the beginning character position
+ */
+ public int getStartIndex() {
+ return startIndex;
+ }
+
+ /**
+ * Gets the ending character position
+ *
+ * @return the ending character position
+ */
+ public int getEndIndex() {
+ return endIndex;
+ }
+
+ /**
+ * Find hyperlinks in a text run
+ *
+ * @param run <code>TextRun</code> to lookup hyperlinks in
+ * @return found hyperlinks or <code>null</code> if not found
+ */
+ protected static Hyperlink[] find(TextRun run){
+ ArrayList lst = new ArrayList();
+ SlideShow ppt = run.getSheet().getSlideShow();
+ //document-level container which stores info about all links in a presentation
+ ExObjList exobj = ppt.getDocumentRecord().getExObjList();
+ if (exobj == null) {
+ return null;
+ }
+ Record[] records = run._records;
+ if(records != null) find(records, exobj, lst);
+
+ Hyperlink[] links = null;
+ if (lst.size() > 0){
+ links = new Hyperlink[lst.size()];
+ lst.toArray(links);
+ }
+ return links;
+ }
+
+ /**
+ * Find hyperlink assigned to the supplied shape
+ *
+ * @param shape <code>Shape</code> to lookup hyperlink in
+ * @return found hyperlink or <code>null</code>
+ */
+ protected static Hyperlink find(Shape shape){
+ ArrayList lst = new ArrayList();
+ SlideShow ppt = shape.getSheet().getSlideShow();
+ //document-level container which stores info about all links in a presentation
+ ExObjList exobj = ppt.getDocumentRecord().getExObjList();
+ if (exobj == null) {
+ return null;
+ }
+
+ EscherContainerRecord spContainer = shape.getSpContainer();
+ for (Iterator<EscherRecord> it = spContainer.getChildIterator(); it.hasNext(); ) {
+ EscherRecord obj = it.next();
+ if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID){
+ byte[] data = obj.serialize();
+ Record[] records = Record.findChildRecords(data, 8, data.length-8);
+ if(records != null) find(records, exobj, lst);
+ }
+ }
+
+ return lst.size() == 1 ? (Hyperlink)lst.get(0) : null;
+ }
+
+ private static void find(Record[] records, ExObjList exobj, List out){
+ for (int i = 0; i < records.length; i++) {
+ //see if we have InteractiveInfo in the textrun's records
+ if( records[i] instanceof InteractiveInfo){
+ InteractiveInfo hldr = (InteractiveInfo)records[i];
+ InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
+ int id = info.getHyperlinkID();
+ ExHyperlink linkRecord = exobj.get(id);
+ if (linkRecord != null){
+ Hyperlink link = new Hyperlink();
+ link.title = linkRecord.getLinkTitle();
+ link.address = linkRecord.getLinkURL();
+ link.type = info.getAction();
+
+ if (++i < records.length && records[i] instanceof TxInteractiveInfoAtom){
+ TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[i];
+ link.startIndex = txinfo.getStartIndex();
+ link.endIndex = txinfo.getEndIndex();
+ }
+ out.add(link);
+ }
+ }
+ }
+ }
+}
*
* @author Yegor Kozlov
*/
-public class Line extends SimpleShape {
+public final class Line extends SimpleShape {
/**
* Solid (continuous) pen
*/
EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
short type = (ShapeTypes.Line << 4) | 0x2;
spRecord.setOptions(type);
-
+
//set default properties for a line
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hslf.model;
import org.apache.poi.hslf.record.SheetContainer;
* The superclass of all master sheets - Slide masters, Notes masters, etc.
*
* For now it's empty. When we understand more about masters in ppt we will add the common functionality here.
- *
+ *
* @author Yegor Kozlov
*/
public abstract class MasterSheet extends Sheet {
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-\r
-import org.apache.poi.ddf.EscherClientDataRecord;\r
-import org.apache.poi.ddf.EscherContainerRecord;\r
-import org.apache.poi.ddf.EscherProperties;\r
-import org.apache.poi.hslf.exceptions.HSLFException;\r
-import org.apache.poi.hslf.record.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-/**\r
- * Represents a movie in a PowerPoint document.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public final class MovieShape extends Picture {\r
- public static final int DEFAULT_MOVIE_THUMBNAIL = -1;\r
-\r
- public static final int MOVIE_MPEG = 1;\r
- public static final int MOVIE_AVI = 2;\r
-\r
- /**\r
- * Create a new <code>Picture</code>\r
- *\r
- * @param pictureIdx the index of the picture\r
- */\r
- public MovieShape(int movieIdx, int pictureIdx){\r
- super(pictureIdx, null);\r
- setMovieIndex(movieIdx);\r
- setAutoPlay(true);\r
- }\r
-\r
- /**\r
- * Create a new <code>Picture</code>\r
- *\r
- * @param idx the index of the picture\r
- * @param parent the parent shape\r
- */\r
- public MovieShape(int movieIdx, int idx, Shape parent) {\r
- super(idx, parent);\r
- setMovieIndex(movieIdx);\r
- }\r
-\r
- /**\r
- * Create a <code>Picture</code> object\r
- *\r
- * @param escherRecord the <code>EscherSpContainer</code> record which holds information about\r
- * this picture in the <code>Slide</code>\r
- * @param parent the parent shape of this picture\r
- */\r
- protected MovieShape(EscherContainerRecord escherRecord, Shape parent){\r
- super(escherRecord, parent);\r
- }\r
-\r
- /**\r
- * Create a new Placeholder and initialize internal structures\r
- *\r
- * @return the created <code>EscherContainerRecord</code> which holds shape data\r
- */\r
- protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {\r
- _escherContainer = super.createSpContainer(idx, isChild);\r
-\r
- setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x1000100);\r
- setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x10001);\r
-\r
- EscherClientDataRecord cldata = new EscherClientDataRecord();\r
- cldata.setOptions((short)0xF);\r
- _escherContainer.addChildRecord(cldata);\r
-\r
- OEShapeAtom oe = new OEShapeAtom();\r
- InteractiveInfo info = new InteractiveInfo();\r
- InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();\r
- infoAtom.setAction(InteractiveInfoAtom.ACTION_MEDIA);\r
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_NULL);\r
-\r
- AnimationInfo an = new AnimationInfo();\r
- AnimationInfoAtom anAtom = an.getAnimationInfoAtom();\r
- anAtom.setFlag(AnimationInfoAtom.Automatic, true);\r
-\r
- //convert hslf into ddf\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- try {\r
- oe.writeOut(out);\r
- an.writeOut(out);\r
- info.writeOut(out);\r
- } catch(Exception e){\r
- throw new HSLFException(e);\r
- }\r
- cldata.setRemainingData(out.toByteArray());\r
-\r
- return _escherContainer;\r
- }\r
-\r
- /**\r
- * Assign a movie to this shape\r
- *\r
- * @see org.apache.poi.hslf.usermodel.SlideShow#addMovie(String, int)\r
- * @param idx the index of the movie\r
- */\r
- public void setMovieIndex(int idx){\r
- OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);\r
- oe.setOptions(idx);\r
-\r
- AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);\r
- if(an != null) {\r
- AnimationInfoAtom ai = an.getAnimationInfoAtom();\r
- ai.setDimColor(0x07000000);\r
- ai.setFlag(AnimationInfoAtom.Automatic, true);\r
- ai.setFlag(AnimationInfoAtom.Play, true);\r
- ai.setFlag(AnimationInfoAtom.Synchronous, true);\r
- ai.setOrderID(idx + 1);\r
- }\r
- }\r
-\r
- public void setAutoPlay(boolean flag){\r
- AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);\r
- if(an != null){\r
- an.getAnimationInfoAtom().setFlag(AnimationInfoAtom.Automatic, flag);\r
- updateClientData();\r
- }\r
- }\r
-\r
- public boolean isAutoPlay(){\r
- AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);\r
- if(an != null){\r
- return an.getAnimationInfoAtom().getFlag(AnimationInfoAtom.Automatic);\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * Returns UNC or local path to a video file\r
- *\r
- * @return UNC or local path to a video file\r
- */\r
- public String getPath(){\r
- OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);\r
- int idx = oe.getOptions();\r
-\r
- SlideShow ppt = getSheet().getSlideShow();\r
- ExObjList lst = (ExObjList)ppt.getDocumentRecord().findFirstOfType(RecordTypes.ExObjList.typeID);\r
- if(lst == null) return null;\r
-\r
- Record[] r = lst.getChildRecords();\r
- for (int i = 0; i < r.length; i++) {\r
- if(r[i] instanceof ExMCIMovie){\r
- ExMCIMovie mci = (ExMCIMovie)r[i];\r
- ExVideoContainer exVideo = mci.getExVideo();\r
- int objectId = exVideo.getExMediaAtom().getObjectId();\r
- if(objectId == idx){\r
- return exVideo.getPathAtom().getText();\r
- }\r
- }\r
-\r
- }\r
- return null;\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import java.io.ByteArrayOutputStream;
+
+import org.apache.poi.ddf.EscherClientDataRecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+/**
+ * Represents a movie in a PowerPoint document.
+ *
+ * @author Yegor Kozlov
+ */
+public final class MovieShape extends Picture {
+ public static final int DEFAULT_MOVIE_THUMBNAIL = -1;
+
+ public static final int MOVIE_MPEG = 1;
+ public static final int MOVIE_AVI = 2;
+
+ /**
+ * Create a new <code>Picture</code>
+ *
+ * @param pictureIdx the index of the picture
+ */
+ public MovieShape(int movieIdx, int pictureIdx){
+ super(pictureIdx, null);
+ setMovieIndex(movieIdx);
+ setAutoPlay(true);
+ }
+
+ /**
+ * Create a new <code>Picture</code>
+ *
+ * @param idx the index of the picture
+ * @param parent the parent shape
+ */
+ public MovieShape(int movieIdx, int idx, Shape parent) {
+ super(idx, parent);
+ setMovieIndex(movieIdx);
+ }
+
+ /**
+ * Create a <code>Picture</code> object
+ *
+ * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
+ * this picture in the <code>Slide</code>
+ * @param parent the parent shape of this picture
+ */
+ protected MovieShape(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+ }
+
+ /**
+ * Create a new Placeholder and initialize internal structures
+ *
+ * @return the created <code>EscherContainerRecord</code> which holds shape data
+ */
+ protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
+ _escherContainer = super.createSpContainer(idx, isChild);
+
+ setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x1000100);
+ setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x10001);
+
+ EscherClientDataRecord cldata = new EscherClientDataRecord();
+ cldata.setOptions((short)0xF);
+ _escherContainer.addChildRecord(cldata);
+
+ OEShapeAtom oe = new OEShapeAtom();
+ InteractiveInfo info = new InteractiveInfo();
+ InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_MEDIA);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_NULL);
+
+ AnimationInfo an = new AnimationInfo();
+ AnimationInfoAtom anAtom = an.getAnimationInfoAtom();
+ anAtom.setFlag(AnimationInfoAtom.Automatic, true);
+
+ //convert hslf into ddf
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ oe.writeOut(out);
+ an.writeOut(out);
+ info.writeOut(out);
+ } catch(Exception e){
+ throw new HSLFException(e);
+ }
+ cldata.setRemainingData(out.toByteArray());
+
+ return _escherContainer;
+ }
+
+ /**
+ * Assign a movie to this shape
+ *
+ * @see org.apache.poi.hslf.usermodel.SlideShow#addMovie(String, int)
+ * @param idx the index of the movie
+ */
+ public void setMovieIndex(int idx){
+ OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
+ oe.setOptions(idx);
+
+ AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);
+ if(an != null) {
+ AnimationInfoAtom ai = an.getAnimationInfoAtom();
+ ai.setDimColor(0x07000000);
+ ai.setFlag(AnimationInfoAtom.Automatic, true);
+ ai.setFlag(AnimationInfoAtom.Play, true);
+ ai.setFlag(AnimationInfoAtom.Synchronous, true);
+ ai.setOrderID(idx + 1);
+ }
+ }
+
+ public void setAutoPlay(boolean flag){
+ AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);
+ if(an != null){
+ an.getAnimationInfoAtom().setFlag(AnimationInfoAtom.Automatic, flag);
+ updateClientData();
+ }
+ }
+
+ public boolean isAutoPlay(){
+ AnimationInfo an = (AnimationInfo)getClientDataRecord(RecordTypes.AnimationInfo.typeID);
+ if(an != null){
+ return an.getAnimationInfoAtom().getFlag(AnimationInfoAtom.Automatic);
+ }
+ return false;
+ }
+
+ /**
+ * @return UNC or local path to a video file
+ */
+ public String getPath(){
+ OEShapeAtom oe = (OEShapeAtom)getClientDataRecord(RecordTypes.OEShapeAtom.typeID);
+ int idx = oe.getOptions();
+
+ SlideShow ppt = getSheet().getSlideShow();
+ ExObjList lst = (ExObjList)ppt.getDocumentRecord().findFirstOfType(RecordTypes.ExObjList.typeID);
+ if(lst == null) return null;
+
+ Record[] r = lst.getChildRecords();
+ for (int i = 0; i < r.length; i++) {
+ if(r[i] instanceof ExMCIMovie){
+ ExMCIMovie mci = (ExMCIMovie)r[i];
+ ExVideoContainer exVideo = mci.getExVideo();
+ int objectId = exVideo.getExMediaAtom().getObjectId();
+ if(objectId == idx){
+ return exVideo.getPathAtom().getText();
+ }
+ }
+
+ }
+ return null;
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.model;
/**
- * This class represents a slide's notes in a PowerPoint Document. It
- * allows access to the text within, and the layout. For now, it only
+ * This class represents a slide's notes in a PowerPoint Document. It
+ * allows access to the text within, and the layout. For now, it only
* does the text side of things though
*
* @author Nick Burch
*/
-public class Notes extends Sheet
+public final class Notes extends Sheet
{
private TextRun[] _runs;
super(notes, notes.getNotesAtom().getSlideID());
// Now, build up TextRuns from pairs of TextHeaderAtom and
- // one of TextBytesAtom or TextCharsAtom, found inside
+ // one of TextBytesAtom or TextCharsAtom, found inside
// EscherTextboxWrapper's in the PPDrawing
_runs = findTextRuns(getPPDrawing());
-/*\r
-* Licensed to the Apache Software Foundation (ASF) under one or more\r
-* contributor license agreements. See the NOTICE file distributed with\r
-* this work for additional information regarding copyright ownership.\r
-* The ASF licenses this file to You under the Apache License, Version 2.0\r
-* (the "License"); you may not use this file except in compliance with\r
-* the License. You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.ObjectData;\r
-import org.apache.poi.hslf.record.ExObjList;\r
-import org.apache.poi.hslf.record.Record;\r
-import org.apache.poi.hslf.record.ExEmbed;\r
-import org.apache.poi.util.POILogger;\r
-\r
-\r
-/**\r
- * A shape representing embedded OLE obejct.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class OLEShape extends Picture {\r
- protected ExEmbed _exEmbed;\r
-\r
- /**\r
- * Create a new <code>OLEShape</code>\r
- *\r
- * @param idx the index of the picture\r
- */\r
- public OLEShape(int idx){\r
- super(idx);\r
- }\r
-\r
- /**\r
- * Create a new <code>OLEShape</code>\r
- *\r
- * @param idx the index of the picture\r
- * @param parent the parent shape\r
- */\r
- public OLEShape(int idx, Shape parent) {\r
- super(idx, parent);\r
- }\r
-\r
- /**\r
- * Create a <code>OLEShape</code> object\r
- *\r
- * @param escherRecord the <code>EscherSpContainer</code> record which holds information about\r
- * this picture in the <code>Slide</code>\r
- * @param parent the parent shape of this picture\r
- */\r
- protected OLEShape(EscherContainerRecord escherRecord, Shape parent){\r
- super(escherRecord, parent);\r
- }\r
-\r
- /**\r
- * Returns unique identifier for the OLE object.\r
- *\r
- * @return the unique identifier for the OLE object\r
- */\r
- public int getObjectID(){\r
- return getEscherProperty(EscherProperties.BLIP__PICTUREID);\r
- }\r
-\r
- /**\r
- * Returns unique identifier for the OLE object.\r
- *\r
- * @return the unique identifier for the OLE object\r
- */\r
- public ObjectData getObjectData(){\r
- SlideShow ppt = getSheet().getSlideShow();\r
- ObjectData[] ole = ppt.getEmbeddedObjects();\r
-\r
- //persist reference\r
- int ref = getExEmbed().getExOleObjAtom().getObjStgDataRef();\r
- for (int i = 0; i < ole.length; i++) {\r
- if(ole[i].getExOleObjStg().getPersistId() == ref) return ole[i];\r
-\r
- }\r
- logger.log(POILogger.WARN, "OLE data not found");\r
- return null;\r
- }\r
-\r
- /**\r
- * Return the record container for this embedded object.\r
- *\r
- * <p>\r
- * It contains:\r
- * 1. ExEmbedAtom.(4045)\r
- * 2. ExOleObjAtom (4035)\r
- * 3. CString (4026), Instance MenuName (1) used for menus and the Links dialog box.\r
- * 4. CString (4026), Instance ProgID (2) that stores the OLE Programmatic Identifier.\r
- * A ProgID is a string that uniquely identifies a given object.\r
- * 5. CString (4026), Instance ClipboardName (3) that appears in the paste special dialog.\r
- * 6. MetaFile( 4033), optional\r
- * </p>\r
- */\r
- public ExEmbed getExEmbed(){\r
- if(_exEmbed == null){\r
- SlideShow ppt = getSheet().getSlideShow();\r
-\r
- ExObjList lst = ppt.getDocumentRecord().getExObjList();\r
- if(lst == null){\r
- logger.log(POILogger.WARN, "ExObjList not found");\r
- return null;\r
- }\r
-\r
- int id = getObjectID();\r
- Record[] ch = lst.getChildRecords();\r
- for (int i = 0; i < ch.length; i++) {\r
- if(ch[i] instanceof ExEmbed){\r
- ExEmbed embd = (ExEmbed)ch[i];\r
- if( embd.getExOleObjAtom().getObjID() == id) _exEmbed = embd;\r
- }\r
- }\r
- }\r
- return _exEmbed;\r
- }\r
-\r
- /**\r
- * Returns the instance name of the embedded object, e.g. "Document" or "Workbook".\r
- *\r
- * @return the instance name of the embedded object\r
- */\r
- public String getInstanceName(){\r
- return getExEmbed().getMenuName();\r
- }\r
-\r
- /**\r
- * Returns the full name of the embedded object,\r
- * e.g. "Microsoft Word Document" or "Microsoft Office Excel Worksheet".\r
- *\r
- * @return the full name of the embedded object\r
- */\r
- public String getFullName(){\r
- return getExEmbed().getClipboardName();\r
- }\r
-\r
- /**\r
- * Returns the ProgID that stores the OLE Programmatic Identifier.\r
- * A ProgID is a string that uniquely identifies a given object, for example,\r
- * "Word.Document.8" or "Excel.Sheet.8".\r
- *\r
- * @return the ProgID\r
- */\r
- public String getProgID(){\r
- return getExEmbed().getProgId();\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.ObjectData;
+import org.apache.poi.hslf.record.ExObjList;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.ExEmbed;
+import org.apache.poi.util.POILogger;
+
+
+/**
+ * A shape representing embedded OLE obejct.
+ *
+ * @author Yegor Kozlov
+ */
+public final class OLEShape extends Picture {
+ protected ExEmbed _exEmbed;
+
+ /**
+ * Create a new <code>OLEShape</code>
+ *
+ * @param idx the index of the picture
+ */
+ public OLEShape(int idx){
+ super(idx);
+ }
+
+ /**
+ * Create a new <code>OLEShape</code>
+ *
+ * @param idx the index of the picture
+ * @param parent the parent shape
+ */
+ public OLEShape(int idx, Shape parent) {
+ super(idx, parent);
+ }
+
+ /**
+ * Create a <code>OLEShape</code> object
+ *
+ * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
+ * this picture in the <code>Slide</code>
+ * @param parent the parent shape of this picture
+ */
+ protected OLEShape(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+ }
+
+ /**
+ * Returns unique identifier for the OLE object.
+ *
+ * @return the unique identifier for the OLE object
+ */
+ public int getObjectID(){
+ return getEscherProperty(EscherProperties.BLIP__PICTUREID);
+ }
+
+ /**
+ * Returns unique identifier for the OLE object.
+ *
+ * @return the unique identifier for the OLE object
+ */
+ public ObjectData getObjectData(){
+ SlideShow ppt = getSheet().getSlideShow();
+ ObjectData[] ole = ppt.getEmbeddedObjects();
+
+ //persist reference
+ int ref = getExEmbed().getExOleObjAtom().getObjStgDataRef();
+ for (int i = 0; i < ole.length; i++) {
+ if(ole[i].getExOleObjStg().getPersistId() == ref) return ole[i];
+
+ }
+ logger.log(POILogger.WARN, "OLE data not found");
+ return null;
+ }
+
+ /**
+ * Return the record container for this embedded object.
+ *
+ * <p>
+ * It contains:
+ * 1. ExEmbedAtom.(4045)
+ * 2. ExOleObjAtom (4035)
+ * 3. CString (4026), Instance MenuName (1) used for menus and the Links dialog box.
+ * 4. CString (4026), Instance ProgID (2) that stores the OLE Programmatic Identifier.
+ * A ProgID is a string that uniquely identifies a given object.
+ * 5. CString (4026), Instance ClipboardName (3) that appears in the paste special dialog.
+ * 6. MetaFile( 4033), optional
+ * </p>
+ */
+ public ExEmbed getExEmbed(){
+ if(_exEmbed == null){
+ SlideShow ppt = getSheet().getSlideShow();
+
+ ExObjList lst = ppt.getDocumentRecord().getExObjList();
+ if(lst == null){
+ logger.log(POILogger.WARN, "ExObjList not found");
+ return null;
+ }
+
+ int id = getObjectID();
+ Record[] ch = lst.getChildRecords();
+ for (int i = 0; i < ch.length; i++) {
+ if(ch[i] instanceof ExEmbed){
+ ExEmbed embd = (ExEmbed)ch[i];
+ if( embd.getExOleObjAtom().getObjID() == id) _exEmbed = embd;
+ }
+ }
+ }
+ return _exEmbed;
+ }
+
+ /**
+ * Returns the instance name of the embedded object, e.g. "Document" or "Workbook".
+ *
+ * @return the instance name of the embedded object
+ */
+ public String getInstanceName(){
+ return getExEmbed().getMenuName();
+ }
+
+ /**
+ * Returns the full name of the embedded object,
+ * e.g. "Microsoft Word Document" or "Microsoft Office Excel Worksheet".
+ *
+ * @return the full name of the embedded object
+ */
+ public String getFullName(){
+ return getExEmbed().getClipboardName();
+ }
+
+ /**
+ * Returns the ProgID that stores the OLE Programmatic Identifier.
+ * A ProgID is a string that uniquely identifies a given object, for example,
+ * "Word.Document.8" or "Excel.Sheet.8".
+ *
+ * @return the ProgID
+ */
+ public String getProgID(){
+ return getExEmbed().getProgId();
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.hslf.record.FontEntityAtom;\r
-\r
-/**\r
- * Represents a Font used in a presenation.\r
- * <p>\r
- * In PowerPoint Font is a shared resource and can be shared among text object in the presentation.\r
- * </p>\r
- * Some commonly used fonts are predefined in static constants. \r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class PPFont {\r
- /**\r
- * ANSI character set\r
- */\r
- public final static byte ANSI_CHARSET = 0;\r
-\r
- /**\r
- * Default character set.\r
- */\r
- public final static byte DEFAULT_CHARSET = 1;\r
-\r
- /**\r
- * Symbol character set\r
- */\r
- public final static byte SYMBOL_CHARSET = 2;\r
-\r
-\r
- /**\r
- * Constants for the pitch and family of the font.\r
- * The two low-order bits specify the pitch of the font and can be one of the following values\r
- */\r
- public final static byte DEFAULT_PITCH = 0;\r
- public final static byte FIXED_PITCH = 1;\r
- public final static byte VARIABLE_PITCH = 2;\r
-\r
- /**\r
- * Don't care or don't know.\r
- */\r
- public final static byte FF_DONTCARE = 0;\r
- /**\r
- * Fonts with variable stroke width (proportional) and with serifs. Times New Roman is an example.\r
- */\r
- public final static byte FF_ROMAN = 16;\r
- /**\r
- * Fonts with variable stroke width (proportional) and without serifs. Arial is an example.\r
- */\r
- public final static byte FF_SWISS = 32;\r
- /**\r
- * Fonts designed to look like handwriting. Script and Cursive are examples.\r
- */\r
- public final static byte FF_SCRIPT = 64;\r
- /**\r
- * Fonts with constant stroke width (monospace), with or without serifs.\r
- * Monospace fonts are usually modern. CourierNew is an example\r
- */\r
- public final static byte FF_MODERN = 48;\r
- /**\r
- * Novelty fonts. Old English is an example\r
- */\r
- public final static byte FF_DECORATIVE = 80;\r
-\r
-\r
- protected int charset;\r
- protected int type;\r
- protected int flags;\r
- protected int pitch;\r
- protected String name;\r
-\r
- /**\r
- * Creates a new instance of PPFont\r
- */\r
- public PPFont(){\r
-\r
- }\r
-\r
- /**\r
- * Creates a new instance of PPFont and initialize it from the supplied font atom\r
- */\r
- public PPFont(FontEntityAtom fontAtom){\r
- name = fontAtom.getFontName();\r
- charset = fontAtom.getCharSet();\r
- type = fontAtom.getFontType();\r
- flags = fontAtom.getFontFlags();\r
- pitch = fontAtom.getPitchAndFamily();\r
- }\r
-\r
- /**\r
- * set the name for the font (i.e. Arial)\r
- *\r
- * @param val String representing the name of the font to use\r
- */\r
- public void setFontName(String val){\r
- name = val;\r
- }\r
-\r
- /**\r
- * get the name for the font (i.e. Arial)\r
- *\r
- * @return String representing the name of the font to use\r
- */\r
- public String getFontName(){\r
- return name;\r
- }\r
-\r
- /**\r
- * set the character set\r
- *\r
- * @param val - characterset\r
- */\r
- public void setCharSet(int val){\r
- charset = val;\r
- }\r
-\r
- /**\r
- * get the character set\r
- *\r
- * @return charset - characterset\r
- */\r
- public int getCharSet(){\r
- return charset;\r
- }\r
-\r
- /**\r
- * set the font flags\r
- * Bit 1: If set, font is subsetted\r
- *\r
- * @param val - the font flags\r
- */\r
- public void setFontFlags(int val){\r
- flags = val;\r
- }\r
-\r
- /**\r
- * get the character set\r
- * Bit 1: If set, font is subsetted\r
- *\r
- * @return the font flags\r
- */\r
- public int getFontFlags(){\r
- return flags;\r
- }\r
-\r
- /**\r
- * set the font type\r
- * <p>\r
- * Bit 1: Raster Font\r
- * Bit 2: Device Font\r
- * Bit 3: TrueType Font\r
- * </p>\r
- *\r
- * @param val - the font type\r
- */\r
- public void setFontType(int val){\r
- type = val;\r
- }\r
-\r
- /**\r
- * get the font type\r
- * <p>\r
- * Bit 1: Raster Font\r
- * Bit 2: Device Font\r
- * Bit 3: TrueType Font\r
- * </p>\r
- *\r
- * @return the font type\r
- */\r
- public int getFontType(){\r
- return type;\r
- }\r
-\r
- /**\r
- * set lfPitchAndFamily\r
- *\r
- *\r
- * @param val - Corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure\r
- */\r
- public void setPitchAndFamily(int val){\r
- pitch = val;\r
- }\r
-\r
- /**\r
- * get lfPitchAndFamily\r
- *\r
- * @return corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure\r
- */\r
- public int getPitchAndFamily(){\r
- return pitch;\r
- }\r
-\r
- public static final PPFont ARIAL;\r
- public static final PPFont TIMES_NEW_ROMAN ;\r
- public static final PPFont COURIER_NEW;\r
- public static final PPFont WINGDINGS;\r
- static {\r
- ARIAL = new PPFont();\r
- ARIAL.setFontName("Arial");\r
- ARIAL.setCharSet(ANSI_CHARSET);\r
- ARIAL.setFontType(4);\r
- ARIAL.setFontFlags(0);\r
- ARIAL.setPitchAndFamily(VARIABLE_PITCH | FF_SWISS);\r
-\r
- TIMES_NEW_ROMAN = new PPFont();\r
- TIMES_NEW_ROMAN.setFontName("Times New Roman");\r
- TIMES_NEW_ROMAN.setCharSet(ANSI_CHARSET);\r
- TIMES_NEW_ROMAN.setFontType(4);\r
- TIMES_NEW_ROMAN.setFontFlags(0);\r
- TIMES_NEW_ROMAN.setPitchAndFamily(VARIABLE_PITCH | FF_ROMAN);\r
-\r
- COURIER_NEW = new PPFont();\r
- COURIER_NEW.setFontName("Courier New");\r
- COURIER_NEW.setCharSet(ANSI_CHARSET);\r
- COURIER_NEW.setFontType(4);\r
- COURIER_NEW.setFontFlags(0);\r
- COURIER_NEW.setPitchAndFamily(FIXED_PITCH | FF_MODERN);\r
-\r
- WINGDINGS = new PPFont();\r
- WINGDINGS.setFontName("Wingdings");\r
- WINGDINGS.setCharSet(SYMBOL_CHARSET);\r
- WINGDINGS.setFontType(4);\r
- WINGDINGS.setFontFlags(0);\r
- WINGDINGS.setPitchAndFamily(VARIABLE_PITCH | FF_DONTCARE);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.hslf.record.FontEntityAtom;
+
+/**
+ * Represents a Font used in a presenation.
+ * <p>
+ * In PowerPoint Font is a shared resource and can be shared among text object in the presentation.
+ * </p>
+ * Some commonly used fonts are predefined in static constants.
+ *
+ * @author Yegor Kozlov
+ */
+public final class PPFont {
+ /**
+ * ANSI character set
+ */
+ public final static byte ANSI_CHARSET = 0;
+
+ /**
+ * Default character set.
+ */
+ public final static byte DEFAULT_CHARSET = 1;
+
+ /**
+ * Symbol character set
+ */
+ public final static byte SYMBOL_CHARSET = 2;
+
+
+ /**
+ * Constants for the pitch and family of the font.
+ * The two low-order bits specify the pitch of the font and can be one of the following values
+ */
+ public final static byte DEFAULT_PITCH = 0;
+ public final static byte FIXED_PITCH = 1;
+ public final static byte VARIABLE_PITCH = 2;
+
+ /**
+ * Don't care or don't know.
+ */
+ public final static byte FF_DONTCARE = 0;
+ /**
+ * Fonts with variable stroke width (proportional) and with serifs. Times New Roman is an example.
+ */
+ public final static byte FF_ROMAN = 16;
+ /**
+ * Fonts with variable stroke width (proportional) and without serifs. Arial is an example.
+ */
+ public final static byte FF_SWISS = 32;
+ /**
+ * Fonts designed to look like handwriting. Script and Cursive are examples.
+ */
+ public final static byte FF_SCRIPT = 64;
+ /**
+ * Fonts with constant stroke width (monospace), with or without serifs.
+ * Monospace fonts are usually modern. CourierNew is an example
+ */
+ public final static byte FF_MODERN = 48;
+ /**
+ * Novelty fonts. Old English is an example
+ */
+ public final static byte FF_DECORATIVE = 80;
+
+
+ protected int charset;
+ protected int type;
+ protected int flags;
+ protected int pitch;
+ protected String name;
+
+ /**
+ * Creates a new instance of PPFont
+ */
+ public PPFont(){
+
+ }
+
+ /**
+ * Creates a new instance of PPFont and initialize it from the supplied font atom
+ */
+ public PPFont(FontEntityAtom fontAtom){
+ name = fontAtom.getFontName();
+ charset = fontAtom.getCharSet();
+ type = fontAtom.getFontType();
+ flags = fontAtom.getFontFlags();
+ pitch = fontAtom.getPitchAndFamily();
+ }
+
+ /**
+ * set the name for the font (i.e. Arial)
+ *
+ * @param val String representing the name of the font to use
+ */
+ public void setFontName(String val){
+ name = val;
+ }
+
+ /**
+ * get the name for the font (i.e. Arial)
+ *
+ * @return String representing the name of the font to use
+ */
+ public String getFontName(){
+ return name;
+ }
+
+ /**
+ * set the character set
+ *
+ * @param val - characterset
+ */
+ public void setCharSet(int val){
+ charset = val;
+ }
+
+ /**
+ * get the character set
+ *
+ * @return charset - characterset
+ */
+ public int getCharSet(){
+ return charset;
+ }
+
+ /**
+ * set the font flags
+ * Bit 1: If set, font is subsetted
+ *
+ * @param val - the font flags
+ */
+ public void setFontFlags(int val){
+ flags = val;
+ }
+
+ /**
+ * get the character set
+ * Bit 1: If set, font is subsetted
+ *
+ * @return the font flags
+ */
+ public int getFontFlags(){
+ return flags;
+ }
+
+ /**
+ * set the font type
+ * <p>
+ * Bit 1: Raster Font
+ * Bit 2: Device Font
+ * Bit 3: TrueType Font
+ * </p>
+ *
+ * @param val - the font type
+ */
+ public void setFontType(int val){
+ type = val;
+ }
+
+ /**
+ * get the font type
+ * <p>
+ * Bit 1: Raster Font
+ * Bit 2: Device Font
+ * Bit 3: TrueType Font
+ * </p>
+ *
+ * @return the font type
+ */
+ public int getFontType(){
+ return type;
+ }
+
+ /**
+ * set lfPitchAndFamily
+ *
+ *
+ * @param val - Corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure
+ */
+ public void setPitchAndFamily(int val){
+ pitch = val;
+ }
+
+ /**
+ * get lfPitchAndFamily
+ *
+ * @return corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure
+ */
+ public int getPitchAndFamily(){
+ return pitch;
+ }
+
+ public static final PPFont ARIAL;
+ public static final PPFont TIMES_NEW_ROMAN ;
+ public static final PPFont COURIER_NEW;
+ public static final PPFont WINGDINGS;
+ static {
+ ARIAL = new PPFont();
+ ARIAL.setFontName("Arial");
+ ARIAL.setCharSet(ANSI_CHARSET);
+ ARIAL.setFontType(4);
+ ARIAL.setFontFlags(0);
+ ARIAL.setPitchAndFamily(VARIABLE_PITCH | FF_SWISS);
+
+ TIMES_NEW_ROMAN = new PPFont();
+ TIMES_NEW_ROMAN.setFontName("Times New Roman");
+ TIMES_NEW_ROMAN.setCharSet(ANSI_CHARSET);
+ TIMES_NEW_ROMAN.setFontType(4);
+ TIMES_NEW_ROMAN.setFontFlags(0);
+ TIMES_NEW_ROMAN.setPitchAndFamily(VARIABLE_PITCH | FF_ROMAN);
+
+ COURIER_NEW = new PPFont();
+ COURIER_NEW.setFontName("Courier New");
+ COURIER_NEW.setCharSet(ANSI_CHARSET);
+ COURIER_NEW.setFontType(4);
+ COURIER_NEW.setFontFlags(0);
+ COURIER_NEW.setPitchAndFamily(FIXED_PITCH | FF_MODERN);
+
+ WINGDINGS = new PPFont();
+ WINGDINGS.setFontName("Wingdings");
+ WINGDINGS.setCharSet(SYMBOL_CHARSET);
+ WINGDINGS.setFontType(4);
+ WINGDINGS.setFontFlags(0);
+ WINGDINGS.setPitchAndFamily(VARIABLE_PITCH | FF_DONTCARE);
+ }
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
*
* @author Yegor Kozlov
*/
-public class PPGraphics2D extends Graphics2D implements Cloneable {
+public final class PPGraphics2D extends Graphics2D implements Cloneable {
protected POILogger log = POILogFactory.getLogger(this.getClass());
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*;
* Windows DIB (BMP)
*/
public static final byte DIB = 7;
-
+
/**
* Create a new <code>Picture</code>
*
/**
* Resize this picture to the default size.
* For PNG and JPEG resizes the image to 100%,
- * for other types sets the default size of 200x200 pixels.
+ * for other types sets the default size of 200x200 pixels.
*/
public void setDefaultSize(){
PictureData pict = getPictureData();
BufferedImage img = null;
try {
img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
- }
+ }
catch (IOException e){}
catch (NegativeArraySizeException ne) {}
-
+
if(img != null) {
// Valid image, set anchor from it
setAnchor(new java.awt.Rectangle(0, 0, img.getWidth()*POINT_DPI/PIXEL_DPI, img.getHeight()*POINT_DPI/PIXEL_DPI));
setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
}
} else {
- //default size of a metafile picture is 200x200
+ //default size of a metafile picture is 200x200
setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
}
}
*
* @author Yegor Kozlov
*/
-public class Placeholder extends TextBox {
+public final class Placeholder extends TextBox {
protected Placeholder(EscherContainerRecord escherRecord, Shape parent){
super(escherRecord, parent);
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-import java.awt.geom.Point2D;\r
-\r
-/**\r
- * A simple closed polygon shape\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class Polygon extends AutoShape {\r
- /**\r
- * Create a Polygon object and initialize it from the supplied Record container.\r
- *\r
- * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape\r
- * @param parent the parent of the shape\r
- */\r
- protected Polygon(EscherContainerRecord escherRecord, Shape parent){\r
- super(escherRecord, parent);\r
-\r
- }\r
-\r
- /**\r
- * Create a new Polygon. This constructor is used when a new shape is created.\r
- *\r
- * @param parent the parent of this Shape. For example, if this text box is a cell\r
- * in a table then the parent is Table.\r
- */\r
- public Polygon(Shape parent){\r
- super(null, parent);\r
- _escherContainer = createSpContainer(ShapeTypes.NotPrimitive, parent instanceof ShapeGroup);\r
- }\r
-\r
- /**\r
- * Create a new Polygon. This constructor is used when a new shape is created.\r
- *\r
- */\r
- public Polygon(){\r
- this(null);\r
- }\r
-\r
- /**\r
- * Set the polygon vertices\r
- *\r
- * @param xPoints\r
- * @param yPoints\r
- */\r
- public void setPoints(float[] xPoints, float[] yPoints)\r
- {\r
- float right = findBiggest(xPoints);\r
- float bottom = findBiggest(yPoints);\r
- float left = findSmallest(xPoints);\r
- float top = findSmallest(yPoints);\r
-\r
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)((right - left)*POINT_DPI/MASTER_DPI)));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)((bottom - top)*POINT_DPI/MASTER_DPI)));\r
-\r
- for (int i = 0; i < xPoints.length; i++) {\r
- xPoints[i] += -left;\r
- yPoints[i] += -top;\r
- }\r
-\r
- int numpoints = xPoints.length;\r
-\r
- EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0] );\r
- verticesProp.setNumberOfElementsInArray(numpoints+1);\r
- verticesProp.setNumberOfElementsInMemory(numpoints+1);\r
- verticesProp.setSizeOfElements(0xFFF0);\r
- for (int i = 0; i < numpoints; i++)\r
- {\r
- byte[] data = new byte[4];\r
- LittleEndian.putShort(data, 0, (short)(xPoints[i]*POINT_DPI/MASTER_DPI));\r
- LittleEndian.putShort(data, 2, (short)(yPoints[i]*POINT_DPI/MASTER_DPI));\r
- verticesProp.setElement(i, data);\r
- }\r
- byte[] data = new byte[4];\r
- LittleEndian.putShort(data, 0, (short)(xPoints[0]*POINT_DPI/MASTER_DPI));\r
- LittleEndian.putShort(data, 2, (short)(yPoints[0]*POINT_DPI/MASTER_DPI));\r
- verticesProp.setElement(numpoints, data);\r
- opt.addEscherProperty(verticesProp);\r
-\r
- EscherArrayProperty segmentsProp = new EscherArrayProperty(EscherProperties.GEOMETRY__SEGMENTINFO, false, null );\r
- segmentsProp.setSizeOfElements(0x0002);\r
- segmentsProp.setNumberOfElementsInArray(numpoints * 2 + 4);\r
- segmentsProp.setNumberOfElementsInMemory(numpoints * 2 + 4);\r
- segmentsProp.setElement(0, new byte[] { (byte)0x00, (byte)0x40 } );\r
- segmentsProp.setElement(1, new byte[] { (byte)0x00, (byte)0xAC } );\r
- for (int i = 0; i < numpoints; i++)\r
- {\r
- segmentsProp.setElement(2 + i * 2, new byte[] { (byte)0x01, (byte)0x00 } );\r
- segmentsProp.setElement(3 + i * 2, new byte[] { (byte)0x00, (byte)0xAC } );\r
- }\r
- segmentsProp.setElement(segmentsProp.getNumberOfElementsInArray() - 2, new byte[] { (byte)0x01, (byte)0x60 } );\r
- segmentsProp.setElement(segmentsProp.getNumberOfElementsInArray() - 1, new byte[] { (byte)0x00, (byte)0x80 } );\r
- opt.addEscherProperty(segmentsProp);\r
-\r
- opt.sortProperties();\r
- }\r
-\r
- /**\r
- * Set the polygon vertices\r
- *\r
- * @param points the polygon vertices\r
- */\r
- public void setPoints(Point2D[] points)\r
- {\r
- float[] xpoints = new float[points.length];\r
- float[] ypoints = new float[points.length];\r
- for (int i = 0; i < points.length; i++) {\r
- xpoints[i] = (float)points[i].getX();\r
- ypoints[i] = (float)points[i].getY();\r
-\r
- }\r
-\r
- setPoints(xpoints, ypoints);\r
- }\r
-\r
- private float findBiggest( float[] values )\r
- {\r
- float result = Float.MIN_VALUE;\r
- for ( int i = 0; i < values.length; i++ )\r
- {\r
- if (values[i] > result)\r
- result = values[i];\r
- }\r
- return result;\r
- }\r
-\r
- private float findSmallest( float[] values )\r
- {\r
- float result = Float.MAX_VALUE;\r
- for ( int i = 0; i < values.length; i++ )\r
- {\r
- if (values[i] < result)\r
- result = values[i];\r
- }\r
- return result;\r
- }\r
-\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.util.LittleEndian;
+
+import java.awt.geom.Point2D;
+
+/**
+ * A simple closed polygon shape
+ *
+ * @author Yegor Kozlov
+ */
+public final class Polygon extends AutoShape {
+ /**
+ * Create a Polygon object and initialize it from the supplied Record container.
+ *
+ * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected Polygon(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+
+ }
+
+ /**
+ * Create a new Polygon. This constructor is used when a new shape is created.
+ *
+ * @param parent the parent of this Shape. For example, if this text box is a cell
+ * in a table then the parent is Table.
+ */
+ public Polygon(Shape parent){
+ super(null, parent);
+ _escherContainer = createSpContainer(ShapeTypes.NotPrimitive, parent instanceof ShapeGroup);
+ }
+
+ /**
+ * Create a new Polygon. This constructor is used when a new shape is created.
+ *
+ */
+ public Polygon(){
+ this(null);
+ }
+
+ /**
+ * Set the polygon vertices
+ *
+ * @param xPoints
+ * @param yPoints
+ */
+ public void setPoints(float[] xPoints, float[] yPoints)
+ {
+ float right = findBiggest(xPoints);
+ float bottom = findBiggest(yPoints);
+ float left = findSmallest(xPoints);
+ float top = findSmallest(yPoints);
+
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, (int)((right - left)*POINT_DPI/MASTER_DPI)));
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, (int)((bottom - top)*POINT_DPI/MASTER_DPI)));
+
+ for (int i = 0; i < xPoints.length; i++) {
+ xPoints[i] += -left;
+ yPoints[i] += -top;
+ }
+
+ int numpoints = xPoints.length;
+
+ EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0] );
+ verticesProp.setNumberOfElementsInArray(numpoints+1);
+ verticesProp.setNumberOfElementsInMemory(numpoints+1);
+ verticesProp.setSizeOfElements(0xFFF0);
+ for (int i = 0; i < numpoints; i++)
+ {
+ byte[] data = new byte[4];
+ LittleEndian.putShort(data, 0, (short)(xPoints[i]*POINT_DPI/MASTER_DPI));
+ LittleEndian.putShort(data, 2, (short)(yPoints[i]*POINT_DPI/MASTER_DPI));
+ verticesProp.setElement(i, data);
+ }
+ byte[] data = new byte[4];
+ LittleEndian.putShort(data, 0, (short)(xPoints[0]*POINT_DPI/MASTER_DPI));
+ LittleEndian.putShort(data, 2, (short)(yPoints[0]*POINT_DPI/MASTER_DPI));
+ verticesProp.setElement(numpoints, data);
+ opt.addEscherProperty(verticesProp);
+
+ EscherArrayProperty segmentsProp = new EscherArrayProperty(EscherProperties.GEOMETRY__SEGMENTINFO, false, null );
+ segmentsProp.setSizeOfElements(0x0002);
+ segmentsProp.setNumberOfElementsInArray(numpoints * 2 + 4);
+ segmentsProp.setNumberOfElementsInMemory(numpoints * 2 + 4);
+ segmentsProp.setElement(0, new byte[] { (byte)0x00, (byte)0x40 } );
+ segmentsProp.setElement(1, new byte[] { (byte)0x00, (byte)0xAC } );
+ for (int i = 0; i < numpoints; i++)
+ {
+ segmentsProp.setElement(2 + i * 2, new byte[] { (byte)0x01, (byte)0x00 } );
+ segmentsProp.setElement(3 + i * 2, new byte[] { (byte)0x00, (byte)0xAC } );
+ }
+ segmentsProp.setElement(segmentsProp.getNumberOfElementsInArray() - 2, new byte[] { (byte)0x01, (byte)0x60 } );
+ segmentsProp.setElement(segmentsProp.getNumberOfElementsInArray() - 1, new byte[] { (byte)0x00, (byte)0x80 } );
+ opt.addEscherProperty(segmentsProp);
+
+ opt.sortProperties();
+ }
+
+ /**
+ * Set the polygon vertices
+ *
+ * @param points the polygon vertices
+ */
+ public void setPoints(Point2D[] points)
+ {
+ float[] xpoints = new float[points.length];
+ float[] ypoints = new float[points.length];
+ for (int i = 0; i < points.length; i++) {
+ xpoints[i] = (float)points[i].getX();
+ ypoints[i] = (float)points[i].getY();
+
+ }
+
+ setPoints(xpoints, ypoints);
+ }
+
+ private float findBiggest( float[] values )
+ {
+ float result = Float.MIN_VALUE;
+ for ( int i = 0; i < values.length; i++ )
+ {
+ if (values[i] > result)
+ result = values[i];
+ }
+ return result;
+ }
+
+ private float findSmallest( float[] values )
+ {
+ float result = Float.MAX_VALUE;
+ for ( int i = 0; i < values.length; i++ )
+ {
+ if (values[i] < result)
+ result = values[i];
+ }
+ return result;
+ }
+
+
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*;
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*;
*
* @author Yegor Kozlov
*/
-public class ShapeFactory {
+public final class ShapeFactory {
// For logging
protected static POILogger logger = POILogFactory.getLogger(ShapeFactory.class);
/**
- * Create a new shape from the data provided.
+ * Create a new shape from the data provided.
*/
public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
} else if (oes != null){
shape = new OLEShape(spContainer, parent);
}
-
+
if(shape == null) shape = new Picture(spContainer, parent);
break;
}
logger.log(POILogger.ERROR, "Shape contained non container escher record, was " + r.getClass().getName());
}
}
-
+
// Put the shapes into an array, and return
Shape[] shapes = shapeList.toArray(new Shape[shapeList.size()]);
return shapes;
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-/**\r
- * Date: Apr 17, 2008\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public interface ShapeOutline {\r
- java.awt.Shape getOutline(Shape shape);\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+/**
+ * Date: Apr 17, 2008
+ *
+ * @author Yegor Kozlov
+ */
+public interface ShapeOutline {
+ java.awt.Shape getOutline(Shape shape);
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-\r
-import org.apache.poi.util.POILogger;\r
-import org.apache.poi.util.POILogFactory;\r
-\r
-import java.awt.*;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-/**\r
- * Paint a shape into java.awt.Graphics2D\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class ShapePainter {\r
- protected static POILogger logger = POILogFactory.getLogger(ShapePainter.class);\r
-\r
- public static void paint(SimpleShape shape, Graphics2D graphics){\r
- Rectangle2D anchor = shape.getLogicalAnchor2D();\r
- java.awt.Shape outline = shape.getOutline();\r
-\r
- //flip vertical\r
- if(shape.getFlipVertical()){\r
- graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());\r
- graphics.scale(1, -1);\r
- graphics.translate(-anchor.getX(), -anchor.getY());\r
- }\r
- //flip horizontal\r
- if(shape.getFlipHorizontal()){\r
- graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());\r
- graphics.scale(-1, 1);\r
- graphics.translate(-anchor.getX() , -anchor.getY());\r
- }\r
-\r
- //rotate transform\r
- double angle = shape.getRotation();\r
-\r
- if(angle != 0){\r
- double centerX = anchor.getX() + anchor.getWidth()/2;\r
- double centerY = anchor.getY() + anchor.getHeight()/2;\r
-\r
- graphics.translate(centerX, centerY);\r
- graphics.rotate(Math.toRadians(angle));\r
- graphics.translate(-centerX, -centerY);\r
- }\r
-\r
- //fill\r
- Color fillColor = shape.getFill().getForegroundColor();\r
- if (fillColor != null) {\r
- //TODO: implement gradient and texture fill patterns\r
- graphics.setPaint(fillColor);\r
- graphics.fill(outline);\r
- }\r
-\r
- //border\r
- Color lineColor = shape.getLineColor();\r
- if (lineColor != null){\r
- graphics.setPaint(lineColor);\r
- float width = (float)shape.getLineWidth();\r
- if(width == 0) width = 0.75f;\r
-\r
- int dashing = shape.getLineDashing();\r
- //TODO: implement more dashing styles\r
- float[] dashptrn = null;\r
- switch(dashing){\r
- case Line.PEN_SOLID:\r
- dashptrn = null;\r
- break;\r
- case Line.PEN_PS_DASH:\r
- dashptrn = new float[]{width, width};\r
- break;\r
- case Line.PEN_DOTGEL:\r
- dashptrn = new float[]{width*4, width*3};\r
- break;\r
- default:\r
- logger.log(POILogger.WARN, "unsupported dashing: " + dashing);\r
- dashptrn = new float[]{width, width};\r
- break;\r
- }\r
-\r
- Stroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashptrn, 0.0f);\r
- graphics.setStroke(stroke);\r
- graphics.draw(outline);\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
+
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Paint a shape into java.awt.Graphics2D
+ *
+ * @author Yegor Kozlov
+ */
+public final class ShapePainter {
+ protected static POILogger logger = POILogFactory.getLogger(ShapePainter.class);
+
+ public static void paint(SimpleShape shape, Graphics2D graphics){
+ Rectangle2D anchor = shape.getLogicalAnchor2D();
+ java.awt.Shape outline = shape.getOutline();
+
+ //flip vertical
+ if(shape.getFlipVertical()){
+ graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
+ graphics.scale(1, -1);
+ graphics.translate(-anchor.getX(), -anchor.getY());
+ }
+ //flip horizontal
+ if(shape.getFlipHorizontal()){
+ graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
+ graphics.scale(-1, 1);
+ graphics.translate(-anchor.getX() , -anchor.getY());
+ }
+
+ //rotate transform
+ double angle = shape.getRotation();
+
+ if(angle != 0){
+ double centerX = anchor.getX() + anchor.getWidth()/2;
+ double centerY = anchor.getY() + anchor.getHeight()/2;
+
+ graphics.translate(centerX, centerY);
+ graphics.rotate(Math.toRadians(angle));
+ graphics.translate(-centerX, -centerY);
+ }
+
+ //fill
+ Color fillColor = shape.getFill().getForegroundColor();
+ if (fillColor != null) {
+ //TODO: implement gradient and texture fill patterns
+ graphics.setPaint(fillColor);
+ graphics.fill(outline);
+ }
+
+ //border
+ Color lineColor = shape.getLineColor();
+ if (lineColor != null){
+ graphics.setPaint(lineColor);
+ float width = (float)shape.getLineWidth();
+ if(width == 0) width = 0.75f;
+
+ int dashing = shape.getLineDashing();
+ //TODO: implement more dashing styles
+ float[] dashptrn = null;
+ switch(dashing){
+ case Line.PEN_SOLID:
+ dashptrn = null;
+ break;
+ case Line.PEN_PS_DASH:
+ dashptrn = new float[]{width, width};
+ break;
+ case Line.PEN_DOTGEL:
+ dashptrn = new float[]{width*4, width*3};
+ break;
+ default:
+ logger.log(POILogger.WARN, "unsupported dashing: " + dashing);
+ dashptrn = new float[]{width, width};
+ break;
+ }
+
+ Stroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashptrn, 0.0f);
+ graphics.setStroke(stroke);
+ graphics.draw(outline);
+ }
+ }
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import org.apache.poi.hslf.exceptions.HSLFException;
*
* @author Yegor Kozlov
*/
-public class ShapeTypes implements org.apache.poi.sl.usermodel.ShapeTypes {
+public final class ShapeTypes implements org.apache.poi.sl.usermodel.ShapeTypes {
/**
* Return name of the shape by id
* @param type - the id of the shape, one of the static constants defined in this class
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*;
lst.toArray(recs);
trun._records = recs;
trun.setIndex(slwtIndex);
-
+
found.add(trun);
i++;
} else {
* @param shape
*/
protected void onAddTextShape(TextShape shape) {
-
+
}
/**
*
* @author Yegor Kozlov
*/
-public class SimpleShape extends Shape {
+public abstract class SimpleShape extends Shape {
/**
* Records stored in EscherClientDataRecord
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.EscherSpRecord;
/**
- * This class represents a slide in a PowerPoint Document. It allows
+ * This class represents a slide in a PowerPoint Document. It allows
* access to the text within, and the layout. For now, it only does
* the text side of things though
*
* @author Yegor Kozlov
*/
-public class Slide extends Sheet
+public final class Slide extends Sheet
{
private int _slideNo;
private SlideAtomsSet _atomSet;
_runs[i].setSheet(this);
}
}
-
+
/**
* Create a new Slide instance
* @param sheetNumber The internal number of the sheet, as used by PersistPtrHolder
sa.setNotesID(notes._getSheetNumber());
}
}
-
+
/**
* Changes the Slide's (external facing) page number.
* @see org.apache.poi.hslf.usermodel.SlideShow#reorderSlide(int, int)
public void setSlideNumber(int newSlideNumber) {
_slideNo = newSlideNumber;
}
-
+
/**
* Called by SlideShow ater a new slide is created.
* <p>
if(spr != null) spr.setShapeId(allocateShapeId());
}
- //PPT doen't increment the number of saved shapes for group descriptor and background
+ //PPT doen't increment the number of saved shapes for group descriptor and background
dg.setNumShapes(1);
}
}
return null;
}
-
+
// Simple Accesser methods follow
/**
}
return super.getColorScheme();
}
-
+
/**
* Get the comment(s) for this slide.
- * Note - for now, only works on PPT 2000 and
+ * Note - for now, only works on PPT 2000 and
* PPT 2003 files. Doesn't work for PPT 97
* ones, as they do their comments oddly.
*/
count++;
}
}
-
+
// Now build
Comment[] comments = new Comment[count];
count = 0;
count++;
}
}
-
+
return comments;
}
}
}
-
+
// None found
return new Comment[0];
}
}
/**
- * Header / Footer settings for this slide.
+ * Header / Footer settings for this slide.
*
* @return Header / Footer settings for this slide
*/
*
* @author Yegor Kozlov
*/
-public class SlideMaster extends MasterSheet {
+public final class SlideMaster extends MasterSheet {
private TextRun[] _runs;
/**
/**
* Pickup a style attribute from the master.
- * This is the "workhorse" which returns the default style attrubutes.
+ * This is the "workhorse" which returns the default style attrubutes.
*/
public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
/**
* Assign SlideShow for this slide master.
* (Used interanlly)
- */
+ */
public void setSlideShow(SlideShow ss) {
super.setSlideShow(ss);
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-import java.util.*;\r
-import java.util.List;\r
-import java.awt.*;\r
-\r
-/**\r
- * Represents a table in a PowerPoint presentation\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class Table extends ShapeGroup {\r
-\r
- protected static final int BORDER_TOP = 1;\r
- protected static final int BORDER_RIGHT = 2;\r
- protected static final int BORDER_BOTTOM = 3;\r
- protected static final int BORDER_LEFT = 4;\r
-\r
- protected static final int BORDERS_ALL = 5;\r
- protected static final int BORDERS_OUTSIDE = 6;\r
- protected static final int BORDERS_INSIDE = 7;\r
- protected static final int BORDERS_NONE = 8;\r
-\r
-\r
- protected TableCell[][] cells;\r
-\r
- /**\r
- * Create a new Table of the given number of rows and columns\r
- *\r
- * @param numrows the number of rows\r
- * @param numcols the number of columns\r
- */\r
- public Table(int numrows, int numcols) {\r
- super();\r
-\r
- if(numrows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1");\r
- if(numcols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1");\r
-\r
- int x=0, y=0, tblWidth=0, tblHeight=0;\r
- cells = new TableCell[numrows][numcols];\r
- for (int i = 0; i < cells.length; i++) {\r
- x = 0;\r
- for (int j = 0; j < cells[i].length; j++) {\r
- cells[i][j] = new TableCell(this);\r
- Rectangle anchor = new Rectangle(x, y, TableCell.DEFAULT_WIDTH, TableCell.DEFAULT_HEIGHT);\r
- cells[i][j].setAnchor(anchor);\r
- x += TableCell.DEFAULT_WIDTH;\r
- }\r
- y += TableCell.DEFAULT_HEIGHT;\r
- }\r
- tblWidth = x;\r
- tblHeight = y;\r
- setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));\r
-\r
- EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);\r
- EscherOptRecord opt = new EscherOptRecord();\r
- opt.setRecordId((short)0xF122);\r
- opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));\r
- EscherArrayProperty p = new EscherArrayProperty((short)0x43A0, false, null);\r
- p.setSizeOfElements(0x0004);\r
- p.setNumberOfElementsInArray(numrows);\r
- p.setNumberOfElementsInMemory(numrows);\r
- opt.addEscherProperty(p);\r
- List<EscherRecord> lst = spCont.getChildRecords();\r
- lst.add(lst.size()-1, opt);\r
- spCont.setChildRecords(lst);\r
- }\r
-\r
- /**\r
- * Create a Table object and initilize it from the supplied Record container.\r
- *\r
- * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape\r
- * @param parent the parent of the shape\r
- */\r
- public Table(EscherContainerRecord escherRecord, Shape parent) {\r
- super(escherRecord, parent);\r
- }\r
-\r
- /**\r
- * Gets a cell\r
- *\r
- * @param row the row index (0-based)\r
- * @param col the column index (0-based)\r
- * @return the cell\r
- */\r
- public TableCell getCell(int row, int col) {\r
- return cells[row][col];\r
- }\r
-\r
- public int getNumberOfColumns() {\r
- return cells[0].length;\r
- }\r
- public int getNumberOfRows() {\r
- return cells.length;\r
- }\r
-\r
- protected void afterInsert(Sheet sh){\r
- super.afterInsert(sh);\r
-\r
- EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);\r
- List<EscherRecord> lst = spCont.getChildRecords();\r
- EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);\r
- EscherArrayProperty p = (EscherArrayProperty)opt.getEscherProperty(1);\r
- for (int i = 0; i < cells.length; i++) {\r
- TableCell cell = cells[i][0];\r
- int rowHeight = cell.getAnchor().height*MASTER_DPI/POINT_DPI;\r
- byte[] val = new byte[4];\r
- LittleEndian.putInt(val, rowHeight);\r
- p.setElement(i, val);\r
- for (int j = 0; j < cells[i].length; j++) {\r
- TableCell c = cells[i][j];\r
- addShape(c);\r
-\r
- Line bt = c.getBorderTop();\r
- if(bt != null) addShape(bt);\r
-\r
- Line br = c.getBorderRight();\r
- if(br != null) addShape(br);\r
-\r
- Line bb = c.getBorderBottom();\r
- if(bb != null) addShape(bb);\r
-\r
- Line bl = c.getBorderLeft();\r
- if(bl != null) addShape(bl);\r
-\r
- }\r
- }\r
-\r
- }\r
-\r
- protected void initTable(){\r
- Shape[] sh = getShapes();\r
- Arrays.sort(sh, new Comparator(){\r
- public int compare( Object o1, Object o2 ) {\r
- Rectangle anchor1 = ((Shape)o1).getAnchor();\r
- Rectangle anchor2 = ((Shape)o2).getAnchor();\r
- int delta = anchor1.y - anchor2.y;\r
- if(delta == 0) delta = anchor1.x - anchor2.y;\r
- return delta;\r
- }\r
- });\r
- int y0 = -1;\r
- int maxrowlen = 0;\r
- ArrayList lst = new ArrayList();\r
- ArrayList row = null;\r
- for (int i = 0; i < sh.length; i++) {\r
- if(sh[i] instanceof TextShape){\r
- Rectangle anchor = sh[i].getAnchor();\r
- if(anchor.y != y0){\r
- y0 = anchor.y;\r
- row = new ArrayList();\r
- lst.add(row);\r
- }\r
- row.add(sh[i]);\r
- maxrowlen = Math.max(maxrowlen, row.size());\r
- }\r
- }\r
- cells = new TableCell[lst.size()][maxrowlen];\r
- for (int i = 0; i < lst.size(); i++) {\r
- row = (ArrayList)lst.get(i);\r
- for (int j = 0; j < row.size(); j++) {\r
- TextShape tx = (TextShape)row.get(j);\r
- cells[i][j] = new TableCell(tx.getSpContainer(), getParent());\r
- cells[i][j].setSheet(tx.getSheet());\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Assign the <code>SlideShow</code> this shape belongs to\r
- *\r
- * @param sheet owner of this shape\r
- */\r
- public void setSheet(Sheet sheet){\r
- super.setSheet(sheet);\r
- if(cells == null) initTable();\r
- }\r
-\r
- /**\r
- * Sets the row height.\r
- *\r
- * @param row the row index (0-based)\r
- * @param height the height to set (in pixels)\r
- */\r
- public void setRowHeight(int row, int height){\r
- int currentHeight = cells[row][0].getAnchor().height;\r
- int dy = height - currentHeight;\r
-\r
- for (int i = row; i < cells.length; i++) {\r
- for (int j = 0; j < cells[i].length; j++) {\r
- Rectangle anchor = cells[i][j].getAnchor();\r
- if(i == row) anchor.height = height;\r
- else anchor.y += dy;\r
- cells[i][j].setAnchor(anchor);\r
- }\r
- }\r
- Rectangle tblanchor = getAnchor();\r
- tblanchor.height += dy;\r
- setAnchor(tblanchor);\r
-\r
- }\r
-\r
- /**\r
- * Sets the column width.\r
- *\r
- * @param col the column index (0-based)\r
- * @param width the width to set (in pixels)\r
- */\r
- public void setColumnWidth(int col, int width){\r
- int currentWidth = cells[0][col].getAnchor().width;\r
- int dx = width - currentWidth;\r
- for (int i = 0; i < cells.length; i++) {\r
- Rectangle anchor = cells[i][col].getAnchor();\r
- anchor.width = width;\r
- cells[i][col].setAnchor(anchor);\r
-\r
- if(col < cells[i].length - 1) for (int j = col+1; j < cells[i].length; j++) {\r
- anchor = cells[i][j].getAnchor();\r
- anchor.x += dx;\r
- cells[i][j].setAnchor(anchor);\r
- }\r
- }\r
- Rectangle tblanchor = getAnchor();\r
- tblanchor.width += dx;\r
- setAnchor(tblanchor);\r
- }\r
-\r
- /**\r
- * Format the table and apply the specified Line to all cell boundaries,\r
- * both outside and inside\r
- *\r
- * @param line the border line\r
- */\r
- public void setAllBorders(Line line){\r
- for (int i = 0; i < cells.length; i++) {\r
- for (int j = 0; j < cells[i].length; j++) {\r
- TableCell cell = cells[i][j];\r
- cell.setBorderTop(cloneBorder(line));\r
- cell.setBorderLeft(cloneBorder(line));\r
- if(j == cells[i].length - 1) cell.setBorderRight(cloneBorder(line));\r
- if(i == cells.length - 1) cell.setBorderBottom(cloneBorder(line));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Format the outside border using the specified Line object\r
- *\r
- * @param line the border line\r
- */\r
- public void setOutsideBorders(Line line){\r
- for (int i = 0; i < cells.length; i++) {\r
- for (int j = 0; j < cells[i].length; j++) {\r
- TableCell cell = cells[i][j];\r
-\r
- if(j == 0) cell.setBorderLeft(cloneBorder(line));\r
- if(j == cells[i].length - 1) cell.setBorderRight(cloneBorder(line));\r
- else {\r
- cell.setBorderLeft(null);\r
- cell.setBorderLeft(null);\r
- }\r
-\r
- if(i == 0) cell.setBorderTop(cloneBorder(line));\r
- else if(i == cells.length - 1) cell.setBorderBottom(cloneBorder(line));\r
- else {\r
- cell.setBorderTop(null);\r
- cell.setBorderBottom(null);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Format the inside border using the specified Line object\r
- *\r
- * @param line the border line\r
- */\r
- public void setInsideBorders(Line line){\r
- for (int i = 0; i < cells.length; i++) {\r
- for (int j = 0; j < cells[i].length; j++) {\r
- TableCell cell = cells[i][j];\r
-\r
- if(j != cells[i].length - 1)\r
- cell.setBorderRight(cloneBorder(line));\r
- else {\r
- cell.setBorderLeft(null);\r
- cell.setBorderLeft(null);\r
- }\r
- if(i != cells.length - 1) cell.setBorderBottom(cloneBorder(line));\r
- else {\r
- cell.setBorderTop(null);\r
- cell.setBorderBottom(null);\r
- }\r
- }\r
- }\r
- }\r
-\r
- private Line cloneBorder(Line line){\r
- Line border = createBorder();\r
- border.setLineWidth(line.getLineWidth());\r
- border.setLineStyle(line.getLineStyle());\r
- border.setLineDashing(line.getLineDashing());\r
- border.setLineColor(line.getLineColor());\r
- return border;\r
- }\r
-\r
- /**\r
- * Create a border to format this table\r
- *\r
- * @return the created border\r
- */\r
- public Line createBorder(){\r
- Line line = new Line(this);\r
-\r
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(line.getSpContainer(), EscherOptRecord.RECORD_ID);\r
- setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1);\r
- setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1);\r
- setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);\r
- setEscherProperty(opt, EscherProperties.THREED__LIGHTFACE, 0x80000);\r
-\r
- return line;\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.util.LittleEndian;
+
+import java.util.*;
+import java.util.List;
+import java.awt.*;
+
+/**
+ * Represents a table in a PowerPoint presentation
+ *
+ * @author Yegor Kozlov
+ */
+public final class Table extends ShapeGroup {
+
+ protected static final int BORDER_TOP = 1;
+ protected static final int BORDER_RIGHT = 2;
+ protected static final int BORDER_BOTTOM = 3;
+ protected static final int BORDER_LEFT = 4;
+
+ protected static final int BORDERS_ALL = 5;
+ protected static final int BORDERS_OUTSIDE = 6;
+ protected static final int BORDERS_INSIDE = 7;
+ protected static final int BORDERS_NONE = 8;
+
+
+ protected TableCell[][] cells;
+
+ /**
+ * Create a new Table of the given number of rows and columns
+ *
+ * @param numrows the number of rows
+ * @param numcols the number of columns
+ */
+ public Table(int numrows, int numcols) {
+ super();
+
+ if(numrows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1");
+ if(numcols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1");
+
+ int x=0, y=0, tblWidth=0, tblHeight=0;
+ cells = new TableCell[numrows][numcols];
+ for (int i = 0; i < cells.length; i++) {
+ x = 0;
+ for (int j = 0; j < cells[i].length; j++) {
+ cells[i][j] = new TableCell(this);
+ Rectangle anchor = new Rectangle(x, y, TableCell.DEFAULT_WIDTH, TableCell.DEFAULT_HEIGHT);
+ cells[i][j].setAnchor(anchor);
+ x += TableCell.DEFAULT_WIDTH;
+ }
+ y += TableCell.DEFAULT_HEIGHT;
+ }
+ tblWidth = x;
+ tblHeight = y;
+ setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
+
+ EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
+ EscherOptRecord opt = new EscherOptRecord();
+ opt.setRecordId((short)0xF122);
+ opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
+ EscherArrayProperty p = new EscherArrayProperty((short)0x43A0, false, null);
+ p.setSizeOfElements(0x0004);
+ p.setNumberOfElementsInArray(numrows);
+ p.setNumberOfElementsInMemory(numrows);
+ opt.addEscherProperty(p);
+ List<EscherRecord> lst = spCont.getChildRecords();
+ lst.add(lst.size()-1, opt);
+ spCont.setChildRecords(lst);
+ }
+
+ /**
+ * Create a Table object and initilize it from the supplied Record container.
+ *
+ * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ public Table(EscherContainerRecord escherRecord, Shape parent) {
+ super(escherRecord, parent);
+ }
+
+ /**
+ * Gets a cell
+ *
+ * @param row the row index (0-based)
+ * @param col the column index (0-based)
+ * @return the cell
+ */
+ public TableCell getCell(int row, int col) {
+ return cells[row][col];
+ }
+
+ public int getNumberOfColumns() {
+ return cells[0].length;
+ }
+ public int getNumberOfRows() {
+ return cells.length;
+ }
+
+ protected void afterInsert(Sheet sh){
+ super.afterInsert(sh);
+
+ EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
+ List<EscherRecord> lst = spCont.getChildRecords();
+ EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);
+ EscherArrayProperty p = (EscherArrayProperty)opt.getEscherProperty(1);
+ for (int i = 0; i < cells.length; i++) {
+ TableCell cell = cells[i][0];
+ int rowHeight = cell.getAnchor().height*MASTER_DPI/POINT_DPI;
+ byte[] val = new byte[4];
+ LittleEndian.putInt(val, rowHeight);
+ p.setElement(i, val);
+ for (int j = 0; j < cells[i].length; j++) {
+ TableCell c = cells[i][j];
+ addShape(c);
+
+ Line bt = c.getBorderTop();
+ if(bt != null) addShape(bt);
+
+ Line br = c.getBorderRight();
+ if(br != null) addShape(br);
+
+ Line bb = c.getBorderBottom();
+ if(bb != null) addShape(bb);
+
+ Line bl = c.getBorderLeft();
+ if(bl != null) addShape(bl);
+
+ }
+ }
+
+ }
+
+ protected void initTable(){
+ Shape[] sh = getShapes();
+ Arrays.sort(sh, new Comparator(){
+ public int compare( Object o1, Object o2 ) {
+ Rectangle anchor1 = ((Shape)o1).getAnchor();
+ Rectangle anchor2 = ((Shape)o2).getAnchor();
+ int delta = anchor1.y - anchor2.y;
+ if(delta == 0) delta = anchor1.x - anchor2.y;
+ return delta;
+ }
+ });
+ int y0 = -1;
+ int maxrowlen = 0;
+ ArrayList lst = new ArrayList();
+ ArrayList row = null;
+ for (int i = 0; i < sh.length; i++) {
+ if(sh[i] instanceof TextShape){
+ Rectangle anchor = sh[i].getAnchor();
+ if(anchor.y != y0){
+ y0 = anchor.y;
+ row = new ArrayList();
+ lst.add(row);
+ }
+ row.add(sh[i]);
+ maxrowlen = Math.max(maxrowlen, row.size());
+ }
+ }
+ cells = new TableCell[lst.size()][maxrowlen];
+ for (int i = 0; i < lst.size(); i++) {
+ row = (ArrayList)lst.get(i);
+ for (int j = 0; j < row.size(); j++) {
+ TextShape tx = (TextShape)row.get(j);
+ cells[i][j] = new TableCell(tx.getSpContainer(), getParent());
+ cells[i][j].setSheet(tx.getSheet());
+ }
+ }
+ }
+
+ /**
+ * Assign the <code>SlideShow</code> this shape belongs to
+ *
+ * @param sheet owner of this shape
+ */
+ public void setSheet(Sheet sheet){
+ super.setSheet(sheet);
+ if(cells == null) initTable();
+ }
+
+ /**
+ * Sets the row height.
+ *
+ * @param row the row index (0-based)
+ * @param height the height to set (in pixels)
+ */
+ public void setRowHeight(int row, int height){
+ int currentHeight = cells[row][0].getAnchor().height;
+ int dy = height - currentHeight;
+
+ for (int i = row; i < cells.length; i++) {
+ for (int j = 0; j < cells[i].length; j++) {
+ Rectangle anchor = cells[i][j].getAnchor();
+ if(i == row) anchor.height = height;
+ else anchor.y += dy;
+ cells[i][j].setAnchor(anchor);
+ }
+ }
+ Rectangle tblanchor = getAnchor();
+ tblanchor.height += dy;
+ setAnchor(tblanchor);
+
+ }
+
+ /**
+ * Sets the column width.
+ *
+ * @param col the column index (0-based)
+ * @param width the width to set (in pixels)
+ */
+ public void setColumnWidth(int col, int width){
+ int currentWidth = cells[0][col].getAnchor().width;
+ int dx = width - currentWidth;
+ for (int i = 0; i < cells.length; i++) {
+ Rectangle anchor = cells[i][col].getAnchor();
+ anchor.width = width;
+ cells[i][col].setAnchor(anchor);
+
+ if(col < cells[i].length - 1) for (int j = col+1; j < cells[i].length; j++) {
+ anchor = cells[i][j].getAnchor();
+ anchor.x += dx;
+ cells[i][j].setAnchor(anchor);
+ }
+ }
+ Rectangle tblanchor = getAnchor();
+ tblanchor.width += dx;
+ setAnchor(tblanchor);
+ }
+
+ /**
+ * Format the table and apply the specified Line to all cell boundaries,
+ * both outside and inside
+ *
+ * @param line the border line
+ */
+ public void setAllBorders(Line line){
+ for (int i = 0; i < cells.length; i++) {
+ for (int j = 0; j < cells[i].length; j++) {
+ TableCell cell = cells[i][j];
+ cell.setBorderTop(cloneBorder(line));
+ cell.setBorderLeft(cloneBorder(line));
+ if(j == cells[i].length - 1) cell.setBorderRight(cloneBorder(line));
+ if(i == cells.length - 1) cell.setBorderBottom(cloneBorder(line));
+ }
+ }
+ }
+
+ /**
+ * Format the outside border using the specified Line object
+ *
+ * @param line the border line
+ */
+ public void setOutsideBorders(Line line){
+ for (int i = 0; i < cells.length; i++) {
+ for (int j = 0; j < cells[i].length; j++) {
+ TableCell cell = cells[i][j];
+
+ if(j == 0) cell.setBorderLeft(cloneBorder(line));
+ if(j == cells[i].length - 1) cell.setBorderRight(cloneBorder(line));
+ else {
+ cell.setBorderLeft(null);
+ cell.setBorderLeft(null);
+ }
+
+ if(i == 0) cell.setBorderTop(cloneBorder(line));
+ else if(i == cells.length - 1) cell.setBorderBottom(cloneBorder(line));
+ else {
+ cell.setBorderTop(null);
+ cell.setBorderBottom(null);
+ }
+ }
+ }
+ }
+
+ /**
+ * Format the inside border using the specified Line object
+ *
+ * @param line the border line
+ */
+ public void setInsideBorders(Line line){
+ for (int i = 0; i < cells.length; i++) {
+ for (int j = 0; j < cells[i].length; j++) {
+ TableCell cell = cells[i][j];
+
+ if(j != cells[i].length - 1)
+ cell.setBorderRight(cloneBorder(line));
+ else {
+ cell.setBorderLeft(null);
+ cell.setBorderLeft(null);
+ }
+ if(i != cells.length - 1) cell.setBorderBottom(cloneBorder(line));
+ else {
+ cell.setBorderTop(null);
+ cell.setBorderBottom(null);
+ }
+ }
+ }
+ }
+
+ private Line cloneBorder(Line line){
+ Line border = createBorder();
+ border.setLineWidth(line.getLineWidth());
+ border.setLineStyle(line.getLineStyle());
+ border.setLineDashing(line.getLineDashing());
+ border.setLineColor(line.getLineColor());
+ return border;
+ }
+
+ /**
+ * Create a border to format this table
+ *
+ * @return the created border
+ */
+ public Line createBorder(){
+ Line line = new Line(this);
+
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(line.getSpContainer(), EscherOptRecord.RECORD_ID);
+ setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1);
+ setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1);
+ setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
+ setEscherProperty(opt, EscherProperties.THREED__LIGHTFACE, 0x80000);
+
+ return line;
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.hslf.record.TextHeaderAtom;\r
-\r
-import java.awt.*;\r
-\r
-/**\r
- * Represents a cell in a ppt table\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TableCell extends TextBox {\r
- protected static final int DEFAULT_WIDTH = 100;\r
- protected static final int DEFAULT_HEIGHT = 40;\r
-\r
- private Line borderLeft;\r
- private Line borderRight;\r
- private Line borderTop;\r
- private Line borderBottom;\r
-\r
- /**\r
- * Create a TableCell object and initialize it from the supplied Record container.\r
- *\r
- * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape\r
- * @param parent the parent of the shape\r
- */\r
- protected TableCell(EscherContainerRecord escherRecord, Shape parent){\r
- super(escherRecord, parent);\r
- }\r
-\r
- /**\r
- * Create a new TableCell. This constructor is used when a new shape is created.\r
- *\r
- * @param parent the parent of this Shape. For example, if this text box is a cell\r
- * in a table then the parent is Table.\r
- */\r
- public TableCell(Shape parent){\r
- super(parent);\r
-\r
- setShapeType(ShapeTypes.Rectangle);\r
- //_txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);\r
- //_txtrun.getRichTextRuns()[0].setFlag(false, 0, false);\r
- }\r
-\r
- protected EscherContainerRecord createSpContainer(boolean isChild){\r
- _escherContainer = super.createSpContainer(isChild);\r
- EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);\r
- setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);\r
- setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);\r
- setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);\r
- setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);\r
-\r
- return _escherContainer;\r
- }\r
-\r
- protected void anchorBorder(int type, Line line){\r
- Rectangle cellAnchor = getAnchor();\r
- Rectangle lineAnchor = new Rectangle();\r
- switch(type){\r
- case Table.BORDER_TOP:\r
- lineAnchor.x = cellAnchor.x;\r
- lineAnchor.y = cellAnchor.y;\r
- lineAnchor.width = cellAnchor.width;\r
- lineAnchor.height = 0;\r
- break;\r
- case Table.BORDER_RIGHT:\r
- lineAnchor.x = cellAnchor.x + cellAnchor.width;\r
- lineAnchor.y = cellAnchor.y;\r
- lineAnchor.width = 0;\r
- lineAnchor.height = cellAnchor.height;\r
- break;\r
- case Table.BORDER_BOTTOM:\r
- lineAnchor.x = cellAnchor.x;\r
- lineAnchor.y = cellAnchor.y + cellAnchor.height;\r
- lineAnchor.width = cellAnchor.width;\r
- lineAnchor.height = 0;\r
- break;\r
- case Table.BORDER_LEFT:\r
- lineAnchor.x = cellAnchor.x;\r
- lineAnchor.y = cellAnchor.y;\r
- lineAnchor.width = 0;\r
- lineAnchor.height = cellAnchor.height;\r
- break;\r
- default:\r
- throw new IllegalArgumentException("Unknown border type: " + type);\r
- }\r
- line.setAnchor(lineAnchor);\r
- }\r
-\r
- public Line getBorderLeft() {\r
- return borderLeft;\r
- }\r
-\r
- public void setBorderLeft(Line line) {\r
- if(line != null) anchorBorder(Table.BORDER_LEFT, line);\r
- this.borderLeft = line;\r
- }\r
-\r
- public Line getBorderRight() {\r
- return borderRight;\r
- }\r
-\r
- public void setBorderRight(Line line) {\r
- if(line != null) anchorBorder(Table.BORDER_RIGHT, line);\r
- this.borderRight = line;\r
- }\r
-\r
- public Line getBorderTop() {\r
- return borderTop;\r
- }\r
-\r
- public void setBorderTop(Line line) {\r
- if(line != null) anchorBorder(Table.BORDER_TOP, line);\r
- this.borderTop = line;\r
- }\r
-\r
- public Line getBorderBottom() {\r
- return borderBottom;\r
- }\r
-\r
- public void setBorderBottom(Line line) {\r
- if(line != null) anchorBorder(Table.BORDER_BOTTOM, line);\r
- this.borderBottom = line;\r
- }\r
-\r
- public void setAnchor(Rectangle anchor){\r
- super.setAnchor(anchor);\r
-\r
- if(borderTop != null) anchorBorder(Table.BORDER_TOP, borderTop);\r
- if(borderRight != null) anchorBorder(Table.BORDER_RIGHT, borderRight);\r
- if(borderBottom != null) anchorBorder(Table.BORDER_BOTTOM, borderBottom);\r
- if(borderLeft != null) anchorBorder(Table.BORDER_LEFT, borderLeft);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+import java.awt.*;
+
+/**
+ * Represents a cell in a ppt table
+ *
+ * @author Yegor Kozlov
+ */
+public final class TableCell extends TextBox {
+ protected static final int DEFAULT_WIDTH = 100;
+ protected static final int DEFAULT_HEIGHT = 40;
+
+ private Line borderLeft;
+ private Line borderRight;
+ private Line borderTop;
+ private Line borderBottom;
+
+ /**
+ * Create a TableCell object and initialize it from the supplied Record container.
+ *
+ * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected TableCell(EscherContainerRecord escherRecord, Shape parent){
+ super(escherRecord, parent);
+ }
+
+ /**
+ * Create a new TableCell. This constructor is used when a new shape is created.
+ *
+ * @param parent the parent of this Shape. For example, if this text box is a cell
+ * in a table then the parent is Table.
+ */
+ public TableCell(Shape parent){
+ super(parent);
+
+ setShapeType(ShapeTypes.Rectangle);
+ //_txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);
+ //_txtrun.getRichTextRuns()[0].setFlag(false, 0, false);
+ }
+
+ protected EscherContainerRecord createSpContainer(boolean isChild){
+ _escherContainer = super.createSpContainer(isChild);
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+ setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
+ setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
+ setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);
+ setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
+ setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
+
+ return _escherContainer;
+ }
+
+ protected void anchorBorder(int type, Line line){
+ Rectangle cellAnchor = getAnchor();
+ Rectangle lineAnchor = new Rectangle();
+ switch(type){
+ case Table.BORDER_TOP:
+ lineAnchor.x = cellAnchor.x;
+ lineAnchor.y = cellAnchor.y;
+ lineAnchor.width = cellAnchor.width;
+ lineAnchor.height = 0;
+ break;
+ case Table.BORDER_RIGHT:
+ lineAnchor.x = cellAnchor.x + cellAnchor.width;
+ lineAnchor.y = cellAnchor.y;
+ lineAnchor.width = 0;
+ lineAnchor.height = cellAnchor.height;
+ break;
+ case Table.BORDER_BOTTOM:
+ lineAnchor.x = cellAnchor.x;
+ lineAnchor.y = cellAnchor.y + cellAnchor.height;
+ lineAnchor.width = cellAnchor.width;
+ lineAnchor.height = 0;
+ break;
+ case Table.BORDER_LEFT:
+ lineAnchor.x = cellAnchor.x;
+ lineAnchor.y = cellAnchor.y;
+ lineAnchor.width = 0;
+ lineAnchor.height = cellAnchor.height;
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown border type: " + type);
+ }
+ line.setAnchor(lineAnchor);
+ }
+
+ public Line getBorderLeft() {
+ return borderLeft;
+ }
+
+ public void setBorderLeft(Line line) {
+ if(line != null) anchorBorder(Table.BORDER_LEFT, line);
+ this.borderLeft = line;
+ }
+
+ public Line getBorderRight() {
+ return borderRight;
+ }
+
+ public void setBorderRight(Line line) {
+ if(line != null) anchorBorder(Table.BORDER_RIGHT, line);
+ this.borderRight = line;
+ }
+
+ public Line getBorderTop() {
+ return borderTop;
+ }
+
+ public void setBorderTop(Line line) {
+ if(line != null) anchorBorder(Table.BORDER_TOP, line);
+ this.borderTop = line;
+ }
+
+ public Line getBorderBottom() {
+ return borderBottom;
+ }
+
+ public void setBorderBottom(Line line) {
+ if(line != null) anchorBorder(Table.BORDER_BOTTOM, line);
+ this.borderBottom = line;
+ }
+
+ public void setAnchor(Rectangle anchor){
+ super.setAnchor(anchor);
+
+ if(borderTop != null) anchorBorder(Table.BORDER_TOP, borderTop);
+ if(borderRight != null) anchorBorder(Table.BORDER_RIGHT, borderRight);
+ if(borderBottom != null) anchorBorder(Table.BORDER_BOTTOM, borderBottom);
+ if(borderLeft != null) anchorBorder(Table.BORDER_LEFT, borderLeft);
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
/**
* Create a TextBox object and initialize it from the supplied Record container.
- *
+ *
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.hslf.usermodel.RichTextRun;\r
-import org.apache.poi.hslf.record.TextRulerAtom;\r
-import org.apache.poi.util.POILogger;\r
-import org.apache.poi.util.POILogFactory;\r
-\r
-import java.text.AttributedString;\r
-import java.text.AttributedCharacterIterator;\r
-import java.text.BreakIterator;\r
-import java.awt.font.TextAttribute;\r
-import java.awt.font.LineBreakMeasurer;\r
-import java.awt.font.TextLayout;\r
-import java.awt.font.FontRenderContext;\r
-import java.awt.*;\r
-import java.awt.geom.Rectangle2D;\r
-import java.awt.geom.Point2D;\r
-import java.util.ArrayList;\r
-\r
-/**\r
- * Paint text into java.awt.Graphics2D\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TextPainter {\r
- protected POILogger logger = POILogFactory.getLogger(this.getClass());\r
-\r
- /**\r
- * Display unicode square if a bullet char can't be displayed,\r
- * for example, if Wingdings font is used.\r
- * TODO: map Wingdngs and Symbol to unicode Arial\r
- */\r
- protected static final char DEFAULT_BULLET_CHAR = '\u25a0';\r
-\r
- protected TextShape _shape;\r
-\r
- public TextPainter(TextShape shape){\r
- _shape = shape;\r
- }\r
-\r
- /**\r
- * Convert the underlying set of rich text runs into java.text.AttributedString\r
- */\r
- public AttributedString getAttributedString(TextRun txrun){\r
- String text = txrun.getText();\r
- //TODO: properly process tabs\r
- text = text.replace('\t', ' ');\r
- text = text.replace((char)160, ' ');\r
-\r
- AttributedString at = new AttributedString(text);\r
- RichTextRun[] rt = txrun.getRichTextRuns();\r
- for (int i = 0; i < rt.length; i++) {\r
- int start = rt[i].getStartIndex();\r
- int end = rt[i].getEndIndex();\r
- if(start == end) {\r
- logger.log(POILogger.INFO, "Skipping RichTextRun with zero length");\r
- continue;\r
- }\r
-\r
- at.addAttribute(TextAttribute.FAMILY, rt[i].getFontName(), start, end);\r
- at.addAttribute(TextAttribute.SIZE, new Float(rt[i].getFontSize()), start, end);\r
- at.addAttribute(TextAttribute.FOREGROUND, rt[i].getFontColor(), start, end);\r
- if(rt[i].isBold()) at.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, start, end);\r
- if(rt[i].isItalic()) at.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, start, end);\r
- if(rt[i].isUnderlined()) {\r
- at.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, start, end);\r
- at.addAttribute(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_TWO_PIXEL, start, end);\r
- }\r
- if(rt[i].isStrikethrough()) at.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, start, end);\r
- int superScript = rt[i].getSuperscript();\r
- if(superScript != 0) at.addAttribute(TextAttribute.SUPERSCRIPT, superScript > 0 ? TextAttribute.SUPERSCRIPT_SUPER : TextAttribute.SUPERSCRIPT_SUB, start, end);\r
-\r
- }\r
- return at;\r
- }\r
-\r
- public void paint(Graphics2D graphics){\r
- Rectangle2D anchor = _shape.getLogicalAnchor2D();\r
- TextElement[] elem = getTextElements((float)anchor.getWidth(), graphics.getFontRenderContext());\r
- if(elem == null) return;\r
-\r
- float textHeight = 0;\r
- for (int i = 0; i < elem.length; i++) {\r
- textHeight += elem[i].ascent + elem[i].descent;\r
- }\r
-\r
- int valign = _shape.getVerticalAlignment();\r
- double y0 = anchor.getY();\r
- switch (valign){\r
- case TextShape.AnchorTopBaseline:\r
- case TextShape.AnchorTop:\r
- y0 += _shape.getMarginTop();\r
- break;\r
- case TextShape.AnchorBottom:\r
- y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();\r
- break;\r
- default:\r
- case TextShape.AnchorMiddle:\r
- float delta = (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();\r
- y0 += _shape.getMarginTop() + delta/2;\r
- break;\r
- }\r
-\r
- //finally draw the text fragments\r
- for (int i = 0; i < elem.length; i++) {\r
- y0 += elem[i].ascent;\r
-\r
- Point2D.Double pen = new Point2D.Double();\r
- pen.y = y0;\r
- switch (elem[i]._align) {\r
- default:\r
- case TextShape.AlignLeft:\r
- pen.x = anchor.getX() + _shape.getMarginLeft();\r
- break;\r
- case TextShape.AlignCenter:\r
- pen.x = anchor.getX() + _shape.getMarginLeft() +\r
- (anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight()) / 2;\r
- break;\r
- case TextShape.AlignRight:\r
- pen.x = anchor.getX() + _shape.getMarginLeft() +\r
- (anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight());\r
- break;\r
- }\r
- if(elem[i]._bullet != null){\r
- graphics.drawString(elem[i]._bullet.getIterator(), (float)(pen.x + elem[i]._bulletOffset), (float)pen.y);\r
- }\r
- AttributedCharacterIterator chIt = elem[i]._text.getIterator();\r
- if(chIt.getEndIndex() > chIt.getBeginIndex()) {\r
- graphics.drawString(chIt, (float)(pen.x + elem[i]._textOffset), (float)pen.y);\r
- }\r
- y0 += elem[i].descent;\r
- }\r
- }\r
-\r
- public TextElement[] getTextElements(float textWidth, FontRenderContext frc){\r
- TextRun run = _shape.getTextRun();\r
- if (run == null) return null;\r
-\r
- String text = run.getText();\r
- if (text == null || text.equals("")) return null;\r
-\r
- AttributedString at = getAttributedString(run);\r
-\r
- AttributedCharacterIterator it = at.getIterator();\r
- int paragraphStart = it.getBeginIndex();\r
- int paragraphEnd = it.getEndIndex();\r
-\r
- ArrayList lines = new ArrayList();\r
- LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);\r
- measurer.setPosition(paragraphStart);\r
- while (measurer.getPosition() < paragraphEnd) {\r
- int startIndex = measurer.getPosition();\r
- int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);\r
-\r
- boolean prStart = text.charAt(startIndex) == '\n';\r
- if(prStart) measurer.setPosition(startIndex++);\r
-\r
- RichTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);\r
- if(rt == null) {\r
- logger.log(POILogger.WARN, "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());\r
- break;\r
- }\r
-\r
- float wrappingWidth = textWidth - _shape.getMarginLeft() - _shape.getMarginRight();\r
- int bulletOffset = rt.getBulletOffset();\r
- int textOffset = rt.getTextOffset();\r
- int indent = rt.getIndentLevel();\r
-\r
- TextRulerAtom ruler = run.getTextRuler();\r
- if(ruler != null) {\r
- int bullet_val = ruler.getBulletOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;\r
- int text_val = ruler.getTextOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;\r
- if(bullet_val > text_val){\r
- int a = bullet_val;\r
- bullet_val = text_val;\r
- text_val = a;\r
- }\r
- if(bullet_val != 0 ) bulletOffset = bullet_val;\r
- if(text_val != 0) textOffset = text_val;\r
- }\r
-\r
- if(bulletOffset > 0 || prStart || startIndex == 0) wrappingWidth -= textOffset;\r
-\r
- if (_shape.getWordWrap() == TextShape.WrapNone) {\r
- wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;\r
- }\r
-\r
- TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,\r
- nextBreak == -1 ? paragraphEnd : nextBreak, true);\r
- if (textLayout == null) {\r
- textLayout = measurer.nextLayout(textWidth,\r
- nextBreak == -1 ? paragraphEnd : nextBreak, false);\r
- }\r
- if(textLayout == null){\r
- logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+\r
- "; text: " + rt.getText());\r
- measurer.setPosition(rt.getEndIndex());\r
- continue;\r
- }\r
- int endIndex = measurer.getPosition();\r
-\r
- float lineHeight = (float)textLayout.getBounds().getHeight();\r
- int linespacing = rt.getLineSpacing();\r
- if(linespacing == 0) linespacing = 100;\r
-\r
- TextElement el = new TextElement();\r
- if(linespacing >= 0){\r
- el.ascent = textLayout.getAscent()*linespacing/100;\r
- } else {\r
- el.ascent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;\r
- }\r
-\r
- el._align = rt.getAlignment();\r
- el.advance = textLayout.getAdvance();\r
- el._textOffset = textOffset;\r
- el._text = new AttributedString(it, startIndex, endIndex);\r
- el.textStartIndex = startIndex;\r
- el.textEndIndex = endIndex;\r
-\r
- if (prStart){\r
- int sp = rt.getSpaceBefore();\r
- float spaceBefore;\r
- if(sp >= 0){\r
- spaceBefore = lineHeight * sp/100;\r
- } else {\r
- spaceBefore = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;\r
- }\r
- el.ascent += spaceBefore;\r
- }\r
-\r
- float descent;\r
- if(linespacing >= 0){\r
- descent = (textLayout.getDescent() + textLayout.getLeading())*linespacing/100;\r
- } else {\r
- descent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;\r
- }\r
- if (prStart){\r
- int sp = rt.getSpaceAfter();\r
- float spaceAfter;\r
- if(sp >= 0){\r
- spaceAfter = lineHeight * sp/100;\r
- } else {\r
- spaceAfter = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;\r
- }\r
- el.ascent += spaceAfter;\r
- }\r
- el.descent = descent;\r
-\r
- if(rt.isBullet() && (prStart || startIndex == 0)){\r
- it.setIndex(startIndex);\r
-\r
- AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()));\r
- Color clr = rt.getBulletColor();\r
- if (clr != null) bat.addAttribute(TextAttribute.FOREGROUND, clr);\r
- else bat.addAttribute(TextAttribute.FOREGROUND, it.getAttribute(TextAttribute.FOREGROUND));\r
-\r
- int fontIdx = rt.getBulletFont();\r
- if(fontIdx == -1) fontIdx = rt.getFontIndex();\r
- PPFont bulletFont = _shape.getSheet().getSlideShow().getFont(fontIdx);\r
- bat.addAttribute(TextAttribute.FAMILY, bulletFont.getFontName());\r
-\r
- int bulletSize = rt.getBulletSize();\r
- int fontSize = rt.getFontSize();\r
- if(bulletSize != -1) fontSize = Math.round(fontSize*bulletSize*0.01f);\r
- bat.addAttribute(TextAttribute.SIZE, new Float(fontSize));\r
-\r
- if(!new Font(bulletFont.getFontName(), Font.PLAIN, 1).canDisplay(rt.getBulletChar())){\r
- bat.addAttribute(TextAttribute.FAMILY, "Arial");\r
- bat = new AttributedString("" + DEFAULT_BULLET_CHAR, bat.getIterator().getAttributes());\r
- }\r
-\r
- if(text.substring(startIndex, endIndex).length() > 1){\r
- el._bullet = bat;\r
- el._bulletOffset = bulletOffset;\r
- }\r
- }\r
- lines.add(el);\r
- }\r
-\r
- //finally draw the text fragments\r
- TextElement[] elems = new TextElement[lines.size()];\r
- return (TextElement[])lines.toArray(elems);\r
- }\r
-\r
- public static class TextElement {\r
- public AttributedString _text;\r
- public int _textOffset;\r
- public AttributedString _bullet;\r
- public int _bulletOffset;\r
- public int _align;\r
- public float ascent, descent;\r
- public float advance;\r
- public int textStartIndex, textEndIndex;\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.record.TextRulerAtom;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
+
+import java.text.AttributedString;
+import java.text.AttributedCharacterIterator;
+import java.text.BreakIterator;
+import java.awt.font.TextAttribute;
+import java.awt.font.LineBreakMeasurer;
+import java.awt.font.TextLayout;
+import java.awt.font.FontRenderContext;
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+
+/**
+ * Paint text into java.awt.Graphics2D
+ *
+ * @author Yegor Kozlov
+ */
+public final class TextPainter {
+ protected POILogger logger = POILogFactory.getLogger(this.getClass());
+
+ /**
+ * Display unicode square if a bullet char can't be displayed,
+ * for example, if Wingdings font is used.
+ * TODO: map Wingdngs and Symbol to unicode Arial
+ */
+ protected static final char DEFAULT_BULLET_CHAR = '\u25a0';
+
+ protected TextShape _shape;
+
+ public TextPainter(TextShape shape){
+ _shape = shape;
+ }
+
+ /**
+ * Convert the underlying set of rich text runs into java.text.AttributedString
+ */
+ public AttributedString getAttributedString(TextRun txrun){
+ String text = txrun.getText();
+ //TODO: properly process tabs
+ text = text.replace('\t', ' ');
+ text = text.replace((char)160, ' ');
+
+ AttributedString at = new AttributedString(text);
+ RichTextRun[] rt = txrun.getRichTextRuns();
+ for (int i = 0; i < rt.length; i++) {
+ int start = rt[i].getStartIndex();
+ int end = rt[i].getEndIndex();
+ if(start == end) {
+ logger.log(POILogger.INFO, "Skipping RichTextRun with zero length");
+ continue;
+ }
+
+ at.addAttribute(TextAttribute.FAMILY, rt[i].getFontName(), start, end);
+ at.addAttribute(TextAttribute.SIZE, new Float(rt[i].getFontSize()), start, end);
+ at.addAttribute(TextAttribute.FOREGROUND, rt[i].getFontColor(), start, end);
+ if(rt[i].isBold()) at.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, start, end);
+ if(rt[i].isItalic()) at.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, start, end);
+ if(rt[i].isUnderlined()) {
+ at.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, start, end);
+ at.addAttribute(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_TWO_PIXEL, start, end);
+ }
+ if(rt[i].isStrikethrough()) at.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, start, end);
+ int superScript = rt[i].getSuperscript();
+ if(superScript != 0) at.addAttribute(TextAttribute.SUPERSCRIPT, superScript > 0 ? TextAttribute.SUPERSCRIPT_SUPER : TextAttribute.SUPERSCRIPT_SUB, start, end);
+
+ }
+ return at;
+ }
+
+ public void paint(Graphics2D graphics){
+ Rectangle2D anchor = _shape.getLogicalAnchor2D();
+ TextElement[] elem = getTextElements((float)anchor.getWidth(), graphics.getFontRenderContext());
+ if(elem == null) return;
+
+ float textHeight = 0;
+ for (int i = 0; i < elem.length; i++) {
+ textHeight += elem[i].ascent + elem[i].descent;
+ }
+
+ int valign = _shape.getVerticalAlignment();
+ double y0 = anchor.getY();
+ switch (valign){
+ case TextShape.AnchorTopBaseline:
+ case TextShape.AnchorTop:
+ y0 += _shape.getMarginTop();
+ break;
+ case TextShape.AnchorBottom:
+ y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();
+ break;
+ default:
+ case TextShape.AnchorMiddle:
+ float delta = (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();
+ y0 += _shape.getMarginTop() + delta/2;
+ break;
+ }
+
+ //finally draw the text fragments
+ for (int i = 0; i < elem.length; i++) {
+ y0 += elem[i].ascent;
+
+ Point2D.Double pen = new Point2D.Double();
+ pen.y = y0;
+ switch (elem[i]._align) {
+ default:
+ case TextShape.AlignLeft:
+ pen.x = anchor.getX() + _shape.getMarginLeft();
+ break;
+ case TextShape.AlignCenter:
+ pen.x = anchor.getX() + _shape.getMarginLeft() +
+ (anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight()) / 2;
+ break;
+ case TextShape.AlignRight:
+ pen.x = anchor.getX() + _shape.getMarginLeft() +
+ (anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight());
+ break;
+ }
+ if(elem[i]._bullet != null){
+ graphics.drawString(elem[i]._bullet.getIterator(), (float)(pen.x + elem[i]._bulletOffset), (float)pen.y);
+ }
+ AttributedCharacterIterator chIt = elem[i]._text.getIterator();
+ if(chIt.getEndIndex() > chIt.getBeginIndex()) {
+ graphics.drawString(chIt, (float)(pen.x + elem[i]._textOffset), (float)pen.y);
+ }
+ y0 += elem[i].descent;
+ }
+ }
+
+ public TextElement[] getTextElements(float textWidth, FontRenderContext frc){
+ TextRun run = _shape.getTextRun();
+ if (run == null) return null;
+
+ String text = run.getText();
+ if (text == null || text.equals("")) return null;
+
+ AttributedString at = getAttributedString(run);
+
+ AttributedCharacterIterator it = at.getIterator();
+ int paragraphStart = it.getBeginIndex();
+ int paragraphEnd = it.getEndIndex();
+
+ ArrayList lines = new ArrayList();
+ LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);
+ measurer.setPosition(paragraphStart);
+ while (measurer.getPosition() < paragraphEnd) {
+ int startIndex = measurer.getPosition();
+ int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);
+
+ boolean prStart = text.charAt(startIndex) == '\n';
+ if(prStart) measurer.setPosition(startIndex++);
+
+ RichTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);
+ if(rt == null) {
+ logger.log(POILogger.WARN, "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
+ break;
+ }
+
+ float wrappingWidth = textWidth - _shape.getMarginLeft() - _shape.getMarginRight();
+ int bulletOffset = rt.getBulletOffset();
+ int textOffset = rt.getTextOffset();
+ int indent = rt.getIndentLevel();
+
+ TextRulerAtom ruler = run.getTextRuler();
+ if(ruler != null) {
+ int bullet_val = ruler.getBulletOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
+ int text_val = ruler.getTextOffsets()[indent]*Shape.POINT_DPI/Shape.MASTER_DPI;
+ if(bullet_val > text_val){
+ int a = bullet_val;
+ bullet_val = text_val;
+ text_val = a;
+ }
+ if(bullet_val != 0 ) bulletOffset = bullet_val;
+ if(text_val != 0) textOffset = text_val;
+ }
+
+ if(bulletOffset > 0 || prStart || startIndex == 0) wrappingWidth -= textOffset;
+
+ if (_shape.getWordWrap() == TextShape.WrapNone) {
+ wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
+ }
+
+ TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,
+ nextBreak == -1 ? paragraphEnd : nextBreak, true);
+ if (textLayout == null) {
+ textLayout = measurer.nextLayout(textWidth,
+ nextBreak == -1 ? paragraphEnd : nextBreak, false);
+ }
+ if(textLayout == null){
+ logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+
+ "; text: " + rt.getText());
+ measurer.setPosition(rt.getEndIndex());
+ continue;
+ }
+ int endIndex = measurer.getPosition();
+
+ float lineHeight = (float)textLayout.getBounds().getHeight();
+ int linespacing = rt.getLineSpacing();
+ if(linespacing == 0) linespacing = 100;
+
+ TextElement el = new TextElement();
+ if(linespacing >= 0){
+ el.ascent = textLayout.getAscent()*linespacing/100;
+ } else {
+ el.ascent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
+ }
+
+ el._align = rt.getAlignment();
+ el.advance = textLayout.getAdvance();
+ el._textOffset = textOffset;
+ el._text = new AttributedString(it, startIndex, endIndex);
+ el.textStartIndex = startIndex;
+ el.textEndIndex = endIndex;
+
+ if (prStart){
+ int sp = rt.getSpaceBefore();
+ float spaceBefore;
+ if(sp >= 0){
+ spaceBefore = lineHeight * sp/100;
+ } else {
+ spaceBefore = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
+ }
+ el.ascent += spaceBefore;
+ }
+
+ float descent;
+ if(linespacing >= 0){
+ descent = (textLayout.getDescent() + textLayout.getLeading())*linespacing/100;
+ } else {
+ descent = -linespacing*Shape.POINT_DPI/Shape.MASTER_DPI;
+ }
+ if (prStart){
+ int sp = rt.getSpaceAfter();
+ float spaceAfter;
+ if(sp >= 0){
+ spaceAfter = lineHeight * sp/100;
+ } else {
+ spaceAfter = -sp*Shape.POINT_DPI/Shape.MASTER_DPI;
+ }
+ el.ascent += spaceAfter;
+ }
+ el.descent = descent;
+
+ if(rt.isBullet() && (prStart || startIndex == 0)){
+ it.setIndex(startIndex);
+
+ AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()));
+ Color clr = rt.getBulletColor();
+ if (clr != null) bat.addAttribute(TextAttribute.FOREGROUND, clr);
+ else bat.addAttribute(TextAttribute.FOREGROUND, it.getAttribute(TextAttribute.FOREGROUND));
+
+ int fontIdx = rt.getBulletFont();
+ if(fontIdx == -1) fontIdx = rt.getFontIndex();
+ PPFont bulletFont = _shape.getSheet().getSlideShow().getFont(fontIdx);
+ bat.addAttribute(TextAttribute.FAMILY, bulletFont.getFontName());
+
+ int bulletSize = rt.getBulletSize();
+ int fontSize = rt.getFontSize();
+ if(bulletSize != -1) fontSize = Math.round(fontSize*bulletSize*0.01f);
+ bat.addAttribute(TextAttribute.SIZE, new Float(fontSize));
+
+ if(!new Font(bulletFont.getFontName(), Font.PLAIN, 1).canDisplay(rt.getBulletChar())){
+ bat.addAttribute(TextAttribute.FAMILY, "Arial");
+ bat = new AttributedString("" + DEFAULT_BULLET_CHAR, bat.getIterator().getAttributes());
+ }
+
+ if(text.substring(startIndex, endIndex).length() > 1){
+ el._bullet = bat;
+ el._bulletOffset = bulletOffset;
+ }
+ }
+ lines.add(el);
+ }
+
+ //finally draw the text fragments
+ TextElement[] elems = new TextElement[lines.size()];
+ return (TextElement[])lines.toArray(elems);
+ }
+
+ public static class TextElement {
+ public AttributedString _text;
+ public int _textOffset;
+ public AttributedString _bullet;
+ public int _bulletOffset;
+ public int _align;
+ public float ascent, descent;
+ public float advance;
+ public int textStartIndex, textEndIndex;
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.model;
* @author Nick Burch
*/
-public class TextRun
+public final class TextRun
{
// Note: These fields are protected to help with unit testing
// Other classes shouldn't really go playing with them!
public TextRun(TextHeaderAtom tha, TextBytesAtom tba, StyleTextPropAtom sta) {
this(tha,tba,null,sta);
}
-
+
/**
* Internal constructor and initializer
*/
_isUnicode = true;
}
String runRawText = getText();
-
+
// Figure out the rich text runs
LinkedList pStyles = new LinkedList();
LinkedList cStyles = new LinkedList();
}
buildRichTextRuns(pStyles, cStyles, runRawText);
}
-
+
public void buildRichTextRuns(LinkedList pStyles, LinkedList cStyles, String runRawText){
// Handle case of no current style, with a default
}
// Update methods follow
-
+
/**
- * Adds the supplied text onto the end of the TextRun,
+ * Adds the supplied text onto the end of the TextRun,
* creating a new RichTextRun (returned) for it to
- * sit in.
+ * sit in.
* In many cases, before calling this, you'll want to add
* a newline onto the end of your last RichTextRun
*/
public RichTextRun appendText(String s) {
// We will need a StyleTextProp atom
ensureStyleAtomPresent();
-
- // First up, append the text to the
+
+ // First up, append the text to the
// underlying text atom
int oldSize = getRawText().length();
storeText(
getRawText() + s
);
-
+
// If either of the previous styles overran
// the text by one, we need to shuffle that
// extra character onto the new ones
tpc.getCharactersCovered() - cOverRun
);
}
-
+
// Next, add the styles for its paragraph and characters
TextPropCollection newPTP =
_styleAtom.addParagraphTextPropCollection(s.length()+pOverRun);
TextPropCollection newCTP =
_styleAtom.addCharacterTextPropCollection(s.length()+cOverRun);
-
+
// Now, create the new RichTextRun
RichTextRun nr = new RichTextRun(
- this, oldSize, s.length(),
+ this, oldSize, s.length(),
newPTP, newCTP, false, false
);
-
+
// Add the new RichTextRun onto our list
RichTextRun[] newRuns = new RichTextRun[_rtRuns.length+1];
System.arraycopy(_rtRuns, 0, newRuns, 0, _rtRuns.length);
newRuns[newRuns.length-1] = nr;
_rtRuns = newRuns;
-
+
// And return the new run to the caller
return nr;
}
/**
- * Saves the given string to the records. Doesn't
- * touch the stylings.
+ * Saves the given string to the records. Doesn't
+ * touch the stylings.
*/
private void storeText(String s) {
// Remove a single trailing \r, as there is an implicit one at the
if(s.endsWith("\r")) {
s = s.substring(0, s.length()-1);
}
-
+
// Store in the appropriate record
if(_isUnicode) {
// The atom can safely convert to unicode
_byteAtom.setText(text);
} else {
// Need to swap a TextBytesAtom for a TextCharsAtom
-
+
// Build the new TextCharsAtom
_charAtom = new TextCharsAtom();
_charAtom.setText(s);
-
+
// Use the TextHeaderAtom to do the swap on the parent
RecordContainer parent = _headerAtom.getParentRecord();
Record[] cr = parent.getChildRecords();
break;
}
}
-
+
// Flag the change
_byteAtom = null;
_isUnicode = true;
}
}
}
-
+
/**
* Handles an update to the text stored in one of the Rich Text Runs
* @param run
if(runID == -1) {
throw new IllegalArgumentException("Supplied RichTextRun wasn't from this TextRun");
}
-
+
// Ensure a StyleTextPropAtom is present, adding if required
ensureStyleAtomPresent();
-
+
// Update the text length for its Paragraph and Character stylings
// If it's shared:
// * calculate the new length based on the run's old text
if(runID == _rtRuns.length-1) {
newSize++;
}
-
+
if(run._isParagraphStyleShared()) {
pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length() );
} else {
} else {
cCol.updateTextSize(newSize);
}
-
+
// Build up the new text
// As we go through, update the start position for all subsequent runs
// The building relies on the old text still being present
StringBuffer newText = new StringBuffer();
for(int i=0; i<_rtRuns.length; i++) {
int newStartPos = newText.length();
-
+
// Build up the new text
if(i != runID) {
// Not the affected run, so keep old text
// Affected run, so use new text
newText.append(s);
}
-
+
// Do we need to update the start position of this run?
// (Need to get the text before we update the start pos)
if(i <= runID) {
_rtRuns[i].updateStartPosition(newStartPos);
}
}
-
+
// Now we can save the new text
storeText(newText.toString());
}
/**
* Changes the text, and sets it all to have the same styling
- * as the the first character has.
- * If you care about styling, do setText on a RichTextRun instead
+ * as the the first character has.
+ * If you care about styling, do setText on a RichTextRun instead
*/
public void setRawText(String s) {
// Save the new text to the atoms
if(_styleAtom != null) {
LinkedList pStyles = _styleAtom.getParagraphStyles();
while(pStyles.size() > 1) { pStyles.removeLast(); }
-
+
LinkedList cStyles = _styleAtom.getCharacterStyles();
while(cStyles.size() > 1) { cStyles.removeLast(); }
-
+
_rtRuns[0].setText(s);
} else {
// Recreate rich text run with no styling
}
/**
- * Ensure a StyleTextPropAtom is present for this run,
+ * Ensure a StyleTextPropAtom is present for this run,
* by adding if required. Normally for internal TextRun use.
*/
public void ensureStyleAtomPresent() {
// All there
return;
}
-
+
// Create a new one at the right size
_styleAtom = new StyleTextPropAtom(getRawText().length() + 1);
-
+
// Use the TextHeader atom to get at the parent
RecordContainer runAtomsParent = _headerAtom.getParentRecord();
-
+
// Add the new StyleTextPropAtom after the TextCharsAtom / TextBytesAtom
Record addAfter = _byteAtom;
if(_byteAtom == null) { addAfter = _charAtom; }
runAtomsParent.addChildAfter(_styleAtom, addAfter);
-
+
// Feed this to our sole rich text run
if(_rtRuns.length != 1) {
throw new IllegalStateException("Needed to add StyleTextPropAtom when had many rich text runs");
}
- // These are the only styles for now
+ // These are the only styles for now
_rtRuns[0].supplyTextProps(
(TextPropCollection)_styleAtom.getParagraphStyles().get(0),
(TextPropCollection)_styleAtom.getCharacterStyles().get(0),
return _byteAtom.getText();
}
}
-
+
/**
* Fetch the rich text runs (runs of text with the same styling) that
* are contained within this block of text
public RichTextRun[] getRichTextRuns() {
return _rtRuns;
}
-
+
/**
* Returns the type of the text, from the TextHeaderAtom.
* Possible values can be seen from TextHeaderAtom
* @see org.apache.poi.hslf.record.TextHeaderAtom
*/
- public int getRunType() {
+ public int getRunType() {
return _headerAtom.getTextType();
}
public void setRunType(int type) {
_headerAtom.setTextType(type);
}
-
+
/**
* Supply the SlideShow we belong to.
* Also passes it on to our child RichTextRuns
}
public Sheet getSheet(){
- return this.sheet;
+ return this.sheet;
}
/**
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import org.apache.poi.hslf.model.textproperties.TextProp;\r
-import org.apache.poi.hslf.record.*;\r
-\r
-/**\r
- * Title masters define the design template for slides with a Title Slide layout.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TitleMaster extends MasterSheet {\r
- private TextRun[] _runs;\r
-\r
- /**\r
- * Constructs a TitleMaster\r
- *\r
- */\r
- public TitleMaster(org.apache.poi.hslf.record.Slide record, int sheetNo) {\r
- super(record, sheetNo);\r
-\r
- _runs = findTextRuns(getPPDrawing());\r
- for (int i = 0; i < _runs.length; i++) _runs[i].setSheet(this);\r
- }\r
-\r
- /**\r
- * Returns an array of all the TextRuns found\r
- */\r
- public TextRun[] getTextRuns() {\r
- return _runs;\r
- }\r
-\r
- /**\r
- * Delegate the call to the underlying slide master.\r
- */\r
- public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {\r
- MasterSheet master = getMasterSheet();\r
- return master == null ? null : master.getStyleAttribute(txtype, level, name, isCharacter);\r
- }\r
-\r
- /**\r
- * Returns the slide master for this title master.\r
- */\r
- public MasterSheet getMasterSheet(){\r
- SlideMaster[] master = getSlideShow().getSlidesMasters();\r
- SlideAtom sa = ((org.apache.poi.hslf.record.Slide)getSheetContainer()).getSlideAtom();\r
- int masterId = sa.getMasterID();\r
- for (int i = 0; i < master.length; i++) {\r
- if (masterId == master[i]._getSheetNumber()) return master[i];\r
- }\r
- return null;\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.hslf.model.textproperties.TextProp;
+import org.apache.poi.hslf.record.*;
+
+/**
+ * Title masters define the design template for slides with a Title Slide layout.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TitleMaster extends MasterSheet {
+ private TextRun[] _runs;
+
+ /**
+ * Constructs a TitleMaster
+ *
+ */
+ public TitleMaster(org.apache.poi.hslf.record.Slide record, int sheetNo) {
+ super(record, sheetNo);
+
+ _runs = findTextRuns(getPPDrawing());
+ for (int i = 0; i < _runs.length; i++) _runs[i].setSheet(this);
+ }
+
+ /**
+ * Returns an array of all the TextRuns found
+ */
+ public TextRun[] getTextRuns() {
+ return _runs;
+ }
+
+ /**
+ * Delegate the call to the underlying slide master.
+ */
+ public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
+ MasterSheet master = getMasterSheet();
+ return master == null ? null : master.getStyleAttribute(txtype, level, name, isCharacter);
+ }
+
+ /**
+ * Returns the slide master for this title master.
+ */
+ public MasterSheet getMasterSheet(){
+ SlideMaster[] master = getSlideShow().getSlidesMasters();
+ SlideAtom sa = ((org.apache.poi.hslf.record.Slide)getSheetContainer()).getSlideAtom();
+ int masterId = sa.getMasterID();
+ for (int i = 0; i < master.length; i++) {
+ if (masterId == master[i]._getSheetNumber()) return master[i];
+ }
+ return null;
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model.textproperties;\r
-\r
-/** \r
- * Definition for the common paragraph text property bitset.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class ParagraphFlagsTextProp extends BitMaskTextProp {\r
- public static final int BULLET_IDX = 0;\r
- public static final int BULLET_HARDFONT_IDX = 1;\r
- public static final int BULLET_HARDCOLOR_IDX = 2;\r
- public static final int BULLET_HARDSIZE_IDX = 4;\r
-\r
- public static String NAME = "paragraph_flags";\r
-\r
- public ParagraphFlagsTextProp() {\r
- super(2, 0xF, NAME, new String[] {\r
- "bullet",\r
- "bullet.hardfont",\r
- "bullet.hardcolor",\r
- "bullet.hardsize"}\r
- );\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model.textproperties;
+
+/**
+ * Definition for the common paragraph text property bitset.
+ *
+ * @author Yegor Kozlov
+ */
+public final class ParagraphFlagsTextProp extends BitMaskTextProp {
+ public static final int BULLET_IDX = 0;
+ public static final int BULLET_HARDFONT_IDX = 1;
+ public static final int BULLET_HARDCOLOR_IDX = 2;
+ public static final int BULLET_HARDSIZE_IDX = 4;
+
+ public static String NAME = "paragraph_flags";
+
+ public ParagraphFlagsTextProp() {
+ super(2, 0xF, NAME, new String[] {
+ "bullet",
+ "bullet.hardfont",
+ "bullet.hardcolor",
+ "bullet.hardsize"}
+ );
+ }
+}
-/*\r
-* Licensed to the Apache Software Foundation (ASF) under one or more\r
-* contributor license agreements. See the NOTICE file distributed with\r
-* this work for additional information regarding copyright ownership.\r
-* The ASF licenses this file to You under the Apache License, Version 2.0\r
-* (the "License"); you may not use this file except in compliance with\r
-* the License. You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-/**\r
- * A container record that specifies information about animation information for a shape.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class AnimationInfo extends RecordContainer {\r
- private byte[] _header;\r
-\r
- // Links to our more interesting children\r
- private AnimationInfoAtom animationAtom;\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- */\r
- protected AnimationInfo(byte[] source, int start, int len) {\r
- // Grab the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Find our children\r
- _children = Record.findChildRecords(source,start+8,len-8);\r
- findInterestingChildren();\r
- }\r
-\r
- /**\r
- * Go through our child records, picking out the ones that are\r
- * interesting, and saving those for use by the easy helper\r
- * methods.\r
- */ \r
- private void findInterestingChildren() {\r
-\r
- // First child should be the ExMediaAtom\r
- if(_children[0] instanceof AnimationInfoAtom) {\r
- animationAtom = (AnimationInfoAtom)_children[0];\r
- } else {\r
- logger.log(POILogger.ERROR, "First child record wasn't a AnimationInfoAtom, was of type " + _children[0].getRecordType());\r
- }\r
- }\r
-\r
- /**\r
- * Create a new AnimationInfo, with blank fields\r
- */\r
- public AnimationInfo() {\r
- // Setup our header block\r
- _header = new byte[8];\r
- _header[0] = 0x0f; // We are a container record\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- \r
- _children = new Record[1];\r
- _children[0] = animationAtom = new AnimationInfoAtom();\r
- }\r
-\r
- /**\r
- * We are of type 4103\r
- */\r
- public long getRecordType() { return RecordTypes.AnimationInfo.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- writeOut(_header[0],_header[1],getRecordType(),_children,out);\r
- }\r
-\r
- /**\r
- * Returns the AnimationInfo\r
- */\r
- public AnimationInfoAtom getAnimationInfoAtom() {\r
- return animationAtom;\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A container record that specifies information about animation information for a shape.
+ *
+ * @author Yegor Kozlov
+ */
+public final class AnimationInfo extends RecordContainer {
+ private byte[] _header;
+
+ // Links to our more interesting children
+ private AnimationInfoAtom animationAtom;
+
+ /**
+ * Set things up, and find our more interesting children
+ */
+ protected AnimationInfo(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Find our children
+ _children = Record.findChildRecords(source,start+8,len-8);
+ findInterestingChildren();
+ }
+
+ /**
+ * Go through our child records, picking out the ones that are
+ * interesting, and saving those for use by the easy helper
+ * methods.
+ */
+ private void findInterestingChildren() {
+
+ // First child should be the ExMediaAtom
+ if(_children[0] instanceof AnimationInfoAtom) {
+ animationAtom = (AnimationInfoAtom)_children[0];
+ } else {
+ logger.log(POILogger.ERROR, "First child record wasn't a AnimationInfoAtom, was of type " + _children[0].getRecordType());
+ }
+ }
+
+ /**
+ * Create a new AnimationInfo, with blank fields
+ */
+ public AnimationInfo() {
+ // Setup our header block
+ _header = new byte[8];
+ _header[0] = 0x0f; // We are a container record
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+
+ _children = new Record[1];
+ _children[0] = animationAtom = new AnimationInfoAtom();
+ }
+
+ /**
+ * We are of type 4103
+ */
+ public long getRecordType() { return RecordTypes.AnimationInfo.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],getRecordType(),_children,out);
+ }
+
+ /**
+ * Returns the AnimationInfo
+ */
+ public AnimationInfoAtom getAnimationInfoAtom() {
+ return animationAtom;
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.util.Date;\r
-\r
-import org.apache.poi.hslf.util.SystemTimeUtils;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-/**\r
- * An atom record that specifies the animation information for a shape.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class AnimationInfoAtom extends RecordAtom\r
-{\r
-\r
- /**\r
- * whether the animation plays in the reverse direction\r
- */\r
- public static final int Reverse = 1;\r
- /**\r
- * whether the animation starts automatically\r
- */\r
- public static final int Automatic = 4;\r
- /**\r
- * whether the animation has an associated sound\r
- */\r
- public static final int Sound = 16;\r
- /**\r
- * whether all playing sounds are stopped when this animation begins\r
- */\r
- public static final int StopSound = 64;\r
- /**\r
- * whether an associated sound, media or action verb is activated when the shape is clicked.\r
- */\r
- public static final int Play = 256;\r
- /**\r
- * specifies that the animation, while playing, stops other slide show actions.\r
- */\r
- public static final int Synchronous = 1024;\r
- /**\r
- * whether the shape is hidden while the animation is not playing\r
- */\r
- public static final int Hide = 4096;\r
- /**\r
- * whether the background of the shape is animated\r
- */\r
- public static final int AnimateBg = 16384;\r
-\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * record data\r
- */\r
- private byte[] _recdata;\r
-\r
- /**\r
- * Constructs a brand new link related atom record.\r
- */\r
- protected AnimationInfoAtom() {\r
- _recdata = new byte[28];\r
-\r
- _header = new byte[8];\r
- LittleEndian.putShort(_header, 0, (short)0x01);\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _recdata.length);\r
- }\r
-\r
- /**\r
- * Constructs the link related atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected AnimationInfoAtom(byte[] source, int start, int len) {\r
- // Get the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Grab the record data\r
- _recdata = new byte[len-8];\r
- System.arraycopy(source,start+8,_recdata,0,len-8);\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.AnimationInfoAtom.typeID;\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_recdata);\r
- }\r
-\r
- /**\r
- * A rgb structure that specifies a color for the dim effect after the animation is complete.\r
- *\r
- * @return color for the dim effect after the animation is complete\r
- */\r
- public int getDimColor(){\r
- return LittleEndian.getInt(_recdata, 0);\r
- }\r
-\r
- /**\r
- * A rgb structure that specifies a color for the dim effect after the animation is complete.\r
- *\r
- * @param rgb color for the dim effect after the animation is complete\r
- */\r
- public void setDimColor(int rgb){\r
- LittleEndian.putInt(_recdata, 0, rgb);\r
- }\r
-\r
- /**\r
- * A bit mask specifying options for displaying headers and footers\r
- *\r
- * @return A bit mask specifying options for displaying headers and footers\r
- */\r
- public int getMask(){\r
- return LittleEndian.getInt(_recdata, 4);\r
- }\r
-\r
- /**\r
- * A bit mask specifying options for displaying video\r
- *\r
- * @param mask A bit mask specifying options for displaying video\r
- */\r
- public void setMask(int mask){\r
- LittleEndian.putInt(_recdata, 4, mask);\r
- }\r
-\r
- /**\r
- * @param bit the bit to check\r
- * @return whether the specified flag is set\r
- */\r
- public boolean getFlag(int bit){\r
- return (getMask() & bit) != 0;\r
- }\r
-\r
- /**\r
- * @param bit the bit to set\r
- * @param value whether the specified bit is set\r
- */\r
- public void setFlag(int bit, boolean value){\r
- int mask = getMask();\r
- if(value) mask |= bit;\r
- else mask &= ~bit;\r
- setMask(mask);\r
- }\r
-\r
- /**\r
- * A 4-byte unsigned integer that specifies a reference to a sound\r
- * in the SoundCollectionContainer record to locate the embedded audio\r
- *\r
- * @return reference to a sound\r
- */\r
- public int getSoundIdRef(){\r
- return LittleEndian.getInt(_recdata, 8);\r
- }\r
-\r
- /**\r
- * A 4-byte unsigned integer that specifies a reference to a sound\r
- * in the SoundCollectionContainer record to locate the embedded audio\r
- *\r
- * @param id reference to a sound\r
- */\r
- public void setSoundIdRef(int id){\r
- LittleEndian.putInt(_recdata, 8, id);\r
- }\r
-\r
- /**\r
- * A signed integer that specifies the delay time, in milliseconds, before the animation starts to play.\r
- * If {@link #Automatic} is 0x1, this value MUST be greater than or equal to 0; otherwise, this field MUST be ignored.\r
- */\r
- public int getDelayTime(){\r
- return LittleEndian.getInt(_recdata, 12);\r
- }\r
- /**\r
- * A signed integer that specifies the delay time, in milliseconds, before the animation starts to play.\r
- * If {@link #Automatic} is 0x1, this value MUST be greater than or equal to 0; otherwise, this field MUST be ignored.\r
- */\r
- public void setDelayTime(int id){\r
- LittleEndian.putInt(_recdata, 12, id);\r
- }\r
-\r
- /**\r
- * A signed integer that specifies the order of the animation in the slide.\r
- * It MUST be greater than or equal to -2. The value -2 specifies that this animation follows the order of\r
- * the corresponding placeholder shape on the main master slide or title master slide.\r
- * The value -1 SHOULD NOT <105> be used.\r
- */\r
- public int getOrderID(){\r
- return LittleEndian.getInt(_recdata, 16);\r
- }\r
-\r
- /**\r
- * A signed integer that specifies the order of the animation in the slide.\r
- * It MUST be greater than or equal to -2. The value -2 specifies that this animation follows the order of\r
- * the corresponding placeholder shape on the main master slide or title master slide.\r
- * The value -1 SHOULD NOT <105> be used.\r
- */\r
- public void setOrderID(int id){\r
- LittleEndian.putInt(_recdata, 16, id);\r
- }\r
-\r
- /**\r
- * An unsigned integer that specifies the number of slides that this animation continues playing.\r
- * This field is utilized only in conjunction with media.\r
- * The value 0xFFFFFFFF specifies that the animation plays for one slide.\r
- */\r
- public int getSlideCount(){\r
- return LittleEndian.getInt(_recdata, 18);\r
- }\r
-\r
- /**\r
- * An unsigned integer that specifies the number of slides that this animation continues playing.\r
- * This field is utilized only in conjunction with media.\r
- * The value 0xFFFFFFFF specifies that the animation plays for one slide.\r
- */\r
- public void setSlideCount(int id){\r
- LittleEndian.putInt(_recdata, 18, id);\r
- }\r
-\r
- public String toString(){\r
- StringBuffer buf = new StringBuffer();\r
- buf.append("AnimationInfoAtom\n");\r
- buf.append("\tDimColor: " + getDimColor() + "\n");\r
- int mask = getMask();\r
- buf.append("\tMask: " + mask + ", 0x"+Integer.toHexString(mask)+"\n");\r
- buf.append("\t Reverse: " + getFlag(Reverse)+"\n");\r
- buf.append("\t Automatic: " + getFlag(Automatic)+"\n");\r
- buf.append("\t Sound: " + getFlag(Sound)+"\n");\r
- buf.append("\t StopSound: " + getFlag(StopSound)+"\n");\r
- buf.append("\t Play: " + getFlag(Play)+"\n");\r
- buf.append("\t Synchronous: " + getFlag(Synchronous)+"\n");\r
- buf.append("\t Hide: " + getFlag(Hide)+"\n");\r
- buf.append("\t AnimateBg: " + getFlag(AnimateBg)+"\n");\r
- buf.append("\tSoundIdRef: " + getSoundIdRef() + "\n");\r
- buf.append("\tDelayTime: " + getDelayTime() + "\n");\r
- buf.append("\tOrderID: " + getOrderID() + "\n");\r
- buf.append("\tSlideCount: " + getSlideCount() + "\n");\r
- return buf.toString();\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+
+import org.apache.poi.hslf.util.SystemTimeUtils;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * An atom record that specifies the animation information for a shape.
+ *
+ * @author Yegor Kozlov
+ */
+public final class AnimationInfoAtom extends RecordAtom
+{
+
+ /**
+ * whether the animation plays in the reverse direction
+ */
+ public static final int Reverse = 1;
+ /**
+ * whether the animation starts automatically
+ */
+ public static final int Automatic = 4;
+ /**
+ * whether the animation has an associated sound
+ */
+ public static final int Sound = 16;
+ /**
+ * whether all playing sounds are stopped when this animation begins
+ */
+ public static final int StopSound = 64;
+ /**
+ * whether an associated sound, media or action verb is activated when the shape is clicked.
+ */
+ public static final int Play = 256;
+ /**
+ * specifies that the animation, while playing, stops other slide show actions.
+ */
+ public static final int Synchronous = 1024;
+ /**
+ * whether the shape is hidden while the animation is not playing
+ */
+ public static final int Hide = 4096;
+ /**
+ * whether the background of the shape is animated
+ */
+ public static final int AnimateBg = 16384;
+
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * record data
+ */
+ private byte[] _recdata;
+
+ /**
+ * Constructs a brand new link related atom record.
+ */
+ protected AnimationInfoAtom() {
+ _recdata = new byte[28];
+
+ _header = new byte[8];
+ LittleEndian.putShort(_header, 0, (short)0x01);
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _recdata.length);
+ }
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected AnimationInfoAtom(byte[] source, int start, int len) {
+ // Get the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Grab the record data
+ _recdata = new byte[len-8];
+ System.arraycopy(source,start+8,_recdata,0,len-8);
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.AnimationInfoAtom.typeID;
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_recdata);
+ }
+
+ /**
+ * A rgb structure that specifies a color for the dim effect after the animation is complete.
+ *
+ * @return color for the dim effect after the animation is complete
+ */
+ public int getDimColor(){
+ return LittleEndian.getInt(_recdata, 0);
+ }
+
+ /**
+ * A rgb structure that specifies a color for the dim effect after the animation is complete.
+ *
+ * @param rgb color for the dim effect after the animation is complete
+ */
+ public void setDimColor(int rgb){
+ LittleEndian.putInt(_recdata, 0, rgb);
+ }
+
+ /**
+ * A bit mask specifying options for displaying headers and footers
+ *
+ * @return A bit mask specifying options for displaying headers and footers
+ */
+ public int getMask(){
+ return LittleEndian.getInt(_recdata, 4);
+ }
+
+ /**
+ * A bit mask specifying options for displaying video
+ *
+ * @param mask A bit mask specifying options for displaying video
+ */
+ public void setMask(int mask){
+ LittleEndian.putInt(_recdata, 4, mask);
+ }
+
+ /**
+ * @param bit the bit to check
+ * @return whether the specified flag is set
+ */
+ public boolean getFlag(int bit){
+ return (getMask() & bit) != 0;
+ }
+
+ /**
+ * @param bit the bit to set
+ * @param value whether the specified bit is set
+ */
+ public void setFlag(int bit, boolean value){
+ int mask = getMask();
+ if(value) mask |= bit;
+ else mask &= ~bit;
+ setMask(mask);
+ }
+
+ /**
+ * A 4-byte unsigned integer that specifies a reference to a sound
+ * in the SoundCollectionContainer record to locate the embedded audio
+ *
+ * @return reference to a sound
+ */
+ public int getSoundIdRef(){
+ return LittleEndian.getInt(_recdata, 8);
+ }
+
+ /**
+ * A 4-byte unsigned integer that specifies a reference to a sound
+ * in the SoundCollectionContainer record to locate the embedded audio
+ *
+ * @param id reference to a sound
+ */
+ public void setSoundIdRef(int id){
+ LittleEndian.putInt(_recdata, 8, id);
+ }
+
+ /**
+ * A signed integer that specifies the delay time, in milliseconds, before the animation starts to play.
+ * If {@link #Automatic} is 0x1, this value MUST be greater than or equal to 0; otherwise, this field MUST be ignored.
+ */
+ public int getDelayTime(){
+ return LittleEndian.getInt(_recdata, 12);
+ }
+ /**
+ * A signed integer that specifies the delay time, in milliseconds, before the animation starts to play.
+ * If {@link #Automatic} is 0x1, this value MUST be greater than or equal to 0; otherwise, this field MUST be ignored.
+ */
+ public void setDelayTime(int id){
+ LittleEndian.putInt(_recdata, 12, id);
+ }
+
+ /**
+ * A signed integer that specifies the order of the animation in the slide.
+ * It MUST be greater than or equal to -2. The value -2 specifies that this animation follows the order of
+ * the corresponding placeholder shape on the main master slide or title master slide.
+ * The value -1 SHOULD NOT <105> be used.
+ */
+ public int getOrderID(){
+ return LittleEndian.getInt(_recdata, 16);
+ }
+
+ /**
+ * A signed integer that specifies the order of the animation in the slide.
+ * It MUST be greater than or equal to -2. The value -2 specifies that this animation follows the order of
+ * the corresponding placeholder shape on the main master slide or title master slide.
+ * The value -1 SHOULD NOT <105> be used.
+ */
+ public void setOrderID(int id){
+ LittleEndian.putInt(_recdata, 16, id);
+ }
+
+ /**
+ * An unsigned integer that specifies the number of slides that this animation continues playing.
+ * This field is utilized only in conjunction with media.
+ * The value 0xFFFFFFFF specifies that the animation plays for one slide.
+ */
+ public int getSlideCount(){
+ return LittleEndian.getInt(_recdata, 18);
+ }
+
+ /**
+ * An unsigned integer that specifies the number of slides that this animation continues playing.
+ * This field is utilized only in conjunction with media.
+ * The value 0xFFFFFFFF specifies that the animation plays for one slide.
+ */
+ public void setSlideCount(int id){
+ LittleEndian.putInt(_recdata, 18, id);
+ }
+
+ public String toString(){
+ StringBuffer buf = new StringBuffer();
+ buf.append("AnimationInfoAtom\n");
+ buf.append("\tDimColor: " + getDimColor() + "\n");
+ int mask = getMask();
+ buf.append("\tMask: " + mask + ", 0x"+Integer.toHexString(mask)+"\n");
+ buf.append("\t Reverse: " + getFlag(Reverse)+"\n");
+ buf.append("\t Automatic: " + getFlag(Automatic)+"\n");
+ buf.append("\t Sound: " + getFlag(Sound)+"\n");
+ buf.append("\t StopSound: " + getFlag(StopSound)+"\n");
+ buf.append("\t Play: " + getFlag(Play)+"\n");
+ buf.append("\t Synchronous: " + getFlag(Synchronous)+"\n");
+ buf.append("\t Hide: " + getFlag(Hide)+"\n");
+ buf.append("\t AnimateBg: " + getFlag(AnimateBg)+"\n");
+ buf.append("\tSoundIdRef: " + getSoundIdRef() + "\n");
+ buf.append("\tDelayTime: " + getDelayTime() + "\n");
+ buf.append("\tOrderID: " + getOrderID() + "\n");
+ buf.append("\tSlideCount: " + getSlideCount() + "\n");
+ return buf.toString();
+ }
+
+}
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hslf.record;
import java.io.IOException;
* @author Nick Burch
*/
-public class CString extends RecordAtom {
+public final class CString extends RecordAtom {
private byte[] _header;
private static long _type = 4026l;
-
+
/** The bytes that make up the text */
private byte[] _text;
-
+
/** Grabs the text. */
- public String getText() {
+ public String getText() {
return StringUtil.getFromUnicodeLE(_text);
}
// Update the size (header bytes 5-8)
LittleEndian.putInt(_header,4,_text.length);
}
-
- /**
+
+ /**
* Grabs the count, from the first two bytes of the header.
- * The meaning of the count is specific to the type of the parent record
+ * The meaning of the count is specific to the type of the parent record
*/
public int getOptions() {
return (int)LittleEndian.getShort(_header);
}
-
- /**
+
+ /**
* Sets the count
- * The meaning of the count is specific to the type of the parent record
+ * The meaning of the count is specific to the type of the parent record
*/
public void setOptions(int count) {
LittleEndian.putShort(_header, (short)count);
/* *************** record code follows ********************** */
- /**
- * For the CStrubg Atom
+ /**
+ * For the CStrubg Atom
*/
protected CString(byte[] source, int start, int len) {
// Sanity Checking
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
/**
* A ColorSchemeAtom (type 2032). Holds the 8 RGB values for the different
* colours of bits of text, that makes up a given colour scheme.
- * Slides (presumably) link to a given colour scheme atom, and that
+ * Slides (presumably) link to a given colour scheme atom, and that
* defines the colours to be used
*
* @author Nick Burch
*/
-public class ColorSchemeAtom extends RecordAtom
+public final class ColorSchemeAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 2032l;
{ accentAndHyperlinkColourRGB = rgb; }
/** Fetch the RGB value for Accent And Following Hyperlink Colour */
- public int getAccentAndFollowingHyperlinkColourRGB()
+ public int getAccentAndFollowingHyperlinkColourRGB()
{ return accentAndFollowingHyperlinkColourRGB; }
/** Set the RGB value for Accent And Following Hyperlink Colour */
public void setAccentAndFollowingHyperlinkColourRGB(int rgb)
/* *************** record code follows ********************** */
- /**
+ /**
* For the Colour Scheme (ColorSchem) Atom
*/
protected ColorSchemeAtom(byte[] source, int start, int len) {
accentAndHyperlinkColourRGB = (int)LittleEndian.getInt(source,start+8+24);
accentAndFollowingHyperlinkColourRGB = (int)LittleEndian.getInt(source,start+8+28);
}
-
+
/**
* Create a new ColorSchemeAtom, to go with a new Slide
*/
LittleEndian.putUShort(_header, 0, 16);
LittleEndian.putUShort(_header, 2, (int)_type);
LittleEndian.putInt(_header, 4, 32);
-
+
// Setup the default rgb values
backgroundColourRGB = 16777215;
textAndLinesColourRGB = 0;
accentAndHyperlinkColourRGB = 16764108;
accentAndFollowingHyperlinkColourRGB = 11711154;
}
-
+
/**
* We are of type 3999
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hslf.record;
import java.io.IOException;
/**
* This class represents a comment on a slide, in the format used by
- * PPT 2000/XP/etc. (PPT 97 uses plain Escher Text Boxes for comments)
+ * PPT 2000/XP/etc. (PPT 97 uses plain Escher Text Boxes for comments)
* @author Nick Burch
*/
-public class Comment2000 extends RecordContainer {
+public final class Comment2000 extends RecordContainer {
private byte[] _header;
private static long _type = 12000;
-
+
// Links to our more interesting children
private CString authorRecord;
private CString authorInitialsRecord;
private CString commentRecord;
- private Comment2000Atom commentAtom;
-
- /**
+ private Comment2000Atom commentAtom;
+
+ /**
* Returns the Comment2000Atom of this Comment
- */
+ */
public Comment2000Atom getComment2000Atom() { return commentAtom; }
-
+
/**
* Get the Author of this comment
*/
public void setText(String text) {
commentRecord.setText(text);
}
-
- /**
+
+ /**
* Set things up, and find our more interesting children
*/
protected Comment2000(byte[] source, int start, int len) {
* Go through our child records, picking out the ones that are
* interesting, and saving those for use by the easy helper
* methods.
- */
+ */
private void findInterestingChildren() {
// First child should be the author
if(_children[0] instanceof CString) {
throw new IllegalStateException("Fourth child record wasn't a Comment2000Atom, was of type " + _children[3].getRecordType());
}
}
-
+
/**
* Create a new Comment2000, with blank fields
*/
public Comment2000() {
_header = new byte[8];
_children = new Record[4];
-
+
// Setup our header block
_header[0] = 0x0f; // We are a container record
LittleEndian.putShort(_header, 2, (short)_type);
-
+
// Setup our child records
CString csa = new CString();
CString csb = new CString();
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Daniel Noll
*/
-public class Comment2000Atom extends RecordAtom
+public final class Comment2000Atom extends RecordAtom
{
/**
* Record header.
LittleEndian.putShort(_header, 2, (short)getRecordType());
LittleEndian.putInt(_header, 4, _data.length);
-
+
// It is fine for the other values to be zero
}
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
-
+
// Get the record data.
_data = new byte[len-8];
System.arraycopy(source,start+8,_data,0,len-8);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import java.io.OutputStream;
/**
- * Master container for Document. There is one of these for every
+ * Master container for Document. There is one of these for every
* slideshow, and it holds lots of definitions, and some summaries.
*
* @author Nick Burch
*/
-public class Document extends PositionDependentRecordContainer
+public final class Document extends PositionDependentRecordContainer
{
private byte[] _header;
private static long _type = 1000;
*/
public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
/**
- * Returns the ExObjList, which holds the references to
+ * Returns the ExObjList, which holds the references to
* external objects used in the slides. This may be null, if
* there are no external references.
*/
public ExObjList getExObjList() { return exObjList; }
-
+
/**
* Returns all the SlideListWithTexts that are defined for
* this Document. They hold the text, and some of the text
/**
* Returns the SlideListWithText that deals with the
- * Master Slides
+ * Master Slides
*/
- public SlideListWithText getMasterSlideListWithText() {
+ public SlideListWithText getMasterSlideListWithText() {
for (int i = 0; i < slwts.length; i++) {
if(slwts[i].getInstance() == SlideListWithText.MASTER) {
return slwts[i];
}
- /**
+ /**
* Set things up, and find our more interesting children
*/
protected Document(byte[] source, int start, int len) {
exObjList = (ExObjList)_children[i];
}
}
-
+
// You should only every have 1, 2 or 3 SLWTs
// (normally it's 2, or 3 if you have notes)
// Complain if it's not
if(slwtcount > 3) {
logger.log(POILogger.WARN, "Found " + slwtcount + " SlideListWithTexts - normally there should only be three!");
}
-
+
// Now grab all the SLWTs
slwts = new SlideListWithText[slwtcount];
slwtcount = 0;
}
}
}
-
+
/**
- * Adds a new SlideListWithText record, at the appropriate
+ * Adds a new SlideListWithText record, at the appropriate
* point in the child records.
*/
public void addSlideListWithText(SlideListWithText slwt) {
- // The new SlideListWithText should go in
+ // The new SlideListWithText should go in
// just before the EndDocumentRecord
Record endDoc = _children[_children.length - 1];
if(endDoc.getRecordType() != RecordTypes.EndDocument.typeID) {
throw new IllegalStateException("The last child record of a Document should be EndDocument, but it was " + endDoc);
}
-
+
// Add in the record
addChildBefore(slwt, endDoc);
-
+
// Updated our cached list of SlideListWithText records
int newSize = slwts.length + 1;
SlideListWithText[] nl = new SlideListWithText[newSize];
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class DocumentAtom extends RecordAtom
+public final class DocumentAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 1001l;
/* *************** record code follows ********************** */
- /**
+ /**
* For the Document Atom
*/
protected DocumentAtom(byte[] source, int start, int len) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class DocumentEncryptionAtom extends RecordAtom
+public final class DocumentEncryptionAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 12052l;
private byte[] data;
private String encryptionProviderName;
- /**
+ /**
* For the Document Encryption Atom
*/
protected DocumentEncryptionAtom(byte[] source, int start, int len) {
int stringLen = (endPos-pos) / 2;
encryptionProviderName = StringUtil.getFromUnicodeLE(source, pos, stringLen);
}
-
+
/**
* Return the length of the encryption key, in bits
*/
public int getKeyLength() {
return data[28];
}
-
+
/**
* Return the name of the encryption provider used
*/
public String getEncryptionProviderName() {
return encryptionProviderName;
}
-
+
/**
* We are of type 12052
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class DummyPositionSensitiveRecordWithChildren extends PositionDependentRecordContainer
+public final class DummyPositionSensitiveRecordWithChildren extends PositionDependentRecordContainer
{
private byte[] _header;
private long _type;
- /**
+ /**
* Create a new holder for a boring record with children, but with
* position dependent characteristics
*/
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class DummyRecordWithChildren extends RecordContainer
+public final class DummyRecordWithChildren extends RecordContainer
{
private byte[] _header;
private long _type;
- /**
+ /**
* Create a new holder for a boring record with children
*/
protected DummyRecordWithChildren(byte[] source, int start, int len) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import java.io.OutputStream;
/**
- * Environment, which contains lots of settings for the document.
+ * Environment, which contains lots of settings for the document.
*
* @author Nick Burch
*/
-public class Environment extends PositionDependentRecordContainer
+public final class Environment extends PositionDependentRecordContainer
{
private byte[] _header;
private static long _type = 1010;
public FontCollection getFontCollection() { return fontCollection; }
- /**
+ /**
* Set things up, and find our more interesting children
*/
protected Environment(byte[] source, int start, int len) {
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
-
+
// Find our FontCollection record
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof FontCollection) {
txmaster = (TxMasterStyleAtom)_children[i];
}
}
-
+
if(fontCollection == null) {
throw new IllegalStateException("Environment didn't contain a FontCollection record!");
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import java.io.ByteArrayOutputStream;
/**
- * A wrapper around a DDF (Escher) EscherTextbox Record. Causes the DDF
+ * A wrapper around a DDF (Escher) EscherTextbox Record. Causes the DDF
* Record to be accessible as if it were a HSLF record.
* Note: when asked to write out, will simply put any child records correctly
* into the Escher layer. A call to the escher layer to write out (by the
* @author Nick Burch
*/
-public class EscherTextboxWrapper extends RecordContainer
+public final class EscherTextboxWrapper extends RecordContainer
{
private EscherTextboxRecord _escherRecord;
private long _type;
*/
public EscherTextboxRecord getEscherRecord() { return _escherRecord; }
- /**
+ /**
* Creates the wrapper for the given DDF Escher Record and children
*/
public EscherTextboxWrapper(EscherTextboxRecord textbox) {
byte[] data = _escherRecord.getData();
_children = Record.findChildRecords(data,0,data.length);
}
-
+
/**
* Creates a new, empty wrapper for DDF Escher Records and their children
*/
_children = new Record[0];
}
-
+
/**
* Return the type of the escher record (normally in the 0xFnnn range)
-/*\r
-* Licensed to the Apache Software Foundation (ASF) under one or more\r
-* contributor license agreements. See the NOTICE file distributed with\r
-* this work for additional information regarding copyright ownership.\r
-* The ASF licenses this file to You under the Apache License, Version 2.0\r
-* (the "License"); you may not use this file except in compliance with\r
-* the License. You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-/**\r
- * A container record that specifies information about a movie stored externally.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class ExAviMovie extends ExMCIMovie {\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- */\r
- protected ExAviMovie(byte[] source, int start, int len) {\r
- super(source, start, len);\r
- }\r
-\r
- /**\r
- * Create a new ExAviMovie, with blank fields\r
- */\r
- public ExAviMovie() {\r
- super();\r
-\r
- }\r
- /**\r
- * We are of type 4102\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.ExAviMovie.typeID;\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A container record that specifies information about a movie stored externally.
+ *
+ * @author Yegor Kozlov
+ */
+public final class ExAviMovie extends ExMCIMovie {
+
+ /**
+ * Set things up, and find our more interesting children
+ */
+ protected ExAviMovie(byte[] source, int start, int len) {
+ super(source, start, len);
+ }
+
+ /**
+ * Create a new ExAviMovie, with blank fields
+ */
+ public ExAviMovie() {
+ super();
+
+ }
+ /**
+ * We are of type 4102
+ */
+ public long getRecordType() {
+ return RecordTypes.ExAviMovie.typeID;
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.OutputStream;\r
-import java.io.IOException;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-/**\r
- * A container record that specifies information about an ActiveX control. It contains:\r
- * <p>\r
- * 1. ExControlAtom (4091)\r
- * 2. ExOleObjAtom (4035)\r
- * 3. CString (4026), Instance MenuName (1) used for menus and the Links dialog box.\r
- * 4. CString (4026), Instance ProgID (2) that stores the OLE Programmatic Identifier.\r
- * A ProgID is a string that uniquely identifies a given object.\r
- * 5. CString (4026), Instance ClipboardName (3) that appears in the paste special dialog.\r
- * 6. MetaFile( 4033), optional\r
- * </p>\r
- *\r
- *\r
- * @author Yegor kozlov\r
- */\r
-public class ExControl extends ExEmbed {\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected ExControl(byte[] source, int start, int len) {\r
- super(source, start, len);\r
- }\r
-\r
- /**\r
- * Create a new ExEmbed, with blank fields\r
- */\r
- public ExControl() {\r
- super();\r
-\r
- _children[0] = embedAtom = new ExControlAtom();\r
- }\r
-\r
- /**\r
- * Gets the {@link ExControlAtom}.\r
- *\r
- * @return the {@link ExControlAtom}.\r
- */\r
- public ExControlAtom getExControlAtom()\r
- {\r
- return (ExControlAtom)_children[0];\r
- }\r
-\r
- /**\r
- * Returns the type (held as a little endian in bytes 3 and 4)\r
- * that this class handles.\r
- *\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.ExControl.typeID;\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A container record that specifies information about an ActiveX control. It contains:
+ * <p>
+ * 1. ExControlAtom (4091)
+ * 2. ExOleObjAtom (4035)
+ * 3. CString (4026), Instance MenuName (1) used for menus and the Links dialog box.
+ * 4. CString (4026), Instance ProgID (2) that stores the OLE Programmatic Identifier.
+ * A ProgID is a string that uniquely identifies a given object.
+ * 5. CString (4026), Instance ClipboardName (3) that appears in the paste special dialog.
+ * 6. MetaFile( 4033), optional
+ * </p>
+ *
+ *
+ * @author Yegor kozlov
+ */
+public final class ExControl extends ExEmbed {
+
+ /**
+ * Set things up, and find our more interesting children
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected ExControl(byte[] source, int start, int len) {
+ super(source, start, len);
+ }
+
+ /**
+ * Create a new ExEmbed, with blank fields
+ */
+ public ExControl() {
+ super();
+
+ _children[0] = embedAtom = new ExControlAtom();
+ }
+
+ /**
+ * Gets the {@link ExControlAtom}.
+ *
+ * @return the {@link ExControlAtom}.
+ */
+ public ExControlAtom getExControlAtom()
+ {
+ return (ExControlAtom)_children[0];
+ }
+
+ /**
+ * Returns the type (held as a little endian in bytes 3 and 4)
+ * that this class handles.
+ *
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.ExControl.typeID;
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-/**\r
- * An atom record that specifies an ActiveX control.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class ExControlAtom extends RecordAtom {\r
-\r
-\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * slideId.\r
- */\r
- private int _id;\r
-\r
- /**\r
- * Constructs a brand new embedded object atom record.\r
- */\r
- protected ExControlAtom() {\r
- _header = new byte[8];\r
-\r
- LittleEndian.putShort(_header, 2, (short) getRecordType());\r
- LittleEndian.putInt(_header, 4, 4);\r
-\r
- }\r
-\r
- /**\r
- * Constructs the ExControlAtom record from its source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected ExControlAtom(byte[] source, int start, int len) {\r
- // Get the header.\r
- _header = new byte[8];\r
- System.arraycopy(source, start, _header, 0, 8);\r
-\r
- _id = LittleEndian.getInt(source, start + 8);\r
- }\r
-\r
- /**\r
- * An integer that specifies which presentation slide is associated with the ActiveX control.\r
- * <p>\r
- * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record.\r
- * The value 0x00000000 specifies a null reference.\r
- * </p>\r
- *\r
- * @return an integer that specifies which presentation slide is associated with the ActiveX control\r
- */\r
- public int getSlideId() {\r
- return _id;\r
- }\r
-\r
- /**\r
- * Sets which presentation slide is associated with the ActiveX control.\r
- *\r
- * @param id an integer that specifies which presentation slide is associated with the ActiveX control\r
- * <p>\r
- * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record.\r
- * The value 0x00000000 specifies a null reference.\r
- * </p>\r
- */\r
- public void setSlideId(int id) {\r
- _id = id;\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.ExControlAtom.typeID;\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- byte[] data = new byte[4];\r
- LittleEndian.putInt(data, _id);\r
- out.write(data);\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * An atom record that specifies an ActiveX control.
+ *
+ * @author Yegor Kozlov
+ */
+public final class ExControlAtom extends RecordAtom {
+
+
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * slideId.
+ */
+ private int _id;
+
+ /**
+ * Constructs a brand new embedded object atom record.
+ */
+ protected ExControlAtom() {
+ _header = new byte[8];
+
+ LittleEndian.putShort(_header, 2, (short) getRecordType());
+ LittleEndian.putInt(_header, 4, 4);
+
+ }
+
+ /**
+ * Constructs the ExControlAtom record from its source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected ExControlAtom(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source, start, _header, 0, 8);
+
+ _id = LittleEndian.getInt(source, start + 8);
+ }
+
+ /**
+ * An integer that specifies which presentation slide is associated with the ActiveX control.
+ * <p>
+ * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record.
+ * The value 0x00000000 specifies a null reference.
+ * </p>
+ *
+ * @return an integer that specifies which presentation slide is associated with the ActiveX control
+ */
+ public int getSlideId() {
+ return _id;
+ }
+
+ /**
+ * Sets which presentation slide is associated with the ActiveX control.
+ *
+ * @param id an integer that specifies which presentation slide is associated with the ActiveX control
+ * <p>
+ * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record.
+ * The value 0x00000000 specifies a null reference.
+ * </p>
+ */
+ public void setSlideId(int id) {
+ _id = id;
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.ExControlAtom.typeID;
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ byte[] data = new byte[4];
+ LittleEndian.putInt(data, _id);
+ out.write(data);
+ }
+
+}
-/*\r
-* Licensed to the Apache Software Foundation (ASF) under one or more\r
-* contributor license agreements. See the NOTICE file distributed with\r
-* this work for additional information regarding copyright ownership.\r
-* The ASF licenses this file to You under the Apache License, Version 2.0\r
-* (the "License"); you may not use this file except in compliance with\r
-* the License. You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-/**\r
- * A container record that specifies information about a movie stored externally.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class ExMCIMovie extends RecordContainer {\r
- private byte[] _header;\r
-\r
- //An ExVideoContainer record that specifies information about the MCI movie\r
- private ExVideoContainer exVideo;\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- */\r
- protected ExMCIMovie(byte[] source, int start, int len) {\r
- // Grab the header\r
- _header = new byte[8];\r
- System.arraycopy(source, start, _header, 0, 8);\r
-\r
- // Find our children\r
- _children = Record.findChildRecords(source, start + 8, len - 8);\r
- findInterestingChildren();\r
- }\r
-\r
- /**\r
- * Create a new ExMCIMovie, with blank fields\r
- */\r
- public ExMCIMovie() {\r
- _header = new byte[8];\r
- // Setup our header block\r
- _header[0] = 0x0f; // We are a container record\r
- LittleEndian.putShort(_header, 2, (short) getRecordType());\r
-\r
- exVideo = new ExVideoContainer();\r
- _children = new Record[]{exVideo};\r
-\r
- }\r
-\r
- /**\r
- * Go through our child records, picking out the ones that are\r
- * interesting, and saving those for use by the easy helper\r
- * methods.\r
- */\r
- private void findInterestingChildren() {\r
-\r
- // First child should be the ExVideoContainer\r
- if (_children[0] instanceof ExVideoContainer) {\r
- exVideo = (ExVideoContainer) _children[0];\r
- } else {\r
- logger.log(POILogger.ERROR, "First child record wasn't a ExVideoContainer, was of type " + _children[0].getRecordType());\r
- }\r
- }\r
-\r
- /**\r
- * We are of type 4103\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.ExMCIMovie.typeID;\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- writeOut(_header[0], _header[1], getRecordType(), _children, out);\r
- }\r
-\r
- /**\r
- * Returns the ExVideoContainer that specifies information about the MCI movie\r
- */\r
- public ExVideoContainer getExVideo() {\r
- return exVideo; }\r
-\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A container record that specifies information about a movie stored externally.
+ *
+ * @author Yegor Kozlov
+ */
+public class ExMCIMovie extends RecordContainer { // TODO - instantiable superclass
+ private byte[] _header;
+
+ //An ExVideoContainer record that specifies information about the MCI movie
+ private ExVideoContainer exVideo;
+
+ /**
+ * Set things up, and find our more interesting children
+ */
+ protected ExMCIMovie(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source, start, _header, 0, 8);
+
+ // Find our children
+ _children = Record.findChildRecords(source, start + 8, len - 8);
+ findInterestingChildren();
+ }
+
+ /**
+ * Create a new ExMCIMovie, with blank fields
+ */
+ public ExMCIMovie() {
+ _header = new byte[8];
+ // Setup our header block
+ _header[0] = 0x0f; // We are a container record
+ LittleEndian.putShort(_header, 2, (short) getRecordType());
+
+ exVideo = new ExVideoContainer();
+ _children = new Record[]{exVideo};
+
+ }
+
+ /**
+ * Go through our child records, picking out the ones that are
+ * interesting, and saving those for use by the easy helper
+ * methods.
+ */
+ private void findInterestingChildren() {
+
+ // First child should be the ExVideoContainer
+ if (_children[0] instanceof ExVideoContainer) {
+ exVideo = (ExVideoContainer) _children[0];
+ } else {
+ logger.log(POILogger.ERROR, "First child record wasn't a ExVideoContainer, was of type " + _children[0].getRecordType());
+ }
+ }
+
+ /**
+ * We are of type 4103
+ */
+ public long getRecordType() {
+ return RecordTypes.ExMCIMovie.typeID;
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0], _header[1], getRecordType(), _children, out);
+ }
+
+ /**
+ * Returns the ExVideoContainer that specifies information about the MCI movie
+ */
+ public ExVideoContainer getExVideo() {
+ return exVideo; }
+
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.util.Date;\r
-\r
-import org.apache.poi.hslf.util.SystemTimeUtils;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-/**\r
- * An atom record that specifies information about external audio or video data.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class ExMediaAtom extends RecordAtom\r
-{\r
-\r
- /**\r
- * A bit that specifies whether the audio or video data is repeated continuously during playback.\r
- */\r
- public static final int fLoop = 1;\r
- /**\r
- * A bit that specifies whether the audio or video data is rewound after playing.\r
- */\r
- public static final int fRewind = 2;\r
- /**\r
- * A bit that specifies whether the audio data is recorded narration for the slide show. It MUST be FALSE if this ExMediaAtom record is contained by an ExVideoContainer record.\r
- */\r
- public static final int fNarration = 4;\r
-\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * record data\r
- */\r
- private byte[] _recdata;\r
-\r
- /**\r
- * Constructs a brand new link related atom record.\r
- */\r
- protected ExMediaAtom() {\r
- _recdata = new byte[8];\r
-\r
- _header = new byte[8];\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _recdata.length);\r
- }\r
-\r
- /**\r
- * Constructs the link related atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected ExMediaAtom(byte[] source, int start, int len) {\r
- // Get the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Grab the record data\r
- _recdata = new byte[len-8];\r
- System.arraycopy(source,start+8,_recdata,0,len-8);\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() { return RecordTypes.ExMediaAtom.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_recdata);\r
- }\r
-\r
- /**\r
- * A 4-byte unsigned integer that specifies an ID for an external object.\r
- *\r
- * @return A 4-byte unsigned integer that specifies an ID for an external object.\r
- */\r
- public int getObjectId(){\r
- return LittleEndian.getInt(_recdata, 0);\r
- }\r
-\r
- /**\r
- * A 4-byte unsigned integer that specifies an ID for an external object.\r
- *\r
- * @param id A 4-byte unsigned integer that specifies an ID for an external object.\r
- */\r
- public void setObjectId(int id){\r
- LittleEndian.putInt(_recdata, 0, id);\r
- }\r
-\r
- /**\r
- * A bit mask specifying options for displaying headers and footers\r
- *\r
- * @return A bit mask specifying options for displaying headers and footers\r
- */\r
- public int getMask(){\r
- return LittleEndian.getInt(_recdata, 4);\r
- }\r
-\r
- /**\r
- * A bit mask specifying options for displaying video\r
- *\r
- * @param mask A bit mask specifying options for displaying video\r
- */\r
- public void setMask(int mask){\r
- LittleEndian.putInt(_recdata, 4, mask);\r
- }\r
-\r
- /**\r
- * @param bit the bit to check\r
- * @return whether the specified flag is set\r
- */\r
- public boolean getFlag(int bit){\r
- return (getMask() & bit) != 0;\r
- }\r
-\r
- /**\r
- * @param bit the bit to set\r
- * @param value whether the specified bit is set\r
- */\r
- public void setFlag(int bit, boolean value){\r
- int mask = getMask();\r
- if(value) mask |= bit;\r
- else mask &= ~bit;\r
- setMask(mask);\r
- }\r
-\r
- public String toString(){\r
- StringBuffer buf = new StringBuffer();\r
- buf.append("ExMediaAtom\n");\r
- buf.append("\tObjectId: " + getObjectId() + "\n");\r
- buf.append("\tMask : " + getMask() + "\n");\r
- buf.append("\t fLoop : " + getFlag(fLoop) + "\n");\r
- buf.append("\t fRewind : " + getFlag(fRewind) + "\n");\r
- buf.append("\t fNarration : " + getFlag(fNarration) + "\n");\r
- return buf.toString();\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+
+import org.apache.poi.hslf.util.SystemTimeUtils;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * An atom record that specifies information about external audio or video data.
+ *
+ * @author Yegor Kozlov
+ */
+public final class ExMediaAtom extends RecordAtom
+{
+
+ /**
+ * A bit that specifies whether the audio or video data is repeated continuously during playback.
+ */
+ public static final int fLoop = 1;
+ /**
+ * A bit that specifies whether the audio or video data is rewound after playing.
+ */
+ public static final int fRewind = 2;
+ /**
+ * A bit that specifies whether the audio data is recorded narration for the slide show. It MUST be FALSE if this ExMediaAtom record is contained by an ExVideoContainer record.
+ */
+ public static final int fNarration = 4;
+
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * record data
+ */
+ private byte[] _recdata;
+
+ /**
+ * Constructs a brand new link related atom record.
+ */
+ protected ExMediaAtom() {
+ _recdata = new byte[8];
+
+ _header = new byte[8];
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _recdata.length);
+ }
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected ExMediaAtom(byte[] source, int start, int len) {
+ // Get the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Grab the record data
+ _recdata = new byte[len-8];
+ System.arraycopy(source,start+8,_recdata,0,len-8);
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() { return RecordTypes.ExMediaAtom.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_recdata);
+ }
+
+ /**
+ * A 4-byte unsigned integer that specifies an ID for an external object.
+ *
+ * @return A 4-byte unsigned integer that specifies an ID for an external object.
+ */
+ public int getObjectId(){
+ return LittleEndian.getInt(_recdata, 0);
+ }
+
+ /**
+ * A 4-byte unsigned integer that specifies an ID for an external object.
+ *
+ * @param id A 4-byte unsigned integer that specifies an ID for an external object.
+ */
+ public void setObjectId(int id){
+ LittleEndian.putInt(_recdata, 0, id);
+ }
+
+ /**
+ * A bit mask specifying options for displaying headers and footers
+ *
+ * @return A bit mask specifying options for displaying headers and footers
+ */
+ public int getMask(){
+ return LittleEndian.getInt(_recdata, 4);
+ }
+
+ /**
+ * A bit mask specifying options for displaying video
+ *
+ * @param mask A bit mask specifying options for displaying video
+ */
+ public void setMask(int mask){
+ LittleEndian.putInt(_recdata, 4, mask);
+ }
+
+ /**
+ * @param bit the bit to check
+ * @return whether the specified flag is set
+ */
+ public boolean getFlag(int bit){
+ return (getMask() & bit) != 0;
+ }
+
+ /**
+ * @param bit the bit to set
+ * @param value whether the specified bit is set
+ */
+ public void setFlag(int bit, boolean value){
+ int mask = getMask();
+ if(value) mask |= bit;
+ else mask &= ~bit;
+ setMask(mask);
+ }
+
+ public String toString(){
+ StringBuffer buf = new StringBuffer();
+ buf.append("ExMediaAtom\n");
+ buf.append("\tObjectId: " + getObjectId() + "\n");
+ buf.append("\tMask : " + getMask() + "\n");
+ buf.append("\t fLoop : " + getFlag(fLoop) + "\n");
+ buf.append("\t fRewind : " + getFlag(fRewind) + "\n");
+ buf.append("\t fNarration : " + getFlag(fNarration) + "\n");
+ return buf.toString();
+ }
+
+}
-/*\r
-* Licensed to the Apache Software Foundation (ASF) under one or more\r
-* contributor license agreements. See the NOTICE file distributed with\r
-* this work for additional information regarding copyright ownership.\r
-* The ASF licenses this file to You under the Apache License, Version 2.0\r
-* (the "License"); you may not use this file except in compliance with\r
-* the License. You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-/**\r
- * A container record that specifies information about external video data.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class ExVideoContainer extends RecordContainer {\r
- private byte[] _header;\r
-\r
- // Links to our more interesting children\r
- private ExMediaAtom mediaAtom;\r
- //the UNC or local path to a video file.\r
- private CString pathAtom;\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- */\r
- protected ExVideoContainer(byte[] source, int start, int len) {\r
- // Grab the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Find our children\r
- _children = Record.findChildRecords(source,start+8,len-8);\r
- findInterestingChildren();\r
- }\r
-\r
- /**\r
- * Go through our child records, picking out the ones that are\r
- * interesting, and saving those for use by the easy helper\r
- * methods.\r
- */ \r
- private void findInterestingChildren() {\r
-\r
- // First child should be the ExMediaAtom\r
- if(_children[0] instanceof ExMediaAtom) {\r
- mediaAtom = (ExMediaAtom)_children[0];\r
- } else {\r
- logger.log(POILogger.ERROR, "First child record wasn't a ExMediaAtom, was of type " + _children[0].getRecordType());\r
- }\r
- if(_children[1] instanceof CString) {\r
- pathAtom = (CString)_children[1];\r
- } else {\r
- logger.log(POILogger.ERROR, "Second child record wasn't a CString, was of type " + _children[1].getRecordType());\r
- }\r
- }\r
-\r
- /**\r
- * Create a new ExVideoContainer, with blank fields\r
- */\r
- public ExVideoContainer() {\r
- // Setup our header block\r
- _header = new byte[8];\r
- _header[0] = 0x0f; // We are a container record\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- \r
- _children = new Record[2];\r
- _children[0] = mediaAtom = new ExMediaAtom();\r
- _children[1] = pathAtom = new CString();\r
- }\r
-\r
- /**\r
- * We are of type 4103\r
- */\r
- public long getRecordType() { return RecordTypes.ExVideoContainer.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- writeOut(_header[0],_header[1],getRecordType(),_children,out);\r
- }\r
-\r
- /**\r
- * Returns the ExMediaAtom of this link\r
- */\r
- public ExMediaAtom getExMediaAtom() { return mediaAtom; }\r
-\r
- /**\r
- * Returns the Path Atom (CString) of this link\r
- */\r
- public CString getPathAtom() { return pathAtom; }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A container record that specifies information about external video data.
+ *
+ * @author Yegor Kozlov
+ */
+public final class ExVideoContainer extends RecordContainer {
+ private byte[] _header;
+
+ // Links to our more interesting children
+ private ExMediaAtom mediaAtom;
+ //the UNC or local path to a video file.
+ private CString pathAtom;
+
+ /**
+ * Set things up, and find our more interesting children
+ */
+ protected ExVideoContainer(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Find our children
+ _children = Record.findChildRecords(source,start+8,len-8);
+ findInterestingChildren();
+ }
+
+ /**
+ * Go through our child records, picking out the ones that are
+ * interesting, and saving those for use by the easy helper
+ * methods.
+ */
+ private void findInterestingChildren() {
+
+ // First child should be the ExMediaAtom
+ if(_children[0] instanceof ExMediaAtom) {
+ mediaAtom = (ExMediaAtom)_children[0];
+ } else {
+ logger.log(POILogger.ERROR, "First child record wasn't a ExMediaAtom, was of type " + _children[0].getRecordType());
+ }
+ if(_children[1] instanceof CString) {
+ pathAtom = (CString)_children[1];
+ } else {
+ logger.log(POILogger.ERROR, "Second child record wasn't a CString, was of type " + _children[1].getRecordType());
+ }
+ }
+
+ /**
+ * Create a new ExVideoContainer, with blank fields
+ */
+ public ExVideoContainer() {
+ // Setup our header block
+ _header = new byte[8];
+ _header[0] = 0x0f; // We are a container record
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+
+ _children = new Record[2];
+ _children[0] = mediaAtom = new ExMediaAtom();
+ _children[1] = pathAtom = new CString();
+ }
+
+ /**
+ * We are of type 4103
+ */
+ public long getRecordType() { return RecordTypes.ExVideoContainer.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],getRecordType(),_children,out);
+ }
+
+ /**
+ * Returns the ExMediaAtom of this link
+ */
+ public ExMediaAtom getExMediaAtom() { return mediaAtom; }
+
+ /**
+ * Returns the Path Atom (CString) of this link
+ */
+ public CString getPathAtom() { return pathAtom; }
+
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Yegor Kozlov
*/
-public class FontCollection extends RecordContainer {
+public final class FontCollection extends RecordContainer {
private List fonts;
private byte[] _header;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Yegor Kozlov
*/
-public class FontEntityAtom extends RecordAtom {
+public final class FontEntityAtom extends RecordAtom {
/**
* record header
*/
/**
* A null-terminated string that specifies the typeface name of the font.
- * The length of this string must not exceed 32 characters
+ * The length of this string must not exceed 32 characters
* including the null terminator.
* @return font name
*/
/**
* Set the name of the font.
- * The length of this string must not exceed 32 characters
+ * The length of this string must not exceed 32 characters
* including the null terminator.
* Will be converted to null-terminated if not already
* @param name of the font
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-/**\r
- * An atom record that specifies options for displaying headers and footers\r
- * on a presentation slide or notes slide.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-\r
-public class HeadersFootersAtom extends RecordAtom {\r
-\r
- /**\r
- * A bit that specifies whether the date is displayed in the footer.\r
- * @see #getMask()\r
- * @see #setMask(int)\r
- */\r
- public static final int fHasDate = 1;\r
-\r
- /**\r
- * A bit that specifies whether the current datetime is used for displaying the datetime.\r
- * @see #getMask()\r
- * @see #setMask(int)\r
- */\r
- public static final int fHasTodayDate = 2;\r
-\r
- /**\r
- * A bit that specifies whether the date specified in UserDateAtom record\r
- * is used for displaying the datetime.\r
- *\r
- * @see #getMask()\r
- * @see #setMask(int)\r
- */\r
- public static final int fHasUserDate = 4;\r
-\r
- /**\r
- * A bit that specifies whether the slide number is displayed in the footer.\r
- * \r
- * @see #getMask()\r
- * @see #setMask(int)\r
- */\r
- public static final int fHasSlideNumber = 8;\r
-\r
- /**\r
- * bit that specifies whether the header text is displayed.\r
- *\r
- * @see #getMask()\r
- * @see #setMask(int)\r
- */\r
- public static final int fHasHeader = 16;\r
-\r
- /**\r
- * bit that specifies whether the footer text is displayed.\r
- *\r
- * @see #getMask()\r
- * @see #setMask(int)\r
- */\r
- public static final int fHasFooter = 32;\r
-\r
- /**\r
- * record header\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * record data\r
- */\r
- private byte[] _recdata;\r
-\r
- /**\r
- * Build an instance of <code>HeadersFootersAtom</code> from on-disk data\r
- */\r
- protected HeadersFootersAtom(byte[] source, int start, int len) {\r
- // Get the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Grab the record data\r
- _recdata = new byte[len-8];\r
- System.arraycopy(source,start+8,_recdata,0,len-8);\r
- }\r
-\r
- /**\r
- * Create a new instance of <code>HeadersFootersAtom</code>\r
- */\r
- public HeadersFootersAtom() {\r
- _recdata = new byte[4];\r
-\r
- _header = new byte[8];\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _recdata.length);\r
- }\r
-\r
- public long getRecordType() {\r
- return RecordTypes.HeadersFootersAtom.typeID;\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written to disk\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_recdata);\r
- }\r
-\r
- /**\r
- * A signed integer that specifies the format ID to be used to style the datetime.\r
- * <p>\r
- * It MUST be in the range [0, 12]. </br>\r
- * This value is converted into a string as specified by the index field of the DateTimeMCAtom record.\r
- * It MUST be ignored unless fHasTodayDate is TRUE.\r
- * </b>\r
- *\r
- * @return A signed integer that specifies the format ID to be used to style the datetime.\r
- */\r
- public int getFormatId(){\r
- return LittleEndian.getShort(_recdata, 0);\r
- }\r
-\r
- /**\r
- * A signed integer that specifies the format ID to be used to style the datetime.\r
- *\r
- * @param formatId A signed integer that specifies the format ID to be used to style the datetime.\r
- */\r
- public void setFormatId(int formatId){\r
- LittleEndian.putUShort(_recdata, 0, formatId);\r
- }\r
-\r
- /**\r
- * A bit mask specifying options for displaying headers and footers\r
- *\r
- * <li> A - {@link #fHasDate} (1 bit): A bit that specifies whether the date is displayed in the footer.\r
- * <li> B - {@link #fHasTodayDate} (1 bit): A bit that specifies whether the current datetime is used for\r
- * displaying the datetime.\r
- * <li> C - {@link #fHasUserDate} (1 bit): A bit that specifies whether the date specified in UserDateAtom record\r
- * is used for displaying the datetime.\r
- * <li> D - {@link #fHasSlideNumber} (1 bit): A bit that specifies whether the slide number is displayed in the footer.\r
- * <li> E - {@link #fHasHeader} (1 bit): A bit that specifies whether the header text specified by HeaderAtom\r
- * record is displayed.\r
- * <li> F - {@link #fHasFooter} (1 bit): A bit that specifies whether the footer text specified by FooterAtom\r
- * record is displayed.\r
- * <li> reserved (10 bits): MUST be zero and MUST be ignored.\r
- *\r
- * @return A bit mask specifying options for displaying headers and footers\r
- */\r
- public int getMask(){\r
- return LittleEndian.getShort(_recdata, 2);\r
- }\r
-\r
- /**\r
- * A bit mask specifying options for displaying headers and footers\r
- *\r
- * @param mask A bit mask specifying options for displaying headers and footers\r
- */\r
- public void setMask(int mask){\r
- LittleEndian.putUShort(_recdata, 2, mask);\r
- }\r
-\r
- /**\r
- * @param bit the bit to check\r
- * @return whether the specified flag is set\r
- */\r
- public boolean getFlag(int bit){\r
- return (getMask() & bit) != 0;\r
- }\r
-\r
- /**\r
- * @param bit the bit to set\r
- * @param value whether the specified bit is set\r
- */\r
- public void setFlag(int bit, boolean value){\r
- int mask = getMask();\r
- if(value) mask |= bit;\r
- else mask &= ~bit;\r
- setMask(mask);\r
- }\r
-\r
- public String toString(){\r
- StringBuffer buf = new StringBuffer();\r
- buf.append("HeadersFootersAtom\n");\r
- buf.append("\tFormatId: " + getFormatId() + "\n");\r
- buf.append("\tMask : " + getMask() + "\n");\r
- buf.append("\t fHasDate : " + getFlag(fHasDate) + "\n");\r
- buf.append("\t fHasTodayDate : " + getFlag(fHasTodayDate) + "\n");\r
- buf.append("\t fHasUserDate : " + getFlag(fHasUserDate) + "\n");\r
- buf.append("\t fHasSlideNumber : " + getFlag(fHasSlideNumber) + "\n");\r
- buf.append("\t fHasHeader : " + getFlag(fHasHeader) + "\n");\r
- buf.append("\t fHasFooter : " + getFlag(fHasFooter) + "\n");\r
- return buf.toString();\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.util.LittleEndian;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * An atom record that specifies options for displaying headers and footers
+ * on a presentation slide or notes slide.
+ *
+ * @author Yegor Kozlov
+ */
+
+public final class HeadersFootersAtom extends RecordAtom {
+
+ /**
+ * A bit that specifies whether the date is displayed in the footer.
+ * @see #getMask()
+ * @see #setMask(int)
+ */
+ public static final int fHasDate = 1;
+
+ /**
+ * A bit that specifies whether the current datetime is used for displaying the datetime.
+ * @see #getMask()
+ * @see #setMask(int)
+ */
+ public static final int fHasTodayDate = 2;
+
+ /**
+ * A bit that specifies whether the date specified in UserDateAtom record
+ * is used for displaying the datetime.
+ *
+ * @see #getMask()
+ * @see #setMask(int)
+ */
+ public static final int fHasUserDate = 4;
+
+ /**
+ * A bit that specifies whether the slide number is displayed in the footer.
+ *
+ * @see #getMask()
+ * @see #setMask(int)
+ */
+ public static final int fHasSlideNumber = 8;
+
+ /**
+ * bit that specifies whether the header text is displayed.
+ *
+ * @see #getMask()
+ * @see #setMask(int)
+ */
+ public static final int fHasHeader = 16;
+
+ /**
+ * bit that specifies whether the footer text is displayed.
+ *
+ * @see #getMask()
+ * @see #setMask(int)
+ */
+ public static final int fHasFooter = 32;
+
+ /**
+ * record header
+ */
+ private byte[] _header;
+
+ /**
+ * record data
+ */
+ private byte[] _recdata;
+
+ /**
+ * Build an instance of <code>HeadersFootersAtom</code> from on-disk data
+ */
+ protected HeadersFootersAtom(byte[] source, int start, int len) {
+ // Get the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Grab the record data
+ _recdata = new byte[len-8];
+ System.arraycopy(source,start+8,_recdata,0,len-8);
+ }
+
+ /**
+ * Create a new instance of <code>HeadersFootersAtom</code>
+ */
+ public HeadersFootersAtom() {
+ _recdata = new byte[4];
+
+ _header = new byte[8];
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _recdata.length);
+ }
+
+ public long getRecordType() {
+ return RecordTypes.HeadersFootersAtom.typeID;
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_recdata);
+ }
+
+ /**
+ * A signed integer that specifies the format ID to be used to style the datetime.
+ * <p>
+ * It MUST be in the range [0, 12]. </br>
+ * This value is converted into a string as specified by the index field of the DateTimeMCAtom record.
+ * It MUST be ignored unless fHasTodayDate is TRUE.
+ * </b>
+ *
+ * @return A signed integer that specifies the format ID to be used to style the datetime.
+ */
+ public int getFormatId(){
+ return LittleEndian.getShort(_recdata, 0);
+ }
+
+ /**
+ * A signed integer that specifies the format ID to be used to style the datetime.
+ *
+ * @param formatId A signed integer that specifies the format ID to be used to style the datetime.
+ */
+ public void setFormatId(int formatId){
+ LittleEndian.putUShort(_recdata, 0, formatId);
+ }
+
+ /**
+ * A bit mask specifying options for displaying headers and footers
+ *
+ * <li> A - {@link #fHasDate} (1 bit): A bit that specifies whether the date is displayed in the footer.
+ * <li> B - {@link #fHasTodayDate} (1 bit): A bit that specifies whether the current datetime is used for
+ * displaying the datetime.
+ * <li> C - {@link #fHasUserDate} (1 bit): A bit that specifies whether the date specified in UserDateAtom record
+ * is used for displaying the datetime.
+ * <li> D - {@link #fHasSlideNumber} (1 bit): A bit that specifies whether the slide number is displayed in the footer.
+ * <li> E - {@link #fHasHeader} (1 bit): A bit that specifies whether the header text specified by HeaderAtom
+ * record is displayed.
+ * <li> F - {@link #fHasFooter} (1 bit): A bit that specifies whether the footer text specified by FooterAtom
+ * record is displayed.
+ * <li> reserved (10 bits): MUST be zero and MUST be ignored.
+ *
+ * @return A bit mask specifying options for displaying headers and footers
+ */
+ public int getMask(){
+ return LittleEndian.getShort(_recdata, 2);
+ }
+
+ /**
+ * A bit mask specifying options for displaying headers and footers
+ *
+ * @param mask A bit mask specifying options for displaying headers and footers
+ */
+ public void setMask(int mask){
+ LittleEndian.putUShort(_recdata, 2, mask);
+ }
+
+ /**
+ * @param bit the bit to check
+ * @return whether the specified flag is set
+ */
+ public boolean getFlag(int bit){
+ return (getMask() & bit) != 0;
+ }
+
+ /**
+ * @param bit the bit to set
+ * @param value whether the specified bit is set
+ */
+ public void setFlag(int bit, boolean value){
+ int mask = getMask();
+ if(value) mask |= bit;
+ else mask &= ~bit;
+ setMask(mask);
+ }
+
+ public String toString(){
+ StringBuffer buf = new StringBuffer();
+ buf.append("HeadersFootersAtom\n");
+ buf.append("\tFormatId: " + getFormatId() + "\n");
+ buf.append("\tMask : " + getMask() + "\n");
+ buf.append("\t fHasDate : " + getFlag(fHasDate) + "\n");
+ buf.append("\t fHasTodayDate : " + getFlag(fHasTodayDate) + "\n");
+ buf.append("\t fHasUserDate : " + getFlag(fHasUserDate) + "\n");
+ buf.append("\t fHasSlideNumber : " + getFlag(fHasSlideNumber) + "\n");
+ buf.append("\t fHasHeader : " + getFlag(fHasHeader) + "\n");
+ buf.append("\t fHasFooter : " + getFlag(fHasFooter) + "\n");
+ return buf.toString();
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-import java.io.OutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * A container record that specifies information about the footers on a presentation slide.\r
- * <p>\r
- * It contains:<br>\r
- * <li> 1. {@link HeadersFootersAtom}\r
- * <li> 2. {@link CString }, Instance UserDate (0), optional: Stores the user's date.\r
- * This is the date that the user wants in the footers, instead of today's date.\r
- * <li> 3. {@link CString }, Instance Header (1), optional: Stores the Header's contents.\r
- * <li> 4. {@link CString }, Instance Footer (2), optional: Stores the Footer's contents.\r
- * </p>\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class HeadersFootersContainer extends RecordContainer {\r
-\r
- /**\r
- * "instance" field in the record header indicating that this HeadersFootersContaine\r
- * is applied for slides\r
- */\r
- public static final short SlideHeadersFootersContainer = 0x3F;\r
- /**\r
- * "instance" field in the record header indicating that this HeadersFootersContaine\r
- * is applied for notes and handouts\r
- */\r
- public static final short NotesHeadersFootersContainer = 0x4F;\r
-\r
- public static final int USERDATEATOM = 0;\r
- public static final int HEADERATOM = 1;\r
- public static final int FOOTERATOM = 2;\r
-\r
- private byte[] _header;\r
- private HeadersFootersAtom hdAtom;\r
- private CString csDate, csHeader, csFooter;\r
-\r
- protected HeadersFootersContainer(byte[] source, int start, int len) {\r
- // Grab the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- _children = Record.findChildRecords(source,start+8,len-8);\r
- for(int i=0; i < _children.length; i++){\r
- if(_children[i] instanceof HeadersFootersAtom) hdAtom = (HeadersFootersAtom)_children[i];\r
- else if(_children[i] instanceof CString) {\r
- CString cs = (CString)_children[i];\r
- int opts = cs.getOptions() >> 4;\r
- switch(opts){\r
- case USERDATEATOM: csDate = cs; break;\r
- case HEADERATOM: csHeader = cs; break;\r
- case FOOTERATOM: csFooter = cs; break;\r
- default:\r
- logger.log(POILogger.WARN, "Unexpected CString.Options in HeadersFootersContainer: " + opts);\r
- break;\r
- }\r
- } else {\r
- logger.log(POILogger.WARN, "Unexpected record in HeadersFootersContainer: " + _children[i]);\r
- }\r
- }\r
-\r
- }\r
-\r
- public HeadersFootersContainer(short options) {\r
- _header = new byte[8];\r
- LittleEndian.putShort(_header, 0, options);\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
-\r
- hdAtom = new HeadersFootersAtom();\r
- _children = new Record[]{\r
- hdAtom\r
- };\r
- csDate = csHeader = csFooter = null;\r
-\r
- }\r
-\r
- /**\r
- * Return the type, which is <code>{@link RecordTypes#HeadersFooters}</code>\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.HeadersFooters.typeID;\r
- }\r
-\r
- /**\r
- * Must be either {@link #SlideHeadersFootersContainer} or {@link #NotesHeadersFootersContainer}\r
- *\r
- * @return "instance" field in the record header\r
- */\r
- public int getOptions(){\r
- return LittleEndian.getShort(_header, 0);\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written to disk\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- writeOut(_header[0],_header[1],getRecordType(),_children,out);\r
- }\r
-\r
- /**\r
- * HeadersFootersAtom stores the basic information of the header and footer structure.\r
- *\r
- * @return <code>HeadersFootersAtom</code>\r
- */\r
- public HeadersFootersAtom getHeadersFootersAtom(){\r
- return hdAtom;\r
- }\r
-\r
- /**\r
- * A {@link CString} record that stores the user's date.\r
- * <p>This is the date that the user wants in the footers, instead of today's date.</p>\r
- *\r
- * @return A {@link CString} record that stores the user's date or <code>null</code>\r
- */\r
- public CString getUserDateAtom(){\r
- return csDate;\r
- }\r
-\r
- /**\r
- * A {@link CString} record that stores the Header's contents.\r
- *\r
- * @return A {@link CString} record that stores the Header's contents or <code>null</code>\r
- */\r
- public CString getHeaderAtom(){\r
- return csHeader;\r
- }\r
-\r
- /**\r
- * A {@link CString} record that stores the Footers's contents.\r
- *\r
- * @return A {@link CString} record that stores the Footers's contents or <code>null</code>\r
- */\r
- public CString getFooterAtom(){\r
- return csFooter;\r
- }\r
-\r
- /**\r
- * Insert a {@link CString} record that stores the user's date.\r
- *\r
- * @return the created {@link CString} record that stores the user's date.\r
- */\r
- public CString addUserDateAtom(){\r
- if(csDate != null) return csDate;\r
-\r
- csDate = new CString();\r
- csDate.setOptions(USERDATEATOM << 4);\r
-\r
- addChildAfter(csDate, hdAtom);\r
-\r
- return csDate;\r
- }\r
-\r
- /**\r
- * Insert a {@link CString} record that stores the user's date.\r
- *\r
- * @return the created {@link CString} record that stores the user's date.\r
- */\r
- public CString addHeaderAtom(){\r
- if(csHeader != null) return csHeader;\r
-\r
- csHeader = new CString();\r
- csHeader.setOptions(HEADERATOM << 4);\r
-\r
- Record r = hdAtom;\r
- if(csDate != null) r = hdAtom;\r
- addChildAfter(csHeader, r);\r
-\r
- return csHeader;\r
- }\r
-\r
- /**\r
- * Insert a {@link CString} record that stores the user's date.\r
- *\r
- * @return the created {@link CString} record that stores the user's date.\r
- */\r
- public CString addFooterAtom(){\r
- if(csFooter != null) return csFooter;\r
-\r
- csFooter = new CString();\r
- csFooter.setOptions(FOOTERATOM << 4);\r
-\r
- Record r = hdAtom;\r
- if(csHeader != null) r = csHeader;\r
- else if(csDate != null) r = csDate;\r
- addChildAfter(csFooter, r);\r
-\r
- return csFooter;\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * A container record that specifies information about the footers on a presentation slide.
+ * <p>
+ * It contains:<br>
+ * <li> 1. {@link HeadersFootersAtom}
+ * <li> 2. {@link CString }, Instance UserDate (0), optional: Stores the user's date.
+ * This is the date that the user wants in the footers, instead of today's date.
+ * <li> 3. {@link CString }, Instance Header (1), optional: Stores the Header's contents.
+ * <li> 4. {@link CString }, Instance Footer (2), optional: Stores the Footer's contents.
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public final class HeadersFootersContainer extends RecordContainer {
+
+ /**
+ * "instance" field in the record header indicating that this HeadersFootersContaine
+ * is applied for slides
+ */
+ public static final short SlideHeadersFootersContainer = 0x3F;
+ /**
+ * "instance" field in the record header indicating that this HeadersFootersContaine
+ * is applied for notes and handouts
+ */
+ public static final short NotesHeadersFootersContainer = 0x4F;
+
+ public static final int USERDATEATOM = 0;
+ public static final int HEADERATOM = 1;
+ public static final int FOOTERATOM = 2;
+
+ private byte[] _header;
+ private HeadersFootersAtom hdAtom;
+ private CString csDate, csHeader, csFooter;
+
+ protected HeadersFootersContainer(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ _children = Record.findChildRecords(source,start+8,len-8);
+ for(int i=0; i < _children.length; i++){
+ if(_children[i] instanceof HeadersFootersAtom) hdAtom = (HeadersFootersAtom)_children[i];
+ else if(_children[i] instanceof CString) {
+ CString cs = (CString)_children[i];
+ int opts = cs.getOptions() >> 4;
+ switch(opts){
+ case USERDATEATOM: csDate = cs; break;
+ case HEADERATOM: csHeader = cs; break;
+ case FOOTERATOM: csFooter = cs; break;
+ default:
+ logger.log(POILogger.WARN, "Unexpected CString.Options in HeadersFootersContainer: " + opts);
+ break;
+ }
+ } else {
+ logger.log(POILogger.WARN, "Unexpected record in HeadersFootersContainer: " + _children[i]);
+ }
+ }
+
+ }
+
+ public HeadersFootersContainer(short options) {
+ _header = new byte[8];
+ LittleEndian.putShort(_header, 0, options);
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+
+ hdAtom = new HeadersFootersAtom();
+ _children = new Record[]{
+ hdAtom
+ };
+ csDate = csHeader = csFooter = null;
+
+ }
+
+ /**
+ * Return the type, which is <code>{@link RecordTypes#HeadersFooters}</code>
+ */
+ public long getRecordType() {
+ return RecordTypes.HeadersFooters.typeID;
+ }
+
+ /**
+ * Must be either {@link #SlideHeadersFootersContainer} or {@link #NotesHeadersFootersContainer}
+ *
+ * @return "instance" field in the record header
+ */
+ public int getOptions(){
+ return LittleEndian.getShort(_header, 0);
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],getRecordType(),_children,out);
+ }
+
+ /**
+ * HeadersFootersAtom stores the basic information of the header and footer structure.
+ *
+ * @return <code>HeadersFootersAtom</code>
+ */
+ public HeadersFootersAtom getHeadersFootersAtom(){
+ return hdAtom;
+ }
+
+ /**
+ * A {@link CString} record that stores the user's date.
+ * <p>This is the date that the user wants in the footers, instead of today's date.</p>
+ *
+ * @return A {@link CString} record that stores the user's date or <code>null</code>
+ */
+ public CString getUserDateAtom(){
+ return csDate;
+ }
+
+ /**
+ * A {@link CString} record that stores the Header's contents.
+ *
+ * @return A {@link CString} record that stores the Header's contents or <code>null</code>
+ */
+ public CString getHeaderAtom(){
+ return csHeader;
+ }
+
+ /**
+ * A {@link CString} record that stores the Footers's contents.
+ *
+ * @return A {@link CString} record that stores the Footers's contents or <code>null</code>
+ */
+ public CString getFooterAtom(){
+ return csFooter;
+ }
+
+ /**
+ * Insert a {@link CString} record that stores the user's date.
+ *
+ * @return the created {@link CString} record that stores the user's date.
+ */
+ public CString addUserDateAtom(){
+ if(csDate != null) return csDate;
+
+ csDate = new CString();
+ csDate.setOptions(USERDATEATOM << 4);
+
+ addChildAfter(csDate, hdAtom);
+
+ return csDate;
+ }
+
+ /**
+ * Insert a {@link CString} record that stores the user's date.
+ *
+ * @return the created {@link CString} record that stores the user's date.
+ */
+ public CString addHeaderAtom(){
+ if(csHeader != null) return csHeader;
+
+ csHeader = new CString();
+ csHeader.setOptions(HEADERATOM << 4);
+
+ Record r = hdAtom;
+ if(csDate != null) r = hdAtom;
+ addChildAfter(csHeader, r);
+
+ return csHeader;
+ }
+
+ /**
+ * Insert a {@link CString} record that stores the user's date.
+ *
+ * @return the created {@link CString} record that stores the user's date.
+ */
+ public CString addFooterAtom(){
+ if(csFooter != null) return csFooter;
+
+ csFooter = new CString();
+ csFooter.setOptions(FOOTERATOM << 4);
+
+ Record r = hdAtom;
+ if(csHeader != null) r = csHeader;
+ else if(csDate != null) r = csDate;
+ addChildAfter(csFooter, r);
+
+ return csFooter;
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Yegor Kozlov
*/
-public class MainMaster extends SheetContainer
+public final class MainMaster extends SheetContainer
{
private byte[] _header;
private static long _type = 1016;
public SlideAtom getSlideAtom() { return slideAtom; }
/**
- * Returns the PPDrawing of this Slide, which has all the
+ * Returns the PPDrawing of this Slide, which has all the
* interesting data in it
*/
public PPDrawing getPPDrawing() { return ppDrawing; }
public ColorSchemeAtom[] getColorSchemeAtoms() { return clrscheme; }
- /**
+ /**
* Set things up, and find our more interesting children
*/
protected MainMaster(byte[] source, int start, int len) {
* We are of type 1016
*/
public long getRecordType() { return _type; }
-
+
/**
* Write the contents of the record back, so it can be written
* to disk
public ColorSchemeAtom getColorScheme(){
return _colorScheme;
}
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class Notes extends SheetContainer
+public final class Notes extends SheetContainer
{
private byte[] _header;
private static long _type = 1008l;
*/
public NotesAtom getNotesAtom() { return notesAtom; }
/**
- * Returns the PPDrawing of this Notes, which has all the
+ * Returns the PPDrawing of this Notes, which has all the
* interesting data in it
*/
public PPDrawing getPPDrawing() { return ppDrawing; }
- /**
+ /**
* Set things up, and find our more interesting children
*/
protected Notes(byte[] source, int start, int len) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class NotesAtom extends RecordAtom
+public final class NotesAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 1009l;
/* *************** record code follows ********************** */
- /**
+ /**
* For the Notes Atom
*/
protected NotesAtom(byte[] source, int start, int len) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Yegor Kozlov
*/
-public class OEPlaceholderAtom extends RecordAtom{
+public final class OEPlaceholderAtom extends RecordAtom{
/**
* The full size of the master body text placeholder shape.
public static final byte MasterFooter = 9;
/**
- * The corresponding shape contains a header text field.
+ * The corresponding shape contains a header text field.
* The corresponding slide must be a notes master slide or handout master slide.
*/
public static final byte MasterHeader = 10;
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.util.Date;\r
-\r
-import org.apache.poi.hslf.util.SystemTimeUtils;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-/**\r
- * Atom that contains information that describes shape client data.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class OEShapeAtom extends RecordAtom\r
-{\r
-\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * record data\r
- */\r
- private byte[] _recdata;\r
-\r
- /**\r
- * Constructs a brand new link related atom record.\r
- */\r
- public OEShapeAtom() {\r
- _recdata = new byte[4];\r
-\r
- _header = new byte[8];\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _recdata.length);\r
- }\r
-\r
- /**\r
- * Constructs the link related atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected OEShapeAtom(byte[] source, int start, int len) {\r
- // Get the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Grab the record data\r
- _recdata = new byte[len-8];\r
- System.arraycopy(source,start+8,_recdata,0,len-8);\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() { return RecordTypes.OEShapeAtom.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_recdata);\r
- }\r
-\r
- /**\r
- * shape flags.\r
- *\r
- * @return shape flags.\r
- */\r
- public int getOptions(){\r
- return LittleEndian.getInt(_recdata, 0);\r
- }\r
-\r
- /**\r
- * shape flags.\r
- *\r
- * @param id shape flags.\r
- */\r
- public void setOptions(int id){\r
- LittleEndian.putInt(_recdata, 0, id);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+
+import org.apache.poi.hslf.util.SystemTimeUtils;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Atom that contains information that describes shape client data.
+ *
+ * @author Yegor Kozlov
+ */
+public final class OEShapeAtom extends RecordAtom
+{
+
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * record data
+ */
+ private byte[] _recdata;
+
+ /**
+ * Constructs a brand new link related atom record.
+ */
+ public OEShapeAtom() {
+ _recdata = new byte[4];
+
+ _header = new byte[8];
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _recdata.length);
+ }
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected OEShapeAtom(byte[] source, int start, int len) {
+ // Get the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Grab the record data
+ _recdata = new byte[len-8];
+ System.arraycopy(source,start+8,_recdata,0,len-8);
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() { return RecordTypes.OEShapeAtom.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_recdata);
+ }
+
+ /**
+ * shape flags.
+ *
+ * @return shape flags.
+ */
+ public int getOptions(){
+ return LittleEndian.getInt(_recdata, 0);
+ }
+
+ /**
+ * shape flags.
+ *
+ * @param id shape flags.
+ */
+ public void setOptions(int id){
+ LittleEndian.putInt(_recdata, 0, id);
+ }
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
* @author Yegor Kozlov
*/
-public class OutlineTextRefAtom extends RecordAtom {
+public final class OutlineTextRefAtom extends RecordAtom {
/**
* record header
*/
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* These are actually wrappers onto Escher drawings. Make use of
* the DDF classes to do useful things with them.
* For now, creates a tree of the Escher records, and then creates any
- * PowerPoint (hslf) records found within the EscherTextboxRecord
+ * PowerPoint (hslf) records found within the EscherTextboxRecord
* (msofbtClientTextbox) records.
* Also provides easy access to the EscherTextboxRecords, so that their
* text may be extracted and used in Sheets
// For now, pretending to be an atom. Might not always be, but that
// would require a wrapping class
-public class PPDrawing extends RecordAtom
+public final class PPDrawing extends RecordAtom
{
private byte[] _header;
private long _type;
/* ******************** record stuff follows ********************** */
- /**
+ /**
* Sets everything up, groks the escher etc
*/
protected PPDrawing(byte[] source, int start, int len) {
textboxWrappers[i] = (EscherTextboxWrapper)textboxes.get(i);
}
}
-
+
/**
* Creates a new, empty, PPDrawing (typically for use with a new Slide
* or Notes)
LittleEndian.putUShort(_header, 0, 15);
LittleEndian.putUShort(_header, 2, (int)RecordTypes.PPDrawing.typeID);
LittleEndian.putInt(_header, 4, 0);
-
+
textboxWrappers = new EscherTextboxWrapper[]{};
create();
}
- /**
+ /**
* Tree walking way of finding Escher Child Records
*/
private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, Vector found) {
* Sanity check. Always advance the cursor by the correct value.
*
* getRecordSize() must return exatcly the same number of bytes that was written in fillFields.
- * Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size.
+ * Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size.
*/
if(size != escherBytes){
logger.log(POILogger.WARN, "Record length=" + escherBytes + " but getRecordSize() returned " + r.getRecordSize() + "; record: " + r.getClass());
}
}
- /**
+ /**
* Look for EscherTextboxRecords
*/
private void findEscherTextboxRecord(EscherRecord[] toSearch, Vector found) {
*/
public long getRecordType() { return _type; }
- /**
+ /**
* We're pretending to be an atom, so return null
*/
public Record[] getChildRecords() { return null; }
EscherContainerRecord spgrContainer = new EscherContainerRecord();
spgrContainer.setOptions((short)15);
spgrContainer.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
-
+
EscherContainerRecord spContainer = new EscherContainerRecord();
spContainer.setOptions((short)15);
spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
-
+
EscherSpgrRecord spgr = new EscherSpgrRecord();
spgr.setOptions((short)1);
spContainer.addChildRecord(spgr);
dgContainer
};
}
-
+
/**
* Add a new EscherTextboxWrapper to this <code>PPDrawing</code>.
*/
public void addTextboxWrapper(EscherTextboxWrapper txtbox){
EscherTextboxWrapper[] tw = new EscherTextboxWrapper[textboxWrappers.length + 1];
System.arraycopy(textboxWrappers, 0, tw, 0, textboxWrappers.length);
-
+
tw[textboxWrappers.length] = txtbox;
textboxWrappers = tw;
}
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hslf.record;
import org.apache.poi.ddf.*;
/**
* Container records which always exists inside Document.
* It always acts as a holder for escher DGG container
- * which may contain which Escher BStore container information
+ * which may contain which Escher BStore container information
* about pictures containes in the presentation (if any).
- *
+ *
* @author Yegor Kozlov
*/
-public class PPDrawingGroup extends RecordAtom {
+public final class PPDrawingGroup extends RecordAtom {
private byte[] _header;
private EscherContainerRecord dggContainer;
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hslf.record;
/**
* Interface to define how a record can indicate it cares about what its
* parent is, and how it wants to be told which record is its parent.
- *
+ *
* @author Nick Burch (nick at torchbox dot com)
*/
public interface ParentAwareRecord {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class PersistPtrHolder extends PositionDependentRecordAtom
+public final class PersistPtrHolder extends PositionDependentRecordAtom
{
private byte[] _header;
private byte[] _ptrData; // Will need to update this once we allow updates to _slideLocations
private long _type;
-
- /**
+
+ /**
* Holds the lookup for slides to their position on disk.
* You always need to check the most recent PersistPtrHolder
* that knows about a given slide to find the right location
}
/**
* Get the lookup from slide numbers to their offsets inside
- * _ptrData, used when adding or moving slides.
+ * _ptrData, used when adding or moving slides.
*/
public Hashtable getSlideOffsetDataLocationsLookup() {
return _slideOffsetDataLocation;
// Add to the slide location lookup hash
_slideLocations.put(new Integer(slideID), new Integer(posOnDisk));
// Add to the ptrData offset lookup hash
- _slideOffsetDataLocation.put(new Integer(slideID),
+ _slideOffsetDataLocation.put(new Integer(slideID),
new Integer(_ptrData.length + 4));
// Build the info block
LittleEndian.putInt(_header,4,newPtrData.length);
}
- /**
+ /**
* Create a new holder for a PersistPtr record
*/
protected PersistPtrHolder(byte[] source, int start, int len) {
/**
* At write-out time, update the references to the sheets to their
- * new positions
+ * new positions
*/
public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
int[] slideIDs = getKnownSlideIDs();
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-/**\r
- * A record that can be referenced in PersistPtr storage.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public interface PersistRecord {\r
-\r
- /**\r
- * Fetch the persist ID\r
- */\r
- public int getPersistId();\r
-\r
- /**\r
- * Set the persist ID\r
- */\r
- public void setPersistId(int id);\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+/**
+ * A record that can be referenced in PersistPtr storage.
+ *
+ * @author Yegor Kozlov
+ */
+public interface PersistRecord {
+
+ /**
+ * Fetch the persist ID
+ */
+ public int getPersistId();
+
+ /**
+ * Set the persist ID
+ */
+ public void setPersistId(int id);
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import java.util.Hashtable;
/** Fetch our location on the disk, as of the last write out */
public int getLastOnDiskOffset();
- /**
+ /**
* Update the Record's idea of where on disk it lives, after a write out.
* Use with care...
*/
public void setLastOnDiskOffset(int offset);
/**
- * Offer the record the list of records that have changed their
+ * Offer the record the list of records that have changed their
* location as part of the writeout.
*/
public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import java.util.Hashtable;
/** Fetch our location on the disk, as of the last write out */
public int getLastOnDiskOffset() { return myLastOnDiskOffset; }
- /**
+ /**
* Update the Record's idea of where on disk it lives, after a write out.
* Use with care...
*/
- public void setLastOnDiskOffset(int offset) {
+ public void setLastOnDiskOffset(int offset) {
myLastOnDiskOffset = offset;
}
/**
- * Offer the record the list of records that have changed their
+ * Offer the record the list of records that have changed their
* location as part of the writeout.
* Allows records to update their internal pointers to other records
* locations
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import java.util.Hashtable;
/**
* A special (and dangerous) kind of Record Container, for which other
- * Atoms care about where this one lives on disk.
+ * Atoms care about where this one lives on disk.
* Will track its position on disk.
*
* @author Nick Burch
public abstract class PositionDependentRecordContainer extends RecordContainer implements PositionDependentRecord
{
private int sheetId; // Found from PersistPtrHolder
-
+
/**
* Fetch our sheet ID, as found from a PersistPtrHolder.
* Should match the RefId of our matching SlidePersistAtom
*/
public void setSheetId(int id) { sheetId = id; }
-
+
/** Our location on the disk, as of the last write out */
protected int myLastOnDiskOffset;
/** Fetch our location on the disk, as of the last write out */
public int getLastOnDiskOffset() { return myLastOnDiskOffset; }
- /**
+ /**
* Update the Record's idea of where on disk it lives, after a write out.
* Use with care...
*/
- public void setLastOnDiskOffset(int offset) {
+ public void setLastOnDiskOffset(int offset) {
myLastOnDiskOffset = offset;
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*/
public abstract long getRecordType();
- /**
+ /**
* Fetch all the child records of this record
* If this record is an atom, will return null
- * If this record is a non-atom, but has no children, will return
+ * If this record is a non-atom, but has no children, will return
* an empty array
*/
public abstract Record[] getChildRecords();
* Have the contents printer out into an OutputStream, used when
* writing a file back out to disk
* (Normally, atom classes will keep their bytes around, but
- * non atom classes will just request the bytes from their
+ * non atom classes will just request the bytes from their
* children, then chuck on their header and return)
*/
public abstract void writeOut(OutputStream o) throws IOException;
LittleEndian.putShort(bs,s);
o.write(bs);
}
-
+
/**
* Build and return the Record at the given offset.
* Note - does less error checking and handling than findChildRecords
Class c = null;
try {
c = RecordTypes.recordHandlingClass((int)type);
- if(c == null) {
+ if(c == null) {
// How odd. RecordTypes normally subsitutes in
// a default handler class if it has heard of the record
// type but there's no support for it. Explicitly request
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
public abstract class RecordAtom extends Record
{
- /**
+ /**
* We are an atom
*/
public boolean isAnAtom() { return true; }
- /**
+ /**
* We're an atom, returns null
*/
public Record[] getChildRecords() { return null; }
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
{
protected Record[] _children;
private Boolean changingChildRecordsLock = new Boolean(true);
-
- /**
- * Return any children
+
+ /**
+ * Return any children
*/
public Record[] getChildRecords() { return _children; }
- /**
+ /**
* We're not an atom
*/
public boolean isAnAtom() { return false; }
-
+
/* ===============================================================
* Internal Move Helpers
* ===============================================================
* Finds the location of the given child record
*/
private int findChildLocation(Record child) {
- // Synchronized as we don't want things changing
+ // Synchronized as we don't want things changing
// as we're doing our search
synchronized(changingChildRecordsLock) {
for(int i=0; i<_children.length; i++) {
return i;
}
}
- }
+ }
return -1;
}
-
+
/**
* Adds a child record, at the very end.
* @param newChild The child record to add
_children = nc;
}
}
-
+
/**
* Adds the given new Child Record at the given location,
* shuffling everything from there on down by one
synchronized(changingChildRecordsLock) {
// Firstly, have the child added in at the end
appendChild(newChild);
-
+
// Now, have them moved to the right place
moveChildRecords( (_children.length-1), position, 1 );
}
}
-
+
/**
* Moves <i>number</i> child records from <i>oldLoc</i>
* to <i>newLoc</i>. Caller must have the changingChildRecordsLock
private void moveChildRecords(int oldLoc, int newLoc, int number) {
if(oldLoc == newLoc) { return; }
if(number == 0) { return; }
-
+
// Check that we're not asked to move too many
if(oldLoc+number > _children.length) {
throw new IllegalArgumentException("Asked to move more records than there are!");
}
-
+
// Do the move
ArrayUtil.arrayMoveWithin(_children, oldLoc, newLoc, number);
}
-
-
+
+
/**
* Finds the first child record of the given type,
* or null if none of the child records are of the
}
return null;
}
-
+
/* ===============================================================
* External Move Methods
* ===============================================================
appendChild(newChild);
}
}
-
+
/**
* Adds the given Child Record after the supplied record
* @param newChild
if(loc == -1) {
throw new IllegalArgumentException("Asked to add a new child after another record, but that record wasn't one of our children!");
}
-
+
// Add one place after the supplied record
addChildAt(newChild, loc+1);
}
}
-
+
/**
* Adds the given Child Record before the supplied record
* @param newChild
if(loc == -1) {
throw new IllegalArgumentException("Asked to add a new child before another record, but that record wasn't one of our children!");
}
-
+
// Add at the place of the supplied record
addChildAt(newChild, loc);
}
}
-
+
/**
* Moves the given Child Record to before the supplied record
*/
public void moveChildBefore(Record child, Record before) {
moveChildrenBefore(child, 1, before);
}
-
+
/**
* Moves the given Child Records to before the supplied record
*/
public void moveChildrenBefore(Record firstChild, int number, Record before) {
if(number < 1) { return; }
-
+
synchronized(changingChildRecordsLock) {
// Decide where we're going to put them
int newLoc = findChildLocation(before);
if(newLoc == -1) {
throw new IllegalArgumentException("Asked to move children before another record, but that record wasn't one of our children!");
}
-
+
// Figure out where they are now
int oldLoc = findChildLocation(firstChild);
if(oldLoc == -1) {
throw new IllegalArgumentException("Asked to move a record that wasn't a child!");
}
-
+
// Actually move
moveChildRecords(oldLoc, newLoc, number);
}
}
-
+
/**
- * Moves the given Child Records to after the supplied record
+ * Moves the given Child Records to after the supplied record
*/
public void moveChildrenAfter(Record firstChild, int number, Record after) {
if(number < 1) { return; }
-
+
synchronized(changingChildRecordsLock) {
// Decide where we're going to put them
int newLoc = findChildLocation(after);
}
// We actually want after this though
newLoc++;
-
+
// Figure out where they are now
int oldLoc = findChildLocation(firstChild);
if(oldLoc == -1) {
throw new IllegalArgumentException("Asked to move a record that wasn't a child!");
}
-
+
// Actually move
moveChildRecords(oldLoc, newLoc, number);
}
}
/**
- * Set child records.
+ * Set child records.
*
* @param records the new child records
*/
public void writeOut(byte headerA, byte headerB, long type, Record[] children, OutputStream out) throws IOException {
// If we have a mutable output stream, take advantage of that
if(out instanceof MutableByteArrayOutputStream) {
- MutableByteArrayOutputStream mout =
+ MutableByteArrayOutputStream mout =
(MutableByteArrayOutputStream)out;
// Grab current size
* @author Yegor Kozlov
* @author Nick Burch
*/
-public class RecordTypes {
+public final class RecordTypes {
public static HashMap typeToName;
public static HashMap typeToClass;
public static final Type PersistPtrIncrementalBlock = new Type(6002,PersistPtrHolder.class);
public static final Type GScalingAtom = new Type(10001,null);
public static final Type GRColorAtom = new Type(10002,null);
-
+
// Records ~12000 seem to be related to the Comments used in PPT 2000/XP
// (Comments in PPT97 are normal Escher text boxes)
public static final Type Comment2000 = new Type(12000,Comment2000.class);
public static final Type Comment2000Atom = new Type(12001,Comment2000Atom.class);
public static final Type Comment2000Summary = new Type(12004,null);
public static final Type Comment2000SummaryAtom = new Type(12005,null);
-
+
// Records ~12050 seem to be related to Document Encryption
public static final Type DocumentEncryptionAtom = new Type(12052,DocumentEncryptionAtom.class);
}
- /**
+ /**
* Wrapper for the details of a PowerPoint or Escher record type.
* Contains both the type, and the handling class (if any), and
* offers methods to get either back out.
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.util.Date;\r
-\r
-import org.apache.poi.hslf.util.SystemTimeUtils;\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-/**\r
- * An atom record that specifies that a shape is a header or footer placeholder shape\r
- *\r
- * @since PowerPoint 2007\r
- * @author Yegor Kozlov\r
- */\r
-\r
-public class RoundTripHFPlaceholder12 extends RecordAtom\r
-{\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * Specifies the placeholder shape ID.\r
- *\r
- * MUST be {@link OEPlaceholderAtom#MasterDate}, {@link OEPlaceholderAtom#MasterSlideNumber}, \r
- * {@link OEPlaceholderAtom#MasterFooter}, or {@link OEPlaceholderAtom#MasterHeader}\r
- */\r
- private byte _placeholderId;\r
-\r
- /**\r
- * Constructs the comment atom record from its source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected RoundTripHFPlaceholder12(byte[] source, int start, int len) {\r
- // Get the header.\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Get the record data.\r
- _placeholderId = source[start+8];\r
- }\r
-\r
- /**\r
- * Gets the comment number (note - each user normally has their own count).\r
- * @return the comment number.\r
- */\r
- public int getPlaceholderId() {\r
- return _placeholderId;\r
- }\r
-\r
- /**\r
- * Sets the comment number (note - each user normally has their own count).\r
- * @param number the comment number.\r
- */\r
- public void setPlaceholderId(int number) {\r
- _placeholderId = (byte)number;\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() { return RecordTypes.RoundTripHFPlaceholder12.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_placeholderId);\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+
+import org.apache.poi.hslf.util.SystemTimeUtils;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * An atom record that specifies that a shape is a header or footer placeholder shape
+ *
+ * @since PowerPoint 2007
+ * @author Yegor Kozlov
+ */
+
+public final class RoundTripHFPlaceholder12 extends RecordAtom
+{
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * Specifies the placeholder shape ID.
+ *
+ * MUST be {@link OEPlaceholderAtom#MasterDate}, {@link OEPlaceholderAtom#MasterSlideNumber},
+ * {@link OEPlaceholderAtom#MasterFooter}, or {@link OEPlaceholderAtom#MasterHeader}
+ */
+ private byte _placeholderId;
+
+ /**
+ * Constructs the comment atom record from its source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected RoundTripHFPlaceholder12(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Get the record data.
+ _placeholderId = source[start+8];
+ }
+
+ /**
+ * Gets the comment number (note - each user normally has their own count).
+ * @return the comment number.
+ */
+ public int getPlaceholderId() {
+ return _placeholderId;
+ }
+
+ /**
+ * Sets the comment number (note - each user normally has their own count).
+ * @param number the comment number.
+ */
+ public void setPlaceholderId(int number) {
+ _placeholderId = (byte)number;
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() { return RecordTypes.RoundTripHFPlaceholder12.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_placeholderId);
+ }
+}
-/*\r
-* Licensed to the Apache Software Foundation (ASF) under one or more\r
-* contributor license agreements. See the NOTICE file distributed with\r
-* this work for additional information regarding copyright ownership.\r
-* The ASF licenses this file to You under the Apache License, Version 2.0\r
-* (the "License"); you may not use this file except in compliance with\r
-* the License. You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.apache.poi.hslf.record;\r
-\r
-/**\r
- * The superclass of all sheet container records - Slide, Notes, MainMaster, etc.\r
- */\r
-public abstract class SheetContainer extends PositionDependentRecordContainer {\r
-\r
- /**\r
- * Returns the PPDrawing of this sheet, which has all the\r
- * interesting data in it\r
- */\r
- public abstract PPDrawing getPPDrawing();\r
-\r
- public abstract ColorSchemeAtom getColorScheme();\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+/**
+ * The superclass of all sheet container records - Slide, Notes, MainMaster, etc.
+ */
+public abstract class SheetContainer extends PositionDependentRecordContainer {
+
+ /**
+ * Returns the PPDrawing of this sheet, which has all the
+ * interesting data in it
+ */
+ public abstract PPDrawing getPPDrawing();
+
+ public abstract ColorSchemeAtom getColorScheme();
+
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class Slide extends SheetContainer
+public final class Slide extends SheetContainer
{
private byte[] _header;
private static long _type = 1006l;
public SlideAtom getSlideAtom() { return slideAtom; }
/**
- * Returns the PPDrawing of this Slide, which has all the
+ * Returns the PPDrawing of this Slide, which has all the
* interesting data in it
*/
public PPDrawing getPPDrawing() { return ppDrawing; }
- /**
+ /**
* Set things up, and find our more interesting children
*/
protected Slide(byte[] source, int start, int len) {
* We are of type 1006
*/
public long getRecordType() { return _type; }
-
+
/**
* Write the contents of the record back, so it can be written
* to disk
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class SlideAtom extends RecordAtom
+public final class SlideAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 1007l;
/** Get the ID of the master slide used. 0 if this is a master slide, otherwise -2147483648 */
public int getMasterID() { return masterID; }
- /** Change slide master. */
+ /** Change slide master. */
public void setMasterID(int id) { masterID = id; }
/** Get the ID of the notes for this slide. 0 if doesn't have one */
public int getNotesID() { return notesID; }
/* *************** record code follows ********************** */
- /**
+ /**
* For the Slide Atom
*/
protected SlideAtom(byte[] source, int start, int len) {
reserved = new byte[len-30];
System.arraycopy(source,start+30,reserved,0,reserved.length);
}
-
+
/**
* Create a new SlideAtom, to go with a new Slide
*/
LittleEndian.putUShort(_header, 0, 2);
LittleEndian.putUShort(_header, 2, (int)_type);
LittleEndian.putInt(_header, 4, 24);
-
+
byte[] ssdate = new byte[12];
layoutAtom = new SSlideLayoutAtom(ssdate);
layoutAtom.setGeometryType(SSlideLayoutAtom.BLANK_SLIDE);
* Holds the geometry of the Slide, and the ID of the placeholders
* on the slide.
* (Embeded inside SlideAtom is a SSlideLayoutAtom, without the
- * usual record header. Since it's a fixed size and tied to
+ * usual record header. Since it's a fixed size and tied to
* the SlideAtom, we'll hold it here.)
*/
public class SSlideLayoutAtom {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
*/
// For now, pretend to be an atom
-public class SlideListWithText extends RecordContainer
+public final class SlideListWithText extends RecordContainer
{
/**
private SlideAtomsSet[] slideAtomsSets;
- /**
+ /**
* Create a new holder for slide records
*/
protected SlideListWithText(byte[] source, int start, int len) {
System.arraycopy(source,start,_header,0,8);
// Find our children
- _children = Record.findChildRecords(source,start+8,len-8);
+ _children = Record.findChildRecords(source,start+8,len-8);
// Group our children together into SlideAtomsSets
- // That way, model layer code can just grab the sets to use,
+ // That way, model layer code can just grab the sets to use,
// without having to try to match the children together
Vector sets = new Vector();
for(int i=0; i<_children.length; i++) {
int clen = endPos - i - 1;
boolean emptySet = false;
if(clen == 0) { emptySet = true; }
-
+
// Create a SlideAtomsSets, not caring if they're empty
//if(emptySet) { continue; }
Record[] spaChildren = new Record[clen];
LittleEndian.putUShort(_header, 2, (int)_type);
LittleEndian.putInt(_header, 4, 0);
- // We have no children to start with
+ // We have no children to start with
_children = new Record[0];
slideAtomsSets = new SlideAtomsSet[0];
}
-
+
/**
* Add a new SlidePersistAtom, to the end of the current list,
* and update the internal list of SlidePersistAtoms
/**
* Inner class to wrap up a matching set of records that hold the
* text for a given sheet. Contains the leading SlidePersistAtom,
- * and all of the records until the next SlidePersistAtom. This
+ * and all of the records until the next SlidePersistAtom. This
* includes sets of TextHeaderAtom and TextBytesAtom/TextCharsAtom,
* along with some others.
*/
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class SlidePersistAtom extends RecordAtom
+public final class SlidePersistAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 1011l;
- /**
- * Slide reference ID. Should correspond to the PersistPtr
- * "sheet ID" of the matching slide/notes record
+ /**
+ * Slide reference ID. Should correspond to the PersistPtr
+ * "sheet ID" of the matching slide/notes record
*/
private int refID;
private boolean hasShapesOtherThanPlaceholders;
/** Number of placeholder texts that will follow in the SlideListWithText */
private int numPlaceholderTexts;
- /**
+ /**
* The internal identifier (256+), which is used to tie slides
- * and notes together
+ * and notes together
*/
private int slideIdentifier;
/** Reserved fields. Who knows what they do */
public int getSlideIdentifier() { return slideIdentifier; }
public int getNumPlaceholderTexts() { return numPlaceholderTexts; }
public boolean getHasShapesOtherThanPlaceholders() { return hasShapesOtherThanPlaceholders; }
-
+
// Only set these if you know what you're doing!
public void setRefID(int id) {
refID = id;
/* *************** record code follows ********************** */
- /**
+ /**
* For the SlidePersist Atom
*/
protected SlidePersistAtom(byte[] source, int start, int len) {
// Last useful one is the unique slide identifier
slideIdentifier = (int)LittleEndian.getInt(source,start+20);
- // Finally you have typically 4 or 8 bytes of reserved fields,
+ // Finally you have typically 4 or 8 bytes of reserved fields,
// all zero running from 24 bytes in to the end
reservedFields = new byte[len-24];
System.arraycopy(source,start+24,reservedFields,0,reservedFields.length);
}
-
+
/**
* Create a new SlidePersistAtom, for use with a new Slide
*/
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.util.POILogger;\r
-\r
-import java.io.OutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * A container holding information about a sound. It contains:\r
- * <p>\r
- * <li>1. CString (4026), Instance 0: Name of sound (e.g. "crash")\r
- * <li>2. CString (4026), Instance 1: Type of sound (e.g. ".wav")\r
- * <li>3. CString (4026), Instance 2: Reference id of sound in sound collection\r
- * <li>4. CString (4026), Instance 3, optional: Built-in id of sound, for sounds we ship. This is the id that?s in the reg file.\r
- * <li>5. SoundData (2023), optional\r
- * </p>\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class Sound extends RecordContainer {\r
- /**\r
- * Record header data.\r
- */\r
- private byte[] _header;\r
-\r
- // Links to our more interesting children\r
- private CString _name;\r
- private CString _type;\r
- private SoundData _data;\r
-\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected Sound(byte[] source, int start, int len) {\r
- // Grab the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Find our children\r
- _children = Record.findChildRecords(source,start+8,len-8);\r
- findInterestingChildren();\r
- }\r
-\r
- private void findInterestingChildren() {\r
- // First child should be the ExHyperlinkAtom\r
- if(_children[0] instanceof CString) {\r
- _name = (CString)_children[0];\r
- } else {\r
- logger.log(POILogger.ERROR, "First child record wasn't a CString, was of type " + _children[0].getRecordType());\r
- }\r
-\r
- // Second child should be the ExOleObjAtom\r
- if (_children[1] instanceof CString) {\r
- _type = (CString)_children[1];\r
- } else {\r
- logger.log(POILogger.ERROR, "Second child record wasn't a CString, was of type " + _children[1].getRecordType());\r
- }\r
-\r
- for (int i = 2; i < _children.length; i++) {\r
- if(_children[i] instanceof SoundData){\r
- _data = (SoundData)_children[i];\r
- break;\r
- }\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Returns the type (held as a little endian in bytes 3 and 4)\r
- * that this class handles.\r
- *\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.Sound.typeID;\r
- }\r
-\r
- /**\r
- * Have the contents printer out into an OutputStream, used when\r
- * writing a file back out to disk.\r
- *\r
- * @param out the output stream.\r
- * @throws java.io.IOException if there was an error writing to the stream.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- writeOut(_header[0],_header[1],getRecordType(),_children,out);\r
- }\r
-\r
- /**\r
- * Name of the sound (e.g. "crash")\r
- *\r
- * @return name of the sound\r
- */\r
- public String getSoundName(){\r
- return _name.getText();\r
- }\r
-\r
- /**\r
- * Type of the sound (e.g. ".wav")\r
- *\r
- * @return type of the sound\r
- */\r
- public String getSoundType(){\r
- return _type.getText();\r
- }\r
-\r
- /**\r
- * The sound data\r
- *\r
- * @return the sound data.\r
- */\r
- public byte[] getSoundData(){\r
- return _data == null ? null : _data.getData();\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.util.POILogger;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * A container holding information about a sound. It contains:
+ * <p>
+ * <li>1. CString (4026), Instance 0: Name of sound (e.g. "crash")
+ * <li>2. CString (4026), Instance 1: Type of sound (e.g. ".wav")
+ * <li>3. CString (4026), Instance 2: Reference id of sound in sound collection
+ * <li>4. CString (4026), Instance 3, optional: Built-in id of sound, for sounds we ship. This is the id that?s in the reg file.
+ * <li>5. SoundData (2023), optional
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public final class Sound extends RecordContainer {
+ /**
+ * Record header data.
+ */
+ private byte[] _header;
+
+ // Links to our more interesting children
+ private CString _name;
+ private CString _type;
+ private SoundData _data;
+
+
+ /**
+ * Set things up, and find our more interesting children
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected Sound(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Find our children
+ _children = Record.findChildRecords(source,start+8,len-8);
+ findInterestingChildren();
+ }
+
+ private void findInterestingChildren() {
+ // First child should be the ExHyperlinkAtom
+ if(_children[0] instanceof CString) {
+ _name = (CString)_children[0];
+ } else {
+ logger.log(POILogger.ERROR, "First child record wasn't a CString, was of type " + _children[0].getRecordType());
+ }
+
+ // Second child should be the ExOleObjAtom
+ if (_children[1] instanceof CString) {
+ _type = (CString)_children[1];
+ } else {
+ logger.log(POILogger.ERROR, "Second child record wasn't a CString, was of type " + _children[1].getRecordType());
+ }
+
+ for (int i = 2; i < _children.length; i++) {
+ if(_children[i] instanceof SoundData){
+ _data = (SoundData)_children[i];
+ break;
+ }
+ }
+
+ }
+
+ /**
+ * Returns the type (held as a little endian in bytes 3 and 4)
+ * that this class handles.
+ *
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.Sound.typeID;
+ }
+
+ /**
+ * Have the contents printer out into an OutputStream, used when
+ * writing a file back out to disk.
+ *
+ * @param out the output stream.
+ * @throws java.io.IOException if there was an error writing to the stream.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],getRecordType(),_children,out);
+ }
+
+ /**
+ * Name of the sound (e.g. "crash")
+ *
+ * @return name of the sound
+ */
+ public String getSoundName(){
+ return _name.getText();
+ }
+
+ /**
+ * Type of the sound (e.g. ".wav")
+ *
+ * @return type of the sound
+ */
+ public String getSoundType(){
+ return _type.getText();
+ }
+
+ /**
+ * The sound data
+ *
+ * @return the sound data.
+ */
+ public byte[] getSoundData(){
+ return _data == null ? null : _data.getData();
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.util.POILogger;\r
-\r
-import java.io.OutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * Is a container for all sound related atoms and containers. It contains:\r
- *<li>1. SoundCollAtom (2021)\r
- *<li>2. Sound (2022), for each sound, if any\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class SoundCollection extends RecordContainer {\r
- /**\r
- * Record header data.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * Set things up, and find our more interesting children\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected SoundCollection(byte[] source, int start, int len) {\r
- // Grab the header\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Find our children\r
- _children = Record.findChildRecords(source,start+8,len-8);\r
- }\r
-\r
- /**\r
- * Returns the type (held as a little endian in bytes 3 and 4)\r
- * that this class handles.\r
- *\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.SoundCollection.typeID;\r
- }\r
-\r
- /**\r
- * Have the contents printer out into an OutputStream, used when\r
- * writing a file back out to disk.\r
- *\r
- * @param out the output stream.\r
- * @throws java.io.IOException if there was an error writing to the stream.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- writeOut(_header[0],_header[1],getRecordType(),_children,out);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.util.POILogger;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * Is a container for all sound related atoms and containers. It contains:
+ *<li>1. SoundCollAtom (2021)
+ *<li>2. Sound (2022), for each sound, if any
+ *
+ * @author Yegor Kozlov
+ */
+public final class SoundCollection extends RecordContainer {
+ /**
+ * Record header data.
+ */
+ private byte[] _header;
+
+ /**
+ * Set things up, and find our more interesting children
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected SoundCollection(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Find our children
+ _children = Record.findChildRecords(source,start+8,len-8);
+ }
+
+ /**
+ * Returns the type (held as a little endian in bytes 3 and 4)
+ * that this class handles.
+ *
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.SoundCollection.typeID;
+ }
+
+ /**
+ * Have the contents printer out into an OutputStream, used when
+ * writing a file back out to disk.
+ *
+ * @param out the output stream.
+ * @throws java.io.IOException if there was an error writing to the stream.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],getRecordType(),_children,out);
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
-import java.util.zip.InflaterInputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-/**\r
- * Storage for embedded sounds.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class SoundData extends RecordAtom {\r
-\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * Record data.\r
- */\r
- private byte[] _data;\r
-\r
- /**\r
- * Constructs a new empty sound container.\r
- */\r
- protected SoundData() {\r
- _header = new byte[8];\r
- _data = new byte[0];\r
-\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _data.length);\r
- }\r
-\r
- /**\r
- * Constructs the link related atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected SoundData(byte[] source, int start, int len) {\r
- // Get the header.\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Get the record data.\r
- _data = new byte[len-8];\r
- System.arraycopy(source,start+8,_data,0,len-8);\r
- }\r
-\r
- /**\r
- * Returns the sound data.\r
- *\r
- * @return the sound data \r
- */\r
- public byte[] getData() {\r
- return _data;\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- *\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.SoundData.typeID;\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk.\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_data);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.InflaterInputStream;
+
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Storage for embedded sounds.
+ *
+ * @author Yegor Kozlov
+ */
+public final class SoundData extends RecordAtom {
+
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * Record data.
+ */
+ private byte[] _data;
+
+ /**
+ * Constructs a new empty sound container.
+ */
+ protected SoundData() {
+ _header = new byte[8];
+ _data = new byte[0];
+
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _data.length);
+ }
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected SoundData(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Get the record data.
+ _data = new byte[len-8];
+ System.arraycopy(source,start+8,_data,0,len-8);
+ }
+
+ /**
+ * Returns the sound data.
+ *
+ * @return the sound data
+ */
+ public byte[] getData() {
+ return _data;
+ }
+
+ /**
+ * Gets the record type.
+ *
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.SoundData.typeID;
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk.
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_data);
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
import org.apache.poi.util.HexDump;
/**
- * A StyleTextPropAtom (type 4001). Holds basic character properties
+ * A StyleTextPropAtom (type 4001). Holds basic character properties
* (bold, italic, underline, font size etc) and paragraph properties
* (alignment, line spacing etc) for the block of text (TextBytesAtom
* or TextCharsAtom) that this record follows.
* @author Yegor Kozlov
*/
-public class StyleTextPropAtom extends RecordAtom
+public final class StyleTextPropAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 4001l;
private byte[] rawContents; // Holds the contents between write-outs
- /**
+ /**
* Only set to true once setParentTextSize(int) is called.
* Until then, no stylings will have been decoded
*/
private boolean initialised = false;
- /**
+ /**
* The list of all the different paragraph stylings we code for.
* Each entry is a TextPropCollection, which tells you how many
* Characters the paragraph covers, and also contains the TextProps
* paragraph stylings
*/
public void setParagraphStyles(LinkedList ps) { paragraphStyles = ps; }
- /**
+ /**
* The list of all the different character stylings we code for.
* Each entry is a TextPropCollection, which tells you how many
- * Characters the character styling covers, and also contains the
+ * Characters the character styling covers, and also contains the
* TextProps that actually define the styling of the characters.
*/
private LinkedList charStyles;
* character stylings
*/
public void setCharacterStyles(LinkedList cs) { charStyles = cs; }
-
+
/**
* Returns how many characters the paragraph's
* TextPropCollections cover.
// Save this properties set
charStyles.add(thisCollection);
-
+
// Handle extra 1 char styles at the end
if(pos < rawContents.length && textHandled == size) {
chsize++;
charStyles.add(tpc);
return tpc;
}
-
+
/* ************************************************************************ */
*/
public String toString(){
StringBuffer out = new StringBuffer();
-
+
out.append("StyleTextPropAtom:\n");
if (!initialised) {
out.append("Uninitialised, dumping Raw Style Data\n");
} else {
-
+
out.append("Paragraph properties\n");
-
+
for (Iterator it1 = getParagraphStyles().iterator(); it1.hasNext();) {
TextPropCollection pr = (TextPropCollection)it1.next();
out.append(" chars covered: " + pr.getCharactersCovered());
out.append(" " + p.getName() + " = " + p.getValue() );
out.append(" (0x" + HexDump.toHex(p.getValue()) + ")\n");
}
-
+
out.append(" para bytes that would be written: \n");
-
+
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pr.writeOut(baos);
e.printStackTrace();
}
}
-
+
out.append("Character properties\n");
for (Iterator it1 = getCharacterStyles().iterator(); it1.hasNext();) {
TextPropCollection pr = (TextPropCollection)it1.next();
out.append(" " + p.getName() + " = " + p.getValue() );
out.append(" (0x" + HexDump.toHex(p.getValue()) + ")\n");
}
-
+
out.append(" char bytes that would be written: \n");
-
+
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pr.writeOut(baos);
}
}
}
-
+
out.append(" original byte stream \n");
out.append( HexDump.dump(rawContents, 0, 0) );
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
/**
* A TextBytesAtom (type 4008). Holds text in ascii form (unknown
- * code page, for now assumed to be the default of
+ * code page, for now assumed to be the default of
* org.apache.poi.util.StringUtil, which is the Excel default).
* The trailing return character is always stripped from this
*
* @author Nick Burch
*/
-public class TextBytesAtom extends RecordAtom
+public final class TextBytesAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 4008l;
private byte[] _text;
/** Grabs the text. Uses the default codepage */
- public String getText() {
+ public String getText() {
return StringUtil.getFromCompressedUnicode(_text,0,_text.length);
}
/** Updates the text in the Atom. Must be 8 bit ascii */
- public void setText(byte[] b) {
+ public void setText(byte[] b) {
// Set the text
_text = b;
/* *************** record code follows ********************** */
- /**
+ /**
* For the TextBytes Atom
*/
protected TextBytesAtom(byte[] source, int start, int len) {
_text = new byte[len-8];
System.arraycopy(source,start+8,_text,0,len-8);
}
-
+
/**
* Create an empty TextBytes Atom
*/
}
/**
- * dump debug info; use getText() to return a string
+ * dump debug info; use getText() to return a string
* representation of the atom
*/
public String toString() {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class TextCharsAtom extends RecordAtom
+public final class TextCharsAtom extends RecordAtom
{
private byte[] _header;
private static long _type = 4000l;
private byte[] _text;
/** Grabs the text. */
- public String getText() {
+ public String getText() {
return StringUtil.getFromUnicodeLE(_text);
}
/* *************** record code follows ********************** */
- /**
- * For the TextChars Atom
+ /**
+ * For the TextChars Atom
*/
protected TextCharsAtom(byte[] source, int start, int len) {
// Sanity Checking
// Write out our text
out.write(_text);
}
-
+
/**
- * dump debug info; use getText() to return a string
+ * dump debug info; use getText() to return a string
* representation of the atom
*/
public String toString() {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class TextHeaderAtom extends RecordAtom implements ParentAwareRecord
+public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecord
{
private byte[] _header;
private static long _type = 3999l;
public int getTextType() { return textType; }
public void setTextType(int type) { textType = type; }
-
+
public RecordContainer getParentRecord() { return parentRecord; }
- public void setParentRecord(RecordContainer record) { this.parentRecord = record; }
+ public void setParentRecord(RecordContainer record) { this.parentRecord = record; }
/* *************** record code follows ********************** */
- /**
+ /**
* For the TextHeader Atom
*/
protected TextHeaderAtom(byte[] source, int start, int len) {
// Grab the type
textType = (int)LittleEndian.getInt(source,start+8);
}
-
+
/**
* Create a new TextHeader Atom, for an unknown type of text
*/
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
-import java.util.zip.InflaterInputStream;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-import org.apache.poi.util.POILogger;\r
-\r
-/**\r
- * Ruler of a text as it differs from the style's ruler settings.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TextRulerAtom extends RecordAtom {\r
-\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * Record data.\r
- */\r
- private byte[] _data;\r
-\r
- //ruler internals\r
- private int defaultTabSize;\r
- private int numLevels;\r
- private int[] tabStops;\r
- private int[] bulletOffsets = new int[5];\r
- private int[] textOffsets = new int[5];\r
-\r
- /**\r
- * Constructs a new empty ruler atom.\r
- */\r
- public TextRulerAtom() {\r
- _header = new byte[8];\r
- _data = new byte[0];\r
-\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _data.length);\r
- }\r
-\r
- /**\r
- * Constructs the ruler atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected TextRulerAtom(byte[] source, int start, int len) {\r
- // Get the header.\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Get the record data.\r
- _data = new byte[len-8];\r
- System.arraycopy(source,start+8,_data,0,len-8);\r
-\r
- try {\r
- read();\r
- } catch (Exception e){\r
- logger.log(POILogger.ERROR, "Failed to parse TextRulerAtom: " + e.getMessage()); \r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- *\r
- * @return the record type.\r
- */\r
- public long getRecordType() {\r
- return RecordTypes.TextRulerAtom.typeID;\r
- }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk.\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_data);\r
- }\r
-\r
- /**\r
- * Read the record bytes and initialize the internal variables\r
- */\r
- private void read(){\r
- int pos = 0;\r
- short mask = LittleEndian.getShort(_data); pos += 4;\r
- short val;\r
- int[] bits = {1, 0, 2, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12};\r
- for (int i = 0; i < bits.length; i++) {\r
- if((mask & 1 << bits[i]) != 0){\r
- switch (bits[i]){\r
- case 0:\r
- //defaultTabSize\r
- defaultTabSize = LittleEndian.getShort(_data, pos); pos += 2;\r
- break;\r
- case 1:\r
- //numLevels\r
- numLevels = LittleEndian.getShort(_data, pos); pos += 2;\r
- break;\r
- case 2:\r
- //tabStops\r
- val = LittleEndian.getShort(_data, pos); pos += 2;\r
- tabStops = new int[val*2];\r
- for (int j = 0; j < tabStops.length; j++) {\r
- tabStops[j] = LittleEndian.getUShort(_data, pos); pos += 2;\r
- }\r
- break;\r
- case 3:\r
- case 4:\r
- case 5:\r
- case 6:\r
- case 7:\r
- //bullet.offset\r
- val = LittleEndian.getShort(_data, pos); pos += 2;\r
- bulletOffsets[bits[i]-3] = val;\r
- break;\r
- case 8:\r
- case 9:\r
- case 10:\r
- case 11:\r
- case 12:\r
- //text.offset\r
- val = LittleEndian.getShort(_data, pos); pos += 2;\r
- textOffsets[bits[i]-8] = val;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Default distance between tab stops, in master coordinates (576 dpi).\r
- */\r
- public int getDefaultTabSize(){\r
- return defaultTabSize;\r
- }\r
-\r
- /**\r
- * Number of indent levels (maximum 5).\r
- */\r
- public int getNumberOfLevels(){\r
- return numLevels;\r
- }\r
-\r
- /**\r
- * Default distance between tab stops, in master coordinates (576 dpi).\r
- */\r
- public int[] getTabStops(){\r
- return tabStops;\r
- }\r
-\r
- /**\r
- * Paragraph's distance from shape's left margin, in master coordinates (576 dpi).\r
- */\r
- public int[] getTextOffsets(){\r
- return textOffsets;\r
- }\r
-\r
- /**\r
- * First line of paragraph's distance from shape's left margin, in master coordinates (576 dpi).\r
- */\r
- public int[] getBulletOffsets(){\r
- return bulletOffsets;\r
- }\r
-\r
- public static TextRulerAtom getParagraphInstance(){\r
- byte[] data = new byte[] {\r
- 0x00, 0x00, (byte)0xA6, 0x0F, 0x0A, 0x00, 0x00, 0x00,\r
- 0x10, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01\r
- };\r
- TextRulerAtom ruler = new TextRulerAtom(data, 0, data.length);\r
- return ruler;\r
- }\r
-\r
- public void setParagraphIndent(short tetxOffset, short bulletOffset){\r
- LittleEndian.putShort(_data, 4, tetxOffset);\r
- LittleEndian.putShort(_data, 6, bulletOffset);\r
- LittleEndian.putShort(_data, 8, bulletOffset);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.InflaterInputStream;
+
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * Ruler of a text as it differs from the style's ruler settings.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TextRulerAtom extends RecordAtom {
+
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * Record data.
+ */
+ private byte[] _data;
+
+ //ruler internals
+ private int defaultTabSize;
+ private int numLevels;
+ private int[] tabStops;
+ private int[] bulletOffsets = new int[5];
+ private int[] textOffsets = new int[5];
+
+ /**
+ * Constructs a new empty ruler atom.
+ */
+ public TextRulerAtom() {
+ _header = new byte[8];
+ _data = new byte[0];
+
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _data.length);
+ }
+
+ /**
+ * Constructs the ruler atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected TextRulerAtom(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Get the record data.
+ _data = new byte[len-8];
+ System.arraycopy(source,start+8,_data,0,len-8);
+
+ try {
+ read();
+ } catch (Exception e){
+ logger.log(POILogger.ERROR, "Failed to parse TextRulerAtom: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Gets the record type.
+ *
+ * @return the record type.
+ */
+ public long getRecordType() {
+ return RecordTypes.TextRulerAtom.typeID;
+ }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk.
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_data);
+ }
+
+ /**
+ * Read the record bytes and initialize the internal variables
+ */
+ private void read(){
+ int pos = 0;
+ short mask = LittleEndian.getShort(_data); pos += 4;
+ short val;
+ int[] bits = {1, 0, 2, 3, 8, 4, 9, 5, 10, 6, 11, 7, 12};
+ for (int i = 0; i < bits.length; i++) {
+ if((mask & 1 << bits[i]) != 0){
+ switch (bits[i]){
+ case 0:
+ //defaultTabSize
+ defaultTabSize = LittleEndian.getShort(_data, pos); pos += 2;
+ break;
+ case 1:
+ //numLevels
+ numLevels = LittleEndian.getShort(_data, pos); pos += 2;
+ break;
+ case 2:
+ //tabStops
+ val = LittleEndian.getShort(_data, pos); pos += 2;
+ tabStops = new int[val*2];
+ for (int j = 0; j < tabStops.length; j++) {
+ tabStops[j] = LittleEndian.getUShort(_data, pos); pos += 2;
+ }
+ break;
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ //bullet.offset
+ val = LittleEndian.getShort(_data, pos); pos += 2;
+ bulletOffsets[bits[i]-3] = val;
+ break;
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ //text.offset
+ val = LittleEndian.getShort(_data, pos); pos += 2;
+ textOffsets[bits[i]-8] = val;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Default distance between tab stops, in master coordinates (576 dpi).
+ */
+ public int getDefaultTabSize(){
+ return defaultTabSize;
+ }
+
+ /**
+ * Number of indent levels (maximum 5).
+ */
+ public int getNumberOfLevels(){
+ return numLevels;
+ }
+
+ /**
+ * Default distance between tab stops, in master coordinates (576 dpi).
+ */
+ public int[] getTabStops(){
+ return tabStops;
+ }
+
+ /**
+ * Paragraph's distance from shape's left margin, in master coordinates (576 dpi).
+ */
+ public int[] getTextOffsets(){
+ return textOffsets;
+ }
+
+ /**
+ * First line of paragraph's distance from shape's left margin, in master coordinates (576 dpi).
+ */
+ public int[] getBulletOffsets(){
+ return bulletOffsets;
+ }
+
+ public static TextRulerAtom getParagraphInstance(){
+ byte[] data = new byte[] {
+ 0x00, 0x00, (byte)0xA6, 0x0F, 0x0A, 0x00, 0x00, 0x00,
+ 0x10, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01
+ };
+ TextRulerAtom ruler = new TextRulerAtom(data, 0, data.length);
+ return ruler;
+ }
+
+ public void setParagraphIndent(short tetxOffset, short bulletOffset){
+ LittleEndian.putShort(_data, 4, tetxOffset);
+ LittleEndian.putShort(_data, 6, bulletOffset);
+ LittleEndian.putShort(_data, 8, bulletOffset);
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-import java.io.OutputStream;\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-\r
-/**\r
- * The special info runs contained in this text.\r
- * Special info runs consist of character properties which don?t follow styles.\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TextSpecInfoAtom extends RecordAtom {\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * Record data.\r
- */\r
- private byte[] _data;\r
-\r
- /**\r
- * Constructs the link related atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected TextSpecInfoAtom(byte[] source, int start, int len) {\r
- // Get the header.\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Get the record data.\r
- _data = new byte[len-8];\r
- System.arraycopy(source,start+8,_data,0,len-8);\r
-\r
- }\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() { return RecordTypes.TextSpecInfoAtom.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_data);\r
- }\r
-\r
- /**\r
- * Update the text length\r
- *\r
- * @param size the text length\r
- */\r
- public void setTextSize(int size){\r
- LittleEndian.putInt(_data, 0, size);\r
- }\r
-\r
- /**\r
- * Reset the content to one info run with the default values\r
- * @param size the site of parent text\r
- */\r
- public void reset(int size){\r
- _data = new byte[10];\r
- // 01 00 00 00\r
- LittleEndian.putInt(_data, 0, size);\r
- // 01 00 00 00\r
- LittleEndian.putInt(_data, 4, 1); //mask\r
- // 00 00\r
- LittleEndian.putShort(_data, 8, (short)0); //langId\r
-\r
- // Update the size (header bytes 5-8)\r
- LittleEndian.putInt(_header, 4, _data.length);\r
- }\r
-\r
- /**\r
- * Get the number of characters covered by this records\r
- *\r
- * @return the number of characters covered by this records\r
- */\r
- public int getCharactersCovered(){\r
- int covered = 0;\r
- TextSpecInfoRun[] runs = getTextSpecInfoRuns();\r
- for (int i = 0; i < runs.length; i++) covered += runs[i].len;\r
- return covered;\r
- }\r
-\r
- public TextSpecInfoRun[] getTextSpecInfoRuns(){\r
- ArrayList lst = new ArrayList();\r
- int pos = 0;\r
- int[] bits = {1, 0, 2};\r
- while(pos < _data.length) {\r
- TextSpecInfoRun run = new TextSpecInfoRun();\r
- run.len = LittleEndian.getInt(_data, pos); pos += 4;\r
- run.mask = LittleEndian.getInt(_data, pos); pos += 4;\r
- for (int i = 0; i < bits.length; i++) {\r
- if((run.mask & 1 << bits[i]) != 0){\r
- switch (bits[i]){\r
- case 0:\r
- run.spellInfo = LittleEndian.getShort(_data, pos); pos += 2;\r
- break;\r
- case 1:\r
- run.langId = LittleEndian.getShort(_data, pos); pos += 2;\r
- break;\r
- case 2:\r
- run.altLangId = LittleEndian.getShort(_data, pos); pos += 2;\r
- break;\r
- }\r
- }\r
- }\r
- lst.add(run);\r
- }\r
- return (TextSpecInfoRun[])lst.toArray(new TextSpecInfoRun[lst.size()]);\r
-\r
- }\r
-\r
- public static class TextSpecInfoRun {\r
- //Length of special info run.\r
- protected int len;\r
-\r
- //Special info mask of this run;\r
- protected int mask;\r
-\r
- // info fields as indicated by the mask.\r
- // -1 means the bit is not set\r
- protected short spellInfo = -1;\r
- protected short langId = -1;\r
- protected short altLangId = -1;\r
-\r
- /**\r
- * Spelling status of this text. See Spell Info table below.\r
- *\r
- * <p>Spell Info Types:</p>\r
- * <li>0 Unchecked\r
- * <li>1 Previously incorrect, needs rechecking\r
- * <li>2 Correct\r
- * <li>3 Incorrect\r
- *\r
- * @return Spelling status of this text\r
- */\r
- public short getSpellInfo(){\r
- return spellInfo;\r
- }\r
-\r
- /**\r
- * Windows LANGID for this text.\r
- *\r
- * @return Windows LANGID for this text.\r
- */\r
- public short getLangId(){\r
- return spellInfo;\r
- }\r
-\r
- /**\r
- * Alternate Windows LANGID of this text;\r
- * must be a valid non-East Asian LANGID if the text has an East Asian language,\r
- * otherwise may be an East Asian LANGID or language neutral (zero).\r
- *\r
- * @return Alternate Windows LANGID of this text\r
- */\r
- public short getAltLangId(){\r
- return altLangId;\r
- }\r
-\r
- /**\r
- * @return Length of special info run.\r
- */\r
- public int length(){\r
- return len;\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.util.LittleEndian;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * The special info runs contained in this text.
+ * Special info runs consist of character properties which don?t follow styles.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TextSpecInfoAtom extends RecordAtom {
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * Record data.
+ */
+ private byte[] _data;
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected TextSpecInfoAtom(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Get the record data.
+ _data = new byte[len-8];
+ System.arraycopy(source,start+8,_data,0,len-8);
+
+ }
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() { return RecordTypes.TextSpecInfoAtom.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_data);
+ }
+
+ /**
+ * Update the text length
+ *
+ * @param size the text length
+ */
+ public void setTextSize(int size){
+ LittleEndian.putInt(_data, 0, size);
+ }
+
+ /**
+ * Reset the content to one info run with the default values
+ * @param size the site of parent text
+ */
+ public void reset(int size){
+ _data = new byte[10];
+ // 01 00 00 00
+ LittleEndian.putInt(_data, 0, size);
+ // 01 00 00 00
+ LittleEndian.putInt(_data, 4, 1); //mask
+ // 00 00
+ LittleEndian.putShort(_data, 8, (short)0); //langId
+
+ // Update the size (header bytes 5-8)
+ LittleEndian.putInt(_header, 4, _data.length);
+ }
+
+ /**
+ * Get the number of characters covered by this records
+ *
+ * @return the number of characters covered by this records
+ */
+ public int getCharactersCovered(){
+ int covered = 0;
+ TextSpecInfoRun[] runs = getTextSpecInfoRuns();
+ for (int i = 0; i < runs.length; i++) covered += runs[i].len;
+ return covered;
+ }
+
+ public TextSpecInfoRun[] getTextSpecInfoRuns(){
+ ArrayList lst = new ArrayList();
+ int pos = 0;
+ int[] bits = {1, 0, 2};
+ while(pos < _data.length) {
+ TextSpecInfoRun run = new TextSpecInfoRun();
+ run.len = LittleEndian.getInt(_data, pos); pos += 4;
+ run.mask = LittleEndian.getInt(_data, pos); pos += 4;
+ for (int i = 0; i < bits.length; i++) {
+ if((run.mask & 1 << bits[i]) != 0){
+ switch (bits[i]){
+ case 0:
+ run.spellInfo = LittleEndian.getShort(_data, pos); pos += 2;
+ break;
+ case 1:
+ run.langId = LittleEndian.getShort(_data, pos); pos += 2;
+ break;
+ case 2:
+ run.altLangId = LittleEndian.getShort(_data, pos); pos += 2;
+ break;
+ }
+ }
+ }
+ lst.add(run);
+ }
+ return (TextSpecInfoRun[])lst.toArray(new TextSpecInfoRun[lst.size()]);
+
+ }
+
+ public static class TextSpecInfoRun {
+ //Length of special info run.
+ protected int len;
+
+ //Special info mask of this run;
+ protected int mask;
+
+ // info fields as indicated by the mask.
+ // -1 means the bit is not set
+ protected short spellInfo = -1;
+ protected short langId = -1;
+ protected short altLangId = -1;
+
+ /**
+ * Spelling status of this text. See Spell Info table below.
+ *
+ * <p>Spell Info Types:</p>
+ * <li>0 Unchecked
+ * <li>1 Previously incorrect, needs rechecking
+ * <li>2 Correct
+ * <li>3 Incorrect
+ *
+ * @return Spelling status of this text
+ */
+ public short getSpellInfo(){
+ return spellInfo;
+ }
+
+ /**
+ * Windows LANGID for this text.
+ *
+ * @return Windows LANGID for this text.
+ */
+ public short getLangId(){
+ return spellInfo;
+ }
+
+ /**
+ * Alternate Windows LANGID of this text;
+ * must be a valid non-East Asian LANGID if the text has an East Asian language,
+ * otherwise may be an East Asian LANGID or language neutral (zero).
+ *
+ * @return Alternate Windows LANGID of this text
+ */
+ public short getAltLangId(){
+ return altLangId;
+ }
+
+ /**
+ * @return Length of special info run.
+ */
+ public int length(){
+ return len;
+ }
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.util.LittleEndian;\r
-\r
-import java.io.OutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * Tne atom that holds starting and ending character positions of a hyperlink\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TxInteractiveInfoAtom extends RecordAtom {\r
- /**\r
- * Record header.\r
- */\r
- private byte[] _header;\r
-\r
- /**\r
- * Record data.\r
- */\r
- private byte[] _data;\r
-\r
- /**\r
- * Constructs a brand new link related atom record.\r
- */\r
- public TxInteractiveInfoAtom() {\r
- _header = new byte[8];\r
- _data = new byte[8];\r
-\r
- LittleEndian.putShort(_header, 2, (short)getRecordType());\r
- LittleEndian.putInt(_header, 4, _data.length);\r
- }\r
-\r
- /**\r
- * Constructs the link related atom record from its\r
- * source data.\r
- *\r
- * @param source the source data as a byte array.\r
- * @param start the start offset into the byte array.\r
- * @param len the length of the slice in the byte array.\r
- */\r
- protected TxInteractiveInfoAtom(byte[] source, int start, int len) {\r
- // Get the header.\r
- _header = new byte[8];\r
- System.arraycopy(source,start,_header,0,8);\r
-\r
- // Get the record data.\r
- _data = new byte[len-8];\r
- System.arraycopy(source,start+8,_data,0,len-8);\r
-\r
- }\r
-\r
- /**\r
- * Gets the beginning character position\r
- *\r
- * @return the beginning character position\r
- */\r
- public int getStartIndex() {\r
- return LittleEndian.getInt(_data, 0);\r
- }\r
-\r
- /**\r
- * Sets the beginning character position\r
- * @param idx the beginning character position\r
- */\r
- public void setStartIndex(int idx) {\r
- LittleEndian.putInt(_data, 0, idx);\r
- }\r
-\r
- /**\r
- * Gets the ending character position\r
- *\r
- * @return the ending character position\r
- */\r
- public int getEndIndex() {\r
- return LittleEndian.getInt(_data, 4);\r
- }\r
-\r
- /**\r
- * Sets the ending character position\r
- *\r
- * @param idx the ending character position\r
- */\r
- public void setEndIndex(int idx) {\r
- LittleEndian.putInt(_data, 4, idx);\r
- }\r
-\r
- /**\r
- * Gets the record type.\r
- * @return the record type.\r
- */\r
- public long getRecordType() { return RecordTypes.TxInteractiveInfoAtom.typeID; }\r
-\r
- /**\r
- * Write the contents of the record back, so it can be written\r
- * to disk\r
- *\r
- * @param out the output stream to write to.\r
- * @throws java.io.IOException if an error occurs.\r
- */\r
- public void writeOut(OutputStream out) throws IOException {\r
- out.write(_header);\r
- out.write(_data);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.util.LittleEndian;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * Tne atom that holds starting and ending character positions of a hyperlink
+ *
+ * @author Yegor Kozlov
+ */
+public final class TxInteractiveInfoAtom extends RecordAtom {
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * Record data.
+ */
+ private byte[] _data;
+
+ /**
+ * Constructs a brand new link related atom record.
+ */
+ public TxInteractiveInfoAtom() {
+ _header = new byte[8];
+ _data = new byte[8];
+
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _data.length);
+ }
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected TxInteractiveInfoAtom(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Get the record data.
+ _data = new byte[len-8];
+ System.arraycopy(source,start+8,_data,0,len-8);
+
+ }
+
+ /**
+ * Gets the beginning character position
+ *
+ * @return the beginning character position
+ */
+ public int getStartIndex() {
+ return LittleEndian.getInt(_data, 0);
+ }
+
+ /**
+ * Sets the beginning character position
+ * @param idx the beginning character position
+ */
+ public void setStartIndex(int idx) {
+ LittleEndian.putInt(_data, 0, idx);
+ }
+
+ /**
+ * Gets the ending character position
+ *
+ * @return the ending character position
+ */
+ public int getEndIndex() {
+ return LittleEndian.getInt(_data, 4);
+ }
+
+ /**
+ * Sets the ending character position
+ *
+ * @param idx the ending character position
+ */
+ public void setEndIndex(int idx) {
+ LittleEndian.putInt(_data, 4, idx);
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() { return RecordTypes.TxInteractiveInfoAtom.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws java.io.IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_data);
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
*
* @author Yegor Kozlov
*/
-public class TxMasterStyleAtom extends RecordAtom {
+public final class TxMasterStyleAtom extends RecordAtom {
/**
* Maximum number of indentatio levels allowed in PowerPoint documents
* Must be a constant defined in <code>TextHeaderAtom</code>
*
* @return type of the text
- * @see TextHeaderAtom
+ * @see TextHeaderAtom
*/
public int getTextType(){
//The atom instance value is the text type
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class UnknownRecordPlaceholder extends RecordAtom
+public final class UnknownRecordPlaceholder extends RecordAtom
{
private byte[] _contents;
private long _type;
- /**
+ /**
* Create a new holder for a record we don't grok
*/
protected UnknownRecordPlaceholder(byte[] source, int start, int len) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.record;
* @author Nick Burch
*/
-public class UserEditAtom extends PositionDependentRecordAtom
+public final class UserEditAtom extends PositionDependentRecordAtom
{
public static final int LAST_VIEW_NONE = 0;
public static final int LAST_VIEW_SLIDE_VIEW = 1;
/* *************** record code follows ********************** */
- /**
+ /**
* For the UserEdit Atom
*/
protected UserEditAtom(byte[] source, int start, int len) {
pptVersion = (int)LittleEndian.getInt(source,start+4+8);
// Get the offset to the previous incremental save's UserEditAtom
- // This will be the byte offset on disk where the previous one
+ // This will be the byte offset on disk where the previous one
// starts, or 0 if this is the first one
lastUserEditAtomOffset = (int)LittleEndian.getInt(source,start+8+8);
// Get the offset to the persist pointers
- // This will be the byte offset on disk where the preceding
+ // This will be the byte offset on disk where the preceding
// PersistPtrFullBlock or PersistPtrIncrementalBlock starts
persistPointersOffset = (int)LittleEndian.getInt(source,start+12+8);
// Maximum number of persist objects written
maxPersistWritten = (int)LittleEndian.getInt(source,start+20+8);
-
+
// Last view type
lastViewType = (short)LittleEndian.getShort(source,start+24+8);
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.usermodel;
import org.apache.poi.util.LittleEndian;
* Register ImagePainter for the specified image type
*
* @param type image type, must be one of the static constants defined in the <code>Picture<code> class.
- * @param painter
+ * @param painter
*/
public static void setImagePainter(int type, ImagePainter painter){
painters[type] = painter;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
/**
* Represents a run of text, all with the same style
- *
+ *
*/
-public class RichTextRun {
+public final class RichTextRun {
protected POILogger logger = POILogFactory.getLogger(this.getClass());
/** The TextRun we belong to */
private TextRun parentRun;
/** The SlideShow we belong to */
private SlideShow slideShow;
-
+
/** Where in the parent TextRun we start from */
private int startPos;
-
+
/** How long a string (in the parent TextRun) we represent */
private int length;
-
+
private String _fontname;
/**
* Our paragraph and character style.
* @param pShared The paragraph styles are shared with other runs
* @param cShared The character styles are shared with other runs
*/
- public RichTextRun(TextRun parent, int startAt, int len,
+ public RichTextRun(TextRun parent, int startAt, int len,
TextPropCollection pStyle, TextPropCollection cStyle,
boolean pShared, boolean cShared) {
parentRun = parent;
}
/**
- * Supply (normally default) textprops, and if they're shared,
- * when a run gets them
+ * Supply (normally default) textprops, and if they're shared,
+ * when a run gets them
*/
public void supplyTextProps(TextPropCollection pStyle, TextPropCollection cStyle, boolean pShared, boolean cShared) {
if(paragraphStyle != null || characterStyle != null) {
_fontname = null;
}
}
-
+
/**
* Get the length of the text
*/
public String getRawText() {
return parentRun.getRawText().substring(startPos, startPos+length);
}
-
+
/**
* Change the text
*/
String s = parentRun.normalize(text);
setRawText(s);
}
-
+
/**
* Change the text
*/
public void updateStartPosition(int startAt) {
startPos = startAt;
}
-
-
+
+
// --------------- Internal helpers on rich text properties -------
-
+
/**
* Fetch the value of the given flag in the CharFlagsTextProp.
* Returns false if the CharFlagsTextProp isn't present, since the
/**
* Set the value of the given flag in the CharFlagsTextProp, adding
- * it if required.
+ * it if required.
*/
private void setCharFlagsTextPropVal(int index, boolean value) {
if(getFlag(true, index) != value) setFlag(true, index, value);
}
return tp;
}
-
+
/**
- * Fetch the value of the given Character related TextProp.
- * Returns -1 if that TextProp isn't present.
- * If the TextProp isn't present, the value from the appropriate
+ * Fetch the value of the given Character related TextProp.
+ * Returns -1 if that TextProp isn't present.
+ * If the TextProp isn't present, the value from the appropriate
* Master Sheet will apply.
*/
private int getCharTextPropVal(String propName) {
return prop == null ? -1 : prop.getValue();
}
-
+
/**
* Sets the value of the given Character TextProp, add if required
* @param propName The name of the Character TextProp
parentRun.ensureStyleAtomPresent();
// paragraphStyle will now be defined
}
-
+
TextProp tp = fetchOrAddTextProp(paragraphStyle, propName);
tp.setValue(val);
}
parentRun.ensureStyleAtomPresent();
// characterStyle will now be defined
}
-
+
TextProp tp = fetchOrAddTextProp(characterStyle, propName);
tp.setValue(val);
}
-
-
+
+
// --------------- Friendly getters / setters on rich text properties -------
/**
public void setBold(boolean bold) {
setCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX, bold);
}
-
+
/**
* Is the text italic?
*/
public void setItalic(boolean italic) {
setCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX, italic);
}
-
+
/**
* Is the text underlined?
*/
return slideShow.getFontCollection().getFontWithId(fontIdx);
}
}
-
+
/**
* @return font color as RGB value
* @see java.awt.Color
/**
* Sets color of the text, as a int bgr.
* (PowerPoint stores as BlueGreenRed, not the more
- * usual RedGreenBlue)
+ * usual RedGreenBlue)
* @see java.awt.Color
*/
public void setFontColor(int bgr) {
setCharTextPropVal("font.color", bgr);
}
-
+
/**
* Sets color of the text, as a java.awt.Color
*/
return val == -1 ? 0 : val;
}
// --------------- Internal HSLF methods, not intended for end-user use! -------
-
+
/**
* Internal Use Only - get the underlying paragraph style collection.
- * For normal use, use the friendly setters and getters
+ * For normal use, use the friendly setters and getters
*/
public TextPropCollection _getRawParagraphStyle() { return paragraphStyle; }
/**
* Internal Use Only - get the underlying character style collection.
- * For normal use, use the friendly setters and getters
+ * For normal use, use the friendly setters and getters
*/
public TextPropCollection _getRawCharacterStyle() { return characterStyle; }
/**
* - figure out how to match notes to their correct sheet
* (will involve understanding DocSlideList and DocNotesList)
* - handle Slide creation cleaner
- *
+ *
* @author Nick Burch
* @author Yegor kozlov
*/
// For logging
private POILogger logger = POILogFactory.getLogger(this.getClass());
-
+
/* ===============================================================
* Setup Code
* ===============================================================
*/
-
+
/**
- * Constructs a Powerpoint document from the underlying
+ * Constructs a Powerpoint document from the underlying
* HSLFSlideShow object. Finds the model stuff from this
*
* @param hslfSlideShow the HSLFSlideShow to base on
// Get useful things from our base slideshow
_hslfSlideShow = hslfSlideShow;
_records = _hslfSlideShow.getRecords();
-
+
// Handle Parent-aware Reocrds
for(int i=0; i<_records.length; i++) {
handleParentAwareRecords(_records[i]);
// Find the versions of the core records we'll want to use
findMostRecentCoreRecords();
-
+
// Build up the model level Slides and Notes
buildSlidesAndNotes();
}
-
+
/**
* Constructs a new, empty, Powerpoint document.
*/
if(baseRecord instanceof RecordContainer) {
RecordContainer br = (RecordContainer)baseRecord;
Record[] childRecords = br.getChildRecords();
-
+
// Loop over child records, looking for interesting ones
for(int i=0; i<childRecords.length; i++) {
Record record = childRecords[i];
if(_records[i] instanceof PersistPtrHolder) {
PersistPtrHolder pph = (PersistPtrHolder)_records[i];
- // If we've already seen any of the "slide" IDs for this
+ // If we've already seen any of the "slide" IDs for this
// PersistPtr, remove their old positions
int[] ids = pph.getKnownSlideIDs();
for(int j=0; j<ids.length; j++) {
Integer id = new Integer(ids[j]);
if( mostRecentByBytes.containsKey(id)) {
mostRecentByBytes.remove(id);
- }
+ }
}
// Now, update the byte level locations with their latest values
// We now know how many unique special records we have, so init
// the array
_mostRecentCoreRecords = new Record[mostRecentByBytes.size()];
-
+
// We'll also want to be able to turn the slide IDs into a position
// in this array
_sheetIdToCoreRecordsLookup = new Hashtable();
if(thatRecordAt.equals(recordAt)) {
// Bingo. Now, where do we store it?
- Integer storeAtI =
+ Integer storeAtI =
(Integer)_sheetIdToCoreRecordsLookup.get(thisID);
int storeAt = storeAtI.intValue();
-
+
// Tell it its Sheet ID, if it cares
if(pdr instanceof PositionDependentRecordContainer) {
- PositionDependentRecordContainer pdrc =
+ PositionDependentRecordContainer pdrc =
(PositionDependentRecordContainer)_records[i];
pdrc.setSheetId(thisID.intValue());
}
-
+
// Finally, save the record
_mostRecentCoreRecords[storeAt] = _records[i];
}
}
}
}
-
+
// Now look for the interesting records in there
for(int i=0; i<_mostRecentCoreRecords.length; i++) {
// Check there really is a record at this number
}
}
}
-
+
/**
* For a given SlideAtomsSet, return the core record, based on the refID from the
* SlidePersistAtom
int refID = spa.getRefID();
return getCoreRecordForRefID(refID);
}
-
+
/**
* For a given refID (the internal, 0 based numbering scheme), return the
* core record
// Having indentified the masters, slides and notes + their orders,
// we have to go and find their matching records
// We always use the latest versions of these records, and use the
- // SlideAtom/NotesAtom to match them with the StyleAtomSet
+ // SlideAtom/NotesAtom to match them with the StyleAtomSet
SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText();
SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
Hashtable slideIdToNotes = new Hashtable();
if(notesSLWT == null) {
// None
- notesRecords = new org.apache.poi.hslf.record.Notes[0];
+ notesRecords = new org.apache.poi.hslf.record.Notes[0];
} else {
// Match up the records and the SlideAtomSets
notesSets = notesSLWT.getSlideAtomsSets();
notesRecords = (org.apache.poi.hslf.record.Notes[])
notesRecordsL.toArray(notesRecords);
}
-
+
// Now, do the same thing for our slides
org.apache.poi.hslf.record.Slide[] slidesRecords;
SlideAtomsSet[] slidesSets = new SlideAtomsSet[0];
if(slidesSLWT == null) {
// None
- slidesRecords = new org.apache.poi.hslf.record.Slide[0];
+ slidesRecords = new org.apache.poi.hslf.record.Slide[0];
} else {
// Match up the records and the SlideAtomSets
slidesSets = slidesSLWT.getSlideAtomsSets();
for(int i=0; i<slidesSets.length; i++) {
// Get the right core record
Record r = getCoreRecordForSAS(slidesSets[i]);
-
+
// Ensure it really is a slide record
if(r instanceof org.apache.poi.hslf.record.Slide) {
slidesRecords[i] = (org.apache.poi.hslf.record.Slide)r;
}
}
}
-
+
// Finally, generate model objects for everything
// Notes first
_notes = new Notes[notesRecords.length];
* Accessor Code
* ===============================================================
*/
-
+
/**
* Returns an array of the most recent version of all the interesting
int pgy = (int)docatom.getSlideSizeY()*Shape.POINT_DPI/Shape.MASTER_DPI;
return new Dimension(pgx, pgy);
}
-
+
/**
* Change the current page size
- *
+ *
* @param pgsize page size (in points)
*/
public void setPageSize(Dimension pgsize){
docatom.setSlideSizeX(pgsize.width*Shape.MASTER_DPI/Shape.POINT_DPI);
docatom.setSlideSizeY(pgsize.height*Shape.MASTER_DPI/Shape.POINT_DPI);
}
-
+
/**
* Helper method for usermodel: Get the font collection
*/
*/
public Document getDocumentRecord() { return _documentRecord; }
-
+
/* ===============================================================
* Re-ordering Code
* ===============================================================
*/
-
-
+
+
/**
* Re-orders a slide, to a new position.
* @param oldSlideNumber The old slide number (1 based)
* Addition Code
* ===============================================================
*/
-
+
/**
* Create a blank <code>Slide</code>.
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.usermodel;\r
-\r
-import org.apache.poi.hslf.record.*;\r
-\r
-import java.util.ArrayList;\r
-\r
-/**\r
- * A class that represents sound data embedded in a slide show.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class SoundData {\r
- /**\r
- * The record that contains the object data.\r
- */\r
- private Sound _container;\r
-\r
- /**\r
- * Creates the object data wrapping the record that contains the sound data.\r
- *\r
- * @param container the record that contains the sound data.\r
- */\r
- public SoundData(Sound container) {\r
- this._container = container;\r
- }\r
-\r
- /**\r
- * Name of the sound (e.g. "crash")\r
- *\r
- * @return name of the sound\r
- */\r
- public String getSoundName(){\r
- return _container.getSoundName();\r
- }\r
-\r
- /**\r
- * Type of the sound (e.g. ".wav")\r
- *\r
- * @return type of the sound\r
- */\r
- public String getSoundType(){\r
- return _container.getSoundType();\r
- }\r
-\r
- /**\r
- * Gets an input stream which returns the binary of the sound data.\r
- *\r
- * @return the input stream which will contain the binary of the sound data.\r
- */\r
- public byte[] getData() {\r
- return _container.getSoundData();\r
- }\r
-\r
- /**\r
- * Find all sound records in the supplied Document records\r
- *\r
- * @param document the document to find in\r
- * @return the array with the sound data\r
- */\r
- public static SoundData[] find(Document document){\r
- ArrayList lst = new ArrayList();\r
- Record[] ch = document.getChildRecords();\r
- for (int i = 0; i < ch.length; i++) {\r
- if(ch[i].getRecordType() == RecordTypes.SoundCollection.typeID){\r
- RecordContainer col = (RecordContainer)ch[i];\r
- Record[] sr = col.getChildRecords();\r
- for (int j = 0; j < sr.length; j++) {\r
- if(sr[j] instanceof Sound){\r
- lst.add(new SoundData((Sound)sr[j]));\r
- }\r
- }\r
- }\r
-\r
- }\r
- return (SoundData[])lst.toArray(new SoundData[lst.size()]);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.usermodel;
+
+import org.apache.poi.hslf.record.*;
+
+import java.util.ArrayList;
+
+/**
+ * A class that represents sound data embedded in a slide show.
+ *
+ * @author Yegor Kozlov
+ */
+public final class SoundData {
+ /**
+ * The record that contains the object data.
+ */
+ private Sound _container;
+
+ /**
+ * Creates the object data wrapping the record that contains the sound data.
+ *
+ * @param container the record that contains the sound data.
+ */
+ public SoundData(Sound container) {
+ this._container = container;
+ }
+
+ /**
+ * Name of the sound (e.g. "crash")
+ *
+ * @return name of the sound
+ */
+ public String getSoundName(){
+ return _container.getSoundName();
+ }
+
+ /**
+ * Type of the sound (e.g. ".wav")
+ *
+ * @return type of the sound
+ */
+ public String getSoundType(){
+ return _container.getSoundType();
+ }
+
+ /**
+ * Gets an input stream which returns the binary of the sound data.
+ *
+ * @return the input stream which will contain the binary of the sound data.
+ */
+ public byte[] getData() {
+ return _container.getSoundData();
+ }
+
+ /**
+ * Find all sound records in the supplied Document records
+ *
+ * @param document the document to find in
+ * @return the array with the sound data
+ */
+ public static SoundData[] find(Document document){
+ ArrayList lst = new ArrayList();
+ Record[] ch = document.getChildRecords();
+ for (int i = 0; i < ch.length; i++) {
+ if(ch[i].getRecordType() == RecordTypes.SoundCollection.typeID){
+ RecordContainer col = (RecordContainer)ch[i];
+ Record[] sr = col.getChildRecords();
+ for (int j = 0; j < sr.length; j++) {
+ if(sr[j] instanceof Sound){
+ lst.add(new SoundData((Sound)sr[j]));
+ }
+ }
+ }
+
+ }
+ return (SoundData[])lst.toArray(new SoundData[lst.size()]);
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hslf.util;
* @author Nick Burch
*/
-public class MutableByteArrayOutputStream extends ByteArrayOutputStream
+public final class MutableByteArrayOutputStream extends ByteArrayOutputStream
{
/** Return how many bytes we've stuffed in so far */
public int getBytesWritten() { return -1; }
/**
* A helper class for dealing with SystemTime Structs, as defined at
* http://msdn.microsoft.com/library/en-us/sysinfo/base/systemtime_str.asp .
- *
+ *
* Discrepancies between Calendar and SYSTEMTIME:
* - that January = 1 in SYSTEMTIME, 0 in Calendar.
* - that the day of the week (0) starts on Sunday in SYSTEMTIME, and Monday in Calendar
* @author Daniel Noll
* @author Nick Burch
*/
-public class SystemTimeUtils {
+public final class SystemTimeUtils {
/**
* Get the date found in the byte array, as a java Data object
*/
*/
public static Date getDate(byte[] data, int offset) {
Calendar cal = new GregorianCalendar();
-
+
cal.set(Calendar.YEAR, LittleEndian.getShort(data,offset));
cal.set(Calendar.MONTH, LittleEndian.getShort(data,offset+2)-1);
- // Not actually needed - can be found from day of month
+ // Not actually needed - can be found from day of month
//cal.set(Calendar.DAY_OF_WEEK, LittleEndian.getShort(data,offset+4)+1);
cal.set(Calendar.DAY_OF_MONTH, LittleEndian.getShort(data,offset+6));
cal.set(Calendar.HOUR_OF_DAY, LittleEndian.getShort(data,offset+8));
return cal.getTime();
}
-
+
/**
* Convert the supplied java Date into a SystemTime struct, and write it
- * into the supplied byte array.
+ * into the supplied byte array.
*/
public static void storeDate(Date date, byte[] dest) {
storeDate(date, dest, 0);
}
/**
* Convert the supplied java Date into a SystemTime struct, and write it
- * into the supplied byte array.
+ * into the supplied byte array.
*/
public static void storeDate(Date date, byte[] dest, int offset) {
Calendar cal = new GregorianCalendar();
protected int chunkId;
protected int type;
protected String namePrefix = "__substg1.0_";
-
+
/**
* Gets the id of this chunk
*/
public int getChunkId() {
return this.chunkId;
}
-
+
/**
* Gets the numeric type of this chunk.
*/
public int getType() {
return this.type;
}
-
+
/**
* Creates a string to use to identify this chunk in the POI file system object.
*/
public String getEntryName() {
String type = Integer.toHexString(this.type);
while(type.length() < 4) type = "0" + type;
-
+
String chunkId = Integer.toHexString(this.chunkId);
while(chunkId.length() < 4) chunkId = "0" + chunkId;
-
+
return this.namePrefix + chunkId.toUpperCase() + type.toUpperCase();
}
-
+
/**
* Gets a reference to a ByteArrayOutputStream that contains the value of this chunk.
*/
public abstract ByteArrayOutputStream getValueByteArray();
-
+
/**
* Sets the value of this chunk using a OutputStream
* @param value
/**
* Collection of convenence chunks for standard parts of the MSG file.
- *
+ *
* @author Travis Ferguson
*/
-public class Chunks {
+public final class Chunks {
/* String parts of Outlook Messages that are currently known */
/** Type of message that the MSG represents (ie. IPM.Note) */
public StringChunk conversationTopic;
/** Type of server that the message originated from (SMTP, etc). */
public StringChunk sentByServerType;
-
+
private Chunks(boolean newStringType) {
messageClass = new StringChunk(0x001A, newStringType);
textBodyChunk = new StringChunk(0x1000, newStringType);
conversationTopic = new StringChunk(0x0070, newStringType);
sentByServerType = new StringChunk(0x0075, newStringType);
}
-
+
public static Chunks getInstance(boolean newStringType) {
return new Chunks(newStringType);
}
package org.apache.poi.hsmf.datatypes;
-public class Types {
+public final class Types {
public static int BINARY = 0x0102;
-
+
/** A string, until Outlook 3.0 */
public static int OLD_STRING = 0x001E;
/** A string, from Outlook 3.0 onwards */
public static int NEW_STRING = 0x001F;
-
+
public static int LONG = 0x0003;
public static int TIME = 0x0040;
public static int BOOLEAN = 0x000B;
-
+
public static String asFileEnding(int type) {
String str = Integer.toHexString(type).toUpperCase();
while(str.length() < 4) {
package org.apache.poi.hsmf.exceptions;
-public class ChunkNotFoundException extends Exception {
+public final class ChunkNotFoundException extends Exception {
private static final long serialVersionUID = 1L;
public ChunkNotFoundException(String chunkName) {
* Exception for when a directory chunk is not found but is expected.
* @author Travis Ferguson
*/
-public class DirectoryChunkNotFoundException extends Exception {
+public final class DirectoryChunkNotFoundException extends Exception {
private static final long serialVersionUID = 1L;
public DirectoryChunkNotFoundException(String directory) {
*/
public final class HSSFChart {
private ChartRecord chartRecord;
-
+
private LegendRecord legendRecord;
private ChartTitleFormatRecord chartTitleFormat;
private SeriesTextRecord chartTitleText;
-
+
private List series = new ArrayList();
-
+
private HSSFChart(ChartRecord chartRecord) {
this.chartRecord = chartRecord;
}
sheet.insertChartRecords( records );
workbook.insertChartRecord();
}
-
+
/**
* Returns all the charts for the given sheet.
- *
+ *
* NOTE: You won't be able to do very much with
* these charts yet, as this is very limited support
*/
public static HSSFChart[] getSheetCharts(HSSFSheet sheet) {
List charts = new ArrayList();
HSSFChart lastChart = null;
-
+
// Find records of interest
List records = sheet.getSheet().getRecords();
for(Iterator it = records.iterator(); it.hasNext();) {
RecordBase r = (RecordBase)it.next();
-
+
if(r instanceof ChartRecord) {
lastChart = new HSSFChart((ChartRecord)r);
charts.add(lastChart);
}
}
}
-
+
return (HSSFChart[])
charts.toArray( new HSSFChart[charts.size()] );
}
public void setChartWidth(int width) { chartRecord.setWidth(width); }
/** Sets the height of the chart. {@link ChartRecord} */
public void setChartHeight(int height) { chartRecord.setHeight(height); }
-
+
/**
* Returns the series of the chart
*/
return (HSSFSeries[])
series.toArray(new HSSFSeries[series.size()]);
}
-
+
/**
* Returns the chart's title, if there is one,
* or null if not
}
return null;
}
-
+
/**
- * Changes the chart's title, but only if there
+ * Changes the chart's title, but only if there
* was one already.
* TODO - add in the records if not
*/
return r;
}
-
+
/**
* A series in a chart
*/
public class HSSFSeries {
private SeriesRecord series;
private SeriesTextRecord seriesTitleText;
-
+
/* package */ HSSFSeries(SeriesRecord series) {
this.series = series;
}
-
+
public short getNumValues() {
return series.getNumValues();
}
public short getValueType() {
return series.getValuesDataType();
}
-
+
/**
* Returns the series' title, if there is one,
* or null if not
}
return null;
}
-
+
/**
- * Changes the series' title, but only if there
+ * Changes the series' title, but only if there
* was one already.
* TODO - add in the records if not
*/
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf;
import java.io.InputStream;
*
* @author Ryan Ackley
*/
-public class HWPFDocument extends POIDocument
+public final class HWPFDocument extends POIDocument
// implements Cloneable
{
/** The FIB */
/** Holds the save history for this document. */
protected SavedByTable _sbt;
-
+
/** Holds pictures table */
protected PicturesTable _pictures;
-
+
/** Holds FSBA (shape) information */
protected FSPATable _fspa;
-
+
/** Escher Drawing Group information */
protected EscherRecordHolder _dgg;
//do Ole stuff
this( verifyAndBuildPOIFS(istream) );
}
-
+
/**
* This constructor loads a Word document from a POIFSFileSystem
*
{
this(pfilesystem.getRoot(), pfilesystem);
}
-
+
/**
* This constructor loads a Word document from a specific point
* in a POIFSFileSystem, probably not the default.
// Sort out the hpsf properties
super(directory, pfilesystem);
readProperties();
-
+
// read in the main stream.
DocumentEntry documentProps = (DocumentEntry)
directory.getEntry("WordDocument");
_mainStream = new byte[documentProps.getSize()];
-
+
directory.createDocumentInputStream("WordDocument").read(_mainStream);
// Create our FIB, and check for the doc being encrypted
// Get the cp of the start of text in the main stream
// The latest spec doc says this is always zero!
int fcMin = 0;
- //fcMin = _fib.getFcMin()
+ //fcMin = _fib.getFcMin()
// Start to load up our standard structures.
_dop = new DocumentProperties(_tableStream, _fib.getFcDop());
_cft = new ComplexFileTable(_mainStream, _tableStream, _fib.getFcClx(), fcMin);
_tpt = _cft.getTextPieceTable();
-
+
// Word XP and later all put in a zero filled buffer in
// front of the text. This screws up the system for offsets,
// which assume we always start at zero. This is an adjustment.
int cpMin = _tpt.getCpMin();
-
+
// Now load the rest of the properties, which need to be adjusted
// for where text really begin
_cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), cpMin, _tpt);
_pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), cpMin, _tpt);
-
+
// Read FSPA and Escher information
_fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(), _fib.getLcbPlcspaMom(), getTextTable().getTextPieces());
-
+
if (_fib.getFcDggInfo() != 0)
{
_dgg = new EscherRecordHolder(_tableStream, _fib.getFcDggInfo(), _fib.getLcbDggInfo());
{
_dgg = new EscherRecordHolder();
}
-
+
// read in the pictures stream
_pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg);
// And the art shapes stream
{
return _dop;
}
-
+
/**
* Returns the range that covers all text in the
* file, including main text, footnotes, headers
// First up, trigger a full-recalculate
// Needed in case of deletes etc
getOverallRange();
-
+
// Now, return the real one
return new Range(
- _cpSplit.getMainDocumentStart(),
- _cpSplit.getMainDocumentEnd(),
+ _cpSplit.getMainDocumentStart(),
+ _cpSplit.getMainDocumentEnd(),
this
);
}
-
+
/**
* Returns the range which covers all the Footnotes.
*/
public Range getFootnoteRange() {
return new Range(
- _cpSplit.getFootnoteStart(),
- _cpSplit.getFootnoteEnd(),
+ _cpSplit.getFootnoteStart(),
+ _cpSplit.getFootnoteEnd(),
this
);
}
-
+
/**
* Returns the range which covers all "Header Stories".
* A header story contains a header, footer, end note
- * separators and footnote separators.
+ * separators and footnote separators.
*/
public Range getHeaderStoryRange() {
return new Range(
- _cpSplit.getHeaderStoryStart(),
- _cpSplit.getHeaderStoryEnd(),
+ _cpSplit.getHeaderStoryStart(),
+ _cpSplit.getHeaderStoryEnd(),
this
);
}
{
return _sbt;
}
-
+
/**
* @return PicturesTable object, that is able to extract images from this document
*/
public PicturesTable getPicturesTable() {
return _pictures;
}
-
+
/**
* @return ShapesTable object, that is able to extract office are shapes from this document
*/
pfs.createDocument(new ByteArrayInputStream(tableBuf), "1Table");
pfs.createDocument(new ByteArrayInputStream(dataBuf), "Data");
writeProperties(pfs);
-
+
pfs.writeFilesystem(out);
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import java.io.*;
import org.apache.poi.hwpf.usermodel.*;
-public class QuickTest
+public final class QuickTest
{
public QuickTest()
{
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.dev;
import java.io.FileInputStream;
* HWPF file. End users will probably never need to
* use this program.
*/
-public class HWPFLister {
+public final class HWPFLister {
private HWPFDocument doc;
public HWPFLister(HWPFDocument doc) {
this.doc = doc;
}
-
+
public static void main(String[] args) throws Exception {
if(args.length == 0) {
System.err.println("Use:");
System.err.println(" HWPFLister <filename>");
System.exit(1);
}
-
+
HWPFLister l = new HWPFLister(
new HWPFDocument(new FileInputStream(args[0]))
);
l.dumpFIB();
}
-
+
public void dumpFIB() throws Exception {
FileInformationBlock fib = doc.getFileInformationBlock();
System.out.println(fib.toString());
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.extractor;
import java.io.IOException;
/**
* Class to extract the text from a Word Document.
- *
+ *
* You should use either getParagraphText() or getText() unless
* you have a strong reason otherwise.
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class WordExtractor extends POIOLE2TextExtractor {
+public final class WordExtractor extends POIOLE2TextExtractor {
private POIFSFileSystem fs;
private HWPFDocument doc;
-
+
/**
* Create a new Word Extractor
* @param is InputStream containing the word file
this(new HWPFDocument(dir, fs));
this.fs = fs;
}
-
+
/**
* Create a new Word Extractor
* @param doc The HWPFDocument to extract from
WordExtractor extractor = new WordExtractor(fin);
System.out.println(extractor.getText());
}
-
+
/**
* Get the text from the word file, as an array with one String
* per paragraph
*/
public String[] getParagraphText() {
String[] ret;
-
+
// Extract using the model code
try {
Range r = doc.getRange();
for(int i=0; i<ret.length; i++) {
Paragraph p = r.getParagraph(i);
ret[i] = p.text();
-
+
// Fix the line ending
if(ret[i].endsWith("\r")) {
ret[i] = ret[i] + "\n";
ret = new String[1];
ret[0] = getTextFromPieces();
}
-
+
return ret;
}
-
+
/**
* Add the header/footer text, if it's not empty
*/
*/
public String getHeaderText() {
HeaderStories hs = new HeaderStories(doc);
-
+
StringBuffer ret = new StringBuffer();
if(hs.getFirstHeader() != null) {
appendHeaderFooter(hs.getFirstHeader(), ret);
if(hs.getOddHeader() != null) {
appendHeaderFooter(hs.getOddHeader(), ret);
}
-
+
return ret.toString();
}
/**
*/
public String getFooterText() {
HeaderStories hs = new HeaderStories(doc);
-
+
StringBuffer ret = new StringBuffer();
if(hs.getFirstFooter() != null) {
appendHeaderFooter(hs.getFirstFooter(), ret);
if(hs.getOddFooter() != null) {
appendHeaderFooter(hs.getOddFooter(), ret);
}
-
+
return ret.toString();
}
-
+
/**
* Grab the text out of the text pieces. Might also include various
* bits of crud, but will work in cases where the text piece -> paragraph
*/
public String getTextFromPieces() {
StringBuffer textBuf = new StringBuffer();
-
+
Iterator textPieces = doc.getTextTable().getTextPieces().iterator();
while (textPieces.hasNext()) {
TextPiece piece = (TextPiece) textPieces.next();
throw new InternalError("Standard Encoding " + encoding + " not found, JVM broken");
}
}
-
+
String text = textBuf.toString();
-
+
// Fix line endings (Note - won't get all of them
text = text.replaceAll("\r\r\r", "\r\n\r\n\r\n");
text = text.replaceAll("\r\r", "\r\n\r\n");
-
+
if(text.endsWith("\r")) {
text += "\n";
}
-
+
return text;
}
-
+
/**
* Grab the text, based on the paragraphs. Shouldn't include any crud,
* but slightly slower than getTextFromPieces().
*/
public String getText() {
StringBuffer ret = new StringBuffer();
-
+
ret.append(getHeaderText());
-
+
String[] text = getParagraphText();
for(int i=0; i<text.length; i++) {
ret.append(text[i]);
}
-
+
ret.append(getFooterText());
-
+
return ret.toString();
}
-
+
/**
* Removes any fields (eg macros, page markers etc)
* from the string.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.model;
/**
*/
public abstract class BytePropertyNode extends PropertyNode {
private boolean isUnicode;
-
+
/**
* @param fcStart The start of the text for this property, in _bytes_
* @param fcEnd The end of the text for this property, in _bytes_
return val/2;
return val;
}
-
+
public boolean isUnicode() {
return isUnicode;
}
*
* @author Ryan Ackley
*/
-public class CHPBinTable
+public final class CHPBinTable
{
/** List of character properties.*/
protected ArrayList _textRuns = new ArrayList();
public void insert(int listIndex, int cpStart, SprmBuffer buf)
{
boolean needsToBeUnicode = tpt.isUnicodeAtCharOffset(cpStart);
-
+
CHPX insertChpx = new CHPX(0, 0, buf, needsToBeUnicode);
-
+
// Ensure character offsets are really characters
insertChpx.setStart(cpStart);
insertChpx.setEnd(cpStart);
-
+
if (listIndex == _textRuns.size())
{
_textRuns.add(insertChpx);
// Again ensure contains character based offsets no matter what
clone.setStart(cpStart);
clone.setEnd(chpx.getEnd());
-
+
chpx.setEnd(cpStart);
_textRuns.add(listIndex + 1, insertChpx);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.util.List;
*
* @author Ryan Ackley
*/
-public class CHPFormattedDiskPage extends FormattedDiskPage
+public final class CHPFormattedDiskPage extends FormattedDiskPage
{
private static final int FC_SIZE = 4;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
/**
* DANGER - works in bytes!
- *
+ *
* Make sure you call getStart() / getEnd() when you want characters
- * (normal use), but getStartByte() / getEndByte() when you're
+ * (normal use), but getStartByte() / getEndByte() when you're
* reading in / writing out!
*
* @author Ryan Ackley
*/
-public class CHPX extends BytePropertyNode
+public final class CHPX extends BytePropertyNode
{
public CHPX(int fcStart, int fcEnd, byte[] grpprl, boolean isUnicode)
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.HWPFDocument;
* where different kinds of text can be found within the
* overall CP splurge.
*/
-public class CPSplitCalculator {
+public final class CPSplitCalculator {
private FileInformationBlock fib;
public CPSplitCalculator(FileInformationBlock fib) {
this.fib = fib;
}
-
+
/**
* Where the main document text starts. Always 0.
*/
return 0;
}
/**
- * Where the main document text ends.
+ * Where the main document text ends.
* Given by FibRgLw97.ccpText
*/
public int getMainDocumentEnd() {
return fib.getCcpText();
}
-
+
/**
* Where the Footnotes text starts.
* Follows straight on from the main text.
return getFootnoteStart() +
fib.getCcpFtn();
}
-
+
/**
* Where the "Header Story" text starts.
* Follows straight on from the footnotes.
return getHeaderStoryStart() +
fib.getCcpHdd();
}
-
+
/**
* Where the Comment (Atn) text starts.
* Follows straight on from the header stories.
return getCommentsStart() +
fib.getCcpCommentAtn();
}
-
+
/**
* Where the End Note text starts.
* Follows straight on from the comments.
return getEndNoteStart() +
fib.getCcpEdn();
}
-
+
/**
* Where the Main Textbox text starts.
* Follows straight on from the end note.
return getMainTextboxStart() +
fib.getCcpTxtBx();
}
-
+
/**
* Where the Header Textbox text starts.
* Follows straight on from the main textbox.
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import java.lang.ref.SoftReference;
-public class CachedPropertyNode
+public final class CachedPropertyNode
extends PropertyNode
{
protected SoftReference _propCache;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
-public class ComplexFileTable
+public final class ComplexFileTable
{
private static final byte GRPPRL_TYPE = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
* @author Ryan Ackley
*/
-public class DocumentProperties extends DOPAbstractType
+public final class DocumentProperties extends DOPAbstractType
{
/**
* Based on AbstractEscherRecordHolder from HSSF.
- *
+ *
* @author Squeeself
*/
public final class EscherRecordHolder {
private final ArrayList<EscherRecord> escherRecords;
-
+
public EscherRecordHolder() {
escherRecords = new ArrayList<EscherRecord>();
}
-
+
public EscherRecordHolder(byte[] data, int offset, int size) {
this();
fillEscherRecords(data, offset, size);
}
-
+
private void fillEscherRecords(byte[] data, int offset, int size)
{
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
pos += bytesRead + 1; // There is an empty byte between each top-level record in a Word doc
}
}
-
+
public List<EscherRecord> getEscherRecords() {
return escherRecords;
}
-
+
public String toString() {
StringBuffer buffer = new StringBuffer();
}
return buffer.toString();
}
-
+
/**
* If we have a EscherContainerRecord as one of our
* children (and most top level escher holders do),
return r;
}
}
-
+
// Then check our children in turn
for(Iterator<EscherRecord> it = records.iterator(); it.hasNext();) {
EscherRecord r = it.next();
}
}
}
-
+
// Not found in this lot
return null;
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.util.HashSet;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-public class FIBFieldHandler
+public final class FIBFieldHandler
{
public static final int STSHFORIG = 0;
public static final int STSHF = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.io.IOException;
* Handles the fibRgLw / The FibRgLw97 part of
* the FIB (File Information Block)
*/
-public class FIBLongHandler {
+public final class FIBLongHandler {
public static final int CBMAC = 0;
public static final int PRODUCTCREATED = 1;
public static final int PRODUCTREVISED = 2;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
/**
- * Handles the fibRgW / FibRgW97 part of
+ * Handles the fibRgW / FibRgW97 part of
* the FIB (File Information Block)
*/
-public class FIBShortHandler {
+public final class FIBShortHandler {
public final static int MAGICCREATED = 0;
public final static int MAGICREVISED = 1;
public final static int MAGICCREATEDPRIVATE = 2;
/**
* File Shape Address structure
- *
+ *
* @author Squeeself
*/
-public class FSPA
+public final class FSPA
{
public static final int FSPA_SIZE = 26;
private int spid; // Shape identifier. Used to get data position
private static BitField fBelowText = BitFieldFactory.getInstance(0x4000); // if true, shape is below text, otherwise above
private static BitField fAnchorLock = BitFieldFactory.getInstance(0x8000); // if true, anchor is locked
private int cTxbx; // Count of textboxes in shape (undo doc only)
-
+
public FSPA()
{
}
-
+
public FSPA(byte[] bytes, int offset)
{
spid = LittleEndian.getInt(bytes, offset);
offset += LittleEndian.SHORT_SIZE;
cTxbx = LittleEndian.getInt(bytes, offset);
}
-
+
public int getSpid()
{
return spid;
}
-
+
public int getXaLeft()
{
return xaLeft;
}
-
+
public int getYaTop()
{
return yaTop;
}
-
+
public int getXaRight()
{
return xaRight;
}
-
+
public int getYaBottom()
{
return yaBottom;
}
-
+
public boolean isFHdr()
{
return fHdr.isSet(options);
}
-
+
public short getBx()
{
return bx.getShortValue(options);
}
-
+
public short getBy()
{
return by.getShortValue(options);
}
-
+
public short getWr()
{
return wr.getShortValue(options);
}
-
+
public short getWrk()
{
return wrk.getShortValue(options);
}
-
+
public boolean isFRcaSimple()
{
return fRcaSimple.isSet(options);
}
-
+
public boolean isFBelowText()
{
return fBelowText.isSet(options);
}
-
+
public boolean isFAnchorLock()
{
return fAnchorLock.isSet(options);
}
-
+
public int getCTxbx()
{
return cTxbx;
}
-
+
public byte[] toByteArray()
{
int offset = 0;
return buf;
}
-
+
public String toString()
{
StringBuffer buf = new StringBuffer();
/**
* This class holds all the FSPA (File Shape Address) structures.
- *
+ *
* @author Squeeself
*/
-public final class FSPATable
+public final class FSPATable
{
private final List _shapes = new ArrayList();
private final Map _shapeIndexesByPropertyStart = new HashMap();
private final List _text;
-
+
public FSPATable(byte[] tableStream, int fcPlcspa, int lcbPlcspa, List tpt)
{
_text = tpt;
// Will be 0 if no drawing objects in document
if (fcPlcspa == 0)
return;
-
+
PlexOfCps plex = new PlexOfCps(tableStream, fcPlcspa, lcbPlcspa, FSPA.FSPA_SIZE);
for (int i=0; i < plex.length(); i++)
{
GenericPropertyNode property = plex.getProperty(i);
FSPA fspa = new FSPA(property.getBytes(), 0);
-
+
_shapes.add(fspa);
_shapeIndexesByPropertyStart.put(new Integer(property.getStart()), new Integer(i));
}
}
-
+
public FSPA getFspaFromCp(int cp)
{
Integer idx = (Integer)_shapeIndexesByPropertyStart.get(new Integer(cp));
}
return (FSPA)_shapes.get(idx.intValue());
}
-
+
public FSPA[] getShapes()
{
FSPA[] result = new FSPA[_shapes.size()];
_shapes.toArray(result);
return result;
}
-
+
public String toString()
{
StringBuffer buf = new StringBuffer();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
*
* @author Praveen Mathew
*/
-public class Ffn
+public final class Ffn
{
private int _cbFfnM1;//total length of FFN - 1.
private byte _info;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
-public class FieldDescriptor
+public final class FieldDescriptor
{
byte _fieldBoundaryType;
byte _info;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
* The File Information Block (FIB). Holds pointers
* to various bits of the file, and lots of flags which
* specify properties of the document.
- *
+ *
* The parent class, {@link FIBAbstractType}, holds the
* first 32 bytes, which make up the FibBase.
* The next part, the fibRgW / FibRgW97, is handled
* handled by the {@link FIBLongHandler}.
* Finally, the rest of the fields are handled by
* the {@link FIBFieldHandler}.
- *
+ *
* @author andy
*/
-public class FileInformationBlock extends FIBAbstractType
+public final class FileInformationBlock extends FIBAbstractType
implements Cloneable
{
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh);
}
-
-
+
+
/**
* How many bytes of the main stream contain real data.
*/
}
/**
* Updates the count of the number of bytes in the
- * main stream which contain real data
+ * main stream which contain real data
*/
public void setCbMac(int cbMac) {
_longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
_longHandler.setLong(FIBLongHandler.CCPHDRTXBX, ccpTxtBx);
}
-
+
public void clearOffsetsSizes()
{
_fieldHandler.clearFields();
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
}
-
+
public int getFcPlcspaMom()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCSPAMOM);
}
-
+
public int getLcbPlcspaMom()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLCSPAMOM);
}
-
+
public int getFcDggInfo()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.DGGINFO);
}
-
+
public int getLcbDggInfo()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.DGGINFO);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
*
* @author Praveen Mathew
*/
-public class FontTable
+public final class FontTable
{
private short _stringCount;// how many strings are included in the string table
private short _extraDataSz;// size in bytes of the extra data
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
-public class GenericPropertyNode
+public final class GenericPropertyNode
extends PropertyNode
{
public GenericPropertyNode(int start, int end, byte[] buf)
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-/*
- * HDFType.java
- *
- * Created on February 24, 2002, 2:37 PM
- */
package org.apache.poi.hwpf.model;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.util.Arrays;
-public class ListData
+public final class ListData
{
private int _lsid;
private int _tplc;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.util.Arrays;
-public class ListFormatOverride
+public final class ListFormatOverride
{
int _lsid;
int _reserved1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.util.Arrays;
-public class ListFormatOverrideLevel
+public final class ListFormatOverrideLevel
{
private static final int BASE_SIZE = 8;
import org.apache.poi.util.LittleEndian;
/**
- *
+ *
*/
public final class ListLevel
{
_rgbxchNums = new byte[RGBXCH_NUMS_SIZE];
System.arraycopy(buf, offset, _rgbxchNums, 0, RGBXCH_NUMS_SIZE);
offset += RGBXCH_NUMS_SIZE;
-
+
_ixchFollow = buf[offset++];
_dxaSpace = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
System.arraycopy(buf, offset, _grpprlChpx, 0, _cbGrpprlChpx);
offset += _cbGrpprlChpx;
- int numberTextLength = LittleEndian.getShort(buf, offset);
+ int numberTextLength = LittleEndian.getShort(buf, offset);
/* sometimes numberTextLength<0 */
/* by derjohng */
if (numberTextLength>0)
6 // int byte byte
+ RGBXCH_NUMS_SIZE
+ 13 // byte int int byte byte short
- + _cbGrpprlChpx
+ + _cbGrpprlChpx
+ _cbGrpprlPapx
+ 2; // numberText length
if (_numberText != null) {
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
/**
* @author Ryan Ackley
*/
-public class ListTables
+public final class ListTables
{
private static final int LIST_DATA_SIZE = 28;
private static final int LIST_FORMAT_OVERRIDE_SIZE = 16;
ListLevel lvl = lst.getLevels()[level];
return lvl;
} else {
- log.log(POILogger.WARN, "Requested level " + level + " which was greater than the maximum defined (" + lst.numLevels() + ")");
+ log.log(POILogger.WARN, "Requested level " + level + " which was greater than the maximum defined (" + lst.numLevels() + ")");
return null;
}
}
*
* @author Ryan Ackley
*/
-public class PAPBinTable
+public final class PAPBinTable
{
protected ArrayList _paragraphs = new ArrayList();
byte[] _dataStream;
public void insert(int listIndex, int cpStart, SprmBuffer buf)
{
boolean needsToBeUnicode = tpt.isUnicodeAtCharOffset(cpStart);
-
+
PAPX forInsert = new PAPX(0, 0, buf, _dataStream, needsToBeUnicode);
-
+
// Ensure character offsets are really characters
forInsert.setStart(cpStart);
forInsert.setEnd(cpStart);
-
+
if (listIndex == _paragraphs.size())
{
_paragraphs.add(forInsert);
{
exc.printStackTrace();
}
-
+
// Copy the properties of the one before to afterwards
// Will go:
// Original, until insert at point
// Again ensure contains character based offsets no matter what
clone.setStart(cpStart);
clone.setEnd(currentPap.getEnd());
-
+
currentPap.setEnd(cpStart);
_paragraphs.add(listIndex + 1, forInsert);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import org.apache.poi.poifs.common.POIFSConstants;
*
* @author Ryan Ackley
*/
-public class PAPFormattedDiskPage extends FormattedDiskPage
+public final class PAPFormattedDiskPage extends FormattedDiskPage
{
private static final int BX_SIZE = 13;
int endAt = getEnd(x) - fcMin;
boolean isUnicode = tpt.isUnicodeAtByteOffset(startAt);
//System.err.println(startAt + " -> " + endAt + " = " + isUnicode);
-
+
_papxList.add(new PAPX(startAt, endAt, getGrpprl(x), getParagraphHeight(x), dataStream, isUnicode));
}
_fkp = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
/**
* DANGER - works in bytes!
- *
+ *
* Make sure you call getStart() / getEnd() when you want characters
- * (normal use), but getStartByte() / getEndByte() when you're
+ * (normal use), but getStartByte() / getEndByte() when you're
* reading in / writing out!
*
* @author Ryan Ackley
*/
-public class PAPX extends BytePropertyNode {
+public final class PAPX extends BytePropertyNode {
private ParagraphHeight _phe;
private int _hugeGrpprlOffset = -1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
-public class ParagraphHeight
+public final class ParagraphHeight
{
private short infoField;
private BitField fSpare = BitFieldFactory.getInstance(0x0001);
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
*
* @author Dmitry Romanov
*/
-public class PicturesTable
+public final class PicturesTable
{
static final int TYPE_IMAGE = 0x08;
static final int TYPE_IMAGE_WORD2000 = 0x00;
/**
*
- * @param _document
+ * @param _document
* @param _dataStream
*/
public PicturesTable(HWPFDocument _document, byte[] _dataStream, byte[] _mainStream, FSPATable fspa, EscherRecordHolder dgg)
}
return false;
}
-
+
public boolean hasEscherPicture(CharacterRun run) {
if (run.isSpecialCharacter() && !run.isObj() && !run.isOle2() && !run.isData() && run.text().startsWith("\u0008")) {
return true;
* to have that byte array in memory but only write picture's contents to stream, pass false and then use Picture.writeImageContent
* @see Picture#writeImageContent(java.io.OutputStream)
* @return a Picture object if picture exists for specified CharacterRun, null otherwise. PicturesTable.hasPicture is used to determine this.
- * @see #hasPicture(org.apache.poi.hwpf.usermodel.CharacterRun)
+ * @see #hasPicture(org.apache.poi.hwpf.usermodel.CharacterRun)
*/
public Picture extractPicture(CharacterRun run, boolean fillBytes) {
if (hasPicture(run)) {
}
return null;
}
-
+
/**
* Performs a recursive search for pictures in the given list of escher records.
*
/**
* Not all documents have all the images concatenated in the data stream
* although MS claims so. The best approach is to scan all character runs.
- *
+ *
* @return a list of Picture objects found in current document
*/
public List getAllPictures() {
ArrayList pictures = new ArrayList();
-
+
Range range = _document.getRange();
for (int i = 0; i < range.numCharacterRuns(); i++) {
CharacterRun run = range.getCharacterRun(i);
pictures.add(picture);
}
}
-
+
searchForPictures(_dgg.getEscherRecords(), pictures);
return pictures;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
-public class PieceDescriptor
+public final class PieceDescriptor
{
short descriptor;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.util.ArrayList;
*
* @author Ryan Ackley
*/
-public class PlexOfCps
+public final class PlexOfCps
{
private int _count;
private int _offset;
{
// Figure out the number we hold
_count = (size - 4)/(4 + sizeOfStruct);
-
+
_sizeOfStruct = sizeOfStruct;
_props = new ArrayList(_count);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.util.Arrays;
_cpStart = fcStart;
_cpEnd = fcEnd;
_buf = buf;
-
+
if(_cpStart < 0) {
System.err.println("A property claimed to start before zero, at " + _cpStart + "! Resetting it to zero, and hoping for the best");
_cpStart = 0;
if (_cpEnd > start) {
// The start of the change is before we end
-
+
if (_cpStart < end) {
// The delete was somewhere in the middle of us
_cpEnd = end >= _cpEnd ? start : _cpEnd - length;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
/**
*/
-public class SEPX extends BytePropertyNode
+public final class SEPX extends BytePropertyNode
{
SectionDescriptor _sed;
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
/**
* A single entry in the {@link SavedByTable}.
- *
+ *
* @author Daniel Noll
*/
-public class SavedByEntry
+public final class SavedByEntry
{
private String userName;
private String saveLocation;
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.io.IOException;
/**
* String table containing the history of the last few revisions ("saves") of the document.
* Read-only for the time being.
- *
+ *
* @author Daniel Noll
*/
-public class SavedByTable
+public final class SavedByTable
{
/**
* A value that I don't know what it does, but is maintained for accuracy.
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
-public class SectionDescriptor
+public final class SectionDescriptor
{
private short fn;
/**
* @author Ryan Ackley
*/
-public class SectionTable
+public final class SectionTable
{
private static final int SED_SIZE = 12;
int fileOffset = sed.getFc();
int startAt = CPtoFC(node.getStart());
int endAt = CPtoFC(node.getEnd());
-
+
boolean isUnicodeAtStart = tpt.isUnicodeAtByteOffset( startAt );
// System.err.println(startAt + " -> " + endAt + " = " + isUnicodeAtStart);
_sections.add(new SEPX(sed, startAt, endAt, buf, isUnicodeAtStart));
}
}
-
+
// Some files seem to lie about their unicode status, which
// is very very pesky. Try to work around these, but this
// is getting on for black magic...
for(int i=0; i<_sections.size(); i++) {
SEPX s = (SEPX)_sections.get(i);
GenericPropertyNode node = sedPlex.getProperty(i);
-
+
s.setStart( CPtoFC(node.getStart()) );
s.setEnd( CPtoFC(node.getEnd()) );
}
import org.apache.poi.hwpf.usermodel.Shape;
-public class ShapesTable {
+public final class ShapesTable {
private List _shapes;
private List _shapesVisibili; //holds visible shapes
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
* @author Ryan Ackley
*/
-public class StyleDescription implements HDFType
+public final class StyleDescription implements HDFType
{
private final static int PARAGRAPH_STYLE = 1;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model;
* @author Ryan Ackley
*/
-public class StyleSheet implements HDFType
+public final class StyleSheet implements HDFType
{
public static final int NIL_STYLE = 4095;
{
parentPAP = _styleDescriptions[baseIndex].getPAP();
- if(parentPAP == null)
+ if(parentPAP == null)
{
if(baseIndex == istd) {
// Oh dear, style claims that it is its own parent
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
* @author Ryan Ackley
*/
-public class TextPiece extends PropertyNode implements Comparable
+public final class TextPiece extends PropertyNode implements Comparable
{
private boolean _usesUnicode;
super(start, end, buildInitSB(text, pd));
_usesUnicode = pd.isUnicode();
_pd = pd;
-
+
// Validate
int textLength = ((StringBuffer)_buf).length();
if(end-start != textLength) {
throw new IllegalStateException("Told we're of negative size! start="+start + " end="+end);
}
}
-
+
/**
* Create the StringBuffer from the text and unicode flag
*/
}
return new StringBuffer(str);
}
-
+
/**
* @return If this text piece is unicode
*/
}
/**
- * Returns part of the string.
+ * Returns part of the string.
* Works only in characters, not in bytes!
* @param start Local start position, in characters
* @param end Local end position, in characters
public String substring(int start, int end)
{
StringBuffer buf = (StringBuffer)_buf;
-
+
// Validate
if(start < 0) {
throw new StringIndexOutOfBoundsException("Can't request a substring before 0 - asked for " + start);
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
* convertion.
* @author Ryan Ackley
*/
-public class TextPieceTable
+public final class TextPieceTable
{
protected ArrayList _textPieces = new ArrayList();
//int _multiple;
pieces[x] = new PieceDescriptor(node.getBytes(), 0);
}
-
+
// Figure out the cp of the earliest text piece
// Note that text pieces don't have to be stored in order!
_cpMin = pieces[0].getFilePosition() - fcMin;
{
int start = pieces[x].getFilePosition();
PropertyNode node = pieceTable.getProperty(x);
-
+
// Grab the start and end, which are in characters
int nodeStartChars = node.getStart();
int nodeEndChars = node.getEnd();
-
+
// What's the relationship between bytes and characters?
boolean unicode = pieces[x].isUnicode();
int multiple = 1;
if (unicode) {
multiple = 2;
}
-
+
// Figure out the length, in bytes and chars
int textSizeChars = (nodeEndChars - nodeStartChars);
int textSizeBytes = textSizeChars * multiple;
// And now build the piece
_textPieces.add(new TextPiece(nodeStartChars, nodeEndChars, buf, pieces[x], node.getStart()));
}
-
+
// In the interest of our sanity, now sort the text pieces
// into order, if they're not already
TextPiece[] tp = (TextPiece[])
{
return _textPieces;
}
-
+
/**
* Is the text at the given Character offset
* unicode, or plain old ascii?
- * In a very evil fashion, you have to actually
+ * In a very evil fashion, you have to actually
* know this to make sense of character and
* paragraph properties :(
* @param cp The character offset to check about
*/
public boolean isUnicodeAtCharOffset(int cp) {
boolean lastWas = false;
-
+
Iterator it = _textPieces.iterator();
while(it.hasNext()) {
TextPiece tp = (TextPiece)it.next();
// Otherwise keep track for the last one
lastWas = tp.isUnicode();
}
-
+
// If they ask off the end, just go with the last one...
return lastWas;
}
/**
* Is the text at the given byte offset
* unicode, or plain old ascii?
- * In a very evil fashion, you have to actually
+ * In a very evil fashion, you have to actually
* know this to make sense of character and
* paragraph properties :(
* @param bytePos The character offset to check about
public boolean isUnicodeAtByteOffset(int bytePos) {
boolean lastWas = false;
int curByte = 0;
-
+
Iterator it = _textPieces.iterator();
while(it.hasNext()) {
TextPiece tp = (TextPiece)it.next();
int nextByte = curByte + tp.bytesLength();
-
+
// If the text piece covers the character, all good
if(curByte <= bytePos && nextByte >= bytePos) {
return tp.isUnicode();
// Move along
curByte = nextByte;
}
-
+
// If they ask off the end, just go with the last one...
return lastWas;
}
int size = _textPieces.size();
TextPiece tp = (TextPiece)_textPieces.get(listIndex);
-
+
// Update with the new end
tp.setEnd(tp.getEnd() + length);
-
+
// Now change all subsequent ones
for (int x = listIndex + 1; x < size; x++)
{
tp.setStart(tp.getStart() + length);
tp.setEnd(tp.getEnd() + length);
}
-
+
// All done
return length;
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.util.Arrays;
-public class UPX
+public final class UPX
{
private byte[] _upx;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
-public class UnhandledDataStructure
+public final class UnhandledDataStructure
{
byte[] _buf;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model.io;
import java.util.HashMap;
-public class HWPFFileSystem
+public final class HWPFFileSystem
{
HashMap _streams = new HashMap();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model.io;
import java.io.ByteArrayOutputStream;
-public class HWPFOutputStream extends ByteArrayOutputStream
+public final class HWPFOutputStream extends ByteArrayOutputStream
{
int _offset;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
/**
* Sets the fBold field value.
- *
+ *
*/
public void setFBold(boolean value)
{
field_2_format_flags = (int)fBold.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fBold field value.
*/
public boolean isFBold()
{
return fBold.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fItalic field value.
- *
+ *
*/
public void setFItalic(boolean value)
{
field_2_format_flags = (int)fItalic.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fItalic field value.
*/
public boolean isFItalic()
{
return fItalic.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fRMarkDel field value.
- *
+ *
*/
public void setFRMarkDel(boolean value)
{
field_2_format_flags = (int)fRMarkDel.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fRMarkDel field value.
*/
public boolean isFRMarkDel()
{
return fRMarkDel.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fOutline field value.
- *
+ *
*/
public void setFOutline(boolean value)
{
field_2_format_flags = (int)fOutline.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fOutline field value.
*/
public boolean isFOutline()
{
return fOutline.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fFldVanish field value.
- *
+ *
*/
public void setFFldVanish(boolean value)
{
field_2_format_flags = (int)fFldVanish.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fFldVanish field value.
*/
public boolean isFFldVanish()
{
return fFldVanish.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fSmallCaps field value.
- *
+ *
*/
public void setFSmallCaps(boolean value)
{
field_2_format_flags = (int)fSmallCaps.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fSmallCaps field value.
*/
public boolean isFSmallCaps()
{
return fSmallCaps.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fCaps field value.
- *
+ *
*/
public void setFCaps(boolean value)
{
field_2_format_flags = (int)fCaps.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fCaps field value.
*/
public boolean isFCaps()
{
return fCaps.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fVanish field value.
- *
+ *
*/
public void setFVanish(boolean value)
{
field_2_format_flags = (int)fVanish.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fVanish field value.
*/
public boolean isFVanish()
{
return fVanish.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fRMark field value.
- *
+ *
*/
public void setFRMark(boolean value)
{
field_2_format_flags = (int)fRMark.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fRMark field value.
*/
public boolean isFRMark()
{
return fRMark.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fSpec field value.
- *
+ *
*/
public void setFSpec(boolean value)
{
field_2_format_flags = (int)fSpec.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fSpec field value.
*/
public boolean isFSpec()
{
return fSpec.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fStrike field value.
- *
+ *
*/
public void setFStrike(boolean value)
{
field_2_format_flags = (int)fStrike.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fStrike field value.
*/
public boolean isFStrike()
{
return fStrike.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fObj field value.
- *
+ *
*/
public void setFObj(boolean value)
{
field_2_format_flags = (int)fObj.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fObj field value.
*/
public boolean isFObj()
{
return fObj.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fShadow field value.
- *
+ *
*/
public void setFShadow(boolean value)
{
field_2_format_flags = (int)fShadow.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fShadow field value.
*/
public boolean isFShadow()
{
return fShadow.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fLowerCase field value.
- *
+ *
*/
public void setFLowerCase(boolean value)
{
field_2_format_flags = (int)fLowerCase.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fLowerCase field value.
*/
public boolean isFLowerCase()
{
return fLowerCase.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fData field value.
- *
+ *
*/
public void setFData(boolean value)
{
field_2_format_flags = (int)fData.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fData field value.
*/
public boolean isFData()
{
return fData.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fOle2 field value.
- *
+ *
*/
public void setFOle2(boolean value)
{
field_2_format_flags = (int)fOle2.setBoolean(field_2_format_flags, value);
-
+
}
/**
- *
+ *
* @return the fOle2 field value.
*/
public boolean isFOle2()
{
return fOle2.isSet(field_2_format_flags);
-
+
}
/**
* Sets the fEmboss field value.
- *
+ *
*/
public void setFEmboss(boolean value)
{
field_3_format_flags1 = (int)fEmboss.setBoolean(field_3_format_flags1, value);
-
+
}
/**
- *
+ *
* @return the fEmboss field value.
*/
public boolean isFEmboss()
{
return fEmboss.isSet(field_3_format_flags1);
-
+
}
/**
* Sets the fImprint field value.
- *
+ *
*/
public void setFImprint(boolean value)
{
field_3_format_flags1 = (int)fImprint.setBoolean(field_3_format_flags1, value);
-
+
}
/**
- *
+ *
* @return the fImprint field value.
*/
public boolean isFImprint()
{
return fImprint.isSet(field_3_format_flags1);
-
+
}
/**
* Sets the fDStrike field value.
- *
+ *
*/
public void setFDStrike(boolean value)
{
field_3_format_flags1 = (int)fDStrike.setBoolean(field_3_format_flags1, value);
-
+
}
/**
- *
+ *
* @return the fDStrike field value.
*/
public boolean isFDStrike()
{
return fDStrike.isSet(field_3_format_flags1);
-
+
}
/**
* Sets the fUsePgsuSettings field value.
- *
+ *
*/
public void setFUsePgsuSettings(boolean value)
{
field_3_format_flags1 = (int)fUsePgsuSettings.setBoolean(field_3_format_flags1, value);
-
+
}
/**
- *
+ *
* @return the fUsePgsuSettings field value.
*/
public boolean isFUsePgsuSettings()
{
return fUsePgsuSettings.isSet(field_3_format_flags1);
-
+
}
/**
* Sets the icoHighlight field value.
- *
+ *
*/
public void setIcoHighlight(byte value)
{
field_33_Highlight = (short)icoHighlight.setValue(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the icoHighlight field value.
*/
public byte getIcoHighlight()
{
return ( byte )icoHighlight.getValue(field_33_Highlight);
-
+
}
/**
* Sets the fHighlight field value.
- *
+ *
*/
public void setFHighlight(boolean value)
{
field_33_Highlight = (short)fHighlight.setBoolean(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the fHighlight field value.
*/
public boolean isFHighlight()
{
return fHighlight.isSet(field_33_Highlight);
-
+
}
/**
* Sets the kcd field value.
- *
+ *
*/
public void setKcd(byte value)
{
field_33_Highlight = (short)kcd.setValue(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the kcd field value.
*/
public byte getKcd()
{
return ( byte )kcd.getValue(field_33_Highlight);
-
+
}
/**
* Sets the fNavHighlight field value.
- *
+ *
*/
public void setFNavHighlight(boolean value)
{
field_33_Highlight = (short)fNavHighlight.setBoolean(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the fNavHighlight field value.
*/
public boolean isFNavHighlight()
{
return fNavHighlight.isSet(field_33_Highlight);
-
+
}
/**
* Sets the fChsDiff field value.
- *
+ *
*/
public void setFChsDiff(boolean value)
{
field_33_Highlight = (short)fChsDiff.setBoolean(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the fChsDiff field value.
*/
public boolean isFChsDiff()
{
return fChsDiff.isSet(field_33_Highlight);
-
+
}
/**
* Sets the fMacChs field value.
- *
+ *
*/
public void setFMacChs(boolean value)
{
field_33_Highlight = (short)fMacChs.setBoolean(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the fMacChs field value.
*/
public boolean isFMacChs()
{
return fMacChs.isSet(field_33_Highlight);
-
+
}
/**
* Sets the fFtcAsciSym field value.
- *
+ *
*/
public void setFFtcAsciSym(boolean value)
{
field_33_Highlight = (short)fFtcAsciSym.setBoolean(field_33_Highlight, value);
-
+
}
/**
- *
+ *
* @return the fFtcAsciSym field value.
*/
public boolean isFFtcAsciSym()
{
return fFtcAsciSym.isSet(field_33_Highlight);
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
/**
* Sets the fFacingPages field value.
- *
+ *
*/
public void setFFacingPages(boolean value)
{
field_1_formatFlags = (byte)fFacingPages.setBoolean(field_1_formatFlags, value);
-
+
}
/**
- *
+ *
* @return the fFacingPages field value.
*/
public boolean isFFacingPages()
{
return fFacingPages.isSet(field_1_formatFlags);
-
+
}
/**
* Sets the fWidowControl field value.
- *
+ *
*/
public void setFWidowControl(boolean value)
{
field_1_formatFlags = (byte)fWidowControl.setBoolean(field_1_formatFlags, value);
-
+
}
/**
- *
+ *
* @return the fWidowControl field value.
*/
public boolean isFWidowControl()
{
return fWidowControl.isSet(field_1_formatFlags);
-
+
}
/**
* Sets the fPMHMainDoc field value.
- *
+ *
*/
public void setFPMHMainDoc(boolean value)
{
field_1_formatFlags = (byte)fPMHMainDoc.setBoolean(field_1_formatFlags, value);
-
+
}
/**
- *
+ *
* @return the fPMHMainDoc field value.
*/
public boolean isFPMHMainDoc()
{
return fPMHMainDoc.isSet(field_1_formatFlags);
-
+
}
/**
* Sets the grfSupression field value.
- *
+ *
*/
public void setGrfSupression(byte value)
{
field_1_formatFlags = (byte)grfSupression.setValue(field_1_formatFlags, value);
-
+
}
/**
- *
+ *
* @return the grfSupression field value.
*/
public byte getGrfSupression()
{
return ( byte )grfSupression.getValue(field_1_formatFlags);
-
+
}
/**
* Sets the fpc field value.
- *
+ *
*/
public void setFpc(byte value)
{
field_1_formatFlags = (byte)fpc.setValue(field_1_formatFlags, value);
-
+
}
/**
- *
+ *
* @return the fpc field value.
*/
public byte getFpc()
{
return ( byte )fpc.getValue(field_1_formatFlags);
-
+
}
/**
* Sets the unused1 field value.
- *
+ *
*/
public void setUnused1(boolean value)
{
field_1_formatFlags = (byte)unused1.setBoolean(field_1_formatFlags, value);
-
+
}
/**
- *
+ *
* @return the unused1 field value.
*/
public boolean isUnused1()
{
return unused1.isSet(field_1_formatFlags);
-
+
}
/**
* Sets the rncFtn field value.
- *
+ *
*/
public void setRncFtn(byte value)
{
field_3_footnoteInfo = (short)rncFtn.setValue(field_3_footnoteInfo, value);
-
+
}
/**
- *
+ *
* @return the rncFtn field value.
*/
public byte getRncFtn()
{
return ( byte )rncFtn.getValue(field_3_footnoteInfo);
-
+
}
/**
* Sets the nFtn field value.
- *
+ *
*/
public void setNFtn(short value)
{
field_3_footnoteInfo = (short)nFtn.setValue(field_3_footnoteInfo, value);
-
+
}
/**
- *
+ *
* @return the nFtn field value.
*/
public short getNFtn()
{
return ( short )nFtn.getValue(field_3_footnoteInfo);
-
+
}
/**
* Sets the fOnlyMacPics field value.
- *
+ *
*/
public void setFOnlyMacPics(boolean value)
{
field_5_docinfo = (byte)fOnlyMacPics.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fOnlyMacPics field value.
*/
public boolean isFOnlyMacPics()
{
return fOnlyMacPics.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fOnlyWinPics field value.
- *
+ *
*/
public void setFOnlyWinPics(boolean value)
{
field_5_docinfo = (byte)fOnlyWinPics.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fOnlyWinPics field value.
*/
public boolean isFOnlyWinPics()
{
return fOnlyWinPics.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fLabelDoc field value.
- *
+ *
*/
public void setFLabelDoc(boolean value)
{
field_5_docinfo = (byte)fLabelDoc.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fLabelDoc field value.
*/
public boolean isFLabelDoc()
{
return fLabelDoc.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fHyphCapitals field value.
- *
+ *
*/
public void setFHyphCapitals(boolean value)
{
field_5_docinfo = (byte)fHyphCapitals.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fHyphCapitals field value.
*/
public boolean isFHyphCapitals()
{
return fHyphCapitals.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fAutoHyphen field value.
- *
+ *
*/
public void setFAutoHyphen(boolean value)
{
field_5_docinfo = (byte)fAutoHyphen.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fAutoHyphen field value.
*/
public boolean isFAutoHyphen()
{
return fAutoHyphen.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fFormNoFields field value.
- *
+ *
*/
public void setFFormNoFields(boolean value)
{
field_5_docinfo = (byte)fFormNoFields.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fFormNoFields field value.
*/
public boolean isFFormNoFields()
{
return fFormNoFields.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fLinkStyles field value.
- *
+ *
*/
public void setFLinkStyles(boolean value)
{
field_5_docinfo = (byte)fLinkStyles.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fLinkStyles field value.
*/
public boolean isFLinkStyles()
{
return fLinkStyles.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fRevMarking field value.
- *
+ *
*/
public void setFRevMarking(boolean value)
{
field_5_docinfo = (byte)fRevMarking.setBoolean(field_5_docinfo, value);
-
+
}
/**
- *
+ *
* @return the fRevMarking field value.
*/
public boolean isFRevMarking()
{
return fRevMarking.isSet(field_5_docinfo);
-
+
}
/**
* Sets the fBackup field value.
- *
+ *
*/
public void setFBackup(boolean value)
{
field_6_docinfo1 = (byte)fBackup.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fBackup field value.
*/
public boolean isFBackup()
{
return fBackup.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fExactCWords field value.
- *
+ *
*/
public void setFExactCWords(boolean value)
{
field_6_docinfo1 = (byte)fExactCWords.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fExactCWords field value.
*/
public boolean isFExactCWords()
{
return fExactCWords.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fPagHidden field value.
- *
+ *
*/
public void setFPagHidden(boolean value)
{
field_6_docinfo1 = (byte)fPagHidden.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fPagHidden field value.
*/
public boolean isFPagHidden()
{
return fPagHidden.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fPagResults field value.
- *
+ *
*/
public void setFPagResults(boolean value)
{
field_6_docinfo1 = (byte)fPagResults.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fPagResults field value.
*/
public boolean isFPagResults()
{
return fPagResults.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fLockAtn field value.
- *
+ *
*/
public void setFLockAtn(boolean value)
{
field_6_docinfo1 = (byte)fLockAtn.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fLockAtn field value.
*/
public boolean isFLockAtn()
{
return fLockAtn.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fMirrorMargins field value.
- *
+ *
*/
public void setFMirrorMargins(boolean value)
{
field_6_docinfo1 = (byte)fMirrorMargins.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fMirrorMargins field value.
*/
public boolean isFMirrorMargins()
{
return fMirrorMargins.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the unused3 field value.
- *
+ *
*/
public void setUnused3(boolean value)
{
field_6_docinfo1 = (byte)unused3.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the unused3 field value.
*/
public boolean isUnused3()
{
return unused3.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fDfltTrueType field value.
- *
+ *
*/
public void setFDfltTrueType(boolean value)
{
field_6_docinfo1 = (byte)fDfltTrueType.setBoolean(field_6_docinfo1, value);
-
+
}
/**
- *
+ *
* @return the fDfltTrueType field value.
*/
public boolean isFDfltTrueType()
{
return fDfltTrueType.isSet(field_6_docinfo1);
-
+
}
/**
* Sets the fPagSupressTopSpacing field value.
- *
+ *
*/
public void setFPagSupressTopSpacing(boolean value)
{
field_7_docinfo2 = (byte)fPagSupressTopSpacing.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fPagSupressTopSpacing field value.
*/
public boolean isFPagSupressTopSpacing()
{
return fPagSupressTopSpacing.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the fProtEnabled field value.
- *
+ *
*/
public void setFProtEnabled(boolean value)
{
field_7_docinfo2 = (byte)fProtEnabled.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fProtEnabled field value.
*/
public boolean isFProtEnabled()
{
return fProtEnabled.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the fDispFormFldSel field value.
- *
+ *
*/
public void setFDispFormFldSel(boolean value)
{
field_7_docinfo2 = (byte)fDispFormFldSel.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fDispFormFldSel field value.
*/
public boolean isFDispFormFldSel()
{
return fDispFormFldSel.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the fRMView field value.
- *
+ *
*/
public void setFRMView(boolean value)
{
field_7_docinfo2 = (byte)fRMView.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fRMView field value.
*/
public boolean isFRMView()
{
return fRMView.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the fRMPrint field value.
- *
+ *
*/
public void setFRMPrint(boolean value)
{
field_7_docinfo2 = (byte)fRMPrint.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fRMPrint field value.
*/
public boolean isFRMPrint()
{
return fRMPrint.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the unused4 field value.
- *
+ *
*/
public void setUnused4(boolean value)
{
field_7_docinfo2 = (byte)unused4.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the unused4 field value.
*/
public boolean isUnused4()
{
return unused4.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the fLockRev field value.
- *
+ *
*/
public void setFLockRev(boolean value)
{
field_7_docinfo2 = (byte)fLockRev.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fLockRev field value.
*/
public boolean isFLockRev()
{
return fLockRev.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the fEmbedFonts field value.
- *
+ *
*/
public void setFEmbedFonts(boolean value)
{
field_7_docinfo2 = (byte)fEmbedFonts.setBoolean(field_7_docinfo2, value);
-
+
}
/**
- *
+ *
* @return the fEmbedFonts field value.
*/
public boolean isFEmbedFonts()
{
return fEmbedFonts.isSet(field_7_docinfo2);
-
+
}
/**
* Sets the oldfNoTabForInd field value.
- *
+ *
*/
public void setOldfNoTabForInd(boolean value)
{
field_8_docinfo3 = (short)oldfNoTabForInd.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfNoTabForInd field value.
*/
public boolean isOldfNoTabForInd()
{
return oldfNoTabForInd.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfNoSpaceRaiseLower field value.
- *
+ *
*/
public void setOldfNoSpaceRaiseLower(boolean value)
{
field_8_docinfo3 = (short)oldfNoSpaceRaiseLower.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfNoSpaceRaiseLower field value.
*/
public boolean isOldfNoSpaceRaiseLower()
{
return oldfNoSpaceRaiseLower.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfSuppressSpbfAfterPageBreak field value.
- *
+ *
*/
public void setOldfSuppressSpbfAfterPageBreak(boolean value)
{
field_8_docinfo3 = (short)oldfSuppressSpbfAfterPageBreak.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfSuppressSpbfAfterPageBreak field value.
*/
public boolean isOldfSuppressSpbfAfterPageBreak()
{
return oldfSuppressSpbfAfterPageBreak.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfWrapTrailSpaces field value.
- *
+ *
*/
public void setOldfWrapTrailSpaces(boolean value)
{
field_8_docinfo3 = (short)oldfWrapTrailSpaces.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfWrapTrailSpaces field value.
*/
public boolean isOldfWrapTrailSpaces()
{
return oldfWrapTrailSpaces.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfMapPrintTextColor field value.
- *
+ *
*/
public void setOldfMapPrintTextColor(boolean value)
{
field_8_docinfo3 = (short)oldfMapPrintTextColor.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfMapPrintTextColor field value.
*/
public boolean isOldfMapPrintTextColor()
{
return oldfMapPrintTextColor.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfNoColumnBalance field value.
- *
+ *
*/
public void setOldfNoColumnBalance(boolean value)
{
field_8_docinfo3 = (short)oldfNoColumnBalance.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfNoColumnBalance field value.
*/
public boolean isOldfNoColumnBalance()
{
return oldfNoColumnBalance.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfConvMailMergeEsc field value.
- *
+ *
*/
public void setOldfConvMailMergeEsc(boolean value)
{
field_8_docinfo3 = (short)oldfConvMailMergeEsc.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfConvMailMergeEsc field value.
*/
public boolean isOldfConvMailMergeEsc()
{
return oldfConvMailMergeEsc.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfSupressTopSpacing field value.
- *
+ *
*/
public void setOldfSupressTopSpacing(boolean value)
{
field_8_docinfo3 = (short)oldfSupressTopSpacing.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfSupressTopSpacing field value.
*/
public boolean isOldfSupressTopSpacing()
{
return oldfSupressTopSpacing.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfOrigWordTableRules field value.
- *
+ *
*/
public void setOldfOrigWordTableRules(boolean value)
{
field_8_docinfo3 = (short)oldfOrigWordTableRules.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfOrigWordTableRules field value.
*/
public boolean isOldfOrigWordTableRules()
{
return oldfOrigWordTableRules.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfTransparentMetafiles field value.
- *
+ *
*/
public void setOldfTransparentMetafiles(boolean value)
{
field_8_docinfo3 = (short)oldfTransparentMetafiles.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfTransparentMetafiles field value.
*/
public boolean isOldfTransparentMetafiles()
{
return oldfTransparentMetafiles.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfShowBreaksInFrames field value.
- *
+ *
*/
public void setOldfShowBreaksInFrames(boolean value)
{
field_8_docinfo3 = (short)oldfShowBreaksInFrames.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfShowBreaksInFrames field value.
*/
public boolean isOldfShowBreaksInFrames()
{
return oldfShowBreaksInFrames.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the oldfSwapBordersFacingPgs field value.
- *
+ *
*/
public void setOldfSwapBordersFacingPgs(boolean value)
{
field_8_docinfo3 = (short)oldfSwapBordersFacingPgs.setBoolean(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the oldfSwapBordersFacingPgs field value.
*/
public boolean isOldfSwapBordersFacingPgs()
{
return oldfSwapBordersFacingPgs.isSet(field_8_docinfo3);
-
+
}
/**
* Sets the unused5 field value.
- *
+ *
*/
public void setUnused5(byte value)
{
field_8_docinfo3 = (short)unused5.setValue(field_8_docinfo3, value);
-
+
}
/**
- *
+ *
* @return the unused5 field value.
*/
public byte getUnused5()
{
return ( byte )unused5.getValue(field_8_docinfo3);
-
+
}
/**
* Sets the rncEdn field value.
- *
+ *
*/
public void setRncEdn(byte value)
{
field_23_Edn = (short)rncEdn.setValue(field_23_Edn, value);
-
+
}
/**
- *
+ *
* @return the rncEdn field value.
*/
public byte getRncEdn()
{
return ( byte )rncEdn.getValue(field_23_Edn);
-
+
}
/**
* Sets the nEdn field value.
- *
+ *
*/
public void setNEdn(short value)
{
field_23_Edn = (short)nEdn.setValue(field_23_Edn, value);
-
+
}
/**
- *
+ *
* @return the nEdn field value.
*/
public short getNEdn()
{
return ( short )nEdn.getValue(field_23_Edn);
-
+
}
/**
* Sets the epc field value.
- *
+ *
*/
public void setEpc(byte value)
{
field_24_Edn1 = (short)epc.setValue(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the epc field value.
*/
public byte getEpc()
{
return ( byte )epc.getValue(field_24_Edn1);
-
+
}
/**
* Sets the nfcFtnRef1 field value.
- *
+ *
*/
public void setNfcFtnRef1(byte value)
{
field_24_Edn1 = (short)nfcFtnRef1.setValue(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the nfcFtnRef1 field value.
*/
public byte getNfcFtnRef1()
{
return ( byte )nfcFtnRef1.getValue(field_24_Edn1);
-
+
}
/**
* Sets the nfcEdnRef1 field value.
- *
+ *
*/
public void setNfcEdnRef1(byte value)
{
field_24_Edn1 = (short)nfcEdnRef1.setValue(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the nfcEdnRef1 field value.
*/
public byte getNfcEdnRef1()
{
return ( byte )nfcEdnRef1.getValue(field_24_Edn1);
-
+
}
/**
* Sets the fPrintFormData field value.
- *
+ *
*/
public void setFPrintFormData(boolean value)
{
field_24_Edn1 = (short)fPrintFormData.setBoolean(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the fPrintFormData field value.
*/
public boolean isFPrintFormData()
{
return fPrintFormData.isSet(field_24_Edn1);
-
+
}
/**
* Sets the fSaveFormData field value.
- *
+ *
*/
public void setFSaveFormData(boolean value)
{
field_24_Edn1 = (short)fSaveFormData.setBoolean(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the fSaveFormData field value.
*/
public boolean isFSaveFormData()
{
return fSaveFormData.isSet(field_24_Edn1);
-
+
}
/**
* Sets the fShadeFormData field value.
- *
+ *
*/
public void setFShadeFormData(boolean value)
{
field_24_Edn1 = (short)fShadeFormData.setBoolean(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the fShadeFormData field value.
*/
public boolean isFShadeFormData()
{
return fShadeFormData.isSet(field_24_Edn1);
-
+
}
/**
* Sets the fWCFtnEdn field value.
- *
+ *
*/
public void setFWCFtnEdn(boolean value)
{
field_24_Edn1 = (short)fWCFtnEdn.setBoolean(field_24_Edn1, value);
-
+
}
/**
- *
+ *
* @return the fWCFtnEdn field value.
*/
public boolean isFWCFtnEdn()
{
return fWCFtnEdn.isSet(field_24_Edn1);
-
+
}
/**
* Sets the wvkSaved field value.
- *
+ *
*/
public void setWvkSaved(byte value)
{
field_32_view = (short)wvkSaved.setValue(field_32_view, value);
-
+
}
/**
- *
+ *
* @return the wvkSaved field value.
*/
public byte getWvkSaved()
{
return ( byte )wvkSaved.getValue(field_32_view);
-
+
}
/**
* Sets the wScaleSaved field value.
- *
+ *
*/
public void setWScaleSaved(short value)
{
field_32_view = (short)wScaleSaved.setValue(field_32_view, value);
-
+
}
/**
- *
+ *
* @return the wScaleSaved field value.
*/
public short getWScaleSaved()
{
return ( short )wScaleSaved.getValue(field_32_view);
-
+
}
/**
* Sets the zkSaved field value.
- *
+ *
*/
public void setZkSaved(byte value)
{
field_32_view = (short)zkSaved.setValue(field_32_view, value);
-
+
}
/**
- *
+ *
* @return the zkSaved field value.
*/
public byte getZkSaved()
{
return ( byte )zkSaved.getValue(field_32_view);
-
+
}
/**
* Sets the fRotateFontW6 field value.
- *
+ *
*/
public void setFRotateFontW6(boolean value)
{
field_32_view = (short)fRotateFontW6.setBoolean(field_32_view, value);
-
+
}
/**
- *
+ *
* @return the fRotateFontW6 field value.
*/
public boolean isFRotateFontW6()
{
return fRotateFontW6.isSet(field_32_view);
-
+
}
/**
* Sets the iGutterPos field value.
- *
+ *
*/
public void setIGutterPos(boolean value)
{
field_32_view = (short)iGutterPos.setBoolean(field_32_view, value);
-
+
}
/**
- *
+ *
* @return the iGutterPos field value.
*/
public boolean isIGutterPos()
{
return iGutterPos.isSet(field_32_view);
-
+
}
/**
* Sets the fNoTabForInd field value.
- *
+ *
*/
public void setFNoTabForInd(boolean value)
{
field_33_docinfo4 = (int)fNoTabForInd.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fNoTabForInd field value.
*/
public boolean isFNoTabForInd()
{
return fNoTabForInd.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fNoSpaceRaiseLower field value.
- *
+ *
*/
public void setFNoSpaceRaiseLower(boolean value)
{
field_33_docinfo4 = (int)fNoSpaceRaiseLower.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fNoSpaceRaiseLower field value.
*/
public boolean isFNoSpaceRaiseLower()
{
return fNoSpaceRaiseLower.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fSupressSpdfAfterPageBreak field value.
- *
+ *
*/
public void setFSupressSpdfAfterPageBreak(boolean value)
{
field_33_docinfo4 = (int)fSupressSpdfAfterPageBreak.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fSupressSpdfAfterPageBreak field value.
*/
public boolean isFSupressSpdfAfterPageBreak()
{
return fSupressSpdfAfterPageBreak.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fWrapTrailSpaces field value.
- *
+ *
*/
public void setFWrapTrailSpaces(boolean value)
{
field_33_docinfo4 = (int)fWrapTrailSpaces.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fWrapTrailSpaces field value.
*/
public boolean isFWrapTrailSpaces()
{
return fWrapTrailSpaces.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fMapPrintTextColor field value.
- *
+ *
*/
public void setFMapPrintTextColor(boolean value)
{
field_33_docinfo4 = (int)fMapPrintTextColor.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fMapPrintTextColor field value.
*/
public boolean isFMapPrintTextColor()
{
return fMapPrintTextColor.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fNoColumnBalance field value.
- *
+ *
*/
public void setFNoColumnBalance(boolean value)
{
field_33_docinfo4 = (int)fNoColumnBalance.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fNoColumnBalance field value.
*/
public boolean isFNoColumnBalance()
{
return fNoColumnBalance.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fConvMailMergeEsc field value.
- *
+ *
*/
public void setFConvMailMergeEsc(boolean value)
{
field_33_docinfo4 = (int)fConvMailMergeEsc.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fConvMailMergeEsc field value.
*/
public boolean isFConvMailMergeEsc()
{
return fConvMailMergeEsc.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fSupressTopSpacing field value.
- *
+ *
*/
public void setFSupressTopSpacing(boolean value)
{
field_33_docinfo4 = (int)fSupressTopSpacing.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fSupressTopSpacing field value.
*/
public boolean isFSupressTopSpacing()
{
return fSupressTopSpacing.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fOrigWordTableRules field value.
- *
+ *
*/
public void setFOrigWordTableRules(boolean value)
{
field_33_docinfo4 = (int)fOrigWordTableRules.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fOrigWordTableRules field value.
*/
public boolean isFOrigWordTableRules()
{
return fOrigWordTableRules.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fTransparentMetafiles field value.
- *
+ *
*/
public void setFTransparentMetafiles(boolean value)
{
field_33_docinfo4 = (int)fTransparentMetafiles.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fTransparentMetafiles field value.
*/
public boolean isFTransparentMetafiles()
{
return fTransparentMetafiles.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fShowBreaksInFrames field value.
- *
+ *
*/
public void setFShowBreaksInFrames(boolean value)
{
field_33_docinfo4 = (int)fShowBreaksInFrames.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fShowBreaksInFrames field value.
*/
public boolean isFShowBreaksInFrames()
{
return fShowBreaksInFrames.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fSwapBordersFacingPgs field value.
- *
+ *
*/
public void setFSwapBordersFacingPgs(boolean value)
{
field_33_docinfo4 = (int)fSwapBordersFacingPgs.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fSwapBordersFacingPgs field value.
*/
public boolean isFSwapBordersFacingPgs()
{
return fSwapBordersFacingPgs.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fSuppressTopSPacingMac5 field value.
- *
+ *
*/
public void setFSuppressTopSPacingMac5(boolean value)
{
field_33_docinfo4 = (int)fSuppressTopSPacingMac5.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fSuppressTopSPacingMac5 field value.
*/
public boolean isFSuppressTopSPacingMac5()
{
return fSuppressTopSPacingMac5.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fTruncDxaExpand field value.
- *
+ *
*/
public void setFTruncDxaExpand(boolean value)
{
field_33_docinfo4 = (int)fTruncDxaExpand.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fTruncDxaExpand field value.
*/
public boolean isFTruncDxaExpand()
{
return fTruncDxaExpand.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fPrintBodyBeforeHdr field value.
- *
+ *
*/
public void setFPrintBodyBeforeHdr(boolean value)
{
field_33_docinfo4 = (int)fPrintBodyBeforeHdr.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fPrintBodyBeforeHdr field value.
*/
public boolean isFPrintBodyBeforeHdr()
{
return fPrintBodyBeforeHdr.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fNoLeading field value.
- *
+ *
*/
public void setFNoLeading(boolean value)
{
field_33_docinfo4 = (int)fNoLeading.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fNoLeading field value.
*/
public boolean isFNoLeading()
{
return fNoLeading.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the fMWSmallCaps field value.
- *
+ *
*/
public void setFMWSmallCaps(boolean value)
{
field_33_docinfo4 = (int)fMWSmallCaps.setBoolean(field_33_docinfo4, value);
-
+
}
/**
- *
+ *
* @return the fMWSmallCaps field value.
*/
public boolean isFMWSmallCaps()
{
return fMWSmallCaps.isSet(field_33_docinfo4);
-
+
}
/**
* Sets the lvl field value.
- *
+ *
*/
public void setLvl(byte value)
{
field_37_docinfo5 = (short)lvl.setValue(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the lvl field value.
*/
public byte getLvl()
{
return ( byte )lvl.getValue(field_37_docinfo5);
-
+
}
/**
* Sets the fGramAllDone field value.
- *
+ *
*/
public void setFGramAllDone(boolean value)
{
field_37_docinfo5 = (short)fGramAllDone.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fGramAllDone field value.
*/
public boolean isFGramAllDone()
{
return fGramAllDone.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fGramAllClean field value.
- *
+ *
*/
public void setFGramAllClean(boolean value)
{
field_37_docinfo5 = (short)fGramAllClean.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fGramAllClean field value.
*/
public boolean isFGramAllClean()
{
return fGramAllClean.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fSubsetFonts field value.
- *
+ *
*/
public void setFSubsetFonts(boolean value)
{
field_37_docinfo5 = (short)fSubsetFonts.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fSubsetFonts field value.
*/
public boolean isFSubsetFonts()
{
return fSubsetFonts.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fHideLastVersion field value.
- *
+ *
*/
public void setFHideLastVersion(boolean value)
{
field_37_docinfo5 = (short)fHideLastVersion.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fHideLastVersion field value.
*/
public boolean isFHideLastVersion()
{
return fHideLastVersion.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fHtmlDoc field value.
- *
+ *
*/
public void setFHtmlDoc(boolean value)
{
field_37_docinfo5 = (short)fHtmlDoc.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fHtmlDoc field value.
*/
public boolean isFHtmlDoc()
{
return fHtmlDoc.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fSnapBorder field value.
- *
+ *
*/
public void setFSnapBorder(boolean value)
{
field_37_docinfo5 = (short)fSnapBorder.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fSnapBorder field value.
*/
public boolean isFSnapBorder()
{
return fSnapBorder.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fIncludeHeader field value.
- *
+ *
*/
public void setFIncludeHeader(boolean value)
{
field_37_docinfo5 = (short)fIncludeHeader.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fIncludeHeader field value.
*/
public boolean isFIncludeHeader()
{
return fIncludeHeader.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fIncludeFooter field value.
- *
+ *
*/
public void setFIncludeFooter(boolean value)
{
field_37_docinfo5 = (short)fIncludeFooter.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fIncludeFooter field value.
*/
public boolean isFIncludeFooter()
{
return fIncludeFooter.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fForcePageSizePag field value.
- *
+ *
*/
public void setFForcePageSizePag(boolean value)
{
field_37_docinfo5 = (short)fForcePageSizePag.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fForcePageSizePag field value.
*/
public boolean isFForcePageSizePag()
{
return fForcePageSizePag.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fMinFontSizePag field value.
- *
+ *
*/
public void setFMinFontSizePag(boolean value)
{
field_37_docinfo5 = (short)fMinFontSizePag.setBoolean(field_37_docinfo5, value);
-
+
}
/**
- *
+ *
* @return the fMinFontSizePag field value.
*/
public boolean isFMinFontSizePag()
{
return fMinFontSizePag.isSet(field_37_docinfo5);
-
+
}
/**
* Sets the fHaveVersions field value.
- *
+ *
*/
public void setFHaveVersions(boolean value)
{
field_38_docinfo6 = (short)fHaveVersions.setBoolean(field_38_docinfo6, value);
-
+
}
/**
- *
+ *
* @return the fHaveVersions field value.
*/
public boolean isFHaveVersions()
{
return fHaveVersions.isSet(field_38_docinfo6);
-
+
}
/**
* Sets the fAutoVersions field value.
- *
+ *
*/
public void setFAutoVersions(boolean value)
{
field_38_docinfo6 = (short)fAutoVersions.setBoolean(field_38_docinfo6, value);
-
+
}
/**
- *
+ *
* @return the fAutoVersions field value.
*/
public boolean isFAutoVersions()
{
return fAutoVersions.isSet(field_38_docinfo6);
-
+
}
/**
* Sets the fVirusPrompted field value.
- *
+ *
*/
public void setFVirusPrompted(boolean value)
{
field_43_virusinfo = (int)fVirusPrompted.setBoolean(field_43_virusinfo, value);
-
+
}
/**
- *
+ *
* @return the fVirusPrompted field value.
*/
public boolean isFVirusPrompted()
{
return fVirusPrompted.isSet(field_43_virusinfo);
-
+
}
/**
* Sets the fVirusLoadSafe field value.
- *
+ *
*/
public void setFVirusLoadSafe(boolean value)
{
field_43_virusinfo = (int)fVirusLoadSafe.setBoolean(field_43_virusinfo, value);
-
+
}
/**
- *
+ *
* @return the fVirusLoadSafe field value.
*/
public boolean isFVirusLoadSafe()
{
return fVirusLoadSafe.isSet(field_43_virusinfo);
-
+
}
/**
* Sets the KeyVirusSession30 field value.
- *
+ *
*/
public void setKeyVirusSession30(int value)
{
field_43_virusinfo = (int)KeyVirusSession30.setValue(field_43_virusinfo, value);
-
+
}
/**
- *
+ *
* @return the KeyVirusSession30 field value.
*/
public int getKeyVirusSession30()
{
return ( int )KeyVirusSession30.getValue(field_43_virusinfo);
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
/**
* Sets the fVertical field value.
- *
+ *
*/
public void setFVertical(boolean value)
{
field_35_fontAlign = (short)fVertical.setBoolean(field_35_fontAlign, value);
-
+
}
/**
- *
+ *
* @return the fVertical field value.
*/
public boolean isFVertical()
{
return fVertical.isSet(field_35_fontAlign);
-
+
}
/**
* Sets the fBackward field value.
- *
+ *
*/
public void setFBackward(boolean value)
{
field_35_fontAlign = (short)fBackward.setBoolean(field_35_fontAlign, value);
-
+
}
/**
- *
+ *
* @return the fBackward field value.
*/
public boolean isFBackward()
{
return fBackward.isSet(field_35_fontAlign);
-
+
}
/**
* Sets the fRotateFont field value.
- *
+ *
*/
public void setFRotateFont(boolean value)
{
field_35_fontAlign = (short)fRotateFont.setBoolean(field_35_fontAlign, value);
-
+
}
/**
- *
+ *
* @return the fRotateFont field value.
*/
public boolean isFRotateFont()
{
return fRotateFont.isSet(field_35_fontAlign);
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.model.types;
/**
* Sets the fFirstMerged field value.
- *
+ *
*/
public void setFFirstMerged(boolean value)
{
field_1_rgf = (short)fFirstMerged.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fFirstMerged field value.
*/
public boolean isFFirstMerged()
{
return fFirstMerged.isSet(field_1_rgf);
-
+
}
/**
* Sets the fMerged field value.
- *
+ *
*/
public void setFMerged(boolean value)
{
field_1_rgf = (short)fMerged.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fMerged field value.
*/
public boolean isFMerged()
{
return fMerged.isSet(field_1_rgf);
-
+
}
/**
* Sets the fVertical field value.
- *
+ *
*/
public void setFVertical(boolean value)
{
field_1_rgf = (short)fVertical.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fVertical field value.
*/
public boolean isFVertical()
{
return fVertical.isSet(field_1_rgf);
-
+
}
/**
* Sets the fBackward field value.
- *
+ *
*/
public void setFBackward(boolean value)
{
field_1_rgf = (short)fBackward.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fBackward field value.
*/
public boolean isFBackward()
{
return fBackward.isSet(field_1_rgf);
-
+
}
/**
* Sets the fRotateFont field value.
- *
+ *
*/
public void setFRotateFont(boolean value)
{
field_1_rgf = (short)fRotateFont.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fRotateFont field value.
*/
public boolean isFRotateFont()
{
return fRotateFont.isSet(field_1_rgf);
-
+
}
/**
* Sets the fVertMerge field value.
- *
+ *
*/
public void setFVertMerge(boolean value)
{
field_1_rgf = (short)fVertMerge.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fVertMerge field value.
*/
public boolean isFVertMerge()
{
return fVertMerge.isSet(field_1_rgf);
-
+
}
/**
* Sets the fVertRestart field value.
- *
+ *
*/
public void setFVertRestart(boolean value)
{
field_1_rgf = (short)fVertRestart.setBoolean(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the fVertRestart field value.
*/
public boolean isFVertRestart()
{
return fVertRestart.isSet(field_1_rgf);
-
+
}
/**
* Sets the vertAlign field value.
- *
+ *
*/
public void setVertAlign(byte value)
{
field_1_rgf = (short)vertAlign.setValue(field_1_rgf, value);
-
+
}
/**
- *
+ *
* @return the vertAlign field value.
*/
public byte getVertAlign()
{
return ( byte )vertAlign.getValue(field_1_rgf);
-
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.util.LittleEndian;
-public class CharacterSprmCompressor
+public final class CharacterSprmCompressor
{
public CharacterSprmCompressor()
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.util.LittleEndian;
-public class CharacterSprmUncompressor
+public final class CharacterSprmUncompressor
{
public CharacterSprmUncompressor()
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
-public class ParagraphSprmCompressor
+public final class ParagraphSprmCompressor
{
public ParagraphSprmCompressor()
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import java.util.Collections;
import java.util.ArrayList;
-public class ParagraphSprmUncompressor
+public final class ParagraphSprmUncompressor
extends SprmUncompressor
{
public ParagraphSprmUncompressor()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-//
+
package org.apache.poi.hwpf.sprm;
//
import org.apache.poi.util.LittleEndian;
-public class SectionSprmCompressor
+public final class SectionSprmCompressor
{
private final static SectionProperties DEFAULT_SEP = new SectionProperties();
public SectionSprmCompressor()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.usermodel.BorderCode;
-public class SectionSprmUncompressor extends SprmUncompressor
+public final class SectionSprmUncompressor extends SprmUncompressor
{
public SectionSprmUncompressor()
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import java.util.Arrays;
-public class SprmBuffer
+public final class SprmBuffer
implements Cloneable
{
byte[] _buf;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
* @version 1.0
*/
-public class SprmIterator
+public final class SprmIterator
{
private byte[] _grpprl;
int _offset;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
* @author Ryan Ackley
* @version 1.0
*/
-public class SprmOperation
+public final class SprmOperation
{
final static private BitField OP_BITFIELD = BitFieldFactory.getInstance(0x1ff);
final static private BitField SPECIAL_BITFIELD = BitFieldFactory.getInstance(0x200);
return LittleEndian.getInt(_grpprl, _gOffset);
case 6:
byte operandLength = _grpprl[_gOffset + 1]; //surely shorter than an int...
-
+
byte [] codeBytes = new byte[LittleEndian.INT_SIZE]; //initialized to zeros by JVM
for(int i = 0; i < operandLength; i++)
if(_gOffset + i < _grpprl.length)
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
-public class SprmUncompressor
+public abstract class SprmUncompressor
{
- public SprmUncompressor()
+ protected SprmUncompressor()
{
}
{
return true;
}
- else
- {
- return false;
- }
+ return false;
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.util.LittleEndian;
-public class SprmUtils
+public final class SprmUtils
{
public SprmUtils()
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import java.util.ArrayList;
import java.util.Arrays;
-public class TableSprmCompressor
+public final class TableSprmCompressor
{
public TableSprmCompressor()
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.TableProperties;
import org.apache.poi.util.LittleEndian;
-public class TableSprmUncompressor
+public final class TableSprmUncompressor
extends SprmUncompressor
{
public TableSprmUncompressor()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
-public class BorderCode
+public final class BorderCode
implements Cloneable
{
public static final int SIZE = 4;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.types.CHPAbstractType;
/**
* @author Ryan Ackley
*/
-public class CharacterProperties
+public final class CharacterProperties
extends CHPAbstractType implements Cloneable
{
public final static short SPRM_FRMARKDEL = (short)0x0800;
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.CHPX;
*
* @author Ryan Ackley
*/
-public class CharacterRun
+public final class CharacterRun
extends Range
implements Cloneable
{
return (CharacterProperties)_props.clone();
} catch(java.lang.CloneNotSupportedException e) {
throw new RuntimeException(e);
- }
+ }
}
/**
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitField;
*
* @author Ryan Ackley
*/
-public class DateAndTime
+public final class DateAndTime
implements Cloneable
{
public static final int SIZE = 4;
limitations under the License.
==================================================================== */
-/**
- * @author Ryan Ackley
- */
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.HWPFDocument;
-public class DocumentPosition
+public final class DocumentPosition
extends Range
{
public DocumentPosition(HWPFDocument doc, int pos)
super(pos, pos, doc);
}
-}
\ No newline at end of file
+}
*
* @author Ryan Ackley
*/
-public class DropCapSpecifier
+public final class DropCapSpecifier
{
private short _info;
private static BitField _type = BitFieldFactory.getInstance(0x07);
*
* @author Ryan Ackley
*/
-public class HWPFList
+public final class HWPFList
{
private ListData _listData;
private ListFormatOverride _override;
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.PlexOfCps;
/**
- * A HeaderStory is a Header, a Footer, or footnote/endnote
+ * A HeaderStory is a Header, a Footer, or footnote/endnote
* separator.
* All the Header Stories get stored in the same Range in the
* document, and this handles getting out all the individual
* parts.
- *
+ *
* WARNING - you shouldn't change the headers or footers,
* as offsets are not yet updated!
*/
-public class HeaderStories {
+public final class HeaderStories {
private Range headerStories;
private PlexOfCps plcfHdd;
-
+
private boolean stripFields = false;
-
+
public HeaderStories(HWPFDocument doc) {
this.headerStories = doc.getHeaderStoryRange();
FileInformationBlock fib = doc.getFileInformationBlock();
-
+
// If there's no PlcfHdd, nothing to do
if(fib.getCcpHdd() == 0) {
return;
if(fib.getPlcfHddSize() == 0) {
return;
}
-
+
// Handle the PlcfHdd
plcfHdd = new PlexOfCps(
doc.getTableStream(), fib.getPlcfHddOffset(),
fib.getPlcfHddSize(), 0
);
}
-
+
public String getFootnoteSeparator() {
return getAt(0);
}
public String getEndnoteContNote() {
return getAt(5);
}
-
-
+
+
public String getEvenHeader() {
return getAt(6+0);
}
// Odd is the default
return getOddHeader();
}
-
-
+
+
public String getEvenFooter() {
return getAt(6+2);
}
// Odd is the default
return getOddFooter();
}
-
-
+
+
/**
* Get the string that's pointed to by the
- * given plcfHdd index
+ * given plcfHdd index
*/
private String getAt(int plcfHddIndex) {
if(plcfHdd == null) return null;
-
+
GenericPropertyNode prop = plcfHdd.getProperty(plcfHddIndex);
if(prop.getStart() == prop.getEnd()) {
// Empty story
return "";
}
-
+
// Grab the contents
String text =
headerStories.text().substring(prop.getStart(), prop.getEnd());
-
+
// Strip off fields and macros if requested
if(stripFields) {
return Range.stripFields(text);
if(text.equals("\r\r")) {
return "";
}
-
+
return text;
}
-
+
public Range getRange() {
return headerStories;
}
protected PlexOfCps getPlcfHdd() {
return plcfHdd;
}
-
+
/**
* Are fields currently being stripped from
* the text that this {@link HeaderStories} returns?
*
* @author Ryan Ackley
*/
-public class LineSpacingDescriptor
+public final class LineSpacingDescriptor
implements Cloneable
{
short _dyaLine;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.ListFormatOverride;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-public class ListEntry
+public final class ListEntry
extends Paragraph
{
private static POILogger log = POILogFactory.getLogger(ListEntry.class);
-
+
ListLevel _level;
ListFormatOverrideLevel _overrideLevel;
ListEntry(PAPX papx, Range parent, ListTables tables)
{
super(papx, parent);
-
+
if(tables != null) {
ListFormatOverride override = tables.getOverride(_props.getIlfo());
_overrideLevel = override.getOverrideLevel(_props.getIlvl());
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.PAPX;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.hwpf.sprm.TableSprmCompressor;
-public class Paragraph
- extends Range
- implements Cloneable
-{
+public class Paragraph extends Range implements Cloneable {
public final static short SPRM_JC = 0x2403;
public final static short SPRM_FSIDEBYSIDE = 0x2404;
public final static short SPRM_FKEEP = 0x2405;
/**
* clone the ParagraphProperties object associated with this Paragraph so
* that you can apply the same properties to another paragraph.
- *
+ *
*/
public ParagraphProperties cloneProperties() {
try {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.sprm.SprmBuffer;
-public class ParagraphProperties
+public final class ParagraphProperties
extends PAPAbstractType
implements Cloneable
{
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.LittleEndian;
* Represents embedded picture extracted from Word Document
* @author Dmitry Romanov
*/
-public class Picture
+public final class Picture
{
private static final POILogger log = POILogFactory.getLogger(Picture.class);
fillImageContent();
}
}
-
+
public Picture(byte[] _dataStream)
{
this._dataStream = _dataStream;
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hwpf.usermodel;
*
* @author Ryan Ackley
*/
-public class Range
-{
+public class Range { // TODO -instantiable superclass
public static final int TYPE_PARAGRAPH = 0;
public static final int TYPE_CHARACTER= 1;
_characters = _doc.getCharacterTable().getTextRuns();
_text = _doc.getTextTable().getTextPieces();
_parent = new WeakReference(null);
-
+
sanityCheckStartEnd();
}
_characters = parent._characters;
_text = parent._text;
_parent = new WeakReference(parent);
-
+
sanityCheckStartEnd();
}
_textRangeFound = true;
break;
}
-
+
sanityCheckStartEnd();
}
-
+
/**
* Ensures that the start and end were were given
* are actually valid, to avoid issues later on
for (int x = _textStart; x < _textEnd; x++)
{
TextPiece piece = (TextPiece)_text.get(x);
-
+
// Figure out where in this piece the text
// we're after lives
int rStart = 0;
if(_end < piece.getEnd()) {
rEnd -= (piece.getEnd() - _end);
}
-
+
// Luckily TextPieces work in characters, so we don't
// need to worry about unicode here
sb.append(piece.substring(rStart, rEnd));
}
return sb.toString();
}
-
+
/**
* Removes any fields (eg macros, page markers etc)
* from the string.
// First up, fields can be nested...
// A field can be 0x13 [contents] 0x15
// Or it can be 0x13 [contents] 0x14 [real text] 0x15
-
+
// If there are no fields, all easy
if(text.indexOf('\u0013') == -1) return text;
-
+
// Loop over until they're all gone
// That's when we're out of both 0x13s and 0x15s
while( text.indexOf('\u0013') > -1 &&
int next13 = text.indexOf('\u0013', first13+1);
int first14 = text.indexOf('\u0014', first13+1);
int last15 = text.lastIndexOf('\u0015');
-
+
// If they're the wrong way around, give up
if(last15 < first13) {
break;
}
-
+
// If no more 13s and 14s, just zap
if(next13 == -1 && first14 == -1) {
text = text.substring(0, first13) +
text.substring(last15+1);
break;
}
-
+
// If a 14 comes before the next 13, then
// zap from the 13 to the 14, and remove
// the 15
text.substring(last15+1);
continue;
}
-
+
// Another 13 comes before the next 14.
// This means there's nested stuff, so we
// can just zap the lot
sepx.adjustForDelete(_start, _end - _start);
//System.err.println("Section " + x + " is now " + sepx.getStart() + " -> " + sepx.getEnd());
}
-
+
for (int x = _textStart; x < numTextPieces; x++)
{
TextPiece piece = (TextPiece)_text.get(x);
{
int absPlaceHolderIndex = getStartOffset() + pOffset;
Range subRange = new Range(
- absPlaceHolderIndex,
+ absPlaceHolderIndex,
(absPlaceHolderIndex + pPlaceHolder.length()), getDocument()
);
// re-create the sub-range so we can delete it
subRange = new Range(
(absPlaceHolderIndex + pValue.length()),
- (absPlaceHolderIndex + pPlaceHolder.length() + pValue.length()),
+ (absPlaceHolderIndex + pPlaceHolder.length() + pValue.length()),
getDocument()
);
/**
* Adjust the value of the various FIB character count fields,
* eg <code>FIB.CCPText</code> after an insert or a delete...
- *
+ *
* Works on all CCP fields from this range onwards
*
* @param adjustment The (signed) value that should be added to the FIB CCP fields
CPSplitCalculator cpS = _doc.getCPSplitCalculator();
FileInformationBlock fib = _doc.getFileInformationBlock();
-
+
// Do for each affected part
if(_start < cpS.getMainDocumentEnd()) {
fib.setCcpText(fib.getCcpText() + adjustment);
}
-
+
if(_start < cpS.getCommentsEnd()) {
fib.setCcpAtn(fib.getCcpAtn() + adjustment);
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.SEPX;
-public class Section
+public final class Section
extends Range
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import java.lang.reflect.Field;
import java.lang.reflect.AccessibleObject;
-public class SectionProperties
+public final class SectionProperties
extends SEPAbstractType
{
public SectionProperties()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
-public class ShadingDescriptor
+public final class ShadingDescriptor
implements Cloneable
{
public static final int SIZE = 2;
import org.apache.poi.hwpf.model.GenericPropertyNode;
import org.apache.poi.util.LittleEndian;
-public class Shape {
+public final class Shape {
int _id, _left, _right, _top, _bottom;
/**
* true if the Shape bounds are within document (for
* example, it's false if the image left corner is outside the doc, like for
* embedded documents)
*/
- boolean _inDoc;
+ boolean _inDoc;
public Shape(GenericPropertyNode nodo) {
byte [] contenuto = nodo.getBytes();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
import java.util.ArrayList;
-public class Table
+public final class Table
extends Range
{
ArrayList _rows;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.usermodel;
-public class TableCell
+public final class TableCell
extends Range
{
private int _levelNum;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.types.TCAbstractType;
-public class TableCellDescriptor
+public final class TableCellDescriptor
extends TCAbstractType
{
public static final int SIZE = 20;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.usermodel;
import java.util.ArrayList;
-public class TableIterator
+public final class TableIterator
{
Range _range;
int _index;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.types.TAPAbstractType;
-public class TableProperties
+public final class TableProperties
extends TAPAbstractType
implements Cloneable
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
-public class TableRow
+public final class TableRow
extends Paragraph
{
private final static char TABLE_CELL_MARK = '\u0007';
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface AutoShape extends SimpleShape {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface Background extends Shape {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface Fill extends org.apache.poi.common.usermodel.Fill {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface FontCollection {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
/**
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface Line extends AutoShape {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface LineStyle extends org.apache.poi.common.usermodel.LineStyle {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface MasterSheet extends Sheet {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface Notes extends Sheet {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface Picture extends SimpleShape {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface PictureData {
public int getType();
public byte[] getUID();
-
+
public byte[] getData();
public void setData(byte[] data);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
/**
*/
public interface Resources {
public FontCollection getFontCollection();
-
+
public PictureData[] getPictureData();
public int addPictureData(PictureData pict);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
import java.awt.geom.Rectangle2D;
public interface Shape {
public int getShapeType();
-
+
public Rectangle2D getAnchor();
public void setAnchor(Rectangle2D anchor);
-
+
public void moveTo(float x, float y);
-
+
public Shape getParent();
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface ShapeContainer {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface ShapeGroup extends ShapeContainer {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface ShapeTypes {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
/**
public SlideShow getSlideShow();
public MasterSheet getMasterSheet();
-
+
public Background getBackground();
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface SimpleShape extends Shape {
public Fill getFill();
public LineStyle getLineStyle();
-
+
public Hyperlink getHyperlink();
public void setHyperlink(Hyperlink hyperlink);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface Slide extends Sheet {
public Notes getNotes();
public void setNotes(Notes notes);
-
+
public boolean getFollowMasterBackground();
public void setFollowMasterBackground(boolean follow);
-
+
public boolean getFollowMasterColourScheme();
public void setFollowMasterColourScheme(boolean follow);
-
+
public boolean getFollowMasterObjects();
public void setFollowMasterObjects(boolean follow);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
import java.io.IOException;
public interface SlideShow {
public Slide createSlide() throws IOException;
public MasterSheet createMasterSheet() throws IOException;
-
+
public Slide[] getSlides();
public MasterSheet[] getMasterSheet();
-
+
public Resources getResources();
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
public interface TextBox extends AutoShape {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.sl.usermodel;
/**
* Some text.
- *
+ *
* TODO - decide on how we do rich text stuff
*/
public interface TextRun {
public String getText();
public void setText(String text);
-
+
// TODO - rich text formatting stuff
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi;
*
* This is part 2 of 2 of the tests - it only does the POIDocuments
* which are part of the scratchpad (not main)
- *
+ *
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestPOIDocumentScratchpad extends TestCase {
+public final class TestPOIDocumentScratchpad extends TestCase {
// The POI Documents to work on
private POIDocument doc;
private POIDocument doc2;
private POIFSFileSystem pfs2;
/**
- * Set things up, using a PowerPoint document and
+ * Set things up, using a PowerPoint document and
* a Word Document for our testing
*/
public void setUp() throws Exception {
String filenameHSSF = dirnameHSLF + "/DateFormats.ppt";
String dirnameHWPF = System.getProperty("HWPF.testdata.path");
String filenameHWPF = dirnameHWPF + "/test2.doc";
-
+
FileInputStream fisHSLF = new FileInputStream(filenameHSLF);
pfs = new POIFSFileSystem(fisHSLF);
doc = new HSLFSlideShow(pfs);
-
+
FileInputStream fisHWPF = new FileInputStream(filenameHWPF);
pfs2 = new POIFSFileSystem(fisHWPF);
doc2 = new HWPFDocument(pfs2);
}
-
+
public void testReadProperties() throws Exception {
// We should have both sets
assertNotNull(doc.getDocumentSummaryInformation());
assertNotNull(doc.getSummaryInformation());
-
+
// Check they are as expected for the test doc
assertEquals("Hogwarts", doc.getSummaryInformation().getAuthor());
assertEquals(10598, doc.getDocumentSummaryInformation().getByteCount());
}
-
- public void testReadProperties2() throws Exception {
+
+ public void testReadProperties2() throws Exception {
// Check again on the word one
assertNotNull(doc2.getDocumentSummaryInformation());
assertNotNull(doc2.getSummaryInformation());
-
+
assertEquals("Hogwarts", doc2.getSummaryInformation().getAuthor());
assertEquals("", doc2.getSummaryInformation().getKeywords());
assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
// Just check we can write them back out into a filesystem
POIFSFileSystem outFS = new POIFSFileSystem();
doc.writeProperties(outFS);
-
+
// Should now hold them
assertNotNull(
outFS.createDocumentInputStream("\005SummaryInformation")
public void testWriteReadProperties() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
+
// Write them out
POIFSFileSystem outFS = new POIFSFileSystem();
doc.writeProperties(outFS);
outFS.writeFilesystem(baos);
-
+
// Create a new version
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
POIFSFileSystem inFS = new POIFSFileSystem(bais);
-
+
// Check they're still there
doc.filesystem = inFS;
doc.readProperties();
-
+
// Delegate test
testReadProperties();
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hdf.model;
*
* @author Bob Otterberg
*/
-public class TestHDFDocument
+public final class TestHDFDocument
extends TestCase
{
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf;
import java.io.FileInputStream;
import junit.framework.TestCase;
-public class TestHDGFCore extends TestCase {
+public final class TestHDGFCore extends TestCase {
private POIFSFileSystem fs;
private String dirname;
private String filename;
-
+
protected void setUp() throws Exception {
dirname = System.getProperty("HDGF.testdata.path");
filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
fs = new POIFSFileSystem(new FileInputStream(filename));
}
-
+
public void testCreate() throws Exception {
new HDGFDiagram(fs);
}
-
+
public void testTrailer() throws Exception {
HDGFDiagram hdgf = new HDGFDiagram(fs);
assertNotNull(hdgf);
assertNotNull(hdgf.getTrailerStream());
-
+
// Check it has what we'd expect
TrailerStream trailer = hdgf.getTrailerStream();
assertEquals(0x8a94, trailer.getPointer().getOffset());
-
+
assertNotNull(trailer.getPointedToStreams());
assertEquals(20, trailer.getPointedToStreams().length);
-
+
assertEquals(20, hdgf.getTopLevelStreams().length);
-
+
// 9th one should have children
assertNotNull(trailer.getPointedToStreams()[8]);
assertNotNull(trailer.getPointedToStreams()[8].getPointer());
assertNotNull(ps8.getPointedToStreams());
assertEquals(8, ps8.getPointedToStreams().length);
}
-
+
/**
* Tests that we can open a problematic file, that initially
* appears to have a negative chunk length
public void DISABLEDtestNegativeChunkLength() throws Exception {
filename = dirname + "/NegativeChunkLength.vsd";
fs = new POIFSFileSystem(new FileInputStream(filename));
-
+
HDGFDiagram hdgf = new HDGFDiagram(fs);
assertNotNull(hdgf);
}
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-*/
+==================================================================== */
+
package org.apache.poi.hdgf;
import java.io.ByteArrayInputStream;
import junit.framework.TestCase;
-public class TestHDGFLZW extends TestCase {
+public final class TestHDGFLZW extends TestCase {
public static final byte[] testTrailerComp = new byte[] {
123, // *mask bit*
- -60, 2,
+ -60, 2,
-21, -16, // 3 @ 4093
- 1, 0, 0, -72,
+ 1, 0, 0, -72,
-13, -16, // 3 @ 5
78, // *mask bit*
- -32, -5, // 14 @ 4082
- 1, 0, 3,
+ -32, -5, // 14 @ 4082
+ 1, 0, 3,
-21, -16, // 3 @ 4093
10, 5, // 8 @ 28
- 4,
+ 4,
+ -21, -16, // 3 @ 4093
+ 21, // *mask bit*
+ 9,
-21, -16, // 3 @ 4093
- 21, // *mask bit*
- 9,
- -21, -16, // 3 @ 4093
- 103, -21, -16, 34,
+ 103, -21, -16, 34,
-36, -1, // 18 @ 4078
- 52, 15, // 18 @ 70
- 70, 15, // 18 @ 88
+ 52, 15, // 18 @ 70
+ 70, 15, // 18 @ 88
120, // *mask bit*
- 88, 15, // 18 @ 106
- -7, -2, // 17 @ 11
+ 88, 15, // 18 @ 106
+ -7, -2, // 17 @ 11
-28, -9, // 10 @ 4086
- -123, 21, 0, 44,
- -122, 1, // 4 @ 152
- -4, // *mask bit*
- 104, 15, // 18 @ 122
- -24, -13, 40, -98, 32,
- 78, 102, -67, -1, -2, -30, 64, 40, -67, -113, -73, 116, -98,
- -85, 2, 66, 123, 9, 109, -85, 2, -89, 14, -56, -69, -83, -79,
- -34, -3, 120, 110, 75, -9, -10, 20, -6, -25, -12, 22, -21, -16,
- -12, -81, 67, 1, -128, -70, -21, -16, 84, -21, -16, 70, 0, 23,
- -21, -16, 76, 47, -40, 79, 1, -44, -21, -16, 32, 3, 18, 12, 17,
- -43, -68, 17, 16, -8, 21, 22, -1, -21, -16, -84, -1, -35, 79,
- -9, -10, 96, 0, 46, -21, -16, 44, -39, -41, 79, 1, 119, -13,
- -16, -106, -13, -16, 84, 0, 125, 26, -21, -16, 68, -38, 79, 1,
- 17, 10, 0, -97, 50, 10, 0, 0, -42, -108, 15, 118, 31, 0, -3, 29,
- -21, -16, -100, -25, 79, 1, -18, 97, -36, 76, 16, -21, -16, 86,
- 0, 36, -5, 1, -5, 79, 63, 1, -124, 98, 0, 0, 28, 3, 20, -34, -3,
- 125, 33, -21, -16, 100, -4, 79, 1, -92, -91, 16, -22, 24, 19, 41,
- -21, -16, -44, -59, 16, 108, 100, 0, -21, 0, 71, -105, 18, 39, 85,
- 17, -3, 79, 1, 95, -108, 113, 0, 0, 104, 3, 18, 49, 49, 17, -1, 64,
- 85, 1, 0, 114, 0, 0, -93, -36, -21, -16, 100, 31, 0, 0, -40, -21,
- -16, -92, 66, 127, 85, 1, 98, 119, 0, 0, -48, 79, 18, -3, 50, -17,
- 1, 67, 85, 1, 81, -127, 0, -41, 0, 14, 6, 4, 17, 63, -63, 17, 68,
- 85, -65, 1, 30, -120, 0, 0, 42, 79, 18, 68, 126, -21, -16, -76, 69,
+ -123, 21, 0, 44,
+ -122, 1, // 4 @ 152
+ -4, // *mask bit*
+ 104, 15, // 18 @ 122
+ -24, -13, 40, -98, 32,
+ 78, 102, -67, -1, -2, -30, 64, 40, -67, -113, -73, 116, -98,
+ -85, 2, 66, 123, 9, 109, -85, 2, -89, 14, -56, -69, -83, -79,
+ -34, -3, 120, 110, 75, -9, -10, 20, -6, -25, -12, 22, -21, -16,
+ -12, -81, 67, 1, -128, -70, -21, -16, 84, -21, -16, 70, 0, 23,
+ -21, -16, 76, 47, -40, 79, 1, -44, -21, -16, 32, 3, 18, 12, 17,
+ -43, -68, 17, 16, -8, 21, 22, -1, -21, -16, -84, -1, -35, 79,
+ -9, -10, 96, 0, 46, -21, -16, 44, -39, -41, 79, 1, 119, -13,
+ -16, -106, -13, -16, 84, 0, 125, 26, -21, -16, 68, -38, 79, 1,
+ 17, 10, 0, -97, 50, 10, 0, 0, -42, -108, 15, 118, 31, 0, -3, 29,
+ -21, -16, -100, -25, 79, 1, -18, 97, -36, 76, 16, -21, -16, 86,
+ 0, 36, -5, 1, -5, 79, 63, 1, -124, 98, 0, 0, 28, 3, 20, -34, -3,
+ 125, 33, -21, -16, 100, -4, 79, 1, -92, -91, 16, -22, 24, 19, 41,
+ -21, -16, -44, -59, 16, 108, 100, 0, -21, 0, 71, -105, 18, 39, 85,
+ 17, -3, 79, 1, 95, -108, 113, 0, 0, 104, 3, 18, 49, 49, 17, -1, 64,
+ 85, 1, 0, 114, 0, 0, -93, -36, -21, -16, 100, 31, 0, 0, -40, -21,
+ -16, -92, 66, 127, 85, 1, 98, 119, 0, 0, -48, 79, 18, -3, 50, -17,
+ 1, 67, 85, 1, 81, -127, 0, -41, 0, 14, 6, 4, 17, 63, -63, 17, 68,
+ 85, -65, 1, 30, -120, 0, 0, 42, 79, 18, 68, 126, -21, -16, -76, 69,
85, 1, 102, -119, 72, 37, 0, 97, 33 };
public static final byte[] testTrailerDecomp = new byte[] {
- -60, 2, 0, 0, 0, 1, 0, 0, -72, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0,
- 0, 9, 0, 0, 0, 103, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- -123, 21, 0, 44, -123, 21, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, -98, 32, 78, 102, -67,
- -2, -30, 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, 40, 66,
- 123, 9, 109, -67, -2, -30, 64, 40, -98, 32, 78, 102, -67, -2, -30,
- 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, -56, -83, -79, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 110, 75, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, -12, -81, 67,
- 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0, 23, 0, 0, 0, 76, -40, 79, 1,
- -44, 0, 0, 0, 32, 0, 0, 0, 84, 0, 23, 0, 0, 0, -68, -40, 79, 1, -8,
- 0, 0, 0, 32, 0, 0, 0, 84, 0, -1, 0, 0, 0, -84, -1, 79, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 96, 0, 46, 0, 0, 0, 44, -39, 79, 1, 119, 1, 0, 0,
- -106, 1, 0, 0, 84, 0, 26, 0, 0, 0, 68, -38, 79, 1, 17, 3, 0, 0,
- 50, 10, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 29, 0, 0, 0, -100, -25, 79, 1, -18, 97, 0, 0, -106, 0, 0, 0, 86, 0,
- 36, 0, 0, 0, -12, -5, 79, 1, -124, 98, 0, 0, 28, 0, 0, 0, 84, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 100,
- -4, 79, 1, -92, 98, 0, 0, 32, 0, 0, 0, 84, 0, 41, 0, 0, 0, -44, -4,
- 79, 1, 108, 100, 0, 0, 71, 0, 0, 0, 86, 0, 39, 0, 0, 0, 68, -3, 79,
- 1, -108, 113, 0, 0, 104, 0, 0, 0, 84, 0, 49, 0, 0, 0, -84, 64, 85,
- 1, 0, 114, 0, 0, -93, 0, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, -40, 0, 0, 0, -92, 66, 85, 1, 98, 119,
- 0, 0, -48, 1, 0, 0, 84, 0, 50, 0, 0, 0, 20, 67, 85, 1, 81, -127,
- 0, 0, 14, 6, 0, 0, 84, 0, 63, 0, 0, 0, 100, 68, 85, 1, 30, -120,
- 0, 0, 42, 1, 0, 0, 84, 0, 68, 0, 0, 0, -76, 69, 85, 1, 102, -119,
+ -60, 2, 0, 0, 0, 1, 0, 0, -72, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0,
+ 0, 9, 0, 0, 0, 103, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ -123, 21, 0, 44, -123, 21, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, -98, 32, 78, 102, -67,
+ -2, -30, 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, 40, 66,
+ 123, 9, 109, -67, -2, -30, 64, 40, -98, 32, 78, 102, -67, -2, -30,
+ 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, -56, -83, -79, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 110, 75, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, -12, -81, 67,
+ 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0, 23, 0, 0, 0, 76, -40, 79, 1,
+ -44, 0, 0, 0, 32, 0, 0, 0, 84, 0, 23, 0, 0, 0, -68, -40, 79, 1, -8,
+ 0, 0, 0, 32, 0, 0, 0, 84, 0, -1, 0, 0, 0, -84, -1, 79, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 96, 0, 46, 0, 0, 0, 44, -39, 79, 1, 119, 1, 0, 0,
+ -106, 1, 0, 0, 84, 0, 26, 0, 0, 0, 68, -38, 79, 1, 17, 3, 0, 0,
+ 50, 10, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 29, 0, 0, 0, -100, -25, 79, 1, -18, 97, 0, 0, -106, 0, 0, 0, 86, 0,
+ 36, 0, 0, 0, -12, -5, 79, 1, -124, 98, 0, 0, 28, 0, 0, 0, 84, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 100,
+ -4, 79, 1, -92, 98, 0, 0, 32, 0, 0, 0, 84, 0, 41, 0, 0, 0, -44, -4,
+ 79, 1, 108, 100, 0, 0, 71, 0, 0, 0, 86, 0, 39, 0, 0, 0, 68, -3, 79,
+ 1, -108, 113, 0, 0, 104, 0, 0, 0, 84, 0, 49, 0, 0, 0, -84, 64, 85,
+ 1, 0, 114, 0, 0, -93, 0, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, -40, 0, 0, 0, -92, 66, 85, 1, 98, 119,
+ 0, 0, -48, 1, 0, 0, 84, 0, 50, 0, 0, 0, 20, 67, 85, 1, 81, -127,
+ 0, 0, 14, 6, 0, 0, 84, 0, 63, 0, 0, 0, 100, 68, 85, 1, 30, -120,
+ 0, 0, 42, 1, 0, 0, 84, 0, 68, 0, 0, 0, -76, 69, 85, 1, 102, -119,
0, 0, 42, 1, 0, 0, 84, 0, 0, 0, 0, 0
};
-
+
public void testFromToInt() throws Exception {
byte b255 = -1;
assertEquals(255, HDGFLZW.fromByte(b255));
assertEquals(-1, HDGFLZW.fromInt( HDGFLZW.fromByte(b255) ));
assertEquals(-1, HDGFLZW.fromInt( 255 ));
-
+
byte b11 = 11;
assertEquals(11, HDGFLZW.fromByte(b11));
assertEquals(11, HDGFLZW.fromInt( HDGFLZW.fromByte(b11) ));
assertEquals(11, HDGFLZW.fromInt( 11 ));
-
+
byte b0 = 0;
assertEquals(0, HDGFLZW.fromByte(b0));
assertEquals(0, HDGFLZW.fromInt( HDGFLZW.fromByte(b0) ));
assertEquals(0, HDGFLZW.fromInt( 0 ));
-
+
byte b127 = 127;
assertEquals(127, HDGFLZW.fromByte(b127));
assertEquals(127, HDGFLZW.fromInt( HDGFLZW.fromByte(b127) ));
assertEquals(127, HDGFLZW.fromInt( 127 ));
-
+
byte b128 = -128;
assertEquals(128, HDGFLZW.fromByte(b128));
assertEquals(-128, HDGFLZW.fromInt( HDGFLZW.fromByte(b128) ));
assertEquals(-128, HDGFLZW.fromInt( 128 ));
}
-
+
public void testCounts() throws Exception {
assertEquals(339, testTrailerComp.length);
assertEquals(632, testTrailerDecomp.length);
-
+
// Decode it using our engine
HDGFLZW lzw = new HDGFLZW();
byte[] dec = lzw.decode(new ByteArrayInputStream(testTrailerComp));
-
+
// Check it's of the right size
assertEquals(632, dec.length);
-/*
+/*
// Encode it again using our engine
byte[] comp = lzw.compress(new ByteArrayInputStream(testTrailerDecomp));
-
+
// Check it's of the right size
assertEquals(339, comp.length);
*/
}
-
+
public void testDecompress() throws Exception {
assertEquals(339, testTrailerComp.length);
assertEquals(632, testTrailerDecomp.length);
-
+
// Decode it using our engine
HDGFLZW lzw = new HDGFLZW();
byte[] dec = lzw.decode(new ByteArrayInputStream(testTrailerComp));
-
+
// Now check it's the right data
assertEquals(632, dec.length);
for(int i=0; i<dec.length; i++) {
- if(dec[i] != testTrailerDecomp[i])
+ if(dec[i] != testTrailerDecomp[i])
System.err.println(i + "\t" + dec[i] + "\t" + testTrailerDecomp[i]);
}
}
-
+
public void DISABLEDtestCompress() throws Exception {
assertEquals(339, testTrailerComp.length);
assertEquals(632, testTrailerDecomp.length);
-
+
// Compress it using our engine
HDGFLZW lzw = new HDGFLZW();
byte[] comp = lzw.compress(new ByteArrayInputStream(testTrailerDecomp));
-
+
// Now check it's the right data
assertEquals(339, comp.length);
for(int i=0; i<comp.length; i++) {
- if(comp[i] != testTrailerComp[i])
+ if(comp[i] != testTrailerComp[i])
System.err.println(i + "\t" + comp[i] + "\t" + testTrailerComp[i]);
}
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.chunks;
import junit.framework.TestCase;
-public class TestChunks extends TestCase {
+public final class TestChunks extends TestCase {
public static final byte[] data_a = new byte[] { 70, 0, 0, 0,
- -1, -1, -1, -1, 2, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0,
- 0, 0, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0,
- 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0,
- 0, 36, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
- 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, -110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- -124, 0, 0, 0, 2, 0, 85, 73, 0, 0, 0, 0, 0, 0, -56, 63, 73, 0, 0, 0,
- 0, 0, 0, -64, 63, 63, 0, 0, 0, 0, 0, 0, -64, 63, 63, 0, 0, 0, 0, 0, 0,
- -64, -65, 73, 0, 0, 0, 0, 0, 0, -16, 63, 73, 0, 0, 0, 0, 0, 0, -16, 63,
- 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, -1, 3, 0, 0, 32, 0, 0, 0, 0, 0, -73, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
- 79, 0, 0, 0, 2, 0, 85, 32, 32, 64, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0,
- 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 8, 65, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0,
- 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 1, -13, 15, 0, 0, 0, 0,
- -56, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 2, 0, 85, 63, 0, 0,
- 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0,
- 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 0, 0, 0, 0, 0, 0, -16, 63,
- 0, 0, 0, 0, 0, 0, -16, 63, 1, 0, 1, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0,
- 0, 1, -1, 15, 7, 0, 0, 0, 0, 101, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 28,
- 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- -125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 2, 0, 85, 5, 0, 0,
+ -1, -1, -1, -1, 2, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0,
+ 0, 0, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0,
+ 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0,
+ 0, 36, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, -110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ -124, 0, 0, 0, 2, 0, 85, 73, 0, 0, 0, 0, 0, 0, -56, 63, 73, 0, 0, 0,
+ 0, 0, 0, -64, 63, 63, 0, 0, 0, 0, 0, 0, -64, 63, 63, 0, 0, 0, 0, 0, 0,
+ -64, -65, 73, 0, 0, 0, 0, 0, 0, -16, 63, 73, 0, 0, 0, 0, 0, 0, -16, 63,
+ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, -1, 3, 0, 0, 32, 0, 0, 0, 0, 0, -73, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 79, 0, 0, 0, 2, 0, 85, 32, 32, 64, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0,
+ 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
+ 8, 8, 65, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0,
+ 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 1, -13, 15, 0, 0, 0, 0,
+ -56, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 2, 0, 85, 63, 0, 0,
+ 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0,
+ 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 0, 0, 0, 0, 0, 0, -16, 63,
+ 0, 0, 0, 0, 0, 0, -16, 63, 1, 0, 1, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0,
+ 0, 1, -1, 15, 7, 0, 0, 0, 0, 101, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 28,
+ 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ -125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 2, 0, 85, 5, 0, 0,
0, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
public static final byte[] data_b = new byte[] { 70, 0, 0, 0,
- -1, -1, -1, -1, 3, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0,
- 0, 0, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, 3, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0,
+ 0, 0, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1,
0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0,
- 0, 2, 0, 0, 0, 32, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 0, 0, 0, 0, 0, 0, 0, -110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -124,
- 0, 0, 0, 2, 0, 85, 63, 0, 0, 0, 0, 0, 0, 33, 64, 63, 0, 0, 0, 0, 0, 0,
- 38, 64, 63, 0, 0, 0, 0, 0, 0, -64, 63, 63, 0, 0, 0, 0, 0, 0, -64, -65,
- 73, 0, 0, 0, 0, 0, 0, -16, 63, 73, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 3,
- 0, 4, 32, 0, 0, 0, 0, 0, -56, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0,
- 0, 2, 0, 85, 63, 0, 0, 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48,
- 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 0, 0,
- 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, -16, 63, 1, 0, 1, 0, 0, 1, 1, 0,
- 7, 0, 0, 0, 0, 0, 0, 0, 1, -1, 15, 7, 0, 0, 0, 0, 101, 0, 0, 0, 1, 0, 0,
- 0, 1, 0, 0, 0, 28, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, -125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 2, 0,
- 85, 5, 0, 0, 0, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0, -55, 0, 0, 0, 2, 0, 0, 0,
- 0, 0, 0, 0, -122, 0, 0, 0, 1, 0, 80, 1, 0, 0, 0, 60, 0, 0, 0, 60, 0, 0,
- 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 2, 0, 0, 0, 32, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, -110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -124,
+ 0, 0, 0, 2, 0, 85, 63, 0, 0, 0, 0, 0, 0, 33, 64, 63, 0, 0, 0, 0, 0, 0,
+ 38, 64, 63, 0, 0, 0, 0, 0, 0, -64, 63, 63, 0, 0, 0, 0, 0, 0, -64, -65,
+ 73, 0, 0, 0, 0, 0, 0, -16, 63, 73, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 3,
+ 0, 4, 32, 0, 0, 0, 0, 0, -56, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0,
+ 0, 2, 0, 85, 63, 0, 0, 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48,
+ 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 63, 0, 0, 0, 0, 0, 0, -48, 63, 0, 0,
+ 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, -16, 63, 1, 0, 1, 0, 0, 1, 1, 0,
+ 7, 0, 0, 0, 0, 0, 0, 0, 1, -1, 15, 7, 0, 0, 0, 0, 101, 0, 0, 0, 1, 0, 0,
+ 0, 1, 0, 0, 0, 28, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, -125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 2, 0,
+ 85, 5, 0, 0, 0, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0, -55, 0, 0, 0, 2, 0, 0, 0,
+ 0, 0, 0, 0, -122, 0, 0, 0, 1, 0, 80, 1, 0, 0, 0, 60, 0, 0, 0, 60, 0, 0,
+ 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
};
public void testChunkHeaderA() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
- ChunkHeader h =
+ ChunkHeader h =
ChunkHeader.createChunkHeader(11, data_a, 0);
-
+
assertTrue(h instanceof ChunkHeaderV11);
ChunkHeaderV11 header = (ChunkHeaderV11)h;
-
+
assertEquals(70, header.getType());
assertEquals(-1, header.getId());
assertEquals(2, header.getUnknown1());
assertEquals(68, header.getLength());
assertEquals(0, header.getUnknown2());
assertEquals(0, header.getUnknown3());
-
+
assertTrue(header.hasTrailer());
assertTrue(header.hasSeparator());
}
public void testChunkHeaderB() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
- ChunkHeader h =
+ ChunkHeader h =
ChunkHeader.createChunkHeader(11, data_b, 0);
-
+
assertTrue(h instanceof ChunkHeaderV11);
ChunkHeaderV11 header = (ChunkHeaderV11)h;
-
+
assertEquals(70, header.getType());
assertEquals(-1, header.getId());
assertEquals(3, header.getUnknown1());
assertEquals(68, header.getLength());
assertEquals(0, header.getUnknown2());
assertEquals(0, header.getUnknown3());
-
+
assertTrue(header.hasTrailer());
assertTrue(header.hasSeparator());
}
-
+
public void testOneChunk() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
cf.createChunk(data_a, 0);
cf.createChunk(data_b, 0);
-
+
Chunk chunk = cf.createChunk(data_a, 0);
assertNotNull(chunk.getHeader());
assertNotNull(chunk.getTrailer());
assertNotNull(chunk.getSeparator());
-
+
// Should be 19 + length + 8 + 4 big
assertEquals(68, chunk.getHeader().getLength());
assertEquals(68+19+8+4, chunk.getOnDiskSize());
-
+
// Type is 70, or 0x46
assertEquals(70, chunk.getHeader().getType());
assertEquals(0x46, chunk.getHeader().getType());
-
+
// Should have two virtual chunk commands, a
// 10 (page sheet) and an 18
assertEquals(2, chunk.commandDefinitions.length);
assertEquals(0, chunk.getCommands().length);
-
+
assertEquals(10, chunk.commandDefinitions[0].getType());
assertEquals(0, chunk.commandDefinitions[0].getOffset());
assertEquals("PageSheet", chunk.commandDefinitions[0].getName());
-
+
assertEquals(18, chunk.commandDefinitions[1].getType());
assertEquals(0, chunk.commandDefinitions[1].getOffset());
assertEquals("0", chunk.commandDefinitions[1].getName());
}
-
+
public void testAnotherChunk() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
-
+
// Go for the 2nd chunk in the stream
int offset = 0;
Chunk chunk = cf.createChunk(data_b, offset);
offset += chunk.getOnDiskSize();
chunk = cf.createChunk(data_b, offset);
-
+
assertNotNull(chunk.getHeader());
assertNotNull(chunk.getTrailer());
assertNotNull(chunk.getSeparator());
-
+
// Should be 19 + length + 8 + 4 big
assertEquals(32, chunk.getHeader().getLength());
assertEquals(32+19+8+4, chunk.getOnDiskSize());
-
+
// Type is 104, or 0x68
assertEquals(104, chunk.getHeader().getType());
assertEquals(0x68, chunk.getHeader().getType());
-
+
// Should have two virtual chunk commands, a
// 10 (Unknown) and an 18
assertEquals(2, chunk.commandDefinitions.length);
assertEquals(0, chunk.getCommands().length);
-
+
assertEquals(10, chunk.commandDefinitions[0].getType());
assertEquals(0, chunk.commandDefinitions[0].getOffset());
assertEquals("PropList", chunk.commandDefinitions[0].getName());
-
+
assertEquals(18, chunk.commandDefinitions[1].getType());
assertEquals(0, chunk.commandDefinitions[1].getOffset());
assertEquals("0", chunk.commandDefinitions[1].getName());
}
-
+
public void testManyChunks() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
Chunk chunk;
int offset = 0;
-
+
chunk = cf.createChunk(data_a, offset);
assertNotNull(chunk.getHeader());
assertNotNull(chunk.getTrailer());
assertNotNull(chunk.getSeparator());
offset += chunk.getOnDiskSize();
-
+
chunk = cf.createChunk(data_a, offset);
assertNotNull(chunk.getHeader());
assertNotNull(chunk.getTrailer());
assertNotNull(chunk.getSeparator());
offset += chunk.getOnDiskSize();
-
+
// Has a separator but no trailer
chunk = cf.createChunk(data_a, offset);
assertNotNull(chunk.getHeader());
assertNull(chunk.getTrailer());
assertNotNull(chunk.getSeparator());
offset += chunk.getOnDiskSize();
-
+
chunk = cf.createChunk(data_a, offset);
assertNotNull(chunk.getHeader());
assertNull(chunk.getTrailer());
assertNotNull(chunk.getSeparator());
offset += chunk.getOnDiskSize();
-
+
chunk = cf.createChunk(data_a, offset);
assertNotNull(chunk.getHeader());
assertNull(chunk.getTrailer());
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.extractor;
import java.io.ByteArrayOutputStream;
import org.apache.poi.hdgf.HDGFDiagram;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-public class TestVisioExtractor extends TestCase {
+public final class TestVisioExtractor extends TestCase {
private String dirname;
private String defFilename;
protected void setUp() throws Exception {
dirname = System.getProperty("HDGF.testdata.path");
defFilename = dirname + "/Test_Visio-Some_Random_Text.vsd";
}
-
+
/**
* Test the 3 different ways of creating one
*/
public void testCreation() throws Exception {
VisioTextExtractor extractor;
-
+
extractor = new VisioTextExtractor(new FileInputStream(defFilename));
assertNotNull(extractor);
assertNotNull(extractor.getAllText());
assertEquals(3, extractor.getAllText().length);
-
+
extractor = new VisioTextExtractor(
new POIFSFileSystem(
new FileInputStream(defFilename)
assertNotNull(extractor);
assertNotNull(extractor.getAllText());
assertEquals(3, extractor.getAllText().length);
-
+
extractor = new VisioTextExtractor(
new HDGFDiagram(
new POIFSFileSystem(
assertNotNull(extractor.getAllText());
assertEquals(3, extractor.getAllText().length);
}
-
+
public void testExtraction() throws Exception {
VisioTextExtractor extractor =
new VisioTextExtractor(new FileInputStream(defFilename));
-
+
// Check the array fetch
String[] text = extractor.getAllText();
assertNotNull(text);
assertEquals(3, text.length);
-
+
assertEquals("Test View\n", text[0]);
assertEquals("I am a test view\n", text[1]);
assertEquals("Some random text, on a page\n", text[2]);
-
+
// And the all-in fetch
String textS = extractor.getText();
assertEquals("Test View\nI am a test view\nSome random text, on a page\n", textS);
}
-
+
public void testProblemFiles() throws Exception {
File a = new File(dirname, "44594.vsd");
VisioTextExtractor.main(new String[] {a.toString()});
-
+
File b = new File(dirname, "44594-2.vsd");
VisioTextExtractor.main(new String[] {b.toString()});
-
+
File c = new File(dirname, "ShortChunk1.vsd");
VisioTextExtractor.main(new String[] {c.toString()});
-
+
File d = new File(dirname, "ShortChunk2.vsd");
VisioTextExtractor.main(new String[] {d.toString()});
-
+
File e = new File(dirname, "ShortChunk3.vsd");
VisioTextExtractor.main(new String[] {e.toString()});
}
-
+
public void testMain() throws Exception {
PrintStream oldOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream capture = new PrintStream(baos);
System.setOut(capture);
-
+
VisioTextExtractor.main(new String[] {defFilename});
-
+
// Put things back
System.setOut(oldOut);
-
+
// Check
capture.flush();
String text = baos.toString();
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.pointers;
import junit.framework.TestCase;
/**
* Tests for the pointer factory, and the pointers themselves
*/
-public class TestPointerFactory extends TestCase {
+public final class TestPointerFactory extends TestCase {
// Type: 16 Addr: 0143aff4 Offset: 80 Len: 54 Format: 46 From: 8a94
private static byte[] vp6_a = new byte[] {
22, 0, 0, 0, -12, -81, 67, 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0
};
// Type: 17 Addr: 014fd84c Offset: d4 Len: 20 Format: 54 From: 8a94
private static byte[] vp6_b = new byte[] {
- 23, 0, 0, 0, 76, -40, 79, 1, -44, 0, 0, 0, 32, 0, 0, 0, 84, 0
+ 23, 0, 0, 0, 76, -40, 79, 1, -44, 0, 0, 0, 32, 0, 0, 0, 84, 0
};
// Type: 17 Addr: 014fd8bc Offset: f8 Len: 20 Format: 54 From: 8a94
private static byte[] vp6_c = new byte[] {
private static byte[] vp6_d = new byte[] {
-1, 0, 0, 0, -84, -1, 79, 1, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0
};
-
+
public void testCreateV4() throws Exception {
PointerFactory pf = new PointerFactory(4);
try {
// As expected
}
}
-
+
public void testCreateV5() throws Exception {
PointerFactory pf = new PointerFactory(5);
try {
public void testCreateV6() throws Exception {
PointerFactory pf = new PointerFactory(6);
-
+
Pointer a = pf.createPointer(vp6_a, 0);
assertEquals(0x16, a.getType());
assertEquals(0x0143aff4, a.getAddress());
assertEquals(0x80, a.getOffset());
assertEquals(0x54, a.getLength());
assertEquals(0x46, a.getFormat());
-
+
assertTrue(a.destinationCompressed());
assertTrue(a.destinationHasStrings());
assertFalse(a.destinationHasChunks());
assertFalse(a.destinationHasPointers());
-
+
assertEquals(18, a.getSizeInBytes());
-
-
+
+
Pointer b = pf.createPointer(vp6_b, 0);
assertEquals(0x17, b.getType());
assertEquals(0x014fd84c, b.getAddress());
assertEquals(0xd4, b.getOffset());
assertEquals(0x20, b.getLength());
assertEquals(0x54, b.getFormat());
-
+
assertFalse(b.destinationCompressed());
assertFalse(b.destinationHasStrings());
assertFalse(b.destinationHasChunks());
assertTrue(b.destinationHasPointers());
-
+
Pointer c = pf.createPointer(vp6_c, 0);
assertEquals(0x17, c.getType());
assertEquals(0x014fd8bc, c.getAddress());
assertEquals(0xf8, c.getOffset());
assertEquals(0x20, c.getLength());
assertEquals(0x54, c.getFormat());
-
+
assertFalse(c.destinationCompressed());
assertFalse(c.destinationHasStrings());
assertFalse(c.destinationHasChunks());
assertTrue(c.destinationHasPointers());
-
+
// Type: ff Addr: 014fffac Offset: 0 Len: 0 Format: 60 From: 8a94
Pointer d = pf.createPointer(vp6_d, 0);
assertEquals(0xff, d.getType());
assertEquals(0x00, d.getOffset());
assertEquals(0x00, d.getLength());
assertEquals(0x60, d.getFormat());
-
+
assertFalse(d.destinationCompressed());
assertFalse(d.destinationHasStrings());
assertFalse(d.destinationHasChunks());
public void testCreateV6FromMid() throws Exception {
PointerFactory pf = new PointerFactory(11);
-
+
// Create a from part way down the byte stream
byte[] bytes = new byte[28];
System.arraycopy(vp6_b, 0, bytes, 0, 10);
System.arraycopy(vp6_a, 0, bytes, 10, 18);
-
+
Pointer a = pf.createPointer(bytes, 10);
assertEquals(0x16, a.getType());
assertEquals(0x0143aff4, a.getAddress());
assertEquals(0x80, a.getOffset());
assertEquals(0x54, a.getLength());
assertEquals(0x46, a.getFormat());
-
+
assertTrue(a.destinationCompressed());
assertTrue(a.destinationHasStrings());
assertFalse(a.destinationHasChunks());
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import org.apache.poi.hdgf.pointers.Pointer;
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import org.apache.poi.hdgf.pointers.Pointer;
-public class TestStreamBasics extends StreamTest {
+public final class TestStreamBasics extends StreamTest {
/** The header from when compressedStream is decompressed */
public static final byte[] compressedStreamDCHeader = new byte[] {
-60, 2, 0, 0
};
public static final byte[] compressedStream = new byte[] {
- 123, -60, 2, -21, -16, 1, 0, 0, -72, -13, -16, 78, -32, -5, 1,
- 0, 3, -21, -16, 10, 5, 4, -21, -16, 21, 9, -21, -16, 103, -21,
- -16, 34, -36, -1, 52, 15, 70, 15, 120, 88, 15, -7, -2, -28, -9,
- -123, 21, 0, 44, -122, 1, -4, 104, 15, -24, -13, 40, -98, 32,
- 78, 102, -67, -1, -2, -30, 64, 40, -67, -113, -73, 116, -98,
- -85, 2, 66, 123, 9, 109, -85, 2, -89, 14, -56, -69, -83, -79,
- -34, -3, 120, 110, 75, -9, -10, 20, -6, -25, -12, 22, -21, -16,
- -12, -81, 67, 1, -128, -70, -21, -16, 84, -21, -16, 70, 0, 23,
- -21, -16, 76, 47, -40, 79, 1, -44, -21, -16, 32, 3, 18, 12, 17,
- -43, -68, 17, 16, -8, 21, 22, -1, -21, -16, -84, -1, -35, 79,
- -9, -10, 96, 0, 46, -21, -16, 44, -39, -41, 79, 1, 119, -13,
- -16, -106, -13, -16, 84, 0, 125, 26, -21, -16, 68, -38, 79, 1,
- 17, 10, 0, -97, 50, 10, 0, 0, -42, -108, 15, 118, 31, 0, -3, 29,
- -21, -16, -100, -25, 79, 1, -18, 97, -36, 76, 16, -21, -16, 86,
- 0, 36, -5, 1, -5, 79, 63, 1, -124, 98, 0, 0, 28, 3, 20, -34, -3,
- 125, 33, -21, -16, 100, -4, 79, 1, -92, -91, 16, -22, 24, 19, 41,
- -21, -16, -44, -59, 16, 108, 100, 0, -21, 0, 71, -105, 18, 39, 85,
- 17, -3, 79, 1, 95, -108, 113, 0, 0, 104, 3, 18, 49, 49, 17, -1, 64,
- 85, 1, 0, 114, 0, 0, -93, -36, -21, -16, 100, 31, 0, 0, -40, -21,
- -16, -92, 66, 127, 85, 1, 98, 119, 0, 0, -48, 79, 18, -3, 50, -17,
- 1, 67, 85, 1, 81, -127, 0, -41, 0, 14, 6, 4, 17, 63, -63, 17, 68,
- 85, -65, 1, 30, -120, 0, 0, 42, 79, 18, 68, 126, -21, -16, -76, 69,
+ 123, -60, 2, -21, -16, 1, 0, 0, -72, -13, -16, 78, -32, -5, 1,
+ 0, 3, -21, -16, 10, 5, 4, -21, -16, 21, 9, -21, -16, 103, -21,
+ -16, 34, -36, -1, 52, 15, 70, 15, 120, 88, 15, -7, -2, -28, -9,
+ -123, 21, 0, 44, -122, 1, -4, 104, 15, -24, -13, 40, -98, 32,
+ 78, 102, -67, -1, -2, -30, 64, 40, -67, -113, -73, 116, -98,
+ -85, 2, 66, 123, 9, 109, -85, 2, -89, 14, -56, -69, -83, -79,
+ -34, -3, 120, 110, 75, -9, -10, 20, -6, -25, -12, 22, -21, -16,
+ -12, -81, 67, 1, -128, -70, -21, -16, 84, -21, -16, 70, 0, 23,
+ -21, -16, 76, 47, -40, 79, 1, -44, -21, -16, 32, 3, 18, 12, 17,
+ -43, -68, 17, 16, -8, 21, 22, -1, -21, -16, -84, -1, -35, 79,
+ -9, -10, 96, 0, 46, -21, -16, 44, -39, -41, 79, 1, 119, -13,
+ -16, -106, -13, -16, 84, 0, 125, 26, -21, -16, 68, -38, 79, 1,
+ 17, 10, 0, -97, 50, 10, 0, 0, -42, -108, 15, 118, 31, 0, -3, 29,
+ -21, -16, -100, -25, 79, 1, -18, 97, -36, 76, 16, -21, -16, 86,
+ 0, 36, -5, 1, -5, 79, 63, 1, -124, 98, 0, 0, 28, 3, 20, -34, -3,
+ 125, 33, -21, -16, 100, -4, 79, 1, -92, -91, 16, -22, 24, 19, 41,
+ -21, -16, -44, -59, 16, 108, 100, 0, -21, 0, 71, -105, 18, 39, 85,
+ 17, -3, 79, 1, 95, -108, 113, 0, 0, 104, 3, 18, 49, 49, 17, -1, 64,
+ 85, 1, 0, 114, 0, 0, -93, -36, -21, -16, 100, 31, 0, 0, -40, -21,
+ -16, -92, 66, 127, 85, 1, 98, 119, 0, 0, -48, 79, 18, -3, 50, -17,
+ 1, 67, 85, 1, 81, -127, 0, -41, 0, 14, 6, 4, 17, 63, -63, 17, 68,
+ 85, -65, 1, 30, -120, 0, 0, 42, 79, 18, 68, 126, -21, -16, -76, 69,
85, 1, 102, -119, 72, 37, 0, 97, 33 };
public static final byte[] uncompressedStream = new byte[] {
- 0, 1, 0, 0, -72, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0,
- 0, 9, 0, 0, 0, 103, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- -123, 21, 0, 44, -123, 21, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, -98, 32, 78, 102, -67,
- -2, -30, 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, 40, 66,
- 123, 9, 109, -67, -2, -30, 64, 40, -98, 32, 78, 102, -67, -2, -30,
- 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, -56, -83, -79, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 110, 75, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, -12, -81, 67,
- 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0, 23, 0, 0, 0, 76, -40, 79, 1,
- -44, 0, 0, 0, 32, 0, 0, 0, 84, 0, 23, 0, 0, 0, -68, -40, 79, 1, -8,
- 0, 0, 0, 32, 0, 0, 0, 84, 0, -1, 0, 0, 0, -84, -1, 79, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 96, 0, 46, 0, 0, 0, 44, -39, 79, 1, 119, 1, 0, 0,
- -106, 1, 0, 0, 84, 0, 26, 0, 0, 0, 68, -38, 79, 1, 17, 3, 0, 0,
- 50, 10, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 29, 0, 0, 0, -100, -25, 79, 1, -18, 97, 0, 0, -106, 0, 0, 0, 86, 0,
- 36, 0, 0, 0, -12, -5, 79, 1, -124, 98, 0, 0, 28, 0, 0, 0, 84, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 100,
- -4, 79, 1, -92, 98, 0, 0, 32, 0, 0, 0, 84, 0, 41, 0, 0, 0, -44, -4,
- 79, 1, 108, 100, 0, 0, 71, 0, 0, 0, 86, 0, 39, 0, 0, 0, 68, -3, 79,
- 1, -108, 113, 0, 0, 104, 0, 0, 0, 84, 0, 49, 0, 0, 0, -84, 64, 85,
- 1, 0, 114, 0, 0, -93, 0, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, -40, 0, 0, 0, -92, 66, 85, 1, 98, 119,
- 0, 0, -48, 1, 0, 0, 84, 0, 50, 0, 0, 0, 20, 67, 85, 1, 81, -127,
- 0, 0, 14, 6, 0, 0, 84, 0, 63, 0, 0, 0, 100, 68, 85, 1, 30, -120,
- 0, 0, 42, 1, 0, 0, 84, 0, 68, 0, 0, 0, -76, 69, 85, 1, 102, -119,
+ 0, 1, 0, 0, -72, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0,
+ 0, 9, 0, 0, 0, 103, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ -123, 21, 0, 44, -123, 21, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, -98, 32, 78, 102, -67,
+ -2, -30, 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, 40, 66,
+ 123, 9, 109, -67, -2, -30, 64, 40, -98, 32, 78, 102, -67, -2, -30,
+ 64, 40, -67, -113, -73, 116, -67, -2, -30, 64, -56, -83, -79, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 110, 75, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, -12, -81, 67,
+ 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0, 23, 0, 0, 0, 76, -40, 79, 1,
+ -44, 0, 0, 0, 32, 0, 0, 0, 84, 0, 23, 0, 0, 0, -68, -40, 79, 1, -8,
+ 0, 0, 0, 32, 0, 0, 0, 84, 0, -1, 0, 0, 0, -84, -1, 79, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 96, 0, 46, 0, 0, 0, 44, -39, 79, 1, 119, 1, 0, 0,
+ -106, 1, 0, 0, 84, 0, 26, 0, 0, 0, 68, -38, 79, 1, 17, 3, 0, 0,
+ 50, 10, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 29, 0, 0, 0, -100, -25, 79, 1, -18, 97, 0, 0, -106, 0, 0, 0, 86, 0,
+ 36, 0, 0, 0, -12, -5, 79, 1, -124, 98, 0, 0, 28, 0, 0, 0, 84, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 100,
+ -4, 79, 1, -92, 98, 0, 0, 32, 0, 0, 0, 84, 0, 41, 0, 0, 0, -44, -4,
+ 79, 1, 108, 100, 0, 0, 71, 0, 0, 0, 86, 0, 39, 0, 0, 0, 68, -3, 79,
+ 1, -108, 113, 0, 0, 104, 0, 0, 0, 84, 0, 49, 0, 0, 0, -84, 64, 85,
+ 1, 0, 114, 0, 0, -93, 0, 0, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, -40, 0, 0, 0, -92, 66, 85, 1, 98, 119,
+ 0, 0, -48, 1, 0, 0, 84, 0, 50, 0, 0, 0, 20, 67, 85, 1, 81, -127,
+ 0, 0, 14, 6, 0, 0, 84, 0, 63, 0, 0, 0, 100, 68, 85, 1, 30, -120,
+ 0, 0, 42, 1, 0, 0, 84, 0, 68, 0, 0, 0, -76, 69, 85, 1, 102, -119,
0, 0, 42, 1, 0, 0, 84, 0, 0, 0, 0, 0
};
Pointer ptr = new TestPointer(true, 0, compressedStream.length, -1, (short)-1);
// Now the stream
Stream stream = Stream.createStream(ptr, compressedStream, null, null);
-
+
// Check
assertNotNull(stream.getPointer());
assertNotNull(stream.getStore());
assertTrue(stream.getStore() instanceof StreamStore);
assertTrue(stream.getStore() instanceof CompressedStreamStore);
assertTrue(stream instanceof UnknownStream);
-
+
// Check the stream store
CompressedStreamStore ss = (CompressedStreamStore)stream.getStore();
assertEquals(4, ss._getBlockHeader().length);
assertEquals(compressedStream.length, ss._getCompressedContents().length);
assertEquals(uncompressedStream.length, ss.getContents().length);
-
+
for(int i=0; i<uncompressedStream.length; i++) {
assertEquals(uncompressedStream[i], ss.getContents()[i]);
}
}
-
+
public void testUncompressedStream() {
// Create a fake pointer
Pointer ptr = new TestPointer(false, 0, uncompressedStream.length, -1, (short)-1);
// Now the stream
Stream stream = Stream.createStream(ptr, uncompressedStream, null, null);
-
+
// Check
assertNotNull(stream.getPointer());
assertNotNull(stream.getStore());
assertFalse(stream.getStore() instanceof CompressedStreamStore);
assertTrue(stream instanceof UnknownStream);
}
-}
\ No newline at end of file
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import java.io.FileInputStream;
/**
* Tests for bugs with streams
*/
-public class TestStreamBugs extends StreamTest {
+public final class TestStreamBugs extends StreamTest {
private byte[] contents;
private ChunkFactory chunkFactory;
private PointerFactory ptrFactory;
FileInputStream fin = new FileInputStream(filename);
filesystem = new POIFSFileSystem(fin);
-
+
DocumentEntry docProps =
(DocumentEntry)filesystem.getRoot().getEntry("VisioDocument");
contents = new byte[docProps.getSize()];
filesystem.createDocumentInputStream("VisioDocument").read(contents);
}
-
+
public void testGetTrailer() throws Exception {
Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);
}
-
+
public void TOIMPLEMENTtestGetCertainChunks() throws Exception {
int offsetA = 3708;
int offsetB = 3744;
}
-
+
public void testGetChildren() throws Exception {
Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
TrailerStream trailer = (TrailerStream)
Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);
-
+
// Get without recursing
Pointer[] ptrs = trailer.getChildPointers();
for(int i=0; i<ptrs.length; i++) {
Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
}
-
+
// Get with recursing into chunks
for(int i=0; i<ptrs.length; i++) {
- Stream stream =
+ Stream stream =
Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
if(stream instanceof ChunkStream) {
ChunkStream cStream = (ChunkStream)stream;
cStream.findChunks();
}
}
-
+
// Get with recursing into chunks and pointers
for(int i=0; i<ptrs.length; i++) {
- Stream stream =
+ Stream stream =
Stream.createStream(ptrs[i], contents, chunkFactory, ptrFactory);
if(stream instanceof PointerContainingStream) {
PointerContainingStream pStream =
pStream.findChildren(contents);
}
}
-
+
trailer.findChildren(contents);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hdgf.streams;
import java.io.FileInputStream;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-public class TestStreamComplex extends StreamTest {
+public final class TestStreamComplex extends StreamTest {
private byte[] contents;
private int trailerPointerAt = 0x24;
private int trailerDataAt = 0x8a94;
FileInputStream fin = new FileInputStream(filename);
POIFSFileSystem filesystem = new POIFSFileSystem(fin);
-
+
DocumentEntry docProps =
(DocumentEntry)filesystem.getRoot().getEntry("VisioDocument");
public void testTrailer() {
// Find the trailer
Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
-
+
assertEquals(20, trailerPtr.getType());
assertEquals(trailerDataAt, trailerPtr.getOffset());
-
+
Stream stream = Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
assertTrue(stream instanceof TrailerStream);
TrailerStream ts = (TrailerStream)stream;
-
+
assertNotNull(ts.getChildPointers());
assertNull(ts.getPointedToStreams());
-
+
assertEquals(20, ts.getChildPointers().length);
assertEquals(0x16, ts.getChildPointers()[0].getType());
assertEquals(0x17, ts.getChildPointers()[1].getType());
assertEquals(0x17, ts.getChildPointers()[2].getType());
assertEquals(0xff, ts.getChildPointers()[3].getType());
}
-
+
public void testChunks() {
Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
TrailerStream ts = (TrailerStream)
Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
-
+
// Should be 7th one
Pointer chunkPtr = ts.getChildPointers()[5];
assertFalse(chunkPtr.destinationHasStrings());
assertTrue(chunkPtr.destinationHasChunks());
assertFalse(chunkPtr.destinationHasPointers());
-
+
Stream stream = Stream.createStream(chunkPtr, contents, chunkFactory, ptrFactory);
assertNotNull(stream);
assertTrue(stream instanceof ChunkStream);
-
+
// Now find the chunks within it
ChunkStream cs = (ChunkStream)stream;
cs.findChunks();
}
-
+
public void testStrings() {
Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
TrailerStream ts = (TrailerStream)
Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
-
+
// Should be the 1st one
Pointer stringPtr = ts.getChildPointers()[0];
assertTrue(stringPtr.destinationHasStrings());
assertFalse(stringPtr.destinationHasChunks());
assertFalse(stringPtr.destinationHasPointers());
-
+
Stream stream = Stream.createStream(stringPtr, contents, chunkFactory, ptrFactory);
assertNotNull(stream);
assertTrue(stream instanceof StringsStream);
}
-
+
public void testPointerToStrings() {
// The stream at 0x347f has strings
// The stream at 0x4312 has a pointer to 0x347f
// The stream at 0x44d3 has a pointer to 0x4312
// (it's the 2nd one of 3, and the block is compressed)
-
+
TestPointer ptr44d3 = new TestPointer(true, 0x44d3, 0x51, 0x4e, (short)0x56);
ptr44d3.hasPointers = true;
PointerContainingStream s44d3 = (PointerContainingStream)
Stream.createStream(ptr44d3, contents, chunkFactory, ptrFactory);
-
+
// Type: 0d Addr: 014ff644 Offset: 4312 Len: 48 Format: 54 From: 44d3
Pointer ptr4312 = s44d3.getChildPointers()[1];
assertEquals(0x0d, ptr4312.getType());
assertEquals(0x54, ptr4312.getFormat());
assertTrue(ptr4312.destinationHasPointers());
assertFalse(ptr4312.destinationHasStrings());
-
+
PointerContainingStream s4312 = (PointerContainingStream)
Stream.createStream(ptr4312, contents, chunkFactory, ptrFactory);
-
+
// Check it has 0x347f
// Type: 1f Addr: 01540004 Offset: 347f Len: 8e8 Format: 46 From: 4312
assertEquals(2, s4312.getChildPointers().length);
assertEquals(0x46, ptr347f.getFormat());
assertFalse(ptr347f.destinationHasPointers());
assertTrue(ptr347f.destinationHasStrings());
-
+
// Find the children of 0x4312
assertNull(s4312.getPointedToStreams());
s4312.findChildren(contents);
assertTrue(s4312.getPointedToStreams()[0] instanceof StringsStream);
assertTrue(s4312.getPointedToStreams()[1] instanceof StringsStream);
}
-
+
public void testTrailerContents() {
Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
TrailerStream ts = (TrailerStream)
Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
-
+
assertNotNull(ts.getChildPointers());
assertNull(ts.getPointedToStreams());
assertEquals(20, ts.getChildPointers().length);
-
+
ts.findChildren(contents);
-
+
assertNotNull(ts.getChildPointers());
assertNotNull(ts.getPointedToStreams());
assertEquals(20, ts.getChildPointers().length);
assertEquals(20, ts.getPointedToStreams().length);
-
+
// Step down:
// 8 -> 4 -> 5 -> 1 -> 0 == String
assertNotNull(ts.getPointedToStreams()[8]);
assertTrue(ts.getPointedToStreams()[8] instanceof PointerContainingStream);
-
- PointerContainingStream s8 =
+
+ PointerContainingStream s8 =
(PointerContainingStream)ts.getPointedToStreams()[8];
assertNotNull(s8.getPointedToStreams());
-
+
assertNotNull(s8.getPointedToStreams()[4]);
assertTrue(s8.getPointedToStreams()[4] instanceof PointerContainingStream);
-
- PointerContainingStream s84 =
+
+ PointerContainingStream s84 =
(PointerContainingStream)s8.getPointedToStreams()[4];
assertNotNull(s84.getPointedToStreams());
-
+
assertNotNull(s84.getPointedToStreams()[5]);
assertTrue(s84.getPointedToStreams()[5] instanceof PointerContainingStream);
-
- PointerContainingStream s845 =
+
+ PointerContainingStream s845 =
(PointerContainingStream)s84.getPointedToStreams()[5];
assertNotNull(s845.getPointedToStreams());
-
+
assertNotNull(s845.getPointedToStreams()[1]);
assertTrue(s845.getPointedToStreams()[1] instanceof PointerContainingStream);
-
- PointerContainingStream s8451 =
+
+ PointerContainingStream s8451 =
(PointerContainingStream)s845.getPointedToStreams()[1];
assertNotNull(s8451.getPointedToStreams());
-
+
assertNotNull(s8451.getPointedToStreams()[0]);
assertTrue(s8451.getPointedToStreams()[0] instanceof StringsStream);
assertTrue(s8451.getPointedToStreams()[1] instanceof StringsStream);
}
-
+
public void testChunkWithText() throws Exception {
// Parent ChunkStream is at 0x7194
// This is one of the last children of the trailer
Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
TrailerStream ts = (TrailerStream)
Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
-
+
ts.findChildren(contents);
-
+
assertNotNull(ts.getChildPointers());
assertNotNull(ts.getPointedToStreams());
assertEquals(20, ts.getChildPointers().length);
assertEquals(20, ts.getPointedToStreams().length);
-
+
assertEquals(0x7194, ts.getChildPointers()[13].getOffset());
assertEquals(0x7194, ts.getPointedToStreams()[13].getPointer().getOffset());
-
+
PointerContainingStream ps7194 = (PointerContainingStream)
ts.getPointedToStreams()[13];
-
+
// First child is at 0x64b3
assertEquals(0x64b3, ps7194.getChildPointers()[0].getOffset());
assertEquals(0x64b3, ps7194.getPointedToStreams()[0].getPointer().getOffset());
-
+
ChunkStream cs = (ChunkStream)ps7194.getPointedToStreams()[0];
-
+
// Should be 26bc bytes un-compressed
assertEquals(0x26bc, cs.getStore().getContents().length);
// And should have lots of children
assertEquals(131, cs.getChunks().length);
-
+
// One of which is Text
boolean hasText = false;
for(int i=0; i<cs.getChunks().length; i++) {
assertTrue(hasText);
// Which is the 72nd command
assertEquals("Text", cs.getChunks()[72].getName());
-
+
Chunk text = cs.getChunks()[72];
assertEquals("Text", text.getName());
-
+
// Which contains our text
assertEquals(1, text.getCommands().length);
assertEquals("Test View\n", text.getCommands()[0].getValue());
-
-
+
+
// Almost at the end is some more text
assertEquals("Text", cs.getChunks()[128].getName());
text = cs.getChunks()[128];
assertEquals("Text", text.getName());
-
+
assertEquals(1, text.getCommands().length);
assertEquals("Some random text, on a page\n", text.getCommands()[0].getValue());
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf;
import java.io.File;
import junit.framework.TestCase;
-public class TestHPBFDocument extends TestCase {
+public final class TestHPBFDocument extends TestCase {
private String dir;
protected void setUp() throws Exception {
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
-
+
assertNotNull(doc);
}
-
+
public void testBits() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument(
assertNotNull(doc.getQuillContents());
assertNotNull(doc.getEscherStm());
assertNotNull(doc.getEscherDelayStm());
-
+
assertTrue(doc.getMainContents().getData().length > 0);
assertTrue(doc.getQuillContents().getData().length > 0);
assertTrue(doc.getEscherStm().getData().length > 0);
assertTrue(doc.getEscherDelayStm().getData().length == 0);
}
-
+
// TODO
// public void testWrite() throws Exception {
// }
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.extractor;
import java.io.File;
import junit.framework.TestCase;
-public class TextPublisherTextExtractor extends TestCase {
+public final class TextPublisherTextExtractor extends TestCase {
private String dir;
protected void setUp() throws Exception {
new FileInputStream(f)
);
- PublisherTextExtractor ext =
+ PublisherTextExtractor ext =
new PublisherTextExtractor(doc);
ext.getText();
-
+
f = new File(dir, "Simple.pub");
ext = new PublisherTextExtractor(
new FileInputStream(f)
);
ext.getText();
}
-
+
public void testContents() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
- PublisherTextExtractor ext =
+ PublisherTextExtractor ext =
new PublisherTextExtractor(doc);
String text = ext.getText();
-
+
assertEquals(
"This is some text on the first page\n" +
"It\u2019s in times new roman, font size 10, all normal\n" +
"Within doc to page 1\n"
, text
);
-
+
// Now a simpler one
f = new File(dir, "Simple.pub");
ext = new PublisherTextExtractor(
, text
);
}
-
+
/**
* We have the same file saved for Publisher 98, Publisher
* 2000 and Publisher 2007. Check they all agree.
public void testMultipleVersions() throws Exception {
File f;
HPBFDocument doc;
-
+
f = new File(dir, "Sample.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
String s2007 = (new PublisherTextExtractor(doc)).getText();
-
+
f = new File(dir, "Sample2000.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
String s2000 = (new PublisherTextExtractor(doc)).getText();
-
+
f = new File(dir, "Sample98.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
String s98 = (new PublisherTextExtractor(doc)).getText();
-
+
// Check they all agree
assertEquals(s2007, s2000);
assertEquals(s2007, s98);
}
-
+
/**
* Test that the hyperlink extraction stuff works as well
* as we can hope it to.
new FileInputStream(f)
);
- PublisherTextExtractor ext =
+ PublisherTextExtractor ext =
new PublisherTextExtractor(doc);
ext.getText();
-
+
// Default is no hyperlinks
assertEquals("1234567890LINK\n", ext.getText());
-
+
// Turn on
ext.setHyperlinksByDefault(true);
assertEquals("1234567890LINK\n<http://poi.apache.org/>\n", ext.getText());
-
-
+
+
// Now a much more complex document
f = new File(dir, "Sample.pub");
ext = new PublisherTextExtractor(new FileInputStream(f));
ext.setHyperlinksByDefault(true);
String text = ext.getText();
-
+
assertTrue(text.endsWith(
"<http://poi.apache.org/>\n" +
"<C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx>\n" +
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model;
import java.io.File;
import junit.framework.TestCase;
-public class TestEscherParts extends TestCase {
+public final class TestEscherParts extends TestCase {
private String dir;
protected void setUp() throws Exception {
EscherStm es = doc.getEscherStm();
EscherDelayStm eds = doc.getEscherDelayStm();
-
+
assertNotNull(es);
assertNotNull(eds);
-
+
assertEquals(13, es.getEscherRecords().length);
assertEquals(0, eds.getEscherRecords().length);
-
+
// TODO - check the contents
}
-
+
public void testComplex() throws Exception {
File f = new File(dir, "SampleBrochure.pub");
HPBFDocument doc = new HPBFDocument(
EscherStm es = doc.getEscherStm();
EscherDelayStm eds = doc.getEscherDelayStm();
-
+
assertNotNull(es);
assertNotNull(eds);
-
+
assertEquals(30, es.getEscherRecords().length);
assertEquals(19, eds.getEscherRecords().length);
-
+
// TODO - check contents
-
-
+
+
// Now do another complex file
f = new File(dir, "SampleNewsletter.pub");
doc = new HPBFDocument(
es = doc.getEscherStm();
eds = doc.getEscherDelayStm();
-
+
assertNotNull(es);
assertNotNull(eds);
-
+
assertEquals(51, es.getEscherRecords().length);
assertEquals(92, eds.getEscherRecords().length);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hpbf.model;
import java.io.File;
import junit.framework.TestCase;
-public class TestQuillContents extends TestCase {
+public final class TestQuillContents extends TestCase {
private String dir;
protected void setUp() throws Exception {
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
-
+
QuillContents qc = doc.getQuillContents();
assertEquals(20, qc.getBits().length);
for(int i=0; i<19; i++) {
}
// Last one is blank
assertNull(qc.getBits()[19]);
-
+
// Should be text, then three STSHs
assertEquals("TEXT", qc.getBits()[0].getThingType());
assertEquals("TEXT", qc.getBits()[0].getBitType());
assertEquals(0, qc.getBits()[0].getOptA());
-
+
assertEquals("STSH", qc.getBits()[1].getThingType());
assertEquals("STSH", qc.getBits()[1].getBitType());
assertEquals(0, qc.getBits()[1].getOptA());
-
+
assertEquals("STSH", qc.getBits()[2].getThingType());
assertEquals("STSH", qc.getBits()[2].getBitType());
assertEquals(1, qc.getBits()[2].getOptA());
-
+
assertEquals("STSH", qc.getBits()[3].getThingType());
assertEquals("STSH", qc.getBits()[3].getBitType());
assertEquals(2, qc.getBits()[3].getOptA());
}
-
+
public void testText() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
-
+
QuillContents qc = doc.getQuillContents();
assertEquals(20, qc.getBits().length);
-
+
QCTextBit text = (QCTextBit)qc.getBits()[0];
String t = text.getText();
assertTrue(t.startsWith("This is some text on the first page"));
assertTrue(t.endsWith("Within doc to page 1\r"));
}
-
+
public void testPLC() throws Exception {
File f = new File(dir, "Simple.pub");
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
-
+
QuillContents qc = doc.getQuillContents();
assertEquals(20, qc.getBits().length);
-
+
assertTrue(qc.getBits()[9] instanceof Type4);
assertTrue(qc.getBits()[10] instanceof Type4);
assertTrue(qc.getBits()[12] instanceof Type8);
-
+
Type4 plc9 = (Type4)qc.getBits()[9];
Type4 plc10 = (Type4)qc.getBits()[10];
Type8 plc12 = (Type8)qc.getBits()[12];
-
-
+
+
assertEquals(1, plc9.getNumberOfPLCs());
assertEquals(4, plc9.getPreData().length);
assertEquals(1, plc9.getPlcValA().length);
assertEquals(1, plc9.getPlcValB().length);
-
+
assertEquals(0, plc9.getPreData()[0]);
assertEquals(0, plc9.getPreData()[1]);
assertEquals(0, plc9.getPreData()[2]);
assertEquals(0, plc9.getPreData()[3]);
assertEquals(0x356, plc9.getPlcValA()[0]);
assertEquals(0x600, plc9.getPlcValB()[0]);
-
-
+
+
assertEquals(1, plc10.getNumberOfPLCs());
assertEquals(4, plc10.getPreData().length);
assertEquals(1, plc10.getPlcValA().length);
assertEquals(1, plc10.getPlcValB().length);
-
+
assertEquals(0, plc10.getPreData()[0]);
assertEquals(0, plc10.getPreData()[1]);
assertEquals(0, plc10.getPreData()[2]);
assertEquals(0, plc10.getPreData()[3]);
assertEquals(0x356, plc10.getPlcValA()[0]);
assertEquals(0x800, plc10.getPlcValB()[0]);
-
+
assertEquals(2, plc12.getNumberOfPLCs());
assertEquals(7, plc12.getPreData().length);
assertEquals(2, plc12.getPlcValA().length);
assertEquals(2, plc12.getPlcValB().length);
-
+
assertEquals(0xff, plc12.getPreData()[0]);
assertEquals(0, plc12.getPreData()[1]);
assertEquals(0x3d, plc12.getPreData()[2]);
assertEquals(0x05, plc12.getPlcValA()[1]);
assertEquals(0x04, plc12.getPlcValB()[1]);
}
-
+
public void testComplexPLC() throws Exception {
File f = new File(dir, "Sample.pub");
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
-
+
QuillContents qc = doc.getQuillContents();
assertEquals(20, qc.getBits().length);
-
+
assertTrue(qc.getBits()[10] instanceof Type4);
assertTrue(qc.getBits()[11] instanceof Type4);
assertTrue(qc.getBits()[13] instanceof Type0);
assertTrue(qc.getBits()[14] instanceof Type12);
assertTrue(qc.getBits()[15] instanceof Type12);
assertTrue(qc.getBits()[16] instanceof Type8);
-
+
Type4 plc10 = (Type4)qc.getBits()[10];
Type4 plc11 = (Type4)qc.getBits()[11];
Type0 plc13 = (Type0)qc.getBits()[13];
Type12 plc14 = (Type12)qc.getBits()[14];
Type12 plc15 = (Type12)qc.getBits()[15];
Type8 plc16 = (Type8)qc.getBits()[16];
-
-
+
+
assertEquals(1, plc10.getNumberOfPLCs());
assertEquals(4, plc10.getPreData().length);
assertEquals(1, plc10.getPlcValA().length);
assertEquals(1, plc10.getPlcValB().length);
-
+
assertEquals(0, plc10.getPreData()[0]);
assertEquals(0, plc10.getPreData()[1]);
assertEquals(0, plc10.getPreData()[2]);
assertEquals(0, plc10.getPreData()[3]);
assertEquals(0x5d0, plc10.getPlcValA()[0]);
assertEquals(0x800, plc10.getPlcValB()[0]);
-
-
+
+
assertEquals(2, plc11.getNumberOfPLCs());
assertEquals(4, plc11.getPreData().length);
assertEquals(2, plc11.getPlcValA().length);
assertEquals(2, plc11.getPlcValB().length);
-
+
assertEquals(0, plc11.getPreData()[0]);
assertEquals(0, plc11.getPreData()[1]);
assertEquals(0, plc11.getPreData()[2]);
assertEquals(0x5d0, plc11.getPlcValB()[0]);
assertEquals(0xa00, plc11.getPlcValA()[1]);
assertEquals(0xc00, plc11.getPlcValB()[1]);
-
-
+
+
assertEquals(5, plc13.getNumberOfPLCs());
assertEquals(4, plc13.getPreData().length);
assertEquals(5, plc13.getPlcValA().length);
assertEquals(5, plc13.getPlcValB().length);
-
+
assertEquals(0xff00, plc13.getPreData()[0]);
assertEquals(0, plc13.getPreData()[1]);
assertEquals(0xf, plc13.getPreData()[2]);
assertEquals(0x00, plc13.getPlcValB()[3]);
assertEquals(0x50, plc13.getPlcValA()[4]);
assertEquals(0x00, plc13.getPlcValB()[4]);
-
-
+
+
// TODO - test the type 12s
-
-
+
+
assertEquals(6, plc16.getNumberOfPLCs());
assertEquals(7, plc16.getPreData().length);
assertEquals(6, plc16.getPlcValA().length);
assertEquals(6, plc16.getPlcValB().length);
-
+
assertEquals(0xff, plc16.getPreData()[0]);
assertEquals(0, plc16.getPreData()[1]);
assertEquals(0x56, plc16.getPreData()[2]);
assertEquals(0x000004, plc16.getPlcValA()[5]);
assertEquals(0x000004, plc16.getPlcValB()[5]);
}
-
+
public void testNoHyperlinks() throws Exception {
File f = new File(dir, "SampleNewsletter.pub");
HPBFDocument doc = new HPBFDocument(
new FileInputStream(f)
);
-
+
QuillContents qc = doc.getQuillContents();
assertEquals(20, qc.getBits().length);
-
+
Type12 plc18 = (Type12)qc.getBits()[18];
-
+
assertEquals(1, plc18.getNumberOfPLCs());
assertEquals(0, plc18.getNumberOfHyperlinks());
assertEquals(0, plc18.getTextStartAt(0));
assertEquals(601, plc18.getAllTextEndAt());
}
-
+
public void testSimpleHyperlink() throws Exception {
File f;
HPBFDocument doc;
QuillContents qc;
Type12 hlBit;
-
+
// Link at 10
f = new File(dir, "LinkAt10.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBit = (Type12)qc.getBits()[12];
assertEquals(1, hlBit.getNumberOfPLCs());
assertEquals(1, hlBit.getNumberOfHyperlinks());
-
+
assertEquals(10, hlBit.getTextStartAt(0));
assertEquals(15, hlBit.getAllTextEndAt());
assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0));
-
+
// Longer link at 10
f = new File(dir, "LinkAt10Longer.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBit = (Type12)qc.getBits()[12];
assertEquals(1, hlBit.getNumberOfPLCs());
assertEquals(1, hlBit.getNumberOfHyperlinks());
-
+
assertEquals(10, hlBit.getTextStartAt(0));
assertEquals(15, hlBit.getAllTextEndAt());
assertEquals("http://poi.apache.org/hpbf/", hlBit.getHyperlink(0));
-
+
// Link at 20
f = new File(dir, "LinkAt20.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBit = (Type12)qc.getBits()[12];
assertEquals(1, hlBit.getNumberOfPLCs());
assertEquals(1, hlBit.getNumberOfHyperlinks());
-
+
assertEquals(20, hlBit.getTextStartAt(0));
assertEquals(25, hlBit.getAllTextEndAt());
assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0));
}
-
+
public void testManyHyperlinks() throws Exception {
File f;
HPBFDocument doc;
QuillContents qc;
Type12 hlBit;
-
+
// Link at 10
f = new File(dir, "LinkAt10.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBit = (Type12)qc.getBits()[12];
assertEquals(1, hlBit.getNumberOfPLCs());
assertEquals(1, hlBit.getNumberOfHyperlinks());
-
+
assertEquals(10, hlBit.getTextStartAt(0));
assertEquals(15, hlBit.getAllTextEndAt());
assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0));
-
+
}
-
+
public void testHyperlinkDifferentVersions() throws Exception {
File f;
HPBFDocument doc;
QuillContents qc;
Type12 hlBitA;
Type12 hlBitB;
-
+
// Latest version
f = new File(dir, "Sample.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBitA = (Type12)qc.getBits()[14];
assertEquals(2, hlBitA.getNumberOfPLCs());
assertEquals(2, hlBitA.getNumberOfHyperlinks());
-
+
assertEquals(25, hlBitA.getTextStartAt(0));
assertEquals(72, hlBitA.getTextStartAt(1));
assertEquals(87, hlBitA.getAllTextEndAt());
assertEquals("http://poi.apache.org/", hlBitA.getHyperlink(0));
assertEquals("C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx", hlBitA.getHyperlink(1));
-
+
hlBitB = (Type12)qc.getBits()[15];
assertEquals(3, hlBitB.getNumberOfPLCs());
assertEquals(3, hlBitB.getNumberOfHyperlinks());
-
+
assertEquals(27, hlBitB.getTextStartAt(0));
assertEquals(37, hlBitB.getTextStartAt(1));
assertEquals(54, hlBitB.getTextStartAt(2));
assertEquals("", hlBitB.getHyperlink(0));
assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(1));
assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
-
+
// 2000 version
f = new File(dir, "Sample2000.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBitA = (Type12)qc.getBits()[13];
assertEquals(2, hlBitA.getNumberOfPLCs());
assertEquals(2, hlBitA.getNumberOfHyperlinks());
-
+
assertEquals(25, hlBitA.getTextStartAt(0));
assertEquals(72, hlBitA.getTextStartAt(1));
assertEquals(87, hlBitA.getAllTextEndAt());
assertEquals("http://poi.apache.org/", hlBitA.getHyperlink(0));
assertEquals("C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx", hlBitA.getHyperlink(1));
-
+
hlBitB = (Type12)qc.getBits()[14];
assertEquals(3, hlBitB.getNumberOfPLCs());
assertEquals(3, hlBitB.getNumberOfHyperlinks());
-
+
assertEquals(27, hlBitB.getTextStartAt(0));
assertEquals(37, hlBitB.getTextStartAt(1));
assertEquals(54, hlBitB.getTextStartAt(2));
assertEquals("", hlBitB.getHyperlink(0));
assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(1));
assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
-
+
// 98 version
f = new File(dir, "Sample98.pub");
doc = new HPBFDocument(
new FileInputStream(f)
);
qc = doc.getQuillContents();
-
+
hlBitA = (Type12)qc.getBits()[13];
assertEquals(2, hlBitA.getNumberOfPLCs());
assertEquals(2, hlBitA.getNumberOfHyperlinks());
-
+
assertEquals(25, hlBitA.getTextStartAt(0));
assertEquals(72, hlBitA.getTextStartAt(1));
assertEquals(87, hlBitA.getAllTextEndAt());
assertEquals("http://poi.apache.org/", hlBitA.getHyperlink(0));
assertEquals("C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx", hlBitA.getHyperlink(1));
-
+
hlBitB = (Type12)qc.getBits()[14];
assertEquals(3, hlBitB.getNumberOfPLCs());
assertEquals(3, hlBitB.getNumberOfHyperlinks());
-
+
assertEquals(27, hlBitB.getTextStartAt(0));
assertEquals(37, hlBitB.getTextStartAt(1));
assertEquals(54, hlBitB.getTextStartAt(2));
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestEncryptedFile extends TestCase {
+public final class TestEncryptedFile extends TestCase {
// A non encrypted file
private String ss_ne;
// An encrypted file, with encrypted properties
private String ss_np_e;
// An encrypted file, with a 56 bit key
private String ss_56_e;
-
+
public TestEncryptedFile() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
-
+
ss_ne = dirname + "/basic_test_ppt_file.ppt";
ss_e = dirname + "/Password_Protected-hello.ppt";
ss_np_e = dirname + "/Password_Protected-np-hello.ppt";
ss_56_e = dirname + "/Password_Protected-56-hello.ppt";
}
-
+
public void testLoadNonEncrypted() throws Exception {
HSLFSlideShow hss = new HSLFSlideShow(ss_ne);
-
+
assertNotNull(hss);
}
-
+
public void testLoadEncrypted() throws Exception {
try {
new HSLFSlideShow(ss_e);
} catch(EncryptedPowerPointFileException e) {
// Good
}
-
+
try {
new HSLFSlideShow(ss_np_e);
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
-
+
try {
new HSLFSlideShow(ss_56_e);
fail();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestReWrite extends TestCase {
+public final class TestReWrite extends TestCase {
// HSLFSlideShow primed on the test data
private HSLFSlideShow hssA;
private HSLFSlideShow hssB;
public void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
-
+
String filenameA = dirname + "/basic_test_ppt_file.ppt";
FileInputStream fisA = new FileInputStream(filenameA);
pfsA = new POIFSFileSystem(fisA);
hssA = new HSLFSlideShow(pfsA);
-
+
String filenameB = dirname + "/ParagraphStylesShorterThanCharStyles.ppt";
FileInputStream fisB = new FileInputStream(filenameB);
pfsB = new POIFSFileSystem(fisB);
hssB = new HSLFSlideShow(pfsB);
-
+
String filenameC = dirname + "/WithMacros.ppt";
FileInputStream fisC = new FileInputStream(filenameC);
pfsC = new POIFSFileSystem(fisC);
assertEquals(_oData[i], _nData[i]);
}
}
-
+
public void testWithMacroStreams() throws Exception {
// Check that they're apparently the same
assertSlideShowWritesOutTheSame(hssC, pfsC);
-
+
// Currently has a Macros stream
assertNotNull( pfsC.getRoot().getEntry("Macros") );
-
+
// Write out normally, will loose the macro stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hssC.write(baos);
POIFSFileSystem pfsNew = new POIFSFileSystem(
new ByteArrayInputStream(baos.toByteArray()) );
-
+
try {
pfsNew.getRoot().getEntry("Macros");
fail();
} catch(FileNotFoundException e) {
// Good, as expected
}
-
+
// But if we write out with nodes preserved, will be there
baos = new ByteArrayOutputStream();
hssC.write(baos, true);
/**
* Ensure that simply opening a slideshow (usermodel) view of it
- * doesn't change things
+ * doesn't change things
*/
public void testSlideShowWritesOutTheSame() throws Exception {
assertSlideShowWritesOutTheSame(hssA, pfsA);
-
+
// Some bug in StyleTextPropAtom rewriting means this will fail
// We need to identify and fix that first
//assertSlideShowWritesOutTheSame(hssB, pfsB);
SlideShow ss = new SlideShow(hss);
ss.getSlides();
ss.getNotes();
-
+
// Now write out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss.write(baos);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestReWriteSanity extends TestCase {
+public final class TestReWriteSanity extends TestCase {
// HSLFSlideShow primed on the test data
private HSLFSlideShow ss;
// POIFS primed on the test data
// Create a new one from that
HSLFSlideShow wss = new HSLFSlideShow(bais);
- // Find the location of the PersistPtrIncrementalBlocks and
+ // Find the location of the PersistPtrIncrementalBlocks and
// UserEditAtoms
Record[] r = wss.getRecords();
Hashtable pp = new Hashtable();
ue.put(new Integer(pos), r[i]);
lastUEPos = pos;
}
-
+
ByteArrayOutputStream bc = new ByteArrayOutputStream();
r[i].writeOut(bc);
pos += bc.size();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestRecordCounts extends TestCase {
+public final class TestRecordCounts extends TestCase {
// HSLFSlideShow primed on the test data
private HSLFSlideShow ss;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.extractor;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestCruddyExtractor extends TestCase {
+public final class TestCruddyExtractor extends TestCase {
// Extractor primed on the test data
private QuickButCruddyTextExtractor te;
// All the text to be found in the file
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
/**
* Test <code>Fill</code> object.
- *
+ *
* @author Yegor Kozlov
*/
-public class TestBackground extends TestCase {
+public final class TestBackground extends TestCase {
/**
* Default background for slide, shape and slide master.
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.RichTextRun;\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-\r
-import java.awt.*;\r
-import java.awt.Rectangle;\r
-import java.awt.geom.*;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.ByteArrayInputStream;\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-\r
-/**\r
- * Test Freeform object.\r
- * The Freeform shape is constructed from java.awt.GeneralPath.\r
- * Check that the get/set path accessors are consistent.\r
- * (TODO: verification of Bezier curves is more difficult due to rounding error. Figure out a test approach for that)\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestFreeform extends TestCase {\r
-\r
- public void testClosedPath() throws Exception {\r
-\r
- GeneralPath path1 = new GeneralPath();\r
- path1.moveTo(100, 100);\r
- path1.lineTo(200, 100);\r
- path1.lineTo(200, 200);\r
- path1.lineTo(100, 200);\r
- path1.closePath();\r
-\r
- Freeform p = new Freeform();\r
- p.setPath(path1);\r
-\r
- java.awt.Shape path2 = p.getOutline();\r
- assertTrue(new Area(path1).equals(new Area(path2)));\r
- }\r
-\r
- public void testLine() throws Exception {\r
-\r
- GeneralPath path1 = new GeneralPath(new Line2D.Double(100, 100, 200, 100));\r
-\r
- Freeform p = new Freeform();\r
- p.setPath(path1);\r
-\r
- java.awt.Shape path2 = p.getOutline();\r
- assertTrue(new Area(path1).equals(new Area(path2)));\r
- }\r
-\r
- public void testRectangle() throws Exception {\r
-\r
- GeneralPath path1 = new GeneralPath(new Rectangle2D.Double(100, 100, 200, 50));\r
-\r
- Freeform p = new Freeform();\r
- p.setPath(path1);\r
-\r
- java.awt.Shape path2 = p.getOutline();\r
- assertTrue(new Area(path1).equals(new Area(path2)));\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+import java.awt.*;
+import java.awt.Rectangle;
+import java.awt.geom.*;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * Test Freeform object.
+ * The Freeform shape is constructed from java.awt.GeneralPath.
+ * Check that the get/set path accessors are consistent.
+ * (TODO: verification of Bezier curves is more difficult due to rounding error. Figure out a test approach for that)
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestFreeform extends TestCase {
+
+ public void testClosedPath() throws Exception {
+
+ GeneralPath path1 = new GeneralPath();
+ path1.moveTo(100, 100);
+ path1.lineTo(200, 100);
+ path1.lineTo(200, 200);
+ path1.lineTo(100, 200);
+ path1.closePath();
+
+ Freeform p = new Freeform();
+ p.setPath(path1);
+
+ java.awt.Shape path2 = p.getOutline();
+ assertTrue(new Area(path1).equals(new Area(path2)));
+ }
+
+ public void testLine() throws Exception {
+
+ GeneralPath path1 = new GeneralPath(new Line2D.Double(100, 100, 200, 100));
+
+ Freeform p = new Freeform();
+ p.setPath(path1);
+
+ java.awt.Shape path2 = p.getOutline();
+ assertTrue(new Area(path1).equals(new Area(path2)));
+ }
+
+ public void testRectangle() throws Exception {
+
+ GeneralPath path1 = new GeneralPath(new Rectangle2D.Double(100, 100, 200, 50));
+
+ Freeform p = new Freeform();
+ p.setPath(path1);
+
+ java.awt.Shape path2 = p.getOutline();
+ assertTrue(new Area(path1).equals(new Area(path2)));
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import java.io.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-import junit.framework.TestCase;\r
-\r
-/**\r
- * Test {@link org.apache.poi.hslf.model.HeadersFooters} object\r
- */\r
-public class TestHeadersFooters extends TestCase\r
-{\r
-\r
- public static final String cwd = System.getProperty("HSLF.testdata.path");\r
-\r
- public void testRead() throws Exception\r
- {\r
- File file = new File(cwd, "headers_footers.ppt");\r
- FileInputStream is = new FileInputStream(file);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- HeadersFooters slideHdd = ppt.getSlideHeadersFooters();\r
- assertTrue(slideHdd.isFooterVisible());\r
- assertEquals("Global Slide Footer", slideHdd.getFooterText());\r
- assertTrue(slideHdd.isSlideNumberVisible());\r
- assertFalse(slideHdd.isHeaderVisible());\r
- assertNull(slideHdd.getHeaderText());\r
- assertFalse(slideHdd.isUserDateVisible());\r
- assertNull(slideHdd.getDateTimeText());\r
-\r
-\r
- HeadersFooters notesHdd = ppt.getNotesHeadersFooters();\r
- assertTrue(notesHdd.isFooterVisible());\r
- assertEquals("Notes Footer", notesHdd.getFooterText());\r
- assertTrue(notesHdd.isHeaderVisible());\r
- assertEquals("Notes Header", notesHdd.getHeaderText());\r
- assertTrue(notesHdd.isUserDateVisible());\r
- assertNull(notesHdd.getDateTimeText());\r
-\r
- Slide[] slide = ppt.getSlides();\r
- //the first slide uses presentation-scope headers / footers\r
- HeadersFooters hd1 = slide[0].getHeadersFooters();\r
- assertEquals(slideHdd.isFooterVisible(), hd1.isFooterVisible());\r
- assertEquals(slideHdd.getFooterText(), hd1.getFooterText());\r
- assertEquals(slideHdd.isSlideNumberVisible(), hd1.isSlideNumberVisible());\r
- assertEquals(slideHdd.isHeaderVisible(), hd1.isHeaderVisible());\r
- assertEquals(slideHdd.getHeaderText(), hd1.getHeaderText());\r
- assertEquals(slideHdd.isUserDateVisible(), hd1.isUserDateVisible());\r
- assertEquals(slideHdd.getDateTimeText(), hd1.getDateTimeText());\r
-\r
- //the first slide uses per-slide headers / footers\r
- HeadersFooters hd2 = slide[1].getHeadersFooters();\r
- assertEquals(true, hd2.isFooterVisible());\r
- assertEquals("per-slide footer", hd2.getFooterText());\r
- assertEquals(true, hd2.isUserDateVisible());\r
- assertEquals("custom date format", hd2.getDateTimeText());\r
- }\r
-\r
- /**\r
- * If Headers / Footers are not set, all the getters should return <code>false</code> or <code>null</code>\r
- */\r
- public void testReadNoHeadersFooters() throws Exception\r
- {\r
- File file = new File(cwd, "basic_test_ppt_file.ppt");\r
- FileInputStream is = new FileInputStream(file);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- HeadersFooters slideHdd = ppt.getSlideHeadersFooters();\r
- assertFalse(slideHdd.isFooterVisible());\r
- assertNull(slideHdd.getFooterText());\r
- assertFalse(slideHdd.isSlideNumberVisible());\r
- assertFalse(slideHdd.isHeaderVisible());\r
- assertNull(slideHdd.getHeaderText());\r
- assertFalse(slideHdd.isUserDateVisible());\r
- assertNull(slideHdd.getDateTimeText());\r
-\r
-\r
- HeadersFooters notesHdd = ppt.getNotesHeadersFooters();\r
- assertFalse(notesHdd.isFooterVisible());\r
- assertNull(notesHdd.getFooterText());\r
- assertFalse(notesHdd.isHeaderVisible());\r
- assertNull(notesHdd.getHeaderText());\r
- assertFalse(notesHdd.isUserDateVisible());\r
- assertNull(notesHdd.getDateTimeText());\r
-\r
- Slide[] slide = ppt.getSlides();\r
- for(int i=0 ; i < slide.length; i++){\r
- HeadersFooters hd1 = slide[i].getHeadersFooters();\r
- assertFalse(hd1.isFooterVisible());\r
- assertNull(hd1.getFooterText());\r
- assertFalse(hd1.isHeaderVisible());\r
- assertNull(hd1.getHeaderText());\r
- assertFalse(hd1.isUserDateVisible());\r
- assertNull(hd1.getDateTimeText());\r
- }\r
- }\r
-\r
- /**\r
- * Test extraction of headers / footers from PPTs saved in Office 2007\r
- */\r
- public void testRead2007() throws Exception\r
- {\r
- File file = new File(cwd, "headers_footers_2007.ppt");\r
- FileInputStream is = new FileInputStream(file);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- HeadersFooters slideHdd = ppt.getSlideHeadersFooters();\r
- assertTrue(slideHdd.isFooterVisible());\r
- assertEquals("THE FOOTER TEXT", slideHdd.getFooterText());\r
- assertTrue(slideHdd.isSlideNumberVisible());\r
- assertFalse(slideHdd.isHeaderVisible());\r
- assertNull(slideHdd.getHeaderText());\r
- assertTrue(slideHdd.isUserDateVisible());\r
- assertEquals("Wednesday, August 06, 2008", slideHdd.getDateTimeText());\r
-\r
-\r
- HeadersFooters notesHdd = ppt.getNotesHeadersFooters();\r
- assertTrue(notesHdd.isFooterVisible());\r
- assertEquals("THE NOTES FOOTER TEXT", notesHdd.getFooterText());\r
- assertTrue(notesHdd.isHeaderVisible());\r
- assertEquals("THE NOTES HEADER TEXT", notesHdd.getHeaderText());\r
- assertTrue(notesHdd.isUserDateVisible());\r
- assertTrue(notesHdd.isDateTimeVisible());\r
- //TODO: depending on the formatId getDateTimeText() should return formatted date\r
- //assertEquals("08/12/08", notesHdd.getDateTimeText());\r
-\r
- //per-slide headers / footers\r
- Slide[] slide = ppt.getSlides();\r
- //the first slide uses presentation-scope headers / footers\r
- HeadersFooters hd1 = slide[0].getHeadersFooters();\r
- assertTrue(hd1.isFooterVisible());\r
- assertEquals("THE FOOTER TEXT", hd1.getFooterText());\r
- assertTrue(hd1.isSlideNumberVisible());\r
- assertFalse(hd1.isHeaderVisible());\r
- assertNull(hd1.getHeaderText());\r
- assertTrue(hd1.isUserDateVisible());\r
- assertTrue(hd1.isDateTimeVisible());\r
- assertEquals("Wednesday, August 06, 2008", hd1.getDateTimeText());\r
-\r
- //the second slide uses custom per-slide headers / footers\r
- HeadersFooters hd2 = slide[1].getHeadersFooters();\r
- assertTrue(hd2.isFooterVisible());\r
- assertEquals("THE FOOTER TEXT FOR SLIDE 2", hd2.getFooterText());\r
- assertTrue(hd2.isSlideNumberVisible());\r
- assertFalse(hd2.isHeaderVisible());\r
- assertNull(hd2.getHeaderText());\r
- assertTrue(hd2.isUserDateVisible());\r
- assertTrue(hd2.isDateTimeVisible());\r
- assertEquals("August 06, 2008", hd2.getDateTimeText());\r
-\r
- //the third slide uses per-slide headers / footers\r
- HeadersFooters hd3 = slide[2].getHeadersFooters();\r
- assertTrue(hd3.isFooterVisible());\r
- assertEquals("THE FOOTER TEXT", hd3.getFooterText());\r
- assertTrue(hd3.isSlideNumberVisible());\r
- assertFalse(hd3.isHeaderVisible());\r
- assertNull(hd3.getHeaderText());\r
- assertTrue(hd3.isUserDateVisible());\r
- assertTrue(hd3.isDateTimeVisible());\r
- assertEquals("Wednesday, August 06, 2008", hd3.getDateTimeText());\r
- }\r
-\r
- public void testCreateSlideFooters() throws Exception\r
- {\r
- SlideShow ppt = new SlideShow();\r
- HeadersFooters hdd = ppt.getSlideHeadersFooters();\r
- hdd.setFootersText("My slide footer");\r
- hdd.setSlideNumberVisible(true);\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ppt.write(out);\r
- byte[] b = out.toByteArray();\r
-\r
- SlideShow ppt2 = new SlideShow(new ByteArrayInputStream(b));\r
- HeadersFooters hdd2 = ppt2.getSlideHeadersFooters();\r
- assertTrue(hdd2.isSlideNumberVisible());\r
- assertTrue(hdd2.isFooterVisible());\r
- assertEquals("My slide footer", hdd2.getFooterText());\r
- }\r
-\r
- public void testCreateNotesFooters() throws Exception\r
- {\r
- SlideShow ppt = new SlideShow();\r
- HeadersFooters hdd = ppt.getNotesHeadersFooters();\r
- hdd.setFootersText("My notes footer");\r
- hdd.setHeaderText("My notes header");\r
- hdd.setSlideNumberVisible(true);\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ppt.write(out);\r
- byte[] b = out.toByteArray();\r
-\r
- SlideShow ppt2 = new SlideShow(new ByteArrayInputStream(b));\r
- HeadersFooters hdd2 = ppt2.getNotesHeadersFooters();\r
- assertTrue(hdd2.isSlideNumberVisible());\r
- assertTrue(hdd2.isFooterVisible());\r
- assertEquals("My notes footer", hdd2.getFooterText());\r
- assertTrue(hdd2.isHeaderVisible());\r
- assertEquals("My notes header", hdd2.getHeaderText());\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import java.io.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+import junit.framework.TestCase;
+
+/**
+ * Test {@link org.apache.poi.hslf.model.HeadersFooters} object
+ */
+public final class TestHeadersFooters extends TestCase
+{
+
+ public static final String cwd = System.getProperty("HSLF.testdata.path");
+
+ public void testRead() throws Exception
+ {
+ File file = new File(cwd, "headers_footers.ppt");
+ FileInputStream is = new FileInputStream(file);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
+ assertTrue(slideHdd.isFooterVisible());
+ assertEquals("Global Slide Footer", slideHdd.getFooterText());
+ assertTrue(slideHdd.isSlideNumberVisible());
+ assertFalse(slideHdd.isHeaderVisible());
+ assertNull(slideHdd.getHeaderText());
+ assertFalse(slideHdd.isUserDateVisible());
+ assertNull(slideHdd.getDateTimeText());
+
+
+ HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
+ assertTrue(notesHdd.isFooterVisible());
+ assertEquals("Notes Footer", notesHdd.getFooterText());
+ assertTrue(notesHdd.isHeaderVisible());
+ assertEquals("Notes Header", notesHdd.getHeaderText());
+ assertTrue(notesHdd.isUserDateVisible());
+ assertNull(notesHdd.getDateTimeText());
+
+ Slide[] slide = ppt.getSlides();
+ //the first slide uses presentation-scope headers / footers
+ HeadersFooters hd1 = slide[0].getHeadersFooters();
+ assertEquals(slideHdd.isFooterVisible(), hd1.isFooterVisible());
+ assertEquals(slideHdd.getFooterText(), hd1.getFooterText());
+ assertEquals(slideHdd.isSlideNumberVisible(), hd1.isSlideNumberVisible());
+ assertEquals(slideHdd.isHeaderVisible(), hd1.isHeaderVisible());
+ assertEquals(slideHdd.getHeaderText(), hd1.getHeaderText());
+ assertEquals(slideHdd.isUserDateVisible(), hd1.isUserDateVisible());
+ assertEquals(slideHdd.getDateTimeText(), hd1.getDateTimeText());
+
+ //the first slide uses per-slide headers / footers
+ HeadersFooters hd2 = slide[1].getHeadersFooters();
+ assertEquals(true, hd2.isFooterVisible());
+ assertEquals("per-slide footer", hd2.getFooterText());
+ assertEquals(true, hd2.isUserDateVisible());
+ assertEquals("custom date format", hd2.getDateTimeText());
+ }
+
+ /**
+ * If Headers / Footers are not set, all the getters should return <code>false</code> or <code>null</code>
+ */
+ public void testReadNoHeadersFooters() throws Exception
+ {
+ File file = new File(cwd, "basic_test_ppt_file.ppt");
+ FileInputStream is = new FileInputStream(file);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
+ assertFalse(slideHdd.isFooterVisible());
+ assertNull(slideHdd.getFooterText());
+ assertFalse(slideHdd.isSlideNumberVisible());
+ assertFalse(slideHdd.isHeaderVisible());
+ assertNull(slideHdd.getHeaderText());
+ assertFalse(slideHdd.isUserDateVisible());
+ assertNull(slideHdd.getDateTimeText());
+
+
+ HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
+ assertFalse(notesHdd.isFooterVisible());
+ assertNull(notesHdd.getFooterText());
+ assertFalse(notesHdd.isHeaderVisible());
+ assertNull(notesHdd.getHeaderText());
+ assertFalse(notesHdd.isUserDateVisible());
+ assertNull(notesHdd.getDateTimeText());
+
+ Slide[] slide = ppt.getSlides();
+ for(int i=0 ; i < slide.length; i++){
+ HeadersFooters hd1 = slide[i].getHeadersFooters();
+ assertFalse(hd1.isFooterVisible());
+ assertNull(hd1.getFooterText());
+ assertFalse(hd1.isHeaderVisible());
+ assertNull(hd1.getHeaderText());
+ assertFalse(hd1.isUserDateVisible());
+ assertNull(hd1.getDateTimeText());
+ }
+ }
+
+ /**
+ * Test extraction of headers / footers from PPTs saved in Office 2007
+ */
+ public void testRead2007() throws Exception
+ {
+ File file = new File(cwd, "headers_footers_2007.ppt");
+ FileInputStream is = new FileInputStream(file);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
+ assertTrue(slideHdd.isFooterVisible());
+ assertEquals("THE FOOTER TEXT", slideHdd.getFooterText());
+ assertTrue(slideHdd.isSlideNumberVisible());
+ assertFalse(slideHdd.isHeaderVisible());
+ assertNull(slideHdd.getHeaderText());
+ assertTrue(slideHdd.isUserDateVisible());
+ assertEquals("Wednesday, August 06, 2008", slideHdd.getDateTimeText());
+
+
+ HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
+ assertTrue(notesHdd.isFooterVisible());
+ assertEquals("THE NOTES FOOTER TEXT", notesHdd.getFooterText());
+ assertTrue(notesHdd.isHeaderVisible());
+ assertEquals("THE NOTES HEADER TEXT", notesHdd.getHeaderText());
+ assertTrue(notesHdd.isUserDateVisible());
+ assertTrue(notesHdd.isDateTimeVisible());
+ //TODO: depending on the formatId getDateTimeText() should return formatted date
+ //assertEquals("08/12/08", notesHdd.getDateTimeText());
+
+ //per-slide headers / footers
+ Slide[] slide = ppt.getSlides();
+ //the first slide uses presentation-scope headers / footers
+ HeadersFooters hd1 = slide[0].getHeadersFooters();
+ assertTrue(hd1.isFooterVisible());
+ assertEquals("THE FOOTER TEXT", hd1.getFooterText());
+ assertTrue(hd1.isSlideNumberVisible());
+ assertFalse(hd1.isHeaderVisible());
+ assertNull(hd1.getHeaderText());
+ assertTrue(hd1.isUserDateVisible());
+ assertTrue(hd1.isDateTimeVisible());
+ assertEquals("Wednesday, August 06, 2008", hd1.getDateTimeText());
+
+ //the second slide uses custom per-slide headers / footers
+ HeadersFooters hd2 = slide[1].getHeadersFooters();
+ assertTrue(hd2.isFooterVisible());
+ assertEquals("THE FOOTER TEXT FOR SLIDE 2", hd2.getFooterText());
+ assertTrue(hd2.isSlideNumberVisible());
+ assertFalse(hd2.isHeaderVisible());
+ assertNull(hd2.getHeaderText());
+ assertTrue(hd2.isUserDateVisible());
+ assertTrue(hd2.isDateTimeVisible());
+ assertEquals("August 06, 2008", hd2.getDateTimeText());
+
+ //the third slide uses per-slide headers / footers
+ HeadersFooters hd3 = slide[2].getHeadersFooters();
+ assertTrue(hd3.isFooterVisible());
+ assertEquals("THE FOOTER TEXT", hd3.getFooterText());
+ assertTrue(hd3.isSlideNumberVisible());
+ assertFalse(hd3.isHeaderVisible());
+ assertNull(hd3.getHeaderText());
+ assertTrue(hd3.isUserDateVisible());
+ assertTrue(hd3.isDateTimeVisible());
+ assertEquals("Wednesday, August 06, 2008", hd3.getDateTimeText());
+ }
+
+ public void testCreateSlideFooters() throws Exception
+ {
+ SlideShow ppt = new SlideShow();
+ HeadersFooters hdd = ppt.getSlideHeadersFooters();
+ hdd.setFootersText("My slide footer");
+ hdd.setSlideNumberVisible(true);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ byte[] b = out.toByteArray();
+
+ SlideShow ppt2 = new SlideShow(new ByteArrayInputStream(b));
+ HeadersFooters hdd2 = ppt2.getSlideHeadersFooters();
+ assertTrue(hdd2.isSlideNumberVisible());
+ assertTrue(hdd2.isFooterVisible());
+ assertEquals("My slide footer", hdd2.getFooterText());
+ }
+
+ public void testCreateNotesFooters() throws Exception
+ {
+ SlideShow ppt = new SlideShow();
+ HeadersFooters hdd = ppt.getNotesHeadersFooters();
+ hdd.setFootersText("My notes footer");
+ hdd.setHeaderText("My notes header");
+ hdd.setSlideNumberVisible(true);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ byte[] b = out.toByteArray();
+
+ SlideShow ppt2 = new SlideShow(new ByteArrayInputStream(b));
+ HeadersFooters hdd2 = ppt2.getNotesHeadersFooters();
+ assertTrue(hdd2.isSlideNumberVisible());
+ assertTrue(hdd2.isFooterVisible());
+ assertEquals("My notes footer", hdd2.getFooterText());
+ assertTrue(hdd2.isHeaderVisible());
+ assertEquals("My notes header", hdd2.getHeaderText());
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import java.io.FileInputStream;\r
-import java.io.File;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-/**\r
- * Test Hyperlink.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestHyperlink extends TestCase {\r
- protected String cwd = System.getProperty("HSLF.testdata.path");\r
-\r
- public void testTextRunHyperlinks() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "WithLinks.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- TextRun[] run;\r
- Slide slide;\r
- slide = ppt.getSlides()[0];\r
- run = slide.getTextRuns();\r
- for (int i = 0; i < run.length; i++) {\r
- String text = run[i].getText();\r
- if (text.equals(\r
- "This page has two links:\n" +\r
- "http://jakarta.apache.org/poi/\n" +\r
- "\n" +\r
- "http://slashdot.org/\n" +\r
- "\n" +\r
- "In addition, its notes has one link")){\r
-\r
- Hyperlink[] links = run[i].getHyperlinks();\r
- assertNotNull(links);\r
- assertEquals(2, links.length);\r
-\r
- assertEquals("http://jakarta.apache.org/poi/", links[0].getTitle());\r
- assertEquals("http://jakarta.apache.org/poi/", links[0].getAddress());\r
- assertEquals("http://jakarta.apache.org/poi/", text.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));\r
-\r
- assertEquals("http://slashdot.org/", links[1].getTitle());\r
- assertEquals("http://slashdot.org/", links[1].getAddress());\r
- assertEquals("http://slashdot.org/", text.substring(links[1].getStartIndex(), links[1].getEndIndex()-1));\r
-\r
- }\r
- }\r
-\r
- slide = ppt.getSlides()[1];\r
- run = slide.getTextRuns();\r
- for (int i = 0; i < run.length; i++) {\r
- String text = run[i].getText();\r
- if (text.equals(\r
- "I have the one link:\n" +\r
- "Jakarta HSSF")){\r
-\r
- Hyperlink[] links = run[i].getHyperlinks();\r
- assertNotNull(links);\r
- assertEquals(1, links.length);\r
-\r
- assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getTitle());\r
- assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getAddress());\r
- assertEquals("Jakarta HSSF", text.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));\r
-\r
- }\r
- }\r
-\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+
+import java.io.FileInputStream;
+import java.io.File;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+/**
+ * Test Hyperlink.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestHyperlink extends TestCase {
+ protected String cwd = System.getProperty("HSLF.testdata.path");
+
+ public void testTextRunHyperlinks() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "WithLinks.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ TextRun[] run;
+ Slide slide;
+ slide = ppt.getSlides()[0];
+ run = slide.getTextRuns();
+ for (int i = 0; i < run.length; i++) {
+ String text = run[i].getText();
+ if (text.equals(
+ "This page has two links:\n" +
+ "http://jakarta.apache.org/poi/\n" +
+ "\n" +
+ "http://slashdot.org/\n" +
+ "\n" +
+ "In addition, its notes has one link")){
+
+ Hyperlink[] links = run[i].getHyperlinks();
+ assertNotNull(links);
+ assertEquals(2, links.length);
+
+ assertEquals("http://jakarta.apache.org/poi/", links[0].getTitle());
+ assertEquals("http://jakarta.apache.org/poi/", links[0].getAddress());
+ assertEquals("http://jakarta.apache.org/poi/", text.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
+
+ assertEquals("http://slashdot.org/", links[1].getTitle());
+ assertEquals("http://slashdot.org/", links[1].getAddress());
+ assertEquals("http://slashdot.org/", text.substring(links[1].getStartIndex(), links[1].getEndIndex()-1));
+
+ }
+ }
+
+ slide = ppt.getSlides()[1];
+ run = slide.getTextRuns();
+ for (int i = 0; i < run.length; i++) {
+ String text = run[i].getText();
+ if (text.equals(
+ "I have the one link:\n" +
+ "Jakarta HSSF")){
+
+ Hyperlink[] links = run[i].getHyperlinks();
+ assertNotNull(links);
+ assertEquals(1, links.length);
+
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getTitle());
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getAddress());
+ assertEquals("Jakarta HSSF", text.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
+
+ }
+ }
+
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.*;\r
-\r
-import java.io.FileOutputStream;\r
-import java.io.File;\r
-import java.awt.*;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.PictureData;\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.blip.ImagePainter;\r
-import org.apache.poi.hslf.blip.BitmapPainter;\r
-import org.apache.poi.ddf.EscherBSERecord;\r
-\r
-/**\r
- * Test Picture shape.\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TestImagePainter extends TestCase {\r
-\r
- private static class CustomImagePainer implements ImagePainter{\r
- public void paint(Graphics2D graphics, PictureData pict, Picture parent){\r
- //do noting\r
- }\r
-\r
- }\r
-\r
- public void testImagePainter() throws Exception {\r
-\r
- ImagePainter pntr = PictureData.getImagePainter(Picture.PNG);\r
- assertTrue(PictureData.getImagePainter(Picture.PNG) instanceof BitmapPainter);\r
- assertTrue(PictureData.getImagePainter(Picture.JPEG) instanceof BitmapPainter);\r
- assertTrue(PictureData.getImagePainter(Picture.DIB) instanceof BitmapPainter);\r
-\r
- PictureData.setImagePainter(Picture.WMF, new CustomImagePainer());\r
- assertTrue(PictureData.getImagePainter(Picture.WMF) instanceof CustomImagePainer);\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.*;
+
+import java.io.FileOutputStream;
+import java.io.File;
+import java.awt.*;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.blip.ImagePainter;
+import org.apache.poi.hslf.blip.BitmapPainter;
+import org.apache.poi.ddf.EscherBSERecord;
+
+/**
+ * Test Picture shape.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestImagePainter extends TestCase {
+
+ private static class CustomImagePainer implements ImagePainter{
+ public void paint(Graphics2D graphics, PictureData pict, Picture parent){
+ //do noting
+ }
+
+ }
+
+ public void testImagePainter() throws Exception {
+
+ ImagePainter pntr = PictureData.getImagePainter(Picture.PNG);
+ assertTrue(PictureData.getImagePainter(Picture.PNG) instanceof BitmapPainter);
+ assertTrue(PictureData.getImagePainter(Picture.JPEG) instanceof BitmapPainter);
+ assertTrue(PictureData.getImagePainter(Picture.DIB) instanceof BitmapPainter);
+
+ PictureData.setImagePainter(Picture.WMF, new CustomImagePainer());
+ assertTrue(PictureData.getImagePainter(Picture.WMF) instanceof CustomImagePainer);
+ }
+
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import junit.framework.*;
/**
* Test Line shape.
- *
+ *
* @author Yegor Kozlov
*/
-public class TestLine extends TestCase {
+public final class TestLine extends TestCase {
public void setUp() throws Exception {
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import java.io.*;\r
-import java.awt.*;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-\r
-/**\r
- * Test <code>MovieShape</code> object.\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TestMovieShape extends TestCase {\r
-\r
- protected String cwd = System.getProperty("HSLF.testdata.path");\r
-\r
- public void testCreate() throws Exception {\r
- SlideShow ppt = new SlideShow();\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- String path = cwd + "/test-movie.mpg";\r
- int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG);\r
- int thumbnailIdx = ppt.addPicture(new File(cwd, "tomcat.png"), Picture.PNG);\r
-\r
- MovieShape shape = new MovieShape(movieIdx, thumbnailIdx);\r
- shape.setAnchor(new Rectangle2D.Float(300,225,120,90));\r
- slide.addShape(shape);\r
-\r
- assertEquals(path, shape.getPath());\r
- assertTrue(shape.isAutoPlay());\r
- shape.setAutoPlay(false);\r
- assertFalse(shape.isAutoPlay());\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ppt.write(out);\r
-\r
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));\r
- slide = ppt.getSlides()[0];\r
- shape = (MovieShape)slide.getShapes()[0];\r
- assertEquals(path, shape.getPath());\r
- assertFalse(shape.isAutoPlay());\r
-\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+/**
+ * Test <code>MovieShape</code> object.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestMovieShape extends TestCase {
+
+ protected String cwd = System.getProperty("HSLF.testdata.path");
+
+ public void testCreate() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ String path = cwd + "/test-movie.mpg";
+ int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG);
+ int thumbnailIdx = ppt.addPicture(new File(cwd, "tomcat.png"), Picture.PNG);
+
+ MovieShape shape = new MovieShape(movieIdx, thumbnailIdx);
+ shape.setAnchor(new Rectangle2D.Float(300,225,120,90));
+ slide.addShape(shape);
+
+ assertEquals(path, shape.getPath());
+ assertTrue(shape.isAutoPlay());
+ shape.setAutoPlay(false);
+ assertFalse(shape.isAutoPlay());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+
+ ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ slide = ppt.getSlides()[0];
+ shape = (MovieShape)slide.getShapes()[0];
+ assertEquals(path, shape.getPath());
+ assertFalse(shape.isAutoPlay());
+
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.usermodel.ObjectData;\r
-import org.apache.poi.hslf.usermodel.PictureData;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hssf.usermodel.HSSFSheet;\r
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
-import org.apache.poi.hwpf.HWPFDocument;\r
-\r
-public final class TestOleEmbedding extends TestCase {\r
- /**\r
- * Tests support for OLE objects.\r
- *\r
- * @throws Exception if an error occurs.\r
- */\r
- public void testOleEmbedding2003() throws Exception {\r
- String dirname = System.getProperty("HSLF.testdata.path");\r
- File file = new File(dirname, "ole2-embedding-2003.ppt");\r
- HSLFSlideShow slideShow = new HSLFSlideShow(new FileInputStream(file));\r
- // Placeholder EMFs for clients that don't support the OLE components.\r
- PictureData[] pictures = slideShow.getPictures();\r
- assertEquals("Should be two pictures", 2, pictures.length);\r
- //assertDigestEquals("Wrong data for picture 1", "8d1fbadf4814f321bb1ccdd056e3c788", pictures[0].getData());\r
- //assertDigestEquals("Wrong data for picture 2", "987a698e83559cf3d38a0deeba1cc63b", pictures[1].getData());\r
-\r
- // Actual embedded objects.\r
- ObjectData[] objects = slideShow.getEmbeddedObjects();\r
- assertEquals("Should be two objects", 2, objects.length);\r
- //assertDigestEquals("Wrong data for objecs 1", "0d1fcc61a83de5c4894dc0c88e9a019d", objects[0].getData());\r
- //assertDigestEquals("Wrong data for object 2", "b323604b2003a7299c77c2693b641495", objects[1].getData());\r
- }\r
-\r
- public void testOLEShape() throws Exception {\r
- String dirname = System.getProperty("HSLF.testdata.path");\r
- File file = new File(dirname, "ole2-embedding-2003.ppt");\r
- FileInputStream is = new FileInputStream(file);\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- Slide slide = ppt.getSlides()[0];\r
- Shape[] sh = slide.getShapes();\r
- int cnt = 0;\r
- for (int i = 0; i < sh.length; i++) {\r
- if(sh[i] instanceof OLEShape){\r
- cnt++;\r
- OLEShape ole = (OLEShape)sh[i];\r
- ObjectData data = ole.getObjectData();\r
- if("Worksheet".equals(ole.getInstanceName())){\r
- //Voila! we created a workbook from the embedded OLE data\r
- HSSFWorkbook wb = new HSSFWorkbook(data.getData());\r
- HSSFSheet sheet = wb.getSheetAt(0);\r
- //verify we can access the xls data\r
- assertEquals(1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0);\r
- assertEquals(1, sheet.getRow(1).getCell(0).getNumericCellValue(), 0);\r
- assertEquals(2, sheet.getRow(2).getCell(0).getNumericCellValue(), 0);\r
- assertEquals(3, sheet.getRow(3).getCell(0).getNumericCellValue(), 0);\r
- assertEquals(8, sheet.getRow(5).getCell(0).getNumericCellValue(), 0);\r
- } else if ("Document".equals(ole.getInstanceName())){\r
- //creating a HWPF document \r
- HWPFDocument doc = new HWPFDocument(data.getData());\r
- String txt = doc.getRange().getParagraph(0).text();\r
- assertEquals("OLE embedding is thoroughly unremarkable.\r", txt);\r
- }\r
- }\r
-\r
- }\r
- assertEquals("Expected 2 OLE shapes", 2, cnt);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.ObjectData;
+import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hwpf.HWPFDocument;
+
+public final class TestOleEmbedding extends TestCase {
+ /**
+ * Tests support for OLE objects.
+ *
+ * @throws Exception if an error occurs.
+ */
+ public void testOleEmbedding2003() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ File file = new File(dirname, "ole2-embedding-2003.ppt");
+ HSLFSlideShow slideShow = new HSLFSlideShow(new FileInputStream(file));
+ // Placeholder EMFs for clients that don't support the OLE components.
+ PictureData[] pictures = slideShow.getPictures();
+ assertEquals("Should be two pictures", 2, pictures.length);
+ //assertDigestEquals("Wrong data for picture 1", "8d1fbadf4814f321bb1ccdd056e3c788", pictures[0].getData());
+ //assertDigestEquals("Wrong data for picture 2", "987a698e83559cf3d38a0deeba1cc63b", pictures[1].getData());
+
+ // Actual embedded objects.
+ ObjectData[] objects = slideShow.getEmbeddedObjects();
+ assertEquals("Should be two objects", 2, objects.length);
+ //assertDigestEquals("Wrong data for objecs 1", "0d1fcc61a83de5c4894dc0c88e9a019d", objects[0].getData());
+ //assertDigestEquals("Wrong data for object 2", "b323604b2003a7299c77c2693b641495", objects[1].getData());
+ }
+
+ public void testOLEShape() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ File file = new File(dirname, "ole2-embedding-2003.ppt");
+ FileInputStream is = new FileInputStream(file);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Slide slide = ppt.getSlides()[0];
+ Shape[] sh = slide.getShapes();
+ int cnt = 0;
+ for (int i = 0; i < sh.length; i++) {
+ if(sh[i] instanceof OLEShape){
+ cnt++;
+ OLEShape ole = (OLEShape)sh[i];
+ ObjectData data = ole.getObjectData();
+ if("Worksheet".equals(ole.getInstanceName())){
+ //Voila! we created a workbook from the embedded OLE data
+ HSSFWorkbook wb = new HSSFWorkbook(data.getData());
+ HSSFSheet sheet = wb.getSheetAt(0);
+ //verify we can access the xls data
+ assertEquals(1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0);
+ assertEquals(1, sheet.getRow(1).getCell(0).getNumericCellValue(), 0);
+ assertEquals(2, sheet.getRow(2).getCell(0).getNumericCellValue(), 0);
+ assertEquals(3, sheet.getRow(3).getCell(0).getNumericCellValue(), 0);
+ assertEquals(8, sheet.getRow(5).getCell(0).getNumericCellValue(), 0);
+ } else if ("Document".equals(ole.getInstanceName())){
+ //creating a HWPF document
+ HWPFDocument doc = new HWPFDocument(data.getData());
+ String txt = doc.getRange().getParagraph(0).text();
+ assertEquals("OLE embedding is thoroughly unremarkable.\r", txt);
+ }
+ }
+
+ }
+ assertEquals("Expected 2 OLE shapes", 2, cnt);
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-import java.io.IOException;\r
-\r
-/**\r
- * Test adding fonts to the presenataion resources\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TestPPFont extends TestCase{\r
-\r
- public void testCreate() throws IOException {\r
- SlideShow ppt = new SlideShow();\r
- assertEquals(1, ppt.getNumberOfFonts());\r
- assertEquals("Arial", ppt.getFont(0).getFontName());\r
-\r
- //adding the same font twice\r
- assertEquals(0, ppt.addFont(PPFont.ARIAL));\r
- assertEquals(1, ppt.getNumberOfFonts());\r
-\r
- assertEquals(1, ppt.addFont(PPFont.TIMES_NEW_ROMAN));\r
- assertEquals(2, ppt.addFont(PPFont.COURIER_NEW));\r
- assertEquals(3, ppt.addFont(PPFont.WINGDINGS));\r
-\r
- assertEquals(4, ppt.getNumberOfFonts());\r
-\r
- assertEquals(PPFont.TIMES_NEW_ROMAN.getFontName(), ppt.getFont(1).getFontName());\r
- assertEquals(PPFont.COURIER_NEW.getFontName(), ppt.getFont(2).getFontName());\r
-\r
- PPFont font3 = ppt.getFont(3);\r
- assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());\r
- assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());\r
- assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+import java.io.IOException;
+
+/**
+ * Test adding fonts to the presenataion resources
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestPPFont extends TestCase{
+
+ public void testCreate() throws IOException {
+ SlideShow ppt = new SlideShow();
+ assertEquals(1, ppt.getNumberOfFonts());
+ assertEquals("Arial", ppt.getFont(0).getFontName());
+
+ //adding the same font twice
+ assertEquals(0, ppt.addFont(PPFont.ARIAL));
+ assertEquals(1, ppt.getNumberOfFonts());
+
+ assertEquals(1, ppt.addFont(PPFont.TIMES_NEW_ROMAN));
+ assertEquals(2, ppt.addFont(PPFont.COURIER_NEW));
+ assertEquals(3, ppt.addFont(PPFont.WINGDINGS));
+
+ assertEquals(4, ppt.getNumberOfFonts());
+
+ assertEquals(PPFont.TIMES_NEW_ROMAN.getFontName(), ppt.getFont(1).getFontName());
+ assertEquals(PPFont.COURIER_NEW.getFontName(), ppt.getFont(2).getFontName());
+
+ PPFont font3 = ppt.getFont(3);
+ assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());
+ assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());
+ assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());
+ }
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
*
* @author Yegor Kozlov
*/
-public class TestPPGraphics2D extends TestCase {
+public final class TestPPGraphics2D extends TestCase {
private SlideShow ppt;
protected void setUp() throws Exception {
public void testGraphics() throws Exception {
// Starts off empty
assertEquals(0, ppt.getSlides().length);
-
+
// Add a slide
Slide slide = ppt.createSlide();
assertEquals(1, ppt.getSlides().length);
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.*;\r
-\r
-import java.io.FileOutputStream;\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.awt.*;\r
-import java.awt.image.BufferedImage;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.usermodel.PictureData;\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.ddf.EscherBSERecord;\r
-\r
-/**\r
- * Test Picture shape.\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TestPicture extends TestCase {\r
-\r
- /**\r
- * Test that the reference count of a blip is incremented every time the picture is inserted.\r
- * This is important when the same image appears multiple times in a slide show.\r
- *\r
- */\r
- public void testMultiplePictures() throws Exception {\r
- String cwd = System.getProperty("HSLF.testdata.path");\r
- SlideShow ppt = new SlideShow();\r
-\r
- Slide s = ppt.createSlide();\r
- Slide s2 = ppt.createSlide();\r
- Slide s3 = ppt.createSlide();\r
-\r
- int idx = ppt.addPicture(new File(cwd, "clock.jpg"), Picture.JPEG);\r
- Picture pict = new Picture(idx);\r
- Picture pict2 = new Picture(idx);\r
- Picture pict3 = new Picture(idx);\r
-\r
- pict.setAnchor(new Rectangle(10,10,100,100));\r
- s.addShape(pict);\r
- EscherBSERecord bse1 = pict.getEscherBSERecord();\r
- assertEquals(1, bse1.getRef());\r
-\r
- pict2.setAnchor(new Rectangle(10,10,100,100));\r
- s2.addShape(pict2);\r
- EscherBSERecord bse2 = pict.getEscherBSERecord();\r
- assertSame(bse1, bse2);\r
- assertEquals(2, bse1.getRef());\r
-\r
- pict3.setAnchor(new Rectangle(10,10,100,100));\r
- s3.addShape(pict3);\r
- EscherBSERecord bse3 = pict.getEscherBSERecord();\r
- assertSame(bse2, bse3);\r
- assertEquals(3, bse1.getRef());\r
-\r
- }\r
-\r
- /**\r
- * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER\r
- * was not found. The correct behaviour is to return null.\r
- */\r
- public void test46122() throws IOException {\r
- SlideShow ppt = new SlideShow();\r
- Slide slide = ppt.createSlide();\r
-\r
- Picture pict = new Picture(-1); //index to non-existing picture data\r
- pict.setSheet(slide);\r
- PictureData data = pict.getPictureData();\r
- assertNull(data);\r
-\r
- BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);\r
- Graphics2D graphics = img.createGraphics();\r
- pict.draw(graphics);\r
-\r
- assertTrue("no errors rendering Picture with null data", true);\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.*;
+
+import java.io.FileOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.ddf.EscherBSERecord;
+
+/**
+ * Test Picture shape.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestPicture extends TestCase {
+
+ /**
+ * Test that the reference count of a blip is incremented every time the picture is inserted.
+ * This is important when the same image appears multiple times in a slide show.
+ *
+ */
+ public void testMultiplePictures() throws Exception {
+ String cwd = System.getProperty("HSLF.testdata.path");
+ SlideShow ppt = new SlideShow();
+
+ Slide s = ppt.createSlide();
+ Slide s2 = ppt.createSlide();
+ Slide s3 = ppt.createSlide();
+
+ int idx = ppt.addPicture(new File(cwd, "clock.jpg"), Picture.JPEG);
+ Picture pict = new Picture(idx);
+ Picture pict2 = new Picture(idx);
+ Picture pict3 = new Picture(idx);
+
+ pict.setAnchor(new Rectangle(10,10,100,100));
+ s.addShape(pict);
+ EscherBSERecord bse1 = pict.getEscherBSERecord();
+ assertEquals(1, bse1.getRef());
+
+ pict2.setAnchor(new Rectangle(10,10,100,100));
+ s2.addShape(pict2);
+ EscherBSERecord bse2 = pict.getEscherBSERecord();
+ assertSame(bse1, bse2);
+ assertEquals(2, bse1.getRef());
+
+ pict3.setAnchor(new Rectangle(10,10,100,100));
+ s3.addShape(pict3);
+ EscherBSERecord bse3 = pict.getEscherBSERecord();
+ assertSame(bse2, bse3);
+ assertEquals(3, bse1.getRef());
+
+ }
+
+ /**
+ * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER
+ * was not found. The correct behaviour is to return null.
+ */
+ public void test46122() throws IOException {
+ SlideShow ppt = new SlideShow();
+ Slide slide = ppt.createSlide();
+
+ Picture pict = new Picture(-1); //index to non-existing picture data
+ pict.setSheet(slide);
+ PictureData data = pict.getPictureData();
+ assertNull(data);
+
+ BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = img.createGraphics();
+ pict.draw(graphics);
+
+ assertTrue("no errors rendering Picture with null data", true);
+ }
+
+}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
*
* @author Yegor Kozlov
*/
-public class TestSetBoldItalic extends TestCase {
+public final class TestSetBoldItalic extends TestCase {
/**
* Verify that we can add TextBox shapes to a slide
* and set some of the style attributes
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
*
* @author Yegor Kozlov
*/
-public class TestShapes extends TestCase {
+public final class TestShapes extends TestCase {
private SlideShow ppt;
private SlideShow pptB;
String dirname = System.getProperty("HSLF.testdata.path");
String filename = dirname + "/empty.ppt";
ppt = new SlideShow(new HSLFSlideShow(filename));
-
+
String filenameB = dirname + "/empty_textbox.ppt";
pptB = new SlideShow(new HSLFSlideShow(filenameB));
}
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
sl = ppt.getSlides()[0];
-
+
txtbox = (TextBox)sl.getShapes()[0];
rt = txtbox.getTextRun().getRichTextRuns()[0];
assertEquals("Arial", rt.getFontName());
assertEquals(Color.red, rt.getFontColor());
}
-
+
/**
* Test with an empty text box
*/
assertEquals(2, pptB.getSlides().length);
Slide s1 = pptB.getSlides()[0];
Slide s2 = pptB.getSlides()[1];
-
+
// Check we can get the shapes count
assertEquals(2, s1.getShapes().length);
assertEquals(2, s2.getShapes().length);
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import java.io.FileInputStream;\r
-import java.io.File;\r
-\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;\r
-import org.apache.poi.hslf.record.ColorSchemeAtom;\r
-import org.apache.poi.hslf.record.PPDrawing;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-/**\r
- * Test common functionality of the <code>Sheet</code> object.\r
- * For each ppt in the test directory check that all sheets are properly initialized\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestSheet extends TestCase{\r
-\r
- /**\r
- * For each ppt in the test directory check that all sheets are properly initialized\r
- */\r
- public void testSheet() throws Exception {\r
- File home = new File(System.getProperty("HSLF.testdata.path"));\r
- File[] files = home.listFiles();\r
- for (int i = 0; i < files.length; i++) {\r
- if(!files[i].getName().endsWith(".ppt")) continue;\r
- if(files[i].getName().endsWith("PPT95.ppt")) continue;\r
- \r
- try {\r
- FileInputStream is = new FileInputStream(files[i]);\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- doSlideShow(ppt);\r
- } catch (EncryptedPowerPointFileException e){\r
- ; //skip encrypted ppt\r
- }\r
- }\r
- }\r
-\r
- private void doSlideShow(SlideShow ppt) throws Exception {\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- verify(slide[i]);\r
-\r
- Notes notes = slide[i].getNotesSheet();\r
- if(notes != null) verify(notes);\r
-\r
- MasterSheet master = slide[i].getMasterSheet();\r
- assertNotNull(master);\r
- verify(master);\r
- }\r
- }\r
-\r
- private void verify(Sheet sheet){\r
- assertNotNull(sheet.getSlideShow());\r
-\r
- ColorSchemeAtom colorscheme = sheet.getColorScheme();\r
- assertNotNull(colorscheme);\r
-\r
- PPDrawing ppdrawing = sheet.getPPDrawing();\r
- assertNotNull(ppdrawing);\r
-\r
- Background background = sheet.getBackground();\r
- assertNotNull(background);\r
-\r
- assertTrue(sheet._getSheetNumber() != 0);\r
- assertTrue(sheet._getSheetRefId() != 0);\r
-\r
- TextRun[] txt = sheet.getTextRuns();\r
- assertTrue(txt != null);\r
- for (int i = 0; i < txt.length; i++) {\r
- assertNotNull(txt[i].getSheet());\r
- }\r
-\r
- Shape[] shape = sheet.getShapes();\r
- assertTrue(shape != null);\r
- for (int i = 0; i < shape.length; i++) {\r
- assertNotNull(shape[i].getSpContainer());\r
- assertNotNull(shape[i].getSheet());\r
- assertNotNull(shape[i].getShapeName());\r
- assertNotNull(shape[i].getAnchor());\r
- }\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+
+import java.io.FileInputStream;
+import java.io.File;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.hslf.record.PPDrawing;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+/**
+ * Test common functionality of the <code>Sheet</code> object.
+ * For each ppt in the test directory check that all sheets are properly initialized
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestSheet extends TestCase{
+
+ /**
+ * For each ppt in the test directory check that all sheets are properly initialized
+ */
+ public void testSheet() throws Exception {
+ File home = new File(System.getProperty("HSLF.testdata.path"));
+ File[] files = home.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if(!files[i].getName().endsWith(".ppt")) continue;
+ if(files[i].getName().endsWith("PPT95.ppt")) continue;
+
+ try {
+ FileInputStream is = new FileInputStream(files[i]);
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ doSlideShow(ppt);
+ } catch (EncryptedPowerPointFileException e){
+ ; //skip encrypted ppt
+ }
+ }
+ }
+
+ private void doSlideShow(SlideShow ppt) throws Exception {
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ verify(slide[i]);
+
+ Notes notes = slide[i].getNotesSheet();
+ if(notes != null) verify(notes);
+
+ MasterSheet master = slide[i].getMasterSheet();
+ assertNotNull(master);
+ verify(master);
+ }
+ }
+
+ private void verify(Sheet sheet){
+ assertNotNull(sheet.getSlideShow());
+
+ ColorSchemeAtom colorscheme = sheet.getColorScheme();
+ assertNotNull(colorscheme);
+
+ PPDrawing ppdrawing = sheet.getPPDrawing();
+ assertNotNull(ppdrawing);
+
+ Background background = sheet.getBackground();
+ assertNotNull(background);
+
+ assertTrue(sheet._getSheetNumber() != 0);
+ assertTrue(sheet._getSheetRefId() != 0);
+
+ TextRun[] txt = sheet.getTextRuns();
+ assertTrue(txt != null);
+ for (int i = 0; i < txt.length; i++) {
+ assertNotNull(txt[i].getSheet());
+ }
+
+ Shape[] shape = sheet.getShapes();
+ assertTrue(shape != null);
+ for (int i = 0; i < shape.length; i++) {
+ assertNotNull(shape[i].getSpContainer());
+ assertNotNull(shape[i].getSheet());
+ assertNotNull(shape[i].getShapeName());
+ assertNotNull(shape[i].getAnchor());
+ }
+
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.model;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestSlideChangeNotes extends TestCase {
+public final class TestSlideChangeNotes extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
/**
* Tests for SlideMaster
- *
+ *
* @author Yegor Kozlov
*/
-public class TestSlideMaster extends TestCase{
+public final class TestSlideMaster extends TestCase{
String home;
public void setUp() throws Exception {
/**
* Test adding new slides to a ppt.
- *
- * Note - uses the same empty PPT file as the core "new Slideshow"
+ *
+ * Note - uses the same empty PPT file as the core "new Slideshow"
* stuff does
* @author Yegor Kozlov
*/
-public class TestSlides extends TestCase {
+public final class TestSlides extends TestCase {
/**
* Add 1 slide to an empty ppt.
public void testAddSlides1() throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
assertTrue(ppt.getSlides().length == 0);
-
+
Slide s1 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 1);
assertEquals(3, s1._getSheetRefId());
public void testAddSlides2() throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
assertTrue(ppt.getSlides().length == 0);
-
+
Slide s1 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 1);
assertEquals(3, s1._getSheetRefId());
assertEquals(256, s1._getSheetNumber());
assertEquals(1, s1.getSlideNumber());
-
+
Slide s2 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 2);
assertEquals(4, s2._getSheetRefId());
public void testAddSlides3() throws Exception {
SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
assertTrue(ppt.getSlides().length == 0);
-
+
Slide s1 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 1);
assertEquals(3, s1._getSheetRefId());
assertEquals(256, s1._getSheetNumber());
assertEquals(1, s1.getSlideNumber());
-
+
Slide s2 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 2);
assertEquals(4, s2._getSheetRefId());
assertEquals(258, s3._getSheetNumber());
assertEquals(3, s3.getSlideNumber());
-
+
//serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
assertTrue(ppt.getSlides().length == 3);
-
+
// Check IDs are still right
s1 = ppt.getSlides()[0];
assertEquals(256, s1._getSheetNumber());
public void testAddSlides2to3() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/basic_test_ppt_file.ppt"));
-
+
assertTrue(ppt.getSlides().length == 2);
-
+
// First slide is 256 / 4
Slide s1 = ppt.getSlides()[0];
assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId());
-
+
// Last slide is 257 / 6
Slide s2 = ppt.getSlides()[1];
assertEquals(257, s2._getSheetNumber());
assertEquals(6, s2._getSheetRefId());
-
+
// Add another slide, goes in at the end
Slide s3 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 3);
assertEquals(258, s3._getSheetNumber());
assertEquals(8, s3._getSheetRefId());
-
+
// Serialize and read again
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
assertTrue(ppt.getSlides().length == 3);
-
-
+
+
// Check IDs are still right
s1 = ppt.getSlides()[0];
assertEquals(256, s1._getSheetNumber());
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import java.io.*;\r
-import java.awt.*;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.record.TextHeaderAtom;\r
-\r
-/**\r
- * Test <code>Table</code> object.\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TestTable extends TestCase {\r
-\r
- /**\r
- * Test that ShapeFactory works properly and returns <code>Table</code>\r
- */\r
- public void testShapeFactory() throws Exception {\r
- SlideShow ppt = new SlideShow();\r
-\r
- Slide slide = ppt.createSlide();\r
-\r
- Table tbl = new Table(2, 5);\r
- slide.addShape(tbl);\r
-\r
- TableCell cell = tbl.getCell(0, 0);\r
- //table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033\r
- assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextRun().getRunType());\r
-\r
- assertTrue(slide.getShapes()[0] instanceof Table);\r
- Table tbl2 = (Table)slide.getShapes()[0];\r
- assertEquals(tbl.getNumberOfColumns(), tbl2.getNumberOfColumns());\r
- assertEquals(tbl.getNumberOfRows(), tbl2.getNumberOfRows());\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ppt.write(out);\r
- out.close();\r
-\r
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));\r
- slide = ppt.getSlides()[0];\r
- assertTrue(slide.getShapes()[0] instanceof Table);\r
- Table tbl3 = (Table)slide.getShapes()[0];\r
- assertEquals(tbl.getNumberOfColumns(), tbl3.getNumberOfColumns());\r
- assertEquals(tbl.getNumberOfRows(), tbl3.getNumberOfRows());\r
- }\r
-\r
- /**\r
- * Error constructing Table when rownum=1\r
- */\r
- public void test45889(){\r
- SlideShow ppt = new SlideShow();\r
- Slide slide = ppt.createSlide();\r
- Shape[] shapes;\r
- Table tbl1 = new Table(1, 5);\r
- assertEquals(5, tbl1.getNumberOfColumns());\r
- assertEquals(1, tbl1.getNumberOfRows());\r
- slide.addShape(tbl1);\r
-\r
- shapes = slide.getShapes();\r
- assertEquals(1, shapes.length);\r
-\r
- Table tbl2 = (Table)shapes[0];\r
- assertSame(tbl1.getSpContainer(), tbl2.getSpContainer());\r
-\r
- assertEquals(tbl1.getNumberOfColumns(), tbl2.getNumberOfColumns());\r
- assertEquals(tbl1.getNumberOfRows(), tbl2.getNumberOfRows());\r
- }\r
-\r
- public void testIllegalCOnstruction(){\r
- try {\r
- Table tbl = new Table(0, 5);\r
- fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");\r
- } catch (IllegalArgumentException e){\r
-\r
- }\r
- try {\r
- Table tbl = new Table(5, 0);\r
- fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");\r
- } catch (IllegalArgumentException e){\r
-\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+/**
+ * Test <code>Table</code> object.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestTable extends TestCase {
+
+ /**
+ * Test that ShapeFactory works properly and returns <code>Table</code>
+ */
+ public void testShapeFactory() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ Table tbl = new Table(2, 5);
+ slide.addShape(tbl);
+
+ TableCell cell = tbl.getCell(0, 0);
+ //table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033
+ assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextRun().getRunType());
+
+ assertTrue(slide.getShapes()[0] instanceof Table);
+ Table tbl2 = (Table)slide.getShapes()[0];
+ assertEquals(tbl.getNumberOfColumns(), tbl2.getNumberOfColumns());
+ assertEquals(tbl.getNumberOfRows(), tbl2.getNumberOfRows());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ slide = ppt.getSlides()[0];
+ assertTrue(slide.getShapes()[0] instanceof Table);
+ Table tbl3 = (Table)slide.getShapes()[0];
+ assertEquals(tbl.getNumberOfColumns(), tbl3.getNumberOfColumns());
+ assertEquals(tbl.getNumberOfRows(), tbl3.getNumberOfRows());
+ }
+
+ /**
+ * Error constructing Table when rownum=1
+ */
+ public void test45889(){
+ SlideShow ppt = new SlideShow();
+ Slide slide = ppt.createSlide();
+ Shape[] shapes;
+ Table tbl1 = new Table(1, 5);
+ assertEquals(5, tbl1.getNumberOfColumns());
+ assertEquals(1, tbl1.getNumberOfRows());
+ slide.addShape(tbl1);
+
+ shapes = slide.getShapes();
+ assertEquals(1, shapes.length);
+
+ Table tbl2 = (Table)shapes[0];
+ assertSame(tbl1.getSpContainer(), tbl2.getSpContainer());
+
+ assertEquals(tbl1.getNumberOfColumns(), tbl2.getNumberOfColumns());
+ assertEquals(tbl1.getNumberOfRows(), tbl2.getNumberOfRows());
+ }
+
+ public void testIllegalCOnstruction(){
+ try {
+ Table tbl = new Table(0, 5);
+ fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
+ } catch (IllegalArgumentException e){
+
+ }
+ try {
+ Table tbl = new Table(5, 0);
+ fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1");
+ } catch (IllegalArgumentException e){
+
+ }
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.model;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestTextRun extends TestCase {
+public final class TestTextRun extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
private SlideShow ssRich;
protected void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
-
+
// Basic (non rich) test file
String filename = dirname + "/basic_test_ppt_file.ppt";
hss = new HSLFSlideShow(filename);
ss = new SlideShow(hss);
-
+
// Rich test file
filename = dirname + "/Single_Coloured_Page.ppt";
hssRich = new HSLFSlideShow(filename);
TextRun[] textRuns = slideOne.getTextRuns();
assertEquals(2, textRuns.length);
-
+
// Get text works with \n
assertEquals("This is a test title", textRuns[0].getText());
assertEquals("This is a test subtitle\nThis is on page 1", textRuns[1].getText());
-
+
// Raw text has \r instead
assertEquals("This is a test title", textRuns[0].getRawText());
assertEquals("This is a test subtitle\rThis is on page 1", textRuns[1].getRawText());
-
-
+
+
// Now check on a rich text run
Slide slideOneR = ssRich.getSlides()[0];
TextRun[] textRunsR = slideOneR.getTextRuns();
assertEquals("This is a title, it\u2019s in black", textRunsR[0].getRawText());
assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", textRunsR[1].getRawText());
}
-
+
/**
* Test to ensure changing non rich text bytes->bytes works correctly
*/
// Check current text
assertEquals("This is a test title", run.getText());
-
+
// Change
String changeTo = "New test title";
run.setText(changeTo);
assertEquals(changeTo, run.getText());
-
+
// Ensure trailing \n's get stripped
run.setText(changeTo + "\n");
assertEquals(changeTo, run.getText());
public void testAdvancedSetText() throws Exception {
Slide slideOne = ss.getSlides()[0];
TextRun run = slideOne.getTextRuns()[0];
-
+
TextHeaderAtom tha = run._headerAtom;
TextBytesAtom tba = run._byteAtom;
TextCharsAtom tca = run._charAtom;
assertNotNull(tba);
assertFalse(run._isUnicode);
assertEquals("This is a test title", run.getText());
-
+
String changeBytesOnly = "New Test Title";
run.setText(changeBytesOnly);
tba = run._byteAtom;
tca = run._charAtom;
-
+
assertEquals(changeBytesOnly, run.getText());
assertFalse(run._isUnicode);
assertNull(tca);
assertNotNull(tba);
-
+
// Bytes -> Chars
assertNull(tca);
assertNotNull(tba);
assertFalse(run._isUnicode);
assertEquals(changeBytesOnly, run.getText());
-
+
String changeByteChar = "This is a test title with a '\u0121' g with a dot";
run.setText(changeByteChar);
tba = run._byteAtom;
tca = run._charAtom;
-
+
assertEquals(changeByteChar, run.getText());
assertTrue(run._isUnicode);
assertNotNull(tca);
assertNull(tba);
-
+
// Chars -> Chars
assertNull(tba);
assertNotNull(tca);
assertTrue(run._isUnicode);
assertEquals(changeByteChar, run.getText());
-
+
String changeCharChar = "This is a test title with a '\u0147' N with a hat";
run.setText(changeCharChar);
tba = run._byteAtom;
tca = run._charAtom;
-
+
assertEquals(changeCharChar, run.getText());
assertTrue(run._isUnicode);
assertNotNull(tca);
assertNull(tba);
}
-
+
/**
* Tests to ensure that non rich text has the right default rich text run
* set up for it
TextRun trA = textRuns[0];
TextRun trB = textRuns[1];
-
+
assertEquals(1, trA.getRichTextRuns().length);
assertEquals(1, trB.getRichTextRuns().length);
-
+
RichTextRun rtrA = trA.getRichTextRuns()[0];
RichTextRun rtrB = trB.getRichTextRuns()[0];
-
+
assertEquals(trA.getText(), rtrA.getText());
assertEquals(trB.getText(), rtrB.getText());
-
+
assertNull(rtrA._getRawCharacterStyle());
assertNull(rtrA._getRawParagraphStyle());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
}
-
+
/**
* Tests to ensure that the rich text runs are built up correctly
*/
TextRun trA = textRuns[0];
TextRun trB = textRuns[1];
-
+
assertEquals(1, trA.getRichTextRuns().length);
assertEquals(3, trB.getRichTextRuns().length);
-
+
RichTextRun rtrA = trA.getRichTextRuns()[0];
RichTextRun rtrB = trB.getRichTextRuns()[0];
RichTextRun rtrC = trB.getRichTextRuns()[1];
RichTextRun rtrD = trB.getRichTextRuns()[2];
-
+
assertEquals(trA.getText(), rtrA.getText());
-
+
assertEquals(trB.getText().substring(0, 30), rtrB.getText());
assertEquals(trB.getText().substring(30,58), rtrC.getText());
assertEquals(trB.getText().substring(58,82), rtrD.getText());
-
+
assertNull(rtrA._getRawCharacterStyle());
assertNull(rtrA._getRawParagraphStyle());
assertNotNull(rtrB._getRawCharacterStyle());
assertNotNull(rtrC._getRawParagraphStyle());
assertNotNull(rtrD._getRawCharacterStyle());
assertNotNull(rtrD._getRawParagraphStyle());
-
+
// Same paragraph styles
assertEquals(rtrB._getRawParagraphStyle(), rtrC._getRawParagraphStyle());
assertEquals(rtrB._getRawParagraphStyle(), rtrD._getRawParagraphStyle());
-
+
// Different char styles
assertFalse( rtrB._getRawCharacterStyle().equals( rtrC._getRawCharacterStyle() ));
assertFalse( rtrB._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
assertFalse( rtrC._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
}
-
+
/**
* Tests to ensure that setting the text where the text isn't rich,
* ensuring that everything stays with the same default styling
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(1, trB.getRichTextRuns().length);
-
+
RichTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
-
+
// Change text via normal
trB.setText("Test Foo Test");
rtrB = trB.getRichTextRuns()[0];
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
}
-
+
/**
* Tests to ensure that setting the text where the text is rich
* sets everything to the same styling
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(3, trB.getRichTextRuns().length);
-
+
RichTextRun rtrB = trB.getRichTextRuns()[0];
RichTextRun rtrC = trB.getRichTextRuns()[1];
RichTextRun rtrD = trB.getRichTextRuns()[2];
TextPropCollection tpCC = rtrC._getRawCharacterStyle();
TextPropCollection tpDP = rtrD._getRawParagraphStyle();
TextPropCollection tpDC = rtrD._getRawCharacterStyle();
-
+
assertEquals(trB.getText().substring(0, 30), rtrB.getText());
assertNotNull(tpBP);
assertNotNull(tpBC);
assertFalse(tpBC.equals(tpCC));
assertFalse(tpBC.equals(tpDC));
assertFalse(tpCC.equals(tpDC));
-
+
// Change text via normal
trB.setText("Test Foo Test");
-
+
// Ensure now have first style
assertEquals(1, trB.getRichTextRuns().length);
rtrB = trB.getRichTextRuns()[0];
assertEquals( tpBP, rtrB._getRawParagraphStyle() );
assertEquals( tpBC, rtrB._getRawCharacterStyle() );
}
-
+
/**
* Test to ensure the right stuff happens if we change the text
* in a rich text run, that doesn't happen to actually be rich
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(1, trB.getRichTextRuns().length);
-
+
RichTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
-
+
// Change text via rich
rtrB.setText("Test Test Test");
assertEquals("Test Test Test", trB.getText());
assertEquals("Test Test Test", rtrB.getText());
-
+
// Will now have dummy props
assertNotNull(rtrB._getRawCharacterStyle());
assertNotNull(rtrB._getRawParagraphStyle());
TextRun[] textRuns = slideOne.getTextRuns();
TextRun trB = textRuns[1];
assertEquals(3, trB.getRichTextRuns().length);
-
+
// We start with 3 text runs, each with their own set of styles,
// but all sharing the same paragraph styles
RichTextRun rtrB = trB.getRichTextRuns()[0];
TextPropCollection tpCC = rtrC._getRawCharacterStyle();
TextPropCollection tpDP = rtrD._getRawParagraphStyle();
TextPropCollection tpDC = rtrD._getRawCharacterStyle();
-
+
// Check text and stylings
assertEquals(trB.getText().substring(0, 30), rtrB.getText());
assertNotNull(tpBP);
assertFalse(tpBC.equals(tpCC));
assertFalse(tpBC.equals(tpDC));
assertFalse(tpCC.equals(tpDC));
-
+
// Check text in the rich runs
assertEquals("This is the subtitle, in bold\n", rtrB.getText());
assertEquals("This bit is blue and italic\n", rtrC.getText());
assertEquals("This bit is red (normal)", rtrD.getText());
-
+
String newBText = "New Subtitle, will still be bold\n";
String newCText = "New blue and italic text\n";
String newDText = "Funky new normal red text";
assertEquals(newBText, rtrB.getText());
assertEquals(newCText, rtrC.getText());
assertEquals(newDText, rtrD.getText());
-
+
assertEquals(newBText + newCText + newDText, trB.getText());
-
+
// The styles should have been updated for the new sizes
assertEquals(newBText.length(), tpBC.getCharactersCovered());
assertEquals(newCText.length(), tpCC.getCharactersCovered());
assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger
-
+
assertEquals(
- newBText.length() + newCText.length() + newDText.length(),
+ newBText.length() + newCText.length() + newDText.length(),
tpBP.getCharactersCovered()
);
-
+
// Paragraph style should be sum of text length
assertEquals(newBText.length() + newCText.length() + newDText.length(), tpBP.getCharactersCovered());
-
+
// Check stylings still as expected
TextPropCollection ntpBC = rtrB._getRawCharacterStyle();
TextPropCollection ntpCC = rtrC._getRawCharacterStyle();
assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
}
-
+
/**
* Test case for Bug 41015.
*/
public void testBug41015() throws Exception {
RichTextRun[] rt;
-
+
SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/bug-41015.ppt"));
Slide sl = ppt.getSlides()[0];
TextRun[] txt = sl.getTextRuns();
assertEquals(2, txt.length);
-
+
rt = txt[0].getRichTextRuns();
assertEquals(1, rt.length);
assertEquals(0, rt[0].getIndentLevel());
assertEquals("sdfsdfsdf", rt[0].getText());
-
+
rt = txt[1].getRichTextRuns();
assertEquals(2, rt.length);
assertEquals(0, rt[0].getIndentLevel());
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.model;
/**
* Tests that if we load something up, get a TextRun, set the text
* to be the same as it was before, and write it all back out again,
- * that we don't break anything in the process.
+ * that we don't break anything in the process.
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestTextRunReWrite extends TestCase {
+public final class TestTextRunReWrite extends TestCase {
// HSLFSlideShow primed on the test data
private HSLFSlideShow hss;
// HSLFSlideShow primed on the test data
// Grab the first text run on the first sheet
TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
TextRun tr2 = ss.getSlides()[0].getTextRuns()[1];
-
+
// Ensure the text lengths are as we'd expect to start with
assertEquals(1, ss.getSlides().length);
assertEquals(2, ss.getSlides()[0].getTextRuns().length);
assertEquals(30, tr1.getText().length());
assertEquals(179, tr2.getText().length());
-
+
assertEquals(1, tr1.getRichTextRuns().length);
assertEquals(30, tr1.getRichTextRuns()[0].getLength());
assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
assertEquals(31, tr1.getRichTextRuns()[0]._getRawCharacterStyle().getCharactersCovered());
assertEquals(31, tr1.getRichTextRuns()[0]._getRawParagraphStyle().getCharactersCovered());
-
+
// Set the text to be as it is now
tr1.setText( tr1.getText() );
-
+
// Check the text lengths are still right
assertEquals(30, tr1.getText().length());
assertEquals(179, tr2.getText().length());
-
+
assertEquals(1, tr1.getRichTextRuns().length);
assertEquals(30, tr1.getRichTextRuns()[0].getLength());
assertEquals(30, tr1.getRichTextRuns()[0].getText().length());
assertEquals(31, tr1.getRichTextRuns()[0]._getRawCharacterStyle().getCharactersCovered());
assertEquals(31, tr1.getRichTextRuns()[0]._getRawParagraphStyle().getCharactersCovered());
-
-
+
+
// Write the slideshow out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ss.write(baos);
public void testWritesOutTheSameRich() throws Exception {
// Grab the first text run on the first sheet
TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
-
+
// Get the first rich text run
RichTextRun rtr1 = tr1.getRichTextRuns()[0];
-
-
+
+
// Check that the text sizes are as expected
assertEquals(1, tr1.getRichTextRuns().length);
assertEquals(30, tr1.getText().length());
assertEquals(30, rtr1.getText().length());
assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
-
+
// Set the text to be as it is now
rtr1.setText( rtr1.getText() );
rtr1 = tr1.getRichTextRuns()[0];
-
+
// Check that the text sizes are still as expected
assertEquals(1, tr1.getRichTextRuns().length);
assertEquals(30, tr1.getText().length());
assertEquals(30, rtr1.getText().length());
assertEquals(31, rtr1._getRawCharacterStyle().getCharactersCovered());
assertEquals(31, rtr1._getRawParagraphStyle().getCharactersCovered());
-
-
+
+
// Write the slideshow out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ss.write(baos);
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-\r
-package org.apache.poi.hslf.model;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import java.io.*;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.hslf.record.TextHeaderAtom;\r
-\r
-/**\r
- * Verify behavior of <code>TextShape</code> and its sub-classes\r
- * \r
- * @author Yegor Kozlov\r
- */\r
-public class TestTextShape extends TestCase {\r
- protected String cwd = System.getProperty("HSLF.testdata.path");\r
-\r
- public void testCreateAutoShape(){\r
- TextShape shape = new AutoShape(ShapeTypes.Trapezoid);\r
- assertNull(shape.getTextRun());\r
- assertNull(shape.getText());\r
- assertNull(shape.getEscherTextboxWrapper());\r
-\r
- TextRun run = shape.createTextRun();\r
- assertNotNull(run);\r
- assertNotNull(shape.getTextRun());\r
- assertNotNull(shape.getEscherTextboxWrapper());\r
- assertEquals("", shape.getText());\r
- assertSame(run, shape.createTextRun());\r
-\r
- }\r
-\r
- public void testCreateTextBox(){\r
- TextShape shape = new TextBox();\r
- TextRun run = shape.getTextRun();\r
- assertNotNull(run);\r
- assertNotNull(shape.getText());\r
- assertNotNull(shape.getEscherTextboxWrapper());\r
-\r
- assertSame(run, shape.createTextRun());\r
- assertNotNull(shape.getTextRun());\r
- assertNotNull(shape.getEscherTextboxWrapper());\r
- assertEquals("", shape.getText());\r
-\r
- }\r
-\r
- /**\r
- * Verify we can get text from TextShape in the following cases:\r
- * - placeholders\r
- * - normal TextBox object\r
- * - text in auto-shapes\r
- */\r
- public void testRead() throws IOException {\r
- FileInputStream is = new FileInputStream(new File(cwd, "text_shapes.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- ArrayList lst1 = new ArrayList();\r
- Slide slide = ppt.getSlides()[0];\r
- Shape[] shape = slide.getShapes();\r
- for (int i = 0; i < shape.length; i++) {\r
- assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof TextShape);\r
- TextShape tx = (TextShape)shape[i];\r
- TextRun run = tx.getTextRun();\r
- assertNotNull(run);\r
- int runType = run.getRunType();\r
-\r
- int type = shape[i].getShapeType();\r
- switch (type){\r
- case ShapeTypes.TextBox:\r
- assertEquals("Text in a TextBox", run.getText());\r
- break;\r
- case ShapeTypes.Rectangle:\r
- if(runType == TextHeaderAtom.OTHER_TYPE)\r
- assertEquals("Rectangle", run.getText());\r
- else if(runType == TextHeaderAtom.TITLE_TYPE)\r
- assertEquals("Title Placeholder", run.getText());\r
- break;\r
- case ShapeTypes.Octagon:\r
- assertEquals("Octagon", run.getText());\r
- break;\r
- case ShapeTypes.Ellipse:\r
- assertEquals("Ellipse", run.getText());\r
- break;\r
- case ShapeTypes.RoundRectangle:\r
- assertEquals("RoundRectangle", run.getText());\r
- break;\r
- default:\r
- fail("Unexpected shape: " + shape[i].getShapeName());\r
-\r
- }\r
- lst1.add(run.getText());\r
- }\r
-\r
- ArrayList lst2 = new ArrayList();\r
- TextRun[] run = slide.getTextRuns();\r
- for (int i = 0; i < run.length; i++) {\r
- lst2.add(run[i].getText());\r
- }\r
-\r
- assertTrue(lst1.containsAll(lst2));\r
- }\r
-\r
- public void testReadWrite() throws IOException {\r
- SlideShow ppt = new SlideShow();\r
- Slide slide = ppt.createSlide();\r
-\r
- TextShape shape1 = new TextBox();\r
- TextRun run1 = shape1.createTextRun();\r
- run1.setText("Hello, World!");\r
- slide.addShape(shape1);\r
-\r
- shape1.moveTo(100, 100);\r
-\r
- TextShape shape2 = new AutoShape(ShapeTypes.Arrow);\r
- TextRun run2 = shape2.createTextRun();\r
- run2.setText("Testing TextShape");\r
- slide.addShape(shape2);\r
- shape2.moveTo(300, 300);\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ppt.write(out);\r
- out.close();\r
-\r
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));\r
- slide = ppt.getSlides()[0];\r
- Shape[] shape = slide.getShapes();\r
-\r
- assertTrue(shape[0] instanceof TextShape);\r
- shape1 = (TextShape)shape[0];\r
- assertEquals(ShapeTypes.TextBox, shape1.getShapeType());\r
- assertEquals("Hello, World!", shape1.getTextRun().getText());\r
-\r
- assertTrue(shape[1] instanceof TextShape);\r
- shape1 = (TextShape)shape[1];\r
- assertEquals(ShapeTypes.Arrow, shape1.getShapeType());\r
- assertEquals("Testing TextShape", shape1.getTextRun().getText());\r
- }\r
-\r
- public void testMargins() throws IOException {\r
- FileInputStream is = new FileInputStream(new File(cwd, "text-margins.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- Slide slide = ppt.getSlides()[0];\r
-\r
- HashMap map = new HashMap();\r
- Shape[] shape = slide.getShapes();\r
- for (int i = 0; i < shape.length; i++) {\r
- if(shape[i] instanceof TextShape){\r
- TextShape tx = (TextShape)shape[i];\r
- map.put(tx.getText(), tx);\r
- }\r
- }\r
-\r
- TextShape tx;\r
-\r
- tx = (TextShape)map.get("TEST1");\r
- assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.39, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
-\r
- tx = (TextShape)map.get("TEST2");\r
- assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.39, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
-\r
- tx = (TextShape)map.get("TEST3");\r
- assertEquals(0.39, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
-\r
- tx = (TextShape)map.get("TEST4");\r
- assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.39, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+/**
+ * Verify behavior of <code>TextShape</code> and its sub-classes
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestTextShape extends TestCase {
+ protected String cwd = System.getProperty("HSLF.testdata.path");
+
+ public void testCreateAutoShape(){
+ TextShape shape = new AutoShape(ShapeTypes.Trapezoid);
+ assertNull(shape.getTextRun());
+ assertNull(shape.getText());
+ assertNull(shape.getEscherTextboxWrapper());
+
+ TextRun run = shape.createTextRun();
+ assertNotNull(run);
+ assertNotNull(shape.getTextRun());
+ assertNotNull(shape.getEscherTextboxWrapper());
+ assertEquals("", shape.getText());
+ assertSame(run, shape.createTextRun());
+
+ }
+
+ public void testCreateTextBox(){
+ TextShape shape = new TextBox();
+ TextRun run = shape.getTextRun();
+ assertNotNull(run);
+ assertNotNull(shape.getText());
+ assertNotNull(shape.getEscherTextboxWrapper());
+
+ assertSame(run, shape.createTextRun());
+ assertNotNull(shape.getTextRun());
+ assertNotNull(shape.getEscherTextboxWrapper());
+ assertEquals("", shape.getText());
+
+ }
+
+ /**
+ * Verify we can get text from TextShape in the following cases:
+ * - placeholders
+ * - normal TextBox object
+ * - text in auto-shapes
+ */
+ public void testRead() throws IOException {
+ FileInputStream is = new FileInputStream(new File(cwd, "text_shapes.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ ArrayList lst1 = new ArrayList();
+ Slide slide = ppt.getSlides()[0];
+ Shape[] shape = slide.getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof TextShape);
+ TextShape tx = (TextShape)shape[i];
+ TextRun run = tx.getTextRun();
+ assertNotNull(run);
+ int runType = run.getRunType();
+
+ int type = shape[i].getShapeType();
+ switch (type){
+ case ShapeTypes.TextBox:
+ assertEquals("Text in a TextBox", run.getText());
+ break;
+ case ShapeTypes.Rectangle:
+ if(runType == TextHeaderAtom.OTHER_TYPE)
+ assertEquals("Rectangle", run.getText());
+ else if(runType == TextHeaderAtom.TITLE_TYPE)
+ assertEquals("Title Placeholder", run.getText());
+ break;
+ case ShapeTypes.Octagon:
+ assertEquals("Octagon", run.getText());
+ break;
+ case ShapeTypes.Ellipse:
+ assertEquals("Ellipse", run.getText());
+ break;
+ case ShapeTypes.RoundRectangle:
+ assertEquals("RoundRectangle", run.getText());
+ break;
+ default:
+ fail("Unexpected shape: " + shape[i].getShapeName());
+
+ }
+ lst1.add(run.getText());
+ }
+
+ ArrayList lst2 = new ArrayList();
+ TextRun[] run = slide.getTextRuns();
+ for (int i = 0; i < run.length; i++) {
+ lst2.add(run[i].getText());
+ }
+
+ assertTrue(lst1.containsAll(lst2));
+ }
+
+ public void testReadWrite() throws IOException {
+ SlideShow ppt = new SlideShow();
+ Slide slide = ppt.createSlide();
+
+ TextShape shape1 = new TextBox();
+ TextRun run1 = shape1.createTextRun();
+ run1.setText("Hello, World!");
+ slide.addShape(shape1);
+
+ shape1.moveTo(100, 100);
+
+ TextShape shape2 = new AutoShape(ShapeTypes.Arrow);
+ TextRun run2 = shape2.createTextRun();
+ run2.setText("Testing TextShape");
+ slide.addShape(shape2);
+ shape2.moveTo(300, 300);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ slide = ppt.getSlides()[0];
+ Shape[] shape = slide.getShapes();
+
+ assertTrue(shape[0] instanceof TextShape);
+ shape1 = (TextShape)shape[0];
+ assertEquals(ShapeTypes.TextBox, shape1.getShapeType());
+ assertEquals("Hello, World!", shape1.getTextRun().getText());
+
+ assertTrue(shape[1] instanceof TextShape);
+ shape1 = (TextShape)shape[1];
+ assertEquals(ShapeTypes.Arrow, shape1.getShapeType());
+ assertEquals("Testing TextShape", shape1.getTextRun().getText());
+ }
+
+ public void testMargins() throws IOException {
+ FileInputStream is = new FileInputStream(new File(cwd, "text-margins.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Slide slide = ppt.getSlides()[0];
+
+ HashMap map = new HashMap();
+ Shape[] shape = slide.getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ if(shape[i] instanceof TextShape){
+ TextShape tx = (TextShape)shape[i];
+ map.put(tx.getText(), tx);
+ }
+ }
+
+ TextShape tx;
+
+ tx = (TextShape)map.get("TEST1");
+ assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.39, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+
+ tx = (TextShape)map.get("TEST2");
+ assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.39, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+
+ tx = (TextShape)map.get("TEST3");
+ assertEquals(0.39, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+
+ tx = (TextShape)map.get("TEST4");
+ assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.39, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-import org.apache.poi.util.HexDump;\r
-\r
-/**\r
- * Tests that {@link HeadersFootersAtom} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestAnimationInfoAtom extends TestCase {\r
- // From a real file\r
- /*\r
- <AnimationInfoAtom info="1" type="4081" size="28" offset="4015" header="01 00 F1 0F 1C 00 00 00 ">\r
- 00 00 00 07 04 05 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00\r
- 00 00 00\r
- </AnimationInfoAtom>\r
- */\r
- private byte[] data = new byte[] {\r
- 0x01, 0x00, (byte)0xF1, 0x0F, 0x1C, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x07, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
- };\r
-\r
- public void testRead() throws Exception {\r
- AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);\r
- assertEquals(RecordTypes.AnimationInfoAtom.typeID, record.getRecordType());\r
- assertTrue(record.getFlag(AnimationInfoAtom.Automatic));\r
- assertTrue(record.getFlag(AnimationInfoAtom.Play));\r
- assertTrue(record.getFlag(AnimationInfoAtom.Synchronous));\r
- assertFalse(record.getFlag(AnimationInfoAtom.Reverse));\r
- assertFalse(record.getFlag(AnimationInfoAtom.Sound));\r
- assertFalse(record.getFlag(AnimationInfoAtom.StopSound));\r
- assertFalse(record.getFlag(AnimationInfoAtom.Hide));\r
- assertFalse(record.getFlag(AnimationInfoAtom.AnimateBg));\r
- assertEquals(0x07000000, record.getDimColor());\r
- assertEquals(0, record.getSoundIdRef());\r
- assertEquals(0, record.getDelayTime());\r
- assertEquals(2, record.getOrderID());\r
- assertEquals(0, record.getSlideCount());\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- AnimationInfoAtom record = new AnimationInfoAtom();\r
- record.setDimColor(0x07000000);\r
- record.setOrderID(2);\r
- record.setFlag(AnimationInfoAtom.Automatic, true);\r
- record.setFlag(AnimationInfoAtom.Play, true);\r
- record.setFlag(AnimationInfoAtom.Synchronous, true);\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+import org.apache.poi.util.HexDump;
+
+/**
+ * Tests that {@link HeadersFootersAtom} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestAnimationInfoAtom extends TestCase {
+ // From a real file
+ /*
+ <AnimationInfoAtom info="1" type="4081" size="28" offset="4015" header="01 00 F1 0F 1C 00 00 00 ">
+ 00 00 00 07 04 05 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00
+ 00 00 00
+ </AnimationInfoAtom>
+ */
+ private byte[] data = new byte[] {
+ 0x01, 0x00, (byte)0xF1, 0x0F, 0x1C, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x07, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
+ public void testRead() throws Exception {
+ AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);
+ assertEquals(RecordTypes.AnimationInfoAtom.typeID, record.getRecordType());
+ assertTrue(record.getFlag(AnimationInfoAtom.Automatic));
+ assertTrue(record.getFlag(AnimationInfoAtom.Play));
+ assertTrue(record.getFlag(AnimationInfoAtom.Synchronous));
+ assertFalse(record.getFlag(AnimationInfoAtom.Reverse));
+ assertFalse(record.getFlag(AnimationInfoAtom.Sound));
+ assertFalse(record.getFlag(AnimationInfoAtom.StopSound));
+ assertFalse(record.getFlag(AnimationInfoAtom.Hide));
+ assertFalse(record.getFlag(AnimationInfoAtom.AnimateBg));
+ assertEquals(0x07000000, record.getDimColor());
+ assertEquals(0, record.getSoundIdRef());
+ assertEquals(0, record.getDelayTime());
+ assertEquals(2, record.getOrderID());
+ assertEquals(0, record.getSlideCount());
+ }
+
+ public void testWrite() throws Exception {
+ AnimationInfoAtom record = new AnimationInfoAtom(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ AnimationInfoAtom record = new AnimationInfoAtom();
+ record.setDimColor(0x07000000);
+ record.setOrderID(2);
+ record.setFlag(AnimationInfoAtom.Automatic, true);
+ record.setFlag(AnimationInfoAtom.Play, true);
+ record.setFlag(AnimationInfoAtom.Synchronous, true);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestCString extends TestCase {
+public final class TestCString extends TestCase {
// From a real file
private byte[] data_a = new byte[] { 0, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0,
0x48, 00, 0x6F, 00, 0x67, 00, 0x77, 00,
private byte[] data_b = new byte[] { 0x10, 0, 0xBA-256, 0x0f, 0x10, 0, 0, 0,
0x43, 00, 0x6F, 00, 0x6D, 00, 0x6D, 00,
0x65, 00, 0x6E, 00, 0x74, 00, 0x73, 00 };
-
+
public void testRecordType() throws Exception {
CString ca = new CString(data_a, 0, data_a.length);
assertEquals(4026l, ca.getRecordType());
assertEquals(0, ca.getOptions());
CString cb = new CString(data_b, 0, data_a.length);
assertEquals(0x10, cb.getOptions());
-
+
ca.setOptions(28);
assertEquals(28, ca.getOptions());
}
-
+
public void testText() throws Exception {
CString ca = new CString(data_a, 0, data_a.length);
assertEquals("Hogwarts", ca.getText());
CString cb = new CString(data_b, 0, data_a.length);
assertEquals("Comments", cb.getText());
-
+
ca.setText("FooBar");
assertEquals("FooBar", ca.getText());
}
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],b[i]);
}
-
+
CString cb = new CString(data_b, 0, data_a.length);
ByteArrayOutputStream baosB = new ByteArrayOutputStream();
cb.writeOut(baosB);
assertEquals(data_b[i],b[i]);
}
}
-
+
// Turn data_a into data_b
public void testChange() throws Exception {
CString ca = new CString(data_a, 0, data_a.length);
ca.setText("Comments");
ca.setOptions(0x10);
-
+
try {
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],data_b[i]);
} catch(Error e) {
// Good, they're not the same
}
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
-
+
// Should now be the same
assertEquals(data_b.length, b.length);
for(int i=0; i<data_b.length; i++) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestColorSchemeAtom extends TestCase {
+public final class TestColorSchemeAtom extends TestCase {
// From a real file
- private byte[] data_a = new byte[] { 60, 0, 0xF0-256, 0x07, 0x20, 0, 0, 0,
- 0xFF-256, 0xFF-256, 0xFF-256, 00, 00, 00, 00, 00,
+ private byte[] data_a = new byte[] { 60, 0, 0xF0-256, 0x07, 0x20, 0, 0, 0,
+ 0xFF-256, 0xFF-256, 0xFF-256, 00, 00, 00, 00, 00,
0x80-256, 0x80-256, 0x80-256, 00, 00, 00, 00, 00,
0xBB-256, 0xE0-256, 0xE3-256, 00, 0x33, 0x33, 0x99-256, 00,
00, 0x99-256, 0x99-256, 00, 0x99-256, 0xCC-256, 00, 00
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestComment2000 extends TestCase {
+public final class TestComment2000 extends TestCase {
// From a real file
- private byte[] data_a = new byte[] {
+ private byte[] data_a = new byte[] {
0x0F, 00, 0xE0-256, 0x2E, 0x9C-256, 00, 00, 00,
00, 00, 0xBA-256, 0x0F, 0x14, 00, 00, 00,
0x44, 00, 0x75, 00, 0x6D, 00, 0x62, 00,
- 0x6C, 00, 0x65, 00, 0x64, 00, 0x6F, 00,
+ 0x6C, 00, 0x65, 00, 0x64, 00, 0x6F, 00,
0x72, 00, 0x65, 00,
- 0x10, 00, 0xBA-256, 0x0F, 0x4A, 00, 00, 00,
- 0x59, 00, 0x65, 00, 0x73, 00, 0x2C, 00,
+ 0x10, 00, 0xBA-256, 0x0F, 0x4A, 00, 00, 00,
+ 0x59, 00, 0x65, 00, 0x73, 00, 0x2C, 00,
0x20, 00, 0x74, 00, 0x68, 00, 0x65, 00,
0x79, 00, 0x20, 00, 0x63, 00, 0x65, 00,
0x72, 00, 0x74, 00, 0x61, 00, 0x69, 00,
0x6E, 00, 0x6C, 00, 0x79, 00, 0x20, 00,
- 0x61, 00, 0x72, 00, 0x65, 00, 0x2C, 00,
- 0x20, 00, 0x61, 00, 0x72, 00, 0x65, 00,
+ 0x61, 00, 0x72, 00, 0x65, 00, 0x2C, 00,
+ 0x20, 00, 0x61, 00, 0x72, 00, 0x65, 00,
0x6E, 00, 0x27, 00, 0x74, 00, 0x20, 00,
0x74, 00, 0x68, 00, 0x65, 00, 0x79, 00, 0x21, 00,
0x20, 00, 0xBA-256, 0x0F, 0x02, 00, 00, 00,
0x44, 00,
00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
01, 00, 00, 00, 0xD6-256, 07, 01, 00,
- 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
- 0x0F, 00, 0xCD-256, 00, 0x92-256, 00,
+ 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
+ 0x0F, 00, 0xCD-256, 00, 0x92-256, 00,
00, 00, 0x92-256, 00, 00, 00
};
- private byte[] data_b = new byte[] {
- 0x0F, 00, 0xE0-256, 0x2E, 0xAC-256, 00, 00, 00,
+ private byte[] data_b = new byte[] {
+ 0x0F, 00, 0xE0-256, 0x2E, 0xAC-256, 00, 00, 00,
00, 00, 0xBA-256, 0x0F, 0x10, 00, 00, 00,
0x48, 00, 0x6F, 00, 0x67, 00, 0x77, 00,
0x61, 00, 0x72, 00, 0x74, 00, 0x73, 00,
0x72, 00, 0x65, 00, 0x6E, 00, 0x27, 00,
0x74, 00, 0x20, 00, 0x74, 00, 0x68, 00,
0x65, 00, 0x79, 00, 0x3F, 00,
- 0x20, 00, 0xBA-256, 0x0F, 0x02, 00, 00, 00,
+ 0x20, 00, 0xBA-256, 0x0F, 0x02, 00, 00, 00,
0x48, 00,
00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
- 01, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
+ 01, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
02, 00, 0x18, 00, 0x16, 00, 0x19, 00, 03,
- 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
+ 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
0x0A, 00, 00, 00
};
-
+
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
+
public void testRecordType() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals(12000l, ca.getRecordType());
public void testCommentAtom() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
Comment2000Atom c2a = ca.getComment2000Atom();
-
+
assertEquals(1, c2a.getNumber());
assertEquals(0x92, c2a.getXOffset());
assertEquals(0x92, c2a.getYOffset());
public void testCommentAtomB() throws Exception {
Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
Comment2000Atom c2b = cb.getComment2000Atom();
-
+
assertEquals(1, c2b.getNumber());
assertEquals(0x0a, c2b.getXOffset());
assertEquals(0x0a, c2b.getYOffset());
assertEquals(data_a[i],b[i]);
}
}
-
+
// Change a few things
public void testChange() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
cn.setAuthor("Hogwarts");
cn.setAuthorInitials("H");
cn.setText("Comments are fun things to add in, aren't they?");
-
+
// Change the Comment2000Atom
Comment2000Atom c2a = ca.getComment2000Atom();
Comment2000Atom c2n = cn.getComment2000Atom();
c2n.setNumber(1);
c2n.setXOffset(0x0a);
c2n.setYOffset(0x0a);
-
+
Date new_date = sdf.parse("2006-01-24 22:25:03.725");
c2a.setDate(new_date);
c2n.setDate(new_date);
-
+
// Check now the same
assertEquals(ca.getText(), cb.getText());
assertEquals(cn.getText(), cb.getText());
assertEquals(cn.getAuthor(), cb.getAuthor());
assertEquals(ca.getAuthorInitials(), cb.getAuthorInitials());
assertEquals(cn.getAuthorInitials(), cb.getAuthorInitials());
-
+
// Check bytes weren't the same
try {
for(int i=0; i<data_a.length; i++) {
} catch(Error e) {
// Good, they're not the same
}
-
+
// Check bytes are now the same
ByteArrayOutputStream baosa = new ByteArrayOutputStream();
ByteArrayOutputStream baosn = new ByteArrayOutputStream();
cn.writeOut(baosn);
byte[] ba = baosa.toByteArray();
byte[] bn = baosn.toByteArray();
-
+
// Should now be the same
assertEquals(data_b.length, ba.length);
for(int i=0; i<data_b.length; i++) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestComment2000Atom extends TestCase {
+public final class TestComment2000Atom extends TestCase {
// From a real file
- private byte[] data_a = new byte[] {
+ private byte[] data_a = new byte[] {
00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
01, 00, 00, 00, 0xD6-256, 07, 01, 00,
- 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
- 0x0F, 00, 0xCD-256, 00, 0x92-256, 00,
+ 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
+ 0x0F, 00, 0xCD-256, 00, 0x92-256, 00,
00, 00, 0x92-256, 00, 00, 00
};
- private byte[] data_b = new byte[] {
+ private byte[] data_b = new byte[] {
00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
- 05, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
+ 05, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
02, 00, 0x18, 00, 0x15, 00, 0x19, 00, 03,
- 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
+ 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
0x0E, 00, 00, 00
};
-
+
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
+
public void testRecordType() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
assertEquals(12001l, ca.getRecordType());
}
-
+
public void testGetDate() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
// B is 2006-01-24 (2nd day of week) 21:25:03.725
Date exp_b = sdf.parse("2006-01-24 21:25:03.725");
-
+
assertEquals(exp_a, ca.getDate());
assertEquals(exp_b, cb.getDate());
}
-
+
public void testGetNums() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
// B is number 5
assertEquals(5, cb.getNumber());
}
-
+
public void testGetPos() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
Comment2000Atom cb = new Comment2000Atom(data_b, 0, data_b.length);
// A is at 0x92, 0x92
assertEquals(0x92, ca.getXOffset());
assertEquals(0x92, ca.getYOffset());
-
+
// B is at 0x0A, 0x0E
assertEquals(0x0A, cb.getXOffset());
assertEquals(0x0E, cb.getYOffset());
}
-
+
public void testWrite() throws Exception {
Comment2000Atom ca = new Comment2000Atom(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create A from scratch
public void testCreate() throws Exception {
Comment2000Atom a = new Comment2000Atom();
-
+
// Set number, x and y
a.setNumber(1);
a.setXOffset(0x92);
a.setYOffset(0x92);
-
+
// Set the date
Date date_a = sdf.parse("2006-01-24 10:26:15.205");
a.setDate(date_a);
-
+
// Check it's now the same as a
ByteArrayOutputStream baos = new ByteArrayOutputStream();
a.writeOut(baos);
byte[] b = baos.toByteArray();
-
+
assertEquals(data_a.length, b.length);
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],b[i]);
// Change the number
ca.setNumber(5);
-
+
// Change the date
Date new_date = sdf.parse("2006-01-24 21:25:03.725");
ca.setDate(new_date);
-
+
// Change the x and y
ca.setXOffset(0x0A);
ca.setYOffset(0x0E);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
-
+
// Should now be the same
assertEquals(data_b.length, b.length);
for(int i=0; i<data_b.length; i++) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestCurrentUserAtom extends TestCase {
+public final class TestCurrentUserAtom extends TestCase {
/** Not encrypted */
private String normalFile;
/** Encrypted */
protected void setUp() throws Exception {
super.setUp();
-
+
String dirname = System.getProperty("HSLF.testdata.path");
normalFile = dirname + "/basic_test_ppt_file.ppt";
encFile = dirname + "/Password_Protected-hello.ppt";
POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(normalFile)
);
-
+
CurrentUserAtom cu = new CurrentUserAtom(fs);
-
+
// Check the contents
assertEquals("Hogwarts", cu.getLastEditUsername());
assertEquals(0x2942, cu.getCurrentEditOffset());
-
+
// Round trip
ByteArrayOutputStream baos = new ByteArrayOutputStream();
cu.writeOut(baos);
-
+
CurrentUserAtom cu2 = new CurrentUserAtom(baos.toByteArray());
assertEquals("Hogwarts", cu2.getLastEditUsername());
assertEquals(0x2942, cu2.getCurrentEditOffset());
}
-
+
public void testReadEnc() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(encFile)
);
-
+
try {
new CurrentUserAtom(fs);
fail();
// Good
}
}
-
+
public void testWriteNormal() throws Exception {
// Get raw contents from a known file
POIFSFileSystem fs = new POIFSFileSystem(
byte[] contents = new byte[docProps.getSize()];
InputStream in = fs.getRoot().createDocumentInputStream("Current User");
in.read(contents);
-
+
// Now build up a new one
CurrentUserAtom cu = new CurrentUserAtom();
cu.setLastEditUsername("Hogwarts");
cu.setCurrentEditOffset(0x2942);
-
+
// Check it matches
ByteArrayOutputStream baos = new ByteArrayOutputStream();
cu.writeOut(baos);
byte[] out = baos.toByteArray();
-
+
assertEquals(contents.length, out.length);
for(int i=0; i<contents.length; i++) {
assertEquals("Byte " + i, contents[i], out[i]);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestDocument extends TestCase {
+public final class TestDocument extends TestCase {
// HSLFSlideShow primed on the test data
private HSLFSlideShow ss;
// POIFS primed on the test data
pfs = new POIFSFileSystem(fis);
ss = new HSLFSlideShow(pfs);
}
-
+
private Document getDocRecord() {
Record[] r = ss.getRecords();
for(int i=(r.length-1); i>=0; i--) {
Document dr = getDocRecord();
assertEquals(1000, dr.getRecordType());
}
-
+
public void testChildRecords() throws Exception {
Document dr = getDocRecord();
assertNotNull(dr.getDocumentAtom());
assertTrue(dr.getDocumentAtom() instanceof DocumentAtom);
-
+
assertNotNull(dr.getEnvironment());
assertTrue(dr.getEnvironment() instanceof Environment);
-
+
assertNotNull(dr.getSlideListWithTexts());
assertEquals(3, dr.getSlideListWithTexts().length);
assertNotNull(dr.getSlideListWithTexts()[0]);
assertNotNull(dr.getSlideListWithTexts()[2]);
assertTrue(dr.getSlideListWithTexts()[2] instanceof SlideListWithText);
}
-
+
public void testEnvironment() throws Exception {
Document dr = getDocRecord();
Environment env = dr.getEnvironment();
-
+
assertEquals(1010, env.getRecordType());
assertNotNull(env.getFontCollection());
assertTrue(env.getFontCollection() instanceof FontCollection);
}
-
+
// No need to check re-writing - hslf.TestReWrite does all that for us
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestDocumentAtom extends TestCase {
+public final class TestDocumentAtom extends TestCase {
// From a real file
private byte[] data_a = new byte[] { 1, 0, 0xE9-256, 3, 0x28, 0, 0, 0,
- 0x80-256, 0x16, 0, 0, 0xE0-256, 0x10, 0, 0,
+ 0x80-256, 0x16, 0, 0, 0xE0-256, 0x10, 0, 0,
0xE0-256, 0x10, 0, 0, 0x80-256, 0x16, 0, 0,
0x05, 0, 0, 0, 0x0A, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1 };
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestDocumentEncryptionAtom extends TestCase {
+public final class TestDocumentEncryptionAtom extends TestCase {
// From a real file
- private byte[] data_a = new byte[] {
+ private byte[] data_a = new byte[] {
0x0F, 00, 0x14, 0x2F, 0xBE-256, 00, 00, 00,
- 02, 00, 02, 00, 0x0C, 00, 00, 00,
+ 02, 00, 02, 00, 0x0C, 00, 00, 00,
0x76, 00, 00, 00, 0x0C, 00, 00, 00,
- 00, 00, 00, 00, 01, 0x68, 00, 00,
+ 00, 00, 00, 00, 01, 0x68, 00, 00,
04, 0x80-256, 00, 00, 0x28, 00, 00, 00,
- 01, 00, 00, 00, 0x30, 00, 0x26, 01,
+ 01, 00, 00, 00, 0x30, 00, 0x26, 01,
00, 00, 00, 00,
-
+
0x4D, 00, 0x69, 00,
- 0x63, 00, 0x72, 00, 0x6F, 00, 0x73, 00,
+ 0x63, 00, 0x72, 00, 0x6F, 00, 0x73, 00,
0x6F, 00, 0x66, 00, 0x74, 00, 0x20, 00,
- 0x42, 00, 0x61, 00, 0x73, 00, 0x65, 00,
+ 0x42, 00, 0x61, 00, 0x73, 00, 0x65, 00,
0x20, 00, 0x43, 00, 0x72, 00, 0x79, 00,
- 0x70, 00, 0x74, 00, 0x6F, 00, 0x67, 00,
+ 0x70, 00, 0x74, 00, 0x6F, 00, 0x67, 00,
0x72, 00, 0x61, 00, 0x70, 00, 0x68, 00,
- 0x69, 00, 0x63, 00, 0x20, 00, 0x50, 00,
+ 0x69, 00, 0x63, 00, 0x20, 00, 0x50, 00,
0x72, 00, 0x6F, 00, 0x76, 00, 0x69, 00,
- 0x64, 00, 0x65, 00, 0x72, 00, 0x20, 00,
+ 0x64, 00, 0x65, 00, 0x72, 00, 0x20, 00,
0x76, 00, 0x31, 00, 0x2E, 00, 0x30, 00,
0x00, 0x00,
-
- 0x10, 00, 0x00, 00,
- 0x62, 0xA6-256,
- 0xDF-256, 0xEA-256, 0x96-256, 0x84-256,
+
+ 0x10, 00, 0x00, 00,
+ 0x62, 0xA6-256,
+ 0xDF-256, 0xEA-256, 0x96-256, 0x84-256,
0xFB-256, 0x89-256, 0x93-256, 0xCA-256,
- 0xBA-256, 0xEE-256, 0x8E-256, 0x43,
- 0xC8-256, 0x71, 0xD1-256, 0x89-256,
- 0xF6-256, 0x4B, 0x2B, 0xD9-256,
+ 0xBA-256, 0xEE-256, 0x8E-256, 0x43,
+ 0xC8-256, 0x71, 0xD1-256, 0x89-256,
+ 0xF6-256, 0x4B, 0x2B, 0xD9-256,
0x7E, 0x0B, 0x52, 0xFB-256,
- 0x68, 0xD7-256, 0x5A, 0x4E, 0x45, 0xDF-256, 0x14, 0x00,
+ 0x68, 0xD7-256, 0x5A, 0x4E, 0x45, 0xDF-256, 0x14, 0x00,
0x00, 0x00, 0x93-256, 0x15, 0x27, 0xEB-256, 0x21, 0x54,
- 0x7F, 0x0B, 0x56, 0x07, 0xEE-256, 0x66, 0xEB-256, 0x6F,
+ 0x7F, 0x0B, 0x56, 0x07, 0xEE-256, 0x66, 0xEB-256, 0x6F,
0xB2-256, 0x8E-256, 0x67, 0x54, 0x07, 0x04, 0x00
};
-
+
private byte[] data_b = new byte[] {
15, 0, 20, 47, -66, 0, 0, 0,
- 2, 0, 2, 0, 4,
- 0, 0, 0, 118, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0,
- 0, 1, 104, 0, 0, 4, -128, 0, 0, 56, 0, 0, 0,
- 1, 0, 0, 0, 48, 0, 38, 1, 0, 0, 0, 0, 77, 0,
- 105, 0, 99, 0, 114, 0, 111, 0, 115, 0, 111,
- 0, 102, 0, 116, 0, 32, 0, 66, 0, 97, 0, 115,
- 0, 101, 0, 32, 0, 67, 0, 114, 0, 121, 0, 112,
- 0, 116, 0, 111, 0, 103, 0, 114, 0, 97, 0,
- 112, 0, 104, 0, 105, 0, 99, 0, 32, 0, 80, 0,
- 114, 0, 111, 0, 118, 0, 105, 0, 100, 0, 101,
- 0, 114, 0, 32, 0, 118, 0, 49, 0, 46, 0, 48,
- 0, 0, 0, 16, 0, 0, 0, -80, -66, 112, -40, 57,
- 110, 54, 80, 64, 61, -73, -29, 48, -35, -20,
- 17, -40, 84, 54, 6, -103, 125, -22, -72, 53,
- 103, -114, 13, -48, 111, 29, 78, 20, 0, 0,
- 0, -97, -67, 55, -62, -94, 14, 15, -21, 37,
+ 2, 0, 2, 0, 4,
+ 0, 0, 0, 118, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0,
+ 0, 1, 104, 0, 0, 4, -128, 0, 0, 56, 0, 0, 0,
+ 1, 0, 0, 0, 48, 0, 38, 1, 0, 0, 0, 0, 77, 0,
+ 105, 0, 99, 0, 114, 0, 111, 0, 115, 0, 111,
+ 0, 102, 0, 116, 0, 32, 0, 66, 0, 97, 0, 115,
+ 0, 101, 0, 32, 0, 67, 0, 114, 0, 121, 0, 112,
+ 0, 116, 0, 111, 0, 103, 0, 114, 0, 97, 0,
+ 112, 0, 104, 0, 105, 0, 99, 0, 32, 0, 80, 0,
+ 114, 0, 111, 0, 118, 0, 105, 0, 100, 0, 101,
+ 0, 114, 0, 32, 0, 118, 0, 49, 0, 46, 0, 48,
+ 0, 0, 0, 16, 0, 0, 0, -80, -66, 112, -40, 57,
+ 110, 54, 80, 64, 61, -73, -29, 48, -35, -20,
+ 17, -40, 84, 54, 6, -103, 125, -22, -72, 53,
+ 103, -114, 13, -48, 111, 29, 78, 20, 0, 0,
+ 0, -97, -67, 55, -62, -94, 14, 15, -21, 37,
3, -104, 22, 6, 102, -61, -98, 62, 40, 61, 21
};
public void testRecordType() {
DocumentEncryptionAtom dea1 = new DocumentEncryptionAtom(data_a, 0, data_a.length);
assertEquals(12052l, dea1.getRecordType());
-
+
DocumentEncryptionAtom dea2 = new DocumentEncryptionAtom(data_b, 0, data_b.length);
assertEquals(12052l, dea2.getRecordType());
-
+
assertEquals(199, data_a.length);
assertEquals(198, data_b.length);
}
-
+
public void testEncryptionTypeName() {
DocumentEncryptionAtom dea1 = new DocumentEncryptionAtom(data_a, 0, data_a.length);
assertEquals("Microsoft Base Cryptographic Provider v1.0", dea1.getEncryptionProviderName());
-
+
DocumentEncryptionAtom dea2 = new DocumentEncryptionAtom(data_b, 0, data_b.length);
assertEquals("Microsoft Base Cryptographic Provider v1.0", dea2.getEncryptionProviderName());
}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests that {@link org.apache.poi.hslf.record.ExControl} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestExControl extends TestCase {\r
-\r
- // From a real file (embedded SWF control)\r
- /*\r
- <ExControl info="15" type="4078" size="218" offset="76" header="0F 00 EE 0F DA 00 00 00 ">\r
- <ExControlAtom info="0" type="4091" size="4" offset="84" header="00 00 FB 0F 04 00 00 00 ">\r
- 00 01 00 00\r
- </ExControlAtom>\r
- <ExOleObjAtom info="1" type="4035" size="24" offset="96" header="01 00 C3 0F 18 00 00 00 ">\r
- 01 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 00 96 13 00\r
- </ExOleObjAtom>\r
- <CString info="16" type="4026" size="44" offset="128" header="10 00 BA 0F 2C 00 00 00 ">\r
- 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 20 00 46 00 6C 00 61\r
- 00 73 00 68 00 20 00 4F 00 62 00 6A 00 65 00 63 00 74 00\r
- </CString>\r
- <CString info="32" type="4026" size="62" offset="180" header="20 00 BA 0F 3E 00 00 00 ">\r
- 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 46 00 6C 00 61 00 73\r
- 00 68 00 2E 00 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 46 00\r
- 6C 00 61 00 73 00 68 00 2E 00 39 00\r
- </CString>\r
- <CString info="48" type="4026" size="44" offset="250" header="30 00 BA 0F 2C 00 00 00 ">\r
- 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 20 00 46 00 6C 00 61\r
- 00 73 00 68 00 20 00 4F 00 62 00 6A 00 65 00 63 00 74 00\r
- </CString>\r
- </ExControl>\r
- */\r
- private byte[] data = new byte[] {\r
- 0x0F, 0x00, (byte)0xEE, 0x0F, (byte)0xDA, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xFB, 0x0F, 0x04, 0x00, 0x00, 0x00,\r
- 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,\r
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00,\r
- 0x10, 0x00, (byte)0xBA, 0x0F, 0x2C, 0x00, 0x00, 0x00, 0x53, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00,\r
- 0x77, 0x00, 0x61, 0x00, 0x76, 0x00, 0x65, 0x00, 0x20, 0x00, 0x46, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68,\r
- 0x00, 0x20, 0x00, 0x4F, 0x00, 0x62, 0x00, 0x6A, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x20, 0x00, (byte)0xBA,\r
- 0x0F, 0x3E, 0x00, 0x00, 0x00, 0x53, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x77, 0x00, 0x61, 0x00,\r
- 0x76, 0x00, 0x65, 0x00, 0x46, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x2E, 0x00, 0x53, 0x00, 0x68,\r
- 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x77, 0x00, 0x61, 0x00, 0x76, 0x00, 0x65, 0x00, 0x46, 0x00, 0x6C, 0x00,\r
- 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x2E, 0x00, 0x39, 0x00, 0x30, 0x00, (byte)0xBA, 0x0F, 0x2C, 0x00, 0x00, 0x00,\r
- 0x53, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x77, 0x00, 0x61, 0x00, 0x76, 0x00, 0x65, 0x00, 0x20,\r
- 0x00, 0x46, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x20, 0x00, 0x4F, 0x00, 0x62, 0x00, 0x6A, 0x00,\r
- 0x65, 0x00, 0x63, 0x00, 0x74, 0x00\r
- };\r
-\r
- public void testRead() throws Exception {\r
- ExControl record = new ExControl(data, 0, data.length);\r
- assertEquals(RecordTypes.ExControl.typeID, record.getRecordType());\r
-\r
- assertNotNull(record.getExControlAtom());\r
- assertEquals(256, record.getExControlAtom().getSlideId());\r
-\r
- ExOleObjAtom oleObj = record.getExOleObjAtom();\r
- assertNotNull(oleObj);\r
- assertEquals(oleObj.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);\r
- assertEquals(oleObj.getType(), ExOleObjAtom.TYPE_CONTROL);\r
- assertEquals(oleObj.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);\r
-\r
- assertEquals("Shockwave Flash Object", record.getMenuName());\r
- assertEquals("ShockwaveFlash.ShockwaveFlash.9", record.getProgId());\r
- assertEquals("Shockwave Flash Object", record.getClipboardName());\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- ExControl record = new ExControl(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- ExControl record = new ExControl();\r
- ExControlAtom ctrl = record.getExControlAtom();\r
- ctrl.setSlideId(256);\r
-\r
- ExOleObjAtom oleObj = record.getExOleObjAtom();\r
- oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);\r
- oleObj.setType(ExOleObjAtom.TYPE_CONTROL);\r
- oleObj.setObjID(1);\r
- oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);\r
- oleObj.setObjStgDataRef(2);\r
- oleObj.setOptions(1283584);\r
-\r
- record.setMenuName("Shockwave Flash Object");\r
- record.setProgId("ShockwaveFlash.ShockwaveFlash.9");\r
- record.setClipboardName("Shockwave Flash Object");\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertEquals(data.length, b.length);\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+/**
+ * Tests that {@link org.apache.poi.hslf.record.ExControl} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestExControl extends TestCase {
+
+ // From a real file (embedded SWF control)
+ /*
+ <ExControl info="15" type="4078" size="218" offset="76" header="0F 00 EE 0F DA 00 00 00 ">
+ <ExControlAtom info="0" type="4091" size="4" offset="84" header="00 00 FB 0F 04 00 00 00 ">
+ 00 01 00 00
+ </ExControlAtom>
+ <ExOleObjAtom info="1" type="4035" size="24" offset="96" header="01 00 C3 0F 18 00 00 00 ">
+ 01 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 00 96 13 00
+ </ExOleObjAtom>
+ <CString info="16" type="4026" size="44" offset="128" header="10 00 BA 0F 2C 00 00 00 ">
+ 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 20 00 46 00 6C 00 61
+ 00 73 00 68 00 20 00 4F 00 62 00 6A 00 65 00 63 00 74 00
+ </CString>
+ <CString info="32" type="4026" size="62" offset="180" header="20 00 BA 0F 3E 00 00 00 ">
+ 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 46 00 6C 00 61 00 73
+ 00 68 00 2E 00 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 46 00
+ 6C 00 61 00 73 00 68 00 2E 00 39 00
+ </CString>
+ <CString info="48" type="4026" size="44" offset="250" header="30 00 BA 0F 2C 00 00 00 ">
+ 53 00 68 00 6F 00 63 00 6B 00 77 00 61 00 76 00 65 00 20 00 46 00 6C 00 61
+ 00 73 00 68 00 20 00 4F 00 62 00 6A 00 65 00 63 00 74 00
+ </CString>
+ </ExControl>
+ */
+ private byte[] data = new byte[] {
+ 0x0F, 0x00, (byte)0xEE, 0x0F, (byte)0xDA, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xFB, 0x0F, 0x04, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00,
+ 0x10, 0x00, (byte)0xBA, 0x0F, 0x2C, 0x00, 0x00, 0x00, 0x53, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00,
+ 0x77, 0x00, 0x61, 0x00, 0x76, 0x00, 0x65, 0x00, 0x20, 0x00, 0x46, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68,
+ 0x00, 0x20, 0x00, 0x4F, 0x00, 0x62, 0x00, 0x6A, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x20, 0x00, (byte)0xBA,
+ 0x0F, 0x3E, 0x00, 0x00, 0x00, 0x53, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x77, 0x00, 0x61, 0x00,
+ 0x76, 0x00, 0x65, 0x00, 0x46, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x2E, 0x00, 0x53, 0x00, 0x68,
+ 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x77, 0x00, 0x61, 0x00, 0x76, 0x00, 0x65, 0x00, 0x46, 0x00, 0x6C, 0x00,
+ 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x2E, 0x00, 0x39, 0x00, 0x30, 0x00, (byte)0xBA, 0x0F, 0x2C, 0x00, 0x00, 0x00,
+ 0x53, 0x00, 0x68, 0x00, 0x6F, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x77, 0x00, 0x61, 0x00, 0x76, 0x00, 0x65, 0x00, 0x20,
+ 0x00, 0x46, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x73, 0x00, 0x68, 0x00, 0x20, 0x00, 0x4F, 0x00, 0x62, 0x00, 0x6A, 0x00,
+ 0x65, 0x00, 0x63, 0x00, 0x74, 0x00
+ };
+
+ public void testRead() throws Exception {
+ ExControl record = new ExControl(data, 0, data.length);
+ assertEquals(RecordTypes.ExControl.typeID, record.getRecordType());
+
+ assertNotNull(record.getExControlAtom());
+ assertEquals(256, record.getExControlAtom().getSlideId());
+
+ ExOleObjAtom oleObj = record.getExOleObjAtom();
+ assertNotNull(oleObj);
+ assertEquals(oleObj.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);
+ assertEquals(oleObj.getType(), ExOleObjAtom.TYPE_CONTROL);
+ assertEquals(oleObj.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);
+
+ assertEquals("Shockwave Flash Object", record.getMenuName());
+ assertEquals("ShockwaveFlash.ShockwaveFlash.9", record.getProgId());
+ assertEquals("Shockwave Flash Object", record.getClipboardName());
+ }
+
+ public void testWrite() throws Exception {
+ ExControl record = new ExControl(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ ExControl record = new ExControl();
+ ExControlAtom ctrl = record.getExControlAtom();
+ ctrl.setSlideId(256);
+
+ ExOleObjAtom oleObj = record.getExOleObjAtom();
+ oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
+ oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
+ oleObj.setObjID(1);
+ oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
+ oleObj.setObjStgDataRef(2);
+ oleObj.setOptions(1283584);
+
+ record.setMenuName("Shockwave Flash Object");
+ record.setProgId("ShockwaveFlash.ShockwaveFlash.9");
+ record.setClipboardName("Shockwave Flash Object");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertEquals(data.length, b.length);
+ assertTrue(Arrays.equals(data, b));
+ }
+
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests that {@link org.apache.poi.hslf.record.HeadersFootersAtom} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public final class TestExMediaAtom extends TestCase {\r
- // From a real file\r
- private static final byte[] data = {\r
- 0x00, 0x00, (byte)0x04, 0x10, 0x08, 0x00, 0x00, 00,\r
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r
-\r
- public void testRead() {\r
- ExMediaAtom record = new ExMediaAtom(data, 0, data.length);\r
- assertEquals(RecordTypes.ExMediaAtom.typeID, record.getRecordType());\r
-\r
- assertEquals(1, record.getObjectId());\r
- assertFalse(record.getFlag(ExMediaAtom.fLoop));\r
- assertFalse(record.getFlag(ExMediaAtom.fNarration));\r
- assertFalse(record.getFlag(ExMediaAtom.fRewind));\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- ExMediaAtom record = new ExMediaAtom(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- ExMediaAtom ref = new ExMediaAtom(data, 0, data.length);\r
- assertEquals(0, ref.getMask()); //\r
-\r
- ExMediaAtom record = new ExMediaAtom();\r
- record.setObjectId(1);\r
- record.setFlag(HeadersFootersAtom.fHasDate, false);\r
- record.setFlag(HeadersFootersAtom.fHasTodayDate, false);\r
- record.setFlag(HeadersFootersAtom.fHasFooter, false);\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testFlags() {\r
- ExMediaAtom record = new ExMediaAtom();\r
-\r
- //in a new record all the bits are 0\r
- for(int i = 0; i < 3; i++) assertFalse(record.getFlag(1 << i));\r
-\r
- record.setFlag(ExMediaAtom.fLoop, true);\r
- assertTrue(record.getFlag(ExMediaAtom.fLoop));\r
-\r
- record.setFlag(ExMediaAtom.fNarration, true);\r
- assertTrue(record.getFlag(ExMediaAtom.fNarration));\r
-\r
- record.setFlag(ExMediaAtom.fNarration, false);\r
- assertFalse(record.getFlag(ExMediaAtom.fNarration));\r
-\r
- record.setFlag(ExMediaAtom.fNarration, false);\r
- assertFalse(record.getFlag(ExMediaAtom.fNarration));\r
-\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+/**
+ * Tests that {@link org.apache.poi.hslf.record.HeadersFootersAtom} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestExMediaAtom extends TestCase {
+ // From a real file
+ private static final byte[] data = {
+ 0x00, 0x00, (byte)0x04, 0x10, 0x08, 0x00, 0x00, 00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+ public void testRead() {
+ ExMediaAtom record = new ExMediaAtom(data, 0, data.length);
+ assertEquals(RecordTypes.ExMediaAtom.typeID, record.getRecordType());
+
+ assertEquals(1, record.getObjectId());
+ assertFalse(record.getFlag(ExMediaAtom.fLoop));
+ assertFalse(record.getFlag(ExMediaAtom.fNarration));
+ assertFalse(record.getFlag(ExMediaAtom.fRewind));
+ }
+
+ public void testWrite() throws Exception {
+ ExMediaAtom record = new ExMediaAtom(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ ExMediaAtom ref = new ExMediaAtom(data, 0, data.length);
+ assertEquals(0, ref.getMask()); //
+
+ ExMediaAtom record = new ExMediaAtom();
+ record.setObjectId(1);
+ record.setFlag(HeadersFootersAtom.fHasDate, false);
+ record.setFlag(HeadersFootersAtom.fHasTodayDate, false);
+ record.setFlag(HeadersFootersAtom.fHasFooter, false);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testFlags() {
+ ExMediaAtom record = new ExMediaAtom();
+
+ //in a new record all the bits are 0
+ for(int i = 0; i < 3; i++) assertFalse(record.getFlag(1 << i));
+
+ record.setFlag(ExMediaAtom.fLoop, true);
+ assertTrue(record.getFlag(ExMediaAtom.fLoop));
+
+ record.setFlag(ExMediaAtom.fNarration, true);
+ assertTrue(record.getFlag(ExMediaAtom.fNarration));
+
+ record.setFlag(ExMediaAtom.fNarration, false);
+ assertFalse(record.getFlag(ExMediaAtom.fNarration));
+
+ record.setFlag(ExMediaAtom.fNarration, false);
+ assertFalse(record.getFlag(ExMediaAtom.fNarration));
+
+ }
+}
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests that {@link ExOleObjAtom} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public final class TestExOleObjAtom extends TestCase {\r
- // From a real file (embedded SWF control)\r
- private byte[] data = {\r
- 0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00,\r
- 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00 };\r
-\r
- public void testRead() {\r
- ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);\r
- assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType());\r
-\r
- assertEquals(record.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);\r
- assertEquals(record.getType(), ExOleObjAtom.TYPE_CONTROL);\r
- assertEquals(record.getObjID(), 1);\r
- assertEquals(record.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);\r
- assertEquals(record.getObjStgDataRef(), 2);\r
- assertEquals(record.getOptions(), 1283584); //ther meaning is unknown\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- ExOleObjAtom record = new ExOleObjAtom();\r
- record.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);\r
- record.setType(ExOleObjAtom.TYPE_CONTROL);\r
- record.setObjID(1);\r
- record.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);\r
- record.setObjStgDataRef(2);\r
- record.setOptions(1283584);\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+/**
+ * Tests that {@link ExOleObjAtom} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestExOleObjAtom extends TestCase {
+ // From a real file (embedded SWF control)
+ private byte[] data = {
+ 0x01, 0x00, (byte)0xC3, 0x0F, 0x18, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, (byte)0x96, 0x13, 0x00 };
+
+ public void testRead() {
+ ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
+ assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType());
+
+ assertEquals(record.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);
+ assertEquals(record.getType(), ExOleObjAtom.TYPE_CONTROL);
+ assertEquals(record.getObjID(), 1);
+ assertEquals(record.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);
+ assertEquals(record.getObjStgDataRef(), 2);
+ assertEquals(record.getOptions(), 1283584); //ther meaning is unknown
+ }
+
+ public void testWrite() throws Exception {
+ ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ ExOleObjAtom record = new ExOleObjAtom();
+ record.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
+ record.setType(ExOleObjAtom.TYPE_CONTROL);
+ record.setObjID(1);
+ record.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
+ record.setObjStgDataRef(2);
+ record.setOptions(1283584);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.InputStream;\r
-import java.io.IOException;\r
-import java.util.Arrays;\r
-\r
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;\r
-import org.apache.poi.poifs.filesystem.DirectoryNode;\r
-import org.apache.poi.poifs.filesystem.DocumentEntry;\r
-\r
-/**\r
- * Tests that {@link ExOleObjStg} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestExOleObjStg extends TestCase {\r
-\r
- // From a real file (embedded SWF control)\r
- /*\r
- <ExOleObjStg info="16" type="4113" size="347" offset="4322" header="10 00 11 10 5B 01 00 00 ">\r
- 00 0E 00 00 78 9C BB 70 5E F0 C1 C2 8D 52 0F 19 D0 80 1D 03 33 C3 BF FF 9C\r
- 0C 6C 48 62 8C 40 CC 04 E3 08 30 30 B0 40 C5 FE FD FF FF 1F 24 C4 0C C4 FF\r
- 47 C1 90 02 41 0C F9 40 58 C2 A0 C0 E0 CA 90 07 A4 8B 18 2A D1 93 02 5E 20\r
- C6 C0 0A 8F 73 50 5A C8 BB 5D 73 29 77 DD 79 C1 69 3B 5C 5C 83 43 50 D5 06\r
- BC 48 2F 2B 66 38 C9 C8 0E 64 3B 30 42 C4 9C 81 B6 83 EC 4D 05 93 C5 24 D9\r
- 0D 02 42 0C 4C 8C C8 FE 21 56 9F 02 23 C9 56 E1 04 E4 D8 4F 4D 40 89 FD A0\r
- BC FB 17 4B BA F8 07 C5 A3 60 78 03 7A E6 FF 09 67 59 1B 41 F9 9F 95 61 34\r
- FF 53 13 50 62 3F 4C 1F AC 1C 18 CD F7 23 0B C0 DA 74 A0 B6 1B A8 3D 37 1A\r
- F7 23 0B A4 87 A6 85 0A 00 1B 64 6F 38 21 98 03 DA C2 E7 60 90 01 92 69 0C\r
- 39 0C 65 0C 05 40 32 11 58 2F A4 02 6B 07 3D 60 19 5D 0E 14 27 4E 05 1F 90\r
- 0C 67 C8 04 96 ED 29 C0 72 BE 1C C8 E3 06 E3 FF FF 39 18 B8 80 2C 0F A0 5C\r
- 3A 43 06 58 2D A8 A7 E1 C3 10 02 97 87 B8 02 E6 1A 60 77 83 21 18 A8 12 64\r
- 8A 23 D0 B6 1C B8 59 C8 AA 90 F5 F0 62 94 75 DC C0 DE 0A 37 5C 1D 33 54 35\r
- 88 97 08 35 91 83 81 07 EC 27 10 BF 18 E8 9B E1 0F 00 BD 65 3D D4\r
- </ExOleObjStg>\r
- */\r
- private byte[] data = new byte[] {\r
- 0x10, 0x00, 0x11, 0x10, 0x5B, 0x01, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x78, (byte)0x9C, (byte)0xBB, 0x70,\r
- 0x5E, (byte)0xF0, (byte)0xC1, (byte)0xC2, (byte)0x8D, 0x52, 0x0F, 0x19, (byte)0xD0, (byte)0x80, 0x1D, 0x03,\r
- 0x33, (byte)0xC3, (byte)0xBF, (byte)0xFF, (byte)0x9C, 0x0C, 0x6C, 0x48, 0x62, (byte)0x8C, 0x40, (byte)0xCC,\r
- 0x04, (byte)0xE3, 0x08, 0x30, 0x30, (byte)0xB0, 0x40, (byte)0xC5, (byte)0xFE, (byte)0xFD, (byte)0xFF, (byte)0xFF,\r
- 0x1F, 0x24, (byte)0xC4, (byte)0x0C, (byte)0xC4, (byte)0xFF, 0x47, (byte)0xC1, (byte)0x90, 0x02, 0x41, 0x0C,\r
- (byte)0xF9, 0x40, 0x58, (byte)0xC2, (byte)0xA0, (byte)0xC0, (byte)0xE0, (byte)0xCA, (byte)0x90, 0x07, (byte)0xA4,\r
- (byte)0x8B, 0x18, 0x2A, (byte)0xD1, (byte)0x93, 0x02, 0x5E, 0x20, (byte)0xC6, (byte)0xC0, 0x0A, (byte)0x8F,\r
- 0x73, 0x50, 0x5A, (byte)0xC8, (byte)0xBB, 0x5D, 0x73, 0x29, 0x77, (byte)0xDD, 0x79, (byte)0xC1, 0x69, 0x3B,\r
- 0x5C, 0x5C, (byte)0x83, 0x43, 0x50, (byte)0xD5, 0x06, (byte)0xBC, 0x48, 0x2F, 0x2B, 0x66, 0x38, (byte)0xC9,\r
- (byte)0xC8, 0x0E, 0x64, 0x3B, 0x30, 0x42, (byte)0xC4, (byte)0x9C, (byte)0x81, (byte)0xB6, (byte)0x83, (byte)0xEC,\r
- 0x4D, 0x05, (byte)0x93, (byte)0xC5, 0x24, (byte)0xD9, 0x0D, 0x02, 0x42, 0x0C, 0x4C, (byte)0x8C, (byte)0xC8,\r
- (byte)0xFE, 0x21, 0x56, (byte)0x9F, 0x02, 0x23, (byte)0xC9, 0x56, (byte)0xE1, 0x04, (byte)0xE4, (byte)0xD8,\r
- 0x4F, 0x4D, 0x40, (byte)0x89, (byte)0xFD, (byte)0xA0, (byte)0xBC, (byte)0xFB, 0x17, 0x4B, (byte)0xBA, (byte)0xF8,\r
- 0x07, (byte)0xC5, (byte)0xA3, 0x60, 0x78, 0x03, 0x7A, (byte)0xE6, (byte)0xFF, 0x09, 0x67, 0x59, 0x1B, 0x41,\r
- (byte)0xF9, (byte)0x9F, (byte)0x95, 0x61, 0x34, (byte)0xFF, 0x53, 0x13, 0x50, 0x62, 0x3F, 0x4C, 0x1F, (byte)0xAC,\r
- 0x1C, 0x18, (byte)0xCD, (byte)0xF7, 0x23, 0x0B, (byte)0xC0, (byte)0xDA, 0x74, (byte)0xA0, (byte)0xB6, 0x1B,\r
- (byte)0xA8, 0x3D, 0x37, 0x1A, (byte)0xF7, 0x23, 0x0B, (byte)0xA4, (byte)0x87, (byte)0xA6, (byte)0x85, 0x0A,\r
- 0x00, 0x1B, 0x64, 0x6F, 0x38, 0x21, (byte)0x98, 0x03, (byte)0xDA, (byte)0xC2, (byte)0xE7, 0x60, (byte)0x90,\r
- 0x01, (byte)0x92, 0x69, 0x0C, 0x39, 0x0C, 0x65, 0x0C, 0x05, 0x40, 0x32, 0x11, 0x58, 0x2F, (byte)0xA4, 0x02,\r
- 0x6B, 0x07, 0x3D, 0x60, 0x19, 0x5D, 0x0E, 0x14, 0x27, 0x4E, 0x05, 0x1F, (byte)0x90, 0x0C, 0x67, (byte)0xC8,\r
- 0x04, (byte)0x96, (byte)0xED, 0x29, (byte)0xC0, 0x72, (byte)0xBE, 0x1C, (byte)0xC8, (byte)0xE3, 0x06, (byte)0xE3,\r
- (byte)0xFF, (byte)0xFF, 0x39, 0x18, (byte)0xB8, (byte)0x80, 0x2C, 0x0F, (byte)0xA0, 0x5C, 0x3A, 0x43, 0x06, 0x58,\r
- 0x2D, (byte)0xA8, (byte)0xA7, (byte)0xE1, (byte)0xC3, 0x10, 0x02, (byte)0x97, (byte)0x87, (byte)0xB8, 0x02,\r
- (byte)0xE6, 0x1A, 0x60, 0x77, (byte)0x83, 0x21, 0x18, (byte)0xA8, 0x12, 0x64, (byte)0x8A, 0x23, (byte)0xD0,\r
- (byte)0xB6, 0x1C, (byte)0xB8, 0x59, (byte)0xC8, (byte)0xAA, (byte)0x90, (byte)0xF5, (byte)0xF0, 0x62, (byte)0x94,\r
- 0x75, (byte)0xDC, (byte)0xC0, (byte)0xDE, 0x0A, 0x37, 0x5C, 0x1D, 0x33, 0x54, 0x35, (byte)0x88, (byte)0x97, 0x08,\r
- 0x35, (byte)0x91, (byte)0x83, (byte)0x81, 0x07, (byte)0xEC, 0x27, 0x10, (byte)0xBF, 0x18, (byte)0xE8, (byte)0x9B,\r
- (byte)0xE1, 0x0F, 0x00, (byte)0xBD, 0x65, 0x3D, (byte)0xD4\r
- };\r
-\r
- public void testRead() throws Exception {\r
- ExOleObjStg record = new ExOleObjStg(data, 0, data.length);\r
- assertEquals(RecordTypes.ExOleObjStg.typeID, record.getRecordType());\r
-\r
- int len = record.getDataLength();\r
- byte[] oledata = readAll(record.getData());\r
- assertEquals(len, oledata.length);\r
-\r
- POIFSFileSystem fs = new POIFSFileSystem(record.getData());\r
- assertTrue("Constructed POIFS from ExOleObjStg data", true);\r
- DocumentEntry doc = (DocumentEntry)fs.getRoot().getEntry("Contents");\r
- assertNotNull(doc);\r
- assertTrue("Fetched the Contents stream containing OLE properties", true);\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- ExOleObjStg record = new ExOleObjStg(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- ExOleObjStg src = new ExOleObjStg(data, 0, data.length);\r
- byte[] oledata = readAll(src.getData());\r
-\r
- ExOleObjStg tgt = new ExOleObjStg();\r
- tgt.setData(oledata);\r
-\r
-\r
- assertEquals(src.getDataLength(), tgt.getDataLength());\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- tgt.writeOut(out);\r
- byte[] b = out.toByteArray();\r
-\r
- assertEquals(data.length, b.length);\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- private byte[] readAll(InputStream is) throws IOException {\r
- int pos;\r
- byte[] chunk = new byte[1024];\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- while((pos = is.read(chunk)) > 0){\r
- out.write(chunk, 0, pos);\r
- }\r
- return out.toByteArray();\r
-\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.DocumentEntry;
+
+/**
+ * Tests that {@link ExOleObjStg} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestExOleObjStg extends TestCase {
+
+ // From a real file (embedded SWF control)
+ /*
+ <ExOleObjStg info="16" type="4113" size="347" offset="4322" header="10 00 11 10 5B 01 00 00 ">
+ 00 0E 00 00 78 9C BB 70 5E F0 C1 C2 8D 52 0F 19 D0 80 1D 03 33 C3 BF FF 9C
+ 0C 6C 48 62 8C 40 CC 04 E3 08 30 30 B0 40 C5 FE FD FF FF 1F 24 C4 0C C4 FF
+ 47 C1 90 02 41 0C F9 40 58 C2 A0 C0 E0 CA 90 07 A4 8B 18 2A D1 93 02 5E 20
+ C6 C0 0A 8F 73 50 5A C8 BB 5D 73 29 77 DD 79 C1 69 3B 5C 5C 83 43 50 D5 06
+ BC 48 2F 2B 66 38 C9 C8 0E 64 3B 30 42 C4 9C 81 B6 83 EC 4D 05 93 C5 24 D9
+ 0D 02 42 0C 4C 8C C8 FE 21 56 9F 02 23 C9 56 E1 04 E4 D8 4F 4D 40 89 FD A0
+ BC FB 17 4B BA F8 07 C5 A3 60 78 03 7A E6 FF 09 67 59 1B 41 F9 9F 95 61 34
+ FF 53 13 50 62 3F 4C 1F AC 1C 18 CD F7 23 0B C0 DA 74 A0 B6 1B A8 3D 37 1A
+ F7 23 0B A4 87 A6 85 0A 00 1B 64 6F 38 21 98 03 DA C2 E7 60 90 01 92 69 0C
+ 39 0C 65 0C 05 40 32 11 58 2F A4 02 6B 07 3D 60 19 5D 0E 14 27 4E 05 1F 90
+ 0C 67 C8 04 96 ED 29 C0 72 BE 1C C8 E3 06 E3 FF FF 39 18 B8 80 2C 0F A0 5C
+ 3A 43 06 58 2D A8 A7 E1 C3 10 02 97 87 B8 02 E6 1A 60 77 83 21 18 A8 12 64
+ 8A 23 D0 B6 1C B8 59 C8 AA 90 F5 F0 62 94 75 DC C0 DE 0A 37 5C 1D 33 54 35
+ 88 97 08 35 91 83 81 07 EC 27 10 BF 18 E8 9B E1 0F 00 BD 65 3D D4
+ </ExOleObjStg>
+ */
+ private byte[] data = new byte[] {
+ 0x10, 0x00, 0x11, 0x10, 0x5B, 0x01, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x78, (byte)0x9C, (byte)0xBB, 0x70,
+ 0x5E, (byte)0xF0, (byte)0xC1, (byte)0xC2, (byte)0x8D, 0x52, 0x0F, 0x19, (byte)0xD0, (byte)0x80, 0x1D, 0x03,
+ 0x33, (byte)0xC3, (byte)0xBF, (byte)0xFF, (byte)0x9C, 0x0C, 0x6C, 0x48, 0x62, (byte)0x8C, 0x40, (byte)0xCC,
+ 0x04, (byte)0xE3, 0x08, 0x30, 0x30, (byte)0xB0, 0x40, (byte)0xC5, (byte)0xFE, (byte)0xFD, (byte)0xFF, (byte)0xFF,
+ 0x1F, 0x24, (byte)0xC4, (byte)0x0C, (byte)0xC4, (byte)0xFF, 0x47, (byte)0xC1, (byte)0x90, 0x02, 0x41, 0x0C,
+ (byte)0xF9, 0x40, 0x58, (byte)0xC2, (byte)0xA0, (byte)0xC0, (byte)0xE0, (byte)0xCA, (byte)0x90, 0x07, (byte)0xA4,
+ (byte)0x8B, 0x18, 0x2A, (byte)0xD1, (byte)0x93, 0x02, 0x5E, 0x20, (byte)0xC6, (byte)0xC0, 0x0A, (byte)0x8F,
+ 0x73, 0x50, 0x5A, (byte)0xC8, (byte)0xBB, 0x5D, 0x73, 0x29, 0x77, (byte)0xDD, 0x79, (byte)0xC1, 0x69, 0x3B,
+ 0x5C, 0x5C, (byte)0x83, 0x43, 0x50, (byte)0xD5, 0x06, (byte)0xBC, 0x48, 0x2F, 0x2B, 0x66, 0x38, (byte)0xC9,
+ (byte)0xC8, 0x0E, 0x64, 0x3B, 0x30, 0x42, (byte)0xC4, (byte)0x9C, (byte)0x81, (byte)0xB6, (byte)0x83, (byte)0xEC,
+ 0x4D, 0x05, (byte)0x93, (byte)0xC5, 0x24, (byte)0xD9, 0x0D, 0x02, 0x42, 0x0C, 0x4C, (byte)0x8C, (byte)0xC8,
+ (byte)0xFE, 0x21, 0x56, (byte)0x9F, 0x02, 0x23, (byte)0xC9, 0x56, (byte)0xE1, 0x04, (byte)0xE4, (byte)0xD8,
+ 0x4F, 0x4D, 0x40, (byte)0x89, (byte)0xFD, (byte)0xA0, (byte)0xBC, (byte)0xFB, 0x17, 0x4B, (byte)0xBA, (byte)0xF8,
+ 0x07, (byte)0xC5, (byte)0xA3, 0x60, 0x78, 0x03, 0x7A, (byte)0xE6, (byte)0xFF, 0x09, 0x67, 0x59, 0x1B, 0x41,
+ (byte)0xF9, (byte)0x9F, (byte)0x95, 0x61, 0x34, (byte)0xFF, 0x53, 0x13, 0x50, 0x62, 0x3F, 0x4C, 0x1F, (byte)0xAC,
+ 0x1C, 0x18, (byte)0xCD, (byte)0xF7, 0x23, 0x0B, (byte)0xC0, (byte)0xDA, 0x74, (byte)0xA0, (byte)0xB6, 0x1B,
+ (byte)0xA8, 0x3D, 0x37, 0x1A, (byte)0xF7, 0x23, 0x0B, (byte)0xA4, (byte)0x87, (byte)0xA6, (byte)0x85, 0x0A,
+ 0x00, 0x1B, 0x64, 0x6F, 0x38, 0x21, (byte)0x98, 0x03, (byte)0xDA, (byte)0xC2, (byte)0xE7, 0x60, (byte)0x90,
+ 0x01, (byte)0x92, 0x69, 0x0C, 0x39, 0x0C, 0x65, 0x0C, 0x05, 0x40, 0x32, 0x11, 0x58, 0x2F, (byte)0xA4, 0x02,
+ 0x6B, 0x07, 0x3D, 0x60, 0x19, 0x5D, 0x0E, 0x14, 0x27, 0x4E, 0x05, 0x1F, (byte)0x90, 0x0C, 0x67, (byte)0xC8,
+ 0x04, (byte)0x96, (byte)0xED, 0x29, (byte)0xC0, 0x72, (byte)0xBE, 0x1C, (byte)0xC8, (byte)0xE3, 0x06, (byte)0xE3,
+ (byte)0xFF, (byte)0xFF, 0x39, 0x18, (byte)0xB8, (byte)0x80, 0x2C, 0x0F, (byte)0xA0, 0x5C, 0x3A, 0x43, 0x06, 0x58,
+ 0x2D, (byte)0xA8, (byte)0xA7, (byte)0xE1, (byte)0xC3, 0x10, 0x02, (byte)0x97, (byte)0x87, (byte)0xB8, 0x02,
+ (byte)0xE6, 0x1A, 0x60, 0x77, (byte)0x83, 0x21, 0x18, (byte)0xA8, 0x12, 0x64, (byte)0x8A, 0x23, (byte)0xD0,
+ (byte)0xB6, 0x1C, (byte)0xB8, 0x59, (byte)0xC8, (byte)0xAA, (byte)0x90, (byte)0xF5, (byte)0xF0, 0x62, (byte)0x94,
+ 0x75, (byte)0xDC, (byte)0xC0, (byte)0xDE, 0x0A, 0x37, 0x5C, 0x1D, 0x33, 0x54, 0x35, (byte)0x88, (byte)0x97, 0x08,
+ 0x35, (byte)0x91, (byte)0x83, (byte)0x81, 0x07, (byte)0xEC, 0x27, 0x10, (byte)0xBF, 0x18, (byte)0xE8, (byte)0x9B,
+ (byte)0xE1, 0x0F, 0x00, (byte)0xBD, 0x65, 0x3D, (byte)0xD4
+ };
+
+ public void testRead() throws Exception {
+ ExOleObjStg record = new ExOleObjStg(data, 0, data.length);
+ assertEquals(RecordTypes.ExOleObjStg.typeID, record.getRecordType());
+
+ int len = record.getDataLength();
+ byte[] oledata = readAll(record.getData());
+ assertEquals(len, oledata.length);
+
+ POIFSFileSystem fs = new POIFSFileSystem(record.getData());
+ assertTrue("Constructed POIFS from ExOleObjStg data", true);
+ DocumentEntry doc = (DocumentEntry)fs.getRoot().getEntry("Contents");
+ assertNotNull(doc);
+ assertTrue("Fetched the Contents stream containing OLE properties", true);
+ }
+
+ public void testWrite() throws Exception {
+ ExOleObjStg record = new ExOleObjStg(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ ExOleObjStg src = new ExOleObjStg(data, 0, data.length);
+ byte[] oledata = readAll(src.getData());
+
+ ExOleObjStg tgt = new ExOleObjStg();
+ tgt.setData(oledata);
+
+
+ assertEquals(src.getDataLength(), tgt.getDataLength());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ tgt.writeOut(out);
+ byte[] b = out.toByteArray();
+
+ assertEquals(data.length, b.length);
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ private byte[] readAll(InputStream is) throws IOException {
+ int pos;
+ byte[] chunk = new byte[1024];
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ while((pos = is.read(chunk)) > 0){
+ out.write(chunk, 0, pos);
+ }
+ return out.toByteArray();
+
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests that {@link HeadersFootersAtom} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestExVideoContainer extends TestCase {\r
-\r
- // From a real file\r
- private byte[] data = new byte[]{\r
- 0x0F, 0x00, 0x05, 0x10, (byte) 0x9E, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, 0x04, 0x10, 0x08, 0x00, 0x00, 0x00,\r
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, (byte)0xBA, 0x0F, (byte)0x86, 0x00, 0x00, 0x00,\r
- 0x44, 0x00, 0x3A, 0x00, 0x5C, 0x00, 0x70, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x6A, 0x00, 0x65, 0x00,\r
- 0x63, 0x00, 0x74, 0x00, 0x73, 0x00, 0x5C, 0x00, 0x53, 0x00, 0x63, 0x00, 0x68, 0x00, 0x75, 0x00,\r
- 0x6C, 0x00, 0x65, 0x00, 0x72, 0x00, 0x41, 0x00, 0x47, 0x00, 0x5C, 0x00, 0x6D, 0x00, 0x63, 0x00,\r
- 0x6F, 0x00, 0x6D, 0x00, 0x5F, 0x00, 0x76, 0x00, 0x5F, 0x00, 0x31, 0x00, 0x5F, 0x00, 0x30, 0x00,\r
- 0x5F, 0x00, 0x34, 0x00, 0x5C, 0x00, 0x76, 0x00, 0x69, 0x00, 0x65, 0x00, 0x77, 0x00, 0x5C, 0x00,\r
- 0x64, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x5C, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00,\r
- 0x74, 0x00, 0x73, 0x00, 0x5C, 0x00, 0x69, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00,\r
- 0x73, 0x00, 0x5C, 0x00, 0x63, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x73, 0x00, 0x2E, 0x00,\r
- 0x6D, 0x00, 0x70, 0x00, 0x67, 0x00};\r
-\r
-\r
-\r
-\r
- public void testRead() throws Exception {\r
- ExVideoContainer record = new ExVideoContainer(data, 0, data.length);\r
- assertEquals(RecordTypes.ExVideoContainer.typeID, record.getRecordType());\r
-\r
- ExMediaAtom exMedia = record.getExMediaAtom();\r
- assertEquals(1, exMedia.getObjectId());\r
- assertNotNull(exMedia);\r
- assertFalse(exMedia.getFlag(ExMediaAtom.fLoop));\r
- assertFalse(exMedia.getFlag(ExMediaAtom.fNarration));\r
- assertFalse(exMedia.getFlag(ExMediaAtom.fRewind));\r
-\r
- CString path = record.getPathAtom();\r
- assertNotNull(exMedia);\r
- assertEquals("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg", path.getText());\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- ExVideoContainer record = new ExVideoContainer(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- ExVideoContainer record = new ExVideoContainer();\r
- record.getExMediaAtom().setObjectId(1);\r
- record.getPathAtom().setText("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg");\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+/**
+ * Tests that {@link HeadersFootersAtom} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestExVideoContainer extends TestCase {
+
+ // From a real file
+ private byte[] data = new byte[]{
+ 0x0F, 0x00, 0x05, 0x10, (byte) 0x9E, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x04, 0x10, 0x08, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, (byte)0xBA, 0x0F, (byte)0x86, 0x00, 0x00, 0x00,
+ 0x44, 0x00, 0x3A, 0x00, 0x5C, 0x00, 0x70, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x6A, 0x00, 0x65, 0x00,
+ 0x63, 0x00, 0x74, 0x00, 0x73, 0x00, 0x5C, 0x00, 0x53, 0x00, 0x63, 0x00, 0x68, 0x00, 0x75, 0x00,
+ 0x6C, 0x00, 0x65, 0x00, 0x72, 0x00, 0x41, 0x00, 0x47, 0x00, 0x5C, 0x00, 0x6D, 0x00, 0x63, 0x00,
+ 0x6F, 0x00, 0x6D, 0x00, 0x5F, 0x00, 0x76, 0x00, 0x5F, 0x00, 0x31, 0x00, 0x5F, 0x00, 0x30, 0x00,
+ 0x5F, 0x00, 0x34, 0x00, 0x5C, 0x00, 0x76, 0x00, 0x69, 0x00, 0x65, 0x00, 0x77, 0x00, 0x5C, 0x00,
+ 0x64, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x5C, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00,
+ 0x74, 0x00, 0x73, 0x00, 0x5C, 0x00, 0x69, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00,
+ 0x73, 0x00, 0x5C, 0x00, 0x63, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x73, 0x00, 0x2E, 0x00,
+ 0x6D, 0x00, 0x70, 0x00, 0x67, 0x00};
+
+
+
+
+ public void testRead() throws Exception {
+ ExVideoContainer record = new ExVideoContainer(data, 0, data.length);
+ assertEquals(RecordTypes.ExVideoContainer.typeID, record.getRecordType());
+
+ ExMediaAtom exMedia = record.getExMediaAtom();
+ assertEquals(1, exMedia.getObjectId());
+ assertNotNull(exMedia);
+ assertFalse(exMedia.getFlag(ExMediaAtom.fLoop));
+ assertFalse(exMedia.getFlag(ExMediaAtom.fNarration));
+ assertFalse(exMedia.getFlag(ExMediaAtom.fRewind));
+
+ CString path = record.getPathAtom();
+ assertNotNull(exMedia);
+ assertEquals("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg", path.getText());
+ }
+
+ public void testWrite() throws Exception {
+ ExVideoContainer record = new ExVideoContainer(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ ExVideoContainer record = new ExVideoContainer();
+ record.getExMediaAtom().setObjectId(1);
+ record.getPathAtom().setText("D:\\projects\\SchulerAG\\mcom_v_1_0_4\\view\\data\\tests\\images\\cards.mpg");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
*
* @author Yegor Kozlov
*/
-public class TestFontCollection extends TestCase {
+public final class TestFontCollection extends TestCase {
// From a real file
private byte[] data = new byte[] {
0x0F, 0x00, 0xD5-256, 0x07, 0x4C, 0x00, 0x00, 0x00,
// Font collection should contain 3 fonts
Record[] child = fonts.getChildRecords();
assertEquals(child.length, 3);
-
+
// Check we get the right font name for the indicies
assertEquals("Times New Roman", fonts.getFontWithId(0));
assertEquals("Helvetica", fonts.getFontWithId(1));
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests that {@link HeadersFootersAtom} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestHeadersFootersAtom extends TestCase {\r
- // From a real file\r
- private byte[] data = new byte[] {\r
- 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 00,\r
- 0x00, 0x00, 0x23, 0x00 };\r
-\r
- public void testRead() throws Exception {\r
- HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);\r
- assertEquals(RecordTypes.HeadersFootersAtom.typeID, record.getRecordType());\r
-\r
- assertEquals(0, record.getFormatId());\r
- assertEquals(0x23, record.getMask());\r
-\r
- assertTrue(record.getFlag(HeadersFootersAtom.fHasDate));\r
- assertTrue(record.getFlag(HeadersFootersAtom.fHasTodayDate));\r
- assertFalse(record.getFlag(HeadersFootersAtom.fHasUserDate));\r
- assertFalse(record.getFlag(HeadersFootersAtom.fHasSlideNumber));\r
- assertFalse(record.getFlag(HeadersFootersAtom.fHasHeader));\r
- assertTrue(record.getFlag(HeadersFootersAtom.fHasFooter));\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testNewRecord() throws Exception {\r
- HeadersFootersAtom record = new HeadersFootersAtom();\r
- record.setFlag(HeadersFootersAtom.fHasDate, true);\r
- record.setFlag(HeadersFootersAtom.fHasTodayDate, true);\r
- record.setFlag(HeadersFootersAtom.fHasFooter, true);\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(data, b));\r
- }\r
-\r
- public void testFlags() throws Exception {\r
- HeadersFootersAtom record = new HeadersFootersAtom();\r
-\r
- //in a new record all the bits are 0\r
- for(int i = 0; i < 6; i++) assertFalse(record.getFlag(1 << i));\r
-\r
- record.setFlag(HeadersFootersAtom.fHasTodayDate, true);\r
- assertTrue(record.getFlag(HeadersFootersAtom.fHasTodayDate));\r
-\r
- record.setFlag(HeadersFootersAtom.fHasTodayDate, true);\r
- assertTrue(record.getFlag(HeadersFootersAtom.fHasTodayDate));\r
-\r
- record.setFlag(HeadersFootersAtom.fHasTodayDate, false);\r
- assertFalse(record.getFlag(HeadersFootersAtom.fHasTodayDate));\r
-\r
- record.setFlag(HeadersFootersAtom.fHasTodayDate, false);\r
- assertFalse(record.getFlag(HeadersFootersAtom.fHasTodayDate));\r
-\r
- }\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+/**
+ * Tests that {@link HeadersFootersAtom} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestHeadersFootersAtom extends TestCase {
+ // From a real file
+ private byte[] data = new byte[] {
+ 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 00,
+ 0x00, 0x00, 0x23, 0x00 };
+
+ public void testRead() throws Exception {
+ HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);
+ assertEquals(RecordTypes.HeadersFootersAtom.typeID, record.getRecordType());
+
+ assertEquals(0, record.getFormatId());
+ assertEquals(0x23, record.getMask());
+
+ assertTrue(record.getFlag(HeadersFootersAtom.fHasDate));
+ assertTrue(record.getFlag(HeadersFootersAtom.fHasTodayDate));
+ assertFalse(record.getFlag(HeadersFootersAtom.fHasUserDate));
+ assertFalse(record.getFlag(HeadersFootersAtom.fHasSlideNumber));
+ assertFalse(record.getFlag(HeadersFootersAtom.fHasHeader));
+ assertTrue(record.getFlag(HeadersFootersAtom.fHasFooter));
+ }
+
+ public void testWrite() throws Exception {
+ HeadersFootersAtom record = new HeadersFootersAtom(data, 0, data.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testNewRecord() throws Exception {
+ HeadersFootersAtom record = new HeadersFootersAtom();
+ record.setFlag(HeadersFootersAtom.fHasDate, true);
+ record.setFlag(HeadersFootersAtom.fHasTodayDate, true);
+ record.setFlag(HeadersFootersAtom.fHasFooter, true);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(data, b));
+ }
+
+ public void testFlags() throws Exception {
+ HeadersFootersAtom record = new HeadersFootersAtom();
+
+ //in a new record all the bits are 0
+ for(int i = 0; i < 6; i++) assertFalse(record.getFlag(1 << i));
+
+ record.setFlag(HeadersFootersAtom.fHasTodayDate, true);
+ assertTrue(record.getFlag(HeadersFootersAtom.fHasTodayDate));
+
+ record.setFlag(HeadersFootersAtom.fHasTodayDate, true);
+ assertTrue(record.getFlag(HeadersFootersAtom.fHasTodayDate));
+
+ record.setFlag(HeadersFootersAtom.fHasTodayDate, false);
+ assertFalse(record.getFlag(HeadersFootersAtom.fHasTodayDate));
+
+ record.setFlag(HeadersFootersAtom.fHasTodayDate, false);
+ assertFalse(record.getFlag(HeadersFootersAtom.fHasTodayDate));
+
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests that {@link HeadersFootersContainer} works properly\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestHeadersFootersContainer extends TestCase {\r
- // SlideHeadersFootersContainer\r
- private byte[] slideData = new byte[] {\r
- 0x3F, 0x00, (byte)0xD9, 0x0F, 0x2E, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00,\r
- 0x20, 0x00, (byte)0xBA, 0x0F, 0x1A, 0x00, 0x00, 0x00,\r
- 0x4D, 0x00, 0x79, 0x00, 0x20, 0x00, 0x46, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x74,\r
- 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x2D, 0x00, 0x20, 0x00, 0x31, 0x00\r
-\r
- };\r
-\r
- // NotesHeadersFootersContainer\r
- private byte[] notesData = new byte[] {\r
- 0x4F, 0x00, (byte)0xD9, 0x0F, 0x48, 0x00, 0x00, 0x00,\r
- 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x00,\r
- 0x10, 0x00, (byte)0xBA, 0x0F, 0x16, 0x00, 0x00, 0x00,\r
- 0x4E, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x48, 0x00,\r
- 0x65, 0x00, 0x61, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00,\r
- 0x20, 0x00, (byte)0xBA, 0x0F, 0x16, 0x00, 0x00, 0x00,\r
- 0x4E, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x46, 0x00,\r
- 0x6F, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00\r
- };\r
-\r
- public void testReadSlideHeadersFootersContainer() throws Exception {\r
- HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);\r
- assertEquals(RecordTypes.HeadersFooters.typeID, record.getRecordType());\r
- assertEquals(HeadersFootersContainer.SlideHeadersFootersContainer, record.getOptions());\r
- assertEquals(2, record.getChildRecords().length);\r
-\r
- HeadersFootersAtom hdd = record.getHeadersFootersAtom();\r
- assertNotNull(hdd);\r
-\r
- CString csFooter = record.getFooterAtom();\r
- assertNotNull(csFooter);\r
- assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);\r
-\r
- assertEquals("My Footer - 1", csFooter.getText());\r
-\r
- assertNull(record.getUserDateAtom());\r
- assertNull(record.getHeaderAtom());\r
- }\r
-\r
- public void testWriteSlideHeadersFootersContainer() throws Exception {\r
- HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(slideData, b));\r
- }\r
-\r
- public void testNewSlideHeadersFootersContainer() throws Exception {\r
- HeadersFootersContainer record = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);\r
-\r
- assertNotNull(record.getHeadersFootersAtom());\r
- assertNull(record.getUserDateAtom());\r
- assertNull(record.getHeaderAtom());\r
- assertNull(record.getFooterAtom());\r
-\r
- HeadersFootersAtom hd = record.getHeadersFootersAtom();\r
- hd.setFlag(HeadersFootersAtom.fHasDate, true);\r
- hd.setFlag(HeadersFootersAtom.fHasTodayDate, true);\r
- hd.setFlag(HeadersFootersAtom.fHasFooter, true);\r
-\r
- CString csFooter = record.addFooterAtom();\r
- assertNotNull(csFooter);\r
- assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);\r
- csFooter.setText("My Footer - 1");\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(slideData, b));\r
- }\r
-\r
- public void testReadNotesHeadersFootersContainer() throws Exception {\r
- HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);\r
- assertEquals(RecordTypes.HeadersFooters.typeID, record.getRecordType());\r
- assertEquals(HeadersFootersContainer.NotesHeadersFootersContainer, record.getOptions());\r
- assertEquals(3, record.getChildRecords().length);\r
-\r
- HeadersFootersAtom hdd = record.getHeadersFootersAtom();\r
- assertNotNull(hdd);\r
-\r
- CString csHeader = record.getHeaderAtom();\r
- assertNotNull(csHeader);\r
- assertEquals(HeadersFootersContainer.HEADERATOM, csHeader.getOptions() >> 4);\r
- assertEquals("Note Header", csHeader.getText());\r
-\r
- CString csFooter = record.getFooterAtom();\r
- assertNotNull(csFooter);\r
- assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);\r
- assertEquals("Note Footer", csFooter.getText());\r
- }\r
-\r
- public void testWriteNotesHeadersFootersContainer() throws Exception {\r
- HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(notesData, b));\r
- }\r
-\r
- public void testNewNotesHeadersFootersContainer() throws Exception {\r
- HeadersFootersContainer record = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer);\r
-\r
- assertNotNull(record.getHeadersFootersAtom());\r
- assertNull(record.getUserDateAtom());\r
- assertNull(record.getHeaderAtom());\r
- assertNull(record.getFooterAtom());\r
-\r
- HeadersFootersAtom hd = record.getHeadersFootersAtom();\r
- hd.setFlag(HeadersFootersAtom.fHasDate, true);\r
- hd.setFlag(HeadersFootersAtom.fHasTodayDate, false);\r
- hd.setFlag(HeadersFootersAtom.fHasUserDate, true);\r
- hd.setFlag(HeadersFootersAtom.fHasSlideNumber, true);\r
- hd.setFlag(HeadersFootersAtom.fHasHeader, true);\r
- hd.setFlag(HeadersFootersAtom.fHasFooter, true);\r
-\r
- CString csHeader = record.addHeaderAtom();\r
- assertNotNull(csHeader);\r
- assertEquals(HeadersFootersContainer.HEADERATOM, csHeader.getOptions() >> 4);\r
- csHeader.setText("Note Header");\r
-\r
- CString csFooter = record.addFooterAtom();\r
- assertNotNull(csFooter);\r
- assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);\r
- csFooter.setText("Note Footer");\r
-\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- record.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertTrue(Arrays.equals(notesData, b));\r
- }\r
-\r
-}
\ No newline at end of file
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+/**
+ * Tests that {@link HeadersFootersContainer} works properly
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestHeadersFootersContainer extends TestCase {
+ // SlideHeadersFootersContainer
+ private byte[] slideData = new byte[] {
+ 0x3F, 0x00, (byte)0xD9, 0x0F, 0x2E, 0x00, 0x00, 0x00,
+ 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00,
+ 0x20, 0x00, (byte)0xBA, 0x0F, 0x1A, 0x00, 0x00, 0x00,
+ 0x4D, 0x00, 0x79, 0x00, 0x20, 0x00, 0x46, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x74,
+ 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x2D, 0x00, 0x20, 0x00, 0x31, 0x00
+
+ };
+
+ // NotesHeadersFootersContainer
+ private byte[] notesData = new byte[] {
+ 0x4F, 0x00, (byte)0xD9, 0x0F, 0x48, 0x00, 0x00, 0x00,
+ 0x00, 0x00, (byte)0xDA, 0x0F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x00,
+ 0x10, 0x00, (byte)0xBA, 0x0F, 0x16, 0x00, 0x00, 0x00,
+ 0x4E, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x48, 0x00,
+ 0x65, 0x00, 0x61, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00,
+ 0x20, 0x00, (byte)0xBA, 0x0F, 0x16, 0x00, 0x00, 0x00,
+ 0x4E, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x20, 0x00, 0x46, 0x00,
+ 0x6F, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00
+ };
+
+ public void testReadSlideHeadersFootersContainer() throws Exception {
+ HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);
+ assertEquals(RecordTypes.HeadersFooters.typeID, record.getRecordType());
+ assertEquals(HeadersFootersContainer.SlideHeadersFootersContainer, record.getOptions());
+ assertEquals(2, record.getChildRecords().length);
+
+ HeadersFootersAtom hdd = record.getHeadersFootersAtom();
+ assertNotNull(hdd);
+
+ CString csFooter = record.getFooterAtom();
+ assertNotNull(csFooter);
+ assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);
+
+ assertEquals("My Footer - 1", csFooter.getText());
+
+ assertNull(record.getUserDateAtom());
+ assertNull(record.getHeaderAtom());
+ }
+
+ public void testWriteSlideHeadersFootersContainer() throws Exception {
+ HeadersFootersContainer record = new HeadersFootersContainer(slideData, 0, slideData.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(slideData, b));
+ }
+
+ public void testNewSlideHeadersFootersContainer() throws Exception {
+ HeadersFootersContainer record = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);
+
+ assertNotNull(record.getHeadersFootersAtom());
+ assertNull(record.getUserDateAtom());
+ assertNull(record.getHeaderAtom());
+ assertNull(record.getFooterAtom());
+
+ HeadersFootersAtom hd = record.getHeadersFootersAtom();
+ hd.setFlag(HeadersFootersAtom.fHasDate, true);
+ hd.setFlag(HeadersFootersAtom.fHasTodayDate, true);
+ hd.setFlag(HeadersFootersAtom.fHasFooter, true);
+
+ CString csFooter = record.addFooterAtom();
+ assertNotNull(csFooter);
+ assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);
+ csFooter.setText("My Footer - 1");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(slideData, b));
+ }
+
+ public void testReadNotesHeadersFootersContainer() throws Exception {
+ HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);
+ assertEquals(RecordTypes.HeadersFooters.typeID, record.getRecordType());
+ assertEquals(HeadersFootersContainer.NotesHeadersFootersContainer, record.getOptions());
+ assertEquals(3, record.getChildRecords().length);
+
+ HeadersFootersAtom hdd = record.getHeadersFootersAtom();
+ assertNotNull(hdd);
+
+ CString csHeader = record.getHeaderAtom();
+ assertNotNull(csHeader);
+ assertEquals(HeadersFootersContainer.HEADERATOM, csHeader.getOptions() >> 4);
+ assertEquals("Note Header", csHeader.getText());
+
+ CString csFooter = record.getFooterAtom();
+ assertNotNull(csFooter);
+ assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);
+ assertEquals("Note Footer", csFooter.getText());
+ }
+
+ public void testWriteNotesHeadersFootersContainer() throws Exception {
+ HeadersFootersContainer record = new HeadersFootersContainer(notesData, 0, notesData.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(notesData, b));
+ }
+
+ public void testNewNotesHeadersFootersContainer() throws Exception {
+ HeadersFootersContainer record = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer);
+
+ assertNotNull(record.getHeadersFootersAtom());
+ assertNull(record.getUserDateAtom());
+ assertNull(record.getHeaderAtom());
+ assertNull(record.getFooterAtom());
+
+ HeadersFootersAtom hd = record.getHeadersFootersAtom();
+ hd.setFlag(HeadersFootersAtom.fHasDate, true);
+ hd.setFlag(HeadersFootersAtom.fHasTodayDate, false);
+ hd.setFlag(HeadersFootersAtom.fHasUserDate, true);
+ hd.setFlag(HeadersFootersAtom.fHasSlideNumber, true);
+ hd.setFlag(HeadersFootersAtom.fHasHeader, true);
+ hd.setFlag(HeadersFootersAtom.fHasFooter, true);
+
+ CString csHeader = record.addHeaderAtom();
+ assertNotNull(csHeader);
+ assertEquals(HeadersFootersContainer.HEADERATOM, csHeader.getOptions() >> 4);
+ csHeader.setText("Note Header");
+
+ CString csFooter = record.addFooterAtom();
+ assertNotNull(csFooter);
+ assertEquals(HeadersFootersContainer.FOOTERATOM, csFooter.getOptions() >> 4);
+ csFooter.setText("Note Footer");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ record.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertTrue(Arrays.equals(notesData, b));
+ }
+
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestNotesAtom extends TestCase {
+public final class TestNotesAtom extends TestCase {
// From a real file
private byte[] data_a = new byte[] { 1, 0, 0xF1-256, 3, 8, 0, 0, 0,
0, 0, 0, 0x80-256, 0, 0, 0x0D, 0x30 };
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestRecordContainer extends TestCase {
+public final class TestRecordContainer extends TestCase {
private RecordContainer recordContainer;
public void testIsAnAtom() {
assertFalse( recordContainer.isAnAtom() );
}
-
+
public void testAppendChildRecord() {
// Grab records for testing with
Record r = recordContainer.getChildRecords()[0];
Record rb = recordContainer.getChildRecords()[1];
Record rc = recordContainer.getChildRecords()[2];
Record rd = recordContainer.getChildRecords()[3];
-
+
// Start with an empty set
Record[] rs = new Record[0];
recordContainer._children = rs;
recordContainer.appendChildRecord(r);
Record[] nrs = recordContainer.getChildRecords();
-
+
assertEquals(1, nrs.length);
assertEquals(r, nrs[0]);
-
+
// Now start with one with 3 entries
rs = new Record[3];
recordContainer._children = rs;
rs[0] = rb;
rs[1] = rc;
rs[2] = rd;
-
+
recordContainer.appendChildRecord(r);
nrs = recordContainer.getChildRecords();
-
+
assertEquals(4, nrs.length);
assertEquals(rb, nrs[0]);
assertEquals(rc, nrs[1]);
assertEquals(rd, nrs[2]);
assertEquals(r, nrs[3]);
}
-
+
public void testAddChildAfter() {
// Working with new StyleTextPropAtom
Record newRecord = new StyleTextPropAtom(0);
-
+
// Try to add after a mid-record
Record[] cr = recordContainer.getChildRecords();
Record after = cr[2];
Record before = cr[3];
-
+
recordContainer.addChildAfter(newRecord, after);
Record[] ncr = recordContainer.getChildRecords();
-
+
assertEquals(cr.length+1, ncr.length);
assertEquals(after, ncr[2]);
assertEquals(newRecord, ncr[3]);
assertEquals(before, ncr[4]);
-
+
// Try again at the end
recordContainer._children = cr;
after = cr[cr.length-1];
-
+
recordContainer.addChildAfter(newRecord, after);
ncr = recordContainer.getChildRecords();
-
+
assertEquals(cr.length+1, ncr.length);
assertEquals(after, ncr[cr.length-1]);
assertEquals(newRecord, ncr[cr.length]);
}
-
+
public void testAddChildBefore() {
// Working with new StyleTextPropAtom
Record newRecord = new StyleTextPropAtom(0);
-
+
// Try to add before a mid-record
Record[] cr = recordContainer.getChildRecords();
Record before = cr[2];
-
+
recordContainer.addChildBefore(newRecord, before);
Record[] ncr = recordContainer.getChildRecords();
-
+
assertEquals(cr.length+1, ncr.length);
assertEquals(newRecord, ncr[2]);
assertEquals(before, ncr[3]);
-
-
+
+
// Try again at the end
recordContainer._children = cr;
before = cr[cr.length-1];
-
+
recordContainer.addChildBefore(newRecord, before);
ncr = recordContainer.getChildRecords();
-
+
assertEquals(cr.length+1, ncr.length);
assertEquals(newRecord, ncr[cr.length-1]);
assertEquals(before, ncr[cr.length]);
-
-
+
+
// And at the start
recordContainer._children = cr;
before = cr[0];
-
+
recordContainer.addChildBefore(newRecord, before);
ncr = recordContainer.getChildRecords();
-
+
assertEquals(cr.length+1, ncr.length);
assertEquals(newRecord, ncr[0]);
assertEquals(before, ncr[1]);
}
-
+
protected void setUp() throws Exception {
super.setUp();
-
+
// Find a real RecordContainer record
String dirname = System.getProperty("HSLF.testdata.path");
String filename = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hss = new HSLFSlideShow(filename);
-
+
Record[] r = hss.getRecords();
for(int i=0; i<r.length; i++) {
if(r[i] instanceof RecordContainer) {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestRecordTypes extends TestCase {
+public final class TestRecordTypes extends TestCase {
public void testPPTNameLookups() throws Exception {
assertEquals("MainMaster", RecordTypes.recordName(1016));
assertEquals("TextBytesAtom", RecordTypes.recordName(4008));
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestSlideAtom extends TestCase {
+public final class TestSlideAtom extends TestCase {
// From a real file
private byte[] data_a = new byte[] { 1, 0, 0xEF-256, 3, 0x18, 0, 0, 0,
- 0, 0, 0, 0, 0x0F, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80-256,
+ 0, 0, 0, 0, 0x0F, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80-256,
0, 1, 0, 0, 7, 0, 0x0C, 0x30 };
public void testRecordType() throws Exception {
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestSlidePersistAtom extends TestCase {
+public final class TestSlidePersistAtom extends TestCase {
// From a real file
private byte[] data_a = new byte[] { 0, 0, 0xF3-256, 3, 0x14, 0, 0, 0,
4, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0,
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.Arrays;\r
-\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-\r
-/**\r
- * Tests Sound-related records: SoundCollection(2020), Sound(2022) and SoundData(2023)).\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestSound extends TestCase {\r
- public void testRealFile() throws Exception {\r
- String cwd = System.getProperty("HSLF.testdata.path");\r
- FileInputStream is = new FileInputStream(new File(cwd, "sound.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- // Get the document\r
- Document doc = ppt.getDocumentRecord();\r
- SoundCollection soundCollection = null;\r
- Record[] doc_ch = doc.getChildRecords();\r
- for (int i = 0; i < doc_ch.length; i++) {\r
- if(doc_ch[i] instanceof SoundCollection){\r
- soundCollection = (SoundCollection)doc_ch[i];\r
- break;\r
- }\r
- }\r
- assertNotNull(soundCollection);\r
-\r
- Sound sound = null;\r
- Record[] sound_ch = soundCollection.getChildRecords();\r
- int k = 0;\r
- for (int i = 0; i < sound_ch.length; i++) {\r
- if(sound_ch[i] instanceof Sound){\r
- sound = (Sound)sound_ch[i];\r
- k++;\r
- }\r
- }\r
- assertNotNull(sound);\r
- assertEquals(1, k);\r
-\r
- assertEquals("ringin.wav", sound.getSoundName());\r
- assertEquals(".WAV", sound.getSoundType());\r
- assertNotNull(sound.getSoundData());\r
-\r
- File f = new File(cwd, "ringin.wav");\r
- int length = (int)f.length();\r
- byte[] ref_data = new byte[length];\r
- is = new FileInputStream(f);\r
- is.read(ref_data);\r
- is.close();\r
-\r
- assertTrue(Arrays.equals(ref_data, sound.getSoundData()));\r
-\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Arrays;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+/**
+ * Tests Sound-related records: SoundCollection(2020), Sound(2022) and SoundData(2023)).
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestSound extends TestCase {
+ public void testRealFile() throws Exception {
+ String cwd = System.getProperty("HSLF.testdata.path");
+ FileInputStream is = new FileInputStream(new File(cwd, "sound.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ // Get the document
+ Document doc = ppt.getDocumentRecord();
+ SoundCollection soundCollection = null;
+ Record[] doc_ch = doc.getChildRecords();
+ for (int i = 0; i < doc_ch.length; i++) {
+ if(doc_ch[i] instanceof SoundCollection){
+ soundCollection = (SoundCollection)doc_ch[i];
+ break;
+ }
+ }
+ assertNotNull(soundCollection);
+
+ Sound sound = null;
+ Record[] sound_ch = soundCollection.getChildRecords();
+ int k = 0;
+ for (int i = 0; i < sound_ch.length; i++) {
+ if(sound_ch[i] instanceof Sound){
+ sound = (Sound)sound_ch[i];
+ k++;
+ }
+ }
+ assertNotNull(sound);
+ assertEquals(1, k);
+
+ assertEquals("ringin.wav", sound.getSoundName());
+ assertEquals(".WAV", sound.getSoundType());
+ assertNotNull(sound.getSoundData());
+
+ File f = new File(cwd, "ringin.wav");
+ int length = (int)f.length();
+ byte[] ref_data = new byte[length];
+ is = new FileInputStream(f);
+ is.read(ref_data);
+ is.close();
+
+ assertTrue(Arrays.equals(ref_data, sound.getSoundData()));
+
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestStyleTextPropAtom extends TestCase {
+public final class TestStyleTextPropAtom extends TestCase {
/** From a real file: a paragraph with 4 different styles */
private byte[] data_a = new byte[] {
0, 0, 0xA1-256, 0x0F, 0x2A, 0, 0, 0,
- 0x36, 00, 00, 00, // paragraph is 54 long
+ 0x36, 00, 00, 00, // paragraph is 54 long
00, 00, // (paragraph reserved field)
00, 00, 00, 00, // it doesn't have any styles
0x15, 00, 00, 00, // first char run is 21 long
0x50, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00,
0x01, 0x04, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00,
- 0x01, 0x08, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x0C, 0x00, 0x00,
+ 0x01, 0x08, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x0C, 0x00, 0x00,
0x01, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00,
0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x01, 0x14, 0x00, 0x00,
0x01, 0x14, 0x01, 0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00,
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestTextBytesAtom extends TestCase {
+public final class TestTextBytesAtom extends TestCase {
// From a real file
- private byte[] data = new byte[] { 0, 0, 0xA8-256, 0x0f, 0x1c, 0, 0, 0,
- 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
+ private byte[] data = new byte[] { 0, 0, 0xA8-256, 0x0f, 0x1c, 0, 0, 0,
+ 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68,
0x65, 0x20, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x20, 0x6F, 0x6E,
0x20, 0x70, 0x61, 0x67, 0x65, 0x20, 0x32 };
private String data_text = "This is the title on page 2";
private byte[] alt_data = new byte[] { 0, 0, 0xA8-256, 0x0F, 0x14, 0, 0, 0,
- 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20,
+ 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20,
0x74, 0x65, 0x73, 0x74, 0x20, 0x74, 0x69, 0x74, 0x6C, 0x65 };
private String alt_text = "This is a test title";
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestTextCharsAtom extends TestCase {
+public final class TestTextCharsAtom extends TestCase {
// From a real file
- private byte[] data = new byte[] { 0, 0, 0xA0-256, 0x0f, 0x08, 0, 0, 0,
+ private byte[] data = new byte[] { 0, 0, 0xA0-256, 0x0f, 0x08, 0, 0, 0,
0x54, 0x00, 0x68, 0x00, 0x69, 0x00, 0x73, 0x00 };
private String data_text = "This";
private byte[] alt_data = new byte[] { 0, 0, 0xA0-256, 0x0F, 0x0a, 0, 0, 0,
assertEquals(alt_data[i],b[i]);
}
}
-
+
public void testWrite() throws Exception {
TextCharsAtom tca = new TextCharsAtom(data,0,data.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
assertEquals(data[i],b[i]);
}
}
-
+
public void testCreateNew() throws Exception {
TextCharsAtom tca = new TextCharsAtom();
assertEquals(0, tca.getText().length());
-
+
tca.setText(data_text);
assertEquals(data_text, tca.getText());
-
+
// Check it's now like data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tca.writeOut(baos);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestTextHeaderAtom extends TestCase {
+public final class TestTextHeaderAtom extends TestCase {
// From a real file
private byte[] notes_data = new byte[] { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 2, 0, 0, 0};
private byte[] title_data = new byte[] { 0, 0, 0x9f-256, 0x0f, 4, 0, 0, 0, 0, 0, 0, 0 };
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;\r
-import org.apache.poi.hslf.model.textproperties.TextProp;\r
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;\r
-import org.apache.poi.hslf.record.StyleTextPropAtom.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.util.HexDump;\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.LinkedList;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests TextRulerAtom\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestTextRulerAtom extends TestCase {\r
-\r
- //from a real file\r
- private byte[] data_1 = new byte[] {\r
- 0x00, 0x00, (byte)0xA6, 0x0F, 0x18, 0x00, 0x00, 0x00,\r
- (byte)0xF8, 0x1F, 0x00, 0x00, 0x75, 0x00, (byte)0xE2, 0x00, 0x59,\r
- 0x01, (byte)0xC3, 0x01, 0x1A, 0x03, (byte)0x87, 0x03, (byte)0xF8,\r
- 0x03, 0x69, 0x04, (byte)0xF6, 0x05, (byte)0xF6, 0x05\r
- };\r
-\r
- private byte[] data_2 = new byte[] {\r
- 0x00, 0x00, (byte)0xA6, 0x0F, 0x0A, 0x00, 0x00, 0x00,\r
- 0x10, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01\r
- };\r
-\r
- public void testReadRuler() throws Exception {\r
- TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);\r
- assertEquals(ruler.getNumberOfLevels(), 0);\r
- assertEquals(ruler.getDefaultTabSize(), 0);\r
-\r
- int[] tabStops = ruler.getTabStops();\r
- assertNull(tabStops);\r
-\r
- int[] textOffsets = ruler.getTextOffsets();\r
- assertTrue(Arrays.equals(new int[]{226, 451, 903, 1129, 1526}, textOffsets));\r
-\r
- int[] bulletOffsets = ruler.getBulletOffsets();\r
- assertTrue(Arrays.equals(new int[]{117, 345, 794, 1016, 1526}, bulletOffsets));\r
-\r
- }\r
-\r
- public void testWriteRuler() throws Exception {\r
- TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ruler.writeOut(out);\r
-\r
- byte[] result = out.toByteArray();\r
- assertTrue(Arrays.equals(result, data_1));\r
- }\r
-\r
- public void testRead2() throws Exception {\r
- TextRulerAtom ruler = TextRulerAtom.getParagraphInstance();\r
- ruler.setParagraphIndent((short)249, (short)321);\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- ruler.writeOut(out);\r
-\r
- byte[] result = out.toByteArray();\r
- assertTrue(Arrays.equals(result, data_2));\r
-\r
- }\r
-\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.TextProp;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.StyleTextPropAtom.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.util.HexDump;
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.LinkedList;
+import java.util.Arrays;
+
+/**
+ * Tests TextRulerAtom
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestTextRulerAtom extends TestCase {
+
+ //from a real file
+ private byte[] data_1 = new byte[] {
+ 0x00, 0x00, (byte)0xA6, 0x0F, 0x18, 0x00, 0x00, 0x00,
+ (byte)0xF8, 0x1F, 0x00, 0x00, 0x75, 0x00, (byte)0xE2, 0x00, 0x59,
+ 0x01, (byte)0xC3, 0x01, 0x1A, 0x03, (byte)0x87, 0x03, (byte)0xF8,
+ 0x03, 0x69, 0x04, (byte)0xF6, 0x05, (byte)0xF6, 0x05
+ };
+
+ private byte[] data_2 = new byte[] {
+ 0x00, 0x00, (byte)0xA6, 0x0F, 0x0A, 0x00, 0x00, 0x00,
+ 0x10, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01
+ };
+
+ public void testReadRuler() throws Exception {
+ TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
+ assertEquals(ruler.getNumberOfLevels(), 0);
+ assertEquals(ruler.getDefaultTabSize(), 0);
+
+ int[] tabStops = ruler.getTabStops();
+ assertNull(tabStops);
+
+ int[] textOffsets = ruler.getTextOffsets();
+ assertTrue(Arrays.equals(new int[]{226, 451, 903, 1129, 1526}, textOffsets));
+
+ int[] bulletOffsets = ruler.getBulletOffsets();
+ assertTrue(Arrays.equals(new int[]{117, 345, 794, 1016, 1526}, bulletOffsets));
+
+ }
+
+ public void testWriteRuler() throws Exception {
+ TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ruler.writeOut(out);
+
+ byte[] result = out.toByteArray();
+ assertTrue(Arrays.equals(result, data_1));
+ }
+
+ public void testRead2() throws Exception {
+ TextRulerAtom ruler = TextRulerAtom.getParagraphInstance();
+ ruler.setParagraphIndent((short)249, (short)321);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ruler.writeOut(out);
+
+ byte[] result = out.toByteArray();
+ assertTrue(Arrays.equals(result, data_2));
+
+ }
+
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;\r
-import org.apache.poi.hslf.model.textproperties.TextProp;\r
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;\r
-import org.apache.poi.hslf.record.StyleTextPropAtom.*;\r
-import org.apache.poi.hslf.usermodel.SlideShow;\r
-import org.apache.poi.util.HexDump;\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.util.LinkedList;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Tests TextSpecInfoAtom\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestTextSpecInfoAtom extends TestCase {\r
-\r
- //from a real file\r
- private byte[] data_1 = new byte[] {\r
- 0x00, 0x00, (byte)0xAA, 0x0F, 0x2C, 0x00, 0x00, 0x00,\r
- 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\r
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00,\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01,\r
- 0x00, 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
- };\r
-\r
-\r
- public void testRead() throws Exception {\r
- TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);\r
- TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();\r
- assertEquals(5, run.length);\r
-\r
- assertEquals(10, run[0].length());\r
- assertEquals(1, run[1].length());\r
- assertEquals(70, run[2].length());\r
- assertEquals(9, run[3].length());\r
- assertEquals(32, run[4].length());\r
-\r
- }\r
-\r
- public void testWrite() throws Exception {\r
- TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- spec.writeOut(out);\r
-\r
- byte[] result = out.toByteArray();\r
- assertTrue(Arrays.equals(result, data_1));\r
- }\r
-\r
- public void testReset() throws Exception {\r
- TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);\r
- spec.reset(32); //length of the parent text\r
-\r
- TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();\r
- assertEquals(1, run.length);\r
-\r
- assertEquals(32, run[0].length());\r
-\r
- //serialize and read again\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- spec.writeOut(out);\r
-\r
- byte[] result = out.toByteArray();\r
- TextSpecInfoAtom spec2 = new TextSpecInfoAtom(result, 0, result.length);\r
- TextSpecInfoAtom.TextSpecInfoRun[] run2 = spec2.getTextSpecInfoRuns();\r
- assertEquals(1, run2.length);\r
-\r
- assertEquals(32, run2[0].length());\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.TextProp;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.StyleTextPropAtom.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.util.HexDump;
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.util.LinkedList;
+import java.util.Arrays;
+
+/**
+ * Tests TextSpecInfoAtom
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestTextSpecInfoAtom extends TestCase {
+
+ //from a real file
+ private byte[] data_1 = new byte[] {
+ 0x00, 0x00, (byte)0xAA, 0x0F, 0x2C, 0x00, 0x00, 0x00,
+ 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
+
+ public void testRead() throws Exception {
+ TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
+ TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
+ assertEquals(5, run.length);
+
+ assertEquals(10, run[0].length());
+ assertEquals(1, run[1].length());
+ assertEquals(70, run[2].length());
+ assertEquals(9, run[3].length());
+ assertEquals(32, run[4].length());
+
+ }
+
+ public void testWrite() throws Exception {
+ TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ spec.writeOut(out);
+
+ byte[] result = out.toByteArray();
+ assertTrue(Arrays.equals(result, data_1));
+ }
+
+ public void testReset() throws Exception {
+ TextSpecInfoAtom spec = new TextSpecInfoAtom(data_1, 0, data_1.length);
+ spec.reset(32); //length of the parent text
+
+ TextSpecInfoAtom.TextSpecInfoRun[] run = spec.getTextSpecInfoRuns();
+ assertEquals(1, run.length);
+
+ assertEquals(32, run[0].length());
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ spec.writeOut(out);
+
+ byte[] result = out.toByteArray();
+ TextSpecInfoAtom spec2 = new TextSpecInfoAtom(result, 0, result.length);
+ TextSpecInfoAtom.TextSpecInfoRun[] run2 = spec2.getTextSpecInfoRuns();
+ assertEquals(1, run2.length);
+
+ assertEquals(32, run2[0].length());
+ }
+}
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
- \r
-\r
-\r
-package org.apache.poi.hslf.record;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import java.io.ByteArrayOutputStream;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Date;\r
-\r
-/**\r
- * Tests that TxInteractiveInfoAtom works properly.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestTxInteractiveInfoAtom extends TestCase {\r
- // From WithLinks.ppt \r
- private byte[] data_a = new byte[] { \r
- 00, 00, (byte)0xDF, 0x0F, 0x08, 00, 00, 00,\r
- 0x19, 00, 00, 00, 0x38, 00, 00, 00\r
- };\r
-\r
- private byte[] data_b = new byte[] {\r
- 00, 00, (byte)0xDF, 0x0F, 0x08, 00, 00, 00,\r
- 0x39, 00, 00, 00, 0x4E, 00, 00, 00\r
- };\r
-\r
- public void testRead() throws Exception {\r
- TxInteractiveInfoAtom ia1 = new TxInteractiveInfoAtom(data_a, 0, data_a.length);\r
-\r
- assertEquals(4063, ia1.getRecordType());\r
- assertEquals(25, ia1.getStartIndex());\r
- assertEquals(56, ia1.getEndIndex());\r
-\r
- TxInteractiveInfoAtom ia2 = new TxInteractiveInfoAtom(data_b, 0, data_b.length);\r
-\r
- assertEquals(4063, ia2.getRecordType());\r
- assertEquals(57, ia2.getStartIndex());\r
- assertEquals(78, ia2.getEndIndex());\r
- }\r
- \r
- public void testWrite() throws Exception {\r
- TxInteractiveInfoAtom atom = new TxInteractiveInfoAtom(data_a, 0, data_a.length);\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- atom.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- assertEquals(data_a.length, b.length);\r
- for(int i=0; i<data_a.length; i++) {\r
- assertEquals(data_a[i],b[i]);\r
- }\r
- }\r
-\r
- // Create A from scratch\r
- public void testCreate() throws Exception {\r
- TxInteractiveInfoAtom ia = new TxInteractiveInfoAtom();\r
- \r
- // Set values\r
- ia.setStartIndex(25);\r
- ia.setEndIndex(56);\r
-\r
- // Check it's now the same as a\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- ia.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
- \r
- assertEquals(data_a.length, b.length);\r
- for(int i=0; i<data_a.length; i++) {\r
- assertEquals(data_a[i],b[i]);\r
- }\r
- }\r
-\r
- // Try to turn a into b\r
- public void testChange() throws Exception {\r
- TxInteractiveInfoAtom ia = new TxInteractiveInfoAtom(data_a, 0, data_a.length);\r
-\r
- // Change the number\r
- ia.setStartIndex(57);\r
- ia.setEndIndex(78);\r
-\r
- // Check bytes are now the same\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- ia.writeOut(baos);\r
- byte[] b = baos.toByteArray();\r
-\r
- // Should now be the same\r
- assertEquals(data_b.length, b.length);\r
- for(int i=0; i<data_b.length; i++) {\r
- assertEquals(data_b[i],b[i]);\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Tests that TxInteractiveInfoAtom works properly.
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestTxInteractiveInfoAtom extends TestCase {
+ // From WithLinks.ppt
+ private byte[] data_a = new byte[] {
+ 00, 00, (byte)0xDF, 0x0F, 0x08, 00, 00, 00,
+ 0x19, 00, 00, 00, 0x38, 00, 00, 00
+ };
+
+ private byte[] data_b = new byte[] {
+ 00, 00, (byte)0xDF, 0x0F, 0x08, 00, 00, 00,
+ 0x39, 00, 00, 00, 0x4E, 00, 00, 00
+ };
+
+ public void testRead() throws Exception {
+ TxInteractiveInfoAtom ia1 = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
+
+ assertEquals(4063, ia1.getRecordType());
+ assertEquals(25, ia1.getStartIndex());
+ assertEquals(56, ia1.getEndIndex());
+
+ TxInteractiveInfoAtom ia2 = new TxInteractiveInfoAtom(data_b, 0, data_b.length);
+
+ assertEquals(4063, ia2.getRecordType());
+ assertEquals(57, ia2.getStartIndex());
+ assertEquals(78, ia2.getEndIndex());
+ }
+
+ public void testWrite() throws Exception {
+ TxInteractiveInfoAtom atom = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ atom.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertEquals(data_a.length, b.length);
+ for(int i=0; i<data_a.length; i++) {
+ assertEquals(data_a[i],b[i]);
+ }
+ }
+
+ // Create A from scratch
+ public void testCreate() throws Exception {
+ TxInteractiveInfoAtom ia = new TxInteractiveInfoAtom();
+
+ // Set values
+ ia.setStartIndex(25);
+ ia.setEndIndex(56);
+
+ // Check it's now the same as a
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ia.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertEquals(data_a.length, b.length);
+ for(int i=0; i<data_a.length; i++) {
+ assertEquals(data_a[i],b[i]);
+ }
+ }
+
+ // Try to turn a into b
+ public void testChange() throws Exception {
+ TxInteractiveInfoAtom ia = new TxInteractiveInfoAtom(data_a, 0, data_a.length);
+
+ // Change the number
+ ia.setStartIndex(57);
+ ia.setEndIndex(78);
+
+ // Check bytes are now the same
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ia.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ // Should now be the same
+ assertEquals(data_b.length, b.length);
+ for(int i=0; i<data_b.length; i++) {
+ assertEquals(data_b[i],b[i]);
+ }
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hslf.record;
import junit.framework.TestCase;
*
* @author Yegor Kozlov
*/
-public class TestTxMasterStyleAtom extends TestCase {
+public final class TestTxMasterStyleAtom extends TestCase {
protected SlideShow _ppt;
public void setUp() throws Exception{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.record;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestUserEditAtom extends TestCase {
+public final class TestUserEditAtom extends TestCase {
// From a real file
private byte[] data_a = new byte[] { 0, 0, 0xF5-256, 0x0F, 0x1C, 0, 0, 0,
00, 01, 00, 00, 0xD9-256, 18, 00, 03,
- 00, 00, 00, 00, 00, 0x18, 00, 00, 01, 00, 00, 00,
+ 00, 00, 00, 00, 00, 0x18, 00, 00, 01, 00, 00, 00,
05, 00, 00, 00, 01, 00, 0xF6-256, 77 };
public void testRecordType() throws Exception {
// An empty SlideShow
private HSLFSlideShow hss_empty;
private SlideShow ss_empty;
-
+
// A SlideShow with one slide
private HSLFSlideShow hss_one;
private SlideShow ss_one;
-
+
// A SlideShow with two slides
private HSLFSlideShow hss_two;
private SlideShow ss_two;
-
+
/**
* Create/open the slideshows
*/
public void setUp() throws Exception {
hss_empty = HSLFSlideShow.create();
ss_empty = new SlideShow(hss_empty);
-
+
String dirname = System.getProperty("HSLF.testdata.path");
-
+
String filename = dirname + "/Single_Coloured_Page.ppt";
hss_one = new HSLFSlideShow(filename);
ss_one = new SlideShow(hss_one);
-
+
filename = dirname + "/basic_test_ppt_file.ppt";
hss_two = new HSLFSlideShow(filename);
ss_two = new SlideShow(hss_two);
}
-
+
/**
* Test adding a slide to an empty slideshow
*/
public void testAddSlideToEmpty() throws Exception {
// Doesn't have any slides
assertEquals(0, ss_empty.getSlides().length);
-
+
// Should only have a master SLWT
assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_empty.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it now has a slide
assertEquals(1, ss_read.getSlides().length);
// Check it now has two SLWTs
assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
-
+
// And check it's as expected
slide = ss_read.getSlides()[0];
assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber());
}
-
+
/**
* Test adding a slide to an existing slideshow
*/
// Has one slide
assertEquals(1, ss_one.getSlides().length);
Slide s1 = ss_one.getSlides()[0];
-
+
// Should have two SLTWs
assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
-
+
// Add a second one
Slide s2 = ss_one.createSlide();
assertEquals(2, ss_one.getSlides().length);
assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
-
+
// Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_one.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it now has two slides
assertEquals(2, ss_read.getSlides().length);
-
+
// Should still have two SLTWs
assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length);
-
+
// And check it's as expected
s1 = ss_read.getSlides()[0];
s2 = ss_read.getSlides()[1];
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
}
-
+
/**
* Test adding a slide to an existing slideshow,
* with two slides already
assertEquals(2, ss_two.getSlides().length);
Slide s1 = ss_two.getSlides()[0];
Slide s2 = ss_two.getSlides()[1];
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId()); // master has notes
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_two.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it now has three slides
assertEquals(3, ss_read.getSlides().length);
-
+
// And check it's as expected
s1 = ss_read.getSlides()[0];
s2 = ss_read.getSlides()[1];
-\r
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hslf.usermodel;\r
-\r
-import junit.framework.TestCase;\r
-import org.apache.poi.hslf.HSLFSlideShow;\r
-import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;\r
-import org.apache.poi.hslf.model.*;\r
-import org.apache.poi.hslf.model.Shape;\r
-\r
-import java.io.*;\r
-import java.util.HashSet;\r
-import java.util.HashMap;\r
-import java.util.ArrayList;\r
-import java.awt.*;\r
-\r
-/**\r
- * Testcases for bugs entered in bugzilla\r
- * the Test name contains the bugzilla bug id\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestBugs extends TestCase {\r
- protected String cwd = System.getProperty("HSLF.testdata.path");\r
-\r
- /**\r
- * Bug 41384: Array index wrong in record creation\r
- */\r
- public void test41384() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "41384.ppt"));\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- assertEquals(1, ppt.getSlides().length);\r
-\r
- PictureData[] pict = ppt.getPictureData();\r
- assertEquals(2, pict.length);\r
- assertEquals(Picture.JPEG, pict[0].getType());\r
- assertEquals(Picture.JPEG, pict[1].getType());\r
- }\r
-\r
- /**\r
- * First fix from Bug 42474: NPE in RichTextRun.isBold()\r
- * when the RichTextRun comes from a Notes model object\r
- */\r
- public void test42474_1() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42474-1.ppt"));\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- assertTrue("No Exceptions while reading file", true);\r
- assertEquals(2, ppt.getSlides().length);\r
-\r
- TextRun txrun;\r
- Notes notes;\r
-\r
- notes = ppt.getSlides()[0].getNotesSheet();\r
- assertNotNull(notes);\r
- txrun = notes.getTextRuns()[0];\r
- assertEquals("Notes-1", txrun.getRawText());\r
- assertEquals(false, txrun.getRichTextRuns()[0].isBold());\r
-\r
- //notes for the second slide are in bold\r
- notes = ppt.getSlides()[1].getNotesSheet();\r
- assertNotNull(notes);\r
- txrun = notes.getTextRuns()[0];\r
- assertEquals("Notes-2", txrun.getRawText());\r
- assertEquals(true, txrun.getRichTextRuns()[0].isBold());\r
-\r
- }\r
-\r
- /**\r
- * Second fix from Bug 42474: Incorrect matching of notes to slides\r
- */\r
- public void test42474_2() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42474-2.ppt"));\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
-\r
- //map slide number and starting phrase of its notes\r
- HashMap notesMap = new HashMap();\r
- notesMap.put(new Integer(4), "For decades before calculators");\r
- notesMap.put(new Integer(5), "Several commercial applications");\r
- notesMap.put(new Integer(6), "There are three variations of LNS that are discussed here");\r
- notesMap.put(new Integer(7), "Although multiply and square root are easier");\r
- notesMap.put(new Integer(8), "The bus Z is split into Z_H and Z_L");\r
-\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- Integer slideNumber = new Integer(slide[i].getSlideNumber());\r
- Notes notes = slide[i].getNotesSheet();\r
- if (notesMap.containsKey(slideNumber)){\r
- assertNotNull(notes);\r
- String text = notes.getTextRuns()[0].getRawText();\r
- String startingPhrase = (String)notesMap.get(slideNumber);\r
- assertTrue("Notes for slide " + slideNumber + " must start with " +\r
- startingPhrase , text.startsWith(startingPhrase));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns\r
- */\r
- public void test42485 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt"));\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- Shape[] shape = ppt.getSlides()[0].getShapes();\r
- for (int i = 0; i < shape.length; i++) {\r
- if(shape[i] instanceof ShapeGroup){\r
- ShapeGroup group = (ShapeGroup)shape[i];\r
- Shape[] sh = group.getShapes();\r
- for (int j = 0; j < sh.length; j++) {\r
- if( sh[j] instanceof TextBox){\r
- TextBox txt = (TextBox)sh[j];\r
- assertNotNull(txt.getTextRun());\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Bug 42484: NullPointerException from ShapeGroup.getAnchor()\r
- */\r
- public void test42484 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt")); //test file is the same as for bug 42485\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- Shape[] shape = ppt.getSlides()[0].getShapes();\r
- for (int i = 0; i < shape.length; i++) {\r
- if(shape[i] instanceof ShapeGroup){\r
- ShapeGroup group = (ShapeGroup)shape[i];\r
- assertNotNull(group.getAnchor());\r
- Shape[] sh = group.getShapes();\r
- for (int j = 0; j < sh.length; j++) {\r
- assertNotNull(sh[j].getAnchor());\r
- }\r
- }\r
- }\r
- assertTrue("No Exceptions while reading file", true);\r
- }\r
-\r
- /**\r
- * Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file\r
- */\r
- public void test41381() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "alterman_security.ppt"));\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- assertEquals(1, ppt.getSlidesMasters().length);\r
- assertEquals(1, ppt.getTitleMasters().length);\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- MasterSheet master = slide[i].getMasterSheet();\r
- if (i == 0) assertTrue(master instanceof TitleMaster); //the first slide follows TitleMaster\r
- else assertTrue(master instanceof SlideMaster);\r
- }\r
- }\r
-\r
- /**\r
- * Bug 42486: Failure parsing a seemingly valid PPT\r
- */\r
- public void test42486 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt"));\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- Shape[] shape = slide[i].getShapes();\r
- }\r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- }\r
-\r
- /**\r
- * Bug 42524: NPE in Shape.getShapeType()\r
- */\r
- public void test42524 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt")); //test file is the same as for Bug 42486\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
- //walk down the tree and see if there were no errors while reading\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- Shape[] shape = slide[i].getShapes();\r
- for (int j = 0; j < shape.length; j++) {\r
- assertNotNull(shape[j].getShapeName());\r
- if (shape[j] instanceof ShapeGroup){\r
- ShapeGroup group = (ShapeGroup)shape[j];\r
- Shape[] comps = group.getShapes();\r
- for (int k = 0; k < comps.length; k++) {\r
- assertNotNull(comps[k].getShapeName());\r
- }\r
- }\r
- }\r
-\r
- }\r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- }\r
-\r
- /**\r
- * Bug 42520: NPE in Picture.getPictureData()\r
- */\r
- public void test42520 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "42520.ppt")); //test file is the same as for Bug 42486\r
- HSLFSlideShow hslf = new HSLFSlideShow(is);\r
- is.close();\r
-\r
- SlideShow ppt = new SlideShow(hslf);\r
-\r
- //test case from the bug report\r
- ShapeGroup shapeGroup = (ShapeGroup)ppt.getSlides()[11].getShapes()[10];\r
- Picture picture = (Picture)shapeGroup.getShapes()[0];\r
- picture.getPictureData();\r
-\r
- //walk down the tree and see if there were no errors while reading\r
- Slide[] slide = ppt.getSlides();\r
- for (int i = 0; i < slide.length; i++) {\r
- Shape[] shape = slide[i].getShapes();\r
- for (int j = 0; j < shape.length; j++) {\r
- if (shape[j] instanceof ShapeGroup){\r
- ShapeGroup group = (ShapeGroup)shape[j];\r
- Shape[] comps = group.getShapes();\r
- for (int k = 0; k < comps.length; k++) {\r
- Shape comp = comps[k];\r
- if (comp instanceof Picture){\r
- PictureData pict = ((Picture)comp).getPictureData();\r
- }\r
- }\r
- }\r
- }\r
-\r
- }\r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- }\r
-\r
- /**\r
- * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.\r
- * ( also fixed followup: getTextRuns() returns no text )\r
- */\r
- public void test38256 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "38256.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
- \r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- Slide[] slide = ppt.getSlides();\r
- assertEquals(1, slide.length);\r
- TextRun[] runs = slide[0].getTextRuns();\r
- assertEquals(4, runs.length);\r
-\r
- HashSet txt = new HashSet();\r
- txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D");\r
- txt.add("Have a HAPPY DAY");\r
- txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026");\r
- txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!");\r
-\r
- for (int i = 0; i < runs.length; i++) {\r
- String text = runs[i].getRawText();\r
- assertTrue(text, txt.contains(text));\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.\r
- * ( also fixed followup: getTextRuns() returns no text )\r
- */\r
- public void test43781 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- assertTrue("No Exceptions while reading file", true);\r
-\r
- Slide slide = ppt.getSlides()[0];\r
- TextRun[] tr1 = slide.getTextRuns();\r
-\r
- ArrayList lst = new ArrayList();\r
- Shape[] shape = slide.getShapes();\r
- for (int i = 0; i < shape.length; i++) {\r
- if( shape[i] instanceof TextShape){\r
- TextRun textRun = ((TextShape)shape[i]).getTextRun();\r
- if(textRun != null) lst.add(textRun);\r
- }\r
-\r
- }\r
- TextRun[] tr2 = new TextRun[lst.size()];\r
- lst.toArray(tr2);\r
-\r
- assertEquals(tr1.length, tr2.length);\r
- for (int i = 0; i < tr1.length; i++) {\r
- assertEquals(tr1[i].getText(), tr2[i].getText());\r
- }\r
- }\r
-\r
- /**\r
- * Bug 44296: HSLF Not Extracting Slide Background Image\r
- */\r
- public void test44296 () throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "44296.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- Slide slide = ppt.getSlides()[0];\r
-\r
- Background b = slide.getBackground();\r
- Fill f = b.getFill();\r
- assertEquals(Fill.FILL_PICTURE, f.getFillType());\r
-\r
- PictureData pict = f.getPictureData();\r
- assertNotNull(pict);\r
- assertEquals(Picture.JPEG, pict.getType());\r
- }\r
-\r
- /**\r
- * Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing\r
- */\r
- public void test44770() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "44770.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- assertTrue("No Exceptions while reading file", true);\r
- }\r
-\r
- /**\r
- * Bug 41071: Will not extract text from Powerpoint TextBoxes\r
- */\r
- public void test41071() throws Exception {\r
- FileInputStream is = new FileInputStream(new File(cwd, "41071.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- Slide slide = ppt.getSlides()[0];\r
- Shape[] sh = slide.getShapes();\r
- assertEquals(1, sh.length);\r
- assertTrue(sh[0] instanceof TextShape);\r
- TextShape tx = (TextShape)sh[0];\r
- assertEquals("Fundera, planera och involvera.", tx.getTextRun().getText());\r
-\r
- TextRun[] run = slide.getTextRuns();\r
- assertEquals(1, run.length);\r
- assertEquals("Fundera, planera och involvera.", run[0].getText());\r
- }\r
- \r
- /**\r
- * PowerPoint 95 files should throw a more helpful exception\r
- * @throws Exception\r
- */\r
- public void test41711() throws Exception {\r
- // New file is fine\r
- FileInputStream is = new FileInputStream(new File(cwd, "SampleShow.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- \r
- // PowerPoint 95 gives an old format exception\r
- is = new FileInputStream(new File(cwd, "PPT95.ppt"));\r
- try {\r
- new SlideShow(is);\r
- fail("OldPowerPointFormatException should've been thrown");\r
- } catch(OldPowerPointFormatException e) {\r
- // Good\r
- }\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.model.Shape;
+
+import java.io.*;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.awt.*;
+
+/**
+ * Testcases for bugs entered in bugzilla
+ * the Test name contains the bugzilla bug id
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestBugs extends TestCase {
+ protected String cwd = System.getProperty("HSLF.testdata.path");
+
+ /**
+ * Bug 41384: Array index wrong in record creation
+ */
+ public void test41384() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "41384.ppt"));
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ assertTrue("No Exceptions while reading file", true);
+
+ assertEquals(1, ppt.getSlides().length);
+
+ PictureData[] pict = ppt.getPictureData();
+ assertEquals(2, pict.length);
+ assertEquals(Picture.JPEG, pict[0].getType());
+ assertEquals(Picture.JPEG, pict[1].getType());
+ }
+
+ /**
+ * First fix from Bug 42474: NPE in RichTextRun.isBold()
+ * when the RichTextRun comes from a Notes model object
+ */
+ public void test42474_1() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42474-1.ppt"));
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ assertTrue("No Exceptions while reading file", true);
+ assertEquals(2, ppt.getSlides().length);
+
+ TextRun txrun;
+ Notes notes;
+
+ notes = ppt.getSlides()[0].getNotesSheet();
+ assertNotNull(notes);
+ txrun = notes.getTextRuns()[0];
+ assertEquals("Notes-1", txrun.getRawText());
+ assertEquals(false, txrun.getRichTextRuns()[0].isBold());
+
+ //notes for the second slide are in bold
+ notes = ppt.getSlides()[1].getNotesSheet();
+ assertNotNull(notes);
+ txrun = notes.getTextRuns()[0];
+ assertEquals("Notes-2", txrun.getRawText());
+ assertEquals(true, txrun.getRichTextRuns()[0].isBold());
+
+ }
+
+ /**
+ * Second fix from Bug 42474: Incorrect matching of notes to slides
+ */
+ public void test42474_2() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42474-2.ppt"));
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+
+ //map slide number and starting phrase of its notes
+ HashMap notesMap = new HashMap();
+ notesMap.put(new Integer(4), "For decades before calculators");
+ notesMap.put(new Integer(5), "Several commercial applications");
+ notesMap.put(new Integer(6), "There are three variations of LNS that are discussed here");
+ notesMap.put(new Integer(7), "Although multiply and square root are easier");
+ notesMap.put(new Integer(8), "The bus Z is split into Z_H and Z_L");
+
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ Integer slideNumber = new Integer(slide[i].getSlideNumber());
+ Notes notes = slide[i].getNotesSheet();
+ if (notesMap.containsKey(slideNumber)){
+ assertNotNull(notes);
+ String text = notes.getTextRuns()[0].getRawText();
+ String startingPhrase = (String)notesMap.get(slideNumber);
+ assertTrue("Notes for slide " + slideNumber + " must start with " +
+ startingPhrase , text.startsWith(startingPhrase));
+ }
+ }
+ }
+
+ /**
+ * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
+ */
+ public void test42485 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt"));
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ Shape[] shape = ppt.getSlides()[0].getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ if(shape[i] instanceof ShapeGroup){
+ ShapeGroup group = (ShapeGroup)shape[i];
+ Shape[] sh = group.getShapes();
+ for (int j = 0; j < sh.length; j++) {
+ if( sh[j] instanceof TextBox){
+ TextBox txt = (TextBox)sh[j];
+ assertNotNull(txt.getTextRun());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Bug 42484: NullPointerException from ShapeGroup.getAnchor()
+ */
+ public void test42484 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42485.ppt")); //test file is the same as for bug 42485
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ Shape[] shape = ppt.getSlides()[0].getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ if(shape[i] instanceof ShapeGroup){
+ ShapeGroup group = (ShapeGroup)shape[i];
+ assertNotNull(group.getAnchor());
+ Shape[] sh = group.getShapes();
+ for (int j = 0; j < sh.length; j++) {
+ assertNotNull(sh[j].getAnchor());
+ }
+ }
+ }
+ assertTrue("No Exceptions while reading file", true);
+ }
+
+ /**
+ * Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file
+ */
+ public void test41381() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "alterman_security.ppt"));
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ assertTrue("No Exceptions while reading file", true);
+
+ assertEquals(1, ppt.getSlidesMasters().length);
+ assertEquals(1, ppt.getTitleMasters().length);
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ MasterSheet master = slide[i].getMasterSheet();
+ if (i == 0) assertTrue(master instanceof TitleMaster); //the first slide follows TitleMaster
+ else assertTrue(master instanceof SlideMaster);
+ }
+ }
+
+ /**
+ * Bug 42486: Failure parsing a seemingly valid PPT
+ */
+ public void test42486 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt"));
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ }
+ assertTrue("No Exceptions while reading file", true);
+
+ }
+
+ /**
+ * Bug 42524: NPE in Shape.getShapeType()
+ */
+ public void test42524 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt")); //test file is the same as for Bug 42486
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+ //walk down the tree and see if there were no errors while reading
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ for (int j = 0; j < shape.length; j++) {
+ assertNotNull(shape[j].getShapeName());
+ if (shape[j] instanceof ShapeGroup){
+ ShapeGroup group = (ShapeGroup)shape[j];
+ Shape[] comps = group.getShapes();
+ for (int k = 0; k < comps.length; k++) {
+ assertNotNull(comps[k].getShapeName());
+ }
+ }
+ }
+
+ }
+ assertTrue("No Exceptions while reading file", true);
+
+ }
+
+ /**
+ * Bug 42520: NPE in Picture.getPictureData()
+ */
+ public void test42520 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "42520.ppt")); //test file is the same as for Bug 42486
+ HSLFSlideShow hslf = new HSLFSlideShow(is);
+ is.close();
+
+ SlideShow ppt = new SlideShow(hslf);
+
+ //test case from the bug report
+ ShapeGroup shapeGroup = (ShapeGroup)ppt.getSlides()[11].getShapes()[10];
+ Picture picture = (Picture)shapeGroup.getShapes()[0];
+ picture.getPictureData();
+
+ //walk down the tree and see if there were no errors while reading
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ for (int j = 0; j < shape.length; j++) {
+ if (shape[j] instanceof ShapeGroup){
+ ShapeGroup group = (ShapeGroup)shape[j];
+ Shape[] comps = group.getShapes();
+ for (int k = 0; k < comps.length; k++) {
+ Shape comp = comps[k];
+ if (comp instanceof Picture){
+ PictureData pict = ((Picture)comp).getPictureData();
+ }
+ }
+ }
+ }
+
+ }
+ assertTrue("No Exceptions while reading file", true);
+
+ }
+
+ /**
+ * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
+ * ( also fixed followup: getTextRuns() returns no text )
+ */
+ public void test38256 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "38256.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ assertTrue("No Exceptions while reading file", true);
+
+ Slide[] slide = ppt.getSlides();
+ assertEquals(1, slide.length);
+ TextRun[] runs = slide[0].getTextRuns();
+ assertEquals(4, runs.length);
+
+ HashSet txt = new HashSet();
+ txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D");
+ txt.add("Have a HAPPY DAY");
+ txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026");
+ txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!");
+
+ for (int i = 0; i < runs.length; i++) {
+ String text = runs[i].getRawText();
+ assertTrue(text, txt.contains(text));
+ }
+
+ }
+
+ /**
+ * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
+ * ( also fixed followup: getTextRuns() returns no text )
+ */
+ public void test43781 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "43781.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ assertTrue("No Exceptions while reading file", true);
+
+ Slide slide = ppt.getSlides()[0];
+ TextRun[] tr1 = slide.getTextRuns();
+
+ ArrayList lst = new ArrayList();
+ Shape[] shape = slide.getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ if( shape[i] instanceof TextShape){
+ TextRun textRun = ((TextShape)shape[i]).getTextRun();
+ if(textRun != null) lst.add(textRun);
+ }
+
+ }
+ TextRun[] tr2 = new TextRun[lst.size()];
+ lst.toArray(tr2);
+
+ assertEquals(tr1.length, tr2.length);
+ for (int i = 0; i < tr1.length; i++) {
+ assertEquals(tr1[i].getText(), tr2[i].getText());
+ }
+ }
+
+ /**
+ * Bug 44296: HSLF Not Extracting Slide Background Image
+ */
+ public void test44296 () throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "44296.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Slide slide = ppt.getSlides()[0];
+
+ Background b = slide.getBackground();
+ Fill f = b.getFill();
+ assertEquals(Fill.FILL_PICTURE, f.getFillType());
+
+ PictureData pict = f.getPictureData();
+ assertNotNull(pict);
+ assertEquals(Picture.JPEG, pict.getType());
+ }
+
+ /**
+ * Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
+ */
+ public void test44770() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "44770.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ assertTrue("No Exceptions while reading file", true);
+ }
+
+ /**
+ * Bug 41071: Will not extract text from Powerpoint TextBoxes
+ */
+ public void test41071() throws Exception {
+ FileInputStream is = new FileInputStream(new File(cwd, "41071.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Slide slide = ppt.getSlides()[0];
+ Shape[] sh = slide.getShapes();
+ assertEquals(1, sh.length);
+ assertTrue(sh[0] instanceof TextShape);
+ TextShape tx = (TextShape)sh[0];
+ assertEquals("Fundera, planera och involvera.", tx.getTextRun().getText());
+
+ TextRun[] run = slide.getTextRuns();
+ assertEquals(1, run.length);
+ assertEquals("Fundera, planera och involvera.", run[0].getText());
+ }
+
+ /**
+ * PowerPoint 95 files should throw a more helpful exception
+ * @throws Exception
+ */
+ public void test41711() throws Exception {
+ // New file is fine
+ FileInputStream is = new FileInputStream(new File(cwd, "SampleShow.ppt"));
+ SlideShow ppt = new SlideShow(is);
+
+ // PowerPoint 95 gives an old format exception
+ is = new FileInputStream(new File(cwd, "PPT95.ppt"));
+ try {
+ new SlideShow(is);
+ fail("OldPowerPointFormatException should've been thrown");
+ } catch(OldPowerPointFormatException e) {
+ // Good
+ }
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestCounts extends TestCase {
+public final class TestCounts extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
Slide[] slides = ss.getSlides();
// Two sheets - master sheet is seperate
assertEquals(2, slides.length);
-
+
// They are slides 1+2
assertEquals(1, slides[0].getSlideNumber());
assertEquals(2, slides[1].getSlideNumber());
-
+
// The ref IDs are 4 and 6
assertEquals(4, slides[0]._getSheetRefId());
assertEquals(6, slides[1]._getSheetRefId());
-
+
// These are slides 1+2 -> 256+257
assertEquals(256, slides[0]._getSheetNumber());
assertEquals(257, slides[1]._getSheetNumber());
// Note: there are also notes on the slide master
//assertEquals(3, notes.length); // When we do slide masters
assertEquals(2, notes.length);
-
+
// First is for master
//assertEquals(-2147483648, notes[0]._getSheetNumber()); // When we do slide masters
-
+
// Next two are for the two slides
assertEquals(256, notes[0]._getSheetNumber());
assertEquals(257, notes[1]._getSheetNumber());
-
+
// They happen to go between the two slides in Ref terms
assertEquals(5, notes[0]._getSheetRefId());
assertEquals(7, notes[1]._getSheetRefId());
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestMostRecentRecords extends TestCase {
+public final class TestMostRecentRecords extends TestCase {
// HSLFSlideShow primed on the test data
private HSLFSlideShow hss;
// SlideShow primed on the test data
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestNotesText extends TestCase {
+public final class TestNotesText extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
*
* @author Yegor Kozlov
*/
-public class TestPictures extends TestCase{
+public final class TestPictures extends TestCase{
protected File cwd;
Slide slide = ppt.createSlide();
File img = new File(cwd, "sci_cec.dib");
-
+
// Check we can read the test DIB image
assertTrue(img.exists());
-
+
// Add the image
int idx = ppt.addPicture(img, Picture.DIB);
Picture pict = new Picture(idx);
}
/**
- * Test that on a party corrupt powerpoint document, which has
+ * Test that on a party corrupt powerpoint document, which has
* crazy pictures of type 0, we do our best.
*/
public void testZeroPictureType() throws Exception {
PictureData[] pictures = ppt.getPictureData();
assertEquals(12, slides.length);
assertEquals(2, pictures.length);
-
+
Picture pict;
PictureData pdata;
-
+
pict = (Picture)slides[0].getShapes()[1]; // 2nd object on 1st slide
pdata = pict.getPictureData();
assertTrue(pdata instanceof WMF);
assertEquals(Picture.WMF, pdata.getType());
-
+
pict = (Picture)slides[0].getShapes()[2]; // 3rd object on 1st slide
pdata = pict.getPictureData();
assertTrue(pdata instanceof WMF);
assertEquals(Picture.WMF, pdata.getType());
}
-
+
public void testZeroPictureLength() throws Exception {
HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureLengthZero.ppt").getPath());
// Both are real pictures, both WMF
assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
-
+
// Now test what happens when we use the SlideShow interface
SlideShow ppt = new SlideShow(hslf);
Slide[] slides = ppt.getSlides();
PictureData[] pictures = ppt.getPictureData();
assertEquals(27, slides.length);
assertEquals(2, pictures.length);
-
+
Picture pict;
PictureData pdata;
-
+
pict = (Picture)slides[6].getShapes()[13];
pdata = pict.getPictureData();
assertTrue(pdata instanceof WMF);
assertEquals(Picture.WMF, pdata.getType());
-
+
pict = (Picture)slides[7].getShapes()[13];
pdata = pict.getPictureData();
assertTrue(pdata instanceof WMF);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestReOrderingSlides extends TestCase {
+public final class TestReOrderingSlides extends TestCase {
// A SlideShow with one slide
private HSLFSlideShow hss_one;
private SlideShow ss_one;
-
+
// A SlideShow with two slides
private HSLFSlideShow hss_two;
private SlideShow ss_two;
-
+
// A SlideShow with three slides
private HSLFSlideShow hss_three;
private SlideShow ss_three;
-
+
/**
* Create/open the slideshows
*/
public void setUp() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
-
+
String filename = dirname + "/Single_Coloured_Page.ppt";
hss_one = new HSLFSlideShow(filename);
ss_one = new SlideShow(hss_one);
-
+
filename = dirname + "/basic_test_ppt_file.ppt";
hss_two = new HSLFSlideShow(filename);
ss_two = new SlideShow(hss_two);
-
+
filename = dirname + "/incorrect_slide_order.ppt";
hss_three = new HSLFSlideShow(filename);
ss_three = new SlideShow(hss_three);
// Has one slide
assertEquals(1, ss_one.getSlides().length);
Slide s1 = ss_one.getSlides()[0];
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
-
+
// Now move it to one
ss_one.reorderSlide(1, 1);
-
+
// Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_one.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it still has 1 slide
assertEquals(1, ss_read.getSlides().length);
-
+
// And check it's as expected
s1 = ss_read.getSlides()[0];
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
}
-
+
/**
* Test doing a dummy re-order on a slideshow with
* two slides in it
assertEquals(2, ss_two.getSlides().length);
Slide s1 = ss_two.getSlides()[0];
Slide s2 = ss_two.getSlides()[1];
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId()); // master has notes
assertEquals(257, s2._getSheetNumber());
assertEquals(6, s2._getSheetRefId()); // master and 1 have notes
assertEquals(2, s2.getSlideNumber());
-
+
// Don't swap them around
ss_two.reorderSlide(2, 2);
-
+
// Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_two.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it still has 2 slides
assertEquals(2, ss_read.getSlides().length);
-
+
// And check it's as expected
s1 = ss_read.getSlides()[0];
s2 = ss_read.getSlides()[1];
assertEquals(6, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
}
-
+
/**
* Test re-ordering slides in a slideshow with 2 slides on it
*/
assertEquals(2, ss_two.getSlides().length);
Slide s1 = ss_two.getSlides()[0];
Slide s2 = ss_two.getSlides()[1];
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId()); // master has notes
assertEquals(257, s2._getSheetNumber());
assertEquals(6, s2._getSheetRefId()); // master and 1 have notes
assertEquals(2, s2.getSlideNumber());
-
+
// Swap them around
ss_two.reorderSlide(2, 1);
-
+
// Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_two.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it still has 2 slides
assertEquals(2, ss_read.getSlides().length);
-
+
// And check it's as expected
s1 = ss_read.getSlides()[0];
s2 = ss_read.getSlides()[1];
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
}
-
+
/**
* Test doing a dummy re-order on a slideshow with
* three slides in it
Slide s1 = ss_three.getSlides()[0];
Slide s2 = ss_three.getSlides()[1];
Slide s3 = ss_three.getSlides()[2];
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId()); // no notes on master
assertEquals(257, s3._getSheetNumber());
assertEquals(4, s3._getSheetRefId()); // no notes on slide
assertEquals(3, s3.getSlideNumber());
-
+
// Don't swap them around
ss_three.reorderSlide(2, 2);
-
+
// Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_three.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it still has 3 slides
assertEquals(3, ss_read.getSlides().length);
-
+
// And check it's as expected
s1 = ss_read.getSlides()[0];
s2 = ss_read.getSlides()[1];
s3 = ss_read.getSlides()[2];
-
+
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
assertEquals(4, s3._getSheetRefId());
assertEquals(3, s3.getSlideNumber());
}
-
+
/**
* Test re-ordering slides in a slideshow with 3 slides on it
*/
Slide s1 = ss_three.getSlides()[0];
Slide s2 = ss_three.getSlides()[1];
Slide s3 = ss_three.getSlides()[2];
-
+
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId()); // no notes on master
assertEquals(257, s3._getSheetNumber());
assertEquals(4, s3._getSheetRefId()); // no notes on slide
assertEquals(3, s3.getSlideNumber());
-
+
// Put 3 in place of 1
// (1 -> 2, 2 -> 3)
ss_three.reorderSlide(3, 1);
-
+
// Write out, and read back in
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss_three.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
+
HSLFSlideShow hss_read = new HSLFSlideShow(bais);
SlideShow ss_read = new SlideShow(hss_read);
-
+
// Check it still has 3 slides
assertEquals(3, ss_read.getSlides().length);
-
+
// And check it's as expected
Slide _s1 = ss_read.getSlides()[0];
Slide _s2 = ss_read.getSlides()[1];
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
import org.apache.poi.hslf.record.RecordContainer;
/**
- * Tests that the record setup done by SlideShow
+ * Tests that the record setup done by SlideShow
* has worked correctly
* Note: most recent record stuff has its own test
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestRecordSetup extends TestCase {
+public final class TestRecordSetup extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
private HSLFSlideShow hss;
* (model.TestTextRun tests the other functionality)
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestRichTextRun extends TestCase {
+public final class TestRichTextRun extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
private SlideShow ssRichA;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestSheetText extends TestCase {
+public final class TestSheetText extends TestCase {
// SlideShow primed on the test data
private SlideShow ss;
assertEquals(expectText[i], slideTwo.getTextRuns()[i].getText());
}
}
-
+
/**
* Check we can still get the text from a file where the
* TextProps don't have enough data.
String filename = dirname + "/iisd_report.ppt";
HSLFSlideShow hss = new HSLFSlideShow(filename);
SlideShow sss = new SlideShow(hss);
-
+
// Should come out with 10 slides, no notes
assertEquals(10, sss.getSlides().length);
assertEquals(0, sss.getNotes().length);
-
+
// Check text on first slide
Slide s = sss.getSlides()[0];
- String exp =
+ String exp =
"Realizing the Development Dividend:\n" +
"Community Capacity Building and CDM.\n" +
"Can they co-exist?\n\n" +
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.usermodel;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestSlideOrdering extends TestCase {
+public final class TestSlideOrdering extends TestCase {
// Simple slideshow, record order matches slide order
private SlideShow ssA;
// Complex slideshow, record order doesn't match slide order
public TestSlideOrdering() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
-
+
String filenameA = dirname + "/basic_test_ppt_file.ppt";
HSLFSlideShow hssA = new HSLFSlideShow(filenameA);
ssA = new SlideShow(hssA);
-
+
String filenameB = dirname + "/incorrect_slide_order.ppt";
HSLFSlideShow hssB = new HSLFSlideShow(filenameB);
ssB = new SlideShow(hssB);
*/
public void testSimpleCase() throws Exception {
assertEquals(2, ssA.getSlides().length);
-
+
Slide s1 = ssA.getSlides()[0];
Slide s2 = ssA.getSlides()[1];
-
+
String[] firstTRs = new String[] {
"This is a test title",
"This is the title on page 2"
};
-
+
assertEquals(firstTRs[0], s1.getTextRuns()[0].getText());
assertEquals(firstTRs[1], s2.getTextRuns()[0].getText());
}
*/
public void testComplexCase() throws Exception {
assertEquals(3, ssB.getSlides().length);
-
+
Slide s1 = ssB.getSlides()[0];
Slide s2 = ssB.getSlides()[1];
Slide s3 = ssB.getSlides()[2];
-
+
String[] firstTRs = new String[] {
"Slide 1",
"Slide 2",
"Slide 3"
};
-
+
assertEquals(firstTRs[0], s1.getTextRuns()[0].getText());
assertEquals(firstTRs[1], s2.getTextRuns()[0].getText());
assertEquals(firstTRs[2], s3.getTextRuns()[0].getText());
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.hslf.usermodel;\r
-\r
-import org.apache.poi.hslf.*;\r
-import org.apache.poi.hslf.exceptions.HSLFException;\r
-import org.apache.poi.hslf.blip.*;\r
-import org.apache.poi.hslf.model.*;\r
-import junit.framework.TestCase;\r
-\r
-import java.io.*;\r
-import java.util.Arrays;\r
-\r
-/**\r
- * Test reading sound data from a ppt\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TestSoundData extends TestCase{\r
-\r
- protected File cwd;\r
-\r
- public void setUp() throws Exception {\r
- cwd = new File(System.getProperty("HSLF.testdata.path"));\r
- }\r
-\r
- /**\r
- * Read a reference sound file from disk and compare it from the data extracted from the slide show\r
- */ \r
- public void testSounds() throws Exception {\r
- //read the reference sound file\r
- File f = new File(cwd, "ringin.wav");\r
- int length = (int)f.length();\r
- byte[] ref_data = new byte[length];\r
- FileInputStream is = new FileInputStream(f);\r
- is.read(ref_data);\r
- is.close();\r
-\r
- is = new FileInputStream(new File(cwd, "sound.ppt"));\r
- SlideShow ppt = new SlideShow(is);\r
- is.close();\r
-\r
- SoundData[] sound = ppt.getSoundData();\r
- assertEquals("Expected 1 sound", 1, sound.length);\r
-\r
- assertTrue(Arrays.equals(ref_data, sound[0].getData()));\r
- }\r
-}\r
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.usermodel;
+
+import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.blip.*;
+import org.apache.poi.hslf.model.*;
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.util.Arrays;
+
+/**
+ * Test reading sound data from a ppt
+ *
+ * @author Yegor Kozlov
+ */
+public final class TestSoundData extends TestCase{
+
+ protected File cwd;
+
+ public void setUp() throws Exception {
+ cwd = new File(System.getProperty("HSLF.testdata.path"));
+ }
+
+ /**
+ * Read a reference sound file from disk and compare it from the data extracted from the slide show
+ */
+ public void testSounds() throws Exception {
+ //read the reference sound file
+ File f = new File(cwd, "ringin.wav");
+ int length = (int)f.length();
+ byte[] ref_data = new byte[length];
+ FileInputStream is = new FileInputStream(f);
+ is.read(ref_data);
+ is.close();
+
+ is = new FileInputStream(new File(cwd, "sound.ppt"));
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ SoundData[] sound = ppt.getSoundData();
+ assertEquals("Expected 1 sound", 1, sound.length);
+
+ assertTrue(Arrays.equals(ref_data, sound[0].getData()));
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
package org.apache.poi.hslf.util;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestSystemTimeUtils extends TestCase {
+public final class TestSystemTimeUtils extends TestCase {
// From real files
- private byte[] data_a = new byte[] {
+ private byte[] data_a = new byte[] {
0xD6-256, 07, 01, 00,
- 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
+ 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
0x0F, 00, 0xCD-256, 00
};
private byte[] data_b = new byte[] {
00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
- 01, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
+ 01, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
02, 00, 0x18, 00, 0x15, 00, 0x19, 00, 03,
- 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
+ 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
0x0A, 00, 00, 00
};
-
+
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
public void testGetDateA() throws Exception {
Date date = SystemTimeUtils.getDate(data_a);
-
+
// Is 2006-01-24 (2nd day of week) 10:26:15.205
Date exp = sdf.parse("2006-01-24 10:26:15.205");
assertEquals(exp.getTime(), date.getTime());
public void testGetDateB() throws Exception {
Date date = SystemTimeUtils.getDate(data_b, 8+4);
-
+
// Is 2006-01-24 (2nd day of week) 21:25:03.725
Date exp = sdf.parse("2006-01-24 21:25:03.725");
assertEquals(exp.getTime(), date.getTime());
assertEquals(exp, date);
}
-
+
public void testWriteDateA() throws Exception {
byte[] out_a = new byte[data_a.length];
Date date = sdf.parse("2006-01-24 10:26:15.205");
SystemTimeUtils.storeDate(date, out_a);
-
+
for(int i=0; i<out_a.length; i++) {
assertEquals(data_a[i], out_a[i]);
}
}
-
+
public void testWriteDateB() throws Exception {
byte[] out_b = new byte[data_b.length];
// Copy over start and end, ignoring the 16 byte date field in the middle
System.arraycopy(data_b, 0, out_b, 0, 12);
System.arraycopy(data_b, 12+16, out_b, 12+16, data_b.length-12-16);
-
+
Date date = sdf.parse("2006-01-24 21:25:03.725");
SystemTimeUtils.storeDate(date, out_b, 12);
-
+
for(int i=0; i<out_b.length; i++) {
assertEquals(data_b[i], out_b[i]);
}
/**
* Verifies that the Chunks class is actually setup properly and hasn't been changed in ways
* that will break the library.
- *
+ *
* @author Travis Ferguson
*
*/
-public class TestChunkData extends TestCase {
+public final class TestChunkData extends TestCase {
private Chunks chunks = Chunks.getInstance(false);
-
+
public void testChunkCreate() {
StringChunk chunk = new StringChunk(0x0200, false);
TestCase.assertEquals("__substg1.0_0200001E", chunk.getEntryName());
-
+
/* test the lower and upper limits of the chunk ids */
chunk = new StringChunk(0x0000, false);
TestCase.assertEquals("__substg1.0_0000001E", chunk.getEntryName());
-
+
chunk = new StringChunk(0xFFFF, false);
TestCase.assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
-
+
chunk = new StringChunk(0xFFFF, true);
TestCase.assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
}
-
+
public void testTextBodyChunk() {
StringChunk chunk = new StringChunk(0x1000, false);
TestCase.assertEquals(chunk.getEntryName(), chunks.textBodyChunk.getEntryName());
StringChunk chunk = new StringChunk(0x0E04, false);
TestCase.assertEquals(chunk.getEntryName(), chunks.displayToChunk.getEntryName());
}
-
+
public void testDisplayCCChunk() {
StringChunk chunk = new StringChunk(0x0E03, false);
StringChunk chunk = new StringChunk(0x0E02, false);
TestCase.assertEquals(chunk.getEntryName(), chunks.displayBCCChunk.getEntryName());
}
-
+
public void testSubjectChunk() {
Chunk chunk = new StringChunk(0x0037, false);
TestCase.assertEquals(chunk.getEntryName(), chunks.subjectChunk.getEntryName());
}
-
+
}
/**
* Tests to verify that we can still work on the newer Outlook 3.0 files.
*/
-public class TestOutlook30FileRead extends TestCase {
+public final class TestOutlook30FileRead extends TestCase {
private MAPIMessage mapiMessage;
-
+
/**
* Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
+ * @throws Exception
*/
public TestOutlook30FileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path");
this.mapiMessage = new MAPIMessage(dirname + "/outlook_30_msg.msg");
}
-
+
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
-
+
TestCase.assertEquals(obtained, expected);
}
-
+
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayTo() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayTo();
-
+
assertTrue(obtained.startsWith("Bohn, Shawn"));
}
-
+
/**
* Test to see if we can read the From Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayFrom() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayFrom();
String expected = "Cramer, Nick";
-
+
TestCase.assertEquals(obtained, expected);
}
-
+
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayBCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
-
+
TestCase.assertEquals(obtained, expected);
}
-
-
- /**
+
+
+ /**
* Check if we can read the body of the blank message, we expect "".
- *
+ *
* @throws Exception
*/
public void testReadBody() throws Exception {
String obtained = mapiMessage.getTextBody();
assertTrue(obtained.startsWith("I am shutting down"));
}
-
+
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
+ *
* @throws Exception
*/
public void testReadSubject() throws Exception {
String obtained = mapiMessage.getSubject();
String expected = "IN-SPIRE servers going down for a bit, back up around 8am";
-
+
TestCase.assertEquals(expected, obtained);
}
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
+ *
* @throws Exception
*/
public void testReadConversationTopic() throws Exception {
String obtained = mapiMessage.getConversationTopic();
TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained);
}
-
+
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
+ *
* @throws Exception
*/
public void testReadMessageClass() throws Exception {
String obtained = mapiMessage.getMessageClass();
TestCase.assertEquals("IPM.Note", obtained);
}
-
-
-
+
+
+
}
/**
* Tests to verify that we can read a simple msg file, that is in plain/text format with no attachments
* or extra recipents.
- *
+ *
* @author Travis Ferguson
*/
-public class TestSimpleFileRead extends TestCase {
+public final class TestSimpleFileRead extends TestCase {
private MAPIMessage mapiMessage;
-
+
/**
* Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
+ * @throws Exception
*/
public TestSimpleFileRead() throws IOException {
String dirname = System.getProperty("HSMF.testdata.path");
this.mapiMessage = new MAPIMessage(dirname + "/simple_test_msg.msg");
}
-
+
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
-
+
TestCase.assertEquals(obtained, expected);
}
-
+
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayTo() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayTo();
String expected = "travis@overwrittenstack.com";
-
+
TestCase.assertEquals(obtained, expected);
}
-
+
/**
* Test to see if we can read the From Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayFrom() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayFrom();
String expected = "Travis Ferguson";
-
+
TestCase.assertEquals(obtained, expected);
}
-
+
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
+ * @throws ChunkNotFoundException
+ *
*/
public void testReadDisplayBCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
-
+
TestCase.assertEquals(obtained, expected);
}
-
-
- /**
+
+
+ /**
* Check if we can read the body of the blank message, we expect "".
- *
+ *
* @throws Exception
*/
public void testReadBody() throws Exception {
String obtained = mapiMessage.getTextBody();
String expected = "This is a test message.";
-
+
TestCase.assertEquals(obtained, expected);
}
-
+
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
+ *
* @throws Exception
*/
public void testReadSubject() throws Exception {
String obtained = mapiMessage.getSubject();
String expected = "test message";
-
+
TestCase.assertEquals(expected, obtained);
}
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
+ *
* @throws Exception
*/
public void testReadConversationTopic() throws Exception {
String obtained = mapiMessage.getConversationTopic();
TestCase.assertEquals("test message", obtained);
}
-
+
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
+ *
* @throws Exception
*/
public void testReadMessageClass() throws Exception {
String obtained = mapiMessage.getMessageClass();
TestCase.assertEquals("IPM.Note", obtained);
}
-
-
-
+
+
+
}
public void testSingleChart() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls");
-
+
HSSFSheet s1 = wb.getSheetAt(0);
HSSFSheet s2 = wb.getSheetAt(1);
HSSFSheet s3 = wb.getSheetAt(2);
-
+
assertEquals(0, HSSFChart.getSheetCharts(s1).length);
assertEquals(1, HSSFChart.getSheetCharts(s2).length);
assertEquals(0, HSSFChart.getSheetCharts(s3).length);
-
+
HSSFChart[] charts;
-
+
// Check the chart on the 2nd sheet
charts = HSSFChart.getSheetCharts(s2);
assertEquals(1, charts.length);
-
+
assertEquals(2, charts[0].getSeries().length);
assertEquals("1st Column", charts[0].getSeries()[0].getSeriesTitle());
assertEquals("2nd Column", charts[0].getSeries()[1].getSeriesTitle());
assertEquals(null, charts[0].getChartTitle());
-
+
// Check x, y, width, height
assertEquals(0, charts[0].getChartX());
assertEquals(0, charts[0].getChartY());
public void testTwoCharts() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls");
-
+
HSSFSheet s1 = wb.getSheetAt(0);
HSSFSheet s2 = wb.getSheetAt(1);
HSSFSheet s3 = wb.getSheetAt(2);
-
+
assertEquals(0, HSSFChart.getSheetCharts(s1).length);
assertEquals(1, HSSFChart.getSheetCharts(s2).length);
assertEquals(1, HSSFChart.getSheetCharts(s3).length);
-
+
HSSFChart[] charts;
-
+
// Check the chart on the 2nd sheet
charts = HSSFChart.getSheetCharts(s2);
assertEquals(1, charts.length);
-
+
assertEquals(2, charts[0].getSeries().length);
assertEquals("1st Column", charts[0].getSeries()[0].getSeriesTitle());
assertEquals("2nd Column", charts[0].getSeries()[1].getSeriesTitle());
assertEquals(null, charts[0].getChartTitle());
-
+
// And the third sheet
charts = HSSFChart.getSheetCharts(s3);
assertEquals(1, charts.length);
-
+
assertEquals(2, charts[0].getSeries().length);
assertEquals("Squares", charts[0].getSeries()[0].getSeriesTitle());
assertEquals("Base Numbers", charts[0].getSeries()[1].getSeriesTitle());
assertEquals(null, charts[0].getChartTitle());
}
-
+
public void testThreeCharts() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xls");
-
+
HSSFSheet s1 = wb.getSheetAt(0);
HSSFSheet s2 = wb.getSheetAt(1);
HSSFSheet s3 = wb.getSheetAt(2);
-
+
assertEquals(0, HSSFChart.getSheetCharts(s1).length);
assertEquals(2, HSSFChart.getSheetCharts(s2).length);
assertEquals(1, HSSFChart.getSheetCharts(s3).length);
-
+
HSSFChart[] charts;
-
+
// Check the charts on the 2nd sheet
charts = HSSFChart.getSheetCharts(s2);
assertEquals(2, charts.length);
-
+
assertEquals(2, charts[0].getSeries().length);
assertEquals("1st Column", charts[0].getSeries()[0].getSeriesTitle());
assertEquals("2nd Column", charts[0].getSeries()[1].getSeriesTitle());
assertEquals(SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC, charts[0].getSeries()[0].getValueType());
assertEquals(SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC, charts[0].getSeries()[1].getValueType());
assertEquals(null, charts[0].getChartTitle());
-
+
assertEquals(1, charts[1].getSeries().length);
assertEquals(null, charts[1].getSeries()[0].getSeriesTitle());
assertEquals("Pie Chart Title Thingy", charts[1].getChartTitle());
-
+
// And the third sheet
charts = HSSFChart.getSheetCharts(s3);
assertEquals(1, charts.length);
-
+
assertEquals(2, charts[0].getSeries().length);
assertEquals("Squares", charts[0].getSeries()[0].getSeriesTitle());
assertEquals("Base Numbers", charts[0].getSeries()[1].getSeriesTitle());
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf;
import junit.framework.*;
-public class AllTests
+public final class AllTests
extends TestCase
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import java.io.FileInputStream;
import java.io.File;
-public class HWPFDocFixture
+public final class HWPFDocFixture
{
public byte[] _tableStream;
public byte[] _mainStream;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import java.io.ByteArrayInputStream;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import java.io.ByteArrayOutputStream;
* Test picture support in HWPF
* @author nick
*/
-public class TestHWPFPictures extends TestCase {
+public final class TestHWPFPictures extends TestCase {
private String docAFile;
private String docBFile;
private String docCFile;
private String docDFile;
-
+
private String imgAFile;
private String imgBFile;
private String imgCFile;
private String imgDFile;
-
+
protected void setUp() throws Exception {
String dirname = System.getProperty("HWPF.testdata.path");
-
+
docAFile = dirname + "/testPictures.doc";
docBFile = dirname + "/two_images.doc";
docCFile = dirname + "/vector_image.doc";
docDFile = dirname + "/GaiaTest.doc";
-
+
imgAFile = dirname + "/simple_image.jpg";
imgBFile = dirname + "/simple_image.png";
imgCFile = dirname + "/vector_image.emf";
imgDFile = dirname + "/GaiaTestImg.png";
}
-
+
/**
* Test just opening the files
*/
HWPFDocument docA = new HWPFDocument(new FileInputStream(docAFile));
HWPFDocument docB = new HWPFDocument(new FileInputStream(docBFile));
}
-
+
/**
* Test that we have the right numbers of images in each file
*/
public void testImageCount() throws Exception {
HWPFDocument docA = new HWPFDocument(new FileInputStream(docAFile));
HWPFDocument docB = new HWPFDocument(new FileInputStream(docBFile));
-
+
assertNotNull(docA.getPicturesTable());
assertNotNull(docB.getPicturesTable());
-
+
PicturesTable picA = docA.getPicturesTable();
PicturesTable picB = docB.getPicturesTable();
-
+
List picturesA = picA.getAllPictures();
List picturesB = picB.getAllPictures();
-
+
assertEquals(7, picturesA.size());
assertEquals(2, picturesB.size());
}
-
+
/**
* Test that we have the right images in at least one file
*/
HWPFDocument docB = new HWPFDocument(new FileInputStream(docBFile));
PicturesTable picB = docB.getPicturesTable();
List picturesB = picB.getAllPictures();
-
+
assertEquals(2, picturesB.size());
-
+
Picture pic1 = (Picture)picturesB.get(0);
Picture pic2 = (Picture)picturesB.get(1);
-
+
assertNotNull(pic1);
assertNotNull(pic2);
-
+
// Check the same
byte[] pic1B = readFile(imgAFile);
byte[] pic2B = readFile(imgBFile);
-
+
assertEquals(pic1B.length, pic1.getContent().length);
assertEquals(pic2B.length, pic2.getContent().length);
assertBytesSame(pic1B, pic1.getContent());
assertBytesSame(pic2B, pic2.getContent());
}
-
+
/**
* Test that compressed image data is correctly returned.
*/
HWPFDocument docC = new HWPFDocument(new FileInputStream(docCFile));
PicturesTable picC = docC.getPicturesTable();
List picturesC = picC.getAllPictures();
-
+
assertEquals(1, picturesC.size());
-
+
Picture pic = (Picture)picturesC.get(0);
assertNotNull(pic);
-
+
// Check the same
byte[] picBytes = readFile(imgCFile);
-
+
assertEquals(picBytes.length, pic.getContent().length);
assertBytesSame(picBytes, pic.getContent());
}
-
+
/**
* Pending the missing files being uploaded to
* bug #44937
{
HWPFDocument docD = new HWPFDocument(new FileInputStream(docDFile));
List allPictures = docD.getPicturesTable().getAllPictures();
-
+
assertEquals(1, allPictures.size());
-
+
Picture pic = (Picture) allPictures.get(0);
assertNotNull(pic);
byte[] picD = readFile(imgDFile);
-
+
assertEquals(picD.length, pic.getContent().length);
-
+
assertBytesSame(picD, pic.getContent());
}
-
+
private void assertBytesSame(byte[] a, byte[] b) {
assertEquals(a.length, b.length);
for(int i=0; i<a.length; i++) {
assertEquals(a[i],b[i]);
}
}
-
+
private byte[] readFile(String file) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
-
+
int read = 0;
while(read > -1) {
read = fis.read(buffer);
baos.write(buffer,0,read);
}
}
-
+
return baos.toByteArray();
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import java.io.FileInputStream;
* Test that we pull out the right bits of a file into
* the different ranges
*/
-public class TestHWPFRangeParts extends TestCase {
+public final class TestHWPFRangeParts extends TestCase {
private static final char page_break = (char)12;
- private static final String headerDef =
+ private static final String headerDef =
"\u0003\r\r" +
"\u0004\r\r" +
"\u0003\r\r" +
private static final String footerDef = "\r";
private static final String endHeaderFooter = "\r\r";
-
+
private static final String a_page_1 =
"This is a sample word document. It has two pages. It has a three column heading, and a three column footer\r" +
"\r" +
- "HEADING TEXT\r" +
+ "HEADING TEXT\r" +
"\r" +
"More on page one\r" +
"\r\r" +
private static final String a_page_2 =
"This is page two. It also has a three column heading, and a three column footer.\r"
;
-
+
private static final String a_header =
"First header column!\tMid header Right header!\r"
;
private static final String a_footer =
"Footer Left\tFooter Middle Footer Right\r"
;
-
-
+
+
private static final String u_page_1 =
"This is a fairly simple word document, over two pages, with headers and footers.\r" +
"The trick with this one is that it contains some Unicode based strings in it.\r" +
private static final String u_page_2 =
"This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
;
-
+
private static final String u_header =
"\r\r" +
"This is a simple header, with a \u20ac euro symbol in it.\r"
"The footer, with Moli\u00e8re, has Unicode in it.\r" +
"\r\r\r\r"
;
-
+
/**
* A document made up only of basic ASCII text
*/
* A document with some unicode in it too
*/
private HWPFDocument docUnicode;
-
+
public void setUp() throws Exception {
String dirname = System.getProperty("HWPF.testdata.path");
-
+
String filename = dirname + "/HeaderFooterUnicode.doc";
docUnicode = new HWPFDocument(
new FileInputStream(filename)
);
-
+
filename = dirname + "/ThreeColHeadFoot.doc";
docAscii = new HWPFDocument(
new FileInputStream(filename)
);
}
-
+
public void testBasics() throws Exception {
// First check the start and end bits
assertEquals(
a_page_2.length(),
docAscii._cpSplit.getMainDocumentEnd()
);
-
+
assertEquals(
238,
docAscii._cpSplit.getFootnoteStart()
238,
docAscii._cpSplit.getFootnoteEnd()
);
-
+
assertEquals(
238,
docAscii._cpSplit.getHeaderStoryStart()
docAscii._cpSplit.getHeaderStoryEnd()
);
}
-
+
public void testContents() throws Exception {
Range r;
-
+
// Now check the real ranges
r = docAscii.getRange();
assertEquals(
a_page_2,
r.text()
);
-
+
r = docAscii.getHeaderStoryRange();
assertEquals(
headerDef +
a_header +
footerDef +
- a_footer +
+ a_footer +
endHeaderFooter,
r.text()
);
-
+
r = docAscii.getOverallRange();
assertEquals(
a_page_1 +
page_break + "\r" +
- a_page_2 +
+ a_page_2 +
headerDef +
a_header +
footerDef +
- a_footer +
+ a_footer +
endHeaderFooter +
"\r",
r.text()
);
}
-
+
public void testBasicsUnicode() throws Exception {
// First check the start and end bits
assertEquals(
u_page_2.length(),
docUnicode._cpSplit.getMainDocumentEnd()
);
-
+
assertEquals(
408,
docUnicode._cpSplit.getFootnoteStart()
408,
docUnicode._cpSplit.getFootnoteEnd()
);
-
+
assertEquals(
408,
docUnicode._cpSplit.getHeaderStoryStart()
docUnicode._cpSplit.getHeaderStoryEnd()
);
}
-
+
public void testContentsUnicode() throws Exception {
Range r;
-
+
// Now check the real ranges
r = docUnicode.getRange();
assertEquals(
u_page_2,
r.text()
);
-
+
r = docUnicode.getHeaderStoryRange();
assertEquals(
headerDef +
u_header +
footerDef +
- u_footer +
+ u_footer +
endHeaderFooter,
r.text()
);
-
+
r = docUnicode.getOverallRange();
assertEquals(
u_page_1 +
page_break + "\r" +
- u_page_2 +
+ u_page_2 +
headerDef +
u_header +
footerDef +
- u_footer +
+ u_footer +
endHeaderFooter +
"\r",
r.text()
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.extractor;
import java.io.FileInputStream;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestDifferentRoutes extends TestCase {
+public final class TestDifferentRoutes extends TestCase {
private String[] p_text = new String[] {
"This is a simple word document\r",
"\r",
"\r",
"It is otherwise very very boring.\r"
};
-
+
private HWPFDocument doc;
-
+
protected void setUp() throws Exception {
String dirname = System.getProperty("HWPF.testdata.path");
-
+
String filename = dirname + "/test2.doc";
doc = new HWPFDocument(new FileInputStream(filename));
- }
-
+ }
+
/**
* Test model based extraction
*/
public void testExtractFromModel() {
Range r = doc.getRange();
-
+
String[] text = new String[r.numParagraphs()];
for(int i=0; i < r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
text[i] = p.text();
}
-
+
assertEquals(p_text.length, text.length);
for(int i=0; i<p_text.length; i++) {
assertEquals(p_text[i], text[i]);
}
}
-
+
/**
* Test textPieces based extraction
*/
public void testExtractFromTextPieces() throws Exception {
StringBuffer textBuf = new StringBuffer();
-
+
Iterator textPieces = doc.getTextTable().getTextPieces().iterator();
while (textPieces.hasNext()) {
TextPiece piece = (TextPiece) textPieces.next();
String text = new String(piece.getRawBytes(), encoding);
textBuf.append(text);
}
-
+
StringBuffer exp = new StringBuffer();
for(int i=0; i<p_text.length; i++) {
exp.append(p_text[i]);
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.extractor;
import java.io.FileInputStream;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestWordExtractor extends TestCase {
+public final class TestWordExtractor extends TestCase {
private String[] p_text1 = new String[] {
"This is a simple word document\r\n",
"\r\n",
"It is otherwise very very boring.\r\n"
};
private String p_text1_block = new String();
-
+
// Well behaved document
private WordExtractor extractor;
// Corrupted document - can't do paragraph based stuff
private WordExtractor extractor2;
// A word doc embeded in an excel file
private String filename3;
-
+
// With header and footer
private String filename4;
// With unicode header and footer
private String filename5;
-
+
protected void setUp() throws Exception {
String dirname = System.getProperty("HWPF.testdata.path");
String pdirname = System.getProperty("POIFS.testdata.path");
-
+
String filename = dirname + "/test2.doc";
String filename2 = dirname + "/test.doc";
filename3 = pdirname + "/excel_with_embeded.xls";
filename4 = dirname + "/ThreeColHeadFoot.doc";
filename5 = dirname + "/HeaderFooterUnicode.doc";
-
+
extractor = new WordExtractor(new FileInputStream(filename));
extractor2 = new WordExtractor(new FileInputStream(filename2));
-
+
// Build splat'd out text version
for(int i=0; i<p_text1.length; i++) {
p_text1_block += p_text1[i];
}
- }
-
+ }
+
/**
* Test paragraph based extraction
*/
public void testExtractFromParagraphs() {
String[] text = extractor.getParagraphText();
-
+
assertEquals(p_text1.length, text.length);
for(int i=0; i<p_text1.length; i++) {
assertEquals(p_text1[i], text[i]);
}
-
+
// On second one, should fall back
assertEquals(1, extractor2.getParagraphText().length);
}
-
+
/**
* Test the paragraph -> flat extraction
*/
public void testGetText() {
assertEquals(p_text1_block, extractor.getText());
-
+
// On second one, should fall back to text piece
assertEquals(extractor2.getTextFromPieces(), extractor2.getText());
}
-
+
/**
* Test textPieces based extraction
*/
String text = extractor.getTextFromPieces();
assertEquals(p_text1_block, text);
}
-
-
+
+
/**
* Test that we can get data from two different
* embeded word documents
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3));
HWPFDocument doc;
WordExtractor extractor3;
-
+
DirectoryNode dirA = (DirectoryNode)
fs.getRoot().getEntry("MBD0000A3B7");
DirectoryNode dirB = (DirectoryNode)
fs.getRoot().getEntry("MBD0000A3B2");
-
+
// Should have WordDocument and 1Table
assertNotNull(dirA.getEntry("1Table"));
assertNotNull(dirA.getEntry("WordDocument"));
-
+
assertNotNull(dirB.getEntry("1Table"));
assertNotNull(dirB.getEntry("WordDocument"));
-
+
// Check each in turn
doc = new HWPFDocument(dirA, fs);
extractor3 = new WordExtractor(doc);
-
+
assertNotNull(extractor3.getText());
assertTrue(extractor3.getText().length() > 20);
assertEquals("I am a sample document\r\nNot much on me\r\nI am document 1\r\n",
assertEquals("Sample Doc 1", extractor3.getSummaryInformation().getTitle());
assertEquals("Sample Test", extractor3.getSummaryInformation().getSubject());
-
+
doc = new HWPFDocument(dirB, fs);
extractor3 = new WordExtractor(doc);
-
+
assertNotNull(extractor3.getText());
assertTrue(extractor3.getText().length() > 20);
- assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n",
+ assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n",
extractor3.getText());
assertEquals("Sample Doc 2", extractor3.getSummaryInformation().getTitle());
assertEquals("Another Sample Test", extractor3.getSummaryInformation().getSubject());
}
-
+
public void testWithHeader() throws Exception {
// Non-unicode
HWPFDocument doc = new HWPFDocument(
new FileInputStream(filename4)
);
extractor = new WordExtractor(doc);
-
+
assertEquals(
"First header column!\tMid header Right header!\n",
extractor.getHeaderText()
);
-
+
String text = extractor.getText();
assertTrue(
text.indexOf("First header column!") > -1
);
-
-
+
+
// Unicode
doc = new HWPFDocument(
new FileInputStream(filename5)
);
extractor = new WordExtractor(doc);
-
+
assertEquals(
"This is a simple header, with a \u20ac euro symbol in it.\n\n",
extractor.getHeaderText()
text.indexOf("This is a simple header") > -1
);
}
-
+
public void testWithFooter() throws Exception {
// Non-unicode
HWPFDocument doc = new HWPFDocument(
new FileInputStream(filename4)
);
extractor = new WordExtractor(doc);
-
+
assertEquals(
"Footer Left\tFooter Middle Footer Right\n",
extractor.getFooterText()
);
-
+
String text = extractor.getText();
assertTrue(
text.indexOf("Footer Left") > -1
);
-
-
+
+
// Unicode
doc = new HWPFDocument(
new FileInputStream(filename5)
);
extractor = new WordExtractor(doc);
-
+
assertEquals(
"The footer, with Moli\u00e8re, has Unicode in it.\n",
extractor.getFooterText()
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.extractor;
import java.io.FileInputStream;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestWordExtractorBugs extends TestCase {
+public final class TestWordExtractorBugs extends TestCase {
private String dirname;
protected void setUp() throws Exception {
dirname = System.getProperty("HWPF.testdata.path");
}
-
+
public void testProblemMetadata() throws Exception {
String filename = dirname + "/ProblemExtracting.doc";
- WordExtractor extractor =
+ WordExtractor extractor =
new WordExtractor(new FileInputStream(filename));
-
+
// Check it gives text without error
extractor.getText();
extractor.getParagraphText();
extractor.getTextFromPieces();
- }
-
+ }
+
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
-public class TestCHPBinTable
+public final class TestCHPBinTable
extends TestCase
{
private CHPBinTable _cHPBinTable = null;
private HWPFDocFixture _hWPFDocFixture;
-
+
private TextPieceTable fakeTPT = new TextPieceTable();
public TestCHPBinTable(String name)
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import junit.framework.*;
import java.lang.reflect.*;
import java.util.Arrays;
-public class TestDocumentProperties
+public final class TestDocumentProperties
extends TestCase
{
private DocumentProperties _documentProperties = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import junit.framework.*;
import java.lang.reflect.*;
-public class TestFileInformationBlock
+public final class TestFileInformationBlock
extends TestCase
{
private FileInformationBlock _fileInformationBlock = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
-public class TestFontTable
+public final class TestFontTable
extends TestCase
{
private FontTable _fontTable = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
-public class TestListTables
+public final class TestListTables
extends HWPFTestCase
{
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.io.*;
import java.util.*;
-public class TestPAPBinTable
+public final class TestPAPBinTable
extends TestCase
{
private PAPBinTable _pAPBinTable = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
-public class TestPlexOfCps
+public final class TestPlexOfCps
extends TestCase
{
private PlexOfCps _plexOfCps = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import java.io.*;
*
* @author Daniel Noll
*/
-public class TestSavedByTable
+public final class TestSavedByTable
extends TestCase
{
/** Data dir */
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
-public class TestSectionTable
+public final class TestSectionTable
extends TestCase
{
private HWPFDocFixture _hWPFDocFixture;
int fcMin = fib.getFcMin();
CPSplitCalculator cps = new CPSplitCalculator(fib);
-
+
ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.getFcClx(), fcMin);
TextPieceTable tpt = cft.getTextPieceTable();
byte[] newMainStream = mainOut.toByteArray();
SectionTable newSectionTable = new SectionTable(
- newMainStream, newTableStream, 0,
+ newMainStream, newTableStream, 0,
newTableStream.length, 0, tpt, cps);
ArrayList oldSections = sectionTable.getSections();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
-public class TestStyleSheet
+public final class TestStyleSheet
extends TestCase
{
private StyleSheet _styleSheet = null;
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf.model;
import java.io.ByteArrayInputStream;
import org.apache.poi.hwpf.model.io.HWPFFileSystem;
-public class TestTextPieceTable extends TestCase {
+public final class TestTextPieceTable extends TestCase {
private HWPFDocFixture _hWPFDocFixture;
private String dirname;
new FileInputStream(new File(dirname, "ThreeColHeadFoot.doc"))
);
TextPieceTable tbl = doc.getTextTable();
-
+
// All ascii, so stored in one big lump
assertEquals(1, tbl.getTextPieces().size());
TextPiece tp = (TextPiece)tbl.getTextPieces().get(0);
-
+
assertEquals(0, tp.getStart());
assertEquals(339, tp.getEnd());
assertEquals(339, tp.characterLength());
assertEquals(339, tp.bytesLength());
assertTrue(tp.getStringBuffer().toString().startsWith("This is a sample word document"));
-
+
// Save and re-load
HWPFDocument docB = saveAndReload(doc);
tbl = docB.getTextTable();
-
+
assertEquals(1, tbl.getTextPieces().size());
tp = (TextPiece)tbl.getTextPieces().get(0);
-
+
assertEquals(0, tp.getStart());
assertEquals(339, tp.getEnd());
assertEquals(339, tp.characterLength());
new FileInputStream(new File(dirname, "HeaderFooterUnicode.doc"))
);
TextPieceTable tbl = doc.getTextTable();
-
+
// In three bits, split every 512 bytes
assertEquals(3, tbl.getTextPieces().size());
TextPiece tpA = (TextPiece)tbl.getTextPieces().get(0);
TextPiece tpB = (TextPiece)tbl.getTextPieces().get(1);
TextPiece tpC = (TextPiece)tbl.getTextPieces().get(2);
-
+
assertTrue(tpA.isUnicode());
assertTrue(tpB.isUnicode());
assertTrue(tpC.isUnicode());
-
+
assertEquals(256, tpA.characterLength());
assertEquals(256, tpB.characterLength());
assertEquals(19, tpC.characterLength());
-
+
assertEquals(512, tpA.bytesLength());
assertEquals(512, tpB.bytesLength());
assertEquals(38, tpC.bytesLength());
-
+
assertEquals(0, tpA.getStart());
assertEquals(256, tpA.getEnd());
assertEquals(256, tpB.getStart());
assertEquals(512, tpB.getEnd());
assertEquals(512, tpC.getStart());
assertEquals(531, tpC.getEnd());
-
-
+
+
// Save and re-load
HWPFDocument docB = saveAndReload(doc);
tbl = docB.getTextTable();
-
+
assertEquals(3, tbl.getTextPieces().size());
tpA = (TextPiece)tbl.getTextPieces().get(0);
tpB = (TextPiece)tbl.getTextPieces().get(1);
tpC = (TextPiece)tbl.getTextPieces().get(2);
-
+
assertTrue(tpA.isUnicode());
assertTrue(tpB.isUnicode());
assertTrue(tpC.isUnicode());
-
+
assertEquals(256, tpA.characterLength());
assertEquals(256, tpB.characterLength());
assertEquals(19, tpC.characterLength());
-
+
assertEquals(512, tpA.bytesLength());
assertEquals(512, tpB.bytesLength());
assertEquals(38, tpC.bytesLength());
-
+
assertEquals(0, tpA.getStart());
assertEquals(256, tpA.getEnd());
assertEquals(256, tpB.getStart());
protected HWPFDocument saveAndReload(HWPFDocument doc) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.write(baos);
-
+
return new HWPFDocument(
new ByteArrayInputStream(baos.toByteArray())
);
}
-
+
protected void setUp()
throws Exception
{
_hWPFDocFixture = new HWPFDocFixture(this);
_hWPFDocFixture.setUp();
-
+
dirname = System.getProperty("HWPF.testdata.path");
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import java.io.File;
* Tests for the handling of header stories into
* headers, footers etc
*/
-public class TestHeaderStories extends TestCase {
+public final class TestHeaderStories extends TestCase {
private HWPFDocument none;
- private HWPFDocument header;
- private HWPFDocument footer;
- private HWPFDocument headerFooter;
- private HWPFDocument oddEven;
- private HWPFDocument diffFirst;
+ private HWPFDocument header;
+ private HWPFDocument footer;
+ private HWPFDocument headerFooter;
+ private HWPFDocument oddEven;
+ private HWPFDocument diffFirst;
private HWPFDocument unicode;
private HWPFDocument withFields;
-
+
protected void setUp() throws Exception {
String dirname = System.getProperty("HWPF.testdata.path");
-
+
none = new HWPFDocument(
new FileInputStream(new File(dirname, "NoHeadFoot.doc"))
);
new FileInputStream(new File(dirname, "HeaderWithMacros.doc"))
);
}
-
+
public void testNone() throws Exception {
HeaderStories hs = new HeaderStories(none);
-
+
assertNull(hs.getPlcfHdd());
assertEquals(0, hs.getRange().text().length());
}
-
+
public void testHeader() throws Exception {
HeaderStories hs = new HeaderStories(header);
-
+
assertEquals(60, hs.getRange().text().length());
-
+
// Should have the usual 6 separaters
// Then all 6 of the different header/footer kinds
// Finally a terminater
assertEquals(13, hs.getPlcfHdd().length());
-
+
assertEquals(215, hs.getRange().getStartOffset());
-
+
assertEquals(0, hs.getPlcfHdd().getProperty(0).getStart());
assertEquals(3, hs.getPlcfHdd().getProperty(1).getStart());
assertEquals(6, hs.getPlcfHdd().getProperty(2).getStart());
assertEquals(6, hs.getPlcfHdd().getProperty(3).getStart());
assertEquals(9, hs.getPlcfHdd().getProperty(4).getStart());
assertEquals(12, hs.getPlcfHdd().getProperty(5).getStart());
-
+
assertEquals(12, hs.getPlcfHdd().getProperty(6).getStart());
assertEquals(12, hs.getPlcfHdd().getProperty(7).getStart());
assertEquals(59, hs.getPlcfHdd().getProperty(8).getStart());
assertEquals(59, hs.getPlcfHdd().getProperty(9).getStart());
assertEquals(59, hs.getPlcfHdd().getProperty(10).getStart());
assertEquals(59, hs.getPlcfHdd().getProperty(11).getStart());
-
+
assertEquals(59, hs.getPlcfHdd().getProperty(12).getStart());
-
+
assertEquals("\u0003\r\r", hs.getFootnoteSeparator());
assertEquals("\u0004\r\r", hs.getFootnoteContSeparator());
assertEquals("", hs.getFootnoteContNote());
assertEquals("\u0003\r\r", hs.getEndnoteSeparator());
assertEquals("\u0004\r\r", hs.getEndnoteContSeparator());
assertEquals("", hs.getEndnoteContNote());
-
+
assertEquals("", hs.getFirstHeader());
assertEquals("", hs.getEvenHeader());
assertEquals("First header column!\tMid header Right header!\r\r", hs.getOddHeader());
-
+
assertEquals("", hs.getFirstFooter());
assertEquals("", hs.getEvenFooter());
assertEquals("", hs.getOddFooter());
}
-
+
public void testFooter() throws Exception {
HeaderStories hs = new HeaderStories(footer);
-
+
assertEquals("", hs.getFirstHeader());
assertEquals("", hs.getEvenHeader());
assertEquals("", hs.getOddHeader()); // Was \r\r but gets emptied
-
+
assertEquals("", hs.getFirstFooter());
assertEquals("", hs.getEvenFooter());
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
}
-
+
public void testHeaderFooter() throws Exception {
HeaderStories hs = new HeaderStories(headerFooter);
-
+
assertEquals("", hs.getFirstHeader());
assertEquals("", hs.getEvenHeader());
assertEquals("I am some simple header text here\r\r\r", hs.getOddHeader());
-
+
assertEquals("", hs.getFirstFooter());
assertEquals("", hs.getEvenFooter());
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
}
-
+
public void testOddEven() throws Exception {
HeaderStories hs = new HeaderStories(oddEven);
-
+
assertEquals("", hs.getFirstHeader());
assertEquals("[This is an Even Page, with a Header]\u0007August 20, 2008\u0007\u0007\r\r", hs.getEvenHeader());
assertEquals("August 20, 2008\u0007[ODD Page Header text]\u0007\u0007\r\r", hs.getOddHeader());
-
+
assertEquals("", hs.getFirstFooter());
assertEquals("\u0007Page \u0013 PAGE \\* MERGEFORMAT \u00142\u0015\u0007\u0007\u0007\u0007\u0007\u0007\u0007This is a simple footer on the second page\r\r", hs.getEvenFooter());
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
-
+
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(1));
assertEquals("\u0007Page \u0013 PAGE \\* MERGEFORMAT \u00142\u0015\u0007\u0007\u0007\u0007\u0007\u0007\u0007This is a simple footer on the second page\r\r", hs.getFooter(2));
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
}
-
+
public void testFirst() throws Exception {
HeaderStories hs = new HeaderStories(diffFirst);
-
+
assertEquals("I am the header on the first page, and I\u2019m nice and simple\r\r", hs.getFirstHeader());
assertEquals("", hs.getEvenHeader());
assertEquals("First header column!\tMid header Right header!\r\r", hs.getOddHeader());
-
+
assertEquals("The footer of the first page\r\r", hs.getFirstFooter());
assertEquals("", hs.getEvenFooter());
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
-
+
assertEquals("The footer of the first page\r\r", hs.getFooter(1));
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(2));
assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
}
-
+
public void testUnicode() throws Exception {
HeaderStories hs = new HeaderStories(unicode);
-
+
assertEquals("", hs.getFirstHeader());
assertEquals("", hs.getEvenHeader());
assertEquals("This is a simple header, with a \u20ac euro symbol in it.\r\r\r", hs.getOddHeader());
-
+
assertEquals("", hs.getFirstFooter());
assertEquals("", hs.getEvenFooter());
assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\r\r", hs.getOddFooter());
}
-
+
public void testWithFields() throws Exception {
HeaderStories hs = new HeaderStories(withFields);
assertFalse(hs.areFieldsStripped());
-
+
assertEquals("HEADER GOES HERE. 8/12/2008 \u0013 AUTHOR \\* MERGEFORMAT \u0014Eric Roch\u0015\r\r\r", hs.getOddHeader());
-
+
// Now turn on stripping
hs.setAreFieldsStripped(true);
assertEquals("HEADER GOES HERE. 8/12/2008 Eric Roch\r\r\r", hs.getOddHeader());
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import java.io.ByteArrayOutputStream;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestPictures extends TestCase {
+public final class TestPictures extends TestCase {
private String dirname = System.getProperty("HWPF.testdata.path");
-
+
protected void setUp() throws Exception {
- }
-
+ }
+
/**
* two jpegs
*/
public void testTwoImages() throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/two_images.doc"));
List pics = doc.getPicturesTable().getAllPictures();
-
+
assertNotNull(pics);
assertEquals(pics.size(), 2);
for(int i=0; i<pics.size(); i++) {
Object p = pics.get(i);
assertTrue(p instanceof Picture);
-
+
Picture pic = (Picture)p;
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
}
-
+
Picture picA = (Picture)pics.get(0);
Picture picB = (Picture)pics.get(1);
assertEquals("jpg", picA.suggestFileExtension());
assertEquals("jpg", picA.suggestFileExtension());
}
-
+
/**
* pngs and jpegs
*/
public void testDifferentImages() throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/testPictures.doc"));
List pics = doc.getPicturesTable().getAllPictures();
-
+
assertNotNull(pics);
assertEquals(7, pics.size());
for(int i=0; i<pics.size(); i++) {
Object p = pics.get(i);
assertTrue(p instanceof Picture);
-
+
Picture pic = (Picture)p;
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
}
-
+
assertEquals("jpg", ((Picture)pics.get(0)).suggestFileExtension());
assertEquals("jpg", ((Picture)pics.get(1)).suggestFileExtension());
assertEquals("png", ((Picture)pics.get(3)).suggestFileExtension());
assertEquals("wmf", ((Picture)pics.get(5)).suggestFileExtension());
assertEquals("jpg", ((Picture)pics.get(6)).suggestFileExtension());
}
-
+
/**
* emf image, nice and simple
*/
public void testEmfImage() throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/vector_image.doc"));
List pics = doc.getPicturesTable().getAllPictures();
-
+
assertNotNull(pics);
assertEquals(1, pics.size());
-
+
Picture pic = (Picture)pics.get(0);
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
assertTrue(pic.getSize() > 128);
-
+
// Check right contents
byte[] emf = loadImage("vector_image.emf");
byte[] pemf = pic.getContent();
assertEquals(emf[i], pemf[i]);
}
}
-
+
/**
* emf image, with a crazy offset
*/
public void testEmfComplexImage() throws Exception {
/*
-
+
Commenting out this test case temporarily. The file emf_2003_image does not contain any
pictures. Instead it has an office drawing object. Need to rewrite this test after
revisiting the implementation of office drawing objects.
-
+
HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/emf_2003_image.doc"));
List pics = doc.getPicturesTable().getAllPictures();
-
+
assertNotNull(pics);
assertEquals(1, pics.size());
Picture pic = (Picture)pics.get(0);
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
-
+
// This one's tricky
// TODO: Fix once we've sorted bug #41898
assertNotNull(pic.getContent());
assertNotNull(pic.getRawContent());
-
+
// These are probably some sort of offset, need to figure them out
assertEquals(4, pic.getSize());
assertEquals(0x80000000l, LittleEndian.getUInt(pic.getContent()));
private byte[] loadImage(String filename) throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(dirname + "/" + filename);
-
+
byte[] buf = new byte[4096];
int read = 0;
while( (read = fis.read(buf)) > -1 ) {
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import java.io.File;
*
* @author Nick Burch (nick at torchbox dot com)
*/
-public class TestProblems extends HWPFTestCase {
+public final class TestProblems extends HWPFTestCase {
private String dirname = System.getProperty("HWPF.testdata.path");
-
+
/**
* ListEntry passed no ListTable
*/
public void testListEntryNoListTable() throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(
new File(dirname, "ListEntryNoListTable.doc")));
-
+
Range r = doc.getRange();
StyleSheet styleSheet = doc.getStyleSheet();
for (int x = 0; x < r.numSections(); x++) {
public void testSprmAIOOB() throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(
new File(dirname, "AIOOB-Tap.doc")));
-
+
Range r = doc.getRange();
StyleSheet styleSheet = doc.getStyleSheet();
for (int x = 0; x < r.numSections(); x++) {
assertEquals(6, r.numParagraphs());
assertEquals(0, r.getStartOffset());
assertEquals(87, r.getEndOffset());
-
+
// Paragraph with table
Paragraph p = r.getParagraph(0);
assertEquals(0, p.getStartOffset());
assertEquals(20, p.getEndOffset());
-
+
// Get the table
Table t = r.getTable(p);
-
+
//get the only row
assertEquals(1, t.numRows());
TableRow row = t.getRow(0);
-
+
//get the first cell
TableCell cell = row.getCell(0);
// First cell should have one paragraph
assertEquals(1, cell.numParagraphs());
assertEquals("One paragraph is ok\7", cell.getParagraph(0).text());
-
+
//get the second
cell = row.getCell(1);
// Second cell should be detected as having two paragraphs
assertEquals(2, cell.numParagraphs());
assertEquals("First para is ok\r", cell.getParagraph(0).text());
assertEquals("Second paragraph is skipped\7", cell.getParagraph(1).text());
-
+
//get the last cell
cell = row.getCell(2);
// Last cell should have one paragraph
Range range = doc.getRange();
int numParagraphs = range.numParagraphs();
-
+
int totalLength = 0, deletedLength = 0;
-
+
for (int i = 0; i < numParagraphs; i++) {
Paragraph para = range.getParagraph(i);
String text = para.text();
deletedLength = text.length();
}
}
-
+
// check the text length after deletion
int newLength = 0;
range = doc.getRange();
numParagraphs = range.numParagraphs();
-
+
for (int i = 0; i < numParagraphs; i++) {
Paragraph para = range.getParagraph(i);
String text = para.text();
- newLength += text.length();
+ newLength += text.length();
}
-
+
assertEquals(newLength, totalLength - deletedLength);
}
-
+
/**
* With an encrypted file, we should give a suitable
* exception, and not OOM
// Good
}
}
-
+
public void testWriteProperties() throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(
new File(dirname, "SampleDoc.doc")));
assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
-
+
// Write and read
HWPFDocument doc2 = writeOutAndRead(doc);
assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import junit.framework.TestCase;
* Tests for Range which aren't around deletion, insertion,
* text replacement or textual contents
*/
-public class TestRange extends TestCase {
+public final class TestRange extends TestCase {
public void testFieldStripping() throws Exception {
String exp = "This is some text.";
-
+
String single = "This is some \u0013Blah!\u0015text.";
String with14 = "This is \u0013Blah!\u0014some\u0015 text.";
String withNested =
"This is \u0013Blah!\u0013Blah!\u0015\u0015some text.";
String withNested14 =
"This is \u0013Blah!\u0013Blah!\u0014don't see me\u0015 blah!\u0015some text.";
- String withNestedIn14 =
+ String withNestedIn14 =
"This is \u0013Blah!\u0014some\u0013Blah!\u0015 \u0015text.";
-
+
// Check all comes out right
assertEquals(exp, Range.stripFields(exp));
assertEquals(exp, Range.stripFields(single));
assertEquals(exp, Range.stripFields(withNested));
assertEquals(exp, Range.stripFields(withNested14));
assertEquals(exp, Range.stripFields(withNestedIn14));
-
+
// Ones that are odd and we won't change
String odd1 = "This\u0015 is \u0013 odd";
String odd2 = "This\u0015 is \u0014 also \u0013 odd";
-
+
assertEquals(odd1, Range.stripFields(odd1));
assertEquals(odd2, Range.stripFields(odd2));
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
* Test to see if Range.delete() works even if the Range contains a
* CharacterRun that uses Unicode characters.
*/
-public class TestRangeDelete extends TestCase {
+public final class TestRangeDelete extends TestCase {
// u201c and u201d are "smart-quotes"
- private String introText =
+ private String introText =
"Introduction\r";
- private String fillerText =
+ private String fillerText =
"${delete} This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
private String originalText =
"It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present. Everybody should be thankful to the ${organization} ${delete} and all the POI contributors for their assistance in this matter.\r";
range = daDoc.getOverallRange();
assertEquals(1, range.numSections());
assertEquals(5, range.numParagraphs());
-
-
+
+
// Now, onto just the doc bit
range = daDoc.getRange();
assertEquals(1, range.numSections());
assertEquals(1, daDoc.getSectionTable().getSections().size());
section = range.getSection(0);
-
+
assertEquals(5, section.numParagraphs());
-
+
para = section.getParagraph(0);
assertEquals(1, para.numCharacterRuns());
assertEquals(introText, para.text());
-
+
para = section.getParagraph(1);
assertEquals(5, para.numCharacterRuns());
assertEquals(fillerText, para.text());
-
-
+
+
paraDef = (PAPX)daDoc.getParagraphTable().getParagraphs().get(2);
assertEquals(132, paraDef.getStart());
assertEquals(400, paraDef.getEnd());
-
+
para = section.getParagraph(2);
assertEquals(5, para.numCharacterRuns());
assertEquals(originalText, para.text());
-
-
+
+
paraDef = (PAPX)daDoc.getParagraphTable().getParagraphs().get(3);
assertEquals(400, paraDef.getStart());
assertEquals(438, paraDef.getEnd());
-
+
para = section.getParagraph(3);
assertEquals(1, para.numCharacterRuns());
assertEquals(lastText, para.text());
-
-
+
+
// Check things match on text length
assertEquals(439, range.text().length());
assertEquals(439, section.text().length());
- assertEquals(439,
+ assertEquals(439,
section.getParagraph(0).text().length() +
section.getParagraph(1).text().length() +
section.getParagraph(2).text().length() +
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
*
* TODO - re-enable me when unicode paragraph stuff is fixed!
*/
-public class TestRangeInsertion extends TestCase {
+public final class TestRangeInsertion extends TestCase {
// u201c and u201d are "smart-quotes"
private String originalText =
assertEquals(originalText, para.text());
assertEquals(3, para.numCharacterRuns());
- String text =
- para.getCharacterRun(0).text() +
+ String text =
+ para.getCharacterRun(0).text() +
para.getCharacterRun(1).text() +
para.getCharacterRun(2).text()
;
assertEquals(originalText, text);
-
+
assertEquals(insertionPoint, para.getStartOffset());
}
assertEquals((textToInsert + originalText), para.text());
assertEquals(3, para.numCharacterRuns());
- String text =
- para.getCharacterRun(0).text() +
+ String text =
+ para.getCharacterRun(0).text() +
para.getCharacterRun(1).text() +
para.getCharacterRun(2).text()
;
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import java.io.File;
*
* TODO - re-enable me when unicode paragraph stuff is fixed!
*/
-public class TestRangeProperties extends TestCase {
+public final class TestRangeProperties extends TestCase {
private static final char page_break = (char)12;
-
+
private static final String u_page_1 =
"This is a fairly simple word document, over two pages, with headers and footers.\r" +
"The trick with this one is that it contains some Unicode based strings in it.\r" +
private static final String u_page_2 =
"This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
;
-
- private static final String a_page_1 =
+
+ private static final String a_page_1 =
"I am a test document\r" +
- "This is page 1\r" +
+ "This is page 1\r" +
"I am Calibri (Body) in font size 11\r"
;
- private static final String a_page_2 =
- "This is page two\r" +
+ private static final String a_page_2 =
+ "This is page two\r" +
"It\u2019s Arial Black in 16 point\r" +
"It\u2019s also in blue\r"
;
-
+
private HWPFDocument u;
private HWPFDocument a;
-
+
private String dirname;
-
+
protected void setUp() throws Exception {
dirname = System.getProperty("HWPF.testdata.path");
u = new HWPFDocument(
new FileInputStream(new File(dirname, "SampleDoc.doc"))
);
}
-
-
+
+
public void testAsciiTextParagraphs() throws Exception {
Range r = a.getRange();
assertEquals(
a_page_1 +
- page_break + "\r" +
+ page_break + "\r" +
a_page_2,
r.text()
);
-
+
assertEquals(1, r.numSections());
assertEquals(1, a.getSectionTable().getSections().size());
Section s = r.getSection(0);
assertEquals(
a_page_1 +
- page_break + "\r" +
+ page_break + "\r" +
a_page_2,
s.text()
);
-
+
assertEquals(
7,
r.numParagraphs()
);
String[] p1_parts = a_page_1.split("\r");
String[] p2_parts = a_page_2.split("\r");
-
+
// Check paragraph contents
assertEquals(
p1_parts[0] + "\r",
p1_parts[2] + "\r",
r.getParagraph(2).text()
);
-
+
assertEquals(
page_break + "\r",
r.getParagraph(3).text()
);
-
+
assertEquals(
p2_parts[0] + "\r",
r.getParagraph(4).text()
r.getParagraph(6).text()
);
}
-
+
public void testAsciiStyling() throws Exception {
Range r = a.getRange();
-
+
Paragraph p1 = r.getParagraph(0);
Paragraph p7 = r.getParagraph(6);
-
+
assertEquals(1, p1.numCharacterRuns());
assertEquals(1, p7.numCharacterRuns());
-
+
CharacterRun c1 = p1.getCharacterRun(0);
CharacterRun c7 = p7.getCharacterRun(0);
-
+
assertEquals("Times New Roman", c1.getFontName()); // No Calibri
assertEquals("Arial Black", c7.getFontName());
assertEquals(22, c1.getFontSize());
Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r");
String[] p2_parts = u_page_2.split("\r");
-
+
assertEquals(
u_page_1 + page_break + "\r" + u_page_2,
r.text()
assertEquals(
408, r.text().length()
);
-
-
+
+
assertEquals(1, r.numSections());
assertEquals(1, u.getSectionTable().getSections().size());
Section s = r.getSection(0);
assertEquals(
u_page_1 +
- page_break + "\r" +
+ page_break + "\r" +
u_page_2,
s.text()
);
assertEquals(0, s.getStartOffset());
assertEquals(408, s.getEndOffset());
-
+
List pDefs = r._paragraphs;
assertEquals(35, pDefs.size());
-
+
// Check that the last paragraph ends where it should do
assertEquals(531, u.getOverallRange().text().length());
assertEquals(530, u.getCPSplitCalculator().getHeaderTextboxEnd());
PropertyNode pLast = (PropertyNode)pDefs.get(34);
// assertEquals(530, pLast.getEnd());
-
+
// Only care about the first few really though
PropertyNode p0 = (PropertyNode)pDefs.get(0);
PropertyNode p1 = (PropertyNode)pDefs.get(1);
PropertyNode p2 = (PropertyNode)pDefs.get(2);
PropertyNode p3 = (PropertyNode)pDefs.get(3);
PropertyNode p4 = (PropertyNode)pDefs.get(4);
-
+
// 5 paragraphs should get us to the end of our text
assertTrue(p0.getStart() < 408);
assertTrue(p0.getEnd() < 408);
assertTrue(p3.getEnd() < 408);
assertTrue(p4.getStart() < 408);
assertTrue(p4.getEnd() < 408);
-
+
// Paragraphs should match with lines
assertEquals(
0,
p1_parts[0].length() + 1,
p0.getEnd()
);
-
+
assertEquals(
p1_parts[0].length() + 1,
p1.getStart()
- );
+ );
assertEquals(
p1_parts[0].length() + 1 +
p1_parts[1].length() + 1,
p1.getEnd()
);
-
+
assertEquals(
p1_parts[0].length() + 1 +
p1_parts[1].length() + 1,
Range r = u.getRange();
assertEquals(
u_page_1 +
- page_break + "\r" +
+ page_break + "\r" +
u_page_2,
r.text()
);
-
+
assertEquals(
12,
r.numParagraphs()
);
String[] p1_parts = u_page_1.split("\r");
String[] p2_parts = u_page_2.split("\r");
-
+
// Check text all matches up properly
assertEquals(p1_parts[0] + "\r", r.getParagraph(0).text());
assertEquals(p1_parts[1] + "\r", r.getParagraph(1).text());
public void testUnicodeStyling() throws Exception {
Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r");
-
+
Paragraph p1 = r.getParagraph(0);
Paragraph p7 = r.getParagraph(6);
-
+
// Line ending in its own run each time!
assertEquals(2, p1.numCharacterRuns());
assertEquals(2, p7.numCharacterRuns());
-
+
CharacterRun c1a = p1.getCharacterRun(0);
CharacterRun c1b = p1.getCharacterRun(1);
CharacterRun c7a = p7.getCharacterRun(0);
CharacterRun c7b = p7.getCharacterRun(1);
-
+
assertEquals("Times New Roman", c1a.getFontName()); // No Calibri
assertEquals(22, c1a.getFontSize());
-
+
assertEquals("Times New Roman", c1b.getFontName()); // No Calibri
assertEquals(22, c1b.getFontSize());
-
+
assertEquals("Times New Roman", c7a.getFontName());
assertEquals(48, c7a.getFontSize());
-
+
assertEquals("Times New Roman", c7b.getFontName());
assertEquals(48, c7b.getFontSize());
-
+
// Now check where they crop up
assertEquals(
- 0,
+ 0,
c1a.getStartOffset()
);
assertEquals(
- p1_parts[0].length(),
+ p1_parts[0].length(),
c1a.getEndOffset()
);
-
+
assertEquals(
- p1_parts[0].length(),
+ p1_parts[0].length(),
c1b.getStartOffset()
);
assertEquals(
- p1_parts[0].length()+1,
+ p1_parts[0].length()+1,
c1b.getEndOffset()
);
-
+
assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
- p1_parts[5].length() + 1,
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
+ p1_parts[5].length() + 1,
c7a.getStartOffset()
);
assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
p1_parts[5].length() + 1 +
1,
c7a.getEndOffset()
);
-
+
assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
p1_parts[5].length() + 1 +
- 1,
+ 1,
c7b.getStartOffset()
);
assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
p1_parts[5].length() + 1 +
p1_parts[6].length() + 1,
c7b.getEndOffset()
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
*
* TODO - re-enable me when unicode paragraph stuff is fixed!
*/
-public class TestRangeReplacement extends TestCase {
+public final class TestRangeReplacement extends TestCase {
// u201c and u201d are "smart-quotes"
private String originalText =
Paragraph para = section.getParagraph(2);
assertEquals(5, para.numCharacterRuns());
- String text =
- para.getCharacterRun(0).text() +
+ String text =
+ para.getCharacterRun(0).text() +
para.getCharacterRun(1).text() +
para.getCharacterRun(2).text() +
para.getCharacterRun(3).text() +
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.usermodel;
import java.io.ByteArrayInputStream;
/**
* Test the shapes handling
*/
-public class TestShapes extends TestCase {
+public final class TestShapes extends TestCase {
private String dirname = System.getProperty("HWPF.testdata.path");
/**
assertEquals(4817, s2.getWidth());
assertEquals(2164, s2.getHeight());
assertEquals(true, s2.isWithinDocument());
-
-
+
+
// Re-serialisze, check still there
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
doc = new HWPFDocument(bais);
-
+
shapes = doc.getShapesTable().getAllShapes();
vshapes = doc.getShapesTable().getVisibleShapes();