Cfg: Remove cfg_mgr and more of old cfg system

pull/620/head
gnosygnu 8 years ago
parent 1c00d41b06
commit 08dda6a82d

@ -38,7 +38,6 @@ public class Xoae_app implements Xoa_app, Gfo_invk {
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();
cfg_mgr = new Xoa_cfg_mgr(this);
api_root = new Xoapi_root(this);
user = new Xoue_user(this, user_dir);
this.meta_mgr = new Xoa_meta_mgr(this);
@ -133,7 +132,6 @@ public class Xoae_app implements Xoa_app, Gfo_invk {
public Xoa_ctg_mgr Ctg_mgr() {return ctg_mgr;} private Xoa_ctg_mgr ctg_mgr = new Xoa_ctg_mgr();
public Xoa_fsys_eval Url_cmd_eval() {return url_cmd_eval;} Xoa_fsys_eval url_cmd_eval;
public Xoa_cur Cur_redirect() {return cur_redirect;} private Xoa_cur cur_redirect;
public Xoa_cfg_mgr Cfg_mgr() {return cfg_mgr;} private Xoa_cfg_mgr cfg_mgr;
public 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();
@ -221,7 +219,6 @@ public class Xoae_app implements Xoa_app, Gfo_invk {
else if (ctx.MatchPriv(k, Invk_term_cbk)) return this.Term_cbk();
else if (ctx.Match(k, Invk_xtns)) return xtn_mgr;
else if (ctx.Match(k, Invk_ctg_mgr)) return ctg_mgr;
else if (ctx.Match(k, Invk_cfgs)) return cfg_mgr;
else if (ctx.Match(k, Invk_usr_dlg)) return Xoa_app_.Usr_dlg();
else if (ctx.Match(k, Invk_specials)) return special_mgr;
else if (ctx.Match(k, Invk_server)) return tcp_server;
@ -237,7 +234,7 @@ public class Xoae_app implements Xoa_app, Gfo_invk {
public static final String Invk_gui = "gui", Invk_bldr = "bldr", Invk_wikis = "wikis", Invk_files = "files", Invk_langs = "langs", Invk_users = "users"
, Invk_sys_cfg = "sys_cfg", Invk_fsys = "fsys", Invk_cur = "cur", Invk_shell = "shell", Invk_log = "log"
, Invk_setup = "setup", Invk_scripts = "scripts", Invk_user = "user", Invk_xtns = "xtns", Invk_ctg_mgr = "ctg_mgr"
, Invk_cfgs = "cfgs", Invk_app = "app", Invk_xowa = "xowa", Invk_usr_dlg = "usr_dlg", Invk_specials = "specials", Invk_html = "html"
, Invk_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"

@ -195,7 +195,7 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
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.Cfg_mgr().Init(this);
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

@ -1,25 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public interface Xoa_cfg_db {
void Cfg_reset_all(Xoa_cfg_mgr cfg_mgr);
void Cfg_save_bgn(Xoa_cfg_mgr cfg_mgr);
void Cfg_save_end(Xoa_cfg_mgr cfg_mgr);
void Cfg_save_run(Xoa_cfg_mgr cfg_mgr, Xoa_cfg_grp cfg_grp, Xoa_cfg_itm cfg_itm);
void Cfg_load_run(Xoa_cfg_mgr cfg_mgr);
}

@ -1,52 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.apps.gfs.*;
public class Xoa_cfg_db_txt implements Xoa_cfg_db {
private Bry_fmtr fmtr = Bry_fmtr.new_("app.cfgs.get('~{msg}', '~{wiki}').val = '~{val}';\n", "msg", "wiki", "val");
public void Cfg_reset_all(Xoa_cfg_mgr cfg_mgr) {
Io_url src_url = this.Cfg_url(cfg_mgr);
Io_url trg_url = src_url.GenNewNameAndExt("xowa_user_cfg." + Datetime_now.Get().XtoStr_fmt_yyyyMMdd_HHmmss() + ".gfs");
Io_mgr.Instance.MoveFil_args(src_url, trg_url, true).Exec();
if (cfg_mgr.App().Tid_is_edit())
((Xoae_app)cfg_mgr.App()).Gui_mgr().Kit().Ask_ok("", "", "Options cleared. Please restart XOWA.");
}
public void Cfg_load_run(Xoa_cfg_mgr cfg_mgr) {
String load = Io_mgr.Instance.LoadFilStr(Cfg_url(cfg_mgr));
cfg_mgr.App().Gfs_mgr().Run_str(load);
}
public void Cfg_save_bgn(Xoa_cfg_mgr cfg_mgr) {
bfr.ClearAndReset();
} private Bry_bfr bfr = Bry_bfr_.New();
public void Cfg_save_end(Xoa_cfg_mgr cfg_mgr) {
Io_url cfg_url = Cfg_url(cfg_mgr);
if (Io_mgr.Instance.QueryFil(cfg_url).ReadOnly()) {
Xoa_app_.Usr_dlg().Log_many("", "", "shutting down app; skipping cfg b/c file is marked read-only; src=~{0}", cfg_url);
}
else {
Xoa_app_.Usr_dlg().Log_many("", "", "shutting down app; saving cfg: len=~{0}", bfr.Len());
Io_mgr.Instance.SaveFilBfr(Cfg_url(cfg_mgr), bfr);
}
}
public void Cfg_save_run(Xoa_cfg_mgr cfg_mgr, Xoa_cfg_grp cfg_grp, Xoa_cfg_itm cfg_itm) {
fmtr.Bld_bfr_many(bfr, Xoa_gfs_wtr_.Escape(cfg_grp.Key_bry()), Xoa_gfs_wtr_.Escape(cfg_itm.Key()), Xoa_gfs_wtr_.Escape(cfg_itm.Val()));
}
public Io_url Cfg_url(Xoa_cfg_mgr cfg_mgr) {return ((Xoae_app)cfg_mgr.App()).Usere().Fsys_mgr().App_data_cfg_dir().GenSubFil(File_name);}
public static final String File_name = "xowa_user_cfg.gfs";
}

@ -1,64 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wikis.domains.*;
public class Xoa_cfg_grp {
private final Ordered_hash hash = Ordered_hash_.New_bry(); private final Xoa_cfg_mgr mgr;
public Xoa_cfg_grp(Xoa_cfg_mgr mgr, Xoa_cfg_grp_tid tid, byte[] key_bry) {
this.mgr = mgr; this.tid = tid; this.key_bry = key_bry; this.key_str = String_.new_u8(key_bry);
}
public Xoa_cfg_grp_tid Tid() {return tid;} private final Xoa_cfg_grp_tid tid;
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
public String Key_str() {return key_str;} private final String key_str;
public boolean Notify(Xoa_cfg_itm itm) {return mgr.Notify(this, itm);}
public Xoa_cfg_itm Get_by_or_null(byte[] key) {return (Xoa_cfg_itm)hash.Get_by(key);}
public Xoa_cfg_itm Get_by_or_make(byte[] key) {
Xoa_cfg_itm rv = (Xoa_cfg_itm)hash.Get_by(key);
if (rv == null) {
rv = new Xoa_cfg_itm(this, key);
hash.Add(key, rv);
}
return rv;
}
public Xoa_cfg_itm Get_by_wiki(byte[] domain_bry, int domain_tid) {
Xoa_cfg_itm rv = (Xoa_cfg_itm)hash.Get_by(domain_bry);
if (rv == null) { // match by domain_bry failed; try tid
rv = (Xoa_cfg_itm)hash.Get_by(Xow_domain_tid_.Get_type_as_bry(domain_tid));
if (rv == null) // match by type failed; try all
rv = (Xoa_cfg_itm)hash.Get_by(Xoa_cfg_grp_tid.Key_all_bry);
if (rv == null) // match by all failed; try app
rv = (Xoa_cfg_itm)hash.Get_by(Xoa_cfg_grp_tid.Key_app_bry);
}
return rv;
}
public void Db_load_end() {
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Xoa_cfg_itm itm = (Xoa_cfg_itm)hash.Get_at(i);
itm.Val_load_done();
}
}
public void Db_save(Xoa_cfg_db db) {
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Xoa_cfg_itm itm = (Xoa_cfg_itm)hash.Get_at(i);
if (!itm.Val_is_customized() && !itm.Val_is_dirty()) continue; // system default and unchanged; no need to save
db.Cfg_save_run(mgr, this, itm);
}
}
}

@ -1,47 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wikis.domains.*;
public class Xoa_cfg_grp_tid {
public byte Tid() {return tid;} private byte tid;
public byte[] Key() {return key;} private byte[] key;
public int Wiki_tid() {return wiki_tid;} private int wiki_tid;
public static final byte Tid_null = 0, Tid_all = 1, Tid_type = 2, Tid_wiki = 3, Tid_app = 4;
public static final String Key_app_str = "app";
public static final byte[] Key_all_bry = Bry_.new_a7("*"), Key_app_bry = Bry_.new_a7(Key_app_str);
public static Xoa_cfg_grp_tid parse(byte[] key) {
Xoa_cfg_grp_tid rv = (Xoa_cfg_grp_tid)factory.Get_by_bry(key);
if (rv == null) {
rv = new Xoa_cfg_grp_tid();
if (Bry_.Eq(key, Key_all_bry)) rv.tid = Tid_all;
else if (Bry_.Eq(key, Key_app_bry)) rv.tid = Tid_app;
else {
Xow_domain_itm wiki_type = Xow_domain_itm_.parse(key);
if (wiki_type.Domain_type_id() == Xow_domain_tid_.Tid__other)
rv.tid = Tid_wiki;
else {
rv.tid = Tid_type;
rv.wiki_tid = wiki_type.Domain_type_id();
}
}
rv.key = key;
factory.Add(key, rv);
}
return rv;
} private static Hash_adp_bry factory = Hash_adp_bry.cs();
}

@ -1,43 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_cfg_itm implements Gfo_invk {
public Xoa_cfg_itm(Xoa_cfg_grp grp, byte[] key) {this.grp = grp; this.key = key;}
public Xoa_cfg_grp Grp() {return grp;} private final Xoa_cfg_grp grp;
public byte[] Key() {return key;} private final byte[] key;
public String Val() {return val;} private String val;
public boolean Val_is_dirty() {return val_is_dirty;} private boolean val_is_dirty;
public boolean Val_is_customized() {return val_is_customized;} private boolean val_is_customized; // false if value is system default; true if changed by user
public void Val_(String v) {
this.val = v;
if (grp.Notify(this)) {
val_is_customized = true;
val_is_dirty = true;
}
}
public void Val_load_done() {
val_is_dirty = false;
val_is_customized = true;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_val)) return val;
else if (ctx.Match(k, Invk_val_)) Val_(m.ReadStr("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_val = "val", Invk_val_ = "val_";
}

@ -1,96 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.cfgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.wikis.domains.*;
public class Xoa_cfg_mgr implements Gfo_invk {
private final Ordered_hash hash = Ordered_hash_.New_bry();
public Xoa_cfg_mgr(Xoa_app app) {this.app = app;}
public Xoa_app App() {return app;} private final Xoa_app app;
Xoa_cfg_itm Get_itm_or_make(byte[] grp_key, byte[] itm_key) {
Xoa_cfg_grp grp = null;
Object grp_obj = hash.Get_by(grp_key);
if (grp_obj == null) {
Xoa_cfg_grp_tid tid = Xoa_cfg_grp_tid.parse(itm_key);
grp = new Xoa_cfg_grp(this, tid, grp_key);
hash.Add(grp_key, grp);
}
else
grp = (Xoa_cfg_grp)grp_obj;
return grp.Get_by_or_make(itm_key);
}
public void Set_by_app(String grp_key, String val) {Set(Bry_.new_u8(grp_key), Xoa_cfg_grp_tid.Key_app_bry, val);}
public void Set_by_all(String grp_key, String val) {Set(Bry_.new_u8(grp_key), Xoa_cfg_grp_tid.Key_all_bry, val);}
private void Set(byte[] grp_key, byte[] tid_key, String val) {Get_itm_or_make(grp_key, tid_key).Val_(val);}
public void Init(Xow_wiki wiki) {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Xoa_cfg_grp grp = (Xoa_cfg_grp)hash.Get_at(i);
Xoa_cfg_itm itm = grp.Get_by_wiki(wiki.Domain_bry(), wiki.Domain_tid());
if (itm == null) continue; // grp exists, but not for wiki; EX: rule exists for download.enabled and enwiki, but frwiki loaded
if (itm.Grp().Tid().Tid() == Xoa_cfg_grp_tid.Tid_app) continue; // rule is for app; don't run for wiki init
Eval_set(wiki, grp.Key_str(), itm.Val());
}
}
public boolean Notify(Xoa_cfg_grp grp, Xoa_cfg_itm itm) {
Xoa_cfg_grp_tid grp_tid = grp.Tid();
byte tid_byte = grp_tid.Tid();
switch (tid_byte) {
case Xoa_cfg_grp_tid.Tid_app:
return Eval_set(app, grp.Key_str(), itm.Val());
case Xoa_cfg_grp_tid.Tid_all:
case Xoa_cfg_grp_tid.Tid_type:
boolean all = tid_byte == Xoa_cfg_grp_tid.Tid_all;
int wiki_count = app.Wiki_mgri().Count();
boolean rv = true;
for (int i = 0; i < wiki_count; i++) {
Xow_wiki wiki = app.Wiki_mgri().Get_at(i);
if (all || wiki.Domain_tid() == grp_tid.Wiki_tid()) {
if (!Eval_set(wiki, grp.Key_str(), itm.Val()))
rv = false;
}
}
return rv;
case Xoa_cfg_grp_tid.Tid_wiki: {
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_null(itm.Key());
if (wiki == null) return true; // wiki not installed; return true (no error)
return Eval_set(wiki, grp.Key_str(), itm.Val());
}
default:
throw Err_.new_unhandled(tid_byte);
}
}
public void Db_save_txt() {Db_save(db_txt);} private final Xoa_cfg_db_txt db_txt = new Xoa_cfg_db_txt();
private void Db_save(Xoa_cfg_db db) {
int len = hash.Count();
db.Cfg_save_bgn(this);
for (int i = 0; i < len; i++) {
Xoa_cfg_grp grp = (Xoa_cfg_grp)hash.Get_at(i);
grp.Db_save(db);
}
db.Cfg_save_end(this);
}
private boolean Eval_set(Gfo_invk invk, String key, String val) {
String msg_str = key + "_(<:['\n" + val + "\n']:>);";
Object rslt = app.Gfs_mgr().Run_str_for(invk, msg_str);
return rslt != Gfo_invk_.Rv_error;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_itm_or_make(m.ReadBry("itm_key"), m.ReadBry("grp_key"));
else return Gfo_invk_.Rv_unhandled;
} private static final String Invk_get = "get";
}
Loading…
Cancel
Save