1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.portlet; |
16 |
| |
17 |
| import javax.portlet.PortletRequest; |
18 |
| |
19 |
| import org.apache.hivemind.impl.BaseLocatable; |
20 |
| import org.apache.hivemind.util.Defense; |
21 |
| import org.apache.hivemind.util.ToStringBuilder; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| public class PageResolverContribution extends BaseLocatable implements Comparable |
30 |
| { |
31 |
| private String _portletMode; |
32 |
| |
33 |
| private String _windowState; |
34 |
| |
35 |
| private String _mimeType; |
36 |
| |
37 |
| private String _pageName; |
38 |
| |
39 |
7
| public void setMimeType(String mimeType)
|
40 |
| { |
41 |
7
| _mimeType = mimeType;
|
42 |
| } |
43 |
| |
44 |
7
| public void setPageName(String pageName)
|
45 |
| { |
46 |
7
| _pageName = pageName;
|
47 |
| } |
48 |
| |
49 |
3
| public String getPageName()
|
50 |
| { |
51 |
3
| return _pageName;
|
52 |
| } |
53 |
| |
54 |
7
| public void setPortletMode(String portletMode)
|
55 |
| { |
56 |
7
| _portletMode = portletMode;
|
57 |
| } |
58 |
| |
59 |
7
| public void setWindowState(String windowState)
|
60 |
| { |
61 |
7
| _windowState = windowState;
|
62 |
| } |
63 |
| |
64 |
4
| int sortScore()
|
65 |
| { |
66 |
4
| int result = 0;
|
67 |
| |
68 |
4
| if (_mimeType != null)
|
69 |
0
| result += 4;
|
70 |
| |
71 |
4
| if (_portletMode != null)
|
72 |
4
| result += 2;
|
73 |
| |
74 |
4
| if (_windowState != null)
|
75 |
2
| result += 1;
|
76 |
| |
77 |
4
| return result;
|
78 |
| } |
79 |
| |
80 |
0
| public String toString()
|
81 |
| { |
82 |
0
| ToStringBuilder builder = new ToStringBuilder(this);
|
83 |
| |
84 |
0
| builder.append("mimeType", _mimeType);
|
85 |
0
| builder.append("portletMode", _portletMode);
|
86 |
0
| builder.append("windowState", _windowState);
|
87 |
0
| builder.append("pageName", _pageName);
|
88 |
| |
89 |
0
| return builder.toString();
|
90 |
| } |
91 |
| |
92 |
2
| public int compareTo(Object o)
|
93 |
| { |
94 |
2
| int thisScore = sortScore();
|
95 |
2
| int otherScore = ((PageResolverContribution) o).sortScore();
|
96 |
| |
97 |
| |
98 |
| |
99 |
2
| return otherScore - thisScore;
|
100 |
| } |
101 |
| |
102 |
6
| public boolean match(PortletRequest request)
|
103 |
| { |
104 |
6
| Defense.notNull(request, "request");
|
105 |
| |
106 |
6
| if (_mimeType != null && !_mimeType.equals(request.getResponseContentType()))
|
107 |
1
| return false;
|
108 |
| |
109 |
5
| if (_portletMode != null && !_portletMode.equals(request.getPortletMode().toString()))
|
110 |
1
| return false;
|
111 |
| |
112 |
4
| if (_windowState != null && !_windowState.equals(request.getWindowState().toString()))
|
113 |
1
| return false;
|
114 |
| |
115 |
3
| return true;
|
116 |
| } |
117 |
| } |