Java Code Examples for org.w3c.dom.Node.appendChild()

The following are Jave code examples for showing how to use appendChild() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: TrabalhoFinalEDA2   File: mxObjectCodec.java   Source Code and License Vote up 7 votes
/**
 * Writes the given value as an attribute of the given node.
 */
protected void writePrimitiveAttribute(mxCodec enc, Object obj,
		String attr, Object value, Node node)
{
	if (attr == null || obj instanceof Map)
	{
		Node child = enc.document.createElement("add");

		if (attr != null)
		{
			mxCodec.setAttribute(child, "as", attr);
		}

		mxCodec.setAttribute(child, "value", value);
		node.appendChild(child);
	}
	else
	{
		mxCodec.setAttribute(node, attr, value);
	}
}
 
Example 2
Project: openjdk-jdk10   File: DOMX509IssuerSerial.java   Source Code and License Vote up 6 votes
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);

    Element isElem = DOMUtils.createElement(ownerDoc, "X509IssuerSerial",
                                            XMLSignature.XMLNS, dsPrefix);
    Element inElem = DOMUtils.createElement(ownerDoc, "X509IssuerName",
                                            XMLSignature.XMLNS, dsPrefix);
    Element snElem = DOMUtils.createElement(ownerDoc, "X509SerialNumber",
                                            XMLSignature.XMLNS, dsPrefix);
    inElem.appendChild(ownerDoc.createTextNode(issuerName));
    snElem.appendChild(ownerDoc.createTextNode(serialNumber.toString()));
    isElem.appendChild(inElem);
    isElem.appendChild(snElem);
    parent.appendChild(isElem);
}
 
Example 3
Project: oscm   File: MigrationBillingResultGatheredEvents.java   Source Code and License Vote up 6 votes
protected String migrateBillingResultXml(String billingXml)
        throws ParserConfigurationException, SAXException, IOException,
        TransformerException, XPathExpressionException {
    Document document = XMLConverter.convertToDocument(billingXml, false);
    NodeList nodeList = XMLConverter.getNodeListByXPath(document,
            XPATH_GATHEREDEVENTS);
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node gatheredEvents = nodeList.item(i);
        if (!istotalEventCostsAlreadyPresent(gatheredEvents)
                && gatheredEvents.getChildNodes().getLength() > 0) {
            Element totalCosts = createNodeTotalEventCosts(gatheredEvents);
            gatheredEvents.appendChild(totalCosts);
        }
    }
    return XMLConverter.convertToString(document, false);
}
 
Example 4
Project: Equella   File: PropBagEx.java   Source Code and License Vote up 6 votes
/**
 * Appends the child nodes of another propbag into the node located by
 * szNodeName
 * 
 * @param szNodeName The path to insert into
 * @param xml The propbag that we want the children of
 */
public void appendChildren(final String szNodeName, final PropBagEx xml)
{
	checkNotAttribute(szNodeName);

	ensureRoot();
	xml.ensureRoot();
	Node oNode = getNodeHelper(szNodeName, false, false);
	if( oNode == null )
	{
		createNode(szNodeName, BLANK);
		oNode = getNodeHelper(szNodeName, false, false);
	}

	final Document doc = oNode.getOwnerDocument();
	Node child = xml.m_elRoot.getFirstChild();
	while( child != null )
	{
		oNode.appendChild(importNode(doc, child, true));
		child = child.getNextSibling();
	}

	// we might have pushed two text nodes together, normalise it
	oNode.normalize();
}
 
Example 5
Project: OpenJSharp   File: DOMKeyName.java   Source Code and License Vote up 5 votes
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);
    // prepend namespace prefix, if necessary
    Element knElem = DOMUtils.createElement(ownerDoc, "KeyName",
                                            XMLSignature.XMLNS, dsPrefix);
    knElem.appendChild(ownerDoc.createTextNode(name));
    parent.appendChild(knElem);
}
 
