Search in sources :

Example 56 with P

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

Example 57 with P

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

Example 58 with P

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

Example 59 with P

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

Example 60 with P

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