Search in sources :

Example 96 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class WorkspaceTest method testDeleteWorkspace.

public void testDeleteWorkspace() throws Exception {
    try {
        Workspace wsp = superuser.getWorkspace();
        String name = getNewWorkspaceName(wsp);
        wsp.createWorkspace(name, wsp.getName());
        List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertTrue(wsps.contains(name));
        wsp.deleteWorkspace(name);
        wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertFalse(wsps.contains(name));
        Session s = null;
        try {
            s = getHelper().getSuperuserSession(name);
            fail(name + " has been deleted.");
        } catch (NoSuchWorkspaceException e) {
        // success
        } finally {
            if (s != null) {
                s.logout();
            }
        }
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException();
    } catch (UnsupportedOperationException e) {
        throw new NotExecutableException();
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Workspace(javax.jcr.Workspace) Session(javax.jcr.Session)

Example 97 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class RepositoryServiceImpl method getPrivilegeDefinitions.

@Override
public PrivilegeDefinition[] getPrivilegeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Session session = sInfo.getSession();
    Workspace wsp = session.getWorkspace();
    Collection<Privilege> privs;
    if (wsp instanceof JackrabbitWorkspace) {
        privs = Arrays.asList(((JackrabbitWorkspace) wsp).getPrivilegeManager().getRegisteredPrivileges());
    } else {
        Privilege jcrAll = session.getAccessControlManager().privilegeFromName(Privilege.JCR_ALL);
        privs = new HashSet<Privilege>();
        privs.add(jcrAll);
        for (Privilege p : jcrAll.getAggregatePrivileges()) {
            privs.add(p);
        }
    }
    PrivilegeDefinition[] pDefs = new PrivilegeDefinition[privs.size()];
    NamePathResolver npResolver = sInfo.getNamePathResolver();
    int i = 0;
    for (Privilege p : privs) {
        Set<Name> aggrnames = null;
        if (p.isAggregate()) {
            aggrnames = new HashSet<Name>();
            for (Privilege dap : p.getDeclaredAggregatePrivileges()) {
                aggrnames.add(npResolver.getQName(dap.getName()));
            }
        }
        PrivilegeDefinition def = new PrivilegeDefinitionImpl(npResolver.getQName(p.getName()), p.isAbstract(), aggrnames);
        pDefs[i++] = def;
    }
    return pDefs;
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Name(org.apache.jackrabbit.spi.Name) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 98 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class RepositoryServiceImpl method createWorkspace.

/**
     * {@inheritDoc}
     */
public void createWorkspace(SessionInfo sessionInfo, String name, String srcWorkspaceName) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Workspace wsp = sInfo.getSession().getWorkspace();
    if (srcWorkspaceName == null) {
        wsp.createWorkspace(name);
    } else {
        wsp.createWorkspace(name, srcWorkspaceName);
    }
}
Also used : JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 99 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class RepositoryServiceImpl method deleteWorkspace.

/**
     * {@inheritDoc}
     */
public void deleteWorkspace(SessionInfo sessionInfo, String name) throws AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Workspace wsp = sInfo.getSession().getWorkspace();
    wsp.deleteWorkspace(name);
}
Also used : JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 100 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class Copy method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String srcWorkspace = (String) ctx.get(this.srcWorkspaceKey);
    String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
    String destAbsPath = (String) ctx.get(this.destAbsPathKey);
    Workspace w = CommandHelper.getSession(ctx).getWorkspace();
    if (srcWorkspace == null) {
        srcWorkspace = w.getName();
    }
    if (log.isDebugEnabled()) {
        log.debug("copying node from [" + srcWorkspace + ":" + srcAbsPath + "] to [" + w.getName() + ":" + destAbsPath + "]");
    }
    if (destAbsPath.endsWith("/")) {
        Item source = CommandHelper.getSession(ctx).getItem(srcAbsPath);
        destAbsPath = destAbsPath + source.getName();
    }
    w.copy(srcWorkspace, srcAbsPath, destAbsPath);
    return false;
}
Also used : Item(javax.jcr.Item) Workspace(javax.jcr.Workspace)

Aggregations

Workspace (javax.jcr.Workspace)105 Node (javax.jcr.Node)51 Session (javax.jcr.Session)25 AccessDeniedException (javax.jcr.AccessDeniedException)18 Test (org.junit.Test)18 RepositoryException (javax.jcr.RepositoryException)16 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)16 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)10 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)8 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ObservationManager (javax.jcr.observation.ObservationManager)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 FileOutputStream (java.io.FileOutputStream)5 NodeIterator (javax.jcr.NodeIterator)4 Version (javax.jcr.version.Version)4