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