SLING-6504 - Use-API to support more flexible way to adapt from different objects
* applied slightly modified patch from Feike Visser <fvisser@adobe.com>
(closes #243)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1806544 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/ResourceResolverAdapterUseObject.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/ResourceResolverAdapterUseObject.java
new file mode 100644
index 0000000..1926081
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/ResourceResolverAdapterUseObject.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.adaptable;
+
+public interface ResourceResolverAdapterUseObject {
+
+ String getTitle();
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceResolverAdapterFactory.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceResolverAdapterFactory.java
new file mode 100644
index 0000000..b499b3b
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceResolverAdapterFactory.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.adaptable.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.scripting.sightly.testing.adaptable.ResourceResolverAdapterUseObject;
+
+@Component
+@Service
+@Properties({
+ @Property(
+ name = AdapterFactory.ADAPTABLE_CLASSES,
+ value = {
+ "org.apache.sling.api.resource.ResourceResolver"
+ }
+ ),
+ @Property(
+ name = AdapterFactory.ADAPTER_CLASSES,
+ value = {
+ "org.apache.sling.scripting.sightly.testing.adaptable.ResourceResolverAdapterUseObject"
+ }
+ )
+})
+public class ResourceResolverAdapterFactory implements AdapterFactory {
+
+ @Override
+ public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
+ if (type == ResourceResolverAdapterUseObject.class && adaptable instanceof ResourceResolver) {
+ return (AdapterType) new ResourceResolverAdapterUseObjectImpl("SUCCESS");
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceResolverAdapterUseObjectImpl.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceResolverAdapterUseObjectImpl.java
new file mode 100644
index 0000000..cdc6170
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceResolverAdapterUseObjectImpl.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.adaptable.impl;
+
+import org.apache.sling.scripting.sightly.testing.adaptable.ResourceResolverAdapterUseObject;
+
+public class ResourceResolverAdapterUseObjectImpl implements ResourceResolverAdapterUseObject {
+
+ private String title;
+
+ public ResourceResolverAdapterUseObjectImpl(String title) {
+ this.title = title;
+ }
+
+ @Override
+ public String getTitle() {
+ return title != null ? title : "FAILED";
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/package-info.java
index 1647401..23488f7 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/package-info.java
@@ -15,7 +15,7 @@
* limitations under the License.
******************************************************************************/
-@Version("1.0.4")
+@Version("1.1.0")
package org.apache.sling.scripting.sightly.testing.adaptable;
import org.osgi.annotation.versioning.Version;
diff --git a/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html b/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html
index a64f9b6..255c846 100644
--- a/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html
+++ b/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html
@@ -25,6 +25,7 @@
data-sly-use.resmodel="org.apache.sling.scripting.sightly.testing.models.ResourceModel"
data-sly-use.reqadapt="org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject"
data-sly-use.resadapt="org.apache.sling.scripting.sightly.testing.adaptable.ResourceAdapterUseObject"
+ data-sly-use.rradapt="${'org.apache.sling.scripting.sightly.testing.adaptable.ResourceResolverAdapterUseObject' @ adaptable = request.resourceResolver}"
data-sly-use.osgi="org.apache.sling.scripting.sightly.testing.use.TestService"
data-sly-use.repoNoPkg="RepoPojoNoPkg"
data-sly-use.testEnum="TestEnumHolder">
@@ -37,5 +38,6 @@
<div id="osgi">${osgi.sayHello}</div>
<div id="repopojo-nopkg">${repoNoPkg.FIELD}</div>
<div id="test-enum">${testEnum.constantValue}</div>
+ <div id="rradapt">${rradapt.title}</div>
</body>
</html>