@Deprecated public List<Object> getRunContent() { return getContent(); }
private String getInstrText(R run) { List<Object> rContent = run.getContent(); Object item = null; Text text = null; for (int i=0; i<rContent.size(); i++) { item = rContent.get(i); if (item instanceof JAXBElement && ((JAXBElement)item).getName().equals(_RInstrText_QNAME)) { text = (Text)((JAXBElement)item).getValue(); break; } } return (text != null ? text.getValue() : null); }
private STFldCharType getFldCharType(R r) { STFldCharType ret = null; List<Object> rContent = r.getContent(); Object item = null; if ((rContent != null) && (!rContent.isEmpty())) { for (int i=0; i<rContent.size(); i++) { item = XmlUtils.unwrap(rContent.get(i)); if (item instanceof FldChar) { ret = ((FldChar)item).getFldCharType(); break; } } } return ret; } }
private static boolean checkPageBreak(List<Object> content) { int foundIdx = -1; Object ce = null; if ((content != null) && (!content.isEmpty())) { for (int i=0; (foundIdx == -1) && (i<content.size()); i++) { ce = content.get(i); if (ce instanceof R) { if (checkPageBreak(((R)ce).getContent())) { if ((((R)ce).getContent() == null) || (((R)ce).getContent().isEmpty())) { foundIdx = i; } else { return true; } } } else if (ce instanceof Br) { if (STBrType.PAGE.equals(((Br)ce).getType())) { foundIdx = i; } } } if (foundIdx > -1) { content.remove(foundIdx); } } return foundIdx > -1; }
public void setResult(String val) { resultsSlot.getContent().clear(); StringTokenizer st = new StringTokenizer(val, "\n\r\f"); // tokenize on the newline character, the carriage-return character, and the form-feed character // our docfrag may contain several runs boolean firsttoken = true; while (st.hasMoreTokens()) { String line = (String) st.nextToken(); if (firsttoken) { firsttoken = false; } else { resultsSlot.getContent().add(Context.getWmlObjectFactory().createBr()); } org.docx4j.wml.Text text = Context.getWmlObjectFactory().createText(); resultsSlot.getContent().add(text); if (line.startsWith(" ") || line.endsWith(" ") ) { // TODO: tab character? text.setSpace("preserve"); } text.setValue(line); } }
/** Add a tab, but in a new run (since the tab isn't to be underlined), * unless w:lvl has <w:suff w:val="space"/> or <w:suff w:val="nothing"/> */ private R tabAfterPNumber() { R r = wmlObjectFactory.createR(); R.Tab rtab = wmlObjectFactory.createRTab(); JAXBElement<R.Tab> rtabWrapped = wmlObjectFactory.createRTab(rtab); r.getContent().add(rtabWrapped); return r; }
List runContent = run.getContent(); for (Object o2 : runContent ) { if ( o2 instanceof javax.xml.bind.JAXBElement) {
/** * Parse through all content inside the paragraph to concatenate all values inside a text * * @param paragraph The paragraph which contains (or not) data * @return All text inside the paragraph */ protected static String getTextInsideContent(ContentAccessor paragraph) { StringBuilder result = new StringBuilder(); for (Object content : paragraph.getContent()) { if (content instanceof org.docx4j.wml.R) { org.docx4j.wml.R run = (org.docx4j.wml.R) content; List<Object> runContent = run.getContent(); for (Object o2 : runContent) { if (o2 instanceof javax.xml.bind.JAXBElement) { if (((JAXBElement<?>) o2).getDeclaredType().getName().equals("org.docx4j.wml.Text")) { org.docx4j.wml.Text t = (org.docx4j.wml.Text) ((JAXBElement) o2).getValue(); result.append(t.getValue()); } } else if(o2 instanceof org.docx4j.wml.Text){ org.docx4j.wml.Text t = (org.docx4j.wml.Text) o2; result.append(t.getValue()); } } } } return result.toString(); }
private void addRun(String val, DocumentFragment docfrag) { R r = new R(); Text t = new Text(); t.setValue(val); r.getContent().add(t); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(r); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
private void addTextRun(R r, String val, List<Object> replacementContent) { R rnew = new R(); rnew.setRPr( r.getRPr() ); // point at old rPr, if any Text text = Context.getWmlObjectFactory().createText(); text.setValue(val); if (val.startsWith(" ") || val.endsWith(" ") ) { text.setSpace("preserve"); } rnew.getContent().add(text); replacementContent.add(rnew); }
public P getLastParagraph() { // Create object for p P p = wmlObjectFactory.createP(); // Create object for r R r2 = wmlObjectFactory.createR(); p.getContent().add(r2); // Create object for fldChar (wrapped in JAXBElement) FldChar fldchar = wmlObjectFactory.createFldChar(); JAXBElement<FldChar> fldcharWrapped = wmlObjectFactory.createRFldChar(fldchar); r2.getContent().add(fldcharWrapped); fldchar.setFldCharType(STFldCharType.END); return p; } }
r2.getContent().add(fldcharWrapped); fldchar.setFldCharType(STFldCharType.BEGIN); r3.getContent().add(textWrapped2); text2.setValue(tocInstruction); text2.setSpace(PRESERVE); r4.getContent().add(fldcharWrapped2); fldchar2.setFldCharType(STFldCharType.SEPARATE);
/** * Create a paragraph containing the string simpleText, * without adding it to the document. If passed null, the result * is an empty P. * * @param simpleText * @return */ public org.docx4j.wml.P createParagraphOfText(String simpleText) { org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory(); org.docx4j.wml.P para = factory.createP(); if (simpleText!=null) { org.docx4j.wml.Text t = factory.createText(); t.setValue(simpleText); org.docx4j.wml.R run = factory.createR(); run.getContent().add(t); // ContentAccessor para.getContent().add(run); // ContentAccessor } return para; }
currentR.getContent().addAll( ((R)o).getContent() ); for ( Object rc : ((R)o).getContent() ) { ((R)o).getContent().clear(); ((R)o).getContent().addAll(newRunContents);
org.docx4j.wml.Text text = factory.createText(); text.setValue(message); run.getContent().add(text);
r = Context.getWmlObjectFactory().createR(); } else { r.getContent().clear(); t.setValue(val); r.getContent().add(t);
for (Object o2 : ((R)o).getContent() ) { Object o3 = XmlUtils.unwrap(o2); rnew.getContent().add(o2); replacementContent.add(rnew);
private static P generateTocHeading(String headingStyleId, String tocHeading) { // Create object for p P p = wmlObjectFactory.createP(); // Create object for pPr PPr ppr = wmlObjectFactory.createPPr(); p.setPPr(ppr); // Create object for pStyle PPrBase.PStyle pprbasepstyle = wmlObjectFactory.createPPrBasePStyle(); ppr.setPStyle(pprbasepstyle); pprbasepstyle.setVal(headingStyleId); // Create object for r R r = wmlObjectFactory.createR(); p.getContent().add(r); // Create object for t (wrapped in JAXBElement) Text text = wmlObjectFactory.createText(); JAXBElement<Text> textWrapped = wmlObjectFactory.createRT(text); r.getContent().add(textWrapped); text.setValue(tocHeading); return p; }
rnew.getContent().add(text);
r.getContent().add(textWrapped6); t.setSpace("preserve");