1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.layout.impl; |
18 |
|
|
19 |
|
import java.util.Locale; |
20 |
|
import java.util.Map; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Set; |
23 |
|
import java.util.Iterator; |
24 |
|
|
25 |
|
import org.apache.commons.logging.Log; |
26 |
|
import org.apache.commons.logging.LogFactory; |
27 |
|
import org.apache.jetspeed.JetspeedActions; |
28 |
|
import org.apache.jetspeed.ajax.AjaxAction; |
29 |
|
import org.apache.jetspeed.ajax.AjaxBuilder; |
30 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
31 |
|
import org.apache.jetspeed.page.document.NodeNotFoundException; |
32 |
|
import org.apache.jetspeed.portalsite.Menu; |
33 |
|
import org.apache.jetspeed.portalsite.PortalSiteRequestContext; |
34 |
|
import org.apache.jetspeed.profiler.impl.ProfilerValveImpl; |
35 |
|
import org.apache.jetspeed.request.RequestContext; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
public class GetMenusAction extends BasePortletAction |
47 |
|
implements AjaxAction, AjaxBuilder, Constants |
48 |
|
{ |
49 |
0 |
protected static final Log log = LogFactory.getLog(GetMenusAction.class); |
50 |
|
|
51 |
|
public GetMenusAction(String template, |
52 |
|
String errorTemplate, |
53 |
|
PortletActionSecurityBehavior securityBehavior) |
54 |
|
{ |
55 |
0 |
super(template, errorTemplate, securityBehavior); |
56 |
0 |
} |
57 |
|
|
58 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
59 |
|
{ |
60 |
0 |
boolean success = true; |
61 |
0 |
String status = "success"; |
62 |
|
try |
63 |
|
{ |
64 |
|
|
65 |
0 |
resultMap.put(ACTION, "getmenus"); |
66 |
|
|
67 |
|
|
68 |
0 |
if (!checkAccess(requestContext, JetspeedActions.VIEW)) |
69 |
|
{ |
70 |
0 |
success = false; |
71 |
0 |
resultMap.put(REASON, "Insufficient access to get menus"); |
72 |
0 |
return success; |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
0 |
PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY); |
77 |
0 |
if (siteRequestContext == null) |
78 |
|
{ |
79 |
0 |
success = false; |
80 |
0 |
resultMap.put(REASON, "Missing portal site request context from ProfilerValve"); |
81 |
0 |
return success; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
0 |
Set standardMenuNames = siteRequestContext.getStandardMenuNames(); |
86 |
0 |
Set customMenuNames = null; |
87 |
|
try |
88 |
|
{ |
89 |
0 |
customMenuNames = siteRequestContext.getCustomMenuNames(); |
90 |
|
} |
91 |
0 |
catch (NodeNotFoundException nnfe) |
92 |
|
{ |
93 |
0 |
} |
94 |
|
|
95 |
|
|
96 |
0 |
resultMap.put(STANDARD_MENUS, standardMenuNames); |
97 |
0 |
resultMap.put(CUSTOM_MENUS, customMenuNames); |
98 |
|
|
99 |
|
|
100 |
0 |
String includeMenuDefinitions = getActionParameter(requestContext, INCLUDE_MENU_DEFS); |
101 |
0 |
if ( includeMenuDefinitions != null && includeMenuDefinitions.toLowerCase().equals( "true" ) ) |
102 |
|
{ |
103 |
|
|
104 |
0 |
Locale locale = requestContext.getLocale(); |
105 |
|
|
106 |
0 |
HashMap menuDefinitionsMap = new HashMap(); |
107 |
|
|
108 |
0 |
StringBuffer failReason = new StringBuffer(); |
109 |
0 |
Iterator menuNamesIter = standardMenuNames.iterator(); |
110 |
0 |
while ( menuNamesIter.hasNext() ) |
111 |
|
{ |
112 |
0 |
String menuName = (String)menuNamesIter.next(); |
113 |
0 |
Menu menuDefinition = getMenuDefinition( menuName, siteRequestContext, failReason ); |
114 |
0 |
if ( menuDefinition != null ) |
115 |
0 |
menuDefinitionsMap.put( menuName, menuDefinition ); |
116 |
0 |
} |
117 |
0 |
menuNamesIter = customMenuNames.iterator(); |
118 |
0 |
while ( menuNamesIter.hasNext() ) |
119 |
|
{ |
120 |
0 |
String menuName = (String)menuNamesIter.next(); |
121 |
0 |
Menu menuDefinition = getMenuDefinition( menuName, siteRequestContext, failReason ); |
122 |
0 |
if ( menuDefinition != null ) |
123 |
0 |
menuDefinitionsMap.put( menuName, menuDefinition ); |
124 |
0 |
} |
125 |
|
|
126 |
0 |
if ( failReason.length() > 0 ) |
127 |
|
{ |
128 |
0 |
success = false; |
129 |
0 |
resultMap.put(REASON, failReason.toString() ); |
130 |
0 |
return success; |
131 |
|
} |
132 |
0 |
resultMap.put( INCLUDE_MENU_DEFS, new Boolean( true ) ); |
133 |
0 |
resultMap.put( MENU_DEFINITIONS, menuDefinitionsMap ); |
134 |
0 |
resultMap.put( MENU_CONTEXT, siteRequestContext ); |
135 |
0 |
resultMap.put( MENU_LOCALE, locale ); |
136 |
0 |
} |
137 |
|
else |
138 |
|
{ |
139 |
0 |
resultMap.put( INCLUDE_MENU_DEFS, new Boolean( false ) ); |
140 |
|
} |
141 |
0 |
resultMap.put(STATUS, status); |
142 |
|
} |
143 |
0 |
catch (Exception e) |
144 |
|
{ |
145 |
0 |
log.error("Exception while getting page menus info", e); |
146 |
0 |
success = false; |
147 |
0 |
} |
148 |
|
|
149 |
0 |
return success; |
150 |
|
} |
151 |
|
|
152 |
|
private Menu getMenuDefinition( String menuName, PortalSiteRequestContext siteRequestContext, StringBuffer failReason ) |
153 |
|
{ |
154 |
|
|
155 |
0 |
Menu menuDefinition = null; |
156 |
|
try |
157 |
|
{ |
158 |
0 |
menuDefinition = siteRequestContext.getMenu( menuName ); |
159 |
|
} |
160 |
0 |
catch ( NodeNotFoundException nnfe ) |
161 |
|
{ |
162 |
0 |
} |
163 |
0 |
if ( menuDefinition == null && failReason != class="keyword">null ) |
164 |
|
{ |
165 |
0 |
if ( failReason.length() == 0 ) |
166 |
0 |
failReason.append( "Unable to lookup specified menus: " ).append( menuName ); |
167 |
|
else |
168 |
0 |
failReason.append( ", " ).append( menuName ); |
169 |
|
} |
170 |
0 |
return menuDefinition; |
171 |
|
} |
172 |
|
} |