Example usage for org.w3c.dom Element removeAttributeNS

List of usage examples for org.w3c.dom Element removeAttributeNS

Introduction

In this page you can find the example usage for org.w3c.dom Element removeAttributeNS.

Prototype

public void removeAttributeNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Removes an attribute by local name and namespace URI.

Usage

From source file:Main.java

private static void removeXmlBase(Element e) {
    e.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "base"); // NOI18N
    e.removeAttribute("xml:base"); // NOI18N
}

From source file:com.ryantenney.metrics.spring.config.RegisterMetricBeanDefinitionParser.java

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    final CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(),
            parserContext.extractSource(element));
    parserContext.pushContainingComponent(compDefinition);

    final String metricRegistryBeanName = element.getAttribute("metric-registry");
    if (!StringUtils.hasText(metricRegistryBeanName)) {
        throw new RuntimeException(); // TODO
    }//from  w ww  .j  a v a2s  .c o  m
    final RuntimeBeanReference metricRegistryBeanRef = new RuntimeBeanReference(metricRegistryBeanName);

    final List<Element> metricElements = DomUtils.getChildElementsByTagName(element,
            new String[] { "bean", "ref" });
    for (Element metricElement : metricElements) {
        // Get the name attribute and remove it (to prevent Spring from looking for a BeanDefinitionDecorator)
        final String name = metricElement.getAttributeNS(METRICS_NAMESPACE, "name");
        if (name != null) {
            metricElement.removeAttributeNS(METRICS_NAMESPACE, "name");
        }

        final Object metric = parserContext.getDelegate().parsePropertySubElement(metricElement, null);

        final RootBeanDefinition metricRegistererDef = new RootBeanDefinition(MetricRegisterer.class);
        metricRegistererDef.setSource(parserContext.extractSource(metricElement));
        metricRegistererDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        final ConstructorArgumentValues args = metricRegistererDef.getConstructorArgumentValues();
        args.addIndexedArgumentValue(0, metricRegistryBeanRef);
        args.addIndexedArgumentValue(1, name);
        args.addIndexedArgumentValue(2, metric);

        final String beanName = parserContext.getReaderContext().registerWithGeneratedName(metricRegistererDef);
        parserContext.registerComponent(new BeanComponentDefinition(metricRegistererDef, beanName));
    }

    parserContext.popAndRegisterContainingComponent();

    return null;
}

From source file:com.wfreitas.camelsoap.SoapClient.java

private void injectParameters(Element element, Map params, String soapNs) {
    NodeList children = element.getChildNodes();
    int childCount = children.getLength();

    for (int i = 0; i < childCount; i++) {
        Node node = children.item(i);

        if (childCount == 1 && node.getNodeType() == Node.TEXT_NODE) {
            if (node.getNodeValue().equals("?")) {
                String ognl = OGNLUtils.getOGNLExpression(element, soapNs);
                Object param;//  ww  w .  ja  va2  s .com

                param = OGNLUtils.getParameter(ognl, params);

                element.removeChild(node);
                element.appendChild(element.getOwnerDocument().createTextNode(param.toString()));
            }
        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
            injectParameters((Element) node, params, soapNs);
        }
    }

    element.removeAttributeNS(OGNLUtils.JBOSSESB_SOAP_NS, IS_CLONE_ATTRIB);
    element.removeAttributeNS(OGNLUtils.JBOSSESB_SOAP_NS, OGNLUtils.OGNL_ATTRIB);
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

public static void removePrototypeNodes(final Node instanceDocumentElement) {
    final Map<String, LinkedList<Element>> prototypes = new HashMap<String, LinkedList<Element>>();
    final NodeList children = instanceDocumentElement.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (!(children.item(i) instanceof Element)) {
            continue;
        }/*from   w  w  w.  j a  v  a 2 s  .  co m*/
        final String nodeName = children.item(i).getNodeName();
        if (!prototypes.containsKey(nodeName)) {
            prototypes.put(nodeName, new LinkedList<Element>());
        }
        prototypes.get(nodeName).add((Element) children.item(i));
    }

    for (LinkedList<Element> l : prototypes.values()) {
        for (Element e : l) {
            if (e.hasAttributeNS(NamespaceService.ALFRESCO_URI, "prototype")) {
                assert "true".equals(e.getAttributeNS(NamespaceService.ALFRESCO_URI, "prototype"));
                e.removeAttributeNS(NamespaceService.ALFRESCO_URI, "prototype");

                if (l.getLast().equals(e)) {
                    e.getParentNode().removeChild(e);
                }
            }
            if (e.getParentNode() != null) {
                Schema2XForms.removePrototypeNodes(e);
            }
        }
    }
}

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

