sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1583924 - in /sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl: ./ common/
Date Wed, 02 Apr 2014 08:27:01 GMT
Author: tommaso
Date: Wed Apr  2 08:27:00 2014
New Revision: 1583924

URL: http://svn.apache.org/r1583924
Log:
SLING-3480 - added remaining files in replication.core

Modified:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java?rev=1583924&r1=1583923&r2=1583924&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java
Wed Apr  2 08:27:00 2014
@@ -69,6 +69,7 @@ public class OsgiConfigurationResourcePr
             for (Map.Entry<String, Map<String, Object>> entry : changedResources.entrySet())
{
                 String configName = entry.getKey();
                 Map<String, Object> properties = entry.getValue();
+                properties.put(friendlyNameProperty, configName);
 
                 Configuration configuration = getConfiguration(configName);
 
@@ -92,12 +93,16 @@ public class OsgiConfigurationResourcePr
     @Override
     protected Map<String, Object> getResourceRootProperties() {
         Configuration[] configurations = getConfigurations(null);
+        configurations = configurations == null ? new Configuration[0] : configurations;
 
         List<String> nameList = new ArrayList<String>();
 
         for (Configuration configuration : configurations) {
             String configName = (String) configuration.getProperties().get(friendlyNameProperty);
-            nameList.add(configName);
+
+            if (configName != null) {
+                nameList.add(configName);
+            }
         }
 
         Map<String, Object> result = new HashMap<String, Object>();

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java?rev=1583924&r1=1583923&r2=1583924&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiServicePropertiesResourceProvider.java
Wed Apr  2 08:27:00 2014
@@ -103,6 +103,9 @@ public class OsgiServicePropertiesResour
 
     public Object addingService(ServiceReference serviceReference) {
         String serviceName = PropertiesUtil.toString(serviceReference.getProperty(friendlyNameProperty),
null);
+
+        if (serviceName == null) return null;
+
         Map<String, Object> properties = new HashMap<String, Object>();
 
         for (String key : serviceReference.getPropertyKeys()) {
@@ -125,6 +128,8 @@ public class OsgiServicePropertiesResour
     public void removedService(ServiceReference serviceReference, Object o) {
         String serviceName = PropertiesUtil.toString(serviceReference.getProperty(friendlyNameProperty),
null);
 
+        if (serviceName == null) return;
+
         services.remove(serviceName);
         serviceProperties.remove(serviceName);
 

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java?rev=1583924&r1=1583923&r2=1583924&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java
Wed Apr  2 08:27:00 2014
@@ -102,17 +102,19 @@ public abstract class AbstractReadableRe
         else if (pathInfo.isMain()) {
             Map<String, Object> properties = getMainResourceProperties(pathInfo.getMainResourceName());
 
-            Object adaptable = properties.remove(ADAPTABLE_PROPERTY_NAME);
+            if (properties != null) {
+                Object adaptable = properties.remove(ADAPTABLE_PROPERTY_NAME);
 
-            properties = bindMainResourceProperties(properties);
+                properties = bindMainResourceProperties(properties);
 
-            resource = buildMainResource(resourceResolver, pathInfo, properties, adaptable);
+                resource = buildMainResource(resourceResolver, pathInfo, properties, adaptable);
+            }
         }
         else if (pathInfo.isChild()) {
+            Map<String, Object> mainProperties = getMainResourceProperties(pathInfo.getMainResourceName());
             Map<String, String> childProperties = additionalResourcePropertiesMap.get(pathInfo.getChildResourceName());
 
-            if (childProperties != null) {
-                Map<String, Object> mainProperties = getMainResourceProperties(pathInfo.getMainResourceName());
+            if (mainProperties != null && childProperties != null) {
                 Object adaptable = mainProperties.remove(ADAPTABLE_PROPERTY_NAME);
 
                 Map<String, Object> properties = new HashMap<String, Object>();
@@ -131,36 +133,41 @@ public abstract class AbstractReadableRe
     protected Map<String, Object> bindMainResourceProperties(Map<String, Object>
properties) {
         Map<String, Object> result = new HashMap<String, Object>();
 
-        Map<String, String > resourceProperties = additionalResourcePropertiesMap.get(MAIN_RESOURCE_PREFIX);
+        Map<String, String > resourcePropertyTemplates = additionalResourcePropertiesMap.get(MAIN_RESOURCE_PREFIX);
+
+        for (Map.Entry<String, String> propertyTemplateEntry : resourcePropertyTemplates.entrySet())
{
+            String templateName = propertyTemplateEntry.getKey();
+            String templateValue = propertyTemplateEntry.getValue();
+
+            Object propertyValue = templateValue;
+            if (templateValue.startsWith("{") && templateValue.endsWith("}")) {
+                String propertyName = templateValue.substring(1, templateValue.length()-1);
+                propertyValue = properties.get(propertyName);
+            }
 
-        for (Map.Entry<String, String> entry : resourceProperties.entrySet()) {
-            String key = entry.getKey();
-            String value = entry.getValue();
-            Object objectValue = value;
-            if (value.startsWith("{") && value.endsWith("}")) {
-                objectValue = properties.get(value.substring(1, value.length()-1));
-                if (objectValue == null) continue;
+            if (propertyValue != null) {
+                result.put(templateName, propertyValue);
             }
 
-            result.put(key, objectValue);
+
         }
         return result;
     }
 
-    protected Map<String, Object> unbindMainResourceProperties(Map<String, Object>
properties) {
+    protected Map<String, Object> unbindMainResourceProperties(Map<String, Object>
requestProperties) {
         Map<String, Object> result = new HashMap<String, Object>();
 
-        Map<String, String > resourceProperties = additionalResourcePropertiesMap.get(MAIN_RESOURCE_PREFIX);
-
-        for (Map.Entry<String, String> entry : resourceProperties.entrySet()) {
-            String key = entry.getKey();
-            String value = entry.getValue();
-            Object objectValue = value;
-            if (value.startsWith("{") && value.endsWith("}")) {
-                objectValue = properties.get(key);
+        Map<String, String > resourcePropertyTemplates = additionalResourcePropertiesMap.get(MAIN_RESOURCE_PREFIX);
 
-                if (objectValue != null) {
-                    result.put(key, objectValue);
+        for (Map.Entry<String, String> propertyTemplateEntry : resourcePropertyTemplates.entrySet())
{
+            String templateName = propertyTemplateEntry.getKey();
+            String templateValue = propertyTemplateEntry.getValue();
+
+            if (templateValue.startsWith("{") && templateValue.endsWith("}")) {
+                String propertyName = templateValue.substring(1, templateValue.length()-1);
+                Object propertyValue = requestProperties.get(templateName);
+                if (propertyValue != null) {
+                    result.put(propertyName, propertyValue);
                 }
             }
         }



Mime
View raw message