Example 6
Project: tomcat7   File: NodeCreateRule.java   Source Code and License Vote up 5 votes
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 7
Project: jdk8u-jdk   File: DOMX509Data.java   Source Code and License Vote up 5 votes
private void marshalSKI(byte[] skid, Node parent, Document doc,
                        String dsPrefix)
{
    Element skidElem = DOMUtils.createElement(doc, "X509SKI",
                                              XMLSignature.XMLNS, dsPrefix);
    skidElem.appendChild(doc.createTextNode(Base64.encode(skid)));
    parent.appendChild(skidElem);
}
 
Example 8
Project: jdk8u-jdk   File: DOMXMLSignature.java   Source Code and License Vote up 5 votes
public void marshal(Node parent, String dsPrefix,
                    DOMCryptoContext context)
    throws MarshalException
{
    // create SignatureValue element
    sigValueElem = DOMUtils.createElement(ownerDoc, "SignatureValue",
                                          XMLSignature.XMLNS, dsPrefix);
    if (valueBase64 != null) {
        sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64));
    }

    // append Id attribute, if specified
    DOMUtils.setAttributeID(sigValueElem, "Id", id);
    parent.appendChild(sigValueElem);
}
 
Example 9
Project: alvisnlp   File: XMLWriter2ForINIST.java   Source Code and License Vote up 5 votes
private void makeText(Node parent, int pos) {
    if (pos <= this.pos) {
        return;
    }
    Text text = document.createTextNode(contents.substring(this.pos, pos));
    parent.appendChild(text);
    this.pos = pos;
}
 
Example 10
Project: openjdk-jdk10   File: DOMX509Data.java   Source Code and License Vote up 5 votes
private void marshalCert(X509Certificate cert, Node parent, Document doc,
                         String dsPrefix)
    throws MarshalException
{
    Element certElem = DOMUtils.createElement(doc, "X509Certificate",
                                              XMLSignature.XMLNS, dsPrefix);
    try {
        certElem.appendChild(doc.createTextNode
                             (Base64.encode(cert.getEncoded())));
    } catch (CertificateEncodingException e) {
        throw new MarshalException("Error encoding X509Certificate", e);
    }
    parent.appendChild(certElem);
}
 
Example 11
Project: jdk8u-jdk   File: DOMRetrievalMethod.java   Source Code and License Vote up 5 votes
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
    throws MarshalException
{
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);
    Element rmElem = DOMUtils.createElement(ownerDoc, "RetrievalMethod",
                                            XMLSignature.XMLNS, dsPrefix);

    // add URI and Type attributes
    DOMUtils.setAttribute(rmElem, "URI", uri);
    DOMUtils.setAttribute(rmElem, "Type", type);

    // add Transforms elements
    if (!transforms.isEmpty()) {
        Element transformsElem = DOMUtils.createElement(ownerDoc,
                                                        "Transforms",
                                                        XMLSignature.XMLNS,
                                                        dsPrefix);
        rmElem.appendChild(transformsElem);
        for (Transform transform : transforms) {
            ((DOMTransform)transform).marshal(transformsElem,
                                               dsPrefix, context);
        }
    }

    parent.appendChild(rmElem);

    // save here node
    here = rmElem.getAttributeNodeNS(null, "URI");
}
 
Example 12
Project: openjdk-jdk10   File: DOMXMLSignature.java   Source Code and License Vote up 5 votes
public void marshal(Node parent, String dsPrefix,
                    DOMCryptoContext context)
    throws MarshalException
{
    // create SignatureValue element
    sigValueElem = DOMUtils.createElement(ownerDoc, "SignatureValue",
                                          XMLSignature.XMLNS, dsPrefix);
    if (valueBase64 != null) {
        sigValueElem.appendChild(ownerDoc.createTextNode(valueBase64));
    }

    // append Id attribute, if specified
    DOMUtils.setAttributeID(sigValueElem, "Id", id);
    parent.appendChild(sigValueElem);
}
 
Example 13
Project: jmt   File: XMLWriter.java   Source Code and License Vote up 5 votes
/**
 * Writes a Fork output section <br>
 * Author: Bertoli Marco
 *
 * @param doc
 *            document root
 * @param node
 *            node where created section should be appended
 * @param model
 *            data structure
 * @param stationKey
 *            search's key for fork
 */
