URIUtils { public static String getShortform(URI uri) { return getShortform(getPrefixMappings(), uri, DEFAULT_SHORTFORM_STRICTNESS, DEFAULT_PREFIX_CREATION_MODE); }  synchronized static Map<String, String> getPrefixMappings(); synchronized static Map<String, String> loadPrefixMappings(); static String getShortform(URI uri); static String getShortform(URI uri, ShortformStrictness strictness); static String getShortform(URI uri, ShortformStrictness strictness, PrefixCreationMode prefixCreationMode); static String getShortform(final Map<String, String> prefixMappings, URI uri); static String getShortform(final Map<String, String> prefixMappings,
                                      URI uri,
                                      ShortformStrictness strictness,
                                      PrefixCreationMode prefixCreationMode); static URI getURI(String shortform); static URI getURI(final Map<String, String> prefixMappings, String shortform); static URI getNamespace(String shortform); static URI getNamespace(final Map<String, String> prefixMappings, String shortform); static String getFragment(String shortform); static URI extractNamespace(URI uri); static String extractFragment(URI uri); static boolean isNamespaceKnown(URI uri); static URI normalizeURI(String uriStr); static URI normalizeURI(URI uri); static URI incrementURI(ZoomaDAO dao, URI uri); static final PrefixCreationMode DEFAULT_PREFIX_CREATION_MODE; static final ShortformStrictness DEFAULT_SHORTFORM_STRICTNESS; static final URI SEARCH_NONE; }
@Test public void testGetShortform() { String result; result = URIUtils.getShortform(uri1); System.out.println("Shortened " + uri1 + " -> " + result); assertEquals("Unexpected shortened form", prefix1 + ":term", result); result = URIUtils.getShortform(uri2); System.out.println("Shortened " + uri2 + " -> " + result); assertEquals("Unexpected shortened form", prefix2 + ":term", result); }
@Test public void testGetShortformCustomMappings() { Map<String, String> pm = new HashMap<>(); pm.put(prefix1, namespace2); pm.put(prefix2, namespace3); pm.put(prefix3, namespace4); assertEquals("Unexpected shortened form", prefix1 + ":term", URIUtils.getShortform(pm, uri1)); assertEquals("Unexpected shortened form", prefix2 + ":term", URIUtils.getShortform(pm, uri2)); assertEquals("Unexpected shortened form", prefix3 + ":term", URIUtils.getShortform(pm, uri3)); }
@Test public void testGetUnknownStrict() { try { String shortform = URIUtils.getShortform(uri4); System.out.println("Shortened " + uri4 + " -> " + shortform); fail("Shortened " + uri4 + " in strict mode with missing namespace, this should cause an error"); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); fail("Expected IllegalArgumentException, actually got " + e.getClass().getSimpleName() + " " + "(" + e.getMessage() + ")"); } }
@Test public void testCompoundingStrict() { URIUtils.PrefixCreationMode prefixCreationMode = URIUtils.PrefixCreationMode.CREATE; URIUtils.ShortformStrictness strictness = URIUtils.ShortformStrictness.STRICT; String result; result = URIUtils.getShortform(uri6, strictness, prefixCreationMode); System.out.println("Shortened " + uri6 + " -> " + result); assertFalse("Short form results in an invalid localname", result.contains("/") || result.contains("#")); }
@Test public void testCompoundingRelaxed() { URIUtils.PrefixCreationMode prefixCreationMode = URIUtils.PrefixCreationMode.DO_NOT_CREATE; URIUtils.ShortformStrictness strictness = URIUtils.ShortformStrictness.ALLOW_HASHES; String result; result = URIUtils.getShortform(uri9, strictness, prefixCreationMode); System.out.println("Shortened " + uri9 + " -> " + result); assertFalse("Short form results in an invalid localname", result.contains("/")); }
@Test public void testNamespaceOnly() { String result, localName; result = URIUtils.getShortform(uri7); localName = result.replace(result.substring(0, result.lastIndexOf(":") + 1), ""); System.out.println("Shortened " + uri7 + " -> " + result); assertFalse("Short form results in an invalid localname '" + localName + "'", localName.isEmpty()); result = URIUtils.getShortform(uri7); localName = result.replace(result.substring(0, result.lastIndexOf(":") + 1), ""); System.out.println("Shortened " + uri7 + " -> " + result); assertFalse("Short form results in an invalid localname '" + localName + "'", localName.isEmpty()); }