use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testHref.
@Test
public void testHref() throws Docx4JException {
String name = null;
String href = "http://www.google.com";
String content = "Google";
List<Object> objects = fromXHTML(a(href, name, content));
P p = (P) objects.get(0);
P.Hyperlink h = (P.Hyperlink) p.getContent().get(0);
testLink(h.getId(), href);
// Test content
testContent(h, P.Hyperlink.class, content);
}
use of org.docx4j.wml.P in project Java-Tutorial by gpcodervn.
the class NumberingTest method testNestedWithNoClassOnLevel.
/**
* For a nested list, we should get ilvl right; there should no pPr ind
*/
@Test
public void testNestedWithNoClassOnLevel() throws Docx4JException {
this.addNumberingPart(wordMLPackage.getMainDocumentPart());
this.addStylesPart(wordMLPackage.getMainDocumentPart());
String xhtml = "<div>" + "<ul class=\"MyListStyle\">" + "<li>List item two with subitems:" + // no class here
"<ul >" + "<li>Subitem 1</li>" + "</ul>" + "</li>" + "</ul>" + "</div>";
List<Object> results = convert(xhtml, FormattingOption.CLASS_PLUS_OTHER);
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, using our predefined list
assertTrue(p.getPPr().getNumPr() != null);
assertTrue(p.getPPr().getNumPr().getNumId() != null);
// since no @class on this level
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);
// Indent should 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 testUnorderedCssDefaultIndentUnset.
/**
* Don't add pPr Ind for default css
*/
@Test
public void testUnorderedCssDefaultIndentUnset() throws Docx4JException {
this.addNumberingPart(wordMLPackage.getMainDocumentPart());
this.addStylesPart(wordMLPackage.getMainDocumentPart());
String xhtml = "<div>" + "<ul>" + "<li>List item one</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(0);
// 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);
// 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 testUnorderedCssDefaultIndentFalsePositive.
/**
* Since we don't add pPr Ind for default css, an explicit setting which
* evaluates to same, will be ignored.
*/
@Test
public void testUnorderedCssDefaultIndentFalsePositive() throws Docx4JException {
this.addNumberingPart(wordMLPackage.getMainDocumentPart());
this.addStylesPart(wordMLPackage.getMainDocumentPart());
String xhtml = "<div>" + "<ul style=\"margin-left: 0in;\">" + "<li>List item one</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(0);
// 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);
// Indent should 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 testUnorderedWithStyleAbsent.
@Test
public void testUnorderedWithStyleAbsent() throws Docx4JException {
this.addNumberingPart(wordMLPackage.getMainDocumentPart());
this.addStylesPart(wordMLPackage.getMainDocumentPart());
String xhtml = "<div>" + "<ul class=\"My_MISSING_ListStyle\">" + "<li>List item one</li>" + "</ul>" + "</div>";
List<Object> results = convert(xhtml, FormattingOption.CLASS_PLUS_OTHER);
// 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(0);
// 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);
}
Aggregations