This project has retired. For details please refer to its
Attic page.
PortletApplicationContext xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.request.portlet;
22
23 import java.net.MalformedURLException;
24 import java.net.URL;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Locale;
28 import java.util.Map;
29
30 import javax.portlet.PortletContext;
31
32 import org.apache.tiles.request.ApplicationContext;
33 import org.apache.tiles.request.ApplicationResource;
34 import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
35 import org.apache.tiles.request.collection.ScopeMap;
36 import org.apache.tiles.request.locale.URLApplicationResource;
37 import org.apache.tiles.request.portlet.extractor.ApplicationScopeExtractor;
38 import org.apache.tiles.request.portlet.extractor.InitParameterExtractor;
39
40
41
42
43
44
45 public class PortletApplicationContext implements ApplicationContext {
46
47
48
49
50
51 private Map<String, Object> applicationScope = null;
52
53
54
55
56 protected PortletContext context = null;
57
58
59
60
61
62 private Map<String, String> initParam = null;
63
64
65
66
67
68
69 public PortletApplicationContext(PortletContext context) {
70 initialize(context);
71 }
72
73
74 public Object getContext() {
75 return context;
76 }
77
78
79
80
81
82
83
84 public void initialize(PortletContext context) {
85
86
87 this.context = context;
88
89 }
90
91
92
93
94
95
96 public PortletContext getPortletContext() {
97 return (this.context);
98 }
99
100
101 public Map<String, Object> getApplicationScope() {
102 if ((applicationScope == null) && (context != null)) {
103 applicationScope = new ScopeMap(new ApplicationScopeExtractor(context));
104 }
105 return (applicationScope);
106
107 }
108
109
110 public Map<String, String> getInitParams() {
111 if ((initParam == null) && (context != null)) {
112 initParam = new ReadOnlyEnumerationMap<String>(new InitParameterExtractor(context));
113 }
114 return (initParam);
115
116 }
117
118
119 public ApplicationResource getResource(String localePath) {
120 try {
121 URL url = context.getResource(localePath);
122 if (url != null) {
123 return new URLApplicationResource(localePath, url);
124 } else {
125 return null;
126 }
127 } catch (MalformedURLException e) {
128 return null;
129 }
130 }
131
132
133 public ApplicationResource getResource(ApplicationResource base, Locale locale) {
134 try {
135 URL url = context.getResource(base.getLocalePath(locale));
136 if (url != null) {
137 return new URLApplicationResource(base.getPath(), locale, url);
138 } else {
139 return null;
140 }
141 } catch (MalformedURLException e) {
142 return null;
143 }
144 }
145
146
147 public Collection<ApplicationResource> getResources(String path) {
148 ArrayList<ApplicationResource> resources = new ArrayList<ApplicationResource>();
149 resources.add(getResource(path));
150 return resources;
151 }
152 }