You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/01/16 19:59:37 UTC

svn commit: r1779093 - /pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java

Author: rwhitcomb
Date: Mon Jan 16 19:59:37 2017
New Revision: 1779093

URL: http://svn.apache.org/viewvc?rev=1779093&view=rev
Log:
PIVOT-965:  Add "defaultLanguage" attribute to BXMLSerializer so that custom
scripting language (for instance, "rhino" for compatibility) can be made the
default for scripts.

Note: this change is not quite the same as the suggested patch in two ways:
1. This code accepts "null" for the default language, which will set it back
   to our installation default (namely "javascript").
2. This installation default cannot be "rhino" as suggested or all the scripts
   break in Java 1.8.  Not quite ready for that yet.  But applications that
   really need "rhino" as default should be able to do that with a custom
   subclass that always sets the default language as needed.

Modified:
    pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java

Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=1779093&r1=1779092&r2=1779093&view=diff
==============================================================================
--- pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java Mon Jan 16 19:59:37 2017
@@ -113,19 +113,19 @@ public class BXMLSerializer implements S
     }
 
 /*    private static void printBindings(java.util.Map<String,Object> bindings) {
-	System.out.format("=== Bindings %1$s ===%n", bindings);
-	for (String key : bindings.keySet()) {
-	    Object value = bindings.get(key);
-	    System.out.format("key: %1$s, value: %2$s [%3$s]%n", key, value, Integer.toHexString(System.identityHashCode(value)));
-	    if (key.equals(NASHORN_GLOBAL)) {
-		Bindings globalBindings = (Bindings)value;
-		for (String globalKey : globalBindings.keySet()) {
-		    Object globalValue = globalBindings.get(globalKey);
-		    System.out.format("    global key: %1$s, value: %2$s [%3$s]%n", globalKey, globalValue, Integer.toHexString(System.identityHashCode(globalValue)));
-		}
-	    }
-	}
-	System.out.println("=====================");
+        System.out.format("=== Bindings %1$s ===%n", bindings);
+        for (String key : bindings.keySet()) {
+            Object value = bindings.get(key);
+            System.out.format("key: %1$s, value: %2$s [%3$s]%n", key, value, Integer.toHexString(System.identityHashCode(value)));
+            if (key.equals(NASHORN_GLOBAL)) {
+                Bindings globalBindings = (Bindings)value;
+                for (String globalKey : globalBindings.keySet()) {
+                    Object globalValue = globalBindings.get(globalKey);
+                    System.out.format("    global key: %1$s, value: %2$s [%3$s]%n", globalKey, globalValue, Integer.toHexString(System.identityHashCode(globalValue)));
+                }
+            }
+        }
+        System.out.println("=====================");
     }
 */
     private class AttributeInvocationHandler implements InvocationHandler {
@@ -261,6 +261,7 @@ public class BXMLSerializer implements S
     private Element element = null;
 
     private Object root = null;
+    private String defaultLanguage = DEFAULT_LANGUAGE;
     private String language = null;
     private int nextID = 0;
 
@@ -752,7 +753,7 @@ public class BXMLSerializer implements S
 
         // Initialize the page language
         if (language == null) {
-            language = DEFAULT_LANGUAGE;
+            language = getDefaultLanguage();
         }
 
         // Get element properties
@@ -1854,4 +1855,24 @@ public class BXMLSerializer implements S
             throw new SerializationException(exception);
         }
     }
+
+    /**
+     * Set the default script language to use for all scripts.
+     *
+     * @param defaultLanguage Name of the new default script language,
+     * or {@code null} to set the default, default value.
+     * @see #DEFAULT_LANGUAGE
+     */
+    protected void setDefaultLanguage(String defaultLanguage) {
+        if (defaultLanguage == null) {
+            this.defaultLanguage = DEFAULT_LANGUAGE;
+        } else {
+            this.defaultLanguage = defaultLanguage;
+        }
+    }
+
+    protected String getDefaultLanguage() {
+        return this.defaultLanguage;
+    }
+
 }