View Javadoc

1   package fr.in2p3.jsaga.helpers;
2   
3   import java.util.regex.Matcher;
4   import java.util.regex.Pattern;
5   
6   import org.ogf.saga.error.BadParameterException;
7   import org.ogf.saga.url.URL;
8   
9   public class SAGAId {
10  
11      /**
12       * extract nativeId from a SAGA ID
13       * SAGA ID is something like [URL]-[nativeId]
14       * 
15       * @param sagaId
16       * @return
17       * @throws BadParameterException
18       */
19      public static String idFromSagaId(String sagaId) throws BadParameterException {
20          Pattern p = Pattern.compile("(\\[.*]-\\[)(.+)(])");
21          Matcher m = p.matcher(sagaId);
22          if (m.find()) {
23              return m.group(2);
24          }
25          throw new BadParameterException();
26      }
27  
28      public static String idToSagaId(URL url, String nativeId) {
29          return "[" + url.getString() + "]-[" + nativeId + "]";
30      }
31  }