See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-package org.apache.poi;
-import java.io.IOException;
+package org.apache.poi;
-import org.apache.xmlbeans.XmlException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
/**
* A {@link POITextExtractor} for returning the textual
* content of the OOXML file properties, eg author
- * and title.
+ * and title.
*/
public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
/**
* working on.
*/
public POIXMLPropertiesTextExtractor(POIXMLTextExtractor otherExtractor) {
- super(otherExtractor.document);
+ super(otherExtractor.getDocument());
}
-
+
/**
* Returns the core document properties, eg author
*/
public String getCorePropertiesText() {
StringBuffer text = new StringBuffer();
PackagePropertiesPart props =
- document.getProperties().getCoreProperties().getUnderlyingProperties();
-
+ getDocument().getProperties().getCoreProperties().getUnderlyingProperties();
+
text.append("Category = " + props.getCategoryProperty().getValue() + "\n");
text.append("ContentStatus = " + props.getContentStatusProperty().getValue() + "\n");
text.append("ContentType = " + props.getContentTypeProperty().getValue() + "\n");
public String getExtendedPropertiesText() {
StringBuffer text = new StringBuffer();
org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties
- props = document.getProperties().getExtendedProperties().getUnderlyingProperties();
+ props = getDocument().getProperties().getExtendedProperties().getUnderlyingProperties();
text.append("Application = " + props.getApplication() + "\n");
text.append("AppVersion = " + props.getAppVersion() + "\n");
text.append("PresentationFormat = " + props.getPresentationFormat() + "\n");
text.append("Template = " + props.getTemplate() + "\n");
text.append("TotalTime = " + props.getTotalTime() + "\n");
-
+
return text.toString();
}
/**
- * Returns the custom document properties, if
+ * Returns the custom document properties, if
* there are any
*/
public String getCustomPropertiesText() {
StringBuffer text = new StringBuffer();
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
- props = document.getProperties().getCustomProperties().getUnderlyingProperties();
-
+ props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
+
CTProperty[] properties = props.getPropertyArray();
for(int i = 0; i<properties.length; i++) {
// TODO - finish off
String val = "(not implemented!)";
-
+
text.append(
properties[i].getName() +
" = " + val + "\n"
);
}
-
+
return text.toString();
}
public String getText() {
try {
- return
- getCorePropertiesText() +
+ return
+ getCorePropertiesText() +
getExtendedPropertiesText() +
getCustomPropertiesText();
} catch(Exception e) {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-package org.apache.poi;
-import java.io.IOException;
+package org.apache.poi;
-import org.apache.poi.POIXMLProperties.*;
-import org.apache.xmlbeans.XmlException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.POIXMLProperties.CoreProperties;
+import org.apache.poi.POIXMLProperties.CustomProperties;
+import org.apache.poi.POIXMLProperties.ExtendedProperties;
public abstract class POIXMLTextExtractor extends POITextExtractor {
/** The POIXMLDocument that's open */
- protected POIXMLDocument document;
+ private final POIXMLDocument _document;
/**
* Creates a new text extractor for the given document
*/
public POIXMLTextExtractor(POIXMLDocument document) {
super((POIDocument)null);
-
- this.document = document;
+
+ _document = document;
}
-
+
/**
* Returns the core document properties
*/
public CoreProperties getCoreProperties() {
- return document.getProperties().getCoreProperties();
+ return _document.getProperties().getCoreProperties();
}
/**
* Returns the extended document properties
*/
public ExtendedProperties getExtendedProperties() {
- return document.getProperties().getExtendedProperties();
+ return _document.getProperties().getExtendedProperties();
}
/**
* Returns the custom document properties
*/
public CustomProperties getCustomProperties() {
- return document.getProperties().getCustomProperties();
+ return _document.getProperties().getCustomProperties();
}
/**
- * Returns opened document
+ * Returns opened document
*/
- public POIXMLDocument getDocument(){
- return document;
+ public final POIXMLDocument getDocument(){
+ return _document;
}
-
-
+
+
/**
- * Returns an OOXML properties text extractor for the
+ * Returns an OOXML properties text extractor for the
* document properties metadata, such as title and author.
*/
public POIXMLPropertiesTextExtractor getMetadataTextExtractor() {
- return new POIXMLPropertiesTextExtractor(document);
+ return new POIXMLPropertiesTextExtractor(_document);
}
}
limitations under the License.
==================================================================== */
-
package org.apache.poi;
-import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.POIXMLProperties.CoreProperties;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* Test setting extended and custom OOXML properties
private POIXMLProperties _props;
private CoreProperties _coreProperties;
- public void setUp() throws Exception{
- XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx");
+ public void setUp() {
+ XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx");
_props = sampleDoc.getProperties();
_coreProperties = _props.getCoreProperties();
assertNotNull(_props);
public void testGetSetRevision() {
String revision = _coreProperties.getRevision();
- assertTrue("Revision number is 1", new Integer(revision)> 1);
+ assertTrue("Revision number is 1", Integer.parseInt(revision) > 1);
_coreProperties.setRevision("20");
assertEquals("20", _coreProperties.getRevision());
_coreProperties.setRevision("20xx");
package org.apache.poi.xssf.eventusermodel;
-import java.io.File;
import java.io.InputStream;
import java.util.Iterator;
import junit.framework.TestCase;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
/**
* Tests for {@link XSSFReader}
import java.io.ByteArrayOutputStream;
import java.util.List;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
public class TestCommentsTable extends TestCase {
assertEquals("Another Author", comment.getAuthor());
}
- public void testDontLoostNewLines() throws Exception {
+ public void testDontLoostNewLines() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
CommentsTable ct = null;
assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString());
}
- public void testExisting() throws Exception {
- XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
+ public void testExisting() {
+ XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
Sheet sheet1 = workbook.getSheetAt(0);
Sheet sheet2 = workbook.getSheetAt(1);
assertEquals(2, cc7.getColumn());
}
- public void testWriteRead() throws Exception {
- XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
+ public void testWriteRead() {
+ XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = workbook.getSheetAt(1);
sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
}
- public void testReadWriteMultipleAuthors() throws Exception {
- XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
+ public void testReadWriteMultipleAuthors() {
+ XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = workbook.getSheetAt(1);
assertEquals(0, st._getNumberFormatSize());
}
- public void testLoadExisting() throws Exception {
+ public void testLoadExisting() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
assertNotNull(workbook.getStylesSource());
doTestExisting(st);
}
- public void testLoadSaveLoad() throws Exception {
+ public void testLoadSaveLoad() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
assertNotNull(workbook.getStylesSource());
assertEquals(nf2, st.putNumberFormat("yyyy-mm-DD"));
}
- public void testPopulateExisting() throws Exception {
+ public void testPopulateExisting() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
assertNotNull(workbook.getStylesSource());
int nf2 = st.putNumberFormat("YYYY-mm-DD");
assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd"));
- st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
+ st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
assertEquals(11, st._getXfsSize());
assertEquals(1, st._getStyleXfsSize());
package org.apache.poi.xssf.usermodel;
-import java.io.File;
-
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.ss.usermodel.BaseTestHyperlink;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Hyperlink;
+import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFTestDataSamples;
public final class TestXSSFHyperlink extends BaseTestHyperlink {
@Override
);
}
- public void testLoadExisting() throws Exception {
+ public void testLoadExisting() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
assertEquals(3, workbook.getNumberOfSheets());
doTestHyperlinkContents(sheet);
}
- public void testLoadSave() throws Exception {
+ public void testLoadSave() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
CreationHelper createHelper = workbook.getCreationHelper();
assertEquals(3, workbook.getNumberOfSheets());
baseTestGetSetMargin(new double[]{0.7, 0.7, 0.75, 0.75, 0.3, 0.3});
}
- public void testExistingHeaderFooter() throws Exception {
+ public void testExistingHeaderFooter() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("45540_classic_Header.xlsx");
XSSFOddHeader hdr;
XSSFOddFooter ftr;
short i = workbook.getNumCellStyles();
//get default cellStyles
assertEquals(1, i);
- //get wrong value
- assertNotSame(2, i);
}
public void testLoadSave() {
package org.apache.poi.xwpf;
-import java.io.File;
-
import junit.framework.TestCase;
-import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLProperties;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
public void testContainsMainContentType() throws Exception {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
- OPCPackage pack = doc.getPackage();
+ OPCPackage pack = doc.getPackage();
boolean found = false;
for(PackagePart part : pack.getParts()) {
assertNotNull(xml.getStyle());
// Complex file
- xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
+ xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
assertNotNull(xml.getDocument());
assertNotNull(xml.getDocument().getBody());
assertNotNull(xml.getStyle());
}
- public void testMetadataBasics() throws Exception {
- XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
+ public void testMetadataBasics() {
+ XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
assertNotNull(xml.getProperties().getCoreProperties());
assertNotNull(xml.getProperties().getExtendedProperties());
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
}
- public void testMetadataComplex() throws Exception {
+ public void testMetadataComplex() {
XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
assertNotNull(xml.getProperties().getCoreProperties());
assertNotNull(xml.getProperties().getExtendedProperties());
assertNotNull(props);
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
}
-
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.xwpf.extractor;
-import java.io.File;
-import java.io.IOException;
+import junit.framework.TestCase;
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.XWPFTestDataSamples;
-
-import junit.framework.TestCase;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* Tests for HXFWordExtractor
/**
* Get text out of the simple file
*/
- public void testGetSimpleText() throws Exception {
+ public void testGetSimpleText() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
/**
* Tests getting the text out of a complex file
*/
- public void testGetComplexText() throws Exception {
+ public void testGetComplexText() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
assertEquals(103, ps);
}
- public void testGetWithHyperlinks() throws Exception {
+ public void testGetWithHyperlinks() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
);
}
- public void testHeadersFooters() throws Exception {
+ public void testHeadersFooters() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ThreeColHeadFoot.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
);
}
- public void testFootnotes() throws Exception {
+ public void testFootnotes() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
}
- public void testTableFootnotes() throws Exception {
+ public void testTableFootnotes() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("table_footnotes.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
assertTrue(extractor.getText().contains("snoska"));
}
- public void testFormFootnotes() throws Exception {
+ public void testFormFootnotes() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("form_footnotes.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
}
- public void testEndnotes() throws Exception {
+ public void testEndnotes() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
assertTrue(extractor.getText().contains("XXX"));
}
- public void testInsertedDeletedText() throws Exception {
+ public void testInsertedDeletedText() {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("delins.docx");
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.xwpf.model;
-import java.io.File;
+import junit.framework.TestCase;
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.XWPFTestDataSamples;
-
-import junit.framework.TestCase;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* Tests for XWPF Header Footer Stuff
private XWPFDocument oddEven;
private XWPFDocument diffFirst;
- protected void setUp() throws Exception {
- super.setUp();
+ protected void setUp() {
noHeader = XWPFTestDataSamples.openSampleDocument("NoHeadFoot.docx");
- header = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
- headerFooter = XWPFTestDataSamples.openSampleDocument("SimpleHeadThreeColFoot.docx");
- footer = XWPFTestDataSamples.openSampleDocument("FancyFoot.docx");
- oddEven = XWPFTestDataSamples.openSampleDocument("PageSpecificHeadFoot.docx");
- diffFirst = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx");
+ header = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
+ headerFooter = XWPFTestDataSamples.openSampleDocument("SimpleHeadThreeColFoot.docx");
+ footer = XWPFTestDataSamples.openSampleDocument("FancyFoot.docx");
+ oddEven = XWPFTestDataSamples.openSampleDocument("PageSpecificHeadFoot.docx");
+ diffFirst = XWPFTestDataSamples.openSampleDocument("DiffFirstPageHeadFoot.docx");
}
public void testPolicy() {
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.xwpf.usermodel;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
import junit.framework.TestCase;
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
-public class TestXWPFHeader extends TestCase {
-
- public void testSimpleHeader() throws IOException {
+public final class TestXWPFHeader extends TestCase {
+
+ public void testSimpleHeader() {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx");
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
-
-
+
+
XWPFHeader header = policy.getDefaultHeader();
XWPFFooter footer = policy.getDefaultFooter();
assertNotNull(header);
assertNotNull(footer);
-
+
// TODO verify if the following is correct
assertNull(header.toString());
-
+
}
-
+
public void testSetHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
// no header is set (yet)
assertNull(policy.getDefaultHeader());
assertNull(policy.getFirstPageHeader());
assertNull(policy.getDefaultFooter());
-
+
CTP ctP1 = CTP.Factory.newInstance();
CTR ctR1 = ctP1.addNewR();
CTText t = ctR1.addNewT();
- t.set("Paragraph in header");
-
+ t.setStringValue("Paragraph in header");
+
CTP ctP2 = CTP.Factory.newInstance();
CTR ctR2 = ctP2.addNewR();
CTText t2 = ctR2.addNewT();
- t2.set("Second paragraph.. for footer");
-
+ t2.setStringValue("Second paragraph.. for footer");
+
XWPFParagraph p1 = new XWPFParagraph(ctP1);
XWPFParagraph[] pars = new XWPFParagraph[1];
pars[0] = p1;
XWPFParagraph p2 = new XWPFParagraph(ctP2);
XWPFParagraph[] pars2 = new XWPFParagraph[1];
pars2[0] = p2;
-
+
// set a default header and test it is not null
policy.createHeader(policy.DEFAULT, pars);
policy.createHeader(policy.FIRST);
policy.createFooter(policy.DEFAULT, pars2);
-
+
assertNotNull(policy.getDefaultHeader());
assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getDefaultFooter());
}
-
- public void testSetWatermark() throws IOException {
+
+ public void testSetWatermark() {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
// no header is set (yet)
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
assertNull(policy.getDefaultHeader());
assertNull(policy.getFirstPageHeader());
assertNull(policy.getDefaultFooter());
-
+
policy.createWatermark("DRAFT");
-
+
assertNotNull(policy.getDefaultHeader());
assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getEvenPageHeader());
}
-
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.xwpf.usermodel;
-import java.io.File;
import java.math.BigInteger;
import junit.framework.TestCase;
-import org.apache.poi.POIXMLDocument;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
/**
* Check if we can read the body of the blank message, we expect "".
*/
- public void testReadBody() throws Exception {
+ public void testReadBody() {
try {
mapiMessage.getTextBody();
} catch(ChunkNotFoundException exp) {
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
public void testReadSubject() throws Exception {
String obtained = mapiMessage.getSubject();
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
public void testReadConversationTopic() {
try {
package org.apache.poi.hwpf;
-import java.io.FileInputStream;
-
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.hwpf.model.FileInformationBlock;
import org.apache.poi.poifs.filesystem.DocumentEntry;
-
-import org.apache.poi.hwpf.model.*;
-import java.io.File;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public final class HWPFDocFixture
import junit.framework.TestCase;
-
-public abstract class HWPFTestCase
- extends TestCase
-{
- protected HWPFDocFixture _hWPFDocFixture;
-
- public HWPFTestCase()
- {
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- /**@todo verify the constructors*/
- _hWPFDocFixture = new HWPFDocFixture(this);
-
- _hWPFDocFixture.setUp();
- }
-
- protected void tearDown() throws Exception {
- if(_hWPFDocFixture != null) {
- _hWPFDocFixture.tearDown();
- }
-
- _hWPFDocFixture = null;
- super.tearDown();
- }
-
- public HWPFDocument writeOutAndRead(HWPFDocument doc) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- doc.write(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- HWPFDocument newDoc = new HWPFDocument(bais);
- return newDoc;
- }
+public abstract class HWPFTestCase extends TestCase {
+ protected HWPFDocFixture _hWPFDocFixture;
+
+ protected HWPFTestCase() {
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ /** @todo verify the constructors */
+ _hWPFDocFixture = new HWPFDocFixture(this);
+
+ _hWPFDocFixture.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ if (_hWPFDocFixture != null) {
+ _hWPFDocFixture.tearDown();
+ }
+
+ _hWPFDocFixture = null;
+ super.tearDown();
+ }
+
+ public HWPFDocument writeOutAndRead(HWPFDocument doc) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ HWPFDocument newDoc;
+ try {
+ doc.write(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ newDoc = new HWPFDocument(bais);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return newDoc;
+ }
}
/**
* Test just opening the files
*/
- public void testOpen() throws Exception {
+ public void testOpen() {
HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
}
/**
* Test that we have the right numbers of images in each file
*/
- public void testImageCount() throws Exception {
+ public void testImageCount() {
HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
/**
* Test that we have the right images in at least one file
*/
- public void testImageData() throws Exception {
+ public void testImageData() {
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
PicturesTable picB = docB.getPicturesTable();
List picturesB = picB.getAllPictures();
/**
* Test that compressed image data is correctly returned.
*/
- public void testCompressedImageData() throws Exception {
+ public void testCompressedImageData() {
HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
PicturesTable picC = docC.getPicturesTable();
List picturesC = picC.getAllPictures();
* Pending the missing files being uploaded to
* bug #44937
*/
- public void BROKENtestEscherDrawing() throws Exception {
+ public void BROKENtestEscherDrawing() {
HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile);
List allPictures = docD.getPicturesTable().getAllPictures();
*/
private HWPFDocument docUnicode;
- public void setUp() throws Exception {
+ public void setUp() {
docUnicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
}
private HWPFDocument doc;
- protected void setUp() throws Exception {
+ protected void setUp() {
doc = HWPFTestDataSamples.openSampleFile("test2.doc");
- }
-
- /**
- * Test model based extraction
- */
- public void testExtractFromModel() {
- Range r = doc.getRange();
-
- String[] text = new String[r.numParagraphs()];
- for(int i=0; i < r.numParagraphs(); i++) {
- Paragraph p = r.getParagraph(i);
- text[i] = p.text();
- }
-
- assertEquals(p_text.length, text.length);
- for(int i=0; i<p_text.length; i++) {
- assertEquals(p_text[i], text[i]);
- }
- }
-
- /**
- * Test textPieces based extraction
- */
- public void testExtractFromTextPieces() throws Exception {
- StringBuffer textBuf = new StringBuffer();
-
- Iterator textPieces = doc.getTextTable().getTextPieces().iterator();
- while (textPieces.hasNext()) {
- TextPiece piece = (TextPiece) textPieces.next();
-
- String encoding = "Cp1252";
- if (piece.isUnicode()) {
- encoding = "UTF-16LE";
- }
- String text = new String(piece.getRawBytes(), encoding);
- textBuf.append(text);
- }
-
- StringBuffer exp = new StringBuffer();
- for(int i=0; i<p_text.length; i++) {
- exp.append(p_text[i]);
- }
- assertEquals(exp.toString(), textBuf.toString());
- }
+ }
+
+ /**
+ * Test model based extraction
+ */
+ public void testExtractFromModel() {
+ Range r = doc.getRange();
+
+ String[] text = new String[r.numParagraphs()];
+ for (int i = 0; i < r.numParagraphs(); i++) {
+ Paragraph p = r.getParagraph(i);
+ text[i] = p.text();
+ }
+
+ assertEquals(p_text.length, text.length);
+ for (int i = 0; i < p_text.length; i++) {
+ assertEquals(p_text[i], text[i]);
+ }
+ }
+
+ /**
+ * Test textPieces based extraction
+ */
+ public void testExtractFromTextPieces() throws Exception {
+ StringBuffer textBuf = new StringBuffer();
+
+ Iterator textPieces = doc.getTextTable().getTextPieces().iterator();
+ while (textPieces.hasNext()) {
+ TextPiece piece = (TextPiece) textPieces.next();
+
+ String encoding = "Cp1252";
+ if (piece.isUnicode()) {
+ encoding = "UTF-16LE";
+ }
+ String text = new String(piece.getRawBytes(), encoding);
+ textBuf.append(text);
+ }
+
+ StringBuffer exp = new StringBuffer();
+ for (int i = 0; i < p_text.length; i++) {
+ exp.append(p_text[i]);
+ }
+ assertEquals(exp.toString(), textBuf.toString());
+ }
}
private String filename4;
// With unicode header and footer
private String filename5;
- // With footnote
- private String filename6;
+ // With footnote
+ private String filename6;
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception {
String pdirname = System.getProperty("POIFS.testdata.path");
String filename = "test2.doc";
filename3 = pdirname + "/excel_with_embeded.xls";
filename4 = "ThreeColHeadFoot.doc";
filename5 = "HeaderFooterUnicode.doc";
- filename6 = "footnote.doc";
+ filename6 = "footnote.doc";
extractor = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename));
extractor2 = new WordExtractor(HWPFTestDataSamples.openSampleFileStream(filename2));
for(int i=0; i<p_text1.length; i++) {
p_text1_block += p_text1[i];
}
- }
-
- /**
- * Test paragraph based extraction
- */
- public void testExtractFromParagraphs() {
- String[] text = extractor.getParagraphText();
-
- assertEquals(p_text1.length, text.length);
- for(int i=0; i<p_text1.length; i++) {
- assertEquals(p_text1[i], text[i]);
- }
-
- // On second one, should fall back
- assertEquals(1, extractor2.getParagraphText().length);
- }
-
- /**
- * Test the paragraph -> flat extraction
- */
- public void testGetText() {
- assertEquals(p_text1_block, extractor.getText());
-
- // On second one, should fall back to text piece
- assertEquals(extractor2.getTextFromPieces(), extractor2.getText());
- }
-
- /**
- * Test textPieces based extraction
- */
- public void testExtractFromTextPieces() {
- String text = extractor.getTextFromPieces();
- assertEquals(p_text1_block, text);
- }
-
-
- /**
- * Test that we can get data from two different
- * embeded word documents
- * @throws Exception
- */
- public void testExtractFromEmbeded() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(
- new FileInputStream(filename3));
- HWPFDocument doc;
- WordExtractor extractor3;
-
- DirectoryNode dirA = (DirectoryNode)
- fs.getRoot().getEntry("MBD0000A3B7");
- DirectoryNode dirB = (DirectoryNode)
- fs.getRoot().getEntry("MBD0000A3B2");
-
- // Should have WordDocument and 1Table
- assertNotNull(dirA.getEntry("1Table"));
- assertNotNull(dirA.getEntry("WordDocument"));
-
- assertNotNull(dirB.getEntry("1Table"));
- assertNotNull(dirB.getEntry("WordDocument"));
-
- // Check each in turn
- doc = new HWPFDocument(dirA, fs);
- extractor3 = new WordExtractor(doc);
-
- assertNotNull(extractor3.getText());
- assertTrue(extractor3.getText().length() > 20);
- assertEquals("I am a sample document\r\nNot much on me\r\nI am document 1\r\n",
- extractor3.getText());
- assertEquals("Sample Doc 1", extractor3.getSummaryInformation().getTitle());
- assertEquals("Sample Test", extractor3.getSummaryInformation().getSubject());
-
-
- doc = new HWPFDocument(dirB, fs);
- extractor3 = new WordExtractor(doc);
-
- assertNotNull(extractor3.getText());
- assertTrue(extractor3.getText().length() > 20);
- assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n",
- extractor3.getText());
- assertEquals("Sample Doc 2", extractor3.getSummaryInformation().getTitle());
- assertEquals("Another Sample Test", extractor3.getSummaryInformation().getSubject());
- }
-
- public void testWithHeader() throws Exception {
- // Non-unicode
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
- extractor = new WordExtractor(doc);
-
- assertEquals(
- "First header column!\tMid header Right header!\n",
- extractor.getHeaderText()
- );
-
- String text = extractor.getText();
- assertTrue(
- text.indexOf("First header column!") > -1
- );
-
-
- // Unicode
- doc = HWPFTestDataSamples.openSampleFile(filename5);
- extractor = new WordExtractor(doc);
-
- assertEquals(
- "This is a simple header, with a \u20ac euro symbol in it.\n\n",
- extractor.getHeaderText()
- );
- text = extractor.getText();
- assertTrue(
- text.indexOf("This is a simple header") > -1
- );
- }
-
- public void testWithFooter() throws Exception {
- // Non-unicode
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
- extractor = new WordExtractor(doc);
-
- assertEquals(
- "Footer Left\tFooter Middle Footer Right\n",
- extractor.getFooterText()
- );
-
- String text = extractor.getText();
- assertTrue(
- text.indexOf("Footer Left") > -1
- );
-
-
- // Unicode
- doc = HWPFTestDataSamples.openSampleFile(filename5);
- extractor = new WordExtractor(doc);
-
- assertEquals(
- "The footer, with Moli\u00e8re, has Unicode in it.\n",
- extractor.getFooterText()
- );
- text = extractor.getText();
- assertTrue(
- text.indexOf("The footer, with") > -1
- );
- }
-
- public void testFootnote() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
- extractor = new WordExtractor(doc);
-
- String[] text = extractor.getFootnoteText();
- StringBuffer b = new StringBuffer();
- for (int i=0; i<text.length; i++) {
- b.append(text[i]);
- }
-
- assertTrue(b.toString().contains("TestFootnote"));
- }
-
- public void testEndnote() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
- extractor = new WordExtractor(doc);
-
- String[] text = extractor.getEndnoteText();
- StringBuffer b = new StringBuffer();
- for (int i=0; i<text.length; i++) {
- b.append(text[i]);
- }
-
- assertTrue(b.toString().contains("TestEndnote"));
- }
-
- public void testComments() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
- extractor = new WordExtractor(doc);
-
- String[] text = extractor.getCommentsText();
- StringBuffer b = new StringBuffer();
- for (int i=0; i<text.length; i++) {
- b.append(text[i]);
- }
-
- assertTrue(b.toString().contains("TestComment"));
- }
+ }
+
+ /**
+ * Test paragraph based extraction
+ */
+ public void testExtractFromParagraphs() {
+ String[] text = extractor.getParagraphText();
+
+ assertEquals(p_text1.length, text.length);
+ for (int i = 0; i < p_text1.length; i++) {
+ assertEquals(p_text1[i], text[i]);
+ }
+
+ // On second one, should fall back
+ assertEquals(1, extractor2.getParagraphText().length);
+ }
+
+ /**
+ * Test the paragraph -> flat extraction
+ */
+ public void testGetText() {
+ assertEquals(p_text1_block, extractor.getText());
+
+ // On second one, should fall back to text piece
+ assertEquals(extractor2.getTextFromPieces(), extractor2.getText());
+ }
+
+ /**
+ * Test textPieces based extraction
+ */
+ public void testExtractFromTextPieces() {
+ String text = extractor.getTextFromPieces();
+ assertEquals(p_text1_block, text);
+ }
+
+
+ /**
+ * Test that we can get data from two different
+ * embeded word documents
+ * @throws Exception
+ */
+ public void testExtractFromEmbeded() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3));
+ HWPFDocument doc;
+ WordExtractor extractor3;
+
+ DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7");
+ DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2");
+
+ // Should have WordDocument and 1Table
+ assertNotNull(dirA.getEntry("1Table"));
+ assertNotNull(dirA.getEntry("WordDocument"));
+
+ assertNotNull(dirB.getEntry("1Table"));
+ assertNotNull(dirB.getEntry("WordDocument"));
+
+ // Check each in turn
+ doc = new HWPFDocument(dirA, fs);
+ extractor3 = new WordExtractor(doc);
+
+ assertNotNull(extractor3.getText());
+ assertTrue(extractor3.getText().length() > 20);
+ assertEquals("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", extractor3
+ .getText());
+ assertEquals("Sample Doc 1", extractor3.getSummaryInformation().getTitle());
+ assertEquals("Sample Test", extractor3.getSummaryInformation().getSubject());
+
+ doc = new HWPFDocument(dirB, fs);
+ extractor3 = new WordExtractor(doc);
+
+ assertNotNull(extractor3.getText());
+ assertTrue(extractor3.getText().length() > 20);
+ assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n",
+ extractor3.getText());
+ assertEquals("Sample Doc 2", extractor3.getSummaryInformation().getTitle());
+ assertEquals("Another Sample Test", extractor3.getSummaryInformation().getSubject());
+ }
+
+ public void testWithHeader() {
+ // Non-unicode
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
+ extractor = new WordExtractor(doc);
+
+ assertEquals("First header column!\tMid header Right header!\n", extractor.getHeaderText());
+
+ String text = extractor.getText();
+ assertTrue(text.indexOf("First header column!") > -1);
+
+ // Unicode
+ doc = HWPFTestDataSamples.openSampleFile(filename5);
+ extractor = new WordExtractor(doc);
+
+ assertEquals("This is a simple header, with a \u20ac euro symbol in it.\n\n", extractor
+ .getHeaderText());
+ text = extractor.getText();
+ assertTrue(text.indexOf("This is a simple header") > -1);
+ }
+
+ public void testWithFooter() {
+ // Non-unicode
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename4);
+ extractor = new WordExtractor(doc);
+
+ assertEquals("Footer Left\tFooter Middle Footer Right\n", extractor.getFooterText());
+
+ String text = extractor.getText();
+ assertTrue(text.indexOf("Footer Left") > -1);
+
+ // Unicode
+ doc = HWPFTestDataSamples.openSampleFile(filename5);
+ extractor = new WordExtractor(doc);
+
+ assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\n", extractor
+ .getFooterText());
+ text = extractor.getText();
+ assertTrue(text.indexOf("The footer, with") > -1);
+ }
+
+ public void testFootnote() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
+ extractor = new WordExtractor(doc);
+
+ String[] text = extractor.getFootnoteText();
+ StringBuffer b = new StringBuffer();
+ for (int i = 0; i < text.length; i++) {
+ b.append(text[i]);
+ }
+
+ assertTrue(b.toString().contains("TestFootnote"));
+ }
+
+ public void testEndnote() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
+ extractor = new WordExtractor(doc);
+
+ String[] text = extractor.getEndnoteText();
+ StringBuffer b = new StringBuffer();
+ for (int i = 0; i < text.length; i++) {
+ b.append(text[i]);
+ }
+
+ assertTrue(b.toString().contains("TestEndnote"));
+ }
+
+ public void testComments() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile(filename6);
+ extractor = new WordExtractor(doc);
+
+ String[] text = extractor.getCommentsText();
+ StringBuffer b = new StringBuffer();
+ for (int i = 0; i < text.length; i++) {
+ b.append(text[i]);
+ }
+
+ assertTrue(b.toString().contains("TestComment"));
+ }
}
package org.apache.poi.hwpf.extractor;
-import java.io.FileInputStream;
-
import junit.framework.TestCase;
+
import org.apache.poi.hwpf.HWPFTestDataSamples;
/**
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
-public class TestBug46610 extends TestCase {
-
- public void testUtf() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_1.doc");
-
- runExtract(doc);
- }
-
- public void testUtf2() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_2.doc");
-
- runExtract(doc);
- }
-
- public void testExtraction() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug46610_3.doc");
-
- String text = runExtract(doc);
-
- assertTrue(text.contains("\u0421\u0412\u041e\u042e"));
- }
-
- private String runExtract(HWPFDocument doc) {
- StringBuffer out = new StringBuffer();
-
- Range globalRange = doc.getRange();
- for (int i = 0; i < globalRange.numParagraphs(); i++) {
- Paragraph p = globalRange.getParagraph(i);
- out.append(p.text());
- out.append("\n");
- for (int j = 0; j < p.numCharacterRuns(); j++) {
- CharacterRun characterRun = p.getCharacterRun(j);
- characterRun.text();
- }
- }
-
- return out.toString();
- }
+public final class TestBug46610 extends TestCase {
+
+ public void testUtf() {
+ runExtract("Bug46610_1.doc");
+ }
+
+ public void testUtf2() {
+ runExtract("Bug46610_2.doc");
+ }
+
+ public void testExtraction() {
+ String text = runExtract("Bug46610_3.doc");
+ assertTrue(text.contains("\u0421\u0412\u041e\u042e"));
+ }
+
+ private static String runExtract(String sampleName) {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
+ StringBuffer out = new StringBuffer();
+
+ Range globalRange = doc.getRange();
+ for (int i = 0; i < globalRange.numParagraphs(); i++) {
+ Paragraph p = globalRange.getParagraph(i);
+ out.append(p.text());
+ out.append("\n");
+ for (int j = 0; j < p.numCharacterRuns(); j++) {
+ CharacterRun characterRun = p.getCharacterRun(j);
+ characterRun.text();
+ }
+ }
+ return out.toString();
+ }
}
private HWPFDocument unicode;
private HWPFDocument withFields;
- protected void setUp() throws Exception {
+ protected void setUp() {
none = HWPFTestDataSamples.openSampleFile("NoHeadFoot.doc");
header = HWPFTestDataSamples.openSampleFile("ThreeColHead.doc");
/**
* two jpegs
*/
- public void testTwoImages() throws Exception {
+ public void testTwoImages() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc");
List pics = doc.getPicturesTable().getAllPictures();
/**
* pngs and jpegs
*/
- public void testDifferentImages() throws Exception {
+ public void testDifferentImages() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc");
List pics = doc.getPicturesTable().getAllPictures();
/**
* emf image, nice and simple
*/
- public void testEmfImage() throws Exception {
+ public void testEmfImage() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc");
List pics = doc.getPicturesTable().getAllPictures();
/**
* emf image, with a crazy offset
*/
- public void disabled_testEmfComplexImage() throws Exception {
+ public void disabled_testEmfComplexImage() {
// Commenting out this test case temporarily. The file emf_2003_image does not contain any
// pictures. Instead it has an office drawing object. Need to rewrite this test after
assertEquals(0x80000000l, LittleEndian.getUInt(pic.getRawContent()));
}
- public void testPicturesWithTable() throws Exception {
+ public void testPicturesWithTable() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc");
List pics = doc.getPicturesTable().getAllPictures();
assertEquals(pics.size(), 2);
}
-
}
*/
public final class TestProblems extends HWPFTestCase {
- /**
- * ListEntry passed no ListTable
- */
- public void testListEntryNoListTable() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ListEntryNoListTable.doc");
-
- Range r = doc.getRange();
- StyleSheet styleSheet = doc.getStyleSheet();
- for (int x = 0; x < r.numSections(); x++) {
- Section s = r.getSection(x);
- for (int y = 0; y < s.numParagraphs(); y++) {
- Paragraph paragraph = s.getParagraph(y);
- //System.out.println(paragraph.getCharacterRun(0).text());
- }
- }
- }
+ /**
+ * ListEntry passed no ListTable
+ */
+ public void testListEntryNoListTable() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ListEntryNoListTable.doc");
+
+ Range r = doc.getRange();
+ StyleSheet styleSheet = doc.getStyleSheet();
+ for (int x = 0; x < r.numSections(); x++) {
+ Section s = r.getSection(x);
+ for (int y = 0; y < s.numParagraphs(); y++) {
+ Paragraph paragraph = s.getParagraph(y);
+ // System.out.println(paragraph.getCharacterRun(0).text());
+ }
+ }
+ }
/**
* AIOOB for TableSprmUncompressor.unCompressTAPOperation
*/
- public void testSprmAIOOB() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc");
-
- Range r = doc.getRange();
- StyleSheet styleSheet = doc.getStyleSheet();
- for (int x = 0; x < r.numSections(); x++) {
- Section s = r.getSection(x);
- for (int y = 0; y < s.numParagraphs(); y++) {
- Paragraph paragraph = s.getParagraph(y);
- //System.out.println(paragraph.getCharacterRun(0).text());
- }
- }
+ public void testSprmAIOOB() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc");
+
+ Range r = doc.getRange();
+ StyleSheet styleSheet = doc.getStyleSheet();
+ for (int x = 0; x < r.numSections(); x++) {
+ Section s = r.getSection(x);
+ for (int y = 0; y < s.numParagraphs(); y++) {
+ Paragraph paragraph = s.getParagraph(y);
+ // System.out.println(paragraph.getCharacterRun(0).text());
+ }
+ }
}
/**
- * Test for TableCell not skipping the last paragraph.
- * Bugs #45062 and #44292
+ * Test for TableCell not skipping the last paragraph. Bugs #45062 and
+ * #44292
*/
- public void testTableCellLastParagraph() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44292.doc");
+ public void testTableCellLastParagraph() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44292.doc");
Range r = doc.getRange();
assertEquals(6, r.numParagraphs());
assertEquals(0, r.getStartOffset());
// Get the table
Table t = r.getTable(p);
- //get the only row
+ // get the only row
assertEquals(1, t.numRows());
TableRow row = t.getRow(0);
- //get the first cell
+ // get the first cell
TableCell cell = row.getCell(0);
// First cell should have one paragraph
assertEquals(1, cell.numParagraphs());
assertEquals("One paragraph is ok\7", cell.getParagraph(0).text());
- //get the second
+ // get the second
cell = row.getCell(1);
// Second cell should be detected as having two paragraphs
assertEquals(2, cell.numParagraphs());
assertEquals("First para is ok\r", cell.getParagraph(0).text());
assertEquals("Second paragraph is skipped\7", cell.getParagraph(1).text());
- //get the last cell
+ // get the last cell
cell = row.getCell(2);
// Last cell should have one paragraph
assertEquals(1, cell.numParagraphs());
assertEquals("One paragraph is ok\7", cell.getParagraph(0).text());
}
- public void testRangeDelete() throws Exception {
- HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug28627.doc");
+ public void testRangeDelete() {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug28627.doc");
- Range range = doc.getRange();
+ Range range = doc.getRange();
int numParagraphs = range.numParagraphs();
int totalLength = 0, deletedLength = 0;
// check the text length after deletion
int newLength = 0;
- range = doc.getRange();
+ range = doc.getRange();
numParagraphs = range.numParagraphs();
for (int i = 0; i < numParagraphs; i++) {
}
/**
- * With an encrypted file, we should give a suitable
- * exception, and not OOM
+ * With an encrypted file, we should give a suitable exception, and not OOM
*/
- public void testEncryptedFile() throws Exception {
+ public void testEncryptedFile() {
try {
HWPFTestDataSamples.openSampleFile("PasswordProtected.doc");
fail();
- } catch(EncryptedDocumentException e) {
+ } catch (EncryptedDocumentException e) {
// Good
}
}
- public void testWriteProperties() throws Exception {
+ public void testWriteProperties() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
// Write and read
HWPFDocument doc2 = writeOutAndRead(doc);
- assertEquals("Nick Burch", doc.getSummaryInformation().getAuthor());
+ assertEquals("Nick Burch", doc2.getSummaryInformation().getAuthor());
}
}
/**
* Test just opening the files
*/
- public void testOpen() throws Exception {
+ public void testOpen() {
- HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
}
/**
* Test (more "confirm" than test) that we have the general structure that we expect to have.
*/
- public void testDocStructure() throws Exception {
+ public void testDocStructure() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
Range range;
/**
* Test that we can delete text (one instance) from our Range with Unicode text.
*/
- public void testRangeDeleteOne() throws Exception {
+ public void testRangeDeleteOne() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
/**
* Test that we can delete text (all instances of) from our Range with Unicode text.
*/
- public void testRangeDeleteAll() throws Exception {
+ public void testRangeDeleteAll() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
/**
* Test just opening the files
*/
- public void testOpen() throws Exception {
+ public void testOpen() {
- HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
}
/**
* Test (more "confirm" than test) that we have the general structure that we expect to have.
*/
- public void testDocStructure() throws Exception {
+ public void testDocStructure() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
/**
* Test that we can insert text in our CharacterRun with Unicode text.
*/
- public void testRangeInsertion() throws Exception {
+ public void testRangeInsertion() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
- /*
+ if (false) { // TODO - delete or resurrect this code
Range range = daDoc.getRange();
Section section = range.getSection(0);
Paragraph para = section.getParagraph(2);
para.getCharacterRun(2).text();
System.out.println(text);
- */
+ }
Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc);
range.insertBefore(textToInsert);
// System.out.println(text);
assertEquals((textToInsert + originalText), text);
-
}
}
"The trick with this one is that it contains some Unicode based strings in it.\r" +
"Firstly, some currency symbols:\r" +
"\tGBP - \u00a3\r" +
- "\tEUR - \u20ac\r" +
- "Now, we\u2019ll have some French text, in bold and big:\r" +
- "\tMoli\u00e8re\r" +
- "And some normal French text:\r" +
- "\tL'Avare ou l'\u00c9cole du mensonge\r" +
- "That\u2019s it for page one\r"
+ "\tEUR - \u20ac\r" +
+ "Now, we\u2019ll have some French text, in bold and big:\r" +
+ "\tMoli\u00e8re\r" +
+ "And some normal French text:\r" +
+ "\tL'Avare ou l'\u00c9cole du mensonge\r" +
+ "That\u2019s it for page one\r"
;
private static final String u_page_2 =
"This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
private HWPFDocument u;
private HWPFDocument a;
- protected void setUp() throws Exception {
+ protected void setUp() {
u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
}
/**
* Test just opening the files
*/
- public void testOpen() throws Exception {
+ public void testOpen() {
- HWPFDocument docA = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
+ HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
}
/**
* Test (more "confirm" than test) that we have the general structure that we expect to have.
*/
- public void testDocStructure() throws Exception {
+ public void testDocStructure() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
/**
* Test that we can replace text in our Range with Unicode text.
*/
- public void testRangeReplacementOne() throws Exception {
+ public void testRangeReplacementOne() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
/**
* Test that we can replace text in our Range with Unicode text.
*/
- public void testRangeReplacementAll() throws Exception {
+ public void testRangeReplacementAll() {
HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
assertTrue(fsText.indexOf("TITLE = Titel: \u00c4h") > -1);
}
- public void test42726() throws Exception {
- HPSFPropertiesExtractor ex = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls"));
- String txt = ex.getText();
- assertTrue(txt.indexOf("PID_AUTHOR") != -1);
- assertTrue(txt.indexOf("PID_EDITTIME") != -1);
- assertTrue(txt.indexOf("PID_REVNUMBER") != -1);
- assertTrue(txt.indexOf("PID_THUMBNAIL") != -1);
- }
+ public void test42726() {
+ HPSFPropertiesExtractor ex = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls"));
+ String txt = ex.getText();
+ assertTrue(txt.indexOf("PID_AUTHOR") != -1);
+ assertTrue(txt.indexOf("PID_EDITTIME") != -1);
+ assertTrue(txt.indexOf("PID_REVNUMBER") != -1);
+ assertTrue(txt.indexOf("PID_THUMBNAIL") != -1);
+ }
}
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder.
private static final HSSFTestDataSamples _inst = new HSSFTestDataSamples("HSSF.testdata.path", "SampleSS.xls");
- private HSSFTestDataSamples(String dir, String classPathTestFile){
- super(dir, classPathTestFile);
- }
+ private HSSFTestDataSamples(String dir, String classPathTestFile){
+ super(dir, classPathTestFile);
+ }
- public static POIDataSamples getInstance(){
- return _inst;
- }
+ public static POIDataSamples getInstance(){
+ return _inst;
+ }
- public static InputStream openSampleFileStream(String sampleFileName) {
- return _inst.openResourceAsStream(sampleFileName);
- }
- public static byte[] getTestDataFileContent(String fileName) {
- return _inst.readFile(fileName);
- }
+ public static InputStream openSampleFileStream(String sampleFileName) {
+ return _inst.openResourceAsStream(sampleFileName);
+ }
+ public static byte[] getTestDataFileContent(String fileName) {
+ return _inst.readFile(fileName);
+ }
- public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
+ public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
try {
return new HSSFWorkbook(_inst.openResourceAsStream(sampleFileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
-
}