mirror of https://github.com/gnosygnu/xowa
parent
b3566def7e
commit
da18f05d9f
@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public class Wbase_prop_mgr { // lang-agnostic registry of props; EX: "p15" -> commonsmedia
|
||||
private boolean init_needed = true;
|
||||
private Ordered_hash hash;
|
||||
public Wbase_prop_mgr(Wbase_prop_mgr_loader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
public Wbase_prop_mgr_loader Loader() {return loader;} private Wbase_prop_mgr_loader loader;
|
||||
public void Loader_(Wbase_prop_mgr_loader v) {
|
||||
loader = v;
|
||||
init_needed = true;
|
||||
}
|
||||
private void Init() {
|
||||
init_needed = false;
|
||||
hash = loader.Load();
|
||||
}
|
||||
public String Get_or_null(String pid) {
|
||||
if (init_needed) Init();
|
||||
if (hash == null) return null;
|
||||
String rv = (String)hash.Get_by(pid);
|
||||
if (rv == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "wbase:could not find datatype for pid; pid=~{0}", pid);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public interface Wbase_prop_mgr_loader {
|
||||
Ordered_hash Load();
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Wbase_prop_mgr_loader_ {
|
||||
public static Wbase_prop_mgr_loader New_mock(Keyval... pairs) {
|
||||
return new Wbase_prop_mgr_loader__mock(pairs);
|
||||
}
|
||||
public static Wbase_prop_mgr_loader New_db(Wdata_wiki_mgr wbase_mgr) {
|
||||
return new Wbase_prop_mgr_loader__db(wbase_mgr);
|
||||
}
|
||||
}
|
||||
class Wbase_prop_mgr_loader__mock implements Wbase_prop_mgr_loader {
|
||||
private final Keyval[] pairs;
|
||||
public Wbase_prop_mgr_loader__mock(Keyval[] pairs) {
|
||||
this.pairs = pairs;
|
||||
}
|
||||
public Ordered_hash Load() {
|
||||
Ordered_hash rv = Ordered_hash_.New();
|
||||
for (Keyval kv : pairs)
|
||||
rv.Add(kv.Key(), kv.Val_to_str_or_empty());
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Wbase_prop_mgr_loader__db implements Wbase_prop_mgr_loader {
|
||||
private final Wdata_wiki_mgr wbase_mgr;
|
||||
public Wbase_prop_mgr_loader__db(Wdata_wiki_mgr wbase_mgr) {
|
||||
this.wbase_mgr = wbase_mgr;
|
||||
}
|
||||
public Ordered_hash Load() {
|
||||
gplx.xowa.wikis.data.Xow_db_file wbase_db = wbase_mgr.Wdata_wiki().Data__core_mgr().Db__wbase();
|
||||
if (!wbase_db.Conn().Meta_tbl_exists(wbase_db.Tbl__wbase_prop().Tbl_name())) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "wbase:prop tbl missing");
|
||||
return null;
|
||||
}
|
||||
return wbase_db.Tbl__wbase_prop().Select_all();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue