SLING-8012 - Extract an HTL runtime bundle from the existing HTL modules
* refactored code to use the new o.a.s.scripting.sightly.runtime module
diff --git a/pom.xml b/pom.xml
index efaf3fb..27392f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
The versioning scheme defined here corresponds to SLING-7406 (<module_version>-<htl_specification_version>). Take care when
releasing to only increase the first part, unless the module provides support for a newer version of the HTL specification.
-->
- <version>1.0.27-1.4.0-SNAPSHOT</version>
+ <version>1.1.0-1.4.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -86,6 +86,7 @@
io.sightly.compiler.java; version:Version=1.4
</Provide-Capability>
<Require-Capability>
+ io.sightly.runtime; filter:="(&(version>=1.0)(!(version>=2.0)))"
io.sightly.compiler; filter:="(&(version>=1.0)(version<=1.4))",
</Require-Capability>
</instructions>
@@ -167,7 +168,13 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.22-1.4.0</version>
+ <version>1.1.0-1.4.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.scripting.sightly.runtime</artifactId>
+ <version>1.0.0-1.4.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@@ -198,6 +205,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ <version>4.7.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/Record.java b/src/main/java/org/apache/sling/scripting/sightly/Record.java
deleted file mode 100644
index 5c8be4a..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/Record.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * 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;
-
-import java.util.Set;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * A {@code Record} is a key-value immutable object understood by the HTL runtime, used for abstracting complex objects like Sightly
- * templates (declared with the {@code data-sly-template} block element) or objects that need to be translated from Java to JavaScript
- * and back.
- *
- * @param <T> the type of values for this record
- */
-@ConsumerType
-public interface Record<T> {
-
- /**
- * Gets the value of a specified property.
- *
- * @param name the name of the property
- * @return the value of the property or {@code null} if this record does not have the specified property
- */
- T getProperty(String name);
-
- /**
- * Gets the set of names for this record's properties.
- *
- * @return this record's properties' names
- */
- Set<String> getPropertyNames();
-
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/SightlyException.java b/src/main/java/org/apache/sling/scripting/sightly/SightlyException.java
deleted file mode 100644
index 16111ee..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/SightlyException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * 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;
-
-/**
- * Exceptions caused by the HTL engine.
- */
-public class SightlyException extends RuntimeException {
-
- public SightlyException() {
- }
-
- public SightlyException(String message) {
- super(message);
- }
-
- public SightlyException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public SightlyException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
deleted file mode 100644
index e7b8afd..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * 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.extension;
-
-import org.apache.sling.scripting.sightly.render.RenderContext;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * A {@code RuntimeExtension} represents a HTL runtime construct that provides some processing capabilities for the various
- * {@code data-sly-*} block elements.
- */
-@ConsumerType
-public interface RuntimeExtension {
-
- /**
- * For OSGi environments this is the name of the service registration property indicating the {@code RuntimeExtension} name.
- */
- String NAME = "org.apache.sling.scripting.sightly.extension.name";
-
- /**
- * Call the {@code RuntimeExtension}
- *
- * @param renderContext the runtime context
- * @param arguments the call arguments
- * @return an extension instance
- */
- Object call(RenderContext renderContext, Object... arguments);
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java
deleted file mode 100644
index 0bec18c..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.1")
-package org.apache.sling.scripting.sightly.extension;
-
-import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
deleted file mode 100644
index 76c0f3a..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * 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.java.compiler;
-
-import java.io.PrintWriter;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import javax.script.Bindings;
-import javax.script.SimpleBindings;
-
-import org.apache.sling.scripting.sightly.Record;
-import org.apache.sling.scripting.sightly.render.RenderContext;
-
-/**
- * Basic unit of rendering. This also extends the record interface. The properties for a unit are the sub-units.
- */
-public abstract class RenderUnit implements Record<RenderUnit> {
-
- private final Map<String, RenderUnit> subTemplates = new HashMap<>();
-
- private Map<String, RenderUnit> siblings;
-
- /**
- * Render the main script template
- *
- * @param out the {@link PrintWriter} to which the commands are written
- * @param renderContext the rendering context
- * @param arguments the arguments for this unit
- */
- public final void render(PrintWriter out, RenderContext renderContext, Bindings arguments) {
- Bindings globalBindings = renderContext.getBindings();
- render(out, buildGlobalScope(globalBindings), new CaseInsensitiveBindings(arguments), renderContext);
- }
-
- @Override
- public RenderUnit getProperty(String name) {
- return subTemplates.get(name.toLowerCase());
- }
-
- @Override
- public Set<String> getPropertyNames() {
- return subTemplates.keySet();
- }
-
- protected abstract void render(PrintWriter out,
- Bindings bindings,
- Bindings arguments,
- RenderContext renderContext);
-
- @SuppressWarnings({"unused", "unchecked"})
- protected void callUnit(PrintWriter out, RenderContext renderContext, Object templateObj, Object argsObj) {
- if (!(templateObj instanceof RenderUnit)) {
- if (templateObj == null) {
- throw new SightlyJavaCompilerException("data-sly-call: expression evaluates to null.");
- }
- if (renderContext.getObjectModel().isPrimitive(templateObj)) {
- throw new SightlyJavaCompilerException(
- "data-sly-call: primitive \"" + templateObj.toString() + "\" does not represent a HTL template.");
- } else if (templateObj instanceof String) {
- throw new SightlyJavaCompilerException(
- "data-sly-call: String '" + templateObj.toString() + "' does not represent a HTL template.");
- }
- throw new SightlyJavaCompilerException(
- "data-sly-call: " + templateObj.getClass().getName() + " does not represent a HTL template.");
- }
- RenderUnit unit = (RenderUnit) templateObj;
- Map<String, Object> argumentsMap = renderContext.getObjectModel().toMap(argsObj);
- Bindings arguments = new SimpleBindings(Collections.unmodifiableMap(argumentsMap));
- unit.render(out, renderContext, arguments);
- }
-
- @SuppressWarnings("UnusedDeclaration")
- protected FluentMap obj() {
- return new FluentMap();
- }
-
- @SuppressWarnings("unused")
- protected final void addSubTemplate(String name, RenderUnit renderUnit) {
- renderUnit.setSiblings(subTemplates);
- subTemplates.put(name.toLowerCase(), renderUnit);
- }
-
- private void setSiblings(Map<String, RenderUnit> siblings) {
- this.siblings = siblings;
- }
-
- private Bindings buildGlobalScope(Bindings bindings) {
- SimpleBindings simpleBindings = new SimpleBindings(bindings);
- simpleBindings.putAll(bindings);
- if (siblings != null) {
- simpleBindings.putAll(siblings);
- }
- simpleBindings.putAll(subTemplates);
- return new CaseInsensitiveBindings(simpleBindings);
- }
-
- protected static class FluentMap extends HashMap<String, Object> {
-
- /**
- * Fluent variant of put.
- *
- * @param name the name of the property
- * @param value the value of the property
- * @return this instance
- */
- public FluentMap with(String name, Object value) {
- put(name, value);
- return this;
- }
-
- }
-
- private static final class CaseInsensitiveBindings extends SimpleBindings {
-
- private CaseInsensitiveBindings(Map<String, Object> m) {
- for (Map.Entry<String, Object> entry : m.entrySet()) {
- put(entry.getKey().toLowerCase(), entry.getValue());
- }
- }
-
- @Override
- public Object get(Object key) {
- if (!(key instanceof String)) {
- throw new ClassCastException("key should be a String");
- }
- return super.get(((String) key).toLowerCase());
- }
-
- @Override
- public boolean containsKey(Object key) {
- if (!(key instanceof String)) {
- throw new ClassCastException("key should be a String");
- }
- return super.containsKey(((String) key).toLowerCase());
- }
- }
-
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java
index 599a50b..6d36a55 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java
@@ -19,7 +19,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.sling.scripting.sightly.compiler.RuntimeFunction;
import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
import org.apache.sling.scripting.sightly.compiler.expression.SideEffectVisitor;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral;
@@ -146,7 +145,7 @@
.stringLiteral(runtimeCallName);
for (ExpressionNode arg : runtimeCall.getArguments()) {
source.separateArgument();
- if (RuntimeFunction.USE.equals(runtimeCallName)) {
+ if (RuntimeCall.USE.equals(runtimeCallName)) {
if (arg instanceof StringConstant) {
StringConstant constant = (StringConstant) arg;
String className = constant.getText();
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
index b9292d1..4951746 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
@@ -22,7 +22,6 @@
import java.util.Set;
import java.util.regex.Pattern;
-import org.apache.sling.scripting.sightly.compiler.RuntimeFunction;
import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
import org.apache.sling.scripting.sightly.compiler.expression.NodeVisitor;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral;
@@ -138,7 +137,7 @@
@Override
public Type evaluate(RuntimeCall runtimeCall) {
inferAll(runtimeCall.getArguments());
- if (runtimeCall.getFunctionName().equals(RuntimeFunction.USE)) {
+ if (runtimeCall.getFunctionName().equals(RuntimeCall.USE)) {
ExpressionNode identifier = runtimeCall.getArguments().get(0);
if (identifier instanceof StringConstant) {
String objectType = ((StringConstant) identifier).getText();
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
index 45ddcbe..db80f54 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-@Version("1.2.0")
+@Version("2.0.0")
package org.apache.sling.scripting.sightly.java.compiler;
import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
deleted file mode 100644
index f2af1f3..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * 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("2.0.0")
-package org.apache.sling.scripting.sightly;
-
-import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
deleted file mode 100644
index 722b79a..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * 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.pojo;
-
-import javax.script.Bindings;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * The <code>Use</code> interface can be implemented by Java objects which are instantiated as part of processing {@code data-sly-use}
- * attributes.
- *
- * @see <a href="https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md#221-use">HTL Block Statements - Use</a>
- */
-@ConsumerType
-public interface Use {
-
- /**
- * <p>
- * Called to initialize the Java object with the current Java Scripting API bindings.
- * </p>
- * <p>
- * This method is called only if the object has been instantiated by HTL as part of processing the {@code data-sly-use}
- * attribute. The Java Scripting API bindings provide all the global variables known to a script being executed.
- * </p>
- *
- * @param bindings The Java Scripting API bindings.
- */
- void init(Bindings bindings);
-
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java
deleted file mode 100644
index 746ab8f..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.1")
-package org.apache.sling.scripting.sightly.pojo;
-
-import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
deleted file mode 100644
index 2e77d46..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/*******************************************************************************
- * 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.render;
-
-import java.lang.reflect.Method;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang3.math.NumberUtils;
-import org.apache.sling.scripting.sightly.Record;
-import org.apache.sling.scripting.sightly.compiler.util.ObjectModel;
-
-/**
- * Default abstract implementation of {@link RuntimeObjectModel}.
- */
-public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
-
- /**
- * A {@link Set} that stores all the supported primitive classes.
- */
- public static final Set<Class<?>> PRIMITIVE_CLASSES = ObjectModel.PRIMITIVE_CLASSES;
-
- public static final String TO_STRING_METHOD = "toString";
-
- @Override
- public boolean isPrimitive(Object obj) {
- return ObjectModel.isPrimitive(obj);
- }
-
- @Override
- public boolean isDate(Object target) {
- return (target instanceof Date || target instanceof Calendar);
- }
-
- @Override
- public boolean isNumber(Object target) {
- if (target == null) {
- return false;
- }
- if (target instanceof Number) {
- return true;
- }
- String value = toString(target);
- return NumberUtils.isCreatable(value);
- }
-
- @Override
- public boolean isCollection(Object target) {
- return (target instanceof Collection) || (target instanceof Object[]) || (target instanceof Iterable) ||
- (target instanceof Iterator);
- }
-
- @Override
- public Object resolveProperty(Object target, Object property) {
- if (target == null || property == null) {
- return null;
- }
- Object resolved = null;
- if (property instanceof Number) {
- resolved = ObjectModel.getIndex(target, ((Number) property).intValue());
- }
- if (resolved == null) {
- resolved = getProperty(target, property);
- }
- return resolved;
- }
-
- @Override
- public boolean toBoolean(Object object) {
- return ObjectModel.toBoolean(object);
- }
-
- @Override
- public Number toNumber(Object object) {
- return ObjectModel.toNumber(object);
- }
-
- @Override
- public Date toDate(Object object) {
- if (object instanceof Date) {
- return (Date)object;
- } else if (object instanceof Calendar) {
- return ((Calendar)object).getTime();
- }
- return null;
- }
-
- @Override
- public String toString(Object target) {
- return ObjectModel.toString(target);
- }
-
- @Override
- public Collection<Object> toCollection(Object object) {
- if (object instanceof Record) {
- return ((Record) object).getPropertyNames();
- }
- return ObjectModel.toCollection(object);
- }
-
- @Override
- public Map toMap(Object object) {
- if (object instanceof Map) {
- return (Map) object;
- } else if (object instanceof Record) {
- Map<String, Object> map = new HashMap<>();
- Record record = (Record) object;
- Set<String> properties = record.getPropertyNames();
- for (String property : properties) {
- map.put(property, record.getProperty(property));
- }
- return map;
- }
- return Collections.emptyMap();
- }
-
- protected Object getProperty(Object target, Object propertyObj) {
- if (target == null || propertyObj == null) {
- return null;
- }
- String property = ObjectModel.toString(propertyObj);
- Object result = null;
- if (target instanceof Record) {
- result = ((Record) target).getProperty(property);
- }
- if (result == null) {
- result = ObjectModel.resolveProperty(target, propertyObj);
- }
- return result;
- }
-
- /**
- * @deprecated see {@link ObjectModel#toCollection(Object)}
- */
- @Deprecated
- protected Collection<Object> obtainCollection(Object obj) {
- return ObjectModel.toCollection(obj);
- }
-
- /**
- * @deprecated see {@link ObjectModel#toString(Object)}
- */
- @Deprecated
- protected String objectToString(Object obj) {
- return ObjectModel.toString(obj);
- }
-
- /**
- * @deprecated see {@link ObjectModel#collectionToString(Collection)}
- */
- @Deprecated
- protected String collectionToString(Collection<?> col) {
- return ObjectModel.collectionToString(col);
- }
-
- /**
- * @deprecated see {@link ObjectModel#fromIterator(Iterator)}
- */
- @Deprecated
- protected Collection<Object> fromIterator(Iterator<Object> iterator) {
- return ObjectModel.fromIterator(iterator);
- }
-
- /**
- * @deprecated see {@link ObjectModel#toBoolean(Object)}
- */
- @Deprecated
- protected boolean toBooleanInternal(Object obj) {
- return ObjectModel.toBoolean(obj);
- }
-
- /**
- * @deprecated see {@link ObjectModel#getIndex(Object, int)}
- */
- @Deprecated
- protected Object getIndex(Object obj, int index) {
- return ObjectModel.getIndex(obj, index);
- }
-
- /**
- * @deprecated see {@link ObjectModel#getIndex(Object, int)}
- */
- @Deprecated
- protected Object getIndexSafe(List list, int index) {
- return ObjectModel.getIndex(list, index);
- }
-
- /**
- * @deprecated use {@link Map#get(Object)}
- */
- @Deprecated
- protected Object getMapProperty(Map map, String property) {
- if (map == null) {
- return null;
- }
- return map.get(property);
- }
-
- /**
- * @deprecated see {@link ObjectModel#resolveProperty(Object, Object)}
- */
- @Deprecated
- protected Object getObjectProperty(Object obj, String property) {
- return ObjectModel.resolveProperty(obj, property);
- }
-
- /**
- * @deprecated see {@link ObjectModel#getField(Object, String)}
- */
- @Deprecated
- protected static Object getField(Object obj, String property) {
- return ObjectModel.getField(obj, property);
- }
-
- /**
- * @deprecated see {@link ObjectModel#invokeBeanMethod(Object, String)}
- */
- @Deprecated
- protected Object getObjectNoArgMethod(Object obj, String property) {
- return ObjectModel.invokeBeanMethod(obj, property);
- }
-
- /**
- * @deprecated see {@link ObjectModel#findBeanMethod(Class, String)}
- */
- @Deprecated
- protected static Method findMethod(Class<?> cls, String baseName) {
- return ObjectModel.findBeanMethod(cls, baseName);
- }
-
- /**
- * @deprecated see {@link ObjectModel#isMethodAllowed(Method)}
- */
- @Deprecated
- protected static boolean isMethodAllowed(Method method) {
- return ObjectModel.isMethodAllowed(method);
- }
-
- /**
- * @deprecated see {@link ObjectModel#findBeanMethod(Class, String)} (Class, Method)}
- */
- @Deprecated
- protected Method extractMethodInheritanceChain(Class type, Method m) {
- return ObjectModel.findBeanMethod(type, m.getName());
- }
-
- /**
- * @deprecated see {@link ObjectModel#findBeanMethod(Class, String)} (Class, Method)}
- */
- @Deprecated
- protected Method getClassMethod(Class<?> clazz, Method m) {
- return ObjectModel.findBeanMethod(clazz, m.getName());
- }
-
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
deleted file mode 100644
index d57e4c8..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * 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.render;
-
-import javax.script.Bindings;
-
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * The {@code RenderContext} defines the context for executing HTL scripts.
- */
-@ProviderType
-public interface RenderContext {
-
- /**
- * Provides the {@link RuntimeObjectModel} that will be used for resolving objects' properties or type conversion / coercion.
- *
- * @return the RuntimeObjectModel
- */
- RuntimeObjectModel getObjectModel();
-
- /**
- * Returns the map of script bindings available to HTL scripts.
- *
- * @return the global bindings for a script
- */
- Bindings getBindings();
-
- /**
- * Call one of the registered {@link org.apache.sling.scripting.sightly.extension.RuntimeExtension}s.
- *
- * @param functionName the name under which the extension is registered
- * @param arguments the extension's arguments
- * @return the {@link org.apache.sling.scripting.sightly.extension.RuntimeExtension}'s result
- */
- Object call(String functionName, Object... arguments);
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
deleted file mode 100644
index f386634..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.render;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * The {@code RuntimeObjectModel} provides various utility object inspection & conversion methods that can be applied to runtime
- * objects when executing HTL scripts.
- */
-@ProviderType
-public interface RuntimeObjectModel {
-
- /**
- * Checks if the provided object represents a primitive data type or not.
- *
- * @param obj the target object
- * @return {@code true} if the {@code target} is a primitive, {@code false} otherwise
- */
- boolean isPrimitive(Object obj);
-
- /**
- * Checks if an object is a {@link Collection} or is backed by one.
- *
- * @param target the target object
- * @return {@code true} if the {@code target} is a collection or is backed by one, {@code false} otherwise
- */
- boolean isCollection(Object target);
-
- /**
- * Checks if the provided object represents a number or not.
- *
- * @param target the target object
- * @return {@code true} if the {@code target} is a number, {@code false} otherwise
- */
- boolean isNumber(Object target);
-
- /**
- * Checks if the provided object represents a date or calendar.
- *
- * @param target the target object
- * @return {@code true} if the {@code target} is a date or calendar, {@code false} otherwise
- */
- boolean isDate(Object target);
-
- /**
- * Resolve a property of a target object and return its value. The property can
- * be either an index or a name
- *
- * @param target the target object
- * @param property the property to be resolved
- * @return the value of the property
- */
- Object resolveProperty(Object target, Object property);
-
- /**
- * Convert the given object to a boolean value
- *
- * @param object the target object
- * @return the boolean representation of that object
- */
- boolean toBoolean(Object object);
-
- /**
- * Coerce the object to a numeric value
- *
- * @param object the target object
- * @return the numeric representation
- */
- Number toNumber(Object object);
-
- /**
- * Convert the given object to a {@link Date} object
- *
- * @param object the target object
- * @return the date represented by the {@code object}
- */
- Date toDate(Object object);
-
- /**
- * Convert the given object to a string.
- *
- * @param target the target object
- * @return the string representation of the object
- */
- String toString(Object target);
-
- /**
- * Force the conversion of the object to a collection
- *
- * @param object the target object
- * @return the collection representation of the object
- */
- Collection<Object> toCollection(Object object);
-
- /**
- * Force the conversion of the target object to a map
- *
- * @param object the target object
- * @return a map representation of the object. Default is an empty map
- */
- Map toMap(Object object);
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
deleted file mode 100644
index a996756..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*******************************************************************************
- * 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("2.1.0")
-package org.apache.sling.scripting.sightly.render;
-
-import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java b/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java
deleted file mode 100644
index 83fb379..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * 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.use;
-
-/**
- * Result returned by a {@link UseProvider}.
- */
-public final class ProviderOutcome {
-
- // a generic failure without a cause returned by #failure()
- private static final ProviderOutcome GENERIC_FAILURE = new ProviderOutcome(false, null, null);
-
- // whether this is a success or failure
- private final boolean success;
-
- // the result value in case of success (may be null)
- private final Object result;
-
- // the reason for failure in case of failure (may be null)
- private final Throwable cause;
-
- /**
- * Creates an outcome instance
- *
- * @param success {@code true} to indicate success or {@code false} to indicate failure
- * @param result optional result value in case of success, may be {@code null}
- * @param cause optional cause in case of failure, may be {@code null}
- */
- private ProviderOutcome(boolean success, Object result, Throwable cause) {
- this.success = success;
- this.result = result;
- this.cause = cause;
- }
-
- /**
- * Create a successful outcome
- *
- * @param result the result
- * @return a successful result
- */
- public static ProviderOutcome success(Object result) {
- return new ProviderOutcome(true, result, null);
- }
-
- /**
- * Create a failed outcome without a specific {@link #getCause() cause}. This method must be used for creating outcomes that don't
- * signal an error but rather the fact that the {@link UseProvider} is not capable of fulfilling the request.
- *
- * @return a failed outcome
- */
- public static ProviderOutcome failure() {
- return GENERIC_FAILURE;
- }
-
- /**
- * Create a failed outcome with the given {@link #getCause() cause}. This method must be used when the {@link UseProvider} is
- * capable of fulfilling the request but an error condition prevents the provider from doing so.
- *
- * @param cause The reason for this failure, which may be {@code null}
- * @return a failed outcome
- */
- public static ProviderOutcome failure(Throwable cause) {
- return new ProviderOutcome(false, null, cause);
- }
-
- /**
- * If the given obj is not {@code null} return a {@link #success(Object) successful outcome}, with the given result. Otherwise, return
- * {@link #failure()}.
- *
- * @param obj the result
- * @return an outcome based on whether the parameter is null or not
- */
- public static ProviderOutcome notNullOrFailure(Object obj) {
- return (obj == null) ? failure() : success(obj);
- }
-
- /**
- * Check if the outcome has been successful
- *
- * @return the outcome success status
- */
- public boolean isSuccess() {
- return success;
- }
-
- /**
- * Check whether the outcome is a failure
- *
- * @return the outcome failure status
- */
- public boolean isFailure() {
- return !isSuccess();
- }
-
- /**
- * Get the result in this outcome.
- *
- * @return the result of the container
- * @throws IllegalStateException if the outcome is a failure
- */
- public Object getResult() {
- if (!success) {
- throw new IllegalStateException("Outcome has not been successful");
- }
- return result;
- }
-
- /**
- * Returns the cause for this failure outcome or {@code null} if this outcome is a success or no cause has been defined with the
- * {@link #failure(Throwable)} method.
- *
- * @return the cause for this failure outcome.
- */
- public Throwable getCause() {
- return cause;
- }
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java
deleted file mode 100644
index 14a78ba..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * 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.use;
-
-import javax.script.Bindings;
-
-import org.apache.sling.scripting.sightly.render.RenderContext;
-
-import org.osgi.annotation.versioning.ConsumerType;
-
-/**
- * <p>
- * A {@code UseProvider} instantiates objects for the Use-API.
- * </p>
- */
-@ConsumerType
-public interface UseProvider {
-
- /**
- * Provide an instance based on the given identifier
- *
- * @param identifier the identifier of the dependency
- * @param renderContext the current rendering context
- * @param arguments specific arguments provided by the use plugin
- * @return a container with the instance that corresponds to the identifier; if the identifier cannot be
- * handled by this provider, a failed outcome is returned.
- */
- ProviderOutcome provide(String identifier, RenderContext renderContext, Bindings arguments);
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java
deleted file mode 100644
index 0dfe431..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.1")
-package org.apache.sling.scripting.sightly.use;
-
-import org.osgi.annotation.versioning.Version;
diff --git a/src/main/resources/templates/compiled_unit_template.txt b/src/main/resources/templates/compiled_unit_template.txt
index a327d6a..eff242c 100644
--- a/src/main/resources/templates/compiled_unit_template.txt
+++ b/src/main/resources/templates/compiled_unit_template.txt
@@ -22,7 +22,7 @@
import java.util.Collection;
import javax.script.Bindings;
-import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
+import org.apache.sling.scripting.sightly.render.RenderUnit;
import org.apache.sling.scripting.sightly.render.RenderContext;
public final class ##ClassName## extends RenderUnit {
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
index 3867eea..a1606c3 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
@@ -31,9 +31,9 @@
import org.apache.sling.scripting.sightly.compiler.java.utils.TestUtils;
import org.apache.sling.scripting.sightly.java.compiler.ClassInfo;
import org.apache.sling.scripting.sightly.java.compiler.JavaClassBackendCompiler;
-import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
import org.apache.sling.scripting.sightly.render.AbstractRuntimeObjectModel;
import org.apache.sling.scripting.sightly.render.RenderContext;
+import org.apache.sling.scripting.sightly.render.RenderUnit;
import org.apache.sling.scripting.sightly.render.RuntimeObjectModel;
import org.junit.Test;
diff --git a/src/test/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModelTest.java b/src/test/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModelTest.java
deleted file mode 100644
index 87f14a0..0000000
--- a/src/test/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModelTest.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*******************************************************************************
- * 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.render;
-
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.sling.scripting.sightly.Record;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class AbstractRuntimeObjectModelTest {
-
- private AbstractRuntimeObjectModel runtimeObjectModel = new AbstractRuntimeObjectModel() {};
-
- @Test
- public void testResolveProperty() {
- assertNull(runtimeObjectModel.resolveProperty(null, null));
- assertNull(runtimeObjectModel.resolveProperty(this, null));
- assertNull(runtimeObjectModel.resolveProperty(this, ""));
- assertEquals(0, runtimeObjectModel.resolveProperty(Collections.EMPTY_LIST, "size"));
- assertNull(runtimeObjectModel.resolveProperty(null, null));
- int[] ints = new int[] {1, 2, 3};
- assertEquals(ints.length, runtimeObjectModel.resolveProperty(ints, "length"));
- Integer[] testArray = new Integer[] {1, 2, 3};
- assertEquals(testArray.length, runtimeObjectModel.resolveProperty(testArray, "length"));
- assertEquals(2, runtimeObjectModel.resolveProperty(testArray, 1));
- assertNull(runtimeObjectModel.resolveProperty(testArray, 3));
- assertNull(runtimeObjectModel.resolveProperty(testArray, -1));
- List<Integer> testList = Arrays.asList(testArray);
- assertEquals(2, runtimeObjectModel.resolveProperty(testList, 1));
- assertNull(runtimeObjectModel.resolveProperty(testList, 3));
- assertNull(runtimeObjectModel.resolveProperty(testList, -1));
- Map<String, Integer> map = new HashMap<String, Integer>() {{
- put("one", 1);
- put("two", 2);
- }};
- assertEquals(1, runtimeObjectModel.resolveProperty(map, "one"));
- assertNull(runtimeObjectModel.resolveProperty(map, null));
- assertNull(runtimeObjectModel.resolveProperty(map, ""));
- Map<Integer, String> stringMap = new HashMap<Integer, String>(){{
- put(1, "one");
- put(2, "two");
- }};
- assertEquals("one", runtimeObjectModel.resolveProperty(stringMap, 1));
- assertEquals("two", runtimeObjectModel.resolveProperty(stringMap, 2));
- Map<String, String> strings = new HashMap<String, String>(){{
- put("a", "one");
- put("b", "two");
- }};
- Record<String> record = new Record<String>() {
- @Override
- public String getProperty(String name) {
- return strings.get(name);
- }
-
- @Override
- public Set<String> getPropertyNames() {
- return strings.keySet();
- }
- };
- assertEquals("one", runtimeObjectModel.resolveProperty(record, "a"));
- }
-
- @Test
- public void testGetMapProperty() {
- assertNull(runtimeObjectModel.getMapProperty(null, null));
- Map<String, Integer> map = new HashMap<String, Integer>() {{
- put("one", 1);
- put("two", 2);
- }};
- assertEquals(1, runtimeObjectModel.getMapProperty(map, "one"));
- assertNull(runtimeObjectModel.getMapProperty(map, null));
- }
-
- @Test
- public void testToDate() {
- assertNull(runtimeObjectModel.toDate(null));
- Date testDate = new Date();
- assertEquals(testDate, runtimeObjectModel.toDate(testDate));
- Calendar testCalendar = Calendar.getInstance();
- assertEquals(testCalendar.getTime(), runtimeObjectModel.toDate(testCalendar));
- }
-
- @Test
- public void testGetPropertyNullChecks() {
- assertNull(runtimeObjectModel.getProperty(null, null));
- assertNull(runtimeObjectModel.getProperty(this, null));
- assertNull(runtimeObjectModel.getProperty(this, ""));
- }
-
- @Test
- public void testIsDate() {
- assertFalse(runtimeObjectModel.isDate(null));
- assertTrue(runtimeObjectModel.isDate(new Date()));
- assertTrue(runtimeObjectModel.isDate(Calendar.getInstance()));
- }
-
- @Test
- public void testIsNumber() {
- assertFalse(runtimeObjectModel.isNumber(null));
- assertFalse(runtimeObjectModel.isNumber(""));
- assertTrue(runtimeObjectModel.isNumber(0));
- assertTrue(runtimeObjectModel.isNumber(0.5));
- assertTrue(runtimeObjectModel.isNumber("0"));
- assertTrue(runtimeObjectModel.isNumber("0.5"));
- }
-
- @Test
- public void testToCollection() {
- assertTrue(runtimeObjectModel.toCollection(null).isEmpty());
- Record<String> record = new Record<String>() {
-
- private Map<String, String> properties = new HashMap<String, String>() {{
- put("a", "1");
- put("b", "2");
- }};
-
- @Override
- public String getProperty(String name) {
- return properties.get(name);
- }
-
- @Override
- public Set<String> getPropertyNames() {
- return properties.keySet();
- }
- };
- Collection testCollection = runtimeObjectModel.toCollection(record);
- assertEquals(2, testCollection.size());
- assertTrue(testCollection.contains("a"));
- assertTrue(testCollection.contains("b"));
- }
-
- @Test
- public void testToMap() {
- final Map<String, String> properties = new HashMap<String, String>() {{
- put("a", "1");
- put("b", "2");
- }};
- assertEquals(properties, runtimeObjectModel.toMap(properties));
- Record<String> record = new Record<String>() {
- @Override
- public String getProperty(String name) {
- return properties.get(name);
- }
-
- @Override
- public Set<String> getPropertyNames() {
- return properties.keySet();
- }
- };
- assertEquals(properties, runtimeObjectModel.toMap(record));
- assertTrue(runtimeObjectModel.toMap(null).isEmpty());
- }
-
-}
diff --git a/src/test/resources/imports.html.java b/src/test/resources/imports.html.java
index 0ce9c47..8547e19 100644
--- a/src/test/resources/imports.html.java
+++ b/src/test/resources/imports.html.java
@@ -22,7 +22,7 @@
import java.util.Collection;
import javax.script.Bindings;
-import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
+import org.apache.sling.scripting.sightly.render.RenderUnit;
import org.apache.sling.scripting.sightly.render.RenderContext;
public final class Test_imports extends RenderUnit {