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.apache.shindig.gadgets.templates.tags.FlashTagHandler.java

public void process(Node result, Element tag, TemplateProcessor processor) {
    SwfObjectConfig config;//from  w  w w .  j a v a  2 s. c o m
    try {
        config = getSwfConfig(tag, processor);
    } catch (RuntimeException re) {
        // Record the processing error into the output
        Element err = result.getOwnerDocument().createElement("span");
        err.setTextContent("Failed to process os:Flash tag: " + StringEscapeUtils.escapeHtml(re.getMessage()));
        result.appendChild(err);
        return;
    }

    // Bind the security token to the flashvars if its available
    String st = processor.getTemplateContext().getGadget().getContext().getParameter("st");
    if (!StringUtils.isEmpty(st)) {
        String stVar = "st=" + Utf8UrlCoder.encode(st);
        if (StringUtils.isEmpty(config.flashvars)) {
            config.flashvars = stVar;
        } else {
            config.flashvars += '&' + stVar;
        }
    }

    // Restrict the content if sanitization is enabled
    if (processor.getTemplateContext().getGadget().sanitizeOutput()) {
        config.allowscriptaccess = SwfObjectConfig.ScriptAccess.never;
        config.swliveconnect = false;
        config.allownetworking = SwfObjectConfig.NetworkAccess.internal;
        // TODO - Implement container control over autoplay on views
    }

    // Create a div wrapper around the provided alternate content
    Element altHolder = result.getOwnerDocument().createElement("div");
    String altContentId = ALT_CONTENT_PREFIX + idGenerator.incrementAndGet();
    altHolder.setAttribute("id", altContentId);
    result.appendChild(altHolder);

    // Add the alternate content to the holder
    NodeList alternateContent = tag.getChildNodes();
    if (alternateContent.getLength() > 0) {
        processor.processChildNodes(altHolder, tag);
    }

    // Create the call to swfobject
    String swfObjectCall = buildSwfObjectCall(config, altContentId);
    Element script = result.getOwnerDocument().createElement("script");
    script.setAttribute("type", "text/javascript");
    result.appendChild(script);

    if (config.play == SwfObjectConfig.Play.immediate) {
        // Call swfobject immediately
        script.setTextContent(swfObjectCall);
    } else {
        // Add onclick handler to trigger call to swfobject
        script.setTextContent("function " + altContentId + "(){ " + swfObjectCall + " }");
        altHolder.setAttribute("onclick", altContentId + "()");
    }

    // Bypass sanitization for the holder tag and the call to swfobject
    SanitizingGadgetRewriter.bypassSanitization(altHolder, false);
    SanitizingGadgetRewriter.bypassSanitization(script, false);
    ensureSwfobject(result.getOwnerDocument(), processor);
}

From source file:org.apache.ws.security.message.TestMessageTransformer.java

public static Element duplicateEncryptedDataInWsseHeader(Element saaj, boolean moveReferenceList) {
    if (moveReferenceList) {
        moveReferenceList(saaj);//  w ww .ja  v  a  2 s .  c  o  m
    }
    Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"),
            true);
    Element encData = getFirstChildElement(body,
            new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), true);
    Element newEncData = createNewEncryptedData(encData);
    Element sh = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header"),
            true);
    Element wsseHeader = getFirstChildElement(sh,
            new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                    "Security"),
            true);

    Node newWsseHeader = wsseHeader.cloneNode(false);
    Node cur = wsseHeader.getFirstChild();

    String newId = newEncData.getAttributeNS(null, "Id");
    while (cur != null) {
        cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId);
    }
    newWsseHeader.appendChild(newEncData);

    if (!moveReferenceList) {
        updateEncryptedKeyRefList(newWsseHeader, newId);
    }

    Node parent = wsseHeader.getParentNode();
    parent.removeChild(wsseHeader);
    parent.appendChild(newWsseHeader);
    print(saaj.getOwnerDocument());
    return newEncData;
}

From source file:org.apache.ws.security.message.TestMessageTransformer.java

