1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00
This commit is contained in:
gnosygnu 2014-09-01 00:43:52 -04:00
parent b0a01882de
commit be63adc5af
125 changed files with 1859 additions and 952 deletions

View File

@ -36,6 +36,10 @@ public class Int_ implements GfoInvkAble {
rv[i] = ary[i];
return rv;
}
public static void Ary_copy_to(int[] src, int src_len, int[] trg) {
for (int i = 0; i < src_len; ++i)
trg[i] = src[i];
}
public static int[] AryRng(int bgn, int end) {
int len = end - bgn + 1;
int[] rv = new int[len];

View File

@ -26,8 +26,10 @@ public class Io_url implements CompareAble, EqAble, ParseAble, GfoInvkAble { //_
// catch (Exception e) {throw Err_.err_(e, "Http_file_bry");}
// }
public String To_http_file_str() {return Http_file_str + Http_file_str_encoder.Encode_str(raw);}
public byte[] To_http_file_bry() {return Bry_.Add(Http_file_bry, Http_file_str_encoder.Encode_bry(raw));}
public static Url_encoder_interface Http_file_str_encoder;
public byte[] To_http_file_bry() {
return Bry_.Add(Http_file_bry, Http_file_str_encoder.Encode_bry(raw));
}
public static Url_encoder_interface Http_file_str_encoder = Url_encoder_interface_same._;
public static final String Http_file_str = "file:///";
public static final int Http_file_len = String_.Len(Http_file_str);

View File

@ -20,3 +20,8 @@ public interface Url_encoder_interface {
String Encode_str(String v);
byte[] Encode_bry(String v);
}
class Url_encoder_interface_same implements Url_encoder_interface {
public String Encode_str(String v) {return v;}
public byte[] Encode_bry(String v) {return Bry_.new_utf8_(v);}
public static final Url_encoder_interface_same _ = new Url_encoder_interface_same(); Url_encoder_interface_same() {}
}

View File

@ -40,6 +40,25 @@ public class Yn {
return v_int == Bool_.Y_int;
}
public static String Xto_str(boolean v) {return v ? "y" : "n";}
public static String Xto_nullable_str(byte v) {
switch (v) {
case Bool_.Y_byte: return "y";
case Bool_.N_byte: return "n";
case Bool_.__byte: return "?";
default: throw Err_.unhandled(v);
}
}
public static byte Xto_nullable_byte(String v) {
if (v != null && String_.Len(v) == 1) {
char c = String_.CharAt(v, 0);
switch (c) {
case 'y': return Bool_.Y_byte;
case 'n': return Bool_.N_byte;
case '?': return Bool_.__byte;
}
}
throw Err_.unhandled(v);
}
public static boolean store_bool_or(SrlMgr mgr, String key, boolean or) {
String v = mgr.SrlStrOr(key, "");
return mgr.Type_rdr() ? parse_or_(v, or) : or;

View File

@ -17,6 +17,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.intl; import gplx.*;
public class Utf8_ {
public static int Len_of_bry(byte[] ary) {
if (ary == null) return 0;
int rv = 0;
int pos = 0, len = ary.length;
while (pos < len) {
int char_len = Len_of_char_by_1st_byte(ary[pos]);
++rv;
pos += char_len;
}
return rv;
}
public static int Len_of_char_by_1st_byte(byte b) {// SEE:w:UTF-8
int i = b & 0xff; // PATCH.JAVA:need to convert to unsigned byte
switch (i) {

View File

@ -21,12 +21,23 @@ public class Bry_rdr {
public Bry_rdr Src_(byte[] src, int src_len) {this.src = src; this.src_len = src_len; pos = 0; return this;} public Bry_rdr Src_(byte[] src) {return Src_(src, src.length);}
public int Pos() {return pos;} public Bry_rdr Pos_(int v) {this.pos = v; return this;} private int pos;
public boolean Pos_is_eos() {return pos == src_len;}
public void Pos_add_one() {++pos;}
public int Or_int() {return or_int;} public void Or_int_(int v) {or_int = v;} private int or_int = Int_.MinValue;
public byte[] Or_bry() {return or_bry;} public void Or_bry_(byte[] v) {or_bry = v;} private byte[] or_bry;
public int Find_fwd__pos_at_lhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.N);}
public int Find_fwd__pos_at_rhs(byte[] find_bry) {return Find_fwd__pos_at(find_bry, Bool_.Y);}
public int Find_fwd__pos_at(byte[] find_bry, boolean pos_at_rhs) {
int find_pos = Bry_finder.Find_fwd(src, find_bry, pos, src_len);
if (pos_at_rhs) find_pos += find_bry.length;
if (find_pos != Bry_finder.Not_found) pos = find_pos;
return find_pos;
}
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
public int Read_int_to_nl() {return Read_int_to(Byte_ascii.NewLine);}
public int Read_int_to(byte to_char) {
int bgn = pos;
int rv = 0;
int negative = 1;
while (pos < src_len) {
byte b = src[pos++];
switch (b) {
@ -34,11 +45,17 @@ public class Bry_rdr {
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
rv = (rv * 10) + (b - Byte_ascii.Num_0);
break;
case Byte_ascii.Dash:
if (negative == -1) // 2nd negative
return or_int; // return or_int
else // 1st negative
negative = -1; // flag negative
break;
default:
return b == to_char ? rv : or_int;
return b == to_char ? rv * negative : or_int;
}
}
return bgn == pos ? or_int : rv;
return bgn == pos ? or_int : rv * negative;
}
public byte[] Read_bry_to_nl() {return Read_bry_to(Byte_ascii.NewLine);}
public byte[] Read_bry_to_pipe() {return Read_bry_to(Byte_ascii.Pipe);}

View File

@ -26,6 +26,11 @@ public class Bry_rdr_tst {
fxt.Test_read_int(789);
fxt.Test_read_int(Int_.MinValue);
}
@Test public void Int_negative() {
fxt.Init_src("-1|-2");
fxt.Test_read_int(-1);
fxt.Test_read_int(-2);
}
@Test public void Bry() {
fxt.Init_src("abc|d||ef");
fxt.Test_read_bry("abc");

View File

@ -63,7 +63,7 @@ public class Html_wtr {
return this;
}
public Html_wtr Atr(byte[] key, byte[] val) {
Write_atr(bfr, atr_quote, key, val);
Write_atr_bry(bfr, Bool_.Y, atr_quote, key, val);
return this;
}
public Html_wtr Nde_end_inline() {
@ -85,14 +85,23 @@ public class Html_wtr {
public byte[] Xto_bry_and_clear() {return bfr.XtoAryAndClear();}
public byte[] Xto_bry() {return bfr.XtoAry();}
public String Xto_str() {return bfr.XtoStr();}
public static void Write_atr(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr(bfr, Byte_ascii.Quote, key, val);}
public static void Write_atr(Bry_bfr bfr, byte atr_quote, byte[] key, byte[] val) {
public static void Write_atr_bry(Bry_bfr bfr, byte[] key, byte[] val) {Write_atr_bry(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
public static void Write_atr_bry(Bry_bfr bfr, boolean write_space, byte atr_quote, byte[] key, byte[] val) {
if (Bry_.Len_eq_0(val)) return; // don't write empty
bfr.Add_byte_space();
if (write_space) bfr.Add_byte_space();
bfr.Add(key);
bfr.Add_byte(Byte_ascii.Eq);
bfr.Add_byte(atr_quote);
Html_utl.Escape_html_to_bfr(bfr, val, 0, val.length, false, false, false, true, true);
bfr.Add_byte(atr_quote);
}
public static void Write_atr_int(Bry_bfr bfr, byte[] key, int val) {Write_atr_int(bfr, Bool_.Y, Byte_ascii.Quote, key, val);}
public static void Write_atr_int(Bry_bfr bfr, boolean write_space, byte atr_quote, byte[] key, int val) {
if (write_space) bfr.Add_byte_space();
bfr.Add(key);
bfr.Add_byte(Byte_ascii.Eq);
bfr.Add_byte(atr_quote);
bfr.Add_int_variable(val);
bfr.Add_byte(atr_quote);
}
}

View File

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.intl; import gplx.*;
public class String_surrogate_utl {
public int Byte_pos() {return byte_pos;} int byte_pos;
public int Count_surrogates__char_idx(byte[] src, int src_len, int byte_bgn, int char_idx) {return Count_surrogates(src, src_len, byte_bgn, Bool_.Y, char_idx);}
public int Count_surrogates__codepoint_idx1(byte[] src, int src_len, int byte_bgn, int codepoint_idx) {return Count_surrogates(src, src_len, byte_bgn, Bool_.N, codepoint_idx);}
private int Count_surrogates(byte[] src, int src_len, int byte_bgn, boolean stop_idx_is_char, int stop_idx) {
int char_count = 0, codepoint_count = 0;
byte_pos = byte_bgn;
while (true) {
if (stop_idx == (stop_idx_is_char ? char_count : codepoint_count)) return codepoint_count - char_count;
if (byte_pos >= src_len) throw Err_.new_("codepoint_idx is not in string; stop_idx={0} stop_idx_is_char={1} byte_bgn={2} string={3}", stop_idx, stop_idx_is_char, byte_bgn, String_.new_utf8_(src));
int char_len_in_bytes = gplx.intl.Utf8_.Len_of_char_by_1st_byte(src[byte_pos]);
++char_count; // char_count always incremented by 1
codepoint_count += (char_len_in_bytes == 4) ? 2 : 1; // codepoint_count incremented by 2 if surrogate pair; else 1
byte_pos += char_len_in_bytes;
}
}
}

View File

@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.intl; import gplx.*;
import org.junit.*;
public class String_surrogate_utl_tst {
@Before public void init() {fxt.Clear();} private String_surrogate_utl_fxt fxt = new String_surrogate_utl_fxt();
@Test public void Char_idx() {
String test_str = "aé𡼾bî𡼾";
fxt.Test_count_surrogates__char_idx (test_str, 0, 1, 0, 1); // a
fxt.Test_count_surrogates__char_idx (test_str, 0, 2, 0, 3); //
fxt.Test_count_surrogates__char_idx (test_str, 0, 3, 1, 7); // aé𡼾
fxt.Test_count_surrogates__char_idx (test_str, 7, 1, 0, 8); // b
fxt.Test_count_surrogates__char_idx (test_str, 7, 2, 0, 10); //
fxt.Test_count_surrogates__char_idx (test_str, 7, 3, 1, 14); // bî𡼾
fxt.Test_count_surrogates__char_idx (test_str, 0, 6, 2, 14); // aé𡼾bî𡼾
}
@Test public void Codepoint_idx() {
String test_str = "aé𡼾bî𡼾";
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 1, 0, 1); // a
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 2, 0, 3); //
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 4, 1, 7); // aé𡼾
fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 1, 0, 8); // b
fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 2, 0, 10); //
fxt.Test_count_surrogates__codepoint_idx (test_str, 7, 4, 1, 14); // bî𡼾
fxt.Test_count_surrogates__codepoint_idx (test_str, 0, 8, 2, 14); // aé𡼾bî𡼾
}
}
class String_surrogate_utl_fxt {
private String_surrogate_utl codepoint_utl = new String_surrogate_utl();
public void Clear() {}
public void Test_count_surrogates__char_idx(String src_str, int bgn_byte, int char_idx, int expd_count, int expd_pos) {
byte[] src_bry = Bry_.new_utf8_(src_str); int src_len = src_bry.length;
Tfds.Eq(expd_count , codepoint_utl.Count_surrogates__char_idx(src_bry, src_len, bgn_byte, char_idx));
Tfds.Eq(expd_pos , codepoint_utl.Byte_pos());
}
public void Test_count_surrogates__codepoint_idx(String src_str, int bgn_byte, int char_idx, int expd_count, int expd_pos) {
byte[] src_bry = Bry_.new_utf8_(src_str); int src_len = src_bry.length;
Tfds.Eq(expd_count , codepoint_utl.Count_surrogates__codepoint_idx1(src_bry, src_len, bgn_byte, char_idx), "count");
Tfds.Eq(expd_pos , codepoint_utl.Byte_pos(), "pos");
}
}

View File

@ -23,7 +23,7 @@ public class Xoa_app_ {
boot_mgr.Run(args);
}
public static final String Name = "xowa";
public static final String Version = "1.8.4.1";
public static final String Version = "1.9.1.1";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys;
public static String User_agent = "";

View File

@ -23,21 +23,23 @@ public class Xoa_fsys_mgr implements GfoInvkAble {
bin_plat_dir = root_dir.GenSubDir("bin").GenSubDir(bin_dir_name);
bin_extensions_dir = bin_any_dir.GenSubDir_nest("xowa", "xtns");
file_dir = root_dir.GenSubDir("file");
file_dir_bry_len = file_dir.To_http_file_bry().length;
wiki_dir = root_dir.GenSubDir("wiki");
cfg_lang_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "lang", "core");
cfg_wiki_core_dir = bin_any_dir.GenSubDir_nest("xowa", "cfg", "wiki", "core");
temp_dir = root_dir.GenSubDir("tmp");
app_mgr = new Launcher_app_mgr(app);
}
public Io_url Root_dir() {return root_dir;} private Io_url root_dir;
public Io_url File_dir() {return file_dir;} private Io_url file_dir;
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
public Io_url File_dir() {return file_dir;} private final Io_url file_dir;
public int File_dir_bry_len() {return file_dir_bry_len;} private final int file_dir_bry_len;
public Io_url Wiki_dir() {return wiki_dir;} public Xoa_fsys_mgr Wiki_dir_(Io_url v) {wiki_dir = v; return this;} private Io_url wiki_dir;
public Io_url Cfg_lang_core_dir() {return cfg_lang_core_dir;} private Io_url cfg_lang_core_dir;
public Io_url Cfg_wiki_core_dir() {return cfg_wiki_core_dir;} private Io_url cfg_wiki_core_dir;
public Io_url Cfg_lang_core_dir() {return cfg_lang_core_dir;} private final Io_url cfg_lang_core_dir;
public Io_url Cfg_wiki_core_dir() {return cfg_wiki_core_dir;} private final Io_url cfg_wiki_core_dir;
public Io_url Temp_dir() {return temp_dir;} public Xoa_fsys_mgr Temp_dir_(Io_url v) {temp_dir = v; return this;} private Io_url temp_dir; // set to /xowa/user/<name>/temp
public Io_url Bin_any_dir() {return bin_any_dir;} private Io_url bin_any_dir;
public Io_url Bin_extensions_dir() {return bin_extensions_dir;} private Io_url bin_extensions_dir;
public Io_url Bin_plat_dir() {return bin_plat_dir;} private Io_url bin_plat_dir;
public Io_url Bin_any_dir() {return bin_any_dir;} private final Io_url bin_any_dir;
public Io_url Bin_extensions_dir() {return bin_extensions_dir;} private final Io_url bin_extensions_dir;
public Io_url Bin_plat_dir() {return bin_plat_dir;} private final Io_url bin_plat_dir;
public Io_url Bin_db_dir() {return bin_any_dir.GenSubDir_nest("sql", "xowa");}
public Io_url Bin_data_os_cfg_fil() {return bin_plat_dir.GenSubFil_nest("xowa", "cfg", Xoa_gfs_mgr.Cfg_os);}
public Launcher_app_mgr App_mgr() {return app_mgr;} Launcher_app_mgr app_mgr;

View File

@ -18,4 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
public class Xof_html_elem {
public static final byte Tid_none = 0, Tid_img = 1, Tid_vid = 2, Tid_gallery = 3, Tid_gallery_v2 = 4, Tid_imap = 5;
public static boolean Tid_is_file(byte tid) {
switch (tid) {
case Tid_img: case Tid_vid: return true;
default: return false;
}
}
}

View File

@ -53,7 +53,6 @@ public class Xof_xfer_itm implements Xof_file_itm {
} private Xof_repo_itm trg_repo;
public int Trg_repo_idx() {return trg_repo_idx;} public Xof_xfer_itm Trg_repo_idx_(int trg_repo_idx) {this.trg_repo_idx = trg_repo_idx; return this;} private int trg_repo_idx = Xof_meta_itm.Repo_unknown;
public byte[] Trg_repo_root() {return trg_repo_root;} private byte[] trg_repo_root = Bry_.Empty; // HACK: needed for hdump
public byte[] Html_view_src_rel() {return html_view_src_rel;} public void Html_view_src_rel_(byte[] v) {html_view_src_rel = v;} private byte[] html_view_src_rel;
private byte[] Trg_html(byte mode_id, int width) {return url_bldr.Set_trg_html_(mode_id, trg_repo, lnki_ttl, lnki_md5, lnki_ext, width, lnki_thumbtime, lnki_page).Xto_bry();}
public Io_url Trg_file(byte mode_id, int width) {return url_bldr.Set_trg_file_(mode_id, trg_repo, lnki_ttl, lnki_md5, lnki_ext, width, lnki_thumbtime, lnki_page).Xto_url();}
public Xof_url_bldr Url_bldr(){ return url_bldr;}
@ -65,7 +64,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
img_is_thumbable = false;
orig_file_len = 0; // NOTE: cannot be -1, or else will always download orig; see ext rule chk and (orig_file_len < 0)
lnki_redirect = null; lnki_ttl = null; lnki_md5 = null; lnki_ext = null;
html_orig_src = html_view_src = html_view_src_rel = Bry_.Empty;
html_orig_src = html_view_src = Bry_.Empty;
trg_repo_idx = Int_.Neg1; meta_itm = null;
html_uid = Int_.Neg1; html_elem_tid = Xof_html_elem.Tid_none;
return this;
@ -76,7 +75,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
rv.img_is_thumbable = img_is_thumbable;
rv.orig_w = orig_w; rv.orig_h = orig_h; rv.orig_file_len = orig_file_len;
rv.lnki_redirect = lnki_redirect; rv.lnki_ttl = lnki_ttl; rv.lnki_md5 = lnki_md5; rv.lnki_ext = lnki_ext;
rv.html_w = html_w; rv.html_h = html_h; rv.html_view_src = html_view_src; rv.html_orig_src = html_orig_src; rv.html_view_src_rel = html_view_src_rel;
rv.html_w = html_w; rv.html_h = html_h; rv.html_view_src = html_view_src; rv.html_orig_src = html_orig_src;
rv.file_w = file_w;
rv.trg_repo_idx = trg_repo_idx;
rv.trg_repo_root = trg_repo_root;
@ -104,7 +103,6 @@ public class Xof_xfer_itm implements Xof_file_itm {
this.html_pass = true;
this.file_found = true;
}
public Xof_xfer_itm Init_for_test__hdump(int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] html_view_src_rel) {this.html_uid = uid; this.html_w = img_w; this.html_h = img_h; this.lnki_ttl = lnki_ttl; this.html_view_src_rel = html_view_src_rel; return this;}
public void Init_for_test__img(int html_w, int html_h, byte[] html_view_src, byte[] html_orig_src) {this.html_w = html_w; this.html_h = html_h; this.html_view_src = html_view_src; this.html_orig_src = html_orig_src;}
public Xof_xfer_itm Set__ttl(byte[] ttl, byte[] redirect) {
this.lnki_redirect = redirect;

View File

@ -20,20 +20,20 @@ import gplx.xowa.xtns.gallery.*;
import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.views.*;
public class Js_img_mgr {
public static void Update_img(Xoa_page page, Xof_xfer_itm itm) {
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), String_.new_utf8_(itm.Html_view_src()), itm.Orig_w(), itm.Orig_h(), String_.new_utf8_(itm.Html_orig_src()), itm.Gallery_mgr_h(), itm.Html_img_wkr());
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), String_.new_utf8_(itm.Html_view_src()), itm.Orig_w(), itm.Orig_h(), String_.new_utf8_(itm.Html_orig_src()), itm.Lnki_ttl(), itm.Gallery_mgr_h(), itm.Html_img_wkr());
}
public static void Update_img(Xoa_page page, Xof_fsdb_itm itm) {
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_url().To_http_file_str(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url().To_http_file_str(), itm.Gallery_mgr_h(), itm.Html_img_wkr());
Js_img_mgr.Update_img(page, itm.Html_uid(), itm.Lnki_type(), itm.Html_elem_tid(), itm.Html_w(), itm.Html_h(), itm.Html_url().To_http_file_str(), itm.Orig_w(), itm.Orig_h(), itm.Html_orig_url().To_http_file_str(), itm.Lnki_ttl(), itm.Gallery_mgr_h(), itm.Html_img_wkr());
}
public static void Update_link_missing(Xog_html_itm html_itm, String html_id) {
html_itm.Html_elem_atr_set_append(html_id, "class", " new");
}
private static void Update_img(Xoa_page page, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, int gallery_mgr_h, Js_img_wkr img_wkr) {
private static void Update_img(Xoa_page page, int uid, byte lnki_type, byte elem_tid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, byte[] lnki_ttl, int gallery_mgr_h, Js_img_wkr img_wkr) {
if (Env_.Mode_testing()) return;
Xog_html_itm html_itm = page.Tab().Html_itm();
switch (elem_tid) {
case Xof_html_elem.Tid_gallery_v2:
img_wkr.Html_update(page, html_itm, uid, html_w, html_h, html_src, orig_w, orig_h, orig_src);
img_wkr.Html_update(page, html_itm, uid, html_w, html_h, html_src, orig_w, orig_h, orig_src, lnki_ttl);
return;
}
String html_id = "xowa_file_img_" + uid;
@ -47,7 +47,7 @@ public class Js_img_mgr {
html_itm.Html_atr_set("xowa_gallery_div3_" + uid, "style", "margin:" + Gallery_html_wtr_utl.Calc_vpad(gallery_mgr_h, html_h) + "px auto;");
break;
case Xof_html_elem.Tid_imap:
img_wkr.Html_update(page, html_itm, uid, html_w, html_h, html_src, orig_w, orig_h, orig_src);
img_wkr.Html_update(page, html_itm, uid, html_w, html_h, html_src, orig_w, orig_h, orig_src, lnki_ttl);
break;
case Xof_html_elem.Tid_vid:
String html_id_vid = "xowa_file_play_" + uid;

View File

@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.files.gui; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
import gplx.xowa.gui.views.*;
public interface Js_img_wkr {
void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src);
void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, byte[] lnki_ttl);
}

View File

@ -19,17 +19,18 @@ package gplx.xowa.hdumps; import gplx.*; import gplx.xowa.*;
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.html.*; import gplx.xowa.gui.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.htmls.*; import gplx.xowa.hdumps.dbs.*;
public class Xodb_hdump_mgr {
private Xodb_file hdump_db_file; private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
private Xodb_file hdump_db_file;
public Xodb_hdump_mgr(Xow_wiki wiki) {
this.wiki = wiki;
load_mgr = new Hdump_load_mgr(this);
Tbl_(new Hdump_text_tbl());
Xoa_app app = wiki.App();
html_mgr.Init_by_app(app.Usr_dlg(), app.Fsys_mgr().File_dir().To_http_file_bry());
html_mgr.Init_by_app(app);
}
public Xow_wiki Wiki() {return wiki;} private final Xow_wiki wiki;
@gplx.Internal protected Hdump_load_mgr Load_mgr() {return load_mgr;} private Hdump_load_mgr load_mgr;
@gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr();
public Hdump_html_mgr Html_mgr() {return html_mgr;} private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl;
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
@gplx.Internal protected void Tbl_mem_() {Tbl_(new Hdump_text_tbl_mem());}
@ -59,17 +60,25 @@ public class Xodb_hdump_mgr {
public void Load(Xow_wiki wiki, Xoa_page page) {
if (!Enabled_chk()) return;
page.Root_(new Xop_root_tkn());
Hdump_page_itm hdump_page = new Hdump_page_itm();
load_mgr.Load(hdump_page, page.Revision_data().Id(), page.Url());
Hdump_page hpg = new Hdump_page();
load_mgr.Load(hpg, page.Revision_data().Id(), page.Url());
Load_page(wiki, page, hpg);
}
private void Load_page(Xow_wiki wiki, Xoa_page page, Hdump_page hpg) {
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
html_mgr.Write(tmp_bfr, wiki, hdump_page);
html_mgr.Write(tmp_bfr, wiki, hpg);
page.Hdump_data().Body_(tmp_bfr.XtoAryAndClear());
Xopg_html_data html_data = page.Html_data();
html_data.Display_ttl_(hpg.Display_ttl());
html_data.Content_sub_(hpg.Content_sub());
html_data.Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_mock(hpg.Sidebar_div()));
Hdump_page_body_srl.Load_html_modules(html_data.Module_mgr(), hpg);
tmp_bfr.Mkr_rls();
}
private void Tbl_(Hdump_text_tbl v) {
text_tbl = v;
save_mgr.Tbl_(text_tbl);
load_mgr.Tbl_(text_tbl);
// load_mgr.Tbl_(text_tbl);
}
private boolean Enabled_chk() {
if (enabled && hdump_db_file == null) hdump_db_file = Xodb_hdump_mgr_setup.Hdump_db_file_init(this);

View File

@ -16,15 +16,16 @@ 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.hdumps; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.saves.*;
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.loads.*; import gplx.xowa.hdumps.pages.*;
public class Xodb_hdump_mgr__save_tst {
@Before public void init() {fxt.Clear();} private Xodb_hdump_mgr__save_fxt fxt = new Xodb_hdump_mgr__save_fxt();
@Test public void Body() {
fxt.Test_save("abc", fxt.Make_row_body("abc"));
fxt.Test_save("abc", fxt.Make_row_body(0, "abc"));
}
@Test public void Img() {
fxt.Test_save("a[[File:A.png|test_caption]]b[[File:B.png|test_caption]]"
, fxt.Make_row_body("a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>b<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"test_caption\" xowa_img='1' /></a>")
, fxt.Make_row_body(2, "a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>b<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"test_caption\" xowa_img='1' /></a>")
, fxt.Make_row_img
( fxt.Make_img(0, 0, 0, "A.png", "trg/orig/7/0/A.png")
, fxt.Make_img(1, 0, 0, "B.png", "trg/orig/5/7/B.png")
@ -32,14 +33,26 @@ public class Xodb_hdump_mgr__save_tst {
);
}
@Test public void Display_title() {
fxt.Test_save("{{DISPLAYTITLE:A}}bcd", fxt.Make_row_body("bcd"), fxt.Make_row_display_title("A"));
fxt.Test_write("{{DISPLAYTITLE:A}}bcd", String_.Concat_lines_nl_skip_last
( "0|0"
, "<xo_1/>n|n|n|n|"
, "<xo_2/>A"
, "<xo_5/>bcd"
));
}
@Test public void Content_sub() {
fxt.Test_save("{{#isin:A}}bcd", fxt.Make_row_body("bcd"), fxt.Make_row_content_sub("<a href=\"/wiki/A\">A</a>"));
fxt.Test_write("{{#isin:A}}bcd", String_.Concat_lines_nl_skip_last
( "0|0"
, "<xo_1/>n|n|n|n|"
, "<xo_3/><a href=\"/wiki/A\">A</a>"
, "<xo_5/>bcd"
));
}
@Test public void Sidebar_div() {
fxt.Test_save("{{#related:A}}bcd", fxt.Make_row_body("bcd"), fxt.Make_row_sidebar_div(String_.Concat_lines_nl_skip_last
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
fxt.Test_write("{{#related:A}}bcd", String_.Concat_lines_nl_skip_last
( "0|0"
, "<xo_1/>n|n|n|n|"
, "<xo_4/><div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
, " <h3></h3>"
, " <div class=\"body\">"
, " <ul>"
@ -47,7 +60,8 @@ public class Xodb_hdump_mgr__save_tst {
, " </ul>"
, " </div>"
, "</div>"
)));
, "<xo_5/>bcd"
));
}
}
class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt {
@ -58,17 +72,25 @@ class Xodb_hdump_mgr__save_fxt extends Xodb_hdump_mgr__base_fxt {
hdump_mgr.Tbl_mem_();
hdump_mgr.Text_tbl().Provider_(Hdump_text_tbl_mem.Null_provider);
}
public Hdump_text_row Make_row_body(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, Bry_.new_utf8_(v));}
public Xof_xfer_itm Make_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Xof_xfer_itm().Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel));}
public Hdump_text_row Make_row_img(Xof_xfer_itm... itms) {
public Hdump_text_row Make_row_body(int imgs_count, String body) {
page.Hdump_data().Body_(Bry_.new_utf8_(body));
for (int i = 0; i < imgs_count; ++i)
page.Hdump_data().Imgs().Add(null);
Hdump_page_body_srl.Save(tmp_bfr, page);
return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, tmp_bfr.XtoAryAndClear());
}
public Hdump_data_img__base Make_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Hdump_data_img__basic().Init_by_base(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel));}
public Hdump_text_row Make_row_img(Hdump_data_img__base... itms) {
ListAdp tmp_list = ListAdp_.new_();
tmp_list.AddMany((Object[])itms);
byte[] imgs_bry = Hdump_save_mgr.Write_imgs(tmp_bfr, tmp_list);
return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, imgs_bry);
return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_data, imgs_bry);
}
public void Test_write(String raw, String expd) {
this.Exec_write(raw);
Hdump_page_body_srl.Save(tmp_bfr, page);
Tfds.Eq(expd, tmp_bfr.XtoStrAndClear());
}
public Hdump_text_row Make_row_display_title(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_display_ttl, Bry_.new_utf8_(v));}
public Hdump_text_row Make_row_content_sub(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_content_sub, Bry_.new_utf8_(v));}
public Hdump_text_row Make_row_sidebar_div(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_sidebar_div, Bry_.new_utf8_(v));}
public void Test_save(String raw, Hdump_text_row... expd) {
this.Exec_write(raw);
hdump_mgr.Save_mgr().Update(page);

View File

@ -16,18 +16,19 @@ 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.hdumps; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*;
import org.junit.*; import gplx.xowa.files.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.xtns.hieros.*;
public class Xodb_hdump_mgr__write_tst {
@Before public void init() {fxt.Clear();} private Xodb_hdump_mgr__write_fxt fxt = new Xodb_hdump_mgr__write_fxt();
@Test public void Image_full() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "A.png", "trg/orig/7/0/A.png"));
fxt.Test_write
fxt.Test_write_all
( "[[File:A.png|test_caption]]"
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\" xowa_img='0' /></a>");
}
@Test public void Image_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "A.png", "trg/thumb/7/0/A.png/220px.png"));
fxt.Test_write
fxt.Test_write_all
( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
@ -41,7 +42,7 @@ public class Xodb_hdump_mgr__write_tst {
}
@Test public void Audio_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 220, -1, "A.oga", ""));
fxt.Test_write
fxt.Test_write_all
( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
@ -56,7 +57,7 @@ public class Xodb_hdump_mgr__write_tst {
}
@Test public void Video_thumb() {
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "A.ogv", ""));
fxt.Test_write
fxt.Test_write_all
( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class=\"thumb tright\">"
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
@ -74,6 +75,28 @@ public class Xodb_hdump_mgr__write_tst {
, "</div>"
));
}
@Test public void Hiero() {
Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(fxt.Fxt());
hiero_fxt.Reset();
hiero_fxt.Init_hiero_A1_B1();
fxt.Test_write_frag("<hiero>A1</hiero>", "src='~{xowa_hiero_dir}hiero_A1.png'");
}
@Test public void Gallery() {
fxt.Test_write_all
( "<gallery>File:A.png|A1</gallery>", String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" xowa_gly_box_max='0'>"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" xowa_gly_box_w='0'>"
, " <div xowa_gly_box_w='0'>"
, " <div class=\"thumb\" style=\"height: 150px;\">A.png</div>"
, " <div class=\"gallerytext\"><p>A1"
, "</p>"
, ""
, " </div>"
, " </div>"
, " </li>"
, "</ul>"
));
}
}
class Xodb_hdump_mgr__base_fxt {
protected Xodb_hdump_mgr hdump_mgr;
@ -101,23 +124,25 @@ class Xodb_hdump_mgr__base_fxt {
class Xodb_hdump_mgr__write_fxt extends Xodb_hdump_mgr__base_fxt {
private ListAdp expd_itms_xfers = ListAdp_.new_();
@Override public void Clear_end() {expd_itms_xfers.Clear();}
public Xof_xfer_itm Make_xfer(int uid, int img_w, int img_h, String lnki_ttl, String img_src) {
Xof_xfer_itm rv = new Xof_xfer_itm();
rv.Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src));
return rv;
}
public void Expd_itms_xfers(Xof_xfer_itm... itms) {expd_itms_xfers.AddMany((Object[])itms);}
public void Test_write(String raw, String expd_html) {
public Hdump_data_img__base Make_xfer(int uid, int img_w, int img_h, String lnki_ttl, String img_src) {return new Hdump_data_img__basic().Init_by_base(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src));}
public void Expd_itms_xfers(Hdump_data_img__base... itms) {expd_itms_xfers.AddMany((Object[])itms);}
public void Test_write_all (String raw, String expd_html) {Test_write(Bool_.N, raw, expd_html);}
public void Test_write_frag(String raw, String expd_frag) {Test_write(Bool_.Y, raw, expd_frag);}
public void Test_write(boolean frag, String raw, String expd_html) {
this.Exec_write(raw);
Tfds.Eq_str_lines(expd_html, String_.new_utf8_(page.Hdump_data().Body()));
String actl_html = String_.new_utf8_(page.Hdump_data().Body());
if (frag)
Tfds.Eq_true(String_.Has(actl_html, expd_html), actl_html);
else
Tfds.Eq_str_lines(expd_html, actl_html);
if (expd_itms_xfers.Count() > 0) Tfds.Eq_ary_str(Xfer_to_str_ary(expd_itms_xfers), Xfer_to_str_ary(page.Hdump_data().Imgs()));
}
private static String[] Xfer_to_str_ary(ListAdp list) {
int len = list.Count();
String[] rv = new String[len];
for (int i = 0; i < len; ++i) {
Xof_xfer_itm itm = (Xof_xfer_itm)list.FetchAt(i);
rv[i] = String_.Concat_with_str("|", Int_.XtoStr(itm.Html_uid()), Int_.XtoStr(itm.Html_w()), Int_.XtoStr(itm.Html_h()), String_.new_utf8_(itm.Html_view_src_rel()));
Hdump_data_img__base itm = (Hdump_data_img__base)list.FetchAt(i);
rv[i] = itm.XtoStr();
}
return rv;
}

View File

@ -16,21 +16,38 @@ 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.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_img_itm {
public Hdump_img_itm(int idx, int view_w, int view_h, byte[] lnki_ttl, byte[] view_src) {
this.idx = idx;
import gplx.xowa.hdumps.dbs.*;
public abstract class Hdump_data_img__base implements XtoStrAble {
public Hdump_data_img__base Init_by_base(int uid, int view_w, int view_h, byte[] lnki_ttl, byte[] view_src) {
this.uid = uid;
this.view_w = view_w;
this.view_h = view_h;
this.lnki_ttl = lnki_ttl;
this.view_src = view_src;
return this;
}
public int Idx() {return idx;} private int idx;
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public abstract int Tid();
public int Uid() {return uid;} private int uid;
public int View_w() {return view_w;} private int view_w;
public int View_h() {return view_h;} private int view_h;
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte[] View_src() {return view_src;} private byte[] view_src;
@Override public String toString() {
return String_.Concat_with_str("|", Int_.XtoStr(idx), Int_.XtoStr(view_w), Int_.XtoStr(view_h), String_.new_utf8_(lnki_ttl), String_.new_utf8_(view_src));
public String XtoStr() {
return String_.Concat_with_str("|", Int_.XtoStr(this.Tid()), Int_.XtoStr(uid), Int_.XtoStr(view_w), Int_.XtoStr(view_h), String_.new_utf8_(lnki_ttl), String_.new_utf8_(view_src));
}
public static final Hdump_img_itm[] Ary_empty = new Hdump_img_itm[0];
public void Write(Bry_bfr bfr) {
bfr .Add_int_variable(Hdump_data_tid.Tid_img).Add_byte_pipe()
.Add_int_variable(this.Tid()).Add_byte_pipe()
.Add_int_variable(uid).Add_byte_pipe()
.Add_int_variable(view_w).Add_byte_pipe()
.Add_int_variable(view_h).Add_byte_pipe()
.Add(lnki_ttl).Add_byte_pipe()
.Add(view_src).Add_byte_pipe()
;
Write_hook(bfr);
bfr.Add_byte_nl();
}
@gplx.Virtual public void Write_hook(Bry_bfr bfr) {}
public static final Hdump_data_img__base[] Ary_empty = new Hdump_data_img__base[0];
public static final int Tid_basic = 0, Tid_gallery = 1;
}

View File

@ -0,0 +1,21 @@
/*
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.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_data_img__basic extends Hdump_data_img__base {
@Override public int Tid() {return Hdump_data_img__base.Tid_basic;}
}

View File

@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_data_img__gallery extends Hdump_data_img__base {
@Override public int Tid() {return Hdump_data_img__base.Tid_gallery;}
public Hdump_data_img__base Init_by_gallery(int box_max, int box_w, int img_w, int img_pad) {
this.box_max = box_max;
this.box_w = box_w;
this.img_w = img_w;
this.img_pad = img_pad;
return this;
}
public int Box_max() {return box_max;} private int box_max;
public int Box_w() {return box_w;} private int box_w;
public int Img_w() {return img_w;} private int img_w;
public int Img_pad() {return img_pad;} private int img_pad;
@Override public void Write_hook(Bry_bfr bfr) {
bfr .Add_int_variable(box_max).Add_byte_pipe()
.Add_int_variable(box_w).Add_byte_pipe()
.Add_int_variable(img_w).Add_byte_pipe()
.Add_int_variable(img_pad).Add_byte_pipe()
;
}
}

View File

@ -1,59 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
class Hdump_file_itm {
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
public byte Lnki_tid() {return lnki_tid;} private byte lnki_tid;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public byte Lnki_align_x() {return lnki_align_x;} private byte lnki_align_x;
public byte Lnki_align_y() {return lnki_align_y;} private byte lnki_align_y;
public byte Lnki_border() {return lnki_border;} private byte lnki_border;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} private double lnki_time;
public int Lnki_page() {return lnki_page;} private int lnki_page;
public boolean Lnki_media_icon() {return lnki_media_icon;} private boolean lnki_media_icon;
public byte[] Lnki_alt() {return lnki_alt;} private byte[] lnki_alt;
public byte[] Lnki_caption() {return lnki_caption;} private byte[] lnki_caption;
public void Parse(byte[] src) {
int len = src.length;
int pos = 0;
int fld_idx = 0, fld_bgn = 0;
while (pos < len) {
byte b = src[pos];
if (b == Byte_ascii.Pipe) {
switch (fld_idx) {
case 0: lnki_ttl = Bry_.Mid(src, fld_bgn, pos); break;
case 2: lnki_tid = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 3: lnki_w = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
case 4: lnki_h = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
case 5: lnki_align_x = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 6: lnki_align_y = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 7: lnki_border = Bry_.Xto_byte_by_int(src, fld_bgn, pos, Byte_.MaxValue_127); break;
case 8: lnki_upright = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
case 9: lnki_time = Bry_.XtoDoubleByPos(src, fld_bgn, pos); break;
case 10: lnki_page = Bry_.Xto_int_or(src, fld_bgn, pos, -1); break;
case 11: lnki_media_icon = src[pos] == Byte_ascii.Ltr_y; break;
case 12: lnki_alt = Bry_.Mid(src, fld_bgn, pos); break;
case 13: lnki_caption = Bry_.Mid(src, fld_bgn, pos); break;
}
++fld_idx;
}
}
}
}

View File

@ -0,0 +1,27 @@
/*
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.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_module_mgr {
public boolean Math_exists() {return math_exists;} public void Math_exists_(boolean v) {math_exists = v;} private boolean math_exists;
public boolean Imap_exists() {return imap_exists;} public void Imap_exists_(boolean v) {imap_exists = v;} private boolean imap_exists;
public boolean Gallery_packed_exists() {return gallery_packed_exists;} public void Gallery_packed_exists_(boolean v) {gallery_packed_exists = v;} private boolean gallery_packed_exists;
public boolean Hiero_exists() {return hiero_exists;} public void Hiero_exists_(boolean v) {hiero_exists = v;} private boolean hiero_exists;
public void Clear() {
math_exists = imap_exists = gallery_packed_exists = hiero_exists = false;
}
}

View File

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_page {
public int Page_id() {return page_id;} private int page_id;
public Xoa_url Page_url() {return page_url;} private Xoa_url page_url;
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
public int Img_count() {return img_count;} public void Img_count_(int v) {img_count = v;} private int img_count;
public Hdump_module_mgr Module_mgr() {return module_mgr;} private Hdump_module_mgr module_mgr = new Hdump_module_mgr();
public byte[] Page_body() {return page_body;} public void Page_body_(byte[] v) {this.page_body = v;} private byte[] page_body;
public byte[] Display_ttl() {return display_ttl;} public void Display_ttl_(byte[] v) {this.display_ttl = v;} private byte[] display_ttl;
public byte[] Content_sub() {return content_sub;} public void Content_sub_(byte[] v) {this.content_sub = v;} private byte[] content_sub;
public byte[] Sidebar_div() {return sidebar_div;} public void Sidebar_div_(byte[] v) {this.sidebar_div = v;} private byte[] sidebar_div;
public int[] Redlink_uids() {return redlink_uids;} public void Redlink_uids_(int[] v) {redlink_uids = v;} private int[] redlink_uids;
public Hdump_data_img__base[] Img_itms() {return img_itms;} public void Img_itms_(Hdump_data_img__base[] v) {this.img_itms = v;} private Hdump_data_img__base[] img_itms;
public OrderedHash Gly_itms() {return gly_itms;} private OrderedHash gly_itms = OrderedHash_.new_();
public void Init(int page_id, Xoa_url page_url) {
this.page_id = page_id;
this.page_url = page_url;
content_sub = sidebar_div = Bry_.Empty;
display_ttl = null;
img_itms = Hdump_data_img__base.Ary_empty;
module_mgr.Clear();
gly_itms.Clear();
}
}

View File

@ -1,38 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_page_itm {
public int Page_id() {return page_id;} private int page_id;
public Xoa_url Page_url() {return page_url;} private Xoa_url page_url;
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
public byte[] Page_body() {return page_body;} public void Page_body_(byte[] v) {this.page_body = v;} private byte[] page_body = Bry_.Empty;
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl = Bry_.Empty;
public byte[] Content_sub() {return content_sub;} private byte[] content_sub = Bry_.Empty;
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs = Bry_.Ary_empty;
public Hdump_img_itm[] Img_itms() {return img_itms;} public void Img_itms_(Hdump_img_itm[] v) {this.img_itms = v;} private Hdump_img_itm[] img_itms = Hdump_img_itm.Ary_empty;
public void Init(int page_id, Xoa_url page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
this.page_id = page_id;
this.page_url = page_url;
this.version_id = version_id;
this.display_ttl = display_ttl;
this.content_sub = content_sub;
this.page_body = page_body;
this.sidebar_divs = sidebar_divs;
this.img_itms = img_itms;
}
}

View File

@ -0,0 +1,21 @@
/*
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.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_data_tid { // SERIALIZED
public static final int Tid_img = 1, Tid_redlink = 2, Tid_gallery = 3, Tid_imap = 4;
}

View File

@ -17,5 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Hdump_text_row_tid { // NOTE: SERIALIZED
public static final int Tid_body = 0, Tid_img = 1, Tid_gallery = 2, Tid_imap = 3, Tid_display_ttl = 4, Tid_content_sub = 5, Tid_sidebar_div = 6;
public static final int Tid_body = 0, Tid_data = 1;
}

View File

@ -19,7 +19,7 @@ package gplx.xowa.hdumps.dbs; import gplx.*; import gplx.xowa.*; import gplx.xow
import gplx.dbs.*;
public class Hdump_text_tbl {
private Db_stmt stmt_select, stmt_insert, stmt_delete;
public Db_provider Provider() {return provider;} public void Provider_(Db_provider v) {this.Rls_all(); provider = v;} private Db_provider provider;
public Db_provider Provider() {return provider;} public Hdump_text_tbl Provider_(Db_provider v) {this.Rls_all(); provider = v; return this;} private Db_provider provider;
@gplx.Virtual public void Delete_by_page(int page_id) {
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
try {stmt_delete.Clear().Val_int_(page_id).Exec_delete();}

View 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.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.btries.*;
public class Hdump_html_consts {
public static final byte[]
A_href_bgn = Bry_.new_ascii_("/wiki/File:")
, Bry_img_style_bgn = Bry_.new_ascii_("style='width:")
, Bry_img_style_end = Bry_.new_ascii_("px;'")
;
public static final byte
Tid_dir = 1, Tid_img = 2, Tid_img_style = 3, Tid_file_play = 4, Tid_file_info = 5, Tid_file_mgnf = 6
, Tid_hiero_dir = 7, Tid_gallery_box_max = 8, Tid_gallery_box_w = 9, Tid_gallery_img_w = 10, Tid_gallery_img_pad = 11
;
public static final byte[]
Key_dir = Bry_.new_ascii_("~{xowa_dir}")
, Key_img = Bry_.new_ascii_("xowa_img='")
, Key_img_style = Bry_.new_ascii_("xowa_img_style='")
, Key_file_play = Bry_.new_ascii_("<xowa_play id='")
, Key_file_info = Bry_.new_ascii_("<xowa_info id='")
, Key_file_mgnf = Bry_.new_ascii_("<xowa_mgnf id='")
, Key_hiero_dir = Bry_.new_ascii_("~{xowa_hiero_dir}")
, Key_gallery_box_max = Bry_.new_ascii_("xowa_gly_box_max='")
, Key_gallery_box_w = Bry_.new_ascii_("xowa_gly_box_w='")
, Key_gallery_img_w = Bry_.new_ascii_("xowa_gly_img_w='")
, Key_gallery_img_pad = Bry_.new_ascii_("xowa_gly_img_pad='")
;
public static Btrie_slim_mgr trie_() {
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
trie_itm(rv, Tid_dir , Byte_ascii.Nil , Key_dir);
trie_itm(rv, Tid_img , Byte_ascii.Apos , Key_img);
trie_itm(rv, Tid_img_style , Byte_ascii.Apos , Key_img_style);
trie_itm(rv, Tid_file_play , Byte_ascii.Apos , Key_file_play);
trie_itm(rv, Tid_file_info , Byte_ascii.Apos , Key_file_info);
trie_itm(rv, Tid_file_mgnf , Byte_ascii.Apos , Key_file_mgnf);
trie_itm(rv, Tid_hiero_dir , Byte_ascii.Nil , Key_hiero_dir);
trie_itm(rv, Tid_gallery_box_max , Byte_ascii.Apos , Key_gallery_box_max);
trie_itm(rv, Tid_gallery_box_w , Byte_ascii.Apos , Key_gallery_box_w);
trie_itm(rv, Tid_gallery_img_w , Byte_ascii.Apos , Key_gallery_img_w);
trie_itm(rv, Tid_gallery_img_pad , Byte_ascii.Apos , Key_gallery_img_pad);
return rv;
}
private static void trie_itm(Btrie_slim_mgr trie, byte tid, byte subst_end_byte, byte[] key_bry) {
boolean elem_is_xnde = key_bry[0] == Byte_ascii.Lt;
Hdump_html_fmtr_itm itm = new Hdump_html_fmtr_itm(tid, elem_is_xnde, subst_end_byte, key_bry);
trie.Add_obj(key_bry, itm);
}
}

View File

@ -16,16 +16,22 @@ 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.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.hdumps.core.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.html.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.xtns.gallery.*;
public class Hdump_html_fmtr__body implements Bry_fmtr_arg {
private Bry_rdr bry_rdr = new Bry_rdr();
private Xow_wiki wiki; private Hdump_page_itm page;
private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._; private byte[] file_dir;
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte [] file_dir) {this.usr_dlg = usr_dlg; this.file_dir = file_dir;}
public void Init_by_page(Xow_wiki wiki, Hdump_page_itm page) {this.wiki = wiki; this.page = page;}
private Xow_wiki wiki; private Hdump_page page;
private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_._; private byte[] root_dir, file_dir, hiero_img_dir; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public void Init_by_app(Xoa_app app) {
this.usr_dlg = app.Usr_dlg();
this.root_dir = app.Fsys_mgr().Root_dir().To_http_file_bry();
this.file_dir = app.Fsys_mgr().File_dir().To_http_file_bry();
this.hiero_img_dir = gplx.xowa.xtns.hieros.Hiero_xtn_mgr.Hiero_root_dir(app).GenSubDir("img").To_http_file_bry();
}
public void Init_by_page(Xow_wiki wiki, Hdump_page page) {this.wiki = wiki; this.page = page;}
public void XferAry(Bry_bfr bfr, int idx) {
byte[] src = page.Page_body(); int len = src.length;
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
Hdump_data_img__base[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
bry_rdr.Src_(src);
int pos = 0; int rng_bgn = -1;
Xow_html_mgr html_mgr = wiki.Html_mgr();
@ -44,71 +50,79 @@ public class Hdump_html_fmtr__body implements Bry_fmtr_arg {
}
pos = trie.Match_pos(); // position after match; EX: "xowa_img='" positions after "'"
Hdump_html_fmtr_itm itm = (Hdump_html_fmtr_itm)o;
pos = Write_img(bfr, html_mgr, html_fmtr, page, src, imgs, imgs_len, pos, itm); // note no +1; Write_img return pos after }
pos = Write_data(bfr, html_mgr, html_fmtr, page, src, imgs, imgs_len, pos, itm); // note no +1; Write_data return pos after }
}
}
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
}
private int Write_img(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_file_html_fmtr__base fmtr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int uid_bgn, Hdump_html_fmtr_itm itm) {
private int Write_data(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_file_html_fmtr__base fmtr, Hdump_page hpg, byte[] src, Hdump_data_img__base[] imgs, int imgs_len, int uid_bgn, Hdump_html_fmtr_itm itm) {
bry_rdr.Pos_(uid_bgn);
int uid = bry_rdr.Read_int_to(Byte_ascii.Apos);
int uid_end = bry_rdr.Pos(); // set uid_end after "'"
int uid = itm.Subst_end_byte() == Byte_ascii.Nil ? -1 : bry_rdr.Read_int_to(itm.Subst_end_byte());
int uid_end = bry_rdr.Pos(); // set uid_end after subst_end
int rv = uid_end;
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url().Xto_full_str_safe(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url().Xto_full_str_safe(), uid, imgs_len); return uid_end;}
Hdump_img_itm img = imgs[uid];
int img_view_w = img.View_w();
byte tid = itm.Tid();
if (tid == Tid_img_style) {
bfr.Add(Bry_img_style_bgn);
bfr.Add_int_variable(img_view_w);
bfr.Add(Bry_img_style_end);
return rv;
switch (tid) {
case Hdump_html_consts.Tid_dir: bfr.Add(root_dir); return rv;
case Hdump_html_consts.Tid_hiero_dir: bfr.Add(hiero_img_dir); return rv;
}
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", hpg.Page_url().Xto_full_str_safe(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", hpg.Page_url().Xto_full_str_safe(), uid, imgs_len); return uid_end;}
Hdump_data_img__base img = imgs[uid];
int img_view_w = img.View_w();
switch (tid) {
case Hdump_html_consts.Tid_img_style:
bfr.Add(Hdump_html_consts.Bry_img_style_bgn);
bfr.Add_int_variable(img_view_w);
bfr.Add(Hdump_html_consts.Bry_img_style_end);
return rv;
}
byte[] a_title = img.Lnki_ttl();
byte[] a_href = Bry_.Add(A_href_bgn, a_title);
byte[] a_href = Bry_.Add(Hdump_html_consts.A_href_bgn, a_title);
switch (tid) {
case Tid_file_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, html_mgr.Img_media_info_btn()); return rv;
case Tid_file_mgnf: fmtr.Html_thumb_part_magnify(bfr, uid, a_href, a_title, html_mgr.Img_thumb_magnify()); return rv;
case Tid_file_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, html_mgr.Img_media_play_btn()); return rv;
case Hdump_html_consts.Tid_file_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, html_mgr.Img_media_info_btn()); return rv;
case Hdump_html_consts.Tid_file_mgnf: fmtr.Html_thumb_part_magnify(bfr, uid, a_href, a_title, html_mgr.Img_thumb_magnify()); return rv;
case Hdump_html_consts.Tid_file_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, html_mgr.Img_media_play_btn()); return rv;
case Hdump_html_consts.Tid_gallery_box_max: {
Hdump_data_img__gallery gly = (Hdump_data_img__gallery)img;
if (gly.Box_max() > 0) { // -1 means no box_max
byte[] style = Gallery_mgr_base.box_style_max_width_fmtr.Bld_bry_many(tmp_bfr, gly.Box_max());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
}
return rv;
}
case Hdump_html_consts.Tid_gallery_box_w: {
Hdump_data_img__gallery gly = (Hdump_data_img__gallery)img;
byte[] style = Gallery_mgr_base.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Box_w());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
return rv;
}
case Hdump_html_consts.Tid_gallery_img_w: {
Hdump_data_img__gallery gly = (Hdump_data_img__gallery)img;
byte[] style = Gallery_mgr_base.hdump_box_w_fmtr.Bld_bry_many(tmp_bfr, gly.Img_w());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
return rv;
}
case Hdump_html_consts.Tid_gallery_img_pad: {
Hdump_data_img__gallery gly = (Hdump_data_img__gallery)img;
byte[] style = Gallery_mgr_base.hdump_img_pad_fmtr.Bld_bry_many(tmp_bfr, gly.Img_pad());
Html_wtr.Write_atr_bry(bfr, Bool_.N, Byte_ascii.Quote, Html_atr_.Style_bry, style);
return rv;
}
}
byte[] img_src = Bry_.Add(file_dir, img.View_src());
if (tid == Tid_img) {
if (tid == Hdump_html_consts.Tid_img) {
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.View_h());
}
return rv;
}
private static final Bry_fmtr fmtr_img = Bry_fmtr.new_("src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
private static final byte[] A_href_bgn = Bry_.new_ascii_("/wiki/File:"), Bry_img_style_bgn = Bry_.new_ascii_("style='width:"), Bry_img_style_end = Bry_.new_ascii_("px;'");
public static final byte[]
Key_img = Bry_.new_ascii_("xowa_img='")
, Key_img_style = Bry_.new_ascii_("xowa_img_style='")
, Key_file_play = Bry_.new_ascii_("<xowa_play id='")
, Key_file_info = Bry_.new_ascii_("<xowa_info id='")
, Key_file_mgnf = Bry_.new_ascii_("<xowa_mgnf id='")
;
private static final byte Tid_img = 1, Tid_img_style = 2, Tid_file_play = 3, Tid_file_info = 4, Tid_file_mgnf = 5;
private static final Btrie_slim_mgr trie = trie_();
private static Btrie_slim_mgr trie_() {
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
trie_itm(rv, Tid_img , "xowa_img='");
trie_itm(rv, Tid_img_style , "xowa_img_style='");
trie_itm(rv, Tid_file_play , "<xowa_play id='");
trie_itm(rv, Tid_file_info , "<xowa_info id='");
trie_itm(rv, Tid_file_mgnf , "<xowa_mgnf id='");
return rv;
}
private static void trie_itm(Btrie_slim_mgr trie, byte tid, String key_str) {
byte[] key_bry = Bry_.new_utf8_(key_str);
boolean elem_is_xnde = key_bry[0] == Byte_ascii.Lt;
Hdump_html_fmtr_itm itm = new Hdump_html_fmtr_itm(tid, key_bry, elem_is_xnde);
trie.Add_obj(key_bry, itm);
}
public static final Bry_fmtr fmtr_img = Bry_fmtr.new_("src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
private static final Btrie_slim_mgr trie = Hdump_html_consts.trie_();
}
class Hdump_html_fmtr_itm {
public Hdump_html_fmtr_itm(byte tid, byte[] key, boolean elem_is_xnde) {this.tid = tid; this.key = key; this.elem_is_xnde = elem_is_xnde;}
public byte Tid() {return tid;} private byte tid;
public byte[] Key() {return key;} private byte[] key;
public boolean Elem_is_xnde() {return elem_is_xnde;} private boolean elem_is_xnde;
public Hdump_html_fmtr_itm(byte tid, boolean elem_is_xnde, byte subst_end_byte, byte[] key) {this.tid = tid; this.key = key; this.elem_is_xnde = elem_is_xnde; this.subst_end_byte = subst_end_byte;}
public byte Tid() {return tid;} private final byte tid;
public byte[] Key() {return key;} private final byte[] key;
public boolean Elem_is_xnde() {return elem_is_xnde;} private final boolean elem_is_xnde;
public byte Subst_end_byte() {return subst_end_byte;} private final byte subst_end_byte;
}

View File

@ -16,15 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
import gplx.xowa.hdumps.core.*;
public class Hdump_html_mgr {
private Hdump_html_fmtr__sidebars sidebars_fmtr = new Hdump_html_fmtr__sidebars();
private Hdump_html_fmtr__body body_fmtr = new Hdump_html_fmtr__body();
public Hdump_html_mgr Init_by_app(Gfo_usr_dlg usr_dlg, byte[] file_dir) {body_fmtr.Init_by_app(usr_dlg, file_dir); return this;}
public Bry_fmtr Skin_fmtr() {return skin_fmtr;} private Bry_fmtr skin_fmtr = Bry_fmtr.new_("~{display_ttl}~{content_sub}~{sidebar_divs}~{body_html}", "display_ttl", "content_sub", "sidebar_divs", "body_html");
public void Write(Bry_bfr bfr, Xow_wiki wiki, Hdump_page_itm page) {
public Hdump_html_mgr Init_by_app(Xoa_app app) {body_fmtr.Init_by_app(app); return this;}
public void Write(Bry_bfr bfr, Xow_wiki wiki, Hdump_page page) {
body_fmtr.Init_by_page(wiki, page);
sidebars_fmtr.Init_by_page(page);
skin_fmtr.Bld_bfr_many(bfr, page.Display_ttl(), page.Content_sub(), sidebars_fmtr, body_fmtr);
body_fmtr.XferAry(bfr, 0);
}
}

View File

@ -16,8 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
import org.junit.*;
import org.junit.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*;
public class Hdump_html_mgr_tst {
@Before public void init() {
fxt.Clear();
@ -64,23 +63,47 @@ public class Hdump_html_mgr_tst {
, " </div>"
));
}
@Test public void Hiero_dir() {
fxt .Init_body("<img src='~{xowa_hiero_dir}hiero_a&A1.png' />")
.Test_html("<img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' />");
}
@Test public void Gallery() {
fxt.Clear_imgs();
fxt .Init_gly(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png", 800, 155, 150, 15);
fxt .Init_body(String_.Concat_lines_nl_skip_last
( "<ul xowa_gly_box_max='0'>"
, " <li class='gallerybox' xowa_gly_box_w='0'>"
, " <div xowa_gly_box_w='0'>"
, " <div class='thumb' xowa_gly_img_w='0'>"
, " <div xowa_gly_img_pad='0'>"
))
.Test_html(String_.Concat_lines_nl_skip_last
( "<ul style=\"max-width:800px;_width:800px;\">"
, " <li class='gallerybox' style=\"width:155px;\">"
, " <div style=\"width:155px;\">"
, " <div class='thumb' style=\"width:150px;\">"
, " <div style=\"margin:15px auto;\">"
));
}
}
class Hdump_html_mgr_fxt {
private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
private Hdump_page_itm page = new Hdump_page_itm();
private Hdump_html_mgr html_mgr;
private Bry_bfr bfr = Bry_bfr.reset_(255);
private ListAdp img_list = ListAdp_.new_();
private Xow_wiki wiki;
public Hdump_page Hpg() {return hpg;} private Hdump_page hpg = new Hdump_page();
public void Clear() {
html_mgr.Init_by_app(Gfo_usr_dlg_.Null, Bry_.new_ascii_("file:///mem/xowa/file/"));
Xoa_app app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
html_mgr = wiki.Db_mgr().Hdump_mgr().Html_mgr();
}
public Hdump_html_mgr_fxt Init_body(String body) {page.Page_body_(Bry_.new_utf8_(body)); return this;}
public Hdump_html_mgr_fxt Init_img(int id, int w, int h, String ttl, String src) {img_list.Add(new Hdump_img_itm(id, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public void Clear_imgs() {img_list.Clear();}
public Hdump_html_mgr_fxt Init_body(String body) {hpg.Page_body_(Bry_.new_utf8_(body)); return this;}
public Hdump_html_mgr_fxt Init_img(int id, int w, int h, String ttl, String src) {img_list.Add(new Hdump_data_img__basic().Init_by_base(id, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public Hdump_html_mgr_fxt Init_gly(int id, int w, int h, String ttl, String src, int box_max, int box_w, int img_w, int img_pad) {img_list.Add(new Hdump_data_img__gallery().Init_by_gallery(box_max, box_w, img_w, img_pad).Init_by_base(id, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public Hdump_html_mgr_fxt Test_html(String expd) {
if (img_list.Count() > 0) page.Img_itms_((Hdump_img_itm[])img_list.XtoAryAndClear(Hdump_img_itm.class));
html_mgr.Write(bfr, wiki, page);
if (img_list.Count() > 0) hpg.Img_itms_((Hdump_data_img__base[])img_list.XtoAryAndClear(Hdump_data_img__base.class));
html_mgr.Write(bfr, wiki, hpg);
Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear());
return this;
}

View File

@ -16,60 +16,63 @@ 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.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*;
import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.pages.*;
import gplx.xowa.pages.skins.*;
public class Hdump_load_mgr {
private Xodb_hdump_mgr hdump_mgr;
private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
private byte[] page_text, display_ttl, content_sub;
private ListAdp sidebar_divs = ListAdp_.new_(), img_itms = ListAdp_.new_();
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private ListAdp tmp_text_itms = ListAdp_.new_();
private Bry_rdr bry_rdr = new Bry_rdr();
private Xodb_hdump_mgr hdump_mgr; private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private Bry_rdr rdr = new Bry_rdr(); // private Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr();
private ListAdp tmp_rows = ListAdp_.new_(), img_itms = ListAdp_.new_();
public Hdump_load_mgr(Xodb_hdump_mgr hdump_mgr) {this.hdump_mgr = hdump_mgr;}
public byte Zip_tid() {return zip_tid;} public void Zip_tid_(byte v) {zip_tid = v;} private byte zip_tid = gplx.ios.Io_stream_.Tid_file;
public void Tbl_(Hdump_text_tbl v) {text_tbl = v;}
public void Clear() {
page_text = display_ttl = content_sub = null;
sidebar_divs.Clear();
img_itms.Clear();
}
public void Load(Hdump_page_itm page, int page_id, Xoa_url page_url) {
public void Load(Hdump_page hpg, int page_id, Xoa_url page_url) {
Db_provider provider = hdump_mgr.Db_provider_by_page(page_id);
text_tbl.Provider_(provider);
text_tbl.Select_by_page(tmp_text_itms, page_id);
Load_itm(page, page_id, page_url, tmp_text_itms);
text_tbl.Provider_(provider).Select_by_page(tmp_rows, page_id);
Load_rows(hpg, page_id, page_url, tmp_rows);
}
public void Load_itm(Hdump_page_itm page, int page_id, Xoa_url page_url, ListAdp itms) {
this.Clear();
int len = itms.Count();
public void Load_rows(Hdump_page hpg, int page_id, Xoa_url page_url, ListAdp rows) {
hpg.Init(page_id, page_url);
img_itms.Clear();
int len = rows.Count();
for (int i = 0; i < len; ++i) {
Hdump_text_row itm = (Hdump_text_row)itms.FetchAt(i);
switch (itm.Tid()) {
case Hdump_text_row_tid.Tid_body: Load_itm_body(itm); break;
case Hdump_text_row_tid.Tid_img: Load_itm_img(itm); break;
case Hdump_text_row_tid.Tid_sidebar_div: sidebar_divs.Add(zip_mgr.Unzip(zip_tid, itm.Data())); break;
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(zip_tid, itm.Data()); break;
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(zip_tid, itm.Data()); break;
Hdump_text_row row = (Hdump_text_row)rows.FetchAt(i);
switch (row.Tid()) {
case Hdump_text_row_tid.Tid_body: Hdump_page_body_srl.Load(hpg, rdr, row.Data()); break;
case Hdump_text_row_tid.Tid_data: Load_data(hpg, row); break;
}
}
page.Init(page_id, page_url, 0, display_ttl, content_sub, page_text
, (byte[][])sidebar_divs.XtoAryAndClear(byte[].class)
, (Hdump_img_itm[])img_itms.XtoAryAndClear(Hdump_img_itm.class)
);
itms.Clear();
rows.Clear();
}
public void Load_itm_body(Hdump_text_row itm) {
page_text = zip_mgr.Unzip(zip_tid, itm.Data());
}
public void Load_itm_img(Hdump_text_row itm) {
bry_rdr.Src_(itm.Data());
while (!bry_rdr.Pos_is_eos()) {
int uid = bry_rdr.Read_int_to_pipe();
int w = bry_rdr.Read_int_to_pipe();
int h = bry_rdr.Read_int_to_pipe();
byte[] ttl = bry_rdr.Read_bry_to_pipe();
byte[] src = bry_rdr.Read_bry_to_nl();
Hdump_img_itm img_itm = new Hdump_img_itm(uid, w, h, ttl, src);
img_itms.Add(img_itm);
public void Load_data(Hdump_page hpg, Hdump_text_row row) {
rdr.Src_(row.Data());
while (!rdr.Pos_is_eos()) {
int tid = rdr.Read_int_to_pipe();
switch (tid) {
case Hdump_data_tid.Tid_img :
case Hdump_data_tid.Tid_gallery : Load_data_img(); break; // 1|0|220|110|A.png|commons/7/0/orig/A.png
case Hdump_data_tid.Tid_redlink : Load_data_redlink(hpg); break; // 2|2|0|1
}
}
if (img_itms.Count() > 0) hpg.Img_itms_((Hdump_data_img__base[])img_itms.XtoAryAndClear(Hdump_data_img__base.class));
}
private void Load_data_img() {
int tid = rdr.Read_int_to_pipe();
int uid = rdr.Read_int_to_pipe();
int w = rdr.Read_int_to_pipe();
int h = rdr.Read_int_to_pipe();
byte[] ttl = rdr.Read_bry_to_pipe();
byte[] src = rdr.Read_bry_to_pipe();
Hdump_data_img__base img_itm = null;
switch (tid) {
case Hdump_data_img__base.Tid_basic : img_itm = new Hdump_data_img__basic().Init_by_base(uid, w, h, ttl, src); break;
case Hdump_data_img__base.Tid_gallery : img_itm = new Hdump_data_img__gallery().Init_by_gallery(rdr.Read_int_to_pipe(), rdr.Read_int_to_pipe(), rdr.Read_int_to_pipe(), rdr.Read_int_to_pipe()).Init_by_base(uid, w, h, ttl, src); break;
}
rdr.Pos_add_one();
img_itms.Add(img_itm);
}
public void Load_data_redlink(Hdump_page hpg) {
int len = rdr.Read_int_to_pipe();
int[] redlink_uids = new int[len];
for (int i = 0; i < len; ++i)
redlink_uids[i] = rdr.Read_int_to_pipe();
hpg.Redlink_uids_(redlink_uids);
}
}

View File

@ -16,14 +16,22 @@ 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.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*;
import org.junit.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.saves.*; import gplx.xowa.hdumps.pages.*;
public class Hdump_load_mgr_tst {
@Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt();
@Test public void Body() {
fxt.Init_row_body("<body/>");
fxt.Init_row_body("<body/>", null, null, null);
fxt.Expd_body("<body/>");
fxt.Test_load(0);
}
@Test public void Body_all() {
fxt.Init_row_body("<body/>", "test_display_ttl", "test_content_sub", "test_sidebar_div");
fxt.Expd_body("<body/>");
fxt.Expd_display_ttl("test_display_ttl");
fxt.Expd_content_sub("test_content_sub");
fxt.Expd_sidebar_div("test_sidebar_div");
fxt.Test_load(0);
}
@Test public void Img() {
fxt.Init_row_img
( fxt.Make_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png")
@ -36,35 +44,53 @@ public class Hdump_load_mgr_tst {
}
class Hdump_load_mgr_fxt {
private Hdump_load_mgr load_mgr;
private Hdump_page_itm page = new Hdump_page_itm();
private Hdump_page hpg = new Hdump_page();
private ListAdp init_rows = ListAdp_.new_();
private String expd_body;
private String expd_body, expd_display_ttl, expd_content_sub, expd_sidebar_div;
private ListAdp expd_imgs = ListAdp_.new_();
private int page_id = 0; private Xoa_url page_url;
public void Clear() {
load_mgr = new Hdump_load_mgr(null);
load_mgr.Zip_tid_(gplx.ios.Io_stream_.Tid_file);
init_rows.Clear();
expd_body = null;
expd_body = expd_display_ttl = expd_content_sub = expd_sidebar_div = null;
expd_imgs.Clear();
page_url = Xoa_url.new_(Bry_.new_ascii_("enwiki"), Bry_.new_ascii_("Page_1"));
}
public Xof_xfer_itm Make_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Xof_xfer_itm().Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel));}
public void Init_row_img(Xof_xfer_itm... itms) {
public Hdump_data_img__base Make_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Hdump_data_img__basic().Init_by_base(uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel));}
public void Init_row_img(Hdump_data_img__base... itms) {
ListAdp tmp_list = ListAdp_.new_();
Bry_bfr bfr = Bry_bfr.new_(255);
tmp_list.AddMany((Object[])itms);
byte[] imgs_bry = Hdump_save_mgr.Write_imgs(bfr, tmp_list);
init_rows.Add(new Hdump_text_row(0, Hdump_text_row_tid.Tid_img, imgs_bry));
init_rows.Add(new Hdump_text_row(0, Hdump_text_row_tid.Tid_data, imgs_bry));
}
public Hdump_load_mgr_fxt Init_row_body(String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Init_row_img (String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img , Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Init_row_body(String body, String display_ttl, String content_sub, String sidebar_div) {
Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
Xoa_app app = Xoa_app_fxt.app_();
Xow_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
Xoa_page page = Xoa_page.new_(wiki, Xoa_ttl.parse_(wiki, Bry_.new_ascii_("Page_1")));
if (display_ttl != null) page.Html_data().Display_ttl_(Bry_.new_utf8_(display_ttl));
if (content_sub != null) page.Html_data().Content_sub_(Bry_.new_utf8_(content_sub));
if (sidebar_div != null) page.Html_data().Xtn_skin_mgr().Add(new Xopg_xtn_skin_itm_mock(Bry_.new_utf8_(sidebar_div)));
page.Hdump_data().Body_(Bry_.new_utf8_(body));
Hdump_page_body_srl.Save(tmp_bfr, page);
init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, tmp_bfr.XtoAryAndClear()));
return this;
}
public Hdump_load_mgr_fxt Init_row_img (String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_data, Bry_.new_utf8_(data))); return this;}
public Hdump_load_mgr_fxt Expd_body(String v) {this.expd_body = v; return this;}
public Hdump_load_mgr_fxt Expd_img(int idx, int w, int h, String ttl, String src) {expd_imgs.Add(new Hdump_img_itm(idx, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public Hdump_load_mgr_fxt Expd_display_ttl(String v) {this.expd_display_ttl = v; return this;}
public Hdump_load_mgr_fxt Expd_content_sub(String v) {this.expd_content_sub = v; return this;}
public Hdump_load_mgr_fxt Expd_sidebar_div(String v) {this.expd_sidebar_div = v; return this;}
public Hdump_load_mgr_fxt Expd_img(int idx, int w, int h, String ttl, String src) {expd_imgs.Add(new Hdump_data_img__basic().Init_by_base(idx, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
public Hdump_load_mgr_fxt Test_load(int page_id) {
load_mgr.Load_itm(page, page_id, page_url, init_rows);
if (expd_body != null) Tfds.Eq(expd_body, String_.new_utf8_(page.Page_body()));
if (expd_imgs.Count() != 0) Tfds.Eq_ary_str((Hdump_img_itm[])expd_imgs.XtoAryAndClear(Hdump_img_itm.class), page.Img_itms());
load_mgr.Load_rows(hpg, page_id, page_url, init_rows);
if (expd_body != null) Tfds.Eq(expd_body, String_.new_utf8_(hpg.Page_body()));
if (expd_display_ttl != null) Tfds.Eq(expd_display_ttl, String_.new_utf8_(hpg.Display_ttl()));
if (expd_content_sub != null) Tfds.Eq(expd_content_sub, String_.new_utf8_(hpg.Content_sub()));
if (expd_sidebar_div != null) Tfds.Eq(expd_sidebar_div, String_.new_utf8_(hpg.Sidebar_div()));
if (expd_imgs.Count() != 0) Tfds.Eq_ary_str((Hdump_data_img__base[])expd_imgs.XtoAryAndClear(Hdump_data_img__base.class), hpg.Img_itms());
return this;
}
}

View File

@ -0,0 +1,116 @@
/*
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.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.core.brys.*; import gplx.xowa.pages.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.skins.*;
import gplx.xowa.html.modules.*;
public class Hdump_page_body_srl {
private static final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public static void Save(Bry_bfr bfr, Xoa_page page) {
bfr.Add_int_fixed(0, 1).Add_byte_pipe(); // version
Xopg_hdump_data hdump_data = page.Hdump_data();
bfr.Add_int_variable(hdump_data.Imgs().Count()); // imgs_count
Xopg_html_data html_data = page.Html_data();
Save_html_modules(bfr, html_data);
Save_data(bfr, Tid_display_ttl , html_data.Display_ttl());
Save_data(bfr, Tid_content_sub , html_data.Content_sub());
Save_sidebars(bfr, page, html_data);
Save_data(bfr, Tid_body , hdump_data.Body());
}
private static void Save_html_modules(Bry_bfr bfr, Xopg_html_data html_data) {
Xoh_module_mgr module_mgr = html_data.Module_mgr();
Save_html_modules__itm(tmp_bfr, module_mgr.Itm_mathjax().Enabled());
Save_html_modules__itm(tmp_bfr, module_mgr.Itm_popups().Bind_hover_area());
Save_html_modules__itm(tmp_bfr, module_mgr.Itm_gallery().Enabled());
Save_html_modules__itm(tmp_bfr, module_mgr.Itm_hiero().Enabled());
Save_data(bfr, Tid_html_module, tmp_bfr.XtoAryAndClear());
}
public static void Load_html_modules(Hdump_page hpg, byte[] src, int bgn, int end) {
Hdump_module_mgr module_mgr = hpg.Module_mgr();
module_mgr.Math_exists_ (src[bgn + 0] == Byte_ascii.Ltr_y);
module_mgr.Imap_exists_ (src[bgn + 2] == Byte_ascii.Ltr_y);
module_mgr.Gallery_packed_exists_ (src[bgn + 4] == Byte_ascii.Ltr_y);
module_mgr.Hiero_exists_ (src[bgn + 6] == Byte_ascii.Ltr_y);
}
public static void Load_html_modules(Xoh_module_mgr page_module_mgr, Hdump_page hpg) {
Hdump_module_mgr dump_module_mgr = hpg.Module_mgr();
page_module_mgr.Itm_mathjax().Enabled_ (dump_module_mgr.Math_exists());
page_module_mgr.Itm_popups().Bind_hover_area_ (dump_module_mgr.Imap_exists());
page_module_mgr.Itm_gallery().Enabled_ (dump_module_mgr.Gallery_packed_exists());
page_module_mgr.Itm_hiero().Enabled_ (dump_module_mgr.Hiero_exists());
}
private static void Save_html_modules__itm(Bry_bfr tmp_bfr, boolean v) {
tmp_bfr.Add_yn(v);
tmp_bfr.Add_byte_pipe();
}
private static void Save_sidebars(Bry_bfr bfr, Xoa_page page, Xopg_html_data html_data) {
Xopg_xtn_skin_mgr mgr = html_data.Xtn_skin_mgr();
int len = mgr.Count();
boolean sidebar_exists = false;
for (int i = 0; i < len; ++i) {
Xopg_xtn_skin_itm itm = mgr.Get_at(i);
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
sidebar_exists = true;
itm.Write(tmp_bfr, page);
}
}
if (sidebar_exists)
Save_data(bfr, Tid_sidebar_div, tmp_bfr.XtoAryAndClear());
}
private static void Save_data(Bry_bfr bfr, int tid, byte[] data) {
if (data != null) {
bfr.Add_byte_nl();
bfr.Add(Sect_lhs);
bfr.Add_int_variable(tid);
bfr.Add(Sect_rhs);
bfr.Add(data);
}
}
public static void Load(Hdump_page hpg, Bry_rdr rdr, byte[] src) {
rdr.Src_(src);
Load_body_meta(hpg, rdr);
while (!rdr.Pos_is_eos()) {
int idx_pos = rdr.Find_fwd__pos_at_rhs(Sect_lhs);
int idx = Byte_ascii.Xto_digit(src[idx_pos]);
int lhs_pos = idx_pos + 3; // 2=skip "#/>"
if (idx == Tid_body) {
hpg.Page_body_(Bry_.Mid(src, lhs_pos, src.length));
return;
}
else {
int rhs_pos = rdr.Find_fwd__pos_at_lhs(Sect_lhs) - 1; // -1 to ignore \n
switch (idx) {
case Tid_html_module: Load_html_modules(hpg, src, lhs_pos, rhs_pos); break;
case Tid_display_ttl: hpg.Display_ttl_(Bry_.Mid(src, lhs_pos, rhs_pos)); break;
case Tid_content_sub: hpg.Content_sub_(Bry_.Mid(src, lhs_pos, rhs_pos)); break;
case Tid_sidebar_div: hpg.Sidebar_div_(Bry_.Mid(src, lhs_pos, rhs_pos)); break;
}
}
}
} private static final byte[] Sect_lhs = Bry_.new_ascii_("<xo_"), Sect_rhs = Bry_.new_ascii_("/>");
private static void Load_body_meta(Hdump_page hpg, Bry_rdr rdr) {
hpg.Version_id_(rdr.Read_int_to_pipe());
hpg.Img_count_(rdr.Read_int_to_nl());
}
private static final int
Tid_html_module = 1
, Tid_display_ttl = 2
, Tid_content_sub = 3
, Tid_sidebar_div = 4
, Tid_body = 5
;
}

View File

@ -15,16 +15,14 @@ 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.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
public class Xopg_hdump_img_itm {
public Xopg_hdump_img_itm(int uid, int img_w, int img_h, byte[] img_src) {
this.uid = uid; this.img_w = img_w; this.img_h = img_h; this.img_src = img_src;
}
public int Uid() {return uid;} private final int uid;
public int Img_w() {return img_w;} private final int img_w;
public int Img_h() {return img_h;} private final int img_h;
public byte[] Img_src() {return img_src;} private final byte[] img_src;
@Override public String toString() {
return String_.Concat_with_str("|", Int_.XtoStr(uid), Int_.XtoStr(img_w), Int_.XtoStr(img_h), String_.new_utf8_(img_src));
package gplx.xowa.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.pages.skins.*;
public class Xopg_xtn_skin_itm_mock implements Xopg_xtn_skin_itm {
private byte[] val;
public Xopg_xtn_skin_itm_mock(byte[] val) {this.val = val;}
public byte Tid() {return Xopg_xtn_skin_itm_tid.Tid_sidebar;}
public byte[] Key() {return Bry_.Empty;}
public void Write(Bry_bfr bfr, Xoa_page page) {
bfr.Add(val);
}
}

View File

@ -16,8 +16,17 @@ 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.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.files.*;
public class Xopg_hdump_data {
private final int file_dir_bry_len;
public Xopg_hdump_data(Xoa_app app) {file_dir_bry_len = app.Fsys_mgr().File_dir_bry_len();}
public ListAdp Imgs() {return imgs;} private final ListAdp imgs = ListAdp_.new_();
public void Imgs_add(Hdump_data_img__base img, Xof_xfer_itm xfer_itm, int tid) {
byte[] img_src = xfer_itm.Html_view_src();
img_src = Bry_.Len_eq_0(img_src) ? Bry_.Empty : Bry_.Mid(img_src, file_dir_bry_len);
img.Init_by_base(xfer_itm.Html_uid(), xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Lnki_ttl(), img_src);
imgs.Add(img);
}
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
public void Clear() {
imgs.Clear();

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.dbs.*;
import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.pages.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*; import gplx.xowa.hdumps.loads.*;
public class Hdump_save_mgr {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
private Hdump_text_tbl text_tbl;
@ -28,57 +28,28 @@ public class Hdump_save_mgr {
this.Insert(page);
}
public void Insert(Xoa_page page) {
tmp_bfr.Clear();
Hdump_page_body_srl.Save(tmp_bfr, page);
int page_id = page.Revision_data().Id();
Xopg_html_data html_data = page.Html_data();
Xopg_hdump_data hdump_data = page.Hdump_data();
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, hdump_data.Body());
Insert_files(page_id, hdump_data.Imgs());
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
Insert_sidebars(page_id, page, html_data.Xtn_skin_mgr());
}
private void Insert_files(int page_id, ListAdp imgs) {
byte[] imgs_bry = Write_imgs(tmp_bfr, imgs);
if (imgs_bry != null)
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_img, imgs_bry);
}
private void Insert_if_exists(int page_id, int tid, byte[] val) {
if (Bry_.Len_gt_0(val))
text_tbl.Insert(page_id, tid, val);
}
private void Insert_sidebars(int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
int len = xtn_skin_mgr.Count();
for (int i = 0; i < len; ++i) {
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
itm.Write(tmp_bfr, page);
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_sidebar_div, tmp_bfr.XtoAryAndClear());
}
}
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, tmp_bfr.XtoAryAndClear());
byte[] redlinks_bry = Write_redlinks(tmp_bfr, page.Html_data().Redlink_mgr());
if (redlinks_bry != null) text_tbl.Insert(page_id, Hdump_data_tid.Tid_redlink, redlinks_bry);
byte[] imgs_bry = Write_imgs(tmp_bfr, page.Hdump_data().Imgs());
if (imgs_bry != null) text_tbl.Insert(page_id, Hdump_data_tid.Tid_img, imgs_bry);
}
public static byte[] Write_imgs(Bry_bfr bfr, ListAdp imgs) {
int len = imgs.Count(); if (len == 0) return null; // no images; exit early, else will write blank String
for (int i = 0; i < len; ++i) {
Xof_xfer_itm img = (Xof_xfer_itm)imgs.FetchAt(i);
Write_img(bfr, img.Html_uid(), img.Html_w(), img.Html_h(), img.Lnki_ttl(), img.Html_view_src_rel());
Hdump_data_img__base img = (Hdump_data_img__base)imgs.FetchAt(i);
img.Write(bfr);
}
return bfr.XtoAryAndClear();
}
private static void Write_img(Bry_bfr bfr, int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] img_src_rel) {
bfr .Add_int_variable(uid)
.Add_byte_pipe().Add_int_variable(img_w)
.Add_byte_pipe().Add_int_variable(img_h)
.Add_byte_pipe().Add(lnki_ttl)
.Add_byte_pipe().Add(img_src_rel)
.Add_byte_nl()
;
private static byte[] Write_redlinks(Bry_bfr bfr, Int_list redlink_mgr) {
int len = redlink_mgr.Len(); if (len == 0) return null;
bfr.Add_int_variable(len);
for (int i = 0; i < len; ++i) {
bfr.Add_byte_pipe().Add_int_variable(redlink_mgr.Get_at(i));
}
return bfr.XtoAryAndClear();
}
}
/*
<0/>|0|metadata
<1/>|title
<2/>|content_sub
<3/>|sidebar
<4/>|body
*/

View File

@ -283,7 +283,7 @@ public class Xoh_html_wtr {
bfr.Add(bry.Val());
}
@gplx.Virtual public void Vnt(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_vnt_tkn vnt) {
Xop_vnt_html_wtr.Write(this, ctx, hctx, bfr, src, vnt); // NOTE: using wiki, b/c getting nullPointer with ctx during mass parse
Xop_vnt_html_wtr.Write(bfr, this, ctx, hctx, page, src, vnt); // NOTE: using wiki, b/c getting nullPointer with ctx during mass parse
}
@gplx.Virtual public void Under(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_under_tkn under) {
if (hctx.Mode_is_alt()) return;
@ -405,7 +405,7 @@ public class Xoh_html_wtr {
case Xop_xnde_tag_.Tid_math:
case Xop_xnde_tag_.Tid_xowa_html:
Xox_xnde xtn = xnde.Xnde_xtn();
xtn.Xtn_write(app, this, hctx, ctx, bfr, src, xnde);
xtn.Xtn_write(bfr, app, ctx, this, hctx, xnde, src);
break;
case Xop_xnde_tag_.Tid_xowa_tag_bgn:
case Xop_xnde_tag_.Tid_xowa_tag_end:

View File

@ -15,6 +15,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_module__top_icon extends Xow_module_base {
package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
public interface Xoh_arg_img_core extends Bry_fmtr_arg {
Xoh_arg_img_core Init(int uid, byte[] src, int w, int h);
}

View File

@ -15,17 +15,12 @@ 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.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*;
import gplx.xowa.hdumps.core.*;
class Hdump_html_fmtr__sidebars implements Bry_fmtr_arg {
private Hdump_page_itm page;
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
public class Xoh_arg_img_core__basic implements Xoh_arg_img_core {
private byte[] src; private int w, h;
public Xoh_arg_img_core Init(int uid, byte[] src, int w, int h) {this.src = src; this.w = w; this.h = h; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
byte[][] sidebar_divs = page.Sidebar_divs();
int sidebar_divs_len = sidebar_divs.length;
for (int i = 0; i < sidebar_divs_len; ++i) {
byte[] sidebar_div = sidebar_divs[i];
bfr.Add(sidebar_div);
}
fmtr_img_atrs.Bld_bfr_many(bfr, src, w, h);
}
private Bry_fmtr fmtr_img_atrs = Bry_fmtr.new_(" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"", "img_src", "img_w", "img_h");
}

View 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.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
public class Xoh_arg_img_core__hdump implements Xoh_arg_img_core {
private int uid;
public Xoh_arg_img_core Init(int uid, byte[] img_src, int img_w, int img_h) {
this.uid = uid;
return this;
}
public void XferAry(Bry_bfr bfr, int idx) {
bfr.Add_byte_space();
bfr.Add(gplx.xowa.hdumps.htmls.Hdump_html_consts.Key_img);
bfr.Add_int_variable(uid);
bfr.Add_byte_apos();
}
}

View File

@ -17,26 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.files.*; import gplx.xowa.hdumps.htmls.*;
class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(128);
@gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();}
@Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
tmp_bfr.Add(Hdump_html_fmtr__body.Key_img_style);
tmp_bfr.Add_int_variable(uid);
tmp_bfr.Add_byte_apos();
byte[] div2_width_repl = tmp_bfr.XtoAryAndClear();
fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content);
}
@Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_fmtr__body.Key_file_mgnf, uid);}
@Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Hdump_html_fmtr__body.Key_file_info, uid);}
@Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_fmtr__body.Key_file_play, uid);}
public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
bfr.Add(key);
bfr.Add_int_variable(uid);
bfr.Add(Bry_xnde_end);
} private static final byte[] Bry_xnde_end = Bry_.new_ascii_("'/>");
public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {}
}
public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
private final Xoh_arg_img_core arg_img_core;
private Bry_bfr scratch_bfr = Bry_bfr.reset_(128);
@ -50,7 +30,7 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
, "</a>"
), "a_href", "a_xowa_title", "html"
);
public void Html_full_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_class) {
public void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_class) {
fmtr_full_img.Bld_bfr_many(tmp_bfr, uid, a_href, a_class, a_rel, a_title, a_xowa_title, arg_img_core.Init(uid, img_src, img_w, img_h), img_alt, img_class);
}
private Bry_fmtr fmtr_full_img = Bry_fmtr.new_
@ -159,27 +139,23 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
public static final Xoh_file_html_fmtr__base Base = new Xoh_file_html_fmtr__base();
}
interface Xoh_arg_img_core extends Bry_fmtr_arg {
Xoh_arg_img_core Init(int uid, byte[] src, int w, int h);
}
class Xoh_arg_img_core__hdump implements Xoh_arg_img_core {
private int uid;
public Xoh_arg_img_core Init(int uid, byte[] img_src, int img_w, int img_h) {
this.uid = uid;
return this;
class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(128);
@gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();}
@Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
tmp_bfr.Add(Hdump_html_consts.Key_img_style);
tmp_bfr.Add_int_variable(uid);
tmp_bfr.Add_byte_apos();
byte[] div2_width_repl = tmp_bfr.XtoAryAndClear();
fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content);
}
public void XferAry(Bry_bfr bfr, int idx) {
bfr.Add_str(" xowa_img='");
@Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_mgnf, uid);}
@Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_info, uid);}
@Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Hdump_html_consts.Key_file_play, uid);}
public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
bfr.Add(key);
bfr.Add_int_variable(uid);
bfr.Add_str("'");
// Xoh_file_html_fmtr__hdump.Write_fmt(bfr, Hdump_html_fmtr__body.Key_img, uid);
}
}
class Xoh_arg_img_core__basic implements Xoh_arg_img_core {
private byte[] src; private int w, h;
public Xoh_arg_img_core Init(int uid, byte[] src, int w, int h) {this.src = src; this.w = w; this.h = h; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
fmtr_img_atrs.Bld_bfr_many(bfr, src, w, h);
}
private Bry_fmtr fmtr_img_atrs = Bry_fmtr.new_(" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"", "img_src", "img_w", "img_h");
bfr.Add(Bry_xnde_end);
} private static final byte[] Bry_xnde_end = Bry_.new_ascii_("'/>");
public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {}
}

