Search in sources :

Example 1 with WorkspaceConfig

use of org.apache.jackrabbit.core.config.WorkspaceConfig in project jackrabbit by apache.

the class RepositoryImpl method createWorkspaceInternal.

/**
     * Creates a workspace with the given name and given workspace configuration
     * template.
     *
     * The difference between this method and {@link #createWorkspace(String, InputSource)}
     * is that the later notifies the other cluster node that workspace has been created
     * whereas this method only creates the workspace.
     *
     * @param workspaceName  name of the new workspace
     * @param configTemplate the workspace configuration template of the new
     *                       workspace
     * @throws RepositoryException if a workspace with the given name already
     *                             exists or if another error occurs
     * @see WorkspaceImpl#createWorkspace(String,InputSource)
     */
private void createWorkspaceInternal(String workspaceName, InputSource configTemplate) throws RepositoryException {
    synchronized (wspInfos) {
        if (wspInfos.containsKey(workspaceName)) {
            throw new RepositoryException("workspace '" + workspaceName + "' already exists.");
        }
        // create the workspace configuration
        WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName, configTemplate);
        WorkspaceInfo info = createWorkspaceInfo(config);
        wspInfos.put(workspaceName, info);
    }
}
Also used : WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) RepositoryException(javax.jcr.RepositoryException)

Example 2 with WorkspaceConfig

use of org.apache.jackrabbit.core.config.WorkspaceConfig in project jackrabbit by apache.

the class RepositoryImpl method createWorkspace.

/**
     * Creates a workspace with the given name.
     *
     * @param workspaceName name of the new workspace
     * @throws RepositoryException if a workspace with the given name
     *                             already exists or if another error occurs
     * @see WorkspaceImpl#createWorkspace(String)
     */
protected void createWorkspace(String workspaceName) throws RepositoryException {
    synchronized (wspInfos) {
        if (wspInfos.containsKey(workspaceName)) {
            throw new RepositoryException("workspace '" + workspaceName + "' already exists.");
        }
        // needed to get newly created workspace config file content when
        // running in clustered environment
        StringBuffer workspaceConfigContent = null;
        if (context.getClusterNode() != null) {
            workspaceConfigContent = new StringBuffer();
        }
        // create the workspace configuration
        WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName, workspaceConfigContent);
        WorkspaceInfo info = createWorkspaceInfo(config);
        wspInfos.put(workspaceName, info);
        if (workspaceConfigContent != null && createWorkspaceEventChannel != null) {
            // notify other cluster node that workspace has been created
            InputSource s = new InputSource(new StringReader(workspaceConfigContent.toString()));
            createWorkspaceEventChannel.workspaceCreated(workspaceName, new ClonedInputSource(s));
        }
    }
}
Also used : ClonedInputSource(org.apache.jackrabbit.core.xml.ClonedInputSource) InputSource(org.xml.sax.InputSource) ClonedInputSource(org.apache.jackrabbit.core.xml.ClonedInputSource) StringReader(java.io.StringReader) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) RepositoryException(javax.jcr.RepositoryException)

Example 3 with WorkspaceConfig

use of org.apache.jackrabbit.core.config.WorkspaceConfig in project jackrabbit by apache.

the class PersistenceManagerIteratorTest method testGetAllNodeIds.

