Example usage for org.w3c.dom Element removeChild

List of usage examples for org.w3c.dom Element removeChild

Introduction

In this page you can find the example usage for org.w3c.dom Element removeChild.

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

From source file:net.sf.zekr.engine.bookmark.BookmarkSet.java

private void updateXml() {
    // remove all items first
    Element root = xmlDocument.getDocumentElement();
    NodeList nodes = root.getChildNodes();
    int childNodeCount = nodes.getLength();
    // it should carefully remove from the end of the list (because nodes.getLenth() is decreased as nodes
    // are removed)
    for (int i = childNodeCount - 1; i >= 0; i--) {
        Node node = nodes.item(i);
        root.removeChild(node);
    }//from   w  w  w.  j  a v a2  s .co  m

    Element infoElem = xmlDocument.createElement("info");
    root.appendChild(infoElem);

    Element nameElem = xmlDocument.createElement("name");
    nameElem.appendChild(xmlDocument.createTextNode(getName()));
    infoElem.appendChild(nameElem);
    Element authorElem = xmlDocument.createElement("author");
    authorElem.appendChild(xmlDocument.createTextNode(getAuthor()));
    infoElem.appendChild(authorElem);
    Element language = xmlDocument.createElement("language");
    language.appendChild(xmlDocument.createTextNode(getLanguage()));
    infoElem.appendChild(language);
    Element dirElem = xmlDocument.createElement("dir");
    dirElem.appendChild(xmlDocument.createTextNode(getDirection()));
    infoElem.appendChild(dirElem);
    Element descElem = xmlDocument.createElement("desc");
    descElem.appendChild(xmlDocument.createTextNode(getDescription()));
    infoElem.appendChild(descElem);
    Element modifyDataElem = xmlDocument.createElement("modifyDate");
    setModifyDate(new Date());
    modifyDataElem.appendChild(xmlDocument.createTextNode(dateToString(getModifyDate())));
    infoElem.appendChild(modifyDataElem);
    Element createDateElem = xmlDocument.createElement("createDate");
    createDateElem.appendChild(xmlDocument.createTextNode(
            getCreateDate() == null ? dateToString(getModifyDate()) : dateToString(getCreateDate())));
    infoElem.appendChild(createDateElem);

    _updateXml(parentItem, root);
}

From source file:org.gvnix.dynamic.configuration.roo.addon.PomManagerImpl.java

/**
 * Write a component into POM profile./*from   w  w  w .  j  a  va  2s.c o m*/
 * 
 * @param doc Pom document
 * @param prof Profile element
 * @return New component element
 */
protected Element exportComponent(Document doc, Element prof) {

    Element root = doc.getDocumentElement();

    // <resources>
    // <resource>
    // <directory>src/main/resources</directory>
    // <filtering>true</filtering>
    // </resource>
    // </resources>

    // Build section: find or create if not exists
    Element build = XmlUtils.findFirstElement("/project/build", root);
    if (build == null) {

        build = doc.createElement("build");
        root.appendChild(build);
    }

    Element resos;

    // Resources section: find or create if not exists
    resos = XmlUtils.findFirstElement("resources", build);
    if (resos == null) {

        resos = doc.createElement("resources");
        build.appendChild(resos);
    }

    // Find resource section with directory and filter
    Element reso = XmlUtils.findFirstElement(
            "resource/directory" + "[text()='" + RESOURCES_PATH + "']/../filtering[text()='true']/..", resos);

    // Remove resource if already exists
    if (reso != null) {

        resos.removeChild(reso);
    }

    // Create resource section with directory and filter
    reso = doc.createElement("resource");
    resos.appendChild(reso);
    Element dir = doc.createElement("directory");
    dir.setTextContent(RESOURCES_PATH);
    reso.appendChild(dir);
    Element filter = doc.createElement("filtering");
    filter.setTextContent("true");
    reso.appendChild(filter);

    // <properties>
    // </properties>

    // Properties section: find or create if not exists
    Element props = XmlUtils.findFirstElement("properties", prof);
    if (props == null) {
        props = doc.createElement("properties");
        prof.appendChild(props);
    }

    return props;
}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.general.GeneralConfigConverter.java

