Example usage for org.w3c.dom Element getAttributes

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

Introduction

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

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil.java

/**
 * Copy the attribues on one element to the other
 *//* w  w  w.ja v a2 s . c om*/
public static void copyAttributes(Element from, Element to) {
    // lets copy across all the remainingattributes
    NamedNodeMap attributes = from.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr node = (Attr) attributes.item(i);
        to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue());
    }
}

From source file:org.apache.shindig.gadgets.spec.ModulePrefs.java

public ModulePrefs(Element element, Uri base) throws SpecParserException {
    this.base = base;
    attributes = Maps.newHashMap();/*from  www  .j  a va 2  s.c o m*/
    NamedNodeMap attributeNodes = element.getAttributes();
    for (int i = 0; i < attributeNodes.getLength(); i++) {
        Node node = attributeNodes.item(i);
        attributes.put(node.getNodeName(), node.getNodeValue());
    }

    categories = ImmutableList.of(getAttribute(ATTR_CATEGORY, ""), getAttribute(ATTR_CATEGORY2, ""));

    // Eventually use a list of classes
    MutableBoolean oauthMarker = new MutableBoolean(false);
    Set<ElementVisitor> visitors = ImmutableSet.of(new FeatureVisitor(oauthMarker), new PreloadVisitor(),
            new OAuthVisitor(oauthMarker), new IconVisitor(), new LocaleVisitor(), new LinkVisitor(),
            new ExtraElementsVisitor() // keep this last since it accepts any tag
    );

    walk(element, visitors);

    // Tell the visitors to apply their knowledge
    for (ElementVisitor ev : visitors) {
        ev.apply(this);
    }

    needsUserPrefSubstitution = prefsNeedsUserPrefSubstitution(this);
}

From source file:org.apache.shindig.gadgets.spec.Preload.java

/**
 * Creates a new Preload from an xml node.
 *
 * @param preload The Preload to create/*from w  w w.  j a  v a 2 s.com*/
 * @throws SpecParserException When the href is not specified
 */
public Preload(Element preload, Uri base) throws SpecParserException {
    this.base = base;
    href = XmlUtil.getUriAttribute(preload, "href");
    if (href == null) {
        throw new SpecParserException("Preload/@href is missing or invalid.");
    }

    // Record all the associated views
    String viewNames = XmlUtil.getAttribute(preload, "views", "").trim();
    if (viewNames.length() == 0) {
        this.views = ImmutableSet.of();
    } else {
        this.views = ImmutableSet.copyOf(viewNames.trim().split("\\s*,+\\s*"));
    }

    auth = AuthType.parse(XmlUtil.getAttribute(preload, "authz"));
    signOwner = XmlUtil.getBoolAttribute(preload, "sign_owner", true);
    signViewer = XmlUtil.getBoolAttribute(preload, "sign_viewer", true);
    Map<String, String> attributes = Maps.newHashMap();
    NamedNodeMap attrs = preload.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Node attr = attrs.item(i);
        if (!KNOWN_ATTRIBUTES.contains(attr.getNodeName())) {
            attributes.put(attr.getNodeName(), attr.getNodeValue());
        }
    }
    this.attributes = Collections.unmodifiableMap(attributes);
}

From source file:org.apache.shindig.gadgets.templates.tags.FlashTagHandler.java

Map<String, String> getAllAttributesLowerCase(Element tag, TemplateProcessor processor) {
    Map<String, String> result = Maps.newHashMap();
    for (int i = 0; i < tag.getAttributes().getLength(); i++) {
        Node attr = tag.getAttributes().item(i);
        String attrName = attr.getNodeName().toLowerCase();
        result.put(attrName, processor.evaluate(attr.getNodeValue(), String.class, null));
    }//  w  ww. j  a v  a2 s.  c om
    return result;
}

From source file:org.apache.sling.its.servlets.ItsImportServlet.java

/**
 * Get the attributes and call output to set the attributes into
 * jackrabbit./*from ww w. j ava  2s.  co m*/
 *
 * @param element
 *           an Element from the Document object.
 * @param path
 *           jackrabbit path to store the attributes
 */
private void setAttributes(final Element element, final String path) {
    if (element.hasAttributes()) {
        final NamedNodeMap map = element.getAttributes();

        final ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < map.getLength(); i++) {
            list.add(((Attr) map.item(i)).getNodeName());
        }
        Collections.sort(list);

        for (final String attrName : list) {
            final Attr attr = (Attr) map.getNamedItem(attrName);
            output(path, attr, null);
        }
    }
}

From source file:org.apache.woden.internal.DOMWSDLReader.java

