1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Wiki: Support renamed folders (fix)

This commit is contained in:
gnosygnu
2017-02-06 22:12:56 -05:00
parent 6f9e92afff
commit 938beac9f9
4379 changed files with 0 additions and 327818 deletions

View File

@@ -1,29 +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.bldrs.wms; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.core.net.*;
public class Xowm_api_mgr {
public static byte[] Call_by_qarg(Gfo_usr_dlg usr_dlg, Gfo_inet_conn inet_conn, String domain_str, String api_args) {return Call_by_url(usr_dlg, inet_conn, domain_str, Bld_api_url(domain_str, api_args));}
public static byte[] Call_by_url (Gfo_usr_dlg usr_dlg, Gfo_inet_conn inet_conn, String domain_str, String url) {
if (!gplx.core.ios.IoEngine_system.Web_access_enabled) return null;
usr_dlg.Prog_many("", "", "wm.api:calling; wiki=~{0} api=~{1}", domain_str, url);
byte[] rslt = inet_conn.Download_as_bytes_or_null(url); if (rslt == null) usr_dlg.Warn_many("", "", "wm.api:wmf api returned nothing; api=~{0}", url);
return rslt;
}
public static String Bld_api_url(String wiki, String args) {return String_.Concat("https://", wiki, "/w/api.php?", args);} // EX: https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces
}

View File

@@ -1,30 +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.bldrs.wms; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
import gplx.core.net.*;
import gplx.xowa.apps.wms.apis.*; import gplx.xowa.files.downloads.*;
public class Xowmf_mgr {
public Xowmf_mgr() {
download_wkr.Download_xrg().User_agent_(Xoa_app_.User_agent);
}
public void Init_by_app(Xoa_app app) {
download_wkr.Download_xrg().Prog_dlg_(Xoa_app_.Usr_dlg());
}
public Xowmf_api_mgr Api_mgr() {return api_mgr;} private Xowmf_api_mgr api_mgr = new Xowmf_api_mgr();
public Xof_download_wkr Download_wkr() {return download_wkr;} private final Xof_download_wkr download_wkr = new Xof_download_wkr_io();
}

View File

@@ -1,35 +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.bldrs.wms.dump_pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
public class Xowmf_wiki_dump_dirs_parser {
public static String[] Parse(byte[] wiki, byte[] src) {
List_adp rv = List_adp_.New();
int pos = 0;
while (true) {
int href_bgn = Bry_find_.Move_fwd(src, Tkn_href , pos); if (href_bgn == Bry_find_.Not_found) break;
int href_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, href_bgn); if (href_end == Bry_find_.Not_found) throw Err_.new_wo_type("unable to find date_end", "wiki", wiki, "snip", Bry_.Mid_by_len_safe(src, href_bgn - 3, 25));
if (src[href_end - 1] != Byte_ascii.Slash) throw Err_.new_wo_type("href should end in slash", "wiki", wiki, "snip", Bry_.Mid_by_len_safe(src, href_bgn - 3, 25));
pos = href_end + 1;
byte[] href_bry = Bry_.Mid(src, href_bgn, href_end - 1);
if (Bry_.Eq(href_bry, Tkn_owner)) continue; // ignore <a href="../">
rv.Add(String_.new_u8(href_bry));
}
return (String[])rv.To_ary_and_clear(String.class);
}
private static final byte[] Tkn_href = Bry_.new_a7(" href=\""), Tkn_owner = Bry_.new_a7("..");
}

View File

@@ -1,68 +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.bldrs.wms.dump_pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import org.junit.*;
import gplx.xowa.wikis.domains.*;
public class Xowmf_wiki_dump_dirs_parser_tst {
@Before public void init() {fxt.Clear();} private final Xowmf_wiki_dump_dirs_parser_fxt fxt = new Xowmf_wiki_dump_dirs_parser_fxt();
@Test public void Basic() {
fxt.Test_parse("<a href=\"20141230/\">20141230/</a><a href=\"20150118/\">20150118/</a>", "20141230", "20150118");
}
@Test public void Example() { // http://dumps.wikimedia.org/jawiki/
fxt.Test_parse(String_.Concat_lines_nl_skip_last
( "<html>"
, "<head><title>Index of /jawiki/</title></head>"
, "<body bgcolor=\"white\">"
, "<h1>Index of /jawiki/</h1><hr><pre><a href=\"../\">../</a>"
, "<a href=\"20141122/\">20141122/</a> 25-Nov-2014 22:04 -"
, "<a href=\"20141211/\">20141211/</a> 14-Dec-2014 09:25 -"
, "<a href=\"20141230/\">20141230/</a> 02-Jan-2015 09:02 -"
, "<a href=\"20150118/\">20150118/</a> 21-Jan-2015 04:39 -"
, "<a href=\"20150221/\">20150221/</a> 24-Feb-2015 17:51 -"
, "<a href=\"20150313/\">20150313/</a> 16-Mar-2015 14:37 -"
, "<a href=\"20150402/\">20150402/</a> 05-Apr-2015 06:19 -"
, "<a href=\"20150422/\">20150422/</a> 25-Apr-2015 13:52 -"
, "<a href=\"20150512/\">20150512/</a> 15-May-2015 08:17 -"
, "<a href=\"20150602/\">20150602/</a> 16-Jun-2015 01:34 -"
, "<a href=\"20150703/\">20150703/</a> 08-Jul-2015 14:44 -"
, "<a href=\"latest/\">latest/</a> 08-Jul-2015 14:44 -"
, "</pre><hr></body>"
, "</html>"
)
, "20141122"
, "20141211"
, "20141230"
, "20150118"
, "20150221"
, "20150313"
, "20150402"
, "20150422"
, "20150512"
, "20150602"
, "20150703"
, "latest"
);
}
}
class Xowmf_wiki_dump_dirs_parser_fxt {
public void Clear() {}
public void Test_parse(String src, String... expd_dates) {
String[] actl_dates = Xowmf_wiki_dump_dirs_parser.Parse(Xow_domain_itm_.Bry__enwiki, Bry_.new_u8(src));
Tfds.Eq_ary_str(expd_dates, actl_dates);
}
}

View File

@@ -1,100 +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.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.core.ios.*;
import gplx.xowa.wikis.domains.*;
public class Xowm_dump_file {
public Xowm_dump_file(String domain_str, String dump_date, String dump_type_str) {
this.dump_date = dump_date; this.dump_type_str = dump_type_str;
this.domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
this.dump_abrv = Xow_abrv_wm_.To_abrv(domain_itm);
this.file_name = Bld_file_name(dump_abrv, dump_date, dump_type_str);
}
public Xow_domain_itm Domain_itm() {return domain_itm;} private final Xow_domain_itm domain_itm; // EX: en.wikipedia.org
public byte[] Dump_abrv() {return dump_abrv;} private final byte[] dump_abrv; // EX: enwiki
public String Dump_date() {return dump_date;} private String dump_date; // EX: 20150807
public String Dump_type_str() {return dump_type_str;} private final String dump_type_str; // EX: pages-articles
public String Server_url() {return server_url;} private String server_url; // EX: https://dumps.wikimedia.org
public String File_url() {return file_url;} private String file_url; // EX: https://dumps.wikimedia.org/enwiki/20150807/enwiki-20150807-pages-articles.xml.bz2
public String File_name() {return file_name;} private String file_name; // EX: enwiki-20150807-pages-articles.xml.bz2
public long File_len() {return file_len;} private long file_len; // EX: 10 GB
public DateAdp File_modified() {return file_modified;} private DateAdp file_modified; // EX: 2015-08-10 20:12:34
public void Dump_date_(String v) {dump_date = v;}
public void Server_url_(String server_url) {
this.server_url = server_url;
String dump_dir_url = String_.new_u8(Xowm_dump_file_.Bld_dump_dir_url(Bry_.new_u8(server_url), dump_abrv, Bry_.new_u8(dump_date)));
this.file_url = dump_dir_url + file_name;
}
public boolean Connect() {
IoEngine_xrg_downloadFil args = Io_mgr.Instance.DownloadFil_args("", Io_url_.Empty);
boolean rv = Connect_exec(args, file_url);
// WMF changed dumping approach to partial dumps; this sometimes causes /latest/ to be missing page_articles; try to get earlier dump; DATE:2015-07-09
if ( !rv // not found
&& String_.In(server_url, Xowm_dump_file_.Server_wmf_http, Xowm_dump_file_.Server_wmf_https) // server is dumps.wikimedia.org
&& String_.Eq(dump_date, Xowm_dump_file_.Date_latest) // request dump was latest
) {
Xoa_app_.Usr_dlg().Warn_many("", "", "wmf.dump:latest not found; url=~{0}", file_url);
byte[] abrv_wm_bry = Xow_abrv_wm_.To_abrv(domain_itm);
String new_dump_root = Xowm_dump_file_.Server_wmf_https + String_.new_u8(abrv_wm_bry) + "/"; // EX: http://dumps.wikimedia.org/enwiki/
byte[] wiki_dump_dirs_src = args.Exec_as_bry(new_dump_root);
if (wiki_dump_dirs_src == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "could not connect to dump server; url=~{0}", new_dump_root); return false;}
String[] dates = gplx.xowa.bldrs.wms.dump_pages.Xowmf_wiki_dump_dirs_parser.Parse(domain_itm.Domain_bry(), wiki_dump_dirs_src);
int dates_len = dates.length;
for (int i = dates_len - 1; i > -1; --i) {
String new_dump_date = dates[i];
if (String_.Eq(new_dump_date, Xowm_dump_file_.Date_latest)) continue; // skip latest; assume it is bad
String new_dump_file = String_.Replace(file_name, Xowm_dump_file_.Date_latest, new_dump_date); // replace "-latest-" with "-20150602-";
String new_file_url = new_dump_root + new_dump_date + "/" + new_dump_file;
rv = Connect_exec(args, new_file_url);
if (rv) {
Xoa_app_.Usr_dlg().Note_many("", "", "wmf.dump:dump found; url=~{0}", new_file_url);
dump_date = new_dump_date;
file_name = new_dump_file;
file_url = new_file_url;
break;
}
else
Xoa_app_.Usr_dlg().Warn_many("", "", "wmf.dump:dump not found; url=~{0}", new_file_url);
}
}
return rv;
}
private boolean Connect_exec(IoEngine_xrg_downloadFil args, String cur_file_url) {
boolean rv = args.Src_last_modified_query_(true).Exec_meta(cur_file_url);
long tmp_file_len = args.Src_content_length();
DateAdp tmp_file_modified = args.Src_last_modified();
Xoa_app_.Usr_dlg().Note_many("", "", "wmf.dump:connect rslts; url=~{0} result=~{1} fil_len=~{2} file_modified=~{3} server_url=~{4} dump_date=~{5}", cur_file_url, rv, tmp_file_len, tmp_file_modified == null ? "<<NULL>>" : tmp_file_modified.XtoStr_fmt_yyyy_MM_dd_HH_mm_ss(), server_url, dump_date);
if (rv) {
if (tmp_file_modified != null && tmp_file_modified.Year() <= 1970) return false; // url has invalid file; note that dumps.wikimedia.org currently returns back an HTML page with "404 not found"; rather than try to download and parse this (since content may change), use the date_modified which always appears to be UnixTime 0; DATE:2015-07-21
file_len = tmp_file_len;
file_modified = tmp_file_modified;
}
return rv;
}
private static String Bld_file_name(byte[] dump_abrv, String dump_date, String dump_type_str) {
byte[] dump_type_bry = Bry_.new_u8(dump_type_str);
int dump_type_int = Xowm_dump_type_.parse_by_file(dump_type_bry);
byte[] dump_file_ext = Xowm_dump_file_.Ext_xml_bz2;
switch (dump_type_int) {
case Xowm_dump_type_.Int__page_props: case Xowm_dump_type_.Int__categorylinks: case Xowm_dump_type_.Int__image: case Xowm_dump_type_.Int__pagelinks:
dump_file_ext = Xowm_dump_file_.Ext_sql_gz;
break;
}
return String_.new_u8(Xowm_dump_file_.Bld_dump_file_name(dump_abrv, Bry_.new_u8(dump_date), dump_type_bry, dump_file_ext));
}
}

View File

@@ -1,81 +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.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.installs.*;
public class Xowm_dump_file_ {
public static Xowm_dump_file parse(byte[] src) {
int src_len = src.length;
int dash_0 = Bry_find_.Find_fwd(src, Byte_ascii.Dash, 0 , src_len); if (dash_0 == Bry_find_.Not_found) throw Err_.new_parse_type(Xowm_dump_file.class, String_.new_u8(src));
int dash_1 = Bry_find_.Find_fwd(src, Byte_ascii.Dash, dash_0 + 1 , src_len); if (dash_1 == Bry_find_.Not_found) throw Err_.new_parse_type(Xowm_dump_file.class, String_.new_u8(src));
byte[] domain_bry = Xow_abrv_wm_.Parse_to_domain_bry(Bry_.Mid(src, 0, dash_0));
return new Xowm_dump_file(String_.new_u8(domain_bry), String_.new_u8(src, dash_0 + 1, dash_1), String_.new_u8(src, dash_1 + 1, src_len));
}
public static boolean Connect_first(Xowm_dump_file rv, String[] server_urls) {
int len = server_urls.length;
for (int i = 0; i < len; ++i) {
String server_url = server_urls[i];
rv.Server_url_(server_url);
Override_dump_date(rv, server_url);
if (rv.Connect()) return true;
}
return false;
}
private static void Override_dump_date(Xowm_dump_file rv, String dump_server) {
String dump_date = rv.Dump_date();
if ( String_.Eq(dump_date, Xowm_dump_file_.Date_latest)
&& ( String_.Eq(dump_server, Xowm_dump_file_.Server_c3sl)
|| String_.Eq(dump_server, Xowm_dump_file_.Server_masaryk)
)
){
Xoa_app_.Usr_dlg().Note_many("", "", "wmf.dump:dump date; server_url=~{0} dump_date=~{1}", dump_server, dump_date);
Xoi_mirror_parser mirror_parser = new Xoi_mirror_parser();
String dump_wiki_url = dump_server + String_.new_a7(rv.Dump_abrv()) + "/";
byte[] dump_url_wiki_html = gplx.core.ios.IoEngine_xrg_downloadFil.new_("", Io_url_.Empty).Exec_as_bry(dump_wiki_url); if (Bry_.Len_eq_0(dump_url_wiki_html)) return;
String[] dump_available_dates = mirror_parser.Parse(String_.new_u8(dump_url_wiki_html));
String dump_dates_latest = Xoi_mirror_parser.Find_last_lte(dump_available_dates, dump_date);
if (String_.Eq(dump_dates_latest, "")) return; // nothing found
rv.Dump_date_(dump_dates_latest);
}
}
public static byte[] Bld_dump_dir_url(byte[] server_url, byte[] alias, byte[] date) {
return Bry_.Add
( server_url // "http://dumps.wikimedia.org/"
, Bry_.Replace(alias, Byte_ascii.Dash, Byte_ascii.Underline), Bry_slash // "simplewiki/"
, date, Bry_slash // "latest/"
);
}
public static byte[] Bld_dump_file_name(byte[] alias, byte[] date, byte[] dump_file_type, byte[] ext) {
return Bry_.Add
( Bry_.Replace(alias, Byte_ascii.Dash, Byte_ascii.Underline), Bry_dash // "simplewiki-"
, date, Bry_dash // "latest-"
, dump_file_type // "pages-articles"
, ext // ".xml.bz2"
);
}
private static final byte[] Bry_dash = new byte[] {Byte_ascii.Dash}, Bry_slash = new byte[] {Byte_ascii.Slash};
public static final byte[] Ext_xml_bz2 = Bry_.new_a7(".xml.bz2");
public static final byte[] Ext_sql_gz = Bry_.new_a7(".sql.gz");
public static final String
Server_wmf_http = "http://dumps.wikimedia.org/"
, Server_wmf_https = "https://dumps.wikimedia.org/"
, Server_your_org = "http://dumps.wikimedia.your.org/"
, Server_c3sl = "http://wikipedia.c3sl.ufpr.br/"
, Server_masaryk = "http://ftp.fi.muni.cz/pub/wikimedia/"
, Date_latest = "latest"
;
}

