v3.3.4 v3.7.1.1
gnosygnu 8 years ago
parent 1a4ca00c0b
commit 36584a0cc2

@ -542,6 +542,11 @@ public class Bry_bfr {
if (reset > 0) Reset_if_gt(reset);
return rv;
}
public byte[] To_bry_and_clear_and_rls() {
byte[] rv = To_bry_and_clear();
this.Mkr_rls();
return rv;
}
public String To_str() {return String_.new_u8(To_bry());}
public String To_str_by_pos(int bgn, int end) {return String_.new_u8(To_bry(), bgn, end);}
public String To_str_and_clear() {return String_.new_u8(To_bry_and_clear());}

@ -30,6 +30,7 @@ public class Gfo_log_ {
}
public static Gfo_log New_file(Io_url dir) {
Io_url url = dir.GenSubFil(DateAdp_.Now().XtoStr_fmt(File__fmt) + File__ext);
Gfo_log__file.Delete_old_files(dir, Gfo_log_.Instance);
return new Gfo_log__file(url, new Gfo_log_itm_wtr__csv());
}
}

@ -42,6 +42,16 @@ public class Int_ implements Gfo_invk {
for (int i = 0; i < src_len; ++i)
trg[i] = src[i];
}
public static String Ary_concat(String spr, int... ary) {
Bry_bfr bfr = Bry_bfr_.New();
int len = ary.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_str_u8(spr);
int itm = ary[i];
bfr.Add_int_variable(itm);
}
return bfr.To_str_and_clear();
}
public static int[] AryRng(int bgn, int end) {
int len = end - bgn + 1;
int[] rv = new int[len];

@ -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.core.btries; import gplx.*; import gplx.core.*;
import gplx.core.threads.poolables.*;
public class Btrie_rv implements Gfo_poolable_itm {
public Object Obj() {return obj;} private Object obj;
public int Pos() {return pos;} private int pos;
public Btrie_rv Init(int pos, Object obj) {
this.obj = obj;
this.pos = pos;
return this;
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Btrie_rv rv = new Btrie_rv(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

@ -95,7 +95,7 @@ public class Btrie_slim_itm {
}
if (found) --ary_len;
}
public static final Btrie_slim_itm[] Ary_empty = new Btrie_slim_itm[0]; int ary_len = 0, ary_max = 0;
public static final Btrie_slim_itm[] Ary_empty = new Btrie_slim_itm[0]; int ary_len = 0, ary_max = 0;
}
class ByteHashItm_sorter {// quicksort
Btrie_slim_itm[] ary; int ary_len;
@ -126,5 +126,5 @@ class ByteHashItm_sorter {// quicksort
if (lo < j) Sort_recurse(lo, j);
if (i < hi) Sort_recurse(i, hi);
}
public static final ByteHashItm_sorter Instance = new ByteHashItm_sorter(); ByteHashItm_sorter() {}
public static final ByteHashItm_sorter Instance = new ByteHashItm_sorter(); ByteHashItm_sorter() {}
}

@ -16,11 +16,35 @@ 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.btries; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*;
import gplx.core.primitives.*; import gplx.core.threads.poolables.*;
public class Btrie_slim_mgr implements Btrie_mgr {
private static Gfo_poolable_mgr pool_rv = Gfo_poolable_mgr.New_rlsable(new Btrie_rv(), Object_.Ary_empty, 0, 1024);
Btrie_slim_mgr(boolean case_match) {root = new Btrie_slim_itm(Byte_.Zero, null, !case_match);} private Btrie_slim_itm root;
public int Count() {return count;} private int count;
public int Match_pos() {return match_pos;} private int match_pos;
public Btrie_rv Match_at(byte[] src, int bgn, int end) {return bgn < end ? Match_at_w_b0(src[bgn], src, bgn, end) : null;} // handle out of bounds gracefully; EX: Match_bgn("abc", 3, 3) should return null not fail
public Btrie_rv Match_at_w_b0(byte b, byte[] src, int bgn_pos, int src_end) {
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)
return ((Btrie_rv)pool_rv.Get_safe()).Init(cur_pos, rv_obj); // nxt does not hav b; return rv_obj;
++cur_pos;
if (nxt.Ary_is_empty()) {
return ((Btrie_rv)pool_rv.Get_safe()).Init(cur_pos, nxt.Val()); // nxt is leaf; return nxt.Val() (which should be non-null)
}
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 == src_end)
return ((Btrie_rv)pool_rv.Get_safe()).Init(rv_pos, rv_obj); // increment cur_pos and exit if src_end
b = src[cur_pos];
cur = nxt;
}
}
public Object Match_exact(byte[] src) {return src == null ? null : Match_exact(src, 0, src.length);}
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
if (bgn_pos == end_pos) return null; // NOTE:handle empty String; DATE:2016-04-21