private void convertJmxListener(Document document, Element server, JmxListener from,
        Properties catalinaProperties) {
    Element jmxListener = null;//from ww w. ja  va2  s  .  c o m
    boolean foundJmxListener = false;
    for (Element listener : DomUtils.getChildElementsByTagName(server, TAG_NAME_LISTENER)) {
        if ("com.springsource.tcserver.serviceability.rmi.JmxSocketListener"
                .equals(listener.getAttribute(ATTRIBUTE_CLASS_NAME))) {
            foundJmxListener = true;
            jmxListener = listener;
            if (!from.getEnabled()) {
                server.removeChild(jmxListener);
            }
        }
    }
    if (from.getEnabled()) {
        if (!foundJmxListener) {
            jmxListener = document.createElement(TAG_NAME_LISTENER);
            jmxListener.setAttribute(ATTRIBUTE_CLASS_NAME,
                    "com.springsource.tcserver.serviceability.rmi.JmxSocketListener");
        }
        setAttribute(jmxListener, ACCESS_FILE, from.getAccessFile(), catalinaProperties, true);
        if (from.getAuthenticate() != null) {
            setAttribute(jmxListener, AUTHENTICATE, from.getAuthenticate(), catalinaProperties, true);
        }
        setAttribute(jmxListener, BIND, from.getBind(), catalinaProperties, true);
        setAttribute(jmxListener, CIPHER_SUITES, from.getCipherSuites(), catalinaProperties, true);
        if (from.getClientAuth() != null) {
            setAttribute(jmxListener, CLIENT_AUTH, from.getClientAuth(), catalinaProperties, true);
        }
        setAttribute(jmxListener, KEYSTORE_FILE, from.getKeystoreFile(), catalinaProperties, true);
        setAttribute(jmxListener, KEYSTORE_PASS, from.getKeystorePass(), catalinaProperties, true);
        setAttribute(jmxListener, PASSOWRD_FILE, from.getPasswordFile(), catalinaProperties, true);
        if (from.getPort() != null) {
            setAttribute(jmxListener, JMX_PORT, from.getPort(), catalinaProperties, true);
        }
        setAttribute(jmxListener, PROTOCOLS, from.getProtocols(), catalinaProperties, true);
        setAttribute(jmxListener, TRUSTSTORE_FILE, from.getTruststoreFile(), catalinaProperties, true);
        setAttribute(jmxListener, TRUSTSTORE_PASS, from.getTruststorePass(), catalinaProperties, true);
        if (from.getUseJdkClientFactory() != null) {
            setAttribute(jmxListener, USE_JDK_CLIENT_FACTORY, from.getUseJdkClientFactory(), catalinaProperties,
                    true);
        }
        if (from.getUseSSL() != null) {
            setAttribute(jmxListener, USE_SSL, from.getUseSSL(), catalinaProperties, true);
        }
        if (!foundJmxListener) {
            server.appendChild(jmxListener);
        }
    }
}

From source file:org.gvnix.dynamic.configuration.roo.addon.ConfigurationsImpl.java

/**
 * {@inheritDoc}/*w ww  .  j av  a  2  s .c  o m*/
 */
public DynProperty updateProperty(String configuration, String property, String value) {

    // Get the required property element to update
    Element prop = getProperty(configuration, property);
    if (prop == null) {
        return null;
    }

    // Get the property value element
    Node valueElem = getValueElement(prop);

    if (value == null) {
        if (valueElem != null) {

            // Undefined property value: remove property value element
            prop.removeChild(valueElem);
        }

    } else {

        if (valueElem == null) {

            // Undo undefined property value: Create property value element
            valueElem = prop.getOwnerDocument().createElement(VALUE_ELEMENT_NAME);
            prop.appendChild(valueElem);
        }

        // Set property value
        valueElem.setTextContent(value);
    }

    saveConfiguration(prop);

    return parseProperty(prop);
}

From source file:be.fedict.eid.applet.service.signer.ooxml.RelationshipTransformService.java

private void sortRelationshipElements(Element relationshipsElement) {
    List<Element> relationshipElements = new LinkedList<Element>();
    NodeList relationshipNodes = relationshipsElement.getElementsByTagName("*");
    int nodeCount = relationshipNodes.getLength();
    for (int nodeIdx = 0; nodeIdx < nodeCount; nodeIdx++) {
        Node relationshipNode = relationshipNodes.item(0);
        Element relationshipElement = (Element) relationshipNode;
        LOG.debug("unsorted Id: " + relationshipElement.getAttribute("Id"));
        relationshipElements.add(relationshipElement);
        relationshipsElement.removeChild(relationshipNode);
    }//  www.ja  v a  2s .  co m
    Collections.sort(relationshipElements, new RelationshipComparator());
    for (Element relationshipElement : relationshipElements) {
        LOG.debug("sorted Id: " + relationshipElement.getAttribute("Id"));
        relationshipsElement.appendChild(relationshipElement);
    }
}

From source file:com.twinsoft.convertigo.engine.migration.Migration7_0_0.java

