diff --git a/core/src/org/apache/pivot/beans/BXMLSerializer.java b/core/src/org/apache/pivot/beans/BXMLSerializer.java index 64e4b58e3..2abfc0a62 100644 --- a/core/src/org/apache/pivot/beans/BXMLSerializer.java +++ b/core/src/org/apache/pivot/beans/BXMLSerializer.java @@ -252,6 +252,7 @@ public Object evaluate(final Object value) { 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 @@ private void processStartElement() throws IOException, SerializationException { // 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 @@ private void processEndElement() throws SerializationException { 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 @@ private void processEndElement() throws SerializationException { 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); } diff --git a/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java b/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java new file mode 100644 index 000000000..5b119ee8f --- /dev/null +++ b/tests/src/org/apache/pivot/tests/issues/pivot949/Pivot949.java @@ -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 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); + } + +} diff --git a/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml b/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml new file mode 100644 index 000000000..ebfee64c0 --- /dev/null +++ b/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.bxml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js b/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js new file mode 100644 index 000000000..eb3cdf0dd --- /dev/null +++ b/tests/src/org/apache/pivot/tests/issues/pivot949/pivot_949.js @@ -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';