/** * Clears all paragraphs and tables from this header / footer */ public void clearHeaderFooter() { XmlCursor c = headerFooter.newCursor(); c.removeXmlContents(); c.dispose(); paragraphs.clear(); tables.clear(); bodyElements.clear(); }
@Override public boolean isLineStyle() { XmlCursor cur = props.newCursor(); String name = cur.getName().getLocalPart(); cur.dispose(); return "lnRef".equals(name); } }
/** * Removes a specific table from this header / footer * * @param table - {@link XWPFTable} object to remove */ public void removeTable(XWPFTable table) { if (tables.contains(table)) { CTTbl ctTbl = table.getCTTbl(); XmlCursor c = ctTbl.newCursor(); c.removeXml(); c.dispose(); tables.remove(table); bodyElements.remove(table); } }
/** * Removes a specific paragraph from this header / footer * * @param paragraph - {@link XWPFParagraph} object to remove */ public void removeParagraph(XWPFParagraph paragraph) { if (paragraphs.contains(paragraph)) { CTP ctP = paragraph.getCTP(); XmlCursor c = ctP.newCursor(); c.removeXml(); c.dispose(); paragraphs.remove(paragraph); bodyElements.remove(paragraph); } }
/** * Add the xml:spaces="preserve" attribute if the string has leading or trailing spaces * * @param xs the string to check */ protected static void preserveSpaces(STXstring xs) { String text = xs.getStringValue(); if (text != null && text.length() > 0) { char firstChar = text.charAt(0); char lastChar = text.charAt(text.length() - 1); if(Character.isWhitespace(firstChar) || Character.isWhitespace(lastChar)) { XmlCursor c = xs.newCursor(); c.toNextToken(); c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); c.dispose(); } } }
/** * Add the xml:spaces="preserve" attribute if the string has leading or trailing white spaces * * @param xs the string to check */ static void preserveSpaces(XmlString xs) { String text = xs.getStringValue(); if (text != null && (text.startsWith(" ") || text.endsWith(" "))) { XmlCursor c = xs.newCursor(); c.toNextToken(); c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); c.dispose(); } }
/** * @return list of shapes in this shape group */ public List<XSSFShape> getShapes(XSSFShapeGroup groupshape) { List<XSSFShape> lst = new ArrayList<>(); XmlCursor cur = groupshape.getCTGroupShape().newCursor(); try { addShapes(cur, lst); } finally { cur.dispose(); } return lst; }
/** * @return list of shapes in this drawing */ public List<XSSFShape> getShapes() { List<XSSFShape> lst = new ArrayList<>(); XmlCursor cur = drawing.newCursor(); try { if (cur.toFirstChild()) { addShapes(cur, lst); } } finally { cur.dispose(); } return lst; }
/** * verifies that cursor is on the right position */ private boolean isCursorInTableCell(XmlCursor cursor) { XmlCursor verify = cursor.newCursor(); verify.toParent(); boolean result = (verify.getObject() == this.ctTc); verify.dispose(); return result; }
/** * verifies that cursor is on the right position * * @param cursor */ private boolean isCursorInHdrF(XmlCursor cursor) { XmlCursor verify = cursor.newCursor(); verify.toParent(); boolean result = (verify.getObject() == this.headerFooter); verify.dispose(); return result; }
public void readHdrFtr() { bodyElements = new ArrayList<>(); paragraphs = new ArrayList<>(); tables = new ArrayList<>(); // parse the document with cursor and add // the XmlObject to its lists XmlCursor cursor = headerFooter.newCursor(); cursor.selectPath("./*"); while (cursor.toNextSelection()) { XmlObject o = cursor.getObject(); if (o instanceof CTP) { XWPFParagraph p = new XWPFParagraph((CTP) o, this); paragraphs.add(p); bodyElements.add(p); } if (o instanceof CTTbl) { XWPFTable t = new XWPFTable((CTTbl) o, this); tables.add(t); bodyElements.add(t); } } cursor.dispose(); }
private boolean hasOleLink(XmlObject shape) { QName uriName = new QName(null, "uri"); String xquery = "declare namespace a='" + XSSFRelation.NS_DRAWINGML + "' .//a:extLst/a:ext"; XmlCursor cur = shape.newCursor(); cur.selectPath(xquery); try { while (cur.toNextSelection()) { String uri = cur.getAttributeText(uriName); if ("{63B3BB69-23CF-44E3-9099-C40C66FF867C}".equals(uri)) { return true; } } } finally { cur.dispose(); } return false; }
public XWPFFooter(XWPFDocument doc, CTHdrFtr hdrFtr) throws IOException { super(doc, hdrFtr); XmlCursor cursor = headerFooter.newCursor(); cursor.selectPath("./*"); while (cursor.toNextSelection()) { XmlObject o = cursor.getObject(); if (o instanceof CTP) { XWPFParagraph p = new XWPFParagraph((CTP) o, this); paragraphs.add(p); bodyElements.add(p); } if (o instanceof CTTbl) { XWPFTable t = new XWPFTable((CTTbl) o, this); tables.add(t); bodyElements.add(t); } } cursor.dispose(); }
/** * verifies that cursor is on the right position * * @param cursor */ private boolean isCursorInBody(XmlCursor cursor) { XmlCursor verify = cursor.newCursor(); verify.toParent(); boolean result = (verify.getObject() == this.ctDocument.getBody()); verify.dispose(); return result; }
XSLFTextParagraph(CTTextParagraph p, XSLFTextShape shape){ _p = p; _runs = new ArrayList<>(); _shape = shape; XmlCursor c = _p.newCursor(); try { if (c.toFirstChild()) { do { XmlObject r = c.getObject(); if (r instanceof CTTextLineBreak) { _runs.add(new XSLFLineBreak((CTTextLineBreak)r, this)); } else if (r instanceof CTRegularTextRun || r instanceof CTTextField) { _runs.add(new XSLFTextRun(r, this)); } } while (c.toNextSibling()); } } finally { c.dispose(); } }
protected void write(OutputStream out) throws IOException { XmlObject rootObject = XmlObject.Factory.newInstance(); XmlCursor rootCursor = rootObject.newCursor(); rootCursor.toNextToken(); rootCursor.beginElement("xml"); for(int i=0; i < _items.size(); i++){ XmlCursor xc = _items.get(i).newCursor(); rootCursor.beginElement(_qnames.get(i)); while(xc.toNextToken() == XmlCursor.TokenType.ATTR) { Node anode = xc.getDomNode(); rootCursor.insertAttributeWithValue(anode.getLocalName(), anode.getNamespaceURI(), anode.getNodeValue()); } xc.toStartDoc(); xc.copyXmlContents(rootCursor); rootCursor.toNextToken(); xc.dispose(); } rootCursor.dispose(); rootObject.save(out, DEFAULT_XML_OPTIONS); }
public XWPFHeader(XWPFDocument doc, CTHdrFtr hdrFtr) { super(doc, hdrFtr); XmlCursor cursor = headerFooter.newCursor(); cursor.selectPath("./*"); while (cursor.toNextSelection()) { XmlObject o = cursor.getObject(); if (o instanceof CTP) { XWPFParagraph p = new XWPFParagraph((CTP) o, this); paragraphs.add(p); } if (o instanceof CTTbl) { XWPFTable t = new XWPFTable((CTTbl) o, this); tables.add(t); } } cursor.dispose(); }
@Override public XSSFPictureData getPictureData() { XmlCursor cur = getOleObject().newCursor(); try { if (cur.toChild(XSSFRelation.NS_SPREADSHEETML, "objectPr")) { String blipId = cur.getAttributeText(new QName(PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, "id")); return (XSSFPictureData)getSheet().getRelationById(blipId); } return null; } finally { cur.dispose(); } }
private XSSFAnchor getAnchorFromParent(XmlObject obj) { XSSFAnchor anchor = null; XmlObject parentXbean = null; XmlCursor cursor = obj.newCursor(); if (cursor.toParent()) { parentXbean = cursor.getObject(); } cursor.dispose(); if (parentXbean != null) { if (parentXbean instanceof CTTwoCellAnchor) { CTTwoCellAnchor ct = (CTTwoCellAnchor) parentXbean; anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo()); } else if (parentXbean instanceof CTOneCellAnchor) { CTOneCellAnchor ct = (CTOneCellAnchor) parentXbean; anchor = new XSSFClientAnchor(getSheet(), ct.getFrom(), ct.getExt()); } else if (parentXbean instanceof CTAbsoluteAnchor) { CTAbsoluteAnchor ct = (CTAbsoluteAnchor) parentXbean; anchor = new XSSFClientAnchor(getSheet(), ct.getPos(), ct.getExt()); } } return anchor; }