/** * @since 3.3.1 */ @Override public String cachedXPathGetString(String xpath, String prefixMappings) throws Docx4JException { return getData().cachedXPathGetString(xpath, prefixMappings); }
/** * 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(); }
public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException { String targetName = part.getPartName().getName().substring(1); String filePath = dir.getPath() + dir.separator + targetName; File file = new File(filePath); file.getParentFile().mkdirs(); try { FileOutputStream fos = new FileOutputStream(file); part.getData().writeDocument( fos ); fos.close(); } catch (Exception e) { throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e); } }
public void init() { // Used if this Part is added to [Content_Types].xml setContentType(new org.docx4j.openpackaging.contenttype.ContentType( org.docx4j.openpackaging.contenttype.ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE)); // Used when this Part is added to a rels setRelationshipType(Namespaces.CUSTOM_XML_DATA_STORAGE); }
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()); } } }
/** * @param parts The parts present in the package to which this will be added. * If for example /customXml/item1.xml already exists, this allows * the name /customXml/item2.xml to be generated. * @throws InvalidFormatException */ @Deprecated // since we now have AddPartBehaviour.RENAME_IF_NAME_EXISTS public CustomXmlDataStoragePart(Parts parts) throws InvalidFormatException { int partNum = 1; if (parts!=null) { while (parts.get(new PartName("/customXml/item" + partNum + ".xml"))!=null) { partNum++; } } this.setPartName(new PartName("/customXml/item" + partNum + ".xml")); log.info("Using PartName /customXml/item" + partNum + ".xml"); init(); }
public CustomXmlDataStoragePart(PartName partName) throws InvalidFormatException { super(partName); init(); }
/** * @since 3.0.2 */ public String getItemId() { if (this.getRelationshipsPart()==null) { return null; } else { // Look in its rels for rel of @Type customXmlProps (eg @Target="itemProps1.xml") Relationship r = this.getRelationshipsPart().getRelationshipByType( Namespaces.CUSTOM_XML_DATA_STORAGE_PROPERTIES); if (r==null) { log.warn(".. but that doesn't point to a customXmlProps part"); return null; } CustomXmlDataStoragePropertiesPart customXmlProps = (CustomXmlDataStoragePropertiesPart)this.getRelationshipsPart().getPart(r); if (customXmlProps==null) { log.warn(".. but the target seems to be missing?"); return null; } else { return customXmlProps.getItemId().toLowerCase(); } } }
return new org.docx4j.openpackaging.parts.CustomXmlDataStoragePart(new PartName(partName));
public void init() { // Used if this Part is added to [Content_Types].xml setContentType(new org.docx4j.openpackaging.contenttype.ContentType( org.docx4j.openpackaging.contenttype.ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGE)); // Used when this Part is added to a rels setRelationshipType(Namespaces.CUSTOM_XML_DATA_STORAGE); }
/** * @param parts The parts present in the package to which this will be added. * If for example /customXml/item1.xml already exists, this allows * the name /customXml/item2.xml to be generated. * @throws InvalidFormatException */ @Deprecated // since we now have AddPartBehaviour.RENAME_IF_NAME_EXISTS public CustomXmlDataStoragePart(Parts parts) throws InvalidFormatException { int partNum = 1; if (parts!=null) { while (parts.get(new PartName("/customXml/item" + partNum + ".xml"))!=null) { partNum++; } } this.setPartName(new PartName("/customXml/item" + partNum + ".xml")); log.info("Using PartName /customXml/item" + partNum + ".xml"); init(); }
public CustomXmlDataStoragePart() throws InvalidFormatException { super(new PartName("/customXml/item1.xml")); init(); }
/** * @since 3.0.2 */ public String getItemId() { if (this.getRelationshipsPart()==null) { return null; } else { // Look in its rels for rel of @Type customXmlProps (eg @Target="itemProps1.xml") Relationship r = this.getRelationshipsPart().getRelationshipByType( Namespaces.CUSTOM_XML_DATA_STORAGE_PROPERTIES); if (r==null) { log.warn(".. but that doesn't point to a customXmlProps part"); return null; } CustomXmlDataStoragePropertiesPart customXmlProps = (CustomXmlDataStoragePropertiesPart)this.getRelationshipsPart().getPart(r); if (customXmlProps==null) { log.warn(".. but the target seems to be missing?"); return null; } else { return customXmlProps.getItemId().toLowerCase(); } } }
return new org.docx4j.openpackaging.parts.CustomXmlDataStoragePart(new PartName(partName));
/** * Set the XML * * @since 6.0.0 */ @Override public void setXML(Document xmlDocument) throws Docx4JException { getData().setDocument(xmlDocument); }
public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException { String targetName = part.getPartName().getName().substring(1); try { // Add ZIP entry to output stream. zos.putArchiveEntry(new ZipArchiveEntry(targetName)); part.getData().writeDocument( zos ); // Complete the entry zos.closeArchiveEntry(); } catch (Exception e) { throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e); } }