Example usage for org.apache.commons.jxpath Pointer getNode

List of usage examples for org.apache.commons.jxpath Pointer getNode

Introduction

In this page you can find the example usage for org.apache.commons.jxpath Pointer getNode.

Prototype

Object getNode();

Source Link

Document

Returns the raw value of the object, property or collection element this pointer represents.

Usage

From source file:blueprint.sdk.util.JXPathHelper.java

/**
 * @param xpath XPath to evaluate/*from w w w.  ja  v a 2 s  . com*/
 * @param context target context, JXPathContext.newContext(Node)
 * @return Pointer or null(not found)
 */
@SuppressWarnings("WeakerAccess")
public static Node evaluateNode(String xpath, JXPathContext context) {
    Node result = null;

    try {
        Pointer ptr = context.getPointer(xpath);
        if (ptr != null) {
            result = (Node) ptr.getNode();
        }
    } catch (JXPathNotFoundException ignored) {
    }

    return result;
}

From source file:com.yahoo.xpathproto.JXPathCopier.java

public static JXPathContext getRelativeContext(JXPathContext context, String path) {
    Pointer pointer = context.getPointer(path);
    if ((pointer == null) || (pointer.getNode() == null)) {
        return null;
    }//  www  . ja v  a  2s .c  o  m

    return context.getRelativeContext(pointer);
}

From source file:com.idega.util.config.DefaultConfig.java

/**
 * Returns the specified configuration section in a hash map.
 * //w  ww .  j  a v a 2 s . c  o m
 * @param configContext
 *            the JXPath context holding the configuration.
 * @param sectionPath
 *            the context relative path to the section.
 * @param nameAttribute
 *            the name of the attribute to be used as a hash map key.
 * @param valueAttribute
 *            the name of the attribute to be used as a hash map value.
 * @return the specified configuration section in a hash map.
 * @throws Exception
 *             if any error occured during configuration loading.
 */
private HashMap load(JXPathContext configContext, String sectionPath, String nameAttribute,
        String valueAttribute) throws Exception {
    HashMap map = new HashMap();
    Iterator iterator = configContext.iteratePointers(sectionPath);

    while (iterator.hasNext()) {
        Pointer pointer = (Pointer) iterator.next();
        Element element = (Element) pointer.getNode();

        map.put(element.getAttribute(nameAttribute), element.getAttribute(valueAttribute));
    }

    return map;
}

From source file:com.idega.util.config.DefaultConfig.java

/**
 * Creates and loads a new configuration.
 * //  w  w  w  .  j  a  v  a 2s.  c om
 * @param stream
 *            InputStream to read XML data in the default format.
 */
public DefaultConfig(InputStream stream) throws ConfigException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(false);
        factory.setValidating(false);

        Document document = factory.newDocumentBuilder().parse(stream);
        JXPathContext context = JXPathContext.newContext(document.getDocumentElement());

        for (Iterator iter = context.iteratePointers(properties_xpath); iter.hasNext();) {
            Pointer pointer = (Pointer) iter.next();
            Element properties_el = (Element) pointer.getNode();
            String p_name = properties_el.getAttribute(name_att);

            JXPathContext properties_context = JXPathContext.newContext(properties_el);
            Map<String, String> properties = load(properties_context, property_xpath, name_att, value_att);
            getPropertiesMap().put(p_name, properties);
        }

    } catch (Exception e) {
        throw new ConfigException(e);
    }
}

From source file:com.htm.query.jxpath.JXpathQueryEvaluator.java

