1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portalsite.impl;
18
19 import org.apache.jetspeed.om.folder.Folder;
20 import org.apache.jetspeed.om.folder.MenuOptionsDefinition;
21 import org.apache.jetspeed.om.page.Link;
22 import org.apache.jetspeed.om.page.Page;
23 import org.apache.jetspeed.page.document.Node;
24 import org.apache.jetspeed.page.document.NodeNotFoundException;
25 import org.apache.jetspeed.portalsite.MenuOption;
26 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
27
28 /***
29 * This class implements the portal-site menu option
30 * elements constructed and returned to decorators.
31 *
32 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
33 * @version $Id: MenuOptionImpl.java 537314 2007-05-11 23:08:36Z taylor $
34 */
35 public class MenuOptionImpl extends MenuElementImpl implements MenuOption, Cloneable
36 {
37 /***
38 * definition - menu option definition
39 */
40 private MenuOptionsDefinition definition;
41
42 /***
43 * MenuOptionImpl - constructor
44 *
45 * @param parent containing menu implementation
46 * @param node menu option node proxy
47 * @param definition menu option definition
48 */
49 public MenuOptionImpl(MenuImpl parent, Node node, MenuOptionsDefinition definition)
50 {
51 super(parent, node);
52 this.definition = definition;
53 }
54
55 /***
56 * getElementType - get type of menu element
57 *
58 * @return OPTION_ELEMENT_TYPE
59 */
60 public String getElementType()
61 {
62 return OPTION_ELEMENT_TYPE;
63 }
64
65 /***
66 * getType - get type of menu option
67 *
68 * @return FOLDER_OPTION_TYPE, PAGE_OPTION_TYPE, or
69 * LINK_OPTION_TYPE
70 */
71 public String getType()
72 {
73
74 Node node = getNode();
75 if (node instanceof Page)
76 {
77 return PAGE_OPTION_TYPE;
78 }
79 else if (node instanceof Link)
80 {
81 return LINK_OPTION_TYPE;
82 }
83 else if (node instanceof Folder)
84 {
85 return FOLDER_OPTION_TYPE;
86 }
87 return null;
88 }
89
90 /***
91 * getSkin - get skin name for menu element
92 *
93 * @return skin name
94 */
95 public String getSkin()
96 {
97
98
99 String skin = definition.getSkin();
100 if (skin == null)
101 {
102 Node node = getNode();
103 if (node instanceof Page)
104 {
105 skin = ((Page)node).getSkin();
106 }
107 else if (node instanceof Link)
108 {
109 skin = ((Link)node).getSkin();
110 }
111 else if (node instanceof Folder)
112 {
113 skin = ((Folder)node).getSkin();
114 }
115 }
116 if (skin == null)
117 {
118 skin = super.getSkin();
119 }
120 return skin;
121 }
122
123 /***
124 * getUrl - get url of menu option
125 *
126 * @return folder, page, or link url
127 */
128 public String getUrl()
129 {
130 return getNode().getUrl();
131 }
132
133 /***
134 * getTarget - get target for url of menu option
135 *
136 * @return url target
137 */
138 public String getTarget()
139 {
140
141 Node node = getNode();
142 if (node instanceof Link)
143 {
144 return ((Link)node).getTarget();
145 }
146 return null;
147 }
148
149 /***
150 * getDefaultPage - get default page for a folder (if folder) of menu option
151 *
152 * @return url target
153 */
154 public String getDefaultPage()
155 {
156
157 Node node = getNode();
158 if (node instanceof Folder)
159 {
160 return ((Folder)node).getDefaultPage();
161 }
162 return null;
163 }
164
165 /***
166 * isHidden - get hidden state of menu option
167 *
168 * @return hidden state
169 */
170 public boolean isHidden()
171 {
172 return getNode().isHidden();
173 }
174
175 /***
176 * isSelected - return true if menu option is selected by
177 * the specified request context
178 *
179 * @param context request context
180 * @return selected state
181 */
182 public boolean isSelected(PortalSiteRequestContext context)
183 {
184
185
186
187 if (context != null)
188 {
189
190 Page requestPage = null;
191 try
192 {
193 requestPage = context.getPage();
194 }
195 catch (NodeNotFoundException nnfe)
196 {
197 }
198 catch (SecurityException se)
199 {
200 }
201 if (requestPage != null)
202 {
203
204 Node node = getNode();
205 if (node instanceof Page)
206 {
207
208
209 return requestPage.getUrl().equals(node.getUrl());
210 }
211 else if (node instanceof Folder)
212 {
213
214
215
216 return requestPage.getUrl().startsWith(node.getUrl());
217 }
218 }
219 }
220 return false;
221 }
222 }