01: package org.drools.brms.server.files;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.io.UnsupportedEncodingException;
20: import java.net.URLDecoder;
21: import java.util.regex.Matcher;
22: import java.util.regex.Pattern;
23:
24: import org.drools.brms.client.packages.PackageSnapshotView;
25:
26: /**
27: * Works out from the path URI what package is being requested.
28: * Uses Regular expression Pattern matching to recover packagename and version
29: * it works both with gwt hosted mode and application server standalone.
30: *
31: * @author Michael Neale
32: * @author Fernando Meyer
33: */
34: public class PackageDeploymentURIHelper {
35:
36: private String version;
37: private String packageName;
38:
39: public PackageDeploymentURIHelper(String uri)
40: throws UnsupportedEncodingException {
41:
42: String url = URLDecoder.decode(uri, "UTF-8");
43:
44: Pattern pattern = Pattern.compile(".*/(package|asset)/(.*)");
45: Matcher m = pattern.matcher(url);
46: if (m.matches()) {
47: String result = m.group(2);
48: String[] mtoks = result.split("/");
49: this .version = mtoks[1];
50: this .packageName = mtoks[0];
51: }
52: }
53:
54: public String getPackageName() {
55: return packageName;
56: }
57:
58: public String getVersion() {
59: return version;
60: }
61:
62: public boolean isLatest() {
63: return PackageSnapshotView.LATEST_SNAPSHOT.equals(version);
64: }
65: }
|