use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testHrefNameButNoContent.
@Test
public void testHrefNameButNoContent() throws Docx4JException {
String name = "anchor0";
String href = "http://www.google.com";
String content = null;
List<Object> objects = fromXHTML(a(href, name, content));
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
// Test just bookmark start + end + span
assertEquals(XmlUtils.unwrap(p.getContent().get(1)).getClass(), CTMarkupRange.class);
assertTrue(p.getContent().size() == 3);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testNamedAnchorEmpty.
@Test
public void testNamedAnchorEmpty() throws Docx4JException {
String name = "anchor1";
String href = null;
String content = null;
List<Object> objects = fromXHTML(a(href, name, content));
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
// Test just bookmark start + end + span
assertTrue(p.getContent().size() == 3);
assertEquals(XmlUtils.unwrap(p.getContent().get(1)).getClass(), CTMarkupRange.class);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testNamedAnchorContent.
@Test
public void testNamedAnchorContent() throws Docx4JException {
String name = "anchor2";
String href = null;
String content = "Google";
List<Object> objects = fromXHTML(a(href, name, content));
P p = (P) objects.get(0);
// Test bookmark
testBookmarkName(XmlUtils.unwrap(p.getContent().get(0)), name);
// Test content - not hyperlinked
R r = (R) p.getContent().get(1);
testContent(r, R.class, content);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class NumberingTest method testUnorderedWithStylePresent.
// ===============================================================================
// FormattingOption tests
// - basic tests of @class
@Test
public void testUnorderedWithStylePresent() throws Docx4JException {
this.addNumberingPart(wordMLPackage.getMainDocumentPart());
this.addStylesPart(wordMLPackage.getMainDocumentPart());
String xhtml = "<div>" + "<ul class=\"MyListStyle\">" + "<li>List item one</li>" + "</ul>" + "</div>";
List<Object> results = convert(xhtml, FormattingOption.CLASS_TO_STYLE_ONLY);
P p = (P) results.get(0);
assertTrue(p.getPPr().getNumPr().getNumId().getVal().intValue() == PREDEFINED_OL_NUMID);
// CLASS_TO_STYLE_ONLY, so Indent should not be present in pPr
assertTrue(p.getPPr().getInd() == null);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class NumberingTest method testNestedNoClassButExplicitIndent.
@Test
public void testNestedNoClassButExplicitIndent() throws Docx4JException {
this.addNumberingPart(wordMLPackage.getMainDocumentPart());
this.addStylesPart(wordMLPackage.getMainDocumentPart());
String xhtml = "<div>" + "<ul>" + "<li>List item two with subitems:" + "<ul style=\"margin-left: 2in;\">" + "<li>Subitem 1</li>" + "</ul>" + "</li>" + "</ul>" + "</div>";
List<Object> results = convert(xhtml, FormattingOption.IGNORE_CLASS);
wordMLPackage.getMainDocumentPart().getContent().addAll(results);
System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
// System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getJaxbElement(), true, true));
P p = (P) results.get(1);
// Should be numbered, but not using our predefined list
assertTrue(p.getPPr().getNumPr() != null);
assertTrue(p.getPPr().getNumPr().getNumId() != null);
assertTrue(p.getPPr().getNumPr().getNumId().getVal().intValue() != PREDEFINED_OL_NUMID);
assertTrue(p.getPPr().getNumPr().getIlvl() != null);
// nested
assertTrue(p.getPPr().getNumPr().getIlvl().getVal().intValue() == 1);
// default of 2*600 + 2880 + hanging hack (360)
// TODO this shouldn't be necessary
wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().initialiseMaps();
Ind ind = wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getInd(p.getPPr().getNumPr());
// System.out.println(XmlUtils.marshaltoString(ind));
assertTrue(ind.getLeft().intValue() == 4440);
}
Aggregations