+ private void normalInit() {
+ ConfigurationAdmin conf = findConfigurationAdmin();
+ // Initialise services
+ initTransactionManager();
+ if (repository == null)
+ repository = new NodeRepository();
+ if (repositoryFactory == null)
+ repositoryFactory = new OsgiJackrabbitRepositoryFactory();
+ userAdmin = new NodeUserAdmin(transactionManager, repository);
+
+ // HTTP
+ initWebServer(conf);
+ ServiceReference<ExtendedHttpService> sr = bc
+ .getServiceReference(ExtendedHttpService.class);
+ if (sr != null)
+ addHttpService(sr);
+
+ // ADMIN UIs
+ UserUi userUi = new UserUi();
+ Hashtable<String, String> props = new Hashtable<String, String>();
+ props.put("contextName", "user");
+ bc.registerService(ApplicationConfiguration.class, userUi, props);
+
+ // Kernel thread
+ kernelThread = new KernelThread(this);
+ kernelThread.setContextClassLoader(Kernel.class.getClassLoader());
+ kernelThread.start();
+
+ // Publish services to OSGi
+ publish();
+ }
+
+ private boolean isMaintenance() {
+ String startLevel = KernelUtils.getFrameworkProp("osgi.startLevel");
+ if (startLevel == null)
+ return false;
+ int bundleStartLevel = bc.getBundle().adapt(BundleStartLevel.class)
+ .getStartLevel();
+ // int frameworkStartLevel =
+ // bc.getBundle(0).adapt(BundleStartLevel.class)
+ // .getStartLevel();
+ int frameworkStartLevel = Integer.parseInt(startLevel);
+ // int frameworkStartLevel = bc.getBundle(0)
+ // .adapt(FrameworkStartLevel.class).getStartLevel();
+ return bundleStartLevel == frameworkStartLevel;
+ }
+
+ private void maintenanceInit() {
+ log.info("## MAINTENANCE ##");
+ bc.addServiceListener(Kernel.this);
+ initWebServer(null);
+ MaintenanceUi maintenanceUi = new MaintenanceUi();
+ Hashtable<String, String> props = new Hashtable<String, String>();
+ props.put("contextName", "maintenance");
+ bc.registerService(ApplicationConfiguration.class, maintenanceUi, props);
+ }
+
+ private void firstInit() {
+ log.info("## FIRST INIT ##");
+ String nodeInit = getFrameworkProp(NODE_INIT);
+ if (nodeInit == null)
+ nodeInit = "../../init";
+ if (nodeInit.startsWith("http")) {
+ remoteFirstInit(nodeInit);
+ return;
+ }
+ File initDir;
+ if (nodeInit.startsWith("."))
+ initDir = KernelUtils.getExecutionDir(nodeInit);
+ else
+ initDir = new File(nodeInit);
+ // TODO also uncompress archives
+ if (initDir.exists())
+ try {
+ FileUtils.copyDirectory(initDir, getOsgiInstanceDir(),
+ new FileFilter() {
+
+ @Override
+ public boolean accept(File pathname) {
+ if (pathname.getName().equals(".svn")
+ || pathname.getName().equals(".git"))
+ return false;
+ return true;
+ }
+ });
+ log.info("CMS initialized from " + initDir.getCanonicalPath());
+ } catch (IOException e) {
+ throw new CmsException("Cannot initialize from " + initDir, e);
+ }
+ }
+
+ private void remoteFirstInit(String uri) {
+ try {
+ repository = new NodeRepository();
+ repositoryFactory = new OsgiJackrabbitRepositoryFactory();
+ Repository remoteRepository = ArgeoJcrUtils.getRepositoryByUri(
+ repositoryFactory, uri);
+ Session remoteSession = remoteRepository
+ .login(new SimpleCredentials("root", "demo".toCharArray()),
+ "main");
+ Session localSession = this.repository.login();
+ // FIXME register node type
+ // if (false)
+ // CndImporter.registerNodeTypes(null, localSession);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ remoteSession.exportSystemView("/", out, true, false);
+ ByteArrayInputStream in = new ByteArrayInputStream(
+ out.toByteArray());
+ localSession.importXML("/", in,
+ ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
+ // JcrUtils.copy(remoteSession.getRootNode(),
+ // localSession.getRootNode());
+ } catch (Exception e) {
+ throw new CmsException("Cannot first init from " + uri, e);
+ }
+ }
+
+ /** Can be null */
+ private ConfigurationAdmin findConfigurationAdmin() {
+ configurationAdmin = bc.getServiceReference(ConfigurationAdmin.class);
+ if (configurationAdmin == null) {
+ return null;
+ }
+ return bc.getService(configurationAdmin);
+ }
+
+ private void initTransactionManager() {
+ bitronix.tm.Configuration tmConf = TransactionManagerServices
+ .getConfiguration();