mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-02 07:24:19 +00:00
Hdump: Add missing Xoh_hdump_wkr [#584]
This commit is contained in:
parent
1caeea5705
commit
742e61b718
22
400_xowa/src/gplx/xowa/htmls/hdumps/Xoh_hdump_wkr.java
Normal file
22
400_xowa/src/gplx/xowa/htmls/hdumps/Xoh_hdump_wkr.java
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
public interface Xoh_hdump_wkr {
|
||||
byte[] Key();
|
||||
int Process(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Xoh_hdoc_wkr hdoc_wkr, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag tag);
|
||||
}
|
32
400_xowa/src/gplx/xowa/htmls/hdumps/Xoh_hdump_wkr_utl.java
Normal file
32
400_xowa/src/gplx/xowa/htmls/hdumps/Xoh_hdump_wkr_utl.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.htmls.docs.*;
|
||||
public class Xoh_hdump_wkr_utl {
|
||||
public static void Write_tag_with_val_at_atr_bgn(Bry_bfr bfr, byte[] src, Gfh_tag tag, Gfh_atr atr, byte[] val) {
|
||||
// utility method to write tag, but put "val" at start of atr
|
||||
// EX: val="VAL_" tag="<img id='1' src='b.png' title='c'/>" -> "<img id='1' src='VAL_.png' title='c'/>"
|
||||
bfr.Add_mid(src, tag.Src_bgn(), atr.Val_bgn()); // add bgn of tag
|
||||
if (val != null)
|
||||
bfr.Add(val); // add "val"
|
||||
bfr.Add(atr.Val()); // add atr.val
|
||||
bfr.Add_mid(src, atr.Val_end(), tag.Src_end()); // add end of tag
|
||||
}
|
||||
public static byte[] Build_hdump_atr(byte[] key) {
|
||||
return Bry_.Add(Bry__data_xowa_hdump, key, Byte_ascii.Apos_bry);
|
||||
}
|
||||
private static final byte[] Bry__data_xowa_hdump = Bry_.new_a7("data-xowa-hdump='");
|
||||
}
|
@ -14,15 +14,20 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.parsers.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Mwh_atr_mgr_tst {
|
||||
private final Mwh_atr_mgr_fxt fxt = new Mwh_atr_mgr_fxt();
|
||||
@Test public void Atr_utl_make() {
|
||||
private final Mwh_atr_mgr_fxt fxt = new Mwh_atr_mgr_fxt();
|
||||
@Test public void Atr_utl_make() {
|
||||
// key="val"
|
||||
fxt.Test_atr_utl_make(Mwh_atr_itm_.Qte_tid__qute, Mwh_atr_itm_.Mask__valid__y, Mwh_atr_itm_.Mask__repeated__n, Mwh_atr_itm_.Mask__key_exists__y, Mwh_atr_itm_.Mask__val_made__n, 42);
|
||||
// key=val key=v<nowiki/>al
|
||||
fxt.Test_atr_utl_make(Mwh_atr_itm_.Qte_tid__none, Mwh_atr_itm_.Mask__valid__y, Mwh_atr_itm_.Mask__repeated__y, Mwh_atr_itm_.Mask__key_exists__y, Mwh_atr_itm_.Mask__val_made__y, 120);
|
||||
}
|
||||
@Test public void Resize() {
|
||||
Mwh_atr_mgr atr_mgr = new Mwh_atr_mgr(1);
|
||||
atr_mgr.Add(0, 1, true, true, true, 2, 3, 4, 5, Bry_.Empty, 0, 0, 0, 0, Bry_.Empty);
|
||||
atr_mgr.Add(1, 0, true, true, true, 0, 0, 0, 0, Bry_.Empty, 0, 0, 0, 0, Bry_.Empty);
|
||||
}
|
||||
}
|
||||
class Mwh_atr_mgr_fxt {
|
||||
public void Test_atr_utl_make(int qte_tid, boolean valid, boolean repeated, boolean key_exists, boolean val_made, int expd) {
|
||||
|
@ -38,7 +38,7 @@ class Mwh_doc_mgr {
|
||||
if (data_idx == data_max) {
|
||||
int new_data_max = data_max == 0 ? Idx__mult : data_max * 2;
|
||||
int[] new_data_ary = new int[new_data_max];
|
||||
Int_ary_.Copy_to(data_ary, data_max, data_ary);
|
||||
Int_ary_.Copy_to(data_ary, data_max, new_data_ary);
|
||||
this.data_ary = new_data_ary;
|
||||
this.data_max = new_data_max;
|
||||
}
|
||||
|
@ -1,95 +0,0 @@
|
||||
[1mdiff --git a/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java b/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java[m
|
||||
[1mindex f6d1ef3..97fdf7f 100644[m
|
||||
[1m--- a/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java[m
|
||||
[1m+++ b/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java[m
|
||||
[36m@@ -19,50 +19,55 @@[m [mimport gplx.langs.jsons.*;[m
|
||||
import gplx.xowa.langs.*;[m
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.parsers.*;[m
|
||||
public class Wdata_doc {[m
|
||||
[31m- private Wdata_wiki_mgr mgr; private Int_obj_ref tmp_key;[m
|
||||
[31m- public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc jdoc) {this.qid = qid; this.mgr = mgr; this.jdoc = jdoc;}[m
|
||||
[31m- public Wdata_doc(byte[] qid, Ordered_hash slink_list, Ordered_hash label_list, Ordered_hash descr_list, Ordered_hash alias_list, Ordered_hash claim_list) { // TEST[m
|
||||
[31m- this.qid = qid;[m
|
||||
[31m- this.slink_list = slink_list; this.label_list = label_list; this.descr_list = descr_list; this.alias_list = alias_list; this.claim_list = claim_list;[m
|
||||
[32m+[m [32mprivate final Wdata_wiki_mgr mgr;[m[41m
[m
|
||||
[32m+[m [32mpublic Wdata_doc(Wdata_wiki_mgr mgr, Json_doc jdoc, byte[] qid) {[m[41m
[m
|
||||
[32m+[m [32mthis.mgr = mgr; this.jdoc = jdoc; this.qid = qid;[m[41m
[m
|
||||
}[m
|
||||
[31m- public Json_doc Jdoc() {return jdoc;} private Json_doc jdoc;[m
|
||||
[32m+[m [32mpublic byte[] Qid() {return qid;} private final byte[] qid;[m[41m
[m
|
||||
[32m+[m [32mpublic Json_doc Jdoc() {return jdoc;} private final Json_doc jdoc;[m[41m
[m
|
||||
public int Jdoc_size() {return jdoc == null ? 1 : jdoc.Src().length;}[m
|
||||
[31m- public byte[] Qid() {return qid;} private byte[] qid;[m
|
||||
public byte[][] Sort_langs() {return sort_langs;} public void Sort_langs_(byte[][] v) {sort_langs = v;} private byte[][] sort_langs = Bry_.Ary_empty;[m
|
||||
[31m- public Ordered_hash Slink_list() {if (slink_list == null) slink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return slink_list;} private Ordered_hash slink_list;[m
|
||||
[31m- public Ordered_hash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private Ordered_hash label_list;[m
|
||||
[31m- public Ordered_hash Descr_list() {if (descr_list == null) descr_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return descr_list;} private Ordered_hash descr_list;[m
|
||||
[31m- public Ordered_hash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private Ordered_hash alias_list;[m
|
||||
[31m- public Ordered_hash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(qid, jdoc); return claim_list;} private Ordered_hash claim_list;[m
|
||||
[31m- public Wbase_claim_grp Claim_list_get(int pid) {[m
|
||||
[31m- if (tmp_key == null) tmp_key = Int_obj_ref.New_neg1(); [m
|
||||
[31m- Object o = this.Claim_list().Get_by(tmp_key.Val_(pid));[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// NOTE: lazy instantiation b/c we don't want to parse entire json unless called; particulary necessary for {{#property}} calls;[m[41m
[m
|
||||
[32m+[m [32mpublic Ordered_hash Slink_list() {if (slink_list == null) slink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return slink_list;} private Ordered_hash slink_list;[m[41m
[m
|
||||
[32m+[m [32mpublic Ordered_hash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private Ordered_hash label_list;[m[41m
[m
|
||||
[32m+[m [32mpublic Ordered_hash Descr_list() {if (descr_list == null) descr_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return descr_list;} private Ordered_hash descr_list;[m[41m
[m
|
||||
[32m+[m [32mpublic Ordered_hash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private Ordered_hash alias_list;[m[41m
[m
|
||||
[32m+[m [32mpublic Ordered_hash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(qid, jdoc); return claim_list;} private Ordered_hash claim_list;[m[41m
[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// various getters[m[41m
[m
|
||||
[32m+[m [32mpublic Wbase_claim_grp Get_claim_grp_or_null(int pid) {[m[41m
[m
|
||||
[32m+[m [32mObject o = this.Claim_list().Get_by(Int_obj_ref.New(pid));[m[41m
[m
|
||||
return (Wbase_claim_grp)o;[m
|
||||
[31m- } [m
|
||||
[31m- public byte[] Label_list__get(byte[] lang_key) {return Lang_text_list__get(this.Label_list(), lang_key);}[m
|
||||
[31m- public byte[] Label_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Label_list(), lang);}[m
|
||||
[31m- public byte[] Descr_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Descr_list(), lang);}[m
|
||||
[31m- public byte[] Slink_list__get_or_fallback(byte[] abrv_wm) {[m
|
||||
[31m- Wdata_sitelink_itm rv = (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);[m
|
||||
[31m- return rv == null ? null : rv.Name();[m
|
||||
}[m
|
||||
[31m- private byte[] Lang_text_list__get(Ordered_hash hash, byte[] lang_key) {[m
|
||||
[31m- Object rv_obj = hash.Get_by(lang_key); if (rv_obj == null) return null;[m
|
||||
[31m- Wdata_langtext_itm rv = (Wdata_langtext_itm)rv_obj;[m
|
||||
[31m- return rv.Text();[m
|
||||
[32m+[m [32mpublic byte[] Get_label_bry_or_null(byte[] lang_key) {[m[41m
[m
|
||||
[32m+[m [32mWdata_langtext_itm itm = (Wdata_langtext_itm)this.Label_list().Get_by(lang_key);[m[41m
[m
|
||||
[32m+[m [32mreturn itm == null ? null : itm.Text();[m[41m
[m
|
||||
}[m
|
||||
[31m- public byte[] Lang_text_list__get_or_fallback(Ordered_hash lang_text_list, Xol_lang_itm lang) {[m
|
||||
[31m- byte[] rv = Lang_text_list__get(lang_text_list, lang.Key_bry()); if (rv != null) return rv;[m
|
||||
[31m- byte[][] ary = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang_itm[m
|
||||
[31m- int len = ary.length;[m
|
||||
[31m- for (int i = 0; i < len; ++i) {[m
|
||||
[31m- byte[] lang_key = ary[i];[m
|
||||
[31m- Object itm_obj = lang_text_list.Get_by(lang_key);[m
|
||||
[32m+[m [32mpublic Wdata_langtext_itm Get_label_itm_or_null(Xol_lang_itm lang) {return Get_langtext_itm_or_null(this.Label_list(), lang);}[m[41m
[m
|
||||
[32m+[m [32mpublic Wdata_langtext_itm Get_descr_itm_or_null(Xol_lang_itm lang) {return Get_langtext_itm_or_null(this.Descr_list(), lang);}[m[41m
[m
|
||||
[32m+[m [32mpublic Wdata_sitelink_itm Get_slink_itm_or_null(byte[] abrv_wm) {return (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);}[m[41m
[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// helper method[m[41m
[m
|
||||
[32m+[m [32mprivate Wdata_langtext_itm Get_langtext_itm_or_null(Ordered_hash hash, Xol_lang_itm lang) {[m[41m
[m
|
||||
[32m+[m [32m// get itm by lang's key[m[41m
[m
|
||||
[32m+[m [32mWdata_langtext_itm itm = (Wdata_langtext_itm)hash.Get_by(lang.Key_bry());[m[41m
[m
|
||||
[32m+[m [32mif (itm != null) return itm;[m[41m
[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// loop over fallback_langs[m[41m
[m
|
||||
[32m+[m [32mbyte[][] fallback_langs = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang_itm[m[41m
[m
|
||||
[32m+[m [32mint len = fallback_langs.length;[m[41m
[m
|
||||
[32m+[m [32mfor (int i = 0; i < len; i++) {[m[41m
[m
|
||||
[32m+[m [32mbyte[] lang_key = fallback_langs[i];[m[41m
[m
|
||||
[32m+[m [32mObject itm_obj = hash.Get_by(lang_key);[m[41m
[m
|
||||
if (itm_obj != null) {[m
|
||||
[31m- Wdata_langtext_itm itm = (Wdata_langtext_itm)itm_obj;[m
|
||||
[31m- return itm.Text();[m
|
||||
[32m+[m [32mreturn (Wdata_langtext_itm)itm_obj;[m[41m
[m
|
||||
}[m
|
||||
}[m
|
||||
return null;[m
|
||||
}[m
|
||||
[32m+[m [32mpublic Wdata_doc Ctor_by_test(Ordered_hash slink_list, Ordered_hash label_list, Ordered_hash descr_list, Ordered_hash alias_list, Ordered_hash claim_list) {// TEST[m[41m
[m
|
||||
[32m+[m [32mthis.slink_list = slink_list; this.label_list = label_list; this.descr_list = descr_list; this.alias_list = alias_list; this.claim_list = claim_list;[m[41m
[m
|
||||
[32m+[m [32mreturn this;[m[41m
[m
|
||||
[32m+[m [32m}[m[41m
[m
|
||||
}[m
|
Loading…
Reference in New Issue
Block a user