mirror of https://github.com/gnosygnu/xowa
parent
b7f089a3ab
commit
c98404a8fe
@ -1,57 +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.xowa.addons.htmls.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
|
||||||
import gplx.xowa.wikis.pages.tags.*;
|
|
||||||
public class Xoh_include_mgr {
|
|
||||||
private Io_url[] main_urls; private int main_urls_len;
|
|
||||||
public void Init(Xow_wiki wiki) {
|
|
||||||
// check bin dir
|
|
||||||
Io_url include_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("bin", "html", "include");
|
|
||||||
if (!Io_mgr.Instance.ExistsDir(include_dir)) return;
|
|
||||||
|
|
||||||
this.main_urls = Io_mgr.Instance.QueryDir_args(include_dir).FilPath_("*.js").ExecAsUrlAry();
|
|
||||||
this.main_urls_len = main_urls.length;
|
|
||||||
if (main_urls_len == 0) {
|
|
||||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "no '.js' files found; dir=~{0}", include_dir.Raw());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void Write(Xow_wiki wiki, Xoa_page page) {
|
|
||||||
this.Init(wiki);
|
|
||||||
if (main_urls_len == 0) return;
|
|
||||||
|
|
||||||
// create engine and load scripts
|
|
||||||
Script_engine engine = new Script_engine__java();
|
|
||||||
for (int i = 0; i < main_urls_len; ++i) {
|
|
||||||
engine.Load_script(main_urls[i]);
|
|
||||||
}
|
|
||||||
// engine.Put_object("page", new Xoscript_page())
|
|
||||||
Xoscript_page xos_pg = new Xoscript_page();
|
|
||||||
|
|
||||||
Object xowa_script = engine.Get_object("xowa_script");
|
|
||||||
// engine.Invoke_method(xowa_script, "main", page.Url().To_str());
|
|
||||||
engine.Invoke_method(xowa_script, "main", xos_pg);
|
|
||||||
// if (String_.Has(rv, "yes")) {
|
|
||||||
// Io_url js_url = null;
|
|
||||||
// page.Html_data().Custom_head_tags().Add(Xopg_tag_itm.New_js_file(js_url));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
// public static Xoh_include_mgr Get_or_new(Xow_wiki wiki) {
|
|
||||||
// wiki.Addon_mgr().Itms__get_or_null();
|
|
||||||
// }
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
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.xowa.addons.htmls.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||||
|
import gplx.langs.htmls.scripts.*;
|
||||||
|
import gplx.xowa.wikis.pages.tags.*;
|
||||||
|
import gplx.xowa.addons.htmls.scripts.apis.*;
|
||||||
|
public class Xoscript_mgr {
|
||||||
|
private Io_url root_dir;
|
||||||
|
private Io_url[] script_urls; private int script_urls_len;
|
||||||
|
public void Init(Xow_wiki wiki) {
|
||||||
|
// check script_dir
|
||||||
|
this.root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("bin", "html", "script");
|
||||||
|
if (!Io_mgr.Instance.ExistsDir(root_dir)) return;
|
||||||
|
|
||||||
|
// xowa.boot.js
|
||||||
|
// find script urls
|
||||||
|
this.script_urls = Io_mgr.Instance.QueryDir_args(root_dir).FilPath_("*.js").ExecAsUrlAry();
|
||||||
|
this.script_urls_len = script_urls.length;
|
||||||
|
if (script_urls_len == 0) {
|
||||||
|
Gfo_usr_dlg_.Instance.Warn_many("", "", "xoscript:no '.js' files found; dir=~{0}", root_dir.Raw());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Write(Bry_bfr rv, Xow_wiki wiki, Xoa_page page) {
|
||||||
|
// init
|
||||||
|
this.Init(wiki);
|
||||||
|
if (script_urls_len == 0) return;
|
||||||
|
|
||||||
|
// create engine and load scripts
|
||||||
|
Gfh_script_engine engine = new Gfh_script_engine__java();
|
||||||
|
for (int i = 0; i < script_urls_len; ++i) {
|
||||||
|
engine.Load_script(script_urls[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// call script
|
||||||
|
Object xowa_script = engine.Get_object("xowa_script");
|
||||||
|
Xoscript_env env = new Xoscript_env(root_dir);
|
||||||
|
Xoscript_page spg = new Xoscript_page(rv, env, new Xoscript_url(page.Wiki().Domain_str(), String_.new_u8(page.Url().Page_bry())));
|
||||||
|
engine.Invoke_method(xowa_script, "main", spg);
|
||||||
|
|
||||||
|
// overwrite html
|
||||||
|
if (spg.Doc().Dirty()) {
|
||||||
|
rv.Clear();
|
||||||
|
rv.Add_str_u8(spg.Doc().Html());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
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.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.*;
|
||||||
|
public class Xoscript_doc {
|
||||||
|
private final Bry_bfr bfr;
|
||||||
|
public Xoscript_doc(Bry_bfr bfr, Xoscript_page page) {
|
||||||
|
this.bfr = bfr;
|
||||||
|
this.page = page;
|
||||||
|
this.head = new Xoscript_doc_head(this);
|
||||||
|
this.tail = new Xoscript_doc_tail(this);
|
||||||
|
}
|
||||||
|
public Xoscript_page Page() {return page;} private final Xoscript_page page;
|
||||||
|
public Xoscript_doc_head Head() {return head;} private final Xoscript_doc_head head;
|
||||||
|
public Xoscript_doc_tail Tail() {return tail;} private final Xoscript_doc_tail tail;
|
||||||
|
public String Html() {
|
||||||
|
if (html == null) {
|
||||||
|
html = bfr.To_str();
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
} private String html;
|
||||||
|
public void Html_(String s) {
|
||||||
|
html = s;
|
||||||
|
html_dirty = true;
|
||||||
|
}
|
||||||
|
public boolean Dirty() {
|
||||||
|
return html_dirty;
|
||||||
|
} private boolean html_dirty;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
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.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.*;
|
||||||
|
public class Xoscript_doc_head {
|
||||||
|
private final Xoscript_doc doc;
|
||||||
|
public Xoscript_doc_head(Xoscript_doc doc) {this.doc = doc;}
|
||||||
|
public void Add_js_file(String file, String pos) {
|
||||||
|
String marker = String_.Eq(pos, "top") ? "<!--XOWA.SCRIPT.HEAD.TOP-->" : "<!--XOWA.SCRIPT.HEAD.BOT-->";
|
||||||
|
if (String_.Has_at_bgn(file, "./")) file = String_.Replace(file, "./", doc.Page().Env().Root_dir().To_http_file_str());
|
||||||
|
String elem = "<script src=\"" + file + "\" type=\"text/javascript\"></script>\n";
|
||||||
|
doc.Html_(String_.Replace(doc.Html(), marker, marker + elem));
|
||||||
|
}
|
||||||
|
public void Add_elem(String elem, String pos) {
|
||||||
|
String marker = String_.Eq(pos, "top") ? "<!--XOWA.SCRIPT.HEAD.TOP-->" : "<!--XOWA.SCRIPT.HEAD.BOT-->";
|
||||||
|
doc.Html_(String_.Replace(doc.Html(), marker, marker + elem));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
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.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.*;
|
||||||
|
public class Xoscript_doc_tail {
|
||||||
|
private final Xoscript_doc doc;
|
||||||
|
public Xoscript_doc_tail(Xoscript_doc doc) {this.doc = doc;}
|
||||||
|
public void Add_js_file(String file, String pos) {
|
||||||
|
String marker = String_.Eq(pos, "top") ? "<!--XOWA.SCRIPT.TAIL-->" : "<!--XOWA.SCRIPT.TAIL-->";
|
||||||
|
if (String_.Has_at_bgn(file, "./")) file = String_.Replace(file, "./", doc.Page().Env().Root_dir().To_http_file_str());
|
||||||
|
String elem = "<script src=\"" + file + "\" type=\"text/javascript\"></script>\n";
|
||||||
|
doc.Html_(String_.Replace(doc.Html(), marker, marker + elem));
|
||||||
|
}
|
||||||
|
public void Add_elem(String elem, String pos) {
|
||||||
|
String marker = String_.Eq(pos, "top") ? "<!--XOWA.SCRIPT.TAIL-->" : "<!--XOWA.SCRIPT.TAIL-->";
|
||||||
|
doc.Html_(String_.Replace(doc.Html(), marker, marker + elem));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
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.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.*;
|
||||||
|
public class Xoscript_page {
|
||||||
|
public Xoscript_page(Bry_bfr rv, Xoscript_env env, Xoscript_url url) {
|
||||||
|
this.env = env;
|
||||||
|
this.url = url;
|
||||||
|
this.doc = new Xoscript_doc(rv, this);
|
||||||
|
}
|
||||||
|
public Xoscript_env Env() {return env;} private final Xoscript_env env;
|
||||||
|
public Xoscript_url Url() {return url;} private final Xoscript_url url;
|
||||||
|
public Xoscript_doc Doc() {return doc;} private final Xoscript_doc doc;
|
||||||
|
}
|
Loading…
Reference in new issue