You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2019/08/23 18:42:30 UTC
[sling-org-apache-sling-models-api] 01/01: SLING-8655 - Added the
Externalized Path Annotation and Provider interface
This is an automated email from the ASF dual-hosted git repository.
andysch pushed a commit to branch issues/SLING-8655
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-api.git
commit a8ff663e1c846962f800af0f35fd90a4e04edfcd
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Fri Aug 23 11:42:14 2019 -0700
SLING-8655 - Added the Externalized Path Annotation and Provider interface
---
.../{package-info.java => ExternalizePath.java} | 20 ++++++++++--
.../injectorspecific/ExternalizedPathProvider.java | 37 ++++++++++++++++++++++
.../sling/models/annotations/package-info.java | 2 +-
3 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/models/annotations/package-info.java b/src/main/java/org/apache/sling/models/annotations/ExternalizePath.java
similarity index 53%
copy from src/main/java/org/apache/sling/models/annotations/package-info.java
copy to src/main/java/org/apache/sling/models/annotations/ExternalizePath.java
index fdb8ffe..bb37d5c 100644
--- a/src/main/java/org/apache/sling/models/annotations/package-info.java
+++ b/src/main/java/org/apache/sling/models/annotations/ExternalizePath.java
@@ -14,7 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-@Version("1.5.0")
package org.apache.sling.models.annotations;
-import aQute.bnd.annotation.Version;
\ No newline at end of file
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a given Property as Path to be shortened by a Externalized Path Provider.
+ *
+ * By default the Resource Resolver's map function is used but one can install custom Externalized Path Providers.
+ * The registration of the providers is passive and dynamic meaning that the default provider is used until
+ * other provider services are bound and then the one with the highest priority is selected
+ */
+@Target({ ElementType.FIELD, ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface ExternalizePath {
+}
diff --git a/src/main/java/org/apache/sling/models/annotations/injectorspecific/ExternalizedPathProvider.java b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ExternalizedPathProvider.java
new file mode 100644
index 0000000..2a6c666
--- /dev/null
+++ b/src/main/java/org/apache/sling/models/annotations/injectorspecific/ExternalizedPathProvider.java
@@ -0,0 +1,37 @@
+/*
+ * 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.models.annotations.injectorspecific;
+
+import org.jetbrains.annotations.NotNull;
+
+public interface ExternalizedPathProvider {
+
+ int FALLBACK_PRIORITY = -1;
+
+ /** @return The priority used to select a provider when multiple are available. The one with the highest priority is selected
+ * In order for a custom Provider to be selected the priroty must be higher than the Fallback Priority
+ **/
+ int getPriority();
+
+ /**
+ * Externalizes a given Path
+ * @param sourcePath The path to be externalized. If this value is null then null is returned
+ * @param adaptable The adaptable source
+ * @return The externalized path if there is a mapping or otherwise the same
+ */
+ String externalize(@NotNull Object adaptable, String sourcePath);
+}
diff --git a/src/main/java/org/apache/sling/models/annotations/package-info.java b/src/main/java/org/apache/sling/models/annotations/package-info.java
index fdb8ffe..ee88293 100644
--- a/src/main/java/org/apache/sling/models/annotations/package-info.java
+++ b/src/main/java/org/apache/sling/models/annotations/package-info.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-@Version("1.5.0")
+@Version("1.6.0")
package org.apache.sling.models.annotations;
import aQute.bnd.annotation.Version;
\ No newline at end of file