+ /**
+ * Import declared node type definitions, trying to update them if they have
+ * changed. In case of failures an error will be logged but no exception
+ * will be thrown.
+ */
+ protected void importNodeTypeDefinitions(final Repository repository) {
+ final Credentials credentialsToUse;
+ if (systemExecutor == null) {
+ if (adminCredentials == null)
+ throw new ArgeoException(
+ "No system executor or admin credentials found");
+ credentialsToUse = adminCredentials;
+ } else {
+ credentialsToUse = null;
+ }
+
+ Runnable action = new Runnable() {
+ public void run() {
+ Reader reader = null;
+ Session session = null;
+ try {
+ session = repository.login(credentialsToUse);
+ 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();
+ }
+