Example usage for org.w3c.dom Node getNextSibling

List of usage examples for org.w3c.dom Node getNextSibling

Introduction

In this page you can find the example usage for org.w3c.dom Node getNextSibling.

Prototype

public Node getNextSibling();

Source Link

Document

The node immediately following this node.

Usage

From source file:utils.form.WebFormUserInputsCollector.java

private boolean leftRightDirectedSiblingHasNoInput(Node node, boolean leftLabeled) {
    boolean retVal = true;
    for (int i = 0; i < USER_CHANGABLE_INPUT_TAGS.length; i++) {

        if (leftLabeled) {
            if (node.getPreviousSibling() == null) {
                retVal = true;/*w w w .  ja  va  2  s  . com*/
            } else if (Arrays.asList(USER_CHANGABLE_INPUT_TAGS)
                    .contains(node.getPreviousSibling().getNodeName().toLowerCase()))
                retVal = false;
            else
                retVal = retVal && $(node.getPreviousSibling()).find(USER_CHANGABLE_INPUT_TAGS[i]).isEmpty();
        }
        if (!leftLabeled) {
            if (node.getNextSibling() == null) {
                retVal = true;
            } else if (Arrays.asList(USER_CHANGABLE_INPUT_TAGS)
                    .contains(node.getNextSibling().getNodeName().toLowerCase()))
                retVal = false;
            else
                retVal = retVal && $(node.getNextSibling()).find(USER_CHANGABLE_INPUT_TAGS[i]).isEmpty();
        }
    }
    return retVal;
}

From source file:utils.form.WebFormUserInputsCollector.java

private boolean leftRightDirectedSiblingWithLabel(Node node, boolean leftLabeled) {
    boolean retVal = false;
    if (leftLabeled) {
        if (node.getPreviousSibling() != null) {
            retVal = $(node.getPreviousSibling()).find("label").isNotEmpty()
                    || node.getPreviousSibling().getNodeName().equalsIgnoreCase("label");
        }//from   w  w  w . ja v  a2  s  .co m
    } else {
        if (node.getNextSibling() != null) {
            retVal = $(node.getNextSibling()).find("label").isNotEmpty()
                    || node.getNextSibling().getNodeName().equalsIgnoreCase("label");
        }
    }
    return retVal;
}

From source file:utils.form.WebFormUserInputsCollector.java

private List<Element> getLeftRightDirectedSiblingLabelInNode(Node node, boolean leftLabeled) {
    List<Element> labels2 = new ArrayList<Element>();

    if (leftLabeled) {
        if (node.getPreviousSibling().getNodeName().equalsIgnoreCase("label"))
            labels2.add((Element) node.getPreviousSibling());
        else// w w  w. j  a  v  a 2s  . co m
            labels2 = $(node.getPreviousSibling()).find("label").get();
    } else {
        if (node.getNextSibling().getNodeName().equalsIgnoreCase("label"))
            labels2.add((Element) node.getPreviousSibling());
        else
            labels2 = $(node.getNextSibling()).find("label").get();
    }
    return labels2;
}

From source file:utils.form.WebFormUserInputsCollector.java