public static Element migrate(Document document, Element projectNode) throws EngineException {
    try {//from www.  j a v a 2s.c o m
        NodeList mobileDevicesNodeList = XMLUtils.findElements(projectNode, "/mobiledevice");
        if (mobileDevicesNodeList != null) {
            MobileApplication mobileApplication = new MobileApplication();
            Element mobileApplicationElement = mobileApplication.toXml(document);
            projectNode.appendChild(mobileApplicationElement);

            Node[] mobileDeviceNodes = XMLUtils.toNodeArray(mobileDevicesNodeList);
            boolean hasAndroid = false;
            boolean hasIOs = false;

            for (Node mobileDeviceNode : mobileDeviceNodes) {
                Element mobileDevice = (Element) mobileDeviceNode;
                String classname = mobileDevice.getAttribute("classname");

                if (classname == null) {
                    // may never arrived
                } else if (classname.equals("com.twinsoft.convertigo.beans.mobiledevices.Android")) {
                    hasAndroid = true;
                } else if (classname.startsWith("com.twinsoft.convertigo.beans.mobiledevices.IP")) {
                    hasIOs = true;
                }

                projectNode.removeChild(mobileDevice);
            }

            if (hasAndroid) {
                mobileApplicationElement.appendChild(new Android().toXml(document));
            }
            if (hasIOs) {
                mobileApplicationElement.appendChild(new IOs().toXml(document));
            }
            if (hasAndroid && hasIOs) {
                mobileApplicationElement.appendChild(new WindowsPhone8().toXml(document));
                mobileApplicationElement.appendChild(new Windows().toXml(document));
            }

            String projectName = "" + XMLUtils.findPropertyValue(projectNode, "name");
            File mobileFolder = new File(Engine.PROJECTS_PATH + "/" + projectName + "/DisplayObjects/mobile");
            if (mobileFolder.exists()) {
                FileUtils.write(new File(mobileFolder, "mobile_project_migrated.txt"),
                        "Your mobile project has been migrated.\n"
                                + "Now, we make per platform configuration and resources.\n"
                                + "You may customize your config.xml (the existing one will never used) and dispatch your existing specific resources per platform (see the 'platforms' folder).\n"
                                + "You can delete this file after reading it.",
                        "UTF-8");
            }
        }
    } catch (Exception e) {
        throw new EngineException("[Migration 7.0.0] Unable to migrate project", e);
    }

    return projectNode;
}

From source file:com.enonic.cms.web.portal.services.ContentServicesBase.java

protected String buildXML(UserServicesService userServices, User user, ExtendedMap formItems, SiteKey siteKey,
        int contentTypeKey, String contentTitle, boolean skipEmptyElements) {

    Document doc;/* ww w . j a  v a  2s. c  o m*/
    Element contentElem;
    Element contentdataElem;
    int contentKey = formItems.getInt("key", -1);

    if (contentKey == -1) {
        contentKey = formItems.getInt("contentkey", -1);
    }

    if (contentKey == -1) {
        doc = XMLTool.createDocument("content");
        contentElem = doc.getDocumentElement();

        int categoryKey = formItems.getInt("categorykey");
        CategoryEntity categoryEntity = categoryDao.findByKey(new CategoryKey(categoryKey));

        if (categoryEntity.getAutoMakeAvailableAsBoolean()) {
            contentElem.setAttribute("publishfrom", CalendarUtil.formatCurrentDate());
            contentElem.setAttribute("status", "2");
        } else {
            // new content is created as draft
            contentElem.setAttribute("status", "0");
            contentElem.removeAttribute("publishfrom");
            contentElem.removeAttribute("publishto");
        }

        contentElem.setAttribute("contenttypekey", String.valueOf(contentTypeKey));
        contentElem.setAttribute("priority", "0");

        // category:
        Element category = XMLTool.createElement(doc, contentElem, "categoryname");
        category.setAttribute("key", String.valueOf(categoryKey));

        // content title
        XMLTool.createElement(doc, contentElem, "title", contentTitle);

        // content data
        contentdataElem = XMLTool.createElement(doc, contentElem, "contentdata");
    } else {
        doc = userServices.getContent(user, contentKey, false, 0, 0, 0).getAsDOMDocument();
        Element rootElem = doc.getDocumentElement();
        contentElem = XMLTool.getFirstElement(rootElem);
        rootElem.removeChild(contentElem);
        doc.replaceChild(contentElem, rootElem);

        // modifier/@key
        Element modifierElem = XMLTool.getElement(contentElem, "modifier");
        XMLTool.removeChildFromParent(contentElem, modifierElem);
        modifierElem = XMLTool.createElement(contentElem, "modifier");
        modifierElem.setAttribute("key", String.valueOf(user.getKey()));

        // version/@key
        int versionKey = userServices.getCurrentVersionKey(contentKey);
        contentElem.setAttribute("versionkey", String.valueOf(versionKey));

        // content title
        Element title = XMLTool.getElement(contentElem, "title");
        XMLTool.removeChildNodes(title);
        XMLTool.createTextNode(doc, title, contentTitle);

        // content data
        contentdataElem = XMLTool.getElement(contentElem, "contentdata");
        XMLTool.removeChildNodes(contentdataElem, true);
    }

    buildContentTypeXML(userServices, contentdataElem, formItems, skipEmptyElements);

    return XMLTool.documentToString(doc);
}

