mirror of https://github.com/apache/poi.git
Fix inconsistent indents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1661912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
970d7d7c18
commit
42d9b31296
|
@ -39,99 +39,98 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
||||||
|
|
||||||
public final class TestXWPFDocument extends TestCase {
|
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()) {
|
||||||
if(part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
|
if(part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (false) {
|
if (false) {
|
||||||
// successful tests should be silent
|
// successful tests should be silent
|
||||||
System.out.println(part);
|
System.out.println(part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOpen() throws Exception {
|
public void testOpen() throws Exception {
|
||||||
XWPFDocument xml;
|
XWPFDocument xml;
|
||||||
|
|
||||||
// Simple file
|
// Simple file
|
||||||
xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
// Check it has key parts
|
// Check it has key parts
|
||||||
assertNotNull(xml.getDocument());
|
assertNotNull(xml.getDocument());
|
||||||
assertNotNull(xml.getDocument().getBody());
|
assertNotNull(xml.getDocument().getBody());
|
||||||
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 IOException {
|
public void testMetadataBasics() throws IOException {
|
||||||
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());
|
||||||
|
|
||||||
assertEquals("Microsoft Office Word", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
assertEquals("Microsoft Office Word", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
assertEquals(1315, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
|
assertEquals(1315, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
|
||||||
assertEquals(10, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
|
assertEquals(10, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
|
||||||
|
|
||||||
assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
|
assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
|
||||||
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMetadataComplex() throws IOException {
|
public void testMetadataComplex() throws IOException {
|
||||||
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());
|
||||||
|
|
||||||
assertEquals("Microsoft Office Outlook", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
assertEquals("Microsoft Office Outlook", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
assertEquals(5184, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
|
assertEquals(5184, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
|
||||||
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
|
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
|
||||||
|
|
||||||
assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
|
assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
|
||||||
assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWorkbookProperties() {
|
public void testWorkbookProperties() {
|
||||||
XWPFDocument doc = new XWPFDocument();
|
XWPFDocument doc = new XWPFDocument();
|
||||||
POIXMLProperties props = doc.getProperties();
|
POIXMLProperties props = doc.getProperties();
|
||||||
assertNotNull(props);
|
assertNotNull(props);
|
||||||
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddParagraph() throws IOException{
|
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
|
||||||
assertEquals(3, doc.getParagraphs().size());
|
|
||||||
|
|
||||||
XWPFParagraph p = doc.createParagraph();
|
public void testAddParagraph() throws IOException{
|
||||||
assertEquals(p, doc.getParagraphs().get(3));
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
assertEquals(4, doc.getParagraphs().size());
|
assertEquals(3, doc.getParagraphs().size());
|
||||||
|
|
||||||
assertEquals(3, doc.getParagraphPos(3));
|
|
||||||
assertEquals(3, doc.getPosOfParagraph(p));
|
|
||||||
|
|
||||||
CTP ctp = p.getCTP();
|
XWPFParagraph p = doc.createParagraph();
|
||||||
XWPFParagraph newP = doc.getParagraph(ctp);
|
assertEquals(p, doc.getParagraphs().get(3));
|
||||||
assertSame(p, newP);
|
assertEquals(4, doc.getParagraphs().size());
|
||||||
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
|
|
||||||
XWPFParagraph cP = doc.insertNewParagraph(cursor);
|
|
||||||
assertSame(cP, doc.getParagraphs().get(0));
|
|
||||||
assertEquals(5, doc.getParagraphs().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAddPicture() throws IOException, InvalidFormatException
|
assertEquals(3, doc.getParagraphPos(3));
|
||||||
{
|
assertEquals(3, doc.getPosOfParagraph(p));
|
||||||
|
|
||||||
|
CTP ctp = p.getCTP();
|
||||||
|
XWPFParagraph newP = doc.getParagraph(ctp);
|
||||||
|
assertSame(p, newP);
|
||||||
|
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
|
||||||
|
XWPFParagraph cP = doc.insertNewParagraph(cursor);
|
||||||
|
assertSame(cP, doc.getParagraphs().get(0));
|
||||||
|
assertEquals(5, doc.getParagraphs().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddPicture() throws IOException, InvalidFormatException {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
|
byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
|
||||||
String relationId = doc.addPictureData(jpeg,XWPFDocument.PICTURE_TYPE_JPEG);
|
String relationId = doc.addPictureData(jpeg,XWPFDocument.PICTURE_TYPE_JPEG);
|
||||||
|
|
||||||
byte[] newJpeg = ((XWPFPictureData) doc.getRelationById(relationId)).getData();
|
byte[] newJpeg = ((XWPFPictureData) doc.getRelationById(relationId)).getData();
|
||||||
assertEquals(newJpeg.length,jpeg.length);
|
assertEquals(newJpeg.length,jpeg.length);
|
||||||
for (int i = 0 ; i < jpeg.length ; i++)
|
for (int i = 0 ; i < jpeg.length ; i++)
|
||||||
|
@ -161,182 +160,182 @@ public final class TestXWPFDocument extends TestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveBodyElement() throws IOException {
|
public void testRemoveBodyElement() throws IOException {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
assertEquals(3, doc.getParagraphs().size());
|
assertEquals(3, doc.getParagraphs().size());
|
||||||
assertEquals(3, doc.getBodyElements().size());
|
assertEquals(3, doc.getBodyElements().size());
|
||||||
|
|
||||||
XWPFParagraph p1 = doc.getParagraphs().get(0);
|
XWPFParagraph p1 = doc.getParagraphs().get(0);
|
||||||
XWPFParagraph p2 = doc.getParagraphs().get(1);
|
XWPFParagraph p2 = doc.getParagraphs().get(1);
|
||||||
XWPFParagraph p3 = doc.getParagraphs().get(2);
|
XWPFParagraph p3 = doc.getParagraphs().get(2);
|
||||||
|
|
||||||
assertEquals(p1, doc.getBodyElements().get(0));
|
assertEquals(p1, doc.getBodyElements().get(0));
|
||||||
assertEquals(p1, doc.getParagraphs().get(0));
|
assertEquals(p1, doc.getParagraphs().get(0));
|
||||||
assertEquals(p2, doc.getBodyElements().get(1));
|
assertEquals(p2, doc.getBodyElements().get(1));
|
||||||
assertEquals(p2, doc.getParagraphs().get(1));
|
assertEquals(p2, doc.getParagraphs().get(1));
|
||||||
assertEquals(p3, doc.getBodyElements().get(2));
|
assertEquals(p3, doc.getBodyElements().get(2));
|
||||||
assertEquals(p3, doc.getParagraphs().get(2));
|
assertEquals(p3, doc.getParagraphs().get(2));
|
||||||
|
|
||||||
// Add another
|
// Add another
|
||||||
XWPFParagraph p4 = doc.createParagraph();
|
XWPFParagraph p4 = doc.createParagraph();
|
||||||
|
|
||||||
assertEquals(4, doc.getParagraphs().size());
|
assertEquals(4, doc.getParagraphs().size());
|
||||||
assertEquals(4, doc.getBodyElements().size());
|
assertEquals(4, doc.getBodyElements().size());
|
||||||
assertEquals(p1, doc.getBodyElements().get(0));
|
assertEquals(p1, doc.getBodyElements().get(0));
|
||||||
assertEquals(p1, doc.getParagraphs().get(0));
|
assertEquals(p1, doc.getParagraphs().get(0));
|
||||||
assertEquals(p2, doc.getBodyElements().get(1));
|
assertEquals(p2, doc.getBodyElements().get(1));
|
||||||
assertEquals(p2, doc.getParagraphs().get(1));
|
assertEquals(p2, doc.getParagraphs().get(1));
|
||||||
assertEquals(p3, doc.getBodyElements().get(2));
|
assertEquals(p3, doc.getBodyElements().get(2));
|
||||||
assertEquals(p3, doc.getParagraphs().get(2));
|
assertEquals(p3, doc.getParagraphs().get(2));
|
||||||
assertEquals(p4, doc.getBodyElements().get(3));
|
assertEquals(p4, doc.getBodyElements().get(3));
|
||||||
assertEquals(p4, doc.getParagraphs().get(3));
|
assertEquals(p4, doc.getParagraphs().get(3));
|
||||||
|
|
||||||
// Remove the 2nd
|
// Remove the 2nd
|
||||||
assertEquals(true, doc.removeBodyElement(1));
|
assertEquals(true, doc.removeBodyElement(1));
|
||||||
assertEquals(3, doc.getParagraphs().size());
|
assertEquals(3, doc.getParagraphs().size());
|
||||||
assertEquals(3, doc.getBodyElements().size());
|
assertEquals(3, doc.getBodyElements().size());
|
||||||
|
|
||||||
assertEquals(p1, doc.getBodyElements().get(0));
|
assertEquals(p1, doc.getBodyElements().get(0));
|
||||||
assertEquals(p1, doc.getParagraphs().get(0));
|
assertEquals(p1, doc.getParagraphs().get(0));
|
||||||
assertEquals(p3, doc.getBodyElements().get(1));
|
assertEquals(p3, doc.getBodyElements().get(1));
|
||||||
assertEquals(p3, doc.getParagraphs().get(1));
|
assertEquals(p3, doc.getParagraphs().get(1));
|
||||||
assertEquals(p4, doc.getBodyElements().get(2));
|
assertEquals(p4, doc.getBodyElements().get(2));
|
||||||
assertEquals(p4, doc.getParagraphs().get(2));
|
assertEquals(p4, doc.getParagraphs().get(2));
|
||||||
|
|
||||||
// Remove the 1st
|
// Remove the 1st
|
||||||
assertEquals(true, doc.removeBodyElement(0));
|
assertEquals(true, doc.removeBodyElement(0));
|
||||||
assertEquals(2, doc.getParagraphs().size());
|
assertEquals(2, doc.getParagraphs().size());
|
||||||
assertEquals(2, doc.getBodyElements().size());
|
assertEquals(2, doc.getBodyElements().size());
|
||||||
|
|
||||||
assertEquals(p3, doc.getBodyElements().get(0));
|
assertEquals(p3, doc.getBodyElements().get(0));
|
||||||
assertEquals(p3, doc.getParagraphs().get(0));
|
assertEquals(p3, doc.getParagraphs().get(0));
|
||||||
assertEquals(p4, doc.getBodyElements().get(1));
|
assertEquals(p4, doc.getBodyElements().get(1));
|
||||||
assertEquals(p4, doc.getParagraphs().get(1));
|
assertEquals(p4, doc.getParagraphs().get(1));
|
||||||
|
|
||||||
// Remove the last
|
// Remove the last
|
||||||
assertEquals(true, doc.removeBodyElement(1));
|
assertEquals(true, doc.removeBodyElement(1));
|
||||||
assertEquals(1, doc.getParagraphs().size());
|
assertEquals(1, doc.getParagraphs().size());
|
||||||
assertEquals(1, doc.getBodyElements().size());
|
assertEquals(1, doc.getBodyElements().size());
|
||||||
|
|
||||||
assertEquals(p3, doc.getBodyElements().get(0));
|
assertEquals(p3, doc.getBodyElements().get(0));
|
||||||
assertEquals(p3, doc.getParagraphs().get(0));
|
assertEquals(p3, doc.getParagraphs().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRegisterPackagePictureData() throws IOException, InvalidFormatException {
|
public void testRegisterPackagePictureData() throws IOException, InvalidFormatException {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
|
||||||
|
|
||||||
/* manually assemble a new image package part*/
|
/* manually assemble a new image package part*/
|
||||||
OPCPackage opcPckg = doc.getPackage();
|
OPCPackage opcPckg = doc.getPackage();
|
||||||
XWPFRelation jpgRelation = XWPFRelation.IMAGE_JPEG;
|
XWPFRelation jpgRelation = XWPFRelation.IMAGE_JPEG;
|
||||||
PackagePartName partName = PackagingURIHelper.createPartName(jpgRelation.getDefaultFileName().replace('#', '2'));
|
PackagePartName partName = PackagingURIHelper.createPartName(jpgRelation.getDefaultFileName().replace('#', '2'));
|
||||||
PackagePart newImagePart = opcPckg.createPart(partName, jpgRelation.getContentType());
|
PackagePart newImagePart = opcPckg.createPart(partName, jpgRelation.getContentType());
|
||||||
byte[] nature1 = XWPFTestDataSamples.getImage("abstract4.jpg");
|
byte[] nature1 = XWPFTestDataSamples.getImage("abstract4.jpg");
|
||||||
OutputStream os = newImagePart.getOutputStream();
|
OutputStream os = newImagePart.getOutputStream();
|
||||||
os.write(nature1);
|
os.write(nature1);
|
||||||
os.close();
|
os.close();
|
||||||
XWPFHeader xwpfHeader = doc.getHeaderArray(0);
|
XWPFHeader xwpfHeader = doc.getHeaderArray(0);
|
||||||
PackageRelationship relationship = xwpfHeader.getPackagePart().addRelationship(partName, TargetMode.INTERNAL, jpgRelation.getRelation());
|
PackageRelationship relationship = xwpfHeader.getPackagePart().addRelationship(partName, TargetMode.INTERNAL, jpgRelation.getRelation());
|
||||||
XWPFPictureData newPicData = new XWPFPictureData(newImagePart,relationship);
|
XWPFPictureData newPicData = new XWPFPictureData(newImagePart,relationship);
|
||||||
/* new part is now ready to rumble */
|
/* new part is now ready to rumble */
|
||||||
|
|
||||||
assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
|
|
||||||
assertFalse(doc.getAllPictures().contains(newPicData));
|
|
||||||
assertFalse(doc.getAllPackagePictures().contains(newPicData));
|
|
||||||
|
|
||||||
doc.registerPackagePictureData(newPicData);
|
assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
|
||||||
|
assertFalse(doc.getAllPictures().contains(newPicData));
|
||||||
assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
|
assertFalse(doc.getAllPackagePictures().contains(newPicData));
|
||||||
assertFalse(doc.getAllPictures().contains(newPicData));
|
|
||||||
assertTrue(doc.getAllPackagePictures().contains(newPicData));
|
|
||||||
|
|
||||||
doc.getPackage().revert();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFindPackagePictureData() throws IOException {
|
doc.registerPackagePictureData(newPicData);
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
|
|
||||||
byte[] nature1 = XWPFTestDataSamples.getImage("nature1.gif");
|
assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
|
||||||
XWPFPictureData part = doc.findPackagePictureData(nature1, Document.PICTURE_TYPE_GIF);
|
assertFalse(doc.getAllPictures().contains(newPicData));
|
||||||
assertNotNull(part);
|
assertTrue(doc.getAllPackagePictures().contains(newPicData));
|
||||||
assertTrue(doc.getAllPictures().contains(part));
|
|
||||||
assertTrue(doc.getAllPackagePictures().contains(part));
|
doc.getPackage().revert();
|
||||||
doc.getPackage().revert();
|
}
|
||||||
}
|
|
||||||
|
public void testFindPackagePictureData() throws IOException {
|
||||||
public void testGetAllPictures() throws IOException {
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
|
byte[] nature1 = XWPFTestDataSamples.getImage("nature1.gif");
|
||||||
List<XWPFPictureData> allPictures = doc.getAllPictures();
|
XWPFPictureData part = doc.findPackagePictureData(nature1, Document.PICTURE_TYPE_GIF);
|
||||||
List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
|
assertNotNull(part);
|
||||||
|
assertTrue(doc.getAllPictures().contains(part));
|
||||||
assertNotNull(allPictures);
|
assertTrue(doc.getAllPackagePictures().contains(part));
|
||||||
assertEquals(3,allPictures.size());
|
doc.getPackage().revert();
|
||||||
for (XWPFPictureData xwpfPictureData : allPictures) {
|
}
|
||||||
assertTrue(allPackagePictures.contains(xwpfPictureData));
|
|
||||||
|
public void testGetAllPictures() throws IOException {
|
||||||
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
|
||||||
|
List<XWPFPictureData> allPictures = doc.getAllPictures();
|
||||||
|
List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
|
||||||
|
|
||||||
|
assertNotNull(allPictures);
|
||||||
|
assertEquals(3,allPictures.size());
|
||||||
|
for (XWPFPictureData xwpfPictureData : allPictures) {
|
||||||
|
assertTrue(allPackagePictures.contains(xwpfPictureData));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
allPictures.add(allPictures.get(0));
|
allPictures.add(allPictures.get(0));
|
||||||
fail("This list must be unmodifiable!");
|
fail("This list must be unmodifiable!");
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// all ok
|
// all ok
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.getPackage().revert();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetAllPackagePictures() throws IOException {
|
doc.getPackage().revert();
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
|
}
|
||||||
List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
|
|
||||||
|
|
||||||
assertNotNull(allPackagePictures);
|
|
||||||
assertEquals(5,allPackagePictures.size());
|
|
||||||
|
|
||||||
try {
|
public void testGetAllPackagePictures() throws IOException {
|
||||||
allPackagePictures.add(allPackagePictures.get(0));
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
|
||||||
fail("This list must be unmodifiable!");
|
List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
|
||||||
} catch (UnsupportedOperationException e) {
|
|
||||||
// all ok
|
|
||||||
}
|
|
||||||
|
|
||||||
doc.getPackage().revert();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPictureHandlingSimpleFile() throws IOException, InvalidFormatException {
|
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
|
|
||||||
assertEquals(1,doc.getAllPackagePictures().size());
|
|
||||||
byte[] newPic = XWPFTestDataSamples.getImage("abstract4.jpg");
|
|
||||||
String id1 = doc.addPictureData(newPic, Document.PICTURE_TYPE_JPEG);
|
|
||||||
assertEquals(2,doc.getAllPackagePictures().size());
|
|
||||||
/* copy data, to avoid instance-equality */
|
|
||||||
byte[] newPicCopy = Arrays.copyOf(newPic, newPic.length);
|
|
||||||
String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
|
|
||||||
assertEquals(id1,id2);
|
|
||||||
doc.getPackage().revert();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPictureHandlingHeaderDocumentImages() throws IOException {
|
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_2.docx");
|
|
||||||
assertEquals(1,doc.getAllPictures().size());
|
|
||||||
assertEquals(1,doc.getAllPackagePictures().size());
|
|
||||||
assertEquals(1,doc.getHeaderArray(0).getAllPictures().size());
|
|
||||||
doc.getPackage().revert();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
|
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
|
|
||||||
XWPFHeader xwpfHeader = doc.getHeaderArray(0);
|
|
||||||
|
|
||||||
assertEquals(3,doc.getAllPictures().size());
|
assertNotNull(allPackagePictures);
|
||||||
|
assertEquals(5,allPackagePictures.size());
|
||||||
|
|
||||||
|
try {
|
||||||
|
allPackagePictures.add(allPackagePictures.get(0));
|
||||||
|
fail("This list must be unmodifiable!");
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
|
// all ok
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.getPackage().revert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPictureHandlingSimpleFile() throws IOException, InvalidFormatException {
|
||||||
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
|
||||||
|
assertEquals(1,doc.getAllPackagePictures().size());
|
||||||
|
byte[] newPic = XWPFTestDataSamples.getImage("abstract4.jpg");
|
||||||
|
String id1 = doc.addPictureData(newPic, Document.PICTURE_TYPE_JPEG);
|
||||||
|
assertEquals(2,doc.getAllPackagePictures().size());
|
||||||
|
/* copy data, to avoid instance-equality */
|
||||||
|
byte[] newPicCopy = Arrays.copyOf(newPic, newPic.length);
|
||||||
|
String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
|
||||||
|
assertEquals(id1,id2);
|
||||||
|
doc.getPackage().revert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPictureHandlingHeaderDocumentImages() throws IOException {
|
||||||
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_2.docx");
|
||||||
|
assertEquals(1,doc.getAllPictures().size());
|
||||||
|
assertEquals(1,doc.getAllPackagePictures().size());
|
||||||
|
assertEquals(1,doc.getHeaderArray(0).getAllPictures().size());
|
||||||
|
doc.getPackage().revert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
|
||||||
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
|
||||||
|
XWPFHeader xwpfHeader = doc.getHeaderArray(0);
|
||||||
|
|
||||||
|
assertEquals(3,doc.getAllPictures().size());
|
||||||
assertEquals(3,xwpfHeader.getAllPictures().size());
|
assertEquals(3,xwpfHeader.getAllPictures().size());
|
||||||
assertEquals(5,doc.getAllPackagePictures().size());
|
assertEquals(5,doc.getAllPackagePictures().size());
|
||||||
|
|
||||||
byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
|
byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
|
||||||
String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
|
String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
|
||||||
POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
|
POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
|
||||||
XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
|
XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
|
||||||
assertSame(part1,part2);
|
assertSame(part1,part2);
|
||||||
|
|
||||||
doc.getPackage().revert();
|
doc.getPackage().revert();
|
||||||
}
|
}
|
||||||
public void testZeroLengthLibreOfficeDocumentWithWaterMarkHeader() throws IOException {
|
public void testZeroLengthLibreOfficeDocumentWithWaterMarkHeader() throws IOException {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("zero-length.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("zero-length.docx");
|
||||||
POIXMLProperties properties = doc.getProperties();
|
POIXMLProperties properties = doc.getProperties();
|
||||||
|
|
Loading…
Reference in New Issue