Example usage for org.w3c.dom Node appendChild

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

Introduction

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

Prototype

public Node appendChild(Node newChild) throws DOMException;

Source Link

Document

Adds the node newChild to the end of the list of children of this node.

Usage

From source file:org.etudes.component.app.melete.SubSectionUtilImpl.java

public String MakeSubSection(String sectionsSeqXML, String section_id) throws MeleteException {
    try {//from  www  .ja va 2 s  . c o m
        org.w3c.dom.Document subSectionW3CDOM = Xml.readDocumentFromString(sectionsSeqXML);
        org.w3c.dom.Element root = subSectionW3CDOM.getDocumentElement();
        org.w3c.dom.Element indentthisElement = subSectionW3CDOM.getElementById(section_id);

        //      root.selectSingleNode("//*[@id='" + section_id +"']");
        if (!indentthisElement.getParentNode().getFirstChild().equals(indentthisElement)) {
            logger.debug("actually  creating subsection");
            org.w3c.dom.Node indentParent = indentthisElement.getPreviousSibling();
            indentParent.appendChild(indentthisElement);
        }
        return writeDocumentToString(subSectionW3CDOM);
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.error("some other error in creating sub section" + ex.toString());
            ex.printStackTrace();
        }
        throw new MeleteException("indent_right_fail");
    }
}

From source file:org.etudes.component.app.melete.SubSectionUtilImpl.java

public String bringOneLevelUp(String sectionsSeqXML, String section_id) throws MeleteException {
    try {/*w  w w .  ja v  a2 s . co  m*/
        org.w3c.dom.Document subSectionW3CDOM = Xml.readDocumentFromString(sectionsSeqXML);
        org.w3c.dom.Element root = subSectionW3CDOM.getDocumentElement();
        org.w3c.dom.Element bringUpThisElement = subSectionW3CDOM.getElementById(section_id);

        if (bringUpThisElement == null) {
            throw new MeleteException("indent_left_fail");
        }
        org.w3c.dom.Node makeSiblingOf = bringUpThisElement.getParentNode();
        org.w3c.dom.Node bringUpBeforeThisElement = makeSiblingOf.getNextSibling();

        //Clone the node that needs to be moved
        org.w3c.dom.Node newNode = bringUpThisElement.cloneNode(true);
        org.w3c.dom.Node nextNode = bringUpThisElement.getNextSibling();
        org.w3c.dom.Node prevNode = null;
        //Iterate through each of the node's siblings and make them its children
        //In the process, also delete the siblings
        while (nextNode != null) {
            org.w3c.dom.Node cNode = nextNode.cloneNode(true);
            prevNode = nextNode;
            newNode.appendChild(cNode);
            nextNode = nextNode.getNextSibling();
            prevNode.getParentNode().removeChild(prevNode);
        }
        //Insert the new node, inbetween or end of list, takes null or bringUpBeforeThisElement
        makeSiblingOf.getParentNode().insertBefore(newNode, bringUpBeforeThisElement);
        //Delete node from original position
        bringUpThisElement.getParentNode().removeChild(bringUpThisElement);

        return writeDocumentToString(subSectionW3CDOM);
    } catch (MeleteException mex) {
        throw mex;
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.error("some other error on indenting right" + ex.toString());
            ex.printStackTrace();
        }
        throw new MeleteException("indent_right_fail");
    }
}

From source file:org.firesoa.common.jxpath.model.dom.W3CDomFactory.java