View File

@@ -1,45 +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.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import org.junit.*;
public class Xowm_dump_file_tst {
private final Xowm_dump_file_fxt fxt = new Xowm_dump_file_fxt();
@Test public void Parse() {fxt.Test_parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xowm_dump_type_.Int__pages_articles);}
@Test public void Bld_dump_dir_url() {
fxt.Test_bld_dump_dir_url("simplewiki", "latest", "http://dumps.wikimedia.your.org/simplewiki/latest/");
}
@Test public void Bld_dump_file_name() {
fxt.Test_bld_dump_file_name("simplewiki", "latest", Xowm_dump_type_.Str__pages_articles, "simplewiki-latest-pages-articles.xml.bz2");
}
}
class Xowm_dump_file_fxt {
public void Test_parse(String name, String domain, String date, int tid) {
Xowm_dump_file dump_file = Xowm_dump_file_.parse(Bry_.new_u8(name));
Tfds.Eq(domain , dump_file.Domain_itm().Domain_str());
Tfds.Eq(date , dump_file.Dump_date());
Tfds.Eq(tid , Xowm_dump_type_.parse_by_file(Bry_.new_u8(dump_file.Dump_type_str())));
}
public void Test_bld_dump_dir_url(String dump_file, String date, String expd) {
byte[] actl = Xowm_dump_file_.Bld_dump_dir_url(Bry_.new_a7(Xowm_dump_file_.Server_your_org), Bry_.new_a7(dump_file), Bry_.new_a7(date));
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Test_bld_dump_file_name(String dump_file, String date, String dump_type, String expd) {
byte[] actl = Xowm_dump_file_.Bld_dump_file_name(Bry_.new_a7(dump_file), Bry_.new_a7(date), Bry_.new_a7(dump_type), Xowm_dump_file_.Ext_xml_bz2);
Tfds.Eq(expd, String_.new_a7(actl));
}
}

View File

@@ -1,49 +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.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.core.btries.*; import gplx.core.primitives.*;
public class Xowm_dump_type_ {
public static int parse_by_file(byte[] src) {return parse_by_file(src, 0, src.length);}
public static int parse_by_file(byte[] src, int bgn, int end) { // given "pages-articles.xml", get type from "pages-articles"; ignore ".xml" or ".bz2"
Object o = regy.Match_bgn(src, bgn, end); if (o == null) throw Err_.new_("wm.dump", "unknown dump file type", "src", src);
return ((Int_obj_val)o).Val();
}
public static final int Int__pages_articles = 1, Int__pages_meta_current = 2, Int__categorylinks = 3, Int__page_props = 4, Int__image = 5, Int__pagelinks = 6;
public static final String Str__pages_articles = "pages-articles", Str__pages_meta_current = "pages-meta-current"
, Str__categorylinks = "categorylinks", Str__page_props = "page_props", Str__image = "image", Str__pagelinks = "pagelinks"
;
private static final Btrie_slim_mgr regy = Btrie_slim_mgr.ci_a7()
.Add_str_int(Str__pages_articles , Int__pages_articles)
.Add_str_int(Str__pages_meta_current , Int__pages_meta_current)
.Add_str_int(Str__categorylinks , Int__categorylinks)
.Add_str_int(Str__page_props , Int__page_props)
.Add_str_int(Str__image , Int__image)
.Add_str_int(Str__pagelinks , Int__pagelinks)
;
public static String To_str(byte v) {
switch (v) {
case Int__pages_articles : return Str__pages_articles;
case Int__pages_meta_current : return Str__pages_meta_current;
case Int__categorylinks : return Str__categorylinks;
case Int__page_props : return Str__page_props;
case Int__image : return Str__image;
case Int__pagelinks : return Str__pagelinks;
default : throw Err_.new_unhandled(v);
}
}
}

View File

@@ -1,29 +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.bldrs.wms.dumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.wikis.*;
public class Xowm_dump_type__tst {
private final Xowm_dump_type__fxt fxt = new Xowm_dump_type__fxt();
@Test public void Parse() {
fxt.Test_parse("pages-articles.xml" , Xowm_dump_type_.Int__pages_articles);
fxt.Test_parse("pages-meta-current.xml" , Xowm_dump_type_.Int__pages_meta_current);
}
}
class Xowm_dump_type__fxt {
public void Test_parse(String raw_str, int expd) {Tfds.Eq_int(expd, Xowm_dump_type_.parse_by_file(Bry_.new_u8(raw_str)), "dump_type");}
}

View File

@@ -1,78 +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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Wmapi_itm__pge {
public int Page_id() {return page_id;} private int page_id;
public int Page_ns() {return page_ns;} private int page_ns;
public byte[] Page_ttl() {return page_ttl;} private byte[] page_ttl;
public Wmapi_itm__rvn[] Rvn_ary() {return rvn_ary;} private Wmapi_itm__rvn[] rvn_ary = Wmapi_itm__rvn.Ary_empty;
public Wmapi_itm__ttl[] Tml_ary() {return tml_ary;} private Wmapi_itm__ttl[] tml_ary = Wmapi_itm__ttl.Ary_empty;
public Wmapi_itm__ttl[] Img_ary() {return img_ary;} private Wmapi_itm__ttl[] img_ary = Wmapi_itm__ttl.Ary_empty;
public Wmapi_itm__ctg[] Ctg_ary() {return ctg_ary;} private Wmapi_itm__ctg[] ctg_ary = Wmapi_itm__ctg.Ary_empty;
public void Rvn_ary_(Wmapi_itm__rvn... v) {this.rvn_ary = v;}
public void Tml_ary_(Wmapi_itm__ttl... v) {this.tml_ary = v;}
public void Img_ary_(Wmapi_itm__ttl... v) {this.img_ary = v;}
public void Ctg_ary_(Wmapi_itm__ctg... v) {this.ctg_ary = v;}
public Wmapi_itm__rvn Rvn_itm_last() {return rvn_ary[rvn_ary.length - 1];}
public Wmapi_itm__pge Init_ttl(int page_ns, byte[] page_ttl) {
this.page_ns = page_ns; this.page_ttl = page_ttl;
return this;
}
public Wmapi_itm__pge Init_id(int page_id) {
this.page_id = page_id;
return this;
}
public boolean Eq_meta(Wmapi_itm__pge rhs_page, int idx) {
Wmapi_itm__rvn lhs = rvn_ary[idx];
Wmapi_itm__rvn rhs = rhs_page.rvn_ary[idx];
return lhs.Rvn_len() == rhs.Rvn_len() && Bry_.Eq(lhs.Rvn_time(), rhs.Rvn_time());
}
}
class Wmapi_itm__ttl {
public Wmapi_itm__ttl(int ns_id, byte[] ttl_bry) {this.ns_id = ns_id; this.ttl_bry = ttl_bry;}
public int Ns_id() {return ns_id;} private final int ns_id;
public byte[] Ttl_bry() {return ttl_bry;} private final byte[] ttl_bry;
public static final Wmapi_itm__ttl[] Ary_empty = new Wmapi_itm__ttl[0];
}
class Wmapi_itm__rvn {
public int Rvn_id() {return rvn_id;} private int rvn_id;
public int Rvn_len() {return rvn_len;} private int rvn_len;
public byte[] Rvn_time() {return rvn_time;} private byte[] rvn_time;
public byte[] Rvn_user() {return rvn_user;} private byte[] rvn_user;
public byte[] Rvn_note() {return rvn_note;} private byte[] rvn_note;
public byte[] Rvn_text() {return rvn_text;} private byte[] rvn_text;
public void Rvn_text_(byte[] v) {this.rvn_text = v;}
public void Init(int rvn_id, int rvn_len, byte[] rvn_time, byte[] rvn_user, byte[] rvn_note) {
this.rvn_id = rvn_id;
this.rvn_len = rvn_len; this.rvn_time = rvn_time;
this.rvn_user = rvn_user; this.rvn_note = rvn_note;
}
public static final Wmapi_itm__rvn[] Ary_empty = new Wmapi_itm__rvn[0];
}
class Wmapi_itm__ctg {
public Wmapi_itm__ctg(int ctg_ns, byte[] ctg_ttl, byte[] ctg_sortkey, boolean ctg_sortprefix, byte[] ctg_time, boolean ctg_hidden) {
this.ctg_ns = ctg_ns; this.ctg_ttl = ctg_ttl; this.ctg_sortkey = ctg_sortkey; this.ctg_sortprefix = ctg_sortprefix; this.ctg_time = ctg_time; this.ctg_hidden = ctg_hidden;
}
public int Ctg_ns() {return ctg_ns;} private final int ctg_ns;
public byte[] Ctg_ttl() {return ctg_ttl;} private final byte[] ctg_ttl;
public byte[] Ctg_sortkey() {return ctg_sortkey;} private final byte[] ctg_sortkey;
public boolean Ctg_sortprefix() {return ctg_sortprefix;} private final boolean ctg_sortprefix;
public byte[] Ctg_time() {return ctg_time;} private final byte[] ctg_time;
public boolean Ctg_hidden() {return ctg_hidden;} private final boolean ctg_hidden;
public static final Wmapi_itm__ctg[] Ary_empty = new Wmapi_itm__ctg[0];
}

View File

@@ -1,92 +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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.langs.jsons.*;
class Wmapi_itm_json_wtr {
public Json_wtr Wtr() {return wtr;} private final Json_wtr wtr = new Json_wtr();
public byte[] To_bry(Wmapi_itm__pge[] ary) {
wtr.Clear();
Write_query(ary);
return wtr.To_bry_and_clear();
}
private void Write_query(Wmapi_itm__pge[] ary) {
wtr.Doc_nde_bgn();
wtr.Nde_bgn("query");
wtr.Nde_bgn("pages");
for (Wmapi_itm__pge itm : ary)
Write_page(itm);
wtr.Nde_end();
wtr.Nde_end();
wtr.Doc_nde_end();
}
private void Write_page(Wmapi_itm__pge itm) {
wtr.Nde_bgn(Int_.To_str(itm.Page_id()));
wtr.Kv_int("pageid", itm.Page_id());
wtr.Kv_int("ns", itm.Page_ns());
wtr.Kv_bry("title", itm.Page_ttl());
Write_sub_rvns(itm.Rvn_ary());
Write_sub_ttls(itm.Tml_ary(), "templates");
Write_sub_ttls(itm.Img_ary(), "images");
Write_sub_ctgs(itm.Ctg_ary());
wtr.Nde_end();
}
private void Write_sub_rvns(Wmapi_itm__rvn[] rvn_ary) {
int len = rvn_ary.length; if (len == 0) return;
wtr.Ary_bgn("revisions");
for (int i = 0; i < len; ++i) {
Wmapi_itm__rvn rvn = rvn_ary[i];
wtr.Doc_nde_bgn();
wtr.Kv_int("revid", rvn.Rvn_id());
wtr.Kv_int("parentid", -1);
wtr.Kv_bry("timestamp", rvn.Rvn_time());
wtr.Kv_int("size", rvn.Rvn_len());
wtr.Kv_bry("user", rvn.Rvn_user());
wtr.Kv_bry("parsedcomment", rvn.Rvn_note());
wtr.Doc_nde_end();
}
wtr.Ary_end();
}
private void Write_sub_ttls(Wmapi_itm__ttl[] ttl_ary, String ary_name) {
int len = ttl_ary.length; if (len == 0) return;
wtr.Ary_bgn(ary_name);
for (int i = 0; i < len; ++i) {
Wmapi_itm__ttl ttl = ttl_ary[i];
wtr.Doc_nde_bgn();
wtr.Kv_int("ns", ttl.Ns_id());
wtr.Kv_bry("title", ttl.Ttl_bry());
wtr.Doc_nde_end();
}
wtr.Ary_end();
}
private void Write_sub_ctgs(Wmapi_itm__ctg[] ctg_ary) {
int len = ctg_ary.length; if (len == 0) return;
wtr.Ary_bgn("categories");
for (int i = 0; i < len; ++i) {
Wmapi_itm__ctg ctg = ctg_ary[i];
wtr.Doc_nde_bgn();
wtr.Kv_int("ns", ctg.Ctg_ns());
wtr.Kv_bry("title", ctg.Ctg_ttl());
wtr.Kv_bry("sortkey", ctg.Ctg_sortkey());
wtr.Kv_bool_as_mw("sortkeyprefix", ctg.Ctg_sortprefix());
wtr.Kv_bry("timestamp", ctg.Ctg_time());
wtr.Kv_bool_as_mw("hidden", ctg.Ctg_hidden());
wtr.Doc_nde_end();
}
wtr.Ary_end();
}
}

View File

@@ -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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.langs.jsons.*;
class Xowm_json_parser__page extends Json_parser__list_nde__base {
private Wmapi_itm__pge pge;
private Xowm_json_parser__rev rev_nde_parser = new Xowm_json_parser__rev();
private String nde_context;
public Xowm_json_parser__page() {
this.Ctor("pageid", "ns", "title", "revisions");
}
public void Parse(String context, Wmapi_itm__pge pge, Json_nde nde) {
this.pge = pge;
this.nde_context = context + ".page";
this.Parse_nde(context, nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
int page_id = Kv__int(atrs, 0);
Json_ary revs_ary = atrs[3].Val_as_ary(); if (revs_ary.Len() == 0) throw Err_.new_("rev.parser", "no revisions found", sub.Doc().Src());
Json_nde rev_nde = revs_ary.Get_at_as_nde(0);
pge.Init_id(page_id);
pge.Init_ttl(Kv__int(atrs, 1), Kv__bry(atrs, 2));
rev_nde_parser.Parse(nde_context, pge.Rvn_itm_last(), rev_nde);
}
}
class Xowm_json_parser__rev extends Json_parser__list_nde__base {
private Wmapi_itm__rvn rvn;
public Xowm_json_parser__rev() {
this.Ctor("revid", "parentid", "user", "anon", "timestamp", "size", "parsedcomment");// , "contentformat", "contentmodel", "*"
}
public void Parse(String context, Wmapi_itm__rvn rvn, Json_nde nde) {
this.rvn = rvn;
this.Parse_nde(context + ".rev", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
rvn.Init(Kv__int(atrs, 0), Kv__int(atrs, 5), Kv__bry(atrs, 4), Kv__bry(atrs, 2), Kv__bry(atrs, 6));
}
}

View File

@@ -1,87 +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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.xowa.bldrs.wms.*;
class Xowm_rev_sync {
private final Ordered_hash cur_hash = Ordered_hash_.New_bry(), new_hash = Ordered_hash_.New_bry();
private final List_adp del_list = List_adp_.New();
public int Batch_size() {return batch_size;} public void Batch_size_(int v) {batch_size = v;} private int batch_size = 50;
public Xowm_rev_wkr__meta Wkr__cur_meta() {return wkr__cur_meta;} private Xowm_rev_wkr__meta wkr__cur_meta;
public Xowm_rev_wkr__meta Wkr__new_meta() {return wkr__new_meta;} private Xowm_rev_wkr__meta wkr__new_meta;
public Xowm_rev_wkr__text Wkr__new_text() {return wkr__new_text;} private Xowm_rev_wkr__text wkr__new_text;
public void Init(Xowm_rev_wkr__meta wkr__new_meta, Xowm_rev_wkr__meta wkr__cur_meta, Xowm_rev_wkr__text wkr__new_text) {
this.wkr__cur_meta = wkr__cur_meta;
this.wkr__new_meta = wkr__new_meta;
this.wkr__new_text = wkr__new_text;
}
public void Exec(String domain_str, Xoa_ttl[] ttls_ary) {
synchronized (new_hash) {
Xowm_rev_sync_utl.Build_itms(cur_hash, ttls_ary);
Xowm_rev_sync_utl.Build_itms(new_hash, ttls_ary);
int len = new_hash.Count();
for (int i = 0; i < len; i += batch_size)
Exec_batch(domain_str, i, len);
}
}
private void Exec_batch(String domain_str, int itms_bgn, int itms_len) {
int itms_end = itms_bgn + batch_size; if (itms_end > itms_len) itms_end = itms_len;
wkr__cur_meta.Fetch_meta(domain_str, cur_hash, itms_bgn, itms_end);
wkr__new_meta.Fetch_meta(domain_str, new_hash, itms_bgn, itms_end);
Xowm_rev_sync_utl.Remove_unchanged(cur_hash, new_hash, del_list, itms_bgn, itms_end);
wkr__new_text.Fetch_text(new_hash, itms_bgn, itms_end);
/*
loop (changed texts) {
parse page
}
loop (changed texts) {
get other ref
get files
}
loop (changed texts) {
update category
update search
}
*/
}
}
class Xowm_rev_sync_utl {
public static void Build_itms(Ordered_hash hash, Xoa_ttl[] ttls_ary) {
int len = ttls_ary.length;
for (int i = 0; i < len; ++i) {
Xoa_ttl ttl = ttls_ary[i];
byte[] key = ttl.Full_db();
if (hash.Has(key)) continue; // ignore dupes
hash.Add(key, new Wmapi_itm__pge().Init_ttl(ttl.Ns().Id(), ttl.Page_db()));
}
}
public static void Remove_unchanged(Ordered_hash cur_hash, Ordered_hash new_hash, List_adp del_list, int bgn, int end) {
del_list.Clear();
for (int i = bgn; i < end; ++i) {
Wmapi_itm__pge new_itm = (Wmapi_itm__pge)new_hash.Get_at(i);
byte[] new_key = new_itm.Page_ttl();
Wmapi_itm__pge cur_itm = (Wmapi_itm__pge)cur_hash.Get_by(new_key); if (cur_itm == null) continue; // itm not found; ignore
if (new_itm.Eq_meta(cur_itm, 0)) // itm is same; add to deleted list
del_list.Add(new_itm);
}
int len = del_list.Count();
for (int i = 0; i < len; ++i) {
Wmapi_itm__pge itm = (Wmapi_itm__pge)del_list.Get_at(i);
new_hash.Del(itm.Page_ttl());
}
}
}

View File

@@ -1,55 +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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.langs.jsons.*; import gplx.core.net.*;
class Xowm_rev_wkr__meta__wm implements Xowm_rev_wkr__meta {
private final Json_parser json_parser = new Json_parser();
private final Xowm_json_parser__page json_page_parser = new Xowm_json_parser__page();
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
private final Wmapi_itm__pge tmp_pge = new Wmapi_itm__pge();
public Xowm_rev_wkr__meta__wm() {
tmp_pge.Rvn_ary_(new Wmapi_itm__rvn());
}
public Gfo_inet_conn Inet_conn() {return inet_conn;} public void Inet_conn_(Gfo_inet_conn v) {this.inet_conn = v;} private Gfo_inet_conn inet_conn;
public void Fetch_meta(String domain_str, Ordered_hash hash, int bgn, int end) {
for (int i = bgn; i < end; ++i) {
Wmapi_itm__pge itm = (Wmapi_itm__pge)hash.Get_at(i);
if (i != bgn) tmp_bfr.Add_byte(Byte_ascii.Pipe);
tmp_bfr.Add(itm.Page_ttl());
}
byte[] json = inet_conn.Download_as_bytes_or_null(Xowm_api_mgr.Bld_api_url(domain_str, "action=query&prop=revisions&rvprop=size|ids|timestamp|user|comment&format=json&rawcontinue=titles=" + tmp_bfr.To_str_and_clear()));
Parse_doc(hash, json);
}
private void Parse_doc(Ordered_hash hash, byte[] json) {
Json_doc jdoc = json_parser.Parse(json);
Json_nde pages_nde = Json_nde.cast(jdoc.Get_grp_many(Jpath__query_pages));
int len = pages_nde.Len();
for (int i = 0; i < len; ++i) {
Parse_page(hash, pages_nde.Get_at_as_kv(i).Val_as_nde());
}
}
private void Parse_page(Ordered_hash hash, Json_nde page_nde) {
json_page_parser.Parse("update", tmp_pge, page_nde); // have to pass tmp_pge, b/c don't know which itm is in hash
Wmapi_itm__pge hash_itm = (Wmapi_itm__pge)hash.Get_by(tmp_pge.Page_ttl()); if (hash_itm == null) return;
hash_itm.Init_id(tmp_pge.Page_id());
Wmapi_itm__rvn tmp_rvn = tmp_pge.Rvn_itm_last();
hash_itm.Rvn_ary_(new Wmapi_itm__rvn());
hash_itm.Rvn_itm_last().Init(tmp_rvn.Rvn_id(), tmp_rvn.Rvn_len(), tmp_rvn.Rvn_time(), tmp_rvn.Rvn_user(), tmp_rvn.Rvn_note());
}
private static final byte[][] Jpath__query_pages = Bry_.Ary("query", "pages");
}

View File

@@ -1,83 +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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import org.junit.*; import gplx.langs.jsons.*; import gplx.core.net.*; import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.domains.*;
public class Xowm_rev_wkr__meta__wm_tst {
private final Xowm_rev_wkr__meta__wm_fxt fxt = new Xowm_rev_wkr__meta__wm_fxt();
@Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();}
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
@Test public void Basic() {
Wmapi_itm__pge[] expd = fxt.Make_pge_ary
( fxt.Make_pge(Xow_ns_.Tid__main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1")
, fxt.Make_pge(Xow_ns_.Tid__main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2")
);
fxt.Init_inet_upload(expd);
fxt.Test_fetch(String_.Ary("A", "B"), expd); // test get both
fxt.Init_inet_upload(expd);
fxt.Test_fetch(String_.Ary("A") , expd[0]); // test get 1
fxt.Init_inet_upload(expd);
fxt.Test_fetch(String_.Ary("C"), fxt.Make_pge_empty(0, "C")); // test get none
fxt.Init_inet_upload(expd);
fxt.Test_fetch(String_.Ary("A", "B", "C"), expd[0], expd[1], fxt.Make_pge_empty(0, "C")); // test get too many
}
}
class Xowm_rev_wkr__meta__wm_fxt {
private final String domain_str = Xow_domain_itm_.Str__enwiki;
private final Ordered_hash rev_hash = Ordered_hash_.New_bry();
private final Xowm_rev_wkr__meta__wm meta_wkr = new Xowm_rev_wkr__meta__wm();
private final Wmapi_itm_json_wtr json_wtr = new Wmapi_itm_json_wtr();
public Xowm_rev_wkr__meta__wm_fxt() {
meta_wkr.Inet_conn_(Gfo_inet_conn_.new_mem_pile());
}
public Wmapi_itm__pge[] Make_pge_ary(Wmapi_itm__pge... ary) {return ary;}
public Wmapi_itm__pge Make_pge_empty(int page_ns, String page_ttl) {
Wmapi_itm__pge rv = Make_pge(page_ns, page_ttl, 0, 0, 0, null, null, null);
rv.Rvn_ary_(Wmapi_itm__rvn.Ary_empty);
return rv;
}
public Wmapi_itm__pge Make_pge(int page_ns, String page_ttl, int page_id, int rev_id, int rev_len, String rev_time, String rev_user, String rev_note) {
Wmapi_itm__pge rv = new Wmapi_itm__pge();
rv.Init_id(page_id);
rv.Init_ttl(page_ns, Bry_.new_u8(page_ttl));
Wmapi_itm__rvn rvn = new Wmapi_itm__rvn();
rv.Rvn_ary_(rvn);
rvn.Init(rev_id, rev_len, Bry_.new_a7(rev_time), Bry_.new_a7(rev_user), Bry_.new_a7(rev_note));
return rv;
}
public void Init_inet_upload(Wmapi_itm__pge... ary) {
Gfo_inet_conn inet_conn = meta_wkr.Inet_conn();
byte[] page = json_wtr.To_bry(ary);
inet_conn.Clear();
inet_conn.Upload_by_bytes(domain_str, page);
}
public void Test_fetch(String[] ttl_ary, Wmapi_itm__pge... expd) {
Init_rev_hash(ttl_ary);
meta_wkr.Fetch_meta(domain_str, rev_hash, 0, rev_hash.Count());
Tfds.Eq_str_lines(String_.new_u8(json_wtr.To_bry(expd)), String_.new_u8(json_wtr.To_bry((Wmapi_itm__pge[])rev_hash.To_ary_and_clear(Wmapi_itm__pge.class))));
}
private void Init_rev_hash(String[] ttl_ary) {
rev_hash.Clear();
int len = ttl_ary.length;
for (int i = 0; i < len; ++i) {
String ttl_str = ttl_ary[i];
byte[] ttl_bry = Bry_.new_u8(ttl_str);
rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Tid__main, ttl_bry));
}
}
}

View File

@@ -1,28 +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.bldrs.wms.revs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
interface Xowm_rev_wkr__meta {
void Fetch_meta(String domain_bry, Ordered_hash hash, int bgn, int end);
}
interface Xowm_rev_wkr__text {
void Fetch_text(Ordered_hash hash, int bgn, int end);
}
class Xowm_rev_wkr__meta__xo {
public void Fetch_meta(Ordered_hash hash, int bgn, int end) {
}
}

View File

@@ -1,136 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.xwikis.bldrs.*;
public class Site_core_db {
private Db_conn conn;
private final Site_core_tbl tbl__core;
private final Site_kv_tbl tbl__general;
private final Site_namespace_tbl tbl__namespace;
private final Site_statistic_tbl tbl__statistic;
private final Site_interwikimap_tbl tbl__interwikimap;
private final Site_namespacealias_tbl tbl__namespacealias;
private final Site_specialpagealias_tbl tbl__specialpagealias;
private final Site_library_tbl tbl__library;
private final Site_extension_tbl tbl__extension;
private final Site_skin_tbl tbl__skin;
private final Site_magicword_tbl tbl__magicword;
private final Site_val_tbl tbl__functionhook;
private final Site_showhook_tbl tbl__showhook;
private final Site_val_tbl tbl__extensiontag;
private final Site_val_tbl tbl__protocol;
private final Site_kv_tbl tbl__defaultoption;
private final Site_language_tbl tbl__language;
private final Db_tbl[] tbl_ary;
public Site_core_db(Io_url db_url) {
Db_conn_bldr_data conn_data = Db_conn_bldr.Instance.Get_or_new(db_url);
this.conn = conn_data.Conn(); boolean created = conn_data.Created();
this.tbl__core = new Site_core_tbl(conn);
this.tbl__general = new Site_kv_tbl(conn, "site_general");
this.tbl__namespace = new Site_namespace_tbl(conn);
this.tbl__statistic = new Site_statistic_tbl(conn);
this.tbl__namespacealias = new Site_namespacealias_tbl(conn);
this.tbl__interwikimap = new Site_interwikimap_tbl(conn);
this.tbl__specialpagealias = new Site_specialpagealias_tbl(conn);
this.tbl__library = new Site_library_tbl(conn);
this.tbl__extension = new Site_extension_tbl(conn);
this.tbl__skin = new Site_skin_tbl(conn);
this.tbl__magicword = new Site_magicword_tbl(conn);
this.tbl__functionhook = new Site_val_tbl(conn, "site_functionhook");
this.tbl__showhook = new Site_showhook_tbl(conn);
this.tbl__extensiontag = new Site_val_tbl(conn, "site_extensiontag");
this.tbl__protocol = new Site_val_tbl(conn, "site_protocol");
this.tbl__defaultoption = new Site_kv_tbl(conn, "site_defaultoption");
this.tbl__language = new Site_language_tbl(conn);
this.tbl_ary = new Db_tbl[]
{ tbl__core, tbl__general, tbl__namespace, tbl__statistic, tbl__interwikimap, tbl__namespacealias, tbl__specialpagealias, tbl__library
, tbl__extension, tbl__skin, tbl__magicword, tbl__functionhook, tbl__showhook, tbl__extensiontag, tbl__protocol, tbl__defaultoption, tbl__language
};
if (created) Db_tbl_.Create_tbl(tbl_ary); // NOTE: each Create_tbl also does Create_idx; will be "slower" for inserts, but logic is simpler for updates
}
public Site_core_tbl Tbl__core() {return tbl__core;}
public Site_namespace_tbl Tbl__namespace() {return tbl__namespace;}
public void Rls() {Db_tbl_.Rls(tbl_ary);}
public void Save(Site_meta_itm site_meta, byte[] site_abrv) {
conn.Txn_bgn("site_meta");
tbl__general.Insert(site_abrv, site_meta.General_list());
tbl__statistic.Insert(site_abrv, site_meta.Statistic_itm());
tbl__namespace.Insert(site_abrv, site_meta.Namespace_list());
tbl__interwikimap.Insert(site_abrv, site_meta.Interwikimap_list());
tbl__namespacealias.Insert(site_abrv, site_meta.Namespacealias_list());
tbl__specialpagealias.Insert(site_abrv, site_meta.Specialpagealias_list());
tbl__library.Insert(site_abrv, site_meta.Library_list());
tbl__extension.Insert(site_abrv, site_meta.Extension_list());
tbl__skin.Insert(site_abrv, site_meta.Skin_list());
tbl__magicword.Insert(site_abrv, site_meta.Magicword_list());
tbl__showhook.Insert(site_abrv, site_meta.Showhook_list());
tbl__functionhook.Insert(site_abrv, site_meta.Functionhook_list());
tbl__extensiontag.Insert(site_abrv, site_meta.Extensiontag_list());
tbl__protocol.Insert(site_abrv, site_meta.Protocol_list());
tbl__defaultoption.Insert(site_abrv, site_meta.Defaultoption_list());
tbl__language.Insert(site_abrv, site_meta.Language_list());
tbl__core.Update(site_abrv, Bool_.Y);
conn.Txn_end();
}
public void Load(Site_meta_itm site_meta, byte[] site_abrv) {
tbl__general.Select(site_abrv, site_meta.General_list());
tbl__statistic.Select(site_abrv, site_meta.Statistic_itm());
tbl__namespace.Select(site_abrv, site_meta.Namespace_list());
tbl__interwikimap.Select(site_abrv, site_meta.Interwikimap_list());
tbl__namespacealias.Select(site_abrv, site_meta.Namespacealias_list());
tbl__specialpagealias.Select(site_abrv, site_meta.Specialpagealias_list());
tbl__library.Select(site_abrv, site_meta.Library_list());
tbl__extension.Select(site_abrv, site_meta.Extension_list());
tbl__skin.Select(site_abrv, site_meta.Skin_list());
tbl__magicword.Insert(site_abrv, site_meta.Magicword_list());
tbl__showhook.Select(site_abrv, site_meta.Showhook_list());
tbl__functionhook.Select(site_abrv, site_meta.Functionhook_list());
tbl__extensiontag.Select(site_abrv, site_meta.Extensiontag_list());
tbl__protocol.Select(site_abrv, site_meta.Protocol_list());
tbl__defaultoption.Select(site_abrv, site_meta.Defaultoption_list());
tbl__language.Select(site_abrv, site_meta.Language_list());
}
public Xow_ns_mgr Load_namespace(byte[] domain_bry) {
Xow_ns_mgr rv = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
Ordered_hash hash = Ordered_hash_.New();
tbl__namespace.Select(Xow_abrv_xo_.To_bry(domain_bry), hash);
Ns_mgr__load(rv, hash);
return rv;
}
public void Load_interwikimap(Xow_domain_itm domain_itm, gplx.xowa.wikis.xwikis.Xow_xwiki_mgr xwiki_mgr) {
Ordered_hash hash = Ordered_hash_.New();
tbl__interwikimap.Select(domain_itm.Abrv_xo(), hash);
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Site_interwikimap_itm itm = (Site_interwikimap_itm)hash.Get_at(i);
Xow_xwiki_itm xwiki_itm = Xow_xwiki_itm_bldr.Instance.Bld_mw(domain_itm, itm.Prefix, itm.Url, null);
xwiki_mgr.Add_itm(xwiki_itm);
}
}
private static void Ns_mgr__load(Xow_ns_mgr rv, Ordered_hash hash) {
rv.Clear();
int len = hash.Count();
for (int i = 0; i < len; ++i) {
Site_namespace_itm itm = (Site_namespace_itm)hash.Get_at(i);
byte case_match = Xow_ns_case_.To_tid(String_.new_u8(itm.Case_tid()));
rv.Add_new(itm.Id(), itm.Localized(), case_match, Bool_.N);
}
}
}

View File

@@ -1,33 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
public class Site_core_itm {
public Site_core_itm(byte[] site_abrv, byte[] site_domain, boolean json_completed, DateAdp json_date, byte[] json_text) {
this.site_abrv = site_abrv;
this.site_domain = site_domain;
this.json_completed = json_completed;
this.json_date = json_date;
this.json_text = json_text;
}
public byte[] Site_abrv() {return site_abrv;} private final byte[] site_abrv;
public byte[] Site_domain() {return site_domain;} private final byte[] site_domain;
public boolean Json_completed() {return json_completed;} private final boolean json_completed;
public DateAdp Json_date() {return json_date;} private final DateAdp json_date;
public byte[] Json_text() {return json_text;} private byte[] json_text;
public void Json_text_null_() {json_text = null;}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
public class Site_core_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_site_domain, fld_json_completed, fld_json_date, fld_json_text;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete, stmt_update;
public Site_core_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_site_domain = flds.Add_str("site_domain", 255);
this.fld_json_completed = flds.Add_bool("json_completed");
this.fld_json_date = flds.Add_str("json_date", 20);
this.fld_json_text = flds.Add_text("json_text");
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_core";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv)));}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
stmt_update = Db_stmt_.Rls(stmt_update);
}
public void Update(byte[] site_abrv, boolean json_completed) {
if (stmt_update == null) stmt_update = conn.Stmt_update(tbl_name, String_.Ary(fld_site_abrv), fld_json_completed);
stmt_update.Clear()
.Val_bool_as_byte (fld_json_completed , json_completed)
.Crt_bry_as_str (fld_site_abrv , site_abrv)
.Exec_update();
}
public void Insert(byte[] site_abrv, byte[] site_domain, boolean json_completed, DateAdp json_date, byte[] json_text) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_bry_as_str (fld_site_abrv , site_abrv)
.Val_bry_as_str (fld_site_domain , site_domain)
.Val_bool_as_byte (fld_json_completed , json_completed)
.Val_str (fld_json_date , json_date.XtoStr_gplx())
.Val_bry_as_str (fld_json_text , json_text)
.Exec_insert();
}
public Site_core_itm Select_itm(byte[] site_abrv) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_site_abrv)
.Clear()
.Crt_bry_as_str(fld_site_abrv, site_abrv)
.Exec_select__rls_auto();
try {
return (rdr.Move_next()) ? new_itm(rdr) : null;
}
finally {rdr.Rls();}
}
public Site_core_itm[] Select_all_downloaded(DateAdp cutoff) {
List_adp list = List_adp_.New();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Clear().Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_core_itm itm = new_itm(rdr);
if (itm.Json_date().compareTo(cutoff) == CompareAble_.More_or_same) continue; // ignore those downloaded after cutoff date
itm.Json_text_null_();
list.Add(itm);
}
}
finally {rdr.Rls();}
return (Site_core_itm[])list.To_ary_and_clear(Site_core_itm.class);
}
private Site_core_itm new_itm(Db_rdr rdr) {
return new Site_core_itm
( rdr.Read_bry_by_str(fld_site_abrv)
, rdr.Read_bry_by_str(fld_site_domain)
, rdr.Read_bool_by_byte(fld_json_completed)
, rdr.Read_date_by_str(fld_json_date)
, rdr.Read_bry_by_str(fld_json_text)
);
}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_extension_itm implements To_str_able {
public Site_extension_itm(byte[] type, byte[] name, byte[] namemsg, byte[] description, byte[] descriptionmsg, byte[] author, byte[] url, byte[] version
, byte[] vcs_system, byte[] vcs_version, byte[] vcs_url, byte[] vcs_date, byte[] license_name, byte[] license, byte[] credits) {
this.type = type; this.name = name; this.namemsg = namemsg; this.description = description; this.descriptionmsg = descriptionmsg; this.author = author; this.url = url; this.version = version;
this.vcs_system = vcs_system; this.vcs_version = vcs_version; this.vcs_url = vcs_url; this.vcs_date = vcs_date; this.license_name = license_name; this.license = license; this.credits = credits;
this.key = Bry_.Add_w_dlm(Byte_ascii.Pipe, type, name);
}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Type() {return type;} private final byte[] type;
public byte[] Name() {return name;} private final byte[] name;
public byte[] Namemsg() {return namemsg;} private final byte[] namemsg;
public byte[] Description() {return description;} private final byte[] description;
public byte[] Descriptionmsg() {return descriptionmsg;} private final byte[] descriptionmsg;
public byte[] Author() {return author;} private final byte[] author;
public byte[] Url() {return url;} private final byte[] url;
public byte[] Version() {return version;} private final byte[] version;
public byte[] Vcs_system() {return vcs_system;} private final byte[] vcs_system;
public byte[] Vcs_version() {return vcs_version;} private final byte[] vcs_version;
public byte[] Vcs_url() {return vcs_url;} private final byte[] vcs_url;
public byte[] Vcs_date() {return vcs_date;} private final byte[] vcs_date;
public byte[] License_name() {return license_name;} private final byte[] license_name;
public byte[] License() {return license;} private final byte[] license;
public byte[] Credits() {return credits;} private final byte[] credits;
public String To_str() {return String_.Concat_with_obj("|", type, name, namemsg, description, descriptionmsg, author, url, version, vcs_system, vcs_version, vcs_url, vcs_date, license_name, license, credits);}
}

