View Javadoc

1   /*
2    * $Id: IvornUtil.java,v 1.2 2005/07/05 08:26:57 clq2 Exp $
3    * 
4    * Created on 30-May-2005 by Paul Harrison (pharriso@eso.org)
5    * Copyright 2005 Astrogrid. All rights reserved.
6    *
7    * This software is published under the terms of the AstroGrid 
8    * Software License, a copy of which has been included 
9    * with this distribution in the LICENSE.txt file.  
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   * $Log: IvornUtil.java,v $
85   * Revision 1.2  2005/07/05 08:26:57  clq2
86   * paul's 559b and 559c for wo/apps and jes
87   *
88   * Revision 1.1.4.1  2005/06/09 08:47:32  pah
89   * result of merging branch cea_pah_559b into HEAD
90   *
91   * Revision 1.1.2.1  2005/05/31 12:58:25  pah
92   * moved to v10 schema interpretation - this means that the authorityID is read directly with the applicaion "name"
93   *
94   */