コード例 #1
0
 /*
  Compile a script as provided by the script url
 */
 private CompiledScript loadFileScript(String scriptFilePath) throws IOException, ScriptException {
   if (scriptFilePath.startsWith("http://") || scriptFilePath.startsWith("https://")) {
     // Looks like we got ourselves an absolute url
     URLConnection connection = new URL(scriptFilePath).openConnection();
     InputStream stream = connection.getInputStream();
     return engine.compile(new InputStreamReader(stream));
   } else if (scriptFilePath.startsWith("/")) {
     File file = new File(documentRoot, scriptFilePath);
     return engine.compile(new FileReader(file));
   } else {
     File file = new File(basePath, scriptFilePath);
     return engine.compile(new FileReader(file));
   }
 }
コード例 #2
0
 void initSpaceGlobal() {
   Bindings bindings = engine.createBindings();
   scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
   bindings.put("space", this);
   try {
     Scripts.LocalContext ctx = Scripts.createContext(Scripts.Space.this);
     Scripts.setContext(ctx);
     try {
       scriptContext.setAttribute(
           ScriptEngine.FILENAME, PLATYPUS_JS_FILENAME, ScriptContext.ENGINE_SCOPE);
       engine.eval(new URLReader(platypusJsUrl), scriptContext);
     } finally {
       Scripts.setContext(null);
     }
   } catch (ScriptException ex) {
     Logger.getLogger(Scripts.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
コード例 #3
0
  /* Compile a script as a text element provided as a text node or a cdata section
    or a combination
  */
  private CompiledScript loadTextScript(HTMLElement scriptElement) throws ScriptException {
    StringBuilder scriptText = new StringBuilder();
    for (HTMLNode node : scriptElement.getChildNodes()) {
      // only allowed are text nodes or cdata section
      assert (node.isText() || node.isCdataSection());

      scriptText.append(node.getNodeValue());
    }

    return engine.compile(scriptText.toString());
  }
コード例 #4
0
 public Object exec(String aSource) throws ScriptException, URISyntaxException {
   assert scriptContext != null : SCRIPT_NOT_INITIALIZED;
   return engine.eval(aSource, scriptContext);
 }
コード例 #5
0
 public Object exec(String aSourceName, URL aSourcePlace)
     throws ScriptException, URISyntaxException {
   scriptContext.setAttribute(ScriptEngine.FILENAME, aSourceName, ScriptContext.ENGINE_SCOPE);
   return engine.eval(new URLReader(aSourcePlace), scriptContext);
 }