You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2018/11/06 03:17:29 UTC

[sling-org-apache-sling-app-cms] branch SLING-8074-improve-reference-list created (now 4c03ef7)

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

dklco pushed a change to branch SLING-8074-improve-reference-list
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git.


      at 4c03ef7  Working on improving the references for SLING-8074

This branch includes the following new commits:

     new 4c03ef7  Working on improving the references for SLING-8074

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-app-cms] 01/01: Working on improving the references for SLING-8074

Posted by dk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch SLING-8074-improve-reference-list
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git

commit 4c03ef7d3d9ad3e12b48d2c1803bc3dde320619f
Author: Dan Klco <dk...@apache.org>
AuthorDate: Mon Nov 5 22:17:12 2018 -0500

    Working on improving the references for SLING-8074
---
 .../core/internal/models/ReferenceOperation.java   | 103 +++++++++++----------
 .../libs/sling-cms/content/shared/references.json  |  17 ++++
 .../libs/sling-cms/content/site/content.json       |   7 ++
 3 files changed, 77 insertions(+), 50 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/models/ReferenceOperation.java b/core/src/main/java/org/apache/sling/cms/core/internal/models/ReferenceOperation.java
index baa05c5..311a8d1 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/models/ReferenceOperation.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/models/ReferenceOperation.java
@@ -33,61 +33,64 @@ import org.slf4j.LoggerFactory;
  */
 public abstract class ReferenceOperation {
 
-	private static final Logger log = LoggerFactory.getLogger(ReferenceOperation.class);
+    private static final Logger log = LoggerFactory.getLogger(ReferenceOperation.class);
 
-	private Pattern regex = null;
+    private Pattern regex = null;
 
-	private Resource resource = null;
+    private Resource resource = null;
 
-	public ReferenceOperation(Resource resource) {
-		String path = resource.getPath().replace("/", "\\/");
-		if (CMSConstants.NT_PAGE.equals(resource.getResourceType())) {
-			regex = Pattern.compile(
-					"(^" + path + "($|\\/)|(\\'|\\\")" + path + "(\\.html|\\'|\\\"|\\/))");
-		} else {
-			regex = Pattern.compile("(^" + path + "($|\\/)|(\\'|\\\")" + path + "(\\'|\\\"|\\/))");
-		}
-		this.resource = resource;
-	}
+    public ReferenceOperation(Resource resource) {
+        String path = resource.getPath().replace("/", "\\/");
+        if (CMSConstants.NT_PAGE.equals(resource.getResourceType())) {
+            regex = Pattern.compile("(^" + path + "($|\\/)|(\\'|\\\")" + path + "(\\.html|\\'|\\\"|\\/))");
+        } else {
+            regex = Pattern.compile("(^" + path + "($|\\/)|(\\'|\\\")" + path + "(\\'|\\\"|\\/))");
+        }
+        this.resource = resource;
+    }
 
-	public void init() {
-		log.debug("Finding references to {}", resource.getPath());
+    private void checkReferences(Resource resource) {
+        log.debug("Checking for references in resource {}", resource);
+        ValueMap properties = resource.getValueMap();
+        properties.keySet().forEach(k -> {
+            if (properties.get(k) instanceof String) {
+                if (matches(properties.get(k, String.class))) {
+                    log.trace("Found reference in property {}@{}", resource.getPath(), k);
+                    doProcess(resource, k);
+                }
+            } else if (properties.get(k) instanceof String[]) {
+                for (String v : properties.get(k, String[].class)) {
+                    if (matches(v)) {
+                        log.trace("Found reference in property {}@{}", resource.getPath(), k);
+                        doProcess(resource, k);
+                        break;
+                    }
+                }
+            }
 
-		String query = "SELECT * FROM [nt:base] AS s WHERE CONTAINS(s.*, '" + resource.getPath() + "')";
-		Iterator<Resource> resources = resource.getResourceResolver().findResources(query, Query.JCR_SQL2);
-		log.debug("Checking for references with: {}", query);
-		while (resources.hasNext()) {
-			Resource r = resources.next();
-			log.debug("Checking for references in resource {}", r);
-			ValueMap properties = r.getValueMap();
-			for (String k : properties.keySet()) {
-				if (properties.get(k) instanceof String) {
-					Matcher matcher = regex.matcher(properties.get(k, String.class));
-					if (matcher.find()) {
-						log.trace("Found reference in property {}@{}", r.getPath(), k);
-						doProcess(r, k);
-					}
-				} else if (properties.get(k) instanceof String[]) {
-					boolean matches = false;
-					for (String v : properties.get(k, String[].class)) {
-						Matcher matcher = regex.matcher(v);
-						if (matcher.find()) {
-							matches = true;
-							break;
-						}
-					}
-					if (matches) {
-						log.trace("Found reference in property {}@{}", r.getPath(), k);
-						doProcess(r, k);
-					}
-				}
-			}
-		}
-	}
+        });
+    }
 
-	public abstract void doProcess(Resource resource, String matchingKey);
+    public abstract void doProcess(Resource resource, String matchingKey);
 
-	public Pattern getRegex() {
-		return regex;
-	}
+    public Pattern getRegex() {
+        return regex;
+    }
+
+    public void init() {
+        log.debug("Finding references to {}", resource.getPath());
+        String query = "SELECT * FROM [nt:base] AS s WHERE NOT ISDESCENDANTNODE([/jcr:system/jcr:versionStorage]) AND CONTAINS(s.*, '"
+                + resource.getPath() + "')";
+        Iterator<Resource> resources = resource.getResourceResolver().findResources(query, Query.JCR_SQL2);
+        log.debug("Checking for references with: {}", query);
+        while (resources.hasNext()) {
+            Resource r = resources.next();
+            checkReferences(r);
+        }
+    }
+
+    private boolean matches(String value) {
+        Matcher matcher = regex.matcher(value);
+        return matcher.find();
+    }
 }
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/references.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/references.json
new file mode 100644
index 0000000..100d492
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/references.json
@@ -0,0 +1,17 @@
+{
+    "jcr:primaryType": "sling:Page",
+    "jcr:content": {
+        "sling:resourceType": "sling-cms/components/pages/modal",
+        "jcr:title": "View References",
+        "jcr:primaryType": "nt:unstructured",
+        "container": {
+            "jcr:primaryType": "nt:unstructured",
+            "sling:resourceType": "sling-cms/components/general/container",
+            "references": {
+                "jcr:primaryType": "nt:unstructured",
+                "sling:resourceType": "sling-cms/components/editor/fields/references",
+                "label": "References"
+            }
+        }
+    }
+}
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json
index f48b94c..eae063e 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/site/content.json
@@ -261,6 +261,13 @@
                                     "icon": "move-alt",
                                     "prefix": "/cms/shared/movecopy.html"
                                 },
+                                "references": {
+                                    "jcr:primaryType": "nt:unstructured",
+                                    "modal": true,
+                                    "title": "References",
+                                    "icon": "directions",
+                                    "prefix": "/cms/shared/references.html"
+                                },
                                 "version": {
                                     "jcr:primaryType": "nt:unstructured",
                                     "ajaxPath": ".versionmanager",