com.day.cq.wcm.offline.DocImporter 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.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
/**
* An implementation of {@link TextDocumentImporter} for "classic" MS Word
* documents ("doc").
* @deprecated since 6.3
*/
@Deprecated
public class DocImporter implements TextDocumentImporter {
private final HWPFDocument document;
private final Range range;
public DocImporter(InputStream stream) throws TextImportException {
try {
this.document = new HWPFDocument(stream);
this.range = document.getRange();
} catch (OfficeXmlFileException ex) {
throw new TextImportException("this is a docx file", ex);
} catch (IOException ex) {
throw new TextImportException(ex.getMessage(), ex);
}
}
/**
* @return contents of first non-empty paragraph
*/
public String getTitle() {
for (int i = 0; i < this.range.numParagraphs(); i++) {
org.apache.poi.hwpf.usermodel.Paragraph p = this.range.getParagraph(i);
String t = p.text().trim();
if (!"".equals(t)) {
return t;
}
}
return null;
}
public int getNumberOfParagraphs() {
return this.range.numParagraphs();
}
public Paragraph getParagraph(int index) {
return new DocParagraph(this.range.getParagraph(index));
}
private class DocParagraph implements Paragraph {
private final org.apache.poi.hwpf.usermodel.Paragraph p;
private final String text;
private final String textHTML;
private final List