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

'v3.6.3.1'

This commit is contained in:
gnosygnu
2016-06-19 23:58:10 -04:00
parent 96636f3161
commit d4e8590345
1960 changed files with 20790 additions and 9272 deletions

View 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.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.core.brys.*;
class Volume_make_itm implements Bry_bfr_able {
public int Uid = 0;
public int Prep_id = 0;
public int Item_type = 0; // 0=page;1=thm
public int Item_id = 0; // either page_id or fsdb_id
public String Item_name = ""; // friendly-name
public byte[] Item_ttl = Bry_.Empty; // actual name
public long Item_size = 0; // size of page / file
public void To_bfr(Bry_bfr bfr) {
}
}
/*
1|p|Earth|123|100
1|f|Earth.png|124|200
1|f|Moon.png|125|300
4|p|Sun|123|100
*/

View File

@@ -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.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.wikis.nss.*;
interface Volume_page_loader {
boolean Load(Volume_page_itm rv, byte[] ttl);
}
class Volume_page_loader__wiki implements Volume_page_loader {
private final Xowe_wiki wiki;
public Volume_page_loader__wiki(Xowe_wiki wiki) {this.wiki = wiki;}
public boolean Load(Volume_page_itm rv, byte[] ttl) {
Xoa_ttl page_ttl = wiki.Ttl_parse(ttl); if (page_ttl == null) return false;
Xoa_url page_url = wiki.Utl__url_parser().Parse(ttl);
Xoae_page page = wiki.Data_mgr().Load_page_and_parse(page_url, page_ttl);
Load_links(rv, page.Lnki_list());
return true;
}
private void Load_links(Volume_page_itm rv, List_adp list) {
int len = list.Len();
//gplx.xowa.wikis.data.tbls.Xowd_page_tbl page_tbl; page_tbl.Select_in__ttl
for (int i = 0; i < len; i++) {
Xop_lnki_tkn lnki = (Xop_lnki_tkn)list.Get_at(i);
int ns_id = lnki.Ns_id();
switch (ns_id) {
case Xow_ns_.Tid__special:
case Xow_ns_.Tid__media:
break;
case Xow_ns_.Tid__file:
break; // file
default:
Volume_make_itm make_itm = new Volume_make_itm();
make_itm.Item_ttl = lnki.Ttl().Page_db();
make_itm.Item_size = 1;
rv.Link_list().Add(make_itm);
break;
}
}
}
}
class Volume_page_itm {
public void Init(Xoa_ttl page_ttl, Xoa_url page_url) {
this.page_ttl = page_ttl; this.page_url = page_url;
}
public Xoa_ttl Page_ttl() {return page_ttl;} private Xoa_ttl page_ttl;
public Xoa_url Page_url() {return page_url;} private Xoa_url page_url;
public List_adp Link_list() {return link_list;} private final List_adp link_list = List_adp_.New();
public List_adp File_list() {return file_list;} private final List_adp file_list = List_adp_.New();
}

View 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.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.core.brys.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Volume_prep_cmd extends Xob_cmd__base {
private Io_url prep_url, make_url;
public Volume_prep_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
Volume_prep_itm[] page_itms = new Volume_prep_rdr().Parse(prep_url);
Volume_prep_mgr prep_mgr = new Volume_prep_mgr(new Volume_page_loader__wiki(wiki));
Volume_make_itm[] make_itms = prep_mgr.Calc_makes(page_itms);
Bry_bfr bfr = Bry_bfr_.New();
for (Volume_make_itm make_itm : make_itms) {
make_itm.To_bfr(bfr);
bfr.Add_byte_nl();
}
Io_mgr.Instance.SaveFilBfr(make_url, bfr);
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__prep_url_)) prep_url = m.ReadIoUrl("v");
else if (ctx.Match(k, Invk__make_url_)) make_url = m.ReadIoUrl("v");
else return super.Invk(ctx, ikey, k, m);
return this;
}
private static final String Invk__prep_url_ = "prep_url_", Invk__make_url_ = "make_url_";
public static final String BLDR_CMD_KEY = "volume.prep";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Volume_prep_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Volume_prep_cmd(bldr, wiki);}
}

View 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.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.core.brys.*;
class Volume_prep_itm implements Bry_bfr_able {
public int Prep_id = 0;
public byte[] Page_ttl = null;
public long Max_bytes = 0;
public int Max_depth = 2;
public int Max_article_count = -1;
public int Max_link_count_per_page = -1;
public boolean Skip_navbox = false;
public int Max_file_count = -1;
public long Max_file_size = -1;
public boolean Skip_audio = true;
public static final Volume_prep_itm[] Ary_empty = new Volume_prep_itm[0];
public void To_bfr(Bry_bfr bfr) {
bfr.Add(Page_ttl);
}
}
// Earth|2|100|10|100|100MB

