private void initChildren(org.docx4j.wml.P para) { this.children = null; if (para == null) { return; } List<Object> pKids = para.getParagraphContent(); if (!pKids.isEmpty()) { this.children = new ArrayList<ElementML>(pKids.size()); ElementML ml = null; for (Object o : pKids) { Object value = JAXBIntrospector.getValue(o); if (value instanceof org.docx4j.wml.RunIns) { ml = new RunInsML(value, this.isDummy); ml.setParent(ParagraphML.this); this.children.add(ml); } else if (value instanceof org.docx4j.wml.RunDel) { ml = new RunDelML(value, this.isDummy); ml.setParent(ParagraphML.this); this.children.add(ml); } else if (value instanceof org.docx4j.wml.P.Hyperlink) { ml = new HyperlinkML(value, this.isDummy); ml.setParent(ParagraphML.this); this.children.add(ml); } else if (value instanceof org.docx4j.wml.CTSmartTagRun) { InlineTransparentML transparent = new InlineTransparentML(value, this.isDummy); // Current implementation is using InlineTransparentML // as surrogate container. if (transparent.getChildrenCount() > 0) { List<ElementML> list = new ArrayList<ElementML>(transparent.getChildren()); for (ElementML elem : list) { elem.delete(); elem.setParent(ParagraphML.this); this.children.add(elem); } } } else if (value instanceof org.docx4j.wml.CTMarkupRange) { // suppress <w:bookmarkStart> and <w:bookmarkEnd> JAXBIntrospector inspector = Context.jc.createJAXBIntrospector(); QName name = inspector.getElementName(o); if (name != null && (name.getLocalPart() == "bookmarkStart" || name.getLocalPart() == "bookmarkEnd")) { // suppress } else { ml = new RunML(o, this.isDummy); ml.setParent(ParagraphML.this); this.children.add(ml); } } else { ml = new RunML(o, this.isDummy); ml.setParent(ParagraphML.this); this.children.add(ml); } } } } // initChildren()
public void addChild(int idx, ElementML child, boolean adopt) { if (!(child instanceof RunML) && !(child instanceof RunInsML) && !(child instanceof RunDelML) && !(child instanceof HyperlinkML)) { throw new IllegalArgumentException("Cannot become a child."); } if (child.getParent() != null) { throw new IllegalArgumentException("Not an orphan."); } super.addChild(idx, child, adopt); }
public void setParent(ElementML parent) { if (parent != null && !(parent instanceof BodyML) && !(parent instanceof SdtBlockML) && !(parent instanceof TableCellML)) { throw new IllegalArgumentException("Parent type = " + parent.getClass().getSimpleName()); } this.parent = parent; }