mirror of https://github.com/gnosygnu/xowa
parent
a0dacdcf38
commit
4593483522
@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
public class Xowdir_wiki_cfg_ {
|
||||
public static final String
|
||||
Key__domain = "xowa.wiki.core.domain"
|
||||
, Key__name = "xowa.wiki.core.name"
|
||||
, Key__main_page = "props.main_page"
|
||||
;
|
||||
}
|
@ -1,148 +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.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.sys.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xowdir_wiki_json_ {
|
||||
private static final String Grp__personal = "xowa.personal_wikis", Key__personal__wiki_json = "xowa.personal_wikis.wiki_json";
|
||||
public static void Upsert(Xowe_wiki wiki, String wiki_json) {
|
||||
wiki.Data__core_mgr().Db__core().Tbl__cfg().Upsert_str(Grp__personal, Key__personal__wiki_json, wiki_json);
|
||||
}
|
||||
public static Xowdir_wiki_json Select_or_insert(Io_url core_db_url, Db_conn core_db_conn) {
|
||||
Xowdir_wiki_json rv = null;
|
||||
|
||||
// read from core_db.xowa_cfg
|
||||
Db_cfg_tbl core_cfg_tbl = new Db_cfg_tbl(core_db_conn, Xowd_cfg_tbl_.Tbl_name);
|
||||
String wiki_json_str = core_cfg_tbl.Select_str_or(Grp__personal, Key__personal__wiki_json, null);
|
||||
|
||||
// if not in core_db.xowa_cfg
|
||||
if (wiki_json_str == null) {
|
||||
// infer new based on url and other cfg_itms
|
||||
rv = Infer_new(core_db_url, core_cfg_tbl);
|
||||
core_cfg_tbl.Insert_str(Grp__personal, Key__personal__wiki_json, rv.To_str(new Json_wtr()));
|
||||
}
|
||||
else {
|
||||
rv = Xowdir_wiki_json.New_by_json(new Json_parser(), wiki_json_str);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
// public static Xowdir_wiki_json Verify2(Xoae_app app, boolean mode_is_import, String domain_str, Io_url core_db_url, Db_conn core_db_conn) {
|
||||
// Xowdir_wiki_json rv = null;
|
||||
// boolean dirty = false;
|
||||
//
|
||||
// // read from core_db.xowa_cfg
|
||||
// Db_cfg_tbl core_cfg_tbl = new Db_cfg_tbl(core_db_conn, Xowd_cfg_tbl_.Tbl_name);
|
||||
// String wiki_cfg_str = core_cfg_tbl.Select_str_or(Grp__personal, Key__personal__wiki_json, null);
|
||||
//
|
||||
// // not in core_db; check user_db.user_wiki
|
||||
// if (wiki_cfg_str == null) {
|
||||
// Gfo_usr_dlg_.Instance.Warn_many("", "", "wiki_json not found in core_db; url=~{0}", core_db_url);
|
||||
// dirty = true;
|
||||
// if (!mode_is_import) {
|
||||
// Xowdir_db_mgr user_db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
// Xowdir_wiki_itm user_wiki_row = user_db_mgr.Tbl__wiki().Select_by_key_or_null(domain_str);
|
||||
// if (user_wiki_row != null) {
|
||||
// rv = user_wiki_row.Json();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// rv = Xowdir_wiki_json.New_by_json(new Json_parser(), wiki_cfg_str);
|
||||
// }
|
||||
//
|
||||
// // not in core_db or user_db; infer
|
||||
// if (rv == null) {
|
||||
// Gfo_usr_dlg_.Instance.Warn_many("", "", "wiki_json not found in core_db or user_db; url=~{0}", core_db_url);
|
||||
// dirty = true;
|
||||
// rv = Infer_new(core_db_url, core_cfg_tbl);
|
||||
// }
|
||||
//
|
||||
// // check domain exists
|
||||
// if (String_.Eq(rv.Domain(), String_.Empty)) {
|
||||
// Gfo_usr_dlg_.Instance.Warn_many("", "", "wiki_json does not have domain; url=~{0}", core_db_url);
|
||||
// dirty = true;
|
||||
// rv.Domain_(core_cfg_tbl.Select_str_or(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__domain, core_db_url.NameOnly()));
|
||||
// }
|
||||
//
|
||||
// // something changed; save it
|
||||
// if (dirty) {
|
||||
// String wiki_json_str = rv.To_str(new gplx.langs.jsons.Json_wtr());
|
||||
// core_cfg_tbl.Update_str(Grp__personal, Key__personal__wiki_json, wiki_json_str);
|
||||
// Xowdir_db_mgr user_db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
//
|
||||
// if (!mode_is_import) {
|
||||
// Xowdir_wiki_itm user_wiki_row = user_db_mgr.Tbl__wiki().Select_by_key_or_null(domain_str);
|
||||
// user_db_mgr.Tbl__wiki().Upsert(user_wiki_row.Id(), user_wiki_row.Domain(), user_wiki_row.Url(), wiki_json_str);
|
||||
// }
|
||||
// }
|
||||
// return rv;
|
||||
// }
|
||||
public static void Verify(Xoae_app app, byte[] domain_bry, Io_url core_db_url, Db_conn core_db_conn) {
|
||||
String domain_str = String_.new_u8(domain_bry);
|
||||
boolean dirty = false;
|
||||
|
||||
// read from core_db.xowa_cfg
|
||||
Db_cfg_tbl core_cfg_tbl = new Db_cfg_tbl(core_db_conn, Xowd_cfg_tbl_.Tbl_name);
|
||||
String wiki_cfg_str = core_cfg_tbl.Select_str_or(Grp__personal, Key__personal__wiki_json, null);
|
||||
|
||||
// not in core_db; check user_db.user_wiki
|
||||
Xowdir_wiki_json wiki_json_itm = null;
|
||||
if (wiki_cfg_str == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "wiki_json not found in core_db; url=~{0}", core_db_url);
|
||||
dirty = true;
|
||||
Xowdir_db_mgr user_db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
Xowdir_wiki_itm user_wiki_row = user_db_mgr.Tbl__wiki().Select_by_key_or_null(domain_str);
|
||||
if (user_wiki_row != null) {
|
||||
wiki_json_itm = user_wiki_row.Json();
|
||||
}
|
||||
}
|
||||
else {
|
||||
wiki_json_itm = Xowdir_wiki_json.New_by_json(new Json_parser(), wiki_cfg_str);
|
||||
}
|
||||
|
||||
// not in core_db or user_db; infer
|
||||
if (wiki_json_itm == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "wiki_json not found in core_db or user_db; url=~{0}", core_db_url);
|
||||
dirty = true;
|
||||
wiki_json_itm = Infer_new(core_db_url, core_cfg_tbl);
|
||||
}
|
||||
|
||||
// check domain exists
|
||||
if (String_.Eq(wiki_json_itm.Domain(), String_.Empty)) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "wiki_json does not have domain; url=~{0}", core_db_url);
|
||||
dirty = true;
|
||||
wiki_json_itm.Domain_(core_cfg_tbl.Select_str_or(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__domain, core_db_url.NameOnly()));
|
||||
}
|
||||
|
||||
// something changed; save it
|
||||
if (dirty) {
|
||||
Xowdir_db_mgr user_db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
Xowdir_wiki_itm user_wiki_row = user_db_mgr.Tbl__wiki().Select_by_key_or_null(domain_str);
|
||||
|
||||
String wiki_json_str = wiki_json_itm.To_str(new gplx.langs.jsons.Json_wtr());
|
||||
core_cfg_tbl.Update_str(Grp__personal, Key__personal__wiki_json, wiki_json_str);
|
||||
user_db_mgr.Tbl__wiki().Upsert(user_wiki_row.Id(), user_wiki_row.Domain(), user_wiki_row.Url(), wiki_json_str);
|
||||
}
|
||||
}
|
||||
private static Xowdir_wiki_json Infer_new(Io_url core_db_url, Db_cfg_tbl core_cfg_tbl) {
|
||||
String domain = core_cfg_tbl.Select_str_or(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__domain, core_db_url.NameOnly());
|
||||
String main_page = core_cfg_tbl.Select_str_or(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, Xoa_page_.Main_page_str);
|
||||
return new Xowdir_wiki_json(domain, domain, main_page);
|
||||
}
|
||||
}
|
@ -1,108 +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.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public interface Xowdir_wiki_json_mgr {
|
||||
void Wiki_cfg__upsert(String key, String val);
|
||||
String Wiki_cfg__select_or(String key, String or);
|
||||
void User_reg__upsert(String domain, String val);
|
||||
String User_reg__select(String domain);
|
||||
boolean Dirty();
|
||||
Xowdir_wiki_json Verify(boolean mode_is_import, String domain_str, Io_url core_db_url);
|
||||
}
|
||||
class Xowdir_wiki_cfg_ {
|
||||
public static final String
|
||||
Key__wiki_json = "wiki_json"
|
||||
, Key__domain = "props.domain"
|
||||
, Key__main_page = "props.main_page"
|
||||
;
|
||||
}
|
||||
abstract class Xowdir_wiki_json_mgr__base implements Xowdir_wiki_json_mgr {
|
||||
private final Gfo_usr_dlg usr_dlg;
|
||||
public Xowdir_wiki_json_mgr__base(Gfo_usr_dlg usr_dlg) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
}
|
||||
public abstract void Wiki_cfg__upsert(String key, String val);
|
||||
public abstract String Wiki_cfg__select_or(String key, String or);
|
||||
public abstract void User_reg__upsert(String domain, String val);
|
||||
public abstract String User_reg__select(String domain);
|
||||
public boolean Dirty() {return dirty;} private boolean dirty;
|
||||
public Xowdir_wiki_json Verify(boolean mode_is_import, String domain_str, Io_url core_db_url) {
|
||||
Xowdir_wiki_json rv = null;
|
||||
dirty = false;
|
||||
|
||||
// read from core_db.xowa_cfg
|
||||
String wiki_json_str = Wiki_cfg__select_or(Xowdir_wiki_cfg_.Key__wiki_json, null);
|
||||
|
||||
// not in core_db; check user_db.user_wiki
|
||||
if (wiki_json_str == null) {
|
||||
usr_dlg.Warn_many("", "", "wiki_json not found in core_db; url=~{0}", core_db_url);
|
||||
dirty = true;
|
||||
if (!mode_is_import) {
|
||||
wiki_json_str = User_reg__select(domain_str);
|
||||
}
|
||||
}
|
||||
|
||||
if (wiki_json_str != null) {
|
||||
rv = Xowdir_wiki_json.New_by_json(new Json_parser(), wiki_json_str);
|
||||
}
|
||||
|
||||
// not in core_db or user_db; infer
|
||||
if (rv == null) {
|
||||
usr_dlg.Warn_many("", "", "wiki_json not found in core_db or user_db; url=~{0}", core_db_url);
|
||||
dirty = true;
|
||||
rv = Infer_new(core_db_url);
|
||||
}
|
||||
|
||||
// check domain exists
|
||||
if (String_.Eq(rv.Domain(), String_.Empty)) {
|
||||
usr_dlg.Warn_many("", "", "wiki_json does not have domain; url=~{0}", core_db_url);
|
||||
dirty = true;
|
||||
String domain = Wiki_cfg__select_or(Xowdir_wiki_cfg_.Key__domain, core_db_url.NameOnly());
|
||||
rv.Domain_(domain);
|
||||
}
|
||||
|
||||
// something changed; save it
|
||||
if (dirty) {
|
||||
wiki_json_str = rv.To_str(new gplx.langs.jsons.Json_wtr());
|
||||
Wiki_cfg__upsert(Xowdir_wiki_cfg_.Key__wiki_json, wiki_json_str);
|
||||
|
||||
if (!mode_is_import) {
|
||||
User_reg__upsert(domain_str, wiki_json_str);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private Xowdir_wiki_json Infer_new(Io_url core_db_url) {
|
||||
String domain = this.Wiki_cfg__select_or(Xowdir_wiki_cfg_.Key__domain, core_db_url.NameOnly());
|
||||
String main_page = this.Wiki_cfg__select_or(Xowdir_wiki_cfg_.Key__main_page, Xoa_page_.Main_page_str);
|
||||
return new Xowdir_wiki_json(domain, domain, main_page);
|
||||
}
|
||||
}
|
||||
class Xowdir_wiki_json_mgr__mock extends Xowdir_wiki_json_mgr__base {
|
||||
private final Hash_adp wiki_cfg_hash = Hash_adp_.New();
|
||||
private final Hash_adp user_reg_hash = Hash_adp_.New();
|
||||
public Xowdir_wiki_json_mgr__mock() {super(Gfo_usr_dlg_.Noop);}
|
||||
@Override public void Wiki_cfg__upsert(String key, String val) {wiki_cfg_hash.Add_if_dupe_use_nth(key, val);}
|
||||
@Override public void User_reg__upsert(String domain, String val) {user_reg_hash.Add_if_dupe_use_nth(domain, val);}
|
||||
@Override public String User_reg__select(String domain) {return (String)user_reg_hash.Get_by(domain);}
|
||||
@Override public String Wiki_cfg__select_or(String key, String or) {
|
||||
String rv = (String)wiki_cfg_hash.Get_by(key);
|
||||
return rv == null ? or : rv;
|
||||
}
|
||||
}
|
@ -1,72 +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.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xowdir_wiki_json_mgr__tst {
|
||||
private final Xowdir_wiki_json_mgr__fxt fxt = new Xowdir_wiki_json_mgr__fxt();
|
||||
|
||||
@Test public void Import__wiki__missing_all() {
|
||||
// handle all imported .xowa wikis pre v4.3
|
||||
fxt.Init__wiki_cfg__json(null);
|
||||
|
||||
Xowdir_wiki_json expd = fxt.Make__json("test", "test", "Main_Page");
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, expd);
|
||||
fxt.Test__wiki_cfg(expd);
|
||||
}
|
||||
@Test public void Import__wiki__missing_domain() {
|
||||
// handle personal wikis from v4.2
|
||||
fxt.Init__wiki_cfg__json(fxt.Make__json(null, "test", "Main_Page"));
|
||||
|
||||
Xowdir_wiki_json expd = fxt.Make__json("test", "test", "Main_Page");
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, expd);
|
||||
fxt.Test__wiki_cfg(expd);
|
||||
}
|
||||
@Test public void Import__wiki__clean() {
|
||||
// handle clean wiki
|
||||
fxt.Init__wiki_cfg__json(fxt.Make__json("test", "test", "Main_Page"));
|
||||
|
||||
Xowdir_wiki_json expd = fxt.Make__json("test", "test", "Main_Page");
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.N, expd);
|
||||
fxt.Test__wiki_cfg(expd);
|
||||
}
|
||||
}
|
||||
class Xowdir_wiki_json_mgr__fxt {
|
||||
private final Xowdir_wiki_json_mgr mgr = new Xowdir_wiki_json_mgr__mock();
|
||||
private final Json_wtr json_wtr = new Json_wtr();
|
||||
public Xowdir_wiki_json Make__json(String domain, String name, String main_page) {
|
||||
return new Xowdir_wiki_json(domain, name, main_page);
|
||||
}
|
||||
public void Init__wiki_cfg__json(Xowdir_wiki_json itm) {
|
||||
if (itm != null)
|
||||
mgr.Wiki_cfg__upsert(Xowdir_wiki_cfg_.Key__wiki_json, itm.To_str(json_wtr));
|
||||
}
|
||||
public void Test__verify(boolean mode_is_import, String url, boolean expd_dirty, Xowdir_wiki_json expd) {
|
||||
Xowdir_wiki_json actl = mgr.Verify(mode_is_import, "", Io_url_.new_any_(url));
|
||||
|
||||
String expd_str = expd.To_str(json_wtr);
|
||||
String actl_str = actl.To_str(json_wtr);
|
||||
Gftest.Eq__ary__lines(expd_str, actl_str, "expd");
|
||||
Gftest.Eq__bool(expd_dirty, mgr.Dirty(), "dirty");
|
||||
}
|
||||
public void Test__wiki_cfg(Xowdir_wiki_json expd) {
|
||||
String expd_str = expd.To_str(json_wtr);
|
||||
Gftest.Eq__ary__lines(expd_str, mgr.Wiki_cfg__select_or(Xowdir_wiki_cfg_.Key__wiki_json, null), "wiki_cfg");
|
||||
}
|
||||
// Gftest.Eq__ary__lines(expd_str, mgr.User_reg__select(actl.Domain()), "user_reg");
|
||||
}
|
@ -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.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
public class Xowdir_wiki_props {
|
||||
public Xowdir_wiki_props() {}
|
||||
public Xowdir_wiki_props(String domain, String name, String main_page) {
|
||||
this.domain = domain;
|
||||
this.name = name;
|
||||
this.main_page = main_page;
|
||||
}
|
||||
public boolean Dirty() {return dirty;} private boolean dirty;
|
||||
public String Domain() {return domain;} private String domain;
|
||||
public String Name() {return name;} private String name;
|
||||
public String Main_page() {return main_page;} private String main_page;
|
||||
|
||||
public void Dirty_y_() {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public void Set(String key, String val) {
|
||||
if (String_.Eq(key, Xowdir_wiki_cfg_.Key__domain)) this.domain = val;
|
||||
else if (String_.Eq(key, Xowdir_wiki_cfg_.Key__name)) this.name = val;
|
||||
else if (String_.Eq(key, Xowdir_wiki_cfg_.Key__main_page)) this.main_page = val;
|
||||
else throw Err_.new_unhandled_default(key);
|
||||
}
|
||||
|
||||
public String To_str() {return String_.Concat(domain, "|", name, "|", main_page );}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public interface Xowdir_wiki_props_mgr {
|
||||
void Wiki_cfg__upsert(String key, String val);
|
||||
String Wiki_cfg__select_or(String key, String or);
|
||||
void User_reg__upsert(String domain, String val);
|
||||
String User_reg__select(String domain);
|
||||
Xowdir_wiki_props Verify(boolean mode_is_import, String domain_str, Io_url core_db_url);
|
||||
}
|
||||
abstract class Xowdir_wiki_props_mgr__base implements Xowdir_wiki_props_mgr {
|
||||
private final Gfo_usr_dlg usr_dlg;
|
||||
public Xowdir_wiki_props_mgr__base(Gfo_usr_dlg usr_dlg) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
}
|
||||
public abstract void Wiki_cfg__upsert(String key, String val);
|
||||
public abstract String Wiki_cfg__select_or(String key, String or);
|
||||
public abstract void User_reg__upsert(String domain, String val);
|
||||
public abstract String User_reg__select(String domain);
|
||||
public Xowdir_wiki_props Verify(boolean mode_is_import, String domain_str, Io_url core_db_url) {
|
||||
Xowdir_wiki_props rv = new Xowdir_wiki_props();
|
||||
|
||||
Verify_or_fix(rv, core_db_url, Xowdir_wiki_cfg_.Key__domain);
|
||||
Verify_or_fix(rv, core_db_url, Xowdir_wiki_cfg_.Key__main_page);
|
||||
Verify_or_fix(rv, core_db_url, Xowdir_wiki_cfg_.Key__name);
|
||||
|
||||
return rv;
|
||||
}
|
||||
private String Verify_or_fix(Xowdir_wiki_props props, Io_url core_db_url, String key) {
|
||||
String val = Wiki_cfg__select_or(key, null);
|
||||
if (val == null) {
|
||||
props.Dirty_y_();
|
||||
usr_dlg.Warn_many("", "", "xowdir: core_db.xowa_cfg does not have val; url=~{0} key=~{1}", core_db_url, key);
|
||||
val = Fix(props, core_db_url, key);
|
||||
Wiki_cfg__upsert(key, val);
|
||||
}
|
||||
props.Set(key, val);
|
||||
return val;
|
||||
}
|
||||
private static String Fix(Xowdir_wiki_props props, Io_url core_db_url, String key) {
|
||||
if (String_.Eq(key, Xowdir_wiki_cfg_.Key__domain)) {
|
||||
String rv = core_db_url.NameOnly();
|
||||
if (String_.Has_at_end(rv, "-core"))
|
||||
rv = String_.Mid(rv, 0, String_.Len(rv) - 5);
|
||||
return rv;
|
||||
}
|
||||
else if (String_.Eq(key, Xowdir_wiki_cfg_.Key__name)) {
|
||||
return props.Domain(); // NOTE: must be called after domain
|
||||
}
|
||||
else if (String_.Eq(key, Xowdir_wiki_cfg_.Key__main_page)) {
|
||||
return Xoa_page_.Main_page_str;
|
||||
}
|
||||
else throw Err_.new_unhandled_default(key);
|
||||
}
|
||||
}
|
||||
class Xowdir_wiki_props_mgr__mock extends Xowdir_wiki_props_mgr__base {
|
||||
private final Hash_adp wiki_cfg_hash = Hash_adp_.New();
|
||||
private final Hash_adp user_reg_hash = Hash_adp_.New();
|
||||
public Xowdir_wiki_props_mgr__mock() {super(Gfo_usr_dlg_.Noop);}
|
||||
@Override public void Wiki_cfg__upsert(String key, String val) {
|
||||
if (val != null)
|
||||
wiki_cfg_hash.Add_if_dupe_use_nth(key, val);
|
||||
}
|
||||
@Override public String Wiki_cfg__select_or(String key, String or) {
|
||||
String rv = (String)wiki_cfg_hash.Get_by(key);
|
||||
return rv == null ? or : rv;
|
||||
}
|
||||
@Override public void User_reg__upsert(String domain, String val) {user_reg_hash.Add_if_dupe_use_nth(domain, val);}
|
||||
@Override public String User_reg__select(String domain) {return (String)user_reg_hash.Get_by(domain);}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.directorys.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.directorys.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xowdir_wiki_props_mgr__tst {
|
||||
private final Xowdir_wiki_props_mgr__fxt fxt = new Xowdir_wiki_props_mgr__fxt();
|
||||
|
||||
@Test public void Import__wiki__missing_all() {
|
||||
// handle all imported .xowa wikis pre v4.3
|
||||
fxt.Init__props(null, null, null);
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
|
||||
}
|
||||
@Test public void Import__wiki__missing_domain() {
|
||||
// handle personal wikis from v4.2
|
||||
fxt.Init__props(null, null, "Main_Page");
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
|
||||
}
|
||||
@Test public void Import__wiki__wmf_domain() {
|
||||
// handle wmf wikis with a core-file of "test-core.xowa"
|
||||
fxt.Init__props(null, null, "Main_Page");
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test-core.xowa", Bool_.Y, fxt.Make__json("test", "test", "Main_Page"));
|
||||
}
|
||||
@Test public void Import__wiki__clean() {
|
||||
// handle clean wiki
|
||||
fxt.Init__props("test", "test", "Main_Page");
|
||||
fxt.Test__verify(Bool_.Y, "/dir/test.xowa", Bool_.N, fxt.Make__json("test", "test", "Main_Page"));
|
||||
}
|
||||
}
|
||||
class Xowdir_wiki_props_mgr__fxt {
|
||||
private final Xowdir_wiki_props_mgr mgr = new Xowdir_wiki_props_mgr__mock();
|
||||
public Xowdir_wiki_props Make__json(String domain, String name, String main_page) {
|
||||
return new Xowdir_wiki_props(domain, name, main_page);
|
||||
}
|
||||
public void Init__props(String domain, String name, String main_page) {
|
||||
mgr.Wiki_cfg__upsert(Xowdir_wiki_cfg_.Key__domain, domain);
|
||||
mgr.Wiki_cfg__upsert(Xowdir_wiki_cfg_.Key__name, name);
|
||||
mgr.Wiki_cfg__upsert(Xowdir_wiki_cfg_.Key__main_page, main_page);
|
||||
}
|
||||
public void Test__verify(boolean mode_is_import, String url, boolean expd_dirty, Xowdir_wiki_props expd) {
|
||||
Xowdir_wiki_props actl = mgr.Verify(mode_is_import, "", Io_url_.new_any_(url));
|
||||
|
||||
Gftest.Eq__ary__lines(expd.To_str(), actl.To_str(), "expd");
|
||||
Gftest.Eq__bool(expd_dirty, actl.Dirty(), "dirty");
|
||||
}
|
||||
}
|
Loading…
Reference in new issue