}
}
}
for (Element script : scripts) {
Attr src = script.getAttributeNodeNS(HTML_NS, "src");
CharProducer scriptBody;
if (src != null) {
String resourcePath = src.getNodeValue();
InputSource resource;
if (resourcePath.startsWith("/")) {
try {
resource = new InputSource(
RhinoTestBed.class.getResource(resourcePath).toURI());
} catch (URISyntaxException ex) {
throw new SomethingWidgyHappenedError(
"java.net.URL is not a valid java.net.URI", ex);
}
} else {
InputSource baseUri = Nodes.getFilePositionFor(html).source();
resource = new InputSource(baseUri.getUri().resolve(resourcePath));
}
scriptBody = loadResource(resource);
} else {
scriptBody = textContentOf(script);
}
String scriptText;
InputSource isrc = scriptBody.getSourceBreaks(0).source();
// Add blank lines at the front so that Rhino stack traces have correct
// line numbers.
scriptText = prefixWithBlankLines(
scriptBody.toString(0, scriptBody.getLimit()),
Nodes.getFilePositionFor(script).startLineNo() - 1);
scriptContent.add(Pair.pair(scriptText, isrc));
mc.addInputSource(isrc);
script.getParentNode().removeChild(script);
}