mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.1.1
This commit is contained in:
31
400_xowa/src/gplx/xowa/xtns/cites/Cite_xtn_mgr.java
Normal file
31
400_xowa/src/gplx/xowa/xtns/cites/Cite_xtn_mgr.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Cite_xtn_mgr extends Xox_mgr_base {
|
||||
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("cite");
|
||||
// public byte[] Group_default_name() {return group_default_name;} private byte[] group_default_name = Bry_.new_a7("lower-alpha");
|
||||
public static byte[] Group_default_name() {return group_default_name;} private static byte[] group_default_name = Bry_.new_a7("lower-alpha");
|
||||
@Override public Xox_mgr Clone_new() {return new Cite_xtn_mgr();}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_group_default_name)) return String_.new_u8(group_default_name);
|
||||
else if (ctx.Match(k, Invk_group_default_name_)) group_default_name = m.ReadBry("v");
|
||||
else return super.Invk(ctx, ikey, k, m);
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_group_default_name = "group_default_name", Invk_group_default_name_ = "group_default_name_";
|
||||
}
|
||||
151
400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr.java
Normal file
151
400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr.java
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*; import gplx.core.brys.args.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
|
||||
public class Ref_html_wtr {
|
||||
public Ref_html_wtr(Xowe_wiki wiki) {
|
||||
cfg = Ref_html_wtr_cfg.new_();
|
||||
}
|
||||
public void Xnde_ref(Xoh_wtr_ctx opts, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
Ref_nde itm = (Ref_nde)xnde.Xnde_xtn();
|
||||
if (itm == null) return;
|
||||
if (itm.Follow_y()) return; // NOTE: "follow" is always appended to preceding ref; will never generate its own ^ a
|
||||
byte[] itm_group = itm.Group();
|
||||
boolean itm_group_is_default = Bry_.Eq(itm_group, Bry_.Empty) || Bry_.Eq(itm_group, Cite_xtn_mgr.Group_default_name()); // do not show "lower-alpha"; PAGE:en.w:Moon; DATE:2014-07-21
|
||||
cfg.Itm_html().Bld_bfr_many(bfr
|
||||
, Itm_id(itm, true)
|
||||
, Grp_id(itm)
|
||||
, itm_group_is_default
|
||||
? itm.Idx_major() + 1
|
||||
: (Object)grp_key_fmtr.Set(cfg.Itm_grp_text(), itm.Group(), itm.Idx_major() + 1)
|
||||
);
|
||||
} private Bfr_arg__bry_fmtr grp_key_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
public Ref_html_wtr_cfg Cfg() {return cfg;} private Ref_html_wtr_cfg cfg;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
cfg.Init_by_wiki(wiki);
|
||||
}
|
||||
private Bfr_arg Itm_id(Ref_nde itm, boolean caller_is_ref) {
|
||||
if (itm.Name() == Bry_.Empty)
|
||||
return itm_id_fmtr.Set(cfg.Itm_id_uid(), itm.Uid());
|
||||
else {
|
||||
if (caller_is_ref)
|
||||
return itm_id_fmtr.Set(cfg.Itm_id_key_one(), itm.Name(), itm.Idx_major(), itm.Idx_minor());
|
||||
else
|
||||
return itm_id_fmtr.Set(cfg.Itm_id_key_many(), itm.Name(), itm.Idx_major());
|
||||
}
|
||||
} private Bfr_arg__bry_fmtr itm_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
private Bfr_arg Grp_id(Ref_nde itm) {
|
||||
return itm.Name() == Bry_.Empty // name is blank >>> uid
|
||||
? grp_id_fmtr.Set(cfg.Grp_id_uid(), itm.Uid())
|
||||
: grp_id_fmtr.Set(cfg.Grp_id_key(), itm.Name(), itm.Idx_major());
|
||||
} private Bfr_arg__bry_fmtr grp_id_fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
private int List_len(Ref_nde itm) {
|
||||
int len = itm.Related_len();
|
||||
int rv = len;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Ref_nde list_itm = itm.Related_get(i);
|
||||
if (list_itm.Nested()) --rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Xnde_references(Xoh_html_wtr wtr, Xop_ctx ctx, Xoh_wtr_ctx opts, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
References_nde references = (References_nde)xnde.Xnde_xtn();
|
||||
Ref_itm_lst lst = ctx.Cur_page().Ref_mgr().Lst_get(references.Group(), references.List_idx()); // get group; EX: <references group="note"/>
|
||||
if (lst == null) return; // NOTE: possible to have a grouped references without references; EX: Infobox planet; <references group=note> in sidebar, but no refs
|
||||
if (lst.Itms_len() == 0) return;
|
||||
bfr.Add(cfg.Grp_bgn());
|
||||
int itms_len = lst.Itms_len();
|
||||
for (int j = 0; j < itms_len; j++) { // iterate over itms in grp
|
||||
Ref_nde head_itm = lst.Itms_get_at(j);
|
||||
Bry_bfr tmp = Bry_bfr.new_();
|
||||
int list_len = List_len(head_itm);
|
||||
grp_list_fmtr.Init(ctx.Wiki(), cfg, head_itm);
|
||||
Ref_nde text_itm = grp_list_fmtr.IdentifyTxt(); // find the item that has the text (there should only be 0 or 1)
|
||||
if (text_itm.Body() != null)
|
||||
wtr.Write_tkn(tmp, ctx, opts, text_itm.Body().Root_src(), null, Xoh_html_wtr.Sub_idx_null, text_itm.Body());
|
||||
|
||||
// add follows
|
||||
int related_len = head_itm.Related_len();
|
||||
for (int k = 0; k < related_len; k++) {
|
||||
Ref_nde related_itm = head_itm.Related_get(k);
|
||||
if (related_itm.Follow_y()) { // NOTE: both follow and related are in the related list; only add follow
|
||||
tmp.Add_byte_space(); // always add space; REF.MW:Cite_body.php;$this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' ' . $str;
|
||||
wtr.Write_tkn(tmp, ctx, opts, related_itm.Body().Root_src(), null, Xoh_html_wtr.Sub_idx_null, related_itm.Body());
|
||||
}
|
||||
}
|
||||
|
||||
if (list_len == 0) { // ref has 0 list_itms or 1 list_itm but nested; EX: "123 ^ text"
|
||||
cfg.Grp_html_one().Bld_bfr_many(bfr
|
||||
, Grp_id(head_itm) // NOTE: use head_itm for back ref to work (^ must link to same id)
|
||||
, Itm_id(head_itm, true)
|
||||
, tmp
|
||||
);
|
||||
}
|
||||
else { // ref has 1+ itms; EX: "123 ^ a b c text"
|
||||
cfg.Grp_html_many().Bld_bfr_many(bfr
|
||||
, Itm_id(text_itm, false)
|
||||
, grp_list_fmtr
|
||||
, tmp
|
||||
);
|
||||
}
|
||||
}
|
||||
bfr.Add(cfg.Grp_end());
|
||||
}
|
||||
private static Xoh_ref_list_fmtr grp_list_fmtr = new Xoh_ref_list_fmtr();
|
||||
}
|
||||
class Xoh_ref_list_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
public void Init(Xowe_wiki wiki, Ref_html_wtr_cfg cfg, Ref_nde itm) {
|
||||
this.wiki = wiki; this.cfg = cfg; this.itm = itm;
|
||||
} private Xowe_wiki wiki; private Ref_nde itm; private Ref_html_wtr_cfg cfg;
|
||||
public Ref_nde IdentifyTxt() {
|
||||
if (HasTxt(itm)) return itm;
|
||||
int itm_related_len = itm.Related_len();
|
||||
for (int i = 0; i < itm_related_len; i++) {
|
||||
Ref_nde rel = itm.Related_get(i);
|
||||
if (HasTxt(rel)) return rel;
|
||||
}
|
||||
return itm; // no itm has text; TODO:WARN
|
||||
}
|
||||
private boolean HasTxt(Ref_nde v) {return v.Body() != null && v.Body().Root_src().length > 0;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int related_len = itm.Related_len();
|
||||
Bry_fmtr itm_fmtr = cfg.Grp_html_list();
|
||||
Fmt(itm_fmtr, wiki, bfr, itm);
|
||||
for (int i = 0; i < related_len; i++) {
|
||||
Ref_nde link_itm = itm.Related_get(i);
|
||||
if (link_itm.Nested()) continue;
|
||||
Fmt(itm_fmtr, wiki, bfr, link_itm);
|
||||
}
|
||||
}
|
||||
private void Fmt(Bry_fmtr itm_fmtr, Xowe_wiki wiki, Bry_bfr trg, Ref_nde itm) {
|
||||
int itm_idx_minor = itm.Idx_minor();
|
||||
if (itm_idx_minor < 0) return; // HACK: <ref follow created a negative index; ignore these references for now; de.wikisource.org/wiki/Seite:Die Trunksucht.pdf/63; DATE:2013-06-22
|
||||
byte[] backlabel
|
||||
= itm_idx_minor < cfg.Backlabels_len()
|
||||
? cfg.Backlabels()[itm.Idx_minor()]
|
||||
: wiki.Parser_mgr().Main().Parse_text_to_html(wiki.Parser_mgr().Ctx(), wiki.Msg_mgr().Val_by_key_args(Ref_html_wtr_cfg.Msg_backlabels_err, itm.Idx_minor()))
|
||||
;
|
||||
itm_fmtr.Bld_bfr_many(trg
|
||||
, fmtr.Set(cfg.Itm_id_key_one(), itm.Name(), itm.Idx_major(), itm.Idx_minor())
|
||||
, backlabel
|
||||
);
|
||||
}
|
||||
private Bfr_arg__bry_fmtr fmtr = Bfr_arg_.New_bry_fmtr__null();
|
||||
}
|
||||
122
400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr_cfg.java
Normal file
122
400_xowa/src/gplx/xowa/xtns/cites/Ref_html_wtr_cfg.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
public class Ref_html_wtr_cfg {
|
||||
public Bry_fmtr Itm_html() {return itm_html;} private Bry_fmtr itm_html; public Ref_html_wtr_cfg Itm_html_(String v) {itm_html = Bry_fmtr.new_(v, "itm_id", "grp_id", "grp_key"); return this;}
|
||||
public Bry_fmtr Itm_id_uid() {return itm_id_uid;} private Bry_fmtr itm_id_uid; public Ref_html_wtr_cfg Itm_id_uid_(String v) {itm_id_uid = Bry_fmtr.new_(v, "uid"); return this;}
|
||||
public Bry_fmtr Itm_id_key_one() {return itm_id_key_one;} private Bry_fmtr itm_id_key_one; public Ref_html_wtr_cfg Itm_id_key_one_(String v) {itm_id_key_one = Bry_fmtr.new_(v, "itm_key", "uid", "minor"); return this;}
|
||||
public Bry_fmtr Itm_id_key_many() {return itm_id_key_many;} private Bry_fmtr itm_id_key_many; public Ref_html_wtr_cfg Itm_id_key_many_(String v) {itm_id_key_many = Bry_fmtr.new_(v, "itm_key", "uid"); return this;}
|
||||
public Bry_fmtr Itm_grp_text() {return itm_grp_text;} private Bry_fmtr itm_grp_text; public Ref_html_wtr_cfg Itm_grp_text_(String v) {itm_grp_text = Bry_fmtr.new_(v, "grp_key", "major"); return this;}
|
||||
public Bry_fmtr Grp_html_one() {return grp_html_one;} private Bry_fmtr grp_html_one; public Ref_html_wtr_cfg Grp_html_one_(String v) {grp_html_one = Bry_fmtr.new_(v, "grp_id", "itm_id", "text"); return this;}
|
||||
public Bry_fmtr Grp_html_many() {return grp_html_many;} private Bry_fmtr grp_html_many; public Ref_html_wtr_cfg Grp_html_many_(String v) {grp_html_many = Bry_fmtr.new_(v, "grp_id", "related_ids", "text"); return this;}
|
||||
public Bry_fmtr Grp_html_list() {return grp_html_list;} private Bry_fmtr grp_html_list; public Ref_html_wtr_cfg Grp_html_list_(String v) {grp_html_list = Bry_fmtr.new_(v, "itm_id", "backlabel"); return this;}
|
||||
public Bry_fmtr Grp_id_uid() {return grp_id_uid;} private Bry_fmtr grp_id_uid; public Ref_html_wtr_cfg Grp_id_uid_(String v) {grp_id_uid = Bry_fmtr.new_(v, "uid"); return this;}
|
||||
public Bry_fmtr Grp_id_key() {return grp_id_key;} private Bry_fmtr grp_id_key; public Ref_html_wtr_cfg Grp_id_key_(String v) {grp_id_key = Bry_fmtr.new_(v, "itm_key", "major"); return this;}
|
||||
public byte[][] Backlabels() {return backlabels;} private byte[][] backlabels;
|
||||
public int Backlabels_len() {return backlabels_len;} private int backlabels_len;
|
||||
public byte[] Grp_bgn() {return grp_bgn;} private byte[] grp_bgn;
|
||||
public byte[] Grp_end() {return grp_end;} private byte[] grp_end;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
byte[] backlabels_bry = wiki.Msg_mgr().Val_by_key_obj(Msg_backlabels);
|
||||
Backlabels_(Ref_backlabels_xby_bry(backlabels_bry));
|
||||
}
|
||||
public void Backlabels_(byte[][] v) {
|
||||
backlabels = v;
|
||||
backlabels_len = v.length;
|
||||
}
|
||||
public static final byte[] Msg_backlabels_err = Bry_.new_a7("cite_error_no_link_label_group");
|
||||
private static final byte[] Msg_backlabels = Bry_.new_a7("cite_references_link_many_format_backlink_labels");
|
||||
public static Ref_html_wtr_cfg new_() {
|
||||
Ref_html_wtr_cfg rv = new Ref_html_wtr_cfg();
|
||||
rv.Itm_html_ ("<sup id=\"cite_ref-~{itm_id}\" class=\"reference\"><a href=\"#cite_note-~{grp_id}\">[~{grp_key}]</a></sup>");
|
||||
rv.Itm_id_uid_ ("~{uid}");
|
||||
rv.Itm_id_key_one_ ("~{itm_key}_~{uid}-~{minor}");
|
||||
rv.Itm_id_key_many_ ("~{itm_key}-~{uid}");
|
||||
rv.Itm_grp_text_ ("~{grp_key} ~{major}");
|
||||
rv.Grp_html_one_ ("<li id=\"cite_note-~{grp_id}\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-~{itm_id}\">^</a></span> <span class=\"reference-text\">~{text}</span></li>\n");
|
||||
rv.Grp_html_many_ ("<li id=\"cite_note-~{grp_id}\"><span class=\"mw-cite-backlink\">^~{related_ids}</span> <span class=\"reference-text\">~{text}</span></li>\n");
|
||||
rv.Grp_html_list_ (" <sup><a href=\"#cite_ref-~{itm_id}\">~{backlabel}</a></sup>");
|
||||
rv.Grp_id_uid_ ("~{uid}");
|
||||
rv.Grp_id_key_ ("~{itm_key}-~{major}");
|
||||
rv.grp_bgn = Bry_.new_a7("<ol class=\"references\">\n");
|
||||
rv.grp_end = Bry_.new_a7("</ol>\n");
|
||||
rv.Backlabels_ (Ref_backlabels_default);
|
||||
return rv;
|
||||
} Ref_html_wtr_cfg() {}
|
||||
private static final byte[][] Ref_backlabels_default = Ref_backlabels_xby_str_ary(String_.Ary // TEST:default backlabels for test only; actual backlabels will be overrriden by MediaWiki:Cite_references_link_many_format_backlink_labels; DATE:2014-06-07
|
||||
( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
|
||||
, "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az"
|
||||
, "ba", "bb", "bc", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bk", "bl", "bm", "bn", "bo", "bp", "bq", "br", "bs", "bt", "bu", "bv", "bw", "bx", "by", "bz"
|
||||
, "ca", "cb", "cc", "cd", "ce", "cf", "cg", "ch", "ci", "cj", "ck", "cl", "cm", "cn", "co", "cp", "cq", "cr", "cs", "ct", "cu", "cv", "cw", "cx", "cy", "cz"
|
||||
, "da", "db", "dc", "dd", "de", "df", "dg", "dh", "di", "dj", "dk", "dl", "dm", "dn", "do", "dp", "dq", "dr", "ds", "dt", "du", "dv", "dw", "dx", "dy", "dz"
|
||||
, "ea", "eb", "ec", "ed", "ee", "ef", "eg", "eh", "ei", "ej", "ek", "el", "em", "en", "eo", "ep", "eq", "er", "es", "et", "eu", "ev", "ew", "ex", "ey", "ez"
|
||||
, "fa", "fb", "fc", "fd", "fe", "ff", "fg", "fh", "fi", "fj", "fk", "fl", "fm", "fn", "fo", "fp", "fq", "fr", "fs", "ft", "fu", "fv", "fw", "fx", "fy", "fz"
|
||||
, "ga", "gb", "gc", "gd", "ge", "gf", "gg", "gh", "gi", "gj", "gk", "gl", "gm", "gn", "go", "gp", "gq", "gr", "gs", "gt", "gu", "gv", "gw", "gx", "gy", "gz"
|
||||
, "ha", "hb", "hc", "hd", "he", "hf", "hg", "hh", "hi", "hj", "hk", "hl", "hm", "hn", "ho", "hp", "hq", "hr", "hs", "ht", "hu", "hv", "hw", "hx", "hy", "hz"
|
||||
, "ia", "ib", "ic", "id", "ie", "if", "ig", "ih", "ii", "ij", "ik", "il", "im", "in", "io", "ip", "iq", "ir", "is", "it", "iu", "iv", "iw", "ix", "iy", "iz"
|
||||
, "ja", "jb", "jc", "jd", "je", "jf", "jg", "jh", "ji", "jj", "jk", "jl", "jm", "jn", "jo", "jp", "jq", "jr", "js", "jt", "ju", "jv", "jw", "jx", "jy", "jz"
|
||||
, "ka", "kb", "kc", "kd", "ke", "kf", "kg", "kh", "ki", "kj", "kk", "kl", "km", "kn", "ko", "kp", "kq", "kr", "ks", "kt", "ku", "kv", "kw", "kx", "ky", "kz"
|
||||
, "la", "lb", "lc", "ld", "le", "lf", "lg", "lh", "li", "lj", "lk", "ll", "lm", "ln", "lo", "lp", "lq", "lr", "ls", "lt", "lu", "lv", "lw", "lx", "ly", "lz"
|
||||
, "ma", "mb", "mc", "md", "me", "mf", "mg", "mh", "mi", "mj", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz"
|
||||
, "na", "nb", "nc", "nd", "ne", "nf", "ng", "nh", "ni", "nj", "nk", "nl", "nm", "nn", "no", "np", "nq", "nr", "ns", "nt", "nu", "nv", "nw", "nx", "ny", "nz"
|
||||
, "oa", "ob", "oc", "od", "oe", "of", "og", "oh", "oi", "oj", "ok", "ol", "om", "on", "oo", "op", "oq", "or", "os", "ot", "ou", "ov", "ow", "ox", "oy", "oz"
|
||||
, "pa", "pb", "pc", "pd", "pe", "pf", "pg", "ph", "pi", "pj", "pk", "pl", "pm", "pn", "po", "pp", "pq", "pr", "ps", "pt", "pu", "pv", "pw", "px", "py", "pz"
|
||||
, "qa", "qb", "qc", "qd", "qe", "qf", "qg", "qh", "qi", "qj", "qk", "ql", "qm", "qn", "qo", "qp", "qq", "qr", "qs", "qt", "qu", "qv", "qw", "qx", "qy", "qz"
|
||||
, "ra", "rb", "rc", "rd", "re", "rf", "rg", "rh", "ri", "rj", "rk", "rl", "rm", "rn", "ro", "rp", "rq", "rr", "rs", "rt", "ru", "rv", "rw", "rx", "ry", "rz"
|
||||
, "sa", "sb", "sc", "sd", "se", "sf", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sp", "sq", "sr", "ss", "st", "su", "sv", "sw", "sx", "sy", "sz"
|
||||
, "ta", "tb", "tc", "td", "te", "tf", "tg", "th", "ti", "tj", "tk", "tl", "tm", "tn", "to", "tp", "tq", "tr", "ts", "tt", "tu", "tv", "tw", "tx", "ty", "tz"
|
||||
, "ua", "ub", "uc", "ud", "ue", "uf", "ug", "uh", "ui", "uj", "uk", "ul", "um", "un", "uo", "up", "uq", "ur", "us", "ut", "uu", "uv", "uw", "ux", "uy", "uz"
|
||||
, "va", "vb", "vc", "vd", "ve", "vf", "vg", "vh", "vi", "vj", "vk", "vl", "vm", "vn", "vo", "vp", "vq", "vr", "vs", "vt", "vu", "vv", "vw", "vx", "vy", "vz"
|
||||
, "wa", "wb", "wc", "wd", "we", "wf", "wg", "wh", "wi", "wj", "wk", "wl", "wm", "wn", "wo", "wp", "wq", "wr", "ws", "wt", "wu", "wv", "ww", "wx", "wy", "wz"
|
||||
, "xa", "xb", "xc", "xd", "xe", "xf", "xg", "xh", "xi", "xj", "xk", "xl", "xm", "xn", "xo", "xp", "xq", "xr", "xs", "xt", "xu", "xv", "xw", "xx", "xy", "xz"
|
||||
, "ya", "yb", "yc", "yd", "ye", "yf", "yg", "yh", "yi", "yj", "yk", "yl", "ym", "yn", "yo", "yp", "yq", "yr", "ys", "yt", "yu", "yv", "yw", "yx", "yy", "yz"
|
||||
, "za", "zb", "zc", "zd", "ze", "zf", "zg", "zh", "zi", "zj", "zk", "zl", "zm", "zn", "zo", "zp", "zq", "zr", "zs", "zt", "zu", "zv", "zw", "zx", "zy", "zz"
|
||||
));
|
||||
private static byte[][] Ref_backlabels_xby_str_ary(String[] ary) {
|
||||
int ary_len = ary.length;
|
||||
byte[][] rv = new byte[ary_len][];
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
rv[i] = Bry_.new_a7(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static byte[][] Ref_backlabels_xby_bry(byte[] raw) {
|
||||
if (raw == null) return Ref_backlabels_default;
|
||||
List_adp list = List_adp_.new_();
|
||||
int len = raw.length, pos = 0, bgn = -1;
|
||||
while (true) {
|
||||
boolean last = pos == len;
|
||||
byte b = last ? Byte_ascii.Space : raw[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Nl: case Byte_ascii.Tab:
|
||||
if (bgn != -1) { // guard against leading ws, or multiple ws; EX: "bos\s\s" or "\s\s"
|
||||
list.Add(Bry_.Mid(raw, bgn, pos));
|
||||
bgn = -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (bgn == -1)
|
||||
bgn = pos;
|
||||
break;
|
||||
}
|
||||
if (last) break;
|
||||
++pos;
|
||||
}
|
||||
return (byte[][])list.To_ary_and_clear(byte[].class);
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_grp.java
Normal file
50
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_grp.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_grp {
|
||||
private List_adp lsts = List_adp_.new_();
|
||||
public Ref_itm_grp(byte[] grp_name) {this.grp_name = grp_name;}
|
||||
public byte[] Grp_name() {return grp_name;} private byte[] grp_name;
|
||||
public int Grp_seal() {
|
||||
if (lst_idx == lsts.Count()) // NOTE: lst_idx == lsts.Count() if there are no itms in lst; need to add placeholder list anyway; <references> nodes has a List_index, which will call lsts.Get_at(); see Empty_group_before_ref
|
||||
lsts.Add(new Ref_itm_lst(grp_name));
|
||||
return lst_idx++;
|
||||
} int lst_idx;
|
||||
public int Lsts_len() {return lsts.Count();}
|
||||
public Ref_itm_lst Lsts_get_at(int i) {return i < lsts.Count() ? (Ref_itm_lst)lsts.Get_at(i) : null;} // NOTE: null can be returned; see Infobox planet; w:Mars
|
||||
public void Lsts_add(byte[] itm_name, byte[] follow, Ref_nde itm) {
|
||||
Ref_itm_lst lst = null;
|
||||
int lsts_len = lsts.Count();
|
||||
if (lst_idx >= lsts_len) {
|
||||
lst = new Ref_itm_lst(grp_name);
|
||||
lsts.Add(lst);
|
||||
}
|
||||
else
|
||||
lst = (Ref_itm_lst)lsts.Get_at(lsts_len - 1);
|
||||
lst.Itms_add(itm_name, follow, itm);
|
||||
}
|
||||
public void Lsts_clear() {
|
||||
int lsts_len = lsts.Count();
|
||||
for (int i = 0; i < lsts_len; i++) {
|
||||
Ref_itm_lst lst = (Ref_itm_lst)lsts.Get_at(i);
|
||||
lst.Itms_clear();
|
||||
}
|
||||
lsts.Clear();
|
||||
lst_idx = 0;
|
||||
}
|
||||
}
|
||||
63
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_lst.java
Normal file
63
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_lst.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_lst {
|
||||
public Ref_itm_lst(byte[] grp_name) {this.grp_name = grp_name;}
|
||||
byte[] grp_name; int idx_major_last = 0;
|
||||
public int Itms_len() {return list.Count();}
|
||||
public Ref_nde Itms_get_at(int i) {return (Ref_nde)list.Get_at(i);}
|
||||
public void Itms_add(byte[] itm_name, byte[] follow, Ref_nde itm) {
|
||||
if (itm_name == Bry_.Empty) {
|
||||
if (follow == Bry_.Empty) {
|
||||
itm.Idx_major_(idx_major_last++);
|
||||
list.Add(itm);
|
||||
}
|
||||
else {
|
||||
Object o = hash.Get_by(follow);
|
||||
if (o == null) {// fail
|
||||
}
|
||||
else {
|
||||
Ref_nde head = (Ref_nde)o;
|
||||
head.Related_add(itm, Ref_nde.Idx_minor_follow);
|
||||
itm.Idx_major_(head.Idx_major());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object o = hash.Get_by(itm_name);
|
||||
if (o == null) {
|
||||
hash.Add(itm_name, itm);
|
||||
itm.Idx_major_(idx_major_last++);
|
||||
list.Add(itm);
|
||||
}
|
||||
else {
|
||||
Ref_nde head = (Ref_nde)o;
|
||||
head.Related_add(itm, head.Related_len());
|
||||
itm.Idx_major_(head.Idx_major());
|
||||
itm.Idx_minor_(head.Related_len());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Itms_clear() {
|
||||
hash.Clear();
|
||||
list.Clear();
|
||||
idx_major_last = 0;
|
||||
}
|
||||
Hash_adp hash = Hash_adp_bry.cs(); List_adp list = List_adp_.new_();
|
||||
}
|
||||
53
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr.java
Normal file
53
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Ref_itm_mgr {
|
||||
private Hash_adp_bry grps = Hash_adp_bry.cs(); // CASE_MATCH:changed from ci; DATE:2014-07-07
|
||||
private Ref_itm_grp grp_default = new Ref_itm_grp(Bry_.Empty);
|
||||
private int uid_last;
|
||||
public boolean References__recursing() {return references__recursing;} public void References__recursing_(boolean v) {references__recursing = v;} private boolean references__recursing;
|
||||
public Ref_itm_lst Lst_get(byte[] grp_name, int lst_idx) {
|
||||
return Bry_.Len_eq_0(grp_name) ? grp_default.Lsts_get_at(lst_idx) : ((Ref_itm_grp)grps.Get_by(grp_name)).Lsts_get_at(lst_idx); // NOTE: must be Bry_.Len_eq_0 else <references group=""/> not same as <references/>; DATE:2013-02-06
|
||||
}
|
||||
public void Grps_add(byte[] grp_name, byte[] itm_name, byte[] follow, Ref_nde itm) {
|
||||
Ref_itm_grp grp = Grps_get(grp_name);
|
||||
grp.Lsts_add(itm_name, follow, itm);
|
||||
itm.Uid_(uid_last++);
|
||||
}
|
||||
public int Grps_seal(byte[] grp_name) {
|
||||
Ref_itm_grp grp = Grps_get(grp_name);
|
||||
return grp.Grp_seal();
|
||||
}
|
||||
public void Grps_clear() {
|
||||
grps.Clear();
|
||||
grp_default.Lsts_clear();
|
||||
uid_last = 0;
|
||||
references__recursing = false;
|
||||
}
|
||||
public Ref_itm_grp Grps_get(byte[] grp_name) {
|
||||
if (Bry_.Len_eq_0(grp_name)) return grp_default;
|
||||
Object o = grps.Get_by_bry(grp_name);
|
||||
if (o == null) {
|
||||
Ref_itm_grp grp = new Ref_itm_grp(grp_name);
|
||||
grps.Add(grp_name, grp);
|
||||
return grp;
|
||||
}
|
||||
else
|
||||
return (Ref_itm_grp)o;
|
||||
}
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr_cfg_tst.java
Normal file
35
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr_cfg_tst.java
Normal 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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Ref_itm_mgr_cfg_tst {
|
||||
@Before public void init() {fxt.Clear();} private Ref_itm_mgr_cfg_fxt fxt = new Ref_itm_mgr_cfg_fxt();
|
||||
@Test public void Ref_backlabels_xby_bry() {
|
||||
fxt.Test_Ref_backlabels_xby_bry("a b c" , "a", "b", "c"); // basic
|
||||
fxt.Test_Ref_backlabels_xby_bry(" a b c" , "a", "b", "c"); // leading ws
|
||||
fxt.Test_Ref_backlabels_xby_bry("a b c " , "a", "b", "c"); // trailing ws
|
||||
fxt.Test_Ref_backlabels_xby_bry("a b c" , "a", "b", "c"); // redundant ws
|
||||
}
|
||||
}
|
||||
class Ref_itm_mgr_cfg_fxt {
|
||||
public void Clear() {}
|
||||
public void Test_Ref_backlabels_xby_bry(String raw, String... expd) {
|
||||
byte[][] actl = Ref_html_wtr_cfg.Ref_backlabels_xby_bry(Bry_.new_u8(raw));
|
||||
Tfds.Eq_ary_str(expd, String_.Ary(actl));
|
||||
}
|
||||
}
|
||||
83
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr_tst.java
Normal file
83
400_xowa/src/gplx/xowa/xtns/cites/Ref_itm_mgr_tst.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Ref_itm_mgr_tst {
|
||||
Ref_itm_mgr_fxt fxt = new Ref_itm_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {fxt.run_Add("key_1", "key_2").tst(fxt.itm_("key_1", 0, 0), fxt.itm_("key_2", 1, 1));}
|
||||
@Test public void Repeat() {fxt.run_Add("key_1", "key_2", "key_1").tst(fxt.itm_("key_1", 0).Related_(fxt.itm_uid_(2)), fxt.itm_("key_2", 1, 1));}
|
||||
@Test public void Group() {fxt.run_Add_grp("grp_1", "key_1").run_Add("key_1").tst_grp("grp_1", fxt.itm_("key_1", 0, 0)).tst(fxt.itm_("key_1", 0, 1));}
|
||||
@Test public void Follow() {fxt.run_Add("key_1").run_Add_follow("key_1").tst(fxt.itm_("key_1", 0, 0).Related_(fxt.itm_uid_(1).Idx_minor_follow_()));}
|
||||
}
|
||||
class Ref_itm_mgr_fxt {
|
||||
private Ref_itm_mgr ref_mgr = new Ref_itm_mgr();
|
||||
private Tst_mgr tst_mgr = new Tst_mgr();
|
||||
public Xtn_ref_nde_chkr itm_uid_(int uid) {return itm_(null, -1, uid);}
|
||||
public Xtn_ref_nde_chkr itm_(String key, int idx) {return itm_(key, idx, -1);}
|
||||
public Xtn_ref_nde_chkr itm_(String key, int idx, int uid) {return new Xtn_ref_nde_chkr().Key_(key).Idx_major_(idx).Uid_(uid);}
|
||||
public Ref_itm_mgr_fxt run_Add_follow(String follow) {return run_Add_grp(Bry_.Empty, Bry_.new_u8(follow), Bry_.Ary(Bry_.Empty));}
|
||||
public Ref_itm_mgr_fxt run_Add(String... name_ary) {return run_Add_grp(Bry_.Empty, Bry_.Empty, Bry_.Ary(name_ary));}
|
||||
public Ref_itm_mgr_fxt run_Add_grp(String grp, String... name_ary) {return run_Add_grp(Bry_.new_u8(grp), Bry_.Empty, Bry_.Ary(name_ary));}
|
||||
public void Clear() {ref_mgr.Grps_clear();}
|
||||
Ref_itm_mgr_fxt run_Add_grp(byte[] grp_name, byte[] follow, byte[]... name_ary) {
|
||||
for (int i = 0; i < name_ary.length; i++) {
|
||||
byte[] name = name_ary[i];
|
||||
Ref_nde itm = new Ref_nde().Name_(name);
|
||||
ref_mgr.Grps_add(grp_name, name, follow, itm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Ref_itm_mgr_fxt tst(Xtn_ref_nde_chkr... chkr_ary) {return tst_grp(ref_mgr.Lst_get(Bry_.Empty, 0), chkr_ary);}
|
||||
public Ref_itm_mgr_fxt tst_grp(String grp_name, Xtn_ref_nde_chkr... chkr_ary) {return tst_grp(ref_mgr.Lst_get(Bry_.new_a7(grp_name), 0), chkr_ary);}
|
||||
public Ref_itm_mgr_fxt tst_grp(Ref_itm_lst lst, Xtn_ref_nde_chkr... chkr_ary) {
|
||||
int itms_len = lst.Itms_len();
|
||||
Ref_nde[] actl = new Ref_nde[itms_len];
|
||||
for (int i = 0; i < itms_len; i++)
|
||||
actl[i] = lst.Itms_get_at(i);
|
||||
tst_mgr.Tst_ary("", chkr_ary, actl);
|
||||
return this;
|
||||
} List_adp actl_list = List_adp_.new_();
|
||||
}
|
||||
class Xtn_ref_nde_chkr implements Tst_chkr {
|
||||
public Class<?> TypeOf() {return Ref_nde.class;}
|
||||
public String Key() {return key;} public Xtn_ref_nde_chkr Key_(String v) {key = v; return this;} private String key;
|
||||
public int Idx_major() {return idx_major;} public Xtn_ref_nde_chkr Idx_major_(int v) {idx_major = v; return this;} private int idx_major = -1;
|
||||
public int Idx_minor() {return idx_minor;} public Xtn_ref_nde_chkr Idx_minor_(int v) {idx_minor = v; return this;} private int idx_minor = -1;
|
||||
public Xtn_ref_nde_chkr Idx_minor_follow_() {idx_minor = Ref_nde.Idx_minor_follow; return this;}
|
||||
public int Uid() {return uid;} public Xtn_ref_nde_chkr Uid_(int v) {uid = v; return this;} private int uid = -1;
|
||||
public Xtn_ref_nde_chkr[] Related() {return related;} public Xtn_ref_nde_chkr Related_(Xtn_ref_nde_chkr... v) {related = v; return this;} Xtn_ref_nde_chkr[] related;
|
||||
public int Chk(Tst_mgr mgr, String path, Object actl_obj) {
|
||||
Ref_nde actl = (Ref_nde)actl_obj;
|
||||
int rv = 0;
|
||||
rv += mgr.Tst_val(key == null, path, "key", key, String_.new_u8(actl.Name()));
|
||||
rv += mgr.Tst_val(idx_major == -1, path, "idx_major", idx_major, actl.Idx_major());
|
||||
rv += mgr.Tst_val(idx_minor == -1, path, "idx_minor", idx_minor, actl.Idx_minor());
|
||||
rv += mgr.Tst_val(uid == -1, path, "uid", uid, actl.Uid());
|
||||
if (related != null)
|
||||
rv += mgr.Tst_sub_ary(related, Xto_bry(actl), "related", rv);
|
||||
return rv;
|
||||
}
|
||||
Ref_nde[] Xto_bry(Ref_nde itm) {
|
||||
int len = itm.Related_len();
|
||||
Ref_nde[] rv = new Ref_nde[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = itm.Related_get(i);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
82
400_xowa/src/gplx/xowa/xtns/cites/Ref_nde.java
Normal file
82
400_xowa/src/gplx/xowa/xtns/cites/Ref_nde.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Ref_nde implements Xox_xnde, Mwh_atr_itm_owner {
|
||||
public byte[] Name() {return name;} public Ref_nde Name_(byte[] v) {name = v; return this;} private byte[] name = Bry_.Empty;
|
||||
public byte[] Group() {return group;} private byte[] group = Bry_.Empty;
|
||||
public byte[] Follow() {return follow;} private byte[] follow = Bry_.Empty;
|
||||
public boolean Follow_y() {return follow != Bry_.Empty;}
|
||||
public int Uid() {return uid;} public Ref_nde Uid_(int v) {uid = v; return this;} private int uid;
|
||||
public boolean Head() {return head;} private boolean head;
|
||||
public boolean Nested() {return nested;} private boolean nested;
|
||||
public int Idx_major() {return idx_major;} public Ref_nde Idx_major_(int v) {idx_major = v; return this;} private int idx_major;
|
||||
public int Idx_minor() {return idx_minor;} public Ref_nde Idx_minor_(int v) {idx_minor = v; return this;} private int idx_minor;
|
||||
public Xop_xnde_tkn Xnde() {return xnde;} private Xop_xnde_tkn xnde;
|
||||
public Xop_root_tkn Body() {return body;} private Xop_root_tkn body;
|
||||
public boolean Exists_in_lnki_title() {return exists_in_lnki_title;} public Ref_nde Exists_in_lnki_title_(boolean v) {exists_in_lnki_title = v; return this;} private boolean exists_in_lnki_title;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
|
||||
if (xatr_id_obj == null) return;
|
||||
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
|
||||
switch (xatr_id.Val()) {
|
||||
case Xatr_id_name: name = wiki.Appe().Sanitizer().Escape_id(xatr.Val_as_bry()); break;
|
||||
case Xatr_id_follow: follow = xatr.Val_as_bry(); break;
|
||||
case Xatr_id_group: group = xatr.Val_as_bry(); break;
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (ctx.Tid_is_popup()) return;
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair)
|
||||
body = wiki.Parser_mgr().Main().Parse_text_to_wdom_old_ctx(ctx, Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn()), false);
|
||||
byte[] references_group = ctx.References_group(); // set by <references>
|
||||
if (references_group != null) {
|
||||
group = references_group; // override <ref group> with <references group>; note that MW throws an error if nested <ref> has different group than outer <references>; Cite error: <ref> tag in <references> has conflicting group attribute "a".
|
||||
head = true;
|
||||
nested = true; // refs nested in references don't show <a> entry in <references>
|
||||
}
|
||||
if (!ctx.Ref_ignore()) // sub_ctx may be marked to ignore <ref>; EX: <pages>,{{#lst}}; DATE:2014-04-24
|
||||
ctx.Cur_page().Ref_mgr().Grps_add(group, name, follow, this);
|
||||
this.xnde = xnde;
|
||||
}
|
||||
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) {
|
||||
html_wtr.Ref_wtr().Xnde_ref(hctx, bfr, src, xnde);
|
||||
}
|
||||
private static final Ref_nde[] Ary_empty = new Ref_nde[0];
|
||||
public Ref_nde[] Related() {return related;} Ref_nde[] related = Ary_empty;
|
||||
public int Related_len() {return related_len;} private int related_len;
|
||||
public Ref_nde Related_get(int i) {return related[i];}
|
||||
public void Related_add(Ref_nde itm, int idx_minor) {
|
||||
int new_len = related_len + 1;
|
||||
int related_max = related.length;
|
||||
if (new_len > related_max)
|
||||
related = (Ref_nde[])Array_.Resize(related, related_max == 0 ? 1 : related_max * 2);
|
||||
itm.Idx_minor_(idx_minor);
|
||||
related[related_len] = itm;
|
||||
related_len = new_len;
|
||||
}
|
||||
public static final int Idx_minor_follow = -2;
|
||||
public static final byte Xatr_id_name = 0, Xatr_id_group = 1, Xatr_id_follow = 2;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("name", Byte_obj_val.new_(Ref_nde.Xatr_id_name))
|
||||
.Add_str_obj("group", Byte_obj_val.new_(Ref_nde.Xatr_id_group))
|
||||
.Add_str_obj("follow", Byte_obj_val.new_(Ref_nde.Xatr_id_follow));
|
||||
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/xtns/cites/References_nde.java
Normal file
59
400_xowa/src/gplx/xowa/xtns/cites/References_nde.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class References_nde implements Xox_xnde, Mwh_atr_itm_owner {
|
||||
public byte[] Group() {return group;} public References_nde Group_(byte[] v) {group = v; return this;} private byte[] group = Bry_.Empty;
|
||||
public int List_idx() {return list_idx;} public References_nde List_idx_(int v) {list_idx = v; return this;} private int list_idx;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
|
||||
if (xatr_id_obj == null) return;
|
||||
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
|
||||
switch (xatr_id.Val()) {
|
||||
case Xatr_id_group: group = xatr.Val_as_bry(); break;
|
||||
}
|
||||
}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (ctx.Tid_is_popup()) return;
|
||||
Ref_itm_mgr ref_mgr = ctx.Cur_page().Ref_mgr();
|
||||
if (ref_mgr.References__recursing()) return; // skip nested <references> else refs will be lost; EX:"<references><references/></references>"; PAGE:en.w:Hwair; DATE:2014-06-27
|
||||
ctx.Para().Process_block__bgn_n__end_y(Xop_xnde_tag_.Tag_div); // xnde generates <block_node>; <references> -> <ol>; close any blocks; PAGE:fr.w:Heidi_(roman); DATE:2014-02-17
|
||||
Xox_xnde_.Xatr__set(wiki, this, xatrs_hash, src, xnde);
|
||||
if (xnde.CloseMode() == Xop_xnde_tkn.CloseMode_pair) { // "<references>", "</references>"; parse anything in between but only to pick up <ref> tags; discard everything else; DATE:2014-06-27
|
||||
int itm_bgn = xnde.Tag_open_end(), itm_end = xnde.Tag_close_bgn();
|
||||
Xop_ctx references_ctx = Xop_ctx.new_sub_page_(wiki, ctx, ctx.Lst_page_regy()).References_group_(group); // changed from following: "Xop_ctx references_ctx = Xop_ctx.new_sub_(wiki).References_group_(group);"; DATE:2015-05-16;
|
||||
references_ctx.Para().Enabled_n_(); // disable para during <references> parsing
|
||||
byte[] references_src = Bry_.Mid(src, itm_bgn, itm_end);
|
||||
Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
Xop_root_tkn sub_root = tkn_mkr.Root(src);
|
||||
boolean prv_recursing = ref_mgr.References__recursing();
|
||||
ref_mgr.References__recursing_(true);
|
||||
wiki.Parser_mgr().Main().Parse_text_to_wdom(sub_root, references_ctx, tkn_mkr, references_src, Xop_parser_.Doc_bgn_char_0); // NOTE: parse inner contents, but root will be discarded; only picking up <ref> tags; DATE:2014-06-27
|
||||
ref_mgr.References__recursing_(prv_recursing);
|
||||
}
|
||||
list_idx = ref_mgr.Grps_get(group).Grp_seal(); // NOTE: needs to be sealed at end; else inner refs will end up in new group; EX: <references><ref>don't seal prematurely</ref></references>
|
||||
}
|
||||
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) {
|
||||
html_wtr.Ref_wtr().Xnde_references(html_wtr, ctx, hctx, bfr, src, xnde);
|
||||
}
|
||||
private static final byte Xatr_id_group = 0;
|
||||
public static boolean Enabled = true;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7()
|
||||
.Add_str_obj("group", Byte_obj_val.new_(References_nde.Xatr_id_group));
|
||||
}
|
||||
202
400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java
Normal file
202
400_xowa/src/gplx/xowa/xtns/cites/References_nde_basic_tst.java
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class References_nde_basic_tst {
|
||||
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>x</ref>"
|
||||
, "<ref>y</ref>"
|
||||
, "<ref>z</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
|
||||
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[3]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">z</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Name_dif() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='r_x'>x</ref>"
|
||||
, "<ref name='r_y'>y</ref>"
|
||||
, "<ref name='r_z'>z</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-r_x_0-0\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-r_y_1-0\" class=\"reference\"><a href=\"#cite_note-r_y-1\">[2]</a></sup>"
|
||||
, "<sup id=\"cite_ref-r_z_2-0\" class=\"reference\"><a href=\"#cite_note-r_z-2\">[3]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-r_x-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_x_0-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "<li id=\"cite_note-r_y-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_y_1-0\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "<li id=\"cite_note-r_z-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_z_2-0\">^</a></span> <span class=\"reference-text\">z</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Name_same() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='r_x'>x</ref>"
|
||||
, "<ref name='r_y'>y</ref>"
|
||||
, "<ref name='r_x'>z</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-r_x_0-0\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-r_y_1-0\" class=\"reference\"><a href=\"#cite_note-r_y-1\">[2]</a></sup>"
|
||||
, "<sup id=\"cite_ref-r_x_0-1\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-r_x-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-r_x_0-0\">a</a></sup> <sup><a href=\"#cite_ref-r_x_0-1\">b</a></sup></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "<li id=\"cite_note-r_y-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-r_y_1-0\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Name_same_text_in_last_ref() { // WP:Hundred Years' War
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='ref_a'></ref>"
|
||||
, "<ref name='ref_a'></ref>"
|
||||
, "<ref name='ref_a'>x</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-ref_a_0-0\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-ref_a_0-1\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-ref_a_0-2\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-ref_a-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref_a_0-0\">a</a></sup> <sup><a href=\"#cite_ref-ref_a_0-1\">b</a></sup> <sup><a href=\"#cite_ref-ref_a_0-2\">c</a></sup></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void List_ignored() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>*x</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">*x</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Name_mixed_case() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref NAME=A>x</ref>"
|
||||
, "<ref Name=A>y</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-A_0-0\" class=\"reference\"><a href=\"#cite_note-A-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-A_0-1\" class=\"reference\"><a href=\"#cite_note-A-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-A-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-A_0-0\">a</a></sup> <sup><a href=\"#cite_ref-A_0-1\">b</a></sup></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Name2() { // PURPOSE: make sure inline tag matches open tag
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a<ref name=name_0>b</ref>"
|
||||
, "b<ref name=name_0/>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "a<sup id=\"cite_ref-name_0_0-0\" class=\"reference\"><a href=\"#cite_note-name_0-0\">[1]</a></sup>"
|
||||
, "b<sup id=\"cite_ref-name_0_0-1\" class=\"reference\"><a href=\"#cite_note-name_0-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-name_0-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-name_0_0-0\">a</a></sup> <sup><a href=\"#cite_ref-name_0_0-1\">b</a></sup></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void References_refs() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a<ref group=group_0 name=name_0/>"
|
||||
, "<references group=group_0>"
|
||||
, " <ref name=name_0>b</ref>"
|
||||
, "</references>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "a<sup id=\"cite_ref-name_0_0-0\" class=\"reference\"><a href=\"#cite_note-name_0-0\">[group_0 1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-name_0-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-name_0_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Nested() { // PURPOSE: nested ref was creating 3rd [1]
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a<ref name=r_x/>"
|
||||
, "b<ref name=r_x/>"
|
||||
, "<references>"
|
||||
, "<ref name=r_x>c</ref>"
|
||||
, "</references>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "a<sup id=\"cite_ref-r_x_0-0\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
|
||||
, "b<sup id=\"cite_ref-r_x_0-1\" class=\"reference\"><a href=\"#cite_note-r_x-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-r_x-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-r_x_0-0\">a</a></sup> <sup><a href=\"#cite_ref-r_x_0-1\">b</a></sup></span> <span class=\"reference-text\">c</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Key_ignore_nl_tab() { // PURPOSE: \n in ref_name should be escaped to \s; PAGE:en.w:Self-Transcendence 3100 Mile Race
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name=\"name\na\">b</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-name_a_0-0\" class=\"reference\"><a href=\"#cite_note-name_a-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-name_a-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-name_a_0-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Empty_group_before_ref() { // PURPOSE: empty grp before itm should not throw error; DATE:2013-02-18; EX: w:Help:External links and references; Johnstown,_Colorado
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "<references/><references/>a<ref>test</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl
|
||||
( "a<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">test</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Follow() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='ref_a'>x</ref>"
|
||||
, "<ref>y</ref>"
|
||||
, "<ref follow='ref_a'>z</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-ref_a_0-0\" class=\"reference\"><a href=\"#cite_note-ref_a-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-ref_a-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref_a_0-0\">a</a></sup></span> <span class=\"reference-text\">x z</span></li>"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
}
|
||||
122
400_xowa/src/gplx/xowa/xtns/cites/References_nde_group_tst.java
Normal file
122
400_xowa/src/gplx/xowa/xtns/cites/References_nde_group_tst.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class References_nde_group_tst {
|
||||
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>x</ref>"
|
||||
, "<ref group='group_a'>y</ref>"
|
||||
, "<ref>z</ref>"
|
||||
, "<references group='group_a'/>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[group_a 1]</a></sup>"
|
||||
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[2]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "</ol>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">z</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Lower_alpha_is_ignored() {
|
||||
String expd =
|
||||
String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>" // note:do not show lower-alpha; DATE:2014-07-21
|
||||
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "</ol>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
);
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref group='lower-alpha'>x</ref>"
|
||||
, "<ref>y</ref>"
|
||||
, "<references group='lower-alpha'/>"
|
||||
, "<references group=''/>"
|
||||
), expd);
|
||||
}
|
||||
@Test public void Empty() { // PURPOSE: <references group=""/> is same as <references/>; DATE:2013-02-06
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>b</ref>"
|
||||
, "<references group=\"\"/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Val_less_defaults_to_key() { // PURPOSE: similar to above, except "group" is same as "group=group"; DATE:2014-07-03
|
||||
String expd = String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[group 1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
, "");
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref group='group'>b</ref>"
|
||||
, "<references group/>"
|
||||
), expd
|
||||
);
|
||||
fxt.Clear_ref_mgr();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last // PURPOSE.FIX: similar to above, except "group />" was not same as "group/>"; SEE:xatr_parser and " a " test; DATE:2014-07-03
|
||||
( "<ref group='group'>b</ref>"
|
||||
, "<references group />"
|
||||
), expd
|
||||
);
|
||||
}
|
||||
@Test public void Empty_group() { // PURPOSE: group without items should be blank; should not throw error; DATE:2013-02-12
|
||||
fxt.Test_parse_page_wiki_str("<references name='group_a'/>", "");
|
||||
}
|
||||
@Test public void Multiple_same_name_groups() { // PURPOSE: multiple groups with same name "clears" out references; DATE:2013-02-11
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>a</ref>"
|
||||
, "<references/>"
|
||||
, "<ref>b</ref>"
|
||||
, "<references/>"
|
||||
, "<ref>c</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
|
||||
, "</ol>"
|
||||
, "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">b</span></li>"
|
||||
, "</ol>"
|
||||
, "<sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">c</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class References_nde_pre_tst {
|
||||
@Before public void init() {fxt.Clear_ref_mgr();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_();}
|
||||
@Test public void Pre_ignored() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref> x</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"> x</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Pre_ignored_2() { // PURPOSE: <ref> creates <li> which will effectively disable all pre; PAGE:en.w:Robert_Browning
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>x"
|
||||
, " y"
|
||||
, "</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x"
|
||||
, " y"
|
||||
, "</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Pre_ignored_3() { // PURPOSE: " <references>" should not create pre; fr.w:Heidi_(roman); DATE:2014-02-17
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>x</ref>"
|
||||
, ""
|
||||
, " <references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "</p>"
|
||||
, " <ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">x</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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.xtns.cites; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class References_nde_rare_tst {
|
||||
@Before public void init() {fxt.Clear_ref_mgr(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_();}
|
||||
@Test public void Recursive() { // PURPOSE: handle recursive situations; EX: ja.w:Kソリューション ; ja.w:Template:cite web。; DATE:2014-03-05
|
||||
fxt.Init_page_create("Template:Recursive", "<ref>{{Recursive}}</ref>");
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>{{Recursive}}</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\"></span></li>"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\"><sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Backlabel_out_of_range() { // PURPOSE: handle more backlabels than expected; PAGE:en.w:List_of_Russula_species; DATE:2014-06-07
|
||||
Ref_html_wtr_cfg cfg = fxt.Wiki().Html_mgr().Html_wtr().Ref_wtr().Cfg();
|
||||
byte[][] old = cfg.Backlabels();
|
||||
cfg.Backlabels_(Bry_.Ary("a"));
|
||||
fxt.Wiki().Msg_mgr().Get_or_make(Ref_html_wtr_cfg.Msg_backlabels_err).Atrs_set(Bry_.new_a7("Ran out of custom link labels for group ~{0}."), true, false);
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref name='ref_1'>a</ref><ref name='ref_1'>b</ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-ref_1_0-0\" class=\"reference\"><a href=\"#cite_note-ref_1-0\">[1]</a></sup><sup id=\"cite_ref-ref_1_0-1\" class=\"reference\"><a href=\"#cite_note-ref_1-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-ref_1-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-ref_1_0-0\">a</a></sup> <sup><a href=\"#cite_ref-ref_1_0-1\">Ran out of custom link labels for group 1.</a></sup></span> <span class=\"reference-text\">a</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
cfg.Backlabels_(old);
|
||||
}
|
||||
@Test public void Tag() { // PURPOSE: #tag can create nested refs; PAGE:en.w:Battle_of_Midway DATE:2014-06-27
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "{{#tag:ref|x<ref>y</ref>}}" //"<ref>x<ref>y</ref></ref>"
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-1\" class=\"reference\"><a href=\"#cite_note-1\">[2]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">y</span></li>"
|
||||
, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\">^</a></span> <span class=\"reference-text\">x<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup></span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tag_2() { // PURPOSE: more involved nested refs; PAGE:en.w:Battle_of_Midway DATE:2014-06-27
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "a<ref name='itm_0'/> b {{#tag:ref|c<ref name='itm_0'>d</ref>}}" // <ref>c<ref name='itm_0'>d</ref></ref>
|
||||
, "<references/>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "a<sup id=\"cite_ref-itm_0_0-0\" class=\"reference\"><a href=\"#cite_note-itm_0-0\">[1]</a></sup> b <sup id=\"cite_ref-2\" class=\"reference\"><a href=\"#cite_note-2\">[2]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-itm_0-0\"><span class=\"mw-cite-backlink\">^ <sup><a href=\"#cite_ref-itm_0_0-0\">a</a></sup> <sup><a href=\"#cite_ref-itm_0_0-1\">b</a></sup></span> <span class=\"reference-text\">d</span></li>"
|
||||
, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\">^</a></span> <span class=\"reference-text\">c<sup id=\"cite_ref-itm_0_0-1\" class=\"reference\"><a href=\"#cite_note-itm_0-0\">[1]</a></sup></span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Dangling_references__nested() { // PURPOSE: handle nested <references/>; PAGE:en.w:Hwair; DATE:2014-06-27
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
( "<ref>a</ref>"
|
||||
, "<references>"
|
||||
, " <references/>" // must be ignored, else it will become owner for <ref>
|
||||
, "</references>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<sup id=\"cite_ref-0\" class=\"reference\"><a href=\"#cite_note-0\">[1]</a></sup>"
|
||||
, "<ol class=\"references\">"
|
||||
, "<li id=\"cite_note-0\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-0\">^</a></span> <span class=\"reference-text\">a</span></li>"
|
||||
, "</ol>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user