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.6 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-testing-content.git
commit 492e0a257eb6852bf354c9bce1202c3b273ea7eb Author: Radu Cotescu <[email protected]> AuthorDate: Thu Sep 17 14:07:19 2015 +0000 SLING-5036 - Optimise the ModelsFactoryUseProvider to fail as early as possible if it cannot provide an object * renamed ModelsFactoryUseProvider to SlingModelsUseProvider * delayed all bindings retrievals until they're absolutely necessary * removed bindings merging - models can get their arguments through request attributes if they're adaptable from SlingHttpServletRequest * updated the test setup to take into account the SlingModelsUseProvider (both IT and performance) git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/testing-content@1703629 13f79535-47bb-0310-9956-ffa450edef68 --- .../sightly/testing/adaptable/package-info.java | 21 ++++++ .../sightly/testing/models/RequestModel.java | 12 +++- .../sightly/testing/models/TestModel.java | 75 ++++++++++++++++++++++ .../sightly/testing/models/package-info.java | 21 ++++++ .../sightly/testing/use/package-info.java | 21 ++++++ .../SLING-INF/apps/sightly/scripts/use/use.html | 4 +- .../sightlyperf/test/sly-java-slingmodels.html | 27 ++++++++ 7 files changed, 177 insertions(+), 4 deletions(-) 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 new file mode 100644 index 0000000..372d3e0 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/adaptable/package-info.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ + +@Version("1.0.4") +package org.apache.sling.scripting.sightly.testing.adaptable; + +import aQute.bnd.annotation.Version; \ No newline at end of file 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 index 2237edb..be91165 100644 --- 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 @@ -23,18 +23,24 @@ import javax.inject.Named; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Source; import org.apache.sling.models.annotations.Via; @Model(adaptables = SlingHttpServletRequest.class) public class RequestModel { - @Inject - @Via("resource") - @Named("jcr:title") + @Inject @Via("resource") @Named("jcr:title") private String title; + @Inject @Named("argument") + // get it from request attributes + private String requestArgument; + public String getTitle() { return title != null ? title : "FAILED"; } + public String getRequestArgument() { + return requestArgument != null ? requestArgument : "FAILED"; + } } diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/models/TestModel.java b/src/main/java/org/apache/sling/scripting/sightly/testing/models/TestModel.java new file mode 100644 index 0000000..34b98c4 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/models/TestModel.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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 java.util.Iterator; +import javax.inject.Inject; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.models.annotations.Default; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.Optional; + +@Model(adaptables = Resource.class) +public class TestModel { + + @Inject + private String text; + + @Inject @Optional + private String tag; + + @Inject @Default(booleanValues = false) + private boolean includeChildren; + + private Resource resource; + + public TestModel(Resource resource) { + this.resource = resource; + } + + public String getText() { + return text; + } + + public String getTag() { + return tag; + } + + public boolean getIncludeChildren() { + return includeChildren; + } + + public String getStartTag() { + if (tag == null) { + return null; + } + return "<" + tag + ">"; + } + + public String getEndTag() { + if (tag == null) { + return null; + } + return "</" + tag + ">"; + } + + public Iterator<Resource> getChildren() { + return resource.listChildren(); + } + +} diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/models/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/testing/models/package-info.java new file mode 100644 index 0000000..360c065 --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/models/package-info.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ + +@Version("1.1.0") +package org.apache.sling.scripting.sightly.testing.models; + +import aQute.bnd.annotation.Version; \ No newline at end of file diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/use/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/testing/use/package-info.java new file mode 100644 index 0000000..ff6c54b --- /dev/null +++ b/src/main/java/org/apache/sling/scripting/sightly/testing/use/package-info.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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. + ******************************************************************************/ + +@Version("1.0.0") +package org.apache.sling.scripting.sightly.testing.use; + +import aQute.bnd.annotation.Version; \ No newline at end of file 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 b80eb37..1ff8b0d 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 @@ -22,7 +22,9 @@ <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="reqmodel" data-sly-use.reqmodel="${'org.apache.sling.scripting.sightly.testing.models.RequestModel' @ + argument='SUCCESS'}">${reqmodel.title}</div> + <div id="reqmodel-reqarg">${reqmodel.requestArgument}</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> diff --git a/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-slingmodels.html b/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-slingmodels.html new file mode 100644 index 0000000..0b2b802 --- /dev/null +++ b/src/main/resources/SLING-INF/apps/sightlyperf/test/sly-java-slingmodels.html @@ -0,0 +1,27 @@ +<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/--> +<div data-sly-use.test="org.apache.sling.scripting.sightly.testing.models.TestModel" data-sly-unwrap> + ${test.tag != null ? test.startTag : '' @ context = "unsafe"} + ${test.text @ context = "text"} + ${test.tag != null ? test.endTag : '' @ context = "unsafe"} + <div data-sly-include="mode.jsp" data-sly-unwrap=""></div> + <ul data-sly-test="${test.includeChildren}" data-sly-list.child="${test.children}"> + <li data-sly-resource="${child.path}"></li> + </ul> +</div> -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
