com.day.cq.wcm.offline.DocxImporter Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2013 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.day.cq.wcm.offline;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.poi.POIXMLException;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.xwpf.usermodel.Document;
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPicture;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An implementation of {@link TextDocumentImporter} for "modern" MS Word
* documents ("docx").
* @deprecated since 6.3
*/
@Deprecated
public class DocxImporter implements TextDocumentImporter {
private static final Logger log = LoggerFactory.getLogger(DocxImporter.class);
private final XWPFDocument document;
private final List paragraphs;
public DocxImporter(InputStream stream) throws TextImportException, IOException {
try {
this.document = new XWPFDocument(stream);
List tmp = new ArrayList();
for (XWPFParagraph p : this.document.getParagraphs()) {
if (!p.isEmpty() && !p.isPageBreak()) {
tmp.add(p);
}
}
this.paragraphs = Collections.unmodifiableList(tmp);
} catch (POIXMLException ex) {
throw new TextImportException("not a docx file", ex);
}
}
/**
* @return contents of first non-empty paragraph
*/
public String getTitle() {
for (XWPFParagraph p : this.paragraphs) {
String t = p.getText().trim();
if (!"".equals(t)) {
return t;
}
}
return null;
}
public int getNumberOfParagraphs() {
return this.paragraphs.size();
}
public Paragraph getParagraph(int index) {
return new DocxParagraph(this.paragraphs.get(index));
}
private class DocxParagraph implements Paragraph {
private final XWPFParagraph p;
private final String text;
private final String textHTML;
private final List