mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.12.1.1
This commit is contained in:
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.dbs.*;
|
||||
class Cldr_lang_tbl implements RlsAble {
|
||||
class Cldr_lang_tbl implements Rls_able {
|
||||
private final String tbl_name = "cldr_lang"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_cldr_code, fld_lang_code, fld_lang_name;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
|
||||
|
||||
@@ -20,12 +20,12 @@ import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
class Imap_img_fmtr_arg extends gplx.core.brys.Bfr_arg_base {
|
||||
private Xoh_wtr_ctx hctx; private Imap_map map; private Imap_xtn_mgr xtn_mgr;
|
||||
private Xoh_wtr_ctx hctx; private Imap_map map; private Imap_xtn_mgr xtn_mgr; // private byte[] src;
|
||||
private int img_elem_id, img_w, img_h;
|
||||
private byte[] img_alt, img_src, img_cls, img_href;
|
||||
private Int_2_ref margin_calc = new Int_2_ref();
|
||||
public void Init(Xoh_wtr_ctx hctx, Imap_xtn_mgr xtn_mgr, Imap_map map, int img_elem_id, byte[] img_alt, byte[] img_src, int img_w, int img_h, byte[] img_cls, byte[] img_href) {
|
||||
this.hctx = hctx; this.map = map; this.xtn_mgr = xtn_mgr;
|
||||
public void Init(Xoh_wtr_ctx hctx, Imap_xtn_mgr xtn_mgr, Imap_map map, byte[] src, int img_elem_id, byte[] img_alt, byte[] img_src, int img_w, int img_h, byte[] img_cls, byte[] img_href) {
|
||||
this.hctx = hctx; this.map = map; this.xtn_mgr = xtn_mgr; // this.src = src;
|
||||
this.img_elem_id = img_elem_id; this.img_w = img_w; this.img_h = img_h;
|
||||
this.img_alt = img_alt;
|
||||
this.img_src = img_src;
|
||||
@@ -40,6 +40,9 @@ class Imap_img_fmtr_arg extends gplx.core.brys.Bfr_arg_base {
|
||||
Xoh_arg_img_core img_core_fmtr = xtn_mgr.Img_core_fmtr(hctx_is_hdump);
|
||||
img_core_fmtr.Init(img_elem_id, img_src, img_w, img_h);
|
||||
if (itm_dflt != null) {
|
||||
// Xowe_wiki wiki = map.Xtn_mgr().Wiki();
|
||||
// if (src.length != 0) // imap update will pass 0 src
|
||||
// Imap_link_owner_.Write(itm_dflt, wiki.Appe(), wiki, hctx, src);
|
||||
fmtr = itm_dflt.Link_tid() == Xop_tkn_itm_.Tid_lnki ? Imap_html_fmtrs.Img_anchor_lnki : Imap_html_fmtrs.Img_anchor_lnke;
|
||||
anchor_href = itm_dflt.Link_href();
|
||||
anchor_text = itm_dflt.Link_text();
|
||||
|
||||
@@ -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.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
|
||||
interface Imap_itm {
|
||||
byte Itm_tid();
|
||||
}
|
||||
@@ -49,9 +49,11 @@ class Imap_itm_desc implements Imap_itm {
|
||||
}
|
||||
class Imap_itm_dflt implements Imap_itm, Imap_link_owner {
|
||||
public byte Itm_tid() {return Imap_itm_.Tid_dflt;}
|
||||
public int Link_tid() {return link_tid;} public void Link_tid_(int v) {link_tid = v;} private int link_tid;
|
||||
public int Link_tid() {return link_tid;} private int link_tid;
|
||||
public Xop_tkn_itm Link_tkn() {return link_tkn;} private Xop_tkn_itm link_tkn;
|
||||
public void Link_tid_(int tid, Xop_tkn_itm tkn) {link_tid = tid; link_tkn = tkn;}
|
||||
public byte[] Link_href() {return link_href;} public void Link_href_(byte[] v) {this.link_href = v;} private byte[] link_href;
|
||||
public byte[] Link_text() {return link_text;} public void Link_text_(byte[] v) {this.link_text = v;} private byte[] link_text;
|
||||
public byte[] Link_text() {return link_text;} public void Link_text_(byte[] v) {this.link_text = v;} private byte[] link_text;
|
||||
}
|
||||
class Imap_err {
|
||||
public Imap_err(int itm_idx, String err_key) {this.itm_idx = itm_idx; this.err_key = err_key;}
|
||||
|
||||
@@ -17,10 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkes.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkes.*;
|
||||
interface Imap_link_owner {
|
||||
void Link_tid_(int v);
|
||||
int Link_tid();
|
||||
Xop_tkn_itm Link_tkn();
|
||||
void Link_tid_(int v, Xop_tkn_itm tkn);
|
||||
void Link_href_(byte[] v);
|
||||
void Link_text_(byte[] v);
|
||||
}
|
||||
@@ -29,7 +31,7 @@ class Imap_link_owner_ {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
int tkn_tid = tkn.Tkn_tid();
|
||||
link_owner.Link_tid_(tkn_tid);
|
||||
link_owner.Link_tid_(tkn_tid, tkn);
|
||||
switch (tkn_tid) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn;
|
||||
@@ -43,7 +45,7 @@ class Imap_link_owner_ {
|
||||
Xop_ctx ctx = wiki.Parser_mgr().Ctx();
|
||||
int lnke_bgn = lnke.Lnke_href_bgn(), lnke_end = lnke.Lnke_href_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
|
||||
Xoh_lnke_html lnke_wtr = wiki.Html_mgr().Html_wtr().Wkr__lnke();
|
||||
lnke_wtr.Write_href(bfr, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
lnke_wtr.Write_href(bfr, Xoh_wtr_ctx.Basic, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_href_(bfr.To_bry_and_clear());
|
||||
lnke_wtr.Write_caption(bfr, wiki.Html_mgr().Html_wtr(), Xoh_wtr_ctx.Basic, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_text_(bfr.To_bry_and_clear());
|
||||
@@ -53,6 +55,32 @@ class Imap_link_owner_ {
|
||||
}
|
||||
finally {bfr.Mkr_rls();} // release buffer in case of null error; PAGE:de.u:PPA/Raster/TK25/51/18/12/20; DATE:2015-02-02
|
||||
}
|
||||
public static void Write_todo(Imap_link_owner link_owner, Xoae_app app, Xowe_wiki wiki, Xoh_wtr_ctx hctx, byte[] src) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
switch (link_owner.Link_tid()) {
|
||||
case Xop_tkn_itm_.Tid_lnki: {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)link_owner.Link_tkn();
|
||||
link_owner.Link_href_(app.Html__href_wtr().Build_to_bry(wiki, lnki_tkn.Ttl()));
|
||||
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_caption(bfr, hctx, src, lnki_tkn, lnki_tkn.Ttl());
|
||||
link_owner.Link_text_(bfr.To_bry_and_clear());
|
||||
break;
|
||||
}
|
||||
case Xop_tkn_itm_.Tid_lnke: {
|
||||
Xop_lnke_tkn lnke = (Xop_lnke_tkn)link_owner.Link_tkn();
|
||||
Xop_ctx ctx = wiki.Parser_mgr().Ctx();
|
||||
int lnke_bgn = lnke.Lnke_href_bgn(), lnke_end = lnke.Lnke_href_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
|
||||
Xoh_lnke_html lnke_wtr = wiki.Html_mgr().Html_wtr().Wkr__lnke();
|
||||
lnke_wtr.Write_href(bfr, Xoh_wtr_ctx.Basic, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_href_(bfr.To_bry_and_clear());
|
||||
lnke_wtr.Write_caption(bfr, wiki.Html_mgr().Html_wtr(), hctx, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
|
||||
link_owner.Link_text_(bfr.To_bry_and_clear());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {bfr.Mkr_rls();} // release buffer in case of null error; PAGE:de.u:PPA/Raster/TK25/51/18/12/20; DATE:2015-02-02
|
||||
}
|
||||
}
|
||||
class Imap_itm_shape implements Imap_itm, Imap_link_owner {
|
||||
public Imap_itm_shape(byte shape_tid, Double_obj_val[] shape_pts) {
|
||||
@@ -61,8 +89,10 @@ class Imap_itm_shape implements Imap_itm, Imap_link_owner {
|
||||
}
|
||||
public byte Itm_tid() {return shape_tid;} private byte shape_tid;
|
||||
public Double_obj_val[] Shape_pts() {return shape_pts;} private Double_obj_val[] shape_pts;
|
||||
public int Link_tid() {return link_tid;} public void Link_tid_(int v) {link_tid = v;} private int link_tid;
|
||||
public int Link_tid() {return link_tid;} private int link_tid;
|
||||
public Xop_tkn_itm Link_tkn() {return link_tkn;} private Xop_tkn_itm link_tkn;
|
||||
public void Link_tid_(int tid, Xop_tkn_itm tkn) {link_tid = tid; link_tkn = tkn;}
|
||||
public byte[] Link_href() {return link_href;} public void Link_href_(byte[] v) {this.link_href = v;} private byte[] link_href;
|
||||
public byte[] Link_text() {return link_text;} public void Link_text_(byte[] v) {this.link_text = v;} private byte[] link_text;
|
||||
public byte[] Link_text() {return link_text;} public void Link_text_(byte[] v) {this.link_text = v;} private byte[] link_text;
|
||||
public static final byte Tid_default = 0, Tid_rect = 4, Tid_circle = 3, Tid_poly = 5;
|
||||
}
|
||||
|
||||
@@ -36,27 +36,32 @@ public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
|
||||
@gplx.Internal protected Imap_err[] Errs() {return errs;} private Imap_err[] errs;
|
||||
private byte img_cls_tid;
|
||||
private byte[] a_href, img_alt, img_cls_other;
|
||||
public void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, Xof_file_itm xfer_itm, int uid
|
||||
public void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, byte[] src, Xof_file_itm xfer_itm, int uid
|
||||
, byte[] a_href, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title
|
||||
, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other
|
||||
) {
|
||||
xfer_itm.Html_img_wkr_(this);
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_imap);
|
||||
this.a_href = a_href; this.img_alt = img_alt; this.img_cls_tid = img_cls; this.img_cls_other = img_cls_other;
|
||||
Write_imap_div(tmp_bfr, hctx, uid, img_w, img_h, img_src, xfer_itm.Orig_w(), xfer_itm.Orig_h());
|
||||
Write_imap_div(tmp_bfr, page.Wikie(), hctx, src, uid, img_w, img_h, img_src, xfer_itm.Orig_w(), xfer_itm.Orig_h());
|
||||
if (hctx.Mode_is_hdump())
|
||||
page.Hdump_data().Imgs_add_img(new Xohd_img_itm__img(), xfer_itm, Xohd_img_itm__gallery_itm.Tid_basic);
|
||||
}
|
||||
public void Html_update(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) {
|
||||
Xowe_wiki wiki = xtn_mgr.Wiki();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Write_imap_div(tmp_bfr, Xoh_wtr_ctx.Basic, html_uid, html_w, html_h, html_view_url.To_http_file_bry(), orig_w, orig_h);
|
||||
Write_imap_div(tmp_bfr, (Xowe_wiki)page.Wiki(), Xoh_wtr_ctx.Basic, Bry_.Empty, html_uid, html_w, html_h, html_view_url.To_http_file_bry(), orig_w, orig_h);
|
||||
js_wkr.Html_elem_replace_html("imap_div_" + Int_.To_str(html_uid), tmp_bfr.To_str_and_rls());
|
||||
}
|
||||
private void Write_imap_div(Bry_bfr bfr, Xoh_wtr_ctx hctx, int html_uid, int html_w, int html_h, byte[] html_src, int orig_w, int orig_h) {
|
||||
private void Write_imap_div(Bry_bfr bfr, Xowe_wiki wiki, Xoh_wtr_ctx hctx, byte[] src, int html_uid, int html_w, int html_h, byte[] html_src, int orig_w, int orig_h) {
|
||||
byte[] desc_style = Calc_desc_style(html_w, html_h);
|
||||
// int shapes_len = shapes.length;
|
||||
// for (int i = 0; i < shapes_len; ++i) {
|
||||
// Imap_itm_shape shape = shapes[i];
|
||||
// Imap_link_owner_.Write(shape, wiki.Appe(), wiki, hctx, src);
|
||||
// }
|
||||
map_fmtr_arg.Init(id, shapes, Calc_scale(orig_w, orig_h, html_w, html_h));
|
||||
img_fmtr_arg.Init(hctx, xtn_mgr, this, html_uid, img_alt, html_src, html_w, html_h, Xoh_img_cls_.To_html(img_cls_tid, img_cls_other), a_href);
|
||||
img_fmtr_arg.Init(hctx, xtn_mgr, this, src, html_uid, img_alt, html_src, html_w, html_h, Xoh_img_cls_.To_html(img_cls_tid, img_cls_other), a_href);
|
||||
Imap_html_fmtrs.All.Bld_bfr_many(bfr, html_uid, desc_style, map_fmtr_arg, img_fmtr_arg);
|
||||
}
|
||||
private byte[] Calc_desc_style(int html_w, int html_h) {
|
||||
|
||||
@@ -29,13 +29,11 @@ class Imap_parser {
|
||||
private int itm_idx; private int itm_bgn, itm_end;
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xop_ctx wiki_ctx, imap_ctx; private Xop_root_tkn imap_root;
|
||||
public Imap_parser(Imap_xtn_mgr xtn_mgr) {this.xtn_mgr = xtn_mgr;}
|
||||
public void Init(Xowe_wiki wiki, Xoa_url page_url, Gfo_usr_dlg usr_dlg) {
|
||||
this.app = wiki.Appe(); this.wiki = wiki; this.page_url = page_url; this.usr_dlg = usr_dlg;
|
||||
public void Init(Xowe_wiki wiki, Xoae_page page, Gfo_usr_dlg usr_dlg) {// SCOPE.PAGE
|
||||
this.app = wiki.Appe(); this.wiki = wiki; this.page_url = page.Url(); this.usr_dlg = usr_dlg;
|
||||
this.wiki_ctx = wiki.Parser_mgr().Ctx();
|
||||
if (imap_ctx == null) {
|
||||
imap_ctx = Xop_ctx.new_(wiki);
|
||||
imap_root = app.Parser_mgr().Tkn_mkr().Root(Bry_.Empty);
|
||||
}
|
||||
imap_ctx = Xop_ctx.new_(wiki, page.Ttl().Raw()); // NOTE: must update page ttl for Modules; PAGE:it.s:Patria_Esercito_Re/Indice_generale; DATE:2015-12-02
|
||||
imap_root = app.Parser_mgr().Tkn_mkr().Root(Bry_.Empty);
|
||||
}
|
||||
public void Clear() {
|
||||
this.itm_idx = 0;
|
||||
@@ -44,7 +42,7 @@ class Imap_parser {
|
||||
}
|
||||
public Imap_map Parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
Imap_map rv = new Imap_map(ctx.Cur_page().Html_data().Xtn_imap_next_id());
|
||||
Init(wiki, ctx.Cur_page().Url(), wiki.Appe().Usr_dlg());
|
||||
Init(wiki, ctx.Cur_page(), wiki.Appe().Usr_dlg());
|
||||
this.Parse(rv, src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
return rv;
|
||||
}
|
||||
@@ -56,7 +54,7 @@ class Imap_parser {
|
||||
if (itm_end == src_end) break;
|
||||
itm_bgn = Bry_find_.Trim_fwd_space_tab(src, itm_end + 1, src_end); // trim ws at start, and look for first char
|
||||
if (itm_bgn == src_end) break; // line is entirely ws and terminated by eos; EX: "\n EOS"
|
||||
itm_end = Bry_find_.Find_fwd_until(src, itm_bgn, src_end, Byte_ascii.Nl); // look for \n
|
||||
itm_end = Bry_find_.Find_fwd_until(src, itm_bgn, src_end, Byte_ascii.Nl); // look for \n
|
||||
if (itm_end == Bry_find_.Not_found) itm_end = src_end; // no \n; make EOS = \n
|
||||
itm_end = Bry_find_.Trim_bwd_space_tab(src, itm_end, itm_bgn); // trim any ws at end
|
||||
if (itm_end - itm_bgn == 0) continue; // line is entirely ws; continue;
|
||||
@@ -171,7 +169,7 @@ class Imap_parser {
|
||||
}
|
||||
private Xop_tkn_itm Parse_link(byte[] raw) {
|
||||
imap_root.Clear();
|
||||
imap_ctx.Clear();
|
||||
imap_ctx.Clear(false); // NOTE: imap should not reset scrib; PAGE:it.s:La_guerra_del_vespro_siciliano/Indice DATE:2015-12-02
|
||||
wiki.Parser_mgr().Main().Parse_text_to_wdom(imap_root, imap_ctx, wiki.Appe().Parser_mgr().Tkn_mkr(), raw, 0);
|
||||
int subs_len = imap_root.Subs_len();
|
||||
for (int i = 0; i < subs_len; ++i) {
|
||||
@@ -194,7 +192,7 @@ class Imap_parser {
|
||||
if ( tkn_itm == null // no lnki or lnke
|
||||
|| tkn_itm.Tkn_tid() != Xop_tkn_itm_.Tid_lnki // no lnki; occurs with badly constructed maps; PAGE:en.w:Demography_of_the_United_Kingdom DATE:2015-01-22
|
||||
)
|
||||
imap_ctx.Wiki().Appe().Usr_dlg().Warn_many("", "", "image_map failed to find lnki; page=~{0} imageMap=~{1}", String_.new_u8(imap_ctx.Cur_page().Ttl().Full_txt()), String_.new_u8(imap_img_src));
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "image_map failed to find lnki; page=~{0} imageMap=~{1}", page_url.To_str(), imap_img_src);
|
||||
else {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn_itm;
|
||||
imap_img = new Imap_itm_img(lnki_tkn);
|
||||
@@ -216,7 +214,7 @@ class Imap_parser {
|
||||
else {
|
||||
Object tid_obj = tid_trie.Match_bgn_w_byte(b, src, pos, src_end);
|
||||
if (tid_obj == null) { // not a known imap line; assume continuation of img line and skip to next line
|
||||
imap_ctx.Wiki().Appe().Usr_dlg().Note_many("", "", "image_map extending image over multiple lines; page=~{0} imageMap=~{1}", String_.new_u8(imap_ctx.Cur_page().Ttl().Full_txt()), String_.new_u8(imap_img_src));
|
||||
Xoa_app_.Usr_dlg().Note_many("", "", "image_map extending image over multiple lines; page=~{0} imageMap=~{1}", page_url.To_str(), imap_img_src);
|
||||
int next_line = Bry_find_.Find_fwd(src, Byte_ascii.Nl, pos);
|
||||
if (next_line == Bry_find_.Not_found) next_line = src_end;
|
||||
rv = next_line;
|
||||
|
||||
@@ -67,10 +67,11 @@ class Imap_parser_fxt extends Imap_fxt_base {
|
||||
private Imap_map imap;
|
||||
@Override public void Reset() {
|
||||
super.Reset();
|
||||
Xoa_url url = Xoa_url.new_(wiki.Domain_bry(), Bry_.new_a7("Test_1"));
|
||||
byte[] ttl_bry = Bry_.new_a7("Test_1");
|
||||
Imap_xtn_mgr xtn_mgr = new Imap_xtn_mgr();
|
||||
Xoae_page page = Xoae_page.New(wiki, wiki.Ttl_parse(ttl_bry));
|
||||
parser = new Imap_parser(xtn_mgr);
|
||||
parser.Init(wiki, url, Gfo_usr_dlg_.Noop);
|
||||
parser.Init(wiki, page, Gfo_usr_dlg_.Noop);
|
||||
parser.Clear();
|
||||
imap = new Imap_map(1);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,43 @@ public class Lst_pfunc_lst_tst {
|
||||
fxt.Fxt().Init_page_create("Sub_0", "<section begin=key_0 />a{{Sub_1}}<section end=key_0 />");
|
||||
fxt.Fxt().Test_parse_page_all_str("{{#section:Sub_0|key_0}}", "ab");
|
||||
}
|
||||
@Test public void Nested__ref() { // PURPOSE: handle tags; PAGE:it.s:La_Secchia_rapita/Canto_primo DATE:2015-12-02
|
||||
fxt.Fxt().Init_page_create("Template:TagTemplate", "<ref>xyz</ref>");
|
||||
fxt.Fxt().Init_page_create("PoemPage", "<poem>A{{TagTemplate}}B</poem>");
|
||||
fxt.Fxt().Test_parse_page_all_str("{{#section:PoemPage}}<references/>", String_.Replace(String_.Concat_lines_nl_skip_last
|
||||
( "<div class='poem'>"
|
||||
, "<p>"
|
||||
, "A<sup id='cite_ref-0' class='reference'><a href='#cite_note-0'>[1]</a></sup>B"
|
||||
, "</p>"
|
||||
, "</div><ol class='references'>"
|
||||
, "<li id='cite_note-0'><span class='mw-cite-backlink'><a href='#cite_ref-0'>^</a></span> <span class='reference-text'>xyz</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
), "'", "\""));
|
||||
}
|
||||
@Test public void Nested__ref_poem() { // PURPOSE: handle tags; PAGE:it.s:La_Secchia_rapita/Canto_primo DATE:2015-12-02
|
||||
fxt.Fxt().Init_page_create("Template:TagTemplate", "{{#tag:ref|abc<poem>def</poem>xyz}}");
|
||||
fxt.Fxt().Init_page_create("PoemPage", String_.Concat_lines_nl_skip_last
|
||||
( "<poem>A{{TagTemplate}}"
|
||||
, " B"
|
||||
, "</poem>"
|
||||
));
|
||||
fxt.Fxt().Test_parse_page_all_str("{{#section:PoemPage}}<references/>", String_.Replace(String_.Concat_lines_nl_skip_last
|
||||
( "<div class='poem'>"
|
||||
, "<p>"
|
||||
, "A<sup id='cite_ref-0' class='reference'><a href='#cite_note-0'>[1]</a></sup><br/>"
|
||||
, "    B"
|
||||
, "</p>"
|
||||
, "</div><ol class='references'>"
|
||||
, "<li id='cite_note-0'><span class='mw-cite-backlink'><a href='#cite_ref-0'>^</a></span> <span class='reference-text'>abc<div class='poem'>"
|
||||
, "<p>"
|
||||
, "def"
|
||||
, "</p>"
|
||||
, "</div>xyz</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
), "'", "\""));
|
||||
}
|
||||
}
|
||||
class Lst_pfunc_lst_fxt {
|
||||
public Lst_pfunc_lst_fxt Clear() {
|
||||
|
||||
@@ -23,4 +23,5 @@ public class Map_deg2dd_func_tst {
|
||||
@Test public void Prec_round() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 1.2345|3}}" , "{{test}}" , "1.235");}
|
||||
@Test public void Example() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 14° 23' 45'' S|precision=3}}" , "{{test}}" , "-14.396");}
|
||||
@Test public void Example_N() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 14° 23' 45'' N|precision=3}}" , "{{test}}" , "14.396");}
|
||||
@Test public void Apos() {fxt.Test_parse_tmpl_str_test("{{#deg2dd: 42°39’49’’N |precision=2}}" , "{{test}}" , "42.66");} // PURPOSE: handle ’’ to "; PAGE:it.v:Morro_d'Oro DATE:2015-12-06
|
||||
}
|
||||
|
||||
@@ -245,30 +245,19 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
else return 4;
|
||||
}
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(32);
|
||||
private static byte[] Parse_input_normalize(Bry_bfr bfr, byte[] input) {
|
||||
int input_end = input.length; if (input_end == 0) return null;
|
||||
int i = 0;
|
||||
while (i < input_end) {
|
||||
byte b = input[i];
|
||||
Object o = Input_trie.Match_bgn_w_byte(b, input, i, input_end);
|
||||
if (o == null) {
|
||||
bfr.Add_byte(b);
|
||||
++i;
|
||||
}
|
||||
else {
|
||||
byte tid = ((Byte_obj_val)o).Val();
|
||||
switch (tid) {
|
||||
case Input_tid_apos: bfr.Add_byte(Byte_ascii.Apos).Add_byte_space(); break; // EX: "'" -> "' "
|
||||
case Input_tid_quote: bfr.Add_byte(Byte_ascii.Quote).Add_byte_space(); break; // EX: '"' -> '" '
|
||||
case Input_tid_dash: bfr.Add_byte(Byte_ascii.Dash); break;
|
||||
case Input_tid_space: bfr.Add_byte_space(); break;
|
||||
case Input_tid_degree: bfr.Add_byte(Byte_ascii.Slash); bfr.Add_byte_space(); break; // EX: "°" -> "° "
|
||||
case Input_tid_compass: bfr.Add_byte_space(); bfr.Add_byte(Byte_ascii.Case_upper(b)); break; // NOTE: always single-char ASCII; EX: N,E,S,W,n,e,s,w
|
||||
}
|
||||
i = Input_trie.Match_pos();
|
||||
}
|
||||
}
|
||||
return bfr.To_bry_and_clear_and_trim();
|
||||
public static byte[] Parse_input_normalize(Bry_bfr bfr, byte[] src) {
|
||||
/*
|
||||
$w = str_replace( array( '‘', '’', '′' ), "'", $input );
|
||||
$w = str_replace( array( "''", '“', '”', '″' ), '"', $w );
|
||||
$w = str_replace( '−', '-', $w );
|
||||
$w = strtoupper( str_replace( array( '_', '/', "\t", "\n", "\r" ), ' ', $w ) );
|
||||
$w = str_replace( array( '°', "'", '"' ), array( '° ', "' ", '" ' ), $w );
|
||||
$w = trim( str_replace( array( 'N', 'S', 'E', 'W' ), array( ' N', ' S', ' E', ' W' ), $w ) );
|
||||
*/
|
||||
int src_end = src.length; if (src_end == 0) return null;
|
||||
src = Trie__normalize__apos.Replace(bfr, src, 0, src_end); // normalize apos separately, since 2 apos can go to quotes; EX: ‘’ -> "; PAGE:it.v:Morro_d'Oro DATE:2015-12-06
|
||||
src = Trie__normalize__rest.Replace(bfr, src, 0, src.length); // normalize rest;
|
||||
return Bry_.Trim(src);
|
||||
}
|
||||
private static final byte Dir_unknown_id = 0, Dir_lat_id = 1, Dir_long_id = 2;
|
||||
public static final byte[] Dir_lat_bry = Bry_.new_a7("lat"), Dir_long_bry = Bry_.new_a7("long");
|
||||
@@ -282,38 +271,20 @@ class Map_math {// REF.MW:MapSources_math.php
|
||||
, Compass_S = new byte[] {Byte_ascii.Ltr_S}
|
||||
, Compass_W = new byte[] {Byte_ascii.Ltr_W}
|
||||
;
|
||||
private static final byte Input_tid_apos = 1, Input_tid_quote = 2, Input_tid_dash = 3, Input_tid_space = 4, Input_tid_degree = 5, Input_tid_compass = 6;
|
||||
private static final byte Input_byte_degree = Byte_ascii.Slash; // NOTE: ugly cheat to avoid using multi-byte char; note that all "/" are swapped out to " ", so any remaining "/" was added by the normalizer; EX: "123° 4/5" -> "123/ 4 5"
|
||||
private static final byte[] Input_units = new byte[] {Input_byte_degree, Byte_ascii.Apos, Byte_ascii.Quote, Byte_ascii.Space};
|
||||
private static final int Input_units_len = Input_units.length;
|
||||
private static final byte[] Input_bry_degree = Bry_.new_u8("°");
|
||||
private static final Btrie_slim_mgr Input_trie = Btrie_slim_mgr.cs()
|
||||
.Add_str_byte("'" , Input_tid_apos) // NOTE: must add ' so that "'" -> "' "
|
||||
.Add_str_byte("‘" , Input_tid_apos)
|
||||
.Add_str_byte("’" , Input_tid_apos)
|
||||
.Add_str_byte("′" , Input_tid_apos)
|
||||
.Add_str_byte("\"" , Input_tid_quote) // NOTE: must add " so that '"' -> '" '
|
||||
.Add_str_byte("''" , Input_tid_quote)
|
||||
.Add_str_byte("“" , Input_tid_quote)
|
||||
.Add_str_byte("”" , Input_tid_quote)
|
||||
.Add_str_byte("″" , Input_tid_quote)
|
||||
.Add_str_byte("-" , Input_tid_dash)
|
||||
.Add_str_byte("−" , Input_tid_dash)
|
||||
.Add_str_byte(" " , Input_tid_space)
|
||||
.Add_str_byte("_" , Input_tid_space)
|
||||
.Add_str_byte("/" , Input_tid_space)
|
||||
.Add_str_byte("\t" , Input_tid_space)
|
||||
.Add_str_byte("\n" , Input_tid_space)
|
||||
.Add_str_byte("\r" , Input_tid_space)
|
||||
.Add_bry_byte(Input_bry_degree , Input_tid_degree)
|
||||
.Add_str_byte("N" , Input_tid_compass)
|
||||
.Add_str_byte("S" , Input_tid_compass)
|
||||
.Add_str_byte("E" , Input_tid_compass)
|
||||
.Add_str_byte("W" , Input_tid_compass)
|
||||
.Add_str_byte("n" , Input_tid_compass)
|
||||
.Add_str_byte("s" , Input_tid_compass)
|
||||
.Add_str_byte("e" , Input_tid_compass)
|
||||
.Add_str_byte("w" , Input_tid_compass)
|
||||
;
|
||||
private static final Btrie_slim_mgr Trie__normalize__apos = Btrie_slim_mgr.cs()
|
||||
.Add_replace_many (Byte_ascii.Apos_bry , "‘", "’", "′");
|
||||
private static final Btrie_slim_mgr Trie__normalize__rest = Btrie_slim_mgr.cs()
|
||||
.Add_replace_many ("' " , "'")
|
||||
.Add_replace_many ("\" " , "\"", "''", "“", "”", "″")
|
||||
.Add_replace_many (Byte_ascii.Dash_bry , "-", "−") // NOTE: emdash and endash
|
||||
.Add_replace_many (Byte_ascii.Space_bry , " ", "_", "/", "\t", "\n", "\r") // NOTE: " " =
|
||||
.Add_replace_many ("/ " , "°")
|
||||
.Add_replace_many (" N" , "N", "n")
|
||||
.Add_replace_many (" S" , "S", "s")
|
||||
.Add_replace_many (" E" , "E", "e")
|
||||
.Add_replace_many (" W" , "W", "w");
|
||||
public static final Map_math Instance = new Map_math();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Pfunc_tag extends Pf_func_base {
|
||||
public static final int
|
||||
Xtag_len = 27 // <xtag_bgn id='1234567890'/>
|
||||
, Xtag_bgn = 14 // <xtag_bgn id='
|
||||
, Id_len = 10
|
||||
;
|
||||
public static final byte[]
|
||||
Xtag_bgn_lhs = Bry_.new_a7("<xtag_bgn id='")
|
||||
|
||||
@@ -29,7 +29,8 @@ public class Poem_nde implements Xox_xnde {
|
||||
&& itm_end != itm_bgn) --itm_end; // ...if not same as 1st \n; EX: <poem>\n</poem>
|
||||
Poem_xtn_mgr xtn_mgr = (Poem_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Poem_xtn_mgr.XTN_KEY);
|
||||
byte[] poem_bry = Parse_lines(wiki.Utl__bfr_mkr(), src, itm_bgn, itm_end);
|
||||
xtn_root = xtn_mgr.Parser().Parse_text_to_wdom_old_ctx(ctx, poem_bry, true); // NOTE: ignoring paragraph mode; technically MW enables para mode, but by replacing "\n" with "<br/>\n" all the logic with para/pre mode is skipped
|
||||
// xtn_root = xtn_mgr.Parser().Parse_text_to_wdom_old_ctx(ctx, poem_bry, true); // NOTE: ignoring paragraph mode; technically MW enables para mode, but by replacing "\n" with "<br/>\n" all the logic with para/pre mode is skipped
|
||||
xtn_root = xtn_mgr.Parser().Parse_text_to_wdom(Xop_ctx.New_sub_by_ctx(ctx), poem_bry, true); // NOTE: ignoring paragraph mode; technically MW enables para mode, but by replacing "\n" with "<br/>\n" all the logic with para/pre mode is skipped
|
||||
}
|
||||
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
|
||||
if (xtn_root == null) return; // inline poem; write nothing; EX: <poem/>
|
||||
|
||||
@@ -16,6 +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.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.core.bits.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
public class Scrib_lib_text implements Scrib_lib {
|
||||
private final Scrib_lib_text__json_util json_util = new Scrib_lib_text__json_util();
|
||||
|
||||
@@ -95,7 +95,8 @@ class Scrib_lib_text__json_util {
|
||||
Json_kv json_kv = root.Get_at_as_kv(i);
|
||||
String kv_str = json_kv.Key_as_str();
|
||||
Object kv_val = Decode_obj(json_kv.Val());
|
||||
decode_rslt_as_nde[i] = KeyVal_.new_(kv_str, kv_val);
|
||||
int kv_int = Int_.parse_or(kv_str, Int_.Min_value);
|
||||
decode_rslt_as_nde[i] = kv_int == Int_.Min_value ? KeyVal_.new_(kv_str, kv_val) : KeyVal_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
|
||||
}
|
||||
return Bool_.Y_byte;
|
||||
}
|
||||
@@ -123,7 +124,10 @@ class Scrib_lib_text__json_util {
|
||||
KeyVal[] rv = new KeyVal[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv itm = nde.Get_at_as_kv(i);
|
||||
rv[i] = KeyVal_.new_(itm.Key_as_str(), Decode_obj(itm.Val()));
|
||||
String kv_str = itm.Key_as_str();
|
||||
int kv_int = Int_.parse_or(kv_str, Int_.Min_value);
|
||||
Object kv_val = Decode_obj(itm.Val());
|
||||
rv[i] = kv_int == Int_.Min_value ? KeyVal_.new_(kv_str, kv_val) : KeyVal_.int_(kv_int, kv_val); // use int_key if applicable; PAGE:it.s:Il_Re_Cervo; DATE:2015-12-06
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -215,6 +215,26 @@ public class Scrib_lib_text_json_tst {
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void Decode__key__int() {
|
||||
KeyVal[] kv_ary = (KeyVal[])json_fxt.Test_json_decode(fxt, lib
|
||||
, Scrib_lib_text__json_util.Flag__none
|
||||
, Json_doc.Make_str_by_apos
|
||||
( "{ '1':"
|
||||
, " { '11':'aa'"
|
||||
, " }"
|
||||
, ", '2':'b'"
|
||||
, "}"
|
||||
)
|
||||
, KeyVal_.Ary
|
||||
( KeyVal_.int_(1, KeyVal_.Ary
|
||||
( KeyVal_.int_(11, "aa")
|
||||
))
|
||||
, KeyVal_.int_(2, "b")
|
||||
)
|
||||
);
|
||||
Tfds.Eq(kv_ary[0].Key_as_obj(), 1);
|
||||
Tfds.Eq(((KeyVal[])kv_ary[0].Val())[0].Key_as_obj(), 11);
|
||||
}
|
||||
}
|
||||
class Scrib_lib_json_fxt {
|
||||
private final Json_wtr wtr = new Json_wtr();
|
||||
@@ -222,9 +242,10 @@ class Scrib_lib_json_fxt {
|
||||
Test_json_decode(fxt, lib, Scrib_lib_text__json_util.Flag__none, json, obj);
|
||||
Test_json_encode(fxt, lib, Scrib_lib_text__json_util.Flag__none, obj, json);
|
||||
}
|
||||
public void Test_json_decode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, int flag, String raw, Object expd) {
|
||||
public Object Test_json_decode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, int flag, String raw, Object expd) {
|
||||
Object actl = fxt.Test_scrib_proc_rv_as_obj(lib, Scrib_lib_text.Invk_jsonDecode, Object_.Ary(raw, flag));
|
||||
Tfds.Eq_str_lines(To_str(expd), To_str(actl), raw);
|
||||
return actl;
|
||||
}
|
||||
public void Test_json_encode(Scrib_invoke_func_fxt fxt, Scrib_lib_text lib, int flag, Object raw, String expd) {
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_text.Invk_jsonEncode, Object_.Ary(raw, flag), "1=" + String_.Replace(expd, "'", "\""));
|
||||
|
||||
@@ -139,7 +139,7 @@ class Scrib_lib_wikibase_srl {
|
||||
return (KeyVal[])rv.To_ary_and_clear(KeyVal.class);
|
||||
}
|
||||
private static KeyVal[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) {
|
||||
boolean snak_is_valued = itm.Snak_tid() != Wdata_dict_snak_tid.Tid_novalue;
|
||||
boolean snak_is_valued = itm.Snak_tid() == Wdata_dict_snak_tid.Tid_value; // PURPOSE: was != Wdata_dict_snak_tid.Tid_novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
|
||||
int snak_is_valued_adj = snak_is_valued ? 1 : 0;
|
||||
KeyVal[] rv = new KeyVal[3 + snak_is_valued_adj];
|
||||
if (snak_is_valued) // NOTE: novalue must not return slot (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16; ALSO: sv.w:Joseph_Jaquet; DATE:2015-07-31
|
||||
@@ -160,6 +160,6 @@ class Scrib_lib_wikibase_srl {
|
||||
}
|
||||
}
|
||||
public static final String Key_type = "type", Key_value = "value";
|
||||
private static final KeyVal[] Datavalue_somevalue = new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
|
||||
private static final KeyVal[] Datavalue_somevalue = KeyVal_.Ary_empty; // changed to not return value-node; PAGE:it.s:Autore:Anonimo DATE:2015-12-06 // new KeyVal[] {KeyVal_.new_(Key_type, ""), KeyVal_.new_(Key_value, "")}; // NOTE: must return ""; null fails; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
|
||||
private static final KeyVal[] Datavalue_novalue = KeyVal_.Ary_empty;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
, ""
|
||||
);
|
||||
}
|
||||
@Test public void Claims_somevalue() { // PURPOSE: somevalue should always return value node; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07
|
||||
@Test public void Claims_somevalue() { // PURPOSE: changed to not return value-node; PAGE:it.s:Autore:Anonimo DATE:2015-12-06 // somevalue should always return value node; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07;
|
||||
fxt.Init_prop(fxt.Wdata_fxt().Make_claim_somevalue(2));
|
||||
fxt.Test
|
||||
( "claims:"
|
||||
@@ -152,9 +152,6 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
, " 1:"
|
||||
, " id:'P2'"
|
||||
, " mainsnak:"
|
||||
, " datavalue:"
|
||||
, " type:''"
|
||||
, " value:''"
|
||||
, " property:'P2'"
|
||||
, " snaktype:'somevalue'"
|
||||
, " datatype:'unknown'"
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Wdata_lang_sorter implements GfoEvObj, gplx.core.lists.ComparerAble
|
||||
return new_sort;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Xoapi_wikibase.Evt_sort_langs_changed)) Langs_((byte[][])m.ReadObj("v", ParseAble_.Null));
|
||||
if (ctx.Match(k, Xoapi_wikibase.Evt_sort_langs_changed)) Langs_((byte[][])m.ReadObj("v", null));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ class Wdata_claims_parser_v2 {
|
||||
Wdata_claim_itm_base itm = Parse_claim_itm(qid, claim_itm_nde, pid);
|
||||
if (itm != null) // HACK: itm can be null if value is "somevalue"; DATE:2014-09-20
|
||||
claim_itms_list.Add(itm);
|
||||
else {
|
||||
Tfds.Write();
|
||||
}
|
||||
}
|
||||
}
|
||||
private Wdata_claim_itm_core Parse_claim_itm(byte[] qid, Json_nde nde, int pid) {
|
||||
|
||||
Reference in New Issue
Block a user