protected Node attachContents(DocumentFragment docfrag, Node xhtmlDiv, Node resultSoFar) { XmlUtils.treeCopy(resultSoFar, xhtmlDiv); return docfrag; }
public static void treeCopy( NodeList sourceNodes, Node destParent ) { for (int i=0; i<sourceNodes.getLength(); i++) { treeCopy((Node)sourceNodes.item(i), destParent); } }
static class LoggingErrorListener implements ErrorListener { // See http://www.cafeconleche.org/slides/sd2003west/xmlandjava/346.html boolean strict; public LoggingErrorListener(boolean strict) { } public void warning(TransformerException exception) { log.warn(exception.getMessage(), exception); // Don't throw an exception and stop the processor // just for a warning; but do log the problem } public void error(TransformerException exception) throws TransformerException { log.error(exception.getMessage(), exception); // XSLT is not as draconian as XML. There are numerous errors // which the processor may but does not have to recover from; // e.g. multiple templates that match a node with the same // priority. If I do not want to allow that, I'd throw this // exception here. if (strict) { throw exception; }
private static void createPlaceholderFragment() throws Exception { // create it - one time operation InputStream is; try { is = ResourceUtils.getResourceViaProperty("docx4j.model.datastorage.placeholder" , placeholderResource); } catch (IOException e) { log.info("No resource on classpath for property docx4j.model.datastorage.placeholder; falling back to using org/docx4j/model/datastorage/placeholder.xml"); is = ResourceUtils.getResource(placeholderResourceFallback); } Document tmpDoc = XmlUtils.getNewDocumentBuilder().parse(is); placeholderFragment = tmpDoc.createDocumentFragment(); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), placeholderFragment); }
break; } else { XmlUtils.treeCopy( currentEl, xhtmlBlock ); XmlUtils.treeCopy( currentSpan.getChildNodes(), newSpan ); xhtmlBlock.appendChild(newSpan); XmlUtils.treeCopy( thisSpan, xhtmlBlock ); XmlUtils.treeCopy( thisSpan.getChildNodes(), newSpan ); XmlUtils.treeCopy( thisSpan.getChildNodes(), newSpan ); xhtmlBlock.appendChild(newSpan); currentClass = thisClass;
private void addBookmarkEnd(int id, DocumentFragment docfrag) { CTMarkupRange markuprange = Context.getWmlObjectFactory().createCTMarkupRange(); markuprange.setId( BigInteger.valueOf(id ) ); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(markuprange); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
public static Node toNode(int outputType, AbstractWmlConversionContext context, AbstractHyperlinkWriterModel model, Node content, Document doc) throws TransformerException { Node ret = content; try { context.handleHyperlink(model); // extension point: you can pass your own handler in settings switch (outputType) { case HTML_OUTPUT: ret = toHtmlNode(context, model, content, doc); break; case FO_OUTPUT: ret = toFoNode(context, model, content, doc); break; default: throw new IllegalArgumentException("Invalid output type: " + outputType); } XmlUtils.treeCopy(content.getChildNodes(), ret); } catch (Docx4JException e) { //If handleHyperlink throws an exception should the old model //be used or should the hyperlink be surpressed? //current solution: no hyperlink log.error("Excetion handling the hyperlinkModel: " + model, e); } return ret; }
protected void addHyperlinkToDocFrag(JaxbXmlPart sourcePart, DocumentFragment docfrag, String url) throws Docx4JException { if (url.startsWith("http") || url.startsWith("mailto")) { super.addHyperlinkToDocFrag(sourcePart, docfrag, url); } else { // Handle eg #/components/schemas/Pets String bookmarkName = refToBookmarkName(url); try { Document tmpDoc = XmlUtils.marshaltoW3CDomDocument( BindingHandler.getHyperlinkResolver().generateHyperlink(bookmarkName, url)); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); } catch (JAXBException e) { throw new Docx4JException(e.getMessage(), e); } } }
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 addBookmarkStart(String bookmarkName, int id, DocumentFragment docfrag) { CTBookmark bookmark = Context.getWmlObjectFactory().createCTBookmark(); JAXBElement<org.docx4j.wml.CTBookmark> bookmarkWrapped = Context.getWmlObjectFactory().createPBookmarkStart(bookmark); bookmark.setName( bookmarkName ); bookmark.setId( BigInteger.valueOf( id) ); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(bookmark); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
protected void addBrRunToDocFrag(DocumentFragment docfrag, RPr rPr) throws Docx4JException { // Not sure whether there is ever anything of interest in the rPr, // but add it anyway org.docx4j.wml.R run = Context.getWmlObjectFactory().createR(); if (rPr!=null) { run.setRPr(rPr); } run.getRunContent().add(Context.getWmlObjectFactory().createBr()); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(run); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
private void addRunToDocFrag(JaxbXmlPart sourcePart, DocumentFragment docfrag, String string, RPr rPr) { org.docx4j.wml.R run = Context.getWmlObjectFactory().createR(); if (rPr!=null) { run.setRPr(rPr); } org.docx4j.wml.Text text = Context.getWmlObjectFactory().createText(); run.getRunContent().add(text); if (string.startsWith(" ") || string.endsWith(" ") ) { // TODO: tab character? log.debug("setting xml:space=preserve for '" + string + "'"); text.setSpace("preserve"); } text.setValue(string); Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(run); // avoid WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. // but NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation. // at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode // docfrag.appendChild(fragdoc.importNode(document, true)); // so: XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); }
XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); return docfrag;
span.setAttribute("style", existingStyle ); setSpanAttr(context, defaultCharacterStyleId, styleTree, rPr, span); XmlUtils.treeCopy( n.getChildNodes().item(0).getChildNodes(), span );
protected void addHyperlinkToDocFrag(JaxbXmlPart sourcePart, DocumentFragment docfrag, String url) throws Docx4JException { // We need to add a relationship to word/_rels/document.xml.rels // but since its external, we don't use the // usual wordMLPackage.getMainDocumentPart().addTargetPart // mechanism org.docx4j.relationships.ObjectFactory factory = new org.docx4j.relationships.ObjectFactory(); org.docx4j.relationships.Relationship rel = factory.createRelationship(); rel.setType( Namespaces.HYPERLINK ); rel.setTarget(url); rel.setTargetMode("External"); sourcePart.getRelationshipsPart().addRelationship(rel); // addRelationship sets the rel's @Id try { Document tmpDoc = XmlUtils.marshaltoW3CDomDocument( BindingHandler.getHyperlinkResolver().generateHyperlink(rel.getId(), url)); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), docfrag); } catch (JAXBException e) { throw new Docx4JException(e.getMessage(), e); } }
XmlUtils.treeCopy(content, literalNode); literalNode = literalNode.getFirstChild(); setTextcontent(literalNode, textcontentitem);
XmlUtils.treeCopy( ((AbstractTableWriterModelCell)cell).getContent().getChildNodes(), cellNode);
XmlUtils.treeCopy(d2, n); return document;