1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.gfs.*;
public class Xoa_app_eval implements Bry_fmtr_eval_mgr {
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public byte[] Eval(byte[] cmd) {
Object rslt = GfsCore.Instance.Exec_bry(cmd);
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
}
}

View File

@@ -0,0 +1,42 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import org.junit.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.apps.gfs.*;
public class Xoa_app_eval_tst {
Xoa_app_eval_fxt fxt = new Xoa_app_eval_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.Eval_test("[~{<>app.sys_cfg.version;<>}]", "[" + Xoa_app_.Version + "]");
}
}
class Xoa_app_eval_fxt {
public void Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
fmtr = Bry_fmtr.new_();
eval = new Xoa_app_eval();
fmtr.Eval_mgr_(eval);
Xoa_gfs_mgr.Msg_parser_init();
}
} private Xoae_app app; Bry_fmtr fmtr; Xoa_app_eval eval;
public void Eval_test(String raw, String expd) {
Tfds.Eq(fmtr.Fmt_(raw).Bld_str_many(), expd);
}
}

View File

@@ -0,0 +1,66 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
public class Xoa_app_mode {
Xoa_app_mode(int tid) {this.tid = tid;}
public int Tid() {return tid;} private final int tid;
public boolean Tid_is_gui() {return tid == Tid_gui;}
public boolean Tid_is_tcp() {return tid == Tid_tcp;}
public boolean Tid_is_cmd() {return tid == Tid_cmd;}
public boolean Tid_is_http() {return tid == Tid_http;}
public boolean Tid_supports_js() {
switch (tid) {
case Tid_gui:
case Tid_tcp: return true;
default: return false;
}
}
public byte[] Name() {
switch (tid) {
case Tid_cmd: return Key_cmd;
case Tid_gui: return Key_gui;
case Tid_http: return Key_http;
case Tid_tcp: return Key_tcp;
case Tid_file: return Key_file;
default: return Key_cmd; // see parse
}
}
private static final int Tid_cmd = 1, Tid_gui = 2, Tid_tcp = 3, Tid_http = 4, Tid_file = 5;
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file");
public static final Xoa_app_mode Itm_cmd = new Xoa_app_mode(Tid_cmd), Itm_gui = new Xoa_app_mode(Tid_gui), Itm_tcp = new Xoa_app_mode(Tid_tcp), Itm_http = new Xoa_app_mode(Tid_http), Itm_file = new Xoa_app_mode(Tid_file);
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
.Add_bry_int(Key_cmd , Tid_cmd)
.Add_bry_int(Key_gui , Tid_gui)
.Add_bry_int(Key_http , Tid_http)
.Add_bry_int(Key_tcp , Tid_tcp)
.Add_bry_int(Key_file , Tid_file)
;
public static Xoa_app_mode parse(String s) {
Object o = type_hash.Get_by(Bry_.new_u8(s)); if (o == null) return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong"
int tid = ((Int_obj_val)o).Val();
switch (tid) {
case Tid_cmd: return Itm_cmd;
case Tid_gui: return Itm_gui;
case Tid_http: return Itm_http;
case Tid_tcp: return Itm_tcp;
case Tid_file: return Itm_file;
default: throw Err_.new_unhandled(tid);
}
}
}

View File

@@ -0,0 +1,31 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.xowa.guis.views.*;
public class Xoa_cur implements Gfo_invk {
public Xoa_cur(Xoae_app app) {this.app = app;} private Xoae_app app;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_wiki)) {
Xog_win_itm win = app.Gui_mgr().Browser_win();
return win.Active_tab() == null ? Gfo_invk_.Noop : win.Active_page().Wikie(); // null check when called from mass html gen; DATE:2014-06-04
}
else if (ctx.Match(k, Invk_win)) return app.Gui_mgr().Browser_win();
else if (ctx.Match(k, Invk_user)) return app.Usere();
else return Gfo_invk_.Rv_unhandled;
} private static final String Invk_wiki = "wiki", Invk_win = "win", Invk_user = "user";
}

View File

@@ -0,0 +1,42 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.consoles.*;
import gplx.xowa.wikis.*;
import gplx.xowa.htmls.hrefs.*;
public class Xoa_shell implements Gfo_invk {
public Xoa_shell(Xoae_app app) {this.app = app;} private Xoae_app app;
public boolean Fetch_page_exec_async() {return fetch_page_exec_async;} private boolean fetch_page_exec_async = true;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_fetch_page)) return Fetch_page(m);
else if (ctx.Match(k, Invk_chars_per_line_max_)) Console_adp__sys.Instance.Chars_per_line_max_(m.ReadInt("v"));
else if (ctx.Match(k, Invk_backspace_by_bytes_)) Console_adp__sys.Instance.Backspace_by_bytes_(m.ReadYn("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private String Fetch_page(GfoMsg m) {
String url = m.ReadStr("url");
if (String_.Eq(url, "home")) url = Xoa_url_.Main_page__home_str; // WORKAROUND.ADDON: toolbar button sends "home"; note that Fetch_page is only called from command-line / addon, so "home" should never mean "home" page in current wiki; EX: en.wikipedia.org/wiki/home; DATE:2015-08-18
if (String_.Has_at_bgn(url, "//")) url = gplx.core.net.Gfo_protocol_itm.Itm_https.Key_w_colon_str() + url; // WORKAROUND.ADDON: sidebar sends urls of form "//en.wikipedia.org/"; prefix with "https:" so url parser can handle it; DATE:2015-07-05; DATE:2015-08-18
return String_.new_u8(app.Gui_mgr().Browser_win().App__retrieve_by_url(url, m.ReadStrOr("output_type", "html")));
}
private static final String Invk_fetch_page = "fetch_page"
, Invk_chars_per_line_max_ = "chars_per_line_max_"
, Invk_backspace_by_bytes_ = "backspace_by_bytes_"
;
}

View File

@@ -0,0 +1,30 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.apps.gfs.*;
public class Xoa_shell_tst {
@Test public void Fetch_page() { // PURPOSE.fix: fetch_page failed with nullRef; DATE:2013-04-12
Xop_fxt parser_fxt = new Xop_fxt();
Xoae_app app = parser_fxt.App(); Xowe_wiki wiki = parser_fxt.Wiki();
parser_fxt.Init_page_create("A", "test"); // need to create page in order for html output to gen
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true); // need to set html_capable in order for div_home to load
Xoa_gfs_mgr.Msg_parser_init();
wiki.Html_mgr().Portal_mgr().Div_home_fmtr().Fmt_("~{<>app.user.msgs.get('mainpage-description');<>}");
app.Gfs_mgr().Run_str("app.shell.fetch_page('en.wikipedia.org/wiki/A' 'html');"); // this causes a nullRef error b/c app.user.lang is null
}
}

View File

@@ -0,0 +1,21 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
public class Xoa_stage_ {
public static final byte Tid_ctor = 0, Tid_init = 1, Tid_launch = 2;
}

View File

@@ -0,0 +1,91 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.xowa.langs.*;
public class Xoa_sys_cfg implements Gfo_invk {
private Xoae_app app;
public Xoa_sys_cfg(Xoae_app app) {this.app = app;}
public byte[] Lang() {return lang_key;}
public Xoa_sys_cfg Lang_(byte[] v) {
lang_key = Xol_lang_stub_.Get_by_key_or_en(v).Key();
if (app.Stage() == gplx.xowa.apps.Xoa_stage_.Tid_launch) { // do not update user lang unless launched; DATE:2014-05-26
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_load(lang_key);
app.Usere().Lang_(lang);
app.Usere().Wiki().Html_mgr().Portal_mgr().Init();
}
return this;
} private byte[] lang_key = Xol_lang_itm_.Key_en;
public void Init_by_app(Xoa_app app) {
app.Cfg().Type_mgr().Lists__add("list:" + Cfg__lang, Options_list_lang_.new_());
app.Cfg().Bind_many_app(this, Cfg__lang);
}
private static final String Cfg__lang = "xowa.gui.app.lang";
public int Options_version() {return options_version;} public Xoa_sys_cfg Options_version_(int v) {options_version = v; return this;} private int options_version = 1;
public Keyval[] Options_lang_list() {if (options_lang_list == null) options_lang_list = Options_list_lang_.new_(); return options_lang_list;} private Keyval[] options_lang_list;
public long Free_mem_when() {return free_mem_when;} long free_mem_when;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_version)) return Xoa_app_.Version;
else if (ctx.Match(k, Invk_build_date)) return Xoa_app_.Build_date;
else if (ctx.Match(k, Invk_free_mem_when_)) free_mem_when = gplx.core.ios.Io_size_.parse_or(m.ReadStr("v"), Io_mgr.Len_mb * 5);
else if (ctx.Match(k, Invk_lang)) return lang_key;
else if (ctx.Match(k, Invk_lang_)) Lang_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_lang_list)) return Options_lang_list();
else if (ctx.Match(k, Invk_options_version)) return options_version;
else if (ctx.Match(k, Invk_options_version_)) options_version = m.ReadInt("v");
else if (ctx.Match(k, Cfg__lang)) Lang_(m.ReadBry("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_version = "version", Invk_build_date = "build_date", Invk_free_mem_when_ = "free_mem_when_", Invk_options_version = "options_version", Invk_options_version_ = "options_version_"
, Invk_lang = "lang", Invk_lang_ = "lang_", Invk_lang_list = "lang_list";
}
class Options_list_lang_ {
public static Keyval[] new_() {
Ordered_hash translated = Ordered_hash_.New_bry();
List_adp untranslated = List_adp_.New();
Add_itm_many(translated, Xol_lang_stub_.Id_en, Xol_lang_stub_.Id_de, Xol_lang_stub_.Id_pl, Xol_lang_stub_.Id_zh_hans, Xol_lang_stub_.Id_zh_hant); // add langs with translations first, so they alphabetize to top of list
int len = Xol_lang_stub_.Id__max;
for (int i = 0; i < len; i++) { // add rest of langs, but sort by code
Xol_lang_stub itm = Xol_lang_stub_.Get_by_id(i);
if (translated.Has(itm.Key())) continue;
untranslated.Add(itm);
}
untranslated.Sort_by(Xol_lang_stub_.Comparer_key);
Keyval[] rv = new Keyval[len];
int translated_max = translated.Count();
for (int i = 0; i < translated_max; i++)
rv[i] = new_itm((Xol_lang_stub)translated.Get_at(i));
for (int i = translated_max; i < len; i++)
rv[i] = new_itm((Xol_lang_stub)untranslated.Get_at(i - translated_max));
return rv;
}
private static Keyval new_itm(Xol_lang_stub itm) {
String key_str = String_.new_u8(itm.Key());
String name_str = String_.new_u8(itm.Canonical_name());
return Keyval_.new_(key_str, name_str + " [" + key_str + "]");
}
private static void Add_itm_many(Ordered_hash translated, int... langs) {
int langs_len = langs.length;
for (int i = 0; i < langs_len; i++) {
Xol_lang_stub itm = Xol_lang_stub_.Get_by_id(langs[i]);
translated.Add_if_dupe_use_nth(itm.Key(), itm);
}
}
}

View File

@@ -0,0 +1,30 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
public class Xoa_thread_ {
public static final String
Key_page_async = "xowa.page.async"
, Key_page_redlink = "xowa.page.redlink"
, Key_page_popup = "xowa.page.popup"
, Key_http_server_main = "xowa.http_server.main"
, Key_bldr_download = "xowa.bldr.download"
, Key_special_search_db = "xowa.special.search.db"
, Key_special_search_cancel = "xowa.special.search.cancel"
, Key_special_suggest = "xowa.special.suggest"
;
}

View File

@@ -0,0 +1,27 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.threads.*;
public class Xoa_thread_mgr {
public Gfo_thread_pool Page_load_mgr() {return page_load_mgr;} private Gfo_thread_pool page_load_mgr = new Gfo_thread_pool();
public Gfo_thread_pool File_load_mgr() {return file_load_mgr;} private Gfo_thread_pool file_load_mgr = new Gfo_thread_pool();
public void Usr_dlg_(Gfo_usr_dlg usr_dlg) {
page_load_mgr.Usr_dlg_(usr_dlg);
file_load_mgr.Usr_dlg_(usr_dlg);
}
}

View File

@@ -0,0 +1,113 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.net.*; import gplx.core.log_msgs.*; import gplx.langs.jsons.*; import gplx.core.brys.*; import gplx.core.threads.*;
import gplx.core.ios.*;
import gplx.dbs.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.metas.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.langs.cases.*; import gplx.core.intls.*; import gplx.xowa.users.data.*;
import gplx.xowa.apps.site_cfgs.*; import gplx.xowa.apps.urls.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.bldrs.css.*;
import gplx.xowa.apps.gfs.*;
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.bridges.*;
import gplx.xowa.users.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.xwikis.parsers.*; import gplx.xowa.wikis.xwikis.sitelinks.*;
import gplx.xowa.guis.cbks.*; import gplx.xowa.guis.tabs.*;
import gplx.xowa.langs.*;
import gplx.xowa.bldrs.wms.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.bldrs.*;
import gplx.xowa.addons.*; import gplx.xowa.specials.mgrs.*;
import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.apps.miscs.*;
public class Xoav_app implements Xoa_app, Gfo_invk {
public Xoav_app(Gfo_usr_dlg usr_dlg, Xoa_app_mode mode, Xog_tab_mgr tab_mgr, String plat_name, Io_url root_dir, Io_url file_dir, Io_url css_dir, Io_url http_root) {
Xoa_app_.Usr_dlg_(usr_dlg); this.usr_dlg = usr_dlg; this.mode = mode;
this.fsys_mgr = new Xoa_fsys_mgr(plat_name, root_dir, root_dir.GenSubDir("wiki"), file_dir, css_dir, http_root);
this.gfs_mgr = new Xoa_gfs_mgr("anonymous", this, fsys_mgr);
this.lang_mgr = new Xoa_lang_mgr(this, gfs_mgr);
this.meta_mgr = new Xoa_meta_mgr(this);
this.file__cache_mgr = new Xof_cache_mgr(usr_dlg, null, null);
this.file__img_mgr = new Xof_img_mgr();
this.wiki_mgr = new Xoav_wiki_mgr(this, utl_case_mgr);
this.utl_msg_log = Gfo_msg_log.Test();
this.html__bridge_mgr = new Xoh_bridge_mgr(utl__json_parser);
this.gui__tab_mgr = tab_mgr;
this.user = new Xouv_user(this, "anonymous", root_dir.GenSubDir_nest("user", "anonymous"));
this.api_root = null;
this.site_cfg_mgr = new Xoa_site_cfg_mgr(this);
this.bldr = new Xob_bldr(null);
}
public boolean Tid_is_edit() {return Bool_.N;}
public Xoa_app_mode Mode() {return mode;} private final Xoa_app_mode mode;
public Xou_user User() {return user;} private final Xouv_user user;
public Xoapi_root Api_root() {return api_root;} private final Xoapi_root api_root;
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xoa_fsys_mgr fsys_mgr;
public Xoav_wiki_mgr Wiki_mgr() {return wiki_mgr;} private final Xoav_wiki_mgr wiki_mgr;
public Xoa_wiki_mgr Wiki_mgri() {return wiki_mgr;}
public Xoa_lang_mgr Lang_mgr() {return lang_mgr;} private final Xoa_lang_mgr lang_mgr;
public Xoa_gfs_mgr Gfs_mgr() {return gfs_mgr;} private final Xoa_gfs_mgr gfs_mgr;
public Xof_cache_mgr File__cache_mgr() {return file__cache_mgr;} private final Xof_cache_mgr file__cache_mgr;
public Xof_img_mgr File__img_mgr() {return file__img_mgr;} private final Xof_img_mgr file__img_mgr;
public Io_download_fmt File__download_fmt() {return file__download_fmt;} private final Io_download_fmt file__download_fmt = new Io_download_fmt();
public Xoh_href_parser Html__href_parser() {return href_parser;} private final Xoh_href_parser href_parser = new Xoh_href_parser();
public Xoh_href_wtr Html__href_wtr() {return html__href_wtr;} private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
public Xoa_css_extractor Html__css_installer() {return html__css_installer;} private final Xoa_css_extractor html__css_installer = new Xoa_css_extractor();
public Xoh_bridge_mgr Html__bridge_mgr() {return html__bridge_mgr;} private final Xoh_bridge_mgr html__bridge_mgr;
public Xoa_meta_mgr Dbmeta_mgr() {return meta_mgr;} private final Xoa_meta_mgr meta_mgr;
public Gfo_inet_conn Utl__inet_conn() {return inet_conn;} private final Gfo_inet_conn inet_conn = Gfo_inet_conn_.new_();
public Xoa_site_cfg_mgr Site_cfg_mgr() {return site_cfg_mgr;} private final Xoa_site_cfg_mgr site_cfg_mgr;
public boolean Xwiki_mgr__missing(byte[] domain) {return wiki_mgr.Get_by_or_null(domain) == null;}
public Xoa_sitelink_mgr Xwiki_mgr__sitelink_mgr() {return xwiki_mgr__sitelink_mgr;} private final Xoa_sitelink_mgr xwiki_mgr__sitelink_mgr = new Xoa_sitelink_mgr();
public Xow_xwiki_itm_parser Xwiki_mgr__itm_parser() {return xwiki_mgr__itm_parser;} private final Xow_xwiki_itm_parser xwiki_mgr__itm_parser = new Xow_xwiki_itm_parser();
public Xoax_addon_mgr Addon_mgr() {return addon_mgr;} private final Xoax_addon_mgr addon_mgr = new Xoax_addon_mgr();
public Xob_bldr Bldr() {return bldr;} private final Xob_bldr bldr;
public Xoa_special_regy Special_regy() {return special_regy;} private final Xoa_special_regy special_regy = new Xoa_special_regy();
public Xog_cbk_mgr Gui__cbk_mgr() {return gui__cbk_mgr;} private final Xog_cbk_mgr gui__cbk_mgr = new Xog_cbk_mgr();
public Xog_tab_mgr Gui__tab_mgr() {return gui__tab_mgr;} private final Xog_tab_mgr gui__tab_mgr;
public Gfo_thread_mgr Thread_mgr() {return thread_mgr;} private final Gfo_thread_mgr thread_mgr = new Gfo_thread_mgr();
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private final Xop_amp_mgr parser_amp_mgr = Xop_amp_mgr.Instance;
public Xocfg_mgr Cfg() {return cfg;} private final Xocfg_mgr cfg = new Xocfg_mgr();
public Xoa_misc_mgr Misc_mgr() {return misc_mgr;} private final Xoa_misc_mgr misc_mgr = new Xoa_misc_mgr();
public Xowmf_mgr Wmf_mgr() {return wmf_mgr;} private final Xowmf_mgr wmf_mgr = new Xowmf_mgr();
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} public void Usr_dlg_(Gfo_usr_dlg v) {usr_dlg = v; Xoa_app_.Usr_dlg_(usr_dlg);} private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Noop;
public Bry_bfr_mkr Utl__bfr_mkr() {return utl__bry_bfr_mkr;} private final Bry_bfr_mkr utl__bry_bfr_mkr = new Bry_bfr_mkr();
public Json_parser Utl__json_parser() {return utl__json_parser;} private final Json_parser utl__json_parser = new Json_parser();
public boolean Bldr__running() {return bldr__running;} public void Bldr__running_(boolean v) {this.bldr__running = v;} private boolean bldr__running;
public Xop_amp_mgr Utl_amp_mgr() {return utl_amp_mgr;} private Xop_amp_mgr utl_amp_mgr = Xop_amp_mgr.Instance;
public Xol_case_mgr Utl_case_mgr() {return utl_case_mgr;} private Xol_case_mgr utl_case_mgr = Xol_case_mgr_.U8();
// public Gfo_url_encoder Utl_encoder_fsys() {return utl_encoder_fsys;} private Gfo_url_encoder utl_encoder_fsys = Gfo_url_encoder.New_fsys_lnx();
public Gfo_msg_log Utl_msg_log() {return utl_msg_log;} private Gfo_msg_log utl_msg_log;
public Xoav_url_parser Utl_url_parser_xo() {return utl_url_parser_xo;} private Xoav_url_parser utl_url_parser_xo = new Xoav_url_parser();
public Gfo_url_parser Utl_url_parser_gfo() {return utl_url_parser_gfo;} private final Gfo_url_parser utl_url_parser_gfo = new Gfo_url_parser();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {throw Err_.new_unimplemented_w_msg("implemented for Xoa_cfg_mgr");}
public void Init_by_app(Io_url user_db_url) {
user.Init_db(this, wiki_mgr, user_db_url);
this.Addon_mgr().Add_dflts_by_app(this).Run_by_app(this);
cfg.Init_by_app(this);
misc_mgr.Init_by_app(this);
}
public void Free_mem() { // NOTE:not yet called in drd; DATE:2016-12-04
}
public static Xoav_app New_by_drd(gplx.xowa.drds.files.Xod_fsys_mgr fsys_mgr, Xog_tab_mgr tab_mgr) {
// create log
Gfo_usr_dlg__log_base log = new Gfo_usr_dlg__log_base(); log.Log_dir_(Io_url_.mem_dir_("mem/tmp"));
Gfo_usr_dlg usr_dlg = new Gfo_usr_dlg_base(log, Gfo_usr_dlg__gui_.Console);
Xoa_app_.Usr_dlg_(usr_dlg);
return new Xoav_app(usr_dlg, Xoa_app_mode.Itm_gui, tab_mgr, "drd", fsys_mgr.App_root_dir(), fsys_mgr.Usr_data_dir(), fsys_mgr.Usr_data_dir().GenSubDir("temp"), Io_url_.new_any_("/android_asset/xowa/"));
}
}

View File

