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 | 0 | 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 | 0 | @SuppressWarnings("unused") |
65 | |
@XmlAnyElement |
66 | |
private final Collection<Element> _futureElements = null; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | private DocumentContent() { |
73 | 0 | this.documentId = null; |
74 | 0 | this.applicationContent = null; |
75 | 0 | this.attributeContent = null; |
76 | 0 | this.searchableContent = null; |
77 | 0 | this.formatVersion = 0; |
78 | 0 | } |
79 | |
|
80 | 0 | private DocumentContent(Builder builder) { |
81 | 0 | this.documentId = builder.getDocumentId(); |
82 | 0 | this.applicationContent = builder.getApplicationContent(); |
83 | 0 | this.attributeContent = builder.getAttributeContent(); |
84 | 0 | this.searchableContent = builder.getSearchableContent(); |
85 | 0 | this.formatVersion = builder.getFormatVersion(); |
86 | 0 | } |
87 | |
|
88 | |
@Override |
89 | |
public String getDocumentId() { |
90 | 0 | return this.documentId; |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public String getApplicationContent() { |
95 | 0 | return this.applicationContent; |
96 | |
} |
97 | |
|
98 | |
@Override |
99 | |
public String getAttributeContent() { |
100 | 0 | return this.attributeContent; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public String getSearchableContent() { |
105 | 0 | return this.searchableContent; |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
public int getFormatVersion() { |
110 | 0 | return this.formatVersion; |
111 | |
} |
112 | |
|
113 | |
public String getFullContent() { |
114 | 0 | StringBuilder fullContent = new StringBuilder(); |
115 | 0 | fullContent.append("<").append(KewApiConstants.DOCUMENT_CONTENT_ELEMENT).append(">"); |
116 | 0 | if (!StringUtils.isBlank(getApplicationContent())) { |
117 | 0 | fullContent.append("<").append(KewApiConstants.APPLICATION_CONTENT_ELEMENT).append(">"); |
118 | 0 | fullContent.append(getApplicationContent()); |
119 | 0 | fullContent.append("</").append(KewApiConstants.APPLICATION_CONTENT_ELEMENT).append(">"); |
120 | |
} |
121 | 0 | fullContent.append(getAttributeContent()); |
122 | 0 | fullContent.append(getSearchableContent()); |
123 | 0 | fullContent.append("</").append(KewApiConstants.DOCUMENT_CONTENT_ELEMENT).append(">"); |
124 | 0 | return fullContent.toString(); |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | 0 | 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 | 0 | private Builder(String documentId) { |
141 | 0 | setDocumentId(documentId); |
142 | 0 | setFormatVersion(KewApiConstants.DocumentContentVersions.CURRENT); |
143 | 0 | } |
144 | |
|
145 | |
public static Builder create(String documentId) { |
146 | 0 | return new Builder(documentId); |
147 | |
} |
148 | |
|
149 | |
public static Builder create(DocumentContentContract contract) { |
150 | 0 | if (contract == null) { |
151 | 0 | throw new IllegalArgumentException("contract was null"); |
152 | |
} |
153 | 0 | Builder builder = create(contract.getDocumentId()); |
154 | 0 | builder.setApplicationContent(contract.getApplicationContent()); |
155 | 0 | builder.setAttributeContent(contract.getAttributeContent()); |
156 | 0 | builder.setSearchableContent(contract.getSearchableContent()); |
157 | 0 | builder.setFormatVersion(contract.getFormatVersion()); |
158 | 0 | return builder; |
159 | |
} |
160 | |
|
161 | |
public DocumentContent build() { |
162 | 0 | return new DocumentContent(this); |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public String getDocumentId() { |
167 | 0 | return this.documentId; |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public String getApplicationContent() { |
172 | 0 | return this.applicationContent; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public String getAttributeContent() { |
177 | 0 | return this.attributeContent; |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public String getSearchableContent() { |
182 | 0 | return this.searchableContent; |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public int getFormatVersion() { |
187 | 0 | return this.formatVersion; |
188 | |
} |
189 | |
|
190 | |
public void setDocumentId(String documentId) { |
191 | 0 | if (StringUtils.isBlank(documentId)) { |
192 | 0 | throw new IllegalArgumentException("documentId was null or blank"); |
193 | |
} |
194 | 0 | this.documentId = documentId; |
195 | 0 | } |
196 | |
|
197 | |
public void setApplicationContent(String applicationContent) { |
198 | 0 | this.applicationContent = applicationContent; |
199 | 0 | } |
200 | |
|
201 | |
public void setAttributeContent(String attributeContent) { |
202 | 0 | this.attributeContent = attributeContent; |
203 | 0 | } |
204 | |
|
205 | |
public void setSearchableContent(String searchableContent) { |
206 | 0 | this.searchableContent = searchableContent; |
207 | 0 | } |
208 | |
|
209 | |
public void setFormatVersion(int formatVersion) { |
210 | 0 | if (formatVersion < 0) { |
211 | 0 | throw new IllegalArgumentException("formatVersion must be a valid version, was " + formatVersion); |
212 | |
} |
213 | 0 | this.formatVersion = formatVersion; |
214 | 0 | } |
215 | |
|
216 | |
} |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | 0 | 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 | 0 | 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 | |
|