private boolean _slidesByDefault = true;
private boolean _notesByDefault = false;
private boolean _commentsByDefault = false;
+ private boolean _masterByDefault = false;
/**
* Basic extractor. Returns all the text, and optionally all the notes
boolean notes = false;
boolean comments = false;
+ boolean master = true;
+
String file;
if (args.length > 1) {
notes = true;
}
PowerPointExtractor ppe = new PowerPointExtractor(file);
- System.out.println(ppe.getText(true, notes, comments));
+ System.out.println(ppe.getText(true, notes, comments, master));
}
/**
this._commentsByDefault = commentsByDefault;
}
+ /**
+ * Should a call to getText() return text from master? Default is no
+ */
+ public void setMasterByDefault(boolean masterByDefault) {
+ this._masterByDefault = masterByDefault;
+ }
+
/**
* Fetches all the slide text from the slideshow, but not the notes, unless
* you've called setSlidesByDefault() and setNotesByDefault() to change this
*/
public String getText() {
- return getText(_slidesByDefault, _notesByDefault, _commentsByDefault);
+ return getText(_slidesByDefault, _notesByDefault, _commentsByDefault, _masterByDefault);
}
/**
* @param getNoteText fetch note text
*/
public String getText(boolean getSlideText, boolean getNoteText) {
- return getText(getSlideText, getNoteText, _commentsByDefault);
+ return getText(getSlideText, getNoteText, _commentsByDefault, _masterByDefault);
}
- public String getText(boolean getSlideText, boolean getNoteText, boolean getCommentText) {
+ public String getText(boolean getSlideText, boolean getNoteText, boolean getCommentText, boolean getMasterText) {
StringBuffer ret = new StringBuffer();
if (getSlideText) {
- for (int i = 0; i < _slides.length; i++) {
+ if (getMasterText) {
+ for (SlideMaster master : _show.getSlidesMasters()) {
+ textRunsToText(ret, master.getTextRuns());
+ }
+ }
+
+ for (int i = 0; i < _slides.length; i++) {
Slide slide = _slides[i];
// Slide header, if set
}
// Slide text
- TextRun[] runs = slide.getTextRuns();
- for (int j = 0; j < runs.length; j++) {
- TextRun run = runs[j];
- if (run != null) {
- String text = run.getText();
- ret.append(text);
- if (!text.endsWith("\n")) {
- ret.append("\n");
- }
- }
- }
+ textRunsToText(ret, slide.getTextRuns());
- // Slide footer, if set
+ // Slide footer, if set
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
ret.append(hf.getFooterText() + "\n");
}
}
// Notes text
- TextRun[] runs = notes.getTextRuns();
- if (runs != null && runs.length > 0) {
- for (int j = 0; j < runs.length; j++) {
- TextRun run = runs[j];
- String text = run.getText();
- ret.append(text);
- if (!text.endsWith("\n")) {
- ret.append("\n");
- }
- }
- }
+ textRunsToText(ret, notes.getTextRuns());
// Repeat the notes footer, if set
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
return ret.toString();
}
+
+ private void textRunsToText(StringBuffer ret, TextRun[] runs) {
+ if (runs==null) {
+ return;
+ }
+
+ for (int j = 0; j < runs.length; j++) {
+ TextRun run = runs[j];
+ if (run != null) {
+ String text = run.getText();
+ ret.append(text);
+ if (!text.endsWith("\n")) {
+ ret.append("\n");
+ }
+ }
+ }
+ }
}
//private String pdirname;
protected void setUp() throws Exception {
-
ppe = new PowerPointExtractor(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
ppe2 = new PowerPointExtractor(slTests.openResourceAsStream("with_textbox.ppt"));
}
// 1 page example with text boxes
sheetText = ppe2.getText();
- expectText = "Hello, World!!!\nI am just a poor boy\nThis is Times New Roman\nPlain Text \n";
+ expectText = "Hello, World!!!\nI am just a poor boy\nThis is Times New Roman\nPlain Text \n";
ensureTwoStringsTheSame(expectText, sheetText);
}
*/
public void testMissingCoreRecords() throws Exception {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt"));
-
+
String text = ppe.getText(true, false);
String nText = ppe.getNotes();
private static boolean contains(String text, String searchString) {
return text.indexOf(searchString) >=0;
}
+
+ public void testMasterText() throws Exception {
+ ppe = new PowerPointExtractor(slTests.openResourceAsStream("master_text.ppt"));
+ ppe.setMasterByDefault(true);
+
+ String text = ppe.getText();
+ assertTrue(text.contains("Master Header Text"));
+ }
+
}