/** * true() implementation. * @param context evaluation context * @return Boolean.TRUE */ protected Object functionTrue(EvalContext context) { assertArgCount(0); return Boolean.TRUE; }
/** * null() implementation. * @param context evaluation context * @return null */ protected Object functionNull(EvalContext context) { assertArgCount(0); return null; }
/** * false() implementation. * @param context evaluation context * @return Boolean.FALSE */ protected Object functionFalse(EvalContext context) { assertArgCount(0); return Boolean.FALSE; }
/** * position() implementation. * @param context evaluation context * @return Number */ protected Object functionPosition(EvalContext context) { assertArgCount(0); return new Integer(context.getCurrentPosition()); }
/** * round() implementation. * @param context evaluation context * @return Number */ protected Object functionRound(EvalContext context) { assertArgCount(1); double v = InfoSetUtil.doubleValue(getArg1().computeValue(context)); if (Double.isNaN(v) || Double.isInfinite(v)) { return new Double(v); } return new Double(Math.round(v)); }
/** * floor() implementation. * @param context evaluation context * @return Number */ protected Object functionFloor(EvalContext context) { assertArgCount(1); double v = InfoSetUtil.doubleValue(getArg1().computeValue(context)); if (Double.isNaN(v) || Double.isInfinite(v)) { return new Double(v); } return new Double(Math.floor(v)); }
/** * ceiling() implementation. * @param context evaluation context * @return Number */ protected Object functionCeiling(EvalContext context) { assertArgCount(1); double v = InfoSetUtil.doubleValue(getArg1().computeValue(context)); if (Double.isNaN(v) || Double.isInfinite(v)) { return new Double(v); } return new Double(Math.ceil(v)); }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * substring-after() implementation. * @param context evaluation context * @return String */ protected Object functionSubstringAfter(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(index + s2.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); }
/** * last() implementation. * @param context evaluation context * @return Number */ protected Object functionLast(EvalContext context) { assertArgCount(0); // Move the position to the beginning and iterate through // the context to count nodes. int old = context.getCurrentPosition(); context.reset(); int count = 0; while (context.nextNode()) { count++; } // Restore the current position. if (old != 0) { context.setPosition(old); } return new Double(count); }
/** * 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()); }
/** * 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; }
/** * 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; }
/** * lang() implementation. * @param context evaluation context * @return Boolean */ protected Object functionLang(EvalContext context) { assertArgCount(1); String lang = InfoSetUtil.stringValue(getArg1().computeValue(context)); NodePointer pointer = (NodePointer) context.getSingleNodePointer(); if (pointer == null) { return Boolean.FALSE; } return pointer.isLanguage(lang) ? Boolean.TRUE : Boolean.FALSE; }
/** * 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)); }
/** * id() implementation. * @param context evaluation context * @return Pointer */ protected Object functionID(EvalContext context) { assertArgCount(1); String id = InfoSetUtil.stringValue(getArg1().computeValue(context)); JXPathContext jxpathContext = context.getJXPathContext(); NodePointer pointer = (NodePointer) jxpathContext.getContextPointer(); return pointer.getPointerByID(jxpathContext, id); }
/** * 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)); }