Example usage for org.w3c.dom Attr getValue

List of usage examples for org.w3c.dom Attr getValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getValue.

Prototype

public String getValue();

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:com.gargoylesoftware.htmlunit.html.BaseFrameElement.java

/**
 * {@inheritDoc}/*w ww  .j  ava 2s . c om*/
 */
@Override
public Attr setAttributeNode(final Attr attribute) {
    final String qualifiedName = attribute.getName();
    String attributeValue = null;
    if ("src".equals(qualifiedName)) {
        attributeValue = attribute.getValue().trim();
    }

    final Attr result = super.setAttributeNode(attribute);

    if ("src".equals(qualifiedName) && WebClient.ABOUT_BLANK != attributeValue) {
        if (isDirectlyAttachedToPage()) {
            loadSrc();
        } else {
            loadSrcWhenAddedToPage_ = true;
        }
    }

    return result;
}

From source file:com.apporiented.spring.override.GenericBeanDefinitionParser.java

/**
 * Parse the supplied {@link org.w3c.dom.Element} and populate the supplied
 * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} as required.
 * <p>This implementation maps any attributes present on the
 * supplied element to {@link org.springframework.beans.PropertyValue}
 * instances, and/*from   w  w  w  . j a  v  a  2s  .  co  m*/
 * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder#addPropertyValue(String, Object) adds them}
 * to the
 * {@link org.springframework.beans.factory.config.BeanDefinition builder}.
 * <p>The {@link #extractPropertyName(String)} method is used to
 * reconcile the name of an attribute with the name of a JavaBean
 * property.
 * @param element the XML element being parsed
 * @param parserContext the object encapsulating the current state of the parsing process
 * @param builder used to define the <code>BeanDefinition</code>
 * @see #extractPropertyName(String)
 */
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    NamedNodeMap attributes = element.getAttributes();
    for (int x = 0; x < attributes.getLength(); x++) {
        Attr attribute = (Attr) attributes.item(x);
        String name = attribute.getLocalName();
        if (isEligibleAttribute(name, parserContext)) {
            String propertyName = extractPropertyName(name);
            Assert.state(StringUtils.hasText(propertyName),
                    "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty.");

            Object value;
            if (references.contains(propertyName)) {
                value = new RuntimeBeanReference(attribute.getValue());
            } else {
                value = attribute.getValue();
            }
            builder.addPropertyValue(propertyName, value);
        }
    }
    postProcess(builder, parserContext, element);
}

From source file:uk.co.markfrimston.tasktree.TaskTree.java

protected boolean nodesEqual(Node a, Node b) {
    if ((a == null) != (b == null)) {
        return false;
    }//from   ww w . j a  v a  2  s  .co  m
    if (a != null) {
        if (a.getNodeType() != b.getNodeType()) {
            return false;
        }
        if ((a.getNodeName() == null) != (b.getNodeName() == null)) {
            return false;
        }
        if (a.getNodeName() != null && !a.getNodeName().equals(b.getNodeName())) {
            return false;
        }
        if ((a.getNodeValue() == null) != (b.getNodeValue() == null)) {
            return false;
        }
        if (a.getNodeValue() != null && !a.getNodeValue().equals(b.getNodeValue())) {
            return false;
        }
        NamedNodeMap attrsA = a.getAttributes();
        Map<String, String> attrMapA = new HashMap<String, String>();
        if (attrsA != null) {
            for (int i = 0; i < attrsA.getLength(); i++) {
                Attr att = (Attr) attrsA.item(i);
                attrMapA.put(att.getName(), att.getValue());
            }
        }
        NamedNodeMap attrsB = b.getAttributes();
        Map<String, String> attrMapB = new HashMap<String, String>();
        if (attrsB != null) {
            for (int i = 0; i < attrsB.getLength(); i++) {
                Attr att = (Attr) attrsB.item(i);
                attrMapB.put(att.getName(), att.getValue());
            }
        }
        if (!attrMapA.equals(attrMapB)) {
            return false;
        }

        Node childA = a.getFirstChild();
        Node childB = b.getFirstChild();
        while (childA != null) {
            if (!nodesEqual(childA, childB)) {
                return false;
            }
            childA = childA.getNextSibling();
            childB = childB.getNextSibling();
        }
        if (childB != null) {
            return false;
        }
    }
    return true;
}

From source file:com.github.lindenb.jvarkit.tools.ensembl.VcfEnsemblVepRest.java

@Override
protected Collection<Throwable> doVcfToVcf(final String inputName, final VcfIterator vcfIn,
        final VariantContextWriter out) throws IOException {
    final java.util.Base64.Encoder base64Encoder = java.util.Base64.getEncoder();
    final SequenceOntologyTree soTree = SequenceOntologyTree.getInstance();
    VCFHeader header = vcfIn.getHeader();
    List<VariantContext> buffer = new ArrayList<>(this.batchSize + 1);
    VCFHeader h2 = new VCFHeader(header);
    addMetaData(h2);/*w ww. j a va 2s . c om*/

    if (!xmlBase64) {
        h2.addMetaDataLine(new VCFInfoHeaderLine(TAG, VCFHeaderLineCount.UNBOUNDED, VCFHeaderLineType.String,
                "VEP Transcript Consequences. Format :(biotype|cdnaStart|cdnaEnd|cdsStart|cdsEnd|geneId|geneSymbol|geneSymbolSource|hgnc|strand|transcript|variantAllele|so_acns)"));
    } else {
        h2.addMetaDataLine(
                new VCFInfoHeaderLine(TAG, 1, VCFHeaderLineType.String, "VEP xml answer encoded as base 64"));
    }

    out.writeHeader(h2);
    SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header);
    for (;;) {
        VariantContext ctx = null;
        if (vcfIn.hasNext()) {
            buffer.add((ctx = progress.watch(vcfIn.next())));
        }
        if (ctx == null || buffer.size() >= this.batchSize) {
            if (!buffer.isEmpty()) {
                if (!xmlBase64) {
                    Opt opt = vep(buffer);
                    for (VariantContext ctx2 : buffer) {
                        VariantContextBuilder vcb = new VariantContextBuilder(ctx2);
                        final String inputStr = createInputContext(ctx2);
                        Data mydata = null;
                        for (Data data : opt.getData()) {
                            if (!inputStr.equals(data.getInput()))
                                continue;
                            mydata = data;
                            break;
                        }
                        if (mydata == null) {
                            LOG.info("No Annotation found for " + inputStr);
                            out.add(ctx2);
                            continue;
                        }
                        List<String> infoList = new ArrayList<>();
                        List<TranscriptConsequences> csql = mydata.getTranscriptConsequences();
                        for (int i = 0; i < csql.size(); ++i) {
                            TranscriptConsequences csq = csql.get(i);
                            StringBuilder sb = new StringBuilder();
                            sb.append(empty(csq.getBiotype())).append("|").append(empty(csq.getCdnaStart()))
                                    .append("|").append(empty(csq.getCdnaEnd())).append("|")
                                    .append(empty(csq.getCdsStart())).append("|").append(empty(csq.getCdsEnd()))
                                    .append("|").append(empty(csq.getGeneId())).append("|")
                                    .append(empty(csq.getGeneSymbol())).append("|")
                                    .append(empty(csq.getGeneSymbolSource())).append("|")
                                    .append(empty(csq.getHgncId())).append("|").append(empty(csq.getStrand()))
                                    .append("|").append(empty(csq.getTranscriptId())).append("|")
                                    .append(empty(csq.getVariantAllele())).append("|");
                            List<String> terms = csq.getConsequenceTerms();
                            for (int j = 0; j < terms.size(); ++j) {
                                if (j > 0)
                                    sb.append("&");
                                SequenceOntologyTree.Term term = soTree.getTermByLabel(terms.get(j));
                                if (term == null) {
                                    sb.append(terms.get(j));
                                    LOG.warn("No SO:Term found for " + terms.get(j));
                                } else {
                                    sb.append(term.getAcn());
                                }
                            }
                            infoList.add(sb.toString());
                        }
                        if (!infoList.isEmpty()) {
                            vcb.attribute(TAG, infoList);
                        }

                        out.add(vcb.make());
                    }
                } //end of not(XML base 64)
                else {
                    Document opt = vepxml(buffer);
                    Element root = opt.getDocumentElement();
                    if (!root.getNodeName().equals("opt"))
                        throw new IOException("Bad root node " + root.getNodeName());

                    for (VariantContext ctx2 : buffer) {
                        String inputStr = createInputContext(ctx2);
                        Document newdom = null;

                        //loop over <data/>
                        for (Node dataNode = root.getFirstChild(); dataNode != null; dataNode = dataNode
                                .getNextSibling()) {
                            if (dataNode.getNodeType() != Node.ELEMENT_NODE)
                                continue;
                            Attr att = Element.class.cast(dataNode).getAttributeNode("input");
                            if (att == null) {
                                LOG.warn("no @input in <data/>");
                                continue;
                            }

                            if (!att.getValue().equals(inputStr))
                                continue;
                            if (newdom == null) {
                                newdom = this.documentBuilder.newDocument();
                                newdom.appendChild(newdom.createElement("opt"));
                            }
                            newdom.getDocumentElement().appendChild(newdom.importNode(dataNode, true));
                        }
                        if (newdom == null) {
                            LOG.warn("No Annotation found for " + inputStr);
                            out.add(ctx2);
                            continue;
                        }
                        StringWriter sw = new StringWriter();
                        try {
                            this.xmlSerializer.transform(new DOMSource(newdom), new StreamResult(sw));
                        } catch (TransformerException err) {
                            throw new IOException(err);
                        }
                        VariantContextBuilder vcb = new VariantContextBuilder(ctx2);
                        vcb.attribute(TAG, base64Encoder.encodeToString(sw.toString().getBytes())
                                .replaceAll("[\\s=]", ""));
                        out.add(vcb.make());
                    }
                } //end of XML base 64
            }
            if (ctx == null)
                break;
            buffer.clear();
        }
        if (out.checkError())
            break;
    }
    progress.finish();
    return RETURN_OK;
}