private void addW3CDomElement(Node parent, int index, String tag, String namespaceURI) {
    try {/*from   www.  j a va 2s.  c  o  m*/
        Node child = parent.getFirstChild();
        int count = 0;
        while (child != null) {
            if (child.getNodeName().equals(tag)) {
                count++;
            }
            child = child.getNextSibling();
        }

        // Keep inserting new elements until we have index + 1 of them
        while (count <= index) {
            Document doc = parent.getOwnerDocument();
            Node newElement;
            if (namespaceURI == null) {
                newElement = doc.createElement(tag);
            } else {
                newElement = doc.createElementNS(namespaceURI, tag);
            }

            parent.appendChild(newElement);
            count++;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.firesoa.common.schema.DOMInitializer.java

/**
 * Element//from   www.  j  a v  a2  s .c om
 * @param doc
 * @param parentNode
 * @param childSchemaElement
 * @param xmlSchemaCollection
 * @param createChoice
 */
protected static void createElement(Document doc, Node parentNode, XmlSchemaElement parentSchemaElement,
        XmlSchemaElement childSchemaElement, XmlSchemaCollection xmlSchemaCollection, boolean createChoice) {

    // 1?
    XmlSchemaRef<XmlSchemaElement> ref = childSchemaElement.getRef();
    if (ref != null && ref.getTarget() != null) {
        childSchemaElement = ref.getTarget();
    }

    if (childSchemaElement.getName().equals("foo_1")) {
        System.out.println("this is foo_1");
    }

    QName parentElmTypeQName = null;
    if (parentSchemaElement != null) {
        parentElmTypeQName = parentSchemaElement.getSchemaTypeName();
        if (parentElmTypeQName == null) {
            parentElmTypeQName = parentSchemaElement.getSchemaType().getQName();
        }

    }

    XmlSchemaForm schemaElementForm = childSchemaElement.getForm();

    QName childElmQName = childSchemaElement.getQName();
    Element childElem = null;
    if (schemaElementForm != null && XmlSchemaForm.QUALIFIED.equals(schemaElementForm)) {
        childElem = doc.createElementNS(childElmQName.getNamespaceURI(), getQualifiedName(doc, childElmQName));
    } else {
        if (parentElmTypeQName == null
                || !equalStrings(parentElmTypeQName.getNamespaceURI(), childElmQName.getNamespaceURI())) {
            //
            childElem = doc.createElementNS(childElmQName.getNamespaceURI(),
                    getQualifiedName(doc, childElmQName));
        } else {
            //??namespace prefix
            childElem = doc.createElement(childElmQName.getLocalPart());
        }
    }

    parentNode.appendChild(childElem);

    // 2???
    XmlSchemaType xmlSchemaType = childSchemaElement.getSchemaType();
    if (xmlSchemaType == null) {
        QName qname = childSchemaElement.getSchemaTypeName();
        xmlSchemaType = xmlSchemaCollection.getTypeByQName(qname);
    }
    if (xmlSchemaType instanceof XmlSchemaSimpleType) {
        // ?
        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) xmlSchemaType;
        String value = "";
        if (!StringUtils.isEmpty(childSchemaElement.getFixedValue())) {
            value = childSchemaElement.getFixedValue();
        } else if (!StringUtils.isEmpty(childSchemaElement.getDefaultValue())) {
            value = childSchemaElement.getDefaultValue();
        }
        if (!StringUtils.isEmpty(value)) {
            childElem.appendChild(doc.createTextNode(value));
        }
    } else if (xmlSchemaType instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) xmlSchemaType;

        createChildNode4ComplexType(doc, childElem, childSchemaElement, complexType, xmlSchemaCollection,
                createChoice);
    }
}

From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java

/**
 * Create a html section to open register pattern URL.
 * //from www  .  j  a va2 s .c o  m
 * @param document Document where create section
 * @param linkTarget Base URL to the server
 * @param name Name of pattern
 * @return Html node with register pattern open URL
 */
protected Node openCommandRegister(Document document, String linkTarget, String name) {

    Node tr = document.createElement("tr");

    Node td1 = tr.appendChild(document.createElement("td"));
    td1.setTextContent("open");

    // Add pattern request attributes
    Node td2 = tr.appendChild(document.createElement("td"));

    td2.setTextContent(linkTarget + (linkTarget.contains("?") ? "&" : "?") + "gvnixform" + "&gvnixpattern="
            + name + "&index=1" + "&lang=" + Locale.getDefault());

    Node td3 = tr.appendChild(document.createElement("td"));
    td3.setTextContent(" ");

    return tr;
}

From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java

/**
 * Create a html section to open tabular pattern URL.
 * //  w  w  w.  ja  v  a2  s .co m
 * @param document Document where create section
 * @param linkTarget Base URL to the server
 * @param name Name of pattern
 * @return Html node with tabular pattern open URL
 */
protected Node openCommandTabular(Document document, String linkTarget, String name) {

    Node tr = document.createElement("tr");

    Node td1 = tr.appendChild(document.createElement("td"));
    td1.setTextContent("open");

    // Add pattern request attributes
    Node td2 = tr.appendChild(document.createElement("td"));

    td2.setTextContent(linkTarget + (linkTarget.contains("?") ? "&" : "?") + "gvnixpattern=" + name + "&lang="
            + Locale.getDefault());

    Node td3 = tr.appendChild(document.createElement("td"));
    td3.setTextContent(" ");

    return tr;
}

From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java

/**
 * Add command click and wait for a URL.
 * /*from   w  w  w. j  a  va2  s .c o m*/
 * @param document Document to write command
 * @param linkTarget Destination URL
 * @return Click and wait node
 */
protected Node clickAndWaitCommand(Document document, String linkTarget) {

    Node tr = document.createElement("tr");

    Node td1 = tr.appendChild(document.createElement("td"));
    td1.setTextContent("clickAndWait");

    Node td2 = tr.appendChild(document.createElement("td"));
    td2.setTextContent(linkTarget);

    Node td3 = tr.appendChild(document.createElement("td"));
    td3.setTextContent(" ");

    return tr;
}

From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java

/**
 * Add command click for a URL.//ww  w  .ja  v  a2s.c  om
 * 
 * @param document Document to write command
 * @param linkTarget Destination URL
 * @return Click node
 */
protected Node clickCommand(Document document, String linkTarget) {

    Node tr = document.createElement("tr");

    Node td1 = tr.appendChild(document.createElement("td"));
    td1.setTextContent("click");

    Node td2 = tr.appendChild(document.createElement("td"));
    td2.setTextContent(linkTarget);

    Node td3 = tr.appendChild(document.createElement("td"));
    td3.setTextContent(" ");

    return tr;
}

From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java

/**
 * Add type value command for register pattern.
 * //w w  w  .j  a  va 2  s. c o  m
 * @param document Document to write command
 * @param field Field to add value
 * @return Type node
 */
protected Node typeCommandRegister(Document document, FieldMetadata field, boolean random) {

    Node tr = document.createElement("tr");

    Node td1 = tr.appendChild(document.createElement("td"));
    td1.setTextContent("type");

    Node td2 = tr.appendChild(document.createElement("td"));

    td2.setTextContent("_" + field.getFieldName().getSymbolName() + "_id");

    Node td3 = tr.appendChild(document.createElement("td"));
    td3.setTextContent(convertToInitializer(field, random));

    return tr;
}

From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java

/**
 * Add type value command for tabular pattern.
 * // w ww  . j  a v a  2s.c  o  m
 * @param document Document to write command
 * @param field Field to add value
 * @param entity Field parent entity
 * @return Type node
 */
protected Node typeCommandTabular(Document document, FieldMetadata field, JavaType entity, boolean random) {

    Node tr = document.createElement("tr");

    Node td1 = tr.appendChild(document.createElement("td"));
    td1.setTextContent("type");

    Node td2 = tr.appendChild(document.createElement("td"));

    String id = "_" + XmlUtils.convertId("fu:" + entity.getFullyQualifiedTypeName()) + "[0]_"
            + field.getFieldName() + "_id_create";
    td2.setTextContent(id);

    Node td3 = tr.appendChild(document.createElement("td"));
    td3.setTextContent(convertToInitializer(field, random));

    return tr;
}