private static void writeForkSection(Document doc, Node node,
		CommonModel model, Object stationKey) {
	Element fork = doc.createElement(XML_E_STATION_SECTION);
	fork.setAttribute(XML_A_STATION_SECTION_CLASSNAME, CLASSNAME_FORK);
	node.appendChild(fork);
	// Creates jobsPerLink parameter
	XMLParameter jobsPerLink = new XMLParameter("jobsPerLink", model
			.getStationNumberOfServers(stationKey).getClass().getName(),
			null, model.getStationNumberOfServers(stationKey).toString(),
			false);
	// Creates block parameter
	XMLParameter block = new XMLParameter("block", model
			.getForkBlock(stationKey).getClass().getName(), null, model
			.getForkBlock(stationKey).toString(), false);
	// ...and adds them as fork's children
	XMLParameter isSim = new XMLParameter("isSimplifiedFork", model
			.getIsSimplifiedFork(stationKey).getClass().getName(), null,
			model.getIsSimplifiedFork(stationKey).toString(), false);
	jobsPerLink.appendParameterElement(doc, fork);
	block.appendParameterElement(doc, fork);
	isSim.appendParameterElement(doc, fork);

	Vector<Object> classes = model.getClassKeys();
	XMLParameter[] forkStrats = new XMLParameter[classes.size()];
	Object currentClass;
	for (int i = 0; i < forkStrats.length; i++) {
		currentClass = classes.get(i);
		forkStrats[i] = ForkStrategyWriter
				.getForkStrategyParameter((ForkStrategy) model
						.getForkStrategy(stationKey, currentClass),
						model, currentClass, stationKey);
	}
	XMLParameter globalFork = new XMLParameter("ForkStrategy",
			strategiesClasspathBase + "ForkStrategy", null, forkStrats,
			false);
	globalFork.appendParameterElement(doc, fork);
}
 
Example 14
Project: lazycat   File: MbeansSource.java   Source Code and License Vote up 5 votes
@Override
public void updateField(ObjectName oname, String name, Object value) {
	if (loading)
		return;
	// nothing by default
	// log.info( "XXX UpdateField " + oname + " " + name + " " + value);
	Node n = object2Node.get(oname);
	if (n == null) {
		log.info("Node not found " + oname);
		return;
	}
	Node attNode = DomUtil.findChildWithAtt(n, "attribute", "name", name);
	if (attNode == null) {
		// found no existing attribute with this name
		attNode = n.getOwnerDocument().createElement("attribute");
		DomUtil.setAttribute(attNode, "name", name);
		n.appendChild(attNode);
	}
	String oldValue = DomUtil.getAttribute(attNode, "value");
	if (oldValue != null) {
		// we'll convert all values to text content
		DomUtil.removeAttribute(attNode, "value");
	}
	DomUtil.setText(attNode, value.toString());

	// store();
}
 
Example 15
Project: Tarski   File: Sax2Dom.java   Source Code and License Vote up 5 votes
/**
 * adds processing instruction node to DOM.
 */
public void processingInstruction(String target, String data) {
  final Node last = (Node) _nodeStk.peek();
  ProcessingInstruction pi = _document.createProcessingInstruction(target, data);
  if (pi != null)
    last.appendChild(pi);
}
 
