+ log.debug(request.getRequestURI() + "\n");
+ }
+
+ static void logFrameworkProperties(Log log) {
+ BundleContext bc = getBundleContext();
+ for (Object sysProp : new TreeSet<Object>(System.getProperties().keySet())) {
+ log.debug(sysProp + "=" + bc.getProperty(sysProp.toString()));
+ }
+ // String[] keys = { Constants.FRAMEWORK_STORAGE,
+ // Constants.FRAMEWORK_OS_NAME, Constants.FRAMEWORK_OS_VERSION,
+ // Constants.FRAMEWORK_PROCESSOR, Constants.FRAMEWORK_SECURITY,
+ // Constants.FRAMEWORK_TRUST_REPOSITORIES,
+ // Constants.FRAMEWORK_WINDOWSYSTEM, Constants.FRAMEWORK_VENDOR,
+ // Constants.FRAMEWORK_VERSION, Constants.FRAMEWORK_STORAGE_CLEAN,
+ // Constants.FRAMEWORK_LANGUAGE, Constants.FRAMEWORK_UUID };
+ // for (String key : keys)
+ // log.debug(key + "=" + bc.getProperty(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(AuthConstants.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);
+ }
+ }
+
+ });
+ }
+
+ /**
+ * @return the {@link BundleContext} of the {@link Bundle} which provided
+ * this class, never null.
+ * @throws CmsException
+ * if the related bundle is not active
+ */
+ public 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;
+ }
+
+ private static BundleContext getBundleContext() {
+ return getBundleContext(KernelUtils.class);
+ }
+
+ 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);
+ }