Пример #1
0
 /** Creates an expr, handling some special cases. */
 public static Expr create(AbstractPattern pattern) {
   if (pattern instanceof NodeTypePattern
       && pattern.getParent() instanceof FromSelf
       && pattern.toString().equals(".")) return new ObjectExpr(SELF, ".");
   else if (pattern instanceof FromContext
       && ((FromContext) pattern).getCount() == 0
       && pattern.getParent() == null) return new ObjectExpr(SELF, ".");
   else if (pattern instanceof NodePattern
       && pattern.getParent() instanceof FromAttributes
       && pattern.getParent().getParent() instanceof FromContext
       && ((FromContext) pattern.getParent().getParent()).getCount() == 0)
     return new ObjectExpr(ATTRIBUTE, ((NodePattern) pattern).getNodeName());
   else return new NodeSetExpr(pattern);
 }
Пример #2
0
  /**
   * Returns the value of the expression as a number.
   *
   * @param node the current node
   * @param env the variable environment.
   */
  public double evalNumber(Node node, ExprEnvironment env) throws XPathException {
    Node value = _pattern.findAny(node, env);

    if (value == null) return Double.NaN;

    String string = XmlUtil.textValue(value);

    return stringToNumber(string);
  }
Пример #3
0
  /**
   * Evaluate a node-set object, returning an ArrayList of the node set.
   *
   * @param node the current node
   * @param env the variable environment
   * @return an array list of the nodes
   */
  public Object evalObject(Node node, ExprEnvironment env) throws XPathException {
    NodeListImpl list = new NodeListImpl();

    NodeIterator iter = _pattern.select(node, env);

    Node value = null;
    while ((value = iter.nextNode()) != null) list.add(value);

    return list;
  }
Пример #4
0
 /**
  * Returns true if there are any patterns matching the pattern.
  *
  * @param node the current node
  * @param env the variable environment.
  */
 public boolean evalBoolean(Node node, ExprEnvironment env) throws XPathException {
   return _pattern.findAny(node, env) != null;
 }
Пример #5
0
 public String toString() {
   return _pattern.toString();
 }
Пример #6
0
  public boolean equals(Object b) {
    if (!(b instanceof NodeSetExpr)) return false;

    return _pattern.equals(((NodeSetExpr) b)._pattern);
  }
Пример #7
0
 /**
  * Evaluate a node-set object, returning an iterator of the node set.
  *
  * @param node the current node
  * @param env the variable environment
  * @return an iterator of the nodes
  */
 public NodeIterator evalNodeSet(Node node, ExprEnvironment env) throws XPathException {
   return _pattern.select(node, env);
 }
Пример #8
0
  /**
   * Returns the value of the node set expression as a string. The value is the text value of the
   * first node.
   *
   * @param node the current node
   * @param env the variable environment
   * @return the combined text value of the node.
   */
  public String evalString(Node node, ExprEnvironment env) throws XPathException {
    Node value = _pattern.findAny(node, env);

    if (value == null) return "";
    else return XmlUtil.textValue(value);
  }