mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.6.5.1
This commit is contained in:
213
400_xowa/src/gplx/xowa/Xoa_app.java
Normal file
213
400_xowa/src/gplx/xowa/Xoa_app.java
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
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.threads.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.cfgs2.*;
|
||||
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.parsers.*; import gplx.xowa.parsers.amps.*;
|
||||
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.*;
|
||||
public class Xoa_app implements GfoInvkAble {
|
||||
public Xoa_app(Gfo_usr_dlg usr_dlg, Io_url root_dir, Io_url user_dir, String bin_dir_name) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
log_wtr = usr_dlg.Log_wtr();
|
||||
cfg_mgr = new Xoa_cfg_mgr(this);
|
||||
api_root = new Xoapi_root(this);
|
||||
url_cmd_eval = new Xoa_fsys_eval(this);
|
||||
fsys_mgr = new Xoa_fsys_mgr(this, root_dir, bin_dir_name);
|
||||
user = new Xou_user(this, user_dir);
|
||||
log_wtr.Log_dir_(user.Fsys_mgr().App_temp_dir().GenSubDir("log"));
|
||||
fsys_mgr.Temp_dir_(user.Fsys_mgr().App_temp_dir());
|
||||
lang_mgr = new Xoa_lang_mgr(this);
|
||||
wiki_mgr = new Xoa_wiki_mgr(this);
|
||||
gui_mgr = new Xoa_gui_mgr(this);
|
||||
bldr = new Xob_bldr(this);
|
||||
file_mgr.Init_app(this, usr_dlg);
|
||||
href_parser = new Xoh_href_parser(url_converter_href, 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);
|
||||
gfs_mgr = new Xoa_gfs_mgr(this);
|
||||
xtn_mgr = new Xow_xtn_mgr().Ctor_by_app(this);
|
||||
hive_mgr = new Xoa_hive_mgr(this);
|
||||
Io_url.Http_file_str_encoder = url_converter_fsys;
|
||||
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);
|
||||
// queue_file = new Xop_queue_mgr(this);
|
||||
}
|
||||
public NumberParser Utl_num_parser() {return utl_num_parser;} private NumberParser utl_num_parser = new NumberParser();
|
||||
public void Init() {
|
||||
stage = Xoa_stage_.Tid_init;
|
||||
xtn_mgr.Init_by_app(this);
|
||||
log_wtr.Init();
|
||||
gui_mgr.Init_by_app();
|
||||
fsys_mgr.Init();
|
||||
user.Init_by_app();
|
||||
file_mgr.Init_by_app();
|
||||
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_(usr_dlg);
|
||||
html_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);
|
||||
}
|
||||
public byte Stage() {return stage;} public Xoa_app Stage_(byte v) {stage = v; return this;} private byte stage = Xoa_stage_.Tid_ctor;
|
||||
public boolean Term_cbk() {
|
||||
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;
|
||||
}
|
||||
gui_mgr.Browser_win().Usr_dlg().Canceled_y_();
|
||||
user.App_term();
|
||||
log_wtr.Term();
|
||||
log_mgr.Rls();
|
||||
if (Scrib_core.Core() != null) Scrib_core.Core().Term();
|
||||
wiki_mgr.Rls();
|
||||
return true;
|
||||
}
|
||||
public Xoa_wiki_mgr Wiki_mgr() {return wiki_mgr;} private Xoa_wiki_mgr 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;} private Xou_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 usr_dlg;} private Gfo_usr_dlg usr_dlg;
|
||||
public Gfo_log_wtr Log_wtr() {return log_wtr;} private Gfo_log_wtr log_wtr;
|
||||
public Xoa_gfs_mgr Gfs_mgr() {return gfs_mgr;} private Xoa_gfs_mgr 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 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 byte Mode() {return mode;} public Xoa_app Mode_(byte v) {mode = v; return this;} private byte mode = Xoa_app_.Mode_console;
|
||||
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private Xop_amp_mgr parser_amp_mgr = new Xop_amp_mgr();
|
||||
public Xoa_thread_mgr Thread_mgr() {return thread_mgr;} private Xoa_thread_mgr thread_mgr = new Xoa_thread_mgr();
|
||||
|
||||
|
||||
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xoa_fsys_mgr fsys_mgr;
|
||||
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
|
||||
public Xoa_url_parser Url_parser() {return url_parser;} private Xoa_url_parser url_parser = new Xoa_url_parser();
|
||||
public Xoh_href_parser Href_parser() {return href_parser;} private Xoh_href_parser 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 Gfo_usr_dlg Gui_wtr() {return gui_mgr.Browser_win().Usr_dlg();}
|
||||
|
||||
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 Url_encoder Url_converter_id() {return url_converter_id;} private Url_encoder url_converter_id = Url_encoder.new_html_id_();
|
||||
public Url_encoder Url_converter_url() {return url_converter_url;} private Url_encoder url_converter_url = Url_encoder.new_http_url_();
|
||||
public Url_encoder Url_converter_url_ttl() {return url_converter_url_ttl;} private Url_encoder url_converter_url_ttl = Url_encoder.new_http_url_ttl_();
|
||||
public Url_encoder Url_converter_href() {return url_converter_href;} private Url_encoder url_converter_href = Url_encoder.new_html_href_mw_();
|
||||
public Url_encoder Url_converter_comma() {return url_converter_comma;} private Url_encoder url_converter_comma = Url_encoder.url_comma();
|
||||
public Url_encoder Url_converter_gfs() {return url_converter_gfs;} private Url_encoder url_converter_gfs = Url_encoder.new_gfs_();
|
||||
public Url_encoder Url_converter_fsys() {return url_converter_fsys;} private Url_encoder url_converter_fsys = Url_encoder.new_fsys_lnx_();
|
||||
public Url_encoder Url_converter_fsys_safe() {return url_converter_fsys_safe;} private Url_encoder url_converter_fsys_safe = Url_encoder.new_fsys_wnt_();
|
||||
public Xoh_file_main_wkr File_main_wkr() {return file_main_wkr;} private Xoh_file_main_wkr file_main_wkr = new Xoh_file_main_wkr();
|
||||
public ByteTrieMgr_slim Utl_trie_tblw_ws() {return utl_trie_tblw_ws;} private ByteTrieMgr_slim utl_trie_tblw_ws = Xop_tblw_ws_itm.trie_();
|
||||
public Bry_bfr_mkr Utl_bry_bfr_mkr() {return utl_bry_bfr_mkr;} Bry_bfr_mkr utl_bry_bfr_mkr = new Bry_bfr_mkr();
|
||||
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_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_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 gplx.xowa.html.Xoh_html_mgr Html_mgr() {return html_mgr;} private Xoh_html_mgr html_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;
|
||||
|
||||
private Xoa_fmtr_mgr fmtr_mgr;
|
||||
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) {
|
||||
utl_bry_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 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 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";
|
||||
}
|
||||
194
400_xowa/src/gplx/xowa/Xoa_app_.java
Normal file
194
400_xowa/src/gplx/xowa/Xoa_app_.java
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
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.gfui.*; import gplx.xowa.users.*;
|
||||
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 = "1.6.5.1";
|
||||
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();
|
||||
rv.Ui_wkr_(Gfo_usr_dlg_ui_.Console);
|
||||
rv.Log_wtr_(new Gfo_log_wtr_base());
|
||||
rv.Log_wtr().Queue_enabled_(true);
|
||||
return rv;
|
||||
}
|
||||
public static final byte Mode_console = 0, Mode_gui = 1;
|
||||
}
|
||||
class Xoa_app_boot_mgr {
|
||||
private Gfo_usr_dlg usr_dlg; private Gfo_log_wtr 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_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_._ = usr_dlg = Xoa_app_.usr_dlg_console_();
|
||||
log_wtr = usr_dlg.Log_wtr(); log_wtr.Log_msg_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._.QueryFil(jar_url).ModifiedTime().XtoUtc().XtoStr_fmt("yyyy-MM-dd HH:mm");
|
||||
log_wtr.Log_msg_to_session_fmt("env.init: jar_url=~{0}; build_date=~{1}", jar_url.NameAndExt(), Xoa_app_.Build_date);
|
||||
log_wtr.Log_msg_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\\" + Xou_user.Key_xowa_user).Note_("directory for user_data; defaults to '/xowa/user/" + Xou_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.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_mode_gui = false;
|
||||
Xoa_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", Xou_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(Xoa_sys_cfg.Launch_url_dflt);
|
||||
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);
|
||||
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);
|
||||
app_mode_gui = String_.Eq(app_mode, "gui");
|
||||
|
||||
// init app
|
||||
app = new Xoa_app(usr_dlg, root_dir, user_dir, Xoa_app_.Op_sys); usr_dlg.Log_wtr().Queue_enabled_(false); log_wtr.Log_msg_to_session_fmt("app.init");
|
||||
app.Fsys_mgr().Wiki_dir_(wiki_dir);
|
||||
try {
|
||||
app.Sys_cfg().Lang_(System_lang()); chkpoint = "lang";
|
||||
app.Sys_cfg().Launch_url_(launch_url); chkpoint = "url";
|
||||
app.Tcp_server().Rdr_port_(server_port_recv).Wtr_port_(server_port_send);
|
||||
app.Http_server().Port_(http_server_port);
|
||||
app.Init(); chkpoint = "init_gfs";
|
||||
}
|
||||
catch (Exception e) {usr_dlg.Warn_many("", "", "app init failed: ~{0} ~{1}", chkpoint, Err_.Message_gplx(e));}
|
||||
app.Gui_wtr().Log_wtr_(app.Log_wtr()); // NOTE: log_wtr must be set for cmd-line (else process will fail);
|
||||
|
||||
// run gfs
|
||||
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_mode_gui)
|
||||
GfuiEnv_.ShowMsg(Err_.Message_gplx_brief(e));
|
||||
}
|
||||
|
||||
// launch
|
||||
app.Launch(); chkpoint = "launch";
|
||||
if (String_.Eq(app_mode, "server"))
|
||||
app.Tcp_server().Run();
|
||||
else if (String_.Eq(app_mode, "http_server"))
|
||||
app.Http_server().Run();
|
||||
else {
|
||||
if (cmd_text != null)
|
||||
ConsoleAdp._.WriteLine_utf8(Object_.XtoStr_OrEmpty(app.Gfs_mgr().Run_str(cmd_text)));
|
||||
if (app_mode_gui) {
|
||||
app.Mode_(Xoa_app_.Mode_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_mode_gui) // only cancel if app_mode_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 Err_mgr._.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_ascii_(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();
|
||||
}
|
||||
}
|
||||
56
400_xowa/src/gplx/xowa/Xoa_app_fxt.java
Normal file
56
400_xowa/src/gplx/xowa/Xoa_app_fxt.java
Normal 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; import gplx.*;
|
||||
import gplx.xowa.apps.*;
|
||||
public class Xoa_app_fxt {
|
||||
public static Xoa_app app_() {
|
||||
Io_mgr._.InitEngine_mem();
|
||||
return app_(Io_url_.mem_dir_("mem/xowa/"), "linux");
|
||||
}
|
||||
public static Xoa_app app_(Io_url root_dir, String op_sys) {
|
||||
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
|
||||
Gfo_log_wtr_base._.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
|
||||
Xoa_app app = new Xoa_app(Gfo_usr_dlg_base.test_(), root_dir, user_dir, op_sys);
|
||||
app.Setup_mgr().Dump_mgr().Data_storage_format_(gplx.ios.Io_stream_.Tid_file); // TEST: set data_storage_format to file, else bldr tests will fails (expects plain text)
|
||||
GfsCore._.Clear(); // NOTE: must clear
|
||||
GfsCore._.AddCmd(app, Xoa_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, Xoa_app.Invk_xowa); // add alias for app; DATE:2014-06-09
|
||||
return app;
|
||||
}
|
||||
public static Xow_wiki wiki_tst_(Xoa_app app) {return wiki_(app, "en.wikipedia.org");}
|
||||
public static Xow_wiki wiki_(Xoa_app app, String key) {return wiki_(app, key, app.Lang_mgr().Lang_en());}
|
||||
public static Xow_wiki wiki_(Xoa_app app, String key, Xol_lang lang) {
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(key);
|
||||
Xow_wiki rv = new Xow_wiki(app, wiki_dir, Xow_ns_mgr_.default_(), lang);
|
||||
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 Init_gui(Xoa_app app) {
|
||||
app.Gui_mgr().Browser_win().Init_by_kit(gplx.gfui.Mem_kit._);
|
||||
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init();
|
||||
}
|
||||
public static Xob_bldr bldr_(Xoa_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\\");
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/Xoa_consts.java
Normal file
30
400_xowa/src/gplx/xowa/Xoa_consts.java
Normal 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.NewLine}
|
||||
, 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_ascii_("/wiki/")
|
||||
;
|
||||
}
|
||||
25
400_xowa/src/gplx/xowa/Xoa_test_.java
Normal file
25
400_xowa/src/gplx/xowa/Xoa_test_.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_test_ {
|
||||
public static boolean Db_skip() {return false;}
|
||||
public static boolean Fsdb_is_mem = false;
|
||||
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");}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/apis/Xoapi_root.java
Normal file
60
400_xowa/src/gplx/xowa/apis/Xoapi_root.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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 {
|
||||
public Xoa_app app;
|
||||
public Xoapi_root(Xoa_app app) {usr_api.Ctor_by_app(app);}
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
this.app = app;
|
||||
app_api.Init_by_kit(app);
|
||||
nav.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 Xoapi_app App() {return app_api;} private Xoapi_app app_api = new Xoapi_app();
|
||||
public Xoapi_nav Nav() {return nav;} private Xoapi_nav nav = new Xoapi_nav();
|
||||
public Xoapi_gui Gui() {return gui_api;} private Xoapi_gui gui_api = new Xoapi_gui();
|
||||
public Xoapi_html Html() {return html_api;} private Xoapi_html html_api = new Xoapi_html();
|
||||
public Xoapi_net Net() {return net_api;} private Xoapi_net net_api = new Xoapi_net();
|
||||
public Xoapi_usr Usr() {return usr_api;} private Xoapi_usr usr_api = new Xoapi_usr();
|
||||
public Xoapi_xtns Xtns() {return xtns_api;} private Xoapi_xtns xtns_api = new Xoapi_xtns();
|
||||
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_nav)) return nav;
|
||||
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_xtns)) return xtns_api;
|
||||
else if (ctx.Match(k, Invk_exec)) Exec(m.ReadStr("v"));
|
||||
return this;
|
||||
}
|
||||
private static final String
|
||||
Invk_exec = "exec"
|
||||
, Invk_app = "app", Invk_nav = "nav", Invk_gui = "gui", Invk_html = "html", Invk_net = "net", Invk_usr = "usr", Invk_xtns = "xtns"
|
||||
;
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_app.java
Normal file
32
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_app.java
Normal 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*;
|
||||
import gplx.xowa.gui.views.*;
|
||||
public class Xoapi_app implements GfoInvkAble {
|
||||
private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
win = app.Gui_mgr().Browser_win();
|
||||
}
|
||||
public void Exit() {win.App__exit();}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_exit)) this.Exit();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_exit = "exit";
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_gui.java
Normal file
36
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_gui.java
Normal 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(Xoa_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";
|
||||
}
|
||||
33
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_html.java
Normal file
33
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_html.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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(Xoa_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 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 return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_tidy = "tidy", Invk_modules = "modules";
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_nav.java
Normal file
40
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_nav.java
Normal 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(Xoa_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";
|
||||
}
|
||||
42
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_net.java
Normal file
42
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_net.java
Normal 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(Xoa_app app) {
|
||||
}
|
||||
public boolean Enabled() {return enabled;} private boolean enabled;
|
||||
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";
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_usr.java
Normal file
40
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_usr.java
Normal 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.apis.xowa.usrs.*;
|
||||
public class Xoapi_usr implements GfoInvkAble {
|
||||
public void Ctor_by_app(Xoa_app app) {
|
||||
bookmarks.Ctor_by_app(app);
|
||||
history.Ctor_by_app(app);
|
||||
logs.Ctor_by_app(app);
|
||||
}
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
bookmarks.Init_by_kit(app);
|
||||
history.Init_by_kit(app);
|
||||
}
|
||||
public Xoapi_bookmarks Bookmarks() {return bookmarks;} private Xoapi_bookmarks bookmarks = new Xoapi_bookmarks();
|
||||
public Xoapi_history History() {return history;} private Xoapi_history history = new Xoapi_history();
|
||||
public Xoapi_logs Logs() {return logs;} private Xoapi_logs logs = new Xoapi_logs();
|
||||
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 return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String Invk_bookmarks = "bookmarks", Invk_history = "history", Invk_logs = "logs";
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_xtns.java
Normal file
32
400_xowa/src/gplx/xowa/apis/xowa/Xoapi_xtns.java
Normal 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; 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(Xoa_app app) {
|
||||
scribunto.Init_by_kit(app);
|
||||
}
|
||||
public Xoapi_scribunto Scribunto() {return scribunto;} private Xoapi_scribunto scribunto = new Xoapi_scribunto();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_scribunto)) return scribunto;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
private static final String
|
||||
Invk_scribunto = "scribunto"
|
||||
;
|
||||
}
|
||||
53
400_xowa/src/gplx/xowa/apis/xowa/gui/Xoapi_browser.java
Normal file
53
400_xowa/src/gplx/xowa/apis/xowa/gui/Xoapi_browser.java
Normal 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(Xoa_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";
|
||||
}
|
||||
55
400_xowa/src/gplx/xowa/apis/xowa/gui/Xoapi_font.java
Normal file
55
400_xowa/src/gplx/xowa/apis/xowa/gui/Xoapi_font.java
Normal 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 Xoa_app app;
|
||||
public void Init_by_kit(Xoa_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_.XtoStr(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_.XtoStr(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"
|
||||
;
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apis/xowa/gui/Xoapi_page.java
Normal file
36
400_xowa/src/gplx/xowa/apis/xowa/gui/Xoapi_page.java
Normal 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(Xoa_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";
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
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.*; import gplx.xowa.gui.views.*;
|
||||
public class Xoapi_find implements GfoInvkAble {
|
||||
private Xog_find_box find_box;
|
||||
public void Init_by_kit(Xoa_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 Xoa_app app; private Xog_win_itm win; private GfuiTextBox find_box;
|
||||
private boolean dir_fwd = true, case_match = false, wrap_search = true;
|
||||
public Xog_find_box(Xoa_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();}
|
||||
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() {
|
||||
Xog_tab_itm tab = win.Tab_mgr().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
|
||||
String elem_id = tab.View_mode() == Xog_page_mode.Tid_read
|
||||
? Gfui_html.Elem_id_body
|
||||
: Xog_html_itm.Elem_id__xowa_edit_data_box
|
||||
;
|
||||
tab.Html_box().Html_doc_find(elem_id, find_box.Text(), 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"));
|
||||
}
|
||||
}
|
||||
@@ -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.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.*; import gplx.xowa.gui.views.*;
|
||||
public class Xoapi_html_box implements GfoInvkAble {
|
||||
private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_app app) {this.win = app.Gui_mgr().Browser_win();}
|
||||
public void Focus() {
|
||||
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
|
||||
Gfui_html html_box = tab.Html_itm().Html_box();
|
||||
html_box.Focus();
|
||||
if (tab.View_mode() != Xog_page_mode.Tid_read) // if edit / html, place focus in edit box
|
||||
html_box.Html_elem_focus(Xog_html_itm.Elem_id__xowa_edit_data_box);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_focus)) this.Focus();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_focus = "focus";
|
||||
}
|
||||
@@ -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.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 GfoInvkAble {
|
||||
public void Init_by_kit(Xoa_app app) {this.app = app;} private Xoa_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().Ui_wkr().Clear();}
|
||||
public void Launch() {
|
||||
Io_url session_fil = app.Log_wtr().Session_fil();
|
||||
app.Fsys_mgr().App_mgr().App_view_text().Run(session_fil);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_focus)) this.Focus();
|
||||
else if (ctx.Match(k, Invk_clear)) this.Clear();
|
||||
else if (ctx.Match(k, Invk_launch)) this.Launch();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_focus = "focus", Invk_clear = "clear", Invk_launch = "launch";
|
||||
}
|
||||
@@ -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.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(Xoa_app app) {this.app = app;} private Xoa_app app;
|
||||
private Xog_win_itm Win() {return app.Gui_mgr().Browser_win();}
|
||||
public void Focus() {this.Win().Prog_box().Focus();}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_focus)) this.Focus();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_focus = "focus";
|
||||
}
|
||||
@@ -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(Xoa_app app) {this.app = app;} private Xoa_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";
|
||||
}
|
||||
@@ -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(Xoa_app app) {this.app = app;} private Xoa_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";
|
||||
}
|
||||
@@ -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(Xoa_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 - ListAdp_.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"
|
||||
;
|
||||
}
|
||||
57
400_xowa/src/gplx/xowa/apis/xowa/gui/browsers/Xoapi_url.java
Normal file
57
400_xowa/src/gplx/xowa/apis/xowa/gui/browsers/Xoapi_url.java
Normal 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.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(Xoa_app app) {this.app = app;} private Xoa_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());}
|
||||
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_.HasAtBgn(url, "\"") && String_.HasAtBgn(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 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";
|
||||
public static final String Invk_exec = "exec";
|
||||
}
|
||||
56
400_xowa/src/gplx/xowa/apis/xowa/gui/pages/Xoapi_edit.java
Normal file
56
400_xowa/src/gplx/xowa/apis/xowa/gui/pages/Xoapi_edit.java
Normal 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.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.*;
|
||||
public class Xoapi_edit implements GfoInvkAble {
|
||||
private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_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() {if (Active_tab_is_null()) return; Xog_tab_itm_edit_mgr.Save(win.Active_tab(), false);}
|
||||
public void Save_draft() {if (Active_tab_is_null()) return; Xog_tab_itm_edit_mgr.Save(win.Active_tab(), true);}
|
||||
public void Preview() {if (Active_tab_is_null()) return; Xog_tab_itm_edit_mgr.Preview(win.Active_tab());}
|
||||
public void Dbg_tmpl() {if (Active_tab_is_null()) return; Xog_tab_itm_edit_mgr.Debug(win, Xog_page_mode.Tid_edit);}
|
||||
public void Dbg_html() {if (Active_tab_is_null()) return; Xog_tab_itm_edit_mgr.Debug(win, Xog_page_mode.Tid_html);}
|
||||
public void Focus_edit_box(){if (Active_tab_is_null()) 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"
|
||||
;
|
||||
}
|
||||
@@ -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 Xoa_app app; private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_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().X_to_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._.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"
|
||||
;
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/apis/xowa/gui/pages/Xoapi_view.java
Normal file
61
400_xowa/src/gplx/xowa/apis/xowa/gui/pages/Xoapi_view.java
Normal 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.*;
|
||||
public class Xoapi_view implements GfoInvkAble {
|
||||
private Xoa_app app; private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_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(Xog_page_mode.Tid_read);}
|
||||
public void Mode_edit() {Mode(Xog_page_mode.Tid_edit);}
|
||||
public void Mode_html() {Mode(Xog_page_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_window_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 = app.Url_converter_fsys_safe().Encode_str(String_.new_utf8_(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._.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"
|
||||
;
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_modules.java
Normal file
36
400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_modules.java
Normal 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(Xoa_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";
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_tidy.java
Normal file
40
400_xowa/src/gplx/xowa/apis/xowa/html/Xoapi_tidy.java
Normal 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 Xoa_app app;
|
||||
public void Init_by_kit(Xoa_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_";
|
||||
}
|
||||
@@ -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(Xoa_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.X_to_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_"
|
||||
;
|
||||
}
|
||||
@@ -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(Xoa_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.X_to_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_"
|
||||
;
|
||||
}
|
||||
194
400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_popups.java
Normal file
194
400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_popups.java
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
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 Xoa_app app;
|
||||
public Xoapi_popups() {
|
||||
evMgr = GfoEvMgr.new_(this);
|
||||
}
|
||||
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
|
||||
public void Init_by_app(Xoa_app app) {this.app = app;}
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = false;
|
||||
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;} public void Show_all_if_less_than_(int v) {show_all_if_less_than = v;} private int show_all_if_less_than = Dflt_show_all_if_less_than;
|
||||
public byte[] Html_fmt() {return html_fmt;} private byte[] html_fmt = Dflt_html_fmt;
|
||||
public byte[] Html_fmt_dflt() {return html_fmt_dflt;} private byte[] html_fmt_dflt = Dflt_html_fmt;
|
||||
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_coordinates;
|
||||
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 Tmpl_tkn_max() {return tmpl_tkn_max;} private int tmpl_tkn_max = Dflt_tmpl_tkn_max;
|
||||
public void Show_more(String popup_id) {
|
||||
Xow_wiki wiki = app.Gui_mgr().Browser_win().Active_tab().Page().Wiki();
|
||||
wiki.Html_mgr().Module_mgr().Popup_mgr().Show_more(popup_id);
|
||||
}
|
||||
public void Show_all(String popup_id) {
|
||||
Xow_wiki wiki = app.Gui_mgr().Browser_win().Active_tab().Page().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.X_to_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.X_to_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_utf8_(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_html_fmt)) return String_.new_utf8_(html_fmt);
|
||||
else if (ctx.Match(k, Invk_html_fmt_)) {html_fmt = m.ReadBry("v"); GfoEvMgr_.PubVal(this, Evt_html_fmt_changed, html_fmt);}
|
||||
else if (ctx.Match(k, Invk_html_fmt_dflt)) return String_.new_utf8_(html_fmt_dflt);
|
||||
else if (ctx.Match(k, Invk_html_fmt_dflt_)) {html_fmt_dflt = m.ReadBry("v");}
|
||||
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_ns_allowed)) return String_.new_utf8_(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 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_fmt = "html_fmt", Invk_html_fmt_ = "html_fmt_"
|
||||
, Invk_html_fmt_dflt = "html_fmt_dflt", Invk_html_fmt_dflt_ = "html_fmt_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_ns_allowed = "ns_allowed", Invk_ns_allowed_ = "ns_allowed_"
|
||||
, Invk_tmpl_tkn_max = "tmpl_tkn_max", Invk_tmpl_tkn_max_ = "tmpl_tkn_max_"
|
||||
;
|
||||
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_html_fmt_changed = "html_fmt_changed"
|
||||
, Evt_read_til_stop_fwd_changed = "read_til_stop_fwd_changed"
|
||||
, Evt_read_til_stop_bwd_changed = "read_til_stop_bwd_changed"
|
||||
, Evt_ns_allowed_changed = "ns_allowed_changed"
|
||||
, Evt_tmpl_tkn_max_changed = "tmpl_tkn_max_changed"
|
||||
;
|
||||
public static final byte[]
|
||||
Dflt_coordinates = Bry_.new_ascii_("coordinates")
|
||||
, Dflt_html_fmt = Bry_.new_ascii_(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/modules/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/modules/xowa.popups/imgs/show_all.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>"
|
||||
))
|
||||
;
|
||||
public static final String[] Dflt_html_fmt_keys = String_.Ary("content", "page_lang_ltr", "page_url", "page_title", "wiki_domain", "wiki_item", "page_size", "edit_time", "view_time_item", "xowa_root_dir", "popup_id");
|
||||
public static final byte[]
|
||||
Dflt_ns_allowed = Bry_.Empty
|
||||
;
|
||||
public static final int
|
||||
Dflt_show_init_word_count = 64
|
||||
, Dflt_show_more_word_count = 64
|
||||
, Dflt_show_all_if_less_than = -1
|
||||
, Dflt_show_all_win_max_w = -1
|
||||
, Dflt_win_show_delay = 400, Dflt_win_hide_delay = 400
|
||||
, Dflt_win_max_w = -1, Dflt_win_max_h = -1
|
||||
, Dflt_win_show_all_max_w = -1
|
||||
, Dflt_scan_len = 1 * Io_mgr.Len_kb
|
||||
, Dflt_scan_max = 32 * Io_mgr.Len_kb
|
||||
, Dflt_read_til_stop_fwd = -1
|
||||
, Dflt_read_til_stop_bwd = -1
|
||||
, Dflt_tmpl_tkn_max = 8192
|
||||
;
|
||||
public static final boolean
|
||||
Dflt_win_bind_focus_blur = false
|
||||
;
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_toc.java
Normal file
32
400_xowa/src/gplx/xowa/apis/xowa/html/modules/Xoapi_toc.java
Normal 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(Xoa_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.X_to_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_"
|
||||
;
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apis/xowa/navs/Xoapi_wiki.java
Normal file
36
400_xowa/src/gplx/xowa/apis/xowa/navs/Xoapi_wiki.java
Normal 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.navs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
|
||||
import gplx.xowa.gui.views.*;
|
||||
public class Xoapi_wiki implements GfoInvkAble {
|
||||
private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
win = app.Gui_mgr().Browser_win();
|
||||
}
|
||||
public void Main_page() {win.Page__navigate_by_url_bar(win.Active_page().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 void Random() {win.Page__navigate_by_url_bar("Special:Random");}
|
||||
public void Sandbox() {win.Page__navigate_by_url_bar("Project:Sandbox");}
|
||||
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";
|
||||
}
|
||||
@@ -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.apis.xowa.startup; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
|
||||
class Xoapi_startup_tabs implements GfoInvkAble {
|
||||
public String[] Calc_startup_strs() {
|
||||
switch (type) {
|
||||
case Xoapi_startup_tabs_type_.Tid_blank: return new String[] {gplx.xowa.specials.xowa.default_tab.Default_tab_page.Ttl_full_str};
|
||||
case Xoapi_startup_tabs_type_.Tid_xowa: return new String[] {gplx.xowa.users.Xouc_pages_mgr.Page_xowa};
|
||||
case Xoapi_startup_tabs_type_.Tid_custom: return String_.SplitLines_nl(custom);
|
||||
case Xoapi_startup_tabs_type_.Tid_previous: return String_.SplitLines_nl(previous);
|
||||
default: throw Err_.unhandled(type);
|
||||
}
|
||||
}
|
||||
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;} public Xoapi_startup_tabs Previous_(String v) {previous = v; return this;} private String previous = "";
|
||||
public byte Type() {return type;} private byte type = Xoapi_startup_tabs_type_.Tid_xowa;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_type)) return Xoapi_startup_tabs_type_.X_to_key(type);
|
||||
else if (ctx.Match(k, Invk_type_)) type = Xoapi_startup_tabs_type_.X_to_tid(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.X_to_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_custom = "custom", Invk_custom_ = "custom_"
|
||||
, Invk_custom_is_expr = "custom_is_expr", Invk_custom_is_expr_ = "custom_is_expr_"
|
||||
;
|
||||
}
|
||||
class Xoapi_startup_tabs_type_ {
|
||||
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 X_to_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 Err_.not_implemented_();
|
||||
}
|
||||
}
|
||||
public static byte X_to_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 Err_.not_implemented_();
|
||||
}
|
||||
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_(Key_blank), KeyVal_.new_(Key_xowa), KeyVal_.new_(Key_previous), KeyVal_.new_(Key_custom));
|
||||
}
|
||||
/*
|
||||
startup {
|
||||
tabs {
|
||||
type = 'previous|blank|custom|xowa_home';
|
||||
custom = 'en.wikipedia.org/wiki/{{{MONTHNAME}}} {{{DAY}}';
|
||||
custom_has_wikitext = 'n';
|
||||
}
|
||||
}
|
||||
*/
|
||||
53
400_xowa/src/gplx/xowa/apis/xowa/usrs/Xoapi_bookmarks.java
Normal file
53
400_xowa/src/gplx/xowa/apis/xowa/usrs/Xoapi_bookmarks.java
Normal 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.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.*;
|
||||
public class Xoapi_bookmarks implements GfoInvkAble {
|
||||
private Xoa_app app; private Xog_win_itm win;
|
||||
public void Ctor_by_app(Xoa_app app) {this.app = app;}
|
||||
public void Init_by_kit(Xoa_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;
|
||||
Xoa_page page = tab.Page();
|
||||
byte[] wiki_domain = null, ttl_full_txt = null;
|
||||
if (url_str == null) {
|
||||
wiki_domain = page.Wiki().Domain_bry();
|
||||
ttl_full_txt = page.Ttl().Full_txt();
|
||||
}
|
||||
else {
|
||||
Xoa_url url = Xoa_url_parser.Parse_from_url_bar(app, page.Wiki(), url_str);
|
||||
wiki_domain = url.Wiki_bry();
|
||||
ttl_full_txt = url.Page_bry();
|
||||
}
|
||||
app.User().Bookmarks_add(wiki_domain, ttl_full_txt);
|
||||
app.Usr_dlg().Prog_many("", "", "bookmark added: ~{0}", String_.new_utf8_(ttl_full_txt));
|
||||
}
|
||||
public void Show() {win.Page__navigate_by_url_bar("home/wiki/Data:Bookmarks");}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled)) return Yn.X_to_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";
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apis/xowa/usrs/Xoapi_history.java
Normal file
37
400_xowa/src/gplx/xowa/apis/xowa/usrs/Xoapi_history.java
Normal 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 Xoa_app app; private Xog_win_itm win;
|
||||
public void Ctor_by_app(Xoa_app app) {this.app = app;}
|
||||
public void Init_by_kit(Xoa_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.User().History_mgr().Get_at_last(app));}
|
||||
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.X_to_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";
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apis/xowa/usrs/Xoapi_logs.java
Normal file
37
400_xowa/src/gplx/xowa/apis/xowa/usrs/Xoapi_logs.java
Normal 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 Xoa_app app;
|
||||
public void Ctor_by_app(Xoa_app app) {this.app = app;}
|
||||
public void Init_by_kit(Xoa_app app) {}
|
||||
public boolean Enabled() {return app.Log_wtr().Enabled();}
|
||||
public void Enabled_(boolean v) {
|
||||
app.Log_wtr().Enabled_(v);
|
||||
if (!v)
|
||||
Io_mgr._.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.X_to_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_";
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_scribunto.java
Normal file
38
400_xowa/src/gplx/xowa/apis/xowa/xtns/Xoapi_scribunto.java
Normal 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 Xoa_app app;
|
||||
public void Init_by_kit(Xoa_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_"
|
||||
;
|
||||
}
|
||||
109
400_xowa/src/gplx/xowa/apps/Xoa_gfs_mgr.java
Normal file
109
400_xowa/src/gplx/xowa/apps/Xoa_gfs_mgr.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Xoa_gfs_mgr implements GfoInvkAble, GfoInvkRootWkr {
|
||||
public Xoa_gfs_mgr(Xoa_app app) {
|
||||
this.app = app;
|
||||
GfsCore._.AddCmd(app, Xoa_app.Invk_app);
|
||||
GfsCore._.AddCmd(app, Xoa_app.Invk_xowa);
|
||||
eval_mgr = new Xoa_app_eval(app);
|
||||
} private Xoa_app app;
|
||||
public Xoa_app_eval Eval_mgr() {return eval_mgr;} private Xoa_app_eval eval_mgr;
|
||||
public static boolean Fail_if_unhandled = false;
|
||||
public static final String Cfg_user_file = "xowa_user_cfg.gfs", Cfg_user_custom_file = "user_custom_cfg.gfs";
|
||||
private void Run_url_by_type(String type) {
|
||||
Xou_fsys_mgr fsys_mgr = app.User().Fsys_mgr();
|
||||
Io_url app_data_dir = 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, "user_custom_cfg")) url = fsys_mgr.App_data_cfg_custom_fil();
|
||||
else if (String_.Eq(type, "xowa_user_cfg")) url = fsys_mgr.App_data_cfg_user_fil();
|
||||
else if (String_.Eq(type, "xowa")) url = app.Fsys_mgr().Root_dir().GenSubFil("xowa.gfs");
|
||||
else throw Err_mgr._.fmt_(GRP_KEY, "invalid_gfs_type", "invalid gfs type: ~{0}", type);
|
||||
Run_url(url);
|
||||
}
|
||||
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);
|
||||
app.Log_wtr().Log_msg_to_session_fmt("gfs.done: ~{0}", url.Raw());
|
||||
}
|
||||
public void Run_url_for(GfoInvkAble invk, Io_url url) {
|
||||
String raw = Io_mgr._.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_(app.Usr_dlg());
|
||||
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) {
|
||||
app.Usr_dlg().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 = app;
|
||||
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.XtoAryAndClear();}
|
||||
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.XtoAryAndClear();}
|
||||
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_ascii_(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_ascii_("'"), Bry_apos_2 = Bry_.new_ascii_("''");
|
||||
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.XtoStrAndClear();
|
||||
} static final Bry_bfr Build_code_bfr = Bry_bfr.new_();
|
||||
}
|
||||
117
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr.java
Normal file
117
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr.java
Normal 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.XtoAryAndClear() : src;
|
||||
}
|
||||
private static int Xto_php_swap(Bry_bfr bfr, byte[] src, int len, int pos) {
|
||||
if (pos >= len) throw Err_.new_("invalid gfs: tilde is last char; src={0}", String_.new_utf8_(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 Err_.new_("invalid gfs; num_end not found={0}", String_.new_utf8_(src));
|
||||
bfr.Add_byte(Byte_ascii.Dollar);
|
||||
int arg_idx = Bry_.X_to_int_or(src, num_bgn, num_end, -1);
|
||||
if (arg_idx == -1) {
|
||||
throw Err_.new_("invalid int");
|
||||
}
|
||||
bfr.Add_int_variable(arg_idx + 1);
|
||||
return num_end + 1;
|
||||
}
|
||||
default: {
|
||||
throw Err_.new_("invalid gfs; next char after tilde must be either tilde or open brace; src={0}", String_.new_utf8_(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_.X_to_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.XtoAryAndClear();
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr_tst.java
Normal file
50
400_xowa/src/gplx/xowa/apps/Xoa_gfs_php_mgr_tst.java
Normal 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_utf8_(raw));
|
||||
Tfds.Eq(expd, String_.new_utf8_(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_utf8_(raw));
|
||||
Tfds.Eq(expd, String_.new_utf8_(actl));
|
||||
}
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/apps/Xoa_shell.java
Normal file
36
400_xowa/src/gplx/xowa/apps/Xoa_shell.java
Normal 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; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_shell implements GfoInvkAble {
|
||||
public Xoa_shell(Xoa_app app) {this.app = app;} private Xoa_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) {
|
||||
return String_.new_utf8_(app.Gui_mgr().Browser_win().App__retrieve_by_url(m.ReadStr("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_"
|
||||
;
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java
Normal file
30
400_xowa/src/gplx/xowa/apps/Xoa_shell_tst.java
Normal 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();
|
||||
Xoa_app app = parser_fxt.App(); Xow_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
|
||||
}
|
||||
}
|
||||
21
400_xowa/src/gplx/xowa/apps/Xoa_stage_.java
Normal file
21
400_xowa/src/gplx/xowa/apps/Xoa_stage_.java
Normal 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;
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/apps/Xoa_thread_mgr.java
Normal file
27
400_xowa/src/gplx/xowa/apps/Xoa_thread_mgr.java
Normal 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.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);
|
||||
}
|
||||
}
|
||||
26
400_xowa/src/gplx/xowa/apps/caches/Wdata_doc_cache.java
Normal file
26
400_xowa/src/gplx/xowa/apps/caches/Wdata_doc_cache.java
Normal 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();}
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/apps/caches/Xoa_cache_mgr.java
Normal file
24
400_xowa/src/gplx/xowa/apps/caches/Xoa_cache_mgr.java
Normal 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();
|
||||
}
|
||||
}
|
||||
128
400_xowa/src/gplx/xowa/apps/fsys/Launcher_app_mgr.java
Normal file
128
400_xowa/src/gplx/xowa/apps/fsys/Launcher_app_mgr.java
Normal 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.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Launcher_app_mgr implements GfoInvkAble {
|
||||
public Launcher_app_mgr(Xoa_app app) {this.app = app;} private Xoa_app app;
|
||||
public void Init() {
|
||||
Xoa_fsys_eval cmd_eval = app.Url_cmd_eval();
|
||||
ProcessAdp.ini_(this, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), app_lua , cmd_eval, ProcessAdp.Run_mode_async , 0 , "~{<>bin_plat_dir<>}lua\\lua", "", "");
|
||||
ProcessAdp.ini_(this, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), 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, app.Gui_wtr(), app_view_web , cmd_eval, ProcessAdp.Run_mode_async , 0 , "cmd", "/c start \"~{url}\"", "url");
|
||||
ProcessAdp.ini_(this, app.Gui_wtr(), 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, app.Gui_wtr(), 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_utf8_(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_ascii_(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_ascii_(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;
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_eval.java
Normal file
37
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_eval.java
Normal 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.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_fsys_eval implements Bry_fmtr_eval_mgr {
|
||||
public Xoa_fsys_eval(Xoa_app app) {this.app = app;} private Xoa_app app;
|
||||
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_bin_plat_dir: return app.Fsys_mgr().Bin_plat_dir().RawBry();
|
||||
case Tid_user_temp_dir: return app.User().Fsys_mgr().App_temp_dir().RawBry();
|
||||
case Tid_xowa_root_dir: return app.Fsys_mgr().Root_dir().RawBry();
|
||||
case Tid_user_cfg_dir: return app.User().Fsys_mgr().App_data_cfg_dir().RawBry();
|
||||
default: throw Err_mgr._.unhandled_(val);
|
||||
}
|
||||
}
|
||||
Hash_adp_bry hash = Hash_adp_bry.ci_().Add_bry_byte(Bry_bin_plat_dir, Tid_bin_plat_dir).Add_bry_byte(Bry_user_temp_dir, Tid_user_temp_dir).Add_bry_byte(Bry_xowa_root_dir, Tid_xowa_root_dir).Add_bry_byte(Bry_user_cfg_dir, Tid_user_cfg_dir);
|
||||
private static final byte[] Bry_bin_plat_dir = Bry_.new_ascii_("bin_plat_dir"), Bry_user_temp_dir = Bry_.new_ascii_("user_temp_dir"), Bry_xowa_root_dir = Bry_.new_ascii_("xowa_root_dir"), Bry_user_cfg_dir = Bry_.new_ascii_("user_cfg_dir");
|
||||
static final byte Tid_bin_plat_dir = 0, Tid_user_temp_dir = 1, Tid_xowa_root_dir = 2, Tid_user_cfg_dir = 3;
|
||||
}
|
||||
49
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_mgr.java
Normal file
49
400_xowa/src/gplx/xowa/apps/fsys/Xoa_fsys_mgr.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
public class Xoa_fsys_mgr implements GfoInvkAble {
|
||||
public Xoa_fsys_mgr(Xoa_app app, Io_url root_dir, String bin_dir_name) {
|
||||
this.root_dir = root_dir;
|
||||
bin_any_dir = root_dir.GenSubDir("bin").GenSubDir("any");
|
||||
bin_plat_dir = root_dir.GenSubDir("bin").GenSubDir(bin_dir_name);
|
||||
bin_extensions_dir = bin_any_dir.GenSubDir_nest("xowa", "xtns");
|
||||
file_dir = root_dir.GenSubDir("file");
|
||||
wiki_dir = root_dir.GenSubDir("wiki");
|
||||
temp_dir = root_dir.GenSubDir("tmp");
|
||||
app_mgr = new Launcher_app_mgr(app);
|
||||
}
|
||||
public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
|
||||
public Io_url File_dir() {return file_dir;} private Io_url file_dir;
|
||||
public Io_url Wiki_dir() {return wiki_dir;} public Xoa_fsys_mgr Wiki_dir_(Io_url v) {wiki_dir = v; return this;} private Io_url wiki_dir;
|
||||
public Io_url Temp_dir() {return temp_dir;} public Xoa_fsys_mgr Temp_dir_(Io_url v) {temp_dir = v; return this;} private Io_url temp_dir; // set to /xowa/user/<name>/temp
|
||||
public Io_url Bin_any_dir() {return bin_any_dir;} private Io_url bin_any_dir;
|
||||
public Io_url Bin_extensions_dir() {return bin_extensions_dir;} private Io_url bin_extensions_dir;
|
||||
public Io_url Bin_plat_dir() {return bin_plat_dir;} private Io_url bin_plat_dir;
|
||||
public Io_url Bin_db_dir() {return bin_any_dir.GenSubDir_nest("sql", "xowa");}
|
||||
public Launcher_app_mgr App_mgr() {return app_mgr;} Launcher_app_mgr app_mgr;
|
||||
public void Init() {
|
||||
app_mgr.Init();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_apps)) return app_mgr;
|
||||
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";
|
||||
public static final String DirName_wiki = "wiki", DirName_user = "user";
|
||||
}
|
||||
37
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__anchor_tst.java
Normal file
37
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__anchor_tst.java
Normal 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__anchor_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Anch_y() {fxt.Init_ttl("a#b") .Expd_full_txt("A").Expd_page_txt("A").Expd_anch_txt("b").Test();}
|
||||
@Test public void Anch_only() {fxt.Init_ttl("#a") .Expd_full_txt("").Expd_page_txt("").Expd_anch_txt("a").Test();}
|
||||
@Test public void Anchor_fails() { // PURPOSE: :#batch:Main Page causes ttl to fail b/c # is treated as anchor; DATE:2013-01-02
|
||||
fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_ascii_("#batch"), Bry_.new_ascii_("none"));
|
||||
fxt.Init_ttl(":#batch:Main Page").Expd_full_txt("Main Page").Test();
|
||||
}
|
||||
@Test public void Anchor_angles() {// PURPOSE: angles in anchor should be encoded; DATE: 2013-01-23
|
||||
fxt.Init_ttl("A#b<c>d").Expd_full_txt("A").Expd_anch_txt("b.3Cc.3Ed").Test();
|
||||
}
|
||||
@Test public void Anchor_arg_in_non_main_ns() {
|
||||
fxt.Init_ttl("Help:A#B").Expd_full_txt("Help:A").Expd_anch_txt("B").Test();
|
||||
}
|
||||
@Test public void Anchor_and_slash() { // PURPOSE: slash in anchor was being treated as a subpage; DATE:2014-01-14
|
||||
fxt.Init_ttl("A#b/c").Expd_full_txt("A").Expd_anch_txt("b/c").Expd_leaf_txt("A").Test(); // NOTE: Leaf_txt should be Page_txt; used to fail
|
||||
}
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__basic_tst.java
Normal file
61
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__basic_tst.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__basic_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Ns() {fxt.Init_ttl("Help:Test") .Expd_ns_id(Xow_ns_.Id_help).Expd_page_txt("Test").Test();}
|
||||
@Test public void Ns_false() {fxt.Init_ttl("Helpx:Test") .Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Helpx:Test").Test();}
|
||||
@Test public void Ns_multiple() {fxt.Init_ttl("Help:Talk:test") .Expd_page_txt("Talk:test").Test();}
|
||||
@Test public void Full_txt() {fxt.Init_ttl("Help:a & b") .Expd_full_txt("Help:A & b").Test();} // preserve
|
||||
@Test public void Full_url() {fxt.Init_ttl("Help:a & b") .Expd_full_url("Help:A_%26_b").Test();} // escape
|
||||
@Test public void Page_txt() {fxt.Init_ttl("a & b") .Expd_page_txt("A & b").Test();} // preserve;
|
||||
@Test public void Page_txt_underline() {fxt.Init_ttl("a_b") .Expd_page_txt("A b").Expd_page_url("A_b").Test();} // NOTE: raw is "a_b" but txt is "a b"
|
||||
@Test public void Page_url() {fxt.Init_ttl("a & b") .Expd_page_url("A_%26_b").Test();} // escape
|
||||
@Test public void Page_url_w_ns() {fxt.Init_ttl("Help:a & b") .Expd_page_url("A_%26_b").Test();} // remove ns
|
||||
@Test public void Page_url_symbols() {fxt.Init_ttl(";:@&=$ -_.+!*'(),/").Expd_page_url(";:@%26%3D$_-_.%2B!*%27(),/").Test();}// symbols + space
|
||||
@Test public void Leaf_txt() {fxt.Init_ttl("root/mid/leaf") .Expd_leaf_txt("leaf").Test();}
|
||||
@Test public void Leaf_txt_slash_is_last() {fxt.Init_ttl("root/mid/leaf/") .Expd_leaf_txt("").Test();}
|
||||
@Test public void Leaf_txt_no_slash() {fxt.Init_ttl("root") .Expd_leaf_txt("Root").Test();}
|
||||
@Test public void Leaf_url() {fxt.Init_ttl("root/mid/a & b") .Expd_leaf_url("a_%26_b").Test();} // NOTE: a not capitalized ("root" would be)
|
||||
@Test public void Base_txt() {fxt.Init_ttl("a & b/mid/leaf") .Expd_base_txt("A & b/mid").Test();}
|
||||
@Test public void Base_url() {fxt.Init_ttl("a & b/mid/leaf") .Expd_base_url("A_%26_b/mid").Test();}
|
||||
@Test public void Root_txt() {fxt.Init_ttl("root/mid/leaf") .Expd_root_txt("Root").Test();}
|
||||
@Test public void Rest_txt() {fxt.Init_ttl("root/mid/leaf") .Expd_rest_txt("mid/leaf").Test();}
|
||||
@Test public void Talk_txt() {fxt.Init_ttl("Help:test") .Expd_talk_txt("Help talk:Test").Test();}
|
||||
@Test public void Talk_txt_identity() {fxt.Init_ttl("Help talk:test") .Expd_talk_txt("Help talk:Test").Test();}
|
||||
@Test public void Talk_url() {fxt.Init_ttl("Help:a & b") .Expd_talk_url("Help_talk:A_%26_b").Test();}
|
||||
@Test public void Talk_txt_main() {fxt.Init_ttl("test") .Expd_talk_txt("Talk:Test").Test();}
|
||||
@Test public void Subj_txt() {fxt.Init_ttl("Help talk:test") .Expd_subj_txt("Help:Test").Test();}
|
||||
@Test public void Subj_txt_identity() {fxt.Init_ttl("Help:test") .Expd_subj_txt("Help:Test").Test();}
|
||||
@Test public void Subj_url() {fxt.Init_ttl("Help talk:a & b").Expd_subj_url("Help:A_%26_b").Test();}
|
||||
@Test public void Subj_txt_main() {fxt.Init_ttl("Talk:test") .Expd_subj_txt("Test").Test();}
|
||||
@Test public void Force_literal_link_y() {fxt.Init_ttl(":Help:test") .Expd_force_literal_link(1).Expd_page_txt("Test").Test();}
|
||||
@Test public void Force_literal_link_n() {fxt.Init_ttl( "Help:test") .Expd_force_literal_link(0).Expd_page_txt("Test").Test();}
|
||||
@Test public void Force_literal_link_y_2() {fxt.Init_ttl("::Help:test") .Expd_force_literal_link(1).Expd_page_txt("Test").Test();} // PURPOSE: 2nd initial colon should be ignored; EX:mw:MediaWiki; [[::MediaWiki]]; DATE:2013-12-14
|
||||
@Test public void All_page() {fxt.Init_ttl("test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();}
|
||||
@Test public void All_ns() {fxt.Init_ttl("Help:test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_help).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();}
|
||||
@Test public void Special() {fxt.Init_ttl("Special:Random").Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt("Random").Test();}
|
||||
@Test public void Special_xowa() {fxt.Init_ttl("Special:xowa/Search/Ttl").Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt("Xowa/Search/Ttl").Test();}
|
||||
@Test public void Comment() {fxt.Init_ttl("Ab<!--b-->").Expd_page_txt("Ab").Test();}
|
||||
@Test public void Comment_eos() {fxt.Init_ttl("Ab<!--b--").Expd_page_txt(null).Test();}
|
||||
@Test public void Ns_case() {// PURPOSE: lowercase ns should be converted to proper case; EX: fr.w:Project:Sandbox (redirect link); en.w:Periclimenes imperator; [[commons:category:Periclimenes imperator|''Periclimenes imperator'']]; DATE: 2013-01-27
|
||||
fxt.Init_ttl("help:A").Expd_full_txt("Help:A").Test();
|
||||
fxt.Init_ttl("help talk:A").Expd_full_txt("Help talk:A").Test();
|
||||
}
|
||||
}
|
||||
39
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__err_tst.java
Normal file
39
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__err_tst.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__err_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Invalid() {fxt.Init_ttl("<!--A").Expd_err(Xop_ttl_log.Comment_eos).Test();}
|
||||
@Test public void Invalid_brace() {fxt.Init_ttl("[[a]]").Expd_err(Xop_ttl_log.Invalid_char).Test();}
|
||||
@Test public void Invalid_curly() {fxt.Init_ttl("{{a}}").Expd_err(Xop_ttl_log.Invalid_char).Test();}
|
||||
@Test public void Len_0() {
|
||||
fxt.Init_ttl("").Expd_err(Xop_ttl_log.Len_0).Test();
|
||||
fxt.Init_ttl(" ").Expd_err(Xop_ttl_log.Len_0).Test();
|
||||
fxt.Init_ttl("_").Expd_err(Xop_ttl_log.Len_0).Test();
|
||||
fxt.Init_ttl("_ _").Expd_err(Xop_ttl_log.Len_0).Test();
|
||||
}
|
||||
@Test public void Len_max() {
|
||||
fxt.Init_ttl(String_.Repeat("A", 512)).Expd_page_txt(String_.Repeat("A", 512)).Test();
|
||||
// fxt.Init_ttl("File:" + String_.Repeat("A", 255)).Expd_page_txt(String_.Repeat("A", 255)).Test(); // DELETE: removing multi-byte check; DATE:2013-02-02
|
||||
// fxt.Init_ttl(String_.Repeat("A", 256)).Expd_err(Xop_ttl_log.Len_max).Test();
|
||||
// fxt.Init_ttl("Special:" + String_.Repeat("A", 255)).Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt(String_.Repeat("A", 255)).Test();
|
||||
// fxt.Init_ttl("Special:" + String_.Repeat("A", 512 + 8)).Expd_err(Xop_ttl_log.Len_max).Test(); // 8="Special:".length
|
||||
}
|
||||
@Test public void Colon_is_last_ns() {fxt.Init_ttl("Help:").Expd_err(Xop_ttl_log.Ttl_is_ns_only).Test();}
|
||||
}
|
||||
@@ -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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__html_entity_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Eacute() {fxt.Init_ttl("é").Expd_page_txt("é").Test();} //É
|
||||
@Test public void Amp_at_end() {fxt.Init_ttl("Bisc &").Expd_page_txt("Bisc &").Test();}
|
||||
@Test public void Ltr_a() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();}
|
||||
@Test public void Nbsp() {fxt.Init_ttl("A b").Expd_page_txt("A b").Test();} // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]]
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__i18n_tst.java
Normal file
43
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__i18n_tst.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
public class Xoa_ttl__i18n_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Bidi() {
|
||||
fxt.Init_ttl("A" + String_.new_utf8_(Bry_.ints_(226, 128, 142)) + "B").Expd_page_txt("AB").Test();
|
||||
fxt.Init_ttl("A" + String_.new_utf8_(Bry_.ints_(226, 128, 97)) + "B").Expd_page_txt("A" + String_.new_utf8_(Bry_.ints_(226, 128, 97)) + "B").Test();
|
||||
}
|
||||
@Test public void Multi_byte_char2() { // PURPOSE: multi-byte HTML entity causes array out of index error; EX: w:List_of_Unicode_characters; DATE:2013-12-25
|
||||
fxt.Init_ttl("ⱥ").Expd_full_txt("ⱥ").Test();
|
||||
}
|
||||
@Test public void First_char_is_multi_byte() { // PURPOSE: if multi-byte, uppercasing is complicated; EX: µ -> Μ; DATE:2013-11-27
|
||||
fxt.Wiki().Lang().Case_mgr().Add_bulk(Xol_case_itm_.Universal);
|
||||
fxt.Init_ttl("µ").Expd_full_txt("Μ").Test(); // NOTE: this is not an ASCII "Μ"
|
||||
fxt.Init_ttl("µab").Expd_full_txt("Μab").Test(); // check that rest of title works fine
|
||||
fxt.Init_ttl("Help:µab").Expd_full_txt("Help:Μab").Test(); // check ns
|
||||
fxt.Init_ttl("Ι").Expd_full_txt("Ι").Test(); // check that Ι is not upper-cased to COMBINING GREEK YPOGEGRAMMENI; DATE:2014-02-24
|
||||
}
|
||||
@Test public void First_char_is_multi_byte_assymetrical() { // PURPOSE: test multi-byte asymmetry (lc is 3 bytes; uc is 2 bytes)
|
||||
fxt.Wiki().Lang().Case_mgr().Add_bulk(Xol_case_itm_.Universal);
|
||||
fxt.Init_ttl("ⱥ").Expd_full_txt("Ⱥ").Test();
|
||||
fxt.Init_ttl("ⱥab").Expd_full_txt("Ⱥab").Test(); // check that rest of title works fine
|
||||
fxt.Init_ttl("Help:ⱥab").Expd_full_txt("Help:Ⱥab").Test(); // check ns
|
||||
}
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__qarg_tst.java
Normal file
31
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__qarg_tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__qarg_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Base_txt_wo_qarg() {
|
||||
fxt.Init_ttl("Special:Search/A?b=c").Expd_base_txt_wo_qarg("Search").Expd_qarg_txt("b=c").Test();
|
||||
}
|
||||
@Test public void Leaf_txt_wo_qarg() {
|
||||
fxt.Init_ttl("Special:Search/A?b=c").Expd_leaf_txt_wo_qarg("A").Expd_qarg_txt("b=c").Test();
|
||||
}
|
||||
@Test public void Ttl_has_question_mark() { // PURPOSE: handle titles that have both question mark and leaf; PAGE:en.w:Portal:Organized_Labour/Did_You_Know?/1 DATE:2014-06-08
|
||||
fxt.Init_ttl("A/B?/1").Expd_page_txt("A/B?/1").Expd_base_txt("A/B?").Expd_leaf_txt("1").Expd_leaf_txt_wo_qarg("1").Expd_qarg_txt(null).Test();
|
||||
}
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__ws_tst.java
Normal file
27
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__ws_tst.java
Normal 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__ws_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Space() {fxt.Init_ttl(" a b ") .Expd_page_url("A_b").Expd_page_txt("A b").Test();}
|
||||
@Test public void Space_w_ns() {fxt.Init_ttl(" Help : a b ") .Expd_page_url("A_b").Expd_page_txt("A b").Test();}
|
||||
@Test public void Nl() {fxt.Init_ttl("\n\na\n\n") .Expd_page_txt("A").Test();}
|
||||
@Test public void Nl_end() {fxt.Init_ttl("a\nb") .Expd_page_txt("A b").Test();}
|
||||
@Test public void Tab() {fxt.Init_ttl("\ta\t") .Expd_page_txt("A").Test();}
|
||||
}
|
||||
42
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__xwik_tst.java
Normal file
42
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__xwik_tst.java
Normal 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
import org.junit.*;
|
||||
public class Xoa_ttl__xwik_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt();
|
||||
@Test public void Known() {fxt.Init_ttl("fr:a") .Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("a").Test();}
|
||||
@Test public void Known_ns() {fxt.Init_ttl("fr:Help:a") .Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Id_main).Expd_full_txt("Help:a").Expd_page_txt("Help:a").Test();} // NOTE: Page is "Help:a" b/c ns are unknowable in foreign wiki
|
||||
@Test public void Unknown() {fxt.Init_ttl("frx:a") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Frx:a").Test();}
|
||||
@Test public void Unknown_ns() {fxt.Init_ttl("frx:Help:a") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Frx:Help:a").Test();}
|
||||
@Test public void Known_ns_leaf_anch() {fxt.Init_ttl("fr:Help:a/b/c#d").Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Help:a/b/c").Expd_leaf_txt("c").Expd_anch_txt("d").Expd_full_txt("Help:a/b/c").Test();}
|
||||
@Test public void Colon_is_last() {
|
||||
fxt.Init_ttl("fr:Help:").Expd_xwik_txt("fr").Expd_page_txt("Help:").Test();
|
||||
fxt.Init_ttl("fr:_ _").Expd_xwik_txt("fr").Expd_page_txt("").Test(); // NOTE: fr:_ _ is invalid (resolves to "fr:");
|
||||
fxt.Init_ttl("fr:Help:_ _").Expd_xwik_txt("fr").Expd_page_txt("Help:").Test();
|
||||
}
|
||||
@Test public void Colon_multiple() {
|
||||
fxt.Init_ttl("fr::Help:Test").Expd_xwik_txt("fr").Expd_page_txt(":Help:Test").Test();
|
||||
fxt.Init_ttl("fr::Test").Expd_xwik_txt("fr").Expd_page_txt(":Test").Test();
|
||||
fxt.Init_ttl(":fr:Test").Expd_xwik_txt("fr").Expd_page_txt("Test").Expd_force_literal_link(1).Test();
|
||||
fxt.Init_ttl(":::fr:Test").Expd_xwik_txt("").Expd_page_txt(":fr:Test").Expd_force_literal_link(1).Test();
|
||||
}
|
||||
@Test public void Ns_should_precede_xwiki() {// PURPOSE: the "Wikipedia" in "Wikipedia:Main page" should be interpreted as namespace, not an alias
|
||||
fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_ascii_("Wikipedia"), Bry_.new_ascii_("en.wikipedia.org"));
|
||||
fxt.Init_ttl("Wikipedia:Test").Expd_xwik_txt("").Expd_full_txt("Wikipedia:Test").Test();
|
||||
}
|
||||
}
|
||||
86
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl_fxt.java
Normal file
86
400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl_fxt.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.apps.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
|
||||
class Xoa_ttl_fxt {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
public Xoa_ttl_fxt Init_ttl(String raw) {test_raw = raw; return this;} private String test_raw = "";
|
||||
public Xoa_ttl_fxt Expd_ns_id(int v) {expd_ns_id = v; return this;} private int expd_ns_id = Int_.MinValue;
|
||||
public Xoa_ttl_fxt Expd_page_txt(String v) {expd_page_txt = v; return this;} private String expd_page_txt;
|
||||
public Xoa_ttl_fxt Expd_page_url(String v) {expd_page_url = v; return this;} private String expd_page_url;
|
||||
public Xoa_ttl_fxt Expd_full_txt(String v) {expd_full_txt = v; return this;} private String expd_full_txt;
|
||||
public Xoa_ttl_fxt Expd_full_url(String v) {expd_full_url = v; return this;} private String expd_full_url;
|
||||
public Xoa_ttl_fxt Expd_leaf_txt(String v) {expd_leaf_txt = v; return this;} private String expd_leaf_txt;
|
||||
public Xoa_ttl_fxt Expd_leaf_url(String v) {expd_leaf_url = v; return this;} private String expd_leaf_url;
|
||||
public Xoa_ttl_fxt Expd_base_txt(String v) {expd_base_txt = v; return this;} private String expd_base_txt;
|
||||
public Xoa_ttl_fxt Expd_base_url(String v) {expd_base_url = v; return this;} private String expd_base_url;
|
||||
public Xoa_ttl_fxt Expd_root_txt(String v) {expd_root_txt = v; return this;} private String expd_root_txt;
|
||||
public Xoa_ttl_fxt Expd_rest_txt(String v) {expd_rest_txt = v; return this;} private String expd_rest_txt;
|
||||
public Xoa_ttl_fxt Expd_talk_txt(String v) {expd_talk_txt = v; return this;} private String expd_talk_txt;
|
||||
public Xoa_ttl_fxt Expd_talk_url(String v) {expd_talk_url = v; return this;} private String expd_talk_url;
|
||||
public Xoa_ttl_fxt Expd_subj_txt(String v) {expd_subj_txt = v; return this;} private String expd_subj_txt;
|
||||
public Xoa_ttl_fxt Expd_subj_url(String v) {expd_subj_url = v; return this;} private String expd_subj_url;
|
||||
public Xoa_ttl_fxt Expd_qarg_txt(String v) {expd_qarg_txt = v; return this;} private String expd_qarg_txt;
|
||||
public Xoa_ttl_fxt Expd_xwik_txt(String v) {expd_xwik_txt = v; return this;} private String expd_xwik_txt;
|
||||
public Xoa_ttl_fxt Expd_anch_txt(String v) {expd_anch_txt = v; return this;} private String expd_anch_txt;
|
||||
public Xoa_ttl_fxt Expd_base_txt_wo_qarg(String v) {expd_base_txt_wo_qarg = v; return this;} private String expd_base_txt_wo_qarg;
|
||||
public Xoa_ttl_fxt Expd_leaf_txt_wo_qarg(String v) {expd_leaf_txt_wo_qarg = v; return this;} private String expd_leaf_txt_wo_qarg;
|
||||
public Xoa_ttl_fxt Expd_force_literal_link(int v) {expd_force_literal_link = v; return this;} private int expd_force_literal_link = -1;
|
||||
public Xoa_ttl_fxt Expd_err(Gfo_msg_itm v) {expd_err = v; return this;} private Gfo_msg_itm expd_err;
|
||||
public Xow_wiki Wiki() {return fxt.Wiki();}
|
||||
public void Reset() {
|
||||
fxt.Reset();
|
||||
fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_utf8_("fr"), Bry_.new_utf8_("fr.wikipedia.org"));
|
||||
test_raw = "Test page";
|
||||
expd_ns_id = Int_.MinValue;
|
||||
expd_xwik_txt = expd_full_txt = expd_full_url = expd_page_txt = expd_page_url = expd_leaf_txt = expd_leaf_url = expd_base_txt = expd_base_url
|
||||
= expd_root_txt = expd_rest_txt = expd_talk_txt = expd_talk_url = expd_subj_txt = expd_subj_url = expd_anch_txt
|
||||
= expd_base_txt_wo_qarg = expd_leaf_txt_wo_qarg = expd_qarg_txt = null;
|
||||
expd_err = null;
|
||||
expd_force_literal_link = -1;
|
||||
fxt.Log_clear();
|
||||
}
|
||||
public void Test() {
|
||||
Xoa_ttl actl = Xoa_ttl.parse_(fxt.Wiki(), Bry_.new_utf8_(test_raw));
|
||||
if (expd_err == null) {
|
||||
if (expd_ns_id != Int_.MinValue) Tfds.Eq(expd_ns_id, actl.Ns().Id(), "ns");
|
||||
if (expd_xwik_txt != null) Tfds.Eq(expd_xwik_txt, String_.new_utf8_(actl.Wik_txt()), "Wiki");
|
||||
if (expd_page_txt != null) Tfds.Eq(expd_page_txt, String_.new_utf8_(actl.Page_txt()), "Page_txt");
|
||||
if (expd_page_url != null) Tfds.Eq(expd_page_url, String_.new_utf8_(actl.Page_url()), "Page_url");
|
||||
if (expd_full_txt != null) Tfds.Eq(expd_full_txt, String_.new_utf8_(actl.Full_txt()), "Full_txt");
|
||||
if (expd_full_url != null) Tfds.Eq(expd_full_url, String_.new_utf8_(actl.Full_url()), "Full_url");
|
||||
if (expd_leaf_txt != null) Tfds.Eq(expd_leaf_txt, String_.new_utf8_(actl.Leaf_txt()), "Leaf_txt");
|
||||
if (expd_leaf_url != null) Tfds.Eq(expd_leaf_url, String_.new_utf8_(actl.Leaf_url()), "Leaf_url");
|
||||
if (expd_base_txt != null) Tfds.Eq(expd_base_txt, String_.new_utf8_(actl.Base_txt()), "Base_txt");
|
||||
if (expd_base_url != null) Tfds.Eq(expd_base_url, String_.new_utf8_(actl.Base_url()), "Base_url");
|
||||
if (expd_root_txt != null) Tfds.Eq(expd_root_txt, String_.new_utf8_(actl.Root_txt()), "Root_txt");
|
||||
if (expd_rest_txt != null) Tfds.Eq(expd_rest_txt, String_.new_utf8_(actl.Rest_txt()), "Rest_txt");
|
||||
if (expd_talk_txt != null) Tfds.Eq(expd_talk_txt, String_.new_utf8_(actl.Talk_txt()), "Talk_txt");
|
||||
if (expd_talk_url != null) Tfds.Eq(expd_talk_url, String_.new_utf8_(actl.Talk_url()), "Talk_url");
|
||||
if (expd_subj_txt != null) Tfds.Eq(expd_subj_txt, String_.new_utf8_(actl.Subj_txt()), "Subj_txt");
|
||||
if (expd_subj_url != null) Tfds.Eq(expd_subj_url, String_.new_utf8_(actl.Subj_url()), "Subj_url");
|
||||
if (expd_anch_txt != null) Tfds.Eq(expd_anch_txt, String_.new_utf8_(actl.Anch_txt()), "Anch_txt");
|
||||
if (expd_qarg_txt != null) Tfds.Eq(expd_qarg_txt, String_.new_utf8_(actl.Qarg_txt()), "Qarg_txt");
|
||||
if (expd_base_txt_wo_qarg != null) Tfds.Eq(expd_base_txt_wo_qarg, String_.new_utf8_(actl.Base_txt_wo_qarg()), "Expd_base_txt_wo_qarg");
|
||||
if (expd_leaf_txt_wo_qarg != null) Tfds.Eq(expd_leaf_txt_wo_qarg, String_.new_utf8_(actl.Leaf_txt_wo_qarg()), "Expd_leaf_txt_wo_qarg");
|
||||
if (expd_force_literal_link != -1) Tfds.Eq(expd_force_literal_link == 1, actl.ForceLiteralLink(), "ForceLiteralLink");
|
||||
}
|
||||
else {
|
||||
Tfds.Eq_ary(String_.Ary(String_.new_utf8_(expd_err.Owner().Path()) + "." + String_.new_utf8_(expd_err.Key_bry())), fxt.Log_xtoAry());
|
||||
}
|
||||
}
|
||||
}
|
||||
280
400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java
Normal file
280
400_xowa/src/gplx/xowa/bldrs/Db_mgr_fxt.java
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
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.xowa.dbs.*; import gplx.xowa.specials.search.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.tbls.*;
|
||||
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 Xodb_page page_(int id, String modified_on, boolean type_redirect, int text_len) {return new Xodb_page().Id_(id).Modified_on_(DateAdp_.parse_gplx(modified_on)).Type_redirect_(type_redirect).Text_len_(text_len);}
|
||||
public Xow_wiki Wiki() {return bldr_fxt.Wiki();}
|
||||
public Xob_bldr Bldr() {return bldr_fxt.Bldr();}
|
||||
public Db_mgr_fxt doc_ary_(Xodb_page... v) {bldr_fxt.doc_ary_(v); return this;}
|
||||
public Xodb_page doc_(int id, String date, String title, String text) {return bldr_fxt.doc_(id, date, title, text);}
|
||||
public Xodb_page doc_wo_date_(int id, String title, String text) {return bldr_fxt.doc_(id, "2012-01-02 03:04", title, text);}
|
||||
public Xodb_page 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._.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) {
|
||||
Xow_wiki wiki = this.Wiki();
|
||||
Xodb_page_tbl tbl_page = wiki.Db_mgr_as_sql().Tbl_page();
|
||||
Db_stmt stmt = Db_stmt_.Null;
|
||||
try {
|
||||
stmt = tbl_page.Insert_stmt(wiki.Db_mgr_as_sql().Fsys_mgr().Page_provider());
|
||||
int len = ttls.length;
|
||||
DateAdp modified_on = Tfds.Now_time0_add_min(0);
|
||||
for (int i = 0; i < len; i++) {
|
||||
String ttl = ttls[i];
|
||||
int page_id = page_id_next.Val();
|
||||
tbl_page.Insert(stmt, page_id, ns_id, Bry_.new_utf8_(ttl), false, modified_on, 0, page_id, 0);
|
||||
page_id_next.Val_add(1);
|
||||
}
|
||||
} finally {stmt.Rls();}
|
||||
}
|
||||
public void Test_load_ttl(int ns_id, String ttl_str, Xodb_page expd) {
|
||||
Xow_wiki wiki = bldr_fxt.Wiki();
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
byte[] ttl_bry = Bry_.new_ascii_(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.Type_redirect(), actl.Type_redirect());
|
||||
Tfds.Eq(expd.Text_len(), actl.Text_len());
|
||||
} private Xodb_page actl = new Xodb_page();
|
||||
public void Test_load_page(int ns_id, int page_id, String expd) {
|
||||
Xow_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_ascii_(actl.Text()));
|
||||
}
|
||||
public void Test_search(String search_word_str, int... expd) {
|
||||
Xow_wiki wiki = bldr_fxt.Wiki();
|
||||
ListAdp rv = ListAdp_.new_();
|
||||
byte[] search_word_bry = Bry_.new_ascii_(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(ListAdp rslts) {
|
||||
int len = rslts.Count();
|
||||
int[] rv = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xodb_page page = (Xodb_page)rslts.FetchAt(i);
|
||||
rv[i] = page.Id();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Test_category_v1(String ctg_name_str, int... expd) {
|
||||
Xow_wiki wiki = bldr_fxt.Wiki();
|
||||
byte[] ctg_name_bry = Bry_.new_ascii_(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) {
|
||||
ListAdp list = ListAdp_.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().FetchAt(i);
|
||||
list.Add(itm.Id());
|
||||
}
|
||||
}
|
||||
return (int[])list.XtoAryAndClear(int.class);
|
||||
}
|
||||
public void Test_category_v2(String ctg_name_str, int... expd) {
|
||||
Xow_wiki wiki = bldr_fxt.Wiki();
|
||||
byte[] ctg_name_bry = Bry_.new_ascii_(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._.LoadFilStr(url);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
int[] Xto_int_ary(Xoctg_data_ctg ctg) {
|
||||
ListAdp list = ListAdp_.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.XtoAryAndClear(int.class);
|
||||
}
|
||||
public void Init_db_sqlite() {Init_db_sqlite(Xoa_test_.Url_wiki_enwiki().GenSubFil_nest("en.wikipedia.org.sqlite3"));}
|
||||
public void Init_db_sqlite(Io_url url) {
|
||||
Xow_wiki wiki = this.Wiki();
|
||||
Db_provider_pool._.Clear();
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_create_as_sql();
|
||||
db_mgr.Data_storage_format_(gplx.ios.Io_stream_.Tid_file);
|
||||
db_mgr.Init_make("");
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Core_provider();
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("xowa_cfg"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("xowa_db"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("xowa_ns"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("page"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("text"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("category"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("categorylinks"));
|
||||
} String dsv_db;
|
||||
public void Init_db_tdb() {
|
||||
Io_mgr._.InitEngine_mem();
|
||||
this.Ctor_mem();
|
||||
if (dsv_db == null) dsv_db = dsv_db_();
|
||||
// mem/xowa/bin/any/sql/xowa/xowa.sqlite3
|
||||
Io_url url = Io_url_.mem_fil_("mem/tdb/en.wikipedia.org/xowa.tdb");
|
||||
Io_mgr._.SaveFilStr(url, dsv_db);
|
||||
Io_url url2 = Io_url_.mem_fil_("mem/xowa/bin/any/sql/xowa/xowa.sqlite3");
|
||||
Io_mgr._.SaveFilStr(url2, dsv_db);
|
||||
this.Wiki().Db_mgr_create_as_sql();// .("gplx_key=tdb;url=" + url.Raw());
|
||||
this.Wiki().Db_mgr_as_sql().Init_make("");
|
||||
}
|
||||
private static String dsv_db_() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
dsv_tbl_files(sb);
|
||||
dsv_tbl_tables(sb);
|
||||
dsv_tbl_xowa_cfg(sb);
|
||||
dsv_tbl_xowa_db(sb);
|
||||
dsv_tbl_xowa_ns(sb);
|
||||
dsv_tbl_page(sb);
|
||||
dsv_tbl_text(sb);
|
||||
dsv_tbl_category(sb);
|
||||
dsv_tbl_categorylinks(sb);
|
||||
return sb.XtoStrAndClear();
|
||||
}
|
||||
private static void Add_lines_w_crlf(String_bldr sb, String... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.Add(ary[i]);
|
||||
sb.Add(String_.CrLf);
|
||||
}
|
||||
}
|
||||
private static void dsv_tbl_files(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "_files, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,string,string, ,\" \",$"
|
||||
, "id,url,format, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
, "1,,dsv"
|
||||
, "2,,dsv"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_tables(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "_tables, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,string,int, ,\" \",$"
|
||||
, "id,name,file_id, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
, "1,xowa_cfg,1"
|
||||
, "2,xowa_db,1"
|
||||
, "3,xowa_ns,1"
|
||||
, "4,page,1"
|
||||
, "5,text,1"
|
||||
, "6,category,1"
|
||||
, "7,categorylinks,1"
|
||||
// , "8,site_stats,1"
|
||||
// , "9,wdata_qids,1"
|
||||
// , "10,wdata_pids,1"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_xowa_cfg(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "xowa_cfg, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "string,string,string, ,\" \",$"
|
||||
, "cfg_grp,cfg_key,cfg_val, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_xowa_db(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "xowa_db, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,byte,string, ,\" \",$"
|
||||
, "db_id,db_type,db_url, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_xowa_ns(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "xowa_ns, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,string,byte,bool,int, ,\" \",$"
|
||||
, "ns_id,ns_name,ns_case,ns_is_alias,ns_count, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_page(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "page, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,int,string,byte,string,int,int,int, ,\" \",$"
|
||||
, "page_id,page_namespace,page_title,page_is_redirect,page_touched,page_len,page_random_int,page_file_idx, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_text(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "text, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,string, ,\" \",$"
|
||||
, "page_id,old_text, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_categorylinks(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "categorylinks, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,int,string,string,int,byte, ,\" \",$"
|
||||
, "cl_from,cl_to,cl_to_id,cl_sortkey,cl_timestamp,cl_type_id, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
private static void dsv_tbl_category(String_bldr sb) {
|
||||
Add_lines_w_crlf(sb
|
||||
, "================================, ,\" \",//"
|
||||
, "category, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int,int,int,int,byte,int, ,\" \",$"
|
||||
, "cat_id,cat_pages,cat_subcats,cat_files,cat_hidden,cat_file_idx, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
this.Wiki().Db_mgr().Rls();
|
||||
}
|
||||
}
|
||||
26
400_xowa/src/gplx/xowa/bldrs/Xob_cmd.java
Normal file
26
400_xowa/src/gplx/xowa/bldrs/Xob_cmd.java
Normal 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_ini(Xob_bldr bldr);
|
||||
void Cmd_bgn(Xob_bldr bldr);
|
||||
void Cmd_run();
|
||||
void Cmd_end();
|
||||
void Cmd_print();
|
||||
}
|
||||
148
400_xowa/src/gplx/xowa/bldrs/Xob_cmd_mgr.java
Normal file
148
400_xowa/src/gplx/xowa/bldrs/Xob_cmd_mgr.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
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.*; import gplx.xowa.xtns.wdatas.imports.*; import gplx.xowa.bldrs.imports.ctgs.*; import gplx.xowa.bldrs.imports.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
import gplx.xowa.bldrs.wikis.redirects.*; import gplx.xowa.bldrs.wikis.images.*; import gplx.xowa.files.wiki_orig.*;
|
||||
import gplx.xowa.bldrs.files.*;
|
||||
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();} ListAdp list = ListAdp_.new_();
|
||||
public Xob_cmd Get_at(int i) {return (Xob_cmd)list.FetchAt(i);}
|
||||
public Xob_cmd Add(Xob_cmd cmd) {list.Add(cmd); return cmd;}
|
||||
public GfoInvkAble Add_cmd(Xow_wiki wiki, String cmd_key) {
|
||||
if (String_.Eq(cmd_key, Xob_init_txt.KEY)) return Add(new Xob_init_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_init_sql.KEY)) return Add(new Xob_init_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_term_txt.KEY)) return Add(new Xob_term_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_term_sql.KEY)) return Add(new Xob_term_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_page_sql.KEY)) return Xml_rdr_direct_add(wiki, new Xob_page_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_page_txt.KEY)) return Xml_rdr_direct_add(wiki, new Xob_page_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_search_txt.KEY)) return Xml_rdr_direct_add(wiki, new Xob_search_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_ctg_v1_txt.KEY)) return Xml_rdr_parser_add(wiki, new Xob_ctg_v1_txt().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_ctg_v1_sql.KEY)) return Xml_rdr_parser_add(wiki, new Xob_ctg_v1_sql().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_categorylinks_txt.KEY)) return Add(new Xob_categorylinks_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_categorylinks_sql.KEY)) return Add(new Xob_categorylinks_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_wdata_qid_txt.KEY)) return Xml_rdr_direct_add(wiki, new Xob_wdata_qid_txt().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_wdata_qid_sql.KEY)) return Xml_rdr_direct_add(wiki, new Xob_wdata_qid_sql().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_wdata_pid_txt.KEY)) return Xml_rdr_direct_add(wiki, new Xob_wdata_pid_txt().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_wdata_pid_sql.KEY)) return Xml_rdr_direct_add(wiki, new Xob_wdata_pid_sql().Ctor(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_search_sql_wkr.KEY)) return Xml_rdr_direct_add(wiki, new Xob_search_sql_wkr(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_search_sql_cmd.KEY_search_sql)) return Add(new Xob_search_sql_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_category_registry_sql.KEY)) return Add(new Xob_category_registry_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_lnki_temp_wkr.KEY_oimg)) return Add(new Xob_lnki_temp_wkr(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_lnki_regy_cmd.KEY_oimg)) return Add(new Xob_lnki_regy_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_text_db_prep.KEY_oimg)) return Add(new Xob_text_db_prep(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_orig_regy_cmd.KEY_oimg)) return Add(new Xob_orig_regy_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_xfer_temp_cmd_thumb.KEY_oimg)) return Add(new Xob_xfer_temp_cmd_thumb(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_xfer_temp_cmd_orig.KEY_oimg)) return Add(new Xob_xfer_temp_cmd_orig(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_xfer_regy_cmd.KEY_oimg)) return Add(new Xob_xfer_regy_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_xfer_regy_update_cmd.KEY_oimg)) return Add(new Xob_xfer_regy_update_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_xfer_update_cmd.KEY_oimg)) return Add(new Xob_xfer_update_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xof_wiki_orig_cmd.KEY_oimg)) return Add(new Xof_wiki_orig_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_download_wkr.KEY_oimg)) return Add(new Xob_download_wkr(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_page_regy_cmd.KEY_oimg)) return Add(new Xob_page_regy_cmd(bldr, wiki));
|
||||
|
||||
else if (String_.Eq(cmd_key, Xob_wiki_redirect_cmd.KEY_redirect)) return Add(new Xob_wiki_redirect_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_wiki_image_sql.KEY)) return Add(new Xob_wiki_image_sql(bldr, wiki));
|
||||
|
||||
else if (String_.Eq(cmd_key, Xob_fsdb_make.KEY_oimg)) return Add(new Xob_fsdb_make(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xob_wdata_db_cmd.KEY_oimg)) return Add(new Xob_wdata_db_cmd(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xoctg_link_idx_wkr.KEY)) return Add(new Xoctg_link_idx_wkr(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xoctg_hiddencat_parser_sql.KEY)) return Add(new Xoctg_hiddencat_parser_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xoctg_hiddencat_parser_txt.KEY)) return Add(new Xoctg_hiddencat_parser_txt(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xoctg_hiddencat_ttl_wkr.KEY)) return Add(new Xoctg_hiddencat_ttl_wkr(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_core_make_id.KEY)) return Xml_rdr_direct_add(wiki, new Xobc_core_make_id(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_core_calc_stats.KEY)) return Add(new Xobc_core_calc_stats(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_core_cleanup.KEY)) return Add(new Xobc_core_cleanup(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_core_decompress_bz.KEY)) return Add(new Xobc_core_decompress_bz(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_deploy_zip.KEY)) return Add(new Xobc_deploy_zip(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_deploy_copy.KEY)) return Add(new Xobc_deploy_copy(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_parse_dump_templates.KEY)) return Xml_rdr_direct_add(wiki, new Xobc_parse_dump_templates(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_parse_run.KEY)) return Add(new Xobc_parse_run(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_dump_ttl.KEY)) return Xml_rdr_direct_add(wiki, new Xobc_img_dump_ttl(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_merge_ttl_sql.KEY)) return Add(new Xobc_img_merge_ttl_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_prep_xfer.KEY)) return Add(new Xobc_img_prep_xfer(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_run_xfer.KEY)) return Add(new Xobc_img_run_xfer(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_math_run.KEY)) return Add(new Xobc_math_run(bldr, wiki));
|
||||
else throw Err_.unhandled(cmd_key);
|
||||
}
|
||||
private Xobd_wkr Xml_rdr_direct_add(Xow_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(Xow_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(Xow_wiki wiki) {
|
||||
byte[] wiki_key = wiki.Domain_bry();
|
||||
Xobd_rdr rv = (Xobd_rdr)dump_rdrs.Fetch(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 HashAdp dump_rdrs = HashAdp_.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 Xobc_core_batch(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.FetchAt(i);
|
||||
if (String_.Eq(cmd.Cmd_key(), cmd_key)) return cmd;
|
||||
}
|
||||
throw Err_.new_fmt_("cmd not found; key=~{0}", cmd_key);
|
||||
}
|
||||
private Object Add_many(GfoMsg m) {
|
||||
Xow_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(Xow_wiki wiki, String... cmds) {
|
||||
int len = cmds.length; if (len == 0) throw Err_mgr._.fmt_(GRP_KEY, Invk_add_many, "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 Xow_wiki Wiki_get_or_make(GfoMsg m) {
|
||||
byte[] wiki_key = m.ReadBry("v");
|
||||
Xoa_wiki_mgr wiki_mgr = bldr.App().Wiki_mgr();
|
||||
Xow_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";
|
||||
}
|
||||
184
400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java
Normal file
184
400_xowa/src/gplx/xowa/bldrs/Xob_fxt.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Xob_fxt {
|
||||
public Xob_fxt Ctor_mem() {
|
||||
Io_mgr._.InitEngine_mem();
|
||||
return Ctor(Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public Xob_fxt Ctor(Io_url root_dir) {
|
||||
app = Xoa_app_fxt.app_(root_dir, "linux");
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
bldr = Xoa_app_fxt.bldr_(app);
|
||||
return this;
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public Io_url fil_ns_title(int ns_id, int idx) {return wiki.Fsys_mgr().Url_ns_fil(Xow_dir_info_.Tid_ttl, ns_id, idx);}
|
||||
public Io_url fil_ns_page(int ns_id, int idx) {return wiki.Fsys_mgr().Url_ns_fil(Xow_dir_info_.Tid_page, ns_id, idx);}
|
||||
public Io_url fil_ns_sttl(int ns_id, int idx) {return wiki.Fsys_mgr().Url_ns_fil(Xow_dir_info_.Tid_search_ttl, ns_id, idx);}
|
||||
public Io_url fil_site(byte tid, int idx) {return wiki.Fsys_mgr().Url_site_fil(tid, idx);}
|
||||
public Io_url fil_site_ctg(int idx) {return wiki.Fsys_mgr().Url_site_fil(Xow_dir_info_.Tid_category, idx);}
|
||||
public Io_url fil_site_id(int idx) {return wiki.Fsys_mgr().Url_site_fil(Xow_dir_info_.Tid_id, idx);}
|
||||
public Io_url fil_reg(byte tid) {return wiki.Fsys_mgr().Url_site_reg(tid);}
|
||||
public Io_url fil_reg(int ns_id, byte tid) {return wiki.Fsys_mgr().Url_ns_reg(Int_.XtoStr_PadBgn(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;
|
||||
} ListAdp expd_list = ListAdp_.new_();
|
||||
public Xob_fxt Fil_skip(Io_url... urls) {
|
||||
for (int i = 0; i < urls.length; i++)
|
||||
skip_list.Add(urls[i]);
|
||||
return this;
|
||||
} ListAdp skip_list = ListAdp_.new_();
|
||||
public Xob_fxt doc_ary_(Xodb_page... v) {doc_ary = v; return this;} private Xodb_page[] doc_ary;
|
||||
public Xodb_page doc_wo_date_(int id, String title, String text) {return doc_(id, "2012-01-02 13:14", title, text);}
|
||||
public Xodb_page doc_(int id, String date, String title, String text) {
|
||||
Xodb_page rv = new Xodb_page().Id_(id).Ttl_(Bry_.new_utf8_(title), wiki.Ns_mgr()).Text_(Bry_.new_utf8_(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.imports.ctgs.Xob_ctg_v1_base ctg_wkr = new gplx.xowa.bldrs.imports.ctgs.Xob_ctg_v1_txt().Ctor(bldr, wiki);
|
||||
byte[] bry = Bry_.new_utf8_("[[Category:");
|
||||
ctg_wkr.Wkr_hooks().Add(bry, bry);
|
||||
parser.Wkr_add(ctg_wkr);
|
||||
return Run(parser);
|
||||
}
|
||||
public Xob_fxt Run_id() {
|
||||
gplx.xowa.bldrs.imports.Xobc_core_make_id wkr = new gplx.xowa.bldrs.imports.Xobc_core_make_id(bldr, wiki);
|
||||
Run(wkr);
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_img(String expd) {
|
||||
Xobc_parse_run wkr = new Xobc_parse_run(bldr, wiki).Load_len_(Io_mgr.Len_kb);
|
||||
wkr.Tmpl_on_(true).Cmd_bgn(bldr);
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xodb_page page = doc_ary[i];
|
||||
wkr.Parse_page(page);
|
||||
}
|
||||
wkr.Cmd_end();
|
||||
String actl = Io_mgr._.LoadFilStr(Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/tmp/img.dump_link/make/0000000000.csv"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_math(String expd) {
|
||||
Xobc_parse_run wkr = new Xobc_parse_run(bldr, wiki).Load_len_(Io_mgr.Len_kb);
|
||||
wkr.Tmpl_on_(true).Cmd_bgn(bldr);
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xodb_page page = doc_ary[i];
|
||||
wkr.Parse_page(page);
|
||||
}
|
||||
wkr.Cmd_end();
|
||||
String actl = Io_mgr._.LoadFilStr(Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/tmp/math.text/make/0000000000.csv"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
return this;
|
||||
}
|
||||
private void Run_wkr(Xobd_wkr wkr) {
|
||||
wkr.Wkr_bgn(bldr);
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xodb_page 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.XtoAry(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._.LoadFilStr(url);
|
||||
rv[i] = new Io_fil(url, data);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xob_fxt Run_tmpl_dump() {
|
||||
Xobc_parse_dump_templates wkr = new Xobc_parse_dump_templates(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.imports.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++) {
|
||||
Xodb_page 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.XtoAry(Io_fil_chkr.class);
|
||||
Io_fil[] actl = wiki_();
|
||||
tst_mgr.Tst_ary("all", expd, actl);
|
||||
}
|
||||
}
|
||||
Io_fil[] wiki_() {
|
||||
ListAdp rv = ListAdp_.new_();
|
||||
wiki_fil_add(rv, wiki.Fsys_mgr().Ns_dir());
|
||||
wiki_fil_add(rv, wiki.Fsys_mgr().Site_dir());
|
||||
rv.Sort();
|
||||
return (Io_fil[])rv.XtoAry(Io_fil.class);
|
||||
}
|
||||
private void wiki_fil_add(ListAdp list, Io_url root_dir) {
|
||||
Io_url[] ary = Io_mgr._.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._.LoadFilStr_args(url).MissingIgnored_().Exec());
|
||||
list.Add(fil);
|
||||
}
|
||||
}
|
||||
Tst_mgr tst_mgr = new Tst_mgr();
|
||||
DateAdp_parser dateParser = DateAdp_parser.new_();
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/bldrs/aria2/Aria2_lib_mgr.java
Normal file
50
400_xowa/src/gplx/xowa/bldrs/aria2/Aria2_lib_mgr.java
Normal 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(Xoa_app app) {
|
||||
Xoa_fsys_eval cmd_eval = app.Url_cmd_eval();
|
||||
ProcessAdp.ini_(this, app.Gui_wtr(), 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_utf8_(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"
|
||||
, " http://dumps.wikimedia.org/~{wiki_abrv}/~{wiki_date}/~{wiki_abrv}-~{wiki_date}-~{wiki_type}.xml.bz2"
|
||||
);
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/bldrs/aria2/Gfui_process_win.java
Normal file
40
400_xowa/src/gplx/xowa/bldrs/aria2/Gfui_process_win.java
Normal 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;
|
||||
}
|
||||
55
400_xowa/src/gplx/xowa/bldrs/cfgs/Xob_wiki_cfg_bldr.java
Normal file
55
400_xowa/src/gplx/xowa/bldrs/cfgs/Xob_wiki_cfg_bldr.java
Normal 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.bldrs.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xob_wiki_cfg_bldr implements GfoInvkAble {
|
||||
public Xob_wiki_cfg_bldr(Xob_bldr bldr) {this.app = bldr.App();} private Xoa_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.FetchAt(i);
|
||||
Exec_fil(fil);
|
||||
}
|
||||
}
|
||||
private void Exec_fil(Xoac_wiki_cfg_bldr_fil fil) {
|
||||
String wiki_key = fil.Wiki();
|
||||
Io_url cfg_file = app.User().Fsys_mgr().Wiki_root_dir().GenSubFil_nest("#cfg", "system", wiki_key + ".gfs");
|
||||
String cfg_text = Io_mgr._.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._.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.Fetch(wiki);
|
||||
if (rv == null) {
|
||||
rv = new Xoac_wiki_cfg_bldr_fil(wiki);
|
||||
hash.Add(wiki, rv);
|
||||
}
|
||||
return rv;
|
||||
} private OrderedHash hash = OrderedHash_.new_();
|
||||
}
|
||||
179
400_xowa/src/gplx/xowa/bldrs/cfgs/Xob_wiki_cfg_bldr_tst.java
Normal file
179
400_xowa/src/gplx/xowa/bldrs/cfgs/Xob_wiki_cfg_bldr_tst.java
Normal 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.*;
|
||||
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._.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._.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_.HasAtBgn(lang_code, "be_")
|
||||
// || String_.HasAtBgn(lang_code, "crh_")
|
||||
// || String_.HasAtBgn(lang_code, "kk_")
|
||||
// || String_.HasAtBgn(lang_code, "ku_")
|
||||
// || String_.HasAtBgn(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.XtoStrAndClear());
|
||||
// }
|
||||
@Test public void Ns_aliases() {
|
||||
Io_mgr._.InitEngine_mem();
|
||||
Io_mgr._.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.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_utf8_(Io_mgr._.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.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().FetchAt(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_.XtoStr(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.XtoStrAndClear();
|
||||
}
|
||||
}
|
||||
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 Xoa_app app; Xob_wiki_cfg_bldr wiki_cfg_bldr; OrderedHash hash = OrderedHash_.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.FetchAt(i);
|
||||
String wiki = kv.Key();
|
||||
String expd = (String)kv.Val();
|
||||
String actl = Io_mgr._.LoadFilStr(app.User().Fsys_mgr().Wiki_root_dir().GenSubFil_nest("#cfg", "system", wiki + ".gfs"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
400_xowa/src/gplx/xowa/bldrs/files/Xob_download_wkr.java
Normal file
69
400_xowa/src/gplx/xowa/bldrs/files/Xob_download_wkr.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
public class Xob_download_wkr extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private String dump_date = "latest";
|
||||
private String dump_type = null;
|
||||
private String dump_src = null;
|
||||
private Io_url dump_trg_zip = null, dump_trg_bin = null;
|
||||
private boolean unzip = true;
|
||||
public Xob_download_wkr(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.download";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
if (dump_type == null) throw Err_.new_("dump_type must be specified");
|
||||
Xob_dump_file dump_file = Xob_dump_file.new_(wiki.Domain_str(), dump_date, dump_type);
|
||||
if (dump_src == null) {
|
||||
dump_file.Server_url_(app.Setup_mgr().Dump_mgr().Server_urls()[0]);
|
||||
dump_src = dump_file.File_url();
|
||||
}
|
||||
if (dump_trg_zip == null)
|
||||
dump_trg_zip = wiki.Fsys_mgr().Root_dir().GenSubFil(dump_file.File_name());
|
||||
if (dump_trg_bin == null && unzip)
|
||||
dump_trg_bin = dump_trg_zip.GenNewNameAndExt(dump_trg_zip.NameOnly()); // convert a.sql.gz -> a.sql
|
||||
}
|
||||
public void Cmd_run() {
|
||||
usr_dlg.Note_many("", "", "downloading file: now=~{0} src=~{1} trg=~{2}", DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss(), dump_src, dump_trg_zip.OwnerDir());
|
||||
IoEngine_xrg_downloadFil download_wkr = app.File_mgr().Download_mgr().Download_wkr().Download_xrg();
|
||||
download_wkr.Src_last_modified_query_(false).Init(dump_src, dump_trg_zip);
|
||||
if (!download_wkr.Exec())
|
||||
usr_dlg.Warn_many("", "", "download failed: src=~{0} trg=~{1} err=~{2}", dump_src, dump_trg_zip.Raw(), Err_.Message_gplx_brief(download_wkr.Rslt_err()));
|
||||
if (unzip) {
|
||||
usr_dlg.Note_many("", "", "unzipping file: now=~{0} trg=~{1}", DateAdp_.Now().XtoStr_fmt_yyyyMMdd_HHmmss(), dump_trg_bin.Raw());
|
||||
Xob_unzip_wkr unzip_wkr = new Xob_unzip_wkr().Init(app).Process_run_mode_(ProcessAdp.Run_mode_sync_block);
|
||||
unzip_wkr.Decompress(dump_trg_zip, dump_trg_bin);
|
||||
}
|
||||
}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (String_.Eq(k, Invk_dump_date_)) dump_date = m.ReadStr("v");
|
||||
else if (String_.Eq(k, Invk_dump_type_)) dump_type = m.ReadStr("v");
|
||||
else if (String_.Eq(k, Invk_unzip_)) unzip = m.ReadYn("v");
|
||||
else if (String_.Eq(k, Invk_dump_src_)) dump_src = m.ReadStr("v");
|
||||
else if (String_.Eq(k, Invk_dump_trg_zip_)) dump_trg_zip = m.ReadIoUrl("v");
|
||||
else if (String_.Eq(k, Invk_dump_trg_bin_)) dump_trg_bin = m.ReadIoUrl("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String
|
||||
Invk_dump_date_ = "dump_date_", Invk_dump_type_ = "dump_type_", Invk_unzip_ = "unzip_"
|
||||
, Invk_dump_src_ = "dump_src_", Invk_dump_trg_zip_ = "dump_trg_zip_", Invk_dump_trg_bin_ = "dump_trg_bin_"
|
||||
;
|
||||
}
|
||||
323
400_xowa/src/gplx/xowa/bldrs/files/Xob_fsdb_make.java
Normal file
323
400_xowa/src/gplx/xowa/bldrs/files/Xob_fsdb_make.java
Normal file
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.fsdb.*; import gplx.ios.*; import gplx.xowa.files.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.dbs.tbls.*;
|
||||
import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_fsdb_make extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private int select_interval = 2500, progress_interval = 1, commit_interval = 1, delete_interval = 5000;
|
||||
private int exec_count, exec_count_max = Int_.MaxValue;
|
||||
private int exec_fail, exec_fail_max = 2000; // 115 over 900k
|
||||
private boolean exec_done;
|
||||
private int page_id_bmk = -1, lnki_id_bmk = -1;
|
||||
private int page_id_val = -1, lnki_id_val = -1;
|
||||
private int page_id_end = Int_.MaxValue;
|
||||
private boolean reset_db = false, exit_after_commit = false, exit_now = false;
|
||||
private byte[] wiki_key;
|
||||
private Xobu_poll_mgr poll_mgr; private int poll_interval;
|
||||
private long time_bgn;
|
||||
private Xodb_xowa_cfg_tbl tbl_cfg; private Db_provider provider; private Db_stmt db_select_stmt;
|
||||
private Xof_bin_mgr src_mgr;
|
||||
private Xof_fsdb_mgr_sql trg_fsdb_mgr; private Fsdb_mnt_mgr trg_mnt_mgr;
|
||||
private ListAdp temp_files = ListAdp_.new_();
|
||||
private Fsdb_xtn_img_itm tmp_img_itm = new Fsdb_xtn_img_itm(); private Fsdb_xtn_thm_itm tmp_thm_itm = Fsdb_xtn_thm_itm.new_(); private Fsdb_fil_itm tmp_fil_itm = new Fsdb_fil_itm();
|
||||
private boolean app_restart_enabled = false;
|
||||
private Xof_fsdb_mgr_sql src_fsdb_mgr;
|
||||
public Xob_fsdb_make(Xob_bldr bldr, Xow_wiki wiki) {
|
||||
this.Cmd_ctor(bldr, wiki);
|
||||
trg_fsdb_mgr = new Xof_fsdb_mgr_sql(wiki);
|
||||
trg_fsdb_mgr.Init_by_wiki(wiki);
|
||||
src_fsdb_mgr = new Xof_fsdb_mgr_sql(wiki);
|
||||
src_fsdb_mgr.Init_by_wiki(wiki);
|
||||
src_mgr = src_fsdb_mgr.Bin_mgr();
|
||||
trg_mnt_mgr = trg_fsdb_mgr.Mnt_mgr();
|
||||
trg_mnt_mgr.Insert_to_mnt_(Fsdb_mnt_mgr.Mnt_idx_main); // NOTE: do not delete; mnt_mgr default to Mnt_idx_user; DATE:2014-04-25
|
||||
Fsdb_mnt_mgr.Patch(trg_mnt_mgr); // NOTE: always patch again; fsdb_make may be run separately without lnki_temp; DATE:2014-04-26
|
||||
poll_mgr = new Xobu_poll_mgr(bldr.App());
|
||||
}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.fsdb_make";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
((Xof_bin_wkr_http_wmf)src_fsdb_mgr.Bin_mgr().Get_or_new(Xof_bin_wkr_.Key_http_wmf)).Fail_timeout_(1000); // NOTE: set Fail_timeout here; DATE:2014-06-21; NOTE: do not put in ctor, or else will be 1st wkr; DATE:2014-06-28
|
||||
this.wiki_key = wiki.Domain_bry();
|
||||
wiki.Init_assert();
|
||||
poll_interval = poll_mgr.Poll_interval();
|
||||
}
|
||||
public void Cmd_run() {Exec();}
|
||||
public void Cmd_end() {
|
||||
if (exec_done) {
|
||||
page_id_bmk = Int_.MaxValue;
|
||||
lnki_id_bmk = Int_.MaxValue;
|
||||
}
|
||||
usr_dlg.Note_many("", "", "done: ~{0} ~{1}", exec_count, DecimalAdp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).XtoStr("#,###.000"));
|
||||
this.Txn_save();
|
||||
trg_fsdb_mgr.Txn_save();
|
||||
trg_fsdb_mgr.Rls(); // save changes and rls all connections
|
||||
db_select_stmt.Rls();
|
||||
provider.Rls();
|
||||
}
|
||||
public void Cmd_print() {}
|
||||
private int db_reset_tries_count = 0, db_reset_tries_max = 5;
|
||||
public void Exec() {
|
||||
Init_db(true);
|
||||
if (!Init_bmk(tbl_cfg)) {usr_dlg.Note_many("", "", "make done; delete xowa_cfg to restart"); return;}
|
||||
ListAdp list = ListAdp_.new_();
|
||||
boolean loop = true;
|
||||
time_bgn = Env_.TickCount();
|
||||
usr_dlg.Note_many("", "", "total pending: ~{0}", Xob_xfer_regy_tbl.Select_total_pending(provider));
|
||||
this.Txn_open();
|
||||
while (loop) {
|
||||
byte rslt = Select_ttls(list);
|
||||
switch (rslt) {
|
||||
case Select_ttls_rslt_stop: loop = false; break;
|
||||
case Select_ttls_rslt_next_page: ++page_id_val; lnki_id_val = 0; continue;
|
||||
case Select_ttls_rslt_process: break;
|
||||
}
|
||||
if (!loop) break; // no more ttls found
|
||||
int list_count = list.Count();
|
||||
usr_dlg.Prog_many("", "", "fetched pages: ~{0}", list_count);
|
||||
for (int i = 0; i < list_count; i++) {
|
||||
Xodb_tbl_oimg_xfer_itm itm = (Xodb_tbl_oimg_xfer_itm)list.FetchAt(i);
|
||||
if (!Download_itm(itm)
|
||||
|| app_restart_enabled) {
|
||||
this.Txn_renew();
|
||||
if (db_reset_tries_count < db_reset_tries_max) {
|
||||
db_reset_tries_count++;
|
||||
usr_dlg.Note_many("", "", "restarting db: ~{0}", db_reset_tries_count);
|
||||
Init_db(false);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
if ( exit_now
|
||||
|| exec_count >= exec_count_max
|
||||
|| exec_fail >= exec_fail_max
|
||||
|| page_id_val >= page_id_end
|
||||
) {
|
||||
this.Txn_renew();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
exec_done = true;
|
||||
}
|
||||
private void Init_db(boolean chk_reset) {
|
||||
Xodb_db_file db_file = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir());
|
||||
provider = db_file.Provider();
|
||||
tbl_cfg = new Xodb_xowa_cfg_tbl().Provider_(provider);
|
||||
if (reset_db && chk_reset) {
|
||||
provider.Exec_qry(Db_qry_.delete_tbl_(Xodb_xowa_cfg_tbl.Tbl_name));
|
||||
}
|
||||
db_select_stmt = Xob_xfer_regy_tbl.Select_by_page_id_stmt(provider);
|
||||
}
|
||||
private boolean Init_bmk(Xodb_xowa_cfg_tbl tbl_cfg) {
|
||||
String page_id_str = tbl_cfg.Select_val(Cfg_fsdb_make, Cfg_page_id_bmk);
|
||||
if (page_id_str == null) { // bmks not found; new db; insert;
|
||||
tbl_cfg.Insert_str(Cfg_fsdb_make, Cfg_page_id_bmk , Int_.XtoStr(page_id_bmk));
|
||||
tbl_cfg.Insert_str(Cfg_fsdb_make, Cfg_lnki_id_bmk , Int_.XtoStr(lnki_id_bmk));
|
||||
if (page_id_bmk == -1)
|
||||
page_id_bmk = 0;
|
||||
if (lnki_id_bmk == -1)
|
||||
lnki_id_bmk = 0;
|
||||
}
|
||||
else {
|
||||
if (page_id_bmk == -1) {
|
||||
page_id_bmk = Int_.parse_(page_id_str);
|
||||
if (page_id_bmk == Int_.MaxValue) return false;
|
||||
usr_dlg.Note_many("", "", "restoring from bmk: page_id=~{0}", page_id_bmk);
|
||||
}
|
||||
if (lnki_id_bmk == -1) {
|
||||
lnki_id_bmk = tbl_cfg.Select_val_as_int(Cfg_fsdb_make, Cfg_lnki_id_bmk);
|
||||
usr_dlg.Note_many("", "", "restoring from bmk: lnki_id=~{0}", lnki_id_bmk);
|
||||
}
|
||||
}
|
||||
page_id_val = page_id_bmk;
|
||||
lnki_id_val = lnki_id_bmk;
|
||||
return true;
|
||||
}
|
||||
private static final byte Select_ttls_rslt_stop = 0, Select_ttls_rslt_process = 1, Select_ttls_rslt_next_page = 2;
|
||||
private byte Select_ttls(ListAdp list) {
|
||||
list.Clear();
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
boolean pages_found = false, links_found = false;
|
||||
try {
|
||||
rdr = Xob_xfer_regy_tbl.Select_by_lnki_page_id(provider, page_id_val, select_interval);
|
||||
while (rdr.MoveNextPeer()) {
|
||||
pages_found = true; // at least one page found; set true
|
||||
Xodb_tbl_oimg_xfer_itm itm = Xodb_tbl_oimg_xfer_itm.new_rdr_(rdr);
|
||||
if (itm.Lnki_page_id() == page_id_val // if same page_id but lnki_id < last, then ignore; needed b/c select selects by page_id, and need to be handle breaks between pages
|
||||
&& itm.Lnki_id() <= lnki_id_val)
|
||||
continue;
|
||||
links_found = true;
|
||||
list.Add(itm);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
if (pages_found && !links_found)
|
||||
return Select_ttls_rslt_next_page;
|
||||
else if (!pages_found )
|
||||
return Select_ttls_rslt_stop;
|
||||
else
|
||||
return Select_ttls_rslt_process;
|
||||
}
|
||||
private boolean Download_itm(Xodb_tbl_oimg_xfer_itm itm) {
|
||||
try {
|
||||
page_id_val = itm.Lnki_page_id();
|
||||
lnki_id_val = itm.Lnki_id();
|
||||
Download(itm);
|
||||
if ((exec_count % poll_interval) == 0)
|
||||
poll_mgr.Poll();
|
||||
if (exec_count % commit_interval == 0)
|
||||
this.Txn_renew();
|
||||
if (exec_count % delete_interval == 0)
|
||||
Delete_files();
|
||||
return true;
|
||||
}
|
||||
catch (Exception exc) {
|
||||
++exec_fail;
|
||||
String exc_message = Err_.Message_gplx_brief(exc);
|
||||
usr_dlg.Warn_many("", "", "download error; ttl=~{0} w=~{1} err=~{2}", String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w(), exc_message);
|
||||
return !String_.Has(exc_message, "out of memory"); // hard stop if "java.sql.SQLException out of memory [java.sql.SQLException]" or "java.sql.SQLException [SQLITE_NOMEM] A malloc() failed (out of memory) [java.sql.SQLException]"; else code will fail for a hundred or more downloads before coming to a hard stop
|
||||
}
|
||||
}
|
||||
private void Download(Xodb_tbl_oimg_xfer_itm itm) {
|
||||
byte[] wiki = itm.Orig_repo() == Xof_repo_itm.Repo_local ? wiki_key : Xow_wiki_.Domain_commons_bry;
|
||||
itm.Orig_wiki_(wiki);
|
||||
Io_stream_rdr bin_rdr = Io_stream_rdr_.Null;
|
||||
if ((exec_count % progress_interval) == 0) {
|
||||
int time_elapsed = Env_.TickCount_elapsed_in_sec(time_bgn);
|
||||
usr_dlg.Prog_many("", "", "prog: num=~{0} err=~{1} time=~{2} rate=~{3} page=~{4} lnki=~{5} ttl=~{6}", exec_count, exec_fail, time_elapsed, Math_.Div_safe_as_int(exec_count, time_elapsed), page_id_val, lnki_id_val, String_.new_utf8_(itm.Orig_ttl()));
|
||||
}
|
||||
try {
|
||||
bin_rdr = src_mgr.Find_as_rdr(temp_files, Xof_exec_tid.Tid_wiki_page, itm);
|
||||
if (bin_rdr == Io_stream_rdr_.Null)
|
||||
Download_fail(itm);
|
||||
else {
|
||||
Download_pass(itm, bin_rdr);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
bin_rdr.Rls();
|
||||
}
|
||||
++exec_count;
|
||||
}
|
||||
private void Download_fail(Xodb_tbl_oimg_xfer_itm itm) {
|
||||
++exec_fail;
|
||||
String lnki_ttl = String_.Format("[[File:{0}|{1}px]]", String_.new_utf8_(itm.Lnki_ttl()), itm.Html_w());
|
||||
usr_dlg.Warn_many("", "", "failed: ttl=~{0}", lnki_ttl);
|
||||
}
|
||||
private void Download_pass(Xodb_tbl_oimg_xfer_itm itm, Io_stream_rdr rdr) {
|
||||
int db_uid = -1;
|
||||
if (itm.File_is_orig()) {
|
||||
if (itm.Lnki_ext().Id_is_image()) {
|
||||
trg_fsdb_mgr.Img_insert(tmp_img_itm, itm.Orig_wiki(), itm.Lnki_ttl(), itm.Lnki_ext_id(), itm.Orig_w(), itm.Orig_h(), Sqlite_engine_.Date_null, Fsdb_xtn_thm_tbl.Hash_null, rdr.Len(), rdr);
|
||||
db_uid = tmp_img_itm.Id();
|
||||
}
|
||||
else {
|
||||
trg_fsdb_mgr.Fil_insert(tmp_fil_itm, itm.Orig_wiki(), itm.Lnki_ttl(), itm.Lnki_ext_id(), Sqlite_engine_.Date_null, Fsdb_xtn_thm_tbl.Hash_null, rdr.Len(), rdr);
|
||||
db_uid = tmp_fil_itm.Id();
|
||||
}
|
||||
}
|
||||
else {
|
||||
trg_fsdb_mgr.Thm_insert(tmp_thm_itm, itm.Orig_wiki(), itm.Lnki_ttl(), itm.Lnki_ext_id(), itm.Html_w(), itm.Html_h(), itm.Lnki_thumbtime(), itm.Lnki_page(), Sqlite_engine_.Date_null, Fsdb_xtn_thm_tbl.Hash_null, rdr.Len(), rdr);
|
||||
db_uid = tmp_thm_itm.Id();
|
||||
}
|
||||
app.Usr_dlg().Log_direct(String_.Format("download done; size=~{0} id=~{1}\n", rdr.Len(), db_uid));
|
||||
}
|
||||
private void Txn_renew() {
|
||||
this.Txn_save();
|
||||
this.Txn_open();
|
||||
}
|
||||
private void Txn_open() {
|
||||
tbl_cfg.Provider().Txn_mgr().Txn_bgn_if_none();
|
||||
trg_mnt_mgr.Txn_open();
|
||||
}
|
||||
private void Txn_save() {
|
||||
usr_dlg.Prog_many("", "", "committing data: count=~{0} failed=~{1}", exec_count, exec_fail);
|
||||
tbl_cfg.Update(Cfg_fsdb_make, Cfg_page_id_bmk, page_id_val);
|
||||
tbl_cfg.Update(Cfg_fsdb_make, Cfg_lnki_id_bmk, lnki_id_val);
|
||||
tbl_cfg.Provider().Txn_mgr().Txn_end_all();
|
||||
trg_mnt_mgr.Txn_save();
|
||||
if (exit_after_commit)
|
||||
exit_now = true;
|
||||
}
|
||||
private void Delete_files() {
|
||||
int len = temp_files.Count();
|
||||
for (int i = 0;i < len; i++) {
|
||||
Io_url url = (Io_url)temp_files.FetchAt(i);
|
||||
try {Io_mgr._.DeleteFil(url);}
|
||||
catch (Exception e) {
|
||||
usr_dlg.Warn_many("", "", "failed to delete temp file: idx=~{0} url=~{1} exc=~{2}", i, url.Raw(), Err_.Message_gplx(e));
|
||||
}
|
||||
}
|
||||
temp_files.Clear();
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_progress_interval_)) progress_interval = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_select_interval_)) select_interval = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_src_mgr)) return src_mgr;
|
||||
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_exec_fail_max_)) exec_fail_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 if (ctx.Match(k, Invk_page_id_bmk_)) page_id_bmk = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_lnki_id_bmk_)) lnki_id_bmk = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_delete_interval_)) delete_interval = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_app_restart_enabled_)) app_restart_enabled = m.ReadBool("v");
|
||||
else if (ctx.Match(k, Invk_db_restart_tries_max_)) db_reset_tries_max = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_trg_fsdb_mgr)) return trg_fsdb_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Cfg_fsdb_make = "bldr.fsdb_make", Cfg_page_id_bmk = "page_id_bmk", Cfg_lnki_id_bmk = "lnki_id_bmk";
|
||||
private static final String Invk_select_interval_ = "select_interval_", Invk_progress_interval_ = "progress_interval_", Invk_commit_interval_ = "commit_interval_"
|
||||
, Invk_page_id_bmk_ = "page_id_bmk_", Invk_lnki_id_bmk_ = "lnki_id_bmk_"
|
||||
, Invk_src_mgr = "src_mgr"
|
||||
, Invk_poll_mgr = "poll_mgr", Invk_reset_db_ = "reset_db_"
|
||||
, Invk_exec_count_max_ = "exec_count_max_", Invk_exec_fail_max_ = "exec_fail_max_", Invk_exit_now_ = "exit_now_", Invk_exit_after_commit_ = "exit_after_commit_"
|
||||
, Invk_delete_interval_ = "delete_interval_"
|
||||
, Invk_app_restart_enabled_ = "app_restart_enabled_"
|
||||
, Invk_db_restart_tries_max_ = "db_restart_tries_max_"
|
||||
, Invk_trg_fsdb_mgr = "trg_fsdb_mgr"
|
||||
;
|
||||
public static byte Status_null = 0, Status_pass = 1, Status_fail = 2;
|
||||
}
|
||||
class Xodb_tbl_oimg_xfer_itm extends Xof_fsdb_itm { public int Lnki_id() {return lnki_id;} private int lnki_id;
|
||||
public int Lnki_page_id() {return lnki_page_id;} private int lnki_page_id;
|
||||
public int Lnki_ext_id() {return lnki_ext_id;} private int lnki_ext_id;
|
||||
public static Xodb_tbl_oimg_xfer_itm new_rdr_(DataRdr rdr) {
|
||||
Xodb_tbl_oimg_xfer_itm rv = new Xodb_tbl_oimg_xfer_itm();
|
||||
rv.lnki_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_id);
|
||||
rv.lnki_page_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_page_id);
|
||||
rv.lnki_ext_id = rdr.ReadInt(Xob_xfer_regy_tbl.Fld_lnki_ext);
|
||||
rv.Orig_repo_ (rdr.ReadByte(Xob_xfer_regy_tbl.Fld_orig_repo));
|
||||
rv.File_is_orig_ (rdr.ReadByte(Xob_xfer_regy_tbl.Fld_file_is_orig) == Bool_.Y_byte);
|
||||
byte[] ttl = rdr.ReadBryByStr(Xob_xfer_regy_tbl.Fld_lnki_ttl);
|
||||
rv.Orig_ttl_(ttl);
|
||||
rv.Lnki_ttl_(ttl);
|
||||
rv.Orig_size_(rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_orig_h));
|
||||
rv.Html_size_(rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h)); // set html_size as file_size (may try to optimize later by removing similar thumbs (EX: 220,221 -> 220))
|
||||
rv.Lnki_size_(rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_w), rdr.ReadInt(Xob_xfer_regy_tbl.Fld_file_h)); // set lnki_size; Xof_bin_mgr uses lnki_size;
|
||||
rv.Lnki_page_ (Xof_doc_page.Db_load_int(rdr, Xob_xfer_regy_tbl.Fld_lnki_page));
|
||||
rv.Lnki_thumbtime_ (Xof_doc_thumb.Db_load_double(rdr, Xob_xfer_regy_tbl.Fld_lnki_time));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_regy_cmd.java
Normal file
32
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_regy_cmd.java
Normal 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.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_lnki_regy_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_lnki_regy_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.lnki_regy";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
Db_provider provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
Xob_lnki_regy_tbl.Create_table(provider);
|
||||
Xob_lnki_regy_tbl.Create_data(usr_dlg, provider, Xob_lnki_temp_wkr.Wiki_ns_for_file_is_case_match_all(wiki));
|
||||
}
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
}
|
||||
112
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_regy_tbl.java
Normal file
112
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_regy_tbl.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*;
|
||||
class Xob_lnki_regy_tbl {
|
||||
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_provider p, boolean wiki_ns_for_file_is_case_match_all) {
|
||||
p.Exec_sql(Sql_create_data);
|
||||
Sqlite_engine_.Idx_create(usr_dlg, p, "lnki_regy", Idx_ttl);
|
||||
if (wiki_ns_for_file_is_case_match_all)
|
||||
Sqlite_engine_.Idx_create(usr_dlg, p, "lnki_regy_commons", Idx_ttl_commons);
|
||||
}
|
||||
public static final String Tbl_name = "lnki_regy"
|
||||
, Fld_lnki_id = "lnki_id", Fld_lnki_page_id = "lnki_page_id"
|
||||
, Fld_lnki_ttl = "lnki_ttl", Fld_lnki_commons_ttl = "lnki_commons_ttl"
|
||||
, Fld_lnki_ext = "lnki_ext", Fld_lnki_type = "lnki_type", Fld_lnki_src_tid = "lnki_src_tid"
|
||||
, Fld_lnki_w = "lnki_w", Fld_lnki_h = "lnki_h", Fld_lnki_upright = "lnki_upright", Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page"
|
||||
, Fld_lnki_count = "lnki_count"
|
||||
;
|
||||
private static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS lnki_regy"
|
||||
, "( lnki_id integer NOT NULL PRIMARY KEY"
|
||||
, ", lnki_page_id integer NOT NULL"
|
||||
, ", lnki_ttl varchar(255) NOT NULL"
|
||||
, ", lnki_commons_ttl varchar(255) NULL"
|
||||
, ", lnki_commons_flag integer NULL"
|
||||
, ", lnki_ext integer NOT NULL"
|
||||
, ", lnki_type integer NOT NULL"
|
||||
, ", lnki_src_tid integer NOT NULL"
|
||||
, ", lnki_w integer NOT NULL"
|
||||
, ", lnki_h integer NOT NULL"
|
||||
, ", lnki_upright double NOT NULL"
|
||||
, ", lnki_time double NOT NULL"
|
||||
, ", lnki_page integer NOT NULL"
|
||||
, ", lnki_count integer NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
public static final String Sql_create_data = String_.Concat_lines_nl
|
||||
( "INSERT INTO lnki_regy (lnki_id, lnki_page_id, lnki_ttl, lnki_commons_ttl, lnki_ext, lnki_type, lnki_src_tid, lnki_w, lnki_h, lnki_upright, lnki_time, lnki_page, lnki_count)"
|
||||
, "SELECT Min(lnki_id)"
|
||||
, ", Min(lnki_page_id)"
|
||||
, ", lnki_ttl"
|
||||
, ", lnki_commons_ttl"
|
||||
, ", lnki_ext"
|
||||
, ", lnki_type"
|
||||
, ", lnki_src_tid"
|
||||
, ", lnki_w"
|
||||
, ", lnki_h"
|
||||
, ", lnki_upright"
|
||||
, ", lnki_time"
|
||||
, ", lnki_page"
|
||||
, ", Count(lnki_ttl)"
|
||||
, "FROM lnki_temp"
|
||||
, "GROUP BY"
|
||||
, " lnki_ttl"
|
||||
, ", lnki_commons_ttl"
|
||||
, ", lnki_ext"
|
||||
, ", lnki_type"
|
||||
, ", lnki_src_tid"
|
||||
, ", lnki_w"
|
||||
, ", lnki_h"
|
||||
, ", lnki_upright"
|
||||
, ", lnki_time"
|
||||
, ", lnki_page"
|
||||
, ";"
|
||||
)
|
||||
, Sql_cs_mark_changed = String_.Concat_lines_nl
|
||||
( "REPLACE INTO lnki_regy"
|
||||
, "SELECT l.lnki_id"
|
||||
, ", l.lnki_page_id"
|
||||
, ", l.lnki_ttl"
|
||||
, ", l.lnki_commons_ttl"
|
||||
, ", CASE WHEN o.lnki_ttl IS NULL THEN NULL ELSE 1 END"
|
||||
, ", l.lnki_ext"
|
||||
, ", l.lnki_type"
|
||||
, ", l.lnki_src_tid"
|
||||
, ", l.lnki_w"
|
||||
, ", l.lnki_h"
|
||||
, ", l.lnki_upright"
|
||||
, ", l.lnki_time"
|
||||
, ", l.lnki_page"
|
||||
, ", l.lnki_count"
|
||||
, "FROM lnki_regy l"
|
||||
, " LEFT JOIN orig_regy o ON o.lnki_ttl = l.lnki_commons_ttl AND o.orig_commons_flag = 2"
|
||||
, ";"
|
||||
)
|
||||
, Sql_cs_update_ttls = String_.Concat_lines_nl
|
||||
( "UPDATE lnki_regy"
|
||||
, "SET lnki_ttl = lnki_commons_ttl"
|
||||
, "WHERE lnki_commons_flag = 1"
|
||||
, ";"
|
||||
);
|
||||
private static final Db_idx_itm
|
||||
Idx_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS lnki_regy__ttl ON lnki_regy (lnki_ttl, lnki_ext, lnki_id, lnki_page_id);")
|
||||
, Idx_ttl_commons = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS lnki_regy__ttl ON lnki_regy (lnki_commons_ttl, lnki_ext, lnki_id, lnki_page_id);")
|
||||
;
|
||||
}
|
||||
21
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_src_tid.java
Normal file
21
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_src_tid.java
Normal 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.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xob_lnki_src_tid {
|
||||
public static final byte Tid_file = 0, Tid_media = 1, Tid_gallery = 2, Tid_imageMap = 3;
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_temp_tbl.java
Normal file
61
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_temp_tbl.java
Normal 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.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*;
|
||||
class Xob_lnki_temp_tbl {
|
||||
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create(p, Tbl_name, Tbl_sql);}
|
||||
public static Db_stmt Insert_stmt(Db_provider p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_lnki_page_id, Fld_lnki_ttl, Fld_lnki_commons_ttl, Fld_lnki_ext, Fld_lnki_type, Fld_lnki_src_tid, Fld_lnki_w, Fld_lnki_h, Fld_lnki_upright, Fld_lnki_time, Fld_lnki_page);}
|
||||
public static void Insert(Db_stmt stmt, int page_id, byte[] ttl, byte[] ttl_commons, byte ext_id, byte img_type, byte lnki_src_tid, int w, int h, double upright, double thumbtime, int page) {
|
||||
stmt.Clear()
|
||||
.Val_int_(page_id)
|
||||
.Val_str_by_bry_(ttl)
|
||||
.Val_str_by_bry_(ttl_commons)
|
||||
.Val_byte_(ext_id)
|
||||
.Val_byte_(img_type)
|
||||
.Val_int_(lnki_src_tid)
|
||||
.Val_int_(w)
|
||||
.Val_int_(h)
|
||||
.Val_double_(upright)
|
||||
.Val_double_(gplx.xowa.files.Xof_doc_thumb.Db_save_double(thumbtime))
|
||||
.Val_int_(page)
|
||||
.Exec_insert();
|
||||
}
|
||||
public static final String Tbl_name = "lnki_temp"
|
||||
, Fld_lnki_id = "lnki_id"
|
||||
, Fld_lnki_page_id = "lnki_page_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_commons_ttl = "lnki_commons_ttl"
|
||||
, Fld_lnki_ext = "lnki_ext", Fld_lnki_type = "lnki_type", Fld_lnki_src_tid = "lnki_src_tid"
|
||||
, Fld_lnki_w = "lnki_w", Fld_lnki_h = "lnki_h", Fld_lnki_upright = "lnki_upright"
|
||||
, Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page"
|
||||
;
|
||||
private static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS lnki_temp"
|
||||
, "( lnki_id integer NOT NULL PRIMARY KEY AUTOINCREMENT" // NOTE: insertion order index
|
||||
, ", lnki_page_id integer NOT NULL"
|
||||
, ", lnki_ttl varchar(255) NOT NULL"
|
||||
, ", lnki_commons_ttl varchar(255) NULL"
|
||||
, ", lnki_ext integer NOT NULL"
|
||||
, ", lnki_type integer NOT NULL"
|
||||
, ", lnki_src_tid integer NOT NULL"
|
||||
, ", lnki_w integer NOT NULL"
|
||||
, ", lnki_h integer NOT NULL"
|
||||
, ", lnki_upright double NOT NULL"
|
||||
, ", lnki_time double NOT NULL" // thumbtime is float; using double b/c upright does and would like to keep datatypes same; https://bugzilla.wikimedia.org/show_bug.cgi?id=39014
|
||||
, ", lnki_page integer NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
183
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_temp_wkr.java
Normal file
183
400_xowa/src/gplx/xowa/bldrs/files/Xob_lnki_temp_wkr.java
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.bldrs.oimgs.*; import gplx.fsdb.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.parsers.logs.*;
|
||||
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wdatas.*;
|
||||
public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xop_lnki_logger {
|
||||
private Db_provider provider; private Db_stmt stmt;
|
||||
private boolean wdata_enabled = true, xtn_ref_enabled = true, gen_html = false;
|
||||
private Xop_log_invoke_wkr invoke_wkr; private Xop_log_property_wkr property_wkr;
|
||||
private int[] ns_ids = Int_.Ary(Xow_ns_.Id_main);// , Xow_ns_.Id_category, Xow_ns_.Id_template
|
||||
private boolean wiki_ns_file_is_case_match_all = true; private Xow_wiki commons_wiki;
|
||||
public Xob_lnki_temp_wkr(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
@Override public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.lnki_temp";
|
||||
@Override public byte Init_redirect() {return Bool_.N_byte;} // lnki will never be found in a redirect
|
||||
@Override public int[] Init_ns_ary() {return ns_ids;}
|
||||
@Override protected void Init_reset(Db_provider p) {
|
||||
p.Exec_sql("DELETE FROM " + Xodb_xowa_cfg_tbl.Tbl_name);
|
||||
p.Exec_sql("DELETE FROM " + Xob_lnki_temp_tbl.Tbl_name);
|
||||
invoke_wkr.Init_reset();
|
||||
property_wkr.Init_reset();
|
||||
}
|
||||
@Override protected Db_provider Init_db_file() {
|
||||
ctx.Lnki().File_wkr_(this);
|
||||
Xodb_db_file db_file = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir());
|
||||
provider = db_file.Provider();
|
||||
Xob_lnki_temp_tbl.Create_table(provider);
|
||||
stmt = Xob_lnki_temp_tbl.Insert_stmt(provider);
|
||||
return provider;
|
||||
}
|
||||
@Override protected void Cmd_bgn_end() {
|
||||
wiki_ns_file_is_case_match_all = Wiki_ns_for_file_is_case_match_all(wiki); // NOTE: must call after wiki.init
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xog_page_mode.Tid_read).Ctgs_enabled_(false); // disable categories else progress messages written (also for PERF)
|
||||
commons_wiki = app.Wiki_mgr().Get_by_key_or_make(Xow_wiki_.Domain_commons_bry);
|
||||
Xop_log_mgr log_mgr = ctx.App().Log_mgr();
|
||||
log_mgr.Log_dir_(wiki.Fsys_mgr().Root_dir()); // put log in wiki dir, instead of user.temp
|
||||
invoke_wkr = this.Invoke_wkr(); // set member reference
|
||||
invoke_wkr = log_mgr.Make_wkr_invoke();
|
||||
property_wkr = this.Property_wkr(); // set member reference
|
||||
property_wkr = log_mgr.Make_wkr_property();
|
||||
wiki.App().Wiki_mgr().Wdata_mgr().Enabled_(wdata_enabled);
|
||||
if (!xtn_ref_enabled) gplx.xowa.xtns.refs.References_nde.Enabled = false;
|
||||
gplx.xowa.xtns.gallery.Gallery_xnde.Log_wkr = log_mgr.Make_wkr().Save_src_str_(Bool_.Y);
|
||||
gplx.xowa.xtns.imageMap.Xop_imageMap_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.Xop_xnde_wkr.Timeline_log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.xtns.scores.Score_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
gplx.xowa.xtns.hiero.Hiero_xnde.Log_wkr = log_mgr.Make_wkr();
|
||||
Xof_fsdb_mgr_sql trg_fsdb_mgr = new Xof_fsdb_mgr_sql(wiki);
|
||||
trg_fsdb_mgr.Init_by_wiki(wiki);
|
||||
Fsdb_mnt_mgr trg_mnt_mgr = trg_fsdb_mgr.Mnt_mgr();
|
||||
trg_mnt_mgr.Insert_to_mnt_(Fsdb_mnt_mgr.Mnt_idx_main);
|
||||
Fsdb_mnt_mgr.Patch(trg_mnt_mgr); // NOTE: see fsdb_make; DATE:2014-04-26
|
||||
provider.Txn_mgr().Txn_bgn_if_none();
|
||||
log_mgr.Txn_bgn();
|
||||
}
|
||||
@Override public void Exec_pg_itm_hook(Xow_ns ns, Xodb_page db_page, byte[] page_src) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns.Gen_ttl(db_page.Ttl_wo_ns()));
|
||||
// Io_mgr._.AppendFilStr("C:\\debug.txt", String_.new_utf8_(ttl.Full_txt()) + "\n");
|
||||
byte[] ttl_bry = ttl.Page_db();
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns.Id(), ttl_bry);
|
||||
if (page_tid != Xow_page_tid.Tid_wikitext) return; // ignore js, css, lua, json
|
||||
Xoa_page page = ctx.Cur_page();
|
||||
page.Clear();
|
||||
page.Ttl_(ttl).Revision_data().Id_(db_page.Id());
|
||||
page.Lnki_redlinks_mgr().Page_bgn();
|
||||
if (ns.Id_tmpl())
|
||||
parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src);
|
||||
else {
|
||||
parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), page_src);
|
||||
if (gen_html) {
|
||||
page.Root_(root);
|
||||
wiki.Html_mgr().Page_wtr_mgr().Gen(ctx.Cur_page(), gplx.xowa.gui.Xog_page_mode.Tid_read);
|
||||
}
|
||||
root.Clear();
|
||||
}
|
||||
}
|
||||
// private void Gen_html(Xop_root_tkn root, Xop_ctx ctx) {}
|
||||
@Override public void Exec_commit_hook() {
|
||||
provider.Txn_mgr().Txn_end_all_bgn_if_none(); // save lnki_temp
|
||||
}
|
||||
@Override public void Exec_end_hook() {
|
||||
wiki.App().Log_mgr().Txn_end();
|
||||
provider.Txn_mgr().Txn_end();
|
||||
}
|
||||
public void Wkr_exec(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, byte lnki_src_tid) {
|
||||
if (lnki.Ttl().ForceLiteralLink()) return; // ignore literal links which creat a link to file, but do not show the image; EX: [[:File:A.png|thumb|120px]] creates a link to File:A.png, regardless of other display-oriented args
|
||||
byte[] ttl = lnki.Ttl().Page_db();
|
||||
Xof_ext ext = Xof_ext_.new_by_ttl_(ttl);
|
||||
double lnki_thumbtime = lnki.Thumbtime();
|
||||
int lnki_page = lnki.Page();
|
||||
byte[] ttl_commons = X_to_commons(wiki_ns_file_is_case_match_all, commons_wiki, ttl);
|
||||
if ( Xof_doc_page.Null_n(lnki_page) // page set
|
||||
&& Xof_doc_thumb.Null_n(lnki_thumbtime)) // thumbtime set
|
||||
usr_dlg.Warn_many("", "", "page and thumbtime both set; this may be an issue with fsdb: page=~{0} ttl=~{1}", ctx.Cur_page().Ttl().Page_db_as_str(), String_.new_utf8_(ttl));
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_media)
|
||||
lnki_src_tid = Xob_lnki_src_tid.Tid_media;
|
||||
Xob_lnki_temp_tbl.Insert(stmt, ctx.Cur_page().Revision_data().Id(), ttl, ttl_commons, Byte_.int_(ext.Id()), lnki.Lnki_type(), lnki_src_tid, lnki.Lnki_w(), lnki.Lnki_h(), lnki.Upright(), lnki_thumbtime, lnki_page);
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_wdata_enabled_)) wdata_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_xtn_ref_enabled_)) xtn_ref_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_gen_html_)) gen_html = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_ns_ids_)) ns_ids = Int_.Ary_parse(m.ReadStr("v"), "|");
|
||||
else if (ctx.Match(k, Invk_ns_ids_by_aliases)) ns_ids = Xob_lnki_temp_wkr_.Ns_ids_by_aliases(wiki, m.ReadStrAry("v", "|"));
|
||||
else if (ctx.Match(k, Invk_property_wkr)) return this.Property_wkr();
|
||||
else if (ctx.Match(k, Invk_invoke_wkr)) return this.Invoke_wkr();
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_wdata_enabled_ = "wdata_enabled_", Invk_xtn_ref_enabled_ = "xtn_ref_enabled_"
|
||||
, Invk_ns_ids_ = "ns_ids_", Invk_ns_ids_by_aliases = "ns_ids_by_aliases"
|
||||
, Invk_invoke_wkr = "invoke_wkr", Invk_property_wkr = "property_wkr"
|
||||
, Invk_gen_html_ = "gen_html_"
|
||||
;
|
||||
private Xop_log_invoke_wkr Invoke_wkr() {
|
||||
if (invoke_wkr == null) invoke_wkr = ((Scrib_xtn_mgr)bldr.App().Xtn_mgr().Get_or_fail(Scrib_xtn_mgr.XTN_KEY)).Invoke_wkr_or_new();
|
||||
return invoke_wkr;
|
||||
}
|
||||
private Xop_log_property_wkr Property_wkr() {
|
||||
if (property_wkr == null) property_wkr = bldr.App().Wiki_mgr().Wdata_mgr().Property_wkr_or_new();
|
||||
return property_wkr;
|
||||
}
|
||||
public static byte[] X_to_commons(boolean wiki_ns_file_is_case_match_all, Xow_wiki commons_wiki, byte[] ttl_bry) {
|
||||
if (!wiki_ns_file_is_case_match_all) return null; // return "" if wiki matches common
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(commons_wiki, Xow_ns_.Id_file, ttl_bry);
|
||||
byte[] rv = ttl.Page_db();
|
||||
return Bry_.Eq(rv, ttl_bry) ? null : rv;
|
||||
}
|
||||
public static boolean Wiki_ns_for_file_is_case_match_all(Xow_wiki wiki) {
|
||||
return wiki.Ns_mgr().Ns_file().Case_match() == Xow_ns_case_.Id_all;
|
||||
}
|
||||
}
|
||||
class Xob_lnki_temp_wkr_ {
|
||||
public static int[] Ns_ids_by_aliases(Xow_wiki wiki, String[] aliases) {
|
||||
int[] rv = Xob_lnki_temp_wkr_.Ids_by_aliases(wiki.Ns_mgr(), aliases);
|
||||
int aliases_len = aliases.length;
|
||||
int ids_len = rv.length;
|
||||
for (int i = 0; i < aliases_len; i++) {
|
||||
String alias = aliases[i];
|
||||
int id = i < ids_len ? rv[i] : -1;
|
||||
wiki.App().Usr_dlg().Note_many("", "", "ns: ~{0} <- ~{1}", Int_.XtoStr_fmt(id, "0000"), alias);
|
||||
}
|
||||
if (aliases_len != ids_len) throw Err_.new_fmt_("mismatch in aliases and ids: {0} vs {1}", aliases_len, ids_len);
|
||||
return rv;
|
||||
}
|
||||
private static int[] Ids_by_aliases(Xow_ns_mgr ns_mgr, String[] aliases) {
|
||||
ListAdp list = ListAdp_.new_();
|
||||
int len = aliases.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String alias = aliases[i];
|
||||
if (String_.Eq(alias, Xow_ns_.Key_main))
|
||||
list.Add(ns_mgr.Ns_main());
|
||||
else {
|
||||
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_utf8_(alias));
|
||||
if (ns != null)
|
||||
list.Add(ns);
|
||||
}
|
||||
}
|
||||
len = list.Count();
|
||||
int[] rv = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = ((Xow_ns)list.FetchAt(i)).Id();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_lnki_temp_wkr_tst {
|
||||
private Xob_lnki_temp_wkr_fxt fxt = new Xob_lnki_temp_wkr_fxt();
|
||||
@Test public void X_to_commons() {
|
||||
fxt.Init_X_to_commons(true);
|
||||
fxt.Test_X_to_commons("a", "A");
|
||||
fxt.Test_X_to_commons("A", null);
|
||||
|
||||
fxt.Init_X_to_commons(false);
|
||||
fxt.Test_X_to_commons("a", null);
|
||||
fxt.Test_X_to_commons("A", null);
|
||||
}
|
||||
}
|
||||
class Xob_lnki_temp_wkr_fxt {
|
||||
private boolean wiki_ns_file_is_case_match_all;
|
||||
private Xow_wiki commons_wiki;
|
||||
public Xob_lnki_temp_wkr_fxt Init_X_to_commons(boolean wiki_ns_file_is_case_match_all) {
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
this.wiki_ns_file_is_case_match_all = wiki_ns_file_is_case_match_all;
|
||||
this.commons_wiki = Xoa_app_fxt.wiki_tst_(app); // commons_wiki will default to Xow_ns.Id_file of case_match_1st
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Test_X_to_commons(String ttl, String expd) {
|
||||
Tfds.Eq(expd, String_.new_utf8_(Xob_lnki_temp_wkr.X_to_commons(wiki_ns_file_is_case_match_all, commons_wiki, Bry_.new_utf8_(ttl))));
|
||||
}
|
||||
}
|
||||
68
400_xowa/src/gplx/xowa/bldrs/files/Xob_orig_qry_cmd.java
Normal file
68
400_xowa/src/gplx/xowa/bldrs/files/Xob_orig_qry_cmd.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.qrys.*;
|
||||
import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_orig_qry_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_orig_qry_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "oimg.orig_qry";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
// Xof_qry_mgr qry_mgr = new Xof_qry_mgr();
|
||||
Db_provider provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
Xob_bmk_mgr bmk = new Xob_bmk_mgr();
|
||||
bmk.Init(provider, this.Cmd_key(), true, false, true);
|
||||
bmk.Load();
|
||||
Xof_fsdb_itm itm = new Xof_fsdb_itm();
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
try {
|
||||
// rdr = Select(provider, bmk.Repo_prv(), bmk.Ttl_prv());
|
||||
while (rdr.MoveNextPeer()) {
|
||||
Load_itm(itm, rdr);
|
||||
// QueryItm
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
}
|
||||
/*
|
||||
DataRdr rdr = Get(repo_prv, ttl_prv);
|
||||
while (rdr.MoveNextPeer()) {
|
||||
Itm itm = Itm.load_(rdr);
|
||||
qry.Call(itm);
|
||||
}
|
||||
*/
|
||||
}
|
||||
private void Load_itm(Xof_fsdb_itm itm, DataRdr rdr) {
|
||||
itm.Lnki_ttl_(null);
|
||||
}
|
||||
public DataRdr Select(Db_provider p, byte prv_repo_id, byte[] prv_ttl) {
|
||||
String sql = String_.Concat_lines_nl_skip_last
|
||||
( "SELECT lnki_ttl"
|
||||
, "FROM orig_regy"
|
||||
, "WHERE lnki_repo >= '" + Byte_.XtoStr(prv_repo_id) + "'"
|
||||
, "AND lnki_ttl > '" + prv_ttl + "'"
|
||||
, "AND oimg_orig_page_id = -1;"
|
||||
);
|
||||
Db_qry select_qry = Db_qry_sql.rdr_(sql);
|
||||
return p.Exec_qry_as_rdr(select_qry);
|
||||
}
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
}
|
||||
46
400_xowa/src/gplx/xowa/bldrs/files/Xob_orig_regy_cmd.java
Normal file
46
400_xowa/src/gplx/xowa/bldrs/files/Xob_orig_regy_cmd.java
Normal 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.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_orig_regy_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private boolean repo_0_is_remote = false;
|
||||
public Xob_orig_regy_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.orig_regy";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
Db_provider provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
Xob_orig_regy_tbl.Create_table(provider);
|
||||
Xow_wiki commons_wiki = bldr.App().Wiki_mgr().Get_by_key_or_make(Xow_wiki_.Domain_commons_bry).Init_assert();
|
||||
Xow_wiki repo_0 = wiki, repo_1 = commons_wiki;
|
||||
if (repo_0_is_remote) {
|
||||
repo_0 = commons_wiki;
|
||||
repo_1 = wiki;
|
||||
}
|
||||
repo_0.Init_assert(); repo_1.Init_assert();
|
||||
Xodb_db_file file_registry_db = Xodb_db_file.init__page_regy(commons_wiki.Fsys_mgr().Root_dir());
|
||||
Xob_orig_regy_tbl.Create_data(bldr.Usr_dlg(), provider, file_registry_db, repo_0_is_remote, repo_0, repo_1, Xob_lnki_temp_wkr.Wiki_ns_for_file_is_case_match_all(wiki));
|
||||
}
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_repo_0_is_remote_)) repo_0_is_remote = m.ReadYn("v");
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
return this;
|
||||
} private static final String Invk_repo_0_is_remote_ = "repo_0_is_remote_";
|
||||
}
|
||||
204
400_xowa/src/gplx/xowa/bldrs/files/Xob_orig_regy_tbl.java
Normal file
204
400_xowa/src/gplx/xowa/bldrs/files/Xob_orig_regy_tbl.java
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
class Xob_orig_regy_tbl {
|
||||
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_provider p, Xodb_db_file file_registry_db, boolean repo_0_is_remote, Xow_wiki repo_0_wiki, Xow_wiki repo_1_wiki, boolean wiki_ns_for_file_is_case_match_all) {
|
||||
usr_dlg.Prog_many("", "", "inserting lnki_regy");
|
||||
p.Exec_sql(Sql_create_data);
|
||||
Sqlite_engine_.Idx_create(usr_dlg, p, "orig_regy", Idx_ttl);
|
||||
Sqlite_engine_.Db_attach(p, "page_db", file_registry_db.Url().Raw());
|
||||
Io_url repo_0_dir = repo_0_wiki.Fsys_mgr().Root_dir(), repo_1_dir = repo_1_wiki.Fsys_mgr().Root_dir();
|
||||
byte repo_0_tid = Xof_repo_itm.Repo_local, repo_1_tid = Xof_repo_itm.Repo_remote;
|
||||
boolean local_is_remote = Bry_.Eq(repo_0_wiki.Domain_bry(), repo_1_wiki.Domain_bry());
|
||||
if ( repo_0_is_remote // .gfs manually marked specifes repo_0 as remote
|
||||
|| ( Bry_.Eq(repo_0_wiki.Domain_bry(), Xow_wiki_.Domain_commons_bry) // repo_0 = commons; force repo_0 to be remote; else all orig_repo will be 1; DATE:2014-02-01
|
||||
&& local_is_remote // repo_0 = repo_1
|
||||
)
|
||||
) {
|
||||
repo_0_tid = Xof_repo_itm.Repo_remote;
|
||||
repo_1_tid = Xof_repo_itm.Repo_local;
|
||||
}
|
||||
Create_data_for_repo(usr_dlg, p, Byte_.int_(repo_0_tid), repo_0_dir.GenSubFil(Xodb_db_file.Name__wiki_image));
|
||||
if (!local_is_remote) { // only run for repo_1 if local != remote; only affects commons
|
||||
Create_data_for_repo(usr_dlg, p, Byte_.int_(repo_1_tid), repo_1_dir.GenSubFil(Xodb_db_file.Name__wiki_image));
|
||||
if (wiki_ns_for_file_is_case_match_all) {
|
||||
Io_url repo_remote_dir = repo_0_is_remote ? repo_0_dir : repo_1_dir;
|
||||
Create_data_for_cs(usr_dlg, p, repo_remote_dir);
|
||||
}
|
||||
}
|
||||
Sqlite_engine_.Db_detach(p, "page_db");
|
||||
Sqlite_engine_.Idx_create(usr_dlg, p, "orig_regy", Idx_xfer_temp);
|
||||
}
|
||||
private static void Create_data_for_repo(Gfo_usr_dlg usr_dlg, Db_provider cur, byte wiki_tid, Io_url join) {
|
||||
usr_dlg.Note_many("", "", "inserting page: ~{0}", join.NameOnly());
|
||||
Sqlite_engine_.Db_attach(cur, "image_db", join.Raw());
|
||||
cur.Exec_sql(String_.Format(Sql_update_repo_page, wiki_tid));
|
||||
cur.Exec_sql(String_.Format(Sql_update_repo_redirect, wiki_tid));
|
||||
Sqlite_engine_.Db_detach(cur, "image_db");
|
||||
}
|
||||
private static void Create_data_for_cs(Gfo_usr_dlg usr_dlg, Db_provider p, Io_url repo_remote_dir) {
|
||||
p.Exec_sql(Xob_orig_regy_tbl.Sql_cs_mark_dupes); // orig_regy: find dupes; see note in SQL
|
||||
p.Exec_sql(Xob_orig_regy_tbl.Sql_cs_update_ttls); // orig_regy: update lnki_ttl with lnki_commons_ttl
|
||||
Create_data_for_repo(usr_dlg, p, Xof_repo_itm.Repo_remote, repo_remote_dir.GenSubFil(Xodb_db_file.Name__wiki_image));
|
||||
p.Exec_sql(Xob_lnki_regy_tbl.Sql_cs_mark_changed); // lnki_regy: update lnki_ttl with lnki_commons_ttl
|
||||
p.Exec_sql(Xob_lnki_regy_tbl.Sql_cs_update_ttls); // lnki_regy: update lnki_ttl with lnki_commons_ttl
|
||||
}
|
||||
public static final String Tbl_name = "orig_regy"
|
||||
, Fld_lnki_id = "lnki_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_ext = "lnki_ext", Fld_lnki_count = "lnki_count"
|
||||
, Fld_orig_repo = "orig_repo", Fld_orig_page_id = "orig_page_id"
|
||||
, Fld_orig_redirect_id = "orig_redirect_id", Fld_orig_redirect_ttl = "orig_redirect_ttl", Fld_orig_file_id = "orig_file_id", Fld_orig_file_ttl = "orig_file_ttl"
|
||||
, Fld_orig_size = "orig_size", Fld_orig_w = "orig_w", Fld_orig_h = "orig_h", Fld_orig_bits = "orig_bits"
|
||||
, Fld_orig_media_type = "orig_media_type", Fld_orig_minor_mime = "orig_minor_mime", Fld_orig_file_ext = "orig_file_ext";
|
||||
private static final Db_idx_itm
|
||||
Idx_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS orig_regy__ttl ON orig_regy (lnki_ttl);")
|
||||
, Idx_xfer_temp = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS orig_regy__xfer_temp ON orig_regy (lnki_ttl, orig_file_ttl);")
|
||||
;
|
||||
private static final String
|
||||
Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS orig_regy"
|
||||
, "( lnki_id integer NOT NULL PRIMARY KEY" // NOTE: must be PRIMARY KEY, else later REPLACE INTO will create dupe rows
|
||||
, ", lnki_ttl varchar(256) NOT NULL"
|
||||
, ", lnki_commons_ttl varchar(256) NULL"
|
||||
, ", orig_commons_flag integer NULL"
|
||||
, ", lnki_ext integer NOT NULL"
|
||||
, ", lnki_count integer NOT NULL"
|
||||
, ", orig_repo integer NULL"
|
||||
, ", orig_page_id integer NULL"
|
||||
, ", orig_redirect_id integer NULL"
|
||||
, ", orig_redirect_ttl varchar(256) NULL"
|
||||
, ", orig_file_id integer NULL"
|
||||
, ", orig_file_ttl varchar(256) NULL"
|
||||
, ", orig_file_ext integer NULL"
|
||||
, ", orig_size integer NULL"
|
||||
, ", orig_w integer NULL"
|
||||
, ", orig_h integer NULL"
|
||||
, ", orig_bits smallint NULL"
|
||||
, ", orig_media_type varchar(64) NULL"
|
||||
, ", orig_minor_mime varchar(32) NULL"
|
||||
, ");"
|
||||
)
|
||||
, Sql_create_data = String_.Concat_lines_nl
|
||||
( "INSERT INTO orig_regy (lnki_id, lnki_ttl, lnki_commons_ttl, orig_commons_flag, lnki_ext, lnki_count)"
|
||||
, "SELECT Min(lnki_id)"
|
||||
, ", lnki_ttl"
|
||||
, ", lnki_commons_ttl"
|
||||
, ", NULL"
|
||||
, ", lnki_ext"
|
||||
, ", Sum(lnki_count)"
|
||||
, "FROM lnki_regy"
|
||||
, "GROUP BY lnki_ttl"
|
||||
, ", lnki_ext"
|
||||
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
|
||||
, ";"
|
||||
)
|
||||
, Sql_update_repo_page = String_.Concat_lines_nl
|
||||
( "REPLACE INTO orig_regy"
|
||||
, "SELECT o.lnki_id"
|
||||
, ", o.lnki_ttl"
|
||||
, ", o.lnki_commons_ttl"
|
||||
, ", o.orig_commons_flag"
|
||||
, ", o.lnki_ext"
|
||||
, ", o.lnki_count"
|
||||
, ", {0}"
|
||||
, ", m.src_id"
|
||||
, ", NULL"
|
||||
, ", NULL"
|
||||
, ", m.src_id"
|
||||
, ", m.src_ttl"
|
||||
, ", i.img_ext_id"
|
||||
, ", i.img_size"
|
||||
, ", i.img_width"
|
||||
, ", i.img_height"
|
||||
, ", i.img_bits"
|
||||
, ", i.img_media_type"
|
||||
, ", i.img_minor_mime"
|
||||
, "FROM orig_regy o"
|
||||
, " JOIN image_db.image i ON o.lnki_ttl = i.img_name"
|
||||
, " JOIN page_db.page_regy m ON m.repo_id = {0} AND m.itm_tid = 0 AND o.lnki_ttl = m.src_ttl"
|
||||
, "WHERE o.orig_file_ttl IS NULL"
|
||||
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
|
||||
, ";"
|
||||
)
|
||||
, Sql_update_repo_redirect = String_.Concat_lines_nl
|
||||
( "REPLACE INTO orig_regy"
|
||||
, "SELECT o.lnki_id"
|
||||
, ", o.lnki_ttl"
|
||||
, ", o.lnki_commons_ttl"
|
||||
, ", o.orig_commons_flag"
|
||||
, ", o.lnki_ext"
|
||||
, ", o.lnki_count"
|
||||
, ", {0}"
|
||||
, ", m.src_id"
|
||||
, ", m.trg_id"
|
||||
, ", m.trg_ttl"
|
||||
, ", m.trg_id"
|
||||
, ", m.trg_ttl"
|
||||
, ", i.img_ext_id"
|
||||
, ", i.img_size"
|
||||
, ", i.img_width"
|
||||
, ", i.img_height"
|
||||
, ", i.img_bits"
|
||||
, ", i.img_media_type"
|
||||
, ", i.img_minor_mime"
|
||||
, "FROM orig_regy o"
|
||||
, " JOIN page_db.page_regy m ON m.repo_id = {0} AND m.itm_tid = 1 AND o.lnki_ttl = m.src_ttl"
|
||||
, " JOIN image_db.image i ON m.trg_ttl = i.img_name"
|
||||
, "WHERE o.orig_file_ttl IS NULL"
|
||||
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
|
||||
, ";"
|
||||
)
|
||||
, Sql_cs_mark_dupes = String_.Concat_lines_nl
|
||||
( "REPLACE INTO orig_regy"
|
||||
, "SELECT o.lnki_id"
|
||||
, ", o.lnki_ttl"
|
||||
, ", o.lnki_commons_ttl"
|
||||
, ", 1"
|
||||
, ", o.lnki_ext"
|
||||
, ", o.lnki_count"
|
||||
, ", o.orig_repo"
|
||||
, ", o.orig_page_id"
|
||||
, ", o.orig_redirect_id"
|
||||
, ", o.orig_redirect_ttl"
|
||||
, ", o.orig_file_id"
|
||||
, ", o.orig_file_ttl"
|
||||
, ", o.orig_file_ext"
|
||||
, ", o.orig_size"
|
||||
, ", o.orig_w"
|
||||
, ", o.orig_h"
|
||||
, ", o.orig_bits"
|
||||
, ", o.orig_media_type"
|
||||
, ", o.orig_minor_mime"
|
||||
, "FROM orig_regy o"
|
||||
, " JOIN orig_regy o2 ON o.lnki_commons_ttl = o2.lnki_ttl" // EX: 2 rows in table (1) A.jpg; and (2) "a.jpg,A.jpg"; do not insert row (2) b/c row (1) exists;
|
||||
, "WHERE o.orig_file_ttl IS NULL"
|
||||
, "ORDER BY 1" // must order by lnki_id since it is PRIMARY KEY, else sqlite will spend hours shuffling rows in table
|
||||
, ";"
|
||||
)
|
||||
, Sql_cs_update_ttls = String_.Concat_lines_nl
|
||||
( "UPDATE orig_regy"
|
||||
, "SET lnki_ttl = lnki_commons_ttl"
|
||||
, ", orig_commons_flag = 2"
|
||||
, "WHERE orig_file_ttl IS NULL" // orig not found
|
||||
, "AND lnki_commons_ttl IS NOT NULL" // orig commons ttl exists
|
||||
, "AND orig_commons_flag IS NULL" // orig is not dupe
|
||||
, ";"
|
||||
)
|
||||
;
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/bldrs/files/Xob_page_regy_cmd.java
Normal file
50
400_xowa/src/gplx/xowa/bldrs/files/Xob_page_regy_cmd.java
Normal 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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_page_regy_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_page_regy_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
private boolean build_commons = false;
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.page_regy";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
Xow_wiki commons_wiki = bldr.App().Wiki_mgr().Get_by_key_or_make(Xow_wiki_.Domain_commons_bry).Init_assert();
|
||||
Db_provider page_regy_provider = Xodb_db_file.init__page_regy(commons_wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
commons_wiki.Init_assert();
|
||||
if (build_commons) {
|
||||
Xob_page_regy_tbl.Reset_table(page_regy_provider);
|
||||
Xob_page_regy_tbl.Create_data(bldr.Usr_dlg(), page_regy_provider, Xof_repo_itm.Repo_remote, commons_wiki);
|
||||
Sqlite_engine_.Idx_create(usr_dlg, page_regy_provider, "repo_page", Xob_page_regy_tbl.Idx_main);
|
||||
}
|
||||
else {
|
||||
if (!Bry_.Eq(commons_wiki.Domain_bry(), wiki.Domain_bry())) { // skip local wiki if cur wiki is commons
|
||||
wiki.Init_assert();
|
||||
Xob_page_regy_tbl.Delete_local(page_regy_provider);
|
||||
Xob_page_regy_tbl.Create_data(bldr.Usr_dlg(), page_regy_provider, Xof_repo_itm.Repo_local, wiki);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_build_commons_)) build_commons = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_build_commons_ = "build_commons_";
|
||||
}
|
||||
84
400_xowa/src/gplx/xowa/bldrs/files/Xob_page_regy_tbl.java
Normal file
84
400_xowa/src/gplx/xowa/bldrs/files/Xob_page_regy_tbl.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
class Xob_page_regy_tbl {
|
||||
public static void Reset_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_provider p, byte repo_tid, Xow_wiki wiki) {
|
||||
Create_data__insert_page(usr_dlg, p, repo_tid, wiki.Db_mgr_as_sql().Fsys_mgr().Get_url(Xodb_file.Tid_core));
|
||||
Create_data__insert_redirect(usr_dlg, p, repo_tid, wiki.Fsys_mgr().Root_dir().GenSubFil(Xodb_db_file.Name__wiki_redirect));
|
||||
}
|
||||
public static void Delete_local(Db_provider p) {
|
||||
p.Exec_sql("DELETE FROM page_regy WHERE repo_id = " + Xof_repo_itm.Repo_local);
|
||||
}
|
||||
private static void Create_data__insert_page(Gfo_usr_dlg usr_dlg, Db_provider cur, byte repo_tid, Io_url join) {
|
||||
usr_dlg.Note_many("", "", "inserting page: ~{0}", join.NameOnly());
|
||||
Sqlite_engine_.Db_attach(cur, "page_db", join.Raw());
|
||||
cur.Exec_sql(String_.Format(Sql_create_page, repo_tid));
|
||||
Sqlite_engine_.Db_detach(cur, "page_db");
|
||||
}
|
||||
private static void Create_data__insert_redirect(Gfo_usr_dlg usr_dlg, Db_provider cur, byte repo_tid, Io_url join) {
|
||||
usr_dlg.Note_many("", "", "inserting redirect: ~{0}", join.OwnerDir().NameOnly());
|
||||
Sqlite_engine_.Db_attach(cur, "redirect_db", join.Raw());
|
||||
cur.Exec_sql(String_.Format(Sql_create_redirect, repo_tid));
|
||||
Sqlite_engine_.Db_detach(cur, "redirect_db");
|
||||
}
|
||||
public static final String Tbl_name = "page_regy"
|
||||
, Fld_uid = "uid", Fld_repo_id = "repo_id", Fld_itm_tid = "itm_tid"
|
||||
, Fld_src_id = "src_id", Fld_src_ttl = "src_ttl"
|
||||
, Fld_trg_id = "trg_id", Fld_trg_ttl = "trg_ttl"
|
||||
;
|
||||
public static final Db_idx_itm
|
||||
Idx_main = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS page_regy__main ON page_regy (repo_id, itm_tid, src_ttl, src_id, trg_id, trg_ttl);")
|
||||
;
|
||||
private static final String
|
||||
Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS page_regy"
|
||||
, "( uid integer NOT NULL PRIMARY KEY AUTOINCREMENT" // NOTE: must be PRIMARY KEY, else later REPLACE INTO will create dupe rows
|
||||
, ", repo_id integer NOT NULL"
|
||||
, ", itm_tid tinyint NOT NULL"
|
||||
, ", src_id integer NOT NULL"
|
||||
, ", src_ttl varchar(255) NOT NULL"
|
||||
, ", trg_id integer NOT NULL"
|
||||
, ", trg_ttl varchar(255) NOT NULL"
|
||||
, ");"
|
||||
)
|
||||
, Sql_create_page = String_.Concat_lines_nl
|
||||
( "INSERT INTO page_regy (repo_id, itm_tid, src_id, src_ttl, trg_id, trg_ttl)"
|
||||
, "SELECT {0}"
|
||||
, ", 0" // 0=page
|
||||
, ", p.page_id"
|
||||
, ", p.page_title"
|
||||
, ", -1"
|
||||
, ", ''"
|
||||
, "FROM page_db.page p"
|
||||
, ";"
|
||||
)
|
||||
, Sql_create_redirect = String_.Concat_lines_nl
|
||||
( "INSERT INTO page_regy (repo_id, itm_tid, src_id, src_ttl, trg_id, trg_ttl)"
|
||||
, "SELECT {0}"
|
||||
, ", 1" // 1=redirect
|
||||
, ", r.src_id"
|
||||
, ", r.src_ttl"
|
||||
, ", r.trg_id"
|
||||
, ", r.trg_ttl"
|
||||
, "FROM redirect_db.redirect r"
|
||||
, ";"
|
||||
)
|
||||
;
|
||||
}
|
||||
41
400_xowa/src/gplx/xowa/bldrs/files/Xob_unzip_wkr.java
Normal file
41
400_xowa/src/gplx/xowa/bldrs/files/Xob_unzip_wkr.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xob_unzip_wkr {
|
||||
private ProcessAdp decompress_bz2, decompress_zip, decompress_gz, process;
|
||||
public int Process_exit_code() {return process.Exit_code();}
|
||||
public byte Process_run_mode() {return process_run_mode;} public Xob_unzip_wkr Process_run_mode_(byte v) {process_run_mode = v; return this;} private byte process_run_mode = ProcessAdp.Run_mode_async;
|
||||
public Xob_unzip_wkr Init(Xoa_app app) {return Init(app.Fsys_mgr().App_mgr().App_decompress_bz2(), app.Fsys_mgr().App_mgr().App_decompress_zip(), app.Fsys_mgr().App_mgr().App_decompress_gz());}
|
||||
public Xob_unzip_wkr Init(ProcessAdp decompress_bz2, ProcessAdp decompress_zip, ProcessAdp decompress_gz) {
|
||||
this.decompress_bz2 = decompress_bz2;
|
||||
this.decompress_zip = decompress_zip;
|
||||
this.decompress_gz = decompress_gz;
|
||||
return this;
|
||||
}
|
||||
public void Decompress(Io_url src, Io_url trg) {
|
||||
String src_ext = src.Ext();
|
||||
if (String_.Eq(src_ext, gplx.ios.Io_stream_.Ext_bz2)) process = decompress_bz2;
|
||||
else if (String_.Eq(src_ext, gplx.ios.Io_stream_.Ext_zip)) process = decompress_zip;
|
||||
else if (String_.Eq(src_ext, gplx.ios.Io_stream_.Ext_gz)) process = decompress_gz;
|
||||
else throw Err_.unhandled(src_ext);
|
||||
Io_url trg_owner_dir = trg.OwnerDir();
|
||||
Io_mgr._.CreateDirIfAbsent(trg_owner_dir);
|
||||
process.Run_mode_(process_run_mode);
|
||||
process.Run(src, trg, trg_owner_dir.Xto_api());
|
||||
}
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_regy_cmd.java
Normal file
35
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_regy_cmd.java
Normal 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.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_xfer_regy_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_xfer_regy_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.xfer_regy";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_run() {
|
||||
Db_provider provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
Xob_xfer_regy_tbl.Create_table(provider);
|
||||
Xob_xfer_regy_tbl.Create_data(usr_dlg, provider);
|
||||
Xob_xfer_regy_tbl.Create_index(usr_dlg, provider);
|
||||
Xob_xfer_regy_log_tbl.Create_table(provider);
|
||||
provider.Txn_mgr().Txn_end_all();
|
||||
}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
}
|
||||
156
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_regy_tbl.java
Normal file
156
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_regy_tbl.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_xfer_regy_tbl {
|
||||
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_provider p) {
|
||||
p.Exec_sql(Sql_create_data_orig);
|
||||
p.Exec_sql(Sql_create_data_thumb);
|
||||
}
|
||||
public static void Create_index(Gfo_usr_dlg usr_dlg, Db_provider p) {Sqlite_engine_.Idx_create(usr_dlg, p, Xodb_db_file.Name__file_make, Idx_lnki_page_id, Idx_lnki_ttl);}
|
||||
public static DataRdr Select(Db_provider p, byte repo_id, byte[] ttl, int limit) {
|
||||
Db_qry qry = Db_qry_.select_().Cols_all_()
|
||||
.From_(Tbl_name)
|
||||
.Where_(gplx.criterias.Criteria_.And_many(Db_crt_.mte_(Fld_orig_repo, repo_id), Db_crt_.mt_(Fld_lnki_ttl, String_.new_utf8_(ttl)), Db_crt_.eq_(Fld_xfer_status, 0)))
|
||||
.OrderBy_many_(Fld_xfer_status, Fld_orig_repo, Fld_lnki_ttl, Fld_file_w)
|
||||
.Limit_(limit)
|
||||
;
|
||||
return p.Exec_qry_as_rdr(qry);
|
||||
}
|
||||
public static Db_stmt Select_by_page_id_stmt(Db_provider p) {return p.Prepare(Db_qry_sql.rdr_(Sql_select));}
|
||||
public static DataRdr Select_by_page_id(Db_stmt stmt, int page_id, int limit) {return stmt.Val_int_(page_id).Val_int_(limit).Exec_select();}
|
||||
private static final String
|
||||
Sql_select = String_.Concat_lines_nl
|
||||
( "SELECT *"
|
||||
, "FROM xfer_regy"
|
||||
, "WHERE xfer_status = 0"
|
||||
, "AND lnki_page_id >= ?"
|
||||
, "ORDER BY lnki_page_id, lnki_id"
|
||||
, "LIMIT ?"
|
||||
)
|
||||
, Sql_select_total_pending = String_.Concat_lines_nl
|
||||
( "SELECT Count(*) AS CountAll"
|
||||
, "FROM xfer_regy"
|
||||
, "WHERE xfer_status = 0"
|
||||
)
|
||||
;
|
||||
public static DataRdr Select_by_lnki_page_id(Db_provider p, int lnki_page_id, int select_interval) {
|
||||
Db_qry qry = Db_qry_.select_().Cols_all_()
|
||||
.From_(Tbl_name)
|
||||
.Where_(gplx.criterias.Criteria_.And_many(Db_crt_.eq_(Fld_xfer_status, 0), Db_crt_.mte_(Fld_lnki_page_id, lnki_page_id)))
|
||||
.OrderBy_many_(Fld_lnki_page_id, Fld_lnki_id)
|
||||
.Limit_(select_interval)
|
||||
;
|
||||
return p.Exec_qry_as_rdr(qry);
|
||||
}
|
||||
public static int Select_total_pending(Db_provider p) {
|
||||
DataRdr rdr = p.Exec_sql_as_rdr(Sql_select_total_pending);
|
||||
int rv = 0;
|
||||
if (rdr.MoveNextPeer())
|
||||
rv = rdr.ReadInt("CountAll");
|
||||
rdr.Rls();
|
||||
return rv;
|
||||
}
|
||||
public static final String Tbl_name = "xfer_regy"
|
||||
, Fld_lnki_id = "lnki_id", Fld_lnki_page_id = "lnki_page_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_ext = "lnki_ext"
|
||||
, Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page", Fld_lnki_count = "lnki_count"
|
||||
, Fld_orig_repo = "orig_repo", Fld_orig_page_id = "orig_page_id", Fld_orig_redirect_src = "orig_redirect_src", Fld_orig_media_type = "orig_media_type"
|
||||
, Fld_orig_w = "orig_w", Fld_orig_h = "orig_h"
|
||||
, Fld_file_w = "file_w", Fld_file_h = "file_h", Fld_file_is_orig = "file_is_orig"
|
||||
, Fld_xfer_status = "xfer_status"
|
||||
;
|
||||
private static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS xfer_regy"
|
||||
, "( lnki_id integer NOT NULL PRIMARY KEY"
|
||||
, ", lnki_page_id integer NOT NULL"
|
||||
, ", lnki_ttl varchar(255) NOT NULL"
|
||||
, ", lnki_ext integer NOT NULL"
|
||||
, ", lnki_time double NOT NULL"
|
||||
, ", lnki_page integer NOT NULL"
|
||||
, ", lnki_count integer NOT NULL"
|
||||
, ", orig_repo tinyint NOT NULL"
|
||||
, ", orig_page_id integer NOT NULL"
|
||||
, ", orig_redirect_src varchar(255) NOT NULL"
|
||||
, ", orig_media_type varchar(64) NOT NULL"
|
||||
, ", orig_w integer NOT NULL"
|
||||
, ", orig_h integer NOT NULL"
|
||||
, ", file_is_orig byte NOT NULL"
|
||||
, ", file_w integer NOT NULL"
|
||||
, ", file_h integer NOT NULL"
|
||||
, ", xfer_status integer NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
private static final String Sql_create_data_orig = String_.Concat_lines_nl
|
||||
( "INSERT INTO xfer_regy "
|
||||
, "( lnki_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
|
||||
, ", xfer_status"
|
||||
, ")"
|
||||
, "SELECT "
|
||||
, " Min(lnki_id), Min(lnki_page_id), Min(orig_page_id), orig_repo, lnki_ttl, Max(orig_redirect_src), lnki_ext, orig_media_type" // NOTE: Max(orig_redirect_src) not Min (else would get '')
|
||||
, ", file_is_orig, orig_w, orig_h, -1, -1, lnki_time, lnki_page, Sum(lnki_count)"
|
||||
, ", 0"
|
||||
, "FROM xfer_temp x"
|
||||
, "WHERE file_is_orig = 1"
|
||||
, "GROUP BY orig_repo, lnki_ttl, lnki_ext, orig_media_type, file_is_orig, orig_w, orig_h, lnki_time, lnki_page"
|
||||
);
|
||||
private static final String Sql_create_data_thumb = String_.Concat_lines_nl
|
||||
( "INSERT INTO xfer_regy "
|
||||
, "( lnki_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
|
||||
, ", xfer_status"
|
||||
, ")"
|
||||
, "SELECT "
|
||||
, " Min(lnki_id), Min(lnki_page_id), Min(orig_page_id), orig_repo, lnki_ttl, Max(orig_redirect_src), lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, Sum(lnki_count)"
|
||||
, ", 0"
|
||||
, "FROM xfer_temp x"
|
||||
, "WHERE file_is_orig = 0"
|
||||
, "GROUP BY orig_repo, lnki_ttl, lnki_ext, orig_media_type, file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page"
|
||||
);
|
||||
private static final Db_idx_itm
|
||||
// Idx_select = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS xfer_regy__select ON xfer_regy (xfer_status, orig_repo, lnki_ttl, file_w);")
|
||||
Idx_lnki_page_id = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS xfer_regy__lnki_page_id ON xfer_regy (xfer_status, lnki_page_id, lnki_id, orig_repo, file_is_orig, lnki_ttl, lnki_ext, lnki_time, lnki_page, file_w, file_h);")
|
||||
, Idx_lnki_ttl = Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS xfer_regy__lnki_ttl ON xfer_regy (lnki_ttl);") // needed for troubleshooting
|
||||
;
|
||||
public static byte Status_todo = 0, Status_pass = 1, Status_fail = 2, Status_ignore_processed = 3;
|
||||
}
|
||||
class Xob_xfer_regy_log_tbl {
|
||||
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static Db_stmt Insert_stmt(Db_provider p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_lnki_id, Fld_xfer_status, Fld_xfer_bin_tid, Fld_xfer_bin_msg);}
|
||||
public static void Insert(Db_stmt stmt, byte status, int id, byte wkr_tid, String wkr_msg) {
|
||||
stmt.Clear()
|
||||
.Val_int_(id)
|
||||
.Val_byte_(status)
|
||||
.Val_byte_(wkr_tid)
|
||||
.Val_str_(wkr_msg)
|
||||
.Exec_insert();
|
||||
}
|
||||
private static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS xfer_regy_log"
|
||||
, "( lnki_id integer NOT NULL"
|
||||
, ", xfer_status tinyint NOT NULL" // 0=todo; 1=fail; 2=pass; 3=done
|
||||
, ", xfer_bin_tid tinyint NOT NULL"
|
||||
, ", xfer_bin_msg varchar(255) NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
public static final String Tbl_name = "xfer_regy_log"
|
||||
, Fld_lnki_id = "lnki_id", Fld_xfer_status = "xfer_status", Fld_xfer_bin_tid = "xfer_bin_tid", Fld_xfer_bin_msg = "xfer_bin_msg"
|
||||
;
|
||||
}
|
||||
160
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_regy_update_cmd.java
Normal file
160
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_regy_update_cmd.java
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.fsdb.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_xfer_regy_update_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_xfer_regy_update_cmd(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.xfer_regy_update";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_run() {Exec_main();}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
private void Exec_main() {
|
||||
Db_provider make_db_provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
this.Copy_atrs_to_make_db(make_db_provider);
|
||||
this.Update_status(make_db_provider);
|
||||
}
|
||||
private void Copy_atrs_to_make_db(Db_provider make_db_provider) {
|
||||
wiki.File_mgr().Fsdb_mgr().Init_by_wiki(wiki);
|
||||
Fsdb_db_abc_mgr fsdb_abc_mgr = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Abc_mgr_at(0); // 0 = fsdb.main
|
||||
Io_url fsdb_atr_url = fsdb_abc_mgr.Atr_mgr().Get_at(0).Url(); // 0 = fsdb.atr.00
|
||||
Sqlite_engine_.Tbl_create_and_delete(make_db_provider, Xob_fsdb_regy_tbl.Tbl_name, Xob_fsdb_regy_tbl.Tbl_sql);
|
||||
Sqlite_engine_.Db_attach(make_db_provider, "fsdb_db", fsdb_atr_url.Raw());
|
||||
make_db_provider.Txn_mgr().Txn_bgn();
|
||||
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Insert_fsdb_fil);
|
||||
String insert_sql_fsdb_thm = wiki.File_mgr().Fsdb_mgr().Mnt_mgr().Abc_mgr_at(0).Cfg_mgr().Schema_thm_page() // Cfg_get(Fsdb_cfg_mgr.Grp_core).Get_yn_or_n(Fsdb_cfg_mgr.Key_schema_thm_page)
|
||||
? Xob_fsdb_regy_tbl.Insert_fsdb_thm
|
||||
: Xob_fsdb_regy_tbl.Insert_fsdb_thm_v0
|
||||
;
|
||||
make_db_provider.Exec_sql(insert_sql_fsdb_thm);
|
||||
make_db_provider.Txn_mgr().Txn_end();
|
||||
Sqlite_engine_.Idx_create(make_db_provider, Xob_fsdb_regy_tbl.Idx_main);
|
||||
Sqlite_engine_.Db_detach(make_db_provider, "fsdb_db");
|
||||
}
|
||||
private void Update_status(Db_provider make_db_provider) {
|
||||
make_db_provider.Txn_mgr().Txn_bgn();
|
||||
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Update_regy_fil);
|
||||
make_db_provider.Exec_sql(Xob_fsdb_regy_tbl.Update_regy_thm);
|
||||
make_db_provider.Txn_mgr().Txn_end();
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Xob_fsdb_regy_tbl {
|
||||
public static final String Tbl_name = "fsdb_regy";
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE fsdb_regy "
|
||||
, "( fsdb_id integer NOT NULL PRIMARY KEY AUTOINCREMENT"
|
||||
, ", fsdb_name varchar(255) NOT NULL"
|
||||
, ", fsdb_is_orig tinyint NOT NULL"
|
||||
, ", fsdb_repo tinyint NOT NULL"
|
||||
, ", fsdb_w integer NOT NULL"
|
||||
, ", fsdb_time double NOT NULL"
|
||||
, ", fsdb_page integer NOT NULL"
|
||||
, ", fsdb_db_id integer NOT NULL"
|
||||
, ", fsdb_size bigint NOT NULL"
|
||||
, ", fsdb_status tinyint NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
public static final Db_idx_itm Idx_main = Db_idx_itm.sql_("CREATE INDEX fsdb_regy__main ON fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page);");
|
||||
public static final String
|
||||
Insert_fsdb_fil = String_.Concat_lines_nl
|
||||
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status)"
|
||||
, "SELECT f.fil_name"
|
||||
, ", 1"
|
||||
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
|
||||
, ", -1"
|
||||
, ", -1"
|
||||
, ", -1"
|
||||
, ", f.fil_bin_db_id"
|
||||
, ", f.fil_size"
|
||||
, ", 0"
|
||||
, "FROM fsdb_db.fsdb_fil f"
|
||||
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
|
||||
, "WHERE f.fil_bin_db_id != -1"
|
||||
, ";"
|
||||
)
|
||||
, Insert_fsdb_thm = String_.Concat_lines_nl
|
||||
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status)"
|
||||
, "SELECT f.fil_name"
|
||||
, ", 0"
|
||||
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
|
||||
, ", t.thm_w"
|
||||
, ", t.thm_time"
|
||||
, ", t.thm_page"
|
||||
, ", t.thm_bin_db_id"
|
||||
, ", t.thm_size"
|
||||
, ", 0"
|
||||
, "FROM fsdb_db.fsdb_fil f"
|
||||
, " JOIN fsdb_db.fsdb_xtn_thm t ON f.fil_id = t.thm_owner_id"
|
||||
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
|
||||
, ";"
|
||||
)
|
||||
, Insert_fsdb_thm_v0 = String_.Concat_lines_nl
|
||||
( "INSERT INTO fsdb_regy (fsdb_name, fsdb_is_orig, fsdb_repo, fsdb_w, fsdb_time, fsdb_page, fsdb_db_id, fsdb_size, fsdb_status)"
|
||||
, "SELECT f.fil_name"
|
||||
, ", 0"
|
||||
, ", CASE WHEN d.dir_name = 'commons.wikimedia.org' THEN 0 ELSE 1 END"
|
||||
, ", t.thm_w"
|
||||
, ", t.thm_thumbtime"
|
||||
, ", -1"
|
||||
, ", t.thm_bin_db_id"
|
||||
, ", t.thm_size"
|
||||
, ", 0"
|
||||
, "FROM fsdb_db.fsdb_fil f"
|
||||
, " JOIN fsdb_db.fsdb_xtn_thm t ON f.fil_id = t.thm_owner_id"
|
||||
, " JOIN fsdb_db.fsdb_dir d ON f.fil_owner_id = d.dir_id"
|
||||
, ";"
|
||||
)
|
||||
, Update_regy_fil = String_.Concat_lines_nl
|
||||
( "REPLACE INTO xfer_regy "
|
||||
, "( lnki_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
|
||||
, ", xfer_status"
|
||||
, ")"
|
||||
, "SELECT "
|
||||
, " lnki_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
|
||||
, ", CASE WHEN f.fsdb_name IS NOT NULL THEN 1 ELSE 0 END"
|
||||
, "FROM xfer_regy x"
|
||||
, " LEFT JOIN fsdb_regy f ON x.lnki_ttl = f.fsdb_name"
|
||||
, "WHERE x.file_is_orig = 1 AND f.fsdb_is_orig = 1"
|
||||
, "AND x.orig_repo = f.fsdb_repo"
|
||||
, ";"
|
||||
)
|
||||
, Update_regy_thm = String_.Concat_lines_nl
|
||||
( "REPLACE INTO xfer_regy "
|
||||
, "( lnki_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
|
||||
, ", xfer_status"
|
||||
, ")"
|
||||
, "SELECT "
|
||||
, " lnki_id, lnki_page_id, orig_page_id, orig_repo, lnki_ttl, orig_redirect_src, lnki_ext, orig_media_type"
|
||||
, ", file_is_orig, orig_w, orig_h, file_w, file_h, lnki_time, lnki_page, lnki_count"
|
||||
, ", CASE WHEN f.fsdb_name IS NOT NULL THEN 1 ELSE 0 END"
|
||||
, "FROM xfer_regy x"
|
||||
, " LEFT JOIN fsdb_regy f ON x.lnki_ttl = f.fsdb_name AND x.file_w = f.fsdb_w"
|
||||
, " AND x.lnki_time = f.fsdb_time AND x.lnki_page = f.fsdb_page"
|
||||
, "WHERE x.file_is_orig = 0 AND f.fsdb_is_orig = 0"
|
||||
, "AND x.orig_repo = f.fsdb_repo"
|
||||
, ";"
|
||||
)
|
||||
;
|
||||
}
|
||||
102
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_cmd_orig.java
Normal file
102
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_cmd_orig.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_xfer_temp_cmd_orig extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private byte[] ext_rules_key = Bry_.Empty;
|
||||
public Xob_xfer_temp_cmd_orig(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.xfer_temp.orig";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
Db_provider provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
Xob_xfer_temp_tbl.Create_table(provider);
|
||||
Db_stmt trg_stmt = Xob_xfer_temp_tbl.Insert_stmt(provider);
|
||||
provider.Txn_mgr().Txn_bgn_if_none();
|
||||
DataRdr rdr = provider.Exec_sql_as_rdr(Sql_select);
|
||||
long[] ext_maxs = Calc_ext_max();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
int lnki_ext = rdr.ReadByte(Xob_lnki_regy_tbl.Fld_lnki_ext);
|
||||
String orig_media_type = rdr.ReadStrOr(Xob_orig_regy_tbl.Fld_orig_media_type, ""); // convert nulls to ""
|
||||
lnki_ext = rdr.ReadInt(Xob_orig_regy_tbl.Fld_orig_file_ext);
|
||||
int lnki_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_id);
|
||||
byte orig_repo = rdr.ReadByte(Xob_orig_regy_tbl.Fld_orig_repo);
|
||||
int orig_page_id = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_page_id, -1);
|
||||
if (orig_page_id == -1) continue; // no orig found; ignore
|
||||
String join_ttl = rdr.ReadStr(Xob_orig_regy_tbl.Fld_orig_file_ttl);
|
||||
String redirect_src = rdr.ReadStr(Xob_orig_regy_tbl.Fld_lnki_ttl);
|
||||
if (String_.Eq(join_ttl, redirect_src)) // lnki_ttl is same as redirect_src; not a redirect
|
||||
redirect_src = "";
|
||||
int orig_w = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_w, -1);
|
||||
int orig_h = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_h, -1);
|
||||
int orig_size = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_size, -1);
|
||||
if (orig_size > ext_maxs[lnki_ext]) continue;
|
||||
int lnki_page_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page_id);
|
||||
Xob_xfer_temp_tbl.Insert(trg_stmt, lnki_id, lnki_page_id, orig_repo, orig_page_id, join_ttl, redirect_src, lnki_ext, Xop_lnki_type.Id_none, orig_media_type
|
||||
, Bool_.Y // orig is y
|
||||
, orig_w, orig_h
|
||||
, orig_w, orig_h // file_w, file_h is same as orig_w,orig_h; i.e.: make same file_w as orig_w
|
||||
, Xof_img_size.Null, Xof_img_size.Null // html_w, html_h is -1; i.e.: will not be displayed in page at specific size (this matches logic in Xob_xfer_temp_cmd_thumb)
|
||||
, Xof_doc_thumb.Null
|
||||
, Xof_doc_page.Null
|
||||
, 0);
|
||||
}
|
||||
provider.Txn_mgr().Txn_end_all();
|
||||
}
|
||||
private long[] Calc_ext_max() {
|
||||
Xoft_rule_grp ext_rules = wiki.App().File_mgr().Ext_rules().Get_or_new(ext_rules_key);
|
||||
long[] rv = new long[Xof_ext_.Id__max];
|
||||
for (int i = 0; i < Xof_ext_.Id__max; i++) {
|
||||
byte[] ext = Xof_ext_.Get_ext_by_id_(i);
|
||||
Xoft_rule_itm ext_rule = ext_rules.Get_or_null(ext);
|
||||
long max = ext_rule == null ? 0 : ext_rule.Make_max();
|
||||
rv[i] = max;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
private static final String
|
||||
Sql_select = String_.Concat_lines_nl
|
||||
( "SELECT DISTINCT"
|
||||
, " l.lnki_id"
|
||||
// , ", lnki_ttl"
|
||||
, ", l.lnki_ext"
|
||||
, ", l.lnki_page_id"
|
||||
, ", o.orig_repo"
|
||||
, ", o.orig_page_id"
|
||||
// , ", orig_file_id"
|
||||
, ", o.orig_file_ttl"
|
||||
, ", o.orig_file_ext"
|
||||
, ", o.lnki_ttl"
|
||||
, ", o.orig_size"
|
||||
, ", o.orig_w"
|
||||
, ", o.orig_h"
|
||||
, ", o.orig_media_type"
|
||||
// , ", orig_bits"
|
||||
, "FROM lnki_regy l"
|
||||
, " JOIN orig_regy o ON o.lnki_ttl = l.lnki_ttl"
|
||||
, "WHERE o.orig_file_ttl IS NOT NULL"
|
||||
, "ORDER BY o.orig_file_ttl DESC"
|
||||
);
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_ext_rules_)) ext_rules_key = m.ReadBry("v");
|
||||
else return super.Invk (ctx, ikey, k, m);
|
||||
return this;
|
||||
} private static final String Invk_ext_rules_ = "ext_rules_";
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
public class Xob_xfer_temp_cmd_thumb extends Xob_itm_basic_base implements Xob_cmd {
|
||||
public Xob_xfer_temp_cmd_thumb(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return KEY_oimg;} public static final String KEY_oimg = "file.xfer_temp.thumb";
|
||||
public void Cmd_ini(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {
|
||||
Db_provider provider = Xodb_db_file.init__file_make(wiki.Fsys_mgr().Root_dir()).Provider();
|
||||
Xob_xfer_temp_tbl.Create_table(provider);
|
||||
Db_stmt trg_stmt = Xob_xfer_temp_tbl.Insert_stmt(provider);
|
||||
provider.Txn_mgr().Txn_bgn_if_none();
|
||||
DataRdr rdr = provider.Exec_sql_as_rdr(Sql_select);
|
||||
Xob_xfer_temp_itm temp_itm = new Xob_xfer_temp_itm();
|
||||
Xof_img_size img_size = new Xof_img_size();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
temp_itm.Clear();
|
||||
temp_itm.Load(rdr);
|
||||
if (temp_itm.Chk(img_size))
|
||||
temp_itm.Insert(trg_stmt, img_size);
|
||||
}
|
||||
provider.Txn_mgr().Txn_end_all();
|
||||
}
|
||||
public void Cmd_run() {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_print() {}
|
||||
private static final String
|
||||
Sql_select = String_.Concat_lines_nl
|
||||
( "SELECT l.lnki_id"
|
||||
, ", l.lnki_page_id"
|
||||
, ", l.lnki_ext"
|
||||
, ", l.lnki_type"
|
||||
, ", l.lnki_src_tid"
|
||||
, ", l.lnki_w"
|
||||
, ", l.lnki_h"
|
||||
, ", l.lnki_upright"
|
||||
, ", l.lnki_time"
|
||||
, ", l.lnki_page"
|
||||
, ", l.lnki_count"
|
||||
, ", o.orig_repo"
|
||||
, ", o.orig_page_id"
|
||||
, ", o.orig_file_ttl"
|
||||
, ", o.orig_file_ext"
|
||||
, ", o.orig_file_id"
|
||||
, ", o.lnki_ttl"
|
||||
, ", o.orig_w"
|
||||
, ", o.orig_h"
|
||||
, ", o.orig_media_type"
|
||||
, ", o.orig_minor_mime"
|
||||
, "FROM lnki_regy l"
|
||||
, " JOIN orig_regy o ON o.lnki_ttl = l.lnki_ttl"
|
||||
, "WHERE o.orig_file_ttl IS NOT NULL"
|
||||
, "ORDER BY o.orig_file_ttl, l.lnki_w DESC"
|
||||
);
|
||||
}
|
||||
121
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_itm.java
Normal file
121
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_itm.java
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.files.*;
|
||||
class Xob_xfer_temp_itm {
|
||||
public int Lnki_id() {return lnki_id;} private int lnki_id;
|
||||
public byte Orig_repo() {return orig_repo;} private byte orig_repo;
|
||||
public int Lnki_ext() {return lnki_ext;} private int lnki_ext;
|
||||
public String Orig_media_type() {return orig_media_type;} private String orig_media_type;
|
||||
public String Orig_minor_mime() {return orig_minor_mime;} private String orig_minor_mime;
|
||||
public byte Orig_media_type_tid() {return orig_media_type_tid;} private byte orig_media_type_tid;
|
||||
public int Orig_page_id() {return orig_page_id;} private int orig_page_id;
|
||||
public String Join_ttl() {return join_ttl;} private String join_ttl;
|
||||
public String Redirect_src() {return redirect_src;} private String redirect_src;
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public byte Lnki_src_tid() {return lnki_src_tid;} private byte lnki_src_tid;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public int Lnki_count() {return lnki_count;} private int lnki_count;
|
||||
public int Lnki_page_id() {return lnki_page_id;} private int lnki_page_id;
|
||||
public int Orig_w() {return orig_w;} private int orig_w;
|
||||
public int Orig_h() {return orig_h;} private int orig_h;
|
||||
public int Orig_ext_id() {return orig_ext_id;} private int orig_ext_id;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public double Lnki_thumbtime() {return lnki_thumbtime;} private double lnki_thumbtime;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public void Clear() {
|
||||
lnki_ext = lnki_type = lnki_src_tid
|
||||
= orig_repo = orig_media_type_tid = Byte_.MaxValue_127;
|
||||
chk_tid = Chk_tid_none;
|
||||
lnki_id = lnki_w = lnki_h = lnki_count = lnki_page_id
|
||||
= orig_w = orig_h = orig_page_id = Int_.Neg1;
|
||||
join_ttl = redirect_src = orig_media_type = null;
|
||||
lnki_upright = Xop_lnki_tkn.Upright_null;
|
||||
lnki_thumbtime = Xof_doc_thumb.Null;
|
||||
lnki_page = Xof_doc_page.Null;
|
||||
}
|
||||
public void Load(DataRdr rdr) {
|
||||
lnki_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_id);
|
||||
lnki_page_id = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page_id);
|
||||
lnki_ext = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_ext);
|
||||
lnki_type = rdr.ReadByte(Xob_lnki_regy_tbl.Fld_lnki_type);
|
||||
lnki_src_tid = rdr.ReadByte(Xob_lnki_regy_tbl.Fld_lnki_src_tid);
|
||||
lnki_w = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_w);
|
||||
lnki_h = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_h);
|
||||
lnki_upright = rdr.ReadDouble(Xob_lnki_regy_tbl.Fld_lnki_upright);
|
||||
lnki_thumbtime = Xof_doc_thumb.Db_load_double(rdr, Xob_lnki_regy_tbl.Fld_lnki_time);
|
||||
lnki_page = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_page);
|
||||
lnki_count = rdr.ReadInt(Xob_lnki_regy_tbl.Fld_lnki_count);
|
||||
orig_repo = rdr.ReadByte(Xob_orig_regy_tbl.Fld_orig_repo);
|
||||
orig_page_id = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_page_id, -1);
|
||||
join_ttl = rdr.ReadStr(Xob_orig_regy_tbl.Fld_orig_file_ttl);
|
||||
redirect_src = rdr.ReadStr(Xob_orig_regy_tbl.Fld_lnki_ttl);
|
||||
orig_w = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_w, -1);
|
||||
orig_h = rdr.ReadIntOr(Xob_orig_regy_tbl.Fld_orig_h, -1);
|
||||
orig_media_type = rdr.ReadStrOr(Xob_orig_regy_tbl.Fld_orig_media_type, ""); // convert nulls to ""
|
||||
orig_minor_mime = rdr.ReadStrOr(Xob_orig_regy_tbl.Fld_orig_minor_mime, ""); // convert nulls to ""
|
||||
orig_ext_id = rdr.ReadInt(Xob_orig_regy_tbl.Fld_orig_file_ext);
|
||||
}
|
||||
public static final byte
|
||||
Chk_tid_none = 0
|
||||
, Chk_tid_orig_page_id_is_null = 1
|
||||
, Chk_tid_orig_media_type_is_audio = 2
|
||||
, Chk_tid_ns_is_media = 3
|
||||
;
|
||||
public byte Chk_tid() {return chk_tid;} private byte chk_tid;
|
||||
public boolean Chk(Xof_img_size img_size) {
|
||||
if (String_.Eq(join_ttl, redirect_src)) // join_ttl is same as redirect_src; not a redirect; EX:(direct) join="A.png";redirect_src="A.png"; (redirect) join="A.png";redirect_src="B.png" (i.e.: B redirects to A)
|
||||
redirect_src = "";
|
||||
// else { // redirect; make sure extension matches; EX: A.png redirects to B.png; lnki_ext will be .png (the lnki's ext); should be .png (the actual file's ext)
|
||||
// Xof_ext join_ext = Xof_ext_.new_by_ttl_(Bry_.new_utf8_(join_ttl));
|
||||
// lnki_ext = join_ext.Id();
|
||||
// }
|
||||
lnki_ext = orig_ext_id;
|
||||
orig_media_type_tid = Xof_media_type.Xto_byte(orig_media_type);
|
||||
if ( Xof_doc_thumb.Null_n(lnki_thumbtime) // thumbtime defined
|
||||
&& orig_media_type_tid != Xof_media_type.Tid_video // video can have thumbtime
|
||||
)
|
||||
lnki_thumbtime = Xof_doc_thumb.Null; // set thumbtime to NULL; actually occurs for one file: [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
|
||||
if ( Xof_doc_page.Null_n(lnki_page)
|
||||
&& !Xof_ext_.Id_supports_page(orig_ext_id)) // djvu / pdf can have page parameters, which are currently being stored in thumbtime; DATE:2014-01-18
|
||||
lnki_page = Xof_doc_page.Null;
|
||||
if (orig_page_id == -1) { // no orig found (i.e.: not in local's / remote's image.sql);
|
||||
chk_tid = Chk_tid_orig_page_id_is_null;
|
||||
return false;
|
||||
}
|
||||
if (orig_media_type_tid == Xof_media_type.Tid_audio) { // ignore: audio will never have thumbs
|
||||
chk_tid = Chk_tid_orig_media_type_is_audio;
|
||||
return false;
|
||||
}
|
||||
if (lnki_ext == Xof_ext_.Id_mid) { // NOTE: .mid does not have orig_media_type of "AUDIO"
|
||||
chk_tid = Chk_tid_orig_media_type_is_audio;
|
||||
return false;
|
||||
}
|
||||
if (lnki_src_tid == Xob_lnki_src_tid.Tid_media) {
|
||||
chk_tid = Chk_tid_ns_is_media;
|
||||
return false;
|
||||
}
|
||||
boolean upright_patch = true; // all future blds will have upright_patch
|
||||
img_size.Html_size_calc(Xof_exec_tid.Tid_wiki_page, lnki_w, lnki_h, lnki_type, upright_patch, lnki_upright, lnki_ext, orig_w, orig_h, Xof_img_size.Thumb_width_img);
|
||||
return true;
|
||||
}
|
||||
public void Insert(Db_stmt stmt, Xof_img_size img_size) {
|
||||
Xob_xfer_temp_tbl.Insert(stmt, lnki_id, lnki_page_id, orig_repo, orig_page_id, join_ttl, redirect_src, lnki_ext, lnki_type, orig_media_type, img_size.File_is_orig(), orig_w, orig_h, img_size.File_w(), img_size.File_h(), img_size.Html_w(), img_size.Html_h(), lnki_thumbtime, lnki_page, lnki_count);
|
||||
}
|
||||
}
|
||||
183
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_itm_tst.java
Normal file
183
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_itm_tst.java
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.stores.*; import gplx.xowa.files.*;
|
||||
public class Xob_xfer_temp_itm_tst {
|
||||
private Xob_xfer_temp_itm_fxt fxt = new Xob_xfer_temp_itm_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Pass() {fxt.Test_pass().Test_itm_chk_fail_id_none();}
|
||||
@Test public void Missing_orig() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_page_id_is_null , KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_page_id, null));}
|
||||
@Test public void File_is_audio() {fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_media_type, Xof_media_type.Name_audio));}
|
||||
@Test public void File_is_mid() {
|
||||
fxt.Test_fail(Xob_xfer_temp_itm.Chk_tid_orig_media_type_is_audio , KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext, Xof_ext_.Id_mid));
|
||||
}
|
||||
@Test public void Redirect_src_is_empty() { // orig_cmd sets all direct files to have "orig_join" == "lnki_ttl"
|
||||
fxt.Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "A.png")
|
||||
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
);
|
||||
fxt.Test_lnki_redirect_src(""); // confirm redirect_src set to ""
|
||||
}
|
||||
@Test public void Redirect_src_has_val() { // orig_cmd sets all redirect files to have "orig_join" = redirect and "lnki_ttl" as orig; EX: A.png redirects to B.png; orig_join will be B.png (the actual image) and redirect_src will be A.png (the original lnki)
|
||||
fxt.Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.png")
|
||||
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
);
|
||||
fxt.Test_lnki_redirect_src("A.png"); // confirm redirect_src set to ""
|
||||
}
|
||||
@Test public void Redirect_should_take_trg_ext() {// if "A.png" redirects to "B.jpg", ext_id should be ".jpg" (the actual file) not ".png (lnki_ext_id)
|
||||
fxt.Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ttl , "B.jpg")
|
||||
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
, KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg) // .png b/c B.jpg
|
||||
);
|
||||
fxt.Test_lnki_ext_id(Xof_ext_.Id_jpg); // confirm ext changed to .jpg
|
||||
}
|
||||
@Test public void Thumbtime_check() {// PURPOSE: one image actually had a thumbtime defined; EX: General_Dynamics_F-16_Fighting_Falcon; [[File:Crash.arp.600pix.jpg|thumb|thumbtime=2]]
|
||||
fxt.Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
|
||||
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
|
||||
);
|
||||
fxt.Test_lnki_thumbtime(Xof_doc_thumb.Null);
|
||||
|
||||
fxt.Reset().Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_media_type , Xof_media_type.Name_video)
|
||||
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_time , (double)3)
|
||||
);
|
||||
fxt.Test_lnki_thumbtime(3);
|
||||
}
|
||||
@Test public void Page_check() {
|
||||
fxt.Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_jpg)
|
||||
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
|
||||
);
|
||||
fxt.Test_lnki_page(Xof_doc_page.Null);
|
||||
|
||||
fxt.Reset().Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_pdf)
|
||||
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
|
||||
);
|
||||
fxt.Test_lnki_page(3);
|
||||
|
||||
fxt.Reset().Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_orig_file_ext , Xof_ext_.Id_djvu)
|
||||
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_page , 3)
|
||||
);
|
||||
fxt.Test_lnki_page(3);
|
||||
}
|
||||
@Test public void Media_should_be_ignored() {// ignore [[Media:]] for xfer_thumb (needed for xfer_orig)
|
||||
fxt.Test_bgn
|
||||
( KeyVal_.new_(Xob_orig_regy_tbl.Fld_lnki_ttl , "A.png")
|
||||
, KeyVal_.new_(Xob_lnki_regy_tbl.Fld_lnki_src_tid , Xob_lnki_src_tid.Tid_media)
|
||||
);
|
||||
fxt.Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_ns_is_media);
|
||||
}
|
||||
}
|
||||
class Xob_xfer_temp_itm_fxt {
|
||||
private Xob_xfer_temp_itm itm = new Xob_xfer_temp_itm();
|
||||
private Xof_img_size img_size = new Xof_img_size();
|
||||
private DataRdr_mem rdr;
|
||||
private GfoNde nde;
|
||||
public static String[] Flds = new String[]
|
||||
{ Xob_lnki_regy_tbl.Fld_lnki_ext
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_id
|
||||
, Xob_orig_regy_tbl.Fld_orig_repo
|
||||
, Xob_orig_regy_tbl.Fld_orig_file_ttl
|
||||
, Xob_orig_regy_tbl.Fld_orig_file_ext
|
||||
, Xob_orig_regy_tbl.Fld_lnki_ttl
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_type
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_src_tid
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_w
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_h
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_count
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_page_id
|
||||
, Xob_orig_regy_tbl.Fld_orig_w
|
||||
, Xob_orig_regy_tbl.Fld_orig_h
|
||||
, Xob_orig_regy_tbl.Fld_orig_page_id
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_upright
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_time
|
||||
, Xob_lnki_regy_tbl.Fld_lnki_page
|
||||
, Xob_orig_regy_tbl.Fld_orig_media_type
|
||||
, Xob_orig_regy_tbl.Fld_orig_minor_mime
|
||||
}
|
||||
;
|
||||
public Xob_xfer_temp_itm_fxt Reset() {
|
||||
itm.Clear();
|
||||
img_size.Clear();
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Init_rdr_image() {
|
||||
GfoFldList flds = GfoFldList_.str_(Flds);
|
||||
nde = GfoNde_.vals_(flds, Object_.Ary
|
||||
( Xof_ext_.Id_png, 1, Xof_repo_itm.Repo_remote
|
||||
, "A.png", Xof_ext_.Id_png, "A.png", Xop_lnki_type.Id_thumb, Xob_lnki_src_tid.Tid_file
|
||||
, 220, 200, 1, 2, 440, 400, 3
|
||||
, Xop_lnki_tkn.Upright_null, Xof_doc_thumb.Null, Xof_doc_page.Null
|
||||
, Xof_media_type.Name_bitmap, "png"
|
||||
));
|
||||
GfoNdeList subs = GfoNdeList_.new_();
|
||||
subs.Add(nde);
|
||||
GfoNde root = GfoNde_.root_(nde);
|
||||
rdr = DataRdr_mem.new_(root, flds, subs);
|
||||
rdr.MoveNextPeer();
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Init_rdr(String key, Object val) {
|
||||
nde.Write(key, val);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_pass() {return Test_bgn();}
|
||||
public Xob_xfer_temp_itm_fxt Test_fail(byte fail_tid, KeyVal... kvs) {
|
||||
Test_bgn(kvs);
|
||||
this.Test_itm_chk_fail_id(fail_tid);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_bgn(KeyVal... kvs) {
|
||||
Init_rdr_image();
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
KeyVal kv = kvs[i];
|
||||
Init_rdr(kv.Key(), kv.Val());
|
||||
}
|
||||
this.Exec_load();
|
||||
this.Exec_chk();
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_atr(String key, Object val) {
|
||||
Tfds.Eq(rdr.Read(key), val);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Exec_load() {
|
||||
itm.Load(rdr);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Exec_chk() {
|
||||
itm.Chk(img_size);
|
||||
return this;
|
||||
}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_ext_id(int expd) {Tfds.Eq(expd, itm.Lnki_ext()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_thumbtime(double expd) {Tfds.Eq(expd, itm.Lnki_thumbtime()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_page(int expd) {Tfds.Eq(expd, itm.Lnki_page()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_lnki_redirect_src(String expd) {Tfds.Eq(expd, itm.Redirect_src()); return this;}
|
||||
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id_none() {return Test_itm_chk_fail_id(Xob_xfer_temp_itm.Chk_tid_none);}
|
||||
public Xob_xfer_temp_itm_fxt Test_itm_chk_fail_id(byte expd) {
|
||||
Tfds.Eq(expd, itm.Chk_tid());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
77
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_tbl.java
Normal file
77
400_xowa/src/gplx/xowa/bldrs/files/Xob_xfer_temp_tbl.java
Normal 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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.files.*;
|
||||
class Xob_xfer_temp_tbl {
|
||||
public static void Create_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static Db_stmt Insert_stmt(Db_provider p) {return Db_stmt_.new_insert_(p, Tbl_name, Fld_lnki_id, Fld_lnki_page_id, Fld_orig_repo, Fld_orig_page_id, Fld_lnki_ttl, Fld_orig_redirect_src, Fld_lnki_ext, Fld_lnki_type, Fld_orig_media_type, Fld_file_is_orig, Fld_orig_w, Fld_orig_h, Fld_file_w, Fld_file_h, Fld_html_w, Fld_html_h, Fld_lnki_time, Fld_lnki_page, Fld_lnki_count);}
|
||||
public static void Insert(Db_stmt stmt, int lnki_id, int lnki_page_id, byte repo_id, int page_id, String ttl, String redirect_src, int ext_id, byte lnki_type, String orig_media_type, boolean file_is_orig, int orig_w, int orig_h, int html_w, int html_h, int file_w, int file_h, double thumbtime, int page, int count) {
|
||||
stmt.Clear()
|
||||
.Val_int_(lnki_id)
|
||||
.Val_int_(lnki_page_id)
|
||||
.Val_byte_(repo_id)
|
||||
.Val_int_(page_id)
|
||||
.Val_str_(ttl)
|
||||
.Val_str_(redirect_src)
|
||||
.Val_int_(ext_id)
|
||||
.Val_byte_(lnki_type)
|
||||
.Val_str_(orig_media_type)
|
||||
.Val_byte_by_bool_(file_is_orig)
|
||||
.Val_int_(orig_w)
|
||||
.Val_int_(orig_h)
|
||||
.Val_int_(file_w)
|
||||
.Val_int_(file_h)
|
||||
.Val_int_(html_w)
|
||||
.Val_int_(html_h)
|
||||
.Val_double_(Xof_doc_thumb.Db_save_double(thumbtime))
|
||||
.Val_int_(page)
|
||||
.Val_int_(count)
|
||||
.Exec_insert();
|
||||
}
|
||||
public static final String Tbl_name = "xfer_temp"
|
||||
, Fld_lnki_id = "lnki_id", Fld_lnki_page_id = "lnki_page_id", Fld_lnki_ttl = "lnki_ttl", Fld_lnki_ext = "lnki_ext", Fld_lnki_type = "lnki_type"
|
||||
, Fld_lnki_time = "lnki_time", Fld_lnki_page = "lnki_page", Fld_lnki_count = "lnki_count"
|
||||
, Fld_orig_repo = "orig_repo", Fld_orig_page_id = "orig_page_id", Fld_orig_redirect_src = "orig_redirect_src", Fld_orig_media_type = "orig_media_type"
|
||||
, Fld_orig_w = "orig_w", Fld_orig_h = "orig_h"
|
||||
, Fld_file_w = "file_w", Fld_file_h = "file_h", Fld_file_is_orig = "file_is_orig"
|
||||
, Fld_html_w = "html_w", Fld_html_h = "html_h"
|
||||
;
|
||||
private static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS xfer_temp"
|
||||
, "( lnki_id integer NOT NULL PRIMARY KEY"
|
||||
, ", lnki_page_id integer NOT NULL"
|
||||
, ", lnki_ttl varchar(255) NOT NULL"
|
||||
, ", lnki_ext integer NOT NULL"
|
||||
, ", lnki_type integer NOT NULL"
|
||||
, ", lnki_time double NOT NULL"
|
||||
, ", lnki_page integer NOT NULL"
|
||||
, ", lnki_count integer NOT NULL"
|
||||
, ", orig_repo integer NOT NULL"
|
||||
, ", orig_page_id integer NOT NULL"
|
||||
, ", orig_redirect_src varchar(255) NOT NULL"
|
||||
, ", orig_media_type varchar(64) NOT NULL"
|
||||
, ", orig_w integer NOT NULL"
|
||||
, ", orig_h integer NOT NULL"
|
||||
, ", file_is_orig tinyint NOT NULL"
|
||||
, ", file_w integer NOT NULL"
|
||||
, ", file_h integer NOT NULL"
|
||||
, ", html_w integer NOT NULL"
|
||||
, ", html_h integer NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/bldrs/files/Xobu_poll_mgr.java
Normal file
38
400_xowa/src/gplx/xowa/bldrs/files/Xobu_poll_mgr.java
Normal 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.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
public class Xobu_poll_mgr implements GfoInvkAble {
|
||||
public Xobu_poll_mgr(Xoa_app app) {this.app = app;} private Xoa_app app;
|
||||
public int Poll_interval() {return poll_interval;} private int poll_interval = 1000;
|
||||
private Io_url poll_file;
|
||||
public void Poll() {
|
||||
if (poll_file == null) poll_file = app.Fsys_mgr().Root_dir().GenSubFil("bldr_poll.gfs");
|
||||
if (!Io_mgr._.ExistsFil(poll_file)) return; // file doesn't exist
|
||||
String poll_text = Io_mgr._.LoadFilStr(poll_file);
|
||||
Io_mgr._.DeleteFil(poll_file);
|
||||
app.Usr_dlg().Note_many("", "", "poll file found: ~{0}", poll_file.Raw());
|
||||
app.Gfs_mgr().Run_str(poll_text);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_poll_interval_)) poll_interval = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_poll_file_)) poll_file = m.ReadIoUrl("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_poll_interval_ = "poll_interval_", Invk_poll_file_ = "poll_file_";
|
||||
}
|
||||
58
400_xowa/src/gplx/xowa/bldrs/imports/Xob_import_cfg.java
Normal file
58
400_xowa/src/gplx/xowa/bldrs/imports/Xob_import_cfg.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.ctgs.*;
|
||||
public class Xob_import_cfg {
|
||||
public Xob_import_cfg(Xow_wiki wiki) {this.wiki = wiki;} private Xow_wiki wiki; private boolean src_fil_is_bz2 = true;
|
||||
public byte Category_version() {return category_version;} public Xob_import_cfg Category_version_(byte v) {category_version = v; return this;} private byte category_version = Xoa_ctg_mgr.Version_1;
|
||||
public Io_url Src_fil_xml() {return src_fil_xml;}
|
||||
public Xob_import_cfg Src_fil_xml_(Io_url v) {src_fil_xml = v; src_fil_is_bz2 = Bool_.N; return this;} private Io_url src_fil_xml;
|
||||
public Xob_import_cfg Src_fil_bz2_(Io_url v) {src_fil_bz2 = v; src_fil_is_bz2 = Bool_.Y; return this;} private Io_url src_fil_bz2;
|
||||
public Io_url Src_dir() {
|
||||
if (src_fil_xml == null && src_fil_bz2 == null) return wiki.Fsys_mgr().Root_dir();
|
||||
else if (src_fil_xml != null) return src_fil_xml.OwnerDir();
|
||||
else if (src_fil_bz2 != null) return src_fil_bz2.OwnerDir();
|
||||
else throw Err_.new_("unknown src dir");
|
||||
}
|
||||
public gplx.ios.Io_stream_rdr Src_rdr() {
|
||||
if (src_fil_xml == null && src_fil_bz2 == null) { // will usually be null; non-null when user specifies src through command-line
|
||||
Io_url url = Xow_fsys_mgr.Find_file_or_fail(wiki.Fsys_mgr().Root_dir(), "*", ".xml", ".bz2");
|
||||
if (String_.Eq(url.Ext(), ".xml")) Src_fil_xml_(url);
|
||||
else Src_fil_bz2_(url);
|
||||
}
|
||||
if (src_fil_is_bz2) {
|
||||
Chk_file_ext(wiki.App(), src_fil_bz2, ".bz2", "xml");
|
||||
Xoa_app app = wiki.App();
|
||||
if (app.Setup_mgr().Dump_mgr().Import_bz2_by_stdout()) {
|
||||
ProcessAdp process = app.Fsys_mgr().App_mgr().App_decompress_bz2_by_stdout();
|
||||
return Io_stream_rdr_process.new_(process.Exe_url(), src_fil_bz2, process.X_to_process_bldr_args(src_fil_bz2.Raw()));
|
||||
}
|
||||
else
|
||||
return gplx.ios.Io_stream_rdr_.bzip2_(src_fil_bz2);
|
||||
}
|
||||
else {
|
||||
Chk_file_ext(wiki.App(), src_fil_xml, ".xml", "bz2");
|
||||
return gplx.ios.Io_stream_rdr_.file_(src_fil_xml);
|
||||
}
|
||||
}
|
||||
private static void Chk_file_ext(Xoa_app app, Io_url fil, String expd_ext, String alt_ext) {
|
||||
if (!String_.Eq(fil.Ext(), expd_ext))
|
||||
app.Usr_dlg().Warn_many("", "", "File extension is not " + expd_ext + ". Please use '.src_" + alt_ext + "_fil_' instead; file=~{0}", fil.Raw());
|
||||
}
|
||||
}
|
||||
54
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base.java
Normal file
54
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base.java
Normal 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.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.bldrs.xmls.*;
|
||||
public abstract class Xob_init_base implements Xob_cmd, GfoInvkAble {
|
||||
public Xob_init_base Ctor(Xob_bldr bldr, Xow_wiki wiki) {this.bldr = bldr; this.wiki = wiki; this.usr_dlg = wiki.App().Usr_dlg(); return this;} private Xob_bldr bldr; Xow_wiki wiki; Gfo_usr_dlg usr_dlg;
|
||||
public abstract String Cmd_key();
|
||||
public abstract void Cmd_ini_wdata(Xob_bldr bldr, Xow_wiki wiki);
|
||||
public abstract void Cmd_run_end(Xow_wiki wiki);
|
||||
public void Cmd_ini(Xob_bldr bldr) { // add other cmds; EX: wikidata
|
||||
if (wdata_enabled == Bool_.__byte) wdata_enabled = wiki.Domain_tid() == Xow_wiki_domain_.Tid_wikidata ? Bool_.Y_byte : Bool_.N_byte; // if wdata_enabled not explicitly set, set it to y if wiki is "www.wikidata.org"
|
||||
if (wdata_enabled == Bool_.Y_byte) // if wdata_enabled, auto-add wdata_wkrs bldr
|
||||
this.Cmd_ini_wdata(bldr, wiki);
|
||||
} private byte wdata_enabled = Bool_.__byte;
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_run() { // parse site_info
|
||||
gplx.ios.Io_stream_rdr src_rdr = wiki.Import_cfg().Src_rdr();
|
||||
byte[] siteinfo_xml = Xob_siteinfo_parser.Siteinfo_extract(src_rdr);
|
||||
Xob_siteinfo_parser.Siteinfo_parse(wiki, usr_dlg, String_.new_utf8_(siteinfo_xml));
|
||||
this.Cmd_run_end(wiki); // save site info
|
||||
}
|
||||
public void Cmd_end() {
|
||||
wiki.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_refresh(); // dirty wiki list so that next refresh will load itm
|
||||
if (wiki.App().Setup_mgr().Dump_mgr().Css_wiki_update()) {
|
||||
Io_url url = wiki.App().User().Fsys_mgr().Wiki_html_dir(wiki.Domain_str()).GenSubFil(Xoa_css_extractor.Css_wiki_name);
|
||||
usr_dlg.Log_many("", "", "deleting css: ~{0}", url.Raw());
|
||||
Io_mgr._.DeleteFil_args(url).MissingFails_off().Exec();
|
||||
}
|
||||
}
|
||||
public void Cmd_print() {}
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_src_xml_fil_)) wiki.Import_cfg().Src_fil_xml_(m.ReadIoUrl("v"));
|
||||
else if (ctx.Match(k, Invk_src_bz2_fil_)) wiki.Import_cfg().Src_fil_bz2_(m.ReadIoUrl("v"));
|
||||
else if (ctx.Match(k, Invk_wdata_enabled_)) wdata_enabled = m.ReadYn("v") ? Bool_.Y_byte : Bool_.N_byte;
|
||||
else if (ctx.Match(k, Invk_owner)) return bldr.Cmd_mgr();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_src_xml_fil_ = "src_xml_fil_", Invk_src_bz2_fil_ = "src_bz2_fil_", Invk_owner = "owner", Invk_wdata_enabled_ = "wdata_enabled_";
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base_tst.java
Normal file
43
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_base_tst.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.html.portal.*;
|
||||
public class Xob_init_base_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_init_base_fxt fxt = new Xob_init_base_fxt();
|
||||
@Test public void Dirty_wiki_itms() {
|
||||
Xoa_app app = fxt.App(); Xow_wiki wiki = fxt.Wiki();
|
||||
Xoa_available_wikis_mgr wikis_list = fxt.App().Gui_mgr().Html_mgr().Portal_mgr().Wikis();
|
||||
Tfds.Eq("", wikis_list.Itms_as_html()); // assert
|
||||
app.User().Wiki().Xwiki_mgr().Add_full("en.wikipedia.org", "en.wikipedia.org");
|
||||
Tfds.Eq("", wikis_list.Itms_as_html()); // still empty
|
||||
new Xob_init_txt(app.Bldr(), wiki).Cmd_end(); // mock "init" task
|
||||
Tfds.Eq("\n <li><a href=\"/site/en.wikipedia.org/\">en.wikipedia.org</a></li>", wikis_list.Itms_as_html()); // no longer empty
|
||||
}
|
||||
}
|
||||
class Xob_init_base_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
Io_mgr._.InitEngine_mem();
|
||||
}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_sql.java
Normal file
34
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_sql.java
Normal 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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.xtns.wdatas.*; import gplx.xowa.dbs.*; import gplx.xowa.xtns.wdatas.imports.*;
|
||||
public class Xob_init_sql extends Xob_init_base {
|
||||
public Xob_init_sql(Xob_bldr bldr, Xow_wiki wiki) {this.Ctor(bldr, wiki);}
|
||||
@Override public String Cmd_key() {return KEY;} public static final String KEY = "import.sql.init";
|
||||
@Override public void Cmd_ini_wdata(Xob_bldr bldr, Xow_wiki wiki) {
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_wdata_qid_sql.KEY);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_wdata_pid_sql.KEY);
|
||||
}
|
||||
@Override public void Cmd_run_end(Xow_wiki wiki) {
|
||||
if (Xodb_mgr_sql.Find_core_url(wiki) != null) throw wiki.App().Bldr().Usr_dlg().Fail_many("", "", "directory must not contain any sqlite3 files: ~{0}", wiki.Fsys_mgr().Root_dir().Raw());
|
||||
String ns_map = wiki.App().Setup_mgr().Dump_mgr().Db_ns_map();
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_create_as_sql();
|
||||
db_mgr.Init_make(ns_map); // NOTE: must Init after Xob_siteinfo_parser b/c Xob_siteinfo_parser will create new ns itms
|
||||
db_mgr.Tbl_xowa_cfg().Insert_str(Xodb_mgr_sql.Grp_wiki_init, "db_mgr.data_storage_format", Xoi_dump_mgr.Wtr_tid_to_str(db_mgr.Data_storage_format())); // NOTE: insert data_storage_format at init stage, not at term stage; bldr will reload wiki, and will default to gz since setting is not saved; DATE:2013-10-27
|
||||
}
|
||||
}
|
||||
58
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_sql_tst.java
Normal file
58
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_sql_tst.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_init_sql_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xob_init_sql_fxt fxt = new Xob_init_sql_fxt();
|
||||
@Test public void Basic() {
|
||||
// fxt.Init_fsys();
|
||||
// fxt.Test_run();
|
||||
}
|
||||
}
|
||||
class Xob_init_sql_fxt {
|
||||
public void Clear() {
|
||||
fxt.Ctor_fsys();
|
||||
app = fxt.Wiki().App();
|
||||
wiki = fxt.Wiki();
|
||||
} Db_mgr_fxt fxt = new Db_mgr_fxt();
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public void Init_fsys() {
|
||||
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
|
||||
Io_url[] fils = Io_mgr._.QueryDir_fils(wiki_dir);
|
||||
int len = fils.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_mgr._.DeleteFil(fils[i]);
|
||||
}
|
||||
// Io_mgr._.DeleteFil(wiki_dir.GenSubFil("en.wikipedia.org.sqlite3"));
|
||||
Io_mgr._.SaveFilStr(wiki_dir.GenSubFil("siteinfo.xml"), gplx.xowa.utls.upgrades.Upgrader_v00_02_01_tst.Str_siteinfo_xml);
|
||||
// Io_mgr._.DeleteDirDeep(Db_mgr_fxt.Test_root().GenSubDir("root", "wiki", "en.wikipedia.org"));
|
||||
// app.Fsys_mgr().Root_dir()
|
||||
// Db_mgr_fxt.Test_root()
|
||||
// Io_mgr._
|
||||
// mem/xowa/user/test_user/app/setup/wikixowa.core.sqlite3
|
||||
}
|
||||
public void Test_run() {
|
||||
// fxt.Init_db_sqlite(wiki.Fsys_mgr().Root_dir().GenSubFil("en.wikipedia.org.sqlite3"));
|
||||
app.Bldr().Cmd_mgr().Add_many(wiki, Xob_init_sql.KEY);
|
||||
app.Bldr().Run();
|
||||
// test database copied
|
||||
// test cfg values exists
|
||||
// test ns parsed
|
||||
}
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_txt.java
Normal file
28
400_xowa/src/gplx/xowa/bldrs/imports/Xob_init_txt.java
Normal 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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.xtns.wdatas.imports.*;
|
||||
public class Xob_init_txt extends Xob_init_base {
|
||||
public Xob_init_txt(Xob_bldr bldr, Xow_wiki wiki) {this.Ctor(bldr, wiki);}
|
||||
@Override public String Cmd_key() {return KEY;} public static final String KEY = "core.init";
|
||||
@Override public void Cmd_ini_wdata(Xob_bldr bldr, Xow_wiki wiki) {
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_wdata_qid_txt.KEY);
|
||||
bldr.Cmd_mgr().Add_cmd(wiki, Xob_wdata_pid_txt.KEY);
|
||||
}
|
||||
@Override public void Cmd_run_end(Xow_wiki wiki) {}
|
||||
}
|
||||
145
400_xowa/src/gplx/xowa/bldrs/imports/Xob_page_sql.java
Normal file
145
400_xowa/src/gplx/xowa/bldrs/imports/Xob_page_sql.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.ios.*;
|
||||
public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInvkAble {
|
||||
private Xop_redirect_mgr redirect_mgr; private Io_stream_zip_mgr zip_mgr; private byte data_storage_format;
|
||||
private Xodb_mgr_sql db_mgr; private Xodb_fsys_mgr fsys_mgr; private Db_provider page_provider; private Db_stmt page_stmt; private Xob_text_stmts_mgr text_stmts_mgr;
|
||||
private int page_count_all, page_count_main = 0; private int txn_commit_interval = 100000; // 100 k
|
||||
private DateAdp modified_latest = DateAdp_.MinValue;
|
||||
public Xob_page_sql(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Wkr_key() {return KEY;} public static final String KEY = "import.sql.page";
|
||||
public void Wkr_bgn(Xob_bldr bldr) {
|
||||
// init local variables
|
||||
Xoa_app app = wiki.App();
|
||||
app.Bldr().Parser().Trie_tab_del_(); // disable swapping 	 for \t
|
||||
zip_mgr = app.Zip_mgr();
|
||||
redirect_mgr = wiki.Redirect_mgr();
|
||||
data_storage_format = app.Setup_mgr().Dump_mgr().Data_storage_format();
|
||||
|
||||
// init db
|
||||
db_mgr = wiki.Db_mgr_as_sql();
|
||||
db_mgr.Data_storage_format_(data_storage_format);
|
||||
fsys_mgr = db_mgr.Fsys_mgr();
|
||||
page_provider = fsys_mgr.Page_provider();
|
||||
page_stmt = db_mgr.Tbl_page().Insert_stmt(page_provider);
|
||||
page_provider.Txn_mgr().Txn_bgn_if_none();
|
||||
text_stmts_mgr = new Xob_text_stmts_mgr(db_mgr, fsys_mgr);
|
||||
}
|
||||
public void Wkr_run(Xodb_page page) {
|
||||
int page_id = page.Id();
|
||||
DateAdp modified = page.Modified_on();
|
||||
if (modified.compareTo(modified_latest) == CompareAble_.More) modified_latest = modified;
|
||||
byte[] text = page.Text();
|
||||
int text_len = page.Text_len();
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
|
||||
boolean redirect = redirect_ttl != null;
|
||||
page.Type_redirect_(redirect);
|
||||
Xow_ns ns = page.Ns();
|
||||
int random_int = ns.Count() + 1;
|
||||
ns.Count_(random_int);
|
||||
text = zip_mgr.Zip(data_storage_format, text);
|
||||
int text_stmt_idx = text_stmts_mgr.Get_by_ns(ns.Bldr_file_idx(), text.length);
|
||||
Db_stmt text_stmt = text_stmts_mgr.Get_at(text_stmt_idx);
|
||||
try {
|
||||
db_mgr.Page_create(page_stmt, text_stmt, page_id, page.Ns_id(), page.Ttl_wo_ns(), redirect, modified, text, random_int, text_stmt_idx);
|
||||
}
|
||||
catch (Exception e) {
|
||||
usr_dlg.Warn_many("", "", "failed to insert page: id=~{0} ns=~{1} title=~{2} error=~{3}", page.Id(), page.Ns_id(), String_.new_utf8_(page.Ttl_wo_ns()), Err_.Message_gplx_brief(e));
|
||||
page_stmt.New(); // must new stmt variable, else java.sql.SQLException: "statement is not executing"
|
||||
text_stmt.New(); // must new stmt variable, else java.sql.SQLException: "statement is not executing"
|
||||
}
|
||||
++page_count_all;
|
||||
if (ns.Id_main() && !page.Type_redirect()) ++page_count_main;
|
||||
if (page_count_all % txn_commit_interval == 0) text_stmt.Provider().Txn_mgr().Txn_end_all_bgn_if_none();
|
||||
}
|
||||
public void Wkr_end() {
|
||||
page_provider.Txn_mgr().Txn_end_all();
|
||||
page_stmt.Rls();
|
||||
text_stmts_mgr.Rls();
|
||||
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
|
||||
db_mgr.Tbl_site_stats().Update(page_count_main, page_count_all, ns_mgr.Ns_file().Count()); // save page stats
|
||||
db_mgr.Tbl_xowa_ns().Insert(ns_mgr); // save ns
|
||||
db_mgr.Tbl_xowa_db().Commit_all(page_provider, db_mgr.Fsys_mgr().Ary()); // save dbs; note that dbs can be saved again later
|
||||
db_mgr.Tbl_xowa_cfg().Insert_str(Xodb_mgr_sql.Grp_wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file.Tid_core, Xodb_file.Tid_text), Xodb_file.Indexes_page_title, Xodb_file.Indexes_page_random);
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_txn_commit_interval_)) txn_commit_interval = m.ReadInt("v");
|
||||
return super.Invk(ctx, ikey, k, m);
|
||||
} private static final String Invk_txn_commit_interval_ = "txn_commit_interval_";
|
||||
public void Wkr_ini(Xob_bldr bldr) {}
|
||||
public void Wkr_print() {}
|
||||
}
|
||||
class Xob_text_stmts_mgr {
|
||||
public Xob_text_stmts_mgr(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = fsys_mgr;} private Xodb_mgr_sql db_mgr; Xodb_fsys_mgr fsys_mgr;
|
||||
public Db_stmt Get_at(int i) {return text_stmts[i];}
|
||||
public int Get_by_ns(int ns_file_idx, int text_len) {
|
||||
Xodb_file file = File_get(ns_file_idx, text_len);
|
||||
int stmt_idx = file.Id();
|
||||
Db_stmt stmt = null;
|
||||
if (stmt_idx < text_stmts_len) {
|
||||
stmt = text_stmts[stmt_idx];
|
||||
if (stmt != null) return stmt_idx;
|
||||
}
|
||||
stmt = db_mgr.Tbl_text().Insert_stmt(file.Provider());
|
||||
file.Provider().Txn_mgr().Txn_bgn_if_none(); // automatically start txn
|
||||
Add(stmt, stmt_idx);
|
||||
return stmt_idx;
|
||||
}
|
||||
public void Rls() {
|
||||
for (int i = 0; i < text_stmts_len; i++) {
|
||||
Db_stmt stmt = text_stmts[i];
|
||||
if (stmt != null) {
|
||||
stmt.Provider().Txn_mgr().Txn_end_all();
|
||||
stmt.Rls();
|
||||
}
|
||||
text_stmts[i] = null;
|
||||
}
|
||||
text_stmts = null;
|
||||
}
|
||||
Xodb_file File_get(int file_idx, int text_len) {
|
||||
if (file_idx == Xow_ns.Bldr_file_idx_heap) {
|
||||
file_idx = fsys_mgr.Tid_text_idx();
|
||||
Xodb_file file = fsys_mgr.Get_or_make(Xodb_file.Tid_text, file_idx);
|
||||
long file_len = file.File_len();
|
||||
long file_max = fsys_mgr.Tid_text_max();
|
||||
if (file_max != Xodb_fsys_mgr.Heap_max_infinite && (file_len + text_len > file_max)) { // file is "full"
|
||||
file.Provider().Txn_mgr().Txn_end_all(); // close txn
|
||||
file = fsys_mgr.Make(Xodb_file.Tid_text);
|
||||
file_idx = file.Id();
|
||||
fsys_mgr.Tid_text_idx_(file_idx);
|
||||
}
|
||||
file.File_len_add(text_len);
|
||||
return file;
|
||||
}
|
||||
else
|
||||
return fsys_mgr.Get_or_make(Xodb_file.Tid_text, file_idx);
|
||||
}
|
||||
private void Add(Db_stmt stmt, int stmt_idx) {
|
||||
int new_len = stmt_idx + 1;
|
||||
if (new_len > text_stmts_max) { // ary too small >>> expand
|
||||
text_stmts_max = new_len * 2;
|
||||
Db_stmt[] text_stmts_subs = new Db_stmt[text_stmts_max];
|
||||
Array_.CopyTo(text_stmts, 0, text_stmts_subs, 0, text_stmts_len);
|
||||
text_stmts = text_stmts_subs;
|
||||
}
|
||||
text_stmts[stmt_idx] = stmt;
|
||||
text_stmts_len = new_len;
|
||||
} Db_stmt[] text_stmts = new Db_stmt[0]; int text_stmts_len, text_stmts_max = 0;
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/bldrs/imports/Xob_page_sql_tst.java
Normal file
35
400_xowa/src/gplx/xowa/bldrs/imports/Xob_page_sql_tst.java
Normal 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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import org.junit.*; import gplx.dbs.*; import gplx.xowa.specials.search.*; import gplx.xowa.bldrs.imports.ctgs.*;
|
||||
public class Xob_page_sql_tst {
|
||||
@Before public void init() {fxt.Ctor_fsys();} Db_mgr_fxt fxt = new Db_mgr_fxt();
|
||||
@After public void term() {fxt.Rls();}
|
||||
@Test public void Basic() {
|
||||
fxt.Init_db_sqlite();
|
||||
fxt.doc_ary_
|
||||
( fxt.doc_(2, "2013-06-03 01:23", "A", "text_a")
|
||||
, fxt.doc_(1, "2013-06-03 12:34", "B", "#REDIRECT [[A]]")
|
||||
)
|
||||
.Exec_run(new Xob_page_sql(fxt.Bldr(), fxt.Wiki()))
|
||||
;
|
||||
fxt.Test_load_ttl(Xow_ns_.Id_main, "A", fxt.page_(2, "2013-06-03 01:23", false, 6));
|
||||
fxt.Test_load_page(Xow_ns_.Id_main, 2, "text_a");
|
||||
fxt.Test_load_ttl(Xow_ns_.Id_main, "B", fxt.page_(1, "2013-06-03 12:34", true, 15));
|
||||
}
|
||||
}
|
||||
90
400_xowa/src/gplx/xowa/bldrs/imports/Xob_page_txt.java
Normal file
90
400_xowa/src/gplx/xowa/bldrs/imports/Xob_page_txt.java
Normal 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.bldrs.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.ios.*;
|
||||
public class Xob_page_txt extends Xob_itm_dump_base implements Xobd_wkr, GfoInvkAble {
|
||||
public Xob_page_txt(Xob_bldr bldr, Xow_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Wkr_key() {return KEY;} public static final String KEY = "core.make_page";
|
||||
public void Wkr_ini(Xob_bldr bldr) {}
|
||||
public void Wkr_bgn(Xob_bldr bldr) {
|
||||
redirect_mgr = wiki.Redirect_mgr(); page_storage_type = wiki.App().Setup_mgr().Dump_mgr().Data_storage_format();
|
||||
fsys_mgr = wiki.Fsys_mgr();
|
||||
make_dir = fsys_mgr.Ns_dir();
|
||||
if (Io_mgr._.QueryDir_args(make_dir).DirOnly_().ExecAsUrlAry().length > 0) throw bldr.Usr_dlg().Fail_many("xowa.bldr.itm", "dir_empty", "dir_must_be_empty: ~{0}", make_dir.Raw());
|
||||
this.Init_dump(KEY, make_dir);
|
||||
this.data_rpt_typ = stat_mgr.GetOrNew(Xow_dir_info_.Tid_page);
|
||||
ttl_wtr_mgr = new Xob_tmp_wtr_mgr(new Xob_tmp_wtr_wkr__ttl(temp_dir, dump_fil_len));
|
||||
} private Xow_fsys_mgr fsys_mgr; Xop_redirect_mgr redirect_mgr;
|
||||
int page_file_len = 512 * Io_mgr.Len_kb, title_file_len = 64 * Io_mgr.Len_kb; Xob_tmp_wtr_mgr ttl_wtr_mgr;
|
||||
Xob_xdat_file_wtr[] page_wtr_regy = new Xob_xdat_file_wtr[Ns_ordinal_max]; static final int Ns_ordinal_max = Xow_ns_mgr_.Ordinal_max; // ASSUME: no more than 128 ns in a wiki
|
||||
Xob_stat_type data_rpt_typ; Xob_stat_mgr stat_mgr = new Xob_stat_mgr(); byte page_storage_type;
|
||||
public void Wkr_run(Xodb_page page) {
|
||||
int id = page.Id(); byte[] ttl_wo_ns = page.Ttl_wo_ns(), text = page.Text(); int ttl_len = ttl_wo_ns.length, text_len = text.length; Xow_ns ns = page.Ns();
|
||||
boolean redirect = redirect_mgr.Is_redirect(text, text_len);
|
||||
page.Type_redirect_(redirect);
|
||||
|
||||
// page: EX: \t123\t2012-06-09\ttitle\ttext\n; NOTE: 512k * ~20 ns = 10 MB max memory; no need for intermediary flushing
|
||||
Xob_xdat_file_wtr page_wtr = Page_wtr_get(ns);
|
||||
if (page_wtr.FlushNeeded(Xodb_page_.Txt_page_len__fixed + ttl_len + text_len)) page_wtr.Flush(bldr.Usr_dlg());
|
||||
Xodb_page_.Txt_page_save(page_wtr.Bfr(), id, page.Modified_on(), ttl_wo_ns, text, false);
|
||||
page_wtr.Add_idx(Byte_ascii.NewLine);
|
||||
|
||||
// idx: EX: 00100|aB64|Ttl;
|
||||
Xob_tmp_wtr ttl_wtr = ttl_wtr_mgr.Get_or_new(ns);
|
||||
int file_idx = page_wtr.Fil_idx(), row_idx = page_wtr.Idx_pos() - ListAdp_.LastIdxOffset;
|
||||
page.Db_file_idx_(file_idx).Db_row_idx_(row_idx);
|
||||
if (ttl_wtr.FlushNeeded(Xodb_page_.Txt_ttl_len__fixed + ttl_len)) ttl_wtr.Flush(bldr.Usr_dlg());
|
||||
Xodb_page_.Txt_ttl_save(ttl_wtr.Bfr(), id, file_idx, row_idx, redirect, text_len, ttl_wo_ns);
|
||||
}
|
||||
public void Wkr_end() {
|
||||
Flush_page(page_wtr_regy);
|
||||
ttl_wtr_mgr.Flush_all(bldr.Usr_dlg());
|
||||
Xobdc_merger.Ns(bldr.Usr_dlg(), ttl_wtr_mgr.Regy(), Xow_dir_info_.Name_title, temp_dir, make_dir, sort_mem_len, Io_line_rdr_key_gen_.last_pipe, new Io_sort_cmd_ns(bldr.Usr_dlg()));
|
||||
ttl_wtr_mgr.Rls_all();
|
||||
if (delete_temp) Io_mgr._.DeleteDirDeep(temp_dir);
|
||||
}
|
||||
public void Wkr_print() {bldr.Usr_dlg().Note_many(GRP_KEY, "print", "~{0}", stat_mgr.Print(wiki.Ns_mgr()));}
|
||||
Xob_xdat_file_wtr Page_wtr_get(Xow_ns ns) {
|
||||
Xob_xdat_file_wtr rv = page_wtr_regy[ns.Ord()];
|
||||
if (rv == null) {
|
||||
rv = Xob_xdat_file_wtr.new_by_tid_(page_file_len, fsys_mgr.Ns_dir().GenSubDir_nest(ns.Num_str()), Xow_dir_info_.Tid_page, page_storage_type).Ns_ord_idx_(ns.Ord());
|
||||
page_wtr_regy[ns.Ord()] = rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private void Flush_page(Xob_xdat_file_wtr[] regy) {
|
||||
for (int i = 0; i < Ns_ordinal_max; i++) {
|
||||
Xob_xdat_file_wtr wtr = regy[i];
|
||||
if (wtr != null) {
|
||||
Xow_ns ns_itm = wiki.Ns_mgr().Ords_get_at(wtr.Ns_ord_idx());
|
||||
Xob_stat_itm datRptItm = data_rpt_typ.GetOrNew(ns_itm.Name_str());
|
||||
datRptItm.Tally(wtr.Fil_len(), wtr.Fil_idx());
|
||||
wtr.Flush(bldr.Usr_dlg());
|
||||
wtr.Rls();
|
||||
regy[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_page_file_len_)) page_file_len = gplx.ios.Io_size_.Load_int_(m);
|
||||
else if (ctx.Match(k, Invk_title_file_len_)) title_file_len = gplx.ios.Io_size_.Load_int_(m);
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
return this;
|
||||
} private static final String Invk_page_file_len_ = "page_file_len_", Invk_title_file_len_ = "title_file_len_";
|
||||
static final String GRP_KEY = "xowa.bldr.make_page";
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user