public static Element duplicateEncryptedDataInWsseWrapperHeader(Element saaj, boolean moveReferenceList) {
    if (moveReferenceList) {
        moveReferenceList(saaj);/*www .j  a va 2  s .co m*/
    }
    Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"),
            true);
    Element encData = getFirstChildElement(body,
            new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), true);
    Element newEncData = createNewEncryptedData(encData);
    Element sh = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header"),
            true);
    Element signature = getFirstChildElement(sh, new QName("http://www.w3.org/2000/09/xmldsig#", "Signature"),
            true);

    Node wsseHeader = signature.getParentNode();
    Node newWsseHeader = wsseHeader.cloneNode(false);
    Node cur = wsseHeader.getFirstChild();
    String newId = newEncData.getAttributeNS(null, "Id");
    while (!cur.isSameNode(signature)) {
        cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId);
    }
    Element wrapper = encData.getOwnerDocument().createElementNS(null, "a");
    wrapper.appendChild(newEncData);
    newWsseHeader.appendChild(wrapper);
    while (cur != null) {
        cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId);
    }

    if (!moveReferenceList) {
        updateEncryptedKeyRefList(newWsseHeader, newId);
    }

    Node parent = wsseHeader.getParentNode();
    parent.removeChild(wsseHeader);
    parent.appendChild(newWsseHeader);
    print(saaj.getOwnerDocument());
    return newEncData;
}

From source file:org.apache.ws.security.message.TestMessageTransformer.java

public static Element addEncryptedDataWithEmbeddedEncryptedKeyInWsseHeader(Element saaj) {
    moveReferenceList(saaj);//from  w w w . ja  v a 2 s .c  o  m
    Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"),
            true);
    Element encData = getFirstChildElement(body,
            new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), true);

    Element newEncData = (Element) encData.cloneNode(true);
    String newId = newEncData.getAttributeNS(null, "Id") + "b";
    newEncData.setAttributeNS(null, "Id", newId);

    Element encKey = getFirstChildElement(saaj, new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedKey"),
            true);
    Element newEncKey = (Element) encKey.cloneNode(true);
    String newEcId = newEncKey.getAttributeNS(null, "Id") + "b";
    newEncKey.setAttributeNS(null, "Id", newEcId);

    Element keyInfo = getFirstChildElement(newEncData,
            new QName("http://www.w3.org/2000/09/xmldsig#", "KeyInfo"), true);
    Element str = getFirstChildElement(newEncData,
            new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                    "SecurityTokenReference"),
            true);
    keyInfo.replaceChild(newEncKey, str);

    Element wsseHeader = getFirstChildElement(saaj,
            new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                    "Security"),
            true);

    Node newWsseHeader = wsseHeader.cloneNode(false);
    Node cur = wsseHeader.getFirstChild();

    while (cur != null) {
        cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId);
    }
    newWsseHeader.appendChild(newEncData);

    Node parent = wsseHeader.getParentNode();
    parent.removeChild(wsseHeader);
    parent.appendChild(newWsseHeader);
    print(saaj.getOwnerDocument());
    return newEncData;

}

From source file:org.apache.ws.security.message.TestMessageTransformer.java

private static void moveReferenceList(Element saaj) {
    Element sh = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header"),
            true);// w  w w.jav  a 2s .  c  o  m
    Element encKey = getFirstChildElement(sh, new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedKey"),
            true);
    Element refList = getFirstChildElement(encKey,
            new QName("http://www.w3.org/2001/04/xmlenc#", "ReferenceList"), true);

    Node wsseHeader = encKey.getParentNode();
    encKey.removeChild(refList);
    wsseHeader.appendChild(refList);
}

From source file:org.apache.ws.security.message.TestMessageTransformer.java

private static Node copyHeadersAndUpdateRefList(Node cur, Node dest, String newId) {
    Node temp = cur.cloneNode(true);
    dest.appendChild(temp);
    if (newId != null && temp.getNodeType() == Node.ELEMENT_NODE) {
        Element t = (Element) temp;
        if (t.getLocalName().equals("ReferenceList")) {
            Element ref = getFirstChildElement(t,
                    new QName("http://www.w3.org/2001/04/xmlenc#", "DataReference"), true);
            Element newRef = (Element) ref.cloneNode(true);
            newRef.setAttributeNS(null, "URI", "#" + newId);
            t.appendChild(newRef);/*w  w w. j a  v a2  s  .  c o m*/
        }
    }
    return cur.getNextSibling();
}

From source file:org.apereo.portal.layout.dlm.DeleteManager.java

/**
   Get the delete set if any stored in the root of the document or create
   it is passed in create flag is true.//from  ww w  .  j  a  va 2  s . c o  m
*/
private static Element getDeleteSet(Document plf, IPerson person, boolean create) throws PortalException {
    Node root = plf.getDocumentElement();
    Node child = root.getFirstChild();

    while (child != null) {
        if (child.getNodeName().equals(Constants.ELM_DELETE_SET))
            return (Element) child;
        child = child.getNextSibling();
    }

    if (create == false)
        return null;

    String ID = null;

    try {
        ID = getDLS().getNextStructDirectiveId(person);
    } catch (Exception e) {
        throw new PortalException("Exception encountered while " + "generating new delete set node "
                + "Id for userId=" + person.getID(), e);
    }
    Element delSet = plf.createElement(Constants.ELM_DELETE_SET);
    delSet.setAttribute(Constants.ATT_TYPE, Constants.ELM_DELETE_SET);
    delSet.setAttribute(Constants.ATT_ID, ID);
    root.appendChild(delSet);
    return delSet;
}

