mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.4.3.1'
This commit is contained in:
@@ -78,9 +78,9 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
int options_len = options_ary.length;
|
||||
for (int i = 0; i < options_len; ++i) {
|
||||
Rndsel_option_itm option = options_ary[i];
|
||||
rnd -= option.Weight();
|
||||
rnd -= option.Weight;
|
||||
if (rnd <= 0) {
|
||||
option_bry = option.Text();
|
||||
option_bry = option.Text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class Random_selection_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
public static int Rnd_test = -1;
|
||||
}
|
||||
class Rndsel_option_itm {
|
||||
public Rndsel_option_itm(int weight, byte[] text) {this.weight = weight; this.text = text;}
|
||||
public int Weight() {return weight;} private final int weight;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public Rndsel_option_itm(int weight, byte[] text) {this.Weight = weight; this.Text = text;}
|
||||
public final int Weight;
|
||||
public final byte[] Text;
|
||||
}
|
||||
|
||||
51
400_xowa/src/gplx/xowa/xtns/wikias/Tabber_tab_itm.java
Normal file
51
400_xowa/src/gplx/xowa/xtns/wikias/Tabber_tab_itm.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.htmls.*;
|
||||
class Tabber_tab_itm {
|
||||
public Tabber_tab_itm(boolean active, byte[] name, byte[] text) {
|
||||
this.Active = active;
|
||||
this.Name = name;
|
||||
this.Text = text;
|
||||
}
|
||||
public final boolean Active;
|
||||
public final byte[] Name;
|
||||
public final byte[] Text;
|
||||
public static void Write(Bry_bfr bfr, byte[] id, Tabber_tab_itm[] ary) {
|
||||
bfr.Add_str_a7("<div id=\"tabber-");
|
||||
bfr.Add(id);
|
||||
bfr.Add_str_a7("\" class=\"tabber\">\n");
|
||||
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Tabber_tab_itm itm = ary[i];
|
||||
bfr.Add_str_a7("<div class=\"tabbertab\" title=\"");
|
||||
bfr.Add(Gfh_utl.Escape_html_as_bry(itm.Name));
|
||||
bfr.Add_str_a7("\"");
|
||||
if (itm.Active) {
|
||||
bfr.Add_str_a7(" data-active=\"true\"");
|
||||
}
|
||||
bfr.Add_str_a7(">\n");
|
||||
bfr.Add(Gfh_tag_.P_lhs);
|
||||
bfr.Add(itm.Text);
|
||||
bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl();
|
||||
bfr.Add(Gfh_tag_.Div_rhs).Add_byte_nl();
|
||||
}
|
||||
bfr.Add(Gfh_tag_.Div_rhs);
|
||||
}
|
||||
}
|
||||
@@ -19,43 +19,45 @@ package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.xowa.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Tabber_xnde implements Xox_xnde {
|
||||
private static final byte[] Spr__tab_itms = Bry_.new_a7("|-|");
|
||||
private byte[] html;
|
||||
private byte[] id;
|
||||
private Tabber_tab_itm[] tab_itms_ary;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
tmp_bfr.Add_str_a7("<div id=\"tabber-\" "); // TODO: add key which is md5 of inner src
|
||||
tmp_bfr.Add_str_a7("class=\"tabber\">\n");
|
||||
|
||||
// split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B'
|
||||
byte[][] tab_itms = Bry_split_.Split(src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), Spr__tab_itms);
|
||||
List_adp tab_itms_list = List_adp_.new_();
|
||||
byte[] xnde_body = Xox_xnde_.Extract_body_or_null(src, xnde); if (xnde_body == null) return;
|
||||
this.id = Id_test == null ? gplx.core.security.HashAlgo_.Md5.Calc_hash_bry(xnde_body) : Id_test;
|
||||
byte[][] tab_itms = Bry_split_.Split(xnde_body, Spr__tab_itms);
|
||||
for (int i = 0; i < tab_itms.length; ++i) {
|
||||
byte[] tab_itm = tab_itms[i];
|
||||
tab_itm = Bry_.Trim(tab_itm);
|
||||
int tab_itm_len = tab_itm.length; if (tab_itm_len == 0) continue;
|
||||
|
||||
// split on "="; EX: A=B -> tab_name='A'; tab_body = 'B'
|
||||
byte[][] tab_parts = Bry_split_.Split(tab_itm, Byte_ascii.Eq);
|
||||
byte[] tab_head = tab_parts[0];
|
||||
byte[] tab_body = tab_parts.length == 1 ? Bry_.Empty : Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), tab_parts[1], false);
|
||||
|
||||
tmp_bfr.Add_str_a7("<div class=\"tabbertab\" title=\"");
|
||||
tmp_bfr.Add(Gfh_utl.Escape_html_as_bry(tab_head));
|
||||
tmp_bfr.Add_str_a7("\">\n");
|
||||
tmp_bfr.Add(Gfh_tag_.P_lhs);
|
||||
tmp_bfr.Add(tab_body);
|
||||
tmp_bfr.Add(Gfh_tag_.P_rhs).Add_byte_nl();
|
||||
tmp_bfr.Add(Gfh_tag_.Div_rhs).Add_byte_nl();
|
||||
byte[] tab_head = null, tab_body = null;
|
||||
int eq_pos = Bry_find_.Find_fwd(tab_itm, Byte_ascii.Eq);
|
||||
if (eq_pos == Bry_find_.Not_found) {
|
||||
tab_head = tab_itm;
|
||||
tab_body = Bry_.Empty;
|
||||
}
|
||||
else {
|
||||
tab_head = Bry_.Mid(tab_itm, 0, eq_pos);
|
||||
tab_body = Bry_.Mid(tab_itm, eq_pos + 1, tab_itm_len);
|
||||
tab_body = Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), tab_body, false);
|
||||
}
|
||||
tab_itms_list.Add(new Tabber_tab_itm(Bool_.N, tab_head, tab_body));
|
||||
}
|
||||
tmp_bfr.Add(Gfh_tag_.Div_rhs);
|
||||
html = tmp_bfr.To_bry_and_clear();
|
||||
tab_itms_ary = (Tabber_tab_itm[])tab_itms_list.To_ary_and_clear(Tabber_tab_itm.class);
|
||||
|
||||
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
}
|
||||
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 (html != null) bfr.Add(html);
|
||||
if (tab_itms_ary != null) Tabber_tab_itm.Write(bfr, id, tab_itms_ary);
|
||||
}
|
||||
|
||||
public static byte[] Id_test;
|
||||
private static final byte[] Spr__tab_itms = Bry_.new_a7("|-|");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import org.junit.*;
|
||||
public class Tabber_xnde_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Before public void init() {
|
||||
fxt.Reset();
|
||||
Tabber_xnde.Id_test = Bry_.new_a7("test");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabber>"
|
||||
@@ -28,7 +31,7 @@ public class Tabber_xnde_tst {
|
||||
, "tab2=''b''"
|
||||
, "</tabber>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-\" class=\"tabber\">"
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p><i>a</i></p>"
|
||||
, "</div>"
|
||||
@@ -38,17 +41,30 @@ public class Tabber_xnde_tst {
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Eq_missing() {
|
||||
@Test public void Eq__missing() {
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabber>"
|
||||
, "tab1"
|
||||
, "</tabber>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-\" class=\"tabber\">"
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p></p>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Eq__many() {
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabber>"
|
||||
, "tab1=A=B"
|
||||
, "</tabber>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p>A=B</p>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,136 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
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 Tabview_xnde implements Xox_xnde {
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
|
||||
public class Tabview_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
|
||||
private byte[] id;
|
||||
private Tabber_tab_itm[] tab_itms_ary;
|
||||
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
|
||||
switch (xatr_id) {
|
||||
case Xatr__id: id = 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) {
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
|
||||
ctx.Page().Html_data().Head_mgr().Itm__graph().Enabled_y_();
|
||||
Xox_xnde_.Parse_xatrs(wiki, this, xatrs_hash, src, xnde);
|
||||
|
||||
// get id
|
||||
id = Keep_alphanum(id);
|
||||
if (Bry_.Len_eq_0(id)) id = Int_.To_bry(global_id++);
|
||||
|
||||
// parse src
|
||||
byte[] tabs_src = Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
tabs_src = Bry_.Trim(tabs_src); // if(isset($tabs[0]) && $tabs[0] == "") {unset($tabs[0]);} if($tabs[count($tabs)] == "") {unset($tabs[count($tabs)]);}
|
||||
byte[][] tabs_ary = Bry_split_.Split_lines(tabs_src);
|
||||
List_adp tabs_list = List_adp_.new_();
|
||||
int tabs_len = tabs_ary.length;
|
||||
for (int i = 0; i < tabs_len; ++i) {
|
||||
Tabview_tab_itm itm = Tabview_tab_itm.Parse(wiki, ctx, tabs_ary[i]);
|
||||
if (itm != null)
|
||||
tabs_list.Add(itm);
|
||||
}
|
||||
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
|
||||
Tabview_tab_itm[] ary = (Tabview_tab_itm[])tabs_list.To_ary_and_clear(Tabview_tab_itm.class);
|
||||
tab_itms_ary = Tabview_tab_itm.To_tabber_ary(ary);
|
||||
|
||||
ctx.Page().Html_data().Head_mgr().Itm__tabber().Enabled_y_();
|
||||
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
|
||||
}
|
||||
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) {
|
||||
bfr.Add_mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
if (tab_itms_ary != null) Tabber_tab_itm.Write(bfr, id, tab_itms_ary);
|
||||
// write html
|
||||
//Bry_bfr bfr = Bry_bfr.new_();
|
||||
//bfr.Add_str_a7("<div id=\"flytabs_");
|
||||
//bfr.Add(id);
|
||||
//bfr.Add_str_a7("\">\n<ul>\n");
|
||||
//int ary_len = ary.length;
|
||||
//for (int i = 0; i < ary_len; ++i) {
|
||||
// Tabview_tab_itm itm = ary[i];
|
||||
// bfr.Add_str_a7("<li><a href=");
|
||||
// // href
|
||||
// bfr.Add_str_a7("><span>");
|
||||
// bfr.Add(itm.Tab_name);
|
||||
// bfr.Add_str_a7("</span></a></li>");
|
||||
//}
|
||||
//bfr.Add_str_a7("</ul>\n</div>\n");
|
||||
}
|
||||
|
||||
private int global_id = 0;
|
||||
public static final byte Xatr__id = 0;
|
||||
private static final Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7().Add_str_byte("id", Xatr__id);
|
||||
private static byte[] Keep_alphanum(byte[] src) {
|
||||
if (src == null) return null;
|
||||
int src_len = src.length; if (src_len == 0) return src;
|
||||
Bry_bfr bfr = null;
|
||||
for (int i = 0; i < src_len; ++i) {
|
||||
byte b = src[i];
|
||||
if ( Byte_ascii.Is_ltr(b)
|
||||
|| Byte_ascii.Is_num(b)) {
|
||||
if (bfr != null) bfr.Add_byte(b);
|
||||
}
|
||||
else { // not alphanum;
|
||||
if (bfr == null) { // 1st occurrence; create bfr and add initial to it
|
||||
bfr = Bry_bfr.new_();
|
||||
bfr.Add_mid(src, 0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return bfr == null ? src : bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
class Tabview_tab_itm {
|
||||
public Tabview_tab_itm(boolean active, boolean cache, byte[] tab_name, byte[] page_ttl_bry, byte[] page_body) {
|
||||
this.Active = active;
|
||||
this.Cache = cache;
|
||||
this.Tab_name = tab_name;
|
||||
this.Page_ttl_bry = page_ttl_bry;
|
||||
this.Page_body = page_body;
|
||||
}
|
||||
public final boolean Active;
|
||||
public final boolean Cache;
|
||||
public final byte[] Tab_name;
|
||||
public final byte[] Page_ttl_bry;
|
||||
public final byte[] Page_body;
|
||||
|
||||
public static Tabview_tab_itm Parse(Xowe_wiki wiki, Xop_ctx ctx, byte[] src) {
|
||||
byte[][] args_ary = Bry_split_.Split(src, Byte_ascii.Pipe);
|
||||
int args_len = args_ary.length;
|
||||
|
||||
boolean cache = false, active = false;
|
||||
byte[] tab_name = null, page_ttl_bry = null, page_body = null;
|
||||
for (int i = 0; i < args_len; ++i) {
|
||||
byte[] args_itm = args_ary[i];
|
||||
switch (i) {
|
||||
case 0:
|
||||
page_ttl_bry = args_itm;
|
||||
if (Bry_.Has_at_bgn(page_ttl_bry, Byte_ascii.Angle_bgn) || Bry_.Has_at_end(page_ttl_bry, Byte_ascii.Angle_end)) return null;
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(page_ttl_bry);
|
||||
if (page_ttl == null) return null;
|
||||
gplx.xowa.wikis.caches.Xow_page_cache_itm page_itm = wiki.Cache_mgr().Page_cache().Get_or_load_as_itm(page_ttl);
|
||||
if (page_itm == null) return null;
|
||||
page_body = page_itm.Wtxt__redirect_or_direct();
|
||||
page_body = Xop_parser_.Parse_text_to_html(wiki, ctx.Page(), ctx.Page().Ttl(), page_body, false);
|
||||
break;
|
||||
case 1:
|
||||
tab_name = args_itm;
|
||||
if (Bry_.Has_at_bgn(tab_name, Byte_ascii.Angle_bgn) || Bry_.Has_at_end(tab_name, Byte_ascii.Angle_end)) return null;
|
||||
break;
|
||||
case 2:
|
||||
cache = Bry_.To_bool_or(args_itm, false);
|
||||
break;
|
||||
case 3:
|
||||
active = Bry_.To_bool_or(args_itm, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Tabview_tab_itm(active, cache, tab_name, page_ttl_bry, page_body);
|
||||
}
|
||||
public static Tabber_tab_itm[] To_tabber_ary(Tabview_tab_itm[] ary) {
|
||||
int len = ary.length;
|
||||
Tabber_tab_itm[] rv = new Tabber_tab_itm[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Tabview_tab_itm src = ary[i];
|
||||
rv[i] = new Tabber_tab_itm(src.Active, src.Tab_name, src.Page_body);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
42
400_xowa/src/gplx/xowa/xtns/wikias/Tabview_xnde_tst.java
Normal file
42
400_xowa/src/gplx/xowa/xtns/wikias/Tabview_xnde_tst.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*;
|
||||
public class Tabview_xnde_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@Test public void Basic() {
|
||||
fxt.Init_page_create("A", "''a''");
|
||||
fxt.Init_page_create("B", "''b''");
|
||||
fxt.Test__parse__tmpl_to_html(String_.Concat_lines_nl_skip_last
|
||||
( "<tabview id='test'>"
|
||||
, "A|tab1"
|
||||
, "B|tab2||true"
|
||||
, "</tabview>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"tabber-test\" class=\"tabber\">"
|
||||
, "<div class=\"tabbertab\" title=\"tab1\">"
|
||||
, "<p><i>a</i></p>"
|
||||
, "</div>"
|
||||
, "<div class=\"tabbertab\" title=\"tab2\" data-active=\"true\">"
|
||||
, "<p><i>b</i></p>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user