Example 16
Project: openjdk-jdk10   File: PrettyPrintTest.java   Source Code and License Vote up 4 votes
private Document createDocWithSequentTextNodes() throws Exception {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = db.newDocument();
    Node root = doc.createElement("root");
    doc.appendChild(root);
    root.appendChild(doc.createTextNode("\n"));
    root.appendChild(doc.createTextNode("\n"));
    root.appendChild(doc.createTextNode("\n"));
    root.appendChild(doc.createTextNode(" "));
    root.appendChild(doc.createTextNode("t"));
    root.appendChild(doc.createTextNode("\n"));
    root.appendChild(doc.createTextNode("t"));
    root.appendChild(doc.createTextNode("   "));
    Node child1 = doc.createElement("child1");
    root.appendChild(child1);
    child1.appendChild(doc.createTextNode(" "));
    child1.appendChild(doc.createTextNode("\n"));
    root.appendChild(doc.createTextNode("t"));
    Node child2 = doc.createElement("child2");
    root.appendChild(child2);
    child2.appendChild(doc.createTextNode(" "));
    root.appendChild(doc.createTextNode(" "));
    Node child3 = doc.createElement("child3");
    root.appendChild(child3);
    child3.appendChild(doc.createTextNode(" "));
    root.appendChild(doc.createTextNode(" "));
    Node child4 = doc.createElement("child4");
    root.appendChild(child4);
    child4.appendChild(doc.createTextNode(" "));

    root.appendChild(doc.createTextNode(" "));
    Node child5 = doc.createElement("child5");
    root.appendChild(child5);
    child5.appendChild(doc.createTextNode("t"));

    Node child51 = doc.createElement("child51");
    child5.appendChild(child51);
    child51.appendChild(doc.createTextNode(" "));
    Node child511 = doc.createElement("child511");
    child51.appendChild(child511);
    child511.appendChild(doc.createTextNode("t"));
    child51.appendChild(doc.createTextNode(" "));
    child5.appendChild(doc.createTextNode("t"));

    root.appendChild(doc.createTextNode(" "));
    root.appendChild(doc.createComment(" test comment "));
    root.appendChild(doc.createTextNode(" \n"));
    root.appendChild(doc.createComment(" "));
    root.appendChild(doc.createTextNode("\n"));
    root.appendChild(doc.createProcessingInstruction("target1", "test"));
    root.appendChild(doc.createTextNode(" "));
    root.appendChild(doc.createTextNode(" "));
    return doc;
}
 
Example 17
Project: OpenJSharp   File: SAX2DOM.java   Source Code and License Vote up 4 votes
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;
    }
 
Example 18
Project: jmt   File: XMLWriter.java   Source Code and License Vote up 4 votes
static protected void writeStorageSection(Document doc, Node node,
		CommonModel model, Object stationKey) {
	// Storage Section
	Element elem = doc.createElement(XML_E_STATION_SECTION);
	elem.setAttribute(XML_A_STATION_SECTION_CLASSNAME, CLASSNAME_STORAGE);
	node.appendChild(elem);

	// Total Capacity
	Integer totalCap = model.getStationQueueCapacity(stationKey);
	XMLParameter totalCapacity = new XMLParameter("totalCapacity",
			Integer.class.getName(), null, totalCap.toString(), false);
	totalCapacity.appendParameterElement(doc, elem);

	// Capacities
	Vector<Object> classes = model.getClassKeys();
	XMLParameter[] capacity = new XMLParameter[classes.size()];
	for (int i = 0; i < capacity.length; i++) {
		Integer cap = model.getQueueCapacity(stationKey, classes.get(i));
		capacity[i] = new XMLParameter("capacity",
				Integer.class.getName(), model.getClassName(classes.get(i)),
				cap.toString(), true);
	}
	XMLParameter capacities = new XMLParameter("capacities",
			Integer.class.getName(), null, capacity, false);
	capacities.appendParameterElement(doc, elem);

	// Drop Rules
	XMLParameter[] dropRule = new XMLParameter[classes.size()];
	for (int i = 0; i < dropRule.length; i++) {
		String rule = model.getDropRule(stationKey, classes.get(i));
		dropRule[i] = new XMLParameter("dropRule",
				String.class.getName(), model.getClassName(classes.get(i)),
				DROP_RULES_MAPPING.get(rule), true);
	}
	XMLParameter dropRules = new XMLParameter("dropRules",
			String.class.getName(), null, dropRule, false);
	dropRules.appendParameterElement(doc, elem);

	// Get Strategy
	XMLParameter getStrategy = new XMLParameter("getStrategy",
			strategiesClasspathBase + queueGetStrategiesSuffix + "FCFSstrategy",
			null, (String) null, false);
	getStrategy.appendParameterElement(doc, elem);

	// Put Strategies
	XMLParameter[] putStrategy = new XMLParameter[classes.size()];
	for (int i = 0; i < putStrategy.length; i++) {
		String strategy = QUEUE_PUT_MAPPING.get(
				model.getQueueStrategy(stationKey, classes.get(i)));
		putStrategy[i] = new XMLParameter("putStrategy",
				strategiesClasspathBase + queuePutStrategiesSuffix + strategy,
				model.getClassName(classes.get(i)), (String) null, true);
	}
	XMLParameter putStrategies = new XMLParameter("putStrategies",
			strategiesClasspathBase + "QueuePutStrategy",
			null, putStrategy, false);
	putStrategies.appendParameterElement(doc, elem);
}
 