View File

@@ -1,114 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_extension_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_type, fld_name, fld_namemsg, fld_description, fld_descriptionmsg, fld_author, fld_url, fld_version
, fld_vcs_system, fld_vcs_version, fld_vcs_url, fld_vcs_date, fld_license_name, fld_license, fld_credits;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_extension_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_type = flds.Add_str("type", 255);
this.fld_name = flds.Add_str("name", 255);
this.fld_namemsg = flds.Add_str("namemsg", 255);
this.fld_description = flds.Add_str("description", 255);
this.fld_descriptionmsg = flds.Add_str("descriptionmsg", 255);
this.fld_author = flds.Add_str("author", 255);
this.fld_url = flds.Add_str("url", 255);
this.fld_version = flds.Add_str("version", 255);
this.fld_vcs_system = flds.Add_str("vcs_system", 255);
this.fld_vcs_version = flds.Add_str("vcs_version", 255);
this.fld_vcs_url = flds.Add_str("vcs_url", 255);
this.fld_vcs_date = flds.Add_str("vcs_date", 255);
this.fld_license_name = flds.Add_str("license_name", 255);
this.fld_license = flds.Add_str("license", 255);
this.fld_credits = flds.Add_str("credits", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_extension";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_type, fld_name)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_extension_itm itm = new Site_extension_itm
( rdr.Read_bry_by_str(fld_type)
, rdr.Read_bry_by_str(fld_name)
, rdr.Read_bry_by_str(fld_namemsg)
, rdr.Read_bry_by_str(fld_description)
, rdr.Read_bry_by_str(fld_descriptionmsg)
, rdr.Read_bry_by_str(fld_author)
, rdr.Read_bry_by_str(fld_url)
, rdr.Read_bry_by_str(fld_version)
, rdr.Read_bry_by_str(fld_vcs_system)
, rdr.Read_bry_by_str(fld_vcs_version)
, rdr.Read_bry_by_str(fld_vcs_url)
, rdr.Read_bry_by_str(fld_vcs_date)
, rdr.Read_bry_by_str(fld_license_name)
, rdr.Read_bry_by_str(fld_license)
, rdr.Read_bry_by_str(fld_credits)
);
list.Add(itm.Key(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_extension_itm itm = (Site_extension_itm)list.Get_at(i);
Insert(site_abrv, itm.Type(), itm.Name(), itm.Namemsg(), itm.Description(), itm.Descriptionmsg(), itm.Author(), itm.Url(), itm.Version()
, itm.Vcs_system(), itm.Vcs_version(), itm.Vcs_url(), itm.Vcs_date(), itm.License_name(), itm.License(), itm.Credits());
}
}
private void Insert(byte[] site_abrv, byte[] type, byte[] name, byte[] namemsg, byte[] description, byte[] descriptionmsg, byte[] author, byte[] url, byte[] version
, byte[] vcs_system, byte[] vcs_version, byte[] vcs_url, byte[] vcs_date, byte[] license_name, byte[] license, byte[] credits) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_type , type)
.Val_bry_as_str(fld_name , name)
.Val_bry_as_str(fld_namemsg , namemsg)
.Val_bry_as_str(fld_description , description)
.Val_bry_as_str(fld_descriptionmsg , descriptionmsg)
.Val_bry_as_str(fld_author , author)
.Val_bry_as_str(fld_url , url)
.Val_bry_as_str(fld_version , version)
.Val_bry_as_str(fld_vcs_system , vcs_system)
.Val_bry_as_str(fld_vcs_version , vcs_version)
.Val_bry_as_str(fld_vcs_url , vcs_url)
.Val_bry_as_str(fld_vcs_date , vcs_date)
.Val_bry_as_str(fld_license_name , license_name)
.Val_bry_as_str(fld_license , license)
.Val_bry_as_str(fld_credits , credits)
.Exec_insert();
}
}

