@Test @FixFor("MODE-1408") public void shouldRegisterNewNamespace() { Map<String, String> urisByPrefix = new HashMap<String, String>(); String uri = "http://foo.bar"; String prefix = "foobar"; urisByPrefix.put(prefix, uri); system.registerNamespaces(urisByPrefix); assertEquals(prefix, system.readNamespacePrefix(uri, false)); }
@Test public void shouldUnregisterNamespace() { Map<String, String> urisByPrefix = new HashMap<String, String>(); String uri = "http://foo.bar"; String prefix = "foobar"; urisByPrefix.put(prefix, uri); system.registerNamespaces(urisByPrefix); assertTrue(system.unregisterNamespace(uri)); assertNull(system.readNamespacePrefix(uri, false)); }
/** * Register a set of namespaces. * * @param namespaceUrisByPrefix the map of new namespace URIs by their prefix */ public void register(Map<String, String> namespaceUrisByPrefix) { if (namespaceUrisByPrefix == null || namespaceUrisByPrefix.isEmpty()) return; final Lock lock = this.namespacesLock.writeLock(); try { lock.lock(); SystemContent systemContent = systemContent(false); systemContent.registerNamespaces(namespaceUrisByPrefix); systemContent.save(); for (Map.Entry<String, String> entry : namespaceUrisByPrefix.entrySet()) { String prefix = entry.getKey().trim(); String uri = entry.getValue().trim(); if (prefix.length() == 0) continue; this.cache.register(prefix, uri); } } finally { lock.unlock(); } }
@Override public String register(String prefix, String namespaceUri) { CheckArg.isNotNull(namespaceUri, "namespaceUri"); namespaceUri = namespaceUri.trim(); final Lock lock = this.namespacesLock.writeLock(); try { lock.lock(); // Register it in the cache first ... String previousCachedUriForPrefix = this.cache.register(prefix, namespaceUri); if (!namespaceUri.equals(previousCachedUriForPrefix)) { // And register it in the source ... SystemContent systemContent = systemContent(false); systemContent.registerNamespaces(Collections.singletonMap(prefix, namespaceUri)); systemContent.save(); } return previousCachedUriForPrefix; } finally { lock.unlock(); } }