01: /*
02: * Created on 11 Jul 2006
03: */
04: package uk.org.ponder.rsf.viewstate.support;
05:
06: import java.util.Map;
07:
08: import uk.org.ponder.rsf.viewstate.StaticViewIDInferrer;
09: import uk.org.ponder.rsf.viewstate.ViewParamUtil;
10: import uk.org.ponder.rsf.viewstate.ViewParameters;
11: import uk.org.ponder.stringutil.StringUtil;
12:
13: /** The RSF default ViewIDInferrer which adopts a fixed strategy of inferring
14: * the View ID from a request environment.
15: * @author Antranig Basman (antranig@caret.cam.ac.uk)
16: *
17: */
18: // TODO: this should ultimately connect up with ViewParamsMapInfo for some kind
19: // of global inference strategy.
20: public class BasicViewIDInferrer implements StaticViewIDInferrer {
21:
22: private String viewIDspec = "@0";
23:
24: public String inferViewID(String pathinfo, Map requestmap) {
25: if (viewIDspec.startsWith(ViewParameters.TRUNK_PARSE_PREFIX)) {
26: int index = Integer.parseInt(viewIDspec
27: .substring(ViewParameters.TRUNK_PARSE_PREFIX
28: .length()));
29: Object high0 = requestmap.get(ViewParamUtil.getAttrIndex(
30: index, true));
31: if (high0 != null) {
32: return high0 instanceof String ? (String) high0
33: : ((String[]) high0)[0];
34: }
35: String[] segments = StringUtil.split(pathinfo, '/', false);
36: boolean slash0 = pathinfo.charAt(0) == '/';
37: return segments[index + (slash0 ? 1 : 0)];
38: } else {
39: Object attr = requestmap.get(viewIDspec);
40: return attr instanceof String ? (String) attr
41: : ((String[]) attr)[0];
42: }
43: }
44:
45: public String getViewIDSpec() {
46: return viewIDspec;
47: }
48:
49: public void setViewIDSpec(String viewIDspec) {
50: this.viewIDspec = viewIDspec;
51: }
52:
53: }
|