public List<?> evaluateQuery(IQuery query) throws com.htm.exceptions.IllegalArgumentException {
    log.debug("JXPath: Evaluating XPath query '" + query.getQuery() + "' within context "
            + jXpathContext.getContextBean());
    if (query instanceof XPathQueryImpl) {
        XPathQueryImpl xpath = (XPathQueryImpl) query;
        Hashtable<String, String> namespaces = xpath.getNamespaces();
        if (namespaces != null) {
            for (String key : namespaces.keySet()) {
                this.jXpathContext.registerNamespace(key, namespaces.get(key));
            }//from w w  w  .j a v a  2s  .  c o m
        }
    }
    try {
        // TODO if a jdom object is addressed by an xpath expression that is
        // no leaf node
        // then the values of all leaf nodes are returned. This ha to be
        // handled somehow

        // Object result = this.jXpathContext.getValue(query.getQuery());
        //
        // /* Return empty list if xpath query doesn't match any property */
        // if (result == null) {
        // log.debug("JXPath: Query didn't match");
        // return new ArrayList<Object>();
        // } else if (result instanceof List<?>) {
        // log.debug("JXPath: Query matched. Result type "
        // + result.getClass().getName());
        // return (List<?>) result;
        //
        // } else {
        // log.debug("JXPath: Query matched. Result type "
        // + result.getClass().getName());
        // List<Object> resultList = new ArrayList<Object>();
        // resultList.add(result);
        //
        // return resultList;
        // }
        //            if (log.isDebugEnabled()) {
        //                log.debug("Evaluating all paths for query'" + query.getQuery() + "'");
        //                Iterator paths = this.jXpathContext.iteratePointers("/taskParentContext/properties/child::*");
        //                Pointer path;
        //                while (paths.hasNext()) {
        //                    path = (Pointer) paths.next();
        //                    log.debug("Path found: " + path.asPath());
        //                }
        //            }

        ArrayList<Object> list = new ArrayList<Object>();

        Iterator iterator = this.jXpathContext.iteratePointers(query.getQuery());
        Pointer pointer;
        while (iterator.hasNext()) {
            pointer = (Pointer) iterator.next();
            log.debug("JXPath pointer: " + pointer.asPath());
            list.add(pointer.getNode());
        }
        return list;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new InvalidQueryException(e);
    }

}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

@SuppressWarnings("unchecked")
public static void rebuildInstance(final Node prototypeNode, final Node oldInstanceNode,
        final Node newInstanceNode,

        final HashMap<String, String> schemaNamespaces) {
    final JXPathContext prototypeContext = JXPathContext.newContext(prototypeNode);
    prototypeContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI);
    final JXPathContext instanceContext = JXPathContext.newContext(oldInstanceNode);
    instanceContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI);

    for (final String prefix : schemaNamespaces.keySet()) {
        prototypeContext.registerNamespace(prefix, schemaNamespaces.get(prefix));
        instanceContext.registerNamespace(prefix, schemaNamespaces.get(prefix));
    }//ww w  .j av a2s .com

    // Evaluate non-recursive XPaths for all prototype elements at this level
    final Iterator<Pointer> it = prototypeContext.iteratePointers("*");
    while (it.hasNext()) {
        final Pointer p = it.next();
        Element proto = (Element) p.getNode();
        String path = p.asPath();
        // check if this is a prototype element with the attribute set
        boolean isPrototype = proto.hasAttributeNS(NamespaceService.ALFRESCO_URI, "prototype")
                && proto.getAttributeNS(NamespaceService.ALFRESCO_URI, "prototype").equals("true");

        // We shouldn't locate a repeatable child with a fixed path
        if (isPrototype) {
            path = path.replaceAll("\\[(\\d+)\\]", "[position() >= $1]");
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[rebuildInstance] evaluating prototyped nodes " + path);
            }
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[rebuildInstance] evaluating child node with positional path " + path);
            }
        }

        Document newInstanceDocument = newInstanceNode.getOwnerDocument();

        // Locate the corresponding nodes in the instance document
        List<Node> l = (List<Node>) instanceContext.selectNodes(path);

        // If the prototype node isn't a prototype element, copy it in as a missing node, complete with all its children. We won't need to recurse on this node
        if (l.isEmpty()) {
            if (!isPrototype) {
                LOGGER.debug("[rebuildInstance] copying in missing node " + proto.getNodeName() + " to "
                        + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement()));

                // Clone the prototype node and all its children
                Element clone = (Element) proto.cloneNode(true);
                newInstanceNode.appendChild(clone);

                if (oldInstanceNode instanceof Document) {
                    // add XMLSchema instance NS
                    addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX,
                            NamespaceConstants.XMLSCHEMA_INSTANCE_NS);
                }
            }
        } else {
            // Otherwise, append the matches from the old instance document in order
            for (Node old : l) {
                Element oldEl = (Element) old;

                // Copy the old instance element rather than cloning it, so we don't copy over attributes
                Element clone = null;
                String nSUri = oldEl.getNamespaceURI();
                if (nSUri == null) {
                    clone = newInstanceDocument.createElement(oldEl.getTagName());
                } else {
                    clone = newInstanceDocument.createElementNS(nSUri, oldEl.getTagName());
                }
                newInstanceNode.appendChild(clone);

                if (oldInstanceNode instanceof Document) {
                    // add XMLSchema instance NS
                    addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX,
                            NamespaceConstants.XMLSCHEMA_INSTANCE_NS);
                }

                // Copy over child text if this is not a complex type
                boolean isEmpty = true;
                for (Node n = old.getFirstChild(); n != null; n = n.getNextSibling()) {
                    if (n instanceof Text) {
                        clone.appendChild(newInstanceDocument.importNode(n, false));
                        isEmpty = false;
                    } else if (n instanceof Element) {
                        break;
                    }
                }

                // Populate the nil attribute. It may be true or false
                if (proto.hasAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, "nil")) {
                    clone.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS,
                            NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", String.valueOf(isEmpty));
                }

                // Copy over attributes present in the prototype
                NamedNodeMap attributes = proto.getAttributes();
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attribute = (Attr) attributes.item(i);
                    String localName = attribute.getLocalName();
                    if (localName == null) {
                        String name = attribute.getName();
                        if (oldEl.hasAttribute(name)) {
                            clone.setAttributeNode(
                                    (Attr) newInstanceDocument.importNode(oldEl.getAttributeNode(name), false));
                        } else {
                            LOGGER.debug("[rebuildInstance] copying in missing attribute "
                                    + attribute.getNodeName() + " to "
                                    + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement()));

                            clone.setAttributeNode((Attr) attribute.cloneNode(false));
                        }
                    } else {
                        String namespace = attribute.getNamespaceURI();
                        if (!((!isEmpty
                                && (namespace.equals(NamespaceConstants.XMLSCHEMA_INSTANCE_NS)
                                        && localName.equals("nil"))
                                || (namespace.equals(NamespaceService.ALFRESCO_URI)
                                        && localName.equals("prototype"))))) {
                            if (oldEl.hasAttributeNS(namespace, localName)) {
                                clone.setAttributeNodeNS((Attr) newInstanceDocument
                                        .importNode(oldEl.getAttributeNodeNS(namespace, localName), false));
                            } else {
                                LOGGER.debug("[rebuildInstance] copying in missing attribute "
                                        + attribute.getNodeName() + " to "
                                        + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement()));

                                clone.setAttributeNodeNS((Attr) attribute.cloneNode(false));
                            }
                        }
                    }
                }

                // recurse on children
                rebuildInstance(proto, oldEl, clone, schemaNamespaces);
            }
        }

        // Now add in a new copy of the prototype
        if (isPrototype) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[rebuildInstance] appending " + proto.getNodeName() + " to "
                        + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement()));
            }
            newInstanceNode.appendChild(proto.cloneNode(true));
        }
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

