use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project tika by apache.
the class XSLFPowerPointExtractorDecorator method buildXHTML.
/**
* @see org.apache.poi.xslf.extractor.XSLFPowerPointExtractor#getText()
*/
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, IOException {
XMLSlideShow slideShow = (XMLSlideShow) extractor.getDocument();
XSLFCommentAuthors commentAuthors = slideShow.getCommentAuthors();
List<XSLFSlide> slides = slideShow.getSlides();
for (XSLFSlide slide : slides) {
String slideDesc;
if (slide.getPackagePart() != null && slide.getPackagePart().getPartName() != null) {
slideDesc = getJustFileName(slide.getPackagePart().getPartName().toString());
slideDesc += "_";
} else {
slideDesc = null;
}
// slide content
xhtml.startElement("div", "class", "slide-content");
extractContent(slide.getShapes(), false, xhtml, slideDesc);
xhtml.endElement("div");
// slide layout which is the master sheet for this slide
xhtml.startElement("div", "class", "slide-master-content");
XSLFSlideLayout slideLayout = slide.getMasterSheet();
extractContent(slideLayout.getShapes(), true, xhtml, null);
xhtml.endElement("div");
// slide master which is the master sheet for all text layouts
XSLFSheet slideMaster = slideLayout.getMasterSheet();
extractContent(slideMaster.getShapes(), true, xhtml, null);
// notes (if present)
XSLFNotes slideNotes = slide.getNotes();
if (slideNotes != null) {
xhtml.startElement("div", "class", "slide-notes");
extractContent(slideNotes.getShapes(), false, xhtml, slideDesc);
// master sheet for this notes
XSLFNotesMaster notesMaster = slideNotes.getMasterSheet();
if (notesMaster != null) {
extractContent(notesMaster.getShapes(), true, xhtml, null);
}
xhtml.endElement("div");
}
// comments (if present)
XSLFComments comments = slide.getComments();
if (comments != null) {
StringBuilder authorStringBuilder = new StringBuilder();
for (int i = 0; i < comments.getNumberOfComments(); i++) {
authorStringBuilder.setLength(0);
CTComment comment = comments.getCommentAt(i);
xhtml.startElement("p", "class", "slide-comment");
CTCommentAuthor cta = commentAuthors.getAuthorById(comment.getAuthorId());
if (cta != null) {
if (cta.getName() != null) {
authorStringBuilder.append(cta.getName());
}
if (cta.getInitials() != null) {
if (authorStringBuilder.length() > 0) {
authorStringBuilder.append(" ");
}
authorStringBuilder.append("(" + cta.getInitials() + ")");
}
if (comment.getText() != null && authorStringBuilder.length() > 0) {
authorStringBuilder.append(" - ");
}
if (authorStringBuilder.length() > 0) {
xhtml.startElement("b");
xhtml.characters(authorStringBuilder.toString());
xhtml.endElement("b");
}
}
xhtml.characters(comment.getText());
xhtml.endElement("p");
}
}
}
}
use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project poi by apache.
the class XSLFPowerPointExtractor method getText.
/**
* Gets the requested text from the slide
*
* @param slide the slide to retrieve the text from
* @param slideText Should we retrieve text from slides?
* @param notesText Should we retrieve text from notes?
* @param masterText Should we retrieve text from master slides?
*
* @return the extracted text
*/
public static String getText(XSLFSlide slide, boolean slideText, boolean notesText, boolean masterText) {
StringBuilder text = new StringBuilder();
XSLFCommentAuthors commentAuthors = slide.getSlideShow().getCommentAuthors();
XSLFNotes notes = slide.getNotes();
XSLFComments comments = slide.getComments();
XSLFSlideLayout layout = slide.getSlideLayout();
XSLFSlideMaster master = layout.getSlideMaster();
// Do the slide's text if requested
if (slideText) {
extractText(slide, false, text);
// If requested, get text from the master and it's layout
if (masterText) {
assert (layout != null);
extractText(layout, true, text);
assert (master != null);
extractText(master, true, text);
}
// If the slide has comments, do those too
if (comments != null) {
for (CTComment comment : comments.getCTCommentsList().getCmArray()) {
// Do the author if we can
if (commentAuthors != null) {
CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
if (author != null) {
text.append(author.getName() + ": ");
}
}
// Then the comment text, with a new line afterwards
text.append(comment.getText());
text.append("\n");
}
}
}
// Do the notes if requested
if (notesText && notes != null) {
extractText(notes, false, text);
}
return text.toString();
}
Aggregations