@@ -0,0 +1,50 @@
/*
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.apps; import gplx.*; import gplx.xowa.*;
import gplx.xowa.*; import gplx.xowa.langs.cases.*; import gplx.xowa.users.data.*;
import gplx.xowa.wikis.*;
public class Xoav_wiki_mgr implements Xoa_wiki_mgr {
private final Xoav_app app; private final Ordered_hash hash = Ordered_hash_.New_bry();
public Xoav_wiki_mgr(Xoav_app app, Xol_case_mgr case_mgr) {this.app = app;}
public int Count() {return hash.Count();}
public boolean Has(byte[] key) {return hash.Has(key);}
public Xow_wiki Get_at(int idx) {return (Xow_wiki)hash.Get_at(idx);}
public Xow_wiki Get_by_or_null(byte[] key) {return (Xow_wiki)hash.Get_by(key);}
public Xow_wiki Get_by_or_make_init_y(byte[] key) {
Xow_wiki rv = this.Get_by_or_null(key);
rv.Init_by_wiki();
return rv;
}
public Xow_wiki Get_by_or_make_init_n(byte[] key) {return Get_by_or_make_init_y(key);}
public void Add(Xow_wiki wiki) {hash.Add_if_dupe_use_nth(wiki.Domain_bry(), wiki);}
public Xow_wiki Make(byte[] domain_bry, Io_url wiki_root_dir) {return new Xowv_wiki(app, domain_bry, wiki_root_dir);}
public Xow_wiki Import_by_url(Io_url url) {return Xoa_wiki_mgr_.Import_by_url(app, this, url);}
public void Load_by_user_data() {
Xoud_site_row[] ary = app.User().User_db_mgr().Site_mgr().Get_all();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xoud_site_row itm = ary[i];
Xow_wiki wiki = Make(Bry_.new_u8(itm.Domain()), Io_url_.new_dir_(itm.Path()));
this.Add(wiki);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Xoa_wiki_mgr_.Invk__import_by_url)) return this.Import_by_url(m.ReadIoUrl("v"));
else return Gfo_invk_.Rv_unhandled;
}
}

View File

@@ -0,0 +1,72 @@
/*
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.apps.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.guis.cmds.*;
public class Xoapi_root implements Gfo_invk {
private Xoae_app app;
public Xoapi_root(Xoae_app app) {
app_api.Ctor_by_app(app);
usr_api.Ctor_by_app(app);
bldr_api.Ctor_by_app(app);
html_api.Ctor_by_app(app);
}
public void Init_by_kit(Xoae_app app) {
this.app = app;
app_api.Init_by_kit(app);
nav_api.Init_by_kit(app);
gui_api.Init_by_kit(app);
html_api.Init_by_kit(app);
usr_api.Init_by_kit(app);
xtns_api.Init_by_kit(app);
}
public void Init_by_app(Xoae_app app) {
html_api.Init_by_app(app);
usr_api.Init_by_app(app);
}
public Xoapi_addon Addon() {return addon_api;} private final Xoapi_addon addon_api = new Xoapi_addon();
public Xoapi_app App() {return app_api;} private final Xoapi_app app_api = new Xoapi_app();
public Xoapi_nav Nav() {return nav_api;} private final Xoapi_nav nav_api = new Xoapi_nav();
public Xoapi_gui Gui() {return gui_api;} private final Xoapi_gui gui_api = new Xoapi_gui();
public Xoapi_html Html() {return html_api;} private final Xoapi_html html_api = new Xoapi_html();
public Xoapi_bldr Bldr() {return bldr_api;} private final Xoapi_bldr bldr_api = new Xoapi_bldr();
public Xoapi_usr Usr() {return usr_api;} private final Xoapi_usr usr_api = new Xoapi_usr();
public Xoapi_xtns Xtns() {return xtns_api;} private final Xoapi_xtns xtns_api = new Xoapi_xtns();
public String Test_str() {return test_str;} public void Test_str_(String v) {test_str = v;} private String test_str; // TEST
private void Exec(String key) {
Xog_cmd_itm cmd_itm = app.Gui_mgr().Cmd_mgr().Get_or_null(key);
if (cmd_itm == null) app.Usr_dlg().Warn_many("", "", "could not find cmd; key=~{0}", key);
app.Gfs_mgr().Run_str_for(app, cmd_itm.Cmd());
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_app)) return app_api;
else if (ctx.Match(k, Invk_addon)) return addon_api;
else if (ctx.Match(k, Invk_bldr)) return bldr_api;
else if (ctx.Match(k, Invk_nav)) return nav_api;
else if (ctx.Match(k, Invk_gui)) return gui_api;
else if (ctx.Match(k, Invk_html)) return html_api;
else if (ctx.Match(k, Invk_usr)) return usr_api;
else if (ctx.Match(k, Invk_xtns)) return xtns_api;
else if (ctx.Match(k, Invk_exec)) Exec(m.ReadStr("v"));
else if (ctx.Match(k, Invk_test_str)) return test_str;
else if (ctx.Match(k, Invk_test_str_)) test_str = m.ReadStr("v");
return this;
}
private static final String Invk_exec = "exec", Invk_test_str = "test_str", Invk_test_str_ = "test_str_"
, Invk_app = "app", Invk_addon = "addon"
, Invk_bldr = "bldr", Invk_nav = "nav", Invk_gui = "gui", Invk_html = "html", Invk_usr = "usr", Invk_xtns = "xtns";
}

View File

@@ -0,0 +1,30 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.apps.apis.xowa.addons.*;
public class Xoapi_addon implements Gfo_invk {
public void Ctor_by_app(Xoa_app app) {}
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 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 return Gfo_invk_.Rv_unhandled;
}
private static final String Invk__search = "search", Invk__bldr = "bldr";
}

View File

@@ -0,0 +1,38 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.guis.views.*;
import gplx.xowa.apps.apis.xowa.apps.*;
public class Xoapi_app implements Gfo_invk {
private Xog_win_itm win;
public void Ctor_by_app(Xoae_app app) {
fsys.Ctor_by_app(app);
}
public void Init_by_kit(Xoae_app app) {
win = app.Gui_mgr().Browser_win();
}
public Xoapi_fsys Fsys() {return fsys;} private Xoapi_fsys fsys = new Xoapi_fsys();
public void Exit() {win.App__exit();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_exit)) this.Exit();
else if (ctx.Match(k, Invk_fsys)) return fsys;
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_exit = "exit", Invk_fsys = "fsys";
}

View File

@@ -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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.apps.apis.xowa.bldrs.*;
public class Xoapi_bldr implements Gfo_invk {
public void Ctor_by_app(Xoa_app app) {wiki.Ctor_by_app(app);}
public Xoapi_bldr_wiki Wiki() {return wiki;} private final Xoapi_bldr_wiki wiki = new Xoapi_bldr_wiki();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_wiki)) return wiki;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_wiki = "wiki";
}

View File

@@ -0,0 +1,36 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.apps.apis.xowa.gui.*;
public class Xoapi_gui implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {
browser.Init_by_kit(app);
font.Init_by_kit(app);
page.Init_by_kit(app);
}
public Xoapi_browser Browser() {return browser;} private Xoapi_browser browser = new Xoapi_browser();
public Xoapi_font Font() {return font;} private Xoapi_font font = new Xoapi_font();
public Xoapi_page Page() {return page;} private Xoapi_page page = new Xoapi_page();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_browser)) return browser;
else if (ctx.Match(k, Invk_font)) return font;
else if (ctx.Match(k, Invk_page)) return page;
return this;
}
private static final String Invk_browser = "browser", Invk_font = "font", Invk_page = "page";
}

View File

@@ -0,0 +1,34 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.apps.apis.xowa.html.*;
public class Xoapi_html implements Gfo_invk {
public void Ctor_by_app(Xoae_app app) {
page.Ctor_by_app(app);
}
public void Init_by_app(Xoae_app app) {page.Init_by_app(app);}
public void Init_by_kit(Xoae_app app) {modules.Init_by_kit(app);}
public Xoapi_modules Modules() {return modules;} private final Xoapi_modules modules = new Xoapi_modules();
public Xoapi_page Page() {return page;} private final Xoapi_page page = new Xoapi_page();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_modules)) return modules;
else if (ctx.Match(k, Invk_page)) return page;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_modules = "modules", Invk_page = "page";
}

View File

@@ -0,0 +1,40 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.guis.views.*;
import gplx.xowa.apps.apis.xowa.navs.*;
public class Xoapi_nav implements Gfo_invk {
private Xog_win_itm win;
public void Init_by_kit(Xoae_app app) {
win = app.Gui_mgr().Browser_win();
wiki.Init_by_kit(app);
}
public Xoapi_nav_wiki Wiki() {return wiki;} private Xoapi_nav_wiki wiki = new Xoapi_nav_wiki();
public void Goto(String page) {win.Page__navigate_by_url_bar(page);}
public void Go_bwd() {win.Page__navigate_by_history(Bool_.N);}
public void Go_fwd() {win.Page__navigate_by_history(Bool_.Y);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_go_bwd)) this.Go_bwd();
else if (ctx.Match(k, Invk_go_fwd)) this.Go_fwd();
else if (ctx.Match(k, Invk_goto)) this.Goto(m.ReadStr("v"));
else if (ctx.Match(k, Invk_wiki)) return wiki;
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_go_bwd = "go_bwd", Invk_go_fwd = "go_fwd", Invk_goto = "goto", Invk_wiki = "wiki";
}

View File

@@ -0,0 +1,39 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.apps.apis.xowa.usrs.*;
public class Xoapi_usr implements Gfo_invk {
public void Ctor_by_app(Xoae_app app) {
bookmarks.Ctor_by_app(app);
history.Ctor_by_app(app);
}
public void Init_by_app(Xoa_app app) {
}
public void Init_by_kit(Xoae_app app) {
bookmarks.Init_by_kit(app);
history.Init_by_kit(app);
}
public Xoapi_bookmarks Bookmarks() {return bookmarks;} private final Xoapi_bookmarks bookmarks = new Xoapi_bookmarks();
public Xoapi_history History() {return history;} private final Xoapi_history history = new Xoapi_history();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_bookmarks)) return bookmarks;
else if (ctx.Match(k, Invk_history)) return history;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_bookmarks = "bookmarks", Invk_history = "history";
}

View File

@@ -0,0 +1,30 @@
/*
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.apps.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*;
import gplx.xowa.apps.apis.xowa.xtns.*;
public class Xoapi_xtns implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {
wikibase.Init_by_app(app);
}
public Xoapi_wikibase Wikibase() {return wikibase;} private final Xoapi_wikibase wikibase = new Xoapi_wikibase();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_wikibase)) return wikibase;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_wikibase = "wikibase";
}

View File

@@ -0,0 +1,27 @@
/*
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.apps.apis.xowa.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.apis.xowa.addons.bldrs.*;
public class Xoapi_addon_bldr implements Gfo_invk {
public Xoapi_central_api Central() {return central;} private final Xoapi_central_api central = new Xoapi_central_api();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__central)) return central;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk__central = "central";
}

View File

@@ -0,0 +1,33 @@
/*
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.apps.apis.xowa.addons; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.domains.crts.*;
import gplx.xowa.apps.apis.xowa.addons.searchs.*;
public class Xoapi_addon_search implements Gfo_invk {
@gplx.Internal protected Xoapi_search_box Search_box() {return search_box;} private final Xoapi_search_box search_box = new Xoapi_search_box();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__search_box)) return search_box;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk__search_box = "search_box";
}
class Xoapi_search_box implements Gfo_invk {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return null;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.apps.apis.xowa.addons.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.addons.*;
public class Xoapi_central_api implements Gfo_invk {
public boolean Log_verbose() {return log_verbose;} private boolean log_verbose = false;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__log_verbose_)) log_verbose = m.ReadBool("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk__log_verbose_ = "log_verbose_"
;
}

View File

@@ -0,0 +1,95 @@
/*
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.apps.apis.xowa.addons.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.addons.*;
import gplx.xowa.apps.urls.*;
public class Xopg_match_mgr {
private String scope_raw;
private Ordered_hash wikis;
private boolean wildcard_exists;
private Xopg_match_wiki wildcard_wiki;
public void Set(String v) {
this.scope_raw = v;
this.wikis = null;
this.wildcard_exists = false;
this.wildcard_wiki = null;
}
public boolean Match(Xow_wiki wiki, byte[] page_ttl) {
if (wikis == null) Init(wiki.App());
if (wildcard_exists) return true;
if (wildcard_wiki != null) {
if (wildcard_wiki.Has(page_ttl))
return true;
}
Xopg_match_wiki match_wiki = (Xopg_match_wiki)wikis.Get_by(wiki.Domain_bry());
if (match_wiki == null) return false;
return match_wiki.Has(page_ttl);
}
private void Init(Xoa_app app) {
this.wikis = Ordered_hash_.New_bry();
String[] lines = String_.SplitLines_nl(scope_raw);
Xow_url_parser url_parser = app.User().Wikii().Utl__url_parser();
for (String line : lines) {
if (String_.Eq(line, "*")) {
wildcard_exists = true;
}
else {
byte[] wiki_domain = null, page_db = null;
boolean cur_is_wildcard_wiki = false;
if (String_.Has_at_bgn(line, "*:")) {
wiki_domain = Byte_ascii.Star_bry;
page_db = Bry_.Mid(Bry_.new_u8(line), 2);
cur_is_wildcard_wiki = true;
}
else {
Xoa_url url = url_parser.Parse_by_urlbar_or_null(line);
wiki_domain = url.Wiki_bry();
page_db = url.Page_bry();
}
Xopg_match_wiki match_wiki = (Xopg_match_wiki)wikis.Get_by(wiki_domain);
if (match_wiki == null) {
match_wiki = new Xopg_match_wiki(wiki_domain);
wikis.Add(wiki_domain, match_wiki);
if (cur_is_wildcard_wiki) {
wildcard_wiki = match_wiki;
}
}
match_wiki.Add(page_db);
}
}
}
}
class Xopg_match_wiki {
private final Ordered_hash hash = Ordered_hash_.New_bry();
private boolean wildcard_exists;
public Xopg_match_wiki(byte[] domain_bry) {
this.domain_bry = domain_bry;
}
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry;
public boolean Has(byte[] page_db) {
return wildcard_exists ? true : hash.Has(page_db);
}
public void Add(byte[] page_db) {
if (Bry_.Eq(page_db, Byte_ascii.Star_bry)) {
wildcard_exists = true;
}
else {
hash.Add_if_dupe_use_1st(page_db, page_db);
}
}
}

View File

@@ -0,0 +1,70 @@
/*
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.apps.apis.xowa.addons.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.addons.*;
import org.junit.*; import gplx.core.tests.*;
public class Xopg_match_mgr__tst {
private final Xopg_match_mgr__fxt fxt = new Xopg_match_mgr__fxt();
@Before public void init() {fxt.Clear();}
@Test public void Specific() {
fxt.Init__set("en.w:A");
fxt.Test__match_y("A");
fxt.Test__match_n("AB");
}
@Test public void Other_wiki() {
fxt.Init__set("fr.w:A");
fxt.Test__match_n("A"); // note that test defaults to "en.w" as primary wiki
}
@Test public void Wildcard__app() {
fxt.Init__set("*");
fxt.Test__match_y("A", "B");
}
@Test public void Wildcard__page() {
fxt.Init__set("en.w:*");
fxt.Test__match_y("A", "B");
}
@Test public void Wildcard__page__other() {
fxt.Init__set("fr.w:*");
fxt.Test__match_n("A", "B");
}
@Test public void Wildcard__wiki() {
fxt.Init__set("*:A");
fxt.Test__match_y("A");
fxt.Test__match_n("B");
}
}
class Xopg_match_mgr__fxt {
private final Xopg_match_mgr match_mgr = new Xopg_match_mgr();
private Xowe_wiki wiki;
public void Clear() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
app.User().Wikii().Xwiki_mgr().Add_by_atrs(wiki.Domain_bry(), wiki.Domain_bry());
}
public void Init__set(String url) {
match_mgr.Set(url);
}
public void Test__match_y(String... urls) {Test__match(Bool_.Y, urls);}
public void Test__match_n(String... urls) {Test__match(Bool_.N, urls);}
private void Test__match(boolean expd, String... urls) {
for (int i = 0; i < urls.length; i++) {
String url = urls[i];
boolean actl = match_mgr.Match(wiki, Bry_.new_u8(url));
Gftest.Eq__bool(expd, actl, "match failed", "expd", expd, "url", url);
}
}
}

View File

@@ -0,0 +1,34 @@
/*
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.apps.apis.xowa.addons.searchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.addons.*;
public class Xoapi_search_mode_ {
public static final int Tid__title_full = 0, Tid__title_word = 1;
public static final String Str__title_full = "title.full", Str__title_word = "title.word";
public static String To_str(int v) {
switch (v) {
case Tid__title_full: return Str__title_full;
case Tid__title_word: return Str__title_word;
default: throw Err_.new_unhandled_default(v);
}
}
public static int To_int(String v) {
if (String_.Eq(v, Str__title_full)) return Tid__title_full;
else if (String_.Eq(v, Str__title_word)) return Tid__title_word;
else throw Err_.new_unhandled_default(v);
}
}

View File

@@ -0,0 +1,33 @@
/*
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.apps.apis.xowa.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.core.envs.*;
public class Xoapi_fsys implements Gfo_invk {
public void Ctor_by_app(Xoae_app app) {
this.plat_jar = Env_.AppUrl();
this.root_dir = app.Fsys_mgr().Root_dir();
}
public Io_url Plat_jar() {return plat_jar;} private Io_url plat_jar;
public Io_url Plat_url(String s) {return Io_url_.new_any_(root_dir.Gen_sub_path_for_os(s));} private Io_url root_dir;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_plat_jar)) return plat_jar;
else if (ctx.Match(k, Invk_plat_url)) return Plat_url(m.ReadStr("v"));
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_plat_jar = "plat_jar", Invk_plat_url = "plat_url";
}

View File

@@ -0,0 +1,34 @@
/*
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.apps.apis.xowa.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.apis.xowa.bldrs.filters.*;
import gplx.xowa.apps.apis.xowa.bldrs.imports.*;
import gplx.xowa.apps.apis.xowa.bldrs.runners.*;
public class Xoapi_bldr_wiki implements Gfo_invk {
public void Ctor_by_app(Xoa_app app) {
runner.Ctor_by_app(app);
}
public Xoapi_import Import() {return import_api;} private final Xoapi_import import_api = new Xoapi_import();
public Xoapi_runner Runner() {return runner;} private final Xoapi_runner runner = new Xoapi_runner();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_import)) return import_api;
else if (ctx.Match(k, Invk_runner)) return runner;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_import = "import", Invk_runner = "runner";
}

View File

@@ -0,0 +1,49 @@
/*
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.apps.apis.xowa.bldrs.filters.titles; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.bldrs.*; import gplx.xowa.apps.apis.xowa.bldrs.filters.*;
public class Xoapi_title implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {
// wordlist_dir = app.Fsys_mgr().Bin_xtns_dir().GenSubDir_nest("xowa", "DansGuardian");
}
public boolean Enabled() {return enabled;} private boolean enabled = Bool_.Y;
public Io_url Wordlist_dir() {return wordlist_dir;} private Io_url wordlist_dir;
public int Score_init() {return score_init;} private int score_init = 0;
public int Score_pass() {return score_pass;} private int score_pass = 0;
public boolean Log_enabled() {return log_enabled;} private boolean log_enabled = Bool_.Y;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.To_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_wordlist_dir)) return Int_.To_str(score_init);
else if (ctx.Match(k, Invk_wordlist_dir_)) wordlist_dir= m.ReadIoUrl("v");
else if (ctx.Match(k, Invk_score_init)) return Int_.To_str(score_init);
else if (ctx.Match(k, Invk_score_init_)) score_init = m.ReadInt("v");
else if (ctx.Match(k, Invk_score_pass)) return Int_.To_str(score_pass);
else if (ctx.Match(k, Invk_score_pass_)) score_pass = m.ReadInt("v");
else if (ctx.Match(k, Invk_log_enabled)) return Yn.To_str(enabled);
else if (ctx.Match(k, Invk_log_enabled_)) log_enabled = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_enabled = "enabled" , Invk_enabled_ = "enabled_"
, Invk_wordlist_dir = "wordlist_dir" , Invk_wordlist_dir_ = "wordlist_dir_"
, Invk_score_init = "score_init" , Invk_score_init_ = "score_init_"
, Invk_score_pass = "score_pas" , Invk_score_pass_ = "score_pass_"
, Invk_log_enabled = "log_enabled" , Invk_log_enabled_ = "log_enabled_"
;
}

View File

@@ -0,0 +1,36 @@
/*
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.apps.apis.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.bldrs.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.xowa.wikis.data.*;
public class Xoapi_import implements Gfo_invk {
public long Cat_link_db_max() {return cat_link_db_max;} private long cat_link_db_max = Io_size_.To_long_by_int_mb(1500); // 3.6 GB; v1
public String User_name() {return user_name;} private String user_name = "anonymous";
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_cat_link_db_max)) return Io_size_.To_str_mb(cat_link_db_max);
else if (ctx.Match(k, Invk_cat_link_db_max_)) cat_link_db_max = Io_size_.To_long_by_msg_mb(m, cat_link_db_max);
else if (ctx.Match(k, Invk_user_name)) return user_name;
else if (ctx.Match(k, Invk_user_name_)) user_name = m.ReadStr("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_cat_link_db_max = "cat_link_db_max" , Invk_cat_link_db_max_ = "cat_link_db_max_"
, Invk_user_name = "user_name" , Invk_user_name_ = "user_name_"
;
}

View File

@@ -0,0 +1,47 @@
/*
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.apps.apis.xowa.bldrs.runners; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.bldrs.*;
public class Xoapi_runner implements Gfo_invk {
// private Xoa_app app;
public void Ctor_by_app(Xoa_app app) {}//this.app = app;}
private void Exec(GfoMsg msg) {
// int len = msg.Args_count();
// String cmd = (String)msg.Args_getAt(0).Val();
// Keyval[] args = new Keyval[len - 1];
// for (int i = 1; i < len; ++i) {
// String arg = (String)msg.Args_getAt(i).Val();
// int eq_pos = String_.FindFwd(arg, "=");
// String key = String_.Mid(arg, 0, eq_pos);
// String val = String_.Mid(arg, eq_pos + 1);
// args[i - 1] = Keyval_.new_(key, val);
// }
// gplx.core.ios.zips.Io_zip_decompress_task task = new gplx.core.ios.zips.Io_zip_decompress_task();
// task.Init(true, Gfo
// app.Gui__cbk_mgr().Send_prog("test", "key_0", "val_0");
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_exec)) Exec(m);
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_exec = "exec";
}
// class Xodl_prog_ui : gplx.core.progs.Gfo_prog_ui {
// public void Prog__update_val(long cur, long max) {}
// public void Prog__end() {}
// }

View File

@@ -0,0 +1,53 @@
/*
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.apps.apis.xowa.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.apis.xowa.gui.browsers.*;
public class Xoapi_browser implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {
url.Init_by_kit(app);
tabs.Init_by_kit(app);
html.Init_by_kit(app);
search.Init_by_kit(app);
find.Init_by_kit(app);
prog.Init_by_kit(app);
info.Init_by_kit(app);
prog_log.Init_by_kit(app);
}
public Xoapi_url Url() {return url;} private Xoapi_url url = new Xoapi_url();
public Xoapi_tabs Tabs() {return tabs;} private Xoapi_tabs tabs = new Xoapi_tabs();
public Xoapi_html_box Html() {return html;} private Xoapi_html_box html = new Xoapi_html_box();
public Xoapi_search Search() {return search;} private Xoapi_search search = new Xoapi_search();
public Xoapi_find Find() {return find;} private Xoapi_find find = new Xoapi_find();
public Xoapi_prog Prog() {return prog;} private Xoapi_prog prog = new Xoapi_prog();
public Xoapi_info Info() {return info;} private Xoapi_info info = new Xoapi_info();
public Xoapi_prog_log Prog_log() {return prog_log;} private Xoapi_prog_log prog_log = new Xoapi_prog_log();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_url)) return url;
else if (ctx.Match(k, Invk_tabs)) return tabs;
else if (ctx.Match(k, Invk_html)) return html;
else if (ctx.Match(k, Invk_search)) return search;
else if (ctx.Match(k, Invk_find)) return find;
else if (ctx.Match(k, Invk_prog)) return prog;
else if (ctx.Match(k, Invk_info)) return info;
else if (ctx.Match(k, Invk_prog_log)) return prog_log;
else return Gfo_invk_.Rv_unhandled;
}
private static final String
Invk_url = "url", Invk_tabs = "tabs", Invk_html = "html", Invk_search = "search"
, Invk_find = "find", Invk_prog = "prog", Invk_info = "info", Invk_prog_log = "prog_log";
}

View File

@@ -0,0 +1,51 @@
/*
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.apps.apis.xowa.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.cfgs.*; import gplx.xowa.htmls.*;
public class Xoapi_font implements Gfo_invk {
private Xoae_app app;
public void Init_by_kit(Xoae_app app) {
this.app = app;
}
public void Increase() {Adj(1);}
public void Decrease() {Adj(-1);}
public void Reset() {Set(false, Xoh_page_mgr.Font_size_default, Xocfg_win.Font_size_default);}
public void Adj(int adj) {
float html_font_size = app.Html_mgr().Page_mgr().Font_size() + adj;
float gui_font_size = app.Gui_mgr().Win_cfg().Font().Size() + adj; // (html_font_size * .75f) - 4; // .75f b/c 16px = 12 pt; -4 b/c gui font is currently 4 pt smaller
if (html_font_size < 1 || gui_font_size < 1) return;
Set(true, html_font_size, gui_font_size);
}
private void Set(boolean enabled, float html_font_size, float gui_font_size) {
if (html_font_size <= 0) return; // font must be positive
app.Cfg().Set_bool_app(gplx.xowa.htmls.Xoh_page_mgr.Cfg__font_enabled, enabled);
app.Cfg().Set_float_app(gplx.xowa.htmls.Xoh_page_mgr.Cfg__font_size, html_font_size);
app.Cfg().Set_float_app(gplx.xowa.guis.langs.Xol_font_info.Cfg__font_size, gui_font_size);
app.Gui_mgr().Browser_win().Page__reload(); // NOTE: force reload; needed if viewing home/wiki/Options/HTML, else Font size won't update
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_increase)) this.Increase();
else if (ctx.Match(k, Invk_decrease)) this.Decrease();
else if (ctx.Match(k, Invk_reset)) this.Reset();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_increase = "increase", Invk_decrease = "decrease", Invk_reset = "reset"
;
}

View File

@@ -0,0 +1,36 @@
/*
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.apps.apis.xowa.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.apis.xowa.gui.pages.*;
public class Xoapi_page implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {
view.Init_by_kit(app);
selection.Init_by_kit(app);
edit.Init_by_kit(app);
}
public Xoapi_view View() {return view;} private Xoapi_view view = new Xoapi_view();
public Xoapi_edit Edit() {return edit;} private Xoapi_edit edit = new Xoapi_edit();
public Xoapi_selection Selection() {return selection;} private Xoapi_selection selection = new Xoapi_selection();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_view)) return view;
else if (ctx.Match(k, Invk_selection)) return selection;
else if (ctx.Match(k, Invk_edit)) return edit;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_view = "view", Invk_selection = "selection", Invk_edit = "edit";
}

View File

@@ -0,0 +1,92 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
public class Xoapi_find implements Gfo_invk {
private Xog_find_box find_box;
public void Init_by_kit(Xoae_app app) {
find_box = new Xog_find_box(app);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_show)) find_box.Show();
else if (ctx.Match(k, Invk_show_by_paste)) find_box.Show_by_paste();
else if (ctx.Match(k, Invk_exec)) find_box.Exec();
else if (ctx.Match(k, Invk_type)) find_box.Exec(); // NOTE: same as exec; provided so that exec doesn't accidentally overwrite auto-type for find
else if (ctx.Match(k, Invk_find_fwd)) find_box.Exec_by_dir(Bool_.Y);
else if (ctx.Match(k, Invk_find_bwd)) find_box.Exec_by_dir(Bool_.N);
else if (ctx.Match(k, Invk_case_toggle)) find_box.Case_toggle();
else if (ctx.Match(k, Invk_wrap_toggle)) find_box.Wrap_toggle();
else if (ctx.Match(k, Invk_hide)) find_box.Hide();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_show = "show", Invk_show_by_paste = "show_by_paste", Invk_hide = "hide", Invk_exec = "exec", Invk_type = "type"
, Invk_find_bwd = "find_bwd", Invk_find_fwd = "find_fwd", Invk_case_toggle = "case_toggle", Invk_wrap_toggle = "wrap_toggle";
}
class Xog_find_box {
private Xoae_app app; private Xog_win_itm win; private GfuiTextBox find_box;
private String prv_find_text = ""; // NOTE: must set to "", else will fail during Hide
private boolean dir_fwd = true, case_match = false, wrap_search = true;
public Xog_find_box(Xoae_app app) {
this.app = app;
this.win = app.Gui_mgr().Browser_win();
this.find_box = win.Find_box();
}
public void Show() {app.Gui_mgr().Layout().Find_show();}
public void Hide() {
app.Gui_mgr().Layout().Find_close();
Xog_tab_itm tab = win.Tab_mgr().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
if (tab.View_mode() == Xopg_page_.Tid_read) // do not fire find("") for edit / html, else focus issues; DATE:2015-06-10
Exec_find(prv_find_text, Bool_.N);
}
public void Show_by_paste() {
this.Show();
if (win.Tab_mgr().Active_tab_is_null()) return; // if no active_tab, just show box; don't try to copy what's on tab;
find_box.Text_(win.Active_html_itm().Html_selected_get_text_or_href());
}
public void Exec_by_dir(boolean fwd) {
boolean changed = dir_fwd != fwd;
dir_fwd = fwd;
Exec();
if (changed) // clicking on buttons calls Exec_by_dir; in case of repeated clicks on same button, don't flash changed message again
win.Usr_dlg().Prog_direct("Find direction changed to " + (fwd ? "forward" : "backward"));
}
public void Exec() {
prv_find_text = find_box.Text();
Exec_find(prv_find_text, Bool_.Y);
}
private void Exec_find(String find, boolean highlight_matches) {
Xog_tab_itm tab = win.Tab_mgr().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
find = String_.Replace(find, "\\", "\\\\"); // NOTE: backslashes are always literal, never escape codes; EX: "C:\new" "\n" means "\n", not (byte)10; DATE:2015-08-17
boolean find_in_hdoc = tab.View_mode() == Xopg_page_.Tid_read;
if (find_in_hdoc)
tab.Html_box().Html_js_eval_proc_as_str(Xog_js_procs.Win__find_in_hdoc , find, dir_fwd, case_match, wrap_search, highlight_matches);
else
tab.Html_box().Html_js_eval_proc_as_str(Xog_js_procs.Win__find_in_textarea , find, dir_fwd, case_match, wrap_search);
win.Usr_dlg().Prog_direct("");
}
public void Case_toggle() {
case_match = !case_match;
win.Usr_dlg().Prog_direct("Case match " + (case_match ? "enabled" : "disabled"));
}
public void Wrap_toggle() {
wrap_search = !wrap_search;
win.Usr_dlg().Prog_direct("Wrap search " + (wrap_search ? "enabled" : "disabled"));
}
}

View File

@@ -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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
public class Xoapi_html_box implements Gfo_invk {
private Xog_win_itm win;
public void Init_by_kit(Xoae_app app) {this.win = app.Gui_mgr().Browser_win();}
public void Focus() {
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
Gfui_html html_box = tab.Html_itm().Html_box();
html_box.Focus();
if (tab.View_mode() != Xopg_page_.Tid_read) // if edit / html, place focus in edit box
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__elem_focus, Xog_html_itm.Elem_id__xowa_edit_data_box);
}
public void Selection_focus() {
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
Gfui_html html_box = tab.Html_itm().Html_box();
html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__toggle_focus_for_anchor);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
else if (ctx.Match(k, Invk_selection_focus_toggle)) this.Selection_focus();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_selection_focus_toggle = "selection_focus_toggle";
}

View File

@@ -0,0 +1,37 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.guis.views.*;
public class Xoapi_info implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {this.app = app;} private Xoae_app app;
private Xog_win_itm Win() {return app.Gui_mgr().Browser_win();}
public void Focus() {this.Win().Info_box().Focus();}
public void Clear() {app.Usr_dlg().Gui_wkr().Clear();}
public void Launch() {
Io_url session_fil = app.Log_wtr().Session_fil();
app.Prog_mgr().App_view_text().Run(session_fil);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
else if (ctx.Match(k, Invk_clear)) this.Clear();
else if (ctx.Match(k, Invk_launch)) this.Launch();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_clear = "clear", Invk_launch = "launch";
}

View File

@@ -0,0 +1,31 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.guis.views.*;
public class Xoapi_prog implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {this.app = app;} private Xoae_app app;
private Xog_win_itm Win() {return app.Gui_mgr().Browser_win();}
public void Focus() {this.Win().Prog_box().Focus();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus";
}

View File

@@ -0,0 +1,29 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.guis.views.*;
public class Xoapi_prog_log implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {this.app = app;} private Xoae_app app;
public void Show() {app.Gui_mgr().Show_prog();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_show)) this.Show();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_show = "show";
}

View File

@@ -0,0 +1,34 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.controls.standards.*; import gplx.xowa.guis.views.*;
public class Xoapi_search implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {this.app = app;} private Xoae_app app;
private GfuiTextBox Search_box() {return app.Gui_mgr().Browser_win().Search_box();}
private Xog_win_itm Win() {return app.Gui_mgr().Browser_win();}
public void Focus() {this.Search_box().Focus_select_all();}
public void Exec() {this.Win().Page__navigate_by_search();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
else if (ctx.Match(k, Invk_exec)) this.Exec();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus";
public static final String Invk_exec = "exec";
}

View File

@@ -0,0 +1,90 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.xowa.guis.views.*;
public class Xoapi_tabs implements Gfo_invk {
private Xog_tab_mgr tab_mgr;
public void Init_by_kit(Xoae_app app) {
this.tab_mgr = app.Gui_mgr().Browser_win().Tab_mgr();
}
private boolean Active_tab_is_null() {return tab_mgr.Active_tab_is_null();}
public void New_dupe(boolean focus) {tab_mgr.Tabs_new_dupe(focus);}
public void New_dflt(boolean focus) {tab_mgr.Tabs_new_dflt(focus);}
public void New_link(boolean focus, String link) {tab_mgr.Tabs_new_link(focus, link);}
public void New_href(boolean focus) {
Xog_tab_itm tab = tab_mgr.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
String link = tab.Html_itm().Html_selected_get_href_or_text();
if (String_.Len_eq_0(link)) {tab_mgr.Win().Usr_dlg().Prog_many("", "", "no link or text selected"); return;}
tab_mgr.Tabs_new_dflt(true);
tab_mgr.Win().Page__navigate_by_url_bar(link);
}
public void Close_cur() {tab_mgr.Tabs_close_cur();}
public void Select_bwd() {tab_mgr.Tabs_select(Bool_.N);}
public void Select_fwd() {tab_mgr.Tabs_select(Bool_.Y);}
public void Select_by_idx(int v) {tab_mgr.Tabs_select_by_idx(v - List_adp_.Base1);}
public void Move_bwd() {tab_mgr.Tabs_move(Bool_.N);}
public void Move_fwd() {tab_mgr.Tabs_move(Bool_.Y);}
public void Close_others() {tab_mgr.Tabs_close_others();}
public void Close_to_bgn() {tab_mgr.Tabs_close_to_bgn();}
public void Close_to_end() {tab_mgr.Tabs_close_to_end();}
public void Close_undo() {tab_mgr.Tabs_close_undo();}
public void Pin_toggle() {if (this.Active_tab_is_null()) return; tab_mgr.Active_tab().Pin_toggle();}
public void Tab_bookmark_all() {}//app.Gui_mgr().Browser_win().Tab_mgr().Tabs_close_others();}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_new_dflt__at_dflt__focus_y)) this.New_dflt(Bool_.Y);
else if (ctx.Match(k, Invk_new_link__at_dflt__focus_n)) this.New_link(Bool_.N, m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_new_link__at_dflt__focus_y)) this.New_link(Bool_.Y, m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_new_href__at_dflt__focus_y)) this.New_href(Bool_.Y);
else if (ctx.Match(k, Invk_new_dupe__at_dflt__focus_y)) this.New_dupe(Bool_.Y);
else if (ctx.Match(k, Invk_close_cur)) this.Close_cur();
else if (ctx.Match(k, Invk_select_bwd)) this.Select_bwd();
else if (ctx.Match(k, Invk_select_fwd)) this.Select_fwd();
else if (ctx.Match(k, Invk_move_bwd)) this.Move_bwd();
else if (ctx.Match(k, Invk_move_fwd)) this.Move_fwd();
else if (ctx.Match(k, Invk_close_others)) this.Close_others();
else if (ctx.Match(k, Invk_close_to_bgn)) this.Close_to_bgn();
else if (ctx.Match(k, Invk_close_to_end)) this.Close_to_end();
else if (ctx.Match(k, Invk_close_undo)) this.Close_undo();
else if (ctx.Match(k, Invk_pin_toggle)) this.Pin_toggle();
else if (ctx.Match(k, Invk_select_by_idx_1)) this.Select_by_idx(1);
else if (ctx.Match(k, Invk_select_by_idx_2)) this.Select_by_idx(2);
else if (ctx.Match(k, Invk_select_by_idx_3)) this.Select_by_idx(3);
else if (ctx.Match(k, Invk_select_by_idx_4)) this.Select_by_idx(4);
else if (ctx.Match(k, Invk_select_by_idx_5)) this.Select_by_idx(5);
else if (ctx.Match(k, Invk_select_by_idx_6)) this.Select_by_idx(6);
else if (ctx.Match(k, Invk_select_by_idx_7)) this.Select_by_idx(7);
else if (ctx.Match(k, Invk_select_by_idx_8)) this.Select_by_idx(8);
else if (ctx.Match(k, Invk_select_by_idx_9)) this.Select_by_idx(9);
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_new_dflt__at_dflt__focus_y = "new_dflt__at_dflt__focus_y"
, Invk_new_link__at_dflt__focus_n = "new_link__at_dflt__focus_n"
, Invk_new_link__at_dflt__focus_y = "new_link__at_dflt__focus_y"
, Invk_new_href__at_dflt__focus_y = "new_href__at_dflt__focus_y"
, Invk_new_dupe__at_dflt__focus_y = "new_dupe__at_dflt__focus_y"
, Invk_close_cur = "close_cur"
, Invk_select_bwd = "select_bwd", Invk_select_fwd = "select_fwd"
, Invk_move_bwd = "move_bwd", Invk_move_fwd = "move_fwd"
, Invk_close_others = "close_others", Invk_close_to_bgn = "close_to_bgn", Invk_close_to_end = "close_to_end", Invk_close_undo = "close_undo"
, Invk_pin_toggle = "pin_toggle"
, Invk_select_by_idx_1 = "select_by_idx_1", Invk_select_by_idx_2 = "select_by_idx_2", Invk_select_by_idx_3 = "select_by_idx_3", Invk_select_by_idx_4 = "select_by_idx_4", Invk_select_by_idx_5 = "select_by_idx_5"
, Invk_select_by_idx_6 = "select_by_idx_6", Invk_select_by_idx_7 = "select_by_idx_7", Invk_select_by_idx_8 = "select_by_idx_8", Invk_select_by_idx_9 = "select_by_idx_9"
;
}

View File

@@ -0,0 +1,81 @@
/*
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.apps.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.envs.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.guis.views.*; import gplx.core.envs.*;
public class Xoapi_url implements Gfo_invk {
private Xoae_app app;
public void Init_by_kit(Xoae_app app) {
this.app = app;
}
private GfuiComboBox Url_box() {return app.Gui_mgr().Browser_win().Url_box();}
public void Focus() {this.Url_box().Focus(); this.Url_box().Sel_(0, String_.Len(this.Url_box().Text()));}
public void Exec() {Exec_wkr(Bool_.N, this.Url_box().Text());}
public void Exec_by_paste() {Exec_wkr(Bool_.N, ClipboardAdp_.GetText());}
public void Exec_new_tab_by_paste() {Exec_wkr(Bool_.Y, ClipboardAdp_.GetText());}
public void Restore() {
Xog_tab_itm tab = app.Gui_mgr().Browser_win().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
this.Url_box().Text_(tab.Page().Url().To_str());
}
void Type() {
app.Addon_mgr().Itms__search__urlbar().Search();
}
private void Exec_wkr(boolean new_tab, String urls_text) {
if (Op_sys.Cur().Tid_is_wnt())
urls_text = String_.Replace(urls_text, Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
String[] urls = String_.Split(String_.Trim(urls_text), Op_sys.Lnx.Nl_str());
int urls_len = urls.length;
if (urls_len == 0) return;
if (urls_len == 1) { // 1 url; most cases
String url = urls[0];
gplx.core.threads.Thread_adp_.Sleep(1); // HACK: sleep 1 ms, else rapid keystrokes may cause last keystroke to not register; EX: typing "w:" may show just "w" instead of "w:"; DATE:2016-03-27
GfuiComboBox combo = this.Url_box();
String[] itms_ary = combo.DataSource_as_str_ary();
if ( itms_ary.length > 0 // results exist...
&& combo.List_visible()) { // and dropdown is visible; use selected-item
int sel_idx = combo.List_sel_idx(); // get selected item
if (sel_idx == -1) sel_idx = 0; // if nothing selected, default to 1st; allows typing first few characters and picking 1st item from list
String itms_sel = itms_ary[sel_idx];
// if (String_.Has(String_.Lower(itms_sel), String_.Lower(url))) // make sure itms_sel contains url; handles slow machines, where dropdown may not be updated yet
url = Xog_win_itm.Remove_redirect_if_exists(itms_sel);
}
combo.Text_(url);
app.Gui_mgr().Browser_win().Page__navigate_by_url_bar(url);
}
else {
for (int i = 0; i < urls_len; i++) {
String url = urls[i];
if (String_.Has_at_bgn(url, "\"") && String_.Has_at_bgn(url, "\""))
url = String_.Mid(url, 1, String_.Len(url) - 1);
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_link(url, false);
}
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_focus)) this.Focus();
else if (ctx.Match(k, Invk_exec)) this.Exec();
else if (ctx.Match(k, Invk_exec_by_paste)) this.Exec_by_paste();
else if (ctx.Match(k, Invk_exec_new_tab_by_paste)) this.Exec_new_tab_by_paste();
else if (ctx.Match(k, Invk_restore)) this.Restore();
else if (ctx.Match(k, Invk_type)) this.Type();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_exec_by_paste = "exec_by_paste", Invk_exec_new_tab_by_paste = "exec_new_tab_by_paste", Invk_restore = "restore", Invk_type = "type";
public static final String Invk_exec = "exec";
}

View File

@@ -0,0 +1,58 @@
/*
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.apps.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.kits.core.*;
import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*;
public class Xoapi_edit implements Gfo_invk {
private Xog_win_itm win;
public void Init_by_kit(Xoae_app app) {
win = app.Gui_mgr().Browser_win();
}
private boolean Active_tab_is_null() {return win.Tab_mgr().Active_tab_is_null();}
private boolean Active_tab_is_edit() {return !win.Tab_mgr().Active_tab_is_null() && win.Tab_mgr().Active_tab().View_mode() == Xopg_page_.Tid_edit;}
public void Copy() {if (Active_tab_is_null()) return; win.Kit().Clipboard().Copy(win.Active_html_itm().Html_selected_get_text_or_href());}
public void Select_all() {if (Active_tab_is_null()) return; Gfo_invk_.Invk_by_key(win.Win_box().Kit().Clipboard(), Gfui_clipboard_.Invk_select_all);}
public void Save() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Save(win.Active_tab(), false);}
public void Save_draft() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Save(win.Active_tab(), true);}
public void Preview() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Preview(win.Active_tab());}
public void Dbg_tmpl() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xopg_page_.Tid_edit);}
public void Dbg_html() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xopg_page_.Tid_html);}
public void Focus_edit_box(){if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Focus(win, Xog_html_itm.Elem_id__xowa_edit_data_box);}
public void Exec() {
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_copy)) this.Copy();
else if (ctx.Match(k, Invk_select_all)) this.Select_all();
else if (ctx.Match(k, Invk_save)) this.Save();
else if (ctx.Match(k, Invk_save_draft)) this.Save_draft();
else if (ctx.Match(k, Invk_preview)) this.Preview();
else if (ctx.Match(k, Invk_focus_edit_box)) this.Focus_edit_box();
else if (ctx.Match(k, Invk_dbg_tmpl)) this.Dbg_tmpl();
else if (ctx.Match(k, Invk_dbg_html)) this.Dbg_html();
else if (ctx.Match(k, Invk_exec)) this.Exec();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_copy = "copy"
, Invk_select_all = "select_all"
, Invk_save = "save", Invk_save_draft = "save_draft", Invk_preview = "preview"
, Invk_focus_edit_box = "focus_edit_box"
, Invk_dbg_tmpl = "dbg_tmpl", Invk_dbg_html = "dbg_html", Invk_exec = "exec"
;
}

View File

@@ -0,0 +1,52 @@
/*
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.apps.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; import gplx.core.envs.*;
public class Xoapi_selection implements Gfo_invk {
private Xoae_app app; private Xog_win_itm win;
public void Init_by_kit(Xoae_app app) {
this.app = app;
win = app.Gui_mgr().Browser_win();
}
private boolean Active_tab_is_null() {return win.Tab_mgr().Active_tab_is_null();}
public void Copy() {if (Active_tab_is_null()) return; win.Kit().Clipboard().Copy(win.Active_html_itm().Html_selected_get_text_or_href());}
public void Select_all() {if (Active_tab_is_null()) return; Gfo_invk_.Invk_by_key(win.Win_box().Kit().Clipboard(), Gfui_clipboard_.Invk_select_all);}
public void Save_file_as() {
if (this.Active_tab_is_null()) return;
Xog_html_itm html_itm = win.Tab_mgr().Active_tab().Html_itm();
String src = html_itm.Html_selected_get_src_or_empty();
if (String_.Len_eq_0(src)) {app.Usr_dlg().Prog_many("", "", "no file selected: tab=~{0}", html_itm.Owner_tab().Page().Url().To_str()); return;}
Io_url src_url = Io_url_.New__http_or_fail(src);
String trg_name = src_url.NameAndExt();
if (String_.Has(src, "/thumb/")) trg_name = src_url.OwnerDir().NameOnly();
String trg = app.Gui_mgr().Kit().New_dlg_file(Gfui_kit_.File_dlg_type_save, "Select file to save to:").Init_file_(trg_name).Ask();
if (String_.Len_eq_0(trg)) return;
Io_url trg_url = Io_url_.new_fil_(trg);
Io_mgr.Instance.CopyFil(src_url, trg_url, true);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_copy)) this.Copy();
else if (ctx.Match(k, Invk_select_all)) this.Select_all();
else if (ctx.Match(k, Invk_save_file_as)) this.Save_file_as();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_copy = "copy", Invk_select_all = "select_all", Invk_save_file_as = "save_file_as"
;
}

View File

@@ -0,0 +1,63 @@
/*
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.apps.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*;
import gplx.langs.htmls.encoders.*;
public class Xoapi_view implements Gfo_invk {
private Xoae_app app; private Xog_win_itm win;
private final Gfo_url_encoder fsys_encoder = Gfo_url_encoder_.New__fsys_wnt().Make();
public void Init_by_kit(Xoae_app app) {
this.app = app; this.win = app.Gui_mgr().Browser_win();
}
private boolean Active_tab_is_null() {return win.Tab_mgr().Active_tab_is_null();}
public void Mode_read() {Mode(Xopg_page_.Tid_read);}
public void Mode_edit() {Mode(Xopg_page_.Tid_edit);}
public void Mode_html() {Mode(Xopg_page_.Tid_html);}
private void Mode(byte v) {if (Active_tab_is_null()) return; win.Page__mode_(v);}
public void Reload() {if (Active_tab_is_null()) return; win.Page__reload();}
public void Refresh() {if (Active_tab_is_null()) return; win.Page__refresh();}
public void Print() {
if (this.Active_tab_is_null()) return;
win.Active_html_box().Html_js_eval_proc_as_str(Xog_js_procs.Win__print_preview);
}
public void Save_as() {
if (this.Active_tab_is_null()) return;
Xog_tab_itm tab = win.Tab_mgr().Active_tab();
String file_name = fsys_encoder.Encode_str(String_.new_u8(tab.Page().Ttl().Full_url())) + ".html";
String file_url = app.Gui_mgr().Kit().New_dlg_file(Gfui_kit_.File_dlg_type_save, "Select file to save to:").Init_file_(file_name).Ask();
if (String_.Len_eq_0(file_url)) return;
Io_mgr.Instance.SaveFilStr(file_url, tab.Html_box().Text());
app.Usr_dlg().Prog_many("", "", "saved page: file=~{0}", file_url);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_mode_read)) this.Mode_read();
else if (ctx.Match(k, Invk_mode_edit)) this.Mode_edit();
else if (ctx.Match(k, Invk_mode_html)) this.Mode_html();
else if (ctx.Match(k, Invk_reload)) this.Reload();
else if (ctx.Match(k, Invk_refresh)) this.Refresh();
else if (ctx.Match(k, Invk_print)) this.Print();
else if (ctx.Match(k, Invk_save_as)) this.Save_as();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_mode_read = "mode_read", Invk_mode_edit = "mode_edit", Invk_mode_html = "mode_html"
, Invk_reload = "reload", Invk_refresh = "refresh"
, Invk_print = "print", Invk_save_as = "save_as"
;
}

View File

@@ -0,0 +1,30 @@
/*
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.apps.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.apis.xowa.html.modules.*;
public class Xoapi_modules implements Gfo_invk {
public void Init_by_kit(Xoae_app app) {
popups.Init_by_app(app);
}
public Xoapi_popups Popups() {return popups;} private Xoapi_popups popups = new Xoapi_popups();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_popups)) return popups;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_popups = "popups";
}

View File

@@ -0,0 +1,30 @@
/*
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.apps.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
public class Xoapi_page implements Gfo_invk {
public void Ctor_by_app(Xoae_app app) {
toggle_mgr.Ctor_by_app(app);
}
public void Init_by_app(Xoae_app app) {toggle_mgr.Init_by_app(app);}
public Xoapi_toggle_mgr Toggle_mgr() {return toggle_mgr;} private final Xoapi_toggle_mgr toggle_mgr = new Xoapi_toggle_mgr();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_toggles)) return toggle_mgr;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_toggles = "toggles";
}

View File

@@ -0,0 +1,91 @@
/*
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.apps.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.core.brys.fmtrs.*;
public class Xoapi_toggle_itm {
private final Xoae_app app; // NOTE: needed to get "img_dir" below
private byte[] img_title_val_y, img_title_val_n;
public Xoapi_toggle_itm(Xoae_app app, byte[] key_bry) {
this.app = app; this.key_bry = key_bry;
}
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
public byte[] Heading_bry() {return heading_bry;} private byte[] heading_bry;
public byte[] Icon_src() {return icon_src;} private byte[] icon_src = Bry_.Empty;
public byte[] Icon_title() {return icon_title;} private byte[] icon_title = Bry_.Empty;
public byte[] Elem_display() {return elem_display;} private byte[] elem_display = Bry_.Empty;
public byte[] Html_toggle_hdr_cls() {return html_toggle_hdr_cls;} public Xoapi_toggle_itm Html_toggle_hdr_cls_(byte[] v) {html_toggle_hdr_cls = v; return this;} private byte[] html_toggle_hdr_cls = Bry_.Empty;
public boolean Visible() {return visible;} private boolean visible;
public void Visible_(boolean v) {
this.visible = v;
Html_toggle_gen();
}
public Xoapi_toggle_itm Init(byte[] heading_bry) {
this.heading_bry = heading_bry; // NOTE: sets "Wikis" or "In other languages"; Wikidata twisties are empty;
this.icon_title = app.Usere().Msg_mgr().Val_by_key_obj(visible ? Img_title_msg_y : Img_title_msg_n); // set title ("show" or "hide")
Html_toggle_gen();
return this;
}
public Xoapi_toggle_itm Init_fsys(Io_url img_dir) {
if (Img_src_y == null) {
Img_src_y = img_dir.GenSubFil("twisty_down.png").To_http_file_bry();
Img_src_n = img_dir.GenSubFil("twisty_right.png").To_http_file_bry();
}
return this;
}
public void Init_msgs(byte[] img_title_val_y, byte[] img_title_val_n) {
this.img_title_val_y = img_title_val_y;
this.img_title_val_n = img_title_val_n;
Html_toggle_gen();
}
public byte[] Html_toggle_btn() {return html_toggle_btn;} private byte[] html_toggle_btn;
public byte[] Html_toggle_hdr() {return html_toggle_hdr;} private byte[] html_toggle_hdr;
private void Assert_img_src() {
if (Img_src_y == null) {
Io_url img_dir = app.Fsys_mgr().Bin_xowa_file_dir().GenSubDir_nest("app.general");
Img_src_y = img_dir.GenSubFil("twisty_down.png").To_http_file_bry();
Img_src_n = img_dir.GenSubFil("twisty_right.png").To_http_file_bry();
}
}
private void Html_toggle_gen() {
Assert_img_src();// NOTE: must call Assert_img_src else wikidata twisties will be missing img; DATE:2015-08-05
if (visible) {
icon_src = Img_src_y;
icon_title = img_title_val_y;
elem_display = Img_display_y;
}
else {
icon_src = Img_src_n;
icon_title = img_title_val_n;
elem_display = Img_display_n;
}
Bry_fmtr fmtr = Bry_fmtr.new_(); Bry_bfr bfr = Bry_bfr_.New_w_size(8);
html_toggle_btn
= fmtr.Fmt_("<a href='javascript:xowa_toggle_visible(\"~{key}\");' style='text-decoration: none !important;'>~{heading}<img id='~{key}-toggle-icon' src='~{src}' title='~{title}' /></a>")
.Keys_("key", "src", "title", "heading").Bld_bry_many(bfr, key_bry, icon_src, icon_title, heading_bry)
;
html_toggle_hdr
= fmtr.Fmt_(" id='~{key}-toggle-elem' style='~{display}~{toggle_hdr_cls}'")
.Keys_("key", "display", "toggle_hdr_cls").Bld_bry_many(bfr, key_bry, elem_display, html_toggle_hdr_cls)
;
}
private static byte[] Img_src_y, Img_src_n; // assume these are the same for all itms
private static final byte[]
Img_title_msg_y = Bry_.new_a7("hide"), Img_title_msg_n = Bry_.new_a7("show")
, Img_display_y = Bry_.new_a7("display:;"), Img_display_n = Bry_.new_a7("display:none;")
;
}

View File

@@ -0,0 +1,101 @@
/*
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.apps.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.apps.cfgs.*;
public class Xoapi_toggle_mgr implements Gfo_invk {
private Xoae_app app;
private final Ordered_hash hash = Ordered_hash_.New_bry();
public void Ctor_by_app(Xoae_app app) {this.app = app;}
public void Init_by_app(Xoae_app app) {
Io_url img_dir = app.Fsys_mgr().Bin_xowa_file_dir().GenSubDir_nest("app.general");
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Xoapi_toggle_itm itm = (Xoapi_toggle_itm)hash.Get_at(i);
itm.Init_fsys(img_dir);
}
app.Cfg().Bind_many_app(this
, Cfg__toggles__offline_wikis
, Cfg__toggles__wikidata_langs
, Cfg__toggles__claim
, Cfg__toggles__slink_w
, Cfg__toggles__slink_d
, Cfg__toggles__slink_s
, Cfg__toggles__slink_v
, Cfg__toggles__slink_q
, Cfg__toggles__slink_b
, Cfg__toggles__slink_u
, Cfg__toggles__slink_n
, Cfg__toggles__slink_special
, Cfg__toggles__label
, Cfg__toggles__descr
, Cfg__toggles__alias
, Cfg__toggles__json
);
}
public Xoapi_toggle_itm Get_or_new(String key_str) {
byte[] key_bry = Bry_.new_u8(key_str);
Xoapi_toggle_itm rv = (Xoapi_toggle_itm)hash.Get_by(key_bry);
if (rv == null) {
rv = new Xoapi_toggle_itm(app, key_bry);
hash.Add(key_bry, rv);
}
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.MatchIn(k
, Cfg__toggles__offline_wikis
, Cfg__toggles__wikidata_langs
, Cfg__toggles__claim
, Cfg__toggles__slink_w
, Cfg__toggles__slink_d
, Cfg__toggles__slink_s
, Cfg__toggles__slink_v
, Cfg__toggles__slink_q
, Cfg__toggles__slink_b
, Cfg__toggles__slink_u
, Cfg__toggles__slink_n
, Cfg__toggles__slink_special
, Cfg__toggles__label
, Cfg__toggles__descr
, Cfg__toggles__alias
, Cfg__toggles__json)) {
this.Get_or_new(String_.Replace(k, "xowa.html.toggles.", "")).Visible_(m.ReadYn("v"));
}
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Cfg__toggles__offline_wikis = "xowa.html.toggles.offline-wikis"
, Cfg__toggles__wikidata_langs = "xowa.html.toggles.wikidata-langs"
, Cfg__toggles__claim = "xowa.html.toggles.wikidatawiki-claim"
, Cfg__toggles__slink_w = "xowa.html.toggles.wikidatawiki-slink-wikipedia"
, Cfg__toggles__slink_d = "xowa.html.toggles.wikidatawiki-slink-wiktionary"
, Cfg__toggles__slink_s = "xowa.html.toggles.wikidatawiki-slink-wikisource"
, Cfg__toggles__slink_v = "xowa.html.toggles.wikidatawiki-slink-wikivoyage"
, Cfg__toggles__slink_q = "xowa.html.toggles.wikidatawiki-slink-wikiquote"
, Cfg__toggles__slink_b = "xowa.html.toggles.wikidatawiki-slink-wikibooks"
, Cfg__toggles__slink_u = "xowa.html.toggles.wikidatawiki-slink-wikiversity"
, Cfg__toggles__slink_n = "xowa.html.toggles.wikidatawiki-slink-wikinews"
, Cfg__toggles__slink_special = "xowa.html.toggles.wikidatawiki-slink-special"
, Cfg__toggles__label = "xowa.html.toggles.wikidatawiki-label"
, Cfg__toggles__descr = "xowa.html.toggles.wikidatawiki-descr"
, Cfg__toggles__alias = "xowa.html.toggles.wikidatawiki-alias"
, Cfg__toggles__json = "xowa.html.toggles.wikidatawiki-json"
;
}

View File

@@ -0,0 +1,44 @@
/*
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.apps.apis.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.html.*;
import gplx.xowa.htmls.modules.popups.*;
public class Xoapi_popups implements Gfo_invk, Gfo_evt_mgr_owner {
private Xoae_app app;
public Xoapi_popups() {
evt_mgr = new Gfo_evt_mgr(this);
}
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private Gfo_evt_mgr evt_mgr;
public void Init_by_app(Xoae_app app) {this.app = app;}
public void Show_more(String popup_id) {
Xowe_wiki wiki = app.Gui_mgr().Browser_win().Active_tab().Wiki();
wiki.Html_mgr().Head_mgr().Popup_mgr().Show_more(popup_id);
}
public void Show_all(String popup_id) {
Xowe_wiki wiki = app.Gui_mgr().Browser_win().Active_tab().Wiki();
wiki.Html_mgr().Head_mgr().Popup_mgr().Show_all(popup_id);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_show_more)) Show_more(m.ReadStr("popup_id"));
else if (ctx.Match(k, Invk_show_all)) Show_all (m.ReadStr("popup_id"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_show_more = "show_more", Invk_show_all = "show_all"
;
}

View File

@@ -0,0 +1,40 @@
/*
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.apps.apis.xowa.navs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.guis.views.*;
import gplx.xowa.htmls.hrefs.*;
public class Xoapi_nav_wiki implements Gfo_invk {
private Xog_win_itm win;
public void Init_by_kit(Xoae_app app) {
win = app.Gui_mgr().Browser_win();
}
public void Random() {win.Page__navigate_by_url_bar("Special:Random");}
public void Sandbox() {win.Page__navigate_by_url_bar("Project:Sandbox");}
public void Main_page() {
win.Tab_mgr().Active_tab_assert(); // force an active tab in case all tabs are closed; needed for win.Active_page() below; DATE:2014-09-17
win.Page__navigate_by_url_bar(win.Active_tab().Wiki().Domain_str() + Xoh_href_.Str__wiki); // NOTE: add "/wiki/" to generate non-page like url; EX: "home" -> "home/wiki/" which will be interpreted as a url, as opposed to "home" which will be intrepretted as page; DATE:2014-04-14
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_main_page)) this.Main_page();
else if (ctx.Match(k, Invk_random)) this.Random();
else if (ctx.Match(k, Invk_sandbox)) this.Sandbox();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_main_page = "main_page", Invk_random = "random", Invk_sandbox = "sandbox";
}

View File

@@ -0,0 +1,61 @@
/*
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.apps.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.guis.history.*; import gplx.xowa.guis.views.*;
import gplx.xowa.users.bmks.*;
import gplx.xowa.wikis.*;
public class Xoapi_bookmarks implements Gfo_invk {
private Xoae_app app; private Xog_win_itm win;
private boolean enabled = true;
public void Ctor_by_app(Xoae_app app) {this.app = app;}
public void Init_by_kit(Xoae_app app) {
this.win = app.Gui_mgr().Browser_win();
app.Cfg().Bind_many_app(this, Cfg__enabled);
}
public boolean Delete_confirm() {return delete_confirm;} private boolean delete_confirm = true;
public void Show() {win.Page__navigate_by_url_bar("home/wiki/Special:XowaBookmarks");}
public String Add(String url_str) {
if (!enabled) return app.Html__bridge_mgr().Msg_bldr().To_json_str__empty();
Xoa_url url = null;
if (url_str == null) {
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_("bookmark added").To_json_str(); // called by http_server; return success
url = tab.Page().Url();
}
else
url = app.User().Wikii().Utl__url_parser().Parse(Bry_.new_u8(url_str));
app.User().User_db_mgr().Bmk_mgr().Itms__add(Xoud_bmk_mgr.Owner_root, url);
String msg = "bookmark added: " + String_.new_u8(url.Page_bry());
String rv = app.Html__bridge_mgr().Msg_bldr().Clear().Notify_pass_(msg).To_json_str();
win.Active_tab().Html_box().Html_js_eval_proc_as_str("xowa.cmds.exec_by_str", "xowa.notify", "{\"text\":\"" + msg + "\",\"status\":\"success\"}");
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__enabled)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_delete_confirm)) return Yn.To_str(delete_confirm);
else if (ctx.Match(k, Invk_delete_confirm_)) delete_confirm = m.ReadYn("v");
else if (ctx.Match(k, Invk_add)) return this.Add(m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_show)) this.Show();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Invk_delete_confirm = "delete_confirm", Invk_delete_confirm_ = "delete_confirm_"
, Invk_add = "add", Invk_show = "show"
, Cfg__enabled = "xowa.app.bookmarks.enabled"
;
}

View File

@@ -0,0 +1,33 @@
/*
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.apps.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.guis.views.*;
public class Xoapi_history implements Gfo_invk {
private Xoae_app app; private Xog_win_itm win;
public void Ctor_by_app(Xoae_app app) {this.app = app;}
public void Init_by_kit(Xoae_app app) {this.win = app.Gui_mgr().Browser_win();}
public void Goto_recent() {win.Page__navigate_by_url_bar(app.Usere().History_mgr().Get_at_last());}
public void Show() {win.Page__navigate_by_url_bar("home/wiki/Special:XowaPageHistory");}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_goto_recent)) this.Goto_recent();
else if (ctx.Match(k, Invk_show)) this.Show();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_goto_recent = "goto_recent", Invk_show = "show";
}

View File

@@ -0,0 +1,48 @@
/*
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.apps.apis.xowa.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*;
import gplx.xowa.xtns.wbases.*;
public class Xoapi_wikibase implements Gfo_invk, Gfo_evt_mgr_owner {
public Xoapi_wikibase() {
evt_mgr = new Gfo_evt_mgr(this);
}
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private Gfo_evt_mgr evt_mgr;
public byte[][] Core_langs() {return core_langs;} private byte[][] core_langs = Bry_.Ary("en");
public byte[][] Sort_langs() {return sort_langs;} private byte[][] sort_langs = Bry_.Ary("en", "de", "es", "fr", "it", "nl", "pl", "ru", "sv");
public byte[] Link_wikis() {return link_wikis;} private byte[] link_wikis = Bry_.new_a7("enwiki");
public void Init_by_app(Xoae_app app) {
app.Cfg().Bind_many_app(this, Cfg__core_langs, Cfg__link_wikis, Cfg__sort_langs);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__core_langs)) {core_langs = m.ReadBryAry("v", Byte_ascii.Semic); Gfo_evt_mgr_.Pub_val(this, Evt_core_langs_changed, core_langs);}
else if (ctx.Match(k, Cfg__sort_langs)) {sort_langs = m.ReadBryAry("v", Byte_ascii.Semic); Gfo_evt_mgr_.Pub_val(this, Evt_sort_langs_changed, sort_langs);}
else if (ctx.Match(k, Cfg__link_wikis)) {link_wikis = m.ReadBry("v"); Gfo_evt_mgr_.Pub_val(this, Evt_link_wikis_changed, link_wikis);}
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String
Evt_core_langs_changed = "core_langs_changed"
, Evt_sort_langs_changed = "sort_langs_changed"
, Evt_link_wikis_changed = "link_wikis_changed"
;
private static final String
Cfg__core_langs = "xowa.addon.wikibase.langs.core_langs"
, Cfg__sort_langs = "xowa.addon.wikibase.langs.sort_langs"
, Cfg__link_wikis = "xowa.addon.wikibase.xwikis.link_wikis"
;
}

View File

@@ -0,0 +1,125 @@
/*
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.apps.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.consoles.*; import gplx.core.envs.*;
import gplx.dbs.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.xowa.guis.views.boots.*;
import gplx.xowa.langs.*;
import gplx.xowa.users.*;
public class Xoa_boot_mgr {
private Gfo_usr_dlg usr_dlg; private Gfo_usr_dlg__log log_wtr;
public void Run(String[] args, Xoa_cmd_arg_mgr arg_mgr) {
try {
Init_env(args);
if (arg_mgr.Process(usr_dlg, args, Env_.AppUrl().OwnerDir()))
Run_app(arg_mgr);
}
catch (Exception e) {
String err_str = Err_.Message_gplx_full(e);
log_wtr.Log_to_err(err_str);
Console_adp__sys.Instance.Write_str_w_nl(err_str);
if (log_wtr.Log_dir() == null) log_wtr.Log_dir_(Env_.AppUrl().OwnerDir().GenSubFil("xowa.log"));
log_wtr.Queue_enabled_(false);
}
}
private void Init_env(String[] args) {
Gfo_usr_dlg_.Instance = usr_dlg = Xoa_app_.New__usr_dlg__console();
Gfo_log_.Instance__set(new gplx.xowa.apps.shells.Gfo_log__console());
log_wtr = usr_dlg.Log_wkr(); log_wtr.Log_to_session_fmt("env.init: version=~{0}", Xoa_app_.Version);
GfuiEnv_.Init_swt(args, Xoa_app_.class);
Io_url jar_url = Env_.AppUrl();
Xoa_app_.Build_date = Io_mgr.Instance.QueryFil(jar_url).ModifiedTime().XtoUtc().XtoStr_fmt(Xoa_app_.Build_date_fmt);
log_wtr.Log_to_session_fmt("env.init: jar_url=~{0}; build_date=~{1}", jar_url.NameAndExt(), Xoa_app_.Build_date);
log_wtr.Log_to_session_fmt("env.init: op_sys=~{0}", Op_sys.Cur().To_str());
}
private void Run_app(Xoa_cmd_arg_mgr arg_mgr) {
boolean app_type_is_gui = false;
Xoae_app app = null;
try {
// init vars
Io_url root_dir = arg_mgr.Fsys__root_dir();
Xoa_app_.Op_sys_str = arg_mgr.Fsys__bin_dir();
Xoa_app_.User_agent = String_.Format("XOWA/{0} ({1}) [gnosygnu@gmail.com]", Xoa_app_.Version, Xoa_app_.Op_sys_str);
Xoa_app_mode app_type = arg_mgr.App_type();
app_type_is_gui = app_type.Tid_is_gui();
Xog_splash_win splash_win = new Xog_splash_win(app_type_is_gui);
Db_conn_bldr.Instance.Reg_default_sqlite();
// init app
app = new Xoae_app(usr_dlg, app_type
, root_dir
, arg_mgr.Fsys__wiki_dir()
, root_dir.GenSubDir("file")
, arg_mgr.Fsys__user_dir()
, root_dir.GenSubDir_nest("user", "anonymous", "wiki")
, Xoa_app_.Op_sys_str);
app.Addon_mgr().Add_dflts_by_app(app).Run_by_app(app);
usr_dlg.Log_wkr().Queue_enabled_(false); log_wtr.Log_to_session_fmt("app.init");
try {
app.Sys_cfg().Lang_(System_lang());
String launch_url = arg_mgr.Gui__home_page();
if (launch_url != null) gplx.xowa.guis.views.Xog_startup_tabs.Manual = launch_url;
app.Tcp_server().Rdr_port_(arg_mgr.Tcp__port_recv()).Wtr_port_(arg_mgr.Tcp__port_send());
gplx.xowa.apps.servers.http.Http_server_mgr server_mgr = app.Http_server();
server_mgr.Port_(arg_mgr.Http__port());
server_mgr.Home_(Bry_.new_u8(arg_mgr.Http__home_page()));
server_mgr.Wkr_pool().Init(arg_mgr.Http__max_clients(), arg_mgr.Http__max_clients_timeout());
app.Init_by_app();
}
catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0}", Err_.Message_gplx_full(e));}
app.Usr_dlg().Log_wkr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
// run gfs; prefs.gfs and app.gfs
Io_url cmd_file = arg_mgr.Cmd__file();
try {app.Gfs_mgr().Run_url(cmd_file);}
catch (Exception e) {
usr_dlg.Warn_many("", "", "script file failed: ~{0} ~{1}", cmd_file.Raw(), Err_.Message_gplx_full(e));
if (app_type_is_gui)
GfuiEnv_.ShowMsg(Err_.Message_gplx_full(e));
}
// launch
app.Launch();
if (app_type.Tid_is_tcp()) app.Tcp_server().Run();
else if (app_type.Tid_is_http()) app.Http_server().Run();
else {
String cmd_text = arg_mgr.Cmd__text();
if (cmd_text != null) {
gplx.xowa.apps.servers.Gxw_html_server.Init_gui_for_server(app, null); // NOTE: must init kit else "app.shell.fetch_page" will fail; DATE:2015-04-30
Console_adp__sys.Instance.Write_str_w_nl_utf8(Object_.Xto_str_strict_or_empty(app.Gfs_mgr().Run_str(cmd_text)));
}
if (app_type_is_gui)
app.Gui_mgr().Run(splash_win);
else // teardown app, else lua will keep process running
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all(app);
}
}
catch (Exception e) {usr_dlg.Warn_many("", "", "app launch failed: ~{0}", Err_.Message_gplx_full(e));}
finally {
if (app != null && app_type_is_gui) // only cancel if app_type_is_gui is true; (force cmd_line to end process)
app.Setup_mgr().Cmd_mgr().Canceled_y_();
}
}
private static byte[] System_lang() {
String lang_code = System_.Prop__user_language();
byte[] lang_code_bry = Bry_.new_a7(lang_code);
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_null(lang_code_bry);
return lang_itm == null ? Xol_lang_itm_.Key_en : lang_itm.Key();
}
}

View File

@@ -0,0 +1,103 @@
/*
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.apps.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.consoles.*; import gplx.core.envs.*;
import gplx.xowa.apps.*;
public class Xoa_cmd_arg_mgr {
Xoa_cmd_arg_mgr(Gfo_cmd_arg_mgr arg_mgr) {this.arg_mgr = arg_mgr;}
public Gfo_cmd_arg_mgr Arg_mgr() {return arg_mgr;} private final Gfo_cmd_arg_mgr arg_mgr;
public Xoa_app_mode App_type() {return app_type;} private Xoa_app_mode app_type;
public Io_url Fsys__root_dir() {return fsys__root_dir;} private Io_url fsys__root_dir;
public String Fsys__bin_dir() {return fsys__bin_dir;} private String fsys__bin_dir;
public Io_url Fsys__user_dir() {return fsys__user_dir;} private Io_url fsys__user_dir;
public Io_url Fsys__wiki_dir() {return fsys__wiki_dir;} private Io_url fsys__wiki_dir;
public Io_url Cmd__file() {return cmd__file;} private Io_url cmd__file;
public String Cmd__text() {return cmd__text;} private String cmd__text;
public int Tcp__port_recv() {return tcp__port_recv;} private int tcp__port_recv;
public int Tcp__port_send() {return tcp__port_send;} private int tcp__port_send;
public int Http__port() {return http__port;} private int http__port;
public String Http__home_page() {return http__home_page;} private String http__home_page;
public int Http__max_clients() {return http__max_clients;} private int http__max_clients;
public int Http__max_clients_timeout() {return http__max_clients_timeout;} private int http__max_clients_timeout;
public String Gui__home_page() {return gui__home_page;} private String gui__home_page;
public boolean Process(Gfo_usr_dlg usr_dlg, String[] args, Io_url jar_dir) {
arg_mgr.Parse(args);
if (!Print(usr_dlg)) return false;
this.app_type = Xoa_app_mode.parse(arg_mgr.Get_by("app_mode").Val_as_str_or("gui"));
this.fsys__root_dir = arg_mgr.Get_by("root_dir").Val_as_url__rel_dir_or(jar_dir, jar_dir);
this.fsys__user_dir = arg_mgr.Get_by("user_dir").Val_as_url__rel_dir_or(fsys__root_dir.GenSubDir("user"), fsys__root_dir.GenSubDir_nest("user", User_name_default));
this.fsys__wiki_dir = arg_mgr.Get_by("wiki_dir").Val_as_url__rel_dir_or(fsys__root_dir.GenSubDir("wiki"), fsys__root_dir.GenSubDir("wiki"));
this.cmd__file = arg_mgr.Get_by("cmd_file").Val_as_url__rel_fil_or(jar_dir, fsys__root_dir.GenSubFil_nest("bin", "any", "xowa", "cfg" ,"app", "xowa.gfs"));
this.cmd__text = arg_mgr.Get_by("cmd_text").Val_as_str_or(null);
this.tcp__port_recv = arg_mgr.Get_by("server_port_recv").Val_as_int_or(55000);
this.tcp__port_send = arg_mgr.Get_by("server_port_send").Val_as_int_or(55001);
this.http__port = arg_mgr.Get_by("http_server_port").Val_as_int_or(8080);
this.http__home_page = arg_mgr.Get_by("http_server_home").Val_as_str_or("home/wiki/Main_Page");
this.http__max_clients = arg_mgr.Get_by("http_server.max_clients").Val_as_int_or(0);
this.http__max_clients_timeout = arg_mgr.Get_by("http_server.max_clients_timeout").Val_as_int_or(50);
this.gui__home_page = arg_mgr.Get_by("url").Val_as_str_or(null);
this.fsys__bin_dir = arg_mgr.Get_by("bin_dir_name").Val_as_str_or(Bin_dir_name());
return true;
}
private boolean Print(Gfo_usr_dlg usr_dlg) {
String header = String_.Concat_lines_nl_skip_last
( Xoa_cmd_arg_mgr_.GenHdr(false, "XOWA", "XOWA: the XOWA Offline Wiki Application\n", "")
, String_.Repeat("-", 80)
, ""
, "version: " + Xoa_app_.Version + "; build date: " + Xoa_app_.Build_date
);
Gfo_cmd_arg_mgr_printer printer = new Gfo_cmd_arg_mgr_printer(arg_mgr);
return printer.Print(usr_dlg, header, Xoa_app_.Name, "help", "show_license", "show_args");
}
public static Xoa_cmd_arg_mgr new_() {
Gfo_cmd_arg_mgr arg_mgr = new Gfo_cmd_arg_mgr().Reg_many
( Gfo_cmd_arg_itm_.opt_("root_dir").Example_url_("C:\\xowa").Note_("root directory for xowa; defaults to current directory of xowa.jar")
, Gfo_cmd_arg_itm_.opt_("user_dir").Example_url_("C:\\xowa\\user\\" + User_name_default).Note_("directory for user_data; defaults to '/xowa/user/" + User_name_default + "'")
, Gfo_cmd_arg_itm_.opt_("wiki_dir").Example_url_("C:\\xowa\\wiki\\").Note_("directory for wikis; defaults to '/xowa/wiki/'")
, Gfo_cmd_arg_itm_.opt_("bin_dir_name").Example_("windows").Note_("platform-dependent directory name inside /xowa/bin/; valid values are 'linux', 'macosx', 'windows', 'linux_64', 'macosx_64', 'windows_64'; defaults to detected version")
, Gfo_cmd_arg_itm_.opt_("app_mode").Example_("gui").Note_("type of app to run; valid values are 'gui', 'cmd', 'server', 'http_server'; defaults to 'gui'")
, Gfo_cmd_arg_itm_.opt_("cmd_file").Example_url_("C:\\xowa\\bin\\any\\xowa\\cfg\\app\\xowa.gfs").Note_("file_path of script to execute; defaults to 'xowa.gfs'")
, Gfo_cmd_arg_itm_.opt_("cmd_text").Example_("\"app.shell.fetch_page('en.wikipedia.org/wiki/Earth', 'html');\"").Note_("script to run; runs after cmd_file; does nothing if empty; default is empty.\nCurrently a useful cmd is to do 'java -jar xowa_your_platform.jar --app_mode cmd --show_license n --show_args n --cmd_text \"app.shell.fetch_page('en.wikipedia.org/wiki/Earth' 'html');\"'. This will output the page's html to the console. You can also change 'html' to 'wiki' to get the wikitext.")
, Gfo_cmd_arg_itm_.opt_("url").Example_("en.wikipedia.org/wiki/Earth").Note_("url to be shown when xowa first launches; default is home/wiki/Main_Page")
, Gfo_cmd_arg_itm_.opt_("server_port_recv").Example_("55000").Note_("applies to --app_mode server; port where xowa server will receive messages; clients should send messages to this port")
, Gfo_cmd_arg_itm_.opt_("server_port_send").Example_("55001").Note_("applies to --app_mode server; port where xowa server will send messages; clients should listen for messages from this port")
, Gfo_cmd_arg_itm_.opt_("http_server_port").Example_("8080").Note_("applies to --app_mode http_server; port used by http_server; default is 8080")
, Gfo_cmd_arg_itm_.opt_("http_server_home").Example_("home/wiki/Main_Page").Note_("applies to --app_mode http_server; default home page for root address. EX: navigating to localhost:8080 will navigate to localhost:8080/home/wiki/Main_Page")
, Gfo_cmd_arg_itm_.opt_("http_server.max_clients").Example_("15").Note_("applies to --app_mode http_server; limits maximum number of concurrent connections; default is 0 (no limit)")
, Gfo_cmd_arg_itm_.opt_("http_server.max_clients_timeout").Example_("50").Note_("applies to --app_mode http_server; time in milliseconds to wait before checking again to see if a connection is free; default is 50 (wait 50 ms)")
, Gfo_cmd_arg_itm_.sys_("show_license").Dflt_(true)
, Gfo_cmd_arg_itm_.sys_("show_args").Dflt_(true)
, Gfo_cmd_arg_itm_.new_(Gfo_cmd_arg_itm_.Tid_system, "help", Bool_.N, Gfo_cmd_arg_itm_.Val_tid_string)
);
return new Xoa_cmd_arg_mgr(arg_mgr);
}
private static final String User_name_default = gplx.xowa.users.Xoue_user.Key_xowa_user;
public static String Bin_dir_name() {
String rv = "";
Op_sys op_sys = Op_sys.Cur();
switch (op_sys.Tid()) {
case Op_sys.Tid_lnx: rv = "linux"; break;
case Op_sys.Tid_wnt: rv = "windows"; break;
case Op_sys.Tid_osx: rv = "macosx"; break;
case Op_sys.Tid_arm: rv = "arm"; break;
default: throw Err_.new_unhandled("unknown platform " + Op_sys.Cur());
}
if (op_sys.Bitness() == Op_sys.Bitness_64) rv += "_64";
return rv;
}
}

View File

@@ -0,0 +1,50 @@
/*
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.apps.boots; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.envs.*;
class Xoa_cmd_arg_mgr_ {
public static String GenHdr(boolean forSourceCode, String programName, String hdr_bgn, String hdr_end) {
String newLine = Op_sys.Lnx.Nl_str();
String lineEnd = Op_sys.Lnx.Nl_str();
String codeBgn = forSourceCode ? "/*" + newLine : "";
String codeEnd = forSourceCode ? "*/" + newLine : "";
String codeHdr = forSourceCode ? "This file is part of {0}." + newLine + newLine : "";
String fmt = String_.Concat
( codeBgn
, codeHdr
, hdr_bgn
, "Copyright (c) 2012-2016 gnosygnu@gmail.com", newLine
, newLine
, "This program is free software: you can redistribute it and/or modify", lineEnd
, "it under the terms of the GNU Affero General Public License as", lineEnd
, "published by the Free Software Foundation, either version 3 of the", lineEnd
, "License, or (at your option) any later version.", newLine
, newLine
, "This program is distributed in the hope that it will be useful,", lineEnd
, "but WITHOUT ANY WARRANTY; without even the implied warranty of", lineEnd
, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", lineEnd
, "GNU Affero General Public License for more details.", newLine
, newLine
, "You should have received a copy of the GNU Affero General Public License", lineEnd
, "along with this program. If not, see <http://www.gnu.org/licenses/>.", newLine
, codeEnd
, hdr_end
);
return String_.Format(fmt, programName);
}
}

