1
2
3
4
5 package gboat2.base.plugin.struts.convention;
6
7 import java.util.LinkedHashMap;
8 import java.util.Map;
9
10 import org.apache.struts2.convention.ConventionsServiceImpl;
11 import org.apache.struts2.osgi.DefaultBundleAccessor;
12
13 import com.opensymphony.xwork2.config.entities.ActionConfig;
14 import com.opensymphony.xwork2.config.entities.PackageConfig;
15 import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
16 import com.opensymphony.xwork2.inject.Inject;
17 import com.opensymphony.xwork2.util.ClassLoaderUtil;
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class GboatConventionsServiceImpl extends ConventionsServiceImpl {
32 private String resultPath;
33
34 @Inject
35 public GboatConventionsServiceImpl(@Inject("struts.convention.result.path") String resultPath) {
36 super(resultPath);
37 this.resultPath = resultPath;
38 }
39
40 @Override
41 public String determineResultPath(ActionConfig actionConfig) {
42 if (actionConfig == null) {
43 return resultPath;
44 }
45
46 try {
47 Class<?> clazz = null;
48 try {
49 clazz = ClassLoaderUtil.loadClass(actionConfig.getClassName(), this.getClass());
50 } catch (ClassNotFoundException e) {
51 clazz = DefaultBundleAccessor.getInstance().loadClass(actionConfig.getClassName());
52 }
53 return super.determineResultPath(clazz);
54 } catch (ClassNotFoundException e) {
55 throw new RuntimeException("Invalid action class configuration that references an unknown class named [" + actionConfig.getClassName() + "]", e);
56 }
57 }
58
59 @Override
60 public Map<String, ResultTypeConfig> getResultTypesByExtension(PackageConfig packageConfig) {
61 Map<String, ResultTypeConfig> results = packageConfig.getAllResultTypeConfigs();
62 Map<String, ResultTypeConfig> resultsByExtension = new LinkedHashMap<String, ResultTypeConfig>();
63 resultsByExtension.put("jsp", results.get("dispatcher"));
64 resultsByExtension.put("html", results.get("dispatcher"));
65 resultsByExtension.put("vm", results.get("velocity"));
66 resultsByExtension.put("ftl", results.get("freemarker"));
67 return resultsByExtension;
68 }
69
70 }