You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2015/07/09 15:46:12 UTC
svn commit: r1690105 - in /pivot/branches/2.0.x:
core/src/org/apache/pivot/beans/
tests/src/org/apache/pivot/tests/issues/pivot949/
Author: smartini
Date: Thu Jul 9 13:46:11 2015
New Revision: 1690105
URL: http://svn.apache.org/r1690105
Log:
PIVOT-949: merge from trunk for first part of the fix (add the fallback, but without Java 7 specific features here)
Added:
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js
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=1690105&r1=1690104&r2=1690105&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 Thu Jul 9 13:46:11 2015
@@ -252,6 +252,7 @@ public class BXMLSerializer implements S
public static final char URL_PREFIX = '@';
public static final char RESOURCE_KEY_PREFIX = '%';
public static final char OBJECT_REFERENCE_PREFIX = '$';
+ public static final char SLASH_PREFIX = '/';
public static final String NAMESPACE_BINDING_PREFIX = OBJECT_REFERENCE_PREFIX + "{";
public static final String NAMESPACE_BINDING_SUFFIX = "}";
@@ -886,7 +887,7 @@ public class BXMLSerializer implements S
// Determine location from src attribute
URL locationLocal;
- if (src.charAt(0) == '/') {
+ if (src.charAt(0) == SLASH_PREFIX) {
locationLocal = classLoader.getResource(src.substring(1));
} else {
locationLocal = new URL(this.location, src);
@@ -1327,8 +1328,8 @@ public class BXMLSerializer implements S
case SCRIPT: {
String src = null;
- if (element.properties.containsKey(INCLUDE_SRC_ATTRIBUTE)) {
- src = element.properties.get(INCLUDE_SRC_ATTRIBUTE);
+ if (element.properties.containsKey(SCRIPT_SRC_ATTRIBUTE)) {
+ src = element.properties.get(SCRIPT_SRC_ATTRIBUTE);
}
if (src != null) {
@@ -1350,8 +1351,11 @@ public class BXMLSerializer implements S
try {
URL scriptLocation;
- if (src.charAt(0) == '/') {
+ if (src.charAt(0) == SLASH_PREFIX) {
scriptLocation = classLoader.getResource(src.substring(1));
+ if (scriptLocation == null) { // add a fallback
+ scriptLocation = new URL(location, src.substring(1));
+ }
} else {
scriptLocation = new URL(location, src);
}
Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java?rev=1690105&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java Thu Jul 9 13:46:11 2015
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests.issues.pivot949;
+
+import org.apache.pivot.beans.BXMLSerializer;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Window;
+
+public class Pivot949 extends Application.Adapter {
+
+ private Window window = null;
+
+ @Override
+ public void startup(Display display, Map<String, String> properties) throws Exception {
+ System.out.println("Pivot949 startup(...)");
+ System.out.println("\n"
+ + "Note that this issue is related to include scripts (with absolute path) "
+ + "from a bxml file.\n"
+ + "Here we'll test both relative and absolute scripts.\n"
+ + "\n");
+
+ BXMLSerializer bxmlSerializer = new BXMLSerializer();
+ window = (Window) bxmlSerializer.readObject(Pivot949.class, "pivot_949.bxml");
+ System.out.println("got window = " + window);
+ window.open(display);
+ }
+
+ @Override
+ public boolean shutdown(boolean b) throws Exception {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(Pivot949.class, args);
+ }
+
+}
Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml?rev=1690105&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml Thu Jul 9 13:46:11 2015
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Pivot-949" maximized="true"
+ bxml:id="window"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:app="org.apache.pivot.tests.issues"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk"
+>
+
+ <!-- <bxml:script src="utilities_script.js"/> // ok if it's in the same package/folder -->
+ <!-- <bxml:script src="../../utilities_script.js"/> // ok with a relative package/folder -->
+ <bxml:script src="../../utilities_script.js"/>
+
+ <bxml:script>
+ <![CDATA[
+ // just as a sample, to use the JavaScript just defined in the included file ...
+ log("inline script 1 - just loaded a script with a relative URI");
+
+ var nextURI = '/pivot_949.js';
+ log("inline script 1 - now try to load another script, but with an absolute URI '"
+ + nextURI + "' ...");
+ ]]>
+ </bxml:script>
+
+
+ <!-- <bxml:script src="pivot_949.js"/> // ok if it's in the same package/folder -->
+ <!-- <bxml:script src="./pivot_949.js"/> // ok if it's in the same package/folder -->
+ <bxml:script src="/pivot_949.js"/>
+ <!-- <bxml:script src="$nextURI"/> // TODO: later ... -->
+
+ <Label text="$foo"/>
+
+ <bxml:script>
+ <![CDATA[
+ // just as a sample, to use the JavaScript just defined in the included file ...
+ log("inline script 2 - all is ok");
+ ]]>
+ </bxml:script>
+
+</Window>
Added: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js?rev=1690105&view=auto
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js (added)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js Thu Jul 9 13:46:11 2015
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+importPackage(java.lang); // required to use System.out and System.err
+importPackage(org.apache.pivot.collections); // required to use Pivot class ArrayList and other collections
+importPackage(org.apache.pivot.util); // required to use Pivot Utility class Console
+importPackage(org.apache.pivot.wtk); // required to use Pivot WTK classes
+
+
+var foo = 'Hello from JavaScript in the JVM';