Search in sources :

Example 6 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 7 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 8 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 9 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Example 10 with P

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);
}
Also used : P(org.docx4j.wml.P) Test(org.junit.Test)

Aggregations

P (org.docx4j.wml.P)101 R (org.docx4j.wml.R)58 Text (org.docx4j.wml.Text)32 Test (org.junit.Test)23 PPr (org.docx4j.wml.PPr)22 RPr (org.docx4j.wml.RPr)21 ObjectFactory (org.docx4j.wml.ObjectFactory)18 Jc (org.docx4j.wml.Jc)16 BigInteger (java.math.BigInteger)14 CTVerticalJc (org.docx4j.wml.CTVerticalJc)14 Drawing (org.docx4j.wml.Drawing)14 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)13 STVerticalJc (org.docx4j.wml.STVerticalJc)11 Tc (org.docx4j.wml.Tc)11 File (java.io.File)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tbl (org.docx4j.wml.Tbl)10 Tr (org.docx4j.wml.Tr)10 Br (org.docx4j.wml.Br)9