1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
/*
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; import gplx.*;
import gplx.ios.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*;
import gplx.xowa.bldrs.css.*;
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.urls.encoders.*;
import gplx.xowa.wikis.*;
import gplx.xowa.wmfs.*;
import gplx.xowa.html.hrefs.*; import gplx.xowa.html.wtrs.*; import gplx.xowa.html.js.*;
import gplx.xowa.users.*;
public interface Xoa_app {
Xoa_app_type App_type();
Xoa_fsys_mgr Fsys_mgr();
Xoa_wiki_mgr Wiki_mgri();
Xof_cache_mgr File__cache_mgr();
Xof_img_mgr File__img_mgr();
Io_download_fmt File__download_fmt();
Xoh_href_parser Html__href_parser();
Xoh_lnki_bldr Html__lnki_bldr();
Xoa_css_extractor Html__css_installer();
Xoh_json_exec Html__json_exec();
Xou_user User();
Xowmf_mgr Wmf_mgr();
boolean Xwiki_mgr__missing(byte[] domain);
Gfo_usr_dlg Usr_dlg();
Bry_bfr_mkr Utl__bfr_mkr();
Url_encoder_mgr Utl__encoder_mgr();
Xoa_url_parser Utl__url_parser();
}

View File

@@ -0,0 +1,208 @@
/*
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; import gplx.*;
import gplx.dbs.*; import gplx.ios.*; import gplx.gfui.*;
import gplx.xowa.apps.*; import gplx.xowa.langs.*; import gplx.xowa.users.*;
import gplx.xowa.files.*; import gplx.xowa.html.hdumps.*; import gplx.xowa.html.hdumps.core.*;
import gplx.xowa.urls.encoders.*;
public class Xoa_app_ {
public static void Run(String... args) {
Xoa_app_boot_mgr boot_mgr = new Xoa_app_boot_mgr();
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "2.7.1.2";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";
public static final Gfo_msg_grp Nde = Gfo_msg_grp_.prj_(Name);
public static Gfo_usr_dlg usr_dlg_console_() {
Gfo_usr_dlg rv = new Gfo_usr_dlg_base(new Gfo_usr_dlg__log_base(), Gfo_usr_dlg__gui_.Console);
rv.Log_wkr().Queue_enabled_(true);
return rv;
}
public static Gfo_usr_dlg Usr_dlg() {return usr_dlg;} public static void Usr_dlg_(Gfo_usr_dlg v) {usr_dlg = v;} private static Gfo_usr_dlg usr_dlg;
public static Bry_bfr_mkr Utl__bfr_mkr() {return utl__bry_bfr_mkr;} private static final Bry_bfr_mkr utl__bry_bfr_mkr = new Bry_bfr_mkr();
public static Url_encoder_mgr Utl__encoder_mgr() {return utl__encoder_mgr;} private static final Url_encoder_mgr utl__encoder_mgr = new Url_encoder_mgr();
public static Io_stream_zip_mgr Utl__zip_mgr() {return utl__zip_mgr;} private static final Io_stream_zip_mgr utl__zip_mgr = new Io_stream_zip_mgr();
public static Xoa_gfs_mgr Gfs_mgr() {return gfs_mgr;} public static void Gfs_mgr_(Xoa_gfs_mgr v) {gfs_mgr = v;} private static Xoa_gfs_mgr gfs_mgr;
}
class Xoa_app_boot_mgr {
private Gfo_usr_dlg usr_dlg; private Gfo_usr_dlg__log log_wtr; private String chkpoint = "null";
public void Run(String[] args) {
try {
if (!Init_env(args)) return;
App_cmd_mgr args_mgr = Init_args_mgr(args); if (args_mgr == null) return;
Run_app(args_mgr);
}
catch (Exception e) {
String err_str = Err_.Message_gplx(e);
log_wtr.Log_to_err(err_str);
ConsoleAdp._.WriteLine(err_str);
if (log_wtr.Log_dir() == null) log_wtr.Log_dir_(Env_.AppUrl().OwnerDir().GenSubFil("xowa.log"));
log_wtr.Queue_enabled_(false);
}
}
private boolean Init_env(String[] args) {
Gfo_usr_dlg_.I = usr_dlg = Xoa_app_.usr_dlg_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.I.QueryFil(jar_url).ModifiedTime().XtoUtc().XtoStr_fmt("yyyy-MM-dd HH:mm");
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().Xto_str());
chkpoint = "init_env";
return true;
}
private App_cmd_mgr Init_args_mgr(String[] args) {
App_cmd_mgr rv = new App_cmd_mgr();
try {
String hdr = String_.Concat_lines_nl_skip_last
( Env_.GenHdr(false, "XOWA", "XOWA: the XOWA Offline Wiki Application\n", "")
, String_.Repeat("-", 80)
, ""
, "version: " + Xoa_app_.Version + "; build date: " + Xoa_app_.Build_date
);
rv
.Fmt_hdr_(hdr)
.Expd_add_many
( App_cmd_arg.opt_("root_dir").Example_url_("C:\\xowa").Note_("root directory for xowa; defaults to current directory of xowa.jar")
, App_cmd_arg.opt_("user_dir").Example_url_("C:\\xowa\\user\\" + Xoue_user.Key_xowa_user).Note_("directory for user_data; defaults to '/xowa/user/" + Xoue_user.Key_xowa_user + "'")
, App_cmd_arg.opt_("wiki_dir").Example_url_("C:\\xowa\\wiki\\").Note_("directory for wikis; defaults to '/xowa/wiki/'")
, App_cmd_arg.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")
, App_cmd_arg.opt_("app_mode").Example_("gui").Note_("type of app to run; valid values are 'gui', 'cmd', 'server', 'http_server'; defaults to 'gui'")
, App_cmd_arg.opt_("cmd_file").Example_url_("C:\\xowa\\xowa.gfs").Note_("file_path of script to execute; defaults to 'xowa.gfs'")
, App_cmd_arg.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.")
, App_cmd_arg.opt_("url").Example_("en.wikipedia.org/wiki/Earth").Note_("url to be shown when xowa first launches; default is home/wiki/Main_Page")
, App_cmd_arg.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")
, App_cmd_arg.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")
, App_cmd_arg.opt_("http_server_port").Example_("8080").Note_("applies to --app_mode http_server; port used by http_server; default is 8080")
, App_cmd_arg.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")
, App_cmd_arg.sys_header_("show_license").Dflt_(true)
, App_cmd_arg.sys_args_("show_args").Dflt_(true)
, App_cmd_arg.sys_help_()
)
; chkpoint = "fmt_hdr";
boolean pass = rv.Args_process(args); chkpoint = "args_process";
rv.Print_header(usr_dlg); // always call print_header
if (!pass) {
rv.Print_args(usr_dlg);
rv.Print_fail(usr_dlg);
rv.Print_help(usr_dlg, Xoa_app_.Name);
return null;
}
if (rv.Args_has_help()) {
rv.Print_help(usr_dlg, Xoa_app_.Name);
return null;
}
if (rv.Args_get("show_args").Val_as_bool())
rv.Print_args(usr_dlg);
} catch (Exception e) {usr_dlg.Warn_many("", "", "args failed: ~{0} ~{1}", chkpoint, Err_.Message_gplx(e)); return null;}
return rv;
}
private void Run_app(App_cmd_mgr args_mgr) {
boolean app_type_is_gui = false;
Xoae_app app = null;
try {
// init vars
Io_url jar_dir = Env_.AppUrl().OwnerDir();
Io_url root_dir = args_mgr.Args_get("root_dir").Val_as_url_rel_dir_or(jar_dir, jar_dir);
Io_url user_dir = args_mgr.Args_get("user_dir").Val_as_url_rel_dir_or(root_dir.GenSubDir("user"), root_dir.GenSubDir_nest("user", Xoue_user.Key_xowa_user));
Io_url wiki_dir = args_mgr.Args_get("wiki_dir").Val_as_url_rel_dir_or(root_dir.GenSubDir("wiki"), root_dir.GenSubDir("wiki"));
Io_url cmd_file = args_mgr.Args_get("cmd_file").Val_as_url_rel_fil_or(jar_dir, root_dir.GenSubFil("xowa.gfs"));
String app_mode = args_mgr.Args_get("app_mode").Val_as_str_or("gui");
String launch_url = args_mgr.Args_get("url").Val_as_str_or(null);
int server_port_recv = args_mgr.Args_get("server_port_recv").Val_as_int_or(55000);
int server_port_send = args_mgr.Args_get("server_port_send").Val_as_int_or(55001);
int http_server_port = args_mgr.Args_get("http_server_port").Val_as_int_or(8080);
String http_server_home = args_mgr.Args_get("http_server_home").Val_as_str_or("home/wiki/Main_Page");
Xoa_app_.Op_sys = args_mgr.Args_get("bin_dir_name").Val_as_str_or(Bin_dir_name());
Xoa_app_.User_agent = String_.Format("XOWA/{0} ({1}) [gnosygnu@gmail.com]", Xoa_app_.Version, Xoa_app_.Op_sys);
String cmd_text = args_mgr.Args_get("cmd_text").Val_as_str_or(null);
Xoa_app_type app_type = Xoa_app_type.parse(app_mode);
app_type_is_gui = app_type.Uid_is_gui();
// init app
Db_conn_bldr.I.Reg_default_sqlite();
app = new Xoae_app(usr_dlg, app_type, root_dir, wiki_dir, root_dir.GenSubDir("file"), user_dir, root_dir.GenSubDir_nest("user", "anonymous", "wiki"), Xoa_app_.Op_sys);
usr_dlg.Log_wkr().Queue_enabled_(false); log_wtr.Log_to_session_fmt("app.init");
try {
app.Sys_cfg().Lang_(System_lang());
if (launch_url != null)
app.Api_root().App().Startup().Tabs().Manual_(launch_url);
app.Tcp_server().Rdr_port_(server_port_recv).Wtr_port_(server_port_send);
app.Http_server().Port_(http_server_port);
app.Http_server().Home_(http_server_home);
app.Init_by_app(); chkpoint = "init_gfs";
}
catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0} ~{1}", chkpoint, Err_.Message_gplx(e));}
app.Usr_dlg().Log_wkr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
// run gfs
gplx.xowa.users.prefs.Prefs_rename_mgr._.Check(app.Usere().Fsys_mgr().App_data_cfg_user_fil());
try {app.Gfs_mgr().Run_url(cmd_file); chkpoint = "run_url";}
catch (Exception e) {
usr_dlg.Warn_many("", "", "script file failed: ~{0} ~{1} ~{2}", chkpoint, cmd_file.Raw(), Err_.Message_gplx(e));
if (app_type_is_gui)
GfuiEnv_.ShowMsg(Err_.Message_gplx(e));
}
gplx.xowa.apps.setups.Xoa_setup_mgr.Delete_old_files(app);
// launch
app.Launch(); chkpoint = "launch";
if (app_type.Uid_is_tcp())
app.Tcp_server().Run();
else if (app_type.Uid_is_http())
app.Http_server().Run();
else {
if (cmd_text != null) {
gplx.xowa.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
ConsoleAdp._.WriteLine_utf8(Object_.Xto_str_strict_or_empty(app.Gfs_mgr().Run_str(cmd_text)));
}
if (app_type_is_gui) {
app.Gui_mgr().Run(); chkpoint = "run";
}
else // teardown app, else lua will keep process running
if (gplx.xowa.xtns.scribunto.Scrib_core.Core() != null) gplx.xowa.xtns.scribunto.Scrib_core.Core().Term();
}
}
catch (Exception e) {usr_dlg.Warn_many("", "", "app launch failed: ~{0} ~{1}", chkpoint, Err_.Message_gplx(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 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;
default: throw Exc_.new_unhandled("unknown platform " + Op_sys.Cur());
}
if (op_sys.Bitness() == Op_sys.Bitness_64) rv += "_64";
return rv;
}
private static byte[] System_lang() {
String lang_code = Env_.Env_prop__user_language();
byte[] lang_code_bry = Bry_.new_a7(lang_code);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(lang_code_bry);
return lang_itm == null ? Xol_lang_.Key_en : lang_itm.Key();
}
}

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; import gplx.*;
import gplx.dbs.*;
import gplx.xowa.apps.*; import gplx.xowa.files.exts.*;
import gplx.xowa.wikis.*;
public class Xoa_app_fxt {
public static Xoae_app app_() {
Io_mgr.I.InitEngine_mem();
Db_conn_bldr.I.Reg_default_mem();
return app_("linux", Io_url_.mem_dir_("mem/xowa/"));
}
public static Xoae_app app_(String op_sys, Io_url root_dir) {
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
Gfo_usr_dlg__log_base._.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
Xoae_app app = new Xoae_app(Gfo_usr_dlg_.Test(), Xoa_app_type.Itm_cmd, root_dir, root_dir.GenSubDir("wiki"), root_dir.GenSubDir("file"), user_dir, root_dir.GenSubDir_nest("user", "anonymous", "wiki"), op_sys);
app.Setup_mgr().Dump_mgr().Data_storage_format_(gplx.ios.Io_stream_.Tid_raw); // TEST: set data_storage_format to file, else bldr tests will fails (expects plain text)
GfsCore._.Clear(); // NOTE: must clear
GfsCore._.AddCmd(app, Xoae_app.Invk_app); // NOTE: must add app to GfsCore; app.Gfs_mgr() always adds current app to GfsCore; note this causes old test to leave behind GfsCore for new test
GfsCore._.AddCmd(app, Xoae_app.Invk_xowa); // add alias for app; DATE:2014-06-09
return app;
}
public static Xowe_wiki wiki_nonwmf(Xoae_app app, String key) {
Xol_lang lang = new Xol_lang(app.Lang_mgr(), Xol_lang_.Key_en).Kwd_mgr__strx_(true);
Xol_lang_.Lang_init(lang);
return wiki_(app, key, lang);
}
public static Xowe_wiki wiki_tst_(Xoae_app app) {return wiki_(app, "en.wikipedia.org");}
public static Xowe_wiki wiki_(Xoae_app app, String key) {return wiki_(app, key, app.Lang_mgr().Lang_en());}
public static Xowe_wiki wiki_(Xoae_app app, String key, Xol_lang lang) {
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(key);
Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_.parse(Bry_.new_u8(key)), wiki_dir);
rv.File_mgr().Meta_mgr().Depth_(2); // TEST: written for 2 depth
rv.Props().Main_page_(Xoa_page_.Main_page_bry); // TEST: default to Main Page (nothing tests loading Main Page from wiki.gfs)
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(true);
app.Wiki_mgr().Add(rv);
return rv;
}
public static void repo_(Xoae_app app, Xowe_wiki wiki) {
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_u8("src:wiki"), Bry_.new_u8("trg:wiki"));
app.File_mgr().Repo_mgr().Set("src:c", "mem/wiki/repo/src/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
app.File_mgr().Repo_mgr().Set("trg:c", "mem/wiki/repo/trg/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_u8("src:c"), Bry_.new_u8("trg:c"));
}
public static void Init_gui(Xoae_app app, Xowe_wiki wiki) {
app.Gui_mgr().Browser_win().Init_by_kit(gplx.gfui.Mem_kit._);
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(wiki, Xoae_page.Empty);
}
public static Xob_bldr bldr_(Xoae_app app) {
Xob_bldr rv = new Xob_bldr(app);
rv.Sort_mem_len_(Io_mgr.Len_kb).Dump_fil_len_(Io_mgr.Len_kb).Make_fil_len_(Io_mgr.Len_kb);
return rv;
}
public static final Io_url Root_dir = Op_sys.Cur().Tid_is_lnx() ? Io_url_.new_dir_("/xowa/") : Io_url_.new_dir_("C:\\xowa\\");
}

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; import gplx.*;
public class Xoa_consts {
public static final byte[]
Nl_bry = new byte[] {Byte_ascii.Nl}
, Slash_bry = new byte[] {Byte_ascii.Slash}
, Pipe_bry = new byte[] {Byte_ascii.Pipe}
, Invk_bgn = new byte[] {Byte_ascii.Curly_bgn, Byte_ascii.Curly_bgn} // "{{"
, Invk_end = new byte[] {Byte_ascii.Curly_end, Byte_ascii.Curly_end} // "}}"
, Transclude_bgn = new byte[] {Byte_ascii.Curly_bgn, Byte_ascii.Curly_bgn, Byte_ascii.Colon} // "{{:"
, Url_relative_prefix = new byte[] {Byte_ascii.Slash, Byte_ascii.Slash} // "//"
, Url_wiki_intermediary = Bry_.new_a7("/wiki/")
;
}

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; import gplx.*;
import gplx.dbs.*;
public class Xoa_test_ {
public static boolean Db_skip() {return Bool_.N;}
public static boolean Db_is_mem_dflt() {return Bool_.Y;}
public static void Db_init(Io_url sqlite_url) {Db_init(Db_is_mem_dflt(), sqlite_url);}
public static void Db_init(boolean db_is_mem, Io_url sqlite_url) {
if (db_is_mem) {
Io_mgr.I.InitEngine_mem();
Db_conn_bldr.I.Reg_default_mem();
}
else {
Io_mgr.I.DeleteDirDeep(sqlite_url);
Db_conn_bldr.I.Reg_default_sqlite();
}
}
public static Io_url Url_root() {return Io_url_.Usr().GenSubDir_nest("xowa", "dev", "tst", "400_xowa");}
public static Io_url Url_wiki_enwiki() {return Url_root().GenSubDir_nest("root", "wiki", "en.wikipedia.org");}
public static Io_url Url_file_enwiki() {return Url_root().GenSubDir_nest("root", "file", "en.wikipedia.org");}
}

View File

@@ -0,0 +1,227 @@
/*
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; import gplx.*;
import gplx.core.btries.*; import gplx.core.flds.*; import gplx.ios.*; import gplx.core.threads.*;
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*; import gplx.xowa.urls.encoders.*; import gplx.xowa.apps.progs.*;
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
import gplx.xowa.bldrs.css.*;
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.gui.*; import gplx.xowa.cfgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.html.tocs.*; import gplx.xowa.fmtrs.*; import gplx.xowa.html.*;
import gplx.xowa.html.hrefs.*; import gplx.xowa.html.wtrs.*; import gplx.xowa.html.ns_files.*; import gplx.xowa.html.js.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.tblws.*;
import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.math.*;
import gplx.xowa.parsers.logs.*; import gplx.xowa.servers.tcp.*; import gplx.xowa.servers.http.*;
import gplx.xowa.wmfs.*;
public class Xoae_app implements Xoa_app, GfoInvkAble {
public Xoae_app(Gfo_usr_dlg usr_dlg, Xoa_app_type app_type, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url user_dir, Io_url css_dir, String bin_dir_name) {
Xoa_app_.Usr_dlg_(usr_dlg);
this.app_type = app_type;
Io_url.Http_file_str_encoder = Xoa_app_.Utl__encoder_mgr().Fsys();
fsys_mgr = new Xoa_fsys_mgr(bin_dir_name, root_dir, wiki_dir, file_dir, css_dir);
log_wtr = usr_dlg.Log_wkr();
cfg_mgr = new Xoa_cfg_mgr(this);
api_root = new Xoapi_root(this);
user = new Xoue_user(this, user_dir);
url_cmd_eval = new Xoa_fsys_eval(fsys_mgr, user.Fsys_mgr());
fsys_mgr.Init_by_app(prog_mgr);
log_wtr.Log_dir_(user.Fsys_mgr().App_temp_dir().GenSubDir("log"));
lang_mgr = new Xoa_lang_mgr(this);
wiki_mgr = new Xoae_wiki_mgr(this);
gui_mgr = new Xoa_gui_mgr(this);
bldr = new Xob_bldr(this);
file_mgr.Ctor_by_app(this);
href_parser = new Xoh_href_parser(Xoa_app_.Utl__encoder_mgr().Href(), utl_url_parser.Url_parser());
sanitizer = new Xop_sanitizer(parser_amp_mgr, msg_log);
user_mgr = new Xou_user_mgr(this, user);
sys_cfg = new Xoa_sys_cfg(this);
cur_redirect = new Xoa_cur(this);
shell = new Xoa_shell(this);
setup_mgr = new Xoi_setup_mgr(this);
Xoa_app_.Gfs_mgr_(new Xoa_gfs_mgr(this, fsys_mgr, user.Fsys_mgr()));
xtn_mgr = new Xow_xtn_mgr().Ctor_by_app(this);
hive_mgr = new Xoa_hive_mgr(this);
tcp_server.App_ctor(this);
fmtr_mgr = new Xoa_fmtr_mgr(this);
log_mgr = new Xop_log_mgr(this);
http_server = new Http_server_mgr(this);
cfg_regy = new Xocfg_regy(this);
html_mgr = new Xoh_html_mgr(this);
this.html__lnki_bldr = new Xoh_lnki_bldr(this, href_parser);
this.html__json_exec = new Xoh_json_exec(this);
}
public Xoa_app_type App_type() {return app_type;} private final Xoa_app_type app_type;
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xoa_fsys_mgr fsys_mgr;
public Xof_cache_mgr File__cache_mgr() {return file_mgr.Cache_mgr();}
public Xof_img_mgr File__img_mgr() {return file_mgr.Img_mgr();}
public Io_download_fmt File__download_fmt() {return wmf_mgr.Download_wkr().Download_xrg().Download_fmt();}
public Xoh_href_parser Html__href_parser() {return href_parser;} private Xoh_href_parser href_parser;
public Xoh_lnki_bldr Html__lnki_bldr() {return html__lnki_bldr;} private final Xoh_lnki_bldr html__lnki_bldr;
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_json_exec Html__json_exec() {return html__json_exec;} private final Xoh_json_exec html__json_exec;
public Xowmf_mgr Wmf_mgr() {return wmf_mgr;} private final Xowmf_mgr wmf_mgr = new Xowmf_mgr();
public Bry_bfr_mkr Utl__bfr_mkr() {return Xoa_app_.Utl__bfr_mkr();}
public Url_encoder_mgr Utl__encoder_mgr() {return Xoa_app_.Utl__encoder_mgr();}
public Xoa_url_parser Utl__url_parser() {return utl_url_parser;} private final Xoa_url_parser utl_url_parser = new Xoa_url_parser();
public Xoae_wiki_mgr Wiki_mgr() {return wiki_mgr;} private Xoae_wiki_mgr wiki_mgr;
public Xoa_wiki_mgr Wiki_mgri() {return wiki_mgr;}
public Xou_user_mgr User_mgr() {return user_mgr;} private Xou_user_mgr user_mgr;
public Xof_file_mgr File_mgr() {return file_mgr;} private Xof_file_mgr file_mgr = new Xof_file_mgr();
public Xoa_lang_mgr Lang_mgr() {return lang_mgr;} private Xoa_lang_mgr lang_mgr;
public Xoa_gui_mgr Gui_mgr() {return gui_mgr;} private Xoa_gui_mgr gui_mgr;
public Xou_user User() {return user;}
public Xoue_user Usere() {return user;} private Xoue_user user;
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
public Xow_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Xow_xtn_mgr xtn_mgr;
public Xoapi_root Api_root() {return api_root;} private Xoapi_root api_root;
public Xop_tkn_mkr Tkn_mkr() {return tkn_mkr;} private Xop_tkn_mkr tkn_mkr = new Xop_tkn_mkr();
public Gfo_usr_dlg Usr_dlg() {return Xoa_app_.Usr_dlg();}
public Gfo_usr_dlg__log Log_wtr() {return log_wtr;} private Gfo_usr_dlg__log log_wtr;
public Xoa_gfs_mgr Gfs_mgr() {return Xoa_app_.Gfs_mgr();}
public Xoa_special_mgr Special_mgr() {return special_mgr;} private Xoa_special_mgr special_mgr = new gplx.xowa.specials.Xoa_special_mgr();
public Xoh_html_mgr Html_mgr() {return html_mgr;} private Xoh_html_mgr html_mgr;
public Xop_log_mgr Log_mgr() {return log_mgr;} private Xop_log_mgr log_mgr;
public Xoa_shell Shell() {return shell;} private Xoa_shell shell;
public Xoa_thread_mgr Thread_mgr() {return thread_mgr;} private Xoa_thread_mgr thread_mgr = new Xoa_thread_mgr();
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
public Xoh_href_parser Href_parser() {return href_parser;}
public Xop_sanitizer Sanitizer() {return sanitizer;} private Xop_sanitizer sanitizer;
public Xop_xatr_parser Xatr_parser() {return xatr_parser;} private Xop_xatr_parser xatr_parser = new Xop_xatr_parser();
public Xop_xnde_tag_regy Xnde_tag_regy() {return xnde_tag_regy;} private Xop_xnde_tag_regy xnde_tag_regy = new Xop_xnde_tag_regy();
public Xof_math_subst_regy Math_subst_regy() {return math_subst_regy;} private Xof_math_subst_regy math_subst_regy = new Xof_math_subst_regy();
public Xoa_prog_mgr Prog_mgr() {return prog_mgr;} private final Xoa_prog_mgr prog_mgr = new Xoa_prog_mgr();
public Gfo_async_mgr Async_mgr() {return async_mgr;} private Gfo_async_mgr async_mgr = new Gfo_async_mgr();
public Xoi_setup_mgr Setup_mgr() {return setup_mgr;} private Xoi_setup_mgr setup_mgr;
public Gfo_msg_log Msg_log() {return msg_log;} private Gfo_msg_log msg_log = new Gfo_msg_log(Xoa_app_.Name);
public Gfo_msg_log Msg_log_null() {return msg_log_null;} private Gfo_msg_log msg_log_null = new Gfo_msg_log("null_log");
public Xoh_ns_file_page_mgr Ns_file_page_mgr() {return ns_file_page_mgr;} private Xoh_ns_file_page_mgr ns_file_page_mgr = new Xoh_ns_file_page_mgr();
public Btrie_slim_mgr Utl_trie_tblw_ws() {return utl_trie_tblw_ws;} private Btrie_slim_mgr utl_trie_tblw_ws = Xop_tblw_ws_itm.trie_();
public Gfo_fld_rdr Utl_fld_rdr() {return utl_fld_rdr;} Gfo_fld_rdr utl_fld_rdr = Gfo_fld_rdr.xowa_();
public Gfo_log_bfr Log_bfr() {return log_bfr;} private Gfo_log_bfr log_bfr = new Gfo_log_bfr();
public Xoa_sys_cfg Sys_cfg() {return sys_cfg;} private Xoa_sys_cfg sys_cfg;
public Bry_fmtr Tmp_fmtr() {return tmp_fmtr;} Bry_fmtr tmp_fmtr = Bry_fmtr.new_("");
public boolean Xwiki_mgr__missing(byte[] wiki_key) {return user.Wiki().Xwiki_mgr().Get_by_key(wiki_key) == null;} // NOTE: only the user_wiki has a full list of all wikis b/c it has xwiki objects; wiki_mgr does not, b/c it has heavier wiki objects which are loaded dynamically;
public boolean Xwiki_mgr__exists(byte[] wiki_key) {return user.Wiki().Xwiki_mgr().Get_by_key(wiki_key) != null;}
public Xoa_ctg_mgr Ctg_mgr() {return ctg_mgr;} private Xoa_ctg_mgr ctg_mgr = new Xoa_ctg_mgr();
public Xoa_fsys_eval Url_cmd_eval() {return url_cmd_eval;} Xoa_fsys_eval url_cmd_eval;
public Xoa_cur Cur_redirect() {return cur_redirect;} private Xoa_cur cur_redirect;
public Xoa_cfg_mgr Cfg_mgr() {return cfg_mgr;} private Xoa_cfg_mgr cfg_mgr;
public Xocfg_regy Cfg_regy() {return cfg_regy;} private Xocfg_regy cfg_regy;
public Io_stream_zip_mgr Zip_mgr() {return zip_mgr;} Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
public Xoa_cache_mgr Cache_mgr() {return cache_mgr;} private Xoa_cache_mgr cache_mgr = new Xoa_cache_mgr();
public Xosrv_server Tcp_server() {return tcp_server;} private Xosrv_server tcp_server = new Xosrv_server();
public Http_server_mgr Http_server() {return http_server;} private Http_server_mgr http_server;
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = new Xop_amp_mgr();
private Xoa_fmtr_mgr fmtr_mgr;
public Number_parser Utl_num_parser() {return utl_num_parser;} private Number_parser utl_num_parser = new Number_parser();
public void Init_by_app() {
stage = Xoa_stage_.Tid_init;
user.Init_by_app(this);
prog_mgr.Init_by_app(url_cmd_eval);
xtn_mgr.Init_by_app(this);
gui_mgr.Init_by_app();
html__css_installer.Init_by_app(this);
wiki_mgr.Init_by_app();
gplx.xowa.utls.upgrades.Xoa_upgrade_mgr.Check(this);
ctg_mgr.Init_by_app(this);
setup_mgr.Init_by_app(this);
thread_mgr.Usr_dlg_(Xoa_app_.Usr_dlg());
html_mgr.Init_by_app(this);
api_root.Init_by_app(this);
wmf_mgr.Init_by_app(this);
}
public boolean Launch_done() {return stage == Xoa_stage_.Tid_launch;}
public void Launch() {
if (Launch_done()) return;
stage = Xoa_stage_.Tid_launch;
user.Cfg_mgr().Setup_mgr().Setup_run_check(this); log_bfr.Add("app.upgrade.done");
gplx.xowa.users.prefs.Prefs_converter._.Check(this);
user.Wiki().Init_assert(); // NOTE: must assert wiki and load langs first, else will be asserted during Portal_mgr().Init(), which will cause IndexOutOfBounds; DATE:2014-10-04
}
public byte Stage() {return stage;} public Xoae_app Stage_(byte v) {stage = v; return this;} private byte stage = Xoa_stage_.Tid_ctor;
public boolean Term_cbk() {
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
usr_dlg.Log_many("", "", "term:bgn");
if (setup_mgr.Cmd_mgr().Working()) {
if (!gui_mgr.Kit().Ask_yes_no("", "", "An import is in progress. Are you sure you want to exit?")) return false;
}
if (!gui_mgr.Browser_win().Tab_mgr().Tabs__pub_close_all()) return false;
gui_mgr.Browser_win().Usr_dlg().Canceled_y_();
user.App_term(); usr_dlg.Log_many("", "", "term:app_term");
log_wtr.Log_term(); usr_dlg.Log_many("", "", "term:log_wtr");
log_mgr.Rls(); usr_dlg.Log_many("", "", "term:log_mgr");
if (Scrib_core.Core() != null) {Scrib_core.Core().Term(); usr_dlg.Log_many("", "", "term:scrib");}
wiki_mgr.Rls(); usr_dlg.Log_many("", "", "term:wiki_mgr");
return true;
}
public void Reset_all() {
this.Free_mem(true);
gplx.xowa.xtns.scribunto.Scrib_core.Core_invalidate();
Env_.GarbageCollect();
}
public void Free_mem(boolean clear_ctx) {
this.Utl__bfr_mkr().Clear();
msg_log.Clear();
wiki_mgr.Free_mem(clear_ctx);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_gui)) return gui_mgr;
else if (ctx.Match(k, Invk_api)) return api_root;
else if (ctx.Match(k, Invk_bldr)) return bldr;
else if (ctx.Match(k, Invk_wikis)) return wiki_mgr;
else if (ctx.Match(k, Invk_fsys)) return fsys_mgr;
else if (ctx.Match(k, Invk_files)) return file_mgr;
else if (ctx.Match(k, Invk_langs)) return lang_mgr;
else if (ctx.Match(k, Invk_users)) return user_mgr;
else if (ctx.Match(k, Invk_user)) return user;
else if (ctx.Match(k, Invk_sys_cfg)) return sys_cfg;
else if (ctx.Match(k, Invk_cur)) return cur_redirect;
else if (ctx.Match(k, Invk_html)) return html_mgr;
else if (ctx.Match(k, Invk_shell)) return shell;
else if (ctx.Match(k, Invk_log)) return log_wtr;
else if (ctx.Match(k, Invk_setup)) return setup_mgr;
else if (ctx.Match(k, Invk_scripts)) return Xoa_app_.Gfs_mgr();
else if (ctx.MatchPriv(k, Invk_term_cbk)) return this.Term_cbk();
else if (ctx.Match(k, Invk_xtns)) return xtn_mgr;
else if (ctx.Match(k, Invk_ctg_mgr)) return ctg_mgr;
else if (ctx.Match(k, Invk_cfgs)) return cfg_mgr;
else if (ctx.Match(k, Invk_usr_dlg)) return Xoa_app_.Usr_dlg();
else if (ctx.Match(k, Invk_specials)) return special_mgr;
else if (ctx.Match(k, Invk_server)) return tcp_server;
else if (ctx.Match(k, Invk_http_server)) return http_server;
else if (ctx.Match(k, Invk_app)) return this;
else if (ctx.Match(k, Invk_xowa)) return this;
else if (ctx.Match(k, Invk_fmtrs)) return fmtr_mgr;
else if (ctx.Match(k, Invk_cfg)) return cfg_regy;
else return GfoInvkAble_.Rv_unhandled;
}
public static final String Invk_gui = "gui", Invk_bldr = "bldr", Invk_wikis = "wikis", Invk_files = "files", Invk_langs = "langs", Invk_users = "users"
, Invk_sys_cfg = "sys_cfg", Invk_fsys = "fsys", Invk_cur = "cur", Invk_shell = "shell", Invk_log = "log"
, Invk_setup = "setup", Invk_scripts = "scripts", Invk_user = "user", Invk_xtns = "xtns", Invk_ctg_mgr = "ctg_mgr"
, Invk_cfgs = "cfgs", Invk_app = "app", Invk_xowa = "xowa", Invk_usr_dlg = "usr_dlg", Invk_specials = "specials", Invk_html = "html"
, Invk_server = "tcp_server", Invk_http_server = "http_server"
, Invk_fmtrs = "fmtrs"
, Invk_cfg = "cfg"
, Invk_api = "api"
;
public static final String Invk_term_cbk = "term_cbk";
}

View File

@@ -0,0 +1,178 @@
/*
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.apis; import gplx.*; import gplx.xowa.*;
class Xoapi_doc {}
/*
xowa {
app {
exit();
env {
version_previous;
}
fsys {
plat_jar;
plat_url();
}
startup {
tabs {
type; // [blank,xowa,custom,previous]
previous;
custom;
custom_is_expr;
}
}
}
nav {
go_bwd();
go_fwd();
goto();
wiki {
main_page();
random();
sandbox();
}
}
gui {
browser {
url {
focus();
exec_by_paste();
exec_new_tab_by_paste();
restore();
exec();
}
search {
focus();
exec();
}
tabs {
new_dflt__at_dflt__focus_y();
new_link__at_dflt__focus_n();
new_link__at_dflt__focus_y();
new_href__at_dflt__focus_y();
new_dupe__at_dflt__focus_y();
close_cur();
select_bwd();
select_fwd();
move_bwd();
move_fwd();
close_others();
close_to_bgn();
close_to_end();
close_undo();
pin_toggle();
select_by_idx_1();
select_by_idx_2();
select_by_idx_3();
select_by_idx_4();
select_by_idx_5();
select_by_idx_6();
select_by_idx_7();
select_by_idx_8();
select_by_idx_9();
}
html {
focus();
selection_focus_toggle();
load_tid; // [mem,url]
}
find {
show();
show_by_paste();
hide();
exec();
type();
find_bwd();
find_fwd();
case_toggle();
wrap_toggle();
}
prog {
focus();
show_short_link;
}
info {
focus();
clear();
launch();
warn_enabled;
note_enabled;
}
prog_log {
show();
}
}
font {
increase();
decrease();
reset();
}
page {
edit {
copy();
select_all();
save();
save_draft();
preview();
focus_edit_box();
dbg_tmpl();
dbg_html();
exec();
}
selection {
copy();
select_all();
save_file_as();
}
view {
mode_read();
mode_edit();
mode_html();
reload();
refresh();
print();
save_as();
}
}
}
html {
}
net {
}
usr {
}
special {
}
xtns {
}
bldr {
wikis {
filters {
dansguardians {
}
}
imports {
one_file = 'y';
schema_is_1 = 'y';
text_zip_tid = '.gz';
html_zip_tid = '.gz';
}
}
}
}
*/

