*/
public class PDFStructElem extends StructureHierarchyMember
implements StructureTreeElement, CompressedObject, Serializable {
+ private static final List<StructureType> BLSE = Arrays.asList(StandardStructureTypes.Table.TABLE,
+ StandardStructureTypes.List.L, StandardStructureTypes.Paragraphlike.P);
private static final long serialVersionUID = -3055241807589202532L;
private StructureType structureType;
put("Alt", "No alternate text specified");
} else if (kids != null) {
for (PDFObject kid : kids) {
- if (kid instanceof PDFStructElem
- && !(kid instanceof Placeholder)
- && structureType.toString().equals("P")
- && isBSLE(((PDFStructElem) kid).getStructureType().toString())) {
+ if (kid instanceof PDFStructElem && isBSLE(((PDFStructElem) kid))) {
structureType = StandardStructureTypes.Grouping.DIV;
- put("S", StandardStructureTypes.Grouping.DIV.getName());
+ put("S", structureType.getName());
break;
}
}
return super.output(stream);
}
- private boolean isBSLE(String type) {
- String[] blseValues = {"Table", "L", "P"};
- return Arrays.asList(blseValues).contains(type);
+ private boolean isBSLE(PDFStructElem kid) {
+ boolean pType = !(kid instanceof Placeholder) && structureType == StandardStructureTypes.Paragraphlike.P;
+ return pType && BLSE.contains(kid.getStructureType());
}
/**
public class PDFUAWarningTestCase {
- PDFFactory pdfFactory;
+ private PDFFactory pdfFactory;
+
+ @Before
+ public void setUp() {
+ PDFParentTree tree = new PDFParentTree();
+ PDFDocument doc = new PDFDocument("");
+ doc.makeStructTreeRoot(tree);
+ doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1);
+ pdfFactory = new PDFFactory(doc);
+ }
@Test
public void nestedTableWarningTestCase() throws IOException {
Assert.assertEquals("Div", block.getStructureType().toString());
}
- @Before
- public void setUp() {
- PDFParentTree tree = new PDFParentTree();
- PDFDocument doc = new PDFDocument("");
- doc.makeStructTreeRoot(tree);
- doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1);
- pdfFactory = new PDFFactory(doc);
+ @Test
+ public void testNoStructureType() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ PDFStructElem structElem = new PDFStructElem();
+ structElem.setDocument(pdfFactory.getDocument());
+ PDFStructElem structElem2 = new PDFStructElem();
+ structElem2.setDocument(pdfFactory.getDocument());
+ structElem.addKid(structElem2);
+ structElem.output(bos);
+ Assert.assertEquals(bos.toString(), "<< /K [<< >>] >>");
}
}