Example 19
Project: OpenJSharp   File: RangeImpl.java   Source Code and License Vote up 4 votes
public void surroundContents(Node newParent)
    throws DOMException, RangeException
{
    if (newParent==null) return;
    int type = newParent.getNodeType();

    if (fDocument.errorChecking) {
        if (fDetach) {
            throw new DOMException(
                    DOMException.INVALID_STATE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
        }
        if (type == Node.ATTRIBUTE_NODE
                || type == Node.ENTITY_NODE
                || type == Node.NOTATION_NODE
                || type == Node.DOCUMENT_TYPE_NODE
                || type == Node.DOCUMENT_NODE
                || type == Node.DOCUMENT_FRAGMENT_NODE)
        {
            throw new RangeExceptionImpl(
                    RangeException.INVALID_NODE_TYPE_ERR,
                    DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
        }
    }

    Node realStart = fStartContainer;
    Node realEnd = fEndContainer;
    if (fStartContainer.getNodeType() == Node.TEXT_NODE) {
        realStart = fStartContainer.getParentNode();
    }
    if (fEndContainer.getNodeType() == Node.TEXT_NODE) {
        realEnd = fEndContainer.getParentNode();
    }

    if (realStart != realEnd) {
            throw new RangeExceptionImpl(
            RangeException.BAD_BOUNDARYPOINTS_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "BAD_BOUNDARYPOINTS_ERR", null));
    }

    DocumentFragment frag = extractContents();
    insertNode(newParent);
    newParent.appendChild(frag);
    selectNode(newParent);
}
 
Example 20
Project: myfaces-trinidad   File: ReorderChildrenComponentChange.java   Source Code and License Vote up 4 votes
/**
 * {@inheritDoc}
 * In case children were to be removed between the time when this Change was
 *  added, and the time when it was applied, maybe due to application of a
 *  RemoveChildrenChange, such children are not re-instated.
 * In case children were to be added between the time when this Change was
 *  added, and the time when it was applied, maybe due to application of an 
 *  AddChildChange, such children are appended to the end of the list in
 *  preserving the order in which they were added (that is they appear at 
 *  the end).
 */
public void changeDocument(
  Node componentNode)
{
  // build order map of of current Nodes, keyed by id
  LinkedHashMap<String, Node> currChildrenMap = new LinkedHashMap<String, Node>(13);
      
  Node currChild = componentNode.getFirstChild();
  
  int fakeIndex = 0;
  while (currChild != null)
  {
    NamedNodeMap attributes = currChild.getAttributes();
            
    String currKey = null;
    if (attributes != null)
    {
      Node idAttr = attributes.getNamedItem(_identifier);
      
      if (idAttr != null)
      {
        currKey = idAttr.getNodeValue();
      }
    }
    
    // create a dummy key to maintain order of non-ided children
    if (currKey == null)
    {
      // =-= bts What about insignificant whitespace?
      currKey = Integer.valueOf(fakeIndex++).toString();
    }

    currChildrenMap.put(currKey, currChild);
    
    // remove the children so that we can add them back in
    componentNode.removeChild(currChild);
    
    // next node is first node again
    currChild = componentNode.getFirstChild();
  }

  //
  // put children back in, in order
  //
  for(String currReorderID : _childIds)
  {
    currChild = currChildrenMap.remove(currReorderID);
    if (currChild != null)
    {
      componentNode.appendChild(currChild);
    }
  }
  
  // add in all of the rest of the children in
  // relative order they originally appeared
  for(Map.Entry<String, Node> entry : currChildrenMap.entrySet())
  {
    componentNode.appendChild(entry.getValue());
  } 
}