/** * Returns a prefix that is unique among the already registered prefixes. * * @param uriHint namespace uri that serves as hint for the prefix generation * @return a unique prefix */ public String getUniquePrefix(String uriHint) throws RepositoryException { // TODO: smarter unique prefix generation return "_pre" + (nsReg.getPrefixes().length + 1); } }
/** * Returns a prefix that is unique among the already registered prefixes. * * @param uriHint namespace uri that serves as hint for the prefix generation * @return a unique prefix */ public String getUniquePrefix(String uriHint) throws RepositoryException { // TODO: smarter unique prefix generation return "_pre" + (nsReg.getPrefixes().length + 1); } }
@Override public String[] getPrefixes() throws RepositoryException { return delegate.getPrefixes(); }
public String[] getPrefixes() throws RepositoryException { return nsRegistry.getPrefixes(); }
private String generateNamespacePrefix( NamespaceRegistry registry ) throws RepositoryException { String basePrefix = "ns"; String prefix = basePrefix; int counter = 1; List<String> prefixes = Arrays.asList(registry.getPrefixes()); while (prefixes.contains(prefix)) { prefix = basePrefix + counter; counter++; } return prefix; }
private String generateNamespacePrefix( NamespaceRegistry registry ) throws RepositoryException { String basePrefix = "ns"; String prefix = basePrefix; int counter = 1; List<String> prefixes = Arrays.asList(registry.getPrefixes()); while (prefixes.contains(prefix)) { prefix = basePrefix + counter; counter++; } return prefix; }
protected void endPrefixMapping() throws RepositoryException, SAXException { String[] prefixes = getNamespaceRegistry().getPrefixes(); for (String prefix : prefixes) { contentHandler.endPrefixMapping(prefix); } }
/** {@inheritDoc} */ public String[] getPrefixes() throws RepositoryException, RemoteException { try { return registry.getPrefixes(); } catch (RepositoryException ex) { throw getRepositoryException(ex); } }
@Override public void runTest() throws RepositoryException { for (int i = 0; i < 10000; i++) { for (String prefix : registry.getPrefixes()) { registry.getURI(prefix); } } }
public NamespacesProperty(NamespaceRegistry nsReg) throws RepositoryException { super(JCR_NAMESPACES, false); if (nsReg != null) { for (String prefix : nsReg.getPrefixes()) { value.put(prefix, nsReg.getURI(prefix)); } } }
public String[] execute() throws Exception { return getDelegate().getPrefixes(); } });
@Override public String[] getNamespacePrefixes() throws RepositoryException { return getWorkspace().getNamespaceRegistry().getPrefixes(); }
/** * {@inheritDoc} */ public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException { SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo); NamespaceRegistry nsReg = sInfo.getSession().getWorkspace().getNamespaceRegistry(); Map<String, String> namespaces = new HashMap<String, String>(); for (String prefix : nsReg.getPrefixes()) { namespaces.put(prefix, nsReg.getURI(prefix)); } return namespaces; }
/** * {@inheritDoc} */ public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException { SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo); NamespaceRegistry nsReg = sInfo.getSession().getWorkspace().getNamespaceRegistry(); Map<String, String> namespaces = new HashMap<String, String>(); for (String prefix : nsReg.getPrefixes()) { namespaces.put(prefix, nsReg.getURI(prefix)); } return namespaces; }
protected void tearDown() throws Exception { try { if (Arrays.asList(nsp.getPrefixes()).contains(namespacePrefix)) { nsp.unregisterNamespace(namespacePrefix); } } catch (NamespaceException e) { log.println("Unable to unregister name space with prefix " + namespacePrefix + ": " + e.toString()); } finally { nsp = null; super.tearDown(); } }
@NotNull private String getNewNamespacePrefix(Workspace wsp) throws RepositoryException { String prefix = "prefix"; List<String> pfcs = Arrays.asList(wsp.getNamespaceRegistry().getPrefixes()); int i = 0; while (pfcs.contains(prefix)) { prefix = "prefix" + i++; } return prefix; }
private String getNewNamespacePrefix(Workspace wsp) throws RepositoryException { String prefix = "prefix"; List<String> pfcs = Arrays.asList(wsp.getNamespaceRegistry().getPrefixes()); int i = 0; while (pfcs.contains(prefix)) { prefix = "prefix" + i++; } return prefix; }
@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 assertThatNamespacePrefixIsNotRegistered( String prefix ) throws Exception { try { registry.getURI(prefix); fail("Should not have found namespace mapping with prefix \"" + prefix + "\""); } catch (NamespaceException e) { // good } for (String existingPrefix : registry.getPrefixes()) { assertThat(existingPrefix, is(not(prefix))); } }