View File

@@ -1,112 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_general_itm implements To_str_able {
public Site_general_itm Ctor(byte[] main_page, byte[] base_url, byte[] site_name, byte[] logo, byte[] generator
, byte[] php_version, byte[] php_sapi, byte[] hhvm_version, byte[] db_type, byte[] db_version
, boolean image_whitelist_enabled, boolean lang_conversion, boolean title_conversion
, byte[] link_prefix_charset, byte[] link_prefix, byte[] link_trail, byte[] legal_title_chars
, byte[] git_hash, byte[] git_branch
, byte[] case_type, byte[] lang, byte[][] fallback, byte[] fallback_8bit_encoding
, boolean write_api, byte[] time_zone, int time_offset
, byte[] article_path, byte[] script_path, byte[] script, byte[] variant_article_path
, byte[] server, byte[] server_name, byte[] wiki_id, byte[] time
, boolean miser_mode, long max_upload_size, int[] thumb_limits, int[] image_limits, byte[] favicon
) {
this.main_page = main_page;
this.base_url = base_url;
this.site_name = site_name;
this.logo = logo;
this.generator = generator;
this.php_version = php_version;
this.php_sapi = php_sapi;
this.hhvm_version = hhvm_version;
this.db_type = db_type;
this.db_version = db_version;
this.image_whitelist_enabled = image_whitelist_enabled;
this.lang_conversion = lang_conversion;
this.title_conversion = title_conversion;
this.link_prefix_charset = link_prefix_charset;
this.link_prefix = link_prefix;
this.link_trail = link_trail;
this.legal_title_chars = legal_title_chars;
this.git_hash = git_hash;
this.git_branch = git_branch;
this.case_type = case_type;
this.lang = lang;
this.fallback = fallback;
this.fallback_8bit_encoding = fallback_8bit_encoding;
this.write_api = write_api;
this.time_zone = time_zone;
this.time_offset = time_offset;
this.article_path = article_path;
this.script_path = script_path;
this.script = script;
this.variant_article_path = variant_article_path;
this.server = server;
this.server_name = server_name;
this.wiki_id = wiki_id;
this.time = time;
this.miser_mode = miser_mode;
this.max_upload_size = max_upload_size;
this.thumb_limits = thumb_limits;
this.image_limits = image_limits;
this.favicon = favicon;
return this;
}
public byte[] Main_page() {return main_page;} private byte[] main_page;
public byte[] Base_url() {return base_url;} private byte[] base_url;
public byte[] Site_name() {return site_name;} private byte[] site_name;
public byte[] Logo() {return logo;} private byte[] logo;
public byte[] Generator() {return generator;} private byte[] generator;
public byte[] Php_version() {return php_version;} private byte[] php_version;
public byte[] Php_sapi() {return php_sapi;} private byte[] php_sapi;
public byte[] Hhvm_version() {return hhvm_version;} private byte[] hhvm_version;
public byte[] Db_type() {return db_type;} private byte[] db_type;
public byte[] Db_version() {return db_version;} private byte[] db_version;
public boolean Image_whitelist_enabled() {return image_whitelist_enabled;} private boolean image_whitelist_enabled;
public boolean Lang_conversion() {return lang_conversion;} private boolean lang_conversion;
public boolean Title_conversion() {return title_conversion;} private boolean title_conversion;
public byte[] Link_prefix_charset() {return link_prefix_charset;} private byte[] link_prefix_charset;
public byte[] Link_prefix() {return link_prefix;} private byte[] link_prefix;
public byte[] Link_trail() {return link_trail;} private byte[] link_trail;
public byte[] Legal_title_chars() {return legal_title_chars;} private byte[] legal_title_chars;
public byte[] Git_hash() {return git_hash;} private byte[] git_hash;
public byte[] Git_branch() {return git_branch;} private byte[] git_branch;
public byte[] Case_type() {return case_type;} private byte[] case_type;
public byte[] Lang() {return lang;} private byte[] lang;
public byte[][] Fallback() {return fallback;} private byte[][] fallback;
public byte[] Fallback_8bit_encoding() {return fallback_8bit_encoding;} private byte[] fallback_8bit_encoding;
public boolean Write_api() {return write_api;} private boolean write_api;
public byte[] Time_zone() {return time_zone;} private byte[] time_zone;
public int Time_offset() {return time_offset;} private int time_offset;
public byte[] Article_path() {return article_path;} private byte[] article_path;
public byte[] Script_path() {return script_path;} private byte[] script_path;
public byte[] Script() {return script;} private byte[] script;
public byte[] Variant_article_path() {return variant_article_path;} private byte[] variant_article_path;
public byte[] Server() {return server;} private byte[] server;
public byte[] Server_name() {return server_name;} private byte[] server_name;
public byte[] Wiki_id() {return wiki_id;} private byte[] wiki_id;
public byte[] Time() {return time;} private byte[] time;
public boolean Miser_mode() {return miser_mode;} private boolean miser_mode;
public long Max_upload_size() {return max_upload_size;} private long max_upload_size;
public int[] Thumb_limits() {return thumb_limits;} private int[] thumb_limits;
public int[] Image_limits() {return image_limits;} private int[] image_limits;
public byte[] Favicon() {return favicon;} private byte[] favicon;
public String To_str() {return "";}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_interwikimap_itm implements To_str_able {
public Site_interwikimap_itm(byte[] prefix, boolean local
, boolean extralanglink, byte[] linktext, byte[] sitename
, byte[] language, boolean localinterwiki, byte[] url, boolean protorel) {
this.Prefix = prefix;
this.Local = local;
this.Extralanglink = extralanglink;
this.Linktext = linktext;
this.Sitename = sitename;
this.Language = language;
this.Localinterwiki = localinterwiki;
this.Url = url;
this.Protorel = protorel;
}
public final byte[] Prefix;
public final boolean Local;
public final boolean Extralanglink;
public final byte[] Linktext;
public final byte[] Sitename;
public final byte[] Language;
public final boolean Localinterwiki;
public final byte[] Url;
public final boolean Protorel;
public String To_str() {return String_.Concat_with_obj("|", Prefix, Local, Extralanglink, Linktext, Sitename, Language, Localinterwiki, Url, Protorel);}
}

View File

@@ -1,93 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_interwikimap_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_prefix, fld_local, fld_extralanglink, fld_linktext, fld_sitename, fld_language, fld_localinterwiki, fld_url, fld_protorel;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_interwikimap_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_prefix = flds.Add_str("prefix", 255);
this.fld_local = flds.Add_bool("local");
this.fld_extralanglink = flds.Add_bool("extralanglink");
this.fld_linktext = flds.Add_str("linktext", 255);
this.fld_sitename = flds.Add_str("sitename", 255);
this.fld_language = flds.Add_str("language", 255);
this.fld_localinterwiki = flds.Add_bool("localinterwiki");
this.fld_url = flds.Add_str("url", 255);
this.fld_protorel = flds.Add_bool("protorel");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_interwikimap";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_prefix)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_interwikimap_itm itm = new Site_interwikimap_itm
( rdr.Read_bry_by_str(fld_prefix)
, rdr.Read_bool_by_byte(fld_local)
, rdr.Read_bool_by_byte(fld_extralanglink)
, rdr.Read_bry_by_str(fld_linktext)
, rdr.Read_bry_by_str(fld_sitename)
, rdr.Read_bry_by_str(fld_language)
, rdr.Read_bool_by_byte(fld_localinterwiki)
, rdr.Read_bry_by_str(fld_url)
, rdr.Read_bool_by_byte(fld_protorel)
);
list.Add(itm.Prefix, itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_interwikimap_itm itm = (Site_interwikimap_itm)list.Get_at(i);
Insert(site_abrv, itm.Prefix, itm.Local, itm.Extralanglink, itm.Linktext, itm.Sitename, itm.Language, itm.Localinterwiki, itm.Url, itm.Protorel);
}
}
private void Insert(byte[] site_abrv, byte[] prefix, boolean local, boolean extralanglink, byte[] linktext, byte[] sitename, byte[] language, boolean localinterwiki, byte[] url, boolean protorel) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_prefix , prefix)
.Val_bool_as_byte(fld_local , local)
.Val_bool_as_byte(fld_extralanglink , extralanglink)
.Val_bry_as_str(fld_linktext , linktext)
.Val_bry_as_str(fld_sitename , sitename)
.Val_bry_as_str(fld_language , language)
.Val_bool_as_byte(fld_localinterwiki , localinterwiki)
.Val_bry_as_str(fld_url , url)
.Val_bool_as_byte(fld_protorel , protorel)
.Exec_insert();
}
}

