if (pkg.getDocPropsCustomPart()==null pkg.addDocPropsCustomPart(); if (pkg.getDocPropsCustomPart()==null) { return; } else { pkg.getDocPropsCustomPart().setMarkAsFinal(val); if (pkg.getDocPropsExtendedPart()==null pkg.addDocPropsExtendedPart(); if (pkg.getDocPropsCorePart()==null pkg.addDocPropsCorePart(); if (pkg.getDocPropsCorePart()!=null) { pkg.getDocPropsCorePart().getJaxbElement().setContentStatus("Final");
/** * @since 3.0.0 */ public void setTitle(String title) { if (this.getDocPropsCorePart()==null) { DocPropsCorePart core; try { core = new DocPropsCorePart(); org.docx4j.docProps.core.ObjectFactory coreFactory = new org.docx4j.docProps.core.ObjectFactory(); core.setJaxbElement(coreFactory.createCoreProperties() ); this.addTargetPart(core); } catch (InvalidFormatException e) { log.error(e.getMessage(), e); } } org.docx4j.docProps.core.dc.elements.ObjectFactory of = new org.docx4j.docProps.core.dc.elements.ObjectFactory(); SimpleLiteral literal = of.createSimpleLiteral(); literal.getContent().add(title); this.getDocPropsCorePart().getJaxbElement().setTitle(of.createTitle(literal) ); }
if (targetContentType.equals(this.getContentType())) { log.debug("No change to content type " + this.getContentType()); return clone(); String mainPartNameString = PackageRelsUtil.getNameOfMainPart(this.getRelationshipsPart()); PartName mainPartName = new PartName("/" + mainPartNameString); OpcPackage clone = this.clone(); this.contentTypeManager.addOverrideContentType(mainPartName.getURI(), this.getContentType());
ret.setContentType(new ContentType(opcPackage.getContentType())); ret.setPartName(opcPackage.getPartName()); ret.setContentTypeManager(opcPackage.getContentTypeManager()); ret.getCustomXmlDataStorageParts().putAll(opcPackage.getCustomXmlDataStorageParts()); ret.setPartShortcut(opcPackage.getDocPropsCorePart(), Namespaces.PROPERTIES_CORE); ret.setPartShortcut(opcPackage.getDocPropsCustomPart(), Namespaces.PROPERTIES_CUSTOM); ret.setPartShortcut(opcPackage.getDocPropsExtendedPart(), Namespaces.PROPERTIES_EXTENDED); ret.getExternalResources().putAll(opcPackage.getExternalResources()); ret.setSourcePartStore(opcPackage.getSourcePartStore());
try { p.getTargetPartStore().setOutputStream(realOS); ContentTypeManager ctm = p.getContentTypeManager(); p.getTargetPartStore().saveContentTypes(ctm); RelationshipsPart rp = p.getRelationshipsPart(); saveRawXmlPart(rp ); p.getTargetPartStore().finishSave();
/** * It is often useful to see this [Content_Types].xml */ public static void printContentTypes(org.docx4j.openpackaging.packages.OpcPackage p) { ContentTypeManager ctm = p.getContentTypeManager(); //ctm.listTypes(); System.out.println( ctm.toString() ); }
if (pkg.getDocPropsExtendedPart()==null) pkg.addDocPropsExtendedPart();
/** * Remove this part from the pkg. Beware: it is up to you to make sure * your content doesn't rely on this part being present! A symptom of * that would be that Office now reports your file to be corrupt or in * need of repair. * * @since 3.0.2 */ @Override public void remove() { String itemId = this.getItemId(); if (itemId!=null) { log.debug("removing from CustomXmlDataStorageParts " + itemId); this.getPackage().getCustomXmlDataStorageParts().remove(itemId); } super.remove(); }
ContentTypeManager ctm = p.getContentTypeManager(); out.putNextEntry(new ZipEntry("[Content_Types].xml")); ctm.marshal(out); RelationshipsPart rp = p.getRelationshipsPart();
ContentTypeManager ctm = opcPackage.getContentTypeManager(); String proposedRelId = sourcePart.getRelationshipsPart().getNextId(); opcPackage.getExternalResources().put(imagePart.getExternalTarget(), imagePart);
HashMap<PartName, Part> parts = pkg.getParts().getParts(); if (pkg.getCustomXmlDataStorageParts().get(itemId.toLowerCase())!=null) { log.warn("Duplicate CustomXML itemId " + itemId + "; check your source docx!"); pkg.getCustomXmlDataStorageParts().put(itemId, (CustomXmlPart)entry );
public void addDocPropsExtendedPart() { if (docPropsExtendedPart==null) { try { docPropsExtendedPart = new org.docx4j.openpackaging.parts.DocPropsExtendedPart(); this.addTargetPart(docPropsExtendedPart); docPropsExtendedPart.setJaxbElement(new org.docx4j.docProps.extended.Properties()); } catch (InvalidFormatException e) { //Won't happen, so don't throw log.error(e.getMessage(), e); } } }
/** * @since 3.3.0 */ public boolean getMarkAsFinal() { if (pkg.getDocPropsCustomPart()==null) return false; return pkg.getDocPropsCustomPart().getMarkAsFinal(); }
/** * @since 3.0.0 */ public String getTitle() { if (this.getDocPropsCorePart()==null) { return null; } JAXBElement<SimpleLiteral> sl = this.getDocPropsCorePart().getJaxbElement().getTitle(); if (sl == null) return null; StringWriter sw = new StringWriter(); try { TextUtils.extractText(sl, sw, Context.jcDocPropsCore); } catch (Exception e) { log.error(e.getMessage(), e); } return sw.toString(); }
WordprocessingMLPackage clonePkg = (WordprocessingMLPackage)this.getPackage().clone(); // consistent with MergeDocx approach JaxbXmlPartAltChunkHost clonedPart = (JaxbXmlPartAltChunkHost)clonePkg.getParts().get(partName);
ret.setContentType(new ContentType(opcPackage.getContentType())); ret.setPartName(opcPackage.getPartName()); ret.setContentTypeManager(opcPackage.getContentTypeManager()); ret.getCustomXmlDataStorageParts().putAll(opcPackage.getCustomXmlDataStorageParts()); ret.setPartShortcut(opcPackage.getDocPropsCorePart(), Namespaces.PROPERTIES_CORE); ret.setPartShortcut(opcPackage.getDocPropsCustomPart(), Namespaces.PROPERTIES_CUSTOM); ret.setPartShortcut(opcPackage.getDocPropsExtendedPart(), Namespaces.PROPERTIES_EXTENDED); ret.getExternalResources().putAll(opcPackage.getExternalResources()); ret.setSourcePartStore(opcPackage.getSourcePartStore());
try { p.getTargetPartStore().setOutputStream(realOS); ContentTypeManager ctm = p.getContentTypeManager(); p.getTargetPartStore().saveContentTypes(ctm); RelationshipsPart rp = p.getRelationshipsPart(); saveRawXmlPart(rp ); p.getTargetPartStore().finishSave();
public void registerInContentTypeManager() { ContentTypeManager ctm = this.getPackage().getContentTypeManager(); if (altChunkType != null) { ctm.addDefaultContentType(altChunkType.getExtension(), altChunkType.getContentType()); } } }
if (pkg.getDocPropsExtendedPart()==null) pkg.addDocPropsExtendedPart();
/** * Remove this part from the pkg. Beware: it is up to you to make sure * your content doesn't rely on this part being present! A symptom of * that would be that Office now reports your file to be corrupt or in * need of repair. * * @since 3.0.2 */ @Override public void remove() { String itemId = this.getItemId(); if (itemId!=null) { log.debug("removing from CustomXmlDataStorageParts " + itemId); this.getPackage().getCustomXmlDataStorageParts().remove(itemId); } super.remove(); }