mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.2.1
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public class Bry_comparer_fld_last implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
|
||||
int lhs_bgn = Bry_finder.Find_bwd(lhs, Byte_ascii.Pipe); if (lhs_bgn == Bry_.NotFound) lhs_bgn = -1;
|
||||
int rhs_bgn = Bry_finder.Find_bwd(rhs, Byte_ascii.Pipe); if (rhs_bgn == Bry_.NotFound) rhs_bgn = -1;
|
||||
return Bry_.Compare(lhs, lhs_bgn + 1, lhs.length, rhs, rhs_bgn + 1, rhs.length);
|
||||
}
|
||||
public static final Bry_comparer_fld_last _ = new Bry_comparer_fld_last();
|
||||
}
|
||||
39
400_xowa/src_121_wiki_data/gplx/xowa/ByteAry_fil.java
Normal file
39
400_xowa/src_121_wiki_data/gplx/xowa/ByteAry_fil.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class ByteAry_fil {
|
||||
public List_adp Itms() {return itms;} List_adp itms = List_adp_.new_();
|
||||
public Io_url Fil() {return fil;} Io_url fil;
|
||||
public byte[] Raw_bry() {return raw_bry;} private byte[] raw_bry = Bry_.Empty;
|
||||
public int Raw_len() {return raw_len.Val();} Int_obj_ref raw_len = Int_obj_ref.zero_();
|
||||
public int Raw_max() {return raw_max;} private int raw_max = Io_mgr.Len_mb;
|
||||
public ByteAry_fil Ini_file(Io_url fil) {
|
||||
this.fil = fil;
|
||||
raw_bry = Io_mgr.I.LoadFilBry_reuse(fil, raw_bry, raw_len);
|
||||
return this;
|
||||
}
|
||||
public Object Xto_itms(Class<?> itm_type) {
|
||||
Object rv = itms.To_ary(itm_type);
|
||||
itms.Clear();
|
||||
if (raw_bry.length > raw_max) raw_bry = Bry_.Empty;
|
||||
raw_len.Val_zero_();
|
||||
return rv;
|
||||
}
|
||||
public static final ByteAry_fil _ = new ByteAry_fil(); ByteAry_fil() {}
|
||||
}
|
||||
67
400_xowa/src_121_wiki_data/gplx/xowa/Io_txn_itm_save.java
Normal file
67
400_xowa/src_121_wiki_data/gplx/xowa/Io_txn_itm_save.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
interface Io_txn_itm {
|
||||
byte Txn_tid();
|
||||
Io_url Txn_url();
|
||||
boolean Txn_init(Io_url tmp_dir);
|
||||
boolean Txn_exec(Io_url tmp_dir);
|
||||
boolean Txn_term(Io_url tmp_dir);
|
||||
}
|
||||
class Io_txn_itm_save {
|
||||
public byte Txn_tid() {return 0;}
|
||||
public Io_url Txn_url() {return null;}
|
||||
public boolean Txn_init(Io_url tmp_dir) {
|
||||
// save to tmp_dir
|
||||
return true;
|
||||
}
|
||||
public boolean Txn_exec(Io_url tmp_dir) {
|
||||
// move temp to actl
|
||||
// move actl to temp
|
||||
return true;
|
||||
}
|
||||
public boolean Txn_term(Io_url tmp_dir) {
|
||||
// delete temp
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class Io_txn_mgr {
|
||||
public Io_txn_mgr(Io_url tmp_dir) {this.tmp_dir = tmp_dir;}
|
||||
public Io_url Tmp_dir() {return tmp_dir;} Io_url tmp_dir;
|
||||
public void Add(Io_txn_itm itm) {
|
||||
list.Add(itm);
|
||||
}
|
||||
public boolean Commit() {
|
||||
int len = list.Count();
|
||||
Io_txn_itm[] itms = (Io_txn_itm[])list.To_ary(Io_txn_itm.class);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_txn_itm itm = itms[i];
|
||||
itm.Txn_init(tmp_dir);
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_txn_itm itm = itms[i];
|
||||
itm.Txn_exec(tmp_dir);
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_txn_itm itm = itms[i];
|
||||
itm.Txn_term(tmp_dir);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
List_adp list = List_adp_.new_();
|
||||
}
|
||||
194
400_xowa/src_121_wiki_data/gplx/xowa/Xob_hive_mgr.java
Normal file
194
400_xowa/src_121_wiki_data/gplx/xowa/Xob_hive_mgr.java
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.specials.allPages.*; import gplx.xowa.tdbs.*;
|
||||
public class Xob_hive_mgr {
|
||||
public Xob_hive_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.fsys_mgr = wiki.Tdb_fsys_mgr();} private Xowe_wiki wiki; Xotdb_fsys_mgr fsys_mgr;
|
||||
public void Clear() {regy.Clear(); xdat.Clear();}
|
||||
public void Special_allpages_query(Xows_page_allpages mgr, Xow_ns ns, byte[] key, int count, boolean include_redirects) {
|
||||
byte dir_tid = Xotdb_dir_info_.Tid_ttl;
|
||||
int xdat_idx = Regy__find_file_ns(key, dir_tid, ns.Num_str());
|
||||
Xob_xdat_file xdat_main = new Xob_xdat_file();
|
||||
xdat_main = xdat_load_(xdat_main, dir_tid, ns, xdat_idx);
|
||||
xdat_main.Find(xdat_itm, key, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Tab, false);
|
||||
int itm_idx = xdat_itm.Itm_idx();
|
||||
Special_allpages_query_fwd(mgr, dir_tid, ns, include_redirects, count, xdat_idx, itm_idx , xdat_main);
|
||||
Special_allpages_query_bwd(mgr, dir_tid, ns, include_redirects, count, xdat_idx, itm_idx - 1, xdat_main);
|
||||
}
|
||||
Xob_xdat_file xdat_load_(Xob_xdat_file xdat, byte dir_tid, Xow_ns ns, int fil_idx) {
|
||||
Io_url xdat_url = fsys_mgr.Url_ns_fil(dir_tid, ns.Id(), fil_idx);
|
||||
byte[] xdat_bry = gplx.ios.Io_stream_rdr_.Load_all(xdat_url);
|
||||
xdat.Parse(xdat_bry, xdat_bry.length, xdat_url);
|
||||
return xdat;
|
||||
}
|
||||
private void Special_allpages_query_fwd(Xows_page_allpages mgr, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_idx, int row_idx, Xob_xdat_file xdat_file) {
|
||||
int count = 0; ++total;
|
||||
boolean loop = true;
|
||||
int regy_len = regy.Files_ary().length;
|
||||
int rslt_list_len = mgr.Rslt_list_len();
|
||||
Xowd_page_itm[] rslt_list_ttls = mgr.Rslt_list_ttls();
|
||||
Xowd_page_itm nxt_itm = null;
|
||||
while (loop) {
|
||||
if (fil_idx == regy_len) break;
|
||||
if (xdat_file == null) {
|
||||
xdat_file = xdat_load_(this.xdat, dir_tid, ns, fil_idx);
|
||||
row_idx = 0;
|
||||
}
|
||||
int rows_len = xdat_file.Count();
|
||||
for (; row_idx < rows_len; row_idx++) {
|
||||
xdat_file.GetAt(xdat_itm, row_idx);
|
||||
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
|
||||
if (!include_redirects && ttl_itm.Redirected()) continue;
|
||||
++count;
|
||||
nxt_itm = ttl_itm;
|
||||
if (count == total) {
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
rslt_list_ttls[rslt_list_len++] = ttl_itm;
|
||||
}
|
||||
xdat_file = null;
|
||||
++fil_idx;
|
||||
}
|
||||
mgr.Rslt_list_len_(rslt_list_len);
|
||||
mgr.Rslt_nxt_(nxt_itm);
|
||||
}
|
||||
private void Special_allpages_query_bwd(Xows_page_allpages mgr, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_idx, int row_idx, Xob_xdat_file xdat_file) {
|
||||
if (row_idx < 0) {
|
||||
--fil_idx;
|
||||
row_idx = -1;
|
||||
}
|
||||
int count = 0;
|
||||
boolean loop = true;
|
||||
Xowd_page_itm prv_itm = null;
|
||||
while (loop) {
|
||||
if (fil_idx == -1) break;
|
||||
if (xdat_file == null) {
|
||||
xdat_file = xdat_load_(this.xdat, dir_tid, ns, fil_idx);
|
||||
row_idx = -1;
|
||||
}
|
||||
if (row_idx == -1)
|
||||
row_idx = xdat_file.Count() - 1;
|
||||
for (; row_idx > -1; row_idx--) {
|
||||
xdat_file.GetAt(xdat_itm, row_idx);
|
||||
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
|
||||
if (!include_redirects && ttl_itm.Redirected()) continue;
|
||||
// list.Add(ttl_itm);
|
||||
++count;
|
||||
prv_itm = ttl_itm;
|
||||
if (count == total) {
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// rslt_list_ttls[rslt_list_len++] = ttl_itm;
|
||||
}
|
||||
}
|
||||
xdat_file = null;
|
||||
--fil_idx;
|
||||
}
|
||||
if (prv_itm == null) prv_itm = mgr.Rslt_list_ttls()[0];
|
||||
mgr.Rslt_prv_(prv_itm);
|
||||
}
|
||||
public void Find_bgn(List_adp list, Xow_ns ns, byte[] key, int count, boolean include_redirects) {
|
||||
byte dir_tid = Xotdb_dir_info_.Tid_ttl;
|
||||
int xdat_idx = Regy__find_file_ns(key, dir_tid, ns.Num_str());
|
||||
Io_url xdat_url = fsys_mgr.Url_ns_fil(dir_tid, ns.Id(), xdat_idx);
|
||||
byte[] xdat_bry = gplx.ios.Io_stream_rdr_.Load_all(xdat_url);
|
||||
xdat.Parse(xdat_bry, xdat_bry.length, xdat_url);
|
||||
xdat.Find(xdat_itm, key, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Tab, false);
|
||||
Find_nearby_add_fwd(list, dir_tid, ns, include_redirects, count, xdat_idx, xdat_itm.Itm_idx());
|
||||
} private Xob_xdat_itm xdat_itm = new Xob_xdat_itm(); //Int_2_ref find_nearby_rslt = new Int_2_ref();
|
||||
// private void Find_nearby_add_bwd(List_adp list, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_bgn, int row_bgn) {
|
||||
// if (--row_bgn < 0) {
|
||||
// --fil_bgn;
|
||||
// row_bgn = -1;
|
||||
// }
|
||||
// int fil_idx = fil_bgn;
|
||||
// boolean first = true;
|
||||
// int count = 0;
|
||||
// boolean loop = true;
|
||||
// while (loop) {
|
||||
// if (fil_idx == -1) break;
|
||||
// Io_url xdat_url = fsys_mgr.Url_ns_fil(dir_tid, ns.Id(), fil_idx);
|
||||
// byte[] xdat_bry = gplx.ios.Io_stream_rdr_.Load_all(xdat_url);
|
||||
// xdat.Parse(xdat_bry, xdat_bry.length, xdat_url);
|
||||
// int row_idx = first && row_bgn != -1 ? row_bgn : xdat.Count() - 1;
|
||||
// first = false;
|
||||
// for (; row_idx > -1; row_idx--) {
|
||||
// xdat.GetAt(xdat_itm, row_idx);
|
||||
// Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
|
||||
// if (!include_redirects && ttl_itm.Type_redirect()) continue;
|
||||
// list.Add(ttl_itm);
|
||||
// if (++count == total) {loop = false; break;}
|
||||
// }
|
||||
// --fil_idx;
|
||||
// }
|
||||
// }
|
||||
private void Find_nearby_add_fwd(List_adp list, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_bgn, int row_bgn) {
|
||||
int fil_idx = fil_bgn;
|
||||
boolean first = true;
|
||||
int count = 0;
|
||||
boolean loop = true;
|
||||
int regy_len = regy.Files_ary().length;
|
||||
while (loop) {
|
||||
if (fil_idx == regy_len) break;
|
||||
Io_url xdat_url = fsys_mgr.Url_ns_fil(dir_tid, ns.Id(), fil_idx);
|
||||
byte[] xdat_bry = gplx.ios.Io_stream_rdr_.Load_all(xdat_url);
|
||||
xdat.Parse(xdat_bry, xdat_bry.length, xdat_url);
|
||||
int row_idx = first ? row_bgn : 0;
|
||||
int rows_len = xdat.Count();
|
||||
first = false;
|
||||
for (; row_idx < rows_len; row_idx++) {
|
||||
xdat.GetAt(xdat_itm, row_idx);
|
||||
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
|
||||
if (!include_redirects && ttl_itm.Redirected()) continue;
|
||||
list.Add(ttl_itm);
|
||||
if (++count == total) {loop = false; break;}
|
||||
}
|
||||
++fil_idx;
|
||||
}
|
||||
}
|
||||
public void Create(byte dir_tid, byte[] key, byte[] row) { // Ctg_0; Ctg_0|!!!!"|!!!!#
|
||||
int xdat_idx = Regy__find_file(key, dir_tid);
|
||||
if (xdat_idx == Xowd_regy_mgr.Regy_null) { // no entries in regy; create at least one; EX: "" -> "0|A|A|1"
|
||||
regy.Create(key);
|
||||
xdat_idx = 0;
|
||||
}
|
||||
else
|
||||
regy.Update_add(0, key);
|
||||
regy.Save();
|
||||
Xdat__create_row(dir_tid, key, row, xdat_idx);
|
||||
}
|
||||
int Regy__find_file(byte[] key, byte dir_tid) {return Regy__find_file_by_url(key, fsys_mgr.Url_site_reg(dir_tid));}
|
||||
int Regy__find_file_ns(byte[] key, byte dir_tid, String ns_num) {return Regy__find_file_by_url(key, fsys_mgr.Url_ns_reg(ns_num, Xotdb_dir_info_.Tid_ttl));}
|
||||
int Regy__find_file_by_url(byte[] key, Io_url regy_url) {regy.Init(regy_url); return regy.Files_find(key);} private Xowd_regy_mgr regy = new Xowd_regy_mgr();
|
||||
private void Xdat__create_row(byte dir_tid, byte[] key, byte[] row, int xdat_idx) {
|
||||
Io_url xdat_url = fsys_mgr.Url_site_fil(dir_tid, xdat_idx);
|
||||
byte[] xdat_bry = gplx.ios.Io_stream_rdr_.Load_all(xdat_url);
|
||||
Xob_xdat_file xdat_fil = new Xob_xdat_file();
|
||||
if (xdat_bry.length > 0) // if file is not empty, load it and parse it
|
||||
xdat_fil.Parse(xdat_bry, xdat_bry.length, xdat_url);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
xdat_fil.Insert(tmp_bfr, row);
|
||||
xdat_fil.Save(xdat_url);
|
||||
tmp_bfr.Mkr_rls();
|
||||
} private Xob_xdat_file xdat = new Xob_xdat_file(); Io_zip_mgr zip_mgr = Io_zip_mgr_base._;
|
||||
}
|
||||
43
400_xowa/src_121_wiki_data/gplx/xowa/Xob_hive_mgr_tst.java
Normal file
43
400_xowa/src_121_wiki_data/gplx/xowa/Xob_hive_mgr_tst.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xob_hive_mgr_tst {
|
||||
Xow_hive_mgr_fxt fxt = new Xow_hive_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Drilldown() {
|
||||
// fxt.Files_create_range(10, 10);
|
||||
// fxt.Drilldown("A00", "J09", "A00", "B09", "C00", "D09", "E00", "F09", "G00", "H09", "I00", "J09");
|
||||
// fxt.Drilldown("E00", "F09", "E00", "E03", "E04", "E07", "E08", "F01", "F02", "F05", "F06", "F09");
|
||||
// fxt.Drilldown("E08", "F01", "E08", "E09", "F00", "F01");
|
||||
}
|
||||
}
|
||||
class Xob_reg_wtr {
|
||||
Bry_bfr bfr = Bry_bfr.new_(); int fil_count = 0;
|
||||
public void Add(byte[] bgn, byte[] end, int itm_count) {
|
||||
bfr
|
||||
.Add_int_variable(fil_count++).Add_byte(Byte_ascii.Pipe)
|
||||
.Add(bgn).Add_byte(Byte_ascii.Pipe)
|
||||
.Add(end).Add_byte(Byte_ascii.Pipe)
|
||||
.Add_int_variable(itm_count).Add_byte(Byte_ascii.Nl);
|
||||
}
|
||||
public void Flush(Io_url url) {
|
||||
Io_mgr.I.SaveFilBfr(url, bfr);
|
||||
// Tfds.Write(url.Raw() + "\n" + Io_mgr.I.LoadFilStr(url));
|
||||
}
|
||||
}
|
||||
21
400_xowa/src_121_wiki_data/gplx/xowa/Xobl_data_itm.java
Normal file
21
400_xowa/src_121_wiki_data/gplx/xowa/Xobl_data_itm.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
public interface Xobl_data_itm {
|
||||
void Srl_save(Bry_bfr bfr);
|
||||
}
|
||||
96
400_xowa/src_121_wiki_data/gplx/xowa/Xow_data_mgr.java
Normal file
96
400_xowa/src_121_wiki_data/gplx/xowa/Xow_data_mgr.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.lists.*; /*ComparerAble*/ import gplx.xowa.bldrs.cmds.ctgs.*;
|
||||
import gplx.xowa.dbs.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_data_mgr implements GfoInvkAble {
|
||||
private Xop_redirect_mgr redirect_mgr;
|
||||
private Xoa_url tmp_url = Xoa_url.blank_();
|
||||
public Xow_data_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.redirect_mgr = wiki.Redirect_mgr();}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public boolean Version_is_1() {return Bool_.Y;}
|
||||
public Xoae_page Get_page(Xoa_ttl ttl, boolean called_from_tmpl) {wiki.Appe().Utl__url_parser().Parse(tmp_url, ttl.Raw()); return Get_page(tmp_url, ttl, called_from_tmpl, false);}
|
||||
public Xoae_page Get_page_from_msg(Xoa_ttl ttl) {wiki.Appe().Utl__url_parser().Parse(tmp_url, ttl.Raw()); return Get_page(tmp_url, ttl, false, true);}
|
||||
public Xoae_page Get_page(Xoa_url url, Xoa_ttl ttl, boolean called_from_tmpl, boolean called_from_msg) {
|
||||
Xoae_page rv = Xoae_page.new_(wiki, ttl);
|
||||
return Get_page(rv, url, ttl, called_from_tmpl, called_from_msg);
|
||||
}
|
||||
public Xoae_page Get_page(Xoae_page rv, Xoa_url url, Xoa_ttl ttl, boolean called_from_tmpl, boolean called_from_msg) {
|
||||
rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.new_()
|
||||
Xow_ns ns = ttl.Ns();
|
||||
switch (ns.Id()) {
|
||||
case Xow_ns_.Id_special:
|
||||
wiki.Special_mgr().Special_gen(wiki, rv, url, ttl);
|
||||
return rv;
|
||||
case Xow_ns_.Id_mediawiki:
|
||||
if ( !called_from_msg // if called from msg, fall through to actual data retrieval below, else infinite loop; DATE:2014-05-09
|
||||
&& Xow_page_tid.Identify_by_ttl(ttl.Page_db()) == Xow_page_tid.Tid_wikitext // skip ".js" and ".css" pages in MediaWiki; DATE:2014-06-13
|
||||
) {
|
||||
Xol_lang lang = wiki.Lang();
|
||||
byte[] msg_key = ttl.Page_db();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
msg_key = lang.Case_mgr().Case_build_1st_lower(tmp_bfr, msg_key, 0, msg_key.length);
|
||||
byte[] msg_val = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), msg_key).Val(); // NOTE: do not change to Get_msg_val; Get_msg_val, also replaces $1 with values, and $1 needs to be preserved for callers;
|
||||
rv.Data_raw_(msg_val);
|
||||
tmp_bfr.Mkr_rls();
|
||||
return rv;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Get_page(rv, ns, ttl, called_from_tmpl, url.Redirect_force());
|
||||
}
|
||||
public Xoae_page Get_page(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean called_from_tmpl, boolean redirect_force) {
|
||||
int redirects = 0;
|
||||
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
while (true) {
|
||||
boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(db_page, ns, ttl.Page_db());
|
||||
if (!exists) return rv.Missing_();
|
||||
if (wiki.App().App_type().Uid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
|
||||
wiki.Appe().Usr_dlg().Prog_many(GRP_KEY, "file_load", "loading page for ~{0}", String_.new_u8(ttl.Raw()));
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, ns, !called_from_tmpl);
|
||||
byte[] bry = db_page.Text();
|
||||
rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id()).Html_db_id_(db_page.Html_db_id());
|
||||
if (redirect_force) return rv;
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry, bry.length);
|
||||
if ( redirect_ttl == null // not a redirect
|
||||
|| redirects++ > 4) // too many redirects; something went wrong
|
||||
break;
|
||||
rv.Redirected_ttls().Add(ttl.Full_url()); // NOTE: must be url_encoded; EX: "en.wikipedia.org/?!" should generate link of "en.wikipedia.org/%3F!?redirect=no"
|
||||
if (rv.Redirected_src() == null) rv.Redirected_src_(bry); // only add src for first redirect; DATE:2014-07-11
|
||||
rv.Ttl_(redirect_ttl);
|
||||
ns = redirect_ttl.Ns();
|
||||
ttl = redirect_ttl;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xoae_page Redirect(Xoae_page page, byte[] page_bry) {
|
||||
Xoa_ttl trg_ttl = Xoa_ttl.parse_(wiki, page_bry);
|
||||
Xoa_url trg_url = Xoa_url.new_(wiki.Domain_bry(), page_bry);
|
||||
page.Ttl_(trg_ttl).Url_(trg_url).Redirected_(true);
|
||||
return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Redirect_force());
|
||||
}
|
||||
public static final int File_idx_unknown = -1;
|
||||
static final String GRP_KEY = "xowa.wiki.data";
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_create_enabled_)) wiki.Db_mgr().Save_mgr().Create_enabled_(m.ReadYn("v"));
|
||||
else if (ctx.Match(k, Invk_update_modified_on_enabled_)) wiki.Db_mgr().Save_mgr().Update_modified_on_enabled_(m.ReadYn("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_create_enabled_ = "create_enabled_", Invk_update_modified_on_enabled_ = "update_modified_on_enabled_";
|
||||
}
|
||||
163
400_xowa/src_121_wiki_data/gplx/xowa/Xow_data_mgr_tst.java
Normal file
163
400_xowa/src_121_wiki_data/gplx/xowa/Xow_data_mgr_tst.java
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import org.junit.*; import gplx.xowa.tdbs.*;
|
||||
public class Xow_data_mgr_tst {
|
||||
Xow_data_mgr_fxt fxt = new Xow_data_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear(); Tfds.Now_enabled_y_();}
|
||||
@After public void term() {Tfds.Now_enabled_n_();}
|
||||
@Test public void Create() {
|
||||
fxt .Create("A1", "A1 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("C123", "C123 data")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!9|!!!!;|!!!!=|"
|
||||
, "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 data\t"
|
||||
, "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt .Create("A1", "A1 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("C123", "C123 data")
|
||||
.Update("B12", "B12 changed")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!9|!!!!>|!!!!=|"
|
||||
, "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 changed\t"
|
||||
, "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Update_zip() {
|
||||
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Id_main].Ext_tid_(gplx.ios.Io_stream_.Tid_zip);
|
||||
// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok());
|
||||
// fxt .Create("A1", "A1 data")
|
||||
// .Create("B12", "B12 data")
|
||||
// .Create("C123", "C123 data")
|
||||
// .Update("B12", "B12 changed")
|
||||
// .Tst_regy_title("0|A1|C123|3\n")
|
||||
// .Tst_data_title(String_.Concat_lines_nl
|
||||
// ( "!!!!>|!!!!?|!!!!@|"
|
||||
// , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
// , "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
|
||||
// , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
// ))
|
||||
// .Tst_data_page(String_.Concat_lines_nl
|
||||
// ( "zipped:!!!!9|!!!!>|!!!!=|"
|
||||
// , "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
// , "!!!!\"\t##PX/\tB12\tB12 changed\t"
|
||||
// , "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
// ))
|
||||
// ;
|
||||
}
|
||||
@Test public void Create_out_of_order() {
|
||||
fxt .Create("C123", "C123 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("A1", "A1 data")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!=|!!!!;|!!!!9|"
|
||||
, "!!!!!\t##PX+\tC123\tC123 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 data\t"
|
||||
, "!!!!#\t##PX0\tA1\tA1 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Rename() {
|
||||
fxt .Create("A1", "A1 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("C123", "C123 data")
|
||||
.Rename("C123", "C1234")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!9|!!!!;|!!!!=|"
|
||||
, "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 data\t"
|
||||
, "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xow_data_mgr_fxt {
|
||||
Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
wiki.Db_mgr().Save_mgr().Page_id_next_(0);
|
||||
}
|
||||
public Xow_data_mgr_fxt Create(String ttl_str, String data) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(ttl_str));
|
||||
wiki.Db_mgr().Save_mgr().Data_create(ttl, Bry_.new_u8(data));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Update(String ttl_str, String data) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(ttl_str));
|
||||
Xoae_page page = Xoae_page.test_(wiki, ttl);
|
||||
wiki.Db_mgr().Save_mgr().Data_update(page, Bry_.new_u8(data));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Rename(String old_ttl, String new_ttl) {
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(old_ttl));
|
||||
Xoae_page page = Xoae_page.test_(wiki, ttl);
|
||||
wiki.Db_mgr().Save_mgr().Data_rename(page, ttl.Ns().Id(), Bry_.new_u8(new_ttl));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Tst_regy_title(String expd) {return Tst_regy(Xotdb_dir_info_.Name_title, expd);}
|
||||
Xow_data_mgr_fxt Tst_regy(String name, String expd) {
|
||||
Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/" + name + "/reg.csv");
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(file_orig));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Id_main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Id_main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
98
400_xowa/src_121_wiki_data/gplx/xowa/Xow_hive_mgr_fxt.java
Normal file
98
400_xowa/src_121_wiki_data/gplx/xowa/Xow_hive_mgr_fxt.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.tdbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_hive_mgr_fxt {
|
||||
public void Clear() {
|
||||
if (hive_mgr == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
hive_mgr = new Xob_hive_mgr(wiki);
|
||||
}
|
||||
hive_mgr.Clear();
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
} private Xob_hive_mgr hive_mgr; Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public void Find_nearby(String key, int count, boolean include_redirects, String... expd) {
|
||||
List_adp list = List_adp_.new_();
|
||||
wiki.Hive_mgr().Find_bgn(list, wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), count, include_redirects);
|
||||
int actl_len = list.Count();
|
||||
String[] actl = new String[actl_len];
|
||||
for (int i = 0; i < actl_len; i++) {
|
||||
Xowd_page_itm itm = (Xowd_page_itm)list.Get_at(i);
|
||||
actl[i] = String_.new_a7(itm.Ttl_page_db());
|
||||
}
|
||||
Tfds.Eq_ary_str(expd, actl);
|
||||
}
|
||||
public static void Ttls_create_rng(Xowe_wiki wiki, int files, int ttls_per_file) {Ttls_create_rng(wiki, wiki.Ns_mgr().Ns_main(), files, ttls_per_file);}
|
||||
public static void Ttls_create_rng(Xowe_wiki wiki, Xow_ns ns, int files, int ttls_per_file) {
|
||||
Xob_reg_wtr reg_wtr = new Xob_reg_wtr();
|
||||
byte dir_tid = Xotdb_dir_info_.Tid_ttl;
|
||||
int id = 0;
|
||||
int ttl_bry_len = Int_.DigitCount(ttls_per_file);
|
||||
Xob_xdat_file_wtr xdat_wtr = Xob_xdat_file_wtr.new_file_(ttls_per_file * 8, wiki.Tdb_fsys_mgr().Url_ns_dir(ns.Num_str(), Xotdb_dir_info_.Tid_ttl));
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
byte ltr = Byte_ascii.Ltr_A; byte[] ttl_0 = Bry_.Empty, ttl_n = Bry_.Empty;
|
||||
for (int fil_idx = 0; fil_idx < files; fil_idx++) {
|
||||
for (int ttl_idx = 0; ttl_idx < ttls_per_file; ttl_idx++) {
|
||||
tmp_bfr.Add_byte(ltr).Add_int_fixed(ttl_idx, ttl_bry_len);
|
||||
byte[] ttl_bry = tmp_bfr.Xto_bry_and_clear();
|
||||
if (ttl_idx == 0) ttl_0 = ttl_bry;
|
||||
else if (ttl_idx == ttls_per_file - 1) ttl_n = ttl_bry;
|
||||
Xotdb_page_itm_.Txt_ttl_save(xdat_wtr.Bfr(), id++, 0, ttl_idx, ttl_idx % 2 == 1, 1, ttl_bry);
|
||||
xdat_wtr.Add_idx(Byte_ascii.Nil);
|
||||
}
|
||||
xdat_wtr.Flush(wiki.Appe().Usr_dlg());
|
||||
reg_wtr.Add(ttl_0, ttl_n, ttls_per_file);
|
||||
++ltr;
|
||||
}
|
||||
reg_wtr.Flush(wiki.Tdb_fsys_mgr().Url_ns_reg(ns.Num_str(), dir_tid));
|
||||
}
|
||||
public Xow_hive_mgr_fxt Create_ctg(String key_str, int... pages) {Create_ctg(app, hive_mgr, key_str, pages); return this;}
|
||||
public static void Create_ctg(Xoae_app app, Xob_hive_mgr hive_mgr, String key_str, int... pages) {
|
||||
byte[] key_bry = Bry_.new_a7(key_str);
|
||||
Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
bfr.Add(key_bry);
|
||||
int pages_len = pages.length;
|
||||
for (int i = 0; i < pages_len; i++)
|
||||
bfr.Add_byte_pipe().Add_base85_len_5(pages[i]);
|
||||
bfr.Add_byte_nl();
|
||||
byte[] row = bfr.To_bry_and_rls();
|
||||
hive_mgr.Create(Xotdb_dir_info_.Tid_category, key_bry, row);
|
||||
}
|
||||
public Xow_hive_mgr_fxt Create_id(int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {Create_id(app, hive_mgr, id, fil_idx, row_idx, type_redirect, itm_len, ns_id, ttl); return this;}
|
||||
public static void Create_id(Xoae_app app, Xob_hive_mgr hive_mgr, int id, int fil_idx, int row_idx, boolean type_redirect, int itm_len, int ns_id, String ttl) {
|
||||
Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
byte[] key_bry = Base85_utl.XtoStrByAry(id, 5);
|
||||
bfr .Add(key_bry) .Add_byte_pipe()
|
||||
.Add_base85_len_5(fil_idx) .Add_byte_pipe()
|
||||
.Add_base85_len_5(row_idx) .Add_byte_pipe()
|
||||
.Add_byte(type_redirect ? Byte_ascii.Num_1 : Byte_ascii.Num_0).Add_byte_pipe()
|
||||
.Add_base85_len_5(itm_len) .Add_byte_pipe()
|
||||
.Add_base85_len_5(ns_id) .Add_byte_pipe()
|
||||
.Add_str(ttl) .Add_byte_nl();
|
||||
byte[] row = bfr.Xto_bry_and_clear();
|
||||
bfr.Mkr_rls();
|
||||
hive_mgr.Create(Xotdb_dir_info_.Tid_id, key_bry, row);
|
||||
}
|
||||
public Xow_hive_mgr_fxt Load(String url, String... expd) {
|
||||
String actl = Io_mgr.I.LoadFilStr(url);
|
||||
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(actl));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
95
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_hive_mgr.java
Normal file
95
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_hive_mgr.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.xowa.tdbs.*;
|
||||
public class Xowd_hive_mgr {
|
||||
public Xowd_hive_mgr(Xowe_wiki wiki, byte dir_tid) {
|
||||
this.wiki = wiki; fsys_mgr = wiki.Tdb_fsys_mgr(); this.dir_tid = dir_tid;
|
||||
dir_tid_reg = dir_tid == Xotdb_dir_info_.Tid_page ? Xotdb_dir_info_.Tid_ttl : dir_tid;
|
||||
} Xowe_wiki wiki; Xotdb_fsys_mgr fsys_mgr; Xowd_regy_mgr reg_mgr; byte dir_tid;
|
||||
byte dir_tid_reg;
|
||||
public void Create(Xow_ns ns, byte[] key, byte[] data, gplx.lists.ComparerAble comparer) {
|
||||
if (reg_mgr == null) reg_mgr = new Xowd_regy_mgr(fsys_mgr.Url_ns_reg(ns.Num_str(), dir_tid_reg));
|
||||
int fil_idx = 0;
|
||||
if (reg_mgr.Files_ary().length == 0) {
|
||||
reg_mgr.Create(key);
|
||||
fil_idx = 0;
|
||||
}
|
||||
else {
|
||||
fil_idx = reg_mgr.Files_find(key);
|
||||
reg_mgr.Update_add(fil_idx, key);
|
||||
}
|
||||
Io_url url = fsys_mgr.Url_ns_fil(dir_tid, ns.Id(), fil_idx);
|
||||
byte[] bry = Io_mgr.I.LoadFilBry(url);
|
||||
Xob_xdat_file xdat = new Xob_xdat_file();
|
||||
if (bry != Bry_.Empty)
|
||||
xdat.Parse(bry, bry.length, url);
|
||||
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_m001();
|
||||
xdat.Insert(tmp, data);
|
||||
if (comparer != null)
|
||||
xdat.Sort(tmp, comparer);
|
||||
tmp.Mkr_rls();
|
||||
xdat.Save(url);
|
||||
reg_mgr.Save();
|
||||
}
|
||||
public void Create(byte[] key, byte[] data, gplx.lists.ComparerAble comparer) {
|
||||
if (reg_mgr == null) reg_mgr = new Xowd_regy_mgr(fsys_mgr.Url_site_reg(dir_tid));
|
||||
int fil_idx = 0;
|
||||
if (reg_mgr.Files_ary().length == 0) {
|
||||
reg_mgr.Create(key);
|
||||
fil_idx = 0;
|
||||
}
|
||||
else {
|
||||
fil_idx = reg_mgr.Files_find(key);
|
||||
reg_mgr.Update_add(fil_idx, key);
|
||||
}
|
||||
Io_url url = fsys_mgr.Url_site_fil(dir_tid, fil_idx);
|
||||
byte[] bry = Io_mgr.I.LoadFilBry(url);
|
||||
Xob_xdat_file xdat = new Xob_xdat_file();
|
||||
if (bry != Bry_.Empty)
|
||||
xdat.Parse(bry, bry.length, url);
|
||||
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_m001();
|
||||
xdat.Insert(tmp, data);
|
||||
if (comparer != null)
|
||||
xdat.Sort(tmp, comparer);
|
||||
tmp.Mkr_rls();
|
||||
xdat.Save(url);
|
||||
reg_mgr.Save();
|
||||
}
|
||||
public void Update(Xow_ns ns, byte[] old_key, byte[] new_key, byte[] data, int lkp_bgn, byte lkp_dlm, boolean exact, boolean sort) {
|
||||
if (reg_mgr == null) reg_mgr = new Xowd_regy_mgr(fsys_mgr.Url_ns_reg(ns.Num_str(), Xotdb_dir_info_.Tid_ttl));
|
||||
int fil_idx = reg_mgr.Files_find(old_key);
|
||||
boolean reg_save = false;
|
||||
if (new_key != null)
|
||||
reg_save = reg_mgr.Update_change(fil_idx, old_key, new_key);
|
||||
Io_url url = fsys_mgr.Url_ns_fil(dir_tid, ns.Id(), fil_idx);
|
||||
byte[] bry = Io_mgr.I.LoadFilBry(url);
|
||||
Xob_xdat_file xdat = new Xob_xdat_file();
|
||||
if (bry != Bry_.Empty)
|
||||
xdat.Parse(bry, bry.length, url);
|
||||
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_m001();
|
||||
Xob_xdat_itm itm = new Xob_xdat_itm();
|
||||
xdat.Find(itm, old_key, lkp_bgn, lkp_dlm, exact);
|
||||
if (itm.Missing()) return;
|
||||
xdat.Update(tmp, itm, data);
|
||||
if (sort) xdat.Sort(tmp, new Bry_comparer_bgn_eos(lkp_bgn));
|
||||
tmp.Mkr_rls();
|
||||
xdat.Save(url);
|
||||
if (reg_save) reg_mgr.Save();
|
||||
}
|
||||
}
|
||||
98
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_hive_mgr_tst.java
Normal file
98
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_hive_mgr_tst.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import org.junit.*; import gplx.xowa.tdbs.*;
|
||||
public class Xowd_hive_mgr_tst {
|
||||
Xowd_hive_mgr_fxt fxt = new Xowd_hive_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Create() {
|
||||
fxt.Create("A", "A|A data\n")
|
||||
.Tst_reg(String_.Concat_lines_nl("0|A|A|1"))
|
||||
.Tst_fil(0, String_.Concat("!!!!*|\n", "A|A data\n"))
|
||||
;
|
||||
}
|
||||
@Test public void Create_2() {
|
||||
fxt .Create("A", "A|1\n")
|
||||
.Create("B", "B|12\n")
|
||||
.Tst_reg(String_.Concat_lines_nl("0|A|B|2"))
|
||||
.Tst_fil(0, String_.Concat("!!!!%|!!!!&|\n", "A|1\n", "B|12\n"))
|
||||
;
|
||||
}
|
||||
@Test public void Create_3() {
|
||||
fxt .Create("A", "A|1\n")
|
||||
.Create("B", "B|12\n")
|
||||
.Create("C", "C|123\n")
|
||||
.Tst_reg(String_.Concat_lines_nl("0|A|C|3"))
|
||||
.Tst_fil(0, String_.Concat("!!!!%|!!!!&|!!!!'|\n", "A|1\n", "B|12\n", "C|123\n"))
|
||||
;
|
||||
}
|
||||
@Test public void Create_sort() {
|
||||
fxt .Create_and_sort("C", "C|1\n")
|
||||
.Create_and_sort("A", "A|12\n")
|
||||
.Create_and_sort("B", "B|123\n")
|
||||
.Tst_reg(String_.Concat_lines_nl("0|A|C|3"))
|
||||
.Tst_fil(0, String_.Concat("!!!!&|!!!!'|!!!!%|\n", "A|12\n", "B|123\n", "C|1\n"))
|
||||
;
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt .Create("A", "A|A data\n")
|
||||
.Create("B", "B|B data\n")
|
||||
.Create("C", "C|C data\n")
|
||||
.Tst_reg(String_.Concat_lines_nl("0|A|C|3"))
|
||||
.Tst_fil(0, String_.Concat("!!!!*|!!!!*|!!!!*|\n", "A|A data\n", "B|B data\n", "C|C data\n"))
|
||||
.Update("B", "B|changed\n")
|
||||
.Tst_reg(String_.Concat_lines_nl("0|A|C|3"))
|
||||
.Tst_fil(0, String_.Concat("!!!!*|!!!!+|!!!!*|\n", "A|A data\n", "B|changed\n", "C|C data\n"))
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xowd_hive_mgr_fxt {
|
||||
Xoae_app app; Xowe_wiki wiki; Xowd_hive_mgr mgr;
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
mgr = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_page);
|
||||
}
|
||||
public Xowd_hive_mgr_fxt Tst_reg(String expd) {
|
||||
Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/title/reg.csv");
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(file_orig));
|
||||
return this;
|
||||
}
|
||||
public Xowd_hive_mgr_fxt Tst_fil(int fil, String expd) {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, fil);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
public Xowd_hive_mgr_fxt Update(String key, String data) {
|
||||
mgr.Update(wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), null, Bry_.new_a7(data), 0, Byte_ascii.Pipe, true, true);
|
||||
return this;
|
||||
}
|
||||
public Xowd_hive_mgr_fxt Create(String key, String data) {
|
||||
mgr.Create(wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), Bry_.new_a7(data), null);
|
||||
return this;
|
||||
}
|
||||
public Xowd_hive_mgr_fxt Create_and_sort(String key, String data) {
|
||||
mgr.Create(wiki.Ns_mgr().Ns_main(), Bry_.new_a7(key), Bry_.new_a7(data), new Bry_comparer_bgn_eos(0));
|
||||
return this;
|
||||
}
|
||||
// public void Get(String ttl_str, boolean exists) {
|
||||
// Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_u8(ttl_str));
|
||||
// Xowd_page_itm row = mgr.Get(ttl.Ns(), ttl.Full_txt());
|
||||
// Tfds.Eq(exists, row != null);
|
||||
// }
|
||||
}
|
||||
62
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_hive_regy_itm.java
Normal file
62
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_hive_regy_itm.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xowd_hive_regy_itm {// csv file with the format of "idx|bgn|end|count"; EX: "0|AA|AZ|120\n1|BA|BZ|110"
|
||||
public Xowd_hive_regy_itm(int idx) {this.idx = idx;}
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public byte[] Bgn() {return bgn;} public Xowd_hive_regy_itm Bgn_(byte[] v) {bgn = v; return this;} private byte[] bgn;
|
||||
public byte[] End() {return end;} public Xowd_hive_regy_itm End_(byte[] v) {end = v; return this;} private byte[] end;
|
||||
public int Count() {return count;} public Xowd_hive_regy_itm Count_(int v) {this.count = v; return this;} private int count;
|
||||
public static Xowd_hive_regy_itm[] parse_fil_(ByteAry_fil utl) {
|
||||
List_adp rv = utl.Itms();
|
||||
byte[] ary = utl.Raw_bry();
|
||||
int ary_len = utl.Raw_len(); if (ary_len == 0) return Xowd_hive_regy_itm.Ary_empty; //throw Err_mgr._.fmt_("xowa.wiki.data", "title_registry_file_not_found", "title_registry file not found: ~{0}", utl.Fil().Xto_api());
|
||||
Int_obj_ref pos = Int_obj_ref.zero_();
|
||||
while (pos.Val() < ary_len) {
|
||||
Xowd_hive_regy_itm file = new Xowd_hive_regy_itm();
|
||||
file.idx = Bry_.ReadCsvInt(ary, pos, Bry_.Dlm_fld);
|
||||
file.bgn = Bry_.ReadCsvBry(ary, pos, Bry_.Dlm_fld); // skip bgn
|
||||
file.end = Bry_.ReadCsvBry(ary, pos, Bry_.Dlm_fld);
|
||||
file.count = Bry_.ReadCsvInt(ary, pos, Bry_.Dlm_row);
|
||||
rv.Add(file);
|
||||
}
|
||||
return (Xowd_hive_regy_itm[])utl.Xto_itms(Xowd_hive_regy_itm.class);
|
||||
}
|
||||
public Xowd_hive_regy_itm() {}
|
||||
public Xowd_hive_regy_itm(int id, byte[] bgn, byte[] end, int count) {
|
||||
this.idx = id; this.bgn = bgn; this.end = end; this.count = count;
|
||||
}
|
||||
public void Srl_save(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(idx).Add_byte_pipe()
|
||||
.Add(bgn).Add_byte_pipe()
|
||||
.Add(end).Add_byte_pipe()
|
||||
.Add_int_variable(count).Add_byte_nl();
|
||||
}
|
||||
public static Xowd_hive_regy_itm tmp_() {return new Xowd_hive_regy_itm();}
|
||||
public static final Xowd_hive_regy_itm[] Ary_empty = new Xowd_hive_regy_itm[0];
|
||||
}
|
||||
class Xowd_ttl_file_comparer_end implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xowd_hive_regy_itm lhs = (Xowd_hive_regy_itm)lhsObj, rhs = (Xowd_hive_regy_itm)rhsObj;
|
||||
if (lhs.Count() == 0) return Bry_.Compare(rhs.End(), lhs.Bgn());
|
||||
//else if (rhs.Count() == 0) return Bry_.Compare(lhs.End(), rhs.End()); // NOTE: this line mirrors the top, but is actually covered by below
|
||||
else return Bry_.Compare(lhs.End(), rhs.End());
|
||||
}
|
||||
public static final Xowd_ttl_file_comparer_end _ = new Xowd_ttl_file_comparer_end(); Xowd_ttl_file_comparer_end() {}
|
||||
}
|
||||
76
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_regy_mgr.java
Normal file
76
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_regy_mgr.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import gplx.lists.*;
|
||||
public class Xowd_regy_mgr {
|
||||
public static final int Not_found = -1;
|
||||
public Xowd_regy_mgr() {}
|
||||
public Xowd_regy_mgr(Io_url fil) {this.Init(fil);}
|
||||
public Io_url Fil() {return fil;} Io_url fil;
|
||||
public void Init(Io_url fil) {this.fil = fil; files_ary = Xowd_hive_regy_itm.parse_fil_(ByteAry_fil._.Ini_file(fil));}
|
||||
public Xowd_hive_regy_itm[] Files_ary() {return files_ary;} private Xowd_hive_regy_itm[] files_ary;
|
||||
public void Clear() {files_ary = Xowd_hive_regy_itm.Ary_empty;}
|
||||
public int Files_find(byte[] key) {
|
||||
if (files_ary.length == 0) return Xowd_regy_mgr.Regy_null; // NOTE: FindSlot does not accept empty ary; returning 0, b/c Find returns likely file_idx; EX: regy of 0|B|D and 1|F|H; A returns 0; Z returns 1
|
||||
return CompareAble_.FindSlot(comparer, files_ary, comparer_itm.End_(key));
|
||||
} ComparerAble comparer = Xowd_ttl_file_comparer_end._; Xowd_hive_regy_itm comparer_itm = Xowd_hive_regy_itm.tmp_().Count_(1);
|
||||
public Xowd_hive_regy_itm Create(byte[] key) {
|
||||
int itm_idx = files_ary.length;
|
||||
files_ary = (Xowd_hive_regy_itm[])Array_.Resize(files_ary, itm_idx + 1);
|
||||
Xowd_hive_regy_itm rv = new Xowd_hive_regy_itm(itm_idx).Bgn_(key).End_(key).Count_(1);
|
||||
files_ary[itm_idx] = rv;
|
||||
return rv;
|
||||
}
|
||||
public Xowd_hive_regy_itm Update_add(int fil_idx, byte[] key) {
|
||||
Xowd_hive_regy_itm rv = files_ary[fil_idx];
|
||||
rv.Count_(rv.Count() + 1);
|
||||
if (Bry_.Compare(key, rv.Bgn()) < CompareAble_.Same)
|
||||
rv.Bgn_(key);
|
||||
else if (Bry_.Compare(key, rv.End()) > CompareAble_.Same)
|
||||
rv.End_(key);
|
||||
return rv;
|
||||
}
|
||||
public boolean Update_change(int fil_idx, byte[] old_key, byte[] new_key) {
|
||||
Xowd_hive_regy_itm rv = files_ary[fil_idx];
|
||||
boolean changed = false;
|
||||
if (Bry_.Eq(old_key, rv.Bgn())) {
|
||||
rv.Bgn_(new_key);
|
||||
changed = true;
|
||||
}
|
||||
else if (Bry_.Eq(old_key, rv.End())) {
|
||||
rv.End_(new_key);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
public Xowd_hive_regy_itm Update_del(int fil_idx, byte[] key) {
|
||||
Xowd_hive_regy_itm itm = files_ary[fil_idx];
|
||||
itm.Count_(itm.Count() - 1);
|
||||
throw Exc_.new_unimplemented(); // FUTURE: note that deletes are harder; rng ends could be deleted, so would need to open file and get new rng end
|
||||
}
|
||||
public void Save() {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = files_ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_hive_regy_itm itm = files_ary[i];
|
||||
itm.Srl_save(bfr);
|
||||
}
|
||||
Io_mgr.I.SaveFilBfr(fil, bfr);
|
||||
}
|
||||
public static final int Regy_null = -1;
|
||||
}
|
||||
88
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_regy_mgr_tst.java
Normal file
88
400_xowa/src_121_wiki_data/gplx/xowa/Xowd_regy_mgr_tst.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
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; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class Xowd_regy_mgr_tst {
|
||||
Xowd_regy_mgr_fxt fxt = new Xowd_regy_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Create_cur_is_empty() {fxt.Create("A").Save().Tst_file(String_.Concat_lines_nl("0|A|A|1"));}
|
||||
@Test public void Create_cur_has_one() {fxt.Load(String_.Concat_lines_nl("0|A|A|1")).Create("B").Save().Tst_file(String_.Concat_lines_nl("0|A|A|1", "1|B|B|1"));}
|
||||
@Test public void Update_1st_end() {fxt.Load(String_.Concat_lines_nl("0|B|B|1")).Update_add(0, "C").Save().Tst_file(String_.Concat_lines_nl("0|B|C|2"));}
|
||||
@Test public void Update_1st_bgn() {fxt.Load(String_.Concat_lines_nl("0|B|B|1")).Update_add(0, "A").Save().Tst_file(String_.Concat_lines_nl("0|A|B|2"));}
|
||||
@Test public void Update_mid() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_add(0, "C").Save().Tst_file(String_.Concat_lines_nl("0|B|D|3"));}
|
||||
@Test public void Update_bgn() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_add(0, "A").Save().Tst_file(String_.Concat_lines_nl("0|A|D|3"));}
|
||||
@Test public void Update_end() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_add(0, "E").Save().Tst_file(String_.Concat_lines_nl("0|B|E|3"));}
|
||||
@Test public void Update_change_bgn() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_change(0, "B", "A").Save().Tst_file(String_.Concat_lines_nl("0|A|D|2"));}
|
||||
@Test public void Update_change_end() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_change(0, "D", "E").Save().Tst_file(String_.Concat_lines_nl("0|B|E|2"));}
|
||||
@Test public void Update_change_mid() {fxt.Load(String_.Concat_lines_nl("0|B|D|2")).Update_change(0, "C1", "C2").Save().Tst_file(String_.Concat_lines_nl("0|B|D|2"));}
|
||||
@Test public void Find_none() {fxt.Tst_find("A", Xowd_regy_mgr.Regy_null);}
|
||||
@Test public void Find_existing() {
|
||||
fxt.Load(String_.Concat_lines_nl
|
||||
( "0|B|D|3"
|
||||
, "1|E|G|3"
|
||||
, "2|H|J|3"
|
||||
))
|
||||
.Tst_find("B", 0).Tst_find("C", 0).Tst_find("D", 0)
|
||||
.Tst_find("A", 0)
|
||||
.Tst_find("Z", 2)
|
||||
.Tst_find("Da", 1)
|
||||
;
|
||||
}
|
||||
@Test public void Find_existing_null() {
|
||||
fxt.Load(String_.Concat_lines_nl
|
||||
( "0|B|D|3"
|
||||
, "1|D|H|0"
|
||||
, "2|H|J|3"
|
||||
))
|
||||
.Tst_find("B", 0).Tst_find("C", 0).Tst_find("D", 0)
|
||||
.Tst_find("A", 0)
|
||||
.Tst_find("Z", 2)
|
||||
.Tst_find("Da", 1) // rely on
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xowd_regy_mgr_fxt {
|
||||
Xowd_regy_mgr mgr; Io_url mgr_url;
|
||||
public void Clear() {
|
||||
if (mgr == null) {
|
||||
mgr_url = Io_url_.mem_fil_("mem/hive_regy.csv");
|
||||
Io_mgr.I.DeleteFil(mgr_url);
|
||||
mgr = new Xowd_regy_mgr(mgr_url);
|
||||
}
|
||||
else {
|
||||
mgr.Clear();
|
||||
}
|
||||
}
|
||||
public Xowd_regy_mgr_fxt Create(String key) {mgr.Create(Bry_.new_a7(key)); return this;}
|
||||
public Xowd_regy_mgr_fxt Update_add(int fil_idx, String key) {mgr.Update_add(fil_idx, Bry_.new_a7(key)); return this;}
|
||||
public Xowd_regy_mgr_fxt Update_change(int fil_idx, String old_key, String new_key) {mgr.Update_change(fil_idx, Bry_.new_a7(old_key), Bry_.new_a7(new_key)); return this;}
|
||||
public Xowd_regy_mgr_fxt Load(String lines) {
|
||||
Io_mgr.I.SaveFilStr(mgr_url, lines);
|
||||
mgr = new Xowd_regy_mgr(mgr_url);
|
||||
return this;
|
||||
}
|
||||
public Xowd_regy_mgr_fxt Save() {mgr.Save(); return this;}
|
||||
public Xowd_regy_mgr_fxt Tst_file(String expd) {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.I.LoadFilStr(mgr_url));
|
||||
return this;
|
||||
}
|
||||
public Xowd_regy_mgr_fxt Tst_find(String find, int expd) {
|
||||
Tfds.Eq(expd, mgr.Files_find(Bry_.new_a7(find)));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user