mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
39
400_xowa/src/gplx/xowa/wikis/tdbs/ByteAry_fil.java
Normal file
39
400_xowa/src/gplx/xowa/wikis/tdbs/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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
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.Instance.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 Instance = new ByteAry_fil(); ByteAry_fil() {}
|
||||
}
|
||||
55
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_dir_info.java
Normal file
55
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_dir_info.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.ios.*;
|
||||
public class Xotdb_dir_info {
|
||||
public Xotdb_dir_info(boolean ns_root, byte id, String name) {this.ns_root = ns_root; this.id = id; this.name = name;}
|
||||
public byte Id() {return id;} private byte id;
|
||||
public String Name() {return name;} private String name;
|
||||
public boolean Ns_root() {return ns_root;} private boolean ns_root;
|
||||
public String Ext() {return ext_str;} private String ext_str = Wtr_xdat_str;
|
||||
public byte[] Ext_bry() {return ext_bry;} private byte[] ext_bry = Wtr_xdat_bry;
|
||||
public byte Ext_tid() {return ext_tid;}
|
||||
public Xotdb_dir_info Ext_tid_(byte v) {
|
||||
ext_tid = v;
|
||||
ext_bry = Wtr_ext(v);
|
||||
ext_str = String_.new_a7(ext_bry);
|
||||
return this;
|
||||
} byte ext_tid = gplx.ios.Io_stream_.Tid_raw;
|
||||
|
||||
public static final String Wtr_xdat_str = ".xdat", Wtr_zip_str = ".zip", Wtr_gz_str = ".gz", Wtr_bz2_str = ".bz2";
|
||||
public static final byte[] Wtr_xdat_bry = Bry_.new_a7(Wtr_xdat_str), Wtr_zip_bry = Bry_.new_a7(Wtr_zip_str), Wtr_gz_bry = Bry_.new_a7(Wtr_gz_str), Wtr_bz2_bry = Bry_.new_a7(Wtr_bz2_str);
|
||||
public static String Wtr_dir(byte v) {
|
||||
switch (v) {
|
||||
case gplx.ios.Io_stream_.Tid_raw : return "";
|
||||
case gplx.ios.Io_stream_.Tid_zip : return "_zip";
|
||||
case gplx.ios.Io_stream_.Tid_gzip : return "_gz";
|
||||
case gplx.ios.Io_stream_.Tid_bzip2 : return "_bz2";
|
||||
default : throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
public static byte[] Wtr_ext(byte v) {
|
||||
switch (v) {
|
||||
case gplx.ios.Io_stream_.Tid_raw : return Wtr_xdat_bry;
|
||||
case gplx.ios.Io_stream_.Tid_zip : return Wtr_zip_bry;
|
||||
case gplx.ios.Io_stream_.Tid_gzip : return Wtr_gz_bry;
|
||||
case gplx.ios.Io_stream_.Tid_bzip2 : return Wtr_bz2_bry;
|
||||
default : throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_dir_info_.java
Normal file
62
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_dir_info_.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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xotdb_dir_info_ {
|
||||
public static String Tid_name(byte tid) {
|
||||
switch (tid) {
|
||||
case Xotdb_dir_info_.Tid_page: return Xotdb_dir_info_.Name_page;
|
||||
case Xotdb_dir_info_.Tid_ttl: return Xotdb_dir_info_.Name_title;
|
||||
case Xotdb_dir_info_.Tid_id: return Xotdb_dir_info_.Name_id;
|
||||
case Xotdb_dir_info_.Tid_category: return Xotdb_dir_info_.Name_category;
|
||||
case Xotdb_dir_info_.Tid_category2_link: return Xotdb_dir_info_.Name_category2_link;
|
||||
case Xotdb_dir_info_.Tid_category2_main: return Xotdb_dir_info_.Name_category2_main;
|
||||
case Xotdb_dir_info_.Tid_search_ttl: return Xotdb_dir_info_.Name_search_ttl;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static Xotdb_dir_info[] regy_() {
|
||||
Xotdb_dir_info[] rv = new Xotdb_dir_info[5];
|
||||
regy_itm_(rv, Bool_.Y, Tid_page);
|
||||
regy_itm_(rv, Bool_.Y, Tid_ttl);
|
||||
regy_itm_(rv, Bool_.N, Tid_id);
|
||||
regy_itm_(rv, Bool_.N, Tid_category);
|
||||
regy_itm_(rv, Bool_.N, Tid_search_ttl);
|
||||
return rv;
|
||||
}
|
||||
public static boolean Dir_name_is_tdb(String dir_name) {
|
||||
return String_.In(dir_name, Name_ns, Name_site, Name_cfg, "tmp");
|
||||
}
|
||||
private static void regy_itm_(Xotdb_dir_info[] rv, boolean ns_root, byte id) {rv[id] = new Xotdb_dir_info(ns_root, id, Tid_name(id));}
|
||||
public static final String Ext_xdat = ".xdat", Ext_csv = ".csv", Ext_zip = ".zip"
|
||||
, Name_ns = "ns", Name_site = "site", Name_page = "page", Name_title = "title", Name_id = "id", Name_category = "category", Name_search_ttl = "search_title", Name_zip_suffix = "_zip"
|
||||
, Name_cfg = "cfg"
|
||||
, Name_reg_fil = "reg.csv", Name_category2 = "category2", Name_category2_link = "link", Name_category2_main = "main"
|
||||
;
|
||||
public static final byte[] Bry_xdat = Bry_.new_a7(Ext_xdat), Bry_csv = Bry_.new_a7(Ext_csv), Bry_zip = Bry_.new_a7(Ext_zip);
|
||||
public static final byte
|
||||
Tid_page = 0
|
||||
, Tid_ttl = 1
|
||||
, Tid_id = 2
|
||||
, Tid_category = 3
|
||||
, Tid_search_ttl = 4
|
||||
// , Tid_category2 = 5
|
||||
, Tid_category2_link = 5
|
||||
, Tid_category2_main = 6
|
||||
;
|
||||
public static final byte Regy_tid_max = 7;
|
||||
}
|
||||
95
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr.java
Normal file
95
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.utils.*;
|
||||
public class Xotdb_fsys_mgr {
|
||||
private final Io_url root_dir; private final Xow_ns_mgr ns_mgr;
|
||||
public Xotdb_fsys_mgr(Io_url root_dir, Xow_ns_mgr ns_mgr) {
|
||||
this.root_dir = root_dir; this.ns_mgr = ns_mgr;
|
||||
this.tmp_dir = root_dir.GenSubDir("tmp");
|
||||
this.ns_dir = root_dir.GenSubDir(Xotdb_dir_info_.Name_ns);
|
||||
this.site_dir = root_dir.GenSubDir(Xotdb_dir_info_.Name_site);
|
||||
}
|
||||
public Io_url Tmp_dir() {return tmp_dir;} private final Io_url tmp_dir;
|
||||
public Io_url Ns_dir() {return ns_dir;} private final Io_url ns_dir;
|
||||
public Io_url Site_dir() {return site_dir;} private final Io_url site_dir;
|
||||
public Io_url Cfg_wiki_core_fil() {return root_dir.GenSubFil_nest(Const_url_cfg, "wiki_core.gfs");}
|
||||
public Io_url Cfg_wiki_stats_fil() {return root_dir.GenSubFil_nest(Const_url_cfg, "wiki_stats.gfs");}
|
||||
public Xotdb_dir_info[] Tdb_dir_regy() {return dir_regy;} private final Xotdb_dir_info[] dir_regy = Xotdb_dir_info_.regy_();
|
||||
public Io_url Url_ns_dir(String ns_num, byte tid) {return ns_dir.GenSubDir_nest(ns_num, Xotdb_dir_info_.Tid_name(tid));}
|
||||
public Io_url Url_ns_reg(String ns_num, byte tid) {return ns_dir.GenSubFil_nest(ns_num, Xotdb_dir_info_.Tid_name(tid), Xotdb_dir_info_.Name_reg_fil);}
|
||||
public Io_url Url_ns_fil(byte tid, int ns_id, int fil_idx) {
|
||||
Xotdb_dir_info dir_info = dir_regy[tid];
|
||||
String dir_name = dir_info.Name() + Xotdb_dir_info.Wtr_dir(dir_info.Ext_tid());
|
||||
return Xotdb_fsys_mgr.Url_fil(ns_dir.GenSubDir_nest(Int_.To_str_pad_bgn_zero(ns_id, 3), dir_name), fil_idx, dir_regy[tid].Ext_bry());
|
||||
}
|
||||
public Io_url Url_site_fil(byte tid, int fil_idx) {return Xotdb_fsys_mgr.Url_fil(Url_site_dir(tid), fil_idx, Xotdb_dir_info_.Bry_xdat);}
|
||||
public Io_url Url_site_reg(byte tid) {return Url_site_dir(tid).GenSubFil(Xotdb_dir_info_.Name_reg_fil);}
|
||||
public Io_url Url_site_dir(byte tid) {
|
||||
switch (tid) {
|
||||
case Xotdb_dir_info_.Tid_category2_link: return site_dir.GenSubDir_nest(Xotdb_dir_info_.Name_category2, Xotdb_dir_info_.Name_category2_link);
|
||||
case Xotdb_dir_info_.Tid_category2_main: return site_dir.GenSubDir_nest(Xotdb_dir_info_.Name_category2, Xotdb_dir_info_.Name_category2_main);
|
||||
default: return site_dir.GenSubDir_nest(Xotdb_dir_info_.Tid_name(tid));
|
||||
}
|
||||
}
|
||||
public void Scan_dirs() {
|
||||
Scan_dirs_zip(this, Xotdb_dir_info_.Tid_page);
|
||||
Scan_dirs_ns(ns_dir, ns_mgr);
|
||||
}
|
||||
private static void Scan_dirs_zip(Xotdb_fsys_mgr fsys_mgr, byte id) {
|
||||
Io_url[] dirs = Io_mgr.Instance.QueryDir_args(fsys_mgr.Ns_dir().GenSubDir_nest("000")).FilPath_("*page*").DirOnly_().Recur_(false).ExecAsUrlAry();
|
||||
int len = dirs.length;
|
||||
byte tid = gplx.ios.Io_stream_.Tid_raw; // needed for Xoa_xowa_exec_tst
|
||||
for (int i = 0; i < len; i++) {
|
||||
Io_url dir = dirs[i];
|
||||
String dir_name = dir.NameOnly();
|
||||
if (String_.Eq(dir_name, "page")) {tid = gplx.ios.Io_stream_.Tid_raw; break;}
|
||||
else if (String_.Eq(dir_name, "page_zip")) tid = gplx.ios.Io_stream_.Tid_zip;
|
||||
else if (String_.Eq(dir_name, "page_gz")) tid = gplx.ios.Io_stream_.Tid_gzip;
|
||||
else if (String_.Eq(dir_name, "page_bz2")) tid = gplx.ios.Io_stream_.Tid_bzip2;
|
||||
}
|
||||
fsys_mgr.Tdb_dir_regy()[id].Ext_tid_(tid);
|
||||
}
|
||||
private static Hash_adp Scan_dirs_ns(Io_url ns_dir, Xow_ns_mgr ns_mgr) {
|
||||
Io_url[] ns_dirs = Io_mgr.Instance.QueryDir_args(ns_dir).Recur_(false).DirOnly_().ExecAsUrlAry();
|
||||
int len = ns_dirs.length;
|
||||
Hash_adp rv = Hash_adp_.new_();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int ns_int = Int_.parse_or(ns_dirs[i].NameOnly(), Int_.Min_value); if (ns_int == Int_.Min_value) continue;
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_int); if (ns == null) continue;
|
||||
ns.Exists_(true);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Io_url Url_fil(Io_url root_dir, int fil_idx, byte[] ext) {return Xos_url_gen.bld_fil_(root_dir, fil_idx, ext);} private static final String Const_url_cfg = "cfg";
|
||||
public static Io_url Find_file_or_fail(Io_url dir, String file_name, String file_ext_0, String file_ext_1) {
|
||||
Io_url url = Find_file_or_null(dir, file_name, file_ext_0, file_ext_1);
|
||||
if (url == null) throw Err_.new_wo_type("could not find file", "dir", dir.Raw(), "name", file_name, "ext_0", file_ext_0, "ext_1", file_ext_1);
|
||||
return url;
|
||||
}
|
||||
public static Io_url Find_file_or_null(Io_url dir, String file_name, String file_ext_0, String file_ext_1) {
|
||||
Io_url url = Xobd_rdr.Find_fil_by(dir, file_name + file_ext_0);
|
||||
if (url == null) {
|
||||
url = Xobd_rdr.Find_fil_by(dir, file_name + file_ext_1);
|
||||
if (url == null) return null;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java
Normal file
38
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_fsys_mgr_tst.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xotdb_fsys_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_fsys_mgr_fxt fxt = new Xow_fsys_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat");
|
||||
fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip");
|
||||
}
|
||||
}
|
||||
class Xow_fsys_mgr_fxt {
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
Xoae_app app; Xowe_wiki wiki;
|
||||
public Xow_fsys_mgr_fxt Zip_(byte tid, boolean v) {wiki.Tdb_fsys_mgr().Tdb_dir_regy()[tid].Ext_tid_(v ? gplx.ios.Io_stream_.Tid_zip : gplx.ios.Io_stream_.Tid_raw); return this;}
|
||||
public void Url_ns_fil(byte tid, int ns_id, int fil_idx, String expd) {
|
||||
Tfds.Eq(expd, wiki.Tdb_fsys_mgr().Url_ns_fil(tid, ns_id, fil_idx).Raw());
|
||||
}
|
||||
}
|
||||
88
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_itm_.java
Normal file
88
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_itm_.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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xotdb_page_itm_ {
|
||||
static final int Txt_len_id = 5, Txt_len_fil_idx = 5, Txt_len_row_idx = 5, Txt_len_type = 1, Txt_len_text_len = 5;
|
||||
public static final int Txt_ttl_pos = Txt_len_id + Txt_len_fil_idx + Txt_len_row_idx + Txt_len_type + Txt_len_text_len + 5;
|
||||
public static final int Txt_ttl_len__fixed = Txt_len_id + Txt_len_fil_idx + Txt_len_row_idx + Txt_len_type + Txt_len_text_len + 5 + 1; // 5=| 1=\n
|
||||
public static Xowd_page_itm Txt_ttl_load(byte[] bry) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm();
|
||||
Txt_ttl_load(rv, bry, 0, bry.length);
|
||||
return rv;
|
||||
}
|
||||
public static void Txt_ttl_load(Xowd_page_itm page, byte[] bry) {Txt_ttl_load(page, bry, 0, bry.length);}
|
||||
private static void Txt_ttl_load(Xowd_page_itm page, byte[] bry, int bgn, int end) {
|
||||
try {
|
||||
page.Init_by_tdb
|
||||
( Base85_utl.XtoIntByAry (bry, bgn + 0, bgn + 4)
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 6, bgn + 10)
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 12, bgn + 16)
|
||||
, bry[18] == Byte_ascii.Num_1
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 20, bgn + 24)
|
||||
, page.Ns_id()
|
||||
, Bry_.Mid (bry, bgn + 26, end)
|
||||
);
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "xo", "parse_by_ttl failed", "ttl", String_.new_u8(bry, bgn, end));}
|
||||
}
|
||||
public static void Txt_ttl_save(Bry_bfr bfr, Xowd_page_itm page) {Txt_ttl_save(bfr, page.Id(), page.Text_db_id(), page.Tdb_row_idx(), page.Redirected(), page.Text_len(), page.Ttl_page_db());}
|
||||
public static void Txt_ttl_save(Bry_bfr bfr, int id, int file_idx, int row_idx, boolean redirect, int text_len, byte[] ttl_wo_ns) {
|
||||
bfr .Add_base85_len_5(id) .Add_byte_pipe()
|
||||
.Add_base85_len_5(file_idx) .Add_byte_pipe()
|
||||
.Add_base85_len_5(row_idx) .Add_byte_pipe()
|
||||
.Add_byte(redirect ? Byte_ascii.Num_1 : Byte_ascii.Num_0).Add_byte_pipe()
|
||||
.Add_base85_len_5(text_len) .Add_byte_pipe()
|
||||
.Add(ttl_wo_ns) .Add_byte_nl()
|
||||
;
|
||||
}
|
||||
public static void Txt_id_load(Xowd_page_itm page, byte[] bry) {Txt_id_load(page, bry, 0, bry.length);}
|
||||
private static void Txt_id_load(Xowd_page_itm page, byte[] bry, int bgn, int end) {
|
||||
try {
|
||||
page.Clear();
|
||||
page.Init_by_tdb
|
||||
( Base85_utl.XtoIntByAry (bry, bgn + 0, bgn + 4)
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 6, bgn + 10)
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 12, bgn + 16)
|
||||
, bry[18] == Byte_ascii.Num_1
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 20, bgn + 24)
|
||||
, Base85_utl.XtoIntByAry (bry, bgn + 26, bgn + 30)
|
||||
, Bry_.Mid (bry, bgn + 32, end)
|
||||
);
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "xo", "parse_by_id failed", "id", String_.new_u8(bry, bgn, end));}
|
||||
}
|
||||
public static void Txt_id_save(Bry_bfr bfr, Xowd_page_itm page) {
|
||||
bfr .Add_base85_len_5(page.Id()) .Add_byte_pipe()
|
||||
.Add_base85_len_5(page.Text_db_id()) .Add_byte_pipe()
|
||||
.Add_base85_len_5(page.Tdb_row_idx()) .Add_byte_pipe()
|
||||
.Add_byte(page.Redirected() ? Byte_ascii.Num_1 : Byte_ascii.Num_0).Add_byte_pipe()
|
||||
.Add_base85_len_5(page.Text_len()) .Add_byte_pipe()
|
||||
.Add_base85_len_5(page.Ns_id()) .Add_byte_pipe()
|
||||
.Add(page.Ttl_page_db()) .Add_byte_nl();
|
||||
}
|
||||
public static void Txt_page_save(Bry_bfr bfr, int id, DateAdp modified_on, byte[] title, byte[] text, boolean add_nl) {
|
||||
int ts = Bit_.Xto_int_date_short(modified_on.XtoSegAry());
|
||||
bfr .Add_base85(id , Base85_utl.Len_int) .Add_byte(Txt_page_dlm) // needed for mass template load
|
||||
.Add_base85(ts , Base85_utl.Len_int) .Add_byte(Txt_page_dlm)
|
||||
.Add(title) .Add_byte(Txt_page_dlm) // needed for rebuilding ttl files
|
||||
.Add(text) .Add_byte(Txt_page_dlm);
|
||||
if (add_nl)
|
||||
bfr.Add_byte_nl(); // NOTE: each page row is separated by \t\n
|
||||
}
|
||||
public static final byte Txt_page_dlm = Byte_ascii.Tab;
|
||||
public static final int Txt_page_len__fixed = 1 + 5 + 1 + 5 + 1 + 1 + 1; // \tid|date|title|text\n
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_raw_parser.java
Normal file
60
400_xowa/src/gplx/xowa/wikis/tdbs/Xotdb_page_raw_parser.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.brys.*; import gplx.ios.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.bldrs.*;
|
||||
public class Xotdb_page_raw_parser {
|
||||
public void Init(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, int load_len) {
|
||||
this.wiki = wiki; ns_mgr = wiki.Ns_mgr();
|
||||
rdr = new Io_line_rdr(usr_dlg, new Io_url[1]);
|
||||
rdr.Line_dlm_(Byte_ascii.Tab).Load_len_(load_len).Key_gen_(Io_line_rdr_key_gen_all.Instance);
|
||||
}
|
||||
public void Init_ns(Xow_ns ns_itm) {this.ns_itm = ns_itm;}
|
||||
public void Reset_one(Io_url url) {
|
||||
rdr.Reset_one(url);
|
||||
}
|
||||
public void Load(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, Xow_ns ns_itm, Io_url[] urls, int load_len) {
|
||||
this.wiki = wiki; ns_mgr = wiki.Ns_mgr(); this.ns_itm = ns_itm;
|
||||
rdr = new Io_line_rdr(usr_dlg, urls);
|
||||
rdr.Line_dlm_(Byte_ascii.Tab).Load_len_(load_len).Key_gen_(Io_line_rdr_key_gen_all.Instance);
|
||||
} Io_line_rdr rdr; Xowe_wiki wiki; Xow_ns_mgr ns_mgr; Xow_ns ns_itm;
|
||||
public void Skip_first_line() {
|
||||
rdr.Read_next();
|
||||
int pos = Bry_find_.Find_fwd(rdr.Bfr(), Byte_ascii.Nl);
|
||||
// rdr.Move(pos + 1);
|
||||
rdr.Truncate(pos + 1);
|
||||
}
|
||||
public boolean Read(Xowd_page_itm page) {
|
||||
boolean read = false;
|
||||
read = rdr.Read_next(); if (!read) return false;
|
||||
int id = Base85_utl.XtoIntByAry(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 2);
|
||||
page.Id_(id);
|
||||
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read timestamp");
|
||||
int timestamp = Base85_utl.XtoIntByAry(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
|
||||
page.Modified_on_(Bit_.Xto_date_short(timestamp));
|
||||
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read ttl");
|
||||
byte[] ttl = Bry_.Mid(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
|
||||
page.Ttl_(ttl, ns_mgr);
|
||||
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read text");
|
||||
byte[] text = Bry_.Mid(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
|
||||
page.Text_(text);
|
||||
rdr.Bfr_last_read_add(1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.ios.*;
|
||||
public class Io_line_rdr_key_gen_all implements Io_line_rdr_key_gen {
|
||||
public void Gen(Io_line_rdr bfr) {
|
||||
bfr.Key_pos_bgn_(bfr.Itm_pos_bgn()).Key_pos_end_(bfr.Itm_pos_end());
|
||||
}
|
||||
public static final Io_line_rdr_key_gen_all Instance = new Io_line_rdr_key_gen_all(); Io_line_rdr_key_gen_all() {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
public class Bry_comparer_bgn_eos implements gplx.lists.ComparerAble {
|
||||
public Bry_comparer_bgn_eos(int bgn) {this.bgn = bgn;} private int bgn;
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
|
||||
return Bry_.Compare(lhs, bgn, lhs.length, rhs, bgn, rhs.length);
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xoa_hive_mgr.java
Normal file
40
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xoa_hive_mgr.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
public class Xoa_hive_mgr {
|
||||
public Xoa_hive_mgr(Xoae_app app) {this.app = app;} private Xoae_app app;
|
||||
public Xob_xdat_itm Itm() {return xdat_itm;}
|
||||
public int Find_fil(Io_url hive_root, byte[] ttl) {
|
||||
Io_url hive_url = hive_root.GenSubFil(Xotdb_dir_info_.Name_reg_fil);
|
||||
if (!hive_url.Eq(regy_mgr.Fil()))
|
||||
regy_mgr.Init(hive_url);
|
||||
return regy_mgr.Files_find(ttl);
|
||||
} private Xowd_regy_mgr regy_mgr = new Xowd_regy_mgr(); Int_obj_ref bry_len = Int_obj_ref.zero_(); Xob_xdat_file xdat_rdr = new Xob_xdat_file(); Xob_xdat_itm xdat_itm = new Xob_xdat_itm();
|
||||
public Xowd_regy_mgr Regy_mgr() {return regy_mgr;}
|
||||
public Xob_xdat_file Get_rdr(Io_url hive_root, byte[] fil_ext_bry, int fil_idx) {
|
||||
Bry_bfr tmp_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
byte[] tmp_bry = tmp_bfr.Bfr(); bry_len.Val_zero_();
|
||||
Io_url file = Xotdb_fsys_mgr.Url_fil(hive_root, fil_idx, fil_ext_bry);
|
||||
tmp_bry = Io_mgr.Instance.LoadFilBry_reuse(file, tmp_bry, bry_len);
|
||||
xdat_rdr.Clear().Parse(tmp_bry, bry_len.Val(), file);
|
||||
tmp_bfr.Clear_and_rls();
|
||||
return xdat_rdr;
|
||||
}
|
||||
}
|
||||
198
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xob_hive_mgr.java
Normal file
198
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xob_hive_mgr.java
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.ios.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.specials.*; import gplx.xowa.specials.allPages.*;
|
||||
import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
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.Instance;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
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");
|
||||
}
|
||||
}
|
||||
114
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xow_hive_mgr_fxt.java
Normal file
114
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xow_hive_mgr_fxt.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
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.Instance.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.To_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.Null);
|
||||
}
|
||||
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.To_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.Instance.LoadFilStr(url);
|
||||
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(actl));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
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.Instance.SaveFilBfr(url, bfr);
|
||||
// Tfds.Write(url.Raw() + "\n" + Io_mgr.Instance.LoadFilStr(url));
|
||||
}
|
||||
}
|
||||
96
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_mgr.java
Normal file
96
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_hive_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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
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.Instance.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.Instance.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.Instance.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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
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.Instance.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.Instance.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);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
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.Instance.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];
|
||||
}
|
||||
76
400_xowa/src/gplx/xowa/wikis/tdbs/hives/Xowd_regy_mgr.java
Normal file
76
400_xowa/src/gplx/xowa/wikis/tdbs/hives/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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
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.Instance.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.Instance; 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 Err_.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.Instance.SaveFilBfr(fil, bfr);
|
||||
}
|
||||
public static final int Regy_null = -1;
|
||||
}
|
||||
@@ -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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
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.Instance.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.Instance.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.Instance.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;
|
||||
}
|
||||
}
|
||||
@@ -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.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
public 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 Instance = new Xowd_ttl_file_comparer_end(); Xowd_ttl_file_comparer_end() {}
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_fil.java
Normal file
61
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_fil.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.flds.*;
|
||||
public class Xof_meta_fil {
|
||||
private final Ordered_hash itms = Ordered_hash_.New_bry();
|
||||
public Xof_meta_fil(Xof_meta_mgr meta_mgr, byte[] md5) {this.meta_mgr = meta_mgr; this.md5 = md5;}
|
||||
public Xof_meta_mgr Owner_mgr() {return meta_mgr;} private final Xof_meta_mgr meta_mgr;
|
||||
public byte[] Md5() {return md5;} private final byte[] md5;
|
||||
public void Dirty_() {meta_mgr.Dirty_(this);}
|
||||
public Xof_meta_itm Get_or_new(byte[] ttl) {
|
||||
Xof_meta_itm rv = Get_or_null(ttl);
|
||||
if (rv == null) {
|
||||
rv = new Xof_meta_itm(this, ttl);
|
||||
itms.Add(ttl, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xof_meta_itm Get_or_null(byte[] ttl) {return (Xof_meta_itm)itms.Get_by(ttl);}
|
||||
public void Save(Gfo_fld_wtr wtr) {
|
||||
int itms_len = itms.Count();
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
Xof_meta_itm itm = (Xof_meta_itm)itms.Get_at(i);
|
||||
itm.Save(wtr);
|
||||
}
|
||||
}
|
||||
public Xof_meta_fil Load(Gfo_fld_rdr rdr, Xof_meta_thumb_parser parser) {
|
||||
itms.Clear();
|
||||
int bry_len = rdr.Data().length;
|
||||
while (rdr.Pos() < bry_len) {
|
||||
Xof_meta_itm itm = new Xof_meta_itm(this, Bry_.Empty);
|
||||
itm.Load(rdr, parser);
|
||||
itms.Add(itm.Ttl(), itm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public static Io_url Bld_url(Io_url root, byte[] md5, int depth) {
|
||||
Bld_url_bfr.Add(root.RawBry());
|
||||
for (int i = 0; i < depth - 1; i++)
|
||||
Bld_url_bfr.Add_byte(md5[i]).Add_byte(root.Info().DirSpr_byte());
|
||||
for (int i = 0; i < depth; i++)
|
||||
Bld_url_bfr.Add_byte(md5[i]);
|
||||
Bld_url_bfr.Add(Bry_url_ext);
|
||||
return Io_url_.new_fil_(Bld_url_bfr.To_str_and_clear());
|
||||
} static final byte[] Bry_url_ext = Bry_.new_a7(".csv"); static Bry_bfr Bld_url_bfr = Bry_bfr.new_(260); // 260 is max path of url
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
public class Xof_meta_fil_tst {
|
||||
Xof_meta_fil_fxt fxt = new Xof_meta_fil_fxt();
|
||||
@Before public void init() {fxt.Ini();}
|
||||
@Test public void Bld_url() {fxt.Bld_url("mem/root/", "abcdef", 3, "mem/root/a/b/abc.csv");}
|
||||
}
|
||||
class Xof_meta_fil_fxt {
|
||||
byte[] md5_(byte[] name) {return Xof_file_wkr_.Md5(name);}
|
||||
public void Ini() {}
|
||||
public void Bld_url(String root, String md5, int depth, String expd) {Tfds.Eq(expd, Xof_meta_fil.Bld_url(Io_url_.new_dir_(root), Bry_.new_a7(md5), depth).Raw());}
|
||||
}
|
||||
184
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_itm.java
Normal file
184
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_itm.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.flds.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.parsers.utils.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xof_meta_itm {
|
||||
public Xof_meta_itm(Xof_meta_fil owner_fil, byte[] ttl) {this.owner_fil = owner_fil; this.ttl = ttl;}
|
||||
public Xof_meta_fil Owner_fil() {return owner_fil;} private Xof_meta_fil owner_fil;
|
||||
public byte[] Ttl() {return ttl;} private byte[] ttl;
|
||||
public byte[] Ptr_ttl() {return ptr_ttl;} public Xof_meta_itm Ptr_ttl_(byte[] v) {this.ptr_ttl = v; return this;} private byte[] ptr_ttl = Xop_redirect_mgr.Redirect_null_bry;
|
||||
public boolean Ptr_ttl_exists() {return ptr_ttl != Xop_redirect_mgr.Redirect_null_bry;}
|
||||
public boolean State_new() {return state_new;} private boolean state_new = true;
|
||||
public int Vrtl_repo() {return vrtl_repo;} private int vrtl_repo = Repo_unknown;
|
||||
public void Vrtl_repo_(int v) {
|
||||
// if (vrtl_repo == Xof_meta_itm.Repo_unknown) { // NOTE: only update vrtl_repo when unknown; this assumes that orig and all thumbs sit in same repo (which they should)
|
||||
vrtl_repo = v;
|
||||
Dirty();
|
||||
// }
|
||||
}
|
||||
public Xof_repo_itm Repo_itm(Xowe_wiki wiki) {
|
||||
switch (vrtl_repo) {
|
||||
case Xof_meta_itm.Repo_missing : //return null; // DELETE: used to return null, but this caused Redownload_missing to fail; no reason why missing shouldn't return a default repo; DATE:2013-01-26
|
||||
case Xof_meta_itm.Repo_unknown :
|
||||
case Xof_meta_itm.Repo_same : return wiki.Appe().File_mgr().Repo_mgr().Get_by_primary(wiki.Domain_bry());
|
||||
default : return wiki.File_mgr().Repo_mgr().Repos_get_at(vrtl_repo).Trg();
|
||||
}
|
||||
}
|
||||
public int Orig_w() {return orig_w;} private int orig_w;
|
||||
public int Orig_h() {return orig_h;} private int orig_h;
|
||||
public byte Orig_exists() {return orig_exists;} private byte orig_exists = Exists_unknown;
|
||||
public void Orig_exists_(byte v) {if (this.orig_exists == v) return; this.orig_exists = v; Dirty();}
|
||||
public Xof_meta_thumb[] Thumbs() {return thumbs;} private Xof_meta_thumb[] thumbs = Xof_meta_thumb.Ary_empty;
|
||||
public boolean Thumbs_indicates_oga() {return Thumbs_get_by_w(0, 0, Xof_lnki_time.Null_as_int) != null;} // if 0,0 exists, then assume no thumbs; needed for oga/ogg
|
||||
public boolean Thumbs_del(int w) {
|
||||
int del_idx = -1;
|
||||
int thumbs_len = thumbs.length;
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
Xof_meta_thumb thumb = thumbs[i];
|
||||
if (thumb.Width() == w) {del_idx = i; break;}
|
||||
}
|
||||
if (del_idx == -1) return false;
|
||||
Xof_meta_thumb[] thumbs_new = new Xof_meta_thumb[thumbs_len - 1];
|
||||
int new_idx = 0;
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
Xof_meta_thumb thumb = thumbs[i];
|
||||
if (thumb.Width() == w) continue;
|
||||
thumbs_new[new_idx++] = thumbs[i];
|
||||
}
|
||||
thumbs = thumbs_new;
|
||||
return true;
|
||||
}
|
||||
public Xof_meta_thumb Thumbs_get_img(int w, int w_adj) {return Thumbs_get_by_w(w, w_adj, Xof_lnki_time.Null_as_int);}
|
||||
public Xof_meta_thumb Thumbs_get_vid(int s) {return Thumbs_get_by_w(Xop_lnki_tkn.Width_null, 0, s);}
|
||||
Xof_meta_thumb Thumbs_get_by_w(int w, int w_adj, int seek) {
|
||||
int thumbs_len = thumbs.length;
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
Xof_meta_thumb thumb = thumbs[i];
|
||||
int tmp_adj = w_adj;// thumb.Width() < 50 ? 0 : w_adj;
|
||||
if ( (Xof_lnki_time.Null_y(seek)
|
||||
&& Int_.Between(thumb.Width(), w - tmp_adj, w + tmp_adj))
|
||||
|| (w == Xop_lnki_tkn.Width_null
|
||||
&& (Xof_lnki_time.Null_y(seek) || Int_.In(seek, thumb.Seeks()))))
|
||||
return thumb;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_meta_thumb Thumbs_get_by_h(int h, int thumbs_len) {
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
Xof_meta_thumb thumb = thumbs[i];
|
||||
int tmp_adj = 1;//thumb.Height() < 50 ? 0 : 1;
|
||||
if (Int_.Between(thumb.Height(), h - tmp_adj, h + tmp_adj)) return thumb;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_meta_thumb Thumbs_get_largest(int thumbs_len) {
|
||||
if (thumbs_len == 0) return null;
|
||||
int rv_idx = -1, cur_largest = -1;
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
Xof_meta_thumb thumb = thumbs[i];
|
||||
if (thumb.Width() > cur_largest) {
|
||||
rv_idx = i;
|
||||
cur_largest = thumb.Width();
|
||||
}
|
||||
}
|
||||
return thumbs[rv_idx];
|
||||
}
|
||||
public void Update_all(byte[] ptr_ttl, int w, int h, byte orig_exists, Xof_meta_thumb[] thumbs) {
|
||||
this.ptr_ttl = ptr_ttl; orig_w = w; orig_h = h; this.orig_exists = orig_exists; this.thumbs = thumbs; Dirty();
|
||||
}
|
||||
public void Update_orig_size(int w, int h) {this.orig_w = w; this.orig_h = h; Dirty();}
|
||||
public Xof_meta_itm Update_thumb_oga_() {
|
||||
Update_thumb_add(0, 0).Exists_n_();
|
||||
return this;
|
||||
}
|
||||
public Xof_meta_thumb Update_thumb_add(int w, int h) { // WARNING: h may not match existing val; will be discarded; EX: 10,20 stored in file; 10,21 passed in; 21 effectively discarded
|
||||
Xof_meta_thumb thumb = Thumbs_get_img(w, 0);
|
||||
if (thumb == null) {
|
||||
int thumbs_len = thumbs.length;
|
||||
Xof_meta_thumb[] thumbs_new = new Xof_meta_thumb[thumbs_len + 1];
|
||||
for (int i = 0; i < thumbs_len; i++)
|
||||
thumbs_new[i] = thumbs[i];
|
||||
thumb = new Xof_meta_thumb().Width_(w).Height_(h).Exists_y_().State_new_();
|
||||
thumbs_new[thumbs_len] = thumb;
|
||||
thumbs = thumbs_new;
|
||||
Dirty();
|
||||
}
|
||||
return thumb;
|
||||
}
|
||||
private void Dirty() {if (owner_fil != null) owner_fil.Dirty_();}
|
||||
public void Save(Gfo_fld_wtr wtr) {
|
||||
wtr.Write_bry_escape_fld(ttl);
|
||||
byte vrtl_repo_byte = Byte_.Max_value_127;
|
||||
switch (vrtl_repo) {
|
||||
case Repo_unknown: vrtl_repo_byte = Byte_ascii.Ltr_z; break;
|
||||
case Repo_same: vrtl_repo_byte = Byte_ascii.Ltr_y; break;
|
||||
case Repo_missing: vrtl_repo_byte = Byte_ascii.Ltr_x; break;
|
||||
default: vrtl_repo_byte = (byte)(vrtl_repo + Byte_ascii.Num_0); break;
|
||||
}
|
||||
wtr.Write_byte_fld(vrtl_repo_byte);
|
||||
wtr.Write_bry_escape_fld(ptr_ttl);
|
||||
wtr.Bfr() .Add_int_fixed(orig_exists, 1) .Add_byte(Xof_meta_thumb_parser.Dlm_exists)
|
||||
.Add_int_variable(orig_w) .Add_byte(Xof_meta_thumb_parser.Dlm_width)
|
||||
.Add_int_variable(orig_h) .Add_byte_pipe();
|
||||
int thumbs_len = thumbs.length;
|
||||
Bry_bfr bfr = wtr.Bfr();
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Semic);
|
||||
Xof_meta_thumb thumb = thumbs[i];
|
||||
thumb.Save(bfr);
|
||||
}
|
||||
wtr.Write_dlm_row();
|
||||
state_new = false;
|
||||
}
|
||||
public void Load_orig_(int w, int h) {this.orig_w = w; this.orig_h = h;}
|
||||
public void Load(Gfo_fld_rdr rdr, Xof_meta_thumb_parser parser) {
|
||||
ttl = rdr.Read_bry_escape();
|
||||
byte vrtl_repo_byte = rdr.Read_byte();
|
||||
switch (vrtl_repo_byte) {
|
||||
case Byte_ascii.Ltr_z: vrtl_repo = Repo_unknown; break;
|
||||
case Byte_ascii.Ltr_y: vrtl_repo = Repo_same; break;
|
||||
case Byte_ascii.Ltr_x: vrtl_repo = Repo_missing; break;
|
||||
default: vrtl_repo = (byte)(vrtl_repo_byte - Byte_ascii.Num_0); break;
|
||||
}
|
||||
ptr_ttl = rdr.Read_bry_escape();
|
||||
rdr.Move_next_simple_fld();
|
||||
Xof_meta_thumb orig_itm = parser.Parse_one(rdr.Data(), rdr.Fld_bgn(), rdr.Fld_end());
|
||||
orig_exists = orig_itm.Exists();
|
||||
orig_w = orig_itm.Width();
|
||||
orig_h = orig_itm.Height();
|
||||
rdr.Move_next_simple_fld();
|
||||
parser.Parse_ary(rdr.Data(), rdr.Fld_bgn(), rdr.Fld_end());
|
||||
int thumbs_len = parser.Len();
|
||||
thumbs = new Xof_meta_thumb[thumbs_len];
|
||||
for (int i = 0; i < thumbs_len; i++)
|
||||
thumbs[i] = parser.Ary()[i];
|
||||
parser.Clear();
|
||||
state_new = false;
|
||||
}
|
||||
public static final byte Exists_n = 0, Exists_y = 1, Exists_unknown = 2;
|
||||
public static final byte Repo_unknown = (byte)127, Repo_same = (byte)126, Repo_missing = (byte)125;
|
||||
public static final byte
|
||||
Tid_main = 0
|
||||
, Tid_ptr = 1
|
||||
, Tid_vrtl = 2
|
||||
, Tid_null = Byte_.Max_value_127
|
||||
;
|
||||
public static final byte[] Ptr_ttl_null = Bry_.Empty;
|
||||
}
|
||||
118
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_mgr.java
Normal file
118
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_mgr.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.flds.*;
|
||||
public class Xof_meta_mgr implements GfoInvkAble {
|
||||
private Object[] root = new Object[16]; private final Ordered_hash dirty_fils = Ordered_hash_.New_bry();
|
||||
private final Gfo_fld_rdr rdr = Gfo_fld_rdr.xowa_(); private final Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser();
|
||||
public Xof_meta_mgr(Xowe_wiki wiki) {this.wiki = wiki; this.root_dir = wiki.Appe().Fsys_mgr().File_dir().GenSubDir_nest("#meta", wiki.Domain_str());}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Io_url Root_dir() {return root_dir;} Io_url root_dir;
|
||||
public int Depth() {return depth;} public Xof_meta_mgr Depth_(int v) {depth = v; return this;} private int depth = 3; // allows a full english wikipedia to have meta files of approximately 32 kb; otherwise would be 480 kb; most wikis will not get to this size, but worst case is wasting 16 kb in (16 * 16) files which is less than 4 mb
|
||||
public boolean Append_only() {return append_only;} public Xof_meta_mgr Append_only_(boolean v) {append_only = v; return this;} private boolean append_only;
|
||||
public Xof_meta_fil Get_fil_or_new(byte[] md5) {
|
||||
Xof_meta_fil rv = Get_fil_or_null(md5);
|
||||
if (rv == null) {
|
||||
if (!append_only)
|
||||
rv = Load(md5);
|
||||
if (rv == null) {
|
||||
rv = Bld_new(root, depth - 1, this, md5, 0);
|
||||
dirty_fils.Add(md5, rv);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xof_meta_itm Get_itm_or_new(byte[] ttl) {return Get_itm_or_new(ttl, gplx.xowa.files.Xof_file_wkr_.Md5(ttl));}
|
||||
public Xof_meta_itm Get_itm_or_new(byte[] ttl, byte[] md5) {
|
||||
Xof_meta_fil fil = this.Get_fil_or_new(md5);
|
||||
return fil.Get_or_new(ttl);
|
||||
}
|
||||
Xof_meta_fil Get_fil_or_null(byte[] md5) {return Get_fil_or_null_recur(root, depth - 1, md5, 0);}
|
||||
public void Dirty_(Xof_meta_fil fil) {
|
||||
byte[] md5 = fil.Md5();
|
||||
if (!dirty_fils.Has(md5)) dirty_fils.Add(md5, fil);
|
||||
}
|
||||
public void Clear() {root = new Object[16]; dirty_fils.Clear();}
|
||||
public void Save() {Save(false);}
|
||||
public void Save(boolean clear) {
|
||||
int dirty_len = dirty_fils.Count();
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
wtr.Bfr_(tmp_bfr);
|
||||
for (int i = 0; i < dirty_len; i++) {
|
||||
Xof_meta_fil fil = (Xof_meta_fil)dirty_fils.Get_at(i);
|
||||
Io_url fil_url = Xof_meta_fil.Bld_url(root_dir, fil.Md5(), depth);
|
||||
fil.Save(wtr);
|
||||
if (append_only)
|
||||
Io_mgr.Instance.AppendFilBfr(fil_url, tmp_bfr);
|
||||
else
|
||||
Io_mgr.Instance.SaveFilBfr(fil_url, tmp_bfr);
|
||||
}
|
||||
dirty_fils.Clear();
|
||||
if (clear) this.Clear();
|
||||
} Gfo_fld_wtr wtr = Gfo_fld_wtr.xowa_();
|
||||
Xof_meta_fil Load(byte[] md5) {
|
||||
Io_url fil_url = Xof_meta_fil.Bld_url(root_dir, md5, depth);
|
||||
byte[] bry = Io_mgr.Instance.LoadFilBry(fil_url); if (bry == Bry_.Empty) return null;
|
||||
rdr.Ini(bry, 0);
|
||||
Xof_meta_fil rv = Bld_new(root, depth - 1, this, md5, 0); // NOTE: need to register file before loading it; defect wherein 2 files with same hash prefix would skip one b/c Loaded file was not registered; EX.WS: en.wikiquote.org/The Hitchhiker's Guide to the Galaxy; NMMP_dolphin_with_locator.jpeg, da6f95736ed249f371f30bf5f1205fbd; Hoags_object.jpg, daed4a54e48e4266bd2f2763b7c4018c
|
||||
rv.Load(rdr, parser);
|
||||
return rv;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_regy_depth_)) depth = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_regy_depth_ = "depth_";
|
||||
static final String GRP_KEY = "xowa.file_regy.";
|
||||
private static Xof_meta_fil Get_fil_or_null_recur(Object[] ary, int depth_max, byte[] md5, int md5_idx) {
|
||||
int ary_idx = Int_.To_int_hex(md5[md5_idx]);
|
||||
if (ary_idx < 0 || ary_idx > 15) throw Err_.new_wo_type("md5_not_valid", "md5", String_.new_u8(md5), "idx", md5_idx);
|
||||
Object o = ary[ary_idx];
|
||||
if (o == null) return null;
|
||||
if (md5_idx == depth_max) { // leaf; return fil
|
||||
try {return (Xof_meta_fil)o;} catch (Exception exc) {throw Err_.new_cast(exc, Xof_meta_fil.class, o);}
|
||||
}
|
||||
Object[] nxt = null; try {nxt = (Object[])o;} catch(Exception exc) {throw Err_.new_cast(exc, Object[].class, o);}
|
||||
return Get_fil_or_null_recur(nxt, depth_max, md5, md5_idx + 1);
|
||||
}
|
||||
private static Xof_meta_fil Bld_new(Object[] ary, int depth_max, Xof_meta_mgr regy_mgr, byte[] md5, int md5_idx) {
|
||||
int ary_idx = Int_.To_int_hex(md5[md5_idx]);
|
||||
if (ary_idx < 0 || ary_idx > 15) throw Err_.new_wo_type("md5_not_valid", "md", String_.new_u8(md5), "idx", md5_idx);
|
||||
Object o = ary[ary_idx];
|
||||
if (md5_idx == depth_max) { // leaf; create itm
|
||||
Xof_meta_fil rv = null;
|
||||
if (o == null) {
|
||||
rv = new Xof_meta_fil(regy_mgr, md5);
|
||||
ary[ary_idx] = rv;
|
||||
}
|
||||
else
|
||||
rv = (Xof_meta_fil)o;
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
Object[] nxt = null;
|
||||
if (o == null) {
|
||||
nxt = new Object[16];
|
||||
ary[ary_idx] = nxt;
|
||||
}
|
||||
else
|
||||
nxt = (Object[])o;
|
||||
return Bld_new(nxt, depth_max, regy_mgr, md5, md5_idx + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.gfui.*; import gplx.xowa.files.*;
|
||||
public class Xof_meta_mgr_tst {
|
||||
Xof_file_regy_fxt fxt = new Xof_file_regy_fxt();
|
||||
@Before public void init() {fxt.Ini();}
|
||||
@Test public void Set_one() {
|
||||
fxt .Set("A.png", 440, 400, true, "440,400", "220,200")
|
||||
.tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv", "A.png|y||1?440,400|1?440,400;1?220,200");
|
||||
}
|
||||
@Test public void Set_many() {
|
||||
fxt .Set("A.png" , 440, 400, true, "440,400", "220,200")
|
||||
.Set("Cabbage.jpg" , 640, 456, false, "220,200", "200,180")
|
||||
.tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"
|
||||
, "A.png|y||1?440,400|1?440,400;1?220,200"
|
||||
, "Cabbage.jpg|y||2?640,456|1?220,200;1?200,180"
|
||||
);
|
||||
}
|
||||
@Test public void Load_and_add() {
|
||||
fxt.Save_fil("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"
|
||||
, "A.png|y||1?440,400|"
|
||||
, "Cabbage.jpg|y||2?640,456|1?440,220;1?220,200"
|
||||
)
|
||||
.Set("Wooden_hourglass_3.jpg", 967, 1959, false, "220,200")
|
||||
.tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"
|
||||
, "A.png|y||1?440,400|"
|
||||
, "Cabbage.jpg|y||2?640,456|1?440,220;1?220,200"
|
||||
, "Wooden_hourglass_3.jpg|y||2?967,1959|1?220,200"
|
||||
);
|
||||
}
|
||||
@Test public void Load_and_update() {
|
||||
fxt.Save_fil("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"
|
||||
, "A.png|y||0?440,400|"
|
||||
, "Cabbage.jpg|y||2?640,456|1?440,400;1?220,200"
|
||||
)
|
||||
.Set("A.png", 550, 500, false, "220,200")
|
||||
.tst_Save("mem/xowa/file/#meta/en.wikipedia.org/7/70.csv"
|
||||
, "A.png|y||2?550,500|1?220,200"
|
||||
, "Cabbage.jpg|y||2?640,456|1?440,400;1?220,200"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xof_file_regy_fxt {
|
||||
Xof_meta_mgr regy_mgr;
|
||||
byte[] md5_(byte[] name) {return Xof_file_wkr_.Md5(name);}
|
||||
public void Ini() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
regy_mgr = new Xof_meta_mgr(wiki);
|
||||
regy_mgr.Clear();
|
||||
regy_mgr.Depth_(2);
|
||||
}
|
||||
public Xof_file_regy_fxt Save_fil(String url, String... data) {Io_mgr.Instance.SaveFilStr(Io_url_.mem_fil_(url), String_.Concat_lines_nl(data)); return this;}
|
||||
public Xof_file_regy_fxt Set(String name_str, int w, int h, boolean orig_exists, String... thumbs) {
|
||||
byte[] name = Bry_.new_u8(name_str);
|
||||
byte[] md5 = md5_(name);
|
||||
Xof_meta_itm itm = regy_mgr.Get_itm_or_new(name, md5);
|
||||
itm.Vrtl_repo_(Xof_meta_itm.Repo_same); // all tests above assume this is main
|
||||
itm.Update_all(Bry_.Empty, w, h, orig_exists ? Xof_meta_itm.Exists_y : Xof_meta_itm.Exists_unknown, To_ary(thumbs));
|
||||
return this;
|
||||
}
|
||||
Xof_meta_thumb[] To_ary(String[] ary) {
|
||||
int len = ary.length;
|
||||
Xof_meta_thumb[] rv = new Xof_meta_thumb[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
int[] size = Int_ary_parser.Instance.Parse_ary(ary[i], Byte_ascii.Comma);
|
||||
rv[i] = new Xof_meta_thumb().Width_(size[0]).Height_(size[1]).Exists_y_();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xof_file_regy_fxt tst_Save(String url_str, String... expd_ary) {
|
||||
regy_mgr.Save();
|
||||
Tfds.Eq_ary_str(expd_ary, Io_mgr.Instance.LoadFilStr_args(Io_url_.new_fil_(url_str)).ExecAsStrAryLnx());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
51
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_thumb.java
Normal file
51
400_xowa/src/gplx/xowa/wikis/tdbs/metas/Xof_meta_thumb.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
public class Xof_meta_thumb {
|
||||
public Xof_meta_thumb() {}
|
||||
public Xof_meta_thumb(byte exists, int width, int height, int[] seeks) {this.exists = exists; this.width = width; this.height = height; this.seeks = seeks; if (seeks == null) seeks = Int_.Ary_empty;}
|
||||
public byte Exists() {return exists;} private byte exists = Xof_meta_itm.Exists_unknown; // default to y, b/c thumbs are usually added if they exist; handle n when it occurs; unknown should never happen;
|
||||
public boolean State_new() {return state_new;} public Xof_meta_thumb State_new_() {state_new = true; return this;} private boolean state_new;
|
||||
public Xof_meta_thumb Exists_(byte v) {exists = v; return this;}
|
||||
public Xof_meta_thumb Exists_y_() {exists = Xof_meta_itm.Exists_y; return this;}
|
||||
public Xof_meta_thumb Exists_n_() {exists = Xof_meta_itm.Exists_n; return this;}
|
||||
public int Width() {return width;} public Xof_meta_thumb Width_(int v) {width = v; return this;} private int width;
|
||||
public int Height() {return height;} public Xof_meta_thumb Height_(int v) {height = v; return this;} private int height;
|
||||
public int[] Seeks() {return seeks;} public Xof_meta_thumb Seeks_(int[] v) {seeks = v; return this;} private int[] seeks = Int_.Ary_empty;
|
||||
public Xof_meta_thumb Seeks_add(int v) {
|
||||
int seeks_len = seeks.length;
|
||||
seeks = (int[])Array_.Resize(seeks, seeks_len + 1);
|
||||
seeks[seeks_len] = v;
|
||||
return this;
|
||||
}
|
||||
public void Save(Bry_bfr bfr) {
|
||||
bfr .Add_int_fixed(exists, 1) .Add_byte(Xof_meta_thumb_parser.Dlm_exists)
|
||||
.Add_int_variable(width) .Add_byte(Xof_meta_thumb_parser.Dlm_width)
|
||||
.Add_int_variable(height);
|
||||
if (seeks != Int_.Ary_empty) {
|
||||
bfr.Add_byte(Xof_meta_thumb_parser.Dlm_seek);
|
||||
int seeks_len = seeks.length;
|
||||
for (int i = 0; i < seeks_len; i++) {
|
||||
if (i != 0) bfr.Add_byte(Xof_meta_thumb_parser.Dlm_width);
|
||||
bfr.Add_int_variable(seeks[i]);
|
||||
}
|
||||
}
|
||||
state_new = false;
|
||||
}
|
||||
public static final Xof_meta_thumb[] Ary_empty = new Xof_meta_thumb[0];
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xof_meta_thumb_parser extends Obj_ary_parser_base {
|
||||
Number_parser num_parser = new Number_parser();
|
||||
Int_ary_parser int_ary_parser = new Int_ary_parser();
|
||||
public Xof_meta_thumb[] Ary() {return ary;} private Xof_meta_thumb[] ary = new Xof_meta_thumb[Ary_max]; static final int Ary_max = 16;
|
||||
public int Len() {return ary_idx;} private int ary_idx;
|
||||
public void Parse_ary(byte[] bry, int bgn, int end) {super.Parse_core(bry, bgn, end, Byte_ascii.Semic, Byte_ascii.Null);}
|
||||
public Xof_meta_thumb Parse_one(byte[] bry, int bgn, int end) {
|
||||
super.Parse_core(bry, bgn, end, Byte_ascii.Semic, Byte_ascii.Null);
|
||||
return ary[0];
|
||||
}
|
||||
public void Clear() {if (ary.length > Ary_max) ary = new Xof_meta_thumb[Ary_max];}
|
||||
@Override protected void Ary_len_(int v) {
|
||||
ary_idx = 0;
|
||||
if (v > Ary_max) ary = new Xof_meta_thumb[v];
|
||||
}
|
||||
@Override protected void Parse_itm(byte[] bry, int bgn, int end) { // EX: "1:45,40"; "1:45,40:3,4"
|
||||
Xof_meta_thumb itm = new Xof_meta_thumb(); boolean height_found = false;
|
||||
if (end - 2 < bgn) throw Err_.new_wo_type("itm must be at least 2 bytes long", "itm", String_.new_u8(bry, bgn, end)); // EX: 4,6
|
||||
int pos = bgn;
|
||||
byte exists_byte = bry[pos];
|
||||
switch (exists_byte) {
|
||||
case Byte_ascii.Num_0: itm.Exists_(Xof_meta_itm.Exists_n); break;
|
||||
case Byte_ascii.Num_1: itm.Exists_(Xof_meta_itm.Exists_y); break;
|
||||
case Byte_ascii.Num_2: itm.Exists_(Xof_meta_itm.Exists_unknown); break;
|
||||
default: throw Err_.new_wo_type("exists must be 0,1,2", "exists", exists_byte, "itm", String_.new_u8(bry, bgn, end));
|
||||
}
|
||||
if (bry[pos + 1] != Dlm_exists) throw Err_.new_wo_type("question must follow exists", "bad_char", bry[pos + 1], "itm", String_.new_u8(bry, bgn, end));
|
||||
pos += 2;
|
||||
int num_bgn = pos;
|
||||
while (pos < end) {
|
||||
byte b = bry[pos];
|
||||
switch (b) {
|
||||
case Dlm_width: // "," found; assume width; note that seek commas will be handled by seek
|
||||
itm.Width_(num_parser.Parse(bry, num_bgn, pos).Rv_as_int());
|
||||
num_bgn = pos + Int_.Const_dlm_len;
|
||||
break;
|
||||
case Dlm_seek:
|
||||
itm.Height_(num_parser.Parse(bry, num_bgn, pos).Rv_as_int());
|
||||
num_bgn = pos + Int_.Const_dlm_len;
|
||||
height_found = true;
|
||||
itm.Seeks_(int_ary_parser.Parse_ary(bry, num_bgn, end, Byte_ascii.Comma));
|
||||
pos = end;
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
if (!height_found) // handle '1:2,3' as opposed to '1:2,3@4'
|
||||
itm.Height_(num_parser.Parse(bry, num_bgn, end).Rv_as_int());
|
||||
ary[ary_idx++] = itm;
|
||||
}
|
||||
static final String GRP_KEY = "xowa.meta.itm.file";
|
||||
public static final byte Dlm_exists = Byte_ascii.Question, Dlm_seek = Byte_ascii.At, Dlm_width = Byte_ascii.Comma;
|
||||
public static final String Dlm_seek_str = "@";
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.wikis.tdbs.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
public class Xof_meta_thumb_parser_tst {
|
||||
Xof_meta_thumb_parser parser = new Xof_meta_thumb_parser();
|
||||
@Test public void Exists_y() {Tst_parse("1?45,40", itm_y_(45, 40));}
|
||||
@Test public void Exists_n() {Tst_parse("0?45,40", itm_n_(45, 40));}
|
||||
@Test public void Many() {Tst_parse("1?45,40;0?90,80", itm_y_(45, 40), itm_n_(90, 80));}
|
||||
@Test public void Seek() {Tst_parse("1?45,40@2,3,4", itm_y_(45, 40, 2, 3, 4));}
|
||||
private void Tst_parse(String raw_str, Xof_meta_thumb... expd) {
|
||||
byte[] raw = Bry_.new_a7(raw_str);
|
||||
parser.Parse_ary(raw, 0, raw.length);
|
||||
Tfds.Eq_str_lines(Xto_str(expd, 0, expd.length), Xto_str(parser.Ary(), 0, parser.Len()));
|
||||
}
|
||||
String Xto_str(Xof_meta_thumb[] ary, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xof_meta_thumb itm = ary[i];
|
||||
sb .Add(itm.Exists()).Add(":")
|
||||
.Add(itm.Width()).Add(",")
|
||||
.Add(itm.Height());
|
||||
int seeks_len = itm.Seeks().length;
|
||||
for (int j = 0; j < seeks_len; j++) {
|
||||
int seek = itm.Seeks()[j];
|
||||
sb.Add(i == 0 ? "@" : ",");
|
||||
sb.Add(seek);
|
||||
}
|
||||
sb.Add_char_nl();
|
||||
}
|
||||
return sb.To_str_and_clear();
|
||||
} String_bldr sb = String_bldr_.new_();
|
||||
// Xof_meta_img_chkr img_(int w, int h, params int[] seeks) {return new Xof_meta_img_chkr().Width_(w).Height_(h).Seeks_(seeks);}
|
||||
Xof_meta_thumb itm_y_(int w, int h, int... seeks) {return new Xof_meta_thumb(Xof_meta_itm.Exists_y, w, h, seeks);}
|
||||
Xof_meta_thumb itm_n_(int w, int h, int... seeks) {return new Xof_meta_thumb(Xof_meta_itm.Exists_n, w, h, seeks);}
|
||||
}
|
||||
43
400_xowa/src/gplx/xowa/wikis/tdbs/stats/Xob_stat_itm.java
Normal file
43
400_xowa/src/gplx/xowa/wikis/tdbs/stats/Xob_stat_itm.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.wikis.tdbs.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.strings.*;
|
||||
public class Xob_stat_itm implements NewAble {
|
||||
public String Ns() {return ns;} private String ns;
|
||||
public int Fils;
|
||||
public long Size, SizeMax = Int_.Min_value, SizeMin = Int_.Max_value;
|
||||
public int SizeMaxIdx, SizeMinIdx;
|
||||
public void Tally(long size, int idx) {
|
||||
Fils++;
|
||||
Size += size;
|
||||
if (size > SizeMax) {SizeMax = size; SizeMaxIdx = idx;}
|
||||
if (size < SizeMin) {SizeMin = size; SizeMinIdx = idx;}
|
||||
}
|
||||
public void To_str(String_bldr sb) {
|
||||
XtoStr_fld(sb, ns).XtoStr_fld(sb, Fils).XtoStr_fld(sb, Size).XtoStr_fld(sb, SizeMax).XtoStr_fld(sb, SizeMaxIdx).XtoStr_fld(sb, SizeMin);
|
||||
sb.Add(Int_.To_str(SizeMinIdx));
|
||||
}
|
||||
Xob_stat_itm XtoStr_fld(String_bldr sb, long v) {sb.Add(Long_.To_str(v)).Add(Xob_stat_itm.Dlm); return this;}
|
||||
Xob_stat_itm XtoStr_fld(String_bldr sb, int v) {sb.Add(Int_.To_str(v)).Add(Xob_stat_itm.Dlm); return this;}
|
||||
Xob_stat_itm XtoStr_fld(String_bldr sb, String v) {sb.Add(v).Add(Xob_stat_itm.Dlm); return this;}
|
||||
public Xob_stat_itm(String ns) {
|
||||
this.ns = ns;
|
||||
}
|
||||
public Object NewByKey(Object o) {return new Xob_stat_itm((String)o);} public static final Xob_stat_itm Instance = new Xob_stat_itm(); Xob_stat_itm() {}
|
||||
public static final char Dlm = '|';
|
||||
}
|
||||
69
400_xowa/src/gplx/xowa/wikis/tdbs/stats/Xob_stat_mgr.java
Normal file
69
400_xowa/src/gplx/xowa/wikis/tdbs/stats/Xob_stat_mgr.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.wikis.tdbs.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xob_stat_mgr {
|
||||
public Xob_stat_type GetOrNew(byte tid) {
|
||||
Xob_stat_type rv = (Xob_stat_type)regy.Get_by(tid);
|
||||
if (rv == null) {
|
||||
rv = new Xob_stat_type(tid);
|
||||
regy.Add(tid, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public String Print(Xow_ns_mgr nsMgr) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < regy.Count(); i++) {
|
||||
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
|
||||
sb.Add(String_.PadEnd(Xotdb_dir_info_.Tid_name(typ.Tid()), 6, " "));
|
||||
}
|
||||
sb.Add_str_w_crlf("ns");
|
||||
String[] nsAry = GetNmsAry(nsMgr);
|
||||
for (String ns : nsAry) {
|
||||
for (int i = 0; i < regy.Count(); i++) {
|
||||
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
|
||||
Xob_stat_itm itm = (Xob_stat_itm)typ.GetOrNew(ns);
|
||||
sb.Add(Int_.To_str_pad_bgn_zero(itm.Fils, 5)).Add(" ");
|
||||
}
|
||||
sb.Add_str_w_crlf(ns);
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
public String To_str() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = 0; i < regy.Count(); i++) {
|
||||
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
|
||||
typ.To_str(sb);
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
String[] GetNmsAry(Xow_ns_mgr nsMgr) {
|
||||
Ordered_hash nsRegy = Ordered_hash_.New();
|
||||
for (int i = 0; i < regy.Count(); i++) {
|
||||
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
|
||||
for (int j = 0; j < typ.Count(); j++) {
|
||||
Xob_stat_itm itm = (Xob_stat_itm)typ.GetAt(j);
|
||||
if (!nsRegy.Has(itm.Ns()))
|
||||
nsRegy.Add_as_key_and_val(itm.Ns());
|
||||
}
|
||||
}
|
||||
return (String[])nsRegy.To_ary(String.class);
|
||||
}
|
||||
Ordered_hash regy = Ordered_hash_.New();
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/wikis/tdbs/stats/Xob_stat_type.java
Normal file
36
400_xowa/src/gplx/xowa/wikis/tdbs/stats/Xob_stat_type.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.wikis.tdbs.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.core.strings.*; import gplx.xowa.wikis.tdbs.*;
|
||||
public class Xob_stat_type {
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public Xob_stat_type(byte tid) {this.tid = tid;}
|
||||
public Xob_stat_itm GetOrNew(String ns) {return (Xob_stat_itm)regy.Get_by_or_new(ns, Xob_stat_itm.Instance);}
|
||||
public Xob_stat_itm GetAt(int i) {return (Xob_stat_itm)regy.Get_at(i);}
|
||||
public int Count() {return regy.Count();}
|
||||
public void To_str(String_bldr sb) {
|
||||
for (int i = 0; i < regy.Count(); i++) {
|
||||
Xob_stat_itm itm = (Xob_stat_itm)regy.Get_at(i);
|
||||
sb.Add(Xotdb_dir_info_.Tid_name(tid)).Add(Xob_stat_itm.Dlm);
|
||||
itm.To_str(sb);
|
||||
sb.Add(Byte_ascii.Nl);
|
||||
}
|
||||
}
|
||||
Ordered_hash regy = Ordered_hash_.New();
|
||||
public static final Xob_stat_type Instance = new Xob_stat_type(); Xob_stat_type() {}
|
||||
}
|
||||
48
400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen.java
Normal file
48
400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.wikis.tdbs.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.ios.*;
|
||||
public class Xos_url_gen implements Io_url_gen {
|
||||
public Xos_url_gen(Io_url root) {this.root = root;} Io_url root; int idx = 0;
|
||||
public byte[] Ext() {return ext;} public Xos_url_gen Ext_(byte[] v) {ext = v; return this;} private byte[] ext = Bry_.new_a7(".csv");
|
||||
public Io_url Cur_url() {return cur_url;} Io_url cur_url;
|
||||
public Io_url Nxt_url() {cur_url = bld_fil_(root, idx++, ext); return cur_url;}
|
||||
public Io_url[] Prv_urls() {
|
||||
int len = idx + 1;
|
||||
Io_url[] rv = new Io_url[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = bld_fil_(root, i, ext);
|
||||
return rv;
|
||||
}
|
||||
public void Del_all() {}
|
||||
public static Io_url bld_fil_(Io_url root, int idx, byte[] ext) {
|
||||
byte dir_spr = root.Info().DirSpr_byte();
|
||||
tmp_bfr.Add(root.RawBry());
|
||||
int cur_mod = 100000000, cur_idx = idx;
|
||||
while (cur_mod > 99) {
|
||||
int val = cur_idx / cur_mod;
|
||||
tmp_bfr.Add_int_fixed(val, 2).Add_byte(dir_spr);
|
||||
cur_idx -= (val * cur_mod);
|
||||
cur_mod /= 100;
|
||||
}
|
||||
tmp_bfr.Add_int_fixed(idx, 10);
|
||||
tmp_bfr.Add(ext);
|
||||
return Io_url_.new_fil_(tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
private static Bry_bfr tmp_bfr = Bry_bfr.reset_(256);
|
||||
}
|
||||
32
400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen_tst.java
Normal file
32
400_xowa/src/gplx/xowa/wikis/tdbs/utils/Xos_url_gen_tst.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.wikis.tdbs.utils; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*;
|
||||
import gplx.ios.*;
|
||||
public class Xos_url_gen_tst {
|
||||
@Test public void Url_gen() {
|
||||
tst_url_gen("mem/root/", 0, "mem/root/00/00/00/00/0000000000.csv");
|
||||
tst_url_gen("mem/root/", 99, "mem/root/00/00/00/00/0000000099.csv");
|
||||
tst_url_gen("mem/root/", 1234567890, "mem/root/12/34/56/78/1234567890.csv");
|
||||
}
|
||||
private void tst_url_gen(String root_str, int idx, String expd) {
|
||||
Io_url root = Io_url_.mem_fil_(root_str);
|
||||
Io_url actl_url = Xos_url_gen.bld_fil_(root, idx, Bry_.new_a7(".csv"));
|
||||
Tfds.Eq(expd, actl_url.Xto_api());
|
||||
}
|
||||
}
|
||||
272
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file.java
Normal file
272
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file.java
Normal file
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
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.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.ios.*;
|
||||
public class Xob_xdat_file {
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_len() {return src_len;} public Xob_xdat_file Src_len_(int v) {src_len = v; return this;} private int src_len; // NOTE: src_len can be different than src.length (occurs when reusing brys)
|
||||
public Xob_xdat_file Update(Bry_bfr bfr, Xob_xdat_itm itm, byte[] v) {
|
||||
int ary_len = itm_ends.length;
|
||||
int itm_idx = itm.Itm_idx();
|
||||
int prv = itm_idx == 0 ? 0 : itm_ends[itm_idx - 1];
|
||||
int old_end = itm_ends[itm_idx];
|
||||
int new_end = prv + v.length;
|
||||
int dif = new_end - old_end;
|
||||
itm_ends[itm_idx] = new_end;
|
||||
for (int i = itm_idx + 1; i < ary_len; i++) {
|
||||
itm_ends[i] += dif;
|
||||
}
|
||||
Src_rebuild_hdr(bfr, ary_len);
|
||||
bfr.Add_mid(src, itm_0_bgn, itm.Itm_bgn());
|
||||
bfr.Add(v);
|
||||
bfr.Add_mid(src, itm.Itm_end() + 1, src.length); // NOTE: + 1 to skip nl
|
||||
src = bfr.To_bry_and_clear();
|
||||
return this;
|
||||
}
|
||||
byte[][] Src_extract_brys(int ary_len) {
|
||||
byte[][] rv = new byte[ary_len][];
|
||||
int itm_bgn = this.itm_0_bgn;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
int itm_end = itm_ends[i] + itm_0_bgn;
|
||||
rv[i] = Bry_.Mid(src, itm_bgn, itm_end);
|
||||
itm_bgn = itm_end;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Sort(Bry_bfr bfr, gplx.lists.ComparerAble comparer) {
|
||||
int ary_len = itm_ends.length;
|
||||
byte[][] brys = Src_extract_brys(ary_len);
|
||||
Array_.Sort(brys, comparer);
|
||||
Src_rebuild_hdr(bfr, ary_len);
|
||||
itm_0_bgn = (ary_len * Len_idx_itm) + Len_itm_dlm;
|
||||
int itm_bgn = 0;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
byte[] bry = brys[i];
|
||||
int bry_len = bry.length;
|
||||
int itm_end = itm_bgn + bry_len;
|
||||
itm_ends[i] = itm_end;
|
||||
itm_bgn = itm_end;
|
||||
bfr.Add(bry);
|
||||
}
|
||||
src = bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Insert(Bry_bfr bfr, byte[] itm) {
|
||||
int ary_len = itm_ends.length;
|
||||
itm_ends = (int[])Array_.Resize(itm_ends, ary_len + 1);
|
||||
int prv_pos = ary_len == 0 ? 0 : itm_ends[ary_len - 1];
|
||||
itm_ends[ary_len] = prv_pos + itm.length;
|
||||
Src_rebuild(bfr, ary_len + 1, itm);
|
||||
}
|
||||
private void Src_rebuild_hdr(Bry_bfr bfr, int ary_len) {
|
||||
int bgn = 0;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
int end = itm_ends[i];
|
||||
int len = end - bgn;
|
||||
bfr.Add_base85_len_5(len).Add_byte(Dlm_hdr_fld);
|
||||
bgn = end;
|
||||
}
|
||||
bfr.Add_byte(Dlm_row);
|
||||
}
|
||||
private void Src_rebuild(Bry_bfr bfr, int ary_len, byte[] new_itm) {
|
||||
Src_rebuild_hdr(bfr, ary_len);
|
||||
Src_rebuild_brys(bfr, ary_len, new_itm);
|
||||
}
|
||||
private void Src_rebuild_brys(Bry_bfr bfr, int ary_len, byte[] new_itm) {
|
||||
int bgn = itm_0_bgn;
|
||||
boolean insert = new_itm != null;
|
||||
int ary_end = insert ? ary_len - 1 : ary_len;
|
||||
for (int i = 0; i < ary_end; i++) {
|
||||
int end = itm_ends[i] + itm_0_bgn;
|
||||
bfr.Add_mid(src, bgn, end);
|
||||
bgn = end;
|
||||
}
|
||||
if (insert) bfr.Add(new_itm);
|
||||
itm_0_bgn = (ary_len * Len_idx_itm) + Len_itm_dlm;
|
||||
src = bfr.To_bry_and_clear();
|
||||
} static final byte Dlm_hdr_fld = Byte_ascii.Pipe, Dlm_row = Byte_ascii.Nl;
|
||||
public void Save(Io_url url) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Srl_save_bry(bfr);
|
||||
Io_stream_wtr wtr = Io_stream_wtr_.new_by_url_(url);
|
||||
try {
|
||||
wtr.Open();
|
||||
wtr.Write(bfr.Bfr(), 0, bfr.Len());
|
||||
wtr.Flush();
|
||||
}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to save file", "url", url.Xto_api());}
|
||||
finally {
|
||||
wtr.Rls();
|
||||
}
|
||||
}
|
||||
public void Srl_save_bry(Bry_bfr bfr) {
|
||||
int itm_ends_len = itm_ends.length;
|
||||
int prv_bgn = 0;
|
||||
for (int i = 0; i < itm_ends_len; i++) {
|
||||
int itm_end = itm_ends[i];
|
||||
bfr.Add_base85_len_5(itm_end - prv_bgn).Add_byte(Dlm_hdr_fld);
|
||||
prv_bgn = itm_end;
|
||||
}
|
||||
bfr.Add_byte(Dlm_row);
|
||||
bfr.Add_mid(src, itm_0_bgn, src.length);
|
||||
}
|
||||
public byte[] Get_bry(int i) {
|
||||
int bgn = i == 0 ? itm_0_bgn : itm_0_bgn + itm_ends[i - 1];
|
||||
int end = itm_0_bgn + itm_ends[i];
|
||||
return Bry_.Mid(src, bgn, end);
|
||||
}
|
||||
public int Count() {return itm_ends.length;}
|
||||
public Xob_xdat_file GetAt(Xob_xdat_itm itm, int idx) {
|
||||
itm.Src_(src);
|
||||
itm.Itm_idx_(idx);
|
||||
itm.Itm_bgn_(itm_0_bgn + (idx == 0 ? 0 : itm_ends[idx - 1]));
|
||||
itm.Itm_end_(itm_0_bgn + itm_ends[idx] - Len_itm_dlm);
|
||||
return this;
|
||||
}
|
||||
public Xob_xdat_file Find(Xob_xdat_itm itm, byte[] lkp, int lkp_bgn, byte lkp_dlm, boolean exact) {
|
||||
itm.Clear();
|
||||
int itm_idx = Xob_xdat_file_.BinarySearch(itm_0_bgn, src, itm_ends, lkp, lkp_bgn, lkp_dlm, 1, exact, itm); if (itm_idx == String_.Find_none) {return this;}
|
||||
GetAt(itm, itm_idx);
|
||||
return this;
|
||||
}
|
||||
public Xob_xdat_file Clear() {src = null; itm_ends = Int_.Ary_empty; return this;}
|
||||
private int[] itm_ends = Int_.Ary_empty; private int itm_0_bgn;
|
||||
public Xob_xdat_file Parse(byte[] src, int src_len, Io_url url) {// SEE:NOTE_1;xdat format
|
||||
if (src_len == 0) throw Err_.new_wo_type("file cannot be empty for parse", "url", url.Raw());
|
||||
int itm_count = 0, tmp_len = Parse_tmp_len; int[] tmp = Parse_tmp;
|
||||
try {
|
||||
int slot_bgn = 0, slot_old = 0, slot_new = 0;
|
||||
while (true) {
|
||||
slot_bgn = itm_count * Len_idx_itm;
|
||||
if (slot_bgn >= src_len) break;
|
||||
if (src[slot_bgn] == Byte_ascii.Nl) break;
|
||||
int tmp_val = Base85_utl.XtoIntByAry(src, slot_bgn, slot_bgn + Offset_base85);
|
||||
slot_new = slot_old + tmp_val;
|
||||
int new_idx = itm_count + 1;
|
||||
if (tmp_len < new_idx) {
|
||||
tmp_len = new_idx * 2;
|
||||
tmp = (int[])Array_.Resize(tmp, tmp_len);
|
||||
}
|
||||
tmp[itm_count] = slot_new;
|
||||
itm_count = new_idx;
|
||||
slot_old = slot_new;
|
||||
}
|
||||
int itm_ends_last = slot_new;
|
||||
itm_ends = new int[itm_count];
|
||||
for (int i = 0; i < itm_count; i++)
|
||||
itm_ends[i] = tmp[i];
|
||||
itm_0_bgn = slot_bgn + Len_itm_dlm;
|
||||
this.src = Bry_.Mid(src, 0, itm_ends_last + itm_0_bgn);
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse idx", "itm_count", itm_count, "url", url.Raw());}
|
||||
return this;
|
||||
} private static final int Parse_tmp_len = 8 * 1024; static int[] Parse_tmp = new int[Parse_tmp_len];
|
||||
static final int Len_itm_dlm = 1, Len_idx_itm = 6, Offset_base85 = 4; // 6 = 5 (base85_int) + 1 (new_line/pipe)
|
||||
static final String GRP_KEY = "xowa.xdat_fil";
|
||||
public static byte[] Rebuid_header(byte[] orig, byte[] dlm) {
|
||||
byte[][] rows = Bry_split_.Split(orig, dlm);
|
||||
int rows_len = rows.length;
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int dlm_len = dlm.length;
|
||||
for (int i = 1; i < rows_len; i++) { // i=1; skip 1st row (which is empty header)
|
||||
byte[] row = rows[i];
|
||||
int row_len = row.length + dlm_len;
|
||||
bfr.Add_base85_len_5(row_len).Add_byte(Byte_ascii.Pipe);
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Nl);
|
||||
for (int i = 1; i < rows_len; i++) { // i=1; skip 1st row (which is empty header)
|
||||
byte[] row = rows[i];
|
||||
bfr.Add(row);
|
||||
bfr.Add(dlm);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
class Xob_xdat_file_ {
|
||||
public static int BinarySearch(int itm_0_bgn, byte[] src, int[] itm_ends, byte[] lkp, int lkp_bgn, byte lkp_dlm, int itm_end_adj, boolean exact, Xob_xdat_itm xdat_itm) {if (lkp == null) throw Err_.new_null();
|
||||
int itm_ends_len = itm_ends.length; if (itm_ends_len == 0) throw Err_.new_wo_type("itm_ends_len cannot have 0 itms");
|
||||
int lo = -1, hi = itm_ends_len - 1; // NOTE: -1 is necessary; see test
|
||||
int itm_idx = (hi - lo) / 2;
|
||||
int lkp_len = lkp.length;
|
||||
int delta = 1;
|
||||
boolean flagged = false;
|
||||
while (true) {
|
||||
int itm_bgn = itm_0_bgn + (itm_idx == 0 ? 0 : itm_ends[itm_idx - 1]);
|
||||
int itm_end = itm_0_bgn + itm_ends[itm_idx] - itm_end_adj; // itm_end_adj to handle ttl .xdat and trailing \n
|
||||
int fld_bgn = itm_bgn + lkp_bgn, lkp_pos = -1;
|
||||
int comp = CompareAble_.Same;
|
||||
for (int i = fld_bgn; i < itm_end; i++) { // see if current itm matches lkp; NOTE: that i < itm_end but will end much earlier (since itm_end includes page text)
|
||||
byte b = src[i];
|
||||
if (b == lkp_dlm) { // fld is done
|
||||
if (lkp_pos != lkp_len - 1) comp = CompareAble_.More; // lkp has more chars than itm; lkp_dlm reached early
|
||||
break;
|
||||
}
|
||||
lkp_pos = i - fld_bgn;
|
||||
if (lkp_pos >= lkp_len) {
|
||||
comp = CompareAble_.Less; // lkp has less chars than itm
|
||||
break;
|
||||
}
|
||||
comp = (lkp[lkp_pos] & 0xff) - (b & 0xff); // subtract src[i] from lkp[lkp_pos] // PATCH.JAVA:need to convert to unsigned byte
|
||||
if (comp != CompareAble_.Same) break; // if comp != 0 then not equal; break; otherwise if bytes are the same, then comp == 0;
|
||||
}
|
||||
if (comp > CompareAble_.Same || (comp == CompareAble_.Same && itm_end - fld_bgn < lkp_len)) {lo = itm_idx; delta = 1;}
|
||||
else if (comp == CompareAble_.Same) {xdat_itm.Found_exact_y_(); return itm_idx;}
|
||||
else if (comp < CompareAble_.Same) {hi = itm_idx; delta = -1;}
|
||||
int itm_dif = hi - lo;
|
||||
// if (itm_end - 1 > fld_bgn) Tfds.Write(comp, itm_dif, String_.new_u8(src, fld_bgn, itm_end - 1));
|
||||
switch (itm_dif) {
|
||||
case 0: return exact ? String_.Find_none : hi; // NOTE: can be 0 when src.length == 1 || 2; also, sometimes 0 in some situations
|
||||
case -1:
|
||||
if (flagged) return exact ? String_.Find_none : lo;
|
||||
else {
|
||||
itm_idx--;
|
||||
flagged = true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (flagged) return exact ? String_.Find_none : hi;
|
||||
else {
|
||||
itm_idx++; // ++ to always take higher value when !exact???; EX: "ab,ad,af"
|
||||
if (itm_idx >= itm_ends_len) return String_.Find_none; // NOTE: occurs when there is only 1 item
|
||||
flagged = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
itm_idx += ((itm_dif / 2) * delta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
NOTE_1:xdat format
|
||||
line 0 : delimited String of article lengths; EX: "00012|00004|00005\n"
|
||||
line 1+: articles
|
||||
|
||||
pseudo example: (note that ints/dates will be replaced with base85 variants)
|
||||
== BOF ==
|
||||
00025|00024|00026
|
||||
2006-01-01 Ttl1 Abcd
|
||||
2006-02-01 Ttl2 Abc
|
||||
2006-03-01 Ttl3 Abcde
|
||||
== EOF ==
|
||||
|
||||
other notes:
|
||||
. itm_len is entire length of article including text, title, date and any other fields
|
||||
. line 0 uses len instead of bgn or end b/c len is independent (single len can be changed without having to recalculate entire array)
|
||||
. however, note that in memory, itm_end_ary will be stored; this will make article extraction quicker: getting nth article means getting nth item in array;
|
||||
. Parse is written for speed, not correctness; if correctness is needed, write a separate method that validates and call it before calling parse
|
||||
*/
|
||||
118
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_tst.java
Normal file
118
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_tst.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
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.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*; import gplx.core.strings.*; import gplx.xowa.wikis.tdbs.hives.*;
|
||||
public class Xob_xdat_file_tst {
|
||||
@Test public void Find() {
|
||||
Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "0|b", "1|d", "2|f", "3|h", "4|j");
|
||||
tst_ReadAt(rdr, 0, "0|b");
|
||||
tst_ReadAt(rdr, 1, "1|d");
|
||||
tst_ReadAt(rdr, 2, "2|f");
|
||||
tst_ReadAt(rdr, 3, "3|h");
|
||||
tst_ReadAt(rdr, 4, "4|j");
|
||||
tst_Find(rdr, "b", 0, false);
|
||||
tst_Find(rdr, "j", 4, false);
|
||||
tst_Find(rdr, "a", 0, false);
|
||||
tst_Find(rdr, "c", 1, false);
|
||||
tst_Find(rdr, "k", 4, false);
|
||||
}
|
||||
@Test public void Update() {
|
||||
Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "0|b", "1|d", "2|f", "3|h", "4|j");
|
||||
tst_Update(rdr, 3, "3|h1\n", String_.Concat_lines_nl_skip_last
|
||||
( "!!!!%|!!!!%|!!!!%|!!!!&|!!!!%|"
|
||||
, "0|b"
|
||||
, "1|d"
|
||||
, "2|f"
|
||||
, "3|h1"
|
||||
, "4|j"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Insert() {
|
||||
Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "0|b", "1|d", "2|f", "3|h", "4|j");
|
||||
tst_Insert(rdr, "5|k\n", String_.Concat_lines_nl_skip_last
|
||||
( "!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|"
|
||||
, "0|b"
|
||||
, "1|d"
|
||||
, "2|f"
|
||||
, "3|h"
|
||||
, "4|j"
|
||||
, "5|k"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Sort() {
|
||||
Xob_xdat_file rdr = rdr_("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|", "4|j", "2|f", "0|b", "1|d", "3|h");
|
||||
Bry_comparer_bgn_eos comparer = new Bry_comparer_bgn_eos(2);
|
||||
tst_Sort(rdr, comparer, String_.Concat_lines_nl_skip_last
|
||||
( "!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|"
|
||||
, "0|b"
|
||||
, "1|d"
|
||||
, "2|f"
|
||||
, "3|h"
|
||||
, "4|j"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Rebuild_header() {
|
||||
String orig = String_.Concat_lines_nl("" , "4|j", "2|f", "0|b", "1|d", "3|h");
|
||||
String expd = String_.Concat_lines_nl("!!!!%|!!!!%|!!!!%|!!!!%|!!!!%|" , "4|j", "2|f", "0|b", "1|d", "3|h");
|
||||
Rebuild_header_tst(orig, expd);
|
||||
}
|
||||
private void Rebuild_header_tst(String orig, String expd) {
|
||||
Tfds.Eq_str_lines(expd, String_.new_a7(Xob_xdat_file.Rebuid_header(Bry_.new_a7(orig), Bry_.new_a7("\n"))));
|
||||
}
|
||||
Bry_bfr tmp = Bry_bfr.new_();
|
||||
private void tst_Sort(Xob_xdat_file rdr, gplx.lists.ComparerAble comparer, String expd) {
|
||||
rdr.Sort(tmp, comparer);
|
||||
Chk_file(rdr, expd);
|
||||
}
|
||||
private void tst_Insert(Xob_xdat_file rdr, String new_val, String expd) {
|
||||
rdr.Insert(tmp, Bry_.new_u8(new_val));
|
||||
Chk_file(rdr, expd);
|
||||
}
|
||||
private void tst_Update(Xob_xdat_file rdr, int idx, String new_val, String expd) {
|
||||
Xob_xdat_itm itm = new Xob_xdat_itm();
|
||||
rdr.GetAt(itm, idx);
|
||||
rdr.Update(tmp, itm, Bry_.new_u8(new_val));
|
||||
Chk_file(rdr, expd);
|
||||
}
|
||||
private void Chk_file(Xob_xdat_file rdr, String expd) {
|
||||
Io_url url = Io_url_.new_fil_("mem/test.xdat");
|
||||
rdr.Save(url);
|
||||
String actl = Io_mgr.Instance.LoadFilStr(url);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
private void tst_Find(Xob_xdat_file rdr, String find, int expd, boolean exact) {
|
||||
rdr.Find(itm, Bry_.new_u8(find), 2, Byte_ascii.Nl, exact);
|
||||
int id = Bry_.To_int_or(Bry_.Mid(itm.Itm_bry(), 0, 1), -1);
|
||||
Tfds.Eq(expd, id);
|
||||
}
|
||||
private void tst_ReadAt(Xob_xdat_file rdr, int i, String expd) {rdr.GetAt(itm, i); Tfds.Eq(expd, String_.new_u8(itm.Itm_bry()));}
|
||||
Xob_xdat_itm itm = new Xob_xdat_itm();
|
||||
Xob_xdat_file rdr_(String... lines) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int len = lines.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String line = lines[i];
|
||||
sb.Add(line).Add_char_nl();
|
||||
}
|
||||
byte[] bry = Bry_.new_u8(sb.To_str());
|
||||
return new Xob_xdat_file().Parse(bry, bry.length, Io_url_.Empty);
|
||||
}
|
||||
}
|
||||
148
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_wtr.java
Normal file
148
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_file_wtr.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
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.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.ios.*; import gplx.xowa.wikis.tdbs.*;
|
||||
public class Xob_xdat_file_wtr {
|
||||
public static Xob_xdat_file_wtr new_file_(int fil_max, Io_url root_dir) {return new Xob_xdat_file_wtr(fil_max, root_dir, Io_stream_.Tid_raw);}
|
||||
public static Xob_xdat_file_wtr new_by_tid_(int fil_max, Io_url root_dir, byte dir_tid, byte tid) {return new Xob_xdat_file_wtr(fil_max, root_dir.GenSubDir(Xotdb_dir_info_.Tid_name(dir_tid) + Xotdb_dir_info.Wtr_dir(tid)), tid);}
|
||||
Xob_xdat_file_wtr(int fil_max, Io_url root_dir, byte wtr_tid) {
|
||||
this.fil_max = fil_max;
|
||||
this.root_dir = root_dir;
|
||||
fil_ext = Xotdb_dir_info.Wtr_ext(wtr_tid);
|
||||
bfr = Bry_bfr.new_(fil_max);
|
||||
idx = new int[fil_max / 8]; // ASSUME: any given row must at least be 8 bytes long
|
||||
Url_gen(fil_idx); // set 1st url
|
||||
wtr = Io_stream_wtr_.new_by_tid_(wtr_tid);
|
||||
} int fil_max; Io_stream_wtr wtr; byte[] fil_ext;
|
||||
public int Fil_idx() {return fil_idx;} public Xob_xdat_file_wtr Fil_idx_(int v) {fil_idx = v; return this;} private int fil_idx;
|
||||
public int Ns_ord_idx() {return ns_ord_idx;} public Xob_xdat_file_wtr Ns_ord_idx_(int v) {ns_ord_idx = v; return this;} private int ns_ord_idx; // NOTE: optional; needed for page cmd which will flush all wtrs, but needs ns_idx for stats
|
||||
public Io_url Fil_url() {return fil_url;}
|
||||
@gplx.Internal protected int[] Idx() {return idx;} private int[] idx;
|
||||
public int Idx_pos() {return idx_pos;} private int idx_pos;
|
||||
public Bry_bfr Bfr() {return bfr;} Bry_bfr bfr;
|
||||
public Xob_xdat_file_wtr Add_idx(byte data_dlm) {return Add_idx_direct(bfr.Len(), data_dlm);}
|
||||
public Xob_xdat_file_wtr Add_idx_direct(int itm_len, byte data_dlm) {
|
||||
if (data_dlm != Byte_ascii.Null) { // write closing dlm for data_eny, unless Byte_.Null passed in
|
||||
bfr.Add_byte(data_dlm);
|
||||
++itm_len;
|
||||
}
|
||||
if (idx_pos + 1 > idx.length) Idx_resize(idx.length * 2); // resize hdr if necessary
|
||||
idx[idx_pos++] = itm_len;
|
||||
return this;
|
||||
}
|
||||
public int Fil_len() {return ((idx_pos ) * Len_idx_itm) + bfr.Len();}
|
||||
public boolean FlushNeeded(int writeLen) {return ((idx_pos + 1) * Len_idx_itm) + bfr.Len() + writeLen > fil_max;} // +1: pending entry will create new idx_itm
|
||||
public void Flush(Gfo_usr_dlg usr_dlg) {
|
||||
if (bfr.Len() == 0) return; // nothing to flush
|
||||
if (this.Fil_len() > fil_max) // NOTE: data can exceed proscribed len; EX: wikt:Category for Italian nouns is 1 MB+
|
||||
usr_dlg.Log_many(GRP_KEY, "flush_err", "--ctg exceeds len: expd_len=~{0} actl_len=~{1} url=~{2}", this.Fil_len(), fil_max, fil_url.Xto_api());
|
||||
try {
|
||||
wtr.Url_(fil_url).Open();
|
||||
if (idx_pos > 0) // write idx; NOTE: if idx written, then .xdat; else .csv
|
||||
FlushIdx(wtr);
|
||||
wtr.Write(bfr.Bfr(), 0, bfr.Len()); // write data;
|
||||
wtr.Flush();
|
||||
}
|
||||
finally {wtr.Rls();}
|
||||
Clear();
|
||||
this.Url_gen(++fil_idx);
|
||||
}
|
||||
public void FlushIdx(Io_stream_wtr wtr) {
|
||||
int idx_bry_len = (idx_pos * Len_idx_itm) + 1; // 1=\n.length
|
||||
byte[] idx_bry = new byte[idx_bry_len];
|
||||
int prv_pos = 0; // NOTE: prv_pos needed b/c idx[] stores data_end, not data_len
|
||||
for (int i = 0; i < idx_pos; i++) {
|
||||
int idx_bry_pos = i * Len_idx_itm;
|
||||
int cur_pos = idx[i];
|
||||
Base85_utl.XtoStrByAry(cur_pos - prv_pos, idx_bry, idx_bry_pos, Len_base85);
|
||||
idx_bry[idx_bry_pos + Len_base85] = Dlm_fld;
|
||||
prv_pos = cur_pos;
|
||||
}
|
||||
idx_bry[idx_bry_len - 1] = Byte_ascii.Nl;
|
||||
wtr.Write(idx_bry, 0, idx_bry_len);
|
||||
}
|
||||
// public void Flush(Gfo_usr_dlg usr_dlg) {
|
||||
// if (bfr.Len() == 0) return; // nothing to flush
|
||||
// if (this.Fil_len() > fil_max) // NOTE: data can exceed proscribed len; EX: wikt:Category for Italian nouns is 1 MB+
|
||||
// usr_dlg.Log_many(GRP_KEY, "flush_err", "--ctg exceeds len: expd_len=~{0} actl_len=~{1} url=~{2}", this.Fil_len(), fil_max, fil_url.Xto_api());
|
||||
// IoStream stream = IoStream_.Null;
|
||||
// try {
|
||||
// stream = Io_mgr.Instance.OpenStreamWrite(fil_url);
|
||||
// if (idx_pos > 0) // write idx; NOTE: if idx written, then .xdat; else .csv
|
||||
// FlushIdx(stream);
|
||||
// stream.Write(bfr.Bry(), 0, bfr.Len()); // write data;
|
||||
// }
|
||||
// finally {stream.Rls();}
|
||||
// Clear();
|
||||
// this.Url_gen(++fil_idx);
|
||||
// }
|
||||
// public void FlushIdx(IoStream stream) {
|
||||
// int idx_bry_len = (idx_pos * Len_idx_itm) + 1; // 1=\n.length
|
||||
// byte[] idx_bry = new byte[idx_bry_len];
|
||||
// int prv_pos = 0; // NOTE: prv_pos needed b/c idx[] stores data_end, not data_len
|
||||
// for (int i = 0; i < idx_pos; i++) {
|
||||
// int idx_bry_pos = i * Len_idx_itm;
|
||||
// int cur_pos = idx[i];
|
||||
// Base85_utl.XtoStrByAry(cur_pos - prv_pos, idx_bry, idx_bry_pos, Len_base85);
|
||||
// idx_bry[idx_bry_pos + Len_base85] = Dlm_idx;
|
||||
// prv_pos = cur_pos;
|
||||
// }
|
||||
// idx_bry[idx_bry_len - 1] = Byte_ascii.Nl;
|
||||
// stream.Write(idx_bry, 0, idx_bry_len);
|
||||
// }
|
||||
static final int Len_idx_itm = 6, Len_base85 = 5;
|
||||
public void Clear() {idx_pos = 0; bfr.Clear();}
|
||||
public void Rls() {bfr.Rls(); idx = null;}
|
||||
public void Url_gen_add() {Url_gen(++fil_idx);}
|
||||
private void Url_gen(int newIdx) {fil_url = Xotdb_fsys_mgr.Url_fil(root_dir, newIdx, fil_ext);} Io_url fil_url; Io_url root_dir;
|
||||
private void Idx_resize(int newLen) {idx = (int[])Array_.Resize(idx, newLen);}
|
||||
static final String GRP_KEY = "xowa.bldr.xdat_wtr";
|
||||
private static final byte Dlm_fld = Byte_ascii.Pipe;
|
||||
}
|
||||
class SortAlgo_quick {// quicksort
|
||||
Object[] ary; int ary_len; gplx.lists.ComparerAble comparer;
|
||||
public void Sort(Object[] ary, int ary_len, gplx.lists.ComparerAble comparer) {
|
||||
if (ary == null || ary_len < 2) return;
|
||||
this.ary = ary; this.ary_len = ary_len; this.comparer = comparer;
|
||||
Sort_recurse(0, ary_len - 1);
|
||||
}
|
||||
private void Sort_recurse(int lo, int hi) {
|
||||
int i = lo, j = hi;
|
||||
int mid_idx = lo + (hi-lo)/2;
|
||||
Object mid = ary[mid_idx]; // get mid itm
|
||||
while (i <= j) { // divide into two lists
|
||||
while (comparer.compare(ary[i], mid) == CompareAble_.Less) // if lhs.cur < mid, then get next from lhs
|
||||
i++;
|
||||
while (comparer.compare(ary[j], mid) == CompareAble_.More) // if rhs.cur > mid, then get next from rhs
|
||||
j--;
|
||||
|
||||
// lhs.cur > mid && rhs.cur < mid; switch lhs.cur and rhs.cur; increase i and j
|
||||
if (i <= j) {
|
||||
Object tmp = ary[i];
|
||||
ary[i] = ary[j];
|
||||
ary[j] = tmp;
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (lo < j) Sort_recurse(lo, j);
|
||||
if (i < hi) Sort_recurse(i, hi);
|
||||
}
|
||||
public static final SortAlgo_quick Instance = new SortAlgo_quick(); SortAlgo_quick() {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import org.junit.*;
|
||||
public class Xob_xdat_file_wtr_tst {
|
||||
@Test public void Write() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Io_url dir = Io_url_.mem_dir_("mem/dir");
|
||||
Xob_xdat_file_wtr wtr = Xob_xdat_file_wtr.new_file_(1000, dir);
|
||||
tst_Write(wtr, "<1", "<1");
|
||||
tst_Write(wtr, ">a", "<1>a");
|
||||
tst_Write(wtr, ">b", "<1>a>b");
|
||||
tst_Add_idx(wtr, 7);
|
||||
wtr.Bfr().Add(Bry_.new_a7("<2>b>cc"));
|
||||
tst_Add_idx(wtr, 15);
|
||||
wtr.Bfr().Add(Bry_.new_a7("<3>c>dd"));
|
||||
tst_Add_idx(wtr, 23);
|
||||
tst_Flush(wtr, String_.Concat
|
||||
( "!!!!(|!!!!)|!!!!)|\n"
|
||||
, "<1>a>b\n"
|
||||
, "<2>b>cc\n"
|
||||
, "<3>c>dd\n"
|
||||
));
|
||||
}
|
||||
private void tst_Write(Xob_xdat_file_wtr wtr, String val, String expd) {
|
||||
wtr.Bfr().Add(Bry_.new_u8(val));
|
||||
Tfds.Eq(expd, String_.new_u8(wtr.Bfr().Bfr(), 0, wtr.Bfr().Len()));
|
||||
}
|
||||
private void tst_Add_idx(Xob_xdat_file_wtr wtr, int expd) {
|
||||
wtr.Add_idx(Byte_ascii.Nl);
|
||||
Tfds.Eq(expd, wtr.Idx()[wtr.Idx_pos() - 1]);
|
||||
}
|
||||
private void tst_Flush(Xob_xdat_file_wtr wtr, String expd) {
|
||||
Io_url url = wtr.Fil_url();
|
||||
wtr.Flush(Gfo_usr_dlg_.Test());
|
||||
String actl = Io_mgr.Instance.LoadFilStr(url);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_itm.java
Normal file
29
400_xowa/src/gplx/xowa/wikis/tdbs/xdats/Xob_xdat_itm.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.tdbs.xdats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
|
||||
public class Xob_xdat_itm {
|
||||
public byte[] Src() {return src;} public Xob_xdat_itm Src_(byte[] v) {src = v; return this;} private byte[] src;
|
||||
public int Itm_bgn() {return itm_bgn;} public Xob_xdat_itm Itm_bgn_(int v) {itm_bgn = v; return this;} private int itm_bgn = -1;
|
||||
public int Itm_end() {return itm_end;} public Xob_xdat_itm Itm_end_(int v) {itm_end = v; return this;} private int itm_end = -1;
|
||||
public int Itm_idx() {return itm_idx;} public Xob_xdat_itm Itm_idx_(int v) {itm_idx = v; return this;} private int itm_idx = -1;
|
||||
public void Clear() {itm_bgn = itm_end = itm_idx = -1; src = null; found_exact = false;}
|
||||
public boolean Found_exact() {return found_exact;} private boolean found_exact;
|
||||
public Xob_xdat_itm Found_exact_y_() {found_exact = true; return this;}
|
||||
public boolean Missing() {return itm_bgn == -1;}
|
||||
public byte[] Itm_bry() {return Bry_.Mid(src, itm_bgn, itm_end);}
|
||||
}
|
||||
Reference in New Issue
Block a user