View File

@@ -0,0 +1,26 @@
/*
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.apps.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.xtns.wbases.*;
public class Wdata_doc_cache {
private Hash_adp_bry hash = Hash_adp_bry.cs();
public void Add(byte[] qid, Wdata_doc doc) {hash.Add(qid, doc);}
public Wdata_doc Get_or_null(byte[] qid) {return (Wdata_doc)hash.Get_by_bry(qid);}
public void Free_mem_all() {this.Clear();}
public void Clear() {hash.Clear();}
}

View File

@@ -0,0 +1,24 @@
/*
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.apps.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_cache_mgr {
public Wdata_doc_cache Doc_cache() {return doc_cache;} private Wdata_doc_cache doc_cache = new Wdata_doc_cache();
public void Free_mem_all() {
doc_cache.Free_mem_all();
}
}

View File

@@ -0,0 +1,29 @@
/*
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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xocfg_gui_mgr implements Gfo_invk {
public void Init_by_app(Xoae_app app) {
win_cfg.Init_by_app(app);
}
public Xocfg_win Win() {return win_cfg;} private Xocfg_win win_cfg = new Xocfg_win();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_win)) return win_cfg;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_win = "win";
}

View File

@@ -0,0 +1,36 @@
/*
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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
import gplx.gfui.draws.*;
import gplx.xowa.guis.langs.*;
public class Xocfg_win implements Gfo_invk {
public Xol_font_info Font() {return font;} private Xol_font_info font = new Xol_font_info("Arial", 8, FontStyleAdp_.Plain);
public Bry_fmtr Search_box_fmtr() {return search_box_fmtr;} private Bry_fmtr search_box_fmtr = Bry_fmtr.new_("Special:Allpages?from=", "search");
public void Init_by_app(Xoae_app app) {
font.Init_by_app(app);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_font)) return font;
else if (ctx.Match(k, Invk_search_box_fmt_)) search_box_fmtr.Fmt_(m.ReadBry("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_search_box_fmt_ = "search_box_fmt_", Invk_font = "font";
public static final float Font_size_default = 8;
}

View File

@@ -0,0 +1,38 @@
/*
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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.parsers.lnkis.cfgs.*;
public class Xowc_parser implements Gfo_invk {
public Xowc_parser(Xowe_wiki wiki) {
lnki_cfg = new Xoc_lnki_cfg(wiki);
if (wiki.Domain_tid() == gplx.xowa.wikis.domains.Xow_domain_tid_.Tid__home)
display_title_restrict = false;
}
public Xoc_lnki_cfg Lnki_cfg() {return lnki_cfg;} private Xoc_lnki_cfg lnki_cfg;
public Xowc_xtns Xtns() {return xtns;} private Xowc_xtns xtns = new Xowc_xtns();
public boolean Display_title_restrict() {return display_title_restrict;} public void Display_title_restrict_(boolean v) {display_title_restrict = v;} private boolean display_title_restrict = true;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_xtns)) return xtns;
else if (ctx.Match(k, Invk_lnki)) return lnki_cfg;
else if (ctx.Match(k, Invk_display_title_restrict)) return display_title_restrict;
else if (ctx.Match(k, Invk_display_title_restrict_)) display_title_restrict = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_xtns = "xtns", Invk_lnki = "lnki", Invk_display_title_restrict = "display_title_restrict", Invk_display_title_restrict_ = "display_title_restrict_";
}

View File

@@ -0,0 +1,84 @@
/*
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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wikis.nss.*;
public class Xowc_xtn_pages implements Gfo_invk {
public boolean Init_needed() {return init_needed;} private boolean init_needed = true;
public int Ns_page_id() {return ns_page_id;} private int ns_page_id = Int_.Min_value;
public int Ns_page_talk_id() {return ns_page_talk_id;} private int ns_page_talk_id = Int_.Min_value;
public int Ns_index_id() {return ns_index_id;} private int ns_index_id = Int_.Min_value;
public int Ns_index_talk_id() {return ns_index_talk_id;} private int ns_index_talk_id = Int_.Min_value;
public void Ns_names_(byte[] page_name, byte[] page_talk_name, byte[] index_name, byte[] index_talk_name) {
this.page_name = Xoa_ttl.Replace_spaces(page_name); // ensure underlines, not space; EX:"Mục_lục" not "Mục lục"; PAGE:vi.s:Việt_Nam_sử_lược/Quyển_II DATE:2015-10-27
this.page_talk_name = Xoa_ttl.Replace_spaces(page_talk_name);
this.index_name = Xoa_ttl.Replace_spaces(index_name);
this.index_talk_name = Xoa_ttl.Replace_spaces(index_talk_name);
}
private byte[]
page_name = Default_ns_page_name
, page_talk_name = Default_ns_page_talk_name
, index_name = Default_ns_index_name
, index_talk_name = Default_ns_index_talk_name;
public void Reset() {
ns_page_id = ns_page_talk_id = ns_index_id = ns_index_talk_id = Int_.Min_value;
init_needed = true;
}
public void Init(Xow_ns_mgr ns_mgr) {
init_needed = false;
int len = ns_mgr.Ords_len();
for (int i = 0; i < len; i++) { // Page / Index ns_ids are variable per wiki; iterate over ns, and set ns_id
Xow_ns ns = ns_mgr.Ords_get_at(i); if (ns == null) continue;
byte[] ns_name = ns.Name_enc();
if (Bry_.Eq(ns_name, page_name)) {ns_page_id = ns.Id(); ns_mgr.Ns_page_id_(ns_page_id);}
else if (Bry_.Eq(ns_name, page_talk_name)) ns_page_talk_id = ns.Id();
else if (Bry_.Eq(ns_name, index_name)) ns_index_id = ns.Id();
else if (Bry_.Eq(ns_name, index_talk_name)) ns_index_talk_id = ns.Id();
}
int aliases_added = 0;
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_page_id , Default_ns_page_name);
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_page_talk_id , Default_ns_page_talk_name);
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_index_id , Default_ns_index_name);
aliases_added = Set_canonical(ns_mgr, aliases_added, ns_index_talk_id , Default_ns_index_talk_name);
if (aliases_added > 0) // NOTE: will probably only be 0 for English Wikisource
ns_mgr.Init_w_defaults();
}
private int Set_canonical(Xow_ns_mgr ns_mgr, int aliases_added, int id, byte[] name) {
Xow_ns ns = ns_mgr.Ids_get_or_null(id);
if ( ns == null // ns doesn't exist; should throw error;
|| !Bry_.Eq(ns.Name_db(), name) // ns exists, but name doesn't match canonical
) {
ns_mgr.Aliases_add(id, String_.new_a7(name));
++aliases_added;
}
return aliases_added;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_ns_names_)) Ns_names_(m.ReadBry("page"), m.ReadBry("page_talk"), m.ReadBry("index"), m.ReadBry("index_talk"));
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_ns_names_ = "ns_names_";
public static final byte[] Xtn_key = Bry_.new_a7("pages");
public static final int Ns_index_id_default = 102, Ns_page_id_default = 104;
private static final byte[]
Default_ns_page_name = Bry_.new_a7("Page")
, Default_ns_page_talk_name = Bry_.new_a7("Page_talk")
, Default_ns_index_name = Bry_.new_a7("Index")
, Default_ns_index_talk_name = Bry_.new_a7("Index_talk")
;
}

View File

@@ -0,0 +1,72 @@
/*
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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*;
public class Xowc_xtn_pages_tst {
@Before public void init() {fxt.Clear();} private Xowc_xtn_pages_fxt fxt = new Xowc_xtn_pages_fxt();
@Test public void Init() {
fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by <siteinfo>
fxt.Init_names("Foreign_page", "Foreign_page_talk", "Foreign_index", "Foreign_index_talk"); // ns set by .gfs files in /user/wiki/#cfg
fxt.Exec_init();
fxt.Test_ns_ids(200, 201, 202, 203);
fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk");
}
@Test public void Spaces() { // PURPOSE: ensure underlines, not space; EX:"Mục_lục" not "Mục lục"; PAGE:vi.s:Việt_Nam_sử_lược/Quyển_II DATE:2015-10-27
fxt.Init_ns(200, "Foreign_page").Init_ns(201, "Foreign_page_talk").Init_ns(202, "Foreign_index").Init_ns(203, "Foreign_index_talk"); // ns set by <siteinfo>
fxt.Init_names("Foreign page", "Foreign page talk", "Foreign index", "Foreign index talk"); // ns set by .gfs files in /user/wiki/#cfg
fxt.Exec_init();
fxt.Test_ns_ids(200, 201, 202, 203);
fxt.Test_ns_canonical("Page", "Page_talk", "Index", "Index_talk");
}
}
class Xowc_xtn_pages_fxt {
private Xow_ns_mgr ns_mgr;
private Xowc_xtn_pages cfg_pages;
public void Clear() {
ns_mgr = Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
cfg_pages = new Xowc_xtn_pages();
}
public Xowc_xtn_pages_fxt Init_ns(int id, String name) {
ns_mgr.Add_new(id, name);
return this;
}
public void Init_names(String page_name, String page_talk_name, String index_name, String index_talk_name) {
cfg_pages.Ns_names_(Bry_.new_a7(page_name), Bry_.new_a7(page_talk_name), Bry_.new_a7(index_name), Bry_.new_a7(index_talk_name));
}
public void Exec_init() {
ns_mgr.Init_w_defaults(); // init ns_msg
cfg_pages.Init(ns_mgr); // init cfg
}
public void Test_ns_ids(int page_id, int page_talk_id, int index_id, int index_talk_id) {
Tfds.Eq(page_id , cfg_pages.Ns_page_id());
Tfds.Eq(page_talk_id , cfg_pages.Ns_page_talk_id());
Tfds.Eq(index_id , cfg_pages.Ns_index_id());
Tfds.Eq(index_talk_id , cfg_pages.Ns_index_talk_id());
}
public void Test_ns_canonical(String page_name, String page_talk_name, String index_name, String index_talk_name) {
Test_ns_canonical_itm(page_name , cfg_pages.Ns_page_id());
Test_ns_canonical_itm(page_talk_name , cfg_pages.Ns_page_talk_id());
Test_ns_canonical_itm(index_name , cfg_pages.Ns_index_id());
Test_ns_canonical_itm(index_talk_name , cfg_pages.Ns_index_talk_id());
}
private void Test_ns_canonical_itm(String name, int expd_ns_id) {
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_a7(name));
int actl_ns_id = ns == null ? Int_.Min_value : ns.Id();
Tfds.Eq(expd_ns_id, actl_ns_id);
}
}

View File

@@ -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.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xowc_xtns implements Gfo_invk {
private Hash_adp_bry hash = Hash_adp_bry.ci_a7();
public Xowc_xtns() {hash.Add(Xowc_xtn_pages.Xtn_key, itm_pages);}
public Xowc_xtn_pages Itm_pages() {return itm_pages;} private Xowc_xtn_pages itm_pages = new Xowc_xtn_pages();
public Object Get_by_key(byte[] key) {return hash.Get_by_bry(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return (Gfo_invk)hash.Get_by_bry(m.ReadBry("v"));
else return Gfo_invk_.Rv_unhandled;
} private static final String Invk_get = "get";
}

View File

@@ -0,0 +1,21 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public interface Gfo_sort_able {
void Sort(gplx.core.lists.ComparerAble comparer);
}

View File

@@ -0,0 +1,66 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
public class Xoa_fmtr_itm implements Gfo_invk {
public Xoa_fmtr_itm(Xoae_app app) {this.app = app;} private Xoae_app app;
public String Src() {return src;} public Xoa_fmtr_itm Src_(String v) {this.src = v; return this;} private String src;
public byte[] Fmt() {return fmt;} public Xoa_fmtr_itm Fmt_(byte[] v) {this.fmt = v; return this;} private byte[] fmt;
public Object Sorter() {
Gfo_invk src_invk = (Gfo_invk)app.Gfs_mgr().Run_str(src);
return Gfo_invk_.Invk_by_key(src_invk, Invk_sorter);
}
public String Run() {
Gfo_invk src_invk = (Gfo_invk)app.Gfs_mgr().Run_str(src);
int len = Int_.cast(Gfo_invk_.Invk_by_key(src_invk, Invk_len));
Bry_bfr bfr = Bry_bfr_.New();
Bfmtr_eval_invk eval_mgr = new Bfmtr_eval_invk(app);
Bry_fmtr fmtr = Bry_fmtr.new_bry_(fmt).Eval_mgr_(eval_mgr);
for (int i = 0; i < len; i++) {
Gfo_invk itm_invk = (Gfo_invk)Gfo_invk_.Invk_by_val(src_invk, Invk_get_at, i);
eval_mgr.Invk_(itm_invk);
fmtr.Bld_bfr(bfr, Bry_.Ary_empty);
}
return bfr.To_str_and_clear();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_src)) return src;
else if (ctx.Match(k, Invk_src_)) src = m.ReadStr("v");
else if (ctx.Match(k, Invk_fmt)) return String_.new_u8(fmt);
else if (ctx.Match(k, Invk_fmt_)) fmt = m.ReadBry("v");
else if (ctx.Match(k, Invk_sorter)) return this.Sorter();
else if (ctx.Match(k, Invk_run)) return Run();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_src = "src", Invk_src_ = "src_", Invk_fmt = "fmt", Invk_fmt_ = "fmt_"
, Invk_run = "run"
;
public static final String Invk_get_at = "get_at", Invk_len = "len"
, Invk_sorter = "sorter"
;
}
class Bfmtr_eval_invk implements Bry_fmtr_eval_mgr {
public Bfmtr_eval_invk(Xoae_app app) {this.app = app;} private Xoae_app app;
public Bfmtr_eval_invk Invk_(Gfo_invk invk) {this.invk = invk; return this;} private Gfo_invk invk;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public byte[] Eval(byte[] cmd) {
Object rslt = app.Gfs_mgr().Run_str_for(invk, String_.new_u8(cmd));
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
}
}

View File

@@ -0,0 +1,42 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*; import gplx.langs.gfs.*;
public class Xoa_fmtr_itm_tst {
@Before public void init() {fxt.Clear();} private Xoa_fmtr_itm_fxt fxt = new Xoa_fmtr_itm_fxt();
@Test public void Basic() {
fxt.Init_src("app.wikis;");
fxt.Init_fmt("domain=~{<>domain;<>};");
fxt.Test_run("domain=en.wikipedia.org;");
}
}
class Xoa_fmtr_itm_fxt {
private Xoae_app app; private Xoa_fmtr_itm itm;
public void Clear() {
app = Xoa_app_fxt.Make__app__edit();
Xoa_app_fxt.Make__wiki__edit(app); // create enwiki
itm = new Xoa_fmtr_itm(app);
GfsCore.Instance.MsgParser_(gplx.langs.gfs.Gfs_msg_bldr.Instance);
}
public Xoa_fmtr_itm_fxt Init_src(String v) {itm.Src_(v); return this;}
public Xoa_fmtr_itm_fxt Init_fmt(String v) {itm.Fmt_(Bry_.new_a7(v)); return this;}
public void Test_run(String expd) {
String actl = itm.Run();
Tfds.Eq(expd, actl);
}
}

View File

@@ -0,0 +1,26 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.ios.*;
public class Xoa_fmtr_mgr implements Gfo_invk {
public Xoa_fmtr_mgr(Xoae_app app) {this.app = app;} private Xoae_app app;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_new_grp)) return new Xoa_fmtr_itm(app);
else return Gfo_invk_.Rv_unhandled;
} private static final String Invk_new_grp = "new_grp";
}

View File

@@ -0,0 +1,66 @@
/*
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.apps.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_fmtr_sort_mgr implements Gfo_invk {
private Ordered_hash itms = Ordered_hash_.New();
private Xoa_fmtr_sort_wkr wkr = new Xoa_fmtr_sort_wkr();
private Gfo_sort_able sort_able;
public Xoa_fmtr_sort_mgr(Gfo_sort_able sort_able) {this.sort_able = sort_able;}
public void Clear() {itms.Clear();}
public void Add_many(String[] keys) {
int keys_len = keys.length;
for (int i = 0; i < keys_len; i++) {
Xoa_fmtr_sort_itm itm = new Xoa_fmtr_sort_itm(keys[i], true);
itms.Add_if_dupe_use_1st(itm.Key(), itm);
}
}
public void Exec() {
wkr.Itms_((Xoa_fmtr_sort_itm[])itms.To_ary(Xoa_fmtr_sort_itm.class));
sort_able.Sort(wkr);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_clear)) this.Clear();
else if (ctx.Match(k, Invk_add_many)) this.Add_many(m.ReadStrAry("k", "|"));
else if (ctx.Match(k, Invk_exec)) this.Exec();
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Invk_clear = "clear", Invk_add_many = "add_many", Invk_exec = "exec";
}
class Xoa_fmtr_sort_itm {
public Xoa_fmtr_sort_itm(String key, boolean asc) {this.key = key; this.comp_mult = asc ? CompareAble_.More : CompareAble_.Less;}
public int Comp_mult() {return comp_mult;} private int comp_mult;
public String Key() {return key;} private String key;
}
class Xoa_fmtr_sort_wkr implements gplx.core.lists.ComparerAble {
public Xoa_fmtr_sort_itm[] Itms() {return itms;} public void Itms_(Xoa_fmtr_sort_itm[] v) {itms = v; itms_len = v.length;} private Xoa_fmtr_sort_itm[] itms; private int itms_len;
public int compare(Object lhsObj, Object rhsObj) {
Gfo_invk lhs_invk = (Gfo_invk)lhsObj;
Gfo_invk rhs_invk = (Gfo_invk)rhsObj;
for (int i = 0; i < itms_len; i++) {
Xoa_fmtr_sort_itm itm = itms[i];
String itm_key = itm.Key();
Object lhs_val = Gfo_invk_.Invk_by_key(lhs_invk, itm_key);
Object rhs_val = Gfo_invk_.Invk_by_key(rhs_invk, itm_key);
int compare = CompareAble_.Compare_obj(lhs_val, rhs_val) * itm.Comp_mult();
if (compare != CompareAble_.Same)
return compare;
}
return CompareAble_.Same;
}
}

View File

@@ -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.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
import gplx.core.primitives.*; import gplx.xowa.users.*;
public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
private final Xoa_fsys_mgr app_fsys_mgr; private final Xou_fsys_mgr usr_fsys_mgr;
public Xoa_fsys_eval(Xoa_fsys_mgr app_fsys_mgr, Xou_fsys_mgr usr_fsys_mgr) {this.app_fsys_mgr = app_fsys_mgr; this.usr_fsys_mgr = usr_fsys_mgr;}
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public byte[] Eval(byte[] cmd) {
Object o = hash.Get_by_bry(cmd); if (o == null) return null;
byte val = ((Byte_obj_val)o).Val();
switch (val) {
case Tid__xowa_root_dir: return app_fsys_mgr.Root_dir().RawBry();
case Tid__bin_plat_dir: return app_fsys_mgr.Bin_plat_dir().RawBry();
case Tid__user_temp_dir: return usr_fsys_mgr.App_temp_dir().RawBry();
case Tid__user_cfg_dir: return usr_fsys_mgr.App_data_cfg_dir().RawBry();
default: throw Err_.new_unhandled(val);
}
}
private static final byte Tid__bin_plat_dir = 0, Tid__user_temp_dir = 1, Tid__xowa_root_dir = 2, Tid__user_cfg_dir = 3;
private static final Hash_adp_bry hash = Hash_adp_bry.ci_a7()
.Add_str_byte("bin_plat_dir" , Tid__bin_plat_dir)
.Add_str_byte("user_temp_dir" , Tid__user_temp_dir)
.Add_str_byte("xowa_root_dir" , Tid__xowa_root_dir)
.Add_str_byte("user_cfg_dir" , Tid__user_cfg_dir)
;
}

View File

@@ -0,0 +1,61 @@
/*
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.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.apps.gfs.*;
import gplx.xowa.wikis.domains.*;
public class Xoa_fsys_mgr implements Gfo_invk {
public Xoa_fsys_mgr(String plat_name, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url css_dir, Io_url http_root) {
this.root_dir = root_dir; this.wiki_dir = wiki_dir; this.file_dir = file_dir; this.css_dir = css_dir; this.http_root = http_root;
this.bin_plat_dir = root_dir.GenSubDir("bin").GenSubDir(plat_name);
this.bin_any_dir = root_dir.GenSubDir("bin").GenSubDir("any");
this.bin_xowa_dir = bin_any_dir.GenSubDir("xowa");
this.bin_xowa_file_dir = bin_xowa_dir.GenSubDir_nest("file");
this.bin_xtns_dir = bin_xowa_dir.GenSubDir_nest("xtns");
this.bin_addon_dir = bin_xowa_dir.GenSubDir_nest("addon");
this.cfg_app_fil = bin_xowa_dir.GenSubFil_nest("cfg", "app", "xowa.gfs");
this.cfg_lang_core_dir = bin_xowa_dir.GenSubDir_nest("cfg", "lang", "core");
this.cfg_wiki_core_dir = bin_xowa_dir.GenSubDir_nest("cfg", "wiki", "core");
this.cfg_site_meta_fil = bin_xowa_dir.GenSubFil_nest("cfg", "wiki", "site_meta.sqlite3");
this.home_wiki_dir = bin_xowa_dir.GenSubDir_nest("wiki", Xow_domain_itm_.Str__home);
}
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir; // EX: /xowa/
public Io_url Wiki_dir() {return wiki_dir;} private final Io_url wiki_dir; // EX: /xowa/wiki/
public Io_url File_dir() {return file_dir;} private final Io_url file_dir; // EX: /xowa/file/
public Io_url Css_dir() {return css_dir;} private final Io_url css_dir; // EX: /xowa/user/anonymous/wiki/
public Io_url Bin_plat_dir() {return bin_plat_dir;} private final Io_url bin_plat_dir; // EX: /xowa/bin/lnx_64/
public Io_url Bin_any_dir() {return bin_any_dir;} private final Io_url bin_any_dir; // EX: /xowa/bin/any
public Io_url Bin_xowa_dir() {return bin_xowa_dir;} private final Io_url bin_xowa_dir;
public Io_url Bin_xowa_file_dir() {return bin_xowa_file_dir;} private final Io_url bin_xowa_file_dir;
public Io_url Bin_xtns_dir() {return bin_xtns_dir;} private final Io_url bin_xtns_dir;
public Io_url Bin_addon_dir() {return bin_addon_dir;} private final Io_url bin_addon_dir;
public Io_url Cfg_lang_core_dir() {return cfg_lang_core_dir;} private final Io_url cfg_lang_core_dir;
public Io_url Cfg_wiki_core_dir() {return cfg_wiki_core_dir;} private final Io_url cfg_wiki_core_dir;
public Io_url Cfg_site_meta_fil() {return cfg_site_meta_fil;} private final Io_url cfg_site_meta_fil;
public Io_url Wiki_css_dir(String wiki) {return css_dir.GenSubDir_nest(wiki, "html");} // EX: /xowa/temp/simple.wikipedia.org/html/xowa_common.css
public Io_url Wiki_file_dir(String wiki) {return file_dir.GenSubDir_nest(wiki);} // EX: /xowa/temp/simple.wikipedia.org/orig/
public Io_url Home_wiki_dir() {return home_wiki_dir;} private final Io_url home_wiki_dir;
public Io_url Cfg_app_fil() {return cfg_app_fil;} private final Io_url cfg_app_fil;
public Io_url Http_root() {return http_root;} private final Io_url http_root; // EX: file:///xowa/ or file:///android_asset/xowa/
public void Init_by_app(Gfo_invk app_mgr_invk) {this.app_mgr_invk = app_mgr_invk;} private Gfo_invk app_mgr_invk; // for gfs and app.launcher
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_apps)) return app_mgr_invk;
else if (ctx.Match(k, Invk_root_dir)) return root_dir;
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_apps = "apps", Invk_root_dir = "root_dir";
}

View File

@@ -0,0 +1,146 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.phps.*;
public class Gfs_php_converter {
public static byte[] Xto_php(Bry_bfr bfr, boolean escape_backslash, byte[] src) {
int len = src.length;
int pos = 0;
boolean dirty = false;
while (pos < len) {
byte b = src[pos];
switch (b) {
case Byte_ascii.Tilde:
if (!dirty) {
bfr.Add_mid(src, 0, pos);
dirty = true;
}
pos = Xto_php_swap(bfr, src, len, pos + 1);
break;
case Byte_ascii.Backslash: case Byte_ascii.Dollar:
case Byte_ascii.Apos: case Byte_ascii.Quote:
if (escape_backslash) {
if (!dirty) {
bfr.Add_mid(src, 0, pos);
dirty = true;
}
bfr.Add_byte(Byte_ascii.Backslash);
bfr.Add_byte(b);
}
else {
if (dirty)
bfr.Add_byte(b);
}
++pos;
break;
default:
if (dirty)
bfr.Add_byte(b);
++pos;
break;
}
}
return dirty ? bfr.To_bry_and_clear() : src;
}
private static int Xto_php_swap(Bry_bfr bfr, byte[] src, int len, int pos) {
if (pos >= len) throw Err_.new_wo_type("invalid gfs: tilde is last char", "src", String_.new_u8(src));
byte b = src[pos];
switch (b) {
case Byte_ascii.Tilde: { // ~~ -> ~
bfr.Add_byte(Byte_ascii.Tilde);
return pos + 1;
}
case Byte_ascii.Curly_bgn: {
int num_bgn = pos + 1;
int num_end = Bry_find_.Find_fwd_while_num(src, num_bgn, len); // +1 to position after {
if ( num_end == Bry_find_.Not_found
|| num_end == len
|| src[num_end] != Byte_ascii.Curly_end
)
throw Err_.new_wo_type("invalid gfs; num_end not found", "src", String_.new_u8(src));
bfr.Add_byte(Byte_ascii.Dollar);
int arg_idx = Bry_.To_int_or(src, num_bgn, num_end, -1);
if (arg_idx == -1) {
throw Err_.new_wo_type("invalid int");
}
bfr.Add_int_variable(arg_idx + 1);
return num_end + 1;
}
default: {
throw Err_.new_wo_type("invalid gfs; next char after tilde must be either tilde or open brace", "src", String_.new_u8(src));
}
}
}
public static byte[] To_gfs(Bry_bfr bfr, byte[] raw) {
int raw_len = raw.length;
for (int i = 0; i < raw_len; ++i) {
byte b = raw[i];
switch (b) {
case Byte_ascii.Backslash: // unescape; EX: '\"' -> '"'
++i;
if (i < raw_len){
byte escape_byte = raw[i];
switch (escape_byte) { // REF: http://php.net/manual/en/language.types.String.php
case Byte_ascii.Ltr_t: escape_byte = Byte_ascii.Tab; break;
case Byte_ascii.Ltr_n: escape_byte = Byte_ascii.Nl; break;
case Byte_ascii.Ltr_r: escape_byte = Byte_ascii.Cr; break;
case Byte_ascii.Ltr_v: escape_byte = 11; break; // 11=vertical tab
case Byte_ascii.Ltr_e: escape_byte = 27; break; // 27=escape
case Byte_ascii.Ltr_f: escape_byte = 12; break; // 12=form fed
case Byte_ascii.Backslash:
case Byte_ascii.Quote:
case Byte_ascii.Apos:
case Byte_ascii.Dollar: break;
// FUTURE:
// //\[0-7]{1,3} the sequence of characters matching the regular expression is a character in octal notation, which silently overflows to fit in a byte (e.g. "\400" === "\000")
// \ x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation
// \ u{[0-9A-Fa-f]+} the sequence of characters matching the regular expression is a Unicode codepoint, which will be output to the String as that codepoint's UTF-8 representation (added in PHP 7.0.0)
default: // all else seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
bfr.Add_byte(Byte_ascii.Backslash);
bfr.Add_byte(escape_byte);
continue;
}
bfr.Add_byte(escape_byte);
}
else // if eos, just output "\"; don't fail; EX: "a\" -> "a\"
bfr.Add_byte(Byte_ascii.Backslash);
break;
case Byte_ascii.Tilde: // double up tilde; EX: '~' -> '~~'
bfr.Add_byte_repeat(Bry_fmtr.char_escape, 2); // escape tilde; EX: ~u -> ~~u; DATE:2013-11-11
break;
case Byte_ascii.Dollar: // convert php args to gfs args; EX: $1 -> ~{0}
int int_bgn = i + 1;
int int_end = Php_text_itm_parser.Find_fwd_non_int(raw, int_bgn, raw_len);
if (int_bgn == int_end ) // no numbers after $; EX: "$ "; "$a"
bfr.Add_byte(b);
else {
int int_val = Bry_.To_int_or(raw, int_bgn, int_end, -1);
if (int_val == -1) throw Err_.new_wo_type(String_.Format("unknown php dollar sequence: raw=~{0}", raw));
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - List_adp_.Base1).Add_byte(Bry_fmtr.char_arg_end); // convert "$1" -> "~{0}"
i = int_end - 1; // -1 b/c Find_fwd_non_int positions after non-int
}
break;
default:
bfr.Add_byte(b);
break;
}
}
return bfr.To_bry_and_clear();
}
}

View File

@@ -0,0 +1,55 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Gfs_php_converter__to_gfs__tst {
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
@Test public void Escape_sequences() {
fxt.Test__to_gfs("a\\\"b" , "a\"b");
fxt.Test__to_gfs("a\\'b" , "a'b");
fxt.Test__to_gfs("a\\$b" , "a$b");
fxt.Test__to_gfs("a\\\\b" , "a\\b");
fxt.Test__to_gfs("a\\nb" , "a\nb");
fxt.Test__to_gfs("a\\tb" , "a\tb");
fxt.Test__to_gfs("a\\rb" , "a\rb");
fxt.Test__to_gfs("a\\ b" , "a\\ b"); // "\ " seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
fxt.Test__to_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
fxt.Test__to_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
}
@Test public void Tilde() {
fxt.Test__to_gfs("a~b" , "a~~b"); // tilde.escape
}
@Test public void Arguments() {
fxt.Test__to_gfs("a$1b" , "a~{0}b"); // dollar
fxt.Test__to_gfs("a $ b" , "a $ b"); // noop
}
}
class Gfs_php_converter_fxt {
private final Bry_bfr bfr = Bry_bfr_.New();
public void Clear() {}
public void Test__to_gfs(String raw, String expd) {
byte[] actl = Gfs_php_converter.To_gfs(bfr, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);}
public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);}
public void Test_Xto_php(String raw, boolean escape_backslash, String expd) {
byte[] actl = Gfs_php_converter.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
}

View File

@@ -0,0 +1,30 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Gfs_php_converter__to_php__tst {
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
@Test public void Xto_php() {
fxt.Test_Xto_php_escape_y("a~{0}b" , "a$1b"); // tilde.arg.one
fxt.Test_Xto_php_escape_y("a~{0}b~{1}c~{2}d" , "a$1b$2c$3d"); // tilde.arg.many
fxt.Test_Xto_php_escape_y("a~{9}" , "a$10"); // tilde.arg.9 -> 10
fxt.Test_Xto_php_escape_y("a~~b" , "a~b"); // tilde.escape
fxt.Test_Xto_php_escape_y("a\\b'c\"d$e" , "a\\\\b\\'c\\\"d\\$e"); // backslash.escape_y
fxt.Test_Xto_php_escape_n("a\\b'c\"d$e" , "a\\b'c\"d$e"); // backslash.escape_n
}
}

View File

@@ -0,0 +1,89 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_gfs_bldr {
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr = Bry_bfr_.New();
public byte[] Xto_bry() {return bfr.To_bry_and_clear();}
public Xoa_gfs_bldr Add_byte(byte b) {bfr.Add_byte(b); return this;}
public Xoa_gfs_bldr Add_blob(byte[] bry) {bfr.Add(bry); return this;}
public Xoa_gfs_bldr Add_proc_init_many(String... ary) {return Add_proc_core_many(false, ary);}
public Xoa_gfs_bldr Add_proc_init_one(String itm) {return Add_proc_core_many(false, itm);}
public Xoa_gfs_bldr Add_proc_cont_one(String itm) {return Add_proc_core_many(true, itm);}
public Xoa_gfs_bldr Add_proc_cont_many(String... ary) {return Add_proc_core_many(true, ary);}
Xoa_gfs_bldr Add_proc_core_many(boolean cont, String... ary) {
int ary_len = ary.length;
for (int i = 0; i < ary_len; i++) {
if (i != 0 || cont) bfr.Add_byte(Byte_ascii.Dot);
bfr.Add_str_u8(ary[i]);
}
return this;
}
public Xoa_gfs_bldr Add_indent(int i) {bfr.Add_byte_repeat(Byte_ascii.Space, i * 2); return this;}
public Xoa_gfs_bldr Add_parens_str(String v) {return Add_parens_str(Bry_.new_u8(v));}
public Xoa_gfs_bldr Add_parens_str(byte[] v) {return this.Add_paren_bgn().Add_arg_str(v).Add_paren_end();}
public Xoa_gfs_bldr Add_parens_str_many(String... ary) {
this.Add_paren_bgn();
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) this.Add_comma();
this.Add_arg_str(Bry_.new_u8(ary[i]));
}
this.Add_paren_end();
return this;
}
public Xoa_gfs_bldr Add_arg_int(int v) {bfr.Add_int_variable(v); return this;}
public Xoa_gfs_bldr Add_arg_yn(boolean v) {Add_quote_0(); bfr.Add_byte(v ? Byte_ascii.Ltr_y : Byte_ascii.Ltr_n); Add_quote_0(); return this;}
public Xoa_gfs_bldr Add_arg_str(byte[] v) {bfr.Add_byte(Byte_ascii.Apos); Add_str_escape_apos(bfr, v); bfr.Add_byte(Byte_ascii.Apos); return this;}
public Xoa_gfs_bldr Add_indent() {bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Space); return this;}
public Xoa_gfs_bldr Add_nl() {bfr.Add_byte_nl(); return this;}
public Xoa_gfs_bldr Add_comma() {bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space); return this;}
public Xoa_gfs_bldr Add_curly_bgn_nl() {bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Curly_bgn).Add_byte_nl(); return this;}
public Xoa_gfs_bldr Add_curly_end_nl() {bfr.Add_byte(Byte_ascii.Curly_end).Add_byte_nl(); return this;}
public Xoa_gfs_bldr Add_paren_bgn() {bfr.Add_byte(Byte_ascii.Paren_bgn); return this;}
public Xoa_gfs_bldr Add_paren_end() {bfr.Add_byte(Byte_ascii.Paren_end); return this;}
public Xoa_gfs_bldr Add_quote_xtn_bgn() {bfr.Add(Bry_xquote_bgn); return this;}
public Xoa_gfs_bldr Add_quote_xtn_end() {bfr.Add(Bry_xquote_end); return this;}
public Xoa_gfs_bldr Add_quote_xtn_apos_bgn() {bfr.Add_byte(Byte_ascii.Paren_bgn).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Nl); return this;}
public Xoa_gfs_bldr Add_quote_xtn_apos_end() {bfr.Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Paren_end).Add_byte(Byte_ascii.Semic).Add_byte(Byte_ascii.Nl); return this;}
public Xoa_gfs_bldr Add_quote_0() {bfr.Add_byte(Byte_ascii.Apos); return this;}
public Xoa_gfs_bldr Add_term_nl() {bfr.Add(Bry_semic_nl); return this;}
public Xoa_gfs_bldr Add_eq_str(String k, byte[] v) {
bfr.Add_str_u8(k);
bfr.Add(Bry_eq);
bfr.Add_byte_apos();
bfr.Add(v);
bfr.Add_byte_apos();
bfr.Add(Bry_semic_nl);
return this;
}
private static final byte[] Bry_eq = Bry_.new_a7(" = "), Bry_semic_nl = Bry_.new_a7(";\n");
private void Add_str_escape_apos(Bry_bfr bfr, byte[] src) {
int len = src.length;
for (int i = 0; i < len; i++) {
byte b = src[i];
if (b == Byte_ascii.Apos)
bfr.Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Apos);
else
bfr.Add_byte(b);
}
}
public static final byte[]
Bry_xquote_bgn = Bry_.new_a7("<:['\n")
, Bry_xquote_end = Bry_.new_a7("']:>\n")
;
}

View File

@@ -0,0 +1,70 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.langs.gfs.*;
import gplx.xowa.users.*; import gplx.xowa.apps.fsys.*;
public class Xoa_gfs_mgr implements Gfo_invk, Gfo_invk_root_wkr {
private final String user_name;
public Xoa_gfs_mgr(String user_name, Gfo_invk root_invk, Xoa_fsys_mgr app_fsys_mgr) {
this.user_name = user_name;
this.root_invk = root_invk; this.app_fsys_mgr = app_fsys_mgr;
GfsCore.Instance.AddCmd(root_invk, Xoae_app.Invk_app);
GfsCore.Instance.AddCmd(root_invk, Xoae_app.Invk_xowa);
}
public Gfo_invk Root_invk() {return root_invk;} private final Gfo_invk root_invk;
public Xoa_fsys_mgr App_fsys_mgr() {return app_fsys_mgr;} private final Xoa_fsys_mgr app_fsys_mgr;
public Xoa_app_eval Eval_mgr() {return eval_mgr;} private final Xoa_app_eval eval_mgr = new Xoa_app_eval();
public Gfs_wtr Wtr() {return wtr;} private final Gfs_wtr wtr = new Gfs_wtr();
public void Run_url(Io_url url) {
Run_url_for(GfsCore.Instance.Root(), url);
Gfo_usr_dlg_.Instance.Log_wkr().Log_to_session_fmt("gfs.done: ~{0}", url.Raw());
}
public void Run_url_for(Gfo_invk invk, Io_url url) {
String raw = Io_mgr.Instance.LoadFilStr_args(url).MissingIgnored_().Exec(); if (String_.Len_eq_0(raw)) return;
Run_str_for(invk, raw);
}
public Object Run_str(String raw) {return Run_str_for(GfsCore.Instance.Root(), raw);}
public Object Run_str_for(Gfo_invk invk, String raw) {return Run_str_for(invk, Xoa_gfs_mgr_.Parse_to_msg(raw));}
public Object Run_str_for(Gfo_invk invk, GfoMsg root_msg) {
try {
Object rv = null;
GfsCtx ctx = GfsCtx.new_().Fail_if_unhandled_(Fail_if_unhandled).Usr_dlg_(Gfo_usr_dlg_.Instance);
int len = root_msg.Subs_count();
for (int i = 0; i < len; ++i)
rv = GfsCore.Instance.ExecOne_to(ctx, invk, root_msg.Subs_getAt(i));
return rv; // return rv from last call
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "error while executing script: err=~{0}", Err_.Message_gplx_full(e));
return Gfo_invk_.Rv_error;
}
}
private void Run_url_by_type(String type) {
if (String_.Eq(type, "xowa_cfg_app")) Run_url(app_fsys_mgr.Cfg_app_fil());
else if (String_.Eq(type, "xowa.user.os")) gplx.xowa.addons.apps.cfgs.mgrs.dflts.Xocfg_dflt_mgr.Run_os_gfs(user_name, this, app_fsys_mgr);
else throw Err_.new_wo_type("invalid gfs type", "type", type);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run_file_by_type)) Run_url_by_type(m.ReadStr("v"));
else if (ctx.Match(k, Invk_fail_if_unhandled_)) {Fail_if_unhandled = m.ReadYn("v"); ctx.Fail_if_unhandled_(Fail_if_unhandled);}
else if (ctx.Match(k, Invk_txns)) {return Gfo_invk_.Noop;} // FUTURE: handle version for upgrades
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_run_file_by_type = "run_file_by_type", Invk_fail_if_unhandled_ = "fail_if_unhandled_", Invk_txns = "txns";
public static void Msg_parser_init() {GfsCore.Instance.MsgParser_(gplx.langs.gfs.Gfs_msg_bldr.Instance);}
public static boolean Fail_if_unhandled = false;
}

View File

@@ -0,0 +1,30 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.langs.gfs.*;
public class Xoa_gfs_mgr_ {
public static GfoMsg Parse_to_msg(String v) {return Gfs_msg_bldr.Instance.ParseToMsg(v);}
public static void Cfg_os_assert(Io_url orig_url) {
Io_url dflt_url = orig_url.GenNewNameOnly(orig_url.NameOnly() + "_default");
if (!Io_mgr.Instance.ExistsFil(dflt_url)) return; // no dflt
if (!Io_mgr.Instance.ExistsFil(orig_url)) {
Io_mgr.Instance.CopyFil(dflt_url, orig_url, true);
Gfo_usr_dlg_.Instance.Log_many("", "", "xowa_cfg_os generated; url=~{0}", orig_url.Raw());
}
}
}

View File

@@ -0,0 +1,38 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_gfs_wtr_ {
public static byte[] Escape(String v) {return Escape(Bry_.new_u8(v));}
public static byte[] Escape(byte[] v) {
return Bry_find_.Find_fwd(v, Byte_ascii.Apos) == Bry_find_.Not_found ? v : Bry_.Replace(v, Byte_ascii.Apos_bry, Bry__apos_escaped);
} private static final byte[] Bry__apos_escaped = Bry_.new_a7("''");
public static void Write_prop(Bry_bfr bfr, byte[] prop, byte[] val) {
bfr.Add(prop).Add(Bry__val_bgn).Add(Xoa_gfs_wtr_.Escape(val)).Add(Bry__val_end); // EX: "a_('b');\n"
} private static final byte[] Bry__val_bgn = Bry_.new_a7("_('"), Bry__val_end = Bry_.new_a7("');\n");
public static String Write_func_chain(String... ary) { // EX: "a.b.c"
Bry_bfr bfr = Bry_bfr_.New();
try {
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte(Byte_ascii.Dot);
bfr.Add_str_u8(ary[i]);
}
return bfr.To_str_and_clear();
} finally {bfr.Mkr_rls();}
}
}

View File

@@ -0,0 +1,42 @@
/*
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.apps.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.bldrs.wms.sites.*;
public class Xoa_meta_mgr {
private final Xoa_app app;
private final Hash_adp_bry ns__hash = Hash_adp_bry.cs();
private Site_core_db core_db;
public Xoa_meta_mgr(Xoa_app app) {
this.app = app;
}
public void Ns__add(byte[] wiki_domain, Xow_ns_mgr ns_mgr) {ns__hash.Add(wiki_domain, ns_mgr);} // TEST:public
public Xow_ns_mgr Ns__get_or_load(byte[] wiki_domain) {
Xow_ns_mgr rv = (Xow_ns_mgr)ns__hash.Get_by_bry(wiki_domain);
if (rv == null) {
Core_db__assert();
rv = core_db.Load_namespace(wiki_domain);
Ns__add(wiki_domain, rv);
rv.Init(); // must init to fill Ords
}
return rv;
}
private void Core_db__assert() {
if (core_db == null) core_db = new Site_core_db(app.Fsys_mgr().Cfg_site_meta_fil());
}
}

View File

@@ -0,0 +1,47 @@
/*
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.apps.miscs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_misc_mgr implements Gfo_invk {
private Xoa_app app;
public void Init_by_app(Xoa_app app) {
this.app = app;
app.Cfg().Bind_many_app(this, Cfg__web_enabled, Cfg__logs_enabled, Cfg__script);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__web_enabled)) gplx.core.ios.IoEngine_system.Web_access_enabled = m.ReadYn("v");
else if (ctx.Match(k, Cfg__logs_enabled)) {
if (app.Tid_is_edit()) {
Xoae_app appe = (Xoae_app)app;
boolean logs_enabled = m.ReadYn("v");
appe.Log_wtr().Enabled_(logs_enabled);
if (!logs_enabled)
Io_mgr.Instance.DeleteFil_args(appe.Log_wtr().Session_fil()).MissingFails_off().Exec();
}
}
else if (ctx.Match(k, Cfg__script)) {
String script = m.ReadStr("v");
Object rslt = app.Gfs_mgr().Run_str(script);
if (rslt == Gfo_invk_.Rv_error) {
app.Usr_dlg().Warn_many("", "", "custom script failed: ~{0}", script);
}
}
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Cfg__web_enabled = "xowa.app.web.enabled", Cfg__logs_enabled = "xowa.app.logs.enabled", Cfg__script = "xowa.app.startup.script";
}

View File

@@ -0,0 +1,146 @@
/*
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.apps.progs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.files.*; import gplx.core.envs.*;
public class Xoa_prog_mgr implements Gfo_invk {
private Xoa_app app;
private Gfo_usr_dlg usr_dlg;
private Process_adp app_web;
private Process_adp[] apps_by_ext = new Process_adp[Xof_ext_.Id__max];
public void Init_by_app(Xoa_app app, Xoa_fsys_eval cmd_eval) {
this.app = app;
this.usr_dlg = Xoa_app_.Usr_dlg();
Process_adp.ini_(this, usr_dlg, app_query_img_size , cmd_eval, Process_adp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}imagemagick\\identify", "-ping -format \"<{%w,%h}>\" \"~{file}\"", "file");
Process_adp.ini_(this, usr_dlg, app_resize_img , cmd_eval, Process_adp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "\"~{source}\" -coalesce -resize ~{width}x~{height} \"~{target}\"", "source", "target", "width", "height");
Process_adp.ini_(this, usr_dlg, app_convert_svg_to_png , cmd_eval, Process_adp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}inkscape\\inkscape", "-z -w ~{width} -f \"~{source}\" -e \"~{target}\"", "source", "target", "width").Thread_kill_name_("inkscape.exe"); // // -z=without-gui; -w=width; -f=file -e=export-png
Process_adp.ini_(this, usr_dlg, app_convert_tex_to_dvi , cmd_eval, Process_adp.Run_mode_sync_timeout , 2 * 60, "~{<>bin_plat_dir<>}miktex\\miktex\\bin\\latex", "-quiet -output-directory=~{temp_dir} -job-name=xowa_temp ~{tex_file}", "tex_file", "temp_dir");
Process_adp.ini_(this, usr_dlg, app_convert_dvi_to_png , cmd_eval, Process_adp.Run_mode_sync_timeout , 2 * 60, "~{<>bin_plat_dir<>}miktex\\miktex\\bin\\dvipng", "~{dvi_file} -o ~{png_file} -q* -T tight -bg Transparent", "dvi_file", "png_file", "temp_dir");
Process_adp.ini_(this, usr_dlg, app_convert_djvu_to_tiff , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}djvulibre\\ddjvu", "-format=tiff -page=1 \"~{source}\" \"~{target}\"", "source", "target");
Process_adp.ini_(this, usr_dlg, app_decompress_bz2 , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
Process_adp.ini_(this, usr_dlg, app_decompress_bz2_by_stdout, cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -so \"~{src}\"", "src"); // x=extract; -so=stdout
Process_adp.ini_(this, usr_dlg, app_decompress_zip , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
Process_adp.ini_(this, usr_dlg, app_decompress_gz , cmd_eval, Process_adp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -y \"~{src}\" -o\"~{trg_dir}\"", "src", "trg", "trg_dir"); // x=extract; -y=yes on all queries; -o=output_dir
Process_adp.ini_(this, usr_dlg, app_lua , cmd_eval, Process_adp.Run_mode_async , 0 , "~{<>bin_plat_dir<>}lua\\lua", "", "");
Process_adp.ini_(this, usr_dlg, app_lilypond , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\lilypond.exe", "\"-dsafe=#t\" -dbackend=ps --png --header=texidoc -dmidi-extension=midi \"~{file}\"", "file");
Process_adp.ini_(this, usr_dlg, app_abc2ly , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\python.exe", "abc2ly.py -s \"--output=~{target}\" \"~{source}\"", "source", "target");
Process_adp.ini_(this, usr_dlg, app_trim_img , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "-trim \"~{source}\" \"~{target}\"", "source", "target");
Process_adp.ini_(this, usr_dlg, app_midi_to_ogg , cmd_eval, Process_adp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}timidity\\timidity", "-Ov \"--output-file=~{target}\" \"~{source}\"", "source", "target");
Process_adp.ini_(this, usr_dlg, app_view_text , cmd_eval, Process_adp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
for (int i = 0; i < apps_by_ext.length; i++) {
apps_by_ext[i] = Process_adp.New(usr_dlg, cmd_eval, Process_adp.Run_mode_async, 0, "cmd", "/c start \"\" \"~{file}\"", "file");
}
app_web = Process_adp.New(usr_dlg, cmd_eval, Process_adp.Run_mode_async, 0, "cmd", "/c start \"\" \"~{url}\"", "url");
app.Cfg().Bind_many_app(this
, Cfg__web, Cfg__media, Cfg__image, Cfg__svg, Cfg__pdf, Cfg__djvu
, Cfg__gz, Cfg__bz2, Cfg__bz2__stdout_cmd
, Cfg__query_size, Cfg__resize_img, Cfg__convert_svg_to_png, Cfg__convert_djvu_to_tiff
, Cfg__convert_tex_to_dvi, Cfg__convert_dvi_to_png
, Cfg__lua
, Cfg__lilypond, Cfg__abc2ly, Cfg__trim_img, Cfg__midi_to_ogg
);
}
private Process_adp App_by_ext_key(String ext) {return apps_by_ext[Xof_ext_.Get_id_by_ext_(Bry_.new_a7(ext))];}
public Process_adp App_query_img_size() {return app_query_img_size;} private Process_adp app_query_img_size = new Process_adp();
public Process_adp App_resize_img() {return app_resize_img;} private Process_adp app_resize_img = new Process_adp();
public Process_adp App_convert_svg_to_png() {return app_convert_svg_to_png;} private Process_adp app_convert_svg_to_png = new Process_adp();
public Process_adp App__tex_to_dvi() {return app_convert_tex_to_dvi;} private Process_adp app_convert_tex_to_dvi = new Process_adp();
public Process_adp App__dvi_to_png() {return app_convert_dvi_to_png;} private Process_adp app_convert_dvi_to_png = new Process_adp();
public Process_adp App_convert_djvu_to_tiff() {return app_convert_djvu_to_tiff;} private Process_adp app_convert_djvu_to_tiff = new Process_adp();
public Process_adp App_view_text() {return app_view_text;} private Process_adp app_view_text = new Process_adp();
public Process_adp App_decompress_bz2() {return app_decompress_bz2;} private Process_adp app_decompress_bz2 = new Process_adp();
public Process_adp App_decompress_zip() {return app_decompress_zip;} private Process_adp app_decompress_zip = new Process_adp();
public Process_adp App_decompress_gz() {return app_decompress_gz;} private Process_adp app_decompress_gz = new Process_adp();
public Process_adp App_decompress_bz2_by_stdout() {return app_decompress_bz2_by_stdout;} private Process_adp app_decompress_bz2_by_stdout = new Process_adp();
public Process_adp App_lua() {return app_lua;} private Process_adp app_lua = new Process_adp();
public Process_adp App_lilypond() {return app_lilypond;} private Process_adp app_lilypond = new Process_adp();
public Process_adp App_abc2ly() {return app_abc2ly;} private Process_adp app_abc2ly = new Process_adp();
public Process_adp App_trim_img() {return app_trim_img;} private Process_adp app_trim_img = new Process_adp();
public Process_adp App_convert_midi_to_ogg() {return app_midi_to_ogg;} private Process_adp app_midi_to_ogg = new Process_adp();
public Process_adp App_by_ext(String ext) {return App_by_ext_key(String_.Mid(ext, 1));} // ignore 1st . in ext; EX: ".png" -> "png"
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_convert_tex_to_dvi)) return app_convert_tex_to_dvi;
else if (ctx.Match(k, Invk_convert_dvi_to_png)) return app_convert_dvi_to_png;
else if (String_.Eq(k, Cfg__web)) {Init_cmd(m.ReadStr("v"), app_web);}
else if (String_.Eq(k, Cfg__media)) {Init_cmd(m.ReadStr("v"), Xof_ext_.Id_ogv, Xof_ext_.Id_webm, Xof_ext_.Id_flac, Xof_ext_.Id_ogg, Xof_ext_.Id_oga, Xof_ext_.Id_mid, Xof_ext_.Id_wav);}
else if (String_.Eq(k, Cfg__image)) {Init_cmd(m.ReadStr("v"), Xof_ext_.Id_png, Xof_ext_.Id_jpg, Xof_ext_.Id_jpeg, Xof_ext_.Id_gif, Xof_ext_.Id_tif, Xof_ext_.Id_tiff, Xof_ext_.Id_bmp);}
else if (String_.Eq(k, Cfg__svg)) {Init_cmd(m.ReadStr("v"), Xof_ext_.Id_svg);}
else if (String_.Eq(k, Cfg__pdf)) {Init_cmd(m.ReadStr("v"), Xof_ext_.Id_pdf);}
else if (String_.Eq(k, Cfg__djvu)) {Init_cmd(m.ReadStr("v"), Xof_ext_.Id_djvu);}
else if (String_.Eq(k, Cfg__gz)) {Init_cmd(m.ReadStr("v"), app_decompress_gz);}
else if (String_.Eq(k, Cfg__bz2)) {Init_cmd(m.ReadStr("v"), app_decompress_bz2);}
else if (String_.Eq(k, Cfg__bz2__stdout_cmd)) {Init_cmd(m.ReadStr("v"), app_decompress_bz2_by_stdout);}
else if (String_.Eq(k, Cfg__query_size)) {Init_cmd(m.ReadStr("v"), app_query_img_size);}
else if (String_.Eq(k, Cfg__resize_img)) {Init_cmd(m.ReadStr("v"), app_resize_img);}
else if (String_.Eq(k, Cfg__convert_svg_to_png)) {Init_cmd(m.ReadStr("v"), app_convert_svg_to_png);}
else if (String_.Eq(k, Cfg__convert_djvu_to_tiff)) {Init_cmd(m.ReadStr("v"), app_convert_djvu_to_tiff);}
else if (String_.Eq(k, Cfg__convert_tex_to_dvi)) {Init_cmd(m.ReadStr("v"), app_convert_tex_to_dvi);}
else if (String_.Eq(k, Cfg__convert_dvi_to_png)) {Init_cmd(m.ReadStr("v"), app_convert_dvi_to_png);}
else if (String_.Eq(k, Cfg__lua)) {Init_cmd(m.ReadStr("v"), app_lua); gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all((Xoae_app)app);}
else if (String_.Eq(k, Cfg__lilypond)) {Init_cmd(m.ReadStr("v"), app_lilypond);}
else if (String_.Eq(k, Cfg__abc2ly)) {Init_cmd(m.ReadStr("v"), app_abc2ly);}
else if (String_.Eq(k, Cfg__trim_img)) {Init_cmd(m.ReadStr("v"), app_trim_img);}
else if (String_.Eq(k, Cfg__midi_to_ogg)) {Init_cmd(m.ReadStr("v"), app_midi_to_ogg);}
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static void Init_cmd(String exe_and_args, Process_adp proc) {
String[] lines = gplx.xowa.addons.apps.cfgs.Xocfg_mgr.Parse_io_cmd(exe_and_args);
proc.Exe_and_args_(lines[0], lines[1]);
}
private void Init_cmd(String exe_and_args, int... exts) {
String[] lines = gplx.xowa.addons.apps.cfgs.Xocfg_mgr.Parse_io_cmd(exe_and_args);
for (int ext_id : exts) {
apps_by_ext[ext_id].Exe_and_args_(lines[0], lines[1]);
}
}
public void Exec_view_web(byte[] url) {
String url_str = String_.new_u8(url);
url_str = String_.Replace(url_str, "\"", "\"\""); // escape quotes; DATE:2013-03-31
url_str = Process_adp.Escape_ampersands_if_process_is_cmd(Op_sys.Cur().Tid_is_wnt(), app_web.Exe_url().Raw(), url_str); // escape ampersands; DATE:2014-05-20
app_web.Run(url_str);
}
private static final String Invk_convert_tex_to_dvi = "convert_tex_to_dvi", Invk_convert_dvi_to_png = "convert_dvi_to_png";
private static final String
Cfg__web = "xowa.files.apps.view.web"
, Cfg__media = "xowa.files.apps.view.media"
, Cfg__image = "xowa.files.apps.view.image"
, Cfg__svg = "xowa.files.apps.view.svg"
, Cfg__pdf = "xowa.files.apps.view.pdf"
, Cfg__djvu = "xowa.files.apps.view.djvu"
, Cfg__query_size = "xowa.files.apps.make.img_size_get"
, Cfg__resize_img = "xowa.files.apps.make.img_size_set"
, Cfg__convert_svg_to_png = "xowa.files.apps.make.svg_to_png"
, Cfg__convert_djvu_to_tiff = "xowa.files.apps.make.djvu_to_tiff"
, Cfg__bz2__stdout_cmd = "xowa.bldr.import.apps.bz2_stdout.cmd"
, Cfg__bz2 = "xowa.bldr.import.apps.bz2"
, Cfg__gz = "xowa.bldr.import.apps.gz"
, Cfg__lua = "xowa.addon.scribunto.lua.cmd"
, Cfg__convert_tex_to_dvi = "xowa.addon.math.apps.tex_to_dvi"
, Cfg__convert_dvi_to_png = "xowa.addon.math.apps.dvi_to_png"
, Cfg__lilypond = "xowa.addon.score.apps.lilypond"
, Cfg__abc2ly = "xowa.addon.score.apps.abc2ly"
, Cfg__trim_img = "xowa.addon.score.apps.trim_img"
, Cfg__midi_to_ogg = "xowa.addon.score.apps.midi_to_ogg"
;
}

View File

@@ -0,0 +1,86 @@
/*
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.apps.servers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.primitives.*; import gplx.core.js.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*;
import gplx.xowa.apps.servers.tcp.*;
import gplx.xowa.apps.servers.http.*; import gplx.xowa.guis.views.*;
public class Gxw_html_server implements Gxw_html {
private Xosrv_socket_wtr wtr; private Gfo_usr_dlg usr_dlg;
private final Js_wtr js_wtr = new Js_wtr();
public Gxw_html_server(Gfo_usr_dlg usr_dlg, Xosrv_socket_wtr wtr) {
this.usr_dlg = usr_dlg; this.wtr = wtr;
}
public void Html_doc_html_load_by_mem(String html) {Exec_as_str("location.reload(true);");} // HACK: force reload of page
public void Html_doc_html_load_by_url(Io_url path, String html) {Exec_as_str("location.reload(true);");} // HACK: force reload of page
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
public void Html_dispose() {}
public void Html_js_enabled_(boolean v) {}
public String Html_js_eval_proc_as_str(String name, Object... args) {return Exec_as_str(js_wtr.Write_statement_return_func(name, args).To_str_and_clear());} // TODO_OLD: add other params
public boolean Html_js_eval_proc_as_bool(String name, Object... args) {return Exec_as_bool(js_wtr.Write_statement_return_func(name, args).To_str_and_clear());}
public String Html_js_eval_script(String script) {return Exec_as_str(script);}
public Object Html_js_eval_script_as_obj(String script) {return Exec_as_str(script);}
public void Html_js_cbks_add(String js_func_name, Gfo_invk invk) {}
public String Html_js_send_json(String name, String data) {throw Err_.new_unimplemented();}
public void Html_invk_src_(Gfo_evt_itm v) {}
public GxwCore_base Core() {throw Err_.new_unimplemented();}
public GxwCbkHost Host() {throw Err_.new_unimplemented();} public void Host_set(GxwCbkHost host) {throw Err_.new_unimplemented();}
public Object UnderElem() {throw Err_.new_unimplemented();}
public String TextVal() {throw Err_.new_unimplemented();} public void TextVal_set(String v) {throw Err_.new_unimplemented();}
public void EnableDoubleBuffering() {throw Err_.new_unimplemented();}
private boolean Exec_as_bool(String s) {
Exec_as_str(s);
return true; // NOTE: js is async, so immediate return value is not possible; return true for now;
}
private String Exec_as_str(String s) {
if (wtr == null) return ""; // HACK: handles http_server
s = "(function () {" + s + "})();"; // NOTE: dependent on firefox_addon which does 'var result = Function("with(arguments[0]){return "+cmd_text+"}")(session.window);'; DATE:2014-01-28
gplx.core.threads.Thread_adp_.Sleep(50); // NOTE: need to sleep, else images won't actually show up on screen; PAGE:nethackwiki.com:Weapons; DATE:2015-08-23
Xosrv_msg msg = Xosrv_msg.new_(Xosrv_cmd_types.Browser_exec, Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.new_u8(s));
usr_dlg.Note_many("", "", "sending browser.js: msg=~{0}", s);
wtr.Write(msg);
return "";
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_set)) {}
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_set = "set";
public static void Init_gui_for_server(Xoae_app app, Xosrv_socket_wtr wtr) {
Mem_kit mem_kit = (Mem_kit)Gfui_kit_.Mem();
mem_kit.New_html_impl_prototype_(new Gxw_html_server(app.Usr_dlg(), wtr)); // NOTE: set prototype before calling Kit_
app.Gui_mgr().Kit_(mem_kit);
}
public static void Assert_tab(Xoae_app app, Xoae_page page) {
Xog_win_itm browser_win = app.Gui_mgr().Browser_win();
if (browser_win.Active_tab() == null) { // no active tab
Xowe_wiki wiki = page.Wikie(); // take wiki from current page; NOTE: do not take from browser_win.Active_tab().Wiki(); DATE:2015-02-23
browser_win.Tab_mgr().Tabs_new_init(wiki, page); // create at least one active tab; DATE:2014-07-30
}
}
public static Xog_tab_itm Assert_tab2(Xoae_app app, Xowe_wiki wiki) {
Xog_win_itm browser_win = app.Gui_mgr().Browser_win();
Xog_tab_itm rv = browser_win.Active_tab();
if (rv == null) { // no active tab
Xoae_page page = Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_a7("Empty_tab")));
rv = browser_win.Tab_mgr().Tabs_new_init(wiki, page); // create at least one active tab; DATE:2014-07-30
}
return rv;
}
}

View File

@@ -0,0 +1,36 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
class File_retrieve_mode {
public static String Xto_str(byte v) {
switch (v) {
case Mode_skip: return "skip";
case Mode_wait: return "wait";
case Mode_async_server: return "async_server";
default: throw Err_.new_unimplemented();
}
}
public static byte Xto_byte(String s) {
if (String_.Eq(s, "skip")) return Mode_skip;
else if (String_.Eq(s, "wait")) return Mode_wait;
else if (String_.Eq(s, "async_server")) return Mode_async_server;
else throw Err_.new_unimplemented();
}
public static final byte Mode_skip = 1, Mode_wait = 2, Mode_async_server = 3;
public static Keyval[] Options__list = Keyval_.Ary(Keyval_.new_("wait"), Keyval_.new_("skip"), Keyval_.new_("async_server", "async server"));
}

View File

@@ -0,0 +1,27 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.langs.jsons.*;
public class Http_data__client {
public Http_data__client(byte[] server_host, String ip_address_str) {
this.server_host = server_host;
this.ip_address = Bry_.new_a7(ip_address_str);
}
public byte[] Server_host() {return server_host;} private final byte[] server_host;
public byte[] Ip_address() {return ip_address;} private final byte[] ip_address;
}

View File

@@ -0,0 +1,50 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.xowa.files.*;
class Http_file_utl {
public static byte[] To_mime_type_by_path_as_bry(byte[] path_bry) {
int dot_pos = Bry_find_.Find_bwd(path_bry, Byte_ascii.Dot);
return dot_pos == Bry_find_.Not_found ? Mime_octet_stream : To_mime_type_by_ext_as_bry(path_bry, dot_pos, path_bry.length);
}
public static byte[] To_mime_type_by_ext_as_bry(byte[] ext_bry, int bgn, int end) {
Object o = mime_hash.Get_by_mid(ext_bry, bgn, end);
return o == null ? Mime_octet_stream : (byte[])o;
}
private static final byte[]
Mime_octet_stream = Xof_ext_.Mime_type__ary[Xof_ext_.Id_unknown]
, Mime_html = Bry_.new_a7("text/html")
, Mime_css = Bry_.new_a7("text/css")
, Mime_js = Bry_.new_a7("application/javascript")
;
private static final Hash_adp_bry mime_hash = Mime_hash__new();
private static Hash_adp_bry Mime_hash__new() {
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
int len = Xof_ext_.Id__max;
for (int i = 0; i < len; ++i) {
rv.Add_bry_obj
( Bry_.Add(Byte_ascii.Dot, Xof_ext_.Bry__ary[i])
, Xof_ext_.Mime_type__ary[i]);
}
rv.Add_str_obj(".htm" , Mime_html);
rv.Add_str_obj(".html" , Mime_html);
rv.Add_str_obj(".css" , Mime_css);
rv.Add_str_obj(".js" , Mime_js);
return rv;
}
}

View File

@@ -0,0 +1,150 @@
/*
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/>.
*/
/*
This file is part of XOWA: the XOWA Offline Wiki Application
Copyright (C) 2013 matthiasjasny@gmail.com
This file 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 file 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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.threads.*; import gplx.core.net.*; import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.langs.jsons.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.wikis.pages.*;
public class Http_server_mgr implements Gfo_invk {
private final Object thread_lock = new Object();
private final Gfo_usr_dlg usr_dlg;
private Http_server_socket wkr;
private byte retrieve_mode = File_retrieve_mode.Mode_wait;
private boolean running, init_gui_needed = true;
public Http_server_mgr(Xoae_app app) {
this.app = app;
this.usr_dlg = app.Usr_dlg();
this.request_parser = new Http_request_parser(server_wtr, false);
}
public Xoae_app App() {return app;} private final Xoae_app app;
public Http_server_wtr Server_wtr() {return server_wtr;} private final Http_server_wtr server_wtr = Http_server_wtr_.New__console();
public Http_request_parser Request_parser() {return request_parser;} private final Http_request_parser request_parser;
public Gfo_url_encoder Encoder() {return encoder;} private final Gfo_url_encoder encoder = Gfo_url_encoder_.New__http_url().Make();
public int Port() {return port;} public Http_server_mgr Port_(int v) {port = v; return this;} private int port = 8080;
public Http_server_wkr_pool Wkr_pool() {return wkr_pool;} private final Http_server_wkr_pool wkr_pool = new Http_server_wkr_pool();
public Int_pool Uid_pool() {return uid_pool;} private final Int_pool uid_pool = new Int_pool();
public byte[] Home() {return home;} public void Home_(byte[] v) {home = Bry_.Add(Byte_ascii.Slash_bry, v);} private byte[] home = Bry_.new_a7("/home/wiki/Main_Page");
private void Running_(boolean val) {
if (val) {
if (running)
Note("HTTP Server already started");
else {
Run();
}
}
else {
if (running) {
wkr.Canceled_(true);
wkr = null;
Note("HTTP Server stopped");
}
else
Note("HTTP Server not started");
}
running = val;
}
public void Run() {
app.Cfg().Bind_many_app(this, Cfg__port, Cfg__file_retrieve_mode);
if (wkr == null) wkr = new Http_server_socket(this);
Thread_adp_.Start_by_key("thread:xowa.http_server.server", wkr, Http_server_socket.Invk_run);
Note("HTTP Server started: Navigate to http://localhost:" + Int_.To_str(port));
}
public void Run_xowa_cmd(Xoae_app app, String url_encoded_str) {
Gfo_url_encoder url_converter = Gfo_url_encoder_.New__http_url().Make(); // create instance for each call
String cmd = url_converter.Decode_str(url_encoded_str);
app.Gfs_mgr().Run_str(cmd);
}
public String Parse_page_to_html(Http_data__client data__client, byte[] wiki_domain, byte[] ttl_bry) {
synchronized (thread_lock) {
// create a shim gui to automatically handle default XOWA gui JS calls
if (init_gui_needed) {
init_gui_needed = false;
Gxw_html_server.Init_gui_for_server(app, null);
}
// get the wiki
Xowe_wiki wiki = (Xowe_wiki)app.Wiki_mgr().Get_by_or_make_init_y(wiki_domain); // assert init for Main_Page; EX:click zh.w on wiki sidebar; DATE:2015-07-19
if (Runtime_.Memory_total() > Io_mgr.Len_gb) Xowe_wiki_.Rls_mem(wiki, true); // release memory at 1 GB; DATE:2015-09-11
// get the url / ttl
if (Bry_.Len_eq_0(ttl_bry)) ttl_bry = wiki.Props().Main_page();
Xoa_url url = wiki.Utl__url_parser().Parse(ttl_bry);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
// get the page
gplx.xowa.guis.views.Xog_tab_itm tab = Gxw_html_server.Assert_tab2(app, wiki); // HACK: assert tab exists
Xoae_page page = wiki.Page_mgr().Load_page(url, ttl, tab);
app.Gui_mgr().Browser_win().Active_page_(page); // HACK: init gui_mgr's page for output (which server ordinarily doesn't need)
if (page.Db().Page().Exists_n()) { // if page does not exist, replace with message; else null_ref error; DATE:2014-03-08
page.Db().Text().Text_bry_(Bry_.new_a7("'''Page not found.'''"));
wiki.Parser_mgr().Parse(page, false);
}
page.Html_data().Head_mgr().Itm__server().Init_by_http(data__client).Enabled_y_();
// generate html
String rv = String_.new_u8(wiki.Html_mgr().Page_wtr_mgr().Gen(page, Xopg_page_.Tid_read)); // NOTE: must generate HTML now in order for "wait" and "async_server" to work with text_dbs; DATE:2016-07-10
boolean rebuild_html = false;
switch (retrieve_mode) {
case File_retrieve_mode.Mode_skip: // noop
break;
case File_retrieve_mode.Mode_async_server:
rebuild_html = true;
app.Gui_mgr().Browser_win().Page__async__bgn(tab);
break;
case File_retrieve_mode.Mode_wait:
rebuild_html = true;
gplx.xowa.guis.views.Xog_async_wkr.Async(page, tab.Html_itm());
page = wiki.Page_mgr().Load_page(url, ttl, tab); // HACK: fetch page again so that HTML will now include img data
break;
}
if (rebuild_html) rv = String_.new_u8(wiki.Html_mgr().Page_wtr_mgr().Gen(page, Xopg_page_.Tid_read));
return rv;
}
}
private void Note(String s) {
// usr_dlg.Prog_many("", "", s); // messages should write to progress bar for gui
usr_dlg.Note_many("", "", s);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__port)) Port_(m.ReadInt("v"));
else if (ctx.Match(k, Cfg__file_retrieve_mode)) retrieve_mode = File_retrieve_mode.Xto_byte(m.ReadStr("v"));
else if (ctx.Match(k, Invk_running_)) Running_(m.ReadYn("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_running_ = "running_";
private static final String
Cfg__port = "xowa.addon.http_server.port"
, Cfg__file_retrieve_mode = "xowa.addon.http_server.file_retrieve_mode";
}

View File

@@ -0,0 +1,64 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.net.*; import gplx.core.threads.*; import gplx.core.primitives.*;
class Http_server_socket implements Gfo_invk {
private final Http_server_mgr server_mgr;
private Server_socket_adp server_socket;
public Http_server_socket(Http_server_mgr server_mgr) {this.server_mgr = server_mgr;}
public boolean Canceled() {return canceled;}
public Http_server_socket Canceled_(boolean v) {
canceled = v;
if (canceled) {
server_socket.Rls();
server_socket = null;
}
return this;
} private boolean canceled;
public void Run() {
if (server_socket == null) server_socket = new Server_socket_adp__base().Ctor(server_mgr.Port());
while (true) { // listen for incoming requests
Socket_adp client_socket = server_socket.Accept(); // NOTE: blocking call
int wkr_uid = -1; // NOTE: default to -1 to handle cases when http_server.max_clients is not set; DATE:2015-10-11
Http_server_wkr_pool wkr_pool = server_mgr.Wkr_pool();
if (wkr_pool.Enabled()) {
Http_server_wtr server_wtr = server_mgr.Server_wtr();
int timeout = wkr_pool.Timeout();
boolean print_msg = true;
while (wkr_pool.Full()) {
if (print_msg) {
print_msg = false;
server_wtr.Write_str_w_nl("maximum # of concurrent connections reached; max=" + wkr_pool.Max() + " timeout=" + timeout);
}
Thread_adp_.Sleep(timeout);
}
wkr_uid = server_mgr.Uid_pool().Get_next();
wkr_pool.Add(wkr_uid);
// server_wtr.Write_str_w_nl("added new worker; uid=" + wkr_uid);
}
Http_server_wkr wkr = new Http_server_wkr(server_mgr, wkr_uid);
wkr.Init_by_thread(client_socket);
Thread_adp_.Start_by_key("thread:xowa.http_server.client", wkr, Http_server_wkr.Invk_run);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) this.Run();
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_run = "run";
}

View File

@@ -0,0 +1,182 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.apps.*;
import gplx.xowa.htmls.js.*;
class Http_server_wkr implements Gfo_invk {
private final int uid;
private final Http_server_mgr server_mgr;
private final Http_server_wtr server_wtr;
private final Http_client_wtr client_wtr = Http_client_wtr_.new_stream();
private final Http_client_rdr client_rdr = Http_client_rdr_.new_stream();
private final Http_request_parser request_parser;
private final Gfo_url_encoder url_encoder;
private final Xoae_app app;
private final String root_dir_http;
private final byte[] root_dir_fsys;
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(64);
private Socket_adp socket;
private Http_data__client data__client;
public Http_server_wkr(Http_server_mgr server_mgr, int uid){
this.server_mgr = server_mgr; this.uid = uid;
this.app = server_mgr.App(); this.server_wtr = server_mgr.Server_wtr(); this.url_encoder = server_mgr.Encoder();
this.root_dir_http = app.Fsys_mgr().Root_dir().To_http_file_str();
this.root_dir_fsys = Bry_.new_u8(app.Fsys_mgr().Root_dir().Raw());
this.request_parser = server_mgr.Request_parser();
}
public void Init_by_thread(Socket_adp socket) {
this.socket = socket;
}
public void Run(){
Http_request_itm request = null;
try {
client_rdr.Stream_(socket.Get_input_stream());
client_wtr.Stream_(socket.Get_output_stream());
request = request_parser.Parse(client_rdr);
this.data__client = new Http_data__client(request.Host(), socket.Ip_address());
byte[] url_bry = request.Url();
if (Bry_.Eq(url_bry, Url__home)) url_bry = server_mgr.Home(); // "localhost:8080" comes thru as url of "/"; transform to custom home page; DATE:2015-10-11
switch (request.Type()) {
case Http_request_itm.Type_get: Process_get(request, url_bry); break;
case Http_request_itm.Type_post: Process_post(request); break;
}
client_wtr.Rls(); // client_rdr.Rls(); socket.Rls();
}
catch (Exception e) {
String request_str = request == null ? "<<NULL>>" : request.To_str(tmp_bfr, Bool_.N);
server_wtr.Write_str_w_nl(String_.Format("failed to process request;\nrequest={0}\nerr_msg={1}", request_str, Err_.Message_gplx_full(e)));
}
finally {
if (uid != -1) { // only release if uid was acquired; DATE:2015-10-11
server_mgr.Wkr_pool().Del(uid);
server_mgr.Uid_pool().Del(uid);
}
}
}
private void Process_get(Http_request_itm request, byte[] url) {
server_wtr.Write_str_w_nl(String_.new_u8(request.Host()) + "|GET|" + String_.new_u8(request.Url())); // use request url
if (Bry_.Has_at_bgn(url, Url__fsys)) Serve_file(url);
else if (Bry_.Has_at_bgn(url, Url__exec)) Exec_exec(url, Url__exec);
else if (Bry_.Has_at_bgn(url, Url__exec_2)) Exec_exec(url, Url__exec_2);
else Write_wiki(url);
}
private void Serve_file(byte[] url) {
tmp_bfr.Clear().Add(root_dir_fsys); // add "C:\xowa\"
int question_pos = Bry_find_.Find_fwd(url, Byte_ascii.Question);
int url_bgn = Bry_.Has_at_bgn(url, Url__fsys) ? Url__fsys_len : 0; // most files will have "/fsys/" at start, but Mathjax will not
int url_end = question_pos == Bry_find_.Not_found ? url.length : question_pos; // ignore files with query params; EX: /file/A.png?key=val
url_encoder.Decode(tmp_bfr, Bool_.N, url, url_bgn, url_end); // decode url to actual chars; note that XOWA stores on fsys in UTF-8 chars; "<22>" not "%C3"
byte[] path = tmp_bfr.To_bry_and_clear();
if (gplx.core.envs.Op_sys.Cur().Tid_is_wnt()) path = Bry_.Replace(path, Byte_ascii.Backslash, Byte_ascii.Slash);
client_wtr.Write_bry(Xosrv_http_wkr_.Rsp__http_ok);
// client_wtr.Write_str("Expires: Sun, 17-Jan-2038 19:14:07 GMT\n");
String mime_type = String_.new_u8(Http_file_utl.To_mime_type_by_path_as_bry(path));
client_wtr.Write_str("Content-Type: " + mime_type + "\n\n");
Io_stream_rdr file_stream = Io_stream_rdr_.New_by_url(Io_url_.new_fil_(String_.new_u8(path))).Open();
client_wtr.Write_stream(file_stream);
file_stream.Rls(); client_rdr.Rls(); socket.Rls();
}
private void Exec_exec(byte[] url, byte[] tkn_bgn) {
byte[] cmd = Bry_.Mid(url, tkn_bgn.length);
app.Http_server().Run_xowa_cmd(app, String_.new_u8(cmd));
}
private void Write_wiki(byte[] req) {
String wiki_domain = ""; String page_name = "";
String[] req_split = String_.Split(String_.new_u8(req), "/");
if(req_split.length >= 1){
wiki_domain = req_split[1];
}
if(req_split.length >= 4){
page_name = req_split[3];
for(int i = 4; i <= req_split.length-1; i++){
page_name += "/" + req_split[i];
}
page_name = url_encoder.Decode_str(page_name);
}
String page_html = app.Http_server().Parse_page_to_html(data__client, Bry_.new_u8(wiki_domain), Bry_.new_u8(page_name));
page_html = Convert_page(page_html, root_dir_http, wiki_domain);
Xosrv_http_wkr_.Write_response_as_html(client_wtr, Bool_.N, page_html);
}
private void Process_post(Http_request_itm request) {
byte[] msg = request.Post_data_hash().Get_by(Key__msg).Val();
byte[] app_mode = request.Post_data_hash().Get_by(Key__app_mode).Val();
Xoa_app_mode app_mode_itm = Xoa_app_mode.parse(String_.new_u8(app_mode));
server_wtr.Write_str_w_nl(String_.new_u8(request.Host()) + "|POST|" + String_.new_u8(msg));
Object url_tid_obj = post_url_hash.Get_by_bry(request.Url()); if (url_tid_obj == null) throw Err_.new_wo_type("unknown url", "url", request.Url(), "request", request.To_str(tmp_bfr, Bool_.N));
String rv = null;
switch (((Int_obj_val)url_tid_obj).Val()) {
case Tid_post_url_json:
rv = app.Html__bridge_mgr().Cmd_mgr().Exec(msg);
break;
case Tid_post_url_gfs:
rv = Object_.Xto_str_strict_or_null_mark(app.Gfs_mgr().Run_str(String_.new_u8(msg)));
break;
}
if (app_mode_itm.Tid_is_http())
rv = Convert_page(rv, root_dir_http , "<<MISSING_WIKI>>");
Xosrv_http_wkr_.Write_response_as_html(client_wtr, app_mode_itm.Tid() == Xoa_app_mode.Itm_file.Tid(), rv);
}
private static final byte[] Key__msg = Bry_.new_a7("msg"), Key__app_mode = Bry_.new_a7("app_mode");
private static final int Tid_post_url_json = 1, Tid_post_url_gfs = 2;
private static final Hash_adp_bry post_url_hash = Hash_adp_bry.ci_a7()
.Add_str_int("/exec/json" , Tid_post_url_json)
.Add_str_int("/exec/gfs" , Tid_post_url_gfs)
;
private static String Convert_page(String page_html, String root_dir_http, String wiki_domain) {
page_html = String_.Replace(page_html, root_dir_http , "/fsys/");
page_html = String_.Replace(page_html, "xowa-cmd:" , "/exec/");
page_html = String_.Replace(page_html, "<a href=\"/wiki/" , "<a href=\"/" + wiki_domain + "/wiki/");
page_html = String_.Replace(page_html, "<a href='/wiki/" , "<a href='/" + wiki_domain + "/wiki/");
page_html = String_.Replace(page_html, "action=\"/wiki/" , "action=\"/" + wiki_domain + "/wiki/");
page_html = String_.Replace(page_html, "/site" , "");
return page_html;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_run)) {this.Run();}
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_run = "run";
private static final byte[]
Url__home = Bry_.new_a7("/"), Url__fsys = Bry_.new_a7("/fsys/")
, Url__exec = Bry_.new_a7("/exec/"), Url__exec_2 = Bry_.new_a7("/xowa-cmd:")
;
private static final int Url__fsys_len = Url__fsys.length;
}
class Xosrv_http_wkr_ {
public static void Write_response_as_html(Http_client_wtr client_wtr, boolean cross_domain, String html) {Write_response_as_html(client_wtr, cross_domain, Bry_.new_u8(html));}
public static void Write_response_as_html(Http_client_wtr client_wtr, boolean cross_domain, byte[] html) {
try{
client_wtr.Write_bry(Rsp__http_ok);
// TODO_OLD: add command-line argument to allow testing from local file
// if (cross_domain)
// client_wtr.Write_str("Access-Control-Allow-Origin: *\n"); // No 'Access-Control-Allow-Origin' header is present on the requested resource.
client_wtr.Write_bry(Rsp__content_type_html);
client_wtr.Write_bry(Byte_ascii.Nl_bry);
client_wtr.Write_bry(html);
} catch (Exception err) {
client_wtr.Write_str("Site not found. Check address please, or see console log.\n" + Err_.Message_lang(err));
client_wtr.Rls();
}
}
public static final byte[]
Rsp__http_ok = Bry_.new_a7("HTTP/1.1 200 OK:\n")
, Rsp__content_type_html = Bry_.new_a7("Content-Type: text/html; charset=utf-8\n")
;
}

View File

@@ -0,0 +1,39 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.langs.*;
class Http_server_wkr_ {
public static String Assert_main_page(Xoae_app app, String req) {
int mode = -1;
String[] req_array = String_.Split(req, "/");
if (String_.Has_at_end(req, "wiki/")) mode = 0;
else if (String_.Has_at_end(req, "wiki")) mode = 1;
else if (req_array.length == 3) mode = 2;
if (mode == -1) return req; // not a link to a Main Page; EX:localhost:8080/en.wikipedia.org/wiki/Earth
if (req_array.length < 3) return req; // shouldn't happen; EX: "localhost:8080wiki"
byte[] wiki_domain = Bry_.new_u8(req_array[1]);
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(wiki_domain);
if (domain_itm.Domain_type_id() == Xow_domain_tid_.Tid__other && domain_itm.Lang_actl_itm().Id() == Xol_lang_stub_.Id__intl) return req;
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(wiki_domain);
wiki.Init_assert();
String main_page = String_.new_u8(wiki.Props().Main_page());
if (mode == 1) main_page = "/" + main_page;
else if (mode == 2) main_page = "wiki/" + main_page;
return req + main_page;
}
}

View File

@@ -0,0 +1,42 @@
/*
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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import org.junit.*;
public class Http_server_wkr__tst {
@Before public void init() {fxt.Clear();} private Http_server_wkr__fxt fxt = new Http_server_wkr__fxt();
@Test public void Assert_main_page() {
fxt.Init_wiki_main_page("fr.wikiversity.org", "Accueil");
fxt.Test_assert_main_page("/fr.wikiversity.org/" , "/fr.wikiversity.org/wiki/Accueil");
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki" , "/fr.wikiversity.org/wiki/Accueil");
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/" , "/fr.wikiversity.org/wiki/Accueil");
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/A" , "/fr.wikiversity.org/wiki/A");
}
}
class Http_server_wkr__fxt {
private Xoae_app app;
public void Clear() {
this.app = Xoa_app_fxt.Make__app__edit();
}
public void Init_wiki_main_page(String domain, String main_page) {
Xowe_wiki wiki = app.Wiki_mgr().Get_by_or_make(Bry_.new_u8(domain));
wiki.Props().Main_page_(Bry_.new_u8(main_page));
}
public void Test_assert_main_page(String url, String expd) {
Tfds.Eq(expd, Http_server_wkr_.Assert_main_page(app, url));
}
}

View File

@@ -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.apps.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.primitives.*;
public class Http_server_wkr_pool {
private final Ordered_hash hash = Ordered_hash_.New(); private final Int_obj_ref hash_key = Int_obj_ref.New_neg1();
public boolean Enabled() {return max != 0;}
public int Max() {return max;} private int max;
public int Timeout() {return timeout;} private int timeout;
public int Len() {return len;} private int len;
public boolean Full() {return len >= max;}
public void Init(int max, int timeout) {this.max = max; this.timeout = timeout;}
public void Add(int uid) {
if (max == 0) return; // disabled
synchronized (hash) {
Int_obj_ref wkr_key = Int_obj_ref.New(uid);
hash.Add(wkr_key, wkr_key);
++len;
}
}
public void Del(int uid) {
if (max == 0) return; // disabled
synchronized (hash) {
hash.Del(hash_key.Val_(uid));
--len;
}
}
}

View File

@@ -0,0 +1,55 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
public class Socket_rdr {
private java.net.ServerSocket server;
private java.net.Socket client;
private java.io.InputStream stream;
public IoStream Rdr_stream() {return rdr_stream;} private IoStream rdr_stream = null;
public int Port() {return port;} private int port;
public Socket_rdr Ctor(int port) {this.port = port; return this;}
public Socket_rdr Open() {
try {
// this.Rls();
if (server == null) {
server = new java.net.ServerSocket(port);
server.setReuseAddress(true);
}
client = server.accept();
client.setSoTimeout(10000);
stream = client.getInputStream();
rdr_stream = new IoStream_stream_rdr().UnderRdr_(stream);
return this;
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to open socket", "port", port);}
}
public void Close() {
try {
// if (server != null) server.close();
if (client != null) client.close();
if (stream != null) stream.close();
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to close socket", "port", port);}
}
public void Rls() {
try {
if (server != null) server.close();
if (client != null) client.close();
if (stream != null) stream.close();
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to rls socket", "port", port);}
}
}

View File

@@ -0,0 +1,51 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
public class Socket_wtr {
private String host;
private int port;
private java.net.Socket socket;
private java.io.OutputStream stream;
public Socket_wtr Ctor(String host, int port) {this.host = host; this.port = port; return this;}
public Socket_wtr Open() {
try {
this.Rls();
socket = new java.net.Socket(host, port);
socket.setSoTimeout(10000);
stream = socket.getOutputStream();
return this;
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to open socket", "host", host, "port", port);}
}
public void Write(byte[] bry) {
try {
stream.write(bry, 0, bry.length);
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to write stream", "host", host, "port", port);}
}
public void Close() {
try {
if (stream != null) stream.close();
if (socket != null) socket.close();
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to close socket", "host", host, "port", port);}
}
public void Rls() {
try {
if (stream != null) stream.close();
if (socket != null) socket.close();
} catch (Exception e) {throw Err_.new_exc(e, "net", "failed to release socket", "host", host, "port", port);}
}
}

View File

@@ -0,0 +1,25 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
public class Xosrv_cmd_types {
public static final byte[]
Cmd_exec = Bry_.new_a7("xowa.cmd.exec") , Cmd_pass = Bry_.new_a7("xowa.cmd.result") , Cmd_fail = Bry_.new_a7("xowa.cmd.error")
, Js_exec = Bry_.new_a7("xowa.js.exec") , Js_pass = Bry_.new_a7("xowa.js.result") , Js_fail = Bry_.new_a7("xowa.js.error")
, Browser_exec = Bry_.new_a7("browser.js.exec"), Browser_pass = Bry_.new_a7("browser.js.result") , Browser_fail = Bry_.new_a7("browser.js.error")
;
}

View File

@@ -0,0 +1,121 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
public class Xosrv_msg {
public byte Version_tid() {return Version_tid_0;} static final byte Version_tid_0 = 0;
public byte[] Cmd_name() {return cmd_name;} private byte[] cmd_name;
public byte[] Msg_id() {return msg_id;} private byte[] msg_id;
public byte[] Sender() {return sender;} private byte[] sender;
public byte[] Recipient() {return recipient;} private byte[] recipient;
public byte[] Msg_date() {return msg_date;} private byte[] msg_date;
public byte[] Msg_text() {return msg_text;} private byte[] msg_text;
public void Print(Bry_bfr bfr) {
int body_len = cmd_name.length + msg_id.length + sender.length + recipient.length + msg_date.length + msg_text.length + 5; // 5=5 pipes for 6 fields
int cksum = (body_len * 2) + 1;
bfr.Add_int_fixed(this.Version_tid() , 1).Add_byte_pipe(); // 0|
bfr.Add_int_fixed(body_len , 10).Add_byte_pipe(); // 0123456789|
bfr.Add_int_fixed(cksum , 10).Add_byte_pipe(); // 0123456789|
bfr.Add(cmd_name ).Add_byte_pipe(); // cmd|
bfr.Add(msg_id ).Add_byte_pipe(); // id|
bfr.Add(sender ).Add_byte_pipe(); // sender|
bfr.Add(recipient ).Add_byte_pipe(); // recipient|
bfr.Add(msg_date ).Add_byte_pipe(); // msg_date|
bfr.Add(msg_text ); // msg_text
}
public static final Xosrv_msg Exit = new Xosrv_msg();
public static Xosrv_msg fail_(String fmt, Object... ary) {
Xosrv_msg rv = new Xosrv_msg();
rv.msg_text = Bry_.new_u8(String_.Format(fmt, ary));
return rv;
}
public static Xosrv_msg new_(byte[] cmd_name, byte[] msg_id, byte[] sender, byte[] recipient, byte[] msg_date, byte[] msg_text) {
Xosrv_msg rv = new Xosrv_msg();
rv.cmd_name = cmd_name;
rv.msg_id = msg_id;
rv.sender = sender;
rv.recipient = recipient;
rv.msg_date = msg_date;
rv.msg_text = msg_text;
return rv;
}
}
/*
Message definition
Id : 0
Purpose : Version number for message format
Data type : int
Notes : Always 0; will change to 1 if message format ever changes
Example : "0"
Id : 1
Description : Body length; specified total length of message field 3 (body)
Data type : int
Notes : always zero-padded to 10 bytes (not hexadecimal)
Example : "0000000123"
Id : 2
Description : Checksum; should equal (2 * body length) + 1
Data type : int
Notes : always zero-padded to 10 bytes (not hexadecimal)
Example : "0000000247"
Id : 3
Description : Body
Data type : String
Notes : length specified by field 1 (body length)
Example : see below
Body definition
* Pipes are not allowed in any field except for the last
* Only the first field is required
Id : 0
Purpose : Command name
Data type : String
Notes : unique name identifying the command
Example : "xowa.cmd.exec", "xowa.cmd.result", "xowa.cmd.error", "xowa.js.exec", "xowa.js.result", "xowa.js.error"
Id : 1
Purpose : Message id
Data type : String
Notes : Usage is defined by callers; can be empty
Example : "1", ""
Id : 2
Purpose : Sender id
Data type : String
Notes : Usage is defined by callers; can be empty
Example : "tab1", "xowa", ""
Id : 3
Purpose : Recipient id
Data type : String
Notes : Usage is defined by callers; can be empty
Example : "xowa", "tab1", ""
Id : 4
Purpose : Message date
Data type : String
Notes : ISO 8601 format; see http://www.w3.org/TR/NOTE-datetime; Usage is defined by callers; can be empty
Example : "1997-07-16T19:20:30.45+01:00", ""
Id : 5
Purpose : Message text
Data type : String
Notes : freeform; can contain any character
Example : "app.shell.fetch_page('simple.wikipedia.org/wiki/Earth', 'html');"*/

