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.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-testing-content.git
commit eabce98bd72b5bb856cf5505427a53b8ecd90ee4 Author: Radu Cotescu <[email protected]> AuthorDate: Fri Feb 13 11:40:30 2015 +0000 SLING-4419 - [Regression] Sling Models cannot be used with Sightly Java Use-API * merged PojoUseProvider with ClassUseProvider into JavaUseProvider which first tries to adapt the object to Resource / SlingHttpServletRequest, then tries to load the object as a POJO from the repository * provided IT for the Sling specific Use-API implementation git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/sightly/testing-content@1659520 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 32 ++++++++++++ .../testing/adaptable/RequestAdapterUseObject.java | 25 +++++++++ .../adaptable/ResourceAdapterUseObject.java | 25 +++++++++ .../adaptable/impl/RequestAdapterFactory.java | 60 ++++++++++++++++++++++ .../impl/RequestAdapterUseObjectImpl.java | 35 +++++++++++++ .../adaptable/impl/ResourceAdapterFactory.java | 58 +++++++++++++++++++++ .../impl/ResourceAdapterUseObjectImpl.java | 35 +++++++++++++ .../sightly/testing/models/RequestModel.java | 40 +++++++++++++++ .../sightly/testing/models/ResourceModel.java | 37 +++++++++++++ .../SLING-INF/apps/sightly/scripts/use/use.html | 32 ++++++++++++ src/main/resources/SLING-INF/sightly.json | 8 +++ 11 files changed, 387 insertions(+) diff --git a/pom.xml b/pom.xml index fb906b1..f5e0f78 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,7 @@ <configuration> <instructions> <Sling-Initial-Content>SLING-INF;overwrite=true</Sling-Initial-Content> + <Sling-Model-Packages>org.apache.sling.scripting.sightly.testing.models</Sling-Model-Packages> </instructions> </configuration> </plugin> @@ -152,7 +153,38 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + <dependencies> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + </dependency> + </dependencies> + </plugin> </plugins> </build> + <dependencies> + <!-- Test bundle dependencies --> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.models.api</artifactId> + <version>1.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.1.0</version> + <scope>provided</scope> + </dependency> + </dependencies> + </project> diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/RequestAdapterUseObject.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/RequestAdapterUseObject.java new file mode 100644 index 0000000..24733ff --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/RequestAdapterUseObject.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 RequestAdapterUseObject { + + public String getTitle(); + +} diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/ResourceAdapterUseObject.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/ResourceAdapterUseObject.java new file mode 100644 index 0000000..dc8b88b --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/ResourceAdapterUseObject.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 ResourceAdapterUseObject { + + public String getTitle(); + +} diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/RequestAdapterFactory.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/RequestAdapterFactory.java new file mode 100644 index 0000000..e1bcf72 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/RequestAdapterFactory.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.SlingHttpServletRequest; +import org.apache.sling.api.adapter.AdapterFactory; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject; + +@Component +@Service +@Properties({ + @Property( + name = AdapterFactory.ADAPTABLE_CLASSES, + value = { + "org.apache.sling.api.SlingHttpServletRequest" + } + ), + @Property( + name = AdapterFactory.ADAPTER_CLASSES, + value = { + "org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject" + } + ) +}) +public class RequestAdapterFactory implements AdapterFactory { + + @Override + public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) { + if (type == RequestAdapterUseObject.class && adaptable instanceof SlingHttpServletRequest) { + SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable; + Resource resource = request.getResource(); + ValueMap properties = resource.adaptTo(ValueMap.class); + String title = (String) properties.get("jcr:title"); + return (AdapterType) new RequestAdapterUseObjectImpl(title); + } + return null; + } +} diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/RequestAdapterUseObjectImpl.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/RequestAdapterUseObjectImpl.java new file mode 100644 index 0000000..c7997e2 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/RequestAdapterUseObjectImpl.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.RequestAdapterUseObject; + +public class RequestAdapterUseObjectImpl implements RequestAdapterUseObject { + + private String title; + + public RequestAdapterUseObjectImpl(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/impl/ResourceAdapterFactory.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceAdapterFactory.java new file mode 100644 index 0000000..671ac71 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceAdapterFactory.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.scripting.sightly.testing.adaptable.ResourceAdapterUseObject; + +@Component +@Service +@Properties({ + @Property( + name = AdapterFactory.ADAPTABLE_CLASSES, + value = { + "org.apache.sling.api.resource.Resource" + } + ), + @Property( + name = AdapterFactory.ADAPTER_CLASSES, + value = { + "org.apache.sling.scripting.sightly.testing.adaptable.ResourceAdapterUseObject" + } + ) +}) +public class ResourceAdapterFactory implements AdapterFactory { + + @Override + public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) { + if (type == ResourceAdapterUseObject.class && adaptable instanceof Resource) { + Resource resource = (Resource) adaptable; + ValueMap properties = resource.adaptTo(ValueMap.class); + String title = (String) properties.get("jcr:title"); + return (AdapterType) new ResourceAdapterUseObjectImpl(title); + } + return null; + } +} diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceAdapterUseObjectImpl.java b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceAdapterUseObjectImpl.java new file mode 100644 index 0000000..2c3a8ad --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/impl/ResourceAdapterUseObjectImpl.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.ResourceAdapterUseObject; + +public class ResourceAdapterUseObjectImpl implements ResourceAdapterUseObject { + + private String title; + + public ResourceAdapterUseObjectImpl(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/models/RequestModel.java b/src/main/java/org/apache/sling/scripting/sightly/testing/models/RequestModel.java new file mode 100644 index 0000000..2237edb --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/models/RequestModel.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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.models; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Via; + +@Model(adaptables = SlingHttpServletRequest.class) +public class RequestModel { + + @Inject + @Via("resource") + @Named("jcr:title") + private String title; + + public String getTitle() { + return title != null ? title : "FAILED"; + } + +} diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/models/ResourceModel.java b/src/main/java/org/apache/sling/scripting/sightly/testing/models/ResourceModel.java new file mode 100644 index 0000000..bb5ff94 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/models/ResourceModel.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.scripting.sightly.testing.models; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Model; + +@Model(adaptables = Resource.class) +public class ResourceModel { + + @Inject + @Named("jcr:title") + private String title; + + public String getTitle() { + return title != null ? title : "FAILED"; + } +} 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 new file mode 100644 index 0000000..6efc1d8 --- /dev/null +++ b/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html @@ -0,0 +1,32 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> +<!DOCTYPE html> +<html> + <head> + <title>Sightly Use-API - Sling implementation</title> + </head> + <body> + <div id="reqmodel" data-sly-use.reqmodel="org.apache.sling.scripting.sightly.testing.models.RequestModel">${reqmodel.title}</div> + <div id="resmodel" data-sly-use.resmodel="org.apache.sling.scripting.sightly.testing.models.ResourceModel">${resmodel.title}</div> + <div id="reqadapt" + data-sly-use.reqadapt="org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject">${reqadapt.title}</div> + <div id="resadapt" + data-sly-use.resadapt="org.apache.sling.scripting.sightly.testing.adaptable.ResourceAdapterUseObject">${resadapt.title}</div> + </body> +</html> \ No newline at end of file diff --git a/src/main/resources/SLING-INF/sightly.json b/src/main/resources/SLING-INF/sightly.json new file mode 100644 index 0000000..5374050 --- /dev/null +++ b/src/main/resources/SLING-INF/sightly.json @@ -0,0 +1,8 @@ +{ + "jcr:primaryType": "sling:Folder", + "use": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "/apps/sightly/scripts/use", + "jcr:title": "SUCCESS" + } +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
