Ejemplo n.º 1
0
 /**
  * Applies the namespace prefix to the appropriate sessions, including the underlying provider
  * sessions.
  *
  * @param prefix
  * @param uri
  * @throws NamespaceException
  * @throws RepositoryException
  */
 public void setNamespacePrefix(String prefix, String uri)
     throws NamespaceException, RepositoryException {
   nsToPrefix.put(uri, prefix);
   prefixToNs.put(prefix, uri);
   for (Session s : sessions.values()) {
     s.setNamespacePrefix(prefix, uri);
     try {
       NamespaceRegistry nsReg = s.getWorkspace().getNamespaceRegistry();
       if (nsReg != null) {
         nsReg.registerNamespace(prefix, uri);
       }
     } catch (RepositoryException e) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             "Prefix/uri could not be registered in workspace's registry- " + prefix + "/" + uri,
             e);
       }
     }
   }
 }
Ejemplo n.º 2
0
  public Session getProviderSession(JCRStoreProvider provider) throws RepositoryException {
    if (sessions.get(provider) == null) {
      Session s = null;

      if (credentials instanceof SimpleCredentials) {
        SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;
        JahiaLoginModule.Token t =
            JahiaLoginModule.getToken(
                simpleCredentials.getUserID(), new String(simpleCredentials.getPassword()));

        s = provider.getSession(credentials, workspace.getName());

        credentials =
            JahiaLoginModule.getCredentials(
                simpleCredentials.getUserID(), t != null ? t.deniedPath : null);
      } else {
        s = provider.getSession(credentials, workspace.getName());
      }

      sessions.put(provider, s);
      for (String token : tokens) {
        s.addLockToken(token);
      }

      NamespaceRegistry namespaceRegistryWrapper = getWorkspace().getNamespaceRegistry();
      NamespaceRegistry providerNamespaceRegistry = s.getWorkspace().getNamespaceRegistry();

      if (providerNamespaceRegistry != null) {
        for (String prefix : namespaceRegistryWrapper.getPrefixes()) {
          try {
            providerNamespaceRegistry.getURI(prefix);
          } catch (NamespaceException ne) {
            providerNamespaceRegistry.registerNamespace(
                prefix, namespaceRegistryWrapper.getURI(prefix));
          }
        }
      }

      for (String prefix : prefixToNs.keySet()) {
        s.setNamespacePrefix(prefix, prefixToNs.get(prefix));
      }
    }
    return sessions.get(provider);
  }