mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.4.1
This commit is contained in:
@@ -18,11 +18,11 @@ 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) {
|
||||
public Xoh_cfg_file(Gfo_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"));
|
||||
img_media_play_btn = url_encoder.Encode_to_file_protocol(mw_file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = url_encoder.Encode_to_file_protocol(mw_file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = url_encoder.Encode_to_file_protocol(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;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xoh_consts {
|
||||
, 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_mid_id = Bry_.new_a7("\" id=\"xolnki_")
|
||||
, A_end = Bry_.new_a7("</a>")
|
||||
, Div_bgn_open = Bry_.new_a7("<div ")
|
||||
, Div_end = Bry_.new_a7("</div>")
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Xoh_page implements Xoa_page {
|
||||
public Xoa_page__commons_mgr Commons_mgr() {return commons_mgr;} private final Xoa_page__commons_mgr commons_mgr = new Xoa_page__commons_mgr();
|
||||
public int Exec_tid() {return exec_tid;} private int exec_tid = Xof_exec_tid.Tid_wiki_page;
|
||||
public byte[] Html_head_xtn() {return html_head_xtn;} public void Html_head_xtn_(byte[] v) {html_head_xtn = v;} private byte[] html_head_xtn = Bry_.Empty; // drd:web_browser
|
||||
public byte[] Url_bry_safe() {return page_url == null ? Bry_.Empty : page_url.Raw();}
|
||||
public byte[] Url_bry_safe() {return page_url == null ? Bry_.Empty : page_url.To_bry(Bool_.Y, Bool_.Y);}
|
||||
public void Init(Xow_wiki wiki, Xoa_url page_url, Xoa_ttl page_ttl, int page_id) {
|
||||
this.wiki = wiki; this.page_url = page_url; this.page_ttl = page_ttl; this.page_id = page_id;
|
||||
this.Clear();
|
||||
@@ -56,6 +56,7 @@ public class Xoh_page implements Xoa_page {
|
||||
public Xoh_page Ctor_by_page(Bry_bfr tmp_bfr, Xoae_page page) {
|
||||
this.page_id = page.Revision_data().Id();
|
||||
this.body = page.Hdump_data().Body();
|
||||
this.page_url = page.Url();
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
Xoh_head_mgr mod_mgr = html_data.Head_mgr();
|
||||
head_mgr.Init(mod_mgr.Itm__mathjax().Enabled(), mod_mgr.Itm__popups().Bind_hover_area(), mod_mgr.Itm__gallery().Enabled(), mod_mgr.Itm__hiero().Enabled());
|
||||
@@ -64,7 +65,7 @@ public class Xoh_page implements Xoa_page {
|
||||
this.sidebar_div = Xoh_page_.Save_sidebars(tmp_bfr, page, html_data);
|
||||
return this;
|
||||
}
|
||||
private void Clear() {
|
||||
public void Clear() {
|
||||
this.body_zip_tid = -1; this.body_hzip_tid = -1;
|
||||
display_ttl = content_sub = sidebar_div = Bry_.Empty;
|
||||
img_itms = Xohd_img_itm__base.Ary_empty;
|
||||
|
||||
@@ -17,7 +17,7 @@ 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.*; import gplx.xowa.wikis.pages.skins.*;
|
||||
class Xoh_page_ {
|
||||
public class Xoh_page_ {
|
||||
public static byte[] Save_sidebars(Bry_bfr tmp_bfr, Xoae_page page, Xopg_html_data html_data) {
|
||||
Xopg_xtn_skin_mgr mgr = html_data.Xtn_skin_mgr();
|
||||
int len = mgr.Count();
|
||||
|
||||
@@ -21,7 +21,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.langs.htmls
|
||||
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 extends gplx.core.brys.Bfr_arg_base {
|
||||
public class Xoh_page_wtr_wkr {
|
||||
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
|
||||
@@ -44,14 +44,20 @@ public class Xoh_page_wtr_wkr extends gplx.core.brys.Bfr_arg_base {
|
||||
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
|
||||
Bfr_arg__add(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);
|
||||
if (page_mode == Xopg_page_.Tid_html && wiki.App().Api_root().Html().Page().View_html_generates_hdump()) {
|
||||
Write_body(page_bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
Write_page_by_tid(page_mode, bfr, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_bry(page_bfr.To_bry_and_clear()));
|
||||
}
|
||||
else {
|
||||
Write_body(page_bfr, Xoh_wtr_ctx.Basic, page);
|
||||
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
|
||||
Bfr_arg__add(bfr);
|
||||
Write_body(bfr, Xoh_wtr_ctx.Basic, page);
|
||||
this.page = null;
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
@@ -97,7 +103,6 @@ public class Xoh_page_wtr_wkr extends gplx.core.brys.Bfr_arg_base {
|
||||
Xoh_page_wtr_wkr_.Bld_head_end(bfr, page); // add after </head>
|
||||
Xoh_page_wtr_wkr_.Bld_html_end(bfr, page); // add after </html>
|
||||
}
|
||||
@Override public void Bfr_arg__add(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();
|
||||
@@ -166,7 +171,7 @@ public class Xoh_page_wtr_wkr extends gplx.core.brys.Bfr_arg_base {
|
||||
) {
|
||||
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);
|
||||
app.Ctg_mgr().Pagectgs_wtr().Write(bfr, wiki, page, hctx);
|
||||
else
|
||||
wiki.Html_mgr().Ctg_mgr().Bld(bfr, page, ctgs_len);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ public class Xow_html_mgr implements GfoInvkAble {
|
||||
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"));
|
||||
img_media_play_btn = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(file_dir.GenSubFil("play.png"));
|
||||
img_media_info_btn = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(file_dir.GenSubFil("info.png"));
|
||||
img_thumb_magnify = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(file_dir.GenSubFil("magnify-clip.png"));
|
||||
img_xowa_protocol = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(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);
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Xow_hdump_mgr {
|
||||
Init_by_db(default_zip_tid, default_hzip_enable);
|
||||
}
|
||||
public void Init_by_db(byte default_zip_tid, boolean default_hzip_enable) {
|
||||
int dflt_hzip_tid = default_hzip_enable ? Xoh_hzip_dict_.Hzip__none : Xoh_hzip_dict_.Hzip__v1;
|
||||
int dflt_hzip_tid = default_hzip_enable ? Xoh_hzip_dict_.Hzip__v1 : Xoh_hzip_dict_.Hzip__none;
|
||||
save_mgr.Init_by_db(default_zip_tid, dflt_hzip_tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Xow_hdump_mgr__load {
|
||||
private final Xoh_page tmp_hpg; private final Bry_bfr tmp_bfr; private final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
|
||||
public Xow_hdump_mgr__load(Xow_wiki wiki, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, Xoh_page tmp_hpg, Bry_bfr tmp_bfr) {
|
||||
this.wiki = wiki; this.hzip_mgr = hzip_mgr; this.zip_mgr = zip_mgr; this.tmp_hpg = tmp_hpg; this.tmp_bfr = tmp_bfr;
|
||||
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), Xoa_app_.Utl__encoder_mgr().Fsys(), wiki.Domain_bry());
|
||||
this.make_mgr = new Xoh_make_mgr(wiki.App().Usr_dlg(), wiki.App().Fsys_mgr(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys, wiki.Domain_bry());
|
||||
}
|
||||
public Xoh_make_mgr Make_mgr() {return make_mgr;} private final Xoh_make_mgr make_mgr;
|
||||
public void Load(Xoae_page wpg) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Xow_hdump_mgr__save {
|
||||
private static byte[] Write(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, Xoh_hzip_mgr hzip_mgr, Io_stream_zip_mgr zip_mgr, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
|
||||
hzip_mgr.Encode(bfr.Clear(), wiki, hpg, src);
|
||||
src = bfr.To_bry_and_rls();
|
||||
src = bfr.To_bry_and_clear();
|
||||
}
|
||||
if (zip_tid > gplx.core.ios.Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Zip((byte)zip_tid, src);
|
||||
|
||||
@@ -19,23 +19,34 @@ package gplx.xowa.htmls.core.bldrs; import gplx.*; import gplx.xowa.*; import gp
|
||||
import gplx.dbs.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xob_hdump_mgr {
|
||||
private final Xowe_wiki wiki; private final Xow_hdump_mgr hdump_mgr;
|
||||
private final Xob_ns_to_db_mgr ns_to_db_mgr; int prv_row_len = 0;
|
||||
private final Hzip_stat_tbl stats_tbl; private final Hzip_stat_itm tmp_stat_itm;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
public Xob_hdump_mgr(Xowe_wiki wiki, Db_conn make_conn, long hdump_db_max, byte zip_tid, boolean hzip_enabled) {
|
||||
import gplx.xowa.apps.apis.xowa.bldrs.imports.*;
|
||||
public class Xob_hdump_bldr implements GfoInvkAble {
|
||||
private boolean enabled, hzip_enabled, hzip_compare;
|
||||
private Xowe_wiki wiki; private Xow_hdump_mgr hdump_mgr;
|
||||
private Xob_ns_to_db_mgr ns_to_db_mgr; int prv_row_len = 0;
|
||||
private Hzip_stat_tbl stats_tbl; private Hzip_stat_itm tmp_stat_itm;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(Io_mgr.Len_mb);
|
||||
public boolean Init(Xowe_wiki wiki, Db_conn make_conn) {
|
||||
if (!enabled) return false;
|
||||
this.wiki = wiki; this.hdump_mgr = wiki.Html__hdump_mgr(); this.tmp_stat_itm = hdump_mgr.Hzip_mgr().Hctx().Bicode__stat();
|
||||
hdump_mgr.Init_by_db(zip_tid, hzip_enabled);
|
||||
this.stats_tbl = new Hzip_stat_tbl(make_conn);
|
||||
Xoapi_import import_cfg = wiki.Appe().Api_root().Bldr().Wiki().Import();
|
||||
hdump_mgr.Init_by_db(import_cfg.Zip_tid_html(), hzip_enabled);
|
||||
Xowd_db_mgr core_data_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
|
||||
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(core_data_mgr.Db__core()), core_data_mgr, hdump_db_max);
|
||||
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__html(core_data_mgr.Db__core()), core_data_mgr, import_cfg.Html_db_max());
|
||||
Xob_ns_file_itm.Init_ns_bldr_data(Xowd_db_file_.Tid_html_data, wiki.Ns_mgr(), gplx.xowa.apps.apis.xowa.bldrs.imports.Xoapi_import.Ns_file_map__each);
|
||||
return true;
|
||||
}
|
||||
public void Insert(Xoae_page page) {
|
||||
Make_page_body(page);
|
||||
Xowd_db_file html_db = ns_to_db_mgr.Get_by_ns(page.Ttl().Ns().Bldr_data(), prv_row_len); // get html_db
|
||||
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_page(tmp_bfr, page), html_db, true); // save to db
|
||||
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 in hdump mode
|
||||
byte[] html_orig_bry = tmp_bfr.To_bry_and_clear();
|
||||
page.Hdump_data().Body_(html_orig_bry); // write to body bry
|
||||
Xowd_db_file html_db = ns_to_db_mgr.Get_by_ns(page.Ttl().Ns().Bldr_data(), prv_row_len); // get html_db
|
||||
this.prv_row_len = hdump_mgr.Save_mgr().Save(tmp_hpg.Ctor_by_page(tmp_bfr, page), html_db, true); // save to db
|
||||
if (hzip_compare) {
|
||||
// Compare(html_orig_bry, hdump_mgr.Save_mgr());
|
||||
}
|
||||
stats_tbl.Insert(tmp_hpg, tmp_stat_itm, page.Root().Root_src().length, tmp_hpg.Body().length, prv_row_len); // save stats
|
||||
}
|
||||
public void Bld_term() {this.Commit(); ns_to_db_mgr.Rls_all();}
|
||||
@@ -43,9 +54,12 @@ public class Xob_hdump_mgr {
|
||||
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 Make_page_body(Xoae_page page) {
|
||||
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
|
||||
page.Hdump_data().Body_(tmp_bfr.To_bry_and_clear()); // write to body bry
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_enabled_)) hzip_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_hzip_compare_)) hzip_compare = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_enabled_ = "enabled_", Invk_hzip_enabled_ = "hzip_enabled_", Invk_hzip_compare_ = "hzip_compare_";
|
||||
}
|
||||
@@ -48,6 +48,6 @@ class Xob_ns_to_db_wkr__html implements Xob_ns_to_db_wkr {
|
||||
, ", {0}"
|
||||
, ", p.page_redirect_id"
|
||||
, "FROM page p"
|
||||
, " JOIN <attach_db>html_page h ON p.page_id = h.page_id"
|
||||
, " JOIN <attach_db>html h ON p.page_id = h.page_id"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ public class Xoh_html_wtr {
|
||||
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);
|
||||
gplx.langs.htmls.encoders.Gfo_url_encoder_.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();
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.xowa.apps.fsys.*;
|
||||
public class Xoh_tidy_mgr implements GfoInvkAble {
|
||||
@@ -25,7 +26,7 @@ public class Xoh_tidy_mgr implements GfoInvkAble {
|
||||
wkr_tidy.Init_by_app(app);
|
||||
wkr_jtidy.Init_by_app(app);
|
||||
Xoa_fsys_eval cmd_eval = app.Url_cmd_eval();
|
||||
ProcessAdp.ini_(this, app.Usr_dlg(), wkr_tidy, cmd_eval, ProcessAdp.Run_mode_sync_timeout, 1 * 60, "~{<>bin_plat_dir<>}tidy" + Op_sys.Cur().Fsys_dir_spr_str() + "tidy", Xoh_tidy_wkr_tidy.Args_fmt, "source", "target");
|
||||
Process_adp.ini_(this, app.Usr_dlg(), wkr_tidy, cmd_eval, Process_adp.Run_mode_sync_timeout, 1 * 60, "~{<>bin_plat_dir<>}tidy" + Op_sys.Cur().Fsys_dir_spr_str() + "tidy", Xoh_tidy_wkr_tidy.Args_fmt, "source", "target");
|
||||
Wkr_tid_(Xoh_tidy_wkr_.Tid_jtidy);
|
||||
}
|
||||
public boolean Enabled() {return enabled;} private boolean enabled = true;
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.w3c.tidy.Configuration;
|
||||
import org.w3c.tidy.Tidy;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.core.envs.*;
|
||||
class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
private Tidy tidy;
|
||||
private ByteArrayOutputStream wtr;
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.core.envs.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import org.w3c.tidy.Tidy;
|
||||
|
||||
@@ -16,12 +16,13 @@ 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.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_tidy_wkr_tidy extends ProcessAdp implements Xoh_tidy_wkr { private Xoae_app app; private Io_url tidy_source, tidy_target;
|
||||
import gplx.core.envs.*;
|
||||
public class Xoh_tidy_wkr_tidy extends Process_adp implements Xoh_tidy_wkr { private Xoae_app app; private Io_url tidy_source, tidy_target;
|
||||
public byte Tid() {return Xoh_tidy_wkr_.Tid_tidy;}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
@Override public ProcessAdp Tmp_dir_(Io_url v) {
|
||||
@Override public Process_adp Tmp_dir_(Io_url v) {
|
||||
tidy_source = v.GenSubFil("tidy_source.html");
|
||||
tidy_target = v.GenSubFil("tidy_target.html");
|
||||
return super.Tmp_dir_(v);
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public class Hzip_stat_itm {
|
||||
public void Clear() {
|
||||
a_rhs = lnki_text_n = lnki_text_y = lnke_txt = lnke_brk_text_n = lnke_brk_text_y = 0;
|
||||
a_rhs = lnki_text_n = lnki_text_y = lnke__free = lnke__auto = lnke__text = 0;
|
||||
hdr_1 = hdr_2 = hdr_3 = hdr_4 = hdr_5 = hdr_6 = 0;
|
||||
img_full = 0;
|
||||
space = 0;
|
||||
@@ -27,9 +27,9 @@ public class Hzip_stat_itm {
|
||||
public int A_rhs() {return a_rhs;} public void A_rhs_add() {++a_rhs;} private int a_rhs;
|
||||
public int Lnki_text_n() {return lnki_text_n;} public void Lnki_text_n_add() {++lnki_text_n;} private int lnki_text_n;
|
||||
public int Lnki_text_y() {return lnki_text_y;} public void Lnki_text_y_add() {++lnki_text_y;} private int lnki_text_y;
|
||||
public int Lnke_txt() {return lnke_txt;} public void Lnke_txt_add() {++lnke_txt;} private int lnke_txt;
|
||||
public int Lnke_brk_text_n() {return lnke_brk_text_n;} public void Lnke_brk_text_n_add() {++lnke_brk_text_n;} private int lnke_brk_text_n;
|
||||
public int Lnke_brk_text_y() {return lnke_brk_text_y;} public void Lnke_brk_text_y_add() {++lnke_brk_text_y;} private int lnke_brk_text_y;
|
||||
public int Lnke__free() {return lnke__free;} public void Lnke__free__add() {++lnke__free;} private int lnke__free;
|
||||
public int Lnke__auto() {return lnke__auto;} public void Lnke__auto__add() {++lnke__auto;} private int lnke__auto;
|
||||
public int Lnke__text() {return lnke__text;} public void Lnke__text__add() {++lnke__text;} private int lnke__text;
|
||||
public int Img_full() {return img_full;} public void Img_full_add() {++img_full;} private int img_full;
|
||||
public int Hdr_1() {return hdr_1;} private int hdr_1;
|
||||
public int Hdr_2() {return hdr_2;} private int hdr_2;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Hzip_stat_tbl implements RlsAble {
|
||||
, fld_body_len = flds.Add_int("body_len"), fld_display_ttl_len = flds.Add_int("display_ttl_len"), fld_content_sub_len = flds.Add_int("content_sub_len"), fld_sidebar_div_len = flds.Add_int("sidebar_div_len")
|
||||
, fld_js_math = flds.Add_int("js_math"), fld_js_imap = flds.Add_int("js_imap"), fld_js_packed = flds.Add_int("js_packed"), fld_js_hiero = flds.Add_int("js_hiero")
|
||||
, fld_a_rhs = flds.Add_int("a_rhs"), fld_lnki_text_n = flds.Add_int("lnki_text_n"), fld_lnki_text_y = flds.Add_int("lnki_text_y")
|
||||
, fld_lnke_txt = flds.Add_int("lnke_txt"), fld_lnke_brk_text_n = flds.Add_int("lnke_brk_text_n"), fld_lnke_brk_text_y = flds.Add_int("lnke_brk_text_y")
|
||||
, fld_lnke_free = flds.Add_int("lnke_free"), fld_lnke_auto = flds.Add_int("lnke_auto"), fld_lnke_text = flds.Add_int("lnke_text")
|
||||
, fld_hdr_1 = flds.Add_int("hdr_1"), fld_hdr_2 = flds.Add_int("hdr_2"), fld_hdr_3 = flds.Add_int("hdr_3"), fld_hdr_4 = flds.Add_int("hdr_4"), fld_hdr_5 = flds.Add_int("hdr_5"), fld_hdr_6 = flds.Add_int("hdr_6")
|
||||
, fld_img_full = flds.Add_int("img_full")
|
||||
;
|
||||
@@ -59,9 +59,9 @@ public class Hzip_stat_tbl implements RlsAble {
|
||||
.Val_int(fld_a_rhs , hzip.A_rhs())
|
||||
.Val_int(fld_lnki_text_n , hzip.Lnki_text_n())
|
||||
.Val_int(fld_lnki_text_y , hzip.Lnki_text_y())
|
||||
.Val_int(fld_lnke_txt , hzip.Lnke_txt())
|
||||
.Val_int(fld_lnke_brk_text_n , hzip.Lnke_brk_text_n())
|
||||
.Val_int(fld_lnke_brk_text_y , hzip.Lnke_brk_text_y())
|
||||
.Val_int(fld_lnke_free , hzip.Lnke__free())
|
||||
.Val_int(fld_lnke_auto , hzip.Lnke__auto())
|
||||
.Val_int(fld_lnke_text , hzip.Lnke__text())
|
||||
.Val_int(fld_hdr_1 , hzip.Hdr_1())
|
||||
.Val_int(fld_hdr_2 , hzip.Hdr_2())
|
||||
.Val_int(fld_hdr_3 , hzip.Hdr_3())
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Tid__lnki = 3 + Base85_ascii
|
||||
, Tid__img = 4 + Base85_ascii
|
||||
, Tid__thm = 5 + Base85_ascii
|
||||
, Tid__gly = 6 + Base85_ascii
|
||||
, Tid__escape = 84 + Base85_ascii
|
||||
;
|
||||
public static final byte[]
|
||||
@@ -38,6 +39,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Bry__lnki = Bry_.new_ints(Escape, Tid__lnki)
|
||||
, Bry__img = Bry_.new_ints(Escape, Tid__img)
|
||||
, Bry__thm = Bry_.new_ints(Escape, Tid__thm)
|
||||
, Bry__gly = Bry_.new_ints(Escape, Tid__gly)
|
||||
;
|
||||
public static final String
|
||||
Key__escape = "escape"
|
||||
@@ -47,6 +49,7 @@ public class Xoh_hzip_dict_ {
|
||||
, Key__lnki = "lnki"
|
||||
, Key__img = "img"
|
||||
, Key__thm = "thm"
|
||||
, Key__gly = "gly"
|
||||
;
|
||||
public static final int Hzip__none = 0, Hzip__v1 = 1;
|
||||
}
|
||||
|
||||
@@ -30,11 +30,21 @@ public class Xoh_hzip_fxt {
|
||||
this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr();
|
||||
hpg.Init(wiki, Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
|
||||
}
|
||||
public Xow_wiki Wiki() {return parser_fxt.Wiki();}
|
||||
public void Clear() {hpg.Clear();}
|
||||
public Xowe_wiki Prep_create_wiki(String alias, String domain) {
|
||||
Xowe_wiki rv = Xoa_app_fxt.wiki_(parser_fxt.App(), domain);
|
||||
parser_fxt.Wiki().Xwiki_mgr().Add_by_atrs(Bry_.new_u8(alias), Bry_.new_u8(domain), null);
|
||||
return rv;
|
||||
}
|
||||
public void Test__bicode(String hzip, String html) {Test__bicode(hzip, html, html);}
|
||||
public void Test__bicode(String hzip, String html_enc, String html_dec) {
|
||||
hzip = Html_utl.Replace_apos(Xoh_hzip_fxt.Escape(hzip));
|
||||
html_enc = Html_utl.Replace_apos(html_enc);
|
||||
html_dec = Html_utl.Replace_apos(html_dec);
|
||||
Test__bicode_raw(hzip, html_enc, html_dec);
|
||||
}
|
||||
public void Test__bicode_raw(String hzip, String html_enc, String html_dec) {
|
||||
hzip = Xoh_hzip_fxt.Escape(hzip);
|
||||
Test__encode__raw(hzip, html_enc);
|
||||
Test__decode__raw(hzip, html_dec);
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ public class Xoh_hzip_mgr {
|
||||
pos = rdr.Pos();
|
||||
} catch (Exception e) {
|
||||
wkr.Pool__rls();
|
||||
Err err = Err_.cast_or_make(e);
|
||||
if (!err.Logged()) Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e), "page_url", page_url, "mid", Bry_.Mid_by_len_safe(src, pos, 255));
|
||||
gplx.langs.htmls.Html_utl.Log(e, "hzip decode failed", hpg.Url_bry_safe(), src, pos);
|
||||
pos += 2; // 2: skip escape and hook
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Xoh_make_mgr {
|
||||
private final Bry_rdr parser = new Bry_rdr();
|
||||
private final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
private final Xoh_hdoc_parser make_parser = new Xoh_hdoc_parser(new Xoh_hdoc_wkr__make());
|
||||
public Xoh_make_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Url_encoder fsys_encoder, byte[] wiki_domain) {
|
||||
public Xoh_make_mgr(Gfo_usr_dlg usr_dlg, Xoa_fsys_mgr fsys_mgr, Gfo_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();
|
||||
|
||||
@@ -31,10 +31,10 @@ public class Xoh_make_trie_ {
|
||||
, Bry__file_info = Bry_.new_a7("<xowa_info id='")
|
||||
, Bry__file_mgnf = Bry_.new_a7("<xowa_mgnf id=\"")
|
||||
, Bry__hiero_dir = Bry_.new_a7("~{xowa_hiero_dir}")
|
||||
, Bry__gallery_box_max = Bry_.new_a7("xowa_gly_box_max='")
|
||||
, Bry__gallery_box_w = Bry_.new_a7("xowa_gly_box_w='")
|
||||
, Bry__gallery_img_w = Bry_.new_a7("xowa_gly_img_w='")
|
||||
, Bry__gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
|
||||
// , Bry__gallery_box_max = Bry_.new_a7("xowa_gly_box_max='")
|
||||
// , Bry__gallery_box_w = Bry_.new_a7("xowa_gly_box_w='")
|
||||
// , Bry__gallery_img_w = Bry_.new_a7("xowa_gly_img_w='")
|
||||
// , Bry__gallery_img_pad = Bry_.new_a7("xowa_gly_img_pad='")
|
||||
, Bry__toc = Bry_.new_a7("~{xowa_toc}")
|
||||
;
|
||||
public static final byte[]
|
||||
@@ -51,10 +51,10 @@ public class Xoh_make_trie_ {
|
||||
trie_itm(rv, Tid__file_info , Byte_ascii.Apos , Bry__file_info);
|
||||
trie_itm(rv, Tid__file_mgnf , Byte_ascii.Apos , Bry__file_mgnf);
|
||||
trie_itm(rv, Tid__hiero_dir , Byte_ascii.Escape , Bry__hiero_dir);
|
||||
trie_itm(rv, Tid__gallery_box_max , Byte_ascii.Apos , Bry__gallery_box_max);
|
||||
trie_itm(rv, Tid__gallery_box_w , Byte_ascii.Apos , Bry__gallery_box_w);
|
||||
trie_itm(rv, Tid__gallery_img_w , Byte_ascii.Apos , Bry__gallery_img_w);
|
||||
trie_itm(rv, Tid__gallery_img_pad , Byte_ascii.Apos , Bry__gallery_img_pad);
|
||||
// trie_itm(rv, Tid__gallery_box_max , Byte_ascii.Apos , Bry__gallery_box_max);
|
||||
// trie_itm(rv, Tid__gallery_box_w , Byte_ascii.Apos , Bry__gallery_box_w);
|
||||
// trie_itm(rv, Tid__gallery_img_w , Byte_ascii.Apos , Bry__gallery_img_w);
|
||||
// trie_itm(rv, Tid__gallery_img_pad , Byte_ascii.Apos , Bry__gallery_img_pad);
|
||||
trie_itm(rv, Tid__toc , Byte_ascii.Escape , Bry__toc);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class Xohd_img_itm__base implements Xohd_img_itm {
|
||||
);
|
||||
}
|
||||
@gplx.Virtual public void Data_parse(Bry_rdr_old rdr) {
|
||||
this.lnki_ttl = Xoa_app_.Utl__encoder_mgr().Http_url().Decode(rdr.Read_bry_to_pipe());
|
||||
this.lnki_ttl = gplx.langs.htmls.encoders.Gfo_url_encoder_.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();
|
||||
|
||||
@@ -17,12 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.wkrs.mkrs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.metas.*;
|
||||
public class Xoh_hdoc_ctx {
|
||||
private byte[] fsys__file;
|
||||
public byte[] Fsys__root() {return fsys__root;} private byte[] fsys__root;
|
||||
public byte[] Fsys__file__comm() {return fsys__file__comm;} private byte[] fsys__file__comm;
|
||||
public byte[] Fsys__file__wiki() {return fsys__file__wiki;} private byte[] fsys__file__wiki;
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public byte[] Wiki__domain_bry() {return wiki__domain_bry;} private byte[] wiki__domain_bry;
|
||||
public Xow_ttl_parser Wiki__ttl_parser() {return wiki__ttl_parser;} private Xow_ttl_parser wiki__ttl_parser;
|
||||
public Xoa_file_mgr File__mgr() {return file__mgr;} private final Xoa_file_mgr file__mgr = new Xoa_file_mgr();
|
||||
@@ -33,6 +35,7 @@ public class Xoh_hdoc_ctx {
|
||||
public int Lnki__uid__nxt() {return ++lnki__uid;} private int lnki__uid; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
|
||||
this.app = app;
|
||||
this.fsys__root = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.fsys__file = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.fsys__file__comm = Bry_.Add(fsys__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
|
||||
@@ -49,4 +52,5 @@ public class Xoh_hdoc_ctx {
|
||||
bicode__stat.Clear();
|
||||
this.lnki__uid = 1; // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
|
||||
}
|
||||
public static final int Invalid = -1;
|
||||
}
|
||||
|
||||
@@ -28,4 +28,5 @@ public interface Xoh_hdoc_wkr {
|
||||
void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg);
|
||||
void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg);
|
||||
void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg);
|
||||
void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser arg);
|
||||
}
|
||||
|
||||
@@ -33,4 +33,5 @@ public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {hctx.Mkr().Lnki__hzip().Encode(bfr, hctx, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg) {hctx.Mkr().Thm__hzip().Encode(bfr, this, stat_itm, src, arg).Pool__rls();}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {hctx.Mkr().Img__hzip().Encode(bfr, stat_itm, src, arg, Bool_.Y).Pool__rls();}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser arg) {hctx.Mkr().Gly__hzip().Encode(bfr, stat_itm, src, arg).Pool__rls();}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,5 @@ public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
public void On_hdr (gplx.xowa.htmls.core.wkrs.hdrs.Xoh_hdr_parser arg) {wkr__hdr.Make(bfr, hpg, src, arg);}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {wkr__img.Make_by_parse(bfr, hpg, hctx, src, arg);}
|
||||
public void On_thm (gplx.xowa.htmls.core.wkrs.thms.Xoh_thm_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_gly (gplx.xowa.htmls.core.wkrs.glys.Xoh_gly_grp_parser arg) {}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public abstract class Xoh_itm_parser_fxt_base {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
protected byte[] src; protected int src_len;
|
||||
|
||||
@@ -21,33 +21,56 @@ public class Bfr_arg__html_atr implements Bfr_arg, Clear_able {
|
||||
private final byte[] atr_bgn;
|
||||
private int val_type;
|
||||
private int val_as_int;
|
||||
private byte[] val_as_bry; private int val_as_bry_bgn, val_as_bry_end;
|
||||
private byte[][] val_as_ary;
|
||||
private Bfr_arg val_as_arg;
|
||||
public Bfr_arg__html_atr(byte[] key) {this.atr_bgn = Bld_atr_bgn(key);}
|
||||
public void Clear() {
|
||||
val_type = Type__null;
|
||||
val_type = Tid__null;
|
||||
val_as_arg = null;
|
||||
val_as_int = Int_.Min_value;
|
||||
val_as_bry = null;
|
||||
val_as_ary = null;
|
||||
}
|
||||
public Bfr_arg__html_atr Set_by_arg(Bfr_arg v) {val_type = Type__arg; val_as_arg = v; return this;}
|
||||
public Bfr_arg__html_atr Set_by_int(int v) {val_type = Type__int; val_as_int = v; return this;}
|
||||
public byte[] Val_as_bry() {return val_as_bry;}
|
||||
public int Val_as_bry_bgn() {return val_as_bry_bgn;}
|
||||
public int Val_as_bry_end() {return val_as_bry_end;}
|
||||
public Bfr_arg__html_atr Set_by_arg(Bfr_arg v) {val_type = Tid__arg; val_as_arg = v; return this;}
|
||||
public Bfr_arg__html_atr Set_by_int(int v) {val_type = Tid__int; val_as_int = v; return this;}
|
||||
public Bfr_arg__html_atr Set_by_ary(byte[]... ary) {val_type = Tid__bry__ary; val_as_ary = ary; return this;}
|
||||
public Bfr_arg__html_atr Set_by_bry(byte[] bry) {val_type = Tid__bry__val; val_as_bry = bry; return this;}
|
||||
public Bfr_arg__html_atr Set_by_mid(byte[] bry, int bgn, int end) {val_type = Tid__bry__mid; val_as_bry = bry; val_as_bry_bgn = bgn; val_as_bry_end = end; return this;}
|
||||
public void Bfr_arg__clear() {this.Clear();}
|
||||
public boolean Bfr_arg__exists() {
|
||||
switch (val_type) {
|
||||
case Type__null: return false;
|
||||
case Type__arg: return val_as_arg.Bfr_arg__exists();
|
||||
case Type__int: return val_as_int != Int_.Min_value;
|
||||
default: throw Err_.new_unhandled(val_type);
|
||||
case Tid__null: return false;
|
||||
case Tid__arg: return val_as_arg.Bfr_arg__exists();
|
||||
case Tid__int: return val_as_int != Int_.Min_value;
|
||||
case Tid__bry__ary: return val_as_ary != null;
|
||||
case Tid__bry__val: return val_as_bry != null;
|
||||
case Tid__bry__mid: return val_as_bry != null;
|
||||
default: throw Err_.new_unhandled(val_type);
|
||||
}
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (!Bfr_arg__exists()) return;
|
||||
bfr.Add(atr_bgn);
|
||||
switch (val_type) {
|
||||
case Type__arg: val_as_arg.Bfr_arg__add(bfr); break;
|
||||
case Type__int: bfr.Add_int_variable(val_as_int); break;
|
||||
case Tid__arg: val_as_arg.Bfr_arg__add(bfr); break;
|
||||
case Tid__int: bfr.Add_int_variable(val_as_int); break;
|
||||
case Tid__bry__val: bfr.Add(val_as_bry); break;
|
||||
case Tid__bry__mid: bfr.Add_mid(val_as_bry, val_as_bry_bgn, val_as_bry_end); break;
|
||||
case Tid__bry__ary:
|
||||
int len = val_as_ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i != 0) bfr.Add_byte_space();
|
||||
byte[] v = val_as_ary[i];
|
||||
bfr.Add(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
bfr.Add_byte_quote();
|
||||
}
|
||||
public static byte[] Bld_atr_bgn(byte[] key) {return Bry_.Add(Byte_ascii.Space_bry, key, Byte_ascii.Eq_bry, Byte_ascii.Quote_bry);} // ' key="'
|
||||
private static final int Type__null = 0, Type__arg = 1, Type__int = 2;
|
||||
private static final int Tid__null = 0, Tid__arg = 1, Tid__int = 2, Tid__bry__mid = 3, Tid__bry__val = 4, Tid__bry__ary = 5;
|
||||
}
|
||||
|
||||
@@ -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.core.wkrs.bfr_args; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
public class Bfr_arg__wrapper implements Bfr_arg {
|
||||
private Bfr_arg inner;
|
||||
public void Clear() {
|
||||
inner = Bfr_arg_.Noop;
|
||||
}
|
||||
public Bfr_arg__wrapper Set(Bfr_arg v) {inner = v; return this;}
|
||||
public void Bfr_arg__clear() {this.Clear();}
|
||||
public boolean Bfr_arg__exists() {return inner != Bfr_arg_.Noop;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (!Bfr_arg__exists()) return;
|
||||
inner.Bfr_arg__add(bfr);
|
||||
}
|
||||
}
|
||||
@@ -21,21 +21,21 @@ import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.
|
||||
public class Xoh_gly_grp_parser implements Html_atr_class_wkr {
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
private Xoh_gly_itm_parser itm_parser = new Xoh_gly_itm_parser();
|
||||
// private Xoh_gly_itm_parser itm_parser = new Xoh_gly_itm_parser();
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag ul_tag) {
|
||||
this.rng_bgn = ul_tag.Src_bgn();
|
||||
/*
|
||||
parse class for traditional
|
||||
parse style for max_width
|
||||
*/
|
||||
Html_tag cur_tag = null;
|
||||
while (true) {
|
||||
cur_tag = tag_rdr.Tag__move_fwd_head();
|
||||
if (cur_tag.Name_id() != Html_tag_.Id__li) break; // no more <li>; break;
|
||||
itm_parser.Parse(hdoc_wkr, hctx, src, tag_rdr, cur_tag);
|
||||
}
|
||||
// Html_tag cur_tag = null;
|
||||
// while (true) {
|
||||
// cur_tag = tag_rdr.Tag__move_fwd_head();
|
||||
// if (cur_tag.Name_id() != Html_tag_.Id__li) break; // no more <li>; break;
|
||||
// itm_parser.Parse(hdoc_wkr, hctx, src, tag_rdr, cur_tag);
|
||||
// }
|
||||
// hdoc_wkr.On_thm(this);
|
||||
cur_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__ul);
|
||||
Html_tag cur_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__ul);
|
||||
this.rng_end = cur_tag.Src_end();
|
||||
return rng_end;
|
||||
}
|
||||
@@ -45,4 +45,5 @@ public class Xoh_gly_grp_parser implements Html_atr_class_wkr {
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
public static final byte[] Atr__class__gallery = Bry_.new_a7("gallery");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public class Xoh_gly_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__gly;}
|
||||
public Xoh_gly_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_gly_grp_parser arg) {
|
||||
bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
return hook_bgn;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_gly_hzip rv = new Xoh_gly_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
// private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1 , 1, 1, 1, 1 , 2, 1, 1, 1 , 1, 2, 2);
|
||||
// private static final int // SERIALIZED
|
||||
// Flag__file__w_diff_from_html = 0
|
||||
// , Flag__file__time_exists = 1
|
||||
// , Flag__file__page_exists = 2
|
||||
// , Flag__file__is_orig = 3
|
||||
// , Flag__file__repo_is_local = 4
|
||||
// , Flag__file__src_exists = 5
|
||||
// , Flag__img__cls_other_exists = 6
|
||||
// , Flag__anch__ns_is_image = 7
|
||||
// , Flag__anch__cls_tid = 8 // none, image
|
||||
// , Flag__anch__ns_id_needs_saving = 9
|
||||
// , Flag__img__alt_diff_from_anch_title = 10
|
||||
// , Flag__anch__href_diff_file = 11
|
||||
// , Flag__anch__title_missing = 12
|
||||
// , Flag__img__cls_tid = 13 // none, thumbimage, thumbborder
|
||||
// , Flag__anch__href_tid = 14 // wiki, site, anch, inet
|
||||
// ;
|
||||
}
|
||||
@@ -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.core.wkrs.glys; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_gly_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
private String Html__basic = gplx.langs.htmls.Html_utl.Replace_apos(String_.Concat_lines_nl_skip_last
|
||||
( "<ul class='gallery mw-gallery-traditional' style='max-width:978px;_width:978px;'>"
|
||||
, " <li class='gallerybox' style='width: 155px'>"
|
||||
, " <div style='width: 155px'>"
|
||||
, " <div class='thumb' style='width: 150px;'>"
|
||||
, " <div style='margin:75px auto;'>"
|
||||
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class='gallerytext'>"
|
||||
, " <p>"
|
||||
, " abc"
|
||||
, " </p>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, " <li class='gallerybox' style='width: 155px'>"
|
||||
, " <div style='width: 155px'>"
|
||||
, " <div class='thumb' style='width: 150px;'>"
|
||||
, " <div style='margin:75px auto;'>"
|
||||
, " <a href='/wiki/File:B.png' class='image' xowa_title='B.png'><img data-xoimg='0|120|120|-1|-1|-1' src='' width='0' height='0' alt=''></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class='gallerytext'>"
|
||||
, " <p>"
|
||||
, " abc"
|
||||
, " </p>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
@Test public void Basic() {
|
||||
fxt.Test__bicode(Html__basic, Html__basic);
|
||||
}
|
||||
}
|
||||
@@ -24,24 +24,27 @@ public class Xoh_img_bldr {
|
||||
public Xoh_img_wtr Wtr() {return wtr;} private final Xoh_img_wtr wtr = new Xoh_img_wtr();
|
||||
public Xof_fsdb_itm Fsdb_itm() {return fsdb_itm;} private Xof_fsdb_itm fsdb_itm;
|
||||
public void Make_by_parse(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, Xoh_img_parser arg) {
|
||||
Make( bfr, hpg, hctx, src, arg.Img_src_parser().File_ttl_bry(), arg.Img_xoimg_parser()
|
||||
, arg.Anch_href_parser().Atr(), arg.Anch_cls_parser().Atr(), arg.Anch_title_atr()
|
||||
, arg.Img_w(), arg.Img_h(), arg.Img_src_parser().Atr(), arg.Img_cls_parser().Atr(), arg.Img_alt_atr());
|
||||
Make( bfr, hpg, hctx, src, arg.Img_src().File_ttl_bry(), arg.Img_xoimg()
|
||||
, arg.Anch_href().Rel_nofollow_exists(), arg.Anch_href().Atr(), arg.Anch_cls().Atr(), arg.Anch_title()
|
||||
, arg.Img_w(), arg.Img_h(), arg.Img_src().Atr(), arg.Img_cls().Atr(), arg.Img_alt());
|
||||
wtr.Bfr_arg__add(bfr);
|
||||
}
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, byte[] lnki_ttl, Xoh_img_xoimg_parser img_xoimg
|
||||
, Bfr_arg anch_href, Bfr_arg anch_cls, Bfr_arg anch_ttl
|
||||
, boolean anch_rel_is_nofollow, Bfr_arg anch_href, Bfr_arg anch_cls, Bfr_arg anch_ttl
|
||||
, int img_w, int img_h, Bfr_arg img_src, Bfr_arg img_cls, Bfr_arg img_alt) {
|
||||
wtr.Clear();
|
||||
this.fsdb_itm = hpg.Img_mgr().Make_img();
|
||||
if (img_xoimg.Val_exists()) {
|
||||
if (img_xoimg.Val_dat_exists()) {
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, img_xoimg.Lnki_type(), img_xoimg.Lnki_upright(), img_xoimg.Lnki_w(), img_xoimg.Lnki_h(), img_xoimg.Lnki_time(), img_xoimg.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
|
||||
hctx.File__mgr().Check_cache(fsdb_itm);
|
||||
wtr.Img_xoimg_(src, img_xoimg.Val_bgn(), img_xoimg.Val_end());
|
||||
wtr.Img_src_empty_().Img_w_(0).Img_h_(0);
|
||||
}
|
||||
else if (img_w != -1) {
|
||||
wtr.Img_w_(img_w).Img_h_(img_h).Img_src_(img_src);
|
||||
}
|
||||
wtr.Anch_href_(anch_href).Anch_cls_(anch_cls).Anch_title_(anch_ttl);
|
||||
if (anch_rel_is_nofollow) wtr.Anch_rel_nofollow_();
|
||||
wtr.Anch_href_(anch_href).Anch_cls_(anch_cls).Anch_title_(anch_ttl).Anch_xowa_title_(lnki_ttl);
|
||||
wtr.Img_id_(Xoh_img_mgr.Bry__html_uid, fsdb_itm.Html_uid()).Img_alt_(img_alt).Img_cls_(img_cls);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
|
||||
public class Xoh_img_html__dump__tst {
|
||||
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
||||
public static final String
|
||||
Html__basic = "<a href='/wiki/File:A.png' class='image' title='abc'><img alt='abc' data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'/></a>"
|
||||
Html__basic = "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'/></a>"
|
||||
;
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {fxt.Test__html("[[File:A.png|220x110px|upright=.5|abc]]" , Html__basic);}
|
||||
|
||||
@@ -22,139 +22,170 @@ import gplx.xowa.htmls.core.wkrs.bfr_args.*; import gplx.xowa.htmls.core.wkrs.im
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private final int[] flag_ary;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_
|
||||
( 1, 1, 1, 1, 1, 1, 1, 1
|
||||
, 1, 1, 1, 2, 2);
|
||||
public Xoh_img_hzip() {
|
||||
this.flag_ary = flag_bldr.Val_ary();
|
||||
}
|
||||
public String Key() {return Xoh_hzip_dict_.Key__img;}
|
||||
public Xoh_img_bldr Bldr() {return bldr__img;} private Xoh_img_bldr bldr__img = new Xoh_img_bldr();
|
||||
public Xoh_img_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg, boolean write_hdr) {
|
||||
// img_map: <img id="xowa_file_img_100" alt="" src="file:///J:/xowa/file/commons.wikimedia.org/orig/b/8/a/7/Solar_System_Template_Final.png" width="666" height="36" usemap="#imagemap_1_1">
|
||||
Xoh_anch_href_parser anch_href = arg.Anch_href_parser();
|
||||
Html_atr anch_title = arg.Anch_title_atr();
|
||||
Xoa_ttl anch_href_ttl = anch_href.Page_ttl();
|
||||
Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg_parser();
|
||||
Xoh_img_cls_parser img_cls = arg.Img_cls_parser();
|
||||
Xoh_img_src_parser img_src = arg.Img_src_parser();
|
||||
boolean anch_href_has_site = anch_href.Site_exists();
|
||||
boolean anch_href_is_file = anch_href_ttl.Ns().Id_is_file() && !anch_href_has_site;
|
||||
boolean img_alt__diff__anch_title = arg.Img_alt__diff__anch_title();
|
||||
flag_ary[ 0] = img_xoimg.Val_exists() ? 1 : 0;
|
||||
flag_ary[ 1] = anch_href_has_site ? 1 : 0;
|
||||
flag_ary[ 2] = anch_href_is_file ? 1 : 0;
|
||||
flag_ary[ 3] = anch_title.Val_exists() ? 1 : 0;
|
||||
flag_ary[ 4] = img_alt__diff__anch_title ? 1 : 0;
|
||||
flag_ary[ 5] = img_cls.Other_exists() ? 1 : 0;
|
||||
flag_ary[ 6] = img_src.Repo_is_commons() ? 1 : 0;
|
||||
flag_ary[ 7] = img_src.File_is_orig() ? 1 : 0;
|
||||
flag_ary[ 8] = arg.File_w__diff__img_w() ? 1 : 0;
|
||||
flag_ary[ 9] = img_src.File_time_exists() ? 1 : 0;
|
||||
flag_ary[10] = img_src.File_page_exists() ? 1 : 0;
|
||||
flag_ary[11] = arg.Anch_cls_parser().Tid();
|
||||
flag_ary[12] = img_cls.Cls_tid();
|
||||
if (write_hdr) bfr.Add(Xoh_hzip_dict_.Bry__img);
|
||||
Xoh_hzip_int_.Encode(3, bfr, flag_bldr.Encode());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_w());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_h());
|
||||
bfr.Add(anch_href_ttl.Page_db()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (!anch_href_is_file) {
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href_ttl.Ns().Id());
|
||||
bfr.Add_mid(src, img_src.File_ttl_bgn(), img_src.File_ttl_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
if (arg.File_w__diff__img_w()) Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_w());
|
||||
if (img_src.File_time_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_time());
|
||||
if (img_src.File_page_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_page());
|
||||
if (img_xoimg.Val_exists()) bfr.Add_mid(src, img_xoimg.Val_bgn(), img_xoimg.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (anch_title.Val_exists()) bfr.Add_mid(src, anch_title.Val_bgn(), anch_title.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_alt__diff__anch_title) bfr.Add_mid(src, arg.Img_alt_atr().Val_bgn(), arg.Img_alt_atr().Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return this;
|
||||
}
|
||||
private final Xoh_img_xoimg_parser xoimg_parser = new Xoh_img_xoimg_parser();
|
||||
public Xoh_img_bldr Bldr() {return bldr;} private Xoh_img_bldr bldr = new Xoh_img_bldr();
|
||||
public Bfr_arg__href Anch_href_arg() {return anch_href_arg;} private final Bfr_arg__href anch_href_arg = new Bfr_arg__href();
|
||||
private final Bry_obj_ref
|
||||
anch_cls_mid = Bry_obj_ref.New_empty()
|
||||
, anch_title_mid = Bry_obj_ref.New_empty()
|
||||
, anch_href_mid = Bry_obj_ref.New_empty()
|
||||
, img_alt_mid = Bry_obj_ref.New_empty()
|
||||
, img_src_mid = Bry_obj_ref.New_empty()
|
||||
, img_cls_mid = Bry_obj_ref.New_empty()
|
||||
;
|
||||
public Xoh_img_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg, boolean write_hdr) {
|
||||
// img_map: <img id="xowa_file_img_100" alt="" src="file:///J:/xowa/file/commons.wikimedia.org/orig/b/8/a/7/Solar_System_Template_Final.png" width="666" height="36" usemap="#imagemap_1_1">
|
||||
Xoh_anch_href_parser anch_href = arg.Anch_href();
|
||||
Bry_obj_ref anch_page = arg.Anch_page();
|
||||
byte anch_href_tid = anch_href.Tid();
|
||||
boolean anch__ns_id_needs_saving = anch_href.Tid_has_ns() && anch_href.Page_ns_id() != Xow_ns_.Tid__file;
|
||||
Html_atr anch_title = arg.Anch_title();
|
||||
Xoa_ttl anch_href_ttl = anch_href.Page_ttl();
|
||||
Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg();
|
||||
Xoh_img_cls_parser img_cls = arg.Img_cls();
|
||||
Xoh_img_src_parser img_src = arg.Img_src();
|
||||
boolean img__alt_diff_from_anch_title = arg.Img_alt__diff__anch_title();
|
||||
boolean file__src_exists = !img_xoimg.Val_dat_exists();
|
||||
boolean anch_href_diff_file = !Bry_.Match(anch_page.Val(), anch_page.Val_bgn(), anch_page.Val_end(), anch_href.Page_ttl().Page_db());
|
||||
|
||||
flag_bldr.Set(Flag__file__w_diff_from_html , file__src_exists && arg.Img_w__diff__file_w());
|
||||
flag_bldr.Set(Flag__file__time_exists , file__src_exists && img_src.File_time_exists());
|
||||
flag_bldr.Set(Flag__file__page_exists , file__src_exists && img_src.File_page_exists());
|
||||
flag_bldr.Set(Flag__file__is_orig , file__src_exists && img_src.File_is_orig());
|
||||
flag_bldr.Set(Flag__file__repo_is_local , file__src_exists && !img_src.Repo_is_commons());
|
||||
flag_bldr.Set(Flag__file__src_exists , file__src_exists);
|
||||
flag_bldr.Set(Flag__img__cls_other_exists , img_cls.Other_exists());
|
||||
flag_bldr.Set(Flag__anch__ns_is_image , anch_href.Page_ns_id_is_image());
|
||||
flag_bldr.Set(Flag__anch__cls_tid , arg.Anch_cls().Tid());
|
||||
flag_bldr.Set(Flag__anch__ns_id_needs_saving , anch__ns_id_needs_saving);
|
||||
flag_bldr.Set(Flag__img__alt_diff_from_anch_title , img__alt_diff_from_anch_title);
|
||||
flag_bldr.Set(Flag__anch__href_diff_file , anch_href_diff_file);
|
||||
flag_bldr.Set(Flag__anch__title_missing , anch_title.Val_dat_missing());
|
||||
flag_bldr.Set(Flag__img__cls_tid , img_cls.Cls_tid());
|
||||
flag_bldr.Set(Flag__anch__href_tid , anch_href.Tid());
|
||||
// Tfds.Dbg(flag_bldr.Encode(), Array_.To_str(flag_bldr.Val_ary()));
|
||||
|
||||
if (write_hdr) bfr.Add(Xoh_hzip_dict_.Bry__img);
|
||||
Xoh_hzip_int_.Encode(2, bfr, flag_bldr.Encode());
|
||||
if (anch_href_tid == Xoh_anch_href_parser.Tid__inet)
|
||||
anch_href_mid.Mid_(src, anch_href.Val_bgn(), anch_href.Val_end());
|
||||
else
|
||||
anch_href_mid.Val_(anch_href_ttl.Page_db());
|
||||
bfr.Add_bry_ref_obj(anch_href_mid);
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (anch_href_diff_file) {
|
||||
arg.Anch_page().Bfr_arg__add(bfr);
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
switch (anch_href_tid) {
|
||||
case Xoh_anch_href_parser.Tid__anch:
|
||||
case Xoh_anch_href_parser.Tid__inet:
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__wiki:
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
if (anch__ns_id_needs_saving)
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href_ttl.Ns().Id());
|
||||
break;
|
||||
}
|
||||
if (file__src_exists) {
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_w());
|
||||
Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + arg.Img_h());
|
||||
if (arg.Img_w__diff__file_w()) Xoh_hzip_int_.Encode(2, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_w());
|
||||
if (img_src.File_time_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_time());
|
||||
if (img_src.File_page_exists()) Xoh_hzip_int_.Encode(1, bfr, Xoh_hzip_int_.Neg_1_adj + img_src.File_page());
|
||||
}
|
||||
else
|
||||
bfr.Add_mid(src, img_xoimg.Val_bgn(), img_xoimg.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (anch_title.Val_dat_exists()) bfr.Add_mid(src, anch_title.Val_bgn(), anch_title.Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img__alt_diff_from_anch_title) bfr.Add_mid(src, arg.Img_alt().Val_bgn(), arg.Img_alt().Val_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (img_cls.Other_exists()) bfr.Add_mid(src, img_cls.Other_bgn(), img_cls.Other_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
// decode rdr
|
||||
int flag = rdr.Read_int_by_base85(3);
|
||||
int flag = rdr.Read_int_by_base85(2);
|
||||
flag_bldr.Decode(flag);
|
||||
int img_w = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
int img_h = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
boolean file__is_orig = flag_bldr.Get_as_bool(Flag__file__is_orig);
|
||||
boolean file__repo_is_local = flag_bldr.Get_as_bool(Flag__file__repo_is_local);
|
||||
boolean file__src_exists = flag_bldr.Get_as_bool(Flag__file__src_exists);
|
||||
boolean img__cls_other_exists = flag_bldr.Get_as_bool(Flag__img__cls_other_exists);
|
||||
boolean anch__ns_is_image = flag_bldr.Get_as_bool(Flag__anch__ns_is_image);
|
||||
boolean anch__ns_id_needs_saving = flag_bldr.Get_as_bool(Flag__anch__ns_id_needs_saving);
|
||||
int anch__cls_tid = flag_bldr.Get_as_int(Flag__anch__cls_tid);
|
||||
boolean img__alt_diff_from_anch_title = flag_bldr.Get_as_bool(Flag__img__alt_diff_from_anch_title);
|
||||
boolean anch_href_diff_file = flag_bldr.Get_as_bool(Flag__anch__href_diff_file);
|
||||
boolean anch__title_missing = flag_bldr.Get_as_bool(Flag__anch__title_missing);
|
||||
int img_cls = flag_bldr.Get_as_int(Flag__img__cls_tid);
|
||||
int anch__href_tid = flag_bldr.Get_as_int(Flag__anch__href_tid);
|
||||
byte[] page_db = rdr.Read_bry_to();
|
||||
boolean img_xoimg_exists = flag_ary[ 0] == 1;
|
||||
boolean anch_href_has_site = flag_ary[ 1] == 1;
|
||||
boolean anch_href_is_file = flag_ary[ 2] == 1;
|
||||
boolean anch_title_exists = flag_ary[ 3] == 1;
|
||||
boolean img_alt__diff__anch_title = flag_ary[ 4] == 1;
|
||||
boolean img_cls_other_exists = flag_ary[ 5] == 1;
|
||||
boolean repo_is_commons = flag_ary[ 6] == 1;
|
||||
boolean file_is_orig = flag_ary[ 7] == 1;
|
||||
int anch_cls = flag_ary[11];
|
||||
int img_cls = flag_ary[12];
|
||||
int anch_href_ns = -1; byte[] anch_href_ttl_bry = null;
|
||||
if (!anch_href_is_file) {
|
||||
byte[] file_db = page_db;
|
||||
if (anch_href_diff_file) file_db = rdr.Read_bry_to();
|
||||
int anch_href_ns = -1;
|
||||
if (anch__ns_id_needs_saving)
|
||||
anch_href_ns = Xoh_lnki_dict_.Ns_decode(rdr);
|
||||
anch_href_ttl_bry = rdr.Read_bry_to();
|
||||
}
|
||||
int file_time = -1; int file_page = -1;
|
||||
int img_xoimg_bgn = -1; int img_xoimg_end = -1;
|
||||
int img_xoimg_bgn = -1, img_xoimg_end = -1, img_w = -1, img_h = -1, file_time = -1, file_page = -1;
|
||||
xoimg_parser.Clear();
|
||||
if (img_xoimg_exists) {
|
||||
if (file__src_exists) {
|
||||
img_w = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
img_h = rdr.Read_int_by_base85(2) - Xoh_hzip_int_.Neg_1_adj;
|
||||
}
|
||||
else {
|
||||
img_xoimg_bgn = rdr.Pos();
|
||||
img_xoimg_end = rdr.Find_fwd_lr();
|
||||
xoimg_parser.Parse(rdr, src, img_xoimg_bgn, img_xoimg_end);
|
||||
}
|
||||
int anch_title_bgn = -1, anch_title_end = -1;
|
||||
if (anch_title_exists) {
|
||||
if (!anch__title_missing) {
|
||||
anch_title_bgn = rdr.Pos();
|
||||
anch_title_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
int img_alt_bgn = -1, img_alt_end = -1;
|
||||
if (anch_title_exists) {
|
||||
if (!anch__title_missing) {
|
||||
img_alt_bgn = anch_title_bgn;
|
||||
img_alt_end = anch_title_end;
|
||||
}
|
||||
if (img_alt__diff__anch_title) {
|
||||
if (img__alt_diff_from_anch_title) {
|
||||
img_alt_bgn = rdr.Pos();
|
||||
img_alt_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
byte[] img_cls_other = Bry_.Empty;
|
||||
if (img_cls_other_exists)
|
||||
if (img__cls_other_exists)
|
||||
img_cls_other = Bry_.Mid(src, rdr.Pos(), rdr.Find_fwd_lr());
|
||||
int rv = rdr.Move_to(rdr.Pos());
|
||||
|
||||
// transform values
|
||||
if (anch_href_is_file)
|
||||
anch_href_arg.Set_by_file(page_db);
|
||||
else {
|
||||
if (anch_href_has_site) {
|
||||
}
|
||||
boolean anch_rel_is_nofollow = false;
|
||||
if (anch__ns_id_needs_saving) {
|
||||
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
anch_href_arg.Set_by_page(anch_href_ttl.Full_db());
|
||||
page_db = anch_href_ttl_bry;
|
||||
}
|
||||
else {
|
||||
if (anch__href_tid == Xoh_anch_href_parser.Tid__inet) {
|
||||
anch_href_arg.Set_by_raw(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(page_db));
|
||||
anch_rel_is_nofollow = true;
|
||||
}
|
||||
else {
|
||||
if (anch__ns_is_image)
|
||||
anch_href_arg.Set_by_raw(Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, gplx.xowa.wikis.nss.Xow_ns_.Alias__image__bry, Byte_ascii.Colon_bry, gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(page_db)));
|
||||
else
|
||||
anch_href_arg.Set_by_file(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(page_db));
|
||||
}
|
||||
}
|
||||
// NOTE: src must go underneath ttl
|
||||
Xof_url_bldr url_bldr = hctx.File__url_bldr();
|
||||
url_bldr.Init_by_root(repo_is_commons ? hctx.Fsys__file__comm() : hctx.Fsys__file__wiki(), Byte_ascii.Slash, false, false, Md5_depth);
|
||||
url_bldr.Init_by_itm(file_is_orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, page_db, Xof_file_wkr_.Md5(page_db), Xof_ext_.new_by_ttl_(page_db), img_w, file_time, file_page);
|
||||
url_bldr.Init_by_root(file__repo_is_local ? hctx.Fsys__file__wiki() : hctx.Fsys__file__comm(), Byte_ascii.Slash, false, false, Md5_depth);
|
||||
url_bldr.Init_by_itm(file__is_orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, file_db, Xof_file_wkr_.Md5(file_db), Xof_ext_.new_by_ttl_(file_db), img_w, file_time, file_page);
|
||||
byte[] img_src = url_bldr.Xto_bry();
|
||||
|
||||
anch_cls_mid.Val_(Xoh_anch_cls_.To_val(anch_cls));
|
||||
anch_title_mid.Mid_(src, anch_title_bgn, anch_title_end);
|
||||
img_alt_mid.Mid_(src, img_alt_bgn, img_alt_end);
|
||||
anch_cls_mid.Val_(Xoh_anch_cls_.To_val(anch__cls_tid));
|
||||
anch_title_mid.Mid_(src, anch_title_bgn, anch_title_end); if (anch_title_bgn == anch_title_end) anch_title_mid.Val_(null);
|
||||
img_alt_mid.Mid_(src, img_alt_bgn, img_alt_end); if (img_alt_mid.Val_is_empty()) img_alt_mid.Val_(Bry_.Empty);
|
||||
img_src_mid.Val_(img_src);
|
||||
img_cls_mid.Val_(Xoh_img_cls_.To_val(img_cls, img_cls_other));
|
||||
img_cls_mid.Val_(Xoh_img_cls_.To_val_or_null(img_cls, img_cls_other));
|
||||
|
||||
bldr__img.Make(bfr, hpg, hctx, src, page_db, xoimg_parser, anch_href_arg, anch_cls_mid, anch_title_mid, img_w, img_h, img_src_mid, img_cls_mid, img_alt_mid);
|
||||
if (write_to_bfr) bldr__img.Wtr().Bfr_arg__add(bfr);
|
||||
bldr.Make(bfr, hpg, hctx, src, file_db, xoimg_parser, anch_rel_is_nofollow, anch_href_arg, anch_cls_mid, anch_title_mid, img_w, img_h, img_src_mid, img_cls_mid, img_alt_mid);
|
||||
if (write_to_bfr) bldr.Wtr().Bfr_arg__add(bfr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -163,4 +194,22 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_hzip rv = new Xoh_img_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
public static int Md5_depth = 2;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1 , 1, 1, 1, 1 , 2, 1, 1, 1 , 1, 2, 2);
|
||||
private static final int // SERIALIZED
|
||||
Flag__file__w_diff_from_html = 0
|
||||
, Flag__file__time_exists = 1
|
||||
, Flag__file__page_exists = 2
|
||||
, Flag__file__is_orig = 3
|
||||
, Flag__file__repo_is_local = 4
|
||||
, Flag__file__src_exists = 5
|
||||
, Flag__img__cls_other_exists = 6
|
||||
, Flag__anch__ns_is_image = 7
|
||||
, Flag__anch__cls_tid = 8 // none, image
|
||||
, Flag__anch__ns_id_needs_saving = 9
|
||||
, Flag__img__alt_diff_from_anch_title = 10
|
||||
, Flag__anch__href_diff_file = 11
|
||||
, Flag__anch__title_missing = 12
|
||||
, Flag__img__cls_tid = 13 // none, thumbimage, thumbborder
|
||||
, Flag__anch__href_tid = 14 // wiki, site, anch, inet
|
||||
;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,41 @@ package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; impor
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_img_hzip__dump__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Before public void Clear() {fxt.Clear();}
|
||||
@Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%$+(#T\";A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, Xoh_img_html__dump__tst.Html__basic
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc'></a>"
|
||||
( "~%!!A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Href__encoding() { // [[File:Aéb.png|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!!Aéb.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='/wiki/File:A%C3%A9b.png' class='image' title='abc' xowa_title='Aéb.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link__wm__n() { // [[File:A.png|link=http://a.org|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!Dhttp://a.org~A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='http://a.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
// @Test public void Link__wm__y() { // [[File:A.png|link=//en.wiktionary.org/wiki/A|abc]]
|
||||
// fxt.Test__bicode
|
||||
// ( "~%!i=!!!!A~abc~"
|
||||
// , "<a href='/site/en.wiktionary.org/wiki/A' class='image' title='abc'><img id='xoimg_0' alt='abc'></a>"
|
||||
// );
|
||||
// }
|
||||
@Test public void Href__image() { // [[Image:A.png|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%-%A.png~0|220|110|0.5|-1|-1~abc~"
|
||||
, "<a href='/wiki/Image:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Missing() { // PURPOSE: bad dump shouldn't write corrupt data
|
||||
fxt.Test__bicode
|
||||
( "%|\"\\QA.png!!!!A"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='A' xowa_title='A.png'><img id='xoimg_0' alt='A'></a>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@ package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; impor
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_img_hzip__view__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Before public void Clear() {fxt.Clear();}
|
||||
@Test public void Basic__border__class__caption() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!rC#T\";A.png~abc~other~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' class='thumbborder other'></a>"
|
||||
( "~%iAA.png#T\";abc~other~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' class='thumbborder other' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link() { // [[File:A.png|link=B]]
|
||||
fxt.Test__bicode
|
||||
( "~%!H.#T\";B~#A.png~B~A.png~"
|
||||
, "<a href='/wiki/B' title='B'><img id='xoimg_0' alt='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'></a>"
|
||||
, "<a href='/wiki/B' title='B'><img id='xoimg_0' alt='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'></a>"
|
||||
( "~%SgB~A.png~##T\";B~A.png~"
|
||||
, "<a href='/wiki/B' class='image' title='B' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' alt='A.png'></a>"
|
||||
);
|
||||
}
|
||||
// link_site: [[File:A.png|link=//en.wiktionary.org/B]] -> [[File:Wiktionary-logo-en.svg|25x25px|link=//en.wiktionary.org/wiki/Special:Search/Earth|Search Wiktionary]] -> <a href="/site/en.wiktionary.org/wiki/Special:Search/Earth" rel="nofollow" title="Search Wiktionary" xowa_title="Wiktionary-logo-en.svg"><img id="xowa_file_img_88" alt="Search Wiktionary" src="file:///J:/xowa/file/commons.wikimedia.org/thumb/f/8/c/4/Wiktionary-logo-en.svg/23px.png" width="23" height="25"></a>
|
||||
|
||||
@@ -22,8 +22,8 @@ public class Xoh_img_make__dump__tst {
|
||||
@Before public void Init() {fxt.Clear();}
|
||||
@Test public void Html_exists__n() {
|
||||
String
|
||||
orig = "<a href='/wiki/File:A.png' class='image' title='abc'><img alt='abc' data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'></a>"
|
||||
, expd = "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_0' alt='abc'></a>"
|
||||
orig = "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' alt='abc'></a>"
|
||||
, expd = "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
;
|
||||
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd)
|
||||
.Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1)
|
||||
|
||||
@@ -16,47 +16,52 @@ 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.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_img_parser {
|
||||
private byte[] src;
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public int Anch_tag_bgn() {return anch_tag_bgn;} private int anch_tag_bgn;
|
||||
public int Anch_tag_end() {return anch_tag_end;} private int anch_tag_end;
|
||||
public Xoh_anch_href_parser Anch_href_parser() {return anch_href_parser;} private Xoh_anch_href_parser anch_href_parser = new Xoh_anch_href_parser();
|
||||
public Xoh_anch_cls_parser Anch_cls_parser() {return anch_cls_parser;} private Xoh_anch_cls_parser anch_cls_parser = new Xoh_anch_cls_parser();
|
||||
public Xoh_img_src_parser Img_src_parser() {return img_src_parser;} private final Xoh_img_src_parser img_src_parser = new Xoh_img_src_parser();
|
||||
public Xoh_img_cls_parser Img_cls_parser() {return img_cls_parser;} private final Xoh_img_cls_parser img_cls_parser = new Xoh_img_cls_parser();
|
||||
public Xoh_img_xoimg_parser Img_xoimg_parser() {return img_xoimg_parser;} private Xoh_img_xoimg_parser img_xoimg_parser = new Xoh_img_xoimg_parser();
|
||||
public Html_atr Anch_title_atr() {return anch_title_atr;} private Html_atr anch_title_atr;
|
||||
public Html_atr Img_alt_atr() {return img_alt_atr;} private Html_atr img_alt_atr;
|
||||
public boolean Img_alt__diff__anch_title() {return !Bry_.Match(src, img_alt_atr.Val_bgn(), img_alt_atr.Val_end(), src, anch_title_atr.Val_bgn(), anch_title_atr.Val_end());}
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public boolean Img_w_exists() {return img_w != -1;}
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public boolean File_w__diff__img_w() {return img_src_parser.File_w() != img_w;}
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_tag) {
|
||||
// "<a href='/wiki/File:A.png' class='image'><img alt='' src='file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png' width='220' height='110' class='thumbimage'></a>"
|
||||
this.src = src; this.anch_tag_bgn = anch_tag.Src_bgn(); this.anch_tag_end = anch_tag.Src_end();
|
||||
this.rng_bgn = anch_tag_bgn; // <a
|
||||
this.anch_title_atr = anch_tag.Atrs__get_by_or_empty(Html_atr_.Bry__title); // title='abc'
|
||||
anch_cls_parser.Parse(tag_rdr.Rdr(), src, anch_tag); // class='image'
|
||||
anch_href_parser.Parse(tag_rdr.Rdr(), hctx.Wiki__ttl_parser(), anch_tag); // href='/wiki/File:A.png'
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__img); // <img>
|
||||
img_xoimg_parser.Parse(tag_rdr.Rdr(), src, img_tag); // data-xoimg='...'
|
||||
this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
|
||||
this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
|
||||
this.img_alt_atr = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png'
|
||||
img_cls_parser.Parse(tag_rdr.Rdr(), src, img_tag); // class='thumbborder'
|
||||
img_src_parser.Parse(tag_rdr.Rdr(), hctx.Wiki__domain_bry(), img_tag); // src='...'
|
||||
Html_tag anch_tail_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
this.rng_end = anch_tail_tag.Src_end();
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public Xoh_anch_href_parser Anch_href() {return anch_href;} private Xoh_anch_href_parser anch_href = new Xoh_anch_href_parser();
|
||||
public Xoh_anch_cls_parser Anch_cls() {return anch_cls;} private Xoh_anch_cls_parser anch_cls = new Xoh_anch_cls_parser();
|
||||
public Html_atr Anch_title() {return anch_title;} private Html_atr anch_title;
|
||||
public Bry_obj_ref Anch_page() {return anch_page;} private Bry_obj_ref anch_page = Bry_obj_ref.New_empty();
|
||||
public Xoh_img_src_parser Img_src() {return img_src;} private final Xoh_img_src_parser img_src = new Xoh_img_src_parser();
|
||||
public Xoh_img_cls_parser Img_cls() {return img_cls;} private final Xoh_img_cls_parser img_cls = new Xoh_img_cls_parser();
|
||||
public Xoh_img_xoimg_parser Img_xoimg() {return img_xoimg_parser;} private Xoh_img_xoimg_parser img_xoimg_parser = new Xoh_img_xoimg_parser();
|
||||
public Html_atr Img_alt() {return img_alt;} private Html_atr img_alt;
|
||||
public boolean Img_alt__diff__anch_title() {return !Bry_.Match(src, img_alt.Val_bgn(), img_alt.Val_end(), src, anch_title.Val_bgn(), anch_title.Val_end());}
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public boolean Img_w__diff__file_w() {return img_w != img_src.File_w();}
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_head) {
|
||||
this.src = src; Bry_rdr rdr = tag_rdr.Rdr();
|
||||
this.rng_bgn = anch_head.Src_bgn(); // <a
|
||||
if (!anch_href.Parse(rdr, hctx.App(), hctx.Wiki__ttl_parser(), anch_head)) return Xoh_hdoc_ctx.Invalid; // href='/wiki/File:A.png'
|
||||
if (!anch_cls.Parse(rdr, src, anch_head)) return Xoh_hdoc_ctx.Invalid; // class='image'
|
||||
this.anch_title = anch_head.Atrs__get_by_or_empty(Html_atr_.Bry__title); // title='abc'
|
||||
Html_atr xowa_title = anch_head.Atrs__get_by_or_empty(Bry__atr__xowa_title); // xowa_title='A.png'
|
||||
if (xowa_title.Val_dat_exists()) anch_page.Val_(xowa_title.Val());
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__img); // <img
|
||||
img_xoimg_parser.Parse(rdr, src, img_tag); // data-xoimg='...'
|
||||
this.img_w = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__width, Xof_img_size.Size__neg1); // width='220'
|
||||
this.img_h = img_tag.Atrs__get_as_int_or(Html_atr_.Bry__height, Xof_img_size.Size__neg1); // height='110'
|
||||
this.img_alt = img_tag.Atrs__get_by_or_empty(Html_atr_.Bry__alt); // alt='File:A.png'
|
||||
img_cls.Parse(rdr, src, img_tag); // class='thumbborder'
|
||||
if (!img_src.Parse(rdr, hctx.Wiki__domain_bry(), img_tag)) return Xoh_hdoc_ctx.Invalid; // src='...'
|
||||
if (anch_page.Val_is_empty()) {
|
||||
anch_page.Val_(img_src.File_ttl_bry());
|
||||
if (anch_page.Val_is_empty())
|
||||
anch_page.Val_(anch_href.Page_ttl().Page_db());
|
||||
}
|
||||
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
this.rng_end = anch_tail.Src_end();
|
||||
return rng_end;
|
||||
}
|
||||
public static final byte[]
|
||||
Bry__cls__anch__image = Bry_.new_a7("image")
|
||||
, Bry__cls__img__thumbimage = Bry_.new_a7("thumbimage")
|
||||
, Bry__atr__xowa_title = Bry_.new_a7("xowa_title")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@ public class Xoh_img_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private final Bfr_arg__indent indent = new Bfr_arg__indent();
|
||||
private final Bfr_arg__html_atr
|
||||
anch_href = new Bfr_arg__html_atr(Html_atr_.Bry__href)
|
||||
, anch_rel = new Bfr_arg__html_atr(Html_atr_.Bry__rel)
|
||||
, anch_cls = new Bfr_arg__html_atr(Html_atr_.Bry__class)
|
||||
, anch_title = new Bfr_arg__html_atr(Html_atr_.Bry__title)
|
||||
, anch_xowa_title = new Bfr_arg__html_atr(Xoh_img_parser.Bry__atr__xowa_title)
|
||||
, img_id = new Bfr_arg__html_atr(Html_atr_.Bry__id)
|
||||
, img_xoimg = new Bfr_arg__html_atr(Xoh_img_xoimg_parser.Bry__name)
|
||||
, img_alt = new Bfr_arg__html_atr(Html_atr_.Bry__alt)
|
||||
@@ -37,19 +39,24 @@ public class Xoh_img_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private final Bfr_arg__id img_id_val = new Bfr_arg__id();
|
||||
public Xoh_img_wtr() {
|
||||
arg_ary = new Bfr_arg[]
|
||||
{ indent, anch_href, anch_cls, anch_title
|
||||
, img_id, img_xoimg, img_alt, img_src, img_w, img_h, img_cls
|
||||
{ indent, anch_href, anch_rel, anch_cls, anch_title, anch_xowa_title
|
||||
, img_id, img_xoimg, img_src, img_w, img_h, img_cls, img_alt
|
||||
};
|
||||
}
|
||||
public Bfr_arg__html_atr Img_alt() {return img_alt;}
|
||||
public Xoh_img_wtr Indent_(int v) {indent.Set(v); return this;}
|
||||
public Xoh_img_wtr Anch_href_(Bfr_arg v) {anch_href.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Anch_rel_nofollow_() {anch_rel.Set_by_bry(gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_dict_.Html__rel__nofollow); return this;}
|
||||
public Xoh_img_wtr Anch_cls_(Bfr_arg v) {anch_cls.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Anch_title_(Bfr_arg v) {anch_title.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Anch_xowa_title_(byte[] v) {anch_xowa_title.Set_by_bry(v); return this;}
|
||||
public Xoh_img_wtr Img_id_(byte[] prefix, int uid) {img_id.Set_by_arg(img_id_val.Set(prefix, uid)); return this;}
|
||||
public Xoh_img_wtr Img_w_(int v) {img_w.Set_by_int(v); return this;}
|
||||
public Xoh_img_wtr Img_h_(int v) {img_h.Set_by_int(v); return this;}
|
||||
public Xoh_img_wtr Img_xoimg_(byte[] src, int bgn, int end) {img_xoimg.Set_by_mid(src, bgn, end); return this;}
|
||||
public Xoh_img_wtr Img_cls_(Bfr_arg v) {img_cls.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Img_src_(Bfr_arg v) {img_src.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Img_src_empty_() {img_src.Set_by_bry(Bry_.Empty); return this;}
|
||||
public Xoh_img_wtr Img_alt_(Bfr_arg v) {img_alt.Set_by_arg(v); return this;}
|
||||
public Xoh_img_wtr Clear() {
|
||||
for (Bfr_arg arg : arg_ary)
|
||||
@@ -60,6 +67,6 @@ public class Xoh_img_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
fmtr.Bld_bfr_many(bfr, (Object[])arg_ary);
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_
|
||||
( "~{indent}<a~{anch_href}~{anch_cls}~{anch_title}><img~{img_id}~{img_alt}~{img_xoimg}~{img_src}~{img_w}~{img_h}~{img_cls}></a>"
|
||||
, "indent", "anch_href", "anch_cls", "anch_title", "img_id", "img_xoimg", "img_alt", "img_src", "img_w", "img_h", "img_cls");
|
||||
( "~{indent}<a~{anch_href}~{anch_rel}~{anch_cls}~{anch_title}~{anch_xowa_title}><img~{img_id}~{img_xoimg}~{img_src}~{img_w}~{img_h}~{img_cls}~{img_alt}></a>"
|
||||
, "indent", "anch_href", "anch_rel", "anch_cls", "anch_title", "anch_xowa_title", "img_id", "img_xoimg", "img_src", "img_w", "img_h", "img_cls", "img_alt");
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xoh_anch_cls_ {
|
||||
public static final byte
|
||||
Tid__none = 0 // EX: [[File:A.png|link=A]] -> "<a class=''>"
|
||||
, Tid__image = 1 // EX: [[File:A.png]] -> "<a class='image'>"
|
||||
public static final byte // SERIALIZED
|
||||
Tid__image = 0 // EX: [[File:A.png]] -> "<a class='image'>"
|
||||
, Tid__none = 1 // EX: [[File:A.png|link=A]] -> "<a class=''>"
|
||||
;
|
||||
public static final String
|
||||
Str__image = "image"
|
||||
|
||||
@@ -22,14 +22,17 @@ public class Xoh_anch_cls_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
public boolean Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image'
|
||||
int src_bgn = atr.Val_bgn(); int src_end = atr.Val_end();
|
||||
if (src_bgn == -1)
|
||||
if (src_bgn == -1) {
|
||||
tid = Xoh_anch_cls_.Tid__none;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
rdr.Init_by_sub(owner_rdr, "anch.cls", src_bgn, src_end);
|
||||
this.tid = rdr.Chk(Xoh_anch_cls_.Trie);
|
||||
this.tid = rdr.Chk_or(Xoh_anch_cls_.Trie, Byte_ascii.Max_7_bit);
|
||||
return tid != Byte_ascii.Max_7_bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xoh_img_cls_ {
|
||||
public static final byte
|
||||
Tid__none = 0
|
||||
, Tid__thumbimage = 2 // EX: [[File:A.png|thumb]] -> "<img class='thumbimage'>"
|
||||
, Tid__thumbborder = 3 // EX: [[File:A.png|border]] -> "<img class='thumbborder'>"
|
||||
public static final byte // SERIALIZED
|
||||
Tid__none = 0 // EX: [[File:A.png]] -> "<img>"
|
||||
, Tid__thumbimage = 1 // EX: [[File:A.png|thumb]] -> "<img class='thumbimage'>"
|
||||
, Tid__thumbborder = 2 // EX: [[File:A.png|border]] -> "<img class='thumbborder'>"
|
||||
;
|
||||
public static final String
|
||||
Str__thumbimage = "thumbimage"
|
||||
@@ -54,9 +54,9 @@ public class Xoh_img_cls_ {
|
||||
}
|
||||
return Bry_.Add(Bry__html_class, cls, other_0, other_1, Byte_ascii.Quote_bry);
|
||||
}
|
||||
public static byte[] To_val(int tid, byte[] other) {
|
||||
public static byte[] To_val_or_null(int tid, byte[] other) {
|
||||
boolean other_is_empty = Bry_.Len_eq_0(other);
|
||||
if (tid == Xoh_img_cls_.Tid__none && other_is_empty) return Bry_.Empty;
|
||||
if (tid == Xoh_img_cls_.Tid__none && other_is_empty) return null;
|
||||
byte[] cls = null;
|
||||
switch (tid) {
|
||||
case Xoh_img_cls_.Tid__thumbimage: cls = Bry__thumbimage; break;
|
||||
|
||||
@@ -39,21 +39,33 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
public boolean File_time_exists() {return file_time != -1;}
|
||||
public boolean File_page_exists() {return file_page != -1;}
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, Html_tag tag) {
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
|
||||
if (!atr.Val_exists()) return;
|
||||
Parse(owner_rdr, domain_bry, atr.Val_bgn(), atr.Val_end());
|
||||
private void Clear() {
|
||||
val_bgn = val_end = repo_bgn = repo_end = file_ttl_bgn = file_ttl_end = file_w = file_time = file_page = -1;
|
||||
repo_is_commons = file_is_orig = false;
|
||||
file_ttl_bry = null;
|
||||
atr = null;
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
|
||||
public boolean Parse(Bry_rdr owner_rdr, byte[] domain_bry, Html_tag tag) {
|
||||
this.Clear();
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
|
||||
if (!atr.Val_dat_exists()) return true; // empty src; just return true;
|
||||
return Parse(owner_rdr, domain_bry, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public boolean Parse(Bry_rdr owner_rdr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
|
||||
this.Clear();
|
||||
this.src = owner_rdr.Src();
|
||||
this.val_bgn = val_bgn; this.val_end = val_end;
|
||||
file_w = file_time = file_page = -1;
|
||||
rdr.Init_by_sub(owner_rdr, "img.src.xowa", val_bgn, val_end).Dflt_dlm_(Byte_ascii.Slash);
|
||||
rdr.Fail_throws_err_(Bool_.N);
|
||||
repo_bgn = rdr.Find_fwd_rr(Bry__file); // skip past /file/; EX: "file:///J:/xowa/file/commons.wikimedia.org/"
|
||||
if (repo_bgn == -1) return false;
|
||||
rdr.Fail_throws_err_(Bool_.Y);
|
||||
repo_end = rdr.Find_fwd_lr();
|
||||
repo_is_commons = Bry_.Match(rdr.Src(), repo_bgn, repo_end, Xow_domain_itm_.Bry__commons);
|
||||
if (!repo_is_commons) {
|
||||
if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) return false; // rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
// if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
}
|
||||
file_is_orig = rdr.Chk(trie) == Tid__orig; // check if 'orig/' or 'thumb/'
|
||||
file_ttl_bgn = Skip_md5(); // skip md5; EX: "0/1/2/3/"
|
||||
@@ -68,6 +80,7 @@ public class Xoh_img_src_parser implements Xoh_itm_parser {
|
||||
else if (rdr.Is(Byte_ascii.Dash))
|
||||
file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png"
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private int Skip_md5() {
|
||||
byte[] src = rdr.Src();
|
||||
|
||||
@@ -29,12 +29,12 @@ public class Xoh_img_src_parser_tst {
|
||||
@Test public void Md5_depth_4() {
|
||||
fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/1/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
|
||||
}
|
||||
@Test public void Fail__orig_mode() {
|
||||
fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'");
|
||||
}
|
||||
@Test public void Fail__repo_mode() {
|
||||
fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'");
|
||||
}
|
||||
// @Test public void Fail__orig_mode() {
|
||||
// fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'");
|
||||
// }
|
||||
// @Test public void Fail__repo_mode() {
|
||||
// fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'");
|
||||
// }
|
||||
}
|
||||
class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt_base {
|
||||
private final Xoh_img_src_parser parser = new Xoh_img_src_parser();
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xoh_img_xoimg_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public int Val_bgn() {return val_bgn;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} private int val_end;
|
||||
public boolean Val_exists() {return val_end > val_bgn;}
|
||||
public boolean Val_dat_exists() {return val_end > val_bgn;}
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
public class Xoh_lnke_dict_ {
|
||||
public static final byte // SERIALIZED
|
||||
Type__free = Byte_ascii.Num_1
|
||||
, Type__auto = Byte_ascii.Num_2
|
||||
, Type__text = Byte_ascii.Num_3
|
||||
Type__free = 0
|
||||
, Type__auto = 1
|
||||
, Type__text = 2
|
||||
;
|
||||
public static final byte[]
|
||||
Html__atr__0 = Bry_.new_a7("\" rel=\"nofollow\" class=\"external ")
|
||||
@@ -29,6 +29,10 @@ public class Xoh_lnke_dict_ {
|
||||
, Html__class__text = Bry_.new_a7("text")
|
||||
, Html__rhs_end = Bry_.new_a7("\">")
|
||||
;
|
||||
public static byte[]
|
||||
Html__rel__nofollow = Bry_.new_a7("nofollow")
|
||||
, Html__cls__external = Bry_.new_a7("external")
|
||||
;
|
||||
public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Html__class__free, Type__free)
|
||||
.Add_bry_byte(Html__class__auto, Type__auto)
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Xoh_lnke_html {
|
||||
else { // xowa or regular; EX: http://a.org
|
||||
if (proto_is_xowa) {
|
||||
bfr.Add(Xop_lnke_wkr.Bry_xowa_protocol);
|
||||
Xoa_app_.Utl__encoder_mgr().Gfs().Encode(bfr, src, href_bgn, href_end);
|
||||
gplx.langs.htmls.encoders.Gfo_url_encoder_.Gfs.Encode(bfr, src, href_bgn, href_end);
|
||||
return false;
|
||||
}
|
||||
else { // regular; add href
|
||||
@@ -57,12 +57,12 @@ public class Xoh_lnke_html {
|
||||
}
|
||||
}
|
||||
else { // xwiki
|
||||
Url_encoder href_encoder = Xoa_app_.Utl__encoder_mgr().Href_quotes();
|
||||
Gfo_url_encoder href_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href_quotes;
|
||||
bfr.Add(Xoh_href_.Bry__site).Add(lnke_xwiki_wiki).Add(Xoh_href_.Bry__wiki)
|
||||
.Add(href_encoder.Encode(lnke.Lnke_xwiki_page())); // NOTE: must encode page; EX:%22%3D -> '">' which will end attribute; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
|
||||
.Add(href_encoder.Encode(lnke.Lnke_xwiki_page())); // NOTE: must encode page; EX:%22%3D -> '">' which will end attribute; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
|
||||
if (lnke.Lnke_xwiki_qargs() != null)
|
||||
Gfo_qarg_mgr.Concat_bfr(bfr, href_encoder, lnke.Lnke_xwiki_qargs()); // NOTE: must encode args
|
||||
return false;
|
||||
return ctx.Wiki().App().Xwiki_mgr__missing(lnke_xwiki_wiki);
|
||||
}
|
||||
}
|
||||
public void Write_caption(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke, int href_bgn, int href_end, boolean proto_is_xowa) {
|
||||
|
||||
@@ -21,43 +21,70 @@ import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_lnke_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__lnke;}
|
||||
public Xoh_lnke_hzip Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnke_parser arg) {
|
||||
byte lnke_type = arg.Lnke_type();
|
||||
switch (lnke_type) {
|
||||
case Xoh_lnke_dict_.Type__free: stat_itm.Lnke_txt_add();break;
|
||||
case Xoh_lnke_dict_.Type__text: stat_itm.Lnke_brk_text_y_add(); break;
|
||||
case Xoh_lnke_dict_.Type__auto: stat_itm.Lnke_brk_text_n_add(); break;
|
||||
byte anch_cls_type = arg.Anch_cls_type();
|
||||
boolean auto_exists = arg.Auto_id() != -1;
|
||||
boolean text_exists = arg.Capt_end() != -1;
|
||||
flag_bldr.Set(Flag__auto_exists , auto_exists);
|
||||
flag_bldr.Set(Flag__text_exists , text_exists);
|
||||
flag_bldr.Set(Flag__anch_cls , anch_cls_type);
|
||||
|
||||
switch (anch_cls_type) {
|
||||
case Xoh_lnke_dict_.Type__free: stat_itm.Lnke__free__add();break;
|
||||
case Xoh_lnke_dict_.Type__auto: stat_itm.Lnke__auto__add(); break;
|
||||
case Xoh_lnke_dict_.Type__text: stat_itm.Lnke__text__add(); break;
|
||||
}
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__lnke); // add hook
|
||||
bfr.Add_byte(lnke_type); // add type
|
||||
bfr.Add_mid(src, arg.Href_bgn(), arg.Href_end()); // add href
|
||||
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__lnke); // add hook
|
||||
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode()); // add flag
|
||||
bfr.Add_mid(src, arg.Href_bgn(), arg.Href_end()); // add href
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (lnke_type == Xoh_lnke_dict_.Type__auto)
|
||||
Xoh_hzip_int_.Encode(1, bfr, arg.Autonumber_id());
|
||||
if (auto_exists)
|
||||
Xoh_hzip_int_.Encode(1, bfr, arg.Auto_id());
|
||||
else if (text_exists) {
|
||||
bfr.Add_mid(src, arg.Capt_bgn(), arg.Capt_end()); // add capt
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx ctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte lnke_type = rdr.Read_byte();
|
||||
int flag = rdr.Read_int_by_base85(1);
|
||||
flag_bldr.Decode(flag);
|
||||
boolean auto_exists = flag_bldr.Get_as_bool(Flag__auto_exists);
|
||||
boolean text_exists = flag_bldr.Get_as_bool(Flag__text_exists);
|
||||
byte anch_cls_type = flag_bldr.Get_as_byte(Flag__anch_cls);
|
||||
|
||||
int href_bgn = rdr.Pos();
|
||||
int href_end = rdr.Find_fwd_lr();
|
||||
int auto_id = -1, capt_bgn = -1, capt_end = -1;
|
||||
if (auto_exists)
|
||||
auto_id = rdr.Read_int_by_base85(1);
|
||||
else if (text_exists) {
|
||||
capt_bgn = rdr.Pos();
|
||||
capt_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
int rv = rdr.Pos();
|
||||
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
bfr.Add(Xoh_lnke_dict_.Html__atr__0).Add(Xoh_lnke_dict_.To_html_class(lnke_type)).Add(Xoh_lnke_dict_.Html__rhs_end);
|
||||
switch (lnke_type) {
|
||||
case Xoh_lnke_dict_.Type__free:
|
||||
bfr.Add_mid(src, href_bgn, href_end).Add(Html_bldr_.Bry__a_rhs);
|
||||
break;
|
||||
case Xoh_lnke_dict_.Type__auto:
|
||||
int lnke_id = rdr.Read_int_by_base85(1);
|
||||
if (lnke_id != 0) // will be 0 when reparented by tidy
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(lnke_id).Add_byte(Byte_ascii.Brack_end).Add(Html_bldr_.Bry__a_rhs);
|
||||
break;
|
||||
case Xoh_lnke_dict_.Type__text:
|
||||
break;
|
||||
}
|
||||
return rdr.Pos();
|
||||
bfr.Add(Xoh_lnke_dict_.Html__atr__0).Add(Xoh_lnke_dict_.To_html_class(anch_cls_type)).Add(Xoh_lnke_dict_.Html__rhs_end);
|
||||
if (auto_exists)
|
||||
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(auto_id).Add_byte(Byte_ascii.Brack_end);
|
||||
else if (text_exists)
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
else
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
bfr.Add(Html_bldr_.Bry__a_rhs);
|
||||
|
||||
return rv;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnke_hzip rv = new Xoh_lnke_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ (1, 1, 2);
|
||||
private static final int // SERIALIZED
|
||||
Flag__auto_exists = 0
|
||||
, Flag__text_exists = 1
|
||||
, Flag__anch_cls = 2 // "free", "autonumber", "text"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -20,17 +20,17 @@ import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_lnke_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Free() {
|
||||
fxt.Test__bicode("~#1http://a.org~", Xoh_lnke_html__hdump__tst.Html__free);
|
||||
fxt.Test__bicode("~#!http://a.org~", Xoh_lnke_html__hdump__tst.Html__free);
|
||||
}
|
||||
@Test public void Auto() {
|
||||
fxt.Test__bicode("~#2http://a.org~\"", Xoh_lnke_html__hdump__tst.Html__auto);
|
||||
fxt.Test__bicode("~#*http://a.org~\"", Xoh_lnke_html__hdump__tst.Html__auto);
|
||||
}
|
||||
@Test public void Text() {
|
||||
fxt.Test__bicode("~#3http://a.org~a</a>", Xoh_lnke_html__hdump__tst.Html__text);
|
||||
fxt.Test__bicode("~#'http://a.org~a~", Xoh_lnke_html__hdump__tst.Html__text);
|
||||
}
|
||||
@Test public void Text__tidy() { // PURPOSE:handle reparenting of html elements by HTML tidy EX:<font color="red">[http://a.org]</font>; DATE:2015-08-25
|
||||
fxt.Test__bicode
|
||||
( "~#2http://a.org~!<font color=\"red\">[123]</font></a>"
|
||||
( "~#&http://a.org~<font color=\"red\">[123]</font>~"
|
||||
, "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external autonumber\"><font color=\"red\">[123]</font></a>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,40 +16,44 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xoh_lnke_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public byte Anch_cls_type() {return anch_cls_type;} private byte anch_cls_type;
|
||||
public int Auto_id() {return auto_id;} private int auto_id;
|
||||
public int Href_bgn() {return href_bgn;} private int href_bgn;
|
||||
public int Href_end() {return href_end;} private int href_end;
|
||||
public int Autonumber_id() {return autonumber_id;} private int autonumber_id;
|
||||
public byte Lnke_type() {return lnke_type;} private byte lnke_type;
|
||||
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
|
||||
public int Capt_end() {return capt_end;} private int capt_end;
|
||||
private void Clear() {
|
||||
this.lnke_type = Byte_ascii.Max_7_bit;
|
||||
this.rng_bgn = this.rng_end = this.href_bgn = href_end = -1;
|
||||
this.autonumber_id = 0;
|
||||
anch_cls_type = Byte_ascii.Max_7_bit;
|
||||
auto_id = rng_bgn = rng_end = href_bgn = href_end = capt_bgn = capt_end = -1;
|
||||
}
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, Html_tag anch) {// <a rel="nofollow" class="external autonumber" href="http://a.org">[1]</a>
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, Html_tag anch_head) {
|
||||
this.Clear();
|
||||
this.rng_bgn = anch.Src_bgn(); this.rng_end = anch.Src_end();
|
||||
Html_atr href_atr = anch.Atrs__get_by_or_fail(Html_atr_.Bry__href);
|
||||
this.rng_bgn = anch_head.Src_bgn();
|
||||
rdr.Init_by_hook("lnke", rng_bgn, rng_bgn);
|
||||
Html_atr href_atr = anch_head.Atrs__get_by_or_fail(Html_atr_.Bry__href); // get href; "EX: href='http://a.org'"
|
||||
this.href_bgn = href_atr.Val_bgn(); this.href_end = href_atr.Val_end();
|
||||
this.lnke_type = anch.Atrs__cls_find_or_fail(Xoh_lnke_dict_.Hash);
|
||||
switch (lnke_type) {
|
||||
case Xoh_lnke_dict_.Type__free:
|
||||
this.rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that free is not recursive; EX: "https://a.org"
|
||||
break;
|
||||
case Xoh_lnke_dict_.Type__text:
|
||||
break;
|
||||
this.anch_cls_type = anch_head.Atrs__cls_find_or_fail(Xoh_lnke_dict_.Hash); // get type by class; EX: "class='external free'"
|
||||
boolean capt_exists = false;
|
||||
switch (anch_cls_type) {
|
||||
case Xoh_lnke_dict_.Type__text: capt_exists = true; break;
|
||||
case Xoh_lnke_dict_.Type__auto:
|
||||
if (tag_rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
|
||||
this.autonumber_id = tag_rdr.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "<a ...>[123]</a>"
|
||||
this.rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that auto is not recursive; EX: "[https://a.org]"
|
||||
}
|
||||
if (tag_rdr.Read_and_move(Byte_ascii.Brack_bgn)) // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
|
||||
this.auto_id = tag_rdr.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "<a ...>[123]</a>"
|
||||
else
|
||||
capt_exists = true;
|
||||
break;
|
||||
}
|
||||
if (capt_exists) this.capt_bgn = anch_head.Src_end();
|
||||
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // find '</a>'
|
||||
if (capt_exists) this.capt_end = anch_tail.Src_bgn();
|
||||
this.rng_end = anch_tail.Src_end();
|
||||
hdoc_wkr.On_lnke(this);
|
||||
return rng_end;
|
||||
}
|
||||
public static final byte[] Bry__rel__nofollow = Bry_.new_a7("nofollow");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.core.brys.args.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.bfr_args.*;
|
||||
public class Xoh_lnke_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
private final Bfr_arg[] arg_ary;
|
||||
private final Bfr_arg__indent indent = new Bfr_arg__indent();
|
||||
private final Bfr_arg__html_atr
|
||||
anch_href = new Bfr_arg__html_atr(Html_atr_.Bry__href)
|
||||
, anch_rel = new Bfr_arg__html_atr(Html_atr_.Bry__rel)
|
||||
, anch_cls = new Bfr_arg__html_atr(Html_atr_.Bry__class)
|
||||
;
|
||||
private final Bfr_arg__wrapper anch_capt = new Bfr_arg__wrapper();
|
||||
public Xoh_lnke_wtr() {
|
||||
arg_ary = new Bfr_arg[] {indent, anch_href, anch_rel, anch_cls, anch_capt};
|
||||
}
|
||||
public Xoh_lnke_wtr Indent_(int v) {indent.Set(v); return this;}
|
||||
public Xoh_lnke_wtr Anch_href_(byte[] src, int bgn, int end) {anch_href.Set_by_mid(src, bgn, end); return this;}
|
||||
public Xoh_lnke_wtr Anch_rel_y_() {anch_rel.Set_by_bry(Xoh_lnke_dict_.Html__rel__nofollow); return this;}
|
||||
public Xoh_lnke_wtr Anch_cls_(byte[]... ary) {anch_cls.Set_by_ary(ary); return this;}
|
||||
public Xoh_lnke_wtr Anch_capt_(Bfr_arg v) {anch_capt.Set(v); return this;}
|
||||
public Xoh_lnke_wtr Clear() {
|
||||
for (Bfr_arg arg : arg_ary)
|
||||
arg.Bfr_arg__clear();
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, (Object[])arg_ary);
|
||||
}
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_
|
||||
( "~{indent}<a~{anch_href}~{anch_rel}~{anch_cls}>~{anch_capt}</a>"
|
||||
, "indent", "anch_href", "anch_rel", "anch_cls", "anch_capt");
|
||||
}
|
||||
@@ -17,13 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
public class Xoh_lnki_dict_ {
|
||||
public static final byte // SERIALIZED
|
||||
Capt__same = Xoh_ttl_matcher.Tid__same // EX: [[A]]
|
||||
, Capt__diff = Xoh_ttl_matcher.Tid__diff // EX: [[A|b]]
|
||||
, Capt__trail = Xoh_ttl_matcher.Tid__tail // EX: [[A|b]]
|
||||
, Capt__head = Xoh_ttl_matcher.Tid__head // EX: [[A_(b)|A]]
|
||||
;
|
||||
public static void Ns_encode(Bry_bfr bfr, int ns_id) {
|
||||
gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Encode(1, bfr, ns_id + 2);
|
||||
}
|
||||
|
||||
@@ -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.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_lnki_html__basic__tst {
|
||||
@After public void term() {fxt.Init_para_n_(); fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Test public void Ns__title() { // PURPOSE: title should have full ns; "title='Help talk:A'" not "title='A'" DATE:2015-11-16
|
||||
fxt.Wtr_cfg().Lnki__title_(Bool_.Y);
|
||||
fxt.Test__parse__wtxt_to_html("[[Help talk:A b]]" , "<a href='/wiki/Help_talk:A_b' title='Help talk:A b'>Help talk:A b</a>");
|
||||
fxt.Wtr_cfg().Lnki__title_(Bool_.N);
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,10 @@ import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
|
||||
public class Xoh_lnki_html__hdump__tst {
|
||||
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
||||
public static final String
|
||||
Html__same = "<a href='/wiki/A' id='xowa_lnki_2' title='A'>A</a>"
|
||||
, Html__diff = "<a href='/wiki/A' id='xowa_lnki_2' title='A'>b</a>"
|
||||
, Html__trail = "<a href='/wiki/A' id='xowa_lnki_2' title='A'>Ab</a>"
|
||||
, Html__xwiki = "<a href='/site/en.wiktionary.org/wiki/A' id='xowa_lnki_2' title='A'>wikt:A</a>"
|
||||
Html__same = "<a href='/wiki/A' id='xolnki_2' title='A'>A</a>"
|
||||
, Html__diff = "<a href='/wiki/A' id='xolnki_2' title='A'>b</a>"
|
||||
, Html__trail = "<a href='/wiki/A' id='xolnki_2' title='A'>Ab</a>"
|
||||
, Html__xwiki = "<a href='/site/en.wiktionary.org/wiki/a' id='xolnki_2' title='a'>wikt:a</a>"
|
||||
;
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Same() {fxt.Test__html("[[A]]" , Html__same);}
|
||||
@@ -31,6 +31,6 @@ public class Xoh_lnki_html__hdump__tst {
|
||||
@Test public void Trail() {fxt.Test__html("[[A]]b" , Html__trail);}
|
||||
@Test public void Xwiki() {
|
||||
fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org");
|
||||
fxt.Test__html("[[wikt:A]]", Html__xwiki);
|
||||
fxt.Test__html("[[wikt:a]]", Html__xwiki);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,55 +21,37 @@ import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.lnkis.anch
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private final int[] flag_ary;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ ( 1, 2, 3);
|
||||
public String Key() {return Xoh_hzip_dict_.Key__lnki;}
|
||||
public Xoh_lnki_hzip() {this.flag_ary = flag_bldr.Val_ary();}
|
||||
public Xoh_lnki_hzip Encode(Bry_bfr bfr, Xoh_hdoc_ctx hctx, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnki_parser arg) {
|
||||
byte capt_type = arg.Capt_type();
|
||||
Xoh_anch_href_parser anch_href_parser = arg.Anch_href_parser();
|
||||
Xoa_ttl page_ttl = anch_href_parser.Page_ttl();
|
||||
int page_ns_id = page_ttl.Ns().Id();
|
||||
boolean page_ns_id_is_main = page_ns_id == Xow_ns_.Tid__main;
|
||||
byte text_type = arg.Text_type();
|
||||
Xoh_anch_href_parser anch_href_parser = arg.Href_parser();
|
||||
int page_ns_id = anch_href_parser.Page_ns_id();
|
||||
boolean page_ns_id_is_not_main = page_ns_id != Xow_ns_.Tid__main;
|
||||
int href_type = anch_href_parser.Tid();
|
||||
flag_ary[ 0] = page_ns_id_is_main ? 1 : 0;
|
||||
flag_ary[ 1] = href_type;
|
||||
flag_ary[ 2] = capt_type;
|
||||
flag_bldr.Set(Flag__ns_is_not_main , page_ns_id_is_not_main);
|
||||
flag_bldr.Set(Flag__href_type , href_type);
|
||||
flag_bldr.Set(Flag__text_type , text_type);
|
||||
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__lnki);
|
||||
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
|
||||
if (!page_ns_id_is_main)
|
||||
if (page_ns_id_is_not_main)
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, page_ns_id);
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
bfr.Add_mid(src, anch_href_parser.Site_bgn(), anch_href_parser.Site_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
}
|
||||
switch (capt_type) {
|
||||
case Xoh_lnki_dict_.Capt__same:
|
||||
if (href_type == Xoh_anch_href_parser.Tid__site)
|
||||
bfr.Add_mid(src, anch_href_parser.Site_bgn(), anch_href_parser.Site_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
switch (text_type) {
|
||||
case Xoh_anch_capt_parser.Tid__href:
|
||||
case Xoh_anch_capt_parser.Tid__href_pipe:
|
||||
stat_itm.Lnki_text_n_add();
|
||||
byte[] ttl_bry = page_ns_id_is_main
|
||||
? arg.Capt_bry() // main ns should write html_text; handles [[a]] with html of '<a href="A">a</a>'
|
||||
: page_ttl.Page_db(); // non-main ns should write page_db only; EX: "Template:A" should write "A" since "Template" will be inferred by ns_id
|
||||
bfr.Add(ttl_bry).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add_mid(arg.Href_bry(), arg.Href_bgn(), arg.Href_end());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__diff:
|
||||
case Xoh_anch_capt_parser.Tid__capt:
|
||||
case Xoh_anch_capt_parser.Tid__href_trail:
|
||||
case Xoh_anch_capt_parser.Tid__capt_short:
|
||||
stat_itm.Lnki_text_y_add();
|
||||
bfr.Add(arg.Anch_href_parser().Page_bry());
|
||||
bfr.Add_mid(arg.Href_bry(), arg.Href_bgn(), arg.Href_end());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add(arg.Capt_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__trail:
|
||||
bfr.Add(arg.Capt_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add(arg.Trail_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__head:
|
||||
bfr.Add(arg.Capt_bry());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
bfr.Add(arg.Trail_bry());
|
||||
bfr.Add_mid(arg.Capt_bry(), arg.Capt_bgn(), arg.Capt_end());
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
break;
|
||||
}
|
||||
@@ -78,93 +60,110 @@ public class Xoh_lnki_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public int Decode(Bry_bfr bfr, boolean write_to_bfr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
int flag = rdr.Read_int_by_base85(1);
|
||||
flag_bldr.Decode(flag);
|
||||
boolean page_ns_id_is_main = flag_bldr.Get_as_bool(0);
|
||||
byte href_type = flag_bldr.Get_as_byte(1);
|
||||
byte capt_type = flag_bldr.Get_as_byte(2);
|
||||
boolean page_ns_id_is_not_main = flag_bldr.Get_as_bool(Flag__ns_is_not_main);
|
||||
byte href_type = flag_bldr.Get_as_byte(Flag__href_type);
|
||||
byte text_type = flag_bldr.Get_as_byte(Flag__text_type);
|
||||
|
||||
int ns_id = Xow_ns_.Tid__main;
|
||||
if (!page_ns_id_is_main)
|
||||
ns_id = Xoh_lnki_dict_.Ns_decode(rdr);
|
||||
int ns_id = page_ns_id_is_not_main ? Xoh_lnki_dict_.Ns_decode(rdr) : Xow_ns_.Tid__main;
|
||||
int site_bgn = -1, site_end = -1;
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr();
|
||||
if (href_type == Xoh_anch_href_parser.Tid__site) {
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
int href_bgn = rdr.Pos();
|
||||
int href_end = rdr.Find_fwd_lr();
|
||||
int capt_bgn = -1, capt_end = -1;
|
||||
switch (text_type) {
|
||||
case Xoh_anch_capt_parser.Tid__capt:
|
||||
case Xoh_anch_capt_parser.Tid__capt_short:
|
||||
case Xoh_anch_capt_parser.Tid__href_trail:
|
||||
capt_bgn = rdr.Pos();
|
||||
capt_end = rdr.Find_fwd_lr();
|
||||
break;
|
||||
}
|
||||
int page_bgn = rdr.Pos();
|
||||
int page_end = rdr.Find_fwd_lr();
|
||||
int capt_bgn = -1, capt_end = -1;
|
||||
if (capt_type != Xoh_lnki_dict_.Capt__same) {
|
||||
capt_bgn = rdr.Pos();
|
||||
capt_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
|
||||
byte[] page_bry = null;
|
||||
if (capt_type == Xoh_lnki_dict_.Capt__head)
|
||||
page_bry = Bry_.Add(Bry_.Mid(src, page_bgn, page_end), Bry_.Mid(src, capt_bgn, capt_end));
|
||||
byte[] href_bry = null;
|
||||
if (text_type == Xoh_anch_capt_parser.Tid__capt_short)
|
||||
href_bry = Bry_.Add(Bry_.Mid(src, href_bgn, href_end), Bry_.Mid(src, capt_bgn, capt_end));
|
||||
else
|
||||
page_bry = Bry_.Mid(src, page_bgn, page_end);
|
||||
byte[] title_bry = null, href_bry = null;
|
||||
if (href_type == Xoh_anch_href_parser.Tid__anch)
|
||||
href_bry = page_bry;
|
||||
else {
|
||||
Xow_ns ns = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(ns_id);
|
||||
Xoa_ttl ttl = hctx.Wiki__ttl_parser().Ttl_parse(ns.Id(), page_bry); if (ttl == null) rdr.Fail("invalid ttl", String_.Empty, String_.new_u8(page_bry)); // TODO: parse title based on site
|
||||
href_bry = ttl.Full_db();
|
||||
title_bry = ttl.Full_txt();
|
||||
if (href_type == Xoh_anch_href_parser.Tid__site) {
|
||||
href_bry = ttl.Page_db(); // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
|
||||
href_bry = Bry_.Mid(src, href_bgn, href_end);
|
||||
byte[] title_bry = null;
|
||||
Xoa_ttl ttl = null;
|
||||
if (href_type != Xoh_anch_href_parser.Tid__anch) {
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
Xow_ttl_parser ttl_parser = hctx.App().Wiki_mgri().Get_by_key_or_make_init_n(Bry_.Mid(src, site_bgn, site_end));
|
||||
ttl = ttl_parser.Ttl_parse(ns_id, href_bry);
|
||||
href_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href_qarg.Encode(ttl.Full_db());
|
||||
title_bry = ttl.Full_txt();
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__wiki:
|
||||
ttl = hctx.Wiki__ttl_parser().Ttl_parse(ns_id, href_bry); if (ttl == null) rdr.Fail("invalid ttl", String_.Empty, String_.new_u8(href_bry));
|
||||
href_bry = ttl.Full_db_w_anch();
|
||||
href_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(href_bry); // encode for href; EX: "/wiki/A's" -> "/wiki/A&27s"
|
||||
title_bry = ttl.Full_txt();
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__inet:
|
||||
title_bry = href_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href_qarg.Encode(href_bry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// gen html
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
|
||||
switch (href_type) {
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
bfr.Add(Xoh_href_.Bry__wiki).Add_mid(src, site_bgn, site_end);
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__anch:
|
||||
bfr.Add_byte(Byte_ascii.Hash); // "#"
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__site:
|
||||
bfr.Add(Xoh_href_.Bry__site).Add_mid(src, site_bgn, site_end);
|
||||
bfr.Add(Xoh_href_.Bry__wiki);
|
||||
break;
|
||||
case Xoh_anch_href_parser.Tid__wiki:
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
|
||||
bfr.Add(Xoh_href_.Bry__wiki);
|
||||
break;
|
||||
}
|
||||
bfr.Add(href_bry);
|
||||
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(hctx.Lnki__uid__nxt());
|
||||
bfr.Add(Html_bldr_.Bry__id__nth).Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(hctx.Lnki__uid__nxt());
|
||||
if (href_type != Xoh_anch_href_parser.Tid__anch) {
|
||||
bfr.Add_str_a7("\" title=\"");
|
||||
bfr.Add(Html_utl.Escape_html_as_bry(title_bry));
|
||||
bfr.Add(Html_bldr_.Bry__title__nth);
|
||||
Html_utl.Escape_html_to_bfr(bfr, title_bry, 0, title_bry.length, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y, Bool_.N);
|
||||
}
|
||||
bfr.Add_str_a7("\">");
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_head_w_quote);
|
||||
if ( href_type == Xoh_anch_href_parser.Tid__anch
|
||||
&& capt_type != Xoh_lnki_dict_.Capt__diff )
|
||||
&& text_type != Xoh_anch_capt_parser.Tid__capt )
|
||||
bfr.Add_byte(Byte_ascii.Hash);
|
||||
switch (capt_type) {
|
||||
case Xoh_lnki_dict_.Capt__same:
|
||||
switch (text_type) {
|
||||
case Xoh_anch_capt_parser.Tid__href:
|
||||
if (ns_id == Xow_ns_.Tid__main)
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
else
|
||||
bfr.Add(title_bry);
|
||||
bfr.Add(ttl.Full_txt());
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__diff:
|
||||
case Xoh_anch_capt_parser.Tid__href_pipe:
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
break;
|
||||
case Xoh_anch_capt_parser.Tid__capt:
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__trail:
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
case Xoh_anch_capt_parser.Tid__href_trail:
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
break;
|
||||
case Xoh_lnki_dict_.Capt__head:
|
||||
bfr.Add_mid(src, page_bgn, page_end);
|
||||
case Xoh_anch_capt_parser.Tid__capt_short:
|
||||
bfr.Add_mid(src, href_bgn, href_end);
|
||||
break;
|
||||
}
|
||||
bfr.Add_str_a7("</a>");
|
||||
bfr.Add(Html_bldr_.Bry__a_rhs);
|
||||
return rdr.Pos();
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_lnki_hzip rv = new Xoh_lnki_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ (1, 2, 3);
|
||||
private static final int // SERIALIZED
|
||||
Flag__ns_is_not_main = 0
|
||||
, Flag__href_type = 1 // "wiki", "site", "anch", "inet"
|
||||
, Flag__text_type = 2 // "href", "capt", "href_trail", "capt_short", "href_pipe"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -19,47 +19,95 @@ package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; impo
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_lnki_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Page__basic() {
|
||||
fxt.Test__bicode("~$IA~", Xoh_lnki_html__hdump__tst.Html__same);
|
||||
@Test public void Href__basic() {
|
||||
fxt.Test__bicode("~$!A~", Xoh_lnki_html__hdump__tst.Html__same);
|
||||
}
|
||||
@Test public void Page__alt_case() {
|
||||
fxt.Test__bicode("~$Ia~", "<a href='/wiki/A' id='xowa_lnki_2' title='A'>a</a>");
|
||||
@Test public void Href__case_diff() {
|
||||
fxt.Test__bicode("~$!a~", "<a href='/wiki/A' id='xolnki_2' title='A'>a</a>");
|
||||
}
|
||||
@Test public void Page__ns() {
|
||||
fxt.Test__bicode("~$)-A~", "<a href='/wiki/Template:A' id='xowa_lnki_2' title='Template:A'>Template:A</a>");
|
||||
@Test public void Href__url_encoded() {
|
||||
String html = "<a href=\"/wiki/A%27s\" id=\"xolnki_2\" title=\"A's\">A's</a>";
|
||||
fxt.Test__bicode_raw("~$!A's~", html, html);
|
||||
}
|
||||
@Test public void Anch__basic() {
|
||||
fxt.Test__bicode("$Ya", "<a href='#a' id='xowa_lnki_2'>#a</a>");
|
||||
@Test public void Ns__same() { // EX: [[Help:A]]
|
||||
fxt.Test__bicode("~$A/A~", "<a href='/wiki/Help:A' id='xolnki_2' title='Help:A'>Help:A</a>");
|
||||
}
|
||||
@Test public void Capt__basic() {
|
||||
fxt.Test__bicode("~$JA~b~", Xoh_lnki_html__hdump__tst.Html__diff);
|
||||
@Test public void Ns__diff() { // EX: [[Help:A_b|c]]
|
||||
fxt.Test__bicode("~$B/A_b~c~", "<a href='/wiki/Help:A_b' id='xolnki_2' title='Help:A b'>c</a>");
|
||||
}
|
||||
@Test public void Ns__space() { // EX: [[Help talk:A b]]
|
||||
fxt.Test__bicode("~$A0A b~", "<a href='/wiki/Help_talk:A_b' id='xolnki_2' title='Help talk:A b'>Help talk:A b</a>");
|
||||
}
|
||||
@Test public void Ns__under() { // EX: [[Help_talk:A_b]]; rare; just make sure codec can handle it;
|
||||
fxt.Test__bicode("~$B0A_b~Help_talk:A_b~", "<a href='/wiki/Help_talk:A_b' id='xolnki_2' title='Help talk:A b'>Help_talk:A_b</a>");
|
||||
}
|
||||
@Test public void Ns__pipe() { // EX: [[Help:A|]]
|
||||
fxt.Test__bicode("~$E/A~", "<a href='/wiki/Help:A' id='xolnki_2' title='Help:A'>A</a>");
|
||||
}
|
||||
@Test public void Ns__pipe_w_words() { // EX: [[Help:A b|]]
|
||||
fxt.Test__bicode("~$E/A b~", "<a href='/wiki/Help:A_b' id='xolnki_2' title='Help:A b'>A b</a>");
|
||||
}
|
||||
@Test public void Anch__same() {
|
||||
fxt.Test__bicode("~$2a~#a~", "<a href='#a' id='xolnki_2'>#a</a>");
|
||||
}
|
||||
@Test public void Anch__diff() {
|
||||
fxt.Test__bicode("~$2a~b~", "<a href='#a' id='xolnki_2'>b</a>");
|
||||
}
|
||||
@Test public void Anch__diff__starts_w_same() {
|
||||
fxt.Test__bicode("~$2a~a~", "<a href='#a' id='xolnki_2'>a</a>");
|
||||
}
|
||||
@Test public void Capt__basic() { // EX: [[A|b]]
|
||||
fxt.Test__bicode("~$\"A~b~", Xoh_lnki_html__hdump__tst.Html__diff);
|
||||
}
|
||||
@Test public void Capt__page_w_anch() { // Ex: [[A#b|c]]
|
||||
fxt.Test__bicode("~$\"A#b~b~", "<a href='/wiki/A#b' id='xolnki_2' title='A'>b</a>");
|
||||
}
|
||||
@Test public void Capt__nest() {
|
||||
fxt.Test__bicode
|
||||
( "~$JA~<a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D~"
|
||||
, "<a href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D</a>"
|
||||
( "~$\"A~<a href=\"/wiki/C\" id=\"xolnki_3\" title=\"C\">C1</a>D~"
|
||||
, "<a href=\"/wiki/A\" id=\"xolnki_2\" title=\"A\"><a href=\"/wiki/C\" id=\"xolnki_3\" title=\"C\">C1</a>D</a>"
|
||||
);
|
||||
// old: probably broken; fxt.Test__bicode("~$1!#A~~$1!#C~C1</a>D</a>", "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a data-xotype='lnki1' href=\"/wiki/C\" id=\"xowa_lnki_2\" title=\"C\">C1</a>D</a>");
|
||||
}
|
||||
@Test public void Tail__basic() {
|
||||
fxt.Test__bicode("~$KA~b~", Xoh_lnki_html__hdump__tst.Html__trail);
|
||||
@Test public void Capt__reparent() { // PURPOSE: PAGE:en.w:Abyssal_plain; DATE:2015-06-02; DELETE: not needed in new dump format;
|
||||
fxt.Test__bicode
|
||||
( "$\"A<font color=\"white\">A1</font>"
|
||||
, "<a href=\"/wiki/A\" id=\"xolnki_2\" title=\"A\"><font color='white'>A1</font></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Head__basic() {
|
||||
fxt.Test__bicode("~$LA~b~", "<a href='/wiki/Ab' id='xowa_lnki_2' title='Ab'>A</a>");
|
||||
@Test public void Capt__xwiki() {
|
||||
Xow_wiki wiki = fxt.Prep_create_wiki("wikt", "en.wiktionary.org");
|
||||
wiki.Ns_mgr().Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all);
|
||||
fxt.Test__bicode("$*en.wiktionary.orgawikt:a", Xoh_lnki_html__hdump__tst.Html__xwiki);
|
||||
}
|
||||
@Test public void Head__case() {
|
||||
fxt.Test__bicode("~$La~b~", "<a href='/wiki/Ab' id='xowa_lnki_2' title='Ab'>a</a>");
|
||||
@Test public void Capt__xwiki__qarg() {
|
||||
Xow_wiki wiki = fxt.Prep_create_wiki("wikt", "en.wiktionary.org");
|
||||
wiki.Ns_mgr().Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all);
|
||||
fxt.Test__bicode("$*en.wiktionary.orga?action=editwikt:a?action=edit", "<a href='/site/en.wiktionary.org/wiki/a?action=edit' id='xolnki_2' title='a?action=edit'>wikt:a?action=edit</a>");
|
||||
}
|
||||
@Test public void Capt__xwiki__encode() {
|
||||
Xow_wiki wiki = fxt.Prep_create_wiki("wikt", "en.wiktionary.org");
|
||||
wiki.Ns_mgr().Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all);
|
||||
fxt.Test__bicode("$)en.wiktionary.orgeorðe", "<a href='/site/en.wiktionary.org/wiki/eor%C3%B0e' id='xolnki_2' title='eorðe'>eorðe</a>");
|
||||
}
|
||||
@Test public void Trail__basic() {
|
||||
fxt.Test__bicode("~$#A~b~", Xoh_lnki_html__hdump__tst.Html__trail);
|
||||
}
|
||||
@Test public void Short__basic() {
|
||||
fxt.Test__bicode("~$$A~b~", "<a href='/wiki/Ab' id='xolnki_2' title='Ab'>A</a>");
|
||||
}
|
||||
@Test public void Short__case() {
|
||||
fxt.Test__bicode("~$$a~b~", "<a href='/wiki/Ab' id='xolnki_2' title='Ab'>a</a>");
|
||||
}
|
||||
@Test public void Site__main_page() {
|
||||
fxt.Test__bicode("~$)en.wikipedia.org~Main Page~"
|
||||
, "<a href='/site/en.wikipedia.org/wiki/' id='xolnki_2' title='Main Page'>Main Page</a>"
|
||||
, "<a href='/site/en.wikipedia.org/wiki/Main_Page' id='xolnki_2' title='Main Page'>Main Page</a>"
|
||||
);
|
||||
}
|
||||
@Test public void Site__qarg() {
|
||||
fxt.Test__bicode("~$*en.wikipedia.org~A?b=c~d~", "<a href='/site/en.wikipedia.org/wiki/A?b=c' id='xolnki_2' title='A?b=c'>d</a>");
|
||||
}
|
||||
@Test public void Inet__file() {
|
||||
fxt.Test__bicode("~$:file:///C://A.png~b~", "<a href='file:///C://A.png' id='xolnki_2' title='file:///C://A.png'>b</a>");
|
||||
}
|
||||
// @Test public void Capt__site__xwiki() {
|
||||
// fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org");
|
||||
// fxt.Test__bicode("~$2!A~wikt:A~", Xoh_lnki_html__hdump__tst.Html__xwiki);
|
||||
// }
|
||||
// @Test public void Lnki__apos() {
|
||||
// fxt.Test__bicode("~$0+#A'b~", "<a data-xotype='lnki0' href=\"/wiki/Template:A'b\" id=\"xowa_lnki_2\" title=\"Template:A'b\">Template:A'b</a>");
|
||||
// }
|
||||
// @Test public void Caption__reparent() { // PURPOSE: PAGE:en.w:Abyssal_plain; DATE:2015-06-02
|
||||
// String hzip = Xoh_hzip_fxt.Escape("~$1!#A~<font color='white'>A1</font></a>");
|
||||
// fxt.Test__encode(hzip, "<a data-xotype='lnki0' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><font color='white'>A1</font></a>");
|
||||
// fxt.Test__decode(hzip, "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><font color='white'>A1</font></a>");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -18,42 +18,89 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_lnki_parser {
|
||||
private final Xoh_ttl_matcher ttl_matcher = new Xoh_ttl_matcher();
|
||||
private final Xoh_anch_capt_parser capt_parser = new Xoh_anch_capt_parser();
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public byte Capt_type() {return capt_type;} private byte capt_type;
|
||||
public byte[] Capt_bry() {return capt_bry;} private byte[] capt_bry;
|
||||
public byte[] Trail_bry() {return trail_bry;} private byte[] trail_bry;
|
||||
public Xoh_anch_href_parser Anch_href_parser() {return anch_href_parser;} private final Xoh_anch_href_parser anch_href_parser = new Xoh_anch_href_parser();
|
||||
public int Parse(Xoh_hdoc_wkr wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_tag, Xow_ttl_parser ttl_parser) {// <a href="/wiki/A" title="A">b</a>
|
||||
this.rng_bgn = anch_tag.Src_bgn(); this.rng_end = anch_tag.Src_end();
|
||||
rdr.Init_by_page(Bry_.Empty, src, src.length);
|
||||
anch_href_parser.Parse(rdr, hctx.Wiki__ttl_parser(), anch_tag); // href='/wiki/A'
|
||||
Html_tag lnki_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
int capt_bgn = rng_end; int capt_end = lnki_tail.Src_bgn(); // get capt between "<a>" and "</a>
|
||||
if ( anch_href_parser.Tid() == Xoh_anch_href_parser.Tid__anch
|
||||
&& src[capt_bgn] == Byte_ascii.Hash)
|
||||
++capt_bgn;
|
||||
this.rng_end = lnki_tail.Src_end();
|
||||
this.capt_type = ttl_matcher.Match(rdr, ttl_parser, src, anch_href_parser.Page_bgn(), anch_href_parser.Page_end(), src, capt_bgn, capt_end);
|
||||
this.capt_bry = trail_bry = null;
|
||||
switch (capt_type) {
|
||||
case Xoh_ttl_matcher.Tid__same:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public byte Text_type() {return text_type;} private byte text_type;
|
||||
public byte[] Href_bry() {return href_bry;} private byte[] href_bry;
|
||||
public int Href_bgn() {return href_bgn;} private int href_bgn;
|
||||
public int Href_end() {return href_end;} private int href_end;
|
||||
public byte[] Capt_bry() {return capt_bry;} private byte[] capt_bry;
|
||||
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
|
||||
public int Capt_end() {return capt_end;} private int capt_end;
|
||||
public Xoh_anch_href_parser Href_parser() {return href_parser;} private final Xoh_anch_href_parser href_parser = new Xoh_anch_href_parser();
|
||||
public int Parse(Xoh_hdoc_wkr wkr, Xoh_hdoc_ctx hctx, byte[] src, Html_tag_rdr tag_rdr, Html_tag anch_head, Xow_ttl_parser ttl_parser) {// <a href="/wiki/A" title="A">b</a>
|
||||
this.rng_bgn = anch_head.Src_bgn();
|
||||
rdr.Init_by_sub(tag_rdr.Rdr(), "lnki", rng_bgn, src.length);
|
||||
href_parser.Parse(rdr, hctx.App(), hctx.Wiki__ttl_parser(), anch_head); // href='/wiki/A'
|
||||
// get href
|
||||
this.href_bry = src;
|
||||
this.href_bgn = href_parser.Page_bgn(); this.href_end = href_parser.Page_end();
|
||||
Xoa_ttl href_ttl = null; Xow_ns href_ns = null;
|
||||
int href_ns_id = Xow_ns_.Tid__main; boolean href_cs_tid_1st = true;
|
||||
switch (href_parser.Tid()) {
|
||||
case Xoh_anch_href_parser.Tid__anch:
|
||||
case Xoh_anch_href_parser.Tid__inet:
|
||||
break;
|
||||
case Xoh_ttl_matcher.Tid__diff:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
default:
|
||||
href_ttl = href_parser.Page_ttl();
|
||||
href_ns = href_ttl.Ns();
|
||||
href_ns_id = href_ns.Id();
|
||||
href_cs_tid_1st = href_ttl.Ns().Case_match() == Xow_ns_case_.Tid__1st;
|
||||
this.href_bry = href_parser.Page_bry();
|
||||
this.href_bgn = 0;
|
||||
this.href_end = href_bry.length;
|
||||
break;
|
||||
case Xoh_ttl_matcher.Tid__tail:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, ttl_matcher.Trail_bgn());
|
||||
this.trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), capt_end);
|
||||
}
|
||||
// get capt
|
||||
this.capt_bry = src;
|
||||
this.capt_bgn = anch_head.Src_end(); // capt starts after <a>
|
||||
Html_tag anch_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
|
||||
this.capt_end = anch_tail.Src_bgn(); // get capt between "<a>" and "</a>
|
||||
this.rng_end = anch_tail.Src_end();
|
||||
boolean capt_bgn_has_ns = true;
|
||||
if (href_ns_id != Xow_ns_.Tid__main) { // not main; try to remove template name;
|
||||
int colon_pos = Bry_find_.Find_fwd(href_bry, Byte_ascii.Colon, href_bgn, href_end);
|
||||
byte[] ns_name = Xoa_ttl.Replace_unders(Bry_.Mid(href_bry, href_bgn, colon_pos + 1)); // EX: 11="Template talk:"
|
||||
int ns_name_len = ns_name.length;
|
||||
int ns_name_end = capt_bgn + ns_name_len;
|
||||
href_bgn += ns_name_len; // skip ns_name for href; EX: "Help:A" -> "A"; "Help" will be saved as encoded num
|
||||
if (Bry_.Match(src, capt_bgn, ns_name_end, ns_name, 0, ns_name_len)) // href matches capt; EX: [[Help:A]] -> <a href='/wiki/Help:A'>Help:A</a>
|
||||
capt_bgn = ns_name_end;
|
||||
else
|
||||
capt_bgn_has_ns = false;
|
||||
}
|
||||
if (href_parser.Tid() == Xoh_anch_href_parser.Tid__anch)
|
||||
this.text_type = Xoh_anch_capt_parser.Tid__capt;
|
||||
else
|
||||
this.text_type = capt_parser.Parse(rdr, capt_bgn_has_ns, href_cs_tid_1st, href_bry, href_bgn, href_end, src, capt_bgn, capt_end);
|
||||
int split_pos = capt_parser.Split_pos();
|
||||
switch (text_type) {
|
||||
case Xoh_anch_capt_parser.Tid__capt: // nothing to do; href / capt already set above
|
||||
break;
|
||||
case Xoh_ttl_matcher.Tid__head:
|
||||
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
this.trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), anch_href_parser.Page_end());
|
||||
case Xoh_anch_capt_parser.Tid__href: // redefine href to capt since both href and capt are same except for case-sensitivity / underscores; EX: [[a]], [[A b]]
|
||||
case Xoh_anch_capt_parser.Tid__href_pipe:
|
||||
this.href_bry = src;
|
||||
this.href_bgn = capt_bgn;
|
||||
this.href_end = capt_end;
|
||||
break;
|
||||
case Xoh_anch_capt_parser.Tid__href_trail:
|
||||
this.href_bry = src;
|
||||
this.href_bgn = capt_bgn;
|
||||
this.href_end = split_pos;
|
||||
this.capt_bgn = split_pos;
|
||||
break;
|
||||
case Xoh_anch_capt_parser.Tid__capt_short:
|
||||
int tmp_capt_bgn = capt_bgn, tmp_capt_end = capt_end;
|
||||
this.capt_bry = href_bry;
|
||||
this.capt_bgn = split_pos;
|
||||
this.capt_end = href_end;
|
||||
this.href_bry = src;
|
||||
this.href_bgn = tmp_capt_bgn;
|
||||
this.href_end = tmp_capt_end;
|
||||
break;
|
||||
}
|
||||
wkr.On_lnki(this);
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_ttl_matcher {
|
||||
public int Trail_bgn() {return midpoint_pos;} private int midpoint_pos;
|
||||
public byte Match(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, byte[] page_bry, int page_bgn, int page_end, byte[] capt_bry, int capt_bgn, int capt_end) {
|
||||
midpoint_pos = -1;
|
||||
int page_len = page_end - page_bgn; if (page_len == 0) page_bry = Xoa_page_.Main_page_bry; // NOTE: href="/site/en.wikipedia.org/wiki/" can be null
|
||||
Xoa_ttl page = ttl_parser.Ttl_parse(page_bry, page_bgn, page_end); if (page == null) owner_rdr.Fail("invalid page", "page", page_bry);
|
||||
Xow_ns ns = page.Ns();
|
||||
if (ns.Id() != Xow_ns_.Tid__main) {
|
||||
byte[] ns_name_txt = ns.Name_ui_w_colon(); // EX: 11="Template talk:"
|
||||
int ns_name_txt_len = ns_name_txt.length;
|
||||
int ns_name_txt_end = capt_bgn + ns_name_txt_len;
|
||||
if (Bry_.Match(capt_bry, capt_bgn, ns_name_txt_end, ns_name_txt, 0, ns_name_txt_len)) {
|
||||
capt_bgn = ns_name_txt_end;
|
||||
page_bgn += ns_name_txt_len;
|
||||
page_len = page_end - page_bgn;
|
||||
}
|
||||
else
|
||||
return Tid__diff;
|
||||
}
|
||||
int capt_len = capt_end - capt_bgn;
|
||||
for (int i = 0; i < capt_len; ++i) {
|
||||
byte capt_byte = capt_bry[i + capt_bgn];
|
||||
if (i == page_len) {
|
||||
midpoint_pos = i + capt_bgn;
|
||||
return Tid__tail;
|
||||
}
|
||||
byte page_byte = page_bry[i + page_bgn];
|
||||
if (page_byte == capt_byte) continue;
|
||||
if ( i == 0
|
||||
&& ns.Case_match() == Xow_ns_case_.Tid__1st
|
||||
&& capt_byte >= Byte_ascii.Ltr_a && capt_byte <= Byte_ascii.Ltr_z
|
||||
&& (capt_byte - page_byte) == 32
|
||||
)
|
||||
continue;
|
||||
if ( capt_byte == Byte_ascii.Space
|
||||
&& page_byte == Byte_ascii.Underline
|
||||
)
|
||||
continue;
|
||||
return Tid__diff;
|
||||
}
|
||||
if (capt_len == page_len)
|
||||
return Tid__same;
|
||||
else {
|
||||
midpoint_pos = capt_len + page_bgn;
|
||||
return Tid__head;
|
||||
}
|
||||
}
|
||||
public static final byte
|
||||
Tid__same = 0 // "A" , "A" , "A"
|
||||
, Tid__diff = 1 // "A" , "B" , "A|B"
|
||||
, Tid__tail = 2 // "A" , "As" , "A|s"
|
||||
, Tid__head = 3 // "A_(b)" , "A" , "A|_(b)"
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_anch_capt_parser {
|
||||
public int Split_pos() {return split_pos;} private int split_pos;
|
||||
public byte Parse(Bry_rdr owner_rdr, boolean capt_bgn_has_ns, boolean cs_tid_1st, byte[] href_bry, int href_bgn, int href_end, byte[] capt_bry, int capt_bgn, int capt_end) {
|
||||
this.split_pos = -1;
|
||||
int href_len = href_end - href_bgn;
|
||||
int capt_len = capt_end - capt_bgn;
|
||||
for (int i = 0; i < capt_len; ++i) {
|
||||
if (i == href_len) { // ran out of href; mark as trail; EX: [[A]]s -> href="A"; capt="As"
|
||||
split_pos = i + capt_bgn;
|
||||
return Tid__href_trail;
|
||||
}
|
||||
byte href_byte = href_bry[i + href_bgn];
|
||||
byte capt_byte = capt_bry[i + capt_bgn];
|
||||
if (href_byte == capt_byte) continue;
|
||||
if ( i == 0 // ignore case if 1st letter and ns is Tid__1st; EX: [[earth]] -> href="Earth"; capt="earth"
|
||||
&& cs_tid_1st
|
||||
&& capt_byte >= Byte_ascii.Ltr_a && capt_byte <= Byte_ascii.Ltr_z
|
||||
&& (capt_byte - href_byte) == 32
|
||||
)
|
||||
continue;
|
||||
if ( capt_byte == Byte_ascii.Space // ignore " " vs "_"
|
||||
&& href_byte == Byte_ascii.Underline
|
||||
)
|
||||
continue;
|
||||
return Tid__capt; // bytes still diff; return diff
|
||||
}
|
||||
if (capt_len == href_len) // all bytes same and capt_len == href_len; must be same
|
||||
return capt_bgn_has_ns ? Tid__href : Tid__href_pipe;
|
||||
else { // capt < href; EX: [[A_(b)|A]] -> href="A_(b)"; capt = "A"
|
||||
split_pos = capt_len + href_bgn;
|
||||
return Tid__capt_short;
|
||||
}
|
||||
}
|
||||
public static final byte // SERIALIAZED
|
||||
Tid__href = 0 // [[A]] -> "A|A" -> "A|"
|
||||
, Tid__capt = 1 // [[A|b]] -> "A|b" -> "A|b"
|
||||
, Tid__href_trail = 2 // [[A]]s -> "A|As" -> "A|s"
|
||||
, Tid__capt_short = 3 // [[A_(b)|A]] -> "A_(b)|A" -> "A|_(b)"
|
||||
, Tid__href_pipe = 4 // [[Help:A|]] -> "Help:A|A" -> "A|"
|
||||
;
|
||||
}
|
||||
@@ -15,28 +15,27 @@ 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.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import org.junit.*; import gplx.core.brys.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_ttl_matcher_tst {
|
||||
private final Xoh_ttl_matcher_fxt fxt = new Xoh_ttl_matcher_fxt();
|
||||
@Test public void Basic__same() {fxt.Test__match("Abc" , "Abc", Xoh_ttl_matcher.Tid__same);}
|
||||
@Test public void Basic__diff() {fxt.Test__match("Abc" , "ABC", Xoh_ttl_matcher.Tid__diff);}
|
||||
@Test public void Space__same() {fxt.Test__match("A_b" , "A b", Xoh_ttl_matcher.Tid__same);}
|
||||
@Test public void Case__same() {fxt.Test__match("Abc" , "abc", Xoh_ttl_matcher.Tid__same);}
|
||||
@Test public void Case__reverse() {fxt.Test__match("abc" , "Abc", Xoh_ttl_matcher.Tid__diff);}
|
||||
public class Xoh_anch_capt_parser_tst {
|
||||
private final Xoh_anch_capt_parser_fxt fxt = new Xoh_anch_capt_parser_fxt();
|
||||
@Test public void Basic__same() {fxt.Test__match("Abc" , "Abc", Xoh_anch_capt_parser.Tid__href);}
|
||||
@Test public void Basic__diff() {fxt.Test__match("Abc" , "ABC", Xoh_anch_capt_parser.Tid__capt);}
|
||||
@Test public void Space__same() {fxt.Test__match("A_b" , "A b", Xoh_anch_capt_parser.Tid__href);}
|
||||
@Test public void Case__same() {fxt.Test__match("Abc" , "abc", Xoh_anch_capt_parser.Tid__href);}
|
||||
@Test public void Case__reverse() {fxt.Test__match("abc" , "Abc", Xoh_anch_capt_parser.Tid__capt);}
|
||||
@Test public void Case__disabled() {
|
||||
fxt.Wiki().Ns_mgr().Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all);
|
||||
fxt.Test__match("Abcde", "abcde", Xoh_ttl_matcher.Tid__diff);
|
||||
fxt.Test__match("Abcde", "abcde", Xoh_anch_capt_parser.Tid__capt);
|
||||
}
|
||||
@Test public void Ns__same() {fxt.Test__match("Help_talk:Ab" , "Help talk:Ab", Xoh_ttl_matcher.Tid__same);}
|
||||
@Test public void Ns__diff() {fxt.Test__match("Help_talk:Ab" , "Help_talk:Ab", Xoh_ttl_matcher.Tid__diff);}
|
||||
@Test public void Tail__same() {fxt.Test__match("A" , "Abc" , Xoh_ttl_matcher.Tid__tail, 1);}
|
||||
@Test public void Head__same() {fxt.Test__match("Ab" , "A" , Xoh_ttl_matcher.Tid__head, 1);}
|
||||
@Test public void Ns__href() {fxt.Test__match("Help_talk:Ab" , "Help talk:Ab" , Xoh_anch_capt_parser.Tid__href);}
|
||||
@Test public void Capt_trail() {fxt.Test__match("A" , "Abc" , Xoh_anch_capt_parser.Tid__href_trail, 1);}
|
||||
@Test public void Href_trail() {fxt.Test__match("Ab" , "A" , Xoh_anch_capt_parser.Tid__capt_short, 1);}
|
||||
}
|
||||
class Xoh_ttl_matcher_fxt {
|
||||
private final Xoh_ttl_matcher matcher = new Xoh_ttl_matcher();
|
||||
class Xoh_anch_capt_parser_fxt {
|
||||
private final Xoh_anch_capt_parser matcher = new Xoh_anch_capt_parser();
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public Xoh_ttl_matcher_fxt() {
|
||||
public Xoh_anch_capt_parser_fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
this.wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
@@ -45,7 +44,9 @@ class Xoh_ttl_matcher_fxt {
|
||||
public void Test__match(String page_str, String capt_str, int expd_tid, int expd_trail_bgn) {
|
||||
byte[] page_bry = Bry_.new_u8(page_str);
|
||||
byte[] capt_bry = Bry_.new_u8(capt_str);
|
||||
Tfds.Eq_int(expd_tid , matcher.Match(rdr.Init_by_page(Bry_.Empty, page_bry, page_bry.length), wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length));
|
||||
Tfds.Eq_int(expd_trail_bgn , matcher.Trail_bgn());
|
||||
Xoa_ttl href_ttl = wiki.Ttl_parse(page_bry);
|
||||
boolean cs_tid_1st = href_ttl.Ns().Case_match() == gplx.xowa.wikis.nss.Xow_ns_case_.Tid__1st;
|
||||
Tfds.Eq_int(expd_tid , matcher.Parse(rdr.Init_by_page(Bry_.Empty, page_bry, page_bry.length), Bool_.Y, cs_tid_1st, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length));
|
||||
Tfds.Eq_int(expd_trail_bgn , matcher.Split_pos());
|
||||
}
|
||||
}
|
||||
@@ -18,78 +18,114 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.apps.metas.*;
|
||||
public class Xoh_anch_href_parser implements Xoh_itm_parser {
|
||||
private Xoa_ttl page_ttl; Xow_ttl_parser ttl_parser;
|
||||
private byte[] page_bry; private Xoa_ttl page_ttl; private Xoa_app app; private Xow_ttl_parser ttl_parser;
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
|
||||
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
|
||||
public Html_atr Atr() {return atr;} private Html_atr atr;
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public boolean Tid_has_ns() {return tid_has_ns;} private boolean tid_has_ns;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Val_bgn() {return val_bgn;} private int val_bgn;
|
||||
public int Val_end() {return val_end;} private int val_end;
|
||||
public int Site_bgn() {return site_bgn;} private int site_bgn;
|
||||
public int Site_end() {return site_end;} private int site_end;
|
||||
public boolean Site_exists() {return site_end > site_bgn;}
|
||||
public boolean Rel_nofollow_exists() {
|
||||
if (Site_exists()) {
|
||||
if (rel_nofollow_exists == Bool_.__byte) {
|
||||
Xow_domain_itm itm = Xow_domain_itm_.parse(Bry_.Mid(src, site_bgn, site_end));
|
||||
rel_nofollow_exists = itm.Domain_type_id() == Xow_domain_tid_.Int__other ? Bool_.Y_byte : Bool_.N_byte;
|
||||
}
|
||||
return rel_nofollow_exists == Bool_.Y_byte;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} private byte rel_nofollow_exists;
|
||||
public int Page_bgn() {return page_bgn;} private int page_bgn;
|
||||
public int Page_end() {return page_end;} private int page_end;
|
||||
public byte[] Page_bry() {if (page_bry == null) page_bry = Bry_.Mid(src, page_bgn, page_end); return page_bry;} private byte[] page_bry;
|
||||
public byte[] Page_bry() {
|
||||
if (page_bry == null) {
|
||||
if (page_end - page_bgn == 0) // NOTE: href="/site/en.wikipedia.org/wiki/" can be null
|
||||
page_bry = Xoa_page_.Main_page_bry;
|
||||
else
|
||||
page_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Decode(src, page_bgn, page_end);
|
||||
}
|
||||
return page_bry;
|
||||
}
|
||||
public Xoa_ttl Page_ttl() {
|
||||
if (page_ttl == null) {
|
||||
page_bry = this.Page_bry();
|
||||
if (site_bgn != -1)
|
||||
ttl_parser = app.Wiki_mgri().Get_by_key_or_make_init_n(Bry_.Mid(src, site_bgn, site_end));
|
||||
page_ttl = ttl_parser.Ttl_parse(page_bry);
|
||||
page_bry = page_ttl.Full_db_w_anch();
|
||||
}
|
||||
return page_ttl;
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, Html_tag tag) {
|
||||
this.atr = tag.Atrs__get_by_or_fail(Html_atr_.Bry__href);
|
||||
Parse(owner_rdr, ttl_parser, atr.Val_bgn(), atr.Val_end());
|
||||
public int Page_ns_id() {
|
||||
switch (tid) {
|
||||
case Xoh_anch_href_parser.Tid__anch:
|
||||
case Xoh_anch_href_parser.Tid__inet: return Xow_ns_.Tid__main; // for purposes of hzip/make, assume main_ns
|
||||
case Xoh_anch_href_parser.Tid__wiki:
|
||||
case Xoh_anch_href_parser.Tid__site: return this.Page_ttl().Ns().Id();
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, int href_bgn, int href_end) {
|
||||
rdr.Init_by_sub(owner_rdr, "lnki.href", href_bgn, href_end);
|
||||
site_bgn = site_end = page_bgn = page_end = -1;
|
||||
tid = Tid__null;
|
||||
public boolean Page_ns_id_is_image() {return this.Page_ns_id() == Xow_ns_.Tid__file && Bry_.Has_at_bgn(page_bry, Xow_ns_.Alias__image__bry);}
|
||||
public boolean Parse(Bry_rdr owner_rdr, Xoa_app app, Xow_ttl_parser ttl_parser, Html_tag tag) {
|
||||
this.atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__href);
|
||||
return Parse(owner_rdr, app, ttl_parser, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public boolean Parse(Bry_rdr owner_rdr, Xoa_app app, Xow_ttl_parser ttl_parser, int href_bgn, int href_end) {
|
||||
if (href_bgn == -1) return false;
|
||||
rdr.Init_by_sub(owner_rdr, "anch.href", href_bgn, href_end);
|
||||
rel_nofollow_exists = Bool_.__byte;
|
||||
site_bgn = site_end = page_bgn = page_end = -1; this.src = owner_rdr.Src();
|
||||
tid = Tid__wiki;
|
||||
page_bry = null; page_ttl = null;
|
||||
this.val_bgn = href_bgn; this.val_end = href_end;
|
||||
this.src = owner_rdr.Src(); this.ttl_parser = ttl_parser;
|
||||
this.src = owner_rdr.Src(); this.ttl_parser = ttl_parser; this.app = app;
|
||||
if (val_end == val_bgn) {
|
||||
tid = Tid__inet;
|
||||
page_bgn = page_end = 0;
|
||||
return; // handle empty String separately; EX: href=""
|
||||
return true; // handle empty String separately; EX: href=""
|
||||
}
|
||||
int pos = href_bgn;
|
||||
switch (src[pos]) {
|
||||
case Byte_ascii.Hash:
|
||||
tid = Tid__anch;
|
||||
tid = Tid__anch; tid_has_ns = Bool_.N;
|
||||
page_bgn = pos + 1; // position page_bgn after #
|
||||
page_end = val_end; // anch ends at EOS
|
||||
break;
|
||||
default:
|
||||
tid = Tid__inet;
|
||||
tid = Tid__inet; tid_has_ns = Bool_.N;
|
||||
page_bgn = pos; // position page_bgn after #
|
||||
page_end = val_end; // anch ends at EOS
|
||||
break;
|
||||
case Byte_ascii.Slash:
|
||||
rdr.Move_by_one(); // skip "/"
|
||||
if (rdr.Chk(trie) == Tid__site) { // EX: "/site/wiki/A"
|
||||
tid = Tid__site;
|
||||
tid = Tid__site; tid_has_ns = Bool_.Y;
|
||||
site_bgn = rdr.Pos();
|
||||
site_end = rdr.Find_fwd_lr();
|
||||
rdr.Chk(Bry__wiki);
|
||||
}
|
||||
else {
|
||||
tid = Tid__wiki;
|
||||
tid = Tid__wiki; tid_has_ns = Bool_.Y;
|
||||
}
|
||||
page_bgn = rdr.Pos();
|
||||
page_end = rdr.Src_end();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static final byte
|
||||
Tid__null = 0 // EX: href=""
|
||||
, Tid__wiki = 1 // EX: href="/wiki/A"
|
||||
, Tid__site = 2 // EX: href="/site/en.wikipedia.org/wiki/A"
|
||||
, Tid__anch = 3 // EX: href="#A"
|
||||
, Tid__inet = 4 // EX: href="https://a.org/A"
|
||||
Tid__wiki = 0 // EX: href="/wiki/A"
|
||||
, Tid__site = 1 // EX: href="/site/en.wikipedia.org/wiki/A"
|
||||
, Tid__anch = 2 // EX: href="#A"
|
||||
, Tid__inet = 3 // EX: href="https://a.org/A"
|
||||
;
|
||||
private static final byte[] Bry__site = Bry_.new_a7("site/"), Bry__wiki = Bry_.new_a7("wiki/");
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
|
||||
|
||||
@@ -35,17 +35,18 @@ public class Xoh_anch_href_parser_tst {
|
||||
fxt.Test__parse("http://a.org", "", "http://a.org");
|
||||
}
|
||||
@Test public void Fail__1st_seg_must_be_site_or_wiki() {
|
||||
fxt.Test__parse__fail("/fail/A", "failed trie check: mid='fail/A' ctx='Main_Page' wkr='lnki.href' excerpt='/fail/A'");
|
||||
fxt.Test__parse__fail("/fail/A", "failed trie check: mid='fail/A' ctx='Main_Page' wkr='anch.href' excerpt=/fail/A");
|
||||
}
|
||||
@Test public void Fail__2nd_seg_must_be_wiki() {
|
||||
fxt.Test__parse__fail("/site/A/B/C", "failed check: chk='wiki/' ctx='Main_Page' wkr='lnki.href' excerpt='/site/A/B/C'");
|
||||
fxt.Test__parse__fail("/site/A/B/C", "failed check: chk='wiki/' ctx='Main_Page' wkr='anch.href' excerpt=/site/A/B/C");
|
||||
}
|
||||
}
|
||||
class Xoh_anch_href_parser_fxt extends Xoh_itm_parser_fxt_base {
|
||||
private final Xoae_app app;
|
||||
private final Xoh_anch_href_parser parser = new Xoh_anch_href_parser();
|
||||
private final Xow_ttl_parser ttl_parser;
|
||||
public Xoh_anch_href_parser_fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
this.app = Xoa_app_fxt.app_();
|
||||
ttl_parser = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
@Override public Xoh_itm_parser Parser_get() {return parser;}
|
||||
@@ -55,6 +56,6 @@ class Xoh_anch_href_parser_fxt extends Xoh_itm_parser_fxt_base {
|
||||
Tfds.Eq_str(expd_page, String_.new_u8(src, parser.Page_bgn(), parser.Page_end()));
|
||||
}
|
||||
@Override public void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end) {
|
||||
parser.Parse(owner_rdr, ttl_parser, src_bgn, src_end);
|
||||
parser.Parse(owner_rdr, app, ttl_parser, src_bgn, src_end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,33 +30,36 @@ public class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
|
||||
tmp_bfr.Add_double(xfer_itm.Lnki_upright()).Add_byte_pipe();
|
||||
tmp_bfr.Add_double(xfer_itm.Lnki_time()).Add_byte_pipe();
|
||||
tmp_bfr.Add_int_variable(xfer_itm.Lnki_page()).Add_byte_quote();
|
||||
// fmtr__img__full.Bld_bfr_many(bfr
|
||||
// , a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title
|
||||
// , img_alt, tmp_bfr.To_bry_and_clear(), arg_img_core.Init(uid, img_src, img_w, img_h), Xoh_img_cls_.To_html(img_cls, img_cls_other));
|
||||
fmtr__img__full.Bld_bfr_many(bfr
|
||||
, a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title
|
||||
, img_alt, tmp_bfr.To_bry_and_clear(), arg_img_core.Init(uid, img_src, img_w, img_h), Xoh_img_cls_.To_html(img_cls, img_cls_other));
|
||||
, a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title, Xoa_ttl.Replace_spaces(a_xowa_title)
|
||||
, img_alt, tmp_bfr.To_bry_and_clear(), arg_img_core.Init(uid, Bry_.Empty, 0, 0), Xoh_img_cls_.To_html(img_cls, img_cls_other));
|
||||
}
|
||||
private Bry_fmtr fmtr__img__full = Bry_fmtr.new_
|
||||
( "<a href=\"~{a_href}\"~{a_class}~{a_rel}~{a_title}>"
|
||||
+ "<img alt=\"~{img_alt}\"~{img_xoimg}~{img_core}~{img_class}/>"
|
||||
( "<a href=\"~{a_href}\"~{a_class}~{a_rel}~{a_title} xowa_title=\"~{a_xowa_title}\">"
|
||||
+ "<img~{img_xoimg}~{img_core}~{img_class} alt=\"~{img_alt}\"/>"
|
||||
+ "</a>"
|
||||
, "a_href", "a_class", "a_rel", "a_title", "img_alt", "img_xoimg", "img_core", "img_class"
|
||||
, "a_href", "a_class", "a_rel", "a_title", "a_xowa_title", "img_alt", "img_xoimg", "img_core", "img_class"
|
||||
);
|
||||
// public override void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bfr_arg html) {
|
||||
// fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html);
|
||||
// }
|
||||
@Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
|
||||
tmp_bfr.Add(Xoh_make_trie_.Bry__img_style);
|
||||
tmp_bfr.Add_int_variable(uid);
|
||||
tmp_bfr.Add_byte_quote();
|
||||
byte[] div2_width_repl = tmp_bfr.To_bry_and_clear();
|
||||
fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content);
|
||||
}
|
||||
@Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_mgnf, uid);}
|
||||
@Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_info, uid);}
|
||||
@Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_play, uid);}
|
||||
private static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
|
||||
bfr.Add(key);
|
||||
bfr.Add_int_variable(uid);
|
||||
bfr.Add(Bry_xnde_end);
|
||||
} private static final byte[] Bry_xnde_end = Bry_.new_a7("\"/>");
|
||||
// public override void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
|
||||
// tmp_bfr.Add(Xoh_make_trie_.Bry__img_style);
|
||||
// tmp_bfr.Add_int_variable(uid);
|
||||
// tmp_bfr.Add_byte_quote();
|
||||
// byte[] div2_width_repl = tmp_bfr.To_bry_and_clear();
|
||||
// fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content);
|
||||
// }
|
||||
// public override void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_mgnf, uid);}
|
||||
// public override void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_info, uid);}
|
||||
// public override void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_play, uid);}
|
||||
// private static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
|
||||
// bfr.Add(key);
|
||||
// bfr.Add_int_variable(uid);
|
||||
// bfr.Add(Bry_xnde_end);
|
||||
// } private static final byte[] Bry_xnde_end = Bry_.new_a7("\"/>");
|
||||
public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Xoh_file_wtr__basic {
|
||||
) {
|
||||
img_orig_src = img_view_src = Bry_.Empty; // null out src
|
||||
}
|
||||
if (lnki.Ns_id() == Xow_ns_.Tid__media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
|
||||
if (lnki.Ns_id() == Xow_ns_.Tid__media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
|
||||
this.Write_file_ns_media(bfr, ctx, src, lnki, img_orig_src);
|
||||
else {
|
||||
if ( Xof_ext_.Id_is_video_strict(orig_ext.Id()) // id is .ogv or .webm
|
||||
@@ -78,10 +78,10 @@ public class Xoh_file_wtr__basic {
|
||||
)
|
||||
) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid);
|
||||
this.Write_file_video(bfr, ctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_view_src, img_orig_src, img_alt, xfer_itm);
|
||||
this.Write_file_video(bfr, ctx, hctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_view_src, img_orig_src, img_alt, xfer_itm);
|
||||
}
|
||||
else if (orig_ext.Id_is_audio()) // audio
|
||||
this.Write_file_audio(bfr, ctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_orig_src, img_alt);
|
||||
this.Write_file_audio(bfr, ctx, hctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_orig_src, img_alt);
|
||||
else // image
|
||||
this.Write_file_image(bfr, ctx, hctx, src, lnki, xfer_itm, uid, lnki_is_thumbable, div_width, lnki_halign, lnki_halign_bry, lnki_ttl, orig_ext, lnki_href, img_view_src, img_orig_src, img_alt);
|
||||
}
|
||||
@@ -92,17 +92,17 @@ public class Xoh_file_wtr__basic {
|
||||
private void Write_file_ns_media(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, byte[] img_orig_src) {
|
||||
html_fmtr.Html_full_media(bfr, img_orig_src, lnki.Ttl().Page_txt(), Arg_caption(ctx, src, Xoh_wtr_ctx.Basic, lnki)); // NOTE: use orig_src not view_src; DATE:2014-01-19
|
||||
}
|
||||
private void Write_file_audio(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] img_orig_src, byte[] alt) {
|
||||
byte[] content = Arg_content_audio(lnki, ctx, src, uid, lnki_href, img_orig_src, alt);
|
||||
private void Write_file_audio(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] img_orig_src, byte[] alt) {
|
||||
byte[] content = Arg_content_audio(lnki, ctx, hctx, src, uid, lnki_href, img_orig_src, alt);
|
||||
if (lnki.Media_icon())
|
||||
html_fmtr.Html_thumb_core(bfr, uid, lnki_halign_bry, div_width, content);
|
||||
else
|
||||
bfr.Add(content);
|
||||
}
|
||||
private void Write_file_video(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] img_view_src, byte[] img_orig_src, byte[] alt, Xof_file_itm xfer_itm) {
|
||||
private void Write_file_video(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] img_view_src, byte[] img_orig_src, byte[] alt, Xof_file_itm xfer_itm) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid);
|
||||
boolean video_is_thumb = Xop_lnki_type.Id_defaults_to_thumb(lnki.Lnki_type());
|
||||
byte[] content = Arg_content_video(ctx, src, lnki, xfer_itm, uid, video_is_thumb, lnki_href, img_view_src, img_orig_src, alt);
|
||||
byte[] content = Arg_content_video(ctx, hctx, src, lnki, xfer_itm, uid, video_is_thumb, lnki_href, img_view_src, img_orig_src, alt);
|
||||
if (video_is_thumb)
|
||||
html_fmtr.Html_thumb_core(bfr, uid, lnki_halign_bry, div_width, content);
|
||||
else
|
||||
@@ -145,7 +145,7 @@ public class Xoh_file_wtr__basic {
|
||||
byte[] link_ref = link_tkn.Dat_to_bry(src);
|
||||
byte[] link_ref_new = tmp_link_parser.Parse(tmp_bfr, tmp_url, wiki, link_ref, lnki_href);
|
||||
link_ref = link_ref_new == null ? lnki_href: link_ref_new; // if parse fails, then assign to lnki_href; EX:link={{{1}}}
|
||||
link_ref = Xoa_app_.Utl__encoder_mgr().Href_quotes().Encode(link_ref); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16
|
||||
link_ref = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href_quotes.Encode(link_ref); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16
|
||||
if (Bry_.Len_gt_0(tmp_link_parser.Html_xowa_ttl())) lnki_ttl = tmp_link_parser.Html_xowa_ttl();
|
||||
lnki_file_wkr.Html_full_img(bfr, hctx, page, xfer_itm, uid, link_ref, tmp_link_parser.Html_anchor_cls(), tmp_link_parser.Html_anchor_rel(), anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, img_cls_tid, img_cls_other);
|
||||
}
|
||||
@@ -155,37 +155,37 @@ public class Xoh_file_wtr__basic {
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
private byte[] Arg_content_thumb(Xoh_file_img_wkr lnki_file_wkr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, byte[] lnki_href, byte[] view_src, byte[] img_orig_src, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_title) {
|
||||
byte[] lnki_alt_html = wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val() ? Arg_alt_html(ctx, src, lnki) : Bry_.Empty;
|
||||
byte[] lnki_alt_html = wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val() ? Arg_alt_html(ctx, hctx, src, lnki) : Bry_.Empty;
|
||||
byte img_cls_tid = xfer_itm.File_exists() ? Xoh_img_cls_.Tid__thumbimage : Xoh_img_cls_.Tid__none;
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
lnki_file_wkr.Html_full_img(tmp_bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, img_cls_tid, Xoh_img_cls_.Bry__none);
|
||||
byte[] thumb = tmp_bfr.To_bry_and_clear();
|
||||
html_fmtr.Html_thumb_file_image(tmp_bfr, thumb, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), lnki_alt_html);
|
||||
html_fmtr.Html_thumb_file_image(tmp_bfr, thumb, Arg_caption_div(ctx, hctx, src, lnki, uid, img_orig_src, lnki_href), lnki_alt_html);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private byte[] Arg_content_audio(Xop_lnki_tkn lnki, Xop_ctx ctx, byte[] src, int uid, byte[] lnki_href, byte[] img_orig_src, byte[] alt) {
|
||||
private byte[] Arg_content_audio(Xop_lnki_tkn lnki, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, int uid, byte[] lnki_href, byte[] img_orig_src, byte[] alt) {
|
||||
byte[] info_btn = Bry_.Empty;
|
||||
if (lnki.Media_icon()) {
|
||||
html_fmtr.Html_thumb_part_info(scratch_bfr, uid, lnki_href, html_mgr.Img_media_info_btn());
|
||||
info_btn = scratch_bfr.To_bry_and_clear();
|
||||
}
|
||||
int play_btn_width = lnki.W(); if (play_btn_width < 1) play_btn_width = html_mgr.Img_thumb_width(); // if no width set width to default img width
|
||||
html_fmtr.Html_thumb_file_audio(scratch_bfr, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), Arg_alt_html(ctx, src, lnki), Arg_play_btn(uid, play_btn_width, Play_btn_max_width, img_orig_src, lnki.Ttl().Page_txt()), info_btn);
|
||||
html_fmtr.Html_thumb_file_audio(scratch_bfr, Arg_caption_div(ctx, hctx, src, lnki, uid, img_orig_src, lnki_href), Arg_alt_html(ctx, hctx, src, lnki), Arg_play_btn(uid, play_btn_width, Play_btn_max_width, img_orig_src, lnki.Ttl().Page_txt()), info_btn);
|
||||
return scratch_bfr.To_bry_and_clear();
|
||||
}
|
||||
private byte[] Arg_content_video(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, boolean lnki_thumb, byte[] a_href, byte[] view_src, byte[] orig_src, byte[] img_alt) {
|
||||
private byte[] Arg_content_video(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, boolean lnki_thumb, byte[] a_href, byte[] view_src, byte[] orig_src, byte[] img_alt) {
|
||||
int thumb_w = xfer_itm.Html_w();
|
||||
int play_btn_width = thumb_w; if (play_btn_width < 1) play_btn_width = wiki.Html_mgr().Img_thumb_width();
|
||||
byte[] caption_html = Bry_.Empty, alt_html = Bry_.Empty;
|
||||
if (lnki_thumb) {
|
||||
caption_html = Arg_caption_div(ctx, src, lnki, uid, orig_src, a_href);
|
||||
alt_html = Arg_alt_html(ctx, src, lnki);
|
||||
caption_html = Arg_caption_div(ctx, hctx, src, lnki, uid, orig_src, a_href);
|
||||
alt_html = Arg_alt_html(ctx, hctx, src, lnki);
|
||||
}
|
||||
html_fmtr.Html_thumb_file_video(scratch_bfr, Arg_play_btn(uid, play_btn_width, play_btn_width, orig_src, lnki.Ttl().Page_txt()), html_fmtr.Html_thumb_part_img(scratch_bfr, page, xfer_itm, lnki, uid, a_href, view_src, img_alt), caption_html, alt_html);
|
||||
return scratch_bfr.To_bry_and_clear();
|
||||
}
|
||||
private byte[] Arg_caption_div(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, byte[] img_orig_src, byte[] lnki_href) {
|
||||
Bfr_arg caption = Arg_caption(ctx, src, Xoh_wtr_ctx.Basic, lnki);
|
||||
private byte[] Arg_caption_div(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, int uid, byte[] img_orig_src, byte[] lnki_href) {
|
||||
Bfr_arg caption = Arg_caption(ctx, src, hctx, lnki);
|
||||
byte[] magnify_btn = Bry_.Empty;
|
||||
if (lnki.Media_icon()) {
|
||||
if (msg_file_enlarge == null) msg_file_enlarge = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_file_enlarge);
|
||||
@@ -205,9 +205,9 @@ public class Xoh_file_wtr__basic {
|
||||
media_alt_fmtr.Bfr_arg__add(tmp_bfr);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private byte[] Arg_alt_html(Xop_ctx ctx, byte[] alt_src, Xop_lnki_tkn lnki) {
|
||||
private byte[] Arg_alt_html(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] alt_src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(ctx, Xoh_wtr_ctx.Basic, alt_src, lnki.Alt_tkn().Val_tkn(), html_fmtr.Html_thumb_part_alt_fmtr());
|
||||
media_alt_fmtr.Set(ctx, hctx, alt_src, lnki.Alt_tkn().Val_tkn(), html_fmtr.Html_thumb_part_alt_fmtr());
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.Bfr_arg__add(tmp_bfr);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_lnki_text_fmtr extends gplx.core.brys.Bfr_arg_base { // formats alt or caption
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Xoh_lnki_wtr {
|
||||
Xow_xwiki_itm xwiki_lang = lnki_ttl.Wik_itm();
|
||||
if ( xwiki_lang != null // lnki is xwiki; EX: [[commons:]] [[en:]] [[wikt:]]
|
||||
&& xwiki_lang.Domain_tid() == wiki.Xwiki_mgr().Xwiki_domain_tid() // xwiki is same type as cur wiki; EX: cur=w xwiki=w -> add to xwiki_langs; cur=w xwikid=d -> don't add to xwiki_langs; DATE:2014-09-14
|
||||
&& xwiki_lang.Show_in_sitelangs(wiki.Domain_itm().Lang_orig_key())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10
|
||||
&& xwiki_lang.Show_in_sitelangs(wiki.Domain_itm().Lang_orig_key()) // NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10
|
||||
&& !lnki_ttl.ForceLiteralLink() // not literal; [[:en:A]]
|
||||
) {
|
||||
Wdata_sitelink_itm slink = new Wdata_sitelink_itm(xwiki_lang.Abrv_wm(), xwiki_lang.Domain_name(), null).Page_ttl_(lnki_ttl);
|
||||
@@ -109,7 +109,7 @@ public class Xoh_lnki_wtr {
|
||||
}
|
||||
if (cfg.Lnki__title()) {
|
||||
bfr .Add(Xoh_consts.A_bgn_lnki_0); // '" title=\"'
|
||||
byte[] lnki_title_bry = lnki_ttl.Page_txt(); // 'Abcd' NOTE: use Page_txt to (a) replace underscores with spaces; (b) get title casing; EX:[[roman_empire]] -> Roman empire
|
||||
byte[] lnki_title_bry = lnki_ttl.Full_txt(); // 'Abcd' NOTE: use Full_txt to (a) replace underscores with spaces; (b) get title casing; EX:[[roman_empire]] -> Roman empire; (c) include ns_name; EX: Help:A -> "title='Help:A'" not "title='A'"; DATE:2015-11-16
|
||||
Html_utl.Escape_html_to_bfr(bfr, lnki_title_bry, 0, lnki_title_bry.length, Bool_.N, Bool_.N, Bool_.N, Bool_.Y, Bool_.N); // escape title; DATE:2014-10-27
|
||||
}
|
||||
if (!hctx.Mode_is_hdump()) { // don't write visited for hdump
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*;
|
||||
public class Xoh_hdoc_mkr {
|
||||
private Gfo_poolable_mgr
|
||||
pool__escape__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_escape_hzip())
|
||||
@@ -30,6 +30,7 @@ public class Xoh_hdoc_mkr {
|
||||
, pool__lnki__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_lnki_hzip())
|
||||
, pool__img__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_img_hzip())
|
||||
, pool__thm__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_thm_hzip())
|
||||
, pool__gly__hzip = Gfo_poolable_mgr_.New(1, 32, new Xoh_gly_hzip())
|
||||
;
|
||||
public Xoh_hzip_wkr Hzip__wkr(byte tid) {
|
||||
switch (tid) {
|
||||
@@ -40,6 +41,7 @@ public class Xoh_hdoc_mkr {
|
||||
case Xoh_hzip_dict_.Tid__lnki: return Lnki__hzip();
|
||||
case Xoh_hzip_dict_.Tid__img: return Img__hzip();
|
||||
case Xoh_hzip_dict_.Tid__thm: return Thm__hzip();
|
||||
case Xoh_hzip_dict_.Tid__gly: return Gly__hzip();
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
@@ -50,4 +52,5 @@ public class Xoh_hdoc_mkr {
|
||||
public Xoh_lnki_hzip Lnki__hzip() {return (Xoh_lnki_hzip) pool__lnki__hzip.Get_fast();}
|
||||
public Xoh_img_hzip Img__hzip() {return (Xoh_img_hzip) pool__img__hzip.Get_fast();}
|
||||
public Xoh_thm_hzip Thm__hzip() {return (Xoh_thm_hzip) pool__thm__hzip.Get_fast();}
|
||||
public Xoh_gly_hzip Gly__hzip() {return (Xoh_gly_hzip) pool__gly__hzip.Get_fast();}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ public class Xoh_space_hzip_tst {
|
||||
fxt.Test__bicode("~!{\"!", String_.Repeat(" ", 85));
|
||||
}
|
||||
@Test public void Many() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
fxt.Test__bicode(gplx.langs.htmls.Html_utl.Replace_apos(String_.Concat_lines_nl_skip_last
|
||||
( " <div id='bodyContent' class='mw-body-content'>"
|
||||
, "~!%<div id='siteSub'>a</div>"
|
||||
, "~!%<div id='contentSub'></div>"
|
||||
, "</div>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
)), String_.Concat_lines_nl_skip_last
|
||||
( " <div id='bodyContent' class='mw-body-content'>"
|
||||
, " <div id='siteSub'>a</div>"
|
||||
, " <div id='contentSub'></div>"
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.tags; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*; import gplx.xowa.htmls.core.wkrs.glys.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_tag_parser implements Html_doc_wkr {
|
||||
private final Xoh_hdoc_wkr hdoc_wkr;
|
||||
@@ -26,11 +26,12 @@ public class Xoh_tag_parser implements Html_doc_wkr {
|
||||
private final Xoh_hdr_parser wkr__hdr = new Xoh_hdr_parser();
|
||||
private final Xoh_lnki_parser wkr__lnki = new Xoh_lnki_parser(); private final Xoh_lnke_parser wkr__lnke = new Xoh_lnke_parser();
|
||||
private final Xoh_img_parser wkr__img = new Xoh_img_parser(); private final Xoh_thm_parser wkr__thm = new Xoh_thm_parser();
|
||||
private final Xoh_gly_grp_parser wkr__gly = new Xoh_gly_grp_parser();
|
||||
private Xoh_hdoc_ctx hctx;
|
||||
public byte[] Hook() {return Byte_ascii.Angle_bgn_bry;}
|
||||
public Xoh_tag_parser(Xoh_hdoc_wkr hdoc_wkr) {this.hdoc_wkr = hdoc_wkr;}
|
||||
public void Init(Xoh_hdoc_ctx hctx, byte[] src, int src_bgn, int src_end) {
|
||||
this.hctx = hctx; tag_rdr.Init(src, src_bgn, src_end);
|
||||
this.hctx = hctx; tag_rdr.Init(hctx.Page__url(), src, src_bgn, src_end);
|
||||
}
|
||||
public int Parse(byte[] src, int src_bgn, int src_end, int pos) {
|
||||
tag_rdr.Pos_(pos);
|
||||
@@ -54,16 +55,28 @@ public class Xoh_tag_parser implements Html_doc_wkr {
|
||||
nxt = tag_rdr.Tag__peek_fwd_head();
|
||||
if (nxt.Name_id() == Html_tag_.Id__img) {
|
||||
int rv = wkr__img.Parse(hdoc_wkr, hctx, src, tag_rdr, cur);
|
||||
hdoc_wkr.On_img(wkr__img);
|
||||
return rv;
|
||||
if (rv != Xoh_hdoc_ctx.Invalid) {
|
||||
hdoc_wkr.On_img(wkr__img);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
else if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Xoh_lnke_parser.Bry__rel__nofollow))
|
||||
else if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Xoh_lnke_dict_.Html__rel__nofollow))
|
||||
return wkr__lnke.Parse(hdoc_wkr, tag_rdr, cur);
|
||||
else
|
||||
return wkr__lnki.Parse(hdoc_wkr, hctx, src, tag_rdr, cur, hctx.Wiki__ttl_parser());
|
||||
break;
|
||||
case Html_tag_.Id__div:
|
||||
if (cur.Atrs__cls_has(Xoh_thm_parser.Atr__class__thumb))
|
||||
return wkr__thm.Parse(hdoc_wkr, hctx, src, tag_rdr, cur);
|
||||
if (cur.Atrs__cls_has(Xoh_thm_parser.Atr__class__thumb)) {
|
||||
int rv = wkr__thm.Parse(hdoc_wkr, hctx, src, tag_rdr, cur);
|
||||
if (rv != Xoh_hdoc_ctx.Invalid) return rv;
|
||||
}
|
||||
break;
|
||||
case Html_tag_.Id__ul:
|
||||
if (cur.Atrs__cls_has(Xoh_gly_grp_parser.Atr__class__gallery)) {
|
||||
int rv = wkr__gly.Parse(hdoc_wkr, hctx, src, tag_rdr, cur);
|
||||
hdoc_wkr.On_gly(wkr__gly);
|
||||
if (rv != Xoh_hdoc_ctx.Invalid) return rv;
|
||||
}
|
||||
break;
|
||||
}
|
||||
hdoc_wkr.On_txt(pos, cur.Src_end());
|
||||
|
||||
@@ -22,15 +22,16 @@ import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.imgs.a
|
||||
public class Xoh_thm_bldr {
|
||||
private final Xoh_thm_wtr wtr = new Xoh_thm_wtr();
|
||||
private final byte[] div_2_magnify = Bry_.new_a7("bin/any/xowa/file/mediawiki.file/magnify-clip.png");
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int div_0_align, Xoh_img_bldr img_bldr, Bfr_arg div_2_href, Bfr_arg div_2_capt) {
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] src, int div_0_align, int div_1_width, boolean div_2_alt_exists, byte[] img_alt, Xoh_img_bldr img_bldr, Bfr_arg div_2_href, Bfr_arg div_2_capt) {
|
||||
wtr.Clear();
|
||||
wtr.Div_0_align_(div_0_align);
|
||||
wtr.Div_1_id_(img_bldr.Fsdb_itm().Html_uid());
|
||||
wtr.Div_1_width_(img_bldr.Fsdb_itm().File_w());
|
||||
wtr.Div_1_width_(div_1_width);
|
||||
wtr.Div_1_img_(img_bldr.Wtr());
|
||||
wtr.Div_2_href_(div_2_href);
|
||||
wtr.Div_2_magnify_(hctx.Fsys__root(), div_2_magnify);
|
||||
wtr.Div_2_capt_(div_2_capt);
|
||||
wtr.Div_2_alt_(div_2_alt_exists, img_alt);
|
||||
wtr.Bfr_arg__add(bfr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,14 @@ public class Xoh_thm_html_tst {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png));
|
||||
fxt.Test__html("[[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'><img alt='' data-xoimg='8|-1|-1|-1|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='0' height='0'/></a>"
|
||||
, " <div class='thumbcaption'><xowa_mgnf id='0'/>"
|
||||
, " <div id='xowa_file_div_0' class='thumbinner' style='width:220px;'>"
|
||||
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img data-xoimg='8|-1|-1|-1|-1|-1' src='' width='0' height='0' alt=''/></a>"
|
||||
, " <div class='thumbcaption'>"
|
||||
, " <div class='magnify'>"
|
||||
, " <a href='/wiki/File:A.png' class='internal' title='Enlarge'>"
|
||||
, " <img src='file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt='' />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
|
||||
@@ -19,20 +19,26 @@ package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; impor
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.divs.*;
|
||||
public class Xoh_thm_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
private final int[] flag_ary;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_ ( 2);
|
||||
private final Xoh_img_hzip img_hzip = new Xoh_img_hzip();
|
||||
private final Xoh_thm_bldr bldr = new Xoh_thm_bldr();
|
||||
private final Bry_obj_ref div_2_capt = Bry_obj_ref.New_empty();
|
||||
public Xoh_thm_hzip() {this.flag_ary = flag_bldr.Val_ary();}
|
||||
public String Key() {return Xoh_hzip_dict_.Key__thm;}
|
||||
public Xoh_thm_hzip Encode(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Hzip_stat_itm stat_itm, byte[] src, Xoh_thm_parser arg) {
|
||||
if (!arg.Rng_valid()) {
|
||||
bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());
|
||||
return this;
|
||||
}
|
||||
Xoh_thm_caption_parser div_2_capt_parser = arg.Capt_parser();
|
||||
flag_ary[ 0] = arg.Div_0_align();
|
||||
|
||||
int div_1_width = arg.Div_1_width(); boolean div_1_width_exists = div_1_width != 220;
|
||||
boolean div_2_alt_exists = arg.Capt_parser().Alt_div_exists();
|
||||
flag_bldr.Set(Flag__div_2_alt_exists , div_2_alt_exists);
|
||||
flag_bldr.Set(Flag__div_1_width_exists , div_1_width_exists);
|
||||
flag_bldr.Set(Flag__div_0_align , arg.Div_0_align());
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__thm);
|
||||
Xoh_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
|
||||
if (div_1_width_exists) Xoh_hzip_int_.Encode(2, bfr, div_1_width);
|
||||
bfr.Add_mid(src, div_2_capt_parser.Capt_bgn(), div_2_capt_parser.Capt_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
if (div_2_alt_exists) bfr.Add_mid(src, div_2_capt_parser.Alt_div_bgn(), div_2_capt_parser.Alt_div_end()).Add_byte(Xoh_hzip_dict_.Escape);
|
||||
img_hzip.Encode(bfr, stat_itm, src, arg.Img_parser(), Bool_.N);
|
||||
return this;
|
||||
}
|
||||
@@ -43,14 +49,25 @@ public class Xoh_thm_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
int rv = rdr.Pos();
|
||||
|
||||
flag_bldr.Decode(flag);
|
||||
int div_align = flag_ary[ 0];
|
||||
boolean div_2_alt_exists = flag_bldr.Get_as_bool(Flag__div_2_alt_exists);
|
||||
boolean div_1_width_exists = flag_bldr.Get_as_bool(Flag__div_1_width_exists);
|
||||
int div_0_align = flag_bldr.Get_as_int(Flag__div_0_align);
|
||||
int div_1_width = 220;
|
||||
if (div_1_width_exists) div_1_width = rdr.Read_int_by_base85(2);
|
||||
div_2_capt.Mid_(src, capt_bgn, capt_end);
|
||||
byte[] div_2_alt_bry = div_2_alt_exists ? rdr.Read_bry_to() : Bry_.Empty;
|
||||
img_hzip.Decode(bfr, Bool_.N, hctx, hpg, rdr, src, rv);
|
||||
bldr.Make(bfr, hpg, hctx, src, div_align, img_hzip.Bldr(), img_hzip.Anch_href_arg(), div_2_capt);
|
||||
bldr.Make(bfr, hpg, hctx, src, div_0_align, div_1_width, div_2_alt_exists, div_2_alt_bry, img_hzip.Bldr(), img_hzip.Anch_href_arg(), div_2_capt);
|
||||
return rv;
|
||||
}
|
||||
public int Pool__idx() {return pool_idx;} private int pool_idx;
|
||||
public void Pool__clear (Object[] args) {}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_thm_hzip rv = new Xoh_thm_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 3);
|
||||
private static final int // SERIALIZED
|
||||
Flag__div_2_alt_exists = 0
|
||||
, Flag__div_1_width_exists = 1
|
||||
, Flag__div_0_align = 2 // "", "tnone", "tleft", "tcenter", "tright"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -19,24 +19,56 @@ package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; impor
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_thm_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
private String Html__basic = String_.Concat_lines_nl_skip_last
|
||||
private String Html__image = String_.Concat_lines_nl_skip_last
|
||||
( "<div class='thumb tleft'>"
|
||||
, " <div id='xothm_0' class='thumbinner' style='width:0px;'>"
|
||||
, "<a href='/wiki/File:A.png' class='image'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='119' class='thumbimage'></a>"
|
||||
, " <div id='xothm_0' class='thumbinner' style='width:220px;'>"
|
||||
, " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'><img id='xoimg_0' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' class='thumbimage' alt='abc'></a>"
|
||||
, " <div class='thumbcaption'>"
|
||||
, " <div class='magnify'>"
|
||||
, " <a href='/wiki/File:A.png' class='@gplx.Internal protected' title='Enlarge'>"
|
||||
, " <img src='file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt=''>"
|
||||
, " </a>"
|
||||
, " <a href='/wiki/File:A.png' class='internal' title='Enlarge'><img src='file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt=''></a>"
|
||||
, " </div>abc"
|
||||
, " </div>"
|
||||
, " <hr>"
|
||||
, " <div class='thumbcaption'>"
|
||||
, " abc"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
);
|
||||
@Test public void Page__basic() {
|
||||
fxt.Test__decode("~&#abc~!T8#T\"DA.png~", Html__basic);
|
||||
)
|
||||
, Html__video = String_.Replace(String_.Concat_lines_nl_skip_last
|
||||
( "<div class='thumb tright'>"
|
||||
, " <div id='xowa_file_div_3' class='thumbinner' style='width:220px;'>"
|
||||
, " <div id='xowa_media_div'>"
|
||||
, " <div>"
|
||||
, " <a href='/wiki/File:a.ogv' class='image' title='a.ogv'><img id='xowa_file_img_3' src='file:///' width='-1' height='-1' alt=''></a>"
|
||||
, " </div>"
|
||||
, " <div>"
|
||||
, " <a id='xowa_file_play_3' href='file:///' xowa_title='a.ogv' class='xowa_anchor_button' style='width:218px;max-width:220px;'><img src='file:///C:/xowa/bin/any/xowa/file/mediawiki.file/play.png' width='22' height='22' alt='Play sound'></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class='thumbcaption'>"
|
||||
, " <div class='magnify'>"
|
||||
, " <a href='/wiki/File:a.ogv' class='@gplx.Internal protected' title='Enlarge'><img src='file:///C:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt=''></a>"
|
||||
, " </div>Moscow (Russian Empire) in 1908"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
), "'", "\"")
|
||||
;
|
||||
@Test public void Image() {
|
||||
fxt.Test__bicode("~&3abc~abc~!uA.png~0|220|110|0.5|-1|-1~abc~", Html__image);
|
||||
}
|
||||
@Test public void Dump() {
|
||||
// fxt.Exec_write_to_fsys(Io_url_.new_dir_("J:\\xowa\\dev\\html\\"), "temp_earth_xo.html");
|
||||
@Test public void Video() {
|
||||
fxt.Test__bicode(Html__video, Html__video);
|
||||
}
|
||||
// @Test public void Dump() {
|
||||
// Xowe_wiki en_d = fxt.Prep_create_wiki("wikt", "en.wiktionary.org");
|
||||
// gplx.xowa.wikis.nss.Xow_ns_mgr ns_mgr = en_d.Ns_mgr();
|
||||
// ns_mgr.Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all);
|
||||
//
|
||||
// fxt.Wiki().Ns_mgr().Aliases_add(gplx.xowa.wikis.nss.Xow_ns_.Tid__portal, "WP");
|
||||
// fxt.Wiki().Ns_mgr().Init();
|
||||
//
|
||||
// fxt.Exec_write_to_fsys(Io_url_.new_dir_("D:\\xowa\\dev_rls\\html\\"), "temp_earth_xo.html");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import gplx.xowa.htmls.core.wkrs.thms.divs.*; import gplx.xowa.htmls.core.wkrs.i
|
||||
public class Xoh_thm_parser implements Html_atr_style_wkr {
|
||||
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public boolean Rng_valid() {return rng_valid;} private boolean rng_valid;
|
||||
public byte Div_0_align() {return div_0_align;} private byte div_0_align;
|
||||
public int Div_1_width() {return div_1_width;} private int div_1_width;
|
||||
public Xoh_img_parser Img_parser() {return img_parser;} private final Xoh_img_parser img_parser = new Xoh_img_parser();
|
||||
@@ -33,8 +34,11 @@ public class Xoh_thm_parser implements Html_atr_style_wkr {
|
||||
Html_tag div_1 = tag_rdr.Tag__move_fwd_head(); // <div class='thumbinner'>
|
||||
this.div_1_width = -1;
|
||||
Html_atr_style_parser_.Parse(div_1, this); // " style='120px'"
|
||||
img_parser.Parse(hdoc_wkr, hctx, src, tag_rdr, tag_rdr.Tag__move_fwd_head()); // <a>
|
||||
capt_parser.Parse(hdoc_wkr, tag_rdr, src, tag_rdr.Tag__move_fwd_head()); // <div>
|
||||
rng_valid = false;
|
||||
if (img_parser.Parse(hdoc_wkr, hctx, src, tag_rdr, tag_rdr.Tag__move_fwd_head()) != Xoh_hdoc_ctx.Invalid) { // <a>
|
||||
capt_parser.Parse(hdoc_wkr, tag_rdr, src, tag_rdr.Tag__move_fwd_head()); // <div>
|
||||
rng_valid = true;
|
||||
}
|
||||
tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); // </div> for div_1
|
||||
Html_tag div_0_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); // </div> for div_0
|
||||
this.rng_end = div_0_tail.Src_end();
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Xoh_thm_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
, div_2_href = new Bfr_arg__html_atr(Html_atr_.Bry__href)
|
||||
;
|
||||
private final Bfr_arg__bry_ary div_2_magnify = new Bfr_arg__bry_ary();
|
||||
private final Bfr_arg__bry div_2_alt = new Bfr_arg__bry(Bry_.Empty);
|
||||
private Bfr_arg div_1_img = Bfr_arg_.Noop, div_2_capt = Bfr_arg_.Noop;
|
||||
public Xoh_thm_wtr Div_0_align_(int v) {div_0_align.Val_(gplx.xowa.parsers.lnkis.Xop_lnki_align_h_.To_bry(v)); return this;}
|
||||
public Xoh_thm_wtr Div_1_id_(int v) {div_1_id.Set_by_arg(div_1_id_val.Set(Prefix__div_id, v)); return this;}
|
||||
@@ -36,26 +37,41 @@ public class Xoh_thm_wtr extends gplx.core.brys.Bfr_arg_base {
|
||||
public Xoh_thm_wtr Div_2_href_(Bfr_arg v) {div_2_href.Set_by_arg(v); return this;}
|
||||
public Xoh_thm_wtr Div_2_magnify_(byte[]... v) {div_2_magnify.Set(v); return this;}
|
||||
public Xoh_thm_wtr Div_2_capt_(Bfr_arg v) {div_2_capt = v; return this;}
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
|
||||
public Xoh_thm_wtr Div_2_alt_(boolean v, byte[] img_alt_bry) {
|
||||
if (v) {
|
||||
// img_alt.Bfr_arg__add(tmp_bfr);
|
||||
// byte[] img_alt_bry = tmp_bfr.To_bry_and_clear();
|
||||
alt_fmtr.Bld_bfr_many(tmp_bfr, img_alt_bry);
|
||||
div_2_alt.Set(tmp_bfr.To_bry_and_clear());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Xoh_thm_wtr Clear() {
|
||||
Bfr_arg_.Clear(div_0_align, div_1_id, div_1_width, div_1_img, div_2_href, div_2_magnify, div_2_capt);
|
||||
Bfr_arg_.Clear(div_0_align, div_1_id, div_1_width, div_1_img, div_2_href, div_2_magnify, div_2_capt, div_2_alt);
|
||||
return this;
|
||||
}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, div_0_align, div_1_id, div_1_width, div_1_img, div_2_href, div_2_magnify, div_2_capt);
|
||||
fmtr.Bld_bfr_many(bfr, div_0_align, div_1_id, div_1_width, div_1_img, div_2_href, div_2_magnify, div_2_capt, div_2_alt);
|
||||
}
|
||||
public static final byte[] Prefix__div_id = Bry_.new_a7("xothm_");
|
||||
private static final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb t~{div_0_align}\">"
|
||||
, " <div~{div_1_id} class=\"thumbinner\" style=\"width:~{div_1_width}px;\">"
|
||||
, "~{div_1_img}"
|
||||
, " ~{div_1_img}"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a~{div_2_href} class=\"@gplx.Internal protected\" title=\"Enlarge\">"
|
||||
, " <img src=\"~{div_2_magnify}\" width=\"15\" height=\"11\" alt=\"\">"
|
||||
, " </a>"
|
||||
, " <a~{div_2_href} class=\"internal\" title=\"Enlarge\"><img src=\"~{div_2_magnify}\" width=\"15\" height=\"11\" alt=\"\"></a>"
|
||||
, " </div>~{div_2_capt}"
|
||||
, " </div>"
|
||||
, " </div>~{div_2_alt}"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
), "div_0_align", "div_1_id", "div_1_width", "div_1_img", "div_2_href", "div_2_magnify", "div_2_capt");
|
||||
), "div_0_align", "div_1_id", "div_1_width", "div_1_img", "div_2_href", "div_2_magnify", "div_2_capt", "div_2_alt");
|
||||
private static final Bry_fmtr alt_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <hr>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " ~{alt}"
|
||||
, " </div>"
|
||||
), "alt");
|
||||
}
|
||||
|
||||
@@ -22,15 +22,29 @@ public class Xoh_thm_caption_parser {
|
||||
public int Rng_end() {return rng_end;} private int rng_end;
|
||||
public int Capt_bgn() {return capt_bgn;} private int capt_bgn;
|
||||
public int Capt_end() {return capt_end;} private int capt_end;
|
||||
public int Alt_div_bgn() {return alt_div_bgn;} private int alt_div_bgn;
|
||||
public int Alt_div_end() {return alt_div_end;} private int alt_div_end;
|
||||
public boolean Alt_div_exists() {return alt_div_end > alt_div_bgn;}
|
||||
public Xoh_thm_magnify_parser Magnify_parser() {return magnify_parser;} private final Xoh_thm_magnify_parser magnify_parser = new Xoh_thm_magnify_parser();
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag div_caption) {
|
||||
this.rng_bgn = div_caption.Src_bgn();
|
||||
magnify_parser.Parse(hdoc_wkr, tag_rdr, src, div_caption);
|
||||
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag capt_head) {
|
||||
this.rng_bgn = capt_head.Src_bgn();
|
||||
magnify_parser.Parse(hdoc_wkr, tag_rdr, src, capt_head);
|
||||
this.capt_bgn = magnify_parser.Magnify_tail_div().Src_end();
|
||||
Html_tag div_caption_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
this.capt_end = div_caption_tail.Src_bgn();
|
||||
Html_tag capt_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
|
||||
this.capt_end = capt_tail.Src_bgn();
|
||||
capt_end = Bry_find_.Find_bwd_non_ws_or_end(src, capt_end - 1, -1) + 1;
|
||||
this.rng_end = div_caption_tail.Src_end();
|
||||
Alt_div_exists(tag_rdr, src);
|
||||
this.rng_end = tag_rdr.Pos();
|
||||
return rng_end;
|
||||
}
|
||||
private void Alt_div_exists(Html_tag_rdr tag_rdr, byte[] src) {
|
||||
this.alt_div_bgn = alt_div_end = -1;
|
||||
Html_tag nxt_tag = tag_rdr.Tag__peek_fwd_head();
|
||||
if (nxt_tag.Name_id() != Html_tag_.Id__hr) return;
|
||||
tag_rdr.Tag__move_fwd_head(); // <hr>
|
||||
nxt_tag = tag_rdr.Tag__move_fwd_head().Chk_id(Html_tag_.Id__div); // <div>
|
||||
alt_div_bgn = Bry_find_.Find_fwd_while_ws(src, nxt_tag.Src_end(), src.length);
|
||||
nxt_tag = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div); // </div>
|
||||
alt_div_end = Bry_find_.Find_bwd_non_ws_or_not_found(src, nxt_tag.Src_bgn() - 1, -1) + 1;
|
||||
}
|
||||
}
|
||||
@@ -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.core.wkrs.xndes.styles; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.xndes.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xoh_style_regy {
|
||||
// public void Init() {
|
||||
// // initial, inherit
|
||||
// Add(Tid__style) .List("inline", "block", "flex", "inline-block", "inline-flex", "inline-table", "list-item", "run-in", "table", "table-caption", "table-column-group", "table-header-group", "table-footer-group", "table-row-group", "table-cell", "table-column", "table-row");
|
||||
// Add(Tid__text_align) .List("left", "right", "center", "justify");
|
||||
// Add(Tid__float) .List("none", "left", "right");
|
||||
// Add(Tid__clear) .List("none", "left", "right", "both");
|
||||
// }
|
||||
}
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.css; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.css.*;
|
||||
|
||||
@@ -21,7 +21,7 @@ import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xoh_href_wtr {
|
||||
private final Bry_bfr encoder_bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Url_encoder encoder = Xoa_app_.Utl__encoder_mgr().Href();
|
||||
private final Gfo_url_encoder encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href;
|
||||
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
synchronized (tmp_bfr) {
|
||||
Build_to_bfr(tmp_bfr, wiki.App(), wiki.Domain_bry(), ttl, Bool_.N);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Xow_popup_html_mkr {
|
||||
if (output_js_clean) app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page.Ttl(), wrdx_bfr, 0);
|
||||
if (output_tidy) app.Html_mgr().Tidy_mgr().Run_tidy_html(page, wrdx_bfr);
|
||||
byte[] hdom_bry = wrdx_bfr.To_bry_and_clear();
|
||||
String page_url = wrdx_bfr.Add(page.Wiki().Domain_bry()).Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki).Add(Xoa_app_.Utl__encoder_mgr().Href()
|
||||
String page_url = wrdx_bfr.Add(page.Wiki().Domain_bry()).Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki).Add(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href
|
||||
.Encode(page.Ttl().Full_db())) // NOTE: was page.Url().Raw(), but that doesn't work for Special:Search; PAGE:en.w:Earth and "Quotations"; DATE:2014-06-29
|
||||
.To_str_and_clear()
|
||||
;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.modules.popups; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.modules.*;
|
||||
import gplx.core.primitives.*; import gplx.core.threads.*;
|
||||
import gplx.core.primitives.*; import gplx.core.threads.*; import gplx.core.envs.*;
|
||||
import gplx.core.js.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
|
||||
@@ -210,7 +210,7 @@ public class Xow_popup_parser {
|
||||
class Xow_popup_parser_ {
|
||||
public static int Tmpl_bgn_get_(Xoae_app app, Xow_popup_itm itm, Xoa_ttl page_ttl, Xow_popup_anchor_finder hdr_finder, byte[] src, int src_len) {
|
||||
int rv = Xop_parser_.Doc_bgn_bos; if (itm.Mode_all()) return rv;
|
||||
byte[] anch = itm.Page_href()[0] == Byte_ascii.Hash ? Bry_.Mid(Xoa_app_.Utl__encoder_mgr().Href().Decode(itm.Page_href()), 1) : page_ttl.Anch_txt();
|
||||
byte[] anch = itm.Page_href()[0] == Byte_ascii.Hash ? Bry_.Mid(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Decode(itm.Page_href()), 1) : page_ttl.Anch_txt();
|
||||
if (anch == null) return rv;
|
||||
int hdr_bgn = hdr_finder.Find(src, src_len, anch, rv); // NOTE: starting search from Xop_parser_.Doc_bgn_bos
|
||||
return hdr_bgn == Bry_find_.Not_found ? rv : hdr_bgn;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class Xoh_ns_file_page_mgr extends gplx.core.brys.Bfr_arg_base {
|
||||
alt_wtr.Init_by_fmtr(repo_mgr, xfer_itm, html_wtr);
|
||||
Xof_ext orig_ext = xfer_itm.Orig_ext();
|
||||
if (orig_ext.Id_is_thumbable_img())
|
||||
html_wtr.Html_main_img().Bld_bfr_many(bfr, xfer_itm.Orig_w(), xfer_itm.Orig_h(), xfer_itm.Html_orig_url().To_http_file_bry(), file_size_bry, orig_ext.Mime_type(), xfer_itm.Html_uid(), xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Html_view_url().To_http_file_bry(), ttl.Full_txt(), Xoa_app_.Utl__encoder_mgr().Http_url().Encode(ttl.Page_url()), alt_wtr);
|
||||
html_wtr.Html_main_img().Bld_bfr_many(bfr, xfer_itm.Orig_w(), xfer_itm.Orig_h(), xfer_itm.Html_orig_url().To_http_file_bry(), file_size_bry, orig_ext.Mime_type(), xfer_itm.Html_uid(), xfer_itm.Html_w(), xfer_itm.Html_h(), xfer_itm.Html_view_url().To_http_file_bry(), ttl.Full_txt(), gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Encode(ttl.Page_url()), alt_wtr);
|
||||
else if (orig_ext.Id_is_video()) // NOTE: video must precede audio else File:***.ogg will not show thumbs
|
||||
html_wtr.Html_main_vid().Bld_bfr_many(bfr, xfer_itm.Html_uid(), xfer_itm.Html_view_url().To_http_file_bry(), Atr_class_image, ttl.Page_db(), xfer_itm.Html_view_url().To_http_file_bry(), xfer_itm.Html_w(), xfer_itm.Html_h(), Bry_.Empty, xfer_itm.Html_orig_url().To_http_file_bry(), xfer_itm.Html_w(), xfer_itm.Html_w(), play_btn_icon);
|
||||
else if (orig_ext.Id_is_audio())
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Xoh_subpages_bldr extends gplx.core.brys.Bfr_arg_base {
|
||||
byte[] seg = segs[i];
|
||||
ttl_bfr.Add(seg);
|
||||
byte[] seg_ttl = ttl_bfr.To_bry();
|
||||
byte[] seg_ttl_enc = Xoa_app_.Utl__encoder_mgr().Href().Encode(ttl_bfr.To_bry());
|
||||
byte[] seg_ttl_enc = gplx.langs.htmls.encoders.Gfo_url_encoder_.Href.Encode(ttl_bfr.To_bry());
|
||||
byte[] href = Bry_.Add(Xoh_href_.Bry__wiki, seg_ttl_enc); // EX: /wiki/Help:A
|
||||
fmtr_itm.Bld_bfr(bfr, dlm, href, seg_ttl, seg);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Xow_portal_mgr implements GfoInvkAble {
|
||||
byte[] wiki_user_name = wiki.User().Name();
|
||||
div_personal_bry = Init_fmtr(tmp_bfr, eval_mgr, div_personal_fmtr, Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user).Name_db_w_colon(), wiki_user_name), wiki_user_name, Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Tid__user), Bry_.Add(Xoh_href_.Bry__wiki, wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user_talk).Name_db_w_colon(), wiki_user_name), Ns_cls_by_id(wiki.Ns_mgr(), Xow_ns_.Tid__user_talk));
|
||||
byte[] main_page_href_bry = tmp_bfr.Add(Xoh_href_.Bry__site).Add(wiki.Domain_bry()).Add(Xoh_href_.Bry__wiki).To_bry_and_clear(); // NOTE: build /site/en.wikipedia.org/wiki/ href; no Main_Page, as that will be inserted by Xoh_href_parser
|
||||
div_logo_bry = Init_fmtr(tmp_bfr, eval_mgr, div_logo_fmtr, main_page_href_bry, Xoa_app_.Utl__encoder_mgr().Fsys().Encode_http(wiki.Appe().Usere().Fsys_mgr().Wiki_root_dir().GenSubFil_nest(wiki.Domain_str(), "html", "logo.png")));
|
||||
div_logo_bry = Init_fmtr(tmp_bfr, eval_mgr, div_logo_fmtr, main_page_href_bry, gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys.Encode_to_file_protocol(wiki.Appe().Usere().Fsys_mgr().Wiki_root_dir().GenSubFil_nest(wiki.Domain_str(), "html", "logo.png")));
|
||||
div_home_bry = Init_fmtr(tmp_bfr, eval_mgr, div_home_fmtr);
|
||||
div_wikis_fmtr.Eval_mgr_(eval_mgr);
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Xowh_sidebar_mgr implements GfoInvkAble {
|
||||
public void Parse(Bry_bfr bfr, Bry_bfr comment_bfr, byte[] src) {
|
||||
byte[][] lines = Bry_split_.Split(src, Byte_ascii.Nl);
|
||||
int lines_len = lines.length;
|
||||
Url_encoder id_encoder = Xoa_app_.Utl__encoder_mgr().Id();
|
||||
Gfo_url_encoder id_encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Id;
|
||||
Xowh_sidebar_itm cur_grp = null;
|
||||
Xop_link_parser link_parser = new Xop_link_parser();
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
|
||||
@@ -16,14 +16,14 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.tocs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.core.brys.*; import gplx.core.primitives.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xow_hdr_mgr {
|
||||
private final Url_encoder_mgr encoder_mgr; private final Xoae_page page;
|
||||
private final Xoae_page page;
|
||||
private final Hash_adp hdrs_hash = Hash_adp_.new_(); private final Bry_bfr hdrs_bfr = Bry_bfr.reset_(255); private final Bry_obj_ref hdrs_ref = Bry_obj_ref.New_empty();
|
||||
private Xop_hdr_tkn[] hdrs_ary = new Xop_hdr_tkn[0]; private int hdrs_max, hdrs_len;
|
||||
public Xow_hdr_mgr(Xoae_page page, Url_encoder_mgr encoder_mgr) {this.page = page; this.encoder_mgr = encoder_mgr;}
|
||||
public Xow_hdr_mgr(Xoae_page page) {this.page = page;}
|
||||
public boolean Toc_enabled() {
|
||||
return !toc_hide // check for __NOTOC__
|
||||
&& hdrs_len != 0 // never show TOC if 0 headers, even when __FORCETOC__
|
||||
@@ -63,7 +63,7 @@ public class Xow_hdr_mgr {
|
||||
Bry_bfr_mkr bfr_mkr = Xoa_app_.Utl__bfr_mkr();
|
||||
Bry_bfr raw_bfr = bfr_mkr.Get_b128(), enc_bfr = bfr_mkr.Get_b128();
|
||||
Id_bld_recurse(raw_bfr, src, hdr);
|
||||
Url_encoder encoder = encoder_mgr.Id();
|
||||
Gfo_url_encoder encoder = gplx.langs.htmls.encoders.Gfo_url_encoder_.Id;
|
||||
encoder.Encode(enc_bfr, raw_bfr.Bfr(), 0, raw_bfr.Len());
|
||||
byte[] hdrs_id = enc_bfr.To_bry();
|
||||
Object o = hdrs_hash.Get_by(hdrs_ref.Val_(hdrs_id));
|
||||
|
||||
Reference in New Issue
Block a user