use of groovy.namespace.QName in project groovy by apache.
the class Node method getByName.
/**
* Provides lookup of elements by name.
*
* @param name the name of interest
* @return the nodes matching name
*/
private NodeList getByName(String name) {
NodeList answer = new NodeList();
for (Object child : children()) {
if (child instanceof Node) {
Node childNode = (Node) child;
Object childNodeName = childNode.name();
if (childNodeName instanceof QName) {
QName qn = (QName) childNodeName;
if (qn.matches(name)) {
answer.add(childNode);
}
} else if (name.equals(childNodeName)) {
answer.add(childNode);
}
}
}
return answer;
}
use of groovy.namespace.QName in project groovy by apache.
the class SAXBuilder method getNameInfo.
private Tuple3<String, String, String> getNameInfo(Object name) {
String uri;
String localName;
String qualifiedName;
if (name instanceof QName) {
QName qname = (QName) name;
uri = qname.getNamespaceURI();
localName = qname.getLocalPart();
qualifiedName = qname.getQualifiedName();
} else {
uri = "";
localName = name.toString();
qualifiedName = localName;
}
return new Tuple3<>(uri, localName, qualifiedName);
}
use of groovy.namespace.QName in project groovy by apache.
the class AntBuilderLocator method createNode.
@Override
protected Object createNode(final Object name, final Map attributes) {
final Attributes attrs = buildAttributes(attributes);
String tagName = name.toString();
String ns = "";
if (name instanceof QName) {
QName q = (QName) name;
tagName = q.getLocalPart();
ns = q.getNamespaceURI();
}
// import can be used only as top level element
if ("import".equals(name)) {
antXmlContext.setCurrentTarget(implicitTarget);
} else if ("target".equals(name) && !insideTask) {
return onStartTarget(attrs, tagName, ns);
} else if ("defineTarget".equals(name) && !insideTask) {
return onDefineTarget(attrs, "target", ns);
}
try {
antElementHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
} catch (final SAXParseException e) {
log.log(Level.SEVERE, "Caught: " + e, e);
}
insideTask = true;
final RuntimeConfigurable wrapper = antXmlContext.getWrapperStack().lastElement();
return wrapper.getProxy();
}
use of groovy.namespace.QName in project groovy by apache.
the class XmlSlurper method startElement.
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes atts) throws SAXException {
addCdata();
final Map<String, String> attributes = new NamespaceAwareHashMap();
final Map<String, String> attributeNamespaces = new HashMap<String, String>();
for (int i = atts.getLength() - 1; i != -1; i--) {
if (atts.getURI(i).length() == 0) {
attributes.put(atts.getQName(i), atts.getValue(i));
} else {
String key = new QName(atts.getURI(i), atts.getLocalName(i)).toString();
attributes.put(key, atts.getValue(i));
attributeNamespaces.put(key, atts.getURI(i));
}
}
final Node newElement;
if (namespaceURI.length() == 0) {
newElement = new Node(currentNode, qName, attributes, attributeNamespaces, namespaceURI);
} else {
newElement = new Node(currentNode, localName, attributes, attributeNamespaces, namespaceURI);
}
if (currentNode != null) {
currentNode.addChild(newElement);
}
stack.push(currentNode);
currentNode = newElement;
}
use of groovy.namespace.QName in project groovy by apache.
the class DOMCategory method appendNode.
public static Element appendNode(Element self, Object name, String value) {
Document doc = self.getOwnerDocument();
Element newChild;
if (name instanceof QName) {
QName qn = (QName) name;
newChild = doc.createElementNS(qn.getNamespaceURI(), qn.getQualifiedName());
} else {
newChild = doc.createElement(name.toString());
}
if (value != null) {
Text text = doc.createTextNode(value);
newChild.appendChild(text);
}
self.appendChild(newChild);
return newChild;
}
Aggregations