From: Yegor Kozlov Date: Sat, 21 Nov 2009 15:30:54 +0000 (+0000) Subject: included poi-ooxml-schemas and poi-examples in the release cycle, also misc improveme... X-Git-Tag: REL_3_6~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=437182aa72b8b3f97a44357f93679be998e83878;p=poi.git included poi-ooxml-schemas and poi-examples in the release cycle, also misc improvements in build.xml: merged scratchpad and main examples, improved cross-module classpath dependencies, removed obsolete targets git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@882927 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index 7bc888f386..51f2b5bd54 100644 --- a/build.xml +++ b/build.xml @@ -27,6 +27,7 @@ under the License. Rainer Klute klute@rainer-klute.de Bruno Girin brunogirin@gmail.com + Yegor Kozlov yegor at apache.org This build was tested with ant 1.6.2 although it will probably work with other versions. The following jar files should be available on the @@ -36,9 +37,6 @@ under the License. ======= ======== junit(3.8+) http://www.junit.org - The ant jar "optional.jar" should also be available otherwise the - build will fail. - To build the documentation you will need to install forrest and set the FORREST_HOME environment variable. Forrest 0.5.1 required. @@ -48,160 +46,184 @@ under the License. happens to you, try giving Ant some more memory when you run it, eg: ANT_OPTS="-Xmx1024m -XX:MaxPermSize=256m" ant test - - TO BE COMPLETED: - - Convert book.xml files to a sitemap. - --> - The Apache POI project Ant build. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + The Apache POI project Ant build. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - - - - - - + + + - - - - + + + + + + + - - - + + + + + + + + + + + + + + @@ -212,80 +234,65 @@ under the License. - - - - - - Execute "ant -projecthelp" to view a listing of the main build - targets. - - Execute "ant help-properties" to view a listing of some properties - controlling the build process. - - + + + + - Execute "ant -projecthelp" to view a listing of the main build + targets. + - Execute "ant help-properties" to view a listing of some properties + controlling the build process. + + + + + The following properties control the build process: - - - The following properties control the build process: + -Ddisconnected="true": Do not execute any targets that require an online + connection to the Internet. + -Dtestcase=org.apache.poi.xxx.xxx : for the single-test target, specify + the test to run + -Dfilename=xxxx.xls : for the command line task targets, specify the + file to run against - -Ddisconnected="true": Do not execute any targets that require an online - connection to the Internet. - -Dtestcase=org.apache.poi.xxx.xxx : for the single-test target, specify - the test to run - -Dfilename=xxxx.xls : for the command line task targets, specify the - file to run against + WARNING: This list is not exhaustive. + + - WARNING: This list is not exhaustive. - - + + + - - - - - - - - - - - - - - + + + + + + - - - + - - - - - - - - - + + - + @@ -302,18 +309,19 @@ under the License. + description="Fetches needed JAR files from the Internet"> + - - + + - - + + - - + + @@ -331,25 +339,26 @@ under the License. - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + @@ -358,17 +367,17 @@ under the License. - + + description="Fetches needed OOXML xsd files from the Internet"> - - - - - - - + + + + + + + @@ -377,307 +386,206 @@ under the License. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + @@ -696,22 +604,13 @@ under the License. - - - - - - - - - - - - - - + + + + - @@ -727,27 +626,6 @@ under the License. - - - - - - - - - - - - - - - - - - - - - @@ -755,20 +633,18 @@ under the License. - - + + - - - - + - @@ -791,22 +667,26 @@ under the License. + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + @@ -815,19 +695,20 @@ under the License. - - - - - - - - - - - + + + + + + + + + + + + @@ -836,34 +717,26 @@ under the License. Please install Apache Forrest (see -<http://forrest.apache.org/index.html>) and set the -FORREST_HOME environment variable! + <http://forrest.apache.org/index.html>) and set the + FORREST_HOME environment variable! + - - - - - - + unless="main.docs.notRequired" description="Builds the POI website"> - - - - - - - + + + + + file="${build.site.src}/src/documentation/content/xdocs/status.xml" + tofile="${build.site.src}/status.xml"/> - + @@ -875,322 +748,328 @@ FORREST_HOME environment variable! + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - POI API Documentation]]> - - Copyright ${tstamp.year} The Apache Software Foundation or + POI API Documentation]]> + + Copyright ${tstamp.year} The Apache Software Foundation or its licensors, as applicable.]]> - - - DDF - Dreadful Drawing Format - - - - HPSF - Horrible Property Set Format - - - - HSSF - Horrible Spreadsheet Format - - - - HWPF - Horrible Word Processor Format - - - - POIFS - POI File System - - - - Utilities - - - - Examples - - - - - - + + + DDF - Dreadful Drawing Format + + + + HPSF - Horrible Property Set Format + + + + HSSF - Horrible Spreadsheet Format + + + + HWPF - Horrible Word Processor Format + + + + POIFS - POI File System + + + + Utilities + + + + Examples + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + - - - - - - - - - - - - + + + - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Creating Maven POMs + + + + Generating MD5 Checksums + + + + + + Distribution located in build/dist - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Creating Maven POMs - - - Distribution located in build/dist - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdepend.xsl b/jdepend.xsl deleted file mode 100644 index 4fd00012ba..0000000000 --- a/jdepend.xsl +++ /dev/null @@ -1,278 +0,0 @@ - - - - - - - - - - - JDepend Analysis - - - - - - - - -

