Package javax.script

Examples of javax.script.ScriptException


          map.put((String)key, bindings.get(key));
        }
        }
      return this.expression.execute(map);
      } catch (Exception e) {
        throw new ScriptException(e);
      }
  }
View Full Code Here


    {
      return ((Compilable)compiler).compile(script);
    }
    catch(ClassCastException ex)
    {
      throw new ScriptException("Script engine for '"
                                + language + "' doesn't support CompiledScript." );
    }
   }
View Full Code Here

       return compiler;

     // No compiler created for this language. Lookup in ScriptManager
     compiler = (Compilable)scriptEngineManager.getEngineByName(language);
     if( compiler == null )
       throw new ScriptException("No compiler registered under name '" + language + "'.");

     // Add in cache
     compilers.put(language, compiler);
     return compiler;
   }
View Full Code Here

      {
      return evaluator.evaluate(script, context, Object.class, null, null);
      }
     catch (ELException ex)
      {
      throw new ScriptException(ex);
      }
   }
View Full Code Here

        } catch (JavaScriptException t) {

            // prevent variables to be pushed back in case of errors
            isTopLevelCall = false;

            final ScriptException se = new ScriptException(t.details(),
                t.sourceName(), t.lineNumber());

            // log the script stack trace
            ((Logger) bindings.get(SlingBindings.LOG)).error(t.getScriptStackTrace());

            // set the exception cause
            Object value = t.getValue();
            if (value != null) {
                if (value instanceof Wrapper) {
                    value = ((Wrapper) value).unwrap();
                }
                if (value instanceof Throwable) {
                    se.initCause((Throwable) value);
                }
            }

            // if the cause could not be set, overwrite the stack trace
            if (se.getCause() == null) {
                se.setStackTrace(t.getStackTrace());
            }

            throw se;

        } catch (Throwable t) {

            // prevent variables to be pushed back in case of errors
            isTopLevelCall = false;

            final ScriptException se = new ScriptException(
                "Failure running script " + scriptName + ": " + t.getMessage());
            se.initCause(t);
            throw se;

        } finally {

            // if we are the top call (the Context is now null) we have to
View Full Code Here

            throws ScriptException {
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);

        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        // ensure GET request
        if (helper.getRequest() != null && !"GET".equals(helper.getRequest().getMethod())) {
            throw new ScriptException(
                "JRuby scripting only supports GET requests");
        }

        final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        try {
          Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            StringBuffer scriptString = new StringBuffer();
            BufferedReader bufferedScript = new BufferedReader(script);
            String nextLine = bufferedScript.readLine();
            while (nextLine != null) {
                scriptString.append(nextLine);
                scriptString.append("\n");
                nextLine = bufferedScript.readLine();
            }

            IRubyObject scriptRubyString = JavaEmbedUtils.javaToRuby(runtime,
                scriptString.toString());
            IRubyObject erb = (IRubyObject) JavaEmbedUtils.invokeMethod(
                runtime, erbModule, "new", new Object[] { scriptRubyString },
                IRubyObject.class);

            JavaEmbedUtils.invokeMethod(runtime, erb, "set_props",
                new Object[] { JavaEmbedUtils.javaToRuby(runtime, bindings) },
                IRubyObject.class);

            IRubyObject binding = (IRubyObject) JavaEmbedUtils.invokeMethod(
                runtime, erb, "send", new Object[] { bindingSym },
                IRubyObject.class);

            scriptContext.getWriter().write(
                (String) JavaEmbedUtils.invokeMethod(runtime, erb, "result",
                    new Object[] { binding }, String.class));
        } catch (Throwable t) {
          final ScriptException ex = new ScriptException("Failure running Ruby script:" + t);
          ex.initCause(t);
          throw ex;
        } finally {
          Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
        return null;
View Full Code Here

          "Method argument scriptContext must not be null.");
    }
        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        String scriptName = helper.getScript().getScriptResource().getPath();

        final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
       
        try {
          Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         
          // initialize the Velocity context
          final VelocityContext c = new VelocityContext();
          for (Object entryObj : bindings.entrySet()) {
              Map.Entry<?, ?> entry = (Map.Entry<?, ?>) entryObj;
              c.put((String) entry.getKey(), entry.getValue());
          }
 
          // let Velocity evaluate the script, and send the output to the browser
          final String logTag = getClass().getSimpleName();
          Writer w = scriptContext.getWriter();
          try {
              velocity.evaluate(c, w, logTag, script);
          } catch (Throwable t) {
              throw new ScriptException("Failure running script " + scriptName
                  + ": " + t + ", stack trace: " + t.getStackTrace() );
          }
      } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
      }
