1
0
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:
gnosygnu
2015-11-08 23:48:07 -05:00
parent b990ec409f
commit d9f45cec19
298 changed files with 3908 additions and 2141 deletions

View File

@@ -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, "'", "\"");}
}

View 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_");
}

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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
// );
// */

View 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);
}
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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());
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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, "~", "");}
}

View File

@@ -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;}

View File

@@ -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;\">"
// ));
// }
// }
//}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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")
;
}

View File

@@ -1,30 +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.*; import gplx.xowa.htmls.core.wkrs.txts.*; import gplx.xowa.htmls.core.wkrs.escapes.*; import gplx.xowa.htmls.core.wkrs.spaces.*;
public class Xoh_parser_ {
public static Html_doc_parser new_(Xoh_wkr wkr, Xow_wiki wiki) {
Html_doc_parser rv = new Html_doc_parser();
rv.Reg_txt(new Xoh_txt_parse(wkr)).Reg
( new Xoh_doc_wkr__tag(wkr, wiki)
, new Xoh_escape_parse(wkr)
, new Xoh_space_parse(wkr)
);
return rv;
}
}

View File

@@ -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();}
}

View File

@@ -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) {}
}

View File

@@ -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) {

View File

@@ -15,12 +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.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.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;
}
}

View File

@@ -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);
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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);
}
}

View File

@@ -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);}
}

View File

@@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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);}
}

View File

@@ -15,14 +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; 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.core.brys.*;
public interface Xoh_itm_parser {
void Fail_throws_err_(boolean v);
}

View 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.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);
}

View File

@@ -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();
}
}

View File

@@ -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) {

View File

@@ -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("\">")
;
}

View File

@@ -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"
));
}
}

View File

@@ -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")
;
}

View File

@@ -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"
));
}
}

View File

@@ -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);
}
}

View File

@@ -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"
);

View File

@@ -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;
}
}

View File

@@ -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");
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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;
}
}

View File

@@ -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);}
}

View 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();
}
}

View File

@@ -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
);
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.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>
}

View File

@@ -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>'
}
}

View File

@@ -0,0 +1,53 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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)
// );
// }
}

View File

@@ -0,0 +1,63 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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")
;
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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);
}
}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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);
}
}
}

View File

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
import gplx.core.btries.*;
public class Xoh_img_cls_ {
public static final byte
Tid__none = 0
, Tid__thumbimage = 2 // EX: [[File:A.png|thumb]] -> "<img class='thumbimage'>"
, Tid__thumbborder = 3 // EX: [[File:A.png|border]] -> "<img class='thumbborder'>"
;
public static final String
Str__thumbimage = "thumbimage"
, Str__thumbborder = "thumbborder"
;
public static final byte[]
Bry__none = Bry_.Empty
;
private static final byte[]
Bry__thumbimage = Bry_.new_a7(Str__thumbimage)
, Bry__thumbborder = Bry_.new_a7(Str__thumbborder)
;
public static final Btrie_slim_mgr Trie = Btrie_slim_mgr.cs()
.Add_bry_byte(Bry__thumbimage , Tid__thumbimage)
.Add_bry_byte(Bry__thumbborder , Tid__thumbborder)
;
private static final byte[] Bry__html_class = Bry_.new_a7(" class=\"");
public static byte[] To_html(int tid, byte[] other) {
boolean other_is_empty = Bry_.Len_eq_0(other);
if (tid == Xoh_img_cls_.Tid__none && other_is_empty) return Bry_.Empty;
byte[] cls = null;
switch (tid) {
case Xoh_img_cls_.Tid__thumbimage: cls = Bry__thumbimage; break;
case Xoh_img_cls_.Tid__thumbborder: cls = Bry__thumbborder; break;
}
byte[] other_0 = Bry_.Empty, other_1 = Bry_.Empty;
if (!other_is_empty) {
if (cls != null) other_0 = Byte_ascii.Space_bry;
other_1 = other;
}
return Bry_.Add(Bry__html_class, cls, other_0, other_1, Byte_ascii.Quote_bry);
}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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 org.junit.*;
public class Xoh_img_cls__tst {
private Xoh_img_cls__fxt fxt = new Xoh_img_cls__fxt();
@Test public void To_html() {
fxt.Test__to_html(Xoh_img_cls_.Tid__none , null , "");
fxt.Test__to_html(Xoh_img_cls_.Tid__none , "a" , " class=\"a\"");
fxt.Test__to_html(Xoh_img_cls_.Tid__thumbimage , null , " class=\"thumbimage\"");
fxt.Test__to_html(Xoh_img_cls_.Tid__thumbborder , null , " class=\"thumbborder\"");
fxt.Test__to_html(Xoh_img_cls_.Tid__thumbborder , "a" , " class=\"thumbborder a\"");
}
}
class Xoh_img_cls__fxt {
public void Test__to_html(byte tid, String other, String expd) {
Tfds.Eq(expd, String_.new_u8(Xoh_img_cls_.To_html(tid, Bry_.new_u8_safe(other))));
}
}

View File

@@ -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.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_img_cls_parser {
private final Bry_rdr rdr = new Bry_rdr();
public byte Cls_tid() {return cls_tid;} private byte cls_tid;
public int Other_bgn() {return other_bgn;} private int other_bgn;
public int Other_end() {return other_end;} private int other_end;
public boolean Other_exists() {return other_end > other_bgn;}
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='thumbborder'
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) {
this.cls_tid = Xoh_img_cls_.Tid__none;
this.other_bgn = this.other_end = -1;
return;
}
rdr.Init_by_sub(owner_rdr, "img.cls", src_bgn, src_end);
this.cls_tid = rdr.Chk(Xoh_img_cls_.Trie);
if (rdr.Is(Byte_ascii.Space)) {
this.other_bgn = rdr.Pos();
this.other_end = src_end;
}
else
other_bgn = other_end = -1;
}
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.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.core.btries.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import gplx.xowa.wikis.domains.*;
public class Xoh_img_src_parser implements Xoh_itm_parser {
private final Bry_rdr rdr = new Bry_rdr(); private byte[] src;
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
public int Val_bgn() {return val_bgn;} private int val_bgn;
public int Val_end() {return val_end;} private int val_end;
public boolean Val_exists() {return val_end > val_bgn;}
public int Repo_bgn() {return repo_bgn;} private int repo_bgn;
public int Repo_end() {return repo_end;} private int repo_end;
public boolean Repo_is_commons() {return repo_is_commons;} private boolean repo_is_commons;
public int File_ttl_bgn() {return file_ttl_bgn;} private int file_ttl_bgn;
public int File_ttl_end() {return file_ttl_end;} private int file_ttl_end;
public boolean File_ttl_exists() {return file_ttl_end > file_ttl_bgn;}
public byte[] File_ttl_bry() {if (file_ttl_bry == null) file_ttl_bry = Bry_.Mid(src, file_ttl_bgn, file_ttl_end); return file_ttl_bry;} private byte[] file_ttl_bry;
public boolean File_is_orig() {return file_is_orig;} private boolean file_is_orig;
public int File_w() {return file_w;} private int file_w;
public int File_time() {return file_time;} private int file_time;
public int File_page() {return file_page;} private int file_page;
public boolean File_time_exists() {return file_time != -1;}
public boolean File_page_exists() {return file_page != -1;}
public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, Html_tag tag) {
Html_atr atr = tag.Atrs__get_by_or_empty(Html_atr_.Bry__src);
if (!atr.Val_exists()) return;
Parse(owner_rdr, domain_bry, atr.Val_bgn(), atr.Val_end());
}
public void Parse(Bry_rdr owner_rdr, byte[] domain_bry, int val_bgn, int val_end) { // EX: src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/1/2/A.png/220px.png"
this.src = owner_rdr.Src();
this.val_bgn = val_bgn; this.val_end = val_end;
file_w = file_time = file_page = -1;
rdr.Init_by_sub(owner_rdr, "img.src.xowa", val_bgn, val_end).Dflt_dlm_(Byte_ascii.Slash);
repo_bgn = rdr.Find_fwd_rr(Bry__file); // skip past /file/; EX: "file:///J:/xowa/file/commons.wikimedia.org/"
repo_end = rdr.Find_fwd_lr();
repo_is_commons = Bry_.Match(rdr.Src(), repo_bgn, repo_end, Xow_domain_itm_.Bry__commons);
if (!repo_is_commons) {
if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
}
file_is_orig = rdr.Chk(trie) == Tid__orig; // check if 'orig/' or 'thumb/'
file_ttl_bgn = rdr.Move_by(4); // 8 for 4 levels of md5; EX: "0/1/2/3/"
if (file_is_orig)
file_ttl_end = rdr.Src_end();
else {
file_ttl_end = rdr.Find_fwd_lr();
file_w = rdr.Read_int_to(Byte_ascii.Ltr_p); // EX: "220px"
rdr.Chk(Byte_ascii.Ltr_x);
if (rdr.Is(Byte_ascii.At))
file_time = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px@5.png"
else if (rdr.Is(Byte_ascii.Dash))
file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png"
}
}
private static final byte[] Bry__file = Bry_.new_a7("/file/"), Bry__orig = Bry_.new_a7("orig/"), Bry__thumb = Bry_.new_a7("thumb/");
private static final byte Tid__orig = 1, Tid__thumb = 2;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs().Add_bry_byte(Bry__orig, Tid__orig).Add_bry_byte(Bry__thumb, Tid__thumb);
}

View File

@@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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 org.junit.*; import gplx.core.brys.*;
import gplx.xowa.wikis.domains.*;
public class Xoh_img_src_parser_tst {
private final Xoh_img_src_parser_fxt fxt = new Xoh_img_src_parser_fxt();
@Test public void Basic() {
fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, -1);
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px@5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, 5, -1);
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px-5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, 5);
}
@Test public void Fail__orig_mode() {
fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'");
}
@Test public void Fail__repo_mode() {
fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'");
}
}
class Xoh_img_src_parser_fxt extends Xoh_itm_parser_fxt_base {
private final Xoh_img_src_parser parser = new Xoh_img_src_parser();
@Override public Xoh_itm_parser Parser_get() {return parser;}
public void Test__parse(String src_str, String expd_repo, boolean expd_file_is_orig, String expd_file, int expd_w, int expd_time, int expd_page) {
Exec_parse(src_str);
Tfds.Eq_str(expd_repo, String_.new_u8(src, parser.Repo_bgn(), parser.Repo_end()));
Tfds.Eq_str(expd_file, String_.new_u8(src, parser.File_ttl_bgn(), parser.File_ttl_end()));
Tfds.Eq_bool(expd_file_is_orig, parser.File_is_orig());
Tfds.Eq_int(expd_w, parser.File_w());
Tfds.Eq_int(expd_time, parser.File_time());
Tfds.Eq_int(expd_page, parser.File_page());
}
@Override public void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end) {
parser.Parse(owner_rdr, Xow_domain_itm_.Bry__enwiki, src_bgn, src_end);
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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_img_xoimg_parser {
private final Bry_rdr rdr = new Bry_rdr();
public int Val_bgn() {return val_bgn;} private int val_bgn;
public int Val_end() {return val_end;} private int val_end;
public boolean Val_exists() {return val_end > val_bgn;}
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public int Lnki_w() {return lnki_w;} private int lnki_w;
public int Lnki_h() {return lnki_h;} private int lnki_h;
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
public double Lnki_time() {return lnki_time;} private double lnki_time;
public int Lnki_page() {return lnki_page;} private int lnki_page;
public void Parse(Bry_rdr owner_rdr, byte[] src, Html_tag tag) {
Html_atr atr = tag.Atrs__get_by_or_empty(Bry__name);
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) {
val_bgn = val_end = -1;
}
else {
rdr.Init_by_sub(owner_rdr, "img.xoimg", src_bgn, src_end).Dflt_dlm_(Byte_ascii.Pipe);
this.val_bgn = src_bgn;
this.val_end = src_end;
this.lnki_type = (byte)(rdr.Read_byte_to() - Byte_ascii.Num_0);
this.lnki_w = rdr.Read_int_to();
this.lnki_h = rdr.Read_int_to();
this.lnki_upright = rdr.Read_double_to();
this.lnki_time = rdr.Read_double_to();
this.lnki_page = rdr.Read_int_to();
}
}
public static final byte[]
Bry__name = Bry_.new_a7("data-xoimg")
, Bry__html = Bry_.new_a7("\" data-xoimg=\"")
;
}