JDepend Analysis

-

Designed for use with JDepend and Ant.

-
- -
-

Summary

-
- [summary] - [packages] - [cycles] - [explanations] -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PackageTotal ClassesAbstract ClassesConcrete ClassesAfferent CouplingsEfferent CouplingsAbstractnessInstabilityDistance
- - #PK - - - -
- -
- -
-

Packages

-
- [summary] - [packages] - [cycles] - [explanations] -
- - - -

PK -

- - - - - - - -
Afferent Couplings: Efferent Couplings: Abstractness: Instability: Distance:
- - - - - - - - - - - - - - -
Abstract ClassesConcrete ClassesUsed by PackagesUses Packages
- - None - - -
-
-
- - None - - -
-
-
- - None - - - - #PK - -
-
-
- - None - - - - #PK - -
-
-
-
-
- -
-

Cycles

-
- [summary] - [packages] - [cycles] - [explanations] -
- - -

There are no cyclic dependancies.

-
- -

- -
-

-
- -
-

Explanations

-
- [summary] - [packages] - [cycles] - [explanations] -
- -

The following explanations are for quick reference and are lifted directly from the original JDepend documentation.

- -

Number of Classes

-

The number of concrete and abstract classes (and interfaces) in the package is an indicator of the extensibility of the package.

-

Afferent Couplings

-

The number of other packages that depend upon classes within the package is an indicator of the package's responsibility.

-

Efferent Couplings

-

The number of other packages that the classes in the package depend upon is an indicator of the package's independence.

-

Abstractness

-

The ratio of the number of abstract classes (and interfaces) in the analyzed package to the total number of classes in the analyzed package.

-

The range for this metric is 0 to 1, with A=0 indicating a completely concrete package and A=1 indicating a completely abstract package.

-

Instability

-

The ratio of efferent coupling (Ce) to total coupling (Ce / (Ce + Ca)). This metric is an indicator of the package's resilience to change.

-

The range for this metric is 0 to 1, with I=0 indicating a completely stable package and I=1 indicating a completely instable package.

-

Distance

-

The perpendicular distance of a package from the idealized line A + I = 1. This metric is an indicator of the package's balance between abstractness and stability.

-

A package squarely on the main sequence is optimally balanced with respect to its abstractness and stability. Ideal packages are either completely abstract and stable (x=0, y=1) or completely concrete and instable (x=1, y=0).

-

The range for this metric is 0 to 1, with D=0 indicating a package that is coincident with the main sequence and D=1 indicating a package that is as far from the main sequence as possible.

