protected static void insertXChild(XmlObject root, XmlObject child) { XmlCursor rootCursor = root.newCursor(); rootCursor.toEndToken(); XmlCursor childCursor = child.newCursor(); childCursor.toNextToken(); childCursor.moveXml(rootCursor); childCursor.dispose(); rootCursor.dispose(); }
/** * Verifies that cursor is on the right position. * * @param cursor * @return true if the cursor is within a CTFtnEdn element. */ private boolean isCursorInFtn(XmlCursor cursor) { XmlCursor verify = cursor.newCursor(); verify.toParent(); if (verify.getObject() == this.ctFtnEdn) { return true; } return false; }
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); }
@Override protected void write(OutputStream out) throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement( new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet")); chartsheet.save(out, xmlOptions); }
@Beta public void readFrom(InputStream is) throws IOException { try { XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); //Removing root element options.setLoadReplaceDocumentElement(null); pivotTableDefinition = CTPivotTableDefinition.Factory.parse(is, options); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); } }
/** * Return direct child objects of this shape * * @param childClass the class to cast the properties to * @param namespace the namespace - usually it is {@code "http://schemas.openxmlformats.org/presentationml/2006/main"} * @param nodename the node name, without prefix * @return the properties object or null if it can't be found */ @SuppressWarnings({"unchecked", "WeakerAccess", "unused", "SameParameterValue"}) protected <T extends XmlObject> T getChild(Class<T> childClass, String namespace, String nodename) { XmlCursor cur = getXmlObject().newCursor(); T child = null; if (cur.toChild(namespace, nodename)) { child = (T)cur.getObject(); } if (cur.toChild(XSLFRelation.NS_DRAWINGML, nodename)) { child = (T)cur.getObject(); } cur.dispose(); return child; }
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; }
/** * 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(); } }
@Override protected final void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); String docName = getRootElementName(); if(docName != null) { xmlOptions.setSaveSyntheticDocumentElement( new QName("http://schemas.openxmlformats.org/presentationml/2006/main", docName)); } PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); getXmlObject().save(out, xmlOptions); out.close(); }
/** * 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(); }
/** * save and commit numbering */ @Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "numbering")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctNumbering.save(out, xmlOptions); out.close(); }
@Beta protected void readFrom(InputStream is) throws IOException { try { XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); //Removing root element options.setLoadReplaceDocumentElement(null); ctPivotCache = CTPivotCache.Factory.parse(is, options); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); } }
/** * commit and saves the document */ @Override protected void commit() throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctDocument.save(out, xmlOptions); out.close(); }
@Beta public void readFrom(InputStream is) throws IOException { try { XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); //Removing root element options.setLoadReplaceDocumentElement(null); ctPivotCacheDefinition = CTPivotCacheDefinition.Factory.parse(is, options); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage(), e); } }
@Override protected void commit() throws IOException { saveNamedRanges(); saveCalculationChain(); XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorkbook.type.getName().getNamespaceURI(), "workbook")); PackagePart part = getPackagePart(); try (OutputStream out = part.getOutputStream()) { workbook.save(out, xmlOptions); } }
@Beta protected void readFrom(InputStream is) throws IOException { try { XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); //Removing root element options.setLoadReplaceDocumentElement(null); ctPivotCacheRecords = CTPivotCacheRecords.Factory.parse(is, options); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); } }