public String[] getURIs() throws RepositoryException { return nsRegistry.getURIs(); }
@Override public String[] getURIs() throws RepositoryException { return delegate.getURIs(); }
public String[] getURIs() throws RepositoryException { return nsRegistry.getURIs(); }
/** * Returns a namespace URI that currently not used in the namespace * registry. * @return an unused namespace URI. */ private String getUnusedURI() throws RepositoryException { Set<String> uris = new HashSet<String>(Arrays.asList(nsp.getURIs())); String uri = TEST_URI; int i = 0; while (uris.contains(uri)) { uri += i++; } return uri; } }
@Override public void runTest() throws RepositoryException { for (int i = 0; i < 10000; i++) { for (String uri : registry.getURIs()) { session.getNamespacePrefix(uri); } } }
static boolean isNamespaceRegistered(Session session) throws RepositoryException { Workspace ws = session.getWorkspace(); //no need to set it up again, skip it if it has. String uris[] = ws.getNamespaceRegistry().getURIs(); for (String uri : uris) { if (RulesRepository.DROOLS_URI.equals(uri)) { return true; } } return false; }
/** {@inheritDoc} */ public String[] getURIs() throws RepositoryException, RemoteException { try { return registry.getURIs(); } catch (RepositoryException ex) { throw getRepositoryException(ex); } }
static boolean isNamespaceRegistered(Session session) throws RepositoryException { Workspace ws = session.getWorkspace(); //no need to set it up again, skip it if it has. String uris[] = ws.getNamespaceRegistry().getURIs(); for (String uri : uris) { if (RulesRepository.DROOLS_URI.equals(uri)) { return true; } } return false; }
public String[] execute() throws Exception { return getDelegate().getURIs(); } });
private void copyNamespaces() throws RepositoryException { NamespaceRegistry sourceRegistry = source.getNamespaceRegistry(); NamespaceRegistry targetRegistry = target.getNamespaceRegistry(); logger.info("Copying registered namespaces"); Collection<String> existing = Arrays.asList(targetRegistry.getURIs()); for (String uri : sourceRegistry.getURIs()) { if (!existing.contains(uri)) { // TODO: what if the prefix is already taken? targetRegistry.registerNamespace( sourceRegistry.getPrefix(uri), uri); } } }
private void copyNamespaces() throws RepositoryException { NamespaceRegistry sourceRegistry = source.getNamespaceRegistry(); NamespaceRegistry targetRegistry = target.getNamespaceRegistry(); logger.info("Copying registered namespaces"); Collection<String> existing = Arrays.asList(targetRegistry.getURIs()); for (String uri : sourceRegistry.getURIs()) { if (!existing.contains(uri)) { // TODO: what if the prefix is already taken? targetRegistry.registerNamespace( sourceRegistry.getPrefix(uri), uri); } } }
/** * Tests if {@link javax.jcr.NamespaceRegistry#getURIs()} returns the * required namespace URIs and if they are mapped to the correct prefixes. */ public void testGetNamespaceURIs() throws RepositoryException { Set<String> uris = new HashSet<String>(); uris.addAll(Arrays.asList(nsr.getURIs())); for (int i = 0; i < BUILTIN_URIS.length; i++) { String uri = BUILTIN_URIS[i]; assertTrue("NamespaceRegistry does not contain built in uri: " + uri, uris.contains(uri)); String prefix = nsr.getPrefix(uri); assertEquals("Wrong namespace mapping for uri: " + uri, BUILTIN_PREFIXES[i], prefix); } }
@NotNull private String getNewNamespaceURI(Workspace wsp) throws RepositoryException { String uri = "http://jackrabbit.apache.org/uri"; List<String> uris = Arrays.asList(wsp.getNamespaceRegistry().getURIs()); int i = 0; while (uris.contains(uri)) { uri = "http://jackrabbit.apache.org/uri_" + i++; } return uri; }
protected String registerNamespace( NamespaceRegistry registry, String namespaceUri, String defaultPrefix ) throws RepositoryException { List<String> allNamespaces = Arrays.asList(registry.getURIs()); if (allNamespaces.contains(namespaceUri)) { return registry.getPrefix(namespaceUri); } List<String> allPrefixes = Arrays.asList(registry.getPrefixes()); if (!allPrefixes.contains(defaultPrefix)) { registry.registerNamespace(defaultPrefix, namespaceUri); return defaultPrefix; } String generatedPrefix = generateNamespacePrefix(registry); registry.registerNamespace(generatedPrefix, namespaceUri); return generatedPrefix; }
private static String getUnknownURI(Session session, String uriHint) throws RepositoryException { String uri = uriHint; int index = 0; List<String> uris = Arrays.asList(session.getWorkspace().getNamespaceRegistry().getURIs()); while (uris.contains(uri)) { uri = uriHint + index; index++; } return uri; }
private String getNewNamespaceURI(Workspace wsp) throws RepositoryException { String uri = "http://jackrabbit.apache.org/uri"; List<String> uris = Arrays.asList(wsp.getNamespaceRegistry().getURIs()); int i = 0; while (uris.contains(uri)) { uri = "http://jackrabbit.apache.org/uri_" + i++; } return uri; }
@Test public void testNamespaceRegistry() throws RepositoryException { NamespaceRegistry nsReg = getAdminSession().getWorkspace().getNamespaceRegistry(); assertFalse(asList(nsReg.getPrefixes()).contains("foo")); assertFalse(asList(nsReg.getURIs()).contains("file:///foo")); nsReg.registerNamespace("foo", "file:///foo"); assertTrue(asList(nsReg.getPrefixes()).contains("foo")); assertTrue(asList(nsReg.getURIs()).contains("file:///foo")); nsReg.unregisterNamespace("foo"); assertFalse(asList(nsReg.getPrefixes()).contains("foo")); assertFalse(asList(nsReg.getURIs()).contains("file:///foo")); }
protected void assertNoRepositoryNamespace( String uri, String prefix ) throws RepositoryException { NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); for (String existingPrefix : registry.getPrefixes()) { assertThat(existingPrefix.equals(prefix), is(false)); } for (String existingUri : registry.getURIs()) { assertThat(existingUri.equals(uri), is(false)); } }
protected void assertThatNamespaceIsRegistered( String prefix, String uri ) throws Exception { assertThat(registry.getURI(prefix), is(uri)); assertThat(registry.getPrefix(uri), is(prefix)); boolean foundPrefix = false; for (String existingPrefix : registry.getPrefixes()) { if (existingPrefix.equals(prefix)) foundPrefix = true; } assertThat(foundPrefix, is(true)); boolean foundUri = false; for (String existingUri : registry.getURIs()) { if (existingUri.equals(uri)) foundUri = true; } assertThat(foundUri, is(true)); }
protected void assertThatNamespaceUriIsNotRegistered( String uri ) throws Exception { try { registry.getPrefix(uri); fail("Should not have found namespace mapping with URI \"" + uri + "\""); } catch (NamespaceException e) { // good } for (String existingUri : registry.getURIs()) { assertThat(existingUri, is(not(uri))); } }