[seam-commits] Seam SVN: r9196 - trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Oct 5 10:56:36 EDT 2008


Author: christian.bauer at jboss.com
Date: 2008-10-05 10:56:34 -0400 (Sun, 05 Oct 2008)
New Revision: 9196

Modified:
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/WikiPluginMacro.java
Log:
Fixed non-unique macro bug, appeared in macros that render macros

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/WikiPluginMacro.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/WikiPluginMacro.java	2008-10-05 12:24:30 UTC (rev 9195)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/plugin/WikiPluginMacro.java	2008-10-05 14:56:34 UTC (rev 9196)
@@ -19,6 +19,8 @@
 import java.io.Serializable;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.UUID;
+import java.util.Date;
 
 /**
  * An instance of a macro in wiki text that has an XHTML include/template.
@@ -71,6 +73,7 @@
         }
     }
 
+    private String uniqueId = Long.toString(new Date().getTime());
     private String clientId;
     private MacroPluginModule metadata;
     private Map attributes = new HashMap();
@@ -106,8 +109,11 @@
 
     // Some convenience methods that generate Strings used all over the place
 
+    // This needs to be unique _across_ different wiki texts. So the numeric position and the name is not enough,
+    // the hashCode() is overriden in the superclass to be the name/position combination... so we need the uniqueId.
+    // TODO: We can now actually remove the position and name, but they help us with debugging.
     public String getPageVariableName() {
-        return PAGE_VARIABLE_PREFIX + getPosition() + PAGE_VARIABLE_SEPARATOR + getName();
+        return PAGE_VARIABLE_PREFIX + getPosition() + PAGE_VARIABLE_SEPARATOR + this.uniqueId + PAGE_VARIABLE_SEPARATOR + getName();
     }
 
     public String getCallbackEventName(CallbackEvent event) {
@@ -187,8 +193,25 @@
         return hash.hash(builder.toString());
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        if (!super.equals(o)) return false;
+        WikiPluginMacro that = (WikiPluginMacro) o;
+        return uniqueId.equals(that.uniqueId);
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = super.hashCode();
+        result = 31 * result + uniqueId.hashCode();
+        return result;
+    }
+
     public String toString() {
-        return "WikiPluginMacro ClientId '" + getClientId() + "' (" + getPosition() + "): "
+        return "WikiPluginMacro UniqueId '" + this.uniqueId + "' (" + getPosition() + "): "
                 + getName() + " Params: " + getParams().size();
     }
 




More information about the seam-commits mailing list