X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FSimpleApp.java;h=327438b56c58b04690fa5321bf644756d93ed472;hb=92b77a90db637e71a7ccbc76fc12bad6ba4a289a;hp=b75c700078d7bff8a81840390a94f3a99c2c30da;hpb=c811008ac91053f068c26f48427617de9bb7b79c;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/SimpleApp.java b/org.argeo.cms.ui/src/org/argeo/cms/util/SimpleApp.java index b75c70007..327438b56 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/util/SimpleApp.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/util/SimpleApp.java @@ -2,10 +2,8 @@ package org.argeo.cms.util; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; -import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -28,6 +26,7 @@ import org.argeo.cms.ui.CmsUiProvider; import org.argeo.cms.ui.LifeCycleUiProvider; import org.argeo.jcr.JcrUtils; import org.argeo.node.NodeConstants; +import org.argeo.node.NodeUtils; import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.application.Application; import org.eclipse.rap.rwt.application.Application.OperationMode; @@ -109,7 +108,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration { // favicon if (properties.containsKey(WebClient.FAVICON)) { String themeId = defaultBranding.get(WebClient.THEME_ID); - Bundle themeBundle = findThemeBundle(themeId); + Bundle themeBundle = ThemeUtils.findThemeBundle(bundleContext, themeId); String faviconRelPath = properties.get(WebClient.FAVICON); application.addResource(faviconRelPath, new BundleResourceLoader(themeBundle != null ? themeBundle : bundleContext.getBundle())); @@ -139,7 +138,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration { // stylesheets and themes Set themeBundles = new HashSet<>(); for (String themeId : styleSheets.keySet()) { - Bundle themeBundle = findThemeBundle(themeId); + Bundle themeBundle = ThemeUtils.findThemeBundle(bundleContext, themeId); StyleSheetResourceLoader styleSheetRL = new StyleSheetResourceLoader( themeBundle != null ? themeBundle : bundleContext.getBundle()); if (themeBundle != null) @@ -149,16 +148,16 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration { log.debug("Theme " + themeId); for (String css : cssLst) { application.addStyleSheet(themeId, css, styleSheetRL); - if (log.isTraceEnabled()) - log.trace(" CSS " + css); + if (log.isDebugEnabled()) + log.debug(" CSS " + css); } } for (Bundle themeBundle : themeBundles) { BundleResourceLoader themeBRL = new BundleResourceLoader(themeBundle); - addThemeResources(application, themeBundle, themeBRL, "*.png"); - addThemeResources(application, themeBundle, themeBRL, "*.gif"); - addThemeResources(application, themeBundle, themeBRL, "*.jpg"); + ThemeUtils.addThemeResources(application, themeBundle, themeBRL, "*.png"); + ThemeUtils.addThemeResources(application, themeBundle, themeBRL, "*.gif"); + ThemeUtils.addThemeResources(application, themeBundle, themeBRL, "*.jpg"); } } catch (RuntimeException e) { // Easier access to initialisation errors @@ -167,45 +166,11 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration { } } - private Bundle findThemeBundle(String themeId) { - if (themeId == null) - return null; - // TODO optimize - // TODO deal with multiple versions - Bundle themeBundle = null; - if (themeId != null) { - for (Bundle bundle : bundleContext.getBundles()) - if (themeId.equals(bundle.getSymbolicName())) { - themeBundle = bundle; - break; - } - } - return themeBundle; - } - - private void addThemeResources(Application application, Bundle themeBundle, BundleResourceLoader themeBRL, - String pattern) { - Enumeration themeResources = themeBundle.findEntries("/", pattern, true); - if (themeResources == null) - return; - while (themeResources.hasMoreElements()) { - String resource = themeResources.nextElement().getPath(); - // remove first '/' so that RWT registers it - resource = resource.substring(1); - if (!resource.endsWith("/")) { - application.addResource(resource, themeBRL); - if (log.isTraceEnabled()) - log.trace("Registered " + resource + " from theme " + themeBundle); - } - - } - - } - public void init() throws RepositoryException { Session session = null; try { - session = JcrUtils.loginOrCreateWorkspace(repository, workspace); + session = NodeUtils.openDataAdminSession(repository, workspace); + // session = JcrUtils.loginOrCreateWorkspace(repository, workspace); VersionManager vm = session.getWorkspace().getVersionManager(); JcrUtils.mkdirs(session, jcrBasePath); session.save();