mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Clean up luaj scripting engine; allow multiple lua library files
This commit is contained in:
parent
c1d84249e1
commit
d07b3e1493
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/luaj-vm"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/100_core"/>
|
||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/140_dbs"/>
|
||||
|
@ -15,8 +15,8 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.scripts; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public interface Gfh_script_engine {
|
||||
package gplx.core.scripts; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_script_engine {
|
||||
void Load_script(Io_url url);
|
||||
Object Get_object(String obj_name);
|
||||
void Put_object(String name, Object obj);
|
@ -15,17 +15,17 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.scripts; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_script_engine_ {
|
||||
public static Gfh_script_engine New_by_key(String key) {
|
||||
if (String_.Eq(key, "javascript.java")) return new Gfh_script_engine__javascript();
|
||||
else if (String_.Eq(key, "lua.luaj")) return new Gfh_script_engine__luaj();
|
||||
else if (String_.Eq(key, "noop")) return new Gfh_script_engine__noop();
|
||||
package gplx.core.scripts; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_script_engine_ {
|
||||
public static Gfo_script_engine New_by_key(String key) {
|
||||
if (String_.Eq(key, "javascript.java")) return new Gfo_script_engine__javascript();
|
||||
else if (String_.Eq(key, "lua.luaj")) return new Gfo_script_engine__luaj();
|
||||
else if (String_.Eq(key, "noop")) return new Gfo_script_engine__noop();
|
||||
else throw Err_.new_unhandled(key);
|
||||
}
|
||||
public static Gfh_script_engine New_by_ext(String ext) {
|
||||
if (String_.Eq(ext, ".js")) return new Gfh_script_engine__javascript();
|
||||
else if (String_.Eq(ext, ".lua")) return new Gfh_script_engine__luaj();
|
||||
public static Gfo_script_engine New_by_ext(String ext) {
|
||||
if (String_.Eq(ext, ".js")) return new Gfo_script_engine__javascript();
|
||||
else if (String_.Eq(ext, ".lua")) return new Gfo_script_engine__luaj();
|
||||
else throw Err_.new_unhandled(ext);
|
||||
}
|
||||
}
|
@ -15,14 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.scripts; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
package gplx.core.scripts; import gplx.*; import gplx.core.*;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
public class Gfh_script_engine__javascript implements Gfh_script_engine {
|
||||
public class Gfo_script_engine__javascript implements Gfo_script_engine {
|
||||
private final ScriptEngine engine;
|
||||
private final Invocable invk;
|
||||
public Gfh_script_engine__javascript() {
|
||||
public Gfo_script_engine__javascript() {
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
this.engine = manager.getEngineByName("JavaScript");
|
||||
this.invk = (Invocable)engine;
|
99
400_xowa/src/gplx/core/scripts/Gfo_script_engine__luaj.java
Normal file
99
400_xowa/src/gplx/core/scripts/Gfo_script_engine__luaj.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.scripts; import gplx.*; import gplx.core.*;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
|
||||
import javax.script.SimpleBindings;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
||||
import org.luaj.vm2.lib.jse.CoerceLuaToJava;
|
||||
public class Gfo_script_engine__luaj implements Gfo_script_engine {
|
||||
private final ScriptEngine engine;
|
||||
private final List_adp script_list = List_adp_.New();
|
||||
private SimpleBindings bindings;
|
||||
public Gfo_script_engine__luaj() {
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
this.engine = manager.getEngineByName("luaj");
|
||||
}
|
||||
public void Load_script(Io_url url) {
|
||||
try {
|
||||
// create itm and add it to the list of all scripts; list is not used now, but may be used in future
|
||||
String src = Io_mgr.Instance.LoadFilStr(url);
|
||||
script_list.Add(new Gfo_script_itm__luaj(url, src));
|
||||
|
||||
// compile the item into the "bindings" object; this allows scripts to share one "sandbox-space", allowing funcs in one script to call funcs in another
|
||||
CompiledScript compiled = ((Compilable) engine).compile(src);
|
||||
if (bindings == null) bindings = new SimpleBindings();
|
||||
compiled.eval(bindings);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Warn("failed to load_script; url=~{0} err=~{1}", url, Err_.Message_lang(e));
|
||||
}
|
||||
}
|
||||
public void Put_object(String key, Object val) {
|
||||
engine.put(key, val);
|
||||
}
|
||||
public Object Get_object(String obj_name) {
|
||||
try {return engine.get(obj_name);}
|
||||
catch (Exception e) {
|
||||
Warn("failed to get object; obj_name=~{0} err=~{1}", obj_name, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object Eval_script(String script) {
|
||||
try {return engine.eval(script);}
|
||||
catch (Exception e) {
|
||||
Warn("", "", "failed to eval; script=~{0} err=~{1}", script, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object Invoke_method(Object obj, String func, Object... args) {
|
||||
throw Err_.new_unimplemented_w_msg("luaj does not support invocable interface"); // NOTE: cannot support with Get_object, b/c Get_object needs obj_name, and only "obj" exists
|
||||
}
|
||||
public Object Invoke_function(String func, Object... args) {
|
||||
try {
|
||||
LuaValue arg = CoerceJavaToLua.coerce(args[0]);
|
||||
LuaFunction lfunc = (LuaFunction)bindings.get(func);
|
||||
LuaValue rv = lfunc.call(arg);
|
||||
return CoerceLuaToJava.coerce(rv, Object.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Gfo_script_engine__luaj.Warn("", "", "failed to invoke method; method=~{0} err=~{1}", func, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static void Warn(String fmt, Object... args) {
|
||||
String msg = Gfo_usr_dlg_.Instance.Warn_many("", "", fmt, args);
|
||||
System.out.println(msg);
|
||||
}
|
||||
}
|
||||
class Gfo_script_itm__luaj {
|
||||
public Gfo_script_itm__luaj(Io_url url, String src) {
|
||||
this.url = url;
|
||||
this.src = src;
|
||||
}
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public String Src() {return src;} private final String src;
|
||||
}
|
@ -15,8 +15,8 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.scripts; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
public class Gfh_script_engine__noop implements Gfh_script_engine {
|
||||
package gplx.core.scripts; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_script_engine__noop implements Gfo_script_engine {
|
||||
public void Load_script(Io_url url) {}
|
||||
public Object Get_object(String obj_name) {return null;}
|
||||
public void Put_object(String name, Object obj) {}
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.langs.htmls.scripts; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.SimpleBindings;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
|
||||
import org.luaj.vm2.LuaClosure;
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
||||
public class Gfh_script_engine__luaj implements Gfh_script_engine {
|
||||
private final ScriptEngine engine;
|
||||
// private final Invocable invk;
|
||||
String sss = "";
|
||||
public Gfh_script_engine__luaj() {
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
this.engine = manager.getEngineByName("luaj");
|
||||
// this.invk = (Invocable)engine;
|
||||
}
|
||||
public void Load_script(Io_url url) {
|
||||
try {
|
||||
sss = Io_mgr.Instance.LoadFilStr(url);
|
||||
engine.eval(sss);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to load_script; url=~{0} err=~{1}", url, Err_.Message_lang(e));
|
||||
}
|
||||
}
|
||||
public void Put_object(String key, Object val) {
|
||||
engine.put(key, val);
|
||||
}
|
||||
public Object Get_object(String obj_name) {
|
||||
try {return engine.get(obj_name);}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to get object; obj_name=~{0} err=~{1}", obj_name, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object Eval_script(String script) {
|
||||
try {return engine.eval(script);}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to eval; script=~{0} err=~{1}", script, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object Invoke_method(Object obj, String func, Object... args) {
|
||||
try {
|
||||
CompiledScript script = ((Compilable) engine).compile(sss);
|
||||
Bindings sb = new SimpleBindings();
|
||||
script.eval(sb);
|
||||
// LuaTable lfunc = (LuaTable)sb.get("xo_script");
|
||||
// LuaClosure lfunc2 = (LuaClosure)lfunc.get(func);
|
||||
LuaValue arg = CoerceJavaToLua.coerce(args[0]);
|
||||
LuaFunction lfunc = (LuaFunction)sb.get("write_end");
|
||||
lfunc.call(arg);
|
||||
return null;
|
||||
// return engine.eval(obj);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to invoke method; method=~{0} err=~{1}", func, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object Invoke_function(String func, Object... args) {
|
||||
try {
|
||||
CompiledScript script = ((Compilable) engine).compile(sss);
|
||||
Bindings sb = new SimpleBindings();
|
||||
script.eval(sb);
|
||||
// LuaTable lfunc = (LuaTable)sb.get("xo_script");
|
||||
// LuaClosure lfunc2 = (LuaClosure)lfunc.get(func);
|
||||
LuaValue arg = CoerceJavaToLua.coerce(args[0]);
|
||||
LuaFunction lfunc = (LuaFunction)sb.get(func);
|
||||
lfunc.call(arg);
|
||||
return null;
|
||||
// return engine.eval(obj);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to invoke method; method=~{0} err=~{1}", func, Err_.Message_lang(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,12 +15,12 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
package gplx.xowa.addons.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
public class Xoscript_env {
|
||||
private final Gfh_script_engine engine;
|
||||
public Xoscript_env(Gfh_script_engine engine, Io_url root_dir) {
|
||||
private final Gfo_script_engine engine;
|
||||
public Xoscript_env(Gfo_script_engine engine, Io_url root_dir) {
|
||||
this.root_dir = root_dir;
|
||||
this.engine = engine;
|
||||
}
|
@ -15,13 +15,12 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.core.scripts.*;
|
||||
import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.htmls.scripts.apis.*; import gplx.xowa.addons.htmls.scripts.xtns.*;
|
||||
import gplx.xowa.addons.apps.scripts.apis.*; import gplx.xowa.addons.apps.scripts.xtns.*;
|
||||
public class Xoscript_mgr {
|
||||
private Io_url root_dir;
|
||||
// private Io_url[] script_urls; private int script_urls_len;
|
||||
private Xoscript_xtn_mgr xtn_mgr;
|
||||
public void Init(Xow_wiki wiki) {
|
||||
// check script_dir
|
||||
@ -31,30 +30,11 @@ public class Xoscript_mgr {
|
||||
}
|
||||
public void Write(Bry_bfr rv, Xow_wiki wiki, Xoa_page page) {
|
||||
// init
|
||||
if (!wiki.App().Api_root().Addon().App__scripting__enabled()) return;
|
||||
this.Init(wiki);
|
||||
if (xtn_mgr == null) return;
|
||||
|
||||
xtn_mgr.Load_root();
|
||||
xtn_mgr.Run(rv, wiki, page);
|
||||
|
||||
// // create engine and load scripts
|
||||
// Gfh_script_engine engine = new Gfh_script_engine__luaj();
|
||||
// engine.Put_object("xolog", new Xoscript_log());
|
||||
// for (int i = 0; i < script_urls_len; ++i) {
|
||||
// engine.Load_script(script_urls[i]);
|
||||
// }
|
||||
//
|
||||
// // call script
|
||||
// Xoscript_env env = new Xoscript_env(engine, root_dir);
|
||||
// engine.Invoke_function("xoscript__init", env);
|
||||
//
|
||||
// Xoscript_page spg = new Xoscript_page(rv, env, new Xoscript_url(page.Wiki().Domain_str(), String_.new_u8(page.Url().Page_bry())));
|
||||
// engine.Invoke_function("xoscript__page_write_end", spg);
|
||||
//
|
||||
// // overwrite html
|
||||
// if (spg.doc().dirty()) {
|
||||
// rv.Clear();
|
||||
// rv.Add_str_u8(spg.doc().html());
|
||||
// }
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc {
|
||||
private final Bry_bfr bfr;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
@ -25,8 +25,8 @@ public class Xoscript_doc {
|
||||
this.head_var = new Xoscript_doc_head(this);
|
||||
this.tail_var = new Xoscript_doc_tail(this);
|
||||
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.TOP-->", "top", Xoscript_doc_sect_base.Pos__default);
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.BOT-->", "bot");
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.TOP-->", "top");
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.BOT-->", "bot", Xoscript_doc_sect_base.Pos__default);
|
||||
tail_var.reg_marker("<!--XOWA.SCRIPT.TAIL.TOP-->", "top", Xoscript_doc_sect_base.Pos__default);
|
||||
}
|
||||
public Xoscript_page page() {return page_var;} private final Xoscript_page page_var;
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc_head extends Xoscript_doc_sect_base {
|
||||
public Xoscript_doc_head(Xoscript_doc doc) {super(doc);}
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoscript_doc_head__tst {
|
||||
private final Xoscript_doc_head__fxt fxt = new Xoscript_doc_head__fxt();
|
||||
@ -52,7 +52,7 @@ class Xoscript_doc_head__fxt {
|
||||
private Xoscript_doc_sect_base sect;
|
||||
public Xoscript_doc_head__fxt() {
|
||||
Bry_bfr rv = Bry_bfr_.New();
|
||||
Xoscript_env env = new Xoscript_env(new gplx.langs.htmls.scripts.Gfh_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
|
||||
Xoscript_env env = new Xoscript_env(new gplx.core.scripts.Gfo_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
|
||||
Xoscript_url url = new Xoscript_url("test_wiki", "test_page");
|
||||
spg = new Xoscript_page(rv, env, url);
|
||||
}
|
||||
@ -67,7 +67,7 @@ class Xoscript_doc_head__fxt {
|
||||
public void Exec__add_js_file(String pos, String file) {sect.add_js_file(pos, file);}
|
||||
public void Exec__add_html(String html) {sect.add_html(html);}
|
||||
public void Exec__add_html(String pos, String html) {sect.add_html(pos, html);}
|
||||
public void Exec__add_tag(String pos, String tag, String body, String... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
|
||||
public void Exec__add_tag(String pos, String tag, String body, Object... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
|
||||
public void Test__html(String... expd) {
|
||||
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), spg.doc().html(), "html");
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public abstract class Xoscript_doc_sect_base {
|
||||
protected final Xoscript_doc doc;
|
||||
private final Hash_adp_bry marker_hash = Hash_adp_bry.cs();
|
||||
@ -79,5 +79,5 @@ public abstract class Xoscript_doc_sect_base {
|
||||
public void add_css_code(String pos_str, String code_str) {
|
||||
add_tag(pos_str, "style", code_str, "type", "text/css");
|
||||
}
|
||||
public static final String Pos__default = "default", Body__empty = "";
|
||||
public static final String Pos__default = "", Body__empty = "";
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc_tail extends Xoscript_doc_sect_base {
|
||||
public Xoscript_doc_tail(Xoscript_doc doc) {super(doc);}
|
||||
}
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_log {
|
||||
public void log(String... v) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", String_.Concat_with_str(" ", v));
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_page {
|
||||
public Xoscript_page(Bry_bfr rv, Xoscript_env env_var, Xoscript_url url_var) {
|
||||
this.env_var = env_var;
|
@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_url {
|
||||
public Xoscript_url(String wiki_name_var, String page_name_var) {this.wiki_name_var = wiki_name_var; this.page_name_var = page_name_var;}
|
||||
public String wiki_name() {return wiki_name_var;} private final String wiki_name_var;
|
@ -15,15 +15,15 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
public class Xoscript_xtn_itm {
|
||||
public Xoscript_xtn_itm(String key, Io_url url, Gfh_script_engine engine) {
|
||||
public Xoscript_xtn_itm(String key, Io_url url, Gfo_script_engine engine) {
|
||||
this.key = key;
|
||||
this.url = url;
|
||||
this.engine = engine;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Gfh_script_engine Engine() {return engine;} private final Gfh_script_engine engine;
|
||||
public Gfo_script_engine Engine() {return engine;} private final Gfo_script_engine engine;
|
||||
}
|
@ -15,9 +15,9 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
import gplx.xowa.addons.htmls.scripts.apis.*;
|
||||
package gplx.xowa.addons.apps.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
import gplx.xowa.addons.apps.scripts.apis.*;
|
||||
public class Xoscript_xtn_mgr {
|
||||
private Xoscript_xtn_itm root_itm;
|
||||
private final Io_url root_dir;
|
||||
@ -27,7 +27,7 @@ public class Xoscript_xtn_mgr {
|
||||
}
|
||||
public void reg_xtn(String key, String file) {
|
||||
Io_url url = Io_url_.new_fil_(Xoscript_env.Resolve_file(Bool_.N, root_dir, file));
|
||||
Xoscript_xtn_itm itm = new Xoscript_xtn_itm(key, url, Gfh_script_engine_.New_by_ext(url.Ext()));
|
||||
Xoscript_xtn_itm itm = new Xoscript_xtn_itm(key, url, Gfo_script_engine_.New_by_ext(url.Ext()));
|
||||
hash.Add(key, itm);
|
||||
}
|
||||
public void Load_root() {
|
||||
@ -37,7 +37,7 @@ public class Xoscript_xtn_mgr {
|
||||
Io_url root_url = root_urls[0];
|
||||
String root_name_and_ext = root_url.NameAndExt();
|
||||
if (String_.EqAny(root_name_and_ext, "xowa.script.main.js", "xowa.script.main.lua")) {
|
||||
this.root_itm = new Xoscript_xtn_itm("xowa.root", root_url, Gfh_script_engine_.New_by_ext(root_url.Ext()));
|
||||
this.root_itm = new Xoscript_xtn_itm("xowa.root", root_url, Gfo_script_engine_.New_by_ext(root_url.Ext()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -49,13 +49,15 @@ public class Xoscript_xtn_mgr {
|
||||
Xoscript_log log = new Xoscript_log();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoscript_xtn_itm itm = (Xoscript_xtn_itm)hash.Get_at(i);
|
||||
Gfh_script_engine engine = (Gfh_script_engine)itm.Engine();
|
||||
Gfo_script_engine engine = (Gfo_script_engine)itm.Engine();
|
||||
Xoscript_env env = new Xoscript_env(engine, itm.Url().OwnerDir());
|
||||
Xoscript_page spg = new Xoscript_page(rv, env, new Xoscript_url(page.Wiki().Domain_str(), String_.new_u8(page.Url().Page_bry())));
|
||||
engine.Put_object("xolog", log);
|
||||
engine.Load_script(itm.Url());
|
||||
engine.Invoke_function("xoscript__init", env);
|
||||
engine.Invoke_function("xoscript__page_write_end", spg);
|
||||
try {engine.Invoke_function("xoscript__init", env);}
|
||||
catch (Exception e) {Gfo_usr_dlg_.Instance.Note_many("", "", "xoscript__init failed; url=~{0} err=~{1}", itm.Url(), Err_.Message_lang(e));}
|
||||
try {engine.Invoke_function("xoscript__page_write_end", spg);}
|
||||
catch (Exception e) {Gfo_usr_dlg_.Instance.Note_many("", "", "xoscript__page_write_end failed; url=~{0} err=~{1}", itm.Url(), Err_.Message_lang(e));}
|
||||
|
||||
// overwrite html
|
||||
if (spg.doc().dirty()) {
|
@ -22,16 +22,21 @@ public class Xoapi_addon implements Gfo_invk {
|
||||
public Xoapi_addon_search Search() {return search;} private final Xoapi_addon_search search = new Xoapi_addon_search();
|
||||
public Xoapi_addon_bldr Bldr() {return bldr;} private final Xoapi_addon_bldr bldr = new Xoapi_addon_bldr();
|
||||
public boolean Wikis__ctgs__hidden_enabled() {return wikis__ctgs__hidden_enabled;} private boolean wikis__ctgs__hidden_enabled = false;
|
||||
public boolean App__scripting__enabled() {return app__scripting__enabled;} private boolean app__scripting__enabled = false;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__search)) return search;
|
||||
else if (ctx.Match(k, Invk__bldr)) return bldr;
|
||||
else if (ctx.Match(k, Invk__wikis__ctgs__hidden_enabled)) return Yn.To_str(wikis__ctgs__hidden_enabled);
|
||||
else if (ctx.Match(k, Invk__wikis__ctgs__hidden_enabled_)) wikis__ctgs__hidden_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk__app__scripting__enabled)) return Yn.To_str(app__scripting__enabled);
|
||||
else if (ctx.Match(k, Invk__app__scripting__enabled_)) app__scripting__enabled = m.ReadYn("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk__search = "search", Invk__bldr = "bldr"
|
||||
, Invk__wikis__ctgs__hidden_enabled = "wikis__ctgs__hidden_enabled"
|
||||
, Invk__wikis__ctgs__hidden_enabled_ = "wikis__ctgs__hidden_enabled_"
|
||||
, Invk__app__scripting__enabled = "app__scripting__enabled"
|
||||
, Invk__app__scripting__enabled_ = "app__scripting__enabled_"
|
||||
;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class Xoh_page_wtr_wkr {
|
||||
hctx = Xoh_wtr_ctx.Basic;
|
||||
Write_body(page_bfr, ctx, hctx, page);
|
||||
Write_page_by_tid(ctx, hctx, view_mode, rv, fmtr, page_bfr.To_bry_and_rls());
|
||||
new gplx.xowa.addons.htmls.scripts.Xoscript_mgr().Write(rv, wiki, page);
|
||||
new gplx.xowa.addons.apps.scripts.Xoscript_mgr().Write(rv, wiki, page);
|
||||
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(rv.To_bry_and_clear()));
|
||||
wdata_lang_wtr.Page_(null);
|
||||
|
Loading…
Reference in New Issue
Block a user