private UserInputDom initUserInputDomInsideOfForm(Document domDoc, Node inputNode, Node form) {
    // NodeList allInputNodes, Node inputNodeParentForm) {
    UserInputDom retVal = new UserInputDom(inputNode);

    boolean leftLabeled = isLeftLabeled(inputNode);

    retVal.setxPath($(inputNode).xpath());
    retVal.setParentFormPointer(form);//from  w w  w . j  ava2 s.  c o  m

    Node maxInputParentNoOtherInput = getMaxInputParentNoOtherInput(inputNode, true);

    // Node tempParent = inputNode.getParentNode();
    boolean singleInputFieldForm = false;

    // Node maxInputParentNoOtherInput = tempParent;
    // while (($(tempParent).find("input").get().size() + $(tempParent)
    // .find("textarea").get().size()) <= 1) {
    // maxInputParentNoOtherInput = tempParent;
    // if (tempParent.getNodeName().equalsIgnoreCase("form")) {
    // singleFieldForm = true;
    // break;
    // }
    // tempParent = tempParent.getParentNode();
    // }
    // if signlefieldform leastInputsCommonParent is the form node
    Node leastInputsCommonParent;
    if (maxInputParentNoOtherInput.getNodeName().equalsIgnoreCase("form")) {
        leastInputsCommonParent = maxInputParentNoOtherInput;
        singleInputFieldForm = true;
    } else
        leastInputsCommonParent = maxInputParentNoOtherInput.getParentNode();

    boolean singleFieldFormInputHasNoSibling = false;
    Node maxInputParentNoOtherChild = getMaxInputParentNoOtherChild(inputNode);
    // Node tempParent2 = inputNode.getParentNode();
    // Node maxInputParentNoOtherChild = inputNode;
    // while ($(tempParent2).children().get().size() <= 1) {
    // maxInputParentNoOtherChild = tempParent2;
    if (maxInputParentNoOtherChild.getNodeName().equalsIgnoreCase("form")) {
        singleFieldFormInputHasNoSibling = true;
        // new a return result in a single input and no input
        // sibling form
        List<Node> temp1 = new ArrayList<Node>();
        temp1.add(maxInputParentNoOtherChild.getChildNodes().item(0));
        retVal.setMachineLearningDomHtmlPointer(temp1);

        retVal.setLabelDomPointer(maxInputParentNoOtherChild.getPreviousSibling());

        if (leftLabeled) {
            List<Node> temp = new ArrayList<Node>();
            temp.add(maxInputParentNoOtherChild.getNextSibling());
            retVal.setAdditionalInfoNodes(temp);
        }
        retVal.setPreviousUserViewableHtmlSibling(maxInputParentNoOtherChild.getPreviousSibling());
        retVal.setNextUserViewableHtmlSibling(maxInputParentNoOtherChild.getNextSibling());
        // break;
    }
    // tempParent2 = tempParent2.getParentNode();
    // }
    // TODO the parent of maxInputParentNoOtherChild might have input
    // fields, might not have input fields
    Node leastNonInputSiblingsParent = maxInputParentNoOtherChild.getParentNode();
    if (singleInputFieldForm && !singleFieldFormInputHasNoSibling) {
        List<Node> temp = new ArrayList<Node>();
        for (int i = 0; i < leastInputsCommonParent.getChildNodes().getLength(); i++) {
            temp.add(leastInputsCommonParent.getChildNodes().item(i));
        }
        retVal.setMachineLearningDomHtmlPointer(temp);

        List<Element> labels = $(leastInputsCommonParent).find("label").get();
        if (labels.size() > 0) {
            retVal.setLabelDomPointer(labels.get(0));
        } else {

            fillOutNonLabeledFieldLabelDomPointer(retVal, maxInputParentNoOtherChild, leastInputsCommonParent,
                    false, leftLabeled);
            // tempParent2 = maxInputParentNoOtherChild;
            //
            // while (tempParent2.getPreviousSibling() == null
            // && !tempParent2.getNodeName().equalsIgnoreCase(
            // "form")) {
            // tempParent2 = tempParent2.getParentNode();
            // }
            // // if tempParent2 is form node, we will use the form's
            // // previous sibling as the label node;
            // // Or we will use the nearest input sibling node as the
            // // label node;
            // retVal.setLabelDomPointer(tempParent2.getPreviousSibling());

        }

        // fill out addtional info nodes
        if (leftLabeled)
            fillOutAddtionalInfoNode(retVal, maxInputParentNoOtherChild, leastInputsCommonParent, false, false);
        // tempParent2 = maxInputParentNoOtherChild;
        // List<Node> additionalInfoNodes = new ArrayList<Node>();
        // while (tempParent2.getNextSibling() == null
        // && !tempParent2.getNodeName().equalsIgnoreCase("form")) {
        // tempParent2 = tempParent2.getParentNode();
        // Node tempNode = tempParent2;
        // while (tempNode.getNextSibling() != null) {
        // additionalInfoNodes.add(tempNode.getNextSibling());
        // if (tempNode.getNodeName().equalsIgnoreCase("form")) break;
        // tempNode = tempNode.getNextSibling();
        // }
        // }
        // retVal.setAdditionalInfoNodes(additionalInfoNodes);

        // fill out non empty user viewable previous sibling
        fillOutUserViewablePreviousSibling(retVal, maxInputParentNoOtherChild, leastInputsCommonParent, false);
        // tempParent2 = maxInputParentNoOtherChild;
        //
        // while (tempParent2.getPreviousSibling() == null
        // && !tempParent2.getNodeName().equalsIgnoreCase(
        // "form")) {
        // tempParent2 = tempParent2.getParentNode();
        // }
        // // if tempParent2 is form node, we will use the form's
        // // previous sibling as the label node;
        // // Or we will use the nearest input sibling node as the
        // // label node;
        // retVal.setPreviousUserViewableHtmlSibling(tempParent2.getPreviousSibling());

        // set non empty user viewable next sibling
        fillOutUserViewableNextSibling(retVal, maxInputParentNoOtherChild, leastInputsCommonParent, false);
        // tempParent2 = maxInputParentNoOtherChild;
        // while (tempParent2.getNextSibling() == null
        // && !tempParent2.getNodeName().equalsIgnoreCase("form")) {
        // tempParent2 = tempParent2.getParentNode();
        // }
        // retVal.setNextUserViewableHtmlSibling(tempParent2.getNextSibling());

    } else if (!singleFieldFormInputHasNoSibling) {

        List<Element> labels = $(maxInputParentNoOtherInput).find("label").get();
        if (labels.size() > 0) {

            List<Node> tempList = new ArrayList<Node>();
            tempList.add(maxInputParentNoOtherInput);
            retVal.setMachineLearningDomHtmlPointer(tempList);

            retVal.setLabelDomPointer(labels.get(0));
            if (leftLabeled)
                fillOutAddtionalInfoNode(retVal, maxInputParentNoOtherChild, leastNonInputSiblingsParent, false,
                        false);
            fillOutUserViewablePreviousSibling(retVal, maxInputParentNoOtherChild, leastNonInputSiblingsParent,
                    false);
            fillOutUserViewableNextSibling(retVal, maxInputParentNoOtherChild, leastNonInputSiblingsParent,
                    false);
        } else {
            if (leftRightDirectedSiblingHasNoInput(maxInputParentNoOtherInput, leftLabeled)
                    && leftRightDirectedSiblingWithLabel(maxInputParentNoOtherInput, leftLabeled)) {
                List<Element> labels2 = getLeftRightDirectedSiblingLabelInNode(maxInputParentNoOtherInput,
                        leftLabeled);

                List<Node> tempList = new ArrayList<Node>();
                if (leftLabeled) {
                    tempList.add(maxInputParentNoOtherInput.getPreviousSibling());
                    tempList.add(maxInputParentNoOtherInput);
                } else {
                    tempList.add(maxInputParentNoOtherInput);
                    tempList.add(maxInputParentNoOtherInput.getNextSibling());
                }
                retVal.setMachineLearningDomHtmlPointer(tempList);

                retVal.setLabelDomPointer(labels2.get(0));

                if (leftLabeled && leftRightDirectedSiblingHasNoInput(maxInputParentNoOtherInput, false))
                    fillOutAddtionalInfoNode(retVal, maxInputParentNoOtherInput,
                            maxInputParentNoOtherInput.getParentNode(), false, true);
                fillOutUserViewablePreviousSibling(retVal, maxInputParentNoOtherInput,
                        maxInputParentNoOtherInput.getParentNode(), false);
                fillOutUserViewableNextSibling(retVal, maxInputParentNoOtherInput,
                        maxInputParentNoOtherInput.getParentNode(), false);
            } else if (this.siblingHasInput(maxInputParentNoOtherInput)) {
                // most likely field (label equivelant information has been
                // inside Node
                // maxInputParentNoOtherInput
                List<Node> tempList = new ArrayList<Node>();
                tempList.add(maxInputParentNoOtherInput);
                retVal.setMachineLearningDomHtmlPointer(tempList);

                fillOutNonLabeledFieldLabelDomPointer(retVal, maxInputParentNoOtherChild,
                        maxInputParentNoOtherInput, false, leftLabeled);
                if (leftLabeled)
                    fillOutAddtionalInfoNode(retVal, maxInputParentNoOtherChild, maxInputParentNoOtherInput,
                            false, false);
                fillOutUserViewablePreviousSibling(retVal, maxInputParentNoOtherChild,
                        maxInputParentNoOtherInput, false);
                fillOutUserViewableNextSibling(retVal, maxInputParentNoOtherChild, maxInputParentNoOtherInput,
                        false);

            } else if (leftRightDirectedSiblingHasNoInput(maxInputParentNoOtherInput, leftLabeled)) {
                // most likely field information is out of
                // maxInputParentNoOtherInput in its siblings with no label
                // tag
                List<Node> tempList = new ArrayList<Node>();
                if (leftLabeled) {
                    tempList.add(maxInputParentNoOtherInput.getPreviousSibling());
                    tempList.add(maxInputParentNoOtherInput);
                } else {
                    tempList.add(maxInputParentNoOtherInput);
                    tempList.add(maxInputParentNoOtherInput.getNextSibling());
                }
                retVal.setMachineLearningDomHtmlPointer(tempList);

                if (leftLabeled)
                    retVal.setLabelDomPointer(maxInputParentNoOtherInput.getPreviousSibling());
                else
                    retVal.setLabelDomPointer(maxInputParentNoOtherInput.getNextSibling());

                if (leftLabeled && leftRightDirectedSiblingHasNoInput(maxInputParentNoOtherInput, false))
                    fillOutAddtionalInfoNode(retVal, maxInputParentNoOtherInput,
                            maxInputParentNoOtherInput.getParentNode(), false, true);

                fillOutUserViewablePreviousSibling(retVal, maxInputParentNoOtherInput,
                        maxInputParentNoOtherInput.getParentNode(), false);
                fillOutUserViewableNextSibling(retVal, maxInputParentNoOtherInput,
                        maxInputParentNoOtherInput.getParentNode(), false);

            }
        }
        // if (leastNonInputSiblingsParent != leastInputsCommonParent) {
        // tempParent2 = leastNonInputSiblingsParent;
        // while (tempParent2.getParentNode() != leastInputsCommonParent) {
        // tempParent2.getParentNode();
        // }
        // Node maxNonInputSiblingsParent = tempParent2;
        //
        // } else {
        // List<Element> allInputSiblings = $(leastInputsCommonParent)
        // .children().get();
        // for (int indexOfDirectChild; indexOfDirectChild <
        // allInputSiblings
        // .size(); indexOfDirectChild++) {
        // // if the sibling has form in it, then ignore this
        // // sibling since it and its children inputs are not
        // // related to this current processing input.
        // if ($(allInputSiblings.get(indexOfDirectChild))
        // .find("form").get().size() > 0) {
        // continue;
        // }
        //
        // int sizeOfInputElementInSibling = $(
        // allInputSiblings.get(indexOfDirectChild))
        // .find("input").get().size();
        // if (sizeOfInputElementInSibling == 1) {
        // // input block which might have label and additional
        // // info
        // Node nextSibling = allInputSiblings.get(
        // indexOfDirectChild).getNextSibling();
        // Node previousSibling = allInputSiblings.get(
        // indexOfDirectChild).getPreviousSibling();
        // if (previousSibling == null) {
        // // first child in least common parent
        //
        // } else if (nextSibling == null) {
        // // last child in least common parent
        // } else {
        // // neither first nor last child.
        // if ($(nextSibling).find("input").get().size() == 1) {
        // // this html block most likely a label
        // }
        // }
        // } else if (sizeOfInputElementInSibling == 0) {
        // // might be label or other information of the next
        // // input or might be non input related infor.
        // continue;
        //
        // } else if (sizeOfInputElementInSibling > 1) {
        // // html block has more than one input, need to find
        // // the least parent for these inputs.
        // // TODO need a nest function to handle this type of
        // // html block
        // }
        // }
        // }
    }
    return retVal;
}

From source file:writer2latex.latex.FieldConverter.java

/** <p>Process sequence declarations</p>
 *  @param node the text:sequence-decls node
 *///from   w w  w. ja  v  a 2s  .  co  m
public void handleSequenceDecls(Element node) {
    Node child = node.getFirstChild();
    while (child != null) {
        if (Misc.isElement(child, XMLString.TEXT_SEQUENCE_DECL)) {
            // Don't process the declaration, but store a reference
            seqDecl.put(((Element) child).getAttribute(XMLString.TEXT_NAME), child);
        }
        child = child.getNextSibling();
    }
}