From source file:org.apereo.portal.layout.dlm.ParameterEditManager.java

/**
 * Get the parameter edits set if any stored in the root of the document or
 * create it if passed-in create flag is true.
 *///from  w  w w .j  a va  2  s.  co  m
private static Element getParmEditSet(Document plf, IPerson person, boolean create) throws PortalException {
    Node root = plf.getDocumentElement();
    Node child = root.getFirstChild();

    while (child != null) {
        if (child.getNodeName().equals(Constants.ELM_PARM_SET))
            return (Element) child;
        child = child.getNextSibling();
    }

    if (create == false)
        return null;

    String ID = null;

    try {
        ID = getDLS().getNextStructDirectiveId(person);
    } catch (Exception e) {
        throw new PortalException("Exception encountered while " + "generating new parameter edit set node "
                + "Id for userId=" + person.getID(), e);
    }
    Element parmSet = plf.createElement(Constants.ELM_PARM_SET);
    parmSet.setAttribute(Constants.ATT_TYPE, Constants.ELM_PARM_SET);
    parmSet.setAttribute(Constants.ATT_ID, ID);
    parmSet.setIdAttribute(Constants.ATT_ID, true);
    root.appendChild(parmSet);
    return parmSet;
}

From source file:org.asqatasun.crawler.util.HeritrixRegexpParameterValueModifier.java

private void addRegexpAsParameter(String regexp, Node node, Document document, String url) {
    if (StringUtils.isBlank(regexp)) {
        return;//from www .j av  a  2  s  .  c  om
    }
    String builtRegexp;
    builtRegexp = buildRegexp(regexp, url);
    Logger.getLogger(HeritrixParameterValueModifier.class.getName()).debug(" builtRegexp " + builtRegexp);
    if (StringUtils.isNotBlank(builtRegexp) && compileRegexp(regexp)) {
        Element element = document.createElement(getElementName());
        element.appendChild(document.createTextNode(builtRegexp));
        node.appendChild(element);
    }
}

From source file:org.automagic.deps.doctor.editor.PomWriterImpl.java

private void writeDependency(String parent, TransitiveDependency dependency, int indent, boolean full) {

    Optional<Node> node = Utils.getNode(parent + "/dependencies", document);

    Node dependenciesNode;/*  w ww.  j a v  a  2s. c  o m*/
    if (node.isPresent()) {
        dependenciesNode = node.get();
    } else {
        Node parentNode = Utils.getNode(parent, document).get();
        dependenciesNode = document.createElement("dependencies");
        addDummyComment(dependenciesNode);
        addIndentedNode(parentNode, dependenciesNode, indent - 1);
        dependenciesNode = Utils.getNode(parent + "/dependencies", document).get();
        clearDummyComment(dependenciesNode);
    }

    Artifact artifact = dependency.getArtifact();
    String groupId = trim(artifact.getGroupId());
    String artifactId = trim(artifact.getArtifactId());
    String type = trim(artifact.getType());
    String classifier = trim(artifact.getClassifier());
    String version = dependency.getVersion().toString();

    Node dependencyNode = document.createElement("dependency");

    if (addComments) {
        String comment = getCommentText(dependency);
        dependencyNode.appendChild(document.createComment(comment));
    }

    Node groupIdNode = document.createElement("groupId");
    groupIdNode.setTextContent(groupId);
    dependencyNode.appendChild(groupIdNode);

    Node artifactIdNode = document.createElement("artifactId");
    artifactIdNode.setTextContent(artifactId);
    dependencyNode.appendChild(artifactIdNode);

    if (StringUtils.isNotBlank(type) && !"jar".equals(type)) {
        Node typeNode = document.createElement("type");
        typeNode.setTextContent(type);
        dependencyNode.appendChild(typeNode);
    }
    if (StringUtils.isNotBlank(classifier)) {
        Node classifierNode = document.createElement("classifier");
        classifierNode.setTextContent(classifier);
        dependencyNode.appendChild(classifierNode);
    }

    if (full) {
        Node versionNode = document.createElement("version");
        versionNode.setTextContent(version);
        dependencyNode.appendChild(versionNode);
    }

    addIndentedNode(dependenciesNode, dependencyNode, indent);
}