incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1565706 - in /sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl: MergedResource.java MergedResourceProvider.java MergedResourceProviderFactory.java
Date Fri, 07 Feb 2014 16:03:56 GMT
Author: cziegeler
Date: Fri Feb  7 16:03:56 2014
New Revision: 1565706

URL: http://svn.apache.org/r1565706
Log:
SLING-2986 : Reduce object creation for a resource

Modified:
    sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResource.java
    sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProvider.java
    sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderFactory.java

Modified: sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResource.java?rev=1565706&r1=1565705&r2=1565706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResource.java
(original)
+++ sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResource.java
Fri Feb  7 16:03:56 2014
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.resourcemerger.impl;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.sling.api.resource.AbstractResource;
@@ -32,15 +31,21 @@ import org.apache.sling.api.resource.Val
  */
 public class MergedResource extends AbstractResource {
 
+    private static final String MD_FLAG = "sling.mappedResource";
+    private static final String MD_RESOURCES = "sling.mappedResources";
+
+    /** The resource resolver. */
     private final ResourceResolver resolver;
-    private final String path;
-    private final String relativePath;
-    private final List<String> mappedResources = new ArrayList<String>();
 
-    private final ResourceMetadata metadata = new ResourceMetadata();
+    /** Full path of the resource. */
+    private final String path;
 
+    /** Resource type. */
     private final String resourceType;
 
+    /** Resource metadata. */
+    private final ResourceMetadata metadata = new ResourceMetadata();
+
     /** Cache value map. */
     private ValueMap properties;
 
@@ -59,16 +64,16 @@ public class MergedResource extends Abst
                    final List<ValueMap> valueMaps) {
         this.resolver = resolver;
         this.path = (relativePath.length() == 0 ? mergeRootPath : mergeRootPath + "/" + relativePath);
-        this.relativePath = (relativePath.length() == 0 ? "/" : relativePath);
-        if ( mappedResources != null ) {
-            for(final Resource rsrc : mappedResources) {
-                this.mappedResources.add(rsrc.getPath());
-            }
-        }
         this.properties = new MergedValueMap(valueMaps);
-        this.resourceType = this.properties.get(ResourceResolver.PROPERTY_RESOURCE_TYPE,
this.relativePath);
-        metadata.put("sling.mergedResource", true);
-        metadata.put("sling.mappedResources", this.mappedResources.toArray(new String[this.mappedResources.size()]));
+        this.resourceType = this.properties.get(ResourceResolver.PROPERTY_RESOURCE_TYPE,
(relativePath.length() == 0 ? "/" : relativePath));
+        metadata.put(MD_FLAG, true);
+        final String[] resourcePaths = new String[mappedResources.size()];
+        int i = 0;
+        for(final Resource rsrc : mappedResources) {
+            resourcePaths[i] = rsrc.getPath();
+            i++;
+        }
+        metadata.put(MD_RESOURCES, resourcePaths);
     }
 
     /**
@@ -156,6 +161,6 @@ public class MergedResource extends Abst
     @Override
     public String toString() {
         return "MergedResource [path=" + this.path +
-               ", resources=" + this.mappedResources + "]";
+               ", resources=" + this.metadata.get(MD_RESOURCES) + "]";
     }
 }

Modified: sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProvider.java?rev=1565706&r1=1565705&r2=1565706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProvider.java
(original)
+++ sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProvider.java
Fri Feb  7 16:03:56 2014
@@ -237,7 +237,7 @@ public class MergedResourceProvider impl
             }
             final List<Resource> children = new ArrayList<Resource>();
             for(final ResourceHolder holder : candidates) {
-                final Resource mergedResource = this.createMergedResource(resolver, relativePath
+ '/' + holder.name, holder);
+                final Resource mergedResource = this.createMergedResource(resolver, (relativePath.length()
== 0 ? holder.name : relativePath + '/' + holder.name), holder);
                 if ( mergedResource != null ) {
                     children.add(mergedResource);
                 }

Modified: sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderFactory.java?rev=1565706&r1=1565705&r2=1565706&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderFactory.java
(original)
+++ sling/trunk/contrib/extensions/resourcemerger/src/main/java/org/apache/sling/resourcemerger/impl/MergedResourceProviderFactory.java
Fri Feb  7 16:03:56 2014
@@ -37,7 +37,8 @@ import org.apache.sling.commons.osgi.Pro
 @Properties({
     @Property(name = ResourceProvider.ROOTS, value=MergedResourceProviderFactory.DEFAULT_ROOT,
             label="Root",
-            description="The mount point of merged resources")
+            description="The mount point of merged resources"),
+    @Property(name = ResourceProvider.OWNS_ROOTS, boolValue=true, propertyPrivate=true)
 })
 /**
  * The <code>MergedResourceProviderFactory</code> creates merged resource
@@ -45,7 +46,7 @@ import org.apache.sling.commons.osgi.Pro
  */
 public class MergedResourceProviderFactory implements ResourceProviderFactory {
 
-    public static final String DEFAULT_ROOT = "/merged";
+    public static final String DEFAULT_ROOT = "/mnt/merged";
 
     private String mergeRootPath;
 



Mime
View raw message