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

'v3.7.1.1'

This commit is contained in:
gnosygnu
2016-07-03 22:41:56 -04:00
parent 1a4ca00c0b
commit 36584a0cc2
220 changed files with 4762 additions and 2627 deletions

View File

@@ -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) {

View File

@@ -1,90 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.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;
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 Clear_safe() {synchronized (thread_lock) {Clear_fast();}}
public void Clear_fast() {
this.pool = new Gfo_poolable_itm[pool_len];
for (int i = 0; i < pool_len; ++i)
pool[i] = prototype.Pool__make(this, i, make_args);
this.free_ary = new int[pool_len];
pool_nxt = free_len = 0;
}
public Gfo_poolable_itm Get_safe() {synchronized (thread_lock) {return Get_fast();}}
public Gfo_poolable_itm Get_fast() {
Gfo_poolable_itm rv = null;
int pool_idx = -1;
if (free_len > 0) { // free_itms in pool; use it
pool_idx = free_ary[--free_len];
rv = pool[pool_idx];
}
else { // nothing in pool; take next
if (pool_nxt == pool_len)
Expand_pool();
pool_idx = pool_nxt++;
rv = pool[pool_idx];
if (rv == null) {
rv = prototype.Pool__make(this, pool_idx, make_args);
pool[pool_idx] = rv;
}
}
return rv;
}
public void Rls_safe(int idx) {synchronized (thread_lock) {Rls_safe(idx);}}
public void Rls_fast(int idx) {
if (idx == -1) throw Err_.new_wo_type("rls called on poolable that was not created by pool_mgr");
int pool_idx = pool_nxt - 1;
if (idx == pool_idx) // in-sequence; decrement count
if (free_len == 0)
this.pool_nxt = pool_idx;
else { // idx == pool_idx; assume entire pool released, but out of order
for (int i = 0; i < free_len; ++i)
free_ary[i] = 0;
free_len = 0;
}
else { // out-of-sequence
free_ary[free_len] = idx;
++free_len;
}
}
private void Expand_pool() {
// expand pool
int new_pool_len = pool_len == 0 ? 2 : pool_len * 2;
Gfo_poolable_itm[] new_pool = new Gfo_poolable_itm[new_pool_len];
Array_.Copy_to(pool, 0, new_pool, 0, pool_len);
this.pool = new_pool;
this.pool_len = new_pool_len;
// expand free_ary to same len
int[] new_free = new int[pool_len];
Array_.Copy_to(free_ary, 0, new_free, 0, free_len);
this.free_ary = new_free;
}
@gplx.Internal protected int[] Free_ary() {return free_ary;} private int[] free_ary; private int free_len;
@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;}
}

View File

@@ -1,83 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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();
@Before public void init() {tstr.Clear();}
@Test public void Get__one() {
tstr.Test__get(0);
tstr.Test__free__len(0);
tstr.Test__pool__len(2);
}
@Test public void Get__many__expand() {
tstr.Test__get(0);
tstr.Test__get(1);
tstr.Test__get(2);
tstr.Test__free__len(0);
tstr.Test__pool__len(4);
}
@Test public void Rls__lifo() {
tstr.Test__get(0);
tstr.Test__get(1);
tstr.Test__get(2);
tstr.Exec__rls(2);
tstr.Exec__rls(1);
tstr.Exec__rls(0);
tstr.Test__pool__nxt(0);
tstr.Test__free__len(0);
}
@Test public void Rls__fifo() {
tstr.Test__get(0);
tstr.Test__get(1);
tstr.Test__get(2);
tstr.Exec__rls(0);
tstr.Exec__rls(1);
tstr.Test__pool__nxt(3);
tstr.Test__free__len(2); // 2 items in free_ary
tstr.Test__free__ary(0, 1, 0, 0);
tstr.Test__get(1);
tstr.Exec__rls(1);
tstr.Exec__rls(2);
tstr.Test__free__len(0); // 0 items in free_ary
tstr.Test__free__ary(0, 0, 0, 0);
}
}
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);
public void Clear() {mgr.Clear_fast();}
public void Test__get(int expd_idx) {
Sample_poolable_itm actl_itm = (Sample_poolable_itm)mgr.Get_fast();
Tfds.Eq(expd_idx, actl_itm.Pool__idx(), "pool_idx");
}
public void Test__free__ary(int... expd) {Tfds.Eq_ary(expd, mgr.Free_ary(), "mgr.Free_ary()");}
public void Test__free__len(int expd) {Tfds.Eq(expd, mgr.Free_len(), "mgr.Free_len()");}
public void Test__pool__len(int expd) {Tfds.Eq(expd, mgr.Pool_len(), "mgr.Pool_len()");}
public void Test__pool__nxt(int expd) {Tfds.Eq(expd, mgr.Pool_nxt(), "mgr.Pool_nxt()");}
public void Exec__rls(int idx) {mgr.Rls_fast(idx);}
}
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 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);}
}

View File

@@ -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 = "<!--"

View File

@@ -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()

View File

@@ -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 = "";

View File

@@ -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();
}
}
}

View File

@@ -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);}

View File

@@ -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"

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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));
}
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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"

View File

@@ -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.*;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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);}

View File

@@ -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.*;

View File

@@ -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();

View File

@@ -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 , "");

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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));}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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()

View File

@@ -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

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;'")

View File

@@ -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) {

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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>'
}
}

View File

@@ -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;")
;
}

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -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;")
;
}

View File

@@ -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;
}

View File

@@ -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
;
}

View File

@@ -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"));
}
}

View File

@@ -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;'>"

View File

@@ -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;'>"

View File

@@ -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;

View File

@@ -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)));

View File

@@ -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;}
}

View File

@@ -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>"
);
}
}

View File

@@ -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());

View File

@@ -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) {

View File

@@ -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"
);
}

View File

@@ -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())));
}
}

View File

@@ -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;}
}

View File

@@ -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);
}
}

View File

@@ -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");
}
}

View File

@@ -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);
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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));
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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");}
}

View File

@@ -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);
}
}

View File

@@ -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");
}
}

View File

@@ -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)));
}
}

View File

@@ -1,34 +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__nest__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Xnde__xnde() { // <sup> removed but not <small>
fxt.Test__convert("a <sup>b<small>c</small>d</sup> e", "a b<small>c</small>d e");
}
@Test public void Xnde__inline() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
fxt.Test__convert("a<span id='b'>b<br/></span>", "ab");
}
@Test public void Xnde__lnki() { // <small> and <a> removed
fxt.Test__convert("<small><a href=\"/wiki/A\">b</a></small>", "b");
}
@Test public void Lnki__xnde() {
fxt.Test__convert("<a href=\"/wiki/A\">b<i>c</i>d</a>", "b<i>c</i>d");
}
}

View File

@@ -1,52 +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__skip__tst {
@Before public void init() {fxt.Clear();} private final Xoh_toc_wtr_fxt fxt = new Xoh_toc_wtr_fxt();
@Test public void Comment() {
fxt.Test__convert("<!--a-->", "");
}
@Test public void Comment__many() {
fxt.Test__convert("1<!--2-->3<!--4-->5", "135");
}
@Test public void Comment__dangling() {
fxt.Test__convert("1<!--2-->3<!--4->5", "13<!--4->5");
}
@Test public void Br() {
fxt.Test__convert("a<br/>b", "ab");
}
@Test public void H2() {
fxt.Test__convert("a<h2>b</h2>c", "ac");
}
@Test public void Li() {
fxt.Test__convert("a<ul><li>b</li></ul>c", "ac");
}
@Test public void Table() {
fxt.Test__convert("a<table><tr><td>b</td></tr></table>c", "ac");
}
@Test public void Xnde__small() {
fxt.Test__convert("<small>a</small>", "a");
}
@Test public void Xnde__sup() {
fxt.Test__convert("<sup>a</sup>", "a");
}
@Test public void Translate() { // PURPOSE: <translate> is an xtn and parses its innerText separately; meanwhile, toc_mgr defaults to using the innerText to build toc; EX:Wikidata:Introduction; DATE:2013-07-16
fxt.Test__convert("<translate><!--b-->ac</translate>", "ac");
}
}

View File