View File

@@ -1,66 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.core.net.*; import gplx.dbs.cfgs.*;
import gplx.langs.jsons.*;
class Site_json_fetcher {
private Gfo_usr_dlg usr_dlg; private Gfo_inet_conn inet_conn; private String domain_str; private Db_cfg_tbl cfg_tbl;
private Io_url default_url;
public void Init(Gfo_usr_dlg usr_dlg, Gfo_inet_conn inet_conn, String domain_str, Db_cfg_tbl cfg_tbl, Io_url default_url) {
this.usr_dlg = usr_dlg;
this.inet_conn = inet_conn;
this.domain_str = domain_str;
this.cfg_tbl = cfg_tbl;
this.default_url = default_url;
}
public void Init_by_wiki(Xow_wiki wiki) {
Xoa_app app = wiki.App();
this.usr_dlg = app.Usr_dlg();
this.inet_conn = app.Utl__inet_conn();
this.domain_str = wiki.Domain_str();
this.cfg_tbl = wiki.Data__core_mgr().Tbl__cfg();
this.default_url = app.Fsys_mgr().Bin_xowa_dir().GenSubFil_nest("cfg", "wiki", "api", "xowa_default.json");
}
public byte[] Get_json(Io_url custom_url) {
byte[] rv = null;
int trial = 0;
while (true) {
switch (trial) {
case 0: rv = Get_json_from_fs(custom_url); break;
case 1: rv = Get_json_from_db(cfg_tbl); break;
case 2: rv = Get_json_from_wm(usr_dlg, inet_conn, domain_str, cfg_tbl); break;
case 3: rv = Get_json_from_fs(default_url); break;
default: throw Err_.new_("api.site", "could not find site json", "wiki", domain_str);
}
if (rv == null)
++trial;
else
break;
}
return rv;
}
private byte[] Get_json_from_fs(Io_url url) {return url == null ? null : Io_mgr.Instance.LoadFilBryOrNull(url);}
private byte[] Get_json_from_db(Db_cfg_tbl cfg_tbl) {return cfg_tbl.Select_bry(Cfg_grp__xowa_bldr_api, Cfg_key__xowa_bldr_api__data);}
private byte[] Get_json_from_wm(Gfo_usr_dlg usr_dlg, Gfo_inet_conn inet_conn, String domain_str, Db_cfg_tbl cfg_tbl) {
String api_str = "action=query&format=json&meta=siteinfo&siprop=general|namespaces|statistics|interwikimap|namespacealiases|specialpagealiases|libraries|extensions|skins|magicwords|functionhooks|showhooks|extensiontags|protocols|defaultoptions|languages";
byte[] rv = Xowm_api_mgr.Call_by_qarg(usr_dlg, inet_conn, domain_str, api_str);
if (rv != null) cfg_tbl.Assert_bry(Cfg_grp__xowa_bldr_api, Cfg_key__xowa_bldr_api__data, rv);
return rv;
}
private static final String Cfg_grp__xowa_bldr_api = "xowa.bldr.api", Cfg_key__xowa_bldr_api__data = "data";
}

View File

@@ -1,104 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.core.primitives.*; import gplx.langs.jsons.*;
public class Site_json_parser {
private final Json_parser json_parser;
private final Json_parser__list_nde__base parser__basic = new Json_parser__list_nde__base();
private final Site_meta_parser__general parser__general = new Site_meta_parser__general();
private final Site_meta_parser__namespace parser__namespace = new Site_meta_parser__namespace();
private final Site_meta_parser__statistic parser__statistic = new Site_meta_parser__statistic();
private final Site_meta_parser__interwikimap parser__interwiki = new Site_meta_parser__interwikimap();
private final Site_meta_parser__namespacealias parser__namespacealias = new Site_meta_parser__namespacealias();
private final Site_meta_parser__specialpagealias parser__specialpagealias = new Site_meta_parser__specialpagealias();
private final Site_meta_parser__library parser__library = new Site_meta_parser__library();
private final Site_meta_parser__extension parser__extension = new Site_meta_parser__extension();
private final Site_meta_parser__skin parser__skin = new Site_meta_parser__skin();
private final Site_meta_parser__magicword parser__magicword = new Site_meta_parser__magicword();
private final Site_meta_parser__showhook parser__showhook = new Site_meta_parser__showhook();
private final Site_meta_parser__language parser__language = new Site_meta_parser__language();
public Site_json_parser(Json_parser json_parser) {this.json_parser = json_parser;}
public void Parse_root(Site_meta_itm rv, String context, byte[] src) {
Json_doc jdoc = json_parser.Parse(src);
Parse_root(rv, context, jdoc.Root_nde().Get_at_as_kv(0).Val_as_nde());
}
public void Parse_root(Site_meta_itm rv, String context, Json_nde root) {
int len = root.Len();
for (int i = 0; i < len; ++i) {
Json_kv sub = root.Get_at_as_kv(i);
Parse_node(rv, context, sub);
}
}
private void Parse_node(Site_meta_itm rv, String context, Json_kv sub) {
byte[] sub_key = sub.Key_as_bry();
switch (nde_hash.Get_as_int(sub_key)) {
case Tid_general : parser__general.Parse(context, rv.General_list(), sub.Val_as_nde()); break;
case Tid_namespace : parser__namespace.Parse(context, rv.Namespace_list(), sub.Val_as_nde()); break;
case Tid_statistic : parser__statistic.Parse(context, rv.Statistic_itm(), sub.Val_as_nde()); break;
case Tid_interwikimap : parser__interwiki.Parse(context, rv.Interwikimap_list(), sub.Val_as_ary()); break;
case Tid_namespacealias : parser__namespacealias.Parse(context, rv.Namespacealias_list(), sub.Val_as_ary()); break;
case Tid_specialpagealias : parser__specialpagealias.Parse(context, rv.Specialpagealias_list(), sub.Val_as_ary()); break;
case Tid_library : parser__library.Parse(context, rv.Library_list(), sub.Val_as_ary()); break;
case Tid_extension : parser__extension.Parse(context, rv.Extension_list(), sub.Val_as_ary()); break;
case Tid_skin : parser__skin.Parse(context, rv.Skin_list(), sub.Val_as_ary()); break;
case Tid_magicword : parser__magicword.Parse(context, rv.Magicword_list(), sub.Val_as_ary()); break;
case Tid_functionhook : parser__basic.Parse_to_list_as_bry(context, sub.Val_as_ary(), rv.Functionhook_list()); break;
case Tid_showhook : parser__showhook.Parse(context, rv.Showhook_list(), sub.Val_as_ary()); break;
case Tid_extensiontag : parser__basic.Parse_to_list_as_bry(context, sub.Val_as_ary(), rv.Extensiontag_list()); break;
case Tid_protocol : parser__basic.Parse_to_list_as_bry(context, sub.Val_as_ary(), rv.Protocol_list()); break;
case Tid_defaultoption : parser__basic.Parse_to_list_as_kv(context, sub.Val_as_nde(), rv.Defaultoption_list()); break;
case Tid_language : parser__language.Parse(context, rv.Language_list(), sub.Val_as_ary()); break;
}
}
private static final int
Tid_general = 0
, Tid_namespace = 1
, Tid_statistic = 2
, Tid_interwikimap = 3
, Tid_namespacealias = 4
, Tid_specialpagealias = 5
, Tid_library = 6
, Tid_extension = 7
, Tid_skin = 8
, Tid_magicword = 9
, Tid_functionhook = 10
, Tid_showhook = 11
, Tid_extensiontag = 12
, Tid_protocol = 13
, Tid_defaultoption = 14
, Tid_language = 15
;
private static final Hash_adp_bry nde_hash = Hash_adp_bry.cs()
.Add_str_int("general" , Tid_general)
.Add_str_int("namespaces" , Tid_namespace)
.Add_str_int("statistics" , Tid_statistic)
.Add_str_int("interwikimap" , Tid_interwikimap)
.Add_str_int("namespacealiases" , Tid_namespacealias)
.Add_str_int("specialpagealiases" , Tid_specialpagealias)
.Add_str_int("libraries" , Tid_library)
.Add_str_int("extensions" , Tid_extension)
.Add_str_int("skins" , Tid_skin)
.Add_str_int("magicwords" , Tid_magicword)
.Add_str_int("functionhooks" , Tid_functionhook)
.Add_str_int("showhooks" , Tid_showhook)
.Add_str_int("extensiontags" , Tid_extensiontag)
.Add_str_int("protocols" , Tid_protocol)
.Add_str_int("defaultoptions" , Tid_defaultoption)
.Add_str_int("languages" , Tid_language)
;
}

View File

