예제 #1
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);
  }
예제 #2
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);
       }
     }
   }
 }
예제 #3
0
  public JCRNodeWrapper getNodeByUUID(final String uuid, final boolean checkVersion)
      throws ItemNotFoundException, RepositoryException {

    if (sessionCacheByIdentifier.containsKey(uuid)) {
      return sessionCacheByIdentifier.get(uuid);
    }
    RepositoryException originalEx = null;
    for (JCRStoreProvider provider : sessionFactory.getProviderList()) {
      if (!provider.isInitialized()) {
        logger.debug(
            "Provider "
                + provider.getKey()
                + " / "
                + provider.getClass().getName()
                + " is not yet initialized, skipping...");
        continue;
      }
      if (provider instanceof JackrabbitStoreProvider && JCRContentUtils.isNotJcrUuid(uuid)) {
        // not a valid UUID, probably a VFS node
        continue;
      }
      try {
        Session session = getProviderSession(provider);
        if (session instanceof JahiaSessionImpl
            && getUser() != null
            && sessionFactory.getCurrentAliasedUser() != null
            && sessionFactory.getCurrentAliasedUser().equals(getUser())) {
          ((JahiaSessionImpl) session).toggleThisSessionAsAliased();
        }
        Node n = session.getNodeByIdentifier(uuid);
        JCRNodeWrapper wrapper = provider.getNodeWrapper(n, this);
        if (getUser() != null
            && sessionFactory.getCurrentAliasedUser() != null
            && !sessionFactory.getCurrentAliasedUser().equals(getUser())) {
          JCRTemplate.getInstance()
              .doExecuteWithUserSession(
                  sessionFactory.getCurrentAliasedUser().getUsername(),
                  session.getWorkspace().getName(),
                  getLocale(),
                  new JCRCallback<Object>() {
                    public Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
                      return session.getNodeByUUID(uuid, checkVersion);
                    }
                  });
        }
        if (checkVersion && (versionDate != null || versionLabel != null)) {
          wrapper = getFrozenVersionAsRegular(n, provider);
        }
        sessionCacheByIdentifier.put(uuid, wrapper);
        sessionCacheByPath.put(wrapper.getPath(), wrapper);

        return wrapper;
      } catch (ItemNotFoundException ee) {
        // All good
        if (originalEx == null) {
          originalEx = ee;
        }
      } catch (UnsupportedRepositoryOperationException uso) {
        logger.debug(
            "getNodeByUUID unsupported by : "
                + provider.getKey()
                + " / "
                + provider.getClass().getName());
        if (originalEx == null) {
          originalEx = uso;
        }
      } catch (RepositoryException ex) {
        if (originalEx == null) {
          originalEx = ex;
        }
        logger.warn(
            "repository exception : "
                + provider.getKey()
                + " / "
                + provider.getClass().getName()
                + " : "
                + ex.getMessage());
      }
    }
    if (originalEx != null) {
      if (originalEx instanceof ItemNotFoundException) {
        throw originalEx;
      } else {
        throw new ItemNotFoundException(uuid, originalEx);
      }
    }

    throw new ItemNotFoundException(uuid);
  }