1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.extend.server.deployment.tomcat;
14
15 import java.net.MalformedURLException;
16 import java.net.URI;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19
20 import org.abstracthorizon.extend.server.deployment.ModuleId;
21 import org.abstracthorizon.extend.server.support.URLUtils;
22 import org.abstracthorizon.extend.support.spring.deployment.AbstractApplicationContextModule;
23 import org.abstracthorizon.extend.support.spring.service.ServiceModuleLoader;
24 import org.springframework.beans.BeansException;
25 import org.springframework.context.ApplicationContext;
26 import org.springframework.context.ConfigurableApplicationContext;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class TomcatWarModuleLoader extends ServiceModuleLoader {
43
44
45
46
47 public TomcatWarModuleLoader() {
48 }
49
50
51
52
53
54
55 public boolean canLoad(URI uri) {
56 if (super.canLoad(uri)) {
57 if (URLUtils.isFolder(uri)) {
58 try {
59 URI webINFURL = URLUtils.add(uri, "WEB-INF");
60 return URLUtils.exists(webINFURL);
61 } catch (URISyntaxException ignore) {
62 }
63 } else {
64
65 return true;
66 }
67 }
68 return false;
69 }
70
71
72
73
74
75
76 protected AbstractApplicationContextModule createModule(URL url) {
77 return new TomcatWebApplicationContext(ModuleId.createModuleIdFromFileName(url.getPath()));
78 }
79
80
81
82
83
84 protected void preDefinitionProcessing(AbstractApplicationContextModule service) {
85 TomcatWebApplicationContext tomcatContext = (TomcatWebApplicationContext)service;
86 tomcatContext.setWebServerContext(root);
87 tomcatContext.setParent(root.getParent());
88 }
89
90
91
92
93
94 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
95 this.root = (ConfigurableApplicationContext)applicationContext;
96 }
97
98
99
100
101
102
103 protected void addFilesForScanning(AbstractApplicationContextModule module) {
104 super.addFilesForScanning(module);
105 if (redeployURLScanner != null) {
106
107
108 URL locationURL = module.getOriginalLocation();
109 if (locationURL.equals(module.getWorkingLocation())) {
110 URL serviceFileURL = module.getServiceFile();
111 redeployURLScanner.addURL(serviceFileURL, module);
112 try {
113 URL url = URLUtils.add(locationURL, "WEB-INF/web.xml");
114 if (URLUtils.exists(url)) {
115 redeployURLScanner.addURL(url, module);
116 }
117 } catch (MalformedURLException ignore) {
118 }
119 }
120 }
121 }
122 }