List of usage examples for javax.script ScriptException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:org.apache.sling.scripting.javascript.internal.RhinoJavaScriptEngine.java
public CompiledScript compile(Reader scriptReader) throws ScriptException { final String scriptName = getScriptName(scriptReader); CachedScript cachedScript = scriptCache.getScript(scriptName); if (cachedScript != null) { LOGGER.debug("Detected cached script for {}.", scriptName); return cachedScript.getCompiledScript(); } else {//from w w w. ja v a 2s . c o m scriptReader = wrapReaderIfEspScript(scriptReader, scriptName); try { final Context rhinoContext = Context.enter(); rhinoContext.setOptimizationLevel(optimizationLevel()); if (!ScriptRuntime.hasTopCall(rhinoContext)) { // setup the context for use WrapFactory wrapFactory = ((RhinoJavaScriptEngineFactory) getFactory()).getWrapFactory(); rhinoContext.setWrapFactory(wrapFactory); } final int lineNumber = 1; final Object securityDomain = null; final Script script = rhinoContext.compileReader(scriptReader, scriptName, lineNumber, securityDomain); final SlingCompiledScript slingCompiledScript = new SlingCompiledScript(script, this); cachedScript = new CachedScript() { @Override public String getScriptPath() { return scriptName; } @Override public CompiledScript getCompiledScript() { return slingCompiledScript; } }; // SLING-4935 avoid caching scripts for which we cannot determine a name if (!scriptName.equals(NO_SCRIPT_NAME)) { scriptCache.putScript(cachedScript); } LOGGER.debug("Added {} script to Script Cache.", scriptName); return slingCompiledScript; } catch (IOException e) { final ScriptException se = new ScriptException( "Failure running script " + scriptName + ": " + e.getMessage()); se.initCause(e); throw se; } finally { Context.exit(); } } }
From source file:org.apache.synapse.mediators.bsf.NashornJavaScriptMessageContext.java
/** * Returns the parsed xml document.//from w ww. ja v a 2s .c o m * @param text xml string or document needed to be parser * @return parsed document */ public Document parseXml(String text) throws ScriptException { InputSource sax = new InputSource(new java.io.StringReader(text)); DOMParser parser = new DOMParser(); Document doc; try { parser.parse(sax); doc = parser.getDocument(); doc.getDocumentElement().normalize(); } catch (SAXException | IOException e) { ScriptException scriptException = new ScriptException("Failed to parse provided xml"); scriptException.initCause(e); throw scriptException; } return doc; }