private void addAttributeSet(final Document xformsDocument, final Element modelSection,
        final Element defaultInstanceElement, final Element formSection, final XSModel schema,
        final XSComplexTypeDefinition controlType, final XSElementDeclaration owner, final String pathToRoot,
        final boolean checkIfExtension, final ResourceBundle resourceBundle) throws FormBuilderException {
    XSObjectList attrUses = controlType.getAttributeUses();

    if (attrUses == null) {
        return;/*from   w ww .  jav  a  2s.  com*/
    }
    for (int i = 0; i < attrUses.getLength(); i++) {
        final XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i);
        final XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration();

        String attributeName = currentAttributeUse.getName();
        if (attributeName == null || attributeName.length() == 0) {
            attributeName = currentAttributeUse.getAttrDeclaration().getName();
        }

        //test if extended !
        if (checkIfExtension && SchemaUtil.doesAttributeComeFromExtension(currentAttributeUse, controlType)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(
                        "[addAttributeSet] This attribute comes from an extension: recopy form controls. Model section =\n"
                                + XMLUtil.toString(modelSection));
            }

            //find the existing bind Id
            //(modelSection is the enclosing bind of the element)
            final NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
            String bindId = null;
            for (int j = 0; j < binds.getLength() && bindId == null; j++) {
                Element bind = (Element) binds.item(j);
                String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");
                if (nodeset != null) {
                    //remove "@" in nodeset
                    String name = nodeset.substring(1);
                    if (name.equals(attributeName)) {
                        bindId = bind.getAttributeNS(null, "id");
                    }
                }
            }

            //find the control
            Element control = null;
            if (bindId != null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("[addAttributeSet] bindId found: " + bindId);

                JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument());
                final Pointer pointer = context
                        .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                if (pointer != null) {
                    control = (Element) pointer.getNode();
                } else if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("[addAttributeSet] unable to resolve pointer for: //*[@"
                            + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                }
            }

            if (LOGGER.isDebugEnabled()) {
                if (control == null) {
                    LOGGER.debug("[addAttributeSet] control = <not found>");
                } else {
                    LOGGER.debug("[addAttributeSet] control = " + control.getTagName());
                }
            }

            //copy it
            if (control == null) {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("Corresponding control not found");
            } else {
                Element newControl = (Element) control.cloneNode(true);
                //set new Ids to XForm elements
                this.resetXFormIds(newControl);

                formSection.appendChild(newControl);
            }
        } else {
            String attrNamespace = currentAttribute.getNamespace();
            String namespacePrefix = "";
            if (attrNamespace != null && attrNamespace.length() > 0) {
                String prefix = NamespaceResolver.getPrefix(xformsDocument.getDocumentElement(), attrNamespace);
                if (prefix != null && prefix.length() > 0) {
                    namespacePrefix = prefix + ":";
                }
            }

            final String newPathToRoot = (pathToRoot == null || pathToRoot.length() == 0
                    ? "@" + namespacePrefix + currentAttribute.getName()
                    : (pathToRoot.endsWith("/")
                            ? pathToRoot + "@" + namespacePrefix + currentAttribute.getName()
                            : pathToRoot + "/@" + namespacePrefix + currentAttribute.getName()));

            if (LOGGER.isDebugEnabled())
                LOGGER.debug("[addAttributeSet] adding attribute " + attributeName + " at " + newPathToRoot);

            try {
                String defaultValue = (currentAttributeUse.getConstraintType() == XSConstants.VC_NONE ? null
                        : currentAttributeUse.getConstraintValue());
                // make sure boolean attributes have a default value
                if (defaultValue == null && "boolean".equals(currentAttribute.getTypeDefinition().getName())) {
                    defaultValue = "false";
                }

                if (namespacePrefix.length() > 0) {
                    defaultInstanceElement.setAttributeNS(this.targetNamespace, attributeName, defaultValue);
                } else {
                    defaultInstanceElement.setAttribute(attributeName, defaultValue);
                }
            } catch (Exception e) {
                throw new FormBuilderException("error retrieving default value for attribute " + attributeName
                        + " at " + newPathToRoot, e);
            }
            this.addSimpleType(xformsDocument, modelSection, formSection, schema,
                    currentAttribute.getTypeDefinition(), currentAttributeUse, newPathToRoot, resourceBundle);
        }
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

