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 10:12:47 UTC

[sling-org-apache-sling-scripting-sightly-testing-content] 09/16: SLING-4977 - Optimise the SightlyJavaCompilerService to provide objects faster

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

rombert pushed a commit to annotated tag org.apache.sling.scripting.sightly.testing-content-1.0.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-testing-content.git

commit f3af6354093634adccfe901c582a0f4791dca649
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Aug 31 10:55:07 2015 +0000

    SLING-4977 - Optimise the SightlyJavaCompilerService to provide objects faster
    
    * changed the implementation of the UnitChangeMonitor so that repository POJOs are stored by class name instead of path
    * delayed repository reads in SightlyJavaCompilerService#getInstance
    * added tests for Java POJOs stored in bundles and the repository
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/testing-content@1700229 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 ++
 .../sling/scripting/sightly/testing/use/Test.java  | 85 ++++++++++++++++++++++
 .../SLING-INF/apps/sightlyperf/test/Test.java      | 33 ++++-----
 .../{sly-java.html => sly-java-pojo-bundle.html}   |  2 +-
 .../{sly-java.html => sly-java-pojo-repo.html}     |  0
 5 files changed, 105 insertions(+), 21 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6f440e8..11b2cd9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -205,6 +205,12 @@
             <version>2.1.0</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.sightly</artifactId>
+            <version>1.0.2</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/use/Test.java b/src/main/java/org/apache/sling/scripting/sightly/testing/use/Test.java
new file mode 100644
index 0000000..87776b2
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/use/Test.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.scripting.sightly.testing.use;
+
+import java.util.Iterator;
+import javax.script.Bindings;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.scripting.sightly.pojo.Use;
+
+public class Test implements Use {
+
+    public static final String PROPERTIES = "properties";
+    public static final String TEXT = "text";
+    public static final String TAG = "tag";
+    public static final String INCLUDE_CHIDLREN = "includeChildren";
+
+    private String text = null;
+
+    private String tag = null;
+
+    private boolean includeChildren = false;
+
+    private Iterator<Resource> children = null;
+
+    public void init(Bindings bindings) {
+        Resource resource = (Resource)bindings.get(SlingBindings.RESOURCE);
+        ValueMap properties = (ValueMap)bindings.get(PROPERTIES);
+
+        if (properties != null) {
+            text = properties.get(TEXT, resource.getPath());
+            tag = properties.get(TAG, String.class);
+            includeChildren = properties.get(INCLUDE_CHIDLREN, false);
+            if (includeChildren) {
+                children = resource.listChildren();
+            }
+        }
+    }
+
+    public String getText() {
+        return this.text;
+    }
+
+    public String getTag() {
+        return tag;
+    }
+
+    public String getStartTag() {
+        if (tag == null) {
+            return null;
+        }
+        return "<" + tag + ">";
+    }
+
+    public String getEndTag() {
+        if (tag == null) {
+            return null;
+        }
+        return "</" + tag + ">";
+    }
+
+    public boolean getIncludeChildren() {
+        return includeChildren;
+    }
+
+    public Iterator<Resource> getChildren() {
+        return this.children;
+    }
+}
\ No newline at end of file
diff --git a/src/main/resources/SLING-INF/apps/sightlyperf/test/Test.java b/src/main/resources/SLING-INF/apps/sightlyperf/test/Test.java
index 7929a30..b3d3489 100644
--- a/src/main/resources/SLING-INF/apps/sightlyperf/test/Test.java
+++ b/src/main/resources/SLING-INF/apps/sightlyperf/test/Test.java
@@ -24,10 +24,16 @@ import javax.script.Bindings;
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.scripting.sightly.pojo.Use;
 
 public class Test implements Use {
 
+    public static final String PROPERTIES = "properties";
+    public static final String TEXT = "text";
+    public static final String TAG = "tag";
+    public static final String INCLUDE_CHIDLREN = "includeChildren";
+
     private String text = null;
 
     private String tag = null;
@@ -37,29 +43,16 @@ public class Test implements Use {
     private Iterator<Resource> children = null;
 
     public void init(Bindings bindings) {
-        Resource resource = (Resource)bindings.get("resource");
-        ValueMap properties = (ValueMap)bindings.get("properties");
+        Resource resource = (Resource)bindings.get(SlingBindings.RESOURCE);
+        ValueMap properties = (ValueMap)bindings.get(PROPERTIES);
 
         if (properties != null) {
-            Object text = properties.get("text");
-            if (text != null) {
-                this.text = text.toString();
-            }
-
-            Object tag = properties.get("tag");
-            if (tag != null) {
-                this.tag = tag.toString();
+            text = properties.get(TEXT, resource.getPath());
+            tag = properties.get(TAG, String.class);
+            includeChildren = properties.get(INCLUDE_CHIDLREN, false);
+            if (includeChildren) {
+                children = resource.listChildren();
             }
-
-            Object includeChildren = properties.get("includeChildren");
-            if (includeChildren != null) {
-                this.includeChildren = Boolean.parseBoolean(includeChildren.toString());
-                this.children = resource.listChildren();
-            }
-        }
-
-        if (this.text == null) {
-            this.text = resource.getPath();
         }
     }
 
diff --git a/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java.html b/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-pojo-bundle.html
similarity index 93%
copy from src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java.html
copy to src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-pojo-bundle.html
index ad14853..597bd97 100644
--- a/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java.html
+++ b/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-pojo-bundle.html
@@ -16,7 +16,7 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
-<div data-sly-use.test="apps.sightlyperf.test.Test" data-sly-unwrap>
+<div data-sly-use.test="org.apache.sling.scripting.sightly.testing.use.Test" data-sly-unwrap>
     ${test.tag != null ? test.startTag : '' @ context = "unsafe"}
     ${test.text @ context = "text"}
     ${test.tag != null ? test.endTag : '' @ context = "unsafe"}
diff --git a/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java.html b/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-pojo-repo.html
similarity index 100%
rename from src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java.html
rename to src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-pojo-repo.html

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