v3.3.4 v3.7.3.1
gnosygnu 8 years ago
parent b333db45f8
commit 7a851a41a5

@ -16,13 +16,11 @@ 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.brys; import gplx.*; import gplx.core.*;
public class Bry_bfr_mkr {
private final Bry_bfr_mkr_mgr mkr_b128 = new Bry_bfr_mkr_mgr(Tid_b128, 128);
public Bry_bfr Get_b128() {return mkr_b128.Get();}
public Bry_bfr Get_b512() {return mkr_b512.Get();} private final Bry_bfr_mkr_mgr mkr_b512 = new Bry_bfr_mkr_mgr(Tid_b512, 512);
public Bry_bfr Get_k004() {return mkr_k004.Get();} private final Bry_bfr_mkr_mgr mkr_k004 = new Bry_bfr_mkr_mgr(Tid_k004, 4 * Io_mgr.Len_kb);
public Bry_bfr Get_m001() {return mkr_m001.Get();} private final Bry_bfr_mkr_mgr mkr_m001 = new Bry_bfr_mkr_mgr(Tid_m001, 1 * Io_mgr.Len_mb);
public void Rls(Bry_bfr v) {v.Mkr_rls();}
public class Bry_bfr_mkr {
public Bry_bfr Get_b128() {return mkr_b128.Get();} private final Bry_bfr_mkr_mgr mkr_b128 = new Bry_bfr_mkr_mgr(Tid_b128, 128);
public Bry_bfr Get_b512() {return mkr_b512.Get();} private final Bry_bfr_mkr_mgr mkr_b512 = new Bry_bfr_mkr_mgr(Tid_b512, 512);
public Bry_bfr Get_k004() {return mkr_k004.Get();} private final Bry_bfr_mkr_mgr mkr_k004 = new Bry_bfr_mkr_mgr(Tid_k004, 4 * Io_mgr.Len_kb);
public Bry_bfr Get_m001() {return mkr_m001.Get();} private final Bry_bfr_mkr_mgr mkr_m001 = new Bry_bfr_mkr_mgr(Tid_m001, 1 * Io_mgr.Len_mb);
public void Clear() {
for (byte i = Tid_b128; i <= Tid_m001; i++)
mkr(i).Clear();

@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.brys; import gplx.*; import gplx.core.*;
public class Bry_bfr_mkr_mgr {
private final Object thread_lock = new Object();
private final byte mgr_id; private final int reset;
private Bry_bfr[] used = Bry_bfr_.Ary_empty; private int used_len = 0, used_max = 0;
private int[] free; private int free_len; private int reset;
private int[] free; private int free_len;
public Bry_bfr_mkr_mgr(byte mgr_id, int reset) {// NOTE: random IndexOutOfBounds errors in Get around free[--free_len] with free_len being -1; put member variable initialization within thread_lock to try to avoid; DATE:2014-09-21
this.mgr_id = mgr_id;
this.reset = reset;
this.free = Int_.Ary_empty;
this.free_len = 0;
}
public byte Mgr_id() {return mgr_id;} private byte mgr_id;
public Bry_bfr Get() {
synchronized (thread_lock) {
Bry_bfr rv = null; int rv_idx = -1;
@ -62,7 +62,7 @@ public class Bry_bfr_mkr_mgr {
for (int i = 0; i < used_max; i++) {
Bry_bfr itm = used[i];
if (itm != null) {
if (!itm.Mkr_idx_is_null()) throw Err_.new_wo_type("failed to clear bfr", "idx", Int_.To_str(i));
if (!itm.Mkr_idx_is_null()) throw Err_.new_wo_type("failed to clear bfr", "mgr_id", mgr_id, "idx", Int_.To_str(i));
itm.Clear();
}
used[i] = null;

@ -19,6 +19,7 @@ package gplx.core.brys; import gplx.*; import gplx.core.*;
import gplx.core.errs.*; import gplx.core.btries.*;
public class Bry_rdr {
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.New_neg1();
private final Btrie_rv trv = new Btrie_rv();
public byte[] Src() {return src;} protected byte[] src;
public int Src_end() {return src_end;} protected int src_end;
public int Pos() {return pos;} protected int pos;
@ -150,8 +151,8 @@ public class Bry_rdr {
byte rv = Chk_or(trie, Byte_.Max_value_127);
if (rv == Byte_.Max_value_127) err_wkr.Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16)));
}
public Object Chk_trie_as_obj(Btrie_slim_mgr trie) {
Object rv = trie.Match_bgn(src, pos, src_end); if (rv == null) err_wkr.Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16)));
public Object Chk_trie_as_obj(Btrie_rv trv, Btrie_slim_mgr trie) {
Object rv = trie.Match_at(trv, src, pos, src_end); if (rv == null) err_wkr.Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16)));
return rv;
}
public byte Chk_or(Btrie_slim_mgr trie, byte or) {return Chk_or(trie, pos, src_end, or);}
@ -161,9 +162,9 @@ public class Bry_rdr {
return rv;
}
public byte Chk_or(Btrie_slim_mgr trie, int itm_bgn, int itm_end, byte or) {
Object rv_obj = trie.Match_bgn(src, itm_bgn, itm_end);
Object rv_obj = trie.Match_at(trv, src, itm_bgn, itm_end);
if (rv_obj == null) return or;
pos = trie.Match_pos();
pos = trv.Pos();
return ((gplx.core.primitives.Byte_obj_val)rv_obj).Val();
}
@gplx.Virtual public Bry_rdr Skip_ws() {

@ -23,6 +23,37 @@ public class Btrie_bwd_mgr {
Object rv = Match(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int end_pos) {
// NOTE: bgn, end follows same semantics as fwd where bgn >= & end < except reversed: bgn <= & end >; EX: "abcde" should pass 5, -1
Object rv_obj = null;
int rv_pos = bgn_pos;
int cur_pos = bgn_pos;
Btrie_slim_itm cur = root;
while (true) {
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null) { // nxt does not have b; return rv_obj;
rv.Init(rv_pos, rv_obj);
return rv_obj;
}
--cur_pos;
if (nxt.Ary_is_empty()) { // nxt is leaf; return nxt.Val() (which should be non-null)
rv_obj = nxt.Val();
rv.Init(cur_pos, rv_obj);
return rv_obj;
}
Object nxt_val = nxt.Val();
if (nxt_val != null) {rv_pos = cur_pos; rv_obj = nxt_val;} // nxt is node; cache rv_obj (in case of false match)
if (cur_pos == end_pos) { // increment cur_pos and exit if end_pos
rv.Init(rv_pos, rv_obj);
return rv_obj;
}
b = src[cur_pos];
cur = nxt;
}
}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match(byte b, byte[] src, int bgn_pos, int end_pos) {
// NOTE: bgn, end follows same semantics as fwd where bgn >= & end < except reversed: bgn <= & end >; EX: "abcde" should pass 5, -1

@ -22,12 +22,7 @@ public class Btrie_fast_mgr {
public boolean CaseAny() {return root.CaseAny();} public Btrie_fast_mgr CaseAny_(boolean v) {root.CaseAny_(v); return this;}
public int Match_pos() {return match_pos;} private int match_pos;
// Btrie_rv Match_at_w_b0_and_rls(byte[] src, int bgn, int end) {return Match_at_w_b0_and_rls(src[bgn], src, bgn, end);}
// Btrie_rv Match_at_w_b0_and_rls(byte b, byte[] src, int bgn_pos, int src_end) {
// Btrie_rv rv = ((Btrie_rv)Btrie_rv.Pool__mgr.Get_safe());
// Match_at_w_b0(rv, b, src, bgn_pos, src_end);
// return rv;
// }
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int src_end) {
Object rv_obj = null;
int rv_pos = bgn_pos;

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.btries; import gplx.*; import gplx.core.*;
public interface Btrie_mgr {
int Match_pos();
Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos);
Object Match_bgn(byte[] src, int bgn_pos, int end_pos);
Btrie_mgr Add_obj(String key, Object val);
Btrie_mgr Add_obj(byte[] key, Object val);

@ -31,7 +31,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
while (true) {
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null) {
rv.Init(cur_pos, rv_obj); // nxt does not hav b; return rv_obj;
rv.Init(rv_pos, rv_obj); // nxt does not have b; return rv_obj;
return rv_obj;
}
++cur_pos;
@ -79,6 +79,14 @@ public class Btrie_slim_mgr implements Btrie_mgr {
Object rv_obj = Match_bgn(src, bgn, end);
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
}
public byte Match_byte_or(Btrie_rv trv, byte b, byte[] src, int bgn, int end, byte or) {
Object rv_obj = Match_at_w_b0(trv, b, src, bgn, end);
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
}
public byte Match_byte_or(Btrie_rv trv, byte[] src, int bgn, int end, byte or) {
Object rv_obj = Match_at(trv, src, bgn, end);
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
}
public Btrie_slim_mgr Add_bry_tid(byte[] bry, byte tid) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(tid));}
public Btrie_slim_mgr Add_bry_int(byte[] key, int val) {return (Btrie_slim_mgr)Add_obj(key, Int_obj_val.new_(val));}
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Byte_obj_val.new_(val));}

