Package dk.brics.xact.wrappers

Examples of dk.brics.xact.wrappers.ElementWrapper


  /**
   * Returns the selected nodes.
   */
  public static NodeListResult selectNodes(XML context, String xpath, boolean remove_successors) {
    try {
      ElementWrapper root = makeRoot(context);
      List<?> selected = prepare(xpath, root).selectNodes(root.getFirstChild())// apparently, jaxen doesn't use deep recursive calls
      List<Node> sel = copyNodes(root, selected, remove_successors);
      return new NodeListResult(getRealFirstChild(root), sel);
    } catch (JaxenException e) {
      throw new XMLXPathException(e);
    } catch (JaxenRuntimeException e) {
View Full Code Here


  /**
   * Returns the string values of the selected nodes.
   */
  public static List<String> selectStrings(XML context, String xpath) {
    try {
      ElementWrapper root = makeRoot(context);
      List<?> selected = prepare(xpath, root).selectNodes(root.getFirstChild());
      List<String> res = new ArrayList<String>();
      MyNavigator nav = new MyNavigator(root);
      for (Object s : selected)
        res.add(StringFunction.evaluate(s, nav));
      return Collections.unmodifiableList(res);
View Full Code Here

  /**
   * Returns the first selected node.
   */
  public static NodeResult selectSingleNode(XML context, String xpath, boolean remove_successors) {
    try {
      ElementWrapper root = makeRoot(context);
      List<Object> s = new ArrayList<Object>();
      Object n = prepare(xpath, root).selectSingleNode(root.getFirstChild());
      if (n == null)
        throw new XMLXPathException("no node selected");
      s.add(n);
      List<Node> sel = copyNodes(root, s, remove_successors);
      if (sel.isEmpty()) // root is removed by copyNodes if selected
View Full Code Here

  /**
   * Returns the string value of the first selected node.
   */
  public static String stringValueOf(XML context, String xpath) {
    try {
      ElementWrapper root = makeRoot(context);
      return prepare(xpath, root).stringValueOf(root.getFirstChild());
    } catch (JaxenException e) {
      throw new XMLXPathException(e);
    } catch (JaxenRuntimeException e) {
      throw new XMLXPathException(e.getCause());
    }
View Full Code Here

  /**
   * Returns the boolean value of the first selected node.
   */
  public static boolean booleanValueOf(XML context, String xpath) {
    try {
      ElementWrapper root = makeRoot(context);
      return prepare(xpath, root).booleanValueOf(root.getFirstChild());
    } catch (JaxenException e) {
      throw new XMLXPathException(e);
    } catch (JaxenRuntimeException e) {
      throw new XMLXPathException(e.getCause());
    }
View Full Code Here

  /**
   * Returns the number value of the first selected node.
   */
  public static Number numberValueOf(XML context, String xpath) {
    try {
      ElementWrapper root = makeRoot(context);
      return prepare(xpath, root).numberValueOf(root.getFirstChild());
    } catch (JaxenException e) {
      throw new XMLXPathException(e);
    } catch (JaxenRuntimeException e) {
      throw new XMLXPathException(e.getCause());
    }
View Full Code Here

      throw new XMLXPathException(e.getCause());
    }
  }
 
  private static ElementWrapper makeRoot(XML context) {
    return new ElementWrapper((Element)new Element("root").appendContent(context), null); // used as document root node
  }
View Full Code Here

    }

    @Override
    public Iterator<?> getAttributeAxisIterator(Object node) {
      if (node instanceof ElementWrapper) {
        final ElementWrapper e = (ElementWrapper)node;
        return new Iterator<AttrNodeWrapper<? extends AttrNode>>() {
         
          AttrNodeWrapper<? extends AttrNode> next = e.getFirstAttribute();

          public boolean hasNext() {
            return next != null;
          }
View Full Code Here

    }

    @Override
    public Iterator<?> getChildAxisIterator(Object node) {
      if (node instanceof ElementWrapper) {
        final ElementWrapper e = (ElementWrapper)node;
        return new Iterator<TempNodeWrapper<? extends TempNode>>() {
         
          TempNodeWrapper<? extends TempNode> next = e.getFirstChild();

          public boolean hasNext() {
            return next != null;
          }
View Full Code Here

      throw new UnsupportedAxisException("namespace");
    }

    @Override
    public Iterator<?> getParentAxisIterator(Object node) {
      final ElementWrapper parent = ((NodeWrapper<?>)node).getParent();
      if (parent != null) {
        return Collections.singletonList(parent).iterator();
      } else
        return JaxenConstants.EMPTY_ITERATOR;
    }
View Full Code Here

TOP

Related Classes of dk.brics.xact.wrappers.ElementWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.