@ -98,7 +98,7 @@ public class IoEngine_system extends IoEngine_base {
}
return Load_from_stream_as_str(stream, url_str);
}
@SuppressWarnings("resource") public static String Load_from_stream_as_str(InputStream stream, String url_str) {
public static String Load_from_stream_as_str(InputStream stream, String url_str) {
InputStreamReader reader = null;
try {reader = new InputStreamReader(stream, IoEngineArgs.Instance.LoadFilStr_Encoding);}
catch (UnsupportedEncodingException e) {
@ -131,7 +131,7 @@ public class IoEngine_system extends IoEngine_base {
Closeable_close(reader, url_str, false);
return sw.toString();
}
@SuppressWarnings("resource") public static byte[] Load_from_stream_as_bry(InputStream stream, String url_str) {
public static byte[] Load_from_stream_as_bry(InputStream stream, String url_str) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[4096];
int read = 0;
@ -239,7 +239,6 @@ public class IoEngine_system extends IoEngine_base {
if (!ExistsFil_api(url)) SaveFilText_api(IoEngine_xrg_saveFilStr.new_(url, ""));
return IoStream_base.new_(url, args.Mode());
}
@SuppressWarnings("resource")
@Override public void CopyFil(IoEngine_xrg_xferFil args) {
// TODO:JAVA6 hidden property ignored; 1.6 does not allow OS-independent way of setting isHidden (wnt only possible through jni)
boolean overwrite = args.Overwrite();

@ -77,7 +77,7 @@ abstract class Io_stream_wtr_base implements Io_stream_wtr {
public Io_url Url() {return url;} public Io_stream_wtr Url_(Io_url v) {url = v; trg_bfr = null; return this;} Io_url url;
public void Trg_bfr_(Bry_bfr v) {trg_bfr = v;} Bry_bfr trg_bfr; java.io.ByteArrayOutputStream mem_stream;
public byte[] To_ary_and_clear() {return trg_bfr.To_bry_and_clear();}
@SuppressWarnings("resource") public Io_stream_wtr Open() {
public Io_stream_wtr Open() {
java.io.OutputStream bry_stream = null;
if (trg_bfr == null) {
if (!Io_mgr.Instance.ExistsFil(url)) Io_mgr.Instance.SaveFilStr(url, "");
@ -130,7 +130,7 @@ class Io_stream_wtr_zip implements Io_stream_wtr {
@Override public byte Tid() {return Io_stream_.Tid_zip;}
public Io_url Url() {return url;} public Io_stream_wtr Url_(Io_url v) {url = v; trg_bfr = null; return this;} private Io_url url = Io_url_.Empty;
public void Trg_bfr_(Bry_bfr v) {trg_bfr = v;} private Bry_bfr trg_bfr; private java.io.ByteArrayOutputStream mem_stream;
@SuppressWarnings("resource") // rely on zip_stream to close bry_stream
// rely on zip_stream to close bry_stream
public Io_stream_wtr Open() {
java.io.OutputStream bry_stream;
if (trg_bfr == null) {

@ -41,13 +41,22 @@ public class Io_zip_compress_cmd__jre {
while (true) { // loop over bytes
int read_in_raw = -1;
try {read_in_raw = src_stream.read(buffer);}
catch (Exception e) {throw Err_.new_exc(e, "io", "src read failed", "url", src_url.Raw());}
catch (Exception e) {
try {src_stream.close();}
catch (IOException e1) {}
throw Err_.new_exc(e, "io", "src read failed", "url", src_url.Raw());
}
if (read_in_raw < 1) break;
try {trg_stream.write(buffer, 0, read_in_raw);}
catch (Exception e) {throw Err_.new_exc(e, "io", "trg write failed", "url", trg_url.Raw());}
catch (Exception e) {
try {src_stream.close();}
catch (IOException e1) {}
throw Err_.new_exc(e, "io", "trg write failed", "url", trg_url.Raw());
}
}
try {
trg_stream.closeEntry();
trg_stream.close();
src_stream.close();
}
catch (Exception e) {throw Err_.new_exc(e, "io", "trg close entry failed", "url", src_url.Raw());}

@ -48,4 +48,16 @@ public class Gfo_log__file extends Gfo_log__base {
Io_mgr.Instance.AppendFilByt(url, bry);
itms.Clear();
}
public static void Delete_old_files(Io_url dir, Gfo_log log) {
Io_url[] fils = Io_mgr.Instance.QueryDir_fils(dir);
int fils_len = fils.length;
if (fils_len < 9) return; // exit if less than 8 files
int cutoff = fils_len - 8;
Array_.Sort(fils); // sort by path
for (int i = 0; i < cutoff; ++i) {
Io_url fil = fils[i];
log.Info("deleting old log file", "file", fil.Raw());
Io_mgr.Instance.DeleteFil(fil);
}
}
}

@ -15,13 +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.parsers.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_apos_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "apos");
public static final Gfo_msg_itm
Bold_converted_to_ital = Gfo_msg_itm_.new_note_(owner, "Bold_converted_to_ital")
, Dangling_apos = Gfo_msg_itm_.new_note_(owner, "Dangling_apos")
, Multiple_apos = Gfo_msg_itm_.new_note_(owner, "Multiple_apos")
;
package gplx.core.memorys; import gplx.*; import gplx.core.*;
public interface Gfo_memory_itm {
void Rls_mem();
}

@ -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.core.memorys; import gplx.*; import gplx.core.*;
public class Gfo_memory_mgr {
private final List_adp list = List_adp_.New();
public void Reg_safe(Gfo_memory_itm itm) {synchronized (list) {Reg_fast(itm);}}
public void Reg_fast(Gfo_memory_itm itm) {list.Add(itm);}
public void Rls_safe() {synchronized (list) {Rls_fast();}}
public void Rls_fast() {
int len = list.Len();
for (int i = 0; i < len; ++i) {
Gfo_memory_itm itm = (Gfo_memory_itm)list.Get_at(i);
itm.Rls_mem();
}
list.Clear();
}
public static final Gfo_memory_mgr Instance = new Gfo_memory_mgr(); Gfo_memory_mgr() {}
}

@ -24,7 +24,7 @@ public class Gfo_prog_ui_ {
, Status__done = 4
, Status__fail = 8
, Status__suspended = 16
, Status__runnable = Status__init | Status__suspended
, Status__runnable = Status__init | Status__suspended | Status__fail
;
}
class Gfo_prog_ui__noop implements Gfo_prog_ui {

@ -19,8 +19,9 @@ package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.brys.*;
public class Gftest {
private static final Bry_bfr bfr = Bry_bfr_.New();
public static void Eq__ary(long[] expd, long[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__long, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, String actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_split_.Split_lines(Bry_.new_u8(expd)), Bry_split_.Split_lines(Bry_.new_u8(actl)), msg_fmt, msg_args);}
public static void Eq__ary(int[] expd, int[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__int, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(long[] expd, long[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__long, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, String actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_split_.Split_lines(Bry_.new_u8(expd)), Bry_split_.Split_lines(Bry_.new_u8(actl)), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, String[] actl) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), Bry_.Ary(actl), "no_msg");}
public static void Eq__ary(String[] expd, String[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), Bry_.Ary(actl), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), actl, msg_fmt, msg_args);}
@ -37,6 +38,20 @@ public class Gftest {
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
}
public static void Eq__null(boolean expd, Object actl) {Eq__null(expd, actl, null);}
public static void Eq__null(boolean expd, Object actl, String msg_fmt, Object... msg_args) {
if ( expd && actl == null
|| !expd && actl != null
) return;
Write_fail_head(bfr, msg_fmt, msg_args);
String expd_str = expd ? "null" : "not null";
String actl_str = actl == null ? "null" : "not null";
bfr.Add_str_a7("expd: ").Add_str_a7(expd_str).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add_str_a7(actl_str).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__str(String expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__str(expd, String_.new_u8(actl), msg_fmt, msg_args);}
public static void Eq__str(String expd, byte[] actl) {Eq__str(expd, String_.new_u8(actl), null);}
public static void Eq__str(String expd, String actl) {Eq__str(expd, actl, null);}
public static void Eq__str(String expd, String actl, String msg_fmt, Object... msg_args) {
@ -65,6 +80,24 @@ public class Gftest {
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__byte(byte expd, byte actl) {Eq__byte(expd, actl, null);}
public static void Eq__byte(byte expd, byte actl, String msg_fmt, Object... msg_args) {
if (expd == actl) return;
Write_fail_head(bfr, msg_fmt, msg_args);
bfr.Add_str_a7("expd: ").Add_byte_as_a7(expd).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add_byte_as_a7(actl).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__int(int expd, int actl) {Eq__int(expd, actl, null);}
public static void Eq__int(int expd, int actl, String msg_fmt, Object... msg_args) {
if (expd == actl) return;
Write_fail_head(bfr, msg_fmt, msg_args);
bfr.Add_str_a7("expd: ").Add_int_variable(expd).Add_byte_nl();
bfr.Add_str_a7("actl: ").Add_int_variable(actl).Add_byte_nl();
bfr.Add(Bry__line_end);
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__bool_y(boolean actl) {Eq__bool(Bool_.Y, actl, null);}
public static void Eq__bool(boolean expd, boolean actl) {Eq__bool(expd, actl, null);}
public static void Eq__bool(boolean expd, boolean actl, String msg_fmt, Object... msg_args) {
@ -112,6 +145,7 @@ public class Gftest {
switch (type_id) {
case Type_adp_.Tid__bry: bfr.Add((byte[])Array_.Get_at(ary, idx)); break;
case Type_adp_.Tid__long: bfr.Add_long_variable(Long_.cast(Array_.Get_at(ary, idx))); break;
case Type_adp_.Tid__int: bfr.Add_int_variable(Int_.cast(Array_.Get_at(ary, idx))); break;
default: throw Err_.new_unhandled_default(type_id);
}
}
@ -134,6 +168,7 @@ public class Gftest {
switch (tid) {
case Type_adp_.Tid__bry: eq = Bry_.Eq((byte[])expd_obj, (byte[])actl_obj); break;
case Type_adp_.Tid__long: eq = Long_.cast(expd_obj) == Long_.cast(actl_obj); break;
case Type_adp_.Tid__int: eq = Int_.cast(expd_obj) == Int_.cast(actl_obj); break;
}
}
if (!eq) {

@ -16,15 +16,17 @@ 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.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
public class Gfo_poolable_mgr {
private final Object thread_lock = new Object();
private final Gfo_poolable_itm prototype; private final Object[] make_args;
import gplx.core.memorys.*;
public class Gfo_poolable_mgr implements Gfo_memory_itm {
private final Object thread_lock = new Object();
private final Gfo_poolable_itm prototype; private final Object[] make_args;
private Gfo_poolable_itm[] pool; private int pool_nxt, pool_len;
public Gfo_poolable_mgr(Gfo_poolable_itm prototype, Object[] make_args, int init_pool_len, int pool_max) {// NOTE: random IndexOutOfBounds errors in Get around free_ary[--free_len] with free_len being -1; put member variable initialization within thread_lock to try to avoid; DATE:2014-09-21
this.prototype = prototype; this.make_args = make_args;
this.pool_len = init_pool_len;
this.Clear_fast();
}
public void Rls_mem() {Clear_safe();}
public void Clear_safe() {synchronized (thread_lock) {Clear_fast();}}
public void Clear_fast() {
this.pool = new Gfo_poolable_itm[pool_len];
@ -87,4 +89,10 @@ public class Gfo_poolable_mgr {
@gplx.Internal protected int Free_len() {return free_len;}
@gplx.Internal protected int Pool_len() {return pool_len;}
@gplx.Internal protected int Pool_nxt() {return pool_nxt;}
public static Gfo_poolable_mgr New_rlsable(Gfo_poolable_itm prototype, Object[] make_args, int init_pool_len, int pool_max) {
Gfo_poolable_mgr rv = new Gfo_poolable_mgr(prototype, make_args, init_pool_len, pool_max);
Gfo_memory_mgr.Instance.Reg_safe(rv);
return rv;
}
}

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.threads.poolables; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
import org.junit.*;
public class Gfo_poolable_mgr_tst {
private final Gfo_poolable_mgr_tstr tstr = new Gfo_poolable_mgr_tstr();
private final Gfo_poolable_mgr_tstr tstr = new Gfo_poolable_mgr_tstr();
@Before public void init() {tstr.Clear();}
@Test public void Get__one() {
tstr.Test__get(0);
@ -61,7 +61,7 @@ public class Gfo_poolable_mgr_tst {
}
}
class Gfo_poolable_mgr_tstr {
private final Gfo_poolable_mgr mgr = new Gfo_poolable_mgr(new Sample_poolable_itm(null, -1, Object_.Ary_empty), Object_.Ary("make"), 2, 8);
private final Gfo_poolable_mgr mgr = new Gfo_poolable_mgr(new Sample_poolable_itm(null, -1, Object_.Ary_empty), Object_.Ary("make"), 2, 8);
public void Clear() {mgr.Clear_fast();}
public void Test__get(int expd_idx) {
Sample_poolable_itm actl_itm = (Sample_poolable_itm)mgr.Get_fast();
@ -76,8 +76,8 @@ class Gfo_poolable_mgr_tstr {
class Sample_poolable_itm implements Gfo_poolable_itm {
private Gfo_poolable_mgr pool_mgr;
public Sample_poolable_itm(Gfo_poolable_mgr pool_mgr, int pool_idx, Object[] make_args) {this.pool_mgr = pool_mgr; this.pool_idx = pool_idx; this.pool__make_args = make_args;}
public int Pool__idx() {return pool_idx;} private final int pool_idx;
public Object[] Pool__make_args() {return pool__make_args;} private final Object[] pool__make_args;
public int Pool__idx() {return pool_idx;} private final int pool_idx;
public Object[] Pool__make_args() {return pool__make_args;} private final Object[] pool__make_args;
public void Pool__rls() {pool_mgr.Rls_safe(pool_idx);}
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {return new Sample_poolable_itm(pool_mgr, idx, args);}
}

@ -59,7 +59,14 @@ public class Gfui_html extends GfuiElemBase {
rv.Add(Int_.To_str(i), args[i]); // NOTE: args[i] can be either String or String[]
return rv;
}
public static final String Atr_href = "href", Atr_title = "title", Atr_value = "value", Atr_innerHTML = "innerHTML", Atr_src = "src";
public static final String Elem_id_body = "body";
public static final String Evt_location_changed = "location_changed", Evt_location_changing = "location_changing", Evt_link_hover = "link_hover", Evt_win_resized = "win_resized";
public static final String
Evt_location_changed = "location_changed"
, Evt_location_changing = "location_changing"
, Evt_link_hover = "link_hover"
, Evt_win_resized = "win_resized"
, Evt_zoom_changed = "zoom_changed"
;
}

@ -179,6 +179,7 @@ public class Swt_kit implements Gfui_kit {
swt_html.Under_control().addMenuDetectListener(new Swt_lnr__menu_detect(this, gfui_html));
gfui_html.Owner_(owner);
swt_html.Delete_elems_(owner, gfui_html);
swt_html.Evt_mgr_(gfui_html.Evt_mgr());
return gfui_html;
}
public Gfui_tab_mgr New_tab_mgr(String key, GfuiElem owner, Keyval... args) {

@ -26,6 +26,7 @@ import gplx.gfui.controls.gxws.GxwElem;
import gplx.gfui.controls.gxws.Gxw_html;
import gplx.gfui.controls.gxws.Gxw_html_load_tid_;
import gplx.gfui.controls.standards.Gfui_html;
import gplx.gfui.controls.standards.Gfui_tab_mgr;
import gplx.gfui.ipts.*;
import gplx.gfui.kits.core.Swt_kit;
@ -45,7 +46,7 @@ import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Swt_html implements Gxw_html, Swt_control, FocusListener {
public class Swt_html implements Gxw_html, Swt_control, FocusListener, Gfo_evt_mgr_owner {
private Swt_html_lnr_location lnr_location; private Swt_html_lnr_status lnr_status;
public Swt_html(Swt_kit kit, Swt_control owner_control, Keyval_hash ctorArgs) {
this.kit = kit;
@ -62,10 +63,12 @@ public class Swt_html implements Gxw_html, Swt_control, FocusListener {
browser.addStatusTextListener(lnr_status);
browser.addFocusListener(this);
browser.addTitleListener(new Swt_html_lnr_title(this));
browser.addMouseWheelListener(new Swt_html_lnr_wheel(this));
// browser.addOpenWindowListener(new Swt_open_window_listener(this)); // handle target='blank'
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
}
public Swt_kit Kit() {return kit;} private Swt_kit kit;
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr; public void Evt_mgr_(Gfo_evt_mgr v) {ev_mgr = v;}
@Override public Control Under_control() {return browser;} private Browser browser;
@Override public Composite Under_composite() {return null;}
@Override public Control Under_menu_control() {return browser;}
@ -267,6 +270,17 @@ class Swt_html_lnr_mouse implements MouseListener {
return IptEvtDataMouse.new_(btn, IptMouseWheel_.None, ev.x, ev.y);
}
}
class Swt_html_lnr_wheel implements MouseWheelListener {
private final Swt_html html_box;
public Swt_html_lnr_wheel(Swt_html html_box) {
this.html_box = html_box;
}
@Override public void mouseScrolled(MouseEvent evt) {
if (evt.stateMask == SWT.CTRL) { // ctrl held;
Gfo_evt_mgr_.Pub_obj(html_box, Gfui_html.Evt_zoom_changed, "clicks_is_positive", evt.count > 0);
}
}
}
//class Swt_open_window_listener implements OpenWindowListener {
// private final Swt_html html_box;
// public Swt_open_window_listener(Swt_html html_box) {this.html_box = html_box;}

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/100_core"/>
<classpathentry combineaccessrules="false" kind="src" path="/140_dbs"/>
<classpathentry combineaccessrules="false" kind="src" path="/150_gfui"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/jtidy_xowa.jar"/>
<classpathentry kind="lib" path="lib/luaj_xowa.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -38,7 +38,11 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
InputStream src_stream = null;
URL src_url_itm = null;
try {src_url_itm = new URL(src_url);}
catch (MalformedURLException e) {throw Err_.new_("download_file", "bad url", "src", src_url, "err" + e.toString());}
catch (MalformedURLException e) {
try {trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_("download_file", "bad url", "src", src_url, "err" + e.toString());
}
HttpURLConnection src_conn = null;
try {
// open connection
@ -50,12 +54,18 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
// check response code
int response_code = src_conn.getResponseCode();
if (prog_resumed) {
if (response_code != HttpURLConnection.HTTP_PARTIAL)
if (response_code != HttpURLConnection.HTTP_PARTIAL) {
try {trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_("download_file", "server returned non-partial response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
}
}
else {
if (response_code != HttpURLConnection.HTTP_OK)
if (response_code != HttpURLConnection.HTTP_OK) {
try {trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_("download_file", "server returned non-OK response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
}
}
src_stream = src_conn.getInputStream();
} catch (Exception e) {

@ -52,6 +52,8 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, Id__i = 28
, Id__b = 29
, Id__sup = 30
, Id__sub = 31
, Id__bdi = 32
;
public static final byte[]
Bry__a = Bry_.new_a7("a")
@ -94,6 +96,8 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
.Add_str_int("i" , Id__i)
.Add_str_int("b" , Id__b)
.Add_str_int("sup" , Id__sup)
.Add_str_int("sub" , Id__sub)
.Add_str_int("bdi" , Id__bdi)
;
public static String To_str(int tid) {
switch (tid) {
@ -131,6 +135,8 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
case Id__i: return "i";
case Id__b: return "b";
case Id__sup: return "sup";
case Id__sub: return "sub";
case Id__bdi: return "bdi";
default: throw Err_.new_unhandled(tid);
}
}
@ -145,17 +151,16 @@ public class Gfh_tag_ { // NOTE: not serialized; used by tag_rdr
, Pre_lhs = Bry_.new_a7("<pre>") , Pre_rhs = Bry_.new_a7("</pre>")
, Div_lhs = Bry_.new_a7("<div>") , Div_rhs = Bry_.new_a7("</div>")
, Html_rhs = Bry_.new_a7("</html>")
, Head_lhs_bgn = Bry_.new_a7("<head")
, Head_rhs = Bry_.new_a7("</head>")
, Head_lhs_bgn = Bry_.new_a7("<head") , Head_rhs = Bry_.new_a7("</head>")
, Style_lhs_w_type = Bry_.new_a7("<style type=\"text/css\">")
, Style_rhs = Bry_.new_a7("</style>")
, Script_lhs = Bry_.new_a7("<script>")
, Script_lhs = Bry_.new_a7("<script>") , Script_rhs = Bry_.new_a7("</script>")
, Script_lhs_w_type = Bry_.new_a7("<script type='text/javascript'>")
, Script_rhs = Bry_.new_a7("</script>")
, Span_lhs = Bry_.new_a7("<span")
, Span_rhs = Bry_.new_a7("</span>")
, Strong_lhs = Bry_.new_a7("<strong>")
, Strong_rhs = Bry_.new_a7("</strong>")
, 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")
;
public static final String
Comm_bgn_str = "<!--"

@ -19,7 +19,8 @@ package gplx.langs.htmls.encoders; import gplx.*; import gplx.langs.*; import gp
import gplx.core.btries.*;
import gplx.xowa.parsers.amps.*;
public class Gfo_url_encoder_ {
public static final Gfo_url_encoder
public static Gfo_url_encoder New__id() {return Gfo_url_encoder_.New__html_id().Make();}
public static final Gfo_url_encoder
Id = Gfo_url_encoder_.New__html_id().Make()
, Href = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make()
, Href_wo_anchor = Gfo_url_encoder_.New__html_href_mw(Bool_.N).Make()

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

@ -258,12 +258,13 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
}
}
else {
boolean pass = amp_mgr.Parse_as_int(amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex, src, end, cur2, match_pos);
if (pass) {
b_ary = gplx.core.intls.Utf16_.Encode_int_to_bry(amp_mgr.Rslt_val());
Xop_amp_mgr_rslt amp_rv = new Xop_amp_mgr_rslt();
amp_mgr.Parse_ncr(amp_rv, amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex, src, end, cur2, match_pos);
if (amp_rv.Pass()) {
b_ary = gplx.core.intls.Utf16_.Encode_int_to_bry(amp_rv.Val());
if (b_ary.length == 1 && b_ary[0] == Byte_ascii.Hash) // NOTE: A&#x23;B should be interpreted as A#b; PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07
anch_bgn = (txt_bb_len) + 1;
match_pos = amp_mgr.Rslt_pos();
match_pos = amp_rv.Pos();
}
}
}

@ -95,8 +95,6 @@ public class Xop_fxt {
public Xop_tkn_chkr_base tkn_pipe_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_pipe).Src_rng_(bgn, bgn + 1);}
public Xop_tkn_chkr_base tkn_tab_(int bgn) {return new Xop_tkn_chkr_base().TypeId_dynamic(Xop_tkn_itm_.Tid_tab).Src_rng_(bgn, bgn + 1);}
public Xop_apos_tkn_chkr tkn_apos_(int cmd) {return new Xop_apos_tkn_chkr().Apos_cmd_(cmd);}
public Xop_tkn_chkr_base tkn_html_ref_(String v) {return new Xop_html_txt_tkn_chkr().Html_ref_key_(v);}
public Xop_tkn_chkr_base tkn_html_ncr_(int v) {return new Xop_html_num_tkn_chkr().Html_ncr_val_(v);}
public Xop_ignore_tkn_chkr tkn_comment_(int bgn, int end) {return tkn_ignore_(bgn, end, Xop_ignore_tkn.Ignore_tid_comment);}
public Xop_ignore_tkn_chkr tkn_ignore_(int bgn, int end, byte t){return (Xop_ignore_tkn_chkr)new Xop_ignore_tkn_chkr().Ignore_tid_(t).Src_rng_(bgn, end);}
public Xop_tkn_chkr_hr tkn_hr_(int bgn, int end) {return new Xop_tkn_chkr_hr(bgn, end).Hr_len_(Xop_hr_lxr.Hr_len);}

@ -147,7 +147,6 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
public Xob_import_cfg Import_cfg() {return import_cfg;} private Xob_import_cfg import_cfg;
public Xotdb_fsys_mgr Tdb_fsys_mgr() {return tdb_fsys_mgr;} private final Xotdb_fsys_mgr tdb_fsys_mgr;
public Xou_history_cfg Cfg_history() {return cfg_history;} private Xou_history_cfg cfg_history = new Xou_history_cfg();
public Xoh_cfg_gallery Cfg_gallery() {return cfg_gallery;} private Xoh_cfg_gallery cfg_gallery = new Xoh_cfg_gallery();
public Xoh_file_page_wtr Cfg_file_page() {return cfg_file_page;} private Xoh_file_page_wtr cfg_file_page = new Xoh_file_page_wtr();
public Xow_sys_cfg Sys_cfg() {return sys_cfg;} private Xow_sys_cfg sys_cfg;
public Xowc_parser Cfg_parser() {return cfg_parser;} private Xowc_parser cfg_parser;
@ -235,7 +234,6 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
if (ctx.Match(k, Invk_files)) return file_mgr;
else if (ctx.Match(k, Invk_stats)) return stats;
else if (ctx.Match(k, Invk_props)) return props;
else if (ctx.Match(k, Invk_cfg_gallery_)) return cfg_gallery;
else if (ctx.Match(k, Invk_commons_wiki_)) commons_wiki_key = m.ReadBry("v");
else if (ctx.Match(k, Invk_lang)) return lang;
else if (ctx.Match(k, Invk_lang_)) throw Err_.new_deprecated("wiki.lang_");
@ -263,7 +261,7 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
return this;
}
public static final String
Invk_files = "files", Invk_cfg_gallery_ = "cfg_gallery_", Invk_commons_wiki_ = "commons_wiki_", Invk_stats = "stats"
Invk_files = "files", Invk_commons_wiki_ = "commons_wiki_", Invk_stats = "stats"
, Invk_lang = "lang", Invk_html = "html", Invk_gui = "gui", Invk_cfg_history = "cfg_history", Invk_user = "user", Invk_data_mgr = "data_mgr", Invk_sys_cfg = "sys_cfg", Invk_ns_mgr = "ns_mgr"
, Invk_special = "special"
, Invk_props = "props", Invk_parser = "parser"

@ -44,7 +44,9 @@ public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
@gplx.Virtual public String Cmd_fallback() {return this.Cmd_type();}
@gplx.Virtual public void Cmd_clear() {// called when restarting failed task
this.status = Gfo_prog_ui_.Status__init;
this.cmd_exec_err = null;
this.cmd_exec_err = null; // reset error
this.data_cur = 0; // reset progress else bad progress updates; DATE:2016-06-29
this.Cmd_cleanup(); // do any cleanup, such as deleting bad downloads
}
public void Cmd_exec(Xobc_cmd_ctx ctx) {
@ -57,20 +59,23 @@ public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
Gfo_log_.Instance.Info("xobc_cmd task end", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id);
switch (status) {
case Gfo_prog_ui_.Status__suspended: task_mgr.Work_mgr().On_suspended(this); break;
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, cmd_exec_err); break;
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, Bool_.N, cmd_exec_err); break;
case Gfo_prog_ui_.Status__working:
this.Prog_notify_and_chk_if_suspended(data_end, data_end); // fire one more time for 100%; note that 100% may not fire due to timer logic below
task_mgr.Work_mgr().On_done(this);
break;
}
} catch (Exception e) {
this.status = Gfo_prog_ui_.Status__fail;
Gfo_log_.Instance.Warn("xobc_cmd task fail", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id, "err", Err_.Message_gplx_log(e));
task_mgr.Work_mgr().On_fail(this, this.Cmd_fail_resumes(), Err_.Message_lang(e));
}
finally {
Gfo_log_.Instance.Flush();
}
}
protected abstract void Cmd_exec_hook(Xobc_cmd_ctx ctx);
@gplx.Virtual protected boolean Cmd_fail_resumes() {return false;}
protected void Cmd_exec_err_(String v) {
Gfo_log_.Instance.Warn("xobc_cmd task err", "task_id", task_id, "step_id", step_id, "cmd_id", cmd_id, "err", v);
this.status = Gfo_prog_ui_.Status__fail;

@ -38,6 +38,8 @@ public class Xobc_cmd__download extends Xobc_cmd__base {
@Override public void Cmd_cleanup() {
wkr.Exec_cleanup();
}
@Override protected boolean Cmd_fail_resumes() {return true;}
@Override protected long Load_checkpoint_hook() {
return wkr.Checkpoint__load_by_trg_fil(trg_url);
}

@ -113,11 +113,12 @@ public class Xobc_task_regy__work extends Xobc_task_regy__base {
step.Cmd_idx_next_();
}
// release wake_lock; will be acquired when task is run_next; DATE:2016-06-29
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
// task_regy.done
if (task_is_done) {
if (this.Len() == 0)
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
else
if (this.Len() > 0)
this.Run_next();
}
// task_regy.work
@ -132,8 +133,8 @@ public class Xobc_task_regy__work extends Xobc_task_regy__base {
task.Task_status_(Gfo_prog_ui_.Status__suspended);
task_mgr.Send_json("xo.bldr.work.stop_cur__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()));
}
public void On_fail(Xobc_cmd_itm task, String msg) {
public void On_fail(Xobc_cmd_itm task, boolean resume, String msg) {
Xod_power_mgr_.Instance.Wake_lock__rls("task_mgr");
task_mgr.Send_json("xo.bldr.work.prog__fail__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_str("err", msg));
task_mgr.Send_json("xo.bldr.work.prog__fail__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_str("err", msg).Add_bool("resume", resume));
}
}

@ -79,6 +79,7 @@ public class Srch_search_mgr {
}
}
private void Clear() {
Gfo_usr_dlg_.Instance.Log_many("", "", "search.clear");
search_count = 0;
cache__page.Clear();
cache__word_counts.Clear();

@ -32,6 +32,7 @@ public class Srch_link_wkr extends Percentile_select_base {
private Srch_crt_itm sql_root;
public void Search(Srch_rslt_list rslts_list, Srch_rslt_cbk rslt_cbk, Srch_search_ctx ctx) {
// init
Gfo_usr_dlg_.Instance.Log_many("", "", "search.search by link_tbl; search=~{0}", ctx.Qry.Phrase.Orig);
super.cxl = ctx.Cxl;
super.rng = ctx.Score_rng;
super.rng_log = new Percentile_rng_log(ctx.Addon.Db_mgr().Cfg().Link_score_max());
@ -54,15 +55,15 @@ public class Srch_link_wkr extends Percentile_select_base {
sql_root = Srch_link_wkr_.Find_sql_root(ctx);
attach_mgr.Conn_others_(new Db_attach_itm("page_db", ctx.Db__core.Conn()), new Db_attach_itm("word_db", ctx.Tbl__word.conn));
super.Select();
}
}
finally {
try {
// gplx.core.consoles.Console_adp__sys.Instance.Write_str_w_nl("detaching: " + String_.new_u8(ctx.Qry.Phrase.Lcase_wild) + " " + Int_.To_str(ctx.Score_rng.Score_bgn()) + " " + Int_.To_str(ctx.Score_rng.Score_end()) + " " + attach_mgr.List__to_str());
Gfo_usr_dlg_.Instance.Log_many("", "", "search.detaching; phrase=~{0} score_bgn=~{1} score_end=~{2}", ctx.Qry.Phrase.Orig, ctx.Score_rng.Score_bgn(), ctx.Score_rng.Score_end());
attach_mgr.Detach();
stmt = Db_stmt_.Rls(stmt);
}
catch (Exception e) {
gplx.core.consoles.Console_adp__sys.Instance.Write_str_w_nl("detaching err: " + String_.new_u8(ctx.Qry.Phrase.Orig) + " " + Int_.To_str(ctx.Score_rng.Score_bgn()) + Err_.Message_lang(e));
Gfo_usr_dlg_.Instance.Log_many("", "", "search.detaching fail; phrase=~{0} score_bgn=~{1} err=~{2}", ctx.Qry.Phrase.Orig, ctx.Score_rng.Score_bgn(), Err_.Message_gplx_log(e));
}
}
}
@ -115,7 +116,7 @@ public class Srch_link_wkr extends Percentile_select_base {
rslt_cbk.On_rslts_found(ctx.Qry, rslts_list, rslts_bgn, rslts_end);
rslts_list.Rslts_are_first = false;
rslts_bgn = rslts_end;
// gplx.core.consoles.Console_adp__sys.Instance.Write_str(rng_log.To_str_and_clear());
// Gfo_usr_dlg_.Instance.Log_many("", "", "search.search rslts; rslts=~{0}", rng_log.To_str_and_clear());
}
@Override protected boolean Row__read(Db_rdr rdr) {
if (!rdr.Move_next()) return false;

@ -39,11 +39,11 @@ public class Srch_link_wkr_sql {
public String Write(Srch_search_ctx ctx, Db_attach_mgr attach_mgr) {
String sql = stmt_mgr.Bfr().To_str_and_clear();
try {
// gplx.core.consoles.Console_adp__sys.Instance.Write_str_w_nl("attaching: " + String_.new_u8(ctx.Qry.Phrase.Lcase_wild) + " " + Int_.To_str(ctx.Score_rng.Score_bgn()) + " " + Int_.To_str(ctx.Score_rng.Score_end()) + " " + attach_mgr.List__to_str());
Gfo_usr_dlg_.Instance.Log_many("", "", "search.resolving; phrase=~{0} score_bgn=~{1} score_end=~{2}", ctx.Qry.Phrase.Orig, ctx.Score_rng.Score_bgn(), ctx.Score_rng.Score_end());
sql = attach_mgr.Resolve_sql(sql);
}
catch (Exception e) {
gplx.core.consoles.Console_adp__sys.Instance.Write_str_w_nl("attaching err: " + String_.new_u8(ctx.Qry.Phrase.Orig) + " " + Int_.To_str(ctx.Score_rng.Score_bgn()) + " " + Int_.To_str(ctx.Score_rng.Score_end()) + Err_.Message_lang(e));
Gfo_usr_dlg_.Instance.Log_many("", "", "search.resolving err; phrase=~{0} score_bgn=~{1} score_end=~{2} err=~{3}", ctx.Qry.Phrase.Orig, ctx.Score_rng.Score_bgn(), ctx.Score_rng.Score_end(), Err_.Message_gplx_log(e));
}
return sql;
}
@ -53,7 +53,6 @@ public class Srch_link_wkr_sql {
return cur_link_conn.Stmt_sql(sql);
}
public void Fill(Db_stmt stmt) {
// gplx.core.consoles.Console_adp__sys.Instance.Write_str_w_nl(String_.new_u8(ctx.Qry.Phrase.Orig) + " " + Int_.To_str(ctx.Score_rng.Score_bgn()) + " " + Int_.To_str(ctx.Score_rng.Score_end()));
stmt_mgr.Fill_stmt_and_clear(stmt);
}
private void Bld_where(Srch_search_ctx ctx, Srch_crt_itm node) {

@ -25,6 +25,7 @@ public class Srch_page_tbl_wkr {
public void Search(Srch_search_ctx ctx, Srch_rslt_cbk cbk) {
byte[] search_raw = To_bry_or_null(tmp_bfr, ctx.Scanner_syms.Wild(), ctx.Crt_mgr); // build up search String but handle escapes "\+" -> "+"
if (search_raw == null) return; // search-term has not or symbols; EX: "earth -history"; "(earth & history)"
Gfo_usr_dlg_.Instance.Log_many("", "", "search.search by page_tbl; search=~{0}", search_raw);
Xoa_ttl ttl = ctx.Wiki.Ttl_parse(search_raw); if (ttl == null) return;
Xowd_page_tbl page_tbl = ctx.Tbl__page;
if (ctx.Cxl.Canceled()) return;

@ -63,7 +63,7 @@ class Srch_word_count_wkr extends Percentile_select_base {
return rows_read > 0 || score_too_low;
}
@Override protected void Rdr__done(boolean rslts_are_enough, boolean rslts_are_done) {
// if (rslts_are_enough) gplx.core.consoles.Console_adp__sys.Instance.Write_str(rng_log.To_str_and_clear());
if (rslts_are_enough) Gfo_usr_dlg_.Instance.Log_many("", "", "search.word_count; rng=~{0}", rng_log.To_str_and_clear());
}
private static Bry_fmt
Fmt__main = Bry_fmt.Auto(String_.Concat_lines_nl_skip_last

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.searchs.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*;
import gplx.core.threads.*;
import gplx.xowa.files.gui.*; import gplx.xowa.guis.views.*;
import gplx.xowa.guis.cbks.js.*; import gplx.xowa.guis.views.*;
import gplx.xowa.addons.wikis.searchs.specials.htmls.*; import gplx.xowa.addons.wikis.searchs.searchers.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
public class Srch_special_cmd implements Gfo_invk, Srch_rslt_cbk, Xog_tab_close_lnr {
private final Srch_special_searcher mgr; private final Srch_search_qry qry;

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.searchs.specials.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
import gplx.langs.htmls.*; import gplx.xowa.files.gui.*;
import gplx.langs.htmls.*; import gplx.xowa.guis.cbks.js.*;
import gplx.xowa.addons.wikis.searchs.searchers.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
public class Srch_html_row_wkr {
private final Srch_html_row_bldr html_row_bldr; private final Xog_js_wkr js_wkr;

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.searchs.specials.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.files.gui.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
import org.junit.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.guis.cbks.js.*; import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
public class Srch_rslt_cbk_tst {
@Before public void init() {fxt.Clear();} private Srch_rslt_cbk_fxt fxt = new Srch_rslt_cbk_fxt();
@Test public void Basic() {

@ -25,7 +25,7 @@ public class Xoapi_font implements Gfo_invk {
public void Increase() {Adj(1);}
public void Decrease() {Adj(-1);}
public void Reset() {Set(false, Xoh_page_mgr.Font_size_default, Xocfg_win.Font_size_default);}
private void Adj(int adj) {
public void Adj(int adj) {
float html_font_size = app.Html_mgr().Page_mgr().Font_size() + adj;
float gui_font_size = app.Gui_mgr().Win_cfg().Font().Size() + adj; // (html_font_size * .75f) - 4; // .75f b/c 16px = 12 pt; -4 b/c gui font is currently 4 pt smaller
if (html_font_size < 1 || gui_font_size < 1) return;

@ -41,7 +41,7 @@ public class Wmf_dump_list_parser_tst {
, fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56")
);
}
// @Test public void Update() { // MAINT:QUARTERLY:2016-03-17; must run C:\xowa\ and update dump status
// @Test public void Update() { // MAINT:QUARTERLY:2016-07-03; must run C:\xowa\ and update dump status
// Hash_adp_bry excluded_domains = Hash_adp_bry.cs().Add_many_str
// ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org"
// , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org"

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.drds; import gplx.*; import gplx.xowa.*;
import gplx.xowa.drds.pages.*; import gplx.xowa.drds.files.*;
import gplx.xowa.apps.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.files.gui.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.guis.cbks.js.*;
import gplx.xowa.addons.wikis.searchs.searchers.rslts.*;
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.addons.wikis.searchs.*; import gplx.xowa.addons.wikis.searchs.searchers.*;

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.drds.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.drds.*;
import gplx.core.threads.*;
import gplx.xowa.drds.pages.*;
import gplx.xowa.files.*; import gplx.xowa.files.gui.*;
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*;
import gplx.xowa.htmls.*;
public class Xod_file_mgr {
private final Gfo_thread_pool thread_pool = new Gfo_thread_pool();

@ -16,7 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
import gplx.xowa.guis.cbks.js.*; import gplx.xowa.files.repos.*;
public interface Xof_file_itm {
int Lnki_exec_tid();
byte[] Lnki_wiki_abrv();

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.threads.*; import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.gui.*;
import gplx.xowa.files.repos.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.guis.cbks.js.*;
import gplx.xowa.htmls.core.makes.imgs.*;
public class Xof_file_wkr implements Gfo_thread_wkr {
private final Xof_orig_mgr orig_mgr; private final Xof_bin_mgr bin_mgr; private final Fsm_mnt_mgr mnt_mgr; private final Xou_cache_mgr cache_mgr;

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.ios.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
import gplx.xowa.guis.cbks.js.*; import gplx.xowa.files.repos.*;
import gplx.xowa.parsers.lnkis.*;
public class Xof_fsdb_itm implements Xof_file_itm {
private int lnki_upright_patch;

@ -90,13 +90,6 @@ public class Xof_img_size {
}
}
}
// private static boolean Calc_limit_size(int exec_tid, int lnki_type, int lnki_ext) {
// if (lnki_type != Xop_lnki_type.Id_thumb) return false; // only limit to size for thumb; EX:[[File:A.png|thumb|999x999px]] does not get limited but [[File:A.png|999x999px]] does
// if (lnki_ext == Xof_ext_.Id_svg) // if svg...
// return exec_tid == Xof_exec_tid.Tid_wiki_file; // ... only limit to size if [[File]] page
// else // not svg and thumb; always limit to size
// return true;
// }
public static int Calc_w(int file_w, int file_h, int lnki_h) { // REF.MW:media/MediaHandler.php|fitBoxWidth
double ideal_w = (double)file_w * (double)lnki_h / (double)file_h;
double ideal_w_ceil = Math_.Ceil(ideal_w);
@ -142,7 +135,7 @@ public class Xof_img_size {
}
public static final int Null = -1;
public static final int Thumb_width_img = 220, Thumb_width_ogv = 220;
public static final double Upright_null = -1, Upright_default_marker = 0; // REF:MW: if ( isset( $fp['upright'] ) && $fp['upright'] == 0 )
public static final double Upright_null = -1, Upright_default_marker = 0; // REF:MW: if ( isset( $fp['upright'] ) && $fp['upright'] == 0 )
public static final int Size__neg1 = -1, Size_null = 0; // Size_null = 0, b/c either imageMagick / inkscape fails when -1 is passed
public static final int Size__same_as_orig = -1;
private static final int Svg_max_width = 2048;

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.primitives.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.repos.*;
import gplx.xowa.guis.cbks.js.*; import gplx.xowa.files.repos.*;
import gplx.xowa.wikis.tdbs.metas.*;
import gplx.xowa.parsers.utils.*;
public class Xof_xfer_itm implements Xof_file_itm {

@ -16,7 +16,7 @@ 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.files; import gplx.*; import gplx.xowa.*;
import gplx.core.threads.*; import gplx.xowa.files.gui.*;
import gplx.core.threads.*; import gplx.xowa.guis.cbks.js.*;
public class Xog_redlink_thread implements Gfo_thread_wkr {
private final int[] redlink_ary; private final Xog_js_wkr js_wkr;
public Xog_redlink_thread(int[] redlink_ary, Xog_js_wkr js_wkr) {this.redlink_ary = redlink_ary; this.js_wkr = js_wkr;}

@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
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.files.gui.*;
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(); private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2();
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();

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.fsdb; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.gui.*;
import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.caches.*; import gplx.xowa.guis.cbks.js.*;
public interface Xof_fsdb_mgr {
Xof_bin_mgr Bin_mgr();
Fsm_mnt_mgr Mnt_mgr();

@ -20,7 +20,7 @@ import gplx.core.primitives.*;
import gplx.core.ios.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.files.gui.*;
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.imgs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*; import gplx.xowa.guis.cbks.js.*;
public class Xof_fsdb_mgr__sql implements Xof_fsdb_mgr, Gfo_invk {
private boolean init = false; private boolean fsdb_enabled = false;
private Xow_repo_mgr repo_mgr; private Xof_url_bldr url_bldr; private final Xof_img_size img_size = new Xof_img_size();

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.fsdb.fs_roots; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.core.ios.*; import gplx.core.brys.fmtrs.*; import gplx.core.envs.*;
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
import gplx.xowa.files.gui.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*;
import gplx.xowa.guis.cbks.js.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.caches.*;
public class Fs_root_fsdb_mgr implements Xof_fsdb_mgr, Gfo_invk { // read images from file-system dir
private Xowe_wiki wiki; private Fs_root_wkr_fsdb fsdb_wkr;
public Fs_root_fsdb_mgr(Xowe_wiki wiki) {this.Init_by_wiki(wiki); fsdb_wkr = new Fs_root_wkr_fsdb(wiki);}

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.core.envs.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.files.gui.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.dbs.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.cnvs.*; import gplx.xowa.files.exts.*; import gplx.xowa.guis.cbks.js.*;
import gplx.fsdb.data.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.wikis.nss.*;

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.xfers; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.bins.*; import gplx.xowa.files.origs.*;
import gplx.xowa.files.gui.*;
import gplx.xowa.guis.cbks.js.*;
import gplx.xowa.wikis.tdbs.metas.*;
public class Xof_xfer_queue {
private final List_adp xfer_list = List_adp_.New(); private final Ordered_hash dirty_meta_mgrs = Ordered_hash_.New_bry();

@ -121,7 +121,7 @@ public class Xog_bnd_mgr {
Init_itm(Xog_cmd_itm_.Key_gui_page_view_reload , Xog_bnd_box_.Tid_browser , "key.f5");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_refresh , Xog_bnd_box_.Tid_browser , "mod.s+key.f5");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_save_as , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_print , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_view_print , Xog_bnd_box_.Tid_browser , "mod.c+key.p");
Init_itm(Xog_cmd_itm_.Key_gui_page_selection_select_all , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_selection_copy , Xog_bnd_box_.Tid_browser , "");
Init_itm(Xog_cmd_itm_.Key_gui_page_selection_save_file_as , Xog_bnd_box_.Tid_browser , "");

@ -15,22 +15,24 @@ 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.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
package gplx.xowa.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
import gplx.xowa.xtns.gallery.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.guis.views.*;
import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.guis.views.*; import gplx.xowa.parsers.lnkis.*;
public class Js_img_mgr {
public static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Xof_file_itm itm) {
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_view_url(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url(), itm.Orig_ttl(), itm.Html_gallery_mgr_h());
}
public static void Update_link_missing(Xog_js_wkr html_itm, String html_id) {
html_itm.Html_redlink(html_id);
}
private static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Js_img_wkr img_wkr, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Io_url html_orig_url, byte[] lnki_ttl, int gallery_mgr_h) {
public static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Xof_file_itm itm) {
Js_img_mgr.Update_img(page, js_wkr, itm.Html_img_wkr(), itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_view_url()
, itm.Orig_w(), itm.Orig_h(), itm.Orig_ext(), itm.Html_orig_url(), itm.Orig_ttl(), itm.Html_gallery_mgr_h());
}
private static void Update_img(Xoa_page page, Xog_js_wkr js_wkr, Js_img_wkr img_wkr, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, Io_url html_view_url
, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl, int gallery_mgr_h) {
if (!page.Wiki().App().Mode().Tid_supports_js()) return; // do not update html widget unless app is gui; null ref on http server; DATE:2014-09-17
switch (elem_tid) {
case Xof_html_elem.Tid_gallery_v2:
img_wkr.Js_wkr__update_hdoc(page, js_wkr, uid, html_w, html_h, html_view_url, orig_w, orig_h, html_orig_url, lnki_ttl);
img_wkr.Js_wkr__update_hdoc(page, js_wkr, uid, html_w, html_h, html_view_url, orig_w, orig_h, orig_ext, html_orig_url, lnki_ttl);
return;
}
String html_id = To_doc_uid(uid);
@ -41,10 +43,10 @@ public class Js_img_mgr {
}
switch (elem_tid) {
case Xof_html_elem.Tid_gallery:
js_wkr.Html_atr_set("xowa_gallery_div3_" + uid, "style", "margin:" + Gallery_html_wtr_utl.Calc_vpad(gallery_mgr_h, html_h) + "px auto;");
js_wkr.Html_atr_set("xowa_gallery_div3_" + uid, "style", "margin:" + Gallery_mgr_wtr_.Calc_vpad(gallery_mgr_h, html_h) + "px auto;");
break;
case Xof_html_elem.Tid_imap:
img_wkr.Js_wkr__update_hdoc(page, js_wkr, uid, html_w, html_h, html_view_url, orig_w, orig_h, html_orig_url, lnki_ttl);
img_wkr.Js_wkr__update_hdoc(page, js_wkr, uid, html_w, html_h, html_view_url, orig_w, orig_h, orig_ext, html_orig_url, lnki_ttl);
break;
case Xof_html_elem.Tid_vid:
String html_id_vid = "xowa_file_play_" + uid;

@ -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.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.guis.views.*;
package gplx.xowa.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
import gplx.xowa.files.*;
public interface Js_img_wkr {
void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Io_url html_orig_url, byte[] lnki_ttl);
void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url
, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl);
}

@ -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.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
package gplx.xowa.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
public interface Xog_js_wkr {
void Html_img_update (String uid, String src, int w, int h);
void Html_redlink (String html_uid);

@ -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.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
package gplx.xowa.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
public class Xog_js_wkr_ {
public static final Xog_js_wkr Noop = new Xog_js_wkr__noop();
}

@ -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.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
package gplx.xowa.guis.cbks.js; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*; import gplx.xowa.guis.cbks.*;
public class Xog_js_wkr__log implements Xog_js_wkr {
private final List_adp log_list = List_adp_.New();
public void Html_img_update (String uid, String src, int w, int h) {log_list.Add(Object_.Ary(Proc_img_update, uid, src, w, h));}

@ -75,7 +75,7 @@ public class Xog_url_wkr {
Xof_fsdb_itm fsdb = Xof_orig_file_downloader.Make_fsdb(wiki, lnki_ttl, img_size, url_bldr);
if (!Io_mgr.Instance.ExistsFil(href_url)) {
// if (!Xof_orig_file_downloader.Get_to_url(fsdb, href_url, wiki, lnki_ttl, url_bldr))
if (!Xof_file_wkr.Show_img(fsdb, Xoa_app_.Usr_dlg(), wiki.File__bin_mgr(), wiki.File__mnt_mgr(), wiki.App().User().User_db_mgr().Cache_mgr(), wiki.File__repo_mgr(), gplx.xowa.files.gui.Xog_js_wkr_.Noop, img_size, url_bldr, page))
if (!Xof_file_wkr.Show_img(fsdb, Xoa_app_.Usr_dlg(), wiki.File__bin_mgr(), wiki.File__mnt_mgr(), wiki.App().User().User_db_mgr().Cache_mgr(), wiki.File__repo_mgr(), gplx.xowa.guis.cbks.js.Xog_js_wkr_.Noop, img_size, url_bldr, page))
return Rslt_handled;
}
gplx.core.ios.IoItmFil fil = Io_mgr.Instance.QueryFil(href_url);

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.guis.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.threads.*;
import gplx.xowa.wikis.pages.lnkis.*;
import gplx.xowa.files.gui.*;
import gplx.xowa.guis.cbks.js.*;
public class Xog_async_wkr {
public static void Async(Xog_tab_itm tab) {Xog_async_wkr.Async(tab.Page(), tab.Html_itm());}
public static void Async(Xoae_page page, Xog_html_itm js_wkr) {

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.guis.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
import gplx.xowa.guis.menus.*; import gplx.xowa.guis.menus.dom.*; import gplx.xowa.files.gui.*;
import gplx.xowa.guis.menus.*; import gplx.xowa.guis.menus.dom.*; import gplx.xowa.guis.cbks.js.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.js.*; import gplx.xowa.htmls.heads.*; import gplx.xowa.wikis.pages.*;
public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
private Xoae_app app; private final Object thread_lock = new Object();
@ -33,12 +33,12 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
cmd_async = kit.New_cmd_async(this);
ev_mgr = new Gfo_evt_mgr(this);
}
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr;
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr;
public Xog_tab_itm Owner_tab() {return owner_tab;} private Xog_tab_itm owner_tab;
public Gfui_html Html_box() {return html_box;} private Gfui_html html_box;
public Xoh_js_cbk Js_cbk() {return js_cbk;} private Xoh_js_cbk js_cbk;
public Gfo_invk Cmd_sync() {return cmd_sync;} private Gfo_invk cmd_sync;
public Gfo_invk Cmd_async() {return cmd_async;} private Gfo_invk cmd_async;
public Gfo_invk Cmd_sync() {return cmd_sync;} private Gfo_invk cmd_sync;
public Gfo_invk Cmd_async() {return cmd_async;} private Gfo_invk cmd_async;
public void Switch_mem(Xog_html_itm comp) {
Xog_tab_itm temp_owner_tab = owner_tab; // NOTE: reparent owner_tab, since owner_tab will be switching its html_itm
this.owner_tab = comp.owner_tab;
@ -47,6 +47,7 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
public void Html_box_(Gfui_html html_box) {
this.html_box = html_box;
html_box.Html_js_cbks_add("xowa_exec", js_cbk);
Gfo_evt_mgr_.Sub_same(html_box, Gfui_html.Evt_zoom_changed, this);
}
public String Html_selected_get_src_or_empty() {return html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_src_or_empty);}
public String Html_selected_get_href_or_text() {return Html_extract_text(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Selection__get_href_or_text));}
@ -188,6 +189,9 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
popup_mnu = popup_mnu_mgr.Html_link();
kit.Set_mnu_popup(html_box, popup_mnu.Under_mnu());
}
private void When_zoom_changed(boolean clicks_is_positive) {
app.Api_root().Gui().Font().Adj(clicks_is_positive ? 1 : -1);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_html_img_update)) html_box.Html_js_eval_proc_as_bool (Xog_js_procs.Doc__elem_img_update , m.ReadStr("elem_id"), m.ReadStr("elem_src"), m.ReadInt("elem_width"), m.ReadInt("elem_height"));
else if (ctx.Match(k, Invk_html_elem_atr_set)) html_box.Html_js_eval_proc_as_str (Xog_js_procs.Doc__atr_set , m.ReadStr("elem_id"), m.ReadStr("atr_key"), m.ReadStr("atr_val"));
@ -201,6 +205,7 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
else if (ctx.Match(k, Invk_scroll_page_by_id)) Scroll_page_by_id(m.ReadStr("v"));
else if (ctx.Match(k, Invk_html_elem_focus)) html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__elem_focus, m.ReadStr("v"));
else if (ctx.Match(k, GfuiElemKeys.Evt_menu_detected)) When_menu_detected();
else if (ctx.Match(k, Gfui_html.Evt_zoom_changed)) When_zoom_changed(m.ReadBool("clicks_is_positive"));
else return Gfo_invk_.Rv_unhandled;
return this;
}

@ -79,6 +79,7 @@ public class Xog_layout implements Gfo_invk {
find_bwd_btn.Adj_text(win.Find_bwd_btn());
prog_box.Adj_text(win.Prog_box());
note_box.Adj_text(win.Info_box());
win.Tab_mgr().Tab_mgr().TextMgr().Font_(win.Url_box().TextMgr().Font());
Visible_(false, win.Find_box(), win.Find_bwd_btn(), win.Find_fwd_btn(), win.Find_close_btn());
} private Xog_win_itm win;
public int Box_height_calc(Gfui_kit kit, GfuiElem url_box) {

@ -32,6 +32,7 @@ public class Xog_layout_box implements Gfo_invk {
public float Font_size() {return font_size;} public Xog_layout_box Font_size_(float v) {font_size = v; return this;} float font_size = Float_.NaN;
public FontStyleAdp Font_style() {return font_style;} public Xog_layout_box Font_style_(FontStyleAdp v) {font_style = v; return this;} FontStyleAdp font_style;
public byte Mode() {return mode;} public Xog_layout_box Mode_(byte v) {mode = v; return this;} private byte mode = Mode_rel;
public FontAdp To_font() {return Font_make(font_name, font_size, font_style);}
public void Adj_size(Rect_ref rect) {
if (w_abs > -1) rect.W_(w_abs); if (w_rel != Int_.Min_value) rect.W_(w_rel + rect.W());
if (h_abs > -1) rect.H_(h_abs); if (h_rel != Int_.Min_value) rect.H_(h_rel + rect.H());
@ -74,7 +75,7 @@ public class Xog_layout_box implements Gfo_invk {
, Invk_size_abs_ = "size_abs_", Invk_pos_abs_ = "pos_abs_", Invk_rect_abs_ = "rect_abs_", Invk_size_rel_ = "size_rel_", Invk_pos_rel_ = "pos_rel_", Invk_rect_rel_ = "rect_rel_"
, Invk_text_ = "text_"
, Invk_font_name_ = "font_name_", Invk_font_size_ = "font_size_", Invk_font_style_ = "font_style_", Invk_mode_ = "mode_", Invk_owner = "owner";
FontAdp Font_make(String font_name, float font_size, FontStyleAdp font_style) {
private static FontAdp Font_make(String font_name, float font_size, FontStyleAdp font_style) {
String new_font_name = font_name == null ? "Arial" : font_name;
float new_font_size = Float_.IsNaN(font_size) ? 8 : font_size;
FontStyleAdp new_font_style = font_style == null ? FontStyleAdp_.Plain : font_style;

@ -197,7 +197,7 @@ public class Xog_tab_itm implements Gfo_invk {
this.tab_is_loading = false;
}
}
public void Exec_async_hdump(Xoa_app app, Xow_wiki wiki, gplx.xowa.files.gui.Xog_js_wkr js_wkr, gplx.core.threads.Gfo_thread_pool thread_pool, Xoa_page page, List_adp imgs, int[] redlink_ary) {
public void Exec_async_hdump(Xoa_app app, Xow_wiki wiki, gplx.xowa.guis.cbks.js.Xog_js_wkr js_wkr, gplx.core.threads.Gfo_thread_pool thread_pool, Xoa_page page, List_adp imgs, int[] redlink_ary) {
if (imgs.Count() > 0) {
Xof_file_wkr file_thread = new Xof_file_wkr
( wiki.File__orig_mgr(), wiki.File__bin_mgr(), wiki.File__mnt_mgr()

@ -72,7 +72,7 @@ public class Xoh_html_wtr {
break;
case Xop_tkn_itm_.Tid_ignore: break;
case Xop_tkn_itm_.Tid_html_ncr: Html_ncr(ctx, hctx, bfr, src, (Xop_amp_tkn_num)tkn); break;
case Xop_tkn_itm_.Tid_html_ref: Html_ref(ctx, hctx, bfr, src, (Xop_amp_tkn_txt)tkn); break;
case Xop_tkn_itm_.Tid_html_ref: Html_ref(ctx, hctx, bfr, src, (Xop_amp_tkn_ent)tkn); break;
case Xop_tkn_itm_.Tid_hr: Hr(ctx, hctx, bfr, src, (Xop_hr_tkn)tkn); break;
case Xop_tkn_itm_.Tid_apos: Apos(ctx, hctx, bfr, src, (Xop_apos_tkn)tkn); break;
case Xop_tkn_itm_.Tid_lnki: lnki_wtr.Write_lnki(bfr, hctx, src, (Xop_lnki_tkn)tkn); break;
@ -101,7 +101,7 @@ public class Xoh_html_wtr {
public void Html_ncr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_num tkn) {
bfr.Add_byte(Byte_ascii.Amp).Add_byte(Byte_ascii.Hash).Add_int_variable(tkn.Val()).Add_byte(Byte_ascii.Semic); // NOTE: do not literalize, else browser may not display multi-char bytes properly; EX: &#160; gets added as &#160; not as {192,160}; DATE:2013-12-09
}
public void Html_ref(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_txt tkn) {
public void Html_ref(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_ent tkn) {
if (tkn.Itm_is_custom()) // used by <nowiki>; EX:<nowiki>&#60;</nowiki> -> &xowa_lt; DATE:2014-11-07
tkn.Print_literal(bfr);
else

@ -62,14 +62,15 @@ public class Xoh_html_wtr_escaper {
i = match_pos - 1;
break;
case Xop_amp_trie_itm.Tid_num_dec:
case Xop_amp_trie_itm.Tid_num_hex: // ncr: dec/hex
boolean pass = amp_mgr.Parse_as_int(itm_tid == Xop_amp_trie_itm.Tid_num_hex, src, end, i, match_pos);
int end_pos = amp_mgr.Rslt_pos();
if (pass) { // parse worked; embed entire ncr
case Xop_amp_trie_itm.Tid_num_hex: // ncr: dec/hex; escape if invalid
Xop_amp_mgr_rslt rslt = new Xop_amp_mgr_rslt();
boolean pass = amp_mgr.Parse_ncr(rslt, itm_tid == Xop_amp_trie_itm.Tid_num_hex, src, end, i, match_pos);
if (pass) { // parse worked; embed entire ncr; EX: "&#123;"
int end_pos = rslt.Pos();
bfr.Add_mid(src, i, end_pos);
i = end_pos - 1;
}
else // parse failed; escape and continue
else // parse failed; escape and continue; EX: "&#a!b;"
bfr.Add(Gfh_entity_.Amp_bry);
break;
default: throw Err_.new_unhandled(itm_tid);

@ -106,26 +106,26 @@ public class Xoh_make_mgr {
case Xoh_make_trie_.Tid__gallery_box_max: {
Xohd_img_itm__gallery_mgr gly = (Xohd_img_itm__gallery_mgr)hpg.Gallery_itms().Get_by(uid);
if (gly != null) { // -1 means no box_max
byte[] style = Gallery_html_wtr_.Fmtr__ul__style.Bld_bry_many(tmp_bfr, gly.Box_max());
byte[] style = Gallery_mgr_wtr_.Fmtr__ul__style.Bld_bry_many(tmp_bfr, gly.Box_max());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
}
return rv;
}
case Xoh_make_trie_.Tid__gallery_box_w: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_html_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
byte[] style = Gallery_mgr_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
case Xoh_make_trie_.Tid__gallery_img_w: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_html_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
byte[] style = Gallery_mgr_wtr_.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}
case Xoh_make_trie_.Tid__gallery_img_pad: {
Xohd_img_itm__gallery_itm gly = (Xohd_img_itm__gallery_itm)img;
byte[] style = Gallery_html_wtr_.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
byte[] style = Gallery_mgr_wtr_.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
Gfh_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Gfh_atr_.Bry__style, style);
return rv;
}

@ -23,7 +23,7 @@ public class Xoh_make_trie_ {
, Tid__hiero_dir = 7, Tid__gallery_box_max = 8, Tid__gallery_box_w = 9, Tid__gallery_img_w = 10, Tid__gallery_img_pad = 11
, Tid__toc = 12, Tid__hdr = 13
;
public static final byte[]
public static final byte[]
Bry__dir = Bry_.new_a7("~{xowa_dir}")
, Bry__img = Bry_.new_a7("xowa_img=\"")
, Bry__img_style = Bry_.new_a7("xowa_img_style=\"")
@ -37,7 +37,7 @@ public class Xoh_make_trie_ {
// , Bry__gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
, Bry__toc = Bry_.new_a7("~{xowa_toc}")
;
public static final byte[]
public static final byte[]
A_href_bgn = Bry_.new_a7("/wiki/File:")
, Bry_img_style_bgn = Bry_.new_a7("style='width:")
, Bry_img_style_end = Bry_.new_a7("px;'")

@ -22,6 +22,7 @@ public class Bfr_arg__hatr_id implements Bfr_arg_clearable {
private final byte[] bry; private int num;
public Bfr_arg__hatr_id(byte[] atr_key, byte[] bry) {this.bry = bry; this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(atr_key);}
public Bfr_arg__hatr_id Set(int num) {this.num = num; return this;}
public byte[] Get_id_val() {return Bry_.Add(bry, Int_.To_bry(num));}
public void Bfr_arg__clear() {num = -1;}
public boolean Bfr_arg__missing() {return num == -1;}
public void Bfr_arg__add(Bry_bfr bfr) {

@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.langs.htmls.*;
class Bfr_arg__elem__capt implements gplx.core.brys.Bfr_arg_clearable {
private byte[] capt;
public Bfr_arg__elem__capt() {
this.Clear();
}
public void Capt_(byte[] v) {this.capt = v;}
public void Clear() {capt = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return capt == null;}
public void Bfr_arg__add(Bry_bfr bfr) { // EX: '\n<li class="gallerycaption">Z</li>'
if (Bfr_arg__missing()) return;
bfr.Add_byte_nl();
bfr.Add(Gfh_tag_.Li_lhs_bgn); // '<li'
Gfh_atr_.Add(bfr, Gfh_atr_.Bry__class, Xoh_gly_grp_data.Atr__cls__gallerycaption); // ' class="gallerycaption"'
bfr.Add_byte(Byte_ascii.Angle_end); // '>'
bfr.Add(capt);
bfr.Add(Gfh_tag_.Li_rhs); // '</li>'
}
}

@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Bfr_arg__hatr__style implements gplx.core.brys.Bfr_arg {
private final byte[] atr_bgn;
private int max_w, w;
private byte[] xtra_cls;
public Bfr_arg__hatr__style(byte[] key) {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);
this.Clear();
}
public void Set_args(int max_w, int w, byte[] xtra_cls) {this.max_w = max_w; this.w = w; this.xtra_cls = xtra_cls;}
public void Clear() {max_w = 0; w = 0; xtra_cls = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return max_w == 0 && xtra_cls == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
if (max_w > 0) {
bfr.Add(Style__frag_1);
bfr.Add_int_variable(max_w);
bfr.Add(Style__frag_3);
}
if (w > 0) {
bfr.Add_byte_space();
bfr.Add(Style__frag_2);
bfr.Add_int_variable(w);
bfr.Add(Style__frag_3);
}
if (xtra_cls != null) {
bfr.Add(xtra_cls);
}
bfr.Add_byte_quote();
}
private static final byte[]
Style__frag_1 = Bry_.new_a7("max-width:")
, Style__frag_2 = Bry_.new_a7("_width:")
, Style__frag_3 = Bry_.new_a7("px;")
;
}

@ -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.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Bfr_arg__hatr__xogly implements gplx.core.brys.Bfr_arg_clearable {
private final byte[] atr_bgn;
private int xnde_w, xnde_h, xnde_per_row;
public Bfr_arg__hatr__xogly() {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(gplx.xowa.xtns.gallery.Gallery_mgr_wtr.Bry__data_xogly);
this.Clear();
}
public void Set_args(int xnde_w, int xnde_h, int xnde_per_row) {
this.xnde_w = xnde_w; this.xnde_h = xnde_h; this.xnde_per_row = xnde_per_row;
}
public void Clear() {xnde_w = xnde_h = xnde_per_row = -1;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;} // NOTE: do not check if "xnde_w == -1 && xnde_h == -1 && xnde_per_row == -1" else will fail hzip diff; DATE:2016-07-02
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
bfr.Add_int_variable(xnde_w).Add_byte_pipe();
bfr.Add_int_variable(xnde_h).Add_byte_pipe();
bfr.Add_int_variable(xnde_per_row);
bfr.Add_byte_quote();
}
}

@ -22,31 +22,38 @@ import gplx.xowa.htmls.core.hzips.*;
import gplx.xowa.xtns.gallery.*;
public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { // FUTURE:add gallerycaption
private final List_adp itms_list = List_adp_.New();
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Gly_tid() {return gly_tid;} private int gly_tid;
public int Ul_style_max_w() {return ul_style_max_w;} private int ul_style_max_w;
public int Ul_style_w() {return ul_style_w;} private int ul_style_w;
public int Xtra_atr_bgn() {return xtra_atr_bgn;} private int xtra_atr_bgn;
public int Xtra_atr_end() {return xtra_atr_end;} private int xtra_atr_end;
public boolean Xtra_atr_exists() {return xtra_atr_end > xtra_atr_bgn;}
public int Xtra_cls_bgn() {return xtra_cls_bgn;} private int xtra_cls_bgn;
public int Xtra_cls_end() {return xtra_cls_end;} private int xtra_cls_end;
public boolean Xtra_cls_exists() {return xtra_cls_end > xtra_cls_bgn;}
public int Xtra_style_bgn() {return xtra_style_bgn;} private int xtra_style_bgn;
public int Xtra_style_end() {return xtra_style_end;} private int xtra_style_end;
public boolean Xtra_style_exists() {return xtra_style_end > xtra_style_bgn;}
public int Itms__len() {return itms_list.Count();}
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
public int Gly_tid() {return gly_tid;} private int gly_tid;
public int Xnde_w() {return xnde_w;} private int xnde_w;
public int Xnde_h() {return xnde_h;} private int xnde_h;
public int Xnde_per_row() {return xnde_per_row;} private int xnde_per_row;
public int Ul_style_max_w() {return ul_style_max_w;} private int ul_style_max_w;
public int Ul_style_w() {return ul_style_w;} private int ul_style_w;
public int Xtra_atr_bgn() {return xtra_atr_bgn;} private int xtra_atr_bgn;
public int Xtra_atr_end() {return xtra_atr_end;} private int xtra_atr_end;
public boolean Xtra_atr_exists() {return xtra_atr_end > xtra_atr_bgn;}
public int Xtra_cls_bgn() {return xtra_cls_bgn;} private int xtra_cls_bgn;
public int Xtra_cls_end() {return xtra_cls_end;} private int xtra_cls_end;
public boolean Xtra_cls_exists() {return xtra_cls_end > xtra_cls_bgn;}
public int Xtra_style_bgn() {return xtra_style_bgn;} private int xtra_style_bgn;
public int Xtra_style_end() {return xtra_style_end;} private int xtra_style_end;
public boolean Xtra_style_exists() {return xtra_style_end > xtra_style_bgn;}
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
public int Capt_end() {return capt_end;} private int capt_end;
public int Itms__len() {return itms_list.Count();}
public Xoh_gly_itm_data Itms__get_at(int i) {return (Xoh_gly_itm_data)itms_list.Get_at(i);}
private void Clear() {
this.gly_tid = Byte_.Max_value_127;
this.ul_style_max_w = ul_style_w = 0;
this.xtra_atr_bgn = xtra_atr_end = xtra_cls_bgn = xtra_cls_end = xtra_style_bgn = xtra_style_end = -1;
this.xnde_per_row = xnde_w = xnde_h = capt_bgn = capt_end = -1;
itms_list.Clear();
}
public boolean Parse1(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
this.Clear();
this.src_bgn = ul_head.Src_bgn();
if (!Parse_xogly(src, tag_rdr, ul_head)) return false;
if (!Parse_cls (src, tag_rdr, ul_head)) return false;
if (!Parse_style(src, tag_rdr, ul_head)) return false;
Parse_ul_atrs(src, tag_rdr, ul_head);
@ -55,10 +62,16 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
li_head = tag_rdr.Tag__peek_fwd_head();
if (li_head.Name_id() != Gfh_tag_.Id__li) break; // no more <li>; break;
// FUTURE: galleries with gallerycaption will cause gallery to write raw; instate code below, but would need to then serialize "gallerycaption"; PAGE:en.d:A DATE:2016-06-24
// if (li_head.Atrs__cls_has(Atr__cls__gallerycaption)) {// skip <li class='gallerycaption'>A</li>
// li_head = tag_rdr.Tag__move_fwd_head();
// li_head = tag_rdr.Tag__peek_fwd_head();
// }
if (li_head.Atrs__cls_has(Atr__cls__gallerycaption)) {// skip <li class='gallerycaption'>A</li>
// extract caption between <li></li>
li_head = tag_rdr.Tag__move_fwd_head();
this.capt_bgn = li_head.Src_end();
Gfh_tag li_tail = tag_rdr.Tag__move_fwd_tail(li_head.Name_id());
this.capt_end = li_tail.Src_bgn();
// move tag_rdr to next <li>
li_head = tag_rdr.Tag__peek_fwd_head();
}
if (!li_head.Atrs__cls_has(Atr__cls__gallerybox)) return false;
tag_rdr.Pos_(li_head.Src_end());
Xoh_gly_itm_data itm_parser = new Xoh_gly_itm_data();
@ -71,6 +84,25 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
hdoc_wkr.On_gly(this);
return true;
}
private boolean Parse_xogly(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
Gfh_atr atr = ul_head.Atrs__get_by_or_empty(Gallery_mgr_wtr.Bry__data_xogly);
byte[] val = atr.Val(); int val_len = val.length;
if (val_len == 0) return true; // ignore missing "data-xogly"
int pos = 0;
for (int i = 0; i < 3; ++i) {
int bgn = pos;
int end = Bry_find_.Find_fwd(val, Byte_ascii.Pipe, bgn + 1, val_len);
if (end == Bry_find_.Not_found) end = val_len;
int num = Bry_.To_int_or(val, bgn, end, -1);
pos = end + 1;
switch (i) {
case 0: xnde_w = num; break;
case 1: xnde_h = num; break;
case 2: xnde_per_row = num; break;
}
}
return true;
}
private boolean Parse_cls(byte[] src, Gfh_tag_rdr tag_rdr, Gfh_tag ul_head) {
Gfh_atr ul_cls = ul_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__class);
Gfh_class_parser_.Parse(src, ul_cls.Val_bgn(), ul_cls.Val_end(), this);
@ -89,9 +121,7 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
int atrs_len = ul_head.Atrs__len();
for (int i = 0; i < atrs_len; ++i) {
Gfh_atr hatr = ul_head.Atrs__get_at(i);
if (Bry_.Eq(hatr.Key(), Gfh_atr_.Bry__class)) {}
else if (Bry_.Eq(hatr.Key(), Gfh_atr_.Bry__style)) {}
else {
if (atrs_ignored.Get_by_bry(hatr.Key()) == null) {
if (xtra_atr_bgn == -1) this.xtra_atr_bgn = hatr.Atr_bgn();
this.xtra_atr_end = hatr.Atr_end();
}
@ -104,7 +134,7 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
else if (Bry_.Match(src, val_bgn, val_bgn + Atr__cls__mw_gallery.length, Atr__cls__mw_gallery) // starts with 'mw-gallery-'
&& val_pos == 8) { // occurs after "gallery "
int tid_bgn = val_bgn + Atr__cls__mw_gallery.length;
this.gly_tid = Gallery_mgr_base_.Hash.Get_as_byte_or(src, tid_bgn, val_end, Byte_.Max_value_127);
this.gly_tid = Gallery_mgr_base_.To_tid_or(src, tid_bgn, val_end, Byte_.Max_value_127);
return true;
}
else {
@ -135,8 +165,16 @@ public class Xoh_gly_grp_data implements Gfh_class_parser_wkr, Gfh_style_wkr { /
return true;
}
public static final byte[] Atr__cls__gallery = Bry_.new_a7("gallery");
private static final byte[] Atr__cls__mw_gallery = Bry_.new_a7("mw-gallery-"), Atr__cls__gallerybox = Bry_.new_a7("gallerybox")
// , Atr__cls__gallerycaption = Bry_.new_a7("gallerycaption")
private static final byte[] Atr__cls__mw_gallery = Bry_.new_a7("mw-gallery-"), Atr__cls__gallerybox = Bry_.new_a7("gallerybox")
, Style__max_width = Bry_.new_a7("max-width"), Style___width = Bry_.new_a7("_width")
;
public static final byte[] Atr__cls__gallerycaption = Bry_.new_a7("gallerycaption");
private static final Hash_adp_bry atrs_ignored = Make_atrs_ignored();
private static Hash_adp_bry Make_atrs_ignored() {
Hash_adp_bry rv = Hash_adp_bry.ci_a7();
rv.Add_as_key_and_val(Gfh_atr_.Bry__class);
rv.Add_as_key_and_val(Gfh_atr_.Bry__style);
rv.Add_as_key_and_val(Gallery_mgr_wtr.Bry__data_xogly);
return rv;
}
}

@ -20,21 +20,26 @@ import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*;
class Xoh_gly_grp_wtr implements Bfr_arg {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_id ul_id = Bfr_arg__hatr_id.New_id("xogly_li_");
private final Bfr_arg__hatr_gly_style ul_style = new Bfr_arg__hatr_gly_style(Gfh_atr_.Bry__style);
private final Bfr_arg__hatr_id ul_id = Bfr_arg__hatr_id.New_id("xogly_ul_");
private final Bfr_arg__hatr__style ul_style = new Bfr_arg__hatr__style(Gfh_atr_.Bry__style);
private final Bfr_arg__hatr__xogly ul_xogly = new Bfr_arg__hatr__xogly();
private final Bfr_arg__elem__capt li_capt = new Bfr_arg__elem__capt();
private byte[] ul_cls, xtra_cls, xtra_atr_bry, ul_nl;
private final Xoh_gly_itm_list_wtr itm_list_wtr = new Xoh_gly_itm_list_wtr();
public Xoh_gly_grp_wtr() {
arg_ary = new Bfr_arg_clearable[] {ul_id};
arg_ary = new Bfr_arg_clearable[] {ul_id, ul_xogly, li_capt};
}
public void Init(boolean mode_is_diff, int id, byte[] cls, int ul_style_max_w, int ul_style_w, byte[] xtra_cls, byte[] xtra_style_bry, byte[] xtra_atr_bry, Xoh_gly_itm_wtr[] ary) {
public void Init(boolean mode_is_diff, int id, int xnde_w, int xnde_h, int xnde_per_row, byte[] cls, int ul_style_max_w, int ul_style_w
, byte[] xtra_cls, byte[] xtra_style_bry, byte[] xtra_atr_bry, byte[] capt, Xoh_gly_itm_wtr[] ary) {
this.Clear();
if (!mode_is_diff)
ul_id.Set(id);
ul_xogly.Set_args(xnde_w, xnde_h, xnde_per_row);
this.ul_cls = cls;
this.xtra_cls = xtra_cls == null ? Bry_.Empty : Bry_.Add(Byte_ascii.Space_bry, xtra_cls);
this.xtra_atr_bry = xtra_atr_bry;
this.ul_nl = ary.length == 0 ? Bry_.Empty : Byte_ascii.Nl_bry; // TIDY: <ul></ul> should be on same line if 0 items
li_capt.Capt_(capt);
itm_list_wtr.Init(ary);
ul_style.Set_args(ul_style_max_w, ul_style_w, xtra_style_bry);
}
@ -48,11 +53,11 @@ class Xoh_gly_grp_wtr implements Bfr_arg {
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, ul_id, ul_cls, xtra_cls, ul_style, xtra_atr_bry, itm_list_wtr, ul_nl);
fmtr.Bld_bfr_many(bfr, ul_id, ul_xogly, ul_cls, xtra_cls, ul_style, xtra_atr_bry, li_capt, itm_list_wtr, ul_nl);
}
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<ul~{id} class=\"gallery mw-gallery-~{cls}~{xtra_cls}\"~{style}~{xtra_atr}>~{itms}~{ul_nl}</ul>"
), "id", "cls", "xtra_cls", "style", "xtra_atr", "itms", "ul_nl");
( "<ul~{id}~{xogly} class=\"gallery mw-gallery-~{cls}~{xtra_cls}\"~{style}~{xtra_atr}>~{capt}~{itms}~{ul_nl}</ul>"
), "id", "xogly", "cls", "xtra_cls", "style", "xtra_atr", "capt", "itms", "ul_nl");
}
class Xoh_gly_itm_list_wtr implements Bfr_arg {
private Xoh_gly_itm_wtr[] ary; private int ary_len;
@ -72,40 +77,3 @@ class Xoh_gly_itm_list_wtr implements Bfr_arg {
}
}
}
class Bfr_arg__hatr_gly_style implements Bfr_arg {
private final byte[] atr_bgn;
private int max_w, w;
private byte[] xtra_cls;
public Bfr_arg__hatr_gly_style(byte[] key) {
this.atr_bgn = Bfr_arg__hatr_.Bld_atr_bgn(key);
this.Clear();
}
public void Set_args(int max_w, int w, byte[] xtra_cls) {this.max_w = max_w; this.w = w; this.xtra_cls = xtra_cls;}
public void Clear() {max_w = 0; w = 0; xtra_cls = null;}
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return max_w == 0 && xtra_cls == null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__missing()) return;
bfr.Add(atr_bgn);
if (max_w > 0) {
bfr.Add(Style__frag_1);
bfr.Add_int_variable(max_w);
bfr.Add(Style__frag_3);
}
if (w > 0) {
bfr.Add_byte_space();
bfr.Add(Style__frag_2);
bfr.Add_int_variable(w);
bfr.Add(Style__frag_3);
}
if (xtra_cls != null) {
bfr.Add(xtra_cls);
}
bfr.Add_byte_quote();
}
private static final byte[]
Style__frag_1 = Bry_.new_a7("max-width:")
, Style__frag_2 = Bry_.new_a7("_width:")
, Style__frag_3 = Bry_.new_a7("px;")
;
}

@ -17,9 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
public class Xoh_gly_html__dump__tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Before public void init() {fxt.Clear();}
public class Xoh_gly_html__dump__tst {
@Before public void init() {fxt.Clear();} private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Test public void Basic() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery>"
@ -27,7 +26,7 @@ public class Xoh_gly_html__dump__tst {
, "File:B.png|B1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, " <li class='gallerybox' style='width:155px;'>"
, " <div style='width:155px;'>"
, " <div class='thumb' style='width:150px;'>"
@ -56,4 +55,52 @@ public class Xoh_gly_html__dump__tst {
, " </li>"
, "</ul>"));
}
@Test public void Atrs() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery perrow='5' widths='200' heights='300'>"
, "File:A.png|A1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul data-xogly='200|300|5' class='gallery mw-gallery-traditional' style='max-width:1215px; _width:1215px;'>"
, " <li class='gallerybox' style='width:235px;'>"
, " <div style='width:235px;'>"
, " <div class='thumb' style='width:230px;'>"
, " <div style='margin:15px auto;'>"
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg='0|200|300|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"));
}
@Test public void Packed() {
fxt.Test__html(String_.Concat_lines_nl_skip_last
( "<gallery mode='packed'>"
, "File:A.png|A1"
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-packed'>"
, " <li class='gallerybox' style='width:1302px;'>"
, " <div style='width:1302px;'>"
, " <div class='thumb' style='width:1300px;'>"
, " <div style='margin:0px auto;'>"
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg='0|1950|180|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
, " </div>"
, " </div>"
, " <div class='gallerytext'><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"));
}
// case Gallery_xnde_atrs.Mode_tid: mode = Gallery_mgr_base_.Get_or_traditional(xatr.Val_as_bry()); break;
// case Gallery_xnde_atrs.Perrow_tid: itms_per_row = xatr.Val_as_int_or(Null); break;
// case Gallery_xnde_atrs.Widths_tid: itm_w = xatr.Val_as_int_or(Null); break;
// case Gallery_xnde_atrs.Heights_tid: itm_h = xatr.Val_as_int_or(Null); break;
}

@ -30,19 +30,27 @@ public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
Xoh_gly_grp_data data = (Xoh_gly_grp_data)data_obj;
int ul_style_max_w = data.Ul_style_max_w(), ul_style_w = data.Ul_style_w();
boolean ul_style_w_diff = flag_bldr.Set_as_bool(Flag__ul__style_w_diff , ul_style_max_w != ul_style_w);
boolean xtra_atr = flag_bldr.Set_as_bool(Flag__ul__xtra_atr , data.Xtra_atr_exists());
boolean xtra_cls = flag_bldr.Set_as_bool(Flag__ul__xtra_cls , data.Xtra_cls_exists());
boolean xtra_style = flag_bldr.Set_as_bool(Flag__ul__xtra_style , data.Xtra_style_exists());
boolean xnde_w = flag_bldr.Set_as_bool(Flag__xnde__w , data.Xnde_w() != -1);
boolean xnde_h = flag_bldr.Set_as_bool(Flag__xnde__h , data.Xnde_h() != -1);
boolean xnde_per_row = flag_bldr.Set_as_bool(Flag__xnde__per_row , data.Xnde_per_row() != -1);
boolean capt_exists = flag_bldr.Set_as_bool(Flag__xnde__caption , data.Capt_bgn() != -1);
boolean ul_style_w_diff = flag_bldr.Set_as_bool(Flag__ul__style_w_diff , ul_style_max_w != ul_style_w);
boolean xtra_atr = flag_bldr.Set_as_bool(Flag__ul__xtra_atr , data.Xtra_atr_exists());
boolean xtra_cls = flag_bldr.Set_as_bool(Flag__ul__xtra_cls , data.Xtra_cls_exists());
boolean xtra_style = flag_bldr.Set_as_bool(Flag__ul__xtra_style , data.Xtra_style_exists());
flag_bldr.Set(Flag__gly_tid, data.Gly_tid());
int itms_len = data.Itms__len();
bfr.Add(hook);
Gfo_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
Gfo_hzip_int_.Encode(1, bfr, ul_style_max_w);
if (xnde_w) Gfo_hzip_int_.Encode(4, bfr, data.Xnde_w());
if (xnde_h) Gfo_hzip_int_.Encode(4, bfr, data.Xnde_h());
if (xnde_per_row) Gfo_hzip_int_.Encode(1, bfr, data.Xnde_per_row());
if (ul_style_w_diff) Gfo_hzip_int_.Encode(1, bfr, ul_style_w);
if (xtra_cls) bfr.Add_hzip_mid(src, data.Xtra_cls_bgn(), data.Xtra_cls_end());
if (xtra_style) bfr.Add_hzip_mid(src, data.Xtra_style_bgn(), data.Xtra_style_end());
if (xtra_atr) bfr.Add_hzip_mid(src, data.Xtra_atr_bgn(), data.Xtra_atr_end());
if (xtra_cls) bfr.Add_hzip_mid(src, data.Xtra_cls_bgn(), data.Xtra_cls_end());
if (xtra_style) bfr.Add_hzip_mid(src, data.Xtra_style_bgn(), data.Xtra_style_end());
if (xtra_atr) bfr.Add_hzip_mid(src, data.Xtra_atr_bgn(), data.Xtra_atr_end());
if (capt_exists) bfr.Add_hzip_mid(src, data.Capt_bgn(), data.Capt_end());
Gfo_hzip_int_.Encode(1, bfr, itms_len);
for (int i = 0; i < itms_len; ++i) {
Xoh_gly_itm_data itm_parser = data.Itms__get_at(i);
@ -59,49 +67,70 @@ public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
}
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
boolean ul_style_w_diff = flag_bldr.Get_as_bool(Flag__ul__style_w_diff);
boolean xtra_atr = flag_bldr.Get_as_bool(Flag__ul__xtra_atr);
boolean xtra_cls = flag_bldr.Get_as_bool(Flag__ul__xtra_cls);
boolean xtra_style = flag_bldr.Get_as_bool(Flag__ul__xtra_style);
byte cls_tid = flag_bldr.Get_as_byte(Flag__gly_tid);
byte[] cls_bry = Gallery_mgr_base_.Get_bry_by_tid(cls_tid);
boolean xnde_w_exists = flag_bldr.Get_as_bool(Flag__xnde__w);
boolean xnde_h_exists = flag_bldr.Get_as_bool(Flag__xnde__h);
boolean xnde_per_row_exists = flag_bldr.Get_as_bool(Flag__xnde__per_row);
boolean capt_exists = flag_bldr.Get_as_bool(Flag__xnde__caption);
boolean ul_style_w_diff = flag_bldr.Get_as_bool(Flag__ul__style_w_diff);
boolean xtra_atr = flag_bldr.Get_as_bool(Flag__ul__xtra_atr);
boolean xtra_cls = flag_bldr.Get_as_bool(Flag__ul__xtra_cls);
boolean xtra_style = flag_bldr.Get_as_bool(Flag__ul__xtra_style);
byte cls_tid = flag_bldr.Get_as_byte(Flag__gly_tid);
byte[] cls_bry = Gallery_mgr_base_.To_bry(cls_tid);
int ul_style_max_w = rdr.Read_hzip_int(1);
int xnde_w = xnde_w_exists ? rdr.Read_hzip_int(4) : -1;
int xnde_h = xnde_h_exists ? rdr.Read_hzip_int(4) : -1;
int xnde_per_row = xnde_per_row_exists ? rdr.Read_hzip_int(1) : -1;
int ul_style_w = ul_style_w_diff ? rdr.Read_hzip_int(1) : ul_style_max_w;
byte[] xtra_cls_bry = xtra_cls ? rdr.Read_bry_to(): null;
byte[] xtra_style_bry = xtra_style ? rdr.Read_bry_to(): null;
byte[] xtra_atr_bry = xtra_atr ? rdr.Read_bry_to(): null;
byte[] capt = capt_exists ? rdr.Read_bry_to(): null;
int li_len = rdr.Read_hzip_int(1);
int uid = hctx.Uid__gly__nxt();
Xoh_gly_itm_wtr[] itm_ary = new Xoh_gly_itm_wtr[li_len];
int li_nth = li_len - 1;
for (int i = 0; i < li_len; ++i) {
// init wtr for <li>
Xoh_gly_itm_wtr itm_wtr = new Xoh_gly_itm_wtr();
itm_ary[i] = itm_wtr;
int li_w = rdr.Read_hzip_int(1);
int div_1_w = rdr.Read_hzip_int(1);
int div_2_margin = rdr.Read_hzip_int(1);
int div_3_margin = rdr.Read_hzip_int(1);
byte capt_tid = (byte)(rdr.Read_byte() - gplx.core.encoders.Base85_.A7_offset);
byte[] capt_bry = rdr.Read_bry_to();
Xoh_data_itm img_data = hctx.Pool_mgr__data().Get_by_tid(Xoh_hzip_dict_.Tid__img);
Xoh_hzip_wkr img_hzip = hctx.Pool_mgr__hzip().Mw__img();
img_hzip.Decode1(bfr, hdoc_wkr, hctx, hpg, rdr, src, src_bgn, src_end, img_data);
((gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_data)img_data).Img_is_gallery_(true);
itm_wtr.Img_wtr().Init_by_decode(hpg, hctx, src, img_data);
itm_wtr.Init(hctx.Mode_is_diff(), itm_wtr.Img_wtr().Fsdb_itm().Html_uid(), li_w, div_1_w, div_2_margin, capt_tid, capt_bry);
// init wtr for <img>
itm_wtr.Img_wtr().Init_by_decode(hpg, hctx, src, img_data);
Xof_fsdb_itm fsdb_itm = itm_wtr.Img_wtr().Fsdb_itm();
fsdb_itm.Html_elem_tid_(Xof_html_elem.Tid_gallery_v2);
fsdb_itm.Html_img_wkr_(itm_wtr);
itm_wtr.Init(hctx.Mode_is_diff(), cls_tid, xnde_w, xnde_h, xnde_per_row, fsdb_itm.Html_uid(), i, li_nth, li_w, div_1_w, div_3_margin, capt_tid, capt_bry);
// release
img_data.Pool__rls();
img_hzip.Pool__rls();
}
grp_wtr.Init(hctx.Mode_is_diff(), uid, cls_bry, ul_style_max_w, ul_style_w, xtra_cls_bry, xtra_style_bry, xtra_atr_bry, itm_ary);
}
grp_wtr.Init(hctx.Mode_is_diff(), uid, xnde_w, xnde_h, xnde_per_row, cls_bry, ul_style_max_w, ul_style_w, xtra_cls_bry, xtra_style_bry, xtra_atr_bry, capt, itm_ary);
grp_wtr.Bfr_arg__add(bfr);
hpg.Xtn__gallery_exists_y_();
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_gly_hzip rv = new Xoh_gly_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 1, 1, 3);
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 1, 1, 1, 1, 1, 1, 3);
private static final int // SERIALIZED
Flag__ul__style_w_diff = 0
, Flag__ul__xtra_atr = 1
, Flag__ul__xtra_cls = 2
, Flag__ul__xtra_style = 3
, Flag__gly_tid = 4
Flag__xnde__w = 0
, Flag__xnde__h = 1
, Flag__xnde__per_row = 2
, Flag__xnde__caption = 3
, Flag__ul__style_w_diff = 4
, Flag__ul__xtra_atr = 5
, Flag__ul__xtra_cls = 6
, Flag__ul__xtra_style = 7
, Flag__gly_tid = 8
;
}

@ -21,7 +21,7 @@ public class Xoh_gly_hzip__basic__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Basic() {
fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -46,7 +46,7 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Clear_state() { // page # wasn't being cleared between gallery itms; PAGE:en.w:Almagest; DATE:2016-01-05
fxt.Test__bicode("~'!{,L#{\"g{\"b0!A1~!1A.png~{\"d\"D\"D!#{\"g{\"b0!B1~!1B.png~{\"d\"D\"D!$abc", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -71,7 +71,23 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Extra_cls() { // PURPOSE: handle extra cls; EX: <gallery class='abc'>
fxt.Test__bicode("~'1!cls1 cls2~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional cls1 cls2'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional cls1 cls2'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>"));
}
@Test public void Caption() { // handle <li class='gallerycaption'>A</li>; PAGE:en.d:a; DATE:2016-06-24
fxt.Test__bicode("~'{\"L!Z\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerycaption'>Z</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -84,26 +100,9 @@ public class Xoh_gly_hzip__basic__tst {
, "</li>"
, "</ul>"));
}
// FUTURE: galleries with gallerycaption will cause gallery to write raw; instate code below, but would need to then serialize "gallerycaption"; PAGE:en.d:A DATE:2016-06-24
//@Test public void Caption() { // handle <li class='gallerycaption'>A</li>; PAGE:en.d:a; DATE:2016-06-24
// fxt.Test__bicode("~'!!\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
// ( "<ul class='gallery mw-gallery-traditional'>"
// , "<li class='gallerycaption'>A</li>"
// , "<li class='gallerybox' style='width:155px;'>"
// , "<div style='width:155px;'>"
// , "<div class='thumb' style='width:150px;'>"
// , "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
// , "</div>"
// , "<div class='gallerytext'>"
// , "<p>A1</p>"
// , "</div>"
// , "</div>"
// , "</li>"
// , "</ul>"));
//}
@Test public void Extra_cls__gallery() { // handle redundant gallery; EX: <gallery class='gallery'>; PAGE:en.w:Butuan; DATE:2016-01-05
fxt.Test__bicode("~'1!gallery~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional gallery'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional gallery'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -118,7 +117,7 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Xtra_atr() { // PURPOSE: handle extra atr; EX: <gallery id='abc'>
fxt.Test__bicode("~'A! id=\"abc\"\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' id='abc'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' id='abc'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -136,7 +135,7 @@ public class Xoh_gly_hzip__basic__tst {
( "~'!!\"{\"g{\"b0!A1<br>"
, "~!1A.png~9\"D\"D"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -152,6 +151,31 @@ public class Xoh_gly_hzip__basic__tst {
}
@Test public void Tidy__empty() { // PURPOSE: no items should place </ul> on same line
fxt.Test__bicode("~'!!!", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'></ul>")); // TIDY: <ul></ul> should be on same line if 0 items
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'></ul>")); // TIDY: <ul></ul> should be on same line if 0 items
}
@Test public void Xnde_atrs() {
fxt.Test__bicode("~'{6({,L!!#?!!$N&#{\"g{\"b0!A1~!1A.png~9\"D\"D{\"g{\"b0!B1~!1B.png~9\"D\"Dabc", String_.Concat_lines_nl_skip_last
( "<ul data-xogly='200|300|5' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>A1</p>"
, "</div>"
, "</div>"
, "</li>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
, "<div style='margin:15px auto;'><a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img data-xowa-title='B.png' data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a></div>"
, "</div>"
, "<div class='gallerytext'>"
, "<p>B1</p>"
, "</div>"
, "</div>"
, "</li>"
, "</ul>abc"));
}
}

@ -21,7 +21,7 @@ public class Xoh_gly_hzip__caption__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Capt_is_empty() { // PURPOSE: handle empty caption
fxt.Test__bicode("~'!!#{\"g{\"b0#~!1A.png~9\"D\"D{\"g{\"b0#!1A.png9\"D\"D<p>abc</p>", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -44,7 +44,7 @@ public class Xoh_gly_hzip__caption__tst {
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
( "~'!!\"{\"g{\"b0\"<b><i>A1</i></b>"
, "~!1A.png~9\"D\"D"), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -63,7 +63,7 @@ public class Xoh_gly_hzip__caption__tst {
, "b</p>"
, "<p><br>"
, "~!1A.png~9\"D\"D"), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -84,7 +84,7 @@ public class Xoh_gly_hzip__caption__tst {
( "~'!!\"{\"g{\"b>\"<div class=\"center\"><a href=\"/wiki/B.png\" class=\"image\" xowa_title=\"B.png\"><img data-xowa-title=\"A.png\" data-xoimg=\"0|120|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" alt=\"\"></a></div>"
, "abc~\"\\A.png~#9\"D\"D"
), String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -105,7 +105,7 @@ public class Xoh_gly_hzip__caption__tst {
, "b"
, "~\"\\A.png~#9\"D\"D")
, String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"

@ -21,7 +21,7 @@ public class Xoh_gly_hzip__style__tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
@Test public void Style__no_max_width() { // PURPOSE: if no perrow=# then no "style='max-width:###; _width:###;'"
fxt.Test__bicode("~'!!\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -36,7 +36,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__no_width() { // PURPOSE: if "_width" omitted, do not add back; EX: style="max-width:648px; margin:auto; background:transparent;"; PAGE:en.w:Wikipedia:Village_pump_(technical)/Archive_86 DATE:2016-01-12
fxt.Test__bicode("~'i{,L! color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; color:blue;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; color:blue;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -51,7 +51,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__max_width_duped() { // PURPOSE: if max-width duped, do not delete 2nd; EX: style="max-width:648px; color:blue; max-width:648px;"; PAGE:en.w:Wikipedia:Village_pump_(technical)/Archive_86 DATE:2016-01-12
fxt.Test__bicode("~'){(Z max-width:648px; color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:652px; _width:652px; max-width:648px; color:blue;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:652px; _width:652px; max-width:648px; color:blue;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -66,7 +66,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__append() { // PURPOSE: handle appended style; EX: <gallery perrow=4 style='color:blue; float:left;'>
fxt.Test__bicode("~'){,L color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue; float:left;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue; float:left;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -81,7 +81,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__invalid_unclosed() { // handle broken styles; EX: <gallery style='center'>
fxt.Test__bicode("~'9!center~center~\"{\"g{\"bl!abc~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional center' style='center'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional center' style='center'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -97,7 +97,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__extra_colon() { // handle broken styles; EX: <gallery style='a:b:c:d;' PAGE:en.w:Bronze_Horseman DATE:2016-01-05
fxt.Test__bicode("~'9!center~color:red:float:right;~\"{\"g{\"bl!abc~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional center' style='color:red:float:right;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional center' style='color:red:float:right;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -113,7 +113,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__replace() { // PURPOSE: handle replaced style; EX: <gallery style='color:blue; float:left;'>
fxt.Test__bicode("~')!color:blue; float:left;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='color:blue; float:left;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='color:blue; float:left;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"
@ -128,7 +128,7 @@ public class Xoh_gly_hzip__style__tst {
}
@Test public void Style__ws() { // PURPOSE: handle ws in style; EX: <gallery class="gallery mw-gallery-traditional" style="max-width:1115px; _width:1115px; color:blue;'>; PAGE:en.w:Anti-Serb_sentiment; DATE:2016-01-08
fxt.Test__bicode("~'){,L color:blue;~\"{\"g{\"b0!A1~!1A.png~9\"D\"D", String_.Concat_lines_nl_skip_last
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue;'>"
( "<ul data-xogly='-1|-1|-1' class='gallery mw-gallery-traditional' style='max-width:978px; _width:978px; color:blue;'>"
, "<li class='gallerybox' style='width:155px;'>"
, "<div style='width:155px;'>"
, "<div class='thumb' style='width:150px;'>"

@ -18,19 +18,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
public class Xoh_gly_itm_wtr implements Bfr_arg {
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*;
public class Xoh_gly_itm_wtr implements Bfr_arg, Js_img_wkr {
private final Bfr_arg_clearable[] arg_ary;
private final Bfr_arg__hatr_id li_id = Bfr_arg__hatr_id.New_id("xogly_li_"), img_id = Bfr_arg__hatr_id.New_id(gplx.xowa.htmls.Xoh_img_mgr.Bry__html_uid)
, div_1_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div1_"), div_2_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div2_"), div_3_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div3_");
private final Bfr_arg__hatr_id
li_id = Bfr_arg__hatr_id.New_id("xogly_li_")
, img_id = Bfr_arg__hatr_id.New_id(gplx.xowa.htmls.Xoh_img_mgr.Bry__html_uid)
, div_1_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div1_")
, div_2_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div2_")
, div_3_id = Bfr_arg__hatr_id.New_id("xowa_gallery_div3_");
private final Bfr_arg__itm_caption itm_caption_fmtr = new Bfr_arg__itm_caption();
private int li_w, div_1_w, div_2_margin;
private byte mode;
private int xnde_w_orig, xnde_h_orig, xnde_per_row, div_1_w, div_2_w, div_3_margin, li_idx, li_nth;
public Xoh_gly_itm_wtr() {
arg_ary = new Bfr_arg_clearable[] {li_id, div_1_id, div_2_id, div_3_id, img_id};
}
public Xoh_img_wtr Img_wtr() {return img_wtr;} private final Xoh_img_wtr img_wtr = new Xoh_img_wtr();
public void Init(boolean mode_is_diff, int img_id, int li_w, int div_1_w, int div_2_margin, byte capt_tid, byte[] itm_caption) {
public void Init(boolean mode_is_diff, byte mode, int xnde_w, int xnde_h, int xnde_per_row, int img_id, int li_idx, int li_nth, int div_1_w, int div_2_w, int div_3_margin, byte capt_tid, byte[] itm_caption) {
this.Clear();
this.li_w = li_w; this.div_1_w = div_1_w; this.div_2_margin = div_2_margin;
this.mode = mode; this.xnde_w_orig = xnde_w; this.xnde_h_orig = xnde_h; this.xnde_per_row = xnde_per_row;
this.li_idx = li_idx; this.li_nth = li_nth;
this.div_1_w = div_1_w; this.div_2_w = div_2_w; this.div_3_margin = div_3_margin;
itm_caption_fmtr.Set(capt_tid, itm_caption);
if (!mode_is_diff) {
li_id.Set(img_id); div_1_id.Set(img_id); div_2_id.Set(img_id); div_3_id.Set(img_id); img_wtr.Img_id_(img_id);
@ -38,6 +47,9 @@ public class Xoh_gly_itm_wtr implements Bfr_arg {
img_wtr.Anch_cls_(Xoh_img_data.Bry__cls__anch__image);
}
public Xoh_gly_itm_wtr Clear() {
this.mode = 0;
this.xnde_w_orig = xnde_h_orig = xnde_per_row = li_idx = li_nth = -1;
this.div_1_w = div_2_w = div_3_margin = 0;
for (Bfr_arg_clearable arg : arg_ary)
arg.Bfr_arg__clear();
// img_wtr.Clear(); // TOMBSTONE: do not clear; clear will be called by Xoh_hzip_img.Decode1
@ -46,20 +58,62 @@ public class Xoh_gly_itm_wtr implements Bfr_arg {
public void Bfr_arg__clear() {this.Clear();}
public boolean Bfr_arg__missing() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, li_w, div_1_w, div_2_margin, img_wtr, itm_caption_fmtr);
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, div_1_w, div_2_w, div_3_margin, img_wtr, itm_caption_fmtr);
}
public void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl) {
Bry_bfr bfr = Bry_bfr_.New();
// get mgr
Gallery_mgr_base mgr = Gallery_mgr_base_.New(mode);
int xnde_w_actl = xnde_w_orig == -1 ? Gallery_xnde.Default : xnde_w_orig;
int xnde_h_actl = xnde_h_orig == -1 ? Gallery_xnde.Default : xnde_h_orig;
mgr.Init(xnde_w_actl, xnde_h_actl, xnde_per_row);
// get lnki and calculate expanded dimensions; note that packed will generate large widths; EX: 220 -> 2200+
gplx.xowa.parsers.lnkis.Xop_lnki_tkn lnki = new gplx.xowa.parsers.lnkis.Xop_lnki_tkn();
lnki.Ttl_(page.Wiki().Ttl_parse(lnki_ttl)).W_(html_w).H_(html_h); // NOTE: gallery_parser also does ad-hoc creation of lnki_tkn
mgr.Get_thumb_size(lnki, orig_ext); // noop if traditional; expand by 1.5 if packed
Xof_img_size img_size = new Xof_img_size();
img_size.Html_size_calc(Xof_exec_tid.Tid_wiki_page, lnki.W(), lnki.H(), lnki.Lnki_type(), Xof_patch_upright_tid_.Tid_all, lnki.Upright(), orig_ext.Id(), orig_w, orig_h, Xof_img_size.Thumb_width_img);
int html_w_expand = img_size.Html_w();
int html_h_expand = img_size.Html_h();
Xof_fsdb_itm fsdb_itm = img_wtr.Fsdb_itm();
fsdb_itm.Html_size_(html_w_expand, html_h_expand);
// update div_1, div_2, div_3 vars
div_1_w = mgr.Get_gb_width(html_w_expand, html_h_expand);
div_2_w = mgr.Get_thumb_div_width(html_w_expand);
div_3_margin = mgr.Get_vpad(xnde_h_actl, html_h_expand);
// adjust params
mgr.Adjust_image_parameters(fsdb_itm); // noop if traditional; reduce by 1.5 if packed
int html_w_normal = fsdb_itm.Html_w();
int html_h_normal = fsdb_itm.Html_h();
// fsdb_itm.Init_at_gallery_bgn(html_w_normal, html_h_normal, html_w_expand); // NOTE: gallery_htmlr updates fsdb_itm, but only need to update img_wtr; NOTE: file_w should be set to expanded width so js can resize if gallery
img_wtr.Init_html(html_w_normal, html_h_normal, html_view_url.To_http_file_bry()); // NOTE: html_view_url uses url generated by Xof_file_wkr; theoretically, packed could generate different file, but for now ignore
// generate html; call json
fmtr.Bld_bfr_many(bfr, li_id, div_1_id, div_2_id, div_3_id, div_1_w, div_2_w, div_3_margin, img_wtr, itm_caption_fmtr);
js_wkr.Html_elem_replace_html(String_.new_u8(li_id.Get_id_val()), bfr.To_str_and_clear());
if ( Gallery_mgr_base_.Mode_is_packed(mode) // packed gallery
&& li_idx == li_nth) { // last itm
js_wkr.Html_gallery_packed_exec(); // call packed js
}
}
public static final Xoh_gly_itm_wtr[] Ary_empty = new Xoh_gly_itm_wtr[0];
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, "<li~{li_id} class=\"gallerybox\" style=\"width:~{li_w}px;\">"
, "<div~{div_1_id} style=\"width:~{li_w}px;\">"
, "<div~{div_2_id} class=\"thumb\" style=\"width:~{div_1_w}px;\">"
, "<div~{div_3_id} style=\"margin:~{div_2_margin}px auto;\">~{img_itm}</div>"
, "<li~{li_id} class=\"gallerybox\" style=\"width:~{div_1_w}px;\">"
, "<div~{div_1_id} style=\"width:~{div_1_w}px;\">"
, "<div~{div_2_id} class=\"thumb\" style=\"width:~{div_2_w}px;\">"
, "<div~{div_3_id} style=\"margin:~{div_3_margin}px auto;\">~{img_itm}</div>"
, "</div>"
, "<div class=\"gallerytext\">~{itm_caption}</div>"
, "</div>"
, "</li>"
), "li_id", "div_1_id", "div_2_id", "div_3_id", "li_w", "div_1_w", "div_2_margin", "img_itm", "itm_caption");
), "li_id", "div_1_id", "div_2_id", "div_3_id", "div_1_w", "div_2_w", "div_3_margin", "img_itm", "itm_caption");
}
class Bfr_arg__itm_caption implements Bfr_arg {
private byte capt_tid;

@ -16,11 +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.xowa.htmls.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.core.hzips.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.xtns.gallery.*;
public class Xoh_gly_itm_wtr_tst {
private final Xoh_gly_itm_wtr_fxt fxt = new Xoh_gly_itm_wtr_fxt();
@Test public void Basic() {
fxt.Init__gly(0, 155, 150, 5, "caption");
fxt.Init__gly(Gallery_mgr_base_.Tid__traditional, -1, -1, -1, 0, 155, 150, 5, "caption");
fxt.Init__img("/wiki/File:A.png", "A.png", "0|120|120|-1|-1|-1");
fxt.Test__write(String_.Concat_lines_nl_skip_last
( ""
@ -40,8 +40,8 @@ public class Xoh_gly_itm_wtr_tst {
class Xoh_gly_itm_wtr_fxt {
private final Xoh_gly_itm_wtr wtr = new Xoh_gly_itm_wtr();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public void Init__gly(int id, int itm_w, int file_div_w, int file_div_margin, String caption) {
wtr.Init(Bool_.N, id, itm_w, file_div_w, file_div_margin, Xoh_gly_itm_data.Capt_tid__p, Bry_.new_a7(caption));
public void Init__gly(byte mode, int xnde_w, int xnde_h, int xnde_per_row, int id, int itm_w, int div_1_w, int div_3_margin, String caption) {
wtr.Init(Bool_.N, mode, xnde_w, xnde_h, xnde_per_row, id, 0, 0, itm_w, div_1_w, div_3_margin, Xoh_gly_itm_data.Capt_tid__p, Bry_.new_a7(caption));
}
public void Init__img(String href, String xowa_title, String xoimg) {
wtr.Img_wtr().Init_by_gly(gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(href)), Bry_.new_u8(xowa_title), gplx.core.brys.args.Bfr_arg__bry.New(Bry_.new_u8(xoimg)));

@ -39,7 +39,9 @@ public class Xoh_hdr_data implements Xoh_data_itm {
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag hdr_head, Gfh_tag span_head) {
this.Clear();
this.src_bgn = hdr_head.Src_bgn(); this.hdr_level = hdr_head.Name_id();
Gfh_atr anch_atr = span_head.Atrs__get_by_or_fail(Gfh_atr_.Bry__id);
if (hdr_head.Atrs__len() > 0) return false; // skip manual <h2> with atrs; PAGE:fr.w:Wikipédia:LiveRC/ToDo; DATE:2016-07-02
Gfh_atr anch_atr = span_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__id);
if (anch_atr.Val_dat_missing()) return false; // skip manual <h2> without id; PAGE:fr.w:Portail:Nord-Amérindiens/Image_sélectionnée; DATE:2016-07-01
this.anch_bgn = anch_atr.Val_bgn(); this.anch_end = anch_atr.Val_end();
this.capt_bgn = span_head.Src_end();
Gfh_tag hdr_tail = tag_rdr.Tag__move_fwd_tail(hdr_level); // find </h2> not </span> since <span> can be nested, but <h2> cannot
@ -59,7 +61,7 @@ public class Xoh_hdr_data implements Xoh_data_itm {
this.anch_bgn = anch_bgn; this.anch_end = anch_end; this.capt_bgn = capt_bgn; this.capt_end = capt_end;
this.capt_rhs_bgn = capt_rhs_bgn; this.capt_rhs_end = capt_rhs_end;
}
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
public static final byte[] Bry__class__mw_headline = Bry_.new_a7("mw-headline");
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_hdr_data rv = new Xoh_hdr_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
public class Xoh_hdr_hzip_tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
@Test public void Same() {
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
( "~\"'A~"
@ -91,4 +91,16 @@ public class Xoh_hdr_hzip_tst {
, "</div>"
));
}
@Test public void Manual__no_id() {// PURPOSE: ignore manual "<h2>" with no id; PAGE:fr.w:Portail:Nord-Am<41>rindiens/Image_s<5F>lectionn<6E>e; DATE:2016-07-01
fxt.Test__bicode
( "<h6><span class=\"mw-headline\">A</span></h6>"
, "<h6><span class='mw-headline'>A</span></h6>"
);
}
@Test public void Manual__h_has_atrs() {// PURPOSE: ignore manual "<h2>" with atrs; PAGE:fr.w:Wikip<69>dia:LiveRC/ToDo; DATE:2016-07-02
fxt.Test__bicode
( "<h6 style=\"color:red\"><span class=\"mw-headline\" id=\"A\">B</span></h6>"
, "<h6 style=\"color:red\"><span class=\"mw-headline\" id=\"A\">B</span></h6>"
);
}
}

@ -59,6 +59,13 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
this.Bfr_arg__add(bfr);
}
private static final byte[] Bry__qarg__esc = Bry_.new_a7("%3F");
public void Init_html(int html_w, int html_h, byte[] src_bry) {
img_w.Set_by_int(html_w);
img_h.Set_by_int(html_h);
if (gplx.core.envs.Op_sys.Cur().Tid_is_drd())
src_bry = Bry_.Replace(src_bry, Byte_ascii.Question_bry, Bry__qarg__esc); // NOTE: if drd, always escape "?" as "%3F" PAGE:en.w:Cleopatra en.w:Cave_painting; DATE:2016-01-31
img_src.Set_by_bry(src_bry);
}
public boolean Init_by_decode(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_data_itm data_itm) {
Xoh_img_data data = (Xoh_img_data)data_itm;
this.Clear();
@ -72,17 +79,13 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, gplx.xowa.parsers.lnkis.Xop_lnki_type.To_flag(img_xowa_image.Lnki_type()), img_xowa_image.Lnki_upright(), img_xowa_image.Lnki_w(), img_xowa_image.Lnki_h(), img_xowa_image.Lnki_time(), img_xowa_image.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
hctx.File__mgr().Find(hpg.Wiki(), hpg.Url_bry_safe(), fsdb_itm);
this.img_xowa_image.Set_by_arg(img_xowa_image.Clone()); // NOTE: must clone b/c img_xowa_image is member of Xoh_img_data which is poolable (and cleared); PAGE:en.w:Almagest; DATE:2016-01-05
img_w.Set_by_int(fsdb_itm.Html_w());
img_h.Set_by_int(fsdb_itm.Html_h());
byte[] src_bry = fsdb_itm.Html_view_url().To_http_file_bry();
if (gplx.core.envs.Op_sys.Cur().Tid_is_drd()) src_bry = Bry_.Replace(src_bry, Byte_ascii.Question_bry, Bry__qarg__esc); // NOTE: if drd, always escape "?" as "%3F" PAGE:en.w:Cleopatra en.w:Cave_painting; DATE:2016-01-31
this.img_src.Set_by_bry(src_bry);
this.Init_html(fsdb_itm.Html_w(), fsdb_itm.Html_h(), fsdb_itm.Html_view_url().To_http_file_bry());
}
else if (data.Img_w() != -1) {
img_w.Set_by_int(data.Img_w());
img_h.Set_by_int(data.Img_h());
this.img_src.Set_by_arg(data.Img_src());
}
}
if (data.Anch_rel_nofollow_exists()) anch_rel.Set_by_bry(gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_dict_.Html__rel__nofollow);
if (!hctx.Mode_is_diff()) {
this.Img_id_(fsdb_itm.Html_uid());

@ -23,11 +23,11 @@ import gplx.xowa.parsers.*;
import gplx.xowa.wikis.tdbs.metas.*;
import gplx.xowa.htmls.core.htmls.*;
public class Xoh_file_mgr {
private final Xowe_wiki wiki;
private final Xowe_wiki wiki;
public Xoh_file_mgr(Xowe_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr) {
this.wiki = wiki; this.file_wtr = new Xoh_file_wtr__basic(wiki, html_mgr, html_wtr);
}
public Xoh_file_wtr__basic File_wtr() {return file_wtr;} private final Xoh_file_wtr__basic file_wtr;
public Xoh_file_wtr__basic File_wtr() {return file_wtr;} private final Xoh_file_wtr__basic file_wtr;
public void Init_by_page(Xoh_wtr_ctx hctx, Xoae_page page) {file_wtr.Init_by_page(hctx, page);}
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {Write_or_queue(bfr, page, ctx, hctx, src, lnki, file_wtr.Arg_alt_text(ctx, src, lnki));}
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {

@ -0,0 +1,91 @@
/*
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.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.langs.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 int prv_lvl;
public void Clear() {
prv_lvl = 0;
}
public byte[] To_html(Ordered_hash itms, byte[] toc_title, boolean page_banner) {
this.itms = itms;
fmtr_div.Bld_many(bfr, page_banner ? Bry_.Empty : Bry_toc_cls, toc_title, this);
return bfr.To_bry_and_clear();
}
public byte[] Test__to_html(Ordered_hash itms) {
this.itms = itms;
Bfr_arg__add(bfr);
return bfr.To_bry_and_clear();
}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = itms.Len();
prv_lvl = 0;
for (int i = 0; i < len; ++i) {
Xoh_toc_itm itm = (Xoh_toc_itm)itms.Get_at(i);
Write(bfr, itm);
}
// close all open levels
for (int i = prv_lvl; i > 0; --i) {
int indent = i * 2;
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
bfr.Add_byte_repeat(Byte_ascii.Space, indent ).Add(Gfh_tag_.Ul_rhs).Add_byte_nl(); // EX: " </ul>\n"
}
}
private void Write(Bry_bfr bfr, Xoh_toc_itm itm) {
int cur_lvl = itm.Lvl();
int indent = cur_lvl * 2;
switch (CompareAble_.Compare(cur_lvl, prv_lvl)) {
case CompareAble_.More: // start new "<ul>"
bfr.Add_byte_repeat(Byte_ascii.Space, indent).Add(Gfh_tag_.Ul_lhs).Add_byte_nl(); // EX: " <ul>\n"
break;
case CompareAble_.Same: // close old "</li>"; NOTE: Comparable_.Same will never be 1st item (so won't ever get </li><li>)
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
break;
case CompareAble_.Less: // close old "</ul>" and "</li>"
for (int j = prv_lvl; j > cur_lvl; --j) {
bfr.Add_byte_repeat(Byte_ascii.Space, (j * 2) + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
bfr.Add_byte_repeat(Byte_ascii.Space, (j * 2) ).Add(Gfh_tag_.Ul_rhs).Add_byte_nl(); // EX: " </ul>\n"
}
bfr.Add_byte_repeat(Byte_ascii.Space, indent + 2).Add(Gfh_tag_.Li_rhs).Add_byte_nl(); // EX: " </li>\n"
break;
default: throw Err_.new_unhandled_default(CompareAble_.Compare(cur_lvl, prv_lvl));
}
// write "<li ..."
bfr.Add_byte_repeat(Byte_ascii.Space, indent); // indent
fmtr_itm.Bld_many(bfr, itm.Lvl(), itm.Uid(), itm.Anch(), itm.Path_to_bry(numbering_bfr), itm.Text());
prv_lvl = cur_lvl;
}
private static final byte[] Bry_toc_cls = Bry_.new_a7(" id=\"toc\" class=\"toc\"");
private final Bry_fmt
fmtr_div = Bry_fmt.Auto(String_.Concat_lines_nl_skip_last
( "<div~{toc}>"
, " <div id=\"toctitle\">"
, " <h2>~{contents_title}</h2>"
, " </div>"
, "~{itms}</div>"
, ""
))
, fmtr_itm = Bry_fmt.Auto
( " <li class=\"toclevel-~{level} tocsection-~{toc_idx}\"><a href=\"#~{anchor}\"><span class=\"tocnumber\">~{heading}</span> <span class=\"toctext\">~{text}</span></a>\n"
);
}

@ -0,0 +1,175 @@
/*
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.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.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();
@Test public void D1_S0_S0() {
fxt.Init__add(2, "a");
fxt.Init__add(2, "b");
fxt.Init__add(2, "c");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(4, "a_a_a");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_S0_U1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(3, "a_b");
fxt.Init__add(2, "b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_b\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_U1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(2, "b");
fxt.Init__add(3, "b_a");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-4\"><a href=\"#b_a\"><span class=\"tocnumber\">2.1</span> <span class=\"toctext\">b_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D1_D1_U2() {
fxt.Init__add(2, "a");
fxt.Init__add(3, "a_a");
fxt.Init__add(4, "a_a_a");
fxt.Init__add(2, "b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.1.1</span> <span class=\"toctext\">a_a_a</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-4\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " </ul>"
);
}
@Test public void D1_D2_U1_D1() {
fxt.Init__add(2, "a");
fxt.Init__add(4, "a_a_a_a");
fxt.Init__add(3, "a_a_a");
fxt.Init__add(4, "a_a_a_b");
fxt.Test__html_itms
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " <ul>"
, " <li class=\"toclevel-2 tocsection-2\"><a href=\"#a_a_a_a\"><span class=\"tocnumber\">1.1</span> <span class=\"toctext\">a_a_a_a</span></a>"
, " </li>"
, " <li class=\"toclevel-2 tocsection-3\"><a href=\"#a_a_a\"><span class=\"tocnumber\">1.2</span> <span class=\"toctext\">a_a_a</span></a>"
, " <ul>"
, " <li class=\"toclevel-3 tocsection-4\"><a href=\"#a_a_a_b\"><span class=\"tocnumber\">1.2.1</span> <span class=\"toctext\">a_a_a_b</span></a>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
, " </li>"
, " </ul>"
);
}
@Test public void Div() {
fxt.Init__init_page("Table of contents", false);
fxt.Init__add(2, "a");
fxt.Init__add(2, "b");
fxt.Init__add(2, "c");
fxt.Test__html_div
( "<div id=\"toc\" class=\"toc\">"
, " <div id=\"toctitle\">"
, " <h2>Table of contents</h2>"
, " </div>"
, " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">a</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-2\"><a href=\"#b\"><span class=\"tocnumber\">2</span> <span class=\"toctext\">b</span></a>"
, " </li>"
, " <li class=\"toclevel-1 tocsection-3\"><a href=\"#c\"><span class=\"tocnumber\">3</span> <span class=\"toctext\">c</span></a>"
, " </li>"
, " </ul>"
, "</div>"
);
}
}
class Xoh_toc_htmlr__basic__fxt {
private final Xoh_toc_wtr wtr = new Xoh_toc_wtr();
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), page_banner);}
public void Test__html_itms(String... expd_ary) {
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())));
}
}

@ -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.xowa.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
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"
public int[] Path() {return path;} private int[] path; // path of itm; HTML: "1.1.1"
public byte[] Anch() {return anch;} private byte[] anch; // HTML: "#aaa"
public byte[] Text() {return text;} private byte[] text; // HTML: "aaa"
public byte[] Path_to_bry(Bry_bfr bfr) {
int len = path.length;
for (int i = 0; i < len; ++i) {
if (i != 0) bfr.Add_byte_dot();
bfr.Add_int_variable(path[i]);
}
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;}
}

@ -0,0 +1,75 @@
/*
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.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.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];
private int prv_lvl, toc_lvl, prv_toc_lvl;
private int uid = 0;
public void Clear() {
uid = prv_lvl = toc_lvl = prv_toc_lvl = 0;
}
public void Calc_level(Xoh_toc_itm rv, int lvl) { // REF.MW:Parser.php!formatHeadings
if (lvl > prv_lvl) { // Increase TOC lvl
toc_lvl++;
sub_lvl_count[toc_lvl - List_adp_.Base1] = 0;
if (toc_lvl < Toc_lvls_max) {
prv_toc_lvl = toc_lvl;
// $toc .= Linker::tocIndent();
}
}
else if (lvl < prv_lvl && toc_lvl > 1) {// Decrease TOC lvl, find lvl to jump to
int i = toc_lvl;
for (; i > 0; i--) {
int cur_lvl_count = lvl_count[i];
if (cur_lvl_count == lvl) { // Found last matching lvl
toc_lvl = i;
break;
}
else if (cur_lvl_count < lvl) { // Found first matching lvl below current lvl
toc_lvl = i + 1;
break;
}
}
if (i == 0)
toc_lvl = 1;
if (toc_lvl < Toc_lvls_max) {
if (prv_toc_lvl < Toc_lvls_max) {
// Unindent only if the previous toc lvl was shown :p
// $toc .= Linker::tocUnindent( $prv_toc_lvl - $toc_lvl );
prv_toc_lvl = toc_lvl;
} else {
// $toc .= Linker::tocLineEnd();
}
}
}
else { // No change in lvl, end TOC line
if (toc_lvl < Toc_lvls_max) {
// $toc .= Linker::tocLineEnd();
}
}
lvl_count[toc_lvl] = lvl;
sub_lvl_count[toc_lvl - List_adp_.Base1] = sub_lvl_count[toc_lvl - List_adp_.Base1] + 1;
prv_lvl = lvl; // NOTE: same as "if ( $toclevel ) $prevlevel = $level;" but at end of block
// Tfds.Write(lvl, prv_lvl, lvl, toc_lvl, Int_.Ary_concat(",", lvl_count), Int_.Ary_concat(",", sub_lvl_count));
int[] copy = new int[toc_lvl];
Int_.Ary_copy_to(sub_lvl_count, toc_lvl, copy);
rv.Set__lvl(++uid, toc_lvl, copy);
}
}

@ -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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.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();
@Test public void D1_S0_S0() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(2, fxt.Make(2, 1, Int_.Ary(2)));
fxt.Test__calc(2, fxt.Make(3, 1, Int_.Ary(3)));
}
@Test public void D1_D1_D1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(4, fxt.Make(3, 3, Int_.Ary(1, 1, 1)));
}
@Test public void D1_D1_S0_U1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(3, fxt.Make(3, 2, Int_.Ary(1, 2)));
fxt.Test__calc(2, fxt.Make(4, 1, Int_.Ary(2)));
}
@Test public void D1_D1_U1_D1() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(2, fxt.Make(3, 1, Int_.Ary(2)));
fxt.Test__calc(3, fxt.Make(4, 2, Int_.Ary(2, 1)));
}
@Test public void D1_D1_D1_U2() {
fxt.Test__calc(2, fxt.Make(1, 1, Int_.Ary(1)));
fxt.Test__calc(3, fxt.Make(2, 2, Int_.Ary(1, 1)));
fxt.Test__calc(4, fxt.Make(3, 3, Int_.Ary(1, 1, 1)));
fxt.Test__calc(2, fxt.Make(4, 1, Int_.Ary(2)));
}
}
class Xoh_toc_wkr__lvl__fxt {
private final Xoh_toc_wkr__lvl wkr = new Xoh_toc_wkr__lvl();
private final Xoh_toc_itm actl = new Xoh_toc_itm();
public void Clear() {wkr.Clear();}
public Xoh_toc_itm Make(int uid, int lvl, int[] path) {
Xoh_toc_itm rv = new Xoh_toc_itm();
rv.Set__lvl(uid, lvl, path);
return rv;
}
public void Test__calc(int lvl, Xoh_toc_itm expd) {
wkr.Calc_level(actl, lvl);
Gftest.Eq__int(expd.Uid(), actl.Uid(), "uid");
Gftest.Eq__int(expd.Lvl(), actl.Lvl(), "lvl");
Gftest.Eq__ary(expd.Path(), actl.Path(), "path");
}
}

@ -0,0 +1,152 @@
/*
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.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.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 {
private final Gfh_tag_rdr tag_rdr = Gfh_tag_rdr.New__html();
private final Bry_bfr anch_bfr = Bry_bfr_.New(), text_bfr = Bry_bfr_.New();
private final Gfo_url_encoder anch_encoder = Gfo_url_encoder_.New__id();
private final Xop_amp_mgr amp_mgr = Xop_amp_mgr.Instance;
private final Hash_adp anch_hash = Hash_adp_bry.ci_u8(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
private byte[] page_name = Bry_.Empty;
public void Clear() {
anch_bfr.Clear();
text_bfr.Clear();
anch_hash.Clear();
}
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);
byte[] anch_bry = anch_bfr.To_bry_and_clear_and_trim(Bool_.Y, Bool_.Y, id_trim_ary);
Int_obj_ref anch_idx_ref = (Int_obj_ref)anch_hash.Get_by(anch_bry);
if (anch_idx_ref == null) {
anch_hash.Add(anch_bry, Int_obj_ref.New(2));
}
else {
int anch_idx = anch_idx_ref.Val();
anch_bry = Bry_.Add(anch_bry, Byte_ascii.Underline_bry, Int_.To_bry(anch_idx));
anch_idx_ref.Val_(anch_idx + 1);
}
rv.Set__txt
( anch_bry
, text_bfr.To_bry_and_clear_and_trim()); // NOTE: both id and text trim ends
}
private void Calc_anch_text_recurse(byte[] src, int pos, int end) {
tag_rdr.Src_rng_(pos, end);
while (pos < end) {
Gfh_tag lhs = tag_rdr.Tag__move_fwd_head();
int tag_id = lhs.Name_id();
byte[] span_dir = null;
// add any text before lhs;
int txt_end = lhs.Src_bgn();
switch (tag_id) {
case Gfh_tag_.Id__eos: txt_end = end; break; // eos; print everything until end
}
// add any text before tag
if (pos < txt_end) {
byte[] anch_bry = amp_mgr.Decode_as_bry(Bry_.Mid(src, pos, txt_end));
anch_encoder.Encode(anch_bfr, anch_bry);
text_bfr.Add_mid(src, pos, txt_end);
}
// set print_tag tag; REF.MW:Parser.php!formatHeadings
boolean print_tag = false;
switch (tag_id) {
case Gfh_tag_.Id__eos: // eos; return;
return;
case Gfh_tag_.Id__sup: // always print tag; REF.MW:Parser.php!formatHeadings!"Allowed tags are"
case Gfh_tag_.Id__sub:
case Gfh_tag_.Id__i:
case Gfh_tag_.Id__b:
case Gfh_tag_.Id__bdi:
print_tag = true;
break;
case Gfh_tag_.Id__span: // print span only if it has a dir attribute
span_dir = lhs.Atrs__get_as_bry(Gfh_atr_.Bry__dir);
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;
}
// get lhs / rhs vars
byte[] lhs_bry = lhs.Name_bry();
int lhs_end = lhs.Src_end();
boolean lhs_is_pair = !lhs.Tag_is_inline();
int rhs_bgn = -1, rhs_end = -1, new_pos = lhs_end;
if (lhs_is_pair) { // get rhs unless inline
Gfh_tag rhs = tag_rdr.Tag__move_fwd_tail(tag_id);
rhs_bgn = rhs.Src_bgn(); rhs_end = rhs.Src_end();
new_pos = rhs_end;
}
// print "<tag></tag>"; also, recurse
if (print_tag) {
text_bfr.Add_byte(Byte_ascii.Angle_bgn).Add(lhs_bry);
if (span_dir != null) // if span has dir, add it; EX: <span id='1' dir='rtl'> -> <span dir='rtl'>
Gfh_atr_.Add(text_bfr, Gfh_atr_.Bry__dir, span_dir);
text_bfr.Add_byte(Byte_ascii.Angle_end); // only add name; do not add atrs; EX: <i id='1'> -> <i>
}
Calc_anch_text_recurse(src, lhs_end, rhs_bgn);
if (print_tag && lhs_is_pair)
text_bfr.Add_mid(src, rhs_bgn, rhs_end);
// set new_pos
pos = new_pos;
tag_rdr.Src_rng_(new_pos, end); // NOTE: must reinit pos and especially end
}
}
public static byte[] Remove_comment(Bry_bfr tmp, byte[] src, int bgn, int end) {
boolean dirty = false, append_to_eos = true;
int pos = bgn;
while (true) {
int comm_bgn = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_bgn, pos, end);
if (comm_bgn != -1) { // comment found
int tmp_pos = comm_bgn + Gfh_tag_.Comm_bgn_len;
int comm_end = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_end, tmp_pos, end);
if (comm_end == -1) { // dangling
tmp.Add_mid(src, pos, comm_bgn);
append_to_eos = false;
}
else {
dirty = true;
tmp.Add_mid(src, pos, comm_bgn);
pos = comm_end + Gfh_tag_.Comm_end_len;
continue;
}
}
break;
}
if (dirty && append_to_eos) {
tmp.Add_mid(src, pos, end);
}
return dirty ? tmp.To_bry_and_clear() : src;
}
private static final byte[] id_trim_ary = Bry_.mask_(256, Byte_ascii.Underline_bry);
}

@ -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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.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();
@Test public void Basic() {
fxt.Test__both("a b c", "a_b_c", "a b c");
}
@Test public void Ws() {
fxt.Test__both(" a b ", "a_b", "a b");
}
@Test public void Amp__ncr() {
fxt.Test__both("&#91;a&#93;", ".5Ba.5D", "&#91;a&#93;");
}
@Test public void Encode() {
fxt.Test__both("a+b", "a.2Bb", "a+b");
}
@Test public void Dupe() {
fxt.Test__both("a", "a", "a");
fxt.Test__both("a", "a_2", "a");
fxt.Test__both("A", "A_3", "A");
}
@Test public void Comment() {
fxt.Test__text("a<!--b-->c", "ac");
}
@Test public void Remove_comment__one() {
fxt.Test__remove_comment("a<!--b-->c", "ac");
}
@Test public void Remove_comment__many() {
fxt.Test__remove_comment("1<!--2-->3<!--4-->5", "135");
}
@Test public void Remove_comment__dangling() {
fxt.Test__remove_comment("1<!--2-->3<!--4->5", "13");
}
}
class Xoh_toc_wkr__txt__fxt {
private final Xoh_toc_wkr__txt wkr = new Xoh_toc_wkr__txt();
private final Xoh_toc_itm itm = new Xoh_toc_itm();
private final Bry_bfr tmp = Bry_bfr_.New();
public void Clear() {wkr.Clear();}
public void Test__id (String html, String expd_id) {Test__both(html, expd_id, null);}
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_.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");
}
public void Test__remove_comment(String html, String expd) {
byte[] html_bry = Bry_.new_u8(html);
Gftest.Eq__str(expd, Xoh_toc_wkr__txt.Remove_comment(tmp, html_bry, 0, html_bry.length));
}
}

@ -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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.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();
@Test public void I() {fxt.Test__both("<i>a</i>" , "a", "<i>a</i>");}
@Test public void I__id() {fxt.Test__both("<i id='1'>a</i>" , "a", "<i>a</i>");}
@Test public void B() {fxt.Test__both("<b>a</b>" , "a", "<b>a</b>");}
@Test public void Sup() {fxt.Test__both("<sup>a</sup>" , "a", "<sup>a</sup>");}
@Test public void Sub() {fxt.Test__both("<sub>a</sub>" , "a", "<sub>a</sub>");}
@Test public void Bdi() {fxt.Test__both("<bdi>a</bdi>" , "a", "<bdi>a</bdi>");}
@Test public void Span() {fxt.Test__both("<span>a</span>" , "a", "a");}
@Test public void Span__id() {fxt.Test__both("<span id='1'>a</span>" , "a", "a");}
@Test public void Span__dir() {fxt.Test__both("<span dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
@Test public void Span__dir_id() {fxt.Test__both("<span id='1' dir=\"ltr\">a</span>" , "a", "<span dir=\"ltr\">a</span>");}
@Test public void Small() {fxt.Test__text("<small>a</small>" , "a");}
@Test public void A() {fxt.Test__both("<a href=\"/wiki/A\">b</a>" , "b");}
@Test public void A__nest() {fxt.Test__both("<a href=\"/wiki/A\">b<i>c</i>d</a>" , "bcd", "b<i>c</i>d");}
@Test public void Br() {fxt.Test__both("a<br/>b" , "ab");}
@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");}
}

@ -16,108 +16,32 @@ 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.*; import gplx.langs.htmls.docs.*;
class Xoh_toc_wtr {
private final Gfh_tag_rdr tag_rdr = Gfh_tag_rdr.New__html();
private byte[] page_name = Bry_.Empty;
private final Bry_bfr bfr = Bry_bfr_.New();
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; private boolean page_banner;
public void Clear() {
bfr.Clear();
itms.Clear();
lvl_wkr.Clear();
txt_wkr.Clear();
htmlr.Clear();
}
public void Page_name_(byte[] page_name) {this.page_name = page_name;}
public byte[] Convert(byte[] src) { // text within hdr; EX: <h2>Abc</h2> -> Abc
int end = src.length;
tag_rdr.Init(page_name, src, 0, end);
Convert_recurse(0, src, 0, end);
return bfr.To_bry_and_clear_and_trim();
public void Init(byte[] toc_title, boolean page_banner) {
this.toc_title = toc_title;
this.page_banner = page_banner;
}
private static void Add_wo_comment(Bry_bfr bfr, byte[] src, int bgn, int end) {
int pos = bgn;
while (true) {
int comm_bgn = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_bgn, pos, end);
if (comm_bgn != -1) {
int tmp_pos = comm_bgn + Gfh_tag_.Comm_bgn_len;
int comm_end = Bry_find_.Find_fwd(src, Gfh_tag_.Comm_end, tmp_pos, end);
if (comm_end != -1) {
bfr.Add_mid(src, pos, comm_bgn);
pos = comm_end + Gfh_tag_.Comm_end_len;
continue;
}
}
bfr.Add_mid(src, pos, end);
break;
}
public void 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, hdr_txt);
itms.Add(itm.Anch(), itm);
}
private void Convert_recurse(int depth, byte[] src, int pos, int end) {
tag_rdr.Src_rng_(pos, end);
while (pos < end) {
Gfh_tag lhs = tag_rdr.Tag__move_fwd_head();
int tag_id = lhs.Name_id();
// add any text before lhs;
int txt_end = lhs.Src_bgn();
switch (tag_id) {
case Gfh_tag_.Id__eos: txt_end = end; break; // eos; print everything until end
}
if (pos < txt_end) Add_wo_comment(bfr, src, pos, txt_end);
// set print_tag / recurse based on tag
boolean print_tag = false, recurse = true;
switch (tag_id) {
case Gfh_tag_.Id__eos: // eos; return;
return;
case Gfh_tag_.Id__comment: // never print tag
case Gfh_tag_.Id__img:
case Gfh_tag_.Id__br: case Gfh_tag_.Id__hr: // always ignore in TOC text; EX: en.wikipedia.org/wiki/Magnetic_resonance_imaging; ====''T''<span style="display:inline-block; margin-bottom:-0.3em; vertical-align:-0.4em; line-height:1.2em; font-size:85%; text-align:left;">*<br />2</span>-weighted MRI====
case Gfh_tag_.Id__h1: case Gfh_tag_.Id__h2: case Gfh_tag_.Id__h3: case Gfh_tag_.Id__h4: case Gfh_tag_.Id__h5: case Gfh_tag_.Id__h6:
case Gfh_tag_.Id__ul: case Gfh_tag_.Id__ol: case Gfh_tag_.Id__dd: case Gfh_tag_.Id__dt: case Gfh_tag_.Id__li:
case Gfh_tag_.Id__table: case Gfh_tag_.Id__tr: case Gfh_tag_.Id__td: case Gfh_tag_.Id__th: case Gfh_tag_.Id__thead: case Gfh_tag_.Id__tbody: case Gfh_tag_.Id__caption:
// case Gfh_tag_.Id__ref: // NOTE: don't bother printing references; NOTE: should never show up
print_tag = false;
recurse = false;
break;
case Gfh_tag_.Id__b: // always print tag
case Gfh_tag_.Id__i:
print_tag = true;
break;
case Gfh_tag_.Id__small: // only print tag if not nested
case Gfh_tag_.Id__sup:
case Gfh_tag_.Id__any:
default: {
if (depth > 0)
print_tag = true;
break;
}
case Gfh_tag_.Id__a: // a never prints tag; also, also, do not recurse if ref
print_tag = false;
byte[] href_val = lhs.Atrs__get_as_bry(Gfh_atr_.Bry__href);
if (Bry_.Has_at_bgn(href_val, gplx.xowa.xtns.cites.Ref_html_wtr_cfg.Note_href_bgn)) // do not print if href='#cite_note-...'; EX: <a href=\"#cite_note-0\">[1]</a>
recurse = false;
break;
}
// get lhs / rhs vars
int lhs_bgn = lhs.Src_bgn(), lhs_end = lhs.Src_end();
boolean lhs_is_pair = !lhs.Tag_is_inline();
int rhs_bgn = -1, rhs_end = -1, new_pos = lhs_end;
if (lhs_is_pair) { // get rhs unless inline
Gfh_tag rhs = tag_rdr.Tag__move_fwd_tail(tag_id);
rhs_bgn = rhs.Src_bgn(); rhs_end = rhs.Src_end();
new_pos = rhs_end;
}
// print "<tag></tag>"; also, recurse
if (print_tag) bfr.Add_mid(src, lhs_bgn, lhs_end);
if (recurse) {
Convert_recurse(depth + 1, src, lhs_end, rhs_bgn);
}
if (print_tag && lhs_is_pair)
bfr.Add_mid(src, rhs_bgn, rhs_end);
// set new_pos
pos = new_pos;
tag_rdr.Src_rng_(new_pos, end); // NOTE: must reinit pos and especially end
}
public byte[] To_html() {
return htmlr.To_html(itms, toc_title, page_banner);
}
public byte[] Test__to_html() {
return htmlr.Test__to_html(itms);
}
}

@ -1,36 +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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wtr__anch__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Caption() {
fxt.Test__convert("<a href=\"/wiki/A\">b</a>", "b");
}
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
fxt.Test__convert("a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>", "a");
}
@Test public void Category() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
fxt.Test__convert("A<a href=\"/wiki/Category:B\">Category:B</a>", "ACategory:B");
}
@Test public void File() { // PURPOSE: file should not show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
fxt.Test__convert
( "<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"
, "b");
}
}

@ -1,55 +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.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoh_toc_wtr__keep__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Basic() {
fxt.Test__convert("a b c", "a b c");
}
@Test public void Ws() {
fxt.Test__convert(" a b ", "a b");
}
@Test public void Amp__ncr() {
fxt.Test__convert("&#91;a&#93;", "&#91;a&#93;");
}
@Test public void Italic() {
fxt.Test__convert("<i>a</i>", "<i>a</i>");
}
@Test public void Caption() {
fxt.Test__convert("<a href=\"/wiki/A\">b</a>", "b");
}
@Test public void Ref() { // PURPOSE: ref contents should not print in TOC; DATE:2013-07-23
fxt.Test__convert("a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>", "a");
}
@Test public void Category__literal() { // PURPOSE: literal Category should show in in TOC; EX: de.w:1234; DATE:2014-01-21
fxt.Test__convert("A<a href=\"/wiki/Category:B\">Category:B</a>", "ACategory:B");
}
@Test public void File() { // PURPOSE: file should show in in TOC; EX: tr.w:D<>nya_Miraslari; DATE:2014-06-06
fxt.Test__convert
( "<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"
, "b");
}
}
class Xoh_toc_wtr_fxt {
private final Xoh_toc_wtr wtr = new Xoh_toc_wtr();
public void Clear() {wtr.Clear();}
public void Test__convert(String html, String expd) {
Gftest.Eq__str(expd, wtr.Convert(Bry_.new_u8(html)));
}
}

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

Loading…
Cancel
Save