@Override public String getPrefix(String namespace) { if (localNS.containsValue(namespace)) return localNS.inverse().get(namespace); else return prefixService.getPrefix(namespace); }
@Override public String getNamespace(String prefix) { if (localNS.containsKey(prefix)) return localNS.get(prefix); else return prefixService.getNamespace(prefix); }
@Override public boolean containsPrefix(String prefix) { return localNS.containsKey(prefix) || prefixService.containsPrefix(prefix); }
@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)); }
@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 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));
@Override public Map<String, String> getMappings() { Map<String, String> mappings = new HashMap<String, String>(); mappings.putAll(prefixService.getMappings()); mappings.putAll(localNS); return Collections.unmodifiableMap(mappings); }
@Override public boolean containsNamespace(String namespace) { return localNS.containsValue(namespace) || prefixService.containsNamespace(namespace); }
/** * Add new mapping * * @param prefix prefix * @param namespace uri * @return operation result */ @POST @Path("/" + PREFIX_PATTERN) public Response addMapping(@PathParam("prefix") String prefix, @QueryParam("uri") @NotNull String namespace) { try { prefixService.add(prefix, namespace); return Response.status(Response.Status.CREATED).build(); } catch (URISyntaxException e) { return Response.status(Response.Status.NOT_ACCEPTABLE).entity(e.getMessage()).build(); } catch (IllegalArgumentException e) { return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build(); } }
private String namespaceLookup(String prefix) throws IllegalArgumentException, URISyntaxException { String namespace = prefixcc.getNamespace(prefix); if (StringUtils.isNotBlank(namespace)) { add(prefix, namespace); } return namespace; }
private String prefixLookup(String namespace) throws IllegalArgumentException, URISyntaxException { String prefix = prefixcc.getPrefix(namespace); if (StringUtils.isNotBlank(prefix)) { add(prefix, namespace); } return prefix; }
/** * Removes a prefix * * @param prefix prefix * @return Response with the result of the operation */ @DELETE @Path("/" + PREFIX_PATTERN) public Response deleteMapping(@PathParam("prefix") String prefix) { if (prefixService.remove(prefix)) { return Response.status(Status.NO_CONTENT).build(); } else { return Response.status(Response.Status.NOT_FOUND).entity("prefix " + prefix + " mapping not found").build(); } }
@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)); }
/** * 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 all prefixes mappings * * @return all current prefixes mappings */ @GET @Produces("application/json") public Response getMappings() { Map<String, String> mappings = (prefixService != null ? prefixService.getMappings() : new HashMap<String,String>()); return Response.ok().entity(mappings).build(); }
private String namespaceLookup(String prefix) throws IllegalArgumentException, URISyntaxException { String namespace = prefixcc.getNamespace(prefix); if (StringUtils.isNotBlank(namespace)) { add(prefix, namespace); } return namespace; }
private String prefixLookup(String namespace) throws IllegalArgumentException, URISyntaxException { String prefix = prefixcc.getPrefix(namespace); if (StringUtils.isNotBlank(prefix)) { add(prefix, namespace); } return prefix; }
/** * Removes a prefix * * @param prefix prefix * @return Response with the result of the operation */ @DELETE @Path("/" + PREFIX_PATTERN) public Response deleteMapping(@PathParam("prefix") String prefix) { if (prefixService.remove(prefix)) { return Response.status(Status.NO_CONTENT).build(); } else { return Response.status(Response.Status.NOT_FOUND).entity("prefix " + prefix + " mapping not found").build(); } }
/** * Get all prefixes mappings * * @return all current prefixes mappings */ @GET @Produces("application/json") public Response getMappings() { Map<String, String> mappings = (prefixService != null ? prefixService.getMappings() : new HashMap<String,String>()); return Response.ok().entity(mappings).build(); }