/** * concat() implementation. * @param context evaluation context * @return String */ protected Object functionConcat(EvalContext context) { if (getArgumentCount() < 2) { assertArgCount(2); } StringBuffer buffer = new StringBuffer(); Expression[] args = getArguments(); for (int i = 0; i < args.length; i++) { buffer.append(InfoSetUtil.stringValue(args[i].compute(context))); } return buffer.toString(); }
/** * Assert <code>count</code> args. * @param count int */ private void assertArgCount(int count) { assertArgRange(count, count); }
public Object compute(EvalContext context) { return computeValue(context); }
public Object computeValue(EvalContext context) { switch (functionCode) { case Compiler.FUNCTION_LAST : return functionLast(context); case Compiler.FUNCTION_POSITION : return functionPosition(context); case Compiler.FUNCTION_COUNT : return functionCount(context); case Compiler.FUNCTION_LANG : return functionLang(context); case Compiler.FUNCTION_ID : return functionID(context); case Compiler.FUNCTION_LOCAL_NAME : return functionLocalName(context); case Compiler.FUNCTION_NAMESPACE_URI : return functionNamespaceURI(context); case Compiler.FUNCTION_NAME : return functionName(context); case Compiler.FUNCTION_STRING : return functionString(context); case Compiler.FUNCTION_CONCAT : return functionConcat(context); case Compiler.FUNCTION_STARTS_WITH : return functionStartsWith(context); case Compiler.FUNCTION_CONTAINS : return functionContains(context); case Compiler.FUNCTION_SUBSTRING_BEFORE : return functionSubstringBefore(context); case Compiler.FUNCTION_SUBSTRING_AFTER : return functionSubstringAfter(context);
/** * not() implementation. * @param context evaluation context * @return Boolean */ protected Object functionNot(EvalContext context) { assertArgCount(1); return InfoSetUtil.booleanValue(getArg1().computeValue(context)) ? Boolean.FALSE : Boolean.TRUE; }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(getFunctionName()); buffer.append('('); Expression[] args = getArguments(); if (args != null) { for (int i = 0; i < args.length; i++) { if (i > 0) { buffer.append(", "); } buffer.append(args[i]); } } buffer.append(')'); return buffer.toString(); }
/** * number() implementation. * @param context evaluation context * @return Number */ protected Object functionNumber(EvalContext context) { if (getArgumentCount() == 0) { return InfoSetUtil.number(context.getCurrentNodePointer()); } assertArgCount(1); return InfoSetUtil.number(getArg1().computeValue(context)); }
final int minArgs = 2; final int maxArgs = 3; assertArgRange(minArgs, maxArgs); int ac = getArgumentCount(); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); double from = InfoSetUtil.doubleValue(getArg2().computeValue(context)); if (Double.isNaN(from)) { return ""; InfoSetUtil.doubleValue(getArg3().computeValue(context)); length = Math.round(length); if (length < 0) {
/** * starts-with() implementation. * @param context evaluation context * @return Boolean */ protected Object functionStartsWith(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); return s1.startsWith(s2) ? Boolean.TRUE : Boolean.FALSE; }
/** * translate() implementation. * @param context evaluation context * @return String */ protected Object functionTranslate(EvalContext context) { final int argCount = 3; assertArgCount(argCount); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); String s3 = InfoSetUtil.stringValue(getArg3().computeValue(context)); char[] chars = s1.toCharArray(); int out = 0; for (int in = 0; in < chars.length; in++) { char c = chars[in]; int inx = s2.indexOf(c); if (inx != -1) { if (inx < s3.length()) { chars[out++] = s3.charAt(inx); } } else { chars[out++] = c; } } return new String(chars, 0, out); }
throws XPathException { int code = getCoreFunctionCode(coreFunction); Expression[] arguments = coreFunction.getArguments(); coreFunction.toString())); mLogger.log(Level.FINEST, "processCoreFunction", xpe); throw xpe;
/** * true() implementation. * @param context evaluation context * @return Boolean.TRUE */ protected Object functionTrue(EvalContext context) { assertArgCount(0); return Boolean.TRUE; }
public Object function(int code, Object[] args) { return new CoreFunction(code, toExpressionArray(args)); }
/** * string() implementation. * @param context evaluation context * @return String */ protected Object functionString(EvalContext context) { if (getArgumentCount() == 0) { return InfoSetUtil.stringValue(context.getCurrentNodePointer()); } assertArgCount(1); return InfoSetUtil.stringValue(getArg1().computeValue(context)); }
final int minArgs = 2; final int maxArgs = 3; assertArgRange(minArgs, maxArgs); InfoSetUtil.doubleValue(getArg1().computeValue(context)); String pattern = InfoSetUtil.stringValue(getArg2().computeValue(context)); if (getArgumentCount() == maxArgs) { String symbolsName = InfoSetUtil.stringValue(getArg3().computeValue(context)); symbols = context.getJXPathContext().getDecimalFormatSymbols(symbolsName);
/** * contains() implementation. * @param context evaluation context * @return Boolean */ protected Object functionContains(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); return s1.indexOf(s2) != -1 ? Boolean.TRUE : Boolean.FALSE; }
/** * boolean() implementation. * @param context evaluation context * @return Boolean */ protected Object functionBoolean(EvalContext context) { assertArgCount(1); return InfoSetUtil.booleanValue(getArg1().computeValue(context)) ? Boolean.TRUE : Boolean.FALSE; }
/** * null() implementation. * @param context evaluation context * @return null */ protected Object functionNull(EvalContext context) { assertArgCount(0); return null; }
/** * string-length() implementation. * @param context evaluation context * @return Number */ protected Object functionStringLength(EvalContext context) { String s; if (getArgumentCount() == 0) { s = InfoSetUtil.stringValue(context.getCurrentNodePointer()); } else { assertArgCount(1); s = InfoSetUtil.stringValue(getArg1().computeValue(context)); } return new Double(s.length()); }
/** * substring-before() implementation. * @param context evaluation context * @return String */ protected Object functionSubstringBefore(EvalContext context) { assertArgCount(2); String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context)); String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context)); int index = s1.indexOf(s2); if (index == -1) { return ""; } return s1.substring(0, index); }