Example usage for org.w3c.dom NamedNodeMap setNamedItem

List of usage examples for org.w3c.dom NamedNodeMap setNamedItem

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap setNamedItem.

Prototype

public Node setNamedItem(Node arg) throws DOMException;

Source Link

Document

Adds a node using its nodeName attribute.

Usage

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static void appendHeaderManagerCollectionProp(Document document, Node elementProp,
        Map<String, String> headersMap) {
    Node collectionProp = document.createElement("collectionProp");
    NamedNodeMap attributes = collectionProp.getAttributes();
    attributes.setNamedItem(createAttribute(document, "name", "HeaderManager.headers"));
    createHeaderElementProp(document, headersMap, collectionProp);
    elementProp.setTextContent(null);//from  ww  w  .jav a 2 s.c  o m
    elementProp.appendChild(collectionProp);
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static void appendElementProp(Document document, Node parentNode, String contextType,
        String contextPostData) { // eleme prop
    Node elementProp = document.createElement("elementProp");
    NamedNodeMap attributes = elementProp.getAttributes();

    attributes.setNamedItem(createAttribute(document, "name", "HTTPsampler.Arguments"));
    attributes.setNamedItem(createAttribute(document, "elementType", "Arguments"));
    attributes.setNamedItem(createAttribute(document, "guiclass", "HTTPArgumentsPanel"));
    attributes.setNamedItem(createAttribute(document, "testclass", "Arguments"));
    attributes.setNamedItem(createAttribute(document, "testname", "User Defined Variables"));
    attributes.setNamedItem(createAttribute(document, "enabled", "true"));
    appendCollectionProp(document, elementProp, contextType, contextPostData);

    //parentNode.setTextContent(null);
    parentNode.appendChild(elementProp);
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static Node appendJdbcSampler(Document document, Node hashTree, String name, String dataSource,
        String queryType, String query) {
    Node jdbcSampler = document.createElement("JDBCSampler");

    NamedNodeMap attributes = jdbcSampler.getAttributes();
    attributes.setNamedItem(createAttribute(document, "guiclass", "TestBeanGUI"));
    attributes.setNamedItem(createAttribute(document, "testclass", "JDBCSampler"));
    attributes.setNamedItem(createAttribute(document, "testname", name)); //url name
    attributes.setNamedItem(createAttribute(document, "enabled", "true"));

    appendTypeProp(document, jdbcSampler, "stringProp", "dataSource", dataSource);
    appendTypeProp(document, jdbcSampler, "stringProp", "queryType", queryType);
    appendTypeProp(document, jdbcSampler, "stringProp", "query", query);
    appendTypeProp(document, jdbcSampler, "stringProp", "queryArguments", null);
    appendTypeProp(document, jdbcSampler, "stringProp", "queryArgumentsTypes", null);
    appendTypeProp(document, jdbcSampler, "stringProp", "variableNames", null);
    appendTypeProp(document, jdbcSampler, "stringProp", "resultVariable", null);

    return jdbcSampler;
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static void appendCollectionProp(Document document, Node elementProp, String contextType,
        String contextPostData) { // collection append in prop
    String argumentValue = null;/*from w w w. j a  v  a2s.c o m*/
    if (contextType.equals(FrameworkConstants.POST)) {
        argumentValue = contextPostData;
    }
    Node collectionProp = document.createElement("collectionProp");
    NamedNodeMap attributes = collectionProp.getAttributes();
    attributes.setNamedItem(createAttribute(document, "name", "Arguments.arguments"));

    Node subElementProp = document.createElement("elementProp");
    NamedNodeMap subElementAttributes = subElementProp.getAttributes();
    subElementAttributes.setNamedItem(createAttribute(document, "name", ""));
    subElementAttributes.setNamedItem(createAttribute(document, "elementType", "HTTPArgument"));
    collectionProp.appendChild(subElementProp);
    appendTypeProp(document, subElementProp, "boolProp", "HTTPArgument.always_encode", "false");
    appendTypeProp(document, subElementProp, "stringProp", "Argument.value", argumentValue);
    appendTypeProp(document, subElementProp, "stringProp", "Argument.metadata", "=");
    appendTypeProp(document, subElementProp, "boolProp", "HTTPArgument.use_equals", "true");

    elementProp.setTextContent(null);
    elementProp.appendChild(collectionProp);
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static void createHeaderElementProp(Document document, Map<String, String> headersMap,
        Node collectionProp) {/*from  w  ww .j  av  a 2 s.  c o m*/
    for (Map.Entry<String, String> entry : headersMap.entrySet()) {
        Node subElementProp = document.createElement("elementProp");
        NamedNodeMap subElementAttributes = subElementProp.getAttributes();
        subElementAttributes.setNamedItem(createAttribute(document, "name", ""));
        subElementAttributes.setNamedItem(createAttribute(document, "elementType", "Header"));
        collectionProp.appendChild(subElementProp);
        appendTypeProp(document, subElementProp, "stringProp", "Header.name", entry.getKey());
        appendTypeProp(document, subElementProp, "stringProp", "Header.value", entry.getValue());
    }
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static Node appendHttpSamplerProxy(Document document, Node hashTree, String name, String context,
        String contextType, String contextPostData, String encodingType) {
    Node httpSamplerProxy = document.createElement("HTTPSamplerProxy");
    String contentEncoding = null;
    if (contextType.equals(FrameworkConstants.POST)) {
        contentEncoding = encodingType;/*from w ww . j a  v  a  2s  .  c  o m*/
    }

    NamedNodeMap attributes = httpSamplerProxy.getAttributes();
    attributes.setNamedItem(createAttribute(document, "guiclass", "HttpTestSampleGui"));
    attributes.setNamedItem(createAttribute(document, "testclass", "HTTPSamplerProxy"));
    attributes.setNamedItem(createAttribute(document, "testname", name)); //url name
    attributes.setNamedItem(createAttribute(document, "enabled", "true"));

    appendElementProp(document, httpSamplerProxy, contextType, contextPostData);

    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.domain", null);
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.port", null);
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.connect_timeout", null);
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.response_timeout", null);
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.protocol", null);
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.contentEncoding", contentEncoding);
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.path", context); // server url
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.method", contextType);

    appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.follow_redirects", "false");
    appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.auto_redirects", "true");
    appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.use_keepalive", "true");
    appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.DO_MULTIPART_POST", "false");

    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.implementation", "Java");
    appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.monitor", "false");
    appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.embedded_url_re", null);

    return httpSamplerProxy;
}

From source file:net.sourceforge.ajaxtags.tags.AjaxAnchorsTag.java

/**
 * Rewrite link. Change (or create) "onclick" attribute, set "href" attribute to
 * "javascript://nop/".//from   www.j  a  v  a2  s.  co m
 *
 * @param link
 *            node of document with link
 * @param target
 *            target of request
 */
protected final void rewriteLink(final Node link, final String target) {
    final NamedNodeMap map = link.getAttributes();
    final Attr href = (Attr) map.getNamedItem("href");
    if (href != null) {
        Attr onclick = (Attr) map.getNamedItem("onclick");
        if (onclick == null) {
            onclick = link.getOwnerDocument().createAttribute("onclick");
            map.setNamedItem(onclick);
        }
        onclick.setValue(getOnclickAjax(target, href.getValue(), getOptionsBuilder()));
        href.setValue("javascript://nop/");
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

private static void setQNameAttribute(Element element, Attr attr, QName attributeQnameValue,
        Element definitionElement) {
    String attributeStringValue;//from   w ww  .j  ava2 s  .c o  m

    if (attributeQnameValue == null) {
        attributeStringValue = "";
    } else if (XMLConstants.NULL_NS_URI.equals(attributeQnameValue.getNamespaceURI())) {
        if (QNameUtil.isPrefixUndeclared(attributeQnameValue.getPrefix())) {
            attributeStringValue = attributeQnameValue.getPrefix() + ":" + attributeQnameValue.getLocalPart(); // to give user a chance to see and fix this
        } else {
            attributeStringValue = attributeQnameValue.getLocalPart();
        }
    } else {
        String valuePrefix = lookupOrCreateNamespaceDeclaration(element, attributeQnameValue.getNamespaceURI(),
                attributeQnameValue.getPrefix(), definitionElement, false);
        assert StringUtils.isNotBlank(valuePrefix);
        attributeStringValue = valuePrefix + ":" + attributeQnameValue.getLocalPart();
    }

    NamedNodeMap attributes = element.getAttributes();
    checkValidXmlChars(attributeStringValue);
    attr.setValue(attributeStringValue);
    attributes.setNamedItem(attr);
}

From source file:com.amalto.core.history.UniqueIdTransformer.java

private void _addIds(org.w3c.dom.Document document, Element element, Stack<Integer> levels) {
    NamedNodeMap attributes = element.getAttributes();
    Attr id = document.createAttribute(ID_ATTRIBUTE_NAME);

    int thisElementId = levels.pop() + 1;
    StringBuilder builder;//w  w  w  .  ja v  a2s.c o m
    {
        builder = new StringBuilder();
        for (Integer level : levels) {
            builder.append(level);
        }
    }
    String prefix = builder.toString().isEmpty() ? StringUtils.EMPTY : builder.toString() + '-';
    id.setValue(prefix + element.getNodeName() + '-' + thisElementId);
    attributes.setNamedItem(id);

    levels.push(thisElementId);
    {
        levels.push(0);
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
                Element child = (Element) children.item(i);
                _addIds(document, child, levels);
            }
        }
        levels.pop();
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static void setNamespaceDeclaration(Element element, String prefix, String namespaceUri) {
    Document doc = element.getOwnerDocument();
    NamedNodeMap attributes = element.getAttributes();
    Attr attr;//from   w w  w  . ja  v  a  2s.com
    if (prefix == null || prefix.isEmpty()) {
        // default namespace
        attr = doc.createAttributeNS(W3C_XML_SCHEMA_XMLNS_URI, W3C_XML_SCHEMA_XMLNS_PREFIX);
    } else {
        attr = doc.createAttributeNS(W3C_XML_SCHEMA_XMLNS_URI, W3C_XML_SCHEMA_XMLNS_PREFIX + ":" + prefix);
    }
    checkValidXmlChars(namespaceUri);
    attr.setValue(namespaceUri);
    attributes.setNamedItem(attr);
}