mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.2.1
This commit is contained in:
@@ -34,7 +34,7 @@ public class Xoa_app_ {
|
||||
}
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.11.1.1";
|
||||
public static final String Version = "2.11.2.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys_str;
|
||||
public static String User_agent = "";
|
||||
|
||||
@@ -57,10 +57,6 @@ public class Xoa_app_fxt {
|
||||
((Xoav_wiki_mgr)app.Wiki_mgri()).Add(rv);
|
||||
return rv;
|
||||
}
|
||||
// public static Xow_wiki Make__wiki__view(Xoa_app app, String domain_str) {
|
||||
// byte[] domain_bry = Bry_.new_u8(domain_str);
|
||||
// return app.Wiki_mgri().Get_by_key_or_make_init_y(domain_bry);
|
||||
// }
|
||||
public static Xowe_wiki wiki_nonwmf(Xoae_app app, String key) {
|
||||
Xol_lang_itm lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true);
|
||||
Xol_lang_itm_.Lang_init(lang);
|
||||
@@ -73,7 +69,7 @@ public class Xoa_app_fxt {
|
||||
Xowe_wiki rv = new Xowe_wiki(app, lang, Xow_ns_mgr_.default_(lang.Case_mgr()), Xow_domain_itm_.parse(Bry_.new_u8(key)), wiki_dir);
|
||||
rv.File_mgr().Meta_mgr().Depth_(2); // TEST: written for 2 depth
|
||||
rv.Props().Main_page_(Xoa_page_.Main_page_bry); // TEST: default to Main Page (nothing tests loading Main Page from wiki.gfs)
|
||||
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(true);
|
||||
rv.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__main).Subpages_enabled_(true);
|
||||
app.Wiki_mgr().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
@@ -86,11 +82,11 @@ public class Xoa_app_fxt {
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:c"), Bry_.new_a7("trg:c"));
|
||||
}
|
||||
public static void repo2_(Xoae_app app, Xowe_wiki wiki) {
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
app.File_mgr().Repo_mgr().Set("src:wiki", "mem/http/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:wiki", "mem/xowa/file/en.wikipedia.org/" , wiki.Domain_str()).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:wiki"), Bry_.new_a7("trg:wiki"));
|
||||
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
app.File_mgr().Repo_mgr().Set("src:comm", "mem/http/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2);
|
||||
app.File_mgr().Repo_mgr().Set("trg:comm", "mem/xowa/file/commons.wikimedia.org/" , "commons.wikimedia.org").Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2).Primary_(true);
|
||||
wiki.File_mgr().Repo_mgr().Add_repo(Bry_.new_a7("src:comm"), Bry_.new_a7("trg:comm"));
|
||||
}
|
||||
public static void Init_gui(Xoae_app app, Xowe_wiki wiki) {
|
||||
|
||||
@@ -50,8 +50,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
public int Wik_bgn() {return wik_bgn;}
|
||||
public int Anch_bgn() {return anch_bgn;} // NOTE: anch_bgn is not correct when page has trailing ws; EX: [[A #b]] should have anch_bgn of 3 (1st char after #), but instead it is 2
|
||||
public byte[] Anch_txt() {return anch_bgn == -1 ? Bry_.Empty : Bry_.Mid(full_txt, anch_bgn, full_txt.length);}
|
||||
public byte[] Talk_txt() {return ns.Id_talk() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Subj_txt() {return ns.Id_subj() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Talk_txt() {return ns.Id_is_talk() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Subj_txt() {return ns.Id_is_subj() ? Full_txt() : Bry_.Add(tors_txt, Page_txt());}
|
||||
public byte[] Full_url() {return Xoa_url_encoder.Instance.Encode(full_txt);}
|
||||
public String Full_db_as_str() {return String_.new_u8(Full_db());}
|
||||
public byte[] Full_db() {return ns.Gen_ttl(this.Page_db());}
|
||||
@@ -176,7 +176,7 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
}
|
||||
else {
|
||||
ns = (Xow_ns)o;
|
||||
byte[] ns_name = ns.Name_txt();
|
||||
byte[] ns_name = ns.Name_ui();
|
||||
int ns_name_len = ns_name.length;
|
||||
int tmp_bfr_end = bfr.Len();
|
||||
if (!Bry_.Eq(bfr.Bfr(), ltr_bgn, tmp_bfr_end, ns_name) && ns_name_len == tmp_bfr_end - ltr_bgn) { // if (a) ns_name != bfr_txt (b) both are same length; note that (b) should not happen, but want to safeguard against mismatched arrays
|
||||
@@ -362,8 +362,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
||||
else
|
||||
full_txt = case_mgr.Case_reuse_upper(full_txt, page_bgn, page_end);
|
||||
}
|
||||
Xow_ns tors_ns = ns.Id_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id());
|
||||
tors_txt = tors_ns.Name_txt_w_colon();
|
||||
Xow_ns tors_ns = ns.Id_is_talk() ? ns_mgr.Ords_get_at(ns.Ord_subj_id()) : ns_mgr.Ords_get_at(ns.Ord_talk_id());
|
||||
tors_txt = tors_ns.Name_ui_w_colon();
|
||||
return true;
|
||||
}
|
||||
public static byte[] Replace_spaces(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Space, Byte_ascii.Underline);}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Xoa_url {
|
||||
int wiki_pos = Bry_find_.Find_fwd(raw, Xoh_href_.Bry__wiki, 0, raw_len); // look for /wiki/
|
||||
return wiki_pos == Bry_find_.Not_found ? Bry_find_.Not_found : wiki_pos + Xoh_href_.Bry__wiki.length;
|
||||
}
|
||||
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);}
|
||||
public boolean Eq_page(Xoa_url comp) {return Bry_.Eq(wiki_bry, comp.wiki_bry) && Bry_.Eq(page_bry, comp.page_bry) && this.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no) == comp.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no);}
|
||||
public String To_str() {return String_.new_u8(To_bry(Bool_.Y, Bool_.Y));}
|
||||
public byte[] To_bry_page_w_anch() {
|
||||
byte[] page = page_bry, anch = anch_bry;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Xoa_url_ {
|
||||
public static String Main_page__home_str = gplx.xowa.wikis.domains.Xow_domain_itm_.Str__home + gplx.xowa.htmls.hrefs.Xoh_href_.Str__wiki + gplx.xowa.Xoa_page_.Main_page_str; // EX:home/wiki/Main_Page
|
||||
public static final byte[]
|
||||
Qarg__redirect = Bry_.new_a7("redirect")
|
||||
, Qarg__redirect__yes = Bry_.new_a7("yes")
|
||||
, Qarg__redirect__no = Bry_.new_a7("no")
|
||||
, Qarg__action = Bry_.new_a7("action")
|
||||
, Qarg__action__edit = Bry_.new_a7("edit")
|
||||
;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Xoae_page implements Xoa_page {
|
||||
this.wiki = wiki; this.ttl = ttl;
|
||||
this.lang = wiki.Lang(); // default to wiki.lang; can be override later by wikitext
|
||||
hdr_mgr = new Xow_hdr_mgr(this, Xoa_app_.Utl__encoder_mgr());
|
||||
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_module());
|
||||
redlink_lnki_list = new Xopg_redlink_lnki_list(ttl.Ns().Id_is_module());
|
||||
Ttl_(ttl);
|
||||
} Xoae_page() {} // called by Null
|
||||
public Xow_wiki Wiki() {return wiki;}
|
||||
|
||||
@@ -265,6 +265,7 @@ public class Xop_fxt {
|
||||
Parse_chk(raw_bry, root, expd_ary);
|
||||
}
|
||||
public void Data_create(String ttl_str, String text_str) {Init_page_create(wiki, ttl_str, text_str);}
|
||||
public void Test_parse_page_all_str__esc(String raw, String expd) {Test_parse_page_all_str(raw, Xoh_consts.Escape_apos(expd));}
|
||||
public void Test_parse_page_all_str(String raw, String expd) {
|
||||
String actl = Exec_parse_page_all_as_str(raw);
|
||||
Tfds.Eq_ary_str(String_.SplitLines_nl(expd), String_.SplitLines_nl(actl), raw);
|
||||
@@ -302,6 +303,7 @@ public class Xop_fxt {
|
||||
tst_mgr.Tst_ary("tkns:", expd_ary, actl_ary);
|
||||
tst_Log_check();
|
||||
}
|
||||
public Xop_fxt Test_parse_page_wiki_str__esc(String raw, String expd) {return Test_parse_page_wiki_str(raw, Xoh_consts.Escape_apos(expd));}
|
||||
public Xop_fxt Test_parse_page_wiki_str(String raw, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Exec_parse_page_wiki_as_str(raw), raw);
|
||||
return this;
|
||||
|
||||
@@ -184,7 +184,7 @@ public class Xowe_wiki implements Xow_wiki, GfoInvkAble, GfoEvObj {
|
||||
// init ns_mgr
|
||||
if (lang.Init_by_load()) {
|
||||
if (domain_tid == Xow_domain_tid_.Int__wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
|
||||
ns_mgr.Aliases_add(Xow_ns_.Id_project, Xow_ns_.Ns_name_wikipedia);
|
||||
ns_mgr.Aliases_add(Xow_ns_.Tid__project, Xow_ns_.Alias__wikipedia);
|
||||
}
|
||||
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // NOTE: must be run after lang.Init_by_load b/c lang will reload ns_mgr; DATE:2015-04-17run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
|
||||
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file
|
||||
|
||||
@@ -60,7 +60,7 @@ public class Xowc_xtn_pages implements GfoInvkAble {
|
||||
private int Set_canonical(Xow_ns_mgr ns_mgr, int aliases_added, int id, byte[] name) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(id);
|
||||
if ( ns == null // ns doesn't exist; should throw error;
|
||||
|| !Bry_.Eq(ns.Name_bry(), name) // ns exists, but name doesn't match canonical
|
||||
|| !Bry_.Eq(ns.Name_db(), name) // ns exists, but name doesn't match canonical
|
||||
) {
|
||||
ns_mgr.Aliases_add(id, String_.new_a7(name));
|
||||
++aliases_added;
|
||||
|
||||
@@ -67,13 +67,13 @@ public class Xoa_url_parser__xwiki_tst {
|
||||
@Test public void Xwiki__to_enwiki() { // PURPOSE: handle alias of "wikipedia" and sv.wikipedia.org/wiki/Wikipedia:Main_Page; DATE:2015-07-31
|
||||
Xowe_wiki xwiki = tstr.Prep_create_wiki("sv.wikipedia.org");
|
||||
tstr.Prep_xwiki(xwiki, "wikipedia", "en.wikipedia.org", null);
|
||||
tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Id_project, "Wikipedia");
|
||||
tstr.Prep_get_ns_mgr_from_meta("sv.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Wikipedia");
|
||||
tstr.Run_parse(xwiki, "sv.wikipedia.org/wiki/wikipedia:X").Chk_wiki("sv.wikipedia.org").Chk_page("wikipedia:X");
|
||||
tstr.Run_parse(xwiki, "sv.wikipedia.org/wiki/Wikipedia:X").Chk_wiki("sv.wikipedia.org").Chk_page("Wikipedia:X");
|
||||
}
|
||||
@Test public void Xwiki__to_ns() { // PURPOSE: handle alias of "wikipedia" in current, but no "Wikipedia" ns in other wiki; PAGE:pt.w:Wikipedia:P<>gina_de_testes DATE:2015-09-17
|
||||
tstr.Prep_create_wiki("pt.wikipedia.org");
|
||||
tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Id_project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns
|
||||
tstr.Prep_get_ns_mgr_from_meta("pt.wikipedia.org").Add_new(Xow_ns_.Tid__project, "Project"); // clear ns_mgr and add only "Project" ns, not "Wikipedia" ns
|
||||
tstr.Prep_xwiki(tstr.Wiki(), "wikipedia", "en.wikipedia.org", null); // add alias of "wikipedia" in current wiki
|
||||
tstr.Run_parse(tstr.Wiki(), "pt.wikipedia.org/wiki/Wikipedia:X").Chk_wiki("pt.wikipedia.org").Chk_page("Wikipedia:X"); // should get "pt.wikipedia.org", not "en.wikipedia.org" (through alias)
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class Xob_dump_mgr_base_ {
|
||||
int load_count = 0;
|
||||
usr_dlg.Note_many("", "", "tmpl_load init");
|
||||
while (true) {
|
||||
page_src.Get_pages(pages, 0, Xow_ns_.Id_template, cur_page_id); // 0 is always template db
|
||||
page_src.Get_pages(pages, 0, Xow_ns_.Tid__template, cur_page_id); // 0 is always template db
|
||||
int page_count = pages.Count();
|
||||
if (page_count == 0) break; // no more pages in db;
|
||||
Xowd_page_itm page = null;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Xob_category_registry_sql implements Xob_cmd {
|
||||
wiki.Init_db_mgr();
|
||||
Xowd_page_tbl page_core_tbl = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
|
||||
Db_rdr rdr = page_core_tbl.Conn().Stmt_select_order(page_core_tbl.Tbl_name(), String_.Ary(page_core_tbl.Fld_page_title(), page_core_tbl.Fld_page_id()), String_.Ary(page_core_tbl.Fld_page_ns()), page_core_tbl.Fld_page_title())
|
||||
.Crt_int(page_core_tbl.Fld_page_ns(), Xow_ns_.Id_category)
|
||||
.Crt_int(page_core_tbl.Fld_page_ns(), Xow_ns_.Tid__category)
|
||||
.Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
|
||||
@@ -39,7 +39,7 @@ class Xob_category_registry_sql_fxt {
|
||||
}
|
||||
public void Rls() {fxt.Rls();}
|
||||
public void Init_page_insert(String[] ttls) {
|
||||
fxt.Init_page_insert(page_id_next, Xow_ns_.Id_category, ttls);
|
||||
fxt.Init_page_insert(page_id_next, Xow_ns_.Tid__category, ttls);
|
||||
}
|
||||
public void Exec_category_registry_cmd() {
|
||||
app.Bldr().Cmd_mgr().Add_cmd(wiki, Xob_cmd_keys.Key_text_cat_core);
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class Xob_categorylinks_base extends Xob_sql_dump_base implement
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_timestamp)) {
|
||||
date_parser.Parse_iso8651_like(cur_modified_on, src, fld_bgn, fld_end);
|
||||
cur_date = fld_end - fld_bgn == 0 // ignore null dates added by ctg_v1
|
||||
? 0 : Bit_.Xto_int_date_short(cur_modified_on);
|
||||
? 0 : Int_flag_bldr_.To_int_date_short(cur_modified_on);
|
||||
}
|
||||
else if (Bry_.Eq(fld_key, Fld_cl_sortkey)) {
|
||||
int nl_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl, fld_bgn, fld_end);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Xob_categorylinks_sql_tst {
|
||||
@Test public void Basic() {
|
||||
if (Xoa_test_.Db_skip()) return;
|
||||
fxt.Init_db_sqlite();
|
||||
fxt.Init_page_insert(Int_obj_ref.new_(1), Xow_ns_.Id_category, String_.Ary("Ctg_1", "Ctg_2"));
|
||||
fxt.Init_page_insert(Int_obj_ref.new_(1), Xow_ns_.Tid__category, String_.Ary("Ctg_1", "Ctg_2"));
|
||||
fxt.Init_fil(Xoa_test_.Url_wiki_enwiki().GenSubFil("xowa_categorylinks.sql"), String_.Concat
|
||||
( Xob_categorylinks_sql.Sql_categorylinks
|
||||
, "INSERT INTO `categorylinks` VALUES"
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
|
||||
Xol_lang_itm lang = wiki.Lang();
|
||||
wkr_hooks_add(tmp_bfr, lang.Ns_names());
|
||||
wkr_hooks_add(tmp_bfr, lang.Ns_aliases());
|
||||
wkr_hooks_add(tmp_bfr, Xow_ns_.Canonical);
|
||||
wkr_hooks_add(tmp_bfr, Xow_ns_canonical_.Ary);
|
||||
tmp_bfr.Mkr_rls();
|
||||
fld_wtr.Bfr_(dump_bfr);
|
||||
}
|
||||
@@ -125,14 +125,14 @@ public abstract class Xob_ctg_v1_base extends Xob_itm_dump_base implements Xobd_
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ary[i];
|
||||
if (ns.Id_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_bry());
|
||||
if (ns.Id_is_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_db());
|
||||
}
|
||||
}
|
||||
private void wkr_hooks_add(Bry_bfr tmp_bfr, Xol_ns_grp ns_grp) {
|
||||
int len = ns_grp.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ns_grp.Get_at(i);
|
||||
if (ns.Id_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_bry());
|
||||
if (ns.Id_is_ctg()) wkr_hooks_add(tmp_bfr, ns.Name_db());
|
||||
}
|
||||
}
|
||||
private void wkr_hooks_add(Bry_bfr tmp_bfr, byte[] word) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
public Xob_lnki_temp_wkr(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
@Override public String Cmd_key() {return Xob_cmd_keys.Key_file_lnki_temp;}
|
||||
@Override public byte Init_redirect() {return Bool_.N_byte;} // lnki_temp does not look at redirect pages
|
||||
@Override public int[] Init_ns_ary() {return ns_ids;} private int[] ns_ids = Int_.Ary(Xow_ns_.Id_main);
|
||||
@Override public int[] Init_ns_ary() {return ns_ids;} private int[] ns_ids = Int_.Ary(Xow_ns_.Tid__main);
|
||||
@Override protected void Init_reset(Db_conn conn) {
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
cfg_tbl.Delete_all();
|
||||
@@ -103,7 +103,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
page.Bldr__ns_ord_(ns_ord);
|
||||
page.Ttl_(ttl).Revision_data().Id_(db_page.Id());
|
||||
page.Redlink_lnki_list().Clear();
|
||||
if (ns.Id_tmpl())
|
||||
if (ns.Id_is_tmpl())
|
||||
parser.Parse_text_to_defn_obj(ctx, ctx.Tkn_mkr(), wiki.Ns_mgr().Ns_template(), ttl_bry, page_src);
|
||||
else {
|
||||
parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), page_src);
|
||||
@@ -156,7 +156,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
if ( Xof_lnki_page.Null_n(lnki_page) // page set
|
||||
&& Xof_lnki_time.Null_n(lnki_time)) // thumbtime set
|
||||
usr_dlg.Warn_many("", "", "page and thumbtime both set; this may be an issue with fsdb: page=~{0} ttl=~{1}", ctx.Cur_page().Ttl().Page_db_as_str(), String_.new_u8(ttl));
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_media)
|
||||
if (lnki.Ns_id() == Xow_ns_.Tid__media)
|
||||
lnki_src_tid = Xob_lnki_src_tid.Tid_media;
|
||||
tbl.Insert_cmd_by_batch(ctx.Cur_page().Bldr__ns_ord(), ctx.Cur_page().Revision_data().Id(), ttl, ttl_commons, Byte_.By_int(ext.Id()), lnki.Lnki_type(), lnki_src_tid, lnki.W(), lnki.H(), lnki.Upright(), lnki_time, lnki_page);
|
||||
}
|
||||
@@ -188,7 +188,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xopg_redlink
|
||||
}
|
||||
public static byte[] Xto_commons(boolean ns_file_is_case_match_all, Xowe_wiki commons_wiki, byte[] ttl_bry) {
|
||||
if (!ns_file_is_case_match_all) return null; // return "" if wiki matches common
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(commons_wiki, Xow_ns_.Id_file, ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(commons_wiki, Xow_ns_.Tid__file, ttl_bry);
|
||||
byte[] rv = ttl.Page_db();
|
||||
return Bry_.Eq(rv, ttl_bry) ? null : rv;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class Xob_lnki_temp_wkr_ {
|
||||
int len = aliases.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String alias = aliases[i];
|
||||
if (String_.Eq(alias, Xow_ns_.Key_main))
|
||||
if (String_.Eq(alias, Xow_ns_.Key__main))
|
||||
list.Add(ns_mgr.Ns_main());
|
||||
else {
|
||||
Xow_ns ns = ns_mgr.Names_get_or_null(Bry_.new_u8(alias));
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class Xob_search_base extends Xob_itm_dump_base implements Xobd_
|
||||
ns_main = wiki.Ns_mgr().Ns_main();
|
||||
} private Xob_tmp_wtr_mgr tmp_wtr_mgr; private Xow_ns ns_main;
|
||||
public void Wkr_run(Xowd_page_itm page) {
|
||||
// if (page.Ns_id() != Xow_ns_.Id_main) return; // limit to main ns for now
|
||||
// if (page.Ns_id() != Xow_ns_.Tid__main) return; // limit to main ns for now
|
||||
try {
|
||||
byte[] ttl = page.Ttl_page_db();
|
||||
byte[][] words = Split_ttl_into_words(lang, list, dump_bfr, ttl);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Xob_page_cmd extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
|
||||
if (redirect && redirect_id_enabled)
|
||||
redirect_tbl.Insert(id, page.Ttl_page_db(), redirect_ttl);
|
||||
++page_count_all;
|
||||
if (ns.Id_main() && !page.Redirected()) ++page_count_main;
|
||||
if (ns.Id_is_main() && !page.Redirected()) ++page_count_main;
|
||||
if (page_count_all % commit_interval == 0) {
|
||||
page_core_tbl.Conn().Txn_sav(); text_db.Conn().Txn_sav();
|
||||
if (redirect_id_enabled) redirect_tbl.Conn().Txn_sav();
|
||||
|
||||
@@ -30,8 +30,8 @@ public class Xob_page_cmd_tst {
|
||||
)
|
||||
.Exec_run(new Xob_page_cmd(fxt.Bldr(), fxt.Wiki()))
|
||||
;
|
||||
fxt.Test_load_ttl(Xow_ns_.Id_main, "A", fxt.page_(2, "2013-06-03 01:23", false, 6));
|
||||
fxt.Test_load_page(Xow_ns_.Id_main, 2, "text_a");
|
||||
fxt.Test_load_ttl(Xow_ns_.Id_main, "B", fxt.page_(1, "2013-06-03 12:34", true, 15));
|
||||
fxt.Test_load_ttl(Xow_ns_.Tid__main, "A", fxt.page_(2, "2013-06-03 01:23", false, 6));
|
||||
fxt.Test_load_page(Xow_ns_.Tid__main, 2, "text_a");
|
||||
fxt.Test_load_ttl(Xow_ns_.Tid__main, "B", fxt.page_(1, "2013-06-03 12:34", true, 15));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Xob_page_txt extends Xob_itm_dump_base implements Xobd_wkr, GfoInvk
|
||||
Xob_xdat_file_wtr wtr = regy[i];
|
||||
if (wtr != null) {
|
||||
Xow_ns ns_itm = wiki.Ns_mgr().Ords_get_at(wtr.Ns_ord_idx());
|
||||
Xob_stat_itm datRptItm = data_rpt_typ.GetOrNew(ns_itm.Name_str());
|
||||
Xob_stat_itm datRptItm = data_rpt_typ.GetOrNew(ns_itm.Name_db_str());
|
||||
datRptItm.Tally(wtr.Fil_len(), wtr.Fil_idx());
|
||||
wtr.Flush(bldr.Usr_dlg());
|
||||
wtr.Rls();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xob_parse_dump_templates_cmd extends Xob_itm_dump_base implements X
|
||||
Init_dump(KEY);
|
||||
}
|
||||
public void Wkr_run(Xowd_page_itm page) {
|
||||
if (page.Ns_id() != Xow_ns_.Id_template) return;
|
||||
if (page.Ns_id() != Xow_ns_.Tid__template) return;
|
||||
int id = page.Id(); byte[] title = page.Ttl_page_db(), text = page.Text(); int title_len = title.length, text_len = text.length;
|
||||
if (FixedLen_page + title_len + text_len + dump_bfr.Len() > dump_fil_len) super.Flush_dump();
|
||||
Xotdb_page_itm_.Txt_page_save(dump_bfr, id, page.Modified_on(), title, text, true);
|
||||
|
||||
@@ -32,13 +32,13 @@ public class Xob_search_base_tst {
|
||||
( fxt.doc_wo_date_(2, "A b", "text")
|
||||
, fxt.doc_wo_date_(3, "B a", "text")
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_sttl(Xow_ns_.Id_main, 0)
|
||||
.Fil_expd(fxt.fil_ns_sttl(Xow_ns_.Tid__main, 0)
|
||||
, "!!!!;|!!!!;|"
|
||||
, "a|!!!!#;!!!!%|!!!!$;!!!!%"
|
||||
, "b|!!!!#;!!!!%|!!!!$;!!!!%"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_main, Xotdb_dir_info_.Tid_search_ttl)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__main, Xotdb_dir_info_.Tid_search_ttl)
|
||||
, "0|a|b|2"
|
||||
, ""
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Xob_tst {
|
||||
( fxt.doc_(3, "2012-01-02 13:15", "Title 2a", "text2a\ny")
|
||||
, fxt.doc_(2, "2012-01-02 13:14", "Title 1", "text1\nz")
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Id_main, 0)
|
||||
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Tid__main, 0)
|
||||
, "!!!!@|!!!!>|"
|
||||
, "!!!!$\t#6>K6\tTitle 2a\ttext2a"
|
||||
, "y\t"
|
||||
@@ -35,13 +35,13 @@ public class Xob_tst {
|
||||
, "z\t"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Id_main, 0)
|
||||
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Tid__main, 0)
|
||||
, "!!!!C|!!!!D|"
|
||||
, "!!!!#|!!!!!|!!!!\"|0|!!!!(|Title 1"
|
||||
, "!!!!$|!!!!!|!!!!!|0|!!!!)|Title 2a"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_main, Xotdb_dir_info_.Tid_ttl)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__main, Xotdb_dir_info_.Tid_ttl)
|
||||
, "0|Title 1|Title 2a|2"
|
||||
, ""
|
||||
)
|
||||
@@ -53,19 +53,19 @@ public class Xob_tst {
|
||||
( fxt.doc_(3, "2012-01-02 13:15", "↑", "t2")
|
||||
, fxt.doc_(2, "2012-01-02 13:14", "!", "t1")
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Id_main, 0)
|
||||
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Tid__main, 0)
|
||||
, "!!!!5|!!!!3|"
|
||||
, "!!!!$\t#6>K6\t↑\tt2\t"
|
||||
, "!!!!#\t#6>K5\t!\tt1\t"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Id_main, 0)
|
||||
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Tid__main, 0)
|
||||
, "!!!!=|!!!!?|"
|
||||
, "!!!!#|!!!!!|!!!!\"|0|!!!!#|!"
|
||||
, "!!!!$|!!!!!|!!!!!|0|!!!!#|↑"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_main, Xotdb_dir_info_.Tid_ttl)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__main, Xotdb_dir_info_.Tid_ttl)
|
||||
, "0|!|↑|2"
|
||||
, ""
|
||||
)
|
||||
@@ -76,17 +76,17 @@ public class Xob_tst {
|
||||
fxt.doc_ary_
|
||||
( fxt.doc_(2, "2012-01-02 13:14", "Template:A", "test a")
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Id_template, 0)
|
||||
.Fil_expd(fxt.fil_ns_page(Xow_ns_.Tid__template, 0)
|
||||
, "!!!!7|"
|
||||
, "!!!!#\t#6>K5\tA\ttest a\t"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Id_template, 0)
|
||||
.Fil_expd(fxt.fil_ns_title(Xow_ns_.Tid__template, 0)
|
||||
, "!!!!=|"
|
||||
, "!!!!#|!!!!!|!!!!!|0|!!!!'|A"
|
||||
, ""
|
||||
)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Id_template, Xotdb_dir_info_.Tid_ttl)
|
||||
.Fil_expd(fxt.fil_reg(Xow_ns_.Tid__template, Xotdb_dir_info_.Tid_ttl)
|
||||
, "0|A|A|1"
|
||||
, ""
|
||||
)
|
||||
@@ -175,7 +175,7 @@ public class Xob_tst {
|
||||
Io_mgr.Instance.SaveFilStr(url, raw);
|
||||
Xotdb_page_raw_parser parser = new Xotdb_page_raw_parser();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
parser.Load(Gfo_usr_dlg_.Test(), wiki, new Xow_ns(Xow_ns_.Id_template, Xow_ns_case_.Tid__1st, Bry_.new_a7("Template"), false), new Io_url[] {url}, 1 * Io_mgr.Len_kb);
|
||||
parser.Load(Gfo_usr_dlg_.Test(), wiki, new Xow_ns(Xow_ns_.Tid__template, Xow_ns_case_.Tid__1st, Bry_.new_a7("Template"), false), new Io_url[] {url}, 1 * Io_mgr.Len_kb);
|
||||
List_adp actl = List_adp_.new_();
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
while (parser.Read(page)) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Xob_siteinfo_nde {
|
||||
Xow_ns ns = ns_mgr.Ords_get_at(i);
|
||||
bfr.Add_int_variable(ns.Id()).Add_byte_pipe();
|
||||
bfr.Add_str_u8(Xow_ns_case_.To_str(ns.Case_match())).Add_byte_pipe();
|
||||
bfr.Add(ns.Name_txt()).Add_byte_nl();
|
||||
bfr.Add(ns.Name_ui()).Add_byte_nl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Xob_deploy_zip_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
Log("zipping dir: ~{0}", ns_dir.Raw());
|
||||
String ns_num = ns_dir.NameOnly();
|
||||
Xow_ns ns_itm = wiki.Ns_mgr().Ids_get_or_null(Int_.parse(ns_num));
|
||||
Zip_ns(bldr, ns_dir, type_name, ns_itm.Name_str());
|
||||
Zip_ns(bldr, ns_dir, type_name, ns_itm.Name_db_str());
|
||||
}
|
||||
}
|
||||
private void Zip_ns(Xob_bldr bldr, Io_url root_dir, String type_name, String ns_name) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Xob_redirect_cmd extends Xob_dump_mgr_base {
|
||||
private Xodb_mgr_sql db_mgr; private Xop_redirect_mgr redirect_mgr; private Url_encoder encoder;
|
||||
public Xob_redirect_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); this.Reset_db_y_();}
|
||||
@Override public String Cmd_key() {return Xob_cmd_keys.Key_wiki_redirect;}
|
||||
@Override public int[] Init_ns_ary() {return Int_.Ary(Xow_ns_.Id_file);} // restrict to file ns
|
||||
@Override public int[] Init_ns_ary() {return Int_.Ary(Xow_ns_.Tid__file);} // restrict to file ns
|
||||
@Override public byte Init_redirect() {return Bool_.Y_byte;} // restrict to redirects
|
||||
@Override protected void Init_reset(Db_conn conn) {
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
@@ -43,7 +43,7 @@ public class Xob_redirect_cmd extends Xob_dump_mgr_base {
|
||||
}
|
||||
@Override protected void Cmd_bgn_end() {}
|
||||
@Override public void Exec_pg_itm_hook(int ns_ord, Xow_ns ns, Xowd_page_itm page, byte[] page_src) {
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(page_src, page_src.length);
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(page_src);
|
||||
byte[] redirect_ttl_bry = Xoa_ttl.Replace_spaces(redirect_ttl.Page_db()); // NOTE: spaces can still exist b/c redirect is scraped from #REDIRECT which sometimes has a mix; EX: "A_b c"
|
||||
redirect_ttl_bry = encoder.Decode(redirect_ttl_bry);
|
||||
redirect_tbl.Insert(page.Id(), Xoa_ttl.Replace_spaces(page.Ttl_page_db()), -1, redirect_ttl.Ns().Id(), redirect_ttl_bry, redirect_ttl.Anch_txt(), 1);
|
||||
|
||||
@@ -142,7 +142,7 @@ public class Xoa_css_extractor {
|
||||
return true;
|
||||
} private static final byte[] Ttl_common_css = Bry_.new_a7("Common.css"), Ttl_vector_css = Bry_.new_a7("Vector.css");
|
||||
private boolean Css_wiki_generate_section(Bry_bfr bfr, byte[] ttl) {
|
||||
byte[] page = page_fetcher.Get_by(Xow_ns_.Id_mediawiki, ttl);
|
||||
byte[] page = page_fetcher.Get_by(Xow_ns_.Tid__mediawiki, ttl);
|
||||
if (page == null) return false;
|
||||
if (bfr.Len() != 0) bfr.Add_byte_nl().Add_byte_nl(); // add "\n\n" between sections; !=0 checks against first
|
||||
Css_wiki_section_hdr.Bld_bfr_many(bfr, ttl); // add "/*XOWA:MediaWiki:Common.css*/\n"
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.junit.*; import gplx.core.ios.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoa_css_extractor_wiki_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoa_css_extractor_fxt fxt = new Xoa_css_extractor_fxt();
|
||||
@Test public void Css_wiki_generate() {
|
||||
fxt.Init_page(Xow_ns_.Id_mediawiki, "Common.css" , "css_0");
|
||||
fxt.Init_page(Xow_ns_.Id_mediawiki, "Vector.css" , "css_1");
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "css_0");
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Vector.css" , "css_1");
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:MediaWiki:Common.css*/"
|
||||
@@ -36,7 +36,7 @@ public class Xoa_css_extractor_wiki_tst {
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", "");
|
||||
}
|
||||
@Test public void Css_wiki_tab() { // PURPOSE: swap out 	 for xdat files
|
||||
fxt.Init_page(Xow_ns_.Id_mediawiki, "Common.css" , "a	b");
|
||||
fxt.Init_page(Xow_ns_.Tid__mediawiki, "Common.css" , "a	b");
|
||||
fxt.Exec_css_wiki_setup();
|
||||
fxt.Test_fil("mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/xowa_wiki.css", String_.Concat_lines_nl
|
||||
( "/*XOWA:MediaWiki:Common.css*/"
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Xow_cfg_wiki_core {
|
||||
for (int i = 0; i < nms_len; i++) {
|
||||
Xow_ns ns = wiki.Ns_mgr().Ords_get_at(i);
|
||||
wtr.Bfr().Add_int_variable(ns.Id()).Add_byte_pipe().Add_int_fixed(ns.Case_match(), 1).Add_byte_pipe();
|
||||
csv_parser.Save(wtr.Bfr(), ns.Name_txt());
|
||||
csv_parser.Save(wtr.Bfr(), ns.Name_ui());
|
||||
wtr.Add_nl();
|
||||
}
|
||||
wtr.Add_quote_xtn_end();
|
||||
|
||||
@@ -37,8 +37,8 @@ public class Xow_cfg_wiki_core_tst {
|
||||
, "']:>"
|
||||
, ");"
|
||||
)
|
||||
, fxt.ns_(Xow_ns_.Id_main , true, "")
|
||||
, fxt.ns_(Xow_ns_.Id_project , false, "Wikipedia")
|
||||
, fxt.ns_(Xow_ns_.Tid__main , true, "")
|
||||
, fxt.ns_(Xow_ns_.Tid__project , false, "Wikipedia")
|
||||
);
|
||||
}
|
||||
public static final String Const_wiki_core_cfg = String_.Concat_lines_nl
|
||||
@@ -89,7 +89,7 @@ class Xow_cfg_wiki_core_fxt {
|
||||
}
|
||||
public void Save_tst(String bldr_version, String main_page, String siteinfo_misc, int ns_user_case_match, String ns_user_name, String expd) {
|
||||
wiki.Props().Bldr_version_(Bry_.new_a7(bldr_version)).Main_page_(Bry_.new_a7(main_page)).Siteinfo_misc_(Bry_.new_a7(siteinfo_misc));
|
||||
Xow_ns ns_user = wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Id_user);
|
||||
Xow_ns ns_user = wiki.Ns_mgr().Ids_get_or_null(Xow_ns_.Tid__user);
|
||||
ns_user.Case_match_((byte)ns_user_case_match); ns_user.Name_bry_(Bry_.new_a7(ns_user_name));
|
||||
Tfds.Eq_str_lines(expd, String_.new_a7(wiki.Cfg_wiki_core().Build_gfs()));
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class Xow_cfg_wiki_core_fxt {
|
||||
Xow_ns expd = expd_ary[i];
|
||||
Xow_ns actl = wiki.Ns_mgr().Ids_get_or_null(expd.Id());
|
||||
Tfds.Eq(expd.Case_match(), actl.Case_match(), Int_.To_str(expd.Id()));
|
||||
Tfds.Eq(expd.Name_str(), actl.Name_str(), Int_.To_str(expd.Id()));
|
||||
Tfds.Eq(expd.Name_db_str(), actl.Name_db_str(), Int_.To_str(expd.Id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class Xowm_rev_wkr__meta__wm_tst {
|
||||
@After public void term() {Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;}
|
||||
@Test public void Basic() {
|
||||
Wmapi_itm__pge[] expd = fxt.Make_pge_ary
|
||||
( fxt.Make_pge(Xow_ns_.Id_main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1")
|
||||
, fxt.Make_pge(Xow_ns_.Id_main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2")
|
||||
( fxt.Make_pge(Xow_ns_.Tid__main, "A", 1, 11, 100, "2015-01-01T01:01:01Z", "user1", "note1")
|
||||
, fxt.Make_pge(Xow_ns_.Tid__main, "B", 2, 22, 200, "2015-02-02T02:02:02Z", "user2", "note2")
|
||||
);
|
||||
fxt.Init_inet_upload(expd);
|
||||
fxt.Test_fetch(String_.Ary("A", "B"), expd); // test get both
|
||||
@@ -77,7 +77,7 @@ class Xowm_rev_wkr__meta__wm_fxt {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String ttl_str = ttl_ary[i];
|
||||
byte[] ttl_bry = Bry_.new_u8(ttl_str);
|
||||
rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Id_main, ttl_bry));
|
||||
rev_hash.Add(ttl_bry, new Wmapi_itm__pge().Init_ttl(Xow_ns_.Tid__main, ttl_bry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Xob_xml_dumper {
|
||||
wtr.Atr_kv_int("key" , ns.Id());
|
||||
wtr.Atr_kv_str_a7("case" , Xow_ns_case_.To_str(ns.Case_match()));
|
||||
wtr.Nde_lhs_end();
|
||||
wtr.Txt_bry(ns.Name_bry());
|
||||
wtr.Txt_bry(ns.Name_db());
|
||||
wtr.Nde_rhs();
|
||||
}
|
||||
public void Write_page(Xowd_page_itm page) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Xob_xml_dumper_tst {
|
||||
private final Xob_xml_dumper_fxt fxt = new Xob_xml_dumper_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test_page(fxt.Make_ary(fxt.Make_page(1, Xow_ns_.Id_main, "A", "A_text")), String_.Concat_lines_nl_skip_last
|
||||
fxt.Test_page(fxt.Make_ary(fxt.Make_page(1, Xow_ns_.Tid__main, "A", "A_text")), String_.Concat_lines_nl_skip_last
|
||||
( "<mediawiki xmlns='http://www.mediawiki.org/xml/export-0.10/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd' version='0.10' xml:lang='en'>"
|
||||
, " <siteinfo>"
|
||||
, " <sitename>other</sitename>"
|
||||
|
||||
@@ -85,17 +85,17 @@ public class Xob_xml_parser_tst {
|
||||
}
|
||||
@Test public void Ns_file() {
|
||||
Xowd_page_itm doc = doc_(1, "File:a", "a", Date_1);
|
||||
Tfds.Eq(Xow_ns_.Id_file, doc.Ns_id());
|
||||
Tfds.Eq(Xow_ns_.Tid__file, doc.Ns_id());
|
||||
Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
|
||||
}
|
||||
@Test public void Ns_main() {
|
||||
Xowd_page_itm doc = doc_(1, "a", "a", Date_1);
|
||||
Tfds.Eq(Xow_ns_.Id_main, doc.Ns_id());
|
||||
Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
|
||||
Tfds.Eq("a", String_.new_u8(doc.Ttl_page_db()));
|
||||
}
|
||||
@Test public void Ns_main_book() {
|
||||
Xowd_page_itm doc = doc_(1, "Book", "a", Date_1);
|
||||
Tfds.Eq(Xow_ns_.Id_main, doc.Ns_id());
|
||||
Tfds.Eq(Xow_ns_.Tid__main, doc.Ns_id());
|
||||
Tfds.Eq("Book", String_.new_u8(doc.Ttl_page_db()));
|
||||
}
|
||||
@Test public void XmlEntities() {
|
||||
|
||||
@@ -15,12 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.spaces; 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.parsers.*;
|
||||
public class Xoh_space_parse_tst {
|
||||
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__space(0, 6);
|
||||
fxt.Test__parse(" ");
|
||||
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoa_file_mgr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
public void Clear() {list.Clear();}
|
||||
public boolean Check_cache(Xof_fsdb_itm itm) {
|
||||
return false;
|
||||
}
|
||||
public void Queue_for_viewing(Xof_fsdb_itm itm) {
|
||||
list.Add(itm);
|
||||
}
|
||||
}
|
||||
@@ -148,4 +148,17 @@ public class Xof_fsdb_itm implements Xof_file_itm {
|
||||
file_is_orig = img_size.File_is_orig();
|
||||
}
|
||||
}
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
bfr .Add_int_variable(html_uid);
|
||||
bfr.Add_byte_pipe().Add_int_variable(lnki_exec_tid);
|
||||
bfr.Add_byte_pipe().Add(lnki_wiki_abrv);
|
||||
bfr.Add_byte_pipe().Add_int_variable(lnki_type);
|
||||
bfr.Add_byte_pipe().Add_double(lnki_upright);
|
||||
bfr.Add_byte_pipe().Add_int_variable(lnki_upright_patch);
|
||||
bfr.Add_byte_pipe().Add_int_variable(lnki_w);
|
||||
bfr.Add_byte_pipe().Add_int_variable(lnki_h);
|
||||
bfr.Add_byte_pipe().Add_double(lnki_time);
|
||||
bfr.Add_byte_pipe().Add_int_variable(lnki_page);
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class Xof_file_fxt {
|
||||
itm.Init_at_lnki(arg.Exec_tid(), wiki.Domain_itm().Abrv_xo(), ttl_bry, arg.Lnki_type(), arg.Lnki_upright(), arg.Lnki_w(), arg.Lnki_h(), arg.Lnki_time(), Xof_lnki_page.Null, Xof_patch_upright_tid_.Tid_all);
|
||||
List_adp itms_list = List_adp_.new_(); itms_list.Add(itm);
|
||||
orig_mgr.Find_by_list(Ordered_hash_.New_bry(), itms_list, Xof_exec_tid.Tid_wiki_page);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_main, ttl_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__main, ttl_bry);
|
||||
Xoae_page page = Xoae_page.new_(wiki, ttl);
|
||||
fsdb_mgr.Fsdb_search_by_list(itms_list, wiki, page, Xog_js_wkr_.Noop);
|
||||
if (arg.Rslt_orig_exists() != Bool_.__byte) Tfds.Eq(arg.Rslt_orig_exists() == Bool_.Y_byte, itm.Orig_exists(), "orig_exists");
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Js_img_mgr {
|
||||
String html_id = To_doc_uid(uid);
|
||||
js_wkr.Html_img_update(html_id, html_view_url.To_http_file_str(), html_w, html_h);
|
||||
if (Xop_lnki_type.Id_is_thumbable(lnki_type)) { // thumb needs to set cls and width
|
||||
js_wkr.Html_atr_set(html_id, "class", gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_consts.Str_img_cls_thumbimage);
|
||||
js_wkr.Html_atr_set(html_id, "class", gplx.xowa.htmls.core.wkrs.imgs.atrs.Xoh_img_cls_.Str__thumbimage);
|
||||
js_wkr.Html_atr_set("xowa_file_div_" + uid, "style", "width:" + html_w + "px;");
|
||||
}
|
||||
switch (elem_tid) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class Xofw_wiki_wkr_base implements Xofw_wiki_finder {
|
||||
if (db_page.Redirected()) {
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, file_ns, false);
|
||||
byte[] src = db_page.Text();
|
||||
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src, src.length);
|
||||
Xoa_ttl redirect_ttl = wiki.Redirect_mgr().Extract_redirect(src);
|
||||
return redirect_ttl == Xop_redirect_mgr.Redirect_null_ttl ? Xop_redirect_mgr.Redirect_null_bry : redirect_ttl.Page_db();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Xog_history_mgr {
|
||||
byte[] page = pg.Ttl().Full_url(); // get page_name only (no anchor; no query args)
|
||||
byte[] anch = pg.Url().Anch_bry();
|
||||
byte[] qarg = pg.Url().Qargs_mgr().To_bry();
|
||||
boolean redirect_force = pg.Url().Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes);
|
||||
boolean redirect_force = pg.Url().Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no);
|
||||
String bmk_pos = pg.Html_data().Bmk_pos();
|
||||
if (bmk_pos == null) bmk_pos = Xog_history_itm.Html_doc_pos_toc; // never allow null doc_pos; set to top
|
||||
return new Xog_history_itm(wiki, page, anch, qarg, redirect_force, bmk_pos);
|
||||
|
||||
@@ -151,7 +151,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
if (page.Redirected_ttls().Count() > 0)
|
||||
usr_dlg.Prog_many("", "", "could not find: ~{0} (redirected from ~{1})", String_.new_u8(page.Url().Page_bry()), String_.new_u8((byte[])page.Redirected_ttls().Get_at(0)));
|
||||
else {
|
||||
if (ttl.Ns().Id_file())
|
||||
if (ttl.Ns().Id_is_file())
|
||||
usr_dlg.Prog_one("", "", "commons.wikimedia.org must be installed in order to view the file. See [[Help:Wikis/Commons]]: ~{0}", String_.new_u8(url.Raw()));
|
||||
else
|
||||
usr_dlg.Prog_one("", "", "could not find: ~{0}", String_.new_u8(url.Raw()));
|
||||
|
||||
@@ -82,7 +82,7 @@ public class Xog_tab_itm_edit_mgr {
|
||||
new_text = Xoa_ttl.Replace_spaces(new_text); // ttls cannot have spaces; only underscores
|
||||
Xoa_ttl new_ttl = Xoa_ttl.parse(wiki, new_text);
|
||||
int new_ns_id = new_ttl.Ns().Id();
|
||||
if (new_ns_id != Xow_ns_.Id_main) {
|
||||
if (new_ns_id != Xow_ns_.Tid__main) {
|
||||
win_itm.Usr_dlg().Warn_many("", "", "The new page name must remain in the same namespace");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
Xoae_page cur_page = tab.Page(); Xowe_wiki cur_wiki = tab.Wiki();
|
||||
Xoae_page new_page = tab.History_mgr().Go_by_dir(cur_wiki, fwd);
|
||||
if (new_page.Missing()) return;
|
||||
if (new_page.Ttl().Ns().Id_special()) // if Special, reload page; needed for Special:Search (DATE:2015-04-19; async loading) and Special:XowaBookmarks DATE:2015-10-05
|
||||
if (new_page.Ttl().Ns().Id_is_special()) // if Special, reload page; needed for Special:Search (DATE:2015-04-19; async loading) and Special:XowaBookmarks DATE:2015-10-05
|
||||
new_page = new_page.Wikie().Data_mgr().Load_page_by_ttl(new_page.Url(), new_page.Ttl()); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
|
||||
byte history_nav_type = fwd ? Xog_history_stack.Nav_fwd : Xog_history_stack.Nav_bwd;
|
||||
boolean new_page_is_same = Bry_.Eq(cur_page.Ttl().Full_txt(), new_page.Ttl().Full_txt());
|
||||
|
||||
@@ -53,4 +53,5 @@ public class Xoh_consts {
|
||||
, Atr_xowa_title_bry = Bry_.new_a7(Atr_xowa_title_str)
|
||||
;
|
||||
public static final int Nbsp_int = 160;
|
||||
public static String Escape_apos(String s) {return String_.Replace(s, "'", "\"");}
|
||||
}
|
||||
|
||||
43
400_xowa/src/gplx/xowa/htmls/Xoh_img_mgr.java
Normal file
43
400_xowa/src/gplx/xowa/htmls/Xoh_img_mgr.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_img_mgr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private int uid_nxt = -1;
|
||||
public void Clear() {
|
||||
this.uid_nxt = -1;
|
||||
list.Clear();
|
||||
}
|
||||
public int Len() {return list.Count();}
|
||||
public Xof_fsdb_itm Get_at(int i) {return (Xof_fsdb_itm)list.Get_at(i);}
|
||||
public Xof_fsdb_itm Make_img() {
|
||||
Xof_fsdb_itm itm = new Xof_fsdb_itm();
|
||||
itm.Init_at_hdoc(++uid_nxt, Xof_html_elem.Tid_img);
|
||||
list.Add(itm);
|
||||
return itm;
|
||||
}
|
||||
public void To_bfr(Bry_bfr bfr) {
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_fsdb_itm itm = this.Get_at(i);
|
||||
itm.To_bfr(bfr);
|
||||
}
|
||||
}
|
||||
public static final byte[] Bry__html_uid = Bry_.new_a7("xoimg_");
|
||||
}
|
||||
@@ -28,12 +28,13 @@ public class Xoh_page implements Xoa_page {
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {this.body = v;} private byte[] body;
|
||||
public byte Body_flag() {return body_flag;} private byte body_flag = Byte_.Max_value_127;
|
||||
public Xoh_section_mgr Section_mgr() {return section_mgr;} private final Xoh_section_mgr section_mgr = new Xoh_section_mgr();
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
|
||||
public byte[] Sidebar_div() {return sidebar_div;} private byte[] sidebar_div;
|
||||
public Xoh_section_mgr Section_mgr() {return section_mgr;} private final Xoh_section_mgr section_mgr = new Xoh_section_mgr();
|
||||
public Xoh_img_mgr Img_mgr() {return img_mgr;} private Xoh_img_mgr img_mgr = new Xoh_img_mgr();
|
||||
|
||||
public Ordered_hash Redlink_uids() {return redlink_uids;} private final Ordered_hash redlink_uids = Ordered_hash_.New();
|
||||
public int Img_count() {return img_count;} public void Img_count_(int v) {img_count = v;} private int img_count;
|
||||
public Xohd_img_itm__base[] Img_itms() {return img_itms;} public void Img_itms_(Xohd_img_itm__base[] v) {this.img_itms = v;} private Xohd_img_itm__base[] img_itms = Xohd_img_itm__base.Ary_empty;
|
||||
public Ordered_hash Gallery_itms() {return gallery_itms;} private Ordered_hash gallery_itms = Ordered_hash_.New();
|
||||
public Xopg_module_mgr Head_mgr() {return head_mgr;} private Xopg_module_mgr head_mgr = new Xopg_module_mgr();
|
||||
@@ -66,5 +67,6 @@ public class Xoh_page implements Xoa_page {
|
||||
display_ttl = content_sub = sidebar_div = Bry_.Empty;
|
||||
img_itms = Xohd_img_itm__base.Ary_empty;
|
||||
head_mgr.Clear(); gallery_itms.Clear(); redlink_uids.Clear(); commons_mgr.Clear();
|
||||
section_mgr.Clear(); img_mgr.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,13 +131,13 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
}
|
||||
|
||||
// dump and exit if MediaWiki message;
|
||||
if (ns_id == Xow_ns_.Id_mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
if (ns_id == Xow_ns_.Tid__mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
bfr.Add(Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw));
|
||||
return;
|
||||
}
|
||||
|
||||
// if [[File]], add boilerplate header; note that html is XOWA-generated so does not need to be tidied
|
||||
if (ns_id == Xow_ns_.Id_file) app.Ns_file_page_mgr().Bld_html(wiki, ctx, page, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
|
||||
if (ns_id == Xow_ns_.Tid__file) app.Ns_file_page_mgr().Bld_html(wiki, ctx, page, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
|
||||
|
||||
// get separate bfr; note that bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
|
||||
Bry_bfr tidy_bfr = app.Utl__bfr_mkr().Get_m001();
|
||||
@@ -147,7 +147,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
wiki.Html_mgr().Html_wtr().Write_all(tidy_bfr, page.Wikie().Parser_mgr().Ctx(), hctx, page.Root().Data_mid(), page.Root());
|
||||
|
||||
// if [[Category]], render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
|
||||
if (ns_id == Xow_ns_.Id_category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, tidy_bfr);
|
||||
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, tidy_bfr);
|
||||
|
||||
// tidy html
|
||||
gplx.xowa.htmls.core.htmls.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
|
||||
@@ -180,7 +180,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
tmp_bfr.Clear();
|
||||
}
|
||||
private void Write_body_edit(Bry_bfr bfr, byte[] data_raw, int ns_id, byte page_tid) {
|
||||
if ( ns_id == Xow_ns_.Id_mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
if ( ns_id == Xow_ns_.Tid__mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
&& page_tid == Xow_page_tid.Tid_wikitext
|
||||
)
|
||||
data_raw = Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw);
|
||||
|
||||
@@ -28,8 +28,8 @@ public class Xoh_page_wtr_wkr_ {
|
||||
}
|
||||
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
|
||||
if (display_ttl != null) return display_ttl; // display_ttl explicitly set; use it
|
||||
if (ttl.Ns().Id() == Xow_ns_.Id_special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
|
||||
tmp_bfr.Add(ttl.Ns().Name_txt_w_colon()).Add(ttl.Page_txt_wo_qargs());
|
||||
if (ttl.Ns().Id() == Xow_ns_.Tid__special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
|
||||
tmp_bfr.Add(ttl.Ns().Name_ui_w_colon()).Add(ttl.Page_txt_wo_qargs());
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Xow_hdump_mgr__load {
|
||||
hpg.Init(hpg.Wiki(), hpg.Url(), ttl, tmp_dbpg.Id());
|
||||
if (!html_db.Tbl__html_page().Select_by_page(hpg)) return Load__fail(hpg); // nothing in "html_page" table
|
||||
byte[] src = hzip_mgr.Parse(hpg.Url_bry_safe(), hpg.Body_flag(), hpg.Body());
|
||||
hpg.Body_(make_mgr.Parse(hpg, src));
|
||||
hpg.Body_(make_mgr.Parse(src, hpg, hpg.Wiki()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.imgs.*; import
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xow_hdump_mgr__load_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xohd_hdump_wtr_fxt fxt = new Xohd_hdump_wtr_fxt();
|
||||
@Test public void Stub() {}
|
||||
// @Test public void Image_full() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png));
|
||||
// fxt.Test_write_all
|
||||
@@ -42,68 +43,68 @@ public class Xow_hdump_mgr__load_tst {
|
||||
// , "</div>"
|
||||
// ));
|
||||
// }
|
||||
@Test public void Audio_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer("A.oga", 0, 220, -1, Bool_.N, Xof_ext_.Id_oga));
|
||||
fxt.Test_write_all
|
||||
( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
, " <div id=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer("A.ogv", 0, 0, 0, Bool_.N, Xof_ext_.Id_ogv));
|
||||
fxt.Test_write_all
|
||||
( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
, " <div id=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
, " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div><xowa_play id='0'/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Hiero() {
|
||||
Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(fxt.Fxt());
|
||||
hiero_fxt.Reset();
|
||||
hiero_fxt.Init_hiero_A1_B1();
|
||||
fxt.Test_write_frag("<hiero>A1</hiero>", "src='~{xowa_hiero_dir}hiero_A1.png'");
|
||||
}
|
||||
@Test public void Gallery() {
|
||||
Gallery_mgr_base.File_found_mode = Bool_.__byte;
|
||||
fxt.Test_write_all
|
||||
( "<gallery>File:A.png|A1</gallery>", String_.Concat_lines_nl_skip_last
|
||||
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" xowa_gly_box_max='0'>"
|
||||
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" xowa_gly_box_w='0'>"
|
||||
, " <div xowa_gly_box_w='0'>"
|
||||
, " <div class=\"thumb\" style=\"width: 150px;\">"
|
||||
, " <div xowa_gly_img_pad='0'>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class=\"gallerytext\"><p>A1"
|
||||
, "</p>"
|
||||
, ""
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
));
|
||||
}
|
||||
// @Test public void Audio_thumb() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.oga", 0, 220, -1, Bool_.N, Xof_ext_.Id_oga));
|
||||
// fxt.Test_write_all
|
||||
// ( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class=\"thumb tright\">"
|
||||
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
// , " <div id=\"xowa_media_div\"><xowa_play id='0'/><xowa_info id='0'/>"
|
||||
// , " </div>"
|
||||
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
// , " test_caption"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , "</div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void Video_thumb() {
|
||||
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.ogv", 0, 0, 0, Bool_.N, Xof_ext_.Id_ogv));
|
||||
// fxt.Test_write_all
|
||||
// ( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
// ( "<div class=\"thumb tright\">"
|
||||
// , " <div id=\"xowa_file_div_0\" class=\"thumbinner\" xowa_img_style='0'>"
|
||||
// , " <div id=\"xowa_media_div\">"
|
||||
// , " <div>"
|
||||
// , " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
// , " <img id=\"xowa_file_img_0\" xowa_img='0' alt=\"\" />"
|
||||
// , " </a>"
|
||||
// , " </div><xowa_play id='0'/>"
|
||||
// , " </div>"
|
||||
// , " <div class=\"thumbcaption\"><xowa_mgnf id='0'/>"
|
||||
// , " test_caption"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , "</div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void Hiero() {
|
||||
// Hiero_html_mgr_fxt hiero_fxt = new Hiero_html_mgr_fxt(fxt.Fxt());
|
||||
// hiero_fxt.Reset();
|
||||
// hiero_fxt.Init_hiero_A1_B1();
|
||||
// fxt.Test_write_frag("<hiero>A1</hiero>", "src='~{xowa_hiero_dir}hiero_A1.png'");
|
||||
// }
|
||||
// @Test public void Gallery() {
|
||||
// Gallery_mgr_base.File_found_mode = Bool_.__byte;
|
||||
// fxt.Test_write_all
|
||||
// ( "<gallery>File:A.png|A1</gallery>", String_.Concat_lines_nl_skip_last
|
||||
// ( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" xowa_gly_box_max='0'>"
|
||||
// , " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" xowa_gly_box_w='0'>"
|
||||
// , " <div xowa_gly_box_w='0'>"
|
||||
// , " <div class=\"thumb\" style=\"width: 150px;\">"
|
||||
// , " <div xowa_gly_img_pad='0'>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" xowa_img='0' /></a>"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , " <div class=\"gallerytext\"><p>A1"
|
||||
// , "</p>"
|
||||
// , ""
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , " </li>"
|
||||
// , "</ul>"
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
class Xodb_hdump_mgr__base_fxt {
|
||||
protected Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
|
||||
@@ -81,36 +81,36 @@ interface Page_async_cmd {
|
||||
void Prep();
|
||||
void Exec();
|
||||
}
|
||||
class Page_async_cmd__img implements Page_async_cmd {
|
||||
private Xoh_page hpg;
|
||||
private List_adp missing = List_adp_.new_();
|
||||
public Page_async_cmd__img(Xoh_page hpg) {this.hpg = hpg;}
|
||||
public void Prep() {
|
||||
int len = hpg.Img_count();
|
||||
Xohd_img_itm__base[] ary = hpg.Img_itms();
|
||||
missing.Clear();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xohd_img_itm__base itm = ary[i];
|
||||
boolean exists = Io_mgr.Instance.ExistsFil(itm.Html_view_url());
|
||||
if (!exists) missing.Add(itm);
|
||||
}
|
||||
}
|
||||
public void Exec() {
|
||||
int len = missing.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// Xohd_img_itm__base itm = (Xohd_img_itm__base)missing.Get_at(i);
|
||||
// byte[] bytes = null; //fsdb.Db_get()ttl, file_w,....):
|
||||
// Write file(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
CREATE TABLE xtn_gallery
|
||||
( src_page_id integer NOT NULL
|
||||
, html_uid integer NOT NULL
|
||||
, box_max integer NOT NULL
|
||||
, box_w integer NOT NULL
|
||||
, img_w integer NOT NULL
|
||||
, img_pad integer NOT NULL
|
||||
);
|
||||
*/
|
||||
// class Page_async_cmd__img : Page_async_cmd {
|
||||
// private Xoh_page hpg;
|
||||
// private List_adp missing = List_adp_.new_();
|
||||
// public Page_async_cmd__img(Xoh_page hpg) {this.hpg = hpg;}
|
||||
// public void Prep() {
|
||||
//// int len = hpg.Img_count();
|
||||
//// Xohd_img_itm__base[] ary = hpg.Img_itms();
|
||||
//// missing.Clear();
|
||||
//// for (int i = 0; i < len; ++i) {
|
||||
//// Xohd_img_itm__base itm = ary[i];
|
||||
//// boolean exists = Io_mgr.Instance.ExistsFil(itm.Html_view_url());
|
||||
//// if (!exists) missing.Add(itm);
|
||||
//// }
|
||||
// }
|
||||
// public void Exec() {
|
||||
// int len = missing.Count();
|
||||
// for (int i = 0; i < len; ++i) {
|
||||
//// Xohd_img_itm__base itm = (Xohd_img_itm__base)missing.Get_at(i);
|
||||
//// byte[] bytes = null; //fsdb.Db_get()ttl, file_w,....):
|
||||
//// Write file(bytes);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// /*
|
||||
// CREATE TABLE xtn_gallery
|
||||
// ( src_page_id integer NOT NULL
|
||||
// , html_uid integer NOT NULL
|
||||
// , box_max integer NOT NULL
|
||||
// , box_w integer NOT NULL
|
||||
// , img_w integer NOT NULL
|
||||
// , img_pad integer NOT NULL
|
||||
// );
|
||||
// */
|
||||
|
||||
38
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_decode_ctx.java
Normal file
38
400_xowa/src/gplx/xowa/htmls/core/hzips/Xoh_decode_ctx.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_decode_ctx {
|
||||
private byte[] dir__file;
|
||||
public Xof_url_bldr Url_bldr() {return url_bldr;} private Xof_url_bldr url_bldr = new Xof_url_bldr();
|
||||
public byte[] Dir__root() {return dir__root;} private byte[] dir__root;
|
||||
public byte[] Dir__file__comm() {return dir__file__comm;} private byte[] dir__file__comm;
|
||||
public byte[] Dir__file__wiki() {return dir__file__wiki;} private byte[] dir__file__wiki;
|
||||
public Xow_ttl_parser Ttl_parser() {return ttl_parser;} private Xow_ttl_parser ttl_parser;
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
Xoa_fsys_mgr fsys_mgr = app.Fsys_mgr();
|
||||
this.dir__root = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
this.dir__file = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.dir__file__comm = Bry_.Add(dir__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki) {
|
||||
if (dir__root == null) Init_by_app(wiki.App()); // LAZY INIT
|
||||
this.ttl_parser = wiki;
|
||||
this.dir__file__wiki = Bry_.Add(dir__file, wiki.Domain_bry(), Byte_ascii.Slash_bry);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +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.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
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.escapes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
public class Xoh_hzip_dict_ {
|
||||
public static final byte Escape = Byte_.By_int(27); // SERIALIZED: 27=escape byte
|
||||
public static final byte[] Escape_bry = Bry_.new_ints(27); // SERIALIZED
|
||||
@@ -27,44 +28,40 @@ public class Xoh_hzip_dict_ {
|
||||
, Tid__hdr = 1 + Base85_ascii
|
||||
, Tid__lnke = 2 + Base85_ascii
|
||||
, Tid__lnki = 3 + Base85_ascii
|
||||
, Tid__img = 4 + Base85_ascii
|
||||
, Tid__escape = 84 + Base85_ascii
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__space = Bry_.new_ints(Escape, Tid__space)
|
||||
Bry__escape = Bry_.new_ints(Escape, Tid__escape)
|
||||
, Bry__space = Bry_.new_ints(Escape, Tid__space)
|
||||
, Bry__hdr = Bry_.new_ints(Escape, Tid__hdr)
|
||||
, Bry__lnke = Bry_.new_ints(Escape, Tid__lnke)
|
||||
, Bry__lnki = Bry_.new_ints(Escape, Tid__lnki)
|
||||
, Bry__escape = Bry_.new_ints(Escape, Tid__escape)
|
||||
, Bry__img = Bry_.new_ints(Escape, Tid__img)
|
||||
;
|
||||
public static final String
|
||||
Key__space = "space"
|
||||
Key__escape = "escape"
|
||||
, Key__space = "space"
|
||||
, Key__hdr = "hdr"
|
||||
, Key__lnke = "lnke"
|
||||
, Key__lnki = "lnki"
|
||||
, Key__escape = "escape"
|
||||
, Key__img = "img"
|
||||
;
|
||||
public static Xoh_hzip_wkr To_wkr(byte tid) {
|
||||
switch (tid) {
|
||||
case Tid__escape: return Wkr__escape;
|
||||
case Tid__space: return Wkr__space;
|
||||
case Tid__hdr: return Wkr__hdr;
|
||||
case Tid__lnke: return Wkr__lnke;
|
||||
case Tid__lnki: return Wkr__lnki;
|
||||
case Tid__escape: return Wkr__escape;
|
||||
case Tid__img: return Wkr__img;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_byte(Xoh_html_dict_.Hook__space , Xoh_hzip_dict_.Tid__space) // 4 spaces b/c escape code will be 3 bytes
|
||||
.Add_bry_byte(Xoh_html_dict_.Type__hdr , Xoh_hzip_dict_.Tid__hdr)
|
||||
.Add_bry_byte(Xoh_html_dict_.Hook__lnke , Xoh_hzip_dict_.Tid__lnke)
|
||||
.Add_bry_byte(Xoh_html_dict_.Hook__lnki , Xoh_hzip_dict_.Tid__lnki)
|
||||
.Add_bry_byte(Escape_bry , Xoh_hzip_dict_.Tid__escape)
|
||||
;
|
||||
public static final Xoh_hzip_wkr
|
||||
Wkr__space = new Xoh_space_hzip()
|
||||
, Wkr__hdr = new Xoh_hdr_hzip()
|
||||
, Wkr__lnke = new Xoh_lnke_hzip()
|
||||
, Wkr__lnki = new Xoh_lnki_hzip()
|
||||
, Wkr__escape = new Xoh_escape_hzip()
|
||||
;
|
||||
public static final Xoh_escape_hzip Wkr__escape = new Xoh_escape_hzip();
|
||||
public static final Xoh_space_hzip Wkr__space = new Xoh_space_hzip();
|
||||
public static final Xoh_hdr_hzip Wkr__hdr = new Xoh_hdr_hzip();
|
||||
public static final Xoh_lnke_hzip Wkr__lnke = new Xoh_lnke_hzip();
|
||||
public static final Xoh_lnki_hzip Wkr__lnki = new Xoh_lnki_hzip();
|
||||
public static final Xoh_img_hzip Wkr__img = new Xoh_img_hzip();
|
||||
}
|
||||
|
||||
@@ -18,6 +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.*;
|
||||
import gplx.core.primitives.*; import gplx.core.encoders.*;
|
||||
public class Xoh_hzip_int_ {
|
||||
public static final int Neg_1_adj = 1;
|
||||
public static void Encode(int reqd, Bry_bfr bfr, int val) {
|
||||
int bfr_len = bfr.Len();
|
||||
int len_in_base85 = Base85_.Bry_len(val);
|
||||
|
||||
@@ -18,48 +18,29 @@ 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.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
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.spaces.*; import gplx.xowa.htmls.core.wkrs.escapes.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_hzip_mgr {
|
||||
private final Btrie_slim_mgr trie = Xoh_hzip_dict_.Trie;
|
||||
private final Bry_parser parser = new Bry_parser();
|
||||
public void Encode(Bry_bfr bfr, Xow_ttl_parser ttl_parser, byte[] page_url, byte[] src, Hzip_stat_itm stat_itm) {
|
||||
bfr.Clear(); stat_itm.Clear();
|
||||
((Xoh_lnki_hzip)Xoh_hzip_dict_.To_wkr(Xoh_hzip_dict_.Tid__lnki)).Ttl_parser_(ttl_parser);
|
||||
int pos = 0, add_bgn = -1; int src_len = src.length;
|
||||
parser.Init_src(page_url, src, src_len, 0);
|
||||
while (pos < src_len) {
|
||||
Object o = trie.Match_bgn_w_byte(src[pos], src, pos, src_len);
|
||||
if (o == null) {
|
||||
if (add_bgn == -1) add_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else {
|
||||
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
|
||||
try {
|
||||
Xoh_hzip_wkr wkr = Xoh_hzip_dict_.To_wkr(((Byte_obj_val)o).Val());
|
||||
parser.Init_hook(wkr.Key(), pos, trie.Match_pos());
|
||||
wkr.Encode(bfr, stat_itm, parser, src, pos);
|
||||
pos = parser.Pos();
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e));
|
||||
pos = trie.Match_pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add_bgn != -1) bfr.Add_mid(src, add_bgn, src_len);
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Xoh_hzip_dict_.Escape);
|
||||
private final Xoh_hdoc_wkr__base hdoc_parser = new Xoh_hdoc_wkr__base(new Xoh_hdoc_wkr__hzip());
|
||||
private final Xoh_decode_ctx decode_ctx = new Xoh_decode_ctx();
|
||||
public void Init_by_app(Xoa_app app) {decode_ctx.Init_by_app(app);}
|
||||
public void Encode(Bry_bfr bfr, Xow_wiki wiki, byte[] page_url, byte[] src, Hzip_stat_itm stat_itm) {
|
||||
hdoc_parser.Parse(bfr, wiki, null, page_url, src);
|
||||
}
|
||||
public byte[] Decode(Bry_bfr bfr, Xow_ttl_parser ttl_parser, byte[] page_url, byte[] src) {
|
||||
public byte[] Decode(Bry_bfr bfr, Xow_wiki wiki, byte[] page_url, byte[] src) {
|
||||
bfr.Clear();
|
||||
((gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_hzip)Xoh_hzip_dict_.To_wkr(Xoh_hzip_dict_.Tid__lnki)).Ttl_parser_(wiki);
|
||||
int pos = 0, add_bgn = -1; int src_len = src.length;
|
||||
parser.Init_src(page_url, src, src_len, 0);
|
||||
rdr.Ctor_by_page(page_url, src, src_len);
|
||||
decode_ctx.Init_by_page(wiki);
|
||||
while (pos < src_len) {
|
||||
if (src[pos] == Xoh_hzip_dict_.Escape) {
|
||||
if (add_bgn != -1) {bfr.Add_mid(src, add_bgn, pos); add_bgn = -1;}
|
||||
try {
|
||||
Xoh_hzip_wkr wkr = Xoh_hzip_dict_.To_wkr(src[pos + 1]);
|
||||
parser.Init_hook(wkr.Key(), pos, pos + 2);
|
||||
wkr.Decode(bfr, parser, src, pos);
|
||||
pos = parser.Pos();
|
||||
rdr.Init_by_hook(wkr.Key(), pos, pos + 2);
|
||||
wkr.Decode(bfr, decode_ctx, rdr, src, pos);
|
||||
pos = rdr.Pos();
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", Err_.Message_gplx_log(e));
|
||||
pos += 2;
|
||||
|
||||
@@ -1,71 +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.hzips; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_hzip_mgr_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(Io_mgr.Len_mb); private Xoh_hzip_mgr hzip_mgr; private Xowe_wiki wiki;
|
||||
private Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
public void Clear() {
|
||||
if (hzip_mgr == null) {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
hzip_mgr = wiki.Html__hdump_mgr().Hzip_mgr().Hzip_mgr();
|
||||
wiki.Init_by_wiki();
|
||||
}
|
||||
}
|
||||
public void Init_xwiki(String alias, String domain) {
|
||||
wiki.Appe().Wiki_mgr().Get_by_key_or_make(Bry_.new_u8(domain));
|
||||
wiki.Xwiki_mgr().Add_by_atrs(alias, domain);
|
||||
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_atrs(domain, domain);
|
||||
}
|
||||
public void Test_save(byte[][] expd_brys, String html) {Test_save(html, expd_brys);}
|
||||
public void Test_save(String html, byte[]... expd_brys) {
|
||||
byte[] expd = Bry_.Add(expd_brys);
|
||||
hzip_mgr.Encode(bfr, wiki, Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Tfds.Eq_ary(expd, bfr.To_bry_and_clear());
|
||||
}
|
||||
private final Xoh_page hpg = new Xoh_page();
|
||||
public void Test_swap(String src, String expd) {
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
|
||||
byte[] actl = wiki.Html__hdump_mgr().Load_mgr().Make_mgr().Parse(hpg, Bry_.new_u8(src));
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_load(byte[][] src_brys, String expd) {Test_load(Bry_.Add(src_brys), expd);}
|
||||
public void Test_load(String src, String expd) {Test_load(Bry_.new_u8(src), expd);}
|
||||
public void Test_load(byte[] src, String expd) {
|
||||
byte[] actl = hzip_mgr.Decode(bfr, wiki, Bry_.Empty, src);
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
public void Test_html(String wtxt, String expd) {
|
||||
Xop_ctx ctx = wiki.Parser_mgr().Ctx(); Xop_parser parser = wiki.Parser_mgr().Main(); Xop_tkn_mkr tkn_mkr = ctx.Tkn_mkr();
|
||||
ctx.Para().Enabled_n_();
|
||||
ctx.Cur_page().Redlink_lnki_list().Clear();
|
||||
byte[] html_bry = Bry_.new_u8(wtxt);
|
||||
Xop_root_tkn root = ctx.Tkn_mkr().Root(html_bry);
|
||||
parser.Parse_page_all_clear(root, ctx, tkn_mkr, html_bry);
|
||||
Xoh_wtr_ctx hctx = Xoh_wtr_ctx.Hdump;
|
||||
Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
|
||||
html_wtr.Cfg().Toc__show_(Bool_.Y); // needed for hdr to show <span class='mw-headline' id='A'>
|
||||
html_wtr.Cfg().Lnki__title_(Bool_.N);
|
||||
html_wtr.Cfg().Lnki__id_(Bool_.N);
|
||||
html_wtr.Write_all(bfr, ctx, hctx, html_bry, root);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,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.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public interface Xoh_hzip_wkr {
|
||||
String Key();
|
||||
void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn);
|
||||
int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn);
|
||||
int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr parser, byte[] src, int hook_bgn);
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ public class Hzip_stat_itm {
|
||||
public int Hdr_6() {return hdr_6;} private int hdr_6;
|
||||
public int Space() {return space;} public void Space_add(int v) {space += v;} private int space;
|
||||
public int Escape() {return escape;} public void Escape_add_one() {++escape;} private int escape;
|
||||
public void Hdr_add(byte hdr_num) {
|
||||
public void Hdr_add(int hdr_num) {
|
||||
switch (hdr_num) {
|
||||
case 1: ++hdr_1; break;
|
||||
case 2: ++hdr_2; break;
|
||||
case 3: ++hdr_3; break;
|
||||
case 4: ++hdr_4; break;
|
||||
case 5: ++hdr_5; break;
|
||||
case 6: ++hdr_6; break;
|
||||
case 1: ++hdr_1; break;
|
||||
case 2: ++hdr_2; break;
|
||||
case 3: ++hdr_3; break;
|
||||
case 4: ++hdr_4; break;
|
||||
case 5: ++hdr_5; break;
|
||||
case 6: ++hdr_6; break;
|
||||
default: throw Err_.new_unhandled(hdr_num);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,26 +22,40 @@ public class Xoh_hzip_fxt {
|
||||
private final Xoh_hzip_mgr hzip_mgr;
|
||||
private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
public Xoh_hzip_fxt() {
|
||||
Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
|
||||
parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
|
||||
this.hzip_mgr = parser_fxt.Wiki().Html__hdump_mgr().Hzip_mgr().Hzip_mgr();
|
||||
}
|
||||
public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
public Xoh_hzip_mgr Hzip_mgr() {return hzip_mgr;}
|
||||
public void Test__bicode(String hzip, String html) {
|
||||
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
|
||||
Test__encode__raw(hzip, html);
|
||||
Test__decode__raw(hzip, html);
|
||||
}
|
||||
public void Test__encode(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear());
|
||||
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
|
||||
Test__encode__raw(hzip, html);
|
||||
}
|
||||
public void Test__decode(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
|
||||
byte[] actl = hzip_mgr.Decode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(hzip));
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
Tfds.Eq_str_lines(html, String_.new_u8(actl));
|
||||
hzip = String_.Replace(Xoh_hzip_fxt.Escape(hzip), "'", "\""); html = String_.Replace(html, "'", "\"");
|
||||
Test__decode__raw(hzip, html);
|
||||
}
|
||||
public void Test__bicode(String hzip, String html) {
|
||||
hzip = Xoh_hzip_fxt.Escape(hzip);
|
||||
Test__encode(hzip, html);
|
||||
Test__decode(hzip, html);
|
||||
public void Test__encode__fail(String expd, String html) {
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__encode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
hzip_mgr.Encode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(html), stat_itm);
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(hzip, bfr.To_str_and_clear());
|
||||
}
|
||||
private void Test__decode__raw(String hzip, String html) {
|
||||
Gfo_usr_dlg_.Test__show__init();
|
||||
byte[] actl = hzip_mgr.Decode(bfr, parser_fxt.Wiki(), Bry_.Empty, Bry_.new_u8(hzip));
|
||||
Gfo_usr_dlg_.Test__show__term();
|
||||
Tfds.Eq_str_lines(html, String_.new_u8(actl));
|
||||
}
|
||||
public static String Escape(String v) {return String_.Replace(v, "~", "");}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ package gplx.xowa.htmls.core.makes; import gplx.*; import gplx.xowa.*; import gp
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.xtns.gallery.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.htmls.core.wkrs.*;
|
||||
public class Xoh_make_mgr {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr bry_rdr = new Bry_rdr(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(255), tmp_bfr = Bry_bfr.reset_(255); private final Bry_rdr_old bry_rdr = new Bry_rdr_old(); private Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
|
||||
private Xoh_cfg_file cfg_file; private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2(); private Xoh_file_html_fmtr__base html_fmtr;
|
||||
private final byte[] root_dir, file_dir; private byte[] file_dir_comm, file_dir_wiki, hiero_img_dir; private final byte[] wiki_domain;
|
||||
private final Xoh_hdr_make wkr__hdr = new Xoh_hdr_make();
|
||||
private final Bry_parser parser = new Bry_parser();
|
||||
private final Bry_rdr parser = new Bry_rdr();
|
||||
private final Xoh_hdoc_wkr__base hdoc_parser = new Xoh_hdoc_wkr__base(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) {
|
||||
this.usr_dlg = usr_dlg;
|
||||
this.root_dir = fsys_mgr.Root_dir().To_http_file_bry();
|
||||
@@ -36,7 +36,13 @@ public class Xoh_make_mgr {
|
||||
this.html_fmtr = Xoh_file_html_fmtr__hdump.Base;
|
||||
this.wiki_domain = wiki_domain;
|
||||
}
|
||||
public byte[] Parse(Xoh_page hpg, byte[] src) {
|
||||
public byte[] Parse(byte[] src, Xoh_page hpg, Xow_wiki wiki) {
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
hdoc_parser.Parse(bfr, wiki, hpg, hpg.Url_bry_safe(), src);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Parse_old(Xoh_page hpg, byte[] src) {
|
||||
this.file_dir_comm = tmp_bfr.Add(file_dir).Add(Xow_domain_itm_.Bry__commons).Add_byte_slash().To_bry_and_clear();
|
||||
this.file_dir_wiki = tmp_bfr.Add(file_dir).Add(wiki_domain).Add_byte_slash().To_bry_and_clear();
|
||||
int src_len = src.length;
|
||||
@@ -44,7 +50,7 @@ public class Xoh_make_mgr {
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
Xohd_img_itm__base[] imgs = hpg.Img_itms(); int imgs_len = hpg.Img_itms().length;
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
parser.Init_src(hpg.Url_bry_safe(), src, src_len, 0);
|
||||
parser.Ctor_by_page(hpg.Url_bry_safe(), src, src_len);
|
||||
while (pos < src_len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, src_len);
|
||||
@@ -73,7 +79,6 @@ public class Xoh_make_mgr {
|
||||
switch (tid) {
|
||||
case Xoh_make_trie_.Tid__dir: bfr.Add(root_dir); return rv;
|
||||
case Xoh_make_trie_.Tid__hiero_dir: bfr.Add(hiero_img_dir); return rv;
|
||||
case Xoh_make_trie_.Tid__hdr: return wkr__hdr.Make(bfr, hpg, parser, src, hook_bgn);
|
||||
}
|
||||
if (itm.Elem_is_xnde()) rv += 2; // if xnde, skip "/>"
|
||||
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; hpg=~{0} text=~{1}", hpg.Url().To_str(), Bry_.Mid_safe(src, hook_end, uid_end)); return uid_end;}
|
||||
|
||||
@@ -15,76 +15,77 @@ 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.makes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import org.junit.*;
|
||||
public class Xoh_make_mgr__file__tst {
|
||||
private final Xoh_make_mgr_fxt fxt = new Xoh_make_mgr_fxt();
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_data_img_basic("A.png", 0, 220, 110);
|
||||
}
|
||||
@Test public void Img() {
|
||||
fxt .Init_body("<img xowa_img='0' />")
|
||||
.Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' />");
|
||||
}
|
||||
@Test public void Img_style() {
|
||||
fxt .Init_body("<div xowa_img_style='0'>")
|
||||
.Test_html("<div style='width:220px;'>");
|
||||
}
|
||||
@Test public void File_info() {
|
||||
fxt .Init_body("<xowa_info id='0'/>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/info.png\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_mgnf() {
|
||||
fxt .Init_body("<xowa_mgnf id='0'/>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_play() {
|
||||
fxt .Init_body("<xowa_play id='0'/>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
|
||||
, " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Hiero_dir() {
|
||||
fxt .Init_body("<img src='~{xowa_hiero_dir}hiero_a&A1.png' />")
|
||||
.Test_html("<img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' />");
|
||||
}
|
||||
@Test public void Gallery() {
|
||||
fxt.Clear_imgs();
|
||||
fxt .Init_data_gly(0, 800);
|
||||
fxt .Init_data_img_gly("A.png", 0, 220, 110, 155, 150, 15);
|
||||
fxt .Init_body(String_.Concat_lines_nl_skip_last
|
||||
( "<ul xowa_gly_box_max='0'>"
|
||||
, " <li class='gallerybox' xowa_gly_box_w='0'>"
|
||||
, " <div xowa_gly_box_w='0'>"
|
||||
, " <div class='thumb' xowa_gly_img_w='0'>"
|
||||
, " <div xowa_gly_img_pad='0'>"
|
||||
))
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( "<ul style=\"max-width:800px;_width:800px;\">"
|
||||
, " <li class='gallerybox' style=\"width:155px;\">"
|
||||
, " <div style=\"width:155px;\">"
|
||||
, " <div class='thumb' style=\"width:150px;\">"
|
||||
, " <div style=\"margin:15px auto;\">"
|
||||
));
|
||||
}
|
||||
}
|
||||
//namespace gplx.xowa.htmls.core.makes {
|
||||
// import org.junit.*;
|
||||
// public class Xoh_make_mgr__file__tst {
|
||||
// private final Xoh_make_mgr_fxt fxt = new Xoh_make_mgr_fxt();
|
||||
// @Before public void init() {
|
||||
// fxt.Clear();
|
||||
// fxt.Init_data_img_basic("A.png", 0, 220, 110);
|
||||
// }
|
||||
// @Test public void Img() {
|
||||
// fxt .Init_body("<img xowa_img='0' />")
|
||||
// .Test_html("<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' />");
|
||||
// }
|
||||
// @Test public void Img_style() {
|
||||
// fxt .Init_body("<div xowa_img_style='0'>")
|
||||
// .Test_html("<div style='width:220px;'>");
|
||||
// }
|
||||
// @Test public void File_info() {
|
||||
// fxt .Init_body("<xowa_info id='0'/>")
|
||||
// .Test_html(String_.Concat_lines_nl_skip_last
|
||||
// ( ""
|
||||
// , " <div>"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
|
||||
// , " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/info.png\" width=\"22\" height=\"22\" />"
|
||||
// , " </a>"
|
||||
// , " </div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void File_mgnf() {
|
||||
// fxt .Init_body("<xowa_mgnf id='0'/>")
|
||||
// .Test_html(String_.Concat_lines_nl_skip_last
|
||||
// ( ""
|
||||
// , " <div class=\"magnify\">"
|
||||
// , " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
|
||||
// , " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
// , " </a>"
|
||||
// , " </div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void File_play() {
|
||||
// fxt .Init_body("<xowa_play id='0'/>")
|
||||
// .Test_html(String_.Concat_lines_nl_skip_last
|
||||
// ( ""
|
||||
// , " <div>"
|
||||
// , " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
|
||||
// , " <img src=\"file:///mem/xowa/bin/any/xowa/file/mediawiki.file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
// , " </a>"
|
||||
// , " </div>"
|
||||
// ));
|
||||
// }
|
||||
// @Test public void Hiero_dir() {
|
||||
// fxt .Init_body("<img src='~{xowa_hiero_dir}hiero_a&A1.png' />")
|
||||
// .Test_html("<img src='file:///mem/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_a&A1.png' />");
|
||||
// }
|
||||
// @Test public void Gallery() {
|
||||
// fxt.Clear_imgs();
|
||||
// fxt .Init_data_gly(0, 800);
|
||||
// fxt .Init_data_img_gly("A.png", 0, 220, 110, 155, 150, 15);
|
||||
// fxt .Init_body(String_.Concat_lines_nl_skip_last
|
||||
// ( "<ul xowa_gly_box_max='0'>"
|
||||
// , " <li class='gallerybox' xowa_gly_box_w='0'>"
|
||||
// , " <div xowa_gly_box_w='0'>"
|
||||
// , " <div class='thumb' xowa_gly_img_w='0'>"
|
||||
// , " <div xowa_gly_img_pad='0'>"
|
||||
// ))
|
||||
// .Test_html(String_.Concat_lines_nl_skip_last
|
||||
// ( "<ul style=\"max-width:800px;_width:800px;\">"
|
||||
// , " <li class='gallerybox' style=\"width:155px;\">"
|
||||
// , " <div style=\"width:155px;\">"
|
||||
// , " <div class='thumb' style=\"width:150px;\">"
|
||||
// , " <div style=\"margin:15px auto;\">"
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -61,7 +61,7 @@ class Xoh_make_mgr_fxt {
|
||||
}
|
||||
public Xoh_make_mgr_fxt Test_html(String expd) {
|
||||
if (img_list.Count() > 0) hpg.Img_itms_((Xohd_img_itm__base[])img_list.To_ary_and_clear(Xohd_img_itm__base.class));
|
||||
byte[] actl = hswap_mgr.Parse(hpg, hpg.Body());
|
||||
byte[] actl = hswap_mgr.Parse(hpg.Body(), hpg, wiki);
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ public class Xoh_make_trie_ {
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__dir = Bry_.new_a7("~{xowa_dir}")
|
||||
, Bry__img = Bry_.new_a7("xowa_img='")
|
||||
, Bry__img_style = Bry_.new_a7("xowa_img_style='")
|
||||
, Bry__img = Bry_.new_a7("xowa_img=\"")
|
||||
, Bry__img_style = Bry_.new_a7("xowa_img_style=\"")
|
||||
, Bry__file_play = Bry_.new_a7("<xowa_play id='")
|
||||
, Bry__file_info = Bry_.new_a7("<xowa_info id='")
|
||||
, Bry__file_mgnf = Bry_.new_a7("<xowa_mgnf 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='")
|
||||
@@ -44,7 +44,6 @@ public class Xoh_make_trie_ {
|
||||
;
|
||||
public static Btrie_slim_mgr new_trie() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.cs();
|
||||
trie_itm(rv, Tid__hdr , Byte_ascii.Escape , Xoh_html_dict_.Type__hdr);
|
||||
trie_itm(rv, Tid__dir , Byte_ascii.Escape , Bry__dir);
|
||||
trie_itm(rv, Tid__img , Byte_ascii.Apos , Bry__img);
|
||||
trie_itm(rv, Tid__img_style , Byte_ascii.Apos , Bry__img_style);
|
||||
|
||||
@@ -73,7 +73,7 @@ public abstract class Xohd_img_itm__base implements Xohd_img_itm {
|
||||
, Int_.To_str(orig_repo_id), Int_.To_str(orig_ext), Yn.To_str(file_is_orig), Int_.To_str(file_w), Double_.To_str(lnki_time), Int_.To_str(lnki_page)
|
||||
);
|
||||
}
|
||||
@gplx.Virtual public void Data_parse(Bry_rdr rdr) {
|
||||
@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.orig_ext = rdr.Read_int_to_pipe();
|
||||
this.lnki_type = rdr.Read_byte_to_pipe();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Xohd_img_itm__gallery_itm extends Xohd_img_itm__base {
|
||||
.Add_int_variable(img_pad).Add_byte_pipe()
|
||||
;
|
||||
}
|
||||
@Override public void Data_parse(Bry_rdr rdr) {
|
||||
@Override public void Data_parse(Bry_rdr_old rdr) {
|
||||
super.Data_parse(rdr);
|
||||
this.box_w = rdr.Read_int_to_pipe();
|
||||
this.img_w = rdr.Read_int_to_pipe();
|
||||
|
||||
@@ -19,19 +19,33 @@ package gplx.xowa.htmls.core.makes.tests; import gplx.*; import gplx.xowa.*; imp
|
||||
import gplx.xowa.htmls.sections.*;
|
||||
public class Xoh_make_fxt {
|
||||
public Xoh_make_fxt() {
|
||||
Xoa_app_fxt.repo2_(parser_fxt.App(), parser_fxt.Wiki()); // needed else will be old "mem/wiki/repo/trg/thumb/" instead of standard "mem/file/en.wikipedia.org/thumb/"
|
||||
parser_fxt.Wiki().Html__hdump_mgr().Init_by_db(parser_fxt.Wiki());
|
||||
parser_fxt.Wiki().Html_mgr().Html_wtr().Cfg().Lnki__id_(Bool_.Y).Lnki__title_(Bool_.Y);
|
||||
}
|
||||
public void Clear() {parser_fxt.Reset();}
|
||||
public void Clear() {
|
||||
parser_fxt.Reset();
|
||||
page_chkr.Clear();
|
||||
}
|
||||
public Xoh_page_chkr Page_chkr() {return page_chkr;} private final Xoh_page_chkr page_chkr = new Xoh_page_chkr();
|
||||
public Xop_fxt Parser_fxt() {return parser_fxt;} private final Xop_fxt parser_fxt = new Xop_fxt();
|
||||
public void Init_img_cache
|
||||
( String wiki_abrv, String lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page
|
||||
, boolean repo_is_commons, String html_ttl, int html_w, int html_h, double html_time, int html_page
|
||||
) {
|
||||
// fxt.Init_cache("en.wikipedia.org", "A.png", 0, 220, 110, 0.5, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1);
|
||||
}
|
||||
public void Test__html(String wtxt, String expd) {
|
||||
expd = String_.Replace(expd, "'", "\"");
|
||||
Tfds.Eq_str_lines(expd, parser_fxt.Exec__parse_to_hdump(wtxt));
|
||||
}
|
||||
public void Test__make(String html, Xoh_page_chkr chkr) {
|
||||
html = String_.Replace(html, "'", "\"");
|
||||
Xoh_page actl = new Xoh_page();
|
||||
actl.Init(parser_fxt.Wiki(), Xoa_url.blank(), parser_fxt.Wiki().Ttl_parse(Xoa_page_.Main_page_bry), 1);
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Test_console();
|
||||
byte[] actl_body = parser_fxt.Wiki().Html__hdump_mgr().Load_mgr().Make_mgr().Parse(actl, Bry_.new_u8(html));
|
||||
Xoh_make_mgr make_mgr = parser_fxt.Wiki().Html__hdump_mgr().Load_mgr().Make_mgr();
|
||||
byte[] actl_body = make_mgr.Parse(Bry_.new_u8(html), actl, parser_fxt.Wiki());
|
||||
actl.Body_(actl_body);
|
||||
Gfo_usr_dlg_.Instance = Gfo_usr_dlg_.Noop;
|
||||
chkr.Check(actl);
|
||||
|
||||
@@ -17,21 +17,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.makes.tests; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.makes.*;
|
||||
import gplx.xowa.htmls.sections.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_page_chkr {
|
||||
private final Xoh_section_mgr expd_section_mgr = new Xoh_section_mgr();
|
||||
private final Xoh_img_mgr expd_img_mgr = new Xoh_img_mgr();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
public Xoh_page_chkr Body_(String v) {this.expd_body = v; return this;} private String expd_body;
|
||||
public void Clear() {
|
||||
expd_img_mgr.Clear();
|
||||
}
|
||||
public Xoh_page_chkr Body_(String v) {this.expd_body = String_.Replace(v, "'", "\""); return this;} private String expd_body;
|
||||
public Xoh_page_chkr Sections__add(int uid, int level, String anchor, String display, String content) {
|
||||
expd_section_mgr.Add(uid, level, Bry_.new_u8(anchor), Bry_.new_u8(display)).Content_(Bry_.new_u8(content));
|
||||
return this;
|
||||
}
|
||||
public Xoh_page_chkr Imgs__add(String wiki_abrv, String lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page) {
|
||||
Xof_fsdb_itm fsdb_itm = expd_img_mgr.Make_img();
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, Bry_.new_u8(wiki_abrv), Bry_.new_u8(lnki_ttl), lnki_type, lnki_upright, lnki_w, lnki_h, lnki_time, lnki_page, Xof_patch_upright_tid_.Tid_all);
|
||||
return this;
|
||||
}
|
||||
public void Check(Xoh_page actl) {
|
||||
if (expd_body != null) Tfds.Eq_str_lines(expd_body, String_.new_u8(actl.Body()));
|
||||
if (expd_section_mgr.Len() > 0)
|
||||
Tfds.Eq_str_lines(To_str__section_mgr(expd_section_mgr), To_str__section_mgr(actl.Section_mgr()));
|
||||
if (expd_img_mgr.Len() > 0)
|
||||
Tfds.Eq_str_lines(To_str__img_mgr(expd_img_mgr), To_str__img_mgr(actl.Img_mgr()));
|
||||
}
|
||||
private String To_str__section_mgr(Xoh_section_mgr expd_section_mgr) {
|
||||
expd_section_mgr.To_bfr(bfr);
|
||||
private String To_str__section_mgr(Xoh_section_mgr section_mgr) {
|
||||
section_mgr.To_bfr(bfr);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private String To_str__img_mgr(Xoh_img_mgr img_mgr) {
|
||||
img_mgr.To_bfr(bfr);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.btries.*; import gplx.core.primitives.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
class Xoh_doc_wkr__tag implements Html_doc_wkr {
|
||||
private final Html_tag_rdr rdr = new Html_tag_rdr();
|
||||
private byte[] src; private Xoh_wkr wkr;
|
||||
private final Xoh_lnki_parse wkr__lnki = new Xoh_lnki_parse();
|
||||
private final Xoh_lnke_parse wkr__lnke = new Xoh_lnke_parse();
|
||||
private final Xoh_hdr_parse wkr__hdr = new Xoh_hdr_parse();
|
||||
private Xow_ttl_parser ttl_parser;
|
||||
public byte[] Hook() {return Byte_ascii.Angle_bgn_bry;}
|
||||
public Xoh_doc_wkr__tag(Xoh_wkr wkr, Xow_ttl_parser ttl_parser) {
|
||||
this.wkr = wkr; this.ttl_parser = ttl_parser;
|
||||
}
|
||||
public void Init(byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src;
|
||||
rdr.Init(src, src_bgn, src_end);
|
||||
}
|
||||
public int Parse(int pos) {
|
||||
rdr.Pos_(pos);
|
||||
Html_tag cur = rdr.Tag__move_fwd_head();
|
||||
int cur_name_id = cur.Name_id();
|
||||
switch (cur_name_id) {
|
||||
case Html_tag_.Id__h2:
|
||||
case Html_tag_.Id__h3:
|
||||
case Html_tag_.Id__h4:
|
||||
case Html_tag_.Id__h5:
|
||||
case Html_tag_.Id__h6:
|
||||
int hdr_tag_bgn = cur.Src_bgn();
|
||||
Html_tag nxt = rdr.Tag__peek_fwd_head();
|
||||
if ( nxt.Name_id() == Html_tag_.Id__span
|
||||
&& nxt.Atrs__match_pair(Html_atr_.Bry__class , Atr__class__mw_headline)) {
|
||||
return wkr__hdr.Parse(wkr, rdr, src, cur_name_id, hdr_tag_bgn, nxt);
|
||||
}
|
||||
break;
|
||||
case Html_tag_.Id__a:
|
||||
if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Atr__rel__nofollow))
|
||||
return wkr__lnke.Parse(wkr, rdr, src, cur);
|
||||
else if (cur.Atrs__match_pair(Html_atr_.Bry__class , Atr__class__image)) {
|
||||
// <a href="/wiki/File:A.png" class="image"><img alt="A" src="//upload.wikimedia.org/wikipedia/commons/thumb/7/70/A.png/220px-A.svg.png" width="220" height="149" /></a>
|
||||
}
|
||||
else
|
||||
return wkr__lnki.Parse(wkr, rdr, src, cur, ttl_parser);
|
||||
break;
|
||||
}
|
||||
return cur.Src_end();
|
||||
}
|
||||
private static final byte[]
|
||||
Atr__class__mw_headline = Bry_.new_a7("mw-headline")
|
||||
, Atr__class__image = Bry_.new_a7("image")
|
||||
, Atr__rel__nofollow = Bry_.new_a7("nofollow")
|
||||
;
|
||||
}
|
||||
@@ -1,100 +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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_parser_fxt {
|
||||
private final Html_doc_parser parser;
|
||||
private final Xoh_wkr__test actl_wkr = new Xoh_wkr__test(), expd_wkr = new Xoh_wkr__test();
|
||||
public Xoh_parser_fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.app_();
|
||||
this.wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
parser = Xoh_parser_.new_(actl_wkr, wiki);
|
||||
}
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public void Test__parse(String src_str) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
parser.Parse(src_bry, 0, src_bry.length);
|
||||
Tfds.Eq_ary_str(expd_wkr.To_ary(), actl_wkr.To_ary());
|
||||
}
|
||||
public void Init__hdr(int rng_bgn, int rng_end, int level, String id, String caption, boolean id_caption_related) {
|
||||
expd_wkr.On_hdr(rng_bgn, rng_end, level, Bry_.new_u8(id), Bry_.new_u8(caption), id_caption_related);
|
||||
}
|
||||
public void Init__lnke(int rng_bgn, int rng_end, byte lnke_type, int autonumber_id, String href) {
|
||||
expd_wkr.On_lnke(rng_bgn, rng_end, lnke_type, autonumber_id, Bry_.new_u8(href));
|
||||
}
|
||||
public void Init__lnki(int rng_bgn, int rng_end, byte lnki_type, int site_bgn, int site_end, String page_str, String capt_str, String trail_str) {
|
||||
expd_wkr.On_lnki(rng_bgn, rng_end, lnki_type, site_bgn, site_end, Bry_.new_u8(page_str), Bry_.new_u8(capt_str), Bry_.new_u8(trail_str));
|
||||
}
|
||||
public void Init__escape(int rng_bgn, int rng_end) {
|
||||
expd_wkr.On_escape(rng_bgn, rng_end);
|
||||
}
|
||||
public void Init__space(int rng_bgn, int rng_end) {
|
||||
expd_wkr.On_space(rng_bgn, rng_end);
|
||||
}
|
||||
public void Init__txt(int rng_bgn, int rng_end) {
|
||||
expd_wkr.On_txt(rng_bgn, rng_end);
|
||||
}
|
||||
}
|
||||
class Xoh_wkr__test implements Xoh_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
public void On_hdr(int rng_bgn, int rng_end, int level, byte[] id, byte[] caption, boolean id_caption_related) {
|
||||
bfr.Add_int_variable(rng_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(rng_end).Add_byte_pipe();
|
||||
bfr.Add_int_variable(level).Add_byte_pipe();
|
||||
bfr.Add_safe(id).Add_byte_pipe();
|
||||
bfr.Add(caption).Add_byte_pipe();
|
||||
bfr.Add_bool(id_caption_related);
|
||||
list.Add(bfr.To_str_and_clear());
|
||||
}
|
||||
public void On_lnke(int rng_bgn, int rng_end, byte lnke_type, int autonumber_id, byte[] href) {
|
||||
bfr.Add_int_variable(rng_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(rng_end).Add_byte_pipe();
|
||||
bfr.Add_int_variable(lnke_type).Add_byte_pipe();
|
||||
bfr.Add_int_variable(autonumber_id).Add_byte_pipe();
|
||||
bfr.Add(href);
|
||||
list.Add(bfr.To_str_and_clear());
|
||||
}
|
||||
public void On_lnki(int rng_bgn, int rng_end, byte lnki_type, int site_bgn, int site_end, byte[] page_bry, byte[] capt_bry, byte[] trail_bry) {
|
||||
bfr.Add_int_variable(rng_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(rng_end).Add_byte_pipe();
|
||||
bfr.Add_byte(lnki_type).Add_byte_pipe();
|
||||
bfr.Add_int_variable(site_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(site_end).Add_byte_pipe();
|
||||
bfr.Add_safe(page_bry).Add_byte_pipe();
|
||||
bfr.Add_safe(capt_bry).Add_byte_pipe();
|
||||
bfr.Add_safe(trail_bry).Add_byte_pipe();
|
||||
list.Add(bfr.To_str_and_clear());
|
||||
}
|
||||
public void On_escape(int rng_bgn, int rng_end) {
|
||||
bfr.Add_int_variable(rng_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(rng_end).Add_byte_pipe();
|
||||
list.Add(bfr.To_str_and_clear());
|
||||
}
|
||||
public void On_space(int rng_bgn, int rng_end) {
|
||||
bfr.Add_int_variable(rng_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(rng_end).Add_byte_pipe();
|
||||
list.Add(bfr.To_str_and_clear());
|
||||
}
|
||||
public void On_txt(int rng_bgn, int rng_end) {
|
||||
bfr.Add_int_variable(rng_bgn).Add_byte_pipe();
|
||||
bfr.Add_int_variable(rng_end).Add_byte_pipe();
|
||||
list.Add(bfr.To_str_and_clear());
|
||||
}
|
||||
public String[] To_ary() {return list.To_str_ary_and_clear();}
|
||||
}
|
||||
@@ -1,32 +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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.htmls.core.wkrs.lnkes.*;
|
||||
class Xoh_wkr__hzip implements Xoh_wkr {
|
||||
// private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
// private final Xoh_lnke_hzip wkr__lnke = new Xoh_lnke_hzip();
|
||||
// private byte[] src = null;
|
||||
public void On_hdr (int tag_bgn, int tag_end, int level, byte[] id, byte[] caption, boolean id_caption_related) {}
|
||||
public void On_lnke (int tag_bgn, int tag_end, byte lnke_type, int autonumber_id, byte[] href) {
|
||||
// wkr__lnke.Encode_exec(bfr, src, tag_bgn, tag_end, lnke_type, href, autonumber_id);
|
||||
}
|
||||
public void On_lnki (int tag_bgn, int tag_end, byte lnki_type, int site_bgn, int site_end, byte[] page_bry, byte[] capt_bry, byte[] trail_bry) {}
|
||||
public void On_escape (int rng_bgn, int rng_end) {}
|
||||
public void On_space (int rng_bgn, int rng_end) {}
|
||||
public void On_txt (int rng_bgn, int rng_end) {}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
// using gplx.xowa.wikis.dbs; using gplx.xowa.wikis.pages; using gplx.xowa.htmls.core.makes.imgs; using gplx.xowa.wikis.pages.skins;
|
||||
// using gplx.xowa.wikis.data; using gplx.xowa.wikis.data.tbls; using gplx.xowa.guis;
|
||||
// public class Xohd_page_html_mgr__load {
|
||||
// private final Bry_rdr rdr = new Bry_rdr(); private final List_adp rows = List_adp_.new_(), imgs = List_adp_.new_();
|
||||
// private final Bry_rdr_old rdr = new Bry_rdr_old(); private final List_adp rows = List_adp_.new_(), imgs = List_adp_.new_();
|
||||
// public void Load_page(Xow_wiki wiki, Xoh_page hpg, Xowd_html_tbl tbl, int page_id, Xoa_ttl page_ttl) {
|
||||
// Xoa_app_.Usr_dlg().Plog_many("", "", "hdump.load.text: ttl=~{0}", page_ttl.Full_db_as_str());
|
||||
// tbl.Select_by_page(rows, page_id);
|
||||
@@ -52,7 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
// }
|
||||
// if (imgs.Count() > 0) hpg.Img_itms_((Xohd_img_itm__base[])imgs.To_ary_and_clear(typeof(Xohd_img_itm__base)));
|
||||
// }
|
||||
// public static Xohd_img_itm__base Load_img(Bry_rdr rdr) {
|
||||
// public static Xohd_img_itm__base Load_img(Bry_rdr_old rdr) {
|
||||
// int tid = rdr.Read_int_to_pipe();
|
||||
// Xohd_img_itm__base img_itm = null;
|
||||
// switch (tid) {
|
||||
|
||||
@@ -15,14 +15,11 @@ 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; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
public class Xoh_html_dict_ {
|
||||
public static final byte[]
|
||||
Type__hdr = Bry_.new_a7(" data-xotype='hdr_bgn'")
|
||||
, Hook__space = Bry_.new_a7(" ")
|
||||
, Hook__lnke = Bry_.new_a7("<a data-xotype='lnke")
|
||||
, Hook__lnki = Bry_.new_a7("<a data-xotype='lnki")
|
||||
, Hdr__end = Bry_.new_a7("<!--xo.hdr-->")
|
||||
, Rng__bgn = Bry_.new_a7("<!--xo.rng.")
|
||||
;
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoh_hdoc_ctx {
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
public void Ctor(Xow_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,18 @@ 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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
public interface Xoh_wkr {
|
||||
void On_hdr (int tag_bgn, int tag_end, int level, byte[] id, byte[] caption, boolean id_caption_related);
|
||||
void On_lnke (int tag_bgn, int tag_end, byte lnke_type, int autonumber_id, byte[] href);
|
||||
void On_lnki (int tag_bgn, int tag_end, byte lnki_type, int site_bgn, int site_end, byte[] page_bry, byte[] capt_bry, byte[] trail_bry);
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public interface Xoh_hdoc_wkr {
|
||||
Xoh_hdoc_ctx Ctx();
|
||||
void On_new_page(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src, int src_bgn, int src_end);
|
||||
void On_escape (int rng_bgn, int rng_end);
|
||||
void On_space (int rng_bgn, int rng_end);
|
||||
void On_txt (int rng_bgn, int rng_end);
|
||||
void On_space (int rng_bgn, int rng_end);
|
||||
void On_hdr (int tag_bgn, int tag_end, int level, int capt_bgn, int capt_end, byte[] anch);
|
||||
void On_lnke (int tag_bgn, int tag_end, byte lnke_type, int autonumber_id, int href_bgn, int href_end);
|
||||
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_img_thm (int rng_bgn, int rng_end);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.wkrs.tags.*; import gplx.xowa.htmls.core.wkrs.txts.*; import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*;
|
||||
public class Xoh_hdoc_wkr__base {
|
||||
private final Html_doc_parser hdoc_parser = new Html_doc_parser();
|
||||
private final Xoh_hdoc_wkr hdoc_wkr;
|
||||
private final Xoh_doc_wkr__tag wkr__tag = new Xoh_doc_wkr__tag();
|
||||
public Xoh_hdoc_wkr__base(Xoh_hdoc_wkr hdoc_wkr) {
|
||||
this.hdoc_wkr = hdoc_wkr;
|
||||
this.hdoc_parser.Reg_txt(new Xoh_txt_parser(hdoc_wkr)).Reg_wkrs
|
||||
( wkr__tag
|
||||
, new Xoh_escape_parser(hdoc_wkr)
|
||||
, new Xoh_space_parser(hdoc_wkr)
|
||||
);
|
||||
}
|
||||
public void Parse(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] page_url, byte[] src) {
|
||||
int src_len = src.length;
|
||||
hdoc_wkr.On_new_page(bfr, wiki, hpg, src, 0, src_len);
|
||||
wkr__tag.Ctor(hdoc_wkr, wiki).Init(src, 0, src_len);
|
||||
hdoc_parser.Parse(src, 0, src_len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_hdoc_wkr__hzip implements Xoh_hdoc_wkr {
|
||||
private final Hzip_stat_itm stat_itm = new Hzip_stat_itm();
|
||||
private Bry_bfr bfr; private byte[] src; private int src_end;
|
||||
public Xoh_hdoc_ctx Ctx() {return ctx;} private final Xoh_hdoc_ctx ctx = new Xoh_hdoc_ctx();
|
||||
public void On_new_page(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.src = src; this.src_end = src_end;
|
||||
ctx.Ctor(wiki);
|
||||
stat_itm.Clear();
|
||||
}
|
||||
public void On_hdr (int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
Xoh_hzip_dict_.Wkr__hdr.Encode(bfr, stat_itm, src, rng_bgn, rng_end, level, capt_bgn, capt_end, anch);
|
||||
}
|
||||
public void On_lnke (int rng_bgn, int rng_end, byte lnke_type, int autonumber_id, int href_bgn, int href_end) {
|
||||
Xoh_hzip_dict_.Wkr__lnke.Encode(bfr, stat_itm, src, rng_bgn, rng_end, lnke_type, href_bgn, href_end, autonumber_id);
|
||||
}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {
|
||||
Xoh_hzip_dict_.Wkr__lnki.Encode(bfr, stat_itm, src, arg);
|
||||
}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {
|
||||
Xoh_hzip_dict_.Wkr__img.Encode(bfr, stat_itm, src, arg);
|
||||
}
|
||||
public void On_img_thm (int rng_bgn, int rng_end) {}//wkr__img_thm.Encode(bfr, stat_itm, src, rng_bgn, rng_end);}
|
||||
public void On_escape (int rng_bgn, int rng_end) {Xoh_hzip_dict_.Wkr__escape.Encode(bfr, stat_itm);}
|
||||
public void On_space (int rng_bgn, int rng_end) {Xoh_hzip_dict_.Wkr__space.Encode(bfr, stat_itm, src, src_end, rng_bgn, rng_end);}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.wikis.ttls.*;
|
||||
import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
public class Xoh_hdoc_wkr__make implements Xoh_hdoc_wkr {
|
||||
private final Xoh_hdr_make wkr__hdr = new Xoh_hdr_make();
|
||||
private final Xoh_img_make wkr__img = new Xoh_img_make();
|
||||
private Bry_bfr bfr; private Xoh_page hpg; private byte[] src;
|
||||
public Xoh_hdoc_ctx Ctx() {return ctx;} private final Xoh_hdoc_ctx ctx = new Xoh_hdoc_ctx();
|
||||
public void On_new_page(Bry_bfr bfr, Xow_wiki wiki, Xoh_page hpg, byte[] src, int src_bgn, int src_end) {
|
||||
this.bfr = bfr; this.src = src; this.hpg = hpg;
|
||||
ctx.Ctor(wiki);
|
||||
}
|
||||
public void On_escape (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_txt (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_space (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_hdr (int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
wkr__hdr.Make(bfr, hpg, src, rng_bgn, rng_end, level, capt_bgn, capt_end, anch);
|
||||
}
|
||||
public void On_lnke (int rng_bgn, int rng_end, byte lnke_type, int autonumber_id, int href_bgn, int href_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
public void On_lnki (gplx.xowa.htmls.core.wkrs.lnkis.Xoh_lnki_parser arg) {bfr.Add_mid(src, arg.Rng_bgn(), arg.Rng_end());}
|
||||
public void On_img (gplx.xowa.htmls.core.wkrs.imgs.Xoh_img_parser arg) {wkr__img.Make(bfr, hpg, src, arg);}
|
||||
public void On_img_thm (int rng_bgn, int rng_end) {bfr.Add_mid(src, rng_bgn, rng_end);}
|
||||
}
|
||||
@@ -15,12 +15,8 @@ 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.escapes; 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.parsers.*;
|
||||
public class Xoh_escape_parse_tst {
|
||||
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__escape(0, 1);
|
||||
fxt.Test__parse(gplx.xowa.htmls.core.hzips.tests.Xoh_hzip_fxt.Escape("~"));
|
||||
}
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
public interface Xoh_itm_parser {
|
||||
void Fail_throws_err_(boolean v);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.core.brys.*;
|
||||
public abstract class Xoh_itm_parser_fxt_base {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
protected byte[] src; protected int src_len;
|
||||
private Xoh_itm_parser Parser() {return Parser_get();}
|
||||
public abstract Xoh_itm_parser Parser_get();
|
||||
public void Test__parse__fail(String src_str, String expd) {
|
||||
Gfo_usr_dlg_.Test__list__init();
|
||||
Parser().Fail_throws_err_(Bool_.N);
|
||||
Exec_parse(src_str);
|
||||
Parser().Fail_throws_err_(Bool_.Y);
|
||||
Tfds.Eq_str(expd, Gfo_usr_dlg_.Test__list__term__get_1st());
|
||||
}
|
||||
public void Exec_parse(String src_str) {
|
||||
this.src = Bry_.new_u8(src_str); this.src_len = src.length;
|
||||
rdr.Ctor_by_page(Xoa_page_.Main_page_bry, src, src_len);
|
||||
Exec_parse_hook(rdr, 0, src_len);
|
||||
}
|
||||
public abstract void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end);
|
||||
}
|
||||
@@ -20,12 +20,12 @@ import gplx.core.brys.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_escape_hzip implements Xoh_hzip_wkr {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__escape;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {// " " -> 27,9,4
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm) {
|
||||
stat_itm.Escape_add_one();
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__escape);
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
return parser.Pos();
|
||||
return rdr.Pos();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ 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.escapes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.parsers.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_escape_parse implements Html_doc_wkr {
|
||||
private final Xoh_wkr wkr;
|
||||
public Xoh_escape_parse(Xoh_wkr wkr) {this.wkr = wkr;}
|
||||
public class Xoh_escape_parser implements Html_doc_wkr {
|
||||
private final Xoh_hdoc_wkr wkr;
|
||||
public Xoh_escape_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
|
||||
public byte[] Hook() {return Xoh_hzip_dict_.Escape_bry;}
|
||||
public void Init(byte[] src, int src_bgn, int src_end) {}
|
||||
public int Parse(int pos) {
|
||||
@@ -28,8 +28,6 @@ public class Xoh_hdr_html {
|
||||
if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling
|
||||
Xoh_html_wtr_.Para__assert_tag_starts_on_nl(bfr, hdr.Src_bgn());
|
||||
bfr.Add(Bry__hdr_lhs_bgn).Add_int(hdr_len, 1, 1); // '<h', '2'
|
||||
if (hctx.Mode_is_hdump())
|
||||
bfr.Add(Xoh_html_dict_.Type__hdr);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end); // '>'
|
||||
if (cfg.Toc__show()) {
|
||||
bfr.Add(Bry__span_lhs_bgn); // "<span class='mw-headline' id='"
|
||||
@@ -43,8 +41,6 @@ public class Xoh_hdr_html {
|
||||
wtr.Write_tkn(bfr, ctx, hctx, src, hdr, i, hdr.Subs_get(i));
|
||||
if (hdr_len > 0) { // NOTE: need to check hdr_len b/c it could be dangling
|
||||
if (hdr.Hdr_end_manual() > 0) bfr.Add_byte_repeat(Byte_ascii.Eq, hdr.Hdr_end_manual()); // '='
|
||||
if (hctx.Mode_is_hdump())
|
||||
bfr.Add(Xoh_html_dict_.Hdr__end);
|
||||
if (cfg.Toc__show())
|
||||
bfr.Add(Html_tag_.Span_rhs); // '</span>'
|
||||
bfr.Add(Bry__hdr_rhs_bgn).Add_int(hdr_len, 1, 1); // '</h', '2'
|
||||
@@ -52,6 +48,6 @@ public class Xoh_hdr_html {
|
||||
}
|
||||
}
|
||||
private static final byte[] Bry__hdr_lhs_bgn = Bry_.new_a7("<h"), Bry__hdr_rhs_bgn = Bry_.new_a7("</h"), Bry__hdr_rhs_end = Bry_.new_a7(">\n")
|
||||
, Bry__span_lhs_bgn = Bry_.new_a7("<span class='mw-headline' id='"), Bry__span_lhs_end = Bry_.new_a7("'>")
|
||||
, Bry__span_lhs_bgn = Bry_.new_a7("<span class=\"mw-headline\" id=\""), Bry__span_lhs_end = Bry_.new_a7("\">")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -20,21 +20,20 @@ import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
|
||||
public class Xoh_hdr_html_tst {
|
||||
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
||||
@Test public void Basic() {
|
||||
String html = String_.Concat_lines_nl_skip_last
|
||||
( "z"
|
||||
, ""
|
||||
, "<h2 data-xotype='hdr_bgn'><span class='mw-headline' id='A_1'>A 1<!--xo.hdr--></span></h2>"
|
||||
, "a 1"
|
||||
, ""
|
||||
, "<h2 data-xotype='hdr_bgn'><span class='mw-headline' id='B'>B<!--xo.hdr--></span></h2>"
|
||||
, "b"
|
||||
);
|
||||
fxt.Test__html(String_.Concat_lines_nl_skip_last
|
||||
( "z"
|
||||
, "==A 1=="
|
||||
, "a 1"
|
||||
, "==B=="
|
||||
, "b"
|
||||
), html);
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "z"
|
||||
, ""
|
||||
, "<h2><span class='mw-headline' id='A_1'>A 1</span></h2>"
|
||||
, "a 1"
|
||||
, ""
|
||||
, "<h2><span class='mw-headline' id='B'>B</span></h2>"
|
||||
, "b"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,47 +18,39 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.hdrs; 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.ttls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public class Xoh_hdr_hzip extends Xoh_hdr_parse_base implements Xoh_hzip_wkr {
|
||||
private Hzip_stat_itm stat_itm;
|
||||
public class Xoh_hdr_hzip implements Xoh_hzip_wkr {
|
||||
public String Key() {return Xoh_hzip_dict_.Key__hdr;}
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {
|
||||
this.stat_itm = stat_itm;
|
||||
this.Parse(bfr, parser, src, hook_bgn);
|
||||
}
|
||||
@Override public void Parse_exec(Bry_bfr bfr, byte[] src, int hook_bgn, int rng_bgn, int rng_end, byte level, int anchor_bgn, int anchor_end, int display_bgn, int display_end) {
|
||||
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
stat_itm.Hdr_add(level);
|
||||
bfr.Del_by(3); // delete "<h#"
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__hdr); // add hook
|
||||
bfr.Add_int_digits(1, level); // add level; EX: 2 in <h2>
|
||||
bfr.Add_mid(src, display_bgn, display_end); // add display;
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape
|
||||
if (!Bry_.Match_w_swap(src, display_bgn, display_end, src, anchor_bgn, anchor_end, Byte_ascii.Underline, Byte_ascii.Space)) // check if anchor == display, while treating " " == "_"
|
||||
bfr.Add_mid(src, anchor_bgn, anchor_end); // add anchor
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape
|
||||
bfr.Add(Xoh_hzip_dict_.Bry__hdr); // add hook
|
||||
bfr.Add_int_digits(1, level); // add level; EX: 2 in <h2>
|
||||
bfr.Add_mid(src, capt_bgn, capt_end).Add_byte(Xoh_hzip_dict_.Escape); // add caption
|
||||
if (anch != null) bfr.Add(anch); // add anchor
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape); // add escape
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {
|
||||
byte level = parser.Read_byte();
|
||||
int display_bgn = parser.Pos();
|
||||
int display_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape);
|
||||
int anchor_bgn = parser.Pos();
|
||||
int anchor_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape);
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
byte level = rdr.Read_byte();
|
||||
int capt_bgn = rdr.Pos();
|
||||
int capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
int anch_bgn = rdr.Pos();
|
||||
int anch_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
|
||||
|
||||
bfr.Add(Bry__hdr__0).Add_byte(level);
|
||||
bfr.Add(Bry__hdr__1);
|
||||
if (anchor_end - anchor_bgn == 0)
|
||||
bfr.Add_mid_w_swap (src, display_bgn, display_end, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
if (anch_end > anch_bgn)
|
||||
bfr.Add_mid (src, anch_bgn, anch_end);
|
||||
else
|
||||
bfr.Add_mid (src, anchor_bgn, anchor_end);
|
||||
bfr.Add_mid_w_swap (src, capt_bgn, capt_end, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
bfr.Add(Bry__hdr__2);
|
||||
bfr.Add_mid(src, display_bgn, display_end);
|
||||
bfr.Add_mid(src, capt_bgn, capt_end);
|
||||
bfr.Add(Bry__hdr__3).Add_byte(level);
|
||||
bfr.Add_byte(Byte_ascii.Angle_end);
|
||||
return parser.Pos();
|
||||
return rdr.Pos();
|
||||
}
|
||||
private static final byte[]
|
||||
Bry__hdr__0 = Bry_.new_a7("<h")
|
||||
, Bry__hdr__1 = Bry_.new_a7(" data-xotype='hdr_bgn'>\n <span class='mw-headline' id='")
|
||||
, Bry__hdr__2 = Bry_.new_a7("'>")
|
||||
, Bry__hdr__3 = Bry_.new_a7("<!--xo.hdr--></span>\n</h")
|
||||
, Bry__hdr__1 = Bry_.new_a7(">\n <span class=\"mw-headline\" id=\"")
|
||||
, Bry__hdr__2 = Bry_.new_a7("\">")
|
||||
, Bry__hdr__3 = Bry_.new_a7("</span>\n</h")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -19,56 +19,48 @@ package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; impor
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
public class Xoh_hdr_hzip_tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Test public void Diff() {
|
||||
String html = String_.Concat_lines_nl_skip_last
|
||||
( "<h2 data-xotype='hdr_bgn'>"
|
||||
, " <span class='mw-headline' id='A'><i>A</i><!--xo.hdr--></span>"
|
||||
, "</h2>"
|
||||
, "a"
|
||||
);
|
||||
String hzip = String_.Concat_lines_nl_skip_last
|
||||
( "~\"2<i>A</i>~A~"
|
||||
, "a"
|
||||
);
|
||||
fxt.Test__bicode(hzip, html);
|
||||
}
|
||||
@Test public void Same() {
|
||||
String html = String_.Concat_lines_nl_skip_last
|
||||
( "<h6 data-xotype='hdr_bgn'>"
|
||||
, " <span class='mw-headline' id='A'>A<!--xo.hdr--></span>"
|
||||
, "</h6>"
|
||||
, "a"
|
||||
);
|
||||
String hzip = String_.Concat_lines_nl_skip_last
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"6A~~"
|
||||
, "a"
|
||||
);
|
||||
fxt.Test__bicode(hzip, html);
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h6>"
|
||||
, " <span class='mw-headline' id='A'>A</span>"
|
||||
, "</h6>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Diff() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"2<i>A</i>~A~"
|
||||
, "a"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>"
|
||||
, " <span class='mw-headline' id='A'><i>A</i></span>"
|
||||
, "</h2>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
@Test public void Diff_by_underscore() {
|
||||
String html = String_.Concat_lines_nl_skip_last
|
||||
( "<h2 data-xotype='hdr_bgn'>"
|
||||
, " <span class='mw-headline' id='A_1'>A 1<!--xo.hdr--></span>"
|
||||
, "</h2>"
|
||||
, "a"
|
||||
);
|
||||
String hzip = String_.Concat_lines_nl_skip_last
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"2A 1~~"
|
||||
, "a"
|
||||
);
|
||||
fxt.Test__bicode(hzip, html);
|
||||
}
|
||||
@Test public void Same_w_underscore() {
|
||||
String html = String_.Concat_lines_nl_skip_last
|
||||
( "<h2 data-xotype='hdr_bgn'>"
|
||||
, " <span class='mw-headline' id='A_1'>A_1<!--xo.hdr--></span>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>"
|
||||
, " <span class='mw-headline' id='A_1'>A 1</span>"
|
||||
, "</h2>"
|
||||
, "a"
|
||||
);
|
||||
String hzip = String_.Concat_lines_nl_skip_last
|
||||
));
|
||||
}
|
||||
@Test public void Same_w_underscore() {
|
||||
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
|
||||
( "~\"2A_1~~"
|
||||
, "a"
|
||||
);
|
||||
fxt.Test__bicode(hzip, html);
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<h2>"
|
||||
, " <span class='mw-headline' id='A_1'>A_1</span>"
|
||||
, "</h2>"
|
||||
, "a"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,18 @@ 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.hdrs; 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.sections.*;
|
||||
public class Xoh_hdr_make extends Xoh_hdr_parse_base {
|
||||
private Xoh_page hpg;
|
||||
public int Make(Bry_bfr bfr, Xoh_page hpg, Bry_parser parser, byte[] src, int hook_bgn) {
|
||||
this.hpg = hpg;
|
||||
this.Parse(bfr, parser, src, hook_bgn);
|
||||
return parser.Pos();
|
||||
}
|
||||
@Override public void Parse_exec(Bry_bfr bfr, byte[] src, int hook_bgn, int rng_bgn, int rng_end, byte level, int anchor_bgn, int anchor_end, int display_bgn, int display_end) {
|
||||
public class Xoh_hdr_make {
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, int rng_bgn, int rng_end, int level, int capt_bgn, int capt_end, byte[] anch) {
|
||||
// register section
|
||||
Xoh_section_mgr section_mgr = hpg.Section_mgr();
|
||||
int section_len = section_mgr.Len();
|
||||
if (section_len != 0) // guard against -1 index; should not happen
|
||||
section_mgr.Set_content(section_len - 1, src, rng_bgn - 2); // -2 to skip "\n\n"
|
||||
hpg.Section_mgr().Add(section_len, level, Bry_.Mid(src, anchor_bgn, anchor_end), Bry_.Mid(src, display_bgn, display_end)).Content_bgn_(rng_end + 1); // +1 to skip "\n"
|
||||
bfr.Add_mid(src, hook_bgn, rng_end);
|
||||
byte[] capt = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
if (anch == null) anch = Bry_.Replace(capt, Byte_ascii.Space, Byte_ascii.Underline);
|
||||
hpg.Section_mgr().Add(section_len, level, anch, capt).Content_bgn_(rng_end + 1); // +1 to skip "\n"
|
||||
bfr.Add_mid(src, rng_bgn, rng_end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@ public class Xoh_hdr_make_tst {
|
||||
String html = String_.Concat_lines_nl_skip_last
|
||||
( "z"
|
||||
, ""
|
||||
, "<h2 data-xotype='hdr_bgn'>"
|
||||
, " <span class='mw-headline' id='A_1'>A 1<!--xo.hdr--></span>"
|
||||
, "<h2>"
|
||||
, " <span class='mw-headline' id='A_1'>A 1</span>"
|
||||
, "</h2>"
|
||||
, "a 1"
|
||||
, ""
|
||||
, "<h2 data-xotype='hdr_bgn'>"
|
||||
, " <span class='mw-headline' id='B'>B<!--xo.hdr--></span>"
|
||||
, "<h2>"
|
||||
, " <span class='mw-headline' id='B'>B</span>"
|
||||
, "</h2>"
|
||||
, "b"
|
||||
);
|
||||
|
||||
@@ -1,62 +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.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.parsers.*;
|
||||
public class Xoh_hdr_parse {
|
||||
public int Parse(Xoh_wkr wkr, Html_tag_rdr rdr, byte[] src, int hdr_tag_id, int hdr_tag_bgn, Html_tag span) { // <a rel="nofollow" class="external autonumber_id" href="http://a.org">[1]</a>
|
||||
Html_atr id_atr = span.Atrs__get_by(Html_atr_.Bry__id);
|
||||
int id_bgn = id_atr.Val_bgn(), id_end = id_atr.Val_end();
|
||||
int capt_bgn = span.Src_end();
|
||||
rdr.Tag__move_fwd_tail(hdr_tag_id); // find </h2> not </span> since <span> can be nested, but <h2> cannot
|
||||
int capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get </span> before </h2>
|
||||
boolean id_capt_related = false;
|
||||
byte[] capt = Bry_.Mid(src, capt_bgn, capt_end);
|
||||
byte[] id = null;
|
||||
switch (Match(src, capt_bgn, capt_end, src, id_bgn, id_end)) {
|
||||
case Bool_.Y_byte: break;
|
||||
case Bool_.N_byte: id = Bry_.Mid(src, id_bgn, id_end); break;
|
||||
case Bool_.__byte: id_capt_related = true; break;
|
||||
}
|
||||
int tag_end = rdr.Pos();
|
||||
wkr.On_hdr(hdr_tag_bgn, tag_end, hdr_tag_id, id, capt, id_capt_related);
|
||||
return tag_end;
|
||||
}
|
||||
private static byte Match(byte[] lhs, int lhs_bgn, int lhs_end, byte[] rhs, int rhs_bgn, int rhs_end) {
|
||||
int lhs_len = lhs.length;
|
||||
if (lhs_end > lhs_len) lhs_end = lhs_len; // must limit lhs_end to lhs_len, else ArrayIndexOutOfBounds below; DATE:2015-01-31
|
||||
int rhs_len = rhs_end - rhs_bgn;
|
||||
if (rhs_len != lhs_end - lhs_bgn) return Bool_.N_byte;
|
||||
if (rhs_len == 0) return lhs_end - lhs_bgn == 0 ? Bool_.Y_byte : Bool_.N_byte; // "" only matches ""
|
||||
byte rv = Bool_.Y_byte;
|
||||
for (int i = 0; i < rhs_len; ++i) {
|
||||
int pos = lhs_bgn + i;
|
||||
if (pos >= lhs_end) return Bool_.N_byte; // ran out of lhs; exit; EX: lhs=ab; rhs=abc
|
||||
byte lhs_byte = lhs[pos];
|
||||
byte rhs_byte = rhs[i + rhs_bgn];
|
||||
if (lhs_byte != rhs_byte) {
|
||||
if ( lhs_byte == Byte_ascii.Underline
|
||||
&& rhs_byte == Byte_ascii.Space
|
||||
)
|
||||
continue;
|
||||
return Bool_.N_byte;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +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.hdrs; 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.ttls.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.sections.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
public abstract class Xoh_hdr_parse_base {
|
||||
public void Parse(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {// EX: <h2 data-xotype='rng_bgn'>
|
||||
int rng_bgn = parser.Pos_(hook_bgn - 3); // move back to "<h#" b/c hook starts at " data-xotype";
|
||||
parser.Chk(Bry__hdr_lhs_bgn); // check for "<h"
|
||||
|
||||
// get level; EX: '<h2' -> '2'
|
||||
byte level = parser.Read_byte_as_a7_int();
|
||||
|
||||
// get anchor between "id='" and "'>"
|
||||
parser.Fwd_end(Html_tag_.Span_lhs);
|
||||
int anchor_bgn = parser.Fwd_end(Bry__atr_id);
|
||||
int anchor_end = parser.Fwd_bgn(Bry__tag_end);
|
||||
|
||||
// get display between "'>" and "</h#>"
|
||||
int display_bgn = parser.Pos();
|
||||
int display_end = parser.Fwd_bgn(Xoh_html_dict_.Hdr__end);
|
||||
|
||||
// get content_bgn after "</h2>"
|
||||
int rng_end = parser.Fwd_end(Bry__hdr_rhs_bgn);
|
||||
if (level != parser.Read_byte_as_a7_int()) throw parser.Fail("levels doesn't match", Byte_.To_str(level));
|
||||
rng_end = parser.Chk(Byte_ascii.Angle_end);
|
||||
|
||||
Parse_exec(bfr, src, hook_bgn, rng_bgn, rng_end, level, anchor_bgn, anchor_end, display_bgn, display_end);
|
||||
}
|
||||
public abstract void Parse_exec(Bry_bfr bfr, byte[] src, int hook_bgn, int rng_bgn, int rng_end, byte level, int anchor_bgn, int anchor_end, int display_bgn, int display_end);
|
||||
private static final byte[] Bry__hdr_lhs_bgn = Bry_.new_a7("<h"), Bry__atr_id = Bry_.new_a7(" id='"), Bry__tag_end = Bry_.new_a7("'>"), Bry__hdr_rhs_bgn = Bry_.new_a7("</h");
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.hdrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_hdr_parser {
|
||||
public int Parse(Xoh_hdoc_wkr wkr, Html_tag_rdr rdr, byte[] src, int hdr_name_id, int rng_bgn, Html_tag span) {// <h2><span class='mw-headline' id='A_1'>A 1</span></h2>
|
||||
Html_atr anch_atr = span.Atrs__get_by(Html_atr_.Bry__id);
|
||||
int anch_bgn = anch_atr.Val_bgn(), anch_end = anch_atr.Val_end();
|
||||
int capt_bgn = span.Src_end();
|
||||
rdr.Tag__move_fwd_tail(hdr_name_id); // find </h2> not </span> since <span> can be nested, but <h2> cannot
|
||||
int capt_end = rdr.Tag__peek_bwd_tail(Html_tag_.Id__span).Src_bgn(); // get </span> before </h2>
|
||||
byte[] anch = null;
|
||||
if (!Bry_.Match_w_swap(src, capt_bgn, capt_end, src, anch_bgn, anch_end, Byte_ascii.Space, Byte_ascii.Underline))
|
||||
anch = Bry_.Mid(src, anch_bgn, anch_end); // anch is different than capt; occurs with html and dupe-anchors; EX: "==<i>A</i>==" -> id='A'
|
||||
int rng_end = rdr.Pos();
|
||||
wkr.On_hdr(rng_bgn, rng_end, hdr_name_id, capt_bgn, capt_end, anch);
|
||||
return rng_end;
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,13 @@ 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.hdrs; 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.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.parsers.*;
|
||||
public class Xoh_hdr_parse_tst {
|
||||
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__hdr(0, 54, Html_tag_.Id__h2, "A_b", "A b", false);
|
||||
fxt.Test__parse("<h2><span class='mw-headline' id='A_b'>A b</span></h2>");
|
||||
}
|
||||
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 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>"
|
||||
;
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {fxt.Test__html("[[File:A.png|220x110px|upright=.5|abc]]" , Html__basic);}
|
||||
}
|
||||
168
400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip.java
Normal file
168
400_xowa/src/gplx/xowa/htmls/core/wkrs/imgs/Xoh_img_hzip.java
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
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.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.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
|
||||
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_img_hzip implements Xoh_hzip_wkr {
|
||||
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 void Encode( Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_img_parser arg) {
|
||||
// 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();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
|
||||
int flag = rdr.Read_int_by_base85(3);
|
||||
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;
|
||||
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) {
|
||||
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;
|
||||
if (img_xoimg_exists) {
|
||||
img_xoimg_bgn = rdr.Pos();
|
||||
img_xoimg_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
int anch_title_bgn = -1, anch_title_end = -1;
|
||||
if (anch_title_exists) {
|
||||
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) {
|
||||
img_alt_bgn = anch_title_bgn;
|
||||
img_alt_end = anch_title_end;
|
||||
}
|
||||
if (img_alt__diff__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)
|
||||
img_cls_other = Bry_.Mid(src, rdr.Pos(), rdr.Find_fwd_lr());
|
||||
byte[] img_cls_bry = Xoh_img_cls_.To_html(img_cls, img_cls_other);
|
||||
byte[] anch_cls_bry = Xoh_anch_cls_.To_html(anch_cls);
|
||||
|
||||
bfr.Add(Html_bldr_.Bry__a_lhs_w_href); // '<a href="'
|
||||
if (anch_href_is_file) { // 99% of cases; href='/wiki/File:A.png'
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // '/wiki/'
|
||||
bfr.Add(Xow_ns_.Bry__file).Add_byte_colon(); // 'File:'
|
||||
bfr.Add(page_db); // 'A.png'
|
||||
}
|
||||
else {
|
||||
if (anch_href_has_site) {
|
||||
}
|
||||
bfr.Add(Xoh_href_.Bry__wiki); // '/wiki/'
|
||||
Xoa_ttl anch_href_ttl = ctx.Ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
bfr.Add(anch_href_ttl.Full_db());
|
||||
page_db = anch_href_ttl_bry;
|
||||
}
|
||||
Xof_url_bldr url_bldr = ctx.Url_bldr();
|
||||
url_bldr.Init_by_root(repo_is_commons ? ctx.Dir__file__comm() : ctx.Dir__file__wiki(), Byte_ascii.Slash, false, false, 2);
|
||||
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);
|
||||
byte[] img_src = url_bldr.Xto_bry();
|
||||
|
||||
bfr.Add(anch_cls_bry); // '" class="image'
|
||||
if (anch_title_exists) {
|
||||
bfr.Add(Html_bldr_.Bry__title__nth); // '" title="'
|
||||
bfr.Add_mid(src, anch_title_bgn, anch_title_end); // 'abc'
|
||||
}
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_head_w_quote); // '">'
|
||||
bfr.Add(Html_bldr_.Bry__img_lhs_w_alt); // '<img alt="'
|
||||
if (anch_title_exists || img_alt__diff__anch_title)
|
||||
bfr.Add_mid(src, img_alt_bgn, img_alt_end); // 'abc'
|
||||
if (img_xoimg_exists) {
|
||||
bfr.Add(Xoh_img_xoimg_parser.Bry__html);
|
||||
bfr.Add_mid(src, img_xoimg_bgn, img_xoimg_end); // '1|220|110...'
|
||||
}
|
||||
bfr.Add(Html_bldr_.Bry__src__nth); // '" src="'
|
||||
bfr.Add(img_src); // 'file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png'
|
||||
bfr.Add(Html_bldr_.Bry__width__nth); // '" width="'
|
||||
bfr.Add_int_variable(img_w); // '220'
|
||||
bfr.Add(Html_bldr_.Bry__height__nth); // '" height="'
|
||||
bfr.Add_int_variable(img_h).Add_byte_quote(); // '110"'
|
||||
bfr.Add(img_cls_bry); // ' class="thumbimage"'
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_inline); // '/>
|
||||
bfr.Add(Html_bldr_.Bry__a_rhs); // </a>
|
||||
|
||||
rdr.Move_to(rdr.Src_end());
|
||||
return rdr.Pos();
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.txts; 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.parsers.*;
|
||||
public class Xoh_txt_parse_tst {
|
||||
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init__txt(0, 3);
|
||||
fxt.Test__parse("abc");
|
||||
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 org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
|
||||
public class Xoh_img_hzip__dump__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; 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.tests.*;
|
||||
public class Xoh_img_hzip__view__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@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 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>"
|
||||
);
|
||||
}
|
||||
@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 alt='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110'/></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>
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Xoh_img_make {
|
||||
private final Xoa_file_mgr file_mgr = new Xoa_file_mgr();
|
||||
public void Make(Bry_bfr bfr, Xoh_page hpg, byte[] src, Xoh_img_parser arg) {
|
||||
Xoh_img_xoimg_parser img_xoimg = arg.Img_xoimg_parser();
|
||||
Xoh_img_src_parser img_src = arg.Img_src_parser();
|
||||
Xof_fsdb_itm fsdb_itm = hpg.Img_mgr().Make_img();
|
||||
boolean html_data_exists = false;
|
||||
if (img_xoimg.Val_exists()) { // data-xoimg exists; use it
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), img_src.File_ttl_bry(), 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);
|
||||
html_data_exists = file_mgr.Check_cache(fsdb_itm);
|
||||
}
|
||||
else if (arg.Img_w_exists()) { // width exists; use it
|
||||
// fsdb_itm.Init_by_hdump(img_src.Repo_is_commons(), img_src.File_ttl_bry(), arg.Img_w(), img_src.File_time(), img_src.File_page());
|
||||
html_data_exists = true;
|
||||
}
|
||||
Write_html(bfr, src, arg, fsdb_itm, html_data_exists);
|
||||
}
|
||||
private void Write_html(Bry_bfr bfr, byte[] src, Xoh_img_parser arg, Xof_fsdb_itm fsdb_itm, boolean html_data_exists) {
|
||||
// html_data_exists = n : "<a href='/wiki/File:A.png' class='image' title='abc'><img id='xoimg_1' alt='abc' src=''/></a>"
|
||||
bfr.Add_mid(src, arg.Anch_tag_bgn(), arg.Anch_tag_end()); // '<a href="/wiki/File:A.png" class="image" title="abc">'
|
||||
bfr.Add(Html_bldr_.Bry__img_lhs); // '<img'
|
||||
bfr.Add(Html_bldr_.Bry__id__1st); // ' id="'
|
||||
bfr.Add(Xoh_img_mgr.Bry__html_uid); // 'xoimg_'
|
||||
bfr.Add_int_variable(fsdb_itm.Html_uid()); // '123'
|
||||
bfr.Add(Html_bldr_.Bry__alt__nth); // '" alt="'
|
||||
arg.Img_alt_atr().Html__add(bfr); // 'abc'
|
||||
bfr.Add(Html_bldr_.Bry__src__nth); // '" src="'
|
||||
bfr.Add(Html_bldr_.Bry__lhs_end_inline_w_quote); // '"/>'
|
||||
bfr.Add(Html_bldr_.Bry__a_rhs); // '</a>'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; 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.makes.tests.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_img_make__dump__tst {
|
||||
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
|
||||
@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' src=''/></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)
|
||||
);
|
||||
}
|
||||
// @Test public void Html_exists__y__cache() {
|
||||
// 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' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/B.png/330px.png' width='330' height='110'/></a>"
|
||||
// ;
|
||||
// fxt.Init_img_cache("en.w", "A.png", 0, 0.5, 220, 110, -1, -1, Bool_.Y, "B.png", 330, 110, -1, -1);
|
||||
// fxt.Test__make(orig
|
||||
// , fxt.Page_chkr().Body_(expd)
|
||||
// .Imgs__add("en.w", "A.png", 0, 0.5, 220, 110, -1, -1)
|
||||
// );
|
||||
// }
|
||||
// @Test public void Html_exists__y__html() {
|
||||
// String
|
||||
// orig = "<a href='/wiki/File:A.png' class='image' title='abc'><img alt='abc' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='330' height='110'/></a>"
|
||||
// , expd = "<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/B.png/330px.png' width='330' height='110'/></a>"
|
||||
// ;
|
||||
// fxt.Test__make(orig
|
||||
// , fxt.Page_chkr().Body_(expd)
|
||||
// .Imgs__add("en.w", "A.png", 0, 0.5, 220, 110, -1, -1)
|
||||
// );
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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.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, 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(), hdoc_wkr.Ctx().Wiki(), anch_tag); // href='/wiki/File:A.png'
|
||||
Html_tag img_tag = tag_rdr.Tag__move_fwd_head(Html_tag_.Id__img); // <img>
|
||||
img_xoimg_parser.Parse(tag_rdr.Rdr(), src, img_tag);
|
||||
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(), hdoc_wkr.Ctx().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();
|
||||
hdoc_wkr.On_img(this);
|
||||
return rng_end;
|
||||
}
|
||||
public static final byte[]
|
||||
Bry__cls__anch__image = Bry_.new_a7("image")
|
||||
, Bry__cls__img__thumbimage = Bry_.new_a7("thumbimage")
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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.*;
|
||||
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 String
|
||||
Str__image = "image"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__image = Bry_.new_a7(Str__image)
|
||||
;
|
||||
private static final byte[]
|
||||
Html__image = Bry_.Add(Html_bldr_.Bry__cls__nth, Bry__image)
|
||||
;
|
||||
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_byte(Bry__image , Tid__image)
|
||||
;
|
||||
public static byte[] To_html(int tid) {
|
||||
switch (tid) {
|
||||
case Xoh_anch_cls_.Tid__none: return Bry_.Empty;
|
||||
case Xoh_anch_cls_.Tid__image: return Html__image;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.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.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
|
||||
public class Xoh_anch_cls_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr();
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
|
||||
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__class); // EX: class='image'
|
||||
Parse(owner_rdr, src, atr.Val_bgn(), atr.Val_end());
|
||||
}
|
||||
public void Parse(Bry_rdr owner_rdr, byte[] src, int src_bgn, int src_end) {
|
||||
if (src_bgn == -1)
|
||||
tid = Xoh_anch_cls_.Tid__none;
|
||||
else {
|
||||
rdr.Init_by_sub(owner_rdr, "anch.cls", src_bgn, src_end);
|
||||
this.tid = rdr.Chk(Xoh_anch_cls_.Trie);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user