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