- - - -
- -
diff --git a/maven/mvn-deploy.sh b/maven/mvn-deploy.sh index e228addf02..84a509e481 100755 --- a/maven/mvn-deploy.sh +++ b/maven/mvn-deploy.sh @@ -47,19 +47,33 @@ mvn gpg:sign-and-deploy-file -DrepositoryId=apache-releases -P apache-releases \ -Durl=$M2_REPOSITORY \ -Dfile=poi-@VERSION@-@DSTAMP@.jar -DpomFile=poi-@VERSION@.pom scp poi-@VERSION@.pom.asc $M2_SCP/org/apache/poi/poi/@VERSION@/ +scp poi-@VERSION@-sources.* $M2_SCP/org/apache/poi/poi/@VERSION@/ mvn gpg:sign-and-deploy-file -DrepositoryId=apache-releases -P apache-releases \ -Durl=$M2_REPOSITORY \ -Dfile=poi-scratchpad-@VERSION@-@DSTAMP@.jar -DpomFile=poi-scratchpad-@VERSION@.pom scp poi-scratchpad-@VERSION@.pom.asc $M2_SCP/org/apache/poi/poi-scratchpad/@VERSION@/ +scp poi-scratchpad-@VERSION@-sources.* $M2_SCP/org/apache/poi/poi-scratchpad/@VERSION@/ mvn gpg:sign-and-deploy-file -DrepositoryId=apache-releases -P apache-releases \ -Durl=$M2_REPOSITORY \ -Dfile=poi-contrib-@VERSION@-@DSTAMP@.jar -DpomFile=poi-contrib-@VERSION@.pom scp poi-contrib-@VERSION@.pom.asc $M2_SCP/org/apache/poi/poi-contrib/@VERSION@/ +scp poi-contrib-@VERSION@-sources.* $M2_SCP/org/apache/poi/poi-contrib/@VERSION@/ mvn gpg:sign-and-deploy-file -DrepositoryId=apache-releases -P apache-releases \ -Durl=$M2_REPOSITORY \ -Dfile=poi-ooxml-@VERSION@-@DSTAMP@.jar -DpomFile=poi-ooxml-@VERSION@.pom scp poi-ooxml-@VERSION@.pom.asc $M2_SCP/org/apache/poi/poi-ooxml/@VERSION@/ +scp poi-ooxml-@VERSION@-sources.* $M2_SCP/org/apache/poi/poi-ooxml/@VERSION@/ + +mvn gpg:sign-and-deploy-file -DrepositoryId=apache-releases -P apache-releases \ + -Durl=$M2_REPOSITORY \ + -Dfile=poi-ooxml-schemas-@VERSION@-@DSTAMP@.jar -DpomFile=poi-ooxml-schemas-@VERSION@.pom +scp poi-ooxml-schemas-@VERSION@.pom.asc $M2_SCP/org/apache/poi/poi-ooxml-schemas/@VERSION@/ + +mvn gpg:sign-and-deploy-file -DrepositoryId=apache-releases -P apache-releases \ + -Durl=$M2_REPOSITORY \ + -Dfile=poi-examples-@VERSION@-@DSTAMP@.jar -DpomFile=poi-examples-@VERSION@.pom +scp poi-examples-@VERSION@.pom.asc $M2_SCP/org/apache/poi/poi-examples/@VERSION@/ diff --git a/maven/poi-examples.pom b/maven/poi-examples.pom new file mode 100644 index 0000000000..249f2500fe --- /dev/null +++ b/maven/poi-examples.pom @@ -0,0 +1,78 @@ + + + + + + 4.0.0 + org.apache.poi + poi-examples + @VERSION@ + jar + Apache POI + http://poi.apache.org/ + Apache POI Examples + + + + POI Users List + user-subscribe@poi.apache.org + user-unsubscribe@poi.apache.org + http://mail-archives.apache.org/mod_mbox/poi-user/ + + + POI Developer List + dev-subscribe@poi.apache.org + dev-unsubscribe@poi.apache.org + http://mail-archives.apache.org/mod_mbox/poi-dev/ + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + Apache Software Foundation + http://www.apache.org/ + + + + + org.apache.poi + poi + @VERSION@ + + + org.apache.poi + poi-scratchpad + @VERSION@ + + + org.apache.poi + poi-ooxml + @VERSION@ + + + diff --git a/maven/poi-ooxml-schemas.pom b/maven/poi-ooxml-schemas.pom new file mode 100755 index 0000000000..361fe64f3f --- /dev/null +++ b/maven/poi-ooxml-schemas.pom @@ -0,0 +1,68 @@ + + + + + + 4.0.0 + org.apache.poi + poi-ooxml-schemas + @VERSION@ + jar + Apache POI + http://poi.apache.org/ + Apache POI - Java API To Access Microsoft Format Files + + + + POI Users List + user-subscribe@poi.apache.org + user-unsubscribe@poi.apache.org + http://mail-archives.apache.org/mod_mbox/poi-user/ + + + POI Developer List + dev-subscribe@poi.apache.org + dev-unsubscribe@poi.apache.org + http://mail-archives.apache.org/mod_mbox/poi-dev/ + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + Apache Software Foundation + http://www.apache.org/ + + + + + org.apache.xmlbeans + xmlbeans + 2.3.0 + + + diff --git a/maven/poi-ooxml.pom b/maven/poi-ooxml.pom index 52c1583df1..3f32c8cab7 100644 --- a/maven/poi-ooxml.pom +++ b/maven/poi-ooxml.pom @@ -66,8 +66,8 @@ org.apache.poi - ooxml-schemas - 1.0 + poi-ooxml-schemas + @VERSION@ dom4j diff --git a/src/documentation/content/xdocs/howtobuild.xml b/src/documentation/content/xdocs/howtobuild.xml index 27a5e9e21a..83bde6d9e1 100644 --- a/src/documentation/content/xdocs/howtobuild.xml +++ b/src/documentation/content/xdocs/howtobuild.xml @@ -95,19 +95,23 @@ test - Run all unit tests from main, contrib and scratchpad (Requires JUnit) + Run all unit tests from main, ooxml, contrib and scratchpad jar Produce jar files + + assemble + Produce .zip and tar.gz distribution packages + docs Generate all documentation (Requires Apache Forrest) dist - Create a distribution (Requires JUnit and Apache Forrest) + Create a distribution (Apache Forrest) diff --git a/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java b/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java new file mode 100644 index 0000000000..91621339b4 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java b/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java new file mode 100644 index 0000000000..3a97b61aa0 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java b/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java new file mode 100644 index 0000000000..c20a2f186f --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/DataExtraction.java b/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java new file mode 100644 index 0000000000..a278e894b6 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java b/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java new file mode 100644 index 0000000000..b3d85640e0 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java b/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java new file mode 100644 index 0000000000..3ebcecc90f --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java @@ -0,0 +1,51 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT 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.HeadersFooters; +import org.apache.poi.hslf.model.Slide; + +import java.io.FileOutputStream; + +/** + * Demonstrates how to set headers / footers + * + * @author Yegor Kozlov + */ +public class HeadersFootersDemo { + public static void main(String[] args) throws Exception { + SlideShow ppt = new SlideShow(); + + HeadersFooters slideHeaders = ppt.getSlideHeadersFooters(); + slideHeaders.setFootersText("Created by POI-HSLF"); + slideHeaders.setSlideNumberVisible(true); + slideHeaders.setDateTimeText("custom date time"); + + HeadersFooters notesHeaders = ppt.getNotesHeadersFooters(); + notesHeaders.setFootersText("My notes footers"); + notesHeaders.setHeaderText("My notes header"); + + Slide slide = ppt.createSlide(); + + FileOutputStream out = new FileOutputStream("headers_footers.ppt"); + ppt.write(out); + out.close(); + + } + +} diff --git a/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java b/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java new file mode 100644 index 0000000000..968426c513 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java b/src/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java new file mode 100644 index 0000000000..2371f0fbf6 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java @@ -0,0 +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 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/examples/src/org/apache/poi/hslf/examples/SoundFinder.java b/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java new file mode 100644 index 0000000000..b31019db94 --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java @@ -0,0 +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.ddf.*; +import org.apache.poi.hslf.model.*; +import org.apache.poi.hslf.record.InteractiveInfo; +import org.apache.poi.hslf.record.InteractiveInfoAtom; +import org.apache.poi.hslf.record.Record; +import org.apache.poi.hslf.usermodel.*; +import java.io.FileInputStream; +import java.util.Iterator; +import java.util.List; + +/** + * For each slide iterate over shapes and found associated sound data. + * + * @author Yegor Kozlov + */ +public class SoundFinder { + public static void main(String[] args) throws Exception { + SlideShow ppt = new SlideShow(new FileInputStream(args[0])); + SoundData[] sounds = ppt.getSoundData(); + + 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++) { + int soundRef = getSoundReference(shape[j]); + if(soundRef != -1) { + System.out.println("Slide["+i+"], shape["+j+"], soundRef: "+soundRef); + System.out.println(" " + sounds[soundRef].getSoundName()); + System.out.println(" " + sounds[soundRef].getSoundType()); + } + } + } + } + + /** + * Check if a given shape is associated with a sound. + * @return 0-based reference to a sound in the sound collection + * or -1 if the shape is not associated with a sound + */ + protected static int getSoundReference(Shape shape){ + int soundRef = -1; + //dive into the shape container and search for InteractiveInfoAtom + EscherContainerRecord spContainer = shape.getSpContainer(); + List spchild = spContainer.getChildRecords(); + for (Iterator it = spchild.iterator(); it.hasNext();) { + EscherRecord obj = (EscherRecord) it.next(); + if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) { + byte[] data = obj.serialize(); + Record[] records = Record.findChildRecords(data, 8, +data.length - 8); + for (int j = 0; j < records.length; j++) { + if (records[j] instanceof InteractiveInfo) { + InteractiveInfoAtom info = ((InteractiveInfo)records[j]).getInteractiveInfoAtom(); + if (info.getAction() == InteractiveInfoAtom.ACTION_MEDIA) { + soundRef = info.getSoundRef(); + } + } + } + } + } + return soundRef; + } +} diff --git a/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java b/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java new file mode 100644 index 0000000000..44935c05ac --- /dev/null +++ b/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java @@ -0,0 +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 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/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java b/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java new file mode 100644 index 0000000000..546334bdaf --- /dev/null +++ b/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java @@ -0,0 +1,185 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT 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.hsmf.examples; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.Map; + +import org.apache.poi.hsmf.MAPIMessage; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; + +/** + * Reads one or several Outlook MSG files and for each of them creates + * a text file from available chunks and a directory that contains + * attachments. + * + * @author Bruno Girin + * + */ +public class Msg2txt { + + /** + * The stem used to create file names for the text file and the directory + * that contains the attachments. + */ + private String fileNameStem; + + /** + * The Outlook MSG file being processed. + */ + private MAPIMessage msg; + + public Msg2txt(String fileName) throws IOException { + fileNameStem = fileName; + if(fileNameStem.endsWith(".msg") || fileNameStem.endsWith(".MSG")) { + fileNameStem = fileNameStem.substring(0, fileNameStem.length() - 4); + } + msg = new MAPIMessage(fileName); + } + + /** + * Processes the message. + * + * @throws IOException if an exception occurs while writing the message out + */ + public void processMessage() throws IOException { + String txtFileName = fileNameStem + ".txt"; + String attDirName = fileNameStem + "-att"; + PrintWriter txtOut = null; + try { + txtOut = new PrintWriter(txtFileName); + try { + String displayFrom = msg.getDisplayFrom(); + txtOut.println("From: "+displayFrom); + } catch (ChunkNotFoundException e) { + // ignore + } + try { + String displayTo = msg.getDisplayTo(); + txtOut.println("To: "+displayTo); + } catch (ChunkNotFoundException e) { + // ignore + } + try { + String displayCC = msg.getDisplayCC(); + txtOut.println("CC: "+displayCC); + } catch (ChunkNotFoundException e) { + // ignore + } + try { + String displayBCC = msg.getDisplayBCC(); + txtOut.println("BCC: "+displayBCC); + } catch (ChunkNotFoundException e) { + // ignore + } + try { + String subject = msg.getSubject(); + txtOut.println("Subject: "+subject); + } catch (ChunkNotFoundException e) { + // ignore + } + try { + String body = msg.getTextBody(); + txtOut.println(body); + } catch (ChunkNotFoundException e) { + System.err.println("No message body"); + } + Map attachmentMap = msg.getAttachmentFiles(); + if(attachmentMap.size() > 0) { + File d = new File(attDirName); + if(d.mkdir()) { + for( + Iterator ii = attachmentMap.entrySet().iterator(); + ii.hasNext(); + ) { + Map.Entry entry = (Map.Entry)ii.next(); + processAttachment(d, entry.getKey().toString(), + (ByteArrayInputStream)entry.getValue()); + } + } else { + System.err.println("Can't create directory "+attDirName); + } + } + } finally { + if(txtOut != null) { + txtOut.close(); + } + } + } + + /** + * Processes a single attachment: reads it from the Outlook MSG file and + * writes it to disk as an individual file. + * + * @param dir the directory in which to write the attachment file + * @param fileName the name of the attachment file + * @param fileIn the input stream that contains the attachment's data + * @throws IOException when any of the file operations fails + */ + public void processAttachment(File dir, String fileName, + ByteArrayInputStream fileIn) throws IOException { + File f = new File(dir, fileName); + OutputStream fileOut = null; + try { + fileOut = new FileOutputStream(f); + byte[] buffer = new byte[2048]; + int bNum = fileIn.read(buffer); + while(bNum > 0) { + fileOut.write(buffer); + bNum = fileIn.read(buffer); + } + } finally { + try { + if(fileIn != null) { + fileIn.close(); + } + } finally { + if(fileOut != null) { + fileOut.close(); + } + } + } + } + + /** + * Processes the list of arguments as a list of names of Outlook MSG files. + * + * @param args the list of MSG files to process + */ + public static void main(String[] args) { + if(args.length <= 0) { + System.err.println("No files names provided"); + } else { + for(int i = 0; i < args.length; i++) { + try { + Msg2txt processor = new Msg2txt(args[i]); + processor.processMessage(); + } catch (IOException e) { + System.err.println("Could not process "+args[i]+": "+e); + } + } + } + } + +} diff --git a/src/examples/src/org/apache/poi/hwpf/Word2Forrest.java b/src/examples/src/org/apache/poi/hwpf/Word2Forrest.java new file mode 100644 index 0000000000..82d3a8a230 --- /dev/null +++ b/src/examples/src/org/apache/poi/hwpf/Word2Forrest.java @@ -0,0 +1,225 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT 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; + +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.usermodel.*; +import org.apache.poi.hwpf.model.*; + +import java.io.*; + +public final class Word2Forrest +{ + Writer _out; + HWPFDocument _doc; + + public Word2Forrest(HWPFDocument doc, OutputStream stream) + throws IOException, UnsupportedEncodingException + { + OutputStreamWriter out = new OutputStreamWriter (stream, "UTF-8"); + _out = out; + _doc = doc; + + init (); + openDocument (); + openBody (); + + Range r = doc.getRange (); + StyleSheet styleSheet = doc.getStyleSheet (); + + int sectionLevel = 0; + int lenParagraph = r.numParagraphs (); + boolean inCode = false; + for (int x = 0; x < lenParagraph; x++) + { + Paragraph p = r.getParagraph (x); + String text = p.text (); + if (text.trim ().length () == 0) + { + continue; + } + StyleDescription paragraphStyle = styleSheet.getStyleDescription (p. + getStyleIndex ()); + String styleName = paragraphStyle.getName(); + if (styleName.startsWith ("Heading")) + { + if (inCode) + { + closeSource(); + inCode = false; + } + + int headerLevel = Integer.parseInt (styleName.substring (8)); + if (headerLevel > sectionLevel) + { + openSection (); + } + else + { + for (int y = 0; y < (sectionLevel - headerLevel) + 1; y++) + { + closeSection (); + } + openSection (); + } + sectionLevel = headerLevel; + openTitle (); + writePlainText (text); + closeTitle (); + } + else + { + int cruns = p.numCharacterRuns (); + CharacterRun run = p.getCharacterRun (0); + String fontName = run.getFontName(); + if (fontName.startsWith ("Courier")) + { + if (!inCode) + { + openSource (); + inCode = true; + } + writePlainText (p.text()); + } + else + { + if (inCode) + { + inCode = false; + closeSource(); + } + openParagraph(); + writePlainText(p.text()); + closeParagraph(); + } + } + } + for (int x = 0; x < sectionLevel; x++) + { + closeSection(); + } + closeBody(); + closeDocument(); + _out.flush(); + + } + + public void init () + throws IOException + { + _out.write ("\r\n"); + _out.write ("\r\n"); + } + + public void openDocument () + throws IOException + { + _out.write ("\r\n"); + } + public void closeDocument () + throws IOException + { + _out.write ("\r\n"); + } + + + public void openBody () + throws IOException + { + _out.write ("\r\n"); + } + + public void closeBody () + throws IOException + { + _out.write ("\r\n"); + } + + + public void openSection () + throws IOException + { + _out.write ("
"); + + } + + public void closeSection () + throws IOException + { + _out.write ("
"); + + } + + public void openTitle () + throws IOException + { + _out.write (""); + } + + public void closeTitle () + throws IOException + { + _out.write (""); + } + + public void writePlainText (String text) + throws IOException + { + _out.write (text); + } + + public void openParagraph () + throws IOException + { + _out.write ("

