01: /*
02: * Created on Nov 14, 2005
03: */
04: package uk.org.ponder.rsf.viewstate.support;
05:
06: import java.util.Map;
07:
08: import uk.org.ponder.rsf.viewstate.RawURLState;
09: import uk.org.ponder.rsf.viewstate.ViewIDInferrer;
10: import uk.org.ponder.rsf.viewstate.ViewParamUtil;
11: import uk.org.ponder.rsf.viewstate.ViewParameters;
12: import uk.org.ponder.rsf.viewstate.ViewParametersParser;
13: import uk.org.ponder.rsf.viewstate.ViewParamsCodec;
14: import uk.org.ponder.util.Logger;
15:
16: /**
17: * A simple parser of view parameters, which will parse into clones of supplied
18: * "exemplar" objects. The lookup will be performed on the first segment of the
19: * pathinfo (up to first slash), which will be assumed to represent the viewID.
20: * An application scope bean.
21: *
22: * @author Antranig Basman (antranig@caret.cam.ac.uk)
23: */
24: // Really has two functions, that of VPP and also of the basic default
25: // view discoverer, since we have not made the effort to factor off
26: // ViewParamsReceiver
27: public class BasicViewParametersParser implements ViewParametersParser {
28: private ViewParamsCodec vpcodec;
29: private ViewIDInferrer viewIDInferrer;
30:
31: private ViewParamsRegistryImpl defaultViewInfoReceiver;
32: private boolean implicitNullRedirect;
33: private ViewParameters defaultViewParams;
34:
35: public void setDefaultViewInfoReceiver(
36: ViewParamsRegistryImpl defaultViewInfoReceiver) {
37: this .defaultViewInfoReceiver = defaultViewInfoReceiver;
38: }
39:
40: public void setViewParamsCodec(ViewParamsCodec vpcodec) {
41: this .vpcodec = vpcodec;
42: }
43:
44: public void setViewIDInferrer(ViewIDInferrer viewIDInferrer) {
45: this .viewIDInferrer = viewIDInferrer;
46: }
47:
48: public void setImplicitNullRedirect(boolean implicitNullRedirect) {
49: this .implicitNullRedirect = implicitNullRedirect;
50: }
51:
52: public void setDefaultViewParams(ViewParameters defaultViewParams) {
53: this .defaultViewParams = defaultViewParams;
54: }
55:
56: public ViewParameters parse(String pathinfo, Map requestmap) {
57: return parse(pathinfo, requestmap, false);
58: }
59:
60: public ViewParameters parse(String pathinfo, Map requestmap,
61: boolean intercept) {
62: // JSF memorial comment:
63: // restoreView is the very first of the ViewHandler methods to be called for
64: // each request, and it is guaranteed to be called. We take this opportunity
65: // to stash away a parsed parameter object corresponding to our original
66: // request.
67: if (implicitNullRedirect
68: && (pathinfo.equals("") || pathinfo.equals("/"))) {
69: return (ViewParameters) defaultViewParams.get().copy();
70: } else {
71: String viewID = viewIDInferrer.inferViewID(pathinfo,
72: requestmap);
73: ViewParameters origrequest = defaultViewInfoReceiver
74: .getViewParamsExemplar(viewID);
75:
76: vpcodec.parseViewParams(origrequest, new RawURLState(
77: requestmap, pathinfo), null);
78:
79: // this may *disagree* with value forced in by parsePathInfo due to VII
80: origrequest.viewID = viewID;
81: // Map requestmap = req.
82: // requestmap.put(ViewParameters.CURRENT_REQUEST, origrequest);
83: if (Logger.log.isDebugEnabled()) {
84: Logger.log.debug("Parsed view "
85: + origrequest.viewID
86: + " from request parameters "
87: + ViewParamUtil.toHTTPRequest(vpcodec,
88: origrequest));
89: }
90: return origrequest;
91: }
92:
93: }
94:
95: }
|