package org.apache.poi.hslf.examples;
-import org.apache.poi.hslf.usermodel.*;
-
import java.io.FileInputStream;
+import java.util.List;
+
+import org.apache.poi.hslf.usermodel.*;
/**
* Demonstrates how to read hyperlinks from a presentation
HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
- HSLFSlide[] slide = ppt.getSlides();
- for (int j = 0; j < slide.length; j++) {
- System.out.println("slide " + slide[j].getSlideNumber());
+ for (HSLFSlide slide : ppt.getSlides()) {
+ System.out.println("\nslide " + slide.getSlideNumber());
+
+ // read hyperlinks from the slide's text runs
+ System.out.println("- reading hyperlinks from the text runs");
+ for (List<HSLFTextParagraph> txtParas : slide.getTextParagraphs()) {
+ List<HSLFHyperlink> links = HSLFHyperlink.find(txtParas);
+ String text = HSLFTextParagraph.getRawText(txtParas);
- //read hyperlinks from the slide's text runs
- System.out.println("reading hyperlinks from the text runs");
- HSLFTextParagraph[] txt = slide[j].getTextParagraphs();
- for (int k = 0; k < txt.length; k++) {
- String text = txt[k].getRawText();
- HSLFHyperlink[] links = txt[k].getHyperlinks();
- if(links != null) for (int l = 0; l < links.length; l++) {
- HSLFHyperlink 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);
+ for (HSLFHyperlink link : links) {
+ System.out.println(toStr(link, text));
}
}
- //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");
- HSLFShape[] sh = slide[j].getShapes();
- for (int k = 0; k < sh.length; k++) {
- HSLFHyperlink link = sh[k].getHyperlink();
- if(link != null) {
- String title = link.getTitle();
- String address = link.getAddress();
- System.out.println(" " + title);
- System.out.println(" " + address);
- }
+ // 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");
+ for (HSLFShape sh : slide.getShapes()) {
+ HSLFHyperlink link = HSLFHyperlink.find(sh);
+ if (link == null) continue;
+ System.out.println(toStr(link, null));
}
}
-
}
-
}
+
+ static String toStr(HSLFHyperlink link, String rawText) {
+ //in ppt end index is inclusive
+ String formatStr = "title: %1$s, address: %2$s" + (rawText == null ? "" : ", start: %3$s, end: %4$s, substring: %5$s");
+ String substring = (rawText == null) ? "" : rawText.substring(link.getStartIndex(), link.getEndIndex()-1);
+ return String.format(formatStr, link.getTitle(), link.getAddress(), link.getStartIndex(), link.getEndIndex(), substring);
+ }
}
package org.apache.poi.hslf.examples;
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.hslf.model.*;
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import javax.imageio.ImageIO;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.awt.geom.Rectangle2D;
+import org.apache.poi.hslf.usermodel.HSLFSlide;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
/**
* Demonstrates how you can use HSLF to convert each slide into a PNG image
int width = (int)(pgsize.width*scale);
int height = (int)(pgsize.height*scale);
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- if (slidenum != -1 && slidenum != (i+1)) continue;
+ for (HSLFSlide slide : ppt.getSlides()) {
+ if (slidenum != -1 && slidenum != slide.getSlideNumber()) continue;
- String title = slide[i].getTitle();
- System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title));
+ String title = slide.getTitle();
+ System.out.println("Rendering slide "+slide.getSlideNumber() + (title == null ? "" : ": " + title));
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);
- slide[i].draw(graphics);
+ slide.draw(graphics);
- String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png");
+ String fname = file.replaceAll("\\.ppt", "-" + slide.getSlideNumber() + ".png");
FileOutputStream out = new FileOutputStream(fname);
ImageIO.write(img, "png", out);
out.close();
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;
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.*;
+
/**
* For each slide iterate over shapes and found associated sound data.
*
HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(args[0]));
HSLFSoundData[] sounds = ppt.getSoundData();
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- HSLFShape[] 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());
- }
+ for (HSLFSlide slide : ppt.getSlides()) {
+ for (HSLFShape shape : slide.getShapes()) {
+ int soundRef = getSoundReference(shape);
+ if(soundRef == -1) continue;
+
+
+ System.out.println("Slide["+slide.getSlideNumber()+"], shape["+shape.getShapeId()+"], soundRef: "+soundRef);
+ System.out.println(" " + sounds[soundRef].getSoundName());
+ System.out.println(" " + sounds[soundRef].getSoundType());
}
}
}
import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.hslf.model.*;
+import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
+import org.apache.poi.sl.usermodel.VerticalAlignment;
import java.awt.*;
import java.io.FileOutputStream;
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]);
- HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
+ HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
rt.setFontName("Arial");
rt.setFontSize(10);
if(i == 0){
} else {
rt.setBold(true);
}
- cell.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
- cell.setHorizontalAlignment(HSLFTextBox.AlignCenter);
+ cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
+ cell.setHorizontalCentered(true);
+ cell.setText(txt1[i][j]);
}
}
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]);
- HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
+ HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
rt.setFontSize(10);
rt.setFontName("Arial");
if(i == 0){
rt.setFontColor(Color.white);
rt.setBold(true);
rt.setFontSize(14);
- cell.setHorizontalAlignment(HSLFTextBox.AlignCenter);
+ cell.setHorizontalCentered(true);
} else {
- rt.setBullet(true);
+ rt.getTextParagraph().setBullet(true);
rt.setFontSize(12);
- cell.setHorizontalAlignment(HSLFTextBox.AlignLeft);
+ rt.getTextParagraph().setAlignment(TextAlign.LEFT);
+ cell.setHorizontalCentered(false);
}
- cell.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
+ cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
+ cell.setText(txt2[i][j]);
}
}
table2.setColumnWidth(0, 300);
String chartTitle = modelReader.readLine(); // first line is chart title\r
\r
XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]));\r
- XSLFSlide slide = pptx.getSlides()[0];\r
+ XSLFSlide slide = pptx.getSlides().get(0);\r
\r
// find chart in the slide\r
XSLFChart chart = null;\r
/*XSLFSlide blankSlide =*/ ppt.createSlide();\r
\r
\r
- XSLFSlideMaster master = ppt.getSlideMasters()[0];\r
+ XSLFSlideMaster master = ppt.getSlideMasters().get(0);\r
\r
XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE);\r
XSLFSlide slide1 = ppt.createSlide(layout1) ;\r
// blank slide
/*XSLFSlide blankSlide =*/ ppt.createSlide();
- XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
+ XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
// title slide
XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
* @param shape <code>TextRun</code> to lookup hyperlinks in
* @return found hyperlinks or <code>null</code> if not found
*/
- public static HSLFHyperlink[] find(HSLFTextShape shape){
- List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
- HSLFSlideShow ppt = shape.getSheet().getSlideShow();
- //document-level container which stores info about all links in a presentation
- ExObjList exobj = ppt.getDocumentRecord().getExObjList();
- if (exobj == null) {
- return null;
- }
-
- Record[] records = shape.getClientRecords();
- find(records, exobj, lst);
-
- HSLFHyperlink[] links = null;
- if (lst.size() > 0){
- links = new HSLFHyperlink[lst.size()];
- lst.toArray(links);
- }
- return links;
+ public static List<HSLFHyperlink> find(HSLFTextShape shape){
+ return find(shape.getTextParagraphs());
}
/**
* Find hyperlinks in a text paragraph
*
- * @param paragraph <code>TextParagraph</code> to lookup hyperlinks in
- * @return found hyperlinks or <code>null</code> if not found
+ * @param paragraphs List of <code>TextParagraph</code> to lookup hyperlinks
+ * @return found hyperlinks
*/
- public static HSLFHyperlink[] find(HSLFTextParagraph paragraph){
+ public static List<HSLFHyperlink> find(List<HSLFTextParagraph> paragraphs){
List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
- HSLFSlideShow ppt = paragraph.getSheet().getSlideShow();
+ if (paragraphs == null || paragraphs.isEmpty()) return lst;
+
+ HSLFTextParagraph firstPara = paragraphs.get(0);
+
+ HSLFSlideShow ppt = firstPara.getSheet().getSlideShow();
//document-level container which stores info about all links in a presentation
ExObjList exobj = ppt.getDocumentRecord().getExObjList();
- if (exobj == null) {
- return null;
- }
+ if (exobj == null) return lst;
- Record[] records = paragraph.getRecords();
+ Record[] records = firstPara.getRecords();
find(records, exobj, lst);
- HSLFHyperlink[] links = null;
- if (lst.size() > 0){
- links = new HSLFHyperlink[lst.size()];
- lst.toArray(links);
- }
- return links;
+ return lst;
}
/**
if (records == null) return;
for (int i = 0; i < records.length; i++) {
//see if we have InteractiveInfo in the textrun's records
- if( records[i] instanceof InteractiveInfo){
- InteractiveInfo hldr = (InteractiveInfo)records[i];
- InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
- int id = info.getHyperlinkID();
- ExHyperlink linkRecord = exobj.get(id);
- if (linkRecord != null){
- HSLFHyperlink link = new HSLFHyperlink();
- link.title = linkRecord.getLinkTitle();
- link.address = linkRecord.getLinkURL();
- link.type = info.getAction();
-
- if (++i < records.length && records[i] instanceof TxInteractiveInfoAtom){
- TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[i];
- link.startIndex = txinfo.getStartIndex();
- link.endIndex = txinfo.getEndIndex();
- }
- out.add(link);
- }
+ if(!(records[i] instanceof InteractiveInfo)) continue;
+
+ InteractiveInfo hldr = (InteractiveInfo)records[i];
+ InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
+ int id = info.getHyperlinkID();
+ ExHyperlink linkRecord = exobj.get(id);
+ if (linkRecord == null) continue;
+
+ HSLFHyperlink link = new HSLFHyperlink();
+ link.title = linkRecord.getLinkTitle();
+ link.address = linkRecord.getLinkURL();
+ link.type = info.getAction();
+ out.add(link);
+
+ if (i+1 < records.length && records[i+1] instanceof TxInteractiveInfoAtom){
+ TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[++i];
+ link.startIndex = txinfo.getStartIndex();
+ link.endIndex = txinfo.getEndIndex();
}
}
}
// Build up TextRuns from pairs of TextHeaderAtom and
// one of TextBytesAtom or TextCharsAtom
if (_atomSet != null && _atomSet.getSlideRecords().length > 0) {
- List<List<HSLFTextParagraph>> llhtp = HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords());
- _paragraphs.addAll(llhtp);
+ // Grab text from SlideListWithTexts entries
+ _paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()));
if (_paragraphs.isEmpty()) {
throw new RuntimeException("No text records found for slide");
}
// No text on the slide, must just be pictures
}
- // Grab text from SlideListWithTexts entries
- for(List<HSLFTextParagraph> ltp : _paragraphs) {
- for (HSLFTextParagraph tp : ltp) {
- tp.supplySheet(this);
- }
- }
+ // Grab text from slide's PPDrawing
+ _paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(getPPDrawing()));
- // Grab the TextRuns from the PPDrawing
- List<List<HSLFTextParagraph>> llOtherRuns = HSLFTextParagraph.findTextParagraphs(getPPDrawing());
- for (List<HSLFTextParagraph> otherRuns : llOtherRuns) {
- // Grab text from slide's PPDrawing
- for(HSLFTextParagraph tp : otherRuns) {
- tp.supplySheet(this);
- tp.setIndex(-1); // runs found in PPDrawing are not linked with SlideListWithTexts
- }
- }
- _paragraphs.addAll(llOtherRuns);
+ for(List<HSLFTextParagraph> ltp : _paragraphs) {
+ for (HSLFTextParagraph tp : ltp) {
+ tp.supplySheet(this);
+ }
+ }
}
/**
public void setHidden(boolean hidden) {
org.apache.poi.hslf.record.Slide cont = getSlideRecord();
-
- SSSlideInfoAtom slideInfo =
+
+ SSSlideInfoAtom slideInfo =
(SSSlideInfoAtom)cont.findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
if (slideInfo == null) {
slideInfo = new SSSlideInfoAtom();
cont.addChildAfter(slideInfo, cont.findFirstOfType(RecordTypes.SlideAtom.typeID));
}
-
+
slideInfo.setEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT, hidden);
}
-
+
public boolean getHidden() {
- SSSlideInfoAtom slideInfo =
+ SSSlideInfoAtom slideInfo =
(SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
return (slideInfo == null)
? false
public void setFollowMasterColourScheme(boolean follow) {
// TODO Auto-generated method stub
-
+
}
}
SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
List<Record> records = new ArrayList<Record>();
- List<SlideAtomsSet> sa = Arrays.asList(sas);
+ List<SlideAtomsSet> sa = new ArrayList<SlideAtomsSet>(Arrays.asList(sas));
HSLFSlide removedSlide = _slides.remove(index);
_notes.remove(removedSlide.getNotes());
prop.setSubValue(value,index);\r
}\r
\r
+ /**\r
+ * Check and add linebreaks to text runs leading other paragraphs\r
+ *\r
+ * @param paragraphs\r
+ */\r
+ protected static void fixLineEndings(List<HSLFTextParagraph> paragraphs) {\r
+ HSLFTextRun lastRun = null;\r
+ for (HSLFTextParagraph p : paragraphs) {\r
+ if (lastRun != null && !lastRun.getRawText().endsWith("\r")) {\r
+ lastRun.setText(lastRun.getRawText()+"\r");\r
+ }\r
+ List<HSLFTextRun> ltr = p.getTextRuns();\r
+ if (ltr.isEmpty()) {\r
+ throw new RuntimeException("paragraph without textruns found");\r
+ }\r
+ lastRun = ltr.get(ltr.size()-1);\r
+ assert(lastRun.getRawText() != null);\r
+ } \r
+ }\r
+ \r
/**\r
* Saves the modified paragraphs/textrun to the records.\r
* Also updates the styles to the correct text length.\r
*/\r
protected static void storeText(List<HSLFTextParagraph> paragraphs) {\r
+ fixLineEndings(paragraphs);\r
+ \r
String rawText = toInternalString(getRawText(paragraphs));\r
\r
// Will it fit in a 8 bit atom?\r
\r
styleAtom.clearStyles();\r
\r
- TextPropCollection lastPTPC = null, lastRTPC = null;\r
+ TextPropCollection lastPTPC = null, lastRTPC = null, ptpc = null, rtpc = null;\r
for (HSLFTextParagraph para : paragraphs) {\r
- TextPropCollection ptpc = para.getParagraphStyle();\r
+ ptpc = para.getParagraphStyle();\r
ptpc.updateTextSize(0);\r
if (!ptpc.equals(lastPTPC)) {\r
lastPTPC = styleAtom.addParagraphTextPropCollection(0);\r
lastPTPC.copy(ptpc);\r
}\r
for (HSLFTextRun tr : para.getTextRuns()) {\r
- TextPropCollection rtpc = tr.getCharacterStyle();\r
+ rtpc = tr.getCharacterStyle();\r
rtpc.updateTextSize(0);\r
if (!rtpc.equals(lastRTPC)) {\r
lastRTPC = styleAtom.addCharacterTextPropCollection(0);\r
}\r
}\r
\r
- assert(lastPTPC != null && lastRTPC != null);\r
+ assert(lastPTPC != null && lastRTPC != null && ptpc != null && rtpc != null);\r
+ ptpc.updateTextSize(ptpc.getCharactersCovered()+1);\r
+ rtpc.updateTextSize(rtpc.getCharactersCovered()+1);\r
lastPTPC.updateTextSize(lastPTPC.getCharactersCovered()+1);\r
lastRTPC.updateTextSize(lastRTPC.getCharactersCovered()+1);\r
\r
}\r
htr.setText(rawText);\r
}\r
+\r
+ storeText(paragraphs);\r
\r
return htr;\r
}\r
public static List<List<HSLFTextParagraph>> findTextParagraphs(PPDrawing ppdrawing) {\r
List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>();\r
for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) {\r
- // propagate parents to parent-aware records\r
- RecordContainer.handleParentAwareRecords(wrapper);\r
- int shapeId = wrapper.getShapeId();\r
- List<List<HSLFTextParagraph>> rv = findTextParagraphs(wrapper);\r
- for (List<HSLFTextParagraph> htpList : rv) {\r
- for (HSLFTextParagraph htp : htpList) {\r
- htp.setShapeId(shapeId);\r
- }\r
- }\r
- runsV.addAll(rv);\r
+ runsV.addAll(findTextParagraphs(wrapper));\r
}\r
return runsV;\r
}\r
*\r
* @param wrapper an EscherTextboxWrapper\r
*/\r
- protected static List<List<HSLFTextParagraph>> findTextParagraphs(final EscherTextboxWrapper wrapper) {\r
- return findTextParagraphs(wrapper.getChildRecords(), wrapper.getStyleTextProp9Atom());\r
+ protected static List<List<HSLFTextParagraph>> findTextParagraphs(EscherTextboxWrapper wrapper) {\r
+ // propagate parents to parent-aware records\r
+ RecordContainer.handleParentAwareRecords(wrapper);\r
+ int shapeId = wrapper.getShapeId();\r
+ List<List<HSLFTextParagraph>> rv = findTextParagraphs(wrapper.getChildRecords(), wrapper.getStyleTextProp9Atom());\r
+ for (List<HSLFTextParagraph> htpList : rv) {\r
+ for (HSLFTextParagraph htp : htpList) {\r
+ htp.setShapeId(shapeId);\r
+ }\r
+ }\r
+ return rv;\r
}\r
\r
/**\r
}\r
\r
assert(header != null);\r
- if (header.getIndex() == -1) {\r
+ if (header.getParentRecord() instanceof SlideListWithText) {\r
+ // runs found in PPDrawing are not linked with SlideListWithTexts\r
header.setIndex(slwtIndex);\r
}\r
\r
prop.setSubValue(value, index);
}
+ public HSLFTextParagraph getTextParagraph() {
+ return parentParagraph;
+ }
+
public TextCap getTextCap() {
return TextCap.NONE;
}
* @return the array of all hyperlinks in this text run or <code>null</code>
* if not found.
*/
- public HSLFHyperlink[] getHyperlinks() {
+ public List<HSLFHyperlink> getHyperlinks() {
return HSLFHyperlink.find(this);
}
"In addition, its notes has one link";
assertEquals(expected, rawText);
- HSLFHyperlink[] links = HSLFHyperlink.find(para.get(1));
+ List<HSLFHyperlink> links = HSLFHyperlink.find(para);
assertNotNull(links);
- assertEquals(2, links.length);
+ assertEquals(2, links.size());
- assertEquals("http://jakarta.apache.org/poi/", links[0].getTitle());
- assertEquals("http://jakarta.apache.org/poi/", links[0].getAddress());
- assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
+ assertEquals("http://jakarta.apache.org/poi/", links.get(0).getTitle());
+ assertEquals("http://jakarta.apache.org/poi/", links.get(0).getAddress());
+ assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex()-1));
- assertEquals("http://slashdot.org/", links[1].getTitle());
- assertEquals("http://slashdot.org/", links[1].getAddress());
- assertEquals("http://slashdot.org/", rawText.substring(links[1].getStartIndex(), links[1].getEndIndex()-1));
+ assertEquals("http://slashdot.org/", links.get(1).getTitle());
+ assertEquals("http://slashdot.org/", links.get(1).getAddress());
+ assertEquals("http://slashdot.org/", rawText.substring(links.get(1).getStartIndex(), links.get(1).getEndIndex()-1));
slide = ppt.getSlides().get(1);
para = slide.getTextParagraphs().get(1);
"Jakarta HSSF";
assertEquals(expected, rawText);
- links = HSLFHyperlink.find(para.get(1));
+ links = HSLFHyperlink.find(para);
assertNotNull(links);
- assertEquals(1, links.length);
+ assertEquals(1, links.size());
- assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getTitle());
- assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getAddress());
- assertEquals("Jakarta HSSF", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getTitle());
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getAddress());
+ assertEquals("Jakarta HSSF", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex()-1));
}
}
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);\r
HSLFSlideShow ss = new HSLFSlideShow(hss);\r
\r
- HSLFSlide slide = ss.getSlides()[0];\r
- assertEquals("Dominic Salemno", slide.getTextParagraphs()[0].getRawText());\r
+ HSLFSlide slide = ss.getSlides().get(0);\r
+ String rawText = HSLFTextParagraph.getRawText(slide.getTextParagraphs().get(0));\r
+ assertEquals("Dominic Salemno", rawText);\r
\r
String picCmp[][] = {\r
{"0","nKsDTKqxTCR8LFkVVWlP9GSTvZ0="},\r
ss.write(bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ss = new HSLFSlideShow(bis);
- slide1 = ss.getSlides()[0];
- slide2 = ss.getSlides()[1];
+ slide1 = ss.getSlides().get(0);
+ slide2 = ss.getSlides().get(1);
assertFalse(slide1.getHidden());
assertTrue(slide2.getHidden());
}
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.LinkedList;
+import java.util.List;
import junit.framework.TestCase;
-import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.TextProp;
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.model.textproperties.*;
import org.apache.poi.util.HexDump;
/**
stpb.setParentTextSize(data_b_text_len);
// 54 chars, 21 + 17 + 16
- LinkedList<TextPropCollection> a_ch_l = stpa.getCharacterStyles();
+ List<TextPropCollection> a_ch_l = stpa.getCharacterStyles();
TextPropCollection a_ch_1 = a_ch_l.get(0);
TextPropCollection a_ch_2 = a_ch_l.get(1);
TextPropCollection a_ch_3 = a_ch_l.get(2);
assertEquals(16, a_ch_3.getCharactersCovered());
// 179 chars, 30 + 28 + 25
- LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
+ List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len);
- LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
+ List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len);
- LinkedList<TextPropCollection> b_p_l = stpb.getParagraphStyles();
+ List<TextPropCollection> b_p_l = stpb.getParagraphStyles();
TextPropCollection b_p_1 = b_p_l.get(0);
TextPropCollection b_p_2 = b_p_l.get(1);
TextPropCollection b_p_3 = b_p_l.get(2);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len);
- LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
+ List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len);
- LinkedList<TextPropCollection> b_p_l = stpb.getParagraphStyles();
+ List<TextPropCollection> b_p_l = stpb.getParagraphStyles();
TextPropCollection b_p_1 = b_p_l.get(0);
TextPropCollection b_p_2 = b_p_l.get(1);
TextPropCollection b_p_3 = b_p_l.get(2);
TextPropCollection b_p_4 = b_p_l.get(3);
- LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
+ List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2);
// Don't need to touch the paragraph styles
// Add two more character styles
- LinkedList<TextPropCollection> cs = stpa.getCharacterStyles();
+ List<TextPropCollection> cs = stpa.getCharacterStyles();
// First char style is boring, and 21 long
TextPropCollection tpca = cs.get(0);
// Need 4 paragraph styles
- LinkedList<TextPropCollection> ps = stpa.getParagraphStyles();
+ List<TextPropCollection> ps = stpa.getParagraphStyles();
// First is 30 long, left aligned, normal spacing
TextPropCollection tppa = ps.get(0);
// Now do 4 character styles
- LinkedList<TextPropCollection> cs = stpa.getCharacterStyles();
+ List<TextPropCollection> cs = stpa.getCharacterStyles();
// First is 30 long, bold and font size
TextPropCollection tpca = cs.get(0);
// Compare in detail to b
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len);
- LinkedList<TextPropCollection> psb = stpb.getParagraphStyles();
- LinkedList<TextPropCollection> csb = stpb.getCharacterStyles();
+ List<TextPropCollection> psb = stpb.getParagraphStyles();
+ List<TextPropCollection> csb = stpb.getCharacterStyles();
assertEquals(psb.size(), ps.size());
assertEquals(csb.size(), cs.size());
// Ensure Paragraph Character styles match
for(int z=0; z<2; z++) {
- LinkedList<TextPropCollection> lla = cs;
- LinkedList<TextPropCollection> llb = csb;
+ List<TextPropCollection> lla = cs;
+ List<TextPropCollection> llb = csb;
int upto = 5;
if(z == 1) {
lla = ps;
ByteArrayOutputStream ba = new ByteArrayOutputStream();
ByteArrayOutputStream bb = new ByteArrayOutputStream();
- ca.writeOut(ba);
- cb.writeOut(bb);
+ ca.writeOut(ba, StyleTextPropAtom.characterTextPropTypes);
+ cb.writeOut(bb, StyleTextPropAtom.characterTextPropTypes);
byte[] cab = ba.toByteArray();
byte[] cbb = bb.toByteArray();
StyleTextPropAtom atom = new StyleTextPropAtom(data_d, 0, data_d.length);
atom.setParentTextSize(data_d_text_len);
- TextPropCollection prprops = atom.getParagraphStyles().getFirst();
+ TextPropCollection prprops = atom.getParagraphStyles().get(0);
assertEquals(data_d_text_len+1, prprops.getCharactersCovered());
assertEquals(1, prprops.getTextPropList().size()); //1 property found
assertEquals(1, prprops.findByName("alignment").getValue());
- TextPropCollection chprops = atom.getCharacterStyles().getFirst();
+ TextPropCollection chprops = atom.getCharacterStyles().get(0);
assertEquals(data_d_text_len+1, chprops.getCharactersCovered());
assertEquals(5, chprops.getTextPropList().size()); //5 properties found
assertEquals(1, chprops.findByName("char_flags").getValue());
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.util.List;
import junit.framework.TestCase;
-import org.apache.poi.hslf.*;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.record.UserEditAtom;
-import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hslf.record.*;
/**
* Tests that SlideShow adds additional sheets properly
*/
public void testAddSlideToEmpty() throws Exception {
// Doesn't have any slides
- assertEquals(0, ss_empty.getSlides().length);
+ assertEquals(0, ss_empty.getSlides().size());
// Should only have a master SLWT
assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
// Add one
HSLFSlide slide = ss_empty.createSlide();
- assertEquals(1, ss_empty.getSlides().length);
+ assertEquals(1, ss_empty.getSlides().size());
assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber());
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
// Check it now has a slide
- assertEquals(1, ss_read.getSlides().length);
+ assertEquals(1, ss_read.getSlides().size());
// Check it now has two SLWTs
assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
// And check it's as expected
- slide = ss_read.getSlides()[0];
+ slide = ss_read.getSlides().get(0);
assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber());
*/
public void testAddSlideToExisting() throws Exception {
// Has one slide
- assertEquals(1, ss_one.getSlides().length);
- HSLFSlide s1 = ss_one.getSlides()[0];
+ assertEquals(1, ss_one.getSlides().size());
+ HSLFSlide s1 = ss_one.getSlides().get(0);
// Should have two SLTWs
assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
// Add a second one
HSLFSlide s2 = ss_one.createSlide();
- assertEquals(2, ss_one.getSlides().length);
+ assertEquals(2, ss_one.getSlides().size());
assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber());
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
// Check it now has two slides
- assertEquals(2, ss_read.getSlides().length);
+ assertEquals(2, ss_read.getSlides().size());
// Should still have two SLTWs
assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length);
// And check it's as expected
- s1 = ss_read.getSlides()[0];
- s2 = ss_read.getSlides()[1];
+ s1 = ss_read.getSlides().get(0);
+ s2 = ss_read.getSlides().get(1);
assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
* Test adding a slide to an existing slideshow,
* with two slides already
*/
- public void testAddSlideToExisting2() throws Exception {
+ @SuppressWarnings("unused")
+ public void testAddSlideToExisting2() throws Exception {
//grab UserEditAtom
UserEditAtom usredit = null;
Record[] _records = hss_two.getRecords();
assertNotNull(usredit);
// Has two slides
- assertEquals(2, ss_two.getSlides().length);
- HSLFSlide s1 = ss_two.getSlides()[0];
- HSLFSlide s2 = ss_two.getSlides()[1];
+ assertEquals(2, ss_two.getSlides().size());
+ HSLFSlide s1 = ss_two.getSlides().get(0);
+ HSLFSlide s2 = ss_two.getSlides().get(1);
// Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber());
// Add a third one
HSLFSlide s3 = ss_two.createSlide();
- assertEquals(3, ss_two.getSlides().length);
+ assertEquals(3, ss_two.getSlides().size());
assertEquals(258, s3._getSheetNumber());
assertEquals(8, s3._getSheetRefId()); // lots of notes before us
assertEquals(3, s3.getSlideNumber());
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
// Check it now has three slides
- assertEquals(3, ss_read.getSlides().length);
+ assertEquals(3, ss_read.getSlides().size());
// And check it's as expected
- s1 = ss_read.getSlides()[0];
- s2 = ss_read.getSlides()[1];
- s3 = ss_read.getSlides()[2];
+ s1 = ss_read.getSlides().get(0);
+ s2 = ss_read.getSlides().get(1);
+ s3 = ss_read.getSlides().get(2);
assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber());
HSLFSlide slide1 = ppt.createSlide();
HSLFSlide slide2 = ppt.createSlide();
- HSLFSlide[] s1 = ppt.getSlides();
- assertEquals(2, s1.length);
+ List<HSLFSlide> s1 = ppt.getSlides();
+ assertEquals(2, s1.size());
try {
ppt.removeSlide(-1);
fail("expected exception");
assertEquals(1, slide1.getSlideNumber());
HSLFSlide removedSlide = ppt.removeSlide(0);
- HSLFSlide[] s2 = ppt.getSlides();
- assertEquals(1, s2.length);
+ List<HSLFSlide> s2 = ppt.getSlides();
+ assertEquals(1, s2.size());
assertSame(slide1, removedSlide);
- assertSame(slide2, s2[0]);
+ assertSame(slide2, s2.get(0));
assertEquals(0, slide2.getSlideNumber());
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
- HSLFSlide[] s3 = ppt.getSlides();
- assertEquals(1, s3.length);
+ List<HSLFSlide> s3 = ppt.getSlides();
+ assertEquals(1, s3.size());
}
public void test47261() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("47261.ppt"));
- HSLFSlide[] slides = ppt.getSlides();
+ List<HSLFSlide> slides = ppt.getSlides();
Document doc = ppt.getDocumentRecord();
assertNotNull(doc.getSlideSlideListWithText());
- assertEquals(14, ppt.getSlides().length);
- int notesId = slides[0].getSlideRecord().getSlideAtom().getNotesID();
+ assertEquals(14, ppt.getSlides().size());
+ int notesId = slides.get(0).getSlideRecord().getSlideAtom().getNotesID();
assertTrue(notesId > 0);
assertNotNull(doc.getNotesSlideListWithText());
assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length);
//remove all slides, corresponding notes should be removed too
- for (int i = 0; i < slides.length; i++) {
+ for (int i = 0; i < slides.size(); i++) {
ppt.removeSlide(0);
}
- assertEquals(0, ppt.getSlides().length);
- assertEquals(0, ppt.getNotes().length);
+ assertEquals(0, ppt.getSlides().size());
+ assertEquals(0, ppt.getNotes().size());
assertNull(doc.getSlideSlideListWithText());
assertNull(doc.getNotesSlideListWithText());
package org.apache.poi.hslf.usermodel;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true);
- assertEquals(1, ppt.getSlides().length);
+ assertEquals(1, ppt.getSlides().size());
HSLFPictureData[] pict = ppt.getPictureData();
assertEquals(2, pict.length);
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true);
- assertEquals(2, ppt.getSlides().length);
+ assertEquals(2, ppt.getSlides().size());
- HSLFTextParagraph txrun;
+ List<HSLFTextParagraph> txrun;
HSLFNotes notes;
- notes = ppt.getSlides()[0].getNotesSheet();
+ notes = ppt.getSlides().get(0).getNotes();
assertNotNull(notes);
- txrun = notes.getTextParagraphs()[0];
- assertEquals("Notes-1", txrun.getRawText());
- assertEquals(false, txrun.getTextRuns()[0].isBold());
+ txrun = notes.getTextParagraphs().get(0);
+ assertEquals("Notes-1", HSLFTextParagraph.getRawText(txrun));
+ assertEquals(false, txrun.get(0).getTextRuns().get(0).isBold());
//notes for the second slide are in bold
- notes = ppt.getSlides()[1].getNotesSheet();
+ notes = ppt.getSlides().get(1).getNotes();
assertNotNull(notes);
- txrun = notes.getTextParagraphs()[0];
- assertEquals("Notes-2", txrun.getRawText());
- assertEquals(true, txrun.getTextRuns()[0].isBold());
+ txrun = notes.getTextParagraphs().get(0);
+ assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
+ assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold());
}
notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier");
notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L");
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- Integer slideNumber = Integer.valueOf(slide[i].getSlideNumber());
- HSLFNotes notes = slide[i].getNotesSheet();
+ for (HSLFSlide slide : ppt.getSlides()) {
+ Integer slideNumber = Integer.valueOf(slide.getSlideNumber());
+ HSLFNotes notes = slide.getNotes();
if (notesMap.containsKey(slideNumber)){
assertNotNull(notes);
- String text = notes.getTextParagraphs()[0].getRawText();
+ String text = HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(0));
String startingPhrase = notesMap.get(slideNumber);
assertTrue("Notes for slide " + slideNumber + " must start with " +
startingPhrase , text.startsWith(startingPhrase));
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
- HSLFShape[] shape = ppt.getSlides()[0].getShapes();
- for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof HSLFGroupShape){
- HSLFGroupShape group = (HSLFGroupShape)shape[i];
- HSLFShape[] sh = group.getShapes();
- for (int j = 0; j < sh.length; j++) {
- if( sh[j] instanceof HSLFTextBox){
- HSLFTextBox txt = (HSLFTextBox)sh[j];
+ for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
+ if(shape instanceof HSLFGroupShape){
+ HSLFGroupShape group = (HSLFGroupShape)shape;
+ for (HSLFShape sh : group.getShapes()) {
+ if(sh instanceof HSLFTextBox){
+ HSLFTextBox txt = (HSLFTextBox)sh;
assertNotNull(txt.getTextParagraphs());
}
}
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
- HSLFShape[] shape = ppt.getSlides()[0].getShapes();
- for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof HSLFGroupShape){
- HSLFGroupShape group = (HSLFGroupShape)shape[i];
+ for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
+ if(shape instanceof HSLFGroupShape){
+ HSLFGroupShape group = (HSLFGroupShape)shape;
assertNotNull(group.getAnchor());
- HSLFShape[] sh = group.getShapes();
- for (int j = 0; j < sh.length; j++) {
- assertNotNull(sh[j].getAnchor());
+ for (HSLFShape sh : group.getShapes()) {
+ assertNotNull(sh.getAnchor());
}
}
}
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true);
- assertEquals(1, ppt.getSlidesMasters().length);
- assertEquals(1, ppt.getTitleMasters().length);
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- HSLFMasterSheet master = slide[i].getMasterSheet();
- if (i == 0) assertTrue(master instanceof HSLFTitleMaster); //the first slide follows TitleMaster
- else assertTrue(master instanceof HSLFSlideMaster);
+ assertEquals(1, ppt.getSlideMasters().size());
+ assertEquals(1, ppt.getTitleMasters().size());
+ boolean isFirst = true;
+ for (HSLFSlide slide : ppt.getSlides()) {
+ HSLFMasterSheet master = slide.getMasterSheet();
+ // the first slide follows TitleMaster
+ assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
+ isFirst = false;
}
}
/**
* Bug 42486: Failure parsing a seemingly valid PPT
*/
+ @SuppressWarnings("unused")
@Test
public void bug42486 () throws Exception {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- @SuppressWarnings("unused")
- HSLFShape[] shape = slide[i].getShapes();
+ for (HSLFSlide slide : ppt.getSlides()) {
+ List<HSLFShape> shape = slide.getShapes();
}
assertTrue("No Exceptions while reading file", true);
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
//walk down the tree and see if there were no errors while reading
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- HSLFShape[] shape = slide[i].getShapes();
- for (int j = 0; j < shape.length; j++) {
- assertNotNull(shape[j].getShapeName());
- if (shape[j] instanceof HSLFGroupShape){
- HSLFGroupShape group = (HSLFGroupShape)shape[j];
- HSLFShape[] comps = group.getShapes();
- for (int k = 0; k < comps.length; k++) {
- assertNotNull(comps[k].getShapeName());
+ for (HSLFSlide slide : ppt.getSlides()) {
+ for (HSLFShape shape : slide.getShapes()) {
+ assertNotNull(shape.getShapeName());
+ if (shape instanceof HSLFGroupShape){
+ HSLFGroupShape group = (HSLFGroupShape)shape;
+ for (HSLFShape comps : group.getShapes()) {
+ assertNotNull(comps.getShapeName());
}
}
}
/**
* Bug 42520: NPE in Picture.getPictureData()
*/
+ @SuppressWarnings("unused")
@Test
public void bug42520 () throws Exception {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
//test case from the bug report
- HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides()[11].getShapes()[10];
- HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes()[0];
+ HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
+ HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes().get(0);
picture.getPictureData();
//walk down the tree and see if there were no errors while reading
- HSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- HSLFShape[] shape = slide[i].getShapes();
- for (int j = 0; j < shape.length; j++) {
- if (shape[j] instanceof HSLFGroupShape){
- HSLFGroupShape group = (HSLFGroupShape)shape[j];
- HSLFShape[] comps = group.getShapes();
- for (int k = 0; k < comps.length; k++) {
- HSLFShape comp = comps[k];
+ for (HSLFSlide slide : ppt.getSlides()) {
+ for (HSLFShape shape : slide.getShapes()) {
+ if (shape instanceof HSLFGroupShape){
+ HSLFGroupShape group = (HSLFGroupShape)shape;
+ for (HSLFShape comp : group.getShapes()) {
if (comp instanceof HSLFPictureShape){
- @SuppressWarnings("unused")
HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData();
}
}
assertTrue("No Exceptions while reading file", true);
- HSLFSlide[] slide = ppt.getSlides();
- assertEquals(1, slide.length);
- HSLFTextParagraph[] runs = slide[0].getTextParagraphs();
- assertEquals(4, runs.length);
+ List<HSLFSlide> slide = ppt.getSlides();
+ assertEquals(1, slide.size());
+ List<List<HSLFTextParagraph>> paras = slide.get(0).getTextParagraphs();
+ assertEquals(4, paras.size());
Set<String> txt = new HashSet<String>();
txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D");
txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026");
txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!");
- for (int i = 0; i < runs.length; i++) {
- String text = runs[i].getRawText();
+ for (List<HSLFTextParagraph> para : paras) {
+ String text = HSLFTextParagraph.getRawText(para);
assertTrue(text, txt.contains(text));
}
* ( also fixed followup: getTextRuns() returns no text )
*/
@Test
- public void bug43781 () throws Exception {
+ public void bug43781() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt"));
assertTrue("No Exceptions while reading file", true);
// Check the first slide
- HSLFSlide slide = ppt.getSlides()[0];
- HSLFTextParagraph[] slTr = slide.getTextParagraphs();
+ HSLFSlide slide = ppt.getSlides().get(0);
+ List<List<HSLFTextParagraph>> slTr = slide.getTextParagraphs();
- // Has two text runs, one from slide text, one from drawing
- assertEquals(2, slTr.length);
- assertEquals(false, slTr[0].isDrawingBased());
- assertEquals(true, slTr[1].isDrawingBased());
- assertEquals("First run", slTr[0].getRawText());
- assertEquals("Second run", slTr[1].getRawText());
+ // Has 3 text paragraphs, two from slide text (empty title / filled body), one from drawing
+ assertEquals(3, slTr.size());
+ assertFalse(slTr.get(0).get(0).isDrawingBased());
+ assertFalse(slTr.get(1).get(0).isDrawingBased());
+ assertTrue(slTr.get(2).get(0).isDrawingBased());
+ assertEquals("", HSLFTextParagraph.getRawText(slTr.get(0)));
+ assertEquals("First run", HSLFTextParagraph.getRawText(slTr.get(1)));
+ assertEquals("Second run", HSLFTextParagraph.getRawText(slTr.get(2)));
// Check the shape based text runs
List<HSLFTextParagraph> lst = new ArrayList<HSLFTextParagraph>();
- HSLFShape[] shape = slide.getShapes();
- for (int i = 0; i < shape.length; i++) {
- if( shape[i] instanceof HSLFTextShape){
- HSLFTextParagraph textRun = ((HSLFTextShape)shape[i]).getTextParagraphs();
- if(textRun != null) {
- lst.add(textRun);
- }
+ for (HSLFShape shape : slide.getShapes()) {
+ if (shape instanceof HSLFTextShape){
+ List<HSLFTextParagraph> textRun = ((HSLFTextShape)shape).getTextParagraphs();
+ lst.addAll(textRun);
}
}
- // There should be only one shape based one found
- assertEquals(1, lst.size());
- // And it should be the second one
- assertEquals("Second run", lst.get(0).getRawText());
+ // There are two shapes in the ppt
+ assertEquals(2, lst.size());
+ assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
}
/**
public void bug44296 () throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt"));
- HSLFSlide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides().get(0);
HSLFBackground b = slide.getBackground();
HSLFFill f = b.getFill();
public void bug41071() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt"));
- HSLFSlide slide = ppt.getSlides()[0];
- HSLFShape[] sh = slide.getShapes();
- assertEquals(1, sh.length);
- assertTrue(sh[0] instanceof HSLFTextShape);
- HSLFTextShape tx = (HSLFTextShape)sh[0];
- assertEquals("Fundera, planera och involvera.", tx.getTextParagraphs().getRawText());
+ HSLFSlide slide = ppt.getSlides().get(0);
+ List<HSLFShape> sh = slide.getShapes();
+ assertEquals(1, sh.size());
+ assertTrue(sh.get(0) instanceof HSLFTextShape);
+ HSLFTextShape tx = (HSLFTextShape)sh.get(0);
+ assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(tx.getTextParagraphs()));
- HSLFTextParagraph[] run = slide.getTextParagraphs();
- assertEquals(1, run.length);
- assertEquals("Fundera, planera och involvera.", run[0].getRawText());
+ List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
+ assertEquals(3, run.size());
+ assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
}
/**
public void bug49648() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt"));
for(HSLFSlide slide : ppt.getSlides()) {
- for(HSLFTextParagraph run : slide.getTextParagraphs()) {
- String text = run.getRawText();
+ for(List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
+ String text = HSLFTextParagraph.getRawText(run);
text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
- run.setRawText(text);
+ HSLFTextParagraph.setText(run, text);
}
}
}
str = str.replace("$$DATE$$", new Date().toString());
tb.setText(str);
- HSLFTextParagraph tr = tb.getTextParagraphs();
- assertEquals(str.length()+1,tr.getStyleTextPropAtom().getParagraphStyles().getFirst().getCharactersCovered());
- assertEquals(str.length()+1,tr.getStyleTextPropAtom().getCharacterStyles().getFirst().getCharactersCovered());
+ List<HSLFTextParagraph> tr = tb.getTextParagraphs();
+ assertEquals(str.length()+1,tr.get(0).getParagraphStyle().getCharactersCovered());
+ assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
}
}
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
HSLFSlideShow _show = new HSLFSlideShow(ss);
- HSLFSlide[] _slides = _show.getSlides();
+ List<HSLFSlide> _slides = _show.getSlides();
/* Iterate over slides and extract text */
for( HSLFSlide slide : _slides ) {
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
HSLFSlideShow _show = new HSLFSlideShow(ss);
- HSLFSlide[] _slides = _show.getSlides();
- assertEquals(13, _slides.length);
+ List<HSLFSlide> _slides = _show.getSlides();
+ assertEquals(13, _slides.size());
// Check the number of TextHeaderAtoms on Slide 1
Document dr = _show.getDocumentRecord();
// Check the number of text runs based on the slide (not textbox)
// Will have skipped the empty one
int str = 0;
- for (HSLFTextParagraph tr : _slides[0].getTextParagraphs()) {
- if (! tr.isDrawingBased()) str++;
+ for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
+ if (! tr.get(0).isDrawingBased()) str++;
}
assertEquals(1, str);
}
InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt"));
try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
- assertEquals(29, slideShow.getSlides().length);
+ assertEquals(29, slideShow.getSlides().size());
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
assertNotNull(slideBack);
- assertEquals(29, slideBack.getSlides().length);
+ assertEquals(29, slideBack.getSlides().size());
} finally {
inputStream.close();
}
InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
- assertEquals(6, slideShow.getSlides().length);
+ assertEquals(6, slideShow.getSlides().size());
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
assertNotNull(slideBack);
- assertEquals(6, slideBack.getSlides().length);
+ assertEquals(6, slideBack.getSlides().size());
} finally {
inputStream.close();
}
InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt"));
try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
- HSLFSlide slide = slideShow.getSlides()[0];
- HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes()[0];
- HSLFTextBox tb = (HSLFTextBox)sg.getShapes()[0];
+ HSLFSlide slide = slideShow.getSlides().get(0);
+ HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
+ HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
String text = StringUtil.mapMsCodepointString(tb.getText());
assertEquals("\u226575 years", text);
} finally {
InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt"));
try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
- int slideCnt = slideShow.getSlides().length;
+ int slideCnt = slideShow.getSlides().size();
assertEquals(105, slideCnt);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
slideShow.write(bos);
InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt"));
try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
- HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides()[0].getShapes()[0];
+ HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0);
EscherOptRecord opt = as.getEscherOptRecord();
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
double exp[][] = {