diff --git a/docx4j-core-tests/src/test/java/org/docx4j/wml/SdtPrTest.java b/docx4j-core-tests/src/test/java/org/docx4j/wml/SdtPrTest.java new file mode 100644 index 0000000000..afc804a453 --- /dev/null +++ b/docx4j-core-tests/src/test/java/org/docx4j/wml/SdtPrTest.java @@ -0,0 +1,68 @@ +package org.docx4j.wml; + +import org.docx4j.XmlUtils; +import org.docx4j.openpackaging.exceptions.InvalidFormatException; +import org.junit.Assert; +import org.junit.Test; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; + +public class SdtPrTest { + + /** + * Unmarshalling sets sdtcontentblock.getParent() correctly. + * + * @throws InvalidFormatException + * @throws JAXBException + */ + @Test + public void testUnmarshallingAndMarshallingSdtContentBlock() throws InvalidFormatException, JAXBException { + + + String openXML = "" + + "" + + "" // SdtBlock + + "" + + "" + + "" + + "" + + "" + + "" + + + "" // SdtContentBlock + + "" + + "" + + "Some content" + + "" + + "" + + "" + + + "" + + "" + + + "" + ; + + Document document = (Document) XmlUtils.unmarshalString(openXML); + + + SdtBlock sdtblock = (SdtBlock)document.getContent().get(0); + + + Assert.assertTrue(sdtblock.sdtPr.rPrOrAliasOrLock.get(0) instanceof Id); + Assert.assertTrue(sdtblock.sdtPr.rPrOrAliasOrLock.get(1) instanceof JAXBElement); + Assert.assertTrue(sdtblock.sdtPr.rPrOrAliasOrLock.get(2) instanceof JAXBElement); + Assert.assertTrue(((JAXBElement)sdtblock.sdtPr.rPrOrAliasOrLock.get(1)).getValue() instanceof SdtPr.Label); + Assert.assertTrue(((JAXBElement)sdtblock.sdtPr.rPrOrAliasOrLock.get(2)).getValue() instanceof SdtPr.Alias); + Assert.assertTrue(sdtblock.sdtPr.rPrOrAliasOrLock.get(3) instanceof Tag); + Assert.assertEquals(23345677L, ((Id) sdtblock.sdtPr.rPrOrAliasOrLock.get(0)).val.longValue()); + Assert.assertEquals("labelVal", ((SdtPr.Label) ((JAXBElement)sdtblock.sdtPr.rPrOrAliasOrLock.get(1)).getValue()).val); + Assert.assertEquals("aliasVal", ((SdtPr.Alias) ((JAXBElement)sdtblock.sdtPr.rPrOrAliasOrLock.get(2)).getValue()).val); + + + String res = XmlUtils.marshaltoString(document, true, false); + Assert.assertEquals(openXML, res); + } +} + diff --git a/docx4j-openxml-objects/src/main/java/org/docx4j/wml/ObjectFactory.java b/docx4j-openxml-objects/src/main/java/org/docx4j/wml/ObjectFactory.java index 0ddd417554..d53df431e9 100644 --- a/docx4j-openxml-objects/src/main/java/org/docx4j/wml/ObjectFactory.java +++ b/docx4j-openxml-objects/src/main/java/org/docx4j/wml/ObjectFactory.java @@ -144,6 +144,7 @@ public static ObjectFactory get() { private final static QName _CTTrPrBaseHidden_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "hidden"); private final static QName _SdtPrRPr_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "rPr"); private final static QName _SdtPrAlias_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "alias"); + private final static QName _SdtPrLabel_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "label"); private final static QName _SdtPrLock_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "lock"); private final static QName _SdtPrPlaceholder_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "placeholder"); private final static QName _SdtPrShowingPlcHdr_QNAME = new QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "showingPlcHdr"); @@ -5737,6 +5738,15 @@ public JAXBElement createSdtPrLock(CTLock value) { return new JAXBElement(_SdtPrLock_QNAME, CTLock.class, SdtPr.class, value); } + /** + * Create an instance of {@link JAXBElement }{@code <}{@link SdtPr.Label }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "label", scope = SdtPr.class) + public JAXBElement createSdtPrLabel(SdtPr.Label value) { + return new JAXBElement(_SdtPrLabel_QNAME, SdtPr.Label.class, SdtPr.class, value); + } + /** * Create an instance of {@link JAXBElement }{@code <}{@link CTPlaceholder }{@code >}} * diff --git a/docx4j-openxml-objects/src/main/java/org/docx4j/wml/SdtPr.java b/docx4j-openxml-objects/src/main/java/org/docx4j/wml/SdtPr.java index 1c3dc7ace3..ac9b830fc0 100644 --- a/docx4j-openxml-objects/src/main/java/org/docx4j/wml/SdtPr.java +++ b/docx4j-openxml-objects/src/main/java/org/docx4j/wml/SdtPr.java @@ -172,6 +172,7 @@ private static Object unwrap(Object o) { @XmlElementRef(name = "placeholder", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), @XmlElementRef(name = "dataBinding", namespace = "http://schemas.microsoft.com/office/word/2012/wordml", type = JAXBElement.class), @XmlElementRef(name = "alias", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), + @XmlElementRef(name = "label", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), @XmlElementRef(name = "checkbox", namespace = "http://schemas.microsoft.com/office/word/2010/wordml", type = JAXBElement.class), @XmlElementRef(name = "showingPlcHdr", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), @XmlElementRef(name = "webExtensionCreated", namespace = "http://schemas.microsoft.com/office/word/2012/wordml", type = JAXBElement.class), @@ -225,6 +226,7 @@ private static Object unwrap(Object o) { * {@link JAXBElement }{@code <}{@link CTPlaceholder }{@code >} * {@link JAXBElement }{@code <}{@link CTDataBinding }{@code >} * {@link JAXBElement }{@code <}{@link SdtPr.Alias }{@code >} + * {@link JAXBElement }{@code <}{@link SdtPr.Label }{@code >} * {@link JAXBElement }{@code <}{@link CTSdtCheckbox }{@code >} * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >} * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >} @@ -591,6 +593,87 @@ public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { } + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <complexContent>
+     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+     *       <attribute name="val" type="{http://www.w3.org/2001/XMLSchema}string" />
+     *     </restriction>
+     *   </complexContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "") + @XmlRootElement(name = "label") + public static class Label + implements Child + { + + @XmlAttribute(name = "val", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main") + protected String val; + @XmlTransient + private Object parent; + + /** + * Gets the value of the val property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getVal() { + return val; + } + + /** + * Sets the value of the val property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setVal(String value) { + this.val = value; + } + + /** + * Gets the parent object in the object tree representing the unmarshalled xml document. + * + * @return + * The parent object. + */ + public Object getParent() { + return this.parent; + } + + public void setParent(Object parent) { + this.parent = parent; + } + + /** + * This method is invoked by the JAXB implementation on each instance when unmarshalling completes. + * + * @param parent + * The parent object in the object tree. + * @param unmarshaller + * The unmarshaller that generated the instance. + */ + public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + setParent(parent); + } + + } + /** *

Java class for anonymous complex type. *