"); + } + + public void closeParagraph () + throws IOException + { + _out.write ("

"); + } + + public void openSource () + throws IOException + { + _out.write (""); + } + + + public static void main(String[] args) + { + try + { + OutputStream out = new FileOutputStream("c:\\test.xml"); + + new Word2Forrest(new HWPFDocument(new FileInputStream(args[0])), out); + out.close(); + } + catch (Throwable t) + { + t.printStackTrace(); + } + + } +} diff --git a/src/ooxml/java/org/apache/poi/util/OOXMLLite.java b/src/ooxml/java/org/apache/poi/util/OOXMLLite.java index 881f5085be..e533373ba3 100755 --- a/src/ooxml/java/org/apache/poi/util/OOXMLLite.java +++ b/src/ooxml/java/org/apache/poi/util/OOXMLLite.java @@ -82,7 +82,7 @@ public final class OOXMLLite { List lst = new ArrayList(); //collect unit tests - System.out.println("Collecting unit tests"); + System.out.println("Collecting unit tests from " + _testDir); collectTests(_testDir, _testDir, lst, ".+?\\.Test.+?\\.class$"); TestSuite suite = new TestSuite(); @@ -100,11 +100,10 @@ public final class OOXMLLite { } //run tests - System.out.println("Running tests"); TestRunner.run(suite); //see what classes from the ooxml-schemas.jar are loaded - System.out.println("Copying classes"); + System.out.println("Copying classes to " + _destDest); Map> classes = getLoadedClasses(_ooxmlJar.getName()); for (Class cls : classes.values()) { String className = cls.getName(); diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java index 421b979e3a..7ef1f002c3 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java @@ -26,9 +26,7 @@ import org.apache.poi.POIDataSamples; import org.apache.poi.hdgf.extractor.VisioTextExtractor; import org.apache.poi.hslf.extractor.PowerPointExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor; -import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hwpf.extractor.WordExtractor; -import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor; diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java b/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java index 945ffebe6d..ac382ab82c 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java @@ -17,7 +17,6 @@ package org.apache.poi.xwpf; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.POIDataSamples; import java.io.*; diff --git a/src/resources/scratchpad/org/apache/poi/hslf/data/empty.ppt b/src/resources/scratchpad/org/apache/poi/hslf/data/empty.ppt new file mode 100644 index 0000000000..20d2398e39 Binary files /dev/null and b/src/resources/scratchpad/org/apache/poi/hslf/data/empty.ppt differ 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 deleted file mode 100644 index 91621339b4..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java +++ /dev/null @@ -1,516 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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 deleted file mode 100644 index 3a97b61aa0..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java +++ /dev/null @@ -1,62 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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 deleted file mode 100644 index c20a2f186f..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java +++ /dev/null @@ -1,60 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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 deleted file mode 100644 index a278e894b6..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java +++ /dev/null @@ -1,148 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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 deleted file mode 100644 index b3d85640e0..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java +++ /dev/null @@ -1,80 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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/HeadersFootersDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java deleted file mode 100644 index 3ebcecc90f..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java +++ /dev/null @@ -1,51 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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.HeadersFooters; -import org.apache.poi.hslf.model.Slide; - -import java.io.FileOutputStream; - -/** - * Demonstrates how to set headers / footers - * - * @author Yegor Kozlov - */ -public class HeadersFootersDemo { - public static void main(String[] args) throws Exception { - SlideShow ppt = new SlideShow(); - - HeadersFooters slideHeaders = ppt.getSlideHeadersFooters(); - slideHeaders.setFootersText("Created by POI-HSLF"); - slideHeaders.setSlideNumberVisible(true); - slideHeaders.setDateTimeText("custom date time"); - - HeadersFooters notesHeaders = ppt.getNotesHeadersFooters(); - notesHeaders.setFootersText("My notes footers"); - notesHeaders.setHeaderText("My notes header"); - - Slide slide = ppt.createSlide(); - - FileOutputStream out = new FileOutputStream("headers_footers.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 deleted file mode 100644 index 968426c513..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java +++ /dev/null @@ -1,81 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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 deleted file mode 100644 index 2371f0fbf6..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java +++ /dev/null @@ -1,107 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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/SoundFinder.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/SoundFinder.java deleted file mode 100644 index b31019db94..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/SoundFinder.java +++ /dev/null @@ -1,80 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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.ddf.*; -import org.apache.poi.hslf.model.*; -import org.apache.poi.hslf.record.InteractiveInfo; -import org.apache.poi.hslf.record.InteractiveInfoAtom; -import org.apache.poi.hslf.record.Record; -import org.apache.poi.hslf.usermodel.*; -import java.io.FileInputStream; -import java.util.Iterator; -import java.util.List; - -/** - * For each slide iterate over shapes and found associated sound data. - * - * @author Yegor Kozlov - */ -public class SoundFinder { - public static void main(String[] args) throws Exception { - SlideShow ppt = new SlideShow(new FileInputStream(args[0])); - SoundData[] sounds = ppt.getSoundData(); - - 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++) { - int soundRef = getSoundReference(shape[j]); - if(soundRef != -1) { - System.out.println("Slide["+i+"], shape["+j+"], soundRef: "+soundRef); - System.out.println(" " + sounds[soundRef].getSoundName()); - System.out.println(" " + sounds[soundRef].getSoundType()); - } - } - } - } - - /** - * Check if a given shape is associated with a sound. - * @return 0-based reference to a sound in the sound collection - * or -1 if the shape is not associated with a sound - */ - protected static int getSoundReference(Shape shape){ - int soundRef = -1; - //dive into the shape container and search for InteractiveInfoAtom - EscherContainerRecord spContainer = shape.getSpContainer(); - List spchild = spContainer.getChildRecords(); - for (Iterator it = spchild.iterator(); it.hasNext();) { - EscherRecord obj = (EscherRecord) it.next(); - if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) { - byte[] data = obj.serialize(); - Record[] records = Record.findChildRecords(data, 8, -data.length - 8); - for (int j = 0; j < records.length; j++) { - if (records[j] instanceof InteractiveInfo) { - InteractiveInfoAtom info = ((InteractiveInfo)records[j]).getInteractiveInfoAtom(); - if (info.getAction() == InteractiveInfoAtom.ACTION_MEDIA) { - soundRef = info.getSoundRef(); - } - } - } - } - } - return soundRef; - } -} 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 deleted file mode 100644 index 44935c05ac..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java +++ /dev/null @@ -1,127 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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/hsmf/examples/Msg2txt.java b/src/scratchpad/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java deleted file mode 100644 index 546334bdaf..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java +++ /dev/null @@ -1,185 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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.hsmf.examples; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.Iterator; -import java.util.Map; - -import org.apache.poi.hsmf.MAPIMessage; -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; - -/** - * Reads one or several Outlook MSG files and for each of them creates - * a text file from available chunks and a directory that contains - * attachments. - * - * @author Bruno Girin - * - */ -public class Msg2txt { - - /** - * The stem used to create file names for the text file and the directory - * that contains the attachments. - */ - private String fileNameStem; - - /** - * The Outlook MSG file being processed. - */ - private MAPIMessage msg; - - public Msg2txt(String fileName) throws IOException { - fileNameStem = fileName; - if(fileNameStem.endsWith(".msg") || fileNameStem.endsWith(".MSG")) { - fileNameStem = fileNameStem.substring(0, fileNameStem.length() - 4); - } - msg = new MAPIMessage(fileName); - } - - /** - * Processes the message. - * - * @throws IOException if an exception occurs while writing the message out - */ - public void processMessage() throws IOException { - String txtFileName = fileNameStem + ".txt"; - String attDirName = fileNameStem + "-att"; - PrintWriter txtOut = null; - try { - txtOut = new PrintWriter(txtFileName); - try { - String displayFrom = msg.getDisplayFrom(); - txtOut.println("From: "+displayFrom); - } catch (ChunkNotFoundException e) { - // ignore - } - try { - String displayTo = msg.getDisplayTo(); - txtOut.println("To: "+displayTo); - } catch (ChunkNotFoundException e) { - // ignore - } - try { - String displayCC = msg.getDisplayCC(); - txtOut.println("CC: "+displayCC); - } catch (ChunkNotFoundException e) { - // ignore - } - try { - String displayBCC = msg.getDisplayBCC(); - txtOut.println("BCC: "+displayBCC); - } catch (ChunkNotFoundException e) { - // ignore - } - try { - String subject = msg.getSubject(); - txtOut.println("Subject: "+subject); - } catch (ChunkNotFoundException e) { - // ignore - } - try { - String body = msg.getTextBody(); - txtOut.println(body); - } catch (ChunkNotFoundException e) { - System.err.println("No message body"); - } - Map attachmentMap = msg.getAttachmentFiles(); - if(attachmentMap.size() > 0) { - File d = new File(attDirName); - if(d.mkdir()) { - for( - Iterator ii = attachmentMap.entrySet().iterator(); - ii.hasNext(); - ) { - Map.Entry entry = (Map.Entry)ii.next(); - processAttachment(d, entry.getKey().toString(), - (ByteArrayInputStream)entry.getValue()); - } - } else { - System.err.println("Can't create directory "+attDirName); - } - } - } finally { - if(txtOut != null) { - txtOut.close(); - } - } - } - - /** - * Processes a single attachment: reads it from the Outlook MSG file and - * writes it to disk as an individual file. - * - * @param dir the directory in which to write the attachment file - * @param fileName the name of the attachment file - * @param fileIn the input stream that contains the attachment's data - * @throws IOException when any of the file operations fails - */ - public void processAttachment(File dir, String fileName, - ByteArrayInputStream fileIn) throws IOException { - File f = new File(dir, fileName); - OutputStream fileOut = null; - try { - fileOut = new FileOutputStream(f); - byte[] buffer = new byte[2048]; - int bNum = fileIn.read(buffer); - while(bNum > 0) { - fileOut.write(buffer); - bNum = fileIn.read(buffer); - } - } finally { - try { - if(fileIn != null) { - fileIn.close(); - } - } finally { - if(fileOut != null) { - fileOut.close(); - } - } - } - } - - /** - * Processes the list of arguments as a list of names of Outlook MSG files. - * - * @param args the list of MSG files to process - */ - public static void main(String[] args) { - if(args.length <= 0) { - System.err.println("No files names provided"); - } else { - for(int i = 0; i < args.length; i++) { - try { - Msg2txt processor = new Msg2txt(args[i]); - processor.processMessage(); - } catch (IOException e) { - System.err.println("Could not process "+args[i]+": "+e); - } - } - } - } - -} diff --git a/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java b/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java deleted file mode 100644 index 82d3a8a230..0000000000 --- a/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java +++ /dev/null @@ -1,225 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 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; - -import org.apache.poi.hwpf.HWPFDocument; -import org.apache.poi.hwpf.usermodel.*; -import org.apache.poi.hwpf.model.*; - -import java.io.*; - -public final class Word2Forrest -{ - Writer _out; - HWPFDocument _doc; - - public Word2Forrest(HWPFDocument doc, OutputStream stream) - throws IOException, UnsupportedEncodingException - { - OutputStreamWriter out = new OutputStreamWriter (stream, "UTF-8"); - _out = out; - _doc = doc; - - init (); - openDocument (); - openBody (); - - Range r = doc.getRange (); - StyleSheet styleSheet = doc.getStyleSheet (); - - int sectionLevel = 0; - int lenParagraph = r.numParagraphs (); - boolean inCode = false; - for (int x = 0; x < lenParagraph; x++) - { - Paragraph p = r.getParagraph (x); - String text = p.text (); - if (text.trim ().length () == 0) - { - continue; - } - StyleDescription paragraphStyle = styleSheet.getStyleDescription (p. - getStyleIndex ()); - String styleName = paragraphStyle.getName(); - if (styleName.startsWith ("Heading")) - { - if (inCode) - { - closeSource(); - inCode = false; - } - - int headerLevel = Integer.parseInt (styleName.substring (8)); - if (headerLevel > sectionLevel) - { - openSection (); - } - else - { - for (int y = 0; y < (sectionLevel - headerLevel) + 1; y++) - { - closeSection (); - } - openSection (); - } - sectionLevel = headerLevel; - openTitle (); - writePlainText (text); - closeTitle (); - } - else - { - int cruns = p.numCharacterRuns (); - CharacterRun run = p.getCharacterRun (0); - String fontName = run.getFontName(); - if (fontName.startsWith ("Courier")) - { - if (!inCode) - { - openSource (); - inCode = true; - } - writePlainText (p.text()); - } - else - { - if (inCode) - { - inCode = false; - closeSource(); - } - openParagraph(); - writePlainText(p.text()); - closeParagraph(); - } - } - } - for (int x = 0; x < sectionLevel; x++) - { - closeSection(); - } - closeBody(); - closeDocument(); - _out.flush(); - - } - - public void init () - throws IOException - { - _out.write ("\r\n"); - _out.write ("\r\n"); - } - - public void openDocument () - throws IOException - { - _out.write ("\r\n"); - } - public void closeDocument () - throws IOException - { - _out.write ("\r\n"); - } - - - public void openBody () - throws IOException - { - _out.write ("\r\n"); - } - - public void closeBody () - throws IOException - { - _out.write ("\r\n"); - } - - - public void openSection () - throws IOException - { - _out.write ("
"); - - } - - public void closeSection () - throws IOException - { - _out.write ("
"); - - } - - public void openTitle () - throws IOException - { - _out.write (""); - } - - public void closeTitle () - throws IOException - { - _out.write (""); - } - - public void writePlainText (String text) - throws IOException - { - _out.write (text); - } - - public void openParagraph () - throws IOException - { - _out.write ("

"); - } - - public void closeParagraph () - throws IOException - { - _out.write ("

"); - } - - public void openSource () - throws IOException - { - _out.write (""); - } - - - public static void main(String[] args) - { - try - { - OutputStream out = new FileOutputStream("c:\\test.xml"); - - new Word2Forrest(new HWPFDocument(new FileInputStream(args[0])), out); - out.close(); - } - catch (Throwable t) - { - t.printStackTrace(); - } - - } -} diff --git a/src/scratchpad/src/Manifest.mf b/src/scratchpad/src/Manifest.mf deleted file mode 100644 index 348f1bdd38..0000000000 --- a/src/scratchpad/src/Manifest.mf +++ /dev/null @@ -1 +0,0 @@ -Manifest-Version: 1.0 \ No newline at end of file diff --git a/src/scratchpad/src/org/apache/poi/hslf/data/empty.ppt b/src/scratchpad/src/org/apache/poi/hslf/data/empty.ppt deleted file mode 100644 index 20d2398e39..0000000000 Binary files a/src/scratchpad/src/org/apache/poi/hslf/data/empty.ppt and /dev/null differ