1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.resourceloader; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.servlet.ServletContext; |
23 | |
import javax.xml.namespace.QName; |
24 | |
|
25 | |
import org.kuali.rice.core.api.config.CoreConfigHelper; |
26 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
27 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
28 | |
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
29 | |
import org.kuali.rice.core.framework.resourceloader.BaseResourceLoader; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class RiceResourceLoaderFactory { |
40 | |
|
41 | |
private static final String RICE_ROOT_RESOURCE_LOADER_NAME = "RICE_ROOT_RESOURCE_LOADER"; |
42 | |
private static final String RICE_SPRING_RESOURCE_LOADER_NAME = "RICE_SPRING_RESOURCE_LOADER_NAME"; |
43 | |
|
44 | |
public static ResourceLoader createRootRiceResourceLoader(ServletContext context, List<String> springFileLocations, String prefix) { |
45 | |
|
46 | |
|
47 | 0 | if ("KSB".equals(prefix.toUpperCase())) { |
48 | 0 | prefix = "K~S~B"; |
49 | |
} |
50 | |
|
51 | 0 | String applicationId = CoreConfigHelper.getApplicationId(); |
52 | 0 | final QName root = new QName(applicationId, prefix.toUpperCase() + "_" + RICE_ROOT_RESOURCE_LOADER_NAME); |
53 | |
|
54 | 0 | if (getRootResourceLoaderNames() == null || !getRootResourceLoaderNames().contains(root)) { |
55 | 0 | addRootResourceLoaderName(root); |
56 | |
} |
57 | |
|
58 | 0 | final QName spring = new QName(applicationId, prefix.toUpperCase() + "_" + RICE_SPRING_RESOURCE_LOADER_NAME); |
59 | 0 | if (getSpringResourceLoaderNames() == null || !getSpringResourceLoaderNames().contains(root)) { |
60 | 0 | addSpringResourceLoaderName(spring); |
61 | |
} |
62 | |
|
63 | 0 | final ResourceLoader rootResourceLoader = new BaseResourceLoader(root, new SimpleServiceLocator()); |
64 | |
|
65 | 0 | final ResourceLoader springResourceLoader = new SpringResourceLoader(spring, springFileLocations, context); |
66 | 0 | rootResourceLoader.addResourceLoaderFirst(springResourceLoader); |
67 | |
|
68 | 0 | return rootResourceLoader; |
69 | |
} |
70 | |
|
71 | |
public static Collection<BaseResourceLoader> getRootResourceLoaders() { |
72 | 0 | final Collection<QName> names = getRootResourceLoaderNames(); |
73 | 0 | final Collection<BaseResourceLoader> loaders = new ArrayList<BaseResourceLoader>(); |
74 | 0 | for (QName name : names) { |
75 | 0 | loaders.add((BaseResourceLoader) GlobalResourceLoader.getResourceLoader(name)); |
76 | |
} |
77 | 0 | return loaders; |
78 | |
} |
79 | |
|
80 | |
public static Collection<SpringResourceLoader> getSpringResourceLoaders() { |
81 | 0 | final Collection<QName> names = getSpringResourceLoaderNames(); |
82 | 0 | final Collection<SpringResourceLoader> loaders = new ArrayList<SpringResourceLoader>(); |
83 | 0 | for (QName name : names) { |
84 | 0 | loaders.add((SpringResourceLoader) GlobalResourceLoader.getResourceLoader(name)); |
85 | |
} |
86 | 0 | return loaders; |
87 | |
} |
88 | |
|
89 | |
@SuppressWarnings("unchecked") |
90 | |
private static Collection<QName> getRootResourceLoaderNames() { |
91 | 0 | return (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME); |
92 | |
} |
93 | |
|
94 | |
private static void addRootResourceLoaderName(QName name) { |
95 | |
@SuppressWarnings("unchecked") |
96 | 0 | Collection<QName> names = (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME); |
97 | 0 | if (names == null) { |
98 | 0 | names = new ArrayList<QName>(); |
99 | |
} |
100 | 0 | names.add(name); |
101 | |
|
102 | 0 | ConfigContext.getCurrentContextConfig().putObject(RICE_ROOT_RESOURCE_LOADER_NAME, names); |
103 | 0 | } |
104 | |
|
105 | |
@SuppressWarnings("unchecked") |
106 | |
private static Collection<QName> getSpringResourceLoaderNames() { |
107 | 0 | return (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME); |
108 | |
} |
109 | |
|
110 | |
private static void addSpringResourceLoaderName(QName name) { |
111 | |
@SuppressWarnings("unchecked") |
112 | 0 | Collection<QName> names = (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME); |
113 | 0 | if (names == null) { |
114 | 0 | names = new ArrayList<QName>(); |
115 | |
} |
116 | 0 | names.add(name); |
117 | |
|
118 | 0 | ConfigContext.getCurrentContextConfig().putObject(RICE_SPRING_RESOURCE_LOADER_NAME, names); |
119 | 0 | } |
120 | |
|
121 | |
} |