| 1 | /* |
|---|
| 2 | * Copyright 2007-2008, Plutext Pty Ltd. |
|---|
| 3 | * |
|---|
| 4 | * This file is part of docx4j. |
|---|
| 5 | |
|---|
| 6 | docx4j is licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 7 | you may not use this file except in compliance with the License. |
|---|
| 8 | |
|---|
| 9 | You may obtain a copy of the License at |
|---|
| 10 | |
|---|
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 12 | |
|---|
| 13 | Unless required by applicable law or agreed to in writing, software |
|---|
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 16 | See the License for the specific language governing permissions and |
|---|
| 17 | limitations under the License. |
|---|
| 18 | |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | package org.docx4j.wml; |
|---|
| 22 | |
|---|
| 23 | import java.util.ArrayList; |
|---|
| 24 | import java.util.List; |
|---|
| 25 | import javax.xml.bind.JAXBElement; |
|---|
| 26 | import javax.xml.bind.Unmarshaller; |
|---|
| 27 | import javax.xml.bind.annotation.XmlAccessType; |
|---|
| 28 | import javax.xml.bind.annotation.XmlAccessorType; |
|---|
| 29 | import javax.xml.bind.annotation.XmlElementRef; |
|---|
| 30 | import javax.xml.bind.annotation.XmlElementRefs; |
|---|
| 31 | import javax.xml.bind.annotation.XmlRootElement; |
|---|
| 32 | import javax.xml.bind.annotation.XmlTransient; |
|---|
| 33 | import javax.xml.bind.annotation.XmlType; |
|---|
| 34 | import org.docx4j.math.CTOMath; |
|---|
| 35 | import org.docx4j.math.CTOMathPara; |
|---|
| 36 | import org.apache.log4j.Logger; |
|---|
| 37 | import org.jvnet.jaxb2_commons.ppp.Child; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * <p>Java class for CT_SdtContentBlock complex type. |
|---|
| 42 | * |
|---|
| 43 | * <p>The following schema fragment specifies the expected content contained within this class. |
|---|
| 44 | * |
|---|
| 45 | * <pre> |
|---|
| 46 | * <complexType name="CT_SdtContentBlock"> |
|---|
| 47 | * <complexContent> |
|---|
| 48 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> |
|---|
| 49 | * <group ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}EG_ContentBlockContent" maxOccurs="unbounded" minOccurs="0"/> |
|---|
| 50 | * </restriction> |
|---|
| 51 | * </complexContent> |
|---|
| 52 | * </complexType> |
|---|
| 53 | * </pre> |
|---|
| 54 | * |
|---|
| 55 | * |
|---|
| 56 | */ |
|---|
| 57 | @XmlAccessorType(XmlAccessType.FIELD) |
|---|
| 58 | @XmlType(name = "CT_SdtContentBlock", propOrder = { |
|---|
| 59 | "egContentBlockContent" |
|---|
| 60 | }) |
|---|
| 61 | @XmlRootElement(name = "sdtContent") |
|---|
| 62 | public class SdtContentBlock |
|---|
| 63 | implements Child, ContentAccessor |
|---|
| 64 | { |
|---|
| 65 | private static Logger log = Logger.getLogger(SdtContentBlock.class); |
|---|
| 66 | |
|---|
| 67 | @XmlElementRefs({ |
|---|
| 68 | @XmlElementRef(name = "customXmlMoveToRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 69 | @XmlElementRef(name = "commentRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = CommentRangeStart.class), |
|---|
| 70 | @XmlElementRef(name = "moveTo", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 71 | @XmlElementRef(name = "ins", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = RunIns.class), |
|---|
| 72 | @XmlElementRef(name = "p", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = P.class), |
|---|
| 73 | @XmlElementRef(name = "oMath", namespace = "http://schemas.openxmlformats.org/officeDocument/2006/math", type = JAXBElement.class), |
|---|
| 74 | @XmlElementRef(name = "customXmlInsRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 75 | @XmlElementRef(name = "bookmarkStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 76 | @XmlElementRef(name = "bookmarkEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 77 | @XmlElementRef(name = "moveFrom", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 78 | @XmlElementRef(name = "sdt", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = SdtBlock.class), |
|---|
| 79 | @XmlElementRef(name = "customXmlMoveToRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 80 | @XmlElementRef(name = "permStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 81 | @XmlElementRef(name = "customXmlMoveFromRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 82 | @XmlElementRef(name = "commentRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = CommentRangeEnd.class), |
|---|
| 83 | @XmlElementRef(name = "customXmlInsRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 84 | @XmlElementRef(name = "permEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 85 | @XmlElementRef(name = "customXmlDelRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 86 | @XmlElementRef(name = "moveFromRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 87 | @XmlElementRef(name = "proofErr", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = ProofErr.class), |
|---|
| 88 | @XmlElementRef(name = "customXmlDelRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 89 | @XmlElementRef(name = "del", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = RunDel.class), |
|---|
| 90 | @XmlElementRef(name = "moveFromRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 91 | @XmlElementRef(name = "oMathPara", namespace = "http://schemas.openxmlformats.org/officeDocument/2006/math", type = JAXBElement.class), |
|---|
| 92 | @XmlElementRef(name = "moveToRangeEnd", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 93 | @XmlElementRef(name = "tbl", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 94 | @XmlElementRef(name = "moveToRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 95 | @XmlElementRef(name = "customXmlMoveFromRangeStart", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class), |
|---|
| 96 | @XmlElementRef(name = "customXml", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class) |
|---|
| 97 | }) |
|---|
| 98 | protected List<Object> egContentBlockContent; |
|---|
| 99 | @XmlTransient |
|---|
| 100 | private Object parent; |
|---|
| 101 | |
|---|
| 102 | /** |
|---|
| 103 | * Gets the value of the egContentBlockContent property. |
|---|
| 104 | * |
|---|
| 105 | * <p> |
|---|
| 106 | * This accessor method returns a reference to the live list, |
|---|
| 107 | * not a snapshot. Therefore any modification you make to the |
|---|
| 108 | * returned list will be present inside the JAXB object. |
|---|
| 109 | * This is why there is not a <CODE>set</CODE> method for the egContentBlockContent property. |
|---|
| 110 | * |
|---|
| 111 | * <p> |
|---|
| 112 | * For example, to add a new item, do as follows: |
|---|
| 113 | * <pre> |
|---|
| 114 | * getEGContentBlockContent().add(newItem); |
|---|
| 115 | * </pre> |
|---|
| 116 | * |
|---|
| 117 | * |
|---|
| 118 | * <p> |
|---|
| 119 | * Objects of the following type(s) are allowed in the list |
|---|
| 120 | * {@link JAXBElement }{@code <}{@link CTTrackChange }{@code >} |
|---|
| 121 | * {@link CommentRangeStart } |
|---|
| 122 | * {@link JAXBElement }{@code <}{@link RunTrackChange }{@code >} |
|---|
| 123 | * {@link RunIns } |
|---|
| 124 | * {@link P } |
|---|
| 125 | * {@link JAXBElement }{@code <}{@link CTOMath }{@code >} |
|---|
| 126 | * {@link JAXBElement }{@code <}{@link CTMarkup }{@code >} |
|---|
| 127 | * {@link JAXBElement }{@code <}{@link CTBookmark }{@code >} |
|---|
| 128 | * {@link JAXBElement }{@code <}{@link CTMarkupRange }{@code >} |
|---|
| 129 | * {@link JAXBElement }{@code <}{@link RunTrackChange }{@code >} |
|---|
| 130 | * {@link SdtBlock } |
|---|
| 131 | * {@link JAXBElement }{@code <}{@link CTMarkup }{@code >} |
|---|
| 132 | * {@link JAXBElement }{@code <}{@link RangePermissionStart }{@code >} |
|---|
| 133 | * {@link JAXBElement }{@code <}{@link CTMarkup }{@code >} |
|---|
| 134 | * {@link CommentRangeEnd } |
|---|
| 135 | * {@link JAXBElement }{@code <}{@link CTTrackChange }{@code >} |
|---|
| 136 | * {@link JAXBElement }{@code <}{@link CTPerm }{@code >} |
|---|
| 137 | * {@link JAXBElement }{@code <}{@link CTTrackChange }{@code >} |
|---|
| 138 | * {@link JAXBElement }{@code <}{@link CTMoveBookmark }{@code >} |
|---|
| 139 | * {@link ProofErr } |
|---|
| 140 | * {@link JAXBElement }{@code <}{@link CTMarkup }{@code >} |
|---|
| 141 | * {@link RunDel } |
|---|
| 142 | * {@link JAXBElement }{@code <}{@link CTMarkupRange }{@code >} |
|---|
| 143 | * {@link JAXBElement }{@code <}{@link CTOMathPara }{@code >} |
|---|
| 144 | * {@link JAXBElement }{@code <}{@link CTMarkupRange }{@code >} |
|---|
| 145 | * {@link JAXBElement }{@code <}{@link CTTrackChange }{@code >} |
|---|
| 146 | * {@link JAXBElement }{@code <}{@link CTMoveBookmark }{@code >} |
|---|
| 147 | * {@link JAXBElement }{@code <}{@link Tbl }{@code >} |
|---|
| 148 | * {@link JAXBElement }{@code <}{@link CTCustomXmlBlock }{@code >} |
|---|
| 149 | * |
|---|
| 150 | * |
|---|
| 151 | */ |
|---|
| 152 | @Deprecated |
|---|
| 153 | public List<Object> getEGContentBlockContent() { |
|---|
| 154 | if (egContentBlockContent == null) { |
|---|
| 155 | egContentBlockContent = new ArrayList<Object>(); |
|---|
| 156 | } |
|---|
| 157 | return this.egContentBlockContent; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /** |
|---|
| 161 | * Get the content of this element. |
|---|
| 162 | * @since 2.7 |
|---|
| 163 | */ |
|---|
| 164 | public List<Object> getContent() { |
|---|
| 165 | if (egContentBlockContent == null) { |
|---|
| 166 | egContentBlockContent = new ArrayList<Object>(); |
|---|
| 167 | } |
|---|
| 168 | return this.egContentBlockContent; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | * Gets the parent object in the object tree representing the unmarshalled xml document. |
|---|
| 173 | * |
|---|
| 174 | * @return |
|---|
| 175 | * The parent object. |
|---|
| 176 | */ |
|---|
| 177 | public Object getParent() { |
|---|
| 178 | return this.parent; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | public void setParent(Object parent) { |
|---|
| 182 | this.parent = parent; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | * This method is invoked by the JAXB implementation on each instance when unmarshalling completes. |
|---|
| 187 | * |
|---|
| 188 | * @param parent |
|---|
| 189 | * The parent object in the object tree. |
|---|
| 190 | * @param unmarshaller |
|---|
| 191 | * The unmarshaller that generated the instance. |
|---|
| 192 | */ |
|---|
| 193 | public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { |
|---|
| 194 | setParent(parent); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | public void replaceElement(Object current, List insertions) { |
|---|
| 198 | |
|---|
| 199 | int index = egContentBlockContent.indexOf(current); |
|---|
| 200 | if (index > -1 ) { |
|---|
| 201 | egContentBlockContent.addAll(index+1, insertions); |
|---|
| 202 | Object removed = egContentBlockContent.remove(index); |
|---|
| 203 | // sanity check |
|---|
| 204 | if (!current.equals(removed)) { |
|---|
| 205 | log.error("removed wrong object?"); |
|---|
| 206 | } |
|---|
| 207 | } else { |
|---|
| 208 | // Not found |
|---|
| 209 | log.error("Couldn't find replacement target."); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | /* |
|---|
| 213 | List<Object> newList = new ArrayList<Object>(); |
|---|
| 214 | |
|---|
| 215 | for (Object o : getBlockLevelElements() ) { |
|---|
| 216 | |
|---|
| 217 | if (o.equals(current)) { |
|---|
| 218 | log.debug(".. found target "); |
|---|
| 219 | for (Object o2 : insertions ) { |
|---|
| 220 | newList.add(o2); |
|---|
| 221 | log.debug(".. .. inserted "); |
|---|
| 222 | } |
|---|
| 223 | } else { |
|---|
| 224 | newList.add(o); |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | blockLevelElements = newList; |
|---|
| 229 | */ |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | } |
|---|