View 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.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
class Volume_prep_mgr {
private final Volume_page_loader loader;
private final Volume_page_itm tmp_page = new Volume_page_itm();
private final List_adp list = List_adp_.New();
public Volume_prep_mgr(Volume_page_loader loader) {this.loader = loader;}
public Volume_make_itm[] Calc_makes(Volume_prep_itm[] ary) {
Volume_prep_ctx ctx = new Volume_prep_ctx();
int len = ary.length;
for (int i = 0; i < len; ++i) {
Volume_prep_itm itm = ary[i];
ctx.Init(ctx, itm);
Calc_make(ctx, itm.Page_ttl);
}
return (Volume_make_itm[])list.To_ary_and_clear(Volume_make_itm.class);
}
private void Calc_make(Volume_prep_ctx ctx, byte[] page_ttl) {
if (!loader.Load(tmp_page, page_ttl)) return;
if (ctx.Bytes_max != -1 && ctx.Bytes_count > ctx.Bytes_max) return;
if (ctx.Depth_count > ctx.Depth_max) return;
List_adp files_list = tmp_page.File_list();
int files_len = files_list.Len();
for (int i = 0; i < files_len; ++i) {
Volume_make_itm file_itm = (Volume_make_itm)files_list.Get_at(i);
list.Add(file_itm);
}
List_adp links_list = tmp_page.Link_list();
int links_len = links_list.Len();
for (int i = 0; i < links_len; ++i) {
if (ctx.Page_max != -1 && ctx.Page_count++ > ctx.Page_max) return;
Volume_make_itm link_itm = (Volume_make_itm)links_list.Get_at(i);
list.Add(link_itm);
ctx.Depth_count++;
Calc_make(ctx, link_itm.Item_ttl);
ctx.Depth_count--;
}
}
}
class Volume_prep_ctx {
public long Bytes_count;
public long Bytes_max;
public int Page_count;
public int Page_max;
public int Depth_count;
public int Depth_max;
public void Init(Volume_prep_ctx prv_ctx, Volume_prep_itm itm) {
this.Bytes_count = prv_ctx.Bytes_count;
this.Bytes_max = itm.Max_bytes;
this.Page_count = 1;
this.Page_max = itm.Max_article_count;
this.Depth_count = 0;
this.Depth_max = itm.Max_depth;
}
// public int Max_link_count_per_page = -1;
// public int Max_file_count = -1;
// public long Max_file_size = -1;
// public boolean Skip_navbox = false;
// public boolean Skip_audio = true;
}

View File

@@ -0,0 +1,45 @@
/*
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.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
class Volume_prep_rdr {
public Volume_prep_itm[] Parse(Io_url url) {return Parse(Io_mgr.Instance.LoadFilBryOr(url, null));}
public Volume_prep_itm[] Parse(byte[] src) {
if (src == null) return Volume_prep_itm.Ary_empty;
List_adp rv = List_adp_.New();
byte[][] lines = Bry_split_.Split_lines(src);
int lines_len = lines.length;
for (int i = 0; i < lines_len; ++i) {
Volume_prep_itm itm = Parse_line_or_null(lines[i]);
if (itm != null) rv.Add(itm);
}
return (Volume_prep_itm[])rv.To_ary_and_clear(Volume_prep_itm.class);
}
private Volume_prep_itm Parse_line_or_null(byte[] line) {
byte[][] flds = Bry_split_.Split(line, Byte_ascii.Pipe);
int flds_len = flds.length; if (flds_len == 0) return null;
Volume_prep_itm rv = new Volume_prep_itm();
for (int i = 0; i < flds_len; ++i) {
byte[] fld = flds[i];
switch (i) {
case 0: rv.Page_ttl = fld; break;
default: throw Err_.new_unhandled_default(i);
}
}
return rv;
}
}

View 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.addons.bldrs.volumes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import org.junit.*; import gplx.core.tests.*;
public class Volume_prep_rdr_tst {
private final Volume_prep_rdr_fxt fxt = new Volume_prep_rdr_fxt();
@Test public void Parse() {
fxt.Test__parse(String_.Concat_lines_nl_skip_last("A", "", "B")
, fxt.Make__itm("A")
, fxt.Make__itm("B")
);
}
}
class Volume_prep_rdr_fxt {
private final Volume_prep_rdr rdr = new Volume_prep_rdr();
public Volume_prep_rdr_fxt Test__parse(String raw, Volume_prep_itm... expd) {
Gftest.Eq__ary(expd, rdr.Parse(Bry_.new_u8(raw)));
return this;
}
public Volume_prep_itm Make__itm(String page_ttl) {
Volume_prep_itm rv = new Volume_prep_itm();
rv.Page_ttl = Bry_.new_u8(page_ttl);
return rv;
}
}