PIDUtils { public static String getSchemeSpecificId(String uri) { if (uri != null) { { final Matcher matcher = HANDLE_PATTERN.matcher(uri); if (matcher.matches() && matcher.groupCount() >= HANDLE_SCHEME_SPECIFIC_PART_GROUP) { return matcher.group(HANDLE_SCHEME_SPECIFIC_PART_GROUP); } } { final Matcher matcher = DOI_PATTERN.matcher(uri); if (matcher.matches() && matcher.groupCount() >= DOI_SCHEME_SPECIFIC_PART_GROUP) { return matcher.group(DOI_SCHEME_SPECIFIC_PART_GROUP); } } { final Matcher matcher = URN_NBN_PATTERN.matcher(uri); if (matcher.matches() && matcher.groupCount() >= URN_NBN_SCHEME_SPECIFIC_PART_GROUP) { return matcher.group(URN_NBN_SCHEME_SPECIFIC_PART_GROUP); } } } return null; }  static boolean isPid(String uri); static boolean isHandle(String uri); static boolean isDoi(String uri); static boolean isUrnNbn(String uri); static Optional<PIDType> getType(String uri); static String getSchemeSpecificId(String uri); static String getActionableLinkForPid(final String link); final static String HANDLE_PATTERN_STRING; final static int HANDLE_SCHEME_SPECIFIC_PART_GROUP; final static Pattern HANDLE_PATTERN; final static String DOI_PATTERN_STRING; final static int DOI_SCHEME_SPECIFIC_PART_GROUP; final static Pattern DOI_PATTERN; final static String URN_NBN_PATTERN_STRING; final static int URN_NBN_SCHEME_SPECIFIC_PART_GROUP; final static Pattern URN_NBN_PATTERN; final static Pattern PID_PATTERN; }
@Test public void testGetSchemeSpecificId() { VALID_HANDLES.forEach(h -> assertNotNull(PIDUtils.getSchemeSpecificId(h))); assertEquals("1234/5678", PIDUtils.getSchemeSpecificId("hdl:1234/5678")); assertEquals("1234/5678", PIDUtils.getSchemeSpecificId("http: assertEquals("1234/5678", PIDUtils.getSchemeSpecificId("HTTPS: VALID_DOIS.forEach(h -> assertNotNull(PIDUtils.getSchemeSpecificId(h))); assertEquals("1234/5678", PIDUtils.getSchemeSpecificId("doi:1234/5678")); assertEquals("1234/5678", PIDUtils.getSchemeSpecificId("http: assertEquals("1234/5678", PIDUtils.getSchemeSpecificId("HTTPS: VALID_URN_NBNS.forEach(h -> assertNotNull(PIDUtils.getSchemeSpecificId(h))); assertEquals("fi:1234/5678", PIDUtils.getSchemeSpecificId("urn:nbn:fi:1234/5678")); assertEquals("fi:1234/5678", PIDUtils.getSchemeSpecificId("http: assertEquals("de:123:456", PIDUtils.getSchemeSpecificId("http: NOT_PIDS.forEach(h -> assertNull(PIDUtils.getSchemeSpecificId(h))); assertNull(PIDUtils.getSchemeSpecificId(null)); }