From 76adca11afff1649621d462ca67589f76ff29603 Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sun, 6 Oct 2024 16:53:36 -0400 Subject: Updates --- projects/net.wotonomy.all/pom.xml | 3 +- projects/net.wotonomy.datastore/pom.xml | 3 +- projects/net.wotonomy.foundation/pom.xml | 3 +- projects/net.wotonomy.persistence/pom.xml | 3 +- projects/net.wotonomy.ui/pom.xml | 3 +- projects/net.wotonomy.web/pom.xml | 3 +- .../main/java/net/wotonomy/web/WOApplication.java | 2 +- .../main/java/net/wotonomy/web/WOComponent.java | 38 +++++---- .../java/net/wotonomy/web/WODynamicElement.java | 4 +- .../src/main/java/net/wotonomy/web/WOElement.java | 2 +- .../java/net/wotonomy/web/WOElementBindings.java | 91 ++++++++++++++++++++++ .../main/java/net/wotonomy/web/WOHyperlink.java | 1 + .../src/main/java/net/wotonomy/web/WOResponse.java | 13 ++-- projects/pom.xml | 3 +- 14 files changed, 140 insertions(+), 32 deletions(-) create mode 100644 projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElementBindings.java diff --git a/projects/net.wotonomy.all/pom.xml b/projects/net.wotonomy.all/pom.xml index 002ea02..8316b1d 100644 --- a/projects/net.wotonomy.all/pom.xml +++ b/projects/net.wotonomy.all/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy wotonomy-all diff --git a/projects/net.wotonomy.datastore/pom.xml b/projects/net.wotonomy.datastore/pom.xml index 7dfad9e..2db3202 100644 --- a/projects/net.wotonomy.datastore/pom.xml +++ b/projects/net.wotonomy.datastore/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy diff --git a/projects/net.wotonomy.foundation/pom.xml b/projects/net.wotonomy.foundation/pom.xml index 4a347cc..3e85c9a 100644 --- a/projects/net.wotonomy.foundation/pom.xml +++ b/projects/net.wotonomy.foundation/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy diff --git a/projects/net.wotonomy.persistence/pom.xml b/projects/net.wotonomy.persistence/pom.xml index 13bb0c3..813ec4c 100644 --- a/projects/net.wotonomy.persistence/pom.xml +++ b/projects/net.wotonomy.persistence/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy diff --git a/projects/net.wotonomy.ui/pom.xml b/projects/net.wotonomy.ui/pom.xml index a02fd93..04af0d1 100644 --- a/projects/net.wotonomy.ui/pom.xml +++ b/projects/net.wotonomy.ui/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy diff --git a/projects/net.wotonomy.web/pom.xml b/projects/net.wotonomy.web/pom.xml index 1ac517e..d3903fe 100644 --- a/projects/net.wotonomy.web/pom.xml +++ b/projects/net.wotonomy.web/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java index 570a97d..6103b0d 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java @@ -594,7 +594,7 @@ public class WOApplication extends HttpServlet { /** * Returns either a dynamic element or a component for the specified name. */ - public WOElement dynamicElementWithName(String anElementName, NSDictionary anAssociationMap, WOElement aBodyElement, + public WOElement dynamicElementWithName(String anElementName, NSDictionary anAssociationMap, WOElement aBodyElement, List aLanguageList) { WOElement element = null; Class c = null; 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 bindings = processDeclaration(aDeclaration); + List 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 elements, String template, int index, Map 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 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 associations; + if (original == null) { + associations = new NSMutableDictionary((NSDictionary)NSDictionary.EmptyDictionary); + } else { + associations = new NSMutableDictionary(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 processDeclaration(String content) { int index; - NSMutableDictionary result = new NSMutableDictionary(); + NSMutableDictionary 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 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 ); diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java index 8cae72c..62ea6ae 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WODynamicElement.java @@ -39,7 +39,7 @@ public abstract class WODynamicElement extends WOElement { private static final long serialVersionUID = -5383805382837136590L; protected String name; protected WOElement rootElement; - protected NSDictionary associations; + protected NSDictionary associations; /** * The default constructor. @@ -57,7 +57,7 @@ public abstract class WODynamicElement extends WOElement { * and the values are associations to be applied to the context's current * component. */ - public WODynamicElement(String aName, NSDictionary anAssociationMap, WOElement aRootElement) { + public WODynamicElement(String aName, NSDictionary anAssociationMap, WOElement aRootElement) { this(); name = aName; associations = anAssociationMap; diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElement.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElement.java index b1c4282..5f701f1 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElement.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElement.java @@ -32,7 +32,7 @@ import net.wotonomy.foundation.NSDictionary; */ public abstract class WOElement implements WOActionResults, Serializable { private static final long serialVersionUID = 3854088436393061500L; - NSDictionary associations; + NSDictionary associations; /** * Default constructor. Performs necessary initialization. diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElementBindings.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElementBindings.java new file mode 100644 index 0000000..e474a1f --- /dev/null +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOElementBindings.java @@ -0,0 +1,91 @@ +package net.wotonomy.web; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + + +public class WOElementBindings implements Map { + private Map bindings; + private String elementClass; + + public WOElementBindings(Map bindings, String elementClass) { + this.bindings = bindings; + this.elementClass = elementClass; + } + + public String getElementClass() { + return elementClass; + } + + // Delegate methods to Map + @Override + public int size() { + return bindings.size(); + } + + @Override + public boolean isEmpty() { + return bindings.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return bindings.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return bindings.containsValue(value); + } + + @Override + public WOAssociation get(Object key) { + return bindings.get(key); + } + + @Override + public WOAssociation put(String key, WOAssociation value) { + return bindings.put(key, value); + } + + @Override + public WOAssociation remove(Object key) { + return bindings.remove(key); + } + + @Override + public void putAll(Map m) { + bindings.putAll(m); + } + + @Override + public void clear() { + bindings.clear(); + } + + @Override + public Set keySet() { + return bindings.keySet(); + } + + @Override + public Collection values() { + return bindings.values(); + } + + @Override + public Set> entrySet() { + return bindings.entrySet(); + } + + @Override + public boolean equals(Object o) { + return bindings.equals(o); + } + + @Override + public int hashCode() { + return bindings.hashCode(); + } +} diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java index e2041d5..3c1fd06 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java @@ -55,6 +55,7 @@ import net.wotonomy.foundation.NSDictionary; * @version $Revision: 905 $ */ public class WOHyperlink extends WODynamicElement { + private static final long serialVersionUID = -7615256188185925861L; protected String string; protected String href; diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java index 6e729cb..0b436fc 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOResponse.java @@ -74,7 +74,7 @@ public class WOResponse extends WOMessage implements WOActionResults { setHeader(dateString, "Date"); setHeader(dateString, "Expires"); setHeader("no-cache", "Pragma"); - setHeaders(new NSArray(new Object[] { "private", "no-cache", "max-age = 0" }), "Cache-Control"); + setHeaders(new NSArray<>(new String[] { "private", "no-cache", "max-age = 0" }), "Cache-Control"); // System.out.println( "disableClientCaching: " + dateString ); } @@ -100,7 +100,8 @@ public class WOResponse extends WOMessage implements WOActionResults { } String key; - java.util.Enumeration e, f; + java.util.Enumeration e; + java.util.Enumeration f; // set content type: might be overwritten by headers below response.setContentType("text/html"); @@ -114,7 +115,7 @@ public class WOResponse extends WOMessage implements WOActionResults { f = _headers.allKeys().objectEnumerator(); while (f.hasMoreElements()) { key = f.nextElement().toString(); - e = ((NSArray) _headers.objectForKey(key)).objectEnumerator(); + e = ((NSArray) _headers.objectForKey(key)).objectEnumerator(); if (e.hasMoreElements()) { // overwrite existing header response.setHeader(key, e.nextElement().toString()); @@ -125,9 +126,9 @@ public class WOResponse extends WOMessage implements WOActionResults { } // set cookies - e = _cookies.allValues().objectEnumerator(); - while (e.hasMoreElements()) { - response.addCookie((WOCookie) e.nextElement()); + java.util.Enumeration cookies = _cookies.allValues().objectEnumerator(); + while (cookies.hasMoreElements()) { + response.addCookie(cookies.nextElement()); } try { diff --git a/projects/pom.xml b/projects/pom.xml index 7c46448..ab78723 100644 --- a/projects/pom.xml +++ b/projects/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 net.wotonomy wotonomy-root -- cgit v1.2.3