/**
 *//*from ww w .  j a v a  2 s.  co m*/
private void addGroup(final Document xformsDocument, final Element modelSection,
        final Element defaultInstanceElement, final Element formSection, final XSModel schema,
        final XSModelGroup group, final XSComplexTypeDefinition controlType, final XSElementDeclaration owner,
        final String pathToRoot, final SchemaUtil.Occurrence occurs, final boolean checkIfExtension,
        final ResourceBundle resourceBundle) throws FormBuilderException {
    if (group == null) {
        return;
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("[addGroup] Start of addGroup, from owner = " + owner.getName() + " and controlType = "
                + controlType.getName());
        LOGGER.debug("[addGroup] group before =\n" + XMLUtil.toString(formSection));
    }

    final Element repeatSection = this.addRepeatIfNecessary(xformsDocument, modelSection, formSection,
            owner.getTypeDefinition(), pathToRoot, occurs);

    final XSObjectList particles = group.getParticles();
    for (int counter = 0; counter < particles.getLength(); counter++) {
        final XSParticle currentNode = (XSParticle) particles.item(counter);
        XSTerm term = currentNode.getTerm();
        final SchemaUtil.Occurrence childOccurs = new SchemaUtil.Occurrence(currentNode);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("[addGroup] next term = " + term.getName() + ", occurs = " + childOccurs);
        }

        if (term instanceof XSModelGroup) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[addGroup] term is a group");
            }

            this.addGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection, schema,
                    ((XSModelGroup) term), controlType, owner, pathToRoot, childOccurs, checkIfExtension,
                    resourceBundle);
        } else if (term instanceof XSElementDeclaration) {
            XSElementDeclaration element = (XSElementDeclaration) term;

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[addGroup] term is an element declaration: " + term.getName());
            }

            //special case for types already added because used in an extension
            //do not add it when it comes from an extension !!!
            //-> make a copy from the existing form control
            if (checkIfExtension && SchemaUtil.doesElementComeFromExtension(element, controlType)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(
                            "[addGroup] This element comes from an extension: recopy form controls. Model Section =\n"
                                    + XMLUtil.toString(modelSection));
                }

                //find the existing bind Id
                //(modelSection is the enclosing bind of the element)
                NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind");
                String bindId = null;
                for (int i = 0; i < binds.getLength() && bindId == null; i++) {
                    Element bind = (Element) binds.item(i);
                    String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset");

                    Pair<String, String> parsed = parseName(nodeset, xformsDocument);

                    if (nodeset != null
                            && EqualsHelper.nullSafeEquals(parsed.getSecond(), element.getNamespace())
                            && parsed.getFirst().equals(element.getName())) {
                        bindId = bind.getAttributeNS(null, "id");
                    }
                }

                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("[addGroup] found bindId " + bindId + " for element " + element.getName());

                //find the control
                Element control = null;
                if (bindId != null) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[addGroup] bindId found: " + bindId);
                    }

                    final JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument());
                    final Pointer pointer = context
                            .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                    if (pointer != null) {
                        control = (Element) pointer.getNode();
                    } else if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[addGroup] unable to resolve pointer for: //*[@"
                                + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']");
                    }
                }

                if (LOGGER.isDebugEnabled()) {
                    if (control == null) {
                        LOGGER.debug("[addGroup] control = <not found>");
                    } else {
                        LOGGER.debug("[addGroup] control = " + control.getTagName());
                    }
                }

                //copy it
                if (control == null) {
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug("Corresponding control not found");

                    this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection,
                            schema, element, pathToRoot, childOccurs, resourceBundle);
                } else {
                    Element newControl = (Element) control.cloneNode(true);
                    //set new Ids to XForm elements
                    this.resetXFormIds(newControl);

                    repeatSection.appendChild(newControl);
                }
            } else {
                this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection,
                        schema, element, pathToRoot, childOccurs, resourceBundle);
            }
        } else {
            LOGGER.warn("Unhandled term " + term + " found in group from " + owner.getName()
                    + " for pathToRoot = " + pathToRoot);
        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("[addGroup] group after =\n" + XMLUtil.toString(formSection));
        LOGGER.debug("[addGroup] End of addGroup, from owner = " + owner.getName() + " and controlType = "
                + controlType.getName());
    }
}

