mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.brys.*; import gplx.core.ios.*; import gplx.core.net.*; import gplx.core.threads.*;
|
||||
import gplx.langs.jsons.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.site_cfgs.*; import gplx.xowa.apps.metas.*; import gplx.xowa.apps.apis.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.guis.cbks.*; import gplx.xowa.guis.tabs.*;
|
||||
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.js.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.xwikis.parsers.*; import gplx.xowa.wikis.xwikis.sitelinks.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.bldrs.wms.*;
|
||||
import gplx.xowa.users.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.addons.*; import gplx.xowa.specials.mgrs.*;
|
||||
import gplx.xowa.parsers.amps.*;
|
||||
import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.apps.miscs.*;
|
||||
public interface Xoa_app extends Gfo_invk {
|
||||
boolean Tid_is_edit();
|
||||
Xoa_app_mode Mode();
|
||||
Xoapi_root Api_root();
|
||||
Xocfg_mgr Cfg();
|
||||
Xoa_fsys_mgr Fsys_mgr();
|
||||
Xoa_wiki_mgr Wiki_mgri();
|
||||
Xoa_lang_mgr Lang_mgr();
|
||||
Xoa_gfs_mgr Gfs_mgr();
|
||||
Xof_cache_mgr File__cache_mgr();
|
||||
Xof_img_mgr File__img_mgr();
|
||||
Io_download_fmt File__download_fmt();
|
||||
Xoh_href_parser Html__href_parser();
|
||||
Xoa_css_extractor Html__css_installer();
|
||||
Xoh_bridge_mgr Html__bridge_mgr();
|
||||
Xog_cbk_mgr Gui__cbk_mgr();
|
||||
Xog_tab_mgr Gui__tab_mgr();
|
||||
Xou_user User();
|
||||
Xowmf_mgr Wmf_mgr();
|
||||
boolean Xwiki_mgr__missing(byte[] domain);
|
||||
Xoa_sitelink_mgr Xwiki_mgr__sitelink_mgr();
|
||||
Xow_xwiki_itm_parser Xwiki_mgr__itm_parser();
|
||||
boolean Bldr__running(); void Bldr__running_(boolean v);
|
||||
Gfo_usr_dlg Usr_dlg();
|
||||
Json_parser Utl__json_parser();
|
||||
Gfo_inet_conn Utl__inet_conn();
|
||||
Xoa_meta_mgr Dbmeta_mgr();
|
||||
Xoa_site_cfg_mgr Site_cfg_mgr();
|
||||
Xoax_addon_mgr Addon_mgr();
|
||||
Xob_bldr Bldr();
|
||||
Xoa_special_regy Special_regy();
|
||||
Gfo_thread_mgr Thread_mgr();
|
||||
Xop_amp_mgr Parser_amp_mgr();
|
||||
Xoa_misc_mgr Misc_mgr();
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.log_msgs.*;
|
||||
import gplx.xowa.guis.views.boots.*; import gplx.xowa.apps.boots.*;
|
||||
public class Xoa_app_ {
|
||||
public static void Run(String... args) {
|
||||
Xoa_cmd_arg_mgr arg_mgr = Xoa_cmd_arg_mgr.new_();
|
||||
try {
|
||||
Xoa_boot_mgr boot_mgr = new Xoa_boot_mgr();
|
||||
boot_mgr.Run(args, arg_mgr);
|
||||
} catch (Error e) {
|
||||
if (arg_mgr.App_type().Tid_is_gui())
|
||||
Xog_error_win.Run(Err_.Message_lang(e), Err_.Trace_lang(e));
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final int Version_id = 538;
|
||||
public static final String Version = "4.5.17.1710";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Build_date_fmt = "yyyy-MM-dd HH:mm:ss";
|
||||
public static String Op_sys_str;
|
||||
public static String User_agent = "";
|
||||
|
||||
public static Gfo_usr_dlg Usr_dlg() {return usr_dlg;} public static void Usr_dlg_(Gfo_usr_dlg v) {usr_dlg = v;} private static Gfo_usr_dlg usr_dlg;
|
||||
public static Gfo_usr_dlg New__usr_dlg__console() {
|
||||
Gfo_usr_dlg rv = new Gfo_usr_dlg_base(new Gfo_usr_dlg__log_base(), Gfo_usr_dlg__gui_.Console);
|
||||
rv.Log_wkr().Queue_enabled_(true);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static final Gfo_msg_grp Nde = Gfo_msg_grp_.prj_(Name);
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.gfui.kits.core.*;
|
||||
import gplx.langs.gfs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.files.exts.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.guis.tabs.*;
|
||||
public class Xoa_app_fxt {
|
||||
public static Xoae_app Make__app__edit() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
return Make__app__edit("linux", Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public static Xoae_app Make__app__edit(String op_sys, Io_url root_dir) {
|
||||
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
|
||||
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
|
||||
Xoae_app app = new Xoae_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_cmd, root_dir, root_dir.GenSubDir("wiki"), root_dir.GenSubDir("file"), user_dir, root_dir.GenSubDir_nest("user", "anonymous", "wiki"), op_sys);
|
||||
GfsCore.Instance.Clear(); // NOTE: must clear
|
||||
GfsCore.Instance.AddCmd(app, Xoae_app.Invk_app); // NOTE: must add app to GfsCore; app.Gfs_mgr() always adds current app to GfsCore; note this causes old test to leave behind GfsCore for new test
|
||||
GfsCore.Instance.AddCmd(app, Xoae_app.Invk_xowa); // add alias for app; DATE:2014-06-09
|
||||
return app;
|
||||
}
|
||||
public static Xoav_app Make__app__view() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
return Make__app__view("linux", Io_url_.mem_dir_("mem/xowa/"));
|
||||
}
|
||||
public static Xoav_app Make__app__view(String op_sys, Io_url root_dir) {
|
||||
Io_url user_dir = root_dir.GenSubDir_nest("user", "test_user");
|
||||
Gfo_usr_dlg__log_base.Instance.Log_dir_(user_dir.GenSubDir_nest("tmp", "current"));
|
||||
Xoav_app rv = new Xoav_app(Gfo_usr_dlg_.Test(), Xoa_app_mode.Itm_gui, Xog_tab_mgr_.New_mem(), op_sys, root_dir, root_dir.GenSubDir("file"), root_dir.GenSubDir("css"), root_dir);
|
||||
rv.Init_by_app(user_dir);
|
||||
rv.Wiki_mgr().Add(new Xowv_wiki(rv, Xow_domain_itm_.Bry__home, user_dir));
|
||||
return rv;
|
||||
}
|
||||
public static Xowv_wiki Make__wiki__view(Xoa_app app) {return Make__wiki__view(app, "en.wikipedia.org");}
|
||||
public static Xowv_wiki Make__wiki__view(Xoa_app app, String domain_str) {
|
||||
byte[] domain_bry = Bry_.new_u8(domain_str);
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(domain_str);
|
||||
Xowv_wiki rv = new Xowv_wiki((Xoav_app)app, domain_bry, wiki_dir);
|
||||
((Xoav_wiki_mgr)app.Wiki_mgri()).Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public static Xowe_wiki Make__wiki__edit__nonwmf(Xoae_app app, String key) {
|
||||
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true);
|
||||
Xol_lang_itm_.Lang_init(lang);
|
||||
return Make__wiki__edit(app, key, lang);
|
||||
}
|
||||
public static Xowe_wiki Make__wiki__edit(Xoae_app app) {return Make__wiki__edit(app, "en.wikipedia.org");}
|
||||
public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key) {return Make__wiki__edit(app, key, app.Lang_mgr().Lang_en());}
|
||||
public static Xowe_wiki Make__wiki__edit(Xoae_app app, String key, Xol_lang_itm lang) {
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(key);
|
||||
Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_itm_.parse(Bry_.new_u8(key)), wiki_dir);
|
||||
rv.File_mgr().Dbmeta_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_.Tid__main).Subpages_enabled_(true);
|
||||
app.Wiki_mgr().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public static void repo_(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
app.File_mgr().Repo_mgr().Set("src:c", "mem/wiki/repo/src/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:c", "mem/wiki/repo/trg/", "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:c"), Bry_.new_a7("trg:c"));
|
||||
}
|
||||
public static void repo2_(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/xowa/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/xowa/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:comm"), Bry_.new_a7("trg:comm"));
|
||||
}
|
||||
public static void Init_gui(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.Gui_mgr().Browser_win().Init_by_kit(Mem_kit.Instance);
|
||||
app.Gui_mgr().Browser_win().Tab_mgr().Tabs_new_init(wiki, Xoae_page.Empty);
|
||||
}
|
||||
public static Xob_bldr bldr_(Xoae_app app) {
|
||||
Xob_bldr rv = new Xob_bldr(app);
|
||||
rv.Sort_mem_len_(Io_mgr.Len_kb).Dump_fil_len_(Io_mgr.Len_kb).Make_fil_len_(Io_mgr.Len_kb);
|
||||
return rv;
|
||||
}
|
||||
public static final Io_url Root_dir = Op_sys.Cur().Tid_is_lnx() ? Io_url_.new_dir_("/xowa/") : Io_url_.new_dir_("C:\\xowa\\");
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.redirects.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*; import gplx.xowa.wikis.pages.wtxts.*;
|
||||
public interface Xoa_page {
|
||||
Xow_wiki Wiki();
|
||||
Guid_adp Page_guid();
|
||||
Xoa_url Url(); byte[] Url_bry_safe();
|
||||
Xoa_ttl Ttl();
|
||||
Xopg_db_data Db();
|
||||
Xopg_redirect_mgr Redirect_trail();
|
||||
Xopg_html_data Html_data();
|
||||
Xopg_hdump_data Hdump_mgr();
|
||||
Xopg_wtxt_data Wtxt();
|
||||
Xol_lang_itm Lang();
|
||||
|
||||
Xoa_page__commons_mgr Commons_mgr();
|
||||
boolean Xtn__timeline_exists();
|
||||
boolean Xtn__gallery_exists();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_page_ {
|
||||
public static final byte Edit_mode_create = 1, Edit_mode_update = 2;
|
||||
public static final String Main_page_str = "Main_Page";
|
||||
public static final byte[] Main_page_bry = Bry_.new_a7(Main_page_str); // NOTE; may not work for non-english wikis
|
||||
public static final byte[] Main_page_bry_empty = Bry_.Empty;
|
||||
public static final int Page_len_max = 2048 * Io_mgr.Len_kb; // REF.MW: DefaultSettings.php; $wgMaxArticleSize = 2048;
|
||||
public static byte[] Url_bry_safe(Xoa_url url, Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
byte[] rv = url == null ? Bry_.Empty : url.To_bry(Bool_.Y, Bool_.Y);
|
||||
if (Bry_.Len_eq_0(rv))
|
||||
rv = Bry_.Add(wiki == null ? Bry_.Empty : wiki.Domain_bry(), gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, ttl == null ? Bry_.Empty : ttl.Full_db());
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.core.net.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xoa_test_ {
|
||||
public static boolean Db_skip() {return Bool_.N;}
|
||||
public static boolean Db_is_mem_dflt() {return Bool_.Y;}
|
||||
public static void Db_init(Io_url sqlite_url) {Db_init(Db_is_mem_dflt(), sqlite_url);}
|
||||
public static void Init__db__edit(Xowe_wiki wiki) {
|
||||
Db__init__mem();
|
||||
wiki.Db_mgr_create_as_sql();
|
||||
wiki.Data__core_mgr().Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test);
|
||||
}
|
||||
public static void Init__db__view(gplx.xowa.wikis.Xowv_wiki wiki) {
|
||||
Db__init__mem();
|
||||
wiki.Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test);
|
||||
// wiki.Data__core_mgr().Init_by_make(Xowd_core_db_props.Test, Xob_info_session.Test);
|
||||
}
|
||||
public static void Db__init__mem() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public static void Db_init(boolean db_is_mem, Io_url sqlite_url) {
|
||||
if (db_is_mem)
|
||||
Db__init__mem();
|
||||
else {
|
||||
Io_mgr.Instance.DeleteDirDeep(sqlite_url);
|
||||
Db_conn_bldr.Instance.Reg_default_sqlite();
|
||||
}
|
||||
}
|
||||
public static void Inet__init() {
|
||||
Gfo_inet_conn_.new_prototype_(Gfo_inet_conn_.Tid__mem__hash);
|
||||
}
|
||||
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");}
|
||||
}
|
||||
@@ -1,495 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.entitys.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.miscs.*;
|
||||
import gplx.xowa.apps.utls.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.langs.cases.*;
|
||||
/* TODO.XO
|
||||
Is_known
|
||||
Create_fragment_target
|
||||
*/
|
||||
public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.MW: Ttl.php|secureAndSplit;
|
||||
private int wik_bgn = -1, ns_bgn = -1, page_bgn = 0, leaf_bgn = -1, anch_bgn = -1, root_bgn = -1;
|
||||
private byte[] tors_txt;
|
||||
private Xoa_ttl() {}
|
||||
public Xow_ns Ns() {return ns;} private Xow_ns ns;
|
||||
public boolean ForceLiteralLink() {return forceLiteralLink;} private boolean forceLiteralLink;
|
||||
// NOTE: in procs below, all -1 are used to skip previous delimiters; they will only occur for end_pos arguments
|
||||
public boolean Eq_page_db(Xoa_ttl comp) {if (comp == null) return false; return Bry_.Eq(this.Page_db(), comp.Page_db());} // check page is same; ignores anchor and xwiki
|
||||
public boolean Eq_full_db(Xoa_ttl comp) {if (comp == null) return false; return Bry_.Eq(this.Full_db(), comp.Full_db());} // check page is same; ignores anchor and xwiki
|
||||
public byte[] Raw() {return raw;} private byte[] raw = Bry_.Empty;
|
||||
public byte[] Wik_txt() {return wik_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, wik_bgn, ns_bgn == -1 ? page_bgn - 1 : ns_bgn - 1);}
|
||||
public Xow_xwiki_itm Wik_itm() {return wik_itm;} private Xow_xwiki_itm wik_itm;
|
||||
public byte[] Full_txt_w_ttl_case() {return Xoa_ttl.Replace_unders(Full_db());}
|
||||
public byte[] Full_txt_by_orig() {
|
||||
int bgn = wik_bgn == -1 ? 0 : ns_bgn == -1 ? page_bgn : ns_bgn;
|
||||
int end = full_txt.length;
|
||||
if (anch_bgn != -1) end = anch_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Full_txt_raw() {return full_txt;} private byte[] full_txt = Bry_.Empty;
|
||||
public byte[] Full_db_wo_xwiki() {
|
||||
byte[] rv = Bry_.Mid(full_txt, wik_bgn == -1 ? 0 : ns_bgn == -1 ? page_bgn - 1 : ns_bgn - 1, full_txt.length);
|
||||
Bry_.Replace_reuse(rv, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
return rv;
|
||||
}
|
||||
public byte[] Page_txt_w_anchor() {return Bry_.Mid(full_txt, page_bgn, qarg_bgn == -1 ? full_txt.length : qarg_bgn - 1);}
|
||||
public byte[] Page_txt() {return Bry_.Mid(full_txt, page_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
public byte[] Page_db() {
|
||||
byte[] rv = this.Page_txt();
|
||||
Bry_.Replace_reuse(rv, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
return rv;
|
||||
}
|
||||
public String Page_db_as_str() {return String_.new_u8(Page_db());}
|
||||
public byte[] Page_url_w_anch() {
|
||||
synchronized (href_encoder) { // LOCK:static-obj
|
||||
return href_encoder.Encode(Bry_.Mid(full_txt, page_bgn, qarg_bgn == -1 ? full_txt.length : qarg_bgn - 1));
|
||||
}
|
||||
}
|
||||
public int Leaf_bgn() {return leaf_bgn;}
|
||||
public byte[] Base_txt() {return leaf_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, page_bgn, leaf_bgn - 1);}
|
||||
public byte[] Leaf_txt() {return leaf_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, leaf_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
public int Wik_bgn() {return wik_bgn;}
|
||||
public int Anch_bgn() {return anch_bgn;} // NOTE: anch_bgn is not correct when page has trailing ws; EX: [[A #b]] should have anch_bgn of 3 (1st char after #), but instead it is 2
|
||||
public byte[] Anch_txt() {return anch_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, anch_bgn, full_txt.length);}
|
||||
public byte[] Talk_txt() {return ns.Id_is_talk() ? Full_txt_w_ttl_case() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Subj_txt() {return ns.Id_is_subj() ? Full_txt_w_ttl_case() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Full_url() {
|
||||
synchronized (href_encoder) { // LOCK:static-obj
|
||||
return href_encoder.Encode(full_txt);
|
||||
}
|
||||
}
|
||||
public String Full_db_as_str() {return String_.new_u8(Full_db());}
|
||||
public byte[] Full_db() {return ns.Gen_ttl(this.Page_db());}
|
||||
public byte[] Full_db_w_anch() {return Replace_spaces(full_txt);}
|
||||
public byte[] Page_url() {
|
||||
synchronized (url_encoder) { // LOCK:static-obj
|
||||
return url_encoder.Encode(this.Page_txt());
|
||||
}
|
||||
}
|
||||
public byte[] Leaf_url() {
|
||||
synchronized (url_encoder) { // LOCK:static-obj
|
||||
return url_encoder.Encode(this.Leaf_txt());
|
||||
}
|
||||
}
|
||||
public byte[] Base_url() {
|
||||
synchronized (url_encoder) { // LOCK:static-obj
|
||||
return url_encoder.Encode(this.Base_txt());
|
||||
}
|
||||
}
|
||||
public byte[] Root_txt() {return root_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, page_bgn, root_bgn - 1);}
|
||||
public byte[] Rest_txt() {return root_bgn == -1 ? Page_txt() : Bry_.Mid(full_txt, root_bgn, anch_bgn == -1 ? full_txt.length : anch_bgn - 1);}
|
||||
public byte[] Talk_url() {
|
||||
synchronized (url_encoder) { // LOCK:static-obj
|
||||
return url_encoder.Encode(this.Talk_txt());
|
||||
}
|
||||
}
|
||||
public byte[] Subj_url() {
|
||||
synchronized (url_encoder) { // LOCK:static-obj
|
||||
return url_encoder.Encode(this.Subj_txt());
|
||||
}
|
||||
}
|
||||
public int Qarg_bgn() {return qarg_bgn;} private int qarg_bgn = -1;
|
||||
public byte[] Qarg_txt() {return this.Qarg_bgn() == -1 ? null : Bry_.Mid(full_txt, this.Qarg_bgn(), full_txt.length);}
|
||||
public byte[] Base_txt_wo_qarg() {
|
||||
int bgn = page_bgn;
|
||||
int end = full_txt.length;
|
||||
if (leaf_bgn != -1) end = leaf_bgn - 1;
|
||||
else if (qarg_bgn != -1) end = qarg_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Leaf_txt_wo_qarg() {
|
||||
int bgn = leaf_bgn == -1 ? 0 : leaf_bgn;
|
||||
int end = full_txt.length;
|
||||
if (anch_bgn != -1) end = anch_bgn - 1;
|
||||
else if (qarg_bgn != -1) end = qarg_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Full_db_wo_qarg() {return Replace_spaces(Full_txt_wo_qarg());}
|
||||
public byte[] Full_txt_wo_qarg() {
|
||||
int bgn = wik_bgn == -1 ? 0 : ns_bgn == -1 ? page_bgn : ns_bgn;
|
||||
int end = full_txt.length;
|
||||
if (anch_bgn != -1) end = anch_bgn - 1;
|
||||
else if (qarg_bgn != -1) end = qarg_bgn - 1;
|
||||
return Bry_.Mid(full_txt, bgn, end);
|
||||
}
|
||||
public byte[] Page_txt_wo_qargs() { // assume that no Special page has non-ascii characters
|
||||
int full_txt_len = full_txt.length;
|
||||
int ques_pos = Bry_find_.Find_bwd(full_txt, Byte_ascii.Question, full_txt_len, page_bgn);
|
||||
return Bry_.Mid(full_txt, page_bgn, ques_pos == Bry_find_.Not_found ? full_txt_len : ques_pos);
|
||||
}
|
||||
|
||||
public byte[] Get_text() {return Page_txt();}
|
||||
public byte[] Get_prefixed_text() {return Full_txt_wo_qarg();}
|
||||
public byte[] Get_prefixed_db_key() {return Full_db();}
|
||||
public boolean Has_fragment() {return anch_bgn != -1;}
|
||||
public byte[] Get_fragment() {return Anch_txt();}
|
||||
public byte[] Get_link_url(Object qry_mgr, boolean query2, boolean proto) {
|
||||
// if ( $this->isExternal() || $proto !== false ) {
|
||||
// $ret = $this->getFullURL( $query, $query2, $proto );
|
||||
// }
|
||||
// else if ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
|
||||
// $ret = $this->getFragmentForURL();
|
||||
// }
|
||||
// else {
|
||||
// $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
|
||||
// }
|
||||
return Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, this.Full_db_w_anch());
|
||||
}
|
||||
public boolean Is_always_known() {
|
||||
// $isKnown = null;
|
||||
|
||||
/**
|
||||
* Allows overriding default behavior for determining if a page exists.
|
||||
* If $isKnown is kept as null, regular checks happen. If it's
|
||||
* a boolean, this value is returned by the isKnown method.
|
||||
*
|
||||
* @since 1.20
|
||||
*
|
||||
* @param Title $title
|
||||
* @param boolean|null $isKnown
|
||||
*/
|
||||
// Hooks::run( 'TitleIsAlwaysKnown', [ $this, &$isKnown ] );
|
||||
//
|
||||
// if ( !is_null( $isKnown ) ) {
|
||||
// return $isKnown;
|
||||
// }
|
||||
//
|
||||
// if ( $this->isExternal() ) {
|
||||
// return true; // any interwiki link might be viewable, for all we know
|
||||
// }
|
||||
//
|
||||
// switch ( $this->mNamespace ) {
|
||||
// case NS_MEDIA:
|
||||
// case NS_FILE:
|
||||
// // file exists, possibly in a foreign repo
|
||||
// return (boolean)wfFindFile( $this );
|
||||
// case NS_SPECIAL:
|
||||
// // valid special page
|
||||
// return SpecialPageFactory::exists( $this->getDBkey() );
|
||||
// case NS_MAIN:
|
||||
// // selflink, possibly with fragment
|
||||
// return $this->mDbkeyform == '';
|
||||
// case NS_MEDIAWIKI:
|
||||
// // known system message
|
||||
// return $this->hasSourceText() !== false;
|
||||
// default:
|
||||
// return false;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
public boolean Is_known() {
|
||||
return true;
|
||||
}
|
||||
public Xoa_ttl Create_fragment_target() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean Is_external() {return this.wik_bgn != -1;}
|
||||
|
||||
public static final byte Subpage_spr = Byte_ascii.Slash; // EX: A/B/C
|
||||
public static final Xoa_ttl Null = null;
|
||||
|
||||
private static final int Char__bidi = 1, Char__ws = 2;
|
||||
private static final Btrie_slim_mgr char_trie = Btrie_slim_mgr.cs()
|
||||
.Add_many_int(Char__bidi , Bry_.New_by_ints(0xE2, 0x80, 0x8E), Bry_.New_by_ints(0xE2, 0x80, 0x8F), Bry_.New_by_ints(0xE2, 0x80, 0xAA), Bry_.New_by_ints(0xE2, 0x80, 0xAB), Bry_.New_by_ints(0xE2, 0x80, 0xAC), Bry_.New_by_ints(0xE2, 0x80, 0xAD), Bry_.New_by_ints(0xE2, 0x80, 0xAE))
|
||||
.Add_many_int(Char__ws , "\u00A0", "\u1680", "\u180E", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u2028", "\u2029", "\u202F", "\u205F", "\u3000");
|
||||
|
||||
private final static Gfo_url_encoder href_encoder = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make();
|
||||
private final static Xoa_url_encoder url_encoder = new Xoa_url_encoder();
|
||||
|
||||
public static byte[] Replace_spaces(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Space, Byte_ascii.Underline);}
|
||||
public static byte[] Replace_unders(byte[] raw) {return Replace_unders(raw, 0, raw.length);}
|
||||
public static byte[] Replace_unders(byte[] raw, int bgn, int end) {return Bry_.Replace(raw, bgn, end, Byte_ascii.Underline, Byte_ascii.Space);}
|
||||
|
||||
public static Xoa_ttl Parse(Xow_wiki wiki, byte[] raw) {return Parse(wiki, raw, 0, raw.length);}
|
||||
public static Xoa_ttl Parse(Xow_wiki wiki, int ns_id, byte[] ttl) {
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
byte[] raw = Bry_.Add(ns.Name_db_w_colon(), ttl);
|
||||
return Parse(wiki, raw, 0, raw.length);
|
||||
}
|
||||
public static Xoa_ttl Parse(Xow_wiki wiki, byte[] src, int bgn, int end){return Parse(wiki.App().Parser_amp_mgr(), wiki.Lang().Case_mgr(), wiki.Xwiki_mgr(), wiki.Ns_mgr(), src, bgn, end);}
|
||||
public static Xoa_ttl Parse(Xop_amp_mgr amp_mgr, Xol_case_mgr case_mgr, Xow_xwiki_mgr xwiki_mgr, Xow_ns_mgr ns_mgr, byte[] src, int bgn, int end) {
|
||||
Xoa_ttl rv = new Xoa_ttl();
|
||||
Bry_bfr bfr = Bry_bfr_.Get(); // changed from bry_mkr.Get_b512(); DATE:2016-07-06
|
||||
try {return rv.Parse(bfr, amp_mgr, case_mgr, xwiki_mgr, ns_mgr, src, bgn, end) ? rv : null;}
|
||||
finally {bfr.Mkr_rls();}
|
||||
}
|
||||
private boolean Parse(Bry_bfr bfr, Xop_amp_mgr amp_mgr, Xol_case_mgr case_mgr, Xow_xwiki_mgr xwiki_mgr, Xow_ns_mgr ns_mgr, byte[] src, int bgn, int end) {
|
||||
/* This proc will
|
||||
- identify all parts: Wiki, Namespace, Base/Leaf, Anchor; it will also identify Subject/Talk ns
|
||||
- trim whitespace around part delimiters; EX: "Help : Test" --> "Help:Test"; note that it will trim only if the ns part is real; EX: "Helpx : Test" is unchanged
|
||||
- replace multiple whitespaces with 1; EX: "Many ws" --> "Many ws"
|
||||
- capitalize the first letter of the page title
|
||||
note: a byte[] is needed b/c proc does collapsing and casing
|
||||
FUTURE:
|
||||
- "/", "a/" (should be page); "#" (not a page)
|
||||
- Talk:Help:a disallowed; Category talk:Help:a allowed
|
||||
- remove invalid characters $rxTc
|
||||
- forbid ./ /.
|
||||
- forbid ~~~
|
||||
- handle ip address urls for User and User talk
|
||||
*/
|
||||
Gfo_url_encoder anchor_encoder = null;
|
||||
Bry_bfr anchor_encoder_bfr = null;
|
||||
bfr.Clear();
|
||||
if (end - bgn == 0) return false;
|
||||
this.raw = src;
|
||||
ns = ns_mgr.Ns_main();
|
||||
boolean add_ws = false, ltr_bgn_reset = false;
|
||||
int ltr_bgn = -1, txt_bb_len = 0, colon_count = 0;
|
||||
Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie(); Btrie_rv trv = null;
|
||||
byte[] b_ary = null;
|
||||
int cur = bgn;
|
||||
int match_pos = -1;
|
||||
while (cur != end) {
|
||||
byte b = src[cur];
|
||||
switch (b) {
|
||||
case Byte_ascii.Colon:
|
||||
if (cur == bgn) { // initial colon; flag; note that " :" is not handled; note that colon_count is not incremented
|
||||
forceLiteralLink = true;
|
||||
++cur;
|
||||
if (cur < end && src[cur] == Byte_ascii.Colon)
|
||||
++cur;
|
||||
continue; // do not add to bfr
|
||||
}
|
||||
else {
|
||||
if (ltr_bgn == -1) {// no ltrs seen; treat as literal; occurs for ::fr:wikt:test and fr::Help:test
|
||||
++colon_count;
|
||||
break;
|
||||
}
|
||||
boolean part_found = false;
|
||||
if (colon_count == 0) {// 1st colon;
|
||||
Object o = ns_mgr.Names_get_or_null(bfr.Bfr(), ltr_bgn, txt_bb_len);
|
||||
if (o == null) { // not ns; try alias
|
||||
wik_itm = xwiki_mgr.Get_by_mid(bfr.Bfr(), ltr_bgn, txt_bb_len); // check if wiki; note: wiki is not possible for other colons
|
||||
if (wik_itm != null) {
|
||||
wik_bgn = 0; // wik_bgn can only start at 0
|
||||
part_found = true;
|
||||
anch_bgn = -1; // NOTE: do not allow anchors to begin before wiki_itm; breaks Full_txt for [[:#batch:Main Page]]; DATE:20130102
|
||||
}
|
||||
}
|
||||
else {
|
||||
ns = (Xow_ns)o;
|
||||
byte[] ns_name = ns.Name_ui();
|
||||
int ns_name_len = ns_name.length;
|
||||
int tmp_bfr_end = bfr.Len();
|
||||
if (!Bry_.Eq(bfr.Bfr(), ltr_bgn, tmp_bfr_end, ns_name) && ns_name_len == tmp_bfr_end - ltr_bgn) { // if (a) ns_name != bfr_txt (b) both are same length; note that (b) should not happen, but want to safeguard against mismatched arrays
|
||||
Bry_.Set(bfr.Bfr(), ltr_bgn, tmp_bfr_end, ns_name);
|
||||
}
|
||||
ns_bgn = ltr_bgn;
|
||||
part_found = true;
|
||||
}
|
||||
}
|
||||
if (part_found) {
|
||||
page_bgn = txt_bb_len + 1; // anticipate page_bgn;
|
||||
add_ws = false; // if there was an add_ws, ignore; EX: "Category :" should ignore space
|
||||
ltr_bgn_reset = true; // ltr_bgn_reset
|
||||
}
|
||||
colon_count++; // increment colon count
|
||||
break;
|
||||
}
|
||||
case Byte_ascii.Hash:
|
||||
if (anch_bgn == -1) // anchor begins at 1st #, not last #; EX:A#B#C has anchor of "B#C" not "C" PAGE:en.w:Grand_Central_Terminal; DATE:2015-12-31
|
||||
anch_bgn = (txt_bb_len) + 1;
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
if (root_bgn == -1)
|
||||
root_bgn = (txt_bb_len) + 1;
|
||||
if (anch_bgn == -1) { // only set leaf if anchor found; guards against A#B/C and / setting leaf; DATE:2014-01-14
|
||||
leaf_bgn = (txt_bb_len) + 1;
|
||||
qarg_bgn = -1; // always reset qarg; handles ttls which have question_mark which are premptively assumed to be qarg; PAGE:en.w:Portal:Organized_Labour/Did_You_Know?/1 DATE:2014-06-08
|
||||
}
|
||||
break; // flag last leaf_bgn
|
||||
case Byte_ascii.Nl: // NOTE: for now, treat nl just like space; not sure if it should accept "a\nb" or "\nab"; need to handle trailing \n for "Argentina\n\n" in {{Infobox settlement|pushpin_map=Argentina|pushpin_label_position=|pushpin_map_alt=|pushpin_map_caption=Location of Salta in Argentina}};
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Cr: // added \t, \r; DATE:2013-03-27
|
||||
case Byte_ascii.Underline: if (ltr_bgn != -1) add_ws = true; ++cur;
|
||||
continue; // only mark add_ws if ltr_seen; this ignores ws at bgn; also, note "continue"
|
||||
case Byte_ascii.Question:
|
||||
if (txt_bb_len + 1 < end) // guard against trailing ? (which shouldn't happen)
|
||||
qarg_bgn = txt_bb_len + 1;
|
||||
break;
|
||||
case Byte_ascii.Amp:
|
||||
int cur2 = cur + 1;
|
||||
if (cur2 == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c Match_bgn does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
|
||||
else {
|
||||
if (trv == null) trv = new Btrie_rv();
|
||||
Object html_ent_obj = amp_trie.Match_at(trv, src, cur2, end);
|
||||
if (html_ent_obj != null) {
|
||||
Gfh_entity_itm amp_itm = (Gfh_entity_itm)html_ent_obj;
|
||||
match_pos = trv.Pos();
|
||||
if (amp_itm.Tid() == Gfh_entity_itm.Tid_name_std) {
|
||||
switch (amp_itm.Char_int()) {
|
||||
case 160: // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]]
|
||||
if (ltr_bgn != -1) add_ws = true; // apply same ws rules as Space, NewLine; needed for converting multiple ws into one; EX:" " -> " " x> " "; PAGEen.w:Greek_government-debt_crisis; DATE:2014-09-25
|
||||
cur = match_pos; // set cur after ";"
|
||||
continue;
|
||||
case Byte_ascii.Amp:
|
||||
b_ary = Byte_ascii.Amp_bry; // NOTE: if & convert to &; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
case Byte_ascii.Lt:
|
||||
case Byte_ascii.Gt:
|
||||
b_ary = amp_itm.Xml_name_bry();
|
||||
break;
|
||||
case Gfh_entity_itm.Char_int_null: // &#xx;
|
||||
int end_pos = Bry_find_.Find_fwd(src, Byte_ascii.Semic, match_pos, end);
|
||||
if (end_pos == Bry_find_.Not_found) {} // &# but no terminating ";" noop: defaults to current_byte which will be added below;
|
||||
else {
|
||||
b_ary = amp_itm.Xml_name_bry();
|
||||
match_pos = end_pos + 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
b_ary = amp_itm.U8_bry();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Xop_amp_mgr_rslt amp_rv = new Xop_amp_mgr_rslt();
|
||||
amp_mgr.Parse_ncr(amp_rv, amp_itm.Tid() == Gfh_entity_itm.Tid_num_hex, src, end, cur2, match_pos);
|
||||
if (amp_rv.Pass()) {
|
||||
b_ary = gplx.core.intls.Utf16_.Encode_int_to_bry(amp_rv.Val());
|
||||
if (b_ary.length == 1 && b_ary[0] == Byte_ascii.Hash) // NOTE: A#B should be interpreted as A#b; PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07
|
||||
anch_bgn = (txt_bb_len) + 1;
|
||||
match_pos = amp_rv.Pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Byte_ascii.Lt:
|
||||
if (cur + 3 < end) {
|
||||
if ( src[cur + 1] == Byte_ascii.Bang
|
||||
&& src[cur + 2] == Byte_ascii.Dash
|
||||
&& src[cur + 3] == Byte_ascii.Dash
|
||||
) {
|
||||
int cur3 = cur + 3;
|
||||
int find = Bry_find_.Find_fwd(src, Xop_comm_lxr.End_ary, cur3, end);
|
||||
if (find != -1) {
|
||||
cur = find + Xop_comm_lxr.End_ary.length;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (anch_bgn != -1) {
|
||||
if (anchor_encoder == null) {
|
||||
anchor_encoder = Gfo_url_encoder_.Id;
|
||||
anchor_encoder_bfr = Bry_bfr_.Reset(32);
|
||||
}
|
||||
anchor_encoder.Encode(anchor_encoder_bfr, src, cur, cur + 1);
|
||||
b_ary = anchor_encoder_bfr.To_bry_and_clear();
|
||||
match_pos = cur + 1;
|
||||
}
|
||||
break;
|
||||
// NOTE: DefaultSettings.php defines wgLegalTitleChars as " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; the characters above are okay; those below are not
|
||||
case Byte_ascii.Gt: case Byte_ascii.Pipe:
|
||||
case Byte_ascii.Brack_bgn: case Byte_ascii.Brack_end: case Byte_ascii.Curly_bgn: case Byte_ascii.Curly_end:
|
||||
if (anch_bgn != -1) {
|
||||
if (anchor_encoder == null) {
|
||||
anchor_encoder = Gfo_url_encoder_.Id;
|
||||
anchor_encoder_bfr = Bry_bfr_.Reset(32);
|
||||
}
|
||||
anchor_encoder.Encode(anchor_encoder_bfr, src, cur, cur + 1);
|
||||
b_ary = anchor_encoder_bfr.To_bry_and_clear();
|
||||
match_pos = cur + 1;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
if ((b & 0xff) > 127) {// PATCH.JAVA:need to convert to unsigned byte
|
||||
if (trv == null) trv = new Btrie_rv();
|
||||
Object char_obj = char_trie.Match_at_w_b0(trv, b, src, cur, end);
|
||||
if (char_obj != null) {
|
||||
int tid = ((Int_obj_val)(char_obj)).Val();
|
||||
cur = trv.Pos();
|
||||
switch (tid) {
|
||||
case Char__bidi: // ignore bidi
|
||||
continue;
|
||||
case Char__ws: // treat extended_ws as space; PAGE:ja.w:Template:Location_map_USA New_York; DATE:2015-07-28
|
||||
if (ltr_bgn != -1) add_ws = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
++cur;
|
||||
if (add_ws) { // add ws and toggle flag
|
||||
bfr.Add_byte(Byte_ascii.Space); ++txt_bb_len;
|
||||
add_ws = false;
|
||||
}
|
||||
if (ltr_bgn == -1) ltr_bgn = txt_bb_len; // if 1st letter not seen, mark 1st letter
|
||||
if (b_ary == null) {bfr.Add_byte(b); ++txt_bb_len;} // add to bfr
|
||||
else {bfr.Add(b_ary); txt_bb_len += b_ary.length; b_ary = null; cur = match_pos;} // NOTE: b_ary != null only for amp_trie
|
||||
if (ltr_bgn_reset) {// colon found; set ws to bgn mode; note that # and / do not reset
|
||||
ltr_bgn_reset = false;
|
||||
ltr_bgn = -1;
|
||||
}
|
||||
}
|
||||
if (txt_bb_len == 0) return false;
|
||||
if (wik_bgn == -1 && page_bgn == txt_bb_len) return false; // if no wiki, but page_bgn is at end, then ttl is ns only; EX: "Help:"; NOTE: "fr:", "fr:Help" is allowed
|
||||
full_txt = bfr.To_bry_and_clear();
|
||||
if ( ns.Case_match() == Xow_ns_case_.Tid__1st
|
||||
&& wik_bgn == -1 ) { // do not check case if xwiki; EX: "fr:" would have a wik_bgn of 0 (and a wik_end of 3); "A" (and any non-xwiki ttl) would have a wik_bgn == -1
|
||||
byte char_1st = full_txt[page_bgn];
|
||||
int char_1st_len = gplx.core.intls.Utf8_.Len_of_char_by_1st_byte(char_1st);
|
||||
int page_end = page_bgn + char_1st_len;
|
||||
if ( char_1st_len > 1) { // 1st char is multi-byte char
|
||||
int full_txt_len = full_txt.length;
|
||||
if (page_end > full_txt_len) // ttl is too too short for 1st multi-byte char; EX: [[%D0]] is 208 but in utf8, 208 requires at least another char; DATE:2013-11-11
|
||||
return false; // ttl is invalid
|
||||
else { // ttl is long enough for 1st mult-byte char; need to use platform uppercasing; Xol_case_mgr_.Utf_8 is not sufficient
|
||||
Bry_bfr upper_1st = Bry_bfr_.Get();
|
||||
byte[] page_txt = case_mgr.Case_build_1st_upper(upper_1st, full_txt, page_bgn, full_txt_len); // always build; never reuse; (multi-byte character will expand array)
|
||||
if (page_bgn == 0) // page only; EX: A
|
||||
full_txt = page_txt;
|
||||
else // ns + page; EX: Help:A
|
||||
full_txt = Bry_.Add(Bry_.Mid(full_txt, 0, page_bgn), page_txt); // add page_txt to exsiting ns
|
||||
upper_1st.Mkr_rls();
|
||||
}
|
||||
}
|
||||
else
|
||||
full_txt = case_mgr.Case_reuse_upper(full_txt, page_bgn, page_end);
|
||||
}
|
||||
Xow_ns tors_ns = ns.Id_is_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id());
|
||||
tors_txt = tors_ns.Name_ui_w_colon();
|
||||
// tors_txt = tors_ns == null ? Bry_.Empty : tors_ns.Name_ui_w_colon();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class Xoa_ttl_trie {
|
||||
public static Btrie_fast_mgr new_() {
|
||||
Btrie_fast_mgr rv = Btrie_fast_mgr.cs();
|
||||
rv.Add(Byte_ascii.Colon , Byte_obj_val.new_(Id_colon));
|
||||
rv.Add(Byte_ascii.Hash , Byte_obj_val.new_(Id_hash));
|
||||
rv.Add(Byte_ascii.Slash , Byte_obj_val.new_(Id_slash));
|
||||
rv.Add(Byte_ascii.Space , Byte_obj_val.new_(Id_space));
|
||||
rv.Add(Byte_ascii.Underline , Byte_obj_val.new_(Id_underline));
|
||||
rv.Add(Byte_ascii.Amp , Byte_obj_val.new_(Id_amp));
|
||||
rv.Add(Xop_comm_lxr.Bgn_ary , Byte_obj_val.new_(Id_comment_bgn));
|
||||
rv.Add(Byte_ascii.Nl , Byte_obj_val.new_(Id_newLine));
|
||||
rv.Add(Byte_ascii.Brack_bgn , Byte_obj_val.new_(Id_invalid));
|
||||
rv.Add(Byte_ascii.Curly_bgn , Byte_obj_val.new_(Id_invalid));
|
||||
return rv;
|
||||
}
|
||||
public static final byte Id_colon = 0, Id_hash = 1, Id_slash = 2, Id_space = 3, Id_underline = 4, Id_amp = 5, Id_comment_bgn = 6, Id_invalid = 7, Id_newLine = 8;
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xoa_url {
|
||||
public int Tid() {return tid;} public void Tid_(int v) {this.tid = v;} private int tid;
|
||||
public byte[] Raw() {return raw;} private byte[] raw = Bry_.Empty;
|
||||
public byte[] Orig() {return orig;} private byte[] orig;
|
||||
public byte[] Wiki_bry() {return wiki_bry;} public Xoa_url Wiki_bry_(byte[] v) {wiki_bry = v; return this;} private byte[] wiki_bry;
|
||||
public byte[] Page_bry() {return page_bry;} public Xoa_url Page_bry_(byte[] v) {page_bry = v; return this;} private byte[] page_bry;
|
||||
public byte[] Anch_bry() {return anch_bry;} public Xoa_url Anch_bry_(byte[] v) {anch_bry = v; return this;} private byte[] anch_bry;
|
||||
public String Anch_str() {return anch_bry == null ? null : String_.new_u8(anch_bry);}
|
||||
public byte[][] Segs_ary() {return segs_ary;} private byte[][] segs_ary;
|
||||
public Gfo_qarg_itm[] Qargs_ary() {return qargs_ary;} public Xoa_url Qargs_ary_(Gfo_qarg_itm[] v) {qargs_ary = v; return this;} private Gfo_qarg_itm[] qargs_ary = Gfo_qarg_itm.Ary_empty;
|
||||
public Gfo_qarg_mgr_old Qargs_mgr() {if (qargs_mgr == null) qargs_mgr = new Gfo_qarg_mgr_old().Load(qargs_ary); return qargs_mgr;} private Gfo_qarg_mgr_old qargs_mgr;
|
||||
public byte Protocol_tid() {return protocol_tid;} private byte protocol_tid;
|
||||
public byte[] Protocol_bry() {return protocol_bry;} private byte[] protocol_bry;
|
||||
public boolean Protocol_is_relative() {return protocol_is_relative;} private boolean protocol_is_relative;
|
||||
public byte[] Vnt_bry() {return vnt_bry;} private byte[] vnt_bry;
|
||||
public boolean Wiki_is_missing() {return wiki_is_missing;} private boolean wiki_is_missing;
|
||||
public boolean Wiki_is_same() {return wiki_is_same;} private boolean wiki_is_same;
|
||||
public boolean Page_is_main() {return page_is_main;} private boolean page_is_main;
|
||||
public Xoa_url Ctor(int tid, byte[] orig, byte[] raw, byte protocol_tid, byte[] protocol_bry, boolean protocol_is_relative
|
||||
, byte[] wiki, byte[] page, Gfo_qarg_itm[] qargs, byte[] anch
|
||||
, byte[][] segs_ary, byte[] vnt_bry, boolean wiki_is_missing, boolean wiki_is_same, boolean page_is_main) {
|
||||
this.tid = tid; this.orig = orig; this.raw = raw;
|
||||
this.protocol_tid = protocol_tid; this.protocol_bry = protocol_bry; this.protocol_is_relative = protocol_is_relative;
|
||||
this.wiki_bry = wiki; this.page_bry = page; this.qargs_ary = qargs; this.anch_bry = anch;
|
||||
this.segs_ary = segs_ary; this.vnt_bry = vnt_bry;
|
||||
this.wiki_is_missing = wiki_is_missing; this.wiki_is_same = wiki_is_same; this.page_is_main = page_is_main;
|
||||
return this;
|
||||
}
|
||||
public byte[] Page_for_lnki() {
|
||||
int raw_len = raw.length;
|
||||
int page_bgn = Page_bgn(raw_len);
|
||||
if (page_bgn == Bry_find_.Not_found) // no /wiki/ found; return page
|
||||
return page_bry == null ? Bry_.Empty : page_bry; // guard against null ref
|
||||
else
|
||||
return Bry_.Mid(raw, page_bgn, raw_len);// else take everything after "/wiki/";
|
||||
}
|
||||
private int Page_bgn(int raw_len) {
|
||||
int wiki_pos = Bry_find_.Find_fwd(raw, Xoh_href_.Bry__wiki, 0, raw_len); // look for /wiki/
|
||||
return wiki_pos == Bry_find_.Not_found ? Bry_find_.Not_found : wiki_pos + Xoh_href_.Bry__wiki.length;
|
||||
}
|
||||
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no);}
|
||||
public String To_str() {return String_.new_u8(To_bry(Bool_.Y, Bool_.Y));}
|
||||
public byte[] To_bry_page_w_anch() {
|
||||
byte[] page = page_bry, anch = anch_bry;
|
||||
byte[] anch_spr = anch == null ? null : Byte_ascii.Hash_bry;
|
||||
return Bry_.Add(page, anch_spr, anch);
|
||||
}
|
||||
public byte[] To_bry_full_wo_qargs() {return To_bry(Bool_.Y, Bool_.N);}
|
||||
public byte[] To_bry(boolean full, boolean show_qargs) { // currently used for status bar; not embedded in any html
|
||||
switch (tid) {
|
||||
case Xoa_url_.Tid_unknown: // unknown; should not occur?
|
||||
return Bry_.Len_eq_0(raw) ? Bry_.Add(wiki_bry, Xoh_href_.Bry__wiki, page_bry) : raw; // raw is empty when using new_();
|
||||
case Xoa_url_.Tid_inet: // protocol; embed all; EX: "http://a.org/A"; "file:///C/dir/file.txt"
|
||||
case Xoa_url_.Tid_file: // file; EX: "file:///C:/A/B.jpg"
|
||||
return raw;
|
||||
case Xoa_url_.Tid_xcmd: // xcmd; embed page only; EX: "xowa.usr.bookmarks.add"
|
||||
return page_bry;
|
||||
default:
|
||||
throw Err_.new_unhandled(tid);
|
||||
case Xoa_url_.Tid_anch:
|
||||
case Xoa_url_.Tid_page:
|
||||
break;
|
||||
}
|
||||
byte[] wiki = wiki_bry, page = page_bry, anch = anch_bry;
|
||||
byte[] wiki_spr = vnt_bry == null ? Xoh_href_.Bry__wiki : Bry_.Add(Byte_ascii.Slash_bry, vnt_bry, Byte_ascii.Slash_bry);
|
||||
byte[] anch_spr = anch == null ? null : Byte_ascii.Hash_bry;
|
||||
if (!full) {
|
||||
boolean tid_is_anch = tid == Xoa_url_.Tid_anch;
|
||||
if ( wiki_is_same // same wiki; don't show wiki; EX: "/wiki/A" -> "A" x> "en.wikipedia.org/wiki/A"
|
||||
|| tid_is_anch) { // anch never shows wiki; EX: #A
|
||||
wiki = wiki_spr = null; // don't show wiki;
|
||||
}
|
||||
if (tid_is_anch)
|
||||
page = null;
|
||||
}
|
||||
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
bfr.Add_safe(wiki).Add_safe(wiki_spr); // add wiki_key; EX: "en.wikipedia.org", "/wiki/"
|
||||
bfr.Add_safe(page); // add page; EX: "A"
|
||||
if (show_qargs || qargs_ary.length > 0) {
|
||||
Gfo_qarg_mgr_old.Concat_bfr(bfr, gplx.langs.htmls.encoders.Gfo_url_encoder_.Href, qargs_ary);
|
||||
}
|
||||
if (anch != null) // NOTE: anch must go last (after qargs); DATE:2016-10-08
|
||||
bfr.Add(anch_spr).Add(anch); // add anch EX: "#", "B"
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static final Xoa_url Null = null;
|
||||
public static Xoa_url blank() {return new Xoa_url();}
|
||||
public static Xoa_url New(Xow_wiki wiki, Xoa_ttl ttl) {return New(wiki.Domain_bry(), ttl.Full_txt_w_ttl_case());}
|
||||
public static Xoa_url New(byte[] wiki, byte[] page) {
|
||||
Xoa_url rv = new Xoa_url();
|
||||
rv.Wiki_bry_(wiki);
|
||||
rv.Page_bry_(page);
|
||||
rv.tid = Xoa_url_.Tid_page;
|
||||
return rv;
|
||||
} Xoa_url() {}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xoa_url_ {
|
||||
public static final int Tid_unknown = 0, Tid_page = 1, Tid_anch = 2, Tid_inet = 3, Tid_file = 4, Tid_xcmd = 5;
|
||||
public static boolean Tid_is_pagelike(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_page: case Tid_anch: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static void Invalid_warn(String url) {Xoa_app_.Usr_dlg().Plog_many("", "", "invalid url; url=~{0}", url);}
|
||||
public static String Main_page__home_str = gplx.xowa.wikis.domains.Xow_domain_itm_.Str__home + gplx.xowa.htmls.hrefs.Xoh_href_.Str__wiki + gplx.xowa.Xoa_page_.Main_page_str; // EX:home/wiki/Main_Page
|
||||
public static final byte[]
|
||||
Qarg__redirect = Bry_.new_a7("redirect")
|
||||
, Qarg__redirect__no = Bry_.new_a7("no")
|
||||
, Qarg__action = Bry_.new_a7("action")
|
||||
, Qarg__action__edit = Bry_.new_a7("edit")
|
||||
, Qarg__curid = Bry_.new_a7("curid")
|
||||
;
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.brys.fmtrs.*; import gplx.core.flds.*; import gplx.core.ios.*; import gplx.core.threads.*; import gplx.langs.jsons.*; import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.log_msgs.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.site_cfgs.*; import gplx.xowa.apps.caches.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.metas.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.apps.progs.*; import gplx.xowa.apps.gfs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.specials.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.css.*; import gplx.xowa.bldrs.installs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
|
||||
import gplx.xowa.guis.cbks.*; import gplx.xowa.guis.tabs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.guis.*; import gplx.xowa.apps.cfgs.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.apps.fmtrs.*; import gplx.xowa.htmls.*; import gplx.xowa.wikis.xwikis.sitelinks.*; import gplx.xowa.wikis.xwikis.parsers.*;
|
||||
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.ns_files.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.xndes.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.math.*;
|
||||
import gplx.xowa.parsers.utils.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.apps.servers.tcp.*; import gplx.xowa.apps.servers.http.*;
|
||||
import gplx.xowa.bldrs.wms.*;
|
||||
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.addons.*; import gplx.xowa.specials.mgrs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.apps.miscs.*;
|
||||
public class Xoae_app implements Xoa_app, Gfo_invk {
|
||||
public Xoae_app(Gfo_usr_dlg usr_dlg, Xoa_app_mode mode, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url user_dir, Io_url css_dir, String bin_dir_name) {
|
||||
Xoa_app_.Usr_dlg_(usr_dlg);
|
||||
usr_dlg.Log_wkr().Log_to_session_fmt("app.ctor.bgn");
|
||||
|
||||
this.mode = mode;
|
||||
Io_url.Http_file_str_encoder = Gfo_url_encoder_.New__fsys_lnx().Make();
|
||||
fsys_mgr = new Xoa_fsys_mgr(bin_dir_name, root_dir, wiki_dir, file_dir, css_dir, root_dir);
|
||||
log_wtr = usr_dlg.Log_wkr();
|
||||
api_root = new Xoapi_root(this);
|
||||
|
||||
// user
|
||||
user = new Xoue_user(this, user_dir);
|
||||
this.fsys_mgr.Url_finder().Init_by_user(user.Fsys_mgr());
|
||||
|
||||
this.meta_mgr = new Xoa_meta_mgr(this);
|
||||
url_cmd_eval = new Xoa_fsys_eval(fsys_mgr, user.Fsys_mgr());
|
||||
fsys_mgr.Init_by_app(prog_mgr);
|
||||
log_wtr.Log_dir_(user.Fsys_mgr().App_temp_dir().GenSubDir("log"));
|
||||
this.gfs_mgr = new Xoa_gfs_mgr(user.Key(), this, fsys_mgr);
|
||||
lang_mgr = new Xoa_lang_mgr(this, gfs_mgr);
|
||||
wiki_mgr = new Xoae_wiki_mgr(this);
|
||||
gui_mgr = new Xoa_gui_mgr(this);
|
||||
this.gui__tab_mgr = new Xog_tab_mgr__swt(gui_mgr);
|
||||
bldr = new Xob_bldr(this);
|
||||
file_mgr.Ctor_by_app(this);
|
||||
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);
|
||||
xtn_mgr = new Xow_xtn_mgr().Ctor_by_app(this);
|
||||
hive_mgr = new Xoa_hive_mgr(this);
|
||||
tcp_server.App_ctor(this);
|
||||
fmtr_mgr = new Xoa_fmtr_mgr(this);
|
||||
log_mgr = new Xop_log_mgr(this);
|
||||
http_server = new Http_server_mgr(this);
|
||||
html_mgr = new Xoh_html_mgr(this);
|
||||
this.html__bridge_mgr = new Xoh_bridge_mgr(utl__json_parser);
|
||||
this.site_cfg_mgr = new Xoa_site_cfg_mgr(this);
|
||||
|
||||
usr_dlg.Log_wkr().Log_to_session_fmt("app.ctor.end");
|
||||
}
|
||||
public boolean Tid_is_edit() {return Bool_.Y;}
|
||||
public Xoa_app_mode Mode() {return mode;} private final Xoa_app_mode mode;
|
||||
public Xoa_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xoa_fsys_mgr fsys_mgr;
|
||||
public Xof_cache_mgr File__cache_mgr() {return file_mgr.Cache_mgr();}
|
||||
public Xof_img_mgr File__img_mgr() {return file_mgr.Img_mgr();}
|
||||
public Io_download_fmt File__download_fmt() {return wmf_mgr.Download_wkr().Download_xrg().Download_fmt();}
|
||||
public Xoh_href_parser Html__href_parser() {return html__href_parser;} private final Xoh_href_parser html__href_parser = new Xoh_href_parser();
|
||||
public Xoa_css_extractor Html__css_installer() {return html__css_installer;} private final Xoa_css_extractor html__css_installer = new Xoa_css_extractor();
|
||||
public Xoh_bridge_mgr Html__bridge_mgr() {return html__bridge_mgr;} private final Xoh_bridge_mgr html__bridge_mgr;
|
||||
public Xowmf_mgr Wmf_mgr() {return wmf_mgr;} private final Xowmf_mgr wmf_mgr = new Xowmf_mgr();
|
||||
public Bry_bfr_mkr Utl__bfr_mkr() {return utl__bry_bfr_mkr;} private final Bry_bfr_mkr utl__bry_bfr_mkr = new Bry_bfr_mkr();
|
||||
public Json_parser Utl__json_parser() {return utl__json_parser;} private final Json_parser utl__json_parser = new Json_parser();
|
||||
public Gfo_inet_conn Utl__inet_conn() {return inet_conn;} private final Gfo_inet_conn inet_conn = Gfo_inet_conn_.new_();
|
||||
public Xoa_meta_mgr Dbmeta_mgr() {return meta_mgr;} private final Xoa_meta_mgr meta_mgr;
|
||||
public boolean Bldr__running() {return bldr__running;} public void Bldr__running_(boolean v) {this.bldr__running = v;} private boolean bldr__running;
|
||||
public Xoa_parser_mgr Parser_mgr() {return parser_mgr;} private final Xoa_parser_mgr parser_mgr = new Xoa_parser_mgr();
|
||||
public Xoa_site_cfg_mgr Site_cfg_mgr() {return site_cfg_mgr;} private final Xoa_site_cfg_mgr site_cfg_mgr;
|
||||
public Xoa_sitelink_mgr Xwiki_mgr__sitelink_mgr() {return xwiki_mgr__sitelink_mgr;} private final Xoa_sitelink_mgr xwiki_mgr__sitelink_mgr = new Xoa_sitelink_mgr();
|
||||
public boolean Xwiki_mgr__missing(byte[] wiki_key) {return user.Wiki().Xwiki_mgr().Get_by_key(wiki_key) == null;} // NOTE: only the user_wiki has a full list of all wikis b/c it has xwiki objects; wiki_mgr does not, b/c it has heavier wiki objects which are loaded dynamically;
|
||||
public boolean Xwiki_mgr__exists(byte[] wiki_key) {return user.Wiki().Xwiki_mgr().Get_by_key(wiki_key) != null;}
|
||||
public Xow_xwiki_itm_parser Xwiki_mgr__itm_parser() {return xwiki_mgr__itm_parser;} private final Xow_xwiki_itm_parser xwiki_mgr__itm_parser = new Xow_xwiki_itm_parser();
|
||||
public Xoax_addon_mgr Addon_mgr() {return addon_mgr;} private final Xoax_addon_mgr addon_mgr = new Xoax_addon_mgr();
|
||||
public Xoa_special_regy Special_regy() {return special_regy;} private final Xoa_special_regy special_regy = new Xoa_special_regy();
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xog_cbk_mgr Gui__cbk_mgr() {return gui__cbk_mgr;} private final Xog_cbk_mgr gui__cbk_mgr = new Xog_cbk_mgr();
|
||||
public Xog_tab_mgr Gui__tab_mgr() {return gui__tab_mgr;} private final Xog_tab_mgr gui__tab_mgr;
|
||||
public Gfo_thread_mgr Thread_mgr() {return thread_mgr;} private final Gfo_thread_mgr thread_mgr = new Gfo_thread_mgr();
|
||||
public Xocfg_mgr Cfg() {return cfg;} private final Xocfg_mgr cfg = new Xocfg_mgr();
|
||||
public Xoa_misc_mgr Misc_mgr() {return misc_mgr;} private final Xoa_misc_mgr misc_mgr = new Xoa_misc_mgr();
|
||||
|
||||
public Xoae_wiki_mgr Wiki_mgr() {return wiki_mgr;} private Xoae_wiki_mgr wiki_mgr;
|
||||
public Xoa_wiki_mgr Wiki_mgri() {return wiki_mgr;}
|
||||
public Xou_user_mgr User_mgr() {return user_mgr;} private Xou_user_mgr user_mgr;
|
||||
public Xof_file_mgr File_mgr() {return file_mgr;} private Xof_file_mgr file_mgr = new Xof_file_mgr();
|
||||
public Xoa_lang_mgr Lang_mgr() {return lang_mgr;} private Xoa_lang_mgr lang_mgr;
|
||||
public Xoa_gui_mgr Gui_mgr() {return gui_mgr;} private Xoa_gui_mgr gui_mgr;
|
||||
public Xou_user User() {return user;}
|
||||
public Xoue_user Usere() {return user;} private Xoue_user user;
|
||||
public 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 Gfo_usr_dlg Usr_dlg() {return Xoa_app_.Usr_dlg();}
|
||||
public Gfo_usr_dlg__log Log_wtr() {return log_wtr;} private Gfo_usr_dlg__log log_wtr;
|
||||
public Xoa_gfs_mgr Gfs_mgr() {return gfs_mgr;} private final 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 Xoh_html_mgr Html_mgr() {return html_mgr;} private Xoh_html_mgr html_mgr;
|
||||
public Xop_log_mgr Log_mgr() {return log_mgr;} private Xop_log_mgr log_mgr;
|
||||
public Xoa_shell Shell() {return shell;} private Xoa_shell shell;
|
||||
public Xoa_thread_mgr Thread_mgr_old() {return thread_mgr_old;} private Xoa_thread_mgr thread_mgr_old = new Xoa_thread_mgr();
|
||||
public Xoa_hive_mgr Hive_mgr() {return hive_mgr;} private Xoa_hive_mgr hive_mgr;
|
||||
public Xoa_prog_mgr Prog_mgr() {return prog_mgr;} private final Xoa_prog_mgr prog_mgr = new Xoa_prog_mgr();
|
||||
public Gfo_async_mgr Async_mgr() {return async_mgr;} private Gfo_async_mgr async_mgr = new Gfo_async_mgr();
|
||||
|
||||
public Xoi_setup_mgr Setup_mgr() {return setup_mgr;} private Xoi_setup_mgr setup_mgr;
|
||||
public Gfo_msg_log Msg_log() {return msg_log;} private Gfo_msg_log msg_log = new Gfo_msg_log(Xoa_app_.Name);
|
||||
public Gfo_msg_log Msg_log_null() {return msg_log_null;} private Gfo_msg_log msg_log_null = new Gfo_msg_log("null_log");
|
||||
|
||||
public Xoh_ns_file_page_mgr Ns_file_page_mgr() {return ns_file_page_mgr;} private Xoh_ns_file_page_mgr ns_file_page_mgr = new Xoh_ns_file_page_mgr();
|
||||
public Btrie_slim_mgr Utl_trie_tblw_ws() {return utl_trie_tblw_ws;} private Btrie_slim_mgr utl_trie_tblw_ws = Xop_tblw_ws_itm.trie_();
|
||||
public Gfo_fld_rdr Utl_fld_rdr() {return utl_fld_rdr;} Gfo_fld_rdr utl_fld_rdr = Gfo_fld_rdr.xowa_();
|
||||
public Gfo_log_bfr Log_bfr() {return log_bfr;} private Gfo_log_bfr log_bfr = new Gfo_log_bfr();
|
||||
public Xoa_sys_cfg Sys_cfg() {return sys_cfg;} private Xoa_sys_cfg sys_cfg;
|
||||
public Bry_fmtr Tmp_fmtr() {return tmp_fmtr;} Bry_fmtr tmp_fmtr = Bry_fmtr.new_("");
|
||||
public 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 Io_stream_zip_mgr Zip_mgr() {return zip_mgr;} Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
|
||||
public Xoa_cache_mgr Cache_mgr() {return cache_mgr;} private Xoa_cache_mgr cache_mgr = new Xoa_cache_mgr();
|
||||
|
||||
public Xosrv_server Tcp_server() {return tcp_server;} private Xosrv_server tcp_server = new Xosrv_server();
|
||||
public Http_server_mgr Http_server() {return http_server;} private Http_server_mgr http_server;
|
||||
public Xop_amp_mgr Parser_amp_mgr() {return parser_amp_mgr;} private final Xop_amp_mgr parser_amp_mgr = Xop_amp_mgr.Instance;
|
||||
|
||||
private Xoa_fmtr_mgr fmtr_mgr;
|
||||
public Gfo_number_parser Utl_num_parser() {return utl_num_parser;} private Gfo_number_parser utl_num_parser = new Gfo_number_parser();
|
||||
public void Init_by_app() {
|
||||
stage = Xoa_stage_.Tid_init;
|
||||
user.Init_by_app(this);
|
||||
cfg.Init_by_app(this);
|
||||
user.User_db_mgr().Cache_mgr().Init_by_app(this);
|
||||
misc_mgr.Init_by_app(this);
|
||||
user.History_mgr().Init_by_app(this);
|
||||
prog_mgr.Init_by_app(this, url_cmd_eval);
|
||||
xtn_mgr.Init_by_app(this);
|
||||
gui_mgr.Init_by_app();
|
||||
html__css_installer.Init_by_app(this);
|
||||
wiki_mgr.Init_by_app();
|
||||
gplx.xowa.bldrs.setups.upgrades.Xoa_upgrade_mgr.Check(this);
|
||||
setup_mgr.Init_by_app(this);
|
||||
thread_mgr_old.Usr_dlg_(Xoa_app_.Usr_dlg());
|
||||
html_mgr.Init_by_app(this);
|
||||
api_root.Init_by_app(this);
|
||||
wmf_mgr.Init_by_app(this);
|
||||
gplx.core.net.emails.Gfo_email_mgr_.Instance = gplx.core.net.emails.Gfo_email_mgr_.New_jre();
|
||||
special_mgr.Init_by_app(this);
|
||||
sys_cfg.Init_by_app(this);
|
||||
}
|
||||
public void Launch() {
|
||||
// guard against circular calls; probably no longer needed
|
||||
if (stage == Xoa_stage_.Tid_launch) return;
|
||||
stage = Xoa_stage_.Tid_launch;
|
||||
|
||||
// run app-launch actions
|
||||
gplx.xowa.apps.setups.Xoa_setup_mgr.Launch(this);
|
||||
|
||||
// init "In other langs"
|
||||
xwiki_mgr__sitelink_mgr.Init_by_app();
|
||||
|
||||
// init user wiki
|
||||
user.Wiki().Init_assert(); // NOTE: must assert wiki and load langs first, else will be asserted during Portal_mgr().Init(), which will cause IndexOutOfBounds; DATE:2014-10-04
|
||||
gplx.xowa.addons.wikis.directorys.Xowdir_addon.Init(this);
|
||||
}
|
||||
public byte Stage() {return stage;} public Xoae_app Stage_(byte v) {stage = v; return this;} private byte stage = Xoa_stage_.Tid_ctor;
|
||||
public boolean Term_cbk() {
|
||||
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
|
||||
usr_dlg.Log_many("", "", "term:bgn");
|
||||
if (setup_mgr.Cmd_mgr().Working()) {
|
||||
if (!gui_mgr.Kit().Ask_yes_no("", "", "An import is in progress. Are you sure you want to exit?")) return false;
|
||||
}
|
||||
if (!gui_mgr.Browser_win().Tab_mgr().Tabs__pub_close_all()) return false;
|
||||
gui_mgr.Browser_win().Usr_dlg().Canceled_y_();
|
||||
user.App_term(); usr_dlg.Log_many("", "", "term:app_term");
|
||||
log_wtr.Log_term(); usr_dlg.Log_many("", "", "term:log_wtr");
|
||||
log_mgr.Rls(); usr_dlg.Log_many("", "", "term:log_mgr");
|
||||
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all(this);
|
||||
wiki_mgr.Rls(); usr_dlg.Log_many("", "", "term:wiki_mgr");
|
||||
return true;
|
||||
}
|
||||
public void Reset_all() {
|
||||
this.Free_mem(true);
|
||||
gplx.xowa.xtns.scribunto.Scrib_core_mgr.Term_all(this);
|
||||
System_.Garbage_collect();
|
||||
}
|
||||
public void Free_mem(boolean clear_ctx) {
|
||||
this.Utl__bfr_mkr().Clear();
|
||||
msg_log.Clear();
|
||||
wiki_mgr.Free_mem(clear_ctx);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_gui)) return gui_mgr;
|
||||
else if (ctx.Match(k, Invk_api)) return api_root;
|
||||
else if (ctx.Match(k, Invk_bldr)) return bldr;
|
||||
else if (ctx.Match(k, Invk_wikis)) return wiki_mgr;
|
||||
else if (ctx.Match(k, Invk_fsys)) return fsys_mgr;
|
||||
else if (ctx.Match(k, Invk_files)) return file_mgr;
|
||||
else if (ctx.Match(k, Invk_langs)) return lang_mgr;
|
||||
else if (ctx.Match(k, Invk_users)) return user_mgr;
|
||||
else if (ctx.Match(k, Invk_user)) return user;
|
||||
else if (ctx.Match(k, Invk_sys_cfg)) return sys_cfg;
|
||||
else if (ctx.Match(k, Invk_cur)) return cur_redirect;
|
||||
else if (ctx.Match(k, Invk_html)) return html_mgr;
|
||||
else if (ctx.Match(k, Invk_shell)) return shell;
|
||||
else if (ctx.Match(k, Invk_log)) return log_wtr;
|
||||
else if (ctx.Match(k, Invk_setup)) return setup_mgr;
|
||||
else if (ctx.Match(k, Invk_scripts)) return 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_usr_dlg)) return Xoa_app_.Usr_dlg();
|
||||
else if (ctx.Match(k, Invk_specials)) return special_mgr;
|
||||
else if (ctx.Match(k, Invk_server)) return tcp_server;
|
||||
else if (ctx.Match(k, Invk_http_server)) return http_server;
|
||||
else if (ctx.Match(k, Invk_app)) return this;
|
||||
else if (ctx.Match(k, Invk_xowa)) return this;
|
||||
else if (ctx.Match(k, Invk_fmtrs)) return fmtr_mgr;
|
||||
else if (ctx.Match(k, Invk_cfg)) return cfg;
|
||||
else if (ctx.Match(k, Invk_xwiki_langs_load)) xwiki_mgr__sitelink_mgr.Parse(m.ReadBry("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
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_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"
|
||||
, Invk_xwiki_langs_load = "xwiki_langs_load"
|
||||
;
|
||||
public static final String Invk_term_cbk = "term_cbk";
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.pfuncs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.htmls.modules.popups.*;
|
||||
import gplx.xowa.wikis.pages.wtxts.*; import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.redirects.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*;
|
||||
public class Xoae_page implements Xoa_page {
|
||||
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
this.wiki = wiki; this.ttl = ttl;
|
||||
this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
|
||||
html.Init_by_page(ttl);
|
||||
html.Toc_mgr().Init(wiki.Html_mgr().Tidy_mgr(), wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), ttl.Page_db());
|
||||
Ttl_(ttl);
|
||||
} Xoae_page() {} // called by Empty
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
|
||||
public Xoae_page Ttl_(Xoa_ttl v) {
|
||||
ttl = v;
|
||||
url.Wiki_bry_(wiki.Domain_bry()).Page_bry_(v.Full_db()); // NOTE:was Full_url, but caused url_bar to have url-decoded chars; DATE:2016-11-25
|
||||
return this;
|
||||
}
|
||||
public Xoa_url Url() {return url;} public Xoae_page Url_(Xoa_url v) {url = v; return this;} private Xoa_url url = Xoa_url.blank();
|
||||
public byte[] Url_bry_safe() {return Xoa_page_.Url_bry_safe(url, wiki, ttl);}
|
||||
public Xopg_db_data Db() {return db;} private final Xopg_db_data db = new Xopg_db_data();
|
||||
public Xopg_redirect_mgr Redirect_trail() {return redirect_trail;} private final Xopg_redirect_mgr redirect_trail = new Xopg_redirect_mgr();
|
||||
public Xopg_html_data Html_data() {return html;} private final Xopg_html_data html = new Xopg_html_data();
|
||||
public Xopg_hdump_data Hdump_mgr() {return hdump;} private final Xopg_hdump_data hdump = new Xopg_hdump_data();
|
||||
public Xopg_wtxt_data Wtxt() {return wtxt;} private final Xopg_wtxt_data wtxt = new Xopg_wtxt_data();
|
||||
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
public void Xtn_gallery_packed_exists_y_() {html.Xtn_gallery_packed_exists_y_();}
|
||||
public boolean Xtn__timeline_exists() {return false;} // drd always sets timeline
|
||||
public boolean Xtn__gallery_exists() {return false;} // drd does not need to set gallery.style.css
|
||||
private Guid_adp page_guid;
|
||||
public Guid_adp Page_guid() {
|
||||
if (page_guid == null) {
|
||||
page_guid = Guid_adp_.New();
|
||||
}
|
||||
return page_guid;
|
||||
}
|
||||
|
||||
public Xowe_wiki Wikie() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xol_lang_itm Lang() {return lang;} public Xoae_page Lang_(Xol_lang_itm v) {lang = v; return this;} private Xol_lang_itm lang;
|
||||
public Xopg_tab_data Tab_data() {return tab_data;} private final Xopg_tab_data tab_data = new Xopg_tab_data();
|
||||
public byte Edit_mode() {return edit_mode;} private byte edit_mode; public void Edit_mode_update_() {edit_mode = Xoa_page_.Edit_mode_update;}
|
||||
public Xop_root_tkn Root() {return root;} public Xoae_page Root_(Xop_root_tkn v) {root = v; return this;} private Xop_root_tkn root;
|
||||
|
||||
public Xoh_cmd_mgr Html_cmd_mgr() {return html_cmd_mgr;} private Xoh_cmd_mgr html_cmd_mgr = new Xoh_cmd_mgr();
|
||||
public Xof_xfer_queue File_queue() {return file_queue;} private Xof_xfer_queue file_queue = new Xof_xfer_queue();
|
||||
public List_adp File_math() {return file_math;} private List_adp file_math = List_adp_.New();
|
||||
public List_adp Lnki_list() {return lnki_list;} public void Lnki_list_(List_adp v) {this.lnki_list = v;} private List_adp lnki_list = List_adp_.New();
|
||||
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr(); public void Ref_mgr_(Ref_itm_mgr v) {this.ref_mgr = v;}
|
||||
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
|
||||
|
||||
public List_adp Slink_list() {return slink_list;} private List_adp slink_list = List_adp_.New();
|
||||
public Wdata_external_lang_links_data Wdata_external_lang_links() {return wdata_external_lang_links;} private Wdata_external_lang_links_data wdata_external_lang_links = new Wdata_external_lang_links_data();
|
||||
public int Bldr__ns_ord() {return bldr__ns_ord;} public void Bldr__ns_ord_(int v) {bldr__ns_ord = v;} private int bldr__ns_ord;
|
||||
public Xopg_tmpl_prepend_mgr Tmpl_prepend_mgr() {return tmpl_prepend_mgr;} private Xopg_tmpl_prepend_mgr tmpl_prepend_mgr = new Xopg_tmpl_prepend_mgr();
|
||||
public void Clear_all() {Clear(true);}
|
||||
public void Clear(boolean clear_scrib) { // NOTE: this is called post-fetch but pre-wtxt; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
|
||||
db.Clear();
|
||||
redirect_trail.Clear();
|
||||
html.Clear();
|
||||
hdump.Clear();
|
||||
wtxt.Clear();
|
||||
|
||||
lnki_list.Clear();
|
||||
file_math.Clear();
|
||||
file_queue.Clear();
|
||||
ref_mgr.Grps_clear();
|
||||
html_cmd_mgr.Clear();
|
||||
wdata_external_lang_links.Reset();
|
||||
if (clear_scrib) wiki.Parser_mgr().Scrib().When_page_changed(this);
|
||||
slink_list.Clear();
|
||||
tab_data.Clear();
|
||||
popup_mgr.Clear();
|
||||
tmpl_prepend_mgr.Clear();
|
||||
commons_mgr.Clear();
|
||||
}
|
||||
public static final Xoae_page Empty = new Xoae_page();
|
||||
public static Xoae_page New(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page New_test(Xowe_wiki wiki, Xoa_ttl ttl) {return new Xoae_page(wiki, ttl);}
|
||||
public static Xoae_page New_edit(Xowe_wiki wiki, Xoa_ttl ttl) {
|
||||
Xoae_page rv = new Xoae_page(wiki, ttl);
|
||||
rv.edit_mode = Xoa_page_.Edit_mode_create;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoae_page__tst {
|
||||
private final Xoae_page__fxt fxt = new Xoae_page__fxt();
|
||||
@Test public void Ttl() {
|
||||
fxt.Init__page("Abc");
|
||||
fxt.Exec__ttl("Заглавная_страница");
|
||||
fxt.Test__url("en.wikipedia.org/wiki/Заглавная_страница"); // fails if "%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0"; DATE:2016-11-25
|
||||
}
|
||||
}
|
||||
class Xoae_page__fxt {
|
||||
private Xoae_page page;
|
||||
private Xowe_wiki wiki;
|
||||
public Xoae_page__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
public void Init__page(String ttl) {
|
||||
page = Xoae_page.New(wiki, wiki.Ttl_parse(Bry_.new_u8(ttl)));
|
||||
}
|
||||
public void Exec__ttl(String raw) {
|
||||
page.Ttl_(wiki.Ttl_parse(Bry_.new_u8(raw)));
|
||||
}
|
||||
public void Test__url(String expd) {
|
||||
Gftest.Eq__str(expd, page.Url().To_str(), "url");
|
||||
}
|
||||
}
|
||||
@@ -1,485 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.tests.*; import gplx.core.log_msgs.*;
|
||||
import gplx.xowa.apps.cfgs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.files.exts.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.hives.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xop_fxt {
|
||||
public Xop_fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
ctor(app, wiki);
|
||||
}
|
||||
public Xop_fxt(Xoae_app app, Xowe_wiki wiki) {
|
||||
this.ctor(app, wiki);
|
||||
}
|
||||
private void ctor(Xoae_app app, Xowe_wiki wiki) {
|
||||
this.app = app;
|
||||
this.wiki = wiki;
|
||||
app.Wiki_mgr().Add(wiki);
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/wiki/repo/src/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/wiki/repo/trg/", wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
ctx = wiki.Parser_mgr().Ctx();
|
||||
mock_wkr.Clear_commons(); // assume all files are in repo 0
|
||||
wiki.File_mgr().Repo_mgr().Page_finder_(mock_wkr);
|
||||
parser = wiki.Parser_mgr().Main();
|
||||
this.tkn_mkr = app.Parser_mgr().Tkn_mkr();
|
||||
ctx.Para().Enabled_n_();
|
||||
hdom_wtr = wiki.Html_mgr().Html_wtr();
|
||||
wiki.Html_mgr().Img_suppress_missing_src_(false);
|
||||
wiki.Xtn_mgr().Init_by_wiki(wiki);
|
||||
Page_ttl_(Ttl_str);
|
||||
Xot_invk_tkn.Cache_enabled = false;// always disable cache for tests; can cause strange behavior when running entire suite and lnki_temp test turns on;
|
||||
}
|
||||
private Xofw_wiki_wkr_mock mock_wkr = new Xofw_wiki_wkr_mock();
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xop_ctx Ctx() {return ctx;} private Xop_ctx ctx;
|
||||
public Xop_parser Parser() {return parser;} private Xop_parser parser;
|
||||
public Xoae_page Page() {return ctx.Page();}
|
||||
public void Lang_by_id_(int id) {ctx.Page().Lang_(wiki.Appe().Lang_mgr().Get_by_or_new(Xol_lang_stub_.Get_by_id(id).Key()));}
|
||||
public Xoh_html_wtr_cfg Wtr_cfg() {return hdom_wtr.Cfg();} private Xoh_html_wtr hdom_wtr;
|
||||
public Xop_fxt Reset() {
|
||||
ctx.Clear_all();
|
||||
ctx.App().Free_mem(false);
|
||||
ctx.Page().Clear_all();
|
||||
wiki.File_mgr().Clear_for_tests();
|
||||
wiki.Db_mgr().Load_mgr().Clear();
|
||||
app.Wiki_mgr().Clear();
|
||||
Io_mgr.Instance.InitEngine_mem(); // clear created pages
|
||||
wiki.Cfg_parser().Display_title_restrict_(false); // default to false, as a small number of tests assume restrict = false;
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Reset_for_msgs() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
wiki.Lang().Msg_mgr().Clear(); // need to clear out lang
|
||||
wiki.Msg_mgr().Clear(); // need to clear out wiki.Msgs
|
||||
this.Reset();
|
||||
return this;
|
||||
}
|
||||
public Xoa_ttl Page_ttl_(String txt) {
|
||||
Xoa_ttl rv = Xoa_ttl.Parse(wiki, Bry_.new_u8(txt));
|
||||
ctx.Page().Ttl_(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public Xop_tkn_chkr_base tkn_bry_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_bry).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_txt_() {return tkn_txt_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_tkn_chkr_base tkn_txt_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_txt).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_space_() {return tkn_space_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_tkn_chkr_base tkn_space_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_space).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_eq_(int bgn) {return tkn_eq_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_eq_(int bgn, int end) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_eq).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_colon_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_colon).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_pipe_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_pipe).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_tkn_chkr_base tkn_tab_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tab).Src_rng_(bgn, bgn + 1);}
|
||||
public Xop_apos_tkn_chkr tkn_apos_(int cmd) {return new Xop_apos_tkn_chkr().Apos_cmd_(cmd);}
|
||||
public Xop_ignore_tkn_chkr tkn_comment_(int bgn, int end) {return tkn_ignore_(bgn, end, Xop_ignore_tkn.Ignore_tid_comment);}
|
||||
public Xop_ignore_tkn_chkr tkn_ignore_(int bgn, int end, byte t){return (Xop_ignore_tkn_chkr)new Xop_ignore_tkn_chkr().Ignore_tid_(t).Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_hr tkn_hr_(int bgn, int end) {return new Xop_tkn_chkr_hr(bgn, end).Hr_len_(Xop_hr_lxr.Hr_len);}
|
||||
public Xop_tblw_tb_tkn_chkr tkn_tblw_tb_(int bgn, int end) {return (Xop_tblw_tb_tkn_chkr)new Xop_tblw_tb_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_tc_tkn_chkr tkn_tblw_tc_(int bgn, int end) {return (Xop_tblw_tc_tkn_chkr)new Xop_tblw_tc_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_td_tkn_chkr tkn_tblw_td_(int bgn, int end) {return (Xop_tblw_td_tkn_chkr)new Xop_tblw_td_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_th_tkn_chkr tkn_tblw_th_(int bgn, int end) {return (Xop_tblw_th_tkn_chkr)new Xop_tblw_th_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tblw_tr_tkn_chkr tkn_tblw_tr_(int bgn, int end) {return (Xop_tblw_tr_tkn_chkr)new Xop_tblw_tr_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_br_(int pos) {return tkn_xnde_(pos, pos).Xnde_tagId_(Xop_xnde_tag_.Tid__br);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_() {return tkn_xnde_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_xnde_tkn_chkr tkn_xnde_(int bgn, int end) {return (Xop_xnde_tkn_chkr)new Xop_xnde_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_tkn_chkr_base tkn_curly_bgn_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tmpl_curly_bgn).Src_rng_(bgn, bgn + 2);}
|
||||
public Xop_tkn_chkr_base tkn_para_blank_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_pre);}
|
||||
public Xop_tkn_chkr_base tkn_para_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_none, Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_mid_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_pre_bgn_para_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_para);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_para_bgn_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_para, Xop_para_tkn.Tid_pre);}
|
||||
public Xop_tkn_chkr_base tkn_para_end_pre_(int pos) {return tkn_para_(pos, Xop_para_tkn.Tid_pre , Xop_para_tkn.Tid_none);}
|
||||
public Xop_tkn_chkr_base tkn_para_(int pos, byte end, byte bgn) {return new Xop_para_tkn_chkr().Para_end_(end).Para_bgn_(bgn).Src_rng_(pos, pos);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_(int bgn, int end) {return tkn_nl_(bgn, end, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_len1_(int bgn) {return tkn_nl_(bgn, bgn + 1, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_char_len0_(int pos) {return tkn_nl_(pos, pos, Xop_nl_tkn.Tid_char);}
|
||||
public Xop_tkn_chkr_base tkn_nl_(int bgn, int end, byte tid) {return new Xop_nl_tkn_chkr().Nl_tid_(tid).Src_rng_(bgn, end);}
|
||||
public Xop_list_tkn_chkr tkn_list_bgn_(int bgn, int end, byte listType) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().List_itmTyp_(listType).Src_rng_(bgn, end);}
|
||||
public Xop_list_tkn_chkr tkn_list_end_(int pos) {return (Xop_list_tkn_chkr)new Xop_list_tkn_chkr().Src_rng_(pos, pos);}
|
||||
public Xop_tkn_chkr_lnke tkn_lnke_(int bgn, int end) {return new Xop_tkn_chkr_lnke(bgn, end);}
|
||||
public Xop_lnki_tkn_chkr tkn_lnki_() {return tkn_lnki_(-1, -1);}
|
||||
public Xop_lnki_tkn_chkr tkn_lnki_(int bgn, int end) {return (Xop_lnki_tkn_chkr)new Xop_lnki_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_arg_itm_tkn_chkr tkn_arg_itm_(Xop_tkn_chkr_base... subs) {return (Xop_arg_itm_tkn_chkr)new Xop_arg_itm_tkn_chkr().Subs_(subs);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_nde_() {return tkn_arg_nde_(String_.Pos_neg1, String_.Pos_neg1);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_nde_(int bgn, int end) {return (Xop_arg_nde_tkn_chkr)new Xop_arg_nde_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_val_(Xop_tkn_chkr_base... subs) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr val = new Xop_arg_itm_tkn_chkr();
|
||||
val.Subs_(subs);
|
||||
rv.Val_tkn_(val);
|
||||
return rv;
|
||||
}
|
||||
public Xop_arg_nde_tkn_chkr tkn_arg_val_txt_(int bgn, int end) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
|
||||
rv.Val_tkn_(itm);
|
||||
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
|
||||
return rv;
|
||||
}
|
||||
Xop_arg_nde_tkn_chkr tkn_arg_key_txt_(int bgn, int end) {
|
||||
Xop_arg_nde_tkn_chkr rv = new Xop_arg_nde_tkn_chkr();
|
||||
Xop_arg_itm_tkn_chkr itm = new Xop_arg_itm_tkn_chkr();
|
||||
rv.Key_tkn_(itm);
|
||||
itm.Src_rng_(bgn, end).Subs_(tkn_txt_(bgn, end));
|
||||
return rv;
|
||||
}
|
||||
public Xot_invk_tkn_chkr tkn_tmpl_invk_(int bgn, int end) {return (Xot_invk_tkn_chkr)new Xot_invk_tkn_chkr().Src_rng_(bgn, end);}
|
||||
public Xot_invk_tkn_chkr tkn_tmpl_invk_w_name(int bgn, int end, int name_bgn, int name_end) {
|
||||
Xot_invk_tkn_chkr rv = new Xot_invk_tkn_chkr();
|
||||
rv.Src_rng_(bgn, end);
|
||||
rv.Name_tkn_(tkn_arg_key_txt_(name_bgn, name_end));
|
||||
return rv;
|
||||
}
|
||||
public Xot_prm_chkr tkn_tmpl_prm_find_(Xop_tkn_chkr_base find) {
|
||||
Xot_prm_chkr rv = new Xot_prm_chkr();
|
||||
rv.Find_tkn_(tkn_arg_itm_(find));
|
||||
return rv;
|
||||
}
|
||||
public Xop_fxt Init_para_y_() {ctx.Para().Enabled_y_(); return this;}
|
||||
public Xop_fxt Init_para_n_() {ctx.Para().Enabled_n_(); return this;}
|
||||
public Xop_fxt Init_log_(Gfo_msg_itm... itms) {for (Gfo_msg_itm itm : itms) log_itms.Add(itm); return this;} List_adp log_itms = List_adp_.New();
|
||||
public void Init_defn_add(String name, String text) {Init_defn_add(name, text, Xow_ns_case_.Tid__all);}
|
||||
public void Init_defn_add(String name, String text, byte case_match) {
|
||||
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.new_a7(name), Bry_.new_u8(text));
|
||||
wiki.Cache_mgr().Defn_cache().Add(itm, case_match);
|
||||
}
|
||||
public void Init_defn_clear() {wiki.Cache_mgr().Defn_cache().Free_mem_all();}
|
||||
public Xop_fxt Init_id_create(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Xow_hive_mgr_fxt.Create_id(app, wiki.Hive_mgr(), id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;}
|
||||
public Xop_fxt Init_page_create(String ttl) {return Init_page_create(wiki, ttl, "");}
|
||||
public Xop_fxt Init_page_create(String ttl, String txt) {return Init_page_create(wiki, ttl, txt);}
|
||||
public Xop_fxt Init_page_create(Xowe_wiki wiki, String ttl, String txt) {Init_page_create_static(wiki, ttl, txt);return this;}
|
||||
public static void Init_page_create_static(Xowe_wiki wiki, String ttl_str, String text_str) {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
|
||||
byte[] text = Bry_.new_u8(text_str);
|
||||
wiki.Db_mgr().Save_mgr().Data_create(ttl, text);
|
||||
}
|
||||
public static void Init_msg(Xowe_wiki wiki, String key, String val) {
|
||||
wiki.Lang().Msg_mgr().Itm_by_key_or_new(key, val);
|
||||
}
|
||||
public Xop_fxt Init_page_update(String ttl, String txt) {return Init_page_update(wiki, ttl, txt);}
|
||||
public Xop_fxt Init_page_update(Xowe_wiki wiki, String ttl, String txt) {
|
||||
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl));
|
||||
byte[] page_raw = Bry_.new_u8(txt);
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(page_ttl);
|
||||
wiki.Db_mgr().Save_mgr().Data_update(page, page_raw);
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_clear() {
|
||||
wiki.Xwiki_mgr().Clear();
|
||||
app.Usere().Wiki().Xwiki_mgr().Clear();
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_add_wiki_and_user_(String alias, String domain) {
|
||||
wiki.Xwiki_mgr().Add_by_atrs(alias, domain);
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain);
|
||||
return this;
|
||||
}
|
||||
public Xop_fxt Init_xwiki_add_user_(String domain) {return Init_xwiki_add_user_(domain, domain);}
|
||||
public Xop_fxt Init_xwiki_add_user_(String alias, String domain) {
|
||||
app.Usere().Wiki().Xwiki_mgr().Add_by_atrs(alias, domain);
|
||||
return this;
|
||||
}
|
||||
public void Test_parse_template(String tmpl_raw, String expd) {Test_parse_tmpl_str_test(tmpl_raw, "{{test}}", expd);}
|
||||
public void Test_parse_tmpl_str_test(String tmpl_raw, String page_raw, String expd) {
|
||||
Init_defn_add("test", tmpl_raw);
|
||||
Test_parse_tmpl_str(page_raw, expd);
|
||||
}
|
||||
public void Test_parse_tmpl_str(String raw, String expd) {
|
||||
byte[] actl = Test_parse_tmpl_str_rv(raw);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public byte[] Test_parse_tmpl_str_rv(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
ctx.Page().Root_(root);
|
||||
ctx.Page().Db().Text().Text_bry_(raw_bry);
|
||||
return parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
}
|
||||
public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);}
|
||||
public void Test_parse_tmpl(String raw, Tst_chkr... expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xot_defn_tmpl itm = run_Parse_tmpl(Bry_.Empty, raw_bry);
|
||||
Parse_chk(raw_bry, itm.Root(), expd);
|
||||
}
|
||||
public void Test_parse_page_tmpl_str(String raw, String expd) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
byte[] actl = parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Test_parse_page_wiki(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = Test_parse_page_wiki_root(raw_bry);
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public Xop_root_tkn Test_parse_page_wiki_root(String raw) {return Test_parse_page_wiki_root(Bry_.new_u8(raw));}
|
||||
Xop_root_tkn Test_parse_page_wiki_root(byte[] raw_bry) {
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
return root;
|
||||
}
|
||||
public void Test_parse_page_all(String raw, Tst_chkr... expd_ary) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);}
|
||||
public void Test_parse_page_all_str__esc(String raw, String expd) {Test_parse_page_all_str(raw, Xoh_consts.Escape_apos(expd));}
|
||||
public void Test_parse_page_all_str(String raw, String expd) {
|
||||
String actl = Exec_parse_page_all_as_str(raw);
|
||||
Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw);
|
||||
}
|
||||
public void Test_parse_page_all_str_and_chk(String raw, String expd, Gfo_msg_itm... ary) {
|
||||
this.Init_log_(ary);
|
||||
Test_parse_page_all_str(raw, expd);
|
||||
this.tst_Log_check();
|
||||
}
|
||||
public Xop_root_tkn Exec_parse_page_all_as_root(byte[] raw_bry) {
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_page_all_clear(root, ctx, tkn_mkr, raw_bry);
|
||||
return root;
|
||||
}
|
||||
public String Exec_parse_page_all_as_str(String raw) {
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
Bry_bfr actl_bfr = Bry_bfr_.New();
|
||||
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, root.Root_src(), root);
|
||||
return actl_bfr.To_str_and_clear();
|
||||
}
|
||||
public Xoh_wtr_ctx Hctx() {return hctx;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
|
||||
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;}
|
||||
public String Exec_parse_page_wiki_as_str(String raw) {
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
|
||||
Bry_bfr actl_bfr = Bry_bfr_.New();
|
||||
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, raw_bry, root);
|
||||
return actl_bfr.To_str_and_clear();
|
||||
}
|
||||
private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) {
|
||||
int subs_len = root.Subs_len();
|
||||
Object[] actl_ary = new Object[subs_len];
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
actl_ary[i] = root.Subs_get(i);
|
||||
tst_mgr.Vars().Clear().Add("raw_bry", raw_bry);
|
||||
tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary);
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_fxt Test_parse_page_wiki_str__esc(String raw, String expd) {return Test_parse_page_wiki_str(raw, Xoh_consts.Escape_apos(expd));}
|
||||
public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) {
|
||||
String actl = Exec_parse_page_wiki_as_str(raw);
|
||||
Tfds.Eq_str_lines(expd, actl, raw);
|
||||
return this;
|
||||
}
|
||||
public void Log_clear() {ctx.App().Msg_log().Clear();}
|
||||
public String[] Log_xtoAry() {
|
||||
Gfo_msg_log msg_log = app.Msg_log();
|
||||
int len = msg_log.Ary_len();
|
||||
List_adp actl_list = List_adp_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_data eny = msg_log.Ary_get(i);
|
||||
if (eny.Item().Cmd() > Gfo_msg_itm_.Cmd_note) {
|
||||
actl_list.Add(String_.new_u8(eny.Item().Path_bry()));
|
||||
}
|
||||
}
|
||||
String[] actl = actl_list.To_str_ary();
|
||||
msg_log.Clear();
|
||||
return actl;
|
||||
}
|
||||
public Xop_fxt tst_Log_check() {
|
||||
int len = log_itms.Count();
|
||||
String[] expd = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_msg_itm itm = (Gfo_msg_itm)log_itms.Get_at(i);
|
||||
expd[i] = itm.Path_str();
|
||||
}
|
||||
log_itms.Clear();
|
||||
String[] actl = Log_xtoAry();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public void tst_Warn(String... expd) {
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
Gfo_usr_dlg__gui_test ui_wkr = (Gfo_usr_dlg__gui_test)usr_dlg.Gui_wkr();
|
||||
String[] actl = ui_wkr.Warns().To_str_ary();
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
public void Test_parse_page(String ttl, String expd) {
|
||||
byte[] actl = Load_page(wiki, ttl);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public static byte[] Load_page(Xowe_wiki wiki, String ttl_str) {
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
Xoa_url page_url = Xoa_url.New(wiki.Domain_bry(), ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ttl_bry);
|
||||
return wiki.Data_mgr().Load_page_and_parse(page_url, ttl).Db().Text().Text_bry();
|
||||
}
|
||||
public static void Reg_xwiki_alias(Xowe_wiki wiki, String alias, String domain) {
|
||||
byte[] domain_bry = Bry_.new_a7(domain);
|
||||
wiki.Xwiki_mgr().Add_by_atrs(Bry_.new_a7(alias), domain_bry, Bry_.Add(domain_bry, Bry_.new_a7("/wiki/~{0}")));
|
||||
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain_bry, domain_bry);
|
||||
}
|
||||
public static String html_img_none(String trg, String alt, String src, String ttl) {
|
||||
return String_.Format(String_.Concat_lines_nl_skip_last("<a href=\"/wiki/{0}\" class=\"image\" xowa_title=\"{3}\"><img id=\"xoimg_0\" alt=\"{1}\" src=\"{2}\" width=\"9\" height=\"8\" /></a>"), trg, alt, src, ttl);
|
||||
}
|
||||
private String Exec_html_full(String raw) {return this.Exec_parse_page_all_as_str(raw);}
|
||||
private String Exec_html_wiki(String raw) {return this.Exec_parse_page_wiki_as_str(raw);}
|
||||
public void Test_html_wiki_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_wiki(raw));}
|
||||
public void Test_html_full_str(String raw, String expd) {Test_str_full(raw, expd, Exec_html_full(raw));}
|
||||
public void Test_html_wiki_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_wiki(raw), expd_frags);}
|
||||
public void Test_html_full_frag(String raw, String... expd_frags) {Test_str_part_y(Exec_html_full(raw), expd_frags);}
|
||||
public void Test_html_full_frag_n(String raw, String... expd_frags) {Test_str_part_n(Exec_html_full(raw), expd_frags);}
|
||||
public void Test__parse__tmpl_to_html(String raw, String expd) {Test_str_full(raw, gplx.langs.htmls.Gfh_utl.Replace_apos(expd), Exec_html_full(raw));}
|
||||
public void Test__parse__wtxt_to_html(String raw, String expd) {
|
||||
String actl = Exec_html_wiki(raw);
|
||||
Tfds.Eq_str_lines(gplx.langs.htmls.Gfh_utl.Replace_apos(expd), actl, raw);
|
||||
}
|
||||
|
||||
public void Test_str_full(String raw, String expd, String actl) {
|
||||
Tfds.Eq_str_lines(expd, actl, raw);
|
||||
}
|
||||
public void Test_str_part_y(String actl, String... expd_parts) {
|
||||
int expd_parts_len = expd_parts.length;
|
||||
for (int i = 0; i < expd_parts_len; i++) {
|
||||
String expd_part = expd_parts[i];
|
||||
boolean pass = String_.Has(actl, expd_part);
|
||||
if (!pass)
|
||||
Tfds.Eq_true(false, expd_part + "\n" + actl);
|
||||
}
|
||||
}
|
||||
private void Test_str_part_n(String actl, String... expd_parts) {
|
||||
int expd_parts_len = expd_parts.length;
|
||||
for (int i = 0; i < expd_parts_len; i++) {
|
||||
String expd_part = expd_parts[i];
|
||||
boolean has = String_.Has(actl, expd_part);
|
||||
if (has)
|
||||
Tfds.Eq_true(false, expd_part + "\n" + actl);
|
||||
}
|
||||
}
|
||||
public void Test_html_modules_js(String expd) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
this.Page().Html_data().Head_mgr().Init(app, wiki, this.Page());
|
||||
this.Page().Html_data().Head_mgr().Bfr_arg__add(bfr);
|
||||
bfr.Mkr_rls();
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
|
||||
private Tst_mgr tst_mgr = new Tst_mgr(); private Xop_tkn_mkr tkn_mkr;
|
||||
public static final String Ttl_str = "Test page";
|
||||
public Xop_fxt Init_lang_numbers_separators_en() {return Init_lang_numbers_separators(",", ".");}
|
||||
public Xop_fxt Init_lang_numbers_separators(String grp_spr, String dec_spr) {return Init_lang_numbers_separators(wiki.Lang(), grp_spr, dec_spr);}
|
||||
public Xop_fxt Init_lang_numbers_separators(Xol_lang_itm lang, String grp_spr, String dec_spr) {
|
||||
gplx.xowa.langs.numbers.Xol_transform_mgr separator_mgr = lang.Num_mgr().Separators_mgr();
|
||||
separator_mgr.Clear();
|
||||
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_u8(grp_spr));
|
||||
separator_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__dec, Bry_.new_u8(dec_spr));
|
||||
return this;
|
||||
}
|
||||
public void Init_lang_kwds(int kwd_id, boolean case_match, String... kwds) {Init_lang_kwds(wiki.Lang(), kwd_id, case_match, kwds);}
|
||||
public void Init_lang_kwds(Xol_lang_itm lang, int kwd_id, boolean case_match, String... kwds) {
|
||||
Xol_kwd_mgr kwd_mgr = lang.Kwd_mgr();
|
||||
Xol_kwd_grp kwd_grp = kwd_mgr.Get_or_new(kwd_id);
|
||||
kwd_grp.Srl_load(case_match, Bry_.Ary(kwds));
|
||||
}
|
||||
public void Init_lang_vnts(String... vnts) {
|
||||
wiki.Lang().Vnt_mgr().Enabled_(true);
|
||||
gplx.xowa.langs.vnts.Xol_vnt_regy vnt_regy = wiki.Lang().Vnt_mgr().Regy();
|
||||
for (int i = 0; i < vnts.length; i++) {
|
||||
byte[] vnt = Bry_.new_u8(vnts[i]);
|
||||
vnt_regy.Add(vnt, vnt);
|
||||
if (i == 0) {
|
||||
wiki.Lang().Vnt_mgr().Cur_itm_(vnt);
|
||||
}
|
||||
}
|
||||
wiki.Lang().Vnt_mgr().Init_end();
|
||||
}
|
||||
public void Init_xtn_pages() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
wiki.Xtn_mgr().Xtn_proofread().Enabled_y_();
|
||||
wiki.Db_mgr().Load_mgr().Clear(); // must clear; otherwise fails b/c files get deleted, but wiki.data_mgr caches the Xowd_regy_mgr (the .reg file) in memory;
|
||||
wiki.Ns_mgr().Add_new(Xowc_xtn_pages.Ns_page_id_default, "Page").Add_new(Xowc_xtn_pages.Ns_index_id_default, "Index").Init();
|
||||
}
|
||||
public void Clear_ref_mgr() {this.Page().Ref_mgr().Grps_clear();} // clear to reset count
|
||||
public static Xop_fxt new_nonwmf() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
return new Xop_fxt(app, Xoa_app_fxt.Make__wiki__edit__nonwmf(app, "nethackwiki"));
|
||||
}
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
|
||||
public String Exec__parse_to_hdump(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry);
|
||||
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
|
||||
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
|
||||
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
|
||||
ctx.Page().Html_data().Redlink_list().Clear();
|
||||
html_wtr.Write_doc(tmp_bfr, ctx, hctx, src_bry, root);
|
||||
// Tfds.Dbg(tmp_bfr.To_str());
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
public void Test__parse_to_html_mgr(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
Xop_root_tkn root = Exec_parse_page_all_as_root(src_bry);
|
||||
Xoae_page page = this.Page();
|
||||
page.Root_(root);
|
||||
byte[] actl = wiki.Html_mgr().Page_wtr_mgr().Gen(page, gplx.xowa.wikis.pages.Xopg_page_.Tid_read);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public String Exec__parse_to_html_w_skin(String raw) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Xow_html_mgr html_mgr = wiki.Html_mgr();
|
||||
this.Wiki().Html__wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
|
||||
|
||||
byte[] raw_bry = Bry_.new_u8(raw);
|
||||
Xop_root_tkn root = this.Exec_parse_page_all_as_root(raw_bry);
|
||||
this.Page().Root_(root);
|
||||
|
||||
html_mgr.Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_page(bfr, this.Page(), this.Ctx(), Xoh_page_html_source_.Wtr);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public void Test__parse_to_html_w_skin(String raw, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Exec__parse_to_html_w_skin(raw));
|
||||
}
|
||||
public static Xop_fxt New_app_html() {
|
||||
Xop_fxt fxt = new Xop_fxt();
|
||||
fxt.Wiki().Html_mgr().Page_wtr_mgr().Page_read_fmtr().Fmt_("~{page_data}");
|
||||
return fxt;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.ios.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.addons.*; import gplx.xowa.wikis.fsys.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.fsdb.meta.*; import gplx.fsdb.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
public interface Xow_wiki extends Xow_ttl_parser, Gfo_invk {
|
||||
boolean Type_is_edit();
|
||||
Xoa_app App();
|
||||
Xol_lang_itm Lang();
|
||||
Xol_case_mgr Case_mgr();
|
||||
byte[] Domain_bry(); // EX: en.wikipedia.org
|
||||
String Domain_str();
|
||||
int Domain_tid(); // Xow_domain_tid_.Tid__wikipedia
|
||||
byte[] Domain_abrv(); // enwiki
|
||||
Xow_domain_itm Domain_itm();
|
||||
Xow_fsys_mgr Fsys_mgr();
|
||||
Xow_db_mgr Data__core_mgr();
|
||||
Xof_fsdb_mode File__fsdb_mode();
|
||||
Fsdb_db_mgr File__fsdb_core();
|
||||
Xow_repo_mgr File__repo_mgr();
|
||||
Xof_orig_mgr File__orig_mgr();
|
||||
Xof_bin_mgr File__bin_mgr();
|
||||
Fsm_mnt_mgr File__mnt_mgr();
|
||||
boolean Html__hdump_enabled();
|
||||
Xow_hdump_mgr Html__hdump_mgr();
|
||||
Xoh_page_wtr_mgr Html__wtr_mgr();
|
||||
Xoh_href_wtr Html__href_wtr();
|
||||
Xoh_lnki_bldr Html__lnki_bldr();
|
||||
Xoctg_pagebox_wtr Ctg__pagebox_wtr();
|
||||
Xoctg_catpage_mgr Ctg__catpage_mgr();
|
||||
boolean Html__css_installing(); void Html__css_installing_(boolean v);
|
||||
Xow_msg_mgr Msg_mgr();
|
||||
byte[] Wtxt__expand_tmpl(byte[] src);
|
||||
Xow_mw_parser_mgr Mw_parser_mgr();
|
||||
Xow_xwiki_mgr Xwiki_mgr();
|
||||
Xow_wiki_props Props();
|
||||
Xowd_site_stats_mgr Stats();
|
||||
void Init_by_wiki();
|
||||
void Init_by_wiki__force(); // HACK: force init for drd wiki
|
||||
Bry_bfr_mkr Utl__bfr_mkr();
|
||||
Io_stream_zip_mgr Utl__zip_mgr();
|
||||
Xow_url_parser Utl__url_parser();
|
||||
Xoax_addon_mgr Addon_mgr();
|
||||
boolean Embeddable_enabled(); void Embeddable_enabled_(boolean v);
|
||||
void Init_needed_y_();
|
||||
void Rls();
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.bldrs.infos.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_wiki_ {
|
||||
public static void Create_sql_backend(Xow_wiki wiki, gplx.xowa.wikis.data.Xowd_core_db_props core_db_props, gplx.xowa.bldrs.infos.Xob_info_session session) {
|
||||
if (wiki.Type_is_edit()) {
|
||||
Xowe_wiki wikie = (Xowe_wiki)wiki;
|
||||
wikie.Db_mgr_create_as_sql(); // edit-wikis are created with text-backend; convert to sql
|
||||
wiki.Data__core_mgr().Init_by_make(core_db_props, session); // make core_db
|
||||
}
|
||||
else {
|
||||
Xowv_wiki wikiv = (Xowv_wiki)wiki;
|
||||
wikiv.Init_by_make(core_db_props, session); // make core_db
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
public class Xowa_main {
|
||||
public static void main(String[] args) {
|
||||
gplx.xowa.Xoa_app_.Run(args);
|
||||
}
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.ios.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.cfgs.*; import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.caches.*; import gplx.xowa.wikis.fsys.*;
|
||||
import gplx.xowa.users.*; import gplx.xowa.htmls.*; import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.*; import gplx.xowa.wikis.dbs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.exts.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.ns_files.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.bldrs.xmls.*; import gplx.xowa.bldrs.installs.*; import gplx.xowa.bldrs.setups.maints.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.utils.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.guis.cbks.*; import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.xtns.gallery.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*;
|
||||
import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.htmls.css.mgrs.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
|
||||
private boolean init_in_process = false;
|
||||
public Xowe_wiki(Xoae_app app, Xol_lang_itm lang, Xow_ns_mgr ns_mgr, Xow_domain_itm domain_itm, Io_url wiki_dir) {
|
||||
this.ev_mgr = new Gfo_evt_mgr(this);
|
||||
this.app = app; this.lang = lang; this.ns_mgr = ns_mgr;
|
||||
|
||||
this.domain_itm = domain_itm;
|
||||
this.domain_bry = domain_itm.Domain_bry();
|
||||
this.domain_str = domain_itm.Domain_str();
|
||||
this.domain_tid = domain_itm.Domain_type_id();
|
||||
this.domain_abrv = Xow_abrv_wm_.To_abrv(domain_itm);
|
||||
|
||||
this.fsys_mgr = new Xow_fsys_mgr(wiki_dir, app.Fsys_mgr().File_dir().GenSubDir(domain_str));
|
||||
|
||||
this.url__parser = new Xow_url_parser(this);
|
||||
this.xwiki_mgr = new Xow_xwiki_mgr(this);
|
||||
this.html__hdump_mgr = new Xow_hdump_mgr(this);
|
||||
this.html_mgr = new Xow_html_mgr(this);
|
||||
this.page_mgr = new Xowe_page_mgr(this);
|
||||
this.sanitizer = new Xop_sanitizer(app.Parser_amp_mgr(), app.Msg_log());
|
||||
|
||||
tdb_fsys_mgr = new Xotdb_fsys_mgr(wiki_dir, ns_mgr);
|
||||
redirect_mgr = new Xop_redirect_mgr(this);
|
||||
data_mgr = new Xow_page_mgr(this);
|
||||
file_mgr = new Xow_file_mgr(this);
|
||||
parser_mgr = new Xow_parser_mgr(this);
|
||||
cfg_parser = new Xowc_parser(this);
|
||||
props.Init_by_ctor(domain_tid, domain_bry);
|
||||
props.ContentLanguage_(lang.Key_bry());
|
||||
stats = new Xowd_site_stats_mgr(this);
|
||||
Pf_func_.Reg(domain_itm, lang.Func_regy(), lang);
|
||||
special_mgr = new Xow_special_mgr(this, lang);
|
||||
sys_cfg = new Xow_sys_cfg(this);
|
||||
hive_mgr = new Xob_hive_mgr(this);
|
||||
util = new Xow_html_util(this);
|
||||
import_cfg = new Xob_import_cfg(this);
|
||||
msg_mgr = new Xow_msg_mgr(this, lang);
|
||||
eval_mgr = new Bfmtr_eval_wiki(this);
|
||||
fragment_mgr = new Xow_fragment_mgr(this);
|
||||
xtn_mgr = new Xow_xtn_mgr().Ctor_by_wiki(this);
|
||||
if (domain_tid == Xow_domain_tid_.Tid__home) {
|
||||
wdata_wiki_tid = Xow_domain_tid_.Tid__wikipedia;
|
||||
wdata_wiki_lang = Xol_lang_itm_.Key_en;
|
||||
}
|
||||
else {
|
||||
wdata_wiki_tid = domain_tid;
|
||||
wdata_wiki_lang = domain_itm.Lang_orig_key(); // NOTE: must use orig_key for nowiki; "no" not "nb" DATE:2014-10-07
|
||||
}
|
||||
Wdata_wiki_abrv_();
|
||||
db_mgr = new gplx.xowa.wikis.dbs.Xodb_mgr_txt(this, data_mgr);
|
||||
maint_mgr = new Xow_maint_mgr(this);
|
||||
cache_mgr = new Xow_cache_mgr(this);
|
||||
/*if (Bry_.Eq(domain_bry, Xow_domain_itm_.Bry__home))*/ xwiki_mgr.Add_by_atrs(domain_bry, domain_bry); // add full name to xwiki_mgr; needed for lookup in home ns; EX: [[home:Help/Contents]]
|
||||
this.lnki_bldr = new Xoh_lnki_bldr(app, href_wtr);
|
||||
this.ctg_catpage_mgr = new Xoctg_catpage_mgr(this);
|
||||
}
|
||||
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private final Gfo_evt_mgr ev_mgr;
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;} private final Xow_ns_mgr ns_mgr;
|
||||
public Xoa_ttl Ttl_parse(byte[] ttl) {return Xoa_ttl.Parse(this, ttl);}
|
||||
public Xoa_ttl Ttl_parse(byte[] src, int src_bgn, int src_end) {return Xoa_ttl.Parse(this, src, src_bgn, src_end);}
|
||||
public Xoa_ttl Ttl_parse(int ns_id, byte[] ttl) {return Xoa_ttl.Parse(this, ns_id, ttl);}
|
||||
public boolean Type_is_edit() {return Bool_.Y;}
|
||||
public Xoa_app App() {return app;}
|
||||
public Xol_lang_itm Lang() {return lang;} private Xol_lang_itm lang;
|
||||
public Xol_case_mgr Case_mgr() {return lang.Case_mgr();}
|
||||
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private final String domain_str;
|
||||
public int Domain_tid() {return domain_tid;} private final int domain_tid;
|
||||
public byte[] Domain_abrv() {return domain_abrv;} private final byte[] domain_abrv;
|
||||
public Xow_domain_itm Domain_itm() {return domain_itm;} private final Xow_domain_itm domain_itm;
|
||||
public Xow_fsys_mgr Fsys_mgr() {return fsys_mgr;} private final Xow_fsys_mgr fsys_mgr;
|
||||
public Xow_db_mgr Data__core_mgr() {if (db_mgr == null) return null; return db_mgr.Tid() == Xodb_mgr_txt.Tid_txt ? null : this.Db_mgr_as_sql().Core_data_mgr();} // TEST:
|
||||
public Xof_fsdb_mode File__fsdb_mode() {return file_mgr.Fsdb_mode();}
|
||||
public Fsdb_db_mgr File__fsdb_core() {return file_mgr.Db_core();}
|
||||
public Xow_repo_mgr File__repo_mgr() {return file_mgr.Repo_mgr();}
|
||||
public Xof_orig_mgr File__orig_mgr() {return file_mgr.Orig_mgr();}
|
||||
public Xof_bin_mgr File__bin_mgr() {return file_mgr.Fsdb_mgr().Bin_mgr();}
|
||||
public Fsm_mnt_mgr File__mnt_mgr() {return file_mgr.Fsdb_mgr().Mnt_mgr();}
|
||||
public boolean Html__hdump_enabled() {return html_mgr__hdump_enabled;} private boolean html_mgr__hdump_enabled = Bool_.N;
|
||||
public Xoh_page_wtr_mgr Html__wtr_mgr() {return html_mgr.Page_wtr_mgr();}
|
||||
public Xoh_lnki_bldr Html__lnki_bldr() {return lnki_bldr;} private final Xoh_lnki_bldr lnki_bldr;
|
||||
public Xoh_href_wtr Html__href_wtr() {return href_wtr;} private final Xoh_href_wtr href_wtr = new Xoh_href_wtr();
|
||||
public Xoctg_pagebox_wtr Ctg__pagebox_wtr() {return ctg_pagebox_wtr;} private final Xoctg_pagebox_wtr ctg_pagebox_wtr = new Xoctg_pagebox_wtr();
|
||||
public Xoctg_catpage_mgr Ctg__catpage_mgr() {return ctg_catpage_mgr;} private final Xoctg_catpage_mgr ctg_catpage_mgr;
|
||||
public boolean Html__css_installing() {return html__css_installing;} public void Html__css_installing_(boolean v) {html__css_installing = v;} private boolean html__css_installing;
|
||||
public Xow_url_parser Utl__url_parser() {return url__parser;} private final Xow_url_parser url__parser;
|
||||
public Xow_mw_parser_mgr Mw_parser_mgr() {return mw_parser_mgr;} private final Xow_mw_parser_mgr mw_parser_mgr = new Xow_mw_parser_mgr();
|
||||
public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private final Xow_xwiki_mgr xwiki_mgr;
|
||||
public Xow_wiki_props Props() {return props;} private final Xow_wiki_props props = new Xow_wiki_props();
|
||||
public Xowd_site_stats_mgr Stats() {return stats;} private final Xowd_site_stats_mgr stats;
|
||||
public Xow_parser_mgr Parser_mgr() {return parser_mgr;} private final Xow_parser_mgr parser_mgr;
|
||||
public Xoax_addon_mgr Addon_mgr() {return addon_mgr;} private final Xoax_addon_mgr addon_mgr = new Xoax_addon_mgr();
|
||||
public Xog_cbk_mgr Gui__cbk_mgr() {return gui__cbk_mgr;} private final Xog_cbk_mgr gui__cbk_mgr = new Xog_cbk_mgr();
|
||||
public Xowe_page_mgr Page_mgr() {return page_mgr;} private final Xowe_page_mgr page_mgr;
|
||||
public Xop_sanitizer Sanitizer() {return sanitizer;} private final Xop_sanitizer sanitizer;
|
||||
public byte[] Wtxt__expand_tmpl(byte[] src) {return parser_mgr.Main().Expand_tmpl(src);}
|
||||
public boolean Embeddable_enabled() {return embeddable_enabled;} public void Embeddable_enabled_(boolean v) {this.embeddable_enabled = v;} private boolean embeddable_enabled;
|
||||
|
||||
|
||||
public Xow_hdump_mgr Html__hdump_mgr() {return html__hdump_mgr;} private final Xow_hdump_mgr html__hdump_mgr;
|
||||
public Xoae_app Appe() {return app;} private Xoae_app app;
|
||||
public Xow_user User() {return user;} private Xow_user user = new Xow_user();
|
||||
public Xow_page_mgr Data_mgr() {return data_mgr;} private Xow_page_mgr data_mgr;
|
||||
public Xodb_mgr Db_mgr() {return db_mgr;} private Xodb_mgr db_mgr;
|
||||
public Xodb_mgr_sql Db_mgr_as_sql() {return (Xodb_mgr_sql)db_mgr;}
|
||||
public Xow_special_mgr Special_mgr() {return special_mgr;} private Xow_special_mgr special_mgr;
|
||||
public Xow_html_mgr Html_mgr() {return html_mgr;} private Xow_html_mgr html_mgr;
|
||||
public Xow_xtn_mgr Xtn_mgr() {return xtn_mgr;} private Xow_xtn_mgr xtn_mgr;
|
||||
public Xow_cache_mgr Cache_mgr() {return cache_mgr;} private Xow_cache_mgr cache_mgr;
|
||||
|
||||
public byte[] Commons_wiki_key() {return commons_wiki_key;} private byte[] commons_wiki_key = Xow_domain_itm_.Bry__commons;
|
||||
public Xob_hive_mgr Hive_mgr() {return hive_mgr;} private Xob_hive_mgr hive_mgr;
|
||||
public Xow_msg_mgr Msg_mgr() {return msg_mgr;} private final Xow_msg_mgr msg_mgr;
|
||||
public Xow_fragment_mgr Fragment_mgr() {return fragment_mgr;} private Xow_fragment_mgr fragment_mgr;
|
||||
public Bfmtr_eval_wiki Eval_mgr() {return eval_mgr;} private Bfmtr_eval_wiki eval_mgr;
|
||||
public Bry_bfr_mkr Utl__bfr_mkr() {return utl__bry_bfr_mkr;} private final Bry_bfr_mkr utl__bry_bfr_mkr = new Bry_bfr_mkr();
|
||||
public Io_stream_zip_mgr Utl__zip_mgr() {return utl__zip_mgr;} private final Io_stream_zip_mgr utl__zip_mgr = new Io_stream_zip_mgr();
|
||||
public int Wdata_wiki_tid() {return wdata_wiki_tid;} private int wdata_wiki_tid;
|
||||
public byte[] Wdata_wiki_lang() {return wdata_wiki_lang;} private byte[] wdata_wiki_lang;
|
||||
public void Wdata_wiki_lang_(byte[] v) {this.wdata_wiki_lang = v; Wdata_wiki_abrv_();} // TEST:
|
||||
public byte[] Wdata_wiki_abrv() {return wdata_wiki_abrv;} private byte[] wdata_wiki_abrv;
|
||||
private void Wdata_wiki_abrv_() {
|
||||
Bry_bfr bfr = utl__bry_bfr_mkr.Get_b128();
|
||||
Xow_abrv_wm_.To_abrv(bfr, wdata_wiki_lang, Int_obj_ref.New(wdata_wiki_tid));
|
||||
wdata_wiki_abrv = bfr.To_bry_and_rls();
|
||||
}
|
||||
private Xow_html_util util;
|
||||
public boolean Init_needed() {return init_needed;} public Xowe_wiki Init_needed_(boolean v) {init_needed = v; return this;} private boolean init_needed = true;
|
||||
public Xop_redirect_mgr Redirect_mgr() {return redirect_mgr;} private Xop_redirect_mgr redirect_mgr;
|
||||
public List_adp Rls_list() {if (rls_list == null) rls_list = List_adp_.New(); return rls_list;} private List_adp rls_list;
|
||||
public Xow_file_mgr File_mgr() {return file_mgr;} private Xow_file_mgr file_mgr;
|
||||
public Xob_import_cfg Import_cfg() {return import_cfg;} private Xob_import_cfg import_cfg;
|
||||
public Xotdb_fsys_mgr Tdb_fsys_mgr() {return tdb_fsys_mgr;} private final Xotdb_fsys_mgr tdb_fsys_mgr;
|
||||
public Xou_history_cfg Cfg_history() {return cfg_history;} private Xou_history_cfg cfg_history = new Xou_history_cfg();
|
||||
public Xoh_file_page_wtr Cfg_file_page() {return cfg_file_page;} private Xoh_file_page_wtr cfg_file_page = new Xoh_file_page_wtr();
|
||||
public Xow_sys_cfg Sys_cfg() {return sys_cfg;} private Xow_sys_cfg sys_cfg;
|
||||
public Xowc_parser Cfg_parser() {return cfg_parser;} private Xowc_parser cfg_parser;
|
||||
public boolean Cfg_parser_lnki_xwiki_repos_enabled() {return cfg_parser_lnki_xwiki_repos_enabled;} public Xowe_wiki Cfg_parser_lnki_xwiki_repos_enabled_(boolean v) {cfg_parser_lnki_xwiki_repos_enabled = v; return this;} private boolean cfg_parser_lnki_xwiki_repos_enabled;
|
||||
public Xow_maint_mgr Maint_mgr() {return maint_mgr;} private Xow_maint_mgr maint_mgr;
|
||||
public void Clear_for_tests() { // NOTE: these are structures that cache items for PERF; need to be cleared out for multiple test runs
|
||||
file_mgr.Dbmeta_mgr().Clear();
|
||||
db_mgr.Load_mgr().Clear();
|
||||
}
|
||||
public Xodb_mgr_sql Db_mgr_create_as_sql() {Xodb_mgr_sql rv = new Xodb_mgr_sql(this); db_mgr = rv; return rv;}
|
||||
public void Init_by_wiki__force() {init_needed = true; Init_by_wiki();}
|
||||
public void Init_by_wiki__force_and_mark_inited() {
|
||||
init_needed = true;
|
||||
Init_by_wiki();
|
||||
init_needed = false;
|
||||
}
|
||||
public void Init_by_wiki() {Init_assert();}
|
||||
public Xowe_wiki Init_assert() {if (init_needed) Init_wiki(app.Usere()); return this;}
|
||||
public void Init_db_mgr() {
|
||||
Io_url core_db_url = gplx.xowa.wikis.data.Xow_db_file__core_.Find_core_fil_or_null(this);
|
||||
if (core_db_url == null) {
|
||||
tdb_fsys_mgr.Scan_dirs();
|
||||
}
|
||||
else {
|
||||
Xodb_mgr_sql db_mgr_sql = this.Db_mgr_create_as_sql();
|
||||
Xow_db_mgr.Init_by_load(this, core_db_url);
|
||||
file_mgr.Init_file_mgr_by_load(this);
|
||||
db_mgr_sql.Core_data_mgr().Tbl__page().Flds__assert(); // NOTE: must go above html_mgr.Init_by_wiki b/c Page_load will be done via messages
|
||||
|
||||
// FOLDER.RENAME: handle renamed folders; EX:"/wiki/en.wikipedia.org-2016-12" DATE:2017-02-01
|
||||
try {
|
||||
byte[] cfg_domain_bry = db_mgr_sql.Core_data_mgr().Db__core().Tbl__cfg().Select_bry_or("xowa.bldr.session", "wiki_domain", domain_bry); // NOTE: or is "wiki.domain" for user_wikis
|
||||
if (!Bry_.Eq(cfg_domain_bry, domain_bry)) {
|
||||
// set wikidata vars
|
||||
Xow_domain_itm cfg_domain_itm = Xow_domain_itm_.parse(cfg_domain_bry);
|
||||
this.wdata_wiki_tid = cfg_domain_itm.Domain_type_id();
|
||||
this.wdata_wiki_lang = cfg_domain_itm.Lang_orig_key();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Xow_abrv_wm_.To_abrv(bfr, wdata_wiki_lang, Int_obj_ref.New(wdata_wiki_tid));
|
||||
this.wdata_wiki_abrv = bfr.To_bry_and_clear();
|
||||
|
||||
// set lang; handles "German Wikipedia" for "de.wikipedia.org"
|
||||
this.lang = app.Lang_mgr().Get_by_or_load(cfg_domain_itm.Lang_actl_key());
|
||||
this.msg_mgr.Lang_(lang);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "db.init: failed to get domain from config; err=~{0}", Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Init_wiki(Xoue_user user) { // NOTE: (a) one-time initialization for all wikis; (b) not called by tests
|
||||
if (init_in_process) {
|
||||
app.Usr_dlg().Log_many("", "", "wiki.init: circular call canceled: ~{0}", domain_str);
|
||||
return; // NOTE: may be called multiple times due to "if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false;"; TODO_OLD: call this only once; DATE:2014-06-07
|
||||
}
|
||||
init_in_process = true;
|
||||
if (app.Stage() == Xoa_stage_.Tid_launch) init_needed = false; // NOTE: only mark inited if app fully launched; otherwise statements in xowa.gfs can fire and prematurely set home to inited; DATE:2013-03-24
|
||||
Gfo_log_bfr log_bfr = app.Log_bfr(); log_bfr.Add("wiki.init.bgn: " + domain_str);
|
||||
|
||||
app.Gfs_mgr().Run_url_for(this, tdb_fsys_mgr.Cfg_wiki_stats_fil());
|
||||
Init_db_mgr();
|
||||
if (!app.Bldr().Import_marker().Chk(this)) {app.Wiki_mgr().Del(domain_bry); init_needed = false; return;} // NOTE: must call after Db_mgr_create_as_sql(); also, must delete wiki from mgr; DATE:2014-08-24
|
||||
db_mgr.Load_mgr().Load_init(this);
|
||||
app.Gfs_mgr().Run_url_for(this, tdb_fsys_mgr.Cfg_wiki_core_fil());
|
||||
parser_mgr.Init_by_wiki();
|
||||
|
||||
// init ns_mgr
|
||||
if (lang.Init_by_load()) {
|
||||
if (domain_tid == Xow_domain_tid_.Tid__wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
|
||||
ns_mgr.Aliases_add(Xow_ns_.Tid__project, Xow_ns_.Alias__wikipedia);
|
||||
special_mgr.Evt_lang_changed(lang);
|
||||
}
|
||||
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // NOTE: must be run after lang.Init_by_load b/c lang will reload ns_mgr; DATE:2015-04-17run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
|
||||
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file
|
||||
Xow_ns_mgr_.rebuild_(lang, ns_mgr); // always rebuild; may be changed by user_wiki.gfs; different lang will change namespaces; EX: de.wikisource.org will have Seite for File and none of {{#lst}} will work
|
||||
|
||||
// push lang changes
|
||||
fragment_mgr.Evt_lang_changed(lang);
|
||||
parser_mgr.Main().Init_by_lang(lang);
|
||||
html_mgr.Init_by_lang(lang);
|
||||
|
||||
// other init
|
||||
Bry_fmtr.Null.Eval_mgr().Enabled_(false); app.Wiki_mgr().Scripts().Exec(this); Bry_fmtr.Null.Eval_mgr().Enabled_(true);
|
||||
app.Html__css_installer().Install(this, Xowd_css_core_mgr.Key_default);
|
||||
html_mgr.Init_by_wiki(this);
|
||||
html__hdump_mgr.Init_by_db(this);
|
||||
Xow_repo_mgr_.Assert_repos(app, this);
|
||||
xtn_mgr.Init_by_wiki(this);
|
||||
log_bfr.Add("wiki.init.end");
|
||||
app.Log_wtr().Log_to_session_direct(log_bfr.Xto_str());
|
||||
init_in_process = false;
|
||||
// app.Api_root().Wikis().Get(domain_bry).Subscribe(this);
|
||||
app.Site_cfg_mgr().Load(this);
|
||||
app.Addon_mgr().Load_by_wiki(this);
|
||||
ctg_pagebox_wtr.Init_by_wiki(this);
|
||||
ctg_catpage_mgr.Init_by_wiki(this);
|
||||
|
||||
file_mgr.Init_by_wiki(this);
|
||||
page_mgr.Init_by_wiki(this);
|
||||
|
||||
app.Cfg().Bind_many_wiki(this, this, Cfg__variant__current);
|
||||
}
|
||||
public void Rls() {
|
||||
if (rls_list != null) {
|
||||
int len = rls_list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Rls_able rls = (Rls_able)rls_list.Get_at(i);
|
||||
rls.Rls();
|
||||
}
|
||||
}
|
||||
Xow_db_mgr core_db_mgr = this.Data__core_mgr();
|
||||
if (core_db_mgr != null) core_db_mgr.Rls();
|
||||
file_mgr.Rls();
|
||||
}
|
||||
public void Init_needed_y_() {this.init_needed = true;}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_files)) return file_mgr;
|
||||
else if (ctx.Match(k, Invk_stats)) return stats;
|
||||
else if (ctx.Match(k, Invk_props)) return props;
|
||||
else if (ctx.Match(k, Invk_commons_wiki_)) commons_wiki_key = m.ReadBry("v");
|
||||
else if (ctx.Match(k, Invk_lang)) return lang;
|
||||
else if (ctx.Match(k, Invk_lang_)) throw Err_.new_deprecated("wiki.lang_");
|
||||
else if (ctx.Match(k, Invk_html)) return html_mgr;
|
||||
else if (ctx.Match(k, Invk_cfg_history)) return cfg_history;
|
||||
else if (ctx.Match(k, Invk_user)) return user;
|
||||
else if (ctx.Match(k, Invk_data_mgr)) return data_mgr;
|
||||
else if (ctx.Match(k, Invk_ns_mgr)) return ns_mgr;
|
||||
else if (ctx.Match(k, Invk_sys_cfg)) return sys_cfg;
|
||||
else if (ctx.Match(k, Invk_special)) return special_mgr;
|
||||
else if (ctx.Match(k, Invk_parser)) return cfg_parser;
|
||||
else if (ctx.Match(k, Invk_msgs)) return msg_mgr;
|
||||
else if (ctx.Match(k, Invk_util)) return util;
|
||||
else if (ctx.Match(k, Invk_app)) return app;
|
||||
else if (ctx.Match(k, Invk_db_mgr)) return db_mgr;
|
||||
else if (ctx.Match(k, Invk_db_mgr_to_sql_)) this.Db_mgr_create_as_sql();
|
||||
else if (ctx.Match(k, Invk_maint)) return maint_mgr;
|
||||
else if (ctx.Match(k, Invk_domain)) return domain_str;
|
||||
else if (ctx.Match(k, Invk_xtns)) return xtn_mgr;
|
||||
else if (ctx.Match(k, Invk_catpage_mgr)) return ctg_catpage_mgr;
|
||||
else if (ctx.Match(k, Invk_hdump_enabled_)) this.html_mgr__hdump_enabled = m.ReadYn("v");
|
||||
|
||||
else if (ctx.Match(k, Cfg__variant__current)) lang.Vnt_mgr().Cur_itm_(m.ReadBry("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_files = "files", Invk_commons_wiki_ = "commons_wiki_", Invk_stats = "stats"
|
||||
, Invk_lang = "lang", Invk_html = "html", Invk_gui = "gui", Invk_cfg_history = "cfg_history", Invk_user = "user", Invk_data_mgr = "data_mgr", Invk_sys_cfg = "sys_cfg", Invk_ns_mgr = "ns_mgr"
|
||||
, Invk_special = "special"
|
||||
, Invk_props = "props", Invk_parser = "parser"
|
||||
, Invk_msgs = "msgs", Invk_app = "app", Invk_util = "util"
|
||||
, Invk_xtns = "xtns"
|
||||
, Invk_db_mgr_to_sql_ = "db_mgr_to_sql_"
|
||||
, Invk_domain = "domain", Invk_maint = "maint", Invk_hdump_enabled_ = "hdump_enabled_"
|
||||
, Invk_catpage_mgr = "catpage_mgr"
|
||||
;
|
||||
public static final String Cfg__variant__current = "xowa.wiki.lang.variant.current";
|
||||
public static final String Invk_db_mgr = "db_mgr"; // SERIALIZED:000.sqlite3|xowa_cfg
|
||||
public static final String Invk_lang_ = "lang_";
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import gplx.xowa.apps.apis.xowa.bldrs.imports.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xowe_wiki_ {
|
||||
public static void Create(Xowe_wiki wiki, long src_fil_len, String src_fil_name) {
|
||||
wiki.Db_mgr_create_as_sql(); // create db_mgr as sql
|
||||
Xoapi_import import_api = wiki.Appe().Api_root().Bldr().Wiki().Import();
|
||||
Xowd_core_db_props db_mgr_props = gplx.xowa.bldrs.Xobldr_cfg.New_props(wiki.App(), wiki.Domain_str(), src_fil_len);
|
||||
Xob_info_session info_session = Xob_info_session.new_(import_api.User_name(), wiki.Domain_str(), src_fil_name);
|
||||
wiki.Data__core_mgr().Init_by_make(db_mgr_props, info_session); // make core_db
|
||||
}
|
||||
public static void Rls_mem_if_needed(Xowe_wiki wiki) {
|
||||
Xoae_app app = wiki.Appe();
|
||||
if (gplx.core.envs.Runtime_.Memory_free() < app.Sys_cfg().Free_mem_when()) // check if low in memory
|
||||
Xowe_wiki_.Rls_mem(wiki, false); // clear caches (which will clear bry_bfr_mkr)
|
||||
else // not low in memory
|
||||
wiki.Utl__bfr_mkr().Clear(); // clear bry_bfr_mkr only; NOTE: call before page parse, not when page is first added, else threading errors; DATE:2014-05-30
|
||||
}
|
||||
public static void Rls_mem(Xowe_wiki wiki, boolean clear_ctx) {
|
||||
wiki.Appe().Free_mem(clear_ctx);
|
||||
wiki.Cache_mgr().Free_mem__all();
|
||||
wiki.Parser_mgr().Scrib().Core_term();
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoax_addon_itm {
|
||||
String Addon__key();
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.bldrs.wkrs.*;
|
||||
public interface Xoax_addon_itm__bldr {
|
||||
Xob_cmd[] Bldr_cmds();
|
||||
}
|
||||
|
||||
@@ -13,9 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.bldrs.wkrs.*;
|
||||
public interface Xoax_addon_itm__init {
|
||||
void Init_addon_by_app(Xoa_app app);
|
||||
void Init_addon_by_wiki(Xow_wiki wiki);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoax_addon_itm__json {
|
||||
gplx.xowa.htmls.bridges.Bridge_cmd_itm[] Json_cmds();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoax_addon_itm__special {
|
||||
gplx.xowa.specials.Xow_special_page[] Special_pages();
|
||||
}
|
||||
|
||||
@@ -13,121 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.addons.wikis.searchs.gui.urlbars.*; import gplx.xowa.addons.wikis.searchs.gui.htmlbars.*; import gplx.xowa.addons.wikis.searchs.specials.*;
|
||||
public class Xoax_addon_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New(); // LOCK: must synchronized else two search tabs will fail on startup
|
||||
public Xoax_addon_itm Itms__get_or_null(String key) {synchronized (hash) {return (Xoax_addon_itm)hash.Get_by(key);}}
|
||||
public void Itms__add_many(Xoax_addon_itm... ary) {
|
||||
for (Xoax_addon_itm itm : ary)
|
||||
Itms__add(itm);
|
||||
}
|
||||
public void Itms__add(Xoax_addon_itm itm) {
|
||||
synchronized (hash) {
|
||||
String addon_key = itm.Addon__key();
|
||||
hash.Add(addon_key, itm);
|
||||
// Xoa_app_.Usr_dlg().Log_many("", "", "addons.init: ~{0}", addon_key);
|
||||
}
|
||||
}
|
||||
// HACK: should make separate generic app-level container
|
||||
public Srch_urlbar_mgr Itms__search__urlbar() {return itms__search__urlbar;} private final Srch_urlbar_mgr itms__search__urlbar = new Srch_urlbar_mgr();
|
||||
public Srch_htmlbar_mgr Itms__search__htmlbar() {return itms__search__htmlbar;} private final Srch_htmlbar_mgr itms__search__htmlbar = new Srch_htmlbar_mgr();
|
||||
public Srch_special_cfg Itms__search__special() {return itms__search__special;} private final Srch_special_cfg itms__search__special = new Srch_special_cfg();
|
||||
public void Init_by_kit(Xoae_app app, gplx.gfui.kits.core.Gfui_kit kit) {
|
||||
itms__search__urlbar.Init_by_kit(app, kit);
|
||||
itms__search__htmlbar.Init_by_kit(app, kit);
|
||||
itms__search__special.Init_by_kit(app, kit);
|
||||
}
|
||||
public Xoax_addon_mgr Add_dflts_by_app(Xoa_app app) {
|
||||
app.Bldr().Cmd_regy().Add_many
|
||||
( gplx.xowa.bldrs.cmds.utils.Xob_alert_cmd.Prototype
|
||||
);
|
||||
app.Addon_mgr().Itms__add_many
|
||||
// bldrs
|
||||
( new gplx.xowa.addons.bldrs.files .Xoax_builds_files_addon()
|
||||
, new gplx.xowa.addons.bldrs.wmdumps.pagelinks .Xoax_builds_pagelinks_addon()
|
||||
, new gplx.xowa.addons.bldrs.wmdumps.imglinks .Imglnk_addon()
|
||||
, new gplx.xowa.addons.bldrs.utils_rankings .Xoax_builds_utils_rankings_addon()
|
||||
, new gplx.xowa.addons.wikis.searchs .Xoax_builds_search_addon()
|
||||
, new gplx.xowa.addons.bldrs.updates.files .Xodel_addon()
|
||||
, new gplx.xowa.addons.bldrs.htmls .Html__dump_to_fsys__addon()
|
||||
, new gplx.xowa.addons.bldrs.exports .Export_addon()
|
||||
, new gplx.xowa.addons.wikis.pages.randoms .Rndm_addon()
|
||||
, new gplx.xowa.addons.bldrs.hdumps.diffs .Dumpdiff_addon()
|
||||
, new gplx.xowa.addons.wikis.ctgs.bldrs .Xoax_ctg_bldr_addon()
|
||||
, new gplx.xowa.xtns.wbases.imports .Xowb_bldr_addon()
|
||||
|
||||
// xtns
|
||||
, new gplx.xowa.xtns.math .Xomath_addon()
|
||||
|
||||
// specials
|
||||
, new gplx.xowa.addons.wikis.registrys .Wiki_registry_addon()
|
||||
, new gplx.xowa.addons.wikis.imports .Xow_import_addon()
|
||||
, new gplx.xowa.addons.bldrs.xodirs .Xobc_xodir_addon()
|
||||
, new gplx.xowa.addons.bldrs.centrals .Xobc_task_addon()
|
||||
, new gplx.xowa.addons.apps.helps.logs .Xolog_addon()
|
||||
, new gplx.xowa.addons.wikis.pages.syncs .Xosync_addon()
|
||||
, new gplx.xowa.addons.wikis.directorys .Xowdir_addon()
|
||||
, new gplx.xowa.addons.apps.cfgs .Xoa_cfg_addon()
|
||||
, new gplx.xowa.addons.apps.updates .Xoa_update_addon()
|
||||
, new gplx.xowa.addons.apps.maints.sql_execs .Xosql_exec_addon()
|
||||
, new gplx.xowa.addons.wikis.fulltexts .Xosearch_fulltext_addon()
|
||||
|
||||
// jsons
|
||||
);
|
||||
if (app.Mode().Tid_is_http()) {
|
||||
app.Addon_mgr().Itms__add_many(new gplx.xowa.addons.servers.https.Xoax_long_poll_addon());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
public void Run_by_app(Xoa_app app) {
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoax_addon_itm addon = (Xoax_addon_itm)hash.Get_at(i);
|
||||
|
||||
// init
|
||||
if (Type_.Is_assignable_from_by_obj(addon, Xoax_addon_itm__init.class)) {
|
||||
Xoax_addon_itm__init addon_init = (Xoax_addon_itm__init)addon;
|
||||
addon_init.Init_addon_by_app(app);
|
||||
init_list.Add(addon_init);
|
||||
}
|
||||
|
||||
// add bldr cmds
|
||||
if (Type_.Is_assignable_from_by_obj(addon, Xoax_addon_itm__bldr.class)) {
|
||||
Xoax_addon_itm__bldr addon_bldr = (Xoax_addon_itm__bldr)addon;
|
||||
app.Bldr().Cmd_regy().Add_many(addon_bldr.Bldr_cmds());
|
||||
}
|
||||
|
||||
// add special pages
|
||||
if (Type_.Is_assignable_from_by_obj(addon, Xoax_addon_itm__special.class)) {
|
||||
Xoax_addon_itm__special addon_sp = (Xoax_addon_itm__special)addon;
|
||||
app.Special_regy().Add_many(addon_sp.Special_pages());
|
||||
}
|
||||
|
||||
// add json mgrs
|
||||
if (Type_.Is_assignable_from_by_obj(addon, Xoax_addon_itm__json.class)) {
|
||||
Xoax_addon_itm__json addon_json = (Xoax_addon_itm__json)addon;
|
||||
gplx.xowa.htmls.bridges.Bridge_cmd_itm[] json_cmds = addon_json.Json_cmds();
|
||||
for (gplx.xowa.htmls.bridges.Bridge_cmd_itm json_cmd : json_cmds) {
|
||||
json_cmd.Init_by_app(app);
|
||||
app.Html__bridge_mgr().Cmd_mgr().Add(json_cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private boolean init_cfg = true; // WORKAROUND:move cfg to separate proc instead of lazy-loading on 1st wiki
|
||||
public void Load_by_wiki(Xow_wiki wiki) {
|
||||
if (init_cfg) {
|
||||
init_cfg = false;
|
||||
gplx.xowa.bldrs.filters.dansguardians.Dg_match_mgr.Cfg__reg(wiki.App());
|
||||
}
|
||||
|
||||
int len = init_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoax_addon_itm__init itm = (Xoax_addon_itm__init)init_list.Get_at(i);
|
||||
itm.Init_addon_by_wiki(wiki);
|
||||
}
|
||||
}
|
||||
private final List_adp init_list = List_adp_.New();
|
||||
}
|
||||
|
||||
@@ -13,23 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.edits.pages.*; import gplx.xowa.addons.apps.cfgs.specials.edits.services.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.maints.pages.*; import gplx.xowa.addons.apps.cfgs.specials.maints.services.*;
|
||||
public class Xoa_cfg_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xocfg_maint_special.Prototype
|
||||
, Xocfg_edit_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ Xocfg_maint_bridge.Prototype
|
||||
, Xocfg_edit_bridge.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return ADDON__KEY;} private static final String ADDON__KEY = "xowa.app.cfg";
|
||||
}
|
||||
|
||||
@@ -13,137 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.apps.cfgs.mgrs.caches.*; import gplx.xowa.addons.apps.cfgs.mgrs.dflts.*; import gplx.xowa.addons.apps.cfgs.mgrs.types.*; import gplx.xowa.addons.apps.cfgs.mgrs.execs.*;
|
||||
public class Xocfg_mgr implements Gfo_invk {
|
||||
public Xocfg_mgr() {
|
||||
this.dflt_mgr = new Xocfg_dflt_mgr(cache_mgr);
|
||||
}
|
||||
public Xocfg_cache_mgr Cache_mgr() {return cache_mgr;} private final Xocfg_cache_mgr cache_mgr = new Xocfg_cache_mgr();
|
||||
public Xocfg_type_mgr Type_mgr() {return type_mgr;} private final Xocfg_type_mgr type_mgr = new Xocfg_type_mgr();
|
||||
public Xocfg_dflt_mgr Dflt_mgr() {return dflt_mgr;} private final Xocfg_dflt_mgr dflt_mgr;
|
||||
public Xocfg_exec_mgr Exec_mgr() {return exec_mgr;} private final Xocfg_exec_mgr exec_mgr = new Xocfg_exec_mgr();
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
cache_mgr.Init_by_app
|
||||
( gplx.xowa.addons.apps.cfgs.dbs.Xocfg_db_app.New_conn(app)
|
||||
, app.User().User_db_mgr().Conn());
|
||||
}
|
||||
public void Sub_many_app (Gfo_invk sub, String... keys) {Bind_many(Bool_.N, sub, Xocfg_mgr.Ctx__app, keys);}
|
||||
public void Bind_many_app (Gfo_invk sub, String... keys) {Bind_many(Bool_.Y, sub, Xocfg_mgr.Ctx__app, keys);}
|
||||
public void Bind_many_wiki (Gfo_invk sub, Xow_wiki wiki, String... keys) {Bind_many(Bool_.Y, sub, wiki.Domain_itm().Abrv_xo_str(), keys);}
|
||||
private void Bind_many(boolean pub, Gfo_invk sub, String ctx, String... keys) {
|
||||
for (String key : keys) {
|
||||
try {
|
||||
cache_mgr.Sub(sub, ctx, key, key);
|
||||
if (pub) {
|
||||
String val = cache_mgr.Get(ctx, key);
|
||||
cache_mgr.Pub(ctx, key, val);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "bind failed: ctx=~{0} key=~{1} err=~{2}", ctx, key, Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean Get_bool_app_or(String key, boolean or) {
|
||||
String rv = Get_str(Ctx__app, key);
|
||||
return rv == null ? or : Yn.parse_or(rv, or);
|
||||
}
|
||||
public boolean Get_bool_wiki_or(Xow_wiki wiki, String key, boolean or) {
|
||||
String rv = Get_str(wiki.Domain_itm().Abrv_xo_str(), key);
|
||||
return rv == null ? or : Yn.parse_or(rv, or);
|
||||
}
|
||||
public int Get_int_app_or(String key, int or) {
|
||||
String rv = cache_mgr.Get_or(Ctx__app, key, null);
|
||||
return rv == null ? or : Int_.Parse_or(rv, or);
|
||||
}
|
||||
public long Get_long_app_or(String key, long or) {
|
||||
String rv = cache_mgr.Get_or(Ctx__app, key, null);
|
||||
return rv == null ? or : Long_.parse_or(rv, or);
|
||||
}
|
||||
public DateAdp Get_date_app_or(String key, DateAdp or) {
|
||||
String rv = cache_mgr.Get_or(Ctx__app, key, null);
|
||||
return rv == null ? or : DateAdp_.parse_fmt_or(rv, Fmt__time, or);
|
||||
}
|
||||
public String[] Get_strary_app_or(String key, String dlm, String... or) {
|
||||
String rv = cache_mgr.Get_or(Ctx__app, key, null);
|
||||
return rv == null ? or : String_.Ary_parse(String_.Trim(rv), dlm);
|
||||
}
|
||||
public String Get_str_wiki_or(Xow_wiki wiki, String key, String or) {return cache_mgr.Get_or(wiki.Domain_itm().Abrv_xo_str(), key, or);}
|
||||
public String Get_str_app_or(String key, String or) {return cache_mgr.Get_or(Ctx__app, key, or);}
|
||||
public String Get_str_app(String key) {return Get_str(Xocfg_mgr.Ctx__app, key);}
|
||||
public boolean Get_bool_or(String ctx, String key, boolean or) {
|
||||
String rv = cache_mgr.Get(ctx, key);
|
||||
try {return Yn.parse(rv);}
|
||||
catch (Exception exc) {
|
||||
Err_.Noop(exc);
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:failed to parse boolean; key=~{0} val=~{1}", key, rv);
|
||||
return or;
|
||||
}
|
||||
}
|
||||
public int Get_int_wiki_or(Xow_wiki wiki, String key, int or) {
|
||||
String rv = Get_str(wiki.Domain_itm().Abrv_xo_str(), key);
|
||||
try {return Int_.Parse(rv);}
|
||||
catch (Exception exc) {
|
||||
Err_.Noop(exc);
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:failed to parse int; key=~{0} val=~{1}", key, rv);
|
||||
return or;
|
||||
}
|
||||
}
|
||||
public int Get_int_or(String ctx, String key, int or) {
|
||||
String rv = cache_mgr.Get(ctx, key);
|
||||
try {return Int_.Parse(rv);}
|
||||
catch (Exception exc) {
|
||||
Err_.Noop(exc);
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:failed to parse int; key=~{0} val=~{1}", key, rv);
|
||||
return or;
|
||||
}
|
||||
}
|
||||
public Io_url Get_url_or(String ctx, String key, Io_url or) {
|
||||
String rv = cache_mgr.Get(ctx, key);
|
||||
try {return Io_url_.new_any_(rv);}
|
||||
catch (Exception exc) {
|
||||
Err_.Noop(exc);
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:failed to parse int; key=~{0} val=~{1}", key, rv);
|
||||
return or;
|
||||
}
|
||||
}
|
||||
public String To_ctx(Xow_wiki wiki) {return wiki.Domain_itm().Abrv_xo_str();}
|
||||
public String Get_str(String ctx, String key) {return cache_mgr.Get(ctx, key);}
|
||||
public void Set_bool_app(String key, boolean val) {Set_str(Xocfg_mgr.Ctx__app, key, Yn.To_str(val));}
|
||||
public void Set_float_app(String key, float val) {Set_str(Xocfg_mgr.Ctx__app, key, Float_.To_str(val));}
|
||||
public void Set_str_app(String key, String val) {Set_str(Xocfg_mgr.Ctx__app, key, val);}
|
||||
public void Set_bry_app(String key, byte[] val) {Set_str(Xocfg_mgr.Ctx__app, key, String_.new_u8(val));}
|
||||
public void Set_date_app(String key, DateAdp val) {Set_str(Xocfg_mgr.Ctx__app, key, val.XtoUtc().XtoStr_fmt(Fmt__time));}
|
||||
public void Set_int_app(String key, int val) {Set_str(Xocfg_mgr.Ctx__app, key, Int_.To_str(val));}
|
||||
public void Set_bry_wiki(Xowe_wiki wiki, String key, byte[] val) {Set_str(wiki.Domain_itm().Abrv_xo_str(), key, String_.new_u8(val));}
|
||||
|
||||
public void Set_str(String ctx, String key, String val) {
|
||||
cache_mgr.Set(ctx, key, val);
|
||||
}
|
||||
public void Del(String ctx, String key) {
|
||||
cache_mgr.Del(ctx, key);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, "set")) cache_mgr.Set ((String)m.ReadValAt(0), (String)m.ReadValAt(1), (String)m.ReadValAt(2));
|
||||
else if (ctx.Match(k, "set_temp")) cache_mgr.Set_wo_save ((String)m.ReadValAt(0), (String)m.ReadValAt(1), (String)m.ReadValAt(2));
|
||||
else if (ctx.Match(k, "set_dflt")) dflt_mgr.Add ((String)m.ReadValAt(0), (String)m.ReadValAt(1));
|
||||
else if (ctx.Match(k, "run")) cache_mgr.Pub ((String)m.ReadValAt(0), (String)m.ReadValAt(1), (String)m.ReadValAt(2));
|
||||
else if (ctx.Match(k, "get")) return cache_mgr.Get ((String)m.ReadValAt(0), (String)m.ReadValAt(1));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static String Ctx__app = "app";
|
||||
public static String[] Parse_io_cmd(String raw) {
|
||||
String[] rv = new String[2];
|
||||
rv[0] = "";
|
||||
rv[1] = "";
|
||||
int pos = String_.FindFwd(raw, "|");
|
||||
if (pos != Bry_find_.Not_found) {
|
||||
rv[0] = String_.Mid(raw, 0, pos);
|
||||
rv[1] = String_.Mid(raw, pos + 1);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final String Fmt__time = "yyyy-MM-dd HH:mm:ss";
|
||||
}
|
||||
|
||||
@@ -13,28 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.apps.cfgs.dbs.tbls.*;
|
||||
public class Xocfg_db_app {
|
||||
public Xocfg_db_app(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl__grp = new Xocfg_grp_tbl(conn);
|
||||
this.tbl__map = new Xocfg_map_tbl(conn);
|
||||
this.tbl__itm = new Xocfg_itm_tbl(conn);
|
||||
this.tbl__txt = new Xocfg_txt_tbl(conn);
|
||||
conn.Meta_tbl_assert(tbl__grp, tbl__map, tbl__itm, tbl__txt);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Xocfg_grp_tbl Tbl__grp() {return tbl__grp;} private final Xocfg_grp_tbl tbl__grp;
|
||||
public Xocfg_map_tbl Tbl__map() {return tbl__map;} private final Xocfg_map_tbl tbl__map;
|
||||
public Xocfg_itm_tbl Tbl__itm() {return tbl__itm;} private final Xocfg_itm_tbl tbl__itm;
|
||||
public Xocfg_txt_tbl Tbl__txt() {return tbl__txt;} private final Xocfg_txt_tbl tbl__txt;
|
||||
|
||||
public static Db_conn New_conn(Xoa_app app) {
|
||||
Io_url url = app.Fsys_mgr().Bin_addon_dir().GenSubFil_nest("app", "cfg", "xo.cfg.sqlite3");
|
||||
return Db_conn_bldr.Instance.Get_or_autocreate(true, url);
|
||||
}
|
||||
public static Xocfg_db_app New(Xoa_app app) {
|
||||
return new Xocfg_db_app(New_conn(app));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,29 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.tbls.*;
|
||||
public class Xocfg_db_usr {
|
||||
private final Xocfg_itm_tbl tbl__itm;
|
||||
public Xocfg_db_usr(Xocfg_db_app db_app, Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl__val = new Xocfg_val_tbl(conn);
|
||||
conn.Meta_tbl_assert(tbl__val);
|
||||
this.tbl__itm = db_app.Tbl__itm();
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Xocfg_val_tbl Tbl__val() {return tbl__val;} private final Xocfg_val_tbl tbl__val;
|
||||
public String Get_str(String ctx, String key) {
|
||||
Xocfg_itm_row itm_row = tbl__itm.Select_by_key_or_null(key);
|
||||
if (itm_row == null) throw Err_.new_wo_type("cfg not defined", "ctx", ctx, "key", key);
|
||||
Xocfg_val_row val_row = tbl__val.Select_one_or_null(ctx, key);
|
||||
return val_row == null ? itm_row.Dflt() : val_row.Val();
|
||||
}
|
||||
public void Set_str(String ctx, String key, String val) {
|
||||
tbl__val.Upsert(ctx, key, val, Datetime_now.Get().XtoUtc().XtoStr_fmt_iso_8561());
|
||||
}
|
||||
public void Del(String ctx, String key) {
|
||||
tbl__val.Delete(ctx, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
public class Xocfg_grp_row {
|
||||
public Xocfg_grp_row(int id, String key) {
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
|
||||
public static final int Id__root = -1;
|
||||
}
|
||||
|
||||
@@ -13,43 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xocfg_grp_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__grp_id, fld__grp_key;
|
||||
private final Db_conn conn;
|
||||
public Xocfg_grp_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.fld__grp_id = flds.Add_int_pkey("grp_id");
|
||||
this.fld__grp_key = flds.Add_str("grp_key", 255);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
|
||||
, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, fld__grp_key, fld__grp_key)
|
||||
));
|
||||
}
|
||||
public void Upsert(int grp_id, String grp_key) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__grp_id), grp_id, grp_key);
|
||||
}
|
||||
public int Select_id_by_key_or_fail(String key) {
|
||||
Xocfg_grp_row itm = this.Select_by_key_or_null(key);
|
||||
if (itm == null) throw Err_.new_wo_type("cfg.grp:invalid key", "key", key);
|
||||
return itm.Id();
|
||||
}
|
||||
public Xocfg_grp_row Select_by_key_or_null(String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__grp_key).Crt_str(fld__grp_key, key).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Load(rdr): null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xocfg_grp_row Load(Db_rdr rdr) {
|
||||
return new Xocfg_grp_row
|
||||
( rdr.Read_int(fld__grp_id)
|
||||
, rdr.Read_str(fld__grp_key)
|
||||
);
|
||||
}
|
||||
public void Rls() {}
|
||||
public static final String TBL_NAME = "cfg_grp";
|
||||
}
|
||||
|
||||
@@ -13,22 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
public class Xocfg_itm_row {
|
||||
public Xocfg_itm_row(int id, String key, int scope, String type, String dflt, String html_atrs, String html_cls) {
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.scope = scope;
|
||||
this.type = type;
|
||||
this.dflt = dflt;
|
||||
this.html_atrs = html_atrs;
|
||||
this.html_cls = html_cls;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
public int Scope() {return scope;} private final int scope;
|
||||
public String Type() {return type;} private final String type;
|
||||
public String Dflt() {return dflt;} private final String dflt;
|
||||
public String Html_atrs() {return html_atrs;} private final String html_atrs;
|
||||
public String Html_cls() {return html_cls;} private final String html_cls;
|
||||
}
|
||||
|
||||
@@ -13,52 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xocfg_itm_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__itm_id, fld__itm_key, fld__itm_scope, fld__itm_type, fld__itm_dflt, fld__itm_html_atrs, fld__itm_html_cls;
|
||||
private final Db_conn conn;
|
||||
public Xocfg_itm_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cfg_itm";
|
||||
this.fld__itm_id = flds.Add_int_pkey("itm_id"); // EX: '1'
|
||||
this.fld__itm_key = flds.Add_str("itm_key", 255); // EX: 'cfg_1'
|
||||
this.fld__itm_scope = flds.Add_int("itm_scope"); // EX: '1'; ENUM: Xoitm_scope_enum
|
||||
this.fld__itm_type = flds.Add_str("itm_type", 255); // EX: '1'; ENUM: Xoitm_type_enum
|
||||
this.fld__itm_dflt = flds.Add_str("itm_dflt", 4096); // EX: 'abc'
|
||||
this.fld__itm_html_atrs = flds.Add_str("itm_html_atrs", 255); // EX: 'size="5"'
|
||||
this.fld__itm_html_cls = flds.Add_str("itm_html_cls", 255); // EX: 'xocfg__bool__readonly'
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
|
||||
, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, fld__itm_key, fld__itm_key)));
|
||||
}
|
||||
public void Upsert(int id, String key, int scope, String type, String dflt, String html_atrs, String html_cls) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__itm_id), id, key, scope, type, dflt, html_atrs, html_cls);
|
||||
}
|
||||
public int Select_id_or(String key, int or) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_key).Crt_str(fld__itm_key, key).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? rdr.Read_int(fld__itm_id) : or;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xocfg_itm_row Select_by_key_or_null(String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_key).Crt_str(fld__itm_key, key).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Load(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xocfg_itm_row Load(Db_rdr rdr) {
|
||||
return new Xocfg_itm_row
|
||||
( rdr.Read_int(fld__itm_id)
|
||||
, rdr.Read_str(fld__itm_key)
|
||||
, rdr.Read_int(fld__itm_scope)
|
||||
, rdr.Read_str(fld__itm_type)
|
||||
, rdr.Read_str(fld__itm_dflt)
|
||||
, rdr.Read_str(fld__itm_html_atrs)
|
||||
, rdr.Read_str(fld__itm_html_cls)
|
||||
);
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,50 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xocfg_map_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__map_src, fld__map_trg, fld__map_sort;
|
||||
private final Db_conn conn;
|
||||
public Xocfg_map_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cfg_map";
|
||||
this.fld__map_src = flds.Add_int("map_src");
|
||||
this.fld__map_trg = flds.Add_int("map_trg");
|
||||
this.fld__map_sort = flds.Add_int("map_sort");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
|
||||
, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "core", fld__map_src, fld__map_trg)
|
||||
));
|
||||
}
|
||||
public void Upsert(int map_src, int map_trg, int map_sort) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__map_src, fld__map_trg), map_src, map_trg, map_sort);
|
||||
}
|
||||
public int Select_sort_or_next(int src_id, int trg_id) {
|
||||
// select map_sort by map_src,map_trg
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__map_src, fld__map_trg).Crt_int(fld__map_src, src_id).Crt_int(fld__map_trg, trg_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
return rdr.Read_int(fld__map_sort);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
|
||||
// pairing doesn't exist; select max
|
||||
rdr = conn.Stmt_select_max(tbl_name, fld__map_sort, fld__map_src).Crt_int(fld__map_src, src_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (!rdr.Move_next()) return 0;
|
||||
Object max = rdr.Read_obj(fld__map_sort);
|
||||
return max == null ? 0 : Int_.Cast(max) + 10;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Delete(int src_id, int trg_id) {
|
||||
conn.Stmt_delete(tbl_name, fld__map_src, fld__map_trg).Crt_int(fld__map_src, src_id).Crt_int(fld__map_trg, trg_id).Exec_delete();
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
public class Xocfg_txt_itm {
|
||||
public Xocfg_txt_itm(int id, String lang, String name, String help) {
|
||||
this.id = id;
|
||||
this.lang = lang;
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Lang() {return lang;} private final String lang;
|
||||
public String Name() {return name;} private final String name;
|
||||
public String Help() {return help;} private final String help;
|
||||
|
||||
public static final int Tid__grp = 1, Tid__itm = 2;
|
||||
}
|
||||
|
||||
@@ -13,38 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xocfg_txt_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__nde_id, fld__nde_lang, fld__nde_name, fld__nde_help;
|
||||
private final Db_conn conn;
|
||||
public Xocfg_txt_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cfg_txt";
|
||||
this.fld__nde_id = flds.Add_int_pkey("nde_id"); // EX: '2'
|
||||
this.fld__nde_lang = flds.Add_str("nde_lang", 16); // EX: 'en'
|
||||
this.fld__nde_name = flds.Add_str("nde_name", 255); // EX: 'Cfg Name'
|
||||
this.fld__nde_help = flds.Add_str("nde_help", 4096); // EX: 'Help text'
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Upsert(int nde_id, String nde_lang, String nde_name, String nde_help) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__nde_id, fld__nde_lang), nde_id, nde_lang, nde_name, nde_help);
|
||||
}
|
||||
public Xocfg_txt_itm Select_by_id_or_null(int id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__nde_id).Crt_int(fld__nde_id, id).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Load(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
private Xocfg_txt_itm Load(Db_rdr rdr) {
|
||||
return new Xocfg_txt_itm
|
||||
( rdr.Read_int(fld__nde_id)
|
||||
, rdr.Read_str(fld__nde_lang)
|
||||
, rdr.Read_str(fld__nde_name)
|
||||
, rdr.Read_str(fld__nde_help)
|
||||
);
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
public class Xocfg_val_row {
|
||||
public Xocfg_val_row(String key, String ctx, String val, String date) {
|
||||
this.key = key;
|
||||
this.ctx = ctx;
|
||||
this.val = val;
|
||||
this.date = date;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Ctx() {return ctx;} private final String ctx;
|
||||
public String Val() {return val;} private final String val;
|
||||
public String Date() {return date;} private final String date;
|
||||
}
|
||||
|
||||
@@ -13,56 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.dbs.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.dbs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xocfg_val_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld__itm_key, fld__itm_ctx, fld__itm_val, fld__itm_date;
|
||||
private final Db_conn conn;
|
||||
public Xocfg_val_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cfg_val";
|
||||
this.fld__itm_key = flds.Add_str("itm_key", 255); // EX: 'xowa.app.cfg_1'
|
||||
this.fld__itm_ctx = flds.Add_str("itm_ctx", 255); // EX: 'app'; 'en.w'; 'ns-10'
|
||||
this.fld__itm_val = flds.Add_str("itm_val", 4096); // EX: 'abc'
|
||||
this.fld__itm_date = flds.Add_str("itm_date", 16); // EX: '20160901_010203'
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "core", fld__itm_key, fld__itm_ctx) // NOTE: key,ctx b/c key has greater specificity
|
||||
));
|
||||
}
|
||||
public void Upsert(String ctx, String key, String val, String date) {
|
||||
Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld__itm_key, fld__itm_ctx), key, ctx, val, date);
|
||||
}
|
||||
public void Delete(String ctx, String key) {
|
||||
conn.Stmt_delete(tbl_name, fld__itm_key, fld__itm_ctx).Crt_str(fld__itm_key, key).Crt_str(fld__itm_ctx, ctx).Exec_delete();
|
||||
}
|
||||
public Xocfg_val_row Select_one_or_null(String ctx, String key) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_key, fld__itm_ctx).Crt_str(fld__itm_key, key).Crt_str(fld__itm_ctx, ctx).Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? Load(rdr) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public Xocfg_val_row[] Select_all(String key) {
|
||||
List_adp list = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld__itm_key).Crt_str(fld__itm_key, key).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
list.Add(Load(rdr));
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return (Xocfg_val_row[])list.To_ary_and_clear(Xocfg_val_row.class);
|
||||
}
|
||||
private Xocfg_val_row Load(Db_rdr rdr) {
|
||||
return new Xocfg_val_row
|
||||
( rdr.Read_str(fld__itm_key)
|
||||
, rdr.Read_str(fld__itm_ctx)
|
||||
, rdr.Read_str(fld__itm_val)
|
||||
, rdr.Read_str(fld__itm_date)
|
||||
);
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
import gplx.gfui.*; import gplx.xowa.guis.bnds.*;
|
||||
public class Xoitm_gui_binding {
|
||||
public static String[] To_gui(String val) {
|
||||
Gfui_bnd_parser parser = Gfui_bnd_parser.new_en_();
|
||||
String[] rv = new String[2];
|
||||
int pipe_pos = String_.FindFwd(val, "|");
|
||||
if (pipe_pos == -1) throw Err_.new_wo_type("cfg.binding:unknown gui binding; val=" + val);
|
||||
rv[0] = Xog_bnd_box_.To_gui_str(String_.Mid(val, 0, pipe_pos));
|
||||
rv[1] = parser.Xto_norm(String_.Mid(val, pipe_pos + 1, String_.Len(val)));
|
||||
return rv;
|
||||
}
|
||||
public static String To_db_str(String val) {
|
||||
Gfui_bnd_parser parser = Gfui_bnd_parser.new_en_();
|
||||
String[] rv = new String[2];
|
||||
int pipe_pos = String_.FindFwd(val, "|");
|
||||
if (pipe_pos == -1) throw Err_.new_wo_type("cfg.binding:unknown gui binding; val=" + val);
|
||||
rv[0] = Xog_bnd_box_.To_key_str(String_.Mid(val, 0, pipe_pos));
|
||||
rv[1] = parser.Xto_gfui(String_.Mid(val, pipe_pos + 1, String_.Len(val)));
|
||||
return rv[0] + "|" + rv[1];
|
||||
}
|
||||
public static String[] To_ary(String val) {
|
||||
String[] rv = new String[2];
|
||||
int pipe_pos = String_.FindFwd(val, "|");
|
||||
rv[0] = String_.Mid(val, 0, pipe_pos);
|
||||
rv[1] = String_.Mid(val, pipe_pos + 1, String_.Len(val));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
public class Xoitm_lang_tid {
|
||||
public static final String Lang__dflt = "en";
|
||||
}
|
||||
|
||||
@@ -13,12 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
public class Xoitm_scope_enum { // SERIALIZED
|
||||
public static final int Tid__app = 1, Tid__wiki = 2;
|
||||
public static int To_int(String raw) {
|
||||
if (String_.Eq(raw, "app")) return Tid__app;
|
||||
else if (String_.Eq(raw, "wiki")) return Tid__wiki;
|
||||
else throw Err_.new_unhandled_default(raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,28 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
public class Xoitm_type_enum {
|
||||
public static final int
|
||||
Tid__bool = 0
|
||||
, Tid__int = 1
|
||||
, Tid__str = 2
|
||||
, Tid__memo = 3
|
||||
, Tid__list = 4
|
||||
, Tid__btn = 5
|
||||
, Tid__io_cmd = 6
|
||||
, Tid__gui_binding = 7
|
||||
;
|
||||
|
||||
public static int To_uid(String v) {
|
||||
if (String_.Eq(v, Bool_.Cls_val_name)) return Tid__bool;
|
||||
else if (String_.Eq(v, Int_.Cls_val_name)) return Tid__int;
|
||||
else if (String_.Eq(v, String_.Cls_val_name)) return Tid__str;
|
||||
else if (String_.Eq(v, "memo")) return Tid__memo;
|
||||
else if (String_.Eq(v, "btn")) return Tid__btn;
|
||||
else if (String_.Eq(v, "io.cmd")) return Tid__io_cmd;
|
||||
else if (String_.Eq(v, "gui.binding")) return Tid__gui_binding;
|
||||
else if (String_.Has_at_bgn(v, "list:")) return Tid__list;
|
||||
else throw Err_.new_wo_type("unknown cfg type enum; v=" + v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,73 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
public class Xocfg_cache_grp {
|
||||
private final Hash_adp vals = Hash_adp_.New();
|
||||
private final Ordered_hash subs = Ordered_hash_.New();
|
||||
public Xocfg_cache_grp(String key, String dflt, String data_type) {
|
||||
this.key = key;
|
||||
this.dflt = dflt;
|
||||
this.data_type = data_type;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Data_type() {return data_type;} private final String data_type;
|
||||
public String Dflt() {return dflt;} private String dflt;
|
||||
public void Dflt_(String v) {this.dflt = v;}
|
||||
public String Get(String ctx) {
|
||||
// exact match; EX: "en.w|key_1"
|
||||
Xocfg_cache_itm rv = (Xocfg_cache_itm)vals.Get_by(ctx);
|
||||
if (rv != null) return rv.Val();
|
||||
|
||||
// global match; EX: "app|key_1"
|
||||
rv = (Xocfg_cache_itm)vals.Get_by(Xocfg_mgr.Ctx__app);
|
||||
if (rv != null) return rv.Val();
|
||||
|
||||
// dflt
|
||||
return dflt;
|
||||
}
|
||||
public void Set(String ctx, String val) {
|
||||
Xocfg_cache_itm rv = (Xocfg_cache_itm)vals.Get_by(ctx);
|
||||
if (rv == null) {
|
||||
rv = new Xocfg_cache_itm(ctx, key, val);
|
||||
vals.Add(ctx, rv);
|
||||
}
|
||||
else {
|
||||
rv.Val_(val);
|
||||
}
|
||||
}
|
||||
public void Del(String ctx) {
|
||||
vals.Del(ctx);
|
||||
}
|
||||
public void Add(String ctx, Xocfg_cache_itm itm) {
|
||||
vals.Add(ctx, itm);
|
||||
}
|
||||
public void Sub(Gfo_invk sub, String ctx, String evt) {
|
||||
List_adp list = (List_adp)subs.Get_by(ctx);
|
||||
if (list == null) {
|
||||
list = List_adp_.New();
|
||||
subs.Add(ctx, list);
|
||||
}
|
||||
list.Add(new Xocfg_cache_sub(sub, ctx, evt, key));
|
||||
}
|
||||
public void Pub(String ctx, String val) {
|
||||
// exact match; EX: "en.w|key_1"
|
||||
List_adp list = (List_adp)subs.Get_by(ctx);
|
||||
if (list == null) {// global match; EX: "app|key_1"
|
||||
int len = subs.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
list = (List_adp)subs.Get_at(i);
|
||||
Pub(list, val);
|
||||
}
|
||||
}
|
||||
if (list != null) // NOTE: check for null as it's possible for no subscribers
|
||||
Pub(list, val);
|
||||
}
|
||||
private void Pub(List_adp list, String val) {
|
||||
int len = list.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xocfg_cache_sub sub = (Xocfg_cache_sub)list.Get_at(i);
|
||||
Gfo_invk_.Invk_by_msg(sub.Sub(), sub.Evt(), GfoMsg_.new_parse_(sub.Evt()).Add("v", val));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
public class Xocfg_cache_itm {
|
||||
public Xocfg_cache_itm(String ctx, String key, String val) {
|
||||
this.ctx = ctx;
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
public String Ctx() {return ctx;} private final String ctx;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Val() {return val;} private String val;
|
||||
public void Val_(String val) {this.val = val;}
|
||||
}
|
||||
|
||||
@@ -13,91 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.dbs.tbls.*; import gplx.xowa.addons.apps.cfgs.enums.*;
|
||||
public class Xocfg_cache_mgr {
|
||||
private final Hash_adp grps = Hash_adp_.New();
|
||||
public Xocfg_cache_mgr() {
|
||||
this.db_app = new Xocfg_db_app(Db_conn_.Noop);
|
||||
this.db_usr = new Xocfg_db_usr(db_app, Db_conn_.Noop);
|
||||
}
|
||||
public void Init_by_app(Db_conn app_conn, Db_conn usr_conn) {
|
||||
this.db_app = new Xocfg_db_app(app_conn);
|
||||
this.db_usr = new Xocfg_db_usr(db_app, usr_conn);
|
||||
}
|
||||
public Xocfg_db_app Db_app() {return db_app;} private Xocfg_db_app db_app;
|
||||
public Xocfg_db_usr Db_usr() {return db_usr;} private Xocfg_db_usr db_usr;
|
||||
// public void Clear() {grps.Clear();} // TOMBSTONE: do not call .Clear b/c subscribers are kept in grps and are only loaded once at app startup
|
||||
public String Get(String ctx, String key) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
return grp.Get(ctx);
|
||||
}
|
||||
public String Get_or(String ctx, String key, String or) {
|
||||
Xocfg_cache_grp grp = (Xocfg_cache_grp)grps.Get_by(key);
|
||||
if (grp == null) {
|
||||
grp = Load_grp(key, or);
|
||||
grps.Add(key, grp);
|
||||
}
|
||||
return grp.Get(ctx);
|
||||
}
|
||||
public void Set(String ctx, String key, String val) {Set(Bool_.Y, ctx, key, val);}
|
||||
public void Set_wo_save(String ctx, String key, String val) {Set(Bool_.N, ctx, key, val);}
|
||||
public void Set(boolean save, String ctx, String key, String val) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
grp.Pub(ctx, val); // publish first; if fail will throw error
|
||||
grp.Set(ctx, val);
|
||||
if (save) {
|
||||
if (String_.Eq(grp.Dflt(), val))
|
||||
db_usr.Del(ctx, key);
|
||||
else
|
||||
db_usr.Set_str(ctx, key, val);
|
||||
}
|
||||
}
|
||||
public void Del(String ctx, String key) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
grp.Del(ctx);
|
||||
db_usr.Del(ctx, key);
|
||||
grp.Pub(ctx, grp.Dflt());
|
||||
}
|
||||
public void Sub(Gfo_invk sub, String ctx, String key, String evt) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
grp.Sub(sub, ctx, evt);
|
||||
}
|
||||
public void Pub(String ctx, String key, String val) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
grp.Pub(ctx, val);
|
||||
}
|
||||
public void Dflt(String key, String val) {
|
||||
Xocfg_cache_grp grp = Grps__get_or_load(key);
|
||||
grp.Dflt_(val);
|
||||
grp.Pub(Xocfg_mgr.Ctx__app, val); // need to pub after dflt is changed; for now, just pub at app-level
|
||||
}
|
||||
public Xocfg_cache_grp Grps__get_or_load(String key) {
|
||||
Xocfg_cache_grp grp = (Xocfg_cache_grp)grps.Get_by(key);
|
||||
if (grp == null) {
|
||||
grp = Load_grp(key, "");
|
||||
grps.Add(key, grp);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
private Xocfg_cache_grp Load_grp(String key, String or) {
|
||||
// get data from db
|
||||
Xocfg_itm_row meta_itm = db_app.Tbl__itm().Select_by_key_or_null(key);
|
||||
if (meta_itm == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:itm not found; key=~{0}", key);
|
||||
return new Xocfg_cache_grp(key, or, String_.Cls_val_name);
|
||||
}
|
||||
Xocfg_val_row[] itms = db_usr.Tbl__val().Select_all(meta_itm.Key());
|
||||
|
||||
// make
|
||||
Xocfg_cache_grp rv = new Xocfg_cache_grp(key, meta_itm.Dflt(), meta_itm.Type());
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xocfg_val_row itm = itms[0];
|
||||
String itm_ctx = itm.Ctx();
|
||||
rv.Add(itm_ctx, new Xocfg_cache_itm(itm_ctx, key, itm.Val()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,66 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.dbs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.specials.maints.services.*;
|
||||
public class Xocfg_cache_mgr__tst {
|
||||
private final Xocfg_cache_mgr__fxt fxt = new Xocfg_cache_mgr__fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Get__wiki() {
|
||||
fxt.Init__db_add("en.w", "key_1", "val_1");
|
||||
fxt.Test__get("en.w", "key_1", "val_1");
|
||||
fxt.Test__get("en.d", "key_1", "dflt");
|
||||
}
|
||||
@Test public void Get__app() {
|
||||
String ctx = Xocfg_mgr.Ctx__app;
|
||||
fxt.Init__db_add(ctx, "key_1", "val_1");
|
||||
fxt.Test__get(ctx, "key_1", "val_1");
|
||||
fxt.Test__get("en.w", "key_1", "val_1");
|
||||
fxt.Test__get("en.d", "key_1", "val_1");
|
||||
}
|
||||
@Test public void Set__app() {
|
||||
String ctx = Xocfg_mgr.Ctx__app;
|
||||
fxt.Init__db_add(ctx, "key_1", "123");
|
||||
fxt.Init__sub(ctx, "key_1", "key_1");
|
||||
fxt.Exec__set(ctx, "key_1", "234");
|
||||
fxt.Test__get(ctx, "key_1", "234");
|
||||
fxt.Sub().Test__key_1(234);
|
||||
}
|
||||
}
|
||||
class Xocfg_cache_mgr__fxt {
|
||||
private Xocfg_cache_mgr mgr = new Xocfg_cache_mgr();
|
||||
private int id;
|
||||
public void Clear() {
|
||||
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get_or_autocreate(true, Io_url_.new_any_("mem/xowa/wiki/en.wikipedia.org/"));
|
||||
mgr.Init_by_app(conn, conn);
|
||||
}
|
||||
public Xocfg_cache_sub_mock Sub() {return sub;} private Xocfg_cache_sub_mock sub = new Xocfg_cache_sub_mock();
|
||||
public void Init__db_add(String ctx, String key, Object val) {
|
||||
Xocfg_maint_svc.Create_grp(mgr.Db_app(), "", id++, "test_grp", "", "");
|
||||
Xocfg_maint_svc.Create_itm(mgr.Db_app(), "test_grp", id++, key, "", "", "wiki", String_.Cls_val_name, "dflt", "", "");
|
||||
mgr.Db_usr().Set_str(ctx, key, Object_.Xto_str_strict_or_null(val));
|
||||
}
|
||||
public void Init__sub(String ctx, String key, String evt) {
|
||||
mgr.Sub(sub, ctx, key, evt);
|
||||
}
|
||||
public void Test__get(String ctx, String key, String expd) {
|
||||
Gftest.Eq__str(expd, mgr.Get(ctx, key), "ctx={0} key={1}", ctx, key);
|
||||
}
|
||||
public void Exec__set(String ctx, String key, String val) {
|
||||
mgr.Set(ctx, key, val);
|
||||
}
|
||||
}
|
||||
class Xocfg_cache_sub_mock implements Gfo_invk {
|
||||
private int key_1;
|
||||
public void Test__key_1(int expd) {
|
||||
Gftest.Eq__int(expd, key_1);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Evt__key_1)) {key_1 = m.ReadInt("v");}
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Evt__key_1 = "key_1";
|
||||
}
|
||||
|
||||
@@ -13,16 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
class Xocfg_cache_sub {
|
||||
public Xocfg_cache_sub(Gfo_invk sub, String ctx, String evt, String key) {
|
||||
this.ctx = ctx;
|
||||
this.key = key;
|
||||
this.evt = evt;
|
||||
this.sub = sub;
|
||||
}
|
||||
public String Ctx() {return ctx;} private final String ctx;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Evt() {return evt;} private final String evt;
|
||||
public Gfo_invk Sub() {return sub;} private final Gfo_invk sub;
|
||||
}
|
||||
|
||||
@@ -13,43 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.dflts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.mgrs.caches.*;
|
||||
public class Xocfg_dflt_mgr {
|
||||
private final Xocfg_cache_mgr cache_mgr;
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xocfg_dflt_mgr(Xocfg_cache_mgr cache_mgr) {
|
||||
this.cache_mgr = cache_mgr;
|
||||
}
|
||||
public String Get_or(String key, String or) {
|
||||
Gfo_invk itm = (Gfo_invk)hash.Get_by(key);
|
||||
return (itm == null) ? or : (String)Gfo_invk_.Invk_by_key(itm, key);
|
||||
}
|
||||
public void Add(String key, String val) {
|
||||
hash.Add(key, new Xocfg_dflt_itm__static(val));
|
||||
cache_mgr.Dflt(key, val);
|
||||
}
|
||||
public void Add(Gfo_invk invk, String... keys) {
|
||||
for (String key : keys) {
|
||||
hash.Add_if_dupe_use_nth(key, invk);
|
||||
}
|
||||
}
|
||||
public static void Run_os_gfs(String user_name, gplx.xowa.apps.gfs.Xoa_gfs_mgr gfs_mgr, gplx.xowa.apps.fsys.Xoa_fsys_mgr fsys_mgr) {
|
||||
Io_url url = fsys_mgr.Root_dir().GenSubFil_nest("user", user_name, "app", "cfg", "os." + Xoa_app_.Op_sys_str + ".gfs");
|
||||
if (!Io_mgr.Instance.ExistsFil(url)) {
|
||||
Io_url dflt_url = fsys_mgr.Bin_plat_dir().GenSubFil_nest("xowa", "cfg", "os.default.gfs");
|
||||
if (Io_mgr.Instance.ExistsFil(dflt_url)) // TEST: also, DRD
|
||||
Io_mgr.Instance.CopyFil_args(dflt_url, url, true).MissingFails_off().Exec();
|
||||
}
|
||||
gfs_mgr.Run_url(url);
|
||||
}
|
||||
}
|
||||
class Xocfg_dflt_itm__static implements Gfo_invk {
|
||||
private final String val;
|
||||
public Xocfg_dflt_itm__static(String val) {
|
||||
this.val = val;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.execs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
public class Xocfg_exec_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public void Add(Gfo_invk invk, String... cmds) {
|
||||
for (String cmd : cmds) {
|
||||
hash.Add(cmd, invk);
|
||||
}
|
||||
}
|
||||
public void Exec(String cmd, Object... args) {
|
||||
Gfo_invk invk = (Gfo_invk)hash.Get_by(cmd);
|
||||
|
||||
// create msg and add args
|
||||
GfoMsg msg = GfoMsg_.new_parse_(cmd);
|
||||
int args_len = args.length;
|
||||
if (args_len > 0) {
|
||||
for (int i = 0; i < args_len; i += 2) {
|
||||
msg.Add((String)args[i], args[i + 1]);
|
||||
}
|
||||
}
|
||||
Gfo_invk_.Invk_by_msg(invk, cmd, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,34 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.mgrs.types; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.mgrs.*;
|
||||
public class Xocfg_type_mgr {
|
||||
private final Ordered_hash list_hash = Ordered_hash_.New();
|
||||
public Xocfg_type_mgr() {
|
||||
this.Lists__add("list:xowa.app.startup.window.mode", "previous", "maximized", "absolute", "relative", "default");
|
||||
this.Lists__add("list:xowa.app.startup.pages.type", "blank", "xowa", "previous", "custom");
|
||||
this.Lists__add("list:xowa.gui.html_box.page_load_mode", "mem", "url");
|
||||
this.Lists__add("list:xowa.html.portal.missing_class", Keyval_.new_("", "Show as blue link"), Keyval_.new_("new", "Show as red link"), Keyval_.new_("xowa_display_none", "Hide"));
|
||||
this.Lists__add("list:xowa.html.tidy.engine", "tidy", "jtidy");
|
||||
this.Lists__add("list:xowa.bldr.db.zip_mode", Keyval_.new_("raw", "text"), Keyval_.new_("gzip"), Keyval_.new_("bzip2"), Keyval_.new_("xz"));
|
||||
this.Lists__add("list:xowa.addon.category.catpage.missing_class", "normal", "hide", "red_link");
|
||||
this.Lists__add("list:xowa.addon.http_server.file_retrieve_mode", Keyval_.new_("wait"), Keyval_.new_("skip"), Keyval_.new_("async_server", "async server"));
|
||||
this.Lists__add("list:xowa.addon.scribunto.engine", "luaj", "lua");
|
||||
this.Lists__add("list:xowa.addon.math.renderer", Keyval_.new_("mathjax","MathJax"), Keyval_.new_("latex", "LaTeX"));
|
||||
}
|
||||
public void Lists__add(String key, String... vals) {
|
||||
int len = vals.length;
|
||||
Keyval[] itms = new Keyval[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
itms[i] = Keyval_.new_(vals[i]);
|
||||
}
|
||||
Lists__add(key, itms);
|
||||
}
|
||||
public void Lists__add(String key, Keyval... itms) {
|
||||
if (!list_hash.Has(key)) // ignore multiple calls from Init_by_wiki; EX: Xow_hdump_mode
|
||||
list_hash.Add(key, itms);
|
||||
}
|
||||
public Keyval[] Lists__get(String key) {
|
||||
return (Keyval[])list_hash.Get_by_or_fail(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,55 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public class Xoedit_grp implements Xoedit_nde, Mustache_doc_itm {
|
||||
private String lang, name;
|
||||
public Xoedit_grp(int id, String key, int sort) {
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.sort = sort;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
public int Sort() {return sort;} private final int sort;
|
||||
public String Help() {return help;} private String help;
|
||||
|
||||
public Xoedit_itm[] Itms() {return itms;} private Xoedit_itm[] itms = new Xoedit_itm[0];
|
||||
public void Itms_(Xoedit_itm[] v) {this.itms = v;}
|
||||
public void Load_by_i18n(String lang, String name, String help) {
|
||||
this.lang = lang;
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
}
|
||||
public Gfobj_nde To_nde(Bry_bfr tmp_bfr) {
|
||||
Gfobj_nde rv = Gfobj_nde.New();
|
||||
rv.Add_int("id", id);
|
||||
rv.Add_str("key", key);
|
||||
rv.Add_str("lang", lang);
|
||||
rv.Add_str("name", name);
|
||||
rv.Add_str("help", help);
|
||||
|
||||
List_adp list = List_adp_.New();
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoedit_itm itm = itms[i];
|
||||
list.Add(itm.To_nde(tmp_bfr));
|
||||
}
|
||||
rv.Add_ary("itms", new Gfobj_ary((Gfobj_nde[])list.To_ary_and_clear(Gfobj_nde.class)));
|
||||
return rv;
|
||||
}
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
if (String_.Eq(k, "id")) bfr.Add_int(id);
|
||||
else if (String_.Eq(k, "key")) bfr.Add_str_u8(key);
|
||||
else if (String_.Eq(k, "lang")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "name")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "help")) bfr.Add_str_u8(help);
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "itms")) return itms;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,89 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
import gplx.core.gfobjs.*; import gplx.langs.jsons.*;
|
||||
import gplx.xowa.addons.apps.cfgs.mgrs.types.*; import gplx.xowa.addons.apps.cfgs.enums.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xoedit_itm implements Xoedit_nde, Mustache_doc_itm {
|
||||
private boolean edited;
|
||||
private String type, html_atrs, html_cls, lang, name, ctx, date;
|
||||
private byte[] val, dflt; // NOTE: data is always escaped b/c it is only consumed by mustache; EX: "<'" not "<'"
|
||||
private Xocfg_type_mgr type_mgr;
|
||||
public Xoedit_itm(Xocfg_type_mgr type_mgr, int id, String key, int sort) {
|
||||
this.type_mgr = type_mgr;
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.sort = sort;
|
||||
}
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Help() {return help;} private String help;
|
||||
|
||||
public int Sort() {return sort;} private final int sort;
|
||||
public void Load_by_meta(Bry_bfr tmp_bfr, String type, String dflt_str, String html_atrs, String html_cls) {
|
||||
this.type = type;
|
||||
this.dflt = Gfh_utl.Escape_html_as_bry(tmp_bfr, Bry_.new_u8(dflt_str), Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.N);
|
||||
this.html_atrs = html_atrs;
|
||||
this.html_cls = html_cls;
|
||||
}
|
||||
public void Load_by_i18n(String lang, String name, String help) {
|
||||
this.lang = lang;
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
}
|
||||
public void Load_by_data(Bry_bfr tmp_bfr, String ctx, String val_str, String date) {
|
||||
this.ctx = ctx;
|
||||
this.val = Gfh_utl.Escape_html_as_bry(tmp_bfr, Bry_.new_u8(val_str), Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.N);
|
||||
this.date = date;
|
||||
this.edited = true;
|
||||
if ( String_.Has(html_cls, "read"+"only")
|
||||
|| Xoitm_type_enum.To_uid(type) == Xoitm_type_enum.Tid__btn)
|
||||
edited = false;
|
||||
}
|
||||
public void Set_data_by_dflt() {
|
||||
this.ctx = Xocfg_mgr.Ctx__app;
|
||||
this.val = dflt;
|
||||
this.date = String_.Empty;
|
||||
this.edited = false;
|
||||
}
|
||||
public Gfobj_nde To_nde(Bry_bfr tmp_bfr) {
|
||||
Gfobj_nde rv = Gfobj_nde.New();
|
||||
rv.Add_int("id", id);
|
||||
rv.Add_str("key", key);
|
||||
rv.Add_bry("dflt", dflt);
|
||||
rv.Add_str("lang", lang);
|
||||
rv.Add_str("name", name);
|
||||
rv.Add_str("help", help);
|
||||
rv.Add_str("ctx", ctx);
|
||||
rv.Add_bry("val", val);
|
||||
rv.Add_str("date", date);
|
||||
rv.Add_str("type", type);
|
||||
To_html(tmp_bfr, type_mgr);
|
||||
rv.Add_str("html", tmp_bfr.To_str_and_clear());
|
||||
rv.Add_bool("edited", edited);
|
||||
return rv;
|
||||
}
|
||||
private void To_html(Bry_bfr bfr, Xocfg_type_mgr type_mgr) {
|
||||
Xoedit_itm_html.Build_html(bfr, type_mgr, key, name, type, html_atrs, html_cls, val);
|
||||
}
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
if (String_.Eq(k, "id")) bfr.Add_int(id);
|
||||
else if (String_.Eq(k, "key")) bfr.Add_str_u8(key);
|
||||
else if (String_.Eq(k, "dflt")) bfr.Add_bry(dflt);
|
||||
else if (String_.Eq(k, "lang")) bfr.Add_str_u8(lang);
|
||||
else if (String_.Eq(k, "name")) bfr.Add_str_u8(name);
|
||||
else if (String_.Eq(k, "help")) bfr.Add_str_u8(help);
|
||||
else if (String_.Eq(k, "ctx")) bfr.Add_str_u8(ctx);
|
||||
else if (String_.Eq(k, "val")) bfr.Add_bry(val);
|
||||
else if (String_.Eq(k, "date")) bfr.Add_str_u8(date);
|
||||
else if (String_.Eq(k, "type")) bfr.Add_str_u8(type);
|
||||
else if (String_.Eq(k, "html")) To_html(bfr.Bfr(), type_mgr);
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String k) {
|
||||
if (String_.Eq(k, "edited")) return Mustache_doc_itm_.Ary__bool(edited);
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,107 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.xowa.addons.apps.cfgs.enums.*;
|
||||
import gplx.xowa.addons.apps.cfgs.mgrs.types.*;
|
||||
import gplx.xowa.guis.bnds.*;
|
||||
public class Xoedit_itm_html {
|
||||
public static void Build_html(Bry_bfr bfr, Xocfg_type_mgr type_mgr, String key, String name, String type, String html_atrs, String html_cls, byte[] val) {
|
||||
// prepend space for html insertion; EX: "type='checkbox'{1}>" with "a=b" -> "type='checkbox' a='b'" x> "type='checkbox'a='b'"
|
||||
if (String_.Len_gt_0(html_atrs)) html_atrs = " " + html_atrs;
|
||||
if (String_.Len_gt_0(html_cls)) html_cls = " " + html_cls;
|
||||
|
||||
// build html
|
||||
bfr.Add_byte_nl();
|
||||
switch (Xoitm_type_enum.To_uid(type)) {
|
||||
case Xoitm_type_enum.Tid__bool:
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<input id=\"{3}\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}\" accesskey=\"d\" class=\"xocfg_data__bool{2}\" type=\"checkbox\"{1}{4}></input>"
|
||||
, type, html_atrs, html_cls, key, Bry_.Eq(val, Bool_.Y_bry) ? " checked=\"checked\"" : "");
|
||||
break;
|
||||
case Xoitm_type_enum.Tid__int:
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<input id=\"{3}\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}\" accesskey=\"d\" class=\"xocfg_data__int{2}\" type=\"text\"{1} value=\"{4}\"></input>"
|
||||
, type, html_atrs, html_cls, key, val);
|
||||
break;
|
||||
case Xoitm_type_enum.Tid__str:
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<input id=\"{3}\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}\" accesskey=\"d\" class=\"xocfg_data__str{2}\" type=\"text\"{1} value=\"{4}\"></input>"
|
||||
, type, html_atrs, html_cls, key, val);
|
||||
break;
|
||||
case Xoitm_type_enum.Tid__memo:
|
||||
if (String_.Len_eq_0(html_atrs)) html_atrs = " rows=\"4\"";
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<textarea id=\"{3}\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}\" accesskey=\"d\" class=\"xocfg_data__memo{2}\"{1}>{4}</textarea>"
|
||||
, type, html_atrs, html_cls, key, val);
|
||||
break;
|
||||
case Xoitm_type_enum.Tid__list:
|
||||
// get list of kvs by type
|
||||
Keyval[] kvs_ary = type_mgr.Lists__get(type);
|
||||
int len = kvs_ary.length;
|
||||
if (String_.Len_eq_0(html_atrs)) html_atrs = "size=\"" + Int_.To_str(len) + "\"";
|
||||
|
||||
// build html
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<select id=\"{3}\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}\" accesskey=\"d\" class=\"xocfg_data__list{2}\" {1}>\n"
|
||||
, type, html_atrs, html_cls, key);
|
||||
String val_str = String_.new_u8(val);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval kv = kvs_ary[i];
|
||||
String kv_key = kv.Key();
|
||||
String kv_val = kv.Val_to_str_or_null();
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<option value=\"{0}\"{2}>{1}</option>\n"
|
||||
, kv_key, kv_val, String_.Eq(val_str, kv_key) ? " selected=\"selected\"" : "");
|
||||
}
|
||||
bfr.Add_str_u8_fmt("</select>\n");
|
||||
break;
|
||||
case Xoitm_type_enum.Tid__io_cmd:
|
||||
String[] lines = Xocfg_mgr.Parse_io_cmd(String_.new_u8(val));
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<input class=\"xocfg_data__io_cmd__exe__txt{2}\" id=\"{3}-exe\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}-exe\" accesskey=\"d\" type=\"text\"{1} value=\"{4}\"></input>\n"
|
||||
+ "<span class=\"xoimg_btn_x16 xoimg_app_configure\" onclick='xo.cfg_edit.io_cmd__select(\"file\", \"{3}-exe\", \"Please select a file.\");'> </span><br/>\n"
|
||||
, type, html_atrs, html_cls, key, lines[0]);
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<input class=\"xocfg_data__io_cmd__arg__txt{2}\" id=\"{3}-arg\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}-arg\" accesskey=\"d\" type=\"text\"{1} value=\"{4}\">\n"
|
||||
, type, html_atrs, html_cls, key, lines[1]);
|
||||
break;
|
||||
case Xoitm_type_enum.Tid__gui_binding: {
|
||||
String[] flds = Xoitm_gui_binding.To_gui(String_.new_u8(val));
|
||||
|
||||
// write box
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<select class=\"xocfg_data__gui_binding__box\" id=\"{3}-box\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}-box\" size=\"1\" accesskey=\"d\"{1}>\n"
|
||||
, type, html_atrs, html_cls, key, flds[0]);
|
||||
Xog_bnd_box[] box_ary = Xog_bnd_box_.Ary();
|
||||
int box_len = box_ary.length;
|
||||
String selected_box = flds[0];
|
||||
for (int i = 0; i < box_len; i++) {
|
||||
Xog_bnd_box kv = box_ary[i];
|
||||
String kv_key = kv.Key();
|
||||
String kv_val = Xog_bnd_box_.To_gui_str(kv_key);
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<option value=\"{0}\"{2}>{1}</option>\n"
|
||||
, kv_key, kv_val, String_.Eq(selected_box, kv_val) ? " selected=\"selected\"" : "");
|
||||
}
|
||||
bfr.Add_str_u8_fmt("</select>\n");
|
||||
|
||||
// write ipt
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<input class=\"xocfg_data__gui_binding__ipt\" id=\"{3}-ipt\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}-ipt\" accesskey=\"d\" type=\"text\"{1} value=\"{4}\"></input>\n"
|
||||
, type, html_atrs, html_cls, key, flds[1]);
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<span class=\"xoimg_btn_x16 xoimg_app_configure\" onclick='xo.cfg_edit.gui_binding__remap_send(\"{3}\", \"{4}\");'> </span>\n"
|
||||
, type, html_atrs, html_cls, key, name);
|
||||
break;
|
||||
}
|
||||
case Xoitm_type_enum.Tid__btn:
|
||||
bfr.Add_str_u8_fmt
|
||||
( "<button id=\"{3}\" data-xocfg-key=\"{3}\" data-xocfg-type=\"{0}\" class=\"xocfg_data__btn{2}\" {1}>{4}</button>"
|
||||
, type, html_atrs, html_cls, key, name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,23 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
public class Xoedit_nav_itm implements Mustache_doc_itm {
|
||||
private final boolean selected;
|
||||
private final String key, text;
|
||||
public Xoedit_nav_itm(boolean selected, String key, String text) {
|
||||
this.selected = selected;
|
||||
this.key = key;
|
||||
this.text = text;
|
||||
}
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
if (String_.Eq(k, "key")) bfr.Add_str_u8(key);
|
||||
else if (String_.Eq(k, "text")) bfr.Add_str_u8(text);
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String k) {
|
||||
if (String_.Eq(k, "selected")) return Mustache_doc_itm_.Ary__bool(selected);
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
public class Xoedit_nav_mgr implements Mustache_doc_itm {
|
||||
public Xoedit_nav_itm[] Itms() {return itms;} private final Xoedit_nav_itm[] itms;
|
||||
public Xoedit_nav_mgr(Xoedit_nav_itm[] itms) {
|
||||
this.itms = itms;
|
||||
}
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String k) {
|
||||
if (String_.Eq(k, "itms")) return itms;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
public interface Xoedit_nde {
|
||||
int Id();
|
||||
String Key();
|
||||
String Help();
|
||||
void Load_by_i18n(String lang, String name, String help);
|
||||
}
|
||||
|
||||
@@ -13,64 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
public class Xoedit_nde_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Ordered_hash id_hash = Ordered_hash_.New();
|
||||
private final List_adp deleted = List_adp_.New();
|
||||
public int Len() {
|
||||
return hash.Len();
|
||||
}
|
||||
public void Add(Xoedit_nde nde) {
|
||||
hash.Add(nde.Key(), nde);
|
||||
id_hash.Add(nde.Id(), nde);
|
||||
}
|
||||
public Xoedit_nde Get_at(int i) {
|
||||
return (Xoedit_nde)hash.Get_at(i);
|
||||
}
|
||||
public Xoedit_nde Get_by_or_fail(String key) {
|
||||
return (Xoedit_nde)hash.Get_by_or_fail(key);
|
||||
}
|
||||
public Xoedit_nde Get_by_or_fail(int id) {
|
||||
return (Xoedit_nde)id_hash.Get_by_or_fail(id);
|
||||
}
|
||||
public Xoedit_grp[] To_grp_ary_and_clear() {
|
||||
Xoedit_grp[] rv = (Xoedit_grp[])hash.To_ary_and_clear(Xoedit_grp.class);
|
||||
id_hash.Clear();
|
||||
return rv;
|
||||
}
|
||||
public void Delete_container_grps() {// remove container grps else headers with no items will show up
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoedit_grp grp = (Xoedit_grp)hash.Get_at(i);
|
||||
if (grp.Itms().length == 0)
|
||||
deleted.Add(grp);
|
||||
}
|
||||
|
||||
len = deleted.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoedit_grp grp = (Xoedit_grp)deleted.Get_at(i);
|
||||
hash.Del(grp.Key());
|
||||
id_hash.Del(grp.Id());
|
||||
}
|
||||
}
|
||||
|
||||
public Xoedit_nde_hash Merge(Xoedit_nde_hash src) {
|
||||
int len = src.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
this.Add(src.Get_at(i));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Deleted__add(Xoedit_nde nde) {
|
||||
deleted.Add(nde);
|
||||
}
|
||||
public void Deleted__commit() {
|
||||
int len = deleted.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoedit_nde nde = (Xoedit_nde)deleted.Get_at(i);
|
||||
hash.Del(nde.Key());
|
||||
id_hash.Del(nde.Id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,41 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
public class Xoedit_root implements Mustache_doc_itm {
|
||||
private final Xoedit_nav_mgr nav_mgr;
|
||||
private final Xoedit_grp[] grps;
|
||||
private final String page_help;
|
||||
private final boolean app_is_drd;
|
||||
public Xoedit_root(Xoedit_nav_mgr nav_mgr, String page_help, Xoedit_grp[] grps) {
|
||||
this.nav_mgr = nav_mgr;
|
||||
this.page_help = page_help;
|
||||
this.grps = grps;
|
||||
this.app_is_drd = gplx.core.envs.Op_sys.Cur().Tid_is_drd();
|
||||
}
|
||||
public Gfobj_nde To_nde(Bry_bfr tmp_bfr) {
|
||||
Gfobj_nde rv = Gfobj_nde.New();
|
||||
List_adp list = List_adp_.New();
|
||||
int len = grps.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoedit_grp itm = grps[i];
|
||||
list.Add(itm.To_nde(tmp_bfr));
|
||||
}
|
||||
rv.Add_str("page_help", page_help);
|
||||
rv.Add_ary("grps", new Gfobj_ary((Gfobj_nde[])list.To_ary_and_clear(Gfobj_nde.class)));
|
||||
return rv;
|
||||
}
|
||||
public boolean Mustache__write(String k, Mustache_bfr bfr) {
|
||||
if (String_.Eq(k, "page_help")) bfr.Add_str_u8(page_help);
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String k) {
|
||||
if (String_.Eq(k, "grps")) return grps;
|
||||
else if (String_.Eq(k, "nav_exists")) return Mustache_doc_itm_.Ary__bool(nav_mgr.Itms().length > 1); // NOTE: do not show combo if 0 or 1 item
|
||||
else if (String_.Eq(k, "app_is_drd")) return Mustache_doc_itm_.Ary__bool(app_is_drd);
|
||||
else if (String_.Eq(k, "itms")) return nav_mgr.Itms();
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,44 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.objs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
public class Xogui_nde_iter {
|
||||
private final Xoedit_nde_hash hash;
|
||||
private int bgn, max;
|
||||
public Xogui_nde_iter(Xoedit_nde_hash hash, int max) {
|
||||
this.hash = hash;
|
||||
this.max = max;
|
||||
}
|
||||
public boolean Move_next() {
|
||||
return bgn < hash.Len();
|
||||
}
|
||||
public String To_sql_in() {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int end = bgn + max;
|
||||
if (end > hash.Len()) end = hash.Len();
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xoedit_nde nde = hash.Get_at(i);
|
||||
if (i != bgn) bfr.Add_byte_comma();
|
||||
bfr.Add_int_variable(nde.Id());
|
||||
}
|
||||
bgn = end;
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public String To_sql_in_key() {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int end = bgn + max;
|
||||
if (end > hash.Len()) end = hash.Len();
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xoedit_nde nde = (Xoedit_nde)hash.Get_at(i);
|
||||
if (i != bgn) bfr.Add_byte_comma();
|
||||
bfr.Add_byte_apos();
|
||||
bfr.Add_str_u8(nde.Key());
|
||||
bfr.Add_byte_apos();
|
||||
}
|
||||
bgn = end;
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
public static Xogui_nde_iter New_sql(Xoedit_nde_hash hash) {
|
||||
return new Xogui_nde_iter(hash, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,35 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.edits.services.*; import gplx.xowa.addons.apps.cfgs.specials.edits.objs.*;
|
||||
class Xocfg_edit_html extends Xow_special_wtr__base {
|
||||
private final Xocfg_edit_loader loader;
|
||||
private final String grp, ctx, lang;
|
||||
public Xocfg_edit_html(Xocfg_edit_loader loader, String grp, String ctx, String lang) {
|
||||
this.loader = loader;
|
||||
this.grp = grp;
|
||||
this.ctx = ctx;
|
||||
this.lang = lang;
|
||||
}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "app", "cfg", "edit");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xo.cfg_edit.page.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
return loader.Load_root(grp, ctx, lang);
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoelem (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__mustache (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xotmpl (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_htm_frag(addon_dir.GenSubFil_nest("bin", "xo.cfg_edit.grps.mustache.html"), "xocfg.grps"));
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xo.cfg_edit.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xo.cfg_edit.js")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,31 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.edits.services.*;
|
||||
public class Xocfg_edit_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
|
||||
String grp = url_args.Read_str_or("grp", "");
|
||||
String ctx = url_args.Read_str_or("ctx", "app");
|
||||
String lang = url_args.Read_str_or("lang", wiki.App().User().Wikii().Lang().Key_str());
|
||||
|
||||
Xocfg_edit_loader loader = Xocfg_edit_loader.New(wiki.App());
|
||||
if (String_.Eq(grp, "")) {
|
||||
grp = wiki.App().Cfg().Get_str_app(Cfg__previous_grp);
|
||||
if (!loader.Grp_key_exists(grp)) {
|
||||
grp = "xowa.app.security";
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cfg:grp_key not found; defaulting to xowa.app.security; key=~{0}", grp);
|
||||
}
|
||||
}
|
||||
new Xocfg_edit_html(loader, grp, ctx, lang).Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
|
||||
Xocfg_edit_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xocfg_edit_special(Xow_special_meta.New_xo("XowaCfg", "Options"));
|
||||
public static final String Cfg__previous_grp = "xowa.app.cfg.previous_grp";
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.htmls.bridges.*;
|
||||
public class Xocfg_edit_bridge implements Bridge_cmd_itm {
|
||||
private Xocfg_edit_svc svc;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.svc = new Xocfg_edit_svc(app);
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__update: svc.Update(args); break;
|
||||
case Proc__delete: svc.Delete(args); break;
|
||||
case Proc__select: svc.Select(args); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return Bridge_cmd_mgr.Msg__ok;
|
||||
}
|
||||
|
||||
private static final byte Proc__update = 0, Proc__delete = 1, Proc__select = 2;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("update" , Proc__update)
|
||||
.Add_str_byte("delete" , Proc__delete)
|
||||
.Add_str_byte("select" , Proc__select)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("xo.cfg_edit");
|
||||
public static final Xocfg_edit_bridge Prototype = new Xocfg_edit_bridge(); Xocfg_edit_bridge() {}
|
||||
}
|
||||
|
||||
@@ -13,244 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.dbs.tbls.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.edits.objs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.mgrs.*; import gplx.xowa.addons.apps.cfgs.mgrs.dflts.*; import gplx.xowa.addons.apps.cfgs.mgrs.types.*;
|
||||
public class Xocfg_edit_loader {
|
||||
private final Xocfg_db_app db_app;
|
||||
private final Xocfg_db_usr db_usr;
|
||||
private final Xocfg_type_mgr type_mgr;
|
||||
private final Xocfg_dflt_mgr dflt_mgr;
|
||||
public Xocfg_edit_loader(Xocfg_db_app db_app, Xocfg_db_usr db_usr, Xocfg_type_mgr type_mgr, Xocfg_dflt_mgr dflt_mgr) {
|
||||
this.db_app = db_app;
|
||||
this.db_usr = db_usr;
|
||||
this.type_mgr = type_mgr;
|
||||
this.dflt_mgr = dflt_mgr;
|
||||
}
|
||||
public boolean Grp_key_exists(String grp_key) {return db_app.Tbl__grp().Select_by_key_or_null(grp_key) != null;
|
||||
}
|
||||
public Xoedit_root Load_root(String grp_key, String ctx, String lang) {
|
||||
// create lists
|
||||
Ordered_hash grp_temp = Ordered_hash_.New();
|
||||
Xoedit_nde_hash grp_list = new Xoedit_nde_hash();
|
||||
Xoedit_nde_hash itm_list = new Xoedit_nde_hash();
|
||||
|
||||
// get root_itm
|
||||
Xocfg_grp_row grp_meta = db_app.Tbl__grp().Select_by_key_or_null(grp_key);
|
||||
if (grp_meta == null) throw Err_.new_wo_type("cfg:grp not found", "grp", grp_key);
|
||||
Xoedit_grp owner = new Xoedit_grp(grp_meta.Id(), grp_meta.Key(), 0);
|
||||
grp_temp.Add(grp_meta.Id(), owner);
|
||||
grp_list.Add(owner);
|
||||
|
||||
// load tree by selecting subs until no more grps
|
||||
while (grp_temp.Count() > 0) {
|
||||
owner = (Xoedit_grp)grp_temp.Get_at(0);
|
||||
grp_temp.Del(owner.Id());
|
||||
Load_subs(grp_list, itm_list, grp_temp, owner);
|
||||
}
|
||||
|
||||
// load itms and i18n
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
Load_itm_meta(tmp_bfr, itm_list);
|
||||
Load_itm_data(tmp_bfr, itm_list, ctx);
|
||||
Load_i18n(grp_list, itm_list, lang);
|
||||
|
||||
Xoedit_nde page_nde = grp_list.Get_by_or_fail(grp_key);
|
||||
|
||||
grp_list.Delete_container_grps();
|
||||
return new Xoedit_root(Load_nav_mgr(grp_key), page_nde.Help(), (Xoedit_grp[])grp_list.To_grp_ary_and_clear());
|
||||
}
|
||||
private Xoedit_nav_mgr Load_nav_mgr(String grp_key) {
|
||||
// get grp_id
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT grp_id"
|
||||
, "FROM cfg_grp"
|
||||
, "WHERE grp_key = '{0}'"
|
||||
), grp_key
|
||||
);
|
||||
int grp_id = -1;
|
||||
Db_rdr rdr = db_app.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
try {grp_id = rdr.Move_next() ? rdr.Read_int("grp_id") : -1;}
|
||||
finally {rdr.Rls();}
|
||||
|
||||
// get owner_id
|
||||
sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT map_src"
|
||||
, "FROM cfg_map"
|
||||
, "WHERE map_trg = {0}"
|
||||
), grp_id
|
||||
);
|
||||
int owner_id = -1;
|
||||
rdr = db_app.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int map_src = rdr.Read_int("map_src");
|
||||
// WORKAROUND:if drd, then ignore desktop root node; needed for links like "?grp=xowa.addon.fulltext_search" which has two owners:desktop and mobile; DATE:2017-03-28
|
||||
// ideally, (a) cfg_grp should have a plat_id column; (b) the above SQL should join to cfg_grp and (c) filter on plat_id = drd / desktop
|
||||
if (gplx.core.envs.Op_sys.Cur().Tid_is_drd()
|
||||
&& map_src == 10000) {
|
||||
continue;
|
||||
} else {
|
||||
owner_id = map_src;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
|
||||
// get peers
|
||||
sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT m.map_trg"
|
||||
, ", m.map_sort"
|
||||
, ", t.nde_name"
|
||||
, ", g.grp_key"
|
||||
, "FROM cfg_map m"
|
||||
, " LEFT JOIN cfg_grp g ON m.map_trg = g.grp_id"
|
||||
, " LEFT JOIN cfg_txt t ON m.map_trg = t.nde_id"
|
||||
, "WHERE m.map_src = {0}"
|
||||
, "ORDER BY m.map_sort"
|
||||
), owner_id
|
||||
);
|
||||
List_adp list = List_adp_.New();
|
||||
try {
|
||||
rdr = db_app.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
String nav_key = rdr.Read_str("grp_key");
|
||||
String nav_text = rdr.Read_str("nde_name");
|
||||
list.Add(new Xoedit_nav_itm(String_.Eq(grp_key, nav_key), nav_key, nav_text));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
}
|
||||
return new Xoedit_nav_mgr((Xoedit_nav_itm[])list.To_ary_and_clear(Xoedit_nav_itm.class));
|
||||
}
|
||||
private void Load_subs(Xoedit_nde_hash grp_list, Xoedit_nde_hash itm_list, Ordered_hash grp_temp, Xoedit_grp owner) {
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT m.map_trg"
|
||||
, ", m.map_sort"
|
||||
, ", Coalesce(g.grp_key, i.itm_key) AS key"
|
||||
, ", i.itm_dflt"
|
||||
, "FROM cfg_map m"
|
||||
, " LEFT JOIN cfg_grp g ON m.map_trg = g.grp_id"
|
||||
, " LEFT JOIN cfg_itm i ON m.map_trg = i.itm_id"
|
||||
, "WHERE m.map_src = {0}"
|
||||
), owner.Id()
|
||||
);
|
||||
Db_rdr rdr = db_app.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
List_adp itms_list = List_adp_.New();
|
||||
while (rdr.Move_next()) {
|
||||
String grp_key = rdr.Read_str("key");
|
||||
// nde is grp
|
||||
if (rdr.Read_str("itm_dflt") == null) {
|
||||
Xoedit_grp gui_grp = new Xoedit_grp(rdr.Read_int("map_trg"), grp_key, rdr.Read_int("map_sort"));
|
||||
grp_list.Add(gui_grp);
|
||||
grp_temp.Add(gui_grp.Id(), gui_grp);
|
||||
}
|
||||
// nde is itm
|
||||
else {
|
||||
Xoedit_itm gui_itm = new Xoedit_itm(type_mgr, rdr.Read_int("map_trg"), grp_key, rdr.Read_int("map_sort"));
|
||||
itms_list.Add(gui_itm);
|
||||
itm_list.Add(gui_itm);
|
||||
}
|
||||
}
|
||||
owner.Itms_((Xoedit_itm[])itms_list.To_ary_and_clear(Xoedit_itm.class));
|
||||
}
|
||||
private void Load_itm_meta(Bry_bfr tmp_bfr, Xoedit_nde_hash itm_list) {
|
||||
Xogui_nde_iter iter = Xogui_nde_iter.New_sql(itm_list);
|
||||
while (iter.Move_next()) {
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT *"
|
||||
, "FROM cfg_itm i"
|
||||
, "WHERE i.itm_key IN ({0})"
|
||||
), iter.To_sql_in_key()
|
||||
);
|
||||
|
||||
Db_rdr rdr = db_app.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
String key = rdr.Read_str("itm_key");
|
||||
Xoedit_itm edit_itm = (Xoedit_itm)itm_list.Get_by_or_fail(key);
|
||||
String dflt = dflt_mgr.Get_or(key, rdr.Read_str("itm_dflt"));
|
||||
edit_itm.Load_by_meta(tmp_bfr, rdr.Read_str("itm_type"), dflt, rdr.Read_str("itm_html_atrs"), rdr.Read_str("itm_html_cls"));
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Load_itm_data(Bry_bfr tmp_bfr, Xoedit_nde_hash itm_list, String... ctxs) {
|
||||
Xoedit_nde_hash cur_regy = new Xoedit_nde_hash().Merge(itm_list);
|
||||
|
||||
// loop ctxs where later ctxs are more general defaults; EX: ["en.w", "en.*", "*.w", "app"]
|
||||
int ctxs_len = ctxs.length;
|
||||
for (int i = 0; i < ctxs_len; i++) {
|
||||
// create iter for cur_regy; note that iter will be reduced as items are found below
|
||||
Xogui_nde_iter cur_iter = Xogui_nde_iter.New_sql(cur_regy);
|
||||
while (cur_iter.Move_next()) {
|
||||
// get all data by ids and ctx
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT v.itm_key"
|
||||
, ", v.itm_ctx"
|
||||
, ", v.itm_val"
|
||||
, ", v.itm_date"
|
||||
, "FROM cfg_val v"
|
||||
, "WHERE v.itm_key IN ({0})"
|
||||
, "AND v.itm_ctx = '{1}'"
|
||||
), cur_iter.To_sql_in_key(), ctxs[i]
|
||||
);
|
||||
|
||||
// read and set data
|
||||
Db_rdr rdr = db_usr.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoedit_itm gui_itm = (Xoedit_itm)cur_regy.Get_by_or_fail(rdr.Read_str("itm_key"));
|
||||
gui_itm.Load_by_data(tmp_bfr, rdr.Read_str("itm_ctx"), rdr.Read_str("itm_val"), rdr.Read_str("itm_date"));
|
||||
cur_regy.Deleted__add(gui_itm);
|
||||
}
|
||||
}
|
||||
cur_regy.Deleted__commit();
|
||||
}
|
||||
|
||||
// loop over remaining items and set to dflts
|
||||
int cur_len = cur_regy.Len();
|
||||
for (int i = 0; i < cur_len; i++) {
|
||||
Xoedit_itm itm = (Xoedit_itm)cur_regy.Get_at(i);
|
||||
itm.Set_data_by_dflt();
|
||||
}
|
||||
}
|
||||
private void Load_i18n(Xoedit_nde_hash grp_list, Xoedit_nde_hash itm_list, String... langs) {
|
||||
Xoedit_nde_hash cur_regy = new Xoedit_nde_hash().Merge(grp_list).Merge(itm_list);
|
||||
|
||||
// loop langs where later langs are fallbacks; EX: ["de", "en"]
|
||||
int langs_len = langs.length;
|
||||
for (int i = 0; i < langs_len; i++) {
|
||||
// create iter for cur_regy; note that iter will be reduced as items are found below
|
||||
Xogui_nde_iter cur_iter = Xogui_nde_iter.New_sql(cur_regy);
|
||||
while (cur_iter.Move_next()) {
|
||||
// get all i18n for itms and lang
|
||||
String sql = Db_sql_.Make_by_fmt(String_.Ary
|
||||
( "SELECT t.nde_id"
|
||||
, ", t.nde_name"
|
||||
, ", t.nde_help"
|
||||
, ", t.nde_lang"
|
||||
, "FROM cfg_txt t"
|
||||
, "WHERE t.nde_id IN ({0})"
|
||||
, "AND t.nde_lang = '{1}'"
|
||||
), cur_iter.To_sql_in()
|
||||
, langs[i]
|
||||
);
|
||||
|
||||
// read and set i18n
|
||||
Db_rdr rdr = db_app.Conn().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoedit_nde gui_itm = (Xoedit_nde)cur_regy.Get_by_or_fail(rdr.Read_int("nde_id"));
|
||||
gui_itm.Load_by_i18n(rdr.Read_str("nde_lang"), rdr.Read_str("nde_name"), rdr.Read_str("nde_help"));
|
||||
cur_regy.Deleted__add(gui_itm);
|
||||
}
|
||||
}
|
||||
cur_regy.Deleted__commit();
|
||||
}
|
||||
}
|
||||
public static Xocfg_edit_loader New(Xoa_app app) {
|
||||
Xocfg_db_app db_app = Xocfg_db_app.New(app);
|
||||
return new Xocfg_edit_loader(db_app, new Xocfg_db_usr(db_app, app.User().User_db_mgr().Conn()), app.Cfg().Type_mgr(), app.Cfg().Dflt_mgr());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,61 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.edits.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.edits.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.core.gfobjs.*;
|
||||
import gplx.xowa.guis.cbks.*; import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.specials.edits.objs.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.edits.pages.*; import gplx.xowa.addons.apps.cfgs.mgrs.caches.*; import gplx.xowa.addons.apps.cfgs.enums.*;
|
||||
public class Xocfg_edit_svc {
|
||||
private final Xoa_app app;
|
||||
private Xocfg_edit_loader edit_loader;
|
||||
private final Xog_cbk_trg cbk_trg = Xog_cbk_trg.New(Xocfg_edit_special.Prototype.Special__meta().Ttl_bry());
|
||||
public Xocfg_edit_svc(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Update(Json_nde args) {
|
||||
String ctx = args.Get_as_str("ctx");
|
||||
String key = args.Get_as_str("key");
|
||||
String val = args.Get_as_str("val");
|
||||
String type = args.Get_as_str("type");
|
||||
if (String_.Has_at_bgn(type, "gui.binding")) {
|
||||
val = Xoitm_gui_binding.To_db_str(val);
|
||||
}
|
||||
|
||||
Xocfg_cache_grp grp = app.Cfg().Cache_mgr().Grps__get_or_load(key);
|
||||
try {
|
||||
app.Cfg().Set_str(ctx, key, val);
|
||||
} catch (Exception exc) {
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.cfg_edit.update__fail", Gfobj_nde.New().Add_str("key", key).Add_str("new_val", args.Get_as_str("val")).Add_str("old_val", grp.Get(ctx)).Add_str("err", Err_.Message_lang(exc)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!String_.Eq(type, "btn") && String_.Eq(grp.Dflt(), val)) {
|
||||
if (String_.Has_at_bgn(type, "gui.binding")) {
|
||||
val = String_.Concat_with_str("|", gplx.xowa.addons.apps.cfgs.enums.Xoitm_gui_binding.To_gui(val));
|
||||
}
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.cfg_edit.delete__recv", Gfobj_nde.New().Add_str("key", key).Add_str("type", type).Add_str("val", val));
|
||||
}
|
||||
else
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.cfg_edit.update__pass", Gfobj_nde.New().Add_str("key", key).Add_str("type", type));
|
||||
}
|
||||
public void Delete(Json_nde args) {
|
||||
String ctx = args.Get_as_str("ctx");
|
||||
String key = args.Get_as_str("key");
|
||||
String type = args.Get_as_str("type");
|
||||
app.Cfg().Del(ctx, key);
|
||||
String val = app.Cfg().Get_str(ctx, key);
|
||||
if (String_.Has_at_bgn(type, "gui.binding")) {
|
||||
val = String_.Concat_with_str("|", gplx.xowa.addons.apps.cfgs.enums.Xoitm_gui_binding.To_gui(val));
|
||||
}
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.cfg_edit.delete__recv", Gfobj_nde.New().Add_str("key", key).Add_str("val", val));
|
||||
}
|
||||
public void Select(Json_nde args) {
|
||||
String ctx = args.Get_as_str("ctx");
|
||||
String key = args.Get_as_str("key");
|
||||
if (edit_loader == null) edit_loader = Xocfg_edit_loader.New(app);
|
||||
Xoedit_root root = edit_loader.Load_root(key, ctx, "en");
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.cfg_edit.select__recv", root.To_nde(Bry_bfr_.New()));
|
||||
app.Cfg().Set_str_app(Xocfg_edit_special.Cfg__previous_grp, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,24 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.apps.cfgs.specials.edits.objs.*;
|
||||
class Xocfg_maint_html extends Xow_special_wtr__base {
|
||||
public Xocfg_maint_html() {}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "app", "cfg", "maint");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xo.cfg_maint.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
return new Xoedit_grp(0, "test", 1);
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xo.cfg_maint.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xo.cfg_maint.js")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Xocfg_maint_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
new Xocfg_maint_html().Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
|
||||
Xocfg_maint_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xocfg_maint_special(Xow_special_meta.New_xo("XowaCfgMaint", "Option Maintenance"));
|
||||
}
|
||||
|
||||
@@ -13,29 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xocfg_maint_bridge implements Bridge_cmd_itm {
|
||||
private Xocfg_maint_svc svc;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.svc = new Xocfg_maint_svc(app);
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__upsert: svc.Upsert(args.Get_as_str("data")); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static final byte Proc__upsert = 0;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("upsert" , Proc__upsert)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("xo.cfg_maint");
|
||||
public static final Xocfg_maint_bridge Prototype = new Xocfg_maint_bridge(); Xocfg_maint_bridge() {}
|
||||
}
|
||||
|
||||
@@ -13,46 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
abstract class Xocfg_maint_nde implements gplx.core.brys.Bry_bfr_able {
|
||||
public Xocfg_maint_nde(String owner, int id, String key, String name, String help) {
|
||||
this.owner = owner;
|
||||
this.id = id;
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
}
|
||||
public abstract boolean Type_is_grp();
|
||||
public String Owner() {return owner;} private final String owner;
|
||||
public int Id() {return id;} private final int id;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Name() {return name;} private final String name;
|
||||
public String Help() {return help;} private final String help;
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
bfr.Add_str_u8_fmt("{0}|{1}|{2}|{3}|{4}", owner, this.Type_is_grp(), key, name, help);
|
||||
To_bfr_hook(bfr);
|
||||
}
|
||||
protected abstract void To_bfr_hook(Bry_bfr bfr);
|
||||
}
|
||||
class Xocfg_maint_grp extends Xocfg_maint_nde { public Xocfg_maint_grp(String owner, int id, String key, String name, String help) {super(owner, id, key, name, help);
|
||||
}
|
||||
@Override public boolean Type_is_grp() {return true;}
|
||||
@Override protected void To_bfr_hook(Bry_bfr bfr) {}
|
||||
}
|
||||
class Xocfg_maint_itm extends Xocfg_maint_nde { public Xocfg_maint_itm(String owner, int id, String key, String name, String help, String scope, String type, String dflt, String html_atrs, String html_cls) {super(owner, id, key, name, help);
|
||||
this.scope = scope;
|
||||
this.type = type;
|
||||
this.dflt = dflt;
|
||||
this.html_atrs = html_atrs;
|
||||
this.html_cls = html_cls;
|
||||
}
|
||||
@Override public boolean Type_is_grp() {return false;}
|
||||
public String Scope() {return scope;} private final String scope;
|
||||
public String Type() {return type;} private final String type;
|
||||
public String Dflt() {return dflt;} private final String dflt;
|
||||
public String Html_atrs() {return html_atrs;} private final String html_atrs;
|
||||
public String Html_cls() {return html_cls;} private final String html_cls;
|
||||
@Override protected void To_bfr_hook(Bry_bfr bfr) {
|
||||
bfr.Add_str_u8_fmt("|{0}|{1}|{2}|{3}|{4}", scope, type, dflt, html_atrs, html_cls);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,60 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import gplx.langs.gfs.*;
|
||||
class Xocfg_maint_parser {
|
||||
public Xocfg_maint_nde[] Parse(String raw) {
|
||||
GfoMsg root = Gfs_msg_bldr.Instance.ParseToMsg(raw);
|
||||
|
||||
int len = root.Subs_count();
|
||||
Xocfg_maint_nde[] rv = new Xocfg_maint_nde[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
GfoMsg msg = root.Subs_getAt(i);
|
||||
rv[i] = Parse_nde(msg);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private Xocfg_maint_nde Parse_nde(GfoMsg msg) {
|
||||
Ordered_hash hash = To_atr_hash(msg);
|
||||
// get common atrs
|
||||
int id = Int_.Parse(Get_atr_as_str_or_fail(hash, "id_"));
|
||||
String owner = Get_atr_as_str_or_fail(hash, "owner_");
|
||||
String key = Get_atr_as_str_or_fail(hash, "key_");
|
||||
String name = Get_atr_as_str_or_fail(hash, "name_");
|
||||
String help = Get_atr_as_str_or_fail(hash, "help_");
|
||||
|
||||
// create
|
||||
String nde_type = msg.Key();
|
||||
if (String_.Eq(nde_type, "grp")) {
|
||||
return new Xocfg_maint_grp(owner, id, key, name, help);
|
||||
}
|
||||
else if (String_.Eq(nde_type, "itm")) {
|
||||
String scope = Get_atr_as_str_or(hash, "scope_", ""); if (String_.Eq(scope, "")) scope = "wiki";
|
||||
String type = Get_atr_as_str_or_fail(hash, "type_");
|
||||
String dflt = Get_atr_as_str_or_fail(hash, "dflt_");
|
||||
String html_atrs = Get_atr_as_str_or(hash, "html_atrs_", "");
|
||||
String html_cls = Get_atr_as_str_or(hash, "html_cls_", "");
|
||||
return new Xocfg_maint_itm(owner, id, key, name, help, scope, type, dflt, html_atrs, html_cls);
|
||||
}
|
||||
else throw Err_.new_wo_type("xo.cfg_maint:unknown type", "type", nde_type);
|
||||
}
|
||||
private static Ordered_hash To_atr_hash(GfoMsg msg) {
|
||||
Ordered_hash rv = Ordered_hash_.New();
|
||||
int len = msg.Subs_count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
GfoMsg sub = msg.Subs_getAt(i);
|
||||
rv.Add(sub.Key(), sub.Args_getAt(0).Val());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static String Get_atr_as_str_or_fail(Ordered_hash hash, String key) {
|
||||
String rv = Get_atr_as_str_or(hash, key, null);
|
||||
if (rv == null) throw Err_.new_wo_type("xo.cfg_maint:missing key", "key", key);
|
||||
return rv;
|
||||
}
|
||||
private static String Get_atr_as_str_or(Ordered_hash hash, String key, String or) {
|
||||
String val = (String)hash.Get_by(key);
|
||||
return val == null ? or : val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,31 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xocfg_maint_parser__tst {
|
||||
private final Xocfg_maint_parser__fxt fxt = new Xocfg_maint_parser__fxt();
|
||||
@Test public void Parse_grp() {
|
||||
fxt.Exec__parse("grp {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'}"
|
||||
, fxt.Make__grp("owner_1", 123, "key_1", "name_1", "help_1")
|
||||
);
|
||||
}
|
||||
@Test public void Parse_itm() {
|
||||
fxt.Exec__parse("itm {id='123'; key='key_1'; owner='owner_1'; name='name_1'; help='help_1'; scope='scope_1'; type='type_1'; dflt='dflt_1'; html_atrs='html_atrs_1'; html_cls='html_cls_1'}"
|
||||
, fxt.Make__itm("owner_1", 123, "key_1", "name_1", "help_1", "scope_1", "type_1", "dflt_1", "html_atrs_1", "html_cls_1")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xocfg_maint_parser__fxt {
|
||||
private Xocfg_maint_parser parser = new Xocfg_maint_parser();
|
||||
public void Exec__parse(String raw, Xocfg_maint_nde... expd) {
|
||||
Xocfg_maint_nde[] actl = parser.Parse(raw);
|
||||
Gftest.Eq__ary(expd, actl);
|
||||
}
|
||||
public Xocfg_maint_grp Make__grp(String owner, int id, String key, String name, String help) {
|
||||
return new Xocfg_maint_grp(owner, id, key, name, help);
|
||||
}
|
||||
public Xocfg_maint_itm Make__itm(String owner, int id, String key, String name, String help, String scope, String type, String dflt, String html_atrs, String html_cls) {
|
||||
return new Xocfg_maint_itm(owner, id, key, name, help, scope, type, dflt, html_atrs, html_cls);
|
||||
}
|
||||
}
|
||||
@@ -13,67 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.specials.maints.services; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*; import gplx.xowa.addons.apps.cfgs.specials.*; import gplx.xowa.addons.apps.cfgs.specials.maints.*;
|
||||
import gplx.xowa.addons.apps.cfgs.dbs.*; import gplx.xowa.addons.apps.cfgs.dbs.tbls.*;
|
||||
import gplx.xowa.addons.apps.cfgs.enums.*;
|
||||
public class Xocfg_maint_svc {
|
||||
private Xoa_app app;
|
||||
public Xocfg_maint_svc(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Upsert(String raw) {
|
||||
// get wikitext parser
|
||||
Xowe_wiki wiki = (Xowe_wiki)app.User().Wikii();
|
||||
gplx.xowa.parsers.Xow_parser_mgr parser_mgr = wiki.Parser_mgr();
|
||||
|
||||
// parse raw
|
||||
Xocfg_maint_parser maint_parser = new Xocfg_maint_parser();
|
||||
Xocfg_maint_nde[] ndes = maint_parser.Parse(raw);
|
||||
|
||||
// exec
|
||||
Xocfg_db_app db_app = Xocfg_db_app.New(app);
|
||||
db_app.Conn().Txn_bgn("xo__cfg_maint__upsert");
|
||||
byte[] anch_find_bry = Bry_.new_a7("<a "), anch_repl_bry = Bry_.new_a7("<a tabindex=\"-1\" ");
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
for (Xocfg_maint_nde nde : ndes) {
|
||||
// parse help to html
|
||||
parser_mgr.Main().Parse_text_to_html(tmp_bfr, parser_mgr.Ctx(), parser_mgr.Ctx().Page(), true, Bry_.new_u8(nde.Help()));
|
||||
byte[] help = tmp_bfr.To_bry_and_clear();
|
||||
help = Bry_.Replace(help, anch_find_bry, anch_repl_bry); // replace "<a " with "<a tabindex=-1 " else tabbing will go to hidden anchors in help text
|
||||
|
||||
// do insert
|
||||
if (nde.Type_is_grp()) {
|
||||
Xocfg_maint_svc.Create_grp(db_app, nde.Owner(), nde.Id(), nde.Key(), nde.Name(), String_.new_u8(help));
|
||||
}
|
||||
else {
|
||||
Xocfg_maint_itm itm = (Xocfg_maint_itm)nde;
|
||||
Xocfg_maint_svc.Create_itm(db_app, nde.Owner(), nde.Id(), nde.Key(), nde.Name(), String_.new_u8(help), itm.Scope(), itm.Type(), itm.Dflt(), itm.Html_atrs(), itm.Html_cls());
|
||||
}
|
||||
}
|
||||
db_app.Conn().Txn_end();
|
||||
}
|
||||
public static void Create_grp(Xocfg_db_app db_app, String owner, int id, String key, String name, String help) {
|
||||
// insert grp_meta
|
||||
db_app.Tbl__grp().Upsert(id, key);
|
||||
|
||||
// insert grp_map
|
||||
int owner_id = String_.Len_eq_0(owner) ? Xocfg_grp_row.Id__root : db_app.Tbl__grp().Select_id_by_key_or_fail(owner);
|
||||
int map_sort = db_app.Tbl__map().Select_sort_or_next(owner_id, id);
|
||||
db_app.Tbl__map().Upsert(owner_id, id, map_sort);
|
||||
|
||||
// insert nde_i18n
|
||||
db_app.Tbl__txt().Upsert(id, Xoitm_lang_tid.Lang__dflt, name, help);
|
||||
}
|
||||
public static void Create_itm(Xocfg_db_app db_app, String owner, int id, String key, String name, String help, String scope, String type, String dflt, String html_atrs, String html_cls) {
|
||||
// insert itm_meta
|
||||
db_app.Tbl__itm().Upsert(id, key, Xoitm_scope_enum.To_int(scope), type, dflt, html_atrs, html_cls);
|
||||
|
||||
// insert grp_map
|
||||
int grp_id = db_app.Tbl__grp().Select_id_by_key_or_fail(owner);
|
||||
int itm_sort = db_app.Tbl__map().Select_sort_or_next(grp_id, id);
|
||||
db_app.Tbl__map().Upsert(grp_id, id, itm_sort);
|
||||
|
||||
// insert nde_i18n
|
||||
db_app.Tbl__txt().Upsert(id, Xoitm_lang_tid.Lang__dflt, name, help);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,115 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.langs.gfs.*;
|
||||
public class Xocfg_upgrade_mgr {
|
||||
public static void Upgrade_cfg_0(Xoae_app app) {
|
||||
try {
|
||||
// get cfg_fil; if empty, exit
|
||||
Io_url cfg_fil = app.Fsys_mgr().Root_dir().GenSubFil_nest("user", "anonymous", "app", "data", "cfg", "xowa_user_cfg.gfs");
|
||||
byte[] cfg_raw = Io_mgr.Instance.LoadFilBryOrNull(cfg_fil);
|
||||
if (cfg_raw == null) return;
|
||||
|
||||
// log and rename file
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:old cfg found; converting");
|
||||
Io_mgr.Instance.MoveFil_args(cfg_fil, cfg_fil.GenNewExt(".bak"), true).Exec();
|
||||
|
||||
// parse, remap, and update
|
||||
Keyval[] kvs = Parse(cfg_raw);
|
||||
|
||||
// get mappings
|
||||
Ordered_hash mappings = Ordered_hash_.New();
|
||||
Db_conn conn = app.Cfg().Cache_mgr().Db_app().Conn();
|
||||
Db_rdr rdr = conn.Stmt_sql("SELECT * FROM cfg_upgrade").Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
String cfg_old = rdr.Read_str("cfg_old");
|
||||
String cfg_new = rdr.Read_str("cfg_new");
|
||||
mappings.Add(cfg_old, Keyval_.new_(cfg_old, cfg_new));
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
|
||||
// remap
|
||||
for (Keyval kv : kvs) {
|
||||
Keyval mapping = (Keyval)mappings.Get_by(kv.Key());
|
||||
if (mapping == null) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:could not find mapping; key=~{0} val=~{1}", kv.Key(), kv.Val());
|
||||
kv.Key_("");
|
||||
continue;
|
||||
}
|
||||
kv.Key_(mapping.Val());
|
||||
}
|
||||
|
||||
// apply
|
||||
app.Cfg().Cache_mgr().Db_usr().Conn().Txn_bgn("convert");
|
||||
for (Keyval kv : kvs) {
|
||||
if (String_.Eq(kv.Key(), "")) continue;
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:converting; key=~{0} val=~{1}", kv.Key(), kv.Val());
|
||||
app.Cfg().Set_str_app(kv.Key(), kv.Val_to_str_or_empty());
|
||||
}
|
||||
app.Cfg().Cache_mgr().Db_usr().Conn().Txn_end();
|
||||
} catch (Exception exc) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to convert old cfg; err=~{0}", Err_.Message_gplx_log(exc));
|
||||
}
|
||||
}
|
||||
public static Keyval[] Parse(byte[] src) {
|
||||
// main parse
|
||||
Gfs_parser parser = new Gfs_parser();
|
||||
Ordered_hash hash = Ordered_hash_.New();
|
||||
Gfs_nde root = parser.Parse(src);
|
||||
int root_len = root.Subs_len();
|
||||
for (int i = 0; i < root_len; i++) {
|
||||
Gfs_nde app_nde = root.Subs_get_at(i);
|
||||
Gfs_nde cfgs_nde = app_nde.Subs_get_at(0);
|
||||
Gfs_nde get_nde = cfgs_nde.Subs_get_at(0);
|
||||
Gfs_nde key_atr = get_nde.Atrs_get_at(0);
|
||||
Gfs_nde val_nde = get_nde.Subs_get_at(0);
|
||||
Gfs_nde val_atr = val_nde.Atrs_get_at(0);
|
||||
String key = String_.new_u8(key_atr.Name_bry(src));
|
||||
hash.Add(key, Keyval_.new_(key, String_.new_u8(val_atr.Name_bry(src))));
|
||||
}
|
||||
|
||||
// consolidate io.cmd
|
||||
List_adp deleted = List_adp_.New();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval args_kv = (Keyval)hash.Get_at(i);
|
||||
String args_kv_key = args_kv.Key();
|
||||
String args_kv_val = args_kv.Val_to_str_or_empty();
|
||||
if (String_.Has_at_end(args_kv_key, ".args")) {
|
||||
Keyval cmd_kv = (Keyval)hash.Get_by(String_.Replace(args_kv_key, ".args", ".cmd"));
|
||||
if (cmd_kv == null) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "cfg.convert:could not find cmd; key=~{0} val=~{1}", args_kv_key, args_kv.Val());
|
||||
continue;
|
||||
}
|
||||
String cmd_kv_val = cmd_kv.Val_to_str_or_empty();
|
||||
if (!String_.Has_at_end(cmd_kv_val, "|")) cmd_kv_val += "|";
|
||||
cmd_kv.Val_(cmd_kv_val + args_kv_val);
|
||||
deleted.Add(args_kv_key);
|
||||
}
|
||||
else if (String_.Has_at_bgn(args_kv_key, "app.cfg.get.gui.bnds.init('")) {
|
||||
args_kv_key = String_.Replace(args_kv_key, "app.cfg.get.gui.bnds.init('", "");
|
||||
args_kv_key = String_.Replace(args_kv_key, "').src", "");
|
||||
args_kv_key = "xowa.gui.shortcuts." + args_kv_key;
|
||||
args_kv.Key_(args_kv_key);
|
||||
|
||||
args_kv_val = String_.Replace(args_kv_val, "box='", "");
|
||||
args_kv_val = String_.Replace(args_kv_val, "';ipt='", "|");
|
||||
args_kv_val = String_.Replace(args_kv_val, "';", "");
|
||||
args_kv.Val_(args_kv_val);
|
||||
}
|
||||
}
|
||||
|
||||
// delete args
|
||||
len = deleted.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
String deleted_key = (String)deleted.Get_at(i);
|
||||
hash.Del(deleted_key);
|
||||
}
|
||||
|
||||
return (Keyval[])hash.To_ary_and_clear(Keyval.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,44 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.cfgs.upgrades; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xocfg_upgrade_mgr__tst {
|
||||
private final Xocfg_upgrade_mgr__fxt fxt = new Xocfg_upgrade_mgr__fxt();
|
||||
@Test public void Parse__one() {
|
||||
fxt.Test__parse("app.cfgs.get('k_1', 'app').val = 'v_1';\n", Keyval_.new_("k_1", "v_1"));
|
||||
}
|
||||
@Test public void Parse__apos() {
|
||||
fxt.Test__parse("app.cfgs.get('k_1(''k_1a'')', 'app').val = 'v_1';\n", Keyval_.new_("k_1('k_1a')", "v_1"));
|
||||
}
|
||||
@Test public void Parse__many() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('k_1', 'app').val = 'v_1';\n"
|
||||
+ "app.cfgs.get('k_2', 'app').val = 'v_2';\n"
|
||||
, Keyval_.new_("k_1", "v_1"), Keyval_.new_("k_2", "v_2"));
|
||||
}
|
||||
@Test public void Parse__multi_line() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('k_1', 'app').val = '''v_1'';\n"
|
||||
+ "v_2\n"
|
||||
+ "v_3';\n"
|
||||
, Keyval_.new_("k_1", "'v_1';\nv_2\nv_3"));
|
||||
}
|
||||
@Test public void Parse__io_cmd() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('a.cmd', 'app').val = 'cmd_1';\n"
|
||||
+ "app.cfgs.get('a.args', 'app').val = 'args_1';\n"
|
||||
, Keyval_.new_("a.cmd", "cmd_1|args_1"));
|
||||
}
|
||||
@Test public void Parse__gui_binding() {
|
||||
fxt.Test__parse
|
||||
( "app.cfgs.get('app.cfg.get.gui.bnds.init(''xowa.app.exit-1'').src', 'app').val = 'box=''browser'';ipt=''key.none'';';\n"
|
||||
, Keyval_.new_("xowa.gui.shortcuts.xowa.app.exit-1", "browser|key.none"));
|
||||
}
|
||||
}
|
||||
class Xocfg_upgrade_mgr__fxt {
|
||||
public void Test__parse(String raw, Keyval... expd) {
|
||||
Keyval[] actl = Xocfg_upgrade_mgr.Parse(Bry_.new_u8(raw));
|
||||
Gftest.Eq__str(Keyval_.Ary_to_str(expd), Keyval_.Ary_to_str(actl));
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.helps.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.helps.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
|
||||
public class Xolog_addon implements Xoax_addon_itm, Xoax_addon_itm__special {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ Xolog_special.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return "xowa.apps.helps.logs";}
|
||||
}
|
||||
|
||||
@@ -13,73 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.helps.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.helps.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
class Xolog_doc implements Mustache_doc_itm {
|
||||
public Xolog_doc(String log_file, String log_name, byte[] log_data, Xolog_doc_file[] log_files) {
|
||||
this.log_file = log_file; this.log_name = log_name;
|
||||
this.log_data = log_data; this.log_files = log_files;
|
||||
}
|
||||
public String Log_file() {return log_file;} private final String log_file; // EX: 20160613_165025
|
||||
public String Log_name() {return log_name;} private final String log_name; // EX: 2016-06-13 16:50:25
|
||||
public byte[] Log_data() {return log_data;} private final byte[] log_data;
|
||||
public Xolog_doc_file[] Log_files() {return log_files;} private final Xolog_doc_file[] log_files;
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "log_name")) bfr.Add_str_u8(log_name);
|
||||
else if (String_.Eq(key, "log_file")) bfr.Add_str_u8(log_file);
|
||||
else if (String_.Eq(key, "log_data")) bfr.Add_bry(log_data);
|
||||
return false;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
if (String_.Eq(key, "log_files")) return log_files;
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
}
|
||||
class Xolog_doc_ {
|
||||
public static Xolog_doc New(Io_url log_dir, String log_file) {
|
||||
// read fsys
|
||||
Io_url[] fils = Io_mgr.Instance.QueryDir_fils(log_dir);
|
||||
int len = fils.length;
|
||||
|
||||
// get log_files
|
||||
Ordered_hash hash = Ordered_hash_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Io_url fil = fils[i];
|
||||
String file = fil.NameOnly();
|
||||
String name = Xolog_file_utl.To_name(file);
|
||||
hash.Add(file, new Xolog_doc_file(file, name));
|
||||
}
|
||||
|
||||
// determine cur_file
|
||||
String cur_file = log_file;
|
||||
if ( cur_file == null // cur_file is null; happens for plain "Special:XowaLog"
|
||||
|| !hash.Has(cur_file) // cur_file deleted (accessed from history)
|
||||
) {
|
||||
cur_file = hash.Len() == 0
|
||||
? null
|
||||
: ((Xolog_doc_file)hash.Get_at(len - 1)).File();
|
||||
}
|
||||
if (cur_file != null)
|
||||
hash.Del(cur_file); // don't bother showing current item in list
|
||||
Xolog_doc_file[] log_files = (Xolog_doc_file[])hash.To_ary_and_clear(Xolog_doc_file.class);
|
||||
|
||||
// get body
|
||||
byte[] cur_body = Io_mgr.Instance.LoadFilBry(Xolog_file_utl.To_url_by_file(log_dir, cur_file));
|
||||
String cur_name = cur_file == null ? null : Xolog_file_utl.To_name(cur_file);
|
||||
return new Xolog_doc(cur_file, cur_name, cur_body, log_files);
|
||||
}
|
||||
}
|
||||
class Xolog_doc_file implements Mustache_doc_itm {
|
||||
public Xolog_doc_file(String file, String name) {
|
||||
this.file = file; this.name = name;
|
||||
}
|
||||
public String File() {return file;} private final String file;
|
||||
public String Name() {return name;} private final String name;
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "file")) bfr.Add_str_u8(file);
|
||||
else if (String_.Eq(key, "name")) bfr.Add_str_u8(name);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {return Mustache_doc_itm_.Ary__empty;}
|
||||
}
|
||||
|
||||
@@ -13,24 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.helps.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.helps.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
class Xolog_html extends Xow_special_wtr__base {
|
||||
private final Xolog_doc log_doc;
|
||||
public Xolog_html(Xolog_doc log_doc) {
|
||||
this.log_doc = log_doc;
|
||||
}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "app", "help", "log");}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xolog.mustache.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
return log_doc;
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
|
||||
page_data.Head_tags().Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xolog.css")));
|
||||
page_data.Head_tags().Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xolog.js")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,73 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.helps.logs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.helps.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.core.net.emails.*;
|
||||
public class Xolog_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
// init
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
Xoa_app app = wiki.App();
|
||||
Gfo_log_.Instance.Flush(); // flush log to write all memory itms to disk
|
||||
|
||||
// get file
|
||||
String file = url_args.Read_str_or_null("file");
|
||||
Io_url log_dir = app.Fsys_mgr().Root_dir().GenSubDir_nest("user", "anonymous", "app", "tmp", "xolog");
|
||||
Xolog_doc log_doc = Xolog_doc_.New(log_dir, file);
|
||||
if (log_doc.Log_file() == null) return; // occurs when all logs are deleted
|
||||
|
||||
// get cmd
|
||||
int cmd_tid = url_args.Read_enm_as_int_or(Enm_cmd.Itm, Enm_cmd.Tid__view);
|
||||
boolean redirect = true, redirect_to_same_file = false;;
|
||||
switch (cmd_tid) {
|
||||
case Enm_cmd.Tid__view: redirect = false; break;
|
||||
case Enm_cmd.Tid__email: redirect_to_same_file = true; Gfo_email_mgr_.Instance.Send("gnosygnu+xowa_xologs@gmail.com", "XOWA Log", String_.new_u8(log_doc.Log_data())); break;
|
||||
case Enm_cmd.Tid__delete_one: Io_mgr.Instance.DeleteFil(Xolog_file_utl.To_url_by_file(log_dir, log_doc.Log_file())); break;
|
||||
case Enm_cmd.Tid__delete_all: Io_mgr.Instance.DeleteDirDeep(log_dir); break;
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
Xoa_url_args_bldr args_bldr = new Xoa_url_args_bldr();
|
||||
args_bldr.Add("cmd", "view");
|
||||
if (redirect_to_same_file && file != null)
|
||||
args_bldr.Add("file", file);
|
||||
page.Redirect_trail().Itms__add__special(wiki, Prototype.Special__meta(), args_bldr.To_ary());
|
||||
return;
|
||||
}
|
||||
else
|
||||
new Xolog_html(log_doc).Bld_page_by_mustache(app, page, this);
|
||||
}
|
||||
static class Enm_cmd {//#*nested
|
||||
public static final int Tid__view = 0, Tid__email = 1, Tid__delete_one = 2, Tid__delete_all = 3;
|
||||
public static final Gfo_qarg_enum_itm Itm = new Gfo_qarg_enum_itm("cmd")
|
||||
.Add("view" , Tid__view)
|
||||
.Add("email" , Tid__email)
|
||||
.Add("delete_one" , Tid__delete_one)
|
||||
.Add("delete_all" , Tid__delete_all)
|
||||
;
|
||||
}
|
||||
Xolog_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xolog_special(Xow_special_meta.New_xo("XowaLog", "Logs"));
|
||||
}
|
||||
class Xoa_url_args_bldr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
public Xoa_url_args_bldr Add(String key, Object val) {
|
||||
list.Add(Keyval_.new_(key, val));
|
||||
return this;
|
||||
}
|
||||
public Keyval[] To_ary() {return (Keyval[])list.To_ary_and_clear(Keyval.class);}
|
||||
}
|
||||
class Xolog_file_utl {// yyyyMMdd_HHmmss.log
|
||||
private static final String Gui__date_fmt = "yyyy-MM-dd HH:mm:ss";
|
||||
public static String To_name(Io_url url) {return To_name(url.NameOnly());}
|
||||
public static String To_name(String file) {
|
||||
DateAdp date = DateAdp_.parse_fmt(file, Gfo_log_.File__fmt);
|
||||
return date.XtoStr_fmt(Gui__date_fmt);
|
||||
}
|
||||
public static Io_url To_url_by_file(Io_url dir, String file) {
|
||||
return dir.GenSubFil(file + Gfo_log_.File__ext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,19 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.maints.sql_execs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.maints.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
|
||||
public class Xosql_exec_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ gplx.xowa.addons.apps.maints.sql_execs.specials.Xosql_exec_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ gplx.xowa.addons.apps.maints.sql_execs.cbks.Xosql_exec_bridge.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return ADDON__KEY;} private static final String ADDON__KEY = "xowa.app.maint.sql_exec";
|
||||
}
|
||||
|
||||
@@ -13,29 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.maints.sql_execs.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.maints.*; import gplx.xowa.addons.apps.maints.sql_execs.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xosql_exec_bridge implements Bridge_cmd_itm {
|
||||
private Xosql_exec_svc svc;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
this.svc = new Xosql_exec_svc(app);
|
||||
}
|
||||
public String Exec(Json_nde data) {
|
||||
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Bridge_cmd_mgr.Msg__proc, null), Byte_ascii.Max_7_bit);
|
||||
Json_nde args = data.Get_kv(Bridge_cmd_mgr.Msg__args).Val_as_nde();
|
||||
switch (proc_id) {
|
||||
case Proc__exec: svc.Exec(args); break;
|
||||
default: throw Err_.new_unhandled_default(proc_id);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static final byte Proc__exec = 0;
|
||||
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("exec" , Proc__exec)
|
||||
;
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} public static final byte[] BRIDGE_KEY = Bry_.new_a7("xowa.app.maint.sql_exec");
|
||||
public static final Xosql_exec_bridge Prototype = new Xosql_exec_bridge(); Xosql_exec_bridge() {}
|
||||
}
|
||||
|
||||
@@ -13,78 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.maints.sql_execs.cbks; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.maints.*; import gplx.xowa.addons.apps.maints.sql_execs.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.dbs.*; import gplx.xowa.specials.xowa.diags.*;
|
||||
/* TODO.XO
|
||||
* add backup function to backup db
|
||||
* option to output to file
|
||||
* run multiple SQL statements (need to change jdbc)
|
||||
* print column headers if SELECT
|
||||
* print row counts
|
||||
* run stored procs? EXEC debug_image 'A.png'
|
||||
*/
|
||||
class Xosql_exec_svc {
|
||||
private gplx.xowa.guis.cbks.Xog_cbk_trg cbk_trg = gplx.xowa.guis.cbks.Xog_cbk_trg.New(gplx.xowa.addons.apps.maints.sql_execs.specials.Xosql_exec_special.Prototype.Special__meta().Ttl_bry());
|
||||
private final Xoa_app app;
|
||||
public Xosql_exec_svc(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Exec(Json_nde args) {
|
||||
String domain = args.Get_as_str("domain");
|
||||
String db = args.Get_as_str("db");
|
||||
String sql = args.Get_as_str("sql");
|
||||
|
||||
// get conn
|
||||
Db_conn conn = null;
|
||||
if (String_.Eq(domain, DOMAIN__APP)) {
|
||||
if (String_.Eq(db, DB__USER)) {
|
||||
conn = app.User().User_db_mgr().Conn();
|
||||
}
|
||||
}
|
||||
else if (String_.Eq(domain, DOMAIN__FILE)) {
|
||||
conn = Db_conn_bldr.Instance.Get_or_fail(Io_url_.new_any_(db));
|
||||
}
|
||||
else {
|
||||
Xow_wiki wiki = String_.Eq(domain, DOMAIN__HOME)
|
||||
? wiki = app.User().Wikii()
|
||||
: app.Wiki_mgri().Get_by_or_make_init_y(Bry_.new_u8(domain));
|
||||
|
||||
// for now, only support core
|
||||
if (String_.Eq(db, DB__CORE)) {
|
||||
conn = wiki.Data__core_mgr().Db__core().Conn();
|
||||
}
|
||||
}
|
||||
|
||||
String results = null;
|
||||
try {
|
||||
// run sql
|
||||
// HACK: assume SQL starting with SELECT is a reader
|
||||
if (String_.Has_at_bgn(sql, "SELECT ")) {
|
||||
// run select
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Object[][] rows = Db_rdr_utl.Load(conn, sql);
|
||||
Db_rdr_utl.Write_to_bfr(bfr, rows);
|
||||
results = bfr.To_str_and_clear();
|
||||
}
|
||||
else {
|
||||
conn.Exec_sql(sql);
|
||||
results = "executed";
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
results = Err_.Message_gplx_full(exc);
|
||||
results = String_.Replace(results, "\t", " "); // tabs must be escaped, else "bad character in String literal"
|
||||
}
|
||||
|
||||
// send results
|
||||
app.Gui__cbk_mgr().Send_json(cbk_trg, "xo.sql_exec.results__recv", gplx.core.gfobjs.Gfobj_nde.New()
|
||||
.Add_bry("msg_text", Bry_.Escape_html(Bry_.new_u8(results)))); // escape html; EX: "<" -> "<"
|
||||
}
|
||||
private static final String
|
||||
DOMAIN__APP = "[xowa.app]"
|
||||
, DOMAIN__HOME = "[xowa.home]"
|
||||
, DOMAIN__FILE = "[file]"
|
||||
, DB__CORE = "core"
|
||||
, DB__USER = "user"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,25 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.maints.sql_execs.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.maints.*; import gplx.xowa.addons.apps.maints.sql_execs.*;
|
||||
import gplx.langs.mustaches.*;
|
||||
public class Xosql_exec_doc implements Mustache_doc_itm {
|
||||
private final String domain, db, sql;
|
||||
public Xosql_exec_doc(String domain, String db, String sql) {
|
||||
this.domain = domain;
|
||||
this.db = db;
|
||||
this.sql = sql;
|
||||
}
|
||||
public boolean Mustache__write(String key, Mustache_bfr bfr) {
|
||||
if (String_.Eq(key, "domain")) bfr.Add_str_u8(domain);
|
||||
else if (String_.Eq(key, "db")) bfr.Add_str_u8(db);
|
||||
else if (String_.Eq(key, "sql")) bfr.Add_str_u8(sql);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
public Mustache_doc_itm[] Mustache__subs(String key) {
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
|
||||
public static final Xosql_exec_doc[] Ary_empty = new Xosql_exec_doc[0];
|
||||
}
|
||||
|
||||
@@ -13,37 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.maints.sql_execs.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.maints.*; import gplx.xowa.addons.apps.maints.sql_execs.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.dbs.*;
|
||||
class Xosql_exec_html extends Xow_special_wtr__base {
|
||||
private final String domain, db, sql;
|
||||
public Xosql_exec_html(String domain, String db, String sql) {
|
||||
this.domain = domain;
|
||||
this.db = db;
|
||||
this.sql = sql;
|
||||
}
|
||||
@Override protected Io_url Get_addon_dir(Xoa_app app) {return Addon_dir(app);}
|
||||
@Override protected Io_url Get_mustache_fil(Io_url addon_dir) {return addon_dir.GenSubFil_nest("bin", "xosql_exec.template.html");}
|
||||
@Override protected Mustache_doc_itm Bld_mustache_root(Xoa_app app) {
|
||||
return new Xosql_exec_doc(domain, db, sql);
|
||||
}
|
||||
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {
|
||||
Xopg_tag_mgr head_tags = page_data.Head_tags();
|
||||
Xopg_tag_wtr_.Add__xoelem (head_tags, app.Fsys_mgr().Http_root());
|
||||
|
||||
Xopg_tag_wtr_.Add__xocss (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xohelp (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xolog (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xoajax (head_tags, app.Fsys_mgr().Http_root(), app);
|
||||
Xopg_tag_wtr_.Add__jquery (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_tag_wtr_.Add__xonotify (head_tags, app.Fsys_mgr().Http_root());
|
||||
Xopg_alertify_.Add_tags (head_tags, app.Fsys_mgr().Http_root());
|
||||
|
||||
head_tags.Add(Xopg_tag_itm.New_css_file(addon_dir.GenSubFil_nest("bin", "xosql_exec.css")));
|
||||
head_tags.Add(Xopg_tag_itm.New_js_file(addon_dir.GenSubFil_nest("bin", "xosql_exec.js")));
|
||||
}
|
||||
public static Io_url Addon_dir(Xoa_app app) {
|
||||
return app.Fsys_mgr().Http_root().GenSubDir_nest("bin", "any", "xowa", "addon", "app", "maint", "sql_exec");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.maints.sql_execs.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.maints.*; import gplx.xowa.addons.apps.maints.sql_execs.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Xosql_exec_special implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
Gfo_qarg_mgr url_args = new Gfo_qarg_mgr().Init(url.Qargs_ary());
|
||||
|
||||
String domain = url_args.Read_str_or("domain", "[xowa.home]");
|
||||
String db = url_args.Read_str_or("db", "core");
|
||||
String sql = url_args.Read_str_or("sql", "SELECT * FROM xowa_cfg;");
|
||||
|
||||
new Xosql_exec_html(domain, db, sql).Bld_page_by_mustache(wiki.App(), page, this);
|
||||
}
|
||||
Xosql_exec_special(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final Xow_special_page Prototype = new Xosql_exec_special(Xow_special_meta.New_xo("XowaSql", "SQL Exec"));
|
||||
}
|
||||
|
||||
@@ -13,36 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.core.scripts.*;
|
||||
public class Xoscript_env {
|
||||
private final Gfo_script_engine engine;
|
||||
public Xoscript_env(Gfo_script_engine engine, Io_url root_dir) {
|
||||
this.root_dir = root_dir;
|
||||
this.engine = engine;
|
||||
}
|
||||
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
|
||||
public void load_script(String file) {
|
||||
engine.Load_script(Io_url_.new_fil_(Xoscript_env.Resolve_file(Bool_.N, root_dir, file)));
|
||||
}
|
||||
public static String Resolve_file(boolean use_file_protocol, Io_url root_dir, String file) {
|
||||
String rv = file;
|
||||
|
||||
// resolve relative urls; EX: "./a.js" -> "/xowa/wiki/simple.wikipedia.org/bin/script/a.js"
|
||||
if (String_.Has_at_bgn(rv, "./")) {
|
||||
// remove "./"
|
||||
rv = String_.Mid(rv, 2);
|
||||
|
||||
if (use_file_protocol)
|
||||
rv = root_dir.To_http_file_str() + rv;
|
||||
else {
|
||||
// if fsys_url && wnt, replace "\" with "/"
|
||||
if (Op_sys.Cur().Tid_is_wnt())
|
||||
rv = String_.Replace(rv, Op_sys.Lnx.Fsys_dir_spr_str(), Op_sys.Wnt.Fsys_dir_spr_str());
|
||||
rv = root_dir.Xto_api() + Op_sys.Cur().Fsys_dir_spr_str() + rv;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,26 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.core.scripts.*;
|
||||
import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.apps.scripts.apis.*; import gplx.xowa.addons.apps.scripts.xtns.*;
|
||||
public class Xoscript_mgr {
|
||||
private Io_url root_dir;
|
||||
private Xoscript_xtn_mgr xtn_mgr;
|
||||
public void Init(Xow_wiki wiki) {
|
||||
// check script_dir
|
||||
this.root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("bin", "any", "script");
|
||||
if (!Io_mgr.Instance.ExistsDir(root_dir)) return;
|
||||
this.xtn_mgr = new Xoscript_xtn_mgr(root_dir);
|
||||
}
|
||||
public void Write(Bry_bfr rv, Xow_wiki wiki, Xoa_page page) {
|
||||
// init
|
||||
if (!wiki.Html__wtr_mgr().Scripting_enabled()) return;
|
||||
this.Init(wiki);
|
||||
if (xtn_mgr == null) return;
|
||||
|
||||
xtn_mgr.Load_root();
|
||||
xtn_mgr.Run(rv, wiki, page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,47 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc {
|
||||
private final Bry_bfr bfr;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public Xoscript_doc(Bry_bfr bfr, Xoscript_page page_var) {
|
||||
this.bfr = bfr;
|
||||
this.page_var = page_var;
|
||||
this.head_var = new Xoscript_doc_head(this);
|
||||
this.tail_var = new Xoscript_doc_tail(this);
|
||||
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.TOP-->", "top");
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.BOT-->", "bot", Xoscript_doc_sect_base.Pos__default);
|
||||
tail_var.reg_marker("<!--XOWA.SCRIPT.TAIL.TOP-->", "top", Xoscript_doc_sect_base.Pos__default);
|
||||
}
|
||||
public Xoscript_page page() {return page_var;} private final Xoscript_page page_var;
|
||||
public Xoscript_doc_head head() {return head_var;} private final Xoscript_doc_head head_var;
|
||||
public Xoscript_doc_tail tail() {return tail_var;} private final Xoscript_doc_tail tail_var;
|
||||
public String html() {
|
||||
if (html_var == null) {
|
||||
html_var = bfr.To_str();
|
||||
}
|
||||
return html_var;
|
||||
} private String html_var;
|
||||
public void html(String s) {
|
||||
html_var = s;
|
||||
html_dirty = true;
|
||||
}
|
||||
public void html_by_marker(byte[] marker, byte[] marker_html) {
|
||||
byte[] html_bry = Bry_.new_u8(this.html());
|
||||
|
||||
// find marker, and splice it in
|
||||
int marker_pos = Bry_find_.Find_fwd(html_bry, marker);
|
||||
if (marker_pos != Bry_find_.Not_found) {
|
||||
tmp_bfr.Add_mid(html_bry, 0, marker_pos);
|
||||
tmp_bfr.Add(marker_html);
|
||||
tmp_bfr.Add_mid(html_bry, marker_pos, html_bry.length);
|
||||
html_bry = tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
this.html(String_.new_u8(html_bry));
|
||||
}
|
||||
public boolean dirty() {
|
||||
return html_dirty;
|
||||
} private boolean html_dirty;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc_head extends Xoscript_doc_sect_base {
|
||||
public Xoscript_doc_head(Xoscript_doc doc) {super(doc);}
|
||||
}
|
||||
|
||||
@@ -13,60 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoscript_doc_head__tst {
|
||||
private final Xoscript_doc_head__fxt fxt = new Xoscript_doc_head__fxt();
|
||||
@Before public void init() {
|
||||
fxt.Init__sect("head");
|
||||
fxt.Exec__reg_marker("<!--top-->", "top", Xoscript_doc_head.Pos__default);
|
||||
fxt.Exec__reg_marker("<!--bot-->", "bot");
|
||||
fxt.Exec__doc__html("a<!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_html() {
|
||||
fxt.Exec__add_html("top", "<b>add_1</b>");
|
||||
fxt.Exec__add_html("top", "<b>add_2</b>");
|
||||
fxt.Test__html("a<b>add_1</b><b>add_2</b><!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_html__default() {
|
||||
fxt.Exec__add_html("<b>add_1</b>");
|
||||
fxt.Test__html("a<b>add_1</b><!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_tag() {
|
||||
fxt.Exec__add_tag("top", "div", "div_body", "k0", "v0", "k1", "v1");
|
||||
fxt.Test__html
|
||||
( "a<div k0=\"v0\" k1=\"v1\">div_body</div>"
|
||||
, "<!--top-->b<!--bot-->c");
|
||||
}
|
||||
@Test public void Add_js_file() {
|
||||
fxt.Exec__add_js_file("top", "./a.js");
|
||||
fxt.Test__html
|
||||
( "a<script src=\"file:///mem/wiki/test_wiki/bin/script/a.js\" type=\"text/javascript\"></script>"
|
||||
, "<!--top-->b<!--bot-->c");
|
||||
}
|
||||
}
|
||||
class Xoscript_doc_head__fxt {
|
||||
private final Xoscript_page spg;
|
||||
private Xoscript_doc_sect_base sect;
|
||||
public Xoscript_doc_head__fxt() {
|
||||
Bry_bfr rv = Bry_bfr_.New();
|
||||
Xoscript_env env = new Xoscript_env(new gplx.core.scripts.Gfo_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
|
||||
Xoscript_url url = new Xoscript_url("test_wiki", "test_page");
|
||||
spg = new Xoscript_page(rv, env, url);
|
||||
}
|
||||
public void Init__sect(String sect_name) {
|
||||
if (String_.Eq(sect_name, "head"))
|
||||
sect = spg.doc().head();
|
||||
else if (String_.Eq(sect_name, "tail"))
|
||||
sect = spg.doc().tail();
|
||||
}
|
||||
public void Exec__doc__html(String html) {spg.doc().html(html);}
|
||||
public void Exec__reg_marker(String marker, String... pos_ary) {sect.reg_marker(marker, pos_ary);}
|
||||
public void Exec__add_js_file(String pos, String file) {sect.add_js_file(pos, file);}
|
||||
public void Exec__add_html(String html) {sect.add_html(html);}
|
||||
public void Exec__add_html(String pos, String html) {sect.add_html(pos, html);}
|
||||
public void Exec__add_tag(String pos, String tag, String body, Object... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
|
||||
public void Test__html(String... expd) {
|
||||
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), spg.doc().html(), "html");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,68 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public abstract class Xoscript_doc_sect_base {
|
||||
protected final Xoscript_doc doc;
|
||||
private final Hash_adp_bry marker_hash = Hash_adp_bry.cs();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public Xoscript_doc_sect_base(Xoscript_doc doc) {this.doc = doc;}
|
||||
private byte[] get_marker_by_pos(byte[] pos_bry) {
|
||||
return (byte[])marker_hash.Get_by_or_fail(pos_bry);
|
||||
}
|
||||
public void reg_marker(String marker_str, String... pos_ary) {
|
||||
int len = pos_ary.length;
|
||||
byte[] marker_bry = Bry_.new_u8(marker_str);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
marker_hash.Add_if_dupe_use_nth(Bry_.new_u8(pos_ary[i]), marker_bry);
|
||||
}
|
||||
}
|
||||
public void add_html(String html) {add_html(Pos__default, html);}
|
||||
public void add_html(String pos_str, String html) {add_html(Pos__default, Bry_.new_u8(html));}
|
||||
public void add_html(String pos_str, byte[] html) {
|
||||
doc.html_by_marker(get_marker_by_pos(Bry_.new_u8(pos_str)), html);
|
||||
}
|
||||
public void add_tag(String pos_str, String tag_str, String body, Object... head_atrs) {
|
||||
// build tag.bgn; EX: '<tag k1="v1">'
|
||||
tmp_bfr.Add_byte(Byte_ascii.Angle_bgn);
|
||||
tmp_bfr.Add_str_u8(tag_str);
|
||||
int head_atrs_len = head_atrs.length;
|
||||
for (int i = 0; i < head_atrs_len; i += 2) {
|
||||
tmp_bfr.Add_byte_space();
|
||||
tmp_bfr.Add_obj_strict(head_atrs[i]);
|
||||
tmp_bfr.Add_byte_eq();
|
||||
tmp_bfr.Add_byte_quote();
|
||||
tmp_bfr.Add_obj_strict(head_atrs[i + 1]);
|
||||
tmp_bfr.Add_byte_quote();
|
||||
}
|
||||
tmp_bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
|
||||
// build tag.body; EX: 'some body'
|
||||
tmp_bfr.Add_str_u8(body);
|
||||
|
||||
// build tag.end; EX: '</tag>\n'
|
||||
tmp_bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash);
|
||||
tmp_bfr.Add_str_u8(tag_str);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
tmp_bfr.Add_byte_nl();
|
||||
|
||||
add_html(pos_str, tmp_bfr.To_bry_and_clear());
|
||||
}
|
||||
public void add_js_file(String file_str) {add_js_file(Pos__default, file_str);}
|
||||
public void add_js_file(String pos_str, String file_str) {
|
||||
add_tag(pos_str, "script", Body__empty, "src", Xoscript_env.Resolve_file(Bool_.Y, doc.page().env().Root_dir(), file_str), "type", "text/javascript");
|
||||
}
|
||||
public void add_js_code(String code_str) {add_js_file(Pos__default, code_str);}
|
||||
public void add_js_code(String pos_str, String code_str) {
|
||||
add_tag(pos_str, "script", code_str, "type", "text/javascript");
|
||||
}
|
||||
public void add_css_file(String file_str) {add_js_file(Pos__default, file_str);}
|
||||
public void add_css_file(String pos_str, String file_str) {
|
||||
add_tag(pos_str, "link", Body__empty, "rel", "stylesheet", "href", Xoscript_env.Resolve_file(Bool_.Y, doc.page().env().Root_dir(), file_str), "type", "text/css");
|
||||
}
|
||||
public void add_css_code(String code_str) {add_css_code(Pos__default, code_str);}
|
||||
public void add_css_code(String pos_str, String code_str) {
|
||||
add_tag(pos_str, "style", code_str, "type", "text/css");
|
||||
}
|
||||
public static final String Pos__default = "", Body__empty = "";
|
||||
}
|
||||
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc_tail extends Xoscript_doc_sect_base {
|
||||
public Xoscript_doc_tail(Xoscript_doc doc) {super(doc);}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_log {
|
||||
public void log(String... v) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", String_.Concat_with_str(" ", v));
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_page {
|
||||
public Xoscript_page(Bry_bfr rv, Xoscript_env env_var, Xoscript_url url_var) {
|
||||
this.env_var = env_var;
|
||||
this.url_var = url_var;
|
||||
this.doc_var = new Xoscript_doc(rv, this);
|
||||
}
|
||||
public Xoscript_env env() {return env_var;} private final Xoscript_env env_var;
|
||||
public Xoscript_url url() {return url_var;} private final Xoscript_url url_var;
|
||||
public Xoscript_doc doc() {return doc_var;} private final Xoscript_doc doc_var;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_url {
|
||||
public Xoscript_url(String wiki_name_var, String page_name_var) {this.wiki_name_var = wiki_name_var; this.page_name_var = page_name_var;}
|
||||
public String wiki_name() {return wiki_name_var;} private final String wiki_name_var;
|
||||
public String page_name() {return page_name_var;} private final String page_name_var;
|
||||
}
|
||||
|
||||
@@ -13,15 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
public class Xoscript_xtn_itm {
|
||||
public Xoscript_xtn_itm(String key, Io_url url, Gfo_script_engine engine) {
|
||||
this.key = key;
|
||||
this.url = url;
|
||||
this.engine = engine;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Gfo_script_engine Engine() {return engine;} private final Gfo_script_engine engine;
|
||||
}
|
||||
|
||||
@@ -13,55 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
import gplx.xowa.addons.apps.scripts.apis.*;
|
||||
public class Xoscript_xtn_mgr {
|
||||
private Xoscript_xtn_itm root_itm;
|
||||
private final Io_url root_dir;
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xoscript_xtn_mgr(Io_url root_dir) {
|
||||
this.root_dir = root_dir;
|
||||
}
|
||||
public void reg_xtn(String key, String file) {
|
||||
Io_url url = Io_url_.new_fil_(Xoscript_env.Resolve_file(Bool_.N, root_dir, file));
|
||||
Xoscript_xtn_itm itm = new Xoscript_xtn_itm(key, url, Gfo_script_engine_.New_by_ext(url.Ext()));
|
||||
hash.Add(key, itm);
|
||||
}
|
||||
public void Load_root() {
|
||||
Io_url[] root_urls = Io_mgr.Instance.QueryDir_args(root_dir).ExecAsUrlAry();
|
||||
int root_urls_len = root_urls.length;
|
||||
for (int i = 0; i < root_urls_len; ++i) {
|
||||
Io_url root_url = root_urls[0];
|
||||
String root_name_and_ext = root_url.NameAndExt();
|
||||
if (String_.EqAny(root_name_and_ext, "xowa.script.main.js", "xowa.script.main.lua")) {
|
||||
this.root_itm = new Xoscript_xtn_itm("xowa.root", root_url, Gfo_script_engine_.New_by_ext(root_url.Ext()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
root_itm.Engine().Load_script(root_itm.Url());
|
||||
root_itm.Engine().Invoke_function("xoscript__main", this);
|
||||
}
|
||||
public void Run(Bry_bfr rv, Xow_wiki wiki, Xoa_page page) {
|
||||
int len = hash.Len();
|
||||
Xoscript_log log = new Xoscript_log();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoscript_xtn_itm itm = (Xoscript_xtn_itm)hash.Get_at(i);
|
||||
Gfo_script_engine engine = (Gfo_script_engine)itm.Engine();
|
||||
Xoscript_env env = new Xoscript_env(engine, itm.Url().OwnerDir());
|
||||
Xoscript_page spg = new Xoscript_page(rv, env, new Xoscript_url(page.Wiki().Domain_str(), String_.new_u8(page.Url().Page_bry())));
|
||||
engine.Put_object("xolog", log);
|
||||
engine.Load_script(itm.Url());
|
||||
try {engine.Invoke_function("xoscript__init", env);}
|
||||
catch (Exception e) {Gfo_usr_dlg_.Instance.Note_many("", "", "xoscript__init failed; url=~{0} err=~{1}", itm.Url(), Err_.Message_lang(e));}
|
||||
try {engine.Invoke_function("xoscript__page_write_end", spg);}
|
||||
catch (Exception e) {Gfo_usr_dlg_.Instance.Note_many("", "", "xoscript__page_write_end failed; url=~{0} err=~{1}", itm.Url(), Err_.Message_lang(e));}
|
||||
|
||||
// overwrite html
|
||||
if (spg.doc().dirty()) {
|
||||
rv.Clear();
|
||||
rv.Add_str_u8(spg.doc().html());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,19 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.htmls.bridges.*;
|
||||
public class Xoa_update_addon implements Xoax_addon_itm, Xoax_addon_itm__special, Xoax_addon_itm__json {
|
||||
public Xow_special_page[] Special_pages() {
|
||||
return new Xow_special_page[]
|
||||
{ gplx.xowa.addons.apps.updates.specials.Xoa_update_special.Prototype
|
||||
};
|
||||
}
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ gplx.xowa.addons.apps.updates.specials.svcs.Xoa_update_bridge.Prototype
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return ADDON__KEY;} private static final String ADDON__KEY = "xowa.app.update";
|
||||
}
|
||||
|
||||
@@ -13,35 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.xowa.addons.apps.cfgs.*;
|
||||
import gplx.xowa.addons.apps.updates.dbs.*;
|
||||
public class Xoa_update_startup {
|
||||
public static boolean Show_at_startup(Xoa_app app) {
|
||||
try {
|
||||
// set default to this version
|
||||
Xocfg_mgr cfg = app.Cfg();
|
||||
cfg.Dflt_mgr().Add(Cfg__version_cutoff, Int_.To_str(Xoa_app_.Version_id));
|
||||
|
||||
// exit if disabled
|
||||
if (!cfg.Get_bool_app_or(Cfg__enabled, true)) return false;
|
||||
|
||||
// check online for updates
|
||||
Io_url db_url = Xoa_update_db_mgr_.Url(app);
|
||||
Xoa_update_db_mgr_.Download_from_inet(app, Bool_.Y, db_url);
|
||||
|
||||
// check offline for updates
|
||||
int version_cutoff = cfg.Get_int_app_or(Cfg__version_cutoff, Xoa_app_.Version_id);
|
||||
return Xoa_update_db_mgr_.Select(db_url, version_cutoff).length > 0;
|
||||
} catch (Exception exc) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "starup:fatal error while looking up app-update-reminder; err=~{0}", Err_.Message_gplx_log(exc));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static int Version_cutoff(Xoa_app app) {return app.Cfg().Get_int_app_or(Cfg__version_cutoff, Xoa_app_.Version_id);}
|
||||
public static void Version_cutoff_(Xoa_app app, int id) {app.Cfg().Set_int_app(Cfg__version_cutoff, id);}
|
||||
|
||||
private static final String
|
||||
Cfg__enabled = "xowa.app.update.startup.enabled"
|
||||
, Cfg__version_cutoff = "xowa.app.update.startup.version_cutoff";
|
||||
}
|
||||
|
||||
@@ -13,12 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*;
|
||||
public class Xoa_manifest_item {
|
||||
public Xoa_manifest_item(Io_url src, Io_url trg) {
|
||||
this.src = src;
|
||||
this.trg = trg;
|
||||
}
|
||||
public Io_url Src() {return src;} private final Io_url src;
|
||||
public Io_url Trg() {return trg;} private final Io_url trg;
|
||||
}
|
||||
|
||||
@@ -13,47 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*;
|
||||
public class Xoa_manifest_list {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public Xoa_manifest_item Get_at(int i) {return (Xoa_manifest_item)hash.Get_at(i);}
|
||||
public void Del_at(int i) {
|
||||
Xoa_manifest_item item = (Xoa_manifest_item)hash.Get_at(i);
|
||||
hash.Del(item.Src().Raw());
|
||||
}
|
||||
public void Add(Io_url src, Io_url trg) {
|
||||
Xoa_manifest_item item = new Xoa_manifest_item(src, trg);
|
||||
hash.Add(src.Raw(), item);
|
||||
}
|
||||
public void Save(Bry_bfr bfr) {
|
||||
// save as "src\ttrg\n"
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_manifest_item item = (Xoa_manifest_item)hash.Get_at(i);
|
||||
bfr.Add_str_u8(item.Src().Raw());
|
||||
bfr.Add_byte(Byte_ascii.Tab);
|
||||
bfr.Add_str_u8(item.Trg().Raw());
|
||||
bfr.Add_byte(Byte_ascii.Nl);
|
||||
}
|
||||
}
|
||||
public void Load(byte[] src, int src_bgn, int src_end) {
|
||||
int pos = src_bgn;
|
||||
// load by "src\ttrg\n"
|
||||
while (pos < src_end) {
|
||||
// get pos
|
||||
int tab_pos = Bry_find_.Find_fwd(src, Byte_ascii.Tab, pos, src_end);
|
||||
if (tab_pos == Bry_find_.Not_found) throw Err_.new_wo_type("failed to find tab", "excerpt", Bry_.Mid(src, pos, src_end));
|
||||
int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl, tab_pos + 1, src_end);
|
||||
if (nl_pos == Bry_find_.Not_found) throw Err_.new_wo_type("failed to find nl", "excerpt", Bry_.Mid(src, pos, src_end));
|
||||
|
||||
// create
|
||||
Io_url src_url = Io_url_.new_fil_(String_.new_u8(src, pos, tab_pos));
|
||||
Io_url trg_url = Io_url_.new_fil_(String_.new_u8(src, tab_pos + 1, nl_pos));
|
||||
Xoa_manifest_item item = new Xoa_manifest_item(src_url, trg_url);
|
||||
hash.Add(src_url.Raw(), item);
|
||||
|
||||
pos = nl_pos + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,100 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*;
|
||||
import gplx.core.envs.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
public class Xoa_manifest_view extends JFrame implements Gfo_invk {
|
||||
private final Xoa_manifest_wkr wkr;
|
||||
private String run_xowa_cmd;
|
||||
public Xoa_manifest_view(Io_url manifest_url) {
|
||||
super("XOWA Application Update");
|
||||
// init window
|
||||
this.setTitle("XOWA Application Update");
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {System.out.println(e.getMessage());}
|
||||
this.setSize(700, 580);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setBackground(Color.WHITE);
|
||||
|
||||
// init panel
|
||||
JPanel main_panel = new JPanel();
|
||||
main_panel.setSize(700, 580);
|
||||
this.setContentPane(main_panel);
|
||||
New_text_area(main_panel);
|
||||
run_xowa_lbl = New_link_lbl(this, main_panel, Invk__run_xowa, "<html><a href=\"\" style='color:#b9b9b9;'>Run XOWA</a></html>");
|
||||
this.setVisible(true);
|
||||
this.wkr = new Xoa_manifest_wkr(this);
|
||||
wkr.Init(manifest_url);
|
||||
}
|
||||
private JTextArea text_area;
|
||||
private JLabel run_xowa_lbl;
|
||||
private JScrollPane New_text_area(JPanel owner) {
|
||||
// init textarea
|
||||
text_area = new JTextArea();
|
||||
text_area.setForeground(Color.BLACK);
|
||||
text_area.setBackground(Color.WHITE);
|
||||
text_area.setMargin(new Insets(0, 0, 0,0));
|
||||
text_area.setLineWrap(true);
|
||||
text_area.setWrapStyleWord(true); // else text will wrap in middle of words
|
||||
text_area.setCaretColor(Color.BLACK);
|
||||
text_area.getCaret().setBlinkRate(0);
|
||||
|
||||
// init scrollpane
|
||||
JScrollPane text_scroll_pane = new JScrollPane(text_area);
|
||||
text_scroll_pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
owner.add(text_scroll_pane, BorderLayout.CENTER);
|
||||
text_scroll_pane.setPreferredSize(new Dimension(675, 500));
|
||||
return text_scroll_pane;
|
||||
}
|
||||
private static JLabel New_link_lbl(Gfo_invk invk, JPanel owner, String invk_cmd, String text) {
|
||||
JLabel rv = new JLabel();
|
||||
rv.setText(text);
|
||||
rv.setPreferredSize(new Dimension(80, 20));
|
||||
owner.add(rv, BorderLayout.PAGE_END);
|
||||
return rv;
|
||||
}
|
||||
public void Append(String s) {
|
||||
text_area.setText(text_area.getText() + "> " + s + "\n");
|
||||
}
|
||||
public void Mark_done(String s) {
|
||||
this.run_xowa_cmd = s;
|
||||
run_xowa_lbl.setText("<html><a href=\"\"'>Run XOWA</a></html>");
|
||||
run_xowa_lbl.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
run_xowa_lbl.addMouseListener(new Swing_mouse_adapter(Gfo_invk_cmd.New_by_key(this, Invk__run_xowa)));
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__run_xowa)) {
|
||||
Runtime_.Exec(run_xowa_cmd);
|
||||
System_.Exit();
|
||||
}
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk__run_xowa = "run_xowa";
|
||||
|
||||
public static void Run() {
|
||||
Io_url manifest_url = Env_.AppUrl().GenNewExt(".txt");
|
||||
if (!Op_sys.Cur().Tid_is_osx())
|
||||
new Xoa_manifest_view(manifest_url);
|
||||
}
|
||||
}
|
||||
class Swing_mouse_adapter extends MouseAdapter {
|
||||
private final Gfo_invk_cmd cmd;
|
||||
public Swing_mouse_adapter(Gfo_invk_cmd cmd) {this.cmd = cmd;}
|
||||
@Override public void mouseClicked(MouseEvent ev) {
|
||||
try {cmd.Exec();}
|
||||
catch (Exception e) {
|
||||
System.out.println(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,72 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.addons.apps.updates.apps; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.updates.*;
|
||||
import gplx.core.envs.*;
|
||||
class Xoa_manifest_wkr {
|
||||
private final Xoa_manifest_view view;
|
||||
private final Xoa_manifest_list list = new Xoa_manifest_list();
|
||||
private Io_url manifest_url;
|
||||
private String run_xowa_cmd;
|
||||
public Xoa_manifest_wkr(Xoa_manifest_view view) {
|
||||
this.view = view;
|
||||
}
|
||||
public void Init(Io_url manifest_url) {
|
||||
// load manifest
|
||||
this.manifest_url = manifest_url;
|
||||
view.Append("loading manifest from: " + manifest_url.Raw());
|
||||
byte[] src = Io_mgr.Instance.LoadFilBry(manifest_url);
|
||||
|
||||
// parse manifest
|
||||
int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl);
|
||||
if (nl_pos == Bry_find_.Not_found) throw Err_.new_wo_type("could not find nl in manifest", "manifest_url", manifest_url.Raw());
|
||||
this.run_xowa_cmd = String_.new_u8(src, 0, nl_pos);
|
||||
list.Load(src, nl_pos + 1, src.length);
|
||||
|
||||
this.Wait();
|
||||
}
|
||||
private void Wait() {
|
||||
int tries = 0;
|
||||
while (tries++ < 100) {
|
||||
gplx.core.threads.Thread_adp_.Sleep(1000);
|
||||
if (Copy_files())
|
||||
break;
|
||||
else {
|
||||
String topmost = "#error";
|
||||
if (list.Len() > 0) {
|
||||
Xoa_manifest_item item = (Xoa_manifest_item)list.Get_at(0);
|
||||
topmost = item.Src().Raw();
|
||||
}
|
||||
view.Append("waiting for XOWA to release file: " + topmost);
|
||||
}
|
||||
}
|
||||
this.On_exit();
|
||||
}
|
||||
public void On_exit() {
|
||||
Io_mgr.Instance.DeleteFil(manifest_url);
|
||||
view.Mark_done(run_xowa_cmd);
|
||||
}
|
||||
private boolean Copy_files() {
|
||||
// loop list and copy items
|
||||
int len = list.Len();
|
||||
int idx = 0;
|
||||
for (idx = 0; idx < len; idx++) {
|
||||
Xoa_manifest_item item = (Xoa_manifest_item)list.Get_at(idx);
|
||||
try {
|
||||
Io_mgr.Instance.DeleteFil_args(item.Trg()).MissingFails_off().Exec();
|
||||
Io_mgr.Instance.CopyFil(item.Src(), item.Trg(), true);
|
||||
view.Append(String_.Format("copied file: src={0} trg={1}", item.Src().Raw(), item.Trg().Raw()));
|
||||
}
|
||||
catch (Exception exc) {
|
||||
view.Append(String_.Format("failed to copy file: src={0} trg={1} err={2}", item.Src().Raw(), item.Trg().Raw(), Err_.Message_lang(exc)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// remove completed items
|
||||
for (int i = 0; i < idx; i++) {
|
||||
list.Del_at(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user