View Full Code Here

            parser.setFeature("http://xml.org/sax/features/namespaces", false);
            parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
            parser.setProperty("http://cyberneko.org/html/properties/names/attrs", "lower");
            parser.parse(new InputSource(scriptStream));
        } catch(Exception e) {
            final ScriptException se = new ScriptException("Error parsing script " + scriptPath);
            se.initCause(e);
            throw se;
        }
        final Document template = parser.getDocument();

        // compute default rendering
        final StringWriter defaultRendering = new StringWriter();
        if(n!=null) {
            final PrintWriter pw = new PrintWriter(defaultRendering);
            htmlRenderer.render(pw, r, n, pageTitle);
            pw.flush();
        }

        // compute currentNode values in JSON format
        final StringWriter jsonData = new StringWriter();
        if(n != null) {
            final PrintWriter pw = new PrintWriter(jsonData);
            final JsonItemWriter j = new JsonItemWriter(null);
            final int maxRecursionLevels = 1;
            pw.print("var currentNode=");
            j.dump(n, pw, maxRecursionLevels);
            pw.print(";");
            pw.flush();
        }

        // run XSLT transform on script, passing parameter
        // for our computed values
        final String xslt = "/xslt/script-transform.xsl";
        InputStream xslTransform = getClass().getResourceAsStream(xslt);
        if(xslTransform == null) {
            throw new ScriptException("XSLT transform " + xslt + " not found");
        }
        try {
            final TransformerFactory tf = TransformerFactory.newInstance();
            final Transformer t = tf.newTransformer(new StreamSource(xslTransform));
            t.setParameter("pageTitle", pageTitle);
            t.setParameter("slingScriptPath", fullPath(request,SLING_JS_PATH));
            t.setParameter("jstScriptPath", fullPath(request, scriptPath + ".jst.js"));
            t.setParameter("defaultRendering", defaultRendering.toString());
            t.setParameter("jsonData", jsonData.toString());
            final Result result = new StreamResult(output);
            final DOMSource source = new DOMSource(template);
            t.transform(source, result);

        } catch (Exception e) {
            final ScriptException se = new ScriptException("Error in XSLT transform for " + scriptPath);
            se.initCause(e);
            throw se;

        } finally {
            xslTransform.close();
        }
View Full Code Here

            htmlGenerator.generateHtml(helper.getRequest(),
                    helper.getScript().getScriptResource().getPath(), scriptStream,
                    helper.getResponse().getWriter());
                   
        } catch (IOException ioe) {
            throw new ScriptException(ioe);
           
        } catch(RepositoryException re) {
            throw new ScriptException(re);
           
        } catch(JSONException je) {
            throw new ScriptException(je);
           
        } finally {
            if(scriptStream != null) {
                try {
                    scriptStream.close();
View Full Code Here

            if (session == null) {
                session = repository.loginAdministrative(null);
            }
            Node node = deepCreateNode(outDir, session, "sling:Folder");
            if (node == null) {
                throw new ScriptException("Unable to create node " + outDir);
            }
            return JcrFS.create(node);
        }
        catch (RepositoryException e) {
            throw (ScriptException) new ScriptException("Unable to create node " + outDir).initCause(e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.script.ScriptException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.