View File

@@ -0,0 +1,64 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.primitives.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.core.texts.*;
public class Xosrv_msg_rdr {
public Xosrv_msg_rdr(byte[] default_body_bry, IoStream rdr) {this.default_body_bry = default_body_bry; default_body_bry_len = default_body_bry.length; this.rdr = rdr;} private byte[] header_bry = new byte[24], default_body_bry; int default_body_bry_len;
public IoStream Rdr() {return rdr;} private IoStream rdr;
public Xosrv_msg Read() {
int bytes_read = rdr.Read(header_bry, 0, 24); // 24 = version(1) + pipe + msg_len (10) + pipe + cksum (10) + pipe
if (bytes_read < 24) {
if (bytes_read == -1) return Xosrv_msg.Exit; // stream closed; should only occur when shutting down
else return Xosrv_msg.fail_("header is invalid; hdr:{0}", String_.new_u8(header_bry, 0, bytes_read));
}
byte version = header_bry[0]; if (version != Byte_ascii.Num_0) return Xosrv_msg.fail_("version must be 0; version:{0}", Byte_.To_str(version));
int body_len = Bry_.To_int_or(header_bry, 2, 12, -1); if (body_len == -1) return Xosrv_msg.fail_("body_len is not number; body_len:{0}", String_.new_u8(header_bry, 2, 23));
int cksum = Bry_.To_int_or(header_bry, 13, 23, -1); if (cksum == -1) return Xosrv_msg.fail_("checksum is not number; cksum:{0}", String_.new_u8(header_bry, 13, 23));
if (!Chk_bytes(header_bry, Byte_ascii.Pipe, 1, 12, 23)) return Xosrv_msg.fail_("message should be delimited by pipes at 1, 12 and 23; message:{0}", String_.new_u8(header_bry, 0, 24));
if (cksum != (body_len * 2) + 1) return Xosrv_msg.fail_("checksum failed; body_len:{0} chksum:{1}", body_len, cksum);
byte[] body_bry = body_len > default_body_bry_len ? new byte[body_len] : default_body_bry;
rdr.Read(body_bry, 0, body_len);
Int_obj_ref fld_bgn = Int_obj_ref.New_zero(); Bool_obj_ref fail_ref = Bool_obj_ref.n_(); String_obj_ref fld_ref = String_obj_ref.null_();
byte[] cmd_name = Read_fld(body_bry, body_len, fld_bgn, fail_ref, fld_ref.Val_("cmd_name")); if (fail_ref.Val()) return Read_fld_fail(fld_ref, body_bry);
byte[] msg_id = Read_fld(body_bry, body_len, fld_bgn, fail_ref, fld_ref.Val_("msg_id")); if (fail_ref.Val()) return Read_fld_fail(fld_ref, body_bry);
byte[] sender = Read_fld(body_bry, body_len, fld_bgn, fail_ref, fld_ref.Val_("sender")); if (fail_ref.Val()) return Read_fld_fail(fld_ref, body_bry);
byte[] recipient = Read_fld(body_bry, body_len, fld_bgn, fail_ref, fld_ref.Val_("recipient")); if (fail_ref.Val()) return Read_fld_fail(fld_ref, body_bry);
byte[] msg_date = Read_fld(body_bry, body_len, fld_bgn, fail_ref, fld_ref.Val_("msg_date")); if (fail_ref.Val()) return Read_fld_fail(fld_ref, body_bry);
byte[] msg_text = Bry_.Mid(body_bry, fld_bgn.Val(), body_len);
return Xosrv_msg.new_(cmd_name, msg_id, sender, recipient, msg_date, msg_text);
}
private static byte[] Read_fld(byte[] bry, int bry_len, Int_obj_ref fld_bgn, Bool_obj_ref fail_ref, String_obj_ref fld_ref) {
int fld_end = Bry_find_.Find_fwd(bry, Byte_ascii.Pipe, fld_bgn.Val(), bry_len);
if (fld_end == Bry_find_.Not_found) {fail_ref.Val_y_(); return null;}
byte[] rv = Bry_.Mid(bry, fld_bgn.Val(), fld_end);
fld_bgn.Val_(fld_end + 1); // +1 to place after pipe
return rv;
}
private static Xosrv_msg Read_fld_fail(String_obj_ref fld_name, byte[] body_bry) {return Xosrv_msg.fail_("pipe not found for " + fld_name.Val() + "; body:{0}", String_.new_u8(body_bry));}
private static boolean Chk_bytes(byte[] bry, byte expd, int... pos_ary) {
int len = pos_ary.length;
int bry_len = bry.length;
for (int i = 0; i < len; i++) {
int pos = pos_ary[i];
if (pos >= bry_len) return false; // out of bounds; return false (don't fail)
if (bry[pos] != expd) return false;
}
return true;
}
}

