Java 8 Attr - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Attr class.

This code example shows how to use the following methods:getValue
 
	@Override 
	public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
		if (node instanceof Attr) {
			Attr attr = (Attr) node;
			String propertyName = parserContext.getDelegate().getLocalName(attr);
			String propertyValue = attr.getValue();
			MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
			if (pvs.contains(propertyName)) {
				parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
						"both <property> and inline syntax. Only one approach may be used per property.", attr);
			} 
			if (propertyName.endsWith(REF_SUFFIX)) {
				propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
				pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
			} 
			else { 
				pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
			} 
		} 
8
CodeRank
This code example shows how to use the following methods:getName, getNamespaceURI, getNodeName, getNodeValue, getPrefix
        assertEquals("documentcreateattributeNS02_att1_prefix", "xml", prefix);
        assertEquals("documentcreateattributeNS02_att1_namespaceURI", 
                "http://www.w3.org/XML/1998/namespace", namespaceURI);
        attribute2 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/",
                "xmlns"); 
        name = attribute2.getName();
        nodeName = attribute2.getNodeName();
        nodeValue = attribute2.getNodeValue();
        prefix = attribute2.getPrefix();
        namespaceURI = attribute2.getNamespaceURI();
        assertEquals("documentcreateattributeNS02_att2_name", "xmlns", name);
        assertEquals("documentcreateattributeNS02_att2_nodeName", "xmlns", 
                nodeName);
        assertEquals("documentcreateattributeNS02_att2_nodeValue", "", 
                nodeValue);
        assertEquals("documentcreateattributeNS02_att2_namespaceURI", 
                "http://www.w3.org/2000/xmlns/", namespaceURI);
    } 
    public void testCreateAttributeNS3() throws Throwable { 
        Document doc;
8
CodeRank
This code example shows how to use the following methods:getName, getNamespaceURI
 
	/** 
	 * Returns <code>true</code> if given attribute is openable. 
	 */ 
	public boolean isLinkableAttr(Attr attr) {
		String attrName = attr.getName();
		if ("http://www.springframework.org/schema/p".equals(attr.getNamespaceURI())
				&& attrName.endsWith("-ref")) {
			return true; 
		} 
		if ("http://www.springframework.org/schema/c".equals(attr.getNamespaceURI())
				&& attrName.endsWith("-ref")) {
			return true; 
		} 
		return super.isLinkableAttr(attr);
	} 
 
	@Override 
	public void init() { 
		ClassHyperlinkCalculator javaElement = new ClassHyperlinkCalculator();
7
CodeRank
This code example shows how to use the following methods:getValue
  } 
 
  public static String getXmlAttrString(Element element, String name) {
    Attr at = element.getAttributeNode(name);
    if (at != null) {
      return at.getValue();
    } 
    return null; 
  } 
 
  public static void checkStringMatch(String print, String expected, String got) {
    assertTrue( 
        print + " doesn't match, got: " + got + " expected: " + expected,
        got.matches(expected));
  } 
 
  public static void checkStringContains(String print, String expected, String got) {
    assertTrue( 
        print + " doesn't contain expected string, got: " + got + " expected: " + expected,
        got.contains(expected));
7
CodeRank
This code example shows how to use the following methods:setNodeValue
		DOMResult domResult = new DOMResult(result);
		marshaller.marshal(flights, domResult);
		Document expected = builder.newDocument();
		Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
		Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
		namespace.setNodeValue("http://samples.springframework.org/flight");
		flightsElement.setAttributeNode(namespace);
		expected.appendChild(flightsElement);
		Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
		flightsElement.appendChild(flightElement);
		Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
		flightElement.appendChild(numberElement);
		Text text = expected.createTextNode("42");
		numberElement.appendChild(text);
		assertXMLEqual("Marshaller writes invalid DOMResult", expected, result);
	} 
 
	@Test
	public void marshalEmptyDOMResult() throws Exception {
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
7
CodeRank
This code example shows how to use the following methods:getName, getLocalName, getNamespaceURI, getNodeName, getNodeValue
        attribute2 = doc.createAttributeNS("http://www.w3.org/DOM/Level1",
                "att"); 
        element.setAttributeNodeNS(attribute2);
        attribute = element.getAttributeNodeNS("http://www.w3.org/DOM/Level2",
                "att"); 
        attrValue = attribute.getNodeValue();
        attrName = attribute.getName();
        attNodeName = attribute.getNodeName();
        attrLocalName = attribute.getLocalName();
        attrNS = attribute.getNamespaceURI();
        assertEquals("elementgetattributenodens01_attrValue", "", attrValue);
        assertEquals("elementgetattributenodens01_attrName", "l2:att", attrName);
        assertEquals("elementgetattributenodens01_attrNodeName", "l2:att", 
                attNodeName);
        assertEquals("elementgetattributenodens01_attrLocalName", "att", 
                attrLocalName);
        assertEquals("elementgetattributenodens01_attrNs", 
                "http://www.w3.org/DOM/Level2", attrNS);
    } 
    public void testGetAttributeNodeNS2() throws Throwable {
7
CodeRank
This code example shows how to use the following methods:getName
	 * @see #isEligibleAttribute(String) 
	 */ 
	protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
		boolean eligible = isEligibleAttribute(attribute);
		if (!eligible) {
			String fullName = attribute.getName();
			eligible = (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") &&
					isEligibleAttribute(parserContext.getDelegate().getLocalName(attribute)));
		} 
		return eligible;
	} 
 
	/** 
	 * Determine whether the given attribute is eligible for being 
	 * turned into a corresponding bean property value. 
	 * <p>The default implementation considers any attribute as eligible, 
	 * except for the "id" attribute and namespace declaration attributes. 
	 * @param attribute the XML attribute to check 
	 * @see #isEligibleAttribute(String) 
	 * @deprecated in favour of {@link #isEligibleAttribute(org.w3c.dom.Attr, ParserContext)} 
7
CodeRank
This code example shows how to use the following methods:getName, getNamespaceURI, getNodeName, getNodeValue, getPrefix
        assertEquals("documentcreateattributeNS02_att1_prefix", "xml", prefix);
        assertEquals("documentcreateattributeNS02_att1_namespaceURI", 
                "http://www.w3.org/XML/1998/namespace", namespaceURI);
        attribute2 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/",
                "xmlns"); 
        name = attribute2.getName();
        nodeName = attribute2.getNodeName();
        nodeValue = attribute2.getNodeValue();
        prefix = attribute2.getPrefix();
        namespaceURI = attribute2.getNamespaceURI();
        assertEquals("documentcreateattributeNS02_att2_name", "xmlns", name);
        assertEquals("documentcreateattributeNS02_att2_nodeName", "xmlns", 
                nodeName);
        assertEquals("documentcreateattributeNS02_att2_nodeValue", "", 
                nodeValue);
        assertEquals("documentcreateattributeNS02_att2_namespaceURI", 
                "http://www.w3.org/2000/xmlns/", namespaceURI);
    } 
    public void testCreateAttributeNS3() throws Throwable {
        Document doc;
6
CodeRank
This code example shows how to use the following methods:getName, getValue, getLocalName, getNamespaceURI, getPrefix
        Element element = (Element)doc.getDocumentElement().getFirstChild();
        assertTrue(element.hasAttributes());
        NamedNodeMap attributes = element.getAttributes();
        assertEquals(1, attributes.getLength());
        Attr attr = (Attr)attributes.item(0);
        assertEquals("xmlns", attr.getName());
        assertNull(attr.getPrefix());
        assertEquals("xmlns", attr.getLocalName());
        assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr.getNamespaceURI());
        assertEquals("", attr.getValue());
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getOwnerElement, getValue, getLocalName, getNamespaceURI, getPrefix
    /** {@inheritDoc} */ 
    protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
        SignatureConfirmation sc = (SignatureConfirmation) xmlObject;
         
        QName attrName =
            XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute.getPrefix());
        if (SignatureConfirmation.WSU_ID_ATTR_NAME.equals(attrName)) {
            sc.setWSUId(attribute.getValue());
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        } else if (SignatureConfirmation.VALUE_ATTRIB_NAME.equals(attribute.getLocalName())) {
            sc.setValue(attribute.getValue());
        } else { 
            super.processAttribute(xmlObject, attribute);
        } 
    } 
 
} 
6
CodeRank

Related Java 8 Attr Questions & Answers:

See Code Examples for Java 8 Attr Methods: