1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts;
20
21 import java.io.IOException;
22 import java.net.URL;
23 import java.util.Properties;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.springframework.extensions.webscripts.Description.RequiredAuthentication;
28
29
30
31
32
33
34
35 public class PresentationContainer extends AbstractRuntimeContainer
36 {
37 private static final Log logger = LogFactory.getLog(PresentationContainer.class);
38
39
40
41
42
43 public void executeScript(WebScriptRequest scriptReq, WebScriptResponse scriptRes, Authenticator auth)
44 throws IOException
45 {
46
47
48
49 WebScript script = scriptReq.getServiceMatch().getWebScript();
50 Description desc = script.getDescription();
51 RequiredAuthentication required = desc.getRequiredAuthentication();
52 if (auth == null || RequiredAuthentication.none == required || auth.authenticate(required, false))
53 {
54 script.execute(scriptReq, scriptRes);
55 }
56 }
57
58
59
60
61 public ServerModel getDescription()
62 {
63 Properties props = null;
64 URL url = this.getClass().getClassLoader().getResource("version.properties");
65 if (url != null)
66 {
67 try
68 {
69 props = new Properties();
70 props.load(url.openStream());
71 }
72 catch (IOException err)
73 {
74 logger.warn("Failed to load version properties: " + err.getMessage(), err);
75 }
76 }
77 return new PresentationServerModel(props);
78 }
79
80
81
82
83
84
85 private class PresentationServerModel implements ServerModel
86 {
87 private Properties props = null;
88 private String version = null;
89
90 public PresentationServerModel(Properties props)
91 {
92 this.props = props;
93 }
94
95 public String getContainerName()
96 {
97 return getName();
98 }
99
100 public String getId()
101 {
102 return UNKNOWN;
103 }
104
105 public String getName()
106 {
107 return UNKNOWN;
108 }
109
110 public String getEdition()
111 {
112 return (props != null ? props.getProperty("version.edition") : UNKNOWN);
113 }
114
115 public int getSchema()
116 {
117 return (props != null ? Integer.parseInt(props.getProperty("version.schema")) : -1);
118 }
119
120 public String getVersion()
121 {
122 if (this.version == null)
123 {
124 if (props != null)
125 {
126 StringBuilder version = new StringBuilder(getVersionMajor());
127 version.append(".");
128 version.append(getVersionMinor());
129 version.append(".");
130 version.append(getVersionRevision());
131
132 String label = getVersionLabel();
133 String build = getVersionBuild();
134
135 boolean hasLabel = (label != null && label.length() > 0);
136 boolean hasBuild = (build != null && build.length() > 0);
137
138
139 if (hasLabel || hasBuild)
140 {
141 version.append(" (");
142 }
143
144
145 if (hasLabel)
146 {
147 version.append(label);
148 }
149
150
151 if (hasBuild)
152 {
153
154 if (hasLabel)
155 {
156 version.append(" ");
157 }
158
159 version.append(build);
160 }
161
162
163 if (hasLabel || hasBuild)
164 {
165 version.append(")");
166 }
167
168 this.version = version.toString();
169 }
170 else
171 {
172 this.version = UNKNOWN;
173 }
174 }
175 return this.version;
176 }
177
178 public String getVersionBuild()
179 {
180 return (props != null ? props.getProperty("version.build") : UNKNOWN);
181 }
182
183 public String getVersionLabel()
184 {
185 return (props != null ? props.getProperty("version.label") : UNKNOWN);
186 }
187
188 public String getVersionMajor()
189 {
190 return (props != null ? props.getProperty("version.major") : UNKNOWN);
191 }
192
193 public String getVersionMinor()
194 {
195 return (props != null ? props.getProperty("version.minor") : UNKNOWN);
196 }
197
198 public String getVersionRevision()
199 {
200 return (props != null ? props.getProperty("version.revision") : UNKNOWN);
201 }
202
203 private final static String UNKNOWN = "<unknown>";
204 }
205 }