mirror of https://github.com/gnosygnu/xowa
parent
9dfbd472ac
commit
fd79415b53
@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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));
|
||||
}
|
||||
}
|
@ -1,53 +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.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.dbs.utls.*;
|
||||
public class Xocfg_db_mgr {
|
||||
public Xocfg_db_mgr(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl__grp_meta = new Xogrp_meta_tbl(conn);
|
||||
this.tbl__grp_map = new Xogrp_map_tbl(conn);
|
||||
this.tbl__itm_meta = new Xoitm_meta_tbl(conn);
|
||||
this.tbl__itm_data = new Xoitm_data_tbl(conn);
|
||||
this.tbl__nde_i18n = new Xonde_i18n_tbl(conn);
|
||||
conn.Meta_tbl_assert(tbl__grp_meta, tbl__grp_map, tbl__itm_meta, tbl__itm_data, tbl__nde_i18n);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Xogrp_meta_tbl Tbl__grp_meta() {return tbl__grp_meta;} private final Xogrp_meta_tbl tbl__grp_meta;
|
||||
public Xogrp_map_tbl Tbl__grp_map() {return tbl__grp_map ;} private final Xogrp_map_tbl tbl__grp_map;
|
||||
public Xoitm_meta_tbl Tbl__itm_meta() {return tbl__itm_meta;} private final Xoitm_meta_tbl tbl__itm_meta;
|
||||
public Xoitm_data_tbl Tbl__itm_data() {return tbl__itm_data;} private final Xoitm_data_tbl tbl__itm_data;
|
||||
public Xonde_i18n_tbl Tbl__nde_i18n() {return tbl__nde_i18n;} private final Xonde_i18n_tbl tbl__nde_i18n;
|
||||
|
||||
public String Get_str(String ctx, String key) {
|
||||
Xoitm_meta_itm meta_itm = tbl__itm_meta.Select_by_key_or_null(key);
|
||||
if (meta_itm == null) throw Err_.new_wo_type("cfg not defined", "ctx", ctx, "key", key);
|
||||
Xoitm_data_itm data_itm = tbl__itm_data.Select_one_by_id_or_null(meta_itm.Id(), ctx);
|
||||
return data_itm == null ? meta_itm.Dflt() : data_itm.Val();
|
||||
}
|
||||
public void Set_str(String ctx, String key, String val) {
|
||||
Xoitm_meta_itm meta_itm = tbl__itm_meta.Select_by_key_or_null(key);
|
||||
if (meta_itm == null) throw Err_.new_wo_type("cfg not defined", "ctx", ctx, "key", key);
|
||||
tbl__itm_data.Upsert(meta_itm.Id(), ctx, val, Datetime_now.Get().XtoUtc().XtoStr_fmt_iso_8561());
|
||||
}
|
||||
public void Del(String ctx, String key) {
|
||||
Xoitm_meta_itm meta_itm = tbl__itm_meta.Select_by_key_or_null(key);
|
||||
if (meta_itm == null) throw Err_.new_wo_type("cfg not defined", "ctx", ctx, "key", key);
|
||||
tbl__itm_data.Delete(meta_itm.Id(), ctx);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
}
|
||||
}
|
@ -1,53 +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.addons.apps.cfgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
public class Xocfg_itm_bldr {
|
||||
private final Xocfg_db_mgr db_mgr;
|
||||
private final String Lang__dflt = "en";
|
||||
public Xocfg_itm_bldr(Xocfg_db_mgr db_mgr) {
|
||||
this.db_mgr = db_mgr;
|
||||
}
|
||||
public void Create_grp(String owner_key, String grp_key, String grp_name, String grp_help) {
|
||||
// insert grp_meta
|
||||
int grp_id = db_mgr.Conn().Sys_mgr().Autonum_next("cfg_grp_meta.grp_id");
|
||||
db_mgr.Tbl__grp_meta().Upsert(grp_id, grp_key);
|
||||
|
||||
// insert grp_map
|
||||
int owner_id = String_.Len_eq_0(owner_key) ? Xogrp_meta_itm.Id__root : db_mgr.Tbl__grp_meta().Select_id_by_key_or_fail(owner_key);
|
||||
int map_sort = db_mgr.Tbl__grp_map().Select_next_sort(owner_id);
|
||||
db_mgr.Tbl__grp_map().Upsert(owner_id, grp_id, map_sort);
|
||||
|
||||
// insert nde_i18n
|
||||
db_mgr.Tbl__nde_i18n().Upsert(grp_id, Lang__dflt, grp_name, grp_help);
|
||||
}
|
||||
public void Create_itm(String grp_key, String itm_key, String scope_id_str, int db_type_id, String gui_type, String gui_args, String itm_dflt, String itm_name, String help) {
|
||||
// insert itm_meta
|
||||
int grp_id = db_mgr.Tbl__grp_meta().Select_id_by_key_or_fail(grp_key);
|
||||
int itm_id = db_mgr.Conn().Sys_mgr().Autonum_next("cfg_itm_meta.itm_id");
|
||||
int scope_id = Xoitm_scope_tid.To_int(scope_id_str);
|
||||
int gui_type_id = Xoitm_gui_tid.To_tid(gui_type);
|
||||
db_mgr.Tbl__itm_meta().Upsert(itm_id, scope_id, db_type_id, gui_type_id, gui_args, itm_key, itm_dflt);
|
||||
|
||||
// insert grp_map
|
||||
int itm_sort = db_mgr.Tbl__grp_map().Select_next_sort(grp_id);
|
||||
db_mgr.Tbl__grp_map().Upsert(grp_id, itm_id, itm_sort);
|
||||
|
||||
// insert nde_i18n
|
||||
db_mgr.Tbl__nde_i18n().Upsert(itm_id, Lang__dflt, itm_name, help);
|
||||
}
|
||||
}
|
@ -1,34 +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.addons.apps.cfgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
public class Xoitm_gui_tid { // SERIALIZED
|
||||
public static final int Tid__checkbox = 1, Tid__numeric = 2, Tid__select = 3, Tid__textbox = 4, Tid__fs_file = 5, Tid__fs_dir = 6, Tid__memo = 7, Tid__button = 8, Tid__label = 9;
|
||||
|
||||
public static int To_tid(String str) {
|
||||
if (String_.Eq(str, "checkbox")) return Tid__checkbox;
|
||||
else if (String_.Eq(str, "numeric")) return Tid__numeric;
|
||||
else if (String_.Eq(str, "select")) return Tid__select;
|
||||
else if (String_.Eq(str, "textbox")) return Tid__textbox;
|
||||
else if (String_.Eq(str, "fs_file")) return Tid__fs_file;
|
||||
else if (String_.Eq(str, "fs_dir")) return Tid__fs_dir;
|
||||
else if (String_.Eq(str, "memo")) return Tid__memo;
|
||||
else if (String_.Eq(str, "button")) return Tid__button;
|
||||
else if (String_.Eq(str, "label")) return Tid__label;
|
||||
else throw Err_.new_unhandled_default(str);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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_db_tid {
|
||||
public static final int Tid__bool = 1, Tid__int = 2, Tid__str = 3, Tid__memo = 4;
|
||||
public static int To_int(String s) {
|
||||
if (String_.Eq(s, "bool")) return Tid__bool;
|
||||
else if (String_.Eq(s, "int")) return Tid__int;
|
||||
else if (String_.Eq(s, "string")) return Tid__str;
|
||||
else if (String_.Eq(s, "memo")) return Tid__memo;
|
||||
else return Tid__str;
|
||||
// else throw Err_.new_wo_type("xo.cfg_maint:unknown db_type", "db_type", s);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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_gui_tid { // SERIALIZED
|
||||
public static final int Tid__checkbox = 1, Tid__numeric = 2, Tid__select = 3, Tid__textbox = 4, Tid__fs_file = 5, Tid__fs_dir = 6, Tid__memo = 7, Tid__button = 8, Tid__label = 9;
|
||||
public static final String
|
||||
Str__checkbox = "checkbox"
|
||||
, Str__numeric = "numeric"
|
||||
, Str__select = "select"
|
||||
, Str__textbox = "textbox"
|
||||
, Str__fs_file = "fs_file"
|
||||
, Str__fs_dir = "fs_dir"
|
||||
, Str__memo = "memo"
|
||||
, Str__button = "button"
|
||||
, Str__label = "label"
|
||||
;
|
||||
|
||||
public static int To_tid(String str) {
|
||||
if (String_.Eq(str, Str__checkbox)) return Tid__checkbox;
|
||||
else if (String_.Eq(str, Str__numeric)) return Tid__numeric;
|
||||
else if (String_.Eq(str, Str__select)) return Tid__select;
|
||||
else if (String_.Eq(str, Str__textbox)) return Tid__textbox;
|
||||
else if (String_.Eq(str, Str__fs_file)) return Tid__fs_file;
|
||||
else if (String_.Eq(str, Str__fs_dir)) return Tid__fs_dir;
|
||||
else if (String_.Eq(str, Str__memo)) return Tid__memo;
|
||||
else if (String_.Eq(str, Str__button)) return Tid__button;
|
||||
else if (String_.Eq(str, Str__label)) return Tid__label;
|
||||
else throw Err_.new_unhandled_default(str);
|
||||
}
|
||||
public static String Infer_gui_type(String db_type) {
|
||||
if (String_.Eq(db_type, "bool"))
|
||||
return Xoitm_gui_tid.Str__checkbox;
|
||||
else if (String_.Eq(db_type, "memo"))
|
||||
return Xoitm_gui_tid.Str__memo;
|
||||
else
|
||||
return Xoitm_gui_tid.Str__textbox;
|
||||
}
|
||||
}
|
@ -1,95 +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.addons.apps.cfgs.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.cfgs.*;
|
||||
class Xogui_nde_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final List_adp deleted = List_adp_.New();
|
||||
public int Len() {
|
||||
return hash.Len();
|
||||
}
|
||||
public void Add(Xogui_nde nde) {
|
||||
hash.Add(nde.Id(), nde);
|
||||
}
|
||||
public Xogui_nde Get_at(int i) {
|
||||
return (Xogui_nde)hash.Get_at(i);
|
||||
}
|
||||
public Xogui_nde Get_by_or_fail(int id) {
|
||||
return (Xogui_nde)hash.Get_by_or_fail(id);
|
||||
}
|
||||
public Xogui_grp[] To_grp_ary_and_clear() {
|
||||
return (Xogui_grp[])hash.To_ary_and_clear(Xogui_grp.class);
|
||||
}
|
||||
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++) {
|
||||
Xogui_grp grp = (Xogui_grp)hash.Get_at(i);
|
||||
if (grp.Itms().length == 0)
|
||||
deleted.Add(grp);
|
||||
}
|
||||
|
||||
len = deleted.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xogui_grp grp = (Xogui_grp)deleted.Get_at(i);
|
||||
hash.Del(grp.Id());
|
||||
}
|
||||
}
|
||||
|
||||
public Xogui_nde_hash Merge(Xogui_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(Xogui_nde nde) {
|
||||
deleted.Add(nde);
|
||||
}
|
||||
public void Deleted__commit() {
|
||||
int len = deleted.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xogui_nde nde = (Xogui_nde)deleted.Get_at(i);
|
||||
hash.Del(nde.Id());
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xogui_nde_iter {
|
||||
private final Xogui_nde_hash hash;
|
||||
private int bgn, max;
|
||||
public Xogui_nde_iter(Xogui_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++) {
|
||||
Xogui_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 static Xogui_nde_iter New_sql(Xogui_nde_hash hash) {
|
||||
return new Xogui_nde_iter(hash, 255);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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();
|
||||
void Load_by_i18n(String lang, String name, String help);
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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 key, String owner, String name, String help) {
|
||||
this.key = key;
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
}
|
||||
public abstract boolean Type_is_grp();
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Owner() {return owner;} private final String owner;
|
||||
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}", this.Type_is_grp(), key, owner, 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 key, String owner, String name, String help) {super(key, owner, 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 key, String owner, String name, String help, String scope, String db_type, String dflt, String gui_type, String gui_args) {super(key, owner, name, help);
|
||||
this.scope = scope;
|
||||
this.db_type = db_type;
|
||||
this.dflt = dflt;
|
||||
this.gui_type = gui_type;
|
||||
this.gui_args = gui_args;
|
||||
}
|
||||
@Override public boolean Type_is_grp() {return false;}
|
||||
public String Scope() {return scope;} private final String scope;
|
||||
public String Db_type() {return db_type;} private final String db_type;
|
||||
public String Dflt() {return dflt;} private final String dflt;
|
||||
public String Gui_type() {return gui_type;} private final String gui_type;
|
||||
public String Gui_args() {return gui_args;} private final String gui_args;
|
||||
@Override protected void To_bfr_hook(Bry_bfr bfr) {
|
||||
bfr.Add_str_u8_fmt("|{0}|{1}|{2}|{3}|{4}", scope, db_type, dflt, gui_type, gui_args);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
root = root.Subs_getAt(0); // NOTE: ignore fake root
|
||||
|
||||
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
|
||||
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(key, owner, name, help);
|
||||
}
|
||||
else if (String_.Eq(nde_type, "itm")) {
|
||||
String scope = Get_atr_as_str_or_fail(hash, "scope_");
|
||||
String db_type = Get_atr_as_str_or_fail(hash, "db_type_");
|
||||
String dflt = Get_atr_as_str_or_fail(hash, "dflt_");
|
||||
String gui_type = Get_atr_as_str_or(hash, "gui_type_", null);
|
||||
String gui_args = Get_atr_as_str_or(hash, "gui_args_", "");
|
||||
|
||||
if (gui_type == null) {
|
||||
gui_type = gplx.xowa.addons.apps.cfgs.enums.Xoitm_gui_tid.Infer_gui_type(db_type);
|
||||
}
|
||||
return new Xocfg_maint_itm(key, owner, name, help, scope, db_type, dflt, gui_type, gui_args);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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("root {grp {key='key_1'; owner='owner_1'; name='name_1'; help='help_1'}}"
|
||||
, fxt.Make__grp("key_1", "owner_1", "name_1", "help_1")
|
||||
);
|
||||
}
|
||||
@Test public void Parse_itm() {
|
||||
fxt.Exec__parse("root {itm {key='key_1'; owner='owner_1'; name='name_1'; help='help_1'; scope='scope_1'; db_type='db_type_1'; dflt='dflt_1'; gui_type='gui_type_1'; gui_args='gui_args_1'}}"
|
||||
, fxt.Make__itm("key_1", "owner_1", "name_1", "help_1", "scope_1", "db_type_1", "dflt_1", "gui_type_1", "gui_args_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 key, String owner, String name, String help) {
|
||||
return new Xocfg_maint_grp(key, owner, name, help);
|
||||
}
|
||||
public Xocfg_maint_itm Make__itm(String key, String owner, String name, String help, String scope, String db_type, String dflt, String gui_type, String gui_args) {
|
||||
return new Xocfg_maint_itm(key, owner, name, help, scope, db_type, dflt, gui_type, gui_args);
|
||||
}
|
||||
}
|
@ -1,40 +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.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.*;
|
||||
class Xocfg_maint_service {
|
||||
private Xoa_app app;
|
||||
public Xocfg_maint_service(Xoa_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public void Upsert(String data) {
|
||||
Xocfg_itm_bldr itm_bldr = new Xocfg_itm_bldr(new Xocfg_db_mgr(app.User().User_db_mgr().Conn()));
|
||||
String[] lines = String_.Split(data, "\n");
|
||||
for (String line : lines) {
|
||||
String[] ary = String_.Split(line, "|");
|
||||
if (ary.length < 4) continue; // ignore blank lines
|
||||
String type = String_.Trim(ary[0]); // get 1st arg and ignore leading space
|
||||
if (String_.Eq(type, "grp")) {
|
||||
itm_bldr.Create_grp(ary[1], ary[2], ary[3], ary[4]);
|
||||
}
|
||||
else {
|
||||
itm_bldr.Create_itm(ary[1], ary[2], ary[3], Type_adp_.To_tid(ary[4]), ary[5], ary[6], ary[7], ary[8], ary[9]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.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);
|
||||
for (Xocfg_maint_nde nde : ndes) {
|
||||
if (nde.Type_is_grp()) {
|
||||
Xocfg_maint_svc.Create_grp(db_app, nde.Key(), nde.Owner(), nde.Name(), nde.Help());
|
||||
}
|
||||
else {
|
||||
Xocfg_maint_itm itm = (Xocfg_maint_itm)nde;
|
||||
byte[] help = parser_mgr.Main().Parse_text_to_html(parser_mgr.Ctx(), Bry_.new_u8(itm.Help()));
|
||||
Xocfg_maint_svc.Create_itm(db_app, nde.Key(), nde.Owner(), nde.Name(), String_.new_u8(help), itm.Scope(), itm.Db_type(), itm.Dflt(), itm.Gui_type(), itm.Gui_args());
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Create_grp(Xocfg_db_app db_app, String key, String owner, String name, String help) {
|
||||
// insert grp_meta
|
||||
int grp_id = db_app.Conn().Sys_mgr().Autonum_next("cfg_grp_meta.grp_id");
|
||||
db_app.Tbl__grp().Upsert(grp_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_next_sort(owner_id);
|
||||
db_app.Tbl__map().Upsert(owner_id, grp_id, map_sort);
|
||||
|
||||
// insert nde_i18n
|
||||
db_app.Tbl__txt().Upsert(grp_id, Xoitm_lang_tid.Lang__dflt, name, help);
|
||||
}
|
||||
public static void Create_itm(Xocfg_db_app db_app, String key, String owner, String name, String help, String scope, String db_type, String dflt, String gui_type, String gui_args) {
|
||||
// insert itm_meta
|
||||
int grp_id = db_app.Tbl__grp().Select_id_by_key_or_fail(owner);
|
||||
int itm_id = db_app.Conn().Sys_mgr().Autonum_next("cfg_itm_meta.itm_id");
|
||||
int scope_id = Xoitm_scope_tid.To_int(scope);
|
||||
int db_type_id = Xoitm_db_tid.To_int(db_type);
|
||||
int gui_type_id = Xoitm_gui_tid.To_tid(gui_type);
|
||||
db_app.Tbl__itm().Upsert(itm_id, scope_id, db_type_id, gui_type_id, gui_args, key, dflt);
|
||||
|
||||
// insert grp_map
|
||||
int itm_sort = db_app.Tbl__map().Select_next_sort(grp_id);
|
||||
db_app.Tbl__map().Upsert(grp_id, itm_id, itm_sort);
|
||||
|
||||
// insert nde_i18n
|
||||
db_app.Tbl__txt().Upsert(itm_id, Xoitm_lang_tid.Lang__dflt, name, help);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue