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;
}
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;
}
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());
}
}
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();
}
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()));
}
}
}
Aggregations