protected String setXFormsId(final Element el, String id) {
    if (el.hasAttributeNS(null, "id")) {
        el.removeAttributeNS(null, "id");
    }/*from   w  w w . ja  va 2  s  . c o m*/
    if (id == null) {
        final String name = el.getLocalName();
        final Long l = this.counter.get(name);
        final long count = (l != null) ? l : 0;

        // increment the counter
        this.counter.put(name, new Long(count + 1));

        id = name + "_" + count;
    }
    el.setAttributeNS(null, "id", id);
    return id;
}

From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java

protected String setXFormsId(Element el) {
    //remove the eventuel "id" attribute
    if (el.hasAttributeNS(SchemaFormBuilder.XFORMS_NS, "id")) {
        el.removeAttributeNS(SchemaFormBuilder.XFORMS_NS, "id");
    }//w  ww.j a  va  2  s  . co m

    //long count=this.incIdCounter();
    long count = 0;
    String name = el.getLocalName();
    Long l = (Long) counter.get(name);

    if (l != null) {
        count = l.longValue();
    }

    String id = name + "_" + count;

    //increment the counter
    counter.put(name, new Long(count + 1));
    el.setAttributeNS(SchemaFormBuilder.XFORMS_NS, this.getXFormsNSPrefix() + "id", id);

    return id;
}

From source file:org.chiba.xml.xforms.ui.state.UIElementStateUtil.java

/**
 * Creates or updates the specified state attribute. If the value is
 * <code>null</code>, the attribute will be removed.
 *
 * @param element the element./*from  w  w  w  . j  a  va 2 s  .c o  m*/
 * @param name the attribute name.
 * @param value the attribute value.
 */
public static void setStateAttribute(Element element, String name, String value) {
    if (value != null) {
        element.setAttributeNS(NamespaceConstants.CHIBA_NS, NamespaceConstants.CHIBA_PREFIX + ":" + name,
                value);
    } else {
        element.removeAttributeNS(NamespaceConstants.CHIBA_NS, name);
    }
}

From source file:org.dita.dost.AbstractIntegrationTest.java

private Document parseXml(final File f) throws SAXException, IOException {
    final Document d = db.parse(f);
    final NodeList elems = d.getElementsByTagName("*");
    for (int i = 0; i < elems.getLength(); i++) {
        final Element e = (Element) elems.item(i);
        // remove debug attributes
        e.removeAttribute(ATTRIBUTE_NAME_XTRF);
        e.removeAttribute(ATTRIBUTE_NAME_XTRC);
        // remove DITA version and domains attributes
        e.removeAttributeNS(DITA_NAMESPACE, ATTRIBUTE_NAME_DITAARCHVERSION);
        e.removeAttribute(ATTRIBUTE_NAME_DOMAINS);
        // remove workdir processing instructions
        removeWorkdirProcessingInstruction(e);
    }//from  w w w.ja v a  2s .  com
    // rewrite IDs
    return rewriteIds(d, ditaIdPattern);
}

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

public static void setStringValue(Element elem, String value) {
    // remove jbpm:initialized
    elem.removeAttributeNS(BpelConstants.NS_VENDOR, BpelConstants.ATTR_INITIALIZED);

    Node firstChild = elem.getFirstChild();
    // if first child is a text node, reuse it
    if (firstChild instanceof org.w3c.dom.Text)
        firstChild.setNodeValue(value);//  w  w w.  j a v  a 2s.c o m
    // otherwise, just create a new text node
    else
        firstChild = elem.getOwnerDocument().createTextNode(value);

    // remove all children
    removeChildNodes(elem);
    // append text
    elem.appendChild(firstChild);
}