use of org.docx4j.wml.R in project mdw-designer by CenturyLinkCloud.
the class DocxBuilder method addNumberedList.
public void addNumberedList(List<String> list) throws Exception {
if (numberingNum == null) {
numberingNum = getNdp().addAbstractListNumberingDefinition((Numbering.AbstractNum) XmlUtils.unmarshalString(getFragment("numbering")));
numberingNumId = numberingNum.getNumId();
} else {
numberingNumId = BigInteger.valueOf(ndp.restart(numberingNumId.longValue(), 0, 1));
}
for (String item : list) {
ObjectFactory factory = Context.getWmlObjectFactory();
P listP = factory.createP();
Text t = factory.createText();
t.setValue(item);
R listRun = factory.createR();
listRun.getContent().add(t);
listP.getContent().add(listRun);
PPr listPpr = factory.createPPr();
listP.setPPr(listPpr);
// create and add <w:numPr>
NumPr numPr = factory.createPPrBaseNumPr();
listPpr.setNumPr(numPr);
// the <w:ilvl> element
Ilvl ilvlElement = factory.createPPrBaseNumPrIlvl();
numPr.setIlvl(ilvlElement);
ilvlElement.setVal(BigInteger.valueOf(0));
// The <w:numId> element
NumId numIdElement = factory.createPPrBaseNumPrNumId();
numPr.setNumId(numIdElement);
numIdElement.setVal(numberingNumId);
getMdp().addObject(listP);
}
}
use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class ContainerParseTest method testParagraphInTableCellLayout.
@Test
public void testParagraphInTableCellLayout() throws Exception {
String html = "<table><tbody><tr>" + "<td><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/>" + "<p><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></p>" + "<img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></td></tr></tbody></table>";
List<Object> tConvert = convert(html);
Assert.assertTrue(tConvert.size() == 1);
for (Object t : tConvert) {
Assert.assertTrue(t instanceof Tbl);
Tbl table = (Tbl) t;
List<Object> convert = ((Tc) ((Tr) table.getContent().get(0)).getContent().get(0)).getContent();
Assert.assertTrue(convert.size() == 3);
for (Object o : convert) {
Assert.assertTrue(o instanceof P);
P paragraph = (P) o;
List<Object> content = paragraph.getContent();
Assert.assertTrue(content.size() == 2);
for (Object child : content) {
Assert.assertTrue(child instanceof R);
R run = ((R) child);
List<Object> rContent = run.getContent();
Assert.assertTrue(rContent.size() == 1);
Assert.assertTrue(rContent.get(0) instanceof Drawing);
}
}
}
}
use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class ContainerParseTest method testParagraphInParagraphLayout.
@Test
public void testParagraphInParagraphLayout() throws Exception {
String html = "<p><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/>" + "<p><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></p>" + "<img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/><img src='" + PNG_IMAGE_DATA + "' height='16' width='19'/></p>";
List<Object> convert = convert(html);
Assert.assertTrue(convert.size() == 3);
for (Object o : convert) {
Assert.assertTrue(o instanceof P);
P paragraph = (P) o;
List<Object> content = paragraph.getContent();
Assert.assertTrue(content.size() == 2);
for (Object child : content) {
Assert.assertTrue(child instanceof R);
R run = ((R) child);
List<Object> rContent = run.getContent();
Assert.assertTrue(rContent.size() == 1);
Assert.assertTrue(rContent.get(0) instanceof Drawing);
}
}
}
use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testFollowingSpan.
private void testFollowingSpan(List<Object> contents, String followingSpanContent) {
R lastRun = null;
for (Object o : contents) {
o = XmlUtils.unwrap(o);
if (o instanceof R) {
lastRun = (R) o;
}
}
testContent(lastRun, R.class, followingSpanContent);
}
use of org.docx4j.wml.R in project Java-Tutorial by gpcodervn.
the class HyperlinkTest method testFollowingP.
private void testFollowingP(P p, String followingPContent) {
System.out.println(XmlUtils.marshaltoString(p, true, true));
R r = (R) p.getContent().get(0);
testContent(r, R.class, followingPContent);
}
Aggregations