@@ -180,7 +180,7 @@ public class Xow_toc_mgr implements gplx.core.brys.Bfr_arg {
break;
case Xop_tkn_itm_.Tid_apos: html_wtr.Apos (ctx, html_wtr_opts, bfr, src, (Xop_apos_tkn)sub); break;
case Xop_tkn_itm_.Tid_html_ncr: html_wtr.Html_ncr (ctx, html_wtr_opts, bfr, src, (Xop_amp_tkn_num)sub); break;
case Xop_tkn_itm_.Tid_html_ref: html_wtr.Html_ref (ctx, html_wtr_opts, bfr, src, (Xop_amp_tkn_txt)sub); break;
case Xop_tkn_itm_.Tid_html_ref: html_wtr.Html_ref (ctx, html_wtr_opts, bfr, src, (Xop_amp_tkn_ent)sub); break;
default:
if (sub.Subs_len() == 0) // NOTE: never call html_wtr directly unless leaf elem; DATE:2014-06-22
html_wtr.Write_tkn(bfr, ctx, html_wtr_opts, src, tkn, Xoh_html_wtr.Sub_idx_null, sub);
@@ -190,7 +190,7 @@ public class Xow_toc_mgr implements gplx.core.brys.Bfr_arg {
}
}
}
public void Html(Xoae_page page, Xoh_wtr_ctx hctx, byte[] src, Bry_bfr bfr, boolean write_toc_cls) {
public void Html(Xoae_page page, Xoh_wtr_ctx hctx, byte[] src, Bry_bfr bfr, boolean write_toc_cls) { // write_toc_cls needed for Page_banner
if (!page.Hdr_mgr().Toc_enabled()) return; // REF.MW: Parser.php|formatHeadings
if (hctx.Mode_is_hdump()) return;
this.page = page;

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.htmls.core.htmls.*;
public class Xow_toc_mgr_tst {
public class Xow_toc_mgr_tst {
@Before public void init() {fxt.Clear();} private final Xow_toc_mgr_fxt fxt = new Xow_toc_mgr_fxt();
@Test public void Basic() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
@@ -173,7 +173,7 @@ public class Xow_toc_mgr_tst {
, " </ul>"
));
}
@Test public void Encode() {
@Test public void Id__encode() {
fxt.Test_html_toc(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a+b=="
@@ -215,7 +215,7 @@ public class Xow_toc_mgr_tst {
, ""
));
}
@Test public void Xnde_italic() {
@Test public void Xnde__italic() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<i>a</i>=="
@@ -230,7 +230,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a'><i>a</i></span></h2>"
));
}
@Test public void Xnde_small() {
@Test public void Xnde__small() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>a</small>=="
@@ -245,7 +245,61 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a'><small>a</small></span></h2>"
));
}
@Test public void Xnde_dangling() { // PURPOSE: do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
@Test public void Xnde__li() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<ul><li>b</li></ul>c=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>" // NOTE: toctext should be "abc", not "ab"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='abc'>a<ul>"
, "<li>b</li></ul>c</span></h2>"
));
}
@Test public void Xnde__table() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<table><tr><td>b</td></tr></table>c=="
)
, String_.Concat_lines_nl
( fxt.toc_tbl_nl_n
( " <ul>"
, " <li class=\"toclevel-1 tocsection-1\"><a href=\"#a.3Ctable.3E.3Ctr.3E.3Ctd.3Eb.3C.2Ftd.3E.3C.2Ftr.3E.3C.2Ftable.3Ec\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">abc</span></a>" // NOTE: toc id should be "abc"
, " </li>"
, " </ul>"
)
, "<h2><span class='mw-headline' id='a.3Ctable.3E.3Ctr.3E.3Ctd.3Eb.3C.2Ftd.3E.3C.2Ftr.3E.3C.2Ftable.3Ec'>a"
, "<table>"
, " <tr>"
, " <td>b"
, " </td>"
, " </tr>"
, "</table>"
, "c</span></h2>"
));
}
// TOMBSTONE: on MW, shows up as 'href="#ab"; <span class="toctext">ab</span>; '; TIDY doing strange things; ignore for now; DATE:2016-06-28
//@Test public void Xnde__h2() {
// fxt.Test_html_all(String_.Concat_lines_nl_skip_last
// ( "__FORCETOC__"
// , "==a<h2>b</h2>c=="
// )
// , String_.Concat_lines_nl
// ( fxt.toc_tbl_nl_n
// ( " <ul>"
// , " <li class=\"toclevel-1 tocsection-1\"><a href=\"#abc\"><span class=\"tocnumber\">1</span> <span class=\"toctext\">ac</span></a>"
// , " </li>"
// , " </ul>"
// )
// , "<h2><span class='mw-headline' id='abc'>a<h2>b</h2>c</span></h2>"
// ));
//}
@Test public void Xnde__dangling() { // PURPOSE: do not render dangling xndes; EX: Casualties_of_the_Iraq_War; ===<small>Iraqi Health Ministry<small>===
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>a<small>=="
@@ -260,7 +314,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a'><small>a<small></small></small></span></h2>"
));
}
@Test public void Xnde_nest_xnde() {
@Test public void Nest__xnde__small() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a <sup>b<small>c</small>d</sup> e=="
@@ -275,7 +329,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='a_bcd_e'>a <sup>b<small>c</small>d</sup> e</span></h2>"
));
}
@Test public void Xnde_nest_lnki() {
@Test public void Nest__lnki() {
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==<small>[[a|b]]</small>=="
@@ -290,7 +344,7 @@ public class Xow_toc_mgr_tst {
, "<h2><span class='mw-headline' id='b'><small><a href=\"/wiki/A\">b</a></small></span></h2>"
));
}
@Test public void Xnde_nest_inline() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
@Test public void Nest__br() { // PURPOSE: do not render inline xndes; EX: Magnetic_resonance_imaging
fxt.Test_html_all(String_.Concat_lines_nl_skip_last
( "__FORCETOC__"
, "==a<span id=\"b\">b<br/></span>=="

View File

@@ -32,6 +32,10 @@ public class Xoa_lang_mgr implements Gfo_invk {
public Xol_lang_itm Get_at(int i) {return (Xol_lang_itm)hash.Get_at(i);}
public Xol_lang_itm Get_by(byte[] key) {return (Xol_lang_itm)hash.Get_by(key);}
public Xol_lang_itm Get_by_or_load(byte[] key) {return Get_by_or_new(key).Init_by_load_assert();}
public Xol_lang_itm Get_by_or_en(byte[] key) { // called by Xowv_wiki for its .Lang()
Xol_lang_itm rv = Get_by(key);
return rv == null ? lang_en : rv;
}
public Xol_lang_itm Get_by_or_new(byte[] key) {
Xol_lang_itm rv = Get_by(key);
if (rv == null) {

View File

@@ -25,7 +25,7 @@ public class Xop_tkn_mkr {
public Xop_space_tkn Space_mutable(int bgn, int end) {return new Xop_space_tkn(false, bgn, end);}
public Xop_apos_tkn Apos(int bgn, int end
, int aposLen, int typ, int cmd, int lit_apos) {return new Xop_apos_tkn(bgn, end, aposLen, typ, cmd, lit_apos);}
public Xop_tkn_itm Amp_txt(int bgn, int end, Xop_amp_trie_itm itm) {return new Xop_amp_tkn_txt(bgn, end, itm);}
public Xop_tkn_itm Amp_txt(int bgn, int end, Xop_amp_trie_itm itm) {return new Xop_amp_tkn_ent(bgn, end, itm);}
public Xop_tkn_itm Amp_num(int bgn, int end, int val_int, byte[] val_bry) {return new Xop_amp_tkn_num(bgn, end, val_int, val_bry);}
public Xop_tkn_itm Amp_num(int bgn, int end, int val_int) {return new Xop_amp_tkn_num(bgn, end, val_int, gplx.core.intls.Utf16_.Encode_int_to_bry(val_int));}
public Xop_nl_tkn NewLine(int bgn, int end, byte nl_typ, int nl_len) {return new Xop_nl_tkn(bgn, end, nl_typ, nl_len);}

View File

@@ -17,113 +17,189 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_amp_mgr {
private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(32);
public class Xop_amp_mgr { // TS
public Btrie_slim_mgr Amp_trie() {return amp_trie;} private final Btrie_slim_mgr amp_trie = Xop_amp_trie.Instance;
public int Rslt_pos() {return rslt_pos;} private int rslt_pos;
public int Rslt_val() {return rslt_val;} private int rslt_val;
public Xop_tkn_itm Parse_as_tkn(Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, int amp_pos, int cur_pos) {
synchronized (thread_lock_1) {
rslt_pos = amp_pos + 1; // default to fail pos; after amp;
Object o = amp_trie.Match_bgn(src, cur_pos, src_len);
cur_pos = amp_trie.Match_pos();
if (o == null) return null;
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
switch (itm.Tid()) {
case Xop_amp_trie_itm.Tid_name_std:
case Xop_amp_trie_itm.Tid_name_xowa:
rslt_pos = cur_pos;
return tkn_mkr.Amp_txt(amp_pos, cur_pos, itm);
case Xop_amp_trie_itm.Tid_num_hex:
case Xop_amp_trie_itm.Tid_num_dec:
boolean ncr_is_hex = itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
boolean pass = Parse_as_int(ncr_is_hex, src, src_len, amp_pos, cur_pos);
return pass ? tkn_mkr.Amp_num(amp_pos, rslt_pos, rslt_val) : null;
default: throw Err_.new_unhandled(itm.Tid());
}
public Xop_amp_mgr_rslt Parse_tkn(Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, int amp_pos, int bgn) {
int fail_pos = amp_pos + 1; // default to fail pos which is after &
// check amp_trie; EX: 'lt'
Xop_amp_mgr_rslt rv = new Xop_amp_mgr_rslt();
Btrie_rv match = amp_trie.Match_at(src, bgn, src_len);
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)match.Obj();
int cur = match.Pos();
match.Pool__rls();
if (itm == null) {
rv.Pass_n_(fail_pos);
return rv;
}
}
public boolean Parse_as_int(boolean ncr_is_hex, byte[] src, int src_len, int amp_pos, int int_bgn) {
synchronized (thread_lock_2) {
rslt_pos = amp_pos + 1; // default to fail pos; after amp;
rslt_val = -1; // clear any previous setting
int cur_pos = int_bgn, int_end = -1;
int semic_pos = Bry_find_.Find_fwd(src, Byte_ascii.Semic, cur_pos, src_len);
if (semic_pos == Bry_find_.Not_found) return false;
int_end = semic_pos - 1; // int_end = pos before semicolon
int multiple = ncr_is_hex ? 16 : 10, val = 0, factor = 1, cur = 0;
for (int i = int_end; i >= int_bgn; i--) {
byte b = src[i];
if (ncr_is_hex) {
if (b >= 48 && b <= 57) cur = b - 48;
else if (b >= 65 && b <= 70) cur = b - 55;
else if (b >= 97 && b <= 102) cur = b - 87;
else if((b >= 71 && b <= 90)
|| (b >= 91 && b <= 122)) continue; // NOTE: wiki discards letters G-Z; PAGE:en.w:Miscellaneous_Symbols "{{Unicode|&#xx26D0;}}"; NOTE 2nd x is discarded
else return false;
// check itm
switch (itm.Tid()) {
// letters; EX: '&lt;'
case Xop_amp_trie_itm.Tid_name_std:
case Xop_amp_trie_itm.Tid_name_xowa:
rv.Pos_(cur);
rv.Tkn_(tkn_mkr.Amp_txt(amp_pos, cur, itm));
return rv;
// numbers; EX: '&#123;' '&#x123'
case Xop_amp_trie_itm.Tid_num_hex:
case Xop_amp_trie_itm.Tid_num_dec:
boolean ncr_is_hex = itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
boolean pass = Parse_ncr(rv, ncr_is_hex, src, src_len, amp_pos, cur);
if (pass) { // NOTE: do not set rv.Pos_(); will be set by Parse_ncr
rv.Tkn_(tkn_mkr.Amp_num(amp_pos, rv.Pos(), rv.Val()));
return rv;
}
else {
cur = b - Byte_ascii.Num_0;
if (cur < 0 || cur > 10) return false;
rv.Pass_n_(fail_pos);
return rv;
}
val += cur * factor;
if (val > gplx.core.intls.Utf8_.Codepoint_max) return false; // fail if value > largest_unicode_codepoint
factor *= multiple;
}
rslt_val = val;
rslt_pos = semic_pos + 1; // position after semic
return true;
default: throw Err_.new_unhandled_default(itm.Tid());
}
}
public boolean Parse_ncr(Xop_amp_mgr_rslt rv, boolean ncr_is_hex, byte[] src, int src_len, int amp_pos, int num_bgn) {
int fail_pos = amp_pos + 1; // default to fail pos; after amp;
// find semic; fail if none found
int semic_pos = Bry_find_.Find_fwd(src, Byte_ascii.Semic, num_bgn, src_len);
if (semic_pos == Bry_find_.Not_found) return rv.Pass_n_(fail_pos);
int num_end = semic_pos - 1; // num_end = pos before semicolon
// calc amp_val; EX: &#x3A3; -> 931; &#931; -> 931;
int multiple = ncr_is_hex ? 16 : 10, val = 0, factor = 1, cur = 0;
for (int i = num_end; i >= num_bgn; i--) {
byte b = src[i];
if (ncr_is_hex) {
if (b >= 48 && b <= 57) cur = b - 48;
else if (b >= 65 && b <= 70) cur = b - 55;
else if (b >= 97 && b <= 102) cur = b - 87;
else if((b >= 71 && b <= 90)
|| (b >= 91 && b <= 122)) continue; // NOTE: wiki discards letters G-Z; PAGE:en.w:Miscellaneous_Symbols "{{Unicode|&#xx26D0;}}"; NOTE 2nd x is discarded
else return rv.Pass_n_(fail_pos);
}
else {
cur = b - Byte_ascii.Num_0;
if (cur < 0 || cur > 10) return rv.Pass_n_(fail_pos);
}
val += cur * factor;
if (val > gplx.core.intls.Utf8_.Codepoint_max) return rv.Pass_n_(fail_pos); // fail if value > largest_unicode_codepoint
factor *= multiple;
}
return rv.Pass_y_(semic_pos + 1, val); // +1 to position after semic
}
public byte[] Decode_as_bry(byte[] src) {
if (src == null) return src;
int src_len = src.length;
boolean dirty = false;
int end = src.length;
int pos = 0;
synchronized (tmp_bfr) {
while (pos < src_len) {
byte b = src[pos];
if (b == Byte_ascii.Amp) {
int nxt_pos = pos + 1;
if (nxt_pos < src_len) {
byte nxt_b = src[nxt_pos];
Object amp_obj = amp_trie.Match_bgn_w_byte(nxt_b, src, nxt_pos, src_len);
if (amp_obj != null) {
if (!dirty) {
tmp_bfr.Add_mid(src, 0, pos);
Xop_amp_mgr_rslt amp_rv = null;
Bry_bfr bfr = null;
// scan for &
while (pos < end) {
byte b = src[pos];
if (b == Byte_ascii.Amp) { // & found
int nxt_pos = pos + 1;
if (nxt_pos < end) { // check & is not eos
byte nxt_b = src[nxt_pos];
Btrie_rv trie_rv = amp_trie.Match_at_w_b0(nxt_b, src, nxt_pos, end);
Object amp_obj = trie_rv.Obj();
int amp_pos = trie_rv.Pos();
trie_rv.Pool__rls();
if (amp_obj != null) {
if (!dirty) { // 1st amp found; add preceding String to bfr
if (bfr == null) {
bfr = Bry_bfr_.Get();
dirty = true;
}
Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)amp_obj;
switch (amp_itm.Tid()) {
case Xop_amp_trie_itm.Tid_name_std:
case Xop_amp_trie_itm.Tid_name_xowa:
tmp_bfr.Add(amp_itm.U8_bry());
pos = amp_trie.Match_pos();
break;
case Xop_amp_trie_itm.Tid_num_hex:
case Xop_amp_trie_itm.Tid_num_dec:
boolean ncr_is_hex = amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
int int_bgn = amp_trie.Match_pos();
if (Parse_as_int(ncr_is_hex, src, src_len, pos, int_bgn))
tmp_bfr.Add_u8_int(rslt_val);
else
tmp_bfr.Add_mid(src, pos, nxt_pos);
pos = rslt_pos;
break;
default:
throw Err_.new_unhandled(amp_itm.Tid());
}
continue;
bfr.Add_mid(src, 0, pos);
}
}
}
if (dirty)
tmp_bfr.Add_byte(b);
++pos;
Xop_amp_trie_itm amp_itm = (Xop_amp_trie_itm)amp_obj;
switch (amp_itm.Tid()) {
case Xop_amp_trie_itm.Tid_name_std:
case Xop_amp_trie_itm.Tid_name_xowa:
bfr.Add(amp_itm.U8_bry());
pos = amp_pos;
break;
case Xop_amp_trie_itm.Tid_num_hex:
case Xop_amp_trie_itm.Tid_num_dec:
boolean ncr_is_hex = amp_itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
int int_bgn = amp_pos;
if (amp_rv == null)
amp_rv = new Xop_amp_mgr_rslt();
boolean pass = Parse_ncr(amp_rv, ncr_is_hex, src, end, pos, int_bgn);
if (pass)
bfr.Add_u8_int(amp_rv.Val());
else
bfr.Add_mid(src, pos, nxt_pos);
pos = amp_rv.Pos();
break;
default:
throw Err_.new_unhandled_default(amp_itm.Tid());
}
continue;
}
}
}
return dirty ? tmp_bfr.To_bry_and_clear() : src;
if (dirty)
bfr.Add_byte(b);
++pos;
}
return dirty ? bfr.To_bry_and_clear_and_rls() : src;
}
public static final Xop_amp_mgr Instance = new Xop_amp_mgr(); Xop_amp_mgr() {}
// private Xop_tkn_itm Parse_as_tkn_old(Xop_tkn_mkr tkn_mkr, byte[] src, int src_len, int amp_pos, int cur_pos) {
// synchronized (thread_lock_1) {
// rv_pos = amp_pos + 1; // default to fail pos; after amp;
// Object o = amp_trie.Match_bgn(src, cur_pos, src_len);
// cur_pos = amp_trie.Match_pos();
// if (o == null) return null;
// Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
// switch (itm.Tid()) {
// case Xop_amp_trie_itm.Tid_name_std:
// case Xop_amp_trie_itm.Tid_name_xowa:
// rv_pos = cur_pos;
// return tkn_mkr.Amp_txt(amp_pos, cur_pos, itm);
// case Xop_amp_trie_itm.Tid_num_hex:
// case Xop_amp_trie_itm.Tid_num_dec:
// boolean ncr_is_hex = itm.Tid() == Xop_amp_trie_itm.Tid_num_hex;
// Xop_amp_mgr_rslt rv = Parse_as_int2(ncr_is_hex, src, src_len, amp_pos, cur_pos);
// return rv.Pass() ? tkn_mkr.Amp_num(amp_pos, rv_pos, rslt_val) : null;
// default: throw Err_.new_unhandled(itm.Tid());
// }
// }
// }
// private boolean Parse_as_int_old(boolean ncr_is_hex, byte[] src, int src_len, int amp_pos, int int_bgn) {
// synchronized (thread_lock_2) {
// rv_pos = amp_pos + 1; // default to fail pos; after amp;
// rslt_val = -1; // clear any previous setting
// int cur_pos = int_bgn, int_end = -1;
// int semic_pos = Bry_find_.Find_fwd(src, Byte_ascii.Semic, cur_pos, src_len);
// if (semic_pos == Bry_find_.Not_found) return false;
// int_end = semic_pos - 1; // int_end = pos before semicolon
// int multiple = ncr_is_hex ? 16 : 10, val = 0, factor = 1, cur = 0;
// for (int i = int_end; i >= int_bgn; i--) {
// byte b = src[i];
// if (ncr_is_hex) {
// if (b >= 48 && b <= 57) cur = b - 48;
// else if (b >= 65 && b <= 70) cur = b - 55;
// else if (b >= 97 && b <= 102) cur = b - 87;
// else if((b >= 71 && b <= 90)
// || (b >= 91 && b <= 122)) continue; // NOTE: wiki discards letters G-Z; PAGE:en.w:Miscellaneous_Symbols "{{Unicode|&#xx26D0;}}"; NOTE 2nd x is discarded
// else return false;
// }
// else {
// cur = b - Byte_ascii.Num_0;
// if (cur < 0 || cur > 10) return false;
// }
// val += cur * factor;
// if (val > gplx.core.intls.Utf8_.Codepoint_max) return false; // fail if value > largest_unicode_codepoint
// factor *= multiple;
// }
// rslt_val = val;
// rv_pos = semic_pos + 1; // position after semic
// return true;
// }
// }
}

View File

@@ -0,0 +1,64 @@
/*
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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*; import gplx.core.tests.*;
public class Xop_amp_mgr__decode__tst {
@Before public void init() {} private final Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt();
@Test public void Text() {fxt.Test__decode_as_bry("a" , "a");}
@Test public void Name() {fxt.Test__decode_as_bry("&amp;" , "&");}
@Test public void Name_w_text() {fxt.Test__decode_as_bry("a&amp;b" , "a&b");}
@Test public void Name_fail_semic_missing() {fxt.Test__decode_as_bry("a&ampb" , "a&ampb");}
@Test public void Name_fail_amp_only() {fxt.Test__decode_as_bry("a&" , "a&");}
@Test public void Num_fail() {fxt.Test__decode_as_bry("&#!;" , "&#!;");} // ! is not valid num
@Test public void Hex_fail() {fxt.Test__decode_as_bry("&#x!;" , "&#x!;");} // ! is not valid hex
@Test public void Num_basic() {fxt.Test__decode_as_bry("&#0931;" , "Σ");}
@Test public void Num_zero_padded() {fxt.Test__decode_as_bry("&#00931;" , "Σ");}
@Test public void Hex_upper() {fxt.Test__decode_as_bry("&#x3A3;" , "Σ");}
@Test public void Hex_lower() {fxt.Test__decode_as_bry("&#x3a3;" , "Σ");}
@Test public void Hex_zero_padded() {fxt.Test__decode_as_bry("&#x03a3;" , "Σ");}
@Test public void Hex_upper_x() {fxt.Test__decode_as_bry("&#X3A3;" , "Σ");}
@Test public void Num_fail_large_codepoint() {fxt.Test__decode_as_bry("&#538189831;" , "&#538189831;");}
@Test public void Num_ignore_extra_x() {fxt.Test__decode_as_bry("&#xx26D0;" , Char_.To_str(Char_.By_int(9936)));} // 2nd x is ignored
}
class Xop_amp_mgr_fxt {
private final Xop_amp_mgr amp_mgr = Xop_amp_mgr.Instance;
public void Test__decode_as_bry(String raw, String expd) {
Gftest.Eq__str(expd, String_.new_u8(amp_mgr.Decode_as_bry(Bry_.new_u8(raw))));
}
public void Test__parse_tkn__ent(String raw, String expd) {
Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw);
Xop_amp_tkn_ent tkn = (Xop_amp_tkn_ent)rv.Tkn();
Gftest.Eq__byte(Xop_tkn_itm_.Tid_html_ref, tkn.Tkn_tid());
Gftest.Eq__str(expd, tkn.Xml_name_bry());
}
public void Test__parse_tkn__ncr(String raw, int expd) {
Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw);
Xop_amp_tkn_num tkn = (Xop_amp_tkn_num)rv.Tkn();
Gftest.Eq__byte(Xop_tkn_itm_.Tid_html_ncr, tkn.Tkn_tid());
Gftest.Eq__int(expd, tkn.Val());
}
public void Test__parse_tkn__txt(String raw, int expd) {
Xop_amp_mgr_rslt rv = Exec__parse_tkn(raw);
Gftest.Eq__null(Bool_.Y, rv.Tkn());
Gftest.Eq__int(expd, rv.Pos());
}
private Xop_amp_mgr_rslt Exec__parse_tkn(String raw) {
byte[] src = Bry_.new_u8(raw);
return amp_mgr.Parse_tkn(new Xop_tkn_mkr(), src, src.length, 0, 1);
}
}

View File

@@ -16,14 +16,12 @@ 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.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.tests.*;
public class Xop_html_num_tkn_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Xop_amp_tkn_num.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_html_ncr;}
public int Html_ncr_val() {return html_ncr_val;} public Xop_html_num_tkn_chkr Html_ncr_val_(int v) {html_ncr_val = v; return this;} private int html_ncr_val = -1;
@Override public int Chk_hook(Tst_mgr mgr, String path, Object actl_obj, int err) {
Xop_amp_tkn_num actl = (Xop_amp_tkn_num)actl_obj;
err += mgr.Tst_val(html_ncr_val == -1, path, "html_ncr_val", html_ncr_val, actl.Val());
return err;
}
import org.junit.*; import gplx.core.tests.*;
public class Xop_amp_mgr__parse_tkn__tst {
@Before public void init() {} private final Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt();
@Test public void Ent() {fxt.Test__parse_tkn__ent("&amp;" , "&amp;");} // check for html_ref
@Test public void Ent__fail() {fxt.Test__parse_tkn__txt("&nil;" , 1);}
@Test public void Num__nex() {fxt.Test__parse_tkn__ncr("&#x3A3;" , 931);} // check for html_ncr; Σ: http://en.wikipedia.org/wiki/Numeric_character_reference
@Test public void Num__dec() {fxt.Test__parse_tkn__ncr("&#931;" , 931);}
@Test public void Num__fail() {fxt.Test__parse_tkn__txt("&#" , 1);}
}

View File

@@ -1,44 +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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_amp_mgr_decode_tst {
@Before public void init() {fxt.Reset();} private Xop_amp_mgr_fxt fxt = new Xop_amp_mgr_fxt();
@Test public void Text() {fxt.Test_decode_as_bry("a" , "a");}
@Test public void Name() {fxt.Test_decode_as_bry("&amp;" , "&");}
@Test public void Name_w_text() {fxt.Test_decode_as_bry("a&amp;b" , "a&b");}
@Test public void Name_fail_semic_missing() {fxt.Test_decode_as_bry("a&ampb" , "a&ampb");}
@Test public void Name_fail_amp_only() {fxt.Test_decode_as_bry("a&" , "a&");}
@Test public void Num_fail() {fxt.Test_decode_as_bry("&#!;" , "&#!;");} // ! is not valid num
@Test public void Hex_fail() {fxt.Test_decode_as_bry("&#x!;" , "&#x!;");} // ! is not valid hex
@Test public void Num_basic() {fxt.Test_decode_as_bry("&#0931;" , "Σ");}
@Test public void Num_zero_padded() {fxt.Test_decode_as_bry("&#00931;" , "Σ");}
@Test public void Hex_upper() {fxt.Test_decode_as_bry("&#x3A3;" , "Σ");}
@Test public void Hex_lower() {fxt.Test_decode_as_bry("&#x3a3;" , "Σ");}
@Test public void Hex_zero_padded() {fxt.Test_decode_as_bry("&#x03a3;" , "Σ");}
@Test public void Hex_upper_x() {fxt.Test_decode_as_bry("&#X3A3;" , "Σ");}
@Test public void Num_fail_large_codepoint() {fxt.Test_decode_as_bry("&#538189831;" , "&#538189831;");}
@Test public void Num_ignore_extra_x() {fxt.Test_decode_as_bry("&#xx26D0;" , Char_.To_str(Char_.By_int(9936)));} // 2nd x is ignored
}
class Xop_amp_mgr_fxt {
private Xop_amp_mgr amp_mgr = Xop_amp_mgr.Instance;
public void Reset() {}
public void Test_decode_as_bry(String raw, String expd) {
Tfds.Eq(expd, String_.new_u8(amp_mgr.Decode_as_bry(Bry_.new_u8(raw))));
}
}

View File

@@ -0,0 +1,42 @@
/*
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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public class Xop_amp_mgr_rslt {
public Xop_amp_mgr_rslt(int pos, int val, Xop_tkn_itm tkn) {
this.pos = pos;
this.val = val;
this.tkn = tkn;
}
public Xop_amp_mgr_rslt() {}
public boolean Pass() {return pass;} private boolean pass; public void Valid_(boolean v) {this.pass = v;}
public int Pos() {return pos;} private int pos; public void Pos_(int v) {this.pos = v;}
public int Val() {return val;} private int val; public void Val_(int v) {this.val = v;}
public Xop_tkn_itm Tkn() {return tkn;} private Xop_tkn_itm tkn; public void Tkn_(Xop_tkn_itm v) {this.tkn = v;}
public boolean Pass_y_(int pos, int val) {
this.pos = pos; this.val = val;
this.pass = true;
return true;
}
public boolean Pass_n_(int pos) {
this.pass = false;
this.pos = pos;
this.val = -1;
this.tkn = null;
return false;
}
}

View File

@@ -16,9 +16,9 @@ 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.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public class Xop_amp_tkn_txt extends Xop_tkn_itm_base {
public class Xop_amp_tkn_ent extends Xop_tkn_itm_base {
private Xop_amp_trie_itm html_ref_itm;
public Xop_amp_tkn_txt(int bgn, int end, Xop_amp_trie_itm html_ref_itm) {
public Xop_amp_tkn_ent(int bgn, int end, Xop_amp_trie_itm html_ref_itm) {
this.html_ref_itm = html_ref_itm;
this.Tkn_ini_pos(false, bgn, end);
}

View File

@@ -17,301 +17,300 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*;
public class Xop_amp_trie {
public static final byte[] // NOTE: top_define
Bry_xowa_lt = Bry_.new_a7("&xowa_lt;")
, Bry_xowa_brack_bgn = Bry_.new_a7("&xowa_brack_bgn;")
, Bry_xowa_brack_end = Bry_.new_a7("&xowa_brack_end;")
, Bry_xowa_pipe = Bry_.new_a7("&xowa_pipe;")
, Bry_xowa_apos = Bry_.new_a7("&xowa_apos;")
, Bry_xowa_colon = Bry_.new_a7("&xowa_colon;")
, Bry_xowa_underline = Bry_.new_a7("&xowa_underline;")
, Bry_xowa_asterisk = Bry_.new_a7("&xowa_asterisk;")
, Bry_xowa_space = Bry_.new_a7("&xowa_space;")
, Bry_xowa_nl = Bry_.new_a7("&xowa_nl;")
, Bry_xowa_dash = Bry_.new_a7("&xowa_dash;")
public class Xop_amp_trie { // TS
public static final String // NOTE: top_define; entities needed for <nowiki> escaping
Str__xowa_lt = "&xowa_lt;"
, Str__xowa_brack_bgn = "&xowa_brack_bgn;"
, Str__xowa_brack_end = "&xowa_brack_end;"
, Str__xowa_pipe = "&xowa_pipe;"
, Str__xowa_apos = "&xowa_apos;"
, Str__xowa_colon = "&xowa_colon;"
, Str__xowa_underline = "&xowa_underline;"
, Str__xowa_asterisk = "&xowa_asterisk;"
, Str__xowa_space = "&xowa_space;"
, Str__xowa_nl = "&xowa_nl;"
, Str__xowa_dash = "&xowa_dash;"
;
public static final Btrie_slim_mgr Instance = new_(); Xop_amp_trie() {}
private static Btrie_slim_mgr new_() {// REF.MW: Sanitizer|$wgHtmlEntities; NOTE:added apos
public static final Btrie_slim_mgr Instance = New(); Xop_amp_trie() {}
private static Btrie_slim_mgr New() {// REF.MW: Sanitizer|$wgHtmlEntities; NOTE:added apos
Btrie_slim_mgr rv = Btrie_slim_mgr.cs();
Reg_name(rv, Bool_.Y, 60, Bry_xowa_lt);
Reg_name(rv, Bool_.Y, 91, Bry_xowa_brack_bgn);
Reg_name(rv, Bool_.Y, 93, Bry_xowa_brack_end);
Reg_name(rv, Bool_.Y, 124, Bry_xowa_pipe);
Reg_name(rv, Bool_.Y, 39, Bry_xowa_apos);
Reg_name(rv, Bool_.Y, 58, Bry_xowa_colon);
Reg_name(rv, Bool_.Y, 95, Bry_xowa_underline);
Reg_name(rv, Bool_.Y, 42, Bry_xowa_asterisk);
Reg_name(rv, Bool_.Y, 32, Bry_xowa_space);
Reg_name(rv, Bool_.Y, 10, Bry_xowa_nl);
Reg_name(rv, Bool_.Y, 45, Bry_xowa_dash);
Reg_name(rv, Bool_.N, 39, "&apos;");
Reg_name(rv, Bool_.N, 193, "&Aacute;");
Reg_name(rv, Bool_.N, 225, "&aacute;");
Reg_name(rv, Bool_.N, 194, "&Acirc;");
Reg_name(rv, Bool_.N, 226, "&acirc;");
Reg_name(rv, Bool_.N, 180, "&acute;");
Reg_name(rv, Bool_.N, 198, "&AElig;");
Reg_name(rv, Bool_.N, 230, "&aelig;");
Reg_name(rv, Bool_.N, 192, "&Agrave;");
Reg_name(rv, Bool_.N, 224, "&agrave;");
Reg_name(rv, Bool_.N, 8501, "&alefsym;");
Reg_name(rv, Bool_.N, 913, "&Alpha;");
Reg_name(rv, Bool_.N, 945, "&alpha;");
Reg_name(rv, Bool_.N, 38, "&amp;");
Reg_name(rv, Bool_.N, 8743, "&and;");
Reg_name(rv, Bool_.N, 8736, "&ang;");
Reg_name(rv, Bool_.N, 197, "&Aring;");
Reg_name(rv, Bool_.N, 229, "&aring;");
Reg_name(rv, Bool_.N, 8776, "&asymp;");
Reg_name(rv, Bool_.N, 195, "&Atilde;");
Reg_name(rv, Bool_.N, 227, "&atilde;");
Reg_name(rv, Bool_.N, 196, "&Auml;");
Reg_name(rv, Bool_.N, 228, "&auml;");
Reg_name(rv, Bool_.N, 8222, "&bdquo;");
Reg_name(rv, Bool_.N, 914, "&Beta;");
Reg_name(rv, Bool_.N, 946, "&beta;");
Reg_name(rv, Bool_.N, 166, "&brvbar;");
Reg_name(rv, Bool_.N, 8226, "&bull;");
Reg_name(rv, Bool_.N, 8745, "&cap;");
Reg_name(rv, Bool_.N, 199, "&Ccedil;");
Reg_name(rv, Bool_.N, 231, "&ccedil;");
Reg_name(rv, Bool_.N, 184, "&cedil;");
Reg_name(rv, Bool_.N, 162, "&cent;");
Reg_name(rv, Bool_.N, 935, "&Chi;");
Reg_name(rv, Bool_.N, 967, "&chi;");
Reg_name(rv, Bool_.N, 710, "&circ;");
Reg_name(rv, Bool_.N, 9827, "&clubs;");
Reg_name(rv, Bool_.N, 8773, "&cong;");
Reg_name(rv, Bool_.N, 169, "&copy;");
Reg_name(rv, Bool_.N, 8629, "&crarr;");
Reg_name(rv, Bool_.N, 8746, "&cup;");
Reg_name(rv, Bool_.N, 164, "&curren;");
Reg_name(rv, Bool_.N, 8224, "&dagger;");
Reg_name(rv, Bool_.N, 8225, "&Dagger;");
Reg_name(rv, Bool_.N, 8595, "&darr;");
Reg_name(rv, Bool_.N, 8659, "&dArr;");
Reg_name(rv, Bool_.N, 176, "&deg;");
Reg_name(rv, Bool_.N, 916, "&Delta;");
Reg_name(rv, Bool_.N, 948, "&delta;");
Reg_name(rv, Bool_.N, 9830, "&diams;");
Reg_name(rv, Bool_.N, 247, "&divide;");
Reg_name(rv, Bool_.N, 201, "&Eacute;");
Reg_name(rv, Bool_.N, 233, "&eacute;");
Reg_name(rv, Bool_.N, 202, "&Ecirc;");
Reg_name(rv, Bool_.N, 234, "&ecirc;");
Reg_name(rv, Bool_.N, 200, "&Egrave;");
Reg_name(rv, Bool_.N, 232, "&egrave;");
Reg_name(rv, Bool_.N, 8709, "&empty;");
Reg_name(rv, Bool_.N, 8195, "&emsp;");
Reg_name(rv, Bool_.N, 8194, "&ensp;");
Reg_name(rv, Bool_.N, 917, "&Epsilon;");
Reg_name(rv, Bool_.N, 949, "&epsilon;");
Reg_name(rv, Bool_.N, 8801, "&equiv;");
Reg_name(rv, Bool_.N, 919, "&Eta;");
Reg_name(rv, Bool_.N, 951, "&eta;");
Reg_name(rv, Bool_.N, 208, "&ETH;");
Reg_name(rv, Bool_.N, 240, "&eth;");
Reg_name(rv, Bool_.N, 203, "&Euml;");
Reg_name(rv, Bool_.N, 235, "&euml;");
Reg_name(rv, Bool_.N, 8364, "&euro;");
Reg_name(rv, Bool_.N, 8707, "&exist;");
Reg_name(rv, Bool_.N, 402, "&fnof;");
Reg_name(rv, Bool_.N, 8704, "&forall;");
Reg_name(rv, Bool_.N, 189, "&frac12;");
Reg_name(rv, Bool_.N, 188, "&frac14;");
Reg_name(rv, Bool_.N, 190, "&frac34;");
Reg_name(rv, Bool_.N, 8260, "&frasl;");
Reg_name(rv, Bool_.N, 915, "&Gamma;");
Reg_name(rv, Bool_.N, 947, "&gamma;");
Reg_name(rv, Bool_.N, 8805, "&ge;");
Reg_name(rv, Bool_.N, 62, "&gt;");
Reg_name(rv, Bool_.N, 8596, "&harr;");
Reg_name(rv, Bool_.N, 8660, "&hArr;");
Reg_name(rv, Bool_.N, 9829, "&hearts;");
Reg_name(rv, Bool_.N, 8230, "&hellip;");
Reg_name(rv, Bool_.N, 205, "&Iacute;");
Reg_name(rv, Bool_.N, 237, "&iacute;");
Reg_name(rv, Bool_.N, 206, "&Icirc;");
Reg_name(rv, Bool_.N, 238, "&icirc;");
Reg_name(rv, Bool_.N, 161, "&iexcl;");
Reg_name(rv, Bool_.N, 204, "&Igrave;");
Reg_name(rv, Bool_.N, 236, "&igrave;");
Reg_name(rv, Bool_.N, 8465, "&image;");
Reg_name(rv, Bool_.N, 8734, "&infin;");
Reg_name(rv, Bool_.N, 8747, "&int;");
Reg_name(rv, Bool_.N, 921, "&Iota;");
Reg_name(rv, Bool_.N, 953, "&iota;");
Reg_name(rv, Bool_.N, 191, "&iquest;");
Reg_name(rv, Bool_.N, 8712, "&isin;");
Reg_name(rv, Bool_.N, 207, "&Iuml;");
Reg_name(rv, Bool_.N, 239, "&iuml;");
Reg_name(rv, Bool_.N, 922, "&Kappa;");
Reg_name(rv, Bool_.N, 954, "&kappa;");
Reg_name(rv, Bool_.N, 923, "&Lambda;");
Reg_name(rv, Bool_.N, 955, "&lambda;");
Reg_name(rv, Bool_.N, 9001, "&lang;");
Reg_name(rv, Bool_.N, 171, "&laquo;");
Reg_name(rv, Bool_.N, 8592, "&larr;");
Reg_name(rv, Bool_.N, 8656, "&lArr;");
Reg_name(rv, Bool_.N, 8968, "&lceil;");
Reg_name(rv, Bool_.N, 8220, "&ldquo;");
Reg_name(rv, Bool_.N, 8804, "&le;");
Reg_name(rv, Bool_.N, 8970, "&lfloor;");
Reg_name(rv, Bool_.N, 8727, "&lowast;");
Reg_name(rv, Bool_.N, 9674, "&loz;");
Reg_name(rv, Bool_.N, 8206, "&lrm;");
Reg_name(rv, Bool_.N, 8249, "&lsaquo;");
Reg_name(rv, Bool_.N, 8216, "&lsquo;");
Reg_name(rv, Bool_.N, 60, "&lt;");
Reg_name(rv, Bool_.N, 175, "&macr;");
Reg_name(rv, Bool_.N, 8212, "&mdash;");
Reg_name(rv, Bool_.N, 181, "&micro;");
Reg_name(rv, Bool_.N, 183, "&middot;");
Reg_name(rv, Bool_.N, 8722, "&minus;");
Reg_name(rv, Bool_.N, 924, "&Mu;");
Reg_name(rv, Bool_.N, 956, "&mu;");
Reg_name(rv, Bool_.N, 8711, "&nabla;");
Reg_name(rv, Bool_.N, 160, "&nbsp;");
Reg_name(rv, Bool_.N, 8211, "&ndash;");
Reg_name(rv, Bool_.N, 8800, "&ne;");
Reg_name(rv, Bool_.N, 8715, "&ni;");
Reg_name(rv, Bool_.N, 172, "&not;");
Reg_name(rv, Bool_.N, 8713, "&notin;");
Reg_name(rv, Bool_.N, 8836, "&nsub;");
Reg_name(rv, Bool_.N, 209, "&Ntilde;");
Reg_name(rv, Bool_.N, 241, "&ntilde;");
Reg_name(rv, Bool_.N, 925, "&Nu;");
Reg_name(rv, Bool_.N, 957, "&nu;");
Reg_name(rv, Bool_.N, 211, "&Oacute;");
Reg_name(rv, Bool_.N, 243, "&oacute;");
Reg_name(rv, Bool_.N, 212, "&Ocirc;");
Reg_name(rv, Bool_.N, 244, "&ocirc;");
Reg_name(rv, Bool_.N, 338, "&OElig;");
Reg_name(rv, Bool_.N, 339, "&oelig;");
Reg_name(rv, Bool_.N, 210, "&Ograve;");
Reg_name(rv, Bool_.N, 242, "&ograve;");
Reg_name(rv, Bool_.N, 8254, "&oline;");
Reg_name(rv, Bool_.N, 937, "&Omega;");
Reg_name(rv, Bool_.N, 969, "&omega;");
Reg_name(rv, Bool_.N, 927, "&Omicron;");
Reg_name(rv, Bool_.N, 959, "&omicron;");
Reg_name(rv, Bool_.N, 8853, "&oplus;");
Reg_name(rv, Bool_.N, 8744, "&or;");
Reg_name(rv, Bool_.N, 170, "&ordf;");
Reg_name(rv, Bool_.N, 186, "&ordm;");
Reg_name(rv, Bool_.N, 216, "&Oslash;");
Reg_name(rv, Bool_.N, 248, "&oslash;");
Reg_name(rv, Bool_.N, 213, "&Otilde;");
Reg_name(rv, Bool_.N, 245, "&otilde;");
Reg_name(rv, Bool_.N, 8855, "&otimes;");
Reg_name(rv, Bool_.N, 214, "&Ouml;");
Reg_name(rv, Bool_.N, 246, "&ouml;");
Reg_name(rv, Bool_.N, 182, "&para;");
Reg_name(rv, Bool_.N, 8706, "&part;");
Reg_name(rv, Bool_.N, 8240, "&permil;");
Reg_name(rv, Bool_.N, 8869, "&perp;");
Reg_name(rv, Bool_.N, 934, "&Phi;");
Reg_name(rv, Bool_.N, 966, "&phi;");
Reg_name(rv, Bool_.N, 928, "&Pi;");
Reg_name(rv, Bool_.N, 960, "&pi;");
Reg_name(rv, Bool_.N, 982, "&piv;");
Reg_name(rv, Bool_.N, 177, "&plusmn;");
Reg_name(rv, Bool_.N, 163, "&pound;");
Reg_name(rv, Bool_.N, 8242, "&prime;");
Reg_name(rv, Bool_.N, 8243, "&Prime;");
Reg_name(rv, Bool_.N, 8719, "&prod;");
Reg_name(rv, Bool_.N, 8733, "&prop;");
Reg_name(rv, Bool_.N, 936, "&Psi;");
Reg_name(rv, Bool_.N, 968, "&psi;");
Reg_name(rv, Bool_.N, 34, "&quot;");
Reg_name(rv, Bool_.N, 8730, "&radic;");
Reg_name(rv, Bool_.N, 9002, "&rang;");
Reg_name(rv, Bool_.N, 187, "&raquo;");
Reg_name(rv, Bool_.N, 8594, "&rarr;");
Reg_name(rv, Bool_.N, 8658, "&rArr;");
Reg_name(rv, Bool_.N, 8969, "&rceil;");
Reg_name(rv, Bool_.N, 8221, "&rdquo;");
Reg_name(rv, Bool_.N, 8476, "&real;");
Reg_name(rv, Bool_.N, 174, "&reg;");
Reg_name(rv, Bool_.N, 8971, "&rfloor;");
Reg_name(rv, Bool_.N, 929, "&Rho;");
Reg_name(rv, Bool_.N, 961, "&rho;");
Reg_name(rv, Bool_.N, 8207, "&rlm;");
Reg_name(rv, Bool_.N, 8250, "&rsaquo;");
Reg_name(rv, Bool_.N, 8217, "&rsquo;");
Reg_name(rv, Bool_.N, 8218, "&sbquo;");
Reg_name(rv, Bool_.N, 352, "&Scaron;");
Reg_name(rv, Bool_.N, 353, "&scaron;");
Reg_name(rv, Bool_.N, 8901, "&sdot;");
Reg_name(rv, Bool_.N, 167, "&sect;");
Reg_name(rv, Bool_.N, 173, "&shy;");
Reg_name(rv, Bool_.N, 931, "&Sigma;");
Reg_name(rv, Bool_.N, 963, "&sigma;");
Reg_name(rv, Bool_.N, 962, "&sigmaf;");
Reg_name(rv, Bool_.N, 8764, "&sim;");
Reg_name(rv, Bool_.N, 9824, "&spades;");
Reg_name(rv, Bool_.N, 8834, "&sub;");
Reg_name(rv, Bool_.N, 8838, "&sube;");
Reg_name(rv, Bool_.N, 8721, "&sum;");
Reg_name(rv, Bool_.N, 8835, "&sup;");
Reg_name(rv, Bool_.N, 185, "&sup1;");
Reg_name(rv, Bool_.N, 178, "&sup2;");
Reg_name(rv, Bool_.N, 179, "&sup3;");
Reg_name(rv, Bool_.N, 8839, "&supe;");
Reg_name(rv, Bool_.N, 223, "&szlig;");
Reg_name(rv, Bool_.N, 932, "&Tau;");
Reg_name(rv, Bool_.N, 964, "&tau;");
Reg_name(rv, Bool_.N, 8756, "&there4;");
Reg_name(rv, Bool_.N, 920, "&Theta;");
Reg_name(rv, Bool_.N, 952, "&theta;");
Reg_name(rv, Bool_.N, 977, "&thetasym;");
Reg_name(rv, Bool_.N, 8201, "&thinsp;");
Reg_name(rv, Bool_.N, 222, "&THORN;");
Reg_name(rv, Bool_.N, 254, "&thorn;");
Reg_name(rv, Bool_.N, 732, "&tilde;");
Reg_name(rv, Bool_.N, 215, "&times;");
Reg_name(rv, Bool_.N, 8482, "&trade;");
Reg_name(rv, Bool_.N, 218, "&Uacute;");
Reg_name(rv, Bool_.N, 250, "&uacute;");
Reg_name(rv, Bool_.N, 8593, "&uarr;");
Reg_name(rv, Bool_.N, 8657, "&uArr;");
Reg_name(rv, Bool_.N, 219, "&Ucirc;");
Reg_name(rv, Bool_.N, 251, "&ucirc;");
Reg_name(rv, Bool_.N, 217, "&Ugrave;");
Reg_name(rv, Bool_.N, 249, "&ugrave;");
Reg_name(rv, Bool_.N, 168, "&uml;");
Reg_name(rv, Bool_.N, 978, "&upsih;");
Reg_name(rv, Bool_.N, 933, "&Upsilon;");
Reg_name(rv, Bool_.N, 965, "&upsilon;");
Reg_name(rv, Bool_.N, 220, "&Uuml;");
Reg_name(rv, Bool_.N, 252, "&uuml;");
Reg_name(rv, Bool_.N, 8472, "&weierp;");
Reg_name(rv, Bool_.N, 926, "&Xi;");
Reg_name(rv, Bool_.N, 958, "&xi;");
Reg_name(rv, Bool_.N, 221, "&Yacute;");
Reg_name(rv, Bool_.N, 253, "&yacute;");
Reg_name(rv, Bool_.N, 165, "&yen;");
Reg_name(rv, Bool_.N, 376, "&Yuml;");
Reg_name(rv, Bool_.N, 255, "&yuml;");
Reg_name(rv, Bool_.N, 918, "&Zeta;");
Reg_name(rv, Bool_.N, 950, "&zeta;");
Reg_name(rv, Bool_.N, 8205, "&zwj;");
Reg_name(rv, Bool_.N, 8204, "&zwnj;");
Reg_prefix(rv, Xop_amp_trie_itm.Tid_num_hex, "#x");
Reg_prefix(rv, Xop_amp_trie_itm.Tid_num_hex, "#X");
Reg_prefix(rv, Xop_amp_trie_itm.Tid_num_dec, "#");
Add_name(rv, Bool_.Y, 60, Str__xowa_lt);
Add_name(rv, Bool_.Y, 91, Str__xowa_brack_bgn);
Add_name(rv, Bool_.Y, 93, Str__xowa_brack_end);
Add_name(rv, Bool_.Y, 124, Str__xowa_pipe);
Add_name(rv, Bool_.Y, 39, Str__xowa_apos);
Add_name(rv, Bool_.Y, 58, Str__xowa_colon);
Add_name(rv, Bool_.Y, 95, Str__xowa_underline);
Add_name(rv, Bool_.Y, 42, Str__xowa_asterisk);
Add_name(rv, Bool_.Y, 32, Str__xowa_space);
Add_name(rv, Bool_.Y, 10, Str__xowa_nl);
Add_name(rv, Bool_.Y, 45, Str__xowa_dash);
Add_name(rv, Bool_.N, 39, "&apos;");
Add_name(rv, Bool_.N, 193, "&Aacute;");
Add_name(rv, Bool_.N, 225, "&aacute;");
Add_name(rv, Bool_.N, 194, "&Acirc;");
Add_name(rv, Bool_.N, 226, "&acirc;");
Add_name(rv, Bool_.N, 180, "&acute;");
Add_name(rv, Bool_.N, 198, "&AElig;");
Add_name(rv, Bool_.N, 230, "&aelig;");
Add_name(rv, Bool_.N, 192, "&Agrave;");
Add_name(rv, Bool_.N, 224, "&agrave;");
Add_name(rv, Bool_.N, 8501, "&alefsym;");
Add_name(rv, Bool_.N, 913, "&Alpha;");
Add_name(rv, Bool_.N, 945, "&alpha;");
Add_name(rv, Bool_.N, 38, "&amp;");
Add_name(rv, Bool_.N, 8743, "&and;");
Add_name(rv, Bool_.N, 8736, "&ang;");
Add_name(rv, Bool_.N, 197, "&Aring;");
Add_name(rv, Bool_.N, 229, "&aring;");
Add_name(rv, Bool_.N, 8776, "&asymp;");
Add_name(rv, Bool_.N, 195, "&Atilde;");
Add_name(rv, Bool_.N, 227, "&atilde;");
Add_name(rv, Bool_.N, 196, "&Auml;");
Add_name(rv, Bool_.N, 228, "&auml;");
Add_name(rv, Bool_.N, 8222, "&bdquo;");
Add_name(rv, Bool_.N, 914, "&Beta;");
Add_name(rv, Bool_.N, 946, "&beta;");
Add_name(rv, Bool_.N, 166, "&brvbar;");
Add_name(rv, Bool_.N, 8226, "&bull;");
Add_name(rv, Bool_.N, 8745, "&cap;");
Add_name(rv, Bool_.N, 199, "&Ccedil;");
Add_name(rv, Bool_.N, 231, "&ccedil;");
Add_name(rv, Bool_.N, 184, "&cedil;");
Add_name(rv, Bool_.N, 162, "&cent;");
Add_name(rv, Bool_.N, 935, "&Chi;");
Add_name(rv, Bool_.N, 967, "&chi;");
Add_name(rv, Bool_.N, 710, "&circ;");
Add_name(rv, Bool_.N, 9827, "&clubs;");
Add_name(rv, Bool_.N, 8773, "&cong;");
Add_name(rv, Bool_.N, 169, "&copy;");
Add_name(rv, Bool_.N, 8629, "&crarr;");
Add_name(rv, Bool_.N, 8746, "&cup;");
Add_name(rv, Bool_.N, 164, "&curren;");
Add_name(rv, Bool_.N, 8224, "&dagger;");
Add_name(rv, Bool_.N, 8225, "&Dagger;");
Add_name(rv, Bool_.N, 8595, "&darr;");
Add_name(rv, Bool_.N, 8659, "&dArr;");
Add_name(rv, Bool_.N, 176, "&deg;");
Add_name(rv, Bool_.N, 916, "&Delta;");
Add_name(rv, Bool_.N, 948, "&delta;");
Add_name(rv, Bool_.N, 9830, "&diams;");
Add_name(rv, Bool_.N, 247, "&divide;");
Add_name(rv, Bool_.N, 201, "&Eacute;");
Add_name(rv, Bool_.N, 233, "&eacute;");
Add_name(rv, Bool_.N, 202, "&Ecirc;");
Add_name(rv, Bool_.N, 234, "&ecirc;");
Add_name(rv, Bool_.N, 200, "&Egrave;");
Add_name(rv, Bool_.N, 232, "&egrave;");
Add_name(rv, Bool_.N, 8709, "&empty;");
Add_name(rv, Bool_.N, 8195, "&emsp;");
Add_name(rv, Bool_.N, 8194, "&ensp;");
Add_name(rv, Bool_.N, 917, "&Epsilon;");
Add_name(rv, Bool_.N, 949, "&epsilon;");
Add_name(rv, Bool_.N, 8801, "&equiv;");
Add_name(rv, Bool_.N, 919, "&Eta;");
Add_name(rv, Bool_.N, 951, "&eta;");
Add_name(rv, Bool_.N, 208, "&ETH;");
Add_name(rv, Bool_.N, 240, "&eth;");
Add_name(rv, Bool_.N, 203, "&Euml;");
Add_name(rv, Bool_.N, 235, "&euml;");
Add_name(rv, Bool_.N, 8364, "&euro;");
Add_name(rv, Bool_.N, 8707, "&exist;");
Add_name(rv, Bool_.N, 402, "&fnof;");
Add_name(rv, Bool_.N, 8704, "&forall;");
Add_name(rv, Bool_.N, 189, "&frac12;");
Add_name(rv, Bool_.N, 188, "&frac14;");
Add_name(rv, Bool_.N, 190, "&frac34;");
Add_name(rv, Bool_.N, 8260, "&frasl;");
Add_name(rv, Bool_.N, 915, "&Gamma;");
Add_name(rv, Bool_.N, 947, "&gamma;");
Add_name(rv, Bool_.N, 8805, "&ge;");
Add_name(rv, Bool_.N, 62, "&gt;");
Add_name(rv, Bool_.N, 8596, "&harr;");
Add_name(rv, Bool_.N, 8660, "&hArr;");
Add_name(rv, Bool_.N, 9829, "&hearts;");
Add_name(rv, Bool_.N, 8230, "&hellip;");
Add_name(rv, Bool_.N, 205, "&Iacute;");
Add_name(rv, Bool_.N, 237, "&iacute;");
Add_name(rv, Bool_.N, 206, "&Icirc;");
Add_name(rv, Bool_.N, 238, "&icirc;");
Add_name(rv, Bool_.N, 161, "&iexcl;");
Add_name(rv, Bool_.N, 204, "&Igrave;");
Add_name(rv, Bool_.N, 236, "&igrave;");
Add_name(rv, Bool_.N, 8465, "&image;");
Add_name(rv, Bool_.N, 8734, "&infin;");
Add_name(rv, Bool_.N, 8747, "&int;");
Add_name(rv, Bool_.N, 921, "&Iota;");
Add_name(rv, Bool_.N, 953, "&iota;");
Add_name(rv, Bool_.N, 191, "&iquest;");
Add_name(rv, Bool_.N, 8712, "&isin;");
Add_name(rv, Bool_.N, 207, "&Iuml;");
Add_name(rv, Bool_.N, 239, "&iuml;");
Add_name(rv, Bool_.N, 922, "&Kappa;");
Add_name(rv, Bool_.N, 954, "&kappa;");
Add_name(rv, Bool_.N, 923, "&Lambda;");
Add_name(rv, Bool_.N, 955, "&lambda;");
Add_name(rv, Bool_.N, 9001, "&lang;");
Add_name(rv, Bool_.N, 171, "&laquo;");
Add_name(rv, Bool_.N, 8592, "&larr;");
Add_name(rv, Bool_.N, 8656, "&lArr;");
Add_name(rv, Bool_.N, 8968, "&lceil;");
Add_name(rv, Bool_.N, 8220, "&ldquo;");
Add_name(rv, Bool_.N, 8804, "&le;");
Add_name(rv, Bool_.N, 8970, "&lfloor;");
Add_name(rv, Bool_.N, 8727, "&lowast;");
Add_name(rv, Bool_.N, 9674, "&loz;");
Add_name(rv, Bool_.N, 8206, "&lrm;");
Add_name(rv, Bool_.N, 8249, "&lsaquo;");
Add_name(rv, Bool_.N, 8216, "&lsquo;");
Add_name(rv, Bool_.N, 60, "&lt;");
Add_name(rv, Bool_.N, 175, "&macr;");
Add_name(rv, Bool_.N, 8212, "&mdash;");
Add_name(rv, Bool_.N, 181, "&micro;");
Add_name(rv, Bool_.N, 183, "&middot;");
Add_name(rv, Bool_.N, 8722, "&minus;");
Add_name(rv, Bool_.N, 924, "&Mu;");
Add_name(rv, Bool_.N, 956, "&mu;");
Add_name(rv, Bool_.N, 8711, "&nabla;");
Add_name(rv, Bool_.N, 160, "&nbsp;");
Add_name(rv, Bool_.N, 8211, "&ndash;");
Add_name(rv, Bool_.N, 8800, "&ne;");
Add_name(rv, Bool_.N, 8715, "&ni;");
Add_name(rv, Bool_.N, 172, "&not;");
Add_name(rv, Bool_.N, 8713, "&notin;");
Add_name(rv, Bool_.N, 8836, "&nsub;");
Add_name(rv, Bool_.N, 209, "&Ntilde;");
Add_name(rv, Bool_.N, 241, "&ntilde;");
Add_name(rv, Bool_.N, 925, "&Nu;");
Add_name(rv, Bool_.N, 957, "&nu;");
Add_name(rv, Bool_.N, 211, "&Oacute;");
Add_name(rv, Bool_.N, 243, "&oacute;");
Add_name(rv, Bool_.N, 212, "&Ocirc;");
Add_name(rv, Bool_.N, 244, "&ocirc;");
Add_name(rv, Bool_.N, 338, "&OElig;");
Add_name(rv, Bool_.N, 339, "&oelig;");
Add_name(rv, Bool_.N, 210, "&Ograve;");
Add_name(rv, Bool_.N, 242, "&ograve;");
Add_name(rv, Bool_.N, 8254, "&oline;");
Add_name(rv, Bool_.N, 937, "&Omega;");
Add_name(rv, Bool_.N, 969, "&omega;");
Add_name(rv, Bool_.N, 927, "&Omicron;");
Add_name(rv, Bool_.N, 959, "&omicron;");
Add_name(rv, Bool_.N, 8853, "&oplus;");
Add_name(rv, Bool_.N, 8744, "&or;");
Add_name(rv, Bool_.N, 170, "&ordf;");
Add_name(rv, Bool_.N, 186, "&ordm;");
Add_name(rv, Bool_.N, 216, "&Oslash;");
Add_name(rv, Bool_.N, 248, "&oslash;");
Add_name(rv, Bool_.N, 213, "&Otilde;");
Add_name(rv, Bool_.N, 245, "&otilde;");
Add_name(rv, Bool_.N, 8855, "&otimes;");
Add_name(rv, Bool_.N, 214, "&Ouml;");
Add_name(rv, Bool_.N, 246, "&ouml;");
Add_name(rv, Bool_.N, 182, "&para;");
Add_name(rv, Bool_.N, 8706, "&part;");
Add_name(rv, Bool_.N, 8240, "&permil;");
Add_name(rv, Bool_.N, 8869, "&perp;");
Add_name(rv, Bool_.N, 934, "&Phi;");
Add_name(rv, Bool_.N, 966, "&phi;");
Add_name(rv, Bool_.N, 928, "&Pi;");
Add_name(rv, Bool_.N, 960, "&pi;");
Add_name(rv, Bool_.N, 982, "&piv;");
Add_name(rv, Bool_.N, 177, "&plusmn;");
Add_name(rv, Bool_.N, 163, "&pound;");
Add_name(rv, Bool_.N, 8242, "&prime;");
Add_name(rv, Bool_.N, 8243, "&Prime;");
Add_name(rv, Bool_.N, 8719, "&prod;");
Add_name(rv, Bool_.N, 8733, "&prop;");
Add_name(rv, Bool_.N, 936, "&Psi;");
Add_name(rv, Bool_.N, 968, "&psi;");
Add_name(rv, Bool_.N, 34, "&quot;");
Add_name(rv, Bool_.N, 8730, "&radic;");
Add_name(rv, Bool_.N, 9002, "&rang;");
Add_name(rv, Bool_.N, 187, "&raquo;");
Add_name(rv, Bool_.N, 8594, "&rarr;");
Add_name(rv, Bool_.N, 8658, "&rArr;");
Add_name(rv, Bool_.N, 8969, "&rceil;");
Add_name(rv, Bool_.N, 8221, "&rdquo;");
Add_name(rv, Bool_.N, 8476, "&real;");
Add_name(rv, Bool_.N, 174, "&reg;");
Add_name(rv, Bool_.N, 8971, "&rfloor;");
Add_name(rv, Bool_.N, 929, "&Rho;");
Add_name(rv, Bool_.N, 961, "&rho;");
Add_name(rv, Bool_.N, 8207, "&rlm;");
Add_name(rv, Bool_.N, 8250, "&rsaquo;");
Add_name(rv, Bool_.N, 8217, "&rsquo;");
Add_name(rv, Bool_.N, 8218, "&sbquo;");
Add_name(rv, Bool_.N, 352, "&Scaron;");
Add_name(rv, Bool_.N, 353, "&scaron;");
Add_name(rv, Bool_.N, 8901, "&sdot;");
Add_name(rv, Bool_.N, 167, "&sect;");
Add_name(rv, Bool_.N, 173, "&shy;");
Add_name(rv, Bool_.N, 931, "&Sigma;");
Add_name(rv, Bool_.N, 963, "&sigma;");
Add_name(rv, Bool_.N, 962, "&sigmaf;");
Add_name(rv, Bool_.N, 8764, "&sim;");
Add_name(rv, Bool_.N, 9824, "&spades;");
Add_name(rv, Bool_.N, 8834, "&sub;");
Add_name(rv, Bool_.N, 8838, "&sube;");
Add_name(rv, Bool_.N, 8721, "&sum;");
Add_name(rv, Bool_.N, 8835, "&sup;");
Add_name(rv, Bool_.N, 185, "&sup1;");
Add_name(rv, Bool_.N, 178, "&sup2;");
Add_name(rv, Bool_.N, 179, "&sup3;");
Add_name(rv, Bool_.N, 8839, "&supe;");
Add_name(rv, Bool_.N, 223, "&szlig;");
Add_name(rv, Bool_.N, 932, "&Tau;");
Add_name(rv, Bool_.N, 964, "&tau;");
Add_name(rv, Bool_.N, 8756, "&there4;");
Add_name(rv, Bool_.N, 920, "&Theta;");
Add_name(rv, Bool_.N, 952, "&theta;");
Add_name(rv, Bool_.N, 977, "&thetasym;");
Add_name(rv, Bool_.N, 8201, "&thinsp;");
Add_name(rv, Bool_.N, 222, "&THORN;");
Add_name(rv, Bool_.N, 254, "&thorn;");
Add_name(rv, Bool_.N, 732, "&tilde;");
Add_name(rv, Bool_.N, 215, "&times;");
Add_name(rv, Bool_.N, 8482, "&trade;");
Add_name(rv, Bool_.N, 218, "&Uacute;");
Add_name(rv, Bool_.N, 250, "&uacute;");
Add_name(rv, Bool_.N, 8593, "&uarr;");
Add_name(rv, Bool_.N, 8657, "&uArr;");
Add_name(rv, Bool_.N, 219, "&Ucirc;");
Add_name(rv, Bool_.N, 251, "&ucirc;");
Add_name(rv, Bool_.N, 217, "&Ugrave;");
Add_name(rv, Bool_.N, 249, "&ugrave;");
Add_name(rv, Bool_.N, 168, "&uml;");
Add_name(rv, Bool_.N, 978, "&upsih;");
Add_name(rv, Bool_.N, 933, "&Upsilon;");
Add_name(rv, Bool_.N, 965, "&upsilon;");
Add_name(rv, Bool_.N, 220, "&Uuml;");
Add_name(rv, Bool_.N, 252, "&uuml;");
Add_name(rv, Bool_.N, 8472, "&weierp;");
Add_name(rv, Bool_.N, 926, "&Xi;");
Add_name(rv, Bool_.N, 958, "&xi;");
Add_name(rv, Bool_.N, 221, "&Yacute;");
Add_name(rv, Bool_.N, 253, "&yacute;");
Add_name(rv, Bool_.N, 165, "&yen;");
Add_name(rv, Bool_.N, 376, "&Yuml;");
Add_name(rv, Bool_.N, 255, "&yuml;");
Add_name(rv, Bool_.N, 918, "&Zeta;");
Add_name(rv, Bool_.N, 950, "&zeta;");
Add_name(rv, Bool_.N, 8205, "&zwj;");
Add_name(rv, Bool_.N, 8204, "&zwnj;");
Add_prefix(rv, Xop_amp_trie_itm.Tid_num_hex, "#x");
Add_prefix(rv, Xop_amp_trie_itm.Tid_num_hex, "#X");
Add_prefix(rv, Xop_amp_trie_itm.Tid_num_dec, "#");
return rv;
}
private static void Reg_name(Btrie_slim_mgr trie, boolean tid_is_xowa, int char_int, String xml_name_str) {Reg_name(trie, tid_is_xowa, char_int, Bry_.new_a7(xml_name_str));}
private static void Reg_name(Btrie_slim_mgr trie, boolean tid_is_xowa, int char_int, byte[] xml_name_bry) {
private static void Add_name(Btrie_slim_mgr trie, boolean tid_is_xowa, int char_int, String xml_name_str) {
byte itm_tid = tid_is_xowa ? Xop_amp_trie_itm.Tid_name_xowa : Xop_amp_trie_itm.Tid_name_std;
Xop_amp_trie_itm itm = new Xop_amp_trie_itm(itm_tid, char_int, xml_name_bry);
byte[] xml_name_bry = Bry_.new_a7(xml_name_str);
byte[] key = Bry_.Mid(xml_name_bry, 1, xml_name_bry.length); // ignore & for purpose of trie; EX: "amp;"; NOTE: must keep trailing ";" else "&amp " will be valid;
trie.Add_obj(key, itm);
trie.Add_obj(key, new Xop_amp_trie_itm(itm_tid, char_int, xml_name_bry));
}
private static void Reg_prefix(Btrie_slim_mgr trie, byte prefix_type, String prefix) {
byte[] prefix_ary = Bry_.new_a7(prefix);
private static void Add_prefix(Btrie_slim_mgr trie, byte prefix_type, String prefix) {
byte[] prefix_ary = Bry_.new_u8(prefix);
Xop_amp_trie_itm itm = new Xop_amp_trie_itm(prefix_type, Xop_amp_trie_itm.Char_int_null, prefix_ary);
trie.Add_obj(prefix_ary, itm);
}

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
public class Xop_amp_trie_itm {
public class Xop_amp_trie_itm { // TS
public Xop_amp_trie_itm(byte tid, int char_int, byte[] xml_name_bry) {
this.tid = tid;
this.char_int = char_int;
@@ -25,11 +25,12 @@ public class Xop_amp_trie_itm {
this.xml_name_bry = xml_name_bry;
this.key_name_len = xml_name_bry.length - 2; // 2 for & and ;
}
public byte Tid() {return tid;} private final byte tid;
public int Char_int() {return char_int;} private final int char_int; // val; EX: 160
public byte[] U8_bry() {return u8_bry;} private final byte[] u8_bry; // EX: new byte[] {192, 160}; (C2, A0)
public byte[] Xml_name_bry() {return xml_name_bry;} private final byte[] xml_name_bry; // EX: "&nbsp;"
public int Key_name_len() {return key_name_len;} private final int key_name_len; // EX: "nbsp".Len
public byte Tid() {return tid;} private final byte tid;
public int Char_int() {return char_int;} private final int char_int; // val; EX: 160
public byte[] U8_bry() {return u8_bry;} private final byte[] u8_bry; // EX: new byte[] {192, 160}; (C2, A0)
public byte[] Xml_name_bry() {return xml_name_bry;} private final byte[] xml_name_bry; // EX: "&nbsp;"
public int Key_name_len() {return key_name_len;} private final int key_name_len; // EX: "nbsp".Len
public void Print_ncr(Bry_bfr bfr) {
switch (char_int) {
case Byte_ascii.Lt: case Byte_ascii.Gt: case Byte_ascii.Quote: case Byte_ascii.Amp:
@@ -48,9 +49,7 @@ public class Xop_amp_trie_itm {
case Byte_ascii.Gt: bfr.Add(Gfh_entity_.Gt_bry); break;
case Byte_ascii.Quote: bfr.Add(Gfh_entity_.Quote_bry); break;
case Byte_ascii.Amp: bfr.Add(Gfh_entity_.Amp_bry); break;
default:
bfr.Add(u8_bry); // write literal; EX: "[" not "&#91;"
break;
default: bfr.Add(u8_bry); break; // write literal; EX: "[" not "&#91;"
}
}
public static final byte Tid_name_std = 1, Tid_name_xowa = 2, Tid_num_hex = 3, Tid_num_dec = 4;

View File

@@ -20,11 +20,13 @@ public class Xop_amp_wkr implements Xop_ctx_wkr {
public void Ctor_ctx(Xop_ctx ctx) {}
public void Page_bgn(Xop_ctx ctx, Xop_root_tkn root) {}
public void Page_end(Xop_ctx ctx, Xop_root_tkn root, byte[] src, int src_len) {}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn, int cur_pos) {
if (cur_pos == src_len) return ctx.Lxr_make_txt_(cur_pos); // NOTE: & is last char in page; strange and rare, but don't raise error
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn, int cur) {
if (cur == src_len) return ctx.Lxr_make_txt_(cur); // NOTE: & is last char in page; strange and rare, but don't raise error
Xop_amp_mgr amp_mgr = ctx.App().Parser_amp_mgr();
Xop_tkn_itm amp_tkn = amp_mgr.Parse_as_tkn(tkn_mkr, src, src_len, bgn, cur_pos);
int rv_pos = amp_mgr.Rslt_pos();
Xop_amp_mgr_rslt amp_rv = amp_mgr.Parse_tkn(tkn_mkr, src, src_len, bgn, cur);
Xop_tkn_itm amp_tkn = amp_rv.Tkn();
int rv_pos = amp_rv.Pos();
if (amp_tkn == null) return ctx.Lxr_make_txt_(rv_pos);
ctx.Subs_add(root, amp_tkn);
return rv_pos;

View File

@@ -18,11 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xop_amp_wkr_tst {
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Name() {fxt.Test_parse_page_wiki("&amp;" , fxt.tkn_html_ref_("&amp;"));} // check for html_ref
@Test public void Name_fail() {fxt.Test_parse_page_wiki("&nil;" , fxt.tkn_txt_(0, 5));} // check for text
@Test public void Hex() {fxt.Test_parse_page_wiki("&#x3A3;" , fxt.tkn_html_ncr_(931));} // check for html_ncr; Σ: http://en.wikipedia.org/wiki/Numeric_character_reference
@Test public void Num_fail_incomplete() {fxt.Test_parse_page_wiki("&#" , fxt.tkn_txt_());}
private final Xop_fxt fxt = new Xop_fxt();
@Test public void Convert_to_named() {fxt.Test_parse_page_wiki_str("&amp;" , "&amp;");} // note that &amp; is printed, not &
@Test public void Convert_to_named_amp() {fxt.Test_parse_page_wiki_str("&" , "&amp;");} // PURPOSE: html_wtr was not handling & only
@Test public void Convert_to_numeric() {fxt.Test_parse_page_wiki_str("&aacute;" , "&#225;");} // testing that &#225; is outputted, not á

View File

@@ -1,29 +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.parsers.amps; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.tests.*;
public class Xop_html_txt_tkn_chkr extends Xop_tkn_chkr_base {
@Override public Class<?> TypeOf() {return Xop_amp_tkn_txt.class;}
@Override public byte Tkn_tid() {return Xop_tkn_itm_.Tid_html_ref;}
public String Html_ref_key() {return html_ref_key;} public Xop_html_txt_tkn_chkr Html_ref_key_(String v) {html_ref_key = v; return this;} private String html_ref_key;
@Override public int Chk_hook(Tst_mgr mgr, String path, Object actl_obj, int err) {
Xop_amp_tkn_txt actl = (Xop_amp_tkn_txt)actl_obj;
err += mgr.Tst_val(html_ref_key == null, path, "html_ref_key", html_ref_key, String_.new_u8(actl.Xml_name_bry()));
return err;
}
}

View File

@@ -33,8 +33,6 @@ public class Xop_apos_dat {
default:
lit_apos = apos_len - Xop_apos_tkn_.Len_dual;
Ident_props(Xop_apos_tkn_.Len_dual);
if (lit_apos > 1)
ctx.Msg_log().Add_itm_none(Xop_apos_log.Multiple_apos, src, cur_pos - apos_len, cur_pos);
break;
}
}

View File

@@ -0,0 +1,84 @@
/*
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.parsers.apos; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
public class Xop_apos_itm {
public int State() {return state;} public void State_clear() {state = Xop_apos_tkn_.State_nil;} private int state = Xop_apos_tkn_.State_nil;
public int Typ() {return typ;} private int typ;
public int Cmd() {return cmd;} private int cmd;
public int Lit_apos() {return lit_apos;} private int lit_apos;
public int Dual_cmd() {return dual_cmd;} private int dual_cmd;
public void Init(int state, int typ, int cmd, int lit_apos, int dual_cmd) {
this.state = state;
this.typ = typ; this.cmd = cmd; this.lit_apos = lit_apos; this.dual_cmd = dual_cmd;
}
public static void Ident(Xop_apos_itm rv, Xop_ctx ctx, byte[] src, int apos_len, int cur_pos, int state) {
switch (apos_len) {
case Xop_apos_tkn_.Len_ital: case Xop_apos_tkn_.Len_bold: case Xop_apos_tkn_.Len_dual:
Ident_props(rv, state, apos_len, 0); break;
case Xop_apos_tkn_.Len_apos_bold:
Ident_props(rv, state, Xop_apos_tkn_.Len_bold, 1); break;
default:
Ident_props(rv, state, Xop_apos_tkn_.Len_dual, apos_len - Xop_apos_tkn_.Len_dual);
break;
}
}
private static void Ident_props(Xop_apos_itm rv, int state, int apos_len, int lit_apos) {
int typ = apos_len;
int cmd = 0, dual_cmd = 0;
switch (apos_len) {
case Xop_apos_tkn_.Len_ital: {
switch (state) {
case Xop_apos_tkn_.State_i: cmd = Xop_apos_tkn_.Cmd_i_end; state = Xop_apos_tkn_.State_nil; break;
case Xop_apos_tkn_.State_bi: cmd = Xop_apos_tkn_.Cmd_i_end; state = Xop_apos_tkn_.State_b; break;
case Xop_apos_tkn_.State_ib: cmd = Xop_apos_tkn_.Cmd_bi_end__b_bgn; state = Xop_apos_tkn_.State_b; break;
case Xop_apos_tkn_.State_dual: cmd = Xop_apos_tkn_.Cmd_i_end; state = Xop_apos_tkn_.State_b; dual_cmd = Xop_apos_tkn_.Cmd_bi_bgn; break;
case Xop_apos_tkn_.State_b: cmd = Xop_apos_tkn_.Cmd_i_bgn; state = Xop_apos_tkn_.State_bi; break;
case Xop_apos_tkn_.State_nil: cmd = Xop_apos_tkn_.Cmd_i_bgn; state = Xop_apos_tkn_.State_i; break;
default: throw Err_.new_unhandled(state);
}
break;
}
case Xop_apos_tkn_.Len_bold: {
switch (state) {
case Xop_apos_tkn_.State_b: cmd = Xop_apos_tkn_.Cmd_b_end; state = Xop_apos_tkn_.State_nil; break;
case Xop_apos_tkn_.State_bi: cmd = Xop_apos_tkn_.Cmd_ib_end__i_bgn; state = Xop_apos_tkn_.State_i; break;
case Xop_apos_tkn_.State_ib: cmd = Xop_apos_tkn_.Cmd_b_end; state = Xop_apos_tkn_.State_i; break;
case Xop_apos_tkn_.State_dual: cmd = Xop_apos_tkn_.Cmd_b_end; state = Xop_apos_tkn_.State_i; break; // NOTE: dual_cmd = Cmd_ib_bgn is implied
case Xop_apos_tkn_.State_i: cmd = Xop_apos_tkn_.Cmd_b_bgn; state = Xop_apos_tkn_.State_ib; break;
case Xop_apos_tkn_.State_nil: cmd = Xop_apos_tkn_.Cmd_b_bgn; state = Xop_apos_tkn_.State_b; break;
default: throw Err_.new_unhandled(state);
}
break;
}
case Xop_apos_tkn_.Len_dual: {
switch (state) {
case Xop_apos_tkn_.State_b: cmd = Xop_apos_tkn_.Cmd_b_end__i_bgn; state = Xop_apos_tkn_.State_i; break;
case Xop_apos_tkn_.State_i: cmd = Xop_apos_tkn_.Cmd_i_end__b_bgn; state = Xop_apos_tkn_.State_b; break;
case Xop_apos_tkn_.State_bi: cmd = Xop_apos_tkn_.Cmd_ib_end; state = Xop_apos_tkn_.State_nil; break;
case Xop_apos_tkn_.State_ib: cmd = Xop_apos_tkn_.Cmd_bi_end; state = Xop_apos_tkn_.State_nil; break;
case Xop_apos_tkn_.State_dual: cmd = Xop_apos_tkn_.Cmd_bi_end; state = Xop_apos_tkn_.State_nil; break; // NOTE: dual_cmd = Cmd_ib_bgn is implied
case Xop_apos_tkn_.State_nil: cmd = Xop_apos_tkn_.Cmd_ib_bgn; state = Xop_apos_tkn_.State_dual; break;
default: throw Err_.new_unhandled(state);
}
break;
}
default: throw Err_.new_unhandled_default(apos_len);
}
rv.Init(state, typ, cmd, lit_apos, dual_cmd);
}
}

View File

@@ -17,27 +17,32 @@ 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.*;
public class Xop_apos_wkr implements Xop_ctx_wkr {
public Xop_apos_dat Dat() {return dat;} private Xop_apos_dat dat = new Xop_apos_dat();
private List_adp stack = List_adp_.New(); private int bold_count, ital_count; private Xop_apos_tkn dual_tkn = null;
private final List_adp stack = List_adp_.New();
private int bold_count, ital_count; private Xop_apos_tkn dual_tkn = null;
private Xop_apos_dat dat = new Xop_apos_dat();
public void Ctor_ctx(Xop_ctx ctx) {}
public void Page_bgn(Xop_ctx ctx, Xop_root_tkn root) {
Reset();
}
public void Page_bgn(Xop_ctx ctx, Xop_root_tkn root) {Clear();}
public void Page_end(Xop_ctx ctx, Xop_root_tkn root, byte[] src, int src_len) {
this.EndFrame(ctx, root, src, src_len, false);
this.End_frame(ctx, root, src, src_len, false);
}
public void AutoClose(Xop_ctx ctx, byte[] src, int src_len, int bgn_pos, int cur_pos, Xop_tkn_itm tkn) {}
public int Stack_len() {return stack.Count();}
public int Stack_len() {return stack.Len();}
private void Clear() {
bold_count = ital_count = 0;
dual_tkn = null;
stack.Clear();
dat.State_clear();
}
public int Make_tkn(Xop_ctx ctx, Xop_tkn_mkr tkn_mkr, Xop_root_tkn root, byte[] src, int src_len, int bgn_pos, int cur_pos) {
cur_pos = Bry_find_.Find_fwd_while(src, cur_pos, src_len, Byte_ascii.Apos);
int apos_len = cur_pos - bgn_pos;
dat.Ident(ctx, src, apos_len, cur_pos);
Xop_apos_tkn apos_tkn = tkn_mkr.Apos(bgn_pos, cur_pos, apos_len, dat.Typ(), dat.Cmd(), dat.Lit_apos());
ctx.Subs_add(root, apos_tkn);
ctx.Apos().RegTkn(apos_tkn, cur_pos);
ctx.Apos().Reg_tkn(apos_tkn, cur_pos); // NOTE: register in root ctx (main document)
return cur_pos;
}
public void RegTkn(Xop_apos_tkn tkn, int cur_pos) { // REF.MW: Parser|doQuotes
private void Reg_tkn(Xop_apos_tkn tkn, int cur_pos) { // REF.MW: Parser|doQuotes
stack.Add(tkn);
switch (tkn.Apos_tid()) {
case Xop_apos_tkn_.Len_ital: ital_count++; break;
@@ -52,19 +57,18 @@ public class Xop_apos_wkr implements Xop_ctx_wkr {
dual_tkn = null;
}
}
public void EndFrame(Xop_ctx ctx, Xop_root_tkn root, byte[] src, int cur_pos, boolean skip_cancel_if_lnki_and_apos) {
public void End_frame(Xop_ctx ctx, Xop_root_tkn root, byte[] src, int cur_pos, boolean skip_cancel_if_lnki_and_apos) {
int state = dat.State();
if (state == 0) {Reset(); return;}
if (bold_count % 2 == 1 && ital_count % 2 == 1) ConvertBoldToItal(ctx, src);
if (state == 0) {Clear(); return;} // all apos close correctly; nothing dangling; return;
if (bold_count % 2 == 1 && ital_count % 2 == 1) Convert_bold_to_ital(ctx, src, stack, dat);
state = dat.State();
if (state == 0) {Clear(); return;} // all apos close correctly after converting bold to italic; return;
int closeCmd = 0, closeTyp = 0;
if (state == 0) {Reset(); return;} // all closed: return
byte cur_tkn_tid = ctx.Cur_tkn_tid();
Xop_apos_tkn prv = Previous_bgn(stack, closeTyp);
if ( skip_cancel_if_lnki_and_apos // NOTE: if \n or tblw
&& cur_tkn_tid == Xop_tkn_itm_.Tid_lnki // and cur scope is lnki
// && prv.Ctx_tkn_tid() != Xop_tkn_itm_.Tid_lnki // but apos_bgn is not lnki; NOTE: disabled on 2013-11-10
)
return; // don't end frame
switch (state) {
@@ -74,30 +78,29 @@ public class Xop_apos_wkr implements Xop_ctx_wkr {
case Xop_apos_tkn_.State_ib: closeTyp = Xop_apos_tkn_.Typ_dual; closeCmd = Xop_apos_tkn_.Cmd_bi_end; break;
case Xop_apos_tkn_.State_bi: closeTyp = Xop_apos_tkn_.Typ_dual; closeCmd = Xop_apos_tkn_.Cmd_ib_end; break;
}
ctx.Msg_log().Add_itm_none(Xop_apos_log.Dangling_apos, src, prv.Src_bgn(), cur_pos);
ctx.Subs_add(root, ctx.Tkn_mkr().Apos(cur_pos, cur_pos, 0, closeTyp, closeCmd, 0));
Reset();
Clear();
}
private void ConvertBoldToItal(Xop_ctx ctx, byte[] src) {
private static void Convert_bold_to_ital(Xop_ctx ctx, byte[] src, List_adp stack, Xop_apos_dat dat) {
Xop_apos_tkn idxNeg1 = null, idxNeg2 = null, idxNone = null; // look at previous tkn for spaces; EX: "a '''" -> idxNeg1; " a'''" -> idxNeg2; "ab'''" -> idxNone
int tknsLen = stack.Count();
for (int i = 0; i < tknsLen; i++) {
int len = stack.Len();
for (int i = 0; i < len; ++i) {
Xop_apos_tkn apos = (Xop_apos_tkn)stack.Get_at(i);
if (apos.Apos_tid() != Xop_apos_tkn_.Typ_bold) continue; // only look for bold
int tknBgn = apos.Src_bgn();
boolean idxNeg1Space = tknBgn > 0 && src[tknBgn - 1] == Byte_ascii.Space;
boolean idxNeg2Space = tknBgn > 1 && src[tknBgn - 2] == Byte_ascii.Space;
int tkn_bgn = apos.Src_bgn();
boolean idxNeg1Space = tkn_bgn > 0 && src[tkn_bgn - 1] == Byte_ascii.Space;
boolean idxNeg2Space = tkn_bgn > 1 && src[tkn_bgn - 2] == Byte_ascii.Space;
if (idxNeg1 == null && idxNeg1Space) {idxNeg1 = apos;}
else if (idxNeg2 == null && idxNeg2Space) {idxNeg2 = apos;}
else if (idxNone == null && !idxNeg1Space && !idxNeg2Space) {idxNone = apos;}
}
if (idxNeg2 != null) ConvertBoldToItal(ctx, src, idxNeg2); // 1st single letter word
else if (idxNone != null) ConvertBoldToItal(ctx, src, idxNone); // 1st multi letter word
else if (idxNeg1 != null) ConvertBoldToItal(ctx, src, idxNeg1); // everything else
if (idxNeg2 != null) Convert_bold_to_ital(ctx, src, idxNeg2); // 1st single letter word
else if (idxNone != null) Convert_bold_to_ital(ctx, src, idxNone); // 1st multi letter word
else if (idxNeg1 != null) Convert_bold_to_ital(ctx, src, idxNeg1); // everything else
// now recalc all cmds for stack
dat.State_clear();
for (int i = 0; i < tknsLen; i++) {
for (int i = 0; i < len; i++) {
Xop_apos_tkn apos = (Xop_apos_tkn)stack.Get_at(i);
dat.Ident(ctx, src, apos.Apos_tid(), apos.Src_end()); // NOTE: apos.Typ() must map to apos_len
int newCmd = dat.Cmd();
@@ -105,57 +108,7 @@ public class Xop_apos_wkr implements Xop_ctx_wkr {
apos.Apos_cmd_(newCmd);
}
}
private void ConvertBoldToItal(Xop_ctx ctx, byte[] src, Xop_apos_tkn oldTkn) {
ctx.Msg_log().Add_itm_none(Xop_apos_log.Bold_converted_to_ital, src, oldTkn.Src_bgn(), oldTkn.Src_end());
private static void Convert_bold_to_ital(Xop_ctx ctx, byte[] src, Xop_apos_tkn oldTkn) {
oldTkn.Apos_tid_(Xop_apos_tkn_.Typ_ital).Apos_cmd_(Xop_apos_tkn_.Cmd_i_bgn).Apos_lit_(oldTkn.Apos_lit() + 1);// NOTE: Cmd_i_bgn may be overridden later
}
private void Reset() {
bold_count = ital_count = 0;
dual_tkn = null;
stack.Clear();
dat.State_clear();
}
private static Xop_apos_tkn Previous_bgn(List_adp stack, int typ) {
int stack_len = stack.Count();
for (int i = stack_len - 1; i > -1; --i) {
Xop_apos_tkn apos = (Xop_apos_tkn)stack.Get_at(i);
int cmd = apos.Apos_cmd();
switch (typ) {
case Xop_apos_tkn_.Typ_ital:
switch (cmd) {
case Xop_apos_tkn_.Cmd_i_bgn:
case Xop_apos_tkn_.Cmd_ib_bgn:
case Xop_apos_tkn_.Cmd_bi_bgn:
case Xop_apos_tkn_.Cmd_ib_end__i_bgn:
case Xop_apos_tkn_.Cmd_b_end__i_bgn:
return apos;
}
break;
case Xop_apos_tkn_.Typ_bold:
switch (cmd) {
case Xop_apos_tkn_.Cmd_b_bgn:
case Xop_apos_tkn_.Cmd_ib_bgn:
case Xop_apos_tkn_.Cmd_bi_bgn:
case Xop_apos_tkn_.Cmd_bi_end__b_bgn:
case Xop_apos_tkn_.Cmd_i_end__b_bgn:
return apos;
}
break;
default: // NOTE: this is approximate; will not be exact in most dual situations; EX: <b>a<i>b will return <i>; should return <b> and <i>
switch (cmd) {
case Xop_apos_tkn_.Cmd_b_bgn:
case Xop_apos_tkn_.Cmd_i_bgn:
case Xop_apos_tkn_.Cmd_ib_bgn:
case Xop_apos_tkn_.Cmd_bi_bgn:
case Xop_apos_tkn_.Cmd_bi_end__b_bgn:
case Xop_apos_tkn_.Cmd_i_end__b_bgn:
case Xop_apos_tkn_.Cmd_ib_end__i_bgn:
case Xop_apos_tkn_.Cmd_b_end__i_bgn:
return apos;
}
break;
}
}
return null;
}
}

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