01: /*
02: * Created on 11 Sep 2007
03: */
04: package uk.org.ponder.rsf.view.support;
05:
06: import uk.org.ponder.rsf.content.ContentTypeResolver;
07: import uk.org.ponder.rsf.view.ViewGroup;
08: import uk.org.ponder.rsf.viewstate.ViewParameters;
09:
10: /** The service for matching a ViewGroup predicate against a particular
11: * ViewParameters.
12: *
13: * @author Antranig Basman (antranig@caret.cam.ac.uk)
14: */
15:
16: public class ViewGroupResolver {
17: private ContentTypeResolver contentTypeResolver;
18:
19: public void setContentTypeResolver(
20: ContentTypeResolver contentTypeResolver) {
21: this .contentTypeResolver = contentTypeResolver;
22: }
23:
24: public boolean isMatch(ViewGroup group, ViewParameters viewparams) {
25: ParsedPredicate parsedcont = ParsedPredicate.parse(group
26: .getContentTypeSpec());
27: ParsedPredicate parsedview = ParsedPredicate.parse(group
28: .getViewList());
29:
30: if (!(applyFilter(parsedview, viewparams.viewID)))
31: return false;
32:
33: String contenttype = contentTypeResolver
34: .resolveContentType(viewparams);
35: if (!(applyFilter(parsedcont, contenttype)))
36: return false;
37:
38: return true;
39: }
40:
41: private boolean applyFilter(ParsedPredicate predicate, String match) {
42: if (predicate.elements != null && predicate.elements.length > 0) {
43: for (int i = 0; i < predicate.elements.length; ++i) {
44: if (!(predicate.elements[i].equals(match) ^ predicate.positive))
45: return true;
46: }
47: return false;
48: }
49: return true;
50: }
51:
52: }
|