@Override public String getPrefix(String namespace) { if (localNS.containsValue(namespace)) return localNS.inverse().get(namespace); else return prefixService.getPrefix(namespace); }
/** * Reverse prefix lookup * * @param uri namespace * @return Response with the result of the reverse search */ @GET @Path("/reverse") @Produces("application/json") public Response getPrefix(@QueryParam("uri") @NotNull String uri) { if (StringUtils.isNotBlank(uri)) { if (prefixService.containsNamespace(uri)) { Map<String, String> result = new HashMap<>(); result.put(uri, prefixService.getPrefix(uri)); return Response.ok().entity(result).build(); } else { log.error("namespace {} mapping not found", uri); return Response.status(Response.Status.NOT_FOUND).entity("namespace " + uri + " mapping not found").build(); } } else { log.error("Empty namespace requested"); return Response.status(Response.Status.BAD_REQUEST).build(); } }
/** * Reverse prefix lookup * * @param uri namespace * @return Response with the result of the reverse search */ @GET @Path("/reverse") @Produces("application/json") public Response getPrefix(@QueryParam("uri") @NotNull String uri) { if (StringUtils.isNotBlank(uri)) { if (prefixService.containsNamespace(uri)) { Map<String, String> result = new HashMap<>(); result.put(uri, prefixService.getPrefix(uri)); return Response.ok().entity(result).build(); } else { log.error("namespace {} mapping not found", uri); return Response.status(Response.Status.NOT_FOUND).entity("namespace " + uri + " mapping not found").build(); } } else { log.error("Empty namespace requested"); return Response.status(Response.Status.BAD_REQUEST).build(); } }
if (mode.equals(MODE_TRANSFORM)) { for (String s : ldPathService.getTransformableTypes()) { String px = prefixService.getPrefix(UriUtil.getNamespace(s)); if (px != null && px.startsWith(prefix) && !suggestions.contains(px)) { suggestions.add(px);
@Test public void testForceDoubleSet() throws IllegalArgumentException, URISyntaxException { String prefix = "baz"; String namespace1 = "http://baz1#"; String namespace2 = "http://baz2#"; Assert.assertNull(prefixService.getNamespace(prefix)); prefixService.add(prefix, namespace1); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace1, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace1)); prefixService.forceAdd(prefix, namespace2); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace2, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace2)); }
@Test public void testSet() throws IllegalArgumentException, URISyntaxException { String prefix = "foo"; String namespace = "http://foo#"; Assert.assertNull(prefixService.getNamespace(prefix)); prefixService.add(prefix, namespace); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace)); }
@Test(expected=IllegalArgumentException.class) public void testDoubleSet() throws IllegalArgumentException, URISyntaxException { String prefix = "bar"; String namespace1 = "http://bar1#"; String namespace2 = "http://bar2#"; Assert.assertNull(prefixService.getNamespace(prefix)); prefixService.add(prefix, namespace1); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace1, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace1)); prefixService.add(prefix, namespace2); }
Assert.assertEquals(prefix, prefixService.getPrefix(namespace));