You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:47:47 UTC

[sling-org-apache-sling-jcr-contentloader] 07/28: SLING-1448 - adding support for Sling-Initial-Content-Workspace manifest header

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.contentloader-2.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git

commit 23366116ded663c8deaaa4a245b9fc515d42977d
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Sat Mar 20 02:22:41 2010 +0000

    SLING-1448 - adding support for Sling-Initial-Content-Workspace manifest header
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/contentloader@925533 13f79535-47bb-0310-9956-ffa450edef68
---
 .../internal/ContentLoaderService.java             | 43 +++++++++++-----------
 .../sling/jcr/contentloader/internal/Loader.java   |  7 +++-
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
index 24d6e35..9062a13 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
@@ -60,6 +60,9 @@ import org.slf4j.LoggerFactory;
  */
 public class ContentLoaderService implements SynchronousBundleListener {
 
+    /** The manifest header to specify the workspace for initial content loading. */
+    public static final String CONTENT_WORKSPACE_HEADER = "Sling-Initial-Content-Workspace";
+
     public static final String PROPERTY_CONTENT_LOADED = "content-loaded";
     private static final String PROPERTY_CONTENT_LOADED_AT = "content-load-time";
     private static final String PROPERTY_CONTENT_LOADED_BY = "content-loaded-by";
@@ -135,20 +138,21 @@ public class ContentLoaderService implements SynchronousBundleListener {
         //
 
         Session session = null;
+        final Bundle bundle = event.getBundle();
         switch (event.getType()) {
             case BundleEvent.STARTING:
                 // register content when the bundle content is available
                 // as node types are registered when the bundle is installed
                 // we can safely add the content at this point.
                 try {
-                    session = this.getSession();
-                    final boolean isUpdate = this.updatedBundles.remove(event.getBundle().getSymbolicName());
-                    initialContentLoader.registerBundle(session, event.getBundle(), isUpdate);
+                    session = this.getSession(bundle);
+                    final boolean isUpdate = this.updatedBundles.remove(bundle.getSymbolicName());
+                    initialContentLoader.registerBundle(session, bundle, isUpdate);
                 } catch (Throwable t) {
                     log.error(
                         "bundleChanged: Problem loading initial content of bundle "
-                            + event.getBundle().getSymbolicName() + " ("
-                            + event.getBundle().getBundleId() + ")", t);
+                            + bundle.getSymbolicName() + " ("
+                            + bundle.getBundleId() + ")", t);
                 } finally {
                     this.ungetSession(session);
                 }
@@ -156,17 +160,17 @@ public class ContentLoaderService implements SynchronousBundleListener {
             case BundleEvent.UPDATED:
                 // we just add the symbolic name to the list of updated bundles
                 // we will use this info when the new start event is triggered
-                this.updatedBundles.add(event.getBundle().getSymbolicName());
+                this.updatedBundles.add(bundle.getSymbolicName());
                 break;
             case BundleEvent.UNINSTALLED:
                 try {
-                    session = this.getSession();
-                    initialContentLoader.unregisterBundle(session, event.getBundle());
+                    session = this.getSession(bundle);
+                    initialContentLoader.unregisterBundle(session, bundle);
                 } catch (Throwable t) {
                     log.error(
                         "bundleChanged: Problem unloading initial content of bundle "
-                            + event.getBundle().getSymbolicName() + " ("
-                            + event.getBundle().getBundleId() + ")", t);
+                            + bundle.getSymbolicName() + " ("
+                            + bundle.getBundleId() + ")", t);
                 } finally {
                     this.ungetSession(session);
                 }
@@ -247,10 +251,7 @@ public class ContentLoaderService implements SynchronousBundleListener {
             passwordDigestAlgoritm = DEFAULT_PASSWORD_DIGEST_ALGORITHM;
         }
 
-        Session session = null;
         try {
-            session = this.getSession();
-            this.createRepositoryPath(session, ContentLoaderService.BUNDLE_CONTENT_NODE);
             log.debug(
                     "Activated - attempting to load content from all "
                     + "bundles which are neither INSTALLED nor UNINSTALLED");
@@ -259,6 +260,7 @@ public class ContentLoaderService implements SynchronousBundleListener {
             Bundle[] bundles = componentContext.getBundleContext().getBundles();
             for (Bundle bundle : bundles) {
                 if ((bundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
+                    Session session = getSession(bundle);
                     // load content for bundles which are neither INSTALLED nor
                     // UNINSTALLED
                     try {
@@ -269,9 +271,7 @@ public class ContentLoaderService implements SynchronousBundleListener {
                                 + bundle.getSymbolicName() + " ("
                                 + bundle.getBundleId() + ")", t);
                     } finally {
-                        if ( session.hasPendingChanges() ) {
-                            session.refresh(false);
-                        }
+                        this.ungetSession(session);
                     }
                 } else {
                     ignored++;
@@ -287,8 +287,6 @@ public class ContentLoaderService implements SynchronousBundleListener {
         } catch (Throwable t) {
             log.error("activate: Problem while loading initial content and"
                 + " registering mappings for existing bundles", t);
-        } finally {
-            this.ungetSession(session);
         }
     }
 
@@ -311,11 +309,14 @@ public class ContentLoaderService implements SynchronousBundleListener {
     }
 
     /**
-     * Returns an administrative session to the default workspace.
+     * Returns an administrative session to the workspace
+     * specified in the bundle or, if none specified,
+     * the default workspace
      */
-    private Session getSession()
+    private Session getSession(Bundle bundle)
     throws RepositoryException {
-        return getRepository().loginAdministrative(null);
+        String workspace = (String) bundle.getHeaders().get(CONTENT_WORKSPACE_HEADER);
+        return getRepository().loginAdministrative(workspace);
     }
 
     /**
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
index 6b87271..c33145c 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
@@ -107,10 +107,12 @@ public class Loader {
      *
      * @param session
      * @param bundle
+     * @throws RepositoryException
      */
     public void registerBundle(final Session session,
                                final Bundle bundle,
-                               final boolean isUpdate) {
+                               final boolean isUpdate) throws RepositoryException {
+
         // if this is an update, we have to uninstall the old content first
         if ( isUpdate ) {
             this.unregisterBundle(session, bundle);
@@ -157,6 +159,7 @@ public class Loader {
         }
 
         try {
+            jcrContentHelper.createRepositoryPath(session, ContentLoaderService.BUNDLE_CONTENT_NODE);
 
             // check if the content has already been loaded
             final Map<String, Object> bundleContentInfo = jcrContentHelper.getBundleContentInfo(
@@ -225,6 +228,8 @@ public class Loader {
 
         } else {
             try {
+                jcrContentHelper.createRepositoryPath(session, ContentLoaderService.BUNDLE_CONTENT_NODE);
+
                 final Map<String, Object> bundleContentInfo = jcrContentHelper.getBundleContentInfo(
                         session, bundle, false);
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.