@ -24,6 +24,37 @@ public class Btrie_u8_mgr implements Btrie_mgr {
this.root = new Btrie_u8_itm(Bry_.Empty, null);
}
public int Count() {return count;} private int count;
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int end_pos) {
Object rv_obj = null;
int rv_pos = bgn_pos;
int cur_pos = bgn_pos;
Btrie_u8_itm cur = root;
while (true) {
int c_len = Utf8_.Len_of_char_by_1st_byte(b);
int c_end = cur_pos + c_len;
Btrie_u8_itm nxt = cur.Nxts_find(src, cur_pos, c_end, true);
if (nxt == null) {
rv.Init(rv_pos, rv_obj); // nxts does not have key; return rv_obj;
return rv_obj;
}
cur_pos = c_end;
if (nxt.Nxts_is_empty()) { // nxt is leaf; return nxt.Val() (which should be non-null)
rv_obj = nxt.Val();
rv.Init(cur_pos, rv_obj);
return rv_obj;
}
Object nxt_val = nxt.Val();
if (nxt_val != null) {rv_pos = cur_pos; rv_obj = nxt_val;} // nxt is node; cache rv_obj (in case of false match)
if (cur_pos == end_pos) { // increment cur_pos and exit if end
rv.Init(rv_pos, rv_obj);
return rv_obj;
}
b = src[cur_pos];
cur = nxt;
}
}
public int Match_pos() {return match_pos;} private int match_pos;
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);}
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int end_pos) {

@ -0,0 +1,35 @@
/*
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.threads.utils; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
import java.util.concurrent.ArrayBlockingQueue;
public class Gfo_blocking_queue {
private final ArrayBlockingQueue queue;
public Gfo_blocking_queue(int capacity) {
this.capacity = capacity;
this.queue = new ArrayBlockingQueue(capacity);
}
public int Capacity() {return capacity;} private final int capacity;
public void Put(Object o) {
try {queue.put(o);}
catch (InterruptedException e) {throw Err_.new_exc(e, "threads", "put interrupted");}
}
public Object Take() {
try {return queue.take();}
catch (InterruptedException e) {throw Err_.new_exc(e, "threads", "take interrupted");}
}
}

@ -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.core.threads.utils; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
import java.util.concurrent.CountDownLatch;
public class Gfo_countdown_latch {
private final CountDownLatch latch;
public Gfo_countdown_latch(int count) {
latch = new CountDownLatch(count);
}
public void Countdown() {
latch.countDown();
}
public void Await() {
try {latch.await();}
catch (InterruptedException e) {throw Err_.new_exc(e, "threads", "await interrupted");}
}
}

@ -39,6 +39,7 @@ public class Db_conn {
public void Env_vacuum() {Exec_sql_plog_ntx("vacuuming: url=" + this.Conn_info().Db_api(), "VACUUM;");}
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {engine.Meta_tbl_create(meta); engine.Meta_idx_create(Gfo_usr_dlg_.Noop, meta.Idxs().To_ary());}
public void Meta_tbl_delete(String tbl) {engine.Meta_tbl_delete(tbl);}
public void Meta_tbl_remake(Db_tbl tbl) {engine.Meta_tbl_delete(tbl.Tbl_name()); tbl.Create_tbl();}
public void Meta_tbl_remake(Dbmeta_tbl_itm meta) {engine.Meta_tbl_delete(meta.Name()); engine.Meta_tbl_create(meta);}
public void Meta_idx_assert(String tbl, String suffix, String... flds) {if (engine.Meta_idx_exists(tbl + "__" + suffix)) return; this.Meta_idx_create(tbl, suffix, flds);}
public void Meta_idx_assert(String tbl, String suffix, Dbmeta_idx_fld... flds) {if (engine.Meta_idx_exists(tbl + "__" + suffix)) return; this.Meta_idx_create(tbl, suffix, flds);}

@ -17,26 +17,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs; import gplx.*;
public class Db_conn_bldr {
private final Object thread_lock = new Object(); // LOCK:synchronized else random failures in Schema_mgr due to diff conn pointing to same db; DATE:2016-07-12
private Db_conn_bldr_wkr wkr;
public void Reg_default_sqlite() {wkr = Db_conn_bldr_wkr__sqlite.Instance; wkr.Clear_for_tests();}
public void Reg_default_mem() {wkr = Db_conn_bldr_wkr__mem.Instance; wkr.Clear_for_tests();}
public boolean Exists(Io_url url) {return wkr.Exists(url);}
public Db_conn Get(Io_url url) {return wkr.Get(url);}
public Db_conn New(Io_url url) {return wkr.New(url);}
public boolean Exists(Io_url url) {synchronized (thread_lock) {return wkr.Exists(url);}}
public Db_conn Get(Io_url url) {synchronized (thread_lock) {return wkr.Get(url);}}
public Db_conn New(Io_url url) {synchronized (thread_lock) {return wkr.New(url);}}
public Db_conn_bldr_data Get_or_new(Io_url url) {
boolean exists = wkr.Exists(url);
Db_conn conn = exists ? Get(url) : New(url);
return new Db_conn_bldr_data(conn, exists);
synchronized (thread_lock) {
boolean exists = wkr.Exists(url);
Db_conn conn = exists ? Get(url) : New(url);
return new Db_conn_bldr_data(conn, exists);
}
}
public Db_conn Get_or_noop(Io_url url) {
Db_conn rv = wkr.Get(url);
return rv == null ? Db_conn_.Noop : rv;
synchronized (thread_lock) {
Db_conn rv = wkr.Get(url);
return rv == null ? Db_conn_.Noop : rv;
}
}
public Db_conn Get_or_autocreate(boolean autocreate, Io_url url) {
boolean exists = wkr.Exists(url);
if (exists) return Get(url);
if (autocreate) return New(url);
else throw Err_.new_("dbs", "db does not exist", "url", url.Raw());
synchronized (thread_lock) {
boolean exists = wkr.Exists(url);
if (exists) return Get(url);
if (autocreate) return New(url);
else throw Err_.new_("dbs", "db does not exist", "url", url.Raw());
}
}
public static final Db_conn_bldr Instance = new Db_conn_bldr(); Db_conn_bldr() {}
}

@ -19,7 +19,7 @@ package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.db
import gplx.core.brys.*; import gplx.core.btries.*;
abstract class Dbmeta_fld_wkr__base {
private byte[] hook;
private final Btrie_slim_mgr words_trie = Btrie_slim_mgr.ci_a7();
private final Btrie_slim_mgr words_trie = Btrie_slim_mgr.ci_a7();
private int words_len;
@gplx.Virtual public int Tid() {return Tid_other;}
public void Ctor(byte[] hook, byte[]... words_ary) {
@ -46,47 +46,47 @@ class Dbmeta_fld_wkr__end_comma extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__end_comma() {this.Ctor(Hook);}
@Override public int Tid() {return Tid_end_comma;}
@Override protected void When_match(Dbmeta_fld_itm fld) {}
private static final byte[] Hook = Bry_.new_a7(",");
public static final Dbmeta_fld_wkr__end_comma Instance = new Dbmeta_fld_wkr__end_comma();
private static final byte[] Hook = Bry_.new_a7(",");
public static final Dbmeta_fld_wkr__end_comma Instance = new Dbmeta_fld_wkr__end_comma();
}
class Dbmeta_fld_wkr__end_paren extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__end_paren() {this.Ctor(Hook);}
@Override public int Tid() {return Tid_end_paren;}
@Override protected void When_match(Dbmeta_fld_itm fld) {}
private static final byte[] Hook = Bry_.new_a7(")");
public static final Dbmeta_fld_wkr__end_paren Instance = new Dbmeta_fld_wkr__end_paren();
private static final byte[] Hook = Bry_.new_a7(")");
public static final Dbmeta_fld_wkr__end_paren Instance = new Dbmeta_fld_wkr__end_paren();
}
class Dbmeta_fld_wkr__nullable_null extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__nullable_null() {this.Ctor(Hook);}
@Override protected void When_match(Dbmeta_fld_itm fld) {
fld.Nullable_tid_(Dbmeta_fld_itm.Nullable_null);
}
private static final byte[] Hook = Bry_.new_a7("null");
public static final Dbmeta_fld_wkr__nullable_null Instance = new Dbmeta_fld_wkr__nullable_null();
private static final byte[] Hook = Bry_.new_a7("null");
public static final Dbmeta_fld_wkr__nullable_null Instance = new Dbmeta_fld_wkr__nullable_null();
}
class Dbmeta_fld_wkr__nullable_not extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__nullable_not() {this.Ctor(Hook, Bry_null);}
@Override protected void When_match(Dbmeta_fld_itm fld) {
fld.Nullable_tid_(Dbmeta_fld_itm.Nullable_not_null);
}
private static final byte[] Hook = Bry_.new_a7("not"), Bry_null = Bry_.new_a7("null");
public static final Dbmeta_fld_wkr__nullable_not Instance = new Dbmeta_fld_wkr__nullable_not();
private static final byte[] Hook = Bry_.new_a7("not"), Bry_null = Bry_.new_a7("null");
public static final Dbmeta_fld_wkr__nullable_not Instance = new Dbmeta_fld_wkr__nullable_not();
}
class Dbmeta_fld_wkr__primary_key extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__primary_key() {this.Ctor(Hook, Bry_key);}
@Override protected void When_match(Dbmeta_fld_itm fld) {
fld.Primary_y_();
}
private static final byte[] Hook = Bry_.new_a7("primary"), Bry_key = Bry_.new_a7("key");
public static final Dbmeta_fld_wkr__primary_key Instance = new Dbmeta_fld_wkr__primary_key();
private static final byte[] Hook = Bry_.new_a7("primary"), Bry_key = Bry_.new_a7("key");
public static final Dbmeta_fld_wkr__primary_key Instance = new Dbmeta_fld_wkr__primary_key();
}
class Dbmeta_fld_wkr__autonumber extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__autonumber() {this.Ctor(Hook);}
@Override protected void When_match(Dbmeta_fld_itm fld) {
fld.Autonum_y_();
}
private static final byte[] Hook = Bry_.new_a7("autoincrement");
public static final Dbmeta_fld_wkr__autonumber Instance = new Dbmeta_fld_wkr__autonumber();
private static final byte[] Hook = Bry_.new_a7("autoincrement");
public static final Dbmeta_fld_wkr__autonumber Instance = new Dbmeta_fld_wkr__autonumber();
}
class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
public Dbmeta_fld_wkr__default() {this.Ctor(Hook);}
@ -143,6 +143,6 @@ class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
return String_.new_a7(src, bgn, end);
}
@Override protected void When_match(Dbmeta_fld_itm fld) {}
private static final byte[] Hook = Bry_.new_a7("default");
public static final Dbmeta_fld_wkr__default Instance = new Dbmeta_fld_wkr__default();
private static final byte[] Hook = Bry_.new_a7("default");
public static final Dbmeta_fld_wkr__default Instance = new Dbmeta_fld_wkr__default();
}

@ -19,6 +19,7 @@ package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.db
import gplx.core.brys.*; import gplx.core.btries.*;
import gplx.dbs.engines.sqlite.*;
public class Dbmeta_parser__fld {
private final Btrie_rv trv = new Btrie_rv();
public Dbmeta_fld_itm Parse_fld(Sql_bry_rdr rdr) { // starts after "(" or ","; EX: "(fld1 int", ", fld2 int"; ends at ")"
byte[] name = rdr.Read_sql_identifier();
Dbmeta_fld_tid type = this.Parse_type(rdr);
@ -41,12 +42,12 @@ public class Dbmeta_parser__fld {
}
return fld;
}
Dbmeta_fld_wkr__base type_wkr = (Dbmeta_fld_wkr__base)rdr.Chk_trie_as_obj(fld_trie);
Dbmeta_fld_wkr__base type_wkr = (Dbmeta_fld_wkr__base)rdr.Chk_trie_as_obj(trv, fld_trie);
switch (type_wkr.Tid()) {
case Dbmeta_fld_wkr__base.Tid_end_comma:
case Dbmeta_fld_wkr__base.Tid_end_paren: return fld;
default:
rdr.Move_to(fld_trie.Match_pos());
rdr.Move_to(trv.Pos());
type_wkr.Match(rdr, fld);
break;
}
@ -54,7 +55,7 @@ public class Dbmeta_parser__fld {
}
@gplx.Internal protected Dbmeta_fld_tid Parse_type(Bry_rdr rdr) {
rdr.Skip_ws();
Dbmeta_parser__fld_itm type_itm = (Dbmeta_parser__fld_itm)rdr.Chk_trie_as_obj(type_trie);
Dbmeta_parser__fld_itm type_itm = (Dbmeta_parser__fld_itm)rdr.Chk_trie_as_obj(trv, type_trie);
rdr.Move_by(type_itm.Word().length);
int paren_itms_count = type_itm.Paren_itms_count();
int len_1 = Int_.Min_value, len_2 = Int_.Min_value;

@ -25,7 +25,7 @@ public abstract class Db_in_wkr__base {
public void Select_in(Cancelable cancelable, Db_conn conn, int full_bgn, int full_end) {
int part_len = Interval();
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
boolean show_progress = this.Show_progress();
boolean show_progress = this.Show_progress();;
for (int part_bgn = full_bgn; part_bgn < full_end; part_bgn += part_len) {
int part_end = part_bgn + part_len;
if (part_end > full_end) part_end = full_end;

@ -18,9 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.ios; import gplx.*; import gplx.core.*;
import gplx.core.ios.streams.*;
public class Io_stream_zip_mgr {
private final Bry_bfr bfr = Bry_bfr_.Reset(256);
private Io_stream_wtr wtr_gzip, wtr_zip, wtr_bzip2;
private Io_stream_rdr rdr_gzip, rdr_zip, rdr_bzip2;
public byte[] Zip(byte type, byte[] val) {
if (type == Io_stream_.Tid_raw) return val;
Io_stream_wtr wtr = Wtr(type);
@ -29,14 +27,13 @@ public class Io_stream_zip_mgr {
return wtr.To_ary_and_clear();
}
public byte[] Unzip(byte type, byte[] val) {
synchronized (this) { // LOCK:static-obj;rdr_*;necessary; DATE:2016-07-06
if (type == Io_stream_.Tid_raw) return val;
Io_stream_rdr rdr = Rdr(type);
rdr.Open_mem(val);
return Io_stream_rdr_.Load_all_as_bry(bfr, rdr);
}
if (type == Io_stream_.Tid_raw) return val;
Io_stream_rdr rdr = Rdr(type);
rdr.Open_mem(val);
return Io_stream_rdr_.Load_all_as_bry(Bry_bfr_.New(), rdr);
}
private Io_stream_wtr Wtr(byte type) {
Bry_bfr bfr = Bry_bfr_.New();
switch (type) {
case Io_stream_.Tid_gzip : if (wtr_gzip == null) wtr_gzip = Io_stream_wtr_.new_by_mem(bfr, Io_stream_.Tid_gzip) ; return wtr_gzip.Open();
case Io_stream_.Tid_zip : if (wtr_zip == null) wtr_zip = Io_stream_wtr_.new_by_mem(bfr, Io_stream_.Tid_zip) ; return wtr_zip.Open();
@ -45,11 +42,11 @@ public class Io_stream_zip_mgr {
default : throw Err_.new_unhandled(type);
}
}
private Io_stream_rdr Rdr(byte type) {
private Io_stream_rdr Rdr(byte type) { // TS.MEM: DATE:2016-07-12
switch (type) {
case Io_stream_.Tid_gzip : if (rdr_gzip == null) rdr_gzip = Io_stream_rdr_.new_by_tid_(Io_stream_.Tid_gzip) ; return rdr_gzip;
case Io_stream_.Tid_zip : if (rdr_zip == null) rdr_zip = Io_stream_rdr_.new_by_tid_(Io_stream_.Tid_zip) ; return rdr_zip;
case Io_stream_.Tid_bzip2 : if (rdr_bzip2 == null) rdr_bzip2 = Io_stream_rdr_.new_by_tid_(Io_stream_.Tid_bzip2) ; return rdr_bzip2;
case Io_stream_.Tid_gzip : return Io_stream_rdr_.new_by_tid_(Io_stream_.Tid_gzip);
case Io_stream_.Tid_zip : return Io_stream_rdr_.new_by_tid_(Io_stream_.Tid_zip);
case Io_stream_.Tid_bzip2 : return Io_stream_rdr_.new_by_tid_(Io_stream_.Tid_bzip2);
case Io_stream_.Tid_raw :
default : throw Err_.new_unhandled(type);
}

@ -22,6 +22,7 @@ public class Gfo_url_parser {
private final Btrie_slim_mgr protocols = Btrie_slim_mgr.ci_a7(); // ASCII:url_protocol; EX:"http:", "ftp:", etc
private final Bry_ary segs_ary = new Bry_ary(4), qargs = new Bry_ary(4);
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(500);
private final Btrie_rv trv = new Btrie_rv();
public byte[] Relative_url_protocol_bry() {return Gfo_protocol_itm.Itm_https.Key_w_colon_bry();} // NOTE: https b/c any WMF wiki will now default to WMF; DATE:2015-07-26
public Gfo_url_parser() {
Init_protocols(Gfo_protocol_itm.Ary());
@ -76,8 +77,8 @@ public class Gfo_url_parser {
path_bgn = qarg_key_bgn = qarg_val_bgn = anch_bgn = anch_nth_bgn = -1;
segs_ary.Clear(); qargs.Clear();
int pos = src_bgn;
Object protocol_obj = protocols.Match_bgn(src, src_bgn, src_end);
pos = protocols.Match_pos();
Object protocol_obj = protocols.Match_at(trv, src, src_bgn, src_end);
pos = trv.Pos();
pos = Bry_find_.Find_fwd_while(src, pos, src_end, Byte_ascii.Slash);
if (protocol_obj == null) {
this.protocol_tid = Gfo_protocol_itm.Tid_unknown;

@ -22,7 +22,7 @@ public class Http_request_parser {
private int type, content_length;
private byte[] url, protocol, host, user_agent, accept, accept_language, accept_encoding, x_requested_with, cookie, referer, content_type, content_type_boundary, connection, pragma, cache_control, origin;
private Http_post_data_hash post_data_hash;
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255); private final Btrie_rv trv = new Btrie_rv();
private final Http_server_wtr server_wtr; private final boolean log;
public Http_request_parser(Http_server_wtr server_wtr, boolean log) {this.server_wtr = server_wtr; this.log = log;}
public void Clear() {
@ -59,12 +59,12 @@ public class Http_request_parser {
}
break; // assume form_data sends POST request
}
Object o = trie.Match_bgn(line, 0, line_len);
Object o = trie.Match_at(trv, line, 0, line_len);
if (o == null) {
server_wtr.Write_str_w_nl(String_.Format("http.request.parser; unknown line; line={0} request={1}", line_str, To_str()));
continue;
}
int val_bgn = Bry_find_.Find_fwd_while_ws(line, trie.Match_pos(), line_len); // skip ws after key; EX: "Host: "
int val_bgn = Bry_find_.Find_fwd_while_ws(line, trv.Pos(), line_len); // skip ws after key; EX: "Host: "
int tid = ((Int_obj_val)o).Val();
switch (tid) {
case Tid_get:

@ -27,7 +27,7 @@ class Gfs_lxr_whitespace implements Gfs_lxr {
int rv = Gfs_lxr_.Rv_eos, cur_pos;
for (cur_pos = end; cur_pos < src_len; cur_pos++) {
byte b = src[cur_pos];
Object o = ctx.Trie().Match_bgn_w_byte(b, src, cur_pos, src_len);
Object o = ctx.Trie().Match_at_w_b0(ctx.Trie_rv(), b, src, cur_pos, src_len);
if (o == null) {
rv = Gfs_lxr_.Rv_null;
ctx.Process_null(cur_pos);
@ -45,7 +45,7 @@ class Gfs_lxr_whitespace implements Gfs_lxr {
}
return rv;
}
public static final Gfs_lxr_whitespace Instance = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
public static final Gfs_lxr_whitespace Instance = new Gfs_lxr_whitespace(); Gfs_lxr_whitespace() {}
}
class Gfs_lxr_comment_flat implements Gfs_lxr {
public Gfs_lxr_comment_flat(byte[] bgn_bry, byte[] end_bry) {
@ -69,7 +69,7 @@ class Gfs_lxr_identifier implements Gfs_lxr {
int pos, rv = Gfs_lxr_.Rv_eos;
for (pos = end; pos < src_len; pos++) {
byte b = src[pos];
Object o = ctx.Trie().Match_bgn_w_byte(b, src, pos, src_len);
Object o = ctx.Trie().Match_at_w_b0(ctx.Trie_rv(), b, src, pos, src_len);
if (o == null) { // invalid char; stop;
rv = Gfs_lxr_.Rv_null;
ctx.Process_null(pos);
@ -89,7 +89,7 @@ class Gfs_lxr_identifier implements Gfs_lxr {
if (rv == Gfs_lxr_.Rv_eos) ctx.Process_eos(); // eos
return rv;
}
public static final Gfs_lxr_identifier Instance = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
public static final Gfs_lxr_identifier Instance = new Gfs_lxr_identifier(); Gfs_lxr_identifier() {}
}
class Gfs_lxr_semic implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_semic;}
@ -103,7 +103,7 @@ class Gfs_lxr_semic implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_semic Instance = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
public static final Gfs_lxr_semic Instance = new Gfs_lxr_semic(); Gfs_lxr_semic() {}
}
class Gfs_lxr_dot implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_dot;}
@ -115,7 +115,7 @@ class Gfs_lxr_dot implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_dot Instance = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
public static final Gfs_lxr_dot Instance = new Gfs_lxr_dot(); Gfs_lxr_dot() {}
}
class Gfs_lxr_paren_bgn implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_bgn;}
@ -126,7 +126,7 @@ class Gfs_lxr_paren_bgn implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_paren_bgn Instance = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
public static final Gfs_lxr_paren_bgn Instance = new Gfs_lxr_paren_bgn(); Gfs_lxr_paren_bgn() {}
}
class Gfs_lxr_paren_end implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_paren_end;}
@ -139,7 +139,7 @@ class Gfs_lxr_paren_end implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_paren_end Instance = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
public static final Gfs_lxr_paren_end Instance = new Gfs_lxr_paren_end(); Gfs_lxr_paren_end() {}
}
class Gfs_lxr_quote implements Gfs_lxr {
public Gfs_lxr_quote(byte[] bgn_bry, byte[] end_bry) {
@ -184,7 +184,7 @@ class Gfs_lxr_curly_bgn implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_curly_bgn Instance = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
public static final Gfs_lxr_curly_bgn Instance = new Gfs_lxr_curly_bgn(); Gfs_lxr_curly_bgn() {}
}
class Gfs_lxr_curly_end implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_curly_end;}
@ -192,7 +192,7 @@ class Gfs_lxr_curly_end implements Gfs_lxr {
ctx.Stack_pop(bgn);
return end;
}
public static final Gfs_lxr_curly_end Instance = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
public static final Gfs_lxr_curly_end Instance = new Gfs_lxr_curly_end(); Gfs_lxr_curly_end() {}
}
class Gfs_lxr_equal implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_eq;}
@ -200,7 +200,7 @@ class Gfs_lxr_equal implements Gfs_lxr {
ctx.Make_nde(bgn, end).Op_tid_(Gfs_nde.Op_tid_assign);
return end;
}
public static final Gfs_lxr_equal Instance = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
public static final Gfs_lxr_equal Instance = new Gfs_lxr_equal(); Gfs_lxr_equal() {}
}
class Gfs_lxr_comma implements Gfs_lxr {
public int Lxr_tid() {return Gfs_lxr_.Tid_comma;}
@ -210,5 +210,5 @@ class Gfs_lxr_comma implements Gfs_lxr {
}
return end;
}
public static final Gfs_lxr_comma Instance = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
public static final Gfs_lxr_comma Instance = new Gfs_lxr_comma(); Gfs_lxr_comma() {}
}

@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import gplx.core.btries.*;
public class Gfs_parser {
Btrie_fast_mgr trie = Gfs_parser_.trie_();
Gfs_parser_ctx ctx = new Gfs_parser_ctx();
private final Btrie_fast_mgr trie = Gfs_parser_.trie_();
private final Gfs_parser_ctx ctx = new Gfs_parser_ctx();
public Gfs_nde Parse(byte[] src) {
ctx.Root().Subs_clear();
int src_len = src.length; if (src_len == 0) return ctx.Root();
@ -27,13 +27,13 @@ public class Gfs_parser {
int pos = 0;
while (pos < src_len) {
byte b = src[pos];
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
Object o = trie.Match_at_w_b0(ctx.Trie_rv(), b, src, pos, src_len);
if (o == null)
ctx.Err_mgr().Fail_unknown_char(ctx, pos, b);
else {
Gfs_lxr lxr = (Gfs_lxr)o;
while (lxr != null) {
int rslt = lxr.Process(ctx, pos, trie.Match_pos());
int rslt = lxr.Process(ctx, pos, ctx.Trie_rv().Pos());
switch (lxr.Lxr_tid()) {
case Gfs_lxr_.Tid_whitespace: break;
case Gfs_lxr_.Tid_comment: break;

@ -19,6 +19,7 @@ package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import gplx.core.btries.*;
class Gfs_parser_ctx {
public Btrie_fast_mgr Trie() {return trie;} Btrie_fast_mgr trie;
public Btrie_rv Trie_rv() {return trie_rv;} private final Btrie_rv trie_rv = new Btrie_rv();
public Gfs_nde Root() {return root;} Gfs_nde root = new Gfs_nde();
public byte[] Src() {return src;} private byte[] src;
public int Src_len() {return src_len;} private int src_len;

@ -50,6 +50,7 @@ public class Gfh_atr_ {
, Bry__align = Bry_.new_a7("align") // HTML.v4
, Bry__bgcolor = Bry_.new_a7("bgcolor") // HTML.v4
, Bry__abbr = Bry_.new_a7("abbr") // HTML.ua
, Bry__srcset = Bry_.new_a7("srcset")
;
public static byte[] Make(Bry_bfr bfr, byte[] key, byte[] val) {
return bfr.Add_byte_space().Add(key).Add_byte_eq().Add_byte_quote().Add(val).Add_byte_quote().To_bry_and_clear();
@ -66,4 +67,9 @@ public class Gfh_atr_ {
bfr.Add_int_variable(val);
bfr.Add_byte_quote();
}
public static void Add_double(Bry_bfr bfr, byte[] key, double val) {
bfr.Add_byte_space().Add(key).Add_byte_eq().Add_byte_quote();
bfr.Add_double(val);
bfr.Add_byte_quote();
}
}

@ -65,6 +65,14 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, Id__del = 41
, Id__strike = 42
, Id__tt = 43
, Id__code = 44
, Id__wbr = 45
, Id__center = 46 // en.v:Vandalism_in_progress
, Id__dfn = 47
, Id__kbd = 48
, Id__samp = 49
, Id__ins = 50
, Id__em = 51
;
public static final byte[]
Bry__a = Bry_.new_a7("a")
@ -122,6 +130,14 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
.Add_str_int("del" , Id__del)
.Add_str_int("strike" , Id__strike)
.Add_str_int("tt" , Id__tt)
.Add_str_int("code" , Id__code)
.Add_str_int("wbr" , Id__wbr)
.Add_str_int("center" , Id__center)
.Add_str_int("dfn" , Id__dfn)
.Add_str_int("kbd" , Id__kbd)
.Add_str_int("samp" , Id__samp)
.Add_str_int("ins" , Id__ins)
.Add_str_int("em" , Id__em)
;
public static String To_str(int tid) {
switch (tid) {
@ -172,6 +188,14 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
case Id__del: return "del";
case Id__strike: return "strike";
case Id__tt: return "tt";
case Id__code: return "code";
case Id__wbr: return "wbr";
case Id__center: return "center";
case Id__dfn: return "dfn";
case Id__kbd: return "kbd";
case Id__samp: return "samp";
case Id__ins: return "ins";
case Id__em: return "em";
default: throw Err_.new_unhandled(tid);
}
}
@ -184,8 +208,7 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, I_lhs = Bry_.new_a7("<i>") , I_rhs = Bry_.new_a7("</i>")
, P_lhs = Bry_.new_a7("<p>") , P_rhs = Bry_.new_a7("</p>")
, Pre_lhs = Bry_.new_a7("<pre>") , Pre_rhs = Bry_.new_a7("</pre>")
, Div_lhs = Bry_.new_a7("<div>") , Div_rhs = Bry_.new_a7("</div>")
, Div_lhs_bgn = Bry_.new_a7("<div")
, Div_lhs = Bry_.new_a7("<div>") , Div_rhs = Bry_.new_a7("</div>") , Div_lhs_bgn = Bry_.new_a7("<div")
, Html_rhs = Bry_.new_a7("</html>")
, Head_lhs_bgn = Bry_.new_a7("<head") , Head_rhs = Bry_.new_a7("</head>")
, Style_lhs_w_type = Bry_.new_a7("<style type=\"text/css\">")
@ -195,8 +218,16 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, Span_lhs = Bry_.new_a7("<span") , Span_rhs = Bry_.new_a7("</span>")
, Strong_lhs = Bry_.new_a7("<strong>") , Strong_rhs = Bry_.new_a7("</strong>")
, Ul_lhs = Bry_.new_a7("<ul>") , Ul_rhs = Bry_.new_a7("</ul>")
, Li_lhs = Bry_.new_a7("<li>") , Li_rhs = Bry_.new_a7("</li>")
, Li_lhs_bgn = Bry_.new_a7("<li")
, Ol_lhs = Bry_.new_a7("<ol>") , Ol_rhs = Bry_.new_a7("</ol>")
, Dt_lhs = Bry_.new_a7("<dt>") , Dt_rhs = Bry_.new_a7("</dt>")
, Dd_lhs = Bry_.new_a7("<dd>") , Dd_rhs = Bry_.new_a7("</dd>")
, Dl_lhs = Bry_.new_a7("<dl>") , Dl_rhs = Bry_.new_a7("</dl>")
, Li_lhs = Bry_.new_a7("<li>") , Li_rhs = Bry_.new_a7("</li>") , Li_lhs_bgn = Bry_.new_a7("<li")
, Table_lhs = Bry_.new_a7("<table>") , Table_rhs = Bry_.new_a7("</table>") , Table_lhs_bgn = Bry_.new_a7("<table")
, Tr_lhs = Bry_.new_a7("<tr>") , Tr_rhs = Bry_.new_a7("</tr>") , Tr_lhs_bgn = Bry_.new_a7("<tr")
, Td_lhs = Bry_.new_a7("<td>") , Td_rhs = Bry_.new_a7("</td>") , Td_lhs_bgn = Bry_.new_a7("<td")
, Th_lhs = Bry_.new_a7("<th>") , Th_rhs = Bry_.new_a7("</th>") , Th_lhs_bgn = Bry_.new_a7("<th")
, Caption_lhs = Bry_.new_a7("<caption>") , Caption_rhs = Bry_.new_a7("</caption>") , Caption_lhs_bgn = Bry_.new_a7("<caption")
;
public static final String
Comm_bgn_str = "<!--"
@ -210,6 +241,8 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
Comm_bgn_len = Comm_bgn.length
, Comm_end_len = Comm_end.length
;
public static void Lhs_end_nde(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Gt);}
public static void Lhs_end_inl(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Gt);}
private static final byte[] Rhs_bgn = Bry_.new_a7("</");
public static void Bld_lhs_end_nde(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Gt);}
public static void Bld_lhs_end_inl(Bry_bfr bfr) {bfr.Add_byte(Byte_ascii.Slash).Add_byte(Byte_ascii.Gt);}
public static void Bld_rhs(Bry_bfr bfr, byte[] name) {bfr.Add(Rhs_bgn).Add(name).Add_byte(Byte_ascii.Angle_end);} // EX:"</tag_name>"
}

@ -119,9 +119,10 @@ public class Gfh_utl {
if (bry == null) return null;
boolean dirty = write_to_bfr ? true : false; // if write_to_bfr, then mark true, else bfr.Add_mid(bry, 0, i); will write whole bry again
int pos = bgn;
Btrie_rv trv = new Btrie_rv();
while (pos < end) {
byte b = bry[pos];
Object o = unescape_trie.Match_bgn_w_byte(b, bry, pos, end);
Object o = unescape_trie.Match_at_w_b0(trv, b, bry, pos, end);
if (o == null) {
if (dirty || write_to_bfr)
bfr.Add_byte(b);
@ -149,7 +150,7 @@ public class Gfh_utl {
if (dirty || write_to_bfr)
bfr.Add_byte(b);
}
pos = unescape_trie.Match_pos();
pos = trv.Pos();
}
}
if (write_to_bfr)

@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.langs.htmls.docs; import gplx.*; import gplx.langs.*; import gplx.langs.htmls.*;
import gplx.core.btries.*;
public class Gfh_doc_parser {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
private final Gfh_txt_wkr txt_wkr;
private final Btrie_rv trv = new Btrie_rv();
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
private final Gfh_txt_wkr txt_wkr;
public Gfh_doc_parser(Gfh_txt_wkr txt_wkr, Gfh_doc_wkr... wkr_ary) {
this.txt_wkr = txt_wkr;
for (Gfh_doc_wkr wkr : wkr_ary)
@ -29,7 +30,7 @@ public class Gfh_doc_parser {
int txt_bgn = -1;
int pos = src_bgn;
while (pos < src_end) {
Object o = trie.Match_bgn(src, pos, src_end);
Object o = trie.Match_at(trv, src, pos, src_end);
if (o == null) { // not a known hook; add to txt
if (txt_bgn == -1) txt_bgn = pos;
++pos;
@ -44,7 +45,7 @@ public class Gfh_doc_parser {
catch (Exception e) {
Gfh_utl.Log(e, "html parse failed", page_url, src, pos);
txt_bgn = pos; // set txt_bgn to hook_bgn which is "pos"; i.e.: txt resumes from start of failed hook
pos = trie.Match_pos(); // set pos to hook_end
pos = trv.Pos(); // set pos to hook_end
}
}
}

@ -104,6 +104,11 @@ public class Gfh_tag implements Mwh_atr_wkr {
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key); if (rv == null) return or;
return Bry_.To_int_or(src, rv.Val_bgn(), rv.Val_end(), or);
}
public double Atrs__get_as_double_or(byte[] key, double or) {
if (atrs_null) Atrs__make();
Gfh_atr rv = (Gfh_atr)atrs_hash.Get_by(key); if (rv == null) return or;
return Bry_.To_double_or(src, rv.Val_bgn(), rv.Val_end(), or);
}
public Gfh_atr Atrs__get_at(int i) {return (Gfh_atr)atrs_hash.Get_at(i);}
public Gfh_atr Atrs__get_by_or_fail(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.Y);}
public Gfh_atr Atrs__get_by_or_empty(byte[] key) {return Atrs__get_by_or_fail(key, Bool_.N);}

@ -19,7 +19,7 @@ package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gp
import gplx.core.btries.*; import gplx.xowa.parsers.amps.*;
import gplx.langs.htmls.*;
public class Gfo_url_encoder implements Url_encoder_interface {
private Gfo_url_encoder_itm[] encode_ary, decode_ary; private Gfo_url_encoder anchor_encoder = null;
private final Gfo_url_encoder_itm[] encode_ary, decode_ary; private final Gfo_url_encoder anchor_encoder;
public Gfo_url_encoder(Gfo_url_encoder_itm[] encode_ary, Gfo_url_encoder_itm[] decode_ary, Gfo_url_encoder anchor_encoder) {
this.encode_ary = encode_ary; this.decode_ary = decode_ary; this.anchor_encoder = anchor_encoder;
}
@ -50,18 +50,16 @@ public class Gfo_url_encoder implements Url_encoder_interface {
public byte[] Decode(byte[] bry, int bgn, int end) {return Decode(Bool_.N, bry, bgn, end);}
private byte[] Decode(boolean fail, byte[] bry, int bgn, int end) {Bry_bfr bfr = Bry_bfr_.Get(); Decode(bfr, fail, bry, bgn, end); return bfr.To_bry_and_rls();}
public Bry_bfr Decode(Bry_bfr bfr, boolean fail, byte[] bry, int bgn, int end) {
// synchronized (this) { // LOCK:DELETE; DATE:2016-07-06
for (int i = bgn; i < end; ++i) {
byte b = bry[i];
if (anchor_encoder != null && b == Byte_ascii.Hash) {
bfr.Add_byte(Byte_ascii.Hash);
anchor_encoder.Decode(bfr, Bool_.N, bry, i + 1, end);
break;
}
Gfo_url_encoder_itm itm = decode_ary[b & 0xff];// PATCH.JAVA:need to convert to unsigned byte
i += itm.Decode(bfr, bry, end, i, b, fail);
for (int i = bgn; i < end; ++i) {
byte b = bry[i];
if (anchor_encoder != null && b == Byte_ascii.Hash) {
bfr.Add_byte(Byte_ascii.Hash);
anchor_encoder.Decode(bfr, Bool_.N, bry, i + 1, end);
break;
}
return bfr;
// }
Gfo_url_encoder_itm itm = decode_ary[b & 0xff];// PATCH.JAVA:need to convert to unsigned byte
i += itm.Decode(bfr, bry, end, i, b, fail);
}
return bfr;
}
}

@ -25,6 +25,7 @@ public class Gfo_url_encoder_ {
, Href = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make()
, Href_wo_anchor = Gfo_url_encoder_.New__html_href_mw(Bool_.N).Make()
, Href_quotes = Gfo_url_encoder_.New__html_href_quotes().Make()
, Href_quotes_v2 = Gfo_url_encoder_.New__html_href_quotes_v2().Make()
, Href_qarg = Gfo_url_encoder_.New__html_href_qarg().Make()
, Xourl = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Init__same__many(Byte_ascii.Underline).Make()
, Http_url = Gfo_url_encoder_.New__http_url().Make()
@ -39,7 +40,7 @@ public class Gfo_url_encoder_ {
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
.Init__html_ent(Byte_ascii.Amp, Xop_amp_trie.Instance);
}
private static Gfo_url_encoder_mkr New__html_href_mw(boolean use_anchor_encoder) { // EX: "<a href='^#^'>" -> "<a href='%5E#.5E'>"; REF.MW: ";:@$!*(),/"
public static Gfo_url_encoder_mkr New__html_href_mw(boolean use_anchor_encoder) { // EX: "<a href='^#^'>" -> "<a href='%5E#.5E'>"; REF.MW: ";:@$!*(),/"
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
.Init__same__many
@ -61,6 +62,16 @@ public class Gfo_url_encoder_ {
, Byte_ascii.Question, Byte_ascii.Eq, Byte_ascii.Hash, Byte_ascii.Plus// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
);
}
private static Gfo_url_encoder_mkr New__html_href_quotes_v2() {// same as href encoder, but do not encode ?, =, #, +; also, don't encode "%" vals
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.Y)
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline)
.Init__same__many
( Byte_ascii.Semic, Byte_ascii.Colon, Byte_ascii.At, Byte_ascii.Dollar, Byte_ascii.Bang, Byte_ascii.Star
, Byte_ascii.Paren_bgn, Byte_ascii.Paren_end, Byte_ascii.Comma, Byte_ascii.Slash
, Byte_ascii.Question, Byte_ascii.Eq, Byte_ascii.Hash, Byte_ascii.Plus// NOTE: not part of wfUrlEncode; not sure where this is specified; needed for A#b
, Byte_ascii.Percent // DATE:2016-07-12
);
}
public static Gfo_url_encoder_mkr New__http_url() {
return new Gfo_url_encoder_mkr().Init(Byte_ascii.Percent).Init_common(Bool_.N)
.Init__diff__one(Byte_ascii.Space, Byte_ascii.Plus);

@ -24,15 +24,17 @@ public interface Gfo_url_encoder_itm {
class Gfo_url_encoder_itm_same implements Gfo_url_encoder_itm {
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {bfr.Add_byte(b); return 0;}
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {bfr.Add_byte(b); return 0;}
public static final Gfo_url_encoder_itm Instance = new Gfo_url_encoder_itm_same();
public static final Gfo_url_encoder_itm Instance = new Gfo_url_encoder_itm_same();
}
class Gfo_url_encoder_itm_diff implements Gfo_url_encoder_itm {
public Gfo_url_encoder_itm_diff(byte orig, byte repl) {this.orig = orig; this.repl = repl;} private byte orig, repl;
private final byte orig, repl;
public Gfo_url_encoder_itm_diff(byte orig, byte repl) {this.orig = orig; this.repl = repl;}
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {bfr.Add_byte(repl); return 0;}
public int Decode(Bry_bfr bfr, byte[] src, int end, int idx, byte b, boolean fail_when_invalid) {bfr.Add_byte(orig); return 0;}
}
class Gfo_url_encoder_itm_hex implements Gfo_url_encoder_itm {
public Gfo_url_encoder_itm_hex(byte encode_marker) {this.encode_marker = encode_marker;} private byte encode_marker;
private final byte encode_marker;
public Gfo_url_encoder_itm_hex(byte encode_marker) {this.encode_marker = encode_marker;}
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {Encode_byte(b, bfr, encode_marker); return 0;}
public static void Encode_byte(byte b, Bry_bfr bfr, byte encode_marker) {
int b_int = b & 0xFF;// PATCH.JAVA:need to convert to unsigned byte
@ -68,13 +70,14 @@ class Gfo_url_encoder_itm_hex implements Gfo_url_encoder_itm {
return 0;
}
}
public static final byte[] HexBytes = new byte[]
public static final byte[] HexBytes = new byte[]
{ Byte_ascii.Num_0, Byte_ascii.Num_1, Byte_ascii.Num_2, Byte_ascii.Num_3, Byte_ascii.Num_4, Byte_ascii.Num_5, Byte_ascii.Num_6, Byte_ascii.Num_7
, Byte_ascii.Num_8, Byte_ascii.Num_9, Byte_ascii.Ltr_A, Byte_ascii.Ltr_B, Byte_ascii.Ltr_C, Byte_ascii.Ltr_D, Byte_ascii.Ltr_E, Byte_ascii.Ltr_F
};
}
class Gfo_url_encoder_itm_html_ent implements Gfo_url_encoder_itm {
public Gfo_url_encoder_itm_html_ent(Btrie_slim_mgr amp_trie) {this.amp_trie = amp_trie;} Btrie_slim_mgr amp_trie;
private final Btrie_slim_mgr amp_trie;
public Gfo_url_encoder_itm_html_ent(Btrie_slim_mgr amp_trie) {this.amp_trie = amp_trie;}
public int Encode(Bry_bfr bfr, byte[] src, int end, int idx, byte b) {
++idx; // b is &; get next character afterwards
if (idx == end) { // & is last char; return

@ -20,7 +20,8 @@ import gplx.core.btries.*; import gplx.core.log_msgs.*;
public class Php_parser {
Php_lxr[] lxrs; int lxrs_len;
int txt_bgn; Php_tkn_txt txt_tkn;
private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci:PHP tkns are ASCII
private final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci:PHP tkns are ASCII
private final Btrie_rv trv = new Btrie_rv();
byte[] src; int src_len; Php_tkn_wkr tkn_wkr; Php_tkn_factory tkn_factory = new Php_tkn_factory(); Php_ctx ctx = new Php_ctx();
Php_parser_interrupt[] parser_interrupts = new Php_parser_interrupt[256];
public Php_parser() {
@ -71,7 +72,7 @@ public class Php_parser {
txt_tkn = null; txt_bgn = 0;
boolean loop_raw = true, loop_txt = true;
while (loop_raw) {
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
Object o = trie.Match_at_w_b0(trv, b, src, pos, src_len);
if (o == null) { // char does not hook into a lxr
loop_txt = true;
while (loop_txt) { // keep looping until end of String or parser_interrupt
@ -90,7 +91,7 @@ public class Php_parser {
if (txt_bgn != pos) // txt_bgn is set; make text tkn
Make_txt(txt_bgn, pos);
Php_lxr lxr = (Php_lxr)o;
int match_pos = trie.Match_pos();
int match_pos = trv.Pos();
int make_pos = lxr.Lxr_make(ctx, pos, match_pos);
if (make_pos == Php_parser.NotFound) {
Make_txt(txt_bgn, pos);

@ -43,7 +43,6 @@ public interface Xoa_app extends Gfo_invk {
Xof_img_mgr File__img_mgr();
Io_download_fmt File__download_fmt();
Xoh_href_parser Html__href_parser();
Xoh_href_wtr Html__href_wtr();
Xoh_lnki_bldr Html__lnki_bldr();
Xoa_css_extractor Html__css_installer();
Xoh_bridge_mgr Html__bridge_mgr();

@ -34,7 +34,7 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final String Version = "3.7.2.1";
public static final String Version = "3.7.3.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str;
public static String User_agent = "";

@ -215,14 +215,14 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
break; // flag last leaf_bgn
case Byte_ascii.Nl: // NOTE: for now, treat nl just like space; not sure if it should accept "a\nb" or "\nab"; need to handle trailing \n for "Argentina\n\n" in {{Infobox settlement|pushpin_map=Argentina|pushpin_label_position=|pushpin_map_alt=|pushpin_map_caption=Location of Salta in Argentina}};
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Cr: // added \t, \r; DATE:2013-03-27
case Byte_ascii.Underline:if (ltr_bgn != -1) add_ws = true; ++cur;//cur = ttlTrie.Match_pos();
case Byte_ascii.Underline: if (ltr_bgn != -1) add_ws = true; ++cur;
continue; // only mark add_ws if ltr_seen; this ignores ws at bgn; also, note "continue"
case Byte_ascii.Question:
if (txt_bb_len + 1 < end) // guard against trailing ? (which shouldn't happen)
qarg_bgn = txt_bb_len + 1;
break;
case Byte_ascii.Amp:
int cur2 = cur + 1;//cur = ttlTrie.Match_pos();
int cur2 = cur + 1;
if (cur2 == end) {} // guards against terminating &; EX: [[Bisc &]]; NOTE: needed b/c Match_bgn does not do bounds checking for cur in src; src[src.length] will be called when & is last character;
else {
if (trv == null) trv = new Btrie_rv();
@ -276,7 +276,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
&& src[cur + 2] == Byte_ascii.Dash
&& src[cur + 3] == Byte_ascii.Dash
) {
int cur3 = cur + 3;//cur = ttlTrie.Match_pos();
int cur3 = cur + 3;
int find = Bry_find_.Find_fwd(src, Xop_comm_lxr.End_ary, cur3, end);
if (find != -1) {
cur = find + Xop_comm_lxr.End_ary.length;

@ -22,7 +22,7 @@ import gplx.xowa.langs.*; import gplx.xowa.specials.*; import gplx.xowa.apps.cfg
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.css.*; import gplx.xowa.bldrs.installs.*;
import gplx.xowa.files.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.imgs.*;
import gplx.xowa.guis.cbks.*; import gplx.xowa.guis.tabs.*;
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.guis.*; import gplx.xowa.apps.cfgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.htmls.tocs.*; import gplx.xowa.apps.fmtrs.*; import gplx.xowa.htmls.*; import gplx.xowa.wikis.xwikis.sitelinks.*; import gplx.xowa.wikis.xwikis.parsers.*;
import gplx.xowa.wikis.*; import gplx.xowa.users.*; import gplx.xowa.guis.*; import gplx.xowa.apps.cfgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.apps.fmtrs.*; import gplx.xowa.htmls.*; import gplx.xowa.wikis.xwikis.sitelinks.*; import gplx.xowa.wikis.xwikis.parsers.*;
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.ns_files.*; import gplx.xowa.htmls.bridges.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.xndes.*;
import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.math.*;
@ -31,6 +31,7 @@ import gplx.xowa.bldrs.wms.*;
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.addons.*; import gplx.xowa.specials.mgrs.*;
public class Xoae_app implements Xoa_app, Gfo_invk {
private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
public Xoae_app(Gfo_usr_dlg usr_dlg, Xoa_app_mode mode, Io_url root_dir, Io_url wiki_dir, Io_url file_dir, Io_url user_dir, Io_url css_dir, String bin_dir_name) {
Xoa_app_.Usr_dlg_(usr_dlg);
this.mode = mode;
@ -76,7 +77,6 @@ public class Xoae_app implements Xoa_app, Gfo_invk {
public Xof_img_mgr File__img_mgr() {return file_mgr.Img_mgr();}
public Io_download_fmt File__download_fmt() {return wmf_mgr.Download_wkr().Download_xrg().Download_fmt();}
public Xoh_href_parser Html__href_parser() {return html__href_parser;} private final Xoh_href_parser html__href_parser = new Xoh_href_parser();
public Xoh_href_wtr Html__href_wtr() {return html__href_wtr;} private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
public Xoh_lnki_bldr Html__lnki_bldr() {return html__lnki_bldr;} private final Xoh_lnki_bldr html__lnki_bldr;
public Xoa_css_extractor Html__css_installer() {return html__css_installer;} private final Xoa_css_extractor html__css_installer = new Xoa_css_extractor();
public Xoh_bridge_mgr Html__bridge_mgr() {return html__bridge_mgr;} private final Xoh_bridge_mgr html__bridge_mgr;

@ -20,14 +20,14 @@ import gplx.xowa.langs.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.guis.*; import gplx.xowa.guis.views.*;
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*;
import gplx.xowa.parsers.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.tocs.*; import gplx.xowa.htmls.modules.popups.*;
import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.redirects.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.htmls.modules.popups.*;
import gplx.xowa.wikis.pages.wtxts.*; import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.redirects.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*;
public class Xoae_page implements Xoa_page {
Xoae_page(Xowe_wiki wiki, Xoa_ttl ttl) {
this.wiki = wiki; this.ttl = ttl;
this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
hdr_mgr = new Xow_hdr_mgr(this);
html.Init_by_page(ttl);
html.Toc_mgr().Init(wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), ttl.Page_db());
Ttl_(ttl);
} Xoae_page() {} // called by Empty
public Xow_wiki Wiki() {return wiki;}
@ -50,10 +50,11 @@ public class Xoae_page implements Xoa_page {
public byte Edit_mode() {return edit_mode;} private byte edit_mode; public void Edit_mode_update_() {edit_mode = Xoa_page_.Edit_mode_update;}
public Xop_root_tkn Root() {return root;} public Xoae_page Root_(Xop_root_tkn v) {root = v; return this;} private Xop_root_tkn root;
public Xopg_wtxt_data Wtxt() {return wtxt;} private final Xopg_wtxt_data wtxt = new Xopg_wtxt_data();
public Xoh_cmd_mgr Html_cmd_mgr() {return html_cmd_mgr;} private Xoh_cmd_mgr html_cmd_mgr = new Xoh_cmd_mgr();
public Xof_xfer_queue File_queue() {return file_queue;} private Xof_xfer_queue file_queue = new Xof_xfer_queue();
public List_adp File_math() {return file_math;} private List_adp file_math = List_adp_.New();
public Xow_hdr_mgr Hdr_mgr() {return hdr_mgr;} private Xow_hdr_mgr hdr_mgr;
public List_adp Lnki_list() {return lnki_list;} public void Lnki_list_(List_adp v) {this.lnki_list = v;} private List_adp lnki_list = List_adp_.New();
public Ref_itm_mgr Ref_mgr() {return ref_mgr;} private Ref_itm_mgr ref_mgr = new Ref_itm_mgr(); public void Ref_mgr_(Ref_itm_mgr v) {this.ref_mgr = v;}
public Xopg_popup_mgr Popup_mgr() {return popup_mgr;} private Xopg_popup_mgr popup_mgr = new Xopg_popup_mgr();
@ -78,13 +79,13 @@ public class Xoae_page implements Xoa_page {
return true;
} private byte[][] tmpl_stack_ary = Bry_.Ary_empty; private int tmpl_stack_ary_len = 0, tmpl_stack_ary_max = 0;
public void Clear_all() {Clear(true);}
public void Clear(boolean clear_scrib) { // NOTE: this is called post-fetch but pre-parse; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
public void Clear(boolean clear_scrib) { // NOTE: this is called post-fetch but pre-wtxt; do not clear items set by post-fetch, such as id, ttl, redirected_ttls, data_raw
db.Clear();
redirect.Clear();
html.Clear();
hdump.Clear();
wtxt.Clear();
hdr_mgr.Clear();
lnki_list.Clear();
file_math.Clear();
file_queue.Clear();

@ -103,7 +103,6 @@ public class Xop_fxt {
public Xop_tblw_td_tkn_chkr tkn_tblw_td_(int bgn, int end) {return (Xop_tblw_td_tkn_chkr)new Xop_tblw_td_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tblw_th_tkn_chkr tkn_tblw_th_(int bgn, int end) {return (Xop_tblw_th_tkn_chkr)new Xop_tblw_th_tkn_chkr().Src_rng_(bgn, end);}
public Xop_tblw_tr_tkn_chkr tkn_tblw_tr_(int bgn, int end) {return (Xop_tblw_tr_tkn_chkr)new Xop_tblw_tr_tkn_chkr().Src_rng_(bgn, end);}
public Xop_hdr_tkn_chkr tkn_hdr_(int bgn, int end, int hdr_len) {return (Xop_hdr_tkn_chkr)new Xop_hdr_tkn_chkr().Hdr_level_(hdr_len).Src_rng_(bgn, end);}
public Xop_xnde_tkn_chkr tkn_xnde_br_(int pos) {return tkn_xnde_(pos, pos).Xnde_tagId_(Xop_xnde_tag_.Tid__br);}
public Xop_xnde_tkn_chkr tkn_xnde_() {return tkn_xnde_(String_.Pos_neg1, String_.Pos_neg1);}
public Xop_xnde_tkn_chkr tkn_xnde_(int bgn, int end) {return (Xop_xnde_tkn_chkr)new Xop_xnde_tkn_chkr().Src_rng_(bgn, end);}
@ -222,7 +221,7 @@ public class Xop_fxt {
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
ctx.Page().Root_(root);
ctx.Page().Db().Text().Text_bry_(raw_bry);
return parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
return parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
}
public Xot_defn_tmpl run_Parse_tmpl(byte[] name, byte[] raw) {return parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), name, raw);}
public void Test_parse_tmpl(String raw, Tst_chkr... expd) {
@ -233,20 +232,20 @@ public class Xop_fxt {
public void Test_parse_page_tmpl_str(String raw, String expd) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
byte[] actl = parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
byte[] actl = parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
Tfds.Eq(expd, String_.new_u8(actl));
tst_Log_check();
}
public Xop_root_tkn Test_parse_page_tmpl_tkn(String raw) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
return root;
}
public void Test_parse_page_tmpl(String raw, Tst_chkr... expd_ary) {
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry);
parser.Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
Parse_chk(raw_bry, root, expd_ary);
}
public void Test_parse_page_wiki(String raw, Tst_chkr... expd_ary) {
@ -284,7 +283,7 @@ public class Xop_fxt {
public String Exec_parse_page_all_as_str(String raw) {
Xop_root_tkn root = Exec_parse_page_all_as_root(Bry_.new_u8(raw));
Bry_bfr actl_bfr = Bry_bfr_.New();
hdom_wtr.Write_all(actl_bfr, ctx, hctx, root.Root_src(), root);
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, root.Root_src(), root);
return actl_bfr.To_str_and_clear();
}
public void Hctx_(Xoh_wtr_ctx v) {hctx = v;} private Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Basic;
@ -293,7 +292,7 @@ public class Xop_fxt {
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
parser.Parse_wtxt_to_wdom(root, ctx, tkn_mkr, raw_bry, Xop_parser_.Doc_bgn_bos);
Bry_bfr actl_bfr = Bry_bfr_.New();
hdom_wtr.Write_all(actl_bfr, ctx, hctx, raw_bry, root);
hdom_wtr.Write_doc(actl_bfr, ctx, hctx, raw_bry, root);
return actl_bfr.To_str_and_clear();
}
private void Parse_chk(byte[] raw_bry, Xop_root_tkn root, Tst_chkr[] expd_ary) {
@ -375,7 +374,7 @@ public class Xop_fxt {
}
public void Test_str_full(String raw, String expd, String actl) {Tfds.Eq_str_lines(expd, actl, raw);}
private void Test_str_part_y(String actl, String... expd_parts) {
public void Test_str_part_y(String actl, String... expd_parts) {
int expd_parts_len = expd_parts.length;
for (int i = 0; i < expd_parts_len; i++) {
String expd_part = expd_parts[i];
@ -437,7 +436,7 @@ public class Xop_fxt {
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
ctx.Page().Html_data().Redlink_list().Clear();
html_wtr.Write_all(tmp_bfr, ctx, hctx, src_bry, root);
html_wtr.Write_doc(tmp_bfr, ctx, hctx, src_bry, root);
// Tfds.Dbg(tmp_bfr.To_str());
return tmp_bfr.To_str_and_clear();
}

@ -20,7 +20,7 @@ import gplx.core.primitives.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.addons.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.fsdb.meta.*; import gplx.fsdb.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.apps.urls.*;
public interface Xow_wiki extends Xow_ttl_parser, Gfo_invk {
@ -44,6 +44,7 @@ public interface Xow_wiki extends Xow_ttl_parser, Gfo_invk {
boolean Html__hdump_enabled();
Xow_hdump_mgr Html__hdump_mgr();
Xoh_page_wtr_mgr Html__wtr_mgr();
Xoh_href_wtr Html__href_wtr();
boolean Html__css_installing(); void Html__css_installing_(boolean v);
Xow_mw_parser_mgr Mw_parser_mgr();
Xow_xwiki_mgr Xwiki_mgr();

@ -22,7 +22,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.caches.*;
import gplx.xowa.users.*; import gplx.xowa.htmls.*; import gplx.xowa.users.history.*; import gplx.xowa.specials.*; import gplx.xowa.xtns.*; import gplx.xowa.wikis.dbs.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.xowa.files.exts.*;
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.ns_files.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*;
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.ns_files.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.bldrs.xmls.*; import gplx.xowa.bldrs.installs.*; import gplx.xowa.bldrs.setups.maints.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.utils.*;
import gplx.xowa.wikis.ctgs.*;
@ -101,6 +101,7 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
public Fsm_mnt_mgr File__mnt_mgr() {return file_mgr.Fsdb_mgr().Mnt_mgr();}
public boolean Html__hdump_enabled() {return html_mgr__hdump_enabled;} private boolean html_mgr__hdump_enabled = Bool_.N;
public Xoh_page_wtr_mgr Html__wtr_mgr() {return html_mgr.Page_wtr_mgr();}
public Xoh_href_wtr Html__href_wtr() {return html__href_wtr;} private final Xoh_href_wtr html__href_wtr = new Xoh_href_wtr();
public boolean Html__css_installing() {return html__css_installing;} public void Html__css_installing_(boolean v) {html__css_installing = v;} private boolean html__css_installing;
public Xow_url_parser Utl__url_parser() {return url__parser;} private final Xow_url_parser url__parser;
public Xow_mw_parser_mgr Mw_parser_mgr() {return mw_parser_mgr;} private final Xow_mw_parser_mgr mw_parser_mgr = new Xow_mw_parser_mgr();
@ -129,7 +130,7 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
public Xow_msg_mgr Msg_mgr() {return msg_mgr;} private Xow_msg_mgr msg_mgr;
public Xow_fragment_mgr Fragment_mgr() {return fragment_mgr;} private Xow_fragment_mgr fragment_mgr;
public Bfmtr_eval_wiki Eval_mgr() {return eval_mgr;} private Bfmtr_eval_wiki eval_mgr;
public Bry_bfr_mkr Utl__bfr_mkr() {return app.Utl__bfr_mkr();}
public Bry_bfr_mkr Utl__bfr_mkr() {return utl__bry_bfr_mkr;} private final Bry_bfr_mkr utl__bry_bfr_mkr = new Bry_bfr_mkr();
public byte[] Wdata_wiki_lang() {return wdata_wiki_lang;} private byte[] wdata_wiki_lang;
public void Wdata_wiki_lang_(byte[] v) {this.wdata_wiki_lang = v; Wdata_wiki_abrv_();} // TEST:
public byte[] Wdata_wiki_abrv() {return wdata_wiki_abrv;} private byte[] wdata_wiki_abrv; private int wdata_wiki_tid;

@ -18,8 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.addons.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.addons.bldrs.files.cmds.*;
import gplx.xowa.addons.bldrs.mass_parses.inits.*;
import gplx.xowa.addons.bldrs.mass_parses.makes.*;
import gplx.xowa.addons.bldrs.mass_parses.inits.*; import gplx.xowa.addons.bldrs.mass_parses.parses.*; import gplx.xowa.addons.bldrs.mass_parses.makes.*;
public class Xoax_builds_files_addon implements Xoax_addon_itm, Xoax_addon_itm__bldr {
public Xob_cmd[] Bldr_cmds() {
return new Xob_cmd[]
@ -43,6 +42,7 @@ public class Xoax_builds_files_addon implements Xoax_addon_itm, Xoax_addon_itm__
, Xomp_init_cmd.Prototype
, Xomp_parse_cmd.Prototype
, Xomp_make_cmd.Prototype
};
}

@ -111,11 +111,11 @@ public class Xobldr__lnki_temp__create extends Xob_dump_mgr_base implements gplx
parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src);
else {
parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), page_src);
if ( gen_html
if ( gen_html
&& page.Redirect().Itms__len() == 0) // don't generate html for redirected pages
wiki.Html_mgr().Page_wtr_mgr().Gen(ctx.Page().Root_(root), Xopg_page_.Tid_read);
if (gen_hdump)
hdump_bldr.Insert(page.Root_(root));
hdump_bldr.Insert(ctx, page.Root_(root));
root.Clear();
}
}

@ -0,0 +1,59 @@
/*
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.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
public class Xomp_db_core {
private final Object thread_lock = new Object();
private final Io_url root_dir;
Xomp_db_core(Io_url root_dir) {
this.root_dir = root_dir;
Io_url mgr_url = root_dir.GenSubFil("xomp.sqlite3");
this.mgr_db = new Xomp_mgr_db(mgr_url);
}
public Xomp_mgr_db Mgr_db() {return mgr_db;} private Xomp_mgr_db mgr_db;
public Xomp_wkr_db Wkr_db(boolean delete, int idx) {
Io_url wkr_url = root_dir.GenSubFil_nest("xomp_" + Int_.To_str_fmt(idx, "000"), "xomp_wkr.sqlite3");
if (delete) Io_mgr.Instance.DeleteFil(wkr_url);
return new Xomp_wkr_db(idx, wkr_url);
}
public int Wkr_count() {
Io_url[] wkr_dirs = Io_mgr.Instance.QueryDir_args(root_dir).DirOnly_().ExecAsUrlAry();
return wkr_dirs.length;
}
public void Update_wkr_id(int idx, Db_conn wkr_conn) {
synchronized (thread_lock) {
Db_attach_mgr attach_mgr = new Db_attach_mgr(mgr_db.Conn(), new Db_attach_itm("wkr_db", wkr_conn));
attach_mgr.Exec_sql_w_msg("updating page_regy: wkr_id=" + idx, String_.Concat_lines_nl_skip_last // ANSI.Y
( "UPDATE xomp_page"
, "SET xomp_wkr_id = " + Int_.To_str(idx)
, ", html_len = (SELECT length(body) FROM <wkr_db>html h WHERE h.page_id = xomp_page.page_id)"
, "WHERE page_id IN (SELECT page_id FROM <wkr_db>html h)"
));
}
}
public static Xomp_db_core New__make(Xowe_wiki wiki) {
Io_url root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("tmp", "xomp");
Io_mgr.Instance.DeleteDirDeep(root_dir);
return new Xomp_db_core(root_dir);
}
public static Xomp_db_core New__load(Xowe_wiki wiki) {
Io_url root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("tmp", "xomp");
return new Xomp_db_core(root_dir);
}
}

@ -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.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
public class Xomp_mgr_db {
public Xomp_mgr_db(Io_url url) {
this.url = url;
this.conn = Db_conn_bldr.Instance.Get_or_autocreate(true, url);
this.page_tbl = new Xomp_page_tbl(conn);
}
public Io_url Url() {return url;} private Io_url url;
public Db_conn Conn() {return conn;} private Db_conn conn;
public Xomp_page_tbl Page_tbl() {return page_tbl;} private Xomp_page_tbl page_tbl;
}

@ -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.addons.bldrs.mass_parses.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
public class Xomp_page_tbl implements Db_tbl {
// private final String fld_page_id, fld_page_status, fld_page_mgr_id;
private final Db_conn conn;
public Xomp_page_tbl(Db_conn conn) {
this.conn = conn;
this.tbl_name = "xomp_page";
flds.Add_int_pkey("page_id");
flds.Add_int("page_ns");
flds.Add_byte("page_status"); // 0=wait; 1=done; 2=fail
flds.Add_int_dflt("html_len", -1);
flds.Add_int_dflt("xomp_wkr_id", -1);
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public Dbmeta_fld_list Flds() {return flds;} private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
}
public void Rls() {}
}

@ -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.mass_parses.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
import gplx.xowa.htmls.core.dbs.*;
public class Xomp_wkr_db {
public Xomp_wkr_db(int idx, Io_url url) {
this.idx = idx;
this.url = url;
this.conn = Db_conn_bldr.Instance.Get_or_autocreate(true, url);
this.html_tbl = new Xowd_html_tbl(conn);
conn.Meta_tbl_assert(html_tbl);
}
public int Idx() {return idx;} private final int idx;
public Io_url Url() {return url;} private Io_url url;
public Db_conn Conn() {return conn;} private Db_conn conn;
public Xowd_html_tbl Html_tbl() {return html_tbl;} private final Xowd_html_tbl html_tbl;
}

@ -18,35 +18,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.addons.bldrs.mass_parses.inits; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*;
import gplx.xowa.addons.bldrs.mass_parses.parses.*; import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
class Xomp_init_mgr {
private final Xow_wiki wiki;
public Xomp_init_mgr(Xow_wiki wiki) {this.wiki = wiki;}
private final Xowe_wiki wiki;
public Xomp_init_mgr(Xowe_wiki wiki) {this.wiki = wiki;}
public void Exec() {
Xob_db_file make_db = Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir());
Db_conn conn = make_db.Conn();
// init
Xomp_db_core db_core = Xomp_db_core.New__make(wiki);
Xomp_page_tbl page_tbl = db_core.Mgr_db().Page_tbl();
// make table
conn.Meta_tbl_remake(Dbmeta_tbl_itm.New("mp_page", new Dbmeta_fld_itm[]
{ Dbmeta_fld_itm.new_int("page_id").Primary_y_()
, Dbmeta_fld_itm.new_bool("page_done")
}
, Dbmeta_idx_itm.new_normal_by_tbl("mp_page", "page_id__page_done", "page_id", "page_done")
));
// rebuild table
Db_conn mgr_conn = db_core.Mgr_db().Conn();
mgr_conn.Meta_tbl_remake(page_tbl);
// fill table
Db_attach_mgr attach_mgr = new Db_attach_mgr(conn, new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn()));
Db_attach_mgr attach_mgr = new Db_attach_mgr(mgr_conn, new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn()));
int[] ns_ary = new int[] {0, 4, 14};
int len = ns_ary.length;
String sql = String_.Concat_lines_nl_skip_last
( "INSERT INTO mp_page (page_id, page_done)"
, "SELECT page_id, 0"
, "FROM <page_db>page"
, "WHERE page_namespace = {0}"
, "AND page_is_redirect = 0"
( "INSERT INTO xomp_page (page_id, page_ns, page_status, html_len, xomp_wkr_id)"
, "SELECT p.page_id, p.page_namespace, 0, 0, 0"
, "FROM <page_db>page p"
, "WHERE p.page_namespace = {0}"
, "AND p.page_is_redirect = 0"
);
for (int i = 0; i < len; ++i) {
int ns_id = ns_ary[i];
attach_mgr.Exec_sql_w_msg("adding rows for mp_page: ns=" + ns_id, sql, ns_id);// ANSI.Y
attach_mgr.Exec_sql_w_msg("adding rows for xomp_page: ns=" + ns_id, sql, ns_id);// ANSI.Y
}
}
}

@ -0,0 +1,41 @@
/*
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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*; import gplx.xowa.htmls.core.dbs.*;
import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
class Xomp_html_db_rdr {
private final Xowd_html_tbl[] src_tbls;
private final Xomp_db_core db;
public Xomp_html_db_rdr(Xowe_wiki wiki) {
this.db = Xomp_db_core.New__load(wiki);
this.src_tbls = new Xowd_html_tbl[db.Wkr_count()];
}
public void Rows__get(Xowd_html_row rv, int wkr_id, int page_id) {
Xowd_html_tbl src_tbl = src_tbls[wkr_id];
if (src_tbl == null) {
Db_conn wkr_conn = db.Wkr_db(Bool_.N, wkr_id).Conn();
src_tbl = new Xowd_html_tbl(wkr_conn);
src_tbls[wkr_id] = src_tbl;
}
src_tbl.Select_as_row(rv, page_id);
}
public void Rls() {
for (Xowd_html_tbl src_tbl : src_tbls)
src_tbl.Conn().Rls_conn();
}
}

@ -0,0 +1,66 @@
/*
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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.wikis.data.*;
class Xomp_html_db_wtr {
private final long len_max;
private final Xowe_wiki wiki; private final Xow_db_mgr db_mgr;
private long len_cur;
private Xow_db_file html_db; private Xowd_html_tbl html_tbl;
public Xomp_html_db_wtr(Xowe_wiki wiki) {
this.wiki = wiki; this.db_mgr = wiki.Data__core_mgr();
this.len_max = wiki.Appe().Api_root().Bldr().Wiki().Import().Html_db_max();
// delete all existing tbls
if (!db_mgr.Props().Layout_html().Tid_is_all())
wiki.Data__core_mgr().Dbs__delete_by_tid(Xow_db_file_.Tid__html_data);
}
public int Cur_db_id() {return html_db.Id();}
public Xowd_html_tbl Tbls__get_or_new(int ns_id, long html_len) {
long len_new = len_cur + html_len;
if (html_tbl == null || len_new > len_max) {
Commit();
this.html_db = wiki.Data__core_mgr().Dbs__get_by_tid_or_null(Xow_db_file_.Tid__html_data);
if (html_db == null) {
html_db = wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__html_data);
html_db.Conn().Txn_bgn("xomp.html_db_wtr");
this.html_tbl = new Xowd_html_tbl(html_db.Conn());
html_tbl.Create_tbl();
}
}
len_cur = len_new;
return html_tbl;
}
public void Rls() {
this.Commit();
}
private void Commit() {
if (html_tbl == null) return;
html_tbl.Conn().Txn_end();
html_tbl.Conn().Rls_conn();
// update page_ids
String sql = String_.Format(String_.Concat_lines_nl_skip_last // ANSI.Y
( "UPDATE page"
, "SET page_html_db_id = {0}"
, "WHERE page_id IN (SELECT page_id FROM <html_db>html h)"
), html_db.Id());
Db_attach_mgr attach_mgr = new Db_attach_mgr(db_mgr.Db__core().Conn(), new Db_attach_itm("html_db", html_db.Conn()));
attach_mgr.Exec_sql_w_msg("updating page_ids: " + Int_.To_str(html_db.Id()), sql);
}
}

@ -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.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xomp_make_cmd extends Xob_cmd__base {
public Xomp_make_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
Xomp_make_wkr wkr = new Xomp_make_wkr(wiki);
wkr.Exec();
}
@Override public String Cmd_key() {return BLDR_CMD_KEY;} private static final String BLDR_CMD_KEY = "wiki.mass_parse.make";
public static final Xob_cmd Prototype = new Xomp_make_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xomp_make_cmd(bldr, wiki);}
}

@ -0,0 +1,71 @@
/*
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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.core.brys.*;
import gplx.dbs.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
class Xomp_make_wkr {
private final Db_conn mgr_conn;
private final Xomp_html_db_wtr html_db_wtr;
private final Xomp_html_db_rdr html_db_rdr;
private final Int_flag_bldr src_body_flag_bldr = Xowd_html_tbl.Make_body_flag_bldr();
public Xomp_make_wkr(Xowe_wiki wiki) {
this.db = Xomp_db_core.New__load(wiki);
this.mgr_conn = db.Mgr_db().Conn();
this.html_db_rdr = new Xomp_html_db_rdr(wiki);
this.html_db_wtr = new Xomp_html_db_wtr(wiki);
}
public Xomp_db_core Db() {return db;} private Xomp_db_core db;
public void Exec() {
Xowd_html_row src_row = new Xowd_html_row();
int[] ns_ary = new int[] {0, 4, 14};
int ns_ary_len = ns_ary.length;
for (int i = 0; i < ns_ary_len; ++i) {
int ns_id = ns_ary[i];
String sql = String_.Format("SELECT * FROM xomp_page WHERE page_ns = {0} AND html_len != 0 ORDER BY page_id;", ns_id); // NOTE: html_len == 0 when page failed
int count = 0;
Db_rdr rdr = mgr_conn.Stmt_sql(sql).Exec_select__rls_auto(); // ANSI.Y
try {
while (rdr.Move_next()) {
Make_page(rdr, src_row, ns_id);
if (++count % 10000 == 0)
Gfo_usr_dlg_.Instance.Prog_many("", "", "xomp.html.insert: ns=~{0} db=~{1} count=~{2}", Int_.To_str_pad_bgn_space(ns_id, 3), Int_.To_str_pad_bgn_space(html_db_wtr.Cur_db_id(), 3), Int_.To_str_pad_bgn_space(count, 8));
}
} finally {rdr.Rls();}
}
this.Rls();
}
private void Make_page(Db_rdr rdr, Xowd_html_row src_row, int ns_id) {
// get src_row
int page_id = rdr.Read_int("page_id");
int html_len = rdr.Read_int("html_len");
int wkr_id = rdr.Read_int("xomp_wkr_id");
html_db_rdr.Rows__get(src_row, wkr_id, page_id);
src_body_flag_bldr.Decode(src_row.Body_flag());
// get trg_tbl and write
Xowd_html_tbl trg_tbl = html_db_wtr.Tbls__get_or_new(ns_id, html_len);
trg_tbl.Insert(src_row.Page_id(), src_row.Head_flag(), src_body_flag_bldr.Get_as_int(0), src_body_flag_bldr.Get_as_int(1), src_row.Display_ttl(), src_row.Content_sub(), src_row.Sidebar_div(), src_row.Body());
}
private void Rls() {
mgr_conn.Rls_conn();
html_db_rdr.Rls();
html_db_wtr.Rls();
}
}

@ -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.xowa.addons.bldrs.mass_parses.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
class Xomp_page_pool {
private final Object thread_lock = new Object();
private Xomp_page_pool_loader loader;
private List_adp pool = List_adp_.New(); private int pool_idx = 0, pool_len = 0;
private Db_conn make_conn;
private final Bry_bfr prog_bfr = Bry_bfr_.New();
private int pages_done, pages_total;
private long time_bgn, time_prv, time_done;
public void Init(Xow_wiki wiki, int num_pages_per_load) {
this.make_conn = gplx.xowa.bldrs.Xob_db_file.New__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
this.loader = new Xomp_page_pool_loader(wiki, make_conn, num_pages_per_load);
this.pages_done = 0;
this.time_bgn = this.time_prv = gplx.core.envs.Env_.TickCount();
this.pages_total = loader.Get_pending_count();
}
public boolean Empty() {return empty;} private boolean empty = false;
public void Get_next(List_adp wkr_list, int num_pages_per_wkr) {
synchronized (thread_lock) {
// pool already marked exhausted by another wkr; return;
if (empty) return;
int wkr_end = pool_idx + num_pages_per_wkr;
// need pages to fulfill request
if (wkr_end > pool_len) {
this.pool = loader.Load(pool, pool_idx, pool_len);
this.pool_idx = 0;
this.pool_len = pool.Len();
if (pool_len == 0) { // no more pages; return;
empty = true;
return;
}
wkr_end = num_pages_per_wkr; // recalc wkr_end
}
// reset wkr_end; needed for very last set
if (wkr_end >= pool_len)
wkr_end = pool_len;
// add pages to wkr_list
for (int i = pool_idx; i < wkr_end; ++i) {
Xomp_page_itm page = (Xomp_page_itm)pool.Get_at(i);
wkr_list.Add(page);
}
pool_idx = wkr_end;
}
}
public void Mark_done(int id) {
synchronized (thread_lock) {
pages_done += 1;
if (pages_done % 1000 == 0) {
long time_cur = gplx.core.envs.Env_.TickCount();
int pages_left = pages_total - pages_done;
time_done += (time_cur - time_prv);
double rate_cur = pages_done / (time_done / Time_span_.Ratio_f_to_s);
String time_past = gplx.xowa.addons.bldrs.centrals.utils.Time_dhms_.To_str(prog_bfr, (int)((time_cur - time_bgn) / 1000), true, 0);
String time_left = gplx.xowa.addons.bldrs.centrals.utils.Time_dhms_.To_str(prog_bfr, (int)(pages_left / rate_cur), true, 0);
Gfo_usr_dlg_.Instance.Prog_many("", "", "done=~{0} left=~{1} rate=~{2} time_past=~{3} time_left=~{4}", pages_done, pages_left, (int)rate_cur, time_past, time_left);
time_prv = time_cur;
}
}
}
public void Rls() {
make_conn.Rls_conn();
}
}

@ -15,16 +15,15 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.htmls.core.bldrs.*; import gplx.xowa.htmls.core.dbs.*;
class Xob_hdump_tbl_retriever__xomp implements Xob_hdump_tbl_retriever {
private final Db_conn conn;
private final Xowd_html_tbl tbl;
public Xob_hdump_tbl_retriever__xomp(Db_conn conn) {
this.conn = conn;
this.tbl = new Xowd_html_tbl(conn);
conn.Meta_tbl_assert(tbl);
public Xob_hdump_tbl_retriever__xomp(Xowd_html_tbl tbl) {
this.tbl = tbl;
this.conn = tbl.Conn();
}
public Xowd_html_tbl Get_html_tbl(Xow_ns ns, int prv_row_len) {
return tbl;

@ -0,0 +1,126 @@
/*
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*; import gplx.core.threads.utils.*;
class Xomp_load_wkr implements Gfo_invk {
private final Object thread_lock = new Object();
private final Xow_wiki wiki;
private final Db_conn mgr_conn;
private final Db_attach_mgr attach_mgr;
private final Gfo_blocking_queue queue;
private final int num_wkrs;
private final Bry_bfr prog_bfr = Bry_bfr_.New();
private int pages_done, pages_total;
private long time_bgn, time_prv, time_done;
public Xomp_load_wkr(Xow_wiki wiki, Db_conn mgr_conn, int num_pages_in_pool, int num_wkrs) {
this.wiki = wiki;
this.mgr_conn = mgr_conn;
this.attach_mgr = new Db_attach_mgr(mgr_conn);
this.queue = new Gfo_blocking_queue(num_pages_in_pool);
this.num_wkrs = num_wkrs;
this.time_bgn = this.time_prv = gplx.core.envs.Env_.TickCount();
this.pages_total = this.Get_pending_count();
}
public int Get_pending_count() {
Db_rdr rdr = mgr_conn.Stmt_sql("SELECT Count(*) AS Count_of FROM xomp_page mp WHERE mp.page_status = 0").Exec_select__rls_auto();
try {return rdr.Move_next() ? rdr.Read_int("Count_of") : 0;}
finally {rdr.Rls();}
}
public Xomp_page_itm Take() {return (Xomp_page_itm)queue.Take();}
private void Exec() {
int prv_page_id = 0;
while (prv_page_id != -1) {
prv_page_id = Load_pages(prv_page_id);
}
for (int i = 0; i < num_wkrs; ++i)
queue.Put(Xomp_page_itm.Null);
}
private int Load_pages(int prv_page_id) {
// page_tbl.prep_sql
String sql = String_.Format(String_.Concat_lines_nl_skip_last // ANSI.Y
( "SELECT mp.page_id"
, ", pp.page_namespace"
, ", pp.page_title"
, ", pp.page_text_db_id"
, "FROM xomp_page mp"
, " JOIN <page_db>page pp ON mp.page_id = pp.page_id"
, "WHERE mp.page_id > {0}"
, "AND mp.page_status = 0"
, "LIMIT {1}"
), prv_page_id, queue.Capacity());
this.attach_mgr.Conn_others_(new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn()));
sql = attach_mgr.Resolve_sql(sql);
// page_tbl.load_sql
Xomp_text_db_loader text_db_loader = new Xomp_text_db_loader(wiki);
attach_mgr.Attach();
Db_rdr rdr = mgr_conn.Stmt_sql(sql).Exec_select__rls_auto();
List_adp list = List_adp_.New();
int count = 0;
try {
while (rdr.Move_next()) {
prv_page_id = rdr.Read_int("page_id");
int text_db_id = rdr.Read_int("page_text_db_id");
Xomp_page_itm ppg = new Xomp_page_itm(prv_page_id);
ppg.Init_by_page
( rdr.Read_int("page_namespace")
, rdr.Read_bry_by_str("page_title")
, text_db_id
);
list.Add(ppg);
text_db_loader.Add(text_db_id, ppg);
++count;
}
} finally {rdr.Rls();}
attach_mgr.Detach();
text_db_loader.Load();
int len = list.Len();
for (int i = 0; i < len; ++i) {
queue.Put((Xomp_page_itm)list.Get_at(i));
}
return count == 0 ? -1 : prv_page_id;
}
public void Mark_done(int id) {
synchronized (thread_lock) {
pages_done += 1;
if (pages_done % 1000 == 0) {
long time_cur = gplx.core.envs.Env_.TickCount();
int pages_left = pages_total - pages_done;
time_done += (time_cur - time_prv);
double rate_cur = pages_done / (time_done / Time_span_.Ratio_f_to_s);
String time_past = gplx.xowa.addons.bldrs.centrals.utils.Time_dhms_.To_str(prog_bfr, (int)((time_cur - time_bgn) / 1000), true, 0);
String time_left = gplx.xowa.addons.bldrs.centrals.utils.Time_dhms_.To_str(prog_bfr, (int)(pages_left / rate_cur), true, 0);
Gfo_usr_dlg_.Instance.Prog_many("", "", "done=~{0} left=~{1} rate=~{2} time_past=~{3} time_left=~{4}", pages_done, pages_left, (int)rate_cur, time_past, time_left);
time_prv = time_cur;
}
}
}
public void Rls() {
mgr_conn.Rls_conn();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__exec)) this.Exec();
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final String Invk__exec = "exec";
}

@ -15,8 +15,9 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
class Xomp_page_itm {
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.xowa.wikis.data.tbls.*;
class Xomp_page_itm implements Xowd_text_bry_owner {
public Xomp_page_itm(int id) {this.id = id;}
public int Id() {return id;} private final int id;
public int Ns_id() {return ns_id;} private int ns_id;
@ -29,9 +30,9 @@ class Xomp_page_itm {
this.ttl_bry = ttl_bry;
this.text_db_id = text_db_id;
}
public void Init_by_text(byte[] text) {
this.text = text;
}
public int Page_id() {return id;}
public void Set_text_bry_by_db(byte[] v) {this.text = v;}
public static final Xomp_page_itm Null = new Xomp_page_itm(-1);
}

@ -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.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
class Xomp_page_pool {
private final Object thread_lock = new Object();
private final Xomp_page_pool_loader loader;
private final int num_pages_per_wkr;
private List_adp pool = List_adp_.New(); private int pool_idx = 0, pool_len = 0;
public Xomp_page_pool(Xomp_page_pool_loader loader, int num_pages_per_wkr) {
this.loader = loader; this.num_pages_per_wkr = num_pages_per_wkr;
}
public boolean Empty() {synchronized (thread_lock) {return empty;}} private boolean empty = false;
public void Get_next(List_adp wkr_list) {
synchronized (thread_lock) {
// pool already marked exhausted by another wkr; return;
if (empty) return;
int wkr_end = pool_idx + num_pages_per_wkr;
// need pages to fulfill request
if (wkr_end > pool_len) {
this.pool = loader.Load(pool, pool_idx, pool_len);
this.pool_idx = 0;
this.pool_len = pool.Len();
if (pool_len == 0) { // no more pages; return;
empty = true;
return;
}
wkr_end = num_pages_per_wkr; // recalc wkr_end
}
// reset wkr_end; needed for very last set
if (wkr_end >= pool_len)
wkr_end = pool_len;
// add pages to wkr_list
for (int i = pool_idx; i < wkr_end; ++i) {
Xomp_page_itm page = (Xomp_page_itm)pool.Get_at(i);
wkr_list.Add(page);
}
pool_idx = wkr_end;
}
}
public void Rls() {
loader.Conn().Rls_conn();
}
}

@ -15,22 +15,22 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
class Xomp_page_pool_loader {
private final Xow_wiki wiki;
private int prv_page_id = -1;
private final Db_conn make_conn;
private final int num_pages_per_load;
private final Db_attach_mgr attach_mgr;
private int prv_page_id = -1;
public Xomp_page_pool_loader(Xow_wiki wiki, Db_conn make_conn, int num_pages_per_load) {
this.wiki = wiki;
this.make_conn = make_conn;
this.attach_mgr = new Db_attach_mgr(make_conn);
this.num_pages_per_load = num_pages_per_load;
}
public Db_conn Conn() {return make_conn;} private final Db_conn make_conn;
public int Get_pending_count() {
Db_rdr rdr = make_conn.Stmt_sql("SELECT Count(*) AS Count_of FROM mp_page mp WHERE mp.page_done = 0").Exec_select__rls_auto();
Db_rdr rdr = make_conn.Stmt_sql("SELECT Count(*) AS Count_of FROM xomp_page mp WHERE mp.page_status = 0").Exec_select__rls_auto();
try {
return rdr.Move_next() ? rdr.Read_int("Count_of") : 0;
} finally {rdr.Rls();}
@ -53,10 +53,10 @@ class Xomp_page_pool_loader {
, ", pp.page_namespace"
, ", pp.page_title"
, ", pp.page_text_db_id"
, "FROM mp_page mp"
, "FROM xomp_page mp"
, " JOIN <page_db>page pp ON mp.page_id = pp.page_id"
, "WHERE mp.page_id > {0}"
, "AND mp.page_done = 0"
, "AND mp.page_status = 0"
, "LIMIT {1}"
), prv_page_id, num_pages_per_load);
this.attach_mgr.Conn_others_(new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn()));

@ -15,7 +15,7 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xomp_parse_cmd extends Xob_cmd__base {
private final Xomp_parse_mgr mgr = new Xomp_parse_mgr();

@ -15,24 +15,38 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.core.threads.*;
import gplx.xowa.langs.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.core.threads.*; import gplx.core.threads.utils.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*;
import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
import gplx.xowa.wikis.caches.*;
class Xomp_parse_mgr {
private final Xomp_page_pool page_pool = new Xomp_page_pool();
private Gfo_countdown_latch latch;
public Xomp_parse_mgr_cfg Cfg() {return cfg;} private final Xomp_parse_mgr_cfg cfg = new Xomp_parse_mgr_cfg();
private int wkrs_done;
public void Wkrs_done_add_1() {synchronized (page_pool) {++wkrs_done;}}
public Xomp_db_core Db_core() {return db_core;} private Xomp_db_core db_core;
public Xomp_prog_mgr Prog_mgr() {return prog_mgr;} private final Xomp_prog_mgr prog_mgr = new Xomp_prog_mgr();
public void Wkrs_done_add_1() {latch.Countdown();}
public void Run(Xowe_wiki wiki) {
// init pool
// init db, pool_loader, pool, prog_mgr
cfg.Init(wiki);
page_pool.Init(wiki, cfg.Num_pages_in_pool());
this.db_core = Xomp_db_core.New__load(wiki);
Xomp_page_pool_loader pool_loader = new Xomp_page_pool_loader(wiki, db_core.Mgr_db().Conn(), cfg.Num_pages_in_pool());
Xomp_page_pool page_pool = new Xomp_page_pool(pool_loader, cfg.Num_pages_per_wkr());
prog_mgr.Init(pool_loader.Get_pending_count());
Xow_page_cache page_cache = Xomp_tmpl_cache_bldr.New(wiki, true);
wiki.App().User().User_db_mgr().Cache_mgr().Enabled_n_(); // disable db lookups of cache
// init threads
// load_wkr: init and start
// Xomp_load_wkr load_wkr = new Xomp_load_wkr(wiki, db_core.Mgr_db().Conn(), cfg.Num_pages_in_pool(), cfg.Num_wkrs());
// Thread_adp_.Start_by_key("xomp.load", Cancelable_.Never, load_wkr, Xomp_load_wkr.Invk__exec);
// init parse_wkrs
int wkr_len = cfg.Num_wkrs();
latch = new Gfo_countdown_latch(wkr_len);
Xomp_parse_wkr[] wkrs = new Xomp_parse_wkr[wkr_len];
for (int i = 0; i < wkr_len; ++i) {
Xomp_parse_wkr wkr = new Xomp_parse_wkr(this, Clone_wiki(wiki), page_pool, i, cfg.Num_pages_per_wkr());
Xomp_parse_wkr wkr = new Xomp_parse_wkr(this, Clone_wiki(wiki), page_pool, i);
wkr.Wiki().Cache_mgr().Page_cache_(page_cache);
wkrs[i] = wkr;
}
@ -43,12 +57,7 @@ class Xomp_parse_mgr {
}
// wait until wkrs are wkrs_done
while (true) {
synchronized (page_pool) {
if (wkrs_done == wkr_len) break;
}
Thread_adp_.Sleep(1000);
}
latch.Await();
page_pool.Rls();
// print stats
@ -61,7 +70,7 @@ class Xomp_parse_mgr {
private static Xowe_wiki Clone_wiki(Xowe_wiki wiki) {
Xol_lang_itm lang = new Xol_lang_itm(wiki.App().Lang_mgr(), wiki.Lang().Key_bry());
Xol_lang_itm_.Lang_init(lang);
Xowe_wiki rv = new Xowe_wiki(wiki.Appe(), lang, wiki.Ns_mgr(), wiki.Domain_itm(), wiki.Fsys_mgr().Root_dir());
Xowe_wiki rv = new Xowe_wiki(wiki.Appe(), lang, gplx.xowa.wikis.nss.Xow_ns_mgr_.default_(lang.Case_mgr()), wiki.Domain_itm(), wiki.Fsys_mgr().Root_dir());
rv.Init_by_wiki();
return rv;
}

@ -15,14 +15,14 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
class Xomp_parse_mgr_cfg implements Gfo_invk {
public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
// public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
public int Num_wkrs() {return num_wkrs;} private int num_wkrs = -1;
public int Num_pages_in_pool() {return num_pages_in_pool;} private int num_pages_in_pool = 1000;
public int Num_pages_per_wkr() {return num_pages_per_wkr;} private int num_pages_per_wkr = 1000;
public void Init(Xowe_wiki wiki) {
if (root_dir == null) root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("tmp", "xomp");
// if (root_dir == null) root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("tmp", "xomp");
if (num_wkrs == -1) num_wkrs = gplx.core.envs.Env_.System_cpu_count();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
@ -30,11 +30,11 @@ class Xomp_parse_mgr_cfg implements Gfo_invk {
else if (ctx.Match(k, Invk__num_pages_in_pool_)) num_pages_in_pool = m.ReadInt("v");
else if (ctx.Match(k, Invk__num_pages_per_wkr_)) num_pages_per_wkr = m.ReadInt("v");
else if (ctx.Match(k, Invk__num_pages_per_wkr_)) num_pages_per_wkr = m.ReadInt("v");
else if (ctx.Match(k, Invk__root_dir_)) root_dir = m.ReadIoUrl("v");
// else if (ctx.Match(k, Invk__root_dir_)) root_dir = m.ReadIoUrl("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk__num_wkrs_ = "num_wkrs_", Invk__num_pages_in_pool_ = "num_pages_in_pool_", Invk__num_pages_per_wkr_ = "num_pages_per_wkr_"
, Invk__root_dir_ = "root_dir_"
// , Invk__root_dir_ = "root_dir_"
;
}

@ -15,33 +15,33 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.mass_parses.dbs.*;
import gplx.xowa.htmls.core.bldrs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.parsers.*;
class Xomp_parse_wkr implements Gfo_invk {
private final Xomp_parse_mgr mgr;
private final Xowe_wiki wiki;
private final Xomp_parse_mgr mgr;
private final Xomp_page_pool page_pool;
private final List_adp list = List_adp_.New(); private int list_idx = 0, list_len = 0;
private final int num_pages_per_wkr;
private final int idx;
private final List_adp list = List_adp_.New(); private int list_idx = 0, list_len = 0;
private final Xob_hdump_bldr hdump_bldr = new Xob_hdump_bldr();
// private boolean gen_html = true;// gen_hdump = true;
private int done_count; private long done_time;
public Xomp_parse_wkr(Xomp_parse_mgr mgr, Xowe_wiki wiki, Xomp_page_pool page_pool, int idx, int num_pages_per_wkr) {
private Xomp_wkr_db wkr_db;
public Xomp_parse_wkr(Xomp_parse_mgr mgr, Xowe_wiki wiki, Xomp_page_pool page_pool, int idx) {
this.mgr = mgr; this.wiki = wiki;
this.page_pool = page_pool; this.num_pages_per_wkr = num_pages_per_wkr;
this.page_pool = page_pool;
this.idx = idx;
this.wkr_db = mgr.Db_core().Wkr_db(Bool_.Y, idx); // NOTE: must go in ctor, or else thread issues
}
public Xowe_wiki Wiki() {return wiki;} private final Xowe_wiki wiki;
public void Exec() {
// init
Db_conn wkr_conn = Db_conn_bldr.Instance.Get_or_autocreate(true, mgr.Cfg().Root_dir().GenSubFil_nest("xomp_" + Int_.To_str_fmt(idx, "000"), "xomp_wkr.sqlite3"));
Xow_parser_mgr parser = new Xow_parser_mgr(wiki);
Xow_parser_mgr parser_mgr = new Xow_parser_mgr(wiki);
wiki.Html_mgr().Page_wtr_mgr().Wkr(gplx.xowa.wikis.pages.Xopg_page_.Tid_read).Ctgs_enabled_(false); // disable categories else progress messages written (also for PERF)
if (wiki.File__bin_mgr() != null)
wiki.File__bin_mgr().Wkrs__del(gplx.xowa.files.bins.Xof_bin_wkr_.Key_http_wmf); // remove wmf wkr, else will try to download images during parsing
hdump_bldr.Init(wiki, wkr_conn, new Xob_hdump_tbl_retriever__xomp(wkr_conn));
hdump_bldr.Enabled_(true).Hzip_enabled_(true).Hzip_diff_(true).Init(wiki, wkr_db.Conn(), new Xob_hdump_tbl_retriever__xomp(wkr_db.Html_tbl()));
wkr_db.Conn().Txn_bgn("xomp");
while (true) {
Xomp_page_itm ppg = Get_next(); if (ppg == Xomp_page_itm.Null) break; // no more pages
@ -56,18 +56,15 @@ class Xomp_parse_wkr implements Gfo_invk {
wpg.Db().Page().Id_(ppg.Id());
// parse page
parser.Ctx().Clear_all();
parser.Parse(wpg, true);
Xop_ctx pctx = parser_mgr.Ctx();
pctx.Clear_all();
parser_mgr.Parse(wpg, true);
// gen_html
// if ( gen_html
// && wpg.Redirect().Itms__len() == 0) // don't generate html for redirected pages
// wiki.Html_mgr().Page_wtr_mgr().Gen(wpg, gplx.xowa.wikis.pages.Xopg_page_.Tid_read);
// if (gen_hdump)
// hdump_bldr.Insert(wpg);
hdump_bldr.Insert(pctx, wpg);
// mark done for sake of progress
page_pool.Mark_done(ppg.Id());
mgr.Prog_mgr().Mark_done(ppg.Id());
// update stats
long time_cur = gplx.core.envs.Env_.TickCount();
@ -80,15 +77,17 @@ class Xomp_parse_wkr implements Gfo_invk {
if (wiki.Cache_mgr().Tmpl_result_cache().Count() > 50000)
wiki.Cache_mgr().Tmpl_result_cache().Clear();
if (done_count % 50 == 0) {
wiki.Cache_mgr().Free_mem_all();
wiki.Cache_mgr().Free_mem_all(Bool_.N);
wiki.Parser_mgr().Scrib().Core_term();
}
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "mass_parse.fail:ns=~{0} ttl=~{1} err=~{2}", ppg.Ns_id(), ppg.Ttl_bry(), Err_.Message_gplx_log(e));
}
}
wkr_db.Conn().Txn_end(); // NOTE: must end txn before running update wkr_id
mgr.Db_core().Update_wkr_id(idx, wkr_db.Conn());
mgr.Wkrs_done_add_1();
wkr_conn.Rls_conn();
wkr_db.Conn().Rls_conn();
}
public void Bld_stats(Bry_bfr bfr) {
int done_time_in_sec = (int)(done_time / 1000); if (done_time_in_sec == 0) done_time_in_sec = 1;
@ -101,7 +100,7 @@ class Xomp_parse_wkr implements Gfo_invk {
private Xomp_page_itm Get_next() {
if (list_idx == list_len) {
list.Clear();
page_pool.Get_next(list, num_pages_per_wkr);
page_pool.Get_next(list);
list_len = list.Len();
if (list_len == 0) return Xomp_page_itm.Null;
list_idx = 0;

@ -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.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
class Xomp_prog_mgr {
private final Object thread_lock = new Object();
private int pages_done, pages_total;
private long time_bgn, time_prv, time_done;
private final Bry_bfr prog_bfr = Bry_bfr_.New();
public void Init(int pages_total) {
this.time_bgn = this.time_prv = gplx.core.envs.Env_.TickCount();
this.pages_total = pages_total;
}
public void Mark_done(int id) {
synchronized (thread_lock) {
pages_done += 1;
if (pages_done % 1000 == 0) {
long time_cur = gplx.core.envs.Env_.TickCount();
int pages_left = pages_total - pages_done;
time_done += (time_cur - time_prv);
double rate_cur = pages_done / (time_done / Time_span_.Ratio_f_to_s);
String time_past = gplx.xowa.addons.bldrs.centrals.utils.Time_dhms_.To_str(prog_bfr, (int)((time_cur - time_bgn) / 1000), true, 0);
String time_left = gplx.xowa.addons.bldrs.centrals.utils.Time_dhms_.To_str(prog_bfr, (int)(pages_left / rate_cur), true, 0);
Gfo_usr_dlg_.Instance.Prog_many("", "", "done=~{1} left=~{2} rate=~{3} time_past=~{4} time_left=~{5}", id, pages_done, pages_left, (int)rate_cur, time_past, time_left);
time_prv = time_cur;
}
}
}
}

@ -15,9 +15,10 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
package gplx.xowa.addons.bldrs.mass_parses.parses; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
import gplx.core.ios.*;
import gplx.xowa.wikis.data.tbls.*;
class Xomp_text_db_loader {
private final Xow_wiki wiki;
private final Ordered_hash text_db_hash = Ordered_hash_.New();
@ -25,7 +26,7 @@ class Xomp_text_db_loader {
public Xomp_text_db_loader(Xow_wiki wiki) {
this.wiki = wiki;
}
public void Add(int text_db_id, Xomp_page_itm ppg) {
public void Add(int text_db_id, Xowd_text_bry_owner ppg) {
Xomp_text_db_itm itm = (Xomp_text_db_itm)text_db_hash.Get_by(text_db_id);
if (itm == null) {
itm = new Xomp_text_db_itm(text_db_id);
@ -53,8 +54,8 @@ class Xomp_text_db_loader {
}
// build WHERE IN for page_ids; EX: "1, 2, 3, 4"
Xomp_page_itm ppg = (Xomp_page_itm)list.Get_at(i);
int page_id = ppg.Id();
Xowd_text_bry_owner ppg = (Xowd_text_bry_owner)list.Get_at(i);
int page_id = ppg.Page_id();
if (batch_idx != 0) bry.Add_byte_comma();
bry.Add_int_variable(page_id);
page_hash.Add(page_id, ppg);
@ -77,8 +78,8 @@ class Xomp_text_db_loader {
int page_id = rdr.Read_int("page_id");
byte[] text_data = rdr.Read_bry("text_data");
text_data = zip_mgr.Unzip(zip_tid, text_data);
Xomp_page_itm ppg = (Xomp_page_itm)page_hash.Get_by(page_id);
ppg.Init_by_text(text_data);
Xowd_text_bry_owner ppg = (Xowd_text_bry_owner)page_hash.Get_by(page_id);
ppg.Set_text_bry_by_db(text_data);
}
}
finally {

@ -0,0 +1,81 @@
/*
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.mass_parses.*;
import gplx.dbs.*;
import gplx.xowa.wikis.caches.*;
class Xomp_tmpl_cache_bldr {
public static Xow_page_cache New(Xowe_wiki wiki, boolean fill_all) {
Xow_page_cache rv = new Xow_page_cache(wiki);
if (fill_all) Fill_all(rv, wiki);
return rv;
}
private static void Fill_all(Xow_page_cache cache, Xowe_wiki wiki) {
String sql = String_.Concat_lines_nl_skip_last // ANSI.Y
( "SELECT pp.page_id"
, ", pp.page_namespace"
, ", pp.page_title"
, ", pp.page_text_db_id"
, ", pp.page_redirect_id"
, "FROM page pp"
, "WHERE pp.page_namespace IN (10, 828)"
);
Xomp_text_db_loader text_db_loader = new Xomp_text_db_loader(wiki);
// load pages
int count = 0;
List_adp redirect_list = List_adp_.New();
Ordered_hash page_regy = Ordered_hash_.New();
Db_rdr rdr = wiki.Data__core_mgr().Db__core().Tbl__page().Conn().Stmt_sql(sql).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
// get ttl
Xoa_ttl page_ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
// add to text_db_loader
int page_id = rdr.Read_int("page_id");
int page_redirect_id = rdr.Read_int("page_redirect_id");
Xow_page_cache_itm itm = new Xow_page_cache_itm(page_ttl, Bry_.Empty, Bry_.Empty);
itm.Set_page_ids(page_id, page_redirect_id);
text_db_loader.Add(rdr.Read_int("page_text_db_id"), itm);
cache.Add(page_ttl.Full_db(), itm);
page_regy.Add(page_id, itm);
if (page_redirect_id != -1)
redirect_list.Add(itm);
if ((++count % 10000) == 0)
Gfo_usr_dlg_.Instance.Prog_many("", "", "loading tmpls: ~{0}", count);
}
} finally {rdr.Rls();}
// load wikitext
text_db_loader.Load();
// handle redirects
int redirect_len = redirect_list.Len();
for (int i = 0; i < redirect_len; ++i) {
Xow_page_cache_itm src_itm = (Xow_page_cache_itm)redirect_list.Get_at(i);
Xow_page_cache_itm trg_itm = (Xow_page_cache_itm)page_regy.Get_by(src_itm.Redirect_id());
if (trg_itm == null) {
Gfo_usr_dlg_.Instance.Prog_many("", "", "missing redirect for tmpl: ~{0}", src_itm.Ttl().Full_db());
continue;
}
src_itm.Set_redirect_bry(trg_itm.Wtxt__direct());
}
}
}

@ -15,31 +15,32 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.langs.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
class Xoh_toc_htmlr implements gplx.core.brys.Bfr_arg {
private final Bry_bfr bfr = Bry_bfr_.New();
private final Bry_bfr numbering_bfr = Bry_bfr_.New();
private Ordered_hash itms;
private byte[] toc_label;
private int prv_lvl;
private Ordered_hash toc_itms;
public void Clear() {
prv_lvl = 0;
}
public byte[] To_html(Ordered_hash itms, byte[] toc_title, boolean toc_mode_is_pgbnr) {
this.itms = itms;
fmtr_div.Bld_many(bfr, toc_mode_is_pgbnr ? Bry_.Empty : Bry_toc_cls, toc_title, this);
return bfr.To_bry_and_clear();
public void Init(byte[] toc_label) {
this.toc_label = toc_label;
}
public byte[] Test__to_html(Ordered_hash itms) {
this.itms = itms;
Bfr_arg__add(bfr);
return bfr.To_bry_and_clear();
public void To_html(Bry_bfr rv, Xoh_wtr_ctx hctx, Ordered_hash toc_itms, boolean toc_mode_is_pgbnr) {
this.toc_itms = toc_itms;
fmtr_div.Bld_many(rv, toc_mode_is_pgbnr ? Bry_.Empty : Bry_toc_cls, toc_label, this);
}
public void Test__to_html(Bry_bfr rv, Ordered_hash toc_itms) {
this.toc_itms = toc_itms;
Bfr_arg__add(rv);
}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = itms.Len();
int len = toc_itms.Len();
prv_lvl = 0;
for (int i = 0; i < len; ++i) {
Xoh_toc_itm itm = (Xoh_toc_itm)itms.Get_at(i);
Xoh_toc_itm itm = (Xoh_toc_itm)toc_itms.Get_at(i);
Write(bfr, itm);
}

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_htmlr__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_htmlr__basic__fxt fxt = new Xoh_toc_htmlr__basic__fxt();
@ -162,7 +162,8 @@ public class Xoh_toc_htmlr__basic__tst {
}
}
class Xoh_toc_htmlr__basic__fxt {
private final Xoh_toc_wtr wtr = new Xoh_toc_wtr();
private final Xoh_toc_mgr wtr = new Xoh_toc_mgr();
private final Bry_bfr bfr = Bry_bfr_.New();
public void Clear() {wtr.Clear();}
public void Init__add(int hdr_num, String hdr_txt) {wtr.Add(hdr_num, Bry_.new_u8(hdr_txt));}
public void Init__init_page(String toc_title, boolean page_banner) {wtr.Init(Bry_.new_u8(toc_title), Bry_.Empty);}
@ -170,6 +171,7 @@ class Xoh_toc_htmlr__basic__fxt {
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.Test__to_html())));
}
public void Test__html_div(String... expd_ary) {
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(wtr.To_html(false))));
wtr.To_html(bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, false);
Gftest.Eq__ary(expd_ary, String_.Ary(Bry_split_.Split_lines(bfr.To_bry_and_clear())));
}
}

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
public class Xoh_toc_itm {// EX: <li class="toclevel-3 tocsection-3"><a href="#aaa"><span class="tocnumber">1.1.1</span> <span class="toctext">aaa</span></a></li>
public int Uid() {return uid;} private int uid; // uid of itm; HTML: "tocsection-3"
public int Lvl() {return lvl;} private int lvl; // indent level; HTML: "toclevel-3"
@ -31,5 +31,5 @@ public class Xoh_toc_itm {// EX: <li class="toclevel-3 tocsection-3"><a href="#a
return bfr.To_bry_and_clear();
}
public void Set__lvl(int uid, int lvl, int[] path) {this.uid = uid; this.lvl = lvl; this.path = path;}
public void Set__txt(byte[] anch, byte[] text) {this.anch = anch; this.text = text;}
public Xoh_toc_itm Set__txt(byte[] anch, byte[] text) {this.anch = anch; this.text = text; return this;}
}

@ -15,37 +15,42 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.xowa.htmls.core.wkrs.tocs.*;
public class Xoh_toc_wtr {
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.tocs.*;
public class Xoh_toc_mgr {
private final Ordered_hash itms = Ordered_hash_.New_bry();
private final Xoh_toc_wkr__lvl lvl_wkr = new Xoh_toc_wkr__lvl();
private final Xoh_toc_wkr__txt txt_wkr = new Xoh_toc_wkr__txt();
private final Xoh_toc_htmlr htmlr = new Xoh_toc_htmlr();
private byte[] toc_title, page_name;
public boolean Exists() {return exists && Enabled;} private boolean exists;
public void Exists_y_() {exists = true;}
public int Toc_bgn() {return toc_bgn;} private int toc_bgn;
public void Toc_bgn_(int v) {this.toc_bgn = v;}
public void Clear() {
this.exists = false;
itms.Clear();
lvl_wkr.Clear();
txt_wkr.Clear();
htmlr.Clear();
this.exists = false;
toc_bgn = -1;
}
public boolean Exists() {return exists && Enabled;} private boolean exists;
public void Exists_y_() {exists = true;}
public void Init(byte[] toc_title, byte[] page_name) {
this.Clear();
this.toc_title = toc_title;
this.page_name = page_name;
htmlr.Init(toc_title);
txt_wkr.Init(page_name);
}
public void Add(int hdr_num, byte[] hdr_txt) {
public Xoh_toc_itm Add(int hdr_num, byte[] hdr_txt) {
Xoh_toc_itm itm = new Xoh_toc_itm();
lvl_wkr.Calc_level(itm, hdr_num);
txt_wkr.Calc_anch_text(itm, page_name, hdr_txt);
txt_wkr.Calc_anch_text(itm, hdr_txt);
itms.Add(itm.Anch(), itm);
return itm;
}
public byte[] To_html(boolean toc_mode_is_pgbnr) {return htmlr.To_html(itms, toc_title, toc_mode_is_pgbnr);}
public void To_html(Bry_bfr rv, Xoh_wtr_ctx hctx, boolean toc_mode_is_pgbnr) {htmlr.To_html(rv, hctx, itms, toc_mode_is_pgbnr);}
public byte[] Test__to_html() {
return htmlr.Test__to_html(itms);
Bry_bfr bfr = Bry_bfr_.New();
htmlr.Test__to_html(bfr, itms);
return bfr.To_bry_and_clear();
}
public static boolean Enabled = true;
public static boolean Enabled = true; // TEST
}

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
class Xoh_toc_wkr__lvl {
private static final int Toc_lvls_max = 7;
private final int[] sub_lvl_count = new int[Toc_lvls_max], lvl_count = new int[Toc_lvls_max];

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__lvl__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__lvl__fxt fxt = new Xoh_toc_wkr__lvl__fxt();

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.parsers.amps.*; import gplx.core.primitives.*;
class Xoh_toc_wkr__txt {
@ -30,13 +30,19 @@ class Xoh_toc_wkr__txt {
text_bfr.Clear();
anch_hash.Clear();
}
public void Calc_anch_text(Xoh_toc_itm rv, byte[] page_name, byte[] src) { // text within hdr; EX: <h2>Abc</h2> -> Abc
this.page_name = page_name;
public void Init(byte[] page_name) {this.page_name = page_name;}
public void Calc_anch_text(Xoh_toc_itm rv, byte[] src) { // text within hdr; EX: <h2>Abc</h2> -> Abc
int end = src.length;
src = Remove_comment(text_bfr, src, 0, end);
end = src.length;
tag_rdr.Init(page_name, src, 0, end);
Calc_anch_text_recurse(src, 0, end);
try {
Calc_anch_text_recurse(src, 0, end);
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "toc:failed while generating anch_text; page=~{0} src=~{1} err=~{2}", page_name, Err_.Message_gplx_log(e));
text_bfr.Clear().Add(src);
anch_encoder.Encode(anch_bfr, src);
}
byte[] anch_bry = anch_bfr.To_bry_and_clear_and_trim(Bool_.Y, Bool_.Y, id_trim_ary);
if (anch_hash.Has(anch_bry)) {
@ -91,10 +97,12 @@ class Xoh_toc_wkr__txt {
print_tag = Bry_.Len_gt_0(span_dir);
break;
case Gfh_tag_.Id__comment: // never print tag
case Gfh_tag_.Id__any: // all other tags never print
default:
print_tag = false;
break;
case Gfh_tag_.Id__any: // unknown tags print
print_tag = true;
break;
}
// get lhs / rhs vars

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__basic__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@ -25,6 +25,9 @@ public class Xoh_toc_wkr__txt__basic__tst {
@Test public void Ws() {
fxt.Test__both(" a b ", "a_b", "a b");
}
@Test public void Empty() { // PAGE:s.w:Colac,_Victoria DATE:2016-07-17
fxt.Test__both("", "", "");
}
@Test public void Amp__ncr() {
fxt.Test__both("&#91;a&#93;", ".5Ba.5D", "&#91;a&#93;");
}
@ -53,7 +56,7 @@ class Xoh_toc_wkr__txt__fxt {
public void Test__text(String html, String expd_text) {Test__both(html, null, expd_text);}
public void Test__both(String html, String expd) {Test__both(html, expd, expd);}
public void Test__both(String html, String expd_anch, String expd_text) {
wkr.Calc_anch_text(itm, Bry_.Empty, Bry_.new_u8(html));
wkr.Calc_anch_text(itm, Bry_.new_u8(html));
if (expd_anch != null) Gftest.Eq__str(expd_anch, itm.Anch(), "anch");
if (expd_text != null) Gftest.Eq__str(expd_text, itm.Text(), "text");
}

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__dupe__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();

@ -15,7 +15,7 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wkr__txt__xnde__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wkr__txt__fxt fxt = new Xoh_toc_wkr__txt__fxt();
@ -37,6 +37,6 @@ public class Xoh_toc_wkr__txt__xnde__tst {
@Test public void H2() {fxt.Test__both("a<h2>b</h2>c" , "abc");} // NOTE: not a valid test; MW actually generates "ab" b/c of tidy; see corresponding edit test; DATE:2016-06-28
@Test public void Li() {fxt.Test__text("a<ul><li>b</li></ul>c" , "abc");}
@Test public void Table() {fxt.Test__text("a<table><tr><td>b</td></tr></table>c" , "abc");}
@Test public void Unknown__i() {fxt.Test__both("a<unknown>b<i>c</i>d</unknown>e" , "abcde", "ab<i>c</i>de");} // PURPOSE: unknown tags should not fail; DATE:2016-07-09
@Test public void Unknown__a() {fxt.Test__both("a<unknown>b<a>c</a>d</unknown>e" , "abcde");} // PURPOSE: unknown tags should not fail; DATE:2016-07-09
@Test public void Unknown__i() {fxt.Test__both("a<unknown>b<i>c</i>d</unknown>e" , "abcde", "a<unknown>b<i>c</i>d</unknown>e");} // NOTE: technically, anch should be href_encoded a<unknown>b<i>c</i>d</unknown>e b/c <unknown> is not a valid tag; compare with known tags like <li> / <table> which are just stripped
@Test public void Unknown__a() {fxt.Test__both("a<unknown>b<a>c</a>d</unknown>e" , "abcde", "a<unknown>bcd</unknown>e");}
}

@ -15,10 +15,11 @@ 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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.core.htmls.*;
public class Xow_toc_mgr_tst {
@Before public void init() {fxt.Clear();} private final Xow_toc_mgr_fxt fxt = new Xow_toc_mgr_fxt();
package gplx.xowa.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.hdrs.*;
public class Xowe_hdr_bldr__tst {
@Before public void init() {fxt.Clear();} private final Xowe_hdr_bldr_fxt fxt = new Xowe_hdr_bldr_fxt();
@Test public void Basic() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "==a=="
@ -253,12 +254,11 @@ public class Xow_toc_mgr_tst {
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>" // NOTE: toctext should be "abc", not "ab"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='abc'>a<ul>"
, "<li>b</li></ul>c</span></h2>"
, "<h2><span class='mw-headline' id='abc'>a<ul><li>b</li></ul>c</span></h2>"
));
}
@Test public void Xnde__table() {
@ -269,18 +269,11 @@ public class Xow_toc_mgr_tst {
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.3Ctable.3E.3Ctr.3E.3Ctd.3Eb.3C.2Ftd.3E.3C.2Ftr.3E.3C.2Ftable.3Ec\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>" // NOTE: toc id should be "abc"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>" // NOTE: toc id should be "abc"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a.3Ctable.3E.3Ctr.3E.3Ctd.3Eb.3C.2Ftd.3E.3C.2Ftr.3E.3C.2Ftable.3Ec'>a"
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, "c</span></h2>"
, "<h2><span class='mw-headline' id='abc'>a<table><tr><td>b</td></tr></table>c</span></h2>"
));
}
// TOMBSTONE: on MW, shows up as 'href="#ab"; <span class="toctext">ab</span>; '; TIDY doing strange things; ignore for now; DATE:2016-06-28
@ -322,7 +315,7 @@ public class Xow_toc_mgr_tst {
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_bcd_e\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a b<small>c</small>d e</span></a>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a_bcd_e\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a <sup>bcd</sup> e</span></a>"
, " </li>"
, " </ul>"
)
@ -465,7 +458,7 @@ public class Xow_toc_mgr_tst {
, "==<translate><!--b-->ac</translate>=="
), fxt.toc_tbl_nl_y
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#.3C.21--b--.3Eac\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ac\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
, " </li>"
, " </ul>"
));
@ -478,11 +471,11 @@ public class Xow_toc_mgr_tst {
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#ab\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.5B1.5D\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a<sup>[1]</sup></span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='ab'>a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></h2>"
, "<h2><span class='mw-headline' id='a.5B1.5D'>a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></h2>"
));
}
@Test public void Category() { // PURPOSE: Category should not show in in TOC; DATE:2013-12-09
@ -523,11 +516,11 @@ public class Xow_toc_mgr_tst {
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#File:A.png_b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\"> b</span></a>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#b\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='File:A.png_b'><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b</span></h2>"
, "<h2><span class='mw-headline' id='b'><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"0\" height=\"0\" /></a> b</span></h2>"
));
}
@Test public void Lnki_invalid() { // PURPOSE: invalid lnki was causing null ref; DATE:2014-02-07
@ -554,46 +547,3 @@ public class Xow_toc_mgr_tst {
);
}
}
class Xow_toc_mgr_fxt {
private Xow_toc_mgr toc_mgr = new Xow_toc_mgr();
private Bry_bfr tmp = Bry_bfr_.New();
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
toc_mgr.Clear();
tmp.Clear();
}
public void Test_html_toc(String raw, String expd) {
toc_mgr.Clear();
byte[] raw_bry = Bry_.new_u8(raw);
Xop_root_tkn root = fxt.Ctx().Tkn_mkr().Root(raw_bry);
fxt.Parser().Parse_page_all_clear(root, fxt.Ctx(), fxt.Ctx().Tkn_mkr(), raw_bry);
toc_mgr.Html(fxt.Page(), Xoh_wtr_ctx.Basic, tmp, false);
Tfds.Eq_ary(String_.SplitLines_nl(expd), String_.SplitLines_nl(tmp.To_str_and_clear()), raw);
}
public void Test_html_all(String raw, String expd) {
expd = Xoh_consts.Escape_apos(expd);
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
toc_mgr.Clear();
fxt.Test_parse_page_all_str(raw, expd);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public void Test_html_frag(String raw, String frag) {
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
toc_mgr.Clear();
fxt.Test_html_full_frag(raw, frag);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public String toc_tbl_nl_y(String... ary) {return toc_tbl(Bool_.Y, ary);}
public String toc_tbl_nl_n(String... ary) {return toc_tbl(Bool_.N, ary);}
public String toc_tbl(boolean nl, String... ary) {
return String_.Concat_lines_nl_skip_last
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\">"
, " <h2>Contents</h2>"
, " </div>"
, String_.Concat_lines_nl_skip_last(ary)
, "</div>" + (nl ? "\n" : "")
);
}
}

@ -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.addons.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
public class Xowe_hdr_bldr_fxt {
private final Bry_bfr tmp = Bry_bfr_.New();
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
public void Clear() {
fxt.Reset();
tmp.Clear();
}
public void Test_html_toc(String raw, String expd) {
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
String actl = Bld_page_with_toc(tmp, fxt, raw);
// HACK: proc only tests TOC; remove <h#><span class="mw-> section; ugly hack, but this is only test code
int span_pos = String_.FindFwd(actl, "<span class=\"mw-");
actl = String_.Mid(actl, 0, span_pos - 5);
Tfds.Eq_str_lines(expd, actl);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public void Test_html_all(String raw, String expd) {
expd = Xoh_consts.Escape_apos(expd);
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
String actl = Bld_page_with_toc(tmp, fxt, raw);
Tfds.Eq(expd, actl);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public void Test_html_frag(String raw, String frag) {
fxt.Wtr_cfg().Toc__show_(Bool_.Y);
String actl = Bld_page_with_toc(tmp, fxt, raw);
fxt.Test_str_part_y(actl, frag);
fxt.Wtr_cfg().Toc__show_(Bool_.N);
}
public String toc_tbl_nl_y(String... ary) {return toc_tbl(Bool_.Y, ary);}
public String toc_tbl_nl_n(String... ary) {return toc_tbl(Bool_.N, ary);}
public String toc_tbl(boolean nl, String... ary) {
return String_.Concat_lines_nl_skip_last
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\">"
, " <h2>Contents</h2>"
, " </div>"
, String_.Concat_lines_nl_skip_last(ary)
, "</div>" + (nl ? "\n" : "")
);
}
public static String Bld_page_with_toc(Bry_bfr bfr, Xop_fxt fxt, String raw) {
String rv = fxt.Exec_parse_page_all_as_str(raw);
bfr.Add_str_u8(rv);
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(bfr, fxt.Page(), Xoh_wtr_ctx.Basic);
return bfr.To_str_and_clear();
}
}

@ -19,6 +19,7 @@ package gplx.xowa.addons.wikis.searchs.parsers; import gplx.*; import gplx.xowa.
import gplx.core.btries.*; import gplx.xowa.langs.cases.*;
public class Srch_text_parser {
private Btrie_slim_mgr parser_trie = Btrie_slim_mgr.cs(); public Btrie_slim_mgr word_end_trie = Btrie_slim_mgr.cs(); private Btrie_slim_mgr word_bgn_trie = Btrie_slim_mgr.cs();
private final Btrie_rv trv = new Btrie_rv();
private Xol_case_mgr case_mgr;
public final Bry_bfr Tmp_bfr = Bry_bfr_.New_w_size(32);
private byte[] src; private int end;
@ -87,14 +88,14 @@ public class Srch_text_parser {
break;
}
byte b = src[pos];
Object o = parser_trie.Match_bgn_w_byte(b, src, pos, end);
Object o = parser_trie.Match_at_w_b0(trv, b, src, pos, end);
if (o == null) { // unknown sequence; word-char
if (cur_bgn == -1) cur_bgn = pos; // set 1st char for word
++pos;
}
else {
Srch_sym_parser parser = (Srch_sym_parser)o;
pos = parser.Parse(this, src, end, pos, parser_trie.Match_pos());
pos = parser.Parse(this, src, end, pos, trv.Pos());
}
}
}
@ -133,9 +134,9 @@ public class Srch_text_parser {
int pos = 0; int len = bry.length;
while (pos < len) {
byte b = bry[pos];
if (word_bgn_trie.Match_bgn_w_byte(b, bry, pos, len) != null) { // b is symbol;
if (word_bgn_trie.Match_at_w_b0(trv, b, bry, pos, len) != null) { // b is symbol;
dirty = true;
pos = word_bgn_trie.Match_pos();
pos = trv.Pos();
}
else {
break;

@ -20,8 +20,8 @@ import gplx.core.btries.*; import gplx.xowa.langs.cases.*;
import gplx.xowa.addons.wikis.searchs.parsers.*;
class Srch_crt_scanner {
private final List_adp tkns = List_adp_.New(); private byte[] src; private int src_len, pos, txt_bgn;
private final Srch_crt_scanner_syms trie_bldr; private final Btrie_slim_mgr trie;
private final Bry_bfr word_bfr = Bry_bfr_.New(); private boolean word_is_dirty;
private final Srch_crt_scanner_syms trie_bldr; private final Btrie_slim_mgr trie; private final Btrie_rv trv = new Btrie_rv();
private final Bry_bfr word_bfr = Bry_bfr_.New(); private boolean word_is_dirty;
public Srch_crt_scanner(Srch_crt_scanner_syms trie_bldr) {
this.trie_bldr = trie_bldr;
this.trie = trie_bldr.Trie();
@ -31,14 +31,14 @@ class Srch_crt_scanner {
tkns.Clear(); pos = 0; txt_bgn = -1;
while (pos < src_len) {
byte cur_b = src[pos];
byte cur_tid = trie.Match_byte_or(cur_b, src, pos, src_len, Byte_.Max_value_127);
byte cur_tid = trie.Match_byte_or(trv, cur_b, src, pos, src_len, Byte_.Max_value_127);
if (cur_tid == Byte_.Max_value_127) { // text character
if (txt_bgn == -1) txt_bgn = pos; // 1st character not set; set it
if (word_is_dirty) word_bfr.Add_byte(cur_b);
++pos;
}
else { // \ \s " - & | ( )
int pos_end = trie.Match_pos();
int pos_end = trv.Pos();
if ( cur_tid == Srch_crt_tkn.Tid__not // if "-"
&& txt_bgn != -1) { // && "word has started"
++pos;

@ -35,7 +35,7 @@ public class Srch_special_cmd implements Gfo_invk, Srch_rslt_cbk, Xog_tab_close_
}
public void Search() {
if (async) { // NOTE: async useful with multiple wikis; allows parallel searches;
Srch_html_row_bldr html_row_bldr = new Srch_html_row_bldr(new gplx.xowa.htmls.core.htmls.utls.Xoh_lnki_bldr(wiki.App(), wiki.App().Html__href_wtr()));
Srch_html_row_bldr html_row_bldr = new Srch_html_row_bldr(new gplx.xowa.htmls.core.htmls.utls.Xoh_lnki_bldr(wiki.App(), wiki.Html__href_wtr()));
html_row_wkr = new Srch_html_row_wkr(html_row_bldr, js_wkr, qry.Slab_end - qry.Slab_bgn, wiki.Domain_bry());
Thread_adp_.Start_by_key(gplx.xowa.apps.Xoa_thread_.Key_special_search_db, this, Invk_search_db);
}

@ -19,9 +19,10 @@ package gplx.xowa.apps; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
public class Xoa_app_mode {
Xoa_app_mode(int tid) {this.tid = tid;}
public int Tid() {return tid;} private final int tid;
public int Tid() {return tid;} private final int tid;
public boolean Tid_is_gui() {return tid == Tid_gui;}
public boolean Tid_is_tcp() {return tid == Tid_tcp;}
public boolean Tid_is_cmd() {return tid == Tid_cmd;}
public boolean Tid_is_http() {return tid == Tid_http;}
public boolean Tid_supports_js() {
switch (tid) {
@ -41,9 +42,9 @@ public class Xoa_app_mode {
}
}
private static final int Tid_cmd = 1, Tid_gui = 2, Tid_tcp = 3, Tid_http = 4, Tid_file = 5;
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file");
public static final Xoa_app_mode Itm_cmd = new Xoa_app_mode(Tid_cmd), Itm_gui = new Xoa_app_mode(Tid_gui), Itm_tcp = new Xoa_app_mode(Tid_tcp), Itm_http = new Xoa_app_mode(Tid_http), Itm_file = new Xoa_app_mode(Tid_file);
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_gui = Bry_.new_a7("gui"), Key_tcp = Bry_.new_a7("server"), Key_http = Bry_.new_a7("http_server"), Key_file = Bry_.new_a7("file");
public static final Xoa_app_mode Itm_cmd = new Xoa_app_mode(Tid_cmd), Itm_gui = new Xoa_app_mode(Tid_gui), Itm_tcp = new Xoa_app_mode(Tid_tcp), Itm_http = new Xoa_app_mode(Tid_http), Itm_file = new Xoa_app_mode(Tid_file);
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
.Add_bry_int(Key_cmd , Tid_cmd)
.Add_bry_int(Key_gui , Tid_gui)
.Add_bry_int(Key_http , Tid_http)

@ -108,7 +108,7 @@ class Xoa_site_cfg_mgr_fxt {
public void Test_extensiontags_y(String... ary) {Test_extensiontags(Bool_.Y, ary);}
public void Test_extensiontags_n(String... ary) {Test_extensiontags(Bool_.N, ary);}
public void Test_extensiontags(boolean expd_exists, String... ary) {
Btrie_slim_mgr trie = wiki.Mw_parser_mgr().Xnde_tag_regy().Get_trie(Xop_parser_.Parse_tid_tmpl);
Btrie_slim_mgr trie = wiki.Mw_parser_mgr().Xnde_tag_regy().Get_trie(Xop_parser_tid_.Tid__defn);
int len = ary.length;
for (int i = 0; i < len; ++i) {
String str = ary[i];

@ -21,6 +21,7 @@ import gplx.xowa.wikis.data.tbls.*;
public class Xobd_parser implements Xob_page_wkr {
private final Xob_bldr bldr;
private final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; ctg.v1 assumes [[Category:
private final Btrie_rv trv = new Btrie_rv();
private final List_adp wkr_list = List_adp_.New();
public String Page_wkr__key() {return KEY;} static final String KEY = "page_parser";
public Xobd_parser(Xob_bldr bldr) {this.bldr = bldr;}
@ -42,12 +43,12 @@ public class Xobd_parser implements Xob_page_wkr {
int pos = 0;
while (true) {
if (pos == src_len) break;
Object o = trie.Match_bgn(src, pos, src_len);
Object o = trie.Match_at(trv, src, pos, src_len);
if (o == null)
++pos;
else {
Xobd_parser_wkr wkr = (Xobd_parser_wkr)o;
pos = wkr.Wkr_run(page, src, src_len, pos, trie.Match_pos());
pos = wkr.Wkr_run(page, src, src_len, pos, trv.Pos());
}
}
}

@ -18,7 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
import gplx.core.btries.*;
class Uca_trie {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
private final Btrie_rv trv = new Btrie_rv();
public void Init() {
Init_itm(1, Bry_.New_by_ints(1,1));
Init_itm(2, Bry_.New_by_ints(1,1));
@ -1049,12 +1050,12 @@ Init_itm(1024, Bry_.New_by_ints(92,52,1,134,143,1,143,5));
public void Decode(Bry_bfr tmp, byte[] src, int bgn, int end) {
int i = bgn;
while (i < end) {
Object o = trie.Match_bgn(src, i, end);
Object o = trie.Match_at(trv, src, i, end);
if (src[i] < 4) return;
if (o == null) return; //throw Err_.new_fmt_("unknown error: {0}", i);
byte[] utf8_char = (byte[])o;
tmp.Add(utf8_char);
i = trie.Match_pos();
i = trv.Pos();
}
}
public void Init_itm(int charAsInt, byte[] uca) {

@ -21,6 +21,7 @@ class Xob_css_parser {
private final Bry_bfr bfr = Bry_bfr_.New_w_size(255);
private final Xob_mirror_mgr mgr;
private final Xob_css_parser__url url_parser; private final Xob_css_parser__import import_parser;
private final Btrie_rv trv = new Btrie_rv();
public Xob_css_parser(Xob_mirror_mgr mgr) {
this.mgr = mgr;
this.url_parser = new Xob_css_parser__url(mgr.Site_url());
@ -30,14 +31,14 @@ class Xob_css_parser {
int src_len = src.length; int pos = 0;
while (pos < src_len) {
byte b = src[pos];
Object o = tkns_trie.Match_bgn_w_byte(b, src, pos, src_len);
Object o = tkns_trie.Match_at_w_b0(trv, b, src, pos, src_len);
if (o == null) {
bfr.Add_byte(b);
++pos;
}
else {
byte tkn_tid = ((Byte_obj_val)o).Val();
int match_pos = tkns_trie.Match_pos();
int match_pos = trv.Pos();
Xob_css_tkn__base tkn = null;
switch (tkn_tid) {
case Tkn_url: tkn = url_parser.Parse(src, src_len, pos, match_pos); break;

@ -19,6 +19,7 @@ package gplx.xowa.bldrs.setups.maints; import gplx.*; import gplx.xowa.*; import
import gplx.core.btries.*; import gplx.core.ios.*;
public class Wmf_latest_parser {
private Ordered_hash hash = Ordered_hash_.New_bry();
private final Btrie_rv trv = new Btrie_rv();
public int Count() {return hash.Count();}
public Wmf_latest_itm Get_at(int i) {return (Wmf_latest_itm)hash.Get_at(i);}
public Wmf_latest_itm Get_by(byte[] k) {return (Wmf_latest_itm)hash.Get_by(k);}
@ -47,7 +48,7 @@ public class Wmf_latest_parser {
date_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, date_bgn, src_len); if (date_bgn == Bry_find_.Not_found) {Gfo_usr_dlg_.Instance.Warn_many("", "", "date_bgn not found"); break;}
int date_end = Bry_find_.Find_fwd(src, date_end_bry, date_bgn, src_len);
byte[] date_bry = Bry_.Mid(src, date_bgn, date_end);
DateAdp date = DateAdp_.parse_fmt(String_.new_a7(Replace_or(tmp_bfr, date_trie, date_bry, 3, date_or)), "dd-MM-yyyy HH:mm");
DateAdp date = DateAdp_.parse_fmt(String_.new_a7(Replace_or(tmp_bfr, date_trie, trv, date_bry, 3, date_or)), "dd-MM-yyyy HH:mm");
int size_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, date_end, src_len); if (size_bgn == Bry_find_.Not_found) {Gfo_usr_dlg_.Instance.Warn_many("", "", "size_bgn not found"); break;}
size_end = Bry_find_.Find_fwd(src, Byte_ascii.Cr, size_bgn, src_len);
byte[] size_bry = Bry_.Mid(src, size_bgn, size_end);
@ -56,12 +57,12 @@ public class Wmf_latest_parser {
hash.Add(name, itm);
}
}
private static byte[] Replace_or(Bry_bfr tmp_bfr, Btrie_slim_mgr trie, byte[] src, int pos, byte[] or) {
private static byte[] Replace_or(Bry_bfr tmp_bfr, Btrie_slim_mgr trie, Btrie_rv trv, byte[] src, int pos, byte[] or) {
int src_len = src.length;
Object o = trie.Match_bgn(src, pos, src_len); if (o == null) return or;
Object o = trie.Match_at(trv, src, pos, src_len); if (o == null) return or;
tmp_bfr.Add_mid(src, 0, pos);
tmp_bfr.Add((byte[])o);
tmp_bfr.Add_mid(src, trie.Match_pos(), src_len);
tmp_bfr.Add_mid(src, trv.Pos(), src_len);
return tmp_bfr.To_bry_and_clear();
}
}

@ -29,7 +29,7 @@ public class Xob_xml_parser_ {
trie_add(rv, Bry_tab, Id_tab, Bry_tab_ent); trie_add(rv, Bry_cr_nl, Id_cr_nl, Byte_ascii.Nl); trie_add(rv, Bry_cr, Id_cr, Byte_ascii.Nl);
return rv;
}
public static final byte[]
public static final byte[]
Bry_page_bgn = Bry_.new_a7("<page>"), Bry_page_bgn_frag = Bry_.new_a7("<page"), Bry_page_end = Bry_.new_a7("</page>")
, Bry_title_bgn = Bry_.new_a7("<title>"), Bry_title_bgn_frag = Bry_.new_a7("<title"), Bry_title_end = Bry_.new_a7("</title>")
, Bry_id_bgn = Bry_.new_a7("<id>"), Bry_id_bgn_frag = Bry_.new_a7("<id"), Bry_id_end = Bry_.new_a7("</id>")

@ -36,7 +36,7 @@ public class Xod_page_mgr {
// load page data
Xoh_page hpg = new Xoh_page();
hpg.Init(wiki, Xoa_url.New(wiki, ttl), ttl, 1);
hpg.Ctor_by_hview(wiki, Xoa_url.New(wiki, ttl), ttl, 1);
rv.Init_by_hpg(hpg);
wiki.Html__hdump_mgr().Load_mgr().Load(hpg, ttl);
Load_sections(rv, hpg);
@ -57,7 +57,7 @@ public class Xod_page_mgr {
// generate special
Xoh_page page = new Xoh_page();
page.Init(wiki, Xoa_url.New(wiki, ttl), ttl, 1); // NOTE: init page to set url, ttl; DATE:2016-06-23
page.Ctor_by_hview(wiki, Xoa_url.New(wiki, ttl), ttl, 1); // NOTE: init page to set url, ttl; DATE:2016-06-23
try {proto.Special__clone().Special__gen(wiki, page, url, ttl);}
catch (Exception e) {Gfo_log_.Instance.Warn("failed to generate special page", "url", url.To_str(), "err", Err_.Message_gplx_log(e)); return rv;}

@ -20,10 +20,16 @@ import gplx.core.consoles.*; import gplx.langs.htmls.encoders.*;
public class Xof_file_wkr_ {
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
public static final Gfo_url_encoder Md5_decoder = Gfo_url_encoder_.New__http_url().Init__same__many(Byte_ascii.Plus).Make();
public static byte[] Md5_fast(byte[] v) {return md5_hash.Hash_bry_as_bry(v);}
public static byte[] Md5_fast(byte[] v) {
synchronized (md5_hash) {
return md5_hash.Hash_bry_as_bry(v);
}
}
public static byte[] Md5(byte[] ttl) {
ttl = Md5_decoder.Decode(Ttl_standardize(ttl));
return Xof_file_wkr_.Md5_fast(ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title
synchronized (md5_hash) {
ttl = Md5_decoder.Decode(Ttl_standardize(ttl));
return Xof_file_wkr_.Md5_fast(ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title
}
}
public static byte[] Ttl_standardize(byte[] src) {
int len = src.length; if (len == 0) return src;

@ -28,6 +28,7 @@ public class Xou_cache_mgr {
this.cfg_tbl = db_file.Tbl__cfg();
this.cache_tbl = db_file.Tbl__cache();
}
public boolean Enabled() {return enabled;} private boolean enabled = true; public void Enabled_n_() {enabled = false;}
public int Fsys_count_cur() {return hash.Count();}
public long Fsys_size_cur() {return fsys_size_cur;} private long fsys_size_cur = 0;
public long Fsys_size_min() {return fsys_size_min;} public void Fsys_size_min_(long v) {fsys_size_min = v;} private long fsys_size_min = Io_mgr.Len_mb * 75;
@ -50,6 +51,7 @@ public class Xou_cache_mgr {
}
public Xou_cache_itm Get_or_null(Xof_fsdb_itm fsdb) {return Get_or_null(fsdb.Lnki_wiki_abrv(), fsdb.Lnki_ttl(), fsdb.Lnki_type(), fsdb.Lnki_upright(), fsdb.Lnki_w(), fsdb.Lnki_h(), fsdb.Lnki_time(), fsdb.Lnki_page(), fsdb.User_thumb_w());}
public Xou_cache_itm Get_or_null(byte[] wiki, byte[] ttl, int type, double upright, int w, int h, double time, int page, int user_thumb_w) {
if (!enabled) return null;
synchronized (thread_lock) {
this.Page_bgn();
byte[] key = Xou_cache_itm.Key_gen(key_bfr, wiki, ttl, type, upright, w, h, time, page, user_thumb_w);

@ -19,10 +19,11 @@ package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.x
import gplx.core.ios.*;
import gplx.xowa.files.origs.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.bins.*; import gplx.xowa.guis.cbks.js.*;
public class Xou_file_itm_finder {
private final Xou_cache_mgr cache_mgr; private final Xof_img_size img_size = new Xof_img_size(); private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2();
private final Xou_cache_mgr cache_mgr; private final Xof_img_size img_size = new Xof_img_size();
public Xou_file_itm_finder(Xou_cache_mgr cache_mgr) {this.cache_mgr = cache_mgr;}
public boolean Find(Xowe_wiki wiki, int exec_tid, Xof_file_itm xfer, byte[] page_url) {
byte[] lnki_ttl = xfer.Lnki_ttl();
Xof_url_bldr url_bldr = wiki.Parser_mgr().Url_bldr();
try {
if (wiki.File__fsdb_mode().Tid_v2_bld()) return false; // disable during build
Xou_cache_itm cache_itm = cache_mgr.Get_or_null(wiki.Domain_itm().Abrv_xo(), lnki_ttl, xfer.Lnki_type(), xfer.Lnki_upright(), xfer.Lnki_w(), xfer.Lnki_h(), xfer.Lnki_time(), xfer.Lnki_page(), Xof_img_size.Thumb_width_img);

@ -19,16 +19,12 @@ package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
import gplx.xowa.htmls.core.htmls.tidy.*; import gplx.xowa.htmls.js.*; import gplx.xowa.htmls.skins.*;
import gplx.xowa.parsers.xndes.*;
public class Xoh_html_mgr implements Gfo_invk {
public Xoh_html_mgr(Xoae_app app) {
js_cleaner = new Xoh_js_cleaner(app);
}
public Xoh_html_mgr(Xoae_app app) {}
public void Init_by_app(Xoae_app app) {
tidy_mgr.Init_by_app(app);
}
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private final Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
public Xoh_page_mgr Page_mgr() {return page_mgr;} private final Xoh_page_mgr page_mgr = new Xoh_page_mgr();
public Xoh_tidy_mgr Tidy_mgr() {return tidy_mgr;} private final Xoh_tidy_mgr tidy_mgr = new Xoh_tidy_mgr();
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private final Xoh_js_cleaner js_cleaner;
public Xoa_tidy_mgr Tidy_mgr() {return tidy_mgr;} private final Xoa_tidy_mgr tidy_mgr = new Xoa_tidy_mgr();
public Xoh_skin_mgr Skin_mgr() {return skin_mgr;} private final Xoh_skin_mgr skin_mgr = new Xoh_skin_mgr();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_page)) return page_mgr;

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.pages.lnkis.*; import gplx.xowa.wikis.pages.redirects.*;
import gplx.xowa.files.*;
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.sections.*; import gplx.xowa.htmls.tocs.*;
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.sections.*; import gplx.xowa.addons.htmls.tocs.*;
import gplx.xowa.wikis.pages.dbs.*; import gplx.xowa.wikis.pages.hdumps.*; import gplx.xowa.wikis.pages.htmls.*;
public class Xoh_page implements Xoa_page {
// core
@ -48,23 +48,17 @@ public class Xoh_page implements Xoa_page {
public int Exec_tid() {return exec_tid;} private int exec_tid = Xof_exec_tid.Tid_wiki_page;
public byte[] Html_head_xtn() {return html_head_xtn;} public void Html_head_xtn_(byte[] v) {html_head_xtn = v;} private byte[] html_head_xtn = Bry_.Empty; // drd:web_browser
public byte[] Url_bry_safe() {return page_url == null ? Bry_.Empty : page_url.To_bry(Bool_.Y, Bool_.Y);}
public void Init(Xow_wiki wiki, Xoa_url page_url, Xoa_ttl page_ttl, int page_id) {
public void Ctor_by_hview(Xow_wiki wiki, Xoa_url page_url, Xoa_ttl page_ttl, int page_id) {
this.wiki = wiki; this.page_url = page_url; this.page_ttl = page_ttl; this.page_id = page_id;
this.Clear();
html.Redlink_list().Disabled_(page_ttl.Ns().Id_is_module()); // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
hdump.Toc_wtr().Init(wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), page_url.Raw());
html.Toc_mgr().Init(wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), page_url.Raw());
}
public void Ctor_by_db(int head_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, int zip_tid, int hzip_tid, byte[] body) {
head_mgr.Flag_(head_flag);
this.display_ttl = display_ttl; this.content_sub = content_sub; this.sidebar_div = sidebar_div;
db.Html().Html_bry_(body);
db.Html().Zip_tids_(zip_tid, hzip_tid);
}
public Xoh_page Ctor_by_page(Bry_bfr tmp_bfr, Xoae_page page) {
this.page_id = page.Db().Page().Id();
this.wiki = page.Wiki();
public Xoh_page Ctor_by_hdiff(Bry_bfr tmp_bfr, Xoae_page page) {
this.wiki = page.Wiki(); this.page_url = page.Url(); this.page_ttl = page.Ttl(); this.page_id = page.Db().Page().Id();
db.Html().Html_bry_(page.Db().Html().Html_bry());
this.page_url = page.Url();
Xopg_html_data html = page.Html_data();
html.Init_by_page(page.Ttl());
Xoh_head_mgr mod_mgr = html.Head_mgr();
@ -72,12 +66,21 @@ public class Xoh_page implements Xoa_page {
this.display_ttl = html.Display_ttl();
this.content_sub = html.Content_sub();
this.sidebar_div = Xoh_page_.Save_sidebars(tmp_bfr, page, html);
html.Toc_mgr().Init(Bry_.Empty, page_url.Page_bry());
return this;
}
public void Ctor_by_db(int head_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, int zip_tid, int hzip_tid, byte[] body) {
head_mgr.Flag_(head_flag);
this.display_ttl = display_ttl; this.content_sub = content_sub; this.sidebar_div = sidebar_div;
db.Html().Html_bry_(body);
db.Html().Zip_tids_(zip_tid, hzip_tid);
}
public void Clear() {
redirect.Clear();
html.Clear();
hdump.Clear();
db.Clear();
display_ttl = content_sub = sidebar_div = Bry_.Empty;
head_mgr.Clear(); commons_mgr.Clear();

@ -0,0 +1,49 @@
/*
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.htmls; import gplx.*; import gplx.xowa.*;
import gplx.xowa.htmls.core.wkrs.tocs.*;
public class Xoh_page_bfr {
private byte toc_mode;
private Bry_bfr head_bfr; private final Bry_bfr body_bfr = Bry_bfr_.New();
public void Init(Bry_bfr head_bfr) {
this.toc_mode = Xoh_toc_data.Toc_mode__none;
this.head_bfr = head_bfr;
body_bfr.Clear();
}
public Bry_bfr Split_by_toc(byte toc_mode) {
this.toc_mode = toc_mode;
return body_bfr;
}
public void Commit(Xoa_page pg) {
boolean toc_mode_enabled = true, toc_mode_is_pgbnr = false; // default to Xoh_toc_data_.Toc_mode__basic
switch (toc_mode) {
case Xoh_toc_data.Toc_mode__none : toc_mode_enabled = false; break;
case Xoh_toc_data.Toc_mode__pgbnr : toc_mode_is_pgbnr = true; break;
}
// set flags
pg.Html_data().Toc_mgr().Exists_y_();
pg.Html_data().Head_mgr().Itm__pgbnr().Enabled_(toc_mode_is_pgbnr);
// build bfr by add bfr_0, toc, body_bfr
if (toc_mode_enabled) {
pg.Html_data().Toc_mgr().To_html(head_bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, toc_mode_is_pgbnr);
head_bfr.Add_bfr_and_clear(body_bfr);
}
}
}

@ -19,7 +19,7 @@ package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.wikis.pages.*;
public class Xoh_page_wtr_mgr implements Gfo_invk {
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255), html_bfr = Bry_bfr_.Reset(Io_mgr.Len_mb);
private Xoh_page_wtr_wkr edit_wtr, html_wtr, read_wtr;
public Xoh_page_wtr_mgr(boolean html_capable) {
this.html_capable = html_capable;
@ -48,10 +48,8 @@ public class Xoh_page_wtr_mgr implements Gfo_invk {
page_edit_fmtr.Eval_mgr_(wiki.Eval_mgr());
page_html_fmtr.Eval_mgr_(wiki.Eval_mgr());
}
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001();
byte[] bry = wtr.Write_page(page, wiki.Parser_mgr().Ctx(), tmp_bfr);
tmp_bfr.Mkr_rls();
return bry;
wtr.Write_page(html_bfr, page, wiki.Parser_mgr().Ctx());
return html_bfr.To_bry_and_clear_and_rls();
}
public Xoh_page_wtr_wkr Wkr(byte output_tid) {
switch (output_tid) {
@ -81,7 +79,7 @@ public class Xoh_page_wtr_mgr implements Gfo_invk {
public static final String Invk_page_read_ = "page_read_", Invk_page_edit_ = "page_edit_", Invk_page_html_ = "page_html_", Invk_xowa_div_edit_rename_ = "xowa_div_edit_rename_";
private static final String[] Fmtr_keys = new String[]
{ "app_root_dir", "app_version", "app_build_date", "xowa_mode_is_server"
, "page_id", "page_name", "page_heading", "page_modified_on_msg"
, "page_id", "page_ttl_full", "page_name", "page_heading", "page_modified_on_msg"
, "html_css_common_path", "html_css_wiki_path", "xowa_head"
, "page_lang_ltr", "page_indicators", "page_content_sub", "page_jumpto", "page_pgbnr", "page_body_cls", "html_content_editable"
, "page_data", "page_langs"

@ -23,13 +23,14 @@ import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.d
import gplx.xowa.xtns.pagebanners.*;
import gplx.xowa.apps.gfs.*; import gplx.xowa.htmls.portal.*;
public class Xoh_page_wtr_wkr {
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private final Xoh_page_wtr_mgr mgr; private final byte page_mode;
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr(); // In other languages
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page; private byte[] root_dir_bry;
public Xoh_page_wtr_wkr(Xoh_page_wtr_mgr mgr, byte page_mode) {this.mgr = mgr; this.page_mode = page_mode;}
public Xoh_page_wtr_wkr Ctgs_enabled_(boolean v) {ctgs_enabled = v; return this;} private boolean ctgs_enabled = true;
public byte[] Write_page(Xoae_page page, Xop_ctx ctx, Bry_bfr bfr) {
public void Write_page(Bry_bfr rv, Xoae_page page, Xop_ctx ctx) {
synchronized (thread_lock_1) {
this.page = page; this.wiki = page.Wikie(); this.app = wiki.Appe();
ctx.Page_(page); // HACK: must update page for toc_mgr; WHEN: Xoae_page rewrite
@ -44,26 +45,25 @@ public class Xoh_page_wtr_wkr {
// ctx.Page().Redlink_list().Clear(); // not sure if this is the best place to put it, but redlinks (a) must only fire once; (b) must fire before html generation; (c) cannot fire during edit (preview will handle separately); NOTE: probably put in to handle reusable redlink lists; redlink lists are now instantiated per page, so clear is not useful
break;
}
Bry_bfr page_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page bfr to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
Bry_bfr page_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page rv to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
Xoh_wtr_ctx hctx = null;
if (page_mode == Xopg_page_.Tid_html && wiki.App().Api_root().Wiki().Hdump().Html_mode().Tid_is_hdump_save()) {
hctx = Xoh_wtr_ctx.Hdump;
Write_body(page_bfr, ctx, hctx, page);
Write_page_by_tid(ctx, hctx, page_mode, bfr, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
}
else {
hctx = Xoh_wtr_ctx.Basic;
Write_body(page_bfr, ctx, hctx, page);
Write_page_by_tid(ctx, hctx, view_mode, bfr, fmtr, page_bfr.To_bry_and_rls());
Write_page_by_tid(ctx, hctx, view_mode, rv, fmtr, page_bfr.To_bry_and_rls());
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
Write_page_by_tid(ctx, hctx, page_mode, bfr, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
Write_page_by_tid(ctx, hctx, page_mode, rv, mgr.Page_html_fmtr(), Gfh_utl.Escape_html_as_bry(rv.To_bry_and_clear()));
wdata_lang_wtr.Page_(null);
}
}
else
Write_body(bfr, ctx, Xoh_wtr_ctx.Basic, page);
Write_body(rv, ctx, Xoh_wtr_ctx.Basic, page);
this.page = null;
return bfr.To_bry_and_clear();
}
}
private void Write_page_by_tid(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte html_gen_tid, Bry_bfr bfr, Bry_fmtr fmtr, byte[] page_data) {
@ -93,7 +93,7 @@ public class Xoh_page_wtr_wkr {
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
fmtr.Bld_bfr_many(bfr
, root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str()
, page.Db().Page().Id()
, page.Db().Page().Id(), page.Ttl().Full_db()
, page_name, page.Html_data().Page_heading().Init(page.Html_data(), page_display_title)
, modified_on_msg
, mgr.Css_common_bry(), mgr.Css_wiki_bry(), page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts()
@ -104,7 +104,7 @@ public class Xoh_page_wtr_wkr {
, mgr.Edit_rename_div_bry(page_ttl), page.Html_data().Edit_preview_w_dbg(), js_edit_toolbar_bry
);
Xoh_page_wtr_wkr_.Bld_head_end(bfr, tmp_bfr, page); // add after </head>
Xoh_page_wtr_wkr_.Bld_html_end(bfr, tmp_bfr, page); // add after </html>
Xoh_page_wtr_wkr_.Bld_html_end(bfr, tmp_bfr, page); // add after </html>
}
public void Write_hdump(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoae_page wpg) {
if (wpg.Html_data().Xtn_pgbnr() != null) {
@ -133,7 +133,7 @@ public class Xoh_page_wtr_wkr {
}
if ( wiki.Domain_tid() != Xow_domain_tid_.Int__home // allow home wiki to use javascript
&& !page_tid_uses_pre) { // if .js, .css or .lua, skip test; may have js fragments, but entire text is escaped and put in pre; don't show spurious warning; DATE:2013-11-21
app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page_ttl, bfr, bfr_page_bgn);
wiki.Html_mgr().Js_cleaner().Clean_bfr(wiki, page_ttl, bfr, bfr_page_bgn);
}
}
}
@ -158,15 +158,19 @@ public class Xoh_page_wtr_wkr {
tidy_bfr.Add(page.Html_data().Custom_body());
}
else {
if (page.Root() != null) // NOTE: will be null if blank; occurs for one test: Logo_has_correct_main_page; DATE:2015-09-29
wiki.Html_mgr().Html_wtr().Write_all(tidy_bfr, page.Wikie().Parser_mgr().Ctx(), hctx, page.Root().Data_mid(), page.Root());
if (page.Root() != null) { // NOTE: will be null if blank; occurs for one test: Logo_has_correct_main_page; DATE:2015-09-29
page.Html_data().Toc_mgr().Clear(); // NOTE: always clear tocs before writing html; toc_itms added when writing html_hdr; DATE:2016-07-17
wiki.Html_mgr().Html_wtr().Write_doc(tidy_bfr, ctx, hctx, page.Root().Data_mid(), page.Root());
if (wiki.Html_mgr().Html_wtr().Cfg().Toc__show())
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_toc(tidy_bfr, page, hctx);
}
}
// if [[Category]], render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, hctx, tidy_bfr);
// tidy html
gplx.xowa.htmls.core.htmls.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
if (tidy_mgr.Enabled()) tidy_mgr.Run_tidy_html(page, tidy_bfr, !hctx.Mode_is_hdump());
wiki.Html_mgr().Tidy_mgr().Run_tidy_html(page, tidy_bfr, !hctx.Mode_is_hdump());
// add back to main bfr
bfr.Add_bfr_and_clear(tidy_bfr);

@ -19,7 +19,7 @@ package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
public class Xohp_ctg_grp_mgr {
final Bry_fmtr grp_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
final Bry_fmtr grp_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "~{grp_lbl}"
@ -29,7 +29,7 @@ public class Xohp_ctg_grp_mgr {
, "</div>"
), "grp_lbl", "grp_itms")
;
final Bry_fmtr itm_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
final Bry_fmtr itm_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, "<li>"
, "<a href=\"~{itm_href}\" class=\"internal\" title=\"~{itm_title}\">~{itm_text}</a>"
@ -55,7 +55,7 @@ class Xoh_ctg_itm_fmtr implements gplx.core.brys.Bfr_arg {
for (int i = 0; i < ctgs_len; i++) {
byte[] page_name = page.Category_list()[i];
tmp_bfr.Add(ctg_prefix).Add(page_name);
page.Wikie().Appe().Html__href_wtr().Build_to_bfr(tmp_href, app, wiki.Domain_bry(), wiki.Ttl_parse(tmp_bfr.To_bry_and_clear()));
page.Wikie().Html__href_wtr().Build_to_bfr(tmp_href, app, wiki.Domain_bry(), wiki.Ttl_parse(tmp_bfr.To_bry_and_clear()));
itm_fmtr.Bld_bfr(bfr, tmp_href.To_bry_and_clear(), page_name, page_name);
}
tmp_bfr.Mkr_rls();

@ -18,8 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
import gplx.gfui.kits.core.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.ctgs.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.htmls.portal.*; import gplx.xowa.htmls.tocs.*; import gplx.xowa.wikis.modules.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.wikis.ctgs.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.parsers.xndes.*;
import gplx.xowa.htmls.portal.*; import gplx.xowa.addons.htmls.tocs.*; import gplx.xowa.wikis.modules.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.htmls.tidy.*; import gplx.xowa.htmls.js.*;
public class Xow_html_mgr implements Gfo_invk {
public Xow_html_mgr(Xowe_wiki wiki) {
this.wiki = wiki;
@ -34,20 +35,24 @@ public class Xow_html_mgr implements Gfo_invk {
portal_mgr = new Xow_portal_mgr(wiki);
imgs_mgr = new Xoh_imgs_mgr(this);
module_mgr = new Xow_module_mgr(wiki);
this.js_cleaner = new Xoh_js_cleaner(app);
}
public void Init_by_wiki(Xowe_wiki wiki) {
html_wtr.Init_by_wiki(wiki);
module_mgr.Init_by_wiki(wiki);
tidy_mgr.Init_by_app(wiki.Appe());
}
public void Init_by_lang(Xol_lang_itm lang) {
portal_mgr.Init_by_lang(lang);
}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xoh_html_wtr Html_wtr() {return html_wtr;} private Xoh_html_wtr html_wtr;
public Xoh_page_wtr_mgr Page_wtr_mgr() {return page_wtr_mgr;} private Xoh_page_wtr_mgr page_wtr_mgr;
public Xow_portal_mgr Portal_mgr() {return portal_mgr;} private Xow_portal_mgr portal_mgr;
public Xow_toc_mgr Toc_mgr() {return toc_mgr;} private Xow_toc_mgr toc_mgr = new Xow_toc_mgr();
public Xow_module_mgr Head_mgr() {return module_mgr;} private Xow_module_mgr module_mgr;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xoh_html_wtr Html_wtr() {return html_wtr;} private Xoh_html_wtr html_wtr;
public Xoh_page_wtr_mgr Page_wtr_mgr() {return page_wtr_mgr;} private Xoh_page_wtr_mgr page_wtr_mgr;
public Xow_tidy_mgr Tidy_mgr() {return tidy_mgr;} private final Xow_tidy_mgr tidy_mgr = new Xow_tidy_mgr();
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private final Xoh_js_cleaner js_cleaner;
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private final Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
public Xow_portal_mgr Portal_mgr() {return portal_mgr;} private Xow_portal_mgr portal_mgr;
public Xow_module_mgr Head_mgr() {return module_mgr;} private Xow_module_mgr module_mgr;
public boolean Importing_ctgs() {return importing_ctgs;} public void Importing_ctgs_(boolean v) {importing_ctgs = v;} private boolean importing_ctgs;
public int Img_thumb_width() {return img_thumb_width;} private int img_thumb_width = 220;
public byte[] Img_media_play_btn() {return img_media_play_btn;} private byte[] img_media_play_btn;

@ -30,7 +30,7 @@ public class Xow_hdump_mgr__load {
}
public Xoh_make_mgr Make_mgr() {return make_mgr;} private final Xoh_make_mgr make_mgr;
public void Load_by_edit(Xoae_page wpg) {
tmp_hpg.Init(wpg.Wiki(), wpg.Url(), wpg.Ttl(), wpg.Db().Page().Id());
tmp_hpg.Ctor_by_hview(wpg.Wiki(), wpg.Url(), wpg.Ttl(), wpg.Db().Page().Id());
Load(tmp_hpg, wpg.Ttl());
wpg.Db().Html().Html_bry_(tmp_hpg.Db().Html().Html_bry());
wpg.Root_(new gplx.xowa.parsers.Xop_root_tkn()); // HACK: set root, else load page will fail
@ -44,7 +44,7 @@ public class Xow_hdump_mgr__load {
this.override_mgr__html = new Xow_override_mgr(override_root_url.GenSubDir_nest("html"));
}
boolean loaded = Load__dbpg(wiki, tmp_dbpg.Clear(), hpg, ttl);
hpg.Init(hpg.Wiki(), hpg.Url(), ttl, tmp_dbpg.Id());
hpg.Ctor_by_hview(hpg.Wiki(), hpg.Url(), ttl, tmp_dbpg.Id());
if (!loaded) { // nothing in "page" table
byte[] page_override = override_mgr__page.Get_or_same(ttl.Page_db(), null);
if (page_override == null) return Load__fail(hpg);
@ -85,7 +85,7 @@ public class Xow_hdump_mgr__load {
wpg_head.Itm__hiero().Enabled_ (hpg_head.Hiero_exists());
wpg_head.Itm__timeline().Enabled_ (hpg.Xtn__timeline_exists());
wpg_head.Itm__gallery_styles().Enabled_ (hpg.Xtn__gallery_exists());
wpg_head.Itm__toc().Enabled_(hpg.Hdump_mgr().Toc_wtr().Exists());
wpg_head.Itm__toc().Enabled_(hpg.Html_data().Toc_mgr().Exists());
wpg_head.Itm__pgbnr().Enabled_(hpg.Html_data().Head_mgr().Itm__pgbnr().Enabled());
// transfer images from Xoh_page to Xoae_page

@ -32,7 +32,7 @@ public class Xow_hdump_mgr__save {
public int Save(Xoae_page page) {
synchronized (tmp_hpg) {
Bld_hdump(page);
tmp_hpg.Ctor_by_page(tmp_bfr, page);
tmp_hpg.Ctor_by_hdiff(tmp_bfr, page);
Xow_db_file html_db = Get_html_db(wiki, page, html_db_is_new.Val_n_());
return Save(tmp_hpg, html_db.Tbl__html(), html_db_is_new.Val());
}

@ -20,6 +20,7 @@ import gplx.core.brys.*; import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.apps.apis.xowa.bldrs.imports.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.dbs.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.parsers.*;
public class Xob_hdump_bldr implements Gfo_invk {
private boolean enabled, hzip_enabled, hzip_diff, hzip_b256; private byte zip_tid = Byte_.Max_value_127;
private Xowe_wiki wiki; private Xow_hdump_mgr hdump_mgr; private Xob_hdump_tbl_retriever html_tbl_retriever;
@ -27,6 +28,9 @@ public class Xob_hdump_bldr implements Gfo_invk {
private int prv_row_len = 0;
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private boolean op_sys_is_wnt;
public Xob_hdump_bldr Enabled_(boolean v) {this.enabled = v; return this;}
public Xob_hdump_bldr Hzip_enabled_(boolean v) {this.hzip_enabled = v; return this;}
public Xob_hdump_bldr Hzip_diff_(boolean v) {this.hzip_diff = v; return this;}
public boolean Init(Xowe_wiki wiki, Db_conn make_conn, Xob_hdump_tbl_retriever html_tbl_retriever) {
if (!enabled) return false;
this.op_sys_is_wnt = gplx.core.envs.Op_sys.Cur().Tid_is_wnt();
@ -38,19 +42,19 @@ public class Xob_hdump_bldr implements Gfo_invk {
hdump_mgr.Init_by_db(zip_tid, hzip_enabled, hzip_b256);
return true;
}
public void Insert(Xoae_page wpg) {
public void Insert(Xop_ctx ctx, Xoae_page wpg) {
// clear
tmp_hpg.Clear(); // NOTE: must clear tmp_hpg or else will leak memory during mass build; DATE:2016-01-09
wpg.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
// write to html
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_hdump(tmp_bfr, wiki.Parser_mgr().Ctx(), Xoh_wtr_ctx.Hdump, wpg);
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_hdump(tmp_bfr, ctx, Xoh_wtr_ctx.Hdump, wpg);
byte[] orig_bry = tmp_bfr.To_bry_and_clear();
wpg.Db().Html().Html_bry_(orig_bry);
// save to db
Xowd_html_tbl html_tbl = html_tbl_retriever.Get_html_tbl(wpg.Ttl().Ns(), prv_row_len); // get html_tbl
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_page(tmp_bfr, wpg), html_tbl, true); // save to db
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_hdiff(tmp_bfr, wpg), html_tbl, true); // save to db
stat_tbl.Insert(tmp_hpg, stat_itm, wpg.Root().Root_src().length, tmp_hpg.Db().Html().Html_bry().length, prv_row_len); // save stats
// run hzip diff if enabled

@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.core.brys.*;
public class Xowd_html_tbl implements Db_tbl {
private final String fld_page_id, fld_head_flag, fld_body_flag, fld_display_ttl, fld_content_sub, fld_sidebar_div, fld_body;
private Db_stmt stmt_select, stmt_insert, stmt_delete, stmt_update;
private final Int_flag_bldr body_flag_bldr = new Int_flag_bldr().Pow_ary_bld_(3, 2); // 8 different zip types; 4 different hzip types
private final Int_flag_bldr body_flag_bldr = Make_body_flag_bldr();
public Xowd_html_tbl(Db_conn conn) {
this.conn = conn;
this.fld_page_id = flds.Add_int_pkey("page_id");
@ -105,4 +105,5 @@ public class Xowd_html_tbl implements Db_tbl {
stmt.Val_int(fld_head_flag, head_flag).Val_int(fld_body_flag, body_flag)
.Val_bry_as_str(fld_display_ttl, Bry_.Coalesce_to_empty(display_ttl)).Val_bry_as_str(fld_content_sub, Bry_.Coalesce_to_empty(content_sub)).Val_bry_as_str(fld_sidebar_div, Bry_.Coalesce_to_empty(sidebar_div)).Val_bry(fld_body, body);
}
public static Int_flag_bldr Make_body_flag_bldr() {return new Int_flag_bldr().Pow_ary_bld_(3, 2);} // 8 different zip types; 4 different hzip types
}

@ -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.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import gplx.core.btries.*;
import gplx.xowa.parsers.htmls.*;
class Xoh_display_ttl_wtr {
public static boolean Is_style_restricted(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Mwh_atr_itm atr, byte[] atr_key) {
if (atr_key != null
&& Bry_.Eq(atr_key, Atr_key_style)
) {
byte[] atr_val = atr.Val_as_bry(); if (atr_val == null) return false; // bounds_chk
int atr_val_len = atr_val.length;
int atr_pos = 0;
while (atr_pos < atr_val_len) {
byte b = atr_val[atr_pos];
Object o = style_trie.Match_bgn_w_byte(b, atr_val, atr_pos, atr_val_len);
if (o != null) {
bfr.Add(Msg_style_restricted);
return true;
}
++atr_pos;
}
}
return false;
}
private static final byte[]
Atr_key_style = Bry_.new_a7("style")
, Msg_style_restricted = Bry_.new_a7(" style='/* attempt to bypass $wgRestrictDisplayTitle */'")
;
private static final Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_a7()
.Add_str_byte__many(Byte_.By_int(0), "display", "user-select", "visibility"); // if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save