From source file:com.enonic.vertical.userservices.ContentHandlerBaseController.java

protected String buildXML(UserServicesService userServices, User user, ExtendedMap formItems, SiteKey siteKey,
        int contentTypeKey, String contentTitle, boolean skipEmptyElements)
        throws VerticalUserServicesException, RemoteException {

    Document doc;/*w w w . ja v a2s  .  c o  m*/
    Element contentElem;
    Element contentdataElem;
    int contentKey = formItems.getInt("key", -1);

    if (contentKey == -1) {
        contentKey = formItems.getInt("contentkey", -1);
    }

    if (contentKey == -1) {
        doc = XMLTool.createDocument("content");
        contentElem = doc.getDocumentElement();

        int categoryKey = formItems.getInt("categorykey");
        CategoryEntity categoryEntity = categoryDao.findByKey(new CategoryKey(categoryKey));

        if (categoryEntity.getAutoMakeAvailableAsBoolean()) {
            contentElem.setAttribute("publishfrom", CalendarUtil.formatCurrentDate());
            contentElem.setAttribute("status", "2");
        } else {
            // new content is created as draft
            contentElem.setAttribute("status", "0");
            contentElem.removeAttribute("publishfrom");
            contentElem.removeAttribute("publishto");
        }

        contentElem.setAttribute("contenttypekey", String.valueOf(contentTypeKey));
        contentElem.setAttribute("priority", "0");

        // category:
        Element category = XMLTool.createElement(doc, contentElem, "categoryname");
        category.setAttribute("key", String.valueOf(categoryKey));

        // content title
        XMLTool.createElement(doc, contentElem, "title", contentTitle);

        // content data
        contentdataElem = XMLTool.createElement(doc, contentElem, "contentdata");
    } else {
        doc = XMLTool.domparse(userServices.getContent(user, contentKey, false, 0, 0, 0));
        Element rootElem = doc.getDocumentElement();
        contentElem = XMLTool.getFirstElement(rootElem);
        rootElem.removeChild(contentElem);
        doc.replaceChild(contentElem, rootElem);

        // modifier/@key
        Element modifierElem = XMLTool.getElement(contentElem, "modifier");
        XMLTool.removeChildFromParent(contentElem, modifierElem);
        modifierElem = XMLTool.createElement(contentElem, "modifier");
        modifierElem.setAttribute("key", String.valueOf(user.getKey()));

        // version/@key
        int versionKey = userServices.getCurrentVersionKey(contentKey);
        contentElem.setAttribute("versionkey", String.valueOf(versionKey));

        // content title
        Element title = XMLTool.getElement(contentElem, "title");
        XMLTool.removeChildNodes(title);
        XMLTool.createTextNode(doc, title, contentTitle);

        // content data
        contentdataElem = XMLTool.getElement(contentElem, "contentdata");
        XMLTool.removeChildNodes(contentdataElem, true);
    }

    buildContentTypeXML(userServices, contentdataElem, formItems, skipEmptyElements);

    return XMLTool.documentToString(doc);
}

From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java

private void removeAllChildren(Element element) {
    Node child = element.getFirstChild();

    while (child != null) {
        Node next = child.getNextSibling();
        element.removeChild(child);
        child = next;//from   w w w .j  a v a  2s .  c om
    }
}

From source file:org.gvnix.addon.jpa.addon.entitylistener.JpaOrmEntityListenerOperationsImpl.java

/**
 * Iterate over entityListenerElements to check if referred class exists on
 * project. Remove elements which missing class.
 * /* ww  w  .j  a va  2s  .  co  m*/
 * @param entityListenerElement
 * @param entityListenerElements
 * @return
 */
private boolean cleanUpMissingListeners(JavaType entity, Element entityListenerElement,
        List<Element> entityListenerElements) {
    boolean changed = false;

    String classOfListener;
    for (Element current : entityListenerElements) {
        classOfListener = current.getAttribute(CLASS_ATTRIBUTE);
        if (typeLocationService.getPhysicalTypeIdentifier(new JavaType(classOfListener)) == null) {
            // class not found
            entityListenerElement.removeChild(current);
            LOGGER.info(String.format("Removing missing entity-listenen '%s' of entity '%s' from orm.xml",
                    classOfListener, entity));
            changed = true;
        }
    }
    return changed;
}