]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/provisioning/ModularDistributionInterceptor.java
Remove unused classes in org.argeo.slc.server package
[gpl/argeo-slc.git] / runtime / org.argeo.slc.server / src / main / java / org / argeo / slc / web / mvc / provisioning / ModularDistributionInterceptor.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.web.mvc.provisioning;
18
19 import java.util.Iterator;
20 import java.util.Set;
21 import java.util.SortedMap;
22 import java.util.StringTokenizer;
23 import java.util.TreeMap;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.argeo.slc.SlcException;
29 import org.argeo.slc.build.BasicNameVersion;
30 import org.argeo.slc.build.BuildConstants;
31 import org.argeo.slc.build.ModularDistribution;
32 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
33
34 public class ModularDistributionInterceptor extends HandlerInterceptorAdapter {
35 private Set<ModularDistribution> modularDistributions;
36
37 @Override
38 public boolean preHandle(HttpServletRequest request,
39 HttpServletResponse response, Object handler) throws Exception {
40 String path = request.getPathInfo();
41 StringTokenizer stS = new StringTokenizer(path, "/");
42 String distributionName = stS.nextToken();
43 String distributionVersion = stS.nextToken();
44
45 SortedMap<String, ModularDistribution> choices = new TreeMap<String, ModularDistribution>();
46 distribs: for (Iterator<ModularDistribution> it = modularDistributions
47 .iterator(); it.hasNext();) {
48 ModularDistribution md = it.next();
49 if (md.getName().equals(distributionName)) {
50 if (distributionVersion.equals(BuildConstants.RELEASE)
51 && md.getVersion().contains(BuildConstants.SNAPSHOT))
52 continue distribs;
53
54 else if (distributionVersion.equals(BuildConstants.LATEST))
55 choices.put(md.getVersion(), md);
56 else if (distributionVersion.equals(md.getVersion())) {
57 choices.put(md.getVersion(), md);
58 break distribs;
59 }
60 }
61 }
62
63 if (choices.size() == 0)
64 throw new SlcException("Cannot find distribution for "
65 + new BasicNameVersion(distributionName,
66 distributionVersion));
67
68 ModularDistribution modularDistribution = choices.get(choices
69 .firstKey());
70
71 request.setAttribute("modularDistribution", modularDistribution);
72
73 return true;
74 }
75
76 public void setModularDistributions(
77 Set<ModularDistribution> modularDistributions) {
78 this.modularDistributions = modularDistributions;
79 }
80
81 }