mirror of https://github.com/gnosygnu/xowa
parent
35d78f6106
commit
e3b393650d
@ -1,84 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.lists; import gplx.*; import gplx.core.*;
|
||||
public class Binary_search_ {
|
||||
public static int Search(CompareAble[] ary, int ary_len, CompareAble val) {
|
||||
if (ary_len == 1) return 0;
|
||||
int interval = ary_len / 2;
|
||||
int pos = interval - List_adp_.Base1;
|
||||
int pos_last = ary_len - 1;
|
||||
int pos_prv = -1;
|
||||
int loop_count = 0;
|
||||
while (loop_count++ < 32) { // 32 bit integer
|
||||
CompareAble lo = ary[pos];
|
||||
CompareAble hi = pos + 1 == ary_len ? null : ary[pos + 1];
|
||||
int adj = 0;
|
||||
int lo_comp = val.compareTo(lo);
|
||||
if (lo_comp == CompareAble_.Less) // val is < lo; search slots below
|
||||
adj = -1;
|
||||
else {
|
||||
if (hi == null) return pos; // hi is null when at last slot in ary
|
||||
int hi_comp = val.compareTo(hi);
|
||||
if (hi_comp == CompareAble_.More) // val is > hi; search slots above
|
||||
adj = 1;
|
||||
else
|
||||
return pos; // val is > lo and < hi; return slot
|
||||
}
|
||||
interval /= 2;
|
||||
if (interval == 0) interval = 1; // do not allow 0 intervals; pos must always change;
|
||||
pos += (interval * adj);
|
||||
if (pos == 0 && pos_prv == 0) break; // NOTE: this will only happen when 1st member is not ""
|
||||
if (pos < 0) pos = 0;
|
||||
else if (pos > pos_last) pos = pos_last;
|
||||
pos_prv = pos;
|
||||
}
|
||||
return Int_.Min_value; // should only occur if (a) ary's 0th slot is not ""; or (b) some unknown error
|
||||
}
|
||||
public static int Search(List_adp__getable list, int list_len, CompareAble val) {
|
||||
if (list_len == 1) return 0;
|
||||
int interval = list_len / 2;
|
||||
int pos = interval - List_adp_.Base1;
|
||||
int pos_last = list_len - 1;
|
||||
int pos_prv = -1;
|
||||
int loop_count = 0;
|
||||
while (loop_count++ < 32) { // 32 bit integer
|
||||
CompareAble lo = (CompareAble)list.Get_at(pos);
|
||||
CompareAble hi = pos + 1 == list_len ? null : (CompareAble)list.Get_at(pos + 1);
|
||||
int adj = 0;
|
||||
int lo_comp = val.compareTo(lo);
|
||||
if (lo_comp == CompareAble_.Less) // val is < lo; search slots below
|
||||
adj = -1;
|
||||
else {
|
||||
if (hi == null) return pos; // hi is null when at last slot in ary
|
||||
int hi_comp = val.compareTo(hi);
|
||||
if (hi_comp == CompareAble_.More) // val is > hi; search slots above
|
||||
adj = 1;
|
||||
else
|
||||
return pos; // val is > lo and < hi; return slot
|
||||
}
|
||||
interval /= 2;
|
||||
if (interval == 0) interval = 1; // do not allow 0 intervals; pos must always change;
|
||||
pos += (interval * adj);
|
||||
if (pos == 0 && pos_prv == 0) break; // NOTE: this will only happen when 1st member is not ""
|
||||
if (pos < 0) pos = 0;
|
||||
else if (pos > pos_last) pos = pos_last;
|
||||
pos_prv = pos;
|
||||
}
|
||||
return Int_.Min_value; // should only occur if (a) ary's 0th slot is not ""; or (b) some unknown error
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
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.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
public class Binary_search_ {
|
||||
public static int Search(CompareAble[] ary , CompareAble val) {return Search(new Binary_search_grp__ary(ary) , new Binary_search_cmp__comparable(val));}
|
||||
public static int Search(Object[] ary , Binary_comparer comparer, Object val) {return Search(new Binary_search_grp__ary(ary), new Binary_search_cmp__comparer(comparer, val));}
|
||||
private static int Search(Binary_search_grp grp, Binary_search_cmp cmp) {
|
||||
int grp_len = grp.Len();
|
||||
if (grp_len == 1) return 0; // if 1 item, return 0;
|
||||
if (grp_len == 0) return Bry_find_.Not_found; // if 0 item, return -1
|
||||
|
||||
// init
|
||||
int interval = grp_len / 2;
|
||||
int pos = interval - List_adp_.Base1;
|
||||
int pos_last = grp_len - 1;
|
||||
int pos_prv = -1;
|
||||
int loop_count = 0;
|
||||
while (loop_count++ < 32) { // 32=32-bit integer
|
||||
Object lo = grp.Get_at(pos);
|
||||
Object hi = pos + 1 == grp_len ? null : grp.Get_at(pos + 1);
|
||||
int adj = 0;
|
||||
int lo_comp = cmp.Compare(lo);
|
||||
if (lo_comp == CompareAble_.Less) // val is < lo; search slots below
|
||||
adj = -1;
|
||||
else {
|
||||
if (hi == null) return pos; // hi is null when at last slot in ary
|
||||
int hi_comp = cmp.Compare(hi);
|
||||
switch (hi_comp) {
|
||||
case CompareAble_.More: // val is > hi; search slots above
|
||||
adj = 1;
|
||||
break;
|
||||
case CompareAble_.Same: // val is > hi; search slots above
|
||||
return pos + 1;
|
||||
case CompareAble_.Less: // val is > lo and < hi; return slot
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
interval /= 2;
|
||||
if (interval == 0) interval = 1; // do not allow 0 intervals; pos must always change;
|
||||
pos += (interval * adj);
|
||||
if (pos == 0 && pos_prv == 0) break; // NOTE: this will only happen when 1st member is not ""
|
||||
if (pos < 0) pos = 0;
|
||||
else if (pos > pos_last) pos = pos_last;
|
||||
pos_prv = pos;
|
||||
}
|
||||
return Bry_find_.Not_found; // should only occur if (a) ary's 0th slot is not ""; or (b) some unknown error
|
||||
}
|
||||
}
|
@ -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.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
import gplx.core.lists.*;
|
||||
interface Binary_search_cmp {
|
||||
int Compare(Object comp);
|
||||
}
|
||||
class Binary_search_cmp__comparable implements Binary_search_cmp {
|
||||
private final CompareAble val;
|
||||
public Binary_search_cmp__comparable(CompareAble val) {this.val = val;}
|
||||
public int Compare(Object comp) {
|
||||
return val.compareTo((CompareAble)comp);
|
||||
}
|
||||
}
|
||||
class Binary_search_cmp__comparer implements Binary_search_cmp {
|
||||
private final Binary_comparer comparer; private final Object val;
|
||||
public Binary_search_cmp__comparer(Binary_comparer comparer, Object val) {this.comparer = comparer; this.val = val;}
|
||||
public int Compare(Object comp) {
|
||||
return comparer.Compare_val_to_obj(val, comp);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.core.lists.binary_searches; import gplx.*; import gplx.core.*; import gplx.core.lists.*;
|
||||
interface Binary_search_grp {
|
||||
int Len();
|
||||
Object Get_at(int i);
|
||||
}
|
||||
class Binary_search_grp__ary implements Binary_search_grp {
|
||||
private final Object[] ary;
|
||||
public Binary_search_grp__ary(Object[] ary) {this.ary = ary;}
|
||||
public int Len() {return ary.length;}
|
||||
public Object Get_at(int i) {return ary[i];}
|
||||
}
|
||||
class Binary_search_grp__list implements Binary_search_grp {
|
||||
private final List_adp list;
|
||||
public Binary_search_grp__list(List_adp list) {this.list = list;}
|
||||
public int Len() {return list.Len();}
|
||||
public Object Get_at(int i) {return list.Get_at(i);}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.bldrs.updates.files.*;
|
||||
public class Xobc_cmd__fsdb_delete extends Xobc_cmd__base {
|
||||
private final Io_url deletion_db_url;
|
||||
public Xobc_cmd__fsdb_delete(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url deletion_db_url) {super(task_mgr, task_id, step_id, cmd_idx);
|
||||
this.deletion_db_url = deletion_db_url;
|
||||
}
|
||||
@Override public String Cmd_type() {return CMD_TYPE;} public static final String CMD_TYPE = "xowa.fsdb.delete";
|
||||
@Override public String Cmd_name() {return "deleting old files";}
|
||||
@Override public boolean Cmd_suspendable() {return true;}
|
||||
@Override protected void Cmd_exec_hook(Xobc_cmd_ctx ctx) {
|
||||
if (!Io_mgr.Instance.ExistsFil(deletion_db_url)) throw Err_.New("deletion db does not exist; file={0}", deletion_db_url.Raw());
|
||||
boolean pass = false;
|
||||
try {
|
||||
new Xodel_exec_mgr().Exec_delete(this, ctx.App().Bldr(), deletion_db_url);
|
||||
pass = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.Cmd_exec_err_(Err_.Message_gplx_log(e));
|
||||
}
|
||||
Gfo_log_.Instance.Info("xobc_cmd task delete", "task_id", this.Task_id(), "step_id", this.Step_id(), "delete_url", deletion_db_url.Raw(), "pass", pass);
|
||||
}
|
||||
@Override public void Cmd_cleanup() {
|
||||
if (Io_mgr.Instance.ExistsFil(deletion_db_url))
|
||||
new Xodel_exec_mgr().Exec_cleanup(deletion_db_url);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
|
||||
public class Pack_zip_name_bldr { // en.wikipedia.org-file-ns.000-db.001.xowa -> Xowa_enwiki_2016-05_file_ns.000_db.001.zip
|
||||
private final Io_url pack_dir;
|
||||
private final byte[] wiki_domain, zip_name_prefix;
|
||||
|
||||
public Pack_zip_name_bldr(Io_url pack_dir, String wiki_domain_str, String wiki_abrv, String wiki_date) {
|
||||
this.pack_dir = pack_dir;
|
||||
this.wiki_domain = Bry_.new_u8(wiki_domain_str);
|
||||
this.zip_name_prefix = Bry_.new_u8("Xowa_" + wiki_abrv + "_" + String_.Replace(wiki_date, ".", "-"));
|
||||
}
|
||||
public Io_url Bld(Io_url orig_url) {
|
||||
String orig_str = orig_url.NameOnly() + ".zip";
|
||||
byte[] orig_bry = Bry_.new_u8(orig_str);
|
||||
orig_bry = Bry_.Replace(orig_bry, Byte_ascii.Dash, Byte_ascii.Underline);
|
||||
orig_bry = Bry_.Replace(orig_bry, wiki_domain, zip_name_prefix);
|
||||
return pack_dir.GenSubFil(String_.new_u8(orig_bry));
|
||||
}
|
||||
public static Io_url To_wiki_url(Io_url wiki_dir, Io_url zip_dir) {
|
||||
// get wiki_url based on wiki_dir and xobc_zip_fil; EX: "/wiki/en.wikipedia.org/", "/wiki/tmp/Xowa_enwiki_2016-09_file_core_deletion_2016-09/" -> "/wiki/en.wikipedia.org-file-core-deletion-2016.09.zip"
|
||||
String name_str = zip_dir.NameOnly() + ".xowa";
|
||||
byte[] name_bry = Bry_.new_u8(name_str);
|
||||
int pos = Bry_find__Find_fwd_idx(name_bry, Byte_ascii.Underline, 2);
|
||||
name_bry = Bry_.Mid(name_bry, pos, name_bry.length);
|
||||
name_bry = Bry_.Add(Bry_.new_u8(wiki_dir.NameOnly()), name_bry);
|
||||
name_bry = Bry_.Replace(name_bry, Byte_ascii.Underline, Byte_ascii.Dash);
|
||||
return wiki_dir.GenSubFil(String_.new_u8(name_bry));
|
||||
}
|
||||
private static int Bry_find__Find_fwd_idx(byte[] src, byte val, int find_max) {
|
||||
int src_len = src.length;
|
||||
int find_cur = 0;
|
||||
int cur_pos = 0;
|
||||
while (true) {
|
||||
int new_pos = Bry_find_.Find_fwd(src, val, cur_pos, src_len);
|
||||
if (new_pos == -1) throw Err_.New("failed to find value; src={0} val={1}", src, val);
|
||||
if (find_cur++ == find_max) return new_pos;
|
||||
cur_pos = new_pos + 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Pack_zip_name_bldr__tst {
|
||||
private Pack_zip_name_bldr__fxt fxt = new Pack_zip_name_bldr__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test__to_wiki_url("mem/wiki/en.wikipedia.org/", "mem/wiki/en.wikipedia.org/tmp/Xowa_enwiki_2016-09_file_deletion_2016.09/", "mem/wiki/en.wikipedia.org/en.wikipedia.org-file-deletion-2016.09.xowa");
|
||||
}
|
||||
}
|
||||
class Pack_zip_name_bldr__fxt {
|
||||
public void Test__to_wiki_url(String wiki_dir, String zip_fil, String expd) {
|
||||
Gftest.Eq__str(expd, Pack_zip_name_bldr.To_wiki_url(Io_url_.mem_fil_(wiki_dir), Io_url_.mem_dir_(zip_fil)).Raw(), "wiki_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.addons.bldrs.mass_parses.parses.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*; import gplx.xowa.addons.bldrs.mass_parses.parses.*;
|
||||
import gplx.core.primitives.*; import gplx.core.lists.hashs.*;
|
||||
public class Xomp_ns_ord_mgr {
|
||||
private final Hash_adp__int hash = new Hash_adp__int();
|
||||
public Xomp_ns_ord_mgr(int[] ns_id_ary) {
|
||||
int len = ns_id_ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
hash.Add(ns_id_ary[i], new Int_obj_val(i));
|
||||
}
|
||||
}
|
||||
public int Get_ord_by_ns_id(int ns_id) {return ((Int_obj_val)hash.Get_by_or_fail(ns_id)).Val();}
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.addons.bldrs.files.cmds.*;
|
||||
public class Xobldr__deletion_db__exec extends Xob_cmd__base {
|
||||
private Io_url deletion_db_url;
|
||||
public Xobldr__deletion_db__exec(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, null);}
|
||||
@Override public void Cmd_run() {
|
||||
if (deletion_db_url == null) throw Err_.new_("bldr", "no file specified");
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get_or_noop(deletion_db_url);
|
||||
if (conn == Db_conn_.Noop) throw Err_.new_("bldr", "file does not exist", "file", deletion_db_url.Raw());
|
||||
|
||||
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.Get_or_null(conn);
|
||||
if (cfg_tbl == null) throw Err_.new_("bldr", "xowa_cfg tbl does not exist", "file", deletion_db_url.Raw());
|
||||
byte[] domain_bry = cfg_tbl.Select_bry_or("", Xobldr__deletion_db__make.Cfg__deletion_db__domain, null);
|
||||
if (domain_bry == null) throw Err_.new_("bldr", "no domain found in deletion db", "file", deletion_db_url.Raw());
|
||||
this.wiki = bldr.App().Wiki_mgr().Get_by_or_make(domain_bry);
|
||||
wiki.Init_assert();
|
||||
Delete_by_url(wiki, deletion_db_url);
|
||||
conn.Rls_conn();
|
||||
Io_mgr.Instance.DeleteFil(deletion_db_url);
|
||||
}
|
||||
private void Delete_by_url(Xowe_wiki wiki, Io_url delete_url) {
|
||||
Xof_fsdb_mgr fsdb_mgr = wiki.File_mgr().Fsdb_mgr();
|
||||
Fsm_mnt_itm mnt_itm = fsdb_mgr.Mnt_mgr().Mnts__get_main();
|
||||
Db_conn core_conn = mnt_itm.Atr_mgr().Db__core().Conn();
|
||||
Db_conn delete_conn = Db_conn_bldr.Instance.Get_or_new(delete_url).Conn();
|
||||
core_conn.Env_db_attach("delete_db", delete_conn);
|
||||
int dbs_len = mnt_itm.Bin_mgr().Dbs__len();
|
||||
String dbs_len_str = Int_.To_str(dbs_len - Int_.Base1);
|
||||
for (int i = 0; i < dbs_len; ++i) {
|
||||
Fsm_bin_fil bin_db = mnt_itm.Bin_mgr().Dbs__get_at(i);
|
||||
Delete_by_db(core_conn, bin_db, dbs_len_str);
|
||||
}
|
||||
core_conn.Env_db_detach("delete_db");
|
||||
}
|
||||
private void Delete_by_db(Db_conn conn, Fsm_bin_fil bin_db, String dbs_len_str) {
|
||||
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
|
||||
// get rows to delete in db
|
||||
List_adp list = List_adp_.New();
|
||||
int bin_db_id = bin_db.Id();
|
||||
String bin_db_id_str = Int_.To_str(bin_db_id);
|
||||
usr_dlg.Prog_many("", "", "processing files for deletion in database " + bin_db_id_str + " of " + dbs_len_str);
|
||||
Db_rdr rdr = conn.Exec_rdr(String_.Concat_lines_nl
|
||||
( "SELECT ff.fil_id AS item_id"
|
||||
, ", 1 AS item_is_orig"
|
||||
, "FROM fsdb_fil ff"
|
||||
, "JOIN delete_db.delete_regy dr ON ff.fil_id = dr.fil_id AND dr.thm_id = -1"
|
||||
, "WHERE ff.fil_bin_db_id = " + bin_db_id_str
|
||||
, "UNION"
|
||||
, "SELECT ft.thm_id AS item_id"
|
||||
, ", 0 AS item_is_orig"
|
||||
, "FROM fsdb_thm ft"
|
||||
, " JOIN delete_db.delete_regy dr ON ft.thm_owner_id = dr.fil_id AND ft.thm_id = dr.thm_id"
|
||||
, "WHERE ft.thm_bin_db_id = " + bin_db_id_str
|
||||
));
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int item_id = rdr.Read_int("item_id");
|
||||
int item_is_orig = rdr.Read_int("item_is_orig");
|
||||
list.Add(new Xob_img_prune_itm(item_id, item_is_orig == 1));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
|
||||
int len = list.Count();
|
||||
if (len == 0) return; // no files; exit, else will vacuum below
|
||||
|
||||
conn.Env_db_attach("bin_db", bin_db.Conn());
|
||||
conn.Txn_bgn("img_prune__" + bin_db_id_str);
|
||||
// delete bin
|
||||
Db_stmt delete_bin_stmt = conn.Stmt_sql("DELETE FROM bin_db.fsdb_bin WHERE bin_owner_id = ?");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xob_img_prune_itm itm = (Xob_img_prune_itm)list.Get_at(i);
|
||||
delete_bin_stmt.Clear().Crt_int("bin_owner_id", itm.Item_id);
|
||||
delete_bin_stmt.Exec_delete();
|
||||
|
||||
if (i % 10000 == 0) usr_dlg.Prog_many("", "", "deleting data in database " + bin_db_id_str + " of " + dbs_len_str);
|
||||
}
|
||||
delete_bin_stmt.Rls();
|
||||
|
||||
// delete meta
|
||||
Db_stmt delete_fil_stmt = conn.Stmt_sql("DELETE FROM fsdb_fil WHERE fil_id = ?");
|
||||
Db_stmt delete_thm_stmt = conn.Stmt_sql("DELETE FROM fsdb_thm WHERE thm_id = ?");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xob_img_prune_itm itm = (Xob_img_prune_itm)list.Get_at(i);
|
||||
if (itm.Item_is_orig) {
|
||||
delete_fil_stmt.Clear().Crt_int("fil_id", itm.Item_id);
|
||||
delete_fil_stmt.Exec_delete();
|
||||
}
|
||||
else {
|
||||
delete_thm_stmt.Clear().Crt_int("thm_id", itm.Item_id);
|
||||
delete_thm_stmt.Exec_delete();
|
||||
}
|
||||
if (i % 10000 == 0) usr_dlg.Prog_many("", "", "deleting meta in database " + bin_db_id_str + " of " + dbs_len_str);
|
||||
}
|
||||
delete_fil_stmt.Rls();
|
||||
delete_thm_stmt.Rls();
|
||||
|
||||
conn.Txn_end();
|
||||
conn.Env_db_detach("bin_db");
|
||||
bin_db.Conn().Env_vacuum();
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__file_)) this.deletion_db_url = Io_url_.new_any_(m.ReadStr("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk__file_ = "file_";
|
||||
|
||||
public static final String BLDR_CMD_KEY = "fsdb.deletion_db.exec";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xobldr__deletion_db__exec(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xobldr__deletion_db__exec(bldr, wiki);}
|
||||
}
|
||||
class Xob_img_prune_itm {
|
||||
public Xob_img_prune_itm(int item_id, boolean item_is_orig) {
|
||||
this.Item_id = item_id;
|
||||
this.Item_is_orig = item_is_orig;
|
||||
}
|
||||
public final int Item_id;
|
||||
public final boolean Item_is_orig;
|
||||
}
|
@ -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.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xodel_exec_cmd extends Xob_cmd__base {
|
||||
private Io_url deletion_db_url;
|
||||
public Xodel_exec_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
@Override public void Cmd_run() {
|
||||
new Xodel_exec_mgr().Exec_delete(gplx.core.progs.Gfo_prog_ui_.Noop, bldr, deletion_db_url);
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__file_)) this.deletion_db_url = Io_url_.new_any_(m.ReadStr("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk__file_ = "file_";
|
||||
|
||||
public static final String BLDR_CMD_KEY = "fsdb.deletion_db.exec";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xodel_exec_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xodel_exec_cmd(bldr, wiki);}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
|
||||
import gplx.core.progs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
import gplx.xowa.files.fsdb.*; import gplx.fsdb.meta.*;
|
||||
public class Xodel_exec_mgr {
|
||||
public void Exec_delete(Gfo_prog_ui prog_ui, Xob_bldr bldr, Io_url deletion_db_url) {
|
||||
// get domain bry from deletion_conn's cfg_tbl
|
||||
Db_conn deletion_conn = Db_conn_bldr.Instance.Get_or_fail(deletion_db_url);
|
||||
Db_cfg_tbl cfg_tbl = Xowd_cfg_tbl_.Get_or_fail(deletion_conn);
|
||||
byte[] domain_bry = cfg_tbl.Select_bry("", Xodel_exec_mgr.Cfg__deletion_db__domain);
|
||||
|
||||
// get wiki; init it; do delete
|
||||
Xowe_wiki wiki = bldr.App().Wiki_mgr().Get_by_or_make(domain_bry);
|
||||
wiki.Init_assert();
|
||||
Delete_by_url(prog_ui, wiki, deletion_conn, cfg_tbl);
|
||||
|
||||
// cleanup
|
||||
deletion_conn.Rls_conn();
|
||||
Io_mgr.Instance.DeleteFil(deletion_db_url);
|
||||
}
|
||||
public void Exec_cleanup(Io_url deletion_db_url) {
|
||||
Db_conn deletion_conn = Db_conn_bldr.Instance.Get_or_fail(deletion_db_url);
|
||||
Db_cfg_tbl cfg_tbl = Xowd_cfg_tbl_.Get_or_fail(deletion_conn);
|
||||
cfg_tbl.Delete_val("", Xodel_exec_mgr.Cfg__deletion_db__db_bgn);
|
||||
}
|
||||
private void Delete_by_url(Gfo_prog_ui prog_ui, Xowe_wiki wiki, Db_conn deletion_conn, Db_cfg_tbl cfg_tbl) {
|
||||
// get fsdb_mgr
|
||||
Xof_fsdb_mgr fsdb_mgr = wiki.File_mgr().Fsdb_mgr();
|
||||
Fsm_mnt_itm mnt_itm = fsdb_mgr.Mnt_mgr().Mnts__get_main();
|
||||
Db_conn core_conn = mnt_itm.Atr_mgr().Db__core().Conn();
|
||||
try {
|
||||
core_conn.Env_db_attach("delete_db", deletion_conn);
|
||||
|
||||
// loop dbs
|
||||
int dbs_len = mnt_itm.Bin_mgr().Dbs__len();
|
||||
String dbs_len_str = Int_.To_str(dbs_len - Int_.Base1);
|
||||
int db_bgn = cfg_tbl.Select_int_or("", Cfg__deletion_db__db_bgn, 0);
|
||||
for (int i = db_bgn; i < dbs_len; ++i) {
|
||||
if (prog_ui.Prog_notify_and_chk_if_suspended(i, dbs_len)) return;
|
||||
Fsm_bin_fil bin_db = mnt_itm.Bin_mgr().Dbs__get_at(i);
|
||||
Delete_by_db(core_conn, bin_db, dbs_len_str);
|
||||
cfg_tbl.Upsert_int("", Cfg__deletion_db__db_bgn, i + 1);
|
||||
}
|
||||
} finally {core_conn.Env_db_detach("delete_db");}
|
||||
}
|
||||
private void Delete_by_db(Db_conn deletion_conn, Fsm_bin_fil bin_db, String dbs_len_str) {
|
||||
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
|
||||
|
||||
// get rows to delete in db
|
||||
List_adp list = List_adp_.New();
|
||||
int bin_db_id = bin_db.Id();
|
||||
String bin_db_id_str = Int_.To_str(bin_db_id);
|
||||
usr_dlg.Prog_many("", "", "processing files for deletion in database " + bin_db_id_str + " of " + dbs_len_str);
|
||||
Db_rdr rdr = deletion_conn.Exec_rdr(String_.Concat_lines_nl
|
||||
( "SELECT ff.fil_id AS item_id"
|
||||
, ", 1 AS item_is_orig"
|
||||
, "FROM fsdb_fil ff"
|
||||
, "JOIN delete_db.delete_regy dr ON ff.fil_id = dr.fil_id AND dr.thm_id = -1"
|
||||
, "WHERE ff.fil_bin_db_id = " + bin_db_id_str
|
||||
, "UNION"
|
||||
, "SELECT ft.thm_id AS item_id"
|
||||
, ", 0 AS item_is_orig"
|
||||
, "FROM fsdb_thm ft"
|
||||
, " JOIN delete_db.delete_regy dr ON ft.thm_owner_id = dr.fil_id AND ft.thm_id = dr.thm_id"
|
||||
, "WHERE ft.thm_bin_db_id = " + bin_db_id_str
|
||||
));
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int item_id = rdr.Read_int("item_id");
|
||||
int item_is_orig = rdr.Read_int("item_is_orig");
|
||||
list.Add(new Xodel_prune_itm(item_id, item_is_orig == 1));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
|
||||
int len = list.Count();
|
||||
if (len == 0) return; // no files; exit, else will vacuum below
|
||||
|
||||
deletion_conn.Env_db_attach("bin_db", bin_db.Conn());
|
||||
deletion_conn.Txn_bgn("img_prune__" + bin_db_id_str);
|
||||
|
||||
// delete bin
|
||||
Db_stmt delete_bin_stmt = deletion_conn.Stmt_sql("DELETE FROM bin_db.fsdb_bin WHERE bin_owner_id = ?");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xodel_prune_itm itm = (Xodel_prune_itm)list.Get_at(i);
|
||||
delete_bin_stmt.Clear().Crt_int("bin_owner_id", itm.Item_id);
|
||||
delete_bin_stmt.Exec_delete();
|
||||
|
||||
if (i % 10000 == 0) usr_dlg.Prog_many("", "", "deleting data in database " + bin_db_id_str + " of " + dbs_len_str);
|
||||
}
|
||||
delete_bin_stmt.Rls();
|
||||
|
||||
// delete meta
|
||||
Db_stmt delete_fil_stmt = deletion_conn.Stmt_sql("DELETE FROM fsdb_fil WHERE fil_id = ?");
|
||||
Db_stmt delete_thm_stmt = deletion_conn.Stmt_sql("DELETE FROM fsdb_thm WHERE thm_id = ?");
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xodel_prune_itm itm = (Xodel_prune_itm)list.Get_at(i);
|
||||
if (itm.Item_is_orig) {
|
||||
delete_fil_stmt.Clear().Crt_int("fil_id", itm.Item_id);
|
||||
delete_fil_stmt.Exec_delete();
|
||||
}
|
||||
else {
|
||||
delete_thm_stmt.Clear().Crt_int("thm_id", itm.Item_id);
|
||||
delete_thm_stmt.Exec_delete();
|
||||
}
|
||||
if (i % 10000 == 0) usr_dlg.Prog_many("", "", "deleting meta in database " + bin_db_id_str + " of " + dbs_len_str);
|
||||
}
|
||||
delete_fil_stmt.Rls();
|
||||
delete_thm_stmt.Rls();
|
||||
|
||||
// cleanup
|
||||
deletion_conn.Txn_end();
|
||||
deletion_conn.Env_db_detach("bin_db");
|
||||
bin_db.Conn().Env_vacuum();
|
||||
}
|
||||
public static final String Cfg__deletion_db__domain = "file.deletion_db.domain", Cfg__deletion_db__db_bgn = "file.deletion_db.db_bgn";
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xodel_make_cmd extends Xob_cmd__base implements Xob_cmd {
|
||||
public Xodel_make_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
@Override public void Cmd_run() {
|
||||
wiki.Init_assert();
|
||||
new Xodel_make_mgr().Exec(wiki);
|
||||
}
|
||||
|
||||
public static final String BLDR_CMD_KEY = "file.deletion_db.make";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xodel_make_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xodel_make_cmd(bldr, wiki);}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
|
||||
class Xodel_prune_itm {
|
||||
public Xodel_prune_itm(int item_id, boolean item_is_orig) {
|
||||
this.Item_id = item_id;
|
||||
this.Item_is_orig = item_is_orig;
|
||||
}
|
||||
public final int Item_id;
|
||||
public final boolean Item_is_orig;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xodel_small_cmd extends Xob_cmd__base {
|
||||
public Xodel_small_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
|
||||
private final int[] ext_max_ary = Xobldr__fsdb_db__delete_small_files_.New_ext_max_ary();
|
||||
@Override public void Cmd_run() {
|
||||
wiki.Init_assert();
|
||||
new Xodel_small_mgr().Exec(wiki, ext_max_ary);
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
|
||||
|
||||
public static final String BLDR_CMD_KEY = "file.deletion_db.small_files";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xodel_small_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xodel_small_cmd(bldr, wiki);}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_mgr__navlink__tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
|
||||
@Test public void Navlink__basic() {
|
||||
fxt .Init_itms__pages("A1", "A2", "A3").Init_grp_max(1).Init_grp__pages(1, 2)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 1</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 1</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11
|
||||
fxt .Init_itms__pages("A\" 1", "A\" 2", "A\" 3").Init_grp_max(1).Init_grp__pages(1, 2)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 1</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 1</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__bos() {
|
||||
fxt .Init_itms__pages("A1", "A2", "A3").Init_grp_max(1).Init_grp__pages(0, 1)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(previous 1)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 1</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__eos() {
|
||||
fxt .Init_itms__pages("A1", "A2", "A3").Init_grp_max(2).Init_grp__pages(2, 3)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 2</a>)"
|
||||
, "(next 2)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__eos__2() { // PURPOSE.fix: do not suppress next page on penultimate page; DATE:2016-09-25
|
||||
fxt .Init_itms__pages("A1", "A2", "A3", "A4").Init_grp_max(2).Init_grp__pages(2, 3)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 2</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A4#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 2</a>)"
|
||||
));
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_url {
|
||||
public byte[][] Grp_idxs() {return grp_idxs;} private byte[][] grp_idxs = new byte[3][];
|
||||
public byte[] Grp_fwds() {return grp_fwds;} private byte[] grp_fwds = new byte[3];
|
||||
private void Clear() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
grp_fwds[i] = Bool_.__byte;
|
||||
grp_idxs[i] = null;
|
||||
}
|
||||
}
|
||||
public Xoctg_catpage_url Parse(Gfo_usr_dlg usr_dlg, Xoa_url url) {
|
||||
this.Clear();
|
||||
Gfo_qarg_itm[] args = url.Qargs_ary();
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_qarg_itm arg = args[i];
|
||||
byte[] arg_key = arg.Key_bry();
|
||||
Object tid_obj = Arg_keys.Get_by_bry(arg_key);
|
||||
if (tid_obj == null) {usr_dlg.Warn_many("", "", "unknown arg_key: ~{0}", String_.new_u8(arg_key)); continue;} // ignore invalid args
|
||||
byte[] arg_val = arg.Val_bry();
|
||||
byte tid = ((Byte_obj_val)tid_obj).Val();
|
||||
switch (tid) {
|
||||
case Tid_all_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break; // if "from", default all grps to val; DATE:2014-02-05
|
||||
case Tid_all_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break;
|
||||
case Tid_subc_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc); break;
|
||||
case Tid_subc_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc); break;
|
||||
case Tid_file_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_file); break;
|
||||
case Tid_file_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_file); break;
|
||||
case Tid_page_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_page); break;
|
||||
case Tid_page_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_page); break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Set_grp(byte[] val, byte fwd, byte... tids) {
|
||||
int tids_len = tids.length;
|
||||
for (int i = 0; i < tids_len; i++) {
|
||||
byte tid = tids[i];
|
||||
grp_fwds[tid] = fwd;
|
||||
grp_idxs[tid] = val;
|
||||
}
|
||||
}
|
||||
public static final byte Tid_all_bgn = 0, Tid_subc_bgn = 1, Tid_subc_end = 2, Tid_file_bgn = 3, Tid_file_end = 4, Tid_page_bgn = 5, Tid_page_end = 6, Tid_all_end = 8;
|
||||
public static final byte[]
|
||||
Url_arg_from = Bry_.new_a7("from")
|
||||
, Url_arg_until = Bry_.new_a7("until")
|
||||
, Url_arg_subc_bgn = Bry_.new_a7("subcatfrom")
|
||||
, Url_arg_subc_end = Bry_.new_a7("subcatuntil")
|
||||
, Url_arg_page_bgn = Bry_.new_a7("pagefrom")
|
||||
, Url_arg_page_end = Bry_.new_a7("pageuntil")
|
||||
, Url_arg_file_bgn = Bry_.new_a7("filefrom")
|
||||
, Url_arg_file_end = Bry_.new_a7("fileuntil")
|
||||
;
|
||||
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Url_arg_from , Tid_all_bgn)
|
||||
.Add_bry_byte(Url_arg_until , Tid_all_end)
|
||||
.Add_bry_byte(Url_arg_subc_bgn , Tid_subc_bgn)
|
||||
.Add_bry_byte(Url_arg_subc_end , Tid_subc_end)
|
||||
.Add_bry_byte(Url_arg_file_bgn , Tid_file_bgn)
|
||||
.Add_bry_byte(Url_arg_file_end , Tid_file_end)
|
||||
.Add_bry_byte(Url_arg_page_bgn , Tid_page_bgn)
|
||||
.Add_bry_byte(Url_arg_page_end , Tid_page_end)
|
||||
;
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xoctg_catpage_url_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url_fxt fxt = new Xoctg_catpage_url_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse("A?subcatfrom=B&filefrom=C&pagefrom=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
|
||||
fxt.Test_parse("A?subcatuntil=B&fileuntil=C&pageuntil=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
|
||||
fxt.Test_parse("A?from=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
|
||||
fxt.Test_parse("A?until=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_url_fxt {
|
||||
public Xoctg_catpage_url_chkr url() {return expd.Clear();} private Xoctg_catpage_url_chkr expd;
|
||||
public void Clear() {
|
||||
if (parser == null) {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
parser = app.User().Wikii().Utl__url_parser();
|
||||
page_url = Xoa_url.blank();
|
||||
ctg_url = new Xoctg_catpage_url();
|
||||
expd = new Xoctg_catpage_url_chkr();
|
||||
}
|
||||
} private Xow_url_parser parser; Xoa_url page_url; Xoctg_catpage_url ctg_url;
|
||||
public void Test_parse(String url_str, Xoctg_catpage_url_chkr expd) {
|
||||
page_url = parser.Parse(Bry_.new_u8(url_str));
|
||||
ctg_url.Parse(Gfo_usr_dlg_.Test(), page_url);
|
||||
expd.Chk(ctg_url);
|
||||
expd.Clear();
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_url_chkr {
|
||||
public Xoctg_catpage_url_chkr Grp_idxs_(String subc, String file, String page) {
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_subc] = Bry_.new_a7(subc);
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_file] = Bry_.new_a7(file);
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_page] = Bry_.new_a7(page);
|
||||
return this;
|
||||
} byte[][] grp_idxs = new byte[Xoa_ctg_mgr.Tid__max][];
|
||||
public Xoctg_catpage_url_chkr Grp_fwds_(byte subc, byte file, byte page) {
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_subc] = subc;
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_file] = file;
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_page] = page;
|
||||
return this;
|
||||
} byte[] grp_fwds = new byte[Xoa_ctg_mgr.Tid__max];
|
||||
public void Chk(Xoctg_catpage_url actl) {
|
||||
Tfds.Eq_ary_str(String_.Ary(grp_idxs), String_.Ary(actl.Grp_idxs()));
|
||||
Tfds.Eq_ary(grp_fwds, actl.Grp_fwds());
|
||||
}
|
||||
public Xoctg_catpage_url_chkr Clear() {
|
||||
int len = Xoa_ctg_mgr.Tid__max;
|
||||
for (int i = 0; i < len; i++) {
|
||||
grp_idxs[i] = null;
|
||||
grp_fwds[i] = Bool_.__byte;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xoctg_catpage_url {
|
||||
public Xoctg_catpage_url(byte[][] keys, boolean[] fwds) {this.keys = keys; this.fwds = fwds;}
|
||||
public byte[][] Grp_keys() {return keys;} private final byte[][] keys;
|
||||
public boolean[] Grp_fwds() {return fwds;} private final boolean[] fwds;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xoctg_catpage_url__tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url__fxt fxt = new Xoctg_catpage_url__fxt();
|
||||
@Test public void Specific() {
|
||||
fxt.Exec__parse("A?subcatfrom=B&filefrom=C&pagefrom=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
fxt.Exec__parse("A?subcatuntil=B&fileuntil=C&pageuntil=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
|
||||
}
|
||||
@Test public void General() {
|
||||
fxt.Exec__parse("A?from=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
fxt.Exec__parse("A?until=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
|
||||
}
|
||||
@Test public void Url_encoded() {
|
||||
fxt.Exec__parse("A?from=B+C").Test__keys("B C", "B C", "B C").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_url__fxt {
|
||||
private Xow_url_parser xo_url_parser; private Xoctg_catpage_url ctg_url;
|
||||
public void Clear() {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.xo_url_parser = app.User().Wikii().Utl__url_parser();
|
||||
}
|
||||
public Xoctg_catpage_url__fxt Exec__parse(String url_str) {
|
||||
Xoa_url page_url = xo_url_parser.Parse(Bry_.new_u8(url_str));
|
||||
this.ctg_url = Xoctg_catpage_url_parser.Parse(page_url);
|
||||
return this;
|
||||
}
|
||||
public Xoctg_catpage_url__fxt Test__keys(String... expd) {Gftest.Eq__ary(Bry_.Ary(expd), ctg_url.Grp_keys(), "keys"); return this;}
|
||||
public Xoctg_catpage_url__fxt Test__fwds(boolean... expd) {Gftest.Eq__ary(expd, ctg_url.Grp_fwds(), "fwds"); return this;}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Xoctg_catpage_url_parser {
|
||||
public static Xoctg_catpage_url Parse(Xoa_url url) {
|
||||
Gfo_qarg_itm[] args = url.Qargs_ary();
|
||||
if (args == null) return null;
|
||||
|
||||
// init caturl structs
|
||||
byte[][] keys = new byte[Xoa_ctg_mgr.Tid___max][];
|
||||
boolean[] fwds = new boolean[Xoa_ctg_mgr.Tid___max];
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
|
||||
// loop qargs; EX: "?subcatfrom=B&filefrom=C&pagefrom=D"
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfo_qarg_itm arg = args[i];
|
||||
|
||||
// get tid from arg; EX: "pagefrom" -> Tid__page_bgn
|
||||
byte[] key = arg.Key_bry();
|
||||
byte tid = Key_hash.Get_as_byte_or(key, Byte_ascii.Max_7_bit);
|
||||
if (tid == Byte_ascii.Max_7_bit) { // if invalid, warn and skip
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "catpage:unknown url arg: raw~={0} key=~{1}", url.To_bry(true, true), key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// set val
|
||||
byte[] val = arg.Val_bry();
|
||||
Gfo_url_encoder_.Http_url.Decode(tmp_bfr, Bool_.N, val, 0, val.length);
|
||||
val = tmp_bfr.To_bry_and_clear();
|
||||
|
||||
// set struct
|
||||
switch (tid) {
|
||||
case Tid__each_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__subc, Xoa_ctg_mgr.Tid__file, Xoa_ctg_mgr.Tid__page); break; // if "from", default all grps to val; DATE:2014-02-05
|
||||
case Tid__each_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__subc, Xoa_ctg_mgr.Tid__file, Xoa_ctg_mgr.Tid__page); break;
|
||||
case Tid__subc_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__subc); break;
|
||||
case Tid__subc_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__subc); break;
|
||||
case Tid__file_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__file); break;
|
||||
case Tid__file_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__file); break;
|
||||
case Tid__page_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__page); break;
|
||||
case Tid__page_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__page); break;
|
||||
}
|
||||
}
|
||||
return new Xoctg_catpage_url(keys, fwds);
|
||||
}
|
||||
private static void Set_grp(byte[][] keys, boolean[] fwds, byte[] key, boolean fwd, byte... tids) {
|
||||
int len = tids.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte tid = tids[i];
|
||||
keys[tid] = key;
|
||||
fwds[tid] = fwd;
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte
|
||||
Tid__each_bgn = 0, Tid__each_end = 1
|
||||
, Tid__subc_bgn = 2, Tid__subc_end = 3
|
||||
, Tid__file_bgn = 4, Tid__file_end = 5
|
||||
, Tid__page_bgn = 6, Tid__page_end = 7
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__arg_each_bgn = Bry_.new_a7("from") , Bry__arg_each_end = Bry_.new_a7("until")
|
||||
, Bry__arg_subc_bgn = Bry_.new_a7("subcatfrom") , Bry__arg_subc_end = Bry_.new_a7("subcatuntil")
|
||||
, Bry__arg_page_bgn = Bry_.new_a7("pagefrom") , Bry__arg_page_end = Bry_.new_a7("pageuntil")
|
||||
, Bry__arg_file_bgn = Bry_.new_a7("filefrom") , Bry__arg_file_end = Bry_.new_a7("fileuntil")
|
||||
;
|
||||
private static final Hash_adp_bry Key_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Bry__arg_each_bgn , Tid__each_bgn) .Add_bry_byte(Bry__arg_each_end , Tid__each_end)
|
||||
.Add_bry_byte(Bry__arg_subc_bgn , Tid__subc_bgn) .Add_bry_byte(Bry__arg_subc_end , Tid__subc_end)
|
||||
.Add_bry_byte(Bry__arg_page_bgn , Tid__page_bgn) .Add_bry_byte(Bry__arg_page_end , Tid__page_end)
|
||||
.Add_bry_byte(Bry__arg_file_bgn , Tid__file_bgn) .Add_bry_byte(Bry__arg_file_end , Tid__file_end)
|
||||
;
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.catpages.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.core.lists.binary_searches.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_filter {
|
||||
public static void Filter(int limit, Xoctg_catpage_url cat_url, Xoctg_catpage_ctg ctg) {
|
||||
int len = Xoa_ctg_mgr.Tid___max;
|
||||
for (byte i = 0; i < len; ++i) {
|
||||
Filter_by_grp(limit, cat_url, ctg.Grp_by_tid(i));
|
||||
}
|
||||
}
|
||||
private static void Filter_by_grp(int grp_len, Xoctg_catpage_url cat_url, Xoctg_catpage_grp grp) {
|
||||
byte grp_tid = grp.Tid();
|
||||
byte[] grp_key = cat_url.Grp_keys()[grp_tid];
|
||||
|
||||
// dflt to bos; EX: grp_bgn=0 grp_end=200
|
||||
int grp_bgn = 0;
|
||||
int grp_end = grp_bgn + grp_len;
|
||||
|
||||
// key specified; calc new grp_bgn, grp_end
|
||||
if (grp_key != null) {
|
||||
// get idx of key
|
||||
int key_idx = Binary_search_.Search(grp.Itms(), Xoctg_catpage_itm_sorter__sort_key.Sorter, grp_key);
|
||||
|
||||
// if fwd, set grp_bgn to key_idx, and add grp_len
|
||||
if (cat_url.Grp_fwds()[grp_tid]) {
|
||||
grp_bgn = key_idx;
|
||||
grp_end = grp_bgn + grp_len;
|
||||
}
|
||||
// if bwd, set grp_end to key_idx, and subtract grp_len
|
||||
else {
|
||||
grp_end = key_idx;
|
||||
grp_bgn = grp_end - grp_len;
|
||||
|
||||
// assert new grp_bgn is not negative
|
||||
if (grp_bgn < 0) grp_bgn = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// assert new grp_end is not > grp_max; note that this needs to be specified for when grp_key is null and not null
|
||||
int grp_max = grp.Itms__len();
|
||||
if (grp_end > grp_max)
|
||||
grp_end = grp_max;
|
||||
grp.Rng_(grp_bgn, grp_end);
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_filter__tst {
|
||||
private final Xoctg_catpage_filter__fxt fxt = new Xoctg_catpage_filter__fxt();
|
||||
private Xoctg_catpage_ctg ctg;
|
||||
@Before public void init() {
|
||||
this.ctg = fxt.Make__ctg(25, 25, 25);
|
||||
}
|
||||
@Test public void Initial() {
|
||||
fxt.Exec__filter(5, "A", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__05() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=05", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 5, 10);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__10() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=10", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 10, 15);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__23() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=23", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 23, 25);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__full__06() {
|
||||
fxt.Exec__filter(5, "A?from=06", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 6, 11);
|
||||
}
|
||||
@Test public void Bwd__page__20() {
|
||||
fxt.Exec__filter(5, "A?pageuntil=20", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 15, 20);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Bwd__page__2() {
|
||||
fxt.Exec__filter(5, "A?pageuntil=01", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 0, 1);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Bwd__full__11() {
|
||||
fxt.Exec__filter(5, "A?until=11", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 6, 11);
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_filter__fxt {
|
||||
private Xow_url_parser url_parser;
|
||||
public Xoctg_catpage_filter__fxt() {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.url_parser = app.User().Wikii().Utl__url_parser();
|
||||
}
|
||||
public Xoctg_catpage_ctg Make__ctg(int subc, int page, int file) {
|
||||
Xoctg_catpage_ctg ctg = new Xoctg_catpage_ctg(Bry_.new_a7("A"));
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__subc, subc);
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__page, page);
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__file, file);
|
||||
return ctg;
|
||||
}
|
||||
private void Make__ctg_grp(Xoctg_catpage_ctg ctg, byte tid, int count) {
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(i * tid, Xoa_ttl.Null, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 2)));
|
||||
grp.Itms__add(itm);
|
||||
}
|
||||
grp.Itms__make();
|
||||
}
|
||||
public void Exec__filter(int limit, String cat_url_str, Xoctg_catpage_ctg ctg) {
|
||||
Xoctg_catpage_url cat_url = Xoctg_catpage_url_parser.Parse(url_parser.Parse(Bry_.new_a7(cat_url_str)));
|
||||
Xoctg_catpage_filter.Filter(limit, cat_url, ctg);
|
||||
}
|
||||
public void Test__cat_grp(Xoctg_catpage_ctg ctg, byte tid, int expd_bgn, int expd_end) {
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
Gftest.Eq__int(expd_bgn, grp.Bgn(), "bgn failed; tid={0}", tid);
|
||||
Gftest.Eq__int(expd_end, grp.End(), "end failed; tid={0}", tid);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue