%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.container.state.impl.JetspeedNavigationalStateComponent |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.container.state.impl; |
|
18 | ||
19 | import java.util.Collections; |
|
20 | import java.util.Enumeration; |
|
21 | import java.util.HashMap; |
|
22 | import java.util.Map; |
|
23 | ||
24 | import javax.portlet.PortletMode; |
|
25 | import javax.portlet.WindowState; |
|
26 | import javax.servlet.http.HttpServletRequest; |
|
27 | ||
28 | import org.apache.jetspeed.PortalContext; |
|
29 | import org.apache.jetspeed.container.state.FailedToCreateNavStateException; |
|
30 | import org.apache.jetspeed.container.state.NavigationalState; |
|
31 | import org.apache.jetspeed.container.state.NavigationalStateComponent; |
|
32 | import org.apache.jetspeed.container.url.PortalURL; |
|
33 | import org.apache.jetspeed.util.ArgUtil; |
|
34 | import org.springframework.beans.BeansException; |
|
35 | import org.springframework.beans.factory.BeanFactory; |
|
36 | import org.springframework.beans.factory.BeanFactoryAware; |
|
37 | ||
38 | /** |
|
39 | * JetspeedNavigationalStateComponent |
|
40 | * |
|
41 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a> |
|
42 | * @version $Id: JetspeedNavigationalStateComponent.java 517124 2007-03-12 08:10:25Z ate $ |
|
43 | */ |
|
44 | public class JetspeedNavigationalStateComponent implements NavigationalStateComponent, BeanFactoryAware |
|
45 | { |
|
46 | private final String navBeanName; |
|
47 | private final String urlBeanName; |
|
48 | private final String desktopUrlBeanName; |
|
49 | ||
50 | // maps containing allowed PortletMode and WindowState objects on their lowercase name |
|
51 | // ensuring only allowed, and always the same objects are returned and allowing comparision by value |
|
52 | 0 | private final Map supportedPortletModes = Collections.synchronizedMap(new HashMap()); |
53 | 0 | private final Map supportedWindowStates = Collections.synchronizedMap(new HashMap()); |
54 | ||
55 | private BeanFactory beanFactory; |
|
56 | ||
57 | ||
58 | /** |
|
59 | * @param navBeanName |
|
60 | * name of the bean implementing Navigational State instances |
|
61 | * @param urlBeanName |
|
62 | * name of the bean implementing Portal URL instances |
|
63 | * @param navCodecBeanName |
|
64 | * name of the bean implementing Navigational State Codec instance |
|
65 | * @throws ClassNotFoundException |
|
66 | * if <code>navClassName</code> or <code>urlClassName</code> |
|
67 | * do not exist. |
|
68 | */ |
|
69 | public JetspeedNavigationalStateComponent(String navBeanName, String urlBeanName, PortalContext portalContext, String desktopUrlBeanName) |
|
70 | throws ClassNotFoundException |
|
71 | 0 | { |
72 | 0 | ArgUtil.assertNotNull(String.class, navBeanName, this); |
73 | 0 | ArgUtil.assertNotNull(String.class, urlBeanName, this); |
74 | 0 | this.navBeanName = navBeanName; |
75 | 0 | this.urlBeanName = urlBeanName; |
76 | 0 | this.desktopUrlBeanName = desktopUrlBeanName; |
77 | ||
78 | 0 | Enumeration portletModesEnum = portalContext.getSupportedPortletModes(); |
79 | PortletMode portletMode; |
|
80 | 0 | while ( portletModesEnum.hasMoreElements() ) |
81 | { |
|
82 | 0 | portletMode = (PortletMode)portletModesEnum.nextElement(); |
83 | 0 | supportedPortletModes.put(portletMode.toString(), portletMode); |
84 | } |
|
85 | 0 | Enumeration windowStatesEnum = portalContext.getSupportedWindowStates(); |
86 | WindowState windowState; |
|
87 | 0 | while ( windowStatesEnum.hasMoreElements() ) |
88 | { |
|
89 | 0 | windowState = (WindowState)windowStatesEnum.nextElement(); |
90 | 0 | supportedWindowStates.put(windowState.toString(), windowState); |
91 | } |
|
92 | 0 | } |
93 | ||
94 | /** |
|
95 | * |
|
96 | * <p> |
|
97 | * create |
|
98 | * </p> |
|
99 | * |
|
100 | * @see org.apache.jetspeed.container.state.NavigationalStateComponent#create(org.apache.jetspeed.request.RequestContext) |
|
101 | * @return @throws |
|
102 | * FailedToCreateNavStateException if the nav state could not be |
|
103 | * created. Under normal circumstances, this should not happen. |
|
104 | */ |
|
105 | public NavigationalState create() throws FailedToCreateNavStateException |
|
106 | { |
|
107 | try |
|
108 | { |
|
109 | 0 | return (NavigationalState) beanFactory.getBean(navBeanName, NavigationalState.class); |
110 | } |
|
111 | 0 | catch (BeansException e) |
112 | { |
|
113 | 0 | throw new FailedToCreateNavStateException("Spring failed to create the NavigationalState bean.", e); |
114 | } |
|
115 | } |
|
116 | ||
117 | /** |
|
118 | * |
|
119 | * <p> |
|
120 | * createURL |
|
121 | * </p> |
|
122 | * |
|
123 | * @see org.apache.jetspeed.container.state.NavigationalStateComponent#createURL(org.apache.jetspeed.request.RequestContext) |
|
124 | * @param context |
|
125 | * @return |
|
126 | */ |
|
127 | public PortalURL createURL( HttpServletRequest request, String characterEncoding ) |
|
128 | { |
|
129 | 0 | PortalURL url = (PortalURL) beanFactory.getBean(urlBeanName, PortalURL.class); |
130 | 0 | url.setRequest(request); |
131 | 0 | url.setCharacterEncoding(characterEncoding); |
132 | 0 | return url; |
133 | } |
|
134 | ||
135 | public WindowState lookupWindowState( String name ) |
|
136 | { |
|
137 | 0 | return (WindowState)supportedWindowStates.get(name.toLowerCase()); |
138 | } |
|
139 | ||
140 | public PortletMode lookupPortletMode( String name ) |
|
141 | { |
|
142 | 0 | return (PortletMode)supportedPortletModes.get(name.toLowerCase()); |
143 | } |
|
144 | ||
145 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException |
|
146 | { |
|
147 | 0 | this.beanFactory = beanFactory; |
148 | 0 | } |
149 | ||
150 | public PortalURL createDesktopURL(HttpServletRequest request, String characterEncoding) |
|
151 | { |
|
152 | 0 | PortalURL url = (PortalURL) beanFactory.getBean(desktopUrlBeanName, PortalURL.class); |
153 | 0 | url.setRequest(request); |
154 | 0 | url.setCharacterEncoding(characterEncoding); |
155 | 0 | return url; |
156 | } |
|
157 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |