mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
30
400_xowa/src/gplx/xowa/htmls/Xoh_cfg_file.java
Normal file
30
400_xowa/src/gplx/xowa/htmls/Xoh_cfg_file.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Xoh_cfg_file {
|
||||
public Xoh_cfg_file(Url_encoder url_encoder, Io_url xowa_dir) {
|
||||
Io_url mw_file_dir = xowa_dir.GenSubDir_nest("file", "mediawiki.file");
|
||||
img_media_play_btn = url_encoder.Encode_http(mw_file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = url_encoder.Encode_http(mw_file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = url_encoder.Encode_http(mw_file_dir.GenSubFil("magnify-clip.png"));
|
||||
}
|
||||
public byte[] Img_media_play_btn() {return img_media_play_btn;} private final byte[] img_media_play_btn;
|
||||
public byte[] Img_media_info_btn() {return img_media_info_btn;} private final byte[] img_media_info_btn;
|
||||
public byte[] Img_thumb_magnify() {return img_thumb_magnify;} private final byte[] img_thumb_magnify;
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/htmls/Xoh_cmd_itm.java
Normal file
23
400_xowa/src/gplx/xowa/htmls/Xoh_cmd_itm.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoh_cmd_itm {
|
||||
String Hcmd_id();
|
||||
void Hcmd_exec(Xoae_app app, Gfo_usr_dlg usr_dlg, Xoae_page page);
|
||||
void Hcmd_write(Xoae_app app, Gfo_usr_dlg usr_dlg, Xoae_page page);
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/htmls/Xoh_cmd_mgr.java
Normal file
40
400_xowa/src/gplx/xowa/htmls/Xoh_cmd_mgr.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_cmd_mgr {
|
||||
public int Count() {return cmds.Count();}
|
||||
public void Clear() {cmds.Clear();}
|
||||
public void Add(Xoh_cmd_itm itm) {cmds.Add(itm);} List_adp cmds = List_adp_.new_();
|
||||
public void Exec(Xoae_app app, Xoae_page page) {
|
||||
int len = cmds.Count();
|
||||
if (len == 0) return;
|
||||
Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
usr_dlg.Prog_one(GRP_KEY, "bgn", "cmds bgn: ~{0}", len); // NOTE: this message will not show, but is needed for other messages to show; SWT swallowing 1st msg before showing others?; DATE:2013-04-25
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (usr_dlg.Canceled()) {usr_dlg.Prog_none(GRP_KEY, "cmds.done", ""); app.Log_wtr().Queue_enabled_(false); return;}
|
||||
Xoh_cmd_itm itm = null;
|
||||
try {
|
||||
itm = (Xoh_cmd_itm)cmds.Get_at(i);
|
||||
itm.Hcmd_exec(app, usr_dlg, page);
|
||||
itm.Hcmd_write(app, usr_dlg, page);
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to execute html cmd", "name", itm == null ? "unknown" : itm.Hcmd_id());}
|
||||
}
|
||||
this.Clear();
|
||||
}
|
||||
static final String GRP_KEY = "xowa.html.cmd_mgr";
|
||||
}
|
||||
56
400_xowa/src/gplx/xowa/htmls/Xoh_consts.java
Normal file
56
400_xowa/src/gplx/xowa/htmls/Xoh_consts.java
Normal 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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_consts {
|
||||
public static final String
|
||||
Atr_xowa_title_str = "xowa_title"
|
||||
, Img_w_str = "width"
|
||||
, Img_h_str = "height"
|
||||
;
|
||||
public static final byte[]
|
||||
__end = Bry_.new_a7(">")
|
||||
, __inline = Bry_.new_a7("/>")
|
||||
, __end_quote = Bry_.new_a7("\">")
|
||||
, __inline_quote = Bry_.new_a7("\"/>")
|
||||
, Space_2 = Bry_.new_a7(" ")
|
||||
|
||||
, A_bgn = Bry_.new_a7("<a href=\""), A_bgn_lnki_0 = Bry_.new_a7("\" title=\""), A_mid_xowa_title = Bry_.new_a7("\" xowa_title=\"")
|
||||
, A_mid_id = Bry_.new_a7("\" id=\"xowa_lnki_")
|
||||
, A_end = Bry_.new_a7("</a>")
|
||||
, Div_bgn_open = Bry_.new_a7("<div ")
|
||||
, Div_end = Bry_.new_a7("</div>")
|
||||
|
||||
, Img_bgn = Bry_.new_a7("<img src=\"")
|
||||
, Span_bgn_open = Bry_.new_a7("<span")
|
||||
, Span_end = Bry_.new_a7("</span>")
|
||||
, Span_bgn = Bry_.new_a7("<span>")
|
||||
|
||||
, Pre_bgn = Bry_.new_a7("<pre>"), Pre_end = Bry_.new_a7("</pre>")
|
||||
, Pre_bgn_open = Bry_.new_a7("<pre")
|
||||
, Pre_bgn_overflow = Bry_.new_a7("<pre style=\"overflow:auto\">")
|
||||
|
||||
, Code_bgn_closed = Bry_.new_a7("<code>")
|
||||
, Code_bgn_open = Bry_.new_a7("<code")
|
||||
, Code_end = Bry_.new_a7("</code>")
|
||||
, Title_atr = Bry_.new_a7("\" title=\"")
|
||||
, Id_atr = Bry_.new_a7(" id=\"")
|
||||
, Style_atr = Bry_.new_a7(" style=\"")
|
||||
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)
|
||||
;
|
||||
public static final int Nbsp_int = 160;
|
||||
}
|
||||
39
400_xowa/src/gplx/xowa/htmls/Xoh_html_mgr.java
Normal file
39
400_xowa/src/gplx/xowa/htmls/Xoh_html_mgr.java
Normal 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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.htmls.tidy.*; import gplx.xowa.htmls.utils.*; import gplx.xowa.htmls.skins.*;
|
||||
import gplx.xowa.parsers.xndes.*;
|
||||
public class Xoh_html_mgr implements GfoInvkAble {
|
||||
public Xoh_html_mgr(Xoae_app app) {
|
||||
js_cleaner = new Xoh_js_cleaner(app);
|
||||
}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
tidy_mgr.Init_by_app(app);
|
||||
}
|
||||
public Xop_xatr_whitelist_mgr Whitelist_mgr() {return whitelist_mgr;} private final Xop_xatr_whitelist_mgr whitelist_mgr = new Xop_xatr_whitelist_mgr().Ini();
|
||||
public Xoh_page_mgr Page_mgr() {return page_mgr;} private final Xoh_page_mgr page_mgr = new Xoh_page_mgr();
|
||||
public Xoh_tidy_mgr Tidy_mgr() {return tidy_mgr;} private final Xoh_tidy_mgr tidy_mgr = new Xoh_tidy_mgr();
|
||||
public Xoh_js_cleaner Js_cleaner() {return js_cleaner;} private final Xoh_js_cleaner js_cleaner;
|
||||
public Xoh_skin_mgr Skin_mgr() {return skin_mgr;} private final Xoh_skin_mgr skin_mgr = new Xoh_skin_mgr();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_page)) return page_mgr;
|
||||
else if (ctx.Match(k, Invk_tidy)) return tidy_mgr;
|
||||
else if (ctx.Match(k, Invk_skins)) return skin_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_page = "page", Invk_tidy = "tidy", Invk_skins = "skins";
|
||||
}
|
||||
649
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr.java
Normal file
649
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr.java
Normal file
@@ -0,0 +1,649 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.htmls.lnkis.*; import gplx.xowa.parsers.tblws.*; import gplx.xowa.parsers.paras.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.miscs.*; import gplx.xowa.parsers.vnts.*; import gplx.xowa.parsers.htmls.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.xtns.cite.*; import gplx.xowa.htmls.hzips.*;
|
||||
public class Xoh_html_wtr {
|
||||
private Xowe_wiki wiki; private Xoae_app app; private Xoae_page page; private Xop_xatr_whitelist_mgr whitelist_mgr;
|
||||
public Xoh_html_wtr(Xowe_wiki wiki, Xow_html_mgr html_mgr) {
|
||||
this.wiki = wiki; this.app = wiki.Appe(); this.whitelist_mgr = app.Html_mgr().Whitelist_mgr();
|
||||
this.html_mgr = html_mgr;
|
||||
lnki_wtr = new Xoh_lnki_wtr(this, wiki, html_mgr, cfg);
|
||||
ref_wtr = new Ref_html_wtr(wiki);
|
||||
lnke_wtr = new Xoh_lnke_wtr(wiki);
|
||||
}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
cfg.Toc__show_(Bool_.Y).Lnki__title_(true).Lnki_visited_y_().Lnki__id_y_(); // NOTE: set during Init_by_wiki, b/c all tests assume these are false
|
||||
ref_wtr.Init_by_wiki(wiki);
|
||||
}
|
||||
public Xow_html_mgr Html_mgr() {return html_mgr;} private Xow_html_mgr html_mgr;
|
||||
public Xoh_html_wtr_cfg Cfg() {return cfg;} private Xoh_html_wtr_cfg cfg = new Xoh_html_wtr_cfg();
|
||||
public Xoh_lnki_wtr Lnki_wtr() {return lnki_wtr;} private Xoh_lnki_wtr lnki_wtr;
|
||||
public Xoh_lnke_wtr Lnke_wtr() {return lnke_wtr;} private Xoh_lnke_wtr lnke_wtr;
|
||||
public Ref_html_wtr Ref_wtr() {return ref_wtr;} private Ref_html_wtr ref_wtr;
|
||||
public void Init_by_page(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xoae_page page) {this.page = page; lnki_wtr.Init_by_page(ctx, hctx, src, page);}
|
||||
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_root_tkn root) {Write_all(bfr, ctx, Xoh_wtr_ctx.Basic, src, root);}
|
||||
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_root_tkn root) {
|
||||
try {
|
||||
indent_level = 0; this.page = ctx.Cur_page();
|
||||
page.Slink_list().Clear(); // HACK: always clear langs; necessary for reload
|
||||
lnki_wtr.Init_by_page(ctx, hctx, src, ctx.Cur_page());
|
||||
Write_tkn(bfr, ctx, hctx, src, null, -1, root);
|
||||
if (cfg.Hdr__div_wrapper())
|
||||
bfr.Add(Tag_hdr__div_wrapper_end);
|
||||
}
|
||||
finally {
|
||||
page.Category_list_(page.Html_data().Ctgs_to_ary());
|
||||
}
|
||||
}
|
||||
public void Write_tkn_ary(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tkn_itm[] ary) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Xop_tkn_itm itm = ary[i];
|
||||
Write_tkn(bfr, ctx, hctx, src, itm, i, itm);
|
||||
}
|
||||
}
|
||||
public void Write_tkn(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_tkn_itm tkn) {
|
||||
if (tkn.Ignore()) return;
|
||||
switch (tkn.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_arg_itm:
|
||||
case Xop_tkn_itm_.Tid_root:
|
||||
int subs_len = tkn.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, tkn, i, tkn.Subs_get(i));
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_ignore: break;
|
||||
case Xop_tkn_itm_.Tid_html_ncr: Html_ncr(ctx, hctx, bfr, src, (Xop_amp_tkn_num)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_html_ref: Html_ref(ctx, hctx, bfr, src, (Xop_amp_tkn_txt)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_hr: Hr(ctx, hctx, bfr, src, (Xop_hr_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_hdr: Hdr(ctx, hctx, bfr, src, (Xop_hdr_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_apos: Apos(ctx, hctx, bfr, src, (Xop_apos_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnke: lnke_wtr.Write_all(bfr, this, hctx, ctx, src, (Xop_lnke_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_lnki: lnki_wtr.Write(bfr, hctx, src, (Xop_lnki_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_list: List(ctx, hctx, bfr, src, (Xop_list_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_xnde: Xnde(ctx, hctx, bfr, src, (Xop_xnde_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_under: Under(ctx, hctx, bfr, src, (Xop_under_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tb: Tblw(ctx, hctx, bfr, src, (Xop_tblw_tkn)tkn, Tag_tblw_tb_bgn_atr, Tag_tblw_tb_end, true); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tr: Tblw(ctx, hctx, bfr, src, (Xop_tblw_tkn)tkn, Tag_tblw_tr_bgn_atr, Tag_tblw_tr_end, false); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_td: Tblw(ctx, hctx, bfr, src, (Xop_tblw_tkn)tkn, Tag_tblw_td_bgn_atr, Tag_tblw_td_end, false); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_th: Tblw(ctx, hctx, bfr, src, (Xop_tblw_tkn)tkn, Tag_tblw_th_bgn_atr, Tag_tblw_th_end, false); break;
|
||||
case Xop_tkn_itm_.Tid_tblw_tc: Tblw(ctx, hctx, bfr, src, (Xop_tblw_tkn)tkn, Tag_tblw_tc_bgn_atr, Tag_tblw_tc_end, false); break;
|
||||
case Xop_tkn_itm_.Tid_para: Para(ctx, hctx, bfr, src, (Xop_para_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_space: Space(ctx, hctx, bfr, src, grp, sub_idx, (Xop_space_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_pre: Pre(ctx, hctx, bfr, src, (Xop_pre_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_newLine: NewLine(ctx, hctx, bfr, src, (Xop_nl_tkn)tkn); break;
|
||||
case Xop_tkn_itm_.Tid_bry: Bry(ctx, hctx, bfr, src, (Xop_bry_tkn)tkn); break;
|
||||
default:
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, tkn.Src_bgn(), tkn.Src_end(), true, false); // NOTE: always escape text including (a) lnki_alt text; and (b) any other text, especially failed xndes; DATE:2013-06-18
|
||||
break;
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void Html_ncr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_num tkn) {
|
||||
bfr.Add_byte(Byte_ascii.Amp).Add_byte(Byte_ascii.Hash).Add_int_variable(tkn.Val()).Add_byte(Byte_ascii.Semic); // NOTE: do not literalize, else browser may not display multi-char bytes properly; EX:   gets added as   not as {192,160}; DATE:2013-12-09
|
||||
}
|
||||
@gplx.Virtual public void Html_ref(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_txt tkn) {
|
||||
if (tkn.Itm_is_custom()) // used by <nowiki>; EX:<nowiki><</nowiki> -> &xowa_lt; DATE:2014-11-07
|
||||
tkn.Print_literal(bfr);
|
||||
else
|
||||
tkn.Print_ncr(bfr);
|
||||
}
|
||||
private static final byte[] Bry_hdr_bgn = Bry_.new_a7("<span class='mw-headline' id='"), Bry_hdr_end = Bry_.new_a7("</span>");
|
||||
@gplx.Virtual public void Hr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hr_tkn tkn) {bfr.Add(Tag_hr);}
|
||||
@gplx.Virtual public void Hdr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hdr_tkn hdr) {
|
||||
boolean hdr_is_1st = hdr.Hdr_html_first();
|
||||
if (hdr_is_1st && cfg.Toc__show() && !page.Hdr_mgr().Toc_manual()) { // __TOC__ not specified; place at top; NOTE: if __TOC__ was specified, then it would be placed wherever __TOC__ appears
|
||||
wiki.Html_mgr().Toc_mgr().Html(ctx.Cur_page(), hctx, src, bfr);
|
||||
}
|
||||
int hdr_len = hdr.Hdr_len();
|
||||
if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling
|
||||
Para_assert_tag_starts_on_nl(bfr, hdr.Src_bgn());
|
||||
if ( cfg.Hdr__div_wrapper() // div_wrapper enabled
|
||||
&& !hdr_is_1st // not 1st <h#>; 2nd and up will close previous <#>
|
||||
)
|
||||
bfr.Add(Tag_hdr__div_wrapper_end); // add </div>
|
||||
bfr.Add(Tag_hdr_bgn).Add_int(hdr_len, 1, 1);
|
||||
if (cfg.Toc__show()) {
|
||||
bfr.Add_byte(Tag__end);
|
||||
bfr.Add(Bry_hdr_bgn);
|
||||
bfr.Add(hdr.Hdr_html_id());
|
||||
bfr.Add_byte(Byte_ascii.Apos);
|
||||
}
|
||||
bfr.Add_byte(Tag__end);
|
||||
}
|
||||
if (hdr.Hdr_bgn_manual() > 0) bfr.Add_byte_repeat(Byte_ascii.Eq, hdr.Hdr_bgn_manual());
|
||||
int subs_len = hdr.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, hdr, i, hdr.Subs_get(i));
|
||||
if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling
|
||||
if (hdr.Hdr_end_manual() > 0) bfr.Add_byte_repeat(Byte_ascii.Eq, hdr.Hdr_end_manual());
|
||||
if (cfg.Toc__show()) {
|
||||
if (hctx.Mode_is_hdump())
|
||||
bfr.Add(Xow_hzip_itm__header.Hdr_end);
|
||||
bfr.Add(Bry_hdr_end);
|
||||
}
|
||||
bfr.Add(Tag_hdr_end).Add_int(hdr_len, 1, 1).Add_byte(Tag__end).Add_byte_nl();// NOTE: do not need to check hdr_len b/c it is impossible for end to occur without bgn
|
||||
if ( cfg.Hdr__div_wrapper()) // div_wrapper enabled
|
||||
bfr.Add(Tag_hdr__div_wrapper_bgn); // add <div>
|
||||
}
|
||||
}
|
||||
public void Apos(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_apos_tkn apos) {
|
||||
if (hctx.Mode_is_alt()) return; // ignore apos if alt; EX: [[File:A.png|''A'']] should have alt of A; DATE:2013-10-25
|
||||
int literal_apos = apos.Apos_lit();
|
||||
if (literal_apos > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Apos, literal_apos);
|
||||
switch (apos.Apos_cmd()) {
|
||||
case Xop_apos_tkn_.Cmd_b_bgn: bfr.Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end: bfr.Add(Html_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_bgn: bfr.Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end: bfr.Add(Html_tag_.I_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_bgn: bfr.Add(Html_tag_.B_lhs).Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_rhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_bgn: bfr.Add(Html_tag_.I_lhs).Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_rhs);; break;
|
||||
case Xop_apos_tkn_.Cmd_bi_end__b_bgn: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_rhs).Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_ib_end__i_bgn: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_rhs).Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_b_end__i_bgn: bfr.Add(Html_tag_.B_rhs).Add(Html_tag_.I_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_i_end__b_bgn: bfr.Add(Html_tag_.I_rhs).Add(Html_tag_.B_lhs); break;
|
||||
case Xop_apos_tkn_.Cmd_nil: break;
|
||||
default: throw Err_.new_unhandled(apos.Apos_cmd());
|
||||
}
|
||||
}
|
||||
public static byte[] Ttl_to_title(byte[] ttl) {return ttl;} // FUTURE: swap html chars?
|
||||
public void List(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_list_tkn list) {
|
||||
if (hctx.Mode_is_alt()) { // alt; add literally; EX: "*" for "\n*"; note that \n is added in NewLine()
|
||||
if (list.List_bgn() == Bool_.Y_byte) { // bgn tag
|
||||
bfr.Add_byte(list.List_itmTyp()); // add literal byte
|
||||
}
|
||||
else {} // end tag; ignore
|
||||
}
|
||||
else {
|
||||
byte list_itm_type = list.List_itmTyp();
|
||||
if (list.List_bgn() == Bool_.Y_byte) {
|
||||
if (list.List_sub_first()) List_grp_bgn(ctx, hctx, bfr, src, list_itm_type);
|
||||
List_itm_bgn(ctx, hctx, bfr, src, list_itm_type);
|
||||
}
|
||||
else {
|
||||
List_itm_end(ctx, hctx, bfr, src, list_itm_type);
|
||||
if (list.List_sub_last() == Bool_.Y_byte) List_grp_end(ctx, hctx, bfr, src, list_itm_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void List_grp_bgn(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol: tag = Tag_list_grp_ol_bgn; break;
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Tag_list_grp_ul_bgn; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd:
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Tag_list_grp_dl_bgn; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
if (bfr.Len() > 0) bfr.Add_byte_nl(); // NOTE: do not add newLine if start
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(tag);
|
||||
++indent_level;
|
||||
}
|
||||
@gplx.Virtual public void List_itm_bgn(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol:
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Tag_list_itm_li_bgn; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Tag_list_itm_dt_bgn; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd: tag = Tag_list_itm_dd_bgn; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(tag);
|
||||
++indent_level;
|
||||
}
|
||||
@gplx.Virtual public void List_grp_end(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
--indent_level;
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol: tag = Tag_list_grp_ol_end; break;
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Tag_list_grp_ul_end; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd:
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Tag_list_grp_dl_end; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(tag);
|
||||
}
|
||||
|
||||
@gplx.Virtual public void List_itm_end(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
--indent_level;
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol:
|
||||
case Xop_list_tkn_.List_itmTyp_ul: tag = Tag_list_itm_li_end; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dt: tag = Tag_list_itm_dt_end; break;
|
||||
case Xop_list_tkn_.List_itmTyp_dd: tag = Tag_list_itm_dd_end; break;
|
||||
default: throw Err_.new_unhandled(type);
|
||||
}
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(tag);
|
||||
}
|
||||
@gplx.Virtual public void NewLine(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_nl_tkn tkn) {
|
||||
if (hctx.Mode_is_alt())
|
||||
bfr.Add_byte_space();
|
||||
else {
|
||||
if (tkn.Nl_tid() == Xop_nl_tkn.Tid_char) {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Space(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_space_tkn space) {
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, space.Src_end_grp(grp, sub_idx) - space.Src_bgn_grp(grp, sub_idx)); // NOTE: lnki.caption will convert \n to \s; see Xop_nl_lxr; PAGE:en.w:Schwarzschild radius
|
||||
}
|
||||
@gplx.Virtual public void Para(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_para_tkn para) {
|
||||
if (para.Nl_bgn() && bfr.Len() > 0) {
|
||||
if (hctx.Mode_is_alt())
|
||||
bfr.Add_byte_space();
|
||||
else
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
}
|
||||
switch (para.Para_end()) {
|
||||
case Xop_para_tkn.Tid_none: break;
|
||||
case Xop_para_tkn.Tid_para: bfr.Add(Tag_para_end).Add_byte_nl(); break;
|
||||
case Xop_para_tkn.Tid_pre: bfr.Add(Tag_pre_end).Add_byte_nl(); break;
|
||||
default: throw Err_.new_unhandled(para.Para_end());
|
||||
}
|
||||
switch (para.Para_bgn()) {
|
||||
case Xop_para_tkn.Tid_none: break;
|
||||
case Xop_para_tkn.Tid_para: Para_assert_tag_starts_on_nl(bfr, para.Src_bgn()); bfr.Add(Tag_para_bgn); break;
|
||||
case Xop_para_tkn.Tid_pre: Para_assert_tag_starts_on_nl(bfr, para.Src_bgn()); bfr.Add(Tag_pre_bgn); break;
|
||||
default: throw Err_.new_unhandled(para.Para_bgn());
|
||||
}
|
||||
if (para.Space_bgn() > 0)
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, para.Space_bgn());
|
||||
}
|
||||
private void Para_assert_tag_starts_on_nl(Bry_bfr bfr, int src_bgn) {
|
||||
if (!bfr.Match_end_byt_nl_or_bos()) bfr.Add_byte_nl();
|
||||
if (src_bgn != 0) bfr.Add_byte_nl();
|
||||
}
|
||||
@gplx.Virtual public void Pre(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_pre_tkn pre) {
|
||||
switch (pre.Pre_tid()) {
|
||||
case Xop_pre_tkn.Pre_tid_bgn:
|
||||
bfr.Add(Tag_pre_bgn);
|
||||
break;
|
||||
case Xop_pre_tkn.Pre_tid_end:
|
||||
bfr.Add_byte_nl().Add(Tag_pre_end).Add_byte_nl().Add_byte_nl();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void Bry(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_bry_tkn bry) {
|
||||
bfr.Add(bry.Val());
|
||||
}
|
||||
@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;
|
||||
switch (under.Under_tid()) {
|
||||
case Xol_kwd_grp_.Id_toc:
|
||||
wiki.Html_mgr().Toc_mgr().Html(page, hctx, src, bfr);
|
||||
break;
|
||||
case Xol_kwd_grp_.Id_notoc: case Xol_kwd_grp_.Id_forcetoc: // NOTE: skip output; changes flag on page only
|
||||
break;
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void Xnde(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (hctx.Mode_is_alt()) {
|
||||
if (xnde.Tag_close_bgn() > 0) // NOTE: some tags are not closed; WP.EX: France; <p>
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), true, false);
|
||||
else
|
||||
Xnde_subs(ctx, hctx, bfr, src, xnde);
|
||||
return;
|
||||
}
|
||||
Xop_xnde_tag tag = xnde.Tag();
|
||||
int tag_id = tag.Id();
|
||||
switch (tag_id) {
|
||||
case Xop_xnde_tag_.Tid_br:
|
||||
if (xnde.Src_end() - xnde.Src_bgn() < 4
|
||||
|| xnde.Src_bgn() == -1)
|
||||
bfr.Add(Tag_br); else bfr.Add_mid(src, xnde.Src_bgn(), xnde.Src_end()); break;
|
||||
case Xop_xnde_tag_.Tid_hr: bfr.Add(Tag_hr); break;
|
||||
case Xop_xnde_tag_.Tid_includeonly: // NOTE: do not write tags or content
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid_noinclude: // NOTE: do not write tags
|
||||
case Xop_xnde_tag_.Tid_onlyinclude:
|
||||
Xnde_subs_escape(ctx, hctx, bfr, src, xnde, false, false);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid_nowiki:
|
||||
Xnde_subs_escape(ctx, hctx, bfr, src, xnde, false, false);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid_b: case Xop_xnde_tag_.Tid_strong:
|
||||
case Xop_xnde_tag_.Tid_i: case Xop_xnde_tag_.Tid_em: case Xop_xnde_tag_.Tid_cite: case Xop_xnde_tag_.Tid_dfn: case Xop_xnde_tag_.Tid_var:
|
||||
case Xop_xnde_tag_.Tid_u: case Xop_xnde_tag_.Tid_ins: case Xop_xnde_tag_.Tid_abbr:
|
||||
case Xop_xnde_tag_.Tid_strike: case Xop_xnde_tag_.Tid_s: case Xop_xnde_tag_.Tid_del:
|
||||
case Xop_xnde_tag_.Tid_sub: case Xop_xnde_tag_.Tid_sup: case Xop_xnde_tag_.Tid_big: case Xop_xnde_tag_.Tid_small:
|
||||
case Xop_xnde_tag_.Tid_code: case Xop_xnde_tag_.Tid_tt: case Xop_xnde_tag_.Tid_kbd: case Xop_xnde_tag_.Tid_samp: case Xop_xnde_tag_.Tid_blockquote:
|
||||
case Xop_xnde_tag_.Tid_font: case Xop_xnde_tag_.Tid_center:
|
||||
case Xop_xnde_tag_.Tid_p: case Xop_xnde_tag_.Tid_span: case Xop_xnde_tag_.Tid_div:
|
||||
case Xop_xnde_tag_.Tid_h1: case Xop_xnde_tag_.Tid_h2: case Xop_xnde_tag_.Tid_h3: case Xop_xnde_tag_.Tid_h4: case Xop_xnde_tag_.Tid_h5: case Xop_xnde_tag_.Tid_h6:
|
||||
case Xop_xnde_tag_.Tid_dt: case Xop_xnde_tag_.Tid_dd: case Xop_xnde_tag_.Tid_ol: case Xop_xnde_tag_.Tid_ul: case Xop_xnde_tag_.Tid_dl:
|
||||
case Xop_xnde_tag_.Tid_table: case Xop_xnde_tag_.Tid_tr: case Xop_xnde_tag_.Tid_td: case Xop_xnde_tag_.Tid_th: case Xop_xnde_tag_.Tid_caption: case Xop_xnde_tag_.Tid_tbody:
|
||||
case Xop_xnde_tag_.Tid_ruby: case Xop_xnde_tag_.Tid_rt: case Xop_xnde_tag_.Tid_rb: case Xop_xnde_tag_.Tid_rp:
|
||||
case Xop_xnde_tag_.Tid_time: case Xop_xnde_tag_.Tid_bdi: case Xop_xnde_tag_.Tid_data: case Xop_xnde_tag_.Tid_mark: case Xop_xnde_tag_.Tid_wbr: case Xop_xnde_tag_.Tid_bdo: // HTML 5: write literally and let browser handle them
|
||||
case Xop_xnde_tag_.Tid_q:
|
||||
Write_xnde(bfr, ctx, hctx, xnde, tag, tag_id, src);
|
||||
break;
|
||||
case Xop_xnde_tag_.Tid_pre: {
|
||||
if (xnde.Tag_open_end() == xnde.Tag_close_bgn()) return; // ignore empty tags, else blank pre line will be printed; DATE:2014-03-12
|
||||
byte[] name = tag.Name_bry();
|
||||
bfr.Add_byte(Tag__bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Tag__end);
|
||||
Xnde_subs_escape(ctx, hctx, bfr, src, xnde, false, true);
|
||||
bfr.Add(Tag__end_bgn).Add(name).Add_byte(Tag__end);
|
||||
break;
|
||||
}
|
||||
case Xop_xnde_tag_.Tid_li: {
|
||||
byte[] name = tag.Name_bry();
|
||||
int bfr_len = bfr.Len();
|
||||
if (bfr_len > 0 && bfr.Bfr()[bfr_len - 1] != Byte_ascii.Nl) bfr.Add_byte_nl(); // NOTE: always add nl before li else some lists will merge and force long horizontal bar; EX:w:Music
|
||||
if (xnde.Tag_visible()) {
|
||||
bfr.Add_byte(Tag__bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Tag__end);
|
||||
}
|
||||
Xnde_subs(ctx, hctx, bfr, src, xnde);
|
||||
if (xnde.Tag_visible())
|
||||
bfr.Add(Tag__end_bgn).Add(name).Add_byte(Tag__end); // NOTE: inline is never written as <b/>; will be written as <b></b>; SEE: NOTE_1
|
||||
break;
|
||||
}
|
||||
case Xop_xnde_tag_.Tid_timeline: {
|
||||
bfr.Add_str_a7("<pre class='xowa-timeline'>");
|
||||
Xox_mgr_base.Xtn_write_escape(app, bfr, src, xnde.Tag_open_end(), xnde.Tag_close_bgn()); // NOTE: do not embed <timeline> tag inside pre, else timeline will render in black; EX:<pre><timeline>a</timeline></pre> will fail; DATE:2014-05-22
|
||||
bfr.Add_str_a7("</pre>");
|
||||
break;
|
||||
}
|
||||
case Xop_xnde_tag_.Tid_gallery:
|
||||
case Xop_xnde_tag_.Tid_poem:
|
||||
case Xop_xnde_tag_.Tid_hiero:
|
||||
case Xop_xnde_tag_.Tid_score:
|
||||
case Xop_xnde_tag_.Tid_ref:
|
||||
case Xop_xnde_tag_.Tid_references:
|
||||
case Xop_xnde_tag_.Tid_inputBox:
|
||||
case Xop_xnde_tag_.Tid_imageMap:
|
||||
case Xop_xnde_tag_.Tid_pages:
|
||||
case Xop_xnde_tag_.Tid_pagequality:
|
||||
case Xop_xnde_tag_.Tid_pagelist:
|
||||
case Xop_xnde_tag_.Tid_section:
|
||||
case Xop_xnde_tag_.Tid_translate:
|
||||
case Xop_xnde_tag_.Tid_dynamicPageList:
|
||||
case Xop_xnde_tag_.Tid_languages:
|
||||
case Xop_xnde_tag_.Tid_templateData:
|
||||
case Xop_xnde_tag_.Tid_source: // DATE:2015-09-29
|
||||
case Xop_xnde_tag_.Tid_syntaxHighlight:
|
||||
case Xop_xnde_tag_.Tid_listing_buy:
|
||||
case Xop_xnde_tag_.Tid_listing_do:
|
||||
case Xop_xnde_tag_.Tid_listing_drink:
|
||||
case Xop_xnde_tag_.Tid_listing_eat:
|
||||
case Xop_xnde_tag_.Tid_listing_listing:
|
||||
case Xop_xnde_tag_.Tid_listing_see:
|
||||
case Xop_xnde_tag_.Tid_listing_sleep:
|
||||
case Xop_xnde_tag_.Tid_xowa_cmd:
|
||||
case Xop_xnde_tag_.Tid_rss:
|
||||
case Xop_xnde_tag_.Tid_quiz:
|
||||
case Xop_xnde_tag_.Tid_math:
|
||||
case Xop_xnde_tag_.Tid_indicator:
|
||||
case Xop_xnde_tag_.Tid_xowa_html:
|
||||
case Xop_xnde_tag_.Tid_graph:
|
||||
Xox_xnde xtn = xnde.Xnde_xtn();
|
||||
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:
|
||||
break;
|
||||
default: // unknown tag
|
||||
if (tag.Restricted()) { // a; img; script; etc..
|
||||
if ( !page.Html_data().Html_restricted() // page is not marked restricted (only [[Special:]])
|
||||
|| page.Wiki().Domain_tid() == Xow_domain_tid_.Int__home) { // page is in home wiki
|
||||
bfr.Add_mid(src, xnde.Src_bgn(), xnde.Src_end());
|
||||
return;
|
||||
}
|
||||
}
|
||||
bfr.Add(Ary_escape_bgn).Add(tag.Name_bry()); // escape bgn
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
switch (xnde.CloseMode()) {
|
||||
case Xop_xnde_tkn.CloseMode_inline:
|
||||
bfr.Add_byte(Byte_ascii.Slash).Add(Ary_escape_end);
|
||||
break;
|
||||
default: // NOTE: close tag, even if dangling; EX: <center>a -> <center>a</center>
|
||||
bfr.Add_byte(Byte_ascii.Gt);
|
||||
Xnde_subs(ctx, hctx, bfr, src, xnde);
|
||||
bfr.Add(Ary_escape_bgn).Add_byte(Byte_ascii.Slash).Add(tag.Name_bry()).Add(Ary_escape_end);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void Write_xnde(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, Xop_xnde_tag tag, int tag_id, byte[] src) {
|
||||
byte[] name = tag.Name_bry();
|
||||
boolean at_bgn = true;
|
||||
Bry_bfr ws_bfr = wiki.Utl__bfr_mkr().Get_b512(); // create separate ws_bfr to handle "a<b> c </b>d" -> "a <b>c</b> d"
|
||||
int subs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++) {
|
||||
Xop_tkn_itm sub = xnde.Subs_get(i);
|
||||
byte tkn_tid = sub.Tkn_tid();
|
||||
switch (tkn_tid) {
|
||||
case Xop_tkn_itm_.Tid_space: // space; add to ws_bfr;
|
||||
ws_bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
break;
|
||||
default:
|
||||
if (tkn_tid == Xop_tkn_itm_.Tid_html_ncr) { // html_entity   needed for fr.wikipedia.org and many spans with <span> </span>; DATE:2013-06-18
|
||||
Xop_amp_tkn_num ncr_tkn = (Xop_amp_tkn_num)sub;
|
||||
if (ncr_tkn.Val() == Byte_ascii.Space
|
||||
|| ncr_tkn.Val() == 160
|
||||
) {
|
||||
|
||||
ws_bfr.Add_mid(src, ncr_tkn.Src_bgn(), ncr_tkn.Src_end());
|
||||
continue; // just add entity; don't process rest;
|
||||
}
|
||||
}
|
||||
if (ws_bfr.Len() > 0) bfr.Add_bfr_and_clear(ws_bfr); // dump ws_bfr to real bfr
|
||||
if (at_bgn) { // 1st non-ws tkn; add open tag; <b>
|
||||
at_bgn = false;
|
||||
bfr.Add_byte(Tag__bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Tag__end);
|
||||
}
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, sub); // NOTE: never escape; <p>, <table>, <center> etc may have nested nodes
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (at_bgn) { // occurs when xnde is empty; EX: <b></b>
|
||||
bfr.Add_byte(Tag__bgn).Add(name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(tag_id, hctx, src, xnde.Atrs_bgn(), xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add_byte(Tag__end);
|
||||
}
|
||||
bfr.Add(Tag__end_bgn).Add(name).Add_byte(Tag__end); // NOTE: inline is never written as <b/>; will be written as <b></b>; SEE: NOTE_1
|
||||
if (ws_bfr.Len() > 0) bfr.Add_bfr_and_clear(ws_bfr); // dump any leftover ws to bfr; handles "<b>c </b>" -> "<b>c</b> "
|
||||
ws_bfr.Mkr_rls();
|
||||
}
|
||||
public void Xnde_atrs(int tag_id, Xoh_wtr_ctx hctx, byte[] src, int bgn, int end, Mwh_atr_itm[] ary, Bry_bfr bfr) {
|
||||
if (ary == null) return; // NOTE: some nodes will have null xatrs b/c of whitelist; EX: <pre style="overflow:auto">a</pre>; style is not on whitelist so not xatr generated, but xatr_bgn will != -1
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Mwh_atr_itm atr = ary[i];
|
||||
if (atr.Invalid()) continue;
|
||||
if (!whitelist_mgr.Chk(tag_id, src, atr)) continue;
|
||||
Xnde_atr_write(bfr, app, hctx, src, atr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Xnde_atr_write(Bry_bfr bfr, Xoae_app app, Xoh_wtr_ctx hctx, byte[] src, Mwh_atr_itm atr) {
|
||||
byte[] atr_key = atr.Key_bry();
|
||||
if ( hctx.Mode_is_display_title()
|
||||
&& Xoh_display_ttl_wtr.Instance.Is_style_restricted(bfr, hctx, src, atr, atr_key))
|
||||
return;
|
||||
|
||||
bfr.Add_byte(Byte_ascii.Space); // add space before every attribute
|
||||
if (atr_key != null) {
|
||||
bfr.Add(atr_key);
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
}
|
||||
byte quote_byte = atr.Qte_byte(); if (quote_byte == Byte_ascii.Null) quote_byte = Byte_ascii.Quote;
|
||||
bfr.Add_byte(quote_byte);
|
||||
if (atr.Key_tid() == Mwh_atr_itm_.Key_tid__id) { // ids should not have spaces; DATE:2013-04-01
|
||||
if (atr.Val_bry() == null)
|
||||
Xnde_atr_write_id(bfr, app, atr.Src(), atr.Val_bgn(), atr.Val_end());
|
||||
else {
|
||||
byte[] atr_val = atr.Val_bry();
|
||||
Xnde_atr_write_id(bfr, app, atr_val, 0, atr_val.length);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (atr.Val_bry() == null)
|
||||
bfr.Add_mid(src, atr.Val_bgn(), atr.Val_end());
|
||||
else
|
||||
bfr.Add(atr.Val_bry());
|
||||
}
|
||||
bfr.Add_byte(quote_byte);
|
||||
}
|
||||
private static void Xnde_atr_write_id(Bry_bfr bfr, Xoae_app app, byte[] bry, int bgn, int end) {
|
||||
Xoa_app_.Utl__encoder_mgr().Id().Encode(bfr, bry, bgn, end);
|
||||
}
|
||||
private void Xnde_subs(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
int subs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, xnde.Subs_get(i));
|
||||
}
|
||||
private void Xnde_subs_escape(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde, boolean amp_enable, boolean nowiki) {
|
||||
int xndesubs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < xndesubs_len; i++) {
|
||||
Xop_tkn_itm sub = xnde.Subs_get(i);
|
||||
switch (sub.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_xnde:
|
||||
Xop_xnde_tkn sub_xnde = (Xop_xnde_tkn)sub;
|
||||
switch (sub_xnde.Tag().Id()) {
|
||||
case Xop_xnde_tag_.Tid_noinclude:
|
||||
case Xop_xnde_tag_.Tid_onlyinclude:
|
||||
case Xop_xnde_tag_.Tid_includeonly:
|
||||
break;
|
||||
default:
|
||||
byte[] tag_name = sub_xnde.Tag().Name_bry();
|
||||
bfr.Add(Html_entity_.Lt_bry).Add(tag_name);
|
||||
if (xnde.Atrs_bgn() > Xop_tblw_wkr.Atrs_ignore_check) Xnde_atrs(sub_xnde.Tag().Id(), hctx, src, sub_xnde.Atrs_bgn(), sub_xnde.Atrs_end(), xnde.Atrs_ary(), bfr);
|
||||
bfr.Add(Html_entity_.Gt_bry);
|
||||
break;
|
||||
}
|
||||
Xnde_subs_escape(ctx, hctx, bfr, src, sub_xnde, amp_enable, false);
|
||||
break;
|
||||
case Xop_tkn_itm_.Tid_txt:
|
||||
if (amp_enable)
|
||||
bfr.Add_mid(src, sub.Src_bgn(), sub.Src_end());
|
||||
else
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), bfr, src, sub.Src_bgn(), sub.Src_end(), true, nowiki);
|
||||
break;
|
||||
default:
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, sub);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Tblw(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_tblw_tkn tkn, byte[] bgn, byte[] end, boolean tblw_bgn) {
|
||||
if (hctx.Mode_is_alt()) // add \s for each \n
|
||||
bfr.Add_byte_space();
|
||||
else {
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(bgn);
|
||||
int atrs_bgn = tkn.Atrs_bgn();
|
||||
if (atrs_bgn != -1) Xnde_atrs(tkn.Tblw_tid(), hctx, src, atrs_bgn, tkn.Atrs_end(), tkn.Atrs_ary(), bfr); //bfr.Add_byte(Byte_ascii.Space).Add_mid(src, atrs_bgn, tkn.Atrs_end());
|
||||
bfr.Add_byte(Tag__end);
|
||||
++indent_level;
|
||||
}
|
||||
int subs_len = tkn.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, tkn, i, tkn.Subs_get(i));
|
||||
if (hctx.Mode_is_alt()) {
|
||||
if (tblw_bgn) // only add \s for closing table; |} -> "\s"
|
||||
bfr.Add_byte_space();
|
||||
}
|
||||
else {
|
||||
--indent_level;
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(end);
|
||||
bfr.Add_byte_if_not_last(Byte_ascii.Nl);
|
||||
}
|
||||
}
|
||||
public static final byte[] Tag__end_quote = Bry_.new_a7("\">"), Tag__end_bgn = Bry_.new_a7("</")
|
||||
, Tag_hdr_bgn = Bry_.new_a7("<h"), Tag_hdr_end = Bry_.new_a7("</h"), Tag_hr = Bry_.new_a7("<hr/>"), Tag_br = Bry_.new_a7("<br/>")
|
||||
, Tag_list_grp_ul_bgn = Bry_.new_a7("<ul>"), Tag_list_grp_ul_end = Bry_.new_a7("</ul>")
|
||||
, Tag_list_grp_ol_bgn = Bry_.new_a7("<ol>"), Tag_list_grp_ol_end = Bry_.new_a7("</ol>")
|
||||
, Tag_list_itm_li_bgn = Bry_.new_a7("<li>"), Tag_list_itm_li_end = Bry_.new_a7("</li>")
|
||||
, Tag_list_itm_dt_bgn = Bry_.new_a7("<dt>"), Tag_list_itm_dt_end = Bry_.new_a7("</dt>")
|
||||
, Tag_list_itm_dd_bgn = Bry_.new_a7("<dd>"), Tag_list_itm_dd_end = Bry_.new_a7("</dd>")
|
||||
, Tag_list_grp_dl_bgn = Bry_.new_a7("<dl>"), Tag_list_grp_dl_end = Bry_.new_a7("</dl>")
|
||||
, File_divider = Bry_.new_a7("---------------------------------")
|
||||
, Tag_tblw_tb_bgn = Bry_.new_a7("<table>"), Tag_tblw_tb_bgn_atr = Bry_.new_a7("<table"), Tag_tblw_tb_end = Bry_.new_a7("</table>")
|
||||
, Tag_tblw_tr_bgn = Bry_.new_a7("<tr>"), Tag_tblw_tr_bgn_atr = Bry_.new_a7("<tr"), Tag_tblw_tr_end = Bry_.new_a7("</tr>")
|
||||
, Tag_tblw_td_bgn = Bry_.new_a7("<td>"), Tag_tblw_td_bgn_atr = Bry_.new_a7("<td"), Tag_tblw_td_end = Bry_.new_a7("</td>")
|
||||
, Tag_tblw_th_bgn = Bry_.new_a7("<th>"), Tag_tblw_th_bgn_atr = Bry_.new_a7("<th"), Tag_tblw_th_end = Bry_.new_a7("</th>")
|
||||
, Tag_tblw_tc_bgn = Bry_.new_a7("<caption>"), Tag_tblw_tc_bgn_atr = Bry_.new_a7("<caption"), Tag_tblw_tc_end = Bry_.new_a7("</caption>")
|
||||
, Ary_escape_bgn = Bry_.new_a7("<"), Ary_escape_end = Bry_.new_a7(">"), Ary_escape_end_bgn = Bry_.new_a7("</")
|
||||
, Tag_para_bgn = Bry_.new_a7("<p>"), Tag_para_end = Bry_.new_a7("</p>"), Tag_para_mid = Bry_.new_a7("</p>\n\n<p>")
|
||||
, Tag_pre_bgn = Bry_.new_a7("<pre>"), Tag_pre_end = Bry_.new_a7("</pre>")
|
||||
;
|
||||
private static final byte[] Tag_hdr__div_wrapper_bgn = Bry_.new_a7("<div>\n"), Tag_hdr__div_wrapper_end = Bry_.new_a7("</div>\n");
|
||||
public static final byte Tag__bgn = Byte_ascii.Lt, Tag__end = Byte_ascii.Gt;
|
||||
public static final byte Dir_spr_http = Byte_ascii.Slash;
|
||||
private int indent_level = 0;
|
||||
public static final int Sub_idx_null = -1; // nonsense placeholder
|
||||
}
|
||||
class Xoh_display_ttl_wtr {
|
||||
private static final byte[]
|
||||
Atr_key_style = Bry_.new_a7("style")
|
||||
, Msg_style_restricted = Bry_.new_a7(" style='/* attempt to bypass $wgRestrictDisplayTitle */'")
|
||||
;
|
||||
private Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_str_byte__many(Byte_.By_int(0), "display", "user-select", "visibility"); // if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
|
||||
public boolean Is_style_restricted(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Mwh_atr_itm atr, byte[] atr_key) {
|
||||
if (atr_key != null
|
||||
&& Bry_.Eq(atr_key, Atr_key_style)
|
||||
) {
|
||||
byte[] atr_val = atr.Val_as_bry(); if (atr_val == null) return false; // bounds_chk
|
||||
int atr_val_len = atr_val.length;
|
||||
int atr_pos = 0;
|
||||
while (atr_pos < atr_val_len) {
|
||||
byte b = atr_val[atr_pos];
|
||||
Object o = style_trie.Match_bgn_w_byte(b, atr_val, atr_pos, atr_val_len);
|
||||
if (o != null) {
|
||||
bfr.Add(Msg_style_restricted);
|
||||
return true;
|
||||
}
|
||||
++atr_pos;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static final Xoh_display_ttl_wtr Instance = new Xoh_display_ttl_wtr(); Xoh_display_ttl_wtr() {}
|
||||
}
|
||||
/*
|
||||
NOTE_1:inline always written as <tag></tag>, not <tag/>
|
||||
see WP:Permian<61>Triassic extinction event
|
||||
this will cause firefox to swallow up rest of text
|
||||
<div id="ScaleBar" style="width:1px; float:left; height:38em; padding:0; background-color:#242020" />
|
||||
this will not
|
||||
<div id="ScaleBar" style="width:1px; float:left; height:38em; padding:0; background-color:#242020" ></div>
|
||||
*/
|
||||
25
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr_cfg.java
Normal file
25
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr_cfg.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_html_wtr_cfg {
|
||||
public boolean Toc__show() {return toc__show;} public Xoh_html_wtr_cfg Toc__show_(boolean v) {toc__show = v; return this;} private boolean toc__show;
|
||||
public boolean Lnki__id() {return lnki__id;} public Xoh_html_wtr_cfg Lnki__id_y_() {lnki__id = Bool_.Y; return this;} private boolean lnki__id;
|
||||
public boolean Lnki__title() {return lnki__title;} public Xoh_html_wtr_cfg Lnki__title_(boolean v) {lnki__title = v; return this;} private boolean lnki__title;
|
||||
public boolean Lnki__visited() {return lnki__visited;} public Xoh_html_wtr_cfg Lnki_visited_y_() {lnki__visited = true; return this;} private boolean lnki__visited;
|
||||
public boolean Hdr__div_wrapper() {return hdr__div_wrapper;} public Xoh_html_wtr_cfg Hdr__div_wrapper_(boolean v) {hdr__div_wrapper = v; return this;} private boolean hdr__div_wrapper;
|
||||
}
|
||||
124
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr_escaper.java
Normal file
124
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr_escaper.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*; import gplx.langs.htmls.*;
|
||||
import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.xndes.*;
|
||||
public class Xoh_html_wtr_escaper {
|
||||
public static byte[] Escape(Xop_amp_mgr amp_mgr, Bry_bfr tmp_bfr, byte[] src) {
|
||||
Escape(amp_mgr, tmp_bfr, src, 0, src.length, true, false);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public static void Escape(Xop_amp_mgr amp_mgr, Bry_bfr bfr, byte[] src, int bgn, int end, boolean interpret_amp, boolean nowiki_skip) {
|
||||
Btrie_slim_mgr amp_trie = amp_mgr.Amp_trie();
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Lt:
|
||||
if (nowiki_skip) {
|
||||
byte[] nowiki_name = Xop_xnde_tag_.Tag_nowiki.Name_bry();
|
||||
int nowiki_name_len = nowiki_name.length;
|
||||
if (Bry_.Eq(src, i + 1, i + 1 + nowiki_name_len, nowiki_name)) { // <nowiki found;
|
||||
int end_gt = Escape_nowiki_skip(bfr, src, i, end, nowiki_name, nowiki_name_len);
|
||||
if (end_gt != Bry_.NotFound) {
|
||||
i = end_gt;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
bfr.Add(Html_entity_.Lt_bry);
|
||||
break;
|
||||
case Byte_ascii.Gt:
|
||||
bfr.Add(Html_entity_.Gt_bry);
|
||||
break;
|
||||
case Byte_ascii.Amp:
|
||||
if (interpret_amp) {
|
||||
int text_bgn = i + 1; // i is &; i + 1 is first char after amp
|
||||
Object o = (text_bgn < end) ? amp_trie.Match_bgn(src, text_bgn, end) : null; // check if this is a valid &; note must check that text_bgn < end or else arrayIndex error; occurs when src is just "&"; DATE:2013-12-19
|
||||
if (o == null) // invalid; EX: "a&b"; "&bad;"; "&#letters;";
|
||||
bfr.Add(Html_entity_.Amp_bry); // escape & and continue
|
||||
else { // is either (1) a name or (2) an ncr (hex/dec)
|
||||
Xop_amp_trie_itm itm = (Xop_amp_trie_itm)o;
|
||||
int match_pos = amp_trie.Match_pos();
|
||||
int itm_tid = itm.Tid();
|
||||
switch (itm_tid) {
|
||||
case Xop_amp_trie_itm.Tid_name_std:
|
||||
case Xop_amp_trie_itm.Tid_name_xowa: // name
|
||||
bfr.Add_mid(src, i, match_pos); // embed entire name
|
||||
i = match_pos - 1;
|
||||
break;
|
||||
case Xop_amp_trie_itm.Tid_num_dec:
|
||||
case Xop_amp_trie_itm.Tid_num_hex: // ncr: dec/hex
|
||||
boolean pass = amp_mgr.Parse_as_int(itm_tid == Xop_amp_trie_itm.Tid_num_hex, src, end, i, match_pos);
|
||||
int end_pos = amp_mgr.Rslt_pos();
|
||||
if (pass) { // parse worked; embed entire ncr
|
||||
bfr.Add_mid(src, i, end_pos);
|
||||
i = end_pos - 1;
|
||||
}
|
||||
else // parse failed; escape and continue
|
||||
bfr.Add(Html_entity_.Amp_bry);
|
||||
break;
|
||||
default: throw Err_.new_unhandled(itm_tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bfr.Add(Html_entity_.Amp_bry);
|
||||
break;
|
||||
case Byte_ascii.Quote:
|
||||
bfr.Add(Html_entity_.Quote_bry);
|
||||
break;
|
||||
default:
|
||||
bfr.Add_byte(b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static int Escape_nowiki_skip(Bry_bfr bfr, byte[] src, int bgn, int end, byte[] nowiki_name, int nowiki_name_len) {
|
||||
try {
|
||||
boolean tag_is_bgn = true;
|
||||
int bgn_gt = -1, end_lt = -1, end_gt = -1;
|
||||
for (int i = bgn + nowiki_name_len; i < end; i++) {
|
||||
byte b = src[i];
|
||||
switch (b) {
|
||||
case Byte_ascii.Gt:
|
||||
if (tag_is_bgn) {bgn_gt = i; tag_is_bgn = false;}
|
||||
else return Bry_.NotFound; // <nowiki>> found
|
||||
break;
|
||||
case Byte_ascii.Lt:
|
||||
if ( tag_is_bgn // <nowiki < found
|
||||
|| (i + nowiki_name_len + 2 > end) // not enough chars for "/nowiki>"
|
||||
|| src[i + 1] != Byte_ascii.Slash // /
|
||||
|| !Bry_.Eq(src, i + 2, i + 2 + nowiki_name_len, nowiki_name) // nowiki
|
||||
|| src[i + 2 + nowiki_name_len] != Byte_ascii.Gt // >
|
||||
) return Bry_.NotFound;
|
||||
end_lt = i;
|
||||
end_gt = i + 2 + nowiki_name_len;
|
||||
i = end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end_gt == -1) return Bry_.NotFound; // ">" of </nowiki> not found
|
||||
bfr.Add_mid(src, bgn_gt + 1, end_lt);
|
||||
return end_gt;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "unknown error in escape.nowiki: ~{0} ~{1}", String_.new_u8(src, bgn, end), Err_.Message_gplx_full(e));
|
||||
return Bry_.NotFound;
|
||||
}
|
||||
}
|
||||
}
|
||||
357
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr_tst.java
Normal file
357
400_xowa/src/gplx/xowa/htmls/Xoh_html_wtr_tst.java
Normal file
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_html_wtr_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_(); fxt.Reset();}
|
||||
@Test public void Hr_basic() {fxt.Test_parse_page_wiki_str("----" , "<hr/>");}
|
||||
@Test public void Hr_extended() {fxt.Test_parse_page_wiki_str("--------" , "<hr/>");}
|
||||
@Test public void Lnki_basic() {fxt.Test_parse_page_wiki_str("[[a]]" , "<a href=\"/wiki/A\">a</a>");}
|
||||
@Test public void Lnki_caption() {fxt.Test_parse_page_wiki_str("[[a|b]]" , "<a href=\"/wiki/A\">b</a>");}
|
||||
@Test public void Lnki_caption_fmt() {fxt.Test_parse_page_wiki_str("[[a|''b'']]" , "<a href=\"/wiki/A\"><i>b</i></a>");}
|
||||
@Test public void Lnki_tail_trg() {fxt.Test_parse_page_wiki_str("[[a]]b" , "<a href=\"/wiki/A\">ab</a>");}
|
||||
@Test public void Lnki_tail_caption() {fxt.Test_parse_page_wiki_str("[[a|b]]c" , "<a href=\"/wiki/A\">bc</a>");}
|
||||
@Test public void Lnki_title() {
|
||||
fxt.Wtr_cfg().Lnki__title_(true);
|
||||
fxt.Test_parse_page_wiki_str("[[a|b]]", "<a href=\"/wiki/A\" title=\"A\">b</a>");
|
||||
fxt.Wtr_cfg().Lnki__title_(false);
|
||||
}
|
||||
@Test public void Lnki_title_page_text() {
|
||||
fxt.Wtr_cfg().Lnki__title_(true);
|
||||
fxt.Test_parse_page_wiki_str("[[a_b]]", "<a href=\"/wiki/A_b\" title=\"A b\">a_b</a>");
|
||||
fxt.Wtr_cfg().Lnki__title_(false);
|
||||
}
|
||||
@Test public void Lnki_category() {fxt.Test_parse_page_wiki_str("[[Category:A]]" , "");} // NOTE: Category does not get written in main page bfr
|
||||
@Test public void Lnki_category_force() {fxt.Test_parse_page_wiki_str("[[:Category:A]]" , "<a href=\"/wiki/Category:A\">Category:A</a>");}
|
||||
@Test public void Lnki_matches_page() {fxt.Test_parse_page_wiki_str("[[test page|t1]]", "<b>t1</b>");} // NOTE: "Test page" is hardcoded to be the test page name
|
||||
@Test public void Lnki_matches_page_but_has_anchor() {fxt.Test_parse_page_wiki_str("[[Test page#a|test 1]]", "<a href=\"/wiki/Test_page#a\">test 1</a>");} // NOTE: "Test page" is hardcoded to be the test page name
|
||||
@Test public void Lnki_anchor() {fxt.Test_parse_page_wiki_str("[[A#b]]" , "<a href=\"/wiki/A#b\">A#b</a>");}
|
||||
// @Test public void Img_invalid_wnt_char() {
|
||||
// fxt.Test_parse_page_wiki_str
|
||||
// ( "[[File:A*b.png]]"
|
||||
// , "<div class=\"floatnone\"><a href=\"File:A.png\" class=\"image\"><img alt=\"\" src=\"\" width=\"20\" height=\"30\" /></a></div>"
|
||||
// );
|
||||
// }
|
||||
// @Test public void Img_alt() { // FUTURE: enable; WHEN: after fixing xnde to handle bad xnde; EX: France
|
||||
// fxt.Test_parse_page_wiki_str("[[File:A.png|none|9x8px|alt=a<b>b</b>\"c\"d]]", Xop_fxt.html_img_none("File:A.png", "ab"c"d"));
|
||||
// }
|
||||
@Test public void Url_encode() {fxt.Test_parse_page_wiki_str("[[a;@$!*(),/ _^b|z]]" , "<a href=\"/wiki/A;@$!*(),/_%5Eb\">z</a>");} // NOTE: was "a" instead of "A"; "__" instead of "_" DATE:2014-09-07
|
||||
@Test public void Url_encode_space() {fxt.Test_parse_page_wiki_str("[[a _b|z]]" , "<a href=\"/wiki/A_b\">z</a>");}
|
||||
@Test public void Apos_i() {fxt.Test_parse_page_wiki_str("''a''" , "<i>a</i>");}
|
||||
@Test public void Apos_b() {fxt.Test_parse_page_wiki_str("'''a'''" , "<b>a</b>");}
|
||||
@Test public void Apos_ib() {fxt.Test_parse_page_wiki_str("'''''a'''''" , "<i><b>a</b></i>");}
|
||||
@Test public void Html_ent() {fxt.Test_parse_page_wiki_str("!" , "!");} // PURPOSE:ncrs should be literal, not decoded (!); DATE:2014-11-06
|
||||
@Test public void Html_ref() {fxt.Test_parse_page_wiki_str(">" , ">");}
|
||||
@Test public void List_1_itm() {
|
||||
fxt.Test_parse_page_wiki_str("*a", String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li>a"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
@Test public void List_2_itms() {
|
||||
fxt.Test_parse_page_wiki_str("*a\n*b", String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li>a"
|
||||
, " </li>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
@Test public void List_nest_ul() {
|
||||
fxt.Test_parse_page_wiki_str("*a\n**b", String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li>a"
|
||||
, " <ul>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
@Test public void List_dt_dd() {
|
||||
fxt.Test_parse_page_wiki_str(";a:b", String_.Concat_lines_nl_skip_last
|
||||
( "<dl>"
|
||||
, " <dt>a"
|
||||
, " </dt>"
|
||||
, " <dd>b"
|
||||
, " </dd>"
|
||||
, "</dl>"
|
||||
));
|
||||
}
|
||||
@Test public void List_dd_nest2() {
|
||||
fxt.Test_parse_page_wiki_str("::a", String_.Concat_lines_nl_skip_last
|
||||
( "<dl>"
|
||||
, " <dd>"
|
||||
, " <dl>"
|
||||
, " <dd>a"
|
||||
, " </dd>"
|
||||
, " </dl>"
|
||||
, " </dd>"
|
||||
, "</dl>"
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_basic() {
|
||||
fxt.Test_parse_page_wiki_str("{|\n|+a\n!b||c\n|-\n|d||e\n|}", String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <caption>a"
|
||||
, " </caption>"
|
||||
, " <tr>"
|
||||
, " <th>b"
|
||||
, " </th>"
|
||||
, " <th>c"
|
||||
, " </th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>d"
|
||||
, " </td>"
|
||||
, " <td>e"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_atrs() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "{|style='z'"
|
||||
, "|+a"
|
||||
, "!style='y'|b||style='x'|c"
|
||||
, "|-style='w'"
|
||||
, "|style='v'|d||style='u'|e"
|
||||
, "|}"
|
||||
), String_.Concat_lines_nl
|
||||
( "<table style='z'>"
|
||||
, " <caption>a"
|
||||
, " </caption>"
|
||||
, " <tr>"
|
||||
, " <th style='y'>b"
|
||||
, " </th>"
|
||||
, " <th style='x'>c"
|
||||
, " </th>"
|
||||
, " </tr>"
|
||||
, " <tr style='w'>"
|
||||
, " <td style='v'>d"
|
||||
, " </td>"
|
||||
, " <td style='u'>e"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
));
|
||||
}
|
||||
@Test public void Para_hdr_list() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "==a=="
|
||||
, ""
|
||||
, "*b"
|
||||
, "*c"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>a</h2>"
|
||||
, ""
|
||||
, "<ul>"
|
||||
, " <li>b"
|
||||
, " </li>"
|
||||
, " <li>c"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Para_nl_is_space() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, "b"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p>a"
|
||||
, "b"
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Para_nl_2_2() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "a"
|
||||
, ""
|
||||
, "b"
|
||||
, ""
|
||||
, "c"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<p>a"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p>b"
|
||||
, "</p>"
|
||||
, ""
|
||||
, "<p>c"
|
||||
, "</p>"
|
||||
, ""
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Div_2() { // WP:[[Air]]#Density of air
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
|
||||
( "<div>a</div>"
|
||||
, ""
|
||||
, "<div>b</div>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<div>a</div>"
|
||||
, "<div>b</div>"
|
||||
));
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Tblw() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "|a"
|
||||
, "|b"
|
||||
, "|-"
|
||||
, "|c"
|
||||
, "|d"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>a"
|
||||
, " </td>"
|
||||
, " <td>b"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>c"
|
||||
, " </td>"
|
||||
, " <td>d"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_lnki_bang() {
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "|[[a|!]]"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td><a href=\"/wiki/A\">!</a>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tr_inside_tblw_td() { // WP:[[Earth]]
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, "<tr><td>a</td></tr>"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>a"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Tblw_tr_with_newlines() {// WP:[[John Adams]] Infobox Officeholder
|
||||
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl
|
||||
( "{|"
|
||||
, "|-"
|
||||
, ""
|
||||
, ""
|
||||
, ""
|
||||
, "|a"
|
||||
, "|}"
|
||||
)
|
||||
, String_.Concat_lines_nl
|
||||
( "<table>"
|
||||
, " <tr>"
|
||||
, " <td>a"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Bang_doesnt_force_tbl() {
|
||||
fxt.Init_para_y_();
|
||||
fxt.Test_parse_page_wiki_str("a! b! c", "<p>a! b! c\n</p>\n");
|
||||
fxt.Init_para_n_();
|
||||
}
|
||||
@Test public void Err_nlOnly() {
|
||||
fxt.Test_parse_page_wiki_str("{{\n}}", "{{\n}}"); // NOTE: was {{}}
|
||||
}
|
||||
@Test public void Xnde_inline() {
|
||||
fxt.Test_parse_page_wiki_str("<div/>", "<div></div>");
|
||||
}
|
||||
@Test public void Xnde_id_encode() { // PURPOSE: id should be url-encoded; DATE: 2013-11-13;
|
||||
fxt.Test_parse_page_wiki_str("<div id='a*'></div>", "<div id='a.2A'></div>");
|
||||
fxt.Test_parse_page_wiki_str("<div id='a b'></div>", "<div id='a_b'></div>");
|
||||
}
|
||||
@Test public void Math() {
|
||||
fxt.App().File_mgr().Math_mgr().Renderer_is_mathjax_(false);
|
||||
fxt.Test_parse_page_all_str("<math>x + y</math>", "<img id='xowa_math_img_0' src='' width='' height=''/><span id='xowa_math_txt_0'>x + y</span>"); // latex has img
|
||||
fxt.App().File_mgr().Math_mgr().Renderer_is_mathjax_(true);
|
||||
fxt.Test_parse_page_all_str("<math>x + y</math>", "<span id='xowa_math_txt_0'>x + y</span>"); // mathjax has no img
|
||||
fxt.App().File_mgr().Math_mgr().Renderer_is_mathjax_(false);
|
||||
}
|
||||
@Test public void Timeline() {// PURPOSE: embed timeline contents in pre; DATE:2014-05-22
|
||||
fxt.Test_parse_page_wiki_str("<timeline>a</timeline>", "<pre class='xowa-timeline'>a</pre>");
|
||||
}
|
||||
@Test public void Amp_ncr_should_not_be_rendered_as_bytes() { // PURPOSE:   should be rendered as   not as literal bytes {192,160}; DATE:2013-12-09
|
||||
fxt.Test_parse_page_wiki_str("a b", "a b");
|
||||
}
|
||||
|
||||
// @Test public void Fix_PositionAbsolute_stripped() {
|
||||
// fxt.Test_parse_page_wiki_str("<span style=\"position:absolute;\"></span>", "<span style=\";\"></span>");
|
||||
// }
|
||||
// @Test public void Xnde_nl() {
|
||||
// fxt.Test_parse_page_wiki_str("<div id='a'\nclass='b'>c</div>", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div id='a' class='b'>c</div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void Tblw() {
|
||||
// fxt.Test_parse_page_wiki_str("{|\n|}", String_.Concat_lines_nl
|
||||
// ( "<table>"
|
||||
// , " <tr>"
|
||||
// , " <td>a"
|
||||
// , " </td>"
|
||||
// , " <td>b"
|
||||
// , " </td>"
|
||||
// , " </tr>"
|
||||
// , "</table>"
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
36
400_xowa/src/gplx/xowa/htmls/Xoh_imgs_mgr.java
Normal file
36
400_xowa/src/gplx/xowa/htmls/Xoh_imgs_mgr.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoh_imgs_mgr implements GfoInvkAble {
|
||||
public Xoh_imgs_mgr(Xow_html_mgr html_mgr) {wiki_is_default = html_mgr.Wiki().Domain_tid() == Xow_domain_tid_.Int__home;} private boolean wiki_is_default;
|
||||
public Bool_obj_ref Alt_in_caption() {return alt_in_caption;} Bool_obj_ref alt_in_caption = Bool_obj_ref.y_();
|
||||
public Bool_obj_ref Alt_defaults_to_caption() {return alt_defaults_to_caption;} Bool_obj_ref alt_defaults_to_caption = Bool_obj_ref.y_();
|
||||
public void Copy_cfg(Xoh_imgs_mgr copy) {this.alt_in_caption = copy.alt_in_caption;}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_alt_in_caption)) return Yn.To_str(alt_in_caption.Val());
|
||||
else if (ctx.Match(k, Invk_alt_in_caption_)) alt_in_caption = Modify(wiki_is_default, alt_in_caption, m.ReadYn("v"));
|
||||
else if (ctx.Match(k, Invk_alt_defaults_to_caption)) return Yn.To_str(alt_defaults_to_caption.Val());
|
||||
else if (ctx.Match(k, Invk_alt_defaults_to_caption_)) alt_defaults_to_caption = Modify(wiki_is_default, alt_defaults_to_caption, m.ReadYn("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_alt_in_caption = "alt_in_caption", Invk_alt_in_caption_ = "alt_in_caption_", Invk_alt_defaults_to_caption = "alt_defaults_to_caption", Invk_alt_defaults_to_caption_ = "alt_defaults_to_caption_";
|
||||
private static Bool_obj_ref Modify(boolean orig, Bool_obj_ref cur, boolean v) {return orig ? cur.Val_(v) : Bool_obj_ref.new_(v);}
|
||||
}
|
||||
59
400_xowa/src/gplx/xowa/htmls/Xoh_page_mgr.java
Normal file
59
400_xowa/src/gplx/xowa/htmls/Xoh_page_mgr.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.htmls.portal.*;
|
||||
public class Xoh_page_mgr implements GfoInvkAble {
|
||||
public Xoh_subpages_bldr Subpages_bldr() {return subpages_bldr;} private final Xoh_subpages_bldr subpages_bldr = new Xoh_subpages_bldr();
|
||||
public boolean Font_enabled() {return font_enabled;} private boolean font_enabled = false;
|
||||
public void Font_enabled_(boolean v) {font_enabled = v;}
|
||||
public String Font_name() {return font_name;} private String font_name = "Arial";
|
||||
public float Font_size() {return font_size;} private float font_size = Font_size_default;
|
||||
public void Font_size_(float v) {
|
||||
font_size = v;
|
||||
this.Font_css_bry_update();
|
||||
}
|
||||
public Bry_fmtr Font_css_fmtr() {return font_css_fmtr;} private final Bry_fmtr font_css_fmtr = Bry_fmtr.new_("body {font-family: ~{font_name}; font-size: ~{font_size}px;}", "font_name", "font_size");
|
||||
public Bry_fmtr Content_code_fmtr() {return content_code_fmtr;} private final Bry_fmtr content_code_fmtr = Bry_fmtr.new_("<pre>~{page_text}</pre>", "page_text");
|
||||
private void Font_css_fmtr_(byte[] bry) {
|
||||
font_css_fmtr.Fmt_(bry);
|
||||
Font_css_bry_update();
|
||||
}
|
||||
public byte[] Font_css_bry() {return font_css_bry;}
|
||||
public void Font_css_bry_update() {
|
||||
font_css_bry = font_css_fmtr.Bld_bry_many(Bry_bfr.new_(), font_name, font_size);
|
||||
} private byte[] font_css_bry = Bry_.Empty;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_font_name)) return font_name;
|
||||
else if (ctx.Match(k, Invk_font_name_)) {font_name = m.ReadStr("v"); this.Font_css_bry_update();}
|
||||
else if (ctx.Match(k, Invk_font_size)) return font_size;
|
||||
else if (ctx.Match(k, Invk_font_size_)) {font_size = m.ReadFloat("v"); this.Font_css_bry_update();}
|
||||
else if (ctx.Match(k, Invk_font_css_fmt)) return String_.new_u8(font_css_fmtr.Fmt());
|
||||
else if (ctx.Match(k, Invk_font_css_fmt_)) Font_css_fmtr_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_font_enabled)) return Yn.To_str(font_enabled);
|
||||
else if (ctx.Match(k, Invk_font_enabled_)) font_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_content_code_fmt)) return String_.new_u8(content_code_fmtr.Fmt());
|
||||
else if (ctx.Match(k, Invk_content_code_fmt_)) content_code_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_font_name = "font_name", Invk_font_name_ = "font_name_", Invk_font_size = "font_size", Invk_font_size_ = "font_size_"
|
||||
, Invk_font_css_fmt = "font_css_fmt", Invk_font_css_fmt_ = "font_css_fmt_", Invk_font_enabled = "font_enabled", Invk_font_enabled_ = "font_enabled_"
|
||||
, Invk_content_code_fmt = "content_code_fmt", Invk_content_code_fmt_ = "content_code_fmt_"
|
||||
;
|
||||
public static final float Font_size_default = 16;
|
||||
}
|
||||
101
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr.java
Normal file
101
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_page_wtr_mgr implements GfoInvkAble {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private Xoh_page_wtr_wkr edit_wtr, html_wtr, read_wtr;
|
||||
public Xoh_page_wtr_mgr(boolean html_capable) {
|
||||
this.html_capable = html_capable;
|
||||
this.read_wtr = new Xoh_page_wtr_wkr(this, Xopg_page_.Tid_read);
|
||||
this.edit_wtr = new Xoh_page_wtr_wkr(this, Xopg_page_.Tid_edit);
|
||||
this.html_wtr = new Xoh_page_wtr_wkr(this, Xopg_page_.Tid_html);
|
||||
}
|
||||
public boolean Html_capable() {return html_capable;} public Xoh_page_wtr_mgr Html_capable_(boolean v) {html_capable = v; return this;} private boolean html_capable;
|
||||
public byte[] Css_common_bry() {return css_common_bry;} private byte[] css_common_bry;
|
||||
public byte[] Css_wiki_bry() {return css_wiki_bry;} private byte[] css_wiki_bry;
|
||||
public Bry_fmtr Page_read_fmtr() {return page_read_fmtr;} private Bry_fmtr page_read_fmtr = Bry_fmtr.new_("", Fmtr_keys);
|
||||
public Bry_fmtr Page_edit_fmtr() {return page_edit_fmtr;} private Bry_fmtr page_edit_fmtr = Bry_fmtr.new_("", Fmtr_keys);
|
||||
public Bry_fmtr Page_html_fmtr() {return page_html_fmtr;} private Bry_fmtr page_html_fmtr = Bry_fmtr.new_("", Fmtr_keys);
|
||||
public byte[] Edit_rename_div_bry(Xoa_ttl ttl) {return div_edit_rename_fmtr.Bld_bry_many(tmp_bfr, ttl.Full_db());}
|
||||
public void Init_css_urls(Io_url css_common_url, Io_url css_wiki_url) {
|
||||
this.css_common_bry = css_common_url.To_http_file_bry();
|
||||
this.css_wiki_bry = css_wiki_url.To_http_file_bry();
|
||||
}
|
||||
public void Init_(boolean v) {init = v;} private boolean init = true;
|
||||
public byte[] Gen(Xoae_page page, byte output_tid) {
|
||||
Xoh_page_wtr_wkr wtr = Wkr(output_tid);
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
if (init) {
|
||||
init = false;
|
||||
page_read_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
page_edit_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
page_html_fmtr.Eval_mgr_(wiki.Eval_mgr());
|
||||
}
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001();
|
||||
byte[] bry = wtr.Write_page(page, wiki.Parser_mgr().Ctx(), tmp_bfr);
|
||||
tmp_bfr.Mkr_rls();
|
||||
return bry;
|
||||
}
|
||||
public Xoh_page_wtr_wkr Wkr(byte output_tid) {
|
||||
switch (output_tid) {
|
||||
case Xopg_page_.Tid_edit: return edit_wtr;
|
||||
case Xopg_page_.Tid_html: return html_wtr;
|
||||
case Xopg_page_.Tid_read: return read_wtr;
|
||||
default: throw Err_.new_unhandled(output_tid);
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_page_read_)) page_read_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_page_edit_)) page_edit_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_page_html_)) page_html_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_xowa_div_edit_rename_)) div_edit_rename_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private Bry_fmtr div_edit_rename_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( " <input id='xowa_edit_rename_box' width='120' height='20' />"
|
||||
, " <a href='xowa-cmd:app.gui.main_win.page_edit_rename;' class='xowa_anchor_button' style='width:100px;max-width:1024px;'>"
|
||||
, " Rename page"
|
||||
, " </a>"
|
||||
, " <a href='/wiki/Special:MovePage?wpOldTitle=~{src_full_db}' class='xowa_anchor_button' style='width:100px;max-width:1024px;'>"
|
||||
, " Special:MovePage"
|
||||
, " </a>"
|
||||
), "src_full_db");
|
||||
public static final String Invk_page_read_ = "page_read_", Invk_page_edit_ = "page_edit_", Invk_page_html_ = "page_html_", Invk_xowa_div_edit_rename_ = "xowa_div_edit_rename_";
|
||||
private static final String[] Fmtr_keys = new String[]
|
||||
{ "app_root_dir", "app_version", "app_build_date", "xowa_mode_is_server"
|
||||
, "page_id", "page_name", "page_title", "page_modified_on_msg"
|
||||
, "html_css_common_path", "html_css_wiki_path", "xowa_head"
|
||||
, "page_lang_ltr", "page_indicators", "page_content_sub", "page_jumpto", "page_body_cls", "html_content_editable"
|
||||
, "page_data", "page_langs"
|
||||
, "portal_div_personal", "portal_div_ns", "portal_div_view"
|
||||
, "portal_div_logo", "portal_div_home", "portal_div_xtn"
|
||||
, "portal_div_wikis", "portal_sidebar"
|
||||
, "edit_div_rename", "edit_div_preview", "js_edit_toolbar"
|
||||
};
|
||||
}
|
||||
/*
|
||||
NOTE_1:xowa_anchor_button
|
||||
. used for media (WP forces javascript with oggplayer. wanted "simpler" model)
|
||||
. display:inline-block; must be set for centering to work; see USSR and anthem; (display:block; must be enabled in order for padding to work)
|
||||
. text-align:center; forces img to be in center
|
||||
|
||||
General notes:
|
||||
. contentSub div is needed; PAGE:en.w:Battle of Spotsylvania Court House
|
||||
*/
|
||||
33
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java
Normal file
33
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_mgr_tst.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.portal.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_page_wtr_mgr_tst {
|
||||
@Before public void init() {}
|
||||
@Test public void Logo_has_correct_main_page() { // PURPOSE: Logo href should be "/site/en.wikipedia.org/wiki/", not "/wiki/Main_Page"
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr();
|
||||
GfoInvkAble_.InvkCmd_val(portal_mgr, Xow_portal_mgr.Invk_div_logo_, Bry_.new_a7("~{portal_nav_main_href}"));
|
||||
portal_mgr.Init_assert();
|
||||
Xoh_page_wtr_mgr page_wtr_mgr = new Xoh_page_wtr_mgr(true);
|
||||
page_wtr_mgr.Gen(wiki.Parser_mgr().Ctx().Cur_page(), Xopg_page_.Tid_read);
|
||||
Tfds.Eq(String_.new_a7(portal_mgr.Div_logo_bry()), "/site/en.wikipedia.org/wiki/");
|
||||
}
|
||||
}
|
||||
196
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java
Normal file
196
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.langs.htmls.*; import gplx.xowa.langs.vnts.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.parsers.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.apps.gfs.*; import gplx.xowa.htmls.portal.*;
|
||||
public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
|
||||
private final Xoh_page_wtr_mgr mgr; private final byte page_mode;
|
||||
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr(); // In other languages
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xop_ctx ctx; private Xoae_page page; private byte[] root_dir_bry;
|
||||
public Xoh_page_wtr_wkr(Xoh_page_wtr_mgr mgr, byte page_mode) {this.mgr = mgr; this.page_mode = page_mode;}
|
||||
public Xoh_page_wtr_wkr Ctgs_enabled_(boolean v) {ctgs_enabled = v; return this;} private boolean ctgs_enabled = true;
|
||||
public byte[] Write_page(Xoae_page page, Xop_ctx ctx, Bry_bfr bfr) {
|
||||
synchronized (thread_lock_1) {
|
||||
this.page = page; this.ctx = ctx; this.wiki = page.Wikie(); this.app = wiki.Appe();
|
||||
ctx.Cur_page_(page); // HACK: must update page for toc_mgr; WHEN: Xoae_page rewrite
|
||||
Bry_fmtr fmtr = null;
|
||||
if (mgr.Html_capable()) {
|
||||
wdata_lang_wtr.Page_(page);
|
||||
byte view_mode = page_mode;
|
||||
switch (page_mode) {
|
||||
case Xopg_page_.Tid_edit: fmtr = mgr.Page_edit_fmtr(); break;
|
||||
case Xopg_page_.Tid_html: fmtr = mgr.Page_read_fmtr(); view_mode = Xopg_page_.Tid_read; break; // set view_mode to read, so that "read" is highlighted in HTML
|
||||
case Xopg_page_.Tid_read: fmtr = mgr.Page_read_fmtr();
|
||||
ctx.Cur_page().Redlink_lnki_list().Clear(); // not sure if this is the best place to put it, but redlinks (a) must only fire once; (b) must fire before html generation; (c) cannot fire during edit (preview will handle separately)
|
||||
break;
|
||||
}
|
||||
Bry_bfr page_bfr = Xoa_app_.Utl__bfr_mkr().Get_m001(); // NOTE: get separate page bfr to output page; do not reuse tmp_bfr b/c it will be used inside Fmt_do
|
||||
Fmt__do(page_bfr);
|
||||
Write_page_by_tid(view_mode, bfr, fmtr, page_bfr.To_bry_and_rls());
|
||||
if (page_mode == Xopg_page_.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(bfr.To_bry_and_clear()));
|
||||
wdata_lang_wtr.Page_(null);
|
||||
}
|
||||
else
|
||||
Fmt__do(bfr);
|
||||
this.page = null;
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
private void Write_page_by_tid(byte html_gen_tid, Bry_bfr bfr, Bry_fmtr fmtr, byte[] page_data) {
|
||||
// if custom_html, use it and exit; needed for Default_tab
|
||||
byte[] custom_html = page.Html_data().Custom_html();
|
||||
if (custom_html != null) {bfr.Add(custom_html); return;}
|
||||
|
||||
// temp variables
|
||||
if (root_dir_bry == null) this.root_dir_bry = app.Fsys_mgr().Root_dir().To_http_file_bry();
|
||||
Xoa_ttl page_ttl = page.Ttl(); int page_ns_id = page_ttl.Ns().Id();
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), page_ns_id, page_ttl.Page_db());
|
||||
DateAdp modified_on = page.Revision_data().Modified_on();
|
||||
byte[] modified_on_msg = wiki.Msg_mgr().Val_by_id_args(Xol_msg_itm_.Id_portal_lastmodified, modified_on.XtoStr_fmt_yyyy_MM_dd(), modified_on.XtoStr_fmt_HHmm());
|
||||
byte[] page_body_class = Xoh_page_body_cls.Calc(tmp_bfr, page_ttl, page_tid);
|
||||
byte[] html_content_editable = wiki.Gui_mgr().Cfg_browser().Content_editable() ? Content_editable_bry : Bry_.Empty;
|
||||
byte[] page_content_sub = Xoh_page_wtr_wkr_.Bld_page_content_sub(app, wiki, page, tmp_bfr);
|
||||
byte[] js_edit_toolbar_bry = html_gen_tid == Xopg_page_.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty;
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) {
|
||||
byte[] converted_title = vnt_mgr.Convert_lang().Converted_title(); // prefer converted title
|
||||
if (converted_title == null) // converted title does not exist; use regular page title and convert it
|
||||
converted_title = vnt_mgr.Convert_lang().Auto_convert(vnt_mgr.Cur_itm(), page_ttl.Page_txt());
|
||||
page_ttl = Xoa_ttl.parse(wiki, page_ttl.Ns().Id(), converted_title);
|
||||
}
|
||||
byte[] page_name = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null); // NOTE: page_name does not show display_title (<i>). always pass in null
|
||||
byte[] page_display = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl());
|
||||
page.Html_data().Custom_tab_name_(page_name); // set tab_name to page_name; note that if null, gui code will ignore and use Ttl.Page_txt; PAGE: zh.w:釣魚臺列嶼主權問題 DATE:2015-10-05
|
||||
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
|
||||
fmtr.Bld_bfr_many(bfr
|
||||
, root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str()
|
||||
, page.Revision_data().Id()
|
||||
, page_name, page_display
|
||||
, modified_on_msg
|
||||
, mgr.Css_common_bry(), mgr.Css_wiki_bry(), page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts()
|
||||
, page.Lang().Dir_ltr_bry(), page.Html_data().Indicators(), page_content_sub, wiki.Html_mgr().Portal_mgr().Div_jump_to(), page_body_class, html_content_editable
|
||||
, page_data, wdata_lang_wtr
|
||||
, portal_mgr.Div_personal_bry(), portal_mgr.Div_ns_bry(app.Utl__bfr_mkr(), page_ttl, wiki.Ns_mgr()), portal_mgr.Div_view_bry(app.Utl__bfr_mkr(), html_gen_tid, page.Html_data().Xtn_search_text())
|
||||
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar), portal_mgr.Div_wikis_bry(app.Utl__bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry()
|
||||
, mgr.Edit_rename_div_bry(page_ttl), page.Html_data().Edit_preview_w_dbg(), js_edit_toolbar_bry
|
||||
);
|
||||
Xoh_page_wtr_wkr_.Bld_head_end(bfr, page); // add after </head>
|
||||
Xoh_page_wtr_wkr_.Bld_html_end(bfr, page); // add after </html>
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {Write_body(bfr, Xoh_wtr_ctx.Basic, page);}
|
||||
public void Write_body(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xoae_page page) {
|
||||
synchronized (thread_lock_2) {
|
||||
this.page = page; this.wiki = page.Wikie(); this.app = wiki.Appe();
|
||||
Xoa_ttl page_ttl = page.Ttl(); int page_ns_id = page_ttl.Ns().Id();
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), page_ns_id, page_ttl.Page_db()); // NOTE: can't cache page_tid b/c Write_body is called directly; DATE:2014-10-02
|
||||
byte[] data_raw = page.Data_raw();
|
||||
int bfr_page_bgn = bfr.Len();
|
||||
boolean page_tid_uses_pre = false;
|
||||
if (page_mode == Xopg_page_.Tid_edit)
|
||||
Write_body_edit(bfr, data_raw, page_ns_id, page_tid);
|
||||
else {
|
||||
switch (page_tid) {
|
||||
case Xow_page_tid.Tid_js:
|
||||
case Xow_page_tid.Tid_css:
|
||||
case Xow_page_tid.Tid_lua: Write_body_pre (bfr, app, wiki, data_raw, tmp_bfr); page_tid_uses_pre = true; break;
|
||||
case Xow_page_tid.Tid_json: app.Wiki_mgr().Wdata_mgr().Write_json_as_html(bfr, page_ttl.Page_db(), data_raw); break;
|
||||
case Xow_page_tid.Tid_wikitext: Write_body_wikitext (bfr, app, wiki, data_raw, hctx, page, page_tid, page_ns_id); break;
|
||||
}
|
||||
}
|
||||
if ( wiki.Domain_tid() != Xow_domain_tid_.Int__home // allow home wiki to use javascript
|
||||
&& !page_tid_uses_pre) { // if .js, .css or .lua, skip test; may have js fragments, but entire text is escaped and put in pre; don't show spurious warning; DATE:2013-11-21
|
||||
app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page_ttl, bfr, bfr_page_bgn);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Write_body_wikitext(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, byte[] data_raw, Xoh_wtr_ctx hctx, Xoae_page page, byte page_tid, int ns_id) {
|
||||
// dump and exit if pre-generated html from html dumps
|
||||
byte[] hdump_data = page.Hdump_data().Body();
|
||||
if (Bry_.Len_gt_0(hdump_data)) {
|
||||
bfr.Add(hdump_data);
|
||||
return;
|
||||
}
|
||||
|
||||
// dump and exit if MediaWiki message;
|
||||
if (ns_id == Xow_ns_.Id_mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
bfr.Add(Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw));
|
||||
return;
|
||||
}
|
||||
|
||||
// if [[File]], add boilerplate header; note that html is XOWA-generated so does not need to be tidied
|
||||
if (ns_id == Xow_ns_.Id_file) app.Ns_file_page_mgr().Bld_html(wiki, ctx, page, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
|
||||
|
||||
// get separate bfr; note that bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
|
||||
Bry_bfr tidy_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
|
||||
// write wikitext
|
||||
if (page.Root() != null) // NOTE: will be null if blank; occurs for one test: Logo_has_correct_main_page; DATE:2015-09-29
|
||||
wiki.Html_mgr().Html_wtr().Write_all(tidy_bfr, page.Wikie().Parser_mgr().Ctx(), hctx, page.Root().Data_mid(), page.Root());
|
||||
|
||||
// if [[Category]], render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
|
||||
if (ns_id == Xow_ns_.Id_category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, tidy_bfr);
|
||||
|
||||
// tidy html
|
||||
gplx.xowa.htmls.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
|
||||
if (tidy_mgr.Enabled()) tidy_mgr.Run_tidy_html(page, tidy_bfr);
|
||||
|
||||
// add back to main bfr
|
||||
bfr.Add_bfr_and_clear(tidy_bfr);
|
||||
tidy_bfr.Mkr_rls();
|
||||
|
||||
// handle Categories at bottom of page; note that html is XOWA-generated so does not need to be tidied
|
||||
int ctgs_len = page.Category_list().length;
|
||||
if ( ctgs_enabled
|
||||
&& ctgs_len > 0
|
||||
&& !wiki.Html_mgr().Importing_ctgs() // do not show categories if importing categories, page will wait for category import to be done; DATE:2014-10-15
|
||||
) {
|
||||
app.Usr_dlg().Prog_many("", "", "loading categories: count=~{0}", ctgs_len);
|
||||
if (app.Ctg_mgr().Pagecats_grouping_enabled())
|
||||
app.Ctg_mgr().Pagectgs_wtr().Write(bfr, wiki, page);
|
||||
else
|
||||
wiki.Html_mgr().Ctg_mgr().Bld(bfr, page, ctgs_len);
|
||||
}
|
||||
|
||||
// translate if variants are enabled
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) bfr.Add(vnt_mgr.Convert_lang().Parse_page(vnt_mgr.Cur_itm(), page.Revision_data().Id(), bfr.To_bry_and_clear()));
|
||||
}
|
||||
private void Write_body_pre(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, byte[] data_raw, Bry_bfr tmp_bfr) {
|
||||
Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, data_raw, 0, data_raw.length, false, false);
|
||||
app.Html_mgr().Page_mgr().Content_code_fmtr().Bld_bfr_many(bfr, tmp_bfr);
|
||||
tmp_bfr.Clear();
|
||||
}
|
||||
private void Write_body_edit(Bry_bfr bfr, byte[] data_raw, int ns_id, byte page_tid) {
|
||||
if ( ns_id == Xow_ns_.Id_mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
&& page_tid == Xow_page_tid.Tid_wikitext
|
||||
)
|
||||
data_raw = Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw);
|
||||
int data_raw_len = data_raw.length;
|
||||
if (mgr.Html_capable())
|
||||
Xoh_html_wtr_escaper.Escape(page.Wikie().Appe().Parser_amp_mgr(), bfr, data_raw, 0, data_raw_len, false, false); // NOTE: must escape; assume that browser will automatically escape (<) (which Mozilla does)
|
||||
else
|
||||
bfr.Add(data_raw);
|
||||
if (data_raw_len > 0) // do not add nl if empty String
|
||||
bfr.Add_byte_nl(); // per MW:EditPage.php: "Ensure there's a newline at the end, otherwise adding lines is awkward."
|
||||
}
|
||||
private static final byte[] Content_editable_bry = Bry_.new_a7(" contenteditable=\"true\"");
|
||||
}
|
||||
58
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_.java
Normal file
58
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.xtns.relatedSites.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Xoh_page_wtr_wkr_ {
|
||||
public static byte[] Bld_page_content_sub(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Bry_bfr tmp_bfr) {
|
||||
byte[] subpages = app.Html_mgr().Page_mgr().Subpages_bldr().Bld(wiki.Ns_mgr(), page.Ttl());
|
||||
byte[] page_content_sub = page.Html_data().Content_sub(); // contentSub exists; SEE: {{#isin}}
|
||||
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page);
|
||||
return Bry_.Add(subpages, page_content_sub, redirect_msg);
|
||||
}
|
||||
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
|
||||
if (display_ttl != null) return display_ttl; // display_ttl explicitly set; use it
|
||||
if (ttl.Ns().Id() == Xow_ns_.Id_special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
|
||||
tmp_bfr.Add(ttl.Ns().Name_txt_w_colon()).Add(ttl.Page_txt_wo_qargs());
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
else
|
||||
return ttl.Full_txt(); // NOTE: include ns with ttl as per defect d88a87b3
|
||||
}
|
||||
public static void Bld_head_end(Bry_bfr html_bfr, Xoae_page page) {
|
||||
byte[] head_end = page.Html_data().Custom_head_end();
|
||||
if (head_end == null) return;
|
||||
int insert_pos = Bry_find_.Find_fwd(html_bfr.Bfr(), Html_tag_.Head_rhs);
|
||||
if (insert_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </head>");
|
||||
return;
|
||||
}
|
||||
html_bfr.Insert_at(insert_pos, head_end);
|
||||
}
|
||||
public static void Bld_html_end(Bry_bfr html_bfr, Xoae_page page) {
|
||||
byte[] html_end = page.Html_data().Custom_html_end();
|
||||
if (html_end == null) return;
|
||||
int insert_pos = Bry_find_.Find_bwd(html_bfr.Bfr(), Html_tag_.Html_rhs, html_bfr.Len());
|
||||
if (insert_pos == Bry_find_.Not_found) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "could not find </html>");
|
||||
return;
|
||||
}
|
||||
html_bfr.Insert_at(insert_pos, html_end);
|
||||
}
|
||||
}
|
||||
75
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java
Normal file
75
400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr_tst.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.wikis.pages.*;
|
||||
public class Xoh_page_wtr_wkr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_page_wtr_fxt fxt = new Xoh_page_wtr_fxt();
|
||||
@Test public void Page_name() {
|
||||
fxt.Test_page_name_by_ttl("Earth", "Earth");
|
||||
fxt.Test_page_name_by_ttl("File:A.png", "File:A.png");
|
||||
fxt.Test_page_name_by_ttl("Special:Search/earth?fulltext=y", "Special:Search/earth");
|
||||
fxt.Test_page_name_by_ttl("Special:Search/earth", "Special:Search/earth");
|
||||
fxt.Test_page_name_by_display("Special:Allpages", "All pages", "All pages");
|
||||
}
|
||||
@Test public void Edit() {
|
||||
fxt.Test_edit("	", "&#9;\n"); // NOTE: cannot by 	 or will show up in edit box as "\t" and save as "\t" instead of 	
|
||||
}
|
||||
@Test public void Css() {
|
||||
fxt.App().Html_mgr().Page_mgr().Content_code_fmtr().Fmt_("<pre style='overflow:auto'>~{page_text}</pre>");
|
||||
fxt.Test_read("MediaWiki:Common.css", ".xowa {}", "<pre style='overflow:auto'>.xowa {}</pre>");
|
||||
fxt.App().Html_mgr().Page_mgr().Content_code_fmtr().Fmt_("<pre>~{page_text}</pre>");
|
||||
}
|
||||
@Test public void Amp_disable() { // PURPOSE: in js documents; " should be rendered as ", not as "; DATE:2013-11-07
|
||||
fxt.Test_read("MediaWiki:Gadget.js", """, "<pre>&quot;</pre>");
|
||||
}
|
||||
}
|
||||
class Xoh_page_wtr_fxt {
|
||||
public void Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
} private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private Xowe_wiki wiki;
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public void Test_page_name_by_display(String ttl, String display, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.parse(wiki, Bry_.new_a7(ttl)), Bry_.new_a7(display))));
|
||||
}
|
||||
public void Test_page_name_by_ttl(String raw, String expd) {
|
||||
Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.parse(wiki, Bry_.new_a7(raw)), null)));
|
||||
}
|
||||
public void Test_edit(String raw, String expd) {
|
||||
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true);
|
||||
Xoae_page page = wiki.Parser_mgr().Ctx().Cur_page();
|
||||
page.Data_raw_(Bry_.new_u8(raw));
|
||||
Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_page_.Tid_edit);
|
||||
wkr.Write_body(tmp_bfr, Xoh_wtr_ctx.Basic, page);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test_read(String page_name, String page_text, String expd) {
|
||||
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true);
|
||||
Xoae_page page = wiki.Parser_mgr().Ctx().Cur_page();
|
||||
page.Ttl_(Xoa_ttl.parse(wiki, Bry_.new_a7(page_name)));
|
||||
page.Data_raw_(Bry_.new_u8(page_text));
|
||||
Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_page_.Tid_read);
|
||||
wkr.Write_body(tmp_bfr, Xoh_wtr_ctx.Basic, page);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
33
400_xowa/src/gplx/xowa/htmls/Xoh_wtr_ctx.java
Normal file
33
400_xowa/src/gplx/xowa/htmls/Xoh_wtr_ctx.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_wtr_ctx {
|
||||
Xoh_wtr_ctx(byte mode) {this.mode = mode;} private byte mode;
|
||||
public boolean Mode_is_alt() {return mode == Mode_alt;}
|
||||
public boolean Mode_is_display_title() {return mode == Mode_display_title;}
|
||||
public boolean Mode_is_popup() {return mode == Mode_popup;}
|
||||
public boolean Mode_is_hdump() {return mode == Mode_hdump;}
|
||||
public static final byte Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4;
|
||||
public static final Xoh_wtr_ctx
|
||||
Basic = new Xoh_wtr_ctx(Mode_basic)
|
||||
, Alt = new Xoh_wtr_ctx(Mode_alt)
|
||||
, Display_title = new Xoh_wtr_ctx(Mode_display_title)
|
||||
, Popup = new Xoh_wtr_ctx(Mode_popup)
|
||||
, Hdump = new Xoh_wtr_ctx(Mode_hdump)
|
||||
;
|
||||
}
|
||||
63
400_xowa/src/gplx/xowa/htmls/Xohp_ctg_grp_mgr.java
Normal file
63
400_xowa/src/gplx/xowa/htmls/Xohp_ctg_grp_mgr.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xohp_ctg_grp_mgr {
|
||||
final Bry_fmtr grp_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, " <div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, " ~{grp_lbl}"
|
||||
, " <ul>~{grp_itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
), "grp_lbl", "grp_itms")
|
||||
;
|
||||
final Bry_fmtr itm_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <li>"
|
||||
, " <a href=\"~{itm_href}\" class=\"internal\" title=\"~{itm_title}\">~{itm_text}</a>"
|
||||
, " </li>"
|
||||
), "itm_href", "itm_title", "itm_text"
|
||||
);
|
||||
Xoh_ctg_itm_fmtr itm_mgr = new Xoh_ctg_itm_fmtr();
|
||||
public void Bld(Bry_bfr bfr, Xoae_page page, int ctgs_len) {
|
||||
byte[] categories_lbl = page.Wikie().Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ctg_tbl_hdr);
|
||||
itm_mgr.Set(page, itm_fmtr);
|
||||
grp_fmtr.Bld_bfr_many(bfr, categories_lbl, itm_mgr);
|
||||
}
|
||||
}
|
||||
class Xoh_ctg_itm_fmtr implements Bry_fmtr_arg {
|
||||
public void Set(Xoae_page page, Bry_fmtr itm_fmtr) {this.page = page; this.itm_fmtr = itm_fmtr;} private Xoae_page page; Bry_fmtr itm_fmtr;
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
int ctgs_len = page.Category_list().length;
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
Bry_bfr tmp_href = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
Xoae_app app = wiki.Appe();
|
||||
byte[] ctg_prefix = wiki.Ns_mgr().Ns_category().Name_db_w_colon();
|
||||
for (int i = 0; i < ctgs_len; i++) {
|
||||
byte[] page_name = page.Category_list()[i];
|
||||
tmp_bfr.Add(ctg_prefix).Add(page_name);
|
||||
page.Wikie().Appe().Html__href_wtr().Build_to_bfr(tmp_href, app, wiki.Domain_bry(), wiki.Ttl_parse(tmp_bfr.To_bry_and_clear()));
|
||||
itm_fmtr.Bld_bfr(bfr, tmp_href.To_bry_and_clear(), page_name, page_name);
|
||||
}
|
||||
tmp_bfr.Mkr_rls();
|
||||
tmp_href.Mkr_rls();
|
||||
}
|
||||
}
|
||||
56
400_xowa/src/gplx/xowa/htmls/Xohp_ctg_grp_mgr_tst.java
Normal file
56
400_xowa/src/gplx/xowa/htmls/Xohp_ctg_grp_mgr_tst.java
Normal 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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
public class Xohp_ctg_grp_mgr_tst {
|
||||
Xoh_ctg_mgr_fxt fxt = new Xoh_ctg_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Init_ctgs("A", "B").Test_html(String_.Concat_lines_nl
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, " <div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, " Categories"
|
||||
, " <ul>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_ctg_mgr_fxt {
|
||||
public Xoh_ctg_mgr_fxt Clear() {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
ctg_grp_mgr = new Xohp_ctg_grp_mgr();
|
||||
return this;
|
||||
} private Xohp_ctg_grp_mgr ctg_grp_mgr; Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
public Xoh_ctg_mgr_fxt Init_ctgs(String... v) {init_ctgs = v; return this;} private String[] init_ctgs;
|
||||
public void Test_html(String expd) {
|
||||
byte[][] ctgs_bry_ary = Bry_.Ary(init_ctgs);
|
||||
Xoae_page page = wiki.Parser_mgr().Ctx().Cur_page();
|
||||
page.Category_list_(ctgs_bry_ary);
|
||||
ctg_grp_mgr.Bld(tmp_bfr, page, ctgs_bry_ary.length);
|
||||
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
76
400_xowa/src/gplx/xowa/htmls/Xow_html_mgr.java
Normal file
76
400_xowa/src/gplx/xowa/htmls/Xow_html_mgr.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.ctgs.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.htmls.portal.*; import gplx.xowa.htmls.tocs.*; import gplx.xowa.wikis.modules.*; import gplx.xowa.htmls.hzips.*;
|
||||
public class Xow_html_mgr implements GfoInvkAble {
|
||||
public Xow_html_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
html_wtr = new Xoh_html_wtr(wiki, this);
|
||||
Xoae_app app = wiki.Appe();
|
||||
page_wtr_mgr = new Xoh_page_wtr_mgr(app.Gui_mgr().Kit().Tid() != gplx.gfui.Gfui_kit_.Swing_tid); // reverse logic to handle swt,drd but not mem
|
||||
Io_url file_dir = app.Fsys_mgr().Bin_xowa_file_dir().GenSubDir_nest("mediawiki.file");
|
||||
img_media_play_btn = Xoa_app_.Utl__encoder_mgr().Fsys().Encode_http(file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = Xoa_app_.Utl__encoder_mgr().Fsys().Encode_http(file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = Xoa_app_.Utl__encoder_mgr().Fsys().Encode_http(file_dir.GenSubFil("magnify-clip.png"));
|
||||
img_xowa_protocol = Xoa_app_.Utl__encoder_mgr().Fsys().Encode_http(app.Fsys_mgr().Bin_xowa_file_dir().GenSubFil_nest("app.general", "xowa_exec.png"));
|
||||
portal_mgr = new Xow_portal_mgr(wiki);
|
||||
imgs_mgr = new Xoh_imgs_mgr(this);
|
||||
module_mgr = new Xow_module_mgr(wiki);
|
||||
hzip_mgr = new Xow_hzip_mgr(app.Usr_dlg(), wiki);
|
||||
}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
html_wtr.Init_by_wiki(wiki);
|
||||
module_mgr.Init_by_wiki(wiki);
|
||||
}
|
||||
public void Init_by_lang(Xol_lang_itm lang) {
|
||||
portal_mgr.Init_by_lang(lang);
|
||||
}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xoh_html_wtr Html_wtr() {return html_wtr;} private Xoh_html_wtr html_wtr;
|
||||
public Xoh_page_wtr_mgr Page_wtr_mgr() {return page_wtr_mgr;} private Xoh_page_wtr_mgr page_wtr_mgr;
|
||||
public Xow_portal_mgr Portal_mgr() {return portal_mgr;} private Xow_portal_mgr portal_mgr;
|
||||
public Xow_toc_mgr Toc_mgr() {return toc_mgr;} private Xow_toc_mgr toc_mgr = new Xow_toc_mgr();
|
||||
public Xow_module_mgr Head_mgr() {return module_mgr;} private Xow_module_mgr module_mgr;
|
||||
public Xow_hzip_mgr Hzip_mgr() {return hzip_mgr;} private Xow_hzip_mgr hzip_mgr;
|
||||
public boolean Importing_ctgs() {return importing_ctgs;} public void Importing_ctgs_(boolean v) {importing_ctgs = v;} private boolean importing_ctgs;
|
||||
public int Img_thumb_width() {return img_thumb_width;} private int img_thumb_width = 220;
|
||||
public byte[] Img_media_play_btn() {return img_media_play_btn;} private byte[] img_media_play_btn;
|
||||
public byte[] Img_media_info_btn() {return img_media_info_btn;} private byte[] img_media_info_btn;
|
||||
public byte[] Img_thumb_magnify() {return img_thumb_magnify;} private byte[] img_thumb_magnify;
|
||||
public byte[] Img_xowa_protocol() {return img_xowa_protocol;} private byte[] img_xowa_protocol;
|
||||
public boolean Img_suppress_missing_src() {return img_suppress_missing_src;} public Xow_html_mgr Img_suppress_missing_src_(boolean v) {img_suppress_missing_src = v; return this;} private boolean img_suppress_missing_src = true;
|
||||
public Xohp_ctg_grp_mgr Ctg_mgr() {return ctg_mgr;} private Xohp_ctg_grp_mgr ctg_mgr = new Xohp_ctg_grp_mgr();
|
||||
public Xoctg_html_mgr Ns_ctg() {return ns_ctg;} private Xoctg_html_mgr ns_ctg = new Xoctg_html_mgr();
|
||||
public Xoh_imgs_mgr Imgs_mgr() {return imgs_mgr;} private Xoh_imgs_mgr imgs_mgr;
|
||||
public void Copy_cfg(Xow_html_mgr html_mgr) {imgs_mgr.Copy_cfg(html_mgr.Imgs_mgr());}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_article)) return page_wtr_mgr;
|
||||
else if (ctx.Match(k, Invk_portal)) return portal_mgr;
|
||||
else if (ctx.Match(k, Invk_imgs)) return imgs_mgr;
|
||||
else if (ctx.Match(k, Invk_ns_ctg)) return ns_ctg;
|
||||
else if (ctx.Match(k, Invk_modules)) return module_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
}
|
||||
public static final String
|
||||
Invk_article = "article"
|
||||
, Invk_portal = "portal", Invk_imgs = "imgs", Invk_ns_ctg = "ns_ctg"
|
||||
, Invk_modules = "modules"
|
||||
;
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/htmls/bridges/Bridge_cmd_itm.java
Normal file
23
400_xowa/src/gplx/xowa/htmls/bridges/Bridge_cmd_itm.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public interface Bridge_cmd_itm {
|
||||
byte[] Key();
|
||||
String Exec(Json_nde data);
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/htmls/bridges/Bridge_cmd_mgr.java
Normal file
40
400_xowa/src/gplx/xowa/htmls/bridges/Bridge_cmd_mgr.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Bridge_cmd_mgr {
|
||||
private final Json_parser parser;
|
||||
private final Hash_adp_bry cmd_hash = Hash_adp_bry.cs();
|
||||
public Bridge_cmd_mgr(Json_parser parser) {this.parser = parser;}
|
||||
public void Add(Bridge_cmd_itm cmd) {cmd_hash.Add_bry_obj(cmd.Key(), cmd);}
|
||||
public String Exec(GfoMsg m) {
|
||||
if (m.Args_count() == 0) throw Err_.new_("bridge.cmds", "no json specified for json_exec");
|
||||
return Exec(m.Args_getAt(0).Val_to_bry());
|
||||
}
|
||||
public String Exec(byte[] jdoc_bry) {
|
||||
Json_doc jdoc = null;
|
||||
try {jdoc = parser.Parse(jdoc_bry);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "bridge.cmds", "invalid json", "json", jdoc_bry);}
|
||||
Json_nde msg = jdoc.Root_nde();
|
||||
byte[] key_bry = msg.Get_bry(Key_cmd);
|
||||
Bridge_cmd_itm cmd = (Bridge_cmd_itm)cmd_hash.Get_by_bry(key_bry); if (cmd == null) throw Err_.new_("bridge.cmds", "unknown cmd", "cmd", cmd);
|
||||
try {return cmd.Exec(msg.Get(Key_data));}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "bridge.cmds", "exec json failed", "json", jdoc_bry);}
|
||||
}
|
||||
private static final byte[] Key_cmd = Bry_.new_a7("cmd"), Key_data = Bry_.new_a7("data");
|
||||
}
|
||||
103
400_xowa/src/gplx/xowa/htmls/bridges/Bridge_msg_bldr.java
Normal file
103
400_xowa/src/gplx/xowa/htmls/bridges/Bridge_msg_bldr.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
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.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Bridge_msg_bldr {
|
||||
private final Json_wtr wtr = new Json_wtr();
|
||||
private boolean rslt_pass; private String rslt_msg;
|
||||
private String notify_text; private String notify_status;
|
||||
private final Gfo_tree_list data_root = new Gfo_tree_list("data");
|
||||
public Bridge_msg_bldr() {
|
||||
wtr.Opt_ws_(Bool_.N);
|
||||
this.Clear();
|
||||
}
|
||||
public Bridge_msg_bldr Opt_quote_byte_apos_() {wtr.Opt_quote_byte_(Byte_ascii.Apos); return this;}
|
||||
public Bridge_msg_bldr Rslt_pass_y_() {return Rslt_pass_(Bool_.Y);}
|
||||
public Bridge_msg_bldr Rslt_pass_n_(String v) {Rslt_msg_(v); return Rslt_pass_(Bool_.N);}
|
||||
private Bridge_msg_bldr Rslt_pass_(boolean v) {synchronized(wtr){this.rslt_pass = v;} return this;}
|
||||
private Bridge_msg_bldr Rslt_msg_(String v) {synchronized(wtr){this.rslt_msg = v;} return this;}
|
||||
public Bridge_msg_bldr Notify_hint_(String v) {synchronized(wtr){this.notify_hint = v;} return this;} private String notify_hint;
|
||||
public Bridge_msg_bldr Notify_pass_(String v){synchronized(wtr){this.notify_text = v; this.notify_status = "success";} return this;}
|
||||
public Bridge_msg_bldr Notify_fail_(String v){synchronized(wtr){this.notify_text = v; this.notify_status = "error"; this.rslt_pass = false;} return this;}
|
||||
public Bridge_msg_bldr Data(String key, boolean val) {return Data_obj(key, val, Type_adp_.Tid__bool);}
|
||||
public Bridge_msg_bldr Data(String key, int val) {return Data_obj(key, val, Type_adp_.Tid__int);}
|
||||
public Bridge_msg_bldr Data(String key, String val) {return Data_obj(key, val, Type_adp_.Tid__str);}
|
||||
public Bridge_msg_bldr Data(String key, byte[] val) {return Data_obj(key, val, Type_adp_.Tid__bry);}
|
||||
private Bridge_msg_bldr Data_obj(String key, Object val, int val_tid) {
|
||||
synchronized (wtr) {data_root.Add_data(key, val, val_tid);}
|
||||
return this;
|
||||
}
|
||||
public byte[] To_json_bry() {synchronized(wtr){ Bld_json(); return wtr.To_bry_and_clear();}}
|
||||
public String To_json_str() {synchronized(wtr){ Bld_json(); return wtr.To_str_and_clear();}}
|
||||
public String To_json_str__empty() {return "{}";}
|
||||
public Bridge_msg_bldr Clear() {
|
||||
synchronized (wtr) {
|
||||
rslt_pass = true; // by default, set all msgs to pass==true
|
||||
rslt_msg = null;
|
||||
notify_hint = null;
|
||||
notify_text = null;
|
||||
notify_status = null;
|
||||
data_root.Clear();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Bld_json() {
|
||||
wtr.Clear();
|
||||
wtr.Doc_nde_bgn();
|
||||
wtr.Nde_bgn(Key_rslt);
|
||||
wtr.Kv_bool(Key_rslt_pass, rslt_pass);
|
||||
if (rslt_msg != null) wtr.Kv_str(Key_rslt_msg, rslt_msg);
|
||||
wtr.Nde_end();
|
||||
if (notify_text != null) {
|
||||
wtr.Nde_bgn(Key_notify);
|
||||
wtr.Kv_str(Key_notify_text, notify_text);
|
||||
wtr.Kv_str(Key_notify_status, notify_status);
|
||||
if (notify_hint != null)
|
||||
wtr.Kv_str(Key_notify_hint, notify_hint);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
Bld_json_for_hash(wtr, data_root);
|
||||
wtr.Doc_nde_end();
|
||||
}
|
||||
private void Bld_json_for_hash(Json_wtr wtr, Gfo_tree_list hash) {
|
||||
int len = hash.Len(); if (len == 0) return;
|
||||
wtr.Nde_bgn(hash.Key());
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Gfo_tree_itm itm = hash.Get_at(i);
|
||||
if (itm.Tid() == Gfo_tree_itm_.Tid_data) {
|
||||
Gfo_tree_data sub_kv = (Gfo_tree_data)itm;
|
||||
String key = sub_kv.Key(); Object val = sub_kv.Val();
|
||||
switch (sub_kv.Val_tid()) {
|
||||
case Type_adp_.Tid__bool: wtr.Kv_bool(key, Bool_.cast(val)); break;
|
||||
case Type_adp_.Tid__int: wtr.Kv_int(key, Int_.cast(val)); break;
|
||||
case Type_adp_.Tid__bry: wtr.Kv_bry(key, (byte[])val); break;
|
||||
default: wtr.Kv_str(key, Object_.Xto_str_strict_or_null_mark(val)); break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Gfo_tree_list sub_hash = (Gfo_tree_list)itm;
|
||||
Bld_json_for_hash(wtr, sub_hash);
|
||||
}
|
||||
}
|
||||
wtr.Nde_end();
|
||||
}
|
||||
private static final byte[]
|
||||
Key_rslt = Bry_.new_a7("rslt"), Key_rslt_pass = Bry_.new_a7("pass"), Key_rslt_msg = Bry_.new_a7("msg")
|
||||
, Key_notify = Bry_.new_a7("notify"), Key_notify_text = Bry_.new_a7("text"), Key_notify_status = Bry_.new_a7("status"), Key_notify_hint = Bry_.new_a7("hint")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Bridge_msg_bldr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Bridge_msg_bldr_fxt fxt = new Bridge_msg_bldr_fxt();
|
||||
@Test public void Bld() {
|
||||
fxt.Bldr().Rslt_pass_y_().Notify_pass_("passed").Data("key1", true).Data("key2", 1).Data("key3", "val3");
|
||||
fxt.Test_to_json_str("{'rslt':{'pass':true},'notify':{'text':'passed','status':'success'},'data':{'key1':true,'key2':1,'key3':'val3'}}");
|
||||
}
|
||||
}
|
||||
class Bridge_msg_bldr_fxt {
|
||||
public Bridge_msg_bldr Bldr() {return bldr;} private final Bridge_msg_bldr bldr = new Bridge_msg_bldr().Opt_quote_byte_apos_();
|
||||
public void Clear() {}
|
||||
public void Test_to_json_str(String expd) {
|
||||
Tfds.Eq_str_lines(expd, bldr.To_json_str());
|
||||
}
|
||||
}
|
||||
45
400_xowa/src/gplx/xowa/htmls/bridges/Gfo_tree_itm.java
Normal file
45
400_xowa/src/gplx/xowa/htmls/bridges/Gfo_tree_itm.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
interface Gfo_tree_itm {
|
||||
int Tid();
|
||||
}
|
||||
class Gfo_tree_itm_ {
|
||||
public static final int Tid_data = 1, Tid_list = 2;
|
||||
}
|
||||
class Gfo_tree_data implements Gfo_tree_itm {
|
||||
public int Tid() {return Gfo_tree_itm_.Tid_data;}
|
||||
public Gfo_tree_data(String key, Object val, int val_tid) {
|
||||
this.key = key; this.val = val; this.val_tid = val_tid;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public Object Val() {return val;} private final Object val;
|
||||
public int Val_tid() {return val_tid;} private final int val_tid;
|
||||
}
|
||||
class Gfo_tree_list implements Gfo_tree_itm {
|
||||
private final Ordered_hash list = Ordered_hash_.New();
|
||||
public Gfo_tree_list(String key) {this.key = key;}
|
||||
public int Tid() {return Gfo_tree_itm_.Tid_list;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public void Clear() {list.Clear();}
|
||||
public int Len() {return list.Count();}
|
||||
public Gfo_tree_data Add_data(String key, Object val, int val_tid) {Gfo_tree_data rv = new Gfo_tree_data(key, val, val_tid); this.Add(key, rv); return rv;}
|
||||
public Gfo_tree_list Add_list(String key) {Gfo_tree_list rv = new Gfo_tree_list(key); this.Add(key, rv); return rv;}
|
||||
private void Add(String key, Gfo_tree_itm itm) {list.Add(key, itm);}
|
||||
public Gfo_tree_itm Get_at(int i) {return (Gfo_tree_itm)list.Get_at(i);}
|
||||
}
|
||||
25
400_xowa/src/gplx/xowa/htmls/bridges/Xoh_bridge_mgr.java
Normal file
25
400_xowa/src/gplx/xowa/htmls/bridges/Xoh_bridge_mgr.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Xoh_bridge_mgr {
|
||||
public Xoh_bridge_mgr(Json_parser parser) {this.cmd_mgr = new Bridge_cmd_mgr(parser);}
|
||||
public Bridge_cmd_mgr Cmd_mgr() {return cmd_mgr;} private final Bridge_cmd_mgr cmd_mgr;
|
||||
public Bridge_msg_bldr Msg_bldr() {return msg_bldr;} private final Bridge_msg_bldr msg_bldr = new Bridge_msg_bldr();
|
||||
}
|
||||
87
400_xowa/src/gplx/xowa/htmls/bridges/dbuis/Dbui_cmd_mgr.java
Normal file
87
400_xowa/src/gplx/xowa/htmls/bridges/dbuis/Dbui_cmd_mgr.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cmd_mgr {
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
private boolean init;
|
||||
public void Init_by_bridge(Bridge_cmd_mgr cmd_mgr) {
|
||||
if (init) return;
|
||||
init = true;
|
||||
cmd_mgr.Add(new Dbui_cmd_row_edit ("xowa.dbui.edit_bgn", this));
|
||||
cmd_mgr.Add(new Dbui_cmd_row_save ("xowa.dbui.save_bgn", this));
|
||||
cmd_mgr.Add(new Dbui_cmd_row_del ("xowa.dbui.delete_bgn", this));
|
||||
cmd_mgr.Add(new Dbui_cmd_row_reorder ("xowa.dbui.reorder_bgn", this));
|
||||
}
|
||||
public void Add(Dbui_tbl_itm tbl) {hash.Add_bry_obj(tbl.Key(), tbl);}
|
||||
public String Del(Json_nde data) {return Get_tbl(data).Del (data.Get_bry(Arg_row_id), data.Get_bry(Arg_row_pkey));}
|
||||
public String Edit(Json_nde data) {return Get_tbl(data).Edit(data.Get_bry(Arg_row_id), data.Get_bry(Arg_row_pkey));}
|
||||
public String Save(Json_nde data) {return Get_tbl(data).Save(data.Get_bry(Arg_row_id), data.Get_bry(Arg_row_pkey), To_hash(data.Get(Arg_vals)));}
|
||||
public String Reorder(Json_nde data){
|
||||
byte[] pkeys_concat = data.Get_bry(Arg_pkeys);
|
||||
return Get_tbl(data).Reorder(Bry_split_.Split(pkeys_concat, Byte_ascii.Pipe), -1);
|
||||
}
|
||||
private Dbui_tbl_itm Get_tbl(Json_nde data) {
|
||||
byte[] tbl_key = data.Get_bry(Arg_tbl_key);
|
||||
Dbui_tbl_itm rv = (Dbui_tbl_itm)hash.Get_by(tbl_key); if (rv == null) throw Err_.new_("dbui", "unknown tbl_key", "tbl_key", tbl_key);
|
||||
return rv;
|
||||
}
|
||||
private static Dbui_val_hash To_hash(Json_grp grp) {
|
||||
Dbui_val_hash rv = new Dbui_val_hash();
|
||||
int len = grp.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Json_kv kv = (Json_kv)grp.Get_at(i);
|
||||
Json_nde nde = (Json_nde)kv.Val();
|
||||
Json_kv key = (Json_kv)nde.Get_itm(Arg_key);
|
||||
Json_kv val = (Json_kv)nde.Get_itm(Arg_val);
|
||||
Dbui_val_itm fld = new Dbui_val_itm(val.Val().Data_bry(), Bry_.Empty);
|
||||
rv.Add(key.Val().Data_bry(), fld);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final Dbui_cmd_mgr Instance = new Dbui_cmd_mgr(); Dbui_cmd_mgr() {}
|
||||
private static final byte[]
|
||||
Arg_tbl_key = Bry_.new_a7("tbl_key"), Arg_row_pkey = Bry_.new_a7("row_pkey"), Arg_row_id = Bry_.new_a7("row_id")
|
||||
, Arg_vals = Bry_.new_a7("vals"), Arg_key = Bry_.new_a7("key"), Arg_val = Bry_.new_a7("val")
|
||||
, Arg_pkeys = Bry_.new_a7("pkeys")
|
||||
;
|
||||
}
|
||||
class Dbui_cmd_row_del implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_del(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public String Exec(Json_nde data) {return mgr.Del(data);}
|
||||
}
|
||||
class Dbui_cmd_row_edit implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_edit(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public String Exec(Json_nde data) {return mgr.Edit(data);}
|
||||
}
|
||||
class Dbui_cmd_row_save implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_save(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public String Exec(Json_nde data) {return mgr.Save(data);}
|
||||
}
|
||||
class Dbui_cmd_row_reorder implements Bridge_cmd_itm {
|
||||
private final Dbui_cmd_mgr mgr;
|
||||
public Dbui_cmd_row_reorder(String key, Dbui_cmd_mgr mgr) {this.key = Bry_.new_u8(key); this.mgr = mgr;}
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public String Exec(Json_nde data) {return mgr.Reorder(data);}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_cells_fmtr implements Bry_fmtr_arg {
|
||||
private final Dbui_cell_fmtr cell_fmtr = new Dbui_cell_fmtr();
|
||||
private final Dbui_btn_fmtr btn_fmtr = new Dbui_btn_fmtr();
|
||||
private Dbui_btn_itm[] btns;
|
||||
private byte[] row_key; private Dbui_row_itm row_itm;
|
||||
public void Ctor(Dbui_val_fmtr val_fmtr, Dbui_btn_itm[] btns) {
|
||||
cell_fmtr.Ctor(val_fmtr); this.btns = btns;
|
||||
}
|
||||
public Dbui_cells_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {
|
||||
this.row_key = row_key; this.row_itm = row_itm;
|
||||
return this;
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, cell_fmtr.Init(row_key, row_itm), btn_fmtr.Init(row_key, btns));
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='xo_drag_handle xo_cell'></div>~{vals}"
|
||||
, " <div class='xo_cell'>~{btns}"
|
||||
, " </div>"
|
||||
), "vals", "btns");
|
||||
}
|
||||
class Dbui_cell_fmtr implements Bry_fmtr_arg {
|
||||
private byte[] row_key; private Dbui_row_itm row_itm;
|
||||
private Dbui_val_fmtr val_fmtr;
|
||||
public void Ctor(Dbui_val_fmtr val_fmtr) {this.val_fmtr = val_fmtr;}
|
||||
public Dbui_cell_fmtr Init(byte[] row_key, Dbui_row_itm row_itm) {this.row_key = row_key; this.row_itm = row_itm; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
Dbui_col_itm[] cols = row_itm.Tbl().Cols();
|
||||
Dbui_val_itm[] vals = row_itm.Vals(); int len = vals.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_val_itm val = vals[i];
|
||||
fmtr.Bld_bfr_many(bfr, row_key, i, val_fmtr.Init(cols[i], row_key, val));
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='xo_cell'>~{html}</div>"
|
||||
), "row_key", "val_idx", "html");
|
||||
}
|
||||
class Dbui_btn_fmtr implements Bry_fmtr_arg {
|
||||
private byte[] row_key; private Dbui_btn_itm[] btns;
|
||||
public Dbui_btn_fmtr Init(byte[] row_key, Dbui_btn_itm[] btns) {
|
||||
this.row_key = row_key; this.btns = btns; return this;
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
int len = btns.length;
|
||||
Io_url img_dir = gplx.xowa.htmls.heads.Xoh_head_itm__dbui.Img_dir();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_btn_itm btn = btns[i];
|
||||
fmtr.Bld_bfr_many(bfr, row_key, btn.Cmd(), img_dir.GenSubFil(btn.Img()).To_http_file_bry(), btn.Text());
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <span><a href='javascript:~{btn_cmd}(\"~{row_key}\");'><img src='~{btn_img}' title='~{btn_text}'/></a></span>"
|
||||
), "row_key", "btn_cmd", "btn_img", "btn_text");
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public class Dbui_tbl_fmtr {
|
||||
private final Dbui_head_cell_fmtr head_cell_fmtr = new Dbui_head_cell_fmtr();
|
||||
private final Dbui_row_fmtr row_fmtr = new Dbui_row_fmtr();
|
||||
public void Write(Bry_bfr bfr, Dbui_tbl_itm tbl, byte[] origin_html, byte[] delete_confirm_msg, Dbui_row_itm[] rows) {
|
||||
tbl_fmtr.Bld_bfr_many(bfr, tbl.Key(), Dbui_tbl_itm_.Calc_width(tbl), origin_html, delete_confirm_msg, head_cell_fmtr.Init(tbl), row_fmtr.Init(tbl, rows));
|
||||
}
|
||||
private static final Bry_fmtr tbl_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div class='xo_tbl xo_sortable' data-dbui-tbl_key='~{tbl_key}'~{delete_confirm_msg} style='width: ~{width}px;'>"
|
||||
, " <div class='xo_row xo_header'>"
|
||||
, " <div class='xo_origin xo_resizable_col' style='width:20px'>~{origin}</div>~{head_cells}"
|
||||
, " </div>~{data_rows}"
|
||||
, "</div>"
|
||||
), "tbl_key", "width", "origin", "delete_confirm_msg", "head_cells", "data_rows");
|
||||
}
|
||||
class Dbui_head_cell_fmtr implements Bry_fmtr_arg {
|
||||
private Dbui_tbl_itm tbl;
|
||||
public Dbui_head_cell_fmtr Init(Dbui_tbl_itm tbl) {this.tbl = tbl; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
Dbui_col_itm[] cols = tbl.Cols(); int len = cols.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_col_itm col = cols[i];
|
||||
fmtr.Bld_bfr_many(bfr, col.Width(), col.Display());
|
||||
}
|
||||
bfr.Add_str_a7("\n <div class='xo_head xo_resizable_col' style='width:50px;'> </div>"); // btns headers
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='xo_head xo_resizable_col' style='width:~{width}px;'>~{display}</div>"
|
||||
), "width", "display");
|
||||
}
|
||||
class Dbui_row_fmtr implements Bry_fmtr_arg {
|
||||
private final Dbui_cells_fmtr cells_fmtr = new Dbui_cells_fmtr();
|
||||
private final Dbui_val_fmtr val_fmtr = Dbui_val_fmtr_.new_view();
|
||||
private final Bry_bfr row_key_bfr = Bry_bfr.new_(255);
|
||||
private Dbui_tbl_itm tbl; private Dbui_row_itm[] rows;
|
||||
public Dbui_row_fmtr Init(Dbui_tbl_itm tbl, Dbui_row_itm[] rows) {this.tbl = tbl; this.rows = rows; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
byte[] tbl_key = tbl.Key();
|
||||
int len = rows.length;
|
||||
cells_fmtr.Ctor(val_fmtr, tbl.View_btns());
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbui_row_itm row = rows[i];
|
||||
row_key_bfr.Add(tbl_key).Add_byte(Byte_ascii.Underline).Add_int_variable(i);
|
||||
byte[] row_key = row_key_bfr.To_bry_and_clear();
|
||||
fmtr.Bld_bfr_many(bfr, row_key, row.Pkey(), cells_fmtr.Init(row_key, row));
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id='~{row_key}' class='xo_row xo_draggable' data-dbui-row_pkey='~{pkey}'>~{cells}"
|
||||
, " </div>"
|
||||
), "row_key", "pkey", "cells");
|
||||
}
|
||||
@@ -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.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
import org.junit.*;
|
||||
public class Dbui_tbl_fmtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Dbui_tbl_fmtr_fxt fxt = new Dbui_tbl_fmtr_fxt();
|
||||
@Test public void Basic() {
|
||||
// fxt.Test_write
|
||||
// ( fxt.Make_tbl()
|
||||
// , String_.Concat_lines_nl_skip_last()
|
||||
// );
|
||||
}
|
||||
}
|
||||
class Dbui_tbl_fmtr_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.new_(255);
|
||||
private final Dbui_tbl_fmtr tbl_fmtr = new Dbui_tbl_fmtr();
|
||||
public void Clear() {}
|
||||
public Dbui_tbl_itm Make_tbl() {
|
||||
return null;
|
||||
}
|
||||
public void Test_write(Dbui_tbl_itm tbl, String expd) {
|
||||
tbl_fmtr.Write(bfr, tbl, null, null, null);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
public interface Dbui_val_fmtr {
|
||||
Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val);
|
||||
}
|
||||
class Dbui_val_fmtr__view implements Bry_fmtr_arg, Dbui_val_fmtr {
|
||||
private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.val = val; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
bfr.Add(val.Html());
|
||||
}
|
||||
}
|
||||
class Dbui_val_fmtr__edit implements Bry_fmtr_arg, Dbui_val_fmtr {
|
||||
private Dbui_col_itm col; private byte[] row_id; private Dbui_val_itm val;
|
||||
public Dbui_val_fmtr Init(Dbui_col_itm col, byte[] row_id, Dbui_val_itm val) {this.col = col; this.row_id = row_id; this.val = val; return this;}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
switch (col.Type()) {
|
||||
case Dbui_col_itm.Type_id_str: input_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
|
||||
case Dbui_col_itm.Type_id_text: textarea_fmtr_str.Bld_bfr_many(bfr, col.Key(), col.Width(), val.Data(), row_id); break;
|
||||
default: throw Err_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr input_fmtr_str = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <input class='dbui_cell xo_resizable_col' dbui_col='~{col_key}' style='border:1px solid black; width:~{width}px' value='~{value}' onkeyup='Dbui__edit__keyup(event, \"~{row_id}\");'/>"
|
||||
), "col_key", "width", "value", "row_id");
|
||||
private static final Bry_fmtr textarea_fmtr_str = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <textarea class='dbui_cell' dbui_col='~{col_key}' style='border:1px solid black; width:~{width}px; height:18px;' onkeyup='Dbui__edit__keyup(event, \"~{row_id}\");'>~{value}</textarea>"
|
||||
), "col_key", "width", "value", "row_id");
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.fmtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_val_fmtr_ {
|
||||
public static Dbui_val_fmtr new_view() {return new Dbui_val_fmtr__view();}
|
||||
public static Dbui_val_fmtr new_edit() {return new Dbui_val_fmtr__edit();}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_btn_itm {
|
||||
public Dbui_btn_itm(String cmd, String img, String text) {this.cmd = cmd; this.img = img; this.text = text;}
|
||||
public String Key() {return text;}
|
||||
public String Cmd() {return cmd;} private final String cmd;
|
||||
public String Img() {return img;} private final String img;
|
||||
public String Text() {return text;} private final String text;
|
||||
public static final Dbui_btn_itm[] Ary_empty = new Dbui_btn_itm[0];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_col_itm {
|
||||
public Dbui_col_itm(int type, int width, String key, String display) {this.type = type; this.width = width; this.key = key; this.display = display;}
|
||||
public int Type() {return type;} private final int type;
|
||||
public String Key() {return key;} private final String key;
|
||||
public String Display() {return display;} private final String display;
|
||||
public int Width() {return width;} private final int width;
|
||||
public static final int Type_id_str = 1, Type_id_text = 2, Type_id_int = 3, Type_id_datetime = 4;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_row_itm {
|
||||
public Dbui_row_itm(Dbui_tbl_itm tbl, byte[] pkey, Dbui_val_itm[] vals) {
|
||||
this.tbl = tbl; this.pkey = pkey; this.vals = vals;
|
||||
}
|
||||
public Dbui_tbl_itm Tbl() {return tbl;} private final Dbui_tbl_itm tbl;
|
||||
public byte[] Pkey() {return pkey;} private final byte[] pkey;
|
||||
public Dbui_val_itm[] Vals() {return vals;} private Dbui_val_itm[] vals;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public interface Dbui_tbl_itm {
|
||||
byte[] Key();
|
||||
Dbui_col_itm[] Cols();
|
||||
Dbui_btn_itm[] View_btns();
|
||||
Dbui_btn_itm[] Edit_btns();
|
||||
String Del (byte[] row_id, byte[] row_pkey);
|
||||
String Edit(byte[] row_id, byte[] row_pkey);
|
||||
String Save(byte[] row_id, byte[] row_pkey, Dbui_val_hash vals);
|
||||
String Reorder(byte[][] pkeys, int owner);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_tbl_itm_ {
|
||||
public static int Calc_width(Dbui_tbl_itm tbl) {
|
||||
int rv = 40; // 40 for button col
|
||||
Dbui_col_itm[] ary = tbl.Cols();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
rv += ary[i].Width();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_val_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
public void Add(byte[] key, Dbui_val_itm itm) {hash.Add(key, itm);}
|
||||
public byte[] Get_val_as_bry(String key) {return Get_val_as_bry(Bry_.new_u8(key));}
|
||||
public byte[] Get_val_as_bry(byte[] key) {
|
||||
Dbui_val_itm itm = (Dbui_val_itm)hash.Get_by(key); if (itm == null) throw Err_.new_wo_type("dbui.val_hash; unknown key", "key", key);
|
||||
return itm.Data();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.htmls.bridges.dbuis.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.bridges.*; import gplx.xowa.htmls.bridges.dbuis.*;
|
||||
public class Dbui_val_itm {
|
||||
public Dbui_val_itm(byte[] data, byte[] html) {this.data = data; this.html = html;}
|
||||
public byte[] Data() {return data;} private byte[] data;
|
||||
public byte[] Html() {return html;} private final byte[] html;
|
||||
public void Data_(byte[] v) {this.data = v;}
|
||||
}
|
||||
79
400_xowa/src/gplx/xowa/htmls/css/Xob_css_status.java
Normal file
79
400_xowa/src/gplx/xowa/htmls/css/Xob_css_status.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
public class Xob_css_status {
|
||||
public int Update_tid() {return update_tid;} private int update_tid;
|
||||
public boolean Fs_exists() {return fs_exists;} private boolean fs_exists;
|
||||
public Io_url Fs_dir() {return fs_dir;} private Io_url fs_dir;
|
||||
public boolean Db_exists() {return db_exists;} private boolean db_exists;
|
||||
public void Fs_exists_(boolean fs_exists, Io_url fs_dir) {
|
||||
this.fs_exists = fs_exists;
|
||||
this.fs_dir = fs_dir;
|
||||
}
|
||||
public void Db_exists_(boolean db_exists) {
|
||||
this.db_exists = db_exists;
|
||||
}
|
||||
public void Update_tid_none_y_() {this.update_tid = Update_tid_none;}
|
||||
public void Update_tid_wmf_y_() {this.update_tid = Update_tid_wmf;}
|
||||
public void Update_tid_db_y_() {this.update_tid = Update_tid_db;}
|
||||
public static final int Update_tid_none = 0, Update_tid_db = 1, Update_tid_wmf = 2;
|
||||
public static Xob_css_status Chk(Xow_wiki wiki, Io_url css_dir, String key) {
|
||||
Xob_css_status rv = new Xob_css_status();
|
||||
Chk_fs(rv, wiki);
|
||||
Chk_db(rv, wiki, css_dir);
|
||||
return rv;
|
||||
}
|
||||
private static void Chk_fs(Xob_css_status rv, Xow_wiki wiki) {
|
||||
Io_url css_dir = wiki.App().Fsys_mgr().Wiki_css_dir(wiki.Domain_str()); // EX: /xowa/user/anonymous/wiki/en.wikipedia.org/html/
|
||||
Io_url css_fil_wiki = css_dir.GenSubFil(Xoa_css_extractor.Css_wiki_name); // EX: /xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css
|
||||
boolean exists = Io_mgr.Instance.ExistsFil(css_fil_wiki);
|
||||
rv.Fs_exists_(exists, css_dir);
|
||||
}
|
||||
private static void Chk_db(Xob_css_status rv, Xow_wiki wiki, Io_url css_dir) {
|
||||
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
|
||||
if ( core_db_mgr == null
|
||||
|| core_db_mgr.Props() != null
|
||||
|| !core_db_mgr.Props().Schema_is_1()
|
||||
|| core_db_mgr.Tbl__cfg().Select_yn_or(Xow_cfg_consts.Grp__wiki_schema, Xowd_db_file_schema_props.Key__tbl_css_core, Bool_.N)
|
||||
) {
|
||||
rv.Db_exists_(false);
|
||||
if (rv.Fs_exists())
|
||||
rv.Update_tid_none_y_(); // v1_db and fs_exists; don't do update; legacy behavior
|
||||
else
|
||||
rv.Update_tid_wmf_y_(); // v1_db and fs_missing; update from wmf; legacy behavior
|
||||
}
|
||||
if (rv.Fs_exists()) {
|
||||
DateAdp fs_timestamp = Timestamp_load(css_dir);
|
||||
DateAdp db_timestamp = DateAdp_.Now();
|
||||
if (db_timestamp.compareTo(fs_timestamp) == CompareAble_.More)
|
||||
rv.Update_tid_db_y_(); // v2_db and later_version; update from db
|
||||
else
|
||||
rv.Update_tid_none_y_(); // v2_db and current version; noop
|
||||
}
|
||||
}
|
||||
public static void Timestamp_save(Io_url css_dir, DateAdp time) {
|
||||
Io_mgr.Instance.SaveFilStr(css_dir.GenSubFil(Timestamp_filename), time.XtoStr_fmt_yyyyMMdd_HHmmss());
|
||||
}
|
||||
public static DateAdp Timestamp_load(Io_url css_dir) {
|
||||
String rv = Io_mgr.Instance.LoadFilStr(css_dir.GenSubFil(Timestamp_filename));
|
||||
return rv == null ? DateAdp_.MinValue : DateAdp_.parse_iso8561_or(rv, DateAdp_.MinValue);
|
||||
}
|
||||
private static final String Timestamp_filename = "xowa.css.timestamp.txt";
|
||||
}
|
||||
53
400_xowa/src/gplx/xowa/htmls/css/Xow_css_mgr.java
Normal file
53
400_xowa/src/gplx/xowa/htmls/css/Xow_css_mgr.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_css_mgr {
|
||||
private final Xow_wiki wiki;
|
||||
private boolean db_css_exists;
|
||||
private Xowd_css_core_tbl css_core_tbl; private Xowd_css_file_tbl css_file_tbl;
|
||||
public Xow_css_mgr(Xow_wiki wiki) {this.wiki = wiki;}
|
||||
public void Init_by_wiki() {
|
||||
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
|
||||
Xowd_db_mgr core_db_mgr = wiki.Data__core_mgr();
|
||||
if (core_db_mgr == null) {
|
||||
usr_dlg.Log_many("", "", "db.css.exists; css_missing b/c tdb; wiki=~{0}", wiki.Domain_str());
|
||||
return;
|
||||
}
|
||||
if ( core_db_mgr.Props() == null
|
||||
|| core_db_mgr.Props().Schema_is_1()) {
|
||||
usr_dlg.Log_many("", "", "db.css.exists; css_missing b/c v1; wiki=~{0}", wiki.Domain_str());
|
||||
return;
|
||||
}
|
||||
Xowd_db_file core_db = core_db_mgr.Db__core();
|
||||
this.css_core_tbl = core_db.Tbl__css_core();
|
||||
this.css_file_tbl = core_db.Tbl__css_file();
|
||||
if ( core_db == null
|
||||
|| !core_db.Conn().Meta_tbl_exists(css_core_tbl.Tbl_name())
|
||||
) {
|
||||
usr_dlg.Log_many("", "", "db.css.exists; css_missing b/c v2 w/o css; wiki=~{0}", wiki.Domain_str());
|
||||
return;
|
||||
}
|
||||
this.db_css_exists = true;
|
||||
}
|
||||
public void Db_del_all() {
|
||||
if (!db_css_exists) {Xoa_app_.Usr_dlg().Log_many("", "", "db.css.del_all; del_all skipped; wiki=~{0}", wiki.Domain_str()); return;}
|
||||
css_core_tbl.Delete_all();
|
||||
css_file_tbl.Delete_all();
|
||||
}
|
||||
}
|
||||
60
400_xowa/src/gplx/xowa/htmls/css/Xowd_css_core_mgr.java
Normal file
60
400_xowa/src/gplx/xowa/htmls/css/Xowd_css_core_mgr.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
public class Xowd_css_core_mgr {
|
||||
public static void Set(Xowd_css_core_tbl core_tbl, Xowd_css_file_tbl file_tbl, Io_url css_dir, String key) {
|
||||
Db_conn conn = core_tbl.Conn();
|
||||
Io_url[] file_list = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry();
|
||||
try {
|
||||
conn.Txn_bgn("schema__css_core__set");
|
||||
int css_id = core_tbl.Select_id_by_key(key);
|
||||
DateAdp updated_on = DateAdp_.Now().XtoUtc();
|
||||
if (css_id == -1)
|
||||
css_id = core_tbl.Insert(key, updated_on);
|
||||
else {
|
||||
core_tbl.Update(css_id, key, updated_on);
|
||||
file_tbl.Delete(css_id);
|
||||
}
|
||||
for (Io_url file : file_list) {
|
||||
String path = Op_sys.Fsys_path_to_lnx(file.GenRelUrl_orEmpty(css_dir));
|
||||
byte[] data = Io_mgr.Instance.LoadFilBry(file);
|
||||
file_tbl.Insert(css_id, path, data);
|
||||
}
|
||||
conn.Txn_end();
|
||||
}
|
||||
catch (Exception e) {conn.Txn_cxl(); throw e;}
|
||||
}
|
||||
public static boolean Get(Xowd_css_core_tbl core_tbl, Xowd_css_file_tbl file_tbl, Io_url css_dir, String key) {
|
||||
int css_id = core_tbl.Select_id_by_key(key); if (css_id == Xowd_css_core_tbl.Id_null) return false; // unknown key; return false (not found)
|
||||
Xowd_css_file_itm[] file_list = file_tbl.Select_by_owner(css_id);
|
||||
// Io_mgr.Instance.DeleteDirDeep(css_dir); // NOTE: do not delete existing files; just overwrite;
|
||||
int len = file_list.length;
|
||||
if (len == 0) return false; // no css files in db
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_css_file_itm file = file_list[i];
|
||||
Io_url file_url = Io_url_.new_fil_(css_dir.Gen_sub_path_for_os(file.Path()));
|
||||
if (file.Data() == null) continue; // NOTE: sqlite will return 0 length fields as NULL; if no data, just ignore, else error below
|
||||
Io_mgr.Instance.SaveFilBry(file_url, file.Data());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static final String Key_default = "xowa.default", Key_mobile = "xowa.mobile";
|
||||
}
|
||||
120
400_xowa/src/gplx/xowa/htmls/css/Xowd_css_core_mgr_tst.java
Normal file
120
400_xowa/src/gplx/xowa/htmls/css/Xowd_css_core_mgr_tst.java
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_css_core_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xowd_css_core_mgr_fxt fxt = new Xowd_css_core_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
|
||||
( fxt.Make_skin_itm(1, "desktop", "20010101_050200")
|
||||
);
|
||||
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
|
||||
( fxt.Make_file_itm(1, "a.css", "a_data")
|
||||
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
|
||||
);
|
||||
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
|
||||
fxt.Init_fs(src_dir, file_ary);
|
||||
fxt.Exec_set(src_dir, "desktop");
|
||||
fxt.Test_skin_tbl(skin_ary);
|
||||
fxt.Test_file_tbl(file_ary);
|
||||
|
||||
Io_url trg_dir = Io_url_.mem_dir_("mem/trg/");
|
||||
fxt.Exec_get(trg_dir, "desktop");
|
||||
fxt.Test_fs(trg_dir, file_ary);
|
||||
}
|
||||
@Test public void Update() { // update css files; keep same skin_id; insert new files
|
||||
Xowd_css_core_itm[] skin_ary = fxt.Make_skin_ary
|
||||
( fxt.Make_skin_itm(1, "desktop", "20010101_050500")
|
||||
);
|
||||
Xowd_css_file_itm[] file_ary = fxt.Make_file_ary
|
||||
( fxt.Make_file_itm(1, "a.css", "a_data")
|
||||
, fxt.Make_file_itm(1, "b/b.png", "b/b_data")
|
||||
);
|
||||
Io_url src_dir = Io_url_.mem_dir_("mem/src/");
|
||||
fxt.Init_fs(src_dir, file_ary);
|
||||
fxt.Exec_set(src_dir, "desktop");
|
||||
|
||||
file_ary = fxt.Make_file_ary
|
||||
( fxt.Make_file_itm(1, "a1.css", "a1_data")
|
||||
, fxt.Make_file_itm(1, "b/b1.png", "b/b1_data")
|
||||
);
|
||||
Io_mgr.Instance.DeleteDirDeep(src_dir);
|
||||
fxt.Init_fs(src_dir, file_ary);
|
||||
fxt.Exec_set(src_dir, "desktop");
|
||||
fxt.Test_skin_tbl(skin_ary);
|
||||
fxt.Test_file_tbl(file_ary);
|
||||
}
|
||||
}
|
||||
class Xowd_css_core_mgr_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(32);
|
||||
private Xowd_css_core_tbl core_tbl; private Xowd_css_file_tbl file_tbl;
|
||||
public void Clear() {
|
||||
Tfds.Now_enabled_y_();
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
Db_conn conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/css.sqlite3"));
|
||||
this.core_tbl = new Xowd_css_core_tbl(conn);
|
||||
this.file_tbl = new Xowd_css_file_tbl(conn);
|
||||
core_tbl.Create_tbl();
|
||||
file_tbl.Create_tbl();
|
||||
}
|
||||
public Xowd_css_core_itm Make_skin_itm(int id, String key, String updated_on) {return new Xowd_css_core_itm(id, key, DateAdp_.parse_gplx(updated_on));}
|
||||
public Xowd_css_file_itm Make_file_itm(int skin_id, String path, String data) {return new Xowd_css_file_itm(skin_id, path, Bry_.new_u8(data));}
|
||||
public Xowd_css_file_itm[] Make_file_ary(Xowd_css_file_itm... ary) {return ary;}
|
||||
public Xowd_css_core_itm[] Make_skin_ary(Xowd_css_core_itm... ary) {return ary;}
|
||||
public void Init_fs(Io_url css_dir, Xowd_css_file_itm[] file_ary) {
|
||||
for (Xowd_css_file_itm itm : file_ary)
|
||||
Io_mgr.Instance.SaveFilBry(css_dir.GenSubFil(itm.Path()), itm.Data());
|
||||
}
|
||||
public void Exec_set(Io_url css_dir, String key) {Xowd_css_core_mgr.Set(core_tbl, file_tbl, css_dir, key);}
|
||||
public void Exec_get(Io_url css_dir, String key) {Xowd_css_core_mgr.Get(core_tbl, file_tbl, css_dir, key);}
|
||||
public void Test_skin_tbl(Xowd_css_core_itm[] expd) {
|
||||
Xowd_css_core_itm[] actl = core_tbl.Select_all();
|
||||
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
|
||||
}
|
||||
public void Test_file_tbl(Xowd_css_file_itm[] expd) {
|
||||
Xowd_css_file_itm[] actl = file_tbl.Select_all();
|
||||
Tfds.Eq_str_lines(To_str(expd), To_str(actl));
|
||||
}
|
||||
public void Test_fs(Io_url css_dir, Xowd_css_file_itm[] expd) {
|
||||
Io_url[] actl = Io_mgr.Instance.QueryDir_args(css_dir).Recur_().ExecAsUrlAry();
|
||||
int len = expd.length;
|
||||
Tfds.Eq(len, actl.length);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_css_file_itm expd_itm = expd[i];
|
||||
Tfds.Eq_bry(expd_itm.Data(), Io_mgr.Instance.LoadFilBry(actl[i]));
|
||||
}
|
||||
}
|
||||
private String To_str(Xowd_css_file_itm[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_css_file_itm itm = ary[i];
|
||||
bfr.Add_int_variable(itm.Css_id()).Add_byte_pipe().Add_str_u8(itm.Path()).Add_byte_pipe().Add(itm.Data()).Add_byte_nl();
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private String To_str(Xowd_css_core_itm[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_css_core_itm itm = ary[i];
|
||||
bfr.Add_int_variable(itm.Id()).Add_byte_pipe().Add_str_u8(itm.Key()).Add_byte_pipe().Add_str_u8(itm.Updated_on().XtoStr_fmt_yyyyMMdd_HHmmss()).Add_byte_nl();
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
71
400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_.java
Normal file
71
400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.htmls.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xoh_dom_ {
|
||||
private static final byte[] Lt_bry = Bry_.new_a7("<"), Space_bry = Bry_.new_a7(" ");
|
||||
public static byte[] Query_val_by_where(Xoh_find rv, byte[] src, byte[] where_nde, byte[] where_key, byte[] where_val, byte[] query_key, int bgn) {
|
||||
int src_len = src.length;
|
||||
where_nde = Bry_.Add(Lt_bry, where_nde, Space_bry);
|
||||
while (true) {
|
||||
boolean where_val_found = Select_tag(rv, src, where_nde, where_key, bgn, src_len);
|
||||
if (where_val_found) {
|
||||
int tag_bgn = rv.Tag_bgn();
|
||||
int tag_end = rv.Tag_end();
|
||||
boolean where_val_match = Bry_.Match(src, rv.Val_bgn(), rv.Val_end(), where_val);
|
||||
if (where_val_match) {
|
||||
boolean query_val_found = Find_atr_val_in_tag(rv, src, query_key, tag_bgn, tag_end);
|
||||
if (query_val_found) {
|
||||
return Bry_.Mid(src, rv.Val_bgn(), rv.Val_end());
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else
|
||||
bgn = tag_end + 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static boolean Select_tag(Xoh_find rv, byte[] src, byte[] nde, byte[] key, int rng_bgn, int rng_end) {
|
||||
int tag_bgn = Bry_find_.Find_fwd(src, nde, rng_bgn, rng_end); if (tag_bgn == Bry_.NotFound) return false;
|
||||
int tag_end = Bry_find_.Find_fwd(src, Byte_ascii.Gt, tag_bgn, rng_end); if (tag_end == Bry_.NotFound) return false;
|
||||
int key_bgn = Bry_find_.Find_fwd(src, key, tag_bgn, tag_end); if (key_bgn == Bry_.NotFound) return false;
|
||||
int key_end = key_bgn + key.length;
|
||||
int val_bgn = Bry_find_.Find_fwd(src, Byte_ascii.Quote, key_end, tag_end); if (val_bgn == Bry_.NotFound) return false;
|
||||
++val_bgn;
|
||||
int val_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, val_bgn, tag_end); if (val_end == Bry_.NotFound) return false;
|
||||
rv.Set_all(tag_bgn, tag_end, key_bgn, key_end, val_bgn, val_end);
|
||||
return true;
|
||||
}
|
||||
public static boolean Find_atr_val_in_tag(Xoh_find rv, byte[] src, byte[] key, int tag_bgn, int tag_end) {
|
||||
int key_bgn = Bry_find_.Find_fwd(src, key, tag_bgn, tag_end); if (key_bgn == Bry_.NotFound) return false;
|
||||
int key_end = key_bgn + key.length;
|
||||
int val_bgn = Bry_find_.Find_fwd(src, Byte_ascii.Quote, key_end, tag_end); if (val_bgn == Bry_.NotFound) return false;
|
||||
++val_bgn;
|
||||
int val_end = Bry_find_.Find_fwd(src, Byte_ascii.Quote, val_bgn, tag_end); if (val_end == Bry_.NotFound) return false;
|
||||
rv.Set_all(tag_bgn, tag_end, key_bgn, key_end, val_bgn, val_end);
|
||||
return true;
|
||||
}
|
||||
public static String Title_by_href(byte[] href, byte[] html_src) {
|
||||
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.A_name_bry, Html_atr_.Href_bry, href, gplx.xowa.htmls.Xoh_consts.Atr_xowa_title_bry, 0);
|
||||
return String_.new_u8(xowa_title);
|
||||
} private static final Xoh_find dom_find = new Xoh_find();
|
||||
}
|
||||
45
400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_tst.java
Normal file
45
400_xowa/src/gplx/xowa/htmls/doms/Xoh_dom_tst.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.htmls.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_dom_tst {
|
||||
@Test public void Find_atr() {
|
||||
String src = "a <nde0 atr0=\"val0\" atr1=\"val1\"/> b <nde1 atr0=\"val3\" atr1=\"val4\"/> c";
|
||||
tst_Find(src, "nde0", "atr0", "val0", "atr1", "val1"); // match nde0
|
||||
tst_Find(src, "nde1", "atr0", "val3", "atr1", "val4"); // match nde1
|
||||
tst_Find(src, "nde0", "atr0", "val5", "atr1", null); // wrong val
|
||||
tst_Find(src, "nde0", "atr2", "val0", "atr1", null); // wrong key
|
||||
tst_Find(src, "nde2", "atr0", "val0", "atr1", null); // wrong nde
|
||||
}
|
||||
@Test public void Title_by_href() {// PURPOSE: handle content-editable=n and finding file directly for download
|
||||
Title_by_href_tst
|
||||
( "/wiki/File:Bazille,_Fr%C3%A9d%C3%A9ric_%7E_Le_Petit_Jardinier_%28The_Little_Gardener%29,_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg"
|
||||
, "<a href=\"lure\" xowa_title=\"wrong\"></a><a href=\"/wiki/File:Bazille,_Fr%C3%A9d%C3%A9ric_%7E_Le_Petit_Jardinier_%28The_Little_Gardener%29,_c1866-67_oil_on_canvas_Museum_of_Fine_Arts,_Houston.jpg\" xowa_title=\"find_me\"></a>"
|
||||
, "find_me"
|
||||
);
|
||||
}
|
||||
private void tst_Find(String src, String where_nde, String where_key, String where_val, String select_key, String expd) {
|
||||
Xoh_find rv = new Xoh_find();
|
||||
byte[] actl = Xoh_dom_.Query_val_by_where(rv, Bry_.new_u8(src), Bry_.new_u8(where_nde), Bry_.new_u8(where_key), Bry_.new_u8(where_val), Bry_.new_u8(select_key), 0);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
private void Title_by_href_tst(String href, String html_src, String expd) {
|
||||
String actl = Xoh_dom_.Title_by_href(Bry_.new_u8(href), Bry_.new_u8(html_src));
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/htmls/doms/Xoh_find.java
Normal file
29
400_xowa/src/gplx/xowa/htmls/doms/Xoh_find.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.htmls.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_find {
|
||||
public int Tag_bgn() {return tag_bgn;} public Xoh_find Tag_bgn_(int v) {tag_bgn = v; return this;} private int tag_bgn;
|
||||
public int Tag_end() {return tag_end;} public Xoh_find Tag_end_(int v) {tag_end = v; return this;} private int tag_end;
|
||||
public int Key_bgn() {return key_bgn;} public Xoh_find Key_bgn_(int v) {key_bgn = v; return this;} private int key_bgn;
|
||||
public int Key_end() {return key_end;} public Xoh_find Key_end_(int v) {key_end = v; return this;} private int key_end;
|
||||
public int Val_bgn() {return val_bgn;} public Xoh_find Val_bgn_(int v) {val_bgn = v; return this;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} public Xoh_find Val_end_(int v) {val_end = v; return this;} private int val_end;
|
||||
public void Set_all(int tag_bgn, int tag_end, int key_bgn, int key_end, int val_bgn, int val_end) {
|
||||
this.tag_bgn = tag_bgn; this.tag_end = tag_end; this.key_bgn = key_bgn; this.key_end = key_end; this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
}
|
||||
}
|
||||
89
400_xowa/src/gplx/xowa/htmls/hdumps/Xohd_hdump_rdr.java
Normal file
89
400_xowa/src/gplx/xowa/htmls/hdumps/Xohd_hdump_rdr.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.abrvs.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.guis.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xohd_hdump_rdr {
|
||||
private final Bry_bfr_mkr bfr_mkr; private final Xow_hzip_mgr hzip_mgr;
|
||||
private final Xohd_abrv_mgr abrv_mgr; private final Xohd_page_html_mgr__load load_mgr;
|
||||
private Xowd_db_mgr core_data_mgr; private final Xowd_page_itm dbpg = new Xowd_page_itm();
|
||||
private final Xow_wiki wiki;
|
||||
public Xohd_hdump_rdr(Xoa_app app, Xow_wiki wiki) {
|
||||
this.bfr_mkr = app.Utl__bfr_mkr(); this.hzip_mgr = wiki.Html__hzip_mgr(); this.wiki = wiki;
|
||||
abrv_mgr = new Xohd_abrv_mgr(app.Usr_dlg(), app.Fsys_mgr(), app.Utl__encoder_mgr().Fsys(), wiki.Domain_bry());
|
||||
load_mgr = new Xohd_page_html_mgr__load(); // TODO: get db_id
|
||||
}
|
||||
public void Init_by_db(Xowd_db_mgr core_data_mgr) {this.core_data_mgr = core_data_mgr;}
|
||||
public void Get_by_ttl(Xoae_page page) {
|
||||
Xog_page hpg = new Xog_page();
|
||||
Get_by_ttl(hpg, page.Ttl());
|
||||
page.Hdump_data().Body_(hpg.Page_body());
|
||||
page.Root_(new Xop_root_tkn());
|
||||
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_stub(hpg.Sidebar_div()));
|
||||
Load_module_mgr(html_data.Head_mgr(), hpg);
|
||||
for (gplx.xowa.htmls.hdumps.core.Xohd_data_itm__base itm : hpg.Img_itms())
|
||||
page.Hdump_data().Imgs_add(itm);
|
||||
}
|
||||
public void Get_by_ttl(Xog_page rv, Xoa_ttl ttl) {
|
||||
synchronized (dbpg) {
|
||||
dbpg.Clear();
|
||||
if ( !Get_by_ttl__fill_hpg(rv, ttl)
|
||||
|| rv.Page_body() == null) { // occurs when row exists in page_table, but not in html_table
|
||||
rv.Exists_n_();
|
||||
return;
|
||||
}
|
||||
Bry_bfr bfr = bfr_mkr.Get_m001();
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.abrv: ttl=~{0}", ttl.Full_db_as_str());
|
||||
byte[] body_bry = abrv_mgr.Parse(bfr, rv);
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.hzip: ttl=~{0}", ttl.Full_db_as_str());
|
||||
body_bry = hzip_mgr.Parse(bfr, ttl.Page_db(), body_bry, rv.Redlink_uids());
|
||||
bfr.Mkr_rls();
|
||||
rv.Page_body_(body_bry);
|
||||
}
|
||||
}
|
||||
private boolean Get_by_ttl__fill_hpg(Xog_page rv, Xoa_ttl ttl) {
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.meta: ttl=~{0}", ttl.Full_db_as_str());
|
||||
core_data_mgr.Tbl__page().Select_by_ttl(dbpg, ttl.Ns(), ttl.Page_db()); // get rows from db
|
||||
if (dbpg.Redirect_id() != -1) Get_by_ttl__resolve_redirect(dbpg, rv);
|
||||
if (dbpg.Html_db_id() == -1) return false; // dbpg does not hdump; exit;
|
||||
rv.Init(wiki, dbpg.Id(), null, ttl); // FIXME
|
||||
Xowd_db_file html_db = core_data_mgr.Dbs__get_at(dbpg.Html_db_id());
|
||||
load_mgr.Load_page(wiki, rv, html_db.Tbl__html(), dbpg.Id(), ttl);
|
||||
return true;
|
||||
}
|
||||
private void Get_by_ttl__resolve_redirect(Xowd_page_itm dbpg, Xog_page hpg) {
|
||||
int redirect_count = 0;
|
||||
while (redirect_count < 5) {
|
||||
int redirect_id = dbpg.Redirect_id();
|
||||
core_data_mgr.Tbl__page().Select_by_id(dbpg, redirect_id);
|
||||
if (redirect_id == -1) break;
|
||||
}
|
||||
}
|
||||
public static void Load_module_mgr(Xoh_head_mgr page_module_mgr, Xog_page hpg) {
|
||||
Xopg_module_mgr dump_module_mgr = hpg.Head_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());
|
||||
}
|
||||
}
|
||||
63
400_xowa/src/gplx/xowa/htmls/hdumps/Xohd_hdump_wtr.java
Normal file
63
400_xowa/src/gplx/xowa/htmls/hdumps/Xohd_hdump_wtr.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.abrvs.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.wikis.dbs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.guis.*;
|
||||
public class Xohd_hdump_wtr {
|
||||
private final Bry_bfr_mkr bfr_mkr; private final Xoh_page_wtr_mgr page_wtr_mgr;
|
||||
private final Xohd_page_html_mgr__save save_mgr; private Xowd_db_mgr core_data_mgr;
|
||||
public Xohd_hdump_wtr(Xoa_app app, Xowe_wiki wiki) {
|
||||
this.bfr_mkr = app.Utl__bfr_mkr(); this.page_wtr_mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
save_mgr = new Xohd_page_html_mgr__save();
|
||||
}
|
||||
public void Init_by_db(Xowd_db_mgr core_data_mgr) {
|
||||
this.core_data_mgr = core_data_mgr;
|
||||
}
|
||||
public void Save(Xoae_page page) {
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_m001();
|
||||
Generate_hdump(tmp_bfr, page);
|
||||
int html_db_id = page.Revision_data().Html_db_id();
|
||||
Xowd_db_file hdump_db = Xowd_db_file.Null;
|
||||
if (html_db_id == -1) {
|
||||
hdump_db = core_data_mgr.Db__html();
|
||||
if (hdump_db == null) {
|
||||
hdump_db = core_data_mgr.Dbs__make_by_tid(Xowd_db_file_.Tid_html_data);
|
||||
Xowd_html_tbl tbl = hdump_db.Tbl__html();
|
||||
tbl.Create_tbl();
|
||||
}
|
||||
|
||||
html_db_id = hdump_db.Id();
|
||||
page.Revision_data().Html_db_id_(html_db_id);
|
||||
core_data_mgr.Tbl__page().Update__html_db_id(page.Revision_data().Id(), html_db_id);
|
||||
}
|
||||
else {
|
||||
hdump_db = core_data_mgr.Dbs__get_at(html_db_id);
|
||||
html_db_id = hdump_db.Id();
|
||||
// return; // DELETE: don't remember why return was here; DATE:2015-06-06
|
||||
}
|
||||
save_mgr.Update(tmp_bfr, hdump_db.Tbl__html(), page);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
public void Generate_hdump(Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
page_wtr_mgr.Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
if (!Env_.Mode_testing()) page.Wikie().Html_mgr().Hzip_mgr().Write(tmp_bfr, new Xodump_stats_itm(), page.Url().To_bry_full_wo_qargs(), tmp_bfr.To_bry_and_clear()); // hzip data;
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear()); // write to body bry
|
||||
}
|
||||
}
|
||||
159
400_xowa/src/gplx/xowa/htmls/hdumps/Xohd_hdump_wtr_tst.java
Normal file
159
400_xowa/src/gplx/xowa/htmls/hdumps/Xohd_hdump_wtr_tst.java
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
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.htmls.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hdumps.pages.*; import gplx.xowa.xtns.hieros.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xohd_hdump_wtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xohd_hdump_wtr_fxt fxt = new Xohd_hdump_wtr_fxt();
|
||||
// @Test public void Image_full() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png));
|
||||
// fxt.Test_write_all
|
||||
// ( "[[File:A.png|test_caption]]"
|
||||
// , "<a xtid='a_img_full' xatrs='1|0|0||0|test_caption'/>"
|
||||
// );
|
||||
// }
|
||||
@Test public void Image_thumb() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.N, Xof_ext_.Id_png));
|
||||
// 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'>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
// , " test_caption"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , "</div>"
|
||||
// ));
|
||||
}
|
||||
@Test public void Audio_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer("A.oga", 0, 220, -1, Bool_.N, Xof_ext_.Id_oga));
|
||||
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'>"
|
||||
, " <div id=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer("A.ogv", 0, 0, 0, Bool_.N, Xof_ext_.Id_ogv));
|
||||
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'>"
|
||||
, " <div id=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
, " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div><xowa_play id='0'/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</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() {
|
||||
Gallery_mgr_base.File_found_mode = Bool_.__byte;
|
||||
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=\"width: 150px;\">"
|
||||
, " <div xowa_gly_img_pad='0'>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class=\"gallerytext\"><p>A1"
|
||||
, "</p>"
|
||||
, ""
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xodb_hdump_mgr__base_fxt {
|
||||
protected Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
protected Xowe_wiki wiki; protected Xoae_page page;
|
||||
private Xohd_hdump_wtr hdump_wtr;
|
||||
public Xop_fxt Fxt() {return fxt;} protected Xop_fxt fxt;
|
||||
public void Clear() {
|
||||
if (fxt == null) {
|
||||
fxt = new Xop_fxt();
|
||||
wiki = fxt.Wiki();
|
||||
page = wiki.Parser_mgr().Ctx().Cur_page();
|
||||
hdump_wtr = new Xohd_hdump_wtr(fxt.App(), fxt.Wiki());
|
||||
}
|
||||
fxt.Reset();
|
||||
page.Revision_data().Id_(0);
|
||||
this.Clear_end();
|
||||
}
|
||||
@gplx.Virtual public void Clear_end() {}
|
||||
@gplx.Virtual public void Exec_write(String raw) {
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_u8(raw));
|
||||
page.Root_(root);
|
||||
hdump_wtr.Generate_hdump(bfr, page);
|
||||
}
|
||||
public Xohd_data_itm__base Make_xfer(String lnki_ttl, int html_uid, int html_w, int html_h, boolean file_is_orig, int file_ext_id) {
|
||||
return new Xohd_data_itm__img().Data_init_base
|
||||
(Bry_.new_u8(lnki_ttl), Byte_.Zero, Xof_img_size.Upright_null, 0, 0, Xof_lnki_time.Null, Xof_lnki_page.Null, Xohd_data_itm__base.File_repo_id_null, file_ext_id, file_is_orig, html_w, html_uid, html_w, html_h);
|
||||
}
|
||||
}
|
||||
class Xohd_hdump_wtr_fxt extends Xodb_hdump_mgr__base_fxt {
|
||||
private List_adp expd_itms_xfers = List_adp_.new_();
|
||||
@Override public void Clear_end() {expd_itms_xfers.Clear();}
|
||||
public void Expd_itms_xfers(Xohd_data_itm__base... itms) {expd_itms_xfers.Add_many((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);
|
||||
String actl_html = String_.new_u8(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(List_adp list) {
|
||||
int len = list.Count();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_data_itm__base itm = (Xohd_data_itm__base)list.Get_at(i);
|
||||
rv[i] = itm.Data_print();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
74
400_xowa/src/gplx/xowa/htmls/hdumps/abrvs/Xohd_abrv_.java
Normal file
74
400_xowa/src/gplx/xowa/htmls/hdumps/abrvs/Xohd_abrv_.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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.htmls.hdumps.abrvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xohd_abrv_ {
|
||||
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
|
||||
, Tid_redlink = 12, Tid_toc = 13, Tid_hdr_bgn = 14, Tid_hdr_end = 15
|
||||
;
|
||||
public static final byte[]
|
||||
Key_dir = Bry_.new_a7("~{xowa_dir}")
|
||||
, Key_img = Bry_.new_a7("xowa_img='")
|
||||
, Key_img_style = Bry_.new_a7("xowa_img_style='")
|
||||
, Key_file_play = Bry_.new_a7("<xowa_play id='")
|
||||
, Key_file_info = Bry_.new_a7("<xowa_info id='")
|
||||
, Key_file_mgnf = Bry_.new_a7("<xowa_mgnf id='")
|
||||
, Key_hiero_dir = Bry_.new_a7("~{xowa_hiero_dir}")
|
||||
, Key_gallery_box_max = Bry_.new_a7("xowa_gly_box_max='")
|
||||
, Key_gallery_box_w = Bry_.new_a7("xowa_gly_box_w='")
|
||||
, Key_gallery_img_w = Bry_.new_a7("xowa_gly_img_w='")
|
||||
, Key_gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
|
||||
, Key_redlink = Bry_.new_a7("xowa_redlink='")
|
||||
, Key_toc = Bry_.new_a7("~{xowa_toc}")
|
||||
, Key_hdr_bgn = Bry_.new_a7("<h")
|
||||
, Key_hdr_end = Bry_.new_a7("</h")
|
||||
;
|
||||
public static final byte[]
|
||||
A_href_bgn = Bry_.new_a7("/wiki/File:")
|
||||
, Bry_img_style_bgn = Bry_.new_a7("style='width:")
|
||||
, Bry_img_style_end = Bry_.new_a7("px;'")
|
||||
, Html_redlink_bgn = Bry_.Add(Bry_.new_a7("\" "), Key_redlink)
|
||||
, Html_redlink_end = Bry_.new_a7("'>")
|
||||
;
|
||||
public static Btrie_slim_mgr new_trie() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs();
|
||||
trie_itm(rv, Tid_dir , Byte_ascii.Null , 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.Null , 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);
|
||||
trie_itm(rv, Tid_redlink , Byte_ascii.Apos , Key_redlink);
|
||||
trie_itm(rv, Tid_toc , Byte_ascii.Null , Key_toc);
|
||||
// trie_itm(rv, Tid_hdr_bgn , Byte_ascii.Null , Key_hdr_bgn);
|
||||
// trie_itm(rv, Tid_hdr_end , Byte_ascii.Null , Key_hdr_end);
|
||||
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);
|
||||
}
|
||||
}
|
||||
162
400_xowa/src/gplx/xowa/htmls/hdumps/abrvs/Xohd_abrv_mgr.java
Normal file
162
400_xowa/src/gplx/xowa/htmls/hdumps/abrvs/Xohd_abrv_mgr.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
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.htmls.hdumps.abrvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.lnkis.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_abrv_mgr {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); private Bry_rdr bry_rdr = new Bry_rdr(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private Xoh_cfg_file cfg_file; private Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
|
||||
private byte[] root_dir, file_dir, file_dir_comm, file_dir_wiki, hiero_img_dir;
|
||||
private byte[] wiki_domain;
|
||||
private final Xohd_abrv_wkr__hdr wkr__hdr = new Xohd_abrv_wkr__hdr();
|
||||
public Xohd_abrv_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder, byte[] wiki_domain) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
this.root_dir = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.file_dir = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.hiero_img_dir = gplx.xowa.xtns.hieros.Hiero_xtn_mgr.Hiero_root_dir(fsys_mgr).GenSubDir("img").To_http_file_bry();
|
||||
this.cfg_file = new Xoh_cfg_file(fsys_encoder, fsys_mgr.Bin_xowa_dir());
|
||||
this.html_fmtr = Xoh_file_html_fmtr__hdump.Base;
|
||||
this.wiki_domain = wiki_domain;
|
||||
}
|
||||
private void Init() {
|
||||
file_dir_comm = tmp_bfr.Add(file_dir).Add(Xow_domain_itm_.Bry__commons).Add_byte_slash().To_bry_and_clear();
|
||||
file_dir_wiki = tmp_bfr.Add(file_dir).Add(wiki_domain).Add_byte_slash().To_bry_and_clear();
|
||||
}
|
||||
public byte[] Parse(Bry_bfr rv, Xog_page hpg) {
|
||||
this.Init();
|
||||
byte[] src = hpg.Page_body(); int len = src.length;
|
||||
Xohd_data_itm__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length;
|
||||
bry_rdr.Init(src);
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
|
||||
if (o == null) { // regular char; set bgn and move to next char
|
||||
if (rng_bgn == -1) rng_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else { // special tkn
|
||||
if (rng_bgn != -1) { // pending rng exists; add it
|
||||
rv.Add_mid(src, rng_bgn, pos);
|
||||
rng_bgn = -1;
|
||||
}
|
||||
pos = trie.Match_pos(); // position after match; EX: "xowa_img='" positions after "'"
|
||||
Hdump_html_fmtr_itm itm = (Hdump_html_fmtr_itm)o;
|
||||
pos = Write_data(rv, html_fmtr, hpg, src, imgs, imgs_len, pos, itm); // note no +1; Write_data return pos after }
|
||||
}
|
||||
}
|
||||
if (rng_bgn != -1) rv.Add_mid(src, rng_bgn, len);
|
||||
return rv.To_bry_and_clear();
|
||||
}
|
||||
private int Write_data(Bry_bfr bfr, Xoh_file_html_fmtr__base fmtr, Xog_page hpg, byte[] src, Xohd_data_itm__base[] imgs, int imgs_len, int uid_bgn, Hdump_html_fmtr_itm itm) {
|
||||
bry_rdr.Pos_(uid_bgn);
|
||||
int uid = itm.Subst_end_byte() == Byte_ascii.Null ? -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;
|
||||
byte tid = itm.Tid();
|
||||
switch (tid) {
|
||||
case Xohd_abrv_.Tid_dir: bfr.Add(root_dir); return rv;
|
||||
case Xohd_abrv_.Tid_hiero_dir: bfr.Add(hiero_img_dir); return rv;
|
||||
case Xohd_abrv_.Tid_redlink: return Write_redlink(bfr, hpg, uid, rv);
|
||||
case Xohd_abrv_.Tid_hdr_bgn: return wkr__hdr.Write_bgn(bfr, hpg, uid, rv);
|
||||
case Xohd_abrv_.Tid_hdr_end: return wkr__hdr.Write_end(bfr, hpg, uid, 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; hpg=~{0} text=~{1}", hpg.Url().To_str(), 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; hpg=~{0} idx=~{1} len=~{2}", hpg.Url().To_str(), uid, imgs_len); return uid_end;}
|
||||
if (uid >= imgs.length) return rv;
|
||||
Xohd_data_itm__base img = imgs[uid];
|
||||
int img_view_w = img.Html_w();
|
||||
switch (tid) {
|
||||
case Xohd_abrv_.Tid_img_style:
|
||||
bfr.Add(Xohd_abrv_.Bry_img_style_bgn);
|
||||
bfr.Add_int_variable(img_view_w);
|
||||
bfr.Add(Xohd_abrv_.Bry_img_style_end);
|
||||
return rv;
|
||||
}
|
||||
byte[] a_title = img.Lnki_ttl();
|
||||
byte[] a_href = Bry_.Add(Xohd_abrv_.A_href_bgn, a_title);
|
||||
try {
|
||||
switch (tid) {
|
||||
case Xohd_abrv_.Tid_file_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, cfg_file.Img_media_info_btn()); return rv;
|
||||
case Xohd_abrv_.Tid_file_mgnf: fmtr.Html_thumb_part_magnify (bfr, uid, a_href, a_title, cfg_file.Img_thumb_magnify()); return rv;
|
||||
case Xohd_abrv_.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, cfg_file.Img_media_play_btn()); return rv;
|
||||
case Xohd_abrv_.Tid_gallery_box_max: {
|
||||
Xohd_data_itm__gallery_mgr gly = (Xohd_data_itm__gallery_mgr)hpg.Gallery_itms().Get_by(uid);
|
||||
if (gly != null) { // -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 Xohd_abrv_.Tid_gallery_box_w: {
|
||||
Xohd_data_itm__gallery_itm gly = (Xohd_data_itm__gallery_itm)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 Xohd_abrv_.Tid_gallery_img_w: {
|
||||
Xohd_data_itm__gallery_itm gly = (Xohd_data_itm__gallery_itm)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 Xohd_abrv_.Tid_gallery_img_pad: {
|
||||
Xohd_data_itm__gallery_itm gly = (Xohd_data_itm__gallery_itm)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;
|
||||
}
|
||||
}
|
||||
url_bldr.Init_by_root(img.Orig_repo_id() == Xof_repo_itm_.Repo_remote ? file_dir_comm : file_dir_wiki, Byte_ascii.Slash, false, false, 2);
|
||||
url_bldr.Init_by_itm(img.File_is_orig() ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, img.Lnki_ttl(), Xof_file_wkr_.Md5(img.Lnki_ttl()), Xof_ext_.new_by_id_(img.Orig_ext()), img.File_w(), img.Lnki_time(), img.Lnki_page());
|
||||
byte[] img_src = url_bldr.Xto_bry();
|
||||
if (tid == Xohd_abrv_.Tid_img) {
|
||||
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.Html_h());
|
||||
}
|
||||
} catch (Exception e) {Xoa_app_.Usr_dlg().Warn_many("", "", "abrv.read: page=~{0} itm=~{1} err=~{2}", hpg.Url_bry_safe(), img == null ? "<NULL>" : img.Data_print(), Err_.Message_gplx_full(e));}
|
||||
return rv;
|
||||
}
|
||||
private int Write_redlink(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
|
||||
if (hpg.Redlink_uids().Has(redlink_key.Val_(uid)))
|
||||
bfr.Add(Xoh_redlink_utl.Cls_bry);
|
||||
else
|
||||
bfr.Del_by_1();
|
||||
return rv;
|
||||
} private final Int_obj_ref redlink_key = Int_obj_ref.neg1_();
|
||||
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 = Xohd_abrv_.new_trie();
|
||||
}
|
||||
class Hdump_html_fmtr_itm {
|
||||
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;
|
||||
}
|
||||
class Xohd_abrv_wkr__hdr {
|
||||
public int Write_bgn(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
|
||||
return rv;
|
||||
}
|
||||
public int Write_end(Bry_bfr bfr, Xog_page hpg, int uid, int rv) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
153
400_xowa/src/gplx/xowa/htmls/hdumps/abrvs/Xohd_abrv_mgr_tst.java
Normal file
153
400_xowa/src/gplx/xowa/htmls/hdumps/abrvs/Xohd_abrv_mgr_tst.java
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
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.htmls.hdumps.abrvs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_abrv_mgr_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_data_img_basic("A.png", 0, 220, 110);
|
||||
} private final Xohd_abrv_mgr_fxt fxt = new Xohd_abrv_mgr_fxt();
|
||||
@Test public void Img() {
|
||||
fxt .Init_body("<img xowa_img='0' />")
|
||||
.Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' />");
|
||||
}
|
||||
@Test public void Img_style() {
|
||||
fxt .Init_body("<div xowa_img_style='0'>")
|
||||
.Test_html("<div style='width:220px;'>");
|
||||
}
|
||||
@Test public void File_info() {
|
||||
fxt .Init_body("<xowa_info id='0'/>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/info.png\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_mgnf() {
|
||||
fxt .Init_body("<xowa_mgnf id='0'/>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_play() {
|
||||
fxt .Init_body("<xowa_play id='0'/>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </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_data_gly(0, 800);
|
||||
fxt .Init_data_img_gly("A.png", 0, 220, 110, 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;\">"
|
||||
));
|
||||
}
|
||||
@Test public void Redlink() {
|
||||
fxt .Init_data_redlink(1, 2);
|
||||
fxt .Init_body(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"/wiki/A\" xowa_redlink='1'>A</a>"
|
||||
, "<a href=\"/wiki/B\" xowa_redlink='2'>B</a>"
|
||||
, "<a href=\"/wiki/C\" xowa_redlink='3'>C</a>"
|
||||
))
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"/wiki/A\" class='new'>A</a>"
|
||||
, "<a href=\"/wiki/B\" class='new'>B</a>"
|
||||
, "<a href=\"/wiki/C\">C</a>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xohd_abrv_mgr_fxt {
|
||||
private Xohd_abrv_mgr abrv_mgr;
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private List_adp img_list = List_adp_.new_();
|
||||
private Xowe_wiki wiki;
|
||||
public Xog_page Hpg() {return hpg;} private Xog_page hpg = new Xog_page();
|
||||
public void Clear() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
abrv_mgr = new Xohd_abrv_mgr(Gfo_usr_dlg_.Instance, app.Fsys_mgr(), app.Utl__encoder_mgr().Fsys(), wiki.Domain_bry());
|
||||
}
|
||||
public void Clear_imgs() {img_list.Clear();}
|
||||
public Xohd_abrv_mgr_fxt Init_body(String body) {hpg.Page_body_(Bry_.new_u8(body)); return this;}
|
||||
public Xohd_abrv_mgr_fxt Init_data_gly(int uid, int box_max) {hpg.Gallery_itms().Add(uid, new Xohd_data_itm__gallery_mgr(uid, box_max)); return this;}
|
||||
public Xohd_abrv_mgr_fxt Init_data_img_basic(String ttl, int html_uid, int html_w, int html_h) {
|
||||
Xohd_data_itm__img img = new Xohd_data_itm__img();
|
||||
img.Data_init_base(Bry_.new_u8(ttl), Xop_lnki_type.Id_none, Xof_img_size.Upright_null, Xof_img_size.Null, Xof_img_size.Null
|
||||
, Xof_lnki_time.Null, Xof_lnki_page.Null
|
||||
, Xohd_data_itm__base.File_repo_id_commons, Xof_ext_.Id_png, Bool_.N, html_w
|
||||
, html_uid, html_w, html_h
|
||||
);
|
||||
img_list.Add(img);
|
||||
return this;
|
||||
}
|
||||
public Xohd_abrv_mgr_fxt Init_data_img_gly(String ttl, int html_uid, int html_w, int html_h, int box_w, int img_w, int img_pad) {
|
||||
Xohd_data_itm__gallery_itm img = new Xohd_data_itm__gallery_itm();
|
||||
img.Data_init_gallery(box_w, img_w, img_pad);
|
||||
img.Data_init_base(Bry_.new_u8(ttl), Xop_lnki_type.Id_none, Xof_img_size.Upright_null, Xof_img_size.Null, Xof_img_size.Null
|
||||
, Xof_lnki_time.Null, Xof_lnki_page.Null
|
||||
, Xohd_data_itm__base.File_repo_id_commons, Xof_ext_.Id_png, Bool_.N, html_w
|
||||
, html_uid, html_w, html_h
|
||||
);
|
||||
img_list.Add(img);
|
||||
return this;
|
||||
}
|
||||
public Xohd_abrv_mgr_fxt Init_data_redlink(int... uids) {
|
||||
int uids_len = uids.length;
|
||||
for (int i = 0; i < uids_len; ++i) {
|
||||
Int_obj_ref redlink_uid = Int_obj_ref.new_(uids[i]);
|
||||
hpg.Redlink_uids().Add(redlink_uid, redlink_uid);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Xohd_abrv_mgr_fxt Test_html(String expd) {
|
||||
if (img_list.Count() > 0) hpg.Img_itms_((Xohd_data_itm__base[])img_list.To_ary_and_clear(Xohd_data_itm__base.class));
|
||||
byte[] actl = abrv_mgr.Parse(bfr, hpg);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hzips.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.pages.*; import gplx.xowa.guis.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
public class Xob_hdump_bldr {
|
||||
private final Xowd_db_mgr wiki_db_mgr; private final Xob_ns_to_db_mgr ns_to_db_mgr; int prv_row_len = 0;
|
||||
private final Xodump_stats_itm stats_itm = new Xodump_stats_itm(); private final Xodump_stats_tbl stats_tbl;
|
||||
private final Xog_page tmp_hpg = new Xog_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
private final Xohd_page_html_mgr__save hdump_save_mgr = new Xohd_page_html_mgr__save();
|
||||
private final boolean hzip_enabled;
|
||||
public Xob_hdump_bldr(Xow_ns_mgr ns_mgr, Xodb_mgr_sql db_mgr, Db_conn make_conn, long hdump_db_max, boolean hzip_enabled) {
|
||||
this.wiki_db_mgr = db_mgr.Core_data_mgr();
|
||||
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(wiki_db_mgr.Db__core()), wiki_db_mgr, hdump_db_max);
|
||||
this.stats_tbl = new Xodump_stats_tbl(make_conn);
|
||||
Xob_ns_file_itm.Init_ns_bldr_data(Xowd_db_file_.Tid_html_data, ns_mgr, gplx.xowa.apps.apis.xowa.bldrs.imports.Xoapi_import.Ns_file_map__each);
|
||||
this.hzip_enabled = hzip_enabled;
|
||||
}
|
||||
public void Bld_term() {
|
||||
this.Commit();
|
||||
Db_term();
|
||||
}
|
||||
public void Insert_page(Xoae_page page) {
|
||||
Hzip_data(page);
|
||||
tmp_hpg.Ctor_from_page(tmp_bfr, page);
|
||||
Xowd_db_file db_file = ns_to_db_mgr.Get_by_ns(page.Ttl().Ns().Bldr_data(), prv_row_len);
|
||||
this.prv_row_len = hdump_save_mgr.Insert(tmp_bfr, db_file.Tbl__html(), tmp_hpg, page.Hdump_data());
|
||||
stats_tbl.Insert(tmp_hpg, stats_itm, page.Root().Root_src().length, tmp_hpg.Page_body().length, prv_row_len);
|
||||
}
|
||||
public void Commit() {
|
||||
ns_to_db_mgr.Commit();
|
||||
// wiki_db_mgr.Tbl__cfg().Update_long(Cfg_grp_hdump_make, Cfg_itm_hdump_size, hdump_db_size); // update cfg; should happen after commit entries
|
||||
}
|
||||
private void Db_term() {
|
||||
ns_to_db_mgr.Rls_all();
|
||||
}
|
||||
// private static final String Cfg_grp_hdump_make = "hdump.make", Cfg_itm_hdump_size = "hdump.size";
|
||||
private void Hzip_data(Xoae_page page) {
|
||||
Xowe_wiki wiki = page.Wikie();
|
||||
Xow_hzip_mgr hzip_mgr = wiki.Html_mgr().Hzip_mgr();
|
||||
page.File_queue().Clear(); // need to reset uid to 0, else xowa_file_# will resume from last
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_page_.Tid_read).Write_body(tmp_bfr, Xoh_wtr_ctx.Hdump, page); // write to html again, except in hdump mode
|
||||
if (hzip_enabled) hzip_mgr.Write(tmp_bfr, stats_itm, page.Url().To_bry_full_wo_qargs(), tmp_bfr.To_bry_and_clear()); // hzip data
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear()); // write to body bry
|
||||
}
|
||||
}
|
||||
class Xob_ns_to_db_wkr__html implements Xob_ns_to_db_wkr {
|
||||
private final Xowd_db_file page_db;
|
||||
public Xob_ns_to_db_wkr__html(Xowd_db_file page_db) {this.page_db = page_db;}
|
||||
public byte Db_tid() {return Xowd_db_file_.Tid_html_data;}
|
||||
public void Tbl_init(Xowd_db_file db) {
|
||||
Xowd_html_tbl tbl = db.Tbl__html();
|
||||
tbl.Create_tbl();
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Tbl_term(Xowd_db_file db) {
|
||||
db.Tbl__text().Insert_end();
|
||||
Db_conn db_conn = db.Conn();
|
||||
db.Tbl__html().Create_idx();
|
||||
Db_attach_cmd.new_(page_db.Conn(), "html_db", db.Url())
|
||||
.Add_fmt("hdump.update page.html_db_id", Sql_update_page_html_db_id, db.Id())
|
||||
.Exec();
|
||||
db_conn.Rls_conn();
|
||||
}
|
||||
private static final String Sql_update_page_html_db_id = String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO page (page_id, page_namespace, page_title, page_is_redirect, page_touched, page_len, page_random_int, page_text_db_id, page_html_db_id, page_redirect_id)"
|
||||
, "SELECT p.page_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", p.page_is_redirect"
|
||||
, ", p.page_touched"
|
||||
, ", p.page_len"
|
||||
, ", p.page_random_int"
|
||||
, ", p.page_text_db_id"
|
||||
, ", {0}"
|
||||
, ", p.page_redirect_id"
|
||||
, "FROM page p"
|
||||
, " JOIN <attach_db>html h ON p.page_id = h.page_id"
|
||||
);
|
||||
}
|
||||
117
400_xowa/src/gplx/xowa/htmls/hdumps/bldrs/Xob_hdump_img_cmd.java
Normal file
117
400_xowa/src/gplx/xowa/htmls/hdumps/bldrs/Xob_hdump_img_cmd.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.htmls.hdumps.core.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.guis.*;
|
||||
class Xob_hdump_img_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private Xowd_html_tbl html_tbl;
|
||||
public Xob_hdump_img_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Key_const;} public static final String Key_const = "hdump.make.imgs";
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_run() {Exec_main();}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_term() {}
|
||||
private void Exec_main() {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
Db_conn conn = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir()).Conn();
|
||||
Db_rdr rdr = conn.Stmt_new(gplx.dbs.qrys.Db_qry_sql.rdr_(Sql_select)).Exec_select__rls_auto();
|
||||
html_tbl = new Xowd_html_tbl(conn, wiki.Db_mgr_as_sql().Core_data_mgr().Props().Zip_tid_text());
|
||||
int cur_page_id = -1;
|
||||
while (rdr.Move_next()) {
|
||||
int lnki_page_id = rdr.Read_int("lnki_page_id");
|
||||
if (lnki_page_id != cur_page_id) {
|
||||
Save(cur_page_id, bfr.To_bry_and_clear());
|
||||
cur_page_id = lnki_page_id;
|
||||
}
|
||||
// int html_uid = rdr.Read_int(1);
|
||||
// byte[] lnki_ttl = rdr.Read_bry(2);
|
||||
// int html_w = rdr.Read_int(3);
|
||||
// int html_h = rdr.Read_int(4);
|
||||
// int file_repo_id = rdr.Read_int(5);
|
||||
// int file_ext_id = rdr.Read_int(6);
|
||||
// boolean file_is_orig = rdr.Read_int(7) == 1;
|
||||
// double file_time = rdr.Read_double(8);
|
||||
// int file_page = rdr.Read_int(9);
|
||||
// Xohd_data_itm__base.Data_write_static(bfr, 0, lnki_ttl, Byte_.Zero, 0, 0, Xof_img_size.Upright_null, html_uid, html_w, html_h, file_repo_id, file_ext_id, file_is_orig, html_w, file_time, file_page);
|
||||
}
|
||||
Save(cur_page_id, bfr.To_bry_and_clear());;
|
||||
}
|
||||
private void Save(int page_id, byte[] data) {
|
||||
if (page_id == -1 || data.length == 0) return;
|
||||
html_tbl.Insert(page_id, Xohd_data_tid.Tid_img, data);
|
||||
}
|
||||
private static final String Sql_select = String_.Concat_lines_nl_skip_last
|
||||
( "SELECT lt.lnki_page_id"
|
||||
, ", lt.html_uid"
|
||||
, ", lt.lnki_ttl"
|
||||
, ", xr.file_w"
|
||||
, ", xr.file_h"
|
||||
, ", xr.orig_repo"
|
||||
, ", xr.lnki_ext"
|
||||
, ", xr.file_is_orig"
|
||||
, ", xr.lnki_time"
|
||||
, ", xr.lnki_page"
|
||||
, "FROM xfer_regy xr"
|
||||
, " JOIN lnki_temp lt ON xr.file_ttl = lt.lnki_ttl"
|
||||
// , " LEFT JOIN xtn_gallery lt ON xr.file_ttl = lt.lnki_ttl"
|
||||
// , " LEFT JOIN xtn_imap lt ON xr.file_ttl = lt.lnki_ttl"
|
||||
, "ORDER BY "
|
||||
, " lt.lnki_page_id"
|
||||
, ", lt.lnki_uid"
|
||||
);
|
||||
}
|
||||
interface Page_async_cmd {
|
||||
void Prep();
|
||||
void Exec();
|
||||
}
|
||||
class Page_async_cmd__img implements Page_async_cmd {
|
||||
private Xog_page hpg;
|
||||
private List_adp missing = List_adp_.new_();
|
||||
public Page_async_cmd__img(Xog_page hpg) {this.hpg = hpg;}
|
||||
public void Prep() {
|
||||
int len = hpg.Img_count();
|
||||
Xohd_data_itm__base[] ary = hpg.Img_itms();
|
||||
missing.Clear();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_data_itm__base itm = ary[i];
|
||||
boolean exists = Io_mgr.Instance.ExistsFil(itm.Html_view_url());
|
||||
if (!exists) missing.Add(itm);
|
||||
}
|
||||
}
|
||||
public void Exec() {
|
||||
int len = missing.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// Xohd_data_itm__base itm = (Xohd_data_itm__base)missing.Get_at(i);
|
||||
// byte[] bytes = null; //fsdb.Db_get()ttl, file_w,....):
|
||||
// Write file(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
CREATE TABLE xtn_gallery
|
||||
( src_page_id integer NOT NULL
|
||||
, html_uid integer NOT NULL
|
||||
, box_max integer NOT NULL
|
||||
, box_w integer NOT NULL
|
||||
, img_w integer NOT NULL
|
||||
, img_pad integer NOT NULL
|
||||
);
|
||||
*/
|
||||
@@ -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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.brys.*; import gplx.dbs.*;
|
||||
public class Xob_link_dump_cmd {
|
||||
private Xob_link_dump_tbl tbl; private int src_page_id; private Io_url page_db_url;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
this.page_db_url = wiki.Data__core_mgr().Db__core().Url();
|
||||
this.tbl = Xob_link_dump_tbl.Get_or_new(wiki);
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Page_bgn(int src_page_id) {this.src_page_id = src_page_id;}
|
||||
public void Add(int src_html_uid, int trg_ns_id, byte[] trg_ttl) {tbl.Insert_cmd_by_batch(src_page_id, src_html_uid, trg_ns_id, trg_ttl);}
|
||||
public void Wkr_commit() {tbl.Conn().Txn_sav();}
|
||||
public void Wkr_end() {
|
||||
try {
|
||||
tbl.Insert_end();
|
||||
tbl.Create_idx_1();
|
||||
Db_conn conn = tbl.Conn();
|
||||
Db_attach_cmd.new_(conn, "page_db", page_db_url)
|
||||
.Add_fmt("update trg_page_id", String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO link_dump"
|
||||
, "SELECT r.uid"
|
||||
, ", r.src_page_id"
|
||||
, ", r.src_html_uid"
|
||||
, ", Coalesce(p.page_id, -1)"
|
||||
, ", r.trg_ns"
|
||||
, ", r.trg_ttl"
|
||||
, "FROM link_dump r"
|
||||
, " LEFT JOIN page_db.page p ON r.trg_ns = p.page_namespace AND r.trg_ttl = p.page_title"
|
||||
, ";"
|
||||
))
|
||||
.Exec();
|
||||
conn.Exec_sql("UPDATE link_dump SET trg_ns = -1 AND trg_ttl = '' WHERE trg_page_id != -1;");
|
||||
tbl.Create_idx_2();
|
||||
conn.Env_vacuum();
|
||||
} catch (Exception e) {
|
||||
Tfds.Write(Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*;
|
||||
class Xob_link_dump_tbl implements RlsAble {
|
||||
public static final String Tbl_name = "link_dump"; private static final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
public static final String
|
||||
Fld_uid = flds.Add_int_pkey_autonum("uid")
|
||||
, Fld_src_page_id = flds.Add_int("src_page_id")
|
||||
, Fld_src_html_uid = flds.Add_int("src_html_uid")
|
||||
, Fld_trg_page_id = flds.Add_int_dflt("trg_page_id", -1)
|
||||
, Fld_trg_ns = flds.Add_int("trg_ns")
|
||||
, Fld_trg_ttl = flds.Add_str("trg_ttl", 255)
|
||||
;
|
||||
private Db_stmt stmt_insert;
|
||||
public Xob_link_dump_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(Tbl_name, flds));}
|
||||
public void Create_idx_1() {
|
||||
conn.Ddl_create_idx
|
||||
( Db_meta_idx.new_normal_by_tbl(Tbl_name, "src", Fld_src_page_id, Fld_src_html_uid)
|
||||
, Db_meta_idx.new_normal_by_tbl(Tbl_name, "trg_temp", Fld_trg_ns, Fld_trg_ttl)
|
||||
);
|
||||
}
|
||||
public void Create_idx_2() {
|
||||
conn.Ddl_create_idx
|
||||
( Db_meta_idx.new_normal_by_tbl(Tbl_name, "trg", Fld_trg_page_id, Fld_src_page_id, Fld_src_html_uid)
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn("bldr__link_dump");}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int src_page_id, int src_html_uid, int trg_ns, byte[] trg_ttl) {
|
||||
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(Tbl_name, flds.To_str_ary_wo_autonum());
|
||||
stmt_insert.Clear().Val_int(Fld_src_page_id, src_page_id)
|
||||
.Val_int(Fld_src_html_uid, src_html_uid).Val_int(Fld_trg_page_id, -1).Val_int(Fld_trg_ns, trg_ns).Val_bry_as_str(Fld_trg_ttl, trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Db_rdr Select_missing() {
|
||||
return conn.Stmt_select_order(Tbl_name, flds, String_.Ary(Fld_trg_page_id), Fld_src_page_id, Fld_src_html_uid)
|
||||
.Crt_int(Fld_trg_page_id, -1).Exec_select__rls_auto();
|
||||
}
|
||||
public static Xob_link_dump_tbl Get_or_new(Xow_wiki wiki) {
|
||||
Db_conn_bldr_data conn_data = Db_conn_bldr.Instance.Get_or_new(wiki.Fsys_mgr().Root_dir().GenSubFil("xowa.temp.redlink.sqlite3"));
|
||||
Xob_link_dump_tbl rv = new Xob_link_dump_tbl(conn_data.Conn());
|
||||
if (conn_data.Created()) rv.Create_tbl();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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.htmls.hdumps.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xob_redlink_mkr_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
private int commit_interval = 10000, commit_count = 0;
|
||||
public Xob_redlink_mkr_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
public String Cmd_key() {return Xob_cmd_keys.Key_html_redlinks;}
|
||||
public void Cmd_run() {Read_data();}
|
||||
private void Read_data() {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
wiki.Init_assert();
|
||||
Xowd_db_file core_db = wiki.Data__core_mgr().Db__core();
|
||||
Xob_db_file link_dump_db = Xob_db_file.new__redlink(wiki.Fsys_mgr().Root_dir());
|
||||
Db_attach_rdr attach_rdr = new Db_attach_rdr(link_dump_db.Conn(), "page_db", core_db.Url());
|
||||
attach_rdr.Attach();
|
||||
Xowd_page_tbl page_tbl = core_db.Tbl__page();
|
||||
int cur_html_db_id = -1, cur_page_id = -1; Xowd_html_tbl html_dump_tbl = null;
|
||||
Db_rdr rdr = attach_rdr.Exec_as_rdr(Sql_select);
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
// switch html_db if needed
|
||||
int html_db_id = rdr.Read_int(page_tbl.Fld_html_db_id());
|
||||
if (html_db_id != cur_html_db_id) {
|
||||
if (html_dump_tbl != null) html_dump_tbl.Conn().Txn_end();
|
||||
html_dump_tbl = wiki.Data__core_mgr().Dbs__get_at(html_db_id).Tbl__html();
|
||||
html_dump_tbl.Conn().Txn_bgn("bldr__redlink");
|
||||
cur_html_db_id = html_db_id;
|
||||
}
|
||||
// commit page_id if needed
|
||||
int page_id = rdr.Read_int(page_tbl.Fld_page_id());
|
||||
if (cur_page_id != page_id) {
|
||||
if (cur_page_id != -1) Commit(html_dump_tbl, cur_page_id, bfr);
|
||||
bfr.Add_int_variable(gplx.xowa.htmls.hdumps.core.Xohd_data_tid.Tid_redlink).Add_byte_pipe();
|
||||
cur_page_id = page_id;
|
||||
}
|
||||
// add html_uid to cur_page's bfr
|
||||
int html_uid = rdr.Read_int(Xob_link_dump_tbl.Fld_src_html_uid);
|
||||
bfr.Add_int_variable(html_uid).Add_byte_pipe();
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
Commit(html_dump_tbl, cur_page_id, bfr); // commit cur page
|
||||
html_dump_tbl.Conn().Txn_end(); // close cur tbl
|
||||
attach_rdr.Detach();
|
||||
}
|
||||
private void Commit(Xowd_html_tbl html_dump_tbl, int cur_page_id, Bry_bfr bfr) {
|
||||
html_dump_tbl.Insert(cur_page_id, Xowd_html_row.Tid_redlink, bfr.To_bry_and_clear());
|
||||
++commit_count;
|
||||
if ((commit_count % commit_interval ) == 0)
|
||||
html_dump_tbl.Conn().Txn_sav();
|
||||
}
|
||||
private static final String Sql_select = String_.Concat_lines_nl_skip_last
|
||||
( "SELECT p.page_html_db_id"
|
||||
, ", p.page_id"
|
||||
, ", ld.src_html_uid"
|
||||
, "FROM link_dump ld"
|
||||
, " JOIN <attach_db>page p ON p.page_id = ld.src_page_id "
|
||||
, "WHERE ld.trg_page_id = -1"
|
||||
, "ORDER BY p.page_html_db_id, p.page_id"
|
||||
, ";"
|
||||
);
|
||||
public void Cmd_init(Xob_bldr bldr) {}
|
||||
public void Cmd_bgn(Xob_bldr bldr) {}
|
||||
public void Cmd_end() {}
|
||||
public void Cmd_term() {}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_commit_interval_)) commit_interval = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_commit_interval_ = "commit_interval_";
|
||||
}
|
||||
23
400_xowa/src/gplx/xowa/htmls/hdumps/core/Xohd_data_itm.java
Normal file
23
400_xowa/src/gplx/xowa/htmls/hdumps/core/Xohd_data_itm.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public interface Xohd_data_itm {
|
||||
int Data_tid();
|
||||
void Data_write(Bry_bfr bfr);
|
||||
String Data_print();
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.files.repos.*;
|
||||
public abstract class Xohd_data_itm__base implements Xohd_data_itm {
|
||||
public abstract int Img_tid();
|
||||
public int Data_tid() {return Xohd_data_tid.Tid_img;}
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public double Lnki_time() {return lnki_time;} private double lnki_time;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page;
|
||||
public int Orig_repo_id() {return orig_repo_id;} private int orig_repo_id;
|
||||
public int Orig_ext() {return orig_ext;} private int orig_ext;
|
||||
public boolean File_is_orig() {return file_is_orig;} private boolean file_is_orig;
|
||||
public int File_w() {return file_w;} private int file_w;
|
||||
public int Html_uid() {return html_uid;} private int html_uid;
|
||||
public int Html_w() {return html_w;} private int html_w;
|
||||
public int Html_h() {return html_h;} private int html_h;
|
||||
public Io_url Html_view_url() {return html_view_url;} public void File_url_(Io_url v) {html_view_url = v;} private Io_url html_view_url;
|
||||
public abstract byte Html_elem_tid();
|
||||
public Xohd_data_itm__base Data_init_base
|
||||
( byte[] lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page
|
||||
, int orig_repo_id, int orig_ext, boolean file_is_orig, int file_w
|
||||
, int html_uid, int html_w, int html_h
|
||||
) {
|
||||
this.lnki_ttl = lnki_ttl; this.orig_ext = orig_ext; this.lnki_type = lnki_type;
|
||||
this.lnki_w = lnki_w; this.lnki_h = lnki_h; this.lnki_upright = lnki_upright; this.lnki_time = lnki_time; this.lnki_page = lnki_page;
|
||||
this.orig_repo_id = orig_repo_id; this.file_is_orig = file_is_orig; this.file_w = file_w;
|
||||
this.html_uid = html_uid; this.html_w = html_w; this.html_h = html_h;
|
||||
return this;
|
||||
}
|
||||
public void Data_write(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(Xohd_data_tid.Tid_img).Add_byte_pipe()
|
||||
.Add_int_variable(this.Img_tid()).Add_byte_pipe()
|
||||
.Add(lnki_ttl).Add_byte_pipe()
|
||||
.Add_int_variable(orig_ext).Add_byte_pipe()
|
||||
.Add_byte(lnki_type).Add_byte_pipe()
|
||||
.Add_int_variable(lnki_w).Add_byte_pipe()
|
||||
.Add_int_variable(lnki_h).Add_byte_pipe()
|
||||
.Add_double(lnki_upright).Add_byte_pipe()
|
||||
.Add_double(lnki_time).Add_byte_pipe()
|
||||
.Add_int_variable(lnki_page).Add_byte_pipe()
|
||||
.Add_int_variable(orig_repo_id).Add_byte_pipe()
|
||||
.Add_yn(file_is_orig).Add_byte_pipe()
|
||||
.Add_int_variable(file_w).Add_byte_pipe()
|
||||
.Add_int_variable(html_uid).Add_byte_pipe()
|
||||
.Add_int_variable(html_w).Add_byte_pipe()
|
||||
.Add_int_variable(html_h).Add_byte_pipe()
|
||||
;
|
||||
Data_write_hook(bfr);
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
public String Data_print() {
|
||||
return String_.Concat_with_str("|", Int_.To_str(this.Img_tid()), String_.new_u8(lnki_ttl), Int_.To_str(html_uid), Int_.To_str(html_w), Int_.To_str(html_h)
|
||||
, Int_.To_str(orig_repo_id), Int_.To_str(orig_ext), Yn.To_str(file_is_orig), Int_.To_str(file_w), Double_.To_str(lnki_time), Int_.To_str(lnki_page)
|
||||
);
|
||||
}
|
||||
@gplx.Virtual public void Data_parse(Bry_rdr rdr) {
|
||||
this.lnki_ttl = Xoa_app_.Utl__encoder_mgr().Http_url().Decode(rdr.Read_bry_to_pipe());
|
||||
this.orig_ext = rdr.Read_int_to_pipe();
|
||||
this.lnki_type = rdr.Read_byte_to_pipe();
|
||||
this.lnki_w = rdr.Read_int_to_pipe();
|
||||
this.lnki_h = rdr.Read_int_to_pipe();
|
||||
this.lnki_upright = rdr.Read_double_to_pipe();
|
||||
this.lnki_time = rdr.Read_double_to_pipe();
|
||||
this.lnki_page = rdr.Read_int_to_pipe();
|
||||
this.orig_repo_id = rdr.Read_int_to_pipe();
|
||||
this.file_is_orig = rdr.Read_yn_to_pipe();
|
||||
this.file_w = rdr.Read_int_to_pipe();
|
||||
this.html_uid = rdr.Read_int_to_pipe();
|
||||
this.html_w = rdr.Read_int_to_pipe();
|
||||
this.html_h = rdr.Read_int_to_pipe();
|
||||
}
|
||||
@gplx.Virtual public void Data_write_hook(Bry_bfr bfr) {}
|
||||
@Override public String toString() {return this.Data_print();} // TEST
|
||||
public static final int Tid_basic = 0, Tid_gallery = 1;
|
||||
public static final int
|
||||
File_repo_id_commons = Xof_repo_itm_.Repo_remote
|
||||
, File_repo_id_local = Xof_repo_itm_.Repo_local
|
||||
, File_repo_id_null = Xof_repo_itm_.Repo_null
|
||||
;
|
||||
public static final Xohd_data_itm__base[] Ary_empty = new Xohd_data_itm__base[0];
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.files.*;
|
||||
public class Xohd_data_itm__gallery_itm extends Xohd_data_itm__base {
|
||||
@Override public int Img_tid() {return Xohd_data_itm__base.Tid_gallery;}
|
||||
@Override public byte Html_elem_tid() {return Xof_html_elem.Tid_img;}
|
||||
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;
|
||||
public Xohd_data_itm__gallery_itm Data_init_gallery(int box_w, int img_w, int img_pad) {
|
||||
this.box_w = box_w;
|
||||
this.img_w = img_w;
|
||||
this.img_pad = img_pad;
|
||||
return this;
|
||||
}
|
||||
@Override public void Data_write_hook(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(box_w).Add_byte_pipe()
|
||||
.Add_int_variable(img_w).Add_byte_pipe()
|
||||
.Add_int_variable(img_pad).Add_byte_pipe()
|
||||
;
|
||||
}
|
||||
@Override public void Data_parse(Bry_rdr rdr) {
|
||||
super.Data_parse(rdr);
|
||||
this.box_w = rdr.Read_int_to_pipe();
|
||||
this.img_w = rdr.Read_int_to_pipe();
|
||||
this.img_pad = rdr.Read_int_to_pipe();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public class Xohd_data_itm__gallery_mgr implements Xohd_data_itm {
|
||||
public Xohd_data_itm__gallery_mgr(int uid, int box_max) {
|
||||
this.uid = uid;
|
||||
this.box_max = box_max;
|
||||
}
|
||||
public int Data_tid() {return Xohd_data_tid.Tid_gallery;}
|
||||
public void Data_write(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(Xohd_data_tid.Tid_gallery).Add_byte_pipe()
|
||||
.Add_int_variable(uid).Add_byte_pipe()
|
||||
.Add_int_variable(box_max).Add_byte_pipe()
|
||||
;
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
public String Data_print() {return Int_.To_str(box_max);}
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public int Box_max() {return box_max;} private int box_max;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xohd_data_itm__img extends Xohd_data_itm__base {
|
||||
@Override public int Img_tid() {return Xohd_data_itm__base.Tid_basic;}
|
||||
@Override public byte Html_elem_tid() {return Xof_html_elem.Tid_img;}
|
||||
}
|
||||
26
400_xowa/src/gplx/xowa/htmls/hdumps/core/Xohd_data_tid.java
Normal file
26
400_xowa/src/gplx/xowa/htmls/hdumps/core/Xohd_data_tid.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.htmls.hdumps.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public class Xohd_data_tid { // SERIALIZED
|
||||
public static final int
|
||||
Tid_img = 1
|
||||
, Tid_redlink = 2
|
||||
, Tid_gallery = 3
|
||||
, Tid_imap = 4
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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.htmls.hdumps.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.dbs.*; import gplx.ios.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.*; import gplx.xowa.htmls.hdumps.pages.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.htmls.hdumps.data.srl.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.guis.*;
|
||||
public class Xohd_page_html_mgr__load {
|
||||
private final Xohd_page_srl_mgr srl_mgr = Xohd_page_srl_mgr.Instance;
|
||||
private final Bry_rdr rdr = new Bry_rdr(); private final List_adp rows = List_adp_.new_(), imgs = List_adp_.new_();
|
||||
public void Load_page(Xow_wiki wiki, Xog_page hpg, Xowd_html_tbl tbl, int page_id, Xoa_ttl page_ttl) {
|
||||
Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.text: ttl=~{0}", page_ttl.Full_db_as_str());
|
||||
tbl.Select_by_page(rows, page_id);
|
||||
Parse_rows(wiki, hpg, page_id, Xoa_url.blank(), page_ttl, rows);
|
||||
}
|
||||
public void Parse_rows(Xow_wiki wiki, Xog_page hpg, int page_id, Xoa_url page_url, Xoa_ttl page_ttl, List_adp rows) { // TEST:
|
||||
hpg.Init(wiki, page_id, page_url, page_ttl);
|
||||
imgs.Clear();
|
||||
int len = rows.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_html_row row = (Xowd_html_row)rows.Get_at(i);
|
||||
switch (row.Tid()) {
|
||||
case Xowd_html_row.Tid_html: srl_mgr.Load(hpg, row.Data()); break;
|
||||
case Xowd_html_row.Tid_img:
|
||||
case Xowd_html_row.Tid_redlink:
|
||||
Parse_data(hpg, row); break;
|
||||
}
|
||||
}
|
||||
rows.Clear();
|
||||
}
|
||||
private void Parse_data(Xog_page hpg, Xowd_html_row row) {
|
||||
rdr.Init(row.Data());
|
||||
while (!rdr.Pos_is_eos()) {
|
||||
int tid = rdr.Read_int_to_pipe();
|
||||
switch (tid) {
|
||||
case Xohd_data_tid.Tid_img : Load_data_img(); break; // 1|0|A.png|0|220|110|...
|
||||
case Xohd_data_tid.Tid_gallery : Load_data_gallery(hpg); break; // 3|0|800
|
||||
case Xohd_data_tid.Tid_redlink : Load_data_redlink(hpg); break; // 2|2|0|1
|
||||
}
|
||||
}
|
||||
if (imgs.Count() > 0) hpg.Img_itms_((Xohd_data_itm__base[])imgs.To_ary_and_clear(Xohd_data_itm__base.class));
|
||||
}
|
||||
public static Xohd_data_itm__base Load_img(Bry_rdr rdr) {
|
||||
int tid = rdr.Read_int_to_pipe();
|
||||
Xohd_data_itm__base img_itm = null;
|
||||
switch (tid) {
|
||||
case Xohd_data_itm__base.Tid_basic : img_itm = new Xohd_data_itm__img(); break;
|
||||
case Xohd_data_itm__base.Tid_gallery : img_itm = new Xohd_data_itm__gallery_itm(); break;
|
||||
default : throw Err_.new_unhandled(tid);
|
||||
}
|
||||
img_itm.Data_parse(rdr);
|
||||
// Xoa_app_.Usr_dlg().Log_many("", "", "itm: ~{0}", img_itm.Data_print());
|
||||
rdr.Pos_add_one();
|
||||
return img_itm;
|
||||
}
|
||||
private void Load_data_img() {
|
||||
Xohd_data_itm__base img = Load_img(rdr);
|
||||
if (img == null) return;
|
||||
imgs.Add(img);
|
||||
}
|
||||
private void Load_data_redlink(Xog_page hpg) {
|
||||
Ordered_hash redlink_hash = hpg.Redlink_uids();
|
||||
while (!rdr.Pos_is_eos()) {
|
||||
Int_obj_ref redlink_uid = Int_obj_ref.new_(rdr.Read_int_to_pipe());
|
||||
redlink_hash.Add(redlink_uid, redlink_uid);
|
||||
}
|
||||
}
|
||||
private void Load_data_gallery(Xog_page hpg) {
|
||||
int uid = rdr.Read_int_to_pipe();
|
||||
int box_max = rdr.Read_int_to_pipe();
|
||||
hpg.Gallery_itms().Add_if_dupe_use_nth(uid, new Xohd_data_itm__gallery_mgr(uid, box_max)); // TODO: temporarily added b/c last build did not add gallery uid correctly
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.htmls.hdumps.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hdumps.data.srl.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.htmls.hdumps.pages.*; import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
public class Xohd_page_html_mgr__save {
|
||||
private Xohd_page_srl_mgr srl_mgr = Xohd_page_srl_mgr.Instance;
|
||||
public void Update(Bry_bfr tmp_bfr, Xowd_html_tbl tbl, Xoae_page page) {
|
||||
Xog_page hpg = new Xog_page();
|
||||
hpg.Ctor_from_page(tmp_bfr, page);
|
||||
tbl.Delete(page.Revision_data().Id());
|
||||
this.Insert(tmp_bfr, tbl, hpg, page.Hdump_data());
|
||||
}
|
||||
public int Insert(Bry_bfr tmp_bfr, Xowd_html_tbl tbl, Xog_page hpg, Xopg_hdump_data hdump_data) {
|
||||
int rv = 0;
|
||||
int page_id = hpg.Page_id();
|
||||
rv += Insert_row(tbl, page_id, Xowd_html_row.Tid_html , srl_mgr.Save(hpg, tmp_bfr));
|
||||
rv += Insert_row(tbl, page_id, Xowd_html_row.Tid_img , Write_imgs(tmp_bfr, hdump_data.Imgs()));
|
||||
rv += Insert_row(tbl, page_id, Xowd_html_row.Tid_redlink , Write_redlinks(tmp_bfr, hdump_data.Redlink_mgr()));
|
||||
return rv;
|
||||
}
|
||||
private int Insert_row(Xowd_html_tbl tbl, int page_id, int row_tid, byte[] bry) {return bry == null ? 0 : tbl.Insert(page_id, row_tid, bry);}
|
||||
public static byte[] Write_redlinks(Bry_bfr bfr, Xopg_redlink_idx_list redlink_mgr) {
|
||||
int len = redlink_mgr.Len(); if (len == 0) return null;
|
||||
for (int i = 0; i < len; ++i)
|
||||
bfr.Add_int_variable(redlink_mgr.Get_at(i)).Add_byte_pipe();
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public static byte[] Write_imgs(Bry_bfr bfr, List_adp 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) {
|
||||
Xohd_data_itm itm = (Xohd_data_itm)imgs.Get_at(i);
|
||||
itm.Data_write(bfr);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.guis.*;
|
||||
public interface Xohd_page_srl_itm { // INFO: serializes Xog_page to a byte[] before storing in the wiki_page_html table
|
||||
byte Tid();
|
||||
void Save(Xog_page hpg, Bry_bfr bfr);
|
||||
int Load(Xog_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref);
|
||||
}
|
||||
abstract class Xohd_page_srl_itm__base implements Xohd_page_srl_itm {
|
||||
public abstract byte Tid();
|
||||
protected void Save_tid_n_() {save_tid = false;} private boolean save_tid = true;
|
||||
public void Save(Xog_page hpg, Bry_bfr bfr) {
|
||||
byte[] bry = Save_itm(hpg); if (bry == null) return; // subclasses return null if nothing to save
|
||||
int len = bry.length; if (len == 0) return; // don't bother saving 0-len
|
||||
if (save_tid) // body doesn't save tid
|
||||
bfr.Add_byte(this.Tid());
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, len);
|
||||
bfr.Add(bry);
|
||||
}
|
||||
public abstract byte[] Save_itm(Xog_page hpg);
|
||||
public int Load(Xog_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref) {
|
||||
int itm_len = Xow_hzip_int_.Load_bin_int_abrv(bry, bry_len, itm_bgn, count_ref); if (itm_len == -1) throw Err_.new_wo_type("bry_itm has invalid len", "page", hpg.Page_id(), "tid", this.Tid());
|
||||
int data_bgn = itm_bgn + count_ref.Val(); if (itm_len == 0) return data_bgn;
|
||||
int data_end = data_bgn + itm_len;
|
||||
byte[] itm_data = Bry_.Mid(bry, data_bgn, data_end);
|
||||
this.Load_itm(hpg, itm_data);
|
||||
return data_end - itm_bgn;
|
||||
}
|
||||
public abstract void Load_itm(Xog_page hpg, byte[] data);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
public class Xohd_page_srl_itm_ {
|
||||
public static final byte // SERIALIZED
|
||||
Tid_body = 0
|
||||
, Tid_html_module = 1
|
||||
, Tid_display_ttl = 2
|
||||
, Tid_content_sub = 3
|
||||
, Tid_sidebar_div = 4
|
||||
;
|
||||
public static final Xohd_page_srl_itm[] Itms = new Xohd_page_srl_itm[] // NOTE: ary_idx must match tid above
|
||||
{ new Xohd_page_srl_itm__body()
|
||||
, new Xohd_page_srl_itm__html_module()
|
||||
, new Xohd_page_srl_itm__display_ttl()
|
||||
, new Xohd_page_srl_itm__content_sub()
|
||||
, new Xohd_page_srl_itm__sidebar_div()
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_page_srl_itm_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xohd_page_srl_itm_fxt fxt = new Xohd_page_srl_itm_fxt();
|
||||
@Test public void Body() {
|
||||
fxt.Test_page(fxt.Make_page().Body_("A"), fxt.Make_srl_body("A"));
|
||||
}
|
||||
@Test public void Html_modules() {
|
||||
fxt.Test_page(fxt.Make_page().Body_("A").Html_modules_(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N), fxt.Make_srl_body("A"), fxt.Make_srl_html_modules(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N));
|
||||
}
|
||||
@Test public void Body_all() {
|
||||
fxt.Test_page(fxt.Make_page().Body_("A").Html_modules_(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N).Display_ttl_("B").Content_sub_("C").Sidebar_div_("D")
|
||||
, fxt.Make_srl_body("A")
|
||||
, fxt.Make_srl_html_modules(Bool_.Y, Bool_.N, Bool_.Y, Bool_.N)
|
||||
, fxt.Make_srl_display_ttl("B")
|
||||
, fxt.Make_srl_content_sub("C")
|
||||
, fxt.Make_srl_sidebar_div("D")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Xohd_page_srl_itm_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(8);
|
||||
public void Clear() {bfr.Clear();}
|
||||
public Xog_page_bldr Make_page() {return new Xog_page_bldr();}
|
||||
public Xohd_page_srl_itm_mok Make_srl_body(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_body, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl_display_ttl(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_display_ttl, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl_content_sub(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_content_sub, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl_sidebar_div(String s) {return Make_srl(Xohd_page_srl_itm_.Tid_sidebar_div, s);}
|
||||
public Xohd_page_srl_itm_mok Make_srl(byte tid, String s) {return new Xohd_page_srl_itm_mok(tid, Bry_.new_u8(s));}
|
||||
public Xohd_page_srl_itm_mok Make_srl_html_modules(boolean... v) {
|
||||
return new Xohd_page_srl_itm_mok(Xohd_page_srl_itm_.Tid_html_module, new byte[] {Xohd_page_srl_itm__html_module.Calc_flag(v[0], v[1], v[2], v[3])});
|
||||
}
|
||||
public void Test_page(Xog_page_bldr hpg_bldr, Xohd_page_srl_itm_mok... expd_itms) {
|
||||
Xog_page hpg = hpg_bldr.Bld();
|
||||
byte[] actl = Xohd_page_srl_mgr.Instance.Save(hpg, bfr);
|
||||
Tfds.Eq_ary(Xohd_page_srl_itm_mok.Xto_bry(bfr, expd_itms), actl);
|
||||
Xog_page actl_hpg = new Xog_page();
|
||||
Xohd_page_srl_mgr.Instance.Load(actl_hpg, actl);
|
||||
Tfds.Eq_ary(actl, Xohd_page_srl_mgr.Instance.Save(hpg, bfr));
|
||||
}
|
||||
}
|
||||
class Xog_page_bldr {
|
||||
public byte[] Body() {return body;} public Xog_page_bldr Body_(String v) {body = Bry_.new_u8(v); return this;} private byte[] body;
|
||||
public boolean[] Html_modules() {return html_modules;} public Xog_page_bldr Html_modules_(boolean... v) {html_modules = v; return this;} private boolean[] html_modules;
|
||||
public byte[] Display_ttl() {return display_ttl;} public Xog_page_bldr Display_ttl_(String v) {display_ttl = Bry_.new_u8(v); return this;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} public Xog_page_bldr Content_sub_(String v) {content_sub = Bry_.new_u8(v); return this;} private byte[] content_sub;
|
||||
public byte[] Sidebar_div() {return sidebar_div;} public Xog_page_bldr Sidebar_div_(String v) {sidebar_div = Bry_.new_u8(v); return this;} private byte[] sidebar_div;
|
||||
public Xog_page Bld() {
|
||||
Xog_page rv = new Xog_page();
|
||||
rv.Page_body_(body);
|
||||
Xopg_module_mgr mod_mgr = rv.Head_mgr();
|
||||
if (html_modules != null) {
|
||||
mod_mgr.Math_exists_(html_modules[0]);
|
||||
mod_mgr.Imap_exists_(html_modules[1]);
|
||||
mod_mgr.Gallery_packed_exists_(html_modules[2]);
|
||||
mod_mgr.Hiero_exists_(html_modules[3]);
|
||||
}
|
||||
rv.Display_ttl_(display_ttl);
|
||||
rv.Content_sub_(content_sub);
|
||||
rv.Sidebar_div_(sidebar_div);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xohd_page_srl_itm_mok {
|
||||
public Xohd_page_srl_itm_mok(byte tid, byte[] data) {this.tid = tid; this.data = data;}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public int Len() {return data.length;}
|
||||
public byte[] Data() {return data;} private final byte[] data;
|
||||
public static byte[] Xto_bry(Bry_bfr bfr, Xohd_page_srl_itm_mok[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_page_srl_itm_mok itm = ary[i];
|
||||
if (itm.Tid() != Xohd_page_srl_itm_.Tid_body)
|
||||
bfr.Add_byte(itm.Tid());
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, itm.Len());
|
||||
bfr.Add(itm.Data());
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.hdumps.pages.*;
|
||||
import gplx.xowa.guis.*;
|
||||
class Xohd_page_srl_itm__body extends Xohd_page_srl_itm__base {
|
||||
public Xohd_page_srl_itm__body() {this.Save_tid_n_();}
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_body;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Page_body();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Page_body_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__display_ttl extends Xohd_page_srl_itm__base {
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_display_ttl;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Display_ttl();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Display_ttl_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__content_sub extends Xohd_page_srl_itm__base {
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_content_sub;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Content_sub();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Content_sub_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__sidebar_div extends Xohd_page_srl_itm__base {
|
||||
@Override public byte Tid() {return Xohd_page_srl_itm_.Tid_sidebar_div;}
|
||||
@Override public byte[] Save_itm(Xog_page hpg) {return hpg.Sidebar_div();}
|
||||
@Override public void Load_itm(Xog_page hpg, byte[] data) {hpg.Sidebar_div_(data);}
|
||||
}
|
||||
class Xohd_page_srl_itm__html_module implements Xohd_page_srl_itm {
|
||||
public byte Tid() {return Xohd_page_srl_itm_.Tid_html_module;}
|
||||
public int Load(Xog_page hpg, byte[] bry, int bry_len, int itm_bgn, Int_obj_ref count_ref) {
|
||||
itm_bgn += 2; // skip bin_int_abrv of [1, 0]
|
||||
byte flag = bry[itm_bgn];
|
||||
hpg.Head_mgr().Init(Bitmask_.Has_byte(flag, Tid_math), Bitmask_.Has_byte(flag, Tid_imap), Bitmask_.Has_byte(flag, Tid_packed), Bitmask_.Has_byte(flag, Tid_hiero));
|
||||
return 3;
|
||||
}
|
||||
public void Save(Xog_page hpg, Bry_bfr bfr) {
|
||||
byte flag = Calc_flag(hpg);
|
||||
if (flag == 0) return;
|
||||
bfr.Add_byte(this.Tid());
|
||||
Xow_hzip_int_.Save_bin_int_abrv(bfr, 1);
|
||||
bfr.Add_byte(flag);
|
||||
}
|
||||
private static byte Calc_flag(Xog_page hpg) {
|
||||
Xopg_module_mgr module_mgr = hpg.Head_mgr();
|
||||
return Calc_flag(module_mgr.Math_exists(), module_mgr.Imap_exists(), module_mgr.Gallery_packed_exists(), module_mgr.Hiero_exists());
|
||||
}
|
||||
public static byte Calc_flag(boolean math, boolean imap, boolean packed, boolean hiero) {
|
||||
byte rv = 0;
|
||||
if (math) rv = Bitmask_.Add_byte(rv, Tid_math);
|
||||
if (imap) rv = Bitmask_.Add_byte(rv, Tid_imap);
|
||||
if (packed) rv = Bitmask_.Add_byte(rv, Tid_packed);
|
||||
if (hiero) rv = Bitmask_.Add_byte(rv, Tid_hiero);
|
||||
return rv;
|
||||
}
|
||||
private static final byte // SERIALIZED; only supports 8 different types
|
||||
Tid_math = 1
|
||||
, Tid_imap = 2
|
||||
, Tid_packed = 4
|
||||
, Tid_hiero = 8
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.htmls.hdumps.data.srl; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hdumps.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hdumps.core.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xohd_page_srl_mgr {
|
||||
private final Xohd_page_srl_itm[] itm_ary; private final Xohd_page_srl_itm itm_body;
|
||||
private final Int_obj_ref count_ref = Int_obj_ref.zero_();
|
||||
public Xohd_page_srl_mgr(Xohd_page_srl_itm[] itm_ary) {
|
||||
this.itm_ary = itm_ary;
|
||||
this.itm_body = itm_ary[0];
|
||||
}
|
||||
public byte[] Save(Xog_page hpg, Bry_bfr bfr) {
|
||||
for (Xohd_page_srl_itm itm : itm_ary)
|
||||
itm.Save(hpg, bfr);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Load(Xog_page hpg, byte[] bry) {
|
||||
if (bry == null) return;
|
||||
int bry_len = bry.length; if (bry_len == 0) return;
|
||||
int pos = itm_body.Load(hpg, bry, bry_len, 0, count_ref); // assume every page has a body; saves 1 byte by not specifying tid for body
|
||||
while (pos < bry_len) {
|
||||
byte itm_tid = bry[pos]; // itm_tid is always 1-byte
|
||||
Xohd_page_srl_itm itm = itm_ary[itm_tid]; // itm_tid always matches itm_ary's idx
|
||||
pos += itm.Load(hpg, bry, bry_len, pos + 1, count_ref) + 1; // +1 to skip tid
|
||||
}
|
||||
}
|
||||
public static final Xohd_page_srl_mgr Instance = new Xohd_page_srl_mgr(Xohd_page_srl_itm_.Itms);
|
||||
}
|
||||
@@ -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.htmls.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.htmls.hdumps.core.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
public class Xopg_hdump_data {
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
|
||||
public Xopg_redlink_idx_list Redlink_mgr() {return redlink_mgr;} private final Xopg_redlink_idx_list redlink_mgr = new Xopg_redlink_idx_list();
|
||||
public List_adp Imgs() {return imgs;} private final List_adp imgs = List_adp_.new_();
|
||||
public void Imgs_add(Xohd_data_itm itm) {imgs.Add(itm);}
|
||||
public void Imgs_add_img(Xohd_data_itm__base img, Xof_file_itm xfer, int tid) {
|
||||
img.Data_init_base
|
||||
( xfer.Lnki_ttl(), xfer.Lnki_type(), xfer.Lnki_upright(), xfer.Lnki_w(), xfer.Lnki_h(), xfer.Lnki_time(), xfer.Lnki_page()
|
||||
, xfer.Orig_repo_id(), xfer.Orig_ext().Id(), xfer.File_is_orig(), xfer.File_w()
|
||||
, xfer.Html_uid(), xfer.Html_w(), xfer.Html_h()
|
||||
);
|
||||
imgs.Add(img);
|
||||
}
|
||||
public void Clear() {
|
||||
body = null;
|
||||
imgs.Clear();
|
||||
redlink_mgr.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.htmls.hdumps.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public class Xopg_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 Init(boolean math, boolean imap, boolean packed, boolean hiero) {
|
||||
this.math_exists = math;
|
||||
this.imap_exists = imap;
|
||||
this.gallery_packed_exists = packed;
|
||||
this.hiero_exists = hiero;
|
||||
}
|
||||
public void Clear() {
|
||||
math_exists = imap_exists = gallery_packed_exists = hiero_exists = false;
|
||||
}
|
||||
}
|
||||
39
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm_.java
Normal file
39
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm_.java
Normal 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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_head_itm_ {
|
||||
public static final byte[] // SRL: navframe, toc, title_rewrite are in wiki.cfg
|
||||
Key__collapsible = Bry_.new_a7("collapsible")
|
||||
, Key__css = Bry_.new_a7("css")
|
||||
, Key__gallery = Bry_.new_a7("gallery")
|
||||
, Key__globals = Bry_.new_a7("globals")
|
||||
, Key__graph = Bry_.new_a7("graph")
|
||||
, Key__hiero = Bry_.new_a7("hiero")
|
||||
, Key__mathjax = Bry_.new_a7("mathjax")
|
||||
, Key__navframe = Bry_.new_a7("navframe")
|
||||
, Key__popups = Bry_.new_a7("popups")
|
||||
, Key__search_suggest = Bry_.new_a7("xowa.search_suggest")
|
||||
, Key__timeline = Bry_.new_a7("xowa.timeline")
|
||||
, Key__title_rewrite = Bry_.new_a7("title_rewrite")
|
||||
, Key__toc = Bry_.new_a7("toc")
|
||||
, Key__top_icon = Bry_.new_a7("top_icon")
|
||||
, Key__dbui = Bry_.new_a7("dbui")
|
||||
, Key__bmk = Bry_.new_a7("bmk")
|
||||
, Key__server = Bry_.new_a7("server")
|
||||
;
|
||||
}
|
||||
48
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__base.java
Normal file
48
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__base.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public abstract class Xoh_head_itm__base {
|
||||
public abstract byte[] Key();
|
||||
public abstract int Flags();
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} public void Enabled_y_() {this.Enabled_(Bool_.Y);} public void Enabled_n_() {this.Enabled_(Bool_.N);} private boolean enabled;
|
||||
@gplx.Virtual public void Clear() {this.Enabled_(Bool_.N);}
|
||||
@gplx.Virtual public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
@gplx.Virtual public void Write_css_text(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
@gplx.Virtual public void Write_js_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
@gplx.Virtual public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
@gplx.Virtual public void Write_js_head_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
@gplx.Virtual public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
@gplx.Virtual public void Write_js_window_onload(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {}
|
||||
public static final int
|
||||
Flag__disabled = 0
|
||||
, Flag__css_include = 1
|
||||
, Flag__css_text = 2
|
||||
, Flag__js_include = 4
|
||||
, Flag__js_head_global = 8
|
||||
, Flag__js_head_script = 16
|
||||
, Flag__js_tail_script = 32
|
||||
, Flag__js_window_onload = 64
|
||||
;
|
||||
public static final int Idx__max = 7;
|
||||
}
|
||||
/*
|
||||
Position // top, bottom
|
||||
Targets // mobile, desktop
|
||||
Dependencies
|
||||
Messages
|
||||
*/
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_head_itm__collapsible extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__collapsible;}
|
||||
@Override public int Flags() {return Flag__js_head_global;}
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_global_ini_atr_val(Key_enabled , true);
|
||||
wtr.Write_js_global_ini_atr_val(Key_collapsed , app.Api_root().Html().Modules().Collapsible().Collapsed());
|
||||
wtr.Write_js_global_ini_atr_msg(wiki , Key_collapse);
|
||||
wtr.Write_js_global_ini_atr_msg(wiki , Key_expand);
|
||||
}
|
||||
private static final byte[]
|
||||
Key_enabled = Bry_.new_a7("collapsible-enabled")
|
||||
, Key_collapsed = Bry_.new_a7("collapsible-collapsed")
|
||||
, Key_collapse = Bry_.new_a7("collapsible-collapse")
|
||||
, Key_expand = Bry_.new_a7("collapsible-expand")
|
||||
;
|
||||
}
|
||||
31
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__css.java
Normal file
31
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__css.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__css extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__css;}
|
||||
@Override public int Flags() {return Flag__css_text;}
|
||||
@Override public void Write_css_text(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_css_style_itm(app.Ctg_mgr().Missing_ctg_cls_css());
|
||||
if (app.Html_mgr().Page_mgr().Font_enabled())
|
||||
wtr.Write_css_style_itm(app.Html_mgr().Page_mgr().Font_css_bry());
|
||||
byte[] css_xtn = app.Gui_mgr().Html_mgr().Css_xtn();
|
||||
if (Bry_.Len_gt_0(css_xtn))
|
||||
wtr.Write_css_style_itm(css_xtn);
|
||||
}
|
||||
}
|
||||
123
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__dbui.java
Normal file
123
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__dbui.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__dbui extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__dbui;}
|
||||
@Override public int Flags() {return Flag__css_text | Flag__css_include | Flag__js_tail_script | Flag__js_window_onload;}
|
||||
public Xoh_head_itm__dbui Init(Xoa_app app) {
|
||||
if (dir_url == null) {
|
||||
Io_url url_html_res = app.Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "html", "res");
|
||||
dir_url = url_html_res.GenSubDir_nest("src", "xowa", "dbui");
|
||||
url_dbui_js = dir_url.GenSubFil("dbui-0.1.1.js").To_http_file_bry();
|
||||
url_jquery_ui_js = url_html_res.GenSubFil_nest("lib", "jquery-ui", "jquery-ui-1.11.4.js").To_http_file_bry();
|
||||
url_jquery_ui_css = url_html_res.GenSubFil_nest("lib", "jquery-ui", "jquery-ui-1.11.4.css").To_http_file_bry();
|
||||
url_notify_js = url_html_res.GenSubFil_nest("lib", "notifyjs" , "notifyjs-0.3.1.js").To_http_file_bry();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_css_include(url_jquery_ui_css);
|
||||
}
|
||||
@Override public void Write_css_text(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_css_style_ary(Css__table_as_div);
|
||||
}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_tail_load_lib(url_dbui_js);
|
||||
wtr.Write_js_tail_load_lib(url_notify_js);
|
||||
wtr.Write_js_tail_load_lib(url_jquery_ui_js);
|
||||
}
|
||||
@Override public void Write_js_window_onload(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_lines(Js__sortable);
|
||||
}
|
||||
public static Io_url Img_dir() {return dir_url.GenSubDir("img");} private static Io_url dir_url;
|
||||
private static byte[] url_dbui_js, url_notify_js, url_jquery_ui_js, url_jquery_ui_css;
|
||||
private static final byte[][]
|
||||
Css__table_as_div = Bry_.Ary(String_.Ary
|
||||
( ".xo_tbl {"
|
||||
, " display: table;"
|
||||
, " table-layout: fixed;" // don't auto-size to text content
|
||||
, " width: 100%;"
|
||||
, "}"
|
||||
, ".xo_row {"
|
||||
, " display: table-row;"
|
||||
, "}"
|
||||
, ".xo_head,.xo_origin {"
|
||||
, " display: table-cell;"
|
||||
, " padding: 3px 10px;"
|
||||
, " border: 1px solid #999999;"
|
||||
, " border-right: none;"
|
||||
, " font-weight:bold;"
|
||||
, "}"
|
||||
, ".xo_origin {"
|
||||
, " padding:0px;" // else box is larger than should be
|
||||
, "}"
|
||||
, ".xo_cell {"
|
||||
, " display: table-cell;"
|
||||
, " padding: 3px 10px;"
|
||||
, " vertical-align: top;" // else <textarea> will cause <input> to align at bottom
|
||||
, " border: 1px solid #999999;"
|
||||
, " border-top: none;"
|
||||
, " border-left: none;"
|
||||
, " border-right: none;"
|
||||
, " white-space: nowrap;"
|
||||
, " overflow: hidden;"
|
||||
, " text-overflow: ellipsis;"
|
||||
, "}"
|
||||
, ".xo_head:nth-child(1),.xo_cell:nth-child(1),.xo_origin {"
|
||||
, " border-left: 1px solid #999999;"
|
||||
, "}"
|
||||
, ".xo_head:nth-last-child(1),.xo_cell:nth-last-child(1) {"
|
||||
, " border-right: 1px solid #999999;"
|
||||
, "}"
|
||||
, ".xo_header {"
|
||||
, " display: table-header-group;"
|
||||
, " background-color: #ddd;"
|
||||
, " font-weight: bold;"
|
||||
, "}"
|
||||
, ".xo_footer {"
|
||||
, " display: table-footer-group;"
|
||||
, " font-weight: bold;"
|
||||
, " background-color: #ddd;"
|
||||
, "}"
|
||||
, ".xo_tbody {"
|
||||
, " display: table-row-group;"
|
||||
, "}"
|
||||
, ".xo_drag_handle {"
|
||||
, " background-color: #ddd;"
|
||||
, " cursor: move;"
|
||||
, "}"
|
||||
))
|
||||
, Js__sortable = Bry_.Ary(String_.Ary
|
||||
( " $('.xo_sortable').sortable({"
|
||||
, " revert: 100," // 100 for "fast" snap back
|
||||
, " items: '.xo_draggable'," // to prevent header from being dragged
|
||||
, " handle: '.xo_drag_handle',"
|
||||
, " cursor: 'move',"
|
||||
, " stop: function(event, ui) {"
|
||||
, " var ids = $(this).sortable('toArray');"
|
||||
, " rows__reorder(ids);"
|
||||
, " },"
|
||||
, " });"
|
||||
, " $('.xo_resizable_col').resizable({"
|
||||
, " handles: 'e',"
|
||||
, " cancel : 'textarea',"
|
||||
, " });"
|
||||
))
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__gallery extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__gallery;}
|
||||
@Override public int Flags() {return Flag__js_head_global;}
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_global_ini_atr_val(Key_enabled , true);
|
||||
}
|
||||
private static final byte[]
|
||||
Key_enabled = Bry_.new_a7("gallery-packed-enabled")
|
||||
;
|
||||
}
|
||||
106
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__globals.java
Normal file
106
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__globals.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Xoh_head_itm__globals extends Xoh_head_itm__base {
|
||||
private final Xoh_head_wtr tmp_wtr = new Xoh_head_wtr();
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__globals;}
|
||||
@Override public int Flags() {return Flag__css_include | Flag__js_include | Flag__js_head_script | Flag__js_tail_script | Flag__js_head_global;}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_core_css == null) Url_core_css = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "xowa", "core", "core.css").To_http_file_bry();
|
||||
wtr.Write_css_include(Url_core_css);
|
||||
}
|
||||
@Override public void Write_js_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_core_js == null) {
|
||||
Io_url core_dir = app.Fsys_mgr().Bin_any_dir().GenSubDir_nest("xowa", "html", "res", "src", "xowa", "core");
|
||||
Url_core_js = core_dir.GenSubFil("core.js").To_http_file_bry();
|
||||
Url_exec_js = core_dir.GenSubFil("exec.js").To_http_file_bry();
|
||||
Url_DOMContentLoaded_js = core_dir.GenSubFil("DOMContentLoaded.js").To_http_file_bry();
|
||||
}
|
||||
wtr.Write_js_include(Url_core_js);
|
||||
wtr.Write_js_include(Url_exec_js);
|
||||
wtr.Write_js_include(Url_DOMContentLoaded_js);
|
||||
}
|
||||
@Override public void Write_js_head_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_var(Var_xowa_root_dir , Bool_.Y, app.Fsys_mgr().Root_dir().To_http_file_bry());
|
||||
wtr.Write_js_var(Var_xowa_mode_is_server , Bool_.N, app.Tcp_server().Running() ? Bool_.True_bry : Bool_.False_bry);
|
||||
}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_xowa_var(Key__app_mode, Bool_.Y, app.Mode().Name());
|
||||
wtr.Write_js_alias_var (Page__alias, Page__key);
|
||||
wtr.Write_js_alias_kv (Page__alias, Key__wiki , page.Wiki().Domain_bry());
|
||||
wtr.Write_js_alias_kv (Page__alias, Key__ttl , page.Ttl().Page_db());
|
||||
} private static final byte[] Key__app_mode = Bry_.new_a7("xowa.app.mode"), Page__alias = Bry_.new_a7("x_p"), Page__key = Bry_.new_a7("xowa.page"), Key__wiki = Bry_.new_a7("wiki"), Key__ttl = Bry_.new_a7("ttl");
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_global_ini_atr_val(Key_mode_is_gui , app.Mode().Tid_is_gui());
|
||||
wtr.Write_js_global_ini_atr_val(Key_mode_is_http , app.Mode().Tid_is_http());
|
||||
wtr.Write_js_global_ini_atr_val(Key_http_port , app.Http_server().Port());
|
||||
wtr.Write_js_global_ini_atr_msg(wiki, Key_sort_ascending);
|
||||
wtr.Write_js_global_ini_atr_msg(wiki, Key_sort_descending);
|
||||
Xol_lang_itm lang = wiki.Lang(); Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
Bry_bfr tmp_bfr = app.Utl__bfr_mkr().Get_b512();
|
||||
tmp_wtr.Init(tmp_bfr);
|
||||
byte[] months_long = Html_js_table_months(tmp_wtr, msg_mgr, Xol_msg_itm_.Id_dte_month_name_january, Xol_msg_itm_.Id_dte_month_name_december);
|
||||
byte[] months_short = Html_js_table_months(tmp_wtr, msg_mgr, Xol_msg_itm_.Id_dte_month_abrv_jan, Xol_msg_itm_.Id_dte_month_abrv_dec);
|
||||
byte[] num_format_separators = Html_js_table_num_format_separators(tmp_wtr, lang.Num_mgr().Separators_mgr());
|
||||
tmp_bfr.Mkr_rls();
|
||||
wtr.Write_js_global_ini_atr_val(Key_wgContentLanguage , lang.Key_bry());
|
||||
wtr.Write_js_global_ini_atr_obj(Key_wgSeparatorTransformTable , num_format_separators);
|
||||
wtr.Write_js_global_ini_atr_obj(Key_wgDigitTransformTable , Num_format_digits);
|
||||
wtr.Write_js_global_ini_atr_val(Key_wgDefaultDateFormat , Date_format_default);
|
||||
wtr.Write_js_global_ini_atr_obj(Key_wgMonthNames , months_long);
|
||||
wtr.Write_js_global_ini_atr_obj(Key_wgMonthNamesShort , months_short);
|
||||
}
|
||||
public static final byte[] // NOTE: most of these are for the table-sorter
|
||||
Key_mode_is_gui = Bry_.new_a7("mode_is_gui")
|
||||
, Key_mode_is_http = Bry_.new_a7("mode_is_http")
|
||||
, Key_http_port = Bry_.new_a7("http-port")
|
||||
, Key_sort_descending = Bry_.new_a7("sort-descending")
|
||||
, Key_sort_ascending = Bry_.new_a7("sort-ascending")
|
||||
, Key_wgContentLanguage = Bry_.new_a7("wgContentLanguage")
|
||||
, Key_wgSeparatorTransformTable = Bry_.new_a7("wgSeparatorTransformTable")
|
||||
, Key_wgDigitTransformTable = Bry_.new_a7("wgDigitTransformTable")
|
||||
, Key_wgDefaultDateFormat = Bry_.new_a7("wgDefaultDateFormat")
|
||||
, Key_wgMonthNames = Bry_.new_a7("wgMonthNames")
|
||||
, Key_wgMonthNamesShort = Bry_.new_a7("wgMonthNamesShort")
|
||||
;
|
||||
private static byte[] Html_js_table_months(Xoh_head_wtr tmp_wtr, Xow_msg_mgr msg_mgr, int january_id, int december_id) {
|
||||
tmp_wtr.Write_js_ary_bgn();
|
||||
tmp_wtr.Write_js_ary_itm(Bry_.Empty); // 1st month is always empty
|
||||
for (int i = january_id; i <= december_id; i++)
|
||||
tmp_wtr.Write_js_ary_itm(msg_mgr.Val_by_id(i));
|
||||
tmp_wtr.Write_js_ary_end();
|
||||
return tmp_wtr.Bfr().To_bry_and_clear();
|
||||
}
|
||||
private static byte[] Html_js_table_num_format_separators(Xoh_head_wtr tmp_wtr, Xol_transform_mgr separator_mgr) {
|
||||
byte[] dec_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__dec);
|
||||
byte[] grp_spr = separator_mgr.Get_val_or_self(Xol_num_mgr.Separators_key__grp);
|
||||
tmp_wtr.Write_js_ary_bgn();
|
||||
tmp_wtr.Write_js_ary_itm(Bry_.Add(dec_spr, Byte_ascii.Tab_bry, Byte_ascii.Dot_bry));
|
||||
tmp_wtr.Write_js_ary_itm(Bry_.Add(grp_spr, Byte_ascii.Tab_bry, Byte_ascii.Comma_bry));
|
||||
tmp_wtr.Write_js_ary_end();
|
||||
return tmp_wtr.Bfr().To_bry_and_clear();
|
||||
}
|
||||
private static final byte[]
|
||||
Date_format_default = Bry_.new_a7("dmy")
|
||||
, Num_format_digits = Bry_.new_a7("['', '']")
|
||||
, Var_xowa_root_dir = Bry_.new_a7("xowa_root_dir")
|
||||
, Var_xowa_mode_is_server = Bry_.new_a7("xowa_mode_is_server")
|
||||
;
|
||||
private static byte[] Url_core_css, Url_core_js, Url_exec_js, Url_DOMContentLoaded_js;
|
||||
}
|
||||
44
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__graph.java
Normal file
44
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__graph.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__graph extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__graph;}
|
||||
@Override public int Flags() {return Flag__js_include | Flag__js_window_onload;}
|
||||
@Override public void Write_js_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url__ary == null) {
|
||||
Io_url lib_dir = app.Fsys_mgr().Bin_xtns_dir().GenSubDir_nest("Graph", "lib");
|
||||
Url__ary = new byte[][]
|
||||
{ app.Fsys_mgr().Bin_xowa_dir().GenSubFil_nest("html", "res", "lib", "jquery", "jquery-1.11.3.min.js").To_http_file_bry()
|
||||
, lib_dir.GenSubFil("d3.js").To_http_file_bry()
|
||||
, lib_dir.GenSubFil("d3.layout.cloud.js").To_http_file_bry()
|
||||
, lib_dir.GenSubFil("topojson.js").To_http_file_bry()
|
||||
, lib_dir.GenSubFil("vega.js").To_http_file_bry()
|
||||
, app.Fsys_mgr().Bin_xtns_dir().GenSubFil_nest("Graph", "js", "graph.js").To_http_file_bry()
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < Url__ary_len; ++i)
|
||||
wtr.Write_js_include(Url__ary[i]);
|
||||
}
|
||||
@Override public void Write_js_window_onload(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_line(Js__graph_exec);
|
||||
}
|
||||
private static final int Url__ary_len = 6;
|
||||
private static byte[][] Url__ary;
|
||||
private static final byte[] Js__graph_exec = Bry_.new_a7("xtn__graph__exec();");
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__hiero.java
Normal file
28
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__hiero.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__hiero extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__hiero;}
|
||||
@Override public int Flags() {return Flag__css_include;}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_css == null) Url_css = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "xtns", "Wikihiero", "modules", "ext.wikihiero.css").To_http_file_bry();
|
||||
wtr.Write_css_include(Url_css);
|
||||
}
|
||||
private static byte[] Url_css;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__mathjax extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__mathjax;}
|
||||
@Override public int Flags() {return Flag__js_include;}
|
||||
@Override public void Write_js_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_mathjax == null) Url_mathjax = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "xtns", "Math", "modules", "mathjax", "xowa_mathjax.js").To_http_file_bry();
|
||||
wtr.Write_js_include(Url_mathjax);
|
||||
}
|
||||
private static byte[] Url_mathjax;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_head_itm__navframe extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__navframe;}
|
||||
@Override public int Flags() {return Flag__js_head_global;}
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
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() || wiki.Html_mgr().Head_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);
|
||||
}
|
||||
private static final byte[]
|
||||
Key_enabled = Bry_.new_a7("navframe-enabled")
|
||||
, Key_collapsed = Bry_.new_a7("navframe-collapsed")
|
||||
, Key_show = Bry_.new_a7("show")
|
||||
, Key_hide = Bry_.new_a7("hide")
|
||||
;
|
||||
}
|
||||
54
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__popups.java
Normal file
54
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__popups.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
import gplx.xowa.apps.apis.xowa.html.modules.*;
|
||||
public class Xoh_head_itm__popups extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__popups;}
|
||||
@Override public int Flags() {return Flag__css_include | Flag__js_head_global | Flag__js_tail_script;}
|
||||
public boolean Bind_hover_area() {return bind_hover_area;} public void Bind_hover_area_(boolean v) {bind_hover_area = v;} private boolean bind_hover_area;
|
||||
@Override public void Clear() {this.Enabled_n_(); bind_hover_area = false;}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Css_url == null) Css_url = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "xowa", "popups", "popups.css").To_http_file_bry();
|
||||
wtr.Write_css_include(Css_url);
|
||||
}
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
Xoapi_popups api_popups = app.Api_root().Html().Modules().Popups();
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_show_delay , api_popups.Win_show_delay());
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_hide_delay , api_popups.Win_hide_delay());
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_max_w , api_popups.Win_max_w());
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_max_h , api_popups.Win_max_h());
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_show_all_max_w , api_popups.Win_show_all_max_w());
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_bind_focus_blur , api_popups.Win_bind_focus_blur());
|
||||
wtr.Write_js_global_ini_atr_val(Key_win_bind_hover_area , bind_hover_area);
|
||||
}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_line(Jquery_init); // NOTE: must assert that jquery is init'd, else popup.js will not compile after going back / forward; DATE:2014-09-10
|
||||
wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "xowa", "popups", "popups.js"));
|
||||
} public static final byte[] Jquery_init = Bry_.new_a7("xowa.js.jquery.init();"), Mw_init = Bry_.new_a7("xowa.js.mediaWiki.init();");
|
||||
private static byte[] Css_url;
|
||||
private static final byte[]
|
||||
Key_win_show_delay = Bry_.new_a7("popups-win-show_delay")
|
||||
, Key_win_hide_delay = Bry_.new_a7("popups-win-hide_delay")
|
||||
, Key_win_max_w = Bry_.new_a7("popups-win-max_w")
|
||||
, Key_win_max_h = Bry_.new_a7("popups-win-max_h")
|
||||
, Key_win_show_all_max_w = Bry_.new_a7("popups-win-show_all_max_w")
|
||||
, Key_win_bind_focus_blur = Bry_.new_a7("popups-win-bind_focus_blur")
|
||||
, Key_win_bind_hover_area = Bry_.new_a7("popups-win-bind_hover_area")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__search_suggest extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__search_suggest;}
|
||||
@Override public int Flags() {return Flag__css_include | Flag__js_include;}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_css == null) Url_css = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "xowa", "search-suggest", "search-suggest.css").To_http_file_bry();
|
||||
wtr.Write_css_include(Url_css);
|
||||
}
|
||||
@Override public void Write_js_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_js == null) Url_js = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "xowa", "search-suggest", "search-suggest.js").To_http_file_bry();
|
||||
wtr.Write_js_include(Url_js);
|
||||
}
|
||||
private static byte[] Url_css, Url_js;
|
||||
}
|
||||
34
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__server.java
Normal file
34
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__server.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.apps.servers.http.*;
|
||||
public class Xoh_head_itm__server extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__server;}
|
||||
@Override public int Flags() {return Flag__js_tail_script;}
|
||||
private Http_data__client client_data;
|
||||
public Xoh_head_itm__server Init_by_http(Http_data__client client_data) {this.client_data = client_data; return this;}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_init_global(Client_key);
|
||||
wtr.Write_js_alias_var (Client_alias, Client_key);
|
||||
wtr.Write_js_alias_kv (Client_alias, Key__server_host , client_data.Server_host());
|
||||
wtr.Write_js_alias_kv (Client_alias, Key__ip_address , client_data.Ip_address());
|
||||
}
|
||||
private static final byte[] Client_key = Bry_.new_a7("xowa.client"), Client_alias = Bry_.new_a7("x_c");
|
||||
private static final byte[] Key__server_host = Bry_.new_a7("server_host"), Key__ip_address = Bry_.new_a7("ip_address");
|
||||
}
|
||||
@@ -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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_head_itm__timeline extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__timeline;}
|
||||
@Override public int Flags() {return Flag__css_include;}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Url_js == null) Url_js = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "xowa", "timeline", "timeline.js").To_http_file_bry();
|
||||
wtr.Write_js_include(Url_js);
|
||||
}
|
||||
private static byte[] Url_js;
|
||||
}
|
||||
@@ -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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
import gplx.xowa.apps.apis.xowa.html.modules.*;
|
||||
public class Xoh_head_itm__title_rewrite extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__title_rewrite;}
|
||||
@Override public int Flags() {return Flag__js_tail_script;}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "gadgets", "titleRewrite", "titleRewrite.js"));
|
||||
}
|
||||
}
|
||||
44
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__toc.java
Normal file
44
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_itm__toc.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_itm__toc extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__toc;}
|
||||
@Override public int Flags() {return Flag__js_head_global | Flag__js_tail_script;}
|
||||
@Override public void Write_js_head_global(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_global_ini_atr_val(Key_exists , true);
|
||||
wtr.Write_js_global_ini_atr_val(Key_collapsed , app.Api_root().Html().Modules().Collapsible().Collapsed() ? Val_collapsed_y : Val_collapsed_n);
|
||||
wtr.Write_js_global_ini_atr_msg(wiki , Key_showtoc);
|
||||
wtr.Write_js_global_ini_atr_msg(wiki , Key_hidetoc);
|
||||
}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
// wtr.Write_js_line(Xoh_head_itm__popups.Jquery_init);
|
||||
// wtr.Write_js_line(Xoh_head_itm__popups.Mw_init);
|
||||
// wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "modules", "mw.toc", "mw.toc.js"));
|
||||
}
|
||||
private static final byte[]
|
||||
Key_exists = Bry_.new_a7("toc-enabled")
|
||||
, Key_collapsed = Bry_.new_a7("mw_hidetoc")
|
||||
, Val_collapsed_y = Bry_.new_a7("1")
|
||||
, Val_collapsed_n = Bry_.new_a7("0")
|
||||
;
|
||||
public static final byte[]
|
||||
Key_showtoc = Bry_.new_a7("showtoc")
|
||||
, Key_hidetoc = Bry_.new_a7("hidetoc")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.guis.*;
|
||||
import gplx.xowa.apps.apis.xowa.html.modules.*;
|
||||
public class Xoh_head_itm__top_icon extends Xoh_head_itm__base {
|
||||
@Override public byte[] Key() {return Xoh_head_itm_.Key__top_icon;}
|
||||
@Override public int Flags() {return Flag__css_include | Flag__js_tail_script;}
|
||||
@Override public void Write_css_include(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
if (Css_url == null) Css_url = app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "gadgets", "top-icon", "top-icon.css").To_http_file_bry();
|
||||
wtr.Write_css_include(Css_url);
|
||||
}
|
||||
@Override public void Write_js_tail_script(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xoh_head_wtr wtr) {
|
||||
wtr.Write_js_tail_load_lib(app.Fsys_mgr().Bin_any_dir().GenSubFil_nest("xowa", "html", "res", "src", "gadgets", "top-icon", "top-icon.js"));
|
||||
}
|
||||
private static byte[] Css_url;
|
||||
}
|
||||
176
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr.java
Normal file
176
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_head_mgr implements Bry_fmtr_arg {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoae_page page;
|
||||
private Xoh_head_itm__base[] itms; private int itms_len;
|
||||
private Xoh_head_wtr wtr = new Xoh_head_wtr();
|
||||
private final Xoh_head_wkr
|
||||
list__css_include = new Xoh_head_wkr()
|
||||
, list__css_text = new Xoh_head_wkr()
|
||||
, list__js_include = new Xoh_head_wkr()
|
||||
, list__js_head_global = new Xoh_head_wkr()
|
||||
, list__js_head_script = new Xoh_head_wkr()
|
||||
, list__js_tail_script = new Xoh_head_wkr()
|
||||
, list__js_window_onload = new Xoh_head_wkr()
|
||||
;
|
||||
public Xoh_head_mgr() {
|
||||
Itms_add(itm__css, itm__globals, itm__server, itm__popups, itm__toc, itm__collapsible, itm__navframe, itm__gallery
|
||||
, itm__mathjax, itm__graph, itm__hiero, itm__top_icon, itm__title_rewrite, itm__search_suggest, itm__timeline
|
||||
, itm__dbui
|
||||
);
|
||||
}
|
||||
public Xoh_head_itm__css Itm__css() {return itm__css;} private final Xoh_head_itm__css itm__css = new Xoh_head_itm__css();
|
||||
public Xoh_head_itm__globals Itm__globals() {return itm__globals;} private final Xoh_head_itm__globals itm__globals = new Xoh_head_itm__globals();
|
||||
public Xoh_head_itm__server Itm__server() {return itm__server;} private final Xoh_head_itm__server itm__server = new Xoh_head_itm__server();
|
||||
public Xoh_head_itm__popups Itm__popups() {return itm__popups;} private final Xoh_head_itm__popups itm__popups = new Xoh_head_itm__popups();
|
||||
public Xoh_head_itm__toc Itm__toc() {return itm__toc;} private final Xoh_head_itm__toc itm__toc = new Xoh_head_itm__toc();
|
||||
public Xoh_head_itm__collapsible Itm__collapsible() {return itm__collapsible;} private final Xoh_head_itm__collapsible itm__collapsible = new Xoh_head_itm__collapsible();
|
||||
public Xoh_head_itm__navframe Itm__navframe() {return itm__navframe;} private final Xoh_head_itm__navframe itm__navframe = new Xoh_head_itm__navframe();
|
||||
public Xoh_head_itm__top_icon Itm__top_icon() {return itm__top_icon;} private final Xoh_head_itm__top_icon itm__top_icon = new Xoh_head_itm__top_icon();
|
||||
public Xoh_head_itm__gallery Itm__gallery() {return itm__gallery;} private final Xoh_head_itm__gallery itm__gallery = new Xoh_head_itm__gallery();
|
||||
public Xoh_head_itm__title_rewrite Itm__title_rewrite() {return itm__title_rewrite;} private final Xoh_head_itm__title_rewrite itm__title_rewrite = new Xoh_head_itm__title_rewrite();
|
||||
public Xoh_head_itm__mathjax Itm__mathjax() {return itm__mathjax;} private final Xoh_head_itm__mathjax itm__mathjax = new Xoh_head_itm__mathjax();
|
||||
public Xoh_head_itm__hiero Itm__hiero() {return itm__hiero;} private final Xoh_head_itm__hiero itm__hiero = new Xoh_head_itm__hiero();
|
||||
public Xoh_head_itm__graph Itm__graph() {return itm__graph;} private final Xoh_head_itm__graph itm__graph = new Xoh_head_itm__graph();
|
||||
public Xoh_head_itm__timeline Itm__timeline() {return itm__timeline;} private final Xoh_head_itm__timeline itm__timeline = new Xoh_head_itm__timeline();
|
||||
public Xoh_head_itm__search_suggest Itm__search_suggest() {return itm__search_suggest;} private final Xoh_head_itm__search_suggest itm__search_suggest = new Xoh_head_itm__search_suggest();
|
||||
public Xoh_head_itm__dbui Itm__dbui() {return itm__dbui;} private final Xoh_head_itm__dbui itm__dbui = new Xoh_head_itm__dbui();
|
||||
public Xoh_head_mgr Init(Xoae_app app, Xowe_wiki wiki, Xoae_page page) {
|
||||
this.app = app; this.wiki = wiki; this.page = page;
|
||||
return this;
|
||||
}
|
||||
public Xoh_head_mgr Init_dflts() {
|
||||
if (page.Hdr_mgr().Toc_enabled()) itm__toc.Enabled_y_();
|
||||
if (wiki.Html_mgr().Head_mgr().Itm__top_icon().Enabled_y()) itm__top_icon.Enabled_y_();
|
||||
if (wiki.Html_mgr().Head_mgr().Itm__title_rewrite().Enabled_y()) itm__title_rewrite.Enabled_y_();
|
||||
if (app.Gui_mgr().Search_suggest_mgr().Enabled()) itm__search_suggest.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_();
|
||||
itm__navframe.Enabled_y_();
|
||||
itm__popups.Enabled_(app.Api_root().Html().Modules().Popups().Enabled());
|
||||
return this;
|
||||
}
|
||||
public void Clear() {
|
||||
for (int i = 0; i < itms_len; ++i)
|
||||
itms[i].Clear();
|
||||
}
|
||||
public void Fmt__do(Bry_bfr bfr) {Write(bfr, app, wiki, page);}
|
||||
public void Write(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, Xoae_page page) {
|
||||
Set_wkrs();
|
||||
wtr.Init(bfr);
|
||||
wtr.Indent_add();
|
||||
int len = 0;
|
||||
len = list__css_include.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_head_itm__base itm = list__css_include.Get_at(i);
|
||||
itm.Write_css_include(app, wiki, page, wtr);
|
||||
}
|
||||
len = list__css_text.Len();
|
||||
if (len > 0) {
|
||||
wtr.Write_css_style_bgn();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_head_itm__base itm = list__css_text.Get_at(i);
|
||||
itm.Write_css_text(app, wiki, page, wtr);
|
||||
}
|
||||
wtr.Write_css_style_end();
|
||||
}
|
||||
int head_global_len = list__js_head_global.Len();
|
||||
int head_script_len = list__js_head_script.Len();
|
||||
if (head_global_len + head_script_len > 0) {
|
||||
len = head_script_len;
|
||||
wtr.Write_js_script_bgn(); // write <script> before <script src=""> b/c <script> will have cfg values that other scripts will use; EX: xowa_root_dir
|
||||
for (int i = 0; i < head_script_len; ++i) {
|
||||
Xoh_head_itm__base itm = list__js_head_script.Get_at(i);
|
||||
itm.Write_js_head_script(app, wiki, page, wtr);
|
||||
}
|
||||
wtr.Write_js_head_global_bgn();
|
||||
len = head_global_len;
|
||||
for (int i = 0; i < head_global_len; ++i) {
|
||||
Xoh_head_itm__base itm = list__js_head_global.Get_at(i);
|
||||
itm.Write_js_head_global(app, wiki, page, wtr);
|
||||
}
|
||||
wtr.Write_js_head_global_end();
|
||||
wtr.Write_js_script_end();
|
||||
}
|
||||
len = list__js_include.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_head_itm__base itm = list__js_include.Get_at(i);
|
||||
itm.Write_js_include(app, wiki, page, wtr);
|
||||
}
|
||||
int tail_script_len = list__js_tail_script.Len();
|
||||
int window_onload_len = list__js_window_onload.Len();
|
||||
if (tail_script_len + window_onload_len > 0) {
|
||||
wtr.Write_js_script_bgn();
|
||||
for (int i = 0; i < tail_script_len; ++i) {
|
||||
Xoh_head_itm__base itm = list__js_tail_script.Get_at(i);
|
||||
itm.Write_js_tail_script(app, wiki, page, wtr);
|
||||
}
|
||||
if (window_onload_len > 0) {
|
||||
wtr.Write_js_line(Js__window_onload__bgn);
|
||||
for (int i = 0; i < window_onload_len; ++i) {
|
||||
Xoh_head_itm__base itm = list__js_window_onload.Get_at(i);
|
||||
itm.Write_js_window_onload(app, wiki, page, wtr);
|
||||
}
|
||||
wtr.Write_js_line(Js__window_onload__end);
|
||||
}
|
||||
wtr.Write_js_script_end();
|
||||
}
|
||||
wtr.Indent_del();
|
||||
wtr.Term();
|
||||
}
|
||||
private static final byte[]
|
||||
Js__window_onload__bgn = Bry_.new_a7("window.onload = function() {")
|
||||
, Js__window_onload__end = Bry_.new_a7("};")
|
||||
;
|
||||
private void Itms_add(Xoh_head_itm__base... ary) {
|
||||
this.itms_len = ary.length;
|
||||
this.itms = ary;
|
||||
}
|
||||
private void Set_wkrs() {
|
||||
list__css_include.Clear();
|
||||
list__css_text.Clear();
|
||||
list__js_include.Clear();
|
||||
list__js_head_global.Clear();
|
||||
list__js_head_script.Clear();
|
||||
list__js_tail_script.Clear();
|
||||
list__js_window_onload.Clear();
|
||||
for (int i = 0; i < itms_len; ++i) {
|
||||
Xoh_head_itm__base itm = itms[i];
|
||||
boolean enabled = itm.Enabled();
|
||||
if (enabled) {
|
||||
int flag = itms[i].Flags();
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__css_include)) list__css_include.Add(itm);
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__css_text)) list__css_text.Add(itm);
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__js_include)) list__js_include.Add(itm);
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__js_head_global)) list__js_head_global.Add(itm);
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__js_head_script)) list__js_head_script.Add(itm);
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__js_tail_script)) list__js_tail_script.Add(itm);
|
||||
if (Bitmask_.Has_int(flag, Xoh_head_itm__base.Flag__js_window_onload)) list__js_window_onload.Add(itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xoh_head_wkr {
|
||||
private final List_adp list = List_adp_.size_(Xoh_head_itm__base.Idx__max);
|
||||
public int Len() {return list.Count();}
|
||||
public void Clear() {list.Clear();}
|
||||
public void Add(Xoh_head_itm__base itm) {list.Add(itm);}
|
||||
public Xoh_head_itm__base Get_at(int i) {return (Xoh_head_itm__base)list.Get_at(i);}
|
||||
}
|
||||
145
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr_tst.java
Normal file
145
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_mgr_tst.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.guis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xoh_head_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_head_mgr_fxt fxt = new Xoh_head_mgr_fxt();
|
||||
@Test public void Css() {
|
||||
fxt.Mgr().Itm__css().Enabled_y_();
|
||||
fxt.Test_write(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <style type=\"text/css\">"
|
||||
, " .xowa-missing-category-entry {color: red;}"
|
||||
, " </style>"
|
||||
));
|
||||
}
|
||||
@Test public void Toc() {
|
||||
fxt.Init_msg(Xoh_head_itm__toc.Key_showtoc, "Sh\"ow");
|
||||
fxt.Init_msg(Xoh_head_itm__toc.Key_hidetoc, "Hi'de");
|
||||
fxt.Mgr().Itm__toc().Enabled_y_();
|
||||
fxt.Test_write(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <script type='text/javascript'>"
|
||||
, " var xowa_global_values = {"
|
||||
, " 'toc-enabled' : true,"
|
||||
, " 'mw_hidetoc' : '0',"
|
||||
, " 'showtoc' : 'Sh\"ow',"
|
||||
, " 'hidetoc' : 'Hi\\'de',"
|
||||
, " }"
|
||||
, " </script>"
|
||||
));
|
||||
}
|
||||
@Test public void Globals() {
|
||||
fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "Jan'uary" ); // add apos to simulate apostrophes in Hebrew months; DATE:2014-07-28
|
||||
fxt.Mgr().Itm__globals().Enabled_y_();
|
||||
fxt.Test_write(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <link rel=\"stylesheet\" href=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.css\" type='text/css'>"
|
||||
, " <script type='text/javascript'>"
|
||||
, " var xowa_root_dir = 'file:///mem/xowa/';"
|
||||
, " var xowa_mode_is_server = false;"
|
||||
, " var xowa_global_values = {"
|
||||
, " 'mode_is_gui' : false,"
|
||||
, " 'mode_is_http' : false,"
|
||||
, " 'http-port' : 8080,"
|
||||
, " 'sort-ascending' : 'Sort ascending',"
|
||||
, " 'sort-descending' : 'Sort descending',"
|
||||
, " 'wgContentLanguage' : 'en',"
|
||||
, " 'wgSeparatorTransformTable' : ['.\t.', ',\t,'],"
|
||||
, " 'wgDigitTransformTable' : ['', ''],"
|
||||
, " 'wgDefaultDateFormat' : 'dmy',"
|
||||
, " 'wgMonthNames' : ['', 'Jan\\'uary', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
|
||||
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
|
||||
, " }"
|
||||
, " </script>"
|
||||
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.js\" type='text/javascript'></script>"
|
||||
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/exec.js\" type='text/javascript'></script>"
|
||||
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/DOMContentLoaded.js\" type='text/javascript'></script>"
|
||||
, " <script type='text/javascript'>"
|
||||
, " xowa.app.mode = 'cmd';"
|
||||
, " var x_p = xowa.page;"
|
||||
, " x_p.wiki = 'en.wikipedia.org';"
|
||||
, " x_p.ttl = 'Test_page';"
|
||||
, " </script>"
|
||||
));
|
||||
fxt.Init_msg(Xol_msg_itm_.Id_dte_month_name_january, "January" ); // set it back
|
||||
}
|
||||
@Test public void Globals_la() { // PURPOSE: la.gfs only specifies "," not "."; make sure both "." and "," show up, or else null ref error during import; DATE:2014-05-13
|
||||
Xol_lang_itm la_lang = fxt.Wiki().Lang();
|
||||
gplx.xowa.langs.numbers.Xol_transform_mgr separators_mgr = la_lang.Num_mgr().Separators_mgr();
|
||||
separators_mgr.Clear();
|
||||
separators_mgr.Set(gplx.xowa.langs.numbers.Xol_num_mgr.Separators_key__grp, Bry_.new_a7(" "));
|
||||
fxt.Mgr().Itm__globals().Enabled_y_();
|
||||
fxt.Test_write(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <link rel=\"stylesheet\" href=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.css\" type='text/css'>"
|
||||
, " <script type='text/javascript'>"
|
||||
, " var xowa_root_dir = 'file:///mem/xowa/';"
|
||||
, " var xowa_mode_is_server = false;"
|
||||
, " var xowa_global_values = {"
|
||||
, " 'mode_is_gui' : false,"
|
||||
, " 'mode_is_http' : false,"
|
||||
, " 'http-port' : 8080,"
|
||||
, " 'sort-ascending' : 'Sort ascending',"
|
||||
, " 'sort-descending' : 'Sort descending',"
|
||||
, " 'wgContentLanguage' : 'en',"
|
||||
, " 'wgSeparatorTransformTable' : ['.\t.', ' \t,']," // note that grp spr (",") is ""
|
||||
, " 'wgDigitTransformTable' : ['', ''],"
|
||||
, " 'wgDefaultDateFormat' : 'dmy',"
|
||||
, " 'wgMonthNames' : ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],"
|
||||
, " 'wgMonthNamesShort' : ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],"
|
||||
, " }"
|
||||
, " </script>"
|
||||
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/core.js\" type='text/javascript'></script>"
|
||||
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/exec.js\" type='text/javascript'></script>"
|
||||
, " <script src=\"file:///mem/xowa/bin/any/xowa/html/res/src/xowa/core/DOMContentLoaded.js\" type='text/javascript'></script>"
|
||||
, " <script type='text/javascript'>"
|
||||
, " xowa.app.mode = 'cmd';"
|
||||
, " var x_p = xowa.page;"
|
||||
, " x_p.wiki = 'en.wikipedia.org';"
|
||||
, " x_p.ttl = 'Test_page';"
|
||||
, " </script>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_head_mgr_fxt {
|
||||
private Xop_fxt fxt = new Xop_fxt();
|
||||
private Xoh_head_mgr mgr;
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xoh_head_mgr Mgr() {return mgr;}
|
||||
public Xol_lang_itm Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_or_new(Bry_.new_a7(key));}
|
||||
public void Clear() {
|
||||
fxt.Reset();
|
||||
mgr = fxt.Page().Html_data().Head_mgr();
|
||||
wiki = fxt.Wiki();
|
||||
}
|
||||
public void Init_msg(byte[] key, String val) {
|
||||
wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_a7(val), false, false);
|
||||
}
|
||||
public void Init_msg(int id, String val) {
|
||||
Xol_msg_itm msg_itm = wiki.Lang().Msg_mgr().Itm_by_id_or_null(id);
|
||||
msg_itm.Atrs_set(Bry_.new_a7(val), false, false);
|
||||
}
|
||||
public void Test_write(String expd) {
|
||||
mgr.Write(bfr, fxt.App(), wiki, fxt.Page());
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
230
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr.java
Normal file
230
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr.java
Normal file
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xoh_head_wtr {
|
||||
private int indent; private int reset_bgn, reset_end;
|
||||
private boolean js_tail_inited = false;
|
||||
public Bry_bfr Bfr() {return bfr;} private Bry_bfr bfr;
|
||||
public void Init(Bry_bfr bfr) {this.bfr = bfr;}
|
||||
public void Term() {
|
||||
this.bfr = null;
|
||||
js_tail_inited = true;
|
||||
}
|
||||
public void Write_css_include(byte[] url) {
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Css_include_bgn).Add(url).Add(Css_include_end);
|
||||
}
|
||||
public void Write_js_include(byte[] url) {
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Js_include_bgn).Add(url).Add(Js_include_end);
|
||||
}
|
||||
public void Write_css_style_bgn() {
|
||||
reset_bgn = bfr.Len();
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Html_tag_.Style_lhs_w_type);
|
||||
Indent_add();
|
||||
reset_end = bfr.Len();
|
||||
}
|
||||
public void Write_css_style_end() {
|
||||
Indent_del();
|
||||
if (Reset()) return;
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Html_tag_.Style_rhs);
|
||||
}
|
||||
public void Write_css_style_ary(byte[][] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
Write_css_style_itm(ary[i]);
|
||||
}
|
||||
public void Write_css_style_itm(byte[] bry) {
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(bry);
|
||||
}
|
||||
public void Write_js_lines(byte[][] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
Write_js_line(ary[i]);
|
||||
}
|
||||
public void Write_js_line(String str) {Write_js_line(Bry_.new_u8(str));}
|
||||
public void Write_js_line(byte[] bry) {
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(bry);
|
||||
}
|
||||
public void Write_js_line_ary(byte[]... ary) {
|
||||
Write_nl_and_indent();
|
||||
for (byte[] bry : ary)
|
||||
bfr.Add(bry);
|
||||
}
|
||||
public void Write_js_script_bgn() {
|
||||
reset_bgn = bfr.Len();
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Html_tag_.Script_lhs_w_type);
|
||||
Indent_add();
|
||||
reset_end = bfr.Len();
|
||||
}
|
||||
public void Write_js_script_end() {
|
||||
Indent_del();
|
||||
if (Reset()) return;
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Html_tag_.Script_rhs);
|
||||
}
|
||||
public void Write_js_head_global_bgn() {
|
||||
reset_bgn = bfr.Len();
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Js_globals_ini_var_bgn);
|
||||
Indent_add();
|
||||
reset_end = bfr.Len();
|
||||
}
|
||||
public void Write_js_head_global_end() {
|
||||
Indent_del();
|
||||
if (Reset()) return;
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Js_globals_ini_var_end);
|
||||
}
|
||||
private void Write_js_tail_init() {
|
||||
if (js_tail_inited) return;
|
||||
js_tail_inited = true;
|
||||
Write_js_line(Js_line_1);
|
||||
}
|
||||
public void Write_js_tail_load_lib(Io_url url) {Write_js_tail_load_lib(url.To_http_file_bry());}
|
||||
public void Write_js_tail_load_lib(byte[] url) {
|
||||
Write_js_tail_init();
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Js_line_2_bgn);
|
||||
bfr.Add(url);
|
||||
bfr.Add(Js_line_2_end);
|
||||
}
|
||||
private static final byte[]
|
||||
Js_line_1 = Bry_.new_a7("xowa.js.jquery.init();")
|
||||
, Js_line_2_bgn = Bry_.new_a7("xowa.js.load_lib('")
|
||||
, Js_line_2_end = Bry_.new_a7("');")
|
||||
;
|
||||
private boolean Reset() {
|
||||
if (bfr.Len() == reset_end) { // itms wrote nothing
|
||||
bfr.Delete_rng_to_end(reset_bgn); // delete bgn
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public void Write_js_global_ini_atr_val(byte[] key, boolean val) {Write_js_global_ini_atr(key, Bool_.N, val ? Bool_.True_bry : Bool_.False_bry);}
|
||||
public void Write_js_global_ini_atr_val(byte[] key, byte[] val) {Write_js_global_ini_atr(key, Bool_.Y, val);}
|
||||
public void Write_js_global_ini_atr_obj(byte[] key, byte[] val) {Write_js_global_ini_atr(key, Bool_.N, val);}
|
||||
public void Write_js_global_ini_atr_msg(Xowe_wiki wiki, byte[] key) {Write_js_global_ini_atr(key, Bool_.Y, wiki.Msg_mgr().Val_by_key_obj(key));}
|
||||
private void Write_js_global_ini_atr(byte[] key, boolean quote_val, byte[] val) {
|
||||
Write_js_global_ini_atr_bgn(key);
|
||||
if (quote_val)
|
||||
Write_js_quote(Byte_ascii.Apos, val);
|
||||
else
|
||||
bfr.Add(val);
|
||||
bfr.Add_byte(Byte_ascii.Comma);
|
||||
}
|
||||
public void Write_js_global_ini_atr_val(byte[] key, int val) {
|
||||
Write_js_global_ini_atr_bgn(key);
|
||||
bfr.Add_int_variable(val);
|
||||
bfr.Add_byte(Byte_ascii.Comma);
|
||||
}
|
||||
private void Write_js_global_ini_atr_bgn(byte[] key) {
|
||||
Write_nl_and_indent();
|
||||
bfr.Add_byte_apos();
|
||||
bfr.Add(key);
|
||||
bfr.Add_byte_apos();
|
||||
bfr.Add(Js_globals_ini_atr_mid);
|
||||
}
|
||||
public void Write_js_ary_bgn() {js_ary_idx = 0; bfr.Add_byte(Byte_ascii.Brack_bgn);}
|
||||
public void Write_js_ary_itm(byte[] val) {
|
||||
if (++js_ary_idx != 1) bfr.Add(js_ary_dlm);
|
||||
Write_js_quote(Byte_ascii.Apos, val);
|
||||
} private int js_ary_idx = 0; private static final byte[] js_ary_dlm = Bry_.new_a7(", ");
|
||||
public void Write_js_ary_end() {js_ary_idx = 0; bfr.Add_byte(Byte_ascii.Brack_end);}
|
||||
public void Write_js_init_global(byte[] key) { // EX: xowa.client = {};
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(key);
|
||||
bfr.Add(Js_init_obj);
|
||||
}
|
||||
public void Write_js_alias_var(byte[] alias, byte[] key) { // EX: var x_s = xowa.server;
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Js_var_bgn);
|
||||
bfr.Add(alias);
|
||||
bfr.Add(Js_var_mid);
|
||||
bfr.Add(key);
|
||||
bfr.Add(Js_var_end);
|
||||
}
|
||||
public void Write_js_alias_kv(byte[] alias, byte[] key, byte[] val) { // EX: x_s.port = 8080;
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(alias).Add_byte_dot().Add(key);
|
||||
bfr.Add(Js_var_mid);
|
||||
Write_js_quote(Byte_ascii.Apos, val);
|
||||
bfr.Add(Js_var_end);
|
||||
}
|
||||
public void Write_js_xowa_var(byte[] key, boolean quote_val, byte[] val) { // EX: var xowa.app.mode = 'gui';
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(key);
|
||||
bfr.Add(Js_var_mid);
|
||||
if (quote_val)
|
||||
Write_js_quote(Byte_ascii.Apos, val);
|
||||
else
|
||||
bfr.Add(val);
|
||||
bfr.Add(Js_var_end);
|
||||
}
|
||||
public void Write_js_var(byte[] key, boolean quote_val, byte[] val) {
|
||||
Write_nl_and_indent();
|
||||
bfr.Add(Js_var_bgn);
|
||||
bfr.Add(key);
|
||||
bfr.Add(Js_var_mid);
|
||||
if (quote_val)
|
||||
Write_js_quote(Byte_ascii.Apos, val);
|
||||
else
|
||||
bfr.Add(val);
|
||||
bfr.Add(Js_var_end);
|
||||
}
|
||||
public void Write(byte[] v) {
|
||||
Indent();
|
||||
bfr.Add(v);
|
||||
}
|
||||
private void Write_js_quote(byte quote_byte, byte[] val) {
|
||||
int val_len = val.length;
|
||||
bfr.Add_byte(quote_byte);
|
||||
for (int i = 0; i < val_len; i++) {
|
||||
byte b = val[i];
|
||||
if (b == quote_byte) bfr.Add_byte_backslash(); // escape quote
|
||||
bfr.Add_byte(b);
|
||||
}
|
||||
bfr.Add_byte(quote_byte);
|
||||
}
|
||||
private void Write_nl_and_indent() {
|
||||
bfr.Add_byte_nl(); Indent();
|
||||
}
|
||||
private void Indent() {bfr.Add_byte_repeat(Byte_ascii.Space, indent);}
|
||||
public Xoh_head_wtr Indent_add() {indent += 2; return this;}
|
||||
public Xoh_head_wtr Indent_del() {indent -= 2; return this;}
|
||||
private static final byte[]
|
||||
Css_include_bgn = Bry_.new_a7("<link rel=\"stylesheet\" href=\"")
|
||||
, Css_include_end = Bry_.new_a7("\" type='text/css'>")
|
||||
, Js_include_bgn = Bry_.new_a7("<script src=\"")
|
||||
, Js_include_end = Bry_.new_a7("\" type='text/javascript'></script>")
|
||||
, Js_globals_ini_var_bgn = Bry_.new_a7("var xowa_global_values = {")
|
||||
, Js_globals_ini_var_end = Bry_.new_a7("}")
|
||||
, Js_globals_ini_atr_mid = Bry_.new_a7(" : ")
|
||||
, Js_var_bgn = Bry_.new_a7("var ")
|
||||
, Js_var_mid = Bry_.new_a7(" = ")
|
||||
, Js_var_end = Bry_.new_a7(";")
|
||||
, Js_init_obj = Bry_.new_a7(" = {};")
|
||||
;
|
||||
}
|
||||
63
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr_tst.java
Normal file
63
400_xowa/src/gplx/xowa/htmls/heads/Xoh_head_wtr_tst.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.guis.*;
|
||||
public class Xoh_head_wtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_head_wtr_fxt fxt = new Xoh_head_wtr_fxt();
|
||||
@Test public void Globals_none() {
|
||||
Xoh_head_wtr wtr = fxt.Wtr();
|
||||
wtr.Write_js_head_global_bgn();
|
||||
wtr.Write_js_head_global_end();
|
||||
fxt.Test("");
|
||||
}
|
||||
@Test public void Globals_some() {
|
||||
Xoh_head_wtr wtr = fxt.Wtr();
|
||||
wtr.Write_js_head_global_bgn();
|
||||
fxt.Exec_Write_js_global_ini_atr_val("key_1", "val_1");
|
||||
fxt.Exec_Write_js_global_ini_atr_val("key_2", "val_2");
|
||||
fxt.Exec_Write_js_global_ini_atr_val("key_3", "apos_'_1");
|
||||
wtr.Write_js_head_global_end();
|
||||
fxt.Test(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "var xowa_global_values = {"
|
||||
, " 'key_1' : 'val_1',"
|
||||
, " 'key_2' : 'val_2',"
|
||||
, " 'key_3' : 'apos_\\'_1',"
|
||||
, "}"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoh_head_wtr_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
public Xoh_head_wtr Wtr() {return wtr;} private Xoh_head_wtr wtr = new Xoh_head_wtr();
|
||||
public void Clear() {
|
||||
wtr.Init(bfr);
|
||||
}
|
||||
public void Exec_Write_js_global_ini_atr_val(String key, String val) {wtr.Write_js_global_ini_atr_val(Bry_.new_u8(key), Bry_.new_u8(val));}
|
||||
public void Test(String expd) {
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
// public void Init_msg(byte[] key, String val) {
|
||||
// wiki.Msg_mgr().Get_or_make(key).Atrs_set(Bry_.new_a7(val), false, false);
|
||||
// }
|
||||
// public void Test_write(String expd) {
|
||||
// mgr.Write(bfr, fxt.App(), wiki, fxt.Page());
|
||||
// Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
// }
|
||||
}
|
||||
65
400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr.java
Normal file
65
400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Xow_fragment_mgr implements GfoInvkAble {
|
||||
public Xow_fragment_mgr(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public byte[] Html_js_edit_toolbar() {return html_js_edit_toolbar;} private byte[] html_js_edit_toolbar;
|
||||
private Bry_fmtr html_js_edit_toolbar_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( " var xowa_edit_i18n = {"
|
||||
, " 'bold_tip' : '~{bold_tip}',"
|
||||
, " 'bold_sample' : '~{bold_sample}',"
|
||||
, " 'italic_tip' : '~{italic_tip}',"
|
||||
, " 'italic_sample' : '~{italic_sample}',"
|
||||
, " 'link_tip' : '~{link_tip}',"
|
||||
, " 'link_sample' : '~{link_sample}',"
|
||||
, " 'headline_tip' : '~{headline_tip}',"
|
||||
, " 'headline_sample' : '~{headline_sample}',"
|
||||
, " 'ulist_tip' : '~{ulist_tip}',"
|
||||
, " 'ulist_sample' : '~{ulist_sample}',"
|
||||
, " 'olist_tip' : '~{olist_tip}',"
|
||||
, " 'olist_sample' : '~{olist_sample}'"
|
||||
, " };"
|
||||
), "bold_tip", "bold_sample", "italic_tip", "italic_sample", "link_tip", "link_sample", "headline_tip", "headline_sample", "ulist_tip", "ulist_sample", "olist_tip", "olist_sample");
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_html_js_edit_toolbar_fmt_)) html_js_edit_toolbar_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html_js_edit_toolbar)) return html_js_edit_toolbar;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_html_js_edit_toolbar_fmt_ = "html_js_edit_toolbar_fmt_", Invk_html_js_edit_toolbar = "html_js_edit_toolbar";
|
||||
public void Evt_lang_changed(Xol_lang_itm lang) {
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b512();
|
||||
Xow_msg_mgr msg_mgr = wiki.Appe().Usere().Msg_mgr();
|
||||
html_js_edit_toolbar = html_js_edit_toolbar_fmtr.Bld_bry_many(bfr
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_bold_sample)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_italic_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_italic_sample)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_link_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_link_sample)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_headline_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_headline_sample)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_ulist_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_ulist_sample)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_olist_tip)
|
||||
, msg_mgr.Val_by_id(Xol_msg_itm_.Id_edit_toolbar_olist_sample)
|
||||
);
|
||||
bfr.Mkr_rls();
|
||||
}
|
||||
}
|
||||
57
400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr_tst.java
Normal file
57
400_xowa/src/gplx/xowa/htmls/heads/Xow_fragment_mgr_tst.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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.htmls.heads; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.numbers.*;
|
||||
public class Xow_fragment_mgr_tst {
|
||||
Xow_fragment_mgr_fxt fxt = new Xow_fragment_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Html_js_edit_toolbar_fmt() {
|
||||
fxt.Test_fragment(Xow_fragment_mgr.Invk_html_js_edit_toolbar, String_.Concat_lines_nl
|
||||
( " var xowa_edit_i18n = {"
|
||||
, " 'bold_tip' : 'Bold text',"
|
||||
, " 'bold_sample' : 'Bold text',"
|
||||
, " 'italic_tip' : 'Italic text',"
|
||||
, " 'italic_sample' : 'Italic text',"
|
||||
, " 'link_tip' : 'Internal link',"
|
||||
, " 'link_sample' : 'Link title',"
|
||||
, " 'headline_tip' : 'Level 2 headline',"
|
||||
, " 'headline_sample' : 'Headline text',"
|
||||
, " 'ulist_tip' : 'Bulleted list',"
|
||||
, " 'ulist_sample' : 'Bulleted list item',"
|
||||
, " 'olist_tip' : 'Numbered list',"
|
||||
, " 'olist_sample' : 'Numbered list item'"
|
||||
, " };"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xow_fragment_mgr_fxt {
|
||||
public void Clear() {
|
||||
if (wiki == null) {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
} private Xowe_wiki wiki;
|
||||
public Xol_lang_itm Make_lang(String key) {return wiki.Appe().Lang_mgr().Get_by_or_new(Bry_.new_a7(key));}
|
||||
public void Test_fragment(String key, String expd) {Test_fragment(wiki.Lang(), key, expd);}
|
||||
public void Test_fragment(Xol_lang_itm lang, String key, String expd) {
|
||||
wiki.Fragment_mgr().Evt_lang_changed(lang);
|
||||
byte[] actl = (byte[])GfoInvkAble_.InvkCmd(wiki.Fragment_mgr(), key);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_.java
Normal file
40
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_href_ {
|
||||
public static final String
|
||||
Str__file = "file://"
|
||||
, Str__site = "/site/"
|
||||
, Str__wiki = "/wiki/"
|
||||
, Str__anch = "#"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__file = Bry_.new_a7(Str__file)
|
||||
, Bry__site = Bry_.new_a7(Str__site)
|
||||
, Bry__wiki = Bry_.new_a7(Str__wiki)
|
||||
, Bry__anch = Bry_.new_a7(Str__anch)
|
||||
, Bry__https = Bry_.new_a7("https://") // NOTE: must be "https:" or wmf api won't work; DATE:2015-06-17
|
||||
, Bry__xcmd = Bry_.new_a7("/xcmd/")
|
||||
;
|
||||
public static final int
|
||||
Len__file = Bry__file.length
|
||||
, Len__site = Bry__site.length
|
||||
, Len__wiki = Bry__wiki.length
|
||||
, Len__anch = Bry__anch.length
|
||||
;
|
||||
}
|
||||
94
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl.java
Normal file
94
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
public class Xoh_href_gui_utl {
|
||||
public static String Html_extract_text(String site, String page, String text_str) {
|
||||
byte[] text_bry = Bry_.new_u8(text_str);
|
||||
int text_len = text_bry.length;
|
||||
int text_tid = Byte_ascii.Xto_digit(text_bry[0]);
|
||||
switch (text_tid) {
|
||||
case Text_tid_none: return ""; // "0"
|
||||
case Text_tid_text: return String_.new_u8(text_bry, 2, text_len); // 2 to skip "1|"
|
||||
case Text_tid_href: break; // fall through to below
|
||||
default: throw Err_.new_unhandled(text_tid);
|
||||
}
|
||||
int href_bgn = 2; // 2 to skip "2|"
|
||||
if (Bry_.Has_at_bgn(text_bry, Xoh_href_.Bry__file, href_bgn, text_len))
|
||||
href_bgn += Xoh_href_.Len__file; // skip "file://"
|
||||
Byte_obj_val href_tid = (Byte_obj_val)href_trie.Match_bgn(text_bry, href_bgn, text_len);
|
||||
if (href_tid != null) {
|
||||
switch (href_tid.Val()) {
|
||||
case Href_tid_wiki: return site + String_.new_u8(text_bry, href_bgn, text_len);
|
||||
case Href_tid_site: return String_.new_u8(text_bry, href_bgn + 6, text_len); // +6 to skip "site/"
|
||||
case Href_tid_anch: return site + "/wiki/" + page + String_.new_u8(text_bry, href_bgn, text_len);
|
||||
}
|
||||
}
|
||||
return String_.new_u8(text_bry, 2, text_len); // 2 to skip "2|"; handles "http://" text as well as any fall-thru from above
|
||||
}
|
||||
public static String Standardize_xowa_link(String str) {
|
||||
byte[] bry = Bry_.new_u8(str);
|
||||
int skip = Skip_start_of_xowa_link(bry, bry.length, 0);
|
||||
return skip == 0 ? str : String_.Mid(str, skip);
|
||||
}
|
||||
private static int Skip_start_of_xowa_link(byte[] src, int src_len, int bgn) {
|
||||
if (!Bry_.Has_at_bgn(src, Xoh_href_.Bry__file, bgn, src_len)) return bgn; // does not start with "file://"
|
||||
int pos = bgn + Xoh_href_.Len__file; // skip "file://"
|
||||
Object tid_obj = href_trie.Match_bgn(src, pos, src_len);
|
||||
if (tid_obj == null) {
|
||||
return bgn; // if not a known xowa link, return original bgn;
|
||||
}
|
||||
switch (((Byte_obj_val)tid_obj).Val()) {
|
||||
case Href_tid_site: return pos;
|
||||
case Href_tid_wiki: return pos;
|
||||
case Href_tid_anch: return pos;
|
||||
default: throw Err_.new_unhandled(tid_obj);
|
||||
}
|
||||
}
|
||||
private static final byte Text_tid_none = 0, Text_tid_text = 1, Text_tid_href = 2;
|
||||
private static final byte Href_tid_wiki = 1, Href_tid_site = 2, Href_tid_anch = 3;
|
||||
private static final Btrie_slim_mgr href_trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_byte(Xoh_href_.Bry__site , Href_tid_site)
|
||||
.Add_bry_byte(Xoh_href_.Bry__wiki , Href_tid_wiki)
|
||||
.Add_bry_byte(Xoh_href_.Bry__anch , Href_tid_anch)
|
||||
;
|
||||
}
|
||||
/*
|
||||
NOTE_1:
|
||||
. swt/mozilla treats text differently in href="{text}" when content_editable=n; occurs in LocationListener.changing
|
||||
http://a.org -> http://a.org does nothing
|
||||
A -> file:///A adds "file:///"
|
||||
/wiki/A -> file:///wiki/A adds "file://"
|
||||
Category:A -> Category:A noops; Category is assumed to be protocol?
|
||||
//en.wiktionary.org/wiki/a -> file:///wiki/a strips out site name and prepends "file://"; no idea why
|
||||
|
||||
. so, to handle the above, the code does the following
|
||||
http://a.org -> http://a.org does nothing; nothing needed
|
||||
A -> /wiki/A always prepend /wiki/
|
||||
Category:A -> /wiki/Category:A always prepend /wiki/
|
||||
//en.wiktionary.org/wiki/A -> /site/en.wiktionary.org/wiki/A always transform relative url to /site/
|
||||
|
||||
. the href will still come here as file:///wiki/A or file:///site/en.wiktionary.org/wiki/A.
|
||||
. however, the file:// can be lopped off and discarded and the rest of the href will fall into one of the following cases
|
||||
.. /wiki/
|
||||
.. /site/
|
||||
.. /xcmd/
|
||||
.. #
|
||||
.. anything else -> assume to be really a file:// url; EX: file://C/dir/fil.txt -> C/dir/fil.txt
|
||||
. the other advantage of this approach is that this proc can be reused outside of swt calls; i.e.: it can parse both "file:///wiki/A" and "/wiki/A"
|
||||
*/
|
||||
68
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl_tst.java
Normal file
68
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_gui_utl_tst.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.guis.views.*;
|
||||
public class Xoh_href_gui_utl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_href_gui_utl_fxt fxt = new Xoh_href_gui_utl_fxt();
|
||||
@Test public void Extract_href__text() {
|
||||
fxt.Test_extract_href("0|" , "");
|
||||
fxt.Test_extract_href("1|selected_text" , "selected_text");
|
||||
fxt.Test_extract_href("2|http://a.org" , "http://a.org");
|
||||
}
|
||||
@Test public void Extract_href__file() {
|
||||
fxt.Test_extract_href("2|file:///site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1");
|
||||
fxt.Test_extract_href("2|file:///wiki/Page_2" , "en.wikipedia.org/wiki/Page_2");
|
||||
fxt.Test_extract_href("2|file://#anchor" , "en.wikipedia.org/wiki/Page_0#anchor");
|
||||
}
|
||||
@Test public void Extract_href__internal() {
|
||||
fxt.Test_extract_href("2|/site/en.wiktionary.org/wiki/Page_1" , "en.wiktionary.org/wiki/Page_1");
|
||||
fxt.Test_extract_href("2|/wiki/Page_2" , "en.wikipedia.org/wiki/Page_2");
|
||||
fxt.Test_extract_href("2|#anchor" , "en.wikipedia.org/wiki/Page_0#anchor");
|
||||
}
|
||||
@Test public void Html_window_vpos_parse() {
|
||||
fxt.Test_Html_window_vpos_parse("0|0,1,2", "0", "'0','1','2'");
|
||||
fxt.Test_Html_window_vpos_parse("org.eclipse.swt.SWTException: Permission denied for <file://> to get property Selection.rangeCount", null, null); // check that invalid path doesn't fail; DATE:2014-04-05
|
||||
}
|
||||
@Test public void Standardize_xowa_link() {
|
||||
fxt.Test_standardize_xowa_link("file:///site/en.wikipedia.org/wiki/A" , "/site/en.wikipedia.org/wiki/A");
|
||||
fxt.Test_standardize_xowa_link("file:///wiki/A" , "/wiki/A");
|
||||
fxt.Test_standardize_xowa_link("file://#A" , "#A");
|
||||
}
|
||||
}
|
||||
class Xoh_href_gui_utl_fxt {
|
||||
public void Clear() {
|
||||
cur_wiki = "en.wikipedia.org";
|
||||
cur_page = "Page_0";
|
||||
}
|
||||
public String Cur_wiki() {return cur_wiki;} public Xoh_href_gui_utl_fxt Cur_wiki_(String v) {cur_wiki = v; return this;} private String cur_wiki;
|
||||
public String Cur_page() {return cur_page;} public Xoh_href_gui_utl_fxt Cur_page_(String v) {cur_page = v; return this;} private String cur_page;
|
||||
public void Test_extract_href(String text_str, String expd) {
|
||||
Tfds.Eq(expd, Xoh_href_gui_utl.Html_extract_text(cur_wiki, cur_page, text_str));
|
||||
}
|
||||
private String_obj_ref scroll_top = String_obj_ref.null_(), node_path = String_obj_ref.null_();
|
||||
public void Test_Html_window_vpos_parse(String raw, String expd_scroll_top, String expd_node_path) {
|
||||
scroll_top.Val_null_(); node_path.Val_null_();
|
||||
Xog_html_itm.Html_window_vpos_parse(raw, scroll_top, node_path);
|
||||
Tfds.Eq(expd_scroll_top, scroll_top.Val(), expd_scroll_top);
|
||||
Tfds.Eq(expd_node_path, node_path.Val(), expd_node_path);
|
||||
}
|
||||
public void Test_standardize_xowa_link(String raw, String expd) {
|
||||
Tfds.Eq_str(expd, Xoh_href_gui_utl.Standardize_xowa_link(raw), "standardize");
|
||||
}
|
||||
}
|
||||
79
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser.java
Normal file
79
400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_parser.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.core.net.*;
|
||||
import gplx.xowa.langs.vnts.*;
|
||||
public class Xoh_href_parser {
|
||||
public void Parse_as_url(Xoa_url rv, byte[] raw, Xowe_wiki wiki, byte[] cur_page) {
|
||||
int bgn = 0;
|
||||
Object seg_obj = btrie.Match_bgn(raw, bgn, raw.length); // match /wiki/ or /site/ or /xcmd/
|
||||
if (seg_obj == null) {
|
||||
Xol_vnt_mgr vnt_mgr = wiki.Lang().Vnt_mgr();
|
||||
if (vnt_mgr.Enabled() && raw[0] == Byte_ascii.Slash) {
|
||||
int slash_end = Bry_find_.Find_fwd(raw, Byte_ascii.Slash, 1);
|
||||
if (vnt_mgr.Regy().Has(Bry_.Mid(raw, 1, slash_end))) {
|
||||
raw = Bry_.Add(wiki.Domain_bry(), raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // something matched
|
||||
switch (((Byte_obj_val)seg_obj).Val()) {
|
||||
case Seg_xcmd_tid: // convert "/xcmd/a" to "xowa-cmd:a"
|
||||
raw = Bry_.Add(Gfo_protocol_itm.Bry_xcmd, Bry_.Mid(raw, btrie.Match_pos()));
|
||||
bgn = 0;
|
||||
break;
|
||||
case Seg_wiki_tid: // skip "/wiki/" or "/site/"
|
||||
case Seg_site_tid:
|
||||
bgn = btrie.Match_pos();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
wiki.Utl__url_parser().Parse(rv, raw, bgn, raw.length);
|
||||
switch (rv.Tid()) {
|
||||
case Xoa_url_.Tid_anch:
|
||||
rv.Wiki_bry_(wiki.Domain_bry());
|
||||
rv.Page_bry_(cur_page);
|
||||
break;
|
||||
case Xoa_url_.Tid_page:
|
||||
Xow_wiki ttl_wiki = wiki.App().Wiki_mgri().Get_by_key_or_make_init_n(rv.Wiki_bry());
|
||||
byte[] tmp_page = rv.Page_bry();
|
||||
if (rv.Page_is_main())
|
||||
tmp_page = ttl_wiki.Props().Main_page();
|
||||
else {
|
||||
if (tmp_page != null) {
|
||||
if (ttl_wiki != null) {
|
||||
Xoa_ttl ttl = ttl_wiki.Ttl_parse(tmp_page);
|
||||
if (ttl == null) // invalid ttl; null out page;
|
||||
tmp_page = Bry_.Empty;
|
||||
else
|
||||
tmp_page = ttl.Full_txt();
|
||||
}
|
||||
}
|
||||
}
|
||||
rv.Page_bry_(tmp_page);
|
||||
break;
|
||||
}
|
||||
}
|
||||
private static final byte Seg_wiki_tid = 0, Seg_site_tid = 1, Seg_xcmd_tid = 2;
|
||||
private static final Btrie_slim_mgr btrie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:XO_const.en; /wiki/, /site/ etc.
|
||||
.Add_bry_tid(Xoh_href_.Bry__wiki, Seg_wiki_tid)
|
||||
.Add_bry_tid(Xoh_href_.Bry__site, Seg_site_tid)
|
||||
.Add_bry_tid(Xoh_href_.Bry__xcmd, Seg_xcmd_tid);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user