Example usage for org.w3c.dom Element hasAttributeNS

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

Introduction

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

Prototype

public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.

Usage

From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java

/**
 * Tests instance URI assignment./* w w  w . j a va 2  s.  c  om*/
 *
 * @throws Exception in any error occurred during the test.
 */
public void testSetInstanceURI() throws Exception {
    this.processor.setXMLContainer(this.form);
    this.processor.setInstanceURI("instance-1", "test-uri");

    Element instance = (Element) this.processor.getXMLContainer()
            .getElementsByTagNameNS(NamespaceCtx.XFORMS_NS, "instance").item(1);

    assertTrue(instance.hasAttributeNS(NamespaceCtx.XFORMS_NS, "src"));
    assertTrue(instance.getAttributeNS(NamespaceCtx.XFORMS_NS, "src").equals("test-uri"));
}

From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java

/**
 * Tests default instance URI assignment.
 *
 * @throws Exception in any error occurred during the test.
 *///from w w  w  .j  av  a 2 s  .c  om
public void testSetInstanceURIDefault() throws Exception {
    this.processor.setXMLContainer(this.form);
    this.processor.setInstanceURI("", "test-uri");

    Element instance = (Element) this.processor.getXMLContainer()
            .getElementsByTagNameNS(NamespaceCtx.XFORMS_NS, "instance").item(0);

    assertTrue(instance.hasAttributeNS(NamespaceCtx.XFORMS_NS, "src"));
    assertTrue(instance.getAttributeNS(NamespaceCtx.XFORMS_NS, "src").equals("test-uri"));
}

From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java

/**
 * Tests submission URI assignment.// w w  w  . j  a  v  a  2s.  c om
 *
 * @throws Exception in any error occurred during the test.
 */
public void testSetSubmissionURI() throws Exception {
    this.processor.setXMLContainer(this.form);
    this.processor.setSubmissionURI("submission-1", "test-uri");

    Element submission = (Element) this.processor.getXMLContainer()
            .getElementsByTagNameNS(NamespaceCtx.XFORMS_NS, "submission").item(1);

    assertTrue(submission.hasAttributeNS(NamespaceCtx.XFORMS_NS, "action"));
    assertTrue(submission.getAttributeNS(NamespaceCtx.XFORMS_NS, "action").equals("test-uri"));
}

From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java

/**
 * Tests submission URI assignment./*from w w w. ja  v  a 2  s  .  c o  m*/
 *
 * @throws Exception in any error occurred during the test.
 */
public void testSetSubmissionURIDefault() throws Exception {
    this.processor.setXMLContainer(this.form);
    this.processor.setSubmissionURI("", "test-uri");

    Element submission = (Element) this.processor.getXMLContainer()
            .getElementsByTagNameNS(NamespaceCtx.XFORMS_NS, "submission").item(0);

    assertTrue(submission.hasAttributeNS(NamespaceCtx.XFORMS_NS, "action"));
    assertTrue(submission.getAttributeNS(NamespaceCtx.XFORMS_NS, "action").equals("test-uri"));
}

From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java

private static XSModel loadSchema(Element schema, Definition def) {
    // add namespaces from definition element
    Map definitionNameSpaces = def.getNamespaces();
    Set nameSpaces = definitionNameSpaces.entrySet();
    Iterator nameSpacesIterator = nameSpaces.iterator();

    while (nameSpacesIterator.hasNext()) {
        Entry nameSpaceEntry = (Entry) nameSpacesIterator.next();
        if (!"".equals((String) nameSpaceEntry.getKey())
                && !schema.hasAttributeNS("http://www.w3.org/2000/xmlns/", (String) nameSpaceEntry.getKey())) {
            Attr nameSpace = schema.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/",
                    "xmlns:" + nameSpaceEntry.getKey());
            nameSpace.setValue((String) nameSpaceEntry.getValue());
            schema.setAttributeNode(nameSpace);
        }//from  w w  w. j  a v a2s .c  om
    }

    LSInput schemaInput = new DOMInputImpl();
    schemaInput
            .setStringData("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + XmlUtils.getElementAsString(schema));
    log.info("Loading schema in types section of definition " + def.getDocumentBaseURI());
    schemaInput.setSystemId(def.getDocumentBaseURI());
    XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
    XSModel schemaModel = schemaLoader.load(schemaInput);
    log.info("Done loading");
    return schemaModel;
}

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

public static String generatePrefix(String base, Element contextElem) {
    // check possible collision with namespace declarations
    if (!contextElem.hasAttributeNS(BpelConstants.NS_XMLNS, base))
        return base;

    // collision detected, append a discriminator number
    StringBuffer prefixBuffer = new StringBuffer(base);

    for (int i = 1; i < Integer.MAX_VALUE; i++) {
        String prefix = prefixBuffer.append(i).toString();

        if (!contextElem.hasAttributeNS(BpelConstants.NS_XMLNS, prefix))
            return prefix;

        // remove appended number
        prefixBuffer.setLength(base.length());
    }/*  ww w  .j av a2  s  .c  o m*/

    throw new Error("could not generate prefix from base: " + base);
}

From source file:org.onehippo.cms7.autoexport.InitializeItem.java

private boolean containsFileReferenceValues(final Element element) {
    if (element.hasAttributeNS(DELTA_URI, FILE)) {
        return true;
    }//www. j a  v  a 2  s . c  o  m
    final NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        final Node item = childNodes.item(i);
        if (item instanceof Element) {
            if (containsFileReferenceValues((Element) item)) {
                return true;
            }
        }
    }
    return false;
}