sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r1665013 - in /sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal: BundleHelper.java ContentLoaderService.java Loader.java
Date Sun, 08 Mar 2015 15:07:42 GMT
Author: olli
Date: Sun Mar  8 15:07:42 2015
New Revision: 1665013

URL: http://svn.apache.org/r1665013
Log:
SLING-4223 make Content Loader extensible to support new import formats

* add interface BundleHelper to make responsibilities visible

Added:
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleHelper.java
Modified:
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java

Added: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleHelper.java?rev=1665013&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleHelper.java
(added)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/BundleHelper.java
Sun Mar  8 15:07:42 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.contentloader.internal;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.osgi.framework.Bundle;
+
+public interface BundleHelper extends ContentHelper {
+
+    Map<String, Object> getBundleContentInfo(Session session, Bundle bundle, boolean
create) throws RepositoryException;
+
+    void unlockBundleContentInfo(Session session, Bundle bundle, boolean contentLoaded, List<String>
createdNodes)throws RepositoryException;
+
+    void contentIsUninstalled(Session session, Bundle bundle);
+
+    void createRepositoryPath(Session session, String path) throws RepositoryException;
+
+    Session getSession() throws RepositoryException;
+    
+    Session getSession(String workspace) throws RepositoryException;
+
+}

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java?rev=1665013&r1=1665012&r2=1665013&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoaderService.java
Sun Mar  8 15:07:42 2015
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
     @Property(name="service.vendor", value="The Apache Software Foundation"),
     @Property(name="service.description", value="Apache Sling Content Loader Implementation")
 })
