1
2
3
4
5
6
7
8
9
10
11
12
13 package org.astrogrid.applications.description.registry;
14
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
17
18 /***
19 * Useful utilities for Ivorns.
20 * @TODO should probably be put into common ivorn class.
21 * @author Paul Harrison (pharriso@eso.org) 30-May-2005
22 * @version $Name: HEAD $
23 * @since initial Coding
24 */
25 public class IvornUtil {
26 private IvornUtil(){}
27 /*** the regular expression for extracting the authorityID and resource name from ivorn */
28 private static final String ivornRegexp = "(ivo://)?(([^/]+)/(.+))";
29 private static final Pattern pattern = Pattern.compile(ivornRegexp);
30 /***
31 * Returns the ID part of an ivorn as a string.
32 * @param s
33 * @return
34 */
35 public static String extractIDFragment(String s) {
36 Matcher matcher = pattern.matcher(s);
37 if(matcher.find())
38 {
39 return matcher.group(4);
40 }
41 else
42 {
43 return null;
44 }
45 }
46 /***
47 * returns the AuthorityID part of an ivorn as a string.
48 * @param s
49 * @return
50 */
51 public static String extractAuthorityFragment(String s)
52 {
53 Matcher matcher = pattern.matcher(s);
54 if(matcher.find())
55 {
56 return matcher.group(3);
57 }
58 else
59 {
60 return null;
61 }
62 }
63
64 public static String removeProtocol(String s)
65 {
66 Matcher matcher = pattern.matcher(s);
67 if(matcher.find())
68 {
69 return matcher.group(2);
70 }
71 else
72 {
73 return null;
74 }
75
76 }
77
78
79
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94