private org.docx4j.vml.CTTextbox getTextBox(org.docx4j.wml.Pict pict) { org.docx4j.vml.CTShape shape = null; for (Object o2 : pict.getAnyAndAny()) { o2 = XmlUtils.unwrap(o2); // System.out.println(o.getClass().getName()); if (o2 instanceof org.docx4j.vml.CTShape) { shape = (org.docx4j.vml.CTShape) o2; break; } } if (shape == null) { getLog().warn("no shape in pict "); return null; } else { org.docx4j.vml.CTTextbox textBox = null; org.docx4j.vml.wordprocessingDrawing.CTWrap w10Wrap = null; for (Object o2 : shape.getPathOrFormulasOrHandles()) { o2 = XmlUtils.unwrap(o2); if (o2 instanceof org.docx4j.vml.CTTextbox) { textBox = (org.docx4j.vml.CTTextbox) o2; } if (o2 instanceof org.docx4j.vml.wordprocessingDrawing.CTWrap) { w10Wrap = (org.docx4j.vml.wordprocessingDrawing.CTWrap) o2; } } return textBox; } }
private static void svg( PresentationMLPackage presentationMLPackage, ResolvedLayout layout, javax.xml.transform.Result result, SvgSettings settings) throws Exception { SvgConversionContext context = null; org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument( layout.getShapeTree(), Context.jcPML, "http://schemas.openxmlformats.org/presentationml/2006/main", "spTree", GroupShape.class); if (settings == null) { settings = new SvgSettings(); } if ((settings.getImageDirPath() == null) && (imageDirPath != null)) { settings.setImageDirPath(imageDirPath); } context = new SvgConversionContext(settings, presentationMLPackage, layout); org.docx4j.XmlUtils.transform(doc, xslt, context.getXsltParameters(), result); }
/** Example of how to find an object in document.xml via traversal (as opposed to XPath) */ public static void main(String[] args) throws Exception { String inputfilepath = System.getProperty("user.dir") + "/checkbox.docx"; WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); Finder finder = new Finder(FldChar.class); // <----- change this to suit new TraversalUtil(documentPart.getContent(), finder); System.out.println("got " + finder.results.size() + " of type " + finder.typeToFind.getName()); for (Object o : finder.results) { Object o2 = XmlUtils.unwrap(o); // this is ok, provided the results of the Callback // won't be marshalled if (o2 instanceof org.docx4j.wml.Text) { org.docx4j.wml.Text txt = (org.docx4j.wml.Text) o2; System.out.println(txt.getValue()); } else { System.out.println(XmlUtils.marshaltoString(o, true, true)); } } }
public void updateState(NodeIterator fldCharNodeIt) { org.docx4j.wml.FldChar field = null; Node node = fldCharNodeIt.nextNode(); try { field = (org.docx4j.wml.FldChar) XmlUtils.unmarshal(node, Context.jc, org.docx4j.wml.FldChar.class); } catch (JAXBException e1) { e1.printStackTrace(); } STFldCharType fieldCharType = field.getFldCharType(); if (fieldCharType == null) { log.debug("Ignoring unrecognised: " + XmlUtils.w3CDomNodeToString(node)); } else { if (fieldCharType == STFldCharType.BEGIN) { inField = true; } else if (fieldCharType == STFldCharType.END) { inField = false; } // else ignore STFldCharType.SEPARATE } }
/** * Use an XSLT to alter the contents of this package. The output of the transformation must be * valid pck:package/pck:part format, as emitted by Word 2007. * * @param is * @param transformParameters * @throws Exception */ public void transform(Templates xslt, Map<String, Object> transformParameters) throws Exception { // Prepare in the input document FlatOpcXmlCreator worker = new FlatOpcXmlCreator(this); org.docx4j.xmlPackage.Package pkg = worker.get(); JAXBContext jc = Context.jcXmlPackage; Marshaller marshaller = jc.createMarshaller(); org.w3c.dom.Document doc = org.docx4j.XmlUtils.neww3cDomDocument(); marshaller.marshal(pkg, doc); // javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(jc ); // Use constructor which takes Unmarshaller, rather than JAXBContext, // so we can set JaxbValidationEventHandler Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(u); // Perform the transformation org.docx4j.XmlUtils.transform(doc, xslt, transformParameters, result); // javax.xml.bind.JAXBElement je = (javax.xml.bind.JAXBElement)result.getResult(); // org.docx4j.xmlPackage.Package wmlPackageEl = (org.docx4j.xmlPackage.Package)je.getValue(); org.docx4j.xmlPackage.Package wmlPackageEl = (org.docx4j.xmlPackage.Package) XmlUtils.unwrap(result.getResult()); org.docx4j.convert.in.FlatOpcXmlImporter xmlPackage = new org.docx4j.convert.in.FlatOpcXmlImporter(wmlPackageEl); ContentTypeManager ctm = new ContentTypeManager(); Part tmpDocPart = xmlPackage.getRawPart(ctm, "/word/document.xml", null); Part tmpStylesPart = xmlPackage.getRawPart(ctm, "/word/styles.xml", null); // This code assumes all the existing rels etc of // the existing main document part are still relevant. // if (wmlDocument==null) { // log.warn("Couldn't get main document part from package transform result!"); // } else { // this.getMainDocumentPart().setJaxbElement(wmlDocument); // } this.getMainDocumentPart() .setJaxbElement(((JaxbXmlPart<Document>) tmpDocPart).getJaxbElement()); // // if (wmlStyles==null) { // log.warn("Couldn't get style definitions part from package transform result!"); // } else { // this.getMainDocumentPart().getStyleDefinitionsPart().setJaxbElement(wmlStyles); // } this.getMainDocumentPart() .getStyleDefinitionsPart(true) .setJaxbElement(((JaxbXmlPart<Styles>) tmpStylesPart).getJaxbElement()); }
/** Connection (line) */ public static Document CxnSpToSVG(CxnSp cxnSp) { // Geometrical transforms CTTransform2D xfrm = cxnSp.getSpPr().getXfrm(); Box b = new Box( xfrm.getOff().getX(), xfrm.getOff().getY(), xfrm.getExt().getCx(), xfrm.getExt().getCy()); if (xfrm.getRot() != 0) { b.rotate(xfrm.getRot()); } if (xfrm.isFlipH()) { b.flipH(); } if (xfrm.isFlipV()) { b.flipV(); } // Convert from EMU to pixels b.toPixels(); // Wrap in a div positioning it on the page Document document = XmlUtils.getNewDocumentBuilder().newDocument(); Element xhtmlDiv = document.createElement("div"); // Firefox needs the following; Chrome doesn't xhtmlDiv.setAttribute( "style", "position: absolute; width:100%; height:100%; left:0px; top:0px;"); Node n = document.appendChild(xhtmlDiv); // Convert the object itself to SVG Svg svg = oFactory.createSvg(); Line line = oFactory.createLine(); svg.getSVGDescriptionClassOrSVGAnimationClassOrSVGStructureClass().add(line); line.setX1(b.getOffset().getXAsString()); line.setY1(b.getOffset().getYAsString()); Point otherEnd = b.getOtherCorner(); line.setX2(otherEnd.getXAsString()); line.setY2(otherEnd.getYAsString()); line.setStyle("stroke:rgb(99,99,99)"); // You can't see the line in Midori, unless you specify the color. // width eg stroke-width:2 is optional Document d2 = XmlUtils.marshaltoW3CDomDocument(svg, jcSVG); XmlUtils.treeCopy(d2, n); return document; }
@Override public void walkJAXBElements(Object parent) { // Breadth first List<Object> newChildren = new ArrayList<Object>(); Object parentUnwrapped = XmlUtils.unwrap(parent); List<Object> children = getChildren(parentUnwrapped); if (children == null) { log.debug("no children: " + parentUnwrapped.getClass().getName()); return; } else { for (Object o : children) { newChildren.addAll(this.apply(o)); } } // Replace list, so we'll traverse all the new sdts we've just // created TraversalUtil.replaceChildren(parentUnwrapped, newChildren); children = getChildren(parentUnwrapped); if (children == null) { log.debug("no children: " + parentUnwrapped.getClass().getName()); } else { for (Object o : children) { // *** this.apply(o); if (this.shouldTraverse(o)) { walkJAXBElements(o); } } } }
@Override public List<Object> apply(Object wrapped) throws RuntimeException { // apply processSdt to any sdt // which might be a conditional|repeat Object o = XmlUtils.unwrap(wrapped); if (o instanceof org.docx4j.wml.SdtBlock || o instanceof org.docx4j.wml.SdtRun || o instanceof org.docx4j.wml.CTSdtRow || o instanceof org.docx4j.wml.CTSdtCell) { if (getSdtPr(o).getDataBinding() == null) { // a real binding attribute trumps any tag return processBindingRoleIfAny(wordMLPackage, o); } } else { // log.warn("TODO: Handle " + o.getClass().getName() + // " (if that's an sdt)"); } // Otherwise just preserve the content List<Object> newContent = new ArrayList<Object>(); newContent.add(wrapped); // we want the JAXBElement (if any) return newContent; }
private void processDescendantCondition(Object sdt, String xpathBase, int index, Tag tag) { Condition c = null; HashMap<String, String> map = QueryString.parseQueryString(tag.getVal(), true); String conditionId = map.get(BINDING_ROLE_CONDITIONAL); if (conditionId != null) { c = ConditionsPart.getConditionById(conditions, conditionId); if (c == null) { log.error("Missing condition " + conditionId); throw new InputIntegrityException("Required condition '" + conditionId + "' is missing"); } // TODO: this code assumes the condition contains // a simple xpath log.debug("Using condition" + XmlUtils.marshaltoString(c, true, true)); Condition newCondition = c.repeat(xpathBase, index, conditions, xPaths); // set sdt to use it map.put(BINDING_ROLE_CONDITIONAL, newCondition.getId()); tag.setVal(QueryString.create(map)); } }
@Override public String getCssProperty() { // Note regarding numbering case; handling of tab after the number:- // We get this right in the PDF case, via setXslFOListBlock below. // We don't attempt to get the tab right in the HTML case, // since without some research, I don't know what markup would be required. String prop = "position: relative; "; BigInteger left = ((Ind) this.getObject()).getLeft(); if (left != null) { prop = prop + composeCss(CSS_NAME, UnitsOfMeasurement.twipToBest(left.intValue())); } // SPEC: The firstLine and hanging attributes are mutually exclusive, if both are specified, // then // the firstLine value is ignored. BigInteger firstline = ((Ind) this.getObject()).getFirstLine(); BigInteger hanging = ((Ind) this.getObject()).getHanging(); if (hanging != null) { prop = prop + composeCss("text-indent", "-" + UnitsOfMeasurement.twipToBest(hanging.intValue())); } else if (firstline != null) { prop = prop + composeCss("text-indent", UnitsOfMeasurement.twipToBest(firstline.intValue())); } if (left == null && firstline == null && hanging == null) { log.debug("What to do with " + XmlUtils.marshaltoString(this.getObject(), true, true)); prop = CSS_NULL; } return prop; }
/** * Create a Hyperlink object, which is suitable for adding to a w:p * * @param bookmarkName * @param linkText * @return */ public static Hyperlink hyperlinkToBookmark(String bookmarkName, String linkText) { try { String hpl = "<w:hyperlink w:anchor=\"" + bookmarkName + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " + "w:history=\"1\" >" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"Hyperlink\" />" + // TODO: enable this style in the document! "</w:rPr>" + "<w:t>" + linkText + "</w:t>" + "</w:r>" + "</w:hyperlink>"; return (Hyperlink) XmlUtils.unmarshalString(hpl); } catch (Exception e) { // Shouldn't happen e.printStackTrace(); return null; } }
public Style getEffectiveTableStyle(TblPr tblPr) { // OK to pass this a null tblPr. Stack<Style> tableStyleStack = new Stack<Style>(); if (tblPr != null && tblPr.getTblStyle() != null) { String styleId = tblPr.getTblStyle().getVal(); log.debug("Table style: " + styleId); fillTableStyleStack(styleId, tableStyleStack); } else { log.debug("No table style specified"); } Style result; if (tableStyleStack.size() > 0) { result = XmlUtils.deepCopy(tableStyleStack.pop()); } else { result = Context.getWmlObjectFactory().createStyle(); if (tblPr == null) { // Return empty style object return result; } } while (!tableStyleStack.empty()) { StyleUtil.apply(tableStyleStack.pop(), result); } // Finally apply the tblPr we were passed result.setTblPr(StyleUtil.apply(tblPr, result.getTblPr())); return result; }
private static SdtBlock createSdt(String tagVal, RPr rPr) { // .. so create content control! SdtBlock sdtBlock = Context.getWmlObjectFactory().createSdtBlock(); SdtPr sdtPr = Context.getWmlObjectFactory().createSdtPr(); sdtBlock.setSdtPr(sdtPr); SdtContentBlock sdtContent = Context.getWmlObjectFactory().createSdtContentBlock(); sdtBlock.setSdtContent(sdtContent); // For borders/shading, we'll use the values in this first paragraph. // We'll use a tag, so the XSLT can detect that its supposed to do something special. Tag tag = Context.getWmlObjectFactory().createTag(); tag.setVal(tagVal); sdtPr.setTag(tag); if (rPr != null) { sdtPr.getRPrOrAliasOrLock().add((RPr) XmlUtils.deepCopy(rPr)); /* * ECMA-376 says "specifies the set of run properties which shall be applied to * the text entered into the parent structured document tag in replacement of * placeholder text. When placeholder text is present in a structured document * tag, its formatting is often different than the desired underlying formatting, * and this element specifies the formatting which shall be used for non-placeholder * text contents when they are initially added to the control. " * * Note that docx2fo.xslt is co-opting this to do something else. */ } return sdtBlock; }
/** Generate or load the XML you want in your CustomXML part. */ public static org.w3c.dom.Document createCustomXmlDocument() { org.w3c.dom.Document domDoc = XmlUtils.neww3cDomDocument(); domDoc.appendChild(domDoc.createElement("someContent")); return domDoc; }
public Object clone() { Object obj = null; if (this.docxObject != null) { obj = XmlUtils.deepCopy(this.docxObject); } return new ParagraphML(obj, this.isDummy); }
public static DocumentFragment createBlockForR( SvgConversionContext context, NodeIterator rPrNodeIt, NodeIterator childResults) { DocumentFragment docfrag = null; Document d = null; Element span = null; try { // Create a DOM builder and parse the fragment d = XmlUtils.getNewDocumentBuilder().newDocument(); span = d.createElement("span"); d.appendChild(span); CTTextCharacterProperties textCharProps = (CTTextCharacterProperties) nodeToObjectModel(rPrNodeIt.nextNode(), CTTextCharacterProperties.class); RPr rPr = TextStyles.getWmlRPr(textCharProps); // Does our rPr contain anything else? StringBuilder inlineStyle = new StringBuilder(); HtmlCssHelper.createCss(context.getPmlPackage(), rPr, inlineStyle); if (!inlineStyle.toString().equals("")) { span.setAttribute("style", inlineStyle.toString()); } Node n = childResults.nextNode(); XmlUtils.treeCopy(n, span); } catch (Exception e) { log.error(e.getMessage(), e); // If something went wrong with the formatting, // still try to display the text! Node n = childResults.nextNode(); XmlUtils.treeCopy(n, span); } // Machinery docfrag = d.createDocumentFragment(); docfrag.appendChild(d.getDocumentElement()); return docfrag; }
private static Document makeErr(String msg) { Document d = XmlUtils.getNewDocumentBuilder().newDocument(); Element span = d.createElement("span"); span.setAttribute("style", "color:red;"); d.appendChild(span); Text err = d.createTextNode(msg); span.appendChild(err); return d; }
/** * Build a table representation from a <var>tbl</var> instance. Remember to set wordMLPackage * before using this method! */ public void build(Node node, NodeList children) throws TransformerException { Tbl tbl = null; try { tbl = (Tbl) XmlUtils.unmarshal(node); } catch (JAXBException e) { throw new TransformerException("Node: " + node.getNodeName() + "=" + node.getNodeValue(), e); } build(tbl, children.item(0)); }
private org.opendope.xpaths.Xpaths.Xpath createNewXPathObject( String newPath, org.opendope.xpaths.Xpaths.Xpath xpathObj, int index) { org.opendope.xpaths.Xpaths.Xpath newXPathObj = XmlUtils.deepCopy(xpathObj); String newXPathId = newXPathObj.getId() + "_" + index; newXPathObj.setId(newXPathId); newXPathObj.getDataBinding().setXpath(newPath); xPaths.getXpath().add(newXPathObj); return newXPathObj; }
/** * Follow the resolution rules to return the paragraph properties which actually apply, given this * pPr element (on a w:p). * * <p>Note 1: the properties are not the definition of any style name returned. Note 2: run * properties are not resolved or returned by this method. * * <p>What is returned is a live object. If you want to change it, you should clone it first! * * @param expressPPr * @return */ public PPr getEffectivePPr(PPr expressPPr) { PPr effectivePPr = null; // First, the document defaults are applied // Done elsewhere // PPr effectivePPr = (PPr)XmlUtils.deepCopy(documentDefaultPPr); // Next, the table style properties are applied to each table in the document, // following the conditional formatting inclusions and exclusions specified // per table. // TODO - if the paragraph is in a table? // Next, numbered item and paragraph properties are applied to each paragraph // formatted with a *numbering *style**. // TODO - who uses numbering styles (as opposed to numbering // via a paragraph style or direct formatting)? // Next, paragraph and run properties are // applied to each paragraph as defined by the paragraph style. PPr resolvedPPr = null; String styleId; if (expressPPr == null || expressPPr.getPStyle() == null) { // styleId = "Normal"; styleId = defaultParagraphStyleId; } else { styleId = expressPPr.getPStyle().getVal(); } resolvedPPr = getEffectivePPr(styleId); // Next, run properties are applied to each run with a specific character style // applied. // Not for pPr // Finally, we apply direct formatting (paragraph or run properties not from // styles). if (hasDirectPPrFormatting(expressPPr)) { if (resolvedPPr == null) { log.warn("resolvedPPr was null. Look into this?"); effectivePPr = Context.getWmlObjectFactory().createPPr(); } else { effectivePPr = (PPr) XmlUtils.deepCopy(resolvedPPr); } applyPPr(expressPPr, effectivePPr); return effectivePPr; } else { return resolvedPPr; } }
/** * Create a <wp:inline> element suitable for this image, which can be linked or embedded in * w:p/w:r/w:drawing, specifying height and width. Note that you'd ordinarily use one of the * methods which don't require you to specify height (cy). * * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document None of these things seem to be exposed in Word * 2007's user interface, but Word won't open the document if any of the attributes these go * in (except @ desc) aren't present! * @param cx Image width in EMU * @param cy Image height in EMU * @param link true if this is to be linked not embedded * @throws Exception */ public Inline createImageInline( String filenameHint, String altText, int id1, int id2, long cx, long cy, boolean link) throws Exception { if (filenameHint == null) { filenameHint = ""; } if (altText == null) { altText = ""; } String type; if (link) { type = "r:link"; } else { type = "r:embed"; } String ml = // "<w:p ><w:r>" + // "<w:drawing>" + "<wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\"" + namespaces + ">" + "<wp:extent cx=\"${cx}\" cy=\"${cy}\"/>" + "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>" + // l=\"19050\" "<wp:docPr id=\"${id1}\" name=\"${filenameHint}\" descr=\"${altText}\"/><wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/></wp:cNvGraphicFramePr><a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + "<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + "<pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:nvPicPr><pic:cNvPr id=\"${id2}\" name=\"${filenameHint}\"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill>" + "<a:blip " + type + "=\"${rEmbedId}\"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>" + "<pic:spPr><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"${cx}\" cy=\"${cy}\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic>" + "</wp:inline>"; // + // "</w:drawing>" + // "</w:r></w:p>"; java.util.HashMap<String, String> mappings = new java.util.HashMap<String, String>(); mappings.put("cx", Long.toString(cx)); mappings.put("cy", Long.toString(cy)); mappings.put("filenameHint", filenameHint); mappings.put("altText", altText); mappings.put("rEmbedId", this.getRelLast().getId()); mappings.put("id1", Integer.toString(id1)); mappings.put("id2", Integer.toString(id2)); Object o = org.docx4j.XmlUtils.unmarshallFromTemplate(ml, mappings); Inline inline = (Inline) ((JAXBElement) o).getValue(); return inline; }
public static Object nodeToObjectModel(Node n, Class declaredType) throws Docx4JException { if (n == null) { throw new Docx4JException("null input"); } // if (log.isDebugEnabled() ) { // System.out.println("IN: " + XmlUtils.w3CDomNodeToString(n)); // } Object jaxb = null; try { jaxb = XmlUtils.unmarshal(n, Context.jcPML, declaredType); } catch (JAXBException e1) { throw new Docx4JException("Couldn't unmarshall " + XmlUtils.w3CDomNodeToString(n), e1); } try { if (jaxb instanceof JAXBElement) { JAXBElement jb = (JAXBElement) jaxb; if (jb.getDeclaredType().getName().equals(declaredType.getName())) { return jb.getValue(); } else { log.error("UNEXPECTED " + XmlUtils.JAXBElementDebug(jb)); throw new Docx4JException( "Expected " + declaredType.getName() + " but got " + XmlUtils.JAXBElementDebug(jb)); } } else if (jaxb.getClass().getName().equals(declaredType.getName())) { return jaxb; } else { log.error(jaxb.getClass().getName()); throw new Docx4JException( "Expected " + declaredType.getName() + " but got " + jaxb.getClass().getName()); } } catch (ClassCastException e) { throw new Docx4JException( "Expected " + declaredType.getName() + " but got " + jaxb.getClass().getName(), e); } }
public OpenDoPEHandler(WordprocessingMLPackage wordMLPackage) throws Docx4JException { this.wordMLPackage = wordMLPackage; if (wordMLPackage.getMainDocumentPart().getXPathsPart() == null) { throw new Docx4JException("OpenDoPE XPaths part missing"); } else { xPaths = wordMLPackage.getMainDocumentPart().getXPathsPart().getJaxbElement(); log.debug(XmlUtils.marshaltoString(xPaths, true, true)); } if (wordMLPackage.getMainDocumentPart().getConditionsPart() != null) { conditions = wordMLPackage.getMainDocumentPart().getConditionsPart().getJaxbElement(); log.debug(XmlUtils.marshaltoString(conditions, true, true)); } if (wordMLPackage.getMainDocumentPart().getComponentsPart() != null) { components = wordMLPackage.getMainDocumentPart().getComponentsPart().getJaxbElement(); log.debug(XmlUtils.marshaltoString(components, true, true)); } shallowTraversor = new ShallowTraversor(); shallowTraversor.wordMLPackage = wordMLPackage; }
private static CTTextParagraphProperties unmarshalFormatting(NodeIterator lvlNpPr) { // Get the pPr node as a JAXB object, // so we can read it using our standard // methods. Its a bit sad that we // can't just adorn our DOM tree with the // original JAXB objects? try { // CTTextListStyle lstStyle = null; CTTextParagraphProperties pPr = null; if (lvlNpPr != null) { Node n = lvlNpPr.nextNode(); log.debug(n.getClass().getName()); String str = XmlUtils.w3CDomNodeToString(n); // log.debug("'" + str + "'"); // Convert to String first ... // unmarshalling the node directly doesn't work as expected // (see comment in XmlUtils) // if (n!=null) { // return (CTTextParagraphProperties)XmlUtils.unmarshal(n, Context.jcPML, // CTTextParagraphProperties.class); // } if (!str.equals("")) { return (CTTextParagraphProperties) XmlUtils.unmarshalString(str, Context.jcPML, CTTextParagraphProperties.class); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
static { try { jcSVG = JAXBContext.newInstance("org.plutext.jaxb.svg11"); oFactory = new ObjectFactory(); Source xsltSource = new StreamSource( org.docx4j.utils.ResourceUtils.getResource( "org/pptx4j/convert/out/svginhtml/pptx2svginhtml.xslt")); xslt = XmlUtils.getTransformerTemplate(xsltSource); } catch (Exception e) { e.printStackTrace(); } }
protected void applyPPr(PPr pPrToApply, PPr effectivePPr) { log.debug( "apply " + XmlUtils.marshaltoString(pPrToApply, true, true) + "\n\r to " + XmlUtils.marshaltoString(effectivePPr, true, true)); if (pPrToApply == null) { return; } List<Property> properties = PropertyFactory.createProperties(wordMLPackage, pPrToApply); for (Property p : properties) { if (p != null) { // log.debug("applying pPr " + p.getClass().getName() ); ((AbstractParagraphProperty) p) .set(effectivePPr); // NB, this new method does not copy. TODO? } } log.debug("result " + XmlUtils.marshaltoString(effectivePPr, true, true)); }
private List<Object> cloneRepeatSdt(Object sdt, String xpathBase, int numRepeats) { List<Object> newContent = new ArrayList<Object>(); SdtPr sdtPr = getSdtPr(sdt); log.debug(XmlUtils.marshaltoString(sdtPr, true, true)); // CTDataBinding binding = // (CTDataBinding)XmlUtils.unwrap(sdtPr.getDataBinding()); CTDataBinding binding = sdtPr.getDataBinding(); if (binding != null) { // Shouldn't be a binding anyway sdtPr.getRPrOrAliasOrLock().remove(binding); } emptyRepeatTagValue(sdtPr.getTag()); // 2012 07 15: do it to the first one for (int i = 0; i < numRepeats; i++) { // 2012 07 13: for "od:RptPosCon" processing to // work (conditional inclusion dependant on position // in repeat), we need each entry (ie including the // original) to have the same tag (which I've changed // to od:rptd). if (i > 0) { // Change ID sdtPr.setId(); } // preserve ID on index 0, important for OpenDoPEReverter! // Clone newContent.add(XmlUtils.deepCopy(sdt)); } return newContent; }
@Override public void walkJAXBElements(Object parent) { List<Object> children = getChildren(parent); if (children != null) { for (Object o : children) { o = XmlUtils.unwrap(o); this.apply(o); if (this.shouldTraverse(o)) { walkJAXBElements(o); } } } }
@Deprecated // since its questionable whether this // is important enough to live in WordprocessingMLPackage, // and in any case probably should be replaced with a TraversalUtil // approach (which wouldn't involve marshal/unmarshall, and // so should be more efficient). public void filter(FilterSettings filterSettings) throws Exception { if (filterTemplate == null) { // first use Source xsltSource = new StreamSource( org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/packages/filter.xslt")); filterTemplate = XmlUtils.getTransformerTemplate(xsltSource); } transform(filterTemplate, filterSettings.getSettings()); }
protected void convertToNode( CC conversionContext, Object unmarshalledNode, String modelId, Document document, Node parentNode) throws DOMException { // To use our existing model, first we need childResults. // We get these using a new Generator object. log.debug(modelId); DocumentFragment childResults = null; if (unmarshalledNode instanceof ContentAccessor) { childResults = document.createDocumentFragment(); AbstractVisitorExporterGenerator<CC> generator = getFactory().createInstance(conversionContext, document, childResults); new TraversalUtil(((ContentAccessor) unmarshalledNode).getContent(), generator); } else if (unmarshalledNode instanceof org.docx4j.wml.Pict) { // if it contains a textbox.. // repeating this... org.docx4j.vml.CTTextbox textBox = getTextBox((org.docx4j.wml.Pict) unmarshalledNode); if (textBox != null) { childResults = document.createDocumentFragment(); AbstractVisitorExporterGenerator<CC> generator = getFactory().createInstance(conversionContext, document, childResults); new TraversalUtil(textBox.getTxbxContent().getContent(), generator); } } Node resultNode = conversionContext .getWriterRegistry() .toNode(conversionContext, unmarshalledNode, modelId, childResults, document); if (resultNode != null) { log.debug("Appending " + XmlUtils.w3CDomNodeToString(resultNode)); parentNode.appendChild(resultNode); } }