1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.pool.impl; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
import javax.faces.component.UIViewRoot; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import org.apache.myfaces.config.RuntimeConfig; |
28 | |
import org.apache.myfaces.config.element.ViewPoolMapping; |
29 | |
import org.apache.myfaces.config.element.ViewPoolParameter; |
30 | |
import org.apache.myfaces.shared.util.ViewProtectionUtils; |
31 | |
import org.apache.myfaces.view.facelets.ViewPoolProcessor; |
32 | |
import org.apache.myfaces.view.facelets.pool.ViewPool; |
33 | |
import org.apache.myfaces.view.facelets.pool.ViewPoolFactory; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class ViewPoolFactoryImpl extends ViewPoolFactory |
39 | |
{ |
40 | |
private List<String> urlPatterns; |
41 | |
private List<ViewPool> viewPoolList; |
42 | |
private ViewPool defaultViewPool; |
43 | |
|
44 | |
public ViewPoolFactoryImpl(FacesContext context) |
45 | 0 | { |
46 | 0 | RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(context.getExternalContext()); |
47 | |
|
48 | 0 | if (runtimeConfig.getViewPoolMappings().isEmpty()) |
49 | |
{ |
50 | 0 | defaultViewPool = new ViewPoolImpl(context, new HashMap<String, String>()); |
51 | |
} |
52 | 0 | urlPatterns = new ArrayList<String>(); |
53 | 0 | viewPoolList = new ArrayList<ViewPool>(); |
54 | 0 | for (ViewPoolMapping vpm : runtimeConfig.getViewPoolMappings()) |
55 | |
{ |
56 | 0 | urlPatterns.add(vpm.getUrlPattern()); |
57 | 0 | Map<String,String> parameters = new HashMap<String, String>(); |
58 | 0 | for (ViewPoolParameter param : vpm.getParameterList()) |
59 | |
{ |
60 | 0 | parameters.put(param.getName(), param.getValue()); |
61 | 0 | } |
62 | 0 | viewPoolList.add(new ViewPoolImpl(context, parameters)); |
63 | 0 | } |
64 | 0 | } |
65 | |
|
66 | |
@Override |
67 | |
public ViewPool getViewPool(FacesContext context, UIViewRoot root) |
68 | |
{ |
69 | 0 | for (int i = 0; i < urlPatterns.size(); i++) |
70 | |
{ |
71 | 0 | String urlPattern = urlPatterns.get(i); |
72 | 0 | if (ViewProtectionUtils.matchPattern(root.getViewId(), urlPattern)) |
73 | |
{ |
74 | 0 | return viewPoolList.get(i); |
75 | |
} |
76 | |
} |
77 | 0 | if (defaultViewPool != null) |
78 | |
{ |
79 | |
|
80 | |
|
81 | |
|
82 | 0 | Boolean enableViewPool = (Boolean) root.getAttributes().get(ViewPoolProcessor.ENABLE_VIEW_POOL); |
83 | 0 | if (enableViewPool == null) |
84 | |
{ |
85 | 0 | return null; |
86 | |
} |
87 | 0 | return defaultViewPool; |
88 | |
} |
89 | 0 | return null; |
90 | |
} |
91 | |
} |