From: Josh Micich Date: Thu, 21 May 2009 18:12:22 +0000 (+0000) Subject: Changed CRLF to LF in scratchpad. Minor fixes for compiler warnings and formatting X-Git-Tag: REL_3_5_BETA6~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=852e34bfea1affa39f4c89ed5edf2442b13708ab;p=poi.git Changed CRLF to LF in scratchpad. Minor fixes for compiler warnings and formatting git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@777204 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java index 962349876a..91621339b4 100755 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java @@ -1,517 +1,516 @@ - -/* ==================================================================== - 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 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); - } -} +/* ==================================================================== + 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); + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java index a4559713c4..3a97b61aa0 100644 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java @@ -1,62 +1,62 @@ - -/* ==================================================================== - 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 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(); - } -} +/* ==================================================================== + 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(); + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java index 9254c37da3..c20a2f186f 100755 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java @@ -1,59 +1,60 @@ -/* ==================================================================== - 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 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(); - - } -} +/* ==================================================================== + 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(); + + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java index 611466c924..a278e894b6 100755 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java @@ -1,149 +1,148 @@ - -/* ==================================================================== - 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 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"); - } -} +/* ==================================================================== + 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"); + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java index 87a59c38bb..b3d85640e0 100755 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java @@ -1,80 +1,80 @@ - -/* ==================================================================== - 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 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(); - } - -} +/* ==================================================================== + 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(); + } + +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java index f919e545ff..968426c513 100644 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java @@ -1,80 +1,81 @@ -/* ==================================================================== - 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 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); - } - } - } - - } - - } -} +/* ==================================================================== + 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); + } + } + } + + } + + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java index 8a75297121..2371f0fbf6 100755 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java @@ -1,108 +1,107 @@ - -/* ==================================================================== - 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 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 -slide ] ppt"); - } -} +/* ==================================================================== + 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 -slide ] ppt"); + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java index 25ff9ad017..44935c05ac 100755 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java +++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java @@ -1,127 +1,127 @@ - -/* ==================================================================== - 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 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 + 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(); + + } +} diff --git a/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java b/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java index 122533f9ec..82d3a8a230 100644 --- a/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java +++ b/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -24,7 +23,7 @@ import org.apache.poi.hwpf.model.*; import java.io.*; -public class Word2Forrest +public final class Word2Forrest { Writer _out; HWPFDocument _doc; diff --git a/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java b/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java index 97b4be484e..b93ac1f6df 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java +++ b/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hdf.event; @@ -27,7 +26,7 @@ import org.apache.poi.util.LittleEndian; import java.util.ArrayList; -public class EventBridge implements HDFLowLevelParsingListener +public final class EventBridge implements HDFLowLevelParsingListener { private static int HEADER_EVEN_INDEX = 0; diff --git a/src/scratchpad/src/org/apache/poi/hdf/event/HDFLowLevelParsingListener.java b/src/scratchpad/src/org/apache/poi/hdf/event/HDFLowLevelParsingListener.java index 8bf2a18313..3358832d30 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/event/HDFLowLevelParsingListener.java +++ b/src/scratchpad/src/org/apache/poi/hdf/event/HDFLowLevelParsingListener.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/event/HDFParsingListener.java b/src/scratchpad/src/org/apache/poi/hdf/event/HDFParsingListener.java index 05c27b9336..aa8f2b5c71 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/event/HDFParsingListener.java +++ b/src/scratchpad/src/org/apache/poi/hdf/event/HDFParsingListener.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/CHP.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/CHP.java index 2d54a3c0f8..50bfc1a36b 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/CHP.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/CHP.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor; @@ -24,10 +21,10 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/FontTable.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/FontTable.java index 0176188ae9..1c9eab6e9c 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/FontTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,17 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/HeaderFooter.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/HeaderFooter.java index 6662754282..83ede7aeda 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/HeaderFooter.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/HeaderFooter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,17 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java index d332fc5f4e..43932b9472 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/NewOleFile.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor; @@ -26,10 +23,10 @@ import java.util.*; /** * 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, diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/PAP.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/PAP.java index 44e9a78607..1075e145d0 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/PAP.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/PAP.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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 diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/PropertySet.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/PropertySet.java index a7f5958ffc..61b7dc52b1 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/PropertySet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/PropertySet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/SEP.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/SEP.java index cdd0e9504c..300c2f8ad3 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/SEP.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/SEP.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleDescription.java index 0be6ada106..b011b425e6 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleDescription.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor; @@ -24,10 +21,10 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java index ff10eb8e9f..751b03666f 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor; @@ -25,10 +22,10 @@ import java.util.*; /** * Comment me * - * @author Ryan Ackley + * @author Ryan Ackley */ -public class StyleSheet +public final class StyleSheet { private static final int NIL_STYLE = 4095; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/TAP.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/TAP.java index b248b3ee58..42ccde2842 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/TAP.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/TAP.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/TC.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/TC.java index a6663410b0..be201b52c8 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/TC.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/TC.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/TableRow.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/TableRow.java index f254ea81b0..c95d0980a4 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/TableRow.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/TableRow.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor; @@ -25,10 +22,10 @@ import java.util.*; /** * Comment me * - * @author Ryan Ackley + * @author Ryan Ackley */ -public class TableRow +public final class TableRow { TAP _descriptor; ArrayList _cells; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/TextPiece.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/TextPiece.java index d5de406b6b..378b78fb9e 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/TextPiece.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdf.extractor; @@ -24,10 +22,10 @@ import org.apache.poi.hdf.extractor.util.*; /** * 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; @@ -49,5 +47,5 @@ public class TextPiece extends PropertyNode implements Comparable public int compareTo(Object obj) { return 0; } - + } diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/Utils.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/Utils.java index 3e663f432c..7c222ec818 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/Utils.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/Utils.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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) diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java index 2c89fa4bef..a525d97141 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor; @@ -39,7 +36,7 @@ import org.apache.poi.util.LittleEndian; * @author Ryan Ackley */ -public class WordDocument +public final class WordDocument { /** byte buffer containing the main Document stream*/ byte[] _header; @@ -182,7 +179,7 @@ public class WordDocument { this(new FileInputStream(fileName)); } - + public WordDocument(InputStream inputStream) throws IOException { //do Ole stuff @@ -818,8 +815,8 @@ public class WordDocument return ""; -// 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=\"" + diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/DOP.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/DOP.java index d5210a02e9..9e5ae6ce2f 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/DOP.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/DOP.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFO.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFO.java index 05aa53b602..86e4cf0f2f 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFO.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFO.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFOLVL.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFOLVL.java index f4f4e39c56..2984d97485 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFOLVL.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LFOLVL.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LST.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LST.java index 16ccfb099f..932a921c7d 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LST.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LST.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LVL.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LVL.java index 52caa33a34..0e0ed23f68 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LVL.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/LVL.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,19 +14,17 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java index c128e1023b..76ff9b2c37 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor.data; @@ -28,10 +25,10 @@ import org.apache.poi.hdf.extractor.*; /** * Comment me * - * @author Ryan Ackley + * @author Ryan Ackley */ -public class ListTables +public final class ListTables { LFO[] _pllfo; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java index f1e2c8371a..3f05811544 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor.util; @@ -34,11 +31,11 @@ import java.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 diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/ChpxNode.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/ChpxNode.java index c65d321e89..35e0da232a 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/ChpxNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/ChpxNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor.util; @@ -24,10 +21,10 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/NumberFormatter.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/NumberFormatter.java index 6566ee7379..5c9e7205d4 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/NumberFormatter.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/NumberFormatter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.extractor.util; @@ -24,10 +21,10 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PapxNode.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PapxNode.java index 4f614b5532..7ba34c0297 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PapxNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PapxNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PropertyNode.java index 6011d00022..aea50f1bfc 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/PropertyNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,19 +14,16 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/SepxNode.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/SepxNode.java index 5b55611e0d..f5391d0976 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/SepxNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/SepxNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,18 +14,16 @@ 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; @@ -39,9 +36,9 @@ public class SepxNode extends PropertyNode { return getGrpprl(); } - + public int compareTo(Object obj) { return 0; } - + } diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java b/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java index da757c6e86..058f111187 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/HDFDocument.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hdf.model; import java.io.InputStream; @@ -24,7 +23,7 @@ import java.io.IOException; import org.apache.poi.hdf.event.HDFParsingListener; import org.apache.poi.hdf.event.EventBridge; -public class HDFDocument +public final class HDFDocument { HDFObjectModel _model; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java index 66012e8c8d..f08bd0deb0 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,12 +14,6 @@ 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; @@ -53,7 +46,7 @@ import org.apache.poi.util.LittleEndian; * that represent the data. * @author andy */ -public class HDFObjectFactory +public final class HDFObjectFactory { /** OLE stuff*/ diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectModel.java b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectModel.java index 4b49b39755..e0c84314f1 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectModel.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectModel.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -31,7 +30,7 @@ import org.apache.poi.hdf.model.hdftypes.ListTables; import org.apache.poi.hdf.model.hdftypes.StyleSheet; -public class HDFObjectModel implements HDFLowLevelParsingListener +public final class HDFObjectModel implements HDFLowLevelParsingListener { /** "WordDocument" from the POIFS */ diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CHPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CHPFormattedDiskPage.java index d0506185aa..7eb167ead4 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CHPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CHPFormattedDiskPage.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -36,7 +35,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class CHPFormattedDiskPage extends FormattedDiskPage +public final class CHPFormattedDiskPage extends FormattedDiskPage { diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CharacterProperties.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CharacterProperties.java index e5d450f87a..a85edbad44 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CharacterProperties.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/CharacterProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.CHPAbstractType; * @author Ryan Ackley */ -public class CharacterProperties extends CHPAbstractType implements Cloneable +public final class CharacterProperties extends CHPAbstractType implements Cloneable { public CharacterProperties() diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ChpxNode.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ChpxNode.java index db45ee88da..ab0845358d 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ChpxNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ChpxNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ package org.apache.poi.hdf.model.hdftypes; * @author Ryan Ackley */ -public class ChpxNode extends PropertyNode +public final class ChpxNode extends PropertyNode { diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/DocumentProperties.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/DocumentProperties.java index 6bfc372489..2020d78f43 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/DocumentProperties.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/DocumentProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ import org.apache.poi.util.LittleEndian; * @author Ryan Ackley */ -public class DocumentProperties implements HDFType +public final class DocumentProperties implements HDFType { public boolean _fFacingPages; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FileInformationBlock.java index b6793b7a64..23409b5478 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FileInformationBlock.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -28,7 +27,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.FIBAbstractType; * * @author andy */ -public class FileInformationBlock extends FIBAbstractType +public final class FileInformationBlock extends FIBAbstractType { /* private short field_1_id; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FontTable.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FontTable.java index 14927f2fec..e1aa22f829 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FontTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdf.model.hdftypes; @@ -26,7 +24,7 @@ import org.apache.poi.util.LittleEndian; * @author Ryan Ackley */ -public class FontTable implements HDFType +public final class FontTable implements HDFType { String[] fontNames; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FormattedDiskPage.java index 0e61cf35b1..ba912cb7ce 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/FormattedDiskPage.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdf.model.hdftypes; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HDFType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HDFType.java index 681d2999fc..f82a0295be 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HDFType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HDFType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,12 +14,6 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HeaderFooter.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HeaderFooter.java index ffe3b3a9c2..e5a8ffae76 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HeaderFooter.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/HeaderFooter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdf.model.hdftypes; @@ -25,7 +23,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFO.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFO.java index d582f93094..0294ed43d8 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFO.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFO.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -26,7 +23,7 @@ package org.apache.poi.hdf.model.hdftypes; * @author Ryan Ackley */ -public class LFO +public final class LFO { int _lsid; int _clfolvl; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFOLVL.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFOLVL.java index 59026ba4ec..78425fa60f 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFOLVL.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LFOLVL.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -26,7 +23,7 @@ package org.apache.poi.hdf.model.hdftypes; * @author Ryan Ackley */ -public class LFOLVL +public final class LFOLVL { int _iStartAt; int _ilvl; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LST.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LST.java index dd7b5e3346..fd8405b97c 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LST.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LST.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -26,7 +23,7 @@ package org.apache.poi.hdf.model.hdftypes; * @author Ryan Ackley */ -public class LST +public final class LST { int _lsid; int _tplc; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LVL.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LVL.java index 408491e9e2..68e891a0b1 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LVL.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/LVL.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ package org.apache.poi.hdf.model.hdftypes; */ -public class LVL +public final class LVL { public int _iStartAt; public byte _nfc; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java index 3767051e37..e8dbead571 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -31,7 +28,7 @@ import org.apache.poi.hdf.extractor.*; * @author Ryan Ackley */ -public class ListTables implements HDFType +public final class ListTables implements HDFType { LFO[] _pllfo; @@ -148,7 +145,7 @@ public class ListTables implements HDFType 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. @@ -175,7 +172,7 @@ public class ListTables implements HDFType 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PAPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PAPFormattedDiskPage.java index a91707d256..40b712f9de 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PAPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PAPFormattedDiskPage.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -36,7 +35,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class PAPFormattedDiskPage extends FormattedDiskPage +public final class PAPFormattedDiskPage extends FormattedDiskPage { /** diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PapxNode.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PapxNode.java index df3c7ff461..14a000f820 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PapxNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PapxNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -26,7 +23,7 @@ package org.apache.poi.hdf.model.hdftypes; * @author Ryan Ackley */ -public class PapxNode extends PropertyNode +public final class PapxNode extends PropertyNode { diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ParagraphProperties.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ParagraphProperties.java index 2d6901b07f..ce4495ac34 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ParagraphProperties.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ParagraphProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.PAPAbstractType; * @author Ryan Ackley */ -public class ParagraphProperties extends PAPAbstractType implements Cloneable +public final class ParagraphProperties extends PAPAbstractType implements Cloneable { diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PlexOfCps.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PlexOfCps.java index 3fe2b53ea1..b757be7be6 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PlexOfCps.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PlexOfCps.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hdf.model.hdftypes; @@ -29,7 +28,7 @@ package org.apache.poi.hdf.model.hdftypes; * * @author Ryan Ackley */ -public class PlexOfCps +public final class PlexOfCps { private int _count; private int _offset; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PropertyNode.java index 19d65e2870..d41e63d1ed 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/PropertyNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hdf.model.hdftypes; @@ -25,8 +24,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SectionProperties.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SectionProperties.java index 455493d77b..ec480cbc23 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SectionProperties.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SectionProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.SEPAbstractType; * @author Ryan Ackley */ -public class SectionProperties extends SEPAbstractType implements HDFType +public final class SectionProperties extends SEPAbstractType implements HDFType { /*int _index; byte _bkc; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SepxNode.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SepxNode.java index 9b274af5cb..f7d293ce50 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SepxNode.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/SepxNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -26,7 +23,7 @@ package org.apache.poi.hdf.model.hdftypes; * @author Ryan Ackley */ -public class SepxNode extends PropertyNode +public final class SepxNode extends PropertyNode { int _index; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleDescription.java index 5c967482ea..d3297c2132 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleDescription.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +24,7 @@ import org.apache.poi.util.LittleEndian; * @author Ryan Ackley */ -public class StyleDescription implements HDFType +public final class StyleDescription implements HDFType { private static int PARAGRAPH_STYLE = 1; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java index c499988eed..99607f837c 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/StyleSheet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -33,7 +30,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.TCAbstractType; * @author Ryan Ackley */ -public class StyleSheet implements HDFType +public final class StyleSheet implements HDFType { private static final int NIL_STYLE = 4095; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableCellDescriptor.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableCellDescriptor.java index 68ef449e92..c58f5f05bf 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableCellDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableCellDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -28,7 +25,7 @@ import org.apache.poi.util.LittleEndian; * @author Ryan Ackley */ -public class TableCellDescriptor extends TCAbstractType implements HDFType +public final class TableCellDescriptor extends TCAbstractType implements HDFType { /*boolean _fFirstMerged; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableProperties.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableProperties.java index ce9f223f75..af029a290e 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableProperties.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TableProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes; @@ -28,7 +25,7 @@ import org.apache.poi.hdf.model.hdftypes.definitions.TAPAbstractType; * @author Ryan Ackley */ -public class TableProperties extends TAPAbstractType +public final class TableProperties extends TAPAbstractType { diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TextPiece.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TextPiece.java index 98f75e934f..61da53bc21 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/TextPiece.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hdf.model.hdftypes; @@ -27,7 +25,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/CHPAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/CHPAbstractType.java index b940c11a79..d49c46f85f 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/CHPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/CHPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/DOPAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/DOPAbstractType.java index b08c8fec14..0853175e47 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/DOPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/DOPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/FIBAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/FIBAbstractType.java index 8c83dad207..6a0f92025b 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/FIBAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/FIBAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/PAPAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/PAPAbstractType.java index e442f2a562..f0bb7b8569 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/PAPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/PAPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/SEPAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/SEPAbstractType.java index 728024ade4..3de980e7d5 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/SEPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/SEPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TAPAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TAPAbstractType.java index 87118a784c..d7d1896270 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TAPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TAPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TCAbstractType.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TCAbstractType.java index 0f262fa006..014958afc3 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TCAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/definitions/TCAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.hdftypes.definitions; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java b/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java index 548ce86497..25d9612d10 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.util; @@ -39,7 +36,7 @@ import org.apache.poi.hdf.model.hdftypes.PropertyNode; * */ -public class BTreeSet extends AbstractSet +public final class BTreeSet extends AbstractSet { /* diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/util/NumberFormatter.java b/src/scratchpad/src/org/apache/poi/hdf/model/util/NumberFormatter.java index 482787131c..48ccceb544 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/util/NumberFormatter.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/util/NumberFormatter.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model.util; @@ -27,7 +24,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/util/ParsingState.java b/src/scratchpad/src/org/apache/poi/hdf/model/util/ParsingState.java index 5ef7ef4d9f..77950d7ed1 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/util/ParsingState.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/util/ParsingState.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,12 +14,12 @@ 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(); diff --git a/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java b/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java index 764b8e3f5f..06bea56a60 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/HDGFDiagram.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf; import java.io.FileInputStream; @@ -40,59 +41,59 @@ import org.apache.poi.util.LittleEndian; * 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); } @@ -108,21 +109,21 @@ public class HDGFDiagram extends POIDocument { */ 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 0) { System.err.println("\tContains " + pcs.getPointedToStreams().length + " other pointers/streams"); for(int j=0; j= 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 @@ -189,7 +190,7 @@ public class Chunk { if(endsAt == startsAt) { endsAt = contents.length; } - + int strLen = (endsAt-startsAt) / 2; command.value = StringUtil.getFromUnicodeLE(contents, startsAt, strLen); break; @@ -203,7 +204,7 @@ public class Chunk { LittleEndian.getInt(contents, offset) ); break; - + // Types 11 and 21 hold the offset to the blocks case 11: case 21: if(offset < contents.length - 3) { @@ -212,26 +213,26 @@ public class Chunk { 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. @@ -239,7 +240,7 @@ public class Chunk { public static class Command { protected Object value; private CommandDefinition definition; - + private Command(CommandDefinition definition, Object value) { this.definition = definition; this.value = value; @@ -247,7 +248,7 @@ public class Chunk { private Command(CommandDefinition definition) { this(definition, null); } - + public CommandDefinition getDefinition() { return definition; } public Object getValue() { return value; } } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index 34a2f4f893..d2779c88b0 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf.chunks; import java.io.BufferedReader; @@ -34,32 +35,32 @@ import org.apache.poi.util.POILogger; * 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; @@ -67,7 +68,7 @@ public class ChunkFactory { 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; @@ -81,28 +82,28 @@ public class ChunkFactory { } 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; } /** @@ -112,25 +113,25 @@ public class ChunkFactory { */ 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; @@ -140,7 +141,7 @@ public class ChunkFactory { endOfDataPos -= 4; } } - + // Create the trailer and separator, if required ChunkTrailer trailer = null; @@ -167,20 +168,20 @@ public class ChunkFactory { 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. @@ -194,7 +195,7 @@ public class ChunkFactory { this.offset = offset; this.name = name; } - + public String getName() { return name; } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java index 88c91c74f9..7808ce847d 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java @@ -14,6 +14,7 @@ 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; @@ -26,7 +27,7 @@ public abstract class ChunkHeader { 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. @@ -45,24 +46,24 @@ public abstract class ChunkHeader { 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. */ @@ -75,11 +76,11 @@ public abstract class ChunkHeader { return ChunkHeaderV4V5.getHeaderSize(); } } - + public abstract int getSizeInBytes(); public abstract boolean hasTrailer(); public abstract boolean hasSeparator(); - + /** * Returns the ID/IX of the chunk */ diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java index c77a249204..1d3b763ece 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java @@ -14,20 +14,21 @@ 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; } @@ -35,7 +36,7 @@ public class ChunkHeaderV11 extends ChunkHeaderV6 { if(unknown2 == 2 && unknown3 == 0x54 && type == 0xaa) { return true; } if(unknown2 == 3 && unknown3 != 0x50) { return true; } if(type == 0x69) { return true; } - + return false; } } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java index 335c9c543e..7162f5056f 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java @@ -14,12 +14,13 @@ 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; @@ -29,15 +30,15 @@ public class ChunkHeaderV4V5 extends ChunkHeader { public short getUnknown3() { return unknown3; } - + protected static int getHeaderSize() { return 12; } - + public int getSizeInBytes() { return getHeaderSize(); } - + /** * Does the chunk have a trailer? */ @@ -45,7 +46,7 @@ public class ChunkHeaderV4V5 extends ChunkHeader { // V4 and V5 never has trailers return false; } - + /** * Does the chunk have a separator? */ diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java index 4d13b85bd2..cfbae6e04c 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf.chunks; /** @@ -29,7 +30,7 @@ public class ChunkHeaderV6 extends ChunkHeader { public short getUnknown3() { return unknown3; } - + protected static int getHeaderSize() { // Looks like it ought to be 19... return 19; @@ -37,7 +38,7 @@ public class ChunkHeaderV6 extends ChunkHeader { public int getSizeInBytes() { return getHeaderSize(); } - + /** * Does the chunk have a trailer? */ diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java index 5ce4097446..bf49ceac48 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java @@ -14,20 +14,21 @@ 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 ""; } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java index a590732466..ad3441d88d 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java @@ -14,19 +14,20 @@ 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 ""; } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java b/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java index 614b9259a0..ed5e700d06 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf.dev; import java.io.FileInputStream; @@ -31,27 +32,27 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * 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 "); 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= 8) { @@ -87,12 +88,12 @@ public class VSDDumper { } } 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 0) { @@ -90,7 +91,7 @@ public class VisioTextExtractor extends POIOLE2TextExtractor { } } } - + /** * Returns the textual contents of the file. * Each textual object's text will be separated @@ -108,17 +109,17 @@ public class VisioTextExtractor extends POIOLE2TextExtractor { } return text.toString(); } - + public static void main(String[] args) throws Exception { if(args.length == 0) { System.err.println("Use:"); System.err.println(" VisioTextExtractor "); 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()); } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java index 848d52b869..d10f154e2e 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java @@ -14,10 +14,11 @@ 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 { @@ -26,7 +27,7 @@ public abstract class Pointer { protected int offset; protected int length; protected short format; - + public int getAddress() { return address; } @@ -42,7 +43,7 @@ public abstract class Pointer { public int getType() { return type; } - + public abstract int getSizeInBytes(); public abstract boolean destinationHasStrings(); public abstract boolean destinationHasPointers(); diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java index 58e863907e..fb97d6e2b8 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java @@ -14,6 +14,7 @@ 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; @@ -22,13 +23,13 @@ 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) { @@ -38,7 +39,7 @@ public class PointerFactory { 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"); diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV6.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV6.java index 5f6ab18cf2..75445dcd11 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV6.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerV6.java @@ -14,12 +14,13 @@ 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); } @@ -31,12 +32,12 @@ public class PointerV6 extends Pointer { 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 */ diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java index 65b69d95ad..0f7a92da95 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf.streams; import java.util.ArrayList; @@ -23,32 +24,32 @@ import org.apache.poi.hdgf.chunks.ChunkFactory; 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) { @@ -57,14 +58,14 @@ public class ChunkStream extends Stream { 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()]); } } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java index 4bf70417dd..da6f3c11a5 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf.streams; import java.io.ByteArrayInputStream; @@ -25,26 +26,26 @@ import org.apache.poi.hdgf.HDGFLZW; * 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); } @@ -55,7 +56,7 @@ public class CompressedStreamStore extends StreamStore { 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. @@ -63,31 +64,31 @@ public class CompressedStreamStore extends StreamStore { */ 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 +} diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java index 761eb181f9..ff8da5e983 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java @@ -14,6 +14,7 @@ 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; @@ -25,35 +26,35 @@ import org.apache.poi.util.LittleEndian; * 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 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()); } } @@ -135,52 +136,52 @@ public class HPBFDumper { 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 @@ -194,7 +195,7 @@ public class HPBFDumper { // 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 @@ -203,7 +204,7 @@ public class HPBFDumper { new String(data, 0, 8) + dumpBytes(data, 8, 0x20-8) ); - + int pos = 0x20; boolean sixNotEight = true; while(pos < 0x200) { @@ -220,11 +221,11 @@ public class HPBFDumper { 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; @@ -240,18 +241,18 @@ public class HPBFDumper { 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]; @@ -259,7 +260,7 @@ public class HPBFDumper { 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) { @@ -275,11 +276,11 @@ public class HPBFDumper { // 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); @@ -287,14 +288,14 @@ public class HPBFDumper { 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] ); @@ -303,30 +304,30 @@ public class HPBFDumper { 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)); @@ -335,15 +336,15 @@ public class HPBFDumper { 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); diff --git a/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java b/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java index cdec78c8cf..c6bfca93b9 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.dev; import java.io.FileInputStream; @@ -31,10 +32,10 @@ import org.apache.poi.util.HexDump; * 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(); @@ -45,7 +46,7 @@ public class PLCDumper { 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:"); @@ -55,14 +56,14 @@ public class PLCDumper { 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"); } - + for(int i=0; i 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. @@ -66,13 +66,13 @@ public abstract class EscherPart extends HPBFPart { protected void generateData() { int size = 0; for(int i=0; i= 2) { until = twoStartsAt + (numberOfPLCs-2)*threePlusIncrement; } - + plcValA = new long[(until-at)/2]; plcValB = new long[0]; for(int i=0; i 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; @@ -102,7 +99,7 @@ public class EncryptedSlideShow 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(), @@ -110,7 +107,7 @@ public class EncryptedSlideShow ); if(! (r2 instanceof PersistPtrHolder)) { return null; } PersistPtrHolder pph = (PersistPtrHolder)r2; - + // Now get the last record int[] slideIds = pph.getKnownSlideIDs(); int maxSlideId = -1; @@ -118,7 +115,7 @@ public class EncryptedSlideShow if(slideIds[i] > maxSlideId) { maxSlideId = slideIds[i]; } } if(maxSlideId == -1) { return null; } - + int offset = ( (Integer)pph.getSlideLocationsLookup().get( new Integer(maxSlideId) @@ -127,13 +124,13 @@ public class EncryptedSlideShow hss.getUnderlyingBytes(), offset ); - + // If we have a DocumentEncryptionAtom, it'll be this one if(r3 instanceof DocumentEncryptionAtom) { return (DocumentEncryptionAtom)r3; } } - + return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java index c0a92a3188..80767b3a0e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java @@ -47,7 +47,7 @@ import org.apache.poi.util.POILogFactory; 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 @@ -80,7 +80,7 @@ public final class HSLFSlideShow extends POIDocument { } /** - * 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. @@ -90,9 +90,9 @@ public final class HSLFSlideShow extends POIDocument { { 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 @@ -104,7 +104,7 @@ public final class HSLFSlideShow extends POIDocument { } /** - * 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 @@ -114,9 +114,9 @@ public final class HSLFSlideShow extends POIDocument { { 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. * @@ -127,15 +127,15 @@ public final class HSLFSlideShow extends POIDocument { 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); @@ -148,7 +148,7 @@ public final class HSLFSlideShow extends POIDocument { // Look for Property Streams: readProperties(); - + // Look for any other streams readOtherStreams(); @@ -171,8 +171,8 @@ public final class HSLFSlideShow extends POIDocument { } /** - * 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 */ @@ -186,9 +186,9 @@ public final class HSLFSlideShow extends POIDocument { _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() @@ -206,7 +206,7 @@ public final class HSLFSlideShow extends POIDocument { // // 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) @@ -216,9 +216,9 @@ public final class HSLFSlideShow extends POIDocument { // 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 @@ -231,7 +231,7 @@ public final class HSLFSlideShow extends POIDocument { 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)); @@ -269,7 +269,7 @@ public final class HSLFSlideShow extends POIDocument { } /** - * Find the "Current User" stream, and load it + * Find the "Current User" stream, and load it */ private void readCurrentUserStream() { try { @@ -279,9 +279,9 @@ public final class HSLFSlideShow extends POIDocument { 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 @@ -301,7 +301,7 @@ public final class HSLFSlideShow extends POIDocument { 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; } @@ -348,7 +348,7 @@ public final class HSLFSlideShow extends POIDocument { logger.log(POILogger.ERROR, "Problem reading picture: " + e + "\nYou document will probably become corrupted if you save it!"); } } - + pos += imgsize; } } @@ -383,7 +383,7 @@ public final class HSLFSlideShow extends POIDocument { // The list of entries we've written out List writtenEntries = new ArrayList(1); - + // Write out the Property Streams writeProperties(outFS, writtenEntries); @@ -449,7 +449,7 @@ public final class HSLFSlideShow extends POIDocument { currentUser.writeToFS(outFS); writtenEntries.add("Current User"); - + // Write any pictures, into another stream if (_pictures.size() > 0) { ByteArrayOutputStream pict = new ByteArrayOutputStream(); @@ -461,7 +461,7 @@ public final class HSLFSlideShow extends POIDocument { ); writtenEntries.add("Pictures"); } - + // If requested, write out any other streams we spot if(preserveNodes) { copyNodes(filesystem, outFS, writtenEntries); @@ -498,7 +498,7 @@ public final class HSLFSlideShow extends POIDocument { _records = r; return addedAt; } - + /** * Add a new picture to this presentation. * diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java b/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java index 223a1bbcd9..9f59de4a86 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java @@ -14,6 +14,7 @@ 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; @@ -24,7 +25,7 @@ import java.io.ByteArrayOutputStream; /** * 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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java b/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java index ab6d645d6e..b9ba597115 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/BitmapPainter.java @@ -1,51 +1,68 @@ -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 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); - } - -} +/* ==================================================================== + 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); + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java b/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java index 5991443133..7e97446e43 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java @@ -14,6 +14,7 @@ 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; @@ -23,10 +24,10 @@ import java.io.IOException; /** * 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 */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java b/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java index 97ef83b769..1f1b13370a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java @@ -14,6 +14,7 @@ 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; @@ -29,10 +30,10 @@ import java.util.zip.DeflaterOutputStream; /** * 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/ImagePainter.java b/src/scratchpad/src/org/apache/poi/hslf/blip/ImagePainter.java index 8849a31a22..2c35007048 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/ImagePainter.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/ImagePainter.java @@ -1,71 +1,72 @@ -/* ==================================================================== - 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. - *

- * 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. - *

- * - * A typical usage is as follows: - * - * 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()); - * ... - * - * 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); -} +/* ==================================================================== + 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. + *

+ * 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. + *

+ * + * A typical usage is as follows: + * + * 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()); + * ... + * + * 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); +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java b/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java index cad42dc67c..65ade3ee38 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/JPEG.java @@ -14,16 +14,17 @@ 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java b/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java index c3895d1d93..8a4d5aeb81 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/Metafile.java @@ -14,6 +14,7 @@ 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; @@ -27,7 +28,7 @@ import java.util.zip.InflaterInputStream; /** * 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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java b/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java index fce1bc803a..5fe6bccec9 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java @@ -14,6 +14,7 @@ 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; @@ -27,10 +28,10 @@ import java.util.zip.DeflaterOutputStream; /** * Represents Macintosh PICT picture data. - * + * * @author Yegor Kozlov */ -public class PICT extends Metafile { +public final class PICT extends Metafile { public PICT(){ super(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java b/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java index a72d3b6c10..20016fd6b3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/PNG.java @@ -14,6 +14,7 @@ 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; @@ -26,10 +27,10 @@ import java.io.IOException; /** * 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java b/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java index b7f22c137b..acc74276ad 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java @@ -14,6 +14,7 @@ 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; @@ -28,10 +29,10 @@ import java.util.zip.DeflaterOutputStream; /** * 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java index d69f45b155..f46906f73c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,8 +15,6 @@ limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.dev; import org.apache.poi.hslf.*; @@ -29,7 +26,7 @@ import org.apache.poi.hslf.record.*; * 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"); diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java index 8a68f8b37b..4b2c9b913b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java @@ -28,7 +28,7 @@ import java.io.*; * @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"; diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java index 8287e48a3b..490e3e2055 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,8 +15,6 @@ limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.dev; import org.apache.poi.hslf.HSLFSlideShow; @@ -31,7 +28,7 @@ import org.apache.poi.hslf.record.SlideListWithText; * 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"); @@ -46,7 +43,7 @@ public class SLWTListing { 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! **"); @@ -54,14 +51,14 @@ public class SLWTListing { 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"); System.err.println("Valid Options:"); @@ -94,7 +94,7 @@ public final class SlideShowRecordDumper { /** - * 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. @@ -139,7 +139,7 @@ public final class SlideShowRecordDumper { public int getDiskLen(Record r) throws IOException { if (r == null) return 0; - + ByteArrayOutputStream baos = new ByteArrayOutputStream(); r.writeOut(baos); byte[] b = baos.toByteArray(); @@ -148,13 +148,13 @@ public final class SlideShowRecordDumper { public String getPrintableRecordContents(Record r) throws IOException { if (r==null) return "<>"; - + 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(); @@ -163,41 +163,41 @@ public final class SlideShowRecordDumper { 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 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(); @@ -211,13 +211,13 @@ public final class SlideShowRecordDumper { 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 + @@ -242,7 +242,7 @@ public final class SlideShowRecordDumper { // 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); @@ -273,9 +273,9 @@ public final class SlideShowRecordDumper { 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 ); diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java index fa19398d27..0ee4fbd0df 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,8 +15,6 @@ limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.dev; import org.apache.poi.hslf.*; @@ -33,7 +30,7 @@ import java.util.LinkedList; * 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"); @@ -84,7 +81,7 @@ public class TextStyleListing { 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 (pptContents.length - 8)) { + if(newPos > (pptContents.length - 8)) { newPos = -1; } return newPos; diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java index 829e0104a7..c9b55082b3 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java @@ -1,169 +1,168 @@ -/* ==================================================================== - 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 Picture - * - * @param pictureIdx the index of the picture - */ - public ActiveXShape(int movieIdx, int pictureIdx){ - super(pictureIdx, null); - setActiveXIndex(movieIdx); - } - - /** - * Create a Picture object - * - * @param escherRecord the EscherSpContainer record which holds information about - * this picture in the Slide - * @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 EscherContainerRecord 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 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); - } - - } -} +/* ==================================================================== + 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 Picture + * + * @param pictureIdx the index of the picture + */ + public ActiveXShape(int movieIdx, int pictureIdx){ + super(pictureIdx, null); + setActiveXIndex(movieIdx); + } + + /** + * Create a Picture object + * + * @param escherRecord the EscherSpContainer record which holds information about + * this picture in the Slide + * @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 EscherContainerRecord 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 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); + } + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java b/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java index 1fc4ec9932..bc1cc1293f 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/AutoShapes.java @@ -1,380 +1,381 @@ -/* ==================================================================== - 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 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); - } - }; - - - } -} +/* ==================================================================== + 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); + } + }; + + + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Background.java b/src/scratchpad/src/org/apache/poi/hslf/model/Background.java index e2718f6aca..531f2da191 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Background.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Background.java @@ -29,10 +29,10 @@ import java.io.ByteArrayInputStream; /** * 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java b/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java index 896d43c84e..27afa47c8a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Comment.java @@ -20,7 +20,7 @@ package org.apache.poi.hslf.model; import org.apache.poi.hslf.record.Comment2000; /** - * + * * @author Nick Burch */ public final class Comment { diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java b/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java index 49393250d1..dd985a0381 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Fill.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -32,7 +31,7 @@ import java.awt.*; * * @author Yegor Kozlov */ -public class Fill { +public final class Fill { // For logging protected POILogger logger = POILogFactory.getLogger(this.getClass()); @@ -229,7 +228,7 @@ public class Fill { /** * Assign picture used to fill the underlying shape. * - * @param idx 0-based index of the picture added to this ppt by SlideShow.addPicture method. + * @param idx 0-based index of the picture added to this ppt by SlideShow.addPicture method. */ public void setPictureData(int idx){ EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java index fb3980a455..545ffdffe1 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java @@ -1,248 +1,249 @@ -/* ==================================================================== - 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. - * - *

- * 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 java.awt.geom.GeneralPath. - *

- * @author Yegor Kozlov - */ -public 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 EscherSpContainer 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); - } -} +/* ==================================================================== + 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. + * + *

+ * 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 java.awt.geom.GeneralPath. + *

+ * @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 EscherSpContainer 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java b/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java index 38b0dff9e2..8bb441e4e4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java @@ -1,267 +1,267 @@ - -/* ==================================================================== - 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 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; - } - -} +/* ==================================================================== + 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; + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java index c92935f7a8..5c33d807ee 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java @@ -1,216 +1,215 @@ - -/* ==================================================================== - 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 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 LINK_* constant - * - * @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 TextRun to lookup hyperlinks in - * @return found hyperlinks or null 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 Shape to lookup hyperlink in - * @return found hyperlink or null - */ - 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 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); - } - } - } - } -} +/* ==================================================================== + 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 LINK_* constant + * + * @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 TextRun to lookup hyperlinks in + * @return found hyperlinks or null 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 Shape to lookup hyperlink in + * @return found hyperlink or null + */ + 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 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); + } + } + } + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Line.java b/src/scratchpad/src/org/apache/poi/hslf/model/Line.java index 370da96d6b..e40a46519c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Line.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Line.java @@ -27,7 +27,7 @@ import java.awt.geom.Line2D; * * @author Yegor Kozlov */ -public class Line extends SimpleShape { +public final class Line extends SimpleShape { /** * Solid (continuous) pen */ @@ -114,7 +114,7 @@ public class Line extends SimpleShape { 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java b/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java index 501cf65bdf..f3968448c4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -26,7 +27,7 @@ import org.apache.poi.hslf.model.textproperties.TextProp; * 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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java index ff4cac0a55..9d066ac944 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java @@ -1,176 +1,174 @@ -/* ==================================================================== - 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 Picture - * - * @param pictureIdx the index of the picture - */ - public MovieShape(int movieIdx, int pictureIdx){ - super(pictureIdx, null); - setMovieIndex(movieIdx); - setAutoPlay(true); - } - - /** - * Create a new Picture - * - * @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 Picture object - * - * @param escherRecord the EscherSpContainer record which holds information about - * this picture in the Slide - * @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 EscherContainerRecord 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; - } - - /** - * Returns UNC or local path to a video file - * - * @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 + 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 Picture + * + * @param pictureIdx the index of the picture + */ + public MovieShape(int movieIdx, int pictureIdx){ + super(pictureIdx, null); + setMovieIndex(movieIdx); + setAutoPlay(true); + } + + /** + * Create a new Picture + * + * @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 Picture object + * + * @param escherRecord the EscherSpContainer record which holds information about + * this picture in the Slide + * @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 EscherContainerRecord 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; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java b/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java index 44fb80630d..cdb05030b4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Notes.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,20 +14,18 @@ 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; @@ -42,7 +39,7 @@ public class Notes extends Sheet 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()); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java index 642b569461..161a332b34 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java @@ -1,159 +1,160 @@ -/* -* 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 class OLEShape extends Picture { - protected ExEmbed _exEmbed; - - /** - * Create a new OLEShape - * - * @param idx the index of the picture - */ - public OLEShape(int idx){ - super(idx); - } - - /** - * Create a new OLEShape - * - * @param idx the index of the picture - * @param parent the parent shape - */ - public OLEShape(int idx, Shape parent) { - super(idx, parent); - } - - /** - * Create a OLEShape object - * - * @param escherRecord the EscherSpContainer record which holds information about - * this picture in the Slide - * @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. - * - *

- * 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 - *

- */ - 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(); - } -} +/* ==================================================================== + 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 OLEShape + * + * @param idx the index of the picture + */ + public OLEShape(int idx){ + super(idx); + } + + /** + * Create a new OLEShape + * + * @param idx the index of the picture + * @param parent the parent shape + */ + public OLEShape(int idx, Shape parent) { + super(idx, parent); + } + + /** + * Create a OLEShape object + * + * @param escherRecord the EscherSpContainer record which holds information about + * this picture in the Slide + * @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. + * + *

+ * 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 + *

+ */ + 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(); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java b/src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java index 8b4de90509..e6f7a9ded9 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java @@ -1,243 +1,243 @@ -/* ==================================================================== - 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. - *

- * In PowerPoint Font is a shared resource and can be shared among text object in the presentation. - *

- * Some commonly used fonts are predefined in static constants. - * - * @author Yegor Kozlov - */ -public 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 - *

- * Bit 1: Raster Font - * Bit 2: Device Font - * Bit 3: TrueType Font - *

- * - * @param val - the font type - */ - public void setFontType(int val){ - type = val; - } - - /** - * get the font type - *

- * Bit 1: Raster Font - * Bit 2: Device Font - * Bit 3: TrueType Font - *

- * - * @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); - } -} +/* ==================================================================== + 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. + *

+ * In PowerPoint Font is a shared resource and can be shared among text object in the presentation. + *

+ * 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 + *

+ * Bit 1: Raster Font + * Bit 2: Device Font + * Bit 3: TrueType Font + *

+ * + * @param val - the font type + */ + public void setFontType(int val){ + type = val; + } + + /** + * get the font type + *

+ * Bit 1: Raster Font + * Bit 2: Device Font + * Bit 3: TrueType Font + *

+ * + * @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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java b/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java index 37cedce0fa..4686dc3f76 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hslf.model; @@ -37,7 +38,7 @@ import org.apache.poi.util.POILogFactory; * * @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()); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java index db86f28811..72fcbd6af7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java @@ -1,19 +1,20 @@ -/* -* 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.*; @@ -72,7 +73,7 @@ public class Picture extends SimpleShape { * Windows DIB (BMP) */ public static final byte DIB = 7; - + /** * Create a new Picture * @@ -143,7 +144,7 @@ public class Picture extends SimpleShape { /** * 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(); @@ -151,10 +152,10 @@ public class Picture extends SimpleShape { 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)); @@ -163,7 +164,7 @@ public class Picture extends SimpleShape { 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)); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java b/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java index 1474fdc7c0..71716fe4b8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java @@ -29,7 +29,7 @@ import java.io.ByteArrayOutputStream; * * @author Yegor Kozlov */ -public class Placeholder extends TextBox { +public final class Placeholder extends TextBox { protected Placeholder(EscherContainerRecord escherRecord, Shape parent){ super(escherRecord, parent); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java b/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java index ea4afe01b2..4e2eb3ed10 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java @@ -1,160 +1,161 @@ -/* ==================================================================== - 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 class Polygon extends AutoShape { - /** - * Create a Polygon object and initialize it from the supplied Record container. - * - * @param escherRecord EscherSpContainer 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; - } - - -} +/* ==================================================================== + 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 EscherSpContainer 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; + } + + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java index 7ab1254370..3971d5216d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java @@ -14,6 +14,7 @@ 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.*; diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java index ab95fae66a..9440bc61e2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java @@ -14,6 +14,7 @@ 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.*; @@ -29,12 +30,12 @@ import java.util.Iterator; * * @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){ @@ -96,7 +97,7 @@ public class ShapeFactory { } else if (oes != null){ shape = new OLEShape(spContainer, parent); } - + if(shape == null) shape = new Picture(spContainer, parent); break; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java index 50119b6bff..fe9b421687 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java @@ -86,7 +86,7 @@ public class ShapeGroup extends Shape{ 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; diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeOutline.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeOutline.java index 069fdbc4d0..591bb55523 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeOutline.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeOutline.java @@ -1,27 +1,28 @@ -/* ==================================================================== - 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); - -} +/* ==================================================================== + 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); + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java index fa947ddfed..15a727af71 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java @@ -1,102 +1,103 @@ -/* ==================================================================== - 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 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); - } - } -} +/* ==================================================================== + 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); + } + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeTypes.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeTypes.java index fea017a08e..8f786e61fd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapeTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapeTypes.java @@ -14,6 +14,7 @@ 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; @@ -26,7 +27,7 @@ import java.lang.reflect.Field; * * @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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java index 26597118b8..6ce6368e51 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.model; import org.apache.poi.ddf.*; @@ -190,7 +189,7 @@ public abstract class Sheet { lst.toArray(recs); trun._records = recs; trun.setIndex(slwtIndex); - + found.add(trun); i++; } else { @@ -379,7 +378,7 @@ public abstract class Sheet { * @param shape */ protected void onAddTextShape(TextShape shape) { - + } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java index cb32e69c2b..13a2835b22 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java @@ -38,7 +38,7 @@ import org.apache.poi.util.LittleEndian; * * @author Yegor Kozlov */ -public class SimpleShape extends Shape { +public abstract class SimpleShape extends Shape { /** * Records stored in EscherClientDataRecord diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java index bb2e8fc79f..d01ac302d7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.model; @@ -32,7 +29,7 @@ import org.apache.poi.ddf.EscherDgRecord; 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 * @@ -40,7 +37,7 @@ import org.apache.poi.ddf.EscherSpRecord; * @author Yegor Kozlov */ -public class Slide extends Sheet +public final class Slide extends Sheet { private int _slideNo; private SlideAtomsSet _atomSet; @@ -90,7 +87,7 @@ public class Slide extends Sheet _runs[i].setSheet(this); } } - + /** * Create a new Slide instance * @param sheetNumber The internal number of the sheet, as used by PersistPtrHolder @@ -120,7 +117,7 @@ public class Slide extends Sheet sa.setNotesID(notes._getSheetNumber()); } } - + /** * Changes the Slide's (external facing) page number. * @see org.apache.poi.hslf.usermodel.SlideShow#reorderSlide(int, int) @@ -128,7 +125,7 @@ public class Slide extends Sheet public void setSlideNumber(int newSlideNumber) { _slideNo = newSlideNumber; } - + /** * Called by SlideShow ater a new slide is created. *

@@ -162,7 +159,7 @@ public class Slide extends Sheet 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); } @@ -207,7 +204,7 @@ public class Slide extends Sheet } return null; } - + // Simple Accesser methods follow /** @@ -361,10 +358,10 @@ public class Slide extends Sheet } 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. */ @@ -393,7 +390,7 @@ public class Slide extends Sheet count++; } } - + // Now build Comment[] comments = new Comment[count]; count = 0; @@ -405,12 +402,12 @@ public class Slide extends Sheet count++; } } - + return comments; } } } - + // None found return new Comment[0]; } @@ -433,7 +430,7 @@ public class Slide extends Sheet } /** - * Header / Footer settings for this slide. + * Header / Footer settings for this slide. * * @return Header / Footer settings for this slide */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java b/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java index b30a46e38a..a72e4658b7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java @@ -29,7 +29,7 @@ import org.apache.poi.hslf.usermodel.SlideShow; * * @author Yegor Kozlov */ -public class SlideMaster extends MasterSheet { +public final class SlideMaster extends MasterSheet { private TextRun[] _runs; /** @@ -64,7 +64,7 @@ public class SlideMaster extends MasterSheet { /** * 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) { @@ -111,7 +111,7 @@ public class SlideMaster extends MasterSheet { /** * Assign SlideShow for this slide master. * (Used interanlly) - */ + */ public void setSlideShow(SlideShow ss) { super.setSlideShow(ss); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java index 907bce3773..b8d9f623b4 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java @@ -1,343 +1,343 @@ - -/* ==================================================================== - 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 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 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 EscherSpContainer 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 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 SlideShow 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; - } -} +/* ==================================================================== + 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 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 EscherSpContainer 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 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 SlideShow 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; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java b/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java index 71833678a5..d8198283bd 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java @@ -1,153 +1,153 @@ - -/* ==================================================================== - 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 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 EscherSpContainer 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 + 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 EscherSpContainer 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java index dda55a2c7b..46e080eb5d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -33,7 +32,7 @@ public class TextBox extends TextShape { /** * Create a TextBox object and initialize it from the supplied Record container. - * + * * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java index 9a86120e7c..f297ff0263 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java @@ -1,311 +1,312 @@ -/* ==================================================================== - 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 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 + 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; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java index cf2db50e86..6260c62cac 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.model; @@ -38,7 +35,7 @@ import org.apache.poi.util.StringUtil; * @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! @@ -80,7 +77,7 @@ public class TextRun public TextRun(TextHeaderAtom tha, TextBytesAtom tba, StyleTextPropAtom sta) { this(tha,tba,null,sta); } - + /** * Internal constructor and initializer */ @@ -95,7 +92,7 @@ public class TextRun _isUnicode = true; } String runRawText = getText(); - + // Figure out the rich text runs LinkedList pStyles = new LinkedList(); LinkedList cStyles = new LinkedList(); @@ -107,7 +104,7 @@ public class TextRun } buildRichTextRuns(pStyles, cStyles, runRawText); } - + public void buildRichTextRuns(LinkedList pStyles, LinkedList cStyles, String runRawText){ // Handle case of no current style, with a default @@ -258,25 +255,25 @@ public class TextRun } // 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 @@ -296,32 +293,32 @@ public class TextRun 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 @@ -329,7 +326,7 @@ public class TextRun 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 @@ -344,11 +341,11 @@ public class TextRun _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(); @@ -360,7 +357,7 @@ public class TextRun break; } } - + // Flag the change _byteAtom = null; _isUnicode = true; @@ -379,7 +376,7 @@ public class TextRun } } } - + /** * Handles an update to the text stored in one of the Rich Text Runs * @param run @@ -396,10 +393,10 @@ public class TextRun 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 @@ -416,7 +413,7 @@ public class TextRun if(runID == _rtRuns.length-1) { newSize++; } - + if(run._isParagraphStyleShared()) { pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length() ); } else { @@ -427,14 +424,14 @@ public class TextRun } 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 @@ -443,7 +440,7 @@ public class TextRun // 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) { @@ -453,15 +450,15 @@ public class TextRun _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 @@ -481,10 +478,10 @@ public class TextRun 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 @@ -503,7 +500,7 @@ public class TextRun } /** - * 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() { @@ -511,23 +508,23 @@ public class TextRun // 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), @@ -572,7 +569,7 @@ public class TextRun return _byteAtom.getText(); } } - + /** * Fetch the rich text runs (runs of text with the same styling) that * are contained within this block of text @@ -580,13 +577,13 @@ public class TextRun 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(); } @@ -599,7 +596,7 @@ public class TextRun public void setRunType(int type) { _headerAtom.setTextType(type); } - + /** * Supply the SlideShow we belong to. * Also passes it on to our child RichTextRuns @@ -618,7 +615,7 @@ public class TextRun } public Sheet getSheet(){ - return this.sheet; + return this.sheet; } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java b/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java index 9b5e8bfc4c..843f123890 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java @@ -1,69 +1,69 @@ -/* ==================================================================== - 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 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; - } -} +/* ==================================================================== + 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; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/ParagraphFlagsTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/ParagraphFlagsTextProp.java index 0ea21b2992..f1bce9593a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/ParagraphFlagsTextProp.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/ParagraphFlagsTextProp.java @@ -1,41 +1,41 @@ -/* ==================================================================== - 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 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"} - ); - } -} \ 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"} + ); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java index 37dae8fec3..e9dc5cd955 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java @@ -1,97 +1,98 @@ -/* -* 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 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; - } - -} +/* ==================================================================== + 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; + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java index 4de22e50c3..731a3b51c9 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java @@ -1,278 +1,277 @@ -/* ==================================================================== - 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 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. +==================================================================== */ + +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(); + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CString.java b/src/scratchpad/src/org/apache/poi/hslf/record/CString.java index e7e46baa00..a428621e63 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CString.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CString.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -30,15 +31,15 @@ import org.apache.poi.util.StringUtil; * @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); } @@ -51,18 +52,18 @@ public class CString extends RecordAtom { // 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); @@ -70,8 +71,8 @@ public class CString extends RecordAtom { /* *************** record code follows ********************** */ - /** - * For the CStrubg Atom + /** + * For the CStrubg Atom */ protected CString(byte[] source, int start, int len) { // Sanity Checking diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java index 4e9e029fd3..4aea93f869 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -27,13 +25,13 @@ import java.io.ByteArrayOutputStream; /** * 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; @@ -85,7 +83,7 @@ public class ColorSchemeAtom extends RecordAtom { 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) @@ -93,7 +91,7 @@ public class ColorSchemeAtom extends RecordAtom /* *************** record code follows ********************** */ - /** + /** * For the Colour Scheme (ColorSchem) Atom */ protected ColorSchemeAtom(byte[] source, int start, int len) { @@ -119,7 +117,7 @@ public class ColorSchemeAtom extends RecordAtom 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 */ @@ -128,7 +126,7 @@ public class ColorSchemeAtom extends RecordAtom 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; @@ -139,7 +137,7 @@ public class ColorSchemeAtom extends RecordAtom accentAndHyperlinkColourRGB = 16764108; accentAndFollowingHyperlinkColourRGB = 11711154; } - + /** * We are of type 3999 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java index 31ef11a66c..0a65cdbffd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -23,24 +24,24 @@ import org.apache.poi.util.LittleEndian; /** * 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 */ @@ -79,8 +80,8 @@ public class Comment2000 extends RecordContainer { 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) { @@ -97,7 +98,7 @@ public class Comment2000 extends RecordContainer { * 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) { @@ -124,18 +125,18 @@ public class Comment2000 extends RecordContainer { 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(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java index be8dc8dab8..ab38e88d1c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,7 +30,7 @@ import org.apache.poi.util.LittleEndian; * @author Daniel Noll */ -public class Comment2000Atom extends RecordAtom +public final class Comment2000Atom extends RecordAtom { /** * Record header. @@ -52,7 +51,7 @@ public class Comment2000Atom extends RecordAtom LittleEndian.putShort(_header, 2, (short)getRecordType()); LittleEndian.putInt(_header, 4, _data.length); - + // It is fine for the other values to be zero } @@ -67,7 +66,7 @@ public class Comment2000Atom extends RecordAtom // 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java index 3284153cb1..069d877a0a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -25,13 +23,13 @@ import java.io.IOException; 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; @@ -58,12 +56,12 @@ public class Document extends PositionDependentRecordContainer */ 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 @@ -74,9 +72,9 @@ public class Document extends PositionDependentRecordContainer /** * 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]; @@ -111,7 +109,7 @@ public class Document extends PositionDependentRecordContainer } - /** + /** * Set things up, and find our more interesting children */ protected Document(byte[] source, int start, int len) { @@ -146,7 +144,7 @@ public class Document extends PositionDependentRecordContainer 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 @@ -156,7 +154,7 @@ public class Document extends PositionDependentRecordContainer 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; @@ -167,22 +165,22 @@ public class Document extends PositionDependentRecordContainer } } } - + /** - * 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]; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java index 86bf5ce14e..3b28ab56a5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -30,7 +28,7 @@ import java.io.OutputStream; * @author Nick Burch */ -public class DocumentAtom extends RecordAtom +public final class DocumentAtom extends RecordAtom { private byte[] _header; private static long _type = 1001l; @@ -96,7 +94,7 @@ public class DocumentAtom extends RecordAtom /* *************** record code follows ********************** */ - /** + /** * For the Document Atom */ protected DocumentAtom(byte[] source, int start, int len) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java index 78e845af29..bf7860454a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -32,7 +30,7 @@ import java.io.OutputStream; * @author Nick Burch */ -public class DocumentEncryptionAtom extends RecordAtom +public final class DocumentEncryptionAtom extends RecordAtom { private byte[] _header; private static long _type = 12052l; @@ -40,7 +38,7 @@ public class DocumentEncryptionAtom extends RecordAtom private byte[] data; private String encryptionProviderName; - /** + /** * For the Document Encryption Atom */ protected DocumentEncryptionAtom(byte[] source, int start, int len) { @@ -67,21 +65,21 @@ public class DocumentEncryptionAtom extends RecordAtom 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java b/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java index c41ce6b80a..285f824b43 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -35,12 +33,12 @@ import java.io.OutputStream; * @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 */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java b/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java index d5dfcb41eb..18dea58923 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,12 +29,12 @@ import java.io.OutputStream; * @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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java b/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java index e17fe12600..eb66f2a288 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -23,12 +21,12 @@ import java.io.IOException; 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; @@ -44,7 +42,7 @@ public class Environment extends PositionDependentRecordContainer public FontCollection getFontCollection() { return fontCollection; } - /** + /** * Set things up, and find our more interesting children */ protected Environment(byte[] source, int start, int len) { @@ -54,7 +52,7 @@ public class Environment extends PositionDependentRecordContainer // 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) { @@ -63,7 +61,7 @@ public class Environment extends PositionDependentRecordContainer txmaster = (TxMasterStyleAtom)_children[i]; } } - + if(fontCollection == null) { throw new IllegalStateException("Environment didn't contain a FontCollection record!"); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java b/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java index 142eee88fc..8476d3dd56 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -26,7 +24,7 @@ import java.io.OutputStream; 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 @@ -35,7 +33,7 @@ import java.io.ByteArrayOutputStream; * @author Nick Burch */ -public class EscherTextboxWrapper extends RecordContainer +public final class EscherTextboxWrapper extends RecordContainer { private EscherTextboxRecord _escherRecord; private long _type; @@ -46,7 +44,7 @@ public class EscherTextboxWrapper extends RecordContainer */ public EscherTextboxRecord getEscherRecord() { return _escherRecord; } - /** + /** * Creates the wrapper for the given DDF Escher Record and children */ public EscherTextboxWrapper(EscherTextboxRecord textbox) { @@ -57,7 +55,7 @@ public class EscherTextboxWrapper extends RecordContainer byte[] data = _escherRecord.getData(); _children = Record.findChildRecords(data,0,data.length); } - + /** * Creates a new, empty wrapper for DDF Escher Records and their children */ @@ -68,7 +66,7 @@ public class EscherTextboxWrapper extends RecordContainer _children = new Record[0]; } - + /** * Return the type of the escher record (normally in the 0xFnnn range) diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExAviMovie.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExAviMovie.java index 81ad98d9b7..5d09e53a19 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExAviMovie.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExAviMovie.java @@ -1,53 +1,54 @@ -/* -* 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 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; - } - -} +/* ==================================================================== + 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; + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExControl.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExControl.java index 603cbad764..7df5a903db 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExControl.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExControl.java @@ -1,82 +1,82 @@ -/* ==================================================================== - 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: - *

- * 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 - *

- * - * - * @author Yegor kozlov - */ -public 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; - } -} +/* ==================================================================== + 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: + *

+ * 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 + *

+ * + * + * @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; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java index 0204803ea5..951b5759eb 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java @@ -1,117 +1,117 @@ -/* ==================================================================== - 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 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. - *

- * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record. - * The value 0x00000000 specifies a null reference. - *

- * - * @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 - *

- * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record. - * The value 0x00000000 specifies a null reference. - *

- */ - 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); - } - -} +/* ==================================================================== + 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. + *

+ * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record. + * The value 0x00000000 specifies a null reference. + *

+ * + * @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 + *

+ * It MUST be 0x00000000 or equal to the value of the slideId field of a SlidePersistAtom record. + * The value 0x00000000 specifies a null reference. + *

+ */ + 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); + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java index c22609206d..7d24175879 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java @@ -1,100 +1,101 @@ -/* -* 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 { - 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; } - - -} +/* ==================================================================== + 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; } + + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java index e80768f30f..ee38bece75 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java @@ -1,172 +1,171 @@ -/* ==================================================================== - 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 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(); - } - -} +/* ==================================================================== + 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(); + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java index 36f9fda1ab..473201f26c 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java @@ -1,108 +1,109 @@ -/* -* 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 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; } - -} +/* ==================================================================== + 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; } + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java index c0d55ac0ee..be6cdde42c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -30,7 +29,7 @@ import java.util.*; * @author Yegor Kozlov */ -public class FontCollection extends RecordContainer { +public final class FontCollection extends RecordContainer { private List fonts; private byte[] _header; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java index 76cb4c264b..54284e028f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -34,7 +32,7 @@ import java.io.UnsupportedEncodingException; * @author Yegor Kozlov */ -public class FontEntityAtom extends RecordAtom { +public final class FontEntityAtom extends RecordAtom { /** * record header */ @@ -75,7 +73,7 @@ public class FontEntityAtom extends RecordAtom { /** * 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 */ @@ -99,7 +97,7 @@ public class FontEntityAtom extends RecordAtom { /** * 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java index 1c90b95960..b9006051dd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java @@ -1,213 +1,211 @@ - -/* ==================================================================== - 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 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 HeadersFootersAtom 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 HeadersFootersAtom - */ - 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. - *

- * It MUST be in the range [0, 12].
- * 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. - * - * - * @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 - * - *

  • A - {@link #fHasDate} (1 bit): A bit that specifies whether the date is displayed in the footer. - *
  • B - {@link #fHasTodayDate} (1 bit): A bit that specifies whether the current datetime is used for - * displaying the datetime. - *
  • C - {@link #fHasUserDate} (1 bit): A bit that specifies whether the date specified in UserDateAtom record - * is used for displaying the datetime. - *
  • D - {@link #fHasSlideNumber} (1 bit): A bit that specifies whether the slide number is displayed in the footer. - *
  • E - {@link #fHasHeader} (1 bit): A bit that specifies whether the header text specified by HeaderAtom - * record is displayed. - *
  • F - {@link #fHasFooter} (1 bit): A bit that specifies whether the footer text specified by FooterAtom - * record is displayed. - *
  • 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(); - } -} +/* ==================================================================== + 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 HeadersFootersAtom 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 HeadersFootersAtom + */ + 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. + *

    + * It MUST be in the range [0, 12].
    + * 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. + * + * + * @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 + * + *

  • A - {@link #fHasDate} (1 bit): A bit that specifies whether the date is displayed in the footer. + *
  • B - {@link #fHasTodayDate} (1 bit): A bit that specifies whether the current datetime is used for + * displaying the datetime. + *
  • C - {@link #fHasUserDate} (1 bit): A bit that specifies whether the date specified in UserDateAtom record + * is used for displaying the datetime. + *
  • D - {@link #fHasSlideNumber} (1 bit): A bit that specifies whether the slide number is displayed in the footer. + *
  • E - {@link #fHasHeader} (1 bit): A bit that specifies whether the header text specified by HeaderAtom + * record is displayed. + *
  • F - {@link #fHasFooter} (1 bit): A bit that specifies whether the footer text specified by FooterAtom + * record is displayed. + *
  • 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(); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java index e121574bc1..9f2a0eecd7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java @@ -1,212 +1,211 @@ - -/* ==================================================================== - 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. - *

    - * It contains:
    - *

  • 1. {@link HeadersFootersAtom} - *
  • 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. - *
  • 3. {@link CString }, Instance Header (1), optional: Stores the Header's contents. - *
  • 4. {@link CString }, Instance Footer (2), optional: Stores the Footer's contents. - *

    - * - * @author Yegor Kozlov - */ -public 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 {@link RecordTypes#HeadersFooters} - */ - 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 HeadersFootersAtom - */ - public HeadersFootersAtom getHeadersFootersAtom(){ - return hdAtom; - } - - /** - * A {@link CString} record that stores the user's date. - *

    This is the date that the user wants in the footers, instead of today's date.

    - * - * @return A {@link CString} record that stores the user's date or null - */ - 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 null - */ - 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 null - */ - 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 + 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. + *

    + * It contains:
    + *

  • 1. {@link HeadersFootersAtom} + *
  • 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. + *
  • 3. {@link CString }, Instance Header (1), optional: Stores the Header's contents. + *
  • 4. {@link CString }, Instance Footer (2), optional: Stores the Footer's contents. + *

    + * + * @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 {@link RecordTypes#HeadersFooters} + */ + 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 HeadersFootersAtom + */ + public HeadersFootersAtom getHeadersFootersAtom(){ + return hdAtom; + } + + /** + * A {@link CString} record that stores the user's date. + *

    This is the date that the user wants in the footers, instead of today's date.

    + * + * @return A {@link CString} record that stores the user's date or null + */ + 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 null + */ + 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 null + */ + 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; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java index 2915040e18..0c1f02b389 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,7 +29,7 @@ import org.apache.poi.util.LittleEndian; * @author Yegor Kozlov */ -public class MainMaster extends SheetContainer +public final class MainMaster extends SheetContainer { private byte[] _header; private static long _type = 1016; @@ -49,7 +47,7 @@ public class MainMaster extends SheetContainer 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; } @@ -58,7 +56,7 @@ public class MainMaster extends SheetContainer public ColorSchemeAtom[] getColorSchemeAtoms() { return clrscheme; } - /** + /** * Set things up, and find our more interesting children */ protected MainMaster(byte[] source, int start, int len) { @@ -96,7 +94,7 @@ public class MainMaster extends SheetContainer * We are of type 1016 */ public long getRecordType() { return _type; } - + /** * Write the contents of the record back, so it can be written * to disk @@ -108,5 +106,5 @@ public class MainMaster extends SheetContainer public ColorSchemeAtom getColorScheme(){ return _colorScheme; } - + } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java b/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java index 4c66e12ada..80ee6039f1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -29,7 +27,7 @@ import java.io.OutputStream; * @author Nick Burch */ -public class Notes extends SheetContainer +public final class Notes extends SheetContainer { private byte[] _header; private static long _type = 1008l; @@ -44,13 +42,13 @@ public class Notes extends SheetContainer */ 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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java index 3c88c1f2bb..bf4c5fe1a9 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -30,7 +28,7 @@ import java.io.OutputStream; * @author Nick Burch */ -public class NotesAtom extends RecordAtom +public final class NotesAtom extends RecordAtom { private byte[] _header; private static long _type = 1009l; @@ -55,7 +53,7 @@ public class NotesAtom extends RecordAtom /* *************** record code follows ********************** */ - /** + /** * For the Notes Atom */ protected NotesAtom(byte[] source, int start, int len) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java index 9bfae4fccb..1d8d7df62f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -32,7 +30,7 @@ import java.io.OutputStream; * @author Yegor Kozlov */ -public class OEPlaceholderAtom extends RecordAtom{ +public final class OEPlaceholderAtom extends RecordAtom{ /** * The full size of the master body text placeholder shape. @@ -109,7 +107,7 @@ public class OEPlaceholderAtom extends RecordAtom{ 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; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/OEShapeAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/OEShapeAtom.java index 4a319c2c41..f0975a152e 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/OEShapeAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/OEShapeAtom.java @@ -1,110 +1,109 @@ -/* ==================================================================== - 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 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); - } -} +/* ==================================================================== + 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java index 51ec016690..e44b360a58 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java @@ -14,6 +14,7 @@ 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; @@ -35,7 +36,7 @@ import java.io.IOException; * @author Yegor Kozlov */ -public class OutlineTextRefAtom extends RecordAtom { +public final class OutlineTextRefAtom extends RecordAtom { /** * record header */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java index 1705a8cede..519154c5b5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -36,7 +34,7 @@ import java.util.Iterator; * 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 @@ -46,7 +44,7 @@ import java.util.Iterator; // 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; @@ -70,7 +68,7 @@ public class PPDrawing extends RecordAtom /* ******************** record stuff follows ********************** */ - /** + /** * Sets everything up, groks the escher etc */ protected PPDrawing(byte[] source, int start, int len) { @@ -104,7 +102,7 @@ public class PPDrawing extends RecordAtom textboxWrappers[i] = (EscherTextboxWrapper)textboxes.get(i); } } - + /** * Creates a new, empty, PPDrawing (typically for use with a new Slide * or Notes) @@ -114,12 +112,12 @@ public class PPDrawing extends RecordAtom 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) { @@ -143,7 +141,7 @@ public class PPDrawing extends RecordAtom * 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()); @@ -156,7 +154,7 @@ public class PPDrawing extends RecordAtom } } - /** + /** * Look for EscherTextboxRecords */ private void findEscherTextboxRecord(EscherRecord[] toSearch, Vector found) { @@ -189,7 +187,7 @@ public class PPDrawing extends RecordAtom */ public long getRecordType() { return _type; } - /** + /** * We're pretending to be an atom, so return null */ public Record[] getChildRecords() { return null; } @@ -245,11 +243,11 @@ public class PPDrawing extends RecordAtom 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); @@ -287,14 +285,14 @@ public class PPDrawing extends RecordAtom dgContainer }; } - + /** * Add a new EscherTextboxWrapper to this PPDrawing. */ 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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java index a9ccd7071d..08d523c3e1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java @@ -1,19 +1,20 @@ -/* -* 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.*; @@ -28,12 +29,12 @@ import java.util.Iterator; /** * 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; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ParentAwareRecord.java b/src/scratchpad/src/org/apache/poi/hslf/record/ParentAwareRecord.java index e46e5837bf..c71699f35b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ParentAwareRecord.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ParentAwareRecord.java @@ -1,25 +1,26 @@ -/* -* 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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java index 68b8b7cafe..4a32d76e0b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -39,13 +37,13 @@ import java.util.Hashtable; * @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 @@ -82,7 +80,7 @@ public class PersistPtrHolder extends PositionDependentRecordAtom } /** * 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; @@ -102,7 +100,7 @@ public class PersistPtrHolder extends PositionDependentRecordAtom // 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 @@ -122,7 +120,7 @@ public class PersistPtrHolder extends PositionDependentRecordAtom LittleEndian.putInt(_header,4,newPtrData.length); } - /** + /** * Create a new holder for a PersistPtr record */ protected PersistPtrHolder(byte[] source, int start, int len) { @@ -181,7 +179,7 @@ public class PersistPtrHolder extends PositionDependentRecordAtom /** * At write-out time, update the references to the sheets to their - * new positions + * new positions */ public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) { int[] slideIDs = getKnownSlideIDs(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistRecord.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistRecord.java index 8238d10fb9..339331865c 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistRecord.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistRecord.java @@ -1,37 +1,36 @@ - -/* ==================================================================== - 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 + 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); +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecord.java b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecord.java index dbcbaa75bd..d32f330736 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecord.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; import java.util.Hashtable; @@ -39,14 +37,14 @@ public interface PositionDependentRecord /** 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordAtom.java index fa9b9cb1ca..adec35908a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; import java.util.Hashtable; @@ -36,16 +34,16 @@ public abstract class PositionDependentRecordAtom extends RecordAtom implements /** 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java index d33359bd4f..652c6d860e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,14 +14,13 @@ 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 @@ -31,7 +29,7 @@ import java.util.Hashtable; 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 @@ -43,18 +41,18 @@ public abstract class PositionDependentRecordContainer extends RecordContainer i */ 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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index 46cb7479e2..62dd11ffd4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.record; @@ -53,10 +50,10 @@ public abstract class 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(); @@ -65,7 +62,7 @@ public abstract class Record * 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; @@ -86,7 +83,7 @@ public abstract class Record 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 @@ -171,7 +168,7 @@ public abstract class Record 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordAtom.java index fbc2a7c211..964d3d1c45 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -27,12 +25,12 @@ 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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java index 0772e03121..9450e6986e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -38,18 +36,18 @@ public abstract class RecordContainer extends 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 * =============================================================== @@ -59,7 +57,7 @@ public abstract class RecordContainer extends Record * 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++) { @@ -67,10 +65,10 @@ public abstract class RecordContainer extends Record return i; } } - } + } return -1; } - + /** * Adds a child record, at the very end. * @param newChild The child record to add @@ -85,7 +83,7 @@ public abstract class RecordContainer extends Record _children = nc; } } - + /** * Adds the given new Child Record at the given location, * shuffling everything from there on down by one @@ -96,12 +94,12 @@ public abstract class RecordContainer extends Record 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 number child records from oldLoc * to newLoc. Caller must have the changingChildRecordsLock @@ -112,17 +110,17 @@ public abstract class RecordContainer extends Record 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 @@ -136,7 +134,7 @@ public abstract class RecordContainer extends Record } return null; } - + /* =============================================================== * External Move Methods * =============================================================== @@ -150,7 +148,7 @@ public abstract class RecordContainer extends Record appendChild(newChild); } } - + /** * Adds the given Child Record after the supplied record * @param newChild @@ -163,12 +161,12 @@ public abstract class RecordContainer extends Record 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 @@ -181,49 +179,49 @@ public abstract class RecordContainer extends Record 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); @@ -232,20 +230,20 @@ public abstract class RecordContainer extends Record } // 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 */ @@ -269,7 +267,7 @@ public abstract class RecordContainer extends Record 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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java index 7fb46e4fd1..9532805a8b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java @@ -30,7 +30,7 @@ import java.lang.reflect.Field; * @author Yegor Kozlov * @author Nick Burch */ -public class RecordTypes { +public final class RecordTypes { public static HashMap typeToName; public static HashMap typeToClass; @@ -152,14 +152,14 @@ public class RecordTypes { 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); @@ -265,7 +265,7 @@ public class RecordTypes { } - /** + /** * 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. diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java b/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java index 0f49b5bd03..26b9e95f17 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java @@ -1,99 +1,98 @@ -/* ==================================================================== - 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 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); - } -} \ 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SheetContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/SheetContainer.java index 1f0ece6014..08c05c46af 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SheetContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SheetContainer.java @@ -1,32 +1,33 @@ -/* -* 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 + 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(); + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java index 26bdfc8046..a833c4016a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,7 +29,7 @@ import org.apache.poi.util.LittleEndian; * @author Nick Burch */ -public class Slide extends SheetContainer +public final class Slide extends SheetContainer { private byte[] _header; private static long _type = 1006l; @@ -47,13 +45,13 @@ public class Slide extends SheetContainer 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) { @@ -105,7 +103,7 @@ public class Slide extends SheetContainer * We are of type 1006 */ public long getRecordType() { return _type; } - + /** * Write the contents of the record back, so it can be written * to disk diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java index 7e05bf8585..f759ed02c1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,7 +29,7 @@ import java.io.OutputStream; * @author Nick Burch */ -public class SlideAtom extends RecordAtom +public final class SlideAtom extends RecordAtom { private byte[] _header; private static long _type = 1007l; @@ -50,7 +48,7 @@ public class SlideAtom extends RecordAtom /** 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; } @@ -70,7 +68,7 @@ public class SlideAtom extends RecordAtom /* *************** record code follows ********************** */ - /** + /** * For the Slide Atom */ protected SlideAtom(byte[] source, int start, int len) { @@ -114,7 +112,7 @@ public class SlideAtom extends RecordAtom reserved = new byte[len-30]; System.arraycopy(source,start+30,reserved,0,reserved.length); } - + /** * Create a new SlideAtom, to go with a new Slide */ @@ -123,7 +121,7 @@ public class SlideAtom extends RecordAtom 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); @@ -172,7 +170,7 @@ public class SlideAtom extends RecordAtom * 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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java index 03f5778139..11bd4752c7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -48,7 +46,7 @@ import java.util.Vector; */ // For now, pretend to be an atom -public class SlideListWithText extends RecordContainer +public final class SlideListWithText extends RecordContainer { /** @@ -72,7 +70,7 @@ public class SlideListWithText extends RecordContainer private SlideAtomsSet[] slideAtomsSets; - /** + /** * Create a new holder for slide records */ protected SlideListWithText(byte[] source, int start, int len) { @@ -81,10 +79,10 @@ public class SlideListWithText extends RecordContainer 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++) { @@ -98,7 +96,7 @@ public class SlideListWithText extends RecordContainer 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]; @@ -127,11 +125,11 @@ public class SlideListWithText extends RecordContainer 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 @@ -184,7 +182,7 @@ public class SlideListWithText extends RecordContainer /** * 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. */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java index 2539bc5708..a567cff830 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -30,22 +28,22 @@ import java.io.OutputStream; * @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 */ @@ -55,7 +53,7 @@ public class SlidePersistAtom extends RecordAtom 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; @@ -66,7 +64,7 @@ public class SlidePersistAtom extends RecordAtom /* *************** record code follows ********************** */ - /** + /** * For the SlidePersist Atom */ protected SlidePersistAtom(byte[] source, int start, int len) { @@ -94,12 +92,12 @@ public class SlidePersistAtom extends RecordAtom // 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 */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java b/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java index 211a9b0ee4..f454e4d208 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java @@ -1,136 +1,137 @@ -/* ==================================================================== - 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: - *

    - *

  • 1. CString (4026), Instance 0: Name of sound (e.g. "crash") - *
  • 2. CString (4026), Instance 1: Type of sound (e.g. ".wav") - *
  • 3. CString (4026), Instance 2: Reference id of sound in sound collection - *
  • 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. - *
  • 5. SoundData (2023), optional - *

    - * - * @author Yegor Kozlov - */ -public 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(); - } -} +/* ==================================================================== + 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: + *

    + *

  • 1. CString (4026), Instance 0: Name of sound (e.g. "crash") + *
  • 2. CString (4026), Instance 1: Type of sound (e.g. ".wav") + *
  • 3. CString (4026), Instance 2: Reference id of sound in sound collection + *
  • 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. + *
  • 5. SoundData (2023), optional + *

    + * + * @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(); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java index c244859ea0..8d86b175e7 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java @@ -1,73 +1,74 @@ -/* ==================================================================== - 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: - *
  • 1. SoundCollAtom (2021) - *
  • 2. Sound (2022), for each sound, if any - * - * @author Yegor Kozlov - */ -public 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); - } -} +/* ==================================================================== + 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: + *
  • 1. SoundCollAtom (2021) + *
  • 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java b/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java index 42be48f2ac..6492d0175c 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java @@ -1,103 +1,103 @@ -/* ==================================================================== - 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 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 + 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 7f084d82e4..7e77c2f949 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -35,7 +33,7 @@ import org.apache.poi.util.POILogger; 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. @@ -51,7 +49,7 @@ import org.apache.poi.util.HexDump; * @author Yegor Kozlov */ -public class StyleTextPropAtom extends RecordAtom +public final class StyleTextPropAtom extends RecordAtom { private byte[] _header; private static long _type = 4001l; @@ -59,13 +57,13 @@ public class StyleTextPropAtom extends RecordAtom 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 @@ -78,10 +76,10 @@ public class StyleTextPropAtom extends RecordAtom * 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; @@ -91,7 +89,7 @@ public class StyleTextPropAtom extends RecordAtom * character stylings */ public void setCharacterStyles(LinkedList cs) { charStyles = cs; } - + /** * Returns how many characters the paragraph's * TextPropCollections cover. @@ -334,7 +332,7 @@ public class StyleTextPropAtom extends RecordAtom // Save this properties set charStyles.add(thisCollection); - + // Handle extra 1 char styles at the end if(pos < rawContents.length && textHandled == size) { chsize++; @@ -407,7 +405,7 @@ public class StyleTextPropAtom extends RecordAtom charStyles.add(tpc); return tpc; } - + /* ************************************************************************ */ @@ -418,14 +416,14 @@ public class StyleTextPropAtom extends RecordAtom */ 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()); @@ -435,9 +433,9 @@ public class StyleTextPropAtom extends RecordAtom 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); @@ -447,7 +445,7 @@ public class StyleTextPropAtom extends RecordAtom e.printStackTrace(); } } - + out.append("Character properties\n"); for (Iterator it1 = getCharacterStyles().iterator(); it1.hasNext();) { TextPropCollection pr = (TextPropCollection)it1.next(); @@ -458,9 +456,9 @@ public class StyleTextPropAtom extends RecordAtom 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); @@ -471,7 +469,7 @@ public class StyleTextPropAtom extends RecordAtom } } } - + out.append(" original byte stream \n"); out.append( HexDump.dump(rawContents, 0, 0) ); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java index 3e6cf2cbfd..b793613764 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -27,14 +25,14 @@ import java.io.OutputStream; /** * 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; @@ -43,12 +41,12 @@ public class TextBytesAtom extends RecordAtom 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; @@ -58,7 +56,7 @@ public class TextBytesAtom extends RecordAtom /* *************** record code follows ********************** */ - /** + /** * For the TextBytes Atom */ protected TextBytesAtom(byte[] source, int start, int len) { @@ -73,7 +71,7 @@ public class TextBytesAtom extends RecordAtom _text = new byte[len-8]; System.arraycopy(source,start+8,_text,0,len-8); } - + /** * Create an empty TextBytes Atom */ @@ -104,7 +102,7 @@ public class TextBytesAtom extends RecordAtom } /** - * 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() { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java index 0e751a73ad..e279af060d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -32,7 +30,7 @@ import java.io.OutputStream; * @author Nick Burch */ -public class TextCharsAtom extends RecordAtom +public final class TextCharsAtom extends RecordAtom { private byte[] _header; private static long _type = 4000l; @@ -41,7 +39,7 @@ public class TextCharsAtom extends RecordAtom private byte[] _text; /** Grabs the text. */ - public String getText() { + public String getText() { return StringUtil.getFromUnicodeLE(_text); } @@ -57,8 +55,8 @@ public class TextCharsAtom extends RecordAtom /* *************** record code follows ********************** */ - /** - * For the TextChars Atom + /** + * For the TextChars Atom */ protected TextCharsAtom(byte[] source, int start, int len) { // Sanity Checking @@ -98,9 +96,9 @@ public class TextCharsAtom extends RecordAtom // 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() { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java index 85ea29c42d..9931eb93b1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,7 +29,7 @@ import java.io.OutputStream; * @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; @@ -51,13 +49,13 @@ public class TextHeaderAtom extends RecordAtom implements ParentAwareRecord 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) { @@ -76,7 +74,7 @@ public class TextHeaderAtom extends RecordAtom implements ParentAwareRecord // Grab the type textType = (int)LittleEndian.getInt(source,start+8); } - + /** * Create a new TextHeader Atom, for an unknown type of text */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java index 0be988d51f..052126e127 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java @@ -1,209 +1,209 @@ -/* ==================================================================== - 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 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); - } -} +/* ==================================================================== + 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java index 85cdd1e156..f0e79761aa 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java @@ -1,200 +1,201 @@ -/* ==================================================================== - 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 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. - * - *

    Spell Info Types:

    - *
  • 0 Unchecked - *
  • 1 Previously incorrect, needs rechecking - *
  • 2 Correct - *
  • 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; - } - } -} +/* ==================================================================== + 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. + * + *

    Spell Info Types:

    + *
  • 0 Unchecked + *
  • 1 Previously incorrect, needs rechecking + *
  • 2 Correct + *
  • 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; + } + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java index e6a8279773..eb9dd8e0ca 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java @@ -1,122 +1,123 @@ -/* ==================================================================== - 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 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 + 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java index 05bf42c7b8..b262530c0d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -41,7 +40,7 @@ import org.apache.poi.hslf.model.textproperties.*; * * @author Yegor Kozlov */ -public class TxMasterStyleAtom extends RecordAtom { +public final class TxMasterStyleAtom extends RecordAtom { /** * Maximum number of indentatio levels allowed in PowerPoint documents @@ -116,7 +115,7 @@ public class TxMasterStyleAtom extends RecordAtom { * Must be a constant defined in TextHeaderAtom * * @return type of the text - * @see TextHeaderAtom + * @see TextHeaderAtom */ public int getTextType(){ //The atom instance value is the text type diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java b/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java index 5b8726a51e..6df2aa9198 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -31,12 +29,12 @@ import java.io.OutputStream; * @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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java index 60a647516b..97765c408b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.record; @@ -35,7 +33,7 @@ import java.util.Hashtable; * @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; @@ -72,7 +70,7 @@ public class UserEditAtom extends PositionDependentRecordAtom /* *************** record code follows ********************** */ - /** + /** * For the UserEdit Atom */ protected UserEditAtom(byte[] source, int start, int len) { @@ -90,12 +88,12 @@ public class UserEditAtom extends PositionDependentRecordAtom 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); @@ -105,7 +103,7 @@ public class UserEditAtom extends PositionDependentRecordAtom // 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java index d21d098c3e..635e0ea265 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java @@ -14,6 +14,7 @@ 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; @@ -234,7 +235,7 @@ public abstract class PictureData { * Register ImagePainter for the specified image type * * @param type image type, must be one of the static constants defined in the Picture class. - * @param painter + * @param painter */ public static void setImagePainter(int type, ImagePainter painter){ painters[type] = painter; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java index a4238b4738..da8093ecf4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -38,22 +35,22 @@ import org.apache.poi.util.POILogFactory; /** * 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. @@ -84,7 +81,7 @@ public class RichTextRun { * @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; @@ -97,8 +94,8 @@ public class RichTextRun { } /** - * 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) { @@ -119,7 +116,7 @@ public class RichTextRun { _fontname = null; } } - + /** * Get the length of the text */ @@ -157,7 +154,7 @@ public class RichTextRun { public String getRawText() { return parentRun.getRawText().substring(startPos, startPos+length); } - + /** * Change the text */ @@ -165,7 +162,7 @@ public class RichTextRun { String s = parentRun.normalize(text); setRawText(s); } - + /** * Change the text */ @@ -181,10 +178,10 @@ public class RichTextRun { 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 @@ -227,7 +224,7 @@ public class RichTextRun { /** * 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); @@ -268,11 +265,11 @@ public class RichTextRun { } 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) { @@ -315,7 +312,7 @@ public class RichTextRun { 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 @@ -327,7 +324,7 @@ public class RichTextRun { parentRun.ensureStyleAtomPresent(); // paragraphStyle will now be defined } - + TextProp tp = fetchOrAddTextProp(paragraphStyle, propName); tp.setValue(val); } @@ -342,12 +339,12 @@ public class RichTextRun { parentRun.ensureStyleAtomPresent(); // characterStyle will now be defined } - + TextProp tp = fetchOrAddTextProp(characterStyle, propName); tp.setValue(val); } - - + + // --------------- Friendly getters / setters on rich text properties ------- /** @@ -363,7 +360,7 @@ public class RichTextRun { public void setBold(boolean bold) { setCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX, bold); } - + /** * Is the text italic? */ @@ -377,7 +374,7 @@ public class RichTextRun { public void setItalic(boolean italic) { setCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX, italic); } - + /** * Is the text underlined? */ @@ -509,7 +506,7 @@ public class RichTextRun { return slideShow.getFontCollection().getFontWithId(fontIdx); } } - + /** * @return font color as RGB value * @see java.awt.Color @@ -529,13 +526,13 @@ public class RichTextRun { /** * 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 */ @@ -772,15 +769,15 @@ public class RichTextRun { 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; } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java index e5fbf12412..15650d0ad7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java @@ -49,7 +49,7 @@ import org.apache.poi.util.POILogger; * - 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 */ @@ -80,15 +80,15 @@ public final class SlideShow { // 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 @@ -97,7 +97,7 @@ public final class SlideShow { // 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]); @@ -105,11 +105,11 @@ public final class SlideShow { // 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. */ @@ -133,7 +133,7 @@ public final class SlideShow { if(baseRecord instanceof RecordContainer) { RecordContainer br = (RecordContainer)baseRecord; Record[] childRecords = br.getChildRecords(); - + // Loop over child records, looking for interesting ones for(int i=0; iSlide. diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java index ad7922ef61..cc084fa029 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java @@ -1,93 +1,94 @@ -/* ==================================================================== - 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 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 + 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()]); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/util/MutableByteArrayOutputStream.java b/src/scratchpad/src/org/apache/poi/hslf/util/MutableByteArrayOutputStream.java index 54e8569d71..be7c046027 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/util/MutableByteArrayOutputStream.java +++ b/src/scratchpad/src/org/apache/poi/hslf/util/MutableByteArrayOutputStream.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hslf.util; @@ -29,7 +27,7 @@ import java.io.ByteArrayOutputStream; * @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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java b/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java index 379b05bf6a..926a2f5645 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java +++ b/src/scratchpad/src/org/apache/poi/hslf/util/SystemTimeUtils.java @@ -26,7 +26,7 @@ import org.apache.poi.util.LittleEndian; /** * 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 @@ -36,7 +36,7 @@ import org.apache.poi.util.LittleEndian; * @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 */ @@ -48,10 +48,10 @@ public class SystemTimeUtils { */ 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)); @@ -61,17 +61,17 @@ public class SystemTimeUtils { 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(); diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java index 7eaca4f1b7..39162852e4 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java @@ -23,39 +23,39 @@ abstract public class Chunk { 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 diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java index af77badb3b..ae7e77b70d 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -20,10 +20,10 @@ package org.apache.poi.hsmf.datatypes; /** * 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) */ @@ -44,7 +44,7 @@ public class Chunks { 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); @@ -56,7 +56,7 @@ public class Chunks { conversationTopic = new StringChunk(0x0070, newStringType); sentByServerType = new StringChunk(0x0075, newStringType); } - + public static Chunks getInstance(boolean newStringType) { return new Chunks(newStringType); } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java index f4d675a05a..2949ba1908 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java @@ -17,18 +17,18 @@ 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) { diff --git a/src/scratchpad/src/org/apache/poi/hsmf/exceptions/ChunkNotFoundException.java b/src/scratchpad/src/org/apache/poi/hsmf/exceptions/ChunkNotFoundException.java index 5c04518cb4..e020884759 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/exceptions/ChunkNotFoundException.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/exceptions/ChunkNotFoundException.java @@ -17,7 +17,7 @@ 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) { diff --git a/src/scratchpad/src/org/apache/poi/hsmf/exceptions/DirectoryChunkNotFoundException.java b/src/scratchpad/src/org/apache/poi/hsmf/exceptions/DirectoryChunkNotFoundException.java index 308d0c6704..0c33901aee 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/exceptions/DirectoryChunkNotFoundException.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/exceptions/DirectoryChunkNotFoundException.java @@ -21,7 +21,7 @@ package org.apache.poi.hsmf.exceptions; * 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) { diff --git a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java index 8aa849fa2f..725659044c 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java +++ b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java @@ -45,13 +45,13 @@ import org.apache.poi.hssf.record.formula.Ptg; */ 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; } @@ -129,22 +129,22 @@ public final class HSSFChart { 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); @@ -174,7 +174,7 @@ public final class HSSFChart { } } } - + return (HSSFChart[]) charts.toArray( new HSSFChart[charts.size()] ); } @@ -196,7 +196,7 @@ public final class HSSFChart { 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 */ @@ -204,7 +204,7 @@ public final class HSSFChart { return (HSSFSeries[]) series.toArray(new HSSFSeries[series.size()]); } - + /** * Returns the chart's title, if there is one, * or null if not @@ -215,9 +215,9 @@ public final class HSSFChart { } 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 */ @@ -860,18 +860,18 @@ public final class HSSFChart { 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(); } @@ -881,7 +881,7 @@ public final class HSSFChart { public short getValueType() { return series.getValuesDataType(); } - + /** * Returns the series' title, if there is one, * or null if not @@ -892,9 +892,9 @@ public final class HSSFChart { } 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 */ diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index 9bc8354a73..a43852be8b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf; import java.io.InputStream; @@ -47,7 +46,7 @@ import org.apache.poi.hwpf.usermodel.*; * * @author Ryan Ackley */ -public class HWPFDocument extends POIDocument +public final class HWPFDocument extends POIDocument // implements Cloneable { /** The FIB */ @@ -93,13 +92,13 @@ public class HWPFDocument extends POIDocument /** 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; @@ -145,7 +144,7 @@ public class HWPFDocument extends POIDocument //do Ole stuff this( verifyAndBuildPOIFS(istream) ); } - + /** * This constructor loads a Word document from a POIFSFileSystem * @@ -157,7 +156,7 @@ public class HWPFDocument extends POIDocument { this(pfilesystem.getRoot(), pfilesystem); } - + /** * This constructor loads a Word document from a specific point * in a POIFSFileSystem, probably not the default. @@ -172,12 +171,12 @@ public class HWPFDocument extends POIDocument // 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 @@ -225,26 +224,26 @@ public class HWPFDocument extends POIDocument // 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()); @@ -252,7 +251,7 @@ public class HWPFDocument extends POIDocument { _dgg = new EscherRecordHolder(); } - + // read in the pictures stream _pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg); // And the art shapes stream @@ -303,7 +302,7 @@ public class HWPFDocument extends POIDocument { return _dop; } - + /** * Returns the range that covers all text in the * file, including main text, footnotes, headers @@ -325,35 +324,35 @@ public class HWPFDocument extends POIDocument // 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 ); } @@ -390,14 +389,14 @@ public class HWPFDocument extends POIDocument { 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 */ @@ -553,7 +552,7 @@ public class HWPFDocument extends POIDocument pfs.createDocument(new ByteArrayInputStream(tableBuf), "1Table"); pfs.createDocument(new ByteArrayInputStream(dataBuf), "Data"); writeProperties(pfs); - + pfs.writeFilesystem(out); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java b/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java index a9a7210e8a..5aba80c606 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,14 +14,14 @@ 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() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java b/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java index 8d14c3613a..8e7bcac90a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hwpf.dev; import java.io.FileInputStream; @@ -26,25 +27,25 @@ import org.apache.poi.hwpf.model.FileInformationBlock; * 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 "); 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()); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java index 816b2c1221..e63ad4f5a4 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -33,16 +34,16 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * 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 @@ -63,7 +64,7 @@ public class WordExtractor extends POIOLE2TextExtractor { this(new HWPFDocument(dir, fs)); this.fs = fs; } - + /** * Create a new Word Extractor * @param doc The HWPFDocument to extract from @@ -89,14 +90,14 @@ public class WordExtractor extends POIOLE2TextExtractor { 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(); @@ -105,7 +106,7 @@ public class WordExtractor extends POIOLE2TextExtractor { for(int i=0; i paragraph @@ -187,7 +188,7 @@ public class WordExtractor extends POIOLE2TextExtractor { */ public String getTextFromPieces() { StringBuffer textBuf = new StringBuffer(); - + Iterator textPieces = doc.getTextTable().getTextPieces().iterator(); while (textPieces.hasNext()) { TextPiece piece = (TextPiece) textPieces.next(); @@ -203,39 +204,39 @@ public class WordExtractor extends POIOLE2TextExtractor { 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 escherRecords; - + public EscherRecordHolder() { escherRecords = new ArrayList(); } - + 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(); @@ -54,11 +54,11 @@ public final class EscherRecordHolder { pos += bytesRead + 1; // There is an empty byte between each top-level record in a Word doc } } - + public List getEscherRecords() { return escherRecords; } - + public String toString() { StringBuffer buffer = new StringBuffer(); @@ -72,7 +72,7 @@ public final class EscherRecordHolder { } return buffer.toString(); } - + /** * If we have a EscherContainerRecord as one of our * children (and most top level escher holders do), @@ -104,7 +104,7 @@ public final class EscherRecordHolder { return r; } } - + // Then check our children in turn for(Iterator it = records.iterator(); it.hasNext();) { EscherRecord r = it.next(); @@ -115,7 +115,7 @@ public final class EscherRecordHolder { } } } - + // Not found in this lot return null; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java index b087978ab1..294cb88f2d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import java.util.HashSet; @@ -29,7 +28,7 @@ import org.apache.poi.util.LittleEndian; 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBLongHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBLongHandler.java index 8129daaed8..8d5967411c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBLongHandler.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBLongHandler.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import java.io.IOException; @@ -26,7 +25,7 @@ import org.apache.poi.util.LittleEndian; * 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java index e8c2b20afe..4de7e5a29d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import java.io.IOException; @@ -23,10 +22,10 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPA.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPA.java index bb3d5def1f..2f683589d1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPA.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPA.java @@ -23,10 +23,10 @@ import org.apache.poi.util.LittleEndian; /** * 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 @@ -44,11 +44,11 @@ public class FSPA 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); @@ -65,77 +65,77 @@ public class FSPA 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; @@ -158,7 +158,7 @@ public class FSPA return buf; } - + public String toString() { StringBuffer buf = new StringBuffer(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java index 812ab1a4a7..5f25e8bb59 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java @@ -25,33 +25,33 @@ import java.util.Map; /** * 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)); @@ -60,14 +60,14 @@ public final class FSPATable } 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(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java index 72f3de9925..b3ddb356c1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -31,7 +29,7 @@ import java.util.Arrays; * * @author Praveen Mathew */ -public class Ffn +public final class Ffn { private int _cbFfnM1;//total length of FFN - 1. private byte _info; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java index d6e2ac30d4..5bf14adf6b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,13 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index 22952735e4..01b95354b3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -31,7 +29,7 @@ import org.apache.poi.hwpf.model.types.FIBAbstractType; * 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 @@ -40,10 +38,10 @@ import org.apache.poi.hwpf.model.types.FIBAbstractType; * 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 { @@ -321,8 +319,8 @@ public class FileInformationBlock extends FIBAbstractType { _fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh); } - - + + /** * How many bytes of the main stream contain real data. */ @@ -331,7 +329,7 @@ public class FileInformationBlock extends FIBAbstractType } /** * 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); @@ -431,7 +429,7 @@ public class FileInformationBlock extends FIBAbstractType _longHandler.setLong(FIBLongHandler.CCPHDRTXBX, ccpTxtBx); } - + public void clearOffsetsSizes() { _fieldHandler.clearFields(); @@ -446,22 +444,22 @@ public class FileInformationBlock extends FIBAbstractType { 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); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java index a06b15634f..2073be4bf9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -32,7 +30,7 @@ import org.apache.poi.util.LittleEndian; * * @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 diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FormattedDiskPage.java index 5eb094d969..bbb56f5b15 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FormattedDiskPage.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/GenericPropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/GenericPropertyNode.java index ff56d7fc91..28c380383f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/GenericPropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/GenericPropertyNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,10 +14,10 @@ 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) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/HDFType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/HDFType.java index af72559ced..b1791132ec 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/HDFType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/HDFType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,12 +14,6 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java index ac2ece86da..e9ab368b3a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -25,7 +23,7 @@ import org.apache.poi.util.LittleEndian; import java.util.Arrays; -public class ListData +public final class ListData { private int _lsid; private int _tplc; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverride.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverride.java index 2c6c7285cc..bd5c123583 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverride.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverride.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -23,7 +21,7 @@ import org.apache.poi.util.LittleEndian; import java.util.Arrays; -public class ListFormatOverride +public final class ListFormatOverride { int _lsid; int _reserved1; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java index 9706c0a474..ceb59167d4 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListFormatOverrideLevel.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -25,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory; import java.util.Arrays; -public class ListFormatOverrideLevel +public final class ListFormatOverrideLevel { private static final int BASE_SIZE = 8; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java index f6b4d8594f..de8e7afccd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java @@ -23,7 +23,7 @@ import org.apache.poi.util.BitField; import org.apache.poi.util.LittleEndian; /** - * + * */ public final class ListLevel { @@ -90,7 +90,7 @@ 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; @@ -108,7 +108,7 @@ public final class ListLevel 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) @@ -241,7 +241,7 @@ public final class ListLevel 6 // int byte byte + RGBXCH_NUMS_SIZE + 13 // byte int int byte byte short - + _cbGrpprlChpx + + _cbGrpprlChpx + _cbGrpprlPapx + 2; // numberText length if (_numberText != null) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java index 4196566d9a..4bc8e74d5c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; import org.apache.poi.util.LittleEndian; @@ -35,7 +34,7 @@ import java.io.IOException; /** * @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; @@ -196,7 +195,7 @@ public class ListTables 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; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index ed47b59c59..66446dfaa1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -34,7 +34,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class PAPBinTable +public final class PAPBinTable { protected ArrayList _paragraphs = new ArrayList(); byte[] _dataStream; @@ -77,13 +77,13 @@ public class PAPBinTable 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); @@ -102,7 +102,7 @@ public class PAPBinTable { exc.printStackTrace(); } - + // Copy the properties of the one before to afterwards // Will go: // Original, until insert at point @@ -112,7 +112,7 @@ public class PAPBinTable // Again ensure contains character based offsets no matter what clone.setStart(cpStart); clone.setEnd(currentPap.getEnd()); - + currentPap.setEnd(cpStart); _paragraphs.add(listIndex + 1, forInsert); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java index 1a9a7bad59..ab7f8155bf 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -41,7 +40,7 @@ import java.util.Arrays; * * @author Ryan Ackley */ -public class PAPFormattedDiskPage extends FormattedDiskPage +public final class PAPFormattedDiskPage extends FormattedDiskPage { private static final int BX_SIZE = 13; @@ -69,7 +68,7 @@ public class PAPFormattedDiskPage extends FormattedDiskPage 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java index 1e8ae86b52..73c1c8edd7 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model; @@ -30,15 +27,15 @@ import org.apache.poi.hwpf.sprm.SprmOperation; /** * 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java index ea24fe4d59..698dba32f6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model; @@ -27,7 +24,7 @@ import org.apache.poi.util.BitField; 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); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java index 5aeb788e95..d61d7f64dd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; import org.apache.poi.util.LittleEndian; @@ -50,7 +49,7 @@ import org.apache.poi.ddf.EscherRecordFactory; * * @author Dmitry Romanov */ -public class PicturesTable +public final class PicturesTable { static final int TYPE_IMAGE = 0x08; static final int TYPE_IMAGE_WORD2000 = 0x00; @@ -72,7 +71,7 @@ public class PicturesTable /** * - * @param _document + * @param _document * @param _dataStream */ public PicturesTable(HWPFDocument _document, byte[] _dataStream, byte[] _mainStream, FSPATable fspa, EscherRecordHolder dgg) @@ -94,7 +93,7 @@ public class PicturesTable } return false; } - + public boolean hasEscherPicture(CharacterRun run) { if (run.isSpecialCharacter() && !run.isObj() && !run.isOle2() && !run.isData() && run.text().startsWith("\u0008")) { return true; @@ -132,7 +131,7 @@ public class PicturesTable * 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)) { @@ -140,7 +139,7 @@ public class PicturesTable } return null; } - + /** * Performs a recursive search for pictures in the given list of escher records. * @@ -184,12 +183,12 @@ public class PicturesTable /** * 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); @@ -199,7 +198,7 @@ public class PicturesTable pictures.add(picture); } } - + searchForPictures(_dgg.getEscherRecords(), pictures); return pictures; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java index ab4ee578f4..2af7b7a6f3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PieceDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model; @@ -24,7 +21,7 @@ import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.LittleEndian; -public class PieceDescriptor +public final class PieceDescriptor { short descriptor; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java index c0df0e8f8f..fe458608a0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import java.util.ArrayList; @@ -31,7 +30,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class PlexOfCps +public final class PlexOfCps { private int _count; private int _offset; @@ -56,7 +55,7 @@ public class PlexOfCps { // Figure out the number we hold _count = (size - 4)/(4 + sizeOfStruct); - + _sizeOfStruct = sizeOfStruct; _props = new ArrayList(_count); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java index 5a14917962..c9b5fb9a73 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import java.util.Arrays; @@ -48,7 +47,7 @@ public abstract class PropertyNode implements Comparable, Cloneable _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; @@ -92,7 +91,7 @@ public abstract class PropertyNode implements Comparable, Cloneable 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java index 7987280ed1..7095f0dcf5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model; @@ -26,7 +23,7 @@ import org.apache.poi.hwpf.usermodel.SectionProperties; /** */ -public class SEPX extends BytePropertyNode +public final class SEPX extends BytePropertyNode { SectionDescriptor _sed; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByEntry.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByEntry.java index a94deaa6fe..f4dc3e00ed 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByEntry.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByEntry.java @@ -15,16 +15,15 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByTable.java index b11b73fe19..f7ffc81db8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SavedByTable.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; import java.io.IOException; @@ -31,10 +30,10 @@ import org.apache.poi.hwpf.model.io.HWPFOutputStream; /** * 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. diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java index 9c5bc08c11..d4a5ef238d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,14 +14,12 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index b88edbb95e..2b15808c29 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -27,7 +27,7 @@ import org.apache.poi.hwpf.model.io.*; /** * @author Ryan Ackley */ -public class SectionTable +public final class SectionTable { private static final int SED_SIZE = 12; @@ -60,7 +60,7 @@ public class SectionTable 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); @@ -79,7 +79,7 @@ public class SectionTable _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... @@ -99,7 +99,7 @@ public class SectionTable 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()) ); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ShapesTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ShapesTable.java index 998ea2d8fe..426a24dfec 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ShapesTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ShapesTable.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.poi.hwpf.usermodel.Shape; -public class ShapesTable { +public final class ShapesTable { private List _shapes; private List _shapesVisibili; //holds visible shapes diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java index 3f81953c99..26e3ac43a3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model; @@ -34,7 +31,7 @@ import org.apache.poi.util.BitFieldFactory; * @author Ryan Ackley */ -public class StyleDescription implements HDFType +public final class StyleDescription implements HDFType { private final static int PARAGRAPH_STYLE = 1; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index b23533de34..e8a1610739 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model; @@ -39,7 +36,7 @@ import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor; * @author Ryan Ackley */ -public class StyleSheet implements HDFType +public final class StyleSheet implements HDFType { public static final int NIL_STYLE = 4095; @@ -231,7 +228,7 @@ public class StyleSheet implements HDFType { parentPAP = _styleDescriptions[baseIndex].getPAP(); - if(parentPAP == null) + if(parentPAP == null) { if(baseIndex == istd) { // Oh dear, style claims that it is its own parent diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java index 57cd9099ee..d7bb2984b5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -29,7 +28,7 @@ import java.io.UnsupportedEncodingException; * @author Ryan Ackley */ -public class TextPiece extends PropertyNode implements Comparable +public final class TextPiece extends PropertyNode implements Comparable { private boolean _usesUnicode; @@ -44,7 +43,7 @@ public class TextPiece extends PropertyNode implements Comparable super(start, end, buildInitSB(text, pd)); _usesUnicode = pd.isUnicode(); _pd = pd; - + // Validate int textLength = ((StringBuffer)_buf).length(); if(end-start != textLength) { @@ -54,7 +53,7 @@ public class TextPiece extends PropertyNode implements Comparable throw new IllegalStateException("Told we're of negative size! start="+start + " end="+end); } } - + /** * Create the StringBuffer from the text and unicode flag */ @@ -71,7 +70,7 @@ public class TextPiece extends PropertyNode implements Comparable } return new StringBuffer(str); } - + /** * @return If this text piece is unicode */ @@ -101,7 +100,7 @@ public class TextPiece extends PropertyNode implements Comparable } /** - * 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 @@ -109,7 +108,7 @@ public class TextPiece extends PropertyNode implements Comparable 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); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index f13e6ecd17..69e1f0ba79 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -38,7 +37,7 @@ import java.util.List; * convertion. * @author Ryan Ackley */ -public class TextPieceTable +public final class TextPieceTable { protected ArrayList _textPieces = new ArrayList(); //int _multiple; @@ -65,7 +64,7 @@ public class TextPieceTable 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; @@ -82,18 +81,18 @@ public class TextPieceTable { 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; @@ -105,7 +104,7 @@ public class TextPieceTable // 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[]) @@ -125,18 +124,18 @@ public class TextPieceTable { 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(); @@ -147,14 +146,14 @@ public class TextPieceTable // 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 @@ -162,12 +161,12 @@ public class TextPieceTable 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(); @@ -177,7 +176,7 @@ public class TextPieceTable // Move along curByte = nextByte; } - + // If they ask off the end, just go with the last one... return lastWas; } @@ -234,10 +233,10 @@ public class TextPieceTable 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++) { @@ -245,7 +244,7 @@ public class TextPieceTable tp.setStart(tp.getStart() + length); tp.setEnd(tp.getEnd() + length); } - + // All done return length; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java index 734577a268..736d66ec87 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,12 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/UnhandledDataStructure.java b/src/scratchpad/src/org/apache/poi/hwpf/model/UnhandledDataStructure.java index b0bb5f72b0..46989804a5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/UnhandledDataStructure.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/UnhandledDataStructure.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,10 +14,10 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java b/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java index c4721b840f..eb76f503c8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFFileSystem.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,13 @@ 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(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFOutputStream.java b/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFOutputStream.java index e9fab43ab6..537576ff99 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFOutputStream.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/io/HWPFOutputStream.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,12 +14,12 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java index d0fc1236cf..fad6c7e462 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; @@ -818,569 +815,569 @@ public abstract class CHPAbstractType /** * 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); - + } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java index 9441f8bb85..9f7b04c95a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; @@ -1430,1934 +1427,1934 @@ public abstract class DOPAbstractType /** * 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); - + } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java index 63961b4552..554d342ace 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/PAPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/PAPAbstractType.java index b14882c9df..70460caaca 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/PAPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/PAPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; @@ -1253,65 +1250,65 @@ public abstract class PAPAbstractType /** * 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); - + } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/SEPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/SEPAbstractType.java index b05a5d7ce3..d1548f73b8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/SEPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/SEPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TAPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TAPAbstractType.java index 8ed88a18b3..f1de3e114b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TAPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TAPAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java index 016907a8a0..e7b97ee4ff 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.model.types; @@ -228,170 +225,170 @@ public abstract class TCAbstractType /** * 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); - + } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java index a6ee4e6d8c..2938df8ab6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -26,7 +24,7 @@ import java.util.Arrays; import org.apache.poi.hwpf.usermodel.CharacterProperties; import org.apache.poi.util.LittleEndian; -public class CharacterSprmCompressor +public final class CharacterSprmCompressor { public CharacterSprmCompressor() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java index c49ac1b9e2..aa98920966 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -26,7 +24,7 @@ import org.apache.poi.hwpf.usermodel.ShadingDescriptor; import org.apache.poi.hwpf.model.StyleSheet; import org.apache.poi.util.LittleEndian; -public class CharacterSprmUncompressor +public final class CharacterSprmUncompressor { public CharacterSprmUncompressor() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java index de2c23994a..c3e48d5226 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -27,7 +25,7 @@ import org.apache.poi.util.LittleEndian; import org.apache.poi.hwpf.usermodel.ParagraphProperties; -public class ParagraphSprmCompressor +public final class ParagraphSprmCompressor { public ParagraphSprmCompressor() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index a7d5690e2e..235f435c2c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; import org.apache.poi.hwpf.usermodel.ParagraphProperties; @@ -33,7 +31,7 @@ import java.util.Iterator; import java.util.Collections; import java.util.ArrayList; -public class ParagraphSprmUncompressor +public final class ParagraphSprmUncompressor extends SprmUncompressor { public ParagraphSprmUncompressor() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java index 4b18dafb78..ad47cdfdc0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - -// + package org.apache.poi.hwpf.sprm; // @@ -246,7 +244,7 @@ import org.apache.poi.hwpf.usermodel.SectionProperties; import org.apache.poi.util.LittleEndian; -public class SectionSprmCompressor +public final class SectionSprmCompressor { private final static SectionProperties DEFAULT_SEP = new SectionProperties(); public SectionSprmCompressor() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java index 30805346b6..802b9fcbc2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,14 +14,13 @@ 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() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java index bef06d43c9..6b1ef43657 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -23,7 +21,7 @@ import org.apache.poi.util.LittleEndian; import java.util.Arrays; -public class SprmBuffer +public final class SprmBuffer implements Cloneable { byte[] _buf; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmIterator.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmIterator.java index 5a1c4b45d8..1a6f23fdfb 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmIterator.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmIterator.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -26,7 +24,7 @@ package org.apache.poi.hwpf.sprm; * @version 1.0 */ -public class SprmIterator +public final class SprmIterator { private byte[] _grpprl; int _offset; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java index 764fc06c4d..41478c80ec 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -29,7 +27,7 @@ import org.apache.poi.util.LittleEndian; * @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); @@ -102,7 +100,7 @@ public class SprmOperation 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) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUncompressor.java index adae2078fb..a2ff38855e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUncompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,15 +14,14 @@ 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() { } @@ -41,10 +39,7 @@ public class SprmUncompressor { return true; } - else - { - return false; - } + return false; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java index b5cd08eb93..9f0abda0f9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -24,7 +22,7 @@ import java.util.List; import org.apache.poi.util.LittleEndian; -public class SprmUtils +public final class SprmUtils { public SprmUtils() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java index a13d59b921..13580fa090 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; @@ -28,7 +26,7 @@ import org.apache.poi.hwpf.usermodel.BorderCode; import java.util.ArrayList; import java.util.Arrays; -public class TableSprmCompressor +public final class TableSprmCompressor { public TableSprmCompressor() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java index f8fc91f123..56de089e99 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.sprm; import org.apache.poi.hwpf.usermodel.TableProperties; @@ -25,7 +23,7 @@ import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.util.LittleEndian; -public class TableSprmUncompressor +public final class TableSprmUncompressor extends SprmUncompressor { public TableSprmUncompressor() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java index 053d3600df..63e534581f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.usermodel; @@ -23,7 +21,7 @@ import org.apache.poi.util.BitField; 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java index 62a384c0eb..540b30000a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.usermodel; import org.apache.poi.hwpf.model.types.CHPAbstractType; @@ -24,7 +22,7 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java index 601c5fa684..9a779643a6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -15,8 +15,6 @@ limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.usermodel; import org.apache.poi.hwpf.model.CHPX; @@ -28,7 +26,7 @@ import org.apache.poi.hwpf.sprm.SprmBuffer; * * @author Ryan Ackley */ -public class CharacterRun +public final class CharacterRun extends Range implements Cloneable { @@ -530,7 +528,7 @@ public class CharacterRun return (CharacterProperties)_props.clone(); } catch(java.lang.CloneNotSupportedException e) { throw new RuntimeException(e); - } + } } /** diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java index 99cc8658b8..27626a515d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java @@ -15,8 +15,6 @@ limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.usermodel; import org.apache.poi.util.BitField; @@ -28,7 +26,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class DateAndTime +public final class DateAndTime implements Cloneable { public static final int SIZE = 4; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java index 234f39e4ec..eb90d5569e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java @@ -15,14 +15,11 @@ 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) @@ -30,4 +27,4 @@ public class DocumentPosition super(pos, pos, doc); } -} \ No newline at end of file +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java index 9793e056ac..b2da9f5eac 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DropCapSpecifier.java @@ -29,7 +29,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class DropCapSpecifier +public final class DropCapSpecifier { private short _info; private static BitField _type = BitFieldFactory.getInstance(0x07); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java index 4fdb184f10..91c993fd7a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java @@ -43,7 +43,7 @@ import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor; * * @author Ryan Ackley */ -public class HWPFList +public final class HWPFList { private ListData _listData; private ListFormatOverride _override; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java index e8f231b6c1..4afaba9d1e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java @@ -14,6 +14,7 @@ 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; @@ -22,25 +23,25 @@ import org.apache.poi.hwpf.model.GenericPropertyNode; 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; @@ -48,14 +49,14 @@ public class HeaderStories { if(fib.getPlcfHddSize() == 0) { return; } - + // Handle the PlcfHdd plcfHdd = new PlexOfCps( doc.getTableStream(), fib.getPlcfHddOffset(), fib.getPlcfHddSize(), 0 ); } - + public String getFootnoteSeparator() { return getAt(0); } @@ -74,8 +75,8 @@ public class HeaderStories { public String getEndnoteContNote() { return getAt(5); } - - + + public String getEvenHeader() { return getAt(6+0); } @@ -108,8 +109,8 @@ public class HeaderStories { // Odd is the default return getOddHeader(); } - - + + public String getEvenFooter() { return getAt(6+2); } @@ -142,25 +143,25 @@ public class HeaderStories { // 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); @@ -171,17 +172,17 @@ public class HeaderStories { 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? diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java index c89332e668..d969d5e1e1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java @@ -24,7 +24,7 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ -public class LineSpacingDescriptor +public final class LineSpacingDescriptor implements Cloneable { short _dyaLine; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java index 9bafce7927..6f29cf0d3c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ 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; @@ -26,18 +25,18 @@ import org.apache.poi.hwpf.model.PAPX; 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()); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java index 107180b86c..a1462ffe0a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,17 +15,13 @@ 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; @@ -457,7 +452,7 @@ public class Paragraph /** * clone the ParagraphProperties object associated with this Paragraph so * that you can apply the same properties to another paragraph. - * + * */ public ParagraphProperties cloneProperties() { try { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java index 2b43ff12b4..167d0837d4 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.usermodel; @@ -24,7 +22,7 @@ import org.apache.poi.hwpf.model.StyleDescription; import org.apache.poi.hwpf.sprm.SprmBuffer; -public class ParagraphProperties +public final class ParagraphProperties extends PAPAbstractType implements Cloneable { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java index 8a3737865b..e485bd0102 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.usermodel; import org.apache.poi.util.LittleEndian; @@ -32,7 +31,7 @@ import java.util.zip.InflaterInputStream; * 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); @@ -98,7 +97,7 @@ public class Picture fillImageContent(); } } - + public Picture(byte[] _dataStream) { this._dataStream = _dataStream; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index d9b679e42d..eb97077e83 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -15,8 +15,6 @@ limitations under the License. ==================================================================== */ - - package org.apache.poi.hwpf.usermodel; @@ -60,8 +58,7 @@ import java.lang.ref.WeakReference; * * @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; @@ -155,7 +152,7 @@ public class Range _characters = _doc.getCharacterTable().getTextRuns(); _text = _doc.getTextTable().getTextPieces(); _parent = new WeakReference(null); - + sanityCheckStartEnd(); } @@ -177,7 +174,7 @@ public class Range _characters = parent._characters; _text = parent._text; _parent = new WeakReference(parent); - + sanityCheckStartEnd(); } @@ -230,10 +227,10 @@ public class Range _textRangeFound = true; break; } - + sanityCheckStartEnd(); } - + /** * Ensures that the start and end were were given * are actually valid, to avoid issues later on @@ -281,7 +278,7 @@ public class Range 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; @@ -292,14 +289,14 @@ public class Range 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. @@ -311,10 +308,10 @@ public class Range // 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 && @@ -323,19 +320,19 @@ public class Range 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 @@ -345,7 +342,7 @@ public class Range 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 @@ -626,7 +623,7 @@ public class Range 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); @@ -728,7 +725,7 @@ public class Range { int absPlaceHolderIndex = getStartOffset() + pOffset; Range subRange = new Range( - absPlaceHolderIndex, + absPlaceHolderIndex, (absPlaceHolderIndex + pPlaceHolder.length()), getDocument() ); @@ -744,7 +741,7 @@ public class Range // 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() ); @@ -1005,7 +1002,7 @@ public class Range /** * Adjust the value of the various FIB character count fields, * eg FIB.CCPText 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 @@ -1017,12 +1014,12 @@ public class Range 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); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java index 050ac9532e..2e471d52f1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,12 +15,11 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java index 71c705c8ca..4f89fe3216 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.usermodel; @@ -24,7 +22,7 @@ import org.apache.poi.hwpf.model.types.SEPAbstractType; import java.lang.reflect.Field; import java.lang.reflect.AccessibleObject; -public class SectionProperties +public final class SectionProperties extends SEPAbstractType { public SectionProperties() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java index 22809be7a8..3e9d2b3ca9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ShadingDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.usermodel; @@ -23,7 +21,7 @@ import org.apache.poi.util.BitField; 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Shape.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Shape.java index 1f798b620c..aecc0d3461 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Shape.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Shape.java @@ -20,14 +20,14 @@ package org.apache.poi.hwpf.usermodel; 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(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java index 29193edf03..4fb4d1636e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -20,7 +19,7 @@ package org.apache.poi.hwpf.usermodel; import java.util.ArrayList; -public class Table +public final class Table extends Range { ArrayList _rows; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java index 4db9da7a95..19c0f7d064 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,10 +14,10 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java index 1c78f5f82a..8d196fce72 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCellDescriptor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,12 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableIterator.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableIterator.java index c836af1f34..f19a340351 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableIterator.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableIterator.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,13 @@ 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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java index a7d485b8a8..b06526ccd1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,13 +14,12 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java index a88e32360e..857a92cfbe 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -20,7 +19,7 @@ package org.apache.poi.hwpf.usermodel; import org.apache.poi.hwpf.sprm.TableSprmUncompressor; -public class TableRow +public final class TableRow extends Paragraph { private final static char TABLE_CELL_MARK = '\u0007'; diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java index ae0ff35939..ae2fb7c7da 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Background.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Background.java index 6211667d0e..f67c57b95a 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Background.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Background.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Fill.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Fill.java index 5a5568a774..e62b0480d6 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Fill.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Fill.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/FontCollection.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/FontCollection.java index 289872a403..61278f4618 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/FontCollection.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/FontCollection.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; public interface FontCollection { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Hyperlink.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Hyperlink.java index 66a84d5131..cde288492c 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Hyperlink.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Hyperlink.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; /** diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java index 7136f7f3cf..630c37de45 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Line.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/LineStyle.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/LineStyle.java index 28a1293863..43ef4a7b78 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/LineStyle.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/LineStyle.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java index 711a6fd5df..61792cd5bb 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java index ff99ef01f8..5d5ba98e7e 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Picture.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Picture.java index 26615ff91c..9a55313963 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Picture.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Picture.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/PictureData.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/PictureData.java index d002cf7981..e325e5a8db 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/PictureData.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/PictureData.java @@ -14,12 +14,13 @@ 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); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Resources.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Resources.java index 28f5edb6b6..96170e50bd 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Resources.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Resources.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; /** @@ -22,7 +23,7 @@ package org.apache.poi.sl.usermodel; */ public interface Resources { public FontCollection getFontCollection(); - + public PictureData[] getPictureData(); public int addPictureData(PictureData pict); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java index 0d68501167..11c0bf6251 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java @@ -14,17 +14,18 @@ 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(); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java index ea295a4932..cabcf4bc89 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeContainer.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; public interface ShapeContainer { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java index e5b6ab9ca5..3c2ff6b8cd 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeTypes.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeTypes.java index f4e06bc806..69325fe13a 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeTypes.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeTypes.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; public interface ShapeTypes { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java index 4a78a403fd..7959838cc1 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; /** @@ -23,6 +24,6 @@ public interface Sheet extends ShapeContainer { public SlideShow getSlideShow(); public MasterSheet getMasterSheet(); - + public Background getBackground(); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/SimpleShape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/SimpleShape.java index c5be4f5df8..449433a7e8 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/SimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/SimpleShape.java @@ -14,12 +14,13 @@ 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); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java index a1e224749d..d3c4af25a4 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java @@ -14,18 +14,19 @@ 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); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java index 39cd4d500f..8239bb91ff 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.sl.usermodel; import java.io.IOException; @@ -21,9 +22,9 @@ 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(); } diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java index eef7cfc2e4..5a88815ee7 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java @@ -14,6 +14,7 @@ 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 { diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java index 5941b18df6..ae1a134771 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextRun.java @@ -14,16 +14,17 @@ 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 } diff --git a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java index 520409fcac..e66a262664 100644 --- a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java +++ b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi; @@ -34,10 +34,10 @@ import org.apache.poi.poifs.filesystem.*; * * 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; @@ -46,7 +46,7 @@ public class TestPOIDocumentScratchpad extends TestCase { 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 { @@ -56,31 +56,31 @@ public class TestPOIDocumentScratchpad extends TestCase { 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()); @@ -90,7 +90,7 @@ public class TestPOIDocumentScratchpad extends TestCase { // 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") @@ -102,20 +102,20 @@ public class TestPOIDocumentScratchpad extends TestCase { 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(); } diff --git a/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java b/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java index 6b9b1a24dc..84ff605096 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hdf/model/TestHDFDocument.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hdf.model; @@ -32,7 +29,7 @@ import java.io.IOException; * * @author Bob Otterberg */ -public class TestHDFDocument +public final class TestHDFDocument extends TestCase { diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java index 85f64df220..e98c8110a0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hdgf; import java.io.FileInputStream; @@ -24,35 +25,35 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; 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()); @@ -61,7 +62,7 @@ public class TestHDGFCore extends TestCase { 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 @@ -69,7 +70,7 @@ public class TestHDGFCore extends TestCase { public void DISABLEDtestNegativeChunkLength() throws Exception { filename = dirname + "/NegativeChunkLength.vsd"; fs = new POIFSFileSystem(new FileInputStream(filename)); - + HDGFDiagram hdgf = new HDGFDiagram(fs); assertNotNull(hdgf); } diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java index f8f0f25558..bbdeadad09 100644 --- a/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java +++ b/src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFLZW.java @@ -13,173 +13,174 @@ 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 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 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 { // } diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java b/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java index 1289882254..6bd05612e0 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/extractor/TextPublisherTextExtractor.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.extractor; import java.io.File; @@ -23,7 +24,7 @@ import org.apache.poi.hpbf.HPBFDocument; import junit.framework.TestCase; -public class TextPublisherTextExtractor extends TestCase { +public final class TextPublisherTextExtractor extends TestCase { private String dir; protected void setUp() throws Exception { @@ -36,27 +37,27 @@ public class TextPublisherTextExtractor extends TestCase { 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" + @@ -84,7 +85,7 @@ public class TextPublisherTextExtractor extends TestCase { "Within doc to page 1\n" , text ); - + // Now a simpler one f = new File(dir, "Simple.pub"); ext = new PublisherTextExtractor( @@ -102,7 +103,7 @@ public class TextPublisherTextExtractor extends TestCase { , text ); } - + /** * We have the same file saved for Publisher 98, Publisher * 2000 and Publisher 2007. Check they all agree. @@ -111,30 +112,30 @@ public class TextPublisherTextExtractor extends TestCase { 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. @@ -145,24 +146,24 @@ public class TextPublisherTextExtractor extends TestCase { 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\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( "\n" + "\n" + diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java index 631095007d..e803cae156 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestEscherParts.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.model; import java.io.File; @@ -23,7 +24,7 @@ import org.apache.poi.hpbf.HPBFDocument; import junit.framework.TestCase; -public class TestEscherParts extends TestCase { +public final class TestEscherParts extends TestCase { private String dir; protected void setUp() throws Exception { @@ -38,16 +39,16 @@ public class TestEscherParts extends TestCase { 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( @@ -56,16 +57,16 @@ public class TestEscherParts extends TestCase { 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( @@ -74,10 +75,10 @@ public class TestEscherParts extends TestCase { es = doc.getEscherStm(); eds = doc.getEscherDelayStm(); - + assertNotNull(es); assertNotNull(eds); - + assertEquals(51, es.getEscherRecords().length); assertEquals(92, eds.getEscherRecords().length); } diff --git a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java index 1ba45813c3..69d46d0923 100644 --- a/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java +++ b/src/scratchpad/testcases/org/apache/poi/hpbf/model/TestQuillContents.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.model; import java.io.File; @@ -28,7 +29,7 @@ import org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8; import junit.framework.TestCase; -public class TestQuillContents extends TestCase { +public final class TestQuillContents extends TestCase { private String dir; protected void setUp() throws Exception { @@ -40,7 +41,7 @@ public class TestQuillContents extends TestCase { HPBFDocument doc = new HPBFDocument( new FileInputStream(f) ); - + QuillContents qc = doc.getQuillContents(); assertEquals(20, qc.getBits().length); for(int i=0; i<19; i++) { @@ -48,88 +49,88 @@ public class TestQuillContents extends TestCase { } // 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]); @@ -142,49 +143,49 @@ public class TestQuillContents extends TestCase { 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]); @@ -193,13 +194,13 @@ public class TestQuillContents extends TestCase { 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]); @@ -214,16 +215,16 @@ public class TestQuillContents extends TestCase { 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]); @@ -244,127 +245,127 @@ public class TestQuillContents extends TestCase { 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)); @@ -372,28 +373,28 @@ public class TestQuillContents extends TestCase { 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)); @@ -401,28 +402,28 @@ public class TestQuillContents extends TestCase { 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)); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java index 218b9f2697..6daeab1b20 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf; @@ -31,7 +28,7 @@ import org.apache.poi.hslf.record.*; * * @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 @@ -40,23 +37,23 @@ public class TestEncryptedFile extends TestCase { 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); @@ -64,14 +61,14 @@ public class TestEncryptedFile extends TestCase { } catch(EncryptedPowerPointFileException e) { // Good } - + try { new HSLFSlideShow(ss_np_e); fail(); } catch(EncryptedPowerPointFileException e) { // Good } - + try { new HSLFSlideShow(ss_56_e); fail(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java index 541b7a3a24..b1468f2c55 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf; @@ -33,7 +30,7 @@ import org.apache.poi.poifs.filesystem.*; * * @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; @@ -45,17 +42,17 @@ public class TestReWrite extends TestCase { 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); @@ -92,27 +89,27 @@ public class TestReWrite extends TestCase { 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); @@ -123,11 +120,11 @@ public class TestReWrite extends TestCase { /** * 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); @@ -137,7 +134,7 @@ public class TestReWrite extends TestCase { SlideShow ss = new SlideShow(hss); ss.getSlides(); ss.getNotes(); - + // Now write out to a byte array ByteArrayOutputStream baos = new ByteArrayOutputStream(); hss.write(baos); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java index 373611e73d..7467021544 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf; @@ -33,7 +30,7 @@ import org.apache.poi.poifs.filesystem.*; * * @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 @@ -58,7 +55,7 @@ public class TestReWriteSanity extends TestCase { // 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(); @@ -75,7 +72,7 @@ public class TestReWriteSanity extends TestCase { ue.put(new Integer(pos), r[i]); lastUEPos = pos; } - + ByteArrayOutputStream bc = new ByteArrayOutputStream(); r[i].writeOut(bc); pos += bc.size(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java index 1b76b72653..60b93dea64 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf; @@ -30,7 +27,7 @@ import org.apache.poi.hslf.record.*; * * @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; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java index 66672cdcb8..e45ca51d12 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.extractor; @@ -29,7 +26,7 @@ import java.util.Vector; * * @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 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java index ebfaccf8bf..7871b05976 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hslf.model; import junit.framework.TestCase; @@ -26,10 +27,10 @@ import org.apache.poi.hslf.HSLFSlideShow; /** * Test Fill object. - * + * * @author Yegor Kozlov */ -public class TestBackground extends TestCase { +public final class TestBackground extends TestCase { /** * Default background for slide, shape and slide master. diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java index 56d5a099cb..77a58844de 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java @@ -1,80 +1,81 @@ -/* ==================================================================== - 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 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))); - } -} +/* ==================================================================== + 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))); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java index 39255d3e8b..cf94e04539 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java @@ -1,224 +1,221 @@ - -/* ==================================================================== - 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 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 false or null - */ - 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()); - } -} \ 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 false or null + */ + 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()); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java index 9108d3c36c..48de8804e9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java @@ -1,89 +1,90 @@ -/* ==================================================================== - 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 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)); - - } - } - - } - -} +/* ==================================================================== + 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)); + + } + } + + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java index d10dd13530..b230679bd3 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java @@ -1,57 +1,58 @@ -/* ==================================================================== - 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 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); - } - -} +/* ==================================================================== + 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); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java index 0138fb4192..7e7c5d3b3b 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hslf.model; import junit.framework.*; @@ -26,10 +27,10 @@ import org.apache.poi.hslf.HSLFSlideShow; /** * Test Line shape. - * + * * @author Yegor Kozlov */ -public class TestLine extends TestCase { +public final class TestLine extends TestCase { public void setUp() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java index 9e0bfaf772..8555bce983 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java @@ -1,66 +1,67 @@ -/* ==================================================================== - 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 MovieShape object. - * - * @author Yegor Kozlov - */ -public 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()); - - } - -} +/* ==================================================================== + 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 MovieShape 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()); + + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java index 9d0288c752..e8fae8a37e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java @@ -1,92 +1,92 @@ -/* ==================================================================== - 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); - } -} +/* ==================================================================== + 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); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java index b6864ea16b..f445f2b62b 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java @@ -1,56 +1,55 @@ - -/* ==================================================================== - 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 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()); - } -} +/* ==================================================================== + 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()); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java index 7efe956e20..521230077e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hslf.model; import junit.framework.TestCase; @@ -30,7 +31,7 @@ import java.io.ByteArrayInputStream; * * @author Yegor Kozlov */ -public class TestPPGraphics2D extends TestCase { +public final class TestPPGraphics2D extends TestCase { private SlideShow ppt; protected void setUp() throws Exception { @@ -42,7 +43,7 @@ public class TestPPGraphics2D extends TestCase { 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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java index b4a362ae8d..b3f5942f39 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java @@ -1,96 +1,97 @@ -/* ==================================================================== - 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 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); - } - -} +/* ==================================================================== + 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); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java index a75c2e73ab..572dbd035c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hslf.model; import junit.framework.TestCase; @@ -29,7 +30,7 @@ import java.io.ByteArrayInputStream; * * @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 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java index 3ce6b91caf..77e2efa08a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hslf.model; import junit.framework.TestCase; @@ -36,7 +37,7 @@ import java.util.ArrayList; * * @author Yegor Kozlov */ -public class TestShapes extends TestCase { +public final class TestShapes extends TestCase { private SlideShow ppt; private SlideShow pptB; @@ -44,7 +45,7 @@ public class TestShapes extends TestCase { 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)); } @@ -166,7 +167,7 @@ public class TestShapes extends TestCase { ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()))); sl = ppt.getSlides()[0]; - + txtbox = (TextBox)sl.getShapes()[0]; rt = txtbox.getTextRun().getRichTextRuns()[0]; @@ -179,7 +180,7 @@ public class TestShapes extends TestCase { assertEquals("Arial", rt.getFontName()); assertEquals(Color.red, rt.getFontColor()); } - + /** * Test with an empty text box */ @@ -187,7 +188,7 @@ public class TestShapes extends TestCase { 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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java index 1fe9ada7fc..0282c2a7e6 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java @@ -1,106 +1,107 @@ -/* ==================================================================== - 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 Sheet object. - * For each ppt in the test directory check that all sheets are properly initialized - * - * @author Yegor Kozlov - */ -public 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 + 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 Sheet 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()); + } + + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java index 0b09e44f62..a6b17ec41c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.model; @@ -32,7 +29,7 @@ import org.apache.poi.hslf.record.SlideAtom; * * @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; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java index 9a733b565d..9799eb0069 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java @@ -31,10 +31,10 @@ import java.awt.*; /** * Tests for SlideMaster - * + * * @author Yegor Kozlov */ -public class TestSlideMaster extends TestCase{ +public final class TestSlideMaster extends TestCase{ String home; public void setUp() throws Exception { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java index 4b8035355d..f60cfed57d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java @@ -26,12 +26,12 @@ import java.io.ByteArrayInputStream; /** * 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. @@ -40,7 +40,7 @@ public class TestSlides extends TestCase { 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()); @@ -63,13 +63,13 @@ public class TestSlides extends TestCase { 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()); @@ -92,13 +92,13 @@ public class TestSlides extends TestCase { 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()); @@ -111,7 +111,7 @@ public class TestSlides extends TestCase { assertEquals(258, s3._getSheetNumber()); assertEquals(3, s3.getSlideNumber()); - + //serialize and read again ByteArrayOutputStream out = new ByteArrayOutputStream(); ppt.write(out); @@ -119,7 +119,7 @@ public class TestSlides extends TestCase { 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()); @@ -139,26 +139,26 @@ public class TestSlides extends TestCase { 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); @@ -166,8 +166,8 @@ public class TestSlides extends TestCase { 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()); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java index 8a9cf7da27..d3c10cbea1 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java @@ -1,104 +1,105 @@ -/* ==================================================================== - 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 Table object. - * - * @author Yegor Kozlov - */ -public class TestTable extends TestCase { - - /** - * Test that ShapeFactory works properly and returns Table - */ - 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 + 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 Table object. + * + * @author Yegor Kozlov + */ +public final class TestTable extends TestCase { + + /** + * Test that ShapeFactory works properly and returns Table + */ + 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){ + + } + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java index 6463da4c31..2fcc6927c7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.model; @@ -36,7 +33,7 @@ import org.apache.poi.hslf.usermodel.SlideShow; * * @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; @@ -45,12 +42,12 @@ public class TestTextRun extends TestCase { 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); @@ -65,16 +62,16 @@ public class TestTextRun extends TestCase { 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(); @@ -85,7 +82,7 @@ public class TestTextRun extends TestCase { 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 */ @@ -96,12 +93,12 @@ public class TestTextRun extends TestCase { // 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()); @@ -114,7 +111,7 @@ public class TestTextRun extends TestCase { 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; @@ -124,50 +121,50 @@ public class TestTextRun extends TestCase { 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 @@ -180,22 +177,22 @@ public class TestTextRun extends TestCase { 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 */ @@ -207,21 +204,21 @@ public class TestTextRun extends TestCase { 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()); @@ -230,17 +227,17 @@ public class TestTextRun extends TestCase { 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 @@ -250,12 +247,12 @@ public class TestTextRun extends TestCase { 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]; @@ -264,7 +261,7 @@ public class TestTextRun extends TestCase { assertNull(rtrB._getRawCharacterStyle()); assertNull(rtrB._getRawParagraphStyle()); } - + /** * Tests to ensure that setting the text where the text is rich * sets everything to the same styling @@ -274,7 +271,7 @@ public class TestTextRun extends TestCase { 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]; @@ -284,7 +281,7 @@ public class TestTextRun extends TestCase { TextPropCollection tpCC = rtrC._getRawCharacterStyle(); TextPropCollection tpDP = rtrD._getRawParagraphStyle(); TextPropCollection tpDC = rtrD._getRawCharacterStyle(); - + assertEquals(trB.getText().substring(0, 30), rtrB.getText()); assertNotNull(tpBP); assertNotNull(tpBC); @@ -298,10 +295,10 @@ public class TestTextRun extends TestCase { 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]; @@ -312,7 +309,7 @@ public class TestTextRun extends TestCase { 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 @@ -322,17 +319,17 @@ public class TestTextRun extends TestCase { 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()); @@ -347,7 +344,7 @@ public class TestTextRun extends TestCase { 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]; @@ -359,7 +356,7 @@ public class TestTextRun extends TestCase { 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); @@ -374,12 +371,12 @@ public class TestTextRun extends TestCase { 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"; @@ -389,22 +386,22 @@ public class TestTextRun extends TestCase { 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(); @@ -413,7 +410,7 @@ public class TestTextRun extends TestCase { assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList()); assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList()); } - + /** * Test case for Bug 41015. @@ -424,17 +421,17 @@ public class TestTextRun extends TestCase { */ 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()); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java index 8967ae1610..2a2a10bb45 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.model; @@ -32,11 +29,11 @@ import org.apache.poi.poifs.filesystem.*; /** * 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 @@ -60,33 +57,33 @@ public class TestTextRunReWrite extends TestCase { // 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); @@ -116,11 +113,11 @@ public class TestTextRunReWrite extends TestCase { 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()); @@ -129,11 +126,11 @@ public class TestTextRunReWrite extends TestCase { 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()); @@ -142,8 +139,8 @@ public class TestTextRunReWrite extends TestCase { 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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java index 7fc8787567..07ed6d2da6 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java @@ -1,203 +1,201 @@ - -/* ==================================================================== - 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 TextShape and its sub-classes - * - * @author Yegor Kozlov - */ -public 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); - } -} +/* ==================================================================== + 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 TextShape 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); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java index 3b8cf756da..a8402a333a 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestAnimationInfoAtom.java @@ -1,91 +1,88 @@ - -/* ==================================================================== - 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 class TestAnimationInfoAtom extends TestCase { - // From a real file - /* - - 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 - - */ - 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)); - } - -} \ 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 + /* + + 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 + + */ + 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)); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java index df8e1a3dae..5fffb13427 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.record; @@ -29,7 +26,7 @@ import java.io.ByteArrayOutputStream; * * @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, @@ -37,7 +34,7 @@ public class TestCString extends TestCase { 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()); @@ -49,17 +46,17 @@ public class TestCString extends TestCase { 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()); } @@ -74,7 +71,7 @@ public class TestCString extends TestCase { for(int i=0; i=0; i--) { @@ -61,15 +58,15 @@ public class TestDocument extends TestCase { 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]); @@ -79,15 +76,15 @@ public class TestDocument extends TestCase { 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 } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java index 19a7c7a416..9b28d431ad 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.record; @@ -29,10 +26,10 @@ import java.io.ByteArrayOutputStream; * * @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 }; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryptionAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryptionAtom.java index 9189db2743..c93b77876f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryptionAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryptionAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.record; @@ -28,80 +25,80 @@ import junit.framework.TestCase; * * @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()); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java index 82255d9734..9aa03a9887 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExControl.java @@ -1,127 +1,124 @@ - -/* ==================================================================== - 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 class TestExControl extends TestCase { - - // From a real file (embedded SWF control) - /* - - - 00 01 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 - - - 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 - - - 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 - - - 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 - - - */ - 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)); - } - -} \ 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) + /* + + + 00 01 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 + + + 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 + + + 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 + + + 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 + + + */ + 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)); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java index d5b7b9f969..3f63a42a22 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExMediaAtom.java @@ -1,91 +1,91 @@ -/* ==================================================================== - 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)); - - } -} \ 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)); + + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java index a7c15812c1..cdd91b91cc 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjAtom.java @@ -1,73 +1,72 @@ -/* ==================================================================== - 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)); - } - -} \ 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)); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjStg.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjStg.java index 4ce08c7564..1365691d41 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjStg.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExOleObjStg.java @@ -1,144 +1,141 @@ - -/* ==================================================================== - 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 class TestExOleObjStg extends TestCase { - - // From a real file (embedded SWF control) - /* - - 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 - - */ - 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(); - - } -} \ 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) + /* + + 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 + + */ + 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(); + + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java index 224aedf61c..3c903f41ee 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExVideoContainer.java @@ -1,90 +1,87 @@ - -/* ==================================================================== - 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 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)); - } -} \ 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)); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java index 1e174fffb7..75af7afa0c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -28,7 +27,7 @@ import java.util.Arrays; * * @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, @@ -64,7 +63,7 @@ public class TestFontCollection extends TestCase { // 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)); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java index 8c6972c6a5..5db87e136d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersAtom.java @@ -1,95 +1,92 @@ - -/* ==================================================================== - 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 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)); - - } -} \ 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)); + + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java index d24ca05f65..921b08929b 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestHeadersFootersContainer.java @@ -1,171 +1,168 @@ - -/* ==================================================================== - 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 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)); - } - -} \ 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)); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java index 44be07ad5e..90deb5253e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestNotesAtom.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.record; @@ -29,7 +26,7 @@ import java.io.ByteArrayOutputStream; * * @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 }; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java index 255e4442c5..89e6387206 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.record; @@ -30,123 +27,123 @@ import org.apache.poi.hslf.HSLFSlideShow; * * @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 256+257 assertEquals(256, slides[0]._getSheetNumber()); assertEquals(257, slides[1]._getSheetNumber()); @@ -65,14 +62,14 @@ public class TestCounts extends TestCase { // 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()); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java index c11515e24d..78c2935727 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -30,7 +27,7 @@ import org.apache.poi.hslf.record.*; * * @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 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java index fde1da57ae..56638e2e98 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -30,7 +27,7 @@ import org.apache.poi.hslf.model.*; * * @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; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java index 2944a74664..24189ad2c8 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java @@ -30,7 +30,7 @@ import java.util.Arrays; * * @author Yegor Kozlov */ -public class TestPictures extends TestCase{ +public final class TestPictures extends TestCase{ protected File cwd; @@ -258,10 +258,10 @@ public class TestPictures extends TestCase{ 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); @@ -375,7 +375,7 @@ public class TestPictures extends TestCase{ } /** - * 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 { @@ -393,21 +393,21 @@ public class TestPictures extends TestCase{ 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()); @@ -416,22 +416,22 @@ public class TestPictures extends TestCase{ // 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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java index e039781cc8..d8437d80d2 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -33,33 +30,33 @@ import org.apache.poi.hslf.model.*; * * @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); @@ -72,33 +69,33 @@ public class TestReOrderingSlides extends TestCase { // 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 @@ -108,7 +105,7 @@ public class TestReOrderingSlides extends TestCase { 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 @@ -117,21 +114,21 @@ public class TestReOrderingSlides extends TestCase { 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]; @@ -142,7 +139,7 @@ public class TestReOrderingSlides extends TestCase { assertEquals(6, s2._getSheetRefId()); assertEquals(2, s2.getSlideNumber()); } - + /** * Test re-ordering slides in a slideshow with 2 slides on it */ @@ -151,7 +148,7 @@ public class TestReOrderingSlides extends TestCase { 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 @@ -160,21 +157,21 @@ public class TestReOrderingSlides extends TestCase { 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]; @@ -185,7 +182,7 @@ public class TestReOrderingSlides extends TestCase { assertEquals(4, s2._getSheetRefId()); assertEquals(2, s2.getSlideNumber()); } - + /** * Test doing a dummy re-order on a slideshow with * three slides in it @@ -196,7 +193,7 @@ public class TestReOrderingSlides extends TestCase { 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 @@ -209,26 +206,26 @@ public class TestReOrderingSlides extends TestCase { 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()); @@ -239,7 +236,7 @@ public class TestReOrderingSlides extends TestCase { assertEquals(4, s3._getSheetRefId()); assertEquals(3, s3.getSlideNumber()); } - + /** * Test re-ordering slides in a slideshow with 3 slides on it */ @@ -249,7 +246,7 @@ public class TestReOrderingSlides extends TestCase { 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 @@ -262,22 +259,22 @@ public class TestReOrderingSlides extends TestCase { 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]; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java index 4cb34ba476..c5f3063fe8 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -29,13 +26,13 @@ import org.apache.poi.hslf.record.Record; 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; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java index 5177977af1..47d2461f55 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java @@ -37,7 +37,7 @@ import org.apache.poi.hslf.record.SlideListWithText; * (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; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java index ae532dd034..9c10f8b036 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -30,7 +27,7 @@ import org.apache.poi.hslf.model.*; * * @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; @@ -59,7 +56,7 @@ public class TestSheetText extends TestCase { 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. @@ -70,14 +67,14 @@ public class TestSheetText extends TestCase { 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" + diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java index 3d89d0272f..7eab827f1c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSlideOrdering.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.usermodel; @@ -30,7 +27,7 @@ import org.apache.poi.hslf.model.*; * * @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 @@ -38,11 +35,11 @@ public class TestSlideOrdering extends TestCase { 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); @@ -53,15 +50,15 @@ public class TestSlideOrdering extends TestCase { */ 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()); } @@ -71,17 +68,17 @@ public class TestSlideOrdering extends TestCase { */ 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()); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java index 95de38f8ba..eea37695c4 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSoundData.java @@ -1,63 +1,63 @@ -/* ==================================================================== - 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 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 + 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())); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java b/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java index d2b0e20f4c..46a7284691 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/util/TestSystemTimeUtils.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - - package org.apache.poi.hslf.util; @@ -31,26 +28,26 @@ import junit.framework.TestCase; * * @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()); @@ -59,32 +56,32 @@ public class TestSystemTimeUtils extends TestCase { 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 -1) { read = fis.read(buffer); @@ -170,7 +169,7 @@ public class TestHWPFPictures extends TestCase { baos.write(buffer,0,read); } } - + return baos.toByteArray(); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java index af0faf96c9..283cae027f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf; import java.io.FileInputStream; @@ -28,9 +27,9 @@ import junit.framework.TestCase; * 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" + @@ -39,11 +38,11 @@ public class TestHWPFRangeParts extends TestCase { 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" + @@ -52,15 +51,15 @@ public class TestHWPFRangeParts extends TestCase { 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" + @@ -76,7 +75,7 @@ public class TestHWPFRangeParts extends TestCase { 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" @@ -86,7 +85,7 @@ public class TestHWPFRangeParts extends TestCase { "The footer, with Moli\u00e8re, has Unicode in it.\r" + "\r\r\r\r" ; - + /** * A document made up only of basic ASCII text */ @@ -95,21 +94,21 @@ public class TestHWPFRangeParts extends TestCase { * 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( @@ -122,7 +121,7 @@ public class TestHWPFRangeParts extends TestCase { a_page_2.length(), docAscii._cpSplit.getMainDocumentEnd() ); - + assertEquals( 238, docAscii._cpSplit.getFootnoteStart() @@ -131,7 +130,7 @@ public class TestHWPFRangeParts extends TestCase { 238, docAscii._cpSplit.getFootnoteEnd() ); - + assertEquals( 238, docAscii._cpSplit.getHeaderStoryStart() @@ -142,10 +141,10 @@ public class TestHWPFRangeParts extends TestCase { docAscii._cpSplit.getHeaderStoryEnd() ); } - + public void testContents() throws Exception { Range r; - + // Now check the real ranges r = docAscii.getRange(); assertEquals( @@ -154,32 +153,32 @@ public class TestHWPFRangeParts extends TestCase { 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( @@ -192,7 +191,7 @@ public class TestHWPFRangeParts extends TestCase { u_page_2.length(), docUnicode._cpSplit.getMainDocumentEnd() ); - + assertEquals( 408, docUnicode._cpSplit.getFootnoteStart() @@ -201,7 +200,7 @@ public class TestHWPFRangeParts extends TestCase { 408, docUnicode._cpSplit.getFootnoteEnd() ); - + assertEquals( 408, docUnicode._cpSplit.getHeaderStoryStart() @@ -213,10 +212,10 @@ public class TestHWPFRangeParts extends TestCase { docUnicode._cpSplit.getHeaderStoryEnd() ); } - + public void testContentsUnicode() throws Exception { Range r; - + // Now check the real ranges r = docUnicode.getRange(); assertEquals( @@ -225,26 +224,26 @@ public class TestHWPFRangeParts extends TestCase { 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() diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java index 786fc807db..685ce949bb 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -31,7 +32,7 @@ import junit.framework.TestCase; * * @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", @@ -48,40 +49,40 @@ public class TestDifferentRoutes extends TestCase { "\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 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 */ @@ -111,8 +112,8 @@ public class TestWordExtractor extends TestCase { String text = extractor.getTextFromPieces(); assertEquals(p_text1_block, text); } - - + + /** * Test that we can get data from two different * embeded word documents @@ -122,23 +123,23 @@ public class TestWordExtractor extends TestCase { 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", @@ -146,42 +147,42 @@ public class TestWordExtractor extends TestCase { 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() @@ -191,31 +192,31 @@ public class TestWordExtractor extends TestCase { 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() diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java index b87f586d36..585c534ed9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -25,21 +26,21 @@ import junit.framework.TestCase; * * @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(); - } - + } + } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java index d1f1451acd..d121666ae1 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -27,12 +25,12 @@ import junit.framework.*; 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) diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java index 1395b98870..c897944e5c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import junit.framework.*; @@ -24,7 +23,7 @@ import org.apache.poi.hwpf.*; import java.lang.reflect.*; import java.util.Arrays; -public class TestDocumentProperties +public final class TestDocumentProperties extends TestCase { private DocumentProperties _documentProperties = null; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java index 31c99173de..5c848ff87a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import junit.framework.*; @@ -23,7 +22,7 @@ import org.apache.poi.hwpf.*; import java.lang.reflect.*; -public class TestFileInformationBlock +public final class TestFileInformationBlock extends TestCase { private FileInformationBlock _fileInformationBlock = null; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java index 9029640008..73b4298431 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -23,7 +21,7 @@ import junit.framework.*; 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; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestListTables.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestListTables.java index c3fb63d374..08cf5dc5fd 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestListTables.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestListTables.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,14 +14,14 @@ 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 { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java index 446b5232a5..008058b5cf 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -26,7 +24,7 @@ import org.apache.poi.hwpf.model.io.*; import java.io.*; import java.util.*; -public class TestPAPBinTable +public final class TestPAPBinTable extends TestCase { private PAPBinTable _pAPBinTable = null; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java index edaf88b999..de585efba1 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -24,7 +22,7 @@ import org.apache.poi.hwpf.*; import org.apache.poi.util.LittleEndian; -public class TestPlexOfCps +public final class TestPlexOfCps extends TestCase { private PlexOfCps _plexOfCps = null; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java index df5f216fe3..c2607f1ac3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; import java.io.*; @@ -32,7 +30,7 @@ import org.apache.poi.util.*; * * @author Daniel Noll */ -public class TestSavedByTable +public final class TestSavedByTable extends TestCase { /** Data dir */ diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java index 2f5ad1ccbc..da0eb00b8e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -27,7 +25,7 @@ import java.util.ArrayList; import org.apache.poi.hwpf.*; import org.apache.poi.hwpf.model.io.*; -public class TestSectionTable +public final class TestSectionTable extends TestCase { private HWPFDocFixture _hWPFDocFixture; @@ -46,7 +44,7 @@ public class TestSectionTable int fcMin = fib.getFcMin(); CPSplitCalculator cps = new CPSplitCalculator(fib); - + ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.getFcClx(), fcMin); TextPieceTable tpt = cft.getTextPieceTable(); @@ -64,7 +62,7 @@ public class TestSectionTable byte[] newMainStream = mainOut.toByteArray(); SectionTable newSectionTable = new SectionTable( - newMainStream, newTableStream, 0, + newMainStream, newTableStream, 0, newTableStream.length, 0, tpt, cps); ArrayList oldSections = sectionTable.getSections(); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java index a93eaa3d15..e9d70370df 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.hwpf.model; @@ -24,7 +22,7 @@ import junit.framework.*; 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; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java index 4595c4ce0e..e69f0dec04 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hwpf.model; import java.io.ByteArrayInputStream; @@ -30,7 +29,7 @@ import org.apache.poi.hwpf.HWPFDocument; 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; @@ -76,25 +75,25 @@ public class TestTextPieceTable extends TestCase { 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()); @@ -111,54 +110,54 @@ public class TestTextPieceTable extends TestCase { 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()); @@ -170,12 +169,12 @@ public class TestTextPieceTable extends TestCase { 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 { @@ -183,7 +182,7 @@ public class TestTextPieceTable extends TestCase { _hWPFDocFixture = new HWPFDocFixture(this); _hWPFDocFixture.setUp(); - + dirname = System.getProperty("HWPF.testdata.path"); } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java index e68352b508..1a48ab6b60 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHeaderStories.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hwpf.usermodel; import java.io.File; @@ -27,19 +28,19 @@ import org.apache.poi.hwpf.HWPFDocument; * 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")) ); @@ -65,138 +66,138 @@ public class TestHeaderStories extends TestCase { 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()); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java index 3656b2ff5f..2dd669e7c3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -31,54 +32,54 @@ import org.apache.poi.util.LittleEndian; * * @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 128); - + // Check right contents byte[] emf = loadImage("vector_image.emf"); byte[] pemf = pic.getContent(); @@ -110,32 +111,32 @@ public class TestPictures extends TestCase { 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())); @@ -154,7 +155,7 @@ public class TestPictures extends TestCase { 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 ) { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java index 2cc47474f8..54e9b42a0c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -29,17 +30,17 @@ import org.apache.poi.hwpf.model.StyleSheet; * * @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++) { @@ -57,7 +58,7 @@ public class TestProblems extends HWPFTestCase { 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++) { @@ -80,32 +81,32 @@ public class TestProblems extends HWPFTestCase { 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 @@ -119,9 +120,9 @@ public class TestProblems extends HWPFTestCase { 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(); @@ -132,22 +133,22 @@ public class TestProblems extends HWPFTestCase { 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 @@ -161,12 +162,12 @@ public class TestProblems extends HWPFTestCase { // 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()); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRange.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRange.java index bcb03996ab..7fc362e3b7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRange.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRange.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -22,19 +23,19 @@ 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)); @@ -42,11 +43,11 @@ public class TestRange extends TestCase { 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)); } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java index 4adc5b9cf8..6468e3e370 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeDelete.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -7,7 +6,7 @@ (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, @@ -29,12 +28,12 @@ import org.apache.poi.hwpf.model.PAPX; * 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"; @@ -78,48 +77,48 @@ public class TestRangeDelete extends TestCase { 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() + diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java index a520b953f7..76452622f7 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -7,7 +6,7 @@ (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, @@ -30,7 +29,7 @@ import org.apache.poi.hwpf.HWPFDocument; * * 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 = @@ -72,14 +71,14 @@ public class TestRangeInsertion extends TestCase { 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()); } @@ -114,8 +113,8 @@ public class TestRangeInsertion extends TestCase { 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() ; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java index 1578ebdaf0..05e3d2ca24 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hwpf.usermodel; import java.io.File; @@ -32,9 +33,9 @@ import junit.framework.TestCase; * * 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" + @@ -50,23 +51,23 @@ public class TestRangeProperties extends TestCase { 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( @@ -76,34 +77,34 @@ public class TestRangeProperties extends TestCase { 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", @@ -117,12 +118,12 @@ public class TestRangeProperties extends TestCase { 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() @@ -136,19 +137,19 @@ public class TestRangeProperties extends TestCase { 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()); @@ -163,7 +164,7 @@ public class TestRangeProperties extends TestCase { 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() @@ -171,37 +172,37 @@ public class TestRangeProperties extends TestCase { 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); @@ -213,7 +214,7 @@ public class TestRangeProperties extends TestCase { assertTrue(p3.getEnd() < 408); assertTrue(p4.getStart() < 408); assertTrue(p4.getEnd() < 408); - + // Paragraphs should match with lines assertEquals( 0, @@ -223,17 +224,17 @@ public class TestRangeProperties extends TestCase { 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, @@ -254,18 +255,18 @@ public class TestRangeProperties extends TestCase { 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()); @@ -283,86 +284,86 @@ public class TestRangeProperties extends TestCase { 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() diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java index 7c47668445..794979d0fa 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -7,7 +6,7 @@ (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, @@ -30,7 +29,7 @@ import org.apache.poi.hwpf.HWPFDocument; * * 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 = @@ -76,8 +75,8 @@ public class TestRangeReplacement extends TestCase { 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() + diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java index 273a03432b..7749e77224 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java @@ -1,19 +1,20 @@ -/* -* 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; @@ -29,7 +30,7 @@ import org.apache.poi.hwpf.HWPFDocument; /** * Test the shapes handling */ -public class TestShapes extends TestCase { +public final class TestShapes extends TestCase { private String dirname = System.getProperty("HWPF.testdata.path"); /** @@ -54,14 +55,14 @@ public class TestShapes extends TestCase { 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();