public void testGetAllNodeIds() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    Repository rep = session.getRepository();
    if (!(rep instanceof RepositoryImpl)) {
        log("Test skipped. Required repository class: " + RepositoryImpl.class + " got: " + rep.getClass());
        return;
    }
    RepositoryImpl r = (RepositoryImpl) rep;
    RepositoryConfig conf = r.getConfig();
    Collection<WorkspaceConfig> coll = conf.getWorkspaceConfigs();
    String[] names = new String[coll.size()];
    Iterator<WorkspaceConfig> wspIt = coll.iterator();
    for (int i = 0; wspIt.hasNext(); i++) {
        WorkspaceConfig wsc = wspIt.next();
        names[i] = wsc.getName();
    }
    for (int i = 0; i < names.length && i < 1; i++) {
        Session s = getHelper().getSuperuserSession(names[i]);
        try {
            Method m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class });
            m.setAccessible(true);
            Object info = m.invoke(r, names[i]);
            m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
            m.setAccessible(true);
            PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
            if (!(pm instanceof AbstractBundlePersistenceManager)) {
                log("PM skipped: " + pm.getClass());
                continue;
            }
            AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
            log("PM: " + pm.getClass().getName());
            log("All nodes in one step");
            NodeId after = null;
            NodeId first = null;
            for (NodeId id : apm.getAllNodeIds(null, 0)) {
                log("  " + id);
                if (first == null) {
                    // initialize first node id
                    first = id;
                }
                if (after != null) {
                    assertFalse(id.compareTo(after) == 0);
                }
                after = id;
            }
            // start with first
            after = first;
            log("All nodes using batches");
            while (true) {
                log(" bigger than: " + after);
                Iterator<NodeId> it = apm.getAllNodeIds(after, 2).iterator();
                if (!it.hasNext()) {
                    break;
                }
                while (it.hasNext()) {
                    NodeId id = it.next();
                    log("    " + id);
                    assertFalse(id.compareTo(after) == 0);
                    after = id;
                }
            }
            log("Random access");
            for (int j = 0; j < 50; j++) {
                after = NodeId.randomId();
                log(" bigger than: " + after);
                for (NodeId id : apm.getAllNodeIds(after, 2)) {
                    log("    " + id);
                    assertFalse(id.compareTo(after) == 0);
                    after = id;
                }
            }
        } finally {
            s.logout();
        }
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) AbstractBundlePersistenceManager(org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager) Node(javax.jcr.Node) Method(java.lang.reflect.Method) Repository(javax.jcr.Repository) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) AbstractBundlePersistenceManager(org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager) Session(javax.jcr.Session)

Example 4 with WorkspaceConfig

use of org.apache.jackrabbit.core.config.WorkspaceConfig in project jackrabbit by apache.

the class DefaultSecurityManager method getAccessControlProvider.

//--------------------------------------------------------------------------
/**
     * Returns the access control provider for the specified
     * <code>workspaceName</code>.
     *
     * @param workspaceName Name of the workspace.
     * @return access control provider
     * @throws NoSuchWorkspaceException If no workspace with 'workspaceName' exists.
     * @throws RepositoryException
     */
private AccessControlProvider getAccessControlProvider(String workspaceName) throws NoSuchWorkspaceException, RepositoryException {
    checkInitialized();
    AccessControlProvider provider = acProviders.get(workspaceName);
    if (provider == null || !provider.isLive()) {
        // mark this workspace as 'active' so the workspace does not
        // get disposed by the workspace-janitor
        // TODO: There should be a cleaner way to do this.
        repository.markWorkspaceActive(workspaceName);
        WorkspaceSecurityConfig secConf = null;
        WorkspaceConfig conf = repository.getConfig().getWorkspaceConfig(workspaceName);
        if (conf != null) {
            secConf = conf.getSecurityConfig();
        }
        provider = acProviderFactory.createProvider(repository.getSystemSession(workspaceName), secConf);
        synchronized (acProviders) {
            acProviders.put(workspaceName, provider);
        }
    }
    return provider;
}
Also used : WorkspaceSecurityConfig(org.apache.jackrabbit.core.config.WorkspaceSecurityConfig) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig)

Aggregations

WorkspaceConfig (org.apache.jackrabbit.core.config.WorkspaceConfig)4 RepositoryException (javax.jcr.RepositoryException)2 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1 Node (javax.jcr.Node)1 Repository (javax.jcr.Repository)1 Session (javax.jcr.Session)1 RepositoryImpl (org.apache.jackrabbit.core.RepositoryImpl)1 RepositoryConfig (org.apache.jackrabbit.core.config.RepositoryConfig)1 WorkspaceSecurityConfig (org.apache.jackrabbit.core.config.WorkspaceSecurityConfig)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 PersistenceManager (org.apache.jackrabbit.core.persistence.PersistenceManager)1 AbstractBundlePersistenceManager (org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager)1 AccessControlProvider (org.apache.jackrabbit.core.security.authorization.AccessControlProvider)1 ClonedInputSource (org.apache.jackrabbit.core.xml.ClonedInputSource)1 InputSource (org.xml.sax.InputSource)1