View File

@@ -0,0 +1,65 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import org.junit.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
public class Xosrv_msg_rdr_tst {
@Before public void init() {fxt.Clear();} private Xosrv_msg_rdr_fxt fxt = new Xosrv_msg_rdr_fxt();
@Test public void Parse() {
String raw = "0|0000000045|0000000091|cmd_0|id_0|sender_0|recipient_0|date_0|text_0";
Xosrv_msg msg = fxt.Test_parse_msg(raw, "cmd_0", "id_0", "sender_0", "recipient_0", "date_0", "text_0");
fxt.Test_print(msg, raw);
}
@Test public void Err_header_is_invalid() {fxt.Test_parse_err("abcde", "header is invalid");}
@Test public void Err_checksum_failed() {fxt.Test_parse_err("0|0000000000|0000000000|", "checksum failed");}
@Test public void Err_cmd_missing() {fxt.Test_parse_err("0|0000000001|0000000003|a", "pipe not found for cmd_name");}
}
class Xosrv_msg_rdr_fxt {
public Xosrv_msg_rdr_fxt Clear() {
if (msg_rdr == null) {
msg_rdr_stream = new IoStream_mock();
msg_rdr = new Xosrv_msg_rdr(Bry_.Empty, msg_rdr_stream);
}
msg_rdr_stream.Reset();
return this;
} private Xosrv_msg_rdr msg_rdr; private IoStream_mock msg_rdr_stream;
public Xosrv_msg Test_parse_msg(String raw, String expd_cmd, String expd_id, String expd_sender, String expd_recipient, String expd_date, String expd_text) {
byte[] raw_bry = Bry_.new_a7(raw);
msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length);
Xosrv_msg msg = msg_rdr.Read();
Tfds.Eq(String_.new_a7(msg.Cmd_name()) , expd_cmd);
Tfds.Eq(String_.new_a7(msg.Msg_id()) , expd_id);
Tfds.Eq(String_.new_a7(msg.Sender()) , expd_sender);
Tfds.Eq(String_.new_a7(msg.Recipient()) , expd_recipient);
Tfds.Eq(String_.new_a7(msg.Msg_date()) , expd_date);
Tfds.Eq(String_.new_a7(msg.Msg_text()) , expd_text);
return msg;
}
public void Test_parse_err(String raw, String expd_err) {
byte[] raw_bry = Bry_.new_a7(raw);
msg_rdr_stream.Data_bry_(raw_bry).Read_limit_(raw_bry.length);
Xosrv_msg msg = msg_rdr.Read();
String msg_text = String_.new_a7(msg.Msg_text());
Tfds.Eq_true(String_.Has_at_bgn(msg_text, expd_err), msg_text);
}
public void Test_print(Xosrv_msg msg, String expd) {
Bry_bfr bfr = Bry_bfr_.New();
msg.Print(bfr);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,130 @@
/*
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.apps.servers.tcp; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.servers.*;
import gplx.core.primitives.*; import gplx.core.ios.*; import gplx.core.envs.*; import gplx.core.threads.*;
import gplx.gfui.controls.standards.*;
import gplx.langs.jsons.*;
public class Xosrv_server implements Gfo_invk {
private long last_cmd;
public Xosrv_socket_rdr Rdr() {return rdr;} private Xosrv_socket_rdr rdr = new Xosrv_socket_rdr();
public Xosrv_socket_wtr Wtr() {return wtr;} private Xosrv_socket_wtr wtr = new Xosrv_socket_wtr();
public int Rdr_port() {return rdr_port;} public Xosrv_server Rdr_port_(int v) {rdr_port = v; return this;} private int rdr_port = 55000;
public int Wtr_port() {return wtr_port;} public Xosrv_server Wtr_port_(int v) {wtr_port = v; return this;} private int wtr_port = 55001;
public int Shutdown_interval() {return shutdown_interval;} public Xosrv_server Shutdown_interval_(int v) {shutdown_interval = v; return this;} private int shutdown_interval = -1;
public String Wtr_host() {return wtr_host;} private String wtr_host = "localhost";
public boolean Running() {return running;} public Xosrv_server Running_(boolean v) {running = v; running_str = Bool_.To_str_lower(running); return this;} private boolean running = false;
public String Running_str() {return running_str;} String running_str = "false";
public void App_ctor(Xoae_app app) {this.app = app;}
public Xoae_app App() {return app;} private Xoae_app app;
public void Run() {
rdr.Init(this, rdr_port);
wtr.Init(wtr_host, wtr_port);
Gxw_html_server.Init_gui_for_server(app, wtr);
Thread_adp_.Start_by_key(gplx.xowa.apps.Xoa_thread_.Key_http_server_main, rdr, Xosrv_socket_rdr.Invk_start);
app.Usr_dlg().Note_many("", "", "server started: listening on ~{0}. Press Ctrl+C to exit", rdr_port);
last_cmd = System_.Ticks();
Running_(true);
while (running) {
if (shutdown_interval != -1 && System_.Ticks() - last_cmd > shutdown_interval) break;
Thread_adp_.Sleep(1000);
}
rdr.Rls();
wtr.Rls();
app.Usr_dlg().Note_many("", "", "server stopped", rdr_port);
}
public void Msg_rcvd(Xosrv_msg msg) {
try {
byte[] cmd_name = msg.Cmd_name();
byte[] rsp_name = Bry_.Empty;
long time_bgn = System_.Ticks();
last_cmd = time_bgn;
byte[] msg_bry = msg.Msg_text();
String msg_str = String_.new_u8(msg_bry);
app.Usr_dlg().Note_many("", "", "processing cmd: ~{0}", msg_str);
String rsp_str = null;
if (Bry_.Eq(cmd_name, Xosrv_cmd_types.Cmd_exec)) {rsp_name = Xosrv_cmd_types.Cmd_pass; rsp_str = Exec_cmd(msg_str);}
else if (Bry_.Eq(cmd_name, Xosrv_cmd_types.Js_exec)) {rsp_name = Xosrv_cmd_types.Js_pass; rsp_str = Exec_js(msg.Sender(), msg_bry);}
Xosrv_msg rsp_msg = Xosrv_msg.new_(rsp_name, msg.Msg_id(), msg.Recipient(), msg.Sender(), msg.Msg_date(), Bry_.new_u8(rsp_str));
app.Usr_dlg().Note_many("", "", "sending rsp: bytes=~{0}", String_.Len(rsp_str));
wtr.Write(rsp_msg);
app.Usr_dlg().Note_many("", "", "rsp sent: elapsed=~{0}", Time_span_.fracs_(System_.Ticks() - time_bgn).XtoStrUiAbbrv());
} catch (Exception e) {app.Usr_dlg().Warn_many("", "", "server error: ~{0}", Err_.Message_gplx_full(e));}
}
private String Exec_cmd(String msg_text) {
Object rv_obj = app.Gfs_mgr().Run_str(msg_text);
String rv = Type_adp_.Eq_typeSafe(rv_obj, String_.Cls_ref_type) ? (String)rv_obj : Object_.Xto_str_strict_or_null(rv_obj);
return rv;
}
public String Exec_js(byte[] sender, byte[] msg_text) {
String_obj_ref trace = String_obj_ref.new_("exec_js");
try {
Object[] xowa_exec_args = xowa_exec_parser.Parse_xowa_exec(msg_text);
trace.Val_("js_args");
// xowa_exec_args = (Object[])Array_.Resize(xowa_exec_args, xowa_exec_args.length + 1);
// xowa_exec_args[xowa_exec_args.length - 1] = sender;
Object rv_obj = Gfui_html.Js_args_exec(app.Gui_mgr().Browser_win().Active_html_itm().Js_cbk(), xowa_exec_args);
trace.Val_("json_write: " + Object_.Xto_str_strict_or_null_mark(rv_obj));
return json_wtr.Write_root(Bry_xowa_js_result, rv_obj).Bld_as_str();
} catch (Exception e) {throw Err_.new_exc(e, "http", "exec_js error", "trace", trace, "msg", msg_text);}
} private Xosrv_xowa_exec_parser xowa_exec_parser = new Xosrv_xowa_exec_parser(); private Json_doc_srl json_wtr = new Json_doc_srl(); private static final byte[] Bry_xowa_js_result = Bry_.new_a7("xowa_js_result");
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_rdr_port)) return rdr_port;
else if (ctx.Match(k, Invk_rdr_port_)) rdr_port = m.ReadInt("v");
else if (ctx.Match(k, Invk_wtr_port)) return wtr_port;
else if (ctx.Match(k, Invk_wtr_port_)) wtr_port = m.ReadInt("v");
else if (ctx.Match(k, Invk_wtr_host)) return wtr_host;
else if (ctx.Match(k, Invk_wtr_host_)) wtr_host = m.ReadStr("v");
else if (ctx.Match(k, Invk_shutdown_interval)) return shutdown_interval;
else if (ctx.Match(k, Invk_shutdown_interval_)) shutdown_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_stop)) running = false;
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Invk_stop = "stop", Invk_rdr_port = "rdr_port", Invk_rdr_port_ = "rdr_port_", Invk_wtr_port = "wtr_port", Invk_wtr_port_ = "wtr_port_", Invk_wtr_host = "wtr_host", Invk_wtr_host_ = "wtr_host_"
, Invk_shutdown_interval = "shutdown_interval", Invk_shutdown_interval_ = "shutdown_interval_";
}
class Xosrv_xowa_exec_parser {
private Json_parser json_parser = new Json_parser();
public Object[] Parse_xowa_exec(byte[] msg_text) { // parses JSON with format '{"args":["arg0","arg1","arg2"]}'
Json_doc doc = json_parser.Parse(msg_text);
Json_kv args_kv = (Json_kv)doc.Root_nde().Get_at(0); // get "args" kv
Json_ary args_ary = (Json_ary)args_kv.Val(); // get []
int len = args_ary.Len();
Object[] rv = new Object[len];
for (int i = 0; i < len; i++) { // extract args
Json_itm itm = args_ary.Get_at(i);
rv[i] = Parse_ary_itm(itm);
}
return rv;
}
private Object Parse_ary_itm(Json_itm itm) {
switch (itm.Tid()) {
case Json_itm_.Tid__str:
return String_.new_u8(itm.Data_bry());
case Json_itm_.Tid__ary:
Json_ary ary = (Json_ary)itm;
int len = ary.Len();
String[] rv = new String[len];
for (int i = 0; i < len; i++)
rv[i] = String_.new_u8(ary.Get_at(i).Data_bry());
return rv;
default:
throw Err_.new_unhandled(itm.Tid());
}
}
}

Some files were not shown because too many files have changed in this diff Show More