protected void parseExtensionAttributes(XMLElement extEl, Class wsdlClass, WSDLElement wsdlObj,
        DescriptionElement desc) throws WSDLException {
    Element domEl = (Element) extEl.getSource();
    NamedNodeMap nodeMap = domEl.getAttributes();
    int length = nodeMap.getLength();

    for (int i = 0; i < length; i++) {
        Attr domAttr = (Attr) nodeMap.item(i);
        String localName = domAttr.getLocalName();
        String namespaceURI = domAttr.getNamespaceURI();
        String prefix = domAttr.getPrefix();
        QName attrType = new QName(namespaceURI, localName, (prefix != null ? prefix : emptyString));
        String attrValue = domAttr.getValue();

        if (namespaceURI != null && !namespaceURI.equals(Constants.NS_STRING_WSDL20)) {
            if (!namespaceURI.equals(Constants.NS_STRING_XMLNS)
                    && !namespaceURI.equals(Constants.NS_STRING_XSI)) //TODO handle xsi attrs elsewhere, without need to register
            {//from w w  w  .j ava  2s .  c  o m
                //TODO reg namespaces at appropriate element scope, not just at desc.
                //DOMUtils.registerUniquePrefix(prefix, namespaceURI, desc);

                ExtensionRegistry extReg = fWsdlContext.extensionRegistry;
                XMLAttr xmlAttr = extReg.createExtAttribute(wsdlClass, attrType, extEl, attrValue);
                if (xmlAttr != null) //TODO use an 'UnknownAttr' class in place of null
                {
                    wsdlObj.setExtensionAttribute(attrType, xmlAttr);
                }
            } else {
                //TODO parse xmlns namespace declarations - here or elsewhere?
            }
        } else {
            //TODO confirm non-native attrs in WSDL 2.0 namespace will be detected by schema validation,
            //so no need to handle error here.
        }
    }

}

From source file:org.apache.woden.internal.DOMWSDLReader.java

protected void parseNamespaceDeclarations(XMLElement xmlElem, WSDLElement wsdlElem) throws WSDLException {

    Element elem = (Element) xmlElem.getSource();

    NamedNodeMap attrs = elem.getAttributes();
    int size = attrs.getLength();

    for (int i = 0; i < size; i++) {
        Attr attr = (Attr) attrs.item(i);
        String namespaceURI = attr.getNamespaceURI();
        String localPart = attr.getLocalName();
        String value = attr.getValue();

        if ((Constants.NS_STRING_XMLNS).equals(namespaceURI)) {
            if (!(Constants.ATTR_XMLNS).equals(localPart)) {
                wsdlElem.addNamespace(localPart, getURI(value)); //a prefixed namespace
            } else {
                wsdlElem.addNamespace(null, getURI(value)); //the default namespace
            }//from ww w.  j  a v  a2s . c o  m
        }
    }
}

From source file:org.apache.ws.scout.transport.SaajTransport.java

private SOAPMessage createSOAPMessage(Element elem) throws Exception {
    String prefix = "";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPFactory factory = SOAPFactory.newInstance();

    SOAPMessage message = msgFactory.createMessage();
    message.getSOAPHeader().detachNode();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPBody soapBody = soapPart.getEnvelope().getBody();
    //Create the outer body element
    Name bodyName = factory.createName(elem.getNodeName(), prefix, UDDI_V2_NAMESPACE);
    SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
    bodyElement.addNamespaceDeclaration(prefix, UDDI_V2_NAMESPACE);
    appendAttributes(bodyElement, elem.getAttributes(), factory);
    appendElements(bodyElement, elem.getChildNodes(), factory);
    return message;
}

From source file:org.apache.ws.scout.transport.SaajTransport.java

private void appendElements(SOAPElement bodyElement, NodeList nlist, SOAPFactory factory) throws SOAPException {
    String prefix = "";
    int len = nlist != null ? nlist.getLength() : 0;
    for (int i = 0; i < len; i++) {
        Node node = nlist.item(i);
        short nodeType = node != null ? node.getNodeType() : -100;
        if (Node.ELEMENT_NODE == nodeType) {
            Element el = (Element) node;
            Name name = factory.createName(el.getNodeName(), prefix, UDDI_V2_NAMESPACE);
            SOAPElement attachedEl = bodyElement.addChildElement(name);
            appendAttributes(attachedEl, el.getAttributes(), factory);
            appendElements(attachedEl, el.getChildNodes(), factory);
        } else if (nodeType == Node.TEXT_NODE) {
            bodyElement.addTextNode(node.getNodeValue());
        }//  w w w.j  a  va  2  s .c  o m
    }
}

From source file:org.apache.ws.security.message.WSSecDKSign.java

protected Set getInclusivePrefixes(Element target, boolean excludeVisible) {
    Set result = new HashSet();
    Node parent = target;/*from   w  ww  .jav a2  s.com*/
    NamedNodeMap attributes;
    Node attribute;
    while (!(parent.getParentNode() instanceof Document)) {
        parent = parent.getParentNode();
        attributes = parent.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            attribute = attributes.item(i);
            if (attribute.getNamespaceURI() != null
                    && attribute.getNamespaceURI().equals(org.apache.ws.security.WSConstants.XMLNS_NS)) {
                if (attribute.getNodeName().equals("xmlns")) {
                    result.add("#default");
                } else {
                    result.add(attribute.getLocalName());
                }
            }
        }
    }

    if (excludeVisible == true) {
        attributes = target.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            attribute = attributes.item(i);
            if (attribute.getNamespaceURI() != null
                    && attribute.getNamespaceURI().equals(org.apache.ws.security.WSConstants.XMLNS_NS)) {
                if (attribute.getNodeName().equals("xmlns")) {
                    result.remove("#default");
                } else {
                    result.remove(attribute.getLocalName());
                }
            }
            if (attribute.getPrefix() != null) {
                result.remove(attribute.getPrefix());
            }
        }

        if (target.getPrefix() == null) {
            result.remove("#default");
        } else {
            result.remove(target.getPrefix());
        }
    }

    return result;
}