You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2015/01/16 16:40:28 UTC
svn commit: r1652437 - in
/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly:
impl/compiler/expression/node/ impl/compiler/optimization/
impl/compiler/optimization/reduce/ impl/engine/extension/ impl/engine/e...
Author: fmeschbe
Date: Fri Jan 16 15:40:27 2015
New Revision: 1652437
URL: http://svn.apache.org/r1652437
Log:
SLING-4326 Remove object traversal and conversion methods from RenderContext
The methods are still used by the internal RuntimeExtensions and thus are kept
in RenderContextImpl for now. If we see a need for them later, we can still
add them again.
Applying patch by Radu Cotescu (thanks alot)
Modified:
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/BinaryOperator.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/UnaryOperator.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/DeadCodeRemoval.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ConstantFolding.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ExpressionReducer.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/I18nRuntimeExtension.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/IncludeRuntimeExtension.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/XSSRuntimeExtension.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/UseRuntimeExtension.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderUnit.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java
sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/BinaryOperator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/BinaryOperator.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/BinaryOperator.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/BinaryOperator.java Fri Jan 16 15:40:27 2015
@@ -18,6 +18,7 @@
******************************************************************************/
package org.apache.sling.scripting.sightly.impl.compiler.expression.node;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.render.RenderContext;
/**
@@ -28,14 +29,16 @@ public enum BinaryOperator {
AND {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return (renderContext.toBoolean(left)) ? right : left;
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return (renderContextImpl.toBoolean(left)) ? right : left;
}
},
// logical disjunction
OR {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return (renderContext.toBoolean(left)) ? left : right;
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return (renderContextImpl.toBoolean(left)) ? left : right;
}
},
// string concatenation
@@ -43,7 +46,8 @@ public enum BinaryOperator {
{
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return renderContext.toString(left).concat(renderContext.toString(right));
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return renderContextImpl.toString(left).concat(renderContextImpl.toString(right));
}
},
// less-than
@@ -108,8 +112,9 @@ public enum BinaryOperator {
ADD {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return adjust(renderContext.toNumber(left).doubleValue()
- + renderContext.toNumber(right).doubleValue());
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return adjust(renderContextImpl.toNumber(left).doubleValue()
+ + renderContextImpl.toNumber(right).doubleValue());
}
},
@@ -117,24 +122,27 @@ public enum BinaryOperator {
SUB {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return adjust(renderContext.toNumber(left).doubleValue()
- - renderContext.toNumber(right).doubleValue());
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return adjust(renderContextImpl.toNumber(left).doubleValue()
+ - renderContextImpl.toNumber(right).doubleValue());
}
},
// multiplication
MUL {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return adjust(renderContext.toNumber(left).doubleValue()
- * renderContext.toNumber(right).doubleValue());
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return adjust(renderContextImpl.toNumber(left).doubleValue()
+ * renderContextImpl.toNumber(right).doubleValue());
}
},
// floating point division
DIV {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return adjust(renderContext.toNumber(left).doubleValue()
- / renderContext.toNumber(right).doubleValue());
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return adjust(renderContextImpl.toNumber(left).doubleValue()
+ / renderContextImpl.toNumber(right).doubleValue());
}
},
@@ -142,8 +150,9 @@ public enum BinaryOperator {
I_DIV {
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return adjust(renderContext.toNumber(left).intValue()
- / renderContext.toNumber(right).intValue());
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return adjust(renderContextImpl.toNumber(left).intValue()
+ / renderContextImpl.toNumber(right).intValue());
}
},
@@ -152,8 +161,9 @@ public enum BinaryOperator {
{
@Override
public Object eval(RenderContext renderContext, Object left, Object right) {
- return adjust(renderContext.toNumber(left).intValue()
- % renderContext.toNumber(right).intValue());
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return adjust(renderContextImpl.toNumber(left).intValue()
+ % renderContextImpl.toNumber(right).intValue());
}
};
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/UnaryOperator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/UnaryOperator.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/UnaryOperator.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/expression/node/UnaryOperator.java Fri Jan 16 15:40:27 2015
@@ -19,6 +19,7 @@
package org.apache.sling.scripting.sightly.impl.compiler.expression.node;
import org.apache.commons.lang.StringUtils;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.render.RenderContext;
/**
@@ -30,7 +31,8 @@ public enum UnaryOperator {
NOT {
@Override
public Object eval(RenderContext renderContext, Object operand) {
- return !renderContext.toBoolean(operand);
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return !renderContextImpl.toBoolean(operand);
}
},
@@ -38,7 +40,8 @@ public enum UnaryOperator {
IS_WHITESPACE {
@Override
public Object eval(RenderContext renderContext, Object operand) {
- return StringUtils.isWhitespace(renderContext.toString(operand));
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return StringUtils.isWhitespace(renderContextImpl.toString(operand));
}
},
@@ -48,7 +51,8 @@ public enum UnaryOperator {
LENGTH {
@Override
public Object eval(RenderContext renderContext, Object operand) {
- return renderContext.toCollection(operand).size();
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ return renderContextImpl.toCollection(operand).size();
}
};
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/DeadCodeRemoval.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/DeadCodeRemoval.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/DeadCodeRemoval.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/DeadCodeRemoval.java Fri Jan 16 15:40:27 2015
@@ -36,6 +36,7 @@ import org.apache.sling.scripting.sightl
import org.apache.sling.scripting.sightly.impl.compiler.visitor.StatefulRangeIgnore;
import org.apache.sling.scripting.sightly.impl.compiler.visitor.StatefulVisitor;
import org.apache.sling.scripting.sightly.impl.compiler.visitor.TrackingVisitor;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.render.RenderContext;
/**
@@ -61,12 +62,12 @@ public class DeadCodeRemoval extends Tra
private final PushStream outStream = new PushStream();
private final StatefulVisitor.StateControl stateControl;
- private final RenderContext renderContext;
+ private final RenderContextImpl renderContext;
private final Stack<Boolean> keepConditionalEndStack = new Stack<Boolean>();
public DeadCodeRemoval(StatefulVisitor.StateControl stateControl, RenderContext renderContext) {
this.stateControl = stateControl;
- this.renderContext = renderContext;
+ this.renderContext = (RenderContextImpl) renderContext;
}
@Override
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ConstantFolding.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ConstantFolding.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ConstantFolding.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ConstantFolding.java Fri Jan 16 15:40:27 2015
@@ -31,21 +31,21 @@ import org.apache.sling.scripting.sightl
import org.apache.sling.scripting.sightly.impl.compiler.util.stream.PushStream;
import org.apache.sling.scripting.sightly.impl.compiler.util.stream.Streams;
import org.apache.sling.scripting.sightly.impl.compiler.visitor.TrackingVisitor;
-import org.apache.sling.scripting.sightly.render.RenderContext;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
/**
* Optimization which evaluates constant expressions during compilation-time
*/
public final class ConstantFolding extends TrackingVisitor<EvalResult> implements EmitterVisitor {
- private final RenderContext renderContext;
+ private final RenderContextImpl renderContext;
private final PushStream outStream = new PushStream();
- private ConstantFolding(RenderContext renderContext) {
+ private ConstantFolding(RenderContextImpl renderContext) {
this.renderContext = renderContext;
}
- public static StreamTransformer transformer(final RenderContext renderContext) {
+ public static StreamTransformer transformer(final RenderContextImpl renderContext) {
return new StreamTransformer() {
@Override
public CommandStream transform(CommandStream inStream) {
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ExpressionReducer.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ExpressionReducer.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ExpressionReducer.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/reduce/ExpressionReducer.java Fri Jan 16 15:40:27 2015
@@ -40,22 +40,22 @@ import org.apache.sling.scripting.sightl
import org.apache.sling.scripting.sightly.impl.compiler.expression.node.TernaryOperator;
import org.apache.sling.scripting.sightly.impl.compiler.expression.node.UnaryOperation;
import org.apache.sling.scripting.sightly.impl.compiler.util.VariableTracker;
-import org.apache.sling.scripting.sightly.render.RenderContext;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
/**
* Try to evaluate constant parts in expressions
*/
public class ExpressionReducer implements NodeVisitor<EvalResult> {
- private final RenderContext renderContext;
+ private final RenderContextImpl renderContext;
private final VariableTracker<EvalResult> tracker;
- public static EvalResult reduce(ExpressionNode node, VariableTracker<EvalResult> tracker, RenderContext renderContext) {
+ public static EvalResult reduce(ExpressionNode node, VariableTracker<EvalResult> tracker, RenderContextImpl renderContext) {
ExpressionReducer reducer = new ExpressionReducer(renderContext, tracker);
return reducer.eval(node);
}
- public ExpressionReducer(RenderContext renderContext, VariableTracker<EvalResult> tracker) {
+ public ExpressionReducer(RenderContextImpl renderContext, VariableTracker<EvalResult> tracker) {
this.renderContext = renderContext;
this.tracker = tracker;
}
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/I18nRuntimeExtension.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/I18nRuntimeExtension.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/I18nRuntimeExtension.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/I18nRuntimeExtension.java Fri Jan 16 15:40:27 2015
@@ -34,6 +34,7 @@ import org.apache.sling.api.scripting.Sl
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.i18n.ResourceBundleProvider;
import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.impl.filter.I18nFilter;
import org.apache.sling.scripting.sightly.render.RenderContext;
import org.slf4j.Logger;
@@ -50,11 +51,12 @@ public class I18nRuntimeExtension implem
@Override
public Object call(final RenderContext renderContext, Object... arguments) {
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
ExtensionUtils.checkArgumentCount(I18nFilter.FUNCTION, arguments, 3);
- String text = renderContext.toString(arguments[0]);
- String locale = renderContext.toString(arguments[1]);
- String hint = renderContext.toString(arguments[2]);
- final Bindings bindings = renderContext.getBindings();
+ String text = renderContextImpl.toString(arguments[0]);
+ String locale = renderContextImpl.toString(arguments[1]);
+ String hint = renderContextImpl.toString(arguments[2]);
+ final Bindings bindings = renderContextImpl.getBindings();
return get(bindings, text, locale, hint);
}
@@ -86,7 +88,7 @@ public class I18nRuntimeExtension implem
}
}
LOG.warn("No translation found for string '{}' using expression provided locale '{}' or default locale '{}'",
- new String[] {text, locale, resourceBundleProvider.getDefaultLocale().getLanguage()});
+ new String[] {text, locale, request.getLocale().getLanguage()});
return text;
}
}
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/IncludeRuntimeExtension.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/IncludeRuntimeExtension.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/IncludeRuntimeExtension.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/IncludeRuntimeExtension.java Fri Jan 16 15:40:27 2015
@@ -36,6 +36,7 @@ import org.apache.sling.api.scripting.Sl
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.api.servlets.ServletResolver;
import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.impl.engine.runtime.SightlyRenderException;
import org.apache.sling.scripting.sightly.impl.plugin.IncludePlugin;
import org.apache.sling.scripting.sightly.render.RenderContext;
@@ -62,7 +63,8 @@ public class IncludeRuntimeExtension imp
@Override
public Object call(final RenderContext renderContext, Object... arguments) {
ExtensionUtils.checkArgumentCount(IncludePlugin.FUNCTION, arguments, 2);
- String originalPath = renderContext.toString(arguments[0]);
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ String originalPath = renderContextImpl.toString(arguments[0]);
Map options = (Map) arguments[1];
String path = buildPath(originalPath, options);
if (path == null) {
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/XSSRuntimeExtension.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/XSSRuntimeExtension.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/XSSRuntimeExtension.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/XSSRuntimeExtension.java Fri Jan 16 15:40:27 2015
@@ -33,6 +33,7 @@ import org.apache.sling.api.SlingHttpSer
import org.apache.sling.scripting.sightly.SightlyException;
import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
import org.apache.sling.scripting.sightly.impl.compiler.CompilerException;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.impl.filter.XSSFilter;
import org.apache.sling.scripting.sightly.impl.html.MarkupUtils;
import org.apache.sling.scripting.sightly.impl.plugin.MarkupContext;
@@ -79,7 +80,8 @@ public class XSSRuntimeExtension impleme
LOG.warn("Expression context {} is invalid, expression will be replaced by the empty string", option);
return "";
}
- String text = renderContext.toString(original);
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ String text = renderContextImpl.toString(original);
final XSSAPI xssapi = obtainAPI(renderContext.getBindings());
return applyXSSFilter(xssapi, text, hint, markupContext);
}
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/UseRuntimeExtension.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/UseRuntimeExtension.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/UseRuntimeExtension.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/UseRuntimeExtension.java Fri Jan 16 15:40:27 2015
@@ -37,6 +37,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.scripting.sightly.SightlyException;
import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.impl.plugin.UsePlugin;
import org.apache.sling.scripting.sightly.render.RenderContext;
import org.apache.sling.scripting.sightly.use.ProviderOutcome;
@@ -67,11 +68,12 @@ public class UseRuntimeExtension impleme
if (arguments.length != 2) {
throw new SightlyException("Use extension requires two arguments");
}
- String identifier = renderContext.toString(arguments[0]);
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ String identifier = renderContextImpl.toString(arguments[0]);
if (StringUtils.isEmpty(identifier)) {
return null;
}
- Map<String, Object> useArgumentsMap = renderContext.toMap(arguments[1]);
+ Map<String, Object> useArgumentsMap = renderContextImpl.toMap(arguments[1]);
Bindings useArguments = new SimpleBindings(Collections.unmodifiableMap(useArgumentsMap));
ArrayList<UseProvider> providers = new ArrayList<UseProvider>(providersMap.values());
ListIterator<UseProvider> iterator = providers.listIterator(providers.size());
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderContextImpl.java Fri Jan 16 15:40:27 2015
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
-
package org.apache.sling.scripting.sightly.impl.engine.runtime;
import java.lang.reflect.Field;
@@ -61,6 +60,12 @@ public class RenderContextImpl implement
private final Map<String, RuntimeExtension> mapping;
private final ResourceResolver scriptResourceResolver;
+ public RenderContextImpl(Bindings bindings, Map<String, RuntimeExtension> mapping, ResourceResolver scriptResourceResolver) {
+ this.bindings = bindings;
+ this.mapping = mapping;
+ this.scriptResourceResolver = scriptResourceResolver;
+ }
+
public static ResourceResolver getScriptResourceResolver(RenderContext renderContext) {
if (renderContext instanceof RenderContextImpl) {
return ((RenderContextImpl) renderContext).getScriptResourceResolver();
@@ -69,12 +74,6 @@ public class RenderContextImpl implement
throw new SightlyException("Cannot retrieve Script ResourceResovler from RenderContext " + renderContext);
}
- public RenderContextImpl(Bindings bindings, Map<String, RuntimeExtension> mapping, ResourceResolver scriptResourceResolver) {
- this.bindings = bindings;
- this.mapping = mapping;
- this.scriptResourceResolver = scriptResourceResolver;
- }
-
public ResourceResolver getScriptResourceResolver() {
return scriptResourceResolver;
}
@@ -97,7 +96,13 @@ public class RenderContextImpl implement
return extension.call(this, arguments);
}
- @Override
+ /**
+ * Retrieve the specified property from the given object
+ *
+ * @param target - the target object
+ * @param property - the property name
+ * @return - the value of the property or null if the object has no such property
+ */
public Object resolveProperty(Object target, Object property) {
if (property instanceof Number) {
return getIndex(target, ((Number) property).intValue());
@@ -105,22 +110,42 @@ public class RenderContextImpl implement
return getProperty(target, property);
}
- @Override
+ /**
+ * Convert the given object to a string.
+ *
+ * @param target - the target object
+ * @return - the string representation of the object
+ */
public String toString(Object target) {
return objectToString(target);
}
- @Override
+ /**
+ * Convert the given object to a boolean value
+ *
+ * @param object - the target object
+ * @return - the boolean representation of that object
+ */
public boolean toBoolean(Object object) {
return toBooleanInternal(object);
}
- @Override
+ /**
+ * Force the conversion of the object to a collection
+ *
+ * @param object - the target object
+ * @return the collection representation of the object
+ */
public Collection<Object> toCollection(Object object) {
return obtainCollection(object);
}
- @Override
+ /**
+ * 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
+ */
public Map toMap(Object object) {
if (object instanceof Map) {
return (Map) object;
@@ -128,8 +153,12 @@ public class RenderContextImpl implement
return Collections.emptyMap();
}
-
- @Override
+ /**
+ * Coerce the object to a numeric value
+ *
+ * @param object - the target object
+ * @return - the numeric representation
+ */
public Number toNumber(Object object) {
if (object instanceof Number) {
return (Number) object;
@@ -137,11 +166,15 @@ public class RenderContextImpl implement
return 0;
}
- @Override
- public boolean isCollection(Object obj) {
- return (obj instanceof Collection) || (obj instanceof Object[])
- || (obj instanceof Iterable)
- || (obj instanceof Iterator);
+ /**
+ * 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
+ */
+ public boolean isCollection(Object target) {
+ return (target instanceof Collection) || (target instanceof Object[])
+ || (target instanceof Iterable)
+ || (target instanceof Iterator);
}
@SuppressWarnings("unchecked")
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderUnit.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderUnit.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderUnit.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/RenderUnit.java Fri Jan 16 15:40:27 2015
@@ -73,8 +73,9 @@ public abstract class RenderUnit impleme
return;
}
RenderUnit unit = (RenderUnit) templateObj;
- SlingScriptHelper ssh = (SlingScriptHelper) renderContext.getBindings().get(SlingBindings.SLING);
- Map<String, Object> argumentsMap = renderContext.toMap(argsObj);
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ SlingScriptHelper ssh = (SlingScriptHelper) renderContextImpl.getBindings().get(SlingBindings.SLING);
+ Map<String, Object> argumentsMap = renderContextImpl.toMap(argsObj);
Bindings arguments = new SimpleBindings(Collections.unmodifiableMap(argumentsMap));
unit.render(renderContext, arguments);
}
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/FormatFilter.java Fri Jan 16 15:40:27 2015
@@ -31,6 +31,7 @@ import org.apache.sling.scripting.sightl
import org.apache.sling.scripting.sightly.impl.compiler.expression.Expression;
import org.apache.sling.scripting.sightly.impl.compiler.expression.ExpressionNode;
import org.apache.sling.scripting.sightly.impl.compiler.expression.node.RuntimeCall;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.render.RenderContext;
/**
@@ -62,22 +63,23 @@ public class FormatFilter extends Filter
@Override
public Object call(final RenderContext renderContext, Object... arguments) {
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
if (arguments.length != 2) {
throw new SightlyException("Format function must be called with two arguments");
}
- String source = renderContext.toString(arguments[0]);
- Object[] params = decodeParams(renderContext, arguments[1]);
- return replace(renderContext, source, params);
+ String source = renderContextImpl.toString(arguments[0]);
+ Object[] params = decodeParams(renderContextImpl, arguments[1]);
+ return replace(renderContextImpl, source, params);
}
- private Object[] decodeParams(final RenderContext renderContext, Object paramObj) {
+ private Object[] decodeParams(final RenderContextImpl renderContext, Object paramObj) {
if (renderContext.isCollection(paramObj)) {
return renderContext.toCollection(paramObj).toArray();
}
return new Object[] {paramObj};
}
- private String replace(final RenderContext renderContext, String source, Object[] params) {
+ private String replace(final RenderContextImpl renderContext, String source, Object[] params) {
Matcher matcher = PLACEHOLDER_REGEX.matcher(source);
StringBuilder builder = new StringBuilder();
int lastPos = 0;
@@ -97,7 +99,7 @@ public class FormatFilter extends Filter
return builder.toString();
}
- private String param(final RenderContext renderContext, Object[] params, int index) {
+ private String param(final RenderContextImpl renderContext, Object[] params, int index) {
if (index >= 0 && index < params.length) {
return renderContext.toString(params[index]);
}
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/filter/JoinFilter.java Fri Jan 16 15:40:27 2015
@@ -31,6 +31,7 @@ import org.apache.sling.scripting.sightl
import org.apache.sling.scripting.sightly.impl.compiler.expression.Expression;
import org.apache.sling.scripting.sightly.impl.compiler.expression.ExpressionNode;
import org.apache.sling.scripting.sightly.impl.compiler.expression.node.RuntimeCall;
+import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
import org.apache.sling.scripting.sightly.render.RenderContext;
/**
@@ -61,12 +62,13 @@ public class JoinFilter extends FilterCo
if (arguments.length != 2) {
throw new SightlyException("Join function must be called with two arguments.");
}
- Collection<?> collection = renderContext.toCollection(arguments[0]);
- String joinString = renderContext.toString(arguments[1]);
- return join(renderContext, collection, joinString);
+ RenderContextImpl renderContextImpl = (RenderContextImpl) renderContext;
+ Collection<?> collection = renderContextImpl.toCollection(arguments[0]);
+ String joinString = renderContextImpl.toString(arguments[1]);
+ return join(renderContextImpl, collection, joinString);
}
- private String join(final RenderContext renderContext, Collection<?> collection, String joinString) {
+ private String join(final RenderContextImpl renderContext, Collection<?> collection, String joinString) {
StringBuilder sb = new StringBuilder();
Iterator<?> iterator = collection.iterator();
while (iterator.hasNext()) {
Modified: sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java?rev=1652437&r1=1652436&r2=1652437&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java (original)
+++ sling/trunk/contrib/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java Fri Jan 16 15:40:27 2015
@@ -18,12 +18,8 @@
******************************************************************************/
package org.apache.sling.scripting.sightly.render;
-import java.util.Collection;
-import java.util.Map;
-
import javax.script.Bindings;
-import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderUnit;
import aQute.bnd.annotation.ProviderType;
@@ -49,56 +45,5 @@ public interface RenderContext {
* @return the {@link RuntimeExtension}'s result
*/
Object call(String functionName, Object... arguments);
-
- /**
- * Retrieve the specified property from the given object
- *
- * @param target - the target object
- * @param property - the property name
- * @return - the value of the property or null if the object has no such property
- */
- Object resolveProperty(Object target, Object property);
-
- /**
- * Convert the given object to a string.
- *
- * @param target - the target object
- * @return - the string representation of the object
- */
- String toString(Object target);
-
- /**
- * 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);
-
- boolean isCollection(Object obj);
-
- /**
- * 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);
-
+
}