Search in sources :

Example 1 with Attr

use of org.w3c.dom.Attr in project camel by apache.

the class EndpointDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata endpointConfig = createBeanMetadata(element, context, CxfBlueprintEndpoint.class);
    NamedNodeMap atts = element.getAttributes();
    String bus = null;
    String address = null;
    for (int i = 0; i < atts.getLength(); i++) {
        Attr node = (Attr) atts.item(i);
        String val = node.getValue();
        String pre = node.getPrefix();
        String name = node.getLocalName();
        if ("bus".equals(name)) {
            bus = val;
        } else if ("address".equals(name)) {
            address = val;
        } else if (isAttribute(pre, name)) {
            if ("endpointName".equals(name) || "serviceName".equals(name)) {
                if (isPlaceHolder(val)) {
                    endpointConfig.addProperty(name + "String", createValue(context, val));
                } else {
                    QName q = parseQName(element, val);
                    endpointConfig.addProperty(name, createValue(context, q));
                }
            } else if ("depends-on".equals(name)) {
                endpointConfig.addDependsOn(val);
            } else if (!"name".equals(name)) {
                endpointConfig.addProperty(name, createValue(context, val));
            }
        }
    }
    Element elem = DOMUtils.getFirstElement(element);
    while (elem != null) {
        String name = elem.getLocalName();
        if ("properties".equals(name)) {
            Metadata map = parseMapData(context, endpointConfig, elem);
            endpointConfig.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, endpointConfig, "bindingConfig");
        } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name) || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name) || "features".equals(name) || "schemaLocations".equals(name) || "handlers".equals(name)) {
            Metadata list = parseListData(context, endpointConfig, elem);
            endpointConfig.addProperty(name, list);
        } else {
            setFirstChildAsProperty(elem, context, endpointConfig, name);
        }
        elem = DOMUtils.getNextElement(elem);
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    //Will create a bus if needed...
    endpointConfig.addProperty("bus", getBusRef(context, bus));
    endpointConfig.setDestroyMethod("destroy");
    endpointConfig.addArgument(createValue(context, address), String.class.getName(), 0);
    endpointConfig.addArgument(createRef(context, "blueprintBundleContext"), BundleContext.class.getName(), 1);
    return endpointConfig;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) CxfBlueprintEndpoint(org.apache.camel.component.cxf.CxfBlueprintEndpoint) Attr(org.w3c.dom.Attr) BundleContext(org.osgi.framework.BundleContext)

Example 2 with Attr

use of org.w3c.dom.Attr in project camel by apache.

the class Namespaces method add.

public Namespaces add(Element element) {
    // let's set the parent first in case we overload a prefix here
    Node parentNode = element.getParentNode();
    if (parentNode instanceof org.w3c.dom.Element) {
        add((Element) parentNode);
    }
    NamedNodeMap attributes = element.getAttributes();
    int size = attributes.getLength();
    for (int i = 0; i < size; i++) {
        Attr node = (Attr) attributes.item(i);
        String name = node.getName();
        if (name.startsWith("xmlns:")) {
            String prefix = name.substring("xmlns:".length());
            String uri = node.getValue();
            add(prefix, uri);
        }
    }
    return this;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Example 3 with Attr

use of org.w3c.dom.Attr in project camel by apache.

the class DomConverter method append.

private static void append(StringBuilder buffer, Node node) {
    if (node instanceof Text) {
        Text text = (Text) node;
        buffer.append(text.getTextContent());
    } else if (node instanceof Attr) {
        Attr attribute = (Attr) node;
        buffer.append(attribute.getTextContent());
    } else if (node instanceof Element) {
        Element element = (Element) node;
        append(buffer, element.getChildNodes());
    }
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Attr(org.w3c.dom.Attr)

Example 4 with Attr

use of org.w3c.dom.Attr in project tomcat by apache.

the class DOMWriter method print.

/**
     * Prints the specified node, recursively.
     * @param node The node to output
     */
public void print(Node node) {
    // is there anything to do?
    if (node == null) {
        return;
    }
    int type = node.getNodeType();
    switch(type) {
        // print document
        case Node.DOCUMENT_NODE:
            if (!canonical) {
                out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            }
            print(((Document) node).getDocumentElement());
            out.flush();
            break;
        // print element with attributes
        case Node.ELEMENT_NODE:
            out.print('<');
            out.print(node.getLocalName());
            Attr[] attrs = sortAttributes(node.getAttributes());
            for (int i = 0; i < attrs.length; i++) {
                Attr attr = attrs[i];
                out.print(' ');
                out.print(attr.getLocalName());
                out.print("=\"");
                out.print(escape(attr.getNodeValue()));
                out.print('"');
            }
            out.print('>');
            printChildren(node);
            break;
        // handle entity reference nodes
        case Node.ENTITY_REFERENCE_NODE:
            if (canonical) {
                printChildren(node);
            } else {
                out.print('&');
                out.print(node.getLocalName());
                out.print(';');
            }
            break;
        // print cdata sections
        case Node.CDATA_SECTION_NODE:
            if (canonical) {
                out.print(escape(node.getNodeValue()));
            } else {
                out.print("<![CDATA[");
                out.print(node.getNodeValue());
                out.print("]]>");
            }
            break;
        // print text
        case Node.TEXT_NODE:
            out.print(escape(node.getNodeValue()));
            break;
        // print processing instruction
        case Node.PROCESSING_INSTRUCTION_NODE:
            out.print("<?");
            out.print(node.getLocalName());
            String data = node.getNodeValue();
            if (data != null && data.length() > 0) {
                out.print(' ');
                out.print(data);
            }
            out.print("?>");
            break;
    }
    if (type == Node.ELEMENT_NODE) {
        out.print("</");
        out.print(node.getLocalName());
        out.print('>');
    }
    out.flush();
}
Also used : Attr(org.w3c.dom.Attr)

Example 5 with Attr

use of org.w3c.dom.Attr in project hackpad by dropbox.

the class XmlNode method addNamespaces.

private void addNamespaces(Namespaces rv, Element element) {
    if (element == null)
        throw new RuntimeException("element must not be null");
    String myDefaultNamespace = toUri(element.lookupNamespaceURI(null));
    String parentDefaultNamespace = "";
    if (element.getParentNode() != null) {
        parentDefaultNamespace = toUri(element.getParentNode().lookupNamespaceURI(null));
    }
    if (!myDefaultNamespace.equals(parentDefaultNamespace) || !(element.getParentNode() instanceof Element)) {
        rv.declare(Namespace.create("", myDefaultNamespace));
    }
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (attr.getPrefix() != null && attr.getPrefix().equals("xmlns")) {
            rv.declare(Namespace.create(attr.getLocalName(), attr.getValue()));
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)385 Element (org.w3c.dom.Element)178 NamedNodeMap (org.w3c.dom.NamedNodeMap)160 Document (org.w3c.dom.Document)134 Node (org.w3c.dom.Node)126 NodeList (org.w3c.dom.NodeList)80 DOMException (org.w3c.dom.DOMException)30 ArrayList (java.util.ArrayList)25 DocumentBuilder (javax.xml.parsers.DocumentBuilder)16 HashMap (java.util.HashMap)12 Text (org.w3c.dom.Text)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 QName (javax.xml.namespace.QName)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)7 ParseException (java.text.ParseException)6 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)6