Search in sources :

Example 31 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 32 with Attr

use of org.w3c.dom.Attr in project redisson by redisson.

the class LocalCachedMapOptionsDecorator method decorate.

@Override
public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
    NodeList list = element.getElementsByTagNameNS(RedissonNamespaceParserSupport.REDISSON_NAMESPACE, RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT);
    Element options = null;
    String id;
    if (list.getLength() == 1) {
        options = (Element) list.item(0);
        id = invokeOptions(options, parserContext, helper);
        for (int i = 0; i < options.getAttributes().getLength(); i++) {
            Attr item = (Attr) options.getAttributes().item(i);
            if (helper.isEligibleAttribute(item) && !RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE.equals(item.getLocalName()) && !RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE.equals(item.getLocalName())) {
                helper.invoker(id, helper.getName(item), new Object[] { item.getValue() }, parserContext);
            }
        }
        invokeTimeUnitOptions(options, id, parserContext, helper, RedissonNamespaceParserSupport.TIME_TO_LIVE_ATTRIBUTE, RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE);
        invokeTimeUnitOptions(options, id, parserContext, helper, RedissonNamespaceParserSupport.MAX_IDLE_ATTRIBUTE, RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE);
    } else {
        id = invokeOptions(options, parserContext, helper);
    }
    helper.addConstructorArgs(new RuntimeBeanReference(id), LocalCachedMapOptions.class, builder);
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Attr(org.w3c.dom.Attr)

Example 33 with Attr

use of org.w3c.dom.Attr in project redisson by redisson.

the class RedissonDefinitionParser method parseAttributes.

private void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    NamedNodeMap attributes = element.getAttributes();
    for (int x = 0; x < attributes.getLength(); x++) {
        Attr attribute = (Attr) attributes.item(x);
        if (helper.isEligibleAttribute(attribute)) {
            String propertyName = attribute.getLocalName().endsWith(REF_SUFFIX) ? attribute.getLocalName().substring(0, attribute.getLocalName().length() - REF_SUFFIX.length()) : attribute.getLocalName();
            propertyName = Conventions.attributeNameToPropertyName(propertyName);
            Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from" + " 'extractPropertyName(String)': cannot be" + " null or empty.");
            if (attribute.getLocalName().endsWith(REF_SUFFIX)) {
                builder.addPropertyReference(propertyName, attribute.getValue());
            } else {
                Object value = attribute.getValue();
                String localName = helper.getName(element);
                if ("masterAddress".equals(propertyName) && ConfigType.masterSlaveServers.name().equals(localName)) {
                    try {
                        value = URLBuilder.create((String) value);
                    } catch (Exception e) {
                        //value may be a placeholder
                        value = "redis://" + value;
                    }
                }
                builder.addPropertyValue(propertyName, value);
            }
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 34 with Attr

use of org.w3c.dom.Attr in project robovm by robovm.

the class DOM3TreeWalker method isAttributeWellFormed.

/**
     * Checks if an attr node is well-formed, by checking it's Name and value
     * for well-formedness.
     * 
     * @param data The contents of the comment node
     * @return a boolean indiacating if the comment is well-formed or not.
     */
protected void isAttributeWellFormed(Node node) {
    boolean isNameWF = false;
    if ((fFeatures & NAMESPACES) != 0) {
        isNameWF = isValidQName(node.getPrefix(), node.getLocalName(), fIsXMLVersion11);
    } else {
        isNameWF = isXMLName(node.getNodeName(), fIsXMLVersion11);
    }
    if (!isNameWF) {
        String msg = Utils.messages.createMessage(MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME, new Object[] { "Attr", node.getNodeName() });
        if (fErrorHandler != null) {
            fErrorHandler.handleError(new DOMErrorImpl(DOMError.SEVERITY_FATAL_ERROR, msg, MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME, null, null, null));
        }
    }
    // Check the Attr's node value
    // WFC: No < in Attribute Values
    String value = node.getNodeValue();
    if (value.indexOf('<') >= 0) {
        String msg = Utils.messages.createMessage(MsgKey.ER_WF_LT_IN_ATTVAL, new Object[] { ((Attr) node).getOwnerElement().getNodeName(), node.getNodeName() });
        if (fErrorHandler != null) {
            fErrorHandler.handleError(new DOMErrorImpl(DOMError.SEVERITY_FATAL_ERROR, msg, MsgKey.ER_WF_LT_IN_ATTVAL, null, null, null));
        }
    }
    // we need to loop through the children of attr nodes and check their values for
    // well-formedness  
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        // should have some exception defined for this.
        if (child == null) {
            // we should probably report an error
            continue;
        }
        switch(child.getNodeType()) {
            case Node.TEXT_NODE:
                isTextWellFormed((Text) child);
                break;
            case Node.ENTITY_REFERENCE_NODE:
                isEntityReferneceWellFormed((EntityReference) child);
                break;
            default:
        }
    }
// TODO:
// WFC: Check if the attribute prefix is bound to 
// http://www.w3.org/2000/xmlns/  
// WFC: Unique Att Spec
// Perhaps pass a seen boolean value to this method.  serializeAttList will determine
// if the attr was seen before.
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Attr(org.w3c.dom.Attr)

Example 35 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)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6