View File

@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.xowa.files.*;
public interface Xoh_file_img_wkr {
void Html_full_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_class);
void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_class);
}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
import gplx.html.*; import gplx.xowa.files.*;
import gplx.html.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.core.*;
public class Xoh_file_wtr__basic {
private final Xow_wiki wiki; private final Xow_html_mgr html_mgr; private final Xoh_html_wtr html_wtr; private final Bry_bfr_mkr bfr_mkr; private final Bry_bfr scratch_bfr = Bry_bfr.reset_(Io_mgr.Len_kb);
private final Xoh_lnki_text_fmtr media_alt_fmtr, caption_fmtr;
@ -76,10 +76,8 @@ public class Xoh_file_wtr__basic {
else // image
this.Write_file_image(bfr, ctx, hctx, src, lnki, xfer_itm, uid, div_width, lnki_halign, lnki_halign_bry, lnki_ttl, lnki_ext, lnki_href, img_view_src, img_orig_src, img_alt);
}
if (hctx.Mode_is_hdump()) {
byte[] rel_src = Bry_.Len_eq_0(img_view_src) ? Bry_.Empty : Bry_.Mid(img_view_src, wiki.App().Fsys_mgr().File_dir().To_http_file_bry().length);
xfer_itm.Html_view_src_rel_(rel_src);
page.Hdump_data().Imgs().Add(xfer_itm.Clone());
if (hctx.Mode_is_hdump() && Xof_html_elem.Tid_is_file(xfer_itm.Html_elem_tid())) {
page.Hdump_data().Imgs_add(new Hdump_data_img__basic(), xfer_itm, Hdump_data_img__gallery.Tid_basic);
}
}
private void Write_file_ns_media(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, byte[] img_orig_src) {
@ -130,7 +128,7 @@ public class Xoh_file_wtr__basic {
}
Arg_nde_tkn lnki_link_tkn = lnki.Link_tkn();
if (lnki_link_tkn == Arg_nde_tkn.Null) // full
lnki_file_wkr.Html_full_img(bfr, page, xfer_itm, uid, lnki_href, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, Arg_img_cls(lnki));
lnki_file_wkr.Html_full_img(bfr, hctx, page, xfer_itm, uid, lnki_href, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, Arg_img_cls(lnki));
else { // thumb
Arg_itm_tkn link_tkn = lnki_link_tkn.Val_tkn();
byte[] link_ref = link_tkn.Dat_to_bry(src);
@ -138,7 +136,7 @@ public class Xoh_file_wtr__basic {
link_ref = link_ref_new == null ? lnki_href: link_ref_new; // if parse fails, then assign to lnki_href; EX:link={{{1}}}
link_ref = ctx.App().Encoder_mgr().Href_quotes().Encode(link_ref); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16
lnki_ttl = Bry_.Coalesce(lnki_ttl, tmp_link_parser.Html_xowa_ttl());
lnki_file_wkr.Html_full_img(bfr, page, xfer_itm, uid, link_ref, tmp_link_parser.Html_anchor_cls(), tmp_link_parser.Html_anchor_rel(), anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, Arg_img_cls(lnki));
lnki_file_wkr.Html_full_img(bfr, hctx, page, xfer_itm, uid, link_ref, tmp_link_parser.Html_anchor_cls(), tmp_link_parser.Html_anchor_rel(), anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, Arg_img_cls(lnki));
}
if (div_align_exists) bfr.Add(Html_tag_.Div_rhs); // close div from above
}
@ -149,7 +147,7 @@ public class Xoh_file_wtr__basic {
byte[] lnki_alt_html = wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val() ? Arg_alt_html(ctx, src, lnki) : Bry_.Empty;
byte[] lnki_cls = xfer_itm.Html_pass() ? Xow_html_mgr.Bry_img_cls_thumbimage : Xow_html_mgr.Bry_img_cls_none;
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
lnki_file_wkr.Html_full_img(tmp_bfr, page, xfer_itm, uid, lnki_href, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, lnki_cls);
lnki_file_wkr.Html_full_img(tmp_bfr, hctx, page, xfer_itm, uid, lnki_href, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, lnki_cls);
byte[] thumb = tmp_bfr.XtoAryAndClear();
html_fmtr.Html_thumb_file_image(tmp_bfr, thumb, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), lnki_alt_html);
return tmp_bfr.Mkr_rls().XtoAryAndClear();

View File

@ -28,7 +28,7 @@ public class Xoh_module_itm__navframe implements Xoh_module_itm {
public void Write_js_head_global(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoh_module_wtr wtr) {
if (!enabled) return;
wtr.Write_js_global_ini_atr_val(Key_enabled , true);
wtr.Write_js_global_ini_atr_val(Key_collapsed , app.Api_root().Html().Modules().Navframe().Collapsed());
wtr.Write_js_global_ini_atr_val(Key_collapsed , app.Api_root().Html().Modules().Navframe().Collapsed() || wiki.Html_mgr().Module_mgr().Itm_navframe().Enabled_n());
wtr.Write_js_global_ini_atr_msg(wiki , Key_show);
wtr.Write_js_global_ini_atr_msg(wiki , Key_hide);
}

View File

@ -37,8 +37,8 @@ public class Xoh_module_mgr implements Bry_fmtr_arg {
return this;
}
public Xoh_module_mgr Init_dflts() {
if (page.Hdr_mgr().Toc_enabled()) itm_toc.Enabled_y_();
if (wiki.Html_mgr().Module_mgr().Itm_top_icon().Enabled()) itm_top_icon.Enabled_y_();
if (page.Hdr_mgr().Toc_enabled()) itm_toc.Enabled_y_();
if (wiki.Html_mgr().Module_mgr().Itm_top_icon().Enabled_y()) itm_top_icon.Enabled_y_();
itm_css.Enabled_y_();
itm_globals.Enabled_y_(); // for now, always mark this and rest as exists; DATE:2014-06-09
itm_collapsible.Enabled_y_();

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.html.*;
public class Xop_vnt_html_wtr {
public static void Write(Xoh_html_wtr html_wtr, Xop_ctx ctx, Xoh_wtr_ctx opts, Bry_bfr bfr, byte[] src, Xop_vnt_tkn vnt) {
public static void Write(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xoa_page page, byte[] src, Xop_vnt_tkn vnt) {
byte[] cur_lang_vnt = ctx.Wiki().Lang().Vnt_mgr().Cur_vnt();
Xop_vnt_rule[] rules = vnt.Vnt_rules(); if (rules == null) return; // shouldn't happen, but guard anyway
int rules_len = rules.length;
@ -28,19 +28,15 @@ public class Xop_vnt_html_wtr {
bfr.Add_mid(src, vnt.Src_bgn(), vnt.Src_end());
break;
case Xop_vnt_html_wtr.Cmd_literal: { // val only; "A"
Xop_vnt_rule rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 item
html_wtr.Write_tkn_ary(bfr, ctx, opts, src, rule_0.Rule_subs());
Xop_vnt_rule rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 item
html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule_0.Rule_subs());
break;
}
case Xop_vnt_html_wtr.Cmd_bidi: // matching rule: "A" if zh-hans; -{zh-hans:A}-
for (int i = 0; i < rules_len; i++) {
Xop_vnt_rule rule = rules[i];
if (Bry_.Eq(rule.Rule_lang(), cur_lang_vnt)) {
html_wtr.Write_tkn_ary(bfr, ctx, opts, src, rule.Rule_subs());
break;
}
}
case Xop_vnt_html_wtr.Cmd_bidi: { // matching rule: "A" if zh-hans; -{zh-hans:A}-
Xop_vnt_rule rule = Get_rule_by_key(rules, rules_len, cur_lang_vnt);
if (rule != null) html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule.Rule_subs());
break;
}
case Xop_vnt_html_wtr.Cmd_lang: { // matching lang: "A" if zh-hans; -{zh-hans|A}-
Xop_vnt_rule rule_0 = rules[0]; // Cmd_calc guarantees there will always be 1 rule
Xop_vnt_flag flag_0 = vnt.Vnt_flags()[0]; // parse guarantees there will always be 1 flag
@ -49,7 +45,7 @@ public class Xop_vnt_html_wtr {
for (int i = 0; i < flags_len; i++) {
byte[] lang = langs[i];
if (Bry_.Eq(lang, cur_lang_vnt)) {
html_wtr.Write_tkn_ary(bfr, ctx, opts, src, rule_0.Rule_subs());
html_wtr.Write_tkn_ary(bfr, ctx, hctx, src, rule_0.Rule_subs());
break;
}
}
@ -63,8 +59,16 @@ public class Xop_vnt_html_wtr {
// bfr.Add_mid(src, vnt.Vnt_pipe_idx_last(), vnt.Src_end() - 2);
break;
}
case Xop_vnt_html_wtr.Cmd_title: break; // title: ignore; already handled during parse; DATE:2014-08-29
}
}
public static Xop_vnt_rule Get_rule_by_key(Xop_vnt_rule[] rules, int rules_len, byte[] cur_lang_vnt) {
for (int i = 0; i < rules_len; i++) {
Xop_vnt_rule rule = rules[i];
if (Bry_.Eq(rule.Rule_lang(), cur_lang_vnt)) return rule;
}
return null;
}
public static final byte
Cmd_error = 0 // eror -> output literal; EX: "-{some_unknown_error}-" -> "-{some_unknown_error}-"
, Cmd_empty = 1 // empty -> output nothing; EX: "-{}-" -> ""
@ -73,5 +77,6 @@ public class Xop_vnt_html_wtr {
, Cmd_lang = 4 // lang EX: "-{zh-hans|A}-" -> "A" if zh-hans; "" if zh-hant
, Cmd_raw = 5 // raw; text in -{}- EX: "-{R|zh-hans:A;zh-hant:B}- -> "zh-hans:A;zh-hant:B"
, Cmd_descrip = 6 // describe; output rules EX: "-{D|zh-hans:A;zh-hant:B}- -> "简体A繁體B"
, Cmd_title = 7 // title; change title EX: "-{T|zh-hans:A;zh-hant:B}- -> "A" as display title
;
}

View File

@ -67,6 +67,7 @@ class Xop_vnt_lxr_end implements Xop_lxr {
int stack_pos = ctx.Stack_idx_typ(Xop_tkn_itm_.Tid_vnt);
if (stack_pos == Xop_ctx.Stack_not_found) return ctx.Lxr_make_txt_(cur_pos); // "}-" found but no "-{" in stack;
Xop_vnt_tkn vnt_tkn = (Xop_vnt_tkn)ctx.Stack_pop_til(root, src, stack_pos, false, bgn_pos, cur_pos, Xop_tkn_itm_.Tid_vnt);
Xow_wiki wiki = ctx.Wiki();
try {
vnt_tkn.Src_end_(cur_pos);
vnt_tkn.Subs_move(root);
@ -74,7 +75,7 @@ class Xop_vnt_lxr_end implements Xop_lxr {
int rule_subs_bgn = 0;
int pipe_tkn_count = vnt_tkn.Vnt_pipe_tkn_count();
if (pipe_tkn_count > 0) {
flag_parser.Parse(ctx.Wiki(), vnt_tkn, pipe_tkn_count, src);
flag_parser.Parse(wiki, vnt_tkn, pipe_tkn_count, src);
vnt_flag_ary = flag_parser.Rslt_flags();
rule_subs_bgn = flag_parser.Rslt_tkn_pos();
vnt_tkn.Vnt_pipe_idx_last_(flag_parser.Rslt_pipe_last());
@ -82,7 +83,7 @@ class Xop_vnt_lxr_end implements Xop_lxr {
vnt_tkn.Vnt_flags_(vnt_flag_ary);
Xop_vnt_rule[] rules = rule_parser.Parse(ctx, vnt_tkn, src, rule_subs_bgn);
vnt_tkn.Vnt_rules_(rules);
vnt_tkn.Vnt_cmd_calc();
vnt_tkn.Vnt_cmd_calc(wiki, ctx.Cur_page(), ctx, src);
}
catch (Exception e) {
ctx.App().Usr_dlg().Warn_many("", "", "vnt.parse failed: page=~{0} src=~{1} err=~{2}", String_.new_utf8_(ctx.Cur_page().Ttl().Raw()), String_.new_utf8_(src, bgn_pos, cur_pos), Err_.Message_gplx_brief(e));

View File

@ -58,6 +58,10 @@ public class Xop_vnt_parser_tst { // uses zh-hant as cur_vnt
@Test public void Macro_ignore() { // PURPOSE: ignore macro (implement later); EX:zh.v:西安; Template:pagebanner; DATE:2014-05-03
fxt.Test_parse("-{H|zh-cn:亚琛; zh-tw:阿亨;}-", "");
}
@Test public void Title() { // PURPOSE: implement title; PAGE:zh.w:Help:進階字詞轉換處理 DATE:2014-08-29
fxt.Test_parse("-{T|zh-hant:A;zh-hans:B}-", "");
Tfds.Eq("A", String_.new_utf8_(fxt.Parser_fxt().Page().Html_data().Display_ttl_vnt()));
}
}
class Xop_vnt_parser_fxt {
public Xop_fxt Parser_fxt() {return fxt;} private Xop_fxt fxt;

View File

@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.langs.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.html.*;
public class Xop_vnt_tkn extends Xop_tkn_itm_base {
public Xop_vnt_tkn(int bgn, int end) {
this.Tkn_ini_pos(false, bgn, end);
@ -28,7 +29,7 @@ public class Xop_vnt_tkn extends Xop_tkn_itm_base {
public Xop_vnt_flag[] Vnt_flags() {return vnt_flags;} public Xop_vnt_tkn Vnt_flags_(Xop_vnt_flag[] v) {vnt_flags = v; return this;} private Xop_vnt_flag[] vnt_flags;
public Xop_vnt_rule[] Vnt_rules() {return vnt_rules;} public Xop_vnt_tkn Vnt_rules_(Xop_vnt_rule[] v) {vnt_rules = v; return this;} private Xop_vnt_rule[] vnt_rules;
public byte Vnt_cmd() {return vnt_cmd;} private byte vnt_cmd;
public void Vnt_cmd_calc() {
public void Vnt_cmd_calc(Xow_wiki wiki, Xoa_page page, Xop_ctx ctx, byte[] src) {
int flags_len = vnt_flags.length;
int rules_len = vnt_rules.length;
if (flags_len == 0) { // no flags; either literal ("-{A}-") or bidi ("-{zh-hans:A;zh-hant:B}-");
@ -51,6 +52,18 @@ public class Xop_vnt_tkn extends Xop_tkn_itm_base {
case Xop_vnt_flag_.Tid_descrip : vnt_cmd = Xop_vnt_html_wtr.Cmd_descrip; break;
case Xop_vnt_flag_.Tid_unknown : vnt_cmd = Xop_vnt_html_wtr.Cmd_literal; break; // flag is unknown; output text as literal; EX: "-{|a}-"; "-{X|a}-"
case Xop_vnt_flag_.Tid_macro : vnt_cmd = Xop_vnt_html_wtr.Cmd_empty; break; // TODO: implement macro; ignore for now; DATE:2014-05-03
case Xop_vnt_flag_.Tid_title: { // title; same as {{DISPLAYTITLE}} but variant aware; PAGE:zh.w:Help:進階字詞轉換處理 DATE:2014-08-29
vnt_cmd = Xop_vnt_html_wtr.Cmd_title;
byte[] cur_lang_vnt = wiki.Lang().Vnt_mgr().Cur_vnt();
Xop_vnt_rule rule = Xop_vnt_html_wtr.Get_rule_by_key(vnt_rules, vnt_rules.length, cur_lang_vnt);
if (rule != null) {
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
wiki.Html_mgr().Html_wtr().Write_tkn_ary(tmp_bfr, ctx, Xoh_wtr_ctx.Alt, src, rule.Rule_subs());
byte[] display_ttl = tmp_bfr.Mkr_rls().XtoAryAndClear();
page.Html_data().Display_ttl_vnt_(display_ttl);
}
break;
}
}
}
}

View File

@ -21,19 +21,34 @@ public class Xopg_html_data {
private OrderedHash ctg_hash;
public boolean Html_restricted() {return html_restricted;} private boolean html_restricted = true;
public void Html_restricted_(boolean v) {html_restricted = v;} public void Html_restricted_n_() {Html_restricted_(Bool_.N);} public void Html_restricted_y_() {Html_restricted_(Bool_.Y);}
public byte[] Display_ttl() {return display_ttl;} public Xopg_html_data Display_ttl_(byte[] v) {display_ttl = v; return this;} private byte[] display_ttl;
public byte[] Display_ttl() {
return ( display_ttl_vnt != null // -{T}- was in document
&& display_ttl == null // {{DISPLAYTITLE}} does not exist
&& lang_convert_content // __NOCONVERTCONTENT__ exists
&& lang_convert_title // __NOCONVERTTITLE__ exists
)
? display_ttl_vnt // return variant title; DATE:2014-08-29
: display_ttl // return normal title
;
}
public Xopg_html_data Display_ttl_(byte[] v) {display_ttl = v; return this;} private byte[] display_ttl;
public byte[] Display_ttl_vnt() {return display_ttl_vnt;} public void Display_ttl_vnt_(byte[] v) {display_ttl_vnt = v;} private byte[] display_ttl_vnt;
public byte[] Content_sub() {return content_sub;} public void Content_sub_(byte[] v) {content_sub = v;} private byte[] content_sub;
public String Bmk_pos() {return html_bmk_pos;} public void Bmk_pos_(String v) {html_bmk_pos = v;} private String html_bmk_pos;
public Bry_bfr Portal_div_xtn() {return portal_div_xtn;} private Bry_bfr portal_div_xtn = Bry_bfr.reset_(255);
public byte[] Edit_preview_w_dbg() {return Bry_.Add(xtn_scribunto_dbg, edit_preview);} public void Edit_preview_(byte[] v) {edit_preview = v;} private byte[] edit_preview = Bry_.Empty;
public int Lnke_autonumber_next() {return lnke_autonumber++;} private int lnke_autonumber = 1;
public boolean Lang_convert_content() {return lang_convert_content;} public void Lang_convert_content_(boolean v) {lang_convert_content = v;} private boolean lang_convert_content = true;
public boolean Lang_convert_title() {return lang_convert_title;} public void Lang_convert_title_(boolean v) {lang_convert_title = v;} private boolean lang_convert_title = true;
public Xopg_xtn_skin_mgr Xtn_skin_mgr() {return xtn_skin_mgr;} private Xopg_xtn_skin_mgr xtn_skin_mgr = new Xopg_xtn_skin_mgr();
public int Xtn_gallery_next_id() {return ++xtn_gallery_next_id;} private int xtn_gallery_next_id = -1;
public boolean Xtn_gallery_packed_exists() {return xtn_gallery_packed_exists;} public void Xtn_gallery_packed_exists_y_() {xtn_gallery_packed_exists = true;} private boolean xtn_gallery_packed_exists;
public boolean Xtn_imap_exists() {return xtn_imap_exists;} public void Xtn_imap_exists_y_() {xtn_imap_exists = true;} private boolean xtn_imap_exists;
public int Xtn_imap_next_id() {return ++xtn_imap_next_id;} private int xtn_imap_next_id; // NOTE: must keep separate imap_id b/c html_elem_id is not always set;
public byte[] Xtn_search_text() {return xtn_search_txt;} public void Xtn_search_text_(byte[] v) {xtn_search_txt = v;} private byte[] xtn_search_txt = Bry_.Empty;
public byte[] Xtn_scribunto_dbg() {return xtn_scribunto_dbg;} public void Xtn_scribunto_dbg_(byte[] v) {xtn_scribunto_dbg = Bry_.Add(xtn_scribunto_dbg, v);} private byte[] xtn_scribunto_dbg = Bry_.Empty;
public Xoh_module_mgr Module_mgr() {return module_mgr;} private Xoh_module_mgr module_mgr = new Xoh_module_mgr();
public Int_list Redlink_mgr() {return redlink_mgr;} private Int_list redlink_mgr = new Int_list();
public byte[] Custom_html() {return custom_html;} public Xopg_html_data Custom_html_(byte[] v) {custom_html = v; return this;} private byte[] custom_html;
public byte[] Custom_name() {return custom_name;} public Xopg_html_data Custom_name_(byte[] v) {custom_name = v; return this;} private byte[] custom_name;
public byte[] Custom_head_end() {return custom_head_end;}
@ -52,16 +67,17 @@ public class Xopg_html_data {
} private byte[] custom_html_end;
public void Clear() {
html_restricted = true;
display_ttl = null;
content_sub = Bry_.Empty;
display_ttl = content_sub = display_ttl_vnt = null;
lang_convert_content = lang_convert_title = true;
lnke_autonumber = 1;
xtn_skin_mgr.Clear();
xtn_gallery_packed_exists = false;
xtn_imap_next_id = 0;
xtn_imap_next_id = 0; xtn_gallery_next_id = -1;
xtn_imap_exists = false;
xtn_search_txt = Bry_.Empty;
xtn_scribunto_dbg = Bry_.Empty;
module_mgr.Clear();
redlink_mgr.Clear();
custom_html = custom_html_end = custom_head_end = custom_name = null;
if (ctg_hash != null) ctg_hash.Clear();
}

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.dbs.tbls.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*;
import gplx.xowa.langs.vnts.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
public class Xop_lnki_logger_redlinks_wkr implements GfoInvkAble {
private Xow_wiki wiki; private Xog_win_itm win; private Xoa_page page;
private ListAdp lnki_list; private boolean log_enabled; private Gfo_usr_dlg usr_dlg;
@ -71,6 +71,7 @@ public class Xop_lnki_logger_redlinks_wkr implements GfoInvkAble {
Bry_bfr bfr = null;
boolean variants_enabled = wiki.Lang().Vnt_mgr().Enabled();
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
Int_list redlink_mgr = page.Html_data().Redlink_mgr();
for (int j = 0; j < len; j++) {
Xop_lnki_tkn lnki = (Xop_lnki_tkn)work_list.FetchAt(j);
byte[] full_db = lnki.Ttl().Full_db();
@ -94,7 +95,9 @@ public class Xop_lnki_logger_redlinks_wkr implements GfoInvkAble {
}
if (win.Usr_dlg().Canceled()) return;
if (redlinks_mgr.Request_idx() != request_idx) return;
gplx.xowa.files.gui.Js_img_mgr.Update_link_missing(html_itm, Xop_lnki_logger_redlinks_mgr.Lnki_id_prefix + Int_.XtoStr(lnki.Html_id()));
int uid = lnki.Html_id();
gplx.xowa.files.gui.Js_img_mgr.Update_link_missing(html_itm, Xop_lnki_logger_redlinks_mgr.Lnki_id_prefix + Int_.XtoStr(uid));
redlink_mgr.Add(uid);
++redlink_count;
}
}

View File

@ -18,11 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.tmpls; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.btries.*; import gplx.html.*;
public class Nowiki_escape_itm {
public Nowiki_escape_itm(boolean tid_space, byte[] src, byte[] trg) {this.tid_space = tid_space; this.src = src; this.trg = trg;}
public Nowiki_escape_itm(byte[] src, byte[] trg) {this.src = src; this.trg = trg; this.src_adj = src.length - 1;}
private int src_adj;
public byte[] Src() {return src;} private byte[] src;
public byte[] Trg() {return trg;} private byte[] trg;
public boolean Tid_space() {return tid_space;} private boolean tid_space;
public static boolean Escape(Bry_bfr tmp_bfr, byte[] src, int bgn, int end) {// <nowiki> works by escaping all wtxt symbols so that wtxt parser does not hook into any of them
boolean dirty = false;
for (int i = bgn; i < end; i++) {
@ -38,33 +37,31 @@ public class Nowiki_escape_itm {
dirty = true;
}
Nowiki_escape_itm itm = (Nowiki_escape_itm)o;
if (itm.Tid_space()) { // NOTE: if space, check if preceding char is \n; else "\n\s" -> "\n&#32;" which will break prew; PAGE:ru.b:Rubyn DATE:2014-07-03
if (i > 0 && src[i - 1] == Byte_ascii.NewLine) { // bounds check && is_preceding_char_nl
tmp_bfr.Add_byte_space(); // don't escape space
continue;
}
}
tmp_bfr.Add(itm.Trg());
i += itm.src_adj;
}
}
return dirty;
}
private static final byte[] Pre_bry = new byte[] {Byte_ascii.NewLine, Byte_ascii.Space}; // NOTE: must go before trie_new
private static final Btrie_slim_mgr trie = trie_new();
private static Btrie_slim_mgr trie_new() {
Btrie_slim_mgr rv = Btrie_slim_mgr.cs_();
trie_new_itm(rv, Bool_.N, Byte_ascii.Lt_bry , Html_entity_.Lt_bry);
trie_new_itm(rv, Bool_.N, Byte_ascii.Brack_bgn_bry , Html_entity_.Brack_bgn_bry);
trie_new_itm(rv, Bool_.N, Byte_ascii.Brack_end_bry , Html_entity_.Brack_end_bry); // PAGE:en.w: Tall_poppy_syndrome DATE:2014-07-23
trie_new_itm(rv, Bool_.N, Byte_ascii.Pipe_bry , Html_entity_.Pipe_bry);
trie_new_itm(rv, Bool_.N, Byte_ascii.Apos_bry , Html_entity_.Apos_key_bry); // NOTE: for backward compatibility, use &apos; note that amp_wkr will turn &apos; -> &#39 but &#39 -> '; DATE:2014-07-03
trie_new_itm(rv, Bool_.N, Byte_ascii.Colon_bry , Html_entity_.Colon_bry);
trie_new_itm(rv, Bool_.N, Byte_ascii.Underline_bry , Html_entity_.Underline_bry);
trie_new_itm(rv, Bool_.N, Byte_ascii.Asterisk_bry , Html_entity_.Asterisk_bry);
trie_new_itm(rv, Bool_.Y, Byte_ascii.Space_bry , Html_entity_.Space_bry);
trie_new_itm(rv, Byte_ascii.Lt_bry , Html_entity_.Lt_bry);
trie_new_itm(rv, Byte_ascii.Brack_bgn_bry , Html_entity_.Brack_bgn_bry);
trie_new_itm(rv, Byte_ascii.Brack_end_bry , Html_entity_.Brack_end_bry); // PAGE:en.w: Tall_poppy_syndrome DATE:2014-07-23
trie_new_itm(rv, Byte_ascii.Pipe_bry , Html_entity_.Pipe_bry);
trie_new_itm(rv, Byte_ascii.Apos_bry , Html_entity_.Apos_key_bry); // NOTE: for backward compatibility, use &apos; note that amp_wkr will turn &apos; -> &#39 but &#39 -> '; DATE:2014-07-03
trie_new_itm(rv, Byte_ascii.Colon_bry , Html_entity_.Colon_bry);
trie_new_itm(rv, Byte_ascii.Underline_bry , Html_entity_.Underline_bry);
trie_new_itm(rv, Byte_ascii.Asterisk_bry , Html_entity_.Asterisk_bry);
trie_new_itm(rv, Byte_ascii.Space_bry , Html_entity_.Space_bry);
trie_new_itm(rv, Byte_ascii.NewLine_bry , Html_entity_.Nl_bry);
trie_new_itm(rv, Pre_bry , Pre_bry);
return rv;
}
private static void trie_new_itm(Btrie_slim_mgr rv, boolean tid_space, byte[] src, byte[] trg) {
Nowiki_escape_itm itm = new Nowiki_escape_itm(tid_space, src, trg);
private static void trie_new_itm(Btrie_slim_mgr rv, byte[] src, byte[] trg) {
Nowiki_escape_itm itm = new Nowiki_escape_itm(src, trg);
rv.Add_obj(src, itm);
}
}

View File

@ -17,10 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_module_base implements GfoInvkAble {
public boolean Enabled() {return enabled;} private boolean enabled;
public byte Enabled() {return enabled;} private byte enabled = Bool_.__byte;
public boolean Enabled_y() {return enabled == Bool_.Y_byte;}
public boolean Enabled_n() {return enabled == Bool_.N_byte;}
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_nullable_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = Yn.Xto_nullable_byte(m.ReadStr("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}

View File

@ -21,12 +21,14 @@ public class Xow_module_mgr implements GfoInvkAble {
private Hash_adp_bry regy = Hash_adp_bry.cs_();
public Xow_module_mgr(Xow_wiki wiki) {
this.popup_mgr = new Xow_popup_mgr(wiki);
regy.Add_str_obj("top_icon", itm_top_icon);
regy.Add_str_obj("top_icon" , itm_top_icon);
regy.Add_str_obj("navframe" , itm_navframe);
}
public void Init_by_wiki(Xow_wiki wiki) {
popup_mgr.Init_by_wiki(wiki);
}
public Xow_module__top_icon Itm_top_icon() {return itm_top_icon;} private Xow_module__top_icon itm_top_icon = new Xow_module__top_icon();
public Xow_module_base Itm_top_icon() {return itm_top_icon;} private Xow_module_base itm_top_icon = new Xow_module_base();
public Xow_module_base Itm_navframe() {return itm_navframe;} private Xow_module_base itm_navframe = new Xow_module_base();
public Xow_popup_mgr Popup_mgr() {return popup_mgr;} private Xow_popup_mgr popup_mgr;
public Xow_module_base Get(byte[] key) {return (Xow_module_base)regy.Get_by_bry(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {

View File

@ -19,5 +19,5 @@ package gplx.xowa.xtns; import gplx.*; import gplx.xowa.*;
import gplx.xowa.html.*;
public interface Xox_xnde {
void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde);
void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde);
void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src);
}

View File

@ -20,5 +20,5 @@ import gplx.xowa.html.*;
public class Xtn_categorylist_nde implements Xox_xnde, Xop_xnde_atr_parser {
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {}
public void Xatr_parse(Xow_wiki wiki, byte[] src, Xop_xatr_itm xatr, Object xatr_key_obj) {}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {}
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
}

View File

@ -54,8 +54,8 @@ public class Ref_nde implements Xox_xnde, Xop_xnde_atr_parser {
ctx.Cur_page().Ref_mgr().Grps_add(group, name, follow, this);
this.xnde = xnde;
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
html_wtr.Ref_wtr().Xnde_ref(opts, bfr, src, xnde);
public void Xtn_write(Bry_bfr bfr, Xoa_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;

View File

@ -47,8 +47,8 @@ public class References_nde implements Xox_xnde, Xop_xnde_atr_parser {
}
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(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
html_wtr.Ref_wtr().Xnde_references(html_wtr, ctx, opts, bfr, src, xnde);
public void Xtn_write(Bry_bfr bfr, Xoa_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);
}
public static final byte Xatr_id_group = 0;
public static boolean Enabled = true;

View File

@ -27,7 +27,7 @@ public class Dpl_xnde implements Xox_xnde, Xop_xnde_atr_parser {
if (itm.Sort_ascending() != Bool_.__byte)
pages.SortBy(new Dpl_page_sorter(itm));
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xow_wiki wiki = ctx.Wiki();
Dpl_html_data html_mode = Dpl_html_data.new_(Dpl_itm_keys.Key_unordered);
int itms_len = pages.Count();

View 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.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.html.*; import gplx.xowa.hdumps.htmls.*;
public interface Gallery_box_w_fmtr_arg extends Bry_fmtr_arg {
Gallery_box_w_fmtr_arg Init(int uid, int width);
}
class Gallery_box_w_fmtr_arg__basic implements Gallery_box_w_fmtr_arg {
private int width;
public Gallery_box_w_fmtr_arg Init(int uid, int width) {this.width = width; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
bfr.Add(Style_bgn);
bfr.Add_int_variable(width);
bfr.Add(Style_end);
}
private static final byte[] Style_bgn = Bry_.new_ascii_("style=\"width: "), Style_end = Bry_.new_ascii_("px\"");
}
class Gallery_box_w_fmtr_arg__hdump implements Gallery_box_w_fmtr_arg {
private int uid;
public Gallery_box_w_fmtr_arg Init(int uid, int width) {this.uid = uid; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
bfr.Add(Hdump_html_consts.Key_gallery_box_w);
bfr.Add_int_variable(uid);
bfr.Add_byte_apos();
}
}
interface Gallery_img_pad_fmtr_arg extends Bry_fmtr_arg {
Gallery_img_pad_fmtr_arg Init(int uid, int vpad);
}
class Gallery_img_pad_fmtr_arg__basic implements Gallery_img_pad_fmtr_arg {
private int vpad;
public Gallery_img_pad_fmtr_arg Init(int uid, int vpad) {this.vpad = vpad; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
bfr.Add(Style_bgn);
bfr.Add_int_variable(vpad);
bfr.Add(Style_end);
}
private static final byte[] Style_bgn = Bry_.new_ascii_("style=\"margin:"), Style_end = Bry_.new_ascii_("px auto;\"");
}
class Gallery_img_pad_fmtr_arg__hdump implements Gallery_img_pad_fmtr_arg {
private int uid;
public Gallery_img_pad_fmtr_arg Init(int uid, int width) {this.uid = uid; return this;}
public void XferAry(Bry_bfr bfr, int idx) {
bfr.Add(Hdump_html_consts.Key_gallery_img_pad);
bfr.Add_int_variable(uid);
bfr.Add_byte_apos();
}
}

View File

@ -16,51 +16,44 @@ 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.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.files.*;
import gplx.xowa.html.*;
import gplx.xowa.files.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*; import gplx.xowa.hdumps.core.*; import gplx.xowa.hdumps.pages.*;
public class Gallery_html_wtr {
private int itms_per_row, itms_len; private boolean mode_is_packed;
public int Itm_div_w() {return itm_div_w;} private int itm_div_w;
public int Itm_div_h() {return itm_div_h;} private int itm_div_h;
public int Itm_box_w() {return itm_box_w;} private int itm_box_w;
public int Mgr_box_width_row() {return mgr_box_width_row;} private int mgr_box_width_row;
public int Mgr_box_width_all() {return mgr_box_width_all;} private int mgr_box_width_all;
public byte[] Mgr_box_cls() {return mgr_box_cls;} private byte[] mgr_box_cls;
public Bry_fmtr Mgr_box_style() {return mgr_box_style;} private Bry_fmtr mgr_box_style;
public int Gallery_multiplier() {return gallery_multiplier;} private int gallery_multiplier;
public void Write_html(Xoa_app app, Xow_wiki wiki, Xop_ctx ctx, Xoa_page page, Xoh_html_wtr wtr, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Gallery_xnde mgr) {
itms_per_row = mgr.Itms_per_row();
private final Xoh_arg_img_core img_core_fmtr_basic = new Xoh_arg_img_core__basic(), img_core_fmtr_hdump = new Xoh_arg_img_core__hdump();
public void Write_html(Bry_bfr bfr, Xoa_app app, Xow_wiki wiki, Xop_ctx ctx, Xoh_html_wtr wtr, Xoh_wtr_ctx hctx, Xoa_page page, Gallery_xnde mgr, byte[] src) {
int itm_div_w = Gallery_html_wtr_utl.Calc_itm_div_len(mgr.Itm_w_or_default());
int itm_div_h = Gallery_html_wtr_utl.Calc_itm_div_len(mgr.Itm_h_or_default());
int itm_box_w = Gallery_html_wtr_utl.Calc_itm_box_w(itm_div_w);
int itms_len = mgr.Itms_len();
int itms_per_row = mgr.Itms_per_row();
if (itms_per_row == Gallery_xnde.Null) itms_per_row = wiki.Cfg_gallery().Imgs_per_row();
itms_len = mgr.Itms_len();
itm_div_w = Gallery_html_wtr_utl.Calc_itm_div_len(mgr.Itm_w_or_default());
itm_div_h = Gallery_html_wtr_utl.Calc_itm_div_len(mgr.Itm_h_or_default());
itm_box_w = Gallery_html_wtr_utl.Calc_itm_box_w(itm_div_w);
int mgr_box_width_row = Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w) * itms_per_row;
int row_multiplier; Bry_fmtr mgr_box_style;
if (itms_per_row == Gallery_xnde.Null) { // no "perrow" defined; default to total # of items;
gallery_multiplier = itms_len;
mgr_box_style = fmtr_mgr_box_style_none;
row_multiplier = itms_len;
mgr_box_style = Gallery_html_wtr_.Mgr_box_style_none;
}
else {
gallery_multiplier = itms_per_row;
mgr_box_style = fmtr_mgr_box_style_per_row;
row_multiplier = itms_per_row;
mgr_box_style = Gallery_html_wtr_.Mgr_box_style_max;
}
mode_is_packed = Gallery_mgr_base_.Mode_is_packed(mgr.Mode());
int gallery_w_count = 0;
boolean mode_is_packed = Gallery_mgr_base_.Mode_is_packed(mgr.Mode());
byte[] mgr_box_cls; int mgr_box_width_all;
if (mode_is_packed) {
mgr_box_cls = Gallery_box_cls_packed;
mgr_box_cls = Gallery_html_wtr_.Cls_packed;
mgr_box_width_all = 0;
}
else {
mgr_box_cls = Bry_.Empty;
mgr_box_width_all = Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w) * gallery_multiplier; // 8=Gallery Box borders; REF.MW:ImageGallery.php|GB_BORDERS;
mgr_box_width_all = Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w) * row_multiplier; // 8=Gallery Box borders; REF.MW:ImageGallery.php|GB_BORDERS;
}
mgr_box_width_row = Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w) * itms_per_row;
int itm_box_w_tmp = itm_box_w;
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
Bry_bfr itm_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
int mgr_elem_id = -1;
Bry_bfr itm_bfr = wiki.Utl_bry_bfr_mkr().Get_k004(), tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
int mgr_elem_id = -1; int gallery_w_count = 0;
boolean hctx_is_hdump = hctx.Mode_is_hdump();
Xoh_arg_img_core img_core_fmtr = hctx_is_hdump ? img_core_fmtr_hdump : img_core_fmtr_basic;
Xopg_hdump_data hdump_imgs = page.Hdump_data();
for (int i = 0; i < itms_len; i++) {
Gallery_itm itm = mgr.Itms_get_at(i);
byte[] itm_caption = Bld_caption(wiki, wtr, ctx, hctx, itm);
byte[] itm_caption = Gallery_html_wtr_.Bld_caption(wiki, ctx, wtr, hctx, itm);
Xoa_ttl itm_ttl = itm.Ttl();
if ( itm_ttl != null // ttl does not have invalid characters
&& itm_ttl.Ns().Id_file() // ttl is in file ns;
@ -72,12 +65,12 @@ public class Gallery_html_wtr {
;
if (mode_is_packed) {
if (gallery_w_count < itms_per_row) {
mgr_box_width_all += Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w_tmp);
mgr_box_width_all += Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w);
++gallery_w_count;
}
if (xfer_itm.Html_w() > 0) {
itm_div_w = Gallery_html_wtr_utl.Calc_itm_div_len(xfer_itm.Html_w());
itm_box_w_tmp = Gallery_html_wtr_utl.Calc_itm_box_w(itm_div_w);
itm_box_w = Gallery_html_wtr_utl.Calc_itm_box_w(itm_div_w); // NOTE: redefine itm_box_w for rest of loop
}
if (xfer_itm.Html_h() > 0)
itm_div_h = Gallery_html_wtr_utl.Calc_itm_div_len(xfer_itm.Html_h());
@ -92,7 +85,6 @@ public class Gallery_html_wtr {
html_w = mgr.Itm_w_or_default();
html_h = mgr.Itm_h_or_default();
}
int v_pad = Gallery_html_wtr_utl.Calc_vpad(mgr.Itm_h(), html_h);
byte[] lnki_ttl = lnki.Ttl().Page_txt();
Xoa_ttl lnki_link_ttl = itm_ttl; // default href to ttl
if ( itm.Link_bgn() != Bry_.NotFound // link is not -1; EX: "A.png" has no link specified
@ -101,21 +93,23 @@ public class Gallery_html_wtr {
lnki_link_ttl = Xoa_ttl.parse_(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()));
byte[] lnki_href = app.Href_parser().Build_to_bry(wiki, lnki_link_ttl);
byte[] lnki_alt = itm.Alt_bgn() == Bry_.NotFound ? lnki_ttl : Xoh_html_wtr_escaper.Escape(app, tmp_bfr, Bry_.Mid(src, itm.Alt_bgn(), itm.Alt_end()));
fmtr_gallery_itm_img.Bld_bfr_many(itm_bfr
, itm_box_w_tmp, itm_div_w
, v_pad
img_core_fmtr.Init(itm_elem_id, html_src, html_w, html_h);
int itm_margin = Gallery_html_wtr_utl.Calc_vpad(mgr.Itm_h(), html_h);
Gallery_html_wtr_.Itm_img_fmtr.Bld_bfr_many(itm_bfr
, itm_box_w, itm_div_w, itm_margin
, itm_elem_id
, lnki_ttl
, lnki_href
, html_src
, html_w, html_h
, img_core_fmtr
, itm_caption
, lnki_alt
);
if (hctx_is_hdump)
hdump_imgs.Imgs_add(new Hdump_data_img__gallery().Init_by_gallery(-1, itm_div_w, itm_box_w, itm_margin), xfer_itm, Hdump_data_img__gallery.Tid_gallery);
}
else {
fmtr_gallery_itm_txt.Bld_bfr_many(itm_bfr
, itm_box_w_tmp, itm_div_h
Gallery_html_wtr_.Itm_txt_fmtr.Bld_bfr_many(itm_bfr
, itm_box_w, itm_div_h
, Bry_.Mid(src, itm.Ttl_bgn(), itm.Ttl_end())
, itm_caption
);
@ -124,9 +118,50 @@ public class Gallery_html_wtr {
itm_bfr.Mkr_rls();
tmp_bfr.Mkr_rls();
int mgr_box_width_max = mgr_box_width_all < mgr_box_width_row ? mgr_box_width_row : mgr_box_width_all;
fmtr_mgr_box.Bld_bfr_many(bfr, mgr_elem_id, mgr_box_cls, Bry_fmtr_arg_.fmtr_(mgr_box_style, Bry_fmtr_arg_.int_(mgr_box_width_max)), itm_bfr);
Gallery_html_wtr_.Mgr_all_fmtr.Bld_bfr_many(bfr, mgr_elem_id, mgr_box_cls, Bry_fmtr_arg_.fmtr_(mgr_box_style, Bry_fmtr_arg_.int_(mgr_box_width_max)), itm_bfr);
}
private static byte[] Bld_caption(Xow_wiki wiki, Xoh_html_wtr wtr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Gallery_itm itm) {
}
class Gallery_html_wtr_ {
public static final byte[] Cls_packed = Bry_.new_utf8_(" mw-gallery-packed");
public static final Bry_fmtr
Mgr_all_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_~{gallery_id}\" class=\"gallery~{gallery_cls}\" style=\"~{gallery_style}\">~{itm_list}"
, "</ul>"
), "gallery_id", "gallery_cls", "gallery_style", "itm_list"
)
, Mgr_box_style_none = Bry_fmtr.new_()
, Mgr_box_style_max = Bry_fmtr.new_("max-width:~{gallery_width}px; _width:~{gallery_width}px;", "gallery_width")
, Itm_img_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li id=\"xowa_gallery_li_~{img_id}\" class=\"gallerybox\" style=\"width:~{itm_box_width}px;\">"
, " <div id=\"xowa_gallery_div1_~{img_id}\" style=\"width:~{itm_box_width}px;\">"
, " <div id=\"xowa_gallery_div2_~{img_id}\" class=\"thumb\" style=\"width:~{itm_div_width}px;\">"
, " <div id=\"xowa_gallery_div3_~{img_id}\" style=\"margin:~{itm_margin}px auto;\">"
, " <a href=\"~{img_href}\" class=\"image\">"
, " <img id=\"xowa_file_img_~{img_id}\" alt=\"~{img_alt}\"~{img_core} />"
, " </a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\">~{itm_caption}"
, " </div>"
, " </div>"
, " </li>"
), "itm_box_width", "itm_div_width", "itm_margin", "img_id", "img_ttl", "img_href", "img_core", "itm_caption", "img_alt"
)
, Itm_txt_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li id=\"xowa_gallery_li_~{img_id}\" class=\"gallerybox\" style=\"width:~{itm_box_width};\">"
, " <div id=\"xowa_gallery_div1_~{img_id}\" style=\"width:~{itm_box_width};\">"
, " <div id=\"xowa_gallery_div2_~{img_id}\" style=\"~{itm_div_height}\">"
, " ~{itm_text}"
, " </div>"
, " <div class=\"gallerytext\">~{itm_caption}"
, " </div>"
, " </div>"
, " </li>"
), "itm_box_width", "itm_div_height", "itm_text", "itm_caption"
);
public static byte[] Bld_caption(Xow_wiki wiki, Xop_ctx ctx, Xoh_html_wtr wtr, Xoh_wtr_ctx hctx, Gallery_itm itm) {
byte[] rv = itm.Caption_bry();
if (Bry_.Len_gt_0(rv)) {
Bry_bfr caption_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
@ -136,44 +171,4 @@ public class Gallery_html_wtr {
}
return rv;
}
private static final byte[] Gallery_box_cls_packed = Bry_.new_utf8_(" mw-gallery-packed");
private Bry_fmtr
fmtr_mgr_box = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_~{gallery_id}\" class=\"gallery~{gallery_cls}\" style=\"~{gallery_style}\">~{itm_list}"
, "</ul>"
), "gallery_id", "gallery_cls", "gallery_style", "itm_list"
)
, fmtr_gallery_itm_img = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li id=\"xowa_gallery_li_~{img_id}\" class=\"gallerybox\" style=\"width:~{itm_box_width}px;\">"
, " <div id=\"xowa_gallery_div1_~{img_id}\" style=\"width:~{itm_box_width}px;\">"
, " <div id=\"xowa_gallery_div2_~{img_id}\" class=\"thumb\" style=\"width:~{itm_div_width}px;\">"
, " <div id=\"xowa_gallery_div3_~{img_id}\" style=\"margin:~{itm_margin}px auto;\">"
, " <a href=\"~{img_href}\" class=\"image\">"
, " <img id=\"xowa_file_img_~{img_id}\" alt=\"~{img_alt}\" src=\"~{html_src}\" width=\"~{img_width}\" height=\"~{img_height}\" />"
, " </a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\">~{itm_caption}"
, " </div>"
, " </div>"
, " </li>"
), "itm_box_width", "itm_div_width", "itm_margin", "img_id", "img_ttl", "img_href", "html_src", "img_width", "img_height", "itm_caption", "img_alt"
)
, fmtr_gallery_itm_txt = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li id=\"xowa_gallery_li_~{img_id}\" class=\"gallerybox\" style=\"width:~{itm_box_width};\">"
, " <div id=\"xowa_gallery_div1_~{img_id}\" style=\"width:~{itm_box_width};\">"
, " <div id=\"xowa_gallery_div2_~{img_id}\" style=\"~{itm_div_height}\">"
, " ~{itm_text}"
, " </div>"
, " <div class=\"gallerytext\">~{itm_caption}"
, " </div>"
, " </div>"
, " </li>"
), "itm_box_width", "itm_div_height", "itm_text", "itm_caption"
)
, fmtr_mgr_box_style_none = Bry_fmtr.new_()
, fmtr_mgr_box_style_per_row = Bry_fmtr.new_("max-width:~{gallery_width}px; _width:~{gallery_width}px;", "gallery_width")
;
}

View File

@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.files.*; import gplx.xowa.files.gui.*; import gplx.xowa.gui.views.*;
import gplx.xowa.files.*; import gplx.xowa.files.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.html.*;
public class Gallery_itm implements Js_img_wkr {
public Xoa_ttl Ttl() {return ttl;} public Gallery_itm Ttl_(Xoa_ttl v) {ttl = v; return this;} private Xoa_ttl ttl;
public int Ttl_bgn() {return ttl_bgn;} public Gallery_itm Ttl_bgn_(int v) {ttl_bgn = v; return this;} private int ttl_bgn;
@ -43,12 +43,12 @@ public class Gallery_itm implements Js_img_wkr {
this.xnde = xnde; this.xfer_itm = xfer_itm;;
this.wiki = wiki; this.ctx = ctx; this.src = src; this.gallery_li_id_bry = gallery_li_id_bry; this.gallery_itm_idx = gallery_itm_idx;
} private Gallery_xnde xnde; private Xof_xfer_itm xfer_itm; private Xow_wiki wiki; private Xop_ctx ctx; private byte[] src; private byte[] gallery_li_id_bry; private int gallery_itm_idx;
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src) {
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, byte[] lnki_ttl) {
Gallery_mgr_base gallery_mgr = xnde.Gallery_mgr();
Bry_bfr bfr = wiki.Utl_bry_bfr_mkr().Get_k004(), tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
try {
xfer_itm.Init_for_gallery_update(html_w, html_h, html_src, orig_src);
gallery_mgr.Write_html_itm(bfr, tmp_bfr, wiki.App(), wiki, ctx.Cur_page(), ctx, wiki.Html_mgr().Html_wtr(), src, xnde, Bry_.Empty, gallery_itm_idx, xfer_itm);
gallery_mgr.Write_html_itm(bfr, tmp_bfr, wiki.App(), wiki, ctx.Cur_page(), ctx, wiki.Html_mgr().Html_wtr(), Xoh_wtr_ctx.Basic, src, xnde, Bry_.Empty, gallery_itm_idx, xfer_itm, false, -1);
String itm_html = bfr.XtoStrAndClear();
html_itm.Html_elem_replace_html(String_.new_utf8_(gallery_li_id_bry), itm_html);
if (gallery_itm_idx == xnde.Itms_len() - 1 && Gallery_mgr_base_.Mode_is_packed(xnde.Mode()))

View File

@ -16,9 +16,10 @@ 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.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.html.*; import gplx.xowa.html.*; import gplx.xowa.html.modules.*;
import gplx.xowa.files.*;
import gplx.html.*; import gplx.xowa.html.*; import gplx.xowa.html.modules.*; import gplx.xowa.files.*; import gplx.xowa.hdumps.htmls.*; import gplx.xowa.hdumps.core.*;
public abstract class Gallery_mgr_base {
private Gallery_box_w_fmtr_arg__basic box_w_fmtr__basic = new Gallery_box_w_fmtr_arg__basic(); private Gallery_box_w_fmtr_arg__hdump box_w_fmtr__hdump = new Gallery_box_w_fmtr_arg__hdump();
private Gallery_img_pad_fmtr_arg__basic img_pad_fmtr__basic = new Gallery_img_pad_fmtr_arg__basic(); private Gallery_img_pad_fmtr_arg__hdump img_pad_fmtr__hdump = new Gallery_img_pad_fmtr_arg__hdump();
public abstract byte Tid();
public abstract byte[] Tid_bry();
@gplx.Virtual public boolean Tid_is_packed() {return false;}
@ -50,29 +51,32 @@ public abstract class Gallery_mgr_base {
.Add(Wrap_gallery_text_end)
;
}
public void Write_html(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page, Xop_ctx ctx, byte[] src, Gallery_xnde xnde) {
public void Write_html(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Gallery_xnde xnde) {
boolean hctx_is_hdump = hctx.Mode_is_hdump();
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_b512();
byte[] box_style = xnde.Atr_style();
int max_width = -1;
if (itms_per_row > 0) {
int max_width = itms_per_row * (itm_default_w + this.Get_all_padding());
max_width = itms_per_row * (itm_default_w + this.Get_all_padding());
box_style = Fmt_and_add(tmp_bfr, box_style_max_width_fmtr, box_style, max_width);
}
byte[] box_cls = Fmt_and_add(tmp_bfr, box_cls_fmtr, xnde.Atr_cls(), this.Tid_bry());
byte[] gallery_ul_id = tmp_bfr.Add(box_id_prefix_bry).Add_int_variable(page.File_queue().Elem_id().Val_add()).XtoAryAndClear();
Box_hdr_write(bfr, wiki.App().Html_mgr().Whitelist_mgr(), src, gallery_ul_id, box_cls, box_style, xnde.Atrs_other());
int gallery_uid = page.Html_data().Xtn_gallery_next_id();
byte[] gallery_ul_id = tmp_bfr.Add(box_id_prefix_bry).Add_int_variable(gallery_uid).XtoAryAndClear();
Box_hdr_write(bfr, wiki.App().Html_mgr().Whitelist_mgr(), src, gallery_ul_id, box_cls, box_style, xnde.Atrs_other(), hctx_is_hdump, gallery_uid);
byte[] box_caption = xnde.Atr_caption();
if (Bry_.Len_gt_0(box_caption)) box_caption_fmtr.Bld_bfr_many(bfr, box_caption);
Xoa_app app = wiki.App(); Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
int itm_len = xnde.Itms_len();
for (int i = 0; i < itm_len; i++) {
Write_html_itm(bfr, tmp_bfr, app, wiki, page, ctx, html_wtr, src, xnde, gallery_ul_id, i, null) ;
Write_html_itm(bfr, tmp_bfr, app, wiki, page, ctx, html_wtr, hctx, src, xnde, gallery_ul_id, i, null, hctx_is_hdump, max_width);
}
bfr.Add(box_html_end_bry);
tmp_bfr.Mkr_rls();
} private static final byte[] box_id_prefix_bry = Bry_.new_ascii_("xowa_gallery_ul_"), itm_id_prefix_bry = Bry_.new_ascii_("xowa_gallery_li_");
public static byte File_found_mode = Bool_.__byte;
public void Write_html_itm(Bry_bfr bfr, Bry_bfr tmp_bfr, Xoa_app app, Xow_wiki wiki, Xoa_page page, Xop_ctx ctx, Xoh_html_wtr html_wtr, byte[] src, Gallery_xnde xnde, byte[] gallery_ul_id, int i, Xof_xfer_itm xfer_itm) {
public void Write_html_itm(Bry_bfr bfr, Bry_bfr tmp_bfr, Xoa_app app, Xow_wiki wiki, Xoa_page page, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, byte[] src, Gallery_xnde xnde, byte[] gallery_ul_id, int i, Xof_xfer_itm xfer_itm, boolean hctx_is_hdump, int max_width) {
Gallery_itm itm = (Gallery_itm)xnde.Itms_get_at(i);
Xoa_ttl ttl = itm.Ttl();
byte[] itm_caption = itm.Caption_bry(); if (itm_caption == null) itm_caption = Bry_.Empty;
@ -86,13 +90,15 @@ public abstract class Gallery_mgr_base {
.Html_elem_tid_(Xof_html_elem.Tid_gallery_v2)
;
}
byte[] gallery_li_id = tmp_bfr.Add(itm_id_prefix_bry).Add_int_variable(xfer_itm.Html_uid()).XtoAryAndClear();
int img_uid = xfer_itm.Html_uid();
byte[] gallery_li_id = tmp_bfr.Add(itm_id_prefix_bry).Add_int_variable(img_uid).XtoAryAndClear();
byte[] itm_html = Bry_.Empty;
int html_w_expand = xfer_itm.Html_w();
int html_h_expand = xfer_itm.Html_h();
boolean file_found = xfer_itm.File_found();
if (File_found_mode != Bool_.__byte)
file_found = File_found_mode == Bool_.Y_byte;
int vpad = -1, img_div_w = -1;
if ( !ttl.Ns().Id_file()
|| !file_found
) { // itm is not a file, or is not found; write text
@ -116,9 +122,12 @@ public abstract class Gallery_mgr_base {
int html_w_normal = xfer_itm.Html_w();
int html_h_normal = xfer_itm.Html_h();
xfer_itm.Init_for_gallery(html_w_normal, html_h_normal, html_w_expand);// NOTE: file_w should be set to expanded width so js can resize if gallery
itm_div0_fmtr.Bld_bfr_many(tmp_bfr, this.Get_thumb_div_width(html_w_expand));
itm_div1_fmtr.Bld_bfr_many(tmp_bfr, this.Get_vpad(itm_default_h, html_h_expand)); // <div style="margin:~{vpad}px auto;">
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_file(tmp_bfr, ctx, Xoh_wtr_ctx.Basic, src, lnki, xfer_itm, alt);
img_div_w = this.Get_thumb_div_width(html_w_expand);
itm_div0_fmtr.Bld_bfr_many(tmp_bfr, img_div_w);
Gallery_img_pad_fmtr_arg vpad_fmtr = hctx_is_hdump ? (Gallery_img_pad_fmtr_arg)img_pad_fmtr__hdump : (Gallery_img_pad_fmtr_arg)img_pad_fmtr__basic;
vpad = this.Get_vpad(itm_default_h, html_h_expand);
itm_div1_fmtr.Bld_bfr_many(tmp_bfr, vpad_fmtr.Init(img_uid, vpad)); // <div style="margin:~{vpad}px auto;">
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_file(tmp_bfr, ctx, hctx, src, lnki, xfer_itm, alt);
tmp_bfr.Add(itm_divs_end_bry);
itm_html = tmp_bfr.XtoAryAndClear();
}
@ -127,21 +136,24 @@ public abstract class Gallery_mgr_base {
if (xnde.Show_filename()) {
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_plain_by_bry
( tmp_bfr, src, lnki
, Bry_.Limit(ttl.Page_txt(), 25) // 25 is defined by captionLength in DefaultSettings.php
, Bry_.Limit(ttl.Page_txt(), 25) // 25 is defined by captionLength in DefaultSettings.php
); // MW:passes know,noclasses which isn't relevant to XO
}
int itm_div_width = this.Get_gb_width(html_w_expand, html_h_expand);
itm_li_bgn_fmtr.Bld_bfr_many(bfr, gallery_li_id, itm_div_width);
Gallery_box_w_fmtr_arg box_w_fmtr_arg = hctx_is_hdump ? (Gallery_box_w_fmtr_arg)box_w_fmtr__hdump : (Gallery_box_w_fmtr_arg)box_w_fmtr__basic;
itm_li_bgn_fmtr.Bld_bfr_many(bfr, gallery_li_id, box_w_fmtr_arg.Init(img_uid, itm_div_width));
bfr.Add(itm_html);
wiki.Parser().Parse_text_to_html(tmp_bfr, page, true, itm_caption);
itm_caption = tmp_bfr.XtoAryAndClear();
itm_caption = tmp_bfr.Add(show_filenames_link).Add(itm_caption).XtoAryAndClear();
Wrap_gallery_text(bfr, itm_caption, html_w_expand, html_h_expand);
bfr.Add(itm_li_end_bry);
if (hctx_is_hdump)
page.Hdump_data().Imgs_add(new Hdump_data_img__gallery().Init_by_gallery(max_width, itm_div_width, img_div_w, vpad), xfer_itm, Hdump_data_img__gallery.Tid_gallery);
}
private static final byte[]
Wrap_gallery_text_bgn = Bry_.new_ascii_("\n <div class=\"gallerytext\">") // NOTE: The newline after <div class="gallerytext"> is needed to accommodate htmltidy
, Wrap_gallery_text_end = Bry_.new_ascii_("\n </div>")
, Wrap_gallery_text_end = Bry_.new_ascii_("\n </div>") // NOTE: prepend "\n"; will cause extra \n when caption exists, but needed when caption doesn't exists; EX: "<div class='caption'> </div>"; \n puts
;
@gplx.Virtual public void Get_thumb_size(Xop_lnki_tkn lnki, Xof_ext ext) { // REF.MW: getThumbParams; Get the transform parameters for a thumbnail.
lnki.Lnki_w_(itm_default_w);
@ -149,15 +161,18 @@ public abstract class Gallery_mgr_base {
}
@gplx.Virtual public void Adjust_image_parameters(Xof_xfer_itm xfer_itm) { // REF.MW: Adjust the image parameters for a thumbnail. Used by a subclass to insert extra high resolution images.
}
private static final Bry_fmtr
public static final Bry_fmtr
box_style_max_width_fmtr = Bry_fmtr.new_( "max-width:~{max_width}px;_width:~{max_width}px;", "max_width") // id=xowa_gallery_ul_1
, box_cls_fmtr = Bry_fmtr.new_( "gallery mw-gallery-~{mode}", "mode")
, box_caption_fmtr = Bry_fmtr.new_( "\n <li class='gallerycaption'>~{caption}</li>", "caption")
, itm_li_bgn_fmtr = Bry_fmtr.new_( "\n <li id=\"~{id}\" class=\"gallerybox\" style=\"width: ~{width}px\">" // id=xowa_gallery_li_1
+ "\n <div style=\"width: ~{width}px\">", "id", "width")
, itm_li_bgn_fmtr = Bry_fmtr.new_( "\n <li id=\"~{id}\" class=\"gallerybox\" ~{itm_box_w}>" // id=xowa_gallery_li_1
+ "\n <div ~{itm_box_w}>", "id", "itm_box_w")
, itm_div0_fmtr = Bry_fmtr.new_( "\n <div class=\"thumb\" style=\"width: ~{width}px;\">", "width")
, itm_missing_fmtr = Bry_fmtr.new_( "\n <div class=\"thumb\" style=\"height: ~{height}px;\">~{ttl_text}</div>", "height", "ttl_text")
, itm_div1_fmtr = Bry_fmtr.new_( "\n <div style=\"margin:~{vpad}px auto;\">\n ", "vpad")
, itm_div1_fmtr = Bry_fmtr.new_( "\n <div ~{vpad}>\n ", "vpad")
, hdump_box_w_fmtr = Bry_fmtr.new_( "width:~{width}px;", "width")
, hdump_img_pad_fmtr = Bry_fmtr.new_( "margin:~{width}px auto;", "width")
;
private static final byte[]
@ -174,11 +189,18 @@ public abstract class Gallery_mgr_base {
}
return tmp_bfr.XtoAryAndClear();
}
private static void Box_hdr_write(Bry_bfr bfr, Xop_xatr_whitelist_mgr whitelist_mgr, byte[] src, byte[] gallery_ul_uid, byte[] cls, byte[] style, ListAdp xatr_list) {
private static void Box_hdr_write(Bry_bfr bfr, Xop_xatr_whitelist_mgr whitelist_mgr, byte[] src, byte[] gallery_ul_uid, byte[] cls, byte[] style, ListAdp xatr_list, boolean hctx_is_hdump, int uid) {
bfr.Add_byte(Byte_ascii.Lt).Add(Html_tag_.Ul_name_bry);
Html_wtr.Write_atr(bfr, Html_atr_.Id_bry, gallery_ul_uid);
Html_wtr.Write_atr(bfr, Html_atr_.Cls_bry, cls);
Html_wtr.Write_atr(bfr, Html_atr_.Style_bry, style);
Html_wtr.Write_atr_bry(bfr, Html_atr_.Id_bry, gallery_ul_uid);
Html_wtr.Write_atr_bry(bfr, Html_atr_.Cls_bry, cls);
if (hctx_is_hdump) {
bfr.Add_byte_space();
bfr.Add(Hdump_html_consts.Key_gallery_box_max);
bfr.Add_int_variable(uid);
bfr.Add_byte_apos();
}
else
Html_wtr.Write_atr_bry(bfr, Html_atr_.Style_bry, style);
if (xatr_list != null) {
int len = xatr_list.Count();
for (int i = 0; i < len; i++) {
@ -186,7 +208,7 @@ public abstract class Gallery_mgr_base {
if (!whitelist_mgr.Chk(Xop_xnde_tag_.Tid_ul, src, xatr)) continue;
byte[] key = xatr.Key_bry();
byte[] val = xatr.Val_as_bry(src);
Html_wtr.Write_atr(bfr, key, val);
Html_wtr.Write_atr_bry(bfr, key, val);
}
}
bfr.Add_byte(Byte_ascii.Gt);

View File

@ -29,11 +29,11 @@ public class Gallery_mgr_base_basic_tst {
, "</gallery>"
), String_.Concat_lines_nl_skip_last
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width: 235px\">"
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width: 235px\">"
, " <div style=\"width: 235px\">"
, " <div class=\"thumb\" style=\"width: 230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>a1</i>"
@ -42,11 +42,11 @@ public class Gallery_mgr_base_basic_tst {
, " </div>"
, " </div>"
, " </li>"
, " <li id=\"xowa_gallery_li_2\" class=\"gallerybox\" style=\"width: 235px\">"
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width: 235px\">"
, " <div style=\"width: 235px\">"
, " <div class=\"thumb\" style=\"width: 230px;\">"
, " <div style=\"margin:15px auto;\">"
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_2\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\"><p><i>b1</i>"
@ -64,7 +64,7 @@ public class Gallery_mgr_base_basic_tst {
fxt.Test_html_frag("<gallery>File:A.png|a{{test_tmpl}}c</gallery>", "<div class=\"gallerytext\"><p>abc\n</p>");
}
@Test public void Itm_defaults_to_120() {
fxt.Test_html_frag("<gallery>File:A.png|a</gallery>", "<img id=\"xowa_file_img_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />");
fxt.Test_html_frag("<gallery>File:A.png|a</gallery>", "<img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />");
}
@Test public void Height_fix() {
fxt.Fxt().Wiki().File_mgr().Cfg_set(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults, "y");
@ -73,7 +73,7 @@ public class Gallery_mgr_base_basic_tst {
}
@Test public void Alt() {
fxt.Test_html_frag("<gallery>File:A.png|b|alt=c</gallery>"
, "<img id=\"xowa_file_img_1\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"
, "<img id=\"xowa_file_img_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"
, "<div class=\"gallerytext\"><p>b\n</p>"
);
}
@ -90,7 +90,7 @@ public class Gallery_mgr_base_basic_tst {
fxt.Test_html_frag("<gallery>File:A.png</gallery>", "<div class=\"gallerytext\">\n");
}
@Test public void Ttl_has_no_ns() { // PURPOSE: MW allows ttl to not have ns; DATE: 2013-11-18
fxt.Test_html_frag("<gallery>A.png|b</gallery>", "<img id=\"xowa_file_img_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"); // make sure image is generated
fxt.Test_html_frag("<gallery>A.png|b</gallery>", "<img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"); // make sure image is generated
}
@Test public void Ref() { // PURPOSE: <ref> inside <gallery> was not showing up in <references>; DATE:2013-10-09
fxt.Test_html_frag("<gallery>File:A.png|<ref name='a'>b</ref></gallery><references/>"

View File

@ -69,13 +69,13 @@ public class Gallery_xnde implements Xox_xnde, Xop_xnde_atr_parser {
wiki.App().Usr_dlg().Warn_many("", "", "failed to write gallery; src=~{0} err=~{1}", String_.new_utf8_(src, xnde.Src_bgn(), xnde.Src_end()), Err_.Message_gplx(exc));
}
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xow_wiki wiki = ctx.Wiki();
try {
if (html_wtr_v1)
xtn_mgr.Html_wtr().Write_html(app, wiki, ctx, ctx.Cur_page(), html_wtr, opts, bfr, src, this);
xtn_mgr.Html_wtr().Write_html(bfr, app, wiki, ctx, html_wtr, hctx, ctx.Cur_page(), this, src);
else {
gallery_mgr.Write_html(bfr, wiki, ctx.Cur_page(), ctx, src, this);
gallery_mgr.Write_html(bfr, wiki, ctx.Cur_page(), ctx, hctx, src, this);
}
} catch (Exception exc) {
wiki.App().Usr_dlg().Warn_many("", "", "failed to write gallery; src=~{0} err=~{1}", String_.new_utf8_(src, xnde.Src_bgn(), xnde.Src_end()), Err_.Message_gplx(exc));

View File

@ -16,9 +16,10 @@ 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.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.html.*;
import gplx.html.*; import gplx.xowa.html.*;
class Hiero_html_mgr {
private Bry_bfr html_bfr = Bry_bfr.reset_(Io_mgr.Len_kb), content_bfr = Bry_bfr.reset_(255), tbl_content_bfr = Bry_bfr.reset_(Io_mgr.Len_kb), temp_bfr = Bry_bfr.reset_(255);
private Xoh_wtr_ctx hctx;
private boolean cartouche_opened = false;
public static int scale = 100;
private Hiero_prefab_mgr prefab_mgr; private Hiero_file_mgr file_mgr; private Hiero_phoneme_mgr phoneme_mgr;
@ -29,7 +30,8 @@ class Hiero_html_mgr {
phoneme_mgr = xtn_mgr.Phoneme_mgr();
wtr = new Hiero_html_wtr(this, phoneme_mgr);
}
public void Render_blocks(Bry_bfr final_bfr, Hiero_block[] blocks, int scale, boolean hr_enabled) {
public void Render_blocks(Bry_bfr final_bfr, Xoh_wtr_ctx hctx, Hiero_block[] blocks, int scale, boolean hr_enabled) {
this.hctx = hctx; wtr.Init_for_write(hctx);
Hiero_html_mgr.scale = scale;
tbl_content_bfr.Clear(); content_bfr.Clear(); temp_bfr.Clear();
cartouche_opened = false;
@ -174,9 +176,9 @@ class Hiero_html_mgr {
else if (Bry_.Eq(glyph, Tkn_dot)) // render 1/2 width void block
return wtr.Void(Bool_.Y);
else if (Bry_.Eq(glyph, Tkn_lt))
return wtr.Cartouche_img(Bool_.Y, glyph);
return wtr.Cartouche_img(hctx, Bool_.Y, glyph);
else if (Bry_.Eq(glyph, Tkn_gt))
return wtr.Cartouche_img(Bool_.N, glyph);
return wtr.Cartouche_img(hctx, Bool_.N, glyph);
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph);
Hiero_file_itm file_itm = null;
@ -235,157 +237,3 @@ class Hiero_html_mgr {
, Tkn_dot_dot = new byte[] {Byte_ascii.Dot, Byte_ascii.Dot}
;
}
class Hiero_html_wtr {
private Hiero_phoneme_mgr phoneme_mgr;
private Bry_bfr temp_bfr = Bry_bfr.reset_(255);
public Hiero_html_wtr(Hiero_html_mgr mgr, Hiero_phoneme_mgr phoneme_mgr) {this.phoneme_mgr = phoneme_mgr;}
public void Hr(Bry_bfr bfr) {bfr.Add(Html_tag_.Hr_inl).Add_byte_nl();}
public void Tbl_eol(Bry_bfr bfr) {bfr.Add(Tbl_eol_bry);}
private static final String
Tbl_bgn_str = "<table class=\"mw-hiero-table\">"
;
private static final byte[]
Tbl_eol_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " </tr>"
, " </table>"
, " " + Tbl_bgn_str
, " <tr>"
));
public byte[] Td_height(int height) {
return temp_bfr.Add(Option_bgn_bry).Add_int_variable(height).Add(Option_end_bry).XtoAryAndClear();
}
private static final byte[]
Option_bgn_bry = Bry_.new_ascii_("height: ")
, Option_end_bry = Bry_.new_ascii_("px;")
;
public void Td(Bry_bfr bfr, byte[] glyph) {
bfr.Add(Td_bgn_bry).Add(glyph).Add(Td_end_bry);
}
private static final byte[]
Td_bgn_bry = Bry_.new_ascii_("\n <td>")
, Td_end_bry = Bry_.new_ascii_("\n </td>")
;
public void Cartouche_bgn(Bry_bfr bfr) {
bfr.Add(Cartouche_bgn_lhs_bry).Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100).Add(Cartouche_bgn_rhs_bry);
}
private static final byte[]
Cartouche_bgn_lhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " <td>"
, " " + Tbl_bgn_str
, " <tr>"
, " <td class='mw-hiero-box' style='height: "
))
, Cartouche_bgn_rhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "px;'>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>"
, " " + Tbl_bgn_str
, " <tr>"
))
;
public void Cartouche_end(Bry_bfr bfr) {
bfr.Add(Cartouche_end_lhs_bry).Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100).Add(Cartouche_end_rhs_bry);
}
private static final byte[]
Cartouche_end_lhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td class='mw-hiero-box' style='height: "
))
, Cartouche_end_rhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "px;'>"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
));
public byte[] Cartouche_img(boolean bgn, byte[] glyph) { // render open / close cartouche; note that MW has two branches, but they are both the same
int height = (int)((Hiero_html_mgr.Max_height * Hiero_html_mgr.scale) / 100);
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph); if (phoneme_itm == null) throw Err_.new_fmt_("missing phoneme: {0}", String_.new_utf8_(glyph));
byte[] code = phoneme_itm.Gardiner_code();
byte[] title = bgn ? Html_entity_.Lt_bry : Html_entity_.Gt_bry;
return cartouche_img_fmtr.Bld_bry_many(temp_bfr, Hiero_xtn_mgr.Img_src_dir, code, height, title);
}
private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_(String_.Concat
( "\n <img src='~{path}hiero_~{code}.png'"
, " height='~{height}' title='~{title}'"
, " alt='~{title}' />"
)
, "path", "code", "height", "title");
public void Tbl_inner(Bry_bfr html_bfr, Bry_bfr text_bfr) {
html_bfr.Add(Tbl_inner_bgn).Add_bfr_and_clear(text_bfr).Add(Tbl_inner_end); // $html .= self::TABLE_START . "<tr>\n" . $tableContentHtml . '</tr></table>';
}
private static final byte[]
Tbl_inner_bgn = Bry_.new_utf8_(String_.Concat_lines_nl_skip_last
( " <table class=\"mw-hiero-table\">"
, " <tr>"
))
, Tbl_inner_end = Bry_.new_utf8_(String_.Concat_lines_nl_skip_last
( ""
, " </tr>"
, " </table>"
))
;
public void Tbl_outer(Bry_bfr bfr, Bry_bfr html_bfr) {
bfr.Add(Outer_tbl_bgn);
bfr.Add_bfr_and_clear(html_bfr);
bfr.Add(Outer_tbl_end);
}
private static final byte[]
Outer_tbl_bgn = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, ""
)
)
, Outer_tbl_end = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " </td>"
, " </tr>"
, "</table>"
, ""
))
;
public byte[] Img_phoneme(byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) {
byte[] code_esc = Html_utl.Escape_html_as_bry(temp_bfr, code);
byte[] img_title = temp_bfr.Add(code_esc).Add_byte_space().Add_byte(Byte_ascii.Brack_bgn).Add(glyph_esc).Add_byte(Byte_ascii.Brack_end).XtoAryAndClear(); // "~{code} [~{glyph}]"
return Img(img_cls, td_height, glyph_esc, code_esc, img_title);
}
public byte[] Img_file(byte[] img_cls, byte[] td_height, byte[] glyph_esc) {return Img(img_cls, td_height, glyph_esc, glyph_esc, glyph_esc);}
private byte[] Img(byte[] img_cls, byte[] td_height, byte[] glyph, byte[] img_src_name, byte[] img_title) {
byte[] img_src = Bld_img_src(img_src_name);
return glyph_img_fmtr.Bld_bry_many(temp_bfr, img_cls, Hiero_html_mgr.Image_margin, td_height, img_src, img_title, glyph);
}
private static final Bry_fmtr
glyph_img_fmtr = Bry_fmtr.new_
( "\n <img ~{img_cls}style='margin: ~{img_margin}px; ~{option}' src='~{img_src}' title='~{img_title}' alt='~{glyph}' />", "img_cls", "img_margin", "option", "img_src", "img_title", "glyph")
;
public byte[] Void(boolean half) { // render void
int width = Hiero_html_mgr.Max_height;
if (half) width /= 2;
return void_fmtr.Bld_bry_many(temp_bfr, width);
}
private static final Bry_fmtr void_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <table class=\"mw-hiero-table\" style=\"width: ~{width}px;\">"
, " <tr>"
, " <td>&#160;"
, " </td>"
, " </tr>"
, " </table>"
)
, "width");
private static byte[] Bld_img_src(byte[] name) {
return Bry_.Add(Hiero_xtn_mgr.Img_src_dir, Img_src_prefix, name, Img_src_ext);
}
private static final byte[] Img_src_prefix = Bry_.new_ascii_("hiero_"), Img_src_ext = Bry_.new_ascii_(".png");
}

View File

@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Hiero_html_mgr_fxt {
private Hiero_xtn_mgr xtn_mgr;
public Hiero_html_mgr_fxt(Xop_fxt fxt) {this.fxt = fxt;}
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt;
public void Reset() {
fxt.Reset();
xtn_mgr = new Hiero_xtn_mgr();
xtn_mgr.Xtn_init_by_app(fxt.App());
xtn_mgr.Clear();
}
public Hiero_html_mgr_fxt Init_hiero_A1_B1() {
this.Init_file("A1", 29, 38);
this.Init_file("B1", 23, 38);
return this;
}
public Hiero_html_mgr_fxt Init_hiero_cartouche() {
this.Init_phoneme("<", "Ca1");
this.Init_phoneme(">", "Ca2");
return this;
}
public Hiero_html_mgr_fxt Init_hiero_p_t() {
this.Init_phoneme("p", "Q3");
this.Init_phoneme("t", "X1");
this.Init_file("Q3", 12, 15);
this.Init_file("X1", 20, 11);
return this;
}
public Hiero_html_mgr_fxt Init_hiero_a_A1() {
this.Init_prefab("a&A1");
this.Init_file("a&A1", 37, 38);
return this;
}
public Hiero_html_mgr_fxt Init_prefab(String prefab) {xtn_mgr.Prefab_mgr().Add(Bry_.new_utf8_(prefab)); return this;}
public Hiero_html_mgr_fxt Init_file(String s, int w, int h) {xtn_mgr.File_mgr().Add(Bry_.new_utf8_(s), w, h); return this;}
public Hiero_html_mgr_fxt Init_phoneme(String phoneme, String code) {xtn_mgr.Phoneme_mgr().Add(Bry_.new_utf8_(phoneme), Bry_.new_utf8_(code)); return this;}
public void Test_html_full_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
public void Test_html_full_frag(String raw, String expd) {fxt.Test_html_full_frag(raw, expd);}
}

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
public class Hiero_html_mgr_tst {
@Before public void init() {fxt.Reset();} private Hiero_html_mgr_fxt fxt = new Hiero_html_mgr_fxt();
@Before public void init() {fxt.Reset();} private Hiero_html_mgr_fxt fxt = new Hiero_html_mgr_fxt(new Xop_fxt());
@Test public void Empty() {
fxt.Test_html_full_str
( "<hiero></hiero>"
@ -387,39 +387,3 @@ public class Hiero_html_mgr_tst {
fxt.Fxt().Init_para_n_();
}
}
class Hiero_html_mgr_fxt {
private Hiero_xtn_mgr xtn_mgr;
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt = new Xop_fxt();
public void Reset() {
fxt.Reset();
xtn_mgr = new Hiero_xtn_mgr();
xtn_mgr.Xtn_init_by_app(fxt.App());
xtn_mgr.Clear();
}
public Hiero_html_mgr_fxt Init_hiero_A1_B1() {
this.Init_file("A1", 29, 38);
this.Init_file("B1", 23, 38);
return this;
}
public Hiero_html_mgr_fxt Init_hiero_cartouche() {
this.Init_phoneme("<", "Ca1");
this.Init_phoneme(">", "Ca2");
return this;
}
public Hiero_html_mgr_fxt Init_hiero_p_t() {
this.Init_phoneme("p", "Q3");
this.Init_phoneme("t", "X1");
this.Init_file("Q3", 12, 15);
this.Init_file("X1", 20, 11);
return this;
}
public Hiero_html_mgr_fxt Init_hiero_a_A1() {
this.Init_prefab("a&A1");
this.Init_file("a&A1", 37, 38);
return this;
}
public Hiero_html_mgr_fxt Init_prefab(String prefab) {xtn_mgr.Prefab_mgr().Add(Bry_.new_utf8_(prefab)); return this;}
public Hiero_html_mgr_fxt Init_file(String s, int w, int h) {xtn_mgr.File_mgr().Add(Bry_.new_utf8_(s), w, h); return this;}
public Hiero_html_mgr_fxt Init_phoneme(String phoneme, String code) {xtn_mgr.Phoneme_mgr().Add(Bry_.new_utf8_(phoneme), Bry_.new_utf8_(code)); return this;}
public void Test_html_full_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
}

View File

@ -0,0 +1,172 @@
/*
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.hieros; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.html.*; import gplx.xowa.html.*;
class Hiero_html_wtr {
private Hiero_phoneme_mgr phoneme_mgr;
private Bry_bfr temp_bfr = Bry_bfr.reset_(255);
public Hiero_html_wtr(Hiero_html_mgr mgr, Hiero_phoneme_mgr phoneme_mgr) {this.phoneme_mgr = phoneme_mgr;}
public void Init_for_write(Xoh_wtr_ctx hctx) {this.hiero_img_dir = hctx.Mode_is_hdump() ? gplx.xowa.hdumps.htmls.Hdump_html_consts.Key_hiero_dir : Hiero_xtn_mgr.Img_src_dir;} private byte[] hiero_img_dir = null;
public void Hr(Bry_bfr bfr) {bfr.Add(Html_tag_.Hr_inl).Add_byte_nl();}
public void Tbl_eol(Bry_bfr bfr) {bfr.Add(Tbl_eol_bry);}
public byte[] Td_height(int height) {
return temp_bfr.Add(Option_bgn_bry).Add_int_variable(height).Add(Option_end_bry).XtoAryAndClear();
}
private static final byte[]
Option_bgn_bry = Bry_.new_ascii_("height: ")
, Option_end_bry = Bry_.new_ascii_("px;")
;
public void Td(Bry_bfr bfr, byte[] glyph) {
bfr.Add(Td_bgn_bry).Add(glyph).Add(Td_end_bry);
}
private static final byte[]
Td_bgn_bry = Bry_.new_ascii_("\n <td>")
, Td_end_bry = Bry_.new_ascii_("\n </td>")
;
public void Cartouche_bgn(Bry_bfr bfr) {
bfr.Add(Cartouche_bgn_lhs_bry).Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100).Add(Cartouche_bgn_rhs_bry);
}
private static final String Tbl_bgn_str = "<table class=\"mw-hiero-table\">";
private static final byte[]
Cartouche_bgn_lhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " <td>"
, " " + Tbl_bgn_str
, " <tr>"
, " <td class='mw-hiero-box' style='height: "
))
, Cartouche_bgn_rhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "px;'>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td>"
, " " + Tbl_bgn_str
, " <tr>"
))
;
public void Cartouche_end(Bry_bfr bfr) {
bfr.Add(Cartouche_end_lhs_bry).Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100).Add(Cartouche_end_rhs_bry);
}
private static final byte[]
Cartouche_end_lhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " </tr>"
, " </table>"
, " </td>"
, " </tr>"
, " <tr>"
, " <td class='mw-hiero-box' style='height: "
))
, Cartouche_end_rhs_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "px;'>"
, " </td>"
, " </tr>"
, " </table>"
, " </td>"
));
public byte[] Cartouche_img(Xoh_wtr_ctx hctx, boolean bgn, byte[] glyph) { // render open / close cartouche; note that MW has two branches, but they are both the same
int height = (int)((Hiero_html_mgr.Max_height * Hiero_html_mgr.scale) / 100);
Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph); if (phoneme_itm == null) throw Err_.new_fmt_("missing phoneme: {0}", String_.new_utf8_(glyph));
byte[] code = phoneme_itm.Gardiner_code();
byte[] title = bgn ? Html_entity_.Lt_bry : Html_entity_.Gt_bry;
return cartouche_img_fmtr.Bld_bry_many(temp_bfr, hiero_img_dir, code, height, title);
}
private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_(String_.Concat
( "\n <img src='~{path}hiero_~{code}.png'"
, " height='~{height}' title='~{title}'"
, " alt='~{title}' />"
)
, "path", "code", "height", "title");
public void Tbl_inner(Bry_bfr html_bfr, Bry_bfr text_bfr) {
html_bfr.Add(Tbl_inner_bgn).Add_bfr_and_clear(text_bfr).Add(Tbl_inner_end); // $html .= self::TABLE_START . "<tr>\n" . $tableContentHtml . '</tr></table>';
}
private static final byte[]
Tbl_inner_bgn = Bry_.new_utf8_(String_.Concat_lines_nl_skip_last
( " <table class=\"mw-hiero-table\">"
, " <tr>"
))
, Tbl_inner_end = Bry_.new_utf8_(String_.Concat_lines_nl_skip_last
( ""
, " </tr>"
, " </table>"
))
;
public void Tbl_outer(Bry_bfr bfr, Bry_bfr html_bfr) {
bfr.Add(Outer_tbl_bgn);
bfr.Add_bfr_and_clear(html_bfr);
bfr.Add(Outer_tbl_end);
}
private static final byte[]
Outer_tbl_bgn = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>"
, " <tr>"
, " <td>"
, ""
)
)
, Outer_tbl_end = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " </td>"
, " </tr>"
, "</table>"
, ""
))
;
public byte[] Img_phoneme(byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) {
byte[] code_esc = Html_utl.Escape_html_as_bry(temp_bfr, code);
byte[] img_title = temp_bfr.Add(code_esc).Add_byte_space().Add_byte(Byte_ascii.Brack_bgn).Add(glyph_esc).Add_byte(Byte_ascii.Brack_end).XtoAryAndClear(); // "~{code} [~{glyph}]"
return Img(img_cls, td_height, glyph_esc, code_esc, img_title);
}
public byte[] Img_file(byte[] img_cls, byte[] td_height, byte[] glyph_esc) {return Img(img_cls, td_height, glyph_esc, glyph_esc, glyph_esc);}
private byte[] Img(byte[] img_cls, byte[] td_height, byte[] glyph, byte[] img_src_name, byte[] img_title) {
byte[] img_src = Bld_img_src(hiero_img_dir, img_src_name);
return glyph_img_fmtr.Bld_bry_many(temp_bfr, img_cls, Hiero_html_mgr.Image_margin, td_height, img_src, img_title, glyph);
}
private static final byte[]
Tbl_eol_bry = Bry_.new_ascii_(String_.Concat_lines_nl_skip_last
( ""
, " </tr>"
, " </table>"
, " " + Tbl_bgn_str
, " <tr>"
));
private static final Bry_fmtr
glyph_img_fmtr = Bry_fmtr.new_
( "\n <img ~{img_cls}style='margin: ~{img_margin}px; ~{option}' src='~{img_src}' title='~{img_title}' alt='~{glyph}' />", "img_cls", "img_margin", "option", "img_src", "img_title", "glyph")
;
public byte[] Void(boolean half) { // render void
int width = Hiero_html_mgr.Max_height;
if (half) width /= 2;
return void_fmtr.Bld_bry_many(temp_bfr, width);
}
private static final Bry_fmtr void_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <table class=\"mw-hiero-table\" style=\"width: ~{width}px;\">"
, " <tr>"
, " <td>&#160;"
, " </td>"
, " </tr>"
, " </table>"
)
, "width");
private static byte[] Bld_img_src(byte[] hiero_img_dir, byte[] name) {
return Bry_.Add(hiero_img_dir, Img_src_prefix, name, Img_src_ext);
}
private static final byte[] Img_src_prefix = Bry_.new_ascii_("hiero_"), Img_src_ext = Bry_.new_ascii_(".png");
}

View File

@ -38,7 +38,7 @@ public class Hiero_xnde implements Xox_xnde, Xop_xnde_atr_parser {
break;
}
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
xtn_mgr.Html_wtr().Render_blocks(bfr, blocks, Hiero_html_mgr.scale, false);
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
xtn_mgr.Html_wtr().Render_blocks(bfr, hctx, blocks, Hiero_html_mgr.scale, false);
}
}

View File

@ -22,14 +22,13 @@ public class Hiero_xtn_mgr extends Xox_mgr_base implements GfoInvkAble {
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_ascii_("hiero");
@Override public Xox_mgr Clone_new() {return new Hiero_xtn_mgr();}
public static byte[] Img_src_dir;
@Override public void Xtn_init_by_wiki(Xow_wiki wiki) {
}
@Override public void Xtn_init_by_wiki(Xow_wiki wiki) {}
private static boolean xtn_init_done = false;
public void Xtn_init_assert(Xow_wiki wiki) {
if (xtn_init_done) return;
if (!Enabled()) return;
Xoa_app app = wiki.App();
Io_url ext_root_dir = app.Fsys_mgr().Bin_extensions_dir().GenSubDir("Wikihiero");
Io_url ext_root_dir = Hiero_root_dir(app);
Img_src_dir = Bry_.new_utf8_(ext_root_dir.GenSubDir("img").To_http_file_str());
app.Gfs_mgr().Run_url_for(this, ext_root_dir.GenSubFil_nest("data", "tables.gfs"));
html_wtr = new Hiero_html_mgr(this);
@ -53,4 +52,5 @@ public class Hiero_xtn_mgr extends Xox_mgr_base implements GfoInvkAble {
else return super.Invk(ctx, ikey, k, m);
}
public static final String Invk_prefabs = "prefabs", Invk_files = "files", Invk_phonemes = "phonemes";
public static Io_url Hiero_root_dir(Xoa_app app) {return app.Fsys_mgr().Bin_extensions_dir().GenSubDir("Wikihiero");}
}

View File

@ -34,22 +34,22 @@ class Imap_html_fmtrs {
), "href", "shape", "coords", "title")
, Img_anchor_none = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
), "imap_id", "img_elem_id", "img_alt", "img_src", "img_w", "img_h", "img_cls", "anchor_href", "anchor_title"
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\"~{img_core}~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
), "imap_id", "img_elem_id", "img_alt", "img_core", "img_cls", "anchor_href", "anchor_title"
)
, Img_anchor_lnki = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <a href=\"~{anchor_href}\" title=\"~{anchor_title}\">"
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\"~{img_core}~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
, " </a>"
), "imap_id", "img_elem_id", "img_alt", "img_src", "img_w", "img_h", "img_cls", "anchor_href", "anchor_title"
), "imap_id", "img_elem_id", "img_alt", "img_core", "img_cls", "anchor_href", "anchor_title"
)
, Img_anchor_lnke = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <a href=\"~{anchor_href}\" title=~{anchor_title} class=\"plainlinks\" rel=\"nofollow\">"
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
, " <img id=\"xowa_file_img_~{img_elem_id}\" alt=\"~{img_alt}\"~{img_core}~{img_cls} usemap=\"#imageMap_1_~{imap_id}\"/>"
, " </a>"
), "imap_id", "img_elem_id", "img_alt", "img_src", "img_w", "img_h", "img_cls", "anchor_href", "anchor_title"
), "imap_id", "img_elem_id", "img_alt", "img_core", "img_cls", "anchor_href", "anchor_title"
)
, Desc_style = Bry_fmtr.new_(" style=\"height:~{div_h}px; width: ~{div_w}px;\"", "div_w", "div_h")
, Desc_main = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last

View File

@ -16,13 +16,14 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
class Imap_img_fmtr_arg implements Bry_fmtr_arg {
private Imap_map map;
private Xoh_wtr_ctx hctx; private Imap_map map; private Imap_xtn_mgr xtn_mgr;
private int img_elem_id, img_w, img_h;
private byte[] img_alt, img_src, img_cls, img_href;
private Int_2_ref margin_calc = new Int_2_ref();
public void Init(Imap_map map, int img_elem_id, byte[] img_alt, byte[] img_src, int img_w, int img_h, byte[] img_cls, byte[] img_href) {
this.map = map;
public void Init(Xoa_page page, Xoh_wtr_ctx hctx, Imap_xtn_mgr xtn_mgr, Imap_map map, int img_elem_id, byte[] img_alt, byte[] img_src, int img_w, int img_h, byte[] img_cls, byte[] img_href, byte[] lnki_ttl) {
this.hctx = hctx; this.map = map; this.xtn_mgr = xtn_mgr;
this.img_elem_id = img_elem_id; this.img_w = img_w; this.img_h = img_h;
this.img_alt = img_alt;
this.img_src = img_src;
@ -33,16 +34,18 @@ class Imap_img_fmtr_arg implements Bry_fmtr_arg {
Bry_fmtr fmtr = Imap_html_fmtrs.Img_anchor_none;
byte[] anchor_href = Bry_.Empty, anchor_text = Bry_.Empty;
Imap_itm_dflt itm_dflt = map.Dflt();
boolean hctx_is_hdump = hctx.Mode_is_hdump();
Xoh_arg_img_core img_core_fmtr = xtn_mgr.Img_core_fmtr(hctx_is_hdump);
img_core_fmtr.Init(img_elem_id, img_src, img_w, img_h);
if (itm_dflt != null) {
fmtr = itm_dflt.Link_tid() == Xop_tkn_itm_.Tid_lnki ? Imap_html_fmtrs.Img_anchor_lnki : Imap_html_fmtrs.Img_anchor_lnke;
anchor_href = itm_dflt.Link_href();
anchor_text = itm_dflt.Link_text();
}
fmtr.Bld_bfr_many(bfr, map.Id(), img_elem_id, img_alt, img_src, img_w, img_h, img_cls, anchor_href, anchor_text);
fmtr.Bld_bfr_many(bfr, map.Id(), img_elem_id, img_alt, img_core_fmtr, img_cls, anchor_href, anchor_text);
Imap_itm_desc itm_desc = map.Desc();
if (itm_desc != null) {
Imap_desc_tid.Calc_desc_margins(margin_calc, itm_desc.Desc_tid(), img_w, img_h);
Imap_xtn_mgr xtn_mgr = map.Xtn_mgr();
Imap_html_fmtrs.Desc_main.Bld_bfr_many(bfr, margin_calc.Val_0(), margin_calc.Val_1(), img_href, xtn_mgr.Desc_msg(), xtn_mgr.Desc_icon_url());
}
}

View File

@ -33,22 +33,22 @@ public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
@gplx.Internal protected Imap_itm_shape[] Shapes() {return shapes;} private Imap_itm_shape[] shapes;
@gplx.Internal protected Imap_err[] Errs() {return errs;} private Imap_err[] errs;
private byte[] a_href, img_alt, img_cls;
public void Html_full_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_cls) {
public void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_cls) {
xfer_itm.Html_img_wkr_(this);
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_imap);
this.a_href = a_href; this.img_alt = img_alt; this.img_cls = img_cls;
Write_imap_div(tmp_bfr, uid, img_w, img_h, img_src, xfer_itm.Orig_w(), xfer_itm.Orig_h());
Write_imap_div(tmp_bfr, page, hctx, uid, img_w, img_h, img_src, xfer_itm.Orig_w(), xfer_itm.Orig_h(), xfer_itm.Lnki_ttl());
}
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src) {
public void Html_update(Xoa_page page, Xog_html_itm html_itm, int html_uid, int html_w, int html_h, String html_src, int orig_w, int orig_h, String orig_src, byte[] lnki_ttl) {
Xow_wiki wiki = xtn_mgr.Wiki();
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004();
Write_imap_div(tmp_bfr, html_uid, html_w, html_h, Bry_.new_utf8_(html_src), orig_w, orig_h);
Write_imap_div(tmp_bfr, page, Xoh_wtr_ctx.Basic, html_uid, html_w, html_h, Bry_.new_utf8_(html_src), orig_w, orig_h, lnki_ttl);
html_itm.Html_elem_replace_html("imap_div_" + Int_.XtoStr(html_uid), tmp_bfr.Mkr_rls().XtoStrAndClear());
}
private void Write_imap_div(Bry_bfr bfr, int html_uid, int html_w, int html_h, byte[] html_src, int orig_w, int orig_h) {
private void Write_imap_div(Bry_bfr bfr, Xoa_page page, Xoh_wtr_ctx hctx, int html_uid, int html_w, int html_h, byte[] html_src, int orig_w, int orig_h, byte[] lnki_ttl) {
byte[] desc_style = Calc_desc_style(html_w, html_h);
map_fmtr_arg.Init(id, shapes, Calc_scale(orig_w, orig_h, html_w, html_h));
img_fmtr_arg.Init(this, html_uid, img_alt, html_src, html_w, html_h, img_cls, a_href);
img_fmtr_arg.Init(page, hctx, xtn_mgr, this, html_uid, img_alt, html_src, html_w, html_h, img_cls, a_href, lnki_ttl);
Imap_html_fmtrs.All.Bld_bfr_many(bfr, html_uid, desc_style, map_fmtr_arg, img_fmtr_arg);
}
private byte[] Calc_desc_style(int html_w, int html_h) {

View File

@ -31,8 +31,8 @@ public class Imap_xnde implements Xox_xnde {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_imageMap, src, xnde);
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
if (imap_data.Invalid()) return;
html_wtr.Write_tkn(bfr, ctx, opts, imap_data.Img_src(), xnde, Xoh_html_wtr.Sub_idx_null, imap_data.Img().Img_link());
html_wtr.Write_tkn(bfr, ctx, hctx, imap_data.Img_src(), xnde, Xoh_html_wtr.Sub_idx_null, imap_data.Img().Img_link());
}
}

View File

@ -16,8 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.*;
import gplx.core.btries.*;
import gplx.core.btries.*; import gplx.xowa.wikis.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
public class Imap_xtn_mgr extends Xox_mgr_base implements GfoInvkAble {
private boolean init;
@Override public boolean Enabled_default() {return true;}
@ -33,6 +32,8 @@ public class Imap_xtn_mgr extends Xox_mgr_base implements GfoInvkAble {
public Btrie_slim_mgr Desc_trie() {return desc_trie;} private Btrie_slim_mgr desc_trie;
public byte[] Desc_msg() {return desc_msg;} private byte[] desc_msg;
public byte[] Desc_icon_url() {return desc_icon_url;} private byte[] desc_icon_url;
public Xoh_arg_img_core Img_core_fmtr(boolean hctx_is_hdump) {return hctx_is_hdump ? img_core_hdump : img_core_basic;}
private final Xoh_arg_img_core img_core_basic = new Xoh_arg_img_core__basic(), img_core_hdump = new Xoh_arg_img_core__hdump();
@Override public Xox_mgr Clone_new() {return new Imap_xtn_mgr();}
@Override public void Xtn_init_by_wiki(Xow_wiki wiki) {
this.wiki = wiki;

View File

@ -19,5 +19,5 @@ package gplx.xowa.xtns.inputBox; import gplx.*; import gplx.xowa.*; import gplx.
import gplx.xowa.html.*;
public class Xtn_inputbox_nde implements Xox_xnde {
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {} // FUTURE: noop for now so it doesn't show (since it's useless)
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {}
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
}

View File

@ -75,7 +75,7 @@ public class Listing_xnde implements Xox_xnde, Xop_xnde_atr_parser {
html_output = hwtr.Xto_bry_and_clear();
}
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
if (xtn_mgr == null || !xtn_mgr.Enabled())
Xox_mgr_base.Xtn_write_escape(app, bfr, src, xnde);
else

View File

@ -36,7 +36,7 @@ public class Lst_section_nde implements Xox_xnde, Xop_xnde_atr_parser {
xnde.Atrs_ary_(atrs);
ctx.Lst_section_mgr().Add(this);
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {} // NOTE: write nothing; <section> is just a bookmark
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {} // NOTE: write nothing; <section> is just a bookmark
public static final byte Xatr_name = 0, Xatr_bgn = 1, Xatr_end = 2;
public static Hash_adp_bry new_xatrs_(Xol_lang lang) {
Hash_adp_bry rv = Hash_adp_bry.ci_utf8_(lang.Case_mgr()); // UTF8:see xatrs below

View File

@ -25,7 +25,7 @@ public class Math_nde implements Xox_xnde, Xop_xnde_atr_parser {
if (math_mgr.Enabled() && math_mgr.Renderer_is_mathjax())
ctx.Cur_page().Html_data().Module_mgr().Itm_mathjax().Enabled_y_();
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
app.File_mgr().Math_mgr().Html_wtr().Write(html_wtr, ctx, hctx, bfr, src, xnde);
}
}

View File

@ -16,16 +16,17 @@ 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.pfuncs.strings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.intl.*;
public class Pfunc_pad extends Pf_func_base {
@Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {// REF.MW: CoreParserFunctions.php|pad
int self_args_len = self.Args_len();
byte[] val = Eval_argx(ctx, src, caller, self);
int val_len = val.length;
int val_len = Utf8_.Len_of_bry(val); // NOTE: length must be in chars, not bytes, else won't work for non-ASCII chars; EX:niǎo has length of 4, not 5; PAGE:zh.d: DATE:2014-08-27
byte[] pad_len = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 0);
int pad_len_int = Bry_.Xto_int_or(pad_len, 0, pad_len.length, -1);
if (pad_len_int == -1) {bfr.Add(val); return;}// NOTE: if pad_len is non-int, add val and exit silently; EX: {{padleft: a|bad|0}}
if (pad_len_int > 500) pad_len_int = 500; // MW: force to be <= 500
if (pad_len_int == -1) {bfr.Add(val); return;} // NOTE: if pad_len is non-int, add val and exit silently; EX: {{padleft: a|bad|0}}
if (pad_len_int > 500) pad_len_int = 500; // MW: force it to be <= 500
byte[] pad_str = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, Ary_pad_dflt);
int pad_str_len = pad_str.length;

View File

@ -25,6 +25,7 @@ public class Pfunc_pad_tst {
@Test public void L_len_neg1() {fxt.Test_parse_tmpl_str_test("{{padleft: a|-1|01}}" , "{{test}}" , "a");}
@Test public void L_val_null() {fxt.Test_parse_tmpl_str_test("{{padleft: |4|0}}" , "{{test}}" , "0000");}
@Test public void L_word_3() {fxt.Test_parse_tmpl_str_test("{{padleft: abc|4}}" , "{{test}}" , "0abc");}
@Test public void L_word_3_utf8() {fxt.Test_parse_tmpl_str_test("{{padleft: niǎo|5}}" , "{{test}}" , "0niǎo");} // PURPOSE:use length of String in chars, not bytes; PAGE:zh.d: DATE:2014-08-27
@Test public void L_exc_len_bad1() {fxt.Test_parse_tmpl_str_test("{{padleft:a|bad|01}}" , "{{test}}" , "a");}
@Test public void L_exc_pad_ws() {fxt.Test_parse_tmpl_str_test("{{padleft:a|4|\n \t}}" , "{{test}}" , "a");}
@Test public void R_len_3() {fxt.Test_parse_tmpl_str_test("{{padright:a|4|0}}" , "{{test}}" , "a000");}

View File

@ -80,7 +80,10 @@ public class Pft_func_time_basic_tst {
fxt.Test_parse_tmpl_str_test("{{#time:Z|}}" , "{{test}}" , "-18000");
DateAdp.Timezone_offset_test = Int_.MinValue;
} // Z=timezone offset in seconds; http://php.net/manual/en/function.date.php;
@Test public void Rfc5322() {fxt.Test_parse_tmpl_str_test("{{#time:r|}}" , "{{test}}" , "Mon, 02 Jan 2012 08:04:05 +0000");}
@Test public void Timezone_plus() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i:s|2012-01-02 03:04:05+06:30}}" , "{{test}}" , "2012-01-02 09:34:05");} // PURPOSE: handle timezone plus ; EX: +01:30; DATE:2014-08-26
@Test public void Timezone_minus() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i:s|2012-01-02 09:34:05-06:30}}" , "{{test}}" , "2012-01-02 03:04:05");} // PURPOSE: handle timezone minus; EX: -01:30; DATE:2014-08-26
@Test public void Timezone_wrap() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i:s|2012-01-31 22:30:05+01:30}}" , "{{test}}" , "2012-02-01 00:00:05");} // PURPOSE: handle timezone wrap ; DATE:2014-08-26
@Test public void Rfc5322() {fxt.Test_parse_tmpl_str_test("{{#time:r|}}" , "{{test}}" , "Mon, 02 Jan 2012 08:04:05 +0000");}
@Test public void Lang() {
Xol_lang fr_lang = fxt.App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_("fr"));
Xol_msg_itm msg_itm = fr_lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_ascii_("January"));

View File

@ -48,6 +48,13 @@ class Pxd_itm_ {
, Tid_ws = 98
, Tid_sym = 99
;
public static Pxd_itm Find_bwd__non_ws(Pxd_itm[] tkns, int bgn) {
for (int i = bgn - 1; i > -1; --i) {
Pxd_itm itm = tkns[i];
if (itm.Tkn_tid() != Tid_ws) return itm;
}
return null;
}
public static Pxd_itm Find_fwd_by_tid(Pxd_itm[] tkns, int bgn, int tid) {
int len = tkns.length;
for (int i = bgn; i < len; i++) {
@ -109,5 +116,6 @@ class Pft_func_time_log {
, Invalid_minute = Gfo_msg_itm_.new_warn_(owner, "Invalid minute: ~{0}")
, Invalid_second = Gfo_msg_itm_.new_warn_(owner, "Invalid second: ~{0}")
, Invalid_date = Gfo_msg_itm_.new_warn_(owner, "Invalid date: ~{0}")
, Invalid_timezone = Gfo_msg_itm_.new_warn_(owner, "Invalid timezone: ~{0}")
;
}

View File

@ -39,11 +39,24 @@ class Pxd_itm_int extends Pxd_itm_base implements Pxd_itm_int_interface {
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_int;}
@Override public int Eval_idx() {return eval_idx;} private int eval_idx = 99;
public int Val() {return val;} public Pxd_itm_int Val_(int v) {val = v; return this;} private int val;
public boolean Val_is_adj() {return val_is_adj;} public void Val_is_adj_(boolean v) {val_is_adj = v;} private boolean val_is_adj;
public int Xto_int_or(int or) {return val;}
public int Digits() {return digits;} private int digits;
@Override public void Time_ini(DateAdpBldr bldr) {
if (this.Seg_idx() == Pxd_itm_base.Seg_idx_skip) return;
bldr.Seg_set(this.Seg_idx(), val);
int seg_idx = this.Seg_idx();
if (seg_idx == Pxd_itm_base.Seg_idx_skip) return;
if (val_is_adj) {
if (val == 0) return; // no adjustment to make
DateAdp date = bldr.Date();
switch (seg_idx) {
case DateAdp_.SegIdx_hour: date = date.Add_hour(val); break;
case DateAdp_.SegIdx_minute: date = date.Add_minute(val); break;
default: return;
}
bldr.Date_(date);
}
else
bldr.Seg_set(seg_idx, val);
}
private static final int Month_max = 12;
@Override public void Eval(Pxd_parser state) {
@ -110,13 +123,13 @@ class Pxd_itm_int extends Pxd_itm_base implements Pxd_itm_int_interface {
}
private void Eval_unknown_at_pos_3(Pxd_parser state) { // int at pos 4
if ( state.Seg_idxs_chk(DateAdp_.SegIdx_year, DateAdp_.SegIdx_month, DateAdp_.SegIdx_day) // check that ymd is set
&& Match_sym(state, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-"
&& Match_sym(state, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-"
Pxd_itm_int_.Hour_err(state, this); // mark as hour; handles strange fmts like November 2, 1991-06; DATE:2013-06-19
}
private void Eval_unknown_at_pos_4(Pxd_parser state) {
if ( state.Seg_idxs_chk(DateAdp_.SegIdx_year
, DateAdp_.SegIdx_month, DateAdp_.SegIdx_day, DateAdp_.SegIdx_hour) // check that ymdh is set
&& Match_sym(state, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-"
&& Match_sym(state, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-"
state.Seg_idxs_(this, Pxd_itm_base.Seg_idx_skip); // mark as ignore; handles strange fmts like November 2, 1991-06-19; DATE:2013-06-19
}
boolean Match_sym(Pxd_parser state, boolean fwd, int sym_tid) {
@ -356,7 +369,7 @@ class Pxd_itm_int_ {
case 1:
case 2:
if (val > -1 && val < 25) {
state.Seg_idxs_(itm, DateAdp_.SegIdx_hour);
state.Seg_idxs_(itm, DateAdp_.SegIdx_hour, val);
return false;
}
break;
@ -370,7 +383,7 @@ class Pxd_itm_int_ {
case 1:
case 2:
if (val > -1 && val < 60) {
state.Seg_idxs_(itm, DateAdp_.SegIdx_minute);
state.Seg_idxs_(itm, DateAdp_.SegIdx_minute, val);
return false;
}
break;
@ -392,4 +405,49 @@ class Pxd_itm_int_ {
state.Err_set(Pft_func_time_log.Invalid_second, Bry_fmtr_arg_.int_(val));
return true;
}
public static byte Tz_sym_err(Pxd_parser state, Pxd_itm[] tkns, Pxd_itm_int hour_itm) {
Pxd_itm sym = Pxd_itm_.Find_bwd__non_ws(tkns, hour_itm.Ary_idx());
switch (sym.Tkn_tid()) {
case Pxd_itm_.Tid_sym:
Pxd_itm_sym sym_itm = (Pxd_itm_sym)sym;
if (sym_itm.Sym_byte() == Byte_ascii.Plus)
return Bool_.Y_byte;
break;
case Pxd_itm_.Tid_dash: return Bool_.N_byte;
}
state.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null"));
return Bool_.__byte;
}
public static boolean Tz_hour_err(Pxd_parser state, Pxd_itm_int itm, boolean negative) {
if (negative) itm.Val_(itm.Val() * -1);
int val = itm.Val();
switch (itm.Digits()) {
case 1:
case 2:
if (val > -12 && val < 12) {
itm.Val_is_adj_(Bool_.Y);
itm.Seg_idx_(DateAdp_.SegIdx_hour);
return false;
}
break;
}
state.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.int_(val));
return true;
}
public static boolean Tz_min_err(Pxd_parser state, Pxd_itm_int itm, boolean negative) {
int val = itm.Val();
if (negative) val *= -1;
switch (itm.Digits()) {
case 1:
case 2:
if (val > -60 && val < 60) {
itm.Val_is_adj_(Bool_.Y);
itm.Seg_idx_(DateAdp_.SegIdx_minute);
return false;
}
break;
}
state.Err_set(Pft_func_time_log.Invalid_minute, Bry_fmtr_arg_.int_(val));
return true;
}
}

View File

@ -20,23 +20,33 @@ class Pxd_itm_colon extends Pxd_itm_base {
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_colon;}
@Override public int Eval_idx() {return 20;}
@Override public void Eval(Pxd_parser state) {
state.Colon_count++;
int colon_count = state.Colon_count;
int colon_count = ++state.Colon_count;
Pxd_itm[] tkns = state.Tkns();
Pxd_itm_int itm_int = null;
switch (colon_count) {
case 1:
itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), false);
case 1: // hh:mm
itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), Bool_.N);
if (itm_int == null) {state.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.bry_("null")); return;}
if (Pxd_itm_int_.Hour_err(state, itm_int)) return;
itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), true);
if (Pxd_itm_int_.Min_err(state, itm_int)) return;
break;
case 2:
state.Colon_count++;
case 2: // :ss
itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), true);
if (Pxd_itm_int_.Sec_err(state, itm_int)) return;
break;
case 3: // +hh:mm; DATE:2014-08-26
itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), Bool_.N);
if (itm_int == null) {state.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null")); return;}
byte tz_positive_val = Pxd_itm_int_.Tz_sym_err(state, tkns, itm_int);
if (tz_positive_val == Bool_.__byte) return;
boolean tz_negative = tz_positive_val == Bool_.N_byte;
if (Pxd_itm_int_.Tz_hour_err(state, itm_int, tz_negative)) return;
itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), Bool_.Y);
if (itm_int == null) {state.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null")); return;}
if (tz_negative) itm_int.Val_(itm_int.Val() * -1);
if (Pxd_itm_int_.Tz_min_err(state, itm_int, tz_negative)) return;
break;
}
}
public Pxd_itm_colon(int ary_idx) {this.Ctor(ary_idx);}
@ -70,7 +80,8 @@ class Pxd_itm_sym extends Pxd_itm_base {
@Override public byte Tkn_tid() {return Pxd_itm_.Tid_sym;}
@Override public int Eval_idx() {return 99;}
@Override public void Time_ini(DateAdpBldr bldr) {}
public Pxd_itm_sym(int ary_idx, int val) {this.Ctor(ary_idx);}
public byte Sym_byte() {return sym_byte;} private byte sym_byte;
public Pxd_itm_sym(int ary_idx, byte val) {this.Ctor(ary_idx); this.sym_byte = val;}
}
class Pxd_itm_int_dmy_14 extends Pxd_itm_base implements Pxd_itm_int_interface {
public Pxd_itm_int_dmy_14(int ary_idx, byte[] src, int digits) {this.Ctor(ary_idx); this.src = src; this.digits = digits;} private byte[] src; int digits;

View File

@ -352,8 +352,7 @@ class Pxd_itm_iso8601_t extends Pxd_itm_base implements Pxd_itm_prototype {
if (hour != null && hour.Seg_idx() == DateAdp_.SegIdx_hour) return; // next item is hour
state.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.bry_("T"));
}
@Override public void Time_ini(DateAdpBldr bldr) {
}
@Override public void Time_ini(DateAdpBldr bldr) {}
private static Pxd_itm Next_non_ws_tkn(Pxd_itm[] tkns, int bgn) {
int len = tkns.length;
for (int i = bgn; i < len; i++) {

View File

@ -31,10 +31,10 @@ class Pxd_parser {
if (ary[i] == Pxd_itm_base.Seg_idx_null) return false;
return true;
}
public void Seg_idxs_(Pxd_itm_int itm, int seg_idx) {Seg_idxs_(itm, seg_idx, itm.Val());}
public void Seg_idxs_(Pxd_itm_int itm, int seg_idx) {Seg_idxs_(itm, seg_idx, itm.Val());}
public void Seg_idxs_(Pxd_itm_base itm, int seg_idx, int val) {
itm.Seg_idx_(seg_idx);
if (seg_idx >= 0) // ignore Seg_idx_null and Seg_idx_skip
if (seg_idx >= 0) // ignore Seg_idx_null and Seg_idx_skip
seg_idxs[seg_idx] = val;
}
public void Err_set(Gfo_msg_itm itm, Bry_fmtr_arg... args) {
@ -111,9 +111,9 @@ class Pxd_parser {
itm = new Pxd_itm_int(tkns_len, digits, int_val); break;
}
break;
case Pxd_itm_.Tid_ws: itm = new Pxd_itm_ws(tkns_len); break;
case Pxd_itm_.Tid_dash: itm = new Pxd_itm_dash(tkns_len); break;
case Pxd_itm_.Tid_dot: itm = new Pxd_itm_dot(tkns_len); break;
case Pxd_itm_.Tid_ws: itm = new Pxd_itm_ws(tkns_len); break;
case Pxd_itm_.Tid_dash: itm = new Pxd_itm_dash(tkns_len); break;
case Pxd_itm_.Tid_dot: itm = new Pxd_itm_dot(tkns_len); break;
case Pxd_itm_.Tid_colon: itm = new Pxd_itm_colon(tkns_len); break;
case Pxd_itm_.Tid_slash: itm = new Pxd_itm_slash(tkns_len); break;
case Pxd_itm_.Tid_null: break; // NOOP

View File

@ -29,10 +29,10 @@ public class Poem_nde implements Xox_xnde {
Poem_xtn_mgr xtn_mgr = (Poem_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Poem_xtn_mgr.XTN_KEY);
xtn_root = xtn_mgr.Parser().Parse_text_to_wdom_old_ctx(ctx, Bry_.Mid(src, itm_bgn, itm_end), true); // NOTE: ignoring paragraph mode; technically MW enables para mode, but by replacing "\n" with "<br/>\n" all the logic with para/pre mode is skipped
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
if (xtn_root == null) return; // inline poem; write nothing; EX: <poem/>
bfr.Add(Bry_poem_bgn);
html_wtr.Write_tkn(bfr, ctx, opts, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
html_wtr.Write_tkn(bfr, ctx, hctx, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
bfr.Add(Bry_poem_end);
}
private static byte[]

View File

@ -23,5 +23,5 @@ public class Pp_pagelist_nde implements Xox_xnde, Xop_xnde_atr_parser { // TODO:
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Cur_page(), Xop_log_basic_wkr.Tid_hiero, src, xnde);
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {}
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
}

View File

@ -19,5 +19,5 @@ package gplx.xowa.xtns.proofreadPage; import gplx.*; import gplx.xowa.*; import
import gplx.xowa.html.*;
public class Pp_pagequality_nde implements Xox_xnde {
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {} // FUTURE: noop for now so it doesn't show (since it's useless)
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {}
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {}
}

View File

@ -64,12 +64,12 @@ public class Pp_pages_nde implements Xox_xnde, Xop_xnde_atr_parser {
page.Pages_recursed_(false);
full_bfr.Mkr_rls();
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
if (xtn_literal)
Xox_mgr_base.Xtn_write_escape(app, bfr, src, xnde);
else {
if (xtn_root == null) return; // xtn_root is null when Xtn_parse exits early; occurs for recursion; DATE:2014-05-21
html_wtr.Write_tkn(bfr, ctx, opts, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
html_wtr.Write_tkn(bfr, ctx, hctx, xtn_root.Root_src(), xnde, Xoh_html_wtr.Sub_idx_null, xtn_root);
}
}
private boolean Init_vars(Xow_wiki wiki, Xop_ctx ctx, byte[] src, Xop_xnde_tkn xnde) {

View File

@ -20,7 +20,7 @@ import gplx.xowa.html.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.logs.*;
public class Quiz_xnde implements Xox_xnde {
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xox_mgr_base.Xtn_write_unsupported(app, ctx, bfr, src, xnde, Xox_mgr_base.Parse_content_tid_none);
}
}

View File

@ -20,7 +20,7 @@ import gplx.xowa.html.*;
import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.logs.*;
public class Rss_xnde implements Xox_xnde {
public void Xtn_parse(Xow_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xox_mgr_base.Xtn_write_unsupported(app, ctx, bfr, src, xnde, Xox_mgr_base.Parse_content_tid_html);
}
}

View File

@ -54,7 +54,7 @@ public class Score_xnde implements Xox_xnde, Xop_xnde_atr_parser, Xoh_cmd_itm {
Xox_mgr_base.Xtn_write_escape(app, bfr, code);
bfr.Add(Xoh_consts.Pre_end);
}
public void Xtn_write(Xoa_app app, Xoh_html_wtr html_wtr, Xoh_wtr_ctx opts, Xop_ctx ctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
public void Xtn_write(Bry_bfr bfr, Xoa_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xow_wiki wiki = ctx.Wiki(); Xoa_page page = ctx.Cur_page();
Score_xtn_mgr score_xtn = (Score_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Score_xtn_mgr.XTN_KEY);
if (!score_xtn.Enabled()) {Html_write_code_as_pre(bfr, app); return;}

View File

@ -16,8 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.scribunto.lib; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.texts.*;
import gplx.texts.*; import gplx.intl.*;
public class Scrib_lib_ustring implements Scrib_lib {
private final String_surrogate_utl surrogate_utl = new String_surrogate_utl();
public Scrib_lib_ustring(Scrib_core core) {this.core = core; gsub_mgr = new Scrib_lib_ustring_gsub_mgr(core, regx_converter);} private Scrib_core core; Scrib_lib_ustring_gsub_mgr gsub_mgr;
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
public int String_len_max() {return string_len_max;} public Scrib_lib_ustring String_len_max_(int v) {string_len_max = v; return this;} private int string_len_max = Xoa_page_.Page_len_max;
@ -47,37 +48,44 @@ public class Scrib_lib_ustring implements Scrib_lib {
public static final String Invk_find = "find", Invk_match = "match", Invk_gmatch_init = "gmatch_init", Invk_gmatch_callback = "gmatch_callback", Invk_gsub = "gsub";
private static final String[] Proc_names = String_.Ary(Invk_find, Invk_match, Invk_gmatch_init, Invk_gmatch_callback, Invk_gsub);
public boolean Find(Scrib_proc_args args, Scrib_proc_rslt rslt) {
String text = args.Pull_str(0);
String regx = args.Pull_str(1);
int bgn = args.Cast_int_or(2, 1);
boolean plain = args.Cast_bool_or_n(3);
bgn = Bgn_adjust(text, bgn);
if (String_.Len_eq_0(regx)) // regx of "" should return (bgn, bgn - 1) regardless of plain = t / f
return rslt.Init_many_objs(bgn + Scrib_lib_ustring.Base1, bgn + Scrib_lib_ustring.Base1 - 1);
if (plain) {
int pos = String_.FindFwd(text, regx, bgn);
boolean found = pos != Bry_.NotFound;
return found
? rslt.Init_many_objs(pos + Scrib_lib_ustring.Base1, pos + Scrib_lib_ustring.Base1 + String_.Len(regx) - Scrib_lib_ustring.End_adj)
: rslt.Init_ary_empty()
;
String text_str = args.Pull_str(0);
String regx = args.Pull_str(1);
int bgn_char_idx = args.Cast_int_or(2, 1);
boolean plain = args.Cast_bool_or_n(3);
synchronized (surrogate_utl) {
byte[] text_bry = Bry_.new_utf8_(text_str); int text_bry_len = text_bry.length;
bgn_char_idx = Bgn_adjust(text_str, bgn_char_idx);
int bgn_adj = surrogate_utl.Count_surrogates__char_idx(text_bry, text_bry_len, 0, bgn_char_idx); // NOTE: convert from lua / php charidx to java regex codepoint; PAGE:zh.w:南北鐵路 (越南) DATE:2014-08-27
int bgn_codepoint_idx = bgn_char_idx + bgn_adj;
int bgn_byte_pos = surrogate_utl.Byte_pos();
if (String_.Len_eq_0(regx)) // regx of "" should return (bgn, bgn - 1) regardless of whether plain is true or false
return rslt.Init_many_objs(bgn_codepoint_idx + Scrib_lib_ustring.Base1, bgn_codepoint_idx + Scrib_lib_ustring.Base1 - 1);
if (plain) {
int pos = String_.FindFwd(text_str, regx, bgn_codepoint_idx);
boolean found = pos != Bry_.NotFound;
return found
? rslt.Init_many_objs(pos + Scrib_lib_ustring.Base1, pos + Scrib_lib_ustring.Base1 + String_.Len(regx) - Scrib_lib_ustring.End_adj)
: rslt.Init_ary_empty()
;
}
regx = regx_converter.Parse(Bry_.new_utf8_(regx), Scrib_regx_converter.Anchor_G);
RegxAdp regx_adp = Scrib_lib_ustring.RegxAdp_new_(core.Ctx(), regx);
RegxMatch[] regx_rslts = regx_adp.Match_all(text_str, bgn_codepoint_idx); // NOTE: MW calculates an offset to handle mb strings. however, java's regex always takes offset in chars (not bytes like PHP preg_match); DATE:2014-03-04
int len = regx_rslts.length;
if (len == 0) return rslt.Init_ary_empty();
ListAdp tmp_list = ListAdp_.new_();
RegxMatch match = regx_rslts[0]; // NOTE: take only 1st result; DATE:2014-08-27
int match_find_bgn_codepoint = match.Find_bgn(); // NOTE: java regex returns results in codepoint; PAGE:zh.w:南北鐵路 (越南) DATE:2014-08-27
int match_find_bgn_adj = -surrogate_utl.Count_surrogates__codepoint_idx1(text_bry, text_bry_len, bgn_byte_pos, match_find_bgn_codepoint - bgn_codepoint_idx); // NOTE: convert from java regex codepoint to lua / php char_idx; PAGE:zh.w:南北鐵路 (越南) DATE:2014-08-27
tmp_list.Add(match_find_bgn_codepoint + match_find_bgn_adj + -bgn_adj + Scrib_lib_ustring.Base1);
tmp_list.Add(match.Find_end() + match_find_bgn_adj + -bgn_adj + Scrib_lib_ustring.Base1 - Scrib_lib_ustring.End_adj);
//Tfds.Write(match_find_bgn_codepoint + match_find_bgn_adj + -bgn_adj + Scrib_lib_ustring.Base1
// ,match.Find_end() + match_find_bgn_adj + -bgn_adj + Scrib_lib_ustring.Base1 - Scrib_lib_ustring.End_adj);
AddCapturesFromMatch(tmp_list, match, text_str, regx_converter.Capt_ary(), false);
return rslt.Init_many_list(tmp_list);
}
regx = regx_converter.Parse(Bry_.new_utf8_(regx), Scrib_regx_converter.Anchor_G);
RegxAdp regx_adp = Scrib_lib_ustring.RegxAdp_new_(core.Ctx(), regx);
RegxMatch[] regx_rslts = regx_adp.Match_all(text, bgn); // NOTE: MW calculates an offset to handle mb strings. however, java's regex always takes offset in chars (not bytes like PHP preg_match); DATE:2014-03-04
int len = regx_rslts.length;
if (len == 0) return rslt.Init_ary_empty();
ListAdp tmp_list = ListAdp_.new_();
for (int i = 0; i < len; i++) {
RegxMatch match = regx_rslts[i];
tmp_list.Add(match.Find_bgn() + Scrib_lib_ustring.Base1);
tmp_list.Add(match.Find_end() + Scrib_lib_ustring.Base1 - Scrib_lib_ustring.End_adj);
AddCapturesFromMatch(tmp_list, match, text, regx_converter.Capt_ary(), false);
}
return rslt.Init_many_list(tmp_list);
}
private int Bgn_adjust(String text, int bgn) { // adjust to handle bgn < 0 or bgn > len (which PHP allows)
// if (bgn == 0) return 0;
if (bgn > 0) bgn -= Scrib_lib_ustring.Base1;
int text_len = String_.Len(text);
if (bgn < 0) // negative number means search from rear of String
@ -149,7 +157,8 @@ public class Scrib_lib_ustring implements Scrib_lib {
}
return rv;
}
static final int Base1 = 1, End_adj = 1;
private static final int Base1 = 1
, End_adj = 1; // lua / php uses "end" as <= not <; EX: "abc" and bgn=0, end= 1; for XOWA, this is "a"; for MW / PHP it is "ab"
}
class Scrib_lib_ustring_gsub_mgr {
private Scrib_regx_converter regx_converter;

View File

@ -33,6 +33,10 @@ public class Scrib_lib_ustring__lib_tst {
Exec_find("abcd" , "" , 2, Bool_.N, "2;1"); // empty regx should return values; regx; EX:w:Fool's_mate; DATE:2014-03-04
Exec_find("abcd" , "^(c)" , 3, Bool_.N, "3;3;c"); // ^ should be converted to \G; regx; EX:cs.n:Category:1._září_2008; DATE:2014-05-07
}
@Test public void Find_surrogate() { // PURPOSE: handle surrogates in Find PAGE:zh.w:南北鐵路_(越南); DATE:2014-08-28
Exec_find("aé𡼾\nbî𡼾\n" , "\n" , 1, Bool_.N, "4;4"); // 4 b/c \n starts at pos 4 (super 1)
Exec_find("aé𡼾\nbî𡼾\n" , "\n" , 5, Bool_.N, "8;8"); // 8 b/c \n starts at pos 8 (super 1)
}
@Test public void Match() {
Exec_match("abcd" , "bc" , 1, "bc"); // basic
Exec_match("abcd" , "x" , 1, String_.Null_mark); // empty

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