@Test public void testRegisterNamespaces() throws Exception { Properties namespaces = new Properties(); namespaces.put("foo", "bar"); namespaces.put("hocus", "pocus"); factory.setNamespaces(namespaces); Session session = createMock(Session.class); Workspace workspace = createMock(Workspace.class); NamespaceRegistry namespaceRegistry = createMock(NamespaceRegistry.class); expect(repository.login(null, null)).andReturn(session); expect(session.getWorkspace()).andReturn(workspace); expect(workspace.getNamespaceRegistry()).andReturn(namespaceRegistry); expect(namespaceRegistry.getPrefixes()).andReturn(new String[0]); namespaceRegistry.registerNamespace("foo", "bar"); namespaceRegistry.registerNamespace("hocus", "pocus"); session.logout(); replay(namespaceRegistry, workspace, session, repository); factory.afterPropertiesSet(); factory.destroy(); verify(namespaceRegistry, workspace, session); }
protected void registerNamespaces() throws Exception { if (namespaces == null || namespaces.isEmpty()) return; if (LOG.isDebugEnabled()) LOG.debug("registering custom namespaces " + namespaces); Session session = getBareSession(); NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); String[] prefixes = registry.getPrefixes(); Arrays.sort(prefixes); if (forceNamespacesRegistration) { if (!keepNewNamespaces) overwrittenNamespaces = new HashMap<String, String>(namespaces.size()); for (Object key : namespaces.keySet()) { String prefix = (String) key; int position = Arrays.binarySearch(prefixes, prefix); if (position >= 0) { if (LOG.isDebugEnabled()) { LOG.debug("prefix " + prefix + " was already registered; unregistering it"); } if (!keepNewNamespaces) { overwrittenNamespaces.put(prefix, registry.getURI(prefix)); } registry.unregisterNamespace(prefix); } } } for (Map.Entry<?, ?> entry : namespaces.entrySet()) { String prefix = (String) entry.getKey(); String ns = (String) entry.getValue(); int position = Arrays.binarySearch(prefixes, prefix); if (skipExistingNamespaces && position >= 0) { LOG.debug("namespace already registered under [" + prefix + "]; skipping registration"); } else { LOG.debug("registering namespace [" + ns + "] under [" + prefix + "]"); registry.registerNamespace(prefix, ns); } } session.logout(); }
JcrSessionFactory implements InitializingBean, DisposableBean, SessionFactory { protected void registerNamespaces() throws Exception { if (namespaces == null || namespaces.isEmpty()) return; if (LOG.isDebugEnabled()) LOG.debug("registering custom namespaces " + namespaces); Session session = getBareSession(); NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); String[] prefixes = registry.getPrefixes(); Arrays.sort(prefixes); if (forceNamespacesRegistration) { if (!keepNewNamespaces) overwrittenNamespaces = new HashMap<String, String>(namespaces.size()); for (Object key : namespaces.keySet()) { String prefix = (String) key; int position = Arrays.binarySearch(prefixes, prefix); if (position >= 0) { if (LOG.isDebugEnabled()) { LOG.debug("prefix " + prefix + " was already registered; unregistering it"); } if (!keepNewNamespaces) { overwrittenNamespaces.put(prefix, registry.getURI(prefix)); } registry.unregisterNamespace(prefix); } } } for (Map.Entry<?, ?> entry : namespaces.entrySet()) { String prefix = (String) entry.getKey(); String ns = (String) entry.getValue(); int position = Arrays.binarySearch(prefixes, prefix); if (skipExistingNamespaces && position >= 0) { LOG.debug("namespace already registered under [" + prefix + "]; skipping registration"); } else { LOG.debug("registering namespace [" + ns + "] under [" + prefix + "]"); registry.registerNamespace(prefix, ns); } } session.logout(); } }
JcrSessionFactory implements InitializingBean, DisposableBean, SessionFactory { protected void registerNamespaces() throws Exception { if (namespaces == null || namespaces.isEmpty()) return; if (LOG.isDebugEnabled()) LOG.debug("registering custom namespaces " + namespaces); Session session = getBareSession(); NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); String[] prefixes = registry.getPrefixes(); Arrays.sort(prefixes); if (forceNamespacesRegistration) { if (!keepNewNamespaces) overwrittenNamespaces = new HashMap<String, String>(namespaces.size()); for (Object key : namespaces.keySet()) { String prefix = (String) key; int position = Arrays.binarySearch(prefixes, prefix); if (position >= 0) { if (LOG.isDebugEnabled()) { LOG.debug("prefix " + prefix + " was already registered; unregistering it"); } if (!keepNewNamespaces) { overwrittenNamespaces.put(prefix, registry.getURI(prefix)); } registry.unregisterNamespace(prefix); } } } for (Map.Entry<?, ?> entry : namespaces.entrySet()) { String prefix = (String) entry.getKey(); String ns = (String) entry.getValue(); int position = Arrays.binarySearch(prefixes, prefix); if (skipExistingNamespaces && position >= 0) { LOG.debug("namespace already registered under [" + prefix + "]; skipping registration"); } else { LOG.debug("registering namespace [" + ns + "] under [" + prefix + "]"); registry.registerNamespace(prefix, ns); } } session.logout(); } JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials);  JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials, SessionHolderProviderManager sessionHolderProviderManager);  JcrSessionFactory(); }
JcrSessionFactory implements InitializingBean, DisposableBean, SessionFactory { protected void registerNamespaces() throws Exception { if (namespaces == null || namespaces.isEmpty()) return; if (LOG.isDebugEnabled()) LOG.debug("registering custom namespaces " + namespaces); Session session = getBareSession(); NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); String[] prefixes = registry.getPrefixes(); Arrays.sort(prefixes); if (forceNamespacesRegistration) { if (!keepNewNamespaces) overwrittenNamespaces = new HashMap<String, String>(namespaces.size()); for (Object key : namespaces.keySet()) { String prefix = (String) key; int position = Arrays.binarySearch(prefixes, prefix); if (position >= 0) { if (LOG.isDebugEnabled()) { LOG.debug("prefix " + prefix + " was already registered; unregistering it"); } if (!keepNewNamespaces) { overwrittenNamespaces.put(prefix, registry.getURI(prefix)); } registry.unregisterNamespace(prefix); } } } for (Map.Entry<?, ?> entry : namespaces.entrySet()) { String prefix = (String) entry.getKey(); String ns = (String) entry.getValue(); int position = Arrays.binarySearch(prefixes, prefix); if (skipExistingNamespaces && position >= 0) { LOG.debug("namespace already registered under [" + prefix + "]; skipping registration"); } else { LOG.debug("registering namespace [" + ns + "] under [" + prefix + "]"); registry.registerNamespace(prefix, ns); } } session.logout(); } JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials);  JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials, SessionHolderProviderManager sessionHolderProviderManager);  JcrSessionFactory(); @Override void afterPropertiesSet(); @Override void destroy(); @Override Session getSession(); @Override SessionHolder getSessionHolder(Session session); Repository getRepository(); void setRepository(Repository repository); void setWorkspaceName(String workspaceName); void setCredentials(Credentials credentials); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); EventListenerDefinition[] getEventListeners(); void setEventListeners(EventListenerDefinition[] eventListenerDefinitions); Properties getNamespaces(); void setNamespaces(Properties namespaces); SessionHolderProviderManager getSessionHolderProviderManager(); void setSessionHolderProviderManager(SessionHolderProviderManager sessionHolderProviderManager); void setKeepNewNamespaces(boolean keepNamespaces); void setForceNamespacesRegistration(boolean forceNamespacesRegistration); void setSkipExistingNamespaces(boolean skipRegisteredNamespace); boolean isForceNamespacesRegistration(); boolean isKeepNewNamespaces(); boolean isSkipExistingNamespaces(); Credentials getCredentials(); String getWorkspaceName(); }
JcrSessionFactory implements InitializingBean, DisposableBean, SessionFactory { protected void registerNamespaces() throws Exception { if (namespaces == null || namespaces.isEmpty()) return; if (LOG.isDebugEnabled()) LOG.debug("registering custom namespaces " + namespaces); Session session = getBareSession(); NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry(); String[] prefixes = registry.getPrefixes(); Arrays.sort(prefixes); if (forceNamespacesRegistration) { if (!keepNewNamespaces) overwrittenNamespaces = new HashMap<String, String>(namespaces.size()); for (Object key : namespaces.keySet()) { String prefix = (String) key; int position = Arrays.binarySearch(prefixes, prefix); if (position >= 0) { if (LOG.isDebugEnabled()) { LOG.debug("prefix " + prefix + " was already registered; unregistering it"); } if (!keepNewNamespaces) { overwrittenNamespaces.put(prefix, registry.getURI(prefix)); } registry.unregisterNamespace(prefix); } } } for (Map.Entry<?, ?> entry : namespaces.entrySet()) { String prefix = (String) entry.getKey(); String ns = (String) entry.getValue(); int position = Arrays.binarySearch(prefixes, prefix); if (skipExistingNamespaces && position >= 0) { LOG.debug("namespace already registered under [" + prefix + "]; skipping registration"); } else { LOG.debug("registering namespace [" + ns + "] under [" + prefix + "]"); registry.registerNamespace(prefix, ns); } } session.logout(); } JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials);  JcrSessionFactory(Repository repository, String workspaceName, Credentials credentials, SessionHolderProviderManager sessionHolderProviderManager);  JcrSessionFactory(); @Override void afterPropertiesSet(); @Override void destroy(); @Override Session getSession(); @Override SessionHolder getSessionHolder(Session session); Repository getRepository(); void setRepository(Repository repository); void setWorkspaceName(String workspaceName); void setCredentials(Credentials credentials); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); EventListenerDefinition[] getEventListeners(); void setEventListeners(EventListenerDefinition[] eventListenerDefinitions); Properties getNamespaces(); void setNamespaces(Properties namespaces); SessionHolderProviderManager getSessionHolderProviderManager(); void setSessionHolderProviderManager(SessionHolderProviderManager sessionHolderProviderManager); void setKeepNewNamespaces(boolean keepNamespaces); void setForceNamespacesRegistration(boolean forceNamespacesRegistration); void setSkipExistingNamespaces(boolean skipRegisteredNamespace); boolean isForceNamespacesRegistration(); boolean isKeepNewNamespaces(); boolean isSkipExistingNamespaces(); Credentials getCredentials(); String getWorkspaceName();  }