/** Unmarshal an InputStream as an object in the package org.docx4j.jaxb.document. * Note: you should ensure you include a namespace declaration for w: and * any other namespace in the xml string. * Also, the object you are attempting to unmarshall to might need to * have an @XmlRootElement annotation for things to work. */ public static Object unmarshal(InputStream is) throws JAXBException { return unmarshal(is, Context.jc); }
private void read(InputStream is) throws Exception { Document domDoc = XmlUtils.getNewDocumentBuilder().parse(is); Element presetShapeDefinitons = domDoc.getDocumentElement(); NodeList nodes = presetShapeDefinitons.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (!(node instanceof Element)) continue; String name = node.getLocalName(); CTCustomGeometry2D geom = (CTCustomGeometry2D)XmlUtils.unmarshal(node, Context.jc, CTCustomGeometry2D.class); if(containsKey(name)) { log.warn("Duplicate definition of " + name) ; // happened for upDownArrow; that dupe now commented out } put(name, geom); log.debug(name); } }
@Override public void setXML(Document xmlDocument) throws Docx4JException { try { this.setJaxbElement( (E)XmlUtils.unmarshal(xmlDocument)); } catch (JAXBException e) { throw new Docx4JException("Problem unmarshalling, check content", e); } }
/** This method is called from the converters with XSL-Transformations * * @param node * @param childResults the already transformed node (element) content * @param doc * @return */ public Node toNode(AbstractWmlConversionContext context, Node node, NodeList childResults) { Object unmarshalledNode = null; Document doc = XmlUtils.neww3cDomDocument(); /* A result tree fragment represents a fragment of the result tree. A result tree fragment is treated equivalently to a node-set that contains just a single root node. */ Node content = ((childResults != null) && (childResults.getLength() > 0) ? childResults.item(0) : null); Node ret = null; try { unmarshalledNode = XmlUtils.unmarshal(node); } catch (JAXBException e) { log.error("Cannot unmarshall " + node.getNodeName(), e); } if (unmarshalledNode != null) { ret = toNode(context, unmarshalledNode, node.getNodeName(), content, doc); } return ret; }
Object jaxb = null; try { jaxb = XmlUtils.unmarshal(n, Context.jc, Pict.class); } catch (JAXBException e1) {
jaxb = XmlUtils.unmarshal(n, Context.jcPML, declaredType); } catch (JAXBException e1) { throw new Docx4JException("Couldn't unmarshall " + XmlUtils.w3CDomNodeToString(n), e1);
} else { try { sdtPr = (SdtPr)XmlUtils.unmarshal(sdtPrNode, Context.jc, SdtPr.class); } catch (JAXBException e) { log.error(e.getMessage(), e);
public static void updateComplexFieldDefinition(AbstractWmlConversionContext context, 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) { if (log.isDebugEnabled()) { log.debug("Ignoring unrecognised: " + XmlUtils.w3CDomNodeToString(node)); } } else { context.updateComplexFieldDefinition(fieldCharType); } }
try { encryption = (CTEncryption)XmlUtils.unwrap( XmlUtils.unmarshal(descriptor, Context.jcEncryption)); } catch (JAXBException e) {
org.w3c.dom.Document doc = ((DefaultXmlPart)p).getDocument(); try { Object o = XmlUtils.unmarshal(doc); if (o instanceof javax.xml.bind.JAXBElement) { sb.append(" containing JaxbElement:" + XmlUtils.JAXBElementDebug((JAXBElement)o) );
/** * Workaround for the fact that Xalan doesn't let us pass an AtomicInteger into an extension * function. Instead, it converts it into an int, which means the object in our * bookmarkIdCounter parameter isn't updated. * * So here we wrap the AtomicInteger in a class, * * @author jharrop * */ public static class BookmarkCounter { protected AtomicInteger bookmarkId; BookmarkCounter(AtomicInteger bookmarkId) { this.bookmarkId = bookmarkId; } }
public static String getXPathValue( Map<String, String> pathMap, WordprocessingMLPackage pkg, Map<String, CustomXmlPart> customXmlDataStorageParts, NodeIterator sdtPrNodeIt ) { SdtPr sdtPr = null; Node sdtPrNode = sdtPrNodeIt.nextNode(); try { sdtPr = (SdtPr)XmlUtils.unmarshal(sdtPrNode); } catch (JAXBException e) { log.error(e.getMessage(), e); return null; } CTDataBinding dataBinding = sdtPr.getDataBinding(); String storeItemId = dataBinding.getStoreItemID(); String xpath = dataBinding.getXpath(); String prefixMappings = dataBinding.getPrefixMappings(); return getXPathValue(pathMap, pkg, customXmlDataStorageParts, storeItemId, xpath, prefixMappings); }
try { Node n = sdtPrNodeIt.nextNode(); sdtPr = (SdtPr)XmlUtils.unmarshal(n, Context.jc, SdtPr.class); } catch (JAXBException e1) { throw new TransformerException("Missing or broken w:sdtPr", e1);
} else { try { sdtPr = (SdtPr)XmlUtils.unmarshal(sdtPrNode, Context.jc, SdtPr.class); } catch (JAXBException e) { log.error(e.getMessage(), e);
Node sdtPrNode = sdtPrNodeIt.nextNode(); try { sdtPr = (SdtPr)XmlUtils.unmarshal(sdtPrNode); } catch (JAXBException e) { log.error(e.getMessage(), e);
converter.pic = (org.pptx4j.pml.Pic)XmlUtils.unmarshal(n, org.pptx4j.jaxb.Context.jcPML, org.pptx4j.pml.Pic.class); } catch (JAXBException e1) { e1.printStackTrace();