comparison artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java @ 5975:95b9e40bbad0

Add handling for OUT id's parameter to D4EArtifact Patch mostly provided by Sascha Teichmann
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 10 May 2013 15:16:36 +0200
parents 59ff03ff48f1
children af13ceeba52a
comparison
equal deleted inserted replaced
5974:95cb104a871b 5975:95b9e40bbad0
15 import java.util.LinkedList; 15 import java.util.LinkedList;
16 import java.util.List; 16 import java.util.List;
17 import java.util.Map; 17 import java.util.Map;
18 import java.util.Set; 18 import java.util.Set;
19 import java.util.TreeMap; 19 import java.util.TreeMap;
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
20 22
21 import javax.xml.xpath.XPathConstants; 23 import javax.xml.xpath.XPathConstants;
22 24
23 import net.sf.ehcache.Cache; 25 import net.sf.ehcache.Cache;
24 26
82 "/art:action/art:template/@uuid"; 84 "/art:action/art:template/@uuid";
83 85
84 public static final String XPATH_FILTER = 86 public static final String XPATH_FILTER =
85 "/art:action/art:filter/art:out"; 87 "/art:action/art:filter/art:out";
86 88
89 public static final Pattern CONTAINS_OUT =
90 Pattern.compile( "^(.*):OUT=(.+)$");
91
92 /** Path to 'ids' (data) in doc that comes from datacage. */
93 public static final String XPATH_IDS = "/art:action/art:ids/@value";
94
95
87 /** The constant string that shows that an operation was successful. */ 96 /** The constant string that shows that an operation was successful. */
88 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; 97 public static final String OPERATION_SUCCESSFUL = "SUCCESS";
89 98
90 /** The constant string that shows that an operation failed. */ 99 /** The constant string that shows that an operation failed. */
91 public static final String OPERATION_FAILED = "FAILURE"; 100 public static final String OPERATION_FAILED = "FAILURE";
108 /** 117 /**
109 * Used to generates "view" on the facets (hides facets not matching the 118 * Used to generates "view" on the facets (hides facets not matching the
110 * filter in output of collection); out -&gt; facets. 119 * filter in output of collection); out -&gt; facets.
111 */ 120 */
112 protected Map<String, List<Facet>> filterFacets; 121 protected Map<String, List<Facet>> filterFacets;
122
123 protected String boundToOut;
113 124
114 125
115 /** 126 /**
116 * The default constructor that creates an empty D4EArtifact. 127 * The default constructor that creates an empty D4EArtifact.
117 */ 128 */
223 log.error(adbe, adbe); 234 log.error(adbe, adbe);
224 } 235 }
225 } 236 }
226 237
227 filterFacets = buildFilterFacets(data); 238 filterFacets = buildFilterFacets(data);
228 } 239
240 extractOut(data);
241 }
242
243 protected void extractOut(Document data) {
244 log.debug("extractOut");
245 String ids = XMLUtils.xpathString(data, XPATH_IDS,
246 ArtifactNamespaceContext.INSTANCE);
247
248 log.debug("ids: '" + ids + "'");
249 if (ids != null) {
250 Matcher m = CONTAINS_OUT.matcher(ids);
251 if (m.matches()) {
252 boundToOut = m.group(2);
253 log.debug("Bound to out :'" + boundToOut + "'");
254 }
255 else {
256 log.debug("does not match");
257 }
258 }
259 }
260
261 /**
262 * Return the value of id element in Datacage data document.
263 * @param data Document as passed by datacage.
264 * @return the id element value of data document.
265 */
266 public static String getDatacageIDValue(Document data) {
267
268 String ids = XMLUtils.xpathString(data, XPATH_IDS,
269 ArtifactNamespaceContext.INSTANCE);
270
271 if (ids != null) {
272 Matcher m = CONTAINS_OUT.matcher(ids);
273 if (m.matches()) {
274 ids = m.group(1);
275 }
276 }
277
278 return ids;
279 }
280
229 281
230 282
231 /** Get copy of previous state ids as Strings in list. */ 283 /** Get copy of previous state ids as Strings in list. */
232 protected List<String> clonePreviousStateIds() { 284 protected List<String> clonePreviousStateIds() {
233 return new ArrayList<String>(previousStateIds); 285 return new ArrayList<String>(previousStateIds);
1566 * @return List of Facets belonging to the state identifier 1618 * @return List of Facets belonging to the state identifier
1567 */ 1619 */
1568 protected List<Facet> getFacets(String stateid) { 1620 protected List<Facet> getFacets(String stateid) {
1569 return this.facets.get(stateid); 1621 return this.facets.get(stateid);
1570 } 1622 }
1623
1624 public String getBoundToOut() {
1625 return boundToOut;
1626 }
1571 } 1627 }
1572 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 1628 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org