Search in sources :

Example 96 with Map

use of java.util.Map in project groovy by apache.

the class Node method build.

public void build(final GroovyObject builder, final Map namespaceMap, final Map<String, String> namespaceTagHints) {
    if (this.replacementNodeStack.empty()) {
        final Closure rest = new Closure(null) {

            public Object doCall(final Object o) {
                buildChildren(builder, namespaceMap, namespaceTagHints);
                return null;
            }
        };
        if (this.namespaceURI.length() == 0 && this.attributeNamespaces.isEmpty()) {
            builder.invokeMethod(this.name, new Object[] { this.attributes, rest });
        } else {
            final List newTags = new LinkedList();
            builder.getProperty("mkp");
            final List namespaces = (List) builder.invokeMethod("getNamespaces", new Object[] {});
            final Map current = (Map) namespaces.get(0);
            final Map pending = (Map) namespaces.get(1);
            if (this.attributeNamespaces.isEmpty()) {
                builder.getProperty(getTagFor(this.namespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder));
                builder.invokeMethod(this.name, new Object[] { this.attributes, rest });
            } else {
                final Map attributesWithNamespaces = new HashMap(this.attributes);
                for (Object key : this.attributes.keySet()) {
                    final Object attributeNamespaceURI = this.attributeNamespaces.get(key);
                    if (attributeNamespaceURI != null) {
                        attributesWithNamespaces.put(getTagFor(attributeNamespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder) + "$" + key, attributesWithNamespaces.remove(key));
                    }
                }
                builder.getProperty(getTagFor(this.namespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder));
                builder.invokeMethod(this.name, new Object[] { attributesWithNamespaces, rest });
            }
            // remove the new tags we had to define for this element
            if (!newTags.isEmpty()) {
                final Iterator iter = newTags.iterator();
                do {
                    pending.remove(iter.next());
                } while (iter.hasNext());
            }
        }
    } else {
        ((ReplacementNode) this.replacementNodeStack.peek()).build(builder, namespaceMap, namespaceTagHints);
    }
}
Also used : Closure(groovy.lang.Closure) HashMap(java.util.HashMap) Iterator(java.util.Iterator) GroovyObject(groovy.lang.GroovyObject) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 97 with Map

use of java.util.Map in project groovy by apache.

the class DOMCategory method appendNode.

public static Element appendNode(Element self, Object name, Map attributes, String value) {
    Element result = appendNode(self, name, value);
    for (Object o : attributes.entrySet()) {
        Map.Entry e = (Map.Entry) o;
        putAt(result, "@" + e.getKey().toString(), e.getValue());
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 98 with Map

use of java.util.Map in project groovy by apache.

the class Builder method fettleMethodMap.

private static Map fettleMethodMap(final Closure defaultGenerator, final Map methodMap) {
    final Map newMethodMap = new HashMap();
    for (Object o : methodMap.keySet()) {
        final Object key = o;
        final Object value = methodMap.get(key);
        if ((value instanceof Closure)) {
            newMethodMap.put(key, value);
        } else {
            newMethodMap.put(key, defaultGenerator.curry((Object[]) value));
        }
    }
    return newMethodMap;
}
Also used : Closure(groovy.lang.Closure) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 99 with Map

use of java.util.Map in project groovy by apache.

the class DomToGroovy method defineNamespaces.

protected Map defineNamespaces(Element element, Map namespaces) {
    Map answer = null;
    String prefix = element.getPrefix();
    if (prefix != null && prefix.length() > 0 && !namespaces.containsKey(prefix)) {
        answer = new HashMap(namespaces);
        defineNamespace(answer, prefix, element.getNamespaceURI());
    }
    NamedNodeMap attributes = element.getAttributes();
    int length = attributes.getLength();
    for (int i = 0; i < length; i++) {
        Attr attribute = (Attr) attributes.item(i);
        prefix = attribute.getPrefix();
        if (prefix != null && prefix.length() > 0 && !namespaces.containsKey(prefix)) {
            if (answer == null) {
                answer = new HashMap(namespaces);
            }
            defineNamespace(answer, prefix, attribute.getNamespaceURI());
        }
    }
    return (answer != null) ? answer : namespaces;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 100 with Map

use of java.util.Map in project groovy by apache.

the class SAXBuilder method createNode.

protected Object createNode(Object name, Map attributeMap, Object text) {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator iter = attributeMap.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        String uri = "";
        String localName = null;
        String qualifiedName = "";
        String valueText = (value != null) ? value.toString() : "";
        if (key instanceof QName) {
            QName qname = (QName) key;
            uri = qname.getNamespaceURI();
            localName = qname.getLocalPart();
            qualifiedName = qname.getQualifiedName();
        } else {
            localName = key.toString();
            qualifiedName = localName;
        }
        attributes.addAttribute(uri, localName, qualifiedName, "CDATA", valueText);
    }
    doStartElement(name, attributes);
    if (text != null) {
        doText(text);
    }
    return name;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Iterator(java.util.Iterator) Map(java.util.Map)

Aggregations

Map (java.util.Map)15646 HashMap (java.util.HashMap)9529 ArrayList (java.util.ArrayList)3619 List (java.util.List)2988 Test (org.junit.Test)2558 Set (java.util.Set)1837 HashSet (java.util.HashSet)1646 IOException (java.io.IOException)1486 Iterator (java.util.Iterator)1307 LinkedHashMap (java.util.LinkedHashMap)1284 TreeMap (java.util.TreeMap)1022 ImmutableMap (com.google.common.collect.ImmutableMap)879 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)729 File (java.io.File)662 Collection (java.util.Collection)576 Collectors (java.util.stream.Collectors)436 ConcurrentMap (java.util.concurrent.ConcurrentMap)375 LinkedList (java.util.LinkedList)333 SSOException (com.iplanet.sso.SSOException)294 Collections (java.util.Collections)288