diff --git a/src/main/java/org/docx4j/Docx4J.java b/src/main/java/org/docx4j/Docx4J.java index a0535f7263..186e92170c 100644 --- a/src/main/java/org/docx4j/Docx4J.java +++ b/src/main/java/org/docx4j/Docx4J.java @@ -497,17 +497,9 @@ protected static String findXPathStorageItemIdInContentControls(WordprocessingML } protected static void removeSDTs(WordprocessingMLPackage wmlPackage)throws Docx4JException { - RemovalHandler removalHandler; - removalHandler = new RemovalHandler(); - removalHandler.removeSDTs(wmlPackage.getMainDocumentPart(), RemovalHandler.Quantifier.ALL, (String[])null); - for (Part part:wmlPackage.getParts().getParts().values()) { - if (part instanceof HeaderPart) { - removalHandler.removeSDTs((HeaderPart)part, RemovalHandler.Quantifier.ALL, (String[])null); - } - else if (part instanceof FooterPart) { - removalHandler.removeSDTs((FooterPart)part, RemovalHandler.Quantifier.ALL, (String[])null); - } - } + RemovalHandler removalHandler; + removalHandler = new RemovalHandler(); + removalHandler.removeSDTs(wmlPackage, RemovalHandler.Quantifier.ALL, (String[])null); } protected static void removeDefinedCustomXmlParts(WordprocessingMLPackage wmlPackage, CustomXmlDataStoragePart customXmlDataStoragePart) { diff --git a/src/main/java/org/docx4j/model/datastorage/BindingHandler.java b/src/main/java/org/docx4j/model/datastorage/BindingHandler.java index bb769ed727..cacb9765a8 100644 --- a/src/main/java/org/docx4j/model/datastorage/BindingHandler.java +++ b/src/main/java/org/docx4j/model/datastorage/BindingHandler.java @@ -32,7 +32,9 @@ import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.parts.CustomXmlPart; import org.docx4j.openpackaging.parts.JaxbXmlPart; +import org.docx4j.openpackaging.parts.WordprocessingML.EndnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; +import org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; import org.docx4j.openpackaging.parts.opendope.XPathsPart; import org.docx4j.openpackaging.parts.relationships.Namespaces; @@ -202,7 +204,12 @@ public void applyBindings() throws Docx4JException { applyBindings((HeaderPart) rp.getPart(r)); } else if (r.getType().equals(Namespaces.FOOTER)) { applyBindings((FooterPart) rp.getPart(r)); - } + } else if (r.getType().equals(Namespaces.FOOTNOTES)) { + applyBindings((FootnotesPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.ENDNOTES)) { + applyBindings((EndnotesPart) rp.getPart(r)); + } + } } diff --git a/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java b/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java index 85319b6e99..32b7cd3722 100644 --- a/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java +++ b/src/main/java/org/docx4j/model/datastorage/OpenDoPEHandler.java @@ -50,7 +50,9 @@ import org.docx4j.openpackaging.parts.CustomXmlPart; import org.docx4j.openpackaging.parts.PartName; import org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart; +import org.docx4j.openpackaging.parts.WordprocessingML.EndnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; +import org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; import org.docx4j.openpackaging.parts.opendope.ComponentsPart; import org.docx4j.openpackaging.parts.relationships.Namespaces; @@ -378,6 +380,10 @@ protected static Set getParts(WordprocessingMLPackage srcPackag partList.add((HeaderPart) rp.getPart(r)); } else if (r.getType().equals(Namespaces.FOOTER)) { partList.add((FooterPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.FOOTNOTES)) { + partList.add((FootnotesPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.ENDNOTES)) { + partList.add((EndnotesPart) rp.getPart(r)); } } diff --git a/src/main/java/org/docx4j/model/datastorage/OpenDoPEIntegrity.java b/src/main/java/org/docx4j/model/datastorage/OpenDoPEIntegrity.java index bc4686931c..f96d11de7e 100644 --- a/src/main/java/org/docx4j/model/datastorage/OpenDoPEIntegrity.java +++ b/src/main/java/org/docx4j/model/datastorage/OpenDoPEIntegrity.java @@ -37,7 +37,9 @@ import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.parts.JaxbXmlPart; +import org.docx4j.openpackaging.parts.WordprocessingML.EndnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; +import org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; import org.docx4j.openpackaging.parts.relationships.Namespaces; import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; @@ -124,6 +126,10 @@ public void process(WordprocessingMLPackage wordMLPackage) throws Docx4JExceptio process((HeaderPart) rp.getPart(r)); } else if (r.getType().equals(Namespaces.FOOTER)) { process((FooterPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.FOOTNOTES)) { + process((FootnotesPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.ENDNOTES)) { + process((EndnotesPart) rp.getPart(r)); } } } diff --git a/src/main/java/org/docx4j/model/datastorage/OpenDoPEReverter.java b/src/main/java/org/docx4j/model/datastorage/OpenDoPEReverter.java index fcd9b5bc54..263994f709 100644 --- a/src/main/java/org/docx4j/model/datastorage/OpenDoPEReverter.java +++ b/src/main/java/org/docx4j/model/datastorage/OpenDoPEReverter.java @@ -34,7 +34,9 @@ import org.docx4j.model.sdt.QueryString; import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; +import org.docx4j.openpackaging.parts.WordprocessingML.EndnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; +import org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; import org.docx4j.openpackaging.parts.opendope.XPathsPart; import org.docx4j.openpackaging.parts.relationships.Namespaces; @@ -175,6 +177,10 @@ private void findSdtsInTemplate(WordprocessingMLPackage pkg, TopLevelSdtTemplate findSdtsInTemplatePart((HeaderPart) rp.getPart(r), sdtPrFinder); } else if (r.getType().equals(Namespaces.FOOTER)) { findSdtsInTemplatePart((FooterPart) rp.getPart(r), sdtPrFinder); + } else if (r.getType().equals(Namespaces.FOOTNOTES)) { + findSdtsInTemplatePart((FootnotesPart) rp.getPart(r), sdtPrFinder); + } else if (r.getType().equals(Namespaces.ENDNOTES)) { + findSdtsInTemplatePart((EndnotesPart) rp.getPart(r), sdtPrFinder); } } } @@ -281,6 +287,10 @@ private void handleSdtsInInstance() throws Docx4JException { handleSdtsInInstancePart((HeaderPart) rp.getPart(r)); } else if (r.getType().equals(Namespaces.FOOTER)) { handleSdtsInInstancePart((FooterPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.FOOTNOTES)) { + handleSdtsInInstancePart((FootnotesPart) rp.getPart(r)); + } else if (r.getType().equals(Namespaces.ENDNOTES)) { + handleSdtsInInstancePart((EndnotesPart) rp.getPart(r)); } } } diff --git a/src/main/java/org/docx4j/model/datastorage/RemovalHandler.java b/src/main/java/org/docx4j/model/datastorage/RemovalHandler.java index edeb74e61a..210755c40e 100644 --- a/src/main/java/org/docx4j/model/datastorage/RemovalHandler.java +++ b/src/main/java/org/docx4j/model/datastorage/RemovalHandler.java @@ -38,7 +38,9 @@ import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.packages.WordprocessingMLPackage; import org.docx4j.openpackaging.parts.JaxbXmlPart; +import org.docx4j.openpackaging.parts.WordprocessingML.EndnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart; +import org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart; import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart; import org.docx4j.openpackaging.parts.relationships.Namespaces; import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; @@ -136,6 +138,10 @@ public void removeSDTs(WordprocessingMLPackage wordMLPackage, removeSDTs((HeaderPart) rp.getPart(r), quantifier, keys); } else if (r.getType().equals(Namespaces.FOOTER)) { removeSDTs((FooterPart) rp.getPart(r), quantifier, keys); + } else if (r.getType().equals(Namespaces.FOOTNOTES)) { + removeSDTs((FootnotesPart) rp.getPart(r), quantifier, keys); + } else if (r.getType().equals(Namespaces.ENDNOTES)) { + removeSDTs((EndnotesPart) rp.getPart(r), quantifier, keys); } } } diff --git a/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/EndnotesPart.java b/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/EndnotesPart.java index 8d79fb384b..9cc620428e 100644 --- a/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/EndnotesPart.java +++ b/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/EndnotesPart.java @@ -21,15 +21,23 @@ package org.docx4j.openpackaging.parts.WordprocessingML; +import java.util.List; + +import org.docx4j.jaxb.Context; +import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.exceptions.InvalidFormatException; import org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware; import org.docx4j.openpackaging.parts.PartName; import org.docx4j.openpackaging.parts.relationships.Namespaces; import org.docx4j.wml.CTEndnotes; +import org.docx4j.wml.CTFtnEdn; +import org.docx4j.wml.ContentAccessor; -public final class EndnotesPart extends JaxbXmlPartXPathAware { +public final class EndnotesPart extends JaxbXmlPartXPathAware + implements ContentAccessor { + /* Unfortunately, this class can't easily implement * ContentAccessor, because to do that, * both CTFootnotes and CTEndnotes would need @@ -70,18 +78,26 @@ public void init() { } -// /** -// * Convenience method to getJaxbElement().getEndnote() -// * @since 2.8.1 -// */ -// public List getContent() { -// -// if (this.getJaxbElement()==null) { -// this.setJaxbElement( Context.getWmlObjectFactory().createCTEndnotes() ); -// } -// -// return this.getJaxbElement().getEndnote(); -// } + + /** + * Convenience method to getJaxbElement().getEndnote() + * @since 2.8.1 + */ + public List getContent() { + try { + CTEndnotes contents = this.getContents(); + if (contents==null) { + contents = Context.getWmlObjectFactory().createCTEndnotes(); + this.setContents(contents); + } + + return contents.getEndnote(); + } catch (Docx4JException e) { + // Similar exception handling as in deprectad JaxbXmlPart.getJaxbElement(). + log.error(e.getMessage(), e); + return null; + } + } } diff --git a/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/FootnotesPart.java b/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/FootnotesPart.java index c11f52b990..7f07a76796 100644 --- a/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/FootnotesPart.java +++ b/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/FootnotesPart.java @@ -21,15 +21,21 @@ package org.docx4j.openpackaging.parts.WordprocessingML; +import java.util.List; + +import org.docx4j.jaxb.Context; +import org.docx4j.openpackaging.exceptions.Docx4JException; import org.docx4j.openpackaging.exceptions.InvalidFormatException; import org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware; import org.docx4j.openpackaging.parts.PartName; import org.docx4j.openpackaging.parts.relationships.Namespaces; import org.docx4j.wml.CTFootnotes; +import org.docx4j.wml.CTFtnEdn; +import org.docx4j.wml.ContentAccessor; -public final class FootnotesPart extends JaxbXmlPartXPathAware { - // implements ContentAccessor { +public final class FootnotesPart extends JaxbXmlPartXPathAware + implements ContentAccessor { /* Unfortunately, this class can't easily implement * ContentAccessor, because to do that, @@ -48,6 +54,11 @@ public final class FootnotesPart extends JaxbXmlPartXPathAware { * the first thing to do would be to change wml.xsd, so we generate * distinct classes CTFtn and CTEdn. But that would be backwards incompatible, * unless we also retained CTFtnEdn in some fashion? + * + * JABOJ78: Is this really that hard to accomplished. By removing generic from + * ContentAccessor.getList return and letting FootnotesPart return list of CTFootnotes seems + * to do the trick! + * */ @@ -72,6 +83,27 @@ public void init() { } + /** + * Convenience method to getJaxbElement().getFootnote() + * @since 2.8.1 + */ + public List getContent() { + try { + CTFootnotes contents = this.getContents(); + if (contents==null) { + contents = Context.getWmlObjectFactory().createCTFootnotes(); + this.setContents(contents); + } + + return contents.getFootnote(); + } catch (Docx4JException e) { + // Similar exception handling as in deprectad JaxbXmlPart.getJaxbElement(). + log.error(e.getMessage(), e); + return null; + } + + } + // /** // * Convenience method to getJaxbElement().getFootnote() // * @since 2.8.1 diff --git a/src/main/java/org/docx4j/wml/CTFtnEdn.java b/src/main/java/org/docx4j/wml/CTFtnEdn.java index 0086f372e9..917aedaf1d 100644 --- a/src/main/java/org/docx4j/wml/CTFtnEdn.java +++ b/src/main/java/org/docx4j/wml/CTFtnEdn.java @@ -22,7 +22,6 @@ package org.docx4j.wml; import java.math.BigInteger; -import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; diff --git a/src/main/java/org/docx4j/wml/ContentAccessor.java b/src/main/java/org/docx4j/wml/ContentAccessor.java index ca325df75d..91ba95772e 100644 --- a/src/main/java/org/docx4j/wml/ContentAccessor.java +++ b/src/main/java/org/docx4j/wml/ContentAccessor.java @@ -5,8 +5,7 @@ /** * @since 2.7 */ -public interface ContentAccessor { - - public List getContent(); +public interface ContentAccessor { + public List getContent(); } diff --git a/src/main/java/org/docx4j/wml/Ftr.java b/src/main/java/org/docx4j/wml/Ftr.java index aa3308acc3..9a0ba148b7 100644 --- a/src/main/java/org/docx4j/wml/Ftr.java +++ b/src/main/java/org/docx4j/wml/Ftr.java @@ -64,7 +64,7 @@ }) @XmlRootElement(name = "ftr") public class Ftr - implements Child, ContentAccessor + implements Child, ContentAccessor { @XmlElementRefs({ diff --git a/src/main/java/org/docx4j/wml/P.java b/src/main/java/org/docx4j/wml/P.java index 2c85331e98..1d3fa44565 100644 --- a/src/main/java/org/docx4j/wml/P.java +++ b/src/main/java/org/docx4j/wml/P.java @@ -75,7 +75,7 @@ "content" }) @XmlRootElement(name = "p") -public class P implements Child, ContentAccessor +public class P implements Child, ContentAccessor { private static Logger log = LoggerFactory.getLogger(P.class); @@ -469,7 +469,7 @@ public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { }) @XmlRootElement(name = "hyperlink") public static class Hyperlink - implements Child, ContentAccessor + implements Child, ContentAccessor { @XmlElementRefs({