public List selectNodes(Object object, NamespaceContext namespaces)
     throws TemplateModelException {
   Context context = getContext(object);
   context.getContextSupport().setNamespaceContext(namespaces);
   try {
     return selectNodesForContext(context);
   } catch (Exception e) {
     throw new TemplateModelException(e);
   }
 }
Example #2
0
  @Override
  @SuppressWarnings("rawtypes")
  public Object call(Context context, List arguments) throws FunctionCallException {

    if (arguments.size() == 2) {
      return evaluate(arguments.get(0), arguments.get(1), context.getNavigator());
    } else if ((arguments.size() == 3) && (arguments.get(2) != null)) {
      return evaluate(arguments.get(0), arguments.get(1), arguments.get(2), context.getNavigator());
    }

    throw new FunctionCallException("matches() requires two or three arguments");
  }
 /*     */ public Object call(Context context, List args) /*     */ throws FunctionCallException
       /*     */ {
   /* 127 */ if (args.size() == 3) {
     /* 128 */ return evaluate(args.get(0), args.get(1), args.get(2), context.getNavigator());
     /*     */ }
   /*     */
   /* 134 */ throw new FunctionCallException("translate() requires three arguments.");
   /*     */ }
Example #4
0
  /**
   * Returns a substring of an XPath string-value by character index.
   *
   * @param context the context at the point in the expression when the function is called
   * @param args a list that contains two or three items
   * @return a <code>String</code> containing the specifed character subsequence of the original
   *     string or the string-value of the context node
   * @throws FunctionCallException if <code>args</code> has more than three or less than two items
   */
  public Object call(Context context, List args) throws FunctionCallException {
    final int argc = args.size();
    if (argc < 2 || argc > 3) {
      throw new FunctionCallException("substring() requires two or three arguments.");
    }

    final Navigator nav = context.getNavigator();

    final String str = StringFunction.evaluate(args.get(0), nav);
    // The spec doesn't really address this case
    if (str == null) {
      return "";
    }

    final int stringLength = (StringLengthFunction.evaluate(args.get(0), nav)).intValue();

    if (stringLength == 0) {
      return "";
    }

    Double d1 = NumberFunction.evaluate(args.get(1), nav);

    if (d1.isNaN()) {
      return "";
    }
    // Round the value and subtract 1 as Java strings are zero based
    int start = RoundFunction.evaluate(d1, nav).intValue() - 1;

    int substringLength = stringLength;
    if (argc == 3) {
      Double d2 = NumberFunction.evaluate(args.get(2), nav);

      if (!d2.isNaN()) {
        substringLength = RoundFunction.evaluate(d2, nav).intValue();
      } else {
        substringLength = 0;
      }
    }

    if (substringLength < 0) return "";

    int end = start + substringLength;
    if (argc == 2) end = stringLength;

    // negative start is treated as 0
    if (start < 0) {
      start = 0;
    } else if (start > stringLength) {
      return "";
    }

    if (end > stringLength) {
      end = stringLength;
    } else if (end < start) return "";

    if (stringLength == str.length()) {
      // easy case; no surrogate pairs
      return str.substring(start, end);
    } else {
      return unicodeSubstring(str, start, end);
    }
  }