View File

@@ -0,0 +1,77 @@
/*
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.apis; import gplx.*; import gplx.xowa.*;
import gplx.xowa.apis.xowa.*; import gplx.xowa.gui.cmds.*;
public class Xoapi_root implements GfoInvkAble {
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);
}
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);
net_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) {
Io_url img_dir = app.Usere().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "portal");
html_api.Page().Toggle_mgr().Img_dir_(img_dir);
usr_api.Init_by_app(app);
}
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_net Net() {return net_api;} private final Xoapi_net net_api = new Xoapi_net();
public Xoapi_usr Usr() {return usr_api;} private final Xoapi_usr usr_api = new Xoapi_usr();
public Xoapi_special Special() {return special_api;} private final Xoapi_special special_api = new Xoapi_special();
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_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_net)) return net_api;
else if (ctx.Match(k, Invk_usr)) return usr_api;
else if (ctx.Match(k, Invk_special)) return special_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_app = "app", Invk_bldr = "bldr", Invk_nav = "nav", Invk_gui = "gui", Invk_html = "html", Invk_net = "net", Invk_usr = "usr", Invk_special = "special", Invk_xtns = "xtns"
, Invk_test_str = "test_str", Invk_test_str_ = "test_str_"
;
}

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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.gui.views.*;
import gplx.xowa.apis.xowa.apps.*; import gplx.xowa.apis.xowa.envs.*; import gplx.xowa.apis.xowa.startups.*;
public class Xoapi_app implements GfoInvkAble {
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 Xoapi_env Env() {return env;} private Xoapi_env env = new Xoapi_env();
public Xoapi_startups Startup() {return startup;} private Xoapi_startups startup = new Xoapi_startups();
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 if (ctx.Match(k, Invk_startup)) return startup;
else if (ctx.Match(k, Invk_env)) return env;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_exit = "exit", Invk_startup = "startup", Invk_env = "env", 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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.bldrs.*;
public class Xoapi_bldr implements GfoInvkAble {
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 GfoInvkAble_.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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.gui.*;
public class Xoapi_gui implements GfoInvkAble {
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,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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.html.*;
public class Xoapi_html implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
tidy.Init_by_kit(app);
modules.Init_by_kit(app);
}
public Xoapi_tidy Tidy() {return tidy;} private Xoapi_tidy tidy = new Xoapi_tidy();
public Xoapi_modules Modules() {return modules;} private Xoapi_modules modules = new Xoapi_modules();
public Xoapi_skins Skins() {return skins;} private Xoapi_skins skins = new Xoapi_skins();
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_tidy)) return tidy;
else if (ctx.Match(k, Invk_modules)) return modules;
else if (ctx.Match(k, Invk_skins)) return skins;
else if (ctx.Match(k, Invk_page)) return page;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_tidy = "tidy", Invk_modules = "modules", Invk_skins = "skins", 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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.gui.views.*;
import gplx.xowa.apis.xowa.navs.*;
public class Xoapi_nav implements GfoInvkAble {
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_wiki Wiki() {return wiki;} private Xoapi_wiki wiki = new Xoapi_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 GfoInvkAble_.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,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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
public class Xoapi_net implements GfoInvkAble, GfoEvObj {
public Xoapi_net() {this.ev_mgr = GfoEvMgr.new_(this);}
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
public void Init_by_kit(Xoae_app app) {
}
public boolean Enabled() {return enabled;} private boolean enabled = true;
public void Enabled_(boolean v) {
this.enabled = v;
gplx.ios.IoEngine_system.Web_access_enabled = v;
GfoEvMgr_.PubVal(this, gplx.xowa.gui.menus.dom.Xog_mnu_evt_mgr.Evt_selected_changed, v);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return this.Enabled();
else if (ctx.Match(k, Invk_enabled_n_)) this.Enabled_(Bool_.N);
else if (ctx.Match(k, Invk_enabled_y_)) this.Enabled_(Bool_.Y);
else if (ctx.Match(k, Invk_enabled_x_)) this.Enabled_(this.Enabled());
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_enabled = "enabled", Invk_enabled_n_ = "enabled_n_", Invk_enabled_y_ = "enabled_y_", Invk_enabled_x_ = "enabled_x_"
;
public static final String Evt_enabled_changed = "enabled_changed";
}

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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.specials.*;
public class Xoapi_special implements GfoInvkAble {
public void Ctor_by_app(Xoae_app app) {
}
public void Init_by_kit(Xoae_app app) {
}
public Xoapi_search Search() {return search;} private Xoapi_search search = new Xoapi_search();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_search)) return search;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_search = "search";
}

View File

@@ -0,0 +1,45 @@
/*
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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.usrs.*;
public class Xoapi_usr implements GfoInvkAble {
public void Ctor_by_app(Xoae_app app) {
bookmarks.Ctor_by_app(app);
history.Ctor_by_app(app);
logs.Ctor_by_app(app);
}
public void Init_by_app(Xoa_app app) {
cache.Init_by_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 Xoapi_logs Logs() {return logs;} private final Xoapi_logs logs = new Xoapi_logs();
public Xoapi_cache Cache() {return cache;} private final Xoapi_cache cache = new Xoapi_cache();
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 if (ctx.Match(k, Invk_logs)) return logs;
else if (ctx.Match(k, Invk_cache)) return cache;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_bookmarks = "bookmarks", Invk_history = "history", Invk_logs = "logs", Invk_cache = "cache";
}

View File

@@ -0,0 +1,35 @@
/*
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.apis.xowa; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
import gplx.xowa.apis.xowa.xtns.*;
public class Xoapi_xtns implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
scribunto.Init_by_kit(app);
}
public Xoapi_scribunto Scribunto() {return scribunto;} private final Xoapi_scribunto scribunto = new Xoapi_scribunto();
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_scribunto)) return scribunto;
else if (ctx.Match(k, Invk_wikibase)) return wikibase;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String
Invk_scribunto = "scribunto"
, Invk_wikibase = "wikibase"
;
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
public class Xoapi_fsys implements GfoInvkAble {
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 GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_plat_jar = "plat_jar", Invk_plat_url = "plat_url";
}

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.apis.xowa.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.bldrs.filters.*;
import gplx.xowa.apis.xowa.bldrs.imports.*;
public class Xoapi_bldr_wiki implements GfoInvkAble {
public void Ctor_by_app(Xoa_app app) {filter.Ctor_by_app(app);}
public Xoapi_filter Filter() {return filter;} private final Xoapi_filter filter = new Xoapi_filter();
public Xoapi_import Import() {return import_api;} private final Xoapi_import import_api = new Xoapi_import();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_filter)) return filter;
else if (ctx.Match(k, Invk_import)) return import_api;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_filter = "filter", Invk_import = "import";
}

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.apis.xowa.bldrs.filters; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.bldrs.*;
import gplx.xowa.apis.xowa.bldrs.filters.dansguardians.*;
public class Xoapi_filter implements GfoInvkAble {
public void Ctor_by_app(Xoa_app app) {dansguardian.Ctor_by_app(app);}
public Xoapi_dansguardian Dansguardian() {return dansguardian;} private final Xoapi_dansguardian dansguardian = new Xoapi_dansguardian();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_dansguardian)) return dansguardian;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_dansguardian = "dansguardian";
}

View File

@@ -0,0 +1,76 @@
/*
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.apis.xowa.bldrs.filters.dansguardians; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.bldrs.*; import gplx.xowa.apis.xowa.bldrs.filters.*;
import gplx.ios.*; import gplx.xowa.bldrs.filters.dansguardians.*;
public class Xoapi_dansguardian implements GfoInvkAble {
public void Ctor_by_app(Xoa_app app) {
root_dir = app.Fsys_mgr().Bin_xowa_dir().GenSubDir_nest("cfg", "bldr", "filter");
}
public boolean Enabled() {return enabled;} private boolean enabled = Bool_.N;
public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
public int Score_init() {return score_init;} private int score_init = 0;
public int Score_fail() {return score_fail;} private int score_fail = 0;
public boolean Case_match() {return case_match;} private boolean case_match = Bool_.N;
public boolean Wildcard_enabled() {return wildcard_enabled;} private boolean wildcard_enabled = Bool_.N;
public byte[] Wildcard_char() {return wildcard_char;} private byte[] wildcard_char = Byte_ascii.Space_bry;
public byte[][] Wildcard_list() {return wildcard_list;} private byte[][] wildcard_list = Bry_.Ary(Byte_ascii.Space_bry);// \s,.!?:;'"-() /@#$%^&*()[]{}<>_+=|\~`
public int Target_tid() {return target_tid;} private int target_tid = Dg_match_mgr.Target_tid_wikitext;
public boolean Log_enabled() {return log_enabled;} private boolean log_enabled = Bool_.Y;
public Dg_match_mgr New_mgr(String domain_str, Io_url wiki_root_dir) {
if (!enabled) return null;
Io_url log_url = wiki_root_dir.GenSubFil("dansguardian_log.sqlite3");
Dg_match_mgr rv = new Dg_match_mgr(root_dir.GenSubDir(domain_str), score_init, score_fail, case_match, log_enabled, log_url);
return rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_root_dir)) return root_dir.Raw();
else if (ctx.Match(k, Invk_root_dir_)) root_dir = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk_score_init)) return Int_.Xto_str(score_init);
else if (ctx.Match(k, Invk_score_init_)) score_init = m.ReadInt("v");
else if (ctx.Match(k, Invk_score_fail)) return Int_.Xto_str(score_fail);
else if (ctx.Match(k, Invk_score_fail_)) score_fail = m.ReadInt("v");
else if (ctx.Match(k, Invk_case_match)) return Yn.Xto_str(case_match);
else if (ctx.Match(k, Invk_case_match_)) case_match = m.ReadYn("v");
else if (ctx.Match(k, Invk_wildcard_enabled)) return Yn.Xto_str(wildcard_enabled);
else if (ctx.Match(k, Invk_wildcard_enabled_)) wildcard_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_wildcard_char)) return String_.new_u8(wildcard_char);
else if (ctx.Match(k, Invk_wildcard_char_)) wildcard_char = m.ReadBry("v");
else if (ctx.Match(k, Invk_wildcard_list)) return "";
else if (ctx.Match(k, Invk_wildcard_list_)) {}
else if (ctx.Match(k, Invk_target_tid)) return Int_.Xto_str(target_tid);
else if (ctx.Match(k, Invk_target_tid_)) target_tid = m.ReadInt("v");
else if (ctx.Match(k, Invk_log_enabled)) return Yn.Xto_str(log_enabled);
else if (ctx.Match(k, Invk_log_enabled_)) log_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_enabled = "enabled" , Invk_enabled_ = "enabled_"
, Invk_root_dir = "root_dir" , Invk_root_dir_ = "root_dir_"
, Invk_score_init = "score_init" , Invk_score_init_ = "score_init_"
, Invk_score_fail = "score_fail" , Invk_score_fail_ = "score_fail_"
, Invk_case_match = "case_match" , Invk_case_match_ = "case_match_"
, Invk_wildcard_enabled = "wildcard_enabled" , Invk_wildcard_enabled_ = "wildcard_enabled_"
, Invk_wildcard_char = "wildcard_char" , Invk_wildcard_char_ = "wildcard_char_"
, Invk_wildcard_list = "wildcard_list" , Invk_wildcard_list_ = "wildcard_list_"
, Invk_target_tid = "target_tid" , Invk_target_tid_ = "target_tid_"
, Invk_log_enabled = "log_enabled" , Invk_log_enabled_ = "log_enabled_"
;
}

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.apis.xowa.bldrs.filters.titles; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.bldrs.*; import gplx.xowa.apis.xowa.bldrs.filters.*;
public class Xoapi_title implements GfoInvkAble {
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.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_wordlist_dir)) return Int_.Xto_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_.Xto_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_.Xto_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.Xto_str(enabled);
else if (ctx.Match(k, Invk_log_enabled_)) log_enabled = m.ReadYn("v");
else return GfoInvkAble_.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,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.apis.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.bldrs.*;
import gplx.ios.*; import gplx.xowa.wikis.data.*;
public class Xoapi_import implements GfoInvkAble {
public long Layout_all_max() {return layout_all_max;} private long layout_all_max = 0; // disable by default; may set to 200 MB in future
public long Layout_text_max() {return layout_text_max;} private long layout_text_max = Io_size_.To_long_by_int_mb(1500); // 1.5 GB
public long Layout_html_max() {return layout_html_max;} private long layout_html_max = Io_size_.To_long_by_int_mb(1500); // 1.5 GB
public long Layout_file_max() {return layout_file_max;} private long layout_file_max = Io_size_.To_long_by_int_mb(1500); // 1.5 GB
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 long Text_db_max() {return text_db_max;} private long text_db_max = Io_size_.To_long_by_int_mb(1500); // 3.0 GB; v1
public long Html_db_max() {return html_db_max;} private long html_db_max = Io_size_.To_long_by_int_mb(1500); // 3.0 GB; v2; use same as text
public long File_db_max() {return file_db_max;} private long file_db_max = Io_size_.To_long_by_int_mb(1500); // 3.2 GB; v2
public byte[] Ns_file_map() {return ns_file_map;} private byte[] ns_file_map = Ns_file_map__each;
public byte Zip_tid_text() {return zip_tid_text;} private byte zip_tid_text = Io_stream_.Tid_gzip;
public byte Zip_tid_html() {return zip_tid_html;} private byte zip_tid_html = Io_stream_.Tid_gzip;
public String User_name() {return user_name;} private String user_name = "anonymous";
public Xowd_core_db_props New_props(String domain_str, long dump_file_size) {
Xowd_db_layout layout_text, layout_html, layout_file;
if (dump_file_size < layout_all_max)
layout_text = layout_html = layout_file = Xowd_db_layout.Itm_all;
else {
layout_text = dump_file_size < layout_text_max ? Xowd_db_layout.Itm_few : Xowd_db_layout.Itm_lot;
layout_html = dump_file_size < layout_html_max ? Xowd_db_layout.Itm_few : Xowd_db_layout.Itm_lot;
layout_file = dump_file_size < layout_file_max ? Xowd_db_layout.Itm_few : Xowd_db_layout.Itm_lot;
}
return new Xowd_core_db_props(2, layout_text, layout_html, layout_file, zip_tid_text, zip_tid_html);
}
public byte[] New_ns_file_map(long dump_file_size) {
return dump_file_size < layout_text_max ? Bry_.Empty : Ns_file_map__each;
}
public void Zip_tid_text_raw_() {zip_tid_text = Io_stream_.Tid_raw;} // TEST:
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_layout_all_max)) return Io_size_.To_str_mb(layout_all_max);
else if (ctx.Match(k, Invk_layout_all_max_)) layout_all_max = Io_size_.To_long_by_msg_mb(m, layout_all_max);
else if (ctx.Match(k, Invk_layout_text_max)) return Io_size_.To_str_mb(layout_text_max);
else if (ctx.Match(k, Invk_layout_text_max_)) layout_text_max = Io_size_.To_long_by_msg_mb(m, layout_text_max);
else if (ctx.Match(k, Invk_layout_html_max)) return Io_size_.To_str_mb(layout_html_max);
else if (ctx.Match(k, Invk_layout_html_max_)) layout_html_max = Io_size_.To_long_by_msg_mb(m, layout_html_max);
else if (ctx.Match(k, Invk_layout_file_max)) return Io_size_.To_str_mb(layout_file_max);
else if (ctx.Match(k, Invk_layout_file_max_)) layout_file_max = Io_size_.To_long_by_msg_mb(m, layout_file_max);
else 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_text_db_max)) return Io_size_.To_str_mb(text_db_max);
else if (ctx.Match(k, Invk_text_db_max_)) text_db_max = Io_size_.To_long_by_msg_mb(m, text_db_max);
else if (ctx.Match(k, Invk_html_db_max)) return Io_size_.To_str_mb(html_db_max);
else if (ctx.Match(k, Invk_html_db_max_)) html_db_max = Io_size_.To_long_by_msg_mb(m, html_db_max);
else if (ctx.Match(k, Invk_file_db_max)) return Io_size_.To_str_mb(file_db_max);
else if (ctx.Match(k, Invk_file_db_max_)) file_db_max = Io_size_.To_long_by_msg_mb(m, file_db_max);
else if (ctx.Match(k, Invk_ns_file_map)) return String_.new_u8(ns_file_map);
else if (ctx.Match(k, Invk_ns_file_map_)) ns_file_map = m.ReadBry("v");
else if (ctx.Match(k, Invk_zip_tid_text)) return Io_stream_.To_str(zip_tid_text);
else if (ctx.Match(k, Invk_zip_tid_text_)) zip_tid_text = Io_stream_.To_tid(m.ReadStr("v"));
else if (ctx.Match(k, Invk_zip_tid_html)) return Io_stream_.To_str(zip_tid_html);
else if (ctx.Match(k, Invk_zip_tid_html_)) zip_tid_html = Io_stream_.To_tid(m.ReadStr("v"));
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 GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_layout_all_max = "layout_all_max" , Invk_layout_all_max_ = "layout_all_max_"
, Invk_layout_text_max = "layout_text_max" , Invk_layout_text_max_ = "layout_text_max_"
, Invk_layout_html_max = "layout_html_max" , Invk_layout_html_max_ = "layout_html_max_"
, Invk_layout_file_max = "layout_file_max" , Invk_layout_file_max_ = "layout_file_max_"
, Invk_cat_link_db_max = "cat_link_db_max" , Invk_cat_link_db_max_ = "cat_link_db_max_"
, Invk_text_db_max = "text_db_max" , Invk_text_db_max_ = "text_db_max_"
, Invk_html_db_max = "html_db_max" , Invk_html_db_max_ = "html_db_max_"
, Invk_file_db_max = "file_db_max" , Invk_file_db_max_ = "file_db_max_"
, Invk_ns_file_map = "ns_file_map" , Invk_ns_file_map_ = "ns_file_map_"
, Invk_zip_tid_text = "zip_tid_text" , Invk_zip_tid_text_ = "zip_tid_text_"
, Invk_zip_tid_html = "zip_tid_html" , Invk_zip_tid_html_ = "zip_tid_html_"
, Invk_user_name = "user_name" , Invk_user_name_ = "user_name_"
;
public static final byte[] Ns_file_map__each = Bry_.new_a7("<each>");
}

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.apis.xowa.envs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
public class Xoapi_env implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {}
public String Version_previous() {return version_previous;} private String version_previous = "";
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_version_previous)) return version_previous;
else if (ctx.Match(k, Invk_version_previous_)) version_previous = m.ReadStr("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_version_previous = "version_previous", Invk_version_previous_ = "version_previous_";
}

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.apis.xowa.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.gui.browsers.*;
public class Xoapi_browser implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
url.Init_by_kit(app);
search.Init_by_kit(app);
tabs.Init_by_kit(app);
html.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_search Search() {return search;} private Xoapi_search search = new Xoapi_search();
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_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_search)) return search;
else if (ctx.Match(k, Invk_tabs)) return tabs;
else if (ctx.Match(k, Invk_html)) return html;
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 GfoInvkAble_.Rv_unhandled;
}
private static final String
Invk_url = "url", Invk_search = "search", Invk_tabs = "tabs", Invk_html = "html"
, Invk_find = "find", Invk_prog = "prog", Invk_info = "info", Invk_prog_log = "prog_log";
}

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.apis.xowa.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.cfgs.gui.*; import gplx.xowa.html.*;
public class Xoapi_font implements GfoInvkAble {
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);}
private 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.Html_mgr().Page_mgr().Font_enabled_(enabled);
app.Html_mgr().Page_mgr().Font_size_(html_font_size);
app.Cfg_mgr().Set_by_app("app.html.page.font_enabled", "y");
app.Cfg_mgr().Set_by_app("app.html.page.font_size", Float_.Xto_str(app.Html_mgr().Page_mgr().Font_size()));
app.Gui_mgr().Win_cfg().Font().Size_(gui_font_size);
app.Cfg_mgr().Set_by_app("app.gui.win_opts.font.size", Float_.Xto_str(gui_font_size));
app.Cfg_mgr().Db_save_txt();
app.Gui_mgr().Browser_win().Page__reload(); // NOTE: force reload; needed if viewing Help: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 GfoInvkAble_.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.apis.xowa.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.gui.pages.*;
public class Xoapi_page implements GfoInvkAble {
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 GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_view = "view", Invk_selection = "selection", Invk_edit = "edit";
}

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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.pages.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
public class Xoapi_find implements GfoInvkAble {
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 GfoInvkAble_.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; 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_view_mode.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;
boolean find_in_hdoc = tab.View_mode() == Xopg_view_mode.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,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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.pages.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
public class Xoapi_html_box implements GfoInvkAble, GfoEvMgrOwner {
private Xog_win_itm win;
public Xoapi_html_box() {
evMgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
public void Init_by_kit(Xoae_app app) {this.win = app.Gui_mgr().Browser_win();}
public byte Load_tid() {return load_tid;} private byte load_tid;
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_view_mode.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 if (ctx.Match(k, Invk_load_tid)) return Gxw_html_load_tid_.Xto_key(load_tid);
else if (ctx.Match(k, Invk_load_tid_)) {load_tid = Gxw_html_load_tid_.Xto_tid(m.ReadStr("v")); GfoEvMgr_.PubVal(this, Evt_load_tid_changed, load_tid);}
else if (ctx.Match(k, Invk_load_tid_list)) return Gxw_html_load_tid_.Options__list;
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_selection_focus_toggle = "selection_focus_toggle"
, Invk_load_tid = "load_tid", Invk_load_tid_ = "load_tid_", Invk_load_tid_list = "load_tid_list"
;
public static final String Evt_load_tid_changed = "load_tid_changed";
}

View File

@@ -0,0 +1,46 @@
/*
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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xoapi_info implements Gfo_usr_dlg__gui__opt, GfoInvkAble {
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 boolean Warn_enabled() {return warn_enabled;} private boolean warn_enabled;
public boolean Note_enabled() {return note_enabled;} private boolean note_enabled;
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 if (ctx.Match(k, Invk_warn_enabled)) return Yn.Xto_str(warn_enabled);
else if (ctx.Match(k, Invk_warn_enabled_)) warn_enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_note_enabled)) return Yn.Xto_str(note_enabled);
else if (ctx.Match(k, Invk_note_enabled_)) note_enabled = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_clear = "clear", Invk_launch = "launch"
, Invk_warn_enabled = "warn_enabled", Invk_warn_enabled_ = "warn_enabled_"
, Invk_note_enabled = "note_enabled", Invk_note_enabled_ = "note_enabled_"
;
}

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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xoapi_prog implements GfoInvkAble {
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 boolean Show_short_url() {return show_short_url;} private boolean show_short_url;
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 if (ctx.Match(k, Invk_show_short_url)) return Yn.Xto_str(show_short_url);
else if (ctx.Match(k, Invk_show_short_url_)) show_short_url = m.ReadBool("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_focus = "focus", Invk_show_short_url = "show_short_url", Invk_show_short_url_ = "show_short_url_";
}

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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xoapi_prog_log implements GfoInvkAble {
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 GfoInvkAble_.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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xoapi_search implements GfoInvkAble {
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 GfoInvkAble_.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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.xowa.gui.views.*;
public class Xoapi_tabs implements GfoInvkAble {
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 GfoInvkAble_.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,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.views.*;
public class Xoapi_url implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {this.app = app;} private Xoae_app app;
private GfuiTextBox Url_box() {return app.Gui_mgr().Browser_win().Url_box();}
public void Focus() {this.Url_box().Focus_select_all();}
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().Xto_full_str());
}
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) {
String url = urls[0];
this.Url_box().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 return GfoInvkAble_.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";
public static final String Invk_exec = "exec";
}

View File

@@ -0,0 +1,57 @@
/*
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.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
public class Xoapi_edit implements GfoInvkAble {
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_view_mode.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; GfoInvkAble_.InvkCmd(win.Win_box().Kit().Clipboard(), gplx.gfui.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_view_mode.Tid_edit);}
public void Dbg_html() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xopg_view_mode.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 GfoInvkAble_.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.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
public class Xoapi_selection implements GfoInvkAble {
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; GfoInvkAble_.InvkCmd(win.Win_box().Kit().Clipboard(), gplx.gfui.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().Xto_full_str()); return;}
Io_url src_url = Io_url_.http_any_(src, Op_sys.Cur().Tid_is_wnt());
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.I.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 GfoInvkAble_.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,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.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
public class Xoapi_view implements GfoInvkAble {
private Xoae_app app; private Xog_win_itm win;
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_view_mode.Tid_read);}
public void Mode_edit() {Mode(Xopg_view_mode.Tid_edit);}
public void Mode_html() {Mode(Xopg_view_mode.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 = Xoa_app_.Utl__encoder_mgr().Fsys_safe().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.I.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 GfoInvkAble_.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,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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.html.modules.*;
public class Xoapi_modules implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
popups.Init_by_app(app);
}
public Xoapi_collapsible Collapsible() {return collapsible;} private Xoapi_collapsible collapsible = new Xoapi_collapsible();
public Xoapi_navframe Navframe() {return navframe;} private Xoapi_navframe navframe = new Xoapi_navframe();
public Xoapi_toc Toc() {return toc;} private Xoapi_toc toc = new Xoapi_toc();
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_collapsible)) return collapsible;
else if (ctx.Match(k, Invk_navframe)) return navframe;
else if (ctx.Match(k, Invk_toc)) return toc;
else if (ctx.Match(k, Invk_popups)) return popups;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_collapsible = "collapsible", Invk_navframe = "navframe", Invk_toc = "toc", Invk_popups = "popups";
}

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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.core.btries.*;
public class Xoapi_page implements GfoInvkAble {
public Xoapi_toggle_mgr Toggle_mgr() {return toggle_mgr;} private 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 GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_toggles = "toggles";
}

View File

@@ -0,0 +1,35 @@
/*
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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.html.skins.*;
public class Xoapi_skins implements GfoInvkAble {
private Hash_adp hash = Hash_adp_.new_();
public Xoapi_skins() {
server.Sidebar_home_enabled_(true);
hash.Add("desktop", desktop);
hash.Add("server", server);
}
public Xoapi_skin_app_base Desktop() {return desktop;} private Xoapi_skin_app_base desktop = new Xoapi_skin_app_base();
public Xoapi_skin_app_base Server () {return server ;} private Xoapi_skin_app_base server = new Xoapi_skin_app_base();
private GfoInvkAble Get(String key) {return (GfoInvkAble)hash.Get_by(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get(m.ReadStr("v"));
return this;
}
private static final String Invk_get = "get";
}

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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.html.tidy.*;
public class Xoapi_tidy implements GfoInvkAble {
private Xoae_app app;
public void Init_by_kit(Xoae_app app) {
this.app = app;
}
public void Toggle() {
app.Html_mgr().Tidy_mgr().Enabled_toggle();
app.Gui_mgr().Browser_win().Page__refresh();
}
public void Engine_(byte v) {
app.Html_mgr().Tidy_mgr().Wkr_tid_(v);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_toggle)) this.Toggle();
else if (ctx.Match(k, Invk_engine_tidy_)) Engine_(Xoh_tidy_wkr_.Tid_tidy);
else if (ctx.Match(k, Invk_engine_jtidy_)) Engine_(Xoh_tidy_wkr_.Tid_jtidy);
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_toggle = "toggle", Invk_engine_tidy_ = "engine_tidy_", Invk_engine_jtidy_ = "engine_jtidy_";
}

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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
public class Xoapi_toggle_itm implements GfoInvkAble {
public Xoapi_toggle_itm(byte[] key_bry) {this.key_bry = key_bry;}
public byte[] Key_bry() {return key_bry;} private 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 Xoapi_toggle_itm Init(Xowe_wiki wiki, byte[] heading_bry) {
if (Img_src_y == null) {
Io_url img_dir = wiki.Appe().Usere().Fsys_mgr().App_img_dir().GenSubDir_nest("window", "portal");
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();
}
icon_src = visible ? Img_src_y : Img_src_n;
byte[] img_title_msg = visible ? Img_title_msg_y : Img_title_msg_n;
icon_title = wiki.Msg_mgr().Val_by_key_obj(img_title_msg);
elem_display = visible ? Img_display_y : Img_display_n;
this.heading_bry = heading_bry;
Html_toggle_gen();
return this;
}
private byte[] img_title_val_y, img_title_val_n;
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 Html_toggle_gen() {
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_(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)
;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_visible)) return Yn.Xto_str(visible);
else if (ctx.Match(k, Invk_visible_)) {this.visible = m.ReadYn("v"); Html_toggle_gen();}
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_visible = "visible", Invk_visible_ = "visible_";
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,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.apis.xowa.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.cfgs.*;
public class Xoapi_toggle_mgr implements GfoInvkAble {
private Ordered_hash hash = Ordered_hash_.new_bry_();
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(key_bry);
hash.Add(key_bry, rv);
}
return rv;
}
public void Img_dir_(Io_url v) {
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(v);
}
}
public void Save(Xoa_cfg_mgr cfg_mgr) {
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Xoapi_toggle_itm itm = (Xoapi_toggle_itm)hash.Get_at(i);
cfg_mgr.Set_by_app("xowa.api.html.page.toggles.get('" + String_.new_u8(itm.Key_bry()) + "').visible", Yn.Xto_str(itm.Visible()));
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return this.Get_or_new(m.ReadStr("key"));
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_get = "get";
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.html.*;
public class Xoapi_collapsible implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
}
public boolean Collapsed() {return collapsed;} private boolean collapsed;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_collapsed)) return Yn.Xto_str(collapsed);
else if (ctx.Match(k, Invk_collapsed_)) collapsed = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_collapsed = "collapsed", Invk_collapsed_ = "collapsed_"
;
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.html.*;
public class Xoapi_navframe implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
}
public boolean Collapsed() {return collapsed;} private boolean collapsed;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_collapsed)) return Yn.Xto_str(collapsed);
else if (ctx.Match(k, Invk_collapsed_)) collapsed = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_collapsed = "collapsed", Invk_collapsed_ = "collapsed_"
;
}

View File

@@ -0,0 +1,242 @@
/*
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.apis.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.html.*;
import gplx.xowa.html.modules.popups.*;
public class Xoapi_popups implements GfoInvkAble, GfoEvMgrOwner {
private Xoae_app app;
public Xoapi_popups() {
evMgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
public void Init_by_app(Xoae_app app) {this.app = app;}
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
public int Show_init_word_count() {return show_init_word_count;} private int show_init_word_count = Dflt_show_init_word_count;
public int Show_more_word_count() {return show_more_word_count;} private int show_more_word_count = Dflt_show_more_word_count;
public int Show_all_if_less_than() {return show_all_if_less_than;} private int show_all_if_less_than = Dflt_show_all_if_less_than;
public int Win_show_delay() {return win_show_delay;} private int win_show_delay = Dflt_win_show_delay;
public int Win_hide_delay() {return win_hide_delay;} private int win_hide_delay = Dflt_win_hide_delay;
public int Win_max_w() {return win_max_w;} private int win_max_w = Dflt_win_max_w;
public int Win_max_h() {return win_max_h;} private int win_max_h = Dflt_win_max_h;
public int Win_show_all_max_w() {return win_show_all_max_w;} private int win_show_all_max_w = Dflt_win_show_all_max_w;
public boolean Win_bind_focus_blur() {return win_bind_focus_blur;} private boolean win_bind_focus_blur = Dflt_win_bind_focus_blur;
public byte[] Xnde_ignore_ids() {return xnde_ignore_ids;} private byte[] xnde_ignore_ids = Dflt_xnde_ignore_ids;
public int Scan_len() {return scan_len;} private int scan_len = Dflt_scan_len;
public int Scan_max() {return scan_max;} private int scan_max = Dflt_scan_max;
public byte[] Ns_allowed() {return ns_allowed;} private byte[] ns_allowed = Dflt_ns_allowed;
public int Read_til_stop_fwd() {return read_til_stop_fwd;} private int read_til_stop_fwd = Dflt_read_til_stop_fwd;
public int Read_til_stop_bwd() {return read_til_stop_bwd;} private int read_til_stop_bwd = Dflt_read_til_stop_bwd;
public int Stop_if_hdr_after() {return stop_if_hdr_after;} private int stop_if_hdr_after = Dflt_stop_if_hdr_after;
public int Tmpl_tkn_max() {return tmpl_tkn_max;} private int tmpl_tkn_max = Dflt_tmpl_tkn_max;
public byte[] Tmpl_keeplist() {return tmpl_keeplist;} private byte[] tmpl_keeplist = Dflt_tmpl_keeplist;
public byte[] Html_fmtr_popup() {return html_fmtr_popup;} private byte[] html_fmtr_popup = Dflt_html_fmtr_popup;
public byte[] Html_fmtr_popup_dflt() {return html_fmtr_popup_dflt;} private byte[] html_fmtr_popup_dflt = Dflt_html_fmtr_popup;
public byte[] Html_fmtr_viewed() {return html_fmtr_viewed;} private byte[] html_fmtr_viewed = Dflt_html_fmtr_viewed;
public byte[] Html_fmtr_viewed_dflt() {return html_fmtr_viewed_dflt;} private byte[] html_fmtr_viewed_dflt = Dflt_html_fmtr_viewed;
public byte[] Html_fmtr_wiki() {return html_fmtr_wiki;} private byte[] html_fmtr_wiki = Dflt_html_fmtr_wiki;
public byte[] Html_fmtr_wiki_dflt() {return html_fmtr_wiki_dflt;} private byte[] html_fmtr_wiki_dflt = Dflt_html_fmtr_wiki;
public byte[] Html_fmtr_next_sect_fmt() {return html_fmtr_next_sect;} private byte[] html_fmtr_next_sect = Dflt_html_fmtr_next_sect;
public byte[] Html_fmtr_next_sect_fmt_dflt() {return html_fmtr_next_sect_dflt;} private byte[] html_fmtr_next_sect_dflt = Dflt_html_fmtr_next_sect;
public void Show_more(String popup_id) {
Xowe_wiki wiki = app.Gui_mgr().Browser_win().Active_tab().Wiki();
wiki.Html_mgr().Module_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().Module_mgr().Popup_mgr().Show_all(popup_id);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else 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 if (ctx.Match(k, Invk_show_init_word_count)) return show_init_word_count;
else if (ctx.Match(k, Invk_show_init_word_count_)) {show_init_word_count = Set_int_gt_0(m, show_init_word_count, Evt_show_init_word_count_changed);}
else if (ctx.Match(k, Invk_show_more_word_count)) return show_more_word_count;
else if (ctx.Match(k, Invk_show_more_word_count_)) {show_more_word_count = Set_int_gt_0(m, show_more_word_count, Evt_show_more_word_count_changed);}
else if (ctx.Match(k, Invk_show_all_if_less_than)) return show_all_if_less_than;
else if (ctx.Match(k, Invk_show_all_if_less_than_)) {show_all_if_less_than = Set_int(m, show_all_if_less_than, Evt_show_all_if_less_than_changed);}
else if (ctx.Match(k, Invk_win_show_delay)) return win_show_delay;
else if (ctx.Match(k, Invk_win_show_delay_)) {win_show_delay = Set_int(m, win_show_delay, Evt_win_show_delay_changed);}
else if (ctx.Match(k, Invk_win_hide_delay)) return win_hide_delay;
else if (ctx.Match(k, Invk_win_hide_delay_)) {win_hide_delay = Set_int(m, win_hide_delay, Evt_win_hide_delay_changed);}
else if (ctx.Match(k, Invk_win_max_w)) return win_max_w;
else if (ctx.Match(k, Invk_win_max_w_)) {win_max_w = Set_int(m, win_max_w, Evt_win_max_w_changed);}
else if (ctx.Match(k, Invk_win_max_h)) return win_max_h;
else if (ctx.Match(k, Invk_win_max_h_)) {win_max_h = Set_int(m, win_max_h, Evt_win_max_h_changed);}
else if (ctx.Match(k, Invk_win_show_all_max_w)) return win_show_all_max_w;
else if (ctx.Match(k, Invk_win_show_all_max_w_)) {win_show_all_max_w = m.ReadInt("v");}
else if (ctx.Match(k, Invk_win_bind_focus_blur)) return Yn.Xto_str(win_bind_focus_blur);
else if (ctx.Match(k, Invk_win_bind_focus_blur_)) win_bind_focus_blur = m.ReadYn("v");
else if (ctx.Match(k, Invk_xnde_ignore_ids)) return String_.new_u8(xnde_ignore_ids);
else if (ctx.Match(k, Invk_xnde_ignore_ids_)) {xnde_ignore_ids = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_xnde_ignore_ids_changed, xnde_ignore_ids);}
else if (ctx.Match(k, Invk_scan_len)) return scan_len;
else if (ctx.Match(k, Invk_scan_len_)) {scan_len = Set_int_gt_0(m, scan_len, Evt_scan_len_changed);}
else if (ctx.Match(k, Invk_scan_max)) return scan_max;
else if (ctx.Match(k, Invk_scan_max_)) {scan_max = Set_int_gt_0(m, scan_max, Evt_scan_max_changed);}
else if (ctx.Match(k, Invk_read_til_stop_fwd)) return read_til_stop_fwd;
else if (ctx.Match(k, Invk_read_til_stop_fwd_)) {read_til_stop_fwd = m.ReadInt("v"); GfoEvMgr_.PubVal(this, Evt_read_til_stop_fwd_changed, read_til_stop_fwd);}
else if (ctx.Match(k, Invk_read_til_stop_bwd)) return read_til_stop_bwd;
else if (ctx.Match(k, Invk_read_til_stop_bwd_)) {read_til_stop_bwd = m.ReadInt("v"); GfoEvMgr_.PubVal(this, Evt_read_til_stop_bwd_changed, read_til_stop_bwd);}
else if (ctx.Match(k, Invk_stop_if_hdr_after)) return stop_if_hdr_after;
else if (ctx.Match(k, Invk_stop_if_hdr_after_)) {stop_if_hdr_after = m.ReadInt("v"); GfoEvMgr_.PubVal(this, Evt_stop_if_hdr_after_changed, stop_if_hdr_after);}
else if (ctx.Match(k, Invk_ns_allowed)) return String_.new_u8(ns_allowed);
else if (ctx.Match(k, Invk_ns_allowed_)) {ns_allowed = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_ns_allowed_changed, ns_allowed);}
else if (ctx.Match(k, Invk_tmpl_tkn_max)) return tmpl_tkn_max;
else if (ctx.Match(k, Invk_tmpl_tkn_max_)) {tmpl_tkn_max = m.ReadInt("v"); GfoEvMgr_.PubVal(this, Evt_tmpl_tkn_max_changed, tmpl_tkn_max);}
else if (ctx.Match(k, Invk_tmpl_keeplist)) return String_.new_u8(tmpl_keeplist);
else if (ctx.Match(k, Invk_tmpl_keeplist_)) {tmpl_keeplist = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_tmpl_keeplist_changed, tmpl_keeplist);}
else if (ctx.Match(k, Invk_html_fmtr_popup)) return String_.new_u8(html_fmtr_popup);
else if (ctx.Match(k, Invk_html_fmtr_popup_)) {html_fmtr_popup = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_html_fmtr_popup_changed, html_fmtr_popup);}
else if (ctx.Match(k, Invk_html_fmtr_popup_dflt)) return String_.new_u8(html_fmtr_popup_dflt);
else if (ctx.Match(k, Invk_html_fmtr_popup_dflt_)) {html_fmtr_popup_dflt = m.ReadBry("v");}
else if (ctx.Match(k, Invk_html_fmtr_viewed)) return String_.new_u8(html_fmtr_viewed);
else if (ctx.Match(k, Invk_html_fmtr_viewed_)) {html_fmtr_viewed = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_html_fmtr_viewed_changed, html_fmtr_viewed);}
else if (ctx.Match(k, Invk_html_fmtr_viewed_dflt)) return String_.new_u8(html_fmtr_viewed_dflt);
else if (ctx.Match(k, Invk_html_fmtr_viewed_dflt_)) {html_fmtr_viewed_dflt = m.ReadBry("v");}
else if (ctx.Match(k, Invk_html_fmtr_wiki)) return String_.new_u8(html_fmtr_wiki);
else if (ctx.Match(k, Invk_html_fmtr_wiki_)) {html_fmtr_wiki = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_html_fmtr_wiki_changed, html_fmtr_wiki);}
else if (ctx.Match(k, Invk_html_fmtr_wiki_dflt)) return String_.new_u8(html_fmtr_wiki_dflt);
else if (ctx.Match(k, Invk_html_fmtr_wiki_dflt_)) {html_fmtr_wiki_dflt = m.ReadBry("v");}
else if (ctx.Match(k, Invk_html_fmtr_next_sect)) return String_.new_u8(html_fmtr_next_sect);
else if (ctx.Match(k, Invk_html_fmtr_next_sect_)) {html_fmtr_next_sect = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_html_fmtr_next_sect_changed, html_fmtr_next_sect);}
else if (ctx.Match(k, Invk_html_fmtr_next_sect_dflt)) return String_.new_u8(html_fmtr_next_sect_dflt);
else if (ctx.Match(k, Invk_html_fmtr_next_sect_dflt_)) {html_fmtr_next_sect_dflt = m.ReadBry("v");}
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private int Set_int_gt_0(GfoMsg m, int cur_val, String evt) {
int tmp = m.ReadInt("v");
if (tmp < 1) return cur_val;
GfoEvMgr_.PubVal(this, evt, tmp);
return tmp;
}
private int Set_int(GfoMsg m, int cur_val, String evt) {
int tmp = m.ReadInt("v");
GfoEvMgr_.PubVal(this, evt, tmp);
return tmp;
}
private static final String
Invk_enabled = "enabled", Invk_enabled_ = "enabled_"
, Invk_show_init_word_count = "show_init_word_count", Invk_show_init_word_count_ = "show_init_word_count_"
, Invk_show_more_word_count = "show_more_word_count", Invk_show_more_word_count_ = "show_more_word_count_"
, Invk_show_all_if_less_than = "show_all_if_less_than", Invk_show_all_if_less_than_ = "show_all_if_less_than_"
, Invk_xnde_ignore_ids = "xnde_ignore_ids", Invk_xnde_ignore_ids_ = "xnde_ignore_ids_"
, Invk_scan_len = "scan_len", Invk_scan_len_ = "scan_len_"
, Invk_scan_max = "scan_max", Invk_scan_max_ = "scan_max_"
, Invk_show_more = "show_more", Invk_show_all = "show_all"
, Invk_html_fmtr_popup = "html_fmtr_popup" , Invk_html_fmtr_popup_ = "html_fmtr_popup"
, Invk_html_fmtr_viewed = "html_fmtr_viewed" , Invk_html_fmtr_viewed_ = "html_fmtr_viewed_"
, Invk_html_fmtr_wiki = "html_fmtr_wiki" , Invk_html_fmtr_wiki_ = "html_fmtr_wiki_"
, Invk_html_fmtr_next_sect = "html_fmtr_next_sect" , Invk_html_fmtr_next_sect_ = "html_fmtr_next_sect_"
, Invk_html_fmtr_popup_dflt = "html_fmtr_popup_dflt" , Invk_html_fmtr_popup_dflt_ = "html_fmtr_popup_dflt_"
, Invk_html_fmtr_viewed_dflt = "html_fmtr_viewed_dflt" , Invk_html_fmtr_viewed_dflt_ = "html_fmtr_viewed_dflt_"
, Invk_html_fmtr_wiki_dflt = "html_fmtr_wiki_dflt" , Invk_html_fmtr_wiki_dflt_ = "html_fmtr_wiki_dflt_"
, Invk_html_fmtr_next_sect_dflt = "html_fmtr_next_sect_dflt" , Invk_html_fmtr_next_sect_dflt_ = "html_fmtr_next_sect_dflt_"
, Invk_win_show_delay = "win_show_delay", Invk_win_show_delay_ = "win_show_delay_"
, Invk_win_hide_delay = "win_hide_delay", Invk_win_hide_delay_ = "win_hide_delay_"
, Invk_win_bind_focus_blur = "win_bind_focus_blur", Invk_win_bind_focus_blur_ = "win_bind_focus_blur_"
, Invk_win_max_w = "win_max_w", Invk_win_max_w_ = "win_max_w_"
, Invk_win_max_h = "win_max_h", Invk_win_max_h_ = "win_max_h_"
, Invk_win_show_all_max_w = "win_show_all_max_w", Invk_win_show_all_max_w_ = "win_show_all_max_w_"
, Invk_read_til_stop_fwd = "read_til_stop_fwd", Invk_read_til_stop_fwd_ = "read_til_stop_fwd_"
, Invk_read_til_stop_bwd = "read_til_stop_bwd", Invk_read_til_stop_bwd_ = "read_til_stop_bwd_"
, Invk_stop_if_hdr_after = "stop_if_hdr_after", Invk_stop_if_hdr_after_ = "stop_if_hdr_after_"
, Invk_ns_allowed = "ns_allowed", Invk_ns_allowed_ = "ns_allowed_"
, Invk_tmpl_tkn_max = "tmpl_tkn_max", Invk_tmpl_tkn_max_ = "tmpl_tkn_max_"
, Invk_tmpl_keeplist = "tmpl_keeplist", Invk_tmpl_keeplist_ = "tmpl_keeplist_"
;
public static final String
Evt_show_init_word_count_changed = "show_init_word_count_changed"
, Evt_show_more_word_count_changed = "show_more_word_count_changed"
, Evt_show_all_if_less_than_changed = "show_all_if_less_than_changed"
, Evt_win_show_delay_changed = "win_show_delay_changed"
, Evt_win_hide_delay_changed = "win_hide_delay_changed"
, Evt_win_max_w_changed = "win_max_w_changed"
, Evt_win_max_h_changed = "win_max_h_changed"
, Evt_xnde_ignore_ids_changed = "xnde_ignore_ids_changed"
, Evt_scan_len_changed = "scan_len_changed"
, Evt_scan_max_changed = "scan_max_changed"
, Evt_read_til_stop_fwd_changed = "read_til_stop_fwd_changed"
, Evt_read_til_stop_bwd_changed = "read_til_stop_bwd_changed"
, Evt_stop_if_hdr_after_changed = "stop_if_hdr_after_changed"
, Evt_ns_allowed_changed = "ns_allowed_changed"
, Evt_tmpl_tkn_max_changed = "tmpl_tkn_max_changed"
, Evt_tmpl_keeplist_changed = "tmpl_keeplist"
, Evt_html_fmtr_popup_changed = "html_fmtr_popup_changed"
, Evt_html_fmtr_viewed_changed = "html_fmtr_viewed_changed"
, Evt_html_fmtr_wiki_changed = "html_fmtr_wiki_changed"
, Evt_html_fmtr_next_sect_changed = "html_fmtr_next_sect_changed"
;
public static final byte[]
Dflt_xnde_ignore_ids = Bry_.new_a7("coordinates")
, Dflt_tmpl_keeplist = Bry_.new_a7("en.wikipedia.org|formatnum;age;age_in_days;age_in_years_and_days*;nts;number_table_sorting*;as_of;oldstyledatedy;gregorian_serial_date;currentminute;currentsecond;dmca;spaced_ndash;trim;month*;convert*;worldpop*;ipa*;lang*;nowrap*;h:*;mvar;math;vgy;audio;iso_639_name;transl;translate;linktext;zh;nihongo*;japanese_name;ko-hhrm;mp|\n")
, Dflt_html_fmtr_popup = Bry_.new_a7(String_.Concat_lines_nl_skip_last
( "<div dir=~{page_lang_ltr}>"
, " <div>~{content}"
, " </div>"
, " <hr/>"
, " <div>"
, " <span class='data_val'><b>~{page_title}</b></span>~{wiki_item}"
, " <span class='data_key'>~{<>msgs.get('api-xowa.html.modules.popups.msgs.size-name');<>}</span><span class='data_val'>~{page_size}</span>"
, " <span class='data_key'>~{<>msgs.get('api-xowa.html.modules.popups.msgs.edited-name');<>}</span><span class='data_val'>~{edit_time}</span>~{view_time_item}"
, " </div>"
, " <hr/>"
, " <div style='float:bottom;'>"
, " <span><a href='xowa-cmd:xowa.api.nav.goto(\"~{page_url}\");' title='~{<>msgs.get('api-xowa.gui.browser.url.exec-name');<>}'><img src='~{xowa_root_dir}user/anonymous/app/img/window/menu/page/open.png'></a></span>"
, " <span><a href='xowa-cmd:xowa.api.gui.browser.tabs.new_link__at_dflt__focus_y(\"~{page_url}\");' title='~{<>msgs.get('api-xowa.gui.browser.tabs.new_link__at_dflt__focus_y-name');<>}'><img src='~{xowa_root_dir}user/anonymous/app/img/window/menu/tabs/new.png'></a></span>"
, " <span><a href='xowa-cmd:xowa.api.gui.browser.tabs.new_link__at_dflt__focus_n(\"~{page_url}\");' title='~{<>msgs.get('api-xowa.gui.browser.tabs.new_link__at_dflt__focus_n-name');<>}'><img src='~{xowa_root_dir}user/anonymous/app/img/window/menu/tabs/new_background.png'></a></span>"
, " <span><a href='xowa-cmd:xowa.api.usr.bookmarks.add(\"~{page_url}\");' title='~{<>msgs.get('api-xowa.usr.bookmarks.add-name');<>}'><img src='~{xowa_root_dir}user/anonymous/app/img/window/menu/bookmarks/add.png'></a></span>"
, " <span><a href='xowa-cmd:xowa.api.html.modules.popups.show_more(\"~{popup_id}\");' title='~{<>msgs.get('api-xowa.html.modules.popups.show_more-tip');<>}'><img src='~{xowa_root_dir}bin/any/xowa/html/res/src/xowa/popups/imgs/show_more.png'></a></span>"
, " <span><a href='xowa-cmd:xowa.api.html.modules.popups.show_all (\"~{popup_id}\");' title='~{<>msgs.get('api-xowa.html.modules.popups.show_all-tip');<>}'> <img src='~{xowa_root_dir}bin/any/xowa/html/res/src/xowa/popups/imgs/show_all.png' ></a></span>"
, " <span><a href='/wiki/Special:XowaPopupHistory' title='~{<>msgs.get('api-xowa.html.modules.popups.history-tip');<>}'><img src='~{xowa_root_dir}user/anonymous/app/img/window/menu/history/show.png'></a></span>"
, " <span><a href='xowa-cmd:xowa.api.gui.browser.tabs.new_link__at_dflt__focus_y(\"home/wiki/Help:Options/Popups\");' title='~{<>msgs.get('api-xowa.nav.cfg.main-name');<>}'><img src='~{xowa_root_dir}user/anonymous/app/img/window/menu/tools/options.png'></a></span>"
, " </div>"
, "</div>"
))
, Dflt_html_fmtr_viewed = Bry_.new_a7("\n <span class='data_key'>~{<>msgs.get('api-xowa.html.modules.popups.msgs.view_time-name');<>}</span><span class='data_val'>~{viewed_val}</span>")
, Dflt_html_fmtr_wiki = Bry_.new_a7("\n <span class='data_key'>~{<>msgs.get('api-xowa.html.modules.popups.msgs.wiki-name');<>}</span><span class='data_val'>~{wiki_val}</span>")
, Dflt_html_fmtr_next_sect = Bry_.new_a7("\n\n<span class='next_sect'>~{<>msgs.get('api-xowa.html.modules.popups.msgs.next_sect-name');<>}~{next_sect_val}</span>")
;
public static final String[]
Dflt_html_fmtr_popup_keys = String_.Ary("content", "page_lang_ltr", "page_url", "page_title", "popup_id", "wiki_item", "page_size", "edit_time", "view_time_item", "xowa_root_dir")
, Dflt_html_fmtr_viewed_keys = String_.Ary("viewed_val")
, Dflt_html_fmtr_wiki_keys = String_.Ary("wiki_val")
, Dflt_html_fmtr_next_sect_keys = String_.Ary("next_sect_val")
;
public static final byte[]
Dflt_ns_allowed = Bry_.Empty
;
public static final int
Dflt_show_init_word_count = 128
, Dflt_show_more_word_count = 192
, Dflt_show_all_if_less_than = -1
, Dflt_show_all_win_max_w = -1
, Dflt_win_show_delay = 600, Dflt_win_hide_delay = 400
, Dflt_win_max_w = -1, Dflt_win_max_h = -1
, Dflt_win_show_all_max_w = 800
, Dflt_scan_len = 1 * Io_mgr.Len_kb
, Dflt_scan_max = 32 * Io_mgr.Len_kb
, Dflt_read_til_stop_fwd = 32
, Dflt_read_til_stop_bwd = 16
, Dflt_stop_if_hdr_after = 96
, Dflt_tmpl_tkn_max = 8 * Io_mgr.Len_kb
;
public static final boolean
Dflt_win_bind_focus_blur = false
;
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apis.xowa.html.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.html.*;
public class Xoapi_toc implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
}
public boolean Collapsed() {return collapsed;} private boolean collapsed = false;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_collapsed)) return Yn.Xto_str(collapsed);
else if (ctx.Match(k, Invk_collapsed_)) collapsed = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_collapsed = "collapsed", Invk_collapsed_ = "collapsed_"
;
}

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.apis.xowa.html.skins; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.html.*;
public class Xoapi_skin_app_base implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
}
public boolean Sidebar_home_enabled() {return sidebar_home_enabled;} public void Sidebar_home_enabled_(boolean v) {sidebar_home_enabled = v;} private boolean sidebar_home_enabled;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_sidebar_home_enabled)) return Yn.Xto_str(sidebar_home_enabled);
else if (ctx.Match(k, Invk_sidebar_home_enabled_)) sidebar_home_enabled = m.ReadYn("v");
return this;
}
private static final String Invk_sidebar_home_enabled = "sidebar_home_enabled", Invk_sidebar_home_enabled_ = "sidebar_home_enabled_";
}

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.apis.xowa.navs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.gui.views.*;
import gplx.xowa.html.hrefs.*;
public class Xoapi_wiki implements GfoInvkAble {
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_parser.Href_wiki_str); // 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 GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_main_page = "main_page", Invk_random = "random", Invk_sandbox = "sandbox";
}

View File

@@ -0,0 +1,73 @@
/*
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.apis.xowa.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.crts.*;
public class Xoapi_search implements GfoInvkAble, GfoEvMgrOwner {
private final Xow_domain_crt_kv_itm_mgr multi_wikis_mgr = new Xow_domain_crt_kv_itm_mgr(); private byte[] multi_wikis_bry = Dflt_multi_wikis_bry;
private final Xow_domain_crt_kv_itm_mgr multi_sorts_mgr = new Xow_domain_crt_kv_itm_mgr(); private byte[] multi_sorts_bry = Dflt_multi_sorts_bry;
public Xoapi_search() {
this.evMgr = GfoEvMgr.new_(this);
multi_wikis_mgr.Parse_as_itms(multi_wikis_bry);
multi_sorts_mgr.Parse_as_arys(multi_sorts_bry);
}
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
public int Results_per_page() {return results_per_page;} private int results_per_page = 20;
public boolean Async_db() {return async_db;} private boolean async_db = true;
public void Multi_wikis_bry_(byte[] v) {
if (!multi_wikis_mgr.Parse_as_itms(v)) return;
this.multi_wikis_bry = v;
GfoEvMgr_.PubVal(this, Evt_multi_wikis_changed, v);
}
public Xow_domain_crt_itm Multi_wikis_crt(Xow_domain cur_domain) {
return multi_wikis_mgr.Find_itm(cur_domain, cur_domain);
}
public void Multi_sorts_bry_(byte[] v) {
if (!multi_sorts_mgr.Parse_as_arys(v)) return;
this.multi_sorts_bry = v;
GfoEvMgr_.PubVal(this, Evt_multi_sorts_changed, v);
}
public Xow_domain_crt_itm[] Multi_sorts_crt(Xow_domain cur_domain) {
return multi_sorts_mgr.Find_ary(cur_domain, cur_domain);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_results_per_page)) return results_per_page;
else if (ctx.Match(k, Invk_results_per_page_)) results_per_page = m.ReadInt("v");
else if (ctx.Match(k, Invk_async_db)) return Yn.Xto_str(async_db);
else if (ctx.Match(k, Invk_async_db_)) async_db = m.ReadYn("v");
else if (ctx.Match(k, Invk_multi_wikis)) return String_.new_u8(multi_wikis_bry);
else if (ctx.Match(k, Invk_multi_wikis_)) Multi_wikis_bry_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_multi_sorts)) return String_.new_u8(multi_sorts_bry);
else if (ctx.Match(k, Invk_multi_sorts_)) Multi_sorts_bry_(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_results_per_page = "results_per_page" , Invk_results_per_page_ = "results_per_page_"
, Invk_async_db = "async_db" , Invk_async_db_ = "async_db_"
, Invk_multi_wikis = "multi_wikis" , Invk_multi_wikis_ = "multi_wikis_"
, Invk_multi_sorts = "multi_sorts" , Invk_multi_sorts_ = "multi_sorts_"
;
public static final String
Evt_multi_wikis_changed = "multi_wikis_changed"
, Evt_multi_sorts_changed = "multi_sorts_changed"
;
public static final byte[]
Dflt_multi_wikis_bry = Bry_.new_a7("<any>|<self>")
, Dflt_multi_sorts_bry = Bry_.new_a7("<any>|<self>,*.wikipedia,*.wikivoyage,*.wiktionary,*.wikisource,*.wikiquote,*.wikibooks,*.wikiversity,*.wikinews")
;
}

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.apis.xowa.startups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.apis.xowa.startups.tabs.*;
public class Xoapi_startups implements GfoInvkAble {
public void Init_by_kit(Xoae_app app) {
}
public Xoapi_startup_tabs Tabs() {return tabs;} private Xoapi_startup_tabs tabs = new Xoapi_startup_tabs();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_tabs)) return tabs;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_tabs = "tabs";
}

View File

@@ -0,0 +1,87 @@
/*
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.apis.xowa.startups.tabs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.startups.*;
import gplx.xowa.specials.*;
public class Xoapi_startup_tabs implements GfoInvkAble {
public String Custom() {return custom;} private String custom;
public boolean Custom_is_expr() {return custom_is_expr;} private boolean custom_is_expr;
public String Previous() {return previous;} private String previous;
public String Manual() {return manual;} public void Manual_(String v) {manual = v;} private String manual;
public byte Type() {return type;} private byte type = Xoapi_startup_tabs_tid_.Tid_previous;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_type)) return Xoapi_startup_tabs_tid_.Xto_key(type);
else if (ctx.Match(k, Invk_type_)) type = Xoapi_startup_tabs_tid_.Xto_tid(m.ReadStr("v"));
else if (ctx.Match(k, Invk_type_list)) return Xoapi_startup_tabs_tid_.Options__list;
else if (ctx.Match(k, Invk_previous)) return previous;
else if (ctx.Match(k, Invk_previous_)) previous = m.ReadStr("v");
else if (ctx.Match(k, Invk_custom)) return custom;
else if (ctx.Match(k, Invk_custom_)) custom = m.ReadStr("v");
else if (ctx.Match(k, Invk_custom_is_expr)) return Yn.Xto_str(custom_is_expr);
else if (ctx.Match(k, Invk_custom_is_expr_)) custom_is_expr = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_type = "type", Invk_type_ = "type_", Invk_type_list = "type_list"
, Invk_custom = "custom", Invk_custom_ = "custom_"
, Invk_previous = "previous", Invk_previous_ = "previous_"
, Invk_custom_is_expr = "custom_is_expr", Invk_custom_is_expr_ = "custom_is_expr_"
;
public String[] Calc_startup_strs(Xoae_app app) {
List_adp rv = List_adp_.new_();
String xowa_home = gplx.xowa.users.Xouc_pages_mgr.Page_xowa;
if (manual == null) {
switch (type) {
case Xoapi_startup_tabs_tid_.Tid_blank: rv.Add(Xows_special_meta_.Itm__default_tab.Ttl_str()); break;
case Xoapi_startup_tabs_tid_.Tid_xowa: rv.Add(xowa_home); break;
case Xoapi_startup_tabs_tid_.Tid_custom: Add_ary(rv, custom); break;
case Xoapi_startup_tabs_tid_.Tid_previous: Add_ary(rv, previous); break;
default: throw Exc_.new_unhandled(type);
}
}
else
rv.Add(manual);
Add_xowa_home_if_new_version(rv, app, xowa_home);
return rv.To_str_ary();
}
private static void Add_ary(List_adp list, String s) {
if (String_.Len_eq_0(s)) return;
String[] ary = String_.SplitLines_nl(String_.Trim(s));
int len = ary.length;
for (int i = 0; i < len; ++i) {
String itm = ary[i];
if (String_.Len_eq_0(itm)) continue;
list.Add(itm);
}
}
private static void Add_xowa_home_if_new_version(List_adp rv, Xoae_app app, String xowa_home) {
if (gplx.xowa.apps.versions.Xoa_version_.Compare(app.Api_root().App().Env().Version_previous(), Xoa_app_.Version) == CompareAble_.Less) {
boolean xowa_home_exists = false;
int len = rv.Count();
for (int i = 0; i < len; ++i) {
String itm = (String)rv.Get_at(i);
if (String_.Eq(itm, xowa_home)) {
xowa_home_exists = true;
break;
}
}
if (!xowa_home_exists)
rv.Add(xowa_home);
}
}
}

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.apis.xowa.startups.tabs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.startups.*;
public class Xoapi_startup_tabs_tid_ {
public static final byte Tid_blank = 0, Tid_xowa = 1, Tid_previous = 2, Tid_custom = 3;
public static final String Key_blank = "blank", Key_xowa = "xowa", Key_previous = "previous", Key_custom = "custom";
public static String Xto_key(byte v) {
switch (v) {
case Tid_blank: return Key_blank;
case Tid_xowa: return Key_xowa;
case Tid_previous: return Key_previous;
case Tid_custom: return Key_custom;
default: throw Exc_.new_unimplemented();
}
}
public static byte Xto_tid(String s) {
if (String_.Eq(s, Key_blank)) return Tid_blank;
else if (String_.Eq(s, Key_xowa)) return Tid_xowa;
else if (String_.Eq(s, Key_previous)) return Tid_previous;
else if (String_.Eq(s, Key_custom)) return Tid_custom;
else throw Exc_.new_unimplemented();
}
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_(Key_blank), KeyVal_.new_(Key_xowa), KeyVal_.new_(Key_previous), KeyVal_.new_(Key_custom));
}

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.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.gui.history.*; import gplx.xowa.gui.views.*;
import gplx.xowa.users.bmks.*;
public class Xoapi_bookmarks implements GfoInvkAble {
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 boolean Enabled() {return enabled;} private boolean enabled = true;
public void Enabled_(boolean v) {enabled = v;}
public void Add(String url_str) {
if (!enabled) return;
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
Xowe_wiki wiki = tab.Wiki(); Xoae_page page = tab.Page();
byte[] wiki_domain = null, ttl_full_txt = null;
if (url_str == null) {
wiki_domain = wiki.Domain_bry();
ttl_full_txt = page.Ttl().Full_txt();
}
else {
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(app, wiki, url_str);
wiki_domain = url.Wiki_bry();
ttl_full_txt = url.Page_bry();
}
app.Usere().Bookmarks_add(wiki_domain, ttl_full_txt);
app.Usr_dlg().Prog_many("", "", "bookmark added: ~{0}", String_.new_u8(ttl_full_txt));
}
public void Show() {win.Page__navigate_by_url_bar("home/wiki/Data:Bookmarks");}
// public void Add(String url_str) {// bmk_v2
// Xoa_url url = null;
// if (url_str == null) {
// Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
// url = tab.Page().Url();
// }
// else
// url = app.Utl__url_parser().Parse(Bry_.new_u8(url_str));
// app.User().User_db_mgr().Bmk_mgr().Itms__add(Xoud_bmk_mgr.Owner_root, url);
// }
// public void Show() {win.Page__navigate_by_url_bar("home/wiki/Special:XowaBookmarks");}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(this.Enabled());
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_add)) this.Add(m.ReadStrOr("v", null));
else if (ctx.Match(k, Invk_show)) this.Show();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_add = "add", Invk_show = "show";
}

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.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.ios.*; import gplx.xowa.files.caches.*;
public class Xoapi_cache implements GfoInvkAble {
private Xou_cache_mgr cache_mgr;
public void Init_by_app(Xoa_app app) {this.cache_mgr = app.User().User_db_mgr().Cache_mgr();}
private String Info() {
cache_mgr.Page_bgn();
Bry_bfr bfr = Bry_bfr.new_(255);
KeyVal[] ary = cache_mgr.Info();
int len = ary.length;
for (int i = 0; i < len; ++i) {
KeyVal kv = ary[i];
bfr.Add_str_a7(kv.Key()).Add_str_a7(": ").Add_str_u8(kv.Val_to_str_or_empty()).Add_byte_nl();
}
return bfr.Xto_str_and_clear();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_fsys_size_min)) return cache_mgr.Fsys_size_min() / Io_mgr.Len_mb;
else if (ctx.Match(k, Invk_fsys_size_min_)) cache_mgr.Fsys_size_min_(Io_size_.To_long_by_msg_mb(m, cache_mgr.Fsys_size_min()));
else if (ctx.Match(k, Invk_fsys_size_max)) return cache_mgr.Fsys_size_max() / Io_mgr.Len_mb;
else if (ctx.Match(k, Invk_fsys_size_max_)) cache_mgr.Fsys_size_max_(Io_size_.To_long_by_msg_mb(m, cache_mgr.Fsys_size_max()));
else if (ctx.Match(k, Invk_info)) return Info();
else if (ctx.Match(k, Invk_reduce_to_min)) cache_mgr.Reduce(cache_mgr.Fsys_size_min());
else if (ctx.Match(k, Invk_reduce_to_zero)) cache_mgr.Reduce(0);
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_fsys_size_min = "fsys_size_min" , Invk_fsys_size_min_ = "fsys_size_min_"
, Invk_fsys_size_max = "fsys_size_max" , Invk_fsys_size_max_ = "fsys_size_max_"
, Invk_info = "info"
, Invk_reduce_to_min = "reduce_to_min" , Invk_reduce_to_zero = "reduce_to_zero"
;
}

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.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.gui.views.*;
public class Xoapi_history implements GfoInvkAble {
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 boolean Enabled() {return enabled;} private boolean enabled = true;
public void Enabled_(boolean v) {enabled = v;}
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_enabled)) return Yn.Xto_str(this.Enabled());
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else if (ctx.Match(k, Invk_goto_recent)) this.Goto_recent();
else if (ctx.Match(k, Invk_show)) this.Show();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_goto_recent = "goto_recent", Invk_show = "show";
}

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.apis.xowa.usrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.gui.views.*;
public class Xoapi_logs implements GfoInvkAble {
private Xoae_app app;
public void Ctor_by_app(Xoae_app app) {this.app = app;}
public void Init_by_kit(Xoae_app app) {}
public boolean Enabled() {return app.Log_wtr().Enabled();}
public void Enabled_(boolean v) {
app.Log_wtr().Enabled_(v);
if (!v)
Io_mgr.I.DeleteFil_args(app.Log_wtr().Session_fil()).MissingFails_off().Exec();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(this.Enabled());
else if (ctx.Match(k, Invk_enabled_)) Enabled_(m.ReadYn("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
}

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.apis.xowa.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*;
public class Xoapi_scribunto implements GfoInvkAble {
private Xoae_app app;
public void Init_by_kit(Xoae_app app) {
this.app = app;
}
public void Engine_(byte v) {
Scrib_xtn_mgr scrib_xtn = (Scrib_xtn_mgr)app.Xtn_mgr().Get_or_fail(Scrib_xtn_mgr.XTN_KEY);
scrib_xtn.Engine_type_(v);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_engine_lua_)) Engine_(Scrib_engine_type.Type_lua);
else if (ctx.Match(k, Invk_engine_luaj_)) Engine_(Scrib_engine_type.Type_luaj);
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_engine_lua_ = "engine_lua_", Invk_engine_luaj_ = "engine_luaj_"
;
}

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.apis.xowa.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
import gplx.xowa.xtns.wdatas.*;
public class Xoapi_wikibase implements GfoInvkAble, GfoEvMgrOwner {
public Xoapi_wikibase() {
evMgr = GfoEvMgr.new_(this);
}
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
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 Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_core_langs)) return Bry_.Add_w_dlm(Byte_ascii.Semic, core_langs);
else if (ctx.Match(k, Invk_core_langs_)) {core_langs = m.ReadBryAry(k, Byte_ascii.Semic); GfoEvMgr_.PubVal(this, Evt_core_langs_changed, core_langs);}
else if (ctx.Match(k, Invk_sort_langs)) return Bry_.Add_w_dlm(Byte_ascii.Semic, sort_langs);
else if (ctx.Match(k, Invk_sort_langs_)) {sort_langs = m.ReadBryAry(k, Byte_ascii.Semic); GfoEvMgr_.PubVal(this, Evt_sort_langs_changed, sort_langs);}
else if (ctx.Match(k, Invk_link_wikis)) return String_.new_u8(link_wikis);
else if (ctx.Match(k, Invk_link_wikis_)) {link_wikis = m.ReadBry(k); GfoEvMgr_.PubVal(this, Evt_link_wikis_changed, link_wikis);}
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_core_langs = "core_langs", Invk_core_langs_ = "core_langs_"
, Invk_sort_langs = "sort_langs", Invk_sort_langs_ = "sort_langs_"
, Invk_link_wikis = "link_wikis", Invk_link_wikis_ = "link_wikis_"
;
public static final String
Evt_core_langs_changed = "core_langs_changed"
, Evt_link_wikis_changed = "link_wikis_changed"
, Evt_sort_langs_changed = "sort_langs_changed"
;
}

View File

@@ -0,0 +1,35 @@
/*
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_app_type {
Xoa_app_type(int uid) {this.uid = uid;}
public int Uid() {return uid;} private final int uid;
public boolean Uid_is_gui() {return uid == Uid_gui;}
public boolean Uid_is_tcp() {return uid == Uid_tcp;}
public boolean Uid_is_http() {return uid == Uid_http;}
private static final int Uid_cmd = 1, Uid_gui = 2, Uid_tcp = 3, Uid_http = 4;
private static final String Key_cmd = "cmd", Key_gui = "gui", Key_tcp = "server", Key_http = "http_server";
public static final Xoa_app_type Itm_cmd = new Xoa_app_type(Uid_cmd), Itm_gui = new Xoa_app_type(Uid_gui), Itm_tcp = new Xoa_app_type(Uid_tcp), Itm_http = new Xoa_app_type(Uid_http);
public static Xoa_app_type parse(String s) {
if (String_.Eq(s, Key_cmd)) return Itm_cmd;
else if (String_.Eq(s, Key_gui)) return Itm_gui;
else if (String_.Eq(s, Key_tcp)) return Itm_tcp;
else if (String_.Eq(s, Key_http)) return Itm_http;
else return Itm_cmd; // default to cmd as per early behaviour; handles mistaken "--app_mode wrong"
}
}

View File

@@ -0,0 +1,126 @@
/*
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.gfs.*;
import gplx.xowa.users.*; import gplx.xowa.apps.fsys.*;
public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
private final GfoInvkAble root_invk; private final Xoa_fsys_mgr app_fsys_mgr; private final Xou_fsys_mgr usr_fsys_mgr;
public Xoa_gfs_mgr(GfoInvkAble root_invk, Xoa_fsys_mgr app_fsys_mgr, Xou_fsys_mgr usr_fsys_mgr) {
this.root_invk = root_invk; this.app_fsys_mgr = app_fsys_mgr; this.usr_fsys_mgr = usr_fsys_mgr;
GfsCore._.AddCmd(root_invk, Xoae_app.Invk_app);
GfsCore._.AddCmd(root_invk, Xoae_app.Invk_xowa);
}
public GfoInvkAble Root_invk() {return root_invk;}
public Xoa_fsys_mgr App_fsys_mgr() {return app_fsys_mgr;}
public Xoa_app_eval Eval_mgr() {return eval_mgr;} private final Xoa_app_eval eval_mgr = new Xoa_app_eval();
private void Run_url_by_type(String type) {
Io_url app_data_dir = usr_fsys_mgr.App_data_dir();
Io_url url = null;
if (String_.Eq(type, "user_system_cfg")) url = app_data_dir.GenSubFil_nest("cfg", "user_system_cfg.gfs");
else if (String_.Eq(type, "xowa_cfg_custom")) url = usr_fsys_mgr.App_data_cfg_custom_fil();
else if (String_.Eq(type, "xowa_cfg_user")) url = usr_fsys_mgr.App_data_cfg_user_fil();
else if (String_.Eq(type, "xowa_cfg_os")) {url = app_fsys_mgr.Bin_data_os_cfg_fil(); Xoa_gfs_mgr_.Cfg_os_assert(url);}
else if (String_.Eq(type, "xowa_cfg_app")) url = app_fsys_mgr.Root_dir().GenSubFil("xowa.gfs");
else throw Exc_.new_("invalid gfs type", "type", type);
try {Run_url(url);}
catch (Exception e) { // gfs is corrupt; may happen if multiple XOWAs opened, and "Close all" chosen in OS; DATE:2014-07-01
if (!String_.Eq(type, "xowa")) // check if user.gfs
Io_mgr.I.MoveFil(url, url.GenNewNameOnly(url.NameOnly() + "-" + DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss())); // move file
Gfo_usr_dlg_.I.Warn_many("", "", "invalid gfs; obsoleting: src=~{0} err=~{1}", url.Raw(), Err_.Message_gplx(e));
}
}
public GfoMsg Parse_root_msg(String v) {return gplx.gfs.Gfs_msg_bldr._.ParseToMsg(v);}
public Gfs_wtr Wtr() {return wtr;} private Gfs_wtr wtr = new Gfs_wtr();
public void Run_url(Io_url url) {
Run_url_for(GfsCore._.Root(), url);
Gfo_usr_dlg_.I.Log_wkr().Log_to_session_fmt("gfs.done: ~{0}", url.Raw());
}
public void Run_url_for(GfoInvkAble invk, Io_url url) {
String raw = Io_mgr.I.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._.Root(), raw);}
public Object Run_str_for(GfoInvkAble invk, String raw) {return Run_str_for(invk, Parse_root_msg(raw));}
public Object Run_str_for(GfoInvkAble invk, GfoMsg root_msg) {
try {
int sub_msgs_len = root_msg.Subs_count();
GfsCtx ctx = GfsCtx.new_().Fail_if_unhandled_(Fail_if_unhandled).Usr_dlg_(Gfo_usr_dlg_.I);
Object rv = null;
for (int i = 0; i < sub_msgs_len; i++) {
GfoMsg sub_msg = root_msg.Subs_getAt(i);
rv = GfsCore._.ExecOne_to(ctx, invk, sub_msg);
}
return rv;
} catch (Exception e) {
Gfo_usr_dlg_.I.Warn_many("", "", "error while executing script: err=~{0}", Err_.Message_gplx(e));
return GfoInvkAble_.Rv_error;
}
}
public GfoEvObj Get_owner_as_event_obj(String cmd) {
GfoMsg cur_msg = Parse_root_msg(cmd).Subs_getAt(0); // ignore root_msg which is ""
GfoInvkAble cur_invk = root_invk;
while (true) {
if (cur_msg.Subs_count() == 0) return (GfoEvObj)cur_invk; // terminal msg; return cur_invk
cur_invk = (GfoInvkAble)GfoInvkAble_.InvkCmd(cur_invk, cur_msg.Key());
cur_msg = cur_msg.Subs_getAt(0);
}
}
public byte[] Build_prop_set_to_bry(Bry_bfr bfr, byte[] prop, byte[] val) {Build_prop_set(bfr, prop, val); return bfr.Xto_bry_and_clear();}
public void Build_prop_set(Bry_bfr bfr, byte[] prop, byte[] val) {
fmtr_eval_set.Bld_bfr_many(bfr, prop, Xoa_gfs_mgr.Cfg_save_escape(val));
} private Bry_fmtr fmtr_eval_set = Bry_fmtr.new_("~{prop}_('~{val}');\n", "prop", "val");
public byte[] Build_prop_get_to_bry(Bry_bfr bfr, byte[] prop) {Build_prop_get(bfr, prop); return bfr.Xto_bry_and_clear();}
public void Build_prop_get(Bry_bfr bfr, byte[] prop) {
fmtr_eval_get.Bld_bfr_many(bfr, prop);
} private Bry_fmtr fmtr_eval_get = Bry_fmtr.new_("~{prop};\n", "prop");
static final String GRP_KEY = "Xoa_gfs_mgr";
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 GfoInvkAble_.Null;} // FUTURE: handle version for upgrades
else return GfoInvkAble_.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._.MsgParser_(gplx.gfs.Gfs_msg_bldr._);
}
public static byte[] Cfg_save_escape(String v) {return Cfg_save_escape(Bry_.new_u8(v));}
public static byte[] Cfg_save_escape(byte[] v) {
return Bry_finder.Find_fwd(v, Byte_ascii.Apos) == Bry_.NotFound ? v : Bry_.Replace(v, Bry_apos_1, Bry_apos_2);
} static final byte[] Bry_apos_1 = Bry_.new_a7("'"), Bry_apos_2 = Bry_.new_a7("''");
public static String Build_code(String... ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
if (i != 0) Build_code_bfr.Add_byte(Byte_ascii.Dot);
Build_code_bfr.Add_str(ary[i]);
}
return Build_code_bfr.Xto_str_and_clear();
} static final Bry_bfr Build_code_bfr = Bry_bfr.new_();
public static final String Cfg_user_file = "xowa_user_cfg.gfs", Cfg_user_custom_file = "user_custom_cfg.gfs", Cfg_os = "xowa_cfg_os.gfs";
public static boolean Fail_if_unhandled = false;
}
class Xoa_gfs_mgr_ {
public static void Cfg_os_assert(Io_url orig_url) {
Io_url dflt_url = orig_url.GenNewNameOnly(orig_url.NameOnly() + "_default");
if (!Io_mgr.I.ExistsFil(dflt_url)) return; // no dflt
if (!Io_mgr.I.ExistsFil(orig_url)) {
Io_mgr.I.CopyFil(dflt_url, orig_url, true);
Gfo_usr_dlg_.I.Log_many("", "", "xowa_cfg_os generated; url=~{0}", orig_url.Raw());
}
}
}

View File

@@ -0,0 +1,117 @@
/*
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.php.*;
public class Xoa_gfs_php_mgr {
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.Xto_bry_and_clear() : src;
}
private static int Xto_php_swap(Bry_bfr bfr, byte[] src, int len, int pos) {
if (pos >= len) throw Exc_.new_("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_finder.Find_fwd_while_num(src, num_bgn, len); // +1 to position after {
if ( num_end == Bry_finder.Not_found
|| num_end == len
|| src[num_end] != Byte_ascii.Curly_end
)
throw Exc_.new_("invalid gfs; num_end not found", "src", String_.new_u8(src));
bfr.Add_byte(Byte_ascii.Dollar);
int arg_idx = Bry_.Xto_int_or(src, num_bgn, num_end, -1);
if (arg_idx == -1) {
throw Exc_.new_("invalid int");
}
bfr.Add_int_variable(arg_idx + 1);
return num_end + 1;
}
default: {
throw Exc_.new_("invalid gfs; next char after tilde must be either tilde or open brace", "src", String_.new_u8(src));
}
}
}
public static byte[] Xto_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:
++i;
if (i < raw_len)
bfr.Add_byte(raw[i]);
else
bfr.Add_byte(Byte_ascii.Backslash);
break;
case Byte_ascii.Tilde:
bfr.Add_byte_repeat(Bry_fmtr.char_escape, 2); // escape tilde; EX: ~u -> ~~u; DATE:2013-11-11
break;
case Byte_ascii.Dollar:
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
int int_val = Bry_.Xto_int_or(raw, i + 1, end_pos, -1);
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
i = end_pos - 1;
break;
default:
bfr.Add_byte(b);
break;
}
}
return bfr.Xto_bry_and_clear();
}
}

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 org.junit.*;
public class Xoa_gfs_php_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoa_gfs_php_mgr_fxt fxt = new Xoa_gfs_php_mgr_fxt();
@Test public void Xto_gfs() {
fxt.Test_Xto_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
fxt.Test_Xto_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
fxt.Test_Xto_gfs("a~b" , "a~~b"); // tilde.escape
fxt.Test_Xto_gfs("a$1b" , "a~{0}b"); // dollar
}
@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
}
}
class Xoa_gfs_php_mgr_fxt {
private Bry_bfr bfr = Bry_bfr.new_();
public void Clear() {}
public void Test_Xto_gfs(String raw, String expd) {
byte[] actl = Xoa_gfs_php_mgr.Xto_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 = Xoa_gfs_php_mgr.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
}

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; import gplx.*; import gplx.xowa.*;
public class Xoa_shell implements GfoInvkAble {
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_)) ConsoleAdp._.CharsPerLineMax_set(m.ReadInt("v"));
else if (ctx.Match(k, Invk_backspace_by_bytes_)) ConsoleAdp._.Backspace_by_bytes_(m.ReadYn("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private String Fetch_page(GfoMsg m) {
String url = m.ReadStr("url");
if (String_.Has_at_bgn(url, "//")) url = String_.Replace(url, "//", ""); // NOTE: handle Firefox_addon which sometimes sends urls of the form "//wiki/" when coming from the sidebar; DATE:2015-07-04
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.*;
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,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,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.wdatas.*;
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,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.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
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 Exc_.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_ascii_()
.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,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.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_fsys_mgr implements GfoInvkAble {
public Xoa_fsys_mgr(String plat_name, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url css_dir) {
this.root_dir = root_dir;
this.wiki_dir = wiki_dir;
this.file_dir = file_dir;
this.css_dir = css_dir;
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_xtns_dir = bin_any_dir.GenSubDir_nest("xowa", "xtns");
this.cfg_lang_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "lang", "core");
this.cfg_wiki_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "wiki", "core");
}
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
public Io_url Wiki_dir() {return wiki_dir;} private final Io_url wiki_dir;
public Io_url File_dir() {return file_dir;} private final Io_url file_dir;
public Io_url Css_dir() {return css_dir;} private final Io_url css_dir;
public Io_url Bin_plat_dir() {return bin_plat_dir;} private final Io_url bin_plat_dir;
public Io_url Bin_any_dir() {return bin_any_dir;} private final Io_url bin_any_dir;
public Io_url Bin_xowa_dir() {return bin_xowa_dir;} private final Io_url bin_xowa_dir;
public Io_url Bin_xtns_dir() {return bin_xtns_dir;} private final Io_url bin_xtns_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 Bin_data_os_cfg_fil() {return bin_plat_dir.GenSubFil_nest("xowa", "cfg", Xoa_gfs_mgr.Cfg_os);}
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 void Init_by_app(GfoInvkAble app_mgr_invk) {this.app_mgr_invk = app_mgr_invk;} private GfoInvkAble 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 GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_apps = "apps", Invk_root_dir = "root_dir";
}

View File

@@ -0,0 +1,128 @@
/*
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.*;
public class Xoa_prog_mgr implements GfoInvkAble {
public void Init_by_app(Xoa_fsys_eval cmd_eval) {
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
ProcessAdp.ini_(this, usr_dlg, app_query_img_size , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}imagemagick\\identify", "-ping -format \"<{%w,%h}>\" \"~{file}\"", "file");
ProcessAdp.ini_(this, usr_dlg, app_resize_img , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 10 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "\"~{source}\" -coalesce -resize ~{width}x~{height} \"~{target}\"", "source", "target", "width", "height");
ProcessAdp.ini_(this, usr_dlg, app_convert_svg_to_png , cmd_eval, ProcessAdp.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
ProcessAdp.ini_(this, usr_dlg, app_convert_tex_to_dvi , cmd_eval, ProcessAdp.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");
ProcessAdp.ini_(this, usr_dlg, app_convert_dvi_to_png , cmd_eval, ProcessAdp.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");
ProcessAdp.ini_(this, usr_dlg, app_convert_djvu_to_tiff , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}djvulibre\\ddjvu", "-format=tiff -page=1 \"~{source}\" \"~{target}\"", "source", "target");
ProcessAdp.ini_(this, usr_dlg, app_decompress_bz2 , cmd_eval, ProcessAdp.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
ProcessAdp.ini_(this, usr_dlg, app_decompress_bz2_by_stdout , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 0 , "~{<>bin_plat_dir<>}7-zip\\7za", "x -so \"~{src}\"", "src"); // x=extract; -so=stdout
ProcessAdp.ini_(this, usr_dlg, app_decompress_zip , cmd_eval, ProcessAdp.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
ProcessAdp.ini_(this, usr_dlg, app_decompress_gz , cmd_eval, ProcessAdp.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
ProcessAdp.ini_(this, usr_dlg, app_lua , cmd_eval, ProcessAdp.Run_mode_async , 0 , "~{<>bin_plat_dir<>}lua\\lua", "", "");
ProcessAdp.ini_(this, usr_dlg, app_lilypond , cmd_eval, ProcessAdp.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");
ProcessAdp.ini_(this, usr_dlg, app_abc2ly , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}lilypond\\usr\\bin\\python.exe", "abc2ly.py -s \"--output=~{target}\" \"~{source}\"", "source", "target");
ProcessAdp.ini_(this, usr_dlg, app_trim_img , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}imagemagick\\convert", "-trim \"~{source}\" \"~{target}\"", "source", "target");
ProcessAdp.ini_(this, usr_dlg, app_convert_midi_to_ogg , cmd_eval, ProcessAdp.Run_mode_sync_timeout , 1 * 60, "~{<>bin_plat_dir<>}timidity\\timidity", "-Ov \"--output-file=~{target}\" \"~{source}\"", "source", "target");
ProcessAdp.ini_(this, usr_dlg, app_view_web , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
ProcessAdp.ini_(this, usr_dlg, app_view_text , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
int cmds_view_file_by_ext_len = cmds_view_file_by_ext.length;
for (int i= 0; i < cmds_view_file_by_ext_len; i++) {
ProcessAdp cmd = new ProcessAdp();
cmds_view_file_by_ext [i] = cmd;
ProcessAdp.ini_(this, usr_dlg, cmd , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{file}\"", "file");
}
}
public ProcessAdp App_query_img_size() {return app_query_img_size;} private ProcessAdp app_query_img_size = new ProcessAdp();
public ProcessAdp App_resize_img() {return app_resize_img;} private ProcessAdp app_resize_img = new ProcessAdp();
public ProcessAdp App_convert_svg_to_png() {return app_convert_svg_to_png;} private ProcessAdp app_convert_svg_to_png = new ProcessAdp();
public ProcessAdp App_convert_tex_to_dvi() {return app_convert_tex_to_dvi;} private ProcessAdp app_convert_tex_to_dvi = new ProcessAdp();
public ProcessAdp App_convert_dvi_to_png() {return app_convert_dvi_to_png;} private ProcessAdp app_convert_dvi_to_png = new ProcessAdp();
public ProcessAdp App_convert_djvu_to_tiff() {return app_convert_djvu_to_tiff;} private ProcessAdp app_convert_djvu_to_tiff = new ProcessAdp();
public ProcessAdp App_view_web() {return app_view_web;} private ProcessAdp app_view_web = new ProcessAdp();
public ProcessAdp App_view_text() {return app_view_text;} private ProcessAdp app_view_text = new ProcessAdp();
public ProcessAdp App_decompress_bz2() {return app_decompress_bz2;} private ProcessAdp app_decompress_bz2 = new ProcessAdp();
public ProcessAdp App_decompress_zip() {return app_decompress_zip;} private ProcessAdp app_decompress_zip = new ProcessAdp();
public ProcessAdp App_decompress_gz() {return app_decompress_gz;} private ProcessAdp app_decompress_gz = new ProcessAdp();
public ProcessAdp App_decompress_bz2_by_stdout() {return app_decompress_bz2_by_stdout;} private ProcessAdp app_decompress_bz2_by_stdout = new ProcessAdp();
public ProcessAdp App_lua() {return app_lua;} private ProcessAdp app_lua = new ProcessAdp();
public ProcessAdp App_lilypond() {return app_lilypond;} private ProcessAdp app_lilypond = new ProcessAdp();
public ProcessAdp App_abc2ly() {return app_abc2ly;} private ProcessAdp app_abc2ly = new ProcessAdp();
public ProcessAdp App_trim_img() {return app_trim_img;} private ProcessAdp app_trim_img = new ProcessAdp();
public ProcessAdp App_convert_midi_to_ogg() {return app_convert_midi_to_ogg;} private ProcessAdp app_convert_midi_to_ogg = new ProcessAdp();
public ProcessAdp 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_query_img_size)) return app_query_img_size;
else if (ctx.Match(k, Invk_resize_img)) return app_resize_img;
else if (ctx.Match(k, Invk_convert_svg_to_png)) return app_convert_svg_to_png;
else 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 (ctx.Match(k, Invk_convert_djvu_to_tiff)) return app_convert_djvu_to_tiff;
else if (ctx.Match(k, Invk_view_web)) return app_view_web;
else if (ctx.Match(k, Invk_decompress_bz2)) return app_decompress_bz2;
else if (ctx.Match(k, Invk_decompress_zip)) return app_decompress_zip;
else if (ctx.Match(k, Invk_decompress_gz)) return app_decompress_gz;
else if (ctx.Match(k, Invk_decompress_bz2_by_stdout)) return app_decompress_bz2_by_stdout;
else if (ctx.Match(k, Invk_lua)) return app_lua;
else if (ctx.Match(k, Invk_lilypond)) return app_lilypond;
else if (ctx.Match(k, Invk_abc2ly)) return app_abc2ly;
else if (ctx.Match(k, Invk_convert_midi_to_ogg)) return app_convert_midi_to_ogg;
else if (ctx.Match(k, Invk_trim_img)) return app_trim_img;
else if (ctx.Match(k, Invk_web)) return app_view_web;
else if (ctx.Match(k, Invk_text)) return app_view_text;
else if (ctx.Match(k, Invk_image)) return Init_by_exts("png", "jpg", "jpeg", "gif", "tif", "tiff", "svg");
else if (ctx.Match(k, Invk_media)) return Init_by_exts("mid", "ogg", "oga", "ogv", "webm");
else if (ctx.Match(k, Invk_svg)) return Init_by_exts("svg");
else if (ctx.Match(k, Invk_pdf)) return Init_by_exts("pdf");
else if (ctx.Match(k, Invk_djvu)) return Init_by_exts("djvu");
else if (ctx.Match(k, Invk_view_by_ext)) Exec_view_by_ext(m.ReadStr("exts"), m.ReadStr("cmd"), m.ReadStr("args"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
public void Exec_view_web(byte[] url) {
url = Bry_.Replace(url, Quote_normal, Quote_escape); // escape quotes; DATE:2013-03-31
String url_str = String_.new_u8(url);
url_str = ProcessAdp.Escape_ampersands_if_process_is_cmd(Op_sys.Cur().Tid_is_wnt(), app_view_web.Exe_url().Raw(), url_str); // escape ampersands; DATE:2014-05-20
app_view_web.Run(url_str);
} private static final byte[] Quote_normal = new byte[] {Byte_ascii.Quote}, Quote_escape = new byte[] {Byte_ascii.Quote, Byte_ascii.Quote};
private ProcessAdp App_by_ext_key(String ext) {return cmds_view_file_by_ext[Xof_ext_.Get_id_by_ext_(Bry_.new_a7(ext))];}
public void Exec_view_by_ext(String exts_raw, String cmd, String args) {
String[] exts_ary = String_.Split(exts_raw, '|');
int exts_ary_len = exts_ary.length;
for (int i = 0; i < exts_ary_len; i++)
App_by_ext_key(exts_ary[i]).Cmd_args(cmd, args);
} ProcessAdp[] cmds_view_file_by_ext = new ProcessAdp[Xof_ext_.Id__max];
private ProcessAdp Init_by_exts(String... exts) {
ProcessAdp rv = App_by_ext_key(exts[0]);
int len = exts.length;
for (int i = 0; i < len; i++) {
cmds_view_file_by_ext[Xof_ext_.Get_id_by_ext_(Bry_.new_a7(exts[i]))] = rv;
}
return rv;
}
private static final String Invk_query_img_size = "query_img_size", Invk_resize_img = "resize_img", Invk_convert_svg_to_png = "convert_svg_to_png", Invk_convert_tex_to_dvi = "convert_tex_to_dvi", Invk_convert_dvi_to_png = "convert_dvi_to_png"
, Invk_convert_djvu_to_tiff = "convert_djvu_to_tiff", Invk_view_web = "view_web"
, Invk_decompress_bz2 = "decompress_bz2", Invk_decompress_zip = "decompress_zip", Invk_decompress_gz = "decompress_gz", Invk_decompress_bz2_by_stdout = "decompress_bz2_by_stdout"
, Invk_view_by_ext = "view_by_ext"
, Invk_lua = "lua", Invk_lilypond = "lilypond", Invk_abc2ly = "abc2ly", Invk_trim_img = "trim_img", Invk_convert_midi_to_ogg = "convert_midi_to_ogg"
, Invk_web = "web"
, Invk_media = "media"
, Invk_image = "image"
, Invk_svg = "svg"
, Invk_pdf = "pdf"
, Invk_djvu = "djvu"
, Invk_text = "text"
;
public static final int Len_dlm_fld = 1, Adj_next_char = 1;
}

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.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.apps.versions.*;
public class Xoa_setup_mgr {
public static void Delete_old_files(Xoae_app app) {
String version_previous = app.Api_root().App().Env().Version_previous();
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
Io_url root_dir = app.Fsys_mgr().Root_dir();
Delete_old_dir(usr_dlg, version_previous, "1.8.2.1" , root_dir.GenSubDir_nest("user", "anonymous", "lang"));
Delete_old_dir(usr_dlg, version_previous, "1.8.2.1" , root_dir.GenSubDir_nest("user", "anonymous", "wiki", "#cfg"));
Delete_old_dir(usr_dlg, version_previous, "1.10.2.1" , root_dir.GenSubDir_nest("bin", "any", "javascript"));
Delete_old_dir(usr_dlg, version_previous, "1.10.2.1" , root_dir.GenSubDir_nest("bin", "any", "xowa", "html", "modules"));
}
@gplx.Internal protected static void Delete_old_dir(Gfo_usr_dlg usr_dlg, String version_prv, String version_del, Io_url dir) {
if (Xoa_version_.Compare(version_prv, version_del) != CompareAble_.Less) return;
usr_dlg.Log_many("", "", "setup:checking if dir exists: version_prv=~{0} version_del=~{1} dir=~{2}", version_prv, version_del, dir.Raw());
if (!Io_mgr.I.ExistsDir(dir)) return;
usr_dlg.Log_many("", "", "setup:deleting dir", version_prv, version_del, dir.Raw());
Io_mgr.I.DeleteDirDeep(dir);
}
}

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.setups; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_setup_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoa_setup_mgr_fxt fxt = new Xoa_setup_mgr_fxt();
@Test public void Compare() {
fxt.Test_delete_old_dir("mem/dir/", "1.8.1.1" , "1.8.2.1", Bool_.Y); // version is earlier than checkpoint; delete
fxt.Test_delete_old_dir("mem/dir/", "1.8.2.1" , "1.8.2.1", Bool_.N); // version is not earlier than checkpoint; don't delete
fxt.Test_delete_old_dir("mem/dir/", "" , "1.8.2.1", Bool_.Y); // version is empty; delete;
}
}
class Xoa_setup_mgr_fxt {
public void Clear() {}
public void Test_delete_old_dir(String dir_str, String version_prv, String version_del, boolean expd) {
Io_url dir = Io_url_.new_fil_(dir_str);
Io_mgr.I.CreateDirIfAbsent(dir);
Xoa_setup_mgr.Delete_old_dir(Gfo_usr_dlg_.Noop, version_prv, version_del, dir);
Tfds.Eq(expd, !Io_mgr.I.ExistsDir(dir), version_prv + "|" + version_del);
}
}

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.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_version_ {
public static int Compare(String lhs_str, String rhs_str) {
String[] lhs_ary = String_.Split(lhs_str, ".");
String[] rhs_ary = String_.Split(rhs_str, ".");
return Compare_as_int(lhs_ary, rhs_ary);
}
private static int Compare_as_int(String[] lhs_ary, String[] rhs_ary) {
int lhs_ary_len = lhs_ary.length;
int rhs_ary_len = rhs_ary.length;
int len_comp = Int_.Compare(lhs_ary_len, rhs_ary_len);
if (len_comp != CompareAble_.Same) return len_comp;
for (int i = 0; i < lhs_ary_len; ++i) {
String lhs_itm = lhs_ary[i];
String rhs_itm = rhs_ary[i];
int itm_comp = Int_.Compare(Int_.parse_or_(lhs_itm, 0), Int_.parse_or_(rhs_itm, 0));
if (itm_comp != CompareAble_.Same) return itm_comp;
}
return CompareAble_.Same;
}
}

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.versions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_version_tst {
@Before public void init() {fxt.Clear();} private Xoa_version_fxt fxt = new Xoa_version_fxt();
@Test public void Compare() {
fxt.Test_compare("1.8.1.1", "1.8.2.1" , CompareAble_.Less); // rev:less
fxt.Test_compare("1.8.2.1", "1.8.1.1" , CompareAble_.More); // rev:more
fxt.Test_compare("1.8.1.1", "1.8.1.1" , CompareAble_.Same); // rev:same
fxt.Test_compare("1.7.9.1", "1.8.1.1" , CompareAble_.Less); // min:less
fxt.Test_compare("", "1.8.1.1" , CompareAble_.Less); // empty:less
fxt.Test_compare("1.8.1.1", "" , CompareAble_.More); // empty:more
fxt.Test_compare("", "" , CompareAble_.Same); // empty:more
}
}
class Xoa_version_fxt {
public void Clear() {}
public void Test_compare(String lhs, String rhs, int expd) {
Tfds.Eq(expd, Xoa_version_.Compare(lhs, rhs), lhs + "|" + rhs);
}
}

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.bldrs; import gplx.*; import gplx.xowa.*;
public class Db_idx_mode {
private int tid;
Db_idx_mode(int tid) {this.tid = tid;}
public boolean Tid_is_bgn() {return tid == Tid_bgn;}
public boolean Tid_is_end() {return tid == Tid_end;}
public boolean Tid_is_skip() {return tid == Tid_skip;}
private static final int Tid_skip = 0, Tid_bgn = 1, Tid_end = 2;
private static final String Key_skip = "skip", Key_bgn = "bgn", Key_end = "end";
public static final Db_idx_mode
Itm_skip = new Db_idx_mode(Tid_skip)
, Itm_bgn = new Db_idx_mode(Tid_bgn)
, Itm_end = new Db_idx_mode(Tid_end)
;
public static Db_idx_mode Xto_itm(String key) {
if (String_.Eq(key, Key_skip)) return Itm_skip;
else if (String_.Eq(key, Key_bgn)) return Itm_bgn;
else if (String_.Eq(key, Key_end)) return Itm_end;
else throw Exc_.new_unhandled(key);
}
}

View File

@@ -0,0 +1,138 @@
/*
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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*; import gplx.core.strings.*;
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.dbs.*; import gplx.xowa.specials.search.*; import gplx.xowa.ctgs.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.infos.*;
public class Db_mgr_fxt {
public Db_mgr_fxt Ctor_fsys() {bldr_fxt = new Xob_fxt().Ctor(Xoa_test_.Url_root().GenSubDir("root")); return this;}
public Db_mgr_fxt Ctor_mem() {bldr_fxt = new Xob_fxt().Ctor_mem(); return this;} private Xob_fxt bldr_fxt;
public Xowd_page_itm page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xowd_page_itm().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Redirected_(type_redirect).Text_len_(text_len);}
public Xowe_wiki Wiki() {return bldr_fxt.Wiki();}
public Xob_bldr Bldr() {return bldr_fxt.Bldr();}
public Db_mgr_fxt doc_ary_(Xowd_page_itm... v) {bldr_fxt.doc_ary_(v); return this;}
public Xowd_page_itm doc_(int id, String date, String title, String text) {return bldr_fxt.doc_(id, date, title, text);}
public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, text);}
public Xowd_page_itm doc_ttl_(int id, String title) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, "IGNORE");}
public Db_mgr_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
public Db_mgr_fxt Init_fil(Io_url url, String raw) {Io_mgr.I.SaveFilStr(url, raw); return this;}
public Db_mgr_fxt Exec_run(Xobd_wkr wkr) {bldr_fxt.Run(wkr); return this;}
public Db_mgr_fxt Exec_run(Xob_cmd cmd) {bldr_fxt.Run_cmds(cmd); return this;}
public Db_mgr_fxt Exec_run(Xobd_parser_wkr wkr) {bldr_fxt.Run(wkr); return this;}
public void Init_page_insert(Int_obj_ref page_id_next, int ns_id, String[] ttls) {
Xowe_wiki wiki = this.Wiki();
int len = ttls.length;
DateAdp modified_on = Tfds.Now_time0_add_min(0);
Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
tbl_page.Insert_bgn();
for (int i = 0; i < len; i++) {
String ttl = ttls[i];
int page_id = page_id_next.Val();
tbl_page.Insert_cmd_by_batch(page_id, ns_id, Bry_.new_u8(ttl), false, modified_on, 0, page_id, 0, 0);
page_id_next.Val_add(1);
}
tbl_page.Insert_end();
}
public void Test_load_ttl(int ns_id, String ttl_str, Xowd_page_itm expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
byte[] ttl_bry = Bry_.new_a7(ttl_str);
wiki.Db_mgr_as_sql().Load_mgr().Load_by_ttl(actl, ns, ttl_bry);
Tfds.Eq(expd.Id(), actl.Id());
Tfds.Eq_date(expd.Modified_on(), actl.Modified_on());
Tfds.Eq(expd.Redirected(), actl.Redirected());
Tfds.Eq(expd.Text_len(), actl.Text_len());
} private Xowd_page_itm actl = new Xowd_page_itm();
public void Test_load_page(int ns_id, int page_id, String expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
wiki.Db_mgr_as_sql().Load_mgr().Load_page(actl.Id_(page_id), ns, false);
Tfds.Eq(expd, String_.new_a7(actl.Text()));
}
public void Test_search(String search_word_str, int... expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();
List_adp rv = List_adp_.new_();
byte[] search_word_bry = Bry_.new_a7(search_word_str);
wiki.Db_mgr_as_sql().Load_mgr().Load_search(Cancelable_.Never, rv, search_word_bry, 100);
Tfds.Eq_ary(expd, Xto_int_ary(rv));
}
int[] Xto_int_ary(List_adp rslts) {
int len = rslts.Count();
int[] rv = new int[len];
for (int i = 0; i < len; i++) {
Xowd_page_itm page = (Xowd_page_itm)rslts.Get_at(i);
rv[i] = page.Id();
}
return rv;
}
public void Test_category_v1(String ctg_name_str, int... expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();
byte[] ctg_name_bry = Bry_.new_a7(ctg_name_str);
Xoctg_view_ctg ctg = new Xoctg_view_ctg();
wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_v1(ctg, ctg_name_bry);
Tfds.Eq_ary(expd, Xto_int_ary(ctg));
}
int[] Xto_int_ary(Xoctg_view_ctg ctg) {
List_adp list = List_adp_.new_();
byte tid_max = Xoa_ctg_mgr.Tid__max;
for (byte tid = 0; tid < tid_max; tid++) {
Xoctg_view_grp grp = ctg.Grp_by_tid(tid); if (grp == null) continue;
int len = grp.Itms_list().Count();
for (int i = 0; i < len; i++) {
Xoctg_view_itm itm = (Xoctg_view_itm)grp.Itms_list().Get_at(i);
list.Add(itm.Id());
}
}
return (int[])list.To_ary_and_clear(int.class);
}
public void Test_category_v2(String ctg_name_str, int... expd) {
Xowe_wiki wiki = bldr_fxt.Wiki();
byte[] ctg_name_bry = Bry_.new_a7(ctg_name_str);
Xoctg_data_ctg ctg = new Xoctg_data_ctg(ctg_name_bry);
wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_v2(ctg, ctg_name_bry);
Tfds.Eq_ary(expd, Xto_int_ary(ctg));
}
public void Test_file(String url, String expd) {
String actl = Io_mgr.I.LoadFilStr(url);
Tfds.Eq_str_lines(expd, actl);
}
int[] Xto_int_ary(Xoctg_data_ctg ctg) {
List_adp list = List_adp_.new_();
byte tid_max = Xoa_ctg_mgr.Tid__max;
for (byte tid = 0; tid < tid_max; tid++) {
Xoctg_idx_mgr grp = ctg.Grp_by_tid(tid); if (grp == null) continue;
int len = grp.Itms_len();
for (int i = 0; i < len; i++) {
Xoctg_idx_itm itm = grp.Itms_get_at(i);
list.Add(itm.Id());
}
}
return (int[])list.To_ary_and_clear(int.class);
}
public void Init_db_sqlite() {
Xowe_wiki wiki = this.Wiki();
Db_conn_pool.I.Clear();
Db_conn_bldr.I.Reg_default_sqlite();
Io_mgr.I.DeleteDir_cmd(wiki.Fsys_mgr().Root_dir()).MissingIgnored_().Exec();
wiki.Db_mgr_create_as_sql().Core_data_mgr().Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test);
Io_mgr.I.SaveFilStr(wiki.Import_cfg().Src_dir().GenSubFil("a.xml"), "<test/>");
}
public void Rls() {
this.Wiki().Db_mgr_as_sql().Core_data_mgr().Rls();
}
}

View File

@@ -0,0 +1,78 @@
/*
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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.ios.*; import gplx.xowa.bldrs.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_base_fxt {
public Xob_base_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
bldr = Xoa_app_fxt.bldr_(app);
}
this.Init_(bldr, wiki);
Clear_hook();
return this;
}
@gplx.Virtual public void Clear_hook() {}
public Xob_base_fxt Init_(Xob_bldr bldr, Xowe_wiki wiki) {this.bldr = bldr; this.wiki = wiki; return this;}
public Xoae_app App() {return app;} private Xoae_app app;
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public GfoInvkAble Bldr_itm() {return bldr_itm;} GfoInvkAble bldr_itm;
public Xowd_page_itm page_(String ttl) {return page_(ttl, "");}
public Xowd_page_itm page_(String ttl, String text) {return new Xowd_page_itm().Ttl_(Bry_.new_u8(ttl), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));}
public Io_fil_chkr meta_(String url, String data) {return new Io_fil_chkr(Io_url_.mem_fil_(url), data);}
public void Init_fxts(Xob_bldr bldr, Xowe_wiki wiki, Xob_base_fxt... fxt_ary) {
int fxt_ary_len = fxt_ary.length;
for (int i = 0; i < fxt_ary_len; i++)
fxt_ary[i].Init_(bldr, wiki);
}
public Xob_base_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
public Xob_base_fxt Init_fil(Io_url url, String raw) {Io_mgr.I.SaveFilStr(url, raw); return this;}
public Xob_base_fxt Exec_cmd(String cmd_key, GfoMsg... msgs) {
Xob_cmd cmd = (Xob_cmd)bldr.Cmd_mgr().Add_cmd(wiki, cmd_key);
this.bldr_itm = cmd;
int len = msgs.length;
GfsCtx ctx = GfsCtx.new_();
for (int i = 0; i < len; i++) {
GfoMsg msg = msgs[i];
cmd.Invk(ctx, GfsCtx.Ikey_null, msg.Key(), msg);
}
Run_cmd(bldr, cmd);
return this;
}
public Xob_base_fxt Test_fil(String url, String expd) {return Test_fil(Io_url_.new_fil_(url), expd);}
public Xob_base_fxt Test_fil(Io_url url, String expd) {
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(url));
return this;
}
public static void Run_cmd(Xob_bldr bldr, Xob_cmd cmd) {
cmd.Cmd_bgn(bldr);
cmd.Cmd_run();
cmd.Cmd_end();
}
public static void Run_wkr(Xob_bldr bldr, Xobd_wkr wkr, Xowd_page_itm[] page_ary) {
wkr.Wkr_bgn(bldr);
int page_ary_len = page_ary.length;
for (int i = 0; i < page_ary_len; i++) {
Xowd_page_itm page = page_ary[i];
wkr.Wkr_run(page);
}
wkr.Wkr_end();
}
}

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.bldrs; import gplx.*; import gplx.xowa.*;
public interface Xob_cmd extends GfoInvkAble {
String Cmd_key();
void Cmd_init(Xob_bldr bldr);
void Cmd_bgn(Xob_bldr bldr);
void Cmd_run();
void Cmd_end();
void Cmd_term();
}

View File

@@ -0,0 +1,77 @@
/*
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.bldrs; import gplx.*; import gplx.xowa.*;
public class Xob_cmd_keys {
public static final String
Key_text_init = "text.init" // "import.sql.init"
, Key_text_page = "text.page" // "import.sql.page"
, Key_text_css = "text.css"
, Key_text_search_cmd = "text.search.cmd" // "import.sql.search_title.cmd"
, Key_text_search_wkr = "text.search" // "import.sql.search_title.wkr"
, Key_text_cat_core_v1 = "text.cat.core.v1" // "import.sql.category_v1"
, Key_text_cat_core = "text.cat.core" // "import.sql.category_registry"
, Key_text_cat_link = "text.cat.link" // "import.sql.categorylinks"
, Key_text_cat_hidden = "text.cat.hidden" // "import.sql.hiddencat"
, Key_text_term = "text.term" // "import.sql.term"
, Key_wiki_redirect = "wiki.redirect" // "wiki.redirect"
, Key_wiki_image = "wiki.image" // "wiki.image"
, Key_wiki_page_dump_make = "wiki.page_dump.make" // "file.page_dump"
, Key_wiki_page_dump_drop = "wiki.page_dump.drop"
, Key_file_lnki_temp = "file.lnki_temp"
, Key_file_lnki_regy = "file.lnki_regy"
, Key_file_page_regy = "file.page_regy"
, Key_file_orig_regy = "file.orig_regy"
, Key_file_xfer_temp_thumb = "file.xfer_temp.thumb"
, Key_file_xfer_temp_orig = "file.xfer_temp.orig"
, Key_file_xfer_regy = "file.xfer_regy"
, Key_file_xfer_regy_update = "file.xfer_regy_update"
, Key_file_fsdb_make = "file.fsdb_make"
, Key_file_fsdb_reduce = "file.fsdb_reduce"
, Key_file_orig_reg = "file.orig_reg"
, Key_file_xfer_update = "file.xfer_update"
, Key_html_redlinks = "html.redlinks"
, Key_util_cleanup = "util.cleanup" // "core.cleanup"
, Key_util_download = "util.download" // "file.download"
, Key_util_xml_dump = "util.xml_dump"
, Key_wbase_json_dump = "wbase.json_dump"
, Key_wbase_qid = "wbase.qid" // "text.wdata.qid"
, Key_wbase_pid = "wbase.pid" // "text.wdata.pid"
, Key_wbase_db = "wbase.db" // "wiki.wdata_db"
, Key_wbase_ns = "wbase.ns"
, Key_tdb_text_init = "tdb.text.init" // "core.init"
, Key_tdb_make_page = "tdb.text.page" // "core.make_page"
, Key_tdb_make_id = "core.make_id"
, Key_tdb_make_search_title = "core.make_search_title"
, Key_tdb_make_category = "core.make_category"
, Key_tdb_calc_stats = "core.calc_stats"
, Key_tdb_core_term = "tdb.text.term" // "core.term"
, Key_tdb_text_cat_link = "ctg.link_sql"
, Key_tdb_ctg_link_idx = "ctg.link_idx"
, Key_tdb_cat_hidden_sql = "ctg.hiddencat_sql"
, Key_tdb_cat_hidden_ttl = "ctg.hiddencat_ttl"
, Key_tdb_text_wdata_qid = "tdb.text.wdata.qid"
, Key_tdb_text_wdata_pid = "tdb.text.wdata.pid"
, Key_diff_regy_exec = "file.diff_regy.exec"
, Key_diff_regy_make = "file.diff_regy.make"
, Key_exec_sql = "import.sql.exec_sql"
, Key_deploy_zip = "deploy.zip"
, Key_deploy_copy = "deploy.copy"
, Key_decompress_bz2 = "core.decompress_bz2"
;
}

View File

@@ -0,0 +1,149 @@
/*
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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.imports.*;
import gplx.xowa.bldrs.cmds.texts.*; import gplx.xowa.bldrs.cmds.texts.sqls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*; import gplx.xowa.bldrs.cmds.files.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.bldrs.cmds.utils.*; import gplx.xowa.bldrs.cmds.wikis.*;
import gplx.xowa.files.origs.*; import gplx.xowa.html.hdumps.bldrs.*;
public class Xob_cmd_mgr implements GfoInvkAble {
public Xob_cmd_mgr(Xob_bldr bldr) {this.bldr = bldr;} private Xob_bldr bldr;
public void Clear() {list.Clear(); dump_rdrs.Clear();}
public int Len() {return list.Count();} List_adp list = List_adp_.new_();
public Xob_cmd Get_at(int i) {return (Xob_cmd)list.Get_at(i);}
public Xob_cmd Add(Xob_cmd cmd) {list.Add(cmd); return cmd;}
public GfoInvkAble Add_cmd(Xowe_wiki wiki, String cmd_key) {
if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_init)) return Add(new Xob_init_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_page)) return Xml_rdr_direct_add(wiki, new Xob_page_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_css)) return Add(new Xob_css_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_search_wkr)) return Xml_rdr_direct_add(wiki, new Xob_search_sql_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_search_cmd)) return Add(new Xob_search_sql_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_cat_core_v1)) return Xml_rdr_parser_add(wiki, new Xob_ctg_v1_sql().Ctor(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_cat_core)) return Add(new Xob_category_registry_sql(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_cat_link)) return Add(new Xob_categorylinks_sql(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_cat_hidden)) return Add(new Xoctg_hiddencat_parser_sql(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_text_term)) return Add(new Xob_term_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wiki_page_dump_make)) return Add(new Xob_page_dump_cmd_make(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wiki_page_dump_drop)) return Add(new Xob_page_dump_cmd_drop(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wiki_redirect)) return Add(new Xob_redirect_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wiki_image)) return Add(new Xob_image_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_lnki_temp)) return Add(new Xob_lnki_temp_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_lnki_regy)) return Add(new Xob_lnki_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_page_regy)) return Add(new Xob_page_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_orig_regy)) return Add(new Xob_orig_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_xfer_temp_thumb)) return Add(new Xob_xfer_temp_cmd_thumb(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_xfer_temp_orig)) return Add(new Xob_xfer_temp_cmd_orig(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_xfer_regy)) return Add(new Xob_xfer_regy_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_xfer_regy_update)) return Add(new Xob_xfer_regy_update_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_fsdb_make)) return Add(new Xob_fsdb_make_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_orig_reg)) return Add(new Xob_orig_tbl_bldr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_file_xfer_update)) return Add(new Xob_xfer_update_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_html_redlinks)) return Add(new Xob_redlink_mkr_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_util_cleanup)) return Add(new Xob_cleanup_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_util_download)) return Add(new Xob_download_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_util_xml_dump)) return Add(new Xob_xml_dumper_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wbase_json_dump)) return Add(new Xob_wbase_json_dump_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wbase_qid)) return Xml_rdr_direct_add(wiki, new Xob_wdata_qid_sql().Ctor(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wbase_pid)) return Xml_rdr_direct_add(wiki, new Xob_wdata_pid_sql().Ctor(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wbase_db)) return Add(new Xob_wdata_db_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_wbase_ns)) return Add(new Xob_site_ns_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_init)) return Add(new Xob_init_tdb(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_make_page)) return Xml_rdr_direct_add(wiki, new Xob_page_txt(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_make_id)) return Xml_rdr_direct_add(wiki, new Xob_make_id_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_make_search_title)) return Xml_rdr_direct_add(wiki, new Xob_search_tdb(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_make_category)) return Xml_rdr_parser_add(wiki, new Xob_ctg_v1_txt().Ctor(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_calc_stats)) return Add(new Xob_calc_stats_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_cat_link)) return Add(new Xob_categorylinks_txt(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_ctg_link_idx)) return Add(new Xoctg_link_idx_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_cat_hidden_sql)) return Add(new Xoctg_hiddencat_parser_txt(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_cat_hidden_ttl)) return Add(new Xoctg_hiddencat_ttl_wkr(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_core_term)) return Add(new Xob_term_txt(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_wdata_qid)) return Xml_rdr_direct_add(wiki, new Xob_wdata_qid_txt().Ctor(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_tdb_text_wdata_pid)) return Xml_rdr_direct_add(wiki, new Xob_wdata_pid_txt().Ctor(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_diff_regy_exec)) return Add(new Xob_diff_regy_exec_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_diff_regy_make)) return Add(new Xob_diff_regy_make_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_exec_sql)) return Add(new Xob_exec_sql_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_decompress_bz2)) return Add(new Xob_decompress_bz2_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_deploy_zip)) return Add(new Xob_deploy_zip_cmd(bldr, wiki));
else if (String_.Eq(cmd_key, Xob_cmd_keys.Key_deploy_copy)) return Add(new Xob_deploy_copy_cmd(bldr, wiki));
else throw Exc_.new_unhandled(cmd_key);
}
private Xobd_wkr Xml_rdr_direct_add(Xowe_wiki wiki, Xobd_wkr wkr) {
Xobd_rdr dump_rdr = Xml_rdr_get(wiki);
dump_rdr.Wkr_add(wkr);
return wkr;
}
private Xobd_parser_wkr Xml_rdr_parser_add(Xowe_wiki wiki, Xobd_parser_wkr wkr) {
Xobd_rdr dump_rdr = Xml_rdr_get(wiki);
dump_rdr.Page_parser_assert().Wkr_add(wkr);
return wkr;
}
private Xobd_rdr Xml_rdr_get(Xowe_wiki wiki) {
byte[] wiki_key = wiki.Domain_bry();
Xobd_rdr rv = (Xobd_rdr)dump_rdrs.Get_by(dump_rdrs_ref.Val_(wiki_key));
if (rv == null) {
rv = new Xobd_rdr(bldr, wiki);
dump_rdrs.Add(Bry_obj_ref.new_(wiki_key), rv);
this.Add(rv);
}
return rv;
}
private Hash_adp dump_rdrs = Hash_adp_.new_(); private Bry_obj_ref dump_rdrs_ref = Bry_obj_ref.null_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_add)) return Add_cmd(Wiki_get_or_make(m), m.ReadStr("v"));
else if (ctx.Match(k, Invk_add_many)) return Add_many(m);
else if (ctx.Match(k, Invk_get_first)) return Get_first(m);
else if (ctx.Match(k, Invk_new_batch)) return new Xob_core_batch_utl(bldr, m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_add = "add", Invk_add_many = "add_many", Invk_new_batch = "new_batch", Invk_get_first = "get_first";
private Object Get_first(GfoMsg m) {
String cmd_key = m.ReadStr("v");
int cmds_len = list.Count();
for (int i = 0;i < cmds_len; i++) {
Xob_cmd cmd = (Xob_cmd)list.Get_at(i);
if (String_.Eq(cmd.Cmd_key(), cmd_key)) return cmd;
}
throw Exc_.new_("cmd not found", "key", cmd_key);
}
private Object Add_many(GfoMsg m) {
Xowe_wiki wiki = Wiki_get_or_make(m);
wiki.Lang().Init_by_load_assert(); // NOTE: must check that lang is loaded; else case_mgr will not initialize; DATE:2013-05-11
int args_len = m.Args_count();
String[] cmds = new String[args_len - 1]; // -1 b/c 1st arg is wiki
for (int i = 1; i < args_len; i++) {
KeyVal kv = m.Args_getAt(i);
cmds[i - 1] = kv.Val_to_str_or_empty();
}
return Add_many(wiki, cmds);
}
public Object Add_many(Xowe_wiki wiki, String... cmds) {
int len = cmds.length; if (len == 0) throw Exc_.new_("add_many cannot have 0 cmds");
Object rv = null;
for (int i = 0; i < len; i++)
rv = Add_cmd(wiki, cmds[i]);
return rv;
}
private Xowe_wiki Wiki_get_or_make(GfoMsg m) {
byte[] wiki_key = m.ReadBry("v");
Xoae_wiki_mgr wiki_mgr = bldr.App().Wiki_mgr();
Xowe_wiki rv = wiki_mgr.Get_by_key_or_make(wiki_key);
rv.Lang().Init_by_load();
return rv;
}
public static final String GRP_KEY = "xowa.bldr.cmds";
}

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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*;
public class Xob_db_file {
Xob_db_file(Io_url url, Db_conn conn) {
this.url = url; this.conn = conn;
this.tbl__cfg = new Db_cfg_tbl(conn, "xowa_cfg");
}
public Io_url Url() {return url;} private final Io_url url;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
public static Xob_db_file new__file_make(Io_url dir) {return new_(dir, Name__file_make);}
public static Xob_db_file new__page_regy(Io_url dir) {return new_(dir, Name__page_regy);}
public static Xob_db_file new__wiki_image(Io_url dir) {return new_(dir, Name__wiki_image);}
public static Xob_db_file new__wiki_redirect(Io_url dir) {return new_(dir, Name__wiki_redirect);}
public static Xob_db_file new__temp_log(Io_url dir) {return new_(dir, Name__temp_log);}
public static Xob_db_file new__redlink(Io_url dir) {return new_(dir, Name__redlink);}
public static Xob_db_file new_(Io_url dir, String name) {
Io_url url = dir.GenSubFil(name);
Db_conn_bldr_data conn_data = Db_conn_bldr.I.Get_or_new(url);
Db_conn conn = conn_data.Conn();
Xob_db_file rv = new Xob_db_file(url, conn);
if (conn_data.Created())
rv.Tbl__cfg().Create_tbl();
return rv;
}
public static final String
Name__wiki_image = "xowa.wiki.image.sqlite3", Name__wiki_redirect = "xowa.wiki.redirect.sqlite3"
, Name__file_make = "xowa.file.make.sqlite3", Name__temp_log = "xowa.temp.log.sqlite3"
, Name__page_regy = "xowa.file.page_regy.sqlite3", Name__redlink = "xowa.temp.redlink.sqlite3"
;
}

View File

@@ -0,0 +1,161 @@
/*
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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.tdbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
public class Xob_fxt {
public Xob_fxt Ctor_mem() {
Io_mgr.I.InitEngine_mem();
return Ctor(Io_url_.mem_dir_("mem/xowa/"));
}
public Xob_fxt Ctor(Io_url root_dir) {
Db_conn_bldr.I.Reg_default_sqlite();
app = Xoa_app_fxt.app_("linux", root_dir);
wiki = Xoa_app_fxt.wiki_tst_(app);
bldr = Xoa_app_fxt.bldr_(app);
return this;
}
public Xoae_app App() {return app;} private Xoae_app app;
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Io_url fil_ns_title(int ns_id, int idx) {return wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_ttl, ns_id, idx);}
public Io_url fil_ns_page(int ns_id, int idx) {return wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, ns_id, idx);}
public Io_url fil_ns_sttl(int ns_id, int idx) {return wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_search_ttl, ns_id, idx);}
public Io_url fil_site(byte tid, int idx) {return wiki.Tdb_fsys_mgr().Url_site_fil(tid, idx);}
public Io_url fil_site_ctg(int idx) {return wiki.Tdb_fsys_mgr().Url_site_fil(Xotdb_dir_info_.Tid_category, idx);}
public Io_url fil_site_id(int idx) {return wiki.Tdb_fsys_mgr().Url_site_fil(Xotdb_dir_info_.Tid_id, idx);}
public Io_url fil_reg(byte tid) {return wiki.Tdb_fsys_mgr().Url_site_reg(tid);}
public Io_url fil_reg(int ns_id, byte tid) {return wiki.Tdb_fsys_mgr().Url_ns_reg(Int_.Xto_str_pad_bgn_zero(ns_id, 3), tid);}
public Xob_fxt Fil_expd(Io_url url, String... expd) {
String text = String_.Concat_lines_nl_skip_last(expd); // skipLast b/c if trailing line wanted, easier to pass in extra argument for ""
expd_list.Add(new Io_fil_chkr(url, text));
return this;
} List_adp expd_list = List_adp_.new_();
public Xob_fxt Fil_skip(Io_url... urls) {
for (int i = 0; i < urls.length; i++)
skip_list.Add(urls[i]);
return this;
} List_adp skip_list = List_adp_.new_();
public Xob_fxt doc_ary_(Xowd_page_itm... v) {doc_ary = v; return this;} private Xowd_page_itm[] doc_ary;
public Xowd_page_itm doc_wo_date_(int id, String title, String text) {return doc_(id, "2012-01-02 13:14", title, text);}
public Xowd_page_itm doc_(int id, String date, String title, String text) {
Xowd_page_itm rv = new Xowd_page_itm().Id_(id).Ttl_(Bry_.new_u8(title), wiki.Ns_mgr()).Text_(Bry_.new_u8(text));
int[] modified_on = new int[7];
dateParser.Parse_iso8651_like(modified_on, date);
rv.Modified_on_(DateAdp_.seg_(modified_on));
return rv;
}
public Xob_fxt Run_ctg() {
Xobd_parser parser = new Xobd_parser();
gplx.xowa.bldrs.cmds.ctgs.Xob_ctg_v1_base ctg_wkr = new gplx.xowa.bldrs.cmds.ctgs.Xob_ctg_v1_txt().Ctor(bldr, wiki);
byte[] bry = Bry_.new_u8("[[Category:");
ctg_wkr.Wkr_hooks().Add(bry, bry);
parser.Wkr_add(ctg_wkr);
return Run(parser);
}
public Xob_fxt Run_id() {
Xob_make_id_wkr wkr = new Xob_make_id_wkr(bldr, wiki);
Run(wkr);
return this;
}
private void Run_wkr(Xobd_wkr wkr) {
wkr.Wkr_bgn(bldr);
for (int i = 0; i < doc_ary.length; i++) {
Xowd_page_itm page = doc_ary[i];
wkr.Wkr_run(page);
}
wkr.Wkr_end();
}
private void tst_fils(Io_url[] ary) {
Io_fil[] actls = Get_actl(ary);
Io_fil_chkr[] expds = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class);
tst_mgr.Tst_ary("all", expds, actls);
}
Io_fil[] Get_actl(Io_url[] ary) {
int len = ary.length;
Io_fil[] rv = new Io_fil[len];
for (int i = 0; i < len; i++) {
Io_url url = ary[i];
String data = Io_mgr.I.LoadFilStr(url);
rv[i] = new Io_fil(url, data);
}
return rv;
}
public Xob_fxt Run_tmpl_dump() {
Xob_parse_dump_templates_cmd wkr = new Xob_parse_dump_templates_cmd(bldr, wiki);
Run_wkr(wkr);
tst_fils(wkr.Dump_url_gen().Prv_urls());
return this;
}
public Xob_fxt Run_page_title() {return Run(new gplx.xowa.bldrs.cmds.texts.tdbs.Xob_page_txt(bldr, wiki));}
public Xob_fxt Run(Xobd_parser_wkr... wkrs) {
Xobd_parser parser_wkr = new Xobd_parser();
int len = wkrs.length;
for (int i = 0; i < len; i++)
parser_wkr.Wkr_add(wkrs[i]);
Run(parser_wkr);
return this;
}
public Xob_fxt Run(Xobd_wkr... wkrs) {
int doc_ary_len = doc_ary.length;
for (int j = 0; j < wkrs.length; j++) {
Xobd_wkr wkr = wkrs[j];
wkr.Wkr_bgn(bldr);
for (int i = 0; i < doc_ary_len; i++) {
Xowd_page_itm page = doc_ary[i];
wkr.Wkr_run(page);
}
wkr.Wkr_end();
}
Test_expd_files();
return this;
}
public Xob_fxt Run_cmds(Xob_cmd... cmds) {
for (int j = 0; j < cmds.length; j++) {
Xob_cmd cmd = cmds[j];
cmd.Cmd_bgn(bldr);
cmd.Cmd_run();
cmd.Cmd_end();
}
Test_expd_files();
return this;
}
private void Test_expd_files() {
if (expd_list.Count() > 0) {
Io_fil_chkr[] expd = (Io_fil_chkr[])expd_list.To_ary(Io_fil_chkr.class);
Io_fil[] actl = wiki_();
tst_mgr.Tst_ary("all", expd, actl);
}
}
Io_fil[] wiki_() {
List_adp rv = List_adp_.new_();
wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Ns_dir());
wiki_fil_add(rv, wiki.Tdb_fsys_mgr().Site_dir());
rv.Sort();
return (Io_fil[])rv.To_ary(Io_fil.class);
}
private void wiki_fil_add(List_adp list, Io_url root_dir) {
Io_url[] ary = Io_mgr.I.QueryDir_args(root_dir).Recur_().ExecAsUrlAry();
for (int i = 0; i < ary.length; i++) {
Io_url url = ary[i];
Io_fil fil = new Io_fil(url, Io_mgr.I.LoadFilStr_args(url).MissingIgnored_().Exec());
list.Add(fil);
}
}
Tst_mgr tst_mgr = new Tst_mgr();
DateAdp_parser dateParser = DateAdp_parser.new_();
}

View File

@@ -0,0 +1,88 @@
/*
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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.cmds.*;
public class Xob_ns_to_db_mgr {
private final Xob_ns_to_db_wkr wkr; private final Xowd_db_mgr db_mgr; private final long db_max; private boolean one_file_conn_init = true;
private final Ordered_hash db_list = Ordered_hash_.new_();
public Xob_ns_to_db_mgr(Xob_ns_to_db_wkr wkr, Xowd_db_mgr db_mgr, long db_max) {
this.wkr = wkr; this.db_mgr = db_mgr; this.db_max = db_max;
}
public Xowd_db_file Get_by_ns(Xob_ns_file_itm ns_file_itm, int data_len) {
Xowd_db_file rv = null;
if (wkr.Db_tid() == Xowd_db_file_.Tid_text && db_mgr.Props().Layout_text().Tid_is_all_or_few()) {
rv = db_mgr.Db__core();
if (one_file_conn_init) {
one_file_conn_init = false;
Init_tbl(rv);
}
}
else if (wkr.Db_tid() == Xowd_db_file_.Tid_html_data && db_mgr.Props().Layout_html().Tid_is_all_or_few()) {
if (one_file_conn_init) {
one_file_conn_init = false;
rv = db_mgr.Dbs__make_by_tid(wkr.Db_tid());
Init_tbl(rv);
}
else
rv = db_mgr.Db__html();
}
else {
int db_id = ns_file_itm.Nth_db_id();
if (db_id == Xob_ns_file_itm.Nth_db_id_null) // ns not assigned yet to db
rv = Init_db(ns_file_itm);
else
rv = db_mgr.Dbs__get_at(db_id);
long file_len = rv.File_len();
if (file_len + data_len > db_max) { // file is "full"
Term_tbl(rv);
rv = Init_db(ns_file_itm);
}
}
rv.File_len_add(data_len);
return rv;
}
private Xowd_db_file Init_db(Xob_ns_file_itm ns_file_itm) {
Xowd_db_file rv = db_mgr.Dbs__make_by_tid(ns_file_itm.Db_file_tid(), Int_.Xto_str(ns_file_itm.Ns_ids(), "|"), ns_file_itm.Nth_db_idx(), ns_file_itm.Make_file_name());
ns_file_itm.Nth_db_id_(rv.Id());
Init_tbl(rv);
return rv;
}
private void Init_tbl(Xowd_db_file db) {
wkr.Tbl_init(db);
db_list.Add(db.Id(), db);
}
private void Term_tbl(Xowd_db_file db) {
wkr.Tbl_term(db);
db_list.Del(db.Id());
}
public void Rls_all() {
Xowd_db_file[] ary = (Xowd_db_file[])db_list.To_ary(Xowd_db_file.class);
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xowd_db_file db = (Xowd_db_file)ary[i];
Term_tbl(db); // SQLITE:1_TXN; may call close on db where txn is already closed
}
}
public void Commit() {
int len = db_list.Count();
for (int i = 0; i < len; ++i) {
Xowd_db_file db = (Xowd_db_file)db_list.Get_at(i);
db.Conn().Txn_sav();
}
}
}

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.bldrs; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.data.*;
public interface Xob_ns_to_db_wkr {
byte Db_tid();
void Tbl_init(Xowd_db_file db);
void Tbl_term(Xowd_db_file db);
}

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.bldrs.aria2; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.xowa.apps.fsys.*;
public class Aria2_lib_mgr implements GfoInvkAble {
public ProcessAdp Lib() {return lib;} private ProcessAdp lib = new ProcessAdp();
public void Init_by_app(Xoae_app app) {
Xoa_fsys_eval cmd_eval = app.Url_cmd_eval();
ProcessAdp.ini_(this, app.Usr_dlg(), lib, cmd_eval, ProcessAdp.Run_mode_sync_block, Int_.MaxValue
, "~{<>bin_plat_dir<>}aria2" + Op_sys.Cur().Fsys_dir_spr_str() + "aria2c"
, Lib_args_fmt
, "wiki_abrv", "wiki_date", "wiki_type");
}
// private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public void Exec(Xob_dump_file dump_file) {
// byte[] args_bry = lib.Args_fmtr().Bld_bry_many(tmp_bfr, dump_file.Wiki_alias(), dump_file.Dump_date(), dump_file.Dump_file_type());
// ProcessAdp process = new ProcessAdp().Exe_url_(lib.Exe_url()).Args_str_(String_.new_u8(args_bry));
// process.Run_wait();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_lib)) return lib;
else return GfoInvkAble_.Rv_unhandled;
}
private static final String Invk_lib = "lib";
private static final String Lib_args_fmt = String_.Concat
( "--max-connection-per-server=2"
, " --max-concurrent-downloads=20"
, " --split=4"
, " --file-allocation=prealloc"
, " --remote-time=true"
, " --server-stat-of=serverstats.txt"
, " ftp://ftpmirror.your.org/pub/wikimedia/dumps/~{wiki_abrv}/~{wiki_date}/~{wiki_abrv}-~{wiki_date}-~{wiki_type}.bz2"
, " https://dumps.wikimedia.org/~{wiki_abrv}/~{wiki_date}/~{wiki_abrv}-~{wiki_date}-~{wiki_type}.xml.bz2"
);
}

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.bldrs.aria2; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.gfui.*;
class Gfui_process_win {
public void Exec_async(String process, String args, GfoInvkAbleCmd done_cbk) {
// Gfo_process process = new Gfo_process().Init_process_(process, args).Init_async_(done_cbk).Init_strm_out_err_(output_box).Exec();
}
}
class Gfo_process {
// private GfoInvkAbleCmd done_cbk;
// private Gfo_process_wtr out_wtr, err_wtr;
public String Cmd_path() {return cmd_path;} private String cmd_path;
public String Cmd_args() {return cmd_args;} private String cmd_args;
public byte Mode() {return mode;} private byte mode;
public Gfo_process Init_cmd_(String cmd_path, String cmd_args) {this.cmd_path = cmd_path; this.cmd_args = cmd_args; return this;}
public Gfo_process Init_mode_async_() {mode = Gfo_process_.Mode_async; return this;}
// public Gfo_process Init_mode_async_(GfoInvkAbleCmd done_cbk) {this.done_cbk = done_cbk; return this.Init_mode_async_();}
// public Gfo_process Init_wtr_out_err_(Gfo_process_wtr wtr) {out_wtr = err_wtr = wtr; return this;}
}
class Gfo_process_wtr {}
class Gfo_process_rdr {}
class Gfo_process_ {
public static final byte Mode_async = 0, Mode_sync = 1, Mode_sync_timeout = 2;
}

View File

@@ -0,0 +1,56 @@
/*
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.bldrs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.core.strings.*;
public class Xob_wiki_cfg_bldr implements GfoInvkAble {
public Xob_wiki_cfg_bldr(Xob_bldr bldr) {this.app = bldr.App();} private Xoae_app app;
public void Exec() {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Xoac_wiki_cfg_bldr_fil fil = (Xoac_wiki_cfg_bldr_fil)hash.Get_at(i);
Exec_fil(fil);
}
}
private void Exec_fil(Xoac_wiki_cfg_bldr_fil fil) {
String wiki_key = fil.Wiki();
Io_url cfg_file = app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki_key + ".gfs");
String cfg_text = Io_mgr.I.LoadFilStr_args(cfg_file).MissingIgnored_().Exec();
int len = fil.Itms_count();
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < len; i++) {
Xoac_wiki_cfg_bldr_cmd cmd = fil.Itms_get_at(i);
cfg_text = cmd.Exec(sb, wiki_key, cfg_text);
}
Io_mgr.I.SaveFilStr(cfg_file, cfg_text);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Itms_get_or_new(m.ReadStr("v"));
else if (ctx.Match(k, Invk_run)) Exec();
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_get = "get", Invk_run = "run";
public void Clear() {hash.Clear();}
public Xoac_wiki_cfg_bldr_fil Itms_get_or_new(String wiki) {
Xoac_wiki_cfg_bldr_fil rv = (Xoac_wiki_cfg_bldr_fil)hash.Get_by(wiki);
if (rv == null) {
rv = new Xoac_wiki_cfg_bldr_fil(wiki);
hash.Add(wiki, rv);
}
return rv;
} private Ordered_hash hash = Ordered_hash_.new_();
}

View File

@@ -0,0 +1,179 @@
/*
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.bldrs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import org.junit.*; import gplx.core.strings.*;
public class Xob_wiki_cfg_bldr_tst {
Xob_wiki_cfg_bldr_fxt fxt = new Xob_wiki_cfg_bldr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Exec() {
fxt .Init_cmd("en.wikipedia.org", "key0", "en.val0")
.Init_cmd("en.wikipedia.org", "key1", "en.val1")
.Init_cmd("fr.wikipedia.org", "key0", "fr.val0")
.Init_cmd("fr.wikipedia.org", "key1", "fr.val1")
.Expd_txt("en.wikipedia.org", String_.Concat_lines_nl
( "// key0.bgn"
, "en.val0"
, "// key0.end"
, "// key1.bgn"
, "en.val1"
, "// key1.end"
))
.Expd_txt("fr.wikipedia.org", String_.Concat_lines_nl
( "// key0.bgn"
, "fr.val0"
, "// key0.end"
, "// key1.bgn"
, "fr.val1"
, "// key1.end"
))
.Test()
;
fxt .Clear()
.Init_cmd("en.wikipedia.org", "key2", "en.val2")
.Expd_txt("en.wikipedia.org", String_.Concat_lines_nl
( "// key0.bgn"
, "en.val0"
, "// key0.end"
, "// key1.bgn"
, "en.val1"
, "// key1.end"
, "// key2.bgn"
, "en.val2"
, "// key2.end"
));
}
// @Test public void Lang_names_run() {
// Io_url dir = Io_url_.new_dir_("/var/www/mediawiki/languages/messages/");
// Io_url[] fils = Io_mgr.I.QueryDir_args(dir).ExecAsUrlAry();
// int fils_len = fils.length;
// String_bldr sb = String_bldr_.new_();
// for (int i = 0; i < fils_len; i++) {
// Io_url fil = fils[i];
// String lang_code = String_.Lower(String_.Replace(fil.NameOnly(), "Messages", ""));
// String txt = Io_mgr.I.LoadFilStr(fil);
// String[] lines = String_.Split(txt, '\n');
// String line = lines[1];
// line = String_.Replace(line, "/** ", "");
// int pos = String_.FindBwd(line, " (");
// if (pos == String_.Find_none) continue; // en; en_rtl have no "language" line
// if ( String_.Has_at_bgn(lang_code, "be_")
// || String_.Has_at_bgn(lang_code, "crh_")
// || String_.Has_at_bgn(lang_code, "kk_")
// || String_.Has_at_bgn(lang_code, "ku_")
// || String_.Has_at_bgn(lang_code, "sr_")
// || String_.In(lang_code, "de_formal", "nb", "nl_informal", "nn", "no")
// ) {
// int new_pos = String_.FindBwd(line, " (", pos - 1);
// if (new_pos != String_.Find_none)
// pos = new_pos;
// }
// line = Replace_by_pos(line, pos, pos + 2, "|");
// int line_len = String_.Len(line);
// if (line_len > 0)
// line = String_.MidByLen(line, 0, line_len - 1);
// String[] terms = String_.Split(line, '|');
// sb.Add(lang_code).Add("|").Add(String_.Trim(terms[0])).Add("|").Add(String_.Trim(terms[1])).Add("\n");
// }
// Tfds.Write(sb.Xto_str_and_clear());
// }
@Test public void Ns_aliases() {
Io_mgr.I.InitEngine_mem();
Io_mgr.I.SaveFilStr("mem/en.wikipedia.org/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases", String_.Concat_lines_nl
( "<api>"
, "<query>"
, "<namespacealiases>"
, "<ns id=\"4\" xml:space=\"preserve\">WP"
, "</ns>"
, "<ns id=\"5\" xml:space=\"preserve\">WT"
, "</ns>"
, "<ns id=\"6\" xml:space=\"preserve\">Image"
, "</ns>"
, "<ns id=\"7\" xml:space=\"preserve\">Image talk"
, "</ns>"
, "</namespacealiases>"
, "</query>"
, "</api>"
));
String[] wikis = new String[] {"en.wikipedia.org"}; String protocol = "mem/";
Tfds.Eq_str_lines(Query_ns(protocol, gplx.ios.IoEngine_.MemKey, wikis), String_.Concat_lines_nl
( "app.bldr.wiki_cfg_bldr.get('en.wikipedia.org').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\""
, "4|WP"
, "5|WT"
, "6|Image"
, "7|Image_talk"
, "\");');"
));
}
String Query_ns(String protocol, String trg_engine_key, String[] wikis) {
String_bldr sb = String_bldr_.new_();
int wikis_len = wikis.length;
for (int i = 0; i < wikis_len; i++) {
String wiki = wikis[i];
if (String_.Len_eq_0(wiki)) continue;
try {
String api = protocol + wiki + "/w/api.php?action=query&format=xml&meta=siteinfo&siprop=namespacealiases";
String xml = String_.new_u8(Io_mgr.I.DownloadFil_args("", null).Trg_engine_key_(trg_engine_key).Exec_as_bry(api));
if (xml == null) continue; // not found
gplx.xmls.XmlDoc xdoc = gplx.xmls.XmlDoc_.parse_(xml);
gplx.xmls.XmlNde xnde = gplx.xmls.Xpath_.SelectFirst(xdoc.Root(), "query/namespacealiases");
sb.Add("app.bldr.wiki_cfg_bldr.get('").Add(wiki).Add("').new_cmd_('wiki.ns_mgr.aliases', 'ns_mgr.add_alias_bulk(\"\n");
int xndes_len = xnde.SubNdes().Count();
for (int j = 0; j < xndes_len; j++) {
gplx.xmls.XmlNde ns_nde = xnde.SubNdes().Get_at(j);
if (!String_.Eq(ns_nde.Name(), "ns")) continue;
int id = Int_.parse_(ns_nde.Atrs().FetchValOr("id", "-1"));
String name = String_.Replace(String_.Replace(ns_nde.Text_inner(), " ", "_"), "'", "''");
sb.Add(Int_.Xto_str(id)).Add("|").Add(String_.Trim(name)).Add_char_nl();
}
sb.Add("\");');\n");
}
catch(Exception e) {sb.Add("// fail: " + wiki + " " + Err_.Message_gplx_brief(e)).Add_char_nl();}
}
return sb.Xto_str_and_clear();
}
}
class Xob_wiki_cfg_bldr_fxt {
public Xob_wiki_cfg_bldr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.app_();
wiki_cfg_bldr = app.Bldr().Wiki_cfg_bldr();
}
wiki_cfg_bldr.Clear();
hash.Clear();
return this;
} private Xoae_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; Ordered_hash hash = Ordered_hash_.new_();
public Xob_wiki_cfg_bldr_fxt Init_cmd(String wiki, String key, String text) {
wiki_cfg_bldr.Itms_get_or_new(wiki).Itms_add(key, text);
return this;
}
public Xob_wiki_cfg_bldr_fxt Expd_txt(String wiki, String text) {
hash.Add(wiki, KeyVal_.new_(wiki, text));
return this;
}
public void Test() {
wiki_cfg_bldr.Exec();
int len = hash.Count();
for (int i = 0; i < len; i++) {
KeyVal kv = (KeyVal)hash.Get_at(i);
String wiki = kv.Key();
String expd = (String)kv.Val();
String actl = Io_mgr.I.LoadFilStr(app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(wiki + ".gfs"));
Tfds.Eq_str_lines(expd, actl);
}
}
}

View File

@@ -0,0 +1,315 @@
/*
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.bldrs.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.dbs.*; import gplx.xowa.wikis.caches.*; import gplx.xowa.bldrs.cmds.files.*; import gplx.xowa.files.origs.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.dbs.*; import gplx.xowa.wikis.data.tbls.*;
public abstract class Xob_dump_mgr_base extends Xob_itm_basic_base implements Xob_cmd, GfoInvkAble {
private Xob_dump_src_id page_src;
private Xowd_db_mgr db_fsys_mgr; protected Xop_parser parser; protected Xop_ctx ctx; protected Xop_root_tkn root;
private int[] ns_ary; private Xowd_db_file[] db_ary;
private int ns_bgn = -1, db_bgn = -1, pg_bgn = -1;
private int ns_end = -1, db_end = -1, pg_end = Int_.MaxValue;
private int commit_interval = 1000, progress_interval = 250, cleanup_interval = 2500, select_size = 10 * Io_mgr.Len_mb;
private int exec_count, exec_count_max = Int_.MaxValue;
private boolean reset_db = false, exit_after_commit = false, exit_now = false;
private boolean load_tmpls;
private Xob_dump_bmk_mgr bmk_mgr = new Xob_dump_bmk_mgr();
private Xobu_poll_mgr poll_mgr; private int poll_interval = 5000;
private Xob_rate_mgr rate_mgr = new Xob_rate_mgr();
public abstract String Cmd_key();
@Override protected void Cmd_ctor_end(Xob_bldr bldr, Xowe_wiki wiki) {
poll_mgr = new Xobu_poll_mgr(bldr.App()); // init in ctor so gfs can invoke methods
}
public void Cmd_bgn(Xob_bldr bldr) {
parser = wiki.Parser();
ctx = wiki.Ctx();
root = ctx.Tkn_mkr().Root(Bry_.Empty);
wiki.Init_assert(); // NOTE: must init wiki for db_mgr_as_sql
wiki.Db_mgr_as_sql().Core_data_mgr().Init_by_load(gplx.xowa.wikis.Xow_fsys_mgr.Find_core_fil(wiki)); // NOTE: must reinit providers as previous steps may have rls'd (and left member variable conn which is closed)
wiki.File__orig_mgr().Wkrs_del(Xof_orig_wkr_.Tid_wmf_api);
db_fsys_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
db_ary = Xob_dump_mgr_base_.Init_text_files_ary(db_fsys_mgr);
poll_interval = poll_mgr.Poll_interval();
page_src = new Xob_dump_src_id().Init(wiki, this.Init_redirect(), select_size);
ns_ary = Init_ns_ary();
Db_conn conn = Init_db_file();
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
bmk_mgr.Cfg_url_(wiki_dir.GenSubFil("xowa.file.make.cfg.gfs"));
rate_mgr.Log_file_(wiki_dir.GenSubFil("xowa.file.make.log.csv"));
if (reset_db) {
bmk_mgr.Reset();
Init_reset(conn);
}
bmk_mgr.Load(wiki.Appe(), this);
Cmd_bgn_end();
}
protected abstract void Cmd_bgn_end();
public abstract byte Init_redirect();
public abstract int[] Init_ns_ary();
protected abstract void Init_reset(Db_conn p);
protected abstract Db_conn Init_db_file();
private long time_bgn;
public void Cmd_run() {Exec_ns_ary();}
private void Exec_ns_ary() {
if (pg_bgn == Int_.MaxValue) return;
if (load_tmpls) Xob_dump_mgr_base_.Load_all_tmpls(usr_dlg, wiki, page_src);
time_bgn = Env_.TickCount();
Xob_dump_bmk dump_bmk = new Xob_dump_bmk();
rate_mgr.Init();
int ns_ary_len = ns_ary.length;
for (int i = 0; i < ns_ary_len; i++) {
int ns_id = ns_ary[i];
if (ns_bgn != -1) { // ns_bgn set
if (ns_id == ns_bgn) // ns_id is ns_bgn; null out ns_bgn and continue
ns_bgn = -1;
else // ns_id is not ns_bgn; keep looking
continue;
}
dump_bmk.Ns_id_(ns_id);
Exec_db_ary(i, dump_bmk, ns_id);
if (ns_id == ns_end) exit_now = true; // ns_end set; exit
if (exit_now) break; // exit_now b/c of pg_bgn, db_bgn or something else
}
Exec_commit(dump_bmk.Ns_id(), dump_bmk.Db_id(), dump_bmk.Pg_id(), Bry_.Empty);
}
private void Exec_db_ary(int ns_ord, Xob_dump_bmk dump_bmk, int ns_id) {
int db_ary_len = db_ary.length;
for (int i = 0; i < db_ary_len; i++) {
int db_id = db_ary[i].Id();
if (db_bgn != -1) { // db_bgn set
if (db_id == db_bgn) // db_id is db_bgn; null out db_bgn and continue
db_bgn = -1;
else // db_id is not db_bgn; keep looking
continue;
}
dump_bmk.Db_id_(db_id);
Exec_db_itm(dump_bmk, ns_ord, ns_id, db_id);
if (db_id == db_end) exit_now = true; // db_end set; exit;
if (exit_now) return; // exit_now b/c of pg_bgn, db_bgn or something else
}
}
private void Exec_db_itm(Xob_dump_bmk dump_bmk, int ns_ord, int ns_id, int db_id) {
List_adp pages = List_adp_.new_();
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
int pg_id = pg_bgn;
while (true) {
page_src.Get_pages(pages, db_id, ns_id, pg_id);
int pages_len = pages.Count();
if (pages_len == 0) { // no more pages in db;
if (pg_id > pg_bgn) // reset pg_bgn to 0 only if pg_bgn seen;
pg_bgn = 0;
return;
}
usr_dlg.Prog_many("", "", "fetched pages: ~{0}", pages_len);
for (int i = 0; i < pages_len; i++) {
Xowd_page_itm page = (Xowd_page_itm)pages.Get_at(i);
dump_bmk.Pg_id_(pg_id);
Exec_pg_itm(ns_ord, ns, db_id, page);
if ( pg_id >= pg_end
|| exec_count >= exec_count_max) {
exit_now = true;
}
if (exit_now) return;
pg_id = page.Id();
}
}
}
private void Exec_pg_itm(int ns_ord, Xow_ns ns, int db_id, Xowd_page_itm page) {
try {
if ((exec_count % progress_interval) == 0)
usr_dlg.Prog_many("", "", "parsing: ns=~{0} db=~{1} pg=~{2} count=~{3} time=~{4} rate=~{5} ttl=~{6}"
, ns.Id(), db_id, page.Id(), exec_count
, Env_.TickCount_elapsed_in_sec(time_bgn), rate_mgr.Rate_as_str(), String_.new_u8(page.Ttl_page_db()));
ctx.Clear();
Exec_pg_itm_hook(ns_ord, ns, page, page.Text());
ctx.App().Utl__bfr_mkr().Clear_fail_check(); // make sure all bfrs are released
if (ctx.Wiki().Cache_mgr().Tmpl_result_cache().Count() > 50000)
ctx.Wiki().Cache_mgr().Tmpl_result_cache().Clear();
++exec_count;
rate_mgr.Increment();
if ((exec_count % poll_interval) == 0)
poll_mgr.Poll();
if ((exec_count % commit_interval) == 0)
Exec_commit(ns.Id(), db_id, page.Id(), page.Ttl_page_db());
if ((exec_count % cleanup_interval) == 0)
Free();
}
catch (Exception exc) {
bldr.Usr_dlg().Warn_many(GRP_KEY, "parse", "failed to parse ~{0} error ~{1}", String_.new_u8(page.Ttl_page_db()), Err_.Message_lang(exc));
ctx.App().Utl__bfr_mkr().Clear();
this.Free();
}
}
public abstract void Exec_pg_itm_hook(int ns_ord, Xow_ns ns, Xowd_page_itm page, byte[] page_text);
private void Exec_commit(int ns_id, int db_id, int pg_id, byte[] ttl) {
usr_dlg.Prog_many("", "", "committing: ns=~{0} db=~{1} pg=~{2} count=~{3} ttl=~{4}", ns_id, db_id, pg_id, exec_count, String_.new_u8(ttl));
Exec_commit_hook();
bmk_mgr.Save(ns_id, db_id, pg_id);
if (exit_after_commit) exit_now = true;
}
public abstract void Exec_commit_hook();
public abstract void Exec_end_hook();
public void Cmd_init(Xob_bldr bldr) {}
public void Cmd_term() {}
public void Cmd_end() {
if (!exit_now)
pg_bgn = Int_.MaxValue;
Exec_commit(-1, -1, -1, Bry_.Empty);
Exec_end_hook();
Free();
usr_dlg.Note_many("", "", "done: ~{0} ~{1}", exec_count, DecimalAdp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).Xto_str("#,###.000"));
}
private void Free() {
ctx.App().Free_mem(true);
gplx.xowa.xtns.scribunto.Scrib_core.Core_invalidate();
wiki.Cache_mgr().Free_mem_all();
}
protected void Reset_db_y_() {this.reset_db = true;}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_progress_interval_)) progress_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_rate_interval_)) rate_mgr.Reset_interval_(m.ReadInt("v"));
else if (ctx.Match(k, Invk_cleanup_interval_)) cleanup_interval = m.ReadInt("v");
else if (ctx.Match(k, Invk_select_size_)) select_size = m.ReadInt("v") * Io_mgr.Len_mb;
else if (ctx.Match(k, Invk_ns_bgn_)) {ns_bgn = m.ReadInt("v"); Notify_restoring("ns", ns_bgn);}
else if (ctx.Match(k, Invk_db_bgn_)) {db_bgn = m.ReadInt("v"); Notify_restoring("db", db_bgn);}
else if (ctx.Match(k, Invk_pg_bgn_)) {pg_bgn = m.ReadInt("v"); Notify_restoring("pg", pg_bgn);}
else if (ctx.Match(k, Invk_ns_end_)) ns_end = m.ReadInt("v");
else if (ctx.Match(k, Invk_db_end_)) db_end = m.ReadInt("v");
else if (ctx.Match(k, Invk_pg_end_)) pg_end = m.ReadInt("v");
else if (ctx.Match(k, Invk_load_tmpls_)) load_tmpls = m.ReadYn("v");
else if (ctx.Match(k, Invk_poll_mgr)) return poll_mgr;
else if (ctx.Match(k, Invk_reset_db_)) reset_db = m.ReadYn("v");
else if (ctx.Match(k, Invk_exec_count_max_)) exec_count_max = m.ReadInt("v");
else if (ctx.Match(k, Invk_exit_now_)) exit_now = m.ReadYn("v");
else if (ctx.Match(k, Invk_exit_after_commit_)) exit_after_commit = m.ReadYn("v");
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private void Notify_restoring(String itm, int val) {
usr_dlg.Note_many("", "", "restoring: itm=~{0} val=~{1}", itm, val);
}
public static final String
Invk_progress_interval_ = "progress_interval_", Invk_commit_interval_ = "commit_interval_", Invk_cleanup_interval_ = "cleanup_interval_", Invk_rate_interval_ = "rate_interval_"
, Invk_select_size_ = "select_size_"
, Invk_ns_bgn_ = "ns_bgn_", Invk_db_bgn_ = "db_bgn_", Invk_pg_bgn_ = "pg_bgn_"
, Invk_ns_end_ = "ns_end_", Invk_db_end_ = "db_end_", Invk_pg_end_ = "pg_end_"
, Invk_load_tmpls_ = "load_tmpls_"
, Invk_poll_mgr = "poll_mgr", Invk_reset_db_ = "reset_db_"
, Invk_exec_count_max_ = "exec_count_max_", Invk_exit_now_ = "exit_now_", Invk_exit_after_commit_ = "exit_after_commit_"
;
private static final String GRP_KEY = "xowa.bldr.parse";
}
class Xob_dump_mgr_base_ {
public static void Load_all_tmpls(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, Xob_dump_src_id page_src) {
List_adp pages = List_adp_.new_();
Xow_ns ns_tmpl = wiki.Ns_mgr().Ns_template();
Xow_defn_cache defn_cache = wiki.Cache_mgr().Defn_cache();
int cur_page_id = -1;
int load_count = 0;
usr_dlg.Note_many("", "", "tmpl_load init");
while (true) {
page_src.Get_pages(pages, 0, Xow_ns_.Id_template, cur_page_id); // 0 is always template db
int page_count = pages.Count();
if (page_count == 0) break; // no more pages in db;
Xowd_page_itm page = null;
for (int i = 0; i < page_count; i++) {
page = (Xowd_page_itm)pages.Get_at(i);
Xot_defn_tmpl defn = new Xot_defn_tmpl();
defn.Init_by_new(ns_tmpl, ns_tmpl.Gen_ttl(page.Ttl_page_db()), page.Text(), null, false); // NOTE: passing null, false; will be overriden later when Parse is called
defn_cache.Add(defn, ns_tmpl.Case_match());
++load_count;
if ((load_count % 10000) == 0) usr_dlg.Prog_many("", "", "tmpl_loading: ~{0}", load_count);
}
cur_page_id = page.Id();
}
usr_dlg.Note_many("", "", "tmpl_load done: ~{0}", load_count);
}
public static Xowd_db_file[] Init_text_files_ary(Xowd_db_mgr core_data_mgr) {
List_adp text_files_list = List_adp_.new_();
int len = core_data_mgr.Dbs__len();
if (len == 1) return new Xowd_db_file[] {core_data_mgr.Dbs__get_at(0)}; // single file: return core; note that there are no Tid = Text
for (int i = 0; i < len; i++) {
Xowd_db_file file = core_data_mgr.Dbs__get_at(i);
switch (file.Tid()) {
case Xowd_db_file_.Tid_text:
case Xowd_db_file_.Tid_text_solo:
text_files_list.Add(file);
break;
}
}
return (Xowd_db_file[])text_files_list.To_ary_and_clear(Xowd_db_file.class);
}
}
class Xob_dump_bmk_mgr {
private Bry_bfr save_bfr = Bry_bfr.reset_(1024);
public Io_url Cfg_url() {return cfg_url;} public Xob_dump_bmk_mgr Cfg_url_(Io_url v) {cfg_url = v; return this;} private Io_url cfg_url;
public void Reset() {Io_mgr.I.DeleteFil(cfg_url);}
public void Load(Xoae_app app, Xob_dump_mgr_base dump_mgr) {
app.Gfs_mgr().Run_url_for(dump_mgr, cfg_url);
}
public void Save(int ns_id, int db_id, int pg_id) {
Save_itm(save_bfr, Xob_dump_mgr_base.Invk_ns_bgn_, ns_id);
Save_itm(save_bfr, Xob_dump_mgr_base.Invk_db_bgn_, db_id);
Save_itm(save_bfr, Xob_dump_mgr_base.Invk_pg_bgn_, pg_id);
Io_mgr.I.SaveFilBfr(cfg_url, save_bfr);
}
private void Save_itm(Bry_bfr save_bfr, String key, int val) {
String fmt = "{0}('{1}');\n";
String str = String_.Format(fmt, key, val);
save_bfr.Add_str(str);
}
}
class Xob_rate_mgr {
private long time_bgn;
private int item_len;
private Bry_bfr save_bfr = Bry_bfr.reset_(255);
public int Reset_interval() {return reset_interval;} public Xob_rate_mgr Reset_interval_(int v) {reset_interval = v; return this;} private int reset_interval = 10000;
public Io_url Log_file() {return log_file;} public Xob_rate_mgr Log_file_(Io_url v) {log_file = v; return this;} private Io_url log_file;
public void Init() {time_bgn = Env_.TickCount();}
public void Increment() {
++item_len;
if (item_len % reset_interval == 0) {
long time_end = Env_.TickCount();
Save(item_len, time_bgn, time_end);
time_bgn = time_end;
item_len = 0;
}
}
private void Save(int count, long bgn, long end) {
int dif = (int)(end - bgn) / 1000;
DecimalAdp rate = DecimalAdp_.divide_safe_(count, dif);
save_bfr
.Add_str(rate.Xto_str("#,##0.000")).Add_byte_pipe()
.Add_int_variable(count).Add_byte_pipe()
.Add_int_variable(dif).Add_byte_nl()
;
Io_mgr.I.AppendFilByt(log_file, save_bfr.Xto_bry_and_clear());
}
public String Rate_as_str() {return Int_.Xto_str(Rate());}
public int Rate() {
int elapsed = Env_.TickCount_elapsed_in_sec(time_bgn);
return Math_.Div_safe_as_int(item_len, elapsed);
}
}
class Xob_dump_bmk {
public int Ns_id() {return ns_id;} public Xob_dump_bmk Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
public int Db_id() {return db_id;} public Xob_dump_bmk Db_id_(int v) {db_id = v; return this;} private int db_id;
public int Pg_id() {return pg_id;} public Xob_dump_bmk Pg_id_(int v) {pg_id = v; return this;} private int pg_id;
}

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.bldrs.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.xowa.wikis.data.*;
public class Xob_ns_file_itm {
public Xob_ns_file_itm(byte db_file_tid, String file_name, int[] ns_ids) {
this.db_file_tid = db_file_tid; this.file_name = file_name; this.ns_ids = ns_ids;
this.nth_db_id = Nth_db_id_null; this.nth_db_idx = 1;
}
public byte Db_file_tid() {return db_file_tid;} private final byte db_file_tid;
public String File_name() {return file_name;} private final String file_name;
public int[] Ns_ids() {return ns_ids;} private final int[] ns_ids;
public int Nth_db_id() {return nth_db_id;} public void Nth_db_id_(int v) {nth_db_id = v;} private int nth_db_id;
public int Nth_db_idx() {return nth_db_idx;} private int nth_db_idx;
public String Make_file_name() { // EX: en.wikipedia.org-text-ns.000-001.xowa
String rv = String_.Format("-{0}{1}{2}.xowa" // EX: -text-ns.000-db.001.xowa
, Xowd_db_file_.To_key(db_file_tid) // text
, String_.Len_eq_0(file_name) ? "" : "-" + file_name // if empty, don't add "ns.000" segment; produces en.wikipedia.org-text-001.xowa
, nth_db_idx == 1 ? "" : "-db." + Int_.Xto_str_pad_bgn_zero(nth_db_idx, 3) // "-db.001"
);
++nth_db_idx;
return rv;
}
public static final int Nth_db_id_null = -1;
public static void Init_ns_bldr_data(byte db_file_tid, Xow_ns_mgr ns_mgr, byte[] ns_file_map) {
int ns_len = ns_mgr.Ords_len();
Xob_ns_file_itm ns_file_itm_default = new Xob_ns_file_itm(db_file_tid, "", null);
for (int i = 0; i < ns_len; ++i) {
Xow_ns ns = ns_mgr.Ords_get_at(i);
ns.Bldr_data_(ns_file_itm_default);
}
Xob_ns_file_itm_parser ns_itm_parser = new Xob_ns_file_itm_parser();
ns_itm_parser.Ctor(db_file_tid, ns_mgr);
Xob_ns_file_itm[] ns_itm_ary = ns_itm_parser.To_ary(ns_file_map);
int ns_itm_ary_len = ns_itm_ary.length;
for (int i = 0; i < ns_itm_ary_len; ++i) {
Xob_ns_file_itm itm = ns_itm_ary[i];
int[] ns_ids = itm.Ns_ids();
int ns_ids_len = ns_ids.length;
for (int j = 0; j < ns_ids_len; j++) {
int ns_id = ns_ids[j];
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id); if (ns == null) continue; // some dumps may not have ns; for example, pre-2013 dumps won't have Module (828)
ns.Bldr_data_(itm);
}
}
}
}

View File

@@ -0,0 +1,79 @@
/*
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.bldrs.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.srls.dsvs.*;
public class Xob_ns_file_itm_parser extends Dsv_wkr_base {
private byte[] ns_ids_bry; private String name; private final List_adp rslts = List_adp_.new_();
private Xow_ns_mgr ns_mgr; private byte db_file_tid; private boolean mode_each = false;
public void Ctor(byte db_file_tid, Xow_ns_mgr ns_mgr) {
this.db_file_tid = db_file_tid; this.ns_mgr = ns_mgr;
this.mode_each = false; rslts.Clear();
}
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser};}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {
case 0: ns_ids_bry = Bry_.Mid(src, bgn, end); return true;
case 1: name = String_.new_u8(src, bgn, end); return true;
default: return false;
}
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
if (ns_ids_bry == null) throw parser.Err_row_bgn("ns_itm missing ns_ids", pos);
if (mode_each) return;
if (Bry_.Eq(ns_ids_bry, ns_ids_bry_each)) {
mode_each = true;
int len = ns_mgr.Ords_len();
for (int i = 0; i < len; ++i) {
Xow_ns ns = ns_mgr.Ords_get_at(i);
int ns_id = ns.Id();
rslts.Add(new Xob_ns_file_itm(db_file_tid, "ns." + Int_.Xto_str_pad_bgn_zero(ns_id, 3), Int_.Ary(ns_id)));
}
return;
}
int[] ns_ids = null;
if (ns_ids_bry.length == 1 && ns_ids_bry[0] == Byte_ascii.Star) { // "*"
int len = ns_mgr.Ords_len();
ns_ids = new int[len];
for (int i = 0; i < len; ++i)
ns_ids[i] = ns_mgr.Ords_get_at(i).Id();
}
else
ns_ids = Int_.Ary_parse(String_.new_u8(ns_ids_bry), ",");
if (ns_ids.length == 0) throw Exc_.new_("map.invalid.ns_missing", "src", this.Src());
if (String_.Len_eq_0(name)) { // no name; auto-generate
int ns_id_1st = ns_ids[0]; // take 1st ns_id
name = "ns." + Int_.Xto_str_pad_bgn_zero(ns_id_1st, 3); // EX: ns.000
}
Xob_ns_file_itm ns_itm = new Xob_ns_file_itm(db_file_tid, name, ns_ids);
rslts.Add(ns_itm);
ns_itm.toString();
ns_ids = null; name = null;
}
public Xob_ns_file_itm[] To_ary(byte[] bry) {
this.Load_by_bry(bry);
return (Xob_ns_file_itm[])rslts.To_ary(Xob_ns_file_itm.class);
}
private static final byte[] ns_ids_bry_each = Bry_.new_a7("<each>");
/*
"" -> no rules; return "default"; generates "text-001" and lumps all ns into it
"*|<id>|3700|2" -> auto-generate per ns
<single-file>
<all>||gzip
<each>||gzip
*/
}

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.bldrs.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.xowa.wikis.data.*; import gplx.xowa.dbs.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.data.tbls.*;
class Xob_dump_src_id {
private Xodb_mgr_sql db_mgr; private byte redirect;
private String page_db_url; private int size_max;
private Db_stmt text_stmt; int cur_text_db_idx = -1;
public Xob_dump_src_id Init(Xowe_wiki wiki, byte redirect, int size_max) {
this.db_mgr = wiki.Db_mgr_as_sql(); this.redirect = redirect;
this.size_max = size_max;
this.page_db_url = db_mgr.Core_data_mgr().Db__core().Url().Raw();
return this;
}
public void Get_pages(List_adp list, int text_db_idx, int cur_ns, int prv_id) {
DataRdr rdr = DataRdr_.Null;
int size_len = 0;
list.Clear();
try {
rdr = New_rdr(db_mgr, page_db_url, text_db_idx, cur_ns, prv_id, redirect);
while (rdr.MoveNextPeer()) {
Xowd_page_itm page = New_page(db_mgr, cur_ns, rdr);
list.Add(page);
size_len += page.Text_len();
if (size_len > size_max)
break;
}
}
finally {rdr.Rls();}
}
private DataRdr New_rdr(Xodb_mgr_sql db_mgr, String page_db_url, int text_db_idx, int cur_ns, int prv_id, byte redirect) {
if (cur_text_db_idx != text_db_idx) {
cur_text_db_idx = text_db_idx;
Xowd_db_file text_db = db_mgr.Core_data_mgr().Dbs__get_at(text_db_idx);
Db_conn conn = text_db.Conn();
String sql = String_.Format(Sql_select, New_rdr__redirect_clause(redirect));
text_stmt = conn.Stmt_new(Db_qry_sql.rdr_(sql));
}
return text_stmt.Clear().Val_int(prv_id).Val_int(cur_ns).Exec_select();
}
private static Xowd_page_itm New_page(Xodb_mgr_sql db_mgr, int ns_id, DataRdr rdr) {
Xowd_page_tbl page_core_tbl = db_mgr.Core_data_mgr().Tbl__page();
Xowd_page_itm rv = new Xowd_page_itm();
rv.Id_(rdr.ReadInt(page_core_tbl.Fld_page_id()));
rv.Ns_id_(ns_id);
rv.Ttl_page_db_(rdr.ReadBryByStr(page_core_tbl.Fld_page_title()));
String text_data_name = db_mgr.Core_data_mgr().Db__core().Tbl__text().Fld_text_data();
byte[] text_data = rdr.ReadBry(text_data_name);
text_data = db_mgr.Wiki().Appe().Zip_mgr().Unzip(db_mgr.Core_data_mgr().Props().Zip_tid_text(), text_data);
rv.Text_(text_data);
return rv;
}
private static String New_rdr__redirect_clause(byte redirect) {
switch (redirect) {
case Bool_.Y_byte: return Sql_select__redirect_y;
case Bool_.N_byte: return Sql_select__redirect_n;
case Bool_.__byte: return Sql_select__redirect__;
default: throw Exc_.new_unhandled(redirect);
}
}
private static final String Sql_select = String_.Concat_lines_nl
( "SELECT p.page_id"
, ", p.page_title"
, ", t.text_data"
, "FROM page_dump p"
, " JOIN text t ON t.page_id = p.page_id"
, "WHERE p.page_id > ?"
, "AND p.page_namespace = ?{0}"
, "ORDER BY p.page_id"
);
private static final String
Sql_select__redirect_y = "\nAND p.page_is_redirect = 1"
, Sql_select__redirect_n = "\nAND p.page_is_redirect = 0"
, Sql_select__redirect__ = ""
;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
/*
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.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
import org.junit.*; import gplx.xowa.bldrs.*;
public class Uca_trie_tst {
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
@Test public void Basic() {
Uca_trie_fxt fxt = new Uca_trie_fxt();
fxt.Clear();
fxt.Init_trie_itm("a", Bry_.ints_(10, 11));
fxt.Init_trie_itm("b", Bry_.ints_(20, 21));
fxt.Init_trie_itm("c", Bry_.ints_(30, 31));
fxt.Test_decode(Bry_.ints_(10, 11), "a");
fxt.Test_decode(Bry_.ints_(10, 11, 20, 21, 30, 31), "abc");
}
}
class Uca_trie_fxt {
public void Clear() {
if (trie == null) {
trie = new Uca_trie();
bfr = Bry_bfr.new_();
}
trie.Clear();
} Uca_trie trie; Bry_bfr bfr;
public void Init_trie_itm(String charAsStr, byte[] uca) {trie.Init_itm(gplx.intl.Utf16_.Decode_to_int(Bry_.new_u8(charAsStr), 0), uca);}
public void Test_decode(byte[] bry, String expd) {
trie.Decode(bfr, bry, 0, bry.length);
Tfds.Eq(expd, bfr.Xto_str_and_clear());
}
}

View File

@@ -0,0 +1,54 @@
/*
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.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.*;
public class Xob_category_registry_sql implements Xob_cmd {
public Xob_category_registry_sql(Xob_bldr bldr, Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
public String Cmd_key() {return Xob_cmd_keys.Key_text_cat_core;}
public void Cmd_end() { // NOTE: placing in end, b/c must run *after* page_sql
// setup
wiki.Html_mgr().Importing_ctgs_(Bool_.Y);
Io_url rslt_dir = Xob_category_registry_sql.Tmp_dir(wiki);
Io_mgr.I.DeleteDirDeep(rslt_dir);
Xob_tmp_wtr rslt_wtr = Xob_tmp_wtr.new_wo_ns_(Io_url_gen_.dir_(rslt_dir), Io_mgr.Len_mb);
// read data
Gfo_usr_dlg usr_dlg = wiki.Appe().Usr_dlg();
wiki.Init_db_mgr();
Xowd_page_tbl page_core_tbl = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
Db_rdr rdr = page_core_tbl.Conn().Stmt_select_order(page_core_tbl.Tbl_name(), String_.Ary(page_core_tbl.Fld_page_title(), page_core_tbl.Fld_page_id()), String_.Ary(page_core_tbl.Fld_page_ns()), page_core_tbl.Fld_page_title())
.Crt_int(page_core_tbl.Fld_page_ns(), Xow_ns_.Id_category)
.Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
byte[] page_ttl = rdr.Read_bry_by_str(page_core_tbl.Fld_page_title());
int page_id = rdr.Read_int(page_core_tbl.Fld_page_id());
if (rslt_wtr.FlushNeeded(page_ttl.length + 2 + 5)) rslt_wtr.Flush(usr_dlg);
rslt_wtr.Bfr().Add(page_ttl).Add_byte_pipe().Add_base85_len_5(page_id).Add_byte_nl();
}
} finally {rdr.Rls();}
// cleanup
rslt_wtr.Flush(usr_dlg);
wiki.Html_mgr().Importing_ctgs_(Bool_.N);
}
public void Cmd_init(Xob_bldr bldr) {}
public void Cmd_bgn(Xob_bldr bldr) {}
public void Cmd_run() {}
public void Cmd_term() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return GfoInvkAble_.Rv_unhandled;}
public static Io_url Tmp_dir(Xowe_wiki wiki) {return wiki.Fsys_mgr().Tmp_dir().GenSubDir(Xob_cmd_keys.Key_text_cat_core);}
}

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.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.bldrs.*;
public class Xob_category_registry_sql_tst {
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Clear();} private Xob_category_registry_sql_fxt fxt = new Xob_category_registry_sql_fxt();
@After public void term() {if (Xoa_test_.Db_skip()) return; fxt.Rls();}
@Test public void Basic() {
if (Xoa_test_.Db_skip()) return;
fxt.Init_page_insert(String_.Ary("Ctg3", "Ctg2", "Ctg1"));
fxt.Exec_category_registry_cmd();
fxt.Test_ids(Int_.Ary(3, 2, 1)); // note that Ctg1 is page_id 3
}
}
class Xob_category_registry_sql_fxt {
Db_mgr_fxt fxt; Xowe_wiki wiki; Xoae_app app; Int_obj_ref page_id_next = Int_obj_ref.new_(1);
public void Clear() {
if (fxt == null) {
fxt = new Db_mgr_fxt().Ctor_fsys();
fxt.Init_db_sqlite();
wiki = fxt.Wiki();
app = wiki.Appe();
}
}
public void Rls() {fxt.Rls();}
public void Init_page_insert(String[] ttls) {
fxt.Init_page_insert(page_id_next, Xow_ns_.Id_category, ttls);
}
public void Exec_category_registry_cmd() {
app.Bldr().Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_cat_core);
app.Bldr().Run();
}
public void Test_ids(int[] expd) {
Io_url rslts_dir = Xob_category_registry_sql.Tmp_dir(wiki);
String rslts_txt = Io_mgr.I.LoadFilStr(Io_mgr.I.QueryDir_fils(rslts_dir)[0]);
int[] actl = Parse_rslts_txt(rslts_txt);
Tfds.Eq_ary(expd, actl);
}
int[] Parse_rslts_txt(String rslts_txt) {
String[] lines = String_.SplitLines_nl(rslts_txt);
List_adp list = List_adp_.new_();
int len = lines.length;
for (int i = 0; i < len; i++) {
String line = lines[i];
if (String_.Len_eq_0(line)) break; // ignore blank line
String[] flds = String_.Split(line, '|');
list.Add(Base85_utl.XtoIntByStr(flds[1]));
}
return (int[])list.To_ary_and_clear(int.class);
}
}

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