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


Java Node.insertBefore方法代码示例

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


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

示例1: mergeChildNodes

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Merge child nodes
 * 
 * @param node     current node base
 * @param childNode child node if exist
 * @param foundBean child bean
 * @param currentChild current child node
 * @param patternChild current pattern child
 * @param nodeMap node map
 * @param document document
 * @param patternBean pattern bean
 * @param children list relevant childs current node base
 */
private static void mergeChildNodes(Node node, Node childNode, BaseBean foundBean,
        Node currentChild, Node patternChild, Map nodeMap, Document document,
        BaseBean patternBean, List children) {
    Node foundChild = childNode;
    if (foundChild == null) {
        foundChild = takeEqualNode(children, patternChild);
    }
    if (foundChild != null) {
        if (foundChild != currentChild) {
            node.removeChild(foundChild);
            node.insertBefore(foundChild, currentChild);
        }
        if (foundBean != null) {
            mergeBeans(nodeMap, foundBean, patternBean);
        } else if (isRelevantNode(foundChild) && foundChild.hasChildNodes()) {
            mergeNode(nodeMap, foundChild, patternChild);
        } else {
            foundChild.setNodeValue(patternChild.getNodeValue());
        }
    } else {
        Node child = document.importNode(patternChild, true);
        node.insertBefore(child, currentChild);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:Schema2BeansUtil.java

示例2: marshal

import org.w3c.dom.Node; //导入方法依赖的package包/类
private void marshal(Node parent, Element kiElem, Node nextSibling,
                     String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    // create and append KeyInfoType elements
    for (XMLStructure kiType : keyInfoTypes) {
        if (kiType instanceof DOMStructure) {
            ((DOMStructure)kiType).marshal(kiElem, dsPrefix, context);
        } else {
            DOMUtils.appendChild(kiElem,
                ((javax.xml.crypto.dom.DOMStructure)kiType).getNode());
        }
    }

    // append id attribute
    DOMUtils.setAttributeID(kiElem, "Id", id);

    parent.insertBefore(kiElem, nextSibling);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:DOMKeyInfo.java

示例3: splitText

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Break a text node into two sibling nodes. (Note that if the current node
 * has no parent, they won't wind up as "siblings" -- they'll both be
 * orphans.)
 *
 * @param offset
 *            The offset at which to split. If offset is at the end of the
 *            available data, the second node will be empty.
 *
 * @return A reference to the new node (containing data after the offset
 *         point). The original node will contain data up to that point.
 *
 * @throws DOMException(INDEX_SIZE_ERR)
 *             if offset is <0 or >length.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
 *             if node is read-only.
 */
public Text splitText(int offset)
    throws DOMException {

    if (isReadOnly()) {
        throw new DOMException(
        DOMException.NO_MODIFICATION_ALLOWED_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
    }

    if (needsSyncData()) {
        synchronizeData();
    }
    if (offset < 0 || offset > data.length() ) {
        throw new DOMException(DOMException.INDEX_SIZE_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
    }

    // split text into two separate nodes
    Text newText =
        getOwnerDocument().createTextNode(data.substring(offset));
    setNodeValue(data.substring(0, offset));

    // insert new text node
    Node parentNode = getParentNode();
    if (parentNode != null) {
        parentNode.insertBefore(newText, nextSibling);
    }

    return newText;

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:TextImpl.java

示例4: marshal

import org.w3c.dom.Node; //导入方法依赖的package包/类
public void marshal(Node parent, Node nextSibling, String dsPrefix,
                    DOMCryptoContext context)
    throws MarshalException
{
    ownerDoc = DOMUtils.getOwnerDocument(parent);
    sigElem = DOMUtils.createElement(ownerDoc, "Signature",
                                     XMLSignature.XMLNS, dsPrefix);

    // append xmlns attribute
    if (dsPrefix == null || dsPrefix.length() == 0) {
        sigElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns",
                               XMLSignature.XMLNS);
    } else {
        sigElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" +
                               dsPrefix, XMLSignature.XMLNS);
    }

    // create and append SignedInfo element
    ((DOMSignedInfo)si).marshal(sigElem, dsPrefix, context);

    // create and append SignatureValue element
    ((DOMSignatureValue)sv).marshal(sigElem, dsPrefix, context);

    // create and append KeyInfo element if necessary
    if (ki != null) {
        ((DOMKeyInfo)ki).marshal(sigElem, null, dsPrefix, context);
    }

    // create and append Object elements if necessary
    for (int i = 0, size = objects.size(); i < size; i++) {
        ((DOMXMLObject)objects.get(i)).marshal(sigElem, dsPrefix, context);
    }

    // append Id attribute
    DOMUtils.setAttributeID(sigElem, "Id", id);

    parent.insertBefore(sigElem, nextSibling);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:DOMXMLSignature.java

示例5: appendTextNode

import org.w3c.dom.Node; //导入方法依赖的package包/类
private void appendTextNode() {
    if (_textBuffer.length() > 0) {
        final Node last = (Node)_nodeStk.peek();
        if (last == _root && _nextSiblingCache != null) {
            _lastSibling = last.insertBefore(_document.createTextNode(_textBuffer.toString()), _nextSiblingCache);
        }
        else {
            _lastSibling = last.appendChild(_document.createTextNode(_textBuffer.toString()));
        }
        _textBuffer.setLength(0);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:SAX2DOM.java

示例6: processingInstruction

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * adds processing instruction node to DOM.
 */
public void processingInstruction(String target, String data) {
    appendTextNode();
    final Node last = (Node)_nodeStk.peek();
    ProcessingInstruction pi = _document.createProcessingInstruction(
            target, data);
    if (pi != null){
      if (last == _root && _nextSibling != null)
          last.insertBefore(pi, _nextSibling);
      else
          last.appendChild(pi);

      _lastSibling = pi;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:SAX2DOM.java

示例7: expandEntityRef

import org.w3c.dom.Node; //导入方法依赖的package包/类
protected final void expandEntityRef (Node parent, Node reference){
    Node kid, next;
    for (kid = reference.getFirstChild(); kid != null; kid = next) {
        next = kid.getNextSibling();
        parent.insertBefore(kid, reference);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:DOMNormalizer.java

示例8: insertOperationNodesBeforeOutSocket

import org.w3c.dom.Node; //导入方法依赖的package包/类
private void insertOperationNodesBeforeOutSocket(Document xmlDocument, Node parent, List<Node> nodes) {
	Node copiedNode;
	Node outSocket = getOutSocket(parent);
	for (int i = 0; i < nodes.size(); i++) {
		copiedNode = xmlDocument.importNode(nodes.get(i), true);
		parent.insertBefore(copiedNode, outSocket);
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:9,代码来源:ParseExternalElements.java

示例9: append

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Append a node to the current container.
 *
 * @param newNode New node to append
 */
protected void append(Node newNode) throws org.xml.sax.SAXException
{

  Node currentNode = m_currentNode;

  if (null != currentNode)
  {
    if (currentNode == m_root && m_nextSibling != null)
      currentNode.insertBefore(newNode, m_nextSibling);
    else
      currentNode.appendChild(newNode);

    // System.out.println(newNode.getNodeName());
  }
  else if (null != m_docFrag)
  {
    if (m_nextSibling != null)
      m_docFrag.insertBefore(newNode, m_nextSibling);
    else
      m_docFrag.appendChild(newNode);
  }
  else
  {
    boolean ok = true;
    short type = newNode.getNodeType();

    if (type == Node.TEXT_NODE)
    {
      String data = newNode.getNodeValue();

      if ((null != data) && (data.trim().length() > 0))
      {
        throw new org.xml.sax.SAXException(
          XMLMessages.createXMLMessage(
            XMLErrorResources.ER_CANT_OUTPUT_TEXT_BEFORE_DOC, null));  //"Warning: can't output text before document element!  Ignoring...");
      }

      ok = false;
    }
    else if (type == Node.ELEMENT_NODE)
    {
      if (m_doc.getDocumentElement() != null)
      {
        ok = false;

        throw new org.xml.sax.SAXException(
          XMLMessages.createXMLMessage(
            XMLErrorResources.ER_CANT_HAVE_MORE_THAN_ONE_ROOT, null));  //"Can't have more than one root on a DOM!");
      }
    }

    if (ok)
    {
      if (m_nextSibling != null)
        m_doc.insertBefore(newNode, m_nextSibling);
      else
        m_doc.appendChild(newNode);
    }
  }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:DOMBuilder.java

示例10: changeDocument

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Given the DOM Node representing a Component, apply any necessary
 * DOM changes.
 */
public void changeDocument(Node componentNode)
{
  if (componentNode == null)
    throw new IllegalArgumentException(_LOG.getMessage(
      "NO_NODE_SPECIFIED"));
  
  // get the fragement, imported into the target document
  DocumentFragment targetFragment = 
    getImportedComponentFragment(componentNode);
  
  // assume that we'll be appending
  Node insertBeforeNode = null;
  
  // search children for the _insertBefore id
  if (_insertBeforeId != null)
  {
    String insertBeforeID = _insertBeforeId;
    
    Node currChild = componentNode.getFirstChild();
    Node idAttr;
    
    while (currChild != null)
    {
      NamedNodeMap attributes = currChild.getAttributes();
      
      if (attributes != null)
      {
        idAttr = attributes.getNamedItem("id");
        if (idAttr != null && insertBeforeID.equals(idAttr.getNodeValue()))
        {
          insertBeforeNode = currChild;
          break;
        }
      }
      currChild = currChild.getNextSibling();
    }
  }    
  
  // insert our DocumentFragment in the correct position
  componentNode.insertBefore(targetFragment, insertBeforeNode);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:46,代码来源:AddChildDocumentChange.java

示例11: changeDocument

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Given the DOM Node representing a Component, apply any necessary
 * DOM changes. The node passed will be the Node that is a common parent for
 * the movable child and the destination container.
 * There is a limitation with the document change, that the movable child 
 * Node, destination container Node, and the common parent Node have to belong
 * to the same document.
 * @param changeTargetNode DOM Node that is a common parent for the movable
 * child and the destination container.
 * @throws IllegalArgumentException If changeTargeNode were to be null.
 */
public void changeDocument(Node changeTargetNode)
{
  if (changeTargetNode == null)
    throw new IllegalArgumentException(_LOG.getMessage("NO_NODE_SPECIFIED"));

  if ( !_moveCompDocPath.equals(_destinationContainerDocPath) ||
       !_moveCompDocPath.equals(_commonParentDocPath) )
  {
    // If all three participants are not in same doc, we cannot proceed with appling doc change.
    // Throw an exception so that ChangeManagers can handle this failure and do alternate
    //  processing (eg. add a component change given that doc change failed)
    throw new IllegalStateException(
      _LOG.getMessage("MOVE_PARTICIPANTS_NOT_IN_SAME_DOC", 
                      new Object[] {_moveCompDocPath,
                                    _destinationContainerDocPath,
                                    _commonParentDocPath}));
  }

  // Move involves four steps.
  // 1. Finding the child node, the source of move
  Node movableChildNode = 
    ChangeUtils.__findNodeByScopedId(changeTargetNode, 
                                     _moveCompScopedIdAtSource, 
                                     Integer.MAX_VALUE);
  
  if(movableChildNode == null)
  {
    _LOG.warning("MOVABLE_CHILD_NOT_FOUND", _moveCompScopedIdAtSource);
    return;
  }
  
  // 2. Finding the destination container node
  Node destinationContainerNode = 
    ChangeUtils.__findNodeByScopedId(changeTargetNode, 
                                     _destinationContainerScopedId, 
                                     Integer.MAX_VALUE);

  
  if(destinationContainerNode == null)
  {
    _LOG.warning("DESTINATION_CONTAINER_NOT_FOUND", _destinationContainerScopedId);
    return;
  }
  
  //3. Finding the neighbor at the destination
  Node insertBeforeNode = (_insertBeforeCompId == null) ? 
    null:ChangeUtils.__findNodeByScopedId(destinationContainerNode, 
                                          _insertBeforeCompId, 
                                          1);
  // insertBeforeId was specified, but corresponding component is missing.
  //  Abort the move.
  if(_insertBeforeCompId != null && insertBeforeNode == null)
  {
    _LOG.warning("INSERT_BEFORE_NOT_FOUND", _insertBeforeCompId);
    return;
  }

  //4. Atomically move the child.
  destinationContainerNode.insertBefore(movableChildNode, insertBeforeNode);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:72,代码来源:MoveChildComponentChange.java

示例12: SortChilds

import org.w3c.dom.Node; //导入方法依赖的package包/类
static public void SortChilds(Node parent, String childname) {
		Node a;                            // Pour parcourrir les elements de parent.
		Node b;                            // Pour parcourrir les elements de parent.
		Node min;                          // Pointe sur le node "minimum" (alphabetiquement).
		String btext;                            // La valeur de l'element b.
		String mintext;                          // La valeur de l'element min
		boolean replace;

//********************* Parcourre tous les elements de type childname ****************
		a=SelectSingleNode(parent,childname);
		if (a!=null) {
			do {
//..................... Pour chaque element ..........................................
				min=a;
				mintext=GetNodeText(min);

//.................. On cherche un element plus petit ................................
				b=SelectSingleNode(a,"following-sibling::"+childname+"[position()=1]");
				replace=false;

				if (b!=null) {
					do {
						btext = GetNodeText(b);
						if (btext.compareTo(mintext)<0) {
							min=b;
							mintext=GetNodeText(min);
							replace=true;
						}
						b=SelectSingleNode(b,"following-sibling::"+childname+"[position()=1]");
					} while (b!=null);
				}
        
//............. Si on a trouve un element plus petit, on remplace ....................
				if (replace) {
					parent.removeChild(min);
					parent.insertBefore(min,a);
					a = min;
				}
				a=SelectSingleNode(a,"following-sibling::"+childname+"[position()=1]");
			} while (a!=null);
		}
	}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:43,代码来源:XmlHelper.java

示例13: startElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
public void startElement(String namespace, String localName, String qName,
        Attributes attrs)
    {
        appendTextNode();
        if (needToSetDocumentInfo) {
            setDocumentInfo();
            needToSetDocumentInfo = false;
        }

        final Element tmp = (Element)_document.createElementNS(namespace, qName);

        // Add namespace declarations first
        if (_namespaceDecls != null) {
            final int nDecls = _namespaceDecls.size();
            for (int i = 0; i < nDecls; i++) {
                final String prefix = (String) _namespaceDecls.elementAt(i++);

                if (prefix == null || prefix.equals(EMPTYSTRING)) {
                    tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX,
                        (String) _namespaceDecls.elementAt(i));
                }
                else {
                    tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix,
                        (String) _namespaceDecls.elementAt(i));
                }
            }
            _namespaceDecls.clear();
        }

        // Add attributes to element
/*      final int nattrs = attrs.getLength();
        for (int i = 0; i < nattrs; i++) {
            if (attrs.getLocalName(i) == null) {
                tmp.setAttribute(attrs.getQName(i), attrs.getValue(i));
            }
            else {
                tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i),
                    attrs.getValue(i));
            }
        } */


        // Add attributes to element
        final int nattrs = attrs.getLength();
        for (int i = 0; i < nattrs; i++) {
            // checking if Namespace processing is being done
            String attQName = attrs.getQName(i);
            String attURI = attrs.getURI(i);
            if (attrs.getLocalName(i).equals("")) {
                tmp.setAttribute(attQName, attrs.getValue(i));
                if (attrs.getType(i).equals("ID")) {
                    tmp.setIdAttribute(attQName, true);
                }
            } else {
                tmp.setAttributeNS(attURI, attQName, attrs.getValue(i));
                if (attrs.getType(i).equals("ID")) {
                    tmp.setIdAttributeNS(attURI, attrs.getLocalName(i), true);
                }
            }
        }


        // Append this new node onto current stack node
        Node last = (Node)_nodeStk.peek();

        // If the SAX2DOM is created with a non-null next sibling node,
        // insert the result nodes before the next sibling under the root.
        if (last == _root && _nextSibling != null)
            last.insertBefore(tmp, _nextSibling);
        else
            last.appendChild(tmp);

        // Push this node onto stack
        _nodeStk.push(tmp);
        _lastSibling = null;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:77,代码来源:SAX2DOM.java

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