- protected void importNodeTypeDefinitions(final Repository repository) {
- Runnable action = new Runnable() {
- public void run() {
- Reader reader = null;
- Session session = null;
- try {
- session = repository.login();
- processNewSession(session);
- // Load cnds as resources
- for (String resUrl : cndFiles) {
- Resource res = resourceLoader.getResource(resUrl);
- byte[] arr = IOUtils.toByteArray(res.getInputStream());
- reader = new InputStreamReader(
- new ByteArrayInputStream(arr));
- CndImporter.registerNodeTypes(reader, session, true);
- }
- session.save();
- } catch (Exception e) {
- log.error(
- "Cannot import node type definitions " + cndFiles,
- e);
- JcrUtils.discardQuietly(session);
- } finally {
- IOUtils.closeQuietly(reader);
- JcrUtils.logoutQuietly(session);
- }
- }
- };
-
- if (systemExecutor != null)
- systemExecutor.execute(action);
- else
- action.run();
- }
-
- // JCR REPOSITORY (delegated)
- public String getDescriptor(String key) {
- return repository.getDescriptor(key);
- }
-
- public String[] getDescriptorKeys() {
- return repository.getDescriptorKeys();
- }
-
- public Session login() throws LoginException, RepositoryException {
- Session session = repository.login();
- processNewSession(session);
- return session;
- }
-
- public Session login(Credentials credentials, String workspaceName)
- throws LoginException, NoSuchWorkspaceException,
- RepositoryException {
- Session session;
- try {
- session = repository.login(credentials, workspaceName);
- } catch (NoSuchWorkspaceException e) {
- if (autocreateWorkspaces)
- session = createWorkspaceAndLogsIn(credentials, workspaceName);
- else
- throw e;
- }
- processNewSession(session);
- return session;
- }
-
- public Session login(Credentials credentials) throws LoginException,
- RepositoryException {
- Session session = repository.login(credentials);
- processNewSession(session);
- return session;
- }
-
- public Session login(String workspaceName) throws LoginException,
- NoSuchWorkspaceException, RepositoryException {
- Session session;
- try {
- session = repository.login(workspaceName);
- } catch (NoSuchWorkspaceException e) {
- if (autocreateWorkspaces)
- session = createWorkspaceAndLogsIn(null, workspaceName);
- else
- throw e;
- }
- processNewSession(session);
- return session;
- }
-
- protected synchronized void processNewSession(Session session) {
- try {
- NamespaceHelper namespaceHelper = new NamespaceHelper(session);
- namespaceHelper.registerNamespaces(namespaces);
- } catch (Exception e) {
- throw new ArgeoException("Cannot process new session", e);
- }
- }
-
- /**
- * Logs in to the default workspace, creates the required workspace, logs
- * out, logs in to the required workspace.
- */
- protected Session createWorkspaceAndLogsIn(Credentials credentials,
- String workspaceName) throws RepositoryException {
- if (workspaceName == null)
- throw new ArgeoException("No workspace specified.");
- Session session = repository.login(credentials);
- session.getWorkspace().createWorkspace(workspaceName);
- session.logout();
- return repository.login(credentials, workspaceName);
- }