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

dklco pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git


The following commit(s) were added to refs/heads/master by this push:
     new 6abe53e  Making the tag filters configurable
6abe53e is described below

commit 6abe53effae54e949f61bf4d2564315ca4346ff9
Author: Dan Klco <[email protected]>
AuthorDate: Thu Aug 23 01:05:46 2018 -0400

    Making the tag filters configurable
---
 .../internal/servlets/PathSuggestionServlet.java   | 27 ++++++++++--------
 .../servlets/PathSuggestionServletConfig.java      | 33 ++++++++++++++++++++++
 .../main/resources/OSGI-INF/l10n/bundle.properties | 13 ++++++++-
 3 files changed, 61 insertions(+), 12 deletions(-)

diff --git 
a/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
 
b/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
index 05ac560..808f236 100644
--- 
a/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
+++ 
b/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServlet.java
@@ -33,7 +33,9 @@ import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.Designate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,21 +44,24 @@ import org.slf4j.LoggerFactory;
  */
 @Component(service = { Servlet.class }, property = { 
"sling.servlet.paths=/bin/cms/paths",
                "sling.servlet.methods=" + HttpConstants.METHOD_GET })
+@Designate(ocd = PathSuggestionServletConfig.class)
 public class PathSuggestionServlet extends SlingSafeMethodsServlet {
 
        private static final long serialVersionUID = -410942682163323725L;
        private static final Logger log = 
LoggerFactory.getLogger(PathSuggestionServlet.class);
 
-       private static final Map<String, String[]> typeMaps = new 
HashMap<String, String[]>();
+       private static final Map<String, String[]> typeFilters = new 
HashMap<String, String[]>();
 
-       static {
-               typeMaps.put("page", new String[] { "sling:Page", "nt:folder", 
"sling:Site" });
-               typeMaps.put("file", new String[] { "nt:file", "nt:folder", 
"sling:Site" });
-               typeMaps.put("folder", new String[] { "nt:folder", "sling:Site" 
});
-               typeMaps.put("taxonomy", new String[] { "nt:folder", 
"sling:Taxonomy" });
-               typeMaps.put("config", new String[] { "nt:folder", 
"sling:Config" });
-               typeMaps.put("content", new String[] { "nt:hierarchyNode" });
-               typeMaps.put("all", new String[] { "nt:base" });
+       @Activate
+       public void activate(PathSuggestionServletConfig config) {
+               typeFilters.clear();
+               for (String filter : config.typeFilters()) {
+                       String[] parts = filter.split("\\=");
+                       String key = parts[0];
+                       String[] types = parts[1].split("\\,");
+                       typeFilters.put(key, types);
+               }
+               log.info("Loaded type filters {}", typeFilters);
        }
 
        protected void doGet(SlingHttpServletRequest request, 
SlingHttpServletResponse response)
@@ -69,7 +74,7 @@ public class PathSuggestionServlet extends 
SlingSafeMethodsServlet {
                log.debug("Finding valid paths under {}", path);
 
                String type = request.getParameter("type");
-               if (!typeMaps.containsKey(type)) {
+               if (!typeFilters.containsKey(type)) {
                        type = "all";
                }
                log.debug("Filtering by type: {}", type);
@@ -101,7 +106,7 @@ public class PathSuggestionServlet extends 
SlingSafeMethodsServlet {
                try {
                        Node node = child.adaptTo(Node.class);
                        if (node != null) {
-                               for (String t : typeMaps.get(type)) {
+                               for (String t : typeFilters.get(type)) {
                                        if (node.isNodeType(t)) {
                                                return true;
                                        }
diff --git 
a/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServletConfig.java
 
b/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServletConfig.java
new file mode 100644
index 0000000..9e180fa
--- /dev/null
+++ 
b/core/src/main/java/org/apache/sling/cms/core/internal/servlets/PathSuggestionServletConfig.java
@@ -0,0 +1,33 @@
+/*
+ * 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.cms.core.internal.servlets;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+/**
+ * Configuration for the Path Suggestion Servlet
+ */
+@ObjectClassDefinition(name = "%pathsuggestionservlet.name", description = 
"%pathsuggestionservlet.description", localization = "OSGI-INF/l10n/bundle")
+public @interface PathSuggestionServletConfig {
+
+       @AttributeDefinition(name = "%pathsuggestionservlet.typeFilters.name", 
description = "%pathsuggestionservlet.typeFilters.description")
+       String[] typeFilters() default { 
"page=sling:Page,nt:folder,sling:Site", "file=nt:file,nt:folder,sling:Site",
+                       "folder=nt:folder,sling:Site", 
"taxonomy=nt:folder,sling:Taxonomy", "config=nt:folder,sling:Config",
+                       "content=nt:hierarchyNode", "all=nt:base" };
+
+}
diff --git a/core/src/main/resources/OSGI-INF/l10n/bundle.properties 
b/core/src/main/resources/OSGI-INF/l10n/bundle.properties
index 29359f2..a1ca302 100644
--- a/core/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/core/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -76,4 +76,15 @@ defaultPathDepth.name=Default Path Depth
 defaultPathDepth.description=The default path depth for UGC content to be 
stored \
 under the bucket. This will be sliced off the UUID, so if you had a UUID of 
123 \
 a bucket of bob and a path depth of 1, this would yield a path like: 
bob/1/123. \
-This can be overridden by the path depth in the UGCBucketConfig.
\ No newline at end of file
+This can be overridden by the path depth in the UGCBucketConfig.
+
+# Path Suggestion Servlet
+pathsuggestionservlet.name=Path Suggestion Servlet
+pathsuggestionservlet.description=A servlet for providing suggested paths 
based \
+on a stemmed path
+
+pathsuggestionservlet.typeFilters.name=Type Filters
+pathsuggestionservlet.typeFilters.description=The defined filters for the path 
\
+suggestion servlet. Each filter is provided in the format 
[name]=[type1],[type2] \
+Each child node of the parent resource to the provided path will be checked to 
see \
+if the node is one of the provided types (or a sub-type) for the filter. 
\ No newline at end of file

Reply via email to