From source file:org.apache.cocoon.components.expression.jxpath.JXPathExpression.java

public Object getNode(ExpressionContext context) throws ExpressionException {
    Iterator iter = this.compiledExpression.iteratePointers(getContext(context));
    if (iter.hasNext()) {
        Pointer first = (Pointer) iter.next();
        if (iter.hasNext()) {
            List result = new LinkedList();
            result.add(first.getNode());
            boolean dom = (first.getNode() instanceof Node);
            while (iter.hasNext()) {
                Object obj = ((Pointer) iter.next()).getNode();
                dom = dom && (obj instanceof Node);
                result.add(obj);//from  www.  j  a  v  a 2  s .  c  o  m
            }
            Object[] arr;
            if (dom) {
                arr = new Node[result.size()];
            } else {
                arr = new Object[result.size()];
            }
            result.toArray(arr);
            return arr;
        }
        return first.getNode();
    }
    return null;
}

From source file:org.apache.cocoon.el.impl.jxpath.JXPathExpression.java

public Object getNode(ObjectModel objectModel) throws ExpressionException {
    Iterator iter = this.compiledExpression.iteratePointers(getContext(objectModel));
    if (iter.hasNext()) {
        Pointer first = (Pointer) iter.next();
        if (iter.hasNext()) {
            List result = new LinkedList();
            result.add(first.getNode());
            boolean dom = (first.getNode() instanceof Node);
            while (iter.hasNext()) {
                Object obj = ((Pointer) iter.next()).getNode();
                dom = dom && (obj instanceof Node);
                result.add(obj);//w  ww .  j  a  va2s  . c o  m
            }
            Object[] arr;
            if (dom) {
                arr = new Node[result.size()];
            } else {
                arr = new Object[result.size()];
            }
            result.toArray(arr);
            return arr;
        }
        return first.getNode();
    }
    return null;
}