1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.document;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAnyElement;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlType;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.kuali.rice.core.api.CoreConstants;
30 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31 import org.kuali.rice.core.api.mo.ModelBuilder;
32 import org.kuali.rice.kew.api.KewApiConstants;
33 import org.w3c.dom.Element;
34
35 @XmlRootElement(name = DocumentContent.Constants.ROOT_ELEMENT_NAME)
36 @XmlAccessorType(XmlAccessType.NONE)
37 @XmlType(name = DocumentContent.Constants.TYPE_NAME, propOrder = {
38 DocumentContent.Elements.DOCUMENT_ID,
39 DocumentContent.Elements.APPLICATION_CONTENT,
40 DocumentContent.Elements.ATTRIBUTE_CONTENT,
41 DocumentContent.Elements.SEARCHABLE_CONTENT,
42 DocumentContent.Elements.FORMAT_VERSION,
43 CoreConstants.CommonElements.FUTURE_ELEMENTS
44 })
45 public final class DocumentContent extends AbstractDataTransferObject implements DocumentContentContract {
46
47 private static final long serialVersionUID = 6110079520547685342L;
48
49 @XmlElement(name = Elements.DOCUMENT_ID, required = true)
50 private final String documentId;
51
52 @XmlElement(name = Elements.APPLICATION_CONTENT, required = false)
53 private final String applicationContent;
54
55 @XmlElement(name = Elements.ATTRIBUTE_CONTENT, required = false)
56 private final String attributeContent;
57
58 @XmlElement(name = Elements.SEARCHABLE_CONTENT, required = false)
59 private final String searchableContent;
60
61 @XmlElement(name = Elements.FORMAT_VERSION, required = true)
62 private final int formatVersion;
63
64 @SuppressWarnings("unused")
65 @XmlAnyElement
66 private final Collection<Element> _futureElements = null;
67
68
69
70
71
72 private DocumentContent() {
73 this.documentId = null;
74 this.applicationContent = null;
75 this.attributeContent = null;
76 this.searchableContent = null;
77 this.formatVersion = 0;
78 }
79
80 private DocumentContent(Builder builder) {
81 this.documentId = builder.getDocumentId();
82 this.applicationContent = builder.getApplicationContent();
83 this.attributeContent = builder.getAttributeContent();
84 this.searchableContent = builder.getSearchableContent();
85 this.formatVersion = builder.getFormatVersion();
86 }
87
88 @Override
89 public String getDocumentId() {
90 return this.documentId;
91 }
92
93 @Override
94 public String getApplicationContent() {
95 return this.applicationContent;
96 }
97
98 @Override
99 public String getAttributeContent() {
100 return this.attributeContent;
101 }
102
103 @Override
104 public String getSearchableContent() {
105 return this.searchableContent;
106 }
107
108 @Override
109 public int getFormatVersion() {
110 return this.formatVersion;
111 }
112
113 public String getFullContent() {
114 StringBuilder fullContent = new StringBuilder();
115 fullContent.append("<").append(KewApiConstants.DOCUMENT_CONTENT_ELEMENT).append(">");
116 if (!StringUtils.isBlank(getApplicationContent())) {
117 fullContent.append("<").append(KewApiConstants.APPLICATION_CONTENT_ELEMENT).append(">");
118 fullContent.append(getApplicationContent());
119 fullContent.append("</").append(KewApiConstants.APPLICATION_CONTENT_ELEMENT).append(">");
120 }
121 fullContent.append(getAttributeContent());
122 fullContent.append(getSearchableContent());
123 fullContent.append("</").append(KewApiConstants.DOCUMENT_CONTENT_ELEMENT).append(">");
124 return fullContent.toString();
125 }
126
127
128
129
130 public final static class Builder implements Serializable, ModelBuilder, DocumentContentContract {
131
132 private static final long serialVersionUID = 7549637048594326790L;
133
134 private String documentId;
135 private String applicationContent;
136 private String attributeContent;
137 private String searchableContent;
138 private int formatVersion;
139
140 private Builder(String documentId) {
141 setDocumentId(documentId);
142 setFormatVersion(KewApiConstants.DocumentContentVersions.CURRENT);
143 }
144
145 public static Builder create(String documentId) {
146 return new Builder(documentId);
147 }
148
149 public static Builder create(DocumentContentContract contract) {
150 if (contract == null) {
151 throw new IllegalArgumentException("contract was null");
152 }
153 Builder builder = create(contract.getDocumentId());
154 builder.setApplicationContent(contract.getApplicationContent());
155 builder.setAttributeContent(contract.getAttributeContent());
156 builder.setSearchableContent(contract.getSearchableContent());
157 builder.setFormatVersion(contract.getFormatVersion());
158 return builder;
159 }
160
161 public DocumentContent build() {
162 return new DocumentContent(this);
163 }
164
165 @Override
166 public String getDocumentId() {
167 return this.documentId;
168 }
169
170 @Override
171 public String getApplicationContent() {
172 return this.applicationContent;
173 }
174
175 @Override
176 public String getAttributeContent() {
177 return this.attributeContent;
178 }
179
180 @Override
181 public String getSearchableContent() {
182 return this.searchableContent;
183 }
184
185 @Override
186 public int getFormatVersion() {
187 return this.formatVersion;
188 }
189
190 public void setDocumentId(String documentId) {
191 if (StringUtils.isBlank(documentId)) {
192 throw new IllegalArgumentException("documentId was null or blank");
193 }
194 this.documentId = documentId;
195 }
196
197 public void setApplicationContent(String applicationContent) {
198 this.applicationContent = applicationContent;
199 }
200
201 public void setAttributeContent(String attributeContent) {
202 this.attributeContent = attributeContent;
203 }
204
205 public void setSearchableContent(String searchableContent) {
206 this.searchableContent = searchableContent;
207 }
208
209 public void setFormatVersion(int formatVersion) {
210 if (formatVersion < 0) {
211 throw new IllegalArgumentException("formatVersion must be a valid version, was " + formatVersion);
212 }
213 this.formatVersion = formatVersion;
214 }
215
216 }
217
218
219
220
221 static class Constants {
222
223 final static String ROOT_ELEMENT_NAME = "documentContent";
224 final static String TYPE_NAME = "DocumentContentType";
225 }
226
227
228
229
230 static class Elements {
231
232 final static String DOCUMENT_ID = "documentId";
233 final static String APPLICATION_CONTENT = "applicationContent";
234 final static String ATTRIBUTE_CONTENT = "attributeContent";
235 final static String SEARCHABLE_CONTENT = "searchableContent";
236 final static String FORMAT_VERSION = "formatVersion";
237
238 }
239
240 }
241