-public class ContentLoaderService implements SynchronousBundleListener, ContentHelper {
+public class ContentLoaderService implements SynchronousBundleListener, BundleHelper {
 
     public static final String PROPERTY_CONTENT_LOADED = "content-loaded";
     public static final String PROPERTY_CONTENT_LOADED_AT = "content-load-time";
@@ -178,7 +178,7 @@ public class ContentLoaderService implem
         return (mts != null) ? mts.getMimeType(name) : null;
     }
 
-    protected void createRepositoryPath(final Session writerSession, final String repositoryPath)
+    public void createRepositoryPath(final Session writerSession, final String repositoryPath)
     throws RepositoryException {
         if ( !writerSession.itemExists(repositoryPath) ) {
             Node node = writerSession.getRootNode();
@@ -278,12 +278,19 @@ public class ContentLoaderService implem
     /**
      * Returns an administrative session to the default workspace.
      */
-    private Session getSession()
+    public Session getSession()
     throws RepositoryException {
         return getRepository().loginAdministrative(null);
     }
 
     /**
+     * Returns an administrative session for the named workspace.
+     */
+    public Session getSession(final String workspace) throws RepositoryException {
+        return getRepository().loginAdministrative(workspace);
+    }
+
+    /**
      * Return the administrative session and close it.
      */
     private void ungetSession(final Session session) {

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java?rev=1665013&r1=1665012&r2=1665013&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
Sun Mar  8 15:07:42 2015
@@ -56,14 +56,14 @@ public class Loader extends BaseImportLo
 
     private final Logger log = LoggerFactory.getLogger(Loader.class);
 
-    private ContentLoaderService contentLoaderService;
+    private BundleHelper bundleHelper;
 
     // bundles whose registration failed and should be retried
     private List<Bundle> delayedBundles;
 
-    public Loader(ContentLoaderService contentLoaderService) {
+    public Loader(BundleHelper bundleHelper) {
         super();
-        this.contentLoaderService = contentLoaderService;
+        this.bundleHelper = bundleHelper;
         this.delayedBundles = new LinkedList<Bundle>();
     }
 
@@ -72,7 +72,7 @@ public class Loader extends BaseImportLo
             delayedBundles.clear();
             delayedBundles = null;
         }
-        contentLoaderService = null;
+        bundleHelper = null;
         super.dispose();
     }
 
@@ -120,10 +120,10 @@ public class Loader extends BaseImportLo
         }
 
         try {
-            contentLoaderService.createRepositoryPath(metadataSession, ContentLoaderService.BUNDLE_CONTENT_NODE);
+            bundleHelper.createRepositoryPath(metadataSession, ContentLoaderService.BUNDLE_CONTENT_NODE);
 
             // check if the content has already been loaded
-            final Map<String, Object> bundleContentInfo = contentLoaderService.getBundleContentInfo(metadataSession,
bundle, true);
+            final Map<String, Object> bundleContentInfo = bundleHelper.getBundleContentInfo(metadataSession,
bundle, true);
 
             // if we don't get an info, someone else is currently loading
             if (bundleContentInfo == null) {
@@ -155,7 +155,7 @@ public class Loader extends BaseImportLo
                 success = true;
                 return true;
             } finally {
-                contentLoaderService.unlockBundleContentInfo(metadataSession, bundle, success,
createdNodes);
+                bundleHelper.unlockBundleContentInfo(metadataSession, bundle, success, createdNodes);
             }
 
         } catch (RepositoryException re) {
@@ -179,9 +179,9 @@ public class Loader extends BaseImportLo
             delayedBundles.remove(bundle);
         } else {
             try {
-                contentLoaderService.createRepositoryPath(session, ContentLoaderService.BUNDLE_CONTENT_NODE);
+                bundleHelper.createRepositoryPath(session, ContentLoaderService.BUNDLE_CONTENT_NODE);
 
-                final Map<String, Object> bundleContentInfo = contentLoaderService.getBundleContentInfo(session,
bundle, false);
+                final Map<String, Object> bundleContentInfo = bundleHelper.getBundleContentInfo(session,
bundle, false);
 
                 // if we don't get an info, someone else is currently loading or unloading
                 // or the bundle is already uninstalled
@@ -191,9 +191,9 @@ public class Loader extends BaseImportLo
 
                 try {
                     uninstallContent(session, bundle, (String[]) bundleContentInfo.get(ContentLoaderService.PROPERTY_UNINSTALL_PATHS));
-                    contentLoaderService.contentIsUninstalled(session, bundle);
+                    bundleHelper.contentIsUninstalled(session, bundle);
                 } finally {
-                    contentLoaderService.unlockBundleContentInfo(session, bundle, false,
null);
+                    bundleHelper.unlockBundleContentInfo(session, bundle, false, null);
                 }
             } catch (RepositoryException re) {
                 log.error("Cannot remove initial content for bundle " + bundle.getSymbolicName()
+ " : " + re.getMessage(), re);
@@ -214,7 +214,7 @@ public class Loader extends BaseImportLo
         final Map<String, Session> createdSessions = new HashMap<String, Session>();
 
         log.debug("Installing initial content from bundle {}", bundle.getSymbolicName());
-        final DefaultContentCreator contentCreator = new DefaultContentCreator(this.contentLoaderService);
+        final DefaultContentCreator contentCreator = new DefaultContentCreator(this.bundleHelper);
         try {
             while (pathIter.hasNext()) {
                 final PathEntry pathEntry = pathIter.next();
@@ -740,12 +740,12 @@ public class Loader extends BaseImportLo
 
     private Session createSession(String workspace) throws RepositoryException {
         try {
-            return contentLoaderService.getRepository().loginAdministrative(workspace);
+            return bundleHelper.getSession(workspace);
         } catch (NoSuchWorkspaceException e) {
-            Session temp = contentLoaderService.getRepository().loginAdministrative(null);
+            Session temp = bundleHelper.getSession();
             temp.getWorkspace().createWorkspace(workspace);
             temp.logout();
-            return contentLoaderService.getRepository().loginAdministrative(workspace);
+            return bundleHelper.getSession(workspace);
         }
     }
 



Mime
View raw message