374 if (aValue.length() == 0
375 || !(aValue.startsWith(ESCAPE_PREFIX)
376 || aValue.startsWith(RELATIVE_PATH_PREFIX)
377 || aValue.startsWith(RESOURCE_KEY_PREFIX)
378 || aValue.startsWith(EXPRESSION_PREFIX)
379 || aValue.startsWith(BI_DIRECTIONAL_BINDING_PREFIX))) {
380 throw constructLoadException("Invalid escape sequence.");
381 }
382 return aValue;
383 } else if (aValue.startsWith(RELATIVE_PATH_PREFIX)) {
384 aValue = aValue.substring(RELATIVE_PATH_PREFIX.length());
385 if (aValue.length() == 0) {
386 throw constructLoadException("Missing relative path.");
387 }
388 if (aValue.startsWith(RELATIVE_PATH_PREFIX)) {
389 // The prefix was escaped
390 warnDeprecatedEscapeSequence(RELATIVE_PATH_PREFIX);
391 return aValue;
392 } else {
393 if (aValue.charAt(0) == '/') {
394 final URL res = getClassLoader().getResource(aValue.substring(1));
395 if (res == null) {
396 throw constructLoadException("Invalid resource: " + aValue + " not found on the classpath");
397 }
398 return res.toString();
399 } else {
400 try {
401 return new URL(FXMLLoader.this.location, aValue).toString();
402 } catch (MalformedURLException e) {
403 System.err.println(FXMLLoader.this.location + "/" + aValue);
404 }
405 }
406 }
407 } else if (aValue.startsWith(RESOURCE_KEY_PREFIX)) {
408 aValue = aValue.substring(RESOURCE_KEY_PREFIX.length());
409 if (aValue.length() == 0) {
410 throw constructLoadException("Missing resource key.");
411 }
412 if (aValue.startsWith(RESOURCE_KEY_PREFIX)) {
413 // The prefix was escaped
1096 }
1097
1098 charset = Charset.forName(value);
1099 } else {
1100 super.processAttribute(prefix, localName, value);
1101 }
1102 } else {
1103 super.processAttribute(prefix, localName, value);
1104 }
1105 }
1106
1107 @Override
1108 public Object constructValue() throws IOException {
1109 if (source == null) {
1110 throw constructLoadException(INCLUDE_SOURCE_ATTRIBUTE + " is required.");
1111 }
1112
1113 URL location;
1114 final ClassLoader cl = getClassLoader();
1115 if (source.charAt(0) == '/') {
1116 location = cl.getResource(source.substring(1));
1117 if (location == null) {
1118 throw constructLoadException("Cannot resolve path: " + source);
1119 }
1120 } else {
1121 if (FXMLLoader.this.location == null) {
1122 throw constructLoadException("Base location is undefined.");
1123 }
1124
1125 location = new URL(FXMLLoader.this.location, source);
1126 }
1127
1128 FXMLLoader fxmlLoader = new FXMLLoader(location, resources,
1129 builderFactory, controllerFactory, charset,
1130 loaders);
1131 fxmlLoader.parentLoader = FXMLLoader.this;
1132
1133 if (isCyclic(FXMLLoader.this, fxmlLoader)) {
1134 throw new IOException(
1135 String.format(
1520 engine = scriptEngine;
1521 } else {
1522 ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
1523 try {
1524 Thread.currentThread().setContextClassLoader(cl);
1525 ScriptEngineManager scriptEngineManager = getScriptEngineManager();
1526 engine = scriptEngineManager.getEngineByExtension(extension);
1527 } finally {
1528 Thread.currentThread().setContextClassLoader(oldLoader);
1529 }
1530 }
1531
1532 if (engine == null) {
1533 throw constructLoadException("Unable to locate scripting engine for"
1534 + " extension " + extension + ".");
1535 }
1536
1537 try {
1538 URL location;
1539 if (source.charAt(0) == '/') {
1540 location = cl.getResource(source.substring(1));
1541 } else {
1542 if (FXMLLoader.this.location == null) {
1543 throw constructLoadException("Base location is undefined.");
1544 }
1545
1546 location = new URL(FXMLLoader.this.location, source);
1547 }
1548
1549 InputStreamReader scriptReader = null;
1550 try {
1551 scriptReader = new InputStreamReader(location.openStream(), charset);
1552 engine.eval(scriptReader);
1553 } catch(ScriptException exception) {
1554 exception.printStackTrace();
1555 } finally {
1556 if (scriptReader != null) {
1557 scriptReader.close();
1558 }
1559 }
|
374 if (aValue.length() == 0
375 || !(aValue.startsWith(ESCAPE_PREFIX)
376 || aValue.startsWith(RELATIVE_PATH_PREFIX)
377 || aValue.startsWith(RESOURCE_KEY_PREFIX)
378 || aValue.startsWith(EXPRESSION_PREFIX)
379 || aValue.startsWith(BI_DIRECTIONAL_BINDING_PREFIX))) {
380 throw constructLoadException("Invalid escape sequence.");
381 }
382 return aValue;
383 } else if (aValue.startsWith(RELATIVE_PATH_PREFIX)) {
384 aValue = aValue.substring(RELATIVE_PATH_PREFIX.length());
385 if (aValue.length() == 0) {
386 throw constructLoadException("Missing relative path.");
387 }
388 if (aValue.startsWith(RELATIVE_PATH_PREFIX)) {
389 // The prefix was escaped
390 warnDeprecatedEscapeSequence(RELATIVE_PATH_PREFIX);
391 return aValue;
392 } else {
393 if (aValue.charAt(0) == '/') {
394 // FIXME: JIGSAW -- use Class.getResourceAsStream if resource is in a module
395 final URL res = getClassLoader().getResource(aValue.substring(1));
396 if (res == null) {
397 throw constructLoadException("Invalid resource: " + aValue + " not found on the classpath");
398 }
399 return res.toString();
400 } else {
401 try {
402 return new URL(FXMLLoader.this.location, aValue).toString();
403 } catch (MalformedURLException e) {
404 System.err.println(FXMLLoader.this.location + "/" + aValue);
405 }
406 }
407 }
408 } else if (aValue.startsWith(RESOURCE_KEY_PREFIX)) {
409 aValue = aValue.substring(RESOURCE_KEY_PREFIX.length());
410 if (aValue.length() == 0) {
411 throw constructLoadException("Missing resource key.");
412 }
413 if (aValue.startsWith(RESOURCE_KEY_PREFIX)) {
414 // The prefix was escaped
1097 }
1098
1099 charset = Charset.forName(value);
1100 } else {
1101 super.processAttribute(prefix, localName, value);
1102 }
1103 } else {
1104 super.processAttribute(prefix, localName, value);
1105 }
1106 }
1107
1108 @Override
1109 public Object constructValue() throws IOException {
1110 if (source == null) {
1111 throw constructLoadException(INCLUDE_SOURCE_ATTRIBUTE + " is required.");
1112 }
1113
1114 URL location;
1115 final ClassLoader cl = getClassLoader();
1116 if (source.charAt(0) == '/') {
1117 // FIXME: JIGSAW -- use Class.getResourceAsStream if resource is in a module
1118 location = cl.getResource(source.substring(1));
1119 if (location == null) {
1120 throw constructLoadException("Cannot resolve path: " + source);
1121 }
1122 } else {
1123 if (FXMLLoader.this.location == null) {
1124 throw constructLoadException("Base location is undefined.");
1125 }
1126
1127 location = new URL(FXMLLoader.this.location, source);
1128 }
1129
1130 FXMLLoader fxmlLoader = new FXMLLoader(location, resources,
1131 builderFactory, controllerFactory, charset,
1132 loaders);
1133 fxmlLoader.parentLoader = FXMLLoader.this;
1134
1135 if (isCyclic(FXMLLoader.this, fxmlLoader)) {
1136 throw new IOException(
1137 String.format(
1522 engine = scriptEngine;
1523 } else {
1524 ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
1525 try {
1526 Thread.currentThread().setContextClassLoader(cl);
1527 ScriptEngineManager scriptEngineManager = getScriptEngineManager();
1528 engine = scriptEngineManager.getEngineByExtension(extension);
1529 } finally {
1530 Thread.currentThread().setContextClassLoader(oldLoader);
1531 }
1532 }
1533
1534 if (engine == null) {
1535 throw constructLoadException("Unable to locate scripting engine for"
1536 + " extension " + extension + ".");
1537 }
1538
1539 try {
1540 URL location;
1541 if (source.charAt(0) == '/') {
1542 // FIXME: JIGSAW -- use Class.getResourceAsStream if resource is in a module
1543 location = cl.getResource(source.substring(1));
1544 } else {
1545 if (FXMLLoader.this.location == null) {
1546 throw constructLoadException("Base location is undefined.");
1547 }
1548
1549 location = new URL(FXMLLoader.this.location, source);
1550 }
1551
1552 InputStreamReader scriptReader = null;
1553 try {
1554 scriptReader = new InputStreamReader(location.openStream(), charset);
1555 engine.eval(scriptReader);
1556 } catch(ScriptException exception) {
1557 exception.printStackTrace();
1558 } finally {
1559 if (scriptReader != null) {
1560 scriptReader.close();
1561 }
1562 }
|