View File

@@ -98,14 +98,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// */
// }
//}
//namespace gplx.xowa.htmls.core.hzips.wkrs {
// import org.junit.*; using gplx.xowa.htmls;
// public class Xoh_hzip_href_tst {
// @Before public void init() {fxt.Clear();} private Xoh_hzip_mgr_fxt fxt = new Xoh_hzip_mgr_fxt();
// @Test public void Srl_lnki_img_full() {
// byte[][] brys = Bry_.Ary(Xoh_hzip_dict_.Bry__img_full, Bry_.new_ints(7), fxt.Make_int(12), Bry_.new_a7("cls_other"), Bry_.new_a7("|caption_other"), Xoh_hzip_dict_.Escape_bry);
// fxt.Test_save(brys, "<a xtid='a_img_full' xatrs='1|1|1|12|cls_other|caption_other'/>");
//// fxt.Test_load(brys, "a_1<a href='/wiki/A' title='A'>A</a>a_2");
// }
// }
//}

View File

@@ -25,12 +25,7 @@ public class Xoh_lnke_html {
int href_bgn = lnke.Lnke_href_bgn(), href_end = lnke.Lnke_href_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
byte lnke_type = Calc_type(lnke);
if (!hctx.Mode_is_alt()) { // do not write "<a ...>" if mode is alt
if (hctx.Mode_is_hdump()) {
bfr.Add(Xoh_html_dict_.Hook__lnke); // "<a data-xotype='lnke"
bfr.Add_byte(lnke_type).Add(Bry__href);
}
else
bfr.Add(Xoh_consts.A_bgn);
bfr.Add(Xoh_consts.A_bgn);
if (Write_href(bfr, ctx, src, lnke, href_bgn, href_end, proto_is_xowa))
bfr.Add(Xoh_lnke_dict_.Html__atr__0).Add(Xoh_lnke_dict_.To_html_class(lnke_type));
bfr.Add(Xoh_lnke_dict_.Html__rhs_end);
@@ -83,9 +78,6 @@ public class Xoh_lnke_html {
html_wtr.Write_tkn(bfr, ctx, hctx, src, lnke, i, lnke.Subs_get(i));
}
}
private static final byte[]
Bry__href = Bry_.new_a7("' href=\"")
;
private static byte Calc_type(Xop_lnke_tkn lnke) {
if (lnke.Lnke_typ() == Xop_lnke_tkn.Lnke_typ_text)
return Xoh_lnke_dict_.Type__free;

View File

@@ -20,9 +20,9 @@ import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
public class Xoh_lnke_html__hdump__tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
public static final String
Html__free = "<a data-xotype='lnke1' href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>"
, Html__auto = "<a data-xotype='lnke2' href=\"http://a.org\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>"
, Html__text = "<a data-xotype='lnke3' href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">a</a>"
Html__free = "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>"
, Html__auto = "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>"
, Html__text = "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">a</a>"
;
@Test public void Free() {fxt.Test__html("http://a.org" , Html__free);}
@Test public void Auto() {fxt.Test__html("[http://a.org]" , Html__auto);}

View File

@@ -20,34 +20,12 @@ import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
public class Xoh_lnke_hzip implements Xoh_hzip_wkr {
public String Key() {return Xoh_hzip_dict_.Key__lnke;}
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {
Parse(bfr, stat_itm, parser, src, hook_bgn);
}
public void Parse(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {// EX: '<a data-xotype='lnke_bgn' data-xolnke='1' href="http://a.org" class="external text" rel="nofollow">http://a.org<!--xo.hdr--></a>'
// NOTE: not serializing caption b/c (a) caption not repeated as title and (b) finding </a> can be tricky, especially with tidy; EX: "[https://a.org b [[A]] c]"; note that lnkis can't be nested; EX: "[https://a.org b [https://b.org] c]"
int rng_bgn = hook_bgn - 2; // -2 to skip "<a"
byte lnke_type = parser.Read_byte();
parser.Chk(Byte_ascii.Apos);
int href_bgn = parser.Fwd_end(Bry__href);
int href_end = parser.Fwd_bgn(Byte_ascii.Quote);
int rng_end = parser.Fwd_end(Byte_ascii.Angle_end);
int lnke_id = 0;
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end, byte lnke_type, int href_bgn, int href_end, int lnke_id) {
switch (lnke_type) {
case Xoh_lnke_dict_.Type__free: stat_itm.Lnke_txt_add();
rng_end = parser.Fwd_end(Html_tag_.A_rhs);
break;
case Xoh_lnke_dict_.Type__text: stat_itm.Lnke_brk_text_n_add(); break;
case Xoh_lnke_dict_.Type__auto: stat_itm.Lnke_brk_text_n_add();
if (parser.Is(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
lnke_id = parser.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "<a ...>[123]</a>"
rng_end = parser.Fwd_end(Html_tag_.A_rhs);
}
break;
case Xoh_lnke_dict_.Type__free: stat_itm.Lnke_txt_add();break;
case Xoh_lnke_dict_.Type__text: stat_itm.Lnke_brk_text_y_add(); break;
case Xoh_lnke_dict_.Type__auto: stat_itm.Lnke_brk_text_n_add(); break;
}
Encode_exec(bfr, src, rng_bgn, rng_end, lnke_type, href_bgn, href_end, lnke_id);
}
public void Encode_exec(Bry_bfr bfr, byte[] src, int rng_bgn, int rng_end, byte lnke_type, int href_bgn, int href_end, int lnke_id) {
bfr.Del_by(2); // delete "<h"
bfr.Add(Xoh_hzip_dict_.Bry__lnke); // add hook
bfr.Add_byte(lnke_type); // add type
bfr.Add_mid(src, href_bgn, href_end); // add href
@@ -55,25 +33,25 @@ public class Xoh_lnke_hzip implements Xoh_hzip_wkr {
if (lnke_type == Xoh_lnke_dict_.Type__auto)
Xoh_hzip_int_.Encode(1, bfr, lnke_id);
}
public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {
byte lnke_type = parser.Read_byte();
int href_bgn = parser.Pos();
int href_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape);
bfr.Add(Xoh_html_dict_.Hook__lnke).Add_byte(lnke_type).Add_str_a7("' href=\"");
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
byte lnke_type = rdr.Read_byte();
int href_bgn = rdr.Pos();
int href_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
bfr.Add_mid(src, href_bgn, href_end);
bfr.Add(Xoh_lnke_dict_.Html__atr__0).Add(Xoh_lnke_dict_.To_html_class(lnke_type)).Add(Xoh_lnke_dict_.Html__rhs_end);
switch (lnke_type) {
case Xoh_lnke_dict_.Type__free:
bfr.Add_mid(src, href_bgn, href_end).Add(Html_tag_.A_rhs);
bfr.Add_mid(src, href_bgn, href_end).Add(Html_bldr_.Bry__a_rhs);
break;
case Xoh_lnke_dict_.Type__auto:
int lnke_id = parser.Read_int_by_base85(1);
int lnke_id = rdr.Read_int_by_base85(1);
if (lnke_id != 0) // will be 0 when reparented by tidy
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(lnke_id).Add_byte(Byte_ascii.Brack_end).Add(Html_tag_.A_rhs);
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(lnke_id).Add_byte(Byte_ascii.Brack_end).Add(Html_bldr_.Bry__a_rhs);
break;
case Xoh_lnke_dict_.Type__text:
break;
case Xoh_lnke_dict_.Type__text: break; // caption not serialized
}
return parser.Pos();
return rdr.Pos();
}
private static final byte[] Bry__href = Bry_.new_a7(" href=\"");
}

View File

@@ -31,7 +31,19 @@ public class Xoh_lnke_hzip_tst {
@Test public void Text__tidy() { // PURPOSE:handle reparenting of html elements by HTML tidy EX:<font color="red">[http://a.org]</font>; DATE:2015-08-25
fxt.Test__bicode
( "~#2http://a.org~!<font color=\"red\">[123]</font></a>"
, "<a data-xotype='lnke2' href=\"http://a.org\" rel=\"nofollow\" class=\"external autonumber\"><font color=\"red\">[123]</font></a>"
, "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external autonumber\"><font color=\"red\">[123]</font></a>"
);
}
@Test public void Fail__href() {
String html = "<a rel='nofollow' class='external autonumber'>a</a>";
fxt.Test__encode__fail(html, html);
}
@Test public void Fail__lnke_type() {
String html = "<a href='http://a.org' rel='nofollow' class='external invalid'>a</a>";
fxt.Test__encode__fail(html, html);
}
@Test public void Fail__auto() {
String html = "<a href='http://a.org' rel='nofollow' class='external autonumber'>[abc]</a>";
fxt.Test__encode__fail(html, html);
}
}

View File

@@ -1,48 +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.lnkes; 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.hrefs.*;
import gplx.xowa.htmls.core.parsers.*;
public class Xoh_lnke_parse {
public int Parse(Xoh_wkr wkr, Html_tag_rdr rdr, byte[] src, Html_tag lnke) { // <a rel="nofollow" class="external autonumber_id" href="http://a.org">[1]</a>
int tag_bgn = lnke.Src_bgn(), tag_end = lnke.Src_end();
byte[] href = lnke.Atrs__get_by(Html_atr_.Bry__href).Val();
byte[] cls = lnke.Atrs__get_by(Html_atr_.Bry__class).Val();
byte lnke_type = Parse_lnke_type(cls, 0, cls.length); if (lnke_type == Byte_ascii.Max_7_bit) return tag_end;
int autonumber_id = 0;
switch (lnke_type) {
case Xoh_lnke_dict_.Type__free:
tag_end = rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that free is not recursive; EX: "https://a.org"
break;
case Xoh_lnke_dict_.Type__text:
break;
case Xoh_lnke_dict_.Type__auto:
if (rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
autonumber_id = rdr.Read_int_to(Byte_ascii.Brack_end, 0); // extract int; EX: "<a ...>[123]</a>"
tag_end = rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that auto is not recursive; EX: "[https://a.org]"
}
break;
}
wkr.On_lnke(tag_bgn, tag_end, lnke_type, autonumber_id, href);
return tag_end;
}
private static byte Parse_lnke_type(byte[] src, int cls_bgn, int cls_end) { // "external autonumber"
int space = Bry_find_.Find_fwd(src, Byte_ascii.Space, cls_bgn, cls_end);
return Xoh_lnke_dict_.Hash.Get_as_byte_or(src, space + 1, cls_end, Byte_ascii.Max_7_bit);
}
}

View File

@@ -1,26 +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.lnkes; 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_lnke_parse_tst {
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
@Test public void Free() {
fxt.Init__lnke(0, 96, Xoh_lnke_dict_.Type__free, 0, "http://a.org");
fxt.Test__parse(Xoh_lnke_html__hdump__tst.Html__free);
}
}

View 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.core.wkrs.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
public class Xoh_lnke_parser {
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, Html_tag anch) {// <a rel="nofollow" class="external autonumber_id" href="http://a.org">[1]</a>
int rng_bgn = anch.Src_bgn(), rng_end = anch.Src_end();
Html_atr href_atr = anch.Atrs__get_by(Html_atr_.Bry__href);
int href_bgn = href_atr.Val_bgn(), href_end = href_atr.Val_end();
byte lnke_type = anch.Atrs__cls_find_1st(Xoh_lnke_dict_.Hash);
int autonumber_id = 0;
switch (lnke_type) {
case Xoh_lnke_dict_.Type__free:
rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that free is not recursive; EX: "https://a.org"
break;
case Xoh_lnke_dict_.Type__text:
break;
case Xoh_lnke_dict_.Type__auto:
if (tag_rdr.Read_and_move(Byte_ascii.Brack_bgn)) { // HTML tidy can reparent lnkes in strange ways; DATE:2015-08-25
autonumber_id = tag_rdr.Read_int_to(Byte_ascii.Brack_end); // extract int; EX: "<a ...>[123]</a>"
rng_end = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a).Src_end(); // find '</a>'; note that auto is not recursive; EX: "[https://a.org]"
}
break;
}
hdoc_wkr.On_lnke(rng_bgn, rng_end, lnke_type, autonumber_id, href_bgn, href_end);
return rng_end;
}
}

View File

@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.xowa.htmls.core.parsers.*;
import gplx.core.brys.*;
public class Xoh_lnki_dict_ {
public static final byte // SERIALIZED
Type__caption_n = Byte_ascii.Num_0
@@ -25,4 +25,10 @@ public class Xoh_lnki_dict_ {
, Type__diff = Xoh_ttl_matcher.Tid__diff // EX: [[A|b]]
, Type__trail = Xoh_ttl_matcher.Tid__trail // EX: [[A|b]]
;
public static void Ns_encode(Bry_bfr bfr, Xoa_ttl ttl) {
gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Encode(1, bfr, ttl.Ns().Id() + 2);
}
public static int Ns_decode(Bry_rdr rdr) {
return rdr.Read_int_by_base85(1) - 2;
}
}

View File

@@ -20,10 +20,10 @@ import org.junit.*; import gplx.xowa.htmls.core.makes.tests.*;
public class Xoh_lnki_html__hdump__tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
public static final String
Html__same = "<a data-xotype='lnki0' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\">A</a>"
, Html__diff = "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\">b</a>"
, Html__trail = "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\">Ab</a>"
, Html__xwiki = "<a data-xotype='lnki0' href=\"/site/en.wiktionary.org/wiki/A\" id=\"xowa_lnki_2\" title=\"A\">wikt:A</a>"
Html__same = "<a href='/wiki/A' id='xowa_lnki_2' title='A'>A</a>"
, Html__diff = "<a href='/wiki/A' id='xowa_lnki_2' title='A'>b</a>"
, Html__trail = "<a href='/wiki/A' id='xowa_lnki_2' title='A'>Ab</a>"
, Html__xwiki = "<a href='/site/en.wiktionary.org/wiki/A' id='xowa_lnki_2' title='A'>wikt:A</a>"
;
@Before public void init() {fxt.Clear();}
@Test public void Same() {fxt.Test__html("[[A]]" , Html__same);}

View File

@@ -17,135 +17,91 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.hzips.stats.*;
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.lnkes.*;
public class Xoh_lnki_hzip implements Xoh_hzip_wkr {
private Xow_ttl_parser ttl_parser;
public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser;}
private Xow_ttl_parser ttl_parser; private int uid;
public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser; this.uid = 1;} // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
public String Key() {return Xoh_hzip_dict_.Key__lnki;}
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {Parse(bfr, stat_itm, parser, src, hook_bgn);}
public int Parse(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {
int rng_bgn = hook_bgn - 2; // -2 to skip "<a"
byte lnki_type = parser.Read_byte();
int page_bgn = parser.Fwd_end(Bry__href);
int site_bgn = -1, site_end = -1;
Object href_tid_obj = btrie_href.Match_bgn(src, parser.Pos(), parser.Src_len()); // if (href_tid_obj == null) return rdr.Warn("lnki.decode:unknown href format", bgn, pos); // not "/wiki/" or "/site/"
if (((Byte_obj_val)href_tid_obj).Val() == Href_tid_site) { // site; EX:"/site/en.wiktionary.org/"
site_bgn = parser.Pos_add(Xoh_href_.Len__site);
site_end = parser.Fwd_bgn(Byte_ascii.Slash);
}
else { // page; EX: "/wiki/Page"
page_bgn = parser.Chk(Xoh_href_.Bry__wiki);
}
int page_end = parser.Fwd_bgn(Byte_ascii.Quote);
parser.Fwd_end(Bry__id);
int uid = parser.Read_int_to(Byte_ascii.Quote);
int title_bgn = parser.Fwd_end(Bry__title);
int title_end = parser.Fwd_bgn(Byte_ascii.Quote);
int caption_bgn = -1, caption_end = -1, rng_end = -1;
if (lnki_type == Xoh_lnki_dict_.Type__caption_n) {
caption_bgn = parser.Fwd_end(Byte_ascii.Angle_end);
caption_end = parser.Fwd_bgn(Html_tag_.A_rhs);
rng_end = parser.Pos();
}
else
rng_end = parser.Chk(Byte_ascii.Angle_end);
// if (id_bgn > rng_end) return Xoh_hzip_dict_.Unhandled; // TODO: handle "jumping" over one "<a" to another
boolean site_exists = site_end - site_bgn > 0;
if ( lnki_type == Xoh_lnki_dict_.Type__caption_n // lnki_text_n; EX: [[A]] not [[A|A1]]
&& !site_exists // not xwiki; EX: [[wikt:A]]
&& (page_end - page_bgn) != (caption_end - caption_bgn) // note that in 99% of lnki_text_n cases, html_text_len == text_len; however, tidy sometimes relocates html inside html_text; PAGE:en.w:Abyssal_plain; EX:<font color='green'>[[A]]</font>; DATE:2015-06-02
) {
lnki_type = Xoh_lnki_dict_.Type__caption_y; // change to lnki_text_y
parser.Pos_(caption_bgn);
}
Parse_done(bfr, parser, null, ttl_parser, stat_itm, src, lnki_type, rng_bgn, rng_end, site_exists, site_bgn, site_end, page_bgn, page_end, uid, title_bgn, title_end, caption_bgn, caption_end);
return parser.Pos();
}
public void Parse_done(Bry_bfr bfr, Bry_parser parser, Bry_rdr rdr, Xow_ttl_parser ttl_parser, Hzip_stat_itm stat_itm, byte[] src, byte lnki_type, int rng_bgn, int rng_end, boolean site_exists, int site_bgn, int site_end, int page_bgn, int page_end, int uid, int title_bgn, int title_end, int caption_bgn, int caption_end) {
Xoa_ttl ttl = ttl_parser.Ttl_parse(Bry_.Mid(src, page_bgn, page_end)); if (ttl == null) throw parser.Fail("lnki.decode:invalid ttl", String_.new_u8(src, page_bgn, page_end));
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, Xoh_lnki_parser arg) {
byte lnki_type = arg.Lnki_type();
Xoa_ttl page_ttl = arg.Anch_href_parser().Page_ttl();
bfr.Add(Xoh_hzip_dict_.Bry__lnki);
bfr.Add_byte(lnki_type);
Xoh_hzip_int_.Encode(1, bfr, ttl.Ns().Id());
Xoh_hzip_int_.Encode(1, bfr, uid);
if (site_exists)
bfr.Add_byte(Xoh_hzip_dict_.Escape).Add_mid(src, site_bgn, site_end).Add_byte(Xoh_hzip_dict_.Escape);
if (lnki_type == Xoh_lnki_dict_.Type__caption_y) {
bfr.Add(ttl.Page_db());
bfr.Add_byte(Xoh_hzip_dict_.Escape);
stat_itm.Lnki_text_y_add();
}
else {
if (!ttl.Ns().Id_main()) // non-main ns should write page_db only; EX: "Template:A" should write "A" since "Template" will be inferred by ns_id
bfr.Add(ttl.Page_db());
else // main ns should write html_text; handles [[a]] which has <a href="A">a</a>
bfr.Add_mid(src, caption_bgn, caption_end);
bfr.Add_byte(Xoh_hzip_dict_.Escape);
stat_itm.Lnki_text_n_add();
Xoh_hzip_int_.Encode(1, bfr, page_ttl.Ns().Ord()); // NOTE: ord b/c Xoh_int does not support negative numbers
// if (site_end - site_bgn > 0)
// bfr.Add_byte(Xoh_hzip_dict_.Escape).Add_mid(src, site_bgn, site_end).Add_byte(Xoh_hzip_dict_.Escape);
switch (lnki_type) {
case Xoh_lnki_dict_.Type__same:
stat_itm.Lnki_text_n_add();
byte[] ttl_bry = page_ttl.Ns().Id_is_main()
? arg.Capt_bry() // main ns should write html_text; handles [[a]] with html of '<a href="A">a</a>'
: page_ttl.Page_db(); // non-main ns should write page_db only; EX: "Template:A" should write "A" since "Template" will be inferred by ns_id
bfr.Add(ttl_bry).Add_byte(Xoh_hzip_dict_.Escape);
break;
case Xoh_lnki_dict_.Type__diff:
stat_itm.Lnki_text_y_add();
bfr.Add(arg.Anch_href_parser().Page_bry());
bfr.Add_byte(Xoh_hzip_dict_.Escape);
bfr.Add(arg.Capt_bry());
bfr.Add_byte(Xoh_hzip_dict_.Escape);
break;
case Xoh_lnki_dict_.Type__trail:
bfr.Add(arg.Capt_bry());
bfr.Add_byte(Xoh_hzip_dict_.Escape);
bfr.Add(arg.Trail_bry());
bfr.Add_byte(Xoh_hzip_dict_.Escape);
break;
}
}
public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {
// parse vars
byte lnki_type = parser.Read_byte();
int ns_id = parser.Read_int_by_base85(1);
int uid = parser.Read_int_by_base85(1);
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
byte lnki_type = rdr.Read_byte();
int ns_ord = rdr.Read_int_by_base85(1);
int site_bgn = -1, site_end = -1;
if (parser.Is(Xoh_hzip_dict_.Escape)) {
site_bgn = parser.Pos();
site_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape);
if (rdr.Is(Xoh_hzip_dict_.Escape)) {
site_bgn = rdr.Pos();
site_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
}
boolean site_exists = site_end - site_bgn > 0;
int page_bgn = parser.Pos();
int page_end = parser.Fwd_bgn(Xoh_hzip_dict_.Escape);
int page_bgn = rdr.Pos();
int page_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
int capt_bgn = -1, capt_end = -1;
if (lnki_type != Xoh_lnki_dict_.Type__same) {
capt_bgn = rdr.Pos();
capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
}
byte[] page_bry = Bry_.Mid(src, page_bgn, page_end);
Xoa_ttl ttl = ttl_parser.Ttl_parse(ns_id, page_bry); if (ttl == null) throw parser.Fail("invalid ttl", String_.new_u8(page_bry)); // TODO: parse title based on site
Xow_ns ns = ttl_parser.Ns_mgr().Ords_get_at(ns_ord);
Xoa_ttl ttl = ttl_parser.Ttl_parse(ns.Id(), page_bry); if (ttl == null) rdr.Fail("invalid ttl", String_.Empty, String_.new_u8(page_bry)); // TODO: parse title based on site
byte[] ttl__full_db = ttl.Full_db();
// gen html
bfr.Add(Xoh_html_dict_.Hook__lnki);
bfr.Add_byte(lnki_type);
bfr.Add_str_a7("' href=\"");
if (site_exists) bfr.Add_str_a7("/site/").Add_mid(src, site_bgn, site_end);
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
if (site_exists) bfr.Add(Xoh_href_.Bry__wiki).Add_mid(src, site_bgn, site_end);
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
bfr.Add(Html_utl.Escape_html_as_bry(ttl__full_db));
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(uid);
bfr.Add(ttl.Full_db());
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(++uid);
bfr.Add_str_a7("\" title=\"");
if (lnki_type == Xoh_lnki_dict_.Type__caption_n) {
byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">");
if (ns_id != 0) page_bry = ttl.Full_db();
bfr.Add(page_bry);
bfr.Add(Html_tag_.A_rhs); // "</a>"
byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">");
switch (lnki_type) {
case Xoh_lnki_dict_.Type__same:
if (ttl.Ns().Id_is_main())
bfr.Add_mid(src, page_bgn, page_end);
else
bfr.Add(ttl.Full_txt());
break;
case Xoh_lnki_dict_.Type__diff:
bfr.Add_mid(src, capt_bgn, capt_end);
break;
case Xoh_lnki_dict_.Type__trail:
bfr.Add_mid(src, page_bgn, page_end);
bfr.Add_mid(src, capt_bgn, capt_end);
break;
}
else {
bfr.Add(Html_utl.Escape_html_as_bry(page_bry));
bfr.Add_str_a7("\">");
}
return parser.Pos();
bfr.Add_str_a7("</a>");
return rdr.Pos();
}
private static final byte[]
Bry__href = Bry_.new_a7(" href=\"")
, Bry__id = Bry_.new_a7(" id=\"xowa_lnki_")
, Bry__title = Bry_.new_a7(" title=\"")
;
private static final byte Href_tid_wiki = 1, Href_tid_site = 2;
private static final Btrie_fast_mgr btrie_href = Btrie_fast_mgr.cs().Add_bry_byte(Xoh_href_.Bry__wiki, Href_tid_wiki).Add_bry_byte(Xoh_href_.Bry__site, Href_tid_site);
// , Find_img_xatrs = Bry_.new_a7("xatrs='")
// private static int[] Save_img_full_pow = new int[] {0, 1, 2};
// private int Save_img_full(Bry_bfr bfr, Bry_rdr rdr, Hzip_stat_itm stat_itm, byte[] src, int src_len, int bgn, int pos) {
// bfr.Add(Xoh_hzip_dict_.Bry__img_full);
// int xatrs_bgn = Bry_find_.Move_fwd(src, Find_img_xatrs, pos, src_len); if (xatrs_bgn == Bry_find_.Not_found) return rdr.Warn("a.img_xatrs_missing", bgn, pos);
// bry_rdr.Init(src, xatrs_bgn);
// int a_cls = bry_rdr.Read_int_to_pipe();
// int a_rel = bry_rdr.Read_int_to_pipe();
// int img_rel = bry_rdr.Read_int_to_pipe();
// byte meta = (byte)Bit_.Shift_lhs_to_int(Save_img_full_pow, a_cls, a_rel, img_rel);
// bfr.Add_byte(meta); // meta
// Xoh_hzip_int_.Encode(bfr, bry_rdr.Read_int_to_pipe()); // uid
// bfr.Add(bry_rdr.Read_bry_to_pipe()).Add_byte_pipe(); // img_cls_other
// bfr.Add(bry_rdr.Read_bry_to_apos()); // alt
// bfr.Add_byte(Xoh_hzip_dict_.Escape);
// return bry_rdr.Pos() + 2; // +2=/>
// }
}

View File

@@ -19,42 +19,38 @@ package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; impo
import org.junit.*; import gplx.xowa.htmls.core.hzips.tests.*;
public class Xoh_lnki_hzip_tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
@Test public void Noop() {
String html = "<a href='/wiki/A'>A";
fxt.Test__bicode(html, html);
@Test public void Page__basic() {
fxt.Test__bicode("~$1#A~", Xoh_lnki_html__hdump__tst.Html__same);
}
@Test public void Lnki__basic() {
fxt.Test__bicode("~$0!#A~", Xoh_lnki_html__hdump__tst.Html__same);
@Test public void Page__alt_case() {
fxt.Test__bicode("~$1#a~", "<a href='/wiki/A' id='xowa_lnki_2' title='A'>a</a>");
}
@Test public void Lnki__alt_case() {
fxt.Test__bicode("~$0!#a~", "<a data-xotype='lnki0' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\">a</a>");
@Test public void Page__ns() {
fxt.Test__bicode("~$1-A~", "<a href='/wiki/Template:A' id='xowa_lnki_2' title='Template:A'>Template:A</a>");
}
@Test public void Lnki__ns() {
fxt.Test__bicode("~$0+#A~", "<a data-xotype='lnki0' href=\"/wiki/Template:A\" id=\"xowa_lnki_2\" title=\"Template:A\">Template:A</a>");
@Test public void Capt__basic() {
fxt.Test__bicode("~$2#A~b~", Xoh_lnki_html__hdump__tst.Html__diff);
}
@Test public void Capt__nest() {
fxt.Test__bicode
( "~$2#A~<a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D~"
, "<a href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a href=\"/wiki/C\" id=\"xowa_lnki_3\" title=\"C\">C1</a>D</a>"
);
// old: probably broken; fxt.Test__bicode("~$1!#A~~$1!#C~C1</a>D</a>", "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a data-xotype='lnki1' href=\"/wiki/C\" id=\"xowa_lnki_2\" title=\"C\">C1</a>D</a>");
}
@Test public void Trail__basic() {
fxt.Test__bicode("~$3#A~b~", Xoh_lnki_html__hdump__tst.Html__trail);
}
// @Test public void Capt__site__xwiki() {
// fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org");
// fxt.Test__bicode("~$2!A~wikt:A~", Xoh_lnki_html__hdump__tst.Html__xwiki);
// }
// @Test public void Lnki__apos() {
// fxt.Test__bicode("~$0+#A'b~", "<a data-xotype='lnki0' href=\"/wiki/Template:A&#39;b\" id=\"xowa_lnki_2\" title=\"Template:A&#39;b\">Template:A'b</a>");
// }
@Test public void Lnki__xwiki() {
fxt.Parser_fxt().Init_xwiki_add_wiki_and_user_("wikt", "en.wiktionary.org");
fxt.Test__bicode("~$0!#~en.wiktionary.org~wikt:A~", Xoh_lnki_html__hdump__tst.Html__xwiki);
}
@Test public void Caption__basic() {
fxt.Test__bicode("~$1!#A~b</a>", Xoh_lnki_html__hdump__tst.Html__diff);
}
@Test public void Caption__nest() {
fxt.Test__bicode("~$1!#A~~$1!#C~C1</a>D</a>", "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><a data-xotype='lnki1' href=\"/wiki/C\" id=\"xowa_lnki_2\" title=\"C\">C1</a>D</a>");
}
// @Test public void Caption__multiple() { // PURPOSE: if id is missing from 1st anchor, do not get from second
// String hzip = Xoh_hzip_fxt.Escape("$0!#A");
// String html = "<a data-xotype='lnki0' href=\"/wiki/A\" title=\"A\">A</a><a data-xotype='lnki0' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"B\">B</a>";
// fxt.Test__encode(hzip, html);
//// fxt.Test_save(brys, "<a xtid='a_lnki_text_n' href=\"/wiki/A\" title=\"A\">A</a><a xtid='a_lnki_text_n' href=\"/wiki/B\" id=\"xowa_lnki_3\" title=\"B\">B</a>");
//// fxt.Test_load(brys, "<a xtid='a_lnki_text_n' href=\"/wiki/A\" title=\"A\">A</a><a href='/wiki/B' id='xowa_lnki_3' title='B'>B</a>");
// @Test public void Caption__reparent() { // PURPOSE: PAGE:en.w:Abyssal_plain; DATE:2015-06-02
// String hzip = Xoh_hzip_fxt.Escape("~$1!#A~<font color='white'>A1</font></a>");
// fxt.Test__encode(hzip, "<a data-xotype='lnki0' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><font color='white'>A1</font></a>");
// fxt.Test__decode(hzip, "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><font color='white'>A1</font></a>");
// }
@Test public void Caption__reparent() { // PURPOSE: PAGE:en.w:Abyssal_plain; DATE:2015-06-02
String hzip = Xoh_hzip_fxt.Escape("~$1!#A~<font color='white'>A1</font></a>");
fxt.Test__encode(hzip, "<a data-xotype='lnki0' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><font color='white'>A1</font></a>");
fxt.Test__decode(hzip, "<a data-xotype='lnki1' href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\"><font color='white'>A1</font></a>");
}
}

View File

@@ -1,60 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.parsers.*;
public class Xoh_lnki_parse {
public int Parse(Xoh_wkr wkr, Html_tag_rdr rdr, byte[] src, Html_tag lnki, Xow_ttl_parser ttl_parser) {// <a href="/wiki/A" title="A">b</a>
int tag_bgn = lnki.Src_bgn(), tag_end = lnki.Src_end();
Html_atr href_atr = lnki.Atrs__get_by(Html_atr_.Bry__href);
int href_pos = href_atr.Val_bgn();
int site_bgn = href_pos + Xoh_href_.Len__site, site_end = -1;
if (href_hash.Get_as_int_or(src, href_pos, site_bgn, -1) == Href_tid__site) // site; EX:"/site/en.wiktionary.org/"
site_end = href_pos = Bry_find_.Find_fwd(src, Byte_ascii.Slash, site_bgn);
else
site_bgn = -1;
int page_bgn = href_pos + Xoh_href_.Len__wiki, page_end = href_atr.Val_end();
if (href_hash.Get_as_int_or(src, href_pos, page_bgn, -1) != Href_tid__wiki) // site; EX:"/site/en.wiktionary.org/"
throw Err_.new_("Xoh_parser", "invalid url", "url", String_.new_u8(src, href_pos, page_bgn));
// Html_atr title_atr = lnki.Atrs__get_by(Html_atr_.Bry__title);
// int title_bgn = title_atr.Val_bgn(), title_end = title_atr.Val_end();
Html_tag lnki_tail = rdr.Tag__move_fwd_tail(Html_tag_.Id__a);
int capt_bgn = tag_end; int capt_end = lnki_tail.Src_bgn();
tag_end = lnki_tail.Src_end();
byte lnki_type = ttl_matcher.Match(ttl_parser, src, page_bgn, page_end, src, capt_bgn, capt_end);
byte[] page_bry = null, capt_bry = null, trail_bry = null;
switch (lnki_type) {
case Xoh_ttl_matcher.Tid__diff:
page_bry = Bry_.Mid(src, page_bgn, page_end);
capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
break;
case Xoh_ttl_matcher.Tid__same:
capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
break;
case Xoh_ttl_matcher.Tid__trail:
capt_bry = Bry_.Mid(src, capt_bgn, ttl_matcher.Trail_bgn());
trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), capt_end);
break;
}
wkr.On_lnki(tag_bgn, tag_end, lnki_type, site_bgn, site_end, page_bry, capt_bry, trail_bry);
return tag_end;
}
private static final int Href_tid__wiki = 1, Href_tid__site = 2;
private static final Hash_adp_bry href_hash = Hash_adp_bry.ci_a7().Add_bry_int(Xoh_href_.Bry__wiki, Href_tid__wiki).Add_bry_int(Xoh_href_.Bry__site, Href_tid__site);
private final Xoh_ttl_matcher ttl_matcher = new Xoh_ttl_matcher();
}

View File

@@ -1,38 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.xowa.htmls.core.parsers.*;
public class Xoh_lnki_parse_tst {
private final Xoh_parser_fxt fxt = new Xoh_parser_fxt();
@Test public void Same() {
fxt.Init__lnki(0, 70, Xoh_lnki_dict_.Type__same, -1, -1, "", "A", "");
fxt.Test__parse(Xoh_lnki_html__hdump__tst.Html__same);
}
@Test public void Diff() {
fxt.Init__lnki(0, 70, Xoh_lnki_dict_.Type__diff, -1, -1, "A", "b", "");
fxt.Test__parse(Xoh_lnki_html__hdump__tst.Html__diff);
}
@Test public void Trail() {
fxt.Init__lnki(0, 71, Xoh_lnki_dict_.Type__trail, -1, -1, "", "A", "b");
fxt.Test__parse(Xoh_lnki_html__hdump__tst.Html__trail);
}
@Test public void Recurse() {
// fxt.Init__lnki(0, 69, Xoh_lnki_dict_.Type__caption_n, -1, -1, "A");
// fxt.Test__parse("<a href=\"/wiki/A\" id=\"xowa_lnki_2\" title=\"A\">A<a href=\"/wiki/B\" id=\"xowa_lnki_2\" title=\"B\">b</a>c</a>");
}
}

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*; import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
import gplx.xowa.wikis.ttls.*;
public class Xoh_lnki_parser {
private final Xoh_ttl_matcher ttl_matcher = new Xoh_ttl_matcher();
private final Bry_rdr rdr = new Bry_rdr();
public int Rng_bgn() {return rng_bgn;} private int rng_bgn;
public int Rng_end() {return rng_end;} private int rng_end;
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
public byte[] Capt_bry() {return capt_bry;} private byte[] capt_bry;
public byte[] Trail_bry() {return trail_bry;} private byte[] trail_bry;
public Xoh_anch_href_parser Anch_href_parser() {return anch_href_parser;} private final Xoh_anch_href_parser anch_href_parser = new Xoh_anch_href_parser();
public int Parse(Xoh_hdoc_wkr wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag anch_tag, Xow_ttl_parser ttl_parser) {// <a href="/wiki/A" title="A">b</a>
this.rng_bgn = anch_tag.Src_bgn(); this.rng_end = anch_tag.Src_end();
rdr.Ctor_by_page(Bry_.Empty, src, src.length);
anch_href_parser.Parse(rdr, wkr.Ctx().Wiki(), anch_tag); // href='/wiki/A'
Html_tag lnki_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__a); // </a>
int capt_bgn = rng_end; int capt_end = lnki_tail.Src_bgn(); // get capt between "<a>" and "</a>
this.rng_end = lnki_tail.Src_end();
this.lnki_type = ttl_matcher.Match(rdr, ttl_parser, src, anch_href_parser.Page_bgn(), anch_href_parser.Page_end(), src, capt_bgn, capt_end);
this.capt_bry = trail_bry = null;
switch (lnki_type) {
case Xoh_ttl_matcher.Tid__same:
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
break;
case Xoh_ttl_matcher.Tid__diff:
this.capt_bry = Bry_.Mid(src, capt_bgn, capt_end);
break;
case Xoh_ttl_matcher.Tid__trail:
this.capt_bry = Bry_.Mid(src, capt_bgn, ttl_matcher.Trail_bgn());
this.trail_bry = Bry_.Mid(src, ttl_matcher.Trail_bgn(), capt_end);
break;
}
wkr.On_lnki(this);
return rng_end;
}
}

View File

@@ -15,17 +15,19 @@ 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.*;
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.ttls.*;
import gplx.langs.htmls.parsers.*;
public class Xoh_ttl_matcher {
public int Trail_bgn() {return trail_bgn;} private int trail_bgn;
public byte Match(Xow_ttl_parser ttl_parser, byte[] page_bry, int page_bgn, int page_end, byte[] capt_bry, int capt_bgn, int capt_end) {
public byte Match(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, byte[] page_bry, int page_bgn, int page_end, byte[] capt_bry, int capt_bgn, int capt_end) {
trail_bgn = -1;
int page_len = page_end - page_bgn;
Xoa_ttl page = ttl_parser.Ttl_parse(page_bry, page_bgn, page_end); if (page == null) throw Err_.new_("", "invalid page", "page", page_bry);
int page_len = page_end - page_bgn; if (page_len == 0) page_bry = Xoa_page_.Main_page_bry; // NOTE: href="/site/en.wikipedia.org/wiki/" can be null
Xoa_ttl page = ttl_parser.Ttl_parse(page_bry, page_bgn, page_end); if (page == null) owner_rdr.Fail("invalid page", "page", page_bry);
Xow_ns ns = page.Ns();
if (ns.Id() != Xow_ns_.Id_main) {
byte[] ns_name_txt = ns.Name_txt_w_colon(); // EX: 11="Template talk:"
if (ns.Id() != Xow_ns_.Tid__main) {
byte[] ns_name_txt = ns.Name_ui_w_colon(); // EX: 11="Template talk:"
int ns_name_txt_len = ns_name_txt.length;
int ns_name_txt_end = capt_bgn + ns_name_txt_len;
if (Bry_.Match(capt_bry, capt_bgn, ns_name_txt_end, ns_name_txt, 0, ns_name_txt_len))

View File

@@ -15,8 +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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
import org.junit.*;
package gplx.xowa.htmls.core.wkrs.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import org.junit.*; import gplx.core.brys.*; import gplx.langs.htmls.parsers.*;
public class Xoh_ttl_matcher_tst {
private final Xoh_ttl_matcher_fxt fxt = new Xoh_ttl_matcher_fxt();
@Test public void Basic__same() {fxt.Test__match("Abc" , "Abc", Xoh_ttl_matcher.Tid__same);}
@@ -34,6 +34,7 @@ public class Xoh_ttl_matcher_tst {
}
class Xoh_ttl_matcher_fxt {
private final Xoh_ttl_matcher matcher = new Xoh_ttl_matcher();
private final Bry_rdr rdr = new Bry_rdr();
public Xoh_ttl_matcher_fxt() {
Xoae_app app = Xoa_app_fxt.app_();
this.wiki = Xoa_app_fxt.wiki_tst_(app);
@@ -43,7 +44,7 @@ class Xoh_ttl_matcher_fxt {
public void Test__match(String page_str, String capt_str, int expd_tid, int expd_trail_bgn) {
byte[] page_bry = Bry_.new_u8(page_str);
byte[] capt_bry = Bry_.new_u8(capt_str);
Tfds.Eq_int(expd_tid , matcher.Match(wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length));
Tfds.Eq_int(expd_tid , matcher.Match(rdr.Ctor_by_page(Bry_.Empty, page_bry, page_bry.length), wiki, page_bry, 0, page_bry.length, capt_bry, 0, capt_bry.length));
Tfds.Eq_int(expd_trail_bgn , matcher.Trail_bgn());
}
}

View File

@@ -0,0 +1,65 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import gplx.core.brys.*; import gplx.core.btries.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import gplx.xowa.wikis.ttls.*;
public class Xoh_anch_href_parser implements Xoh_itm_parser {
private byte[] src; private Xoa_ttl page_ttl; Xow_ttl_parser ttl_parser;
private final Bry_rdr rdr = new Bry_rdr();
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
public int Val_bgn() {return val_bgn;} private int val_bgn;
public int Val_end() {return val_end;} private int val_end;
public int Site_bgn() {return site_bgn;} private int site_bgn;
public int Site_end() {return site_end;} private int site_end;
public boolean Site_exists() {return site_end > site_bgn;}
public int Page_bgn() {return page_bgn;} private int page_bgn;
public int Page_end() {return page_end;} private int page_end;
public byte[] Page_bry() {if (page_bry == null) page_bry = Bry_.Mid(src, page_bgn, page_end); return page_bry;} private byte[] page_bry;
public Xoa_ttl Page_ttl() {
if (page_ttl == null) {
page_bry = this.Page_bry();
page_ttl = ttl_parser.Ttl_parse(page_bry);
}
return page_ttl;
}
public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, Html_tag tag) {
Html_atr atr = tag.Atrs__get_by(Html_atr_.Bry__href);
Parse(owner_rdr, ttl_parser, atr.Val_bgn(), atr.Val_end());
}
public void Parse(Bry_rdr owner_rdr, Xow_ttl_parser ttl_parser, int href_bgn, int href_end) {
rdr.Init_by_sub(owner_rdr, "lnki.href", href_bgn, href_end).Dflt_dlm_(Byte_ascii.Slash);
site_bgn = -1; site_end = -1; page_bry = null; page_ttl = null;
this.val_bgn = href_bgn; this.val_end = href_end;
this.src = owner_rdr.Src(); this.ttl_parser = ttl_parser;
rdr.Chk(Byte_ascii.Slash);
if (rdr.Chk(trie) == Href_tid__site) { // EX: // "/site/wiki/A"
site_bgn = rdr.Pos();
site_end = rdr.Find_fwd_lr();
rdr.Chk(Bry__wiki);
}
page_bgn = rdr.Pos();
page_end = rdr.Src_end();
}
private static final byte Href_tid__wiki = 1, Href_tid__site = 2;
private static final byte[] Bry__site = Bry_.new_a7("site/"), Bry__wiki = Bry_.new_a7("wiki/");
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_bry_byte(Bry__wiki, Href_tid__wiki)
.Add_bry_byte(Bry__site, Href_tid__site)
;
}

View File

@@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*;
public class Xoh_anch_href_parser_tst {
private final Xoh_anch_href_parser_fxt fxt = new Xoh_anch_href_parser_fxt();
@Test public void Site() {
fxt.Test__parse("/site/A/wiki/B", "A", "B");
}
@Test public void Page() {
fxt.Test__parse("/wiki/B", "", "B");
}
@Test public void Fail__1st_seg_must_be_site_or_wiki() {
fxt.Test__parse__fail("/fail/A", "failed trie check: mid='fail/A' ctx='Main_Page' wkr='lnki.href' excerpt='/fail/A'");
}
@Test public void Fail__2nd_seg_must_be_wiki() {
fxt.Test__parse__fail("/site/A/B/C", "failed check: chk='wiki/' ctx='Main_Page' wkr='lnki.href' excerpt='/site/A/B/C'");
}
}
class Xoh_anch_href_parser_fxt extends Xoh_itm_parser_fxt_base {
private final Xoh_anch_href_parser parser = new Xoh_anch_href_parser();
private final Xow_ttl_parser ttl_parser;
public Xoh_anch_href_parser_fxt() {
Xoae_app app = Xoa_app_fxt.app_();
ttl_parser = Xoa_app_fxt.wiki_tst_(app);
}
@Override public Xoh_itm_parser Parser_get() {return parser;}
public void Test__parse(String src_str, String expd_site, String expd_page) {
Exec_parse(src_str);
Tfds.Eq_str(expd_site, parser.Site_bgn() == -1 ? "" : String_.new_u8(src, parser.Site_bgn(), parser.Site_end()));
Tfds.Eq_str(expd_page, String_.new_u8(src, parser.Page_bgn(), parser.Page_end()));
}
@Override public void Exec_parse_hook(Bry_rdr owner_rdr, int src_bgn, int src_end) {
parser.Parse(owner_rdr, ttl_parser, src_bgn, src_end);
}
}

View File

@@ -26,6 +26,6 @@ public class Xoh_arg_img_core__hdump implements Xoh_arg_img_core {
bfr.Add_byte_space();
bfr.Add(gplx.xowa.htmls.core.makes.Xoh_make_trie_.Bry__img);
bfr.Add_int_variable(uid);
bfr.Add_byte_apos();
bfr.Add_byte_quote();
}
}

View File

@@ -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.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*;
import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.lnkis.*;
public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
private final Xoh_arg_img_core arg_img_core;
protected final Xoh_arg_img_core arg_img_core;
private Bry_bfr scratch_bfr = Bry_bfr.reset_(128);
public Xoh_file_html_fmtr__base() {
arg_img_core = New_arg_img_core();
@@ -38,7 +38,7 @@ public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
) {
fmtr_full_img.Bld_bfr_many(tmp_bfr, uid
, a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title, a_xowa_title
, arg_img_core.Init(uid, img_src, img_w, img_h), img_alt, Xoh_lnki_consts.Img_cls_to_bry(img_cls, img_cls_other));
, arg_img_core.Init(uid, img_src, img_w, img_h), img_alt, Xoh_img_cls_.To_html(img_cls, img_cls_other));
}
private Bry_fmtr fmtr_full_img = Bry_fmtr.new_
( "<a href=\"~{a_href}\"~{a_class}~{a_rel}~{a_title} xowa_title=\"~{a_xowa_title}\">"

View File

@@ -18,38 +18,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import gplx.langs.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*;
import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
public class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
private Bry_bfr tmp_bfr = Bry_bfr.reset_(128);
@gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();}
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(128);
@Override public void Html_full_img(Bry_bfr bfr, gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx hctx, Xoae_page page, Xof_file_itm xfer_itm, int uid, byte[] a_href, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other) {
tmp_bfr.Add_str_a7(" data-xoimg=\"");
tmp_bfr.Add_int_digits(1, xfer_itm.Lnki_type()).Add_byte_pipe();
tmp_bfr.Add_int_variable(xfer_itm.Lnki_w()).Add_byte_pipe();
tmp_bfr.Add_int_variable(xfer_itm.Lnki_h()).Add_byte_pipe();
tmp_bfr.Add_double(xfer_itm.Lnki_upright()).Add_byte_pipe();
tmp_bfr.Add_double(xfer_itm.Lnki_time()).Add_byte_pipe();
tmp_bfr.Add_int_variable(xfer_itm.Lnki_page()).Add_byte_quote();
fmtr__img__full.Bld_bfr_many(bfr
, a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title
, img_alt, tmp_bfr.To_bry_and_clear(), arg_img_core.Init(uid, img_src, img_w, img_h), Xoh_img_cls_.To_html(img_cls, img_cls_other));
}
private Bry_fmtr fmtr__img__full = Bry_fmtr.new_
( "<a href=\"~{a_href}\"~{a_class}~{a_rel}~{a_title}>"
+ "<img alt=\"~{img_alt}\"~{img_xoimg}~{img_core}~{img_class}/>"
+ "</a>"
, "a_href", "a_class", "a_rel", "a_title", "img_alt", "img_xoimg", "img_core", "img_class"
);
// public override void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bry_fmtr_arg html) {
// fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html);
// }
// public override void Html_full_img(Bry_bfr tmp_bfr, Xoh_wtr_ctx hctx, Xoae_page page, Xof_file_itm xfer_itm, int uid
// , byte[] a_href, byte a_cls, byte a_rel, byte[] a_title, byte[] a_xowa_title
// , int img_w, int img_h, byte[] img_src, byte[] img_alt, byte img_cls, byte[] img_cls_other) {
// tmp_bfr.Add_str_a7("<a xtid='a_img_full' xatrs='");
// tmp_bfr.Add_str_a7(a_cls == Xoh_lnki_consts.Tid_a_cls_none ? "0|" : "1|"); // a_cls : "" || image
// tmp_bfr.Add_str_a7(a_rel == Xoh_lnki_consts.Tid_a_rel_none ? "0|" : "1|"); // a_rel : "" || nofollow
// tmp_bfr.Add_int_fixed(img_cls, 1).Add_byte_pipe(); // img_cls : "" || thumbborder || thumbimage || other
// tmp_bfr.Add_int_variable(uid).Add_byte_pipe(); // uid
// tmp_bfr.Add_safe(img_cls_other).Add_byte_pipe(); // img_cls_other : "" || {other}
// Html_utl.Escape_html_to_bfr(tmp_bfr, img_alt, 0, img_alt.length, Bool_.N, Bool_.N, Bool_.N, Bool_.N, Bool_.Y);
// tmp_bfr.Add_str_a7("'/>");
// }
@Override public void Html_thumb_core(Bry_bfr bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
tmp_bfr.Add(Xoh_make_trie_.Bry__img_style);
tmp_bfr.Add_int_variable(uid);
tmp_bfr.Add_byte_apos();
tmp_bfr.Add_byte_quote();
byte[] div2_width_repl = tmp_bfr.To_bry_and_clear();
fmtr_thumb_core.Bld_bfr_many(bfr, uid, div1_halign, div2_width_repl, div2_content);
}
@Override public void Html_thumb_part_magnify(Bry_bfr bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_mgnf, uid);}
@Override public void Html_thumb_part_info(Bry_bfr bfr, int uid, byte[] a_href, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_info, uid);}
@Override public void Html_thumb_part_play(Bry_bfr bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_xnde(bfr, Xoh_make_trie_.Bry__file_play, uid);}
public static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
private static void Write_xnde(Bry_bfr bfr, byte[] key, int uid) {
bfr.Add(key);
bfr.Add_int_variable(uid);
bfr.Add(Bry_xnde_end);
} private static final byte[] Bry_xnde_end = Bry_.new_a7("'/>");
} private static final byte[] Bry_xnde_end = Bry_.new_a7("\"/>");
public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {}
}

View File

@@ -33,7 +33,7 @@ public class Xoh_file_mgr {
public void Write_or_queue(Bry_bfr bfr, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {
file_wtr.Write_file(bfr, ctx, hctx, src, lnki, this.Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki), alt_text);
}
public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xop_lnki_tkn lnki) {return Lnki_eval(exec_tid, ctx, page, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Upright(), lnki.W(), lnki.H(), lnki.Time(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Id_media);}
public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xop_lnki_tkn lnki) {return Lnki_eval(exec_tid, ctx, page, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Upright(), lnki.W(), lnki.H(), lnki.Time(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Tid__media);}
public Xof_file_itm Lnki_eval(int exec_tid, Xop_ctx ctx, Xoae_page page, Xof_xfer_queue queue, byte[] lnki_ttl, byte lnki_type, double lnki_upright, int lnki_w, int lnki_h, double lnki_time, int lnki_page, boolean lnki_is_media_ns) {
int uid = queue.Html_uid().Val_add();
Xof_xfer_itm xfer = new Xof_xfer_itm();

View File

@@ -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.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import gplx.langs.htmls.*;
import gplx.langs.htmls.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.files.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*;
public class Xoh_file_wtr__basic {
private final Xowe_wiki wiki; private final Xow_html_mgr html_mgr; private final Xoh_html_wtr html_wtr; private final Bry_bfr_mkr bfr_mkr; private final Bry_bfr scratch_bfr = Bry_bfr.reset_(Io_mgr.Len_kb);
@@ -61,11 +61,11 @@ public class Xoh_file_wtr__basic {
if ( html_mgr.Img_suppress_missing_src() // option to suppress src when file is missing
&& !xfer_itm.File_exists() // file is missing; wipe values and wait for "correct" info before regenerating; mostly to handle unknown redirects
&& !orig_ext.Id_is_media() // file is media; never suppress; src needs to be available for "click" on play; note that most media will be missing (not downloaded)
&& lnki.Ns_id() != Xow_ns_.Id_media // ns is media; never suppress; "src" will use only orig_src; DATE:2014-01-30
&& lnki.Ns_id() != Xow_ns_.Tid__media // ns is media; never suppress; "src" will use only orig_src; DATE:2014-01-30
) {
img_orig_src = img_view_src = Bry_.Empty; // null out src
}
if (lnki.Ns_id() == Xow_ns_.Id_media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
if (lnki.Ns_id() == Xow_ns_.Tid__media) // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
this.Write_file_ns_media(bfr, ctx, src, lnki, img_orig_src);
else {
if ( Xof_ext_.Id_is_video_strict(orig_ext.Id()) // id is .ogv or .webm
@@ -135,7 +135,7 @@ public class Xoh_file_wtr__basic {
case Xop_lnki_align_h.None: bfr.Add(Div_float_none) .Add_byte_nl(); div_align_exists = true; break;
}
Arg_nde_tkn lnki_link_tkn = lnki.Link_tkn();
byte img_cls_tid = lnki.Border() == Bool_.Y_byte ? Xoh_lnki_consts.Tid_img_cls_thumbborder : Xoh_lnki_consts.Tid_img_cls_none;
byte img_cls_tid = lnki.Border() == Bool_.Y_byte ? Xoh_img_cls_.Tid__thumbborder : Xoh_img_cls_.Tid__none;
byte[] img_cls_other = lnki.Lnki_cls(); // PAGE:en.s:Page:Notes_on_Osteology_of_Baptanodon._With_a_Description_of_a_New_Species.pdf/3; DATE:2014-09-06
if (lnki_link_tkn == Arg_nde_tkn.Null) // full
lnki_file_wkr.Html_full_img(bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, img_cls_tid, img_cls_other);
@@ -155,9 +155,9 @@ public class Xoh_file_wtr__basic {
}
private byte[] Arg_content_thumb(Xoh_file_img_wkr lnki_file_wkr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, int uid, byte[] lnki_href, byte[] view_src, byte[] img_orig_src, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_title) {
byte[] lnki_alt_html = wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val() ? Arg_alt_html(ctx, src, lnki) : Bry_.Empty;
byte img_cls_tid = xfer_itm.File_exists() ? Xoh_lnki_consts.Tid_img_cls_thumbimage : Xoh_lnki_consts.Tid_img_cls_none;
byte img_cls_tid = xfer_itm.File_exists() ? Xoh_img_cls_.Tid__thumbimage : Xoh_img_cls_.Tid__none;
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
lnki_file_wkr.Html_full_img(tmp_bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, img_cls_tid, Xoh_lnki_consts.Bry_none);
lnki_file_wkr.Html_full_img(tmp_bfr, hctx, page, xfer_itm, uid, lnki_href, Xoh_lnki_consts.Tid_a_cls_image, Xoh_lnki_consts.Tid_a_rel_none, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, img_cls_tid, Xoh_img_cls_.Bry__none);
byte[] thumb = tmp_bfr.To_bry_and_clear();
html_fmtr.Html_thumb_file_image(tmp_bfr, thumb, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), lnki_alt_html);
return tmp_bfr.To_bry_and_rls();

View File

@@ -20,31 +20,11 @@ public class Xoh_lnki_consts {
public static final byte
Tid_a_cls_none = 0 , Tid_a_cls_image = 1
, Tid_a_rel_none = 0 , Tid_a_rel_nofollow = 1
, Tid_img_cls_none = 0 , Tid_img_cls_thumbimage = 2, Tid_img_cls_thumbborder = 3
;
public static final String Str_img_cls_thumbimage = "thumbimage";
private static final byte[]
Bry_anchor_class_image = Bry_.new_a7(" class=\"image\"")
, Bry_anchor_rel_nofollow = Bry_.new_a7(" rel=\"nofollow\"")
, Bry_img_cls_thumbborder = Bry_.new_a7(" class=\"thumbborder\"")
, Bry_img_cls_prefix = Bry_.new_a7(" class=\"")
;
public static final byte[] Bry_img_cls_thumbimage = Bry_.new_a7(" class=\"thumbimage\"");
public static final byte[] Bry_none = Bry_.Empty;
public static byte[] A_cls_to_bry(byte tid) {return tid == Tid_a_cls_none ? Bry_.Empty : Bry_anchor_class_image;}
public static byte[] A_rel_to_bry(byte tid) {return tid == Tid_a_rel_none ? Bry_.Empty : Bry_anchor_rel_nofollow;}
public static byte[] Img_cls_to_bry(byte tid, byte[] other) {
boolean other_is_empty = Bry_.Len_eq_0(other);
byte[] rv = null;
switch (tid) {
case Tid_img_cls_none: return other_is_empty ? Bry_.Empty : Bry_.Add(Bry_img_cls_prefix, other, Byte_ascii.Quote_bry);
case Tid_img_cls_thumbimage: rv = Bry_img_cls_thumbimage; break;
case Tid_img_cls_thumbborder: rv = Bry_img_cls_thumbborder; break;
default: throw Err_.new_unhandled(tid);
}
if (other_is_empty) return rv;
rv = Bry_.Copy(rv); // copy for replace below
rv[rv.length - 1] = Byte_ascii.Space; // replace " with space
return Bry_.Add(rv, other, Byte_ascii.Quote_bry); // add custom cls
}
}

View File

@@ -1,34 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import org.junit.*;
public class Xoh_lnki_consts_tst {
private Xoh_lnki_consts_fxt fxt = new Xoh_lnki_consts_fxt();
@Test public void Img_cls_to_bry() {
fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_none , null , "");
fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_none , "a" , " class=\"a\"");
fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_thumbimage , null , " class=\"thumbimage\"");
fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_thumbborder , null , " class=\"thumbborder\"");
fxt.Test_img_cls_to_bry(Xoh_lnki_consts.Tid_img_cls_thumbborder , "a" , " class=\"thumbborder a\"");
}
}
class Xoh_lnki_consts_fxt {
public void Test_img_cls_to_bry(byte tid, String other, String expd) {
Tfds.Eq(expd, String_.new_u8(Xoh_lnki_consts.Img_cls_to_bry(tid, Bry_.new_u8_safe(other))));
}
}

View File

@@ -52,7 +52,7 @@ public class Xoh_lnki_wtr {
Xow_xwiki_itm xwiki_lang = lnki_ttl.Wik_itm();
if ( xwiki_lang != null // lnki is xwiki; EX: [[commons:]] [[en:]] [[wikt:]]
&& xwiki_lang.Domain_tid() == wiki.Xwiki_mgr().Xwiki_domain_tid() // xwiki is same type as cur wiki; EX: cur=w xwiki=w -> add to xwiki_langs; cur=w xwikid=d -> don't add to xwiki_langs; DATE:2014-09-14
&& xwiki_lang.Type_is_xwiki_lang(wiki.Domain_itm().Lang_orig_key())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10
&& xwiki_lang.Show_in_sitelangs(wiki.Domain_itm().Lang_orig_key())// NOTE: use Lang_orig_id to handle xwikis between s.w and en.w; PAGE:s.q:Anonymous DATE:2014-09-10
&& !lnki_ttl.ForceLiteralLink() // not literal; [[:en:A]]
) {
Wdata_sitelink_itm slink = new Wdata_sitelink_itm(xwiki_lang.Abrv_wm(), xwiki_lang.Domain_name(), null).Page_ttl_(lnki_ttl);
@@ -63,9 +63,9 @@ public class Xoh_lnki_wtr {
redlinks_mgr.Lnki_add(lnki);
boolean stage_is_alt = hctx.Mode_is_alt();
switch (lnki.Ns_id()) {
case Xow_ns_.Id_media: if (!stage_is_alt) file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return; // NOTE: literal ":" has no effect; PAGE:en.w:Beethoven and [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]
case Xow_ns_.Id_file: if (!literal_link && !stage_is_alt) {file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return;} break;
case Xow_ns_.Id_category: if (!literal_link) {page.Html_data().Ctgs_add(lnki.Ttl()); return;} break;
case Xow_ns_.Tid__media: if (!stage_is_alt) file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return; // NOTE: literal ":" has no effect; PAGE:en.w:Beethoven and [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]
case Xow_ns_.Tid__file: if (!literal_link && !stage_is_alt) {file_wtr.Write_or_queue(bfr, page, ctx, hctx, src, lnki); return;} break;
case Xow_ns_.Tid__category: if (!literal_link) {page.Html_data().Ctgs_add(lnki.Ttl()); return;} break;
}
Write_plain_by_tkn(bfr, hctx, src, lnki, lnki_ttl);
}
@@ -99,10 +99,7 @@ public class Xoh_lnki_wtr {
if (hctx.Mode_is_alt())
Write_caption(bfr, ctx, hctx, src, lnki, ttl_bry, true, caption_wkr);
else {
if (hctx.Mode_is_hdump())
gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Html_plain(bfr, lnki);
else
bfr.Add(Xoh_consts.A_bgn); // '<a href="'
bfr.Add(Xoh_consts.A_bgn); // '<a href="'
app.Html__href_wtr().Build_to_bfr(bfr, app, wiki.Domain_bry(), lnki_ttl, hctx.Mode_is_popup()); // '/wiki/A'
if (cfg.Lnki__id()) {
int lnki_html_id = lnki.Html_uid();
@@ -121,7 +118,7 @@ public class Xoh_lnki_wtr {
bfr.Add(Bry_xowa_visited); // '" class="xowa-visited'
}
bfr.Add(Xoh_consts.__end_quote); // '">'
if (lnki_ttl.Anch_bgn() != -1 && !lnki_ttl.Ns().Id_main()) { // anchor exists and not main_ns; anchor must be manually added b/c Xoa_ttl does not handle # for non main-ns
if (lnki_ttl.Anch_bgn() != -1 && !lnki_ttl.Ns().Id_is_main()) { // anchor exists and not main_ns; anchor must be manually added b/c Xoa_ttl does not handle # for non main-ns
byte[] anch_txt = lnki_ttl.Anch_txt();
byte anch_spr
= (anch_txt.length > 0 && anch_txt[0] == Byte_ascii.Hash) // 1st char is #; occurs when page_txt has trailing space; causes 1st letter of anch_txt to start at # instead of 1st letter
@@ -169,14 +166,6 @@ public class Xoh_lnki_wtr {
}
return false;
}
public static void Html_plain(Bry_bfr bfr, Xop_lnki_tkn lnki) {
bfr.Add_str_a7
( lnki.Caption_exists() // caption exists; EX: [[A|b]]
|| lnki.Tail_bgn() != -1 // trailing chars; EX: [[A]]b
? "<a data-xotype='lnki1' href=\"" // embed caption
: "<a data-xotype='lnki0' href=\"" // use link only
);
}
public static byte[] Lnki_cls_visited(gplx.xowa.users.history.Xou_history_mgr history_mgr, byte[] wiki_key, byte[] page_ttl) {
return history_mgr.Has(wiki_key, page_ttl) ? Lnki_cls_visited_bry : Bry_.Empty;
} private static final byte[] Lnki_cls_visited_bry = Bry_.new_a7(" class=\"xowa-visited\"");

View File

@@ -20,17 +20,17 @@ 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_space_hzip implements Xoh_hzip_wkr {
public String Key() {return Xoh_hzip_dict_.Key__space;}
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, Bry_parser parser, byte[] src, int hook_bgn) {// " " -> 27,9,4
int space_len = parser.Fwd_while(Byte_ascii.Space) - hook_bgn;
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int src_end, int rng_bgn, int rng_end) {// " " -> 27,9,4
int space_len = Bry_find_.Find_fwd_while(src, rng_end, src_end, Byte_ascii.Space) - rng_bgn;
stat_itm.Space_add(space_len);
bfr.Add(Xoh_hzip_dict_.Bry__space);
Xoh_hzip_int_.Encode(1, bfr, space_len);
}
public int Decode(Bry_bfr bfr, Bry_parser parser, byte[] src, int hook_bgn) {
int space_len = parser.Read_int_by_base85(1);
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
int space_len = rdr.Read_int_by_base85(1);
bfr.Add_byte_repeat(Byte_ascii.Space, space_len);
return parser.Pos();
return rdr.Pos();
}
}

View File

@@ -25,4 +25,17 @@ public class Xoh_space_hzip_tst {
@Test public void Len__85() {
fxt.Test__bicode("~!{\"!", String_.Repeat(" ", 85));
}
@Test public void Many() {
fxt.Test__bicode(String_.Concat_lines_nl_skip_last
( " <div id='bodyContent' class='mw-body-content'>"
, "~!%<div id='siteSub'>a</div>"
, "~!%<div id='contentSub'></div>"
, "</div>"
), String_.Concat_lines_nl_skip_last
( " <div id='bodyContent' class='mw-body-content'>"
, " <div id='siteSub'>a</div>"
, " <div id='contentSub'></div>"
, "</div>"
));
}
}

View File

@@ -16,12 +16,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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 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_space_parse implements Html_doc_wkr {
private final Xoh_wkr wkr;
public class Xoh_space_parser implements Html_doc_wkr {
private final Xoh_hdoc_wkr wkr;
private byte[] src; private int src_end;
public Xoh_space_parse(Xoh_wkr wkr) {this.wkr = wkr;}
public Xoh_space_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
public byte[] Hook() {return Hook_bry;}
public void Init(byte[] src, int src_bgn, int src_end) {this.src = src; this.src_end = src_end;}
public int Parse(int pos) {

View File

@@ -0,0 +1,85 @@
/*
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.tags; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.btries.*; import gplx.core.primitives.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*;
import gplx.xowa.htmls.core.wkrs.lnkes.*; import gplx.xowa.htmls.core.wkrs.lnkis.*; import gplx.xowa.htmls.core.wkrs.hdrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*; import gplx.xowa.htmls.core.wkrs.thms.*;
import gplx.xowa.wikis.ttls.*;
public class Xoh_doc_wkr__tag implements Html_doc_wkr {
private Xoh_hdoc_wkr hdoc_wkr; private Xow_ttl_parser ttl_parser;
private final Html_tag_rdr tag_rdr = new Html_tag_rdr(); private byte[] src; private int src_end;
private final Xoh_lnki_parser wkr__lnki = new Xoh_lnki_parser();
private final Xoh_lnke_parser wkr__lnke = new Xoh_lnke_parser();
private final Xoh_hdr_parser wkr__hdr = new Xoh_hdr_parser();
private final Xoh_thm_parse wkr__img_thm = new Xoh_thm_parse();
private final Xoh_img_parser wkr__img_box = new Xoh_img_parser();
public byte[] Hook() {return Byte_ascii.Angle_bgn_bry;}
public Xoh_doc_wkr__tag Ctor(Xoh_hdoc_wkr hdoc_wkr, Xow_ttl_parser ttl_parser) {
this.hdoc_wkr = hdoc_wkr; this.ttl_parser = ttl_parser;
return this;
}
public void Init(byte[] src, int src_bgn, int src_end) {
this.src = src; this.src_end = src_end;
tag_rdr.Init(src, src_bgn, src_end);
}
public int Parse(int pos) {
tag_rdr.Pos_(pos);
int nxt_pos = tag_rdr.Pos() + 1; if (nxt_pos == src_end) return src_end;
Html_tag cur = src[tag_rdr.Pos() + 1] == Byte_ascii.Slash ? tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__any) : tag_rdr.Tag__move_fwd_head();
Html_tag nxt = null;
if (cur.Tag_is_tail()) {
hdoc_wkr.On_txt(pos, cur.Src_end());
}
else {
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();
nxt = tag_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(hdoc_wkr, tag_rdr, src, cur_name_id, hdr_tag_bgn, nxt);
}
break;
case Html_tag_.Id__a:
nxt = tag_rdr.Tag__peek_fwd_head();
if (nxt.Name_id() == Html_tag_.Id__img)
return wkr__img_box.Parse(hdoc_wkr, src, tag_rdr, cur);
else if (cur.Atrs__match_pair(Html_atr_.Bry__rel , Atr__rel__nofollow))
return wkr__lnke.Parse(hdoc_wkr, tag_rdr, cur);
else
return wkr__lnki.Parse(hdoc_wkr, tag_rdr, src, cur, ttl_parser);
case Html_tag_.Id__div:
if (cur.Atrs__cls_has(Atr__class__thumb))
return wkr__img_thm.Parse(hdoc_wkr, tag_rdr, src, cur);
break;
}
hdoc_wkr.On_txt(pos, cur.Src_end());
}
return cur.Src_end();
}
private static final byte[]
Atr__class__mw_headline = Bry_.new_a7("mw-headline")
, Atr__class__thumb = Bry_.new_a7("thumb")
, Atr__rel__nofollow = Bry_.new_a7("nofollow")
;
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.thms; 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_thm_html_tst {
private final Xoh_make_fxt fxt = new Xoh_make_fxt();
@Test public void Thumb__basic() {
// fxt.Expd_itms_xfers(fxt.Make_xfer("A.png", 0, 0, 0, Bool_.Y, Xof_ext_.Id_png));
fxt.Test__html("[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
( "<div class='thumb tright'>"
, " <div id='xowa_file_div_0' class='thumbinner' xowa_img_style='0'>"
, " <a href='/wiki/File:A.png' class='image'><img alt='' data-xoimg='8|-1|-1|-1|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/220px.png' width='0' height='0'/></a>"
, " <div class='thumbcaption'><xowa_mgnf id='0'/>"
, " test_caption"
, " </div>"
, " </div>"
, "</div>"
));
}
}

View File

@@ -0,0 +1,95 @@
/*
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.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.btries.*; import gplx.core.encoders.*;
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.hzips.stats.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.parsers.lnkis.*;
public class Xoh_thm_hzip implements Xoh_hzip_wkr {
private Xow_ttl_parser ttl_parser; private int uid;
public void Ttl_parser_(Xow_ttl_parser ttl_parser) {this.ttl_parser = ttl_parser; this.uid = 1;} // NOTE: should be 0, but for historical reasons, 1st lnki starts at 2; EX: id='xowa_lnki_2'
public String Key() {return Xoh_hzip_dict_.Key__lnki;}
public void Encode(Bry_bfr bfr, Hzip_stat_itm stat_itm, byte[] src, int rng_bgn, int rng_end) {
bfr.Add_mid(src, rng_bgn, rng_end);
}
public int Decode(Bry_bfr bfr, Xoh_decode_ctx ctx, Bry_rdr rdr, byte[] src, int hook_bgn) {
byte lnki_type = rdr.Read_byte();
int ns_id = rdr.Read_int_by_base85(1);
int site_bgn = -1, site_end = -1;
if (rdr.Is(Xoh_hzip_dict_.Escape)) {
site_bgn = rdr.Pos();
site_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
}
boolean site_exists = site_end - site_bgn > 0;
int page_bgn = rdr.Pos();
int page_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
int capt_bgn = -1, capt_end = -1;
if (lnki_type != Xoh_lnki_dict_.Type__same) {
capt_bgn = rdr.Pos();
capt_end = rdr.Find_fwd_lr(Xoh_hzip_dict_.Escape);
}
byte[] page_bry = Bry_.Mid(src, page_bgn, page_end);
Xoa_ttl ttl = ttl_parser.Ttl_parse(ns_id, page_bry); if (ttl == null) rdr.Fail("invalid ttl", "mid", String_.new_u8(page_bry)); // TODO: parse title based on site
byte[] ttl__full_db = ttl.Full_db();
// gen html
bfr.Add(Html_bldr_.Bry__a_lhs_w_href);
if (site_exists) bfr.Add_str_a7("/site/").Add_mid(src, site_bgn, site_end);
bfr.Add(Xoh_href_.Bry__wiki); // "/wiki/"
bfr.Add(ttl.Full_db());
bfr.Add_str_a7("\" id=\"").Add_str_a7(gplx.xowa.parsers.lnkis.redlinks.Xopg_redlink_lnki_list.Lnki_id_prefix).Add_int_variable(++uid);
bfr.Add_str_a7("\" title=\"");
byte[] title_bry = site_exists ? ttl.Page_db() : ttl__full_db; // for xwiki, use page, not full alias; EX: "wikt:A" -> "A" x> "wikt:A"
bfr.Add(Html_utl.Escape_html_as_bry(title_bry)).Add_str_a7("\">");
switch (lnki_type) {
case Xoh_lnki_dict_.Type__same:
if (ttl.Ns().Id_is_main())
bfr.Add_mid(src, page_bgn, page_end);
else
bfr.Add(ttl.Full_txt());
break;
case Xoh_lnki_dict_.Type__diff:
bfr.Add_mid(src, capt_bgn, capt_end);
break;
case Xoh_lnki_dict_.Type__trail:
bfr.Add_mid(src, page_bgn, page_end);
bfr.Add_mid(src, capt_bgn, capt_end);
break;
}
bfr.Add_str_a7("</a>");
return rdr.Pos();
}
// , Find_img_xatrs = Bry_.new_a7("xatrs='")
// private static int[] Save_img_full_pow = new int[] {0, 1, 2};
// private int Save_img_full(Bry_bfr bfr, Bry_rdr_old rdr, Hzip_stat_itm stat_itm, byte[] src, int src_len, int bgn, int pos) {
// bfr.Add(Xoh_hzip_dict_.Bry__img_full);
// int xatrs_bgn = Bry_find_.Move_fwd(src, Find_img_xatrs, pos, src_len); if (xatrs_bgn == Bry_find_.Not_found) return rdr.Warn("a.img_xatrs_missing", bgn, pos);
// bry_rdr.Init(src, xatrs_bgn);
// int a_cls = bry_rdr.Read_int_to_pipe();
// int a_rel = bry_rdr.Read_int_to_pipe();
// int img_rel = bry_rdr.Read_int_to_pipe();
// byte meta = (byte)Bit_.Shift_lhs_to_int(Save_img_full_pow, a_cls, a_rel, img_rel);
// bfr.Add_byte(meta); // meta
// Xoh_hzip_int_.Encode(bfr, bry_rdr.Read_int_to_pipe()); // uid
// bfr.Add(bry_rdr.Read_bry_to_pipe()).Add_byte_pipe(); // img_cls_other
// bfr.Add(bry_rdr.Read_bry_to_apos()); // alt
// bfr.Add_byte(Xoh_hzip_dict_.Escape);
// return bry_rdr.Pos() + 2; // +2=/>
// }
}

View File

@@ -0,0 +1,86 @@
/*
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.thms; 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_thm_hzip_tst {
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
@Test public void Page__basic() {
try {
Io_url html_dir = Io_url_.new_dir_("J:\\xowa\\dev\\html\\");
Bry_bfr bfr = Bry_bfr.new_();
fxt.Hzip_mgr().Encode(bfr, fxt.Parser_fxt().Wiki(), Bry_.Empty, Io_mgr.Instance.LoadFilBry(html_dir.GenSubFil("temp_earth_mw.html")), new gplx.xowa.htmls.core.hzips.stats.Hzip_stat_itm());
Io_mgr.Instance.SaveFilBry(html_dir.GenSubFil("temp_earth_mw_hzip.html"), bfr.To_bry_and_clear());
} catch (Exception e) {
Tfds.Write(e);
}
// fxt.Test__encode(""
// , String_.Concat_lines_nl_skip_last
// ( "<div class='thumb tleft'>"
// , " <div id='xowa_file_div_1' class='thumbinner' style='width:220px;'>"
// , " <a href='/wiki/File:A.png' class='image' xowa_title='A.png'>"
// , " <img id='xowa_file_img_1' alt='' "
// , " src='file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/0/0/A.png/220px.png' "
// , " width='220' height='119' class='thumbimage'>"
// , " </a> "
// , " <div class='thumbcaption'>"
// , " <div class='magnify'>"
// , " <a href='/wiki/File:A.png' class='@gplx.Internal protected' title='Enlarge'>"
// , " <img src='file:///C:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png' width='15' height='11' alt=''>"
// , " </a>"
// , " </div>b"
// , " </div>"
// , " </div>"
// , "</div>"
// ));
}
}
/*
<div class="thumb tleft">
<div id="xowa_file_div_60" class="thumbinner" style="width:220px;">
<a href="/wiki/File:Protoplanetary-disk.jpg" class="image" xowa_title="Protoplanetary-disk.jpg">
<img id="xowa_file_img_60" alt=""
src="file:///J:/xowa/file/commons.wikimedia.org/thumb/7/1/7/c/Protoplanetary-disk.jpg/220px.jpg"
width="220" height="119" class="thumbimage">
</a>
<div class="thumbcaption">
<div class="magnify">
<a href="/wiki/File:Protoplanetary-disk.jpg" class="@gplx.Internal protected" title="Enlarge">
<img src="file:///J:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png" width="15" height="11" alt="">
</a>
</div>Artist's impression of the early Solar System's planetary disk
</div>
</div>
</div>
<div class="thumb tleft">
<div id="xowa_file_div_60" class="thumbinner" style="width:0px;">
<a href="/wiki/File:Protoplanetary-disk.jpg" class="image" xowa_title="Protoplanetary-disk.jpg" data-xoimg='1|2|3|4|5|6|A.png'>
<img id="xowa_file_img_60" alt=""
src=""
width="0" height="0" class="thumbimage">
</a>
<div class="thumbcaption">
<div class="magnify">
<a href="/wiki/File:Protoplanetary-disk.jpg" class="@gplx.Internal protected" title="Enlarge">
<img src="file:///J:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png" width="15" height="11" alt="">
</a>
</div>Artist's impression of the early Solar System's planetary disk
</div>
</div>
</div>
*/

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.htmls.core.wkrs.thms; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
import gplx.core.brys.*;
import gplx.xowa.htmls.core.wkrs.lnkis.anchs.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.parsers.*; import gplx.langs.htmls.parsers.styles.*;
import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.htmls.core.wkrs.imgs.*;
public class Xoh_thm_parse {
/*
<div class="thumb tleft">
<div id="xowa_file_div_60" class="thumbinner" style="width:220px;">
<a href="/wiki/File:Protoplanetary-disk.jpg" class="image" xowa_title="Protoplanetary-disk.jpg">
<img id="xowa_file_img_60" alt=""
src="file:///J:/xowa/file/commons.wikimedia.org/thumb/7/1/7/c/Protoplanetary-disk.jpg/220px.jpg"
width="220" height="119" class="thumbimage">
</a>
<div class="thumbcaption">
<div class="magnify">
<a href="/wiki/File:Protoplanetary-disk.jpg" class="@gplx.Internal protected" title="Enlarge">
<img src="file:///J:/xowa/bin/any/xowa/file/mediawiki.file/magnify-clip.png" width="15" height="11" alt="">
</a>
</div>Artist's impression of the early Solar System's planetary disk
</div>
</div>
</div>
*/
private final Xoh_anch_href_parser href_parser = new Xoh_anch_href_parser();
private final Xoh_img_parser img_parser = new Xoh_img_parser();
private final Bry_rdr rdr = new Bry_rdr();
public int Parse(Xoh_hdoc_wkr hdoc_wkr, Html_tag_rdr tag_rdr, byte[] src, Html_tag div_0) {
int rng_bgn = div_0.Src_bgn(), rng_end = div_0.Src_end();
byte thm_align = div_0.Atrs__cls_find_1st(Xop_lnki_align_h.Hash);
Html_tag div_1 = tag_rdr.Tag__move_fwd_head(Bry__cls__thumbinner);
int div_width = div_1.Atrs__style_get_as_int(Html_atr_style_.Bry__width);
Html_tag anch = tag_rdr.Tag__move_fwd_head(Xoh_img_parser.Bry__cls__anch__image);
Html_atr href = anch.Atrs__get_by(Html_atr_.Bry__href);
rdr.Ctor_by_page(Bry_.Empty, src, src.length);
href_parser.Parse(rdr, hdoc_wkr.Ctx().Wiki(), href.Val_bgn(), href.Val_end());
img_parser.Parse(hdoc_wkr, src, tag_rdr, anch);
tag_rdr.Tag__move_fwd_head(Bry__cls__thumbcaption);
tag_rdr.Tag__move_fwd_head(Bry__cls__magnify);
Html_tag div_3_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
int capt_bgn = div_3_tail.Src_end();
Html_tag div_4_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
int capt_end = div_4_tail.Src_bgn();
tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
Html_tag div_0_tail = tag_rdr.Tag__move_fwd_tail(Html_tag_.Id__div);
rng_end = div_0_tail.Src_end();
Tfds.Write(thm_align, div_width, Bry_.Mid(src, href_parser.Page_bgn(), href_parser.Page_end()), img_parser.Img_w(), img_parser.Img_h(), Bry_.Mid_w_trim(src, capt_bgn, capt_end), rng_end);
hdoc_wkr.On_img_thm(rng_bgn, rng_end);
return rng_end;
}
private static final byte[]
Bry__cls__thumbinner = Bry_.new_a7("thumbinner")
, Bry__cls__thumbcaption = Bry_.new_a7("thumbcaption")
, Bry__cls__magnify = Bry_.new_a7("magnify")
;
}

View File

@@ -16,10 +16,10 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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 gplx.langs.htmls.parsers.*; import gplx.xowa.htmls.core.parsers.*;
public class Xoh_txt_parse implements Html_txt_wkr {
private final Xoh_wkr wkr;
public Xoh_txt_parse(Xoh_wkr wkr) {this.wkr = wkr;}
import gplx.langs.htmls.parsers.*;
public class Xoh_txt_parser implements Html_txt_wkr {
private final Xoh_hdoc_wkr wkr;
public Xoh_txt_parser(Xoh_hdoc_wkr wkr) {this.wkr = wkr;}
public void Init(byte[] src, int src_bgn, int src_end) {}
public void Parse(int rng_bgn, int rng_end) {
wkr.On_txt(rng_bgn, rng_end);

View File

@@ -65,7 +65,7 @@ public class Xoh_dom_ {
return true;
}
public static String Title_by_href(byte[] href, byte[] html_src) {
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.A_name_bry, Html_atr_.Bry__href, href, gplx.xowa.htmls.Xoh_consts.Atr_xowa_title_bry, 0);
byte[] xowa_title = Xoh_dom_.Query_val_by_where(dom_find, html_src, Html_tag_.Bry__a, Html_atr_.Bry__href, href, gplx.xowa.htmls.Xoh_consts.Atr_xowa_title_bry, 0);
return String_.new_u8(xowa_title);
} private static final Xoh_find dom_find = new Xoh_find();
}

View File

@@ -21,6 +21,7 @@ public class Xoh_head_itm_ {
Key__collapsible = Bry_.new_a7("collapsible")
, Key__css = Bry_.new_a7("css")
, Key__gallery = Bry_.new_a7("gallery")
, Key__gallery_styles = Bry_.new_a7("gallery_styles")
, Key__globals = Bry_.new_a7("globals")
, Key__graph = Bry_.new_a7("graph")
, Key__hiero = Bry_.new_a7("hiero")

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