From source file:org.adl.samplerte.server.LMSManifestHandler.java

License:asdf

/****************************************************************************
 ** //from  w w w . j  ava  2  s . c  o  m
 ** Method: getAttribute() Input: Node theNode - The current node that was
 * traversed to String the Attribute - The name of the attribute that the
 * value is desired for. Output: Description: This method
 ** 
 ** Side Effects: none
 ** 
 ***************************************************************************/
protected String getAttribute(Node theNode, String theAttribute) {
    String returnValue = new String();

    // grab attributes of the node
    Attr attrs[] = sortAttributes(theNode.getAttributes());

    // now see if the asked for attribute exists and send
    // back the value
    Attr attribute;
    for (int i = 0; i < attrs.length; i++) {
        attribute = attrs[i];

        if (attribute.getName().equals(theAttribute)) {
            returnValue = attribute.getValue();
            break;
        }
    }

    return returnValue;
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test//w ww. j av a  2 s . c o m
public void testAddChildElementWithUndeclaredNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement child = element.addChildElement("test", "p", "urn:ns");
    assertEquals("urn:ns", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("test", child.getLocalName());
    Attr nsDecl = child.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p");
    assertNotNull(nsDecl);
    assertEquals("urn:ns", nsDecl.getValue());
}

From source file:com.marklogic.dom.ElementImpl.java

protected Node cloneNode(Document doc, boolean deep) {
    Element elem = doc.createElementNS(getNamespaceURI(), getTagName());
    elem.setPrefix(getPrefix());// ww  w . j a v  a  2s  . com

    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (attr instanceof AttrImpl) {
            elem.setAttributeNode((Attr) ((AttrImpl) attr).cloneNode(doc, deep));
        } else {
            // ns decl, stored as Java DOM Attr
            // uri of xmlns is "http://www.w3.org/2000/xmlns/"
            Attr clonedAttr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", attr.getName());
            clonedAttr.setValue(attr.getValue());
            elem.setAttributeNode(clonedAttr);
        }
    }

    if (deep) {
        // clone children
        NodeList list = getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            NodeImpl n = (NodeImpl) list.item(i);
            Node c = n.cloneNode(doc, true);
            elem.appendChild(c);
        }
    }
    return elem;
}

From source file:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java

private void attribute(Writer writer, Attr attr) throws IOException {
    writeText(writer, attr.getName());//from  ww w . j  ava2s .  c  o m
    writer.write("=\"");
    //writeEscapedText(writer, attr.getValue(), true);
    writer.write(StringEscapeUtils.escapeXml(attr.getValue()));
    writer.write("\"");
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test//ww  w .j ava2 s  .  c  o  m
public void testAddAttributeFromQNameWithNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement retValue = element.addAttribute(new QName("urn:ns", "attr", "p"), "value");
    assertSame(element, retValue);
    Attr attr = element.getAttributeNodeNS("urn:ns", "attr");
    assertEquals("urn:ns", attr.getNamespaceURI());
    assertEquals("attr", attr.getLocalName());
    assertEquals("p", attr.getPrefix());
    assertEquals("value", attr.getValue());
    Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p");
    assertNotNull(nsDecl);
    assertEquals("urn:ns", nsDecl.getValue());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test// w w w. j  ava  2  s . c o m
public void testAddAttributeFromNameWithNamespace() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement(new QName("urn:test", "test"));
    SOAPElement retValue = element.addAttribute(envelope.createName("attr", "p", "urn:ns"), "value");
    assertSame(element, retValue);
    Attr attr = element.getAttributeNodeNS("urn:ns", "attr");
    assertEquals("urn:ns", attr.getNamespaceURI());
    assertEquals("attr", attr.getLocalName());
    assertEquals("p", attr.getPrefix());
    assertEquals("value", attr.getValue());
    Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p");
    assertNotNull(nsDecl);
    assertEquals("urn:ns", nsDecl.getValue());
}