Search in sources :

Example 51 with Workspace

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

the class NodeTypeDefinitionScanner method registerNodeTypes.

/**
     * Registers node types found in classpath in JCR repository.
     * @param session Session
     * @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
     */
private void registerNodeTypes(Session session, List<String> nodeTypeResources) throws RepositoryException {
    ClassLoader classLoader = getClass().getClassLoader();
    Workspace workspace = session.getWorkspace();
    NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
    NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
    ValueFactory valueFactory = session.getValueFactory();
    // try registering node types multiple times because the exact order is not known
    int iteration = 0;
    List<String> remainingNodeTypeResources = new ArrayList<String>(nodeTypeResources);
    while (!remainingNodeTypeResources.isEmpty()) {
        registerNodeTypesAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, false);
        iteration++;
        if (iteration >= MAX_ITERATIONS) {
            break;
        }
    }
    if (!remainingNodeTypeResources.isEmpty()) {
        registerNodeTypesAndRemoveSucceeds(remainingNodeTypeResources, classLoader, nodeTypeManager, namespaceRegistry, valueFactory, true);
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NamespaceRegistry(javax.jcr.NamespaceRegistry) ArrayList(java.util.ArrayList) ValueFactory(javax.jcr.ValueFactory) Workspace(javax.jcr.Workspace)

Example 52 with Workspace

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

the class WorkspaceCreator method deactivate.

@SuppressWarnings("unused")
@Deactivate
private void deactivate() {
    Session s = null;
    try {
        s = repo.loginAdministrative(null);
        Workspace w = s.getWorkspace();
        deleteWorkspace(w, "ws3");
        deleteWorkspace(w, "ws2");
        deleteWorkspace(w, "ws1");
    } catch (Exception e) {
    // ignore
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Deactivate(org.apache.felix.scr.annotations.Deactivate)

Example 53 with Workspace

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

the class JcrRouteDifferentWorkspaceTestSupport method setUp.

@Override
@Before
public void setUp() throws Exception {
    deleteDirectory(REPO_PATH);
    super.setUp();
    Session session = getRepository().login(new SimpleCredentials("user", "pass".toCharArray()));
    Workspace workspace = session.getWorkspace();
    workspace.createWorkspace(CUSTOM_WORKSPACE_NAME);
    session.save();
    session.logout();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Before(org.junit.Before)

Example 54 with Workspace

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

the class RootCollection method removeMember.

/**
     * Calls {@link Workspace#deleteWorkspace(String)} for the workspace with
     * the name as indicated by the specified member.
     *
     * @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
     */
@Override
public void removeMember(DavResource member) throws DavException {
    Workspace wsp = getRepositorySession().getWorkspace();
    String name = Text.getName(member.getResourcePath());
    try {
        wsp.deleteWorkspace(name);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace)

Example 55 with Workspace

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

the class NamespaceRegistryReadMethodsTest method setUp.

public void setUp() throws Exception {
    isReadOnly = true;
    super.setUp();
    session = getHelper().getReadOnlySession();
    Workspace ws = session.getWorkspace();
    nsr = ws.getNamespaceRegistry();
}
Also used : 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