@Override public String getNamespace(String prefix) { if (localNS.containsKey(prefix)) return localNS.get(prefix); else return prefixService.getNamespace(prefix); }
/** * Get namespace * * @param prefix prefix * @return Response with the mapping, if exists */ @GET @Path("/" + PREFIX_PATTERN) @Produces("application/json") public Response getMapping(@PathParam("prefix") String prefix) { if (prefixService.containsPrefix(prefix)) { Map<String, String> result = new HashMap<>(); result.put(prefix, prefixService.getNamespace(prefix)); return Response.ok().entity(result).build(); } else { log.error("prefix {} mapping not found", prefix); return Response.status(Response.Status.NOT_FOUND).entity("prefix " + prefix + " mapping not found").build(); } }
/** * Get namespace * * @param prefix prefix * @return Response with the mapping, if exists */ @GET @Path("/" + PREFIX_PATTERN) @Produces("application/json") public Response getMapping(@PathParam("prefix") String prefix) { if (prefixService.containsPrefix(prefix)) { Map<String, String> result = new HashMap<>(); result.put(prefix, prefixService.getNamespace(prefix)); return Response.ok().entity(result).build(); } else { log.error("prefix {} mapping not found", prefix); return Response.status(Response.Status.NOT_FOUND).entity("prefix " + prefix + " mapping not found").build(); } }
@GET @Path("/prefix") @Produces(Namespaces.MIME_TYPE_JSON) public Map<String, String> resolvePrefix(@QueryParam("prefix") String prefix, @Context UriInfo info) { final PrefixService prefixService = createLocalPrefixService(info); if (prefixService.containsPrefix(prefix)) return Collections.singletonMap(prefix, prefixService.getNamespace(prefix)); // As a fallback, try prefix.cc if (prefix != null) { final String namespace = prefixCC.getNamespace(prefix); if (namespace != null) return Collections.singletonMap(prefix, namespace); } return Collections.emptyMap(); }
String resolved = prefixService.getNamespace(px) + (local != null ? local : ""); List<String> suggestions = new ArrayList<String>(); for (String c : getCompletions(resolved, limit, mode)) {
@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); }
@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)); }
String namespace = "http://foo#"; Assert.assertNull(prefixService.getNamespace(prefix)); post("/prefix/" + prefix + "?uri=" + namespace); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace));