protected static void shallowCopyContent(Part source, Part destination) throws Docx4JException { if (source instanceof BinaryPart) { ((BinaryPart)destination).setBinaryData(((BinaryPart)source).getBuffer()); } else if (source instanceof JaxbXmlPart) { ((JaxbXmlPart)destination).setJaxbElement(((JaxbXmlPart)source).getJaxbElement()); ((JaxbXmlPart)destination).setJAXBContext(((JaxbXmlPart)source).getJAXBContext()); } else if (source instanceof CustomXmlDataStoragePart) { ((CustomXmlDataStoragePart)destination).setData(((CustomXmlDataStoragePart)source).getData()); } else if (source instanceof XmlPart) { ((XmlPart)destination).setDocument(((XmlPart)source).getDocument()); } else { throw new IllegalArgumentException("Dont know how to handle a part of type " + source.getClass().getName()); } } }
getContents(); setMceIgnorable( (McIgnorableNamespaceDeclarator) namespacePrefixMapper); if (this.getMceIgnorable()!=null) { mceIgnorable = this.getMceIgnorable(); NamespacePrefixMapperUtils.declareNamespaces(mceIgnorable + getMcChoiceNamespaces(), doc); log.debug( "canonicalizeSubtree with inclusiveNamespaces {}, {}", this.getMceIgnorable(), getMcChoiceNamespaces() ); byte[] bytes = c.canonicalizeSubtree(doc, this.getMceIgnorable() + getMcChoiceNamespaces()); mceIgnorable + getMcChoiceNamespaces()); boolean isNew = (this.getPackage()==null) ? true : this.getPackage().isNew(); // handle edge cases eg unit test where there is no package marshaller.setListener(new Docx4jMarshallerListener(xsww, this.getPackage().isNew())); ((McIgnorableNamespaceDeclarator) namespacePrefixMapper).setMcIgnorable(mceIgnorable + getMcChoiceNamespaces());
@Override public void afterUnmarshal(Object target, Object parent) { if (target instanceof AlternateContent.Choice) { AlternateContent.Choice choice = (AlternateContent.Choice)target; //System.out.print("after, Need to declare " + choice.getRequires() ); if (choice.getRequires()!=null) { part.addMcChoiceNamespace(choice.getRequires()); } if (choice.getIgnorable()!=null) { part.addMcChoiceNamespace(choice.getIgnorable()); } if (choice.getMustUnderstand()!=null) { part.addMcChoiceNamespace(choice.getMustUnderstand()); } } }
public void scramble(JaxbXmlPart p) { log.info("\n\n Scrambling " + p.getPartName().getName()); new TraversalUtil(p.getJaxbElement(), latinizer); }
if (this.getPackage()==null) { log.warn("This part not added to a package, so its contents can't be retrieved. " ); return null; PartStore partStore = this.getPackage().getSourcePartStore(); if (partStore==null) { log.info("No PartStore defined for this package (it was probably created, not loaded). " ); log.info(this.getPartName().getName() + ": did you initialise its contents to something?"); return null; String name = this.getPartName().getName(); this.setContentLengthAsLoaded( partStore.getPartSize( name.substring(1))); && this.getContentLengthAsLoaded()>MAX_BYTES_Unmarshal_Error) { throw new PartTooLargeException(this.getPartName() + ", length " + this.getContentLengthAsLoaded() + " exceeds your configured maximum allowed size for unmarshal."); } else { log.debug("Lazily unmarshalling " + name); unmarshal( is ); throw new Docx4JException("Problem with part " + this.getPartName(), e);
private void process(JaxbXmlPart part) throws Docx4JException { log.info("/n Processing " + part.getPartName().getName() ); = part.getPackage(); part.getJaxbElement() ); part.setJaxbElement(result); part.setJaxbElement(o); } else part.setJaxbElement(o);
parameters.put("types", ArrayUtils.toString(keys)); final Document partDOM = marshaltoW3CDomDocument(part.getJaxbElement()); final JAXBResult result = prepareJAXBResult(Context.jc); part.setJaxbElement(result);
/** * See your content as XML. An easy way to invoke XmlUtils.marshaltoString * * @return * @since 3.0.0 */ public String getXML() { return XmlUtils.marshaltoString( getJaxbElement(), true, true, jc ); }
String mceIgnorable = ((JaxbXmlPart)part).getMceIgnorable(); w3cDoc = marshaltoW3CDomDocument(jaxbXmlPart.getJaxbElement(), jaxbXmlPart.getJAXBContext(), mceIgnorable + jaxbXmlPart.getMcChoiceNamespaces());
part.getJaxbElement() ); part.getPackage().getCustomXmlDataStorageParts()); transformParameters.put("wmlPackage", wordMLPackage); transformParameters.put("sourcePart", part); part.setJaxbElement( unmarshal(((org.w3c.dom.Document)result.getNode()), Docx4jProperties.getProperty("docx4j.model.datastorage.BindingTraverserXSLT.ValidationEventContinue",
partStore = this.getPackage().getSourcePartStore(); String name = this.getPartName().getName(); InputStream is = partStore.loadPart( name.substring(1)); ByteArray byteArray = ((ZipPartStore)partStore).getByteArray(this.getPartName().getName().substring(1)); byteArray.setBytes(saxHandler.getOutputStream().toByteArray()); log.debug("unmarshalling"); jaxbElement = this.unmarshal( new ByteArrayInputStream(saxHandler.getOutputStream().toByteArray()) ); // so much for avoiding JAXB!
part.getJaxbElement() ); part.getPackage().getCustomXmlDataStorageParts()); transformParameters.put("wmlPackage", (WordprocessingMLPackage)pkg); transformParameters.put("sourcePart", part);
if (jaxbElement==null) { PartStore partStore = this.getPackage().getSourcePartStore(); String name = this.getPartName().getName(); InputStream is = partStore.loadPart( name.substring(1));
getContents(); setMceIgnorable( (McIgnorableNamespaceDeclarator) namespacePrefixMapper);
PartStore partStore = this.getPackage().getSourcePartStore(); String name = this.getPartName().getName(); InputStream is = partStore.loadPart( name.substring(1)); org.w3c.dom.Document doc = org.docx4j.XmlUtils.neww3cDomDocument(); try { this.marshal(doc); } catch (JAXBException e) {
/** * Get the live contents of this part. * (getContents() is preferred, this is the older/less friendly method name) * @return */ public E getJaxbElement() { try { return getContents(); } catch (Docx4JException e) { log.error(e.getMessage(), e); return null; } }
getNewPartName("/chunk", ".xml", sourcePart.getRelationshipsPart())); Relationship altChunkRel =sourcePart.addTargetPart(afiPart);
private void process(JaxbXmlPart part) throws Docx4JException { log.info("/n Processing " + part.getPartName().getName() ); = part.getPackage(); part.getJaxbElement() ); part.setJaxbElement(result); part.setJaxbElement(o); } else part.setJaxbElement(o);
/** * Convert any w:fldSimple in this part to complex field. * @param part * @throws Docx4JException */ public static void complexifyFields(JaxbXmlPart part) throws Docx4JException { org.w3c.dom.Document doc = XmlUtils.marshaltoW3CDomDocument( part.getJaxbElement() ); // XPathsPart xPathsPart = null; JAXBContext jc = Context.jc; try { // 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 ); org.docx4j.XmlUtils.transform(doc, xslt, null, result); part.setJaxbElement(result); } catch (Exception e) { throw new Docx4JException("Problems transforming fields", e); } }
public void detectDmlVml(JaxbXmlPart p) { log.info("\n\n Inspecting " + p.getPartName().getName()); dmlVmlAnalyzer.reinit(); dmlVmlAnalyzer.setPart(p); new TraversalUtil(p.getJaxbElement(), dmlVmlAnalyzer); result.unsafeObjectsByPart.put(p, dmlVmlAnalyzer.unsafeObjects); if (dmlVmlAnalyzer.unsafeObjects.size()>0){ result.anyUnsafeObjects = true; } result.inventoryObjectsByPart.put(p, dmlVmlAnalyzer.inventoryObjects); if (!result.containsVML) { result.containsVML = dmlVmlAnalyzer.containsVML; } result.fieldsPresent = this.dmlVmlAnalyzer.fieldsPresent; }