diff options
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponent.java')
| -rw-r--r-- | projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponent.java | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponent.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponent.java index 327e024..a5157fe 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponent.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOComponent.java @@ -180,8 +180,8 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton return null; WOElement result = null; try { - NSDictionary bindings = processDeclaration(aDeclaration); - List elements = new LinkedList(); + NSDictionary<String, WOElementBindings> bindings = processDeclaration(aDeclaration); + List<WOElement> elements = new LinkedList<>(); int index = processTemplate(elements, anHTMLString, 0, bindings, aLanguageList); if (index == -1) { if (elements.size() == 1) { @@ -581,13 +581,14 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton * interesting tags, and calling itself recursively as necessary. Returns the * index to resume parsing, or -1 if done. */ - static private int processTemplate(List elements, String template, int index, Map bindings, List aLanguageList) + static private int processTemplate(List<WOElement> elements, String template, int index, Map<String, WOElementBindings> bindings, List aLanguageList) throws java.io.IOException { // System.out.println( "processTemplate: " + index ); if (template == null) return -1; int start = index; + // TODO proper XML/HTML parsing? while (true) { // search for start of next tag start = template.indexOf('<', start); @@ -667,7 +668,7 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton WOElement body = null; if (hasBody) { - List childElements = new LinkedList(); + List<WOElement> childElements = new LinkedList<>(); index = processTemplate(childElements, template, index, bindings, aLanguageList); start = index; @@ -685,16 +686,22 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton WOElement element = null; String nameProperty = (String) params.get(NAME_KEY); - NSDictionary original = (NSDictionary) bindings.get(nameProperty); - // System.out.println( nameProperty + " : " + associations ); - if (original == null) { - original = NSDictionary.EmptyDictionary; + WOElementBindings original; + if (!bindings.containsKey(nameProperty)) { + original = null; System.err.println("No associations for: " + nameProperty); System.err.println(bindings); + } else { + original = bindings.get(nameProperty); } - NSDictionary associations = new NSMutableDictionary(original); - String elementClass = (String) associations.remove(WOApplication.ELEMENT_CLASS); + NSDictionary<String, WOAssociation> associations; + if (original == null) { + associations = new NSMutableDictionary<String, WOAssociation>((NSDictionary<String, WOAssociation>)NSDictionary.EmptyDictionary); + } else { + associations = new NSMutableDictionary<String, WOAssociation>(original); + } + String elementClass = original.getElementClass(); WOApplication application = WOApplication.application(); element = application.dynamicElementWithName(elementClass, associations, body, aLanguageList); @@ -848,9 +855,9 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton * Parses the declarations in the specified content and returns a map of element * names to maps of attribute names to WOAssociations. */ - private static NSDictionary processDeclaration(String content) { + private static NSDictionary<String, WOElementBindings> processDeclaration(String content) { int index; - NSMutableDictionary result = new NSMutableDictionary(); + NSMutableDictionary<String, WOElementBindings> result = new NSMutableDictionary<>(); // strip out comments StringBuffer stripped = new StringBuffer(); @@ -923,7 +930,7 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton token = tokens.nextToken(); } - NSMutableDictionary associations = new NSMutableDictionary(); + NSMutableDictionary<String, WOAssociation> associations = new NSMutableDictionary<>(); if (!token.equals("}")) { String line, key, value; @@ -972,8 +979,9 @@ public class WOComponent extends WOElement implements WOActionResults, net.woton throw new RuntimeException("Error parsing declaration: expected } but found: '" + token + "'"); } } - associations.put(WOApplication.ELEMENT_CLASS, cl); // store classname - result.put(name, associations); + //associations.put(WOApplication.ELEMENT_CLASS, cl); // store classname + + result.put(name, new WOElementBindings(associations, cl)); } // System.out.println( "processDeclaration: " + result ); |
