Search in sources :

Example 6 with QName

use of groovy.namespace.QName in project groovy by apache.

the class Attributes method iterator.

@Override
public Iterator iterator() {
    return new NodeIterator(nodeIterator()) {

        @Override
        protected Object getNextNode(final Iterator iter) {
            while (iter.hasNext()) {
                final Object next = iter.next();
                if (next instanceof Attribute) {
                    return next;
                } else {
                    String attributeKey = Attributes.this.attributeName;
                    if (Attributes.this.namespacePrefix != null && !"*".equals(Attributes.this.namespacePrefix) && Attributes.this.namespacePrefix.length() > 0) {
                        attributeKey = new QName(Attributes.this.lookupNamespace(Attributes.this.namespacePrefix), Attributes.this.attributeName).toString();
                    }
                    final String value = (String) ((Node) next).attributes().get(attributeKey);
                    if (value != null) {
                        return new Attribute(Attributes.this.name, value, new NodeChild((Node) next, Attributes.this.parent.parent, "", Attributes.this.namespaceTagHints), (Attributes.this.namespacePrefix == null || "*".equals(Attributes.this.namespacePrefix)) ? "" : Attributes.this.namespacePrefix, Attributes.this.namespaceTagHints);
                    }
                }
            }
            return null;
        }
    };
}
Also used : QName(groovy.namespace.QName) Iterator(java.util.Iterator) GroovyObject(groovy.lang.GroovyObject)

Example 7 with QName

use of groovy.namespace.QName in project groovy by apache.

the class NamespaceAwareHashMap method adjustForNamespaceIfNeeded.

private Object adjustForNamespaceIfNeeded(Object key) {
    String keyString = key.toString();
    if (keyString.contains("{") || namespaceTagHints == null || namespaceTagHints.isEmpty() || !keyString.contains(":")) {
        return key;
    }
    final int i = keyString.indexOf(':');
    return new QName(namespaceTagHints.get(keyString.substring(0, i)).toString(), keyString.substring(i + 1)).toString();
}
Also used : QName(groovy.namespace.QName)

Aggregations

QName (groovy.namespace.QName)7 GroovyObject (groovy.lang.GroovyObject)1 Tuple3 (groovy.lang.Tuple3)1 NamespaceAwareHashMap (groovy.xml.slurpersupport.NamespaceAwareHashMap)1 Node (groovy.xml.slurpersupport.Node)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 RuntimeConfigurable (org.apache.tools.ant.RuntimeConfigurable)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Text (org.w3c.dom.Text)1 Attributes (org.xml.sax.Attributes)1 SAXParseException (org.xml.sax.SAXParseException)1