1 | /* |
2 | * Copyright 2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.apache.pluto.driver.services.portal; |
17 | |
18 | import org.apache.commons.logging.Log; |
19 | import org.apache.commons.logging.LogFactory; |
20 | import org.apache.pluto.driver.services.portal.PageConfig; |
21 | |
22 | import java.util.*; |
23 | |
24 | /** |
25 | * @author <a href="ddewolf@apache.org">David H. DeWolf</a> |
26 | */ |
27 | public class RenderConfig { |
28 | private static final Log LOG = |
29 | LogFactory.getLog(RenderConfig.class); |
30 | |
31 | private Map pages; |
32 | private String defaultPageId; |
33 | |
34 | // internally used. |
35 | private int orderNumberCounter = 0; |
36 | private Comparator pageComparator; |
37 | |
38 | public RenderConfig() { |
39 | this.pages = new java.util.HashMap(); |
40 | this.pageComparator = new Comparator() { |
41 | public int compare(Object a, Object b) { |
42 | PageConfig pa = (PageConfig)a; |
43 | PageConfig pb = (PageConfig)b; |
44 | if(pa.getOrderNumber() > pb.getOrderNumber()) { |
45 | return 1; |
46 | } |
47 | else if(pa.getOrderNumber() == pb.getOrderNumber()) { |
48 | return 0; |
49 | } |
50 | else { |
51 | return -1; |
52 | } |
53 | } |
54 | |
55 | public boolean equals(Object a) { |
56 | return false; |
57 | } |
58 | }; |
59 | } |
60 | |
61 | |
62 | public String getDefaultPageId() { |
63 | return defaultPageId; |
64 | } |
65 | |
66 | public void setDefaultPageId(String defaultPageId) { |
67 | this.defaultPageId = defaultPageId; |
68 | } |
69 | |
70 | public List getPages() { |
71 | List col = new ArrayList(pages.values()); |
72 | Collections.sort(col, pageComparator); |
73 | return col; |
74 | } |
75 | |
76 | public PageConfig getPageConfig(String pageId) { |
77 | if (pageId == null || "".equals(pageId)) { |
78 | if (LOG.isDebugEnabled()) { |
79 | LOG.debug( |
80 | "Requested page is null. Returning default: " + |
81 | defaultPageId); |
82 | } |
83 | pageId = defaultPageId; |
84 | } |
85 | return (PageConfig) pages.get(pageId); |
86 | } |
87 | |
88 | public void addPage(PageConfig config) { |
89 | config.setOrderNumber(orderNumberCounter++); |
90 | pages.put(config.getName(), config); |
91 | } |
92 | |
93 | } |