+ static void printSystemProperties(PrintStream out) {
+ TreeMap<String, String> display = new TreeMap<>();
+ for (Object key : System.getProperties().keySet())
+ display.put(key.toString(), System.getProperty(key.toString()));
+ for (String key : display.keySet())
+ out.println(key + "=" + display.get(key));
+ }
+
+ static Session openAdminSession(Repository repository) {
+ return openAdminSession(repository, null);
+ }
+
+ static Session openAdminSession(final Repository repository, final String workspaceName) {
+ ClassLoader currentCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(KernelUtils.class.getClassLoader());
+ LoginContext loginContext;
+ try {
+ loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_DATA_ADMIN);
+ loginContext.login();
+ } catch (LoginException e1) {
+ throw new CmsException("Could not login as data admin", e1);
+ } finally {
+ Thread.currentThread().setContextClassLoader(currentCl);
+ }
+ return Subject.doAs(loginContext.getSubject(), new PrivilegedAction<Session>() {
+
+ @Override
+ public Session run() {
+ try {
+ return repository.login(workspaceName);
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot open admin session", e);
+ }
+ }
+
+ });
+ }
+
+ static void asyncOpen(ServiceTracker<?, ?> st) {
+ Runnable run = new Runnable() {
+
+ @Override
+ public void run() {
+ st.open();
+ }
+ };
+ Activator.getInternalExecutorService().execute(run);
+// new Thread(run, "Open service tracker " + st).start();
+ }
+
+ /**
+ * @return the {@link BundleContext} of the {@link Bundle} which provided this
+ * class, never null.
+ * @throws CmsException if the related bundle is not active
+ */
+ static BundleContext getBundleContext(Class<?> clzz) {
+ Bundle bundle = FrameworkUtil.getBundle(clzz);
+ BundleContext bc = bundle.getBundleContext();
+ if (bc == null)
+ throw new CmsException("Bundle " + bundle.getSymbolicName() + " is not active");
+ return bc;
+ }
+
+ static BundleContext getBundleContext() {
+ return getBundleContext(KernelUtils.class);
+ }
+
+ static boolean asBoolean(String value) {
+ if (value == null)
+ return false;
+ switch (value) {
+ case "true":
+ return true;
+ case "false":
+ return false;
+ default:
+ throw new CmsException("Unsupported value for attribute " + DataModelNamespace.ABSTRACT + ": " + value);
+ }
+ }
+
+ private static URI safeUri(String uri) {
+ if (uri == null)
+ throw new CmsException("URI cannot be null");
+ try {
+ return new URI(uri);
+ } catch (URISyntaxException e) {
+ throw new CmsException("Dadly formatted URI " + uri, e);
+ }
+ }
+