@@ -1,431 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import org.junit.*; import gplx.langs.jsons.*; import gplx.xowa.wikis.nss.*;
public class Site_json_parser_tst {
private final Site_json_parser_fxt fxt = new Site_json_parser_fxt();
@Before public void init() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();}
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
@Test public void General() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'general':"
, " { 'mainpage': 'Main Page'"
, " , 'imagewhitelistenabled': ''"
, " , 'timeoffset': 0"
, " , 'thumblimits': "
, " [ 120"
, " , 150"
, " ]"
, " , 'imagelimits': "
, " [ "
, " { 'width': 320"
, " , 'height': 240"
, " }"
, " , "
, " { 'width': 640"
, " , 'height': 480"
, " }"
, " ]"
, " }"
, "}"
));
fxt.Test_general(Keyval_.new_("mainpage", "Main Page"), Keyval_.new_("imagewhitelistenabled", ""), Keyval_.new_("timeoffset", "0"), Keyval_.new_("thumblimits", "120|150"), Keyval_.new_("imagelimits", "320=240|640=480"));
}
@Test public void Namespace() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'namespaces':"
, " { '0':"
, " { 'id': 0"
, " , 'case': 'first-letter'"
, " , 'content': ''"
, " , '*': ''"
, " }"
, " , '2': "
, " { 'id': 2"
, " , 'case': 'first-letter'"
, " , 'subpages': ''"
, " , 'canonical': 'User'"
, " , '*': 'User'"
, " }"
, " ,'4': "
, " { 'id': 4"
, " , 'case': 'first-letter'"
, " , 'subpages': ''"
, " , 'canonical': 'Project'"
, " , '*': 'Wikipedia'"
, " }"
, " ,'2600': "
, " { 'id': 2600"
, " , 'case': 'case-sensitive'"
, " , 'canonical': 'Topic'"
, " , 'defaultcontentmodel': 'flow-board'"
, " , '*': 'Topic'"
, " }"
, " }"
, "}"
));
fxt.Test_namespace
( fxt.Make_namespace(0 , Bool_.N, null , "" , Bool_.N, Bool_.Y, null)
, fxt.Make_namespace(2 , Bool_.N, "User" , "User" , Bool_.Y, Bool_.N, null)
, fxt.Make_namespace(4 , Bool_.N, "Project" , "Wikipedia" , Bool_.Y, Bool_.N, null)
, fxt.Make_namespace(2600 , Bool_.Y, "Topic" , "Topic" , Bool_.N, Bool_.N, "flow-board")
);
}
@Test public void Statistic() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'statistics':"
, " { 'pages': 1"
, " , 'articles': 2"
, " , 'edits': 3"
, " , 'images': 4"
, " , 'users': 5"
, " , 'activeusers': 6"
, " , 'admins': 7"
, " , 'jobs': 8"
, " , 'queued-massmessages': 9"
, " }"
, "}"
));
fxt.Test_statistic
( fxt.Make_statistic(1, 2, 3, 4, 5, 6, 7, 8, 9)
);
}
@Test public void Interwikimap() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'interwikimap':"
, " ["
, " { 'prefix': 'aquariumwiki'"
, " , 'url': 'http://www.theaquariumwiki.com/$1'"
, " }"
, " , { 'prefix': 'ar'"
, " , 'local': ''"
, " , 'extralanglink': ''"
, " , 'linktext': 'More languages'"
, " , 'sitename': 'Multilingual Wikisource'"
, " , 'language': '\u0627\u0644\u0639\u0631\u0628\u064a\u0629'"
, " , 'url': 'https://ar.wikipedia.org/wiki/$1'"
, " , 'protorel': ''"
, " }"
, " ]"
, "}"
));
fxt.Test_interwikimap
( fxt.Make_interwikimap("aquariumwiki" , Bool_.N, Bool_.N, null , null , null , Bool_.N, "http://www.theaquariumwiki.com/$1" , Bool_.N)
, fxt.Make_interwikimap("ar" , Bool_.Y, Bool_.Y, "More languages", "Multilingual Wikisource" , "العربية" , Bool_.N, "https://ar.wikipedia.org/wiki/$1" , Bool_.Y)
);
}
@Test public void Namespacealias() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'namespacealiases':"
, " [ "
, " { 'id': 4"
, " , '*': 'WP'"
, " }"
, " , "
, " { 'id': 7"
, " , '*': 'Image talk'"
, " }"
, " ]"
, "}"
));
fxt.Test_namespacealias
( fxt.Make_namespacealias(4 ,"WP")
, fxt.Make_namespacealias(7 , "Image talk")
);
}
@Test public void Specialpagealias() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'specialpagealiases':"
, " [ "
, " { 'realname': 'BrokenRedirects'"
, " , 'aliases': "
, " [ 'BrokenRedirects'"
, " ]"
, " }"
, " , "
, " { 'realname': 'Lonelypages'"
, " , 'aliases': "
, " [ 'LonelyPages'"
, " , 'OrphanedPages'"
, " ]"
, " }"
, " ]"
, "}"
));
fxt.Test_specialpagealias
( fxt.Make_specialpagealias("BrokenRedirects" , "BrokenRedirects")
, fxt.Make_specialpagealias("Lonelypages" , "LonelyPages", "OrphanedPages")
);
}
@Test public void Library() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'libraries':"
, " [ "
, " { 'name': 'cssjanus/cssjanus'"
, " , 'version': '1.1.1'"
, " }"
, " , "
, " { 'name': 'leafo/lessphp'"
, " , 'version': '0.5.0'"
, " }"
, " ]"
, "}"
));
fxt.Test_library
( fxt.Make_library("cssjanus/cssjanus" , "1.1.1")
, fxt.Make_library("leafo/lessphp" , "0.5.0")
);
}
@Test public void Extension() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'extensions':"
, " [ "
, " { 'type': 'media'"
, " , 'name': 'PagedTiffHandler'"
, " , 'descriptionmsg': 'tiff-desc'"
, " , 'author': '[http://www.hallowelt.biz HalloWelt! Medienwerkstatt GmbH], Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser for Wikimedia Deutschland'"
, " , 'url': 'https://www.mediawiki.org/wiki/Extension:PagedTiffHandler'"
, " , 'vcs-system': 'git'"
, " , 'vcs-version': 'b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba'"
, " , 'vcs-url': 'https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FPagedTiffHandler.git/b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba'"
, " , 'vcs-date': '2015-03-27T16:44:25Z'"
, " , 'license-name': 'GPL-2.0+'"
, " , 'license': '/wiki/Special:Version/License/PagedTiffHandler'"
, " }"
, " , "
, " { 'type': 'media'"
, " , 'name': 'A'"
, " , 'namemsg': 'A-name'"
, " , 'description': 'desc'"
, " , 'descriptionmsg': 'A-desc'"
, " , 'author': 'B'"
, " , 'url': 'C'"
, " , 'version': '0.1.0'"
, " , 'vcs-system': 'git'"
, " , 'vcs-version': 'd'"
, " , 'vcs-url': 'e'"
, " , 'vcs-date': '2015-03-27T16:44:25Z'"
, " , 'license-name': 'f'"
, " , 'license': 'g'"
, " }"
, " ]"
, "}"
));
fxt.Test_extension
( fxt.Make_extension("media", "PagedTiffHandler", "", "", "tiff-desc", "[http://www.hallowelt.biz HalloWelt! Medienwerkstatt GmbH], Sebastian Ulbricht, Daniel Lynge, Marc Reymann, Markus Glaser for Wikimedia Deutschland", "https://www.mediawiki.org/wiki/Extension:PagedTiffHandler", null, "git", "b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba", "https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FPagedTiffHandler.git/b4a6c2077e3ea70cb0295b2282fe45d2e9ae06ba", "2015-03-27T16:44:25Z", "GPL-2.0+", "/wiki/Special:Version/License/PagedTiffHandler", null)
, fxt.Make_extension("media", "A", "A-name", "desc", "A-desc", "B", "C", "0.1.0", "git", "d", "e", "2015-03-27T16:44:25Z", "f", "g", null)
);
}
@Test public void Skin() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'skins':"
, " [ "
, " { 'code': 'vector'"
, " , 'default': ''"
, " , '*': 'Vector'"
, " }"
, " , "
, " { 'code': 'monobook'"
, " , '*': 'MonoBook'"
, " }"
, " , "
, " { 'code': 'fallback'"
, " , 'unusable': ''"
, " , '*': 'Fallback'"
, " }"
, " ]"
, "}"
));
fxt.Test_skin
( fxt.Make_skin("vector" , Bool_.Y, "Vector" , Bool_.N)
, fxt.Make_skin("monobook" , Bool_.N, "MonoBook" , Bool_.N)
, fxt.Make_skin("fallback" , Bool_.N, "Fallback" , Bool_.Y)
);
}
@Test public void Magicword() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'magicwords':"
, " [ "
, " { 'name': 'expr'"
, " , 'aliases': "
, " [ 'expr'"
, " ]"
, " }"
, " , "
, " { 'name': 'currentmonth'"
, " , 'aliases': "
, " [ 'CURRENTMONTH'"
, " , 'CURRENTMONTH2'"
, " ]"
, " , 'case-sensitive': ''"
, " }"
, " ]"
, "}"
));
fxt.Test_magicword
( fxt.Make_magicword("expr" , Bool_.N, "expr")
, fxt.Make_magicword("currentmonth" , Bool_.Y, "CURRENTMONTH", "CURRENTMONTH2")
);
}
@Test public void Functionhook() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'functionhooks':"
, " [ 'ns'"
, " , 'nse'"
, " ]"
, "}"
));
fxt.Test_functionhook("ns", "nse");
}
@Test public void Showhook() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'showhooks':"
, " [ "
, " { 'name': 'APIAfterExecute'"
, " , 'subscribers': "
, " [ 'ApiParseExtender::onAPIAfterExecute'"
, " , 'ZeroBanner\\\\MccMncLogging::onAPIAfterExecute'"
, " , 'XAnalytics::onAPIAfterExecute'"
, " ]"
, " }"
, " , "
, " { 'name': 'ParserLimitReport'"
, " , 'subscribers': "
, " { 'scribunto': 'ScribuntoHooks::reportLimits'"
, " }"
, " }"
, " ]"
, "}"
));
fxt.Test_showhook
( fxt.Make_showhook("APIAfterExecute" , "", "ApiParseExtender::onAPIAfterExecute", "ZeroBanner\\MccMncLogging::onAPIAfterExecute", "XAnalytics::onAPIAfterExecute")
, fxt.Make_showhook("ParserLimitReport" , "ScribuntoHooks::reportLimits")
);
}
@Test public void Extensiontag() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'extensiontags':"
, " [ '<pre>'"
, " , '<nowiki>'"
, " ]"
, "}"
));
fxt.Test_extensiontag("<pre>", "<nowiki>");
}
@Test public void Protocol() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'protocols':"
, " [ 'bitcoin:'"
, " , 'ftp://'"
, " ]"
, "}"
));
fxt.Test_protocol("bitcoin:", "ftp://");
}
@Test public void Defaultoption() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'defaultoptions':"
, " { 'globaluserpage': true"
, " , 'cols': 80"
, " , 'echo-email-format': 'html'"
, " }"
, "}"
));
fxt.Test_defaultoption(Keyval_.new_("globaluserpage", "true"), Keyval_.new_("cols", "80"), Keyval_.new_("echo-email-format", "html"));
}
@Test public void Language() {
fxt.Exec_parse(String_.Concat_lines_nl_skip_last
( "{ 'languages':"
, " [ "
, " { 'code': 'aa'"
, " , '*': 'Qaf\u00e1r af'"
, " }"
, " , "
, " { 'code': 'ab'"
, " , '*': '\u0410\u04a7\u0441\u0448\u04d9\u0430'"
, " }"
, " ]"
, "}"
));
fxt.Test_language
( fxt.Make_language("aa" , "Qafár af")
, fxt.Make_language("ab" , "Аҧсшәа")
);
}
// @Test public void Smoke() {
// Io_url json_url = Tfds.RscDir.GenSubFil_nest("400_xowa", "site_meta__en.wikipedia.org.json");
// byte[] src = Io_mgr.Instance.LoadFilBry(json_url);
// Site_json_parser parser = new Site_json_parser();
// Site_meta_itm meta_itm = new Site_meta_itm();
// parser.Parse_root(meta_itm, "en.wikipedia.org", src);
// gplx.dbs.Db_conn_bldr.Instance.Reg_default_sqlite();
// Site_core_db core_db = new Site_core_db(Tfds.RscDir.GenSubFil_nest("400_xowa", "site_meta.sqlite3"));
// core_db.Save(meta_itm, Bry_.new_a7("en.w"));
// }
}
class Site_json_parser_fxt {
private final Json_parser json_parser = new Json_parser();
private final Site_json_parser site_meta_parser;
private Site_meta_itm site_meta;
public Site_json_parser_fxt() {
this.site_meta_parser = new Site_json_parser(json_parser);
}
public void Exec_parse(String raw) {
Json_doc jdoc = json_parser.Parse_by_apos(raw);
site_meta = new Site_meta_itm();
site_meta_parser.Parse_root(site_meta, "en.wikipedia.org", jdoc.Root_nde());
}
public Site_namespace_itm Make_namespace(int id, boolean case_tid_is_cs, String canonical, String localized, boolean subpages, boolean content, String defaultcontentmodel) {
return new Site_namespace_itm(id, case_tid_is_cs ? Xow_ns_case_.Bry__all : Xow_ns_case_.Bry__1st, Bry_.new_u8_safe(canonical), Bry_.new_u8_safe(localized), subpages, content, Bry_.new_u8_safe(defaultcontentmodel));
}
public Site_statistic_itm Make_statistic(long pages, long articles, long edits, long images, long users, long activeusers, long admins, long jobs, long queued_massmessages) {return new Site_statistic_itm().Ctor(pages, articles, edits, images, users, activeusers, admins, jobs, queued_massmessages);}
public Site_interwikimap_itm Make_interwikimap(String prefix, boolean local, boolean extralanglink, String linktext, String sitename, String language, boolean localinterwiki, String url, boolean protorel) {
return new Site_interwikimap_itm(Bry_.new_u8_safe(prefix), local, extralanglink, Bry_.new_u8_safe(linktext), Bry_.new_u8_safe(sitename), Bry_.new_u8_safe(language), localinterwiki, Bry_.new_u8_safe(url), protorel);
}
public Site_namespacealias_itm Make_namespacealias(int id, String alias) {return new Site_namespacealias_itm(id, Bry_.new_u8_safe(alias));}
public Site_specialpagealias_itm Make_specialpagealias(String realname, String... aliases) {return new Site_specialpagealias_itm(Bry_.new_u8_safe(realname), Bry_.Ary(aliases));}
public Site_library_itm Make_library(String name, String version) {return new Site_library_itm(Bry_.new_u8_safe(name), Bry_.new_u8_safe(version));}
public Site_extension_itm Make_extension
( String type, String name, String namemsg, String description, String descriptionmsg, String author, String url, String version
, String vcs_system, String vcs_version, String vcs_url, String vcs_date, String license_name, String license, String credits) {
return new Site_extension_itm
( Bry_.new_u8_safe(type), Bry_.new_u8_safe(name), Bry_.new_u8_safe(namemsg), Bry_.new_u8_safe(description), Bry_.new_u8_safe(descriptionmsg), Bry_.new_u8_safe(author), Bry_.new_u8_safe(url), Bry_.new_u8_safe(version)
, Bry_.new_u8_safe(vcs_system), Bry_.new_u8_safe(vcs_version), Bry_.new_u8_safe(vcs_url), Bry_.new_u8_safe(vcs_date), Bry_.new_u8_safe(license_name), Bry_.new_u8_safe(license), Bry_.new_u8_safe(credits)
);
}
public Site_skin_itm Make_skin(String code, boolean dflt, String name, boolean unusable) {return new Site_skin_itm(Bry_.new_u8_safe(code), dflt, Bry_.new_u8_safe(name), unusable);}
public Site_magicword_itm Make_magicword(String name, boolean case_match, String... aliases) {return new Site_magicword_itm(Bry_.new_u8_safe(name), case_match, Bry_.Ary(aliases));}
public Site_showhook_itm Make_showhook(String name, String scribunto, String... subscribers) {return new Site_showhook_itm(Bry_.new_u8_safe(name), Bry_.new_u8_safe(scribunto), Bry_.Ary(subscribers));}
public Site_language_itm Make_language(String code, String name) {return new Site_language_itm(Bry_.new_u8_safe(code), Bry_.new_u8_safe(name));}
public void Test_general(Keyval... expd) {Tfds.Eq_ary_str(expd, (Keyval[])site_meta.General_list().To_ary(Keyval.class));}
public void Test_namespace(Site_namespace_itm... expd) {Tfds.Eq_ary_str(expd, (Site_namespace_itm[])site_meta.Namespace_list().To_ary(Site_namespace_itm.class));}
public void Test_statistic(Site_statistic_itm expd) {Tfds.Eq_str_intf(expd, site_meta.Statistic_itm());}
public void Test_interwikimap(Site_interwikimap_itm... expd) {Tfds.Eq_ary_str(expd, (Site_interwikimap_itm[])site_meta.Interwikimap_list().To_ary(Site_interwikimap_itm.class));}
public void Test_namespacealias(Site_namespacealias_itm... expd) {Tfds.Eq_ary_str(expd, (Site_namespacealias_itm[])site_meta.Namespacealias_list().To_ary(Site_namespacealias_itm.class));}
public void Test_specialpagealias(Site_specialpagealias_itm... expd) {Tfds.Eq_ary_str(expd, (Site_specialpagealias_itm[])site_meta.Specialpagealias_list().To_ary(Site_specialpagealias_itm.class));}
public void Test_library(Site_library_itm... expd) {Tfds.Eq_ary_str(expd, (Site_library_itm[])site_meta.Library_list().To_ary(Site_library_itm.class));}
public void Test_extension(Site_extension_itm... expd) {Tfds.Eq_ary_str(expd, (Site_extension_itm[])site_meta.Extension_list().To_ary(Site_extension_itm.class));}
public void Test_skin(Site_skin_itm... expd) {Tfds.Eq_ary_str(expd, (Site_skin_itm[])site_meta.Skin_list().To_ary(Site_skin_itm.class));}
public void Test_magicword(Site_magicword_itm... expd) {Tfds.Eq_ary_str(expd, (Site_magicword_itm[])site_meta.Magicword_list().To_ary(Site_magicword_itm.class));}
public void Test_functionhook(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Functionhook_list().To_ary(byte[].class)));}
public void Test_showhook(Site_showhook_itm... expd) {Tfds.Eq_ary_str(expd, (Site_showhook_itm[])site_meta.Showhook_list().To_ary(Site_showhook_itm.class));}
public void Test_extensiontag(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Extensiontag_list().To_ary(byte[].class)));}
public void Test_protocol(String... expd) {Tfds.Eq_ary_str(expd, String_.Ary((byte[][])site_meta.Protocol_list().To_ary(byte[].class)));}
public void Test_defaultoption(Keyval... expd) {Tfds.Eq_ary_str(expd, (Keyval[])site_meta.Defaultoption_list().To_ary(Keyval.class));}
public void Test_language(Site_language_itm... expd) {Tfds.Eq_ary_str(expd, (Site_language_itm[])site_meta.Language_list().To_ary(Site_language_itm.class));}
}

View File

@@ -1,23 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_kv_itm {
public Site_kv_itm(byte[] key, byte[] val) {this.key = key; this.val = val;}
public byte[] Key() {return key;} private final byte[] key;
public byte[] Val() {return val;} private final byte[] val;
}

View File

@@ -1,70 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_kv_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_key, fld_val;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_kv_tbl(Db_conn conn, String tbl_name) {
this.conn = conn; this.tbl_name = tbl_name;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_key = flds.Add_str("key", 255);
this.fld_val = flds.Add_str("val", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_key)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
String key = rdr.Read_str(fld_key);
String val = rdr.Read_str(fld_val);
list.Add(key, Keyval_.new_(key, val));
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Keyval itm = (Keyval)list.Get_at(i);
Insert(site_abrv, itm.Key(), itm.Val_to_str_or_empty());
}
}
private void Insert(byte[] site_abrv, String key, String val) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_str(fld_key , key)
.Val_str(fld_val , val)
.Exec_insert();
}
}

View File

@@ -1,24 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_language_itm implements To_str_able {
public Site_language_itm(byte[] code, byte[] name) {this.code = code; this.name = name;}
public byte[] Code() {return code;} private final byte[] code;
public byte[] Name() {return name;} private final byte[] name;
public String To_str() {return String_.Concat_with_obj("|", code, name);}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_language_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_code, fld_name;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_language_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_code = flds.Add_str("code", 255);
this.fld_name = flds.Add_str("name", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_language";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_code)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_language_itm itm = new Site_language_itm
( rdr.Read_bry_by_str(fld_code)
, rdr.Read_bry_by_str(fld_name)
);
list.Add(itm.Code(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_language_itm itm = (Site_language_itm)list.Get_at(i);
Insert(site_abrv, itm.Code(), itm.Name());
}
}
private void Insert(byte[] site_abrv, byte[] code, byte[] name) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_code , code)
.Val_bry_as_str(fld_name , name)
.Exec_insert();
}
}

View File

@@ -1,24 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_library_itm implements To_str_able {
public Site_library_itm(byte[] name, byte[] version) {this.name = name; this.version = version;}
public byte[] Name() {return name;} private final byte[] name;
public byte[] Version() {return version;} private final byte[] version;
public String To_str() {return String_.Concat_with_obj("|", name, version);}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_library_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_name, fld_version;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_library_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_name = flds.Add_str("name", 255);
this.fld_version = flds.Add_str("version", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_library";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_name)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_library_itm itm = new Site_library_itm
( rdr.Read_bry_by_str(fld_name)
, rdr.Read_bry_by_str(fld_version)
);
list.Add(itm.Name(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_library_itm itm = (Site_library_itm)list.Get_at(i);
Insert(site_abrv, itm.Name(), itm.Version());
}
}
private void Insert(byte[] site_abrv, byte[] name, byte[] version) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_name , name)
.Val_bry_as_str(fld_version , version)
.Exec_insert();
}
}

View File

@@ -1,27 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_magicword_itm implements To_str_able {
public Site_magicword_itm(byte[] name, boolean case_match, byte[][] aliases) {
this.name = name; this.case_match = case_match; this.aliases = aliases;
}
public byte[] Name() {return name;} private final byte[] name;
public boolean Case_match() {return case_match;} private final boolean case_match;
public byte[][] Aliases() {return aliases;} private final byte[][] aliases;
public String To_str() {return String_.Concat_with_obj("|", case_match, name, String_.Concat_with_obj(";", (Object[])aliases));}
}

View File

@@ -1,75 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_magicword_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_name, fld_case_match, fld_aliases;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_magicword_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_name = flds.Add_str("name", 255);
this.fld_case_match = flds.Add_bool("case_match");
this.fld_aliases = flds.Add_str("aliases", 2048);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_magicword";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_name)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_magicword_itm itm = new Site_magicword_itm
( rdr.Read_bry_by_str(fld_name)
, rdr.Read_bool_by_byte(fld_case_match)
, Bry_split_.Split(rdr.Read_bry_by_str(fld_aliases), Byte_ascii.Pipe_bry)
);
list.Add(itm.Name(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_magicword_itm itm = (Site_magicword_itm)list.Get_at(i);
Insert(site_abrv, itm.Name(), itm.Case_match(), itm.Aliases());
}
}
private void Insert(byte[] site_abrv, byte[] name, boolean case_match, byte[][] aliases) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_name , name)
.Val_bool_as_byte(fld_case_match , case_match)
.Val_bry_as_str(fld_aliases , Bry_.Add_w_dlm(Byte_ascii.Pipe, aliases))
.Exec_insert();
}
}

View File

@@ -1,55 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
public class Site_meta_itm {
public Ordered_hash General_list() {return general_list;} private final Ordered_hash general_list = Ordered_hash_.New_bry();
public Ordered_hash Namespace_list() {return namespace_list;} private final Ordered_hash namespace_list = Ordered_hash_.New();
public Site_statistic_itm Statistic_itm() {return statistic_itm;} private final Site_statistic_itm statistic_itm = new Site_statistic_itm();
public Ordered_hash Interwikimap_list() {return interwikimap_list;} private final Ordered_hash interwikimap_list = Ordered_hash_.New_bry();
public List_adp Namespacealias_list() {return namespacealias_list;} private final List_adp namespacealias_list = List_adp_.New();
public Ordered_hash Specialpagealias_list() {return specialpagealias_list;} private final Ordered_hash specialpagealias_list = Ordered_hash_.New_bry();
public Ordered_hash Library_list() {return library_list;} private final Ordered_hash library_list = Ordered_hash_.New_bry();
public Ordered_hash Extension_list() {return extension_list;} private final Ordered_hash extension_list = Ordered_hash_.New_bry();
public Ordered_hash Skin_list() {return skin_list;} private final Ordered_hash skin_list = Ordered_hash_.New_bry();
public Ordered_hash Magicword_list() {return magicword_list;} private final Ordered_hash magicword_list = Ordered_hash_.New_bry();
public Ordered_hash Functionhook_list() {return functionhook_list;} private final Ordered_hash functionhook_list = Ordered_hash_.New_bry();
public Ordered_hash Showhook_list() {return showhook_list;} private final Ordered_hash showhook_list = Ordered_hash_.New_bry();
public Ordered_hash Extensiontag_list() {return extensiontag_list;} private final Ordered_hash extensiontag_list = Ordered_hash_.New_bry();
public Ordered_hash Protocol_list() {return protocol_list;} private final Ordered_hash protocol_list = Ordered_hash_.New_bry();
public Ordered_hash Defaultoption_list() {return defaultoption_list;} private final Ordered_hash defaultoption_list = Ordered_hash_.New();
public Ordered_hash Language_list() {return language_list;} private final Ordered_hash language_list = Ordered_hash_.New_bry();
public Site_meta_itm Clear() {
general_list.Clear();
namespace_list.Clear();
statistic_itm.Ctor(0, 0, 0, 0, 0, 0, 0, 0, 0);
interwikimap_list.Clear();
namespacealias_list.Clear();
specialpagealias_list.Clear();
library_list.Clear();
extension_list.Clear();
skin_list.Clear();
magicword_list.Clear();
functionhook_list.Clear();
showhook_list.Clear();
extensiontag_list.Clear();
protocol_list.Clear();
defaultoption_list.Clear();
language_list.Clear();
return this;
}
}

View File

@@ -1,267 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.core.primitives.*; import gplx.langs.jsons.*;
class Site_meta_parser__general extends Json_parser__list_nde__base {
private final Site_meta_parser__general__kv parser__image = new Site_meta_parser__general__kv("imagelimits", "width", "height");
private final Site_meta_parser__general__lone parser__fallback = new Site_meta_parser__general__lone("fallback", "code");
private final Site_meta_parser__general__kv parser__variants = new Site_meta_parser__general__kv("variants", "code", "name");
private String cur_context;
public void Parse(String context, Ordered_hash list, Json_nde nde) {
this.cur_context = context + ".general";
this.Parse_to_list_as_kv(cur_context, nde, list);
}
@Override protected byte[] Parse_to_list_as_kv__get_val(Json_kv sub, byte[] key) {
Object o = complex_props.Get_by_bry(key);
if (o == null) return sub.Val_as_bry();
switch (((Int_obj_val)o).Val()) {
case Tid__thumblimits: return Bry_.Add_w_dlm(Byte_ascii.Pipe, sub.Val_as_ary().Xto_bry_ary()); // [120, 150, 180] -> "120|150|180"
case Tid__fallback: return parser__fallback.Parse(cur_context, tmp_bfr, sub.Val_as_ary()); // [{'code':'zh'},{'code':'zh-hans'}] -> "zh|zh-hans"
case Tid__variants: return parser__variants.Parse(cur_context, tmp_bfr, sub.Val_as_ary()); // [{'code':'zh','name':'a'},{'code':'zh-hans','name':'b'}] -> "zh=a|zh-hans=b"
case Tid__imagelimits: return parser__image.Parse(cur_context, tmp_bfr, sub.Val_as_ary()); // [{'width':320,'height':240},{'width':640,'height':480}] -> '320=240|640=480'
default: throw Err_.new_unhandled(o);
}
}
private static final int Tid__fallback = 1, Tid__variants = 2, Tid__thumblimits = 3, Tid__imagelimits = 4, Tid__imagelimits__width = 5, Tid__imagelimits__height = 6;
private static final Hash_adp_bry complex_props = Hash_adp_bry.cs()
.Add_str_int("fallback" , Tid__fallback)
.Add_str_int("variants" , Tid__variants)
.Add_str_int("thumblimits" , Tid__thumblimits)
.Add_str_int("imagelimits" , Tid__imagelimits)
.Add_str_int("width" , Tid__imagelimits__width)
.Add_str_int("height" , Tid__imagelimits__height)
;
}
class Site_meta_parser__general__lone extends Json_parser__list_nde__base {
private Bry_bfr bfr; private String context_name;
public Site_meta_parser__general__lone(String context_name, String key) {
this.context_name = context_name;
this.Ctor(key);
}
public byte[] Parse(String context, Bry_bfr bfr, Json_ary ary) {
if (ary.Len() == 0) return Bry_.Empty; // no fallbacks
this.bfr = bfr;
this.Parse_grp(context + "." + context_name, ary);
bfr.Del_by_1(); // delete trailing dlm at end of fallbacks
return bfr.To_bry_and_clear();
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
bfr.Add(Kv__bry(atrs, 0)).Add_byte_pipe();
}
}
class Site_meta_parser__general__kv extends Json_parser__list_nde__base {
private Bry_bfr bfr; private String context_name;
public Site_meta_parser__general__kv(String context_name, String key, String val) {
this.context_name = context_name;
this.Ctor(key, val);
}
public byte[] Parse(String context, Bry_bfr bfr, Json_ary ary) {
this.bfr = bfr;
this.Parse_grp(context + "." + context_name, ary);
bfr.Del_by_1();
return bfr.To_bry_and_clear();
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
bfr.Add(Kv__bry(atrs, 0)).Add_byte_eq().Add(Kv__bry(atrs, 1)).Add_byte_pipe();
}
}
class Site_meta_parser__namespace extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__namespace() {
this.Ctor("id", "canonical", "ca"+"se", "*", "subpages", "content", "defaultcontentmodel");
}
public void Parse(String context, Ordered_hash list, Json_nde nde) {
this.list = list;
this.Parse_grp(context + ".namespace", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
int id = Kv__int(atrs, 0);
list.Add(id, new Site_namespace_itm(id, Kv__bry(atrs, 2), Kv__bry_or_empty(atrs, 1), Kv__bry(atrs, 3), Kv__mw_bool(atrs, 4), Kv__mw_bool(atrs, 5), Kv__bry_or_empty(atrs, 6)));
}
}
class Site_meta_parser__statistic extends Json_parser__list_nde__base {
private Site_statistic_itm itm;
public Site_meta_parser__statistic() {
this.Ctor("pages", "articles", "edits", "images", "users", "activeusers", "admins", "jobs", "dispatch", "queued-massmessages");
}
public void Parse(String context, Site_statistic_itm itm, Json_nde nde) {
this.itm = itm;
this.Parse_nde(context + ".statistic", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
itm.Ctor
( Kv__long(atrs, 0)
, Kv__long(atrs, 1)
, Kv__long(atrs, 2)
, Kv__long(atrs, 3)
, Kv__long(atrs, 4)
, Kv__long(atrs, 5)
, Kv__long(atrs, 6)
, Kv__long(atrs, 7)
, Kv__long_or_0(atrs, 9)
);
}
}
class Site_meta_parser__interwikimap extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__interwikimap() {
this.Ctor("prefix", "local", "extralanglink", "linktext", "sitename", "language", "localinterwiki", "url", "protorel");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".interwikimap", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
list.Add(key
, new Site_interwikimap_itm(key
, Kv__mw_bool(atrs, 1), Kv__mw_bool(atrs, 2), Kv__bry_or_empty(atrs, 3), Kv__bry_or_empty(atrs, 4)
, Kv__bry_or_empty(atrs, 5), Kv__mw_bool(atrs, 6), Kv__bry(atrs, 7), Kv__mw_bool(atrs, 8)));
}
}
class Site_meta_parser__namespacealias extends Json_parser__list_nde__base {
private List_adp list;
public Site_meta_parser__namespacealias() {
this.Ctor("id", "*");
}
public void Parse(String context, List_adp list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".namespacealias", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
Site_namespacealias_itm itm = new Site_namespacealias_itm(Kv__int(atrs, 0), Kv__bry(atrs, 1));
list.Add(itm);
}
}
class Site_meta_parser__specialpagealias extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__specialpagealias() {
this.Ctor("realname", "aliases");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".specialpagealias", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
list.Add(key, new Site_specialpagealias_itm(key, Kv__bry_ary(atrs, 1)));
}
}
class Site_meta_parser__library extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__library() {
this.Ctor("name", "version");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".library", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
list.Add(key, new Site_library_itm(key, Kv__bry(atrs, 1)));
}
}
class Site_meta_parser__extension extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__extension() {
this.Ctor("type", "name", "namemsg", "description", "descriptionmsg", "author", "url", "version", "vcs-system", "vcs-version", "vcs-url", "vcs-date", "license-name", "license", "credits");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".extension", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
Site_extension_itm itm = new Site_extension_itm(Kv__bry(atrs, 0), Kv__bry(atrs, 1), Kv__bry_or_empty(atrs, 2), Kv__bry_or_empty(atrs, 3), Kv__bry_or_empty(atrs, 4)
, Kv__bry_or_empty(atrs, 5), Kv__bry_or_empty(atrs, 6)
, Kv__bry_or_empty(atrs, 7), Kv__bry_or_empty(atrs, 8), Kv__bry_or_empty(atrs, 9), Kv__bry_or_empty(atrs, 10), Kv__bry_or_empty(atrs, 11)
, Kv__bry_or_empty(atrs, 12), Kv__bry_or_empty(atrs, 13), Kv__bry_or_empty(atrs, 14)
);
list.Add(itm.Key(), itm);
}
}
class Site_meta_parser__skin extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__skin() {
this.Ctor("code", "de"+"fault", "*", "unusable");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".skin", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
list.Add(key, new Site_skin_itm(key, Kv__mw_bool(atrs, 1), Kv__bry(atrs, 2), Kv__mw_bool(atrs, 3)));
}
}
class Site_meta_parser__magicword extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__magicword() {
this.Ctor("name", "case-sensitive", "aliases");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".magicword", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
list.Add(key, new Site_magicword_itm(key, Kv__mw_bool(atrs, 1), Kv__bry_ary(atrs, 2)));
}
}
class Site_meta_parser__showhook extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__showhook() {
this.Ctor("name", "subscribers");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".showhook", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
Json_kv subscribers_kv = atrs[1];
byte[] scribunto = Bry_.Empty;
byte[][] subscribers_bry_ary = Bry_.Ary_empty;
if (subscribers_kv.Val().Tid() == Json_itm_.Tid__ary)
subscribers_bry_ary = Kv__bry_ary(atrs, 1);
else {
Json_nde subscribers_nde = subscribers_kv.Val_as_nde();
int atr_len = subscribers_nde.Len();
for (int j = 0; j < atr_len; ++j) {
Json_kv atr = subscribers_nde.Get_at_as_kv(j);
if (!Bry_.Eq(atr.Key_as_bry(), Key__scribunto)) {Warn("unknown subscriber key", atr); continue;}
scribunto = atr.Val_as_bry();
}
}
list.Add(key, new Site_showhook_itm(key, scribunto, subscribers_bry_ary));
}
private final static byte[] Key__scribunto = Bry_.new_a7("scribunto");
}
class Site_meta_parser__language extends Json_parser__list_nde__base {
private Ordered_hash list;
public Site_meta_parser__language() {
this.Ctor("code", "*");
}
public void Parse(String context, Ordered_hash list, Json_ary nde) {
this.list = list;
this.Parse_grp(context + ".language", nde);
}
@Override protected void Parse_hook_nde(Json_nde sub, Json_kv[] atrs) {
byte[] key = Kv__bry(atrs, 0);
list.Add(key, new Site_language_itm(key, Kv__bry(atrs, 1)));
}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_namespace_itm implements To_str_able {
public Site_namespace_itm(int id, byte[] case_tid, byte[] canonical, byte[] localized, boolean subpages, boolean content, byte[] defaultcontentmodel) {
this.id = id; this.case_tid = case_tid; this.canonical = canonical; this.localized = localized;
this.subpages = subpages; this.content = content; this.defaultcontentmodel = defaultcontentmodel;
}
public int Id() {return id;} private final int id;
public byte[] Case_tid() {return case_tid;} private final byte[] case_tid;
public byte[] Canonical() {return canonical;} private final byte[] canonical;
public byte[] Localized() {return localized;} private final byte[] localized;
public boolean Subpages() {return subpages;} private final boolean subpages;
public boolean Content() {return content;} private final boolean content;
public byte[] Defaultcontentmodel() {return defaultcontentmodel;} private final byte[] defaultcontentmodel;
public String To_str() {
return String_.Concat_with_obj("|", id, case_tid, canonical, localized, subpages, content, defaultcontentmodel);
}
}

View File

@@ -1,87 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
public class Site_namespace_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_id, fld_case_tid, fld_canonical, fld_localized, fld_subpages, fld_content, fld_defaultcontentmodel;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_namespace_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_id = flds.Add_int("id");
this.fld_case_tid = flds.Add_str("case_tid", 255);
this.fld_canonical = flds.Add_str("canonical", 255);
this.fld_localized = flds.Add_str("localized", 255);
this.fld_subpages = flds.Add_byte("subpages");
this.fld_content = flds.Add_byte("content");
this.fld_defaultcontentmodel = flds.Add_str("defaultcontentmodel", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_namespace";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_id)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_manual();
try {
while (rdr.Move_next()) {
Site_namespace_itm itm = new Site_namespace_itm
( rdr.Read_int (fld_id)
, rdr.Read_bry_by_str (fld_case_tid)
, rdr.Read_bry_by_str (fld_canonical)
, rdr.Read_bry_by_str (fld_localized)
, rdr.Read_bool_by_byte (fld_subpages)
, rdr.Read_bool_by_byte (fld_content)
, rdr.Read_bry_by_str (fld_defaultcontentmodel)
);
list.Add(itm.Id(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_namespace_itm itm = (Site_namespace_itm)list.Get_at(i);
Insert(site_abrv, itm.Id(), itm.Case_tid(), itm.Canonical(), itm.Localized(), itm.Subpages(), itm.Content(), itm.Defaultcontentmodel());
}
}
public void Insert(byte[] site_abrv, int id, byte[] case_tid, byte[] canonical, byte[] localized, boolean subpages, boolean content, byte[] defaultcontentmodel) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_bry_as_str (fld_site_abrv , site_abrv)
.Val_int (fld_id , id)
.Val_bry_as_str (fld_case_tid , case_tid)
.Val_bry_as_str (fld_canonical , canonical)
.Val_bry_as_str (fld_localized , localized)
.Val_bool_as_byte (fld_subpages , subpages)
.Val_bool_as_byte (fld_content , content)
.Val_bry_as_str (fld_defaultcontentmodel , defaultcontentmodel)
.Exec_insert();
}
}

View File

@@ -1,28 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_namespacealias_itm implements To_str_able {
public Site_namespacealias_itm(int id, byte[] alias) {
this.id = id; this.alias = alias;
this.key = Bry_.Add_w_dlm(Byte_ascii.Pipe, Int_.To_bry(id), alias);
}
public byte[] Key() {return key;} private final byte[] key;
public int Id() {return id;} private final int id;
public byte[] Alias() {return alias;} private final byte[] alias;
public String To_str() {return String_.Concat_with_obj("|", id, alias);}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_namespacealias_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_id, fld_alias;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_namespacealias_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_id = flds.Add_int("id");
this.fld_alias = flds.Add_str("alias", 2048);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_namespacealias";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_normal_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_id, fld_alias)));} // NOTE: kk.w has duplicate entries in json
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, List_adp list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_namespacealias_itm itm = new Site_namespacealias_itm
( rdr.Read_int(fld_id)
, rdr.Read_bry_by_str(fld_alias)
);
list.Add(itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, List_adp list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_namespacealias_itm itm = (Site_namespacealias_itm)list.Get_at(i);
Insert(site_abrv, itm.Id(), itm.Alias());
}
}
private void Insert(byte[] site_abrv, int id, byte[] alias) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_int(fld_id , id)
.Val_bry_as_str(fld_alias , alias)
.Exec_insert();
}
}

View File

@@ -1,27 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_showhook_itm implements To_str_able {
public Site_showhook_itm(byte[] name, byte[] scribunto, byte[][] subscribers) {
this.name = name; this.scribunto = scribunto; this.subscribers = subscribers;
}
public byte[] Name() {return name;} private final byte[] name;
public byte[] Scribunto() {return scribunto;} private final byte[] scribunto;
public byte[][] Subscribers() {return subscribers;} private final byte[][] subscribers;
public String To_str() {return String_.Concat_with_obj("|", name, scribunto, String_.Concat_with_obj(";", (Object[])subscribers));}
}

View File

@@ -1,75 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_showhook_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_name, fld_scribunto, fld_subscribers;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_showhook_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_name = flds.Add_str("name", 255);
this.fld_scribunto = flds.Add_str("scribunto", 255);
this.fld_subscribers = flds.Add_str("subscribers", 2048);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_showhook";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_name)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_showhook_itm itm = new Site_showhook_itm
( rdr.Read_bry_by_str(fld_name)
, rdr.Read_bry_by_str(fld_scribunto)
, Bry_split_.Split(rdr.Read_bry_by_str(fld_subscribers), Byte_ascii.Pipe_bry)
);
list.Add(itm.Name(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_showhook_itm itm = (Site_showhook_itm)list.Get_at(i);
Insert(site_abrv, itm.Name(), itm.Scribunto(), itm.Subscribers());
}
}
private void Insert(byte[] site_abrv, byte[] name, byte[] scribunto, byte[][] subscribers) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_name , name)
.Val_bry_as_str(fld_scribunto , scribunto)
.Val_bry_as_str(fld_subscribers , Bry_.Add_w_dlm(Byte_ascii.Pipe, subscribers))
.Exec_insert();
}
}

View File

@@ -1,28 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_skin_itm implements To_str_able {
public Site_skin_itm(byte[] code, boolean dflt, byte[] name, boolean unusable) {
this.code = code; this.dflt = dflt; this.name = name; this.unusable = unusable;
}
public byte[] Code() {return code;} private final byte[] code;
public boolean Dflt() {return dflt;} private final boolean dflt;
public byte[] Name() {return name;} private final byte[] name;
public boolean Unusable() {return unusable;} private final boolean unusable;
public String To_str() {return String_.Concat_with_obj("|", code, dflt, name, unusable);}
}

View File

@@ -1,78 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_skin_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_code, fld_dflt, fld_name, fld_unusable;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_skin_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_code = flds.Add_str("code", 255);
this.fld_dflt = flds.Add_bool("dflt");
this.fld_name = flds.Add_str("name", 255);
this.fld_unusable = flds.Add_bool("unusable");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_skin";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_code)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_skin_itm itm = new Site_skin_itm
( rdr.Read_bry_by_str(fld_code)
, rdr.Read_bool_by_byte(fld_dflt)
, rdr.Read_bry_by_str(fld_name)
, rdr.Read_bool_by_byte(fld_unusable)
);
list.Add(itm.Name(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_skin_itm itm = (Site_skin_itm)list.Get_at(i);
Insert(site_abrv, itm.Code(), itm.Dflt(), itm.Name(), itm.Unusable());
}
}
private void Insert(byte[] site_abrv, byte[] code, boolean dflt, byte[] name, boolean unusable) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_code , code)
.Val_bool_as_byte(fld_dflt , dflt)
.Val_bry_as_str(fld_name , name)
.Val_bool_as_byte(fld_unusable , unusable)
.Exec_insert();
}
}

View File

@@ -1,24 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
class Site_specialpagealias_itm implements To_str_able {
public Site_specialpagealias_itm(byte[] realname, byte[][] aliases) {this.realname = realname; this.aliases = aliases;}
public byte[] Realname() {return realname;} private final byte[] realname;
public byte[][] Aliases() {return aliases;} private final byte[][] aliases;
public String To_str() {return String_.Concat_with_obj("|", realname, String_.Concat_with_obj(";", (Object[])aliases));}
}

View File

@@ -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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_specialpagealias_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_realname, fld_aliases;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_specialpagealias_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_realname = flds.Add_str("realname", 255);
this.fld_aliases = flds.Add_str("aliases", 2048);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_specialpagealias";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main")), fld_site_abrv, fld_realname)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
Site_specialpagealias_itm itm = new Site_specialpagealias_itm
( rdr.Read_bry_by_str(fld_realname)
, Bry_split_.Split(rdr.Read_bry_by_str(fld_aliases), Byte_ascii.Pipe_bry)
);
list.Add(itm.Realname(), itm);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
Site_specialpagealias_itm itm = (Site_specialpagealias_itm)list.Get_at(i);
Insert(site_abrv, itm.Realname(), itm.Aliases());
}
}
private void Insert(byte[] site_abrv, byte[] realname, byte[][] aliases) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_realname , realname)
.Val_bry_as_str(fld_aliases , Bry_.Add_w_dlm(Byte_ascii.Pipe_bry, aliases))
.Exec_insert();
}
}

View File

@@ -1,42 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
public class Site_statistic_itm implements To_str_able {
public Site_statistic_itm Ctor(long pages, long articles, long edits, long images, long users, long activeusers, long admins, long jobs, long queued_massmessages) {
this.pages = pages;
this.articles = articles;
this.edits = edits;
this.images = images;
this.users = users;
this.activeusers = activeusers;
this.admins = admins;
this.jobs = jobs;
this.queued_massmessages = queued_massmessages;
return this;
}
public long Pages() {return pages;} private long pages;
public long Articles() {return articles;} private long articles;
public long Edits() {return edits;} private long edits;
public long Images() {return images;} private long images;
public long Users() {return users;} private long users;
public long Activeusers() {return activeusers;} private long activeusers;
public long Admins() {return admins;} private long admins;
public long Jobs() {return jobs;} private long jobs;
public long Queued_massmessages() {return queued_massmessages;} private long queued_massmessages;
public String To_str() {return String_.Concat_with_obj("|", pages, articles, edits, images, users, activeusers, admins, queued_massmessages);}
}

View File

@@ -1,88 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_statistic_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_pages, fld_articles, fld_edits, fld_images, fld_users, fld_activeusers, fld_admins, fld_jobs, fld_queued_massmessages;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_statistic_tbl(Db_conn conn) {
this.conn = conn;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_pages = flds.Add_long("pages");
this.fld_articles = flds.Add_long("articles");
this.fld_edits = flds.Add_long("edits");
this.fld_images = flds.Add_long("images");
this.fld_users = flds.Add_long("users");
this.fld_activeusers = flds.Add_long("activeusers");
this.fld_admins = flds.Add_long("admins");
this.fld_jobs = flds.Add_long("jobs");
this.fld_queued_massmessages = flds.Add_long("queued_massmessages");
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private static final String tbl_name = "site_statistic";
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Site_statistic_itm itm) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_auto();
try {
if (rdr.Move_next()) {
itm.Ctor
( rdr.Read_long(fld_pages)
, rdr.Read_long(fld_articles)
, rdr.Read_long(fld_edits)
, rdr.Read_long(fld_images)
, rdr.Read_long(fld_users)
, rdr.Read_long(fld_activeusers)
, rdr.Read_long(fld_admins)
, rdr.Read_long(fld_jobs)
, rdr.Read_long(fld_queued_massmessages)
);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Site_statistic_itm itm) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
Insert(site_abrv, itm.Pages(), itm.Articles(), itm.Edits(), itm.Images(), itm.Users(), itm.Activeusers(), itm.Admins(), itm.Jobs(), itm.Queued_massmessages());
}
private void Insert(byte[] site_abrv, long pages, long articles, long edits, long images, long users, long activeusers, long admins, long jobs, long queued_massmessages) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_long(fld_pages , pages)
.Val_long(fld_articles , articles)
.Val_long(fld_edits , edits)
.Val_long(fld_images , images)
.Val_long(fld_users , users)
.Val_long(fld_activeusers , activeusers)
.Val_long(fld_admins , admins)
.Val_long(fld_jobs , jobs)
.Val_long(fld_queued_massmessages , queued_massmessages)
.Exec_insert();
}
}

View File

@@ -1,68 +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.bldrs.wms.sites; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wms.*;
import gplx.dbs.*;
class Site_val_tbl implements Db_tbl {
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
private final String fld_site_abrv, fld_val;
private final Db_conn conn;
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Site_val_tbl(Db_conn conn, String tbl_name) {
this.conn = conn;
this.tbl_name = tbl_name;
this.fld_site_abrv = flds.Add_str("site_abrv", 255);
this.fld_val = flds.Add_str("val", 255);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_name(tbl_name, Dbmeta_idx_itm.Bld_idx_name(tbl_name, "main"), fld_site_abrv, fld_val)));}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
}
public void Select(byte[] site_abrv, Ordered_hash list) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_site_abrv);
list.Clear();
Db_rdr rdr = stmt_select.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_select__rls_manual();
try {
while (rdr.Move_next()) {
byte[] val = rdr.Read_bry_by_str(fld_val);
list.Add(val, val);
}
}
finally {rdr.Rls();}
}
public void Insert(byte[] site_abrv, Ordered_hash list) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_site_abrv);
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_delete.Clear().Crt_bry_as_str(fld_site_abrv, site_abrv).Exec_delete();
int len = list.Count();
for (int i = 0; i < len; ++i) {
byte[] itm = (byte[])list.Get_at(i);
Insert(site_abrv, itm);
}
}
private void Insert(byte[] site_abrv, byte[] val) {
stmt_insert.Clear()
.Val_bry_as_str(fld_site_abrv , site_abrv)
.Val_bry_as_str(fld_val , val)
.Exec_insert();
}
}