当前位置: 首页>>代码示例>>Java>>正文


Java Node.replaceChild方法代码示例

本文整理汇总了Java中org.w3c.dom.Node.replaceChild方法的典型用法代码示例。如果您正苦于以下问题:Java Node.replaceChild方法的具体用法?Java Node.replaceChild怎么用?Java Node.replaceChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Node的用法示例。


在下文中一共展示了Node.replaceChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processSecurityElem

import org.w3c.dom.Node; //导入方法依赖的package包/类
private void processSecurityElem(Document docDom, Node parent) {
    NodeList childNodes = parent.getChildNodes();
    int len = childNodes.getLength();
    for (int i = 0; i < len; i++) {
        Node node = childNodes.item(i);
        if (node != null && node.getNodeType() == Node.COMMENT_NODE) { // node might be null (don't know why)
            if (node.getNodeValue().equals(DEFAULT_JNLP_SECURITY)) {
                String securityProp = getProperty("jnlp.signed", null); //NOI18N // property in project.properties
                if (securityProp != null && securityProp.equalsIgnoreCase("true")) { //NOI18N
                    parent.replaceChild(createSecurityElement(docDom), node);
                } else {
                    parent.removeChild(node);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:GenerateJnlpFileTask.java

示例2: encryptElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Encrypts an <code>Element</code> and replaces it with its encrypted
 * counterpart in the context <code>Document</code>, that is, the
 * <code>Document</code> specified when one calls
 * {@link #getInstance(String) getInstance}.
 *
 * @param element the <code>Element</code> to encrypt.
 * @return the context <code>Document</code> with the encrypted
 *   <code>Element</code> having replaced the source <code>Element</code>.
 *  @throws Exception
 */
private Document encryptElement(Element element) throws Exception{
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Encrypting element...");
    }
    if (null == element) {
        log.log(java.util.logging.Level.SEVERE, "Element unexpectedly null...");
    }
    if (cipherMode != ENCRYPT_MODE && log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "XMLCipher unexpectedly not in ENCRYPT_MODE...");
    }

    if (algorithm == null) {
        throw new XMLEncryptionException("XMLCipher instance without transformation specified");
    }
    encryptData(contextDocument, element, false);

    Element encryptedElement = factory.toElement(ed);

    Node sourceParent = element.getParentNode();
    sourceParent.replaceChild(encryptedElement, element);

    return contextDocument;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:XMLCipher.java

示例3: replaceElementWithSOAPElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
protected static SOAPElement replaceElementWithSOAPElement(
    Element element,
    ElementImpl copy) {

    Iterator eachAttribute = getAllAttributesFrom(element);
    while (eachAttribute.hasNext()) {
        Name name = (Name) eachAttribute.next();
        copy.addAttributeBare(name, getAttributeValueFrom(element, name));
    }

    Iterator eachChild = getChildElementsFrom(element);
    while (eachChild.hasNext()) {
        Node nextChild = (Node) eachChild.next();
        copy.insertBefore(nextChild, null);
    }

    Node parent = element.getParentNode();
    if (parent != null) {
        parent.replaceChild(copy, element);
    } // XXX else throw an exception?

    return copy;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ElementImpl.java

示例4: replaceElementWithSOAPElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
protected SOAPElement replaceElementWithSOAPElement(
    Element element,
    ElementImpl copy) {

    Iterator<Name> eachAttribute = getAllAttributesFrom(element);
    while (eachAttribute.hasNext()) {
        Name name = eachAttribute.next();
        copy.addAttributeBare(name, getAttributeValueFrom(element, name));
    }

    Iterator<Node> eachChild = getChildElementsFromDOM(element);
    while (eachChild.hasNext()) {
        Node nextChild = eachChild.next();
        copy.insertBefore(nextChild, null);
    }

    Node parent = soapDocument.find(element.getParentNode());
    if (parent != null) {
        parent.replaceChild(copy, element);
    } // XXX else throw an exception?

    return copy;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ElementImpl.java

示例5: setByPath

import org.w3c.dom.Node; //导入方法依赖的package包/类
public static void setByPath(Document doc, String path, Node in) {
    if (in.getNodeType() == Node.DOCUMENT_NODE) {
        in = in.getFirstChild();
    }
    Node node = getNodeByPath(doc, path, true);
    if (node == null) {
        throw new RuntimeException("no results for xpath: " + path);
    }
    Node newNode = doc.importNode(in, true);
    if (node.hasChildNodes() && node.getFirstChild().getNodeType() == Node.TEXT_NODE) {
        node.replaceChild(newNode, node.getFirstChild());
    } else {
        node.appendChild(newNode);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:16,代码来源:XmlUtils.java

示例6: decryptElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Decrypts <code>EncryptedData</code> in a single-part operation.
 *
 * @param element the <code>EncryptedData</code> to decrypt.
 * @return the <code>Node</code> as a result of the decrypt operation.
 * @throws XMLEncryptionException
 */
private Document decryptElement(Element element) throws XMLEncryptionException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Decrypting element...");
    }

    if (cipherMode != DECRYPT_MODE) {
        log.log(java.util.logging.Level.SEVERE, "XMLCipher unexpectedly not in DECRYPT_MODE...");
    }

    byte[] octets = decryptToByteArray(element);

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Decrypted octets:\n" + new String(octets));
    }

    Node sourceParent = element.getParentNode();
    Node decryptedNode = serializer.deserialize(octets, sourceParent);

    // The de-serialiser returns a node whose children we need to take on.
    if (sourceParent != null && Node.DOCUMENT_NODE == sourceParent.getNodeType()) {
        // If this is a content decryption, this may have problems
        contextDocument.removeChild(contextDocument.getDocumentElement());
        contextDocument.appendChild(decryptedNode);
    } else if (sourceParent != null) {
        sourceParent.replaceChild(decryptedNode, element);
    }

    return contextDocument;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:XMLCipher.java

示例7: convertToSoapText

import org.w3c.dom.Node; //导入方法依赖的package包/类
protected TextImpl convertToSoapText(CharacterData characterData) {
        final Node soapNode = getSoapDocument().findIfPresent(characterData);
        if (soapNode instanceof TextImpl) {
            return (TextImpl) soapNode;
        } else {
            TextImpl t = null;
            switch (characterData.getNodeType()) {
                case CDATA_SECTION_NODE:
                    t = new CDATAImpl(getSoapDocument(), characterData.getData());
                    break;
                case COMMENT_NODE:
                    t = new SOAPCommentImpl(getSoapDocument(), characterData.getData());
                    break;
                case TEXT_NODE:
                    t = new SOAPTextImpl(getSoapDocument(), characterData.getData());
                    break;
            }
            Node parent = getSoapDocument().find(characterData.getParentNode());
            if (parent != null) {
                parent.replaceChild(t, characterData);
            } // XXX else throw an exception?

            return t;

//            return replaceElementWithSOAPElement(
//                element,
//                (ElementImpl) createElement(NameImpl.copyElementName(element)));
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:ElementImpl.java

示例8: removeNoOpsFromOp

import org.w3c.dom.Node; //导入方法依赖的package包/类
private static void removeNoOpsFromOp(Node root, Node op)
{
	if (!op.getNodeName().equals("op"))
		return;
	NamedNodeMap attr = op.getAttributes();
	String operation =  attr.getNamedItem("name").getTextContent();
	if (operation.equals("NO_OP"))
	{
		root.removeChild(op);
	}
	else if (operation.equals(";"))
	{
		NodeList children = op.getChildNodes();

		if (children.item(0).getNodeName().equals("op"))
			removeNoOpsFromOp(op,children.item(0));
		else if (children.item(0).getNodeName().equals("value"))
			op.removeChild(children.item(0));

		if (children.item(1) == null)
		{
			if (children.item(0).getNodeName().equals("op"))
				removeNoOpsFromOp(op,children.item(0));
			else if (children.item(0).getNodeName().equals("value"))
				op.removeChild(children.item(0));
		}
		else
		{
			if (children.item(1).getNodeName().equals("op"))
				removeNoOpsFromOp(op,children.item(1));
			else if (children.item(1).getNodeName().equals("value"))
				op.removeChild(children.item(1));
		}

		if (op.getChildNodes().getLength() == 1)
			root.replaceChild(op.getFirstChild(), op);
		else if (op.getChildNodes().getLength() == 0)
			root.removeChild(op);
	}
	else if (operation.equals("FUN"))
	{
		removeNoOpsFromOp(op,op.getChildNodes().item(1));
	}
}
 
开发者ID:Christopher-Chianelli,项目名称:ccpa,代码行数:45,代码来源:TreeOptimizer.java

示例9: moveFunctionCallsInNode

import org.w3c.dom.Node; //导入方法依赖的package包/类
public static void moveFunctionCallsInNode(Node node)
{
	if (!node.getNodeName().equals("op"))
		return;

	NamedNodeMap attr = node.getAttributes();
	String operation = attr.getNamedItem("name").getTextContent();
	NodeList children = node.getChildNodes();

	for (int i = 0; i < children.getLength(); i++)
	{
		moveFunctionCallsInNode(children.item(i));
	}

	if (operation.equals("CALL"))
	{
		Node parent = node.getParentNode();
		Node temp = node;

		if (parent != null && parent.getAttributes().getNamedItem("name") != null){
			String parentOp = node.getParentNode().getAttributes().getNamedItem("name").getTextContent();
		while (!parentOp.equals(";") && !parentOp.equals("while") && !parentOp.equals("doWhile") &&  !parentOp.equals("for") && !parentOp.equals("if") && !parentOp.equals("if/else") && !parentOp.equals("ASSIGN"))
		{
			temp = parent;
			parent = temp.getParentNode();
			if (parent == null || parent.getAttributes().getNamedItem("name") == null)
				return;
			parentOp = parent.getAttributes().getNamedItem("name").getTextContent();
		}

		if (node.getParentNode() != parent)
		{
			Element assignOp = doc.createElement("op");
			Element joinOps = doc.createElement("op");
			Element funName = doc.createElement("value");
			Element funType = doc.createElement("value");
			Element usesVar = doc.createElement("uses");

			String type;
			String name = getUniqueName();

			type =  attr.getNamedItem("type").getTextContent();

			funName.setTextContent(name);
			funType.setTextContent(type);

			usesVar.appendChild(funType.cloneNode(true));
			usesVar.appendChild(funName.cloneNode(true));

			assignOp.setAttribute("name", "ASSIGN");
			assignOp.setAttribute("type", type);
			assignOp.appendChild(node.cloneNode(true));
			assignOp.appendChild(funName.cloneNode(true));

			node.getParentNode().replaceChild(funName.cloneNode(true), node);

			joinOps.setAttribute("name", ";");
			joinOps.setAttribute("type", "");
			joinOps.appendChild(temp.cloneNode(true));
			joinOps.appendChild(assignOp.cloneNode(true));

			parent.replaceChild(joinOps.cloneNode(true), temp);
			parent.appendChild(usesVar);
		}
		}
	}
}
 
开发者ID:Christopher-Chianelli,项目名称:ccpa,代码行数:68,代码来源:TreeTransformer.java

示例10: updateNode

import org.w3c.dom.Node; //导入方法依赖的package包/类
private void updateNode(SOAPMessageContext context, List<FieldInfo> fields,
        String variableName, boolean isResponse) throws SOAPException {

    Node variableNode;
    if (isResponse) {
        variableNode = context.getMessage().getSOAPBody().getFirstChild()
                .getFirstChild();
    } else {
        variableNode = context.getMessage().getSOAPBody()
                .getElementsByTagName(variableName).item(0);
    }

    NodeList fieldsList = variableNode.getChildNodes();
    int fieldsSize = fieldsList.getLength();

    for (int i = 0; i < fieldsSize; i++) {
        Node fieldNode = fieldsList.item(i);
        for (FieldInfo field : fields) {
            String oldNodeName = "";
            String updatedNodeName = "";
            if (isResponse) {
                oldNodeName = PREFIX
                        + field.getNewField().getVariableName();
                updatedNodeName = PREFIX
                        + field.getOldField().getVariableName();
            } else {
                oldNodeName = PREFIX
                        + field.getOldField().getVariableName();
                updatedNodeName = PREFIX
                        + field.getNewField().getVariableName();

            }
            if (fieldNode.getNodeName().equals(oldNodeName)) {
                Element newNode = variableNode
                        .getOwnerDocument()
                        .createElementNS(
                                variableNode.getFirstChild()
                                        .getNamespaceURI(), updatedNodeName);
                newNode.setTextContent(fieldNode.getTextContent());
                variableNode.replaceChild(newNode, fieldNode);
            }
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:45,代码来源:UpdateFieldAdapter.java

示例11: addNewNode

import org.w3c.dom.Node; //导入方法依赖的package包/类
/*****
 * Adds a new node or replaces an existing node in the Document
 * 
 * @param doc Target document where the node will added
 * @param xmlEntity contains definition of the xml entity
 * @throws IOException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws XPathExpressionException
 */
public static void addNewNode(final Document doc, final XmlEntity xmlEntity)
    throws IOException, XPathExpressionException, SAXException, ParserConfigurationException {
  // Build up map per call to avoid issues with caching wrong version of the map.
  final LinkedHashMap<String, CacheElement> elementOrderMap = CacheElement.buildElementMap(doc);

  final Node newNode = createNode(doc, xmlEntity.getXmlDefinition());
  final Node root = doc.getDocumentElement();
  final int incomingElementOrder =
      getElementOrder(elementOrderMap, xmlEntity.getNamespace(), xmlEntity.getType());

  boolean nodeAdded = false;
  NodeList nodes = root.getChildNodes();
  final int length = nodes.getLength();
  for (int i = 0; i < length; i++) {
    final Node node = nodes.item(i);

    if (node instanceof Element) {
      final Element childElement = (Element) node;
      final String type = childElement.getLocalName();
      final String namespace = childElement.getNamespaceURI();

      if (namespace.equals(xmlEntity.getNamespace()) && type.equals(xmlEntity.getType())) {
        // TODO this should really be checking all attributes in xmlEntity.getAttributes
        // First check if the element has a name
        String nameOrId = getAttribute(childElement, "name");
        // If not then check if the element has an Id
        if (nameOrId == null) {
          nameOrId = getAttribute(childElement, "id");
        }

        if (nameOrId != null) {
          // If there is a match , then replace the existing node with the incoming node
          if (nameOrId.equals(xmlEntity.getNameOrId())) {
            root.replaceChild(newNode, node);
            nodeAdded = true;
            break;
          }
        } else {
          // This element does not have any name or id identifier for e.g PDX and gateway-receiver
          // If there is only one element of that type then replace it with the incoming node
          if (!isMultiple(elementOrderMap, namespace, type)) {
            root.replaceChild(newNode, node);
            nodeAdded = true;
            break;
          }
        }
      } else {
        if (incomingElementOrder < getElementOrder(elementOrderMap, namespace, type)) {
          root.insertBefore(newNode, node);
          nodeAdded = true;
          break;
        }
      }
    }
  }
  if (!nodeAdded) {
    root.appendChild(newNode);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:70,代码来源:XmlUtils.java


注:本文中的org.w3c.dom.Node.replaceChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。