KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > MatchingPortletPageResolver


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.portlet;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.portlet.PortletRequest;
23
24 import org.apache.tapestry.IRequestCycle;
25 import org.apache.tapestry.PageNotFoundException;
26
27 /**
28  * Uses the tapestry.portlet.resolver.PageResolverRules configuration point to find a match.
29  *
30  * @author Howard M. Lewis Ship
31  * @since 4.0
32  */

33 public class MatchingPortletPageResolver implements PortletPageResolver
34 {
35     private List JavaDoc _contributions;
36
37     private List JavaDoc _sortedContributions;
38
39     private PortletRequest _request;
40
41     public void initializeService()
42     {
43         _sortedContributions = new ArrayList JavaDoc(_contributions);
44         Collections.sort(_sortedContributions);
45     }
46
47     public String JavaDoc getPageNameForRequest(IRequestCycle cycle)
48     {
49         Iterator JavaDoc i = _sortedContributions.iterator();
50         while (i.hasNext())
51         {
52             PageResolverContribution c = (PageResolverContribution) i.next();
53
54             if (c.match(_request))
55             {
56                 String JavaDoc pageName = c.getPageName();
57
58                 try
59                 {
60                     cycle.getPage(pageName);
61
62                     return pageName;
63                 }
64                 catch (PageNotFoundException ex)
65                 {
66                     // Ignore.
67
}
68             }
69         }
70
71         // No match, or no matches where the page actually exists.
72

73         return null;
74     }
75
76     public void setContributions(List JavaDoc contributions)
77     {
78         _contributions = contributions;
79     }
80
81     public void setRequest(PortletRequest